[etherswitch] add LED API to the documentation and command line tool.

Submitted by:	Dan Nelson <dnelson_1901@yahoo.com>
This commit is contained in:
Adrian Chadd 2016-08-04 17:46:07 +00:00
parent c94dc8089f
commit 1cec2c734a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=303752
2 changed files with 85 additions and 34 deletions

View File

@ -33,26 +33,26 @@
.Sh SYNOPSIS
.Nm
.Op Fl "f control file"
.Ar info
.Cm info
.Nm
.Op Fl "f control file"
.Ar config
.Cm config
.Ar command parameter
.Nm
.Op Fl "f control file"
.Ar phy
.Cm phy
.Ar phy.register[=value]
.Nm
.Op Fl "f control file"
.Ar port%d
.Cm port%d
.Ar [flags] command parameter
.Nm
.Op Fl "f control file"
.Ar reg
.Cm reg
.Ar register[=value]
.Nm
.Op Fl "f control file"
.Ar vlangroup%d
.Cm vlangroup%d
.Ar command parameter
.Sh DESCRIPTION
The
@ -81,8 +81,8 @@ The config command provides access to global switch configuration
parameters.
It support the following commands:
.Pp
.Bl -tag -width ".Ar vlan_mode mode" -compact
.It Ar vlan_mode mode
.Bl -tag -width ".Cm vlan_mode mode" -compact
.It Cm vlan_mode Ar mode
Sets the switch VLAN mode (depends on the hardware).
.El
.Ss phy
@ -103,51 +103,60 @@ The port command selects one of the ports of the switch.
It supports the following commands:
.Pp
.Bl -tag -width ".Ar pvid number" -compact
.It Ar pvid number
.It Cm pvid Ar number
Sets the default port VID that is used to process incoming frames that are not tagged.
.It Ar media mediaspec
.It Cm media Ar mediaspec
Specifies the physical media configuration to be configured for a port.
.It Ar mediaopt mediaoption
.It Cm mediaopt Ar mediaoption
Specifies a list of media options for a port.
See
.Xr ifconfig 8
for details on
.Ar media
.Cm media
and
.Ar mediaopt .
.Cm mediaopt .
.It Cm led Ar number style
Sets the display style for a given LED. Available styles are:
.Cm default
(usually flash on activity),
.Cm on ,
.Cm off ,
and
.Cm blink .
Not all switches will support all styles.
.El
.Pp
And the following flags (please note that not all flags
are supported by all switch drivers):
.Pp
.Bl -tag -width ".Ar addtag" -compact
.It Ar addtag
.Bl -tag -width ".Fl addtag" -compact
.It Cm addtag
Add VLAN tag to each packet sent by the port.
.It Ar -addtag
.It Fl addtag
Disable the add VLAN tag option.
.It Ar striptag
.It Cm striptag
Strip the VLAN tags from the packets sent by the port.
.It Ar -striptag
.It Fl striptag
Disable the strip VLAN tag option.
.It Ar firstlock
.It Cm firstlock
This options makes the switch port lock on the first MAC address it sees.
After that, usually you need to reset the switch to learn different
MAC addresses.
.It Ar -firstlock
.It Fl firstlock
Disable the first lock option.
Note that sometimes you need to reset the
switch to really disable this option.
.It Ar dropuntagged
.It Cm dropuntagged
Drop packets without a VLAN tag.
.It Ar -dropuntagged
.It Fl dropuntagged
Disable the drop untagged packets option.
.It Ar doubletag
.It Cm doubletag
Enable QinQ for the port.
.It Ar -doubletag
.It Fl doubletag
Disable QinQ for the port.
.It Ar ingress
.It Cm ingress
Enable the ingress filter on the port.
.It Ar -ingress
.It Fl ingress
Disable the ingress filter.
.El
.Ss reg
@ -156,14 +165,14 @@ The reg command provides access to the registers of the switch controller.
The vlangroup command selects one of the VLAN groups for configuration.
It supports the following commands:
.Pp
.Bl -tag -width ".Ar vlangroup" -compact
.It Ar vlan VID
.Bl -tag -width ".Cm members" -compact
.It Cm vlan Ar VID
Sets the VLAN ID (802.1q VID) for this VLAN group.
Frames transmitted on tagged member ports of this group will be tagged
with this VID.
Incoming frames carrying this tag will be forwarded according to the
configuration of this VLAN group.
.It Ar members port,...
.It Cm members Ar port,...
Configures which ports are to be a member of this VLAN group.
The port numbers are given as a comma-separated list.
Each port can optionally be followed by

View File

@ -83,6 +83,8 @@ struct cmds {
};
static struct cmds cmds[];
/* Must match the ETHERSWITCH_PORT_LED_* enum order */
static const char *ledstyles[] = { "default", "on", "off", "blink", NULL };
/*
* Print a value a la the %b format of the kernel's printf.
@ -269,6 +271,38 @@ set_port_mediaopt(struct cfg *cfg, char *argv[])
err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)");
}
static void
set_port_led(struct cfg *cfg, char *argv[])
{
etherswitch_port_t p;
int led;
int i;
bzero(&p, sizeof(p));
p.es_port = cfg->unit;
if (ioctl(cfg->fd, IOETHERSWITCHGETPORT, &p) != 0)
err(EX_OSERR, "ioctl(IOETHERSWITCHGETPORT)");
led = strtol(argv[1], NULL, 0);
if (led < 1 || led > p.es_nleds)
errx(EX_USAGE, "invalid led number %s; must be between 1 and %d",
argv[1], p.es_nleds);
led--;
for (i=0; ledstyles[i] != NULL; i++) {
if (strcmp(argv[2], ledstyles[i]) == 0) {
p.es_led[led] = i;
break;
}
}
if (ledstyles[i] == NULL)
errx(EX_USAGE, "invalid led style \"%s\"", argv[2]);
if (ioctl(cfg->fd, IOETHERSWITCHSETPORT, &p) != 0)
err(EX_OSERR, "ioctl(IOETHERSWITCHSETPORT)");
}
static void
set_vlangroup_vid(struct cfg *cfg, char *argv[])
{
@ -334,10 +368,10 @@ set_register(struct cfg *cfg, char *arg)
if (c==arg)
return (1);
if (*c == '=') {
v = strtol(c+1, NULL, 0);
v = strtoul(c+1, NULL, 0);
write_register(cfg, a, v);
}
printf("\treg 0x%04x=0x%04x\n", a, read_register(cfg, a));
printf("\treg 0x%04x=0x%08x\n", a, read_register(cfg, a));
return (0);
}
@ -357,7 +391,7 @@ set_phyregister(struct cfg *cfg, char *arg)
if (d == c)
return (1);
if (*c == '=') {
val = strtol(c+1, NULL, 0);
val = strtoul(c+1, NULL, 0);
write_phyregister(cfg, phy, reg, val);
}
printf("\treg %d.0x%02x=0x%04x\n", phy, reg, read_phyregister(cfg, phy, reg));
@ -442,6 +476,13 @@ print_port(struct cfg *cfg, int port)
printf("\tpvid: %d\n", p.es_pvid);
printb("\tflags", p.es_flags, ETHERSWITCH_PORT_FLAGS_BITS);
printf("\n");
if (p.es_nleds) {
printf("\tled: ");
for (i = 0; i < p.es_nleds; i++) {
printf("%d:%s%s", i+1, ledstyles[p.es_led[i]], (i==p.es_nleds-1)?"":" ");
}
printf("\n");
}
printf("\tmedia: ");
print_media_word(p.es_ifmr.ifm_current, 1);
if (p.es_ifmr.ifm_active != p.es_ifmr.ifm_current) {
@ -540,7 +581,7 @@ usage(struct cfg *cfg __unused, char *argv[] __unused)
"phy.register[=value]\n");
fprintf(stderr, "\tetherswitchcfg [-f control file] portX "
"[flags] command parameter\n");
fprintf(stderr, "\t\tport commands: pvid, media, mediaopt\n");
fprintf(stderr, "\t\tport commands: pvid, media, mediaopt, led\n");
fprintf(stderr, "\tetherswitchcfg [-f control file] reg "
"register[=value]\n");
fprintf(stderr, "\tetherswitchcfg [-f control file] vlangroupX "
@ -651,7 +692,7 @@ main(int argc, char *argv[])
for(i=0; cmds[i].name != NULL; i++) {
if (cfg.mode == cmds[i].mode && strcmp(argv[0], cmds[i].name) == 0) {
if (argc < (cmds[i].args + 1)) {
printf("%s needs an argument\n", cmds[i].name);
printf("%s needs %d argument%s\n", cmds[i].name, cmds[i].args, (cmds[i].args==1)?"":",");
break;
}
(cmds[i].f)(&cfg, argv);
@ -691,6 +732,7 @@ static struct cmds cmds[] = {
{ MODE_PORT, "pvid", 1, set_port_vid },
{ MODE_PORT, "media", 1, set_port_media },
{ MODE_PORT, "mediaopt", 1, set_port_mediaopt },
{ MODE_PORT, "led", 2, set_port_led },
{ MODE_PORT, "addtag", 0, set_port_flag },
{ MODE_PORT, "-addtag", 0, set_port_flag },
{ MODE_PORT, "ingress", 0, set_port_flag },