generic: rtl8367: use the generic get_port_link implementation
authorGabor Juhos <juhosg@openwrt.org>
Wed, 7 Mar 2012 16:32:40 +0000 (16:32 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Wed, 7 Mar 2012 16:32:40 +0000 (16:32 +0000)
SVN-Revision: 30844

target/linux/generic/files/drivers/net/phy/rtl8367.c

index 152b06a95665396dcaafbc5991c0685e25d5c81c..917976e3020b38cfc060450652a8d6fee8a094b5 100644 (file)
@@ -1376,56 +1376,43 @@ static int rtl8367_sw_reset_mibs(struct switch_dev *dev,
                                RTL8367_MIB_CTRL_GLOBAL_RESET_MASK);
 }
 
-static const char *rtl8367_speed_str(unsigned speed)
-{
-       switch (speed) {
-       case RTL8367_PORT_STATUS_SPEED_10:
-               return "10baseT";
-       case RTL8367_PORT_STATUS_SPEED_100:
-               return "100baseT";
-       case RTL8367_PORT_STATUS_SPEED_1000:
-               return "1000baseT";
-       }
-
-       return "unknown";
-}
-
 static int rtl8367_sw_get_port_link(struct switch_dev *dev,
-                                    const struct switch_attr *attr,
-                                    struct switch_val *val)
+                                   int port,
+                                   struct switch_port_link *link)
 {
        struct rtl8366_smi *smi = sw_to_rtl8366_smi(dev);
-       u32 len = 0, data = 0;
-       int port;
+       u32 data = 0;
+       u32 speed;
 
-       port = val->port_vlan;
        if (port >= RTL8367_NUM_PORTS)
                return -EINVAL;
 
-       memset(smi->buf, '\0', sizeof(smi->buf));
        rtl8366_smi_read_reg(smi, RTL8367_PORT_STATUS_REG(port), &data);
 
-       if (data & RTL8367_PORT_STATUS_LINK) {
-               len = snprintf(smi->buf, sizeof(smi->buf),
-                               "port:%d link:up speed:%s %s-duplex %s%s%s",
-                               port,
-                               rtl8367_speed_str(data &
-                                         RTL8367_PORT_STATUS_SPEED_MASK),
-                               (data & RTL8367_PORT_STATUS_DUPLEX) ?
-                                       "full" : "half",
-                               (data & RTL8367_PORT_STATUS_TXPAUSE) ?
-                                       "tx-pause ": "",
-                               (data & RTL8367_PORT_STATUS_RXPAUSE) ?
-                                       "rx-pause " : "",
-                               (data & RTL8367_PORT_STATUS_NWAY) ?
-                                       "nway ": "");
-       } else {
-               len = snprintf(smi->buf, sizeof(smi->buf), "port:%d link:down",
-                               port);
-       }
+       link->link = !!(data & RTL8367_PORT_STATUS_LINK);
+       if (!link->link)
+               return 0;
 
-       val->value.s = smi->buf;
-       val->len = len;
+       link->duplex = !!(data & RTL8367_PORT_STATUS_DUPLEX);
+       link->rx_flow = !!(data & RTL8367_PORT_STATUS_RXPAUSE);
+       link->tx_flow = !!(data & RTL8367_PORT_STATUS_TXPAUSE);
+       link->aneg = !!(data & RTL8367_PORT_STATUS_NWAY);
+
+       speed = (data & RTL8367_PORT_STATUS_SPEED_MASK);
+       switch (speed) {
+       case 0:
+               link->speed = SWITCH_PORT_SPEED_10;
+               break;
+       case 1:
+               link->speed = SWITCH_PORT_SPEED_100;
+               break;
+       case 2:
+               link->speed = SWITCH_PORT_SPEED_1000;
+               break;
+       default:
+               link->speed = SWITCH_PORT_SPEED_UNKNOWN;
+               break;
+       }
 
        return 0;
 }
@@ -1548,13 +1535,6 @@ static struct switch_attr rtl8367_globals[] = {
 
 static struct switch_attr rtl8367_port[] = {
        {
-               .type = SWITCH_TYPE_STRING,
-               .name = "link",
-               .description = "Get port link information",
-               .max = 1,
-               .set = NULL,
-               .get = rtl8367_sw_get_port_link,
-       }, {
                .type = SWITCH_TYPE_NOVAL,
                .name = "reset_mib",
                .description = "Reset single port MIB counters",
@@ -1599,6 +1579,7 @@ static const struct switch_dev_ops rtl8366m_ops = {
        .get_port_pvid = rtl8366_sw_get_port_pvid,
        .set_port_pvid = rtl8366_sw_set_port_pvid,
        .reset_switch = rtl8367_sw_reset_switch,
+       .get_port_link = rtl8367_sw_get_port_link,
 };
 
 static int rtl8367_switch_init(struct rtl8366_smi *smi)