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