1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2021, Mellanox Technologies inc. All rights reserved. */
3 
4 #ifndef __MLX5_EN_RX_RES_H__
5 #define __MLX5_EN_RX_RES_H__
6 
7 #include <linux/kernel.h>
8 #include "rqt.h"
9 #include "tir.h"
10 #include "fs.h"
11 #include "rss.h"
12 
13 struct mlx5e_rx_res;
14 
15 struct mlx5e_channels;
16 struct mlx5e_rss_params_hash;
17 
18 enum mlx5e_rx_res_features {
19 	MLX5E_RX_RES_FEATURE_INNER_FT = BIT(0),
20 	MLX5E_RX_RES_FEATURE_XSK = BIT(1),
21 	MLX5E_RX_RES_FEATURE_PTP = BIT(2),
22 };
23 
24 /* Setup */
25 struct mlx5e_rx_res *mlx5e_rx_res_alloc(void);
26 int mlx5e_rx_res_init(struct mlx5e_rx_res *res, struct mlx5_core_dev *mdev,
27 		      enum mlx5e_rx_res_features features, unsigned int max_nch,
28 		      u32 drop_rqn, const struct mlx5e_packet_merge_param *init_pkt_merge_param,
29 		      unsigned int init_nch);
30 void mlx5e_rx_res_destroy(struct mlx5e_rx_res *res);
31 void mlx5e_rx_res_free(struct mlx5e_rx_res *res);
32 
33 /* TIRN getters for flow steering */
34 u32 mlx5e_rx_res_get_tirn_direct(struct mlx5e_rx_res *res, unsigned int ix);
35 u32 mlx5e_rx_res_get_tirn_xsk(struct mlx5e_rx_res *res, unsigned int ix);
36 u32 mlx5e_rx_res_get_tirn_rss(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt);
37 u32 mlx5e_rx_res_get_tirn_rss_inner(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt);
38 u32 mlx5e_rx_res_get_tirn_ptp(struct mlx5e_rx_res *res);
39 
40 /* RQTN getters for modules that create their own TIRs */
41 u32 mlx5e_rx_res_get_rqtn_direct(struct mlx5e_rx_res *res, unsigned int ix);
42 
43 /* Activate/deactivate API */
44 void mlx5e_rx_res_channels_activate(struct mlx5e_rx_res *res, struct mlx5e_channels *chs);
45 void mlx5e_rx_res_channels_deactivate(struct mlx5e_rx_res *res);
46 int mlx5e_rx_res_xsk_activate(struct mlx5e_rx_res *res, struct mlx5e_channels *chs,
47 			      unsigned int ix);
48 int mlx5e_rx_res_xsk_deactivate(struct mlx5e_rx_res *res, unsigned int ix);
49 
50 /* Configuration API */
51 void mlx5e_rx_res_rss_set_indir_uniform(struct mlx5e_rx_res *res, unsigned int nch);
52 int mlx5e_rx_res_rss_get_rxfh(struct mlx5e_rx_res *res, u32 rss_idx,
53 			      u32 *indir, u8 *key, u8 *hfunc);
54 int mlx5e_rx_res_rss_set_rxfh(struct mlx5e_rx_res *res, u32 rss_idx,
55 			      const u32 *indir, const u8 *key, const u8 *hfunc);
56 
57 u8 mlx5e_rx_res_rss_get_hash_fields(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt);
58 int mlx5e_rx_res_rss_set_hash_fields(struct mlx5e_rx_res *res, enum mlx5_traffic_types tt,
59 				     u8 rx_hash_fields);
60 int mlx5e_rx_res_packet_merge_set_param(struct mlx5e_rx_res *res,
61 					struct mlx5e_packet_merge_param *pkt_merge_param);
62 
63 int mlx5e_rx_res_rss_init(struct mlx5e_rx_res *res, u32 *rss_idx, unsigned int init_nch);
64 int mlx5e_rx_res_rss_destroy(struct mlx5e_rx_res *res, u32 rss_idx);
65 int mlx5e_rx_res_rss_cnt(struct mlx5e_rx_res *res);
66 int mlx5e_rx_res_rss_index(struct mlx5e_rx_res *res, struct mlx5e_rss *rss);
67 struct mlx5e_rss *mlx5e_rx_res_rss_get(struct mlx5e_rx_res *res, u32 rss_idx);
68 
69 /* Workaround for hairpin */
70 struct mlx5e_rss_params_hash mlx5e_rx_res_get_current_hash(struct mlx5e_rx_res *res);
71 
72 #endif /* __MLX5_EN_RX_RES_H__ */
73