X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fstaging%2Fyousong.git;a=blobdiff_plain;f=target%2Flinux%2Fgeneric%2Ffiles%2Fdrivers%2Fnet%2Fphy%2Fswconfig.c;h=07efda05ebc772590b008942a2f7eee59972b598;hp=ba9136c34f4feb2eafbaa4e978a6699446ba8303;hb=71cd537a8a5b6310524a113a6ff53b272d19ff4e;hpb=100e795bccaccd50aa9ad3835fc293b241f28b07 diff --git a/target/linux/generic/files/drivers/net/phy/swconfig.c b/target/linux/generic/files/drivers/net/phy/swconfig.c index ba9136c34f..07efda05eb 100644 --- a/target/linux/generic/files/drivers/net/phy/swconfig.c +++ b/target/linux/generic/files/drivers/net/phy/swconfig.c @@ -127,30 +127,11 @@ swconfig_get_pvid(struct switch_dev *dev, const struct switch_attr *attr, return dev->ops->get_port_pvid(dev, val->port_vlan, &val->value.i); } -static const char * -swconfig_speed_str(enum switch_port_speed speed) -{ - switch (speed) { - case SWITCH_PORT_SPEED_10: - return "10baseT"; - case SWITCH_PORT_SPEED_100: - return "100baseT"; - case SWITCH_PORT_SPEED_1000: - return "1000baseT"; - default: - break; - } - - return "unknown"; -} - static int swconfig_get_link(struct switch_dev *dev, const struct switch_attr *attr, struct switch_val *val) { - struct switch_port_link link; - int len; - int ret; + struct switch_port_link *link = val->value.link; if (val->port_vlan >= dev->ports) return -EINVAL; @@ -158,30 +139,8 @@ swconfig_get_link(struct switch_dev *dev, const struct switch_attr *attr, if (!dev->ops->get_port_link) return -EOPNOTSUPP; - memset(&link, 0, sizeof(link)); - ret = dev->ops->get_port_link(dev, val->port_vlan, &link); - if (ret) - return ret; - - memset(dev->buf, 0, sizeof(dev->buf)); - - if (link.link) - len = snprintf(dev->buf, sizeof(dev->buf), - "port:%d link:up speed:%s %s-duplex %s%s%s", - val->port_vlan, - swconfig_speed_str(link.speed), - link.duplex ? "full" : "half", - link.tx_flow ? "txflow " : "", - link.rx_flow ? "rxflow " : "", - link.aneg ? "auto" : ""); - else - len = snprintf(dev->buf, sizeof(dev->buf), "port:%d link:down", - val->port_vlan); - - val->value.s = dev->buf; - val->len = len; - - return 0; + memset(link, 0, sizeof(*link)); + return dev->ops->get_port_link(dev, val->port_vlan, link); } static int @@ -244,7 +203,7 @@ static struct switch_attr default_port[] = { .get = swconfig_get_pvid, }, [PORT_LINK] = { - .type = SWITCH_TYPE_STRING, + .type = SWITCH_TYPE_LINK, .name = "link", .description = "Get port link information", .set = NULL, @@ -394,7 +353,8 @@ swconfig_dump_attr(struct swconfig_callback *cb, void *arg) op->description)) goto nla_put_failure; - return genlmsg_end(msg, hdr); + genlmsg_end(msg, hdr); + return msg->len; nla_put_failure: genlmsg_cancel(msg, hdr); return -EMSGSIZE; @@ -767,6 +727,53 @@ done: return err; } +static int +swconfig_send_link(struct sk_buff *msg, struct genl_info *info, int attr, + const struct switch_port_link *link) +{ + struct nlattr *p = NULL; + int err = 0; + + p = nla_nest_start(msg, attr); + if (link->link) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_LINK)) + goto nla_put_failure; + } + if (link->duplex) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_DUPLEX)) + goto nla_put_failure; + } + if (link->aneg) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_ANEG)) + goto nla_put_failure; + } + if (link->tx_flow) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_TX_FLOW)) + goto nla_put_failure; + } + if (link->rx_flow) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_RX_FLOW)) + goto nla_put_failure; + } + if (nla_put_u32(msg, SWITCH_LINK_SPEED, link->speed)) + goto nla_put_failure; + if (link->eee & ADVERTISED_100baseT_Full) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_EEE_100BASET)) + goto nla_put_failure; + } + if (link->eee & ADVERTISED_1000baseT_Full) { + if (nla_put_flag(msg, SWITCH_LINK_FLAG_EEE_1000BASET)) + goto nla_put_failure; + } + nla_nest_end(msg, p); + + return err; + +nla_put_failure: + nla_nest_cancel(msg, p); + return -1; +} + static int swconfig_get_attr(struct sk_buff *skb, struct genl_info *info) { @@ -791,6 +798,9 @@ swconfig_get_attr(struct sk_buff *skb, struct genl_info *info) val.value.ports = dev->portbuf; memset(dev->portbuf, 0, sizeof(struct switch_port) * dev->ports); + } else if (attr->type == SWITCH_TYPE_LINK) { + val.value.link = &dev->linkbuf; + memset(&dev->linkbuf, 0, sizeof(struct switch_port_link)); } err = attr->get(dev, attr, &val); @@ -821,12 +831,19 @@ swconfig_get_attr(struct sk_buff *skb, struct genl_info *info) if (err < 0) goto nla_put_failure; break; + case SWITCH_TYPE_LINK: + err = swconfig_send_link(msg, info, + SWITCH_ATTR_OP_VALUE_LINK, val.value.link); + if (err < 0) + goto nla_put_failure; + break; default: pr_debug("invalid type in attribute\n"); err = -EINVAL; goto error; } - err = genlmsg_end(msg, hdr); + genlmsg_end(msg, hdr); + err = msg->len; if (err < 0) goto nla_put_failure; @@ -889,7 +906,8 @@ swconfig_send_switch(struct sk_buff *msg, u32 pid, u32 seq, int flags, nla_nest_end(msg, p); } nla_nest_end(msg, m); - return genlmsg_end(msg, hdr); + genlmsg_end(msg, hdr); + return msg->len; nla_put_failure: genlmsg_cancel(msg, hdr); return -EMSGSIZE; @@ -1079,7 +1097,7 @@ register_switch(struct switch_dev *dev, struct net_device *netdev) /* fill device name */ snprintf(dev->devname, IFNAMSIZ, SWCONFIG_DEVNAME, i); - list_add(&dev->dev_list, &swdevs); + list_add_tail(&dev->dev_list, &swdevs); swconfig_unlock(); err = swconfig_create_led_trigger(dev);