[OpenWrt-Devel] [PATCH][RFC] kernel: swconfig: add API for setting port link speed
Rafał Miłecki
zajec5 at gmail.com
Fri Dec 11 08:48:39 EST 2015
Some switches can force link speed for a port. Let's add API that will
allow driver to export this feature.
Signed-off-by: Rafał Miłecki <zajec5 at gmail.com>
---
.../linux/generic/files/drivers/net/phy/swconfig.c | 29 ++++++++++++++++++++++
target/linux/generic/files/include/linux/switch.h | 2 ++
2 files changed, 31 insertions(+)
diff --git a/target/linux/generic/files/drivers/net/phy/swconfig.c b/target/linux/generic/files/drivers/net/phy/swconfig.c
index 6bb3be1..58d6cf5 100644
--- a/target/linux/generic/files/drivers/net/phy/swconfig.c
+++ b/target/linux/generic/files/drivers/net/phy/swconfig.c
@@ -187,6 +187,34 @@ swconfig_get_link(struct switch_dev *dev, const struct switch_attr *attr,
}
static int
+swconfig_set_link(struct switch_dev *dev, const struct switch_attr *attr,
+ struct switch_val *val)
+{
+ enum switch_port_speed speed;
+ const char *s = val->value.s;
+ int len;
+
+ if (val->port_vlan >= dev->ports)
+ return -EINVAL;
+
+ if (!dev->ops->set_port_link)
+ return -EOPNOTSUPP;
+
+ len = strchrnul(s, ' ') - s;
+ if (!strncmp(s, "10", len)) {
+ speed = SWITCH_PORT_SPEED_10;
+ } else if (!strncmp(s, "100", len)) {
+ speed = SWITCH_PORT_SPEED_100;
+ } else if (!strncmp(s, "1000", len)) {
+ speed = SWITCH_PORT_SPEED_1000;
+ } else {
+ speed = SWITCH_PORT_SPEED_UNKNOWN;
+ }
+
+ return dev->ops->set_port_link(dev, val->port_vlan, speed);
+}
+
+static int
swconfig_apply_config(struct switch_dev *dev, const struct switch_attr *attr,
struct switch_val *val)
{
@@ -251,6 +279,7 @@ static struct switch_attr default_port[] = {
.description = "Get port link information",
.set = NULL,
.get = swconfig_get_link,
+ .set = swconfig_set_link,
}
};
diff --git a/target/linux/generic/files/include/linux/switch.h b/target/linux/generic/files/include/linux/switch.h
index 4291364..e21fb05 100644
--- a/target/linux/generic/files/include/linux/switch.h
+++ b/target/linux/generic/files/include/linux/switch.h
@@ -95,6 +95,8 @@ struct switch_dev_ops {
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,
+ enum switch_port_speed speed);
int (*get_port_stats)(struct switch_dev *dev, int port,
struct switch_port_stats *stats);
};
--
1.8.4.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list