diff mbox series

[net-next,v2,5/9] devlink: Add a new devlink port lanes attribute and pass to netlink

Message ID 20200701143251.456693-6-idosch@idosch.org
State Changes Requested
Delegated to: David Miller
Headers show
Series devlink: Expose port split attributes | expand

Commit Message

Ido Schimmel July 1, 2020, 2:32 p.m. UTC
From: Danielle Ratson <danieller@mellanox.com>

Add a new devlink port attribute that indicates the port's number of lanes.

Drivers are expected to set it via devlink_port_attrs_set(), before
registering the port.

The attribute is not passed to user space in case the number of lanes is
invalid (0).

Signed-off-by: Danielle Ratson <danieller@mellanox.com>
Reviewed-by: Jiri Pirko <jiri@mellanox.com>
Signed-off-by: Ido Schimmel <idosch@mellanox.com>
---
 drivers/net/ethernet/mellanox/mlxsw/core.c | 1 +
 include/net/devlink.h                      | 3 +++
 include/uapi/linux/devlink.h               | 2 ++
 net/core/devlink.c                         | 4 ++++
 4 files changed, 10 insertions(+)

Comments

Jakub Kicinski July 1, 2020, 6:54 p.m. UTC | #1
On Wed,  1 Jul 2020 17:32:47 +0300 Ido Schimmel wrote:
> diff --git a/include/net/devlink.h b/include/net/devlink.h
> index 8f9db991192d..91752b79bb29 100644
> --- a/include/net/devlink.h
> +++ b/include/net/devlink.h
> @@ -68,10 +68,13 @@ struct devlink_port_pci_vf_attrs {
>   * struct devlink_port_attrs - devlink port object
>   * @flavour: flavour of the port
>   * @split: indicates if this is split port
> + * @lanes: maximum number of lanes the port supports.
> + *	   0 value is not passed to netlink and valid number is a power of 2.

Why power of two? what about 100G R10?

>   * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
>   */
>  struct devlink_port_attrs {
>  	u8 split:1;
> +	u32 lanes;
>  	enum devlink_port_flavour flavour;
>  	struct netdev_phys_item_id switch_id;
>  	union {
Danielle Ratson July 2, 2020, 7:57 a.m. UTC | #2
On 7/1/2020 9:54 PM, Jakub Kicinski wrote:
> On Wed,  1 Jul 2020 17:32:47 +0300 Ido Schimmel wrote:
>> diff --git a/include/net/devlink.h b/include/net/devlink.h
>> index 8f9db991192d..91752b79bb29 100644
>> --- a/include/net/devlink.h
>> +++ b/include/net/devlink.h
>> @@ -68,10 +68,13 @@ struct devlink_port_pci_vf_attrs {
>>   * struct devlink_port_attrs - devlink port object
>>   * @flavour: flavour of the port
>>   * @split: indicates if this is split port
>> + * @lanes: maximum number of lanes the port supports.
>> + *	   0 value is not passed to netlink and valid number is a power of 2.
> Why power of two? what about 100G R10?


Missed that, thanks.


>
>>   * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
>>   */
>>  struct devlink_port_attrs {
>>  	u8 split:1;
>> +	u32 lanes;
>>  	enum devlink_port_flavour flavour;
>>  	struct netdev_phys_item_id switch_id;
>>  	union {
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mellanox/mlxsw/core.c b/drivers/net/ethernet/mellanox/mlxsw/core.c
index f44cb1a537f3..6cde196f6b70 100644
--- a/drivers/net/ethernet/mellanox/mlxsw/core.c
+++ b/drivers/net/ethernet/mellanox/mlxsw/core.c
@@ -2134,6 +2134,7 @@  static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,
 	int err;
 
 	attrs.split = split;
+	attrs.lanes = lanes;
 	attrs.flavour = flavour;
 	attrs.phys.port_number = port_number;
 	attrs.phys.split_subport_number = split_port_subnumber;
diff --git a/include/net/devlink.h b/include/net/devlink.h
index 8f9db991192d..91752b79bb29 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -68,10 +68,13 @@  struct devlink_port_pci_vf_attrs {
  * struct devlink_port_attrs - devlink port object
  * @flavour: flavour of the port
  * @split: indicates if this is split port
+ * @lanes: maximum number of lanes the port supports.
+ *	   0 value is not passed to netlink and valid number is a power of 2.
  * @switch_id: if the port is part of switch, this is buffer with ID, otherwise this is NULL
  */
 struct devlink_port_attrs {
 	u8 split:1;
+	u32 lanes;
 	enum devlink_port_flavour flavour;
 	struct netdev_phys_item_id switch_id;
 	union {
diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
index 87c83a82991b..f741ab8d9cf0 100644
--- a/include/uapi/linux/devlink.h
+++ b/include/uapi/linux/devlink.h
@@ -455,6 +455,8 @@  enum devlink_attr {
 
 	DEVLINK_ATTR_INFO_BOARD_SERIAL_NUMBER,	/* string */
 
+	DEVLINK_ATTR_PORT_LANES,			/* u32 */
+
 	/* add new attributes above here, update the policy in devlink.c */
 
 	__DEVLINK_ATTR_MAX,
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 266936c38357..7f26d1054974 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -530,6 +530,10 @@  static int devlink_nl_port_attrs_put(struct sk_buff *msg,
 
 	if (!devlink_port->attrs_set)
 		return 0;
+	if (attrs->lanes) {
+		if (nla_put_u32(msg, DEVLINK_ATTR_PORT_LANES, attrs->lanes))
+			return -EMSGSIZE;
+	}
 	if (nla_put_u16(msg, DEVLINK_ATTR_PORT_FLAVOUR, attrs->flavour))
 		return -EMSGSIZE;
 	switch (devlink_port->attrs.flavour) {