xref: /linux/drivers/net/ethernet/mellanox/mlx5/core/en/params.c (revision 91ec2035134982b98fab0609a9fd8480e8217dc1)
1 // SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
2 /* Copyright (c) 2019 Mellanox Technologies. */
3 
4 #include "en/params.h"
5 #include "en/txrx.h"
6 #include "en/port.h"
7 #include "en_accel/en_accel.h"
8 #include "en_accel/ipsec.h"
9 #include "en_accel/psp.h"
10 #include <linux/dim.h>
11 #include <net/page_pool/types.h>
12 #include <net/xdp_sock_drv.h>
13 #include <net/netdev_queues.h>
14 
15 #define MLX5_MPWRQ_MAX_LOG_WQE_SZ 18
16 #define MLX5_REP_MPWRQ_MAX_LOG_WQE_SZ 17
17 
mlx5e_mpwrq_min_page_shift(struct mlx5_core_dev * mdev)18 static u8 mlx5e_mpwrq_min_page_shift(struct mlx5_core_dev *mdev)
19 {
20 	u8 min_page_shift = MLX5_CAP_GEN_2(mdev, log_min_mkey_entity_size);
21 
22 	return min_page_shift ? : 12;
23 }
24 
mlx5e_mpwrq_page_shift(struct mlx5_core_dev * mdev,struct mlx5e_rq_opt_param * rqo)25 u8 mlx5e_mpwrq_page_shift(struct mlx5_core_dev *mdev,
26 			  struct mlx5e_rq_opt_param *rqo)
27 {
28 	struct netdev_queue_config *qcfg = rqo ? rqo->qcfg : NULL;
29 	struct mlx5e_xsk_param *xsk = mlx5e_rqo_xsk_param(rqo);
30 	u8 min_page_shift = mlx5e_mpwrq_min_page_shift(mdev);
31 	u8 req_page_shift;
32 
33 	if (xsk)
34 		req_page_shift = order_base_2(xsk->chunk_size);
35 	else if (qcfg && qcfg->rx_page_size)
36 		req_page_shift = order_base_2(qcfg->rx_page_size);
37 	else
38 		req_page_shift = PAGE_SHIFT;
39 
40 	/* Regular RQ uses order-0 pages, the NIC must be able to map them. */
41 	if (WARN_ON_ONCE(!xsk && req_page_shift < min_page_shift))
42 		min_page_shift = req_page_shift;
43 
44 	return max(req_page_shift, min_page_shift);
45 }
46 
47 enum mlx5e_mpwrq_umr_mode
mlx5e_mpwrq_umr_mode(struct mlx5_core_dev * mdev,struct mlx5e_rq_opt_param * rqo)48 mlx5e_mpwrq_umr_mode(struct mlx5_core_dev *mdev,
49 		     struct mlx5e_rq_opt_param *rqo)
50 {
51 	/* Different memory management schemes use different mechanisms to map
52 	 * user-mode memory. The stricter guarantees we have, the faster
53 	 * mechanisms we use:
54 	 * 1. MTT - direct mapping in page granularity.
55 	 * 2. KSM - indirect mapping to another MKey to arbitrary addresses, but
56 	 *    all mappings have the same size.
57 	 * 3. KLM - indirect mapping to another MKey to arbitrary addresses, and
58 	 *    mappings can have different sizes.
59 	 */
60 	struct mlx5e_xsk_param *xsk = mlx5e_rqo_xsk_param(rqo);
61 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
62 	bool unaligned = xsk ? xsk->unaligned : false;
63 	bool oversized = false;
64 
65 	if (xsk) {
66 		oversized = xsk->chunk_size < (1 << page_shift);
67 		WARN_ON_ONCE(xsk->chunk_size > (1 << page_shift));
68 	}
69 
70 	/* XSK frame size doesn't match the UMR page size, either because the
71 	 * frame size is not a power of two, or it's smaller than the minimal
72 	 * page size supported by the firmware.
73 	 * It's possible to receive packets bigger than MTU in certain setups.
74 	 * To avoid writing over the XSK frame boundary, the top region of each
75 	 * stride is mapped to a garbage page, resulting in two mappings of
76 	 * different sizes per frame.
77 	 */
78 	if (oversized) {
79 		/* An optimization for frame sizes equal to 3 * power_of_two.
80 		 * 3 KSMs point to the frame, and one KSM points to the garbage
81 		 * page, which works faster than KLM.
82 		 */
83 		if (xsk->chunk_size % 3 == 0 && is_power_of_2(xsk->chunk_size / 3))
84 			return MLX5E_MPWRQ_UMR_MODE_TRIPLE;
85 
86 		return MLX5E_MPWRQ_UMR_MODE_OVERSIZED;
87 	}
88 
89 	/* XSK frames can start at arbitrary unaligned locations, but they all
90 	 * have the same size which is a power of two. It allows to optimize to
91 	 * one KSM per frame.
92 	 */
93 	if (unaligned)
94 		return MLX5E_MPWRQ_UMR_MODE_UNALIGNED;
95 
96 	/* XSK: frames are naturally aligned, MTT can be used.
97 	 * Non-XSK: Allocations happen in units of CPU pages, therefore, the
98 	 * mappings are naturally aligned.
99 	 */
100 	return MLX5E_MPWRQ_UMR_MODE_ALIGNED;
101 }
102 
mlx5e_mpwrq_umr_entry_size(enum mlx5e_mpwrq_umr_mode mode)103 u8 mlx5e_mpwrq_umr_entry_size(enum mlx5e_mpwrq_umr_mode mode)
104 {
105 	switch (mode) {
106 	case MLX5E_MPWRQ_UMR_MODE_ALIGNED:
107 		return sizeof(struct mlx5_mtt);
108 	case MLX5E_MPWRQ_UMR_MODE_UNALIGNED:
109 		return sizeof(struct mlx5_ksm);
110 	case MLX5E_MPWRQ_UMR_MODE_OVERSIZED:
111 		return sizeof(struct mlx5_klm) * 2;
112 	case MLX5E_MPWRQ_UMR_MODE_TRIPLE:
113 		return sizeof(struct mlx5_ksm) * 4;
114 	}
115 	WARN_ONCE(1, "MPWRQ UMR mode %d is not known\n", mode);
116 	return 1;
117 }
118 
mlx5e_mpwrq_log_wqe_sz(struct mlx5_core_dev * mdev,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)119 u8 mlx5e_mpwrq_log_wqe_sz(struct mlx5_core_dev *mdev, u8 page_shift,
120 			  enum mlx5e_mpwrq_umr_mode umr_mode)
121 {
122 	u8 umr_entry_size = mlx5e_mpwrq_umr_entry_size(umr_mode);
123 	u8 max_pages_per_wqe, max_log_wqe_size_calc;
124 	u8 max_log_wqe_size_cap;
125 	u16 max_wqe_size;
126 
127 	/* Keep in sync with MLX5_MPWRQ_MAX_PAGES_PER_WQE. */
128 	max_wqe_size = mlx5e_get_max_sq_aligned_wqebbs(mdev) * MLX5_SEND_WQE_BB;
129 	max_pages_per_wqe = ALIGN_DOWN(max_wqe_size - sizeof(struct mlx5e_umr_wqe),
130 				       MLX5_UMR_FLEX_ALIGNMENT) / umr_entry_size;
131 	max_log_wqe_size_calc = ilog2(max_pages_per_wqe) + page_shift;
132 
133 	WARN_ON_ONCE(max_log_wqe_size_calc < MLX5E_ORDER2_MAX_PACKET_MTU);
134 
135 	max_log_wqe_size_cap = mlx5_core_is_ecpf(mdev) ?
136 			   MLX5_REP_MPWRQ_MAX_LOG_WQE_SZ : MLX5_MPWRQ_MAX_LOG_WQE_SZ;
137 
138 	return min_t(u8, max_log_wqe_size_calc, max_log_wqe_size_cap);
139 }
140 
mlx5e_mpwrq_pages_per_wqe(struct mlx5_core_dev * mdev,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)141 u8 mlx5e_mpwrq_pages_per_wqe(struct mlx5_core_dev *mdev, u8 page_shift,
142 			     enum mlx5e_mpwrq_umr_mode umr_mode)
143 {
144 	u8 log_wqe_sz = mlx5e_mpwrq_log_wqe_sz(mdev, page_shift, umr_mode);
145 	u8 pages_per_wqe;
146 
147 	pages_per_wqe = log_wqe_sz > page_shift ? (1 << (log_wqe_sz - page_shift)) : 1;
148 
149 	/* Two MTTs are needed to form an octword. The number of MTTs is encoded
150 	 * in octwords in a UMR WQE, so we need at least two to avoid mapping
151 	 * garbage addresses.
152 	 */
153 	if (WARN_ON_ONCE(pages_per_wqe < 2 && umr_mode == MLX5E_MPWRQ_UMR_MODE_ALIGNED))
154 		pages_per_wqe = 2;
155 
156 	/* Sanity check for further calculations to succeed. */
157 	BUILD_BUG_ON(MLX5_MPWRQ_MAX_PAGES_PER_WQE > 64);
158 	if (WARN_ON_ONCE(pages_per_wqe > MLX5_MPWRQ_MAX_PAGES_PER_WQE))
159 		return MLX5_MPWRQ_MAX_PAGES_PER_WQE;
160 
161 	return pages_per_wqe;
162 }
163 
mlx5e_mpwrq_umr_wqe_sz(struct mlx5_core_dev * mdev,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)164 u16 mlx5e_mpwrq_umr_wqe_sz(struct mlx5_core_dev *mdev, u8 page_shift,
165 			   enum mlx5e_mpwrq_umr_mode umr_mode)
166 {
167 	u8 pages_per_wqe = mlx5e_mpwrq_pages_per_wqe(mdev, page_shift, umr_mode);
168 	u8 umr_entry_size = mlx5e_mpwrq_umr_entry_size(umr_mode);
169 	u16 umr_wqe_sz;
170 
171 	umr_wqe_sz = sizeof(struct mlx5e_umr_wqe) +
172 		ALIGN(pages_per_wqe * umr_entry_size, MLX5_UMR_FLEX_ALIGNMENT);
173 
174 	WARN_ON_ONCE(DIV_ROUND_UP(umr_wqe_sz, MLX5_SEND_WQE_DS) > MLX5_WQE_CTRL_DS_MASK);
175 
176 	return umr_wqe_sz;
177 }
178 
mlx5e_mpwrq_umr_wqebbs(struct mlx5_core_dev * mdev,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)179 u8 mlx5e_mpwrq_umr_wqebbs(struct mlx5_core_dev *mdev, u8 page_shift,
180 			  enum mlx5e_mpwrq_umr_mode umr_mode)
181 {
182 	return DIV_ROUND_UP(mlx5e_mpwrq_umr_wqe_sz(mdev, page_shift, umr_mode),
183 			    MLX5_SEND_WQE_BB);
184 }
185 
mlx5e_mpwrq_mtts_per_wqe(struct mlx5_core_dev * mdev,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)186 u8 mlx5e_mpwrq_mtts_per_wqe(struct mlx5_core_dev *mdev, u8 page_shift,
187 			    enum mlx5e_mpwrq_umr_mode umr_mode)
188 {
189 	u8 pages_per_wqe = mlx5e_mpwrq_pages_per_wqe(mdev, page_shift, umr_mode);
190 
191 	/* Add another page as a buffer between WQEs. This page will absorb
192 	 * write overflow by the hardware, when receiving packets larger than
193 	 * MTU. These oversize packets are dropped by the driver at a later
194 	 * stage.
195 	 */
196 	return ALIGN(pages_per_wqe + 1,
197 		     MLX5_SEND_WQE_BB / mlx5e_mpwrq_umr_entry_size(umr_mode));
198 }
199 
mlx5e_mpwrq_max_num_entries(struct mlx5_core_dev * mdev,enum mlx5e_mpwrq_umr_mode umr_mode)200 u32 mlx5e_mpwrq_max_num_entries(struct mlx5_core_dev *mdev,
201 				enum mlx5e_mpwrq_umr_mode umr_mode)
202 {
203 	/* Same limits apply to KSMs and KLMs. */
204 	u32 klm_limit = min(MLX5E_MAX_RQ_NUM_KSMS,
205 			    1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size));
206 
207 	switch (umr_mode) {
208 	case MLX5E_MPWRQ_UMR_MODE_ALIGNED:
209 		return MLX5E_MAX_RQ_NUM_MTTS;
210 	case MLX5E_MPWRQ_UMR_MODE_UNALIGNED:
211 		return klm_limit;
212 	case MLX5E_MPWRQ_UMR_MODE_OVERSIZED:
213 		/* Each entry is two KLMs. */
214 		return klm_limit / 2;
215 	case MLX5E_MPWRQ_UMR_MODE_TRIPLE:
216 		/* Each entry is four KSMs. */
217 		return klm_limit / 4;
218 	}
219 	WARN_ONCE(1, "MPWRQ UMR mode %d is not known\n", umr_mode);
220 	return 0;
221 }
222 
mlx5e_mpwrq_max_log_rq_size(struct mlx5_core_dev * mdev,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)223 static u8 mlx5e_mpwrq_max_log_rq_size(struct mlx5_core_dev *mdev, u8 page_shift,
224 				      enum mlx5e_mpwrq_umr_mode umr_mode)
225 {
226 	u8 mtts_per_wqe = mlx5e_mpwrq_mtts_per_wqe(mdev, page_shift, umr_mode);
227 	u32 max_entries = mlx5e_mpwrq_max_num_entries(mdev, umr_mode);
228 
229 	return ilog2(max_entries / mtts_per_wqe);
230 }
231 
mlx5e_mpwrq_max_log_rq_pkts(struct mlx5_core_dev * mdev,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)232 u8 mlx5e_mpwrq_max_log_rq_pkts(struct mlx5_core_dev *mdev, u8 page_shift,
233 			       enum mlx5e_mpwrq_umr_mode umr_mode)
234 {
235 	return mlx5e_mpwrq_max_log_rq_size(mdev, page_shift, umr_mode) +
236 		mlx5e_mpwrq_log_wqe_sz(mdev, page_shift, umr_mode) -
237 		MLX5E_ORDER2_MAX_PACKET_MTU;
238 }
239 
mlx5e_get_linear_rq_headroom(struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)240 u16 mlx5e_get_linear_rq_headroom(struct mlx5e_params *params,
241 				 struct mlx5e_rq_opt_param *rqo)
242 {
243 	u16 headroom;
244 
245 	if (mlx5e_rqo_xsk_param(rqo))
246 		return rqo->xsk->headroom;
247 
248 	headroom = NET_IP_ALIGN;
249 	if (params->xdp_prog)
250 		headroom += XDP_PACKET_HEADROOM;
251 	else
252 		headroom += MLX5_RX_HEADROOM;
253 
254 	return headroom;
255 }
256 
mlx5e_rx_get_linear_sz_xsk(struct mlx5e_params * params,struct mlx5e_xsk_param * xsk)257 static u32 mlx5e_rx_get_linear_sz_xsk(struct mlx5e_params *params,
258 				      struct mlx5e_xsk_param *xsk)
259 {
260 	u32 hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
261 
262 	return xsk->headroom + hw_mtu;
263 }
264 
mlx5e_rx_get_linear_sz_skb(struct mlx5e_params * params,bool no_head_tail_room)265 static u32 mlx5e_rx_get_linear_sz_skb(struct mlx5e_params *params, bool no_head_tail_room)
266 {
267 	u32 hw_mtu = MLX5E_SW2HW_MTU(params, params->sw_mtu);
268 	u16 headroom;
269 
270 	if (no_head_tail_room)
271 		return SKB_DATA_ALIGN(hw_mtu);
272 	headroom = mlx5e_get_linear_rq_headroom(params, NULL);
273 
274 	return MLX5_SKB_FRAG_SZ(headroom + hw_mtu);
275 }
276 
mlx5e_rx_get_linear_stride_sz(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo,bool mpwqe)277 static u32 mlx5e_rx_get_linear_stride_sz(struct mlx5_core_dev *mdev,
278 					 struct mlx5e_params *params,
279 					 struct mlx5e_rq_opt_param *rqo,
280 					 bool mpwqe)
281 {
282 	struct mlx5e_xsk_param *xsk = mlx5e_rqo_xsk_param(rqo);
283 	bool no_head_tail_room;
284 	u32 sz;
285 
286 	/* XSK frames are mapped as individual pages, because frames may come in
287 	 * an arbitrary order from random locations in the UMEM.
288 	 */
289 	if (xsk) {
290 		return mpwqe ?
291 			BIT(mlx5e_mpwrq_page_shift(mdev, rqo)) : PAGE_SIZE;
292 	}
293 
294 	no_head_tail_room = params->xdp_prog && mpwqe &&
295 			    !mlx5e_rx_is_linear_skb(mdev, params, rqo);
296 
297 	/* When no_head_tail_room is set, headroom and tailroom are excluded from skb calculations.
298 	 * no_head_tail_room should be set in the case of XDP with Striding RQ
299 	 * when SKB is not linear. This is because another page is allocated for the linear part.
300 	 */
301 	sz = mlx5e_rx_get_linear_sz_skb(params, no_head_tail_room);
302 
303 	return roundup_pow_of_two(sz);
304 }
305 
mlx5e_mpwqe_log_pkts_per_wqe(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)306 static u8 mlx5e_mpwqe_log_pkts_per_wqe(struct mlx5_core_dev *mdev,
307 				       struct mlx5e_params *params,
308 				       struct mlx5e_rq_opt_param *rqo)
309 {
310 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
311 	u32 linear_stride_sz =
312 		mlx5e_rx_get_linear_stride_sz(mdev, params, rqo, true);
313 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
314 
315 	return mlx5e_mpwrq_log_wqe_sz(mdev, page_shift, umr_mode) -
316 		order_base_2(linear_stride_sz);
317 }
318 
mlx5e_rx_is_linear_skb(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)319 bool mlx5e_rx_is_linear_skb(struct mlx5_core_dev *mdev,
320 			    struct mlx5e_params *params,
321 			    struct mlx5e_rq_opt_param *rqo)
322 {
323 	struct mlx5e_xsk_param *xsk = mlx5e_rqo_xsk_param(rqo);
324 
325 	if (params->packet_merge.type != MLX5E_PACKET_MERGE_NONE)
326 		return false;
327 
328 	/* Call mlx5e_rx_get_linear_sz_skb with the no_head_tail_room parameter set
329 	 * to exclude headroom and tailroom from calculations.
330 	 * no_head_tail_room is true when SKB is built on XDP_PASS on XSK RQs
331 	 * since packet data buffers don't have headroom and tailroom resreved for the SKB.
332 	 * Both XSK and non-XSK cases allocate an SKB on XDP_PASS. Packet data
333 	 * must fit into a CPU page.
334 	 */
335 	if (mlx5e_rx_get_linear_sz_skb(params, !!xsk) > PAGE_SIZE)
336 		return false;
337 
338 	/* XSK frames must be big enough to hold the packet data. */
339 	if (xsk && mlx5e_rx_get_linear_sz_xsk(params, xsk) > xsk->chunk_size)
340 		return false;
341 
342 	return true;
343 }
344 
mlx5e_verify_rx_mpwqe_strides(struct mlx5_core_dev * mdev,u8 log_stride_sz,u8 log_num_strides,u8 page_shift,enum mlx5e_mpwrq_umr_mode umr_mode)345 static bool mlx5e_verify_rx_mpwqe_strides(struct mlx5_core_dev *mdev,
346 					  u8 log_stride_sz, u8 log_num_strides,
347 					  u8 page_shift,
348 					  enum mlx5e_mpwrq_umr_mode umr_mode)
349 {
350 	if (log_stride_sz + log_num_strides !=
351 	    mlx5e_mpwrq_log_wqe_sz(mdev, page_shift, umr_mode))
352 		return false;
353 
354 	if (log_stride_sz < MLX5_MPWQE_LOG_STRIDE_SZ_BASE ||
355 	    log_stride_sz > MLX5_MPWQE_LOG_STRIDE_SZ_MAX)
356 		return false;
357 
358 	if (log_num_strides > MLX5_MPWQE_LOG_NUM_STRIDES_MAX)
359 		return false;
360 
361 	if (MLX5_CAP_GEN(mdev, ext_stride_num_range))
362 		return log_num_strides >= MLX5_MPWQE_LOG_NUM_STRIDES_EXT_BASE;
363 
364 	return log_num_strides >= MLX5_MPWQE_LOG_NUM_STRIDES_BASE;
365 }
366 
mlx5e_verify_params_rx_mpwqe_strides(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)367 bool mlx5e_verify_params_rx_mpwqe_strides(struct mlx5_core_dev *mdev,
368 					  struct mlx5e_params *params,
369 					  struct mlx5e_rq_opt_param *rqo)
370 {
371 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
372 	u8 log_wqe_num_of_strides =
373 		mlx5e_mpwqe_get_log_num_strides(mdev, params, rqo);
374 	u8 log_wqe_stride_size =
375 		mlx5e_mpwqe_get_log_stride_size(mdev, params, rqo);
376 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
377 
378 	return mlx5e_verify_rx_mpwqe_strides(mdev, log_wqe_stride_size,
379 					     log_wqe_num_of_strides,
380 					     page_shift, umr_mode);
381 }
382 
mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)383 bool mlx5e_rx_mpwqe_is_linear_skb(struct mlx5_core_dev *mdev,
384 				  struct mlx5e_params *params,
385 				  struct mlx5e_rq_opt_param *rqo)
386 {
387 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
388 	u32 linear_stride_sz =
389 		mlx5e_rx_get_linear_stride_sz(mdev, params, rqo, true);
390 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
391 	u8 log_num_strides;
392 	u8 log_stride_sz;
393 	u8 log_wqe_sz;
394 
395 	if (!mlx5e_rx_is_linear_skb(mdev, params, rqo))
396 		return false;
397 
398 	log_stride_sz = order_base_2(linear_stride_sz);
399 	log_wqe_sz = mlx5e_mpwrq_log_wqe_sz(mdev, page_shift, umr_mode);
400 
401 	if (log_wqe_sz < log_stride_sz)
402 		return false;
403 
404 	log_num_strides = log_wqe_sz - log_stride_sz;
405 
406 	return mlx5e_verify_rx_mpwqe_strides(mdev, log_stride_sz,
407 					     log_num_strides, page_shift,
408 					     umr_mode);
409 }
410 
mlx5e_mpwqe_get_log_rq_size(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)411 u8 mlx5e_mpwqe_get_log_rq_size(struct mlx5_core_dev *mdev,
412 			       struct mlx5e_params *params,
413 			       struct mlx5e_rq_opt_param *rqo)
414 {
415 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
416 	u8 log_pkts_per_wqe, page_shift, max_log_rq_size;
417 
418 	log_pkts_per_wqe = mlx5e_mpwqe_log_pkts_per_wqe(mdev, params, rqo);
419 	page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
420 	max_log_rq_size = mlx5e_mpwrq_max_log_rq_size(mdev, page_shift, umr_mode);
421 
422 	/* Numbers are unsigned, don't subtract to avoid underflow. */
423 	if (params->log_rq_mtu_frames <
424 	    log_pkts_per_wqe + MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW)
425 		return MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE_MPW;
426 
427 	/* Ethtool's rx_max_pending is calculated for regular RQ, that uses
428 	 * pages of PAGE_SIZE. Max length of an XSK RQ might differ if it uses a
429 	 * frame size not equal to PAGE_SIZE.
430 	 * A stricter condition is checked in mlx5e_mpwrq_validate_xsk, WARN on
431 	 * unexpected failure.
432 	 */
433 	if (WARN_ON_ONCE(params->log_rq_mtu_frames > log_pkts_per_wqe + max_log_rq_size))
434 		return max_log_rq_size;
435 
436 	return params->log_rq_mtu_frames - log_pkts_per_wqe;
437 }
438 
mlx5e_shampo_get_log_pkt_per_rsrv(struct mlx5e_params * params)439 static u8 mlx5e_shampo_get_log_pkt_per_rsrv(struct mlx5e_params *params)
440 {
441 	return order_base_2(DIV_ROUND_UP(MLX5E_SHAMPO_WQ_RESRV_SIZE,
442 					 params->sw_mtu));
443 }
444 
mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)445 u8 mlx5e_mpwqe_get_log_stride_size(struct mlx5_core_dev *mdev,
446 				   struct mlx5e_params *params,
447 				   struct mlx5e_rq_opt_param *rqo)
448 {
449 	if (mlx5e_rx_mpwqe_is_linear_skb(mdev, params, rqo))
450 		return order_base_2(mlx5e_rx_get_linear_stride_sz(mdev, params,
451 								  rqo, true));
452 
453 	return MLX5_MPWRQ_DEF_LOG_STRIDE_SZ(mdev);
454 }
455 
mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)456 u8 mlx5e_mpwqe_get_log_num_strides(struct mlx5_core_dev *mdev,
457 				   struct mlx5e_params *params,
458 				   struct mlx5e_rq_opt_param *rqo)
459 {
460 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
461 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
462 	u8 log_wqe_size, log_stride_size;
463 
464 	log_wqe_size = mlx5e_mpwrq_log_wqe_sz(mdev, page_shift, umr_mode);
465 	log_stride_size = mlx5e_mpwqe_get_log_stride_size(mdev, params, rqo);
466 	WARN(log_wqe_size < log_stride_size,
467 	     "Log WQE size %u < log stride size %u (page shift %u, umr mode %d, xsk on? %d)\n",
468 	     log_wqe_size, log_stride_size, page_shift, umr_mode,
469 	     rqo && rqo->xsk);
470 	return log_wqe_size - log_stride_size;
471 }
472 
mlx5e_mpwqe_get_min_wqe_bulk(unsigned int wq_sz)473 u8 mlx5e_mpwqe_get_min_wqe_bulk(unsigned int wq_sz)
474 {
475 #define UMR_WQE_BULK (2)
476 	return min_t(unsigned int, UMR_WQE_BULK, wq_sz / 2 - 1);
477 }
478 
mlx5e_get_rq_headroom(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)479 u16 mlx5e_get_rq_headroom(struct mlx5_core_dev *mdev,
480 			  struct mlx5e_params *params,
481 			  struct mlx5e_rq_opt_param *rqo)
482 {
483 	u16 linear_headroom = mlx5e_get_linear_rq_headroom(params, rqo);
484 
485 	if (params->rq_wq_type == MLX5_WQ_TYPE_CYCLIC)
486 		return linear_headroom;
487 
488 	if (mlx5e_rx_mpwqe_is_linear_skb(mdev, params, rqo))
489 		return linear_headroom;
490 
491 	if (params->packet_merge.type == MLX5E_PACKET_MERGE_SHAMPO)
492 		return linear_headroom;
493 
494 	return 0;
495 }
496 
mlx5e_mpwrq_max_page_size(struct mlx5_core_dev * mdev)497 u32 mlx5e_mpwrq_max_page_size(struct mlx5_core_dev *mdev)
498 {
499 	if (mlx5_core_is_ecpf(mdev))
500 		return PAGE_SIZE;
501 
502 	/* Two MTTs are needed to form an octword. Driver is using a
503 	 * single page per MTT for simplicity. Hence the limit of having
504 	 * at least 2 pages per WQE.
505 	 */
506 	return BIT(MLX5_MPWRQ_MAX_LOG_WQE_SZ - 1);
507 }
508 
mlx5e_calc_sq_stop_room(struct mlx5_core_dev * mdev,struct mlx5e_params * params)509 u16 mlx5e_calc_sq_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *params)
510 {
511 	bool is_mpwqe = MLX5E_GET_PFLAG(params, MLX5E_PFLAG_SKB_TX_MPWQE);
512 	u16 stop_room;
513 
514 	stop_room  = mlx5e_ktls_get_stop_room(mdev, params);
515 	stop_room += mlx5e_stop_room_for_max_wqe(mdev);
516 	if (is_mpwqe)
517 		/* A MPWQE can take up to the maximum cacheline-aligned WQE +
518 		 * all the normal stop room can be taken if a new packet breaks
519 		 * the active MPWQE session and allocates its WQEs right away.
520 		 */
521 		stop_room += mlx5e_stop_room_for_mpwqe(mdev);
522 
523 	return stop_room;
524 }
525 
mlx5e_validate_params(struct mlx5_core_dev * mdev,struct mlx5e_params * params)526 int mlx5e_validate_params(struct mlx5_core_dev *mdev, struct mlx5e_params *params)
527 {
528 	size_t sq_size = 1 << params->log_sq_size;
529 	u16 stop_room;
530 
531 	stop_room = mlx5e_calc_sq_stop_room(mdev, params);
532 	if (stop_room >= sq_size) {
533 		mlx5_core_err(mdev, "Stop room %u is bigger than the SQ size %zu\n",
534 			      stop_room, sq_size);
535 		return -EINVAL;
536 	}
537 
538 	return 0;
539 }
540 
slow_pci_heuristic(struct mlx5_core_dev * mdev)541 bool slow_pci_heuristic(struct mlx5_core_dev *mdev)
542 {
543 	u32 link_speed = 0;
544 	u32 pci_bw = 0;
545 
546 	mlx5_port_max_linkspeed(mdev, &link_speed);
547 	pci_bw = pcie_bandwidth_available(mdev->pdev, NULL, NULL, NULL);
548 	mlx5_core_dbg(mdev, "Max link speed = %d, PCI BW = %d\n", link_speed,
549 		      pci_bw);
550 
551 #define MLX5E_SLOW_PCI_RATIO (2)
552 
553 	return link_speed && pci_bw &&
554 		link_speed > MLX5E_SLOW_PCI_RATIO * pci_bw;
555 }
556 
mlx5e_mpwrq_validate_regular(struct mlx5_core_dev * mdev,struct mlx5e_params * params)557 int mlx5e_mpwrq_validate_regular(struct mlx5_core_dev *mdev, struct mlx5e_params *params)
558 {
559 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, NULL);
560 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, NULL);
561 
562 	if (!mlx5e_check_fragmented_striding_rq_cap(mdev, page_shift, umr_mode))
563 		return -EOPNOTSUPP;
564 
565 	return 0;
566 }
567 
mlx5e_mpwrq_validate_xsk(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)568 int mlx5e_mpwrq_validate_xsk(struct mlx5_core_dev *mdev, struct mlx5e_params *params,
569 			     struct mlx5e_rq_opt_param *rqo)
570 {
571 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
572 	struct mlx5e_xsk_param *xsk = mlx5e_rqo_xsk_param(rqo);
573 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
574 	u16 max_mtu_pkts;
575 
576 	if (!mlx5e_check_fragmented_striding_rq_cap(mdev, page_shift, umr_mode)) {
577 		mlx5_core_err(mdev, "Striding RQ for XSK can't be activated with page_shift %u and umr_mode %d\n",
578 			      page_shift, umr_mode);
579 		return -EOPNOTSUPP;
580 	}
581 
582 	if (!mlx5e_rx_mpwqe_is_linear_skb(mdev, params, rqo)) {
583 		mlx5_core_err(mdev, "Striding RQ linear mode for XSK can't be activated with current params\n");
584 		return -EINVAL;
585 	}
586 
587 	/* Current RQ length is too big for the given frame size, the
588 	 * needed number of WQEs exceeds the maximum.
589 	 */
590 	max_mtu_pkts = min_t(u8, MLX5E_PARAMS_MAXIMUM_LOG_RQ_SIZE,
591 			     mlx5e_mpwrq_max_log_rq_pkts(mdev, page_shift, xsk->unaligned));
592 	if (params->log_rq_mtu_frames > max_mtu_pkts) {
593 		mlx5_core_err(mdev, "Current RQ length %d is too big for XSK with given frame size %u\n",
594 			      1 << params->log_rq_mtu_frames,
595 			      xsk->chunk_size);
596 		return -EINVAL;
597 	}
598 
599 	return 0;
600 }
601 
mlx5e_init_rq_type_params(struct mlx5_core_dev * mdev,struct mlx5e_params * params)602 void mlx5e_init_rq_type_params(struct mlx5_core_dev *mdev,
603 			       struct mlx5e_params *params)
604 {
605 	params->log_rq_mtu_frames = is_kdump_kernel() ?
606 		MLX5E_PARAMS_MINIMUM_LOG_RQ_SIZE :
607 		MLX5E_PARAMS_DEFAULT_LOG_RQ_SIZE;
608 }
609 
mlx5e_set_rq_type(struct mlx5_core_dev * mdev,struct mlx5e_params * params)610 void mlx5e_set_rq_type(struct mlx5_core_dev *mdev, struct mlx5e_params *params)
611 {
612 	params->rq_wq_type = MLX5E_GET_PFLAG(params, MLX5E_PFLAG_RX_STRIDING_RQ) ?
613 		MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ :
614 		MLX5_WQ_TYPE_CYCLIC;
615 }
616 
mlx5e_build_rq_params(struct mlx5_core_dev * mdev,struct mlx5e_params * params)617 void mlx5e_build_rq_params(struct mlx5_core_dev *mdev,
618 			   struct mlx5e_params *params)
619 {
620 	/* Prefer Striding RQ, unless any of the following holds:
621 	 * - Striding RQ configuration is not possible/supported.
622 	 * - CQE compression is ON, and stride_index mini_cqe layout is not supported.
623 	 * - Legacy RQ would use linear SKB while Striding RQ would use non-linear.
624 	 *
625 	 * No XSK params: checking the availability of striding RQ in general.
626 	 */
627 	if ((!MLX5E_GET_PFLAG(params, MLX5E_PFLAG_RX_CQE_COMPRESS) ||
628 	     MLX5_CAP_GEN(mdev, mini_cqe_resp_stride_index)) &&
629 	    !mlx5e_mpwrq_validate_regular(mdev, params) &&
630 	    (mlx5e_rx_mpwqe_is_linear_skb(mdev, params, NULL) ||
631 	     !mlx5e_rx_is_linear_skb(mdev, params, NULL)))
632 		MLX5E_SET_PFLAG(params, MLX5E_PFLAG_RX_STRIDING_RQ, true);
633 	mlx5e_set_rq_type(mdev, params);
634 	mlx5e_init_rq_type_params(mdev, params);
635 }
636 
637 /* Build queue parameters */
638 
mlx5e_build_create_cq_param(struct mlx5e_create_cq_param * ccp,struct mlx5e_channel * c)639 void mlx5e_build_create_cq_param(struct mlx5e_create_cq_param *ccp, struct mlx5e_channel *c)
640 {
641 	*ccp = (struct mlx5e_create_cq_param) {
642 		.netdev = c->netdev,
643 		.wq = c->priv->wq,
644 		.napi = &c->napi,
645 		.ch_stats = c->stats,
646 		.node = cpu_to_node(c->cpu),
647 		.ix = c->vec_ix,
648 		.uar = c->bfreg->up,
649 	};
650 }
651 
mlx5e_max_nonlinear_mtu(int first_frag_size,int frag_size,bool xdp)652 static int mlx5e_max_nonlinear_mtu(int first_frag_size, int frag_size, bool xdp)
653 {
654 	if (xdp)
655 		/* XDP requires all fragments to be of the same size. */
656 		return first_frag_size + (MLX5E_MAX_RX_FRAGS - 1) * frag_size;
657 
658 	/* Optimization for small packets: the last fragment is bigger than the others. */
659 	return first_frag_size + (MLX5E_MAX_RX_FRAGS - 2) * frag_size + PAGE_SIZE;
660 }
661 
mlx5e_rx_compute_wqe_bulk_params(struct mlx5e_params * params,struct mlx5e_rq_frags_info * info)662 static void mlx5e_rx_compute_wqe_bulk_params(struct mlx5e_params *params,
663 					     struct mlx5e_rq_frags_info *info)
664 {
665 	u16 bulk_bound_rq_size = (1 << params->log_rq_mtu_frames) / 4;
666 	u32 bulk_bound_rq_size_in_bytes;
667 	u32 sum_frag_strides = 0;
668 	u32 wqe_bulk_in_bytes;
669 	u16 split_factor;
670 	u32 wqe_bulk;
671 	int i;
672 
673 	for (i = 0; i < info->num_frags; i++)
674 		sum_frag_strides += info->arr[i].frag_stride;
675 
676 	/* For MTUs larger than PAGE_SIZE, align to PAGE_SIZE to reflect
677 	 * amount of consumed pages per wqe in bytes.
678 	 */
679 	if (sum_frag_strides > PAGE_SIZE)
680 		sum_frag_strides = ALIGN(sum_frag_strides, PAGE_SIZE);
681 
682 	bulk_bound_rq_size_in_bytes = bulk_bound_rq_size * sum_frag_strides;
683 
684 #define MAX_WQE_BULK_BYTES(xdp) ((xdp ? 256 : 512) * 1024)
685 
686 	/* A WQE bulk should not exceed min(512KB, 1/4 of rq size). For XDP
687 	 * keep bulk size smaller to avoid filling the page_pool cache on
688 	 * every bulk refill.
689 	 */
690 	wqe_bulk_in_bytes = min_t(u32, MAX_WQE_BULK_BYTES(params->xdp_prog),
691 				  bulk_bound_rq_size_in_bytes);
692 	wqe_bulk = DIV_ROUND_UP(wqe_bulk_in_bytes, sum_frag_strides);
693 
694 	/* Make sure that allocations don't start when the page is still used
695 	 * by older WQEs.
696 	 */
697 	info->wqe_bulk = max_t(u16, info->wqe_index_mask + 1, wqe_bulk);
698 
699 	split_factor = DIV_ROUND_UP(MAX_WQE_BULK_BYTES(params->xdp_prog),
700 				    PP_ALLOC_CACHE_REFILL * PAGE_SIZE);
701 	info->refill_unit = DIV_ROUND_UP(info->wqe_bulk, split_factor);
702 }
703 
704 #define DEFAULT_FRAG_SIZE (2048)
705 
mlx5e_build_rq_frags_info(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo,struct mlx5e_rq_frags_info * info,u32 * xdp_frag_size)706 static int mlx5e_build_rq_frags_info(struct mlx5_core_dev *mdev,
707 				     struct mlx5e_params *params,
708 				     struct mlx5e_rq_opt_param *rqo,
709 				     struct mlx5e_rq_frags_info *info,
710 				     u32 *xdp_frag_size)
711 {
712 	u32 byte_count = MLX5E_SW2HW_MTU(params, params->sw_mtu);
713 	int frag_size_max = DEFAULT_FRAG_SIZE;
714 	int first_frag_size_max;
715 	u32 buf_size = 0;
716 	u16 headroom;
717 	int max_mtu;
718 	int i;
719 
720 	if (mlx5e_rx_is_linear_skb(mdev, params, rqo)) {
721 		int frag_stride;
722 
723 		frag_stride = mlx5e_rx_get_linear_stride_sz(mdev, params, rqo,
724 							    false);
725 
726 		info->arr[0].frag_size = byte_count;
727 		info->arr[0].frag_stride = frag_stride;
728 		info->num_frags = 1;
729 
730 		/* N WQEs share the same page, N = PAGE_SIZE / frag_stride. The
731 		 * first WQE in the page is responsible for allocation of this
732 		 * page, this WQE's index is k*N. If WQEs [k*N+1; k*N+N-1] are
733 		 * still not completed, the allocation must stop before k*N.
734 		 */
735 		info->wqe_index_mask = (PAGE_SIZE / frag_stride) - 1;
736 
737 		goto out;
738 	}
739 
740 	headroom = mlx5e_get_linear_rq_headroom(params, rqo);
741 	first_frag_size_max = SKB_WITH_OVERHEAD(frag_size_max - headroom);
742 
743 	max_mtu = mlx5e_max_nonlinear_mtu(first_frag_size_max, frag_size_max,
744 					  params->xdp_prog);
745 	if (byte_count > max_mtu || params->xdp_prog) {
746 		frag_size_max = PAGE_SIZE;
747 		first_frag_size_max = SKB_WITH_OVERHEAD(frag_size_max - headroom);
748 
749 		max_mtu = mlx5e_max_nonlinear_mtu(first_frag_size_max, frag_size_max,
750 						  params->xdp_prog);
751 		if (byte_count > max_mtu) {
752 			mlx5_core_err(mdev, "MTU %u is too big for non-linear legacy RQ (max %d)\n",
753 				      params->sw_mtu, max_mtu);
754 			return -EINVAL;
755 		}
756 	}
757 
758 	i = 0;
759 	while (buf_size < byte_count) {
760 		int frag_size = byte_count - buf_size;
761 
762 		if (i == 0)
763 			frag_size = min(frag_size, first_frag_size_max);
764 		else if (i < MLX5E_MAX_RX_FRAGS - 1)
765 			frag_size = min(frag_size, frag_size_max);
766 
767 		info->arr[i].frag_size = frag_size;
768 		buf_size += frag_size;
769 
770 		if (params->xdp_prog) {
771 			/* XDP multi buffer expects fragments of the same size. */
772 			info->arr[i].frag_stride = frag_size_max;
773 		} else {
774 			if (i == 0) {
775 				/* Ensure that headroom and tailroom are included. */
776 				frag_size += headroom;
777 				frag_size += SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
778 			}
779 			info->arr[i].frag_stride = roundup_pow_of_two(frag_size);
780 		}
781 
782 		i++;
783 	}
784 	info->num_frags = i;
785 
786 	/* The last fragment of WQE with index 2*N may share the page with the
787 	 * first fragment of WQE with index 2*N+1 in certain cases. If WQE 2*N+1
788 	 * is not completed yet, WQE 2*N must not be allocated, as it's
789 	 * responsible for allocating a new page.
790 	 */
791 	if (frag_size_max == PAGE_SIZE) {
792 		/* No WQE can start in the middle of a page. */
793 		info->wqe_index_mask = 0;
794 	} else {
795 		/* PAGE_SIZEs starting from 8192 don't use 2K-sized fragments,
796 		 * because there would be more than MLX5E_MAX_RX_FRAGS of them.
797 		 */
798 		WARN_ON(PAGE_SIZE != 2 * DEFAULT_FRAG_SIZE);
799 
800 		/* Odd number of fragments allows to pack the last fragment of
801 		 * the previous WQE and the first fragment of the next WQE into
802 		 * the same page.
803 		 * As long as DEFAULT_FRAG_SIZE is 2048, and MLX5E_MAX_RX_FRAGS
804 		 * is 4, the last fragment can be bigger than the rest only if
805 		 * it's the fourth one, so WQEs consisting of 3 fragments will
806 		 * always share a page.
807 		 * When a page is shared, WQE bulk size is 2, otherwise just 1.
808 		 */
809 		info->wqe_index_mask = info->num_frags % 2;
810 	}
811 
812 out:
813 	/* Bulking optimization to skip allocation until a large enough number
814 	 * of WQEs can be allocated in a row. Bulking also influences how well
815 	 * deferred page release works.
816 	 */
817 	mlx5e_rx_compute_wqe_bulk_params(params, info);
818 
819 	mlx5_core_dbg(mdev, "%s: wqe_bulk = %u, wqe_bulk_refill_unit = %u\n",
820 		      __func__, info->wqe_bulk, info->refill_unit);
821 
822 	info->log_num_frags = order_base_2(info->num_frags);
823 
824 	*xdp_frag_size = info->num_frags > 1 && params->xdp_prog ? PAGE_SIZE : 0;
825 
826 	return 0;
827 }
828 
mlx5e_get_rqwq_log_stride(u8 wq_type,int ndsegs)829 static u8 mlx5e_get_rqwq_log_stride(u8 wq_type, int ndsegs)
830 {
831 	int sz = sizeof(struct mlx5_wqe_data_seg) * ndsegs;
832 
833 	switch (wq_type) {
834 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
835 		sz += sizeof(struct mlx5e_rx_wqe_ll);
836 		break;
837 	default: /* MLX5_WQ_TYPE_CYCLIC */
838 		sz += sizeof(struct mlx5e_rx_wqe_cyc);
839 	}
840 
841 	return order_base_2(sz);
842 }
843 
mlx5e_build_common_cq_param(struct mlx5_core_dev * mdev,struct mlx5e_cq_param * param)844 static void mlx5e_build_common_cq_param(struct mlx5_core_dev *mdev,
845 					struct mlx5e_cq_param *param)
846 {
847 	void *cqc = param->cqc;
848 
849 	MLX5_SET(cqc, cqc, uar_page, mdev->priv.bfreg.up->index);
850 	if (MLX5_CAP_GEN(mdev, cqe_128_always) && cache_line_size() >= 128)
851 		MLX5_SET(cqc, cqc, cqe_sz, CQE_STRIDE_128_PAD);
852 }
853 
mlx5e_shampo_get_log_cq_size(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)854 static u32 mlx5e_shampo_get_log_cq_size(struct mlx5_core_dev *mdev,
855 					struct mlx5e_params *params,
856 					struct mlx5e_rq_opt_param *rqo)
857 {
858 	u8 log_stride_sz = mlx5e_mpwqe_get_log_stride_size(mdev, params, rqo);
859 	u16 num_strides = BIT(mlx5e_mpwqe_get_log_num_strides(mdev, params,
860 							      rqo));
861 	int pkt_per_rsrv = BIT(mlx5e_shampo_get_log_pkt_per_rsrv(params));
862 	int wq_size = BIT(mlx5e_mpwqe_get_log_rq_size(mdev, params, rqo));
863 	int wqe_size = BIT(log_stride_sz) * num_strides;
864 	int rsrv_size = MLX5E_SHAMPO_WQ_RESRV_SIZE;
865 
866 	/* +1 is for the case that the pkt_per_rsrv dont consume the reservation
867 	 * so we get a filler cqe for the rest of the reservation.
868 	 */
869 	return order_base_2((wqe_size / rsrv_size) * wq_size * (pkt_per_rsrv + 1));
870 }
871 
mlx5e_build_rx_cq_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo,struct mlx5e_cq_param * param)872 static void mlx5e_build_rx_cq_param(struct mlx5_core_dev *mdev,
873 				    struct mlx5e_params *params,
874 				    struct mlx5e_rq_opt_param *rqo,
875 				    struct mlx5e_cq_param *param)
876 {
877 	bool hw_stridx = false;
878 	void *cqc = param->cqc;
879 	u8 log_cq_size;
880 
881 	switch (params->rq_wq_type) {
882 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
883 		hw_stridx = MLX5_CAP_GEN(mdev, mini_cqe_resp_stride_index);
884 		if (params->packet_merge.type == MLX5E_PACKET_MERGE_SHAMPO)
885 			log_cq_size =
886 				mlx5e_shampo_get_log_cq_size(mdev, params, rqo);
887 		else
888 			log_cq_size =
889 				mlx5e_mpwqe_get_log_rq_size(mdev, params, rqo) +
890 				mlx5e_mpwqe_get_log_num_strides(mdev, params,
891 								rqo);
892 		break;
893 	default: /* MLX5_WQ_TYPE_CYCLIC */
894 		log_cq_size = params->log_rq_mtu_frames;
895 	}
896 
897 	MLX5_SET(cqc, cqc, log_cq_size, log_cq_size);
898 	if (MLX5E_GET_PFLAG(params, MLX5E_PFLAG_RX_CQE_COMPRESS)) {
899 		MLX5_SET(cqc, cqc, mini_cqe_res_format, hw_stridx ?
900 			 MLX5_CQE_FORMAT_CSUM_STRIDX : MLX5_CQE_FORMAT_CSUM);
901 		MLX5_SET(cqc, cqc, cqe_compression_layout,
902 			 MLX5_CAP_GEN(mdev, enhanced_cqe_compression) ?
903 			 MLX5_CQE_COMPRESS_LAYOUT_ENHANCED :
904 			 MLX5_CQE_COMPRESS_LAYOUT_BASIC);
905 		MLX5_SET(cqc, cqc, cqe_comp_en, 1);
906 	}
907 
908 	mlx5e_build_common_cq_param(mdev, param);
909 	param->cq_period_mode = params->rx_cq_moderation.cq_period_mode;
910 }
911 
rq_end_pad_mode(struct mlx5_core_dev * mdev,struct mlx5e_params * params)912 static u8 rq_end_pad_mode(struct mlx5_core_dev *mdev, struct mlx5e_params *params)
913 {
914 	bool lro_en = params->packet_merge.type == MLX5E_PACKET_MERGE_LRO;
915 	bool ro = MLX5_CAP_GEN(mdev, relaxed_ordering_write);
916 
917 	return ro && lro_en ?
918 		MLX5_WQ_END_PAD_MODE_NONE : MLX5_WQ_END_PAD_MODE_ALIGN;
919 }
920 
mlx5e_mpwqe_build_rq_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo,struct mlx5e_rq_param * rq_param)921 static int mlx5e_mpwqe_build_rq_param(struct mlx5_core_dev *mdev,
922 				      struct mlx5e_params *params,
923 				      struct mlx5e_rq_opt_param *rqo,
924 				      struct mlx5e_rq_param *rq_param)
925 {
926 	u8 log_rq_sz = mlx5e_mpwqe_get_log_rq_size(mdev, params, rqo);
927 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
928 	u8 log_wqe_num_of_strides, log_wqe_stride_size;
929 	enum mlx5e_mpwrq_umr_mode umr_mode;
930 	void *rqc = rq_param->rqc;
931 	u32 lro_timeout;
932 	void *wq;
933 
934 	log_wqe_num_of_strides =
935 		mlx5e_mpwqe_get_log_num_strides(mdev, params, rqo);
936 	log_wqe_stride_size =
937 		mlx5e_mpwqe_get_log_stride_size(mdev, params, rqo);
938 	umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
939 
940 	wq = MLX5_ADDR_OF(rqc, rqc, wq);
941 	if (!mlx5e_verify_rx_mpwqe_strides(mdev, log_wqe_stride_size,
942 					   log_wqe_num_of_strides,
943 					   page_shift, umr_mode)) {
944 		mlx5_core_err(mdev,
945 			      "Bad RX MPWQE params: log_stride_size %u, log_num_strides %u, umr_mode %d\n",
946 			      log_wqe_stride_size, log_wqe_num_of_strides,
947 			      umr_mode);
948 		return -EINVAL;
949 	}
950 
951 	MLX5_SET(wq, wq, log_wqe_num_of_strides,
952 		 log_wqe_num_of_strides - MLX5_MPWQE_LOG_NUM_STRIDES_BASE);
953 	MLX5_SET(wq, wq, log_wqe_stride_size,
954 		 log_wqe_stride_size - MLX5_MPWQE_LOG_STRIDE_SZ_BASE);
955 	MLX5_SET(wq, wq, log_wq_sz, log_rq_sz);
956 	if (params->packet_merge.type != MLX5E_PACKET_MERGE_SHAMPO)
957 		return 0;
958 
959 	MLX5_SET(wq, wq, shampo_enable, true);
960 	MLX5_SET(wq, wq, log_reservation_size,
961 		 MLX5E_SHAMPO_WQ_LOG_RESRV_SIZE -
962 		 MLX5E_SHAMPO_WQ_RESRV_SIZE_BASE_SHIFT);
963 	MLX5_SET(wq, wq, log_max_num_of_packets_per_reservation,
964 		 mlx5e_shampo_get_log_pkt_per_rsrv(params));
965 	MLX5_SET(wq, wq, log_headers_entry_size,
966 		 MLX5E_SHAMPO_LOG_HEADER_ENTRY_SIZE -
967 		 MLX5E_SHAMPO_WQ_BASE_HEAD_ENTRY_SIZE_SHIFT);
968 	lro_timeout = mlx5e_choose_lro_timeout(mdev,
969 					       MLX5E_DEFAULT_SHAMPO_TIMEOUT);
970 	MLX5_SET(rqc, rqc, reservation_timeout, lro_timeout);
971 	MLX5_SET(rqc, rqc, shampo_match_criteria_type,
972 		 MLX5_RQC_SHAMPO_MATCH_CRITERIA_TYPE_EXTENDED);
973 	MLX5_SET(rqc, rqc, shampo_no_match_alignment_granularity,
974 		 MLX5_RQC_SHAMPO_NO_MATCH_ALIGNMENT_GRANULARITY_STRIDE);
975 
976 	return 0;
977 }
978 
mlx5e_build_rq_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo,struct mlx5e_rq_param * rq_param)979 int mlx5e_build_rq_param(struct mlx5_core_dev *mdev,
980 			 struct mlx5e_params *params,
981 			 struct mlx5e_rq_opt_param *rqo,
982 			 struct mlx5e_rq_param *rq_param)
983 {
984 	void *rqc = rq_param->rqc;
985 	int ndsegs = 1;
986 	void *wq;
987 	int err;
988 
989 	wq = MLX5_ADDR_OF(rqc, rqc, wq);
990 
991 	switch (params->rq_wq_type) {
992 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
993 		err = mlx5e_mpwqe_build_rq_param(mdev, params, rqo, rq_param);
994 		if (err)
995 			return err;
996 		break;
997 	default: /* MLX5_WQ_TYPE_CYCLIC */
998 		MLX5_SET(wq, wq, log_wq_sz, params->log_rq_mtu_frames);
999 		err = mlx5e_build_rq_frags_info(mdev, params, rqo,
1000 						&rq_param->frags_info,
1001 						&rq_param->xdp_frag_size);
1002 		if (err)
1003 			return err;
1004 		ndsegs = rq_param->frags_info.num_frags;
1005 	}
1006 
1007 	MLX5_SET(wq, wq, wq_type,          params->rq_wq_type);
1008 	MLX5_SET(wq, wq, end_padding_mode, rq_end_pad_mode(mdev, params));
1009 	MLX5_SET(wq, wq, log_wq_stride,
1010 		 mlx5e_get_rqwq_log_stride(params->rq_wq_type, ndsegs));
1011 	MLX5_SET(wq, wq, pd,               mdev->mlx5e_res.hw_objs.pdn);
1012 	MLX5_SET(rqc, rqc, vsd,            params->vlan_strip_disable);
1013 	MLX5_SET(rqc, rqc, scatter_fcs,    params->scatter_fcs_en);
1014 
1015 	rq_param->wq.buf_numa_node = dev_to_node(mlx5_core_dma_dev(mdev));
1016 	mlx5e_build_rx_cq_param(mdev, params, rqo, &rq_param->cqp);
1017 
1018 	return 0;
1019 }
1020 
mlx5e_build_drop_rq_param(struct mlx5_core_dev * mdev,struct mlx5e_rq_param * rq_param)1021 void mlx5e_build_drop_rq_param(struct mlx5_core_dev *mdev,
1022 			       struct mlx5e_rq_param *rq_param)
1023 {
1024 	void *rqc = rq_param->rqc;
1025 	void *wq = MLX5_ADDR_OF(rqc, rqc, wq);
1026 
1027 	MLX5_SET(wq, wq, wq_type, MLX5_WQ_TYPE_CYCLIC);
1028 	MLX5_SET(wq, wq, log_wq_stride,
1029 		 mlx5e_get_rqwq_log_stride(MLX5_WQ_TYPE_CYCLIC, 1));
1030 
1031 	rq_param->wq.buf_numa_node = dev_to_node(mlx5_core_dma_dev(mdev));
1032 }
1033 
mlx5e_build_tx_cq_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_cq_param * param)1034 void mlx5e_build_tx_cq_param(struct mlx5_core_dev *mdev,
1035 			     struct mlx5e_params *params,
1036 			     struct mlx5e_cq_param *param)
1037 {
1038 	void *cqc = param->cqc;
1039 
1040 	MLX5_SET(cqc, cqc, log_cq_size, params->log_sq_size);
1041 
1042 	mlx5e_build_common_cq_param(mdev, param);
1043 	param->cq_period_mode = params->tx_cq_moderation.cq_period_mode;
1044 }
1045 
mlx5e_build_sq_param_common(struct mlx5_core_dev * mdev,struct mlx5e_sq_param * param)1046 void mlx5e_build_sq_param_common(struct mlx5_core_dev *mdev,
1047 				 struct mlx5e_sq_param *param)
1048 {
1049 	void *sqc = param->sqc;
1050 	void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1051 
1052 	MLX5_SET(wq, wq, log_wq_stride, ilog2(MLX5_SEND_WQE_BB));
1053 	MLX5_SET(wq, wq, pd,            mdev->mlx5e_res.hw_objs.pdn);
1054 
1055 	param->wq.buf_numa_node = dev_to_node(mlx5_core_dma_dev(mdev));
1056 }
1057 
mlx5e_build_sq_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_sq_param * param)1058 void mlx5e_build_sq_param(struct mlx5_core_dev *mdev,
1059 			  struct mlx5e_params *params,
1060 			  struct mlx5e_sq_param *param)
1061 {
1062 	void *sqc = param->sqc;
1063 	void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1064 	bool allow_swp;
1065 
1066 	allow_swp = mlx5_geneve_tx_allowed(mdev) ||
1067 		    (mlx5_ipsec_device_caps(mdev) & MLX5_IPSEC_CAP_CRYPTO) ||
1068 		    mlx5_is_psp_device(mdev);
1069 	mlx5e_build_sq_param_common(mdev, param);
1070 	MLX5_SET(wq, wq, log_wq_sz, params->log_sq_size);
1071 	MLX5_SET(sqc, sqc, allow_swp, allow_swp);
1072 	param->is_mpw = MLX5E_GET_PFLAG(params, MLX5E_PFLAG_SKB_TX_MPWQE);
1073 	param->stop_room = mlx5e_calc_sq_stop_room(mdev, params);
1074 	mlx5e_build_tx_cq_param(mdev, params, &param->cqp);
1075 }
1076 
mlx5e_build_ico_cq_param(struct mlx5_core_dev * mdev,u8 log_wq_size,struct mlx5e_cq_param * param)1077 static void mlx5e_build_ico_cq_param(struct mlx5_core_dev *mdev,
1078 				     u8 log_wq_size,
1079 				     struct mlx5e_cq_param *param)
1080 {
1081 	void *cqc = param->cqc;
1082 
1083 	MLX5_SET(cqc, cqc, log_cq_size, log_wq_size);
1084 
1085 	mlx5e_build_common_cq_param(mdev, param);
1086 
1087 	param->cq_period_mode = DIM_CQ_PERIOD_MODE_START_FROM_EQE;
1088 }
1089 
1090 /* This function calculates the maximum number of headers entries that are needed
1091  * per WQE, the formula is based on the size of the reservations and the
1092  * restriction we have about max packets for reservation that is equal to max
1093  * headers per reservation.
1094  */
mlx5e_shampo_hd_per_wqe(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_param * rq_param)1095 u32 mlx5e_shampo_hd_per_wqe(struct mlx5_core_dev *mdev,
1096 			    struct mlx5e_params *params,
1097 			    struct mlx5e_rq_param *rq_param)
1098 {
1099 	u16 num_strides = BIT(mlx5e_mpwqe_get_log_num_strides(mdev, params, NULL));
1100 	u8 log_stride_sz = mlx5e_mpwqe_get_log_stride_size(mdev, params, NULL);
1101 	int pkt_per_rsrv = BIT(mlx5e_shampo_get_log_pkt_per_rsrv(params));
1102 	int wqe_size = BIT(log_stride_sz) * num_strides;
1103 	int rsrv_size = MLX5E_SHAMPO_WQ_RESRV_SIZE;
1104 	u32 hd_per_wqe;
1105 
1106 	/* Assumption: hd_per_wqe % 8 == 0. */
1107 	hd_per_wqe = (wqe_size / rsrv_size) * pkt_per_rsrv;
1108 	mlx5_core_dbg(mdev, "%s hd_per_wqe = %d rsrv_size = %d wqe_size = %d pkt_per_rsrv = %d\n",
1109 		      __func__, hd_per_wqe, rsrv_size, wqe_size, pkt_per_rsrv);
1110 	return hd_per_wqe;
1111 }
1112 
1113 /* This function calculates the maximum number of headers entries that are needed
1114  * for the WQ, this value is uesed to allocate the header buffer in HW, thus
1115  * must be a pow of 2.
1116  */
mlx5e_shampo_hd_per_wq(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_param * rq_param)1117 u32 mlx5e_shampo_hd_per_wq(struct mlx5_core_dev *mdev,
1118 			   struct mlx5e_params *params,
1119 			   struct mlx5e_rq_param *rq_param)
1120 {
1121 	void *wqc = MLX5_ADDR_OF(rqc, rq_param->rqc, wq);
1122 	int wq_size = BIT(MLX5_GET(wq, wqc, log_wq_sz));
1123 	u32 hd_per_wqe, hd_per_wq;
1124 
1125 	hd_per_wqe = mlx5e_shampo_hd_per_wqe(mdev, params, rq_param);
1126 	hd_per_wq = roundup_pow_of_two(hd_per_wqe * wq_size);
1127 	return hd_per_wq;
1128 }
1129 
1130 #define MLX5E_LRO_TIMEOUT_ARR_SIZE                      4
1131 
mlx5e_choose_lro_timeout(struct mlx5_core_dev * mdev,u32 wanted_timeout)1132 u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout)
1133 {
1134 	int i;
1135 
1136 	/* The supported periods are organized in ascending order */
1137 	for (i = 0; i < MLX5E_LRO_TIMEOUT_ARR_SIZE - 1; i++)
1138 		if (MLX5_CAP_ETH(mdev, lro_timer_supported_periods[i]) >= wanted_timeout)
1139 			break;
1140 
1141 	return MLX5_CAP_ETH(mdev, lro_timer_supported_periods[i]);
1142 }
1143 
mlx5e_mpwrq_total_umr_wqebbs(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_opt_param * rqo)1144 static u32 mlx5e_mpwrq_total_umr_wqebbs(struct mlx5_core_dev *mdev,
1145 					struct mlx5e_params *params,
1146 					struct mlx5e_rq_opt_param *rqo)
1147 {
1148 	enum mlx5e_mpwrq_umr_mode umr_mode = mlx5e_mpwrq_umr_mode(mdev, rqo);
1149 	u8 page_shift = mlx5e_mpwrq_page_shift(mdev, rqo);
1150 	u8 umr_wqebbs;
1151 
1152 	umr_wqebbs = mlx5e_mpwrq_umr_wqebbs(mdev, page_shift, umr_mode);
1153 
1154 	return umr_wqebbs *
1155 	       (1 << mlx5e_mpwqe_get_log_rq_size(mdev, params, rqo));
1156 }
1157 
mlx5e_max_xsk_wqebbs(struct mlx5_core_dev * mdev,struct mlx5e_params * params)1158 static u32 mlx5e_max_xsk_wqebbs(struct mlx5_core_dev *mdev,
1159 				struct mlx5e_params *params)
1160 {
1161 	struct mlx5e_rq_opt_param rqo = {0};
1162 	struct mlx5e_xsk_param xsk = {0};
1163 	u32 max_xsk_wqebbs = 0;
1164 	u8 frame_shift;
1165 
1166 	if (!params->xdp_prog)
1167 		return 0;
1168 
1169 	rqo.xsk = &xsk;
1170 
1171 	/* If XDP program is attached, XSK may be turned on at any time without
1172 	 * restarting the channel. ICOSQ must be big enough to fit UMR WQEs of
1173 	 * both regular RQ and XSK RQ.
1174 	 *
1175 	 * XSK uses different values of page_shift, and the total number of UMR
1176 	 * WQEBBs depends on it. This dependency is complex and not monotonic,
1177 	 * especially taking into consideration that some of the parameters come
1178 	 * from capabilities. Hence, we have to try all valid values of XSK
1179 	 * frame size (and page_shift) to find the maximum.
1180 	 */
1181 	for (frame_shift = XDP_UMEM_MIN_CHUNK_SHIFT;
1182 	     frame_shift <= PAGE_SHIFT; frame_shift++) {
1183 		u32 total_wqebbs;
1184 
1185 		/* The headroom doesn't affect the calculations below. */
1186 
1187 		/* XSK aligned mode. */
1188 		xsk.chunk_size = 1 << frame_shift;
1189 		xsk.unaligned = false;
1190 		total_wqebbs = mlx5e_mpwrq_total_umr_wqebbs(mdev, params, &rqo);
1191 		max_xsk_wqebbs = max(max_xsk_wqebbs, total_wqebbs);
1192 
1193 		/* XSK unaligned mode, frame size is a power of two. */
1194 		xsk.unaligned = true;
1195 		total_wqebbs = mlx5e_mpwrq_total_umr_wqebbs(mdev, params, &rqo);
1196 		max_xsk_wqebbs = max(max_xsk_wqebbs, total_wqebbs);
1197 
1198 		/* XSK unaligned mode, frame size is not equal to stride
1199 		 * size.
1200 		 */
1201 		xsk.chunk_size -= 1;
1202 		total_wqebbs = mlx5e_mpwrq_total_umr_wqebbs(mdev, params, &rqo);
1203 		max_xsk_wqebbs = max(max_xsk_wqebbs, total_wqebbs);
1204 
1205 		/* XSK unaligned mode, frame size is a triple power of two. */
1206 		xsk.chunk_size = (1 << frame_shift) / 4 * 3;
1207 		total_wqebbs = mlx5e_mpwrq_total_umr_wqebbs(mdev, params, &rqo);
1208 		max_xsk_wqebbs = max(max_xsk_wqebbs, total_wqebbs);
1209 	}
1210 
1211 	return max_xsk_wqebbs;
1212 }
1213 
mlx5e_build_icosq_log_wq_sz(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_rq_param * rq_param)1214 static u8 mlx5e_build_icosq_log_wq_sz(struct mlx5_core_dev *mdev,
1215 				      struct mlx5e_params *params,
1216 				      struct mlx5e_rq_param *rq_param)
1217 {
1218 	u32 wqebbs, total_pages, useful_space;
1219 
1220 	/* MLX5_WQ_TYPE_CYCLIC */
1221 	if (params->rq_wq_type != MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ)
1222 		return MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
1223 
1224 	/* UMR WQEs for the regular RQ. */
1225 	wqebbs = mlx5e_mpwrq_total_umr_wqebbs(mdev, params, NULL);
1226 
1227 	wqebbs += mlx5e_max_xsk_wqebbs(mdev, params);
1228 
1229 	/* UMR WQEs don't cross the page boundary, they are padded with NOPs.
1230 	 * This padding is always smaller than the max WQE size. That gives us
1231 	 * at least (PAGE_SIZE - (max WQE size - MLX5_SEND_WQE_BB)) useful bytes
1232 	 * per page. The number of pages is estimated as the total size of WQEs
1233 	 * divided by the useful space in page, rounding up. If some WQEs don't
1234 	 * fully fit into the useful space, they can occupy part of the padding,
1235 	 * which proves this estimation to be correct (reserve enough space).
1236 	 */
1237 	useful_space = PAGE_SIZE - mlx5e_get_max_sq_wqebbs(mdev) + MLX5_SEND_WQE_BB;
1238 	total_pages = DIV_ROUND_UP(wqebbs * MLX5_SEND_WQE_BB, useful_space);
1239 	wqebbs = total_pages * (PAGE_SIZE / MLX5_SEND_WQE_BB);
1240 
1241 	return max_t(u8, MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE, order_base_2(wqebbs));
1242 }
1243 
mlx5e_build_async_icosq_log_wq_sz(struct mlx5_core_dev * mdev)1244 static u8 mlx5e_build_async_icosq_log_wq_sz(struct mlx5_core_dev *mdev)
1245 {
1246 	if (mlx5e_is_ktls_rx(mdev))
1247 		return MLX5E_PARAMS_DEFAULT_LOG_SQ_SIZE;
1248 
1249 	return MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE;
1250 }
1251 
mlx5e_build_icosq_param(struct mlx5_core_dev * mdev,u8 log_wq_size,struct mlx5e_sq_param * param)1252 static void mlx5e_build_icosq_param(struct mlx5_core_dev *mdev,
1253 				    u8 log_wq_size,
1254 				    struct mlx5e_sq_param *param)
1255 {
1256 	void *sqc = param->sqc;
1257 	void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1258 
1259 	mlx5e_build_sq_param_common(mdev, param);
1260 
1261 	MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
1262 	MLX5_SET(sqc, sqc, reg_umr, MLX5_CAP_ETH(mdev, reg_umr_sq));
1263 	mlx5e_build_ico_cq_param(mdev, log_wq_size, &param->cqp);
1264 }
1265 
mlx5e_build_async_icosq_param(struct mlx5_core_dev * mdev,u8 log_wq_size,struct mlx5e_sq_param * param)1266 static void mlx5e_build_async_icosq_param(struct mlx5_core_dev *mdev,
1267 					  u8 log_wq_size,
1268 					  struct mlx5e_sq_param *param)
1269 {
1270 	void *sqc = param->sqc;
1271 	void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1272 
1273 	mlx5e_build_sq_param_common(mdev, param);
1274 	param->stop_room = mlx5e_stop_room_for_wqe(mdev, 1); /* for XSK NOP */
1275 	param->is_tls = mlx5e_is_ktls_rx(mdev);
1276 	if (param->is_tls)
1277 		param->stop_room += mlx5e_stop_room_for_wqe(mdev, 1); /* for TLS RX resync NOP */
1278 	MLX5_SET(sqc, sqc, reg_umr, MLX5_CAP_ETH(mdev, reg_umr_sq));
1279 	MLX5_SET(wq, wq, log_wq_sz, log_wq_size);
1280 	mlx5e_build_ico_cq_param(mdev, log_wq_size, &param->cqp);
1281 }
1282 
mlx5e_build_xdpsq_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_sq_param * param)1283 void mlx5e_build_xdpsq_param(struct mlx5_core_dev *mdev,
1284 			     struct mlx5e_params *params,
1285 			     struct mlx5e_sq_param *param)
1286 {
1287 	void *sqc = param->sqc;
1288 	void *wq = MLX5_ADDR_OF(sqc, sqc, wq);
1289 
1290 	mlx5e_build_sq_param_common(mdev, param);
1291 	MLX5_SET(wq, wq, log_wq_sz, params->log_sq_size);
1292 	param->is_mpw = MLX5E_GET_PFLAG(params, MLX5E_PFLAG_XDP_TX_MPWQE);
1293 	mlx5e_build_tx_cq_param(mdev, params, &param->cqp);
1294 }
1295 
mlx5e_build_channel_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct netdev_queue_config * qcfg,struct mlx5e_channel_param * cparam)1296 int mlx5e_build_channel_param(struct mlx5_core_dev *mdev,
1297 			      struct mlx5e_params *params,
1298 			      struct netdev_queue_config *qcfg,
1299 			      struct mlx5e_channel_param *cparam)
1300 {
1301 	u8 icosq_log_wq_sz, async_icosq_log_wq_sz;
1302 	int err;
1303 
1304 	cparam->rq_opt.qcfg = qcfg;
1305 
1306 	err = mlx5e_build_rq_param(mdev, params, &cparam->rq_opt, &cparam->rq);
1307 	if (err)
1308 		return err;
1309 
1310 	icosq_log_wq_sz = mlx5e_build_icosq_log_wq_sz(mdev, params, &cparam->rq);
1311 	async_icosq_log_wq_sz = mlx5e_build_async_icosq_log_wq_sz(mdev);
1312 
1313 	mlx5e_build_sq_param(mdev, params, &cparam->txq_sq);
1314 	mlx5e_build_xdpsq_param(mdev, params, &cparam->xdp_sq);
1315 	mlx5e_build_icosq_param(mdev, icosq_log_wq_sz, &cparam->icosq);
1316 	mlx5e_build_async_icosq_param(mdev, async_icosq_log_wq_sz, &cparam->async_icosq);
1317 
1318 	return 0;
1319 }
1320 
mlx5e_build_xsk_channel_param(struct mlx5_core_dev * mdev,struct mlx5e_params * params,struct mlx5e_xsk_param * xsk,struct mlx5e_channel_param * cparam)1321 void mlx5e_build_xsk_channel_param(struct mlx5_core_dev *mdev,
1322 				   struct mlx5e_params *params,
1323 				   struct mlx5e_xsk_param *xsk,
1324 				   struct mlx5e_channel_param *cparam)
1325 {
1326 	cparam->rq_opt.xsk = xsk;
1327 	mlx5e_build_rq_param(mdev, params, &cparam->rq_opt, &cparam->rq);
1328 	mlx5e_build_xdpsq_param(mdev, params, &cparam->xdp_sq);
1329 }
1330