summaryrefslogtreecommitdiffstats
path: root/target/linux/ar71xx/files
diff options
context:
space:
mode:
authorjuhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73>2010-01-20 20:36:30 +0000
committerjuhosg <juhosg@3c298f89-4303-0410-b956-a3cf2f4a3e73>2010-01-20 20:36:30 +0000
commit4162526b1d946f834024a5a53d10d00b23e714f4 (patch)
treedf8c3cfe626a2bf0aa2b01841d09fbf16f30fd73 /target/linux/ar71xx/files
parent4cff0253843c96e91893e185080b0197a763da30 (diff)
rtl8366_smi: simplify rtl8366_attr_get_port_link function
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@19250 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'target/linux/ar71xx/files')
-rw-r--r--target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c85
1 files changed, 33 insertions, 52 deletions
diff --git a/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c b/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c
index 20510724c..fe1659133 100644
--- a/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c
+++ b/target/linux/ar71xx/files/drivers/net/phy/rtl8366_smi.c
@@ -1275,71 +1275,52 @@ static int rtl8366_set_vlan(struct switch_dev *dev,
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,
const struct switch_attr *attr,
struct switch_val *val)
{
- u32 len = 0, data = 0;
- int speed, duplex, link, txpause, rxpause, nway;
struct rtl8366_smi *smi = sw_to_rtl8366(dev);
- char *buf = smi->buf;
+ u32 len = 0, data = 0;
if (val->port_vlan >= RTL8366_NUM_PORTS)
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 +
- (val->port_vlan >> 1),
- &data);
+ (val->port_vlan / 2), &data);
- if (val->port_vlan & 0x1)
+ if (val->port_vlan % 2)
data = data >> 8;
- speed = (data & RTL8366S_PORT_STATUS_SPEED_MASK);
- duplex = (data & RTL8366S_PORT_STATUS_DUPLEX_MASK) >> 2;
- link = (data & RTL8366S_PORT_STATUS_LINK_MASK) >> 4;
- txpause = (data & RTL8366S_PORT_STATUS_TXPAUSE_MASK) >> 5;
- rxpause = (data & RTL8366S_PORT_STATUS_RXPAUSE_MASK) >> 6;
- nway = (data & RTL8366S_PORT_STATUS_AN_MASK) >> 7;
-
- len += snprintf(buf + len, sizeof(smi->buf) - len, "Port %d: ",
- 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;
+ len = snprintf(smi->buf, sizeof(smi->buf),
+ "port:%d link:%s speed:%s %s-duplex %s%s%s",
+ val->port_vlan,
+ (data & RTL8366S_PORT_STATUS_LINK_MASK) ? "up" : "down",
+ rtl8366_speed_str(data &
+ 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 ": "");
+
+ val->value.s = smi->buf;
val->len = len;
return 0;