From: Cosmin Ratiu This is the canonical name used in the core, so try to be consistent. No-op change. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c | 8 ++++---- drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h | 2 +- .../net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index d9adb993e64d..4f2fa6756b82 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -1072,11 +1072,11 @@ void mlx5e_psp_unregister(struct mlx5e_priv *priv) { struct mlx5e_psp *psp = priv->psp; - if (!psp || !psp->psp) + if (!psp || !psp->psd) return; - psp_dev_unregister(psp->psp); - psp->psp = NULL; + psp_dev_unregister(psp->psd); + psp->psd = NULL; } void mlx5e_psp_register(struct mlx5e_priv *priv) @@ -1100,7 +1100,7 @@ void mlx5e_psp_register(struct mlx5e_priv *priv) psd); return; } - psp->psp = psd; + psp->psd = psd; } int mlx5e_psp_init(struct mlx5e_priv *priv) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h index 6b62fef0d9a7..a53f90f7c341 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h @@ -23,7 +23,7 @@ struct mlx5e_psp_stats { }; struct mlx5e_psp { - struct psp_dev *psp; + struct psp_dev *psd; struct psp_dev_caps caps; struct mlx5e_psp_fs *fs; atomic_t tx_key_cnt; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c index ef7f5338540f..c2f9899d23a5 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c @@ -124,7 +124,7 @@ bool mlx5e_psp_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff * { u32 psp_meta_data = be32_to_cpu(cqe->ft_metadata); struct mlx5e_priv *priv = netdev_priv(netdev); - u16 dev_id = priv->psp->psp->id; + u16 dev_id = priv->psp->psd->id; bool strip_icv = true; u8 generation = 0; -- 2.44.0 From: Cosmin Ratiu PSP steering uses three mutexes to serialize steering rule init/cleanup. But init/cleanup are already serialized with the higher level devlink lock (for both device init and esw mode changes), so there's no need for multiple additional mutexes. Remove them to make room for the new changes. Later in the series, the netdev lock will be used to serialize PSP steering changes from multiple sources, so don't bother adding assertions now only for them to be overwritten later. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 43 +++---------------- 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index 4f2fa6756b82..d4686b5af776 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -26,7 +26,6 @@ struct mlx5e_psp_tx { struct mlx5_flow_table *ft; struct mlx5_flow_group *fg; struct mlx5_flow_handle *rule; - struct mutex mutex; /* Protect PSP TX steering */ u32 refcnt; struct mlx5_fc *tx_counter; }; @@ -48,7 +47,6 @@ struct mlx5e_accel_fs_psp_prot { struct mlx5_flow_destination default_dest; struct mlx5e_psp_rx_err rx_err; u32 refcnt; - struct mutex prot_mutex; /* protect ESP4/ESP6 protocol */ struct mlx5_flow_handle *def_rule; }; @@ -485,15 +483,14 @@ static int accel_psp_fs_rx_ft_get(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ ttc = mlx5e_fs_get_ttc(fs->fs, false); accel_psp = fs->rx_fs; fs_prot = &accel_psp->fs_prot[type]; - mutex_lock(&fs_prot->prot_mutex); if (fs_prot->refcnt++) - goto out; + return 0; /* create FT */ err = accel_psp_fs_rx_create(fs, type); if (err) { fs_prot->refcnt--; - goto out; + return err; } /* connect */ @@ -501,9 +498,7 @@ static int accel_psp_fs_rx_ft_get(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ dest.ft = fs_prot->ft; mlx5_ttc_fwd_dest(ttc, fs_psp2tt(type), &dest); -out: - mutex_unlock(&fs_prot->prot_mutex); - return err; + return 0; } static void accel_psp_fs_rx_ft_put(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type) @@ -514,18 +509,14 @@ static void accel_psp_fs_rx_ft_put(struct mlx5e_psp_fs *fs, enum accel_fs_psp_ty accel_psp = fs->rx_fs; fs_prot = &accel_psp->fs_prot[type]; - mutex_lock(&fs_prot->prot_mutex); if (--fs_prot->refcnt) - goto out; + return; /* disconnect */ mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(type)); /* remove FT */ accel_psp_fs_rx_destroy(fs, type); - -out: - mutex_unlock(&fs_prot->prot_mutex); } static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs) @@ -544,7 +535,6 @@ static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs) mlx5_fc_destroy(fs->mdev, accel_psp->rx_counter); for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { fs_prot = &accel_psp->fs_prot[i]; - mutex_destroy(&fs_prot->prot_mutex); WARN_ON(fs_prot->refcnt); } kfree(fs->rx_fs); @@ -553,22 +543,15 @@ static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs) static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs) { - struct mlx5e_accel_fs_psp_prot *fs_prot; struct mlx5e_accel_fs_psp *accel_psp; struct mlx5_core_dev *mdev = fs->mdev; struct mlx5_fc *flow_counter; - enum accel_fs_psp_type i; int err; accel_psp = kzalloc_obj(*accel_psp); if (!accel_psp) return -ENOMEM; - for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { - fs_prot = &accel_psp->fs_prot[i]; - mutex_init(&fs_prot->prot_mutex); - } - flow_counter = mlx5_fc_create(mdev, false); if (IS_ERR(flow_counter)) { mlx5_core_warn(mdev, @@ -623,10 +606,6 @@ static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs) mlx5_fc_destroy(mdev, accel_psp->rx_counter); accel_psp->rx_counter = NULL; out_err: - for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { - fs_prot = &accel_psp->fs_prot[i]; - mutex_destroy(&fs_prot->prot_mutex); - } kfree(accel_psp); fs->rx_fs = NULL; @@ -763,17 +742,14 @@ static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs) static int accel_psp_fs_tx_ft_get(struct mlx5e_psp_fs *fs) { struct mlx5e_psp_tx *tx_fs = fs->tx_fs; - int err = 0; + int err; - mutex_lock(&tx_fs->mutex); if (tx_fs->refcnt++) - goto out; + return 0; err = accel_psp_fs_tx_create_ft_table(fs); if (err) tx_fs->refcnt--; -out: - mutex_unlock(&tx_fs->mutex); return err; } @@ -781,13 +757,10 @@ static void accel_psp_fs_tx_ft_put(struct mlx5e_psp_fs *fs) { struct mlx5e_psp_tx *tx_fs = fs->tx_fs; - mutex_lock(&tx_fs->mutex); if (--tx_fs->refcnt) - goto out; + return; accel_psp_fs_tx_destroy(tx_fs); -out: - mutex_unlock(&tx_fs->mutex); } static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) @@ -798,7 +771,6 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) return; mlx5_fc_destroy(fs->mdev, tx_fs->tx_counter); - mutex_destroy(&tx_fs->mutex); WARN_ON(tx_fs->refcnt); kfree(tx_fs); fs->tx_fs = NULL; @@ -828,7 +800,6 @@ static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs) return PTR_ERR(flow_counter); } tx_fs->tx_counter = flow_counter; - mutex_init(&tx_fs->mutex); tx_fs->ns = ns; fs->tx_fs = tx_fs; return 0; -- 2.44.0 From: Cosmin Ratiu PSP steering uses reference counting for TX and RX steering tables, but there's only a single reference for each acquired and thus the reference counting is unnecessary. Remove it and consolidate functions to simplify the code. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 129 +++++------------- 1 file changed, 33 insertions(+), 96 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index d4686b5af776..a69c4e2821e9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -26,7 +26,6 @@ struct mlx5e_psp_tx { struct mlx5_flow_table *ft; struct mlx5_flow_group *fg; struct mlx5_flow_handle *rule; - u32 refcnt; struct mlx5_fc *tx_counter; }; @@ -46,7 +45,6 @@ struct mlx5e_accel_fs_psp_prot { struct mlx5_modify_hdr *rx_modify_hdr; struct mlx5_flow_destination default_dest; struct mlx5e_psp_rx_err rx_err; - u32 refcnt; struct mlx5_flow_handle *def_rule; }; @@ -469,75 +467,18 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ return err; } -static int accel_psp_fs_rx_ft_get(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type) -{ - struct mlx5e_accel_fs_psp_prot *fs_prot; - struct mlx5_flow_destination dest = {}; - struct mlx5e_accel_fs_psp *accel_psp; - struct mlx5_ttc_table *ttc; - int err = 0; - - if (!fs || !fs->rx_fs) - return -EINVAL; - - ttc = mlx5e_fs_get_ttc(fs->fs, false); - accel_psp = fs->rx_fs; - fs_prot = &accel_psp->fs_prot[type]; - if (fs_prot->refcnt++) - return 0; - - /* create FT */ - err = accel_psp_fs_rx_create(fs, type); - if (err) { - fs_prot->refcnt--; - return err; - } - - /* connect */ - dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; - dest.ft = fs_prot->ft; - mlx5_ttc_fwd_dest(ttc, fs_psp2tt(type), &dest); - - return 0; -} - -static void accel_psp_fs_rx_ft_put(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type) -{ - struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false); - struct mlx5e_accel_fs_psp_prot *fs_prot; - struct mlx5e_accel_fs_psp *accel_psp; - - accel_psp = fs->rx_fs; - fs_prot = &accel_psp->fs_prot[type]; - if (--fs_prot->refcnt) - return; - - /* disconnect */ - mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(type)); - - /* remove FT */ - accel_psp_fs_rx_destroy(fs, type); -} - static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs) { - struct mlx5e_accel_fs_psp_prot *fs_prot; - struct mlx5e_accel_fs_psp *accel_psp; - enum accel_fs_psp_type i; + struct mlx5e_accel_fs_psp *accel_psp = fs->rx_fs; - if (!fs->rx_fs) + if (!accel_psp) return; - accel_psp = fs->rx_fs; mlx5_fc_destroy(fs->mdev, accel_psp->rx_bad_counter); mlx5_fc_destroy(fs->mdev, accel_psp->rx_err_counter); mlx5_fc_destroy(fs->mdev, accel_psp->rx_auth_fail_counter); mlx5_fc_destroy(fs->mdev, accel_psp->rx_counter); - for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { - fs_prot = &accel_psp->fs_prot[i]; - WARN_ON(fs_prot->refcnt); - } - kfree(fs->rx_fs); + kfree(accel_psp); fs->rx_fs = NULL; } @@ -614,17 +555,27 @@ static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs) void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) { + struct mlx5_ttc_table *ttc; + struct mlx5e_psp_fs *fs; int i; if (!priv->psp) return; - for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) - accel_psp_fs_rx_ft_put(priv->psp->fs, i); + fs = priv->psp->fs; + ttc = mlx5e_fs_get_ttc(fs->fs, false); + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { + /* disconnect */ + mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); + + /* remove FT */ + accel_psp_fs_rx_destroy(fs, i); + } } int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) { + struct mlx5_ttc_table *ttc; struct mlx5e_psp_fs *fs; int err, i; @@ -632,19 +583,30 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) return 0; fs = priv->psp->fs; + ttc = mlx5e_fs_get_ttc(fs->fs, false); + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { - err = accel_psp_fs_rx_ft_get(fs, i); + struct mlx5e_accel_fs_psp_prot *fs_prot; + struct mlx5_flow_destination dest = {}; + + /* create FT */ + err = accel_psp_fs_rx_create(fs, i); if (err) goto out_err; + + /* connect */ + dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; + fs_prot = &fs->rx_fs->fs_prot[i]; + dest.ft = fs_prot->ft; + mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest); } return 0; out_err: - i--; - while (i >= 0) { - accel_psp_fs_rx_ft_put(fs, i); - --i; + while (--i >= 0) { + mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); + accel_psp_fs_rx_destroy(fs, i); } return err; @@ -739,30 +701,6 @@ static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs) mlx5_destroy_flow_table(tx_fs->ft); } -static int accel_psp_fs_tx_ft_get(struct mlx5e_psp_fs *fs) -{ - struct mlx5e_psp_tx *tx_fs = fs->tx_fs; - int err; - - if (tx_fs->refcnt++) - return 0; - - err = accel_psp_fs_tx_create_ft_table(fs); - if (err) - tx_fs->refcnt--; - return err; -} - -static void accel_psp_fs_tx_ft_put(struct mlx5e_psp_fs *fs) -{ - struct mlx5e_psp_tx *tx_fs = fs->tx_fs; - - if (--tx_fs->refcnt) - return; - - accel_psp_fs_tx_destroy(tx_fs); -} - static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) { struct mlx5e_psp_tx *tx_fs = fs->tx_fs; @@ -771,7 +709,6 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) return; mlx5_fc_destroy(fs->mdev, tx_fs->tx_counter); - WARN_ON(tx_fs->refcnt); kfree(tx_fs); fs->tx_fs = NULL; } @@ -844,7 +781,7 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) if (!priv->psp) return; - accel_psp_fs_tx_ft_put(priv->psp->fs); + accel_psp_fs_tx_destroy(priv->psp->fs->tx_fs); } int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) @@ -852,7 +789,7 @@ int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) if (!priv->psp) return 0; - return accel_psp_fs_tx_ft_get(priv->psp->fs); + return accel_psp_fs_tx_create_ft_table(priv->psp->fs); } static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs) -- 2.44.0 From: Cosmin Ratiu The rx_err table is different than the others, having separate functions to create the flow rules in addition to the flow table. Merge the add/delete rules functions with the ft create/delete functions for consistency. Noop change. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 78 +++++++------------ 1 file changed, 30 insertions(+), 48 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index a69c4e2821e9..5c34c0be997a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -73,8 +73,8 @@ static enum mlx5_traffic_types fs_psp2tt(enum accel_fs_psp_type i) return MLX5_TT_IPV6_UDP; } -static void accel_psp_fs_rx_err_del_rules(struct mlx5e_psp_fs *fs, - struct mlx5e_psp_rx_err *rx_err) +static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_rx_err *rx_err) { if (rx_err->bad_rule) { mlx5_del_flow_rules(rx_err->bad_rule); @@ -100,12 +100,6 @@ static void accel_psp_fs_rx_err_del_rules(struct mlx5e_psp_fs *fs, mlx5_modify_header_dealloc(fs->mdev, rx_err->copy_modify_hdr); rx_err->copy_modify_hdr = NULL; } -} - -static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs, - struct mlx5e_psp_rx_err *rx_err) -{ - accel_psp_fs_rx_err_del_rules(fs, rx_err); if (rx_err->ft) { mlx5_destroy_flow_table(rx_err->ft); @@ -125,23 +119,40 @@ static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec, MLX5_SET(fte_match_set_misc2, misc_params_2, psp_syndrome, syndrome); } -static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs, - struct mlx5e_accel_fs_psp_prot *fs_prot, - struct mlx5e_psp_rx_err *rx_err) +static +int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, + struct mlx5e_accel_fs_psp_prot *fs_prot, + struct mlx5e_psp_rx_err *rx_err) { + struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false); u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {}; + struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_core_dev *mdev = fs->mdev; struct mlx5_flow_destination dest[2]; struct mlx5_flow_act flow_act = {}; struct mlx5_modify_hdr *modify_hdr; struct mlx5_flow_handle *fte; struct mlx5_flow_spec *spec; + struct mlx5_flow_table *ft; int err = 0; spec = kzalloc_obj(*spec); if (!spec) return -ENOMEM; + ft_attr.max_fte = 2; + ft_attr.autogroup.max_num_groups = 2; + ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; + ft_attr.prio = MLX5E_NIC_PRIO; + ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr); + if (IS_ERR(ft)) { + err = PTR_ERR(ft); + mlx5_core_err(fs->mdev, + "fail to create psp rx inline ft err=%d\n", err); + goto out_spec; + } + rx_err->ft = ft; + /* Action to copy 7 bit psp_syndrome to regB[23:29] */ MLX5_SET(copy_action_in, action, action_type, MLX5_ACTION_TYPE_COPY); MLX5_SET(copy_action_in, action, src_field, MLX5_ACTION_IN_FIELD_PSP_SYNDROME); @@ -156,8 +167,9 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs, err = PTR_ERR(modify_hdr); mlx5_core_err(mdev, "fail to alloc psp copy modify_header_id err=%d\n", err); - goto out_spec; + goto out_ft; } + rx_err->copy_modify_hdr = modify_hdr; accel_psp_setup_syndrome_match(spec, PSP_OK); /* create fte */ @@ -173,7 +185,7 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs, if (IS_ERR(fte)) { err = PTR_ERR(fte); mlx5_core_err(mdev, "fail to add psp rx err copy rule err=%d\n", err); - goto out; + goto out_modhdr; } rx_err->rule = fte; @@ -230,8 +242,6 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs, } rx_err->bad_rule = fte; - rx_err->copy_modify_hdr = modify_hdr; - goto out_spec; out_drop_error_rule: @@ -243,45 +253,17 @@ static int accel_psp_fs_rx_err_add_rule(struct mlx5e_psp_fs *fs, out_drop_rule: mlx5_del_flow_rules(rx_err->rule); rx_err->rule = NULL; -out: +out_modhdr: mlx5_modify_header_dealloc(mdev, modify_hdr); + rx_err->copy_modify_hdr = NULL; +out_ft: + mlx5_destroy_flow_table(rx_err->ft); + rx_err->ft = NULL; out_spec: kfree(spec); return err; } -static int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, - struct mlx5e_accel_fs_psp_prot *fs_prot, - struct mlx5e_psp_rx_err *rx_err) -{ - struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false); - struct mlx5_flow_table_attr ft_attr = {}; - struct mlx5_flow_table *ft; - int err; - - ft_attr.max_fte = 2; - ft_attr.autogroup.max_num_groups = 2; - ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; // MLX5E_ACCEL_FS_TCP_FT_LEVEL - ft_attr.prio = MLX5E_NIC_PRIO; - ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr); - if (IS_ERR(ft)) { - err = PTR_ERR(ft); - mlx5_core_err(fs->mdev, "fail to create psp rx inline ft err=%d\n", err); - return err; - } - - rx_err->ft = ft; - err = accel_psp_fs_rx_err_add_rule(fs, fs_prot, rx_err); - if (err) - goto out_err; - - return 0; - -out_err: - mlx5_destroy_flow_table(ft); - rx_err->ft = NULL; - return err; -} static void accel_psp_fs_rx_fs_destroy(struct mlx5e_psp_fs *fs, struct mlx5e_accel_fs_psp_prot *fs_prot) -- 2.44.0 From: Cosmin Ratiu Add helper functions for creating and destroying PSP steering objects to reduce code duplication. This will become more relevant in future patches which add more steering tables/groups/flows. One nice side-effect of this is that the cleanup functions become idempotent and can be used instead of long goto chains. This further simplifies the code. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 304 +++++++++--------- 1 file changed, 149 insertions(+), 155 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index 5c34c0be997a..a1c7ca4ae722 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -73,38 +73,103 @@ static enum mlx5_traffic_types fs_psp2tt(enum accel_fs_psp_type i) return MLX5_TT_IPV6_UDP; } -static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs, - struct mlx5e_psp_rx_err *rx_err) +static int accel_psp_fs_create_ft(struct mlx5e_psp_fs *fs, + struct mlx5_flow_table_attr *ft_attr, + struct mlx5_flow_table **ft) { - if (rx_err->bad_rule) { - mlx5_del_flow_rules(rx_err->bad_rule); - rx_err->bad_rule = NULL; + struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false); + int err = 0; + + *ft = mlx5_create_auto_grouped_flow_table(ns, ft_attr); + if (IS_ERR(*ft)) { + err = PTR_ERR(*ft); + *ft = NULL; } - if (rx_err->err_rule) { - mlx5_del_flow_rules(rx_err->err_rule); - rx_err->err_rule = NULL; + return err; +} + +static void accel_psp_fs_destroy_ft(struct mlx5_flow_table **table) +{ + if (*table) { + mlx5_destroy_flow_table(*table); + *table = NULL; + } +} + +static void accel_psp_fs_del_flow_rule(struct mlx5_flow_handle **rule) +{ + if (*rule) { + mlx5_del_flow_rules(*rule); + *rule = NULL; } +} + +static int accel_psp_fs_create_miss_group(struct mlx5_flow_table *ft, + struct mlx5_flow_group **group) +{ + int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); + u32 *in = kvzalloc(inlen, GFP_KERNEL); + int err = 0; + + if (!in) + return -ENOMEM; - if (rx_err->auth_fail_rule) { - mlx5_del_flow_rules(rx_err->auth_fail_rule); - rx_err->auth_fail_rule = NULL; + MLX5_SET(create_flow_group_in, in, start_flow_index, ft->max_fte - 1); + MLX5_SET(create_flow_group_in, in, end_flow_index, ft->max_fte - 1); + *group = mlx5_create_flow_group(ft, in); + if (IS_ERR(*group)) { + err = PTR_ERR(*group); + *group = NULL; } + kvfree(in); + + return err; +} - if (rx_err->rule) { - mlx5_del_flow_rules(rx_err->rule); - rx_err->rule = NULL; +static void accel_psp_fs_destroy_flow_group(struct mlx5_flow_group **group) +{ + if (*group) { + mlx5_destroy_flow_group(*group); + *group = NULL; } +} +static int accel_psp_fs_create_counter(struct mlx5_core_dev *dev, + struct mlx5_fc **counter) +{ + *counter = mlx5_fc_create(dev, false); + if (IS_ERR(*counter)) { + int err = PTR_ERR(*counter); + + *counter = NULL; + return err; + } + + return 0; +} + +static void accel_psp_fs_destroy_counter(struct mlx5_core_dev *dev, + struct mlx5_fc **counter) +{ + if (*counter) { + mlx5_fc_destroy(dev, *counter); + *counter = NULL; + } +} + +static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_rx_err *rx_err) +{ + accel_psp_fs_del_flow_rule(&rx_err->bad_rule); + accel_psp_fs_del_flow_rule(&rx_err->err_rule); + accel_psp_fs_del_flow_rule(&rx_err->auth_fail_rule); + accel_psp_fs_del_flow_rule(&rx_err->rule); if (rx_err->copy_modify_hdr) { mlx5_modify_header_dealloc(fs->mdev, rx_err->copy_modify_hdr); rx_err->copy_modify_hdr = NULL; } - - if (rx_err->ft) { - mlx5_destroy_flow_table(rx_err->ft); - rx_err->ft = NULL; - } + accel_psp_fs_destroy_ft(&rx_err->ft); } static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec, @@ -124,7 +189,6 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, struct mlx5e_accel_fs_psp_prot *fs_prot, struct mlx5e_psp_rx_err *rx_err) { - struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false); u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {}; struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_core_dev *mdev = fs->mdev; @@ -133,7 +197,6 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, struct mlx5_modify_hdr *modify_hdr; struct mlx5_flow_handle *fte; struct mlx5_flow_spec *spec; - struct mlx5_flow_table *ft; int err = 0; spec = kzalloc_obj(*spec); @@ -144,14 +207,12 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, ft_attr.autogroup.max_num_groups = 2; ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; ft_attr.prio = MLX5E_NIC_PRIO; - ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr); - if (IS_ERR(ft)) { - err = PTR_ERR(ft); + err = accel_psp_fs_create_ft(fs, &ft_attr, &rx_err->ft); + if (err) { mlx5_core_err(fs->mdev, "fail to create psp rx inline ft err=%d\n", err); - goto out_spec; + goto out_err; } - rx_err->ft = ft; /* Action to copy 7 bit psp_syndrome to regB[23:29] */ MLX5_SET(copy_action_in, action, action_type, MLX5_ACTION_TYPE_COPY); @@ -167,7 +228,7 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, err = PTR_ERR(modify_hdr); mlx5_core_err(mdev, "fail to alloc psp copy modify_header_id err=%d\n", err); - goto out_ft; + goto out_err; } rx_err->copy_modify_hdr = modify_hdr; @@ -184,8 +245,9 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 2); if (IS_ERR(fte)) { err = PTR_ERR(fte); - mlx5_core_err(mdev, "fail to add psp rx err copy rule err=%d\n", err); - goto out_modhdr; + mlx5_core_err(mdev, "fail to add psp rx err rule err=%d\n", + err); + goto out_err; } rx_err->rule = fte; @@ -203,7 +265,7 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, err = PTR_ERR(fte); mlx5_core_err(mdev, "fail to add psp rx auth fail drop rule err=%d\n", err); - goto out_drop_rule; + goto out_err; } rx_err->auth_fail_rule = fte; @@ -221,7 +283,7 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, err = PTR_ERR(fte); mlx5_core_err(mdev, "fail to add psp rx framing err drop rule err=%d\n", err); - goto out_drop_auth_fail_rule; + goto out_err; } rx_err->err_rule = fte; @@ -238,27 +300,14 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, err = PTR_ERR(fte); mlx5_core_err(mdev, "fail to add psp rx misc. err drop rule err=%d\n", err); - goto out_drop_error_rule; + goto out_err; } rx_err->bad_rule = fte; goto out_spec; -out_drop_error_rule: - mlx5_del_flow_rules(rx_err->err_rule); - rx_err->err_rule = NULL; -out_drop_auth_fail_rule: - mlx5_del_flow_rules(rx_err->auth_fail_rule); - rx_err->auth_fail_rule = NULL; -out_drop_rule: - mlx5_del_flow_rules(rx_err->rule); - rx_err->rule = NULL; -out_modhdr: - mlx5_modify_header_dealloc(mdev, modify_hdr); - rx_err->copy_modify_hdr = NULL; -out_ft: - mlx5_destroy_flow_table(rx_err->ft); - rx_err->ft = NULL; +out_err: + accel_psp_fs_rx_err_destroy_ft(fs, rx_err); out_spec: kfree(spec); return err; @@ -268,30 +317,14 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, static void accel_psp_fs_rx_fs_destroy(struct mlx5e_psp_fs *fs, struct mlx5e_accel_fs_psp_prot *fs_prot) { - if (fs_prot->def_rule) { - mlx5_del_flow_rules(fs_prot->def_rule); - fs_prot->def_rule = NULL; - } - + accel_psp_fs_del_flow_rule(&fs_prot->def_rule); if (fs_prot->rx_modify_hdr) { mlx5_modify_header_dealloc(fs->mdev, fs_prot->rx_modify_hdr); fs_prot->rx_modify_hdr = NULL; } - - if (fs_prot->miss_rule) { - mlx5_del_flow_rules(fs_prot->miss_rule); - fs_prot->miss_rule = NULL; - } - - if (fs_prot->miss_group) { - mlx5_destroy_flow_group(fs_prot->miss_group); - fs_prot->miss_group = NULL; - } - - if (fs_prot->ft) { - mlx5_destroy_flow_table(fs_prot->ft); - fs_prot->ft = NULL; - } + accel_psp_fs_del_flow_rule(&fs_prot->miss_rule); + accel_psp_fs_destroy_flow_group(&fs_prot->miss_group); + accel_psp_fs_destroy_ft(&fs_prot->ft); } static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port) @@ -306,55 +339,42 @@ static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port) static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs, struct mlx5e_accel_fs_psp_prot *fs_prot) { - struct mlx5_flow_namespace *ns = mlx5e_fs_get_ns(fs->fs, false); u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {}; - int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); struct mlx5_modify_hdr *modify_hdr = NULL; struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_flow_destination dest = {}; struct mlx5_core_dev *mdev = fs->mdev; - struct mlx5_flow_group *miss_group; MLX5_DECLARE_FLOW_ACT(flow_act); struct mlx5_flow_handle *rule; struct mlx5_flow_spec *spec; - struct mlx5_flow_table *ft; - u32 *flow_group_in; int err = 0; - flow_group_in = kvzalloc(inlen, GFP_KERNEL); spec = kvzalloc_obj(*spec); - if (!flow_group_in || !spec) { - err = -ENOMEM; - goto out; - } + if (!spec) + return -ENOMEM; /* Create FT */ ft_attr.max_fte = 2; ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_LEVEL; - ft_attr.prio = MLX5E_NIC_PRIO; ft_attr.autogroup.num_reserved_entries = 1; ft_attr.autogroup.max_num_groups = 1; - ft = mlx5_create_auto_grouped_flow_table(ns, &ft_attr); - if (IS_ERR(ft)) { - err = PTR_ERR(ft); + ft_attr.prio = MLX5E_NIC_PRIO; + err = accel_psp_fs_create_ft(fs, &ft_attr, &fs_prot->ft); + if (err) { mlx5_core_err(mdev, "fail to create psp rx ft err=%d\n", err); goto out_err; } - fs_prot->ft = ft; /* Create miss_group */ - MLX5_SET(create_flow_group_in, flow_group_in, start_flow_index, ft->max_fte - 1); - MLX5_SET(create_flow_group_in, flow_group_in, end_flow_index, ft->max_fte - 1); - miss_group = mlx5_create_flow_group(ft, flow_group_in); - if (IS_ERR(miss_group)) { - err = PTR_ERR(miss_group); + err = accel_psp_fs_create_miss_group(fs_prot->ft, &fs_prot->miss_group); + if (err) { mlx5_core_err(mdev, "fail to create psp rx miss_group err=%d\n", err); goto out_err; } - fs_prot->miss_group = miss_group; /* Create miss rule */ - rule = mlx5_add_flow_rules(ft, spec, &flow_act, &fs_prot->default_dest, 1); + rule = mlx5_add_flow_rules(fs_prot->ft, spec, &flow_act, + &fs_prot->default_dest, 1); if (IS_ERR(rule)) { err = PTR_ERR(rule); mlx5_core_err(mdev, "fail to create psp rx miss_rule err=%d\n", err); @@ -399,12 +419,11 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs, } fs_prot->def_rule = rule; - goto out; + goto out_spec; out_err: accel_psp_fs_rx_fs_destroy(fs, fs_prot); -out: - kvfree(flow_group_in); +out_spec: kvfree(spec); return err; } @@ -456,82 +475,61 @@ static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs) if (!accel_psp) return; - mlx5_fc_destroy(fs->mdev, accel_psp->rx_bad_counter); - mlx5_fc_destroy(fs->mdev, accel_psp->rx_err_counter); - mlx5_fc_destroy(fs->mdev, accel_psp->rx_auth_fail_counter); - mlx5_fc_destroy(fs->mdev, accel_psp->rx_counter); + accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_bad_counter); + accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_err_counter); + accel_psp_fs_destroy_counter(fs->mdev, + &accel_psp->rx_auth_fail_counter); + accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_counter); kfree(accel_psp); fs->rx_fs = NULL; } static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs) { - struct mlx5e_accel_fs_psp *accel_psp; struct mlx5_core_dev *mdev = fs->mdev; - struct mlx5_fc *flow_counter; int err; - accel_psp = kzalloc_obj(*accel_psp); - if (!accel_psp) + fs->rx_fs = kzalloc_obj(*fs->rx_fs); + if (!fs->rx_fs) return -ENOMEM; - flow_counter = mlx5_fc_create(mdev, false); - if (IS_ERR(flow_counter)) { + err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_counter); + if (err) { mlx5_core_warn(mdev, - "fail to create psp rx flow counter err=%pe\n", - flow_counter); - err = PTR_ERR(flow_counter); + "fail to create psp rx flow counter err=%d\n", + err); goto out_err; } - accel_psp->rx_counter = flow_counter; - flow_counter = mlx5_fc_create(mdev, false); - if (IS_ERR(flow_counter)) { + err = accel_psp_fs_create_counter(mdev, + &fs->rx_fs->rx_auth_fail_counter); + if (err) { mlx5_core_warn(mdev, - "fail to create psp rx auth fail flow counter err=%pe\n", - flow_counter); - err = PTR_ERR(flow_counter); - goto out_counter_err; + "fail to create psp rx auth fail flow counter err=%d\n", + err); + goto out_err; } - accel_psp->rx_auth_fail_counter = flow_counter; - flow_counter = mlx5_fc_create(mdev, false); - if (IS_ERR(flow_counter)) { + err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_err_counter); + if (err) { mlx5_core_warn(mdev, - "fail to create psp rx error flow counter err=%pe\n", - flow_counter); - err = PTR_ERR(flow_counter); - goto out_auth_fail_counter_err; + "fail to create psp rx error flow counter err=%d\n", + err); + goto out_err; } - accel_psp->rx_err_counter = flow_counter; - flow_counter = mlx5_fc_create(mdev, false); - if (IS_ERR(flow_counter)) { + err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_bad_counter); + if (err) { mlx5_core_warn(mdev, - "fail to create psp rx bad flow counter err=%pe\n", - flow_counter); - err = PTR_ERR(flow_counter); - goto out_err_counter_err; + "fail to create psp rx bad flow counter err=%d\n", + err); + goto out_err; } - accel_psp->rx_bad_counter = flow_counter; - - fs->rx_fs = accel_psp; return 0; -out_err_counter_err: - mlx5_fc_destroy(mdev, accel_psp->rx_err_counter); - accel_psp->rx_err_counter = NULL; -out_auth_fail_counter_err: - mlx5_fc_destroy(mdev, accel_psp->rx_auth_fail_counter); - accel_psp->rx_auth_fail_counter = NULL; -out_counter_err: - mlx5_fc_destroy(mdev, accel_psp->rx_counter); - accel_psp->rx_counter = NULL; out_err: - kfree(accel_psp); - fs->rx_fs = NULL; - + accel_psp_fs_cleanup_rx(fs); return err; } @@ -675,12 +673,9 @@ static int accel_psp_fs_tx_create_ft_table(struct mlx5e_psp_fs *fs) static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs) { - if (!tx_fs->ft) - return; - - mlx5_del_flow_rules(tx_fs->rule); - mlx5_destroy_flow_group(tx_fs->fg); - mlx5_destroy_flow_table(tx_fs->ft); + accel_psp_fs_del_flow_rule(&tx_fs->rule); + accel_psp_fs_destroy_flow_group(&tx_fs->fg); + accel_psp_fs_destroy_ft(&tx_fs->ft); } static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) @@ -690,7 +685,7 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) if (!tx_fs) return; - mlx5_fc_destroy(fs->mdev, tx_fs->tx_counter); + accel_psp_fs_destroy_counter(fs->mdev, &tx_fs->tx_counter); kfree(tx_fs); fs->tx_fs = NULL; } @@ -699,8 +694,8 @@ static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs) { struct mlx5_core_dev *mdev = fs->mdev; struct mlx5_flow_namespace *ns; - struct mlx5_fc *flow_counter; struct mlx5e_psp_tx *tx_fs; + int err; ns = mlx5_get_flow_namespace(mdev, MLX5_FLOW_NAMESPACE_EGRESS_IPSEC); if (!ns) @@ -710,15 +705,14 @@ static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs) if (!tx_fs) return -ENOMEM; - flow_counter = mlx5_fc_create(mdev, false); - if (IS_ERR(flow_counter)) { + err = accel_psp_fs_create_counter(mdev, &tx_fs->tx_counter); + if (err) { mlx5_core_warn(mdev, - "fail to create psp tx flow counter err=%pe\n", - flow_counter); + "fail to create psp tx flow counter err=%d\n", + err); kfree(tx_fs); - return PTR_ERR(flow_counter); + return err; } - tx_fs->tx_counter = flow_counter; tx_fs->ns = ns; fs->tx_fs = tx_fs; return 0; -- 2.44.0 From: Cosmin Ratiu There are 3 rules added with the same structure. Factor out common code into a helper function to reduce duplication. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 65 ++++++++++--------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index a1c7ca4ae722..bdf97e373b42 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -184,6 +184,27 @@ static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec, MLX5_SET(fte_match_set_misc2, misc_params_2, psp_syndrome, syndrome); } +static int accel_psp_add_drop_rule(struct mlx5_flow_table *ft, + struct mlx5_flow_spec *spec, + struct mlx5_fc *counter, + struct mlx5_flow_handle **rule) +{ + struct mlx5_flow_destination dest = {}; + struct mlx5_flow_act flow_act = {}; + int err = 0; + + flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP | + MLX5_FLOW_CONTEXT_ACTION_COUNT; + dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; + dest.counter = counter; + *rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1); + if (IS_ERR(*rule)) { + err = PTR_ERR(*rule); + *rule = NULL; + } + return err; +} + static int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, struct mlx5e_accel_fs_psp_prot *fs_prot, @@ -253,56 +274,38 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, /* add auth fail drop rule */ memset(spec, 0, sizeof(*spec)); - memset(&flow_act, 0, sizeof(flow_act)); accel_psp_setup_syndrome_match(spec, PSP_ICV_FAIL); - /* create fte */ - flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP | - MLX5_FLOW_CONTEXT_ACTION_COUNT; - dest[0].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; - dest[0].counter = fs->rx_fs->rx_auth_fail_counter; - fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 1); - if (IS_ERR(fte)) { - err = PTR_ERR(fte); + err = accel_psp_add_drop_rule(rx_err->ft, spec, + fs->rx_fs->rx_auth_fail_counter, + &rx_err->auth_fail_rule); + if (err) { mlx5_core_err(mdev, "fail to add psp rx auth fail drop rule err=%d\n", err); goto out_err; } - rx_err->auth_fail_rule = fte; /* add framing drop rule */ memset(spec, 0, sizeof(*spec)); - memset(&flow_act, 0, sizeof(flow_act)); accel_psp_setup_syndrome_match(spec, PSP_BAD_TRAILER); - /* create fte */ - flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP | - MLX5_FLOW_CONTEXT_ACTION_COUNT; - dest[0].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; - dest[0].counter = fs->rx_fs->rx_err_counter; - fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 1); - if (IS_ERR(fte)) { - err = PTR_ERR(fte); - mlx5_core_err(mdev, "fail to add psp rx framing err drop rule err=%d\n", + err = accel_psp_add_drop_rule(rx_err->ft, spec, + fs->rx_fs->rx_err_counter, + &rx_err->err_rule); + if (err) { + mlx5_core_err(mdev, "fail to add psp rx framing drop rule err=%d\n", err); goto out_err; } - rx_err->err_rule = fte; /* add misc. errors drop rule */ memset(spec, 0, sizeof(*spec)); - memset(&flow_act, 0, sizeof(flow_act)); - /* create fte */ - flow_act.action = MLX5_FLOW_CONTEXT_ACTION_DROP | - MLX5_FLOW_CONTEXT_ACTION_COUNT; - dest[0].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; - dest[0].counter = fs->rx_fs->rx_bad_counter; - fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 1); - if (IS_ERR(fte)) { - err = PTR_ERR(fte); + err = accel_psp_add_drop_rule(rx_err->ft, spec, + fs->rx_fs->rx_bad_counter, + &rx_err->bad_rule); + if (err) { mlx5_core_err(mdev, "fail to add psp rx misc. err drop rule err=%d\n", err); goto out_err; } - rx_err->bad_rule = fte; goto out_spec; -- 2.44.0 From: Cosmin Ratiu The PSP error flow table copies the HW syndrome to metadata register B, but this value is never used in the RX path. Bad packets (auth fail, bad trailer) are dropped by HW via explicit drop rules before reaching software. Remove the syndrome copy action, the syndrome macro, and the dead syndrome check in the RX handler. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 30 +------------------ .../mellanox/mlx5/core/en_accel/psp_rxtx.c | 11 ------- .../mellanox/mlx5/core/en_accel/psp_rxtx.h | 3 +- 3 files changed, 2 insertions(+), 42 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index bdf97e373b42..534dba678761 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -35,7 +35,6 @@ struct mlx5e_psp_rx_err { struct mlx5_flow_handle *auth_fail_rule; struct mlx5_flow_handle *err_rule; struct mlx5_flow_handle *bad_rule; - struct mlx5_modify_hdr *copy_modify_hdr; }; struct mlx5e_accel_fs_psp_prot { @@ -165,10 +164,6 @@ static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs, accel_psp_fs_del_flow_rule(&rx_err->err_rule); accel_psp_fs_del_flow_rule(&rx_err->auth_fail_rule); accel_psp_fs_del_flow_rule(&rx_err->rule); - if (rx_err->copy_modify_hdr) { - mlx5_modify_header_dealloc(fs->mdev, rx_err->copy_modify_hdr); - rx_err->copy_modify_hdr = NULL; - } accel_psp_fs_destroy_ft(&rx_err->ft); } @@ -210,12 +205,10 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, struct mlx5e_accel_fs_psp_prot *fs_prot, struct mlx5e_psp_rx_err *rx_err) { - u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {}; struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_core_dev *mdev = fs->mdev; struct mlx5_flow_destination dest[2]; struct mlx5_flow_act flow_act = {}; - struct mlx5_modify_hdr *modify_hdr; struct mlx5_flow_handle *fte; struct mlx5_flow_spec *spec; int err = 0; @@ -235,30 +228,10 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, goto out_err; } - /* Action to copy 7 bit psp_syndrome to regB[23:29] */ - MLX5_SET(copy_action_in, action, action_type, MLX5_ACTION_TYPE_COPY); - MLX5_SET(copy_action_in, action, src_field, MLX5_ACTION_IN_FIELD_PSP_SYNDROME); - MLX5_SET(copy_action_in, action, src_offset, 0); - MLX5_SET(copy_action_in, action, length, 7); - MLX5_SET(copy_action_in, action, dst_field, MLX5_ACTION_IN_FIELD_METADATA_REG_B); - MLX5_SET(copy_action_in, action, dst_offset, 23); - - modify_hdr = mlx5_modify_header_alloc(mdev, MLX5_FLOW_NAMESPACE_KERNEL, - 1, action); - if (IS_ERR(modify_hdr)) { - err = PTR_ERR(modify_hdr); - mlx5_core_err(mdev, - "fail to alloc psp copy modify_header_id err=%d\n", err); - goto out_err; - } - rx_err->copy_modify_hdr = modify_hdr; - accel_psp_setup_syndrome_match(spec, PSP_OK); /* create fte */ - flow_act.action = MLX5_FLOW_CONTEXT_ACTION_MOD_HDR | - MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | + flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | MLX5_FLOW_CONTEXT_ACTION_COUNT; - flow_act.modify_hdr = modify_hdr; dest[0].type = fs_prot->default_dest.type; dest[0].ft = fs_prot->default_dest.ft; dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; @@ -389,7 +362,6 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs, setup_fte_udp_psp(spec, PSP_DEFAULT_UDP_PORT); flow_act.crypto.type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_PSP; /* Set bit[31, 30] PSP marker */ - /* Set bit[29-23] psp_syndrome is set in error FT */ #define MLX5E_PSP_MARKER_BIT (BIT(30) | BIT(31)) MLX5_SET(set_action_in, action, action_type, MLX5_ACTION_TYPE_SET); MLX5_SET(set_action_in, action, field, MLX5_ACTION_IN_FIELD_METADATA_REG_B); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c index c2f9899d23a5..348fd7a96261 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.c @@ -14,12 +14,6 @@ #include "en_accel/psp_rxtx.h" #include "en_accel/psp.h" -enum { - MLX5E_PSP_OFFLOAD_RX_SYNDROME_DECRYPTED, - MLX5E_PSP_OFFLOAD_RX_SYNDROME_AUTH_FAILED, - MLX5E_PSP_OFFLOAD_RX_SYNDROME_BAD_TRAILER, -}; - static void mlx5e_psp_set_swp(struct sk_buff *skb, struct mlx5e_accel_tx_psp_state *psp_st, struct mlx5_wqe_eth_seg *eseg) @@ -122,16 +116,11 @@ static bool mlx5e_psp_set_state(struct mlx5e_priv *priv, bool mlx5e_psp_offload_handle_rx_skb(struct net_device *netdev, struct sk_buff *skb, struct mlx5_cqe64 *cqe) { - u32 psp_meta_data = be32_to_cpu(cqe->ft_metadata); struct mlx5e_priv *priv = netdev_priv(netdev); u16 dev_id = priv->psp->psd->id; bool strip_icv = true; u8 generation = 0; - /* TBD: report errors as SW counters to ethtool, any further handling ? */ - if (MLX5_PSP_METADATA_SYNDROME(psp_meta_data) != MLX5E_PSP_OFFLOAD_RX_SYNDROME_DECRYPTED) - goto drop; - if (psp_dev_rcv(skb, dev_id, generation, strip_icv)) goto drop; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h index 70289c921bd6..2b080c39cc37 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp_rxtx.h @@ -10,9 +10,8 @@ #include "en.h" #include "en/txrx.h" -/* Bit30: PSP marker, Bit29-23: PSP syndrome, Bit22-0: PSP obj id */ +/* Bit30: PSP marker, Bit22-0: PSP obj id */ #define MLX5_PSP_METADATA_MARKER(metadata) ((((metadata) >> 30) & 0x3) == 0x3) -#define MLX5_PSP_METADATA_SYNDROME(metadata) (((metadata) >> 23) & GENMASK(6, 0)) #define MLX5_PSP_METADATA_HANDLE(metadata) ((metadata) & GENMASK(22, 0)) struct mlx5e_accel_tx_psp_state { -- 2.44.0 From: Cosmin Ratiu There are multiple naming inconsistencies and the code is fragmented and hard to follow. For example, the PSP TX steering structure is named 'mlx5e_psp_tx', but its RX counterpart is 'mlx5e_accel_fs_psp' and its protocol instantiation 'mlx5e_accel_fs_psp_prot', neither of which make it clear they relate to RX. This commit renames things to be more consistent, realigns declarations to abide by the xmas tree rule, and merges some functions to reduce fragmentation. Renamed: mlx5e_accel_fs_psp -> mlx5e_psp_rx mlx5e_accel_fs_psp_prot -> mlx5e_psp_rx_decrypt_table fs_prot -> decrypt accel_psp -> rx_fs mlx5e_psp_rx_err -> mlx5e_psp_rx_check_table mlx5e_psp_tx -> mlx5e_psp_tx_table def_rule -> rule Also renamed many functions with names of the form accel_psp_fs_A_B_C_..._verb, with A->B->C->... following a general->specific hierarchy. Full list: accel_psp_fs_rx_err_destroy_ft -> accel_psp_fs_rx_check_ft_destroy accel_psp_fs_rx_err_create_ft -> accel_psp_fs_rx_check_ft_create accel_psp_fs_rx_fs_destroy -> accel_psp_fs_rx_decrypt_ft_destroy accel_psp_fs_rx_create_ft -> accel_psp_fs_rx_decrypt_ft_create accel_psp_fs_tx_create_ft_table -> accel_psp_fs_tx_ft_create accel_psp_fs_tx_destroy -> accel_psp_fs_tx_ft_destroy accel_psp_fs_{init,cleanup}_{rx,tx} -> accel_psp_fs_{rx,tx}_{init,cleanup} Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 252 +++++++++--------- 1 file changed, 131 insertions(+), 121 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index 534dba678761..c83d62724ff7 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -21,7 +21,7 @@ enum accel_psp_syndrome { PSP_BAD_TRAILER, }; -struct mlx5e_psp_tx { +struct mlx5e_psp_tx_table { struct mlx5_flow_namespace *ns; struct mlx5_flow_table *ft; struct mlx5_flow_group *fg; @@ -29,7 +29,7 @@ struct mlx5e_psp_tx { struct mlx5_fc *tx_counter; }; -struct mlx5e_psp_rx_err { +struct mlx5e_psp_rx_check_table { struct mlx5_flow_table *ft; struct mlx5_flow_handle *rule; struct mlx5_flow_handle *auth_fail_rule; @@ -37,18 +37,18 @@ struct mlx5e_psp_rx_err { struct mlx5_flow_handle *bad_rule; }; -struct mlx5e_accel_fs_psp_prot { +struct mlx5e_psp_rx_decrypt_table { struct mlx5_flow_table *ft; struct mlx5_flow_group *miss_group; struct mlx5_flow_handle *miss_rule; struct mlx5_modify_hdr *rx_modify_hdr; struct mlx5_flow_destination default_dest; - struct mlx5e_psp_rx_err rx_err; - struct mlx5_flow_handle *def_rule; + struct mlx5e_psp_rx_check_table check; + struct mlx5_flow_handle *rule; }; -struct mlx5e_accel_fs_psp { - struct mlx5e_accel_fs_psp_prot fs_prot[ACCEL_FS_PSP_NUM_TYPES]; +struct mlx5e_psp_rx { + struct mlx5e_psp_rx_decrypt_table decrypt[ACCEL_FS_PSP_NUM_TYPES]; struct mlx5_fc *rx_counter; struct mlx5_fc *rx_auth_fail_counter; struct mlx5_fc *rx_err_counter; @@ -57,10 +57,10 @@ struct mlx5e_accel_fs_psp { struct mlx5e_psp_fs { struct mlx5_core_dev *mdev; - struct mlx5e_psp_tx *tx_fs; + struct mlx5e_psp_tx_table *tx_fs; /* Rx manage */ struct mlx5e_flow_steering *fs; - struct mlx5e_accel_fs_psp *rx_fs; + struct mlx5e_psp_rx *rx_fs; }; /* PSP RX flow steering */ @@ -157,14 +157,15 @@ static void accel_psp_fs_destroy_counter(struct mlx5_core_dev *dev, } } -static void accel_psp_fs_rx_err_destroy_ft(struct mlx5e_psp_fs *fs, - struct mlx5e_psp_rx_err *rx_err) +static +void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_rx_check_table *check) { - accel_psp_fs_del_flow_rule(&rx_err->bad_rule); - accel_psp_fs_del_flow_rule(&rx_err->err_rule); - accel_psp_fs_del_flow_rule(&rx_err->auth_fail_rule); - accel_psp_fs_del_flow_rule(&rx_err->rule); - accel_psp_fs_destroy_ft(&rx_err->ft); + accel_psp_fs_del_flow_rule(&check->bad_rule); + accel_psp_fs_del_flow_rule(&check->err_rule); + accel_psp_fs_del_flow_rule(&check->auth_fail_rule); + accel_psp_fs_del_flow_rule(&check->rule); + accel_psp_fs_destroy_ft(&check->ft); } static void accel_psp_setup_syndrome_match(struct mlx5_flow_spec *spec, @@ -201,9 +202,9 @@ static int accel_psp_add_drop_rule(struct mlx5_flow_table *ft, } static -int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, - struct mlx5e_accel_fs_psp_prot *fs_prot, - struct mlx5e_psp_rx_err *rx_err) +int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_rx_decrypt_table *decrypt, + struct mlx5e_psp_rx_check_table *check) { struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_core_dev *mdev = fs->mdev; @@ -221,10 +222,10 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, ft_attr.autogroup.max_num_groups = 2; ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; ft_attr.prio = MLX5E_NIC_PRIO; - err = accel_psp_fs_create_ft(fs, &ft_attr, &rx_err->ft); + err = accel_psp_fs_create_ft(fs, &ft_attr, &check->ft); if (err) { mlx5_core_err(fs->mdev, - "fail to create psp rx inline ft err=%d\n", err); + "fail to create psp rx check ft err=%d\n", err); goto out_err; } @@ -232,27 +233,28 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, /* create fte */ flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | MLX5_FLOW_CONTEXT_ACTION_COUNT; - dest[0].type = fs_prot->default_dest.type; - dest[0].ft = fs_prot->default_dest.ft; + dest[0].type = decrypt->default_dest.type; + dest[0].ft = decrypt->default_dest.ft; dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; dest[1].counter = fs->rx_fs->rx_counter; - fte = mlx5_add_flow_rules(rx_err->ft, spec, &flow_act, dest, 2); + fte = mlx5_add_flow_rules(check->ft, spec, &flow_act, dest, 2); if (IS_ERR(fte)) { err = PTR_ERR(fte); - mlx5_core_err(mdev, "fail to add psp rx err rule err=%d\n", + mlx5_core_err(mdev, "fail to add psp rx check ok rule err=%d\n", err); goto out_err; } - rx_err->rule = fte; + check->rule = fte; /* add auth fail drop rule */ memset(spec, 0, sizeof(*spec)); accel_psp_setup_syndrome_match(spec, PSP_ICV_FAIL); - err = accel_psp_add_drop_rule(rx_err->ft, spec, + err = accel_psp_add_drop_rule(check->ft, spec, fs->rx_fs->rx_auth_fail_counter, - &rx_err->auth_fail_rule); + &check->auth_fail_rule); if (err) { - mlx5_core_err(mdev, "fail to add psp rx auth fail drop rule err=%d\n", + mlx5_core_err(mdev, + "fail to add psp rx check auth fail drop rule err=%d\n", err); goto out_err; } @@ -260,22 +262,24 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, /* add framing drop rule */ memset(spec, 0, sizeof(*spec)); accel_psp_setup_syndrome_match(spec, PSP_BAD_TRAILER); - err = accel_psp_add_drop_rule(rx_err->ft, spec, + err = accel_psp_add_drop_rule(check->ft, spec, fs->rx_fs->rx_err_counter, - &rx_err->err_rule); + &check->err_rule); if (err) { - mlx5_core_err(mdev, "fail to add psp rx framing drop rule err=%d\n", + mlx5_core_err(mdev, + "fail to add psp rx check framing drop rule err=%d\n", err); goto out_err; } /* add misc. errors drop rule */ memset(spec, 0, sizeof(*spec)); - err = accel_psp_add_drop_rule(rx_err->ft, spec, + err = accel_psp_add_drop_rule(check->ft, spec, fs->rx_fs->rx_bad_counter, - &rx_err->bad_rule); + &check->bad_rule); if (err) { - mlx5_core_err(mdev, "fail to add psp rx misc. err drop rule err=%d\n", + mlx5_core_err(mdev, + "fail to add psp rx check misc. err drop rule err=%d\n", err); goto out_err; } @@ -283,24 +287,25 @@ int accel_psp_fs_rx_err_create_ft(struct mlx5e_psp_fs *fs, goto out_spec; out_err: - accel_psp_fs_rx_err_destroy_ft(fs, rx_err); + accel_psp_fs_rx_check_ft_destroy(fs, check); out_spec: kfree(spec); return err; } -static void accel_psp_fs_rx_fs_destroy(struct mlx5e_psp_fs *fs, - struct mlx5e_accel_fs_psp_prot *fs_prot) +static void +accel_psp_fs_rx_decrypt_ft_destroy(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_rx_decrypt_table *decrypt) { - accel_psp_fs_del_flow_rule(&fs_prot->def_rule); - if (fs_prot->rx_modify_hdr) { - mlx5_modify_header_dealloc(fs->mdev, fs_prot->rx_modify_hdr); - fs_prot->rx_modify_hdr = NULL; + accel_psp_fs_del_flow_rule(&decrypt->rule); + if (decrypt->rx_modify_hdr) { + mlx5_modify_header_dealloc(fs->mdev, decrypt->rx_modify_hdr); + decrypt->rx_modify_hdr = NULL; } - accel_psp_fs_del_flow_rule(&fs_prot->miss_rule); - accel_psp_fs_destroy_flow_group(&fs_prot->miss_group); - accel_psp_fs_destroy_ft(&fs_prot->ft); + accel_psp_fs_del_flow_rule(&decrypt->miss_rule); + accel_psp_fs_destroy_flow_group(&decrypt->miss_group); + accel_psp_fs_destroy_ft(&decrypt->ft); } static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port) @@ -312,8 +317,9 @@ static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port) MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, ip_protocol, IPPROTO_UDP); } -static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs, - struct mlx5e_accel_fs_psp_prot *fs_prot) +static int +accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_rx_decrypt_table *decrypt) { u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {}; struct mlx5_modify_hdr *modify_hdr = NULL; @@ -335,30 +341,36 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs, ft_attr.autogroup.num_reserved_entries = 1; ft_attr.autogroup.max_num_groups = 1; ft_attr.prio = MLX5E_NIC_PRIO; - err = accel_psp_fs_create_ft(fs, &ft_attr, &fs_prot->ft); + err = accel_psp_fs_create_ft(fs, &ft_attr, &decrypt->ft); if (err) { - mlx5_core_err(mdev, "fail to create psp rx ft err=%d\n", err); + mlx5_core_err(mdev, "fail to create psp rx decrypt ft err=%d\n", + err); goto out_err; } /* Create miss_group */ - err = accel_psp_fs_create_miss_group(fs_prot->ft, &fs_prot->miss_group); + err = accel_psp_fs_create_miss_group(decrypt->ft, &decrypt->miss_group); if (err) { - mlx5_core_err(mdev, "fail to create psp rx miss_group err=%d\n", err); + mlx5_core_err(mdev, + "fail to create psp rx decrypt miss_group err=%d\n", + err); goto out_err; } /* Create miss rule */ - rule = mlx5_add_flow_rules(fs_prot->ft, spec, &flow_act, - &fs_prot->default_dest, 1); + flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; + rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, + &decrypt->default_dest, 1); if (IS_ERR(rule)) { err = PTR_ERR(rule); - mlx5_core_err(mdev, "fail to create psp rx miss_rule err=%d\n", err); + mlx5_core_err(mdev, + "fail to create psp rx decrypt miss_rule err=%d\n", + err); goto out_err; } - fs_prot->miss_rule = rule; + decrypt->miss_rule = rule; - /* Add default Rx psp rule */ + /* Add PSP RX decrypt rule */ setup_fte_udp_psp(spec, PSP_DEFAULT_UDP_PORT); flow_act.crypto.type = MLX5_FLOW_CONTEXT_ENCRYPT_DECRYPT_TYPE_PSP; /* Set bit[31, 30] PSP marker */ @@ -376,46 +388,44 @@ static int accel_psp_fs_rx_create_ft(struct mlx5e_psp_fs *fs, modify_hdr = NULL; goto out_err; } - fs_prot->rx_modify_hdr = modify_hdr; + decrypt->rx_modify_hdr = modify_hdr; flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | MLX5_FLOW_CONTEXT_ACTION_CRYPTO_DECRYPT | MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; flow_act.modify_hdr = modify_hdr; dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; - dest.ft = fs_prot->rx_err.ft; - rule = mlx5_add_flow_rules(fs_prot->ft, spec, &flow_act, &dest, 1); + dest.ft = decrypt->check.ft; + rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, &dest, 1); if (IS_ERR(rule)) { err = PTR_ERR(rule); - mlx5_core_err(mdev, - "fail to add psp rule Rx decryption, err=%d, flow_act.action = %#04X\n", - err, flow_act.action); + mlx5_core_err(mdev, "fail to add psp rx decrypt rule, err=%d\n", + err); goto out_err; } - fs_prot->def_rule = rule; + decrypt->rule = rule; goto out_spec; out_err: - accel_psp_fs_rx_fs_destroy(fs, fs_prot); + accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt); out_spec: kvfree(spec); return err; } -static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type) +static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs, + enum accel_fs_psp_type type) { - struct mlx5e_accel_fs_psp_prot *fs_prot; - struct mlx5e_accel_fs_psp *accel_psp; - - accel_psp = fs->rx_fs; + struct mlx5e_psp_rx_decrypt_table *decrypt; + struct mlx5e_psp_rx *rx_fs = fs->rx_fs; /* The netdev unreg already happened, so all offloaded rule are already removed */ - fs_prot = &accel_psp->fs_prot[type]; + decrypt = &rx_fs->decrypt[type]; - accel_psp_fs_rx_fs_destroy(fs, fs_prot); + accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt); - accel_psp_fs_rx_err_destroy_ft(fs, &fs_prot->rx_err); + accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check); return 0; } @@ -423,43 +433,45 @@ static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs, enum accel_fs_psp_ty static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type) { struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false); - struct mlx5e_accel_fs_psp_prot *fs_prot; - struct mlx5e_accel_fs_psp *accel_psp; + struct mlx5e_psp_rx_decrypt_table *decrypt; + struct mlx5e_psp_rx *rx_fs = fs->rx_fs; int err; - accel_psp = fs->rx_fs; - fs_prot = &accel_psp->fs_prot[type]; + decrypt = &rx_fs->decrypt[type]; + decrypt->default_dest = mlx5_ttc_get_default_dest(ttc, + fs_psp2tt(type)); - fs_prot->default_dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type)); - - err = accel_psp_fs_rx_err_create_ft(fs, fs_prot, &fs_prot->rx_err); + err = accel_psp_fs_rx_check_ft_create(fs, decrypt, &decrypt->check); if (err) return err; - err = accel_psp_fs_rx_create_ft(fs, fs_prot); + err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt); if (err) - accel_psp_fs_rx_err_destroy_ft(fs, &fs_prot->rx_err); + goto out_err_ft; + + return 0; +out_err_ft: + accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check); return err; } -static void accel_psp_fs_cleanup_rx(struct mlx5e_psp_fs *fs) +static void accel_psp_fs_rx_cleanup(struct mlx5e_psp_fs *fs) { - struct mlx5e_accel_fs_psp *accel_psp = fs->rx_fs; + struct mlx5e_psp_rx *rx_fs = fs->rx_fs; - if (!accel_psp) + if (!rx_fs) return; - accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_bad_counter); - accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_err_counter); - accel_psp_fs_destroy_counter(fs->mdev, - &accel_psp->rx_auth_fail_counter); - accel_psp_fs_destroy_counter(fs->mdev, &accel_psp->rx_counter); - kfree(accel_psp); + accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_bad_counter); + accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_err_counter); + accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_auth_fail_counter); + accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_counter); + kfree(rx_fs); fs->rx_fs = NULL; } -static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs) +static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs) { struct mlx5_core_dev *mdev = fs->mdev; int err; @@ -504,7 +516,7 @@ static int accel_psp_fs_init_rx(struct mlx5e_psp_fs *fs) return 0; out_err: - accel_psp_fs_cleanup_rx(fs); + accel_psp_fs_rx_cleanup(fs); return err; } @@ -541,7 +553,7 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) ttc = mlx5e_fs_get_ttc(fs->fs, false); for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { - struct mlx5e_accel_fs_psp_prot *fs_prot; + struct mlx5e_psp_rx_decrypt_table *decrypt; struct mlx5_flow_destination dest = {}; /* create FT */ @@ -551,8 +563,8 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) /* connect */ dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; - fs_prot = &fs->rx_fs->fs_prot[i]; - dest.ft = fs_prot->ft; + decrypt = &fs->rx_fs->decrypt[i]; + dest.ft = decrypt->ft; mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest); } @@ -567,17 +579,17 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) return err; } -static int accel_psp_fs_tx_create_ft_table(struct mlx5e_psp_fs *fs) +static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs) { int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_flow_destination dest = {}; struct mlx5_core_dev *mdev = fs->mdev; struct mlx5_flow_act flow_act = {}; + struct mlx5e_psp_tx_table *tx_fs; u32 *in, *mc, *outer_headers_c; struct mlx5_flow_handle *rule; struct mlx5_flow_spec *spec; - struct mlx5e_psp_tx *tx_fs; struct mlx5_flow_table *ft; struct mlx5_flow_group *fg; int err = 0; @@ -646,16 +658,16 @@ static int accel_psp_fs_tx_create_ft_table(struct mlx5e_psp_fs *fs) return err; } -static void accel_psp_fs_tx_destroy(struct mlx5e_psp_tx *tx_fs) +static void accel_psp_fs_tx_ft_destroy(struct mlx5e_psp_tx_table *tx_fs) { accel_psp_fs_del_flow_rule(&tx_fs->rule); accel_psp_fs_destroy_flow_group(&tx_fs->fg); accel_psp_fs_destroy_ft(&tx_fs->ft); } -static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) +static void accel_psp_fs_tx_cleanup(struct mlx5e_psp_fs *fs) { - struct mlx5e_psp_tx *tx_fs = fs->tx_fs; + struct mlx5e_psp_tx_table *tx_fs = fs->tx_fs; if (!tx_fs) return; @@ -665,11 +677,11 @@ static void accel_psp_fs_cleanup_tx(struct mlx5e_psp_fs *fs) fs->tx_fs = NULL; } -static int accel_psp_fs_init_tx(struct mlx5e_psp_fs *fs) +static int accel_psp_fs_tx_init(struct mlx5e_psp_fs *fs) { struct mlx5_core_dev *mdev = fs->mdev; + struct mlx5e_psp_tx_table *tx_fs; struct mlx5_flow_namespace *ns; - struct mlx5e_psp_tx *tx_fs; int err; ns = mlx5_get_flow_namespace(mdev, MLX5_FLOW_NAMESPACE_EGRESS_IPSEC); @@ -697,32 +709,30 @@ static void mlx5e_accel_psp_fs_get_stats_fill(struct mlx5e_priv *priv, struct mlx5e_psp_stats *stats) { - struct mlx5e_psp_tx *tx_fs = priv->psp->fs->tx_fs; + struct mlx5e_psp_tx_table *tx_fs = priv->psp->fs->tx_fs; + struct mlx5e_psp_rx *rx_fs = priv->psp->fs->rx_fs; struct mlx5_core_dev *mdev = priv->mdev; - struct mlx5e_accel_fs_psp *accel_psp; - - accel_psp = (struct mlx5e_accel_fs_psp *)priv->psp->fs->rx_fs; if (tx_fs->tx_counter) mlx5_fc_query(mdev, tx_fs->tx_counter, &stats->psp_tx_pkts, &stats->psp_tx_bytes); - if (accel_psp->rx_counter) - mlx5_fc_query(mdev, accel_psp->rx_counter, &stats->psp_rx_pkts, + if (rx_fs->rx_counter) + mlx5_fc_query(mdev, rx_fs->rx_counter, &stats->psp_rx_pkts, &stats->psp_rx_bytes); - if (accel_psp->rx_auth_fail_counter) - mlx5_fc_query(mdev, accel_psp->rx_auth_fail_counter, + if (rx_fs->rx_auth_fail_counter) + mlx5_fc_query(mdev, rx_fs->rx_auth_fail_counter, &stats->psp_rx_pkts_auth_fail, &stats->psp_rx_bytes_auth_fail); - if (accel_psp->rx_err_counter) - mlx5_fc_query(mdev, accel_psp->rx_err_counter, + if (rx_fs->rx_err_counter) + mlx5_fc_query(mdev, rx_fs->rx_err_counter, &stats->psp_rx_pkts_frame_err, &stats->psp_rx_bytes_frame_err); - if (accel_psp->rx_bad_counter) - mlx5_fc_query(mdev, accel_psp->rx_bad_counter, + if (rx_fs->rx_bad_counter) + mlx5_fc_query(mdev, rx_fs->rx_bad_counter, &stats->psp_rx_pkts_drop, &stats->psp_rx_bytes_drop); } @@ -732,7 +742,7 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) if (!priv->psp) return; - accel_psp_fs_tx_destroy(priv->psp->fs->tx_fs); + accel_psp_fs_tx_ft_destroy(priv->psp->fs->tx_fs); } int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) @@ -740,13 +750,13 @@ int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) if (!priv->psp) return 0; - return accel_psp_fs_tx_create_ft_table(priv->psp->fs); + return accel_psp_fs_tx_ft_create(priv->psp->fs); } static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs) { - accel_psp_fs_cleanup_rx(fs); - accel_psp_fs_cleanup_tx(fs); + accel_psp_fs_rx_cleanup(fs); + accel_psp_fs_tx_cleanup(fs); kfree(fs); } @@ -760,19 +770,19 @@ static struct mlx5e_psp_fs *mlx5e_accel_psp_fs_init(struct mlx5e_priv *priv) return ERR_PTR(-ENOMEM); fs->mdev = priv->mdev; - err = accel_psp_fs_init_tx(fs); + err = accel_psp_fs_tx_init(fs); if (err) goto err_tx; fs->fs = priv->fs; - err = accel_psp_fs_init_rx(fs); + err = accel_psp_fs_rx_init(fs); if (err) goto err_rx; return fs; err_rx: - accel_psp_fs_cleanup_tx(fs); + accel_psp_fs_tx_cleanup(fs); err_tx: kfree(fs); return ERR_PTR(err); -- 2.44.0 From: Cosmin Ratiu The rx_check ft was requesting max_fte == 2, but it created 4 entries. While this accidentally works, it's not accurate, so change that and use the correct number of entries. Also use an explicit drop_group for the last match(*) drop rule. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/en_accel/psp.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index c83d62724ff7..f8b289c50a42 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -31,6 +31,7 @@ struct mlx5e_psp_tx_table { struct mlx5e_psp_rx_check_table { struct mlx5_flow_table *ft; + struct mlx5_flow_group *drop_group; struct mlx5_flow_handle *rule; struct mlx5_flow_handle *auth_fail_rule; struct mlx5_flow_handle *err_rule; @@ -165,6 +166,7 @@ void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs, accel_psp_fs_del_flow_rule(&check->err_rule); accel_psp_fs_del_flow_rule(&check->auth_fail_rule); accel_psp_fs_del_flow_rule(&check->rule); + accel_psp_fs_destroy_flow_group(&check->drop_group); accel_psp_fs_destroy_ft(&check->ft); } @@ -218,7 +220,8 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, if (!spec) return -ENOMEM; - ft_attr.max_fte = 2; + ft_attr.max_fte = 4; + ft_attr.autogroup.num_reserved_entries = 1; ft_attr.autogroup.max_num_groups = 2; ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; ft_attr.prio = MLX5E_NIC_PRIO; @@ -229,6 +232,14 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, goto out_err; } + err = accel_psp_fs_create_miss_group(check->ft, &check->drop_group); + if (err) { + mlx5_core_err(fs->mdev, + "fail to create psp rx check drop group err=%d\n", + err); + goto out_err; + } + accel_psp_setup_syndrome_match(spec, PSP_OK); /* create fte */ flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | -- 2.44.0 From: Cosmin Ratiu Successfully decrypted PSP traffic is currently forwarded to the UDP v4/v6 TTC default destination from its respective PSP rx_check table. In preparation for flattening out RX steering and for decapsulation support (which needs to handle non-UDP traffic as well), add an RX table which directs traffic to either the UDP v4/v6 default TTC destinations, or back to the TTC table itself for further processing. There can be no loops as non-UDP traffic will not go through PSP processing again. This is now used as a destination for successfully decrypted PSP packets. The rx_counter is also incremented there, freeing the rx_check rule for PSP_OK for atomic destination update in a future patch. Use this opportunity to separate RX flow table levels from IPsec, as reusing random IPsec ft levels as PSP isn't clear and now is a good opportunity to separate them. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/en/fs.h | 7 +- .../mellanox/mlx5/core/en_accel/psp.c | 149 +++++++++++++++--- 2 files changed, 136 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h index 091b80a67189..4973fb473ff0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h @@ -88,13 +88,18 @@ enum { #ifdef CONFIG_MLX5_EN_ARFS MLX5E_ARFS_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, #endif -#if defined(CONFIG_MLX5_EN_IPSEC) || defined(CONFIG_MLX5_EN_PSP) +#if defined(CONFIG_MLX5_EN_IPSEC) MLX5E_ACCEL_FS_ESP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL, MLX5E_ACCEL_FS_POL_FT_LEVEL, MLX5E_ACCEL_FS_POL_MISS_FT_LEVEL, MLX5E_ACCEL_FS_ESP_FT_ROCE_LEVEL, #endif +#if defined(CONFIG_MLX5_EN_PSP) + MLX5E_ACCEL_FS_PSP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, + MLX5E_ACCEL_FS_PSP_ERR_FT_LEVEL, + MLX5E_ACCEL_FS_PSP_RX_FT_LEVEL, +#endif }; struct mlx5e_flow_steering; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index f8b289c50a42..c45241025b16 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -43,7 +43,6 @@ struct mlx5e_psp_rx_decrypt_table { struct mlx5_flow_group *miss_group; struct mlx5_flow_handle *miss_rule; struct mlx5_modify_hdr *rx_modify_hdr; - struct mlx5_flow_destination default_dest; struct mlx5e_psp_rx_check_table check; struct mlx5_flow_handle *rule; }; @@ -56,12 +55,21 @@ struct mlx5e_psp_rx { struct mlx5_fc *rx_bad_counter; }; +struct mlx5e_psp_rx_table { + struct mlx5_flow_table *ft; + struct mlx5_flow_group *miss_group; + struct mlx5_flow_handle *miss_rule; + struct mlx5_flow_handle *udp_rules[ACCEL_FS_PSP_NUM_TYPES]; +}; + struct mlx5e_psp_fs { struct mlx5_core_dev *mdev; struct mlx5e_psp_tx_table *tx_fs; /* Rx manage */ struct mlx5e_flow_steering *fs; struct mlx5e_psp_rx *rx_fs; + + struct mlx5e_psp_rx_table rx; }; /* PSP RX flow steering */ @@ -158,6 +166,106 @@ static void accel_psp_fs_destroy_counter(struct mlx5_core_dev *dev, } } +static void accel_psp_fs_rx_ft_destroy(struct mlx5e_psp_rx_table *rx) +{ + int i; + + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) + accel_psp_fs_del_flow_rule(&rx->udp_rules[i]); + accel_psp_fs_del_flow_rule(&rx->miss_rule); + accel_psp_fs_destroy_flow_group(&rx->miss_group); + accel_psp_fs_destroy_ft(&rx->ft); +} + +static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_rx_table *rx) +{ + struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false); + struct mlx5_flow_destination dest[2] = {}; + struct mlx5_flow_table_attr ft_attr = {}; + struct mlx5_core_dev *mdev = fs->mdev; + MLX5_DECLARE_FLOW_ACT(flow_act); + struct mlx5_flow_handle *rule; + struct mlx5_flow_spec *spec; + int i, err = 0; + + spec = kzalloc_obj(*spec); + if (!spec) + return -ENOMEM; + + ft_attr.max_fte = 1 + ACCEL_FS_PSP_NUM_TYPES; + ft_attr.level = MLX5E_ACCEL_FS_PSP_RX_FT_LEVEL; + ft_attr.prio = MLX5E_NIC_PRIO; + ft_attr.autogroup.num_reserved_entries = 1; + err = accel_psp_fs_create_ft(fs, &ft_attr, &rx->ft); + if (err) { + mlx5_core_err(mdev, "fail to create psp rx ft err=%d\n", err); + goto out_err; + } + + err = accel_psp_fs_create_miss_group(rx->ft, &rx->miss_group); + if (err) { + mlx5_core_err(mdev, "fail to create psp rx miss_group err=%d\n", + err); + goto out_err; + } + + /* Add miss rule */ + flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | + MLX5_FLOW_CONTEXT_ACTION_COUNT; + flow_act.flags = FLOW_ACT_IGNORE_FLOW_LEVEL; + dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; + dest[0].ft = mlx5_get_ttc_flow_table(ttc); + dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; + dest[1].counter = fs->rx_fs->rx_counter; + rule = mlx5_add_flow_rules(rx->ft, NULL, &flow_act, dest, 2); + if (IS_ERR(rule)) { + err = PTR_ERR(rule); + mlx5_core_err(mdev, "fail to create psp rx rule, err=%d\n", + err); + goto out_err; + } + rx->miss_rule = rule; + + /* Add UDP v4/v6 rules */ + spec->match_criteria_enable = MLX5_MATCH_OUTER_HEADERS; + MLX5_SET_TO_ONES(fte_match_param, spec->match_criteria, + outer_headers.ip_version); + MLX5_SET_TO_ONES(fte_match_set_lyr_2_4, spec->match_criteria, + ip_protocol); + MLX5_SET(fte_match_set_lyr_2_4, spec->match_value, ip_protocol, + IPPROTO_UDP); + flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | + MLX5_FLOW_CONTEXT_ACTION_COUNT; + flow_act.flags = 0; + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { + int version = i == ACCEL_FS_PSP4 ? 4 : 6; + + MLX5_SET(fte_match_param, spec->match_value, + outer_headers.ip_version, version); + dest[0] = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i)); + dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; + dest[1].counter = fs->rx_fs->rx_counter; + rule = mlx5_add_flow_rules(rx->ft, spec, &flow_act, dest, + 2); + if (IS_ERR(rule)) { + err = PTR_ERR(rule); + mlx5_core_err(mdev, + "fail to create psp rx UDP%d rule err=%d\n", + version, err); + goto out_err; + } + rx->udp_rules[i] = rule; + } + goto out_spec; + +out_err: + accel_psp_fs_rx_ft_destroy(rx); +out_spec: + kvfree(spec); + return err; +} + static void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs, struct mlx5e_psp_rx_check_table *check) @@ -205,12 +313,11 @@ static int accel_psp_add_drop_rule(struct mlx5_flow_table *ft, static int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, - struct mlx5e_psp_rx_decrypt_table *decrypt, struct mlx5e_psp_rx_check_table *check) { struct mlx5_flow_table_attr ft_attr = {}; + struct mlx5_flow_destination dest = {}; struct mlx5_core_dev *mdev = fs->mdev; - struct mlx5_flow_destination dest[2]; struct mlx5_flow_act flow_act = {}; struct mlx5_flow_handle *fte; struct mlx5_flow_spec *spec; @@ -223,7 +330,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, ft_attr.max_fte = 4; ft_attr.autogroup.num_reserved_entries = 1; ft_attr.autogroup.max_num_groups = 2; - ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_ERR_LEVEL; + ft_attr.level = MLX5E_ACCEL_FS_PSP_ERR_FT_LEVEL; ft_attr.prio = MLX5E_NIC_PRIO; err = accel_psp_fs_create_ft(fs, &ft_attr, &check->ft); if (err) { @@ -242,13 +349,10 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, accel_psp_setup_syndrome_match(spec, PSP_OK); /* create fte */ - flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST | - MLX5_FLOW_CONTEXT_ACTION_COUNT; - dest[0].type = decrypt->default_dest.type; - dest[0].ft = decrypt->default_dest.ft; - dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; - dest[1].counter = fs->rx_fs->rx_counter; - fte = mlx5_add_flow_rules(check->ft, spec, &flow_act, dest, 2); + flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; + dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; + dest.ft = fs->rx.ft; + fte = mlx5_add_flow_rules(check->ft, spec, &flow_act, &dest, 1); if (IS_ERR(fte)) { err = PTR_ERR(fte); mlx5_core_err(mdev, "fail to add psp rx check ok rule err=%d\n", @@ -330,7 +434,8 @@ static void setup_fte_udp_psp(struct mlx5_flow_spec *spec, u16 udp_port) static int accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs, - struct mlx5e_psp_rx_decrypt_table *decrypt) + struct mlx5e_psp_rx_decrypt_table *decrypt, + struct mlx5_flow_destination *default_dest) { u8 action[MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto)] = {}; struct mlx5_modify_hdr *modify_hdr = NULL; @@ -348,7 +453,7 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs, /* Create FT */ ft_attr.max_fte = 2; - ft_attr.level = MLX5E_ACCEL_FS_ESP_FT_LEVEL; + ft_attr.level = MLX5E_ACCEL_FS_PSP_FT_LEVEL; ft_attr.autogroup.num_reserved_entries = 1; ft_attr.autogroup.max_num_groups = 1; ft_attr.prio = MLX5E_NIC_PRIO; @@ -370,8 +475,8 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs, /* Create miss rule */ flow_act.action = MLX5_FLOW_CONTEXT_ACTION_FWD_DEST; - rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, - &decrypt->default_dest, 1); + rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, default_dest, + 1); if (IS_ERR(rule)) { err = PTR_ERR(rule); mlx5_core_err(mdev, @@ -446,17 +551,17 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false); struct mlx5e_psp_rx_decrypt_table *decrypt; struct mlx5e_psp_rx *rx_fs = fs->rx_fs; + struct mlx5_flow_destination dest = {}; int err; decrypt = &rx_fs->decrypt[type]; - decrypt->default_dest = mlx5_ttc_get_default_dest(ttc, - fs_psp2tt(type)); - err = accel_psp_fs_rx_check_ft_create(fs, decrypt, &decrypt->check); + err = accel_psp_fs_rx_check_ft_create(fs, &decrypt->check); if (err) return err; - err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt); + dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type)); + err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest); if (err) goto out_err_ft; @@ -549,6 +654,7 @@ void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) /* remove FT */ accel_psp_fs_rx_destroy(fs, i); } + accel_psp_fs_rx_ft_destroy(&priv->psp->fs->rx); } int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) @@ -563,6 +669,10 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) fs = priv->psp->fs; ttc = mlx5e_fs_get_ttc(fs->fs, false); + err = accel_psp_fs_rx_ft_create(fs, &fs->rx); + if (err) + return err; + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { struct mlx5e_psp_rx_decrypt_table *decrypt; struct mlx5_flow_destination dest = {}; @@ -586,6 +696,7 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); accel_psp_fs_rx_destroy(fs, i); } + accel_psp_fs_rx_ft_destroy(&fs->rx); return err; } -- 2.44.0 From: Cosmin Ratiu PSP uses a check steering table per IP version, but the PSP rules are IP-version agnostic, so there's no point duplicating these in HW. This commit makes the rx check steering table independent of the IP version, with the final table added in the previous patch responsible for directing packets to the corresponding UDP TIRs (or the TTC table itself for non-UDP traffic). Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 34 +++++++------------ 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index c45241025b16..48bc59045dfe 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -43,7 +43,6 @@ struct mlx5e_psp_rx_decrypt_table { struct mlx5_flow_group *miss_group; struct mlx5_flow_handle *miss_rule; struct mlx5_modify_hdr *rx_modify_hdr; - struct mlx5e_psp_rx_check_table check; struct mlx5_flow_handle *rule; }; @@ -69,6 +68,7 @@ struct mlx5e_psp_fs { struct mlx5e_flow_steering *fs; struct mlx5e_psp_rx *rx_fs; + struct mlx5e_psp_rx_check_table check; struct mlx5e_psp_rx_table rx; }; @@ -267,8 +267,7 @@ static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs, } static -void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_fs *fs, - struct mlx5e_psp_rx_check_table *check) +void accel_psp_fs_rx_check_ft_destroy(struct mlx5e_psp_rx_check_table *check) { accel_psp_fs_del_flow_rule(&check->bad_rule); accel_psp_fs_del_flow_rule(&check->err_rule); @@ -402,13 +401,12 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, goto out_spec; out_err: - accel_psp_fs_rx_check_ft_destroy(fs, check); + accel_psp_fs_rx_check_ft_destroy(check); out_spec: kfree(spec); return err; } - static void accel_psp_fs_rx_decrypt_ft_destroy(struct mlx5e_psp_fs *fs, struct mlx5e_psp_rx_decrypt_table *decrypt) @@ -511,7 +509,7 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs, MLX5_FLOW_CONTEXT_ACTION_MOD_HDR; flow_act.modify_hdr = modify_hdr; dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; - dest.ft = decrypt->check.ft; + dest.ft = fs->check.ft; rule = mlx5_add_flow_rules(decrypt->ft, spec, &flow_act, &dest, 1); if (IS_ERR(rule)) { err = PTR_ERR(rule); @@ -541,8 +539,6 @@ static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs, accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt); - accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check); - return 0; } @@ -552,24 +548,11 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_typ struct mlx5e_psp_rx_decrypt_table *decrypt; struct mlx5e_psp_rx *rx_fs = fs->rx_fs; struct mlx5_flow_destination dest = {}; - int err; decrypt = &rx_fs->decrypt[type]; - err = accel_psp_fs_rx_check_ft_create(fs, &decrypt->check); - if (err) - return err; - dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type)); - err = accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest); - if (err) - goto out_err_ft; - - return 0; - -out_err_ft: - accel_psp_fs_rx_check_ft_destroy(fs, &decrypt->check); - return err; + return accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest); } static void accel_psp_fs_rx_cleanup(struct mlx5e_psp_fs *fs) @@ -654,6 +637,7 @@ void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) /* remove FT */ accel_psp_fs_rx_destroy(fs, i); } + accel_psp_fs_rx_check_ft_destroy(&fs->check); accel_psp_fs_rx_ft_destroy(&priv->psp->fs->rx); } @@ -673,6 +657,10 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) if (err) return err; + err = accel_psp_fs_rx_check_ft_create(fs, &fs->check); + if (err) + goto err_ft; + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { struct mlx5e_psp_rx_decrypt_table *decrypt; struct mlx5_flow_destination dest = {}; @@ -696,6 +684,8 @@ int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); accel_psp_fs_rx_destroy(fs, i); } + accel_psp_fs_rx_check_ft_destroy(&fs->check); +err_ft: accel_psp_fs_rx_ft_destroy(&fs->rx); return err; -- 2.44.0 From: Cosmin Ratiu PSP steering code has two dynamically allocated structures to store RX and TX steering structs. Remove those and flatten out everything into the parent mlx5e_psp_fs. The tx_counter was moved out of the TX table as well, because the table doesn't own it, it outlives TX table destruction. All table creation/destruction now happens in accel_psp_fs_{rx,tx}_{create,destroy}. This will be used in subsequent patches to make PSP configuration dynamic. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/psp.c | 257 +++++++----------- 1 file changed, 97 insertions(+), 160 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index 48bc59045dfe..b713f235a0f7 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -26,7 +26,6 @@ struct mlx5e_psp_tx_table { struct mlx5_flow_table *ft; struct mlx5_flow_group *fg; struct mlx5_flow_handle *rule; - struct mlx5_fc *tx_counter; }; struct mlx5e_psp_rx_check_table { @@ -46,14 +45,6 @@ struct mlx5e_psp_rx_decrypt_table { struct mlx5_flow_handle *rule; }; -struct mlx5e_psp_rx { - struct mlx5e_psp_rx_decrypt_table decrypt[ACCEL_FS_PSP_NUM_TYPES]; - struct mlx5_fc *rx_counter; - struct mlx5_fc *rx_auth_fail_counter; - struct mlx5_fc *rx_err_counter; - struct mlx5_fc *rx_bad_counter; -}; - struct mlx5e_psp_rx_table { struct mlx5_flow_table *ft; struct mlx5_flow_group *miss_group; @@ -63,11 +54,17 @@ struct mlx5e_psp_rx_table { struct mlx5e_psp_fs { struct mlx5_core_dev *mdev; - struct mlx5e_psp_tx_table *tx_fs; - /* Rx manage */ + struct mlx5_fc *tx_counter; + struct mlx5e_psp_tx_table tx; + + /* Rx */ struct mlx5e_flow_steering *fs; - struct mlx5e_psp_rx *rx_fs; + struct mlx5_fc *rx_counter; + struct mlx5_fc *rx_auth_fail_counter; + struct mlx5_fc *rx_err_counter; + struct mlx5_fc *rx_bad_counter; + struct mlx5e_psp_rx_decrypt_table decrypt[ACCEL_FS_PSP_NUM_TYPES]; struct mlx5e_psp_rx_check_table check; struct mlx5e_psp_rx_table rx; }; @@ -217,7 +214,7 @@ static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs, dest[0].type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; dest[0].ft = mlx5_get_ttc_flow_table(ttc); dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; - dest[1].counter = fs->rx_fs->rx_counter; + dest[1].counter = fs->rx_counter; rule = mlx5_add_flow_rules(rx->ft, NULL, &flow_act, dest, 2); if (IS_ERR(rule)) { err = PTR_ERR(rule); @@ -245,7 +242,7 @@ static int accel_psp_fs_rx_ft_create(struct mlx5e_psp_fs *fs, outer_headers.ip_version, version); dest[0] = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i)); dest[1].type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; - dest[1].counter = fs->rx_fs->rx_counter; + dest[1].counter = fs->rx_counter; rule = mlx5_add_flow_rules(rx->ft, spec, &flow_act, dest, 2); if (IS_ERR(rule)) { @@ -364,7 +361,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, memset(spec, 0, sizeof(*spec)); accel_psp_setup_syndrome_match(spec, PSP_ICV_FAIL); err = accel_psp_add_drop_rule(check->ft, spec, - fs->rx_fs->rx_auth_fail_counter, + fs->rx_auth_fail_counter, &check->auth_fail_rule); if (err) { mlx5_core_err(mdev, @@ -376,8 +373,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, /* add framing drop rule */ memset(spec, 0, sizeof(*spec)); accel_psp_setup_syndrome_match(spec, PSP_BAD_TRAILER); - err = accel_psp_add_drop_rule(check->ft, spec, - fs->rx_fs->rx_err_counter, + err = accel_psp_add_drop_rule(check->ft, spec, fs->rx_err_counter, &check->err_rule); if (err) { mlx5_core_err(mdev, @@ -388,8 +384,7 @@ int accel_psp_fs_rx_check_ft_create(struct mlx5e_psp_fs *fs, /* add misc. errors drop rule */ memset(spec, 0, sizeof(*spec)); - err = accel_psp_add_drop_rule(check->ft, spec, - fs->rx_fs->rx_bad_counter, + err = accel_psp_add_drop_rule(check->ft, spec, fs->rx_bad_counter, &check->bad_rule); if (err) { mlx5_core_err(mdev, @@ -528,46 +523,66 @@ accel_psp_fs_rx_decrypt_ft_create(struct mlx5e_psp_fs *fs, return err; } -static int accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs, - enum accel_fs_psp_type type) +static void accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs) { - struct mlx5e_psp_rx_decrypt_table *decrypt; - struct mlx5e_psp_rx *rx_fs = fs->rx_fs; - - /* The netdev unreg already happened, so all offloaded rule are already removed */ - decrypt = &rx_fs->decrypt[type]; - - accel_psp_fs_rx_decrypt_ft_destroy(fs, decrypt); + struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false); + int i; - return 0; + /* disconnect */ + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { + mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); + accel_psp_fs_rx_decrypt_ft_destroy(fs, &fs->decrypt[i]); + } + accel_psp_fs_rx_check_ft_destroy(&fs->check); + accel_psp_fs_rx_ft_destroy(&fs->rx); } -static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, enum accel_fs_psp_type type) +static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs) { struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false); - struct mlx5e_psp_rx_decrypt_table *decrypt; - struct mlx5e_psp_rx *rx_fs = fs->rx_fs; - struct mlx5_flow_destination dest = {}; + int i, err; + + err = accel_psp_fs_rx_ft_create(fs, &fs->rx); + if (err) + return err; + + err = accel_psp_fs_rx_check_ft_create(fs, &fs->check); + if (err) + goto err_ft; + + for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { + struct mlx5_flow_destination dest; - decrypt = &rx_fs->decrypt[type]; + dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i)); + err = accel_psp_fs_rx_decrypt_ft_create(fs, &fs->decrypt[i], + &dest); + if (err) + goto err_decrypt_ft; + + dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; + dest.ft = fs->decrypt[i].ft; + mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest); + } + + return 0; - dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(type)); - return accel_psp_fs_rx_decrypt_ft_create(fs, decrypt, &dest); +err_decrypt_ft: + while (--i >= 0) { + mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); + accel_psp_fs_rx_decrypt_ft_destroy(fs, &fs->decrypt[i]); + } + accel_psp_fs_rx_check_ft_destroy(&fs->check); +err_ft: + accel_psp_fs_rx_ft_destroy(&fs->rx); + return err; } static void accel_psp_fs_rx_cleanup(struct mlx5e_psp_fs *fs) { - struct mlx5e_psp_rx *rx_fs = fs->rx_fs; - - if (!rx_fs) - return; - - accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_bad_counter); - accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_err_counter); - accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_auth_fail_counter); - accel_psp_fs_destroy_counter(fs->mdev, &rx_fs->rx_counter); - kfree(rx_fs); - fs->rx_fs = NULL; + accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_bad_counter); + accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_err_counter); + accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_auth_fail_counter); + accel_psp_fs_destroy_counter(fs->mdev, &fs->rx_counter); } static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs) @@ -575,11 +590,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs) struct mlx5_core_dev *mdev = fs->mdev; int err; - fs->rx_fs = kzalloc_obj(*fs->rx_fs); - if (!fs->rx_fs) - return -ENOMEM; - - err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_counter); + err = accel_psp_fs_create_counter(mdev, &fs->rx_counter); if (err) { mlx5_core_warn(mdev, "fail to create psp rx flow counter err=%d\n", @@ -587,8 +598,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs) goto out_err; } - err = accel_psp_fs_create_counter(mdev, - &fs->rx_fs->rx_auth_fail_counter); + err = accel_psp_fs_create_counter(mdev, &fs->rx_auth_fail_counter); if (err) { mlx5_core_warn(mdev, "fail to create psp rx auth fail flow counter err=%d\n", @@ -596,7 +606,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs) goto out_err; } - err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_err_counter); + err = accel_psp_fs_create_counter(mdev, &fs->rx_err_counter); if (err) { mlx5_core_warn(mdev, "fail to create psp rx error flow counter err=%d\n", @@ -604,7 +614,7 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs) goto out_err; } - err = accel_psp_fs_create_counter(mdev, &fs->rx_fs->rx_bad_counter); + err = accel_psp_fs_create_counter(mdev, &fs->rx_bad_counter); if (err) { mlx5_core_warn(mdev, "fail to create psp rx bad flow counter err=%d\n", @@ -621,84 +631,28 @@ static int accel_psp_fs_rx_init(struct mlx5e_psp_fs *fs) void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) { - struct mlx5_ttc_table *ttc; - struct mlx5e_psp_fs *fs; - int i; - if (!priv->psp) return; - fs = priv->psp->fs; - ttc = mlx5e_fs_get_ttc(fs->fs, false); - for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { - /* disconnect */ - mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); - - /* remove FT */ - accel_psp_fs_rx_destroy(fs, i); - } - accel_psp_fs_rx_check_ft_destroy(&fs->check); - accel_psp_fs_rx_ft_destroy(&priv->psp->fs->rx); + accel_psp_fs_rx_destroy(priv->psp->fs); } int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) { - struct mlx5_ttc_table *ttc; - struct mlx5e_psp_fs *fs; - int err, i; - if (!priv->psp) return 0; - fs = priv->psp->fs; - ttc = mlx5e_fs_get_ttc(fs->fs, false); - - err = accel_psp_fs_rx_ft_create(fs, &fs->rx); - if (err) - return err; - - err = accel_psp_fs_rx_check_ft_create(fs, &fs->check); - if (err) - goto err_ft; - - for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { - struct mlx5e_psp_rx_decrypt_table *decrypt; - struct mlx5_flow_destination dest = {}; - - /* create FT */ - err = accel_psp_fs_rx_create(fs, i); - if (err) - goto out_err; - - /* connect */ - dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; - decrypt = &fs->rx_fs->decrypt[i]; - dest.ft = decrypt->ft; - mlx5_ttc_fwd_dest(ttc, fs_psp2tt(i), &dest); - } - - return 0; - -out_err: - while (--i >= 0) { - mlx5_ttc_fwd_default_dest(ttc, fs_psp2tt(i)); - accel_psp_fs_rx_destroy(fs, i); - } - accel_psp_fs_rx_check_ft_destroy(&fs->check); -err_ft: - accel_psp_fs_rx_ft_destroy(&fs->rx); - - return err; + return accel_psp_fs_rx_create(priv->psp->fs); } -static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs) +static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs, + struct mlx5e_psp_tx_table *tx) { int inlen = MLX5_ST_SZ_BYTES(create_flow_group_in); struct mlx5_flow_table_attr ft_attr = {}; struct mlx5_flow_destination dest = {}; struct mlx5_core_dev *mdev = fs->mdev; struct mlx5_flow_act flow_act = {}; - struct mlx5e_psp_tx_table *tx_fs; u32 *in, *mc, *outer_headers_c; struct mlx5_flow_handle *rule; struct mlx5_flow_spec *spec; @@ -720,8 +674,7 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs) ft_attr.level = MLX5E_PSP_LEVEL; ft_attr.autogroup.max_num_groups = 1; - tx_fs = fs->tx_fs; - ft = mlx5_create_flow_table(tx_fs->ns, &ft_attr); + ft = mlx5_create_flow_table(tx->ns, &ft_attr); if (IS_ERR(ft)) { err = PTR_ERR(ft); mlx5_core_err(mdev, "PSP: fail to add psp tx flow table, err = %d\n", err); @@ -747,7 +700,7 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs) MLX5_FLOW_CONTEXT_ACTION_CRYPTO_ENCRYPT | MLX5_FLOW_CONTEXT_ACTION_COUNT; dest.type = MLX5_FLOW_DESTINATION_TYPE_COUNTER; - dest.counter = tx_fs->tx_counter; + dest.counter = fs->tx_counter; rule = mlx5_add_flow_rules(ft, spec, &flow_act, &dest, 1); if (IS_ERR(rule)) { err = PTR_ERR(rule); @@ -755,9 +708,9 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs) goto err_add_flow_rule; } - tx_fs->ft = ft; - tx_fs->fg = fg; - tx_fs->rule = rule; + tx->ft = ft; + tx->fg = fg; + tx->rule = rule; goto out; err_add_flow_rule: @@ -770,50 +723,35 @@ static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs) return err; } -static void accel_psp_fs_tx_ft_destroy(struct mlx5e_psp_tx_table *tx_fs) +static void accel_psp_fs_tx_ft_destroy(struct mlx5e_psp_tx_table *tx) { - accel_psp_fs_del_flow_rule(&tx_fs->rule); - accel_psp_fs_destroy_flow_group(&tx_fs->fg); - accel_psp_fs_destroy_ft(&tx_fs->ft); + accel_psp_fs_del_flow_rule(&tx->rule); + accel_psp_fs_destroy_flow_group(&tx->fg); + accel_psp_fs_destroy_ft(&tx->ft); } static void accel_psp_fs_tx_cleanup(struct mlx5e_psp_fs *fs) { - struct mlx5e_psp_tx_table *tx_fs = fs->tx_fs; - - if (!tx_fs) - return; - - accel_psp_fs_destroy_counter(fs->mdev, &tx_fs->tx_counter); - kfree(tx_fs); - fs->tx_fs = NULL; + accel_psp_fs_destroy_counter(fs->mdev, &fs->tx_counter); } static int accel_psp_fs_tx_init(struct mlx5e_psp_fs *fs) { struct mlx5_core_dev *mdev = fs->mdev; - struct mlx5e_psp_tx_table *tx_fs; - struct mlx5_flow_namespace *ns; int err; - ns = mlx5_get_flow_namespace(mdev, MLX5_FLOW_NAMESPACE_EGRESS_IPSEC); - if (!ns) + fs->tx.ns = mlx5_get_flow_namespace(mdev, + MLX5_FLOW_NAMESPACE_EGRESS_IPSEC); + if (!fs->tx.ns) return -EOPNOTSUPP; - tx_fs = kzalloc_obj(*tx_fs); - if (!tx_fs) - return -ENOMEM; - - err = accel_psp_fs_create_counter(mdev, &tx_fs->tx_counter); + err = accel_psp_fs_create_counter(mdev, &fs->tx_counter); if (err) { mlx5_core_warn(mdev, "fail to create psp tx flow counter err=%d\n", err); - kfree(tx_fs); return err; } - tx_fs->ns = ns; - fs->tx_fs = tx_fs; return 0; } @@ -821,30 +759,29 @@ static void mlx5e_accel_psp_fs_get_stats_fill(struct mlx5e_priv *priv, struct mlx5e_psp_stats *stats) { - struct mlx5e_psp_tx_table *tx_fs = priv->psp->fs->tx_fs; - struct mlx5e_psp_rx *rx_fs = priv->psp->fs->rx_fs; + struct mlx5e_psp_fs *fs = priv->psp->fs; struct mlx5_core_dev *mdev = priv->mdev; - if (tx_fs->tx_counter) - mlx5_fc_query(mdev, tx_fs->tx_counter, &stats->psp_tx_pkts, + if (fs->tx_counter) + mlx5_fc_query(mdev, fs->tx_counter, &stats->psp_tx_pkts, &stats->psp_tx_bytes); - if (rx_fs->rx_counter) - mlx5_fc_query(mdev, rx_fs->rx_counter, &stats->psp_rx_pkts, + if (fs->rx_counter) + mlx5_fc_query(mdev, fs->rx_counter, &stats->psp_rx_pkts, &stats->psp_rx_bytes); - if (rx_fs->rx_auth_fail_counter) - mlx5_fc_query(mdev, rx_fs->rx_auth_fail_counter, + if (fs->rx_auth_fail_counter) + mlx5_fc_query(mdev, fs->rx_auth_fail_counter, &stats->psp_rx_pkts_auth_fail, &stats->psp_rx_bytes_auth_fail); - if (rx_fs->rx_err_counter) - mlx5_fc_query(mdev, rx_fs->rx_err_counter, + if (fs->rx_err_counter) + mlx5_fc_query(mdev, fs->rx_err_counter, &stats->psp_rx_pkts_frame_err, &stats->psp_rx_bytes_frame_err); - if (rx_fs->rx_bad_counter) - mlx5_fc_query(mdev, rx_fs->rx_bad_counter, + if (fs->rx_bad_counter) + mlx5_fc_query(mdev, fs->rx_bad_counter, &stats->psp_rx_pkts_drop, &stats->psp_rx_bytes_drop); } @@ -854,7 +791,7 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) if (!priv->psp) return; - accel_psp_fs_tx_ft_destroy(priv->psp->fs->tx_fs); + accel_psp_fs_tx_ft_destroy(&priv->psp->fs->tx); } int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) @@ -862,7 +799,7 @@ int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) if (!priv->psp) return 0; - return accel_psp_fs_tx_ft_create(priv->psp->fs); + return accel_psp_fs_tx_ft_create(priv->psp->fs, &priv->psp->fs->tx); } static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs) -- 2.44.0 From: Cosmin Ratiu Only create PSP steering tables when PSP configuration is enabled on a PSP device. Previously, mlx5e_psp_set_config (== .set_config on the PSP device) did nothing. Steering was created and hooked up to incoming traffic at device initialization time, via mlx5e_init_nic_rx -> mlx5e_accel_init_rx -> mlx5_accel_psp_fs_init_rx_tables. Similarly, TX tables were created and hooked to egress traffic at mlx5e_init_nic_tx -> mlx5e_accel_init_tx -> mlx5_accel_psp_fs_init_tx_tables Doing this means both ingress and egress UDP packets go through the PSP steering tables, causing extra latency and overhead. A better solution is to let the incoming encrypted PSP packets get dropped by SW and not impose an overhead on all UDP packets which have to traverse the PSP steering rules when PSP isn't used. Additionally, upcoming changes to support HW-GRO need to reconfigure PSP steering dynamically and this patch is a necessary step in that direction. Two new functions are defined: - accel_psp_fs_create: Creates steering tables and connects RX UDP v4/v6 traffic to PSP RX tables. - accel_psp_fs_destroy: Disconnects incoming RX traffic from PSP steering and destroys steering tables. PSP steering cleanup, which happens independently from PSP device configuration, is unchanged. When the device is going away, steering tables are destroyed as well. The netdev lock is now used for proper synchronization between the new set_config flow and device steering init/cleanup. This will be important in future patches, when PSP will be able to reconfigure itself dynamically upon netdev feature changes. Signed-off-by: Cosmin Ratiu Reviewed-by: Dragos Tatulea Signed-off-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/en_accel.h | 19 +---- .../mellanox/mlx5/core/en_accel/psp.c | 73 +++++++++++++------ .../mellanox/mlx5/core/en_accel/psp.h | 12 --- 3 files changed, 53 insertions(+), 51 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h index b526b3898c22..3f212e46fc2f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h @@ -220,18 +220,7 @@ static inline void mlx5e_accel_tx_finish(struct mlx5e_txqsq *sq, static inline int mlx5e_accel_init_rx(struct mlx5e_priv *priv) { - int err; - - err = mlx5_accel_psp_fs_init_rx_tables(priv); - if (err) - goto out; - - err = mlx5e_ktls_init_rx(priv); - if (err) - mlx5_accel_psp_fs_cleanup_rx_tables(priv); - -out: - return err; + return mlx5e_ktls_init_rx(priv); } static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv) @@ -242,12 +231,6 @@ static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv) static inline int mlx5e_accel_init_tx(struct mlx5e_priv *priv) { - int err; - - err = mlx5_accel_psp_fs_init_tx_tables(priv); - if (err) - return err; - return mlx5e_ktls_init_tx(priv); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index b713f235a0f7..b3521c3861f6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -537,18 +537,24 @@ static void accel_psp_fs_rx_destroy(struct mlx5e_psp_fs *fs) accel_psp_fs_rx_ft_destroy(&fs->rx); } -static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs) +static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs, + struct netlink_ext_ack *extack) { struct mlx5_ttc_table *ttc = mlx5e_fs_get_ttc(fs->fs, false); int i, err; err = accel_psp_fs_rx_ft_create(fs, &fs->rx); - if (err) + if (err) { + NL_SET_ERR_MSG(extack, "Failed creating RX steering table"); return err; + } err = accel_psp_fs_rx_check_ft_create(fs, &fs->check); - if (err) + if (err) { + NL_SET_ERR_MSG(extack, + "Failed creating RX check steering table"); goto err_ft; + } for (i = 0; i < ACCEL_FS_PSP_NUM_TYPES; i++) { struct mlx5_flow_destination dest; @@ -556,8 +562,11 @@ static int accel_psp_fs_rx_create(struct mlx5e_psp_fs *fs) dest = mlx5_ttc_get_default_dest(ttc, fs_psp2tt(i)); err = accel_psp_fs_rx_decrypt_ft_create(fs, &fs->decrypt[i], &dest); - if (err) + if (err) { + NL_SET_ERR_MSG(extack, + "Failed creating RX decrypt steering table"); goto err_decrypt_ft; + } dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; dest.ft = fs->decrypt[i].ft; @@ -634,15 +643,9 @@ void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) if (!priv->psp) return; + netdev_lock(priv->netdev); accel_psp_fs_rx_destroy(priv->psp->fs); -} - -int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) -{ - if (!priv->psp) - return 0; - - return accel_psp_fs_rx_create(priv->psp->fs); + netdev_unlock(priv->netdev); } static int accel_psp_fs_tx_ft_create(struct mlx5e_psp_fs *fs, @@ -791,15 +794,9 @@ void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) if (!priv->psp) return; + netdev_lock(priv->netdev); accel_psp_fs_tx_ft_destroy(&priv->psp->fs->tx); -} - -int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) -{ - if (!priv->psp) - return 0; - - return accel_psp_fs_tx_ft_create(priv->psp->fs, &priv->psp->fs->tx); + netdev_unlock(priv->netdev); } static void mlx5e_accel_psp_fs_cleanup(struct mlx5e_psp_fs *fs) @@ -837,11 +834,45 @@ static struct mlx5e_psp_fs *mlx5e_accel_psp_fs_init(struct mlx5e_priv *priv) return ERR_PTR(err); } +static int accel_psp_fs_create(struct mlx5e_priv *priv, + struct netlink_ext_ack *extack) +{ + int err; + + err = accel_psp_fs_rx_create(priv->psp->fs, extack); + if (err) + return err; + + err = accel_psp_fs_tx_ft_create(priv->psp->fs, &priv->psp->fs->tx); + if (err) { + NL_SET_ERR_MSG(extack, "Failed creating TX steering table"); + accel_psp_fs_rx_destroy(priv->psp->fs); + } + return err; +} + +static void accel_psp_fs_destroy(struct mlx5e_priv *priv) +{ + accel_psp_fs_tx_ft_destroy(&priv->psp->fs->tx); + accel_psp_fs_rx_destroy(priv->psp->fs); +} + static int mlx5e_psp_set_config(struct psp_dev *psd, struct psp_dev_config *conf, struct netlink_ext_ack *extack) { - return 0; /* TODO: this should actually do things to the device */ + struct mlx5e_priv *priv = netdev_priv(psd->main_netdev); + bool psp_enabled = psd->config.versions; + bool enable_psp = conf->versions; + int err = 0; + + netdev_lock(priv->netdev); + if (!psp_enabled && enable_psp) + err = accel_psp_fs_create(priv, extack); + else if (psp_enabled && !enable_psp) + accel_psp_fs_destroy(priv); + netdev_unlock(priv->netdev); + return err; } static int diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h index a53f90f7c341..57fffcf4a62c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h @@ -43,26 +43,14 @@ static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev) return true; } -int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv); void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv); -int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv); void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv); void mlx5e_psp_register(struct mlx5e_priv *priv); void mlx5e_psp_unregister(struct mlx5e_priv *priv); int mlx5e_psp_init(struct mlx5e_priv *priv); void mlx5e_psp_cleanup(struct mlx5e_priv *priv); #else -static inline int mlx5_accel_psp_fs_init_rx_tables(struct mlx5e_priv *priv) -{ - return 0; -} - static inline void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv) { } -static inline int mlx5_accel_psp_fs_init_tx_tables(struct mlx5e_priv *priv) -{ - return 0; -} - static inline void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv) { } static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev) { -- 2.44.0 From: Cosmin Ratiu profile->enable is called before enabling an mlx5 netdevice and currently doesn't return errors. Code called from it has to either: 1. eat errors and keep going, leaving a netdevice initialized with missing functionality or 2. manually clean up things that other parts of the init flow might have set up. Option 1 might be useful in some cases for optional functionality but option 2 doesn't make for good design. Add a 3rd option for code which wants to propagate errors from profile->enable and fail netdev init. This change is a noop for now, the first 'user' of this option 3 will be in the next patch. Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/en.h | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 15 +++++++++++---- drivers/net/ethernet/mellanox/mlx5/core/en_rep.c | 8 ++++++-- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 2270e2e550dd..3cc7283b6215 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -1016,7 +1016,7 @@ struct mlx5e_profile { void (*cleanup_rx)(struct mlx5e_priv *priv); int (*init_tx)(struct mlx5e_priv *priv); void (*cleanup_tx)(struct mlx5e_priv *priv); - void (*enable)(struct mlx5e_priv *priv); + int (*enable)(struct mlx5e_priv *priv); void (*disable)(struct mlx5e_priv *priv); int (*update_rx)(struct mlx5e_priv *priv); void (*update_stats)(struct mlx5e_priv *priv); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 775f0c6e55c9..9eadd0b6f055 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -6191,7 +6191,7 @@ static int mlx5e_init_nic_tx(struct mlx5e_priv *priv) return 0; } -static void mlx5e_nic_enable(struct mlx5e_priv *priv) +static int mlx5e_nic_enable(struct mlx5e_priv *priv) { struct net_device *netdev = priv->netdev; struct mlx5_core_dev *mdev = priv->mdev; @@ -6222,7 +6222,7 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv) mlx5e_pcie_cong_event_init(priv); mlx5e_hv_vhca_stats_create(priv); if (netdev->reg_state != NETREG_REGISTERED) - return; + return 0; mlx5e_dcbnl_init_app(priv); mlx5e_nic_set_rx_mode(priv); @@ -6235,6 +6235,8 @@ static void mlx5e_nic_enable(struct mlx5e_priv *priv) netdev_unlock(netdev); netif_device_attach(netdev); rtnl_unlock(); + + return 0; } static void mlx5e_nic_disable(struct mlx5e_priv *priv) @@ -6616,13 +6618,18 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv) if (err) goto err_cleanup_tx; - if (profile->enable) - profile->enable(priv); + if (profile->enable) { + err = profile->enable(priv); + if (err) + goto err_cleanup_rx; + } mlx5e_update_features(priv->netdev); return 0; +err_cleanup_rx: + profile->cleanup_rx(priv); err_cleanup_tx: profile->cleanup_tx(priv); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c index c8b76d301c92..603051ab1eaa 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rep.c @@ -1262,9 +1262,11 @@ static void mlx5e_cleanup_rep_tx(struct mlx5e_priv *priv) mlx5e_rep_neigh_cleanup(rpriv); } -static void mlx5e_rep_enable(struct mlx5e_priv *priv) +static int mlx5e_rep_enable(struct mlx5e_priv *priv) { mlx5e_set_netdev_mtu_boundaries(priv); + + return 0; } static void mlx5e_rep_disable(struct mlx5e_priv *priv) @@ -1322,7 +1324,7 @@ static int uplink_rep_async_event(struct notifier_block *nb, unsigned long event return NOTIFY_DONE; } -static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv) +static int mlx5e_uplink_rep_enable(struct mlx5e_priv *priv) { struct net_device *netdev = priv->netdev; struct mlx5_core_dev *mdev = priv->mdev; @@ -1357,6 +1359,8 @@ static void mlx5e_uplink_rep_enable(struct mlx5e_priv *priv) netdev_unlock(netdev); netif_device_attach(netdev); rtnl_unlock(); + + return 0; } static void mlx5e_uplink_rep_disable(struct mlx5e_priv *priv) -- 2.44.0 From: Cosmin Ratiu mlx5e_psp_register() was forced to eat PSP dev registration errors as the caller was not propagating them. Change this so PSP dev registration failures get reported back to the caller instead. After the recent changes in the series, PSP dev registration failures will just leave some data structs in priv->psp (mostly counters), with no steering rules and no means to configure them. There's no point actively cleaning those up on failure, as they'll get removed during profile->cleanup. Signed-off-by: Cosmin Ratiu Signed-off-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c | 8 +++++--- drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h | 4 ++-- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 8 +++++++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c index b3521c3861f6..73b232379263 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.c @@ -1028,14 +1028,14 @@ void mlx5e_psp_unregister(struct mlx5e_priv *priv) psp->psd = NULL; } -void mlx5e_psp_register(struct mlx5e_priv *priv) +int mlx5e_psp_register(struct mlx5e_priv *priv) { struct mlx5e_psp *psp = priv->psp; struct psp_dev *psd; /* FW Caps missing */ if (!priv->psp) - return; + return 0; psp->caps.assoc_drv_spc = sizeof(u32); psp->caps.versions = 1 << PSP_VERSION_HDR0_AES_GCM_128; @@ -1047,9 +1047,11 @@ void mlx5e_psp_register(struct mlx5e_priv *priv) if (IS_ERR(psd)) { mlx5_core_err(priv->mdev, "PSP failed to register due to %pe\n", psd); - return; + return PTR_ERR(psd); } psp->psd = psd; + + return 0; } int mlx5e_psp_init(struct mlx5e_priv *priv) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h index 57fffcf4a62c..3f441e7dd55a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/psp.h @@ -45,7 +45,7 @@ static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev) void mlx5_accel_psp_fs_cleanup_rx_tables(struct mlx5e_priv *priv); void mlx5_accel_psp_fs_cleanup_tx_tables(struct mlx5e_priv *priv); -void mlx5e_psp_register(struct mlx5e_priv *priv); +int mlx5e_psp_register(struct mlx5e_priv *priv); void mlx5e_psp_unregister(struct mlx5e_priv *priv); int mlx5e_psp_init(struct mlx5e_priv *priv); void mlx5e_psp_cleanup(struct mlx5e_priv *priv); @@ -57,7 +57,7 @@ static inline bool mlx5_is_psp_device(struct mlx5_core_dev *mdev) return false; } -static inline void mlx5e_psp_register(struct mlx5e_priv *priv) { } +static inline int mlx5e_psp_register(struct mlx5e_priv *priv) { return 0; } static inline void mlx5e_psp_unregister(struct mlx5e_priv *priv) { } static inline int mlx5e_psp_init(struct mlx5e_priv *priv) { return 0; } static inline void mlx5e_psp_cleanup(struct mlx5e_priv *priv) { } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 9eadd0b6f055..2cb48b24d5ea 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -6199,7 +6199,9 @@ static int mlx5e_nic_enable(struct mlx5e_priv *priv) mlx5e_fs_init_l2_addr(priv->fs, netdev); mlx5e_ipsec_init(priv); - mlx5e_psp_register(priv); + err = mlx5e_psp_register(priv); + if (err) + goto out_ipsec_cleanup; err = mlx5e_macsec_init(priv); if (err) @@ -6237,6 +6239,10 @@ static int mlx5e_nic_enable(struct mlx5e_priv *priv) rtnl_unlock(); return 0; + +out_ipsec_cleanup: + mlx5e_ipsec_cleanup(priv); + return err; } static void mlx5e_nic_disable(struct mlx5e_priv *priv) -- 2.44.0