devlink: Allow to set up parent in devl_rate_leaf_create()

Currently the driver is able to create leaf nodes for the devlink-rate,
but is unable to set parent for them. This wasn't as issue before the
possibility to export hierarchy from the driver. After adding the export
feature, in order for the driver to supply correct hierarchy, it's
necessary for it to be able to supply a parent name to
devl_rate_leaf_create().

Introduce a new parameter 'parent_name' in devl_rate_leaf_create().

Signed-off-by: Michal Wilczynski <michal.wilczynski@intel.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Michal Wilczynski 2022-11-15 11:48:19 +01:00 committed by Jakub Kicinski
parent 04d674f04e
commit f2fc15e271
4 changed files with 14 additions and 5 deletions

View File

@ -91,7 +91,7 @@ int mlx5_esw_offloads_devlink_port_register(struct mlx5_eswitch *esw, u16 vport_
if (err) if (err)
goto reg_err; goto reg_err;
err = devl_rate_leaf_create(dl_port, vport); err = devl_rate_leaf_create(dl_port, vport, NULL);
if (err) if (err)
goto rate_err; goto rate_err;
@ -160,7 +160,7 @@ int mlx5_esw_devlink_sf_port_register(struct mlx5_eswitch *esw, struct devlink_p
if (err) if (err)
return err; return err;
err = devl_rate_leaf_create(dl_port, vport); err = devl_rate_leaf_create(dl_port, vport, NULL);
if (err) if (err)
goto rate_err; goto rate_err;

View File

@ -1401,7 +1401,7 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ
if (nsim_dev_port_is_vf(nsim_dev_port)) { if (nsim_dev_port_is_vf(nsim_dev_port)) {
err = devl_rate_leaf_create(&nsim_dev_port->devlink_port, err = devl_rate_leaf_create(&nsim_dev_port->devlink_port,
nsim_dev_port); nsim_dev_port, NULL);
if (err) if (err)
goto err_nsim_destroy; goto err_nsim_destroy;
} }

View File

@ -1617,10 +1617,12 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro
void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port,
u32 controller, u16 pf, u32 sf, u32 controller, u16 pf, u32 sf,
bool external); bool external);
int devl_rate_leaf_create(struct devlink_port *port, void *priv);
struct devlink_rate * struct devlink_rate *
devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name, devl_rate_node_create(struct devlink *devlink, void *priv, char *node_name,
struct devlink_rate *parent); struct devlink_rate *parent);
int
devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv,
struct devlink_rate *parent);
void devl_rate_leaf_destroy(struct devlink_port *devlink_port); void devl_rate_leaf_destroy(struct devlink_port *devlink_port);
void devl_rate_nodes_destroy(struct devlink *devlink); void devl_rate_nodes_destroy(struct devlink *devlink);
void devlink_port_linecard_set(struct devlink_port *devlink_port, void devlink_port_linecard_set(struct devlink_port *devlink_port,

View File

@ -10435,10 +10435,12 @@ EXPORT_SYMBOL_GPL(devl_rate_node_create);
* devl_rate_leaf_create - create devlink rate leaf * devl_rate_leaf_create - create devlink rate leaf
* @devlink_port: devlink port object to create rate object on * @devlink_port: devlink port object to create rate object on
* @priv: driver private data * @priv: driver private data
* @parent: parent devlink_rate struct
* *
* Create devlink rate object of type leaf on provided @devlink_port. * Create devlink rate object of type leaf on provided @devlink_port.
*/ */
int devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv) int devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv,
struct devlink_rate *parent)
{ {
struct devlink *devlink = devlink_port->devlink; struct devlink *devlink = devlink_port->devlink;
struct devlink_rate *devlink_rate; struct devlink_rate *devlink_rate;
@ -10452,6 +10454,11 @@ int devl_rate_leaf_create(struct devlink_port *devlink_port, void *priv)
if (!devlink_rate) if (!devlink_rate)
return -ENOMEM; return -ENOMEM;
if (parent) {
devlink_rate->parent = parent;
refcount_inc(&devlink_rate->parent->refcnt);
}
devlink_rate->type = DEVLINK_RATE_TYPE_LEAF; devlink_rate->type = DEVLINK_RATE_TYPE_LEAF;
devlink_rate->devlink = devlink; devlink_rate->devlink = devlink;
devlink_rate->devlink_port = devlink_port; devlink_rate->devlink_port = devlink_port;