diff mbox series

[net-next,RFC,05/10] devlink: add port to line card relationship set

Message ID 20210113121222.733517-6-jiri@resnulli.us (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series introduce line card support for modular switch | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers warning 1 maintainers not CCed: jiri@nvidia.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit fail Errors and warnings before: 492 this patch: 492
netdev/kdoc fail Errors and warnings before: 31 this patch: 33
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 58 lines checked
netdev/build_allmodconfig_warn fail Errors and warnings before: 682 this patch: 682
netdev/header_inline success Link
netdev/stable success Stable not CCed

Commit Message

Jiri Pirko Jan. 13, 2021, 12:12 p.m. UTC
From: Jiri Pirko <jiri@nvidia.com>

In order to properly inform user about relationship between port and
line card, introduce a driver API to set line card for a port. Use this
information to extend port devlink netlink message by line card index
and also include the line card index into phys_port_name and by that
into a netdevice name.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
---
 include/net/devlink.h |  3 +++
 net/core/devlink.c    | 25 ++++++++++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

Comments

Ido Schimmel Jan. 15, 2021, 4:10 p.m. UTC | #1
On Wed, Jan 13, 2021 at 01:12:17PM +0100, Jiri Pirko wrote:
> index ec00cd94c626..cb911b6fdeda 100644
> --- a/include/net/devlink.h
> +++ b/include/net/devlink.h
> @@ -137,6 +137,7 @@ struct devlink_port {
>  	struct delayed_work type_warn_dw;
>  	struct list_head reporter_list;
>  	struct mutex reporters_lock; /* Protects reporter_list */
> +	struct devlink_linecard *linecard;
>  };
>  
>  struct devlink_linecard_ops;
> @@ -1438,6 +1439,8 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro
>  				   u16 pf, bool external);
>  void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
>  				   u16 pf, u16 vf, bool external);
> +void devlink_port_linecard_set(struct devlink_port *devlink_port,
> +			       struct devlink_linecard *linecard);
>  struct devlink_linecard *
>  devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index,
>  			const struct devlink_linecard_ops *ops, void *priv);
> diff --git a/net/core/devlink.c b/net/core/devlink.c
> index 347976b88404..2faa30cc5cce 100644
> --- a/net/core/devlink.c
> +++ b/net/core/devlink.c
> @@ -855,6 +855,10 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
>  		goto nla_put_failure;
>  	if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
>  		goto nla_put_failure;
> +	if (devlink_port->linecard &&
> +	    nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX,
> +			devlink_port->linecard->index))
> +		goto nla_put_failure;
>  
>  	genlmsg_end(msg, hdr);
>  	return 0;
> @@ -8642,6 +8646,21 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
>  }
>  EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
>  
> +/**
> + *	devlink_port_linecard_set - Link port with a linecard
> + *
> + *	@devlink_port: devlink port
> + *	@devlink_linecard: devlink linecard
> + */
> +void devlink_port_linecard_set(struct devlink_port *devlink_port,
> +			       struct devlink_linecard *linecard)
> +{
> +	if (WARN_ON(devlink_port->registered))
> +		return;
> +	devlink_port->linecard = linecard;

We already have devlink_port_attrs_set() that is called before the port
is registered, why not extend it to also set the linecard information?

> +}
> +EXPORT_SYMBOL_GPL(devlink_port_linecard_set);
> +
>  static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
>  					     char *name, size_t len)
>  {
> @@ -8654,7 +8673,11 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
>  	switch (attrs->flavour) {
>  	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
>  	case DEVLINK_PORT_FLAVOUR_VIRTUAL:
> -		n = snprintf(name, len, "p%u", attrs->phys.port_number);
> +		if (devlink_port->linecard)
> +			n = snprintf(name, len, "l%u",
> +				     devlink_port->linecard->index);
> +		n += snprintf(name + n, len - n, "p%u",
> +			      attrs->phys.port_number);
>  		if (attrs->split)
>  			n += snprintf(name + n, len - n, "s%u",
>  				      attrs->phys.split_subport_number);
> -- 
> 2.26.2
>
Jiri Pirko Jan. 15, 2021, 4:53 p.m. UTC | #2
Fri, Jan 15, 2021 at 05:10:48PM CET, idosch@idosch.org wrote:
>On Wed, Jan 13, 2021 at 01:12:17PM +0100, Jiri Pirko wrote:
>> index ec00cd94c626..cb911b6fdeda 100644
>> --- a/include/net/devlink.h
>> +++ b/include/net/devlink.h
>> @@ -137,6 +137,7 @@ struct devlink_port {
>>  	struct delayed_work type_warn_dw;
>>  	struct list_head reporter_list;
>>  	struct mutex reporters_lock; /* Protects reporter_list */
>> +	struct devlink_linecard *linecard;
>>  };
>>  
>>  struct devlink_linecard_ops;
>> @@ -1438,6 +1439,8 @@ void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro
>>  				   u16 pf, bool external);
>>  void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
>>  				   u16 pf, u16 vf, bool external);
>> +void devlink_port_linecard_set(struct devlink_port *devlink_port,
>> +			       struct devlink_linecard *linecard);
>>  struct devlink_linecard *
>>  devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index,
>>  			const struct devlink_linecard_ops *ops, void *priv);
>> diff --git a/net/core/devlink.c b/net/core/devlink.c
>> index 347976b88404..2faa30cc5cce 100644
>> --- a/net/core/devlink.c
>> +++ b/net/core/devlink.c
>> @@ -855,6 +855,10 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
>>  		goto nla_put_failure;
>>  	if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
>>  		goto nla_put_failure;
>> +	if (devlink_port->linecard &&
>> +	    nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX,
>> +			devlink_port->linecard->index))
>> +		goto nla_put_failure;
>>  
>>  	genlmsg_end(msg, hdr);
>>  	return 0;
>> @@ -8642,6 +8646,21 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
>>  }
>>  EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
>>  
>> +/**
>> + *	devlink_port_linecard_set - Link port with a linecard
>> + *
>> + *	@devlink_port: devlink port
>> + *	@devlink_linecard: devlink linecard
>> + */
>> +void devlink_port_linecard_set(struct devlink_port *devlink_port,
>> +			       struct devlink_linecard *linecard)
>> +{
>> +	if (WARN_ON(devlink_port->registered))
>> +		return;
>> +	devlink_port->linecard = linecard;
>
>We already have devlink_port_attrs_set() that is called before the port
>is registered, why not extend it to also set the linecard information?

I was thinking about that. Looked odd to put the linecard pointer to the
attr struct. I like it better this way. But if you insist.


>
>> +}
>> +EXPORT_SYMBOL_GPL(devlink_port_linecard_set);
>> +
>>  static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
>>  					     char *name, size_t len)
>>  {
>> @@ -8654,7 +8673,11 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
>>  	switch (attrs->flavour) {
>>  	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
>>  	case DEVLINK_PORT_FLAVOUR_VIRTUAL:
>> -		n = snprintf(name, len, "p%u", attrs->phys.port_number);
>> +		if (devlink_port->linecard)
>> +			n = snprintf(name, len, "l%u",
>> +				     devlink_port->linecard->index);
>> +		n += snprintf(name + n, len - n, "p%u",
>> +			      attrs->phys.port_number);
>>  		if (attrs->split)
>>  			n += snprintf(name + n, len - n, "s%u",
>>  				      attrs->phys.split_subport_number);
>> -- 
>> 2.26.2
>>
diff mbox series

Patch

diff --git a/include/net/devlink.h b/include/net/devlink.h
index ec00cd94c626..cb911b6fdeda 100644
--- a/include/net/devlink.h
+++ b/include/net/devlink.h
@@ -137,6 +137,7 @@  struct devlink_port {
 	struct delayed_work type_warn_dw;
 	struct list_head reporter_list;
 	struct mutex reporters_lock; /* Protects reporter_list */
+	struct devlink_linecard *linecard;
 };
 
 struct devlink_linecard_ops;
@@ -1438,6 +1439,8 @@  void devlink_port_attrs_pci_pf_set(struct devlink_port *devlink_port, u32 contro
 				   u16 pf, bool external);
 void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 controller,
 				   u16 pf, u16 vf, bool external);
+void devlink_port_linecard_set(struct devlink_port *devlink_port,
+			       struct devlink_linecard *linecard);
 struct devlink_linecard *
 devlink_linecard_create(struct devlink *devlink, unsigned int linecard_index,
 			const struct devlink_linecard_ops *ops, void *priv);
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 347976b88404..2faa30cc5cce 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -855,6 +855,10 @@  static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
 		goto nla_put_failure;
 	if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
 		goto nla_put_failure;
+	if (devlink_port->linecard &&
+	    nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX,
+			devlink_port->linecard->index))
+		goto nla_put_failure;
 
 	genlmsg_end(msg, hdr);
 	return 0;
@@ -8642,6 +8646,21 @@  void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
 }
 EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_vf_set);
 
+/**
+ *	devlink_port_linecard_set - Link port with a linecard
+ *
+ *	@devlink_port: devlink port
+ *	@devlink_linecard: devlink linecard
+ */
+void devlink_port_linecard_set(struct devlink_port *devlink_port,
+			       struct devlink_linecard *linecard)
+{
+	if (WARN_ON(devlink_port->registered))
+		return;
+	devlink_port->linecard = linecard;
+}
+EXPORT_SYMBOL_GPL(devlink_port_linecard_set);
+
 static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 					     char *name, size_t len)
 {
@@ -8654,7 +8673,11 @@  static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
 	switch (attrs->flavour) {
 	case DEVLINK_PORT_FLAVOUR_PHYSICAL:
 	case DEVLINK_PORT_FLAVOUR_VIRTUAL:
-		n = snprintf(name, len, "p%u", attrs->phys.port_number);
+		if (devlink_port->linecard)
+			n = snprintf(name, len, "l%u",
+				     devlink_port->linecard->index);
+		n += snprintf(name + n, len - n, "p%u",
+			      attrs->phys.port_number);
 		if (attrs->split)
 			n += snprintf(name + n, len - n, "s%u",
 				      attrs->phys.split_subport_number);