[etherswitch] add LED API to the documentation and command line tool.
Submitted by: Dan Nelson <dnelson_1901@yahoo.com>
This commit is contained in:
parent
c94dc8089f
commit
1cec2c734a
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=303752
@ -33,26 +33,26 @@
|
|||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl "f control file"
|
.Op Fl "f control file"
|
||||||
.Ar info
|
.Cm info
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl "f control file"
|
.Op Fl "f control file"
|
||||||
.Ar config
|
.Cm config
|
||||||
.Ar command parameter
|
.Ar command parameter
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl "f control file"
|
.Op Fl "f control file"
|
||||||
.Ar phy
|
.Cm phy
|
||||||
.Ar phy.register[=value]
|
.Ar phy.register[=value]
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl "f control file"
|
.Op Fl "f control file"
|
||||||
.Ar port%d
|
.Cm port%d
|
||||||
.Ar [flags] command parameter
|
.Ar [flags] command parameter
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl "f control file"
|
.Op Fl "f control file"
|
||||||
.Ar reg
|
.Cm reg
|
||||||
.Ar register[=value]
|
.Ar register[=value]
|
||||||
.Nm
|
.Nm
|
||||||
.Op Fl "f control file"
|
.Op Fl "f control file"
|
||||||
.Ar vlangroup%d
|
.Cm vlangroup%d
|
||||||
.Ar command parameter
|
.Ar command parameter
|
||||||
.Sh DESCRIPTION
|
.Sh DESCRIPTION
|
||||||
The
|
The
|
||||||
@ -81,8 +81,8 @@ The config command provides access to global switch configuration
|
|||||||
parameters.
|
parameters.
|
||||||
It support the following commands:
|
It support the following commands:
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width ".Ar vlan_mode mode" -compact
|
.Bl -tag -width ".Cm vlan_mode mode" -compact
|
||||||
.It Ar vlan_mode mode
|
.It Cm vlan_mode Ar mode
|
||||||
Sets the switch VLAN mode (depends on the hardware).
|
Sets the switch VLAN mode (depends on the hardware).
|
||||||
.El
|
.El
|
||||||
.Ss phy
|
.Ss phy
|
||||||
@ -103,51 +103,60 @@ The port command selects one of the ports of the switch.
|
|||||||
It supports the following commands:
|
It supports the following commands:
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width ".Ar pvid number" -compact
|
.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.
|
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.
|
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.
|
Specifies a list of media options for a port.
|
||||||
See
|
See
|
||||||
.Xr ifconfig 8
|
.Xr ifconfig 8
|
||||||
for details on
|
for details on
|
||||||
.Ar media
|
.Cm media
|
||||||
and
|
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
|
.El
|
||||||
.Pp
|
.Pp
|
||||||
And the following flags (please note that not all flags
|
And the following flags (please note that not all flags
|
||||||
are supported by all switch drivers):
|
are supported by all switch drivers):
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width ".Ar addtag" -compact
|
.Bl -tag -width ".Fl addtag" -compact
|
||||||
.It Ar addtag
|
.It Cm addtag
|
||||||
Add VLAN tag to each packet sent by the port.
|
Add VLAN tag to each packet sent by the port.
|
||||||
.It Ar -addtag
|
.It Fl addtag
|
||||||
Disable the add VLAN tag option.
|
Disable the add VLAN tag option.
|
||||||
.It Ar striptag
|
.It Cm striptag
|
||||||
Strip the VLAN tags from the packets sent by the port.
|
Strip the VLAN tags from the packets sent by the port.
|
||||||
.It Ar -striptag
|
.It Fl striptag
|
||||||
Disable the strip VLAN tag option.
|
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.
|
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
|
After that, usually you need to reset the switch to learn different
|
||||||
MAC addresses.
|
MAC addresses.
|
||||||
.It Ar -firstlock
|
.It Fl firstlock
|
||||||
Disable the first lock option.
|
Disable the first lock option.
|
||||||
Note that sometimes you need to reset the
|
Note that sometimes you need to reset the
|
||||||
switch to really disable this option.
|
switch to really disable this option.
|
||||||
.It Ar dropuntagged
|
.It Cm dropuntagged
|
||||||
Drop packets without a VLAN tag.
|
Drop packets without a VLAN tag.
|
||||||
.It Ar -dropuntagged
|
.It Fl dropuntagged
|
||||||
Disable the drop untagged packets option.
|
Disable the drop untagged packets option.
|
||||||
.It Ar doubletag
|
.It Cm doubletag
|
||||||
Enable QinQ for the port.
|
Enable QinQ for the port.
|
||||||
.It Ar -doubletag
|
.It Fl doubletag
|
||||||
Disable QinQ for the port.
|
Disable QinQ for the port.
|
||||||
.It Ar ingress
|
.It Cm ingress
|
||||||
Enable the ingress filter on the port.
|
Enable the ingress filter on the port.
|
||||||
.It Ar -ingress
|
.It Fl ingress
|
||||||
Disable the ingress filter.
|
Disable the ingress filter.
|
||||||
.El
|
.El
|
||||||
.Ss reg
|
.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.
|
The vlangroup command selects one of the VLAN groups for configuration.
|
||||||
It supports the following commands:
|
It supports the following commands:
|
||||||
.Pp
|
.Pp
|
||||||
.Bl -tag -width ".Ar vlangroup" -compact
|
.Bl -tag -width ".Cm members" -compact
|
||||||
.It Ar vlan VID
|
.It Cm vlan Ar VID
|
||||||
Sets the VLAN ID (802.1q VID) for this VLAN group.
|
Sets the VLAN ID (802.1q VID) for this VLAN group.
|
||||||
Frames transmitted on tagged member ports of this group will be tagged
|
Frames transmitted on tagged member ports of this group will be tagged
|
||||||
with this VID.
|
with this VID.
|
||||||
Incoming frames carrying this tag will be forwarded according to the
|
Incoming frames carrying this tag will be forwarded according to the
|
||||||
configuration of this VLAN group.
|
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.
|
Configures which ports are to be a member of this VLAN group.
|
||||||
The port numbers are given as a comma-separated list.
|
The port numbers are given as a comma-separated list.
|
||||||
Each port can optionally be followed by
|
Each port can optionally be followed by
|
||||||
|
@ -83,6 +83,8 @@ struct cmds {
|
|||||||
};
|
};
|
||||||
static struct cmds 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.
|
* 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)");
|
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
|
static void
|
||||||
set_vlangroup_vid(struct cfg *cfg, char *argv[])
|
set_vlangroup_vid(struct cfg *cfg, char *argv[])
|
||||||
{
|
{
|
||||||
@ -334,10 +368,10 @@ set_register(struct cfg *cfg, char *arg)
|
|||||||
if (c==arg)
|
if (c==arg)
|
||||||
return (1);
|
return (1);
|
||||||
if (*c == '=') {
|
if (*c == '=') {
|
||||||
v = strtol(c+1, NULL, 0);
|
v = strtoul(c+1, NULL, 0);
|
||||||
write_register(cfg, a, v);
|
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);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,7 +391,7 @@ set_phyregister(struct cfg *cfg, char *arg)
|
|||||||
if (d == c)
|
if (d == c)
|
||||||
return (1);
|
return (1);
|
||||||
if (*c == '=') {
|
if (*c == '=') {
|
||||||
val = strtol(c+1, NULL, 0);
|
val = strtoul(c+1, NULL, 0);
|
||||||
write_phyregister(cfg, phy, reg, val);
|
write_phyregister(cfg, phy, reg, val);
|
||||||
}
|
}
|
||||||
printf("\treg %d.0x%02x=0x%04x\n", phy, reg, read_phyregister(cfg, phy, reg));
|
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);
|
printf("\tpvid: %d\n", p.es_pvid);
|
||||||
printb("\tflags", p.es_flags, ETHERSWITCH_PORT_FLAGS_BITS);
|
printb("\tflags", p.es_flags, ETHERSWITCH_PORT_FLAGS_BITS);
|
||||||
printf("\n");
|
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: ");
|
printf("\tmedia: ");
|
||||||
print_media_word(p.es_ifmr.ifm_current, 1);
|
print_media_word(p.es_ifmr.ifm_current, 1);
|
||||||
if (p.es_ifmr.ifm_active != p.es_ifmr.ifm_current) {
|
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");
|
"phy.register[=value]\n");
|
||||||
fprintf(stderr, "\tetherswitchcfg [-f control file] portX "
|
fprintf(stderr, "\tetherswitchcfg [-f control file] portX "
|
||||||
"[flags] command parameter\n");
|
"[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 "
|
fprintf(stderr, "\tetherswitchcfg [-f control file] reg "
|
||||||
"register[=value]\n");
|
"register[=value]\n");
|
||||||
fprintf(stderr, "\tetherswitchcfg [-f control file] vlangroupX "
|
fprintf(stderr, "\tetherswitchcfg [-f control file] vlangroupX "
|
||||||
@ -651,7 +692,7 @@ main(int argc, char *argv[])
|
|||||||
for(i=0; cmds[i].name != NULL; i++) {
|
for(i=0; cmds[i].name != NULL; i++) {
|
||||||
if (cfg.mode == cmds[i].mode && strcmp(argv[0], cmds[i].name) == 0) {
|
if (cfg.mode == cmds[i].mode && strcmp(argv[0], cmds[i].name) == 0) {
|
||||||
if (argc < (cmds[i].args + 1)) {
|
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;
|
break;
|
||||||
}
|
}
|
||||||
(cmds[i].f)(&cfg, argv);
|
(cmds[i].f)(&cfg, argv);
|
||||||
@ -691,6 +732,7 @@ static struct cmds cmds[] = {
|
|||||||
{ MODE_PORT, "pvid", 1, set_port_vid },
|
{ MODE_PORT, "pvid", 1, set_port_vid },
|
||||||
{ MODE_PORT, "media", 1, set_port_media },
|
{ MODE_PORT, "media", 1, set_port_media },
|
||||||
{ MODE_PORT, "mediaopt", 1, set_port_mediaopt },
|
{ 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, "-addtag", 0, set_port_flag },
|
{ MODE_PORT, "-addtag", 0, set_port_flag },
|
||||||
{ MODE_PORT, "ingress", 0, set_port_flag },
|
{ MODE_PORT, "ingress", 0, set_port_flag },
|
||||||
|
Loading…
Reference in New Issue
Block a user