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

John Crispin blogic at openwrt.org
Sat Dec 12 01:54:38 EST 2015


Hi Rafał,

in addition to the comment i made last night, i found another possible
issue. see below.

On 11/12/2015 14:48, Rafał Miłecki wrote:
> 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);

this makes the assumption, that all drivers always add the
set_port_link() callback and uses it unconditionally. i am impartial on
how this is solved in detail as long as some kind of check is added

	John

> +}
> +
> +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);
>  };
> 
_______________________________________________
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