diff mbox series

[net-next,1/2] nfp: initialize netdev's dev_port with correct id

Message ID 20230329144548.66708-2-louis.peens@corigine.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series Small series of enhancements | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 18 this patch: 18
netdev/cc_maintainers warning 1 maintainers not CCed: edumazet@google.com
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 18 this patch: 18
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Louis Peens March 29, 2023, 2:45 p.m. UTC
From: Yinjun Zhang <yinjun.zhang@corigine.com>

`dev_port` is used to differentiate devices that share the same
function, which is the case in most of NFP NICs.

In some customized scenario, `dev_port` is used to rename netdev
instead of `phys_port_name`, which requires to initialize it
correctly to get expected netdev name.

Example rules using `dev_port`:

  SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:e1:00.0", ATTR{dev_port}=="0", NAME:="ens8np0"
  SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:e1:00.0", ATTR{dev_port}=="1", NAME:="ens8np1"

Signed-off-by: Yinjun Zhang <yinjun.zhang@corigine.com>
Acked-by: Simon Horman <simon.horman@corigine.com>
Signed-off-by: Louis Peens <louis.peens@corigine.com>
---
 drivers/net/ethernet/netronome/nfp/nfp_port.c | 1 +
 1 file changed, 1 insertion(+)

Comments

Leon Romanovsky March 29, 2023, 6:49 p.m. UTC | #1
On Wed, Mar 29, 2023 at 04:45:47PM +0200, Louis Peens wrote:
> From: Yinjun Zhang <yinjun.zhang@corigine.com>
> 
> `dev_port` is used to differentiate devices that share the same
> function, which is the case in most of NFP NICs.

And how did it work without dev_port?
I have no idea what does it mean "different devices that share the same
function".

Thanks

> 
> In some customized scenario, `dev_port` is used to rename netdev
> instead of `phys_port_name`, which requires to initialize it
> correctly to get expected netdev name.
> 
> Example rules using `dev_port`:
> 
>   SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:e1:00.0", ATTR{dev_port}=="0", NAME:="ens8np0"
>   SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:e1:00.0", ATTR{dev_port}=="1", NAME:="ens8np1"
> 
> Signed-off-by: Yinjun Zhang <yinjun.zhang@corigine.com>
> Acked-by: Simon Horman <simon.horman@corigine.com>
> Signed-off-by: Louis Peens <louis.peens@corigine.com>
> ---
>  drivers/net/ethernet/netronome/nfp/nfp_port.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.c b/drivers/net/ethernet/netronome/nfp/nfp_port.c
> index 4f2308570dcf..54640bcb70fb 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfp_port.c
> +++ b/drivers/net/ethernet/netronome/nfp/nfp_port.c
> @@ -189,6 +189,7 @@ int nfp_port_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
>  
>  	port->eth_port = &pf->eth_tbl->ports[id];
>  	port->eth_id = pf->eth_tbl->ports[id].index;
> +	port->netdev->dev_port = id;
>  	if (pf->mac_stats_mem)
>  		port->eth_stats =
>  			pf->mac_stats_mem + port->eth_id * NFP_MAC_STATS_SIZE;
> -- 
> 2.34.1
>
Jakub Kicinski March 29, 2023, 7:22 p.m. UTC | #2
On Wed, 29 Mar 2023 16:45:47 +0200 Louis Peens wrote:
> In some customized scenario, `dev_port` is used to rename netdev
> instead of `phys_port_name`, which requires to initialize it
> correctly to get expected netdev name.

What do you mean by "which requires to initialize it correctly to get
expected netdev name." ?
Yinjun Zhang March 30, 2023, 1:32 a.m. UTC | #3
On Wed, 29 Mar 2023 21:49:59 +0300, Leon Romanovsky wrote:
> On Wed, Mar 29, 2023 at 04:45:47PM +0200, Louis Peens wrote:
> > From: Yinjun Zhang <yinjun.zhang@corigine.com>
> >
> > `dev_port` is used to differentiate devices that share the same
> > function, which is the case in most of NFP NICs.
> 
> And how did it work without dev_port?

No functionality fault, just cannot rename netdev as expected when the
udev rules use `dev_port` attribute as the example below.

> I have no idea what does it mean "different devices that share the same
> function".

That's how it's commented for the `dev_port` field of struct netdev:
*      @dev_port:              Used to differentiate devices that share
*                              the same function
I think it's used when single pci function instantiates more than one netdev.
Ref: 3f85944fe207 ("net: Add sysfs file for port number")

> 
> Thanks
> 
> >
> > In some customized scenario, `dev_port` is used to rename netdev
> > instead of `phys_port_name`, which requires to initialize it
> > correctly to get expected netdev name.
> >
> > Example rules using `dev_port`:
> >
> >   SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:e1:00.0",
> ATTR{dev_port}=="0", NAME:="ens8np0"
> >   SUBSYSTEM=="net", ACTION=="add", KERNELS=="0000:e1:00.0",
> ATTR{dev_port}=="1", NAME:="ens8np1"
> >
Yinjun Zhang March 30, 2023, 1:40 a.m. UTC | #4
On Wed, 29 Mar 2023 12:22:27 -0700, Jakub Kicinski wrote:
> On Wed, 29 Mar 2023 16:45:47 +0200 Louis Peens wrote:
> > In some customized scenario, `dev_port` is used to rename netdev
> > instead of `phys_port_name`, which requires to initialize it
> > correctly to get expected netdev name.
> 
> What do you mean by "which requires to initialize it correctly to get
> expected netdev name." ?

I mean it cannot be renamed by udev rules as expected if `dev_port`
is not correctly initialized, because the second port doesn't match
'ATTR{dev_port}=="1"'.
Jakub Kicinski March 30, 2023, 2:38 a.m. UTC | #5
On Thu, 30 Mar 2023 01:40:30 +0000 Yinjun Zhang wrote:
> On Wed, 29 Mar 2023 12:22:27 -0700, Jakub Kicinski wrote:
> > On Wed, 29 Mar 2023 16:45:47 +0200 Louis Peens wrote:  
> > > In some customized scenario, `dev_port` is used to rename netdev
> > > instead of `phys_port_name`, which requires to initialize it
> > > correctly to get expected netdev name.  
> > 
> > What do you mean by "which requires to initialize it correctly to get
> > expected netdev name." ?  
> 
> I mean it cannot be renamed by udev rules as expected if `dev_port`
> is not correctly initialized, because the second port doesn't match
> 'ATTR{dev_port}=="1"'.

Yes, but phys_port_name is still there, and can be used, right?
So why add another attr?
Yinjun Zhang March 30, 2023, 2:52 a.m. UTC | #6
On Wed, 29 Mar 2023 19:38:31 -0700, Jakub Kicinski wrote:
> On Thu, 30 Mar 2023 01:40:30 +0000 Yinjun Zhang wrote:
> > On Wed, 29 Mar 2023 12:22:27 -0700, Jakub Kicinski wrote:
> > > On Wed, 29 Mar 2023 16:45:47 +0200 Louis Peens wrote:
> > > > In some customized scenario, `dev_port` is used to rename netdev
> > > > instead of `phys_port_name`, which requires to initialize it
> > > > correctly to get expected netdev name.
> > >
> > > What do you mean by "which requires to initialize it correctly to get
> > > expected netdev name." ?
> >
> > I mean it cannot be renamed by udev rules as expected if `dev_port`
> > is not correctly initialized, because the second port doesn't match
> > 'ATTR{dev_port}=="1"'.
> 
> Yes, but phys_port_name is still there, and can be used, right?
> So why add another attr?

Yes, phys_port_name is still there. But some users prefer to use dev_port.
I don't add this new attr, it's already existed since 
3f85944fe207 ("net: Add sysfs file for port number").
I just make the attr's value correct.
Jakub Kicinski March 30, 2023, 3:10 a.m. UTC | #7
On Thu, 30 Mar 2023 02:52:22 +0000 Yinjun Zhang wrote:
> > Yes, but phys_port_name is still there, and can be used, right?
> > So why add another attr?  
> 
> Yes, phys_port_name is still there. But some users prefer to use dev_port.
> I don't add this new attr, it's already existed since 
> 3f85944fe207 ("net: Add sysfs file for port number").
> I just make the attr's value correct.

You're using a different ID than phys_port_name, as far as I can tell :(
When the port is not split will id == label, always?
Yinjun Zhang March 30, 2023, 3:27 a.m. UTC | #8
On Wed, 29 Mar 2023 20:10:29 -0700, Jakub Kicinski wrote:
> On Thu, 30 Mar 2023 02:52:22 +0000 Yinjun Zhang wrote:
> > > Yes, but phys_port_name is still there, and can be used, right?
> > > So why add another attr?
> >
> > Yes, phys_port_name is still there. But some users prefer to use dev_port.
> > I don't add this new attr, it's already existed since
> > 3f85944fe207 ("net: Add sysfs file for port number").
> > I just make the attr's value correct.
> 
> You're using a different ID than phys_port_name, as far as I can tell :(
> When the port is not split will id == label, always?

You got the point. We create netdevs according to the port sequence in
eth_table from management firmware. I think M-FW will make sure
the sequence matches the port label id.
Jakub Kicinski March 30, 2023, 3:58 a.m. UTC | #9
On Thu, 30 Mar 2023 03:27:56 +0000 Yinjun Zhang wrote:
> > > Yes, phys_port_name is still there. But some users prefer to use dev_port.
> > > I don't add this new attr, it's already existed since
> > > 3f85944fe207 ("net: Add sysfs file for port number").
> > > I just make the attr's value correct.  
> > 
> > You're using a different ID than phys_port_name, as far as I can tell :(
> > When the port is not split will id == label, always?  
> 
> You got the point. We create netdevs according to the port sequence in
> eth_table from management firmware. I think M-FW will make sure
> the sequence matches the port label id.

Alright, then, with an improved commit message this patch should 
be fine.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_port.c b/drivers/net/ethernet/netronome/nfp/nfp_port.c
index 4f2308570dcf..54640bcb70fb 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_port.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_port.c
@@ -189,6 +189,7 @@  int nfp_port_init_phy_port(struct nfp_pf *pf, struct nfp_app *app,
 
 	port->eth_port = &pf->eth_tbl->ports[id];
 	port->eth_id = pf->eth_tbl->ports[id].index;
+	port->netdev->dev_port = id;
 	if (pf->mac_stats_mem)
 		port->eth_stats =
 			pf->mac_stats_mem + port->eth_id * NFP_MAC_STATS_SIZE;