Some switches can force link speed for a port. Let's add API that will
allow drivers to export this feature.
Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@48142
3c298f89-4303-0410-b956-
a3cf2f4a3e73
+swconfig_set_link(struct switch_dev *dev, const struct switch_attr *attr,
+ struct switch_val *val)
+{
+ if (!dev->ops->set_port_link)
+ return -EOPNOTSUPP;
+
+ return dev->ops->set_port_link(dev, val->port_vlan, val->value.link);
+}
+
+static int
swconfig_get_link(struct switch_dev *dev, const struct switch_attr *attr,
struct switch_val *val)
{
swconfig_get_link(struct switch_dev *dev, const struct switch_attr *attr,
struct switch_val *val)
{
.type = SWITCH_TYPE_LINK,
.name = "link",
.description = "Get port link information",
.type = SWITCH_TYPE_LINK,
.name = "link",
.description = "Get port link information",
+ .set = swconfig_set_link,
.get = swconfig_get_link,
}
};
.get = swconfig_get_link,
}
};
[SWITCH_PORT_FLAG_TAGGED] = { .type = NLA_FLAG },
};
[SWITCH_PORT_FLAG_TAGGED] = { .type = NLA_FLAG },
};
+static struct nla_policy link_policy[SWITCH_LINK_ATTR_MAX] = {
+ [SWITCH_LINK_FLAG_DUPLEX] = { .type = NLA_FLAG },
+ [SWITCH_LINK_FLAG_ANEG] = { .type = NLA_FLAG },
+ [SWITCH_LINK_SPEED] = { .type = NLA_U32 },
+};
+
static inline void
swconfig_lock(void)
{
static inline void
swconfig_lock(void)
{
+swconfig_parse_link(struct sk_buff *msg, struct nlattr *nla,
+ struct switch_port_link *link)
+{
+ struct nlattr *tb[SWITCH_LINK_ATTR_MAX + 1];
+
+ if (nla_parse_nested(tb, SWITCH_LINK_ATTR_MAX, nla, link_policy))
+ return -EINVAL;
+
+ link->duplex = !!tb[SWITCH_LINK_FLAG_DUPLEX];
+ link->aneg = !!tb[SWITCH_LINK_FLAG_ANEG];
+ link->speed = nla_get_u32(tb[SWITCH_LINK_SPEED]);
+
+ return 0;
+}
+
+static int
swconfig_set_attr(struct sk_buff *skb, struct genl_info *info)
{
const struct switch_attr *attr;
swconfig_set_attr(struct sk_buff *skb, struct genl_info *info)
{
const struct switch_attr *attr;
+ case SWITCH_TYPE_LINK:
+ val.value.link = &dev->linkbuf;
+ memset(&dev->linkbuf, 0, sizeof(struct switch_port_link));
+
+ if (info->attrs[SWITCH_ATTR_OP_VALUE_LINK]) {
+ err = swconfig_parse_link(skb,
+ info->attrs[SWITCH_ATTR_OP_VALUE_LINK],
+ val.value.link);
+ if (err < 0)
+ goto error;
+ } else {
+ val.len = 0;
+ err = 0;
+ }
+ break;
int (*get_port_link)(struct switch_dev *dev, int port,
struct switch_port_link *link);
int (*get_port_link)(struct switch_dev *dev, int port,
struct switch_port_link *link);
+ int (*set_port_link)(struct switch_dev *dev, int port,
+ struct switch_port_link *link);
int (*get_port_stats)(struct switch_dev *dev, int port,
struct switch_port_stats *stats);
};
int (*get_port_stats)(struct switch_dev *dev, int port,
struct switch_port_stats *stats);
};