Lines Matching refs:cfg

69 struct cfg {
84 void (*f)(struct cfg *, char *argv[]);
122 read_register(struct cfg *cfg, int r)
127 if (ioctl(cfg->fd, IOETHERSWITCHGETREG, &er) != 0)
133 write_register(struct cfg *cfg, int r, int v)
139 if (ioctl(cfg->fd, IOETHERSWITCHSETREG, &er) != 0)
144 read_phyregister(struct cfg *cfg, int phy, int reg)
150 if (ioctl(cfg->fd, IOETHERSWITCHGETPHYREG, &er) != 0)
156 write_phyregister(struct cfg *cfg, int phy, int reg, int val)
163 if (ioctl(cfg->fd, IOETHERSWITCHSETPHYREG, &er) != 0)
168 set_port_vid(struct cfg *cfg, char *argv[])
178 p.es_port = cfg->unit;
179 if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
182 if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0)
187 set_port_flag(struct cfg *cfg, char *argv[])
216 p.es_port = cfg->unit;
217 if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
223 if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0)
228 set_port_media(struct cfg *cfg, char *argv[])
235 p.es_port = cfg->unit;
238 if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
245 if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0)
250 set_port_mediaopt(struct cfg *cfg, char *argv[])
257 p.es_port = cfg->unit;
260 if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
270 if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0)
275 set_vlangroup_vid(struct cfg *cfg, char *argv[])
284 vg.es_vlangroup = cfg->unit;
285 if (ioctl(cfg->fd, IOETHERSWITCHGETVLANGROUP, &vg) != 0)
288 if (ioctl(cfg->fd, IOETHERSWITCHSETVLANGROUP, &vg) != 0)
293 set_vlangroup_members(struct cfg *cfg, char *argv[])
307 if (v < 0 || v >= cfg->info.es_nports)
308 errx(EX_USAGE, "Member port must be between 0 and %d", cfg->info.es_nports-1);
322 vg.es_vlangroup = cfg->unit;
323 if (ioctl(cfg->fd, IOETHERSWITCHGETVLANGROUP, &vg) != 0)
327 if (ioctl(cfg->fd, IOETHERSWITCHSETVLANGROUP, &vg) != 0)
332 set_register(struct cfg *cfg, char *arg)
342 write_register(cfg, a, v);
344 printf("\treg 0x%04x=0x%04x\n", a, read_register(cfg, a));
349 set_phyregister(struct cfg *cfg, char *arg)
365 write_phyregister(cfg, phy, reg, val);
367 printf("\treg %d.0x%02x=0x%04x\n", phy, reg, read_phyregister(cfg, phy, reg));
372 set_vlan_mode(struct cfg *cfg, char *argv[])
390 if (ioctl(cfg->fd, IOETHERSWITCHSETCONF, &conf) != 0)
395 print_config(struct cfg *cfg)
400 c = strrchr(cfg->controlfile, '/');
404 c = cfg->controlfile;
407 if (cfg->conf.cmd & ETHERSWITCH_CONF_VLAN_MODE) {
409 switch (cfg->conf.vlan_mode) {
432 print_port(struct cfg *cfg, int port)
442 if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
445 if (cfg->conf.vlan_mode == ETHERSWITCH_VLAN_DOT1Q)
459 if (cfg->mediatypes) {
472 print_vlangroup(struct cfg *cfg, int vlangroup)
478 if (ioctl(cfg->fd, IOETHERSWITCHGETVLANGROUP, &vg) != 0)
484 if (cfg->conf.vlan_mode == ETHERSWITCH_VLAN_PORT)
491 for (i=0; i<cfg->info.es_nports; i++) {
507 print_info(struct cfg *cfg)
512 c = strrchr(cfg->controlfile, '/');
516 c = cfg->controlfile;
517 if (cfg->verbose) {
519 cfg->info.es_name, cfg->info.es_nports,
520 cfg->info.es_nvlangroups);
522 printb("VLAN capabilities", cfg->info.es_vlan_caps,
526 print_config(cfg);
527 for (i=0; i<cfg->info.es_nports; i++) {
528 print_port(cfg, i);
530 for (i=0; i<cfg->info.es_nvlangroups; i++) {
531 print_vlangroup(cfg, i);
536 usage(struct cfg *cfg __unused, char *argv[] __unused)
557 newmode(struct cfg *cfg, enum cmdmode mode)
559 if (mode == cfg->mode)
561 switch (cfg->mode) {
569 if (ioctl(cfg->fd, IOETHERSWITCHGETCONF, &cfg->conf) != 0)
571 print_config(cfg);
574 print_port(cfg, cfg->unit);
577 print_vlangroup(cfg, cfg->unit);
583 cfg->mode = mode;
590 struct cfg cfg;
593 bzero(&cfg, sizeof(cfg));
594 cfg.controlfile = "/dev/etherswitch0";
598 cfg.controlfile = optarg;
601 cfg.mediatypes++;
604 cfg.verbose++;
609 usage(&cfg, argv);
613 cfg.fd = open(cfg.controlfile, O_RDONLY);
614 if (cfg.fd < 0)
615 err(EX_UNAVAILABLE, "Can't open control file: %s", cfg.controlfile);
616 if (ioctl(cfg.fd, IOETHERSWITCHGETINFO, &cfg.info) != 0)
618 if (ioctl(cfg.fd, IOETHERSWITCHGETCONF, &cfg.conf) != 0)
621 print_info(&cfg);
624 cfg.mode = MODE_NONE;
626 switch(cfg.mode) {
629 print_info(&cfg);
630 } else if (sscanf(argv[0], "port%d", &cfg.unit) == 1) {
631 if (cfg.unit < 0 || cfg.unit >= cfg.info.es_nports)
632 errx(EX_USAGE, "port unit must be between 0 and %d", cfg.info.es_nports - 1);
633 newmode(&cfg, MODE_PORT);
634 } else if (sscanf(argv[0], "vlangroup%d", &cfg.unit) == 1) {
635 if (cfg.unit < 0 || cfg.unit >= cfg.info.es_nvlangroups)
638 cfg.info.es_nvlangroups - 1);
639 newmode(&cfg, MODE_VLANGROUP);
641 newmode(&cfg, MODE_CONFIG);
643 newmode(&cfg, MODE_PHYREG);
645 newmode(&cfg, MODE_REGISTER);
647 usage(&cfg, argv);
656 if (cfg.mode == cmds[i].mode && strcmp(argv[0], cmds[i].name) == 0) {
661 (cmds[i].f)(&cfg, argv);
668 newmode(&cfg, MODE_NONE);
673 if (set_register(&cfg, argv[0]) != 0) {
674 newmode(&cfg, MODE_NONE);
679 if (set_phyregister(&cfg, argv[0]) != 0) {
680 newmode(&cfg, MODE_NONE);
689 newmode(&cfg, MODE_NONE);
690 close(cfg.fd);