1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2025 NVIDIA Corporation & Affiliates */
3 
4 #ifndef __MLX5_FS_HWS_POOLS_H__
5 #define __MLX5_FS_HWS_POOLS_H__
6 
7 #include <linux/if_vlan.h>
8 #include "fs_pool.h"
9 #include "fs_core.h"
10 
11 #define MLX5_FS_INSERT_HDR_VLAN_ANCHOR MLX5_REFORMAT_CONTEXT_ANCHOR_MAC_START
12 #define MLX5_FS_INSERT_HDR_VLAN_OFFSET offsetof(struct vlan_ethhdr, h_vlan_proto)
13 #define MLX5_FS_INSERT_HDR_VLAN_SIZE sizeof(struct vlan_hdr)
14 
15 enum {
16 	MLX5_FS_DL3TNLTOL2_MAC_HDR_IDX = 0,
17 	MLX5_FS_DL3TNLTOL2_MAC_VLAN_HDR_IDX,
18 };
19 
20 struct mlx5_fs_hws_pr {
21 	struct mlx5_fs_hws_pr_bulk *bulk;
22 	u32 offset;
23 	u8 hdr_idx;
24 	u8 *data;
25 	size_t data_size;
26 };
27 
28 struct mlx5_fs_hws_pr_bulk {
29 	struct mlx5_fs_bulk fs_bulk;
30 	struct mlx5hws_action *hws_action;
31 	struct mlx5_fs_hws_pr prs_data[];
32 };
33 
34 struct mlx5_fs_hws_pr_pool_ctx {
35 	enum mlx5hws_action_type reformat_type;
36 	size_t encap_data_size;
37 };
38 
39 struct mlx5_fs_hws_mh {
40 	struct mlx5_fs_hws_mh_bulk *bulk;
41 	u32 offset;
42 	u8 *data;
43 };
44 
45 struct mlx5_fs_hws_mh_bulk {
46 	struct mlx5_fs_bulk fs_bulk;
47 	struct mlx5_fs_pool *mh_pool;
48 	struct mlx5hws_action *hws_action;
49 	struct mlx5_fs_hws_mh mhs_data[];
50 };
51 
52 int mlx5_fs_hws_pr_pool_init(struct mlx5_fs_pool *pr_pool,
53 			     struct mlx5_core_dev *dev, size_t encap_data_size,
54 			     enum mlx5hws_action_type reformat_type);
55 void mlx5_fs_hws_pr_pool_cleanup(struct mlx5_fs_pool *pr_pool);
56 
57 struct mlx5_fs_hws_pr *mlx5_fs_hws_pr_pool_acquire_pr(struct mlx5_fs_pool *pr_pool);
58 void mlx5_fs_hws_pr_pool_release_pr(struct mlx5_fs_pool *pr_pool,
59 				    struct mlx5_fs_hws_pr *pr_data);
60 struct mlx5hws_action *mlx5_fs_hws_pr_get_action(struct mlx5_fs_hws_pr *pr_data);
61 int mlx5_fs_hws_mh_pool_init(struct mlx5_fs_pool *fs_hws_mh_pool,
62 			     struct mlx5_core_dev *dev,
63 			     struct mlx5hws_action_mh_pattern *pattern);
64 void mlx5_fs_hws_mh_pool_cleanup(struct mlx5_fs_pool *fs_hws_mh_pool);
65 struct mlx5_fs_hws_mh *mlx5_fs_hws_mh_pool_acquire_mh(struct mlx5_fs_pool *mh_pool);
66 void mlx5_fs_hws_mh_pool_release_mh(struct mlx5_fs_pool *mh_pool,
67 				    struct mlx5_fs_hws_mh *mh_data);
68 bool mlx5_fs_hws_mh_pool_match(struct mlx5_fs_pool *mh_pool,
69 			       struct mlx5hws_action_mh_pattern *pattern);
70 struct mlx5hws_action *mlx5_fc_get_hws_action(struct mlx5hws_context *ctx,
71 					      struct mlx5_fc *counter);
72 void mlx5_fc_put_hws_action(struct mlx5_fc *counter);
73 #endif /* __MLX5_FS_HWS_POOLS_H__ */
74