generic: rtl8367: use the generic get_port_link implementation

git-svn-id: svn://svn.openwrt.org/openwrt/trunk@30844 3c298f89-4303-0410-b956-a3cf2f4a3e73
master
Gabor Juhos 2012-03-07 16:32:40 +00:00
parent 79095804dc
commit 99d475bceb
1 changed files with 28 additions and 47 deletions

View 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)