net/mlx5: SWS, fix reformat id error handling
authorVlad Dogaru <vdogaru@nvidia.com>
Tue, 20 May 2025 18:46:39 +0000 (21:46 +0300)
committerJakub Kicinski <kuba@kernel.org>
Thu, 22 May 2025 03:44:21 +0000 (20:44 -0700)
The firmware reformat id is a u32 and can't safely be returned as an
int. Because the functions also need a way to signal error, prefer to
return the id as an output parameter and keep the return code only for
success/error.

While we're at it, also extract some duplicate code to fetch the
reformat id from a more generic struct pkt_reformat.

Signed-off-by: Vlad Dogaru <vdogaru@nvidia.com>
Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/1747766802-958178-2-git-send-email-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/fs_cmd.c
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c
drivers/net/ethernet/mellanox/mlx5/core/fs_core.h
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/fs_dr.c
drivers/net/ethernet/mellanox/mlx5/core/steering/sws/fs_dr.h

index a47c29571f64739f00d662cf0e703154c962458c..1af76da8b1320e2f05091f260055e593c13aa350 100644 (file)
@@ -527,7 +527,7 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
        struct mlx5_flow_rule *dst;
        void *in_flow_context, *vlan;
        void *in_match_value;
-       int reformat_id = 0;
+       u32 reformat_id = 0;
        unsigned int inlen;
        int dst_cnt_size;
        u32 *in, action;
@@ -580,23 +580,21 @@ static int mlx5_cmd_set_fte(struct mlx5_core_dev *dev,
        MLX5_SET(flow_context, in_flow_context, action, action);
 
        if (!extended_dest && fte->act_dests.action.pkt_reformat) {
-               struct mlx5_pkt_reformat *pkt_reformat = fte->act_dests.action.pkt_reformat;
-
-               if (pkt_reformat->owner == MLX5_FLOW_RESOURCE_OWNER_SW) {
-                       reformat_id = mlx5_fs_dr_action_get_pkt_reformat_id(pkt_reformat);
-                       if (reformat_id < 0) {
-                               mlx5_core_err(dev,
-                                             "Unsupported SW-owned pkt_reformat type (%d) in FW-owned table\n",
-                                             pkt_reformat->reformat_type);
-                               err = reformat_id;
-                               goto err_out;
-                       }
-               } else {
-                       reformat_id = fte->act_dests.action.pkt_reformat->id;
+               struct mlx5_pkt_reformat *pkt_reformat =
+                       fte->act_dests.action.pkt_reformat;
+
+               err = mlx5_fs_get_packet_reformat_id(pkt_reformat,
+                                                    &reformat_id);
+               if (err) {
+                       mlx5_core_err(dev,
+                                     "Unsupported pkt_reformat type (%d)\n",
+                                     pkt_reformat->reformat_type);
+                       goto err_out;
                }
        }
 
-       MLX5_SET(flow_context, in_flow_context, packet_reformat_id, (u32)reformat_id);
+       MLX5_SET(flow_context, in_flow_context, packet_reformat_id,
+                reformat_id);
 
        if (fte->act_dests.action.modify_hdr) {
                if (fte->act_dests.action.modify_hdr->owner == MLX5_FLOW_RESOURCE_OWNER_SW) {
index 6163bc98d94a941058dd7d80c735235b857a9118..a81b81a3b8f0ebc1c6a7b4e22fae686d572daa5d 100644 (file)
@@ -1830,14 +1830,33 @@ static int create_auto_flow_group(struct mlx5_flow_table *ft,
        return err;
 }
 
+int mlx5_fs_get_packet_reformat_id(struct mlx5_pkt_reformat *pkt_reformat,
+                                  u32 *id)
+{
+       switch (pkt_reformat->owner) {
+       case MLX5_FLOW_RESOURCE_OWNER_FW:
+               *id = pkt_reformat->id;
+               return 0;
+       case MLX5_FLOW_RESOURCE_OWNER_SW:
+               return mlx5_fs_dr_action_get_pkt_reformat_id(pkt_reformat, id);
+       default:
+               return -EINVAL;
+       }
+}
+
 static bool mlx5_pkt_reformat_cmp(struct mlx5_pkt_reformat *p1,
                                  struct mlx5_pkt_reformat *p2)
 {
-       return p1->owner == p2->owner &&
-               (p1->owner == MLX5_FLOW_RESOURCE_OWNER_FW ?
-                p1->id == p2->id :
-                mlx5_fs_dr_action_get_pkt_reformat_id(p1) ==
-                mlx5_fs_dr_action_get_pkt_reformat_id(p2));
+       int err1, err2;
+       u32 id1, id2;
+
+       if (p1->owner != p2->owner)
+               return false;
+
+       err1 = mlx5_fs_get_packet_reformat_id(p1, &id1);
+       err2 = mlx5_fs_get_packet_reformat_id(p2, &id2);
+
+       return !err1 && !err2 && id1 == id2;
 }
 
 static bool mlx5_flow_dests_cmp(struct mlx5_flow_destination *d1,
index 0767239f651caa19d434daa0b0955e7efac86903..248a74108fb19a1b38deb5421199b764bbad4829 100644 (file)
@@ -386,6 +386,9 @@ u32 mlx5_fs_get_capabilities(struct mlx5_core_dev *dev, enum mlx5_flow_namespace
 
 struct mlx5_flow_root_namespace *find_root(struct fs_node *node);
 
+int mlx5_fs_get_packet_reformat_id(struct mlx5_pkt_reformat *pkt_reformat,
+                                  u32 *id);
+
 #define fs_get_obj(v, _node)  {v = container_of((_node), typeof(*v), node); }
 
 #define fs_list_for_each_entry(pos, root)              \
index 8007d3f523c94ee4e4fd8e629dc8a26163f9e338..f367997ab61e0d4247584db5b4dad8595e36e70a 100644 (file)
@@ -833,15 +833,21 @@ static u32 mlx5_cmd_dr_get_capabilities(struct mlx5_flow_root_namespace *ns,
        return steering_caps;
 }
 
-int mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat)
+int
+mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat,
+                                     u32 *reformat_id)
 {
+       struct mlx5dr_action *dr_action;
+
        switch (pkt_reformat->reformat_type) {
        case MLX5_REFORMAT_TYPE_L2_TO_VXLAN:
        case MLX5_REFORMAT_TYPE_L2_TO_NVGRE:
        case MLX5_REFORMAT_TYPE_L2_TO_L2_TUNNEL:
        case MLX5_REFORMAT_TYPE_L2_TO_L3_TUNNEL:
        case MLX5_REFORMAT_TYPE_INSERT_HDR:
-               return mlx5dr_action_get_pkt_reformat_id(pkt_reformat->fs_dr_action.dr_action);
+               dr_action = pkt_reformat->fs_dr_action.dr_action;
+               *reformat_id = mlx5dr_action_get_pkt_reformat_id(dr_action);
+               return 0;
        }
        return -EOPNOTSUPP;
 }
index 99a3b2eff6b8fdd5c946f71dea7944ea11040777..f869f2daefbf4029e48c5f3d1a3615feedf24df2 100644 (file)
@@ -38,7 +38,9 @@ struct mlx5_fs_dr_table {
 
 bool mlx5_fs_dr_is_supported(struct mlx5_core_dev *dev);
 
-int mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat);
+int
+mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat,
+                                     u32 *reformat_id);
 
 const struct mlx5_flow_cmds *mlx5_fs_cmd_get_dr_cmds(void);
 
@@ -49,9 +51,11 @@ static inline const struct mlx5_flow_cmds *mlx5_fs_cmd_get_dr_cmds(void)
        return NULL;
 }
 
-static inline u32 mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat)
+static inline int
+mlx5_fs_dr_action_get_pkt_reformat_id(struct mlx5_pkt_reformat *pkt_reformat,
+                                     u32 *reformat_id)
 {
-       return 0;
+       return -EOPNOTSUPP;
 }
 
 static inline bool mlx5_fs_dr_is_supported(struct mlx5_core_dev *dev)