Message ID | 20241013064540.170722-2-tariqt@nvidia.com (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | net/mlx5: Refactor esw QoS to support generalized operations | expand |
Hi, > From: Carolina Jubran <cjubran@nvidia.com> > > Introduce `esw_qos_create_group_sched_elem` to handle the creation of > group scheduling elements for E-Switch QoS, Transmit Scheduling > Arbiter (TSAR). > > This reduces duplication and simplifies code for TSAR setup. > > Signed-off-by: Carolina Jubran <cjubran@nvidia.com> > Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> > Signed-off-by: Tariq Toukan <tariqt@nvidia.com> > --- > .../net/ethernet/mellanox/mlx5/core/esw/qos.c | 63 +++++++++---------- > 1 file changed, 30 insertions(+), 33 deletions(-) > > diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c > index ee6f76a6f0b5..e357ccd7bfd3 100644 > --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c > +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c > @@ -371,6 +371,33 @@ static int esw_qos_set_group_max_rate(struct mlx5_esw_rate_group *group, > return err; > } > > +static int esw_qos_create_group_sched_elem(struct mlx5_core_dev *dev, u32 parent_element_id, > + u32 *tsar_ix) > +{ > + u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; > + void *attr; > + > + if (!mlx5_qos_element_type_supported(dev, > + SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR, > + SCHEDULING_HIERARCHY_E_SWITCH) || > + !mlx5_qos_tsar_type_supported(dev, > + TSAR_ELEMENT_TSAR_TYPE_DWRR, > + SCHEDULING_HIERARCHY_E_SWITCH)) > + return -EOPNOTSUPP; > + > + MLX5_SET(scheduling_context, tsar_ctx, element_type, > + SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); > + MLX5_SET(scheduling_context, tsar_ctx, parent_element_id, > + parent_element_id); > + attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); > + MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); > + > + return mlx5_create_scheduling_element_cmd(dev, > + SCHEDULING_HIERARCHY_E_SWITCH, > + tsar_ctx, > + tsar_ix); > +} > + > static int esw_qos_vport_create_sched_element(struct mlx5_vport *vport, > u32 max_rate, u32 bw_share) > { > @@ -496,21 +523,10 @@ static void __esw_qos_free_rate_group(struct mlx5_esw_rate_group *group) > static struct mlx5_esw_rate_group * > __esw_qos_create_rate_group(struct mlx5_eswitch *esw, struct netlink_ext_ack *extack) > { > - u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; > struct mlx5_esw_rate_group *group; > - int tsar_ix, err; > - void *attr; > + u32 tsar_ix, err; > > - MLX5_SET(scheduling_context, tsar_ctx, element_type, > - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); > - MLX5_SET(scheduling_context, tsar_ctx, parent_element_id, > - esw->qos.root_tsar_ix); > - attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); > - MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); > - err = mlx5_create_scheduling_element_cmd(esw->dev, > - SCHEDULING_HIERARCHY_E_SWITCH, > - tsar_ctx, > - &tsar_ix); > + err = esw_qos_create_group_sched_elem(esw->dev, esw->qos.root_tsar_ix, &tsar_ix); 'err' is now u32 and esw_qos_create_group_sched_elem returns an int - is this intentional? the error check should still work though. > if (err) { > NL_SET_ERR_MSG_MOD(extack, "E-Switch create TSAR for group failed"); > return ERR_PTR(err); > @@ -591,32 +607,13 @@ static int __esw_qos_destroy_rate_group(struct mlx5_esw_rate_group *group, > > static int esw_qos_create(struct mlx5_eswitch *esw, struct netlink_ext_ack *extack) > { > - u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; > struct mlx5_core_dev *dev = esw->dev; > - void *attr; > int err; > > if (!MLX5_CAP_GEN(dev, qos) || !MLX5_CAP_QOS(dev, esw_scheduling)) > return -EOPNOTSUPP; > > - if (!mlx5_qos_element_type_supported(dev, > - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR, > - SCHEDULING_HIERARCHY_E_SWITCH) || > - !mlx5_qos_tsar_type_supported(dev, > - TSAR_ELEMENT_TSAR_TYPE_DWRR, > - SCHEDULING_HIERARCHY_E_SWITCH)) > - return -EOPNOTSUPP; > - > - MLX5_SET(scheduling_context, tsar_ctx, element_type, > - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); > - > - attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); > - MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); > - > - err = mlx5_create_scheduling_element_cmd(dev, > - SCHEDULING_HIERARCHY_E_SWITCH, > - tsar_ctx, > - &esw->qos.root_tsar_ix); > + err = esw_qos_create_group_sched_elem(esw->dev, 0, &esw->qos.root_tsar_ix); Same here. > if (err) { > esw_warn(dev, "E-Switch create root TSAR failed (%d)\n", err); > return err; > -- > 2.44.0 > >
On 14/10/2024 11:54, Daniel Machon wrote: > Hi, > >> From: Carolina Jubran <cjubran@nvidia.com> >> >> Introduce `esw_qos_create_group_sched_elem` to handle the creation of >> group scheduling elements for E-Switch QoS, Transmit Scheduling >> Arbiter (TSAR). >> >> This reduces duplication and simplifies code for TSAR setup. >> >> Signed-off-by: Carolina Jubran <cjubran@nvidia.com> >> Reviewed-by: Cosmin Ratiu <cratiu@nvidia.com> >> Signed-off-by: Tariq Toukan <tariqt@nvidia.com> >> --- ... >> @@ -496,21 +523,10 @@ static void __esw_qos_free_rate_group(struct mlx5_esw_rate_group *group) >> static struct mlx5_esw_rate_group * >> __esw_qos_create_rate_group(struct mlx5_eswitch *esw, struct netlink_ext_ack *extack) >> { >> - u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; >> struct mlx5_esw_rate_group *group; >> - int tsar_ix, err; >> - void *attr; >> + u32 tsar_ix, err; >> >> - MLX5_SET(scheduling_context, tsar_ctx, element_type, >> - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); >> - MLX5_SET(scheduling_context, tsar_ctx, parent_element_id, >> - esw->qos.root_tsar_ix); >> - attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); >> - MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); >> - err = mlx5_create_scheduling_element_cmd(esw->dev, >> - SCHEDULING_HIERARCHY_E_SWITCH, >> - tsar_ctx, >> - &tsar_ix); >> + err = esw_qos_create_group_sched_elem(esw->dev, esw->qos.root_tsar_ix, &tsar_ix); > > 'err' is now u32 and esw_qos_create_group_sched_elem returns an int - > is this intentional? the error check should still work though. > will fix. > >> if (err) { >> NL_SET_ERR_MSG_MOD(extack, "E-Switch create TSAR for group failed"); >> return ERR_PTR(err); >> @@ -591,32 +607,13 @@ static int __esw_qos_destroy_rate_group(struct mlx5_esw_rate_group *group, >> >> static int esw_qos_create(struct mlx5_eswitch *esw, struct netlink_ext_ack *extack) >> { >> - u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; >> struct mlx5_core_dev *dev = esw->dev; >> - void *attr; >> int err; >> >> if (!MLX5_CAP_GEN(dev, qos) || !MLX5_CAP_QOS(dev, esw_scheduling)) >> return -EOPNOTSUPP; >> >> - if (!mlx5_qos_element_type_supported(dev, >> - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR, >> - SCHEDULING_HIERARCHY_E_SWITCH) || >> - !mlx5_qos_tsar_type_supported(dev, >> - TSAR_ELEMENT_TSAR_TYPE_DWRR, >> - SCHEDULING_HIERARCHY_E_SWITCH)) >> - return -EOPNOTSUPP; >> - >> - MLX5_SET(scheduling_context, tsar_ctx, element_type, >> - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); >> - >> - attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); >> - MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); >> - >> - err = mlx5_create_scheduling_element_cmd(dev, >> - SCHEDULING_HIERARCHY_E_SWITCH, >> - tsar_ctx, >> - &esw->qos.root_tsar_ix); >> + err = esw_qos_create_group_sched_elem(esw->dev, 0, &esw->qos.root_tsar_ix); > > Same here. err is int here. > >> if (err) { >> esw_warn(dev, "E-Switch create root TSAR failed (%d)\n", err); >> return err; >> -- >> 2.44.0 >> >> > Thanks for your comments.
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c index ee6f76a6f0b5..e357ccd7bfd3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c @@ -371,6 +371,33 @@ static int esw_qos_set_group_max_rate(struct mlx5_esw_rate_group *group, return err; } +static int esw_qos_create_group_sched_elem(struct mlx5_core_dev *dev, u32 parent_element_id, + u32 *tsar_ix) +{ + u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; + void *attr; + + if (!mlx5_qos_element_type_supported(dev, + SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR, + SCHEDULING_HIERARCHY_E_SWITCH) || + !mlx5_qos_tsar_type_supported(dev, + TSAR_ELEMENT_TSAR_TYPE_DWRR, + SCHEDULING_HIERARCHY_E_SWITCH)) + return -EOPNOTSUPP; + + MLX5_SET(scheduling_context, tsar_ctx, element_type, + SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); + MLX5_SET(scheduling_context, tsar_ctx, parent_element_id, + parent_element_id); + attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); + MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); + + return mlx5_create_scheduling_element_cmd(dev, + SCHEDULING_HIERARCHY_E_SWITCH, + tsar_ctx, + tsar_ix); +} + static int esw_qos_vport_create_sched_element(struct mlx5_vport *vport, u32 max_rate, u32 bw_share) { @@ -496,21 +523,10 @@ static void __esw_qos_free_rate_group(struct mlx5_esw_rate_group *group) static struct mlx5_esw_rate_group * __esw_qos_create_rate_group(struct mlx5_eswitch *esw, struct netlink_ext_ack *extack) { - u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; struct mlx5_esw_rate_group *group; - int tsar_ix, err; - void *attr; + u32 tsar_ix, err; - MLX5_SET(scheduling_context, tsar_ctx, element_type, - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); - MLX5_SET(scheduling_context, tsar_ctx, parent_element_id, - esw->qos.root_tsar_ix); - attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); - MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); - err = mlx5_create_scheduling_element_cmd(esw->dev, - SCHEDULING_HIERARCHY_E_SWITCH, - tsar_ctx, - &tsar_ix); + err = esw_qos_create_group_sched_elem(esw->dev, esw->qos.root_tsar_ix, &tsar_ix); if (err) { NL_SET_ERR_MSG_MOD(extack, "E-Switch create TSAR for group failed"); return ERR_PTR(err); @@ -591,32 +607,13 @@ static int __esw_qos_destroy_rate_group(struct mlx5_esw_rate_group *group, static int esw_qos_create(struct mlx5_eswitch *esw, struct netlink_ext_ack *extack) { - u32 tsar_ctx[MLX5_ST_SZ_DW(scheduling_context)] = {}; struct mlx5_core_dev *dev = esw->dev; - void *attr; int err; if (!MLX5_CAP_GEN(dev, qos) || !MLX5_CAP_QOS(dev, esw_scheduling)) return -EOPNOTSUPP; - if (!mlx5_qos_element_type_supported(dev, - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR, - SCHEDULING_HIERARCHY_E_SWITCH) || - !mlx5_qos_tsar_type_supported(dev, - TSAR_ELEMENT_TSAR_TYPE_DWRR, - SCHEDULING_HIERARCHY_E_SWITCH)) - return -EOPNOTSUPP; - - MLX5_SET(scheduling_context, tsar_ctx, element_type, - SCHEDULING_CONTEXT_ELEMENT_TYPE_TSAR); - - attr = MLX5_ADDR_OF(scheduling_context, tsar_ctx, element_attributes); - MLX5_SET(tsar_element, attr, tsar_type, TSAR_ELEMENT_TSAR_TYPE_DWRR); - - err = mlx5_create_scheduling_element_cmd(dev, - SCHEDULING_HIERARCHY_E_SWITCH, - tsar_ctx, - &esw->qos.root_tsar_ix); + err = esw_qos_create_group_sched_elem(esw->dev, 0, &esw->qos.root_tsar_ix); if (err) { esw_warn(dev, "E-Switch create root TSAR failed (%d)\n", err); return err;