mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-26 13:47:26 +00:00
net/mlx5: Add support for setting parent of nodes
Introduce `mlx5_esw_devlink_rate_node_parent_set()` to allow assigning a parent to scheduling nodes. Implement `mlx5_esw_qos_node_update_parent()` and `mlx5_esw_qos_node_validate_set_parent()` to enforce constraints on node reassignment. Don't allow reassignment of nodes with active rate objects. Update `esw_qos_node_set_parent()` to handle cases where the parent is NULL. A NULL parent indicates that the scheduling element is attached to the root scheduling element, and since only rate nodes can be connected to the root, this update is now necessary. Signed-off-by: Carolina Jubran <cjubran@nvidia.com> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> Link: https://patch.msgid.link/1741642016-44918-5-git-send-email-tariqt@nvidia.com Reviewed-by: Jacob Keller <jacob.e.keller@intel.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
parent
f88c349c75
commit
9c7bbf4c33
@ -328,6 +328,7 @@ static const struct devlink_ops mlx5_devlink_ops = {
|
||||
.rate_node_new = mlx5_esw_devlink_rate_node_new,
|
||||
.rate_node_del = mlx5_esw_devlink_rate_node_del,
|
||||
.rate_leaf_parent_set = mlx5_esw_devlink_rate_leaf_parent_set,
|
||||
.rate_node_parent_set = mlx5_esw_devlink_rate_node_parent_set,
|
||||
#endif
|
||||
#ifdef CONFIG_MLX5_SF_MANAGER
|
||||
.port_new = mlx5_devlink_sf_port_new,
|
||||
|
@ -111,9 +111,9 @@ esw_qos_node_set_parent(struct mlx5_esw_sched_node *node, struct mlx5_esw_sched_
|
||||
{
|
||||
list_del_init(&node->entry);
|
||||
node->parent = parent;
|
||||
list_add_tail(&node->entry, &parent->children);
|
||||
node->esw = parent->esw;
|
||||
node->level = parent->level + 1;
|
||||
if (parent)
|
||||
node->esw = parent->esw;
|
||||
esw_qos_node_attach_to_parent(node);
|
||||
}
|
||||
|
||||
void mlx5_esw_qos_vport_qos_free(struct mlx5_vport *vport)
|
||||
@ -1018,3 +1018,105 @@ int mlx5_esw_devlink_rate_leaf_parent_set(struct devlink_rate *devlink_rate,
|
||||
node = parent_priv;
|
||||
return mlx5_esw_qos_vport_update_parent(vport, node, extack);
|
||||
}
|
||||
|
||||
static int
|
||||
mlx5_esw_qos_node_validate_set_parent(struct mlx5_esw_sched_node *node,
|
||||
struct mlx5_esw_sched_node *parent,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
u8 new_level, max_level;
|
||||
|
||||
if (parent && parent->esw != node->esw) {
|
||||
NL_SET_ERR_MSG_MOD(extack,
|
||||
"Cannot assign node to another E-Switch");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
if (!list_empty(&node->children)) {
|
||||
NL_SET_ERR_MSG_MOD(extack,
|
||||
"Cannot reassign a node that contains rate objects");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
new_level = parent ? parent->level + 1 : 2;
|
||||
max_level = 1 << MLX5_CAP_QOS(node->esw->dev, log_esw_max_sched_depth);
|
||||
if (new_level > max_level) {
|
||||
NL_SET_ERR_MSG_MOD(extack,
|
||||
"Node hierarchy depth exceeds the maximum supported level");
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int esw_qos_vports_node_update_parent(struct mlx5_esw_sched_node *node,
|
||||
struct mlx5_esw_sched_node *parent,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlx5_esw_sched_node *curr_parent = node->parent;
|
||||
struct mlx5_eswitch *esw = node->esw;
|
||||
u32 parent_ix;
|
||||
int err;
|
||||
|
||||
parent_ix = parent ? parent->ix : node->esw->qos.root_tsar_ix;
|
||||
mlx5_destroy_scheduling_element_cmd(esw->dev,
|
||||
SCHEDULING_HIERARCHY_E_SWITCH,
|
||||
node->ix);
|
||||
err = esw_qos_create_node_sched_elem(esw->dev, parent_ix,
|
||||
node->max_rate, 0, &node->ix);
|
||||
if (err) {
|
||||
NL_SET_ERR_MSG_MOD(extack,
|
||||
"Failed to create a node under the new hierarchy.");
|
||||
if (esw_qos_create_node_sched_elem(esw->dev, curr_parent->ix,
|
||||
node->max_rate,
|
||||
node->bw_share,
|
||||
&node->ix))
|
||||
esw_warn(esw->dev, "Node restore QoS failed\n");
|
||||
|
||||
return err;
|
||||
}
|
||||
esw_qos_node_set_parent(node, parent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int mlx5_esw_qos_node_update_parent(struct mlx5_esw_sched_node *node,
|
||||
struct mlx5_esw_sched_node *parent,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlx5_esw_sched_node *curr_parent;
|
||||
struct mlx5_eswitch *esw = node->esw;
|
||||
int err;
|
||||
|
||||
err = mlx5_esw_qos_node_validate_set_parent(node, parent, extack);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
esw_qos_lock(esw);
|
||||
curr_parent = node->parent;
|
||||
err = esw_qos_vports_node_update_parent(node, parent, extack);
|
||||
if (err)
|
||||
goto out;
|
||||
|
||||
esw_qos_normalize_min_rate(esw, curr_parent, extack);
|
||||
esw_qos_normalize_min_rate(esw, parent, extack);
|
||||
|
||||
out:
|
||||
esw_qos_unlock(esw);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int mlx5_esw_devlink_rate_node_parent_set(struct devlink_rate *devlink_rate,
|
||||
struct devlink_rate *parent,
|
||||
void *priv, void *parent_priv,
|
||||
struct netlink_ext_ack *extack)
|
||||
{
|
||||
struct mlx5_esw_sched_node *node = priv, *parent_node;
|
||||
|
||||
if (!parent)
|
||||
return mlx5_esw_qos_node_update_parent(node, NULL, extack);
|
||||
|
||||
parent_node = parent_priv;
|
||||
return mlx5_esw_qos_node_update_parent(node, parent_node, extack);
|
||||
}
|
||||
|
@ -33,6 +33,10 @@ int mlx5_esw_devlink_rate_leaf_parent_set(struct devlink_rate *devlink_rate,
|
||||
struct devlink_rate *parent,
|
||||
void *priv, void *parent_priv,
|
||||
struct netlink_ext_ack *extack);
|
||||
int mlx5_esw_devlink_rate_node_parent_set(struct devlink_rate *devlink_rate,
|
||||
struct devlink_rate *parent,
|
||||
void *priv, void *parent_priv,
|
||||
struct netlink_ext_ack *extack);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user