• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */
2 /* Copyright (c) 2019 Mellanox Technologies. */
3 
4 #ifndef __MLX5_EN_TXRX_H___
5 #define __MLX5_EN_TXRX_H___
6 
7 #include "en.h"
8 #include <linux/indirect_call_wrapper.h>
9 
10 #define MLX5E_TX_WQE_EMPTY_DS_COUNT (sizeof(struct mlx5e_tx_wqe) / MLX5_SEND_WQE_DS)
11 
12 #define INL_HDR_START_SZ (sizeof(((struct mlx5_wqe_eth_seg *)NULL)->inline_hdr.start))
13 
14 /* IPSEC inline data includes:
15  * 1. ESP trailer: up to 255 bytes of padding, 1 byte for pad length, 1 byte for
16  *    next header.
17  * 2. ESP authentication data: 16 bytes for ICV.
18  */
19 #define MLX5E_MAX_TX_IPSEC_DS DIV_ROUND_UP(sizeof(struct mlx5_wqe_inline_seg) + \
20 					   255 + 1 + 1 + 16, MLX5_SEND_WQE_DS)
21 
22 /* 366 should be big enough to cover all L2, L3 and L4 headers with possible
23  * encapsulations.
24  */
25 #define MLX5E_MAX_TX_INLINE_DS DIV_ROUND_UP(366 - INL_HDR_START_SZ + VLAN_HLEN, \
26 					    MLX5_SEND_WQE_DS)
27 
28 /* Sync the calculation with mlx5e_sq_calc_wqe_attr. */
29 #define MLX5E_MAX_TX_WQEBBS DIV_ROUND_UP(MLX5E_TX_WQE_EMPTY_DS_COUNT + \
30 					 MLX5E_MAX_TX_INLINE_DS + \
31 					 MLX5E_MAX_TX_IPSEC_DS + \
32 					 MAX_SKB_FRAGS + 1, \
33 					 MLX5_SEND_WQEBB_NUM_DS)
34 
35 #define MLX5E_RX_ERR_CQE(cqe) (get_cqe_opcode(cqe) != MLX5_CQE_RESP_SEND)
36 
37 static inline
mlx5e_cqe_ts_to_ns(cqe_ts_to_ns func,struct mlx5_clock * clock,u64 cqe_ts)38 ktime_t mlx5e_cqe_ts_to_ns(cqe_ts_to_ns func, struct mlx5_clock *clock, u64 cqe_ts)
39 {
40 	return INDIRECT_CALL_2(func, mlx5_real_time_cyc2time, mlx5_timecounter_cyc2time,
41 			       clock, cqe_ts);
42 }
43 
44 enum mlx5e_icosq_wqe_type {
45 	MLX5E_ICOSQ_WQE_NOP,
46 	MLX5E_ICOSQ_WQE_UMR_RX,
47 	MLX5E_ICOSQ_WQE_SHAMPO_HD_UMR,
48 #ifdef CONFIG_MLX5_EN_TLS
49 	MLX5E_ICOSQ_WQE_UMR_TLS,
50 	MLX5E_ICOSQ_WQE_SET_PSV_TLS,
51 	MLX5E_ICOSQ_WQE_GET_PSV_TLS,
52 #endif
53 };
54 
55 /* General */
mlx5e_skb_is_multicast(struct sk_buff * skb)56 static inline bool mlx5e_skb_is_multicast(struct sk_buff *skb)
57 {
58 	return skb->pkt_type == PACKET_MULTICAST || skb->pkt_type == PACKET_BROADCAST;
59 }
60 
61 void mlx5e_trigger_irq(struct mlx5e_icosq *sq);
62 void mlx5e_completion_event(struct mlx5_core_cq *mcq, struct mlx5_eqe *eqe);
63 void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event);
64 int mlx5e_napi_poll(struct napi_struct *napi, int budget);
65 int mlx5e_poll_ico_cq(struct mlx5e_cq *cq);
66 
67 /* RX */
68 void mlx5e_page_dma_unmap(struct mlx5e_rq *rq, struct page *page);
69 void mlx5e_page_release_dynamic(struct mlx5e_rq *rq, struct page *page, bool recycle);
70 INDIRECT_CALLABLE_DECLARE(bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq));
71 INDIRECT_CALLABLE_DECLARE(bool mlx5e_post_rx_mpwqes(struct mlx5e_rq *rq));
72 int mlx5e_poll_rx_cq(struct mlx5e_cq *cq, int budget);
73 void mlx5e_free_rx_descs(struct mlx5e_rq *rq);
74 void mlx5e_free_rx_in_progress_descs(struct mlx5e_rq *rq);
75 
76 /* TX */
77 netdev_tx_t mlx5e_xmit(struct sk_buff *skb, struct net_device *dev);
78 bool mlx5e_poll_tx_cq(struct mlx5e_cq *cq, int napi_budget);
79 void mlx5e_free_txqsq_descs(struct mlx5e_txqsq *sq);
80 
81 static inline bool
mlx5e_skb_fifo_has_room(struct mlx5e_skb_fifo * fifo)82 mlx5e_skb_fifo_has_room(struct mlx5e_skb_fifo *fifo)
83 {
84 	return (u16)(*fifo->pc - *fifo->cc) < fifo->mask;
85 }
86 
87 static inline bool
mlx5e_wqc_has_room_for(struct mlx5_wq_cyc * wq,u16 cc,u16 pc,u16 n)88 mlx5e_wqc_has_room_for(struct mlx5_wq_cyc *wq, u16 cc, u16 pc, u16 n)
89 {
90 	return (mlx5_wq_cyc_ctr2ix(wq, cc - pc) >= n) || (cc == pc);
91 }
92 
mlx5e_fetch_wqe(struct mlx5_wq_cyc * wq,u16 pi,size_t wqe_size)93 static inline void *mlx5e_fetch_wqe(struct mlx5_wq_cyc *wq, u16 pi, size_t wqe_size)
94 {
95 	void *wqe;
96 
97 	wqe = mlx5_wq_cyc_get_wqe(wq, pi);
98 	memset(wqe, 0, wqe_size);
99 
100 	return wqe;
101 }
102 
103 #define MLX5E_TX_FETCH_WQE(sq, pi) \
104 	((struct mlx5e_tx_wqe *)mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_tx_wqe)))
105 
106 static inline struct mlx5e_tx_wqe *
mlx5e_post_nop(struct mlx5_wq_cyc * wq,u32 sqn,u16 * pc)107 mlx5e_post_nop(struct mlx5_wq_cyc *wq, u32 sqn, u16 *pc)
108 {
109 	u16                         pi   = mlx5_wq_cyc_ctr2ix(wq, *pc);
110 	struct mlx5e_tx_wqe        *wqe  = mlx5_wq_cyc_get_wqe(wq, pi);
111 	struct mlx5_wqe_ctrl_seg   *cseg = &wqe->ctrl;
112 
113 	memset(cseg, 0, sizeof(*cseg));
114 
115 	cseg->opmod_idx_opcode = cpu_to_be32((*pc << 8) | MLX5_OPCODE_NOP);
116 	cseg->qpn_ds           = cpu_to_be32((sqn << 8) | 0x01);
117 
118 	(*pc)++;
119 
120 	return wqe;
121 }
122 
123 static inline struct mlx5e_tx_wqe *
mlx5e_post_nop_fence(struct mlx5_wq_cyc * wq,u32 sqn,u16 * pc)124 mlx5e_post_nop_fence(struct mlx5_wq_cyc *wq, u32 sqn, u16 *pc)
125 {
126 	u16                         pi   = mlx5_wq_cyc_ctr2ix(wq, *pc);
127 	struct mlx5e_tx_wqe        *wqe  = mlx5_wq_cyc_get_wqe(wq, pi);
128 	struct mlx5_wqe_ctrl_seg   *cseg = &wqe->ctrl;
129 
130 	memset(cseg, 0, sizeof(*cseg));
131 
132 	cseg->opmod_idx_opcode = cpu_to_be32((*pc << 8) | MLX5_OPCODE_NOP);
133 	cseg->qpn_ds           = cpu_to_be32((sqn << 8) | 0x01);
134 	cseg->fm_ce_se         = MLX5_FENCE_MODE_INITIATOR_SMALL;
135 
136 	(*pc)++;
137 
138 	return wqe;
139 }
140 
141 struct mlx5e_tx_wqe_info {
142 	struct sk_buff *skb;
143 	u32 num_bytes;
144 	u8 num_wqebbs;
145 	u8 num_dma;
146 	u8 num_fifo_pkts;
147 #ifdef CONFIG_MLX5_EN_TLS
148 	struct page *resync_dump_frag_page;
149 #endif
150 };
151 
mlx5e_txqsq_get_next_pi(struct mlx5e_txqsq * sq,u16 size)152 static inline u16 mlx5e_txqsq_get_next_pi(struct mlx5e_txqsq *sq, u16 size)
153 {
154 	struct mlx5_wq_cyc *wq = &sq->wq;
155 	u16 pi, contig_wqebbs;
156 
157 	pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
158 	contig_wqebbs = mlx5_wq_cyc_get_contig_wqebbs(wq, pi);
159 	if (unlikely(contig_wqebbs < size)) {
160 		struct mlx5e_tx_wqe_info *wi, *edge_wi;
161 
162 		wi = &sq->db.wqe_info[pi];
163 		edge_wi = wi + contig_wqebbs;
164 
165 		/* Fill SQ frag edge with NOPs to avoid WQE wrapping two pages. */
166 		for (; wi < edge_wi; wi++) {
167 			*wi = (struct mlx5e_tx_wqe_info) {
168 				.num_wqebbs = 1,
169 			};
170 			mlx5e_post_nop(wq, sq->sqn, &sq->pc);
171 		}
172 		sq->stats->nop += contig_wqebbs;
173 
174 		pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
175 	}
176 
177 	return pi;
178 }
179 
180 void mlx5e_txqsq_wake(struct mlx5e_txqsq *sq);
181 
mlx5e_shampo_get_cqe_header_index(struct mlx5e_rq * rq,struct mlx5_cqe64 * cqe)182 static inline u16 mlx5e_shampo_get_cqe_header_index(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe)
183 {
184 	return be16_to_cpu(cqe->shampo.header_entry_index) & (rq->mpwqe.shampo->hd_per_wq - 1);
185 }
186 
187 struct mlx5e_shampo_umr {
188 	u16 len;
189 };
190 
191 struct mlx5e_icosq_wqe_info {
192 	u8 wqe_type;
193 	u8 num_wqebbs;
194 
195 	/* Auxiliary data for different wqe types. */
196 	union {
197 		struct {
198 			struct mlx5e_rq *rq;
199 		} umr;
200 		struct mlx5e_shampo_umr shampo;
201 #ifdef CONFIG_MLX5_EN_TLS
202 		struct {
203 			struct mlx5e_ktls_offload_context_rx *priv_rx;
204 		} tls_set_params;
205 		struct {
206 			struct mlx5e_ktls_rx_resync_buf *buf;
207 		} tls_get_params;
208 #endif
209 	};
210 };
211 
212 void mlx5e_free_icosq_descs(struct mlx5e_icosq *sq);
213 
mlx5e_icosq_get_next_pi(struct mlx5e_icosq * sq,u16 size)214 static inline u16 mlx5e_icosq_get_next_pi(struct mlx5e_icosq *sq, u16 size)
215 {
216 	struct mlx5_wq_cyc *wq = &sq->wq;
217 	u16 pi, contig_wqebbs;
218 
219 	pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
220 	contig_wqebbs = mlx5_wq_cyc_get_contig_wqebbs(wq, pi);
221 	if (unlikely(contig_wqebbs < size)) {
222 		struct mlx5e_icosq_wqe_info *wi, *edge_wi;
223 
224 		wi = &sq->db.wqe_info[pi];
225 		edge_wi = wi + contig_wqebbs;
226 
227 		/* Fill SQ frag edge with NOPs to avoid WQE wrapping two pages. */
228 		for (; wi < edge_wi; wi++) {
229 			*wi = (struct mlx5e_icosq_wqe_info) {
230 				.wqe_type   = MLX5E_ICOSQ_WQE_NOP,
231 				.num_wqebbs = 1,
232 			};
233 			mlx5e_post_nop(wq, sq->sqn, &sq->pc);
234 		}
235 
236 		pi = mlx5_wq_cyc_ctr2ix(wq, sq->pc);
237 	}
238 
239 	return pi;
240 }
241 
242 static inline void
mlx5e_notify_hw(struct mlx5_wq_cyc * wq,u16 pc,void __iomem * uar_map,struct mlx5_wqe_ctrl_seg * ctrl)243 mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc, void __iomem *uar_map,
244 		struct mlx5_wqe_ctrl_seg *ctrl)
245 {
246 	ctrl->fm_ce_se |= MLX5_WQE_CTRL_CQ_UPDATE;
247 	/* ensure wqe is visible to device before updating doorbell record */
248 	dma_wmb();
249 
250 	*wq->db = cpu_to_be32(pc);
251 
252 	/* ensure doorbell record is visible to device before ringing the
253 	 * doorbell
254 	 */
255 	wmb();
256 
257 	mlx5_write64((__be32 *)ctrl, uar_map);
258 }
259 
mlx5e_cq_arm(struct mlx5e_cq * cq)260 static inline void mlx5e_cq_arm(struct mlx5e_cq *cq)
261 {
262 	struct mlx5_core_cq *mcq;
263 
264 	mcq = &cq->mcq;
265 	mlx5_cq_arm(mcq, MLX5_CQ_DB_REQ_NOT, mcq->uar->map, cq->wq.cc);
266 }
267 
268 static inline struct mlx5e_sq_dma *
mlx5e_dma_get(struct mlx5e_txqsq * sq,u32 i)269 mlx5e_dma_get(struct mlx5e_txqsq *sq, u32 i)
270 {
271 	return &sq->db.dma_fifo[i & sq->dma_fifo_mask];
272 }
273 
274 static inline void
mlx5e_dma_push(struct mlx5e_txqsq * sq,dma_addr_t addr,u32 size,enum mlx5e_dma_map_type map_type)275 mlx5e_dma_push(struct mlx5e_txqsq *sq, dma_addr_t addr, u32 size,
276 	       enum mlx5e_dma_map_type map_type)
277 {
278 	struct mlx5e_sq_dma *dma = mlx5e_dma_get(sq, sq->dma_fifo_pc++);
279 
280 	dma->addr = addr;
281 	dma->size = size;
282 	dma->type = map_type;
283 }
284 
285 static inline
mlx5e_skb_fifo_get(struct mlx5e_skb_fifo * fifo,u16 i)286 struct sk_buff **mlx5e_skb_fifo_get(struct mlx5e_skb_fifo *fifo, u16 i)
287 {
288 	return &fifo->fifo[i & fifo->mask];
289 }
290 
291 static inline
mlx5e_skb_fifo_push(struct mlx5e_skb_fifo * fifo,struct sk_buff * skb)292 void mlx5e_skb_fifo_push(struct mlx5e_skb_fifo *fifo, struct sk_buff *skb)
293 {
294 	struct sk_buff **skb_item = mlx5e_skb_fifo_get(fifo, (*fifo->pc)++);
295 
296 	*skb_item = skb;
297 }
298 
299 static inline
mlx5e_skb_fifo_pop(struct mlx5e_skb_fifo * fifo)300 struct sk_buff *mlx5e_skb_fifo_pop(struct mlx5e_skb_fifo *fifo)
301 {
302 	WARN_ON_ONCE(*fifo->pc == *fifo->cc);
303 
304 	return *mlx5e_skb_fifo_get(fifo, (*fifo->cc)++);
305 }
306 
307 static inline void
mlx5e_tx_dma_unmap(struct device * pdev,struct mlx5e_sq_dma * dma)308 mlx5e_tx_dma_unmap(struct device *pdev, struct mlx5e_sq_dma *dma)
309 {
310 	switch (dma->type) {
311 	case MLX5E_DMA_MAP_SINGLE:
312 		dma_unmap_single(pdev, dma->addr, dma->size, DMA_TO_DEVICE);
313 		break;
314 	case MLX5E_DMA_MAP_PAGE:
315 		dma_unmap_page(pdev, dma->addr, dma->size, DMA_TO_DEVICE);
316 		break;
317 	default:
318 		WARN_ONCE(true, "mlx5e_tx_dma_unmap unknown DMA type!\n");
319 	}
320 }
321 
322 void mlx5e_sq_xmit_simple(struct mlx5e_txqsq *sq, struct sk_buff *skb, bool xmit_more);
323 void mlx5e_tx_mpwqe_ensure_complete(struct mlx5e_txqsq *sq);
324 
mlx5e_tx_mpwqe_is_full(struct mlx5e_tx_mpwqe * session,u8 max_sq_mpw_wqebbs)325 static inline bool mlx5e_tx_mpwqe_is_full(struct mlx5e_tx_mpwqe *session, u8 max_sq_mpw_wqebbs)
326 {
327 	return session->ds_count == max_sq_mpw_wqebbs * MLX5_SEND_WQEBB_NUM_DS;
328 }
329 
mlx5e_rqwq_reset(struct mlx5e_rq * rq)330 static inline void mlx5e_rqwq_reset(struct mlx5e_rq *rq)
331 {
332 	if (rq->wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ) {
333 		mlx5_wq_ll_reset(&rq->mpwqe.wq);
334 		rq->mpwqe.actual_wq_head = 0;
335 	} else {
336 		mlx5_wq_cyc_reset(&rq->wqe.wq);
337 	}
338 }
339 
mlx5e_dump_error_cqe(struct mlx5e_cq * cq,u32 qn,struct mlx5_err_cqe * err_cqe)340 static inline void mlx5e_dump_error_cqe(struct mlx5e_cq *cq, u32 qn,
341 					struct mlx5_err_cqe *err_cqe)
342 {
343 	struct mlx5_cqwq *wq = &cq->wq;
344 	u32 ci;
345 
346 	ci = mlx5_cqwq_ctr2ix(wq, wq->cc - 1);
347 
348 	netdev_err(cq->netdev,
349 		   "Error cqe on cqn 0x%x, ci 0x%x, qn 0x%x, opcode 0x%x, syndrome 0x%x, vendor syndrome 0x%x\n",
350 		   cq->mcq.cqn, ci, qn,
351 		   get_cqe_opcode((struct mlx5_cqe64 *)err_cqe),
352 		   err_cqe->syndrome, err_cqe->vendor_err_synd);
353 	mlx5_dump_err_cqe(cq->mdev, err_cqe);
354 }
355 
mlx5e_rqwq_get_size(struct mlx5e_rq * rq)356 static inline u32 mlx5e_rqwq_get_size(struct mlx5e_rq *rq)
357 {
358 	switch (rq->wq_type) {
359 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
360 		return mlx5_wq_ll_get_size(&rq->mpwqe.wq);
361 	default:
362 		return mlx5_wq_cyc_get_size(&rq->wqe.wq);
363 	}
364 }
365 
mlx5e_rqwq_get_cur_sz(struct mlx5e_rq * rq)366 static inline u32 mlx5e_rqwq_get_cur_sz(struct mlx5e_rq *rq)
367 {
368 	switch (rq->wq_type) {
369 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
370 		return rq->mpwqe.wq.cur_sz;
371 	default:
372 		return rq->wqe.wq.cur_sz;
373 	}
374 }
375 
mlx5e_rqwq_get_head(struct mlx5e_rq * rq)376 static inline u16 mlx5e_rqwq_get_head(struct mlx5e_rq *rq)
377 {
378 	switch (rq->wq_type) {
379 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
380 		return mlx5_wq_ll_get_head(&rq->mpwqe.wq);
381 	default:
382 		return mlx5_wq_cyc_get_head(&rq->wqe.wq);
383 	}
384 }
385 
mlx5e_rqwq_get_wqe_counter(struct mlx5e_rq * rq)386 static inline u16 mlx5e_rqwq_get_wqe_counter(struct mlx5e_rq *rq)
387 {
388 	switch (rq->wq_type) {
389 	case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ:
390 		return mlx5_wq_ll_get_counter(&rq->mpwqe.wq);
391 	default:
392 		return mlx5_wq_cyc_get_counter(&rq->wqe.wq);
393 	}
394 }
395 
396 /* SW parser related functions */
397 
398 struct mlx5e_swp_spec {
399 	__be16 l3_proto;
400 	u8 l4_proto;
401 	u8 is_tun;
402 	__be16 tun_l3_proto;
403 	u8 tun_l4_proto;
404 };
405 
mlx5e_eseg_swp_offsets_add_vlan(struct mlx5_wqe_eth_seg * eseg)406 static inline void mlx5e_eseg_swp_offsets_add_vlan(struct mlx5_wqe_eth_seg *eseg)
407 {
408 	/* SWP offsets are in 2-bytes words */
409 	eseg->swp_outer_l3_offset += VLAN_HLEN / 2;
410 	eseg->swp_outer_l4_offset += VLAN_HLEN / 2;
411 	eseg->swp_inner_l3_offset += VLAN_HLEN / 2;
412 	eseg->swp_inner_l4_offset += VLAN_HLEN / 2;
413 }
414 
415 static inline void
mlx5e_set_eseg_swp(struct sk_buff * skb,struct mlx5_wqe_eth_seg * eseg,struct mlx5e_swp_spec * swp_spec)416 mlx5e_set_eseg_swp(struct sk_buff *skb, struct mlx5_wqe_eth_seg *eseg,
417 		   struct mlx5e_swp_spec *swp_spec)
418 {
419 	/* SWP offsets are in 2-bytes words */
420 	eseg->swp_outer_l3_offset = skb_network_offset(skb) / 2;
421 	if (swp_spec->l3_proto == htons(ETH_P_IPV6))
422 		eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L3_IPV6;
423 	if (swp_spec->l4_proto) {
424 		eseg->swp_outer_l4_offset = skb_transport_offset(skb) / 2;
425 		if (swp_spec->l4_proto == IPPROTO_UDP)
426 			eseg->swp_flags |= MLX5_ETH_WQE_SWP_OUTER_L4_UDP;
427 	}
428 
429 	if (swp_spec->is_tun) {
430 		eseg->swp_inner_l3_offset = skb_inner_network_offset(skb) / 2;
431 		if (swp_spec->tun_l3_proto == htons(ETH_P_IPV6))
432 			eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
433 	} else { /* typically for ipsec when xfrm mode != XFRM_MODE_TUNNEL */
434 		eseg->swp_inner_l3_offset = skb_network_offset(skb) / 2;
435 		if (swp_spec->l3_proto == htons(ETH_P_IPV6))
436 			eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L3_IPV6;
437 	}
438 	switch (swp_spec->tun_l4_proto) {
439 	case IPPROTO_UDP:
440 		eseg->swp_flags |= MLX5_ETH_WQE_SWP_INNER_L4_UDP;
441 		fallthrough;
442 	case IPPROTO_TCP:
443 		eseg->swp_inner_l4_offset = skb_inner_transport_offset(skb) / 2;
444 		break;
445 	}
446 }
447 
448 #define MLX5E_STOP_ROOM(wqebbs) ((wqebbs) * 2 - 1)
449 
mlx5e_stop_room_for_wqe(struct mlx5_core_dev * mdev,u16 wqe_size)450 static inline u16 mlx5e_stop_room_for_wqe(struct mlx5_core_dev *mdev, u16 wqe_size)
451 {
452 	WARN_ON_ONCE(PAGE_SIZE / MLX5_SEND_WQE_BB < mlx5e_get_max_sq_wqebbs(mdev));
453 
454 	/* A WQE must not cross the page boundary, hence two conditions:
455 	 * 1. Its size must not exceed the page size.
456 	 * 2. If the WQE size is X, and the space remaining in a page is less
457 	 *    than X, this space needs to be padded with NOPs. So, one WQE of
458 	 *    size X may require up to X-1 WQEBBs of padding, which makes the
459 	 *    stop room of X-1 + X.
460 	 * WQE size is also limited by the hardware limit.
461 	 */
462 	WARN_ONCE(wqe_size > mlx5e_get_max_sq_wqebbs(mdev),
463 		  "wqe_size %u is greater than max SQ WQEBBs %u",
464 		  wqe_size, mlx5e_get_max_sq_wqebbs(mdev));
465 
466 	return MLX5E_STOP_ROOM(wqe_size);
467 }
468 
mlx5e_stop_room_for_max_wqe(struct mlx5_core_dev * mdev)469 static inline u16 mlx5e_stop_room_for_max_wqe(struct mlx5_core_dev *mdev)
470 {
471 	return MLX5E_STOP_ROOM(mlx5e_get_max_sq_wqebbs(mdev));
472 }
473 
mlx5e_stop_room_for_mpwqe(struct mlx5_core_dev * mdev)474 static inline u16 mlx5e_stop_room_for_mpwqe(struct mlx5_core_dev *mdev)
475 {
476 	u8 mpwqe_wqebbs = mlx5e_get_max_sq_aligned_wqebbs(mdev);
477 
478 	return mlx5e_stop_room_for_wqe(mdev, mpwqe_wqebbs);
479 }
480 
mlx5e_icosq_can_post_wqe(struct mlx5e_icosq * sq,u16 wqe_size)481 static inline bool mlx5e_icosq_can_post_wqe(struct mlx5e_icosq *sq, u16 wqe_size)
482 {
483 	u16 room = sq->reserved_room + MLX5E_STOP_ROOM(wqe_size);
484 
485 	return mlx5e_wqc_has_room_for(&sq->wq, sq->cc, sq->pc, room);
486 }
487 
mlx5e_get_mpw_info(struct mlx5e_rq * rq,int i)488 static inline struct mlx5e_mpw_info *mlx5e_get_mpw_info(struct mlx5e_rq *rq, int i)
489 {
490 	size_t isz = struct_size(rq->mpwqe.info, alloc_units, rq->mpwqe.pages_per_wqe);
491 
492 	return (struct mlx5e_mpw_info *)((char *)rq->mpwqe.info + array_size(i, isz));
493 }
494 #endif
495