rtl8366_smi: simplify rtl8366_attr_get_port_link function

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@19250 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Gabor Juhos 2010-01-20 20:36:30 +00:00
parent fcff949054
commit a6c08e2f1e
1 changed files with 32 additions and 51 deletions

View File

@ -1275,71 +1275,52 @@ static int rtl8366_set_vlan(struct switch_dev *dev,
return rtl8366_vlan_set_4ktable(smi, val->value.i); return rtl8366_vlan_set_4ktable(smi, val->value.i);
} }
static const char *rtl8366_speed_str(unsigned speed)
{
switch (speed) {
case 0:
return "10baseT";
case 1:
return "100baseT";
case 2:
return "1000baseT";
}
return "unknown";
}
static int rtl8366_attr_get_port_link(struct switch_dev *dev, static int rtl8366_attr_get_port_link(struct switch_dev *dev,
const struct switch_attr *attr, const struct switch_attr *attr,
struct switch_val *val) struct switch_val *val)
{ {
u32 len = 0, data = 0;
int speed, duplex, link, txpause, rxpause, nway;
struct rtl8366_smi *smi = sw_to_rtl8366(dev); struct rtl8366_smi *smi = sw_to_rtl8366(dev);
char *buf = smi->buf; u32 len = 0, data = 0;
if (val->port_vlan >= RTL8366_NUM_PORTS) if (val->port_vlan >= RTL8366_NUM_PORTS)
return -EINVAL; return -EINVAL;
memset(buf, '\0', sizeof(smi->buf)); memset(smi->buf, '\0', sizeof(smi->buf));
rtl8366_smi_read_reg(smi, RTL8366S_PORT_LINK_STATUS_BASE + rtl8366_smi_read_reg(smi, RTL8366S_PORT_LINK_STATUS_BASE +
(val->port_vlan >> 1), (val->port_vlan / 2), &data);
&data);
if (val->port_vlan & 0x1) if (val->port_vlan % 2)
data = data >> 8; data = data >> 8;
speed = (data & RTL8366S_PORT_STATUS_SPEED_MASK); len = snprintf(smi->buf, sizeof(smi->buf),
duplex = (data & RTL8366S_PORT_STATUS_DUPLEX_MASK) >> 2; "port:%d link:%s speed:%s %s-duplex %s%s%s",
link = (data & RTL8366S_PORT_STATUS_LINK_MASK) >> 4; val->port_vlan,
txpause = (data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) >> 5; (data & RTL8366S_PORT_STATUS_LINK_MASK) ? "up" : "down",
rxpause = (data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) >> 6; rtl8366_speed_str(data &
nway = (data & RTL8366S_PORT_STATUS_AN_MASK) >> 7; RTL8366S_PORT_STATUS_SPEED_MASK),
(data & RTL8366S_PORT_STATUS_DUPLEX_MASK) ?
"full" : "half",
(data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) ?
"tx-pause ": "",
(data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) ?
"rx-pause " : "",
(data & RTL8366S_PORT_STATUS_AN_MASK) ? "nway ": "");
len += snprintf(buf + len, sizeof(smi->buf) - len, "Port %d: ", val->value.s = smi->buf;
val->port_vlan);
if (link)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"Link UP, Speed: ");
else
len += snprintf(buf + len, sizeof(smi->buf) - len,
"Link DOWN, Speed: ");
if (speed == 0)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"10Base-TX ");
else if (speed == 1)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"100Base-TX ");
else if (speed == 2)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"1000Base-TX ");
if (duplex)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"Full-Duplex, ");
else
len += snprintf(buf + len, sizeof(smi->buf) - len,
"Half-Duplex, ");
if (txpause)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"TX-Pause ");
if (rxpause)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"RX-Pause ");
if (nway)
len += snprintf(buf + len, sizeof(smi->buf) - len,
"nway ");
val->value.s = buf;
val->len = len; val->len = len;
return 0; return 0;