1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 /* Copyright (c) 2020 Mellanox Technologies */ 3 4 #ifndef __MLX5E_EN_MOD_HDR_H__ 5 #define __MLX5E_EN_MOD_HDR_H__ 6 7 #include <linux/hashtable.h> 8 #include <linux/mlx5/fs.h> 9 10 #define MLX5_MH_ACT_SZ MLX5_UN_SZ_BYTES(set_add_copy_action_in_auto) 11 12 struct mlx5e_mod_hdr_handle; 13 14 struct mlx5e_tc_mod_hdr_acts { 15 int num_actions; 16 int max_actions; 17 bool is_static; 18 void *actions; 19 }; 20 21 #define DECLARE_MOD_HDR_ACTS_ACTIONS(name, len) \ 22 u8 name[len][MLX5_MH_ACT_SZ] = {} 23 24 #define DECLARE_MOD_HDR_ACTS(name, acts_arr) \ 25 struct mlx5e_tc_mod_hdr_acts name = { \ 26 .max_actions = ARRAY_SIZE(acts_arr), \ 27 .is_static = true, \ 28 .actions = acts_arr, \ 29 } 30 31 char *mlx5e_mod_hdr_alloc(struct mlx5_core_dev *mdev, int namespace, 32 struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts); 33 void mlx5e_mod_hdr_dealloc(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts); 34 char *mlx5e_mod_hdr_get_item(struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts, int pos); 35 36 struct mlx5e_mod_hdr_handle * 37 mlx5e_mod_hdr_attach(struct mlx5_core_dev *mdev, 38 struct mod_hdr_tbl *tbl, 39 enum mlx5_flow_namespace_type namespace, 40 struct mlx5e_tc_mod_hdr_acts *mod_hdr_acts); 41 void mlx5e_mod_hdr_detach(struct mlx5_core_dev *mdev, 42 struct mod_hdr_tbl *tbl, 43 struct mlx5e_mod_hdr_handle *mh); 44 struct mlx5_modify_hdr *mlx5e_mod_hdr_get(struct mlx5e_mod_hdr_handle *mh); 45 46 void mlx5e_mod_hdr_tbl_init(struct mod_hdr_tbl *tbl); 47 void mlx5e_mod_hdr_tbl_destroy(struct mod_hdr_tbl *tbl); 48 49 static inline int mlx5e_mod_hdr_max_actions(struct mlx5_core_dev *mdev, int namespace) 50 { 51 if (namespace == MLX5_FLOW_NAMESPACE_FDB) /* FDB offloading */ 52 return MLX5_CAP_ESW_FLOWTABLE_FDB(mdev, max_modify_header_actions); 53 else /* namespace is MLX5_FLOW_NAMESPACE_KERNEL - NIC offloading */ 54 return MLX5_CAP_FLOWTABLE_NIC_RX(mdev, max_modify_header_actions); 55 } 56 57 #endif /* __MLX5E_EN_MOD_HDR_H__ */ 58