[OpenWrt-Devel] [PATCH] kernel: swconfig: add API for setting port link speed

Rafał Miłecki zajec5 at gmail.com
Sat Dec 12 08:07:42 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>
---
Changes in V1 (from RFC):
* Remove .set = NULL,
* Update description
---
 .../linux/generic/files/drivers/net/phy/swconfig.c | 32 ++++++++++++++++++++--
 target/linux/generic/files/include/linux/switch.h  |  2 ++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/target/linux/generic/files/drivers/net/phy/swconfig.c b/target/linux/generic/files/drivers/net/phy/swconfig.c
index 6bb3be1..52b8a94 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)
 {
@@ -248,8 +276,8 @@ static struct switch_attr default_port[] = {
 	[PORT_LINK] = {
 		.type = SWITCH_TYPE_STRING,
 		.name = "link",
-		.description = "Get port link information",
-		.set = NULL,
+		.description = "Port link",
+		.set = swconfig_set_link,
 		.get = swconfig_get_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