1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019 Mellanox Technologies. */
3 
4 #ifndef __MLX5_EN_PARAMS_H__
5 #define __MLX5_EN_PARAMS_H__
6 
7 #include "en.h"
8 
9 struct mlx5e_xsk_param {
10 	u16 headroom;
11 	u16 chunk_size;
12 };
13 
14 struct mlx5e_rq_param {
15 	u32                        rqc[MLX5_ST_SZ_DW(rqc)];
16 	struct mlx5_wq_param       wq;
17 	struct mlx5e_rq_frags_info frags_info;
18 };
19 
20 struct mlx5e_sq_param {
21 	u32                        sqc[MLX5_ST_SZ_DW(sqc)];
22 	struct mlx5_wq_param       wq;
23 	bool                       is_mpw;
24 };
25 
26 struct mlx5e_cq_param {
27 	u32                        cqc[MLX5_ST_SZ_DW(cqc)];
28 	struct mlx5_wq_param       wq;
29 	u16                        eq_ix;
30 	u8                         cq_period_mode;
31 };
32 
33 struct mlx5e_channel_param {
34 	struct mlx5e_rq_param      rq;
35 	struct mlx5e_sq_param      sq;
36 	struct mlx5e_sq_param      xdp_sq;
37 	struct mlx5e_sq_param      icosq;
38 	struct mlx5e_cq_param      rx_cq;
39 	struct mlx5e_cq_param      tx_cq;
40 	struct mlx5e_cq_param      icosq_cq;
41 };
42 
43 static inline bool mlx5e_qid_get_ch_if_in_group(struct mlx5e_params *params,
44 						u16 qid,
45 						enum mlx5e_rq_group group,
46 						u16 *ix)
47 {
48 	int nch = params->num_channels;
49 	int ch = qid - nch * group;
50 
51 	if (ch < 0 || ch >= nch)
52 		return false;
53 
54 	*ix = ch;
55 	return true;
56 }
57 
58 static inline void mlx5e_qid_get_ch_and_group(struct mlx5e_params *params,
59 					      u16 qid,
60 					      u16 *ix,
61 					      enum mlx5e_rq_group *group)
62 {
63 	u16 nch = params->num_channels;
64 
65 	*ix = qid % nch;
66 	*group = qid / nch;
67 }
68 
69 static inline bool mlx5e_qid_validate(const struct mlx5e_profile *profile,
70 				      struct mlx5e_params *params, u64 qid)
71 {
72 	return qid < params->num_channels * profile->rq_groups;
73 }
74 
75 /* Parameter calculations */
76 
77 u16 mlx5e_get_linear_rq_headroom(struct mlx5e_params *params,
78 				 struct mlx5e_xsk_param *xsk);
79 u32 mlx5e_rx_get_min_frag_sz(struct mlx5e_params *params,
80 			     struct mlx5e_xsk_param *xsk);
81 u32 mlx5e_rx_get_linear_frag_sz(struct mlx5e_params *params,
82 				struct mlx5e_xsk_param *xsk);
83 u8 mlx5e_mpwqe_log_pkts_per_wqe(struct mlx5e_params *params,
84 				struct mlx5e_xsk_param *xsk);
85 bool mlx5e_rx_is_linear_skb(struct mlx5e_params *params,
86 			    struct mlx5e_xsk_param *xsk);
87 bool mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev *mdev,
88 				  struct mlx5e_params *params,
89 				  struct mlx5e_xsk_param *xsk);
90 u8 mlx5e_mpwqe_get_log_rq_size(struct mlx5e_params *params,
91 			       struct mlx5e_xsk_param *xsk);
92 u8 mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
93 				   struct mlx5e_params *params,
94 				   struct mlx5e_xsk_param *xsk);
95 u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
96 				   struct mlx5e_params *params,
97 				   struct mlx5e_xsk_param *xsk);
98 u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
99 			  struct mlx5e_params *params,
100 			  struct mlx5e_xsk_param *xsk);
101 
102 /* Build queue parameters */
103 
104 void mlx5e_build_rq_param(struct mlx5e_priv *priv,
105 			  struct mlx5e_params *params,
106 			  struct mlx5e_xsk_param *xsk,
107 			  struct mlx5e_rq_param *param);
108 void mlx5e_build_sq_param_common(struct mlx5e_priv *priv,
109 				 struct mlx5e_sq_param *param);
110 void mlx5e_build_rx_cq_param(struct mlx5e_priv *priv,
111 			     struct mlx5e_params *params,
112 			     struct mlx5e_xsk_param *xsk,
113 			     struct mlx5e_cq_param *param);
114 void mlx5e_build_tx_cq_param(struct mlx5e_priv *priv,
115 			     struct mlx5e_params *params,
116 			     struct mlx5e_cq_param *param);
117 void mlx5e_build_ico_cq_param(struct mlx5e_priv *priv,
118 			      u8 log_wq_size,
119 			      struct mlx5e_cq_param *param);
120 void mlx5e_build_icosq_param(struct mlx5e_priv *priv,
121 			     u8 log_wq_size,
122 			     struct mlx5e_sq_param *param);
123 void mlx5e_build_xdpsq_param(struct mlx5e_priv *priv,
124 			     struct mlx5e_params *params,
125 			     struct mlx5e_sq_param *param);
126 
127 #endif /* __MLX5_EN_PARAMS_H__ */
128