Lines 83-88
struct cmds {
Link Here
|
83 |
}; |
83 |
}; |
84 |
static struct cmds cmds[]; |
84 |
static struct cmds cmds[]; |
85 |
|
85 |
|
|
|
86 |
/* Must match the ETHERSWITCH_PORT_LED_* enum order */ |
87 |
static const char *ledstyles[] = { "default", "on", "off", "blink", NULL }; |
86 |
|
88 |
|
87 |
/* |
89 |
/* |
88 |
* Print a value a la the %b format of the kernel's printf. |
90 |
* Print a value a la the %b format of the kernel's printf. |
Lines 270-275
set_port_mediaopt(struct cfg *cfg, char *argv[])
Link Here
|
270 |
} |
272 |
} |
271 |
|
273 |
|
272 |
static void |
274 |
static void |
|
|
275 |
set_port_led(struct cfg *cfg, char *argv[]) |
276 |
{ |
277 |
etherswitch_port_t p; |
278 |
int led; |
279 |
int i; |
280 |
|
281 |
bzero(&p, sizeof(p)); |
282 |
p.es_port = cfg->unit; |
283 |
if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0) |
284 |
err(EX_OSERR, "ioctl(IOETHERSWITCHGETPORT)"); |
285 |
|
286 |
led = strtol(argv[1], NULL, 0); |
287 |
if (led < 1 || led > p.es_nleds) |
288 |
errx(EX_USAGE, "invalid led number %s; must be between 1 and %d", |
289 |
argv[1], p.es_nleds); |
290 |
|
291 |
led--; |
292 |
|
293 |
for (i=0; ledstyles[i] != NULL; i++) { |
294 |
if (strcmp(argv[2], ledstyles[i]) == 0) { |
295 |
p.es_led[led] = i; |
296 |
break; |
297 |
} |
298 |
} |
299 |
if (ledstyles[i] == NULL) |
300 |
errx(EX_USAGE, "invalid led style \"%s\"", argv[2]); |
301 |
|
302 |
if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0) |
303 |
err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)"); |
304 |
} |
305 |
|
306 |
static void |
273 |
set_vlangroup_vid(struct cfg *cfg, char *argv[]) |
307 |
set_vlangroup_vid(struct cfg *cfg, char *argv[]) |
274 |
{ |
308 |
{ |
275 |
int v; |
309 |
int v; |
Lines 334-343
set_register(struct cfg *cfg, char *arg)
Link Here
|
334 |
if (c==arg) |
368 |
if (c==arg) |
335 |
return (1); |
369 |
return (1); |
336 |
if (*c == '=') { |
370 |
if (*c == '=') { |
337 |
v = strtol(c+1, NULL, 0); |
371 |
v = strtoul(c+1, NULL, 0); |
338 |
write_register(cfg, a, v); |
372 |
write_register(cfg, a, v); |
339 |
} |
373 |
} |
340 |
printf("\treg 0x%04x=0x%04x\n", a, read_register(cfg, a)); |
374 |
printf("\treg 0x%04x=0x%08x\n", a, read_register(cfg, a)); |
341 |
return (0); |
375 |
return (0); |
342 |
} |
376 |
} |
343 |
|
377 |
|
Lines 357-363
set_phyregister(struct cfg *cfg, char *arg)
Link Here
|
357 |
if (d == c) |
391 |
if (d == c) |
358 |
return (1); |
392 |
return (1); |
359 |
if (*c == '=') { |
393 |
if (*c == '=') { |
360 |
val = strtol(c+1, NULL, 0); |
394 |
val = strtoul(c+1, NULL, 0); |
361 |
write_phyregister(cfg, phy, reg, val); |
395 |
write_phyregister(cfg, phy, reg, val); |
362 |
} |
396 |
} |
363 |
printf("\treg %d.0x%02x=0x%04x\n", phy, reg, read_phyregister(cfg, phy, reg)); |
397 |
printf("\treg %d.0x%02x=0x%04x\n", phy, reg, read_phyregister(cfg, phy, reg)); |
Lines 442-447
print_port(struct cfg *cfg, int port)
Link Here
|
442 |
printf("\tpvid: %d\n", p.es_pvid); |
476 |
printf("\tpvid: %d\n", p.es_pvid); |
443 |
printb("\tflags", p.es_flags, ETHERSWITCH_PORT_FLAGS_BITS); |
477 |
printb("\tflags", p.es_flags, ETHERSWITCH_PORT_FLAGS_BITS); |
444 |
printf("\n"); |
478 |
printf("\n"); |
|
|
479 |
if (p.es_nleds) { |
480 |
printf("\tled: "); |
481 |
for (i = 0; i < p.es_nleds; i++) { |
482 |
printf("%d:%s%s", i+1, ledstyles[p.es_led[i]], (i==p.es_nleds-1)?"":" "); |
483 |
} |
484 |
printf("\n"); |
485 |
} |
445 |
printf("\tmedia: "); |
486 |
printf("\tmedia: "); |
446 |
print_media_word(p.es_ifmr.ifm_current, 1); |
487 |
print_media_word(p.es_ifmr.ifm_current, 1); |
447 |
if (p.es_ifmr.ifm_active != p.es_ifmr.ifm_current) { |
488 |
if (p.es_ifmr.ifm_active != p.es_ifmr.ifm_current) { |
Lines 540-546
usage(struct cfg *cfg __unused, char *argv[] __unu
Link Here
|
540 |
"phy.register[=value]\n"); |
581 |
"phy.register[=value]\n"); |
541 |
fprintf(stderr, "\tetherswitchcfg [-f control file] portX " |
582 |
fprintf(stderr, "\tetherswitchcfg [-f control file] portX " |
542 |
"[flags] command parameter\n"); |
583 |
"[flags] command parameter\n"); |
543 |
fprintf(stderr, "\t\tport commands: pvid, media, mediaopt\n"); |
584 |
fprintf(stderr, "\t\tport commands: pvid, media, mediaopt, led\n"); |
544 |
fprintf(stderr, "\tetherswitchcfg [-f control file] reg " |
585 |
fprintf(stderr, "\tetherswitchcfg [-f control file] reg " |
545 |
"register[=value]\n"); |
586 |
"register[=value]\n"); |
546 |
fprintf(stderr, "\tetherswitchcfg [-f control file] vlangroupX " |
587 |
fprintf(stderr, "\tetherswitchcfg [-f control file] vlangroupX " |
Lines 651-657
main(int argc, char *argv[])
Link Here
|
651 |
for(i=0; cmds[i].name != NULL; i++) { |
692 |
for(i=0; cmds[i].name != NULL; i++) { |
652 |
if (cfg.mode == cmds[i].mode && strcmp(argv[0], cmds[i].name) == 0) { |
693 |
if (cfg.mode == cmds[i].mode && strcmp(argv[0], cmds[i].name) == 0) { |
653 |
if (argc < (cmds[i].args + 1)) { |
694 |
if (argc < (cmds[i].args + 1)) { |
654 |
printf("%s needs an argument\n", cmds[i].name); |
695 |
printf("%s needs %d argument%s\n", cmds[i].name, cmds[i].args, (cmds[i].args==1)?"":","); |
655 |
break; |
696 |
break; |
656 |
} |
697 |
} |
657 |
(cmds[i].f)(&cfg, argv); |
698 |
(cmds[i].f)(&cfg, argv); |
Lines 691-696
static struct cmds cmds[] = {
Link Here
|
691 |
{ MODE_PORT, "pvid", 1, set_port_vid }, |
732 |
{ MODE_PORT, "pvid", 1, set_port_vid }, |
692 |
{ MODE_PORT, "media", 1, set_port_media }, |
733 |
{ MODE_PORT, "media", 1, set_port_media }, |
693 |
{ MODE_PORT, "mediaopt", 1, set_port_mediaopt }, |
734 |
{ MODE_PORT, "mediaopt", 1, set_port_mediaopt }, |
|
|
735 |
{ MODE_PORT, "led", 2, set_port_led }, |
694 |
{ MODE_PORT, "addtag", 0, set_port_flag }, |
736 |
{ MODE_PORT, "addtag", 0, set_port_flag }, |
695 |
{ MODE_PORT, "-addtag", 0, set_port_flag }, |
737 |
{ MODE_PORT, "-addtag", 0, set_port_flag }, |
696 |
{ MODE_PORT, "ingress", 0, set_port_flag }, |
738 |
{ MODE_PORT, "ingress", 0, set_port_flag }, |