Expose port split attributes
Subsystems (13)
v3 cover Expose port split attributes
From: Ido Schimmel <[email protected]>
Danielle says:
Currently, user space has no way of knowing if a port can be split and into how many ports. Among other things, this makes it impossible to write generic tests for port split functionality.
Therefore, this set exposes two new devlink port attributes to user
space: Number of lanes and whether the port can be split or not.
Patch set overview:
Patches #1-#4 cleanup 'struct devlink_port_attrs' and reduce the number of parameters passed between drivers and devlink via devlink_port_attrs_set()
Patch #5 adds devlink port lanes attributes
Patches #6-#7 add devlink port splittable attribute
Patch #8 exploits the fact that devlink is now aware of port's number of lanes and whether the port can be split or not and moves some checks from drivers to devlink
Patch #9 adds a port split test
Changes since v2:
* Remove some local variables from patch #3
* Reword function description in patch #5
* Fix a bug in patch #8
* Add a test for the splittable attribute in patch #9
Changes since v1:
* Rename 'width' attribute to 'lanes'
* Add 'splittable' attribute
* Move checks from drivers to devlink
Danielle Ratson (9):
devlink: Move set attribute of devlink_port_attrs to devlink_port
devlink: Move switch_port attribute of devlink_port_attrs to
devlink_port
devlink: Replace devlink_port_attrs_set parameters with a struct
mlxsw: Set number of port lanes attribute in driver
devlink: Add a new devlink port lanes attribute and pass to netlink
mlxsw: Set port split ability attribute in driver
devlink: Add a new devlink port split ability attribute and pass to
netlink
devlink: Move input checks from driver to devlink
selftests: net: Add port split test
.../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 9 +- drivers/net/ethernet/intel/ice/ice_devlink.c | 6 +- .../ethernet/mellanox/mlx5/core/en/devlink.c | 19 +- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 16 +- drivers/net/ethernet/mellanox/mlxsw/core.c | 18 +- drivers/net/ethernet/mellanox/mlxsw/core.h | 4 +- drivers/net/ethernet/mellanox/mlxsw/minimal.c | 4 +- .../net/ethernet/mellanox/mlxsw/spectrum.c | 23 +- .../net/ethernet/mellanox/mlxsw/switchib.c | 2 +- .../net/ethernet/mellanox/mlxsw/switchx2.c | 2 +- .../net/ethernet/netronome/nfp/nfp_devlink.c | 17 +- .../ethernet/pensando/ionic/ionic_devlink.c | 5 +- drivers/net/netdevsim/dev.c | 10 +- include/net/devlink.h | 30 +- include/uapi/linux/devlink.h | 3 + net/core/devlink.c | 93 +++--- net/dsa/dsa2.c | 17 +- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/devlink_port_split.py | 277 ++++++++++++++++++ 19 files changed, 424 insertions(+), 132 deletions(-) create mode 100755 tools/testing/selftests/net/devlink_port_split.py
Signature · 1 line
2.26.2
PATCH v3 1/9 devlink: Move set attribute of devlink_port_attrs to devlink_port
From: Danielle Ratson <[email protected]>
The struct devlink_port_attrs holds the attributes of devlink_port.
The 'set' field is not devlink_port's attribute as opposed to most of the others.
Move 'set' to be devlink_port's field called 'attrs_set'.
--- include/net/devlink.h | 4 ++-- net/core/devlink.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-)
include/net/devlink.h +2 -2
@@ -65,8 +65,7 @@ struct devlink_port_pci_vf_attrs { };struct devlink_port_attrs { -u8 set:1 , - split:1 , +u8 split:1 , switch_port:1 ;enum devlink_port_flavour flavour;struct netdev_phys_item_id switch_id;
@@ -90,6 +89,7 @@ struct devlink_port {enum devlink_port_type desired_type;void *type_dev;struct devlink_port_attrs attrs; + u8 attrs_set:1;struct delayed_work type_warn_dw; };
net/core/devlink.c +3 -3
@@ -528,7 +528,7 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, {struct devlink_port_attrs *attrs = &devlink_port->attrs; -if (!attrs->set) +if (!devlink_port->attrs_set)return 0 ;if (nla_put_u16 (msg,DEVLINK_ATTR_PORT_FLAVOUR , attrs->flavour))return -EMSGSIZE ;
@@ -7518,7 +7518,7 @@ static int __devlink_port_attrs_set(struct devlink_port *devlink_port,if (WARN_ON (devlink_port->registered))return -EEXIST ; - attrs->set = true; + devlink_port->attrs_set = true; attrs->flavour = flavour;if (switch_id) { attrs->switch_port = true;
@@ -7626,7 +7626,7 @@ static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,struct devlink_port_attrs *attrs = &devlink_port->attrs;int n =0 ; -if (!attrs->set) +if (!devlink_port->attrs_set)return -EOPNOTSUPP ;switch (attrs->flavour) {
Signature · 1 line
2.26.2
PATCH v3 2/9 devlink: Move switch_port attribute of devlink_port_attrs to devlink_port
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
The struct devlink_port_attrs holds the attributes of devlink_port.
Similarly to the previous patch, 'switch_port' attribute is another exception.
Move 'switch_port' to be devlink_port's field.
--- include/net/devlink.h | 6 +++--- net/core/devlink.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-)
include/net/devlink.h +3 -3
@@ -65,8 +65,7 @@ struct devlink_port_pci_vf_attrs { };struct devlink_port_attrs { -u8 split:1 , - switch_port:1 ; +u8 split:1 ;enum devlink_port_flavour flavour;struct netdev_phys_item_id switch_id;union {
@@ -89,7 +88,8 @@ struct devlink_port {enum devlink_port_type desired_type;void *type_dev;struct devlink_port_attrs attrs; - u8 attrs_set:1; + u8 attrs_set:1, + switch_port:1;struct delayed_work type_warn_dw; };
net/core/devlink.c +3 -3
@@ -7521,13 +7521,13 @@ static int __devlink_port_attrs_set(struct devlink_port *devlink_port, devlink_port->attrs_set = true; attrs->flavour = flavour;if (switch_id) { - attrs->switch_port = true; + devlink_port->switch_port = true;if (WARN_ON (switch_id_len >MAX_PHYS_ITEM_ID_LEN )) switch_id_len =MAX_PHYS_ITEM_ID_LEN ;memcpy (attrs->switch_id.id, switch_id, switch_id_len); attrs->switch_id.id_len = switch_id_len; }else { - attrs->switch_port = false; + devlink_port->switch_port = false; }return 0 ; }
@@ -9461,7 +9461,7 @@ int devlink_compat_switch_id_get(struct net_device *dev,* any devlink lock as only permanent values are accessed. */ devlink_port =netdev_to_devlink_port (dev); -if (!devlink_port || !devlink_port->attrs.switch_port) +if (!devlink_port || !devlink_port->switch_port)return -EOPNOTSUPP ;memcpy (ppid, &devlink_port->attrs.switch_id,sizeof (*ppid));
Signature · 1 line
2.26.2
PATCH v3 3/9 devlink: Replace devlink_port_attrs_set parameters with a struct
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
Currently, devlink_port_attrs_set accepts a long list of parameters, that most of them are devlink port's attributes.
Use the devlink_port_attrs struct to replace the relevant parameters.
--- .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 9 ++-- drivers/net/ethernet/intel/ice/ice_devlink.c | 6 ++- .../ethernet/mellanox/mlx5/core/en/devlink.c | 19 ++++--- .../net/ethernet/mellanox/mlx5/core/en_rep.c | 16 +++--- drivers/net/ethernet/mellanox/mlxsw/core.c | 11 ++-- .../net/ethernet/netronome/nfp/nfp_devlink.c | 11 ++-- .../ethernet/pensando/ionic/ionic_devlink.c | 5 +- drivers/net/netdevsim/dev.c | 10 ++-- include/net/devlink.h | 20 ++++--- net/core/devlink.c | 54 ++++--------------- net/dsa/dsa2.c | 17 +++--- 11 files changed, 82 insertions(+), 96 deletions(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +6 -3
@@ -691,6 +691,7 @@ static void bnxt_dl_params_unregister(struct bnxt *bp)int bnxt_dl_register (struct bnxt *bp) { +struct devlink_port_attrs attrs = {};struct devlink *dl;int rc;
@@ -719,9 +720,11 @@ int bnxt_dl_register(struct bnxt *bp)if (!BNXT_PF (bp))return 0 ; -devlink_port_attrs_set (&bp->dl_port,DEVLINK_PORT_FLAVOUR_PHYSICAL , - bp->pf.port_id, false,0 , bp->dsn, -sizeof (bp->dsn)); + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; + attrs.phys.port_number = bp->pf.port_id; +memcpy (attrs.switch_id.id, bp->dsn,sizeof (bp->dsn)); + attrs.switch_id.id_len =sizeof (bp->dsn); +devlink_port_attrs_set (&bp->dl_port, &attrs); rc =devlink_port_register (dl, &bp->dl_port, bp->pf.port_id);if (rc) {netdev_err (bp->dev,"devlink_port_register failed\n" );
drivers/net/ethernet/intel/ice/ice_devlink.c +4 -2
@@ -312,6 +312,7 @@ int ice_devlink_create_port(struct ice_pf *pf)struct devlink *devlink =priv_to_devlink (pf);struct ice_vsi *vsi =ice_get_main_vsi (pf);struct device *dev =ice_pf_to_dev (pf); +struct devlink_port_attrs attrs = {};int err;if (!vsi) {
@@ -319,8 +320,9 @@ int ice_devlink_create_port(struct ice_pf *pf)return -EIO ; } -devlink_port_attrs_set (&pf->devlink_port,DEVLINK_PORT_FLAVOUR_PHYSICAL , - pf->hw.pf_id, false,0 ,NULL ,0 ); + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; + attrs.phys.port_number = pf->hw.pf_id; +devlink_port_attrs_set (&pf->devlink_port, &attrs); err =devlink_port_register (devlink, &pf->devlink_port, pf->hw.pf_id);if (err) {dev_err (dev,"devlink_port_register failed: %d\n" , err);
drivers/net/ethernet/mellanox/mlx5/core/en/devlink.c +9 -10
@@ -6,17 +6,16 @@int mlx5e_devlink_port_register (struct mlx5e_priv *priv) {struct devlink *devlink =priv_to_devlink (priv->mdev); +struct devlink_port_attrs attrs = {}; -if (mlx5_core_is_pf (priv->mdev)) -devlink_port_attrs_set (&priv->dl_port, -DEVLINK_PORT_FLAVOUR_PHYSICAL , -PCI_FUNC (priv->mdev->pdev->devfn), - false,0 , -NULL ,0 ); -else -devlink_port_attrs_set (&priv->dl_port, -DEVLINK_PORT_FLAVOUR_VIRTUAL , -0 , false,0 ,NULL ,0 ); +if (mlx5_core_is_pf (priv->mdev)) { + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; + attrs.phys.port_number =PCI_FUNC (priv->mdev->pdev->devfn); + }else { + attrs.flavour =DEVLINK_PORT_FLAVOUR_VIRTUAL ; + } + +devlink_port_attrs_set (&priv->dl_port, &attrs);return devlink_port_register (devlink, &priv->dl_port,1 ); }
drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +7 -9
@@ -1185,6 +1185,7 @@ static int register_devlink_port(struct mlx5_core_dev *dev, {struct devlink *devlink =priv_to_devlink (dev);struct mlx5_eswitch_rep *rep = rpriv->rep; +struct devlink_port_attrs attrs = {};struct netdev_phys_item_id ppid = {};unsigned int dl_port_index =0 ;u16 pfnum;
@@ -1195,19 +1196,16 @@ static int register_devlink_port(struct mlx5_core_dev *dev,mlx5e_rep_get_port_parent_id (rpriv->netdev, &ppid); dl_port_index =mlx5_esw_vport_to_devlink_port_index (dev, rep->vport); pfnum =PCI_FUNC (dev->pdev->devfn); - + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; + attrs.phys.port_number = pfnum; +memcpy (attrs.switch_id.id, &ppid.id[0 ], ppid.id_len); + attrs.switch_id.id_len = ppid.id_len;if (rep->vport ==MLX5_VPORT_UPLINK ) -devlink_port_attrs_set (&rpriv->dl_port, -DEVLINK_PORT_FLAVOUR_PHYSICAL , - pfnum, false,0 , - &ppid.id[0 ], ppid.id_len); +devlink_port_attrs_set (&rpriv->dl_port, &attrs);else if (rep->vport ==MLX5_VPORT_PF ) -devlink_port_attrs_pci_pf_set (&rpriv->dl_port, - &ppid.id[0 ], ppid.id_len, - pfnum); +devlink_port_attrs_pci_pf_set (&rpriv->dl_port, pfnum);else if (mlx5_eswitch_is_vf_vport (dev->priv.eswitch, rpriv->rep->vport))devlink_port_attrs_pci_vf_set (&rpriv->dl_port, - &ppid.id[0 ], ppid.id_len, pfnum, rep->vport -1 );return devlink_port_register (devlink, &rpriv->dl_port, dl_port_index);
drivers/net/ethernet/mellanox/mlxsw/core.c +8 -3
@@ -2129,12 +2129,17 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,struct mlxsw_core_port *mlxsw_core_port = &mlxsw_core->ports[local_port];struct devlink_port *devlink_port = &mlxsw_core_port->devlink_port; +struct devlink_port_attrs attrs = {};int err; + attrs.split = split; + attrs.flavour = flavour; + attrs.phys.port_number = port_number; + attrs.phys.split_subport_number = split_port_subnumber; +memcpy (attrs.switch_id.id, switch_id, switch_id_len); + attrs.switch_id.id_len = switch_id_len; mlxsw_core_port->local_port = local_port; -devlink_port_attrs_set (devlink_port, flavour, port_number, - split, split_port_subnumber, - switch_id, switch_id_len); +devlink_port_attrs_set (devlink_port, &attrs); err =devlink_port_register (devlink, devlink_port, local_port);if (err)memset (mlxsw_core_port,0 ,sizeof (*mlxsw_core_port));
drivers/net/ethernet/netronome/nfp/nfp_devlink.c +8 -3
@@ -353,6 +353,7 @@ const struct devlink_ops nfp_devlink_ops = {int nfp_devlink_port_register (struct nfp_app *app,struct nfp_port *port) { +struct devlink_port_attrs attrs = {};struct nfp_eth_table_port eth_port;struct devlink *devlink;const u8 *serial;
@@ -365,10 +366,14 @@ int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port)if (ret)return ret; + attrs.split = eth_port.is_split; + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; + attrs.phys.port_number = eth_port.label_port; + attrs.phys.split_subport_number = eth_port.label_subport; serial_len =nfp_cpp_serial (port->app->cpp, &serial); -devlink_port_attrs_set (&port->dl_port,DEVLINK_PORT_FLAVOUR_PHYSICAL , - eth_port.label_port, eth_port.is_split, - eth_port.label_subport, serial, serial_len); +memcpy (attrs.switch_id.id, serial, serial_len); + attrs.switch_id.id_len = serial_len; +devlink_port_attrs_set (&port->dl_port, &attrs); devlink =priv_to_devlink (app->pf);
drivers/net/ethernet/pensando/ionic/ionic_devlink.c +3 -2
@@ -69,6 +69,7 @@ void ionic_devlink_free(struct ionic *ionic)int ionic_devlink_register (struct ionic *ionic) {struct devlink *dl =priv_to_devlink (ionic); +struct devlink_port_attrs attrs = {};int err; err =devlink_register (dl, ionic->dev);
@@ -77,8 +78,8 @@ int ionic_devlink_register(struct ionic *ionic)return err; } -devlink_port_attrs_set (&ionic->dl_port,DEVLINK_PORT_FLAVOUR_PHYSICAL , -0 , false,0 ,NULL ,0 ); + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; +devlink_port_attrs_set (&ionic->dl_port, &attrs); err =devlink_port_register (dl, &ionic->dl_port,0 );if (err)dev_err (ionic->dev,"devlink_port_register failed: %d\n" , err);
drivers/net/netdevsim/dev.c +6 -4
@@ -889,6 +889,7 @@ static const struct devlink_ops nsim_dev_devlink_ops = {static int __nsim_dev_port_add (struct nsim_dev *nsim_dev,unsigned int port_index) { +struct devlink_port_attrs attrs = {};struct nsim_dev_port *nsim_dev_port;struct devlink_port *devlink_port;int err;
@@ -899,10 +900,11 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, nsim_dev_port->port_index = port_index; devlink_port = &nsim_dev_port->devlink_port; -devlink_port_attrs_set (devlink_port,DEVLINK_PORT_FLAVOUR_PHYSICAL , - port_index +1 ,0 ,0 , - nsim_dev->switch_id.id, - nsim_dev->switch_id.id_len); + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; + attrs.phys.port_number = port_index +1 ; +memcpy (attrs.switch_id.id, nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); + attrs.switch_id.id_len = nsim_dev->switch_id.id_len; +devlink_port_attrs_set (devlink_port, &attrs); err =devlink_port_register (priv_to_devlink (nsim_dev), devlink_port, port_index);if (err)
include/net/devlink.h +9 -11
@@ -52,7 +52,7 @@ struct devlink_port_phys_attrs {* A physical port which is visible to the user * for a given port flavour. */ -u32 split_subport_number; +u32 split_subport_number;/* If the port is split, this is the number of subport. */ };struct devlink_port_pci_pf_attrs {
@@ -64,6 +64,12 @@ struct devlink_port_pci_vf_attrs {u16 vf;/* Associated PCI VF for of the PCI PF for this port. */ }; +/** +* struct devlink_port_attrs - devlink port object +* @flavour: flavour of the port +* @split: indicates if this is split port +* @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 ;enum devlink_port_flavour flavour;
@@ -1180,17 +1186,9 @@ void devlink_port_type_ib_set(struct devlink_port *devlink_port, struct ib_device *ibdev);void devlink_port_type_clear (struct devlink_port *devlink_port);void devlink_port_attrs_set (struct devlink_port *devlink_port, -enum devlink_port_flavour flavour, -u32 port_number,bool split, -u32 split_subport_number, -const unsigned char *switch_id, -unsigned char switch_id_len); -void devlink_port_attrs_pci_pf_set (struct devlink_port *devlink_port, -const unsigned char *switch_id, -unsigned char switch_id_len,u16 pf); +struct devlink_port_attrs *devlink_port_attrs); +void devlink_port_attrs_pci_pf_set (struct devlink_port *devlink_port,u16 pf);void devlink_port_attrs_pci_vf_set (struct devlink_port *devlink_port, -const unsigned char *switch_id, -unsigned char switch_id_len,u16 pf,u16 vf); int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count,
net/core/devlink.c +11 -43
106 lines not on this page · raw message
net/dsa/dsa2.c +11 -6
@@ -261,10 +261,15 @@ static int dsa_port_setup(struct dsa_port *dp)struct devlink_port *dlp = &dp->devlink_port;bool dsa_port_link_registered = false;bool devlink_port_registered = false; +struct devlink_port_attrs attrs = {};struct devlink *dl = ds->devlink;bool dsa_port_enabled = false;int err =0 ; + attrs.phys.port_number = dp->index; +memcpy (attrs.switch_id.id, id, len); + attrs.switch_id.id_len = len; +if (dp->setup)return 0 ;
@@ -274,8 +279,8 @@ static int dsa_port_setup(struct dsa_port *dp)break ;case DSA_PORT_TYPE_CPU :memset (dlp,0 ,sizeof (*dlp)); -devlink_port_attrs_set (dlp,DEVLINK_PORT_FLAVOUR_CPU , - dp->index, false,0 , id, len); + attrs.flavour =DEVLINK_PORT_FLAVOUR_CPU ; +devlink_port_attrs_set (dlp, &attrs); err =devlink_port_register (dl, dlp, dp->index);if (err)break ;
@@ -294,8 +299,8 @@ static int dsa_port_setup(struct dsa_port *dp)break ;case DSA_PORT_TYPE_DSA :memset (dlp,0 ,sizeof (*dlp)); -devlink_port_attrs_set (dlp,DEVLINK_PORT_FLAVOUR_DSA , - dp->index, false,0 , id, len); + attrs.flavour =DEVLINK_PORT_FLAVOUR_DSA ; +devlink_port_attrs_set (dlp, &attrs); err =devlink_port_register (dl, dlp, dp->index);if (err)break ;
@@ -314,8 +319,8 @@ static int dsa_port_setup(struct dsa_port *dp)break ;case DSA_PORT_TYPE_USER :memset (dlp,0 ,sizeof (*dlp)); -devlink_port_attrs_set (dlp,DEVLINK_PORT_FLAVOUR_PHYSICAL , - dp->index, false,0 , id, len); + attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; +devlink_port_attrs_set (dlp, &attrs); err =devlink_port_register (dl, dlp, dp->index);if (err)break ;
Signature · 1 line
2.26.2
PATCH v3 4/9 mlxsw: Set number of port lanes attribute in driver
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
Currently, port attributes like flavour, port number and whether the port was split are set when initializing a port.
Set the number of lanes of the port as well so that it could be easily passed to devlink in the next patch.
--- drivers/net/ethernet/mellanox/mlxsw/core.c | 6 ++++-- drivers/net/ethernet/mellanox/mlxsw/core.h | 1 + drivers/net/ethernet/mellanox/mlxsw/minimal.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 4 +++- drivers/net/ethernet/mellanox/mlxsw/switchib.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/switchx2.c | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core.c +4 -2
@@ -2122,6 +2122,7 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,enum devlink_port_flavour flavour, u32 port_number, bool split, u32 split_port_subnumber, + u32 lanes, const unsigned char *switch_id, unsigned char switch_id_len) {
@@ -2159,13 +2160,14 @@ static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)int mlxsw_core_port_init (struct mlxsw_core *mlxsw_core,u8 local_port,u32 port_number,bool split,u32 split_port_subnumber, +u32 lanes,const unsigned char *switch_id,unsigned char switch_id_len) {return __mlxsw_core_port_init (mlxsw_core, local_port,DEVLINK_PORT_FLAVOUR_PHYSICAL , port_number, split, split_port_subnumber, - switch_id, switch_id_len); + lanes, switch_id, switch_id_len); }EXPORT_SYMBOL (mlxsw_core_port_init);
@@ -2186,7 +2188,7 @@ int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core, err =__mlxsw_core_port_init (mlxsw_core,MLXSW_PORT_CPU_PORT ,DEVLINK_PORT_FLAVOUR_CPU , -0 , false,0 , +0 , false,0 ,0 , switch_id, switch_id_len);if (err)return err;
drivers/net/ethernet/mellanox/mlxsw/core.h +1 -0
@@ -193,6 +193,7 @@ void *mlxsw_core_port_driver_priv(struct mlxsw_core_port *mlxsw_core_port);int mlxsw_core_port_init (struct mlxsw_core *mlxsw_core,u8 local_port,u32 port_number,bool split,u32 split_port_subnumber, +u32 lanes,const unsigned char *switch_id,unsigned char switch_id_len);void mlxsw_core_port_fini (struct mlxsw_core *mlxsw_core,u8 local_port);
drivers/net/ethernet/mellanox/mlxsw/minimal.c +1 -1
@@ -164,7 +164,7 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u8 local_port, u8 module)int err; err =mlxsw_core_port_init (mlxsw_m->core, local_port, - module +1 , false,0 , + module +1 , false,0 ,0 , mlxsw_m->base_mac,sizeof (mlxsw_m->base_mac));if (err) {
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +3 -1
@@ -1733,12 +1733,14 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,struct mlxsw_sp_port_vlan *mlxsw_sp_port_vlan;bool split = !!split_base_local_port;struct mlxsw_sp_port *mlxsw_sp_port; +u32 lanes = port_mapping->width;struct net_device *dev;int err; err =mlxsw_core_port_init (mlxsw_sp->core, local_port, port_mapping->module +1 , split, - port_mapping->lane / port_mapping->width, + port_mapping->lane / lanes, + lanes, mlxsw_sp->base_mac,sizeof (mlxsw_sp->base_mac));if (err) {
drivers/net/ethernet/mellanox/mlxsw/switchib.c +1 -1
@@ -281,7 +281,7 @@ static int mlxsw_sib_port_create(struct mlxsw_sib *mlxsw_sib, u8 local_port,int err; err =mlxsw_core_port_init (mlxsw_sib->core, local_port, - module +1 , false,0 , + module +1 , false,0 ,0 , mlxsw_sib->hw_id,sizeof (mlxsw_sib->hw_id));if (err) { dev_err(mlxsw_sib->bus_info->dev, "Port %d: Failed to init core port\n",
drivers/net/ethernet/mellanox/mlxsw/switchx2.c +1 -1
@@ -1107,7 +1107,7 @@ static int mlxsw_sx_port_eth_create(struct mlxsw_sx *mlxsw_sx, u8 local_port,int err; err =mlxsw_core_port_init (mlxsw_sx->core, local_port, - module +1 , false,0 , + module +1 , false,0 ,0 , mlxsw_sx->hw_id,sizeof (mlxsw_sx->hw_id));if (err) { dev_err(mlxsw_sx->bus_info->dev, "Port %d: Failed to init core port\n",
Signature · 1 line
2.26.2
PATCH v3 5/9 devlink: Add a new devlink port lanes attribute and pass to netlink
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
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).
--- drivers/net/ethernet/mellanox/mlxsw/core.c | 1 + include/net/devlink.h | 2 ++ include/uapi/linux/devlink.h | 2 ++ net/core/devlink.c | 4 ++++ 4 files changed, 9 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/core.c +1 -0
@@ -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;
include/net/devlink.h +2 -0
@@ -68,10 +68,12 @@ 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. * @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 {
include/uapi/linux/devlink.h +2 -0
@@ -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,
net/core/devlink.c +4 -0
@@ -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) {
Signature · 1 line
2.26.2
PATCH v3 6/9 mlxsw: Set port split ability attribute in driver
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
Currently, port attributes like flavour, port number and whether the port was split are set when initializing a port.
Set the split ability of the port as well, based on port_mapping->width field and split attribute of devlink port in spectrum, so that it could be easily passed to devlink in the next patch.
--- drivers/net/ethernet/mellanox/mlxsw/core.c | 9 +++++---- drivers/net/ethernet/mellanox/mlxsw/core.h | 5 ++--- drivers/net/ethernet/mellanox/mlxsw/minimal.c | 4 ++-- drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 4 +++- drivers/net/ethernet/mellanox/mlxsw/switchib.c | 2 +- drivers/net/ethernet/mellanox/mlxsw/switchx2.c | 2 +- 6 files changed, 14 insertions(+), 12 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/core.c +5 -4
@@ -2122,7 +2122,7 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port,enum devlink_port_flavour flavour, u32 port_number, bool split, u32 split_port_subnumber, - u32 lanes, + bool splittable, u32 lanes, const unsigned char *switch_id, unsigned char switch_id_len) {
@@ -2161,14 +2161,15 @@ static void __mlxsw_core_port_fini(struct mlxsw_core *mlxsw_core, u8 local_port)int mlxsw_core_port_init (struct mlxsw_core *mlxsw_core,u8 local_port,u32 port_number,bool split,u32 split_port_subnumber, -u32 lanes, +bool splittable,u32 lanes,const unsigned char *switch_id,unsigned char switch_id_len) {return __mlxsw_core_port_init (mlxsw_core, local_port,DEVLINK_PORT_FLAVOUR_PHYSICAL , port_number, split, split_port_subnumber, - lanes, switch_id, switch_id_len); + splittable, lanes, + switch_id, switch_id_len); }EXPORT_SYMBOL (mlxsw_core_port_init);
@@ -2189,7 +2190,7 @@ int mlxsw_core_cpu_port_init(struct mlxsw_core *mlxsw_core, err =__mlxsw_core_port_init (mlxsw_core,MLXSW_PORT_CPU_PORT ,DEVLINK_PORT_FLAVOUR_CPU , -0 , false,0 ,0 , +0 , false,0 , false,0 , switch_id, switch_id_len);if (err)return err;
drivers/net/ethernet/mellanox/mlxsw/core.h +2 -3
@@ -191,9 +191,8 @@ void mlxsw_core_lag_mapping_clear(struct mlxsw_core *mlxsw_core,void *mlxsw_core_port_driver_priv (struct mlxsw_core_port *mlxsw_core_port);int mlxsw_core_port_init (struct mlxsw_core *mlxsw_core,u8 local_port, -u32 port_number,bool split, -u32 split_port_subnumber, -u32 lanes, +u32 port_number,bool split,u32 split_port_subnumber, +bool splittable,u32 lanes,const unsigned char *switch_id,unsigned char switch_id_len);void mlxsw_core_port_fini (struct mlxsw_core *mlxsw_core,u8 local_port);
drivers/net/ethernet/mellanox/mlxsw/minimal.c +2 -2
@@ -164,8 +164,8 @@ mlxsw_m_port_create(struct mlxsw_m *mlxsw_m, u8 local_port, u8 module)int err; err =mlxsw_core_port_init (mlxsw_m->core, local_port, - module +1 , false,0 ,0 , - mlxsw_m->base_mac, + module +1 , false,0 , false, +0 , mlxsw_m->base_mac,sizeof (mlxsw_m->base_mac));if (err) { dev_err(mlxsw_m->bus_info->dev, "Port %d: Failed to init core port\n",
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +3 -1
@@ -1735,12 +1735,14 @@ static int mlxsw_sp_port_create(struct mlxsw_sp *mlxsw_sp, u8 local_port,struct mlxsw_sp_port *mlxsw_sp_port;u32 lanes = port_mapping->width;struct net_device *dev; +bool splittable;int err; + splittable = lanes >1 && !split; err =mlxsw_core_port_init (mlxsw_sp->core, local_port, port_mapping->module +1 , split, port_mapping->lane / lanes, - lanes, + splittable, lanes, mlxsw_sp->base_mac,sizeof (mlxsw_sp->base_mac));if (err) {
drivers/net/ethernet/mellanox/mlxsw/switchib.c +1 -1
@@ -281,7 +281,7 @@ static int mlxsw_sib_port_create(struct mlxsw_sib *mlxsw_sib, u8 local_port,int err; err =mlxsw_core_port_init (mlxsw_sib->core, local_port, - module +1 , false,0 ,0 , + module +1 , false,0 , false,0 , mlxsw_sib->hw_id,sizeof (mlxsw_sib->hw_id));if (err) { dev_err(mlxsw_sib->bus_info->dev, "Port %d: Failed to init core port\n",
drivers/net/ethernet/mellanox/mlxsw/switchx2.c +1 -1
@@ -1107,7 +1107,7 @@ static int mlxsw_sx_port_eth_create(struct mlxsw_sx *mlxsw_sx, u8 local_port,int err; err =mlxsw_core_port_init (mlxsw_sx->core, local_port, - module +1 , false,0 ,0 , + module +1 , false,0 , false,0 , mlxsw_sx->hw_id,sizeof (mlxsw_sx->hw_id));if (err) { dev_err(mlxsw_sx->bus_info->dev, "Port %d: Failed to init core port\n",
Signature · 1 line
2.26.2
PATCH v3 7/9 devlink: Add a new devlink port split ability attribute and pass to netlink
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
Add a new attribute that indicates the split ability of devlink port.
Drivers are expected to set it via devlink_port_attrs_set(), before registering the port.
--- drivers/net/ethernet/mellanox/mlxsw/core.c | 1 + drivers/net/ethernet/netronome/nfp/nfp_devlink.c | 1 + include/net/devlink.h | 4 +++- include/uapi/linux/devlink.h | 1 + net/core/devlink.c | 3 +++ 5 files changed, 9 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/core.c +1 -0
@@ -2135,6 +2135,7 @@ static int __mlxsw_core_port_init(struct mlxsw_core *mlxsw_core, u8 local_port, attrs.split = split; attrs.lanes = lanes; + attrs.splittable = splittable; attrs.flavour = flavour; attrs.phys.port_number = port_number; attrs.phys.split_subport_number = split_port_subnumber;
drivers/net/ethernet/netronome/nfp/nfp_devlink.c +1 -0
@@ -367,6 +367,7 @@ int nfp_devlink_port_register(struct nfp_app *app, struct nfp_port *port)return ret; attrs.split = eth_port.is_split; + attrs.splittable = !attrs.split; attrs.flavour =DEVLINK_PORT_FLAVOUR_PHYSICAL ; attrs.phys.port_number = eth_port.label_port; attrs.phys.split_subport_number = eth_port.label_subport;
include/net/devlink.h +3 -1
@@ -68,11 +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 +* @splittable: indicates if the port can be split. * @lanes: maximum number of lanes the port supports. 0 value is not passed to netlink. * @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 ; +u8 split:1 , + splittable:1 ;u32 lanes;enum devlink_port_flavour flavour;struct netdev_phys_item_id switch_id;
include/uapi/linux/devlink.h +1 -0
@@ -456,6 +456,7 @@ enum devlink_attr {DEVLINK_ATTR_INFO_BOARD_SERIAL_NUMBER ,/* string */ DEVLINK_ATTR_PORT_LANES ,/* u32 */ + DEVLINK_ATTR_PORT_SPLITTABLE, /* u8 *//* add new attributes above here, update the policy in devlink.c */
net/core/devlink.c +3 -0
@@ -534,6 +534,8 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,if (nla_put_u32 (msg,DEVLINK_ATTR_PORT_LANES , attrs->lanes))return -EMSGSIZE ; } +if (nla_put_u8 (msg,DEVLINK_ATTR_PORT_SPLITTABLE , attrs->splittable)) +return -EMSGSIZE ;if (nla_put_u16 (msg,DEVLINK_ATTR_PORT_FLAVOUR , attrs->flavour))return -EMSGSIZE ;switch (devlink_port->attrs.flavour) {
@@ -7547,6 +7549,7 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port, ret =__devlink_port_attrs_set (devlink_port, attrs->flavour);if (ret)return ; +WARN_ON (attrs->splittable && attrs->split); }EXPORT_SYMBOL_GPL (devlink_port_attrs_set);
Signature · 1 line
2.26.2
PATCH v3 8/9 devlink: Move input checks from driver to devlink
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
Currently, all the input checks are done in driver.
After adding the split capability to devlink port, move the checks to devlink.
--- .../net/ethernet/mellanox/mlxsw/spectrum.c | 17 ++-------------- .../net/ethernet/netronome/nfp/nfp_devlink.c | 5 +---- net/core/devlink.c | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 19 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +2 -15
@@ -2236,13 +2236,6 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,return -EINVAL ; } -/* Split ports cannot be split. */ -if (mlxsw_sp_port->split) { -netdev_err (mlxsw_sp_port->dev,"Port cannot be split further\n" ); -NL_SET_ERR_MSG_MOD (extack,"Port cannot be split further" ); -return -EINVAL ; - } - max_width =mlxsw_core_module_max_width (mlxsw_core, mlxsw_sp_port->mapping.module);if (max_width <0 ) {
@@ -2251,19 +2244,13 @@ static int mlxsw_sp_port_split(struct mlxsw_core *mlxsw_core, u8 local_port,return max_width; } -/* Split port with non-max and 1 module width cannot be split. */ -if (mlxsw_sp_port->mapping.width != max_width || max_width ==1 ) { +/* Split port with non-max cannot be split. */ +if (mlxsw_sp_port->mapping.width != max_width) {netdev_err (mlxsw_sp_port->dev,"Port cannot be split\n" );NL_SET_ERR_MSG_MOD (extack,"Port cannot be split" );return -EINVAL ; } -if (count ==1 || !is_power_of_2 (count) || count > max_width) { -netdev_err (mlxsw_sp_port->dev,"Invalid split count\n" ); -NL_SET_ERR_MSG_MOD (extack,"Invalid split count" ); -return -EINVAL ; - } - offset =mlxsw_sp_local_ports_offset (mlxsw_core, count, max_width);if (offset <0 ) {netdev_err (mlxsw_sp_port->dev,"Cannot obtain local port offset\n" );
drivers/net/ethernet/netronome/nfp/nfp_devlink.c +1 -4
@@ -70,9 +70,6 @@ nfp_devlink_port_split(struct devlink *devlink, unsigned int port_index,unsigned int lanes;int ret; -if (count <2 ) -return -EINVAL ; -mutex_lock (&pf->lock);rtnl_lock ();
@@ -81,7 +78,7 @@ nfp_devlink_port_split(struct devlink *devlink, unsigned int port_index,if (ret) goto out; -if (eth_port.is_split || eth_port.port_lanes % count) { +if (eth_port.port_lanes % count) { ret = -EINVAL ; goto out; }
net/core/devlink.c +20 -0
@@ -940,6 +940,7 @@ static int devlink_nl_cmd_port_split_doit(struct sk_buff *skb, struct genl_info *info) {struct devlink *devlink = info->user_ptr[0 ]; +struct devlink_port *devlink_port;u32 port_index;u32 count;
@@ -947,8 +948,27 @@ static int devlink_nl_cmd_port_split_doit(struct sk_buff *skb, !info->attrs[DEVLINK_ATTR_PORT_SPLIT_COUNT]) return -EINVAL; + devlink_port =devlink_port_get_from_info (devlink, info); port_index =nla_get_u32 (info->attrs[DEVLINK_ATTR_PORT_INDEX ]); count =nla_get_u32 (info->attrs[DEVLINK_ATTR_PORT_SPLIT_COUNT ]); + +if (IS_ERR (devlink_port)) +return -EINVAL ; + +if (!devlink_port->attrs.splittable) { +/* Split ports cannot be split. */ +if (devlink_port->attrs.split) +NL_SET_ERR_MSG_MOD (info->extack,"Port cannot be split further" ); +else +NL_SET_ERR_MSG_MOD (info->extack,"Port cannot be split" ); +return -EINVAL ; + } + +if (count <2 || !is_power_of_2 (count) || count > devlink_port->attrs.lanes) { +NL_SET_ERR_MSG_MOD (info->extack,"Invalid split count" ); +return -EINVAL ; + } +return devlink_port_split (devlink, port_index, count, info->extack); }
Signature · 1 line
2.26.2
PATCH v3 9/9 selftests: net: Add port split test
In reply to Ido SchimmelFrom: Danielle Ratson <[email protected]>
Test port split configuration using previously added number of port lanes attribute.
Check that all the splittable ports are successfully split to their maximum number of lanes and below, and that those which are not splittable fail to be split.
Test output example:
TEST: swp4 is unsplittable [ OK ]
TEST: split port swp53 into 4 [ OK ]
TEST: Unsplit port pci/0000:03:00.0/25 [ OK ]
TEST: split port swp53 into 2 [ OK ]
TEST: Unsplit port pci/0000:03:00.0/25 [ OK ]
--- tools/testing/selftests/net/Makefile | 1 + .../selftests/net/devlink_port_split.py | 277 ++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100755 tools/testing/selftests/net/devlink_port_split.py
tools/testing/selftests/net/Makefile +1 -0
@@ -18,6 +18,7 @@ TEST_PROGS += reuseaddr_ports_exhausted.sh TEST_PROGS += txtimestamp.sh TEST_PROGS += vrf-xfrm-tests.sh TEST_PROGS += rxtimestamp.sh +TEST_PROGS += devlink_port_split.py TEST_PROGS_EXTENDED := in_netns.sh TEST_GEN_FILES = socket nettest TEST_GEN_FILES += psock_fanout psock_tpacket msg_zerocopy reuseport_addr_any
tools/testing/selftests/net/devlink_port_split.py new file +277 -0
277 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 33 lines · On Thu, 9 Jul 2020 16:18:13 +0300 Ido Schimmel wrote:
From: Ido Schimmel <[email protected]>
Danielle says:
Currently, user space has no way of knowing if a port can be split and into how many ports. Among other things, this makes it impossible to write generic tests for port split functionality.
Therefore, this set exposes two new devlink port attributes to user
space: Number of lanes and whether the port can be split or not.Patch set overview:
Patches #1-#4 cleanup 'struct
devlink_port_attrs' and reduce the number of parameters passed between drivers and devlink viadevlink_port_attrs_set()Patch #5 adds devlink port lanes attributes
Patches #6-#7 add devlink port splittable attribute
Patch #8 exploits the fact that devlink is now aware of port's number of lanes and whether the port can be split or not and moves some checks from drivers to devlink
Patch #9 adds a port split test
Changes since v2:
* Remove some local variables from patch #3
* Reword function description in patch #5
* Fix a bug in patch #8
* Add a test for the splittable attribute in patch #9
Quoted 4 lines
Changes since v1:
* Rename 'width' attribute to 'lanes'
* Add 'splittable' attribute
* Move checks from drivers to devlink
FWIW I fancy my:
lanes % count != 0
from the nfp cleaner than the:
!is_power_of_2(count) || count > lanes
of mlxsw, but that's bike shedding at best, and at worst I'm missing something ;) so:
David Miller
maintainerFrom: Ido Schimmel <[email protected]>
Date: Thu, 9 Jul 2020 16:18:13 +0300
Quoted 33 lines
From: Ido Schimmel <[email protected]>
Danielle says:
Currently, user space has no way of knowing if a port can be split and into how many ports. Among other things, this makes it impossible to write generic tests for port split functionality.
Therefore, this set exposes two new devlink port attributes to user
space: Number of lanes and whether the port can be split or not.Patch set overview:
Patches #1-#4 cleanup 'struct
devlink_port_attrs' and reduce the number of parameters passed between drivers and devlink viadevlink_port_attrs_set()Patch #5 adds devlink port lanes attributes
Patches #6-#7 add devlink port splittable attribute
Patch #8 exploits the fact that devlink is now aware of port's number of lanes and whether the port can be split or not and moves some checks from drivers to devlink
Patch #9 adds a port split test
Changes since v2:
* Remove some local variables from patch #3
* Reword function description in patch #5
* Fix a bug in patch #8
* Add a test for the splittable attribute in patch #9
Quoted 4 lines
Changes since v1:
* Rename 'width' attribute to 'lanes'
* Add 'splittable' attribute
* Move checks from drivers to devlink
Series applied, thanks everyone.