Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright 2021 6WIND S.A.
3 : : * Copyright 2021 Mellanox Technologies, Ltd
4 : : */
5 : :
6 : : #ifndef RTE_PMD_MLX5_TX_H_
7 : : #define RTE_PMD_MLX5_TX_H_
8 : :
9 : : #include <stdint.h>
10 : : #include <sys/queue.h>
11 : :
12 : : #include <rte_mbuf.h>
13 : : #include <rte_mempool.h>
14 : : #include <rte_common.h>
15 : : #include <rte_spinlock.h>
16 : : #include <rte_trace_point.h>
17 : :
18 : : #include <mlx5_common.h>
19 : : #include <mlx5_common_mr.h>
20 : :
21 : : #include "mlx5.h"
22 : : #include "mlx5_autoconf.h"
23 : : #include "mlx5_rxtx.h"
24 : : #include "mlx5_trace.h"
25 : :
26 : : /* TX burst subroutines return codes. */
27 : : enum mlx5_txcmp_code {
28 : : MLX5_TXCMP_CODE_EXIT = 0,
29 : : MLX5_TXCMP_CODE_ERROR,
30 : : MLX5_TXCMP_CODE_SINGLE,
31 : : MLX5_TXCMP_CODE_MULTI,
32 : : MLX5_TXCMP_CODE_TSO,
33 : : MLX5_TXCMP_CODE_EMPW,
34 : : };
35 : :
36 : : /*
37 : : * These defines are used to configure Tx burst routine option set supported
38 : : * at compile time. The not specified options are optimized out due to if
39 : : * conditions can be explicitly calculated at compile time.
40 : : * The offloads with bigger runtime check (require more CPU cycles toskip)
41 : : * overhead should have the bigger index - this is needed to select the better
42 : : * matching routine function if no exact match and some offloads are not
43 : : * actually requested.
44 : : */
45 : : #define MLX5_TXOFF_CONFIG_MULTI (1u << 0) /* Multi-segment packets.*/
46 : : #define MLX5_TXOFF_CONFIG_TSO (1u << 1) /* TCP send offload supported.*/
47 : : #define MLX5_TXOFF_CONFIG_SWP (1u << 2) /* Tunnels/SW Parser offloads.*/
48 : : #define MLX5_TXOFF_CONFIG_CSUM (1u << 3) /* Check Sums offloaded. */
49 : : #define MLX5_TXOFF_CONFIG_INLINE (1u << 4) /* Data inlining supported. */
50 : : #define MLX5_TXOFF_CONFIG_VLAN (1u << 5) /* VLAN insertion supported.*/
51 : : #define MLX5_TXOFF_CONFIG_METADATA (1u << 6) /* Flow metadata. */
52 : : #define MLX5_TXOFF_CONFIG_EMPW (1u << 8) /* Enhanced MPW supported.*/
53 : : #define MLX5_TXOFF_CONFIG_MPW (1u << 9) /* Legacy MPW supported.*/
54 : : #define MLX5_TXOFF_CONFIG_TXPP (1u << 10) /* Scheduling on timestamp.*/
55 : :
56 : : /* The most common offloads groups. */
57 : : #define MLX5_TXOFF_CONFIG_NONE 0
58 : : #define MLX5_TXOFF_CONFIG_FULL (MLX5_TXOFF_CONFIG_MULTI | \
59 : : MLX5_TXOFF_CONFIG_TSO | \
60 : : MLX5_TXOFF_CONFIG_SWP | \
61 : : MLX5_TXOFF_CONFIG_CSUM | \
62 : : MLX5_TXOFF_CONFIG_INLINE | \
63 : : MLX5_TXOFF_CONFIG_VLAN | \
64 : : MLX5_TXOFF_CONFIG_METADATA)
65 : :
66 : : #define MLX5_TXOFF_CONFIG(mask) (olx & MLX5_TXOFF_CONFIG_##mask)
67 : :
68 : : #define MLX5_TXOFF_PRE_DECL(func) \
69 : : uint16_t mlx5_tx_burst_##func(void *txq, \
70 : : struct rte_mbuf **pkts, \
71 : : uint16_t pkts_n)
72 : :
73 : : #define MLX5_TXOFF_DECL(func, olx) \
74 : : uint16_t mlx5_tx_burst_##func(void *txq, \
75 : : struct rte_mbuf **pkts, \
76 : : uint16_t pkts_n) \
77 : : { \
78 : : return mlx5_tx_burst_tmpl((struct mlx5_txq_data *)txq, \
79 : : pkts, pkts_n, (olx)); \
80 : : }
81 : :
82 : : /* Mbuf dynamic flag offset for inline. */
83 : : extern uint64_t rte_net_mlx5_dynf_inline_mask;
84 : : #define RTE_MBUF_F_TX_DYNF_NOINLINE rte_net_mlx5_dynf_inline_mask
85 : :
86 : : extern alignas(RTE_CACHE_LINE_SIZE) uint32_t mlx5_ptype_table[];
87 : : extern alignas(RTE_CACHE_LINE_SIZE) uint8_t mlx5_cksum_table[1 << 10];
88 : : extern alignas(RTE_CACHE_LINE_SIZE) uint8_t mlx5_swp_types_table[1 << 10];
89 : :
90 : : struct mlx5_txq_stats {
91 : : #ifdef MLX5_PMD_SOFT_COUNTERS
92 : : uint64_t opackets; /**< Total of successfully sent packets. */
93 : : uint64_t obytes; /**< Total of successfully sent bytes. */
94 : : #endif
95 : : uint64_t oerrors; /**< Total number of failed transmitted packets. */
96 : : };
97 : :
98 : : /* TX queue send local data. */
99 : : __extension__
100 : : struct mlx5_txq_local {
101 : : struct mlx5_wqe *wqe_last; /* last sent WQE pointer. */
102 : : struct rte_mbuf *mbuf; /* first mbuf to process. */
103 : : uint16_t pkts_copy; /* packets copied to elts. */
104 : : uint16_t pkts_sent; /* packets sent. */
105 : : uint16_t pkts_loop; /* packets sent on loop entry. */
106 : : uint16_t elts_free; /* available elts remain. */
107 : : uint16_t wqe_free; /* available wqe remain. */
108 : : uint16_t mbuf_off; /* data offset in current mbuf. */
109 : : uint16_t mbuf_nseg; /* number of remaining mbuf. */
110 : : uint16_t mbuf_free; /* number of inline mbufs to free. */
111 : : };
112 : :
113 : : /* TX queue descriptor. */
114 : : __extension__
115 : : struct __rte_cache_aligned mlx5_txq_data {
116 : : uint16_t elts_head; /* Current counter in (*elts)[]. */
117 : : uint16_t elts_tail; /* Counter of first element awaiting completion. */
118 : : uint16_t elts_comp; /* elts index since last completion request. */
119 : : uint16_t elts_s; /* Number of mbuf elements. */
120 : : uint16_t elts_m; /* Mask for mbuf elements indices. */
121 : : /* Fields related to elts mbuf storage. */
122 : : uint16_t wqe_ci; /* Consumer index for work queue. */
123 : : uint16_t wqe_pi; /* Producer index for work queue. */
124 : : uint16_t wqe_s; /* Number of WQ elements. */
125 : : uint16_t wqe_m; /* Mask Number for WQ elements. */
126 : : uint16_t wqe_comp; /* WQE index since last completion request. */
127 : : uint16_t wqe_thres; /* WQE threshold to request completion in CQ. */
128 : : /* WQ related fields. */
129 : : uint16_t cq_ci; /* Consumer index for completion queue. */
130 : : uint16_t cq_pi; /* Production index for completion queue. */
131 : : uint16_t cqe_s; /* Number of CQ elements. */
132 : : uint16_t cqe_m; /* Mask for CQ indices. */
133 : : /* CQ related fields. */
134 : : uint16_t elts_n:4; /* elts[] length (in log2). */
135 : : uint16_t cqe_n:4; /* Number of CQ elements (in log2). */
136 : : uint16_t wqe_n:4; /* Number of WQ elements (in log2). */
137 : : uint16_t tso_en:1; /* When set hardware TSO is enabled. */
138 : : uint16_t tunnel_en:1;
139 : : /* When set TX offload for tunneled packets are supported. */
140 : : uint16_t swp_en:1; /* Whether SW parser is enabled. */
141 : : uint16_t vlan_en:1; /* VLAN insertion in WQE is supported. */
142 : : uint16_t db_nc:1; /* Doorbell mapped to non-cached region. */
143 : : uint16_t db_heu:1; /* Doorbell heuristic write barrier. */
144 : : uint16_t rt_timestamp:1; /* Realtime timestamp format. */
145 : : uint16_t wait_on_time:1; /* WQE with timestamp is supported. */
146 : : uint16_t fast_free:1; /* mbuf fast free on Tx is enabled. */
147 : : uint16_t inlen_send; /* Ordinary send data inline size. */
148 : : uint16_t inlen_empw; /* eMPW max packet size to inline. */
149 : : uint16_t inlen_mode; /* Minimal data length to inline. */
150 : : uint8_t tx_aggr_affinity; /* TxQ affinity configuration. */
151 : : uint32_t qp_num_8s; /* QP number shifted by 8. */
152 : : uint32_t sq_mem_len; /* Length of TxQ for WQEs */
153 : : uint64_t offloads; /* Offloads for Tx Queue. */
154 : : struct mlx5_mr_ctrl mr_ctrl; /* MR control descriptor. */
155 : : struct mlx5_wqe *wqes; /* Work queue. */
156 : : struct mlx5_wqe *wqes_end; /* Work queue array limit. */
157 : : #ifdef RTE_PMD_MLX5_DEBUG
158 : : uint32_t *fcqs; /* Free completion queue (debug extended). */
159 : : #else
160 : : uint16_t *fcqs; /* Free completion queue. */
161 : : #endif
162 : : volatile struct mlx5_cqe *cqes; /* Completion queue. */
163 : : volatile uint32_t *qp_db; /* Work queue doorbell. */
164 : : volatile uint32_t *cq_db; /* Completion queue doorbell. */
165 : : uint16_t port_id; /* Port ID of device. */
166 : : uint16_t idx; /* Queue index. */
167 : : uint64_t rt_timemask; /* Scheduling timestamp mask. */
168 : : uint64_t ts_mask; /* Timestamp flag dynamic mask. */
169 : : uint64_t ts_last; /* Last scheduled timestamp. */
170 : : int32_t ts_offset; /* Timestamp field dynamic offset. */
171 : : uint32_t cq_mem_len; /* Length of TxQ for CQEs */
172 : : struct mlx5_dev_ctx_shared *sh; /* Shared context. */
173 : : struct mlx5_txq_stats stats; /* TX queue counters. */
174 : : struct mlx5_txq_stats stats_reset; /* stats on last reset. */
175 : : struct mlx5_uar_data uar_data;
176 : : struct rte_mbuf *elts[];
177 : : /* Storage for queued packets, must be the last field. */
178 : : };
179 : :
180 : : /* TX queue control descriptor. */
181 : : __extension__
182 : : struct mlx5_txq_ctrl {
183 : : LIST_ENTRY(mlx5_txq_ctrl) next; /* Pointer to the next element. */
184 : : RTE_ATOMIC(uint32_t) refcnt; /* Reference counter. */
185 : : unsigned int socket; /* CPU socket ID for allocations. */
186 : : bool is_hairpin; /* Whether TxQ type is Hairpin. */
187 : : unsigned int max_inline_data; /* Max inline data. */
188 : : unsigned int max_tso_header; /* Max TSO header size. */
189 : : struct mlx5_txq_obj *obj; /* Verbs/DevX queue object. */
190 : : struct mlx5_priv *priv; /* Back pointer to private data. */
191 : : off_t uar_mmap_offset; /* UAR mmap offset for non-primary process. */
192 : : uint16_t dump_file_n; /* Number of dump files. */
193 : : struct rte_eth_hairpin_conf hairpin_conf; /* Hairpin configuration. */
194 : : uint32_t hairpin_status; /* Hairpin binding status. */
195 : : struct mlx5_txq_data txq; /* Data path structure. */
196 : : /* Must be the last field in the structure, contains elts[]. */
197 : : };
198 : :
199 : : /* mlx5_txq.c */
200 : :
201 : : int mlx5_tx_queue_start(struct rte_eth_dev *dev, uint16_t queue_id);
202 : : int mlx5_tx_queue_stop(struct rte_eth_dev *dev, uint16_t queue_id);
203 : : int mlx5_tx_queue_start_primary(struct rte_eth_dev *dev, uint16_t queue_id);
204 : : int mlx5_tx_queue_stop_primary(struct rte_eth_dev *dev, uint16_t queue_id);
205 : : int mlx5_tx_queue_setup(struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
206 : : unsigned int socket, const struct rte_eth_txconf *conf);
207 : : int mlx5_tx_hairpin_queue_setup
208 : : (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
209 : : const struct rte_eth_hairpin_conf *hairpin_conf);
210 : : void mlx5_tx_queue_release(struct rte_eth_dev *dev, uint16_t qid);
211 : : int mlx5_tx_uar_init_secondary(struct rte_eth_dev *dev, int fd);
212 : : void mlx5_tx_uar_uninit_secondary(struct rte_eth_dev *dev);
213 : : int mlx5_txq_obj_verify(struct rte_eth_dev *dev);
214 : : struct mlx5_txq_ctrl *mlx5_txq_new(struct rte_eth_dev *dev, uint16_t idx,
215 : : uint16_t desc, unsigned int socket,
216 : : const struct rte_eth_txconf *conf);
217 : : struct mlx5_txq_ctrl *mlx5_txq_hairpin_new
218 : : (struct rte_eth_dev *dev, uint16_t idx, uint16_t desc,
219 : : const struct rte_eth_hairpin_conf *hairpin_conf);
220 : : struct mlx5_txq_ctrl *mlx5_txq_get(struct rte_eth_dev *dev, uint16_t idx);
221 : : int mlx5_txq_release(struct rte_eth_dev *dev, uint16_t idx);
222 : : int mlx5_txq_releasable(struct rte_eth_dev *dev, uint16_t idx);
223 : : int mlx5_txq_verify(struct rte_eth_dev *dev);
224 : : int mlx5_txq_get_sqn(struct mlx5_txq_ctrl *txq);
225 : : void mlx5_txq_alloc_elts(struct mlx5_txq_ctrl *txq_ctrl);
226 : : void mlx5_txq_free_elts(struct mlx5_txq_ctrl *txq_ctrl);
227 : : uint64_t mlx5_get_tx_port_offloads(struct rte_eth_dev *dev);
228 : : void mlx5_txq_dynf_timestamp_set(struct rte_eth_dev *dev);
229 : : int mlx5_count_aggr_ports(struct rte_eth_dev *dev);
230 : : int mlx5_map_aggr_tx_affinity(struct rte_eth_dev *dev, uint16_t tx_queue_id,
231 : : uint8_t affinity);
232 : : int mlx5_ext_txq_verify(struct rte_eth_dev *dev);
233 : : struct mlx5_external_q *mlx5_ext_txq_get(struct rte_eth_dev *dev, uint16_t idx);
234 : :
235 : : /* mlx5_tx.c */
236 : :
237 : : void mlx5_tx_handle_completion(struct mlx5_txq_data *__rte_restrict txq);
238 : : int mlx5_tx_descriptor_status(void *tx_queue, uint16_t offset);
239 : : void mlx5_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
240 : : struct rte_eth_txq_info *qinfo);
241 : : int mlx5_tx_burst_mode_get(struct rte_eth_dev *dev, uint16_t tx_queue_id,
242 : : struct rte_eth_burst_mode *mode);
243 : :
244 : : /* mlx5_tx_empw.c */
245 : :
246 : : MLX5_TXOFF_PRE_DECL(full_empw);
247 : : MLX5_TXOFF_PRE_DECL(none_empw);
248 : : MLX5_TXOFF_PRE_DECL(md_empw);
249 : : MLX5_TXOFF_PRE_DECL(mt_empw);
250 : : MLX5_TXOFF_PRE_DECL(mtsc_empw);
251 : : MLX5_TXOFF_PRE_DECL(mti_empw);
252 : : MLX5_TXOFF_PRE_DECL(mtv_empw);
253 : : MLX5_TXOFF_PRE_DECL(mtiv_empw);
254 : : MLX5_TXOFF_PRE_DECL(sc_empw);
255 : : MLX5_TXOFF_PRE_DECL(sci_empw);
256 : : MLX5_TXOFF_PRE_DECL(scv_empw);
257 : : MLX5_TXOFF_PRE_DECL(sciv_empw);
258 : : MLX5_TXOFF_PRE_DECL(i_empw);
259 : : MLX5_TXOFF_PRE_DECL(v_empw);
260 : : MLX5_TXOFF_PRE_DECL(iv_empw);
261 : :
262 : : /* mlx5_tx_nompw.c */
263 : :
264 : : MLX5_TXOFF_PRE_DECL(full);
265 : : MLX5_TXOFF_PRE_DECL(none);
266 : : MLX5_TXOFF_PRE_DECL(md);
267 : : MLX5_TXOFF_PRE_DECL(mt);
268 : : MLX5_TXOFF_PRE_DECL(mtsc);
269 : : MLX5_TXOFF_PRE_DECL(mti);
270 : : MLX5_TXOFF_PRE_DECL(mtv);
271 : : MLX5_TXOFF_PRE_DECL(mtiv);
272 : : MLX5_TXOFF_PRE_DECL(sc);
273 : : MLX5_TXOFF_PRE_DECL(sci);
274 : : MLX5_TXOFF_PRE_DECL(scv);
275 : : MLX5_TXOFF_PRE_DECL(sciv);
276 : : MLX5_TXOFF_PRE_DECL(i);
277 : : MLX5_TXOFF_PRE_DECL(v);
278 : : MLX5_TXOFF_PRE_DECL(iv);
279 : :
280 : : /* mlx5_tx_txpp.c */
281 : :
282 : : MLX5_TXOFF_PRE_DECL(full_ts_nompw);
283 : : MLX5_TXOFF_PRE_DECL(full_ts_nompwi);
284 : : MLX5_TXOFF_PRE_DECL(full_ts);
285 : : MLX5_TXOFF_PRE_DECL(full_ts_noi);
286 : : MLX5_TXOFF_PRE_DECL(none_ts);
287 : : MLX5_TXOFF_PRE_DECL(mdi_ts);
288 : : MLX5_TXOFF_PRE_DECL(mti_ts);
289 : : MLX5_TXOFF_PRE_DECL(mtiv_ts);
290 : :
291 : : /* mlx5_tx_mpw.c */
292 : :
293 : : MLX5_TXOFF_PRE_DECL(none_mpw);
294 : : MLX5_TXOFF_PRE_DECL(mci_mpw);
295 : : MLX5_TXOFF_PRE_DECL(mc_mpw);
296 : : MLX5_TXOFF_PRE_DECL(i_mpw);
297 : :
298 : : static __rte_always_inline struct mlx5_uar_data *
299 : : mlx5_tx_bfreg(struct mlx5_txq_data *txq)
300 : : {
301 : 0 : return &MLX5_PROC_PRIV(txq->port_id)->uar_table[txq->idx];
302 : : }
303 : :
304 : : /**
305 : : * Convert timestamp from mbuf format to linear counter
306 : : * of Clock Queue completions (24 bits).
307 : : *
308 : : * @param sh
309 : : * Pointer to the device shared context to fetch Tx
310 : : * packet pacing timestamp and parameters.
311 : : * @param ts
312 : : * Timestamp from mbuf to convert.
313 : : * @return
314 : : * positive or zero value - completion ID to wait.
315 : : * negative value - conversion error.
316 : : */
317 : : static __rte_always_inline int32_t
318 : : mlx5_txpp_convert_tx_ts(struct mlx5_dev_ctx_shared *sh, uint64_t mts)
319 : : {
320 : : uint64_t ts, ci;
321 : : uint32_t tick;
322 : :
323 : : do {
324 : : /*
325 : : * Read atomically two uint64_t fields and compare lsb bits.
326 : : * It there is no match - the timestamp was updated in
327 : : * the service thread, data should be re-read.
328 : : */
329 : 0 : rte_compiler_barrier();
330 : 0 : ci = rte_atomic_load_explicit(&sh->txpp.ts.ci_ts, rte_memory_order_relaxed);
331 : 0 : ts = rte_atomic_load_explicit(&sh->txpp.ts.ts, rte_memory_order_relaxed);
332 : 0 : rte_compiler_barrier();
333 [ # # # # : 0 : if (!((ts ^ ci) << (64 - MLX5_CQ_INDEX_WIDTH)))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
334 : : break;
335 : : } while (true);
336 : : /* Perform the skew correction, positive value to send earlier. */
337 : 0 : mts -= sh->txpp.skew;
338 : 0 : mts -= ts;
339 [ # # # # : 0 : if (unlikely(mts >= UINT64_MAX / 2)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
340 : : /* We have negative integer, mts is in the past. */
341 : 0 : rte_atomic_fetch_add_explicit(&sh->txpp.err_ts_past,
342 : : 1, rte_memory_order_relaxed);
343 : 0 : return -1;
344 : : }
345 : 0 : tick = sh->txpp.tick;
346 : : MLX5_ASSERT(tick);
347 : : /* Convert delta to completions, round up. */
348 : 0 : mts = (mts + tick - 1) / tick;
349 [ # # # # : 0 : if (unlikely(mts >= (1 << MLX5_CQ_INDEX_WIDTH) / 2 - 1)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
350 : : /* We have mts is too distant future. */
351 : 0 : rte_atomic_fetch_add_explicit(&sh->txpp.err_ts_future,
352 : : 1, rte_memory_order_relaxed);
353 : 0 : return -1;
354 : : }
355 : 0 : mts <<= 64 - MLX5_CQ_INDEX_WIDTH;
356 : 0 : ci += mts;
357 : 0 : ci >>= 64 - MLX5_CQ_INDEX_WIDTH;
358 : 0 : return ci;
359 : : }
360 : :
361 : : /**
362 : : * Read real time clock counter directly from the device PCI BAR area.
363 : : * The PCI BAR must be mapped to the process memory space at initialization.
364 : : *
365 : : * @param dev
366 : : * Device to read clock counter from
367 : : *
368 : : * @return
369 : : * 0 - if HCA BAR is not supported or not mapped.
370 : : * !=0 - read 64-bit value of real-time in UTC formatv (nanoseconds)
371 : : */
372 : : static __rte_always_inline uint64_t mlx5_read_pcibar_clock(struct rte_eth_dev *dev)
373 : : {
374 : 0 : struct mlx5_proc_priv *ppriv = dev->process_private;
375 : :
376 [ # # # # ]: 0 : if (ppriv && ppriv->hca_bar) {
377 : : struct mlx5_priv *priv = dev->data->dev_private;
378 : : struct mlx5_dev_ctx_shared *sh = priv->sh;
379 : 0 : uint64_t *hca_ptr = (uint64_t *)(ppriv->hca_bar) +
380 : : __mlx5_64_off(initial_seg, real_time);
381 : : uint64_t __rte_atomic *ts_addr;
382 : : uint64_t ts;
383 : :
384 : : ts_addr = (uint64_t __rte_atomic *)hca_ptr;
385 : 0 : ts = rte_atomic_load_explicit(ts_addr, rte_memory_order_seq_cst);
386 [ # # ]: 0 : ts = rte_be_to_cpu_64(ts);
387 : : ts = mlx5_txpp_convert_rx_ts(sh, ts);
388 : : return ts;
389 : : }
390 : : return 0;
391 : : }
392 : :
393 : : static __rte_always_inline uint64_t mlx5_read_pcibar_clock_from_txq(struct mlx5_txq_data *txq)
394 : : {
395 : : struct mlx5_txq_ctrl *txq_ctrl = container_of(txq, struct mlx5_txq_ctrl, txq);
396 : : struct rte_eth_dev *dev = ETH_DEV(txq_ctrl->priv);
397 : :
398 : : return mlx5_read_pcibar_clock(dev);
399 : : }
400 : :
401 : : /**
402 : : * Set Software Parser flags and offsets in Ethernet Segment of WQE.
403 : : * Flags must be preliminary initialized to zero.
404 : : *
405 : : * @param loc
406 : : * Pointer to burst routine local context.
407 : : * @param swp_flags
408 : : * Pointer to store Software Parser flags.
409 : : * @param olx
410 : : * Configured Tx offloads mask. It is fully defined at
411 : : * compile time and may be used for optimization.
412 : : *
413 : : * @return
414 : : * Software Parser offsets packed in dword.
415 : : * Software Parser flags are set by pointer.
416 : : */
417 : : static __rte_always_inline uint32_t
418 : : txq_mbuf_to_swp(struct mlx5_txq_local *__rte_restrict loc,
419 : : uint8_t *swp_flags,
420 : : unsigned int olx)
421 : : {
422 : : uint64_t ol, tunnel;
423 : : unsigned int idx, off;
424 : : uint32_t set;
425 : :
426 : : if (!MLX5_TXOFF_CONFIG(SWP))
427 : : return 0;
428 : : ol = loc->mbuf->ol_flags;
429 : : tunnel = ol & RTE_MBUF_F_TX_TUNNEL_MASK;
430 : : /*
431 : : * Check whether Software Parser is required.
432 : : * Only customized tunnels may ask for.
433 : : */
434 : 0 : if (likely(tunnel != RTE_MBUF_F_TX_TUNNEL_UDP && tunnel != RTE_MBUF_F_TX_TUNNEL_IP))
435 : : return 0;
436 : : /*
437 : : * The index should have:
438 : : * bit[0:1] = RTE_MBUF_F_TX_L4_MASK
439 : : * bit[4] = RTE_MBUF_F_TX_IPV6
440 : : * bit[8] = RTE_MBUF_F_TX_OUTER_IPV6
441 : : * bit[9] = RTE_MBUF_F_TX_OUTER_UDP
442 : : */
443 : 0 : idx = (ol & (RTE_MBUF_F_TX_L4_MASK | RTE_MBUF_F_TX_IPV6 | RTE_MBUF_F_TX_OUTER_IPV6)) >> 52;
444 [ # # # # : 0 : idx |= (tunnel == RTE_MBUF_F_TX_TUNNEL_UDP) ? (1 << 9) : 0;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
445 : 0 : *swp_flags = mlx5_swp_types_table[idx];
446 : : /*
447 : : * Set offsets for SW parser. Since ConnectX-5, SW parser just
448 : : * complements HW parser. SW parser starts to engage only if HW parser
449 : : * can't reach a header. For the older devices, HW parser will not kick
450 : : * in if any of SWP offsets is set. Therefore, all of the L3 offsets
451 : : * should be set regardless of HW offload.
452 : : */
453 : 0 : off = loc->mbuf->outer_l2_len;
454 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && ol & RTE_MBUF_F_TX_VLAN)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
455 : 0 : off += sizeof(struct rte_vlan_hdr);
456 : 0 : set = (off >> 1) << 8; /* Outer L3 offset. */
457 : 0 : off += loc->mbuf->outer_l3_len;
458 [ # # # # : 0 : if (tunnel == RTE_MBUF_F_TX_TUNNEL_UDP)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
459 : 0 : set |= off >> 1; /* Outer L4 offset. */
460 [ # # # # : 0 : if (ol & (RTE_MBUF_F_TX_IPV4 | RTE_MBUF_F_TX_IPV6)) { /* Inner IP. */
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
461 : 0 : const uint64_t csum = ol & RTE_MBUF_F_TX_L4_MASK;
462 : 0 : off += loc->mbuf->l2_len;
463 : 0 : set |= (off >> 1) << 24; /* Inner L3 offset. */
464 : 0 : if (csum == RTE_MBUF_F_TX_TCP_CKSUM ||
465 [ # # # # : 0 : csum == RTE_MBUF_F_TX_UDP_CKSUM ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
466 [ # # # # : 0 : (MLX5_TXOFF_CONFIG(TSO) && ol & RTE_MBUF_F_TX_TCP_SEG)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
467 : 0 : off += loc->mbuf->l3_len;
468 : 0 : set |= (off >> 1) << 16; /* Inner L4 offset. */
469 : : }
470 : : }
471 : : set = rte_cpu_to_le_32(set);
472 : : return set;
473 : : }
474 : :
475 : : /**
476 : : * Convert the Checksum offloads to Verbs.
477 : : *
478 : : * @param buf
479 : : * Pointer to the mbuf.
480 : : *
481 : : * @return
482 : : * Converted checksum flags.
483 : : */
484 : : static __rte_always_inline uint8_t
485 : : txq_ol_cksum_to_cs(struct rte_mbuf *buf)
486 : : {
487 : : uint32_t idx;
488 : 0 : uint8_t is_tunnel = !!(buf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK);
489 : : const uint64_t ol_flags_mask = RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_L4_MASK |
490 : : RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_OUTER_IP_CKSUM;
491 : :
492 : : /*
493 : : * The index should have:
494 : : * bit[0] = RTE_MBUF_F_TX_TCP_SEG
495 : : * bit[2:3] = RTE_MBUF_F_TX_UDP_CKSUM, RTE_MBUF_F_TX_TCP_CKSUM
496 : : * bit[4] = RTE_MBUF_F_TX_IP_CKSUM
497 : : * bit[8] = RTE_MBUF_F_TX_OUTER_IP_CKSUM
498 : : * bit[9] = tunnel
499 : : */
500 [ # # # # : 0 : idx = ((buf->ol_flags & ol_flags_mask) >> 50) | (!!is_tunnel << 9);
# # # # #
# # # ]
501 : 0 : return mlx5_cksum_table[idx];
502 : : }
503 : :
504 : : /**
505 : : * Free the mbufs from the linear array of pointers.
506 : : *
507 : : * @param txq
508 : : * Pointer to Tx queue structure.
509 : : * @param pkts
510 : : * Pointer to array of packets to be free.
511 : : * @param pkts_n
512 : : * Number of packets to be freed.
513 : : */
514 : : static __rte_always_inline void
515 : : mlx5_tx_free_mbuf(struct mlx5_txq_data *__rte_restrict txq,
516 : : struct rte_mbuf **__rte_restrict pkts,
517 : : unsigned int pkts_n)
518 : : {
519 : : struct rte_mempool *pool = NULL;
520 : : struct rte_mbuf **p_free = NULL;
521 : : struct rte_mbuf *mbuf;
522 : : unsigned int n_free = 0;
523 : :
524 : : /*
525 : : * The implemented algorithm eliminates
526 : : * copying pointers to temporary array
527 : : * for rte_mempool_put_bulk() calls.
528 : : */
529 : : MLX5_ASSERT(pkts);
530 : : MLX5_ASSERT(pkts_n);
531 : : /*
532 : : * Free mbufs directly to the pool in bulk
533 : : * if fast free offload is engaged
534 : : */
535 : 0 : if (txq->fast_free) {
536 : 0 : mbuf = *pkts;
537 [ # # ]: 0 : pool = mbuf->pool;
538 : : rte_mempool_put_bulk(pool, (void *)pkts, pkts_n);
539 : : return;
540 : : }
541 : : for (;;) {
542 : : for (;;) {
543 : : /*
544 : : * Decrement mbuf reference counter, detach
545 : : * indirect and external buffers if needed.
546 : : */
547 [ # # ]: 0 : mbuf = rte_pktmbuf_prefree_seg(*pkts);
548 [ # # ]: 0 : if (likely(mbuf != NULL)) {
549 : : MLX5_ASSERT(mbuf == *pkts);
550 [ # # ]: 0 : if (likely(n_free != 0)) {
551 [ # # ]: 0 : if (unlikely(pool != mbuf->pool))
552 : : /* From different pool. */
553 : : break;
554 : : } else {
555 : : /* Start new scan array. */
556 : 0 : pool = mbuf->pool;
557 : : p_free = pkts;
558 : : }
559 : 0 : ++n_free;
560 : 0 : ++pkts;
561 : 0 : --pkts_n;
562 [ # # ]: 0 : if (unlikely(pkts_n == 0)) {
563 : : mbuf = NULL;
564 : : break;
565 : : }
566 : : } else {
567 : : /*
568 : : * This happens if mbuf is still referenced.
569 : : * We can't put it back to the pool, skip.
570 : : */
571 : 0 : ++pkts;
572 : 0 : --pkts_n;
573 [ # # ]: 0 : if (unlikely(n_free != 0))
574 : : /* There is some array to free.*/
575 : : break;
576 [ # # ]: 0 : if (unlikely(pkts_n == 0))
577 : : /* Last mbuf, nothing to free. */
578 : : return;
579 : : }
580 : : }
581 : : for (;;) {
582 : : /*
583 : : * This loop is implemented to avoid multiple
584 : : * inlining of rte_mempool_put_bulk().
585 : : */
586 : 0 : MLX5_ASSERT(pool);
587 : : MLX5_ASSERT(p_free);
588 : : MLX5_ASSERT(n_free);
589 : : /*
590 : : * Free the array of pre-freed mbufs
591 : : * belonging to the same memory pool.
592 : : */
593 : : rte_mempool_put_bulk(pool, (void *)p_free, n_free);
594 [ # # ]: 0 : if (unlikely(mbuf != NULL)) {
595 : : /* There is the request to start new scan. */
596 : 0 : pool = mbuf->pool;
597 : 0 : p_free = pkts++;
598 : : n_free = 1;
599 : 0 : --pkts_n;
600 [ # # ]: 0 : if (likely(pkts_n != 0))
601 : : break;
602 : : /*
603 : : * This is the last mbuf to be freed.
604 : : * Do one more loop iteration to complete.
605 : : * This is rare case of the last unique mbuf.
606 : : */
607 : : mbuf = NULL;
608 : : continue;
609 : : }
610 [ # # ]: 0 : if (likely(pkts_n == 0))
611 : : return;
612 : : n_free = 0;
613 : : break;
614 : : }
615 : : }
616 : : }
617 : :
618 : : /**
619 : : * No inline version to free buffers for optimal call
620 : : * on the tx_burst completion.
621 : : */
622 : : static __rte_noinline void
623 [ # # ]: 0 : __mlx5_tx_free_mbuf(struct mlx5_txq_data *__rte_restrict txq,
624 : : struct rte_mbuf **__rte_restrict pkts,
625 : : unsigned int pkts_n)
626 : : {
627 : : mlx5_tx_free_mbuf(txq, pkts, pkts_n);
628 : 0 : }
629 : :
630 : : /**
631 : : * Free the mbuf from the elts ring buffer till new tail.
632 : : *
633 : : * @param txq
634 : : * Pointer to Tx queue structure.
635 : : * @param tail
636 : : * Index in elts to free up to, becomes new elts tail.
637 : : */
638 : : static __rte_always_inline void
639 : : mlx5_tx_free_elts(struct mlx5_txq_data *__rte_restrict txq,
640 : : uint16_t tail)
641 : : {
642 : 0 : uint16_t n_elts = tail - txq->elts_tail;
643 : :
644 : : MLX5_ASSERT(n_elts);
645 : : MLX5_ASSERT(n_elts <= txq->elts_s);
646 : : /*
647 : : * Implement a loop to support ring buffer wraparound
648 : : * with single inlining of mlx5_tx_free_mbuf().
649 : : */
650 : : do {
651 : : unsigned int part;
652 : :
653 : 0 : part = txq->elts_s - (txq->elts_tail & txq->elts_m);
654 : 0 : part = RTE_MIN(part, n_elts);
655 : : MLX5_ASSERT(part);
656 : : MLX5_ASSERT(part <= txq->elts_s);
657 [ # # ]: 0 : mlx5_tx_free_mbuf(txq,
658 : : &txq->elts[txq->elts_tail & txq->elts_m],
659 : : part);
660 : 0 : txq->elts_tail += part;
661 : 0 : n_elts -= part;
662 [ # # ]: 0 : } while (n_elts);
663 : : }
664 : :
665 : : /**
666 : : * Store the mbuf being sent into elts ring buffer.
667 : : * On Tx completion these mbufs will be freed.
668 : : *
669 : : * @param txq
670 : : * Pointer to Tx queue structure.
671 : : * @param pkts
672 : : * Pointer to array of packets to be stored.
673 : : * @param pkts_n
674 : : * Number of packets to be stored.
675 : : * @param olx
676 : : * Configured Tx offloads mask. It is fully defined at
677 : : * compile time and may be used for optimization.
678 : : */
679 : : static __rte_always_inline void
680 : : mlx5_tx_copy_elts(struct mlx5_txq_data *__rte_restrict txq,
681 : : struct rte_mbuf **__rte_restrict pkts,
682 : : unsigned int pkts_n,
683 : : unsigned int olx __rte_unused)
684 : : {
685 : : unsigned int part;
686 : 0 : struct rte_mbuf **elts = (struct rte_mbuf **)txq->elts;
687 : :
688 : : MLX5_ASSERT(pkts);
689 : : MLX5_ASSERT(pkts_n);
690 : 0 : part = txq->elts_s - (txq->elts_head & txq->elts_m);
691 : : MLX5_ASSERT(part);
692 : : MLX5_ASSERT(part <= txq->elts_s);
693 : : /* This code is a good candidate for vectorizing with SIMD. */
694 : 0 : rte_memcpy((void *)(elts + (txq->elts_head & txq->elts_m)),
695 : : (void *)pkts,
696 : 0 : RTE_MIN(part, pkts_n) * sizeof(struct rte_mbuf *));
697 : 0 : txq->elts_head += pkts_n;
698 [ # # # # : 0 : if (unlikely(part < pkts_n))
# # # # #
# # # # #
# # # # #
# # # ]
699 : : /* The copy is wrapping around the elts array. */
700 : 0 : rte_memcpy((void *)elts, (void *)(pkts + part),
701 [ # # # # : 0 : (pkts_n - part) * sizeof(struct rte_mbuf *));
# # # # #
# # # # #
# # # # #
# # # ]
702 : : }
703 : :
704 : : /**
705 : : * Check if the completion request flag should be set in the last WQE.
706 : : * Both pushed mbufs and WQEs are monitored and the completion request
707 : : * flag is set if any of thresholds is reached.
708 : : *
709 : : * @param txq
710 : : * Pointer to TX queue structure.
711 : : * @param loc
712 : : * Pointer to burst routine local context.
713 : : * @param olx
714 : : * Configured Tx offloads mask. It is fully defined at
715 : : * compile time and may be used for optimization.
716 : : */
717 : : static __rte_always_inline void
718 : : mlx5_tx_request_completion(struct mlx5_txq_data *__rte_restrict txq,
719 : : struct mlx5_txq_local *__rte_restrict loc,
720 : : unsigned int olx)
721 : : {
722 : 0 : uint16_t head = txq->elts_head;
723 : : unsigned int part;
724 : :
725 : : part = MLX5_TXOFF_CONFIG(INLINE) ?
726 : 0 : 0 : loc->pkts_sent - loc->pkts_copy;
727 : 0 : head += part;
728 [ # # # # : 0 : if ((uint16_t)(head - txq->elts_comp) >= MLX5_TX_COMP_THRESH ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
729 : 0 : (MLX5_TXOFF_CONFIG(INLINE) &&
730 [ # # # # : 0 : (uint16_t)(txq->wqe_ci - txq->wqe_comp) >= txq->wqe_thres)) {
# # # # #
# # # #
# ]
731 : : volatile struct mlx5_wqe *last = loc->wqe_last;
732 : :
733 : : MLX5_ASSERT(last);
734 : 0 : txq->elts_comp = head;
735 : : if (MLX5_TXOFF_CONFIG(INLINE))
736 : 0 : txq->wqe_comp = txq->wqe_ci;
737 : : /* Request unconditional completion on last WQE. */
738 : 0 : last->cseg.flags = RTE_BE32(MLX5_COMP_ALWAYS <<
739 : : MLX5_COMP_MODE_OFFSET);
740 : : /* Save elts_head in dedicated free on completion queue. */
741 : : #ifdef RTE_PMD_MLX5_DEBUG
742 : : txq->fcqs[txq->cq_pi++ & txq->cqe_m] = head |
743 : : (last->cseg.opcode >> 8) << 16;
744 : : #else
745 : 0 : txq->fcqs[txq->cq_pi++ & txq->cqe_m] = head;
746 : : #endif
747 : : /* A CQE slot must always be available. */
748 : : MLX5_ASSERT((txq->cq_pi - txq->cq_ci) <= txq->cqe_s);
749 : : }
750 : : }
751 : :
752 : : /**
753 : : * Set completion request flag for all issued WQEs.
754 : : * This routine is intended to be used with enabled fast path tracing
755 : : * and send scheduling on time to provide the detailed report in trace
756 : : * for send completions on every WQE.
757 : : *
758 : : * @param txq
759 : : * Pointer to TX queue structure.
760 : : * @param loc
761 : : * Pointer to burst routine local context.
762 : : * @param olx
763 : : * Configured Tx offloads mask. It is fully defined at
764 : : * compile time and may be used for optimization.
765 : : */
766 : : static __rte_always_inline void
767 : : mlx5_tx_request_completion_trace(struct mlx5_txq_data *__rte_restrict txq,
768 : : struct mlx5_txq_local *__rte_restrict loc,
769 : : unsigned int olx)
770 : : {
771 : : uint16_t head = txq->elts_comp;
772 : :
773 : : while (txq->wqe_comp != txq->wqe_ci) {
774 : : volatile struct mlx5_wqe *wqe;
775 : : uint32_t wqe_n;
776 : :
777 : : MLX5_ASSERT(loc->wqe_last);
778 : : wqe = txq->wqes + (txq->wqe_comp & txq->wqe_m);
779 : : if (wqe == loc->wqe_last) {
780 : : head = txq->elts_head;
781 : : head += MLX5_TXOFF_CONFIG(INLINE) ?
782 : : 0 : loc->pkts_sent - loc->pkts_copy;
783 : : txq->elts_comp = head;
784 : : }
785 : : /* Completion request flag was set on cseg constructing. */
786 : : #ifdef RTE_PMD_MLX5_DEBUG
787 : : txq->fcqs[txq->cq_pi++ & txq->cqe_m] = head |
788 : : (wqe->cseg.opcode >> 8) << 16;
789 : : #else
790 : : txq->fcqs[txq->cq_pi++ & txq->cqe_m] = head;
791 : : #endif
792 : : /* A CQE slot must always be available. */
793 : : MLX5_ASSERT((txq->cq_pi - txq->cq_ci) <= txq->cqe_s);
794 : : /* Advance to the next WQE in the queue. */
795 : : wqe_n = rte_be_to_cpu_32(wqe->cseg.sq_ds) & 0x3F;
796 : : txq->wqe_comp += RTE_ALIGN(wqe_n, 4) / 4;
797 : : }
798 : : }
799 : :
800 : : /**
801 : : * Build the Control Segment with specified opcode:
802 : : * - MLX5_OPCODE_SEND
803 : : * - MLX5_OPCODE_ENHANCED_MPSW
804 : : * - MLX5_OPCODE_TSO
805 : : *
806 : : * @param txq
807 : : * Pointer to TX queue structure.
808 : : * @param loc
809 : : * Pointer to burst routine local context.
810 : : * @param wqe
811 : : * Pointer to WQE to fill with built Control Segment.
812 : : * @param ds
813 : : * Supposed length of WQE in segments.
814 : : * @param opcode
815 : : * SQ WQE opcode to put into Control Segment.
816 : : * @param olx
817 : : * Configured Tx offloads mask. It is fully defined at
818 : : * compile time and may be used for optimization.
819 : : */
820 : : static __rte_always_inline void
821 : : mlx5_tx_cseg_init(struct mlx5_txq_data *__rte_restrict txq,
822 : : struct mlx5_txq_local *__rte_restrict loc __rte_unused,
823 : : struct mlx5_wqe *__rte_restrict wqe,
824 : : unsigned int ds,
825 : : unsigned int opcode,
826 : : unsigned int olx)
827 : : {
828 : : struct mlx5_wqe_cseg *__rte_restrict cs = &wqe->cseg;
829 : : uint64_t real_time;
830 : :
831 : : /* For legacy MPW replace the EMPW by TSO with modifier. */
832 : : if (MLX5_TXOFF_CONFIG(MPW) && opcode == MLX5_OPCODE_ENHANCED_MPSW)
833 : : opcode = MLX5_OPCODE_TSO | MLX5_OPC_MOD_MPW << 24;
834 [ # # # # : 0 : cs->opcode = rte_cpu_to_be_32((txq->wqe_ci << 8) | opcode);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
835 [ # # # # : 0 : cs->sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
836 : : if (MLX5_TXOFF_CONFIG(TXPP) && __rte_trace_point_fp_is_enabled())
837 : : cs->flags = RTE_BE32(MLX5_COMP_ALWAYS <<
838 : : MLX5_COMP_MODE_OFFSET);
839 : : else
840 : 0 : cs->flags = RTE_BE32(MLX5_COMP_ONLY_FIRST_ERR <<
841 : : MLX5_COMP_MODE_OFFSET);
842 [ # # # # : 0 : cs->misc = RTE_BE32(0);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
843 : : if (__rte_trace_point_fp_is_enabled()) {
844 : : real_time = mlx5_read_pcibar_clock_from_txq(txq);
845 : : if (!loc->pkts_sent)
846 : : rte_pmd_mlx5_trace_tx_entry(real_time, txq->port_id, txq->idx);
847 : : rte_pmd_mlx5_trace_tx_wqe(real_time, (txq->wqe_ci << 8) | opcode);
848 : : }
849 : : }
850 : :
851 : : /**
852 : : * Build the Synchronize Queue Segment with specified completion index.
853 : : *
854 : : * @param txq
855 : : * Pointer to TX queue structure.
856 : : * @param loc
857 : : * Pointer to burst routine local context.
858 : : * @param wqe
859 : : * Pointer to WQE to fill with built Control Segment.
860 : : * @param wci
861 : : * Completion index in Clock Queue to wait.
862 : : * @param olx
863 : : * Configured Tx offloads mask. It is fully defined at
864 : : * compile time and may be used for optimization.
865 : : */
866 : : static __rte_always_inline void
867 : : mlx5_tx_qseg_init(struct mlx5_txq_data *restrict txq,
868 : : struct mlx5_txq_local *restrict loc __rte_unused,
869 : : struct mlx5_wqe *restrict wqe,
870 : : unsigned int wci,
871 : : unsigned int olx __rte_unused)
872 : : {
873 : : struct mlx5_wqe_qseg *qs;
874 : :
875 : 0 : qs = RTE_PTR_ADD(wqe, MLX5_WSEG_SIZE);
876 : 0 : qs->max_index = rte_cpu_to_be_32(wci);
877 [ # # # # : 0 : qs->qpn_cqn = rte_cpu_to_be_32(txq->sh->txpp.clock_queue.cq_obj.cq->id);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
878 : 0 : qs->reserved0 = RTE_BE32(0);
879 : 0 : qs->reserved1 = RTE_BE32(0);
880 : 0 : }
881 : :
882 : : /**
883 : : * Build the Wait on Time Segment with specified timestamp value.
884 : : *
885 : : * @param txq
886 : : * Pointer to TX queue structure.
887 : : * @param loc
888 : : * Pointer to burst routine local context.
889 : : * @param wqe
890 : : * Pointer to WQE to fill with built Control Segment.
891 : : * @param ts
892 : : * Timesatmp value to wait.
893 : : * @param olx
894 : : * Configured Tx offloads mask. It is fully defined at
895 : : * compile time and may be used for optimization.
896 : : */
897 : : static __rte_always_inline void
898 : : mlx5_tx_wseg_init(struct mlx5_txq_data *restrict txq,
899 : : struct mlx5_txq_local *restrict loc __rte_unused,
900 : : struct mlx5_wqe *restrict wqe,
901 : : uint64_t ts,
902 : : unsigned int olx __rte_unused)
903 : : {
904 : : struct mlx5_wqe_wseg *ws;
905 : :
906 : 0 : ws = RTE_PTR_ADD(wqe, MLX5_WSEG_SIZE);
907 : 0 : ws->operation = rte_cpu_to_be_32(MLX5_WAIT_COND_CYCLIC_SMALLER);
908 : 0 : ws->lkey = RTE_BE32(0);
909 : 0 : ws->va_high = RTE_BE32(0);
910 : 0 : ws->va_low = RTE_BE32(0);
911 [ # # # # : 0 : if (txq->rt_timestamp) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
912 : 0 : ts = ts % (uint64_t)NS_PER_S
913 : 0 : | (ts / (uint64_t)NS_PER_S) << 32;
914 : : }
915 [ # # # # : 0 : ws->value = rte_cpu_to_be_64(ts);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
916 : 0 : ws->mask = txq->rt_timemask;
917 : 0 : }
918 : :
919 : : /**
920 : : * Build the Ethernet Segment without inlined data.
921 : : * Supports Software Parser, Checksums and VLAN insertion Tx offload features.
922 : : *
923 : : * @param txq
924 : : * Pointer to TX queue structure.
925 : : * @param loc
926 : : * Pointer to burst routine local context.
927 : : * @param wqe
928 : : * Pointer to WQE to fill with built Ethernet Segment.
929 : : * @param olx
930 : : * Configured Tx offloads mask. It is fully defined at
931 : : * compile time and may be used for optimization.
932 : : */
933 : : static __rte_always_inline void
934 : : mlx5_tx_eseg_none(struct mlx5_txq_data *__rte_restrict txq __rte_unused,
935 : : struct mlx5_txq_local *__rte_restrict loc,
936 : : struct mlx5_wqe *__rte_restrict wqe,
937 : : unsigned int olx)
938 : : {
939 : : struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
940 : : uint32_t csum;
941 : :
942 : : /*
943 : : * Calculate and set check sum flags first, dword field
944 : : * in segment may be shared with Software Parser flags.
945 : : */
946 : 0 : csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
947 [ # # # # : 0 : es->flags = rte_cpu_to_le_32(csum);
# # # # #
# # # # #
# # # # #
# # # ]
948 : : /*
949 : : * Calculate and set Software Parser offsets and flags.
950 : : * These flags a set for custom UDP and IP tunnel packets.
951 : : */
952 : 0 : es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
953 : : /* Fill metadata field if needed. */
954 : 0 : es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
955 : 0 : loc->mbuf->ol_flags & RTE_MBUF_DYNFLAG_TX_METADATA ?
956 [ # # # # : 0 : rte_cpu_to_be_32(*RTE_FLOW_DYNF_METADATA(loc->mbuf)) :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
957 : : 0 : 0;
958 : : /* Engage VLAN tag insertion feature if requested. */
959 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
# # # # ]
960 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
# # # # #
# # # # #
# # ]
961 : : /*
962 : : * We should get here only if device support
963 : : * this feature correctly.
964 : : */
965 : : MLX5_ASSERT(txq->vlan_en);
966 [ # # # # : 0 : es->inline_hdr = rte_cpu_to_be_32(MLX5_ETH_WQE_VLAN_INSERT |
# # # # #
# # # # #
# # # # #
# ]
967 : : loc->mbuf->vlan_tci);
968 : : } else {
969 : 0 : es->inline_hdr = RTE_BE32(0);
970 : : }
971 : : }
972 : :
973 : : /**
974 : : * Build the Ethernet Segment with minimal inlined data
975 : : * of MLX5_ESEG_MIN_INLINE_SIZE bytes length. This is
976 : : * used to fill the gap in single WQEBB WQEs.
977 : : * Supports Software Parser, Checksums and VLAN
978 : : * insertion Tx offload features.
979 : : *
980 : : * @param txq
981 : : * Pointer to TX queue structure.
982 : : * @param loc
983 : : * Pointer to burst routine local context.
984 : : * @param wqe
985 : : * Pointer to WQE to fill with built Ethernet Segment.
986 : : * @param vlan
987 : : * Length of VLAN tag insertion if any.
988 : : * @param olx
989 : : * Configured Tx offloads mask. It is fully defined at
990 : : * compile time and may be used for optimization.
991 : : */
992 : : static __rte_always_inline void
993 : : mlx5_tx_eseg_dmin(struct mlx5_txq_data *__rte_restrict txq __rte_unused,
994 : : struct mlx5_txq_local *__rte_restrict loc,
995 : : struct mlx5_wqe *__rte_restrict wqe,
996 : : unsigned int vlan,
997 : : unsigned int olx)
998 : : {
999 : : struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
1000 : : uint32_t csum;
1001 : : uint8_t *psrc, *pdst;
1002 : :
1003 : : /*
1004 : : * Calculate and set check sum flags first, dword field
1005 : : * in segment may be shared with Software Parser flags.
1006 : : */
1007 : 0 : csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
1008 [ # # # # : 0 : es->flags = rte_cpu_to_le_32(csum);
# # ]
1009 : : /*
1010 : : * Calculate and set Software Parser offsets and flags.
1011 : : * These flags a set for custom UDP and IP tunnel packets.
1012 : : */
1013 : 0 : es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
1014 : : /* Fill metadata field if needed. */
1015 : 0 : es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
1016 : 0 : loc->mbuf->ol_flags & RTE_MBUF_DYNFLAG_TX_METADATA ?
1017 [ # # # # : 0 : rte_cpu_to_be_32(*RTE_FLOW_DYNF_METADATA(loc->mbuf)) :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
1018 : : 0 : 0;
1019 : 0 : psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
1020 : 0 : es->inline_hdr_sz = RTE_BE16(MLX5_ESEG_MIN_INLINE_SIZE);
1021 [ # # # # : 0 : es->inline_data = *(unaligned_uint16_t *)psrc;
# # ]
1022 : 0 : psrc += sizeof(uint16_t);
1023 : 0 : pdst = (uint8_t *)(es + 1);
1024 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
# # # # ]
1025 : : /* Implement VLAN tag insertion as part inline data. */
1026 : : memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
1027 : : pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
1028 : : psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
1029 : : /* Insert VLAN ethertype + VLAN tag. */
1030 [ # # # # : 0 : *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
# # # # ]
1031 : : ((RTE_ETHER_TYPE_VLAN << 16) |
1032 : : loc->mbuf->vlan_tci);
1033 : : pdst += sizeof(struct rte_vlan_hdr);
1034 : : /* Copy the rest two bytes from packet data. */
1035 : : MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
1036 : 0 : *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
1037 : : } else {
1038 : : /* Fill the gap in the title WQEBB with inline data. */
1039 : : rte_mov16(pdst, psrc);
1040 : : }
1041 : : }
1042 : :
1043 : : /**
1044 : : * Build the Ethernet Segment with entire packet data inlining. Checks the
1045 : : * boundary of WQEBB and ring buffer wrapping, supports Software Parser,
1046 : : * Checksums and VLAN insertion Tx offload features.
1047 : : *
1048 : : * @param txq
1049 : : * Pointer to TX queue structure.
1050 : : * @param loc
1051 : : * Pointer to burst routine local context.
1052 : : * @param wqe
1053 : : * Pointer to WQE to fill with built Ethernet Segment.
1054 : : * @param vlan
1055 : : * Length of VLAN tag insertion if any.
1056 : : * @param inlen
1057 : : * Length of data to inline (VLAN included, if any).
1058 : : * @param tso
1059 : : * TSO flag, set mss field from the packet.
1060 : : * @param olx
1061 : : * Configured Tx offloads mask. It is fully defined at
1062 : : * compile time and may be used for optimization.
1063 : : *
1064 : : * @return
1065 : : * Pointer to the next Data Segment (aligned and wrapped around).
1066 : : */
1067 : : static __rte_always_inline struct mlx5_wqe_dseg *
1068 : : mlx5_tx_eseg_data(struct mlx5_txq_data *__rte_restrict txq,
1069 : : struct mlx5_txq_local *__rte_restrict loc,
1070 : : struct mlx5_wqe *__rte_restrict wqe,
1071 : : unsigned int vlan,
1072 : : unsigned int inlen,
1073 : : unsigned int tso,
1074 : : unsigned int olx)
1075 : : {
1076 : : struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
1077 : : uint32_t csum;
1078 : : uint8_t *psrc, *pdst;
1079 : : unsigned int part;
1080 : :
1081 : : /*
1082 : : * Calculate and set check sum flags first, dword field
1083 : : * in segment may be shared with Software Parser flags.
1084 : : */
1085 : 0 : csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
1086 : : if (tso) {
1087 : 0 : csum <<= 24;
1088 : 0 : csum |= loc->mbuf->tso_segsz;
1089 [ # # # # : 0 : es->flags = rte_cpu_to_be_32(csum);
# # # # #
# # # # #
# # # # #
# ]
1090 : : } else {
1091 [ # # # # : 0 : es->flags = rte_cpu_to_le_32(csum);
# # # # #
# # # ]
1092 : : }
1093 : : /*
1094 : : * Calculate and set Software Parser offsets and flags.
1095 : : * These flags a set for custom UDP and IP tunnel packets.
1096 : : */
1097 : 0 : es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
1098 : : /* Fill metadata field if needed. */
1099 : 0 : es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
1100 : 0 : loc->mbuf->ol_flags & RTE_MBUF_DYNFLAG_TX_METADATA ?
1101 [ # # # # : 0 : rte_cpu_to_be_32(*RTE_FLOW_DYNF_METADATA(loc->mbuf)) :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1102 : : 0 : 0;
1103 : 0 : psrc = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
1104 [ # # # # : 0 : es->inline_hdr_sz = rte_cpu_to_be_16(inlen);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1105 [ # # # # : 0 : es->inline_data = *(unaligned_uint16_t *)psrc;
# # # # #
# # # ]
1106 : 0 : psrc += sizeof(uint16_t);
1107 : 0 : pdst = (uint8_t *)(es + 1);
1108 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
# # # # #
# # # # #
# # # # #
# # # ]
1109 : : /* Implement VLAN tag insertion as part inline data. */
1110 : : memcpy(pdst, psrc, 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t));
1111 : : pdst += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
1112 : : psrc += 2 * RTE_ETHER_ADDR_LEN - sizeof(uint16_t);
1113 : : /* Insert VLAN ethertype + VLAN tag. */
1114 [ # # # # : 0 : *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
# # # # #
# # # # #
# # # # #
# # # ]
1115 : : ((RTE_ETHER_TYPE_VLAN << 16) |
1116 : : loc->mbuf->vlan_tci);
1117 : : pdst += sizeof(struct rte_vlan_hdr);
1118 : : /* Copy the rest two bytes from packet data. */
1119 : : MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, sizeof(uint16_t)));
1120 : 0 : *(uint16_t *)pdst = *(unaligned_uint16_t *)psrc;
1121 : 0 : psrc += sizeof(uint16_t);
1122 : : } else {
1123 : : /* Fill the gap in the title WQEBB with inline data. */
1124 : : rte_mov16(pdst, psrc);
1125 : 0 : psrc += MLX5_SIZE_MOV16;
1126 : : }
1127 : 0 : pdst = (uint8_t *)(es + 2);
1128 : : MLX5_ASSERT(inlen >= MLX5_ESEG_MIN_INLINE_SIZE);
1129 : : MLX5_ASSERT(pdst < (uint8_t *)txq->wqes_end);
1130 : 0 : inlen -= MLX5_ESEG_MIN_INLINE_SIZE;
1131 [ # # # # : 0 : if (!inlen) {
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1132 : : MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
1133 : : return (struct mlx5_wqe_dseg *)pdst;
1134 : : }
1135 : : /*
1136 : : * The WQEBB space availability is checked by caller.
1137 : : * Here we should be aware of WQE ring buffer wraparound only.
1138 : : */
1139 : 0 : part = (uint8_t *)txq->wqes_end - pdst;
1140 : 0 : part = RTE_MIN(part, inlen);
1141 : : do {
1142 [ # # # # : 0 : rte_memcpy(pdst, psrc, part);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1143 : 0 : inlen -= part;
1144 [ # # # # : 0 : if (likely(!inlen)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1145 : : /*
1146 : : * If return value is not used by the caller
1147 : : * the code below will be optimized out.
1148 : : */
1149 : 0 : pdst += part;
1150 : 0 : pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
1151 [ # # # # : 0 : if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1152 : 0 : pdst = (uint8_t *)txq->wqes;
1153 : : return (struct mlx5_wqe_dseg *)pdst;
1154 : : }
1155 : 0 : pdst = (uint8_t *)txq->wqes;
1156 : 0 : psrc += part;
1157 : : part = inlen;
1158 : : } while (true);
1159 : : }
1160 : :
1161 : : /**
1162 : : * Copy data from chain of mbuf to the specified linear buffer.
1163 : : * Checksums and VLAN insertion Tx offload features. If data
1164 : : * from some mbuf copied completely this mbuf is freed. Local
1165 : : * structure is used to keep the byte stream state.
1166 : : *
1167 : : * @param pdst
1168 : : * Pointer to the destination linear buffer.
1169 : : * @param loc
1170 : : * Pointer to burst routine local context.
1171 : : * @param len
1172 : : * Length of data to be copied.
1173 : : * @param must
1174 : : * Length of data to be copied ignoring no inline hint.
1175 : : * @param olx
1176 : : * Configured Tx offloads mask. It is fully defined at
1177 : : * compile time and may be used for optimization.
1178 : : *
1179 : : * @return
1180 : : * Number of actual copied data bytes. This is always greater than or
1181 : : * equal to must parameter and might be lesser than len in no inline
1182 : : * hint flag is encountered.
1183 : : */
1184 : : static __rte_always_inline unsigned int
1185 : : mlx5_tx_mseg_memcpy(uint8_t *pdst,
1186 : : struct mlx5_txq_local *__rte_restrict loc,
1187 : : unsigned int len,
1188 : : unsigned int must,
1189 : : unsigned int olx __rte_unused)
1190 : : {
1191 : : struct rte_mbuf *mbuf;
1192 : : unsigned int part, dlen, copy = 0;
1193 : : uint8_t *psrc;
1194 : :
1195 : : MLX5_ASSERT(len);
1196 : : do {
1197 : : /* Allow zero length packets, must check first. */
1198 : 0 : dlen = rte_pktmbuf_data_len(loc->mbuf);
1199 [ # # # # : 0 : if (dlen <= loc->mbuf_off) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1200 : : /* Exhausted packet, just free. */
1201 : : mbuf = loc->mbuf;
1202 : 0 : loc->mbuf = mbuf->next;
1203 : : rte_pktmbuf_free_seg(mbuf);
1204 : : loc->mbuf_off = 0;
1205 : : MLX5_ASSERT(loc->mbuf_nseg > 1);
1206 : : MLX5_ASSERT(loc->mbuf);
1207 : 0 : --loc->mbuf_nseg;
1208 [ # # # # : 0 : if (loc->mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1209 : : unsigned int diff;
1210 : :
1211 [ # # # # : 0 : if (copy >= must) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1212 : : /*
1213 : : * We already copied the minimal
1214 : : * requested amount of data.
1215 : : */
1216 : : return copy;
1217 : : }
1218 : 0 : diff = must - copy;
1219 [ # # # # : 0 : if (diff <= rte_pktmbuf_data_len(loc->mbuf)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1220 : : /*
1221 : : * Copy only the minimal required
1222 : : * part of the data buffer. Limit amount
1223 : : * of data to be copied to the length of
1224 : : * available space.
1225 : : */
1226 : 0 : len = RTE_MIN(len, diff);
1227 : : }
1228 : : }
1229 : 0 : continue;
1230 : : }
1231 : 0 : dlen -= loc->mbuf_off;
1232 : 0 : psrc = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
1233 : : loc->mbuf_off);
1234 : 0 : part = RTE_MIN(len, dlen);
1235 [ # # # # : 0 : rte_memcpy(pdst, psrc, part);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1236 : 0 : copy += part;
1237 : 0 : loc->mbuf_off += part;
1238 : 0 : len -= part;
1239 [ # # # # : 0 : if (!len) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1240 [ # # # # : 0 : if (loc->mbuf_off >= rte_pktmbuf_data_len(loc->mbuf)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1241 : : loc->mbuf_off = 0;
1242 : : /* Exhausted packet, just free. */
1243 : : mbuf = loc->mbuf;
1244 : 0 : loc->mbuf = mbuf->next;
1245 : : rte_pktmbuf_free_seg(mbuf);
1246 : : loc->mbuf_off = 0;
1247 : : MLX5_ASSERT(loc->mbuf_nseg >= 1);
1248 : 0 : --loc->mbuf_nseg;
1249 : : }
1250 : : return copy;
1251 : : }
1252 : 0 : pdst += part;
1253 : : } while (true);
1254 : : }
1255 : :
1256 : : /**
1257 : : * Build the Ethernet Segment with inlined data from multi-segment packet.
1258 : : * Checks the boundary of WQEBB and ring buffer wrapping, supports Software
1259 : : * Parser, Checksums and VLAN insertion Tx offload features.
1260 : : *
1261 : : * @param txq
1262 : : * Pointer to TX queue structure.
1263 : : * @param loc
1264 : : * Pointer to burst routine local context.
1265 : : * @param wqe
1266 : : * Pointer to WQE to fill with built Ethernet Segment.
1267 : : * @param vlan
1268 : : * Length of VLAN tag insertion if any.
1269 : : * @param inlen
1270 : : * Length of data to inline (VLAN included, if any).
1271 : : * @param tso
1272 : : * TSO flag, set mss field from the packet.
1273 : : * @param olx
1274 : : * Configured Tx offloads mask. It is fully defined at
1275 : : * compile time and may be used for optimization.
1276 : : *
1277 : : * @return
1278 : : * Pointer to the next Data Segment (aligned and possible NOT wrapped
1279 : : * around - caller should do wrapping check on its own).
1280 : : */
1281 : : static __rte_always_inline struct mlx5_wqe_dseg *
1282 : : mlx5_tx_eseg_mdat(struct mlx5_txq_data *__rte_restrict txq,
1283 : : struct mlx5_txq_local *__rte_restrict loc,
1284 : : struct mlx5_wqe *__rte_restrict wqe,
1285 : : unsigned int vlan,
1286 : : unsigned int inlen,
1287 : : unsigned int tso,
1288 : : unsigned int olx)
1289 : : {
1290 : : struct mlx5_wqe_eseg *__rte_restrict es = &wqe->eseg;
1291 : : uint32_t csum;
1292 : : uint8_t *pdst;
1293 : : unsigned int part, tlen = 0;
1294 : :
1295 : : /*
1296 : : * Calculate and set check sum flags first, uint32_t field
1297 : : * in segment may be shared with Software Parser flags.
1298 : : */
1299 : 0 : csum = MLX5_TXOFF_CONFIG(CSUM) ? txq_ol_cksum_to_cs(loc->mbuf) : 0;
1300 : : if (tso) {
1301 : 0 : csum <<= 24;
1302 : 0 : csum |= loc->mbuf->tso_segsz;
1303 [ # # # # : 0 : es->flags = rte_cpu_to_be_32(csum);
# # # # #
# # # # #
# # # # #
# ]
1304 : : } else {
1305 [ # # # # ]: 0 : es->flags = rte_cpu_to_le_32(csum);
1306 : : }
1307 : : /*
1308 : : * Calculate and set Software Parser offsets and flags.
1309 : : * These flags a set for custom UDP and IP tunnel packets.
1310 : : */
1311 : 0 : es->swp_offs = txq_mbuf_to_swp(loc, &es->swp_flags, olx);
1312 : : /* Fill metadata field if needed. */
1313 : 0 : es->metadata = MLX5_TXOFF_CONFIG(METADATA) ?
1314 : 0 : loc->mbuf->ol_flags & RTE_MBUF_DYNFLAG_TX_METADATA ?
1315 [ # # # # : 0 : rte_cpu_to_be_32(*RTE_FLOW_DYNF_METADATA(loc->mbuf)) :
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1316 : : 0 : 0;
1317 : : MLX5_ASSERT(inlen >= MLX5_ESEG_MIN_INLINE_SIZE);
1318 : 0 : pdst = (uint8_t *)&es->inline_data;
1319 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && vlan) {
# # # # #
# # # # #
# # ]
1320 : : /* Implement VLAN tag insertion as part inline data. */
1321 : : mlx5_tx_mseg_memcpy(pdst, loc,
1322 : : 2 * RTE_ETHER_ADDR_LEN,
1323 : : 2 * RTE_ETHER_ADDR_LEN, olx);
1324 : : pdst += 2 * RTE_ETHER_ADDR_LEN;
1325 [ # # # # : 0 : *(unaligned_uint32_t *)pdst = rte_cpu_to_be_32
# # # # #
# # # # #
# # ]
1326 : : ((RTE_ETHER_TYPE_VLAN << 16) |
1327 : : loc->mbuf->vlan_tci);
1328 : 0 : pdst += sizeof(struct rte_vlan_hdr);
1329 : : tlen += 2 * RTE_ETHER_ADDR_LEN + sizeof(struct rte_vlan_hdr);
1330 : : }
1331 : : MLX5_ASSERT(pdst < (uint8_t *)txq->wqes_end);
1332 : : /*
1333 : : * The WQEBB space availability is checked by caller.
1334 : : * Here we should be aware of WQE ring buffer wraparound only.
1335 : : */
1336 : 0 : part = (uint8_t *)txq->wqes_end - pdst;
1337 : 0 : part = RTE_MIN(part, inlen - tlen);
1338 : : MLX5_ASSERT(part);
1339 : 0 : do {
1340 : : unsigned int copy;
1341 : :
1342 : : /*
1343 : : * Copying may be interrupted inside the routine
1344 : : * if run into no inline hint flag.
1345 : : */
1346 : 0 : copy = tso ? inlen : txq->inlen_mode;
1347 [ # # # # : 0 : copy = tlen >= copy ? 0 : (copy - tlen);
# # # # #
# # # # #
# # # # #
# ]
1348 : : copy = mlx5_tx_mseg_memcpy(pdst, loc, part, copy, olx);
1349 : 0 : tlen += copy;
1350 [ # # # # : 0 : if (likely(inlen <= tlen) || copy < part) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1351 [ # # # # : 0 : es->inline_hdr_sz = rte_cpu_to_be_16(tlen);
# # # # #
# # # # #
# # # # #
# ]
1352 : 0 : pdst += copy;
1353 : 0 : pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
1354 : : return (struct mlx5_wqe_dseg *)pdst;
1355 : : }
1356 : 0 : pdst = (uint8_t *)txq->wqes;
1357 : 0 : part = inlen - tlen;
1358 : : } while (true);
1359 : : }
1360 : :
1361 : : /**
1362 : : * Build the Data Segment of pointer type.
1363 : : *
1364 : : * @param txq
1365 : : * Pointer to TX queue structure.
1366 : : * @param loc
1367 : : * Pointer to burst routine local context.
1368 : : * @param dseg
1369 : : * Pointer to WQE to fill with built Data Segment.
1370 : : * @param buf
1371 : : * Data buffer to point.
1372 : : * @param len
1373 : : * Data buffer length.
1374 : : * @param olx
1375 : : * Configured Tx offloads mask. It is fully defined at
1376 : : * compile time and may be used for optimization.
1377 : : */
1378 : : static __rte_always_inline void
1379 : : mlx5_tx_dseg_ptr(struct mlx5_txq_data *__rte_restrict txq,
1380 : : struct mlx5_txq_local *__rte_restrict loc,
1381 : : struct mlx5_wqe_dseg *__rte_restrict dseg,
1382 : : uint8_t *buf,
1383 : : unsigned int len,
1384 : : unsigned int olx __rte_unused)
1385 : :
1386 : : {
1387 : : MLX5_ASSERT(len);
1388 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32(len);
# # # # ]
1389 [ # # # # : 0 : dseg->lkey = mlx5_mr_mb2mr(&txq->mr_ctrl, loc->mbuf);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1390 : 0 : dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
1391 : : }
1392 : :
1393 : : /**
1394 : : * Build the Data Segment of pointer type or inline if data length is less than
1395 : : * buffer in minimal Data Segment size.
1396 : : *
1397 : : * @param txq
1398 : : * Pointer to TX queue structure.
1399 : : * @param loc
1400 : : * Pointer to burst routine local context.
1401 : : * @param dseg
1402 : : * Pointer to WQE to fill with built Data Segment.
1403 : : * @param buf
1404 : : * Data buffer to point.
1405 : : * @param len
1406 : : * Data buffer length.
1407 : : * @param olx
1408 : : * Configured Tx offloads mask. It is fully defined at
1409 : : * compile time and may be used for optimization.
1410 : : */
1411 : : static __rte_always_inline void
1412 : : mlx5_tx_dseg_iptr(struct mlx5_txq_data *__rte_restrict txq,
1413 : : struct mlx5_txq_local *__rte_restrict loc,
1414 : : struct mlx5_wqe_dseg *__rte_restrict dseg,
1415 : : uint8_t *buf,
1416 : : unsigned int len,
1417 : : unsigned int olx __rte_unused)
1418 : :
1419 : : {
1420 : : uintptr_t dst, src;
1421 : :
1422 : : MLX5_ASSERT(len);
1423 [ # # # # : 0 : if (len > MLX5_DSEG_MIN_INLINE_SIZE) {
# # # # #
# # # # #
# # # # #
# ]
1424 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32(len);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1425 [ # # # # : 0 : dseg->lkey = mlx5_mr_mb2mr(&txq->mr_ctrl, loc->mbuf);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1426 : 0 : dseg->pbuf = rte_cpu_to_be_64((uintptr_t)buf);
1427 : :
1428 : 0 : return;
1429 : : }
1430 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1431 : : /* Unrolled implementation of generic rte_memcpy. */
1432 : 0 : dst = (uintptr_t)&dseg->inline_data[0];
1433 : 0 : src = (uintptr_t)buf;
1434 [ # # # # : 0 : if (len & 0x08) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1435 : : #ifdef RTE_ARCH_STRICT_ALIGN
1436 : : MLX5_ASSERT(dst == RTE_PTR_ALIGN(dst, sizeof(uint32_t)));
1437 : : *(uint32_t *)dst = *(unaligned_uint32_t *)src;
1438 : : dst += sizeof(uint32_t);
1439 : : src += sizeof(uint32_t);
1440 : : *(uint32_t *)dst = *(unaligned_uint32_t *)src;
1441 : : dst += sizeof(uint32_t);
1442 : : src += sizeof(uint32_t);
1443 : : #else
1444 : 0 : *(uint64_t *)dst = *(unaligned_uint64_t *)src;
1445 : 0 : dst += sizeof(uint64_t);
1446 : 0 : src += sizeof(uint64_t);
1447 : : #endif
1448 : : }
1449 [ # # # # : 0 : if (len & 0x04) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1450 : 0 : *(uint32_t *)dst = *(unaligned_uint32_t *)src;
1451 : 0 : dst += sizeof(uint32_t);
1452 : 0 : src += sizeof(uint32_t);
1453 : : }
1454 [ # # # # : 0 : if (len & 0x02) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1455 : 0 : *(uint16_t *)dst = *(unaligned_uint16_t *)src;
1456 : 0 : dst += sizeof(uint16_t);
1457 : 0 : src += sizeof(uint16_t);
1458 : : }
1459 [ # # # # : 0 : if (len & 0x01)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1460 : 0 : *(uint8_t *)dst = *(uint8_t *)src;
1461 : : }
1462 : :
1463 : : /**
1464 : : * Build the Data Segment of inlined data from single
1465 : : * segment packet, no VLAN insertion.
1466 : : *
1467 : : * @param txq
1468 : : * Pointer to TX queue structure.
1469 : : * @param loc
1470 : : * Pointer to burst routine local context.
1471 : : * @param dseg
1472 : : * Pointer to WQE to fill with built Data Segment.
1473 : : * @param buf
1474 : : * Data buffer to point.
1475 : : * @param len
1476 : : * Data buffer length.
1477 : : * @param olx
1478 : : * Configured Tx offloads mask. It is fully defined at
1479 : : * compile time and may be used for optimization.
1480 : : *
1481 : : * @return
1482 : : * Pointer to the next Data Segment after inlined data.
1483 : : * Ring buffer wraparound check is needed. We do not do it here because it
1484 : : * may not be needed for the last packet in the eMPW session.
1485 : : */
1486 : : static __rte_always_inline struct mlx5_wqe_dseg *
1487 : : mlx5_tx_dseg_empw(struct mlx5_txq_data *__rte_restrict txq,
1488 : : struct mlx5_txq_local *__rte_restrict loc __rte_unused,
1489 : : struct mlx5_wqe_dseg *__rte_restrict dseg,
1490 : : uint8_t *buf,
1491 : : unsigned int len,
1492 : : unsigned int olx __rte_unused)
1493 : : {
1494 : : unsigned int part;
1495 : : uint8_t *pdst;
1496 : :
1497 : : if (!MLX5_TXOFF_CONFIG(MPW)) {
1498 : : /* Store the descriptor byte counter for eMPW sessions. */
1499 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
# # # # #
# # # #
# ]
1500 : 0 : pdst = &dseg->inline_data[0];
1501 : : } else {
1502 : : /* The entire legacy MPW session counter is stored on close. */
1503 : : pdst = (uint8_t *)dseg;
1504 : : }
1505 : : /*
1506 : : * The WQEBB space availability is checked by caller.
1507 : : * Here we should be aware of WQE ring buffer wraparound only.
1508 : : */
1509 : 0 : part = (uint8_t *)txq->wqes_end - pdst;
1510 : 0 : part = RTE_MIN(part, len);
1511 : : do {
1512 [ # # # # : 0 : rte_memcpy(pdst, buf, part);
# # # # #
# # # #
# ]
1513 : 0 : len -= part;
1514 [ # # # # : 0 : if (likely(!len)) {
# # # # #
# # # #
# ]
1515 : 0 : pdst += part;
1516 : : if (!MLX5_TXOFF_CONFIG(MPW))
1517 : 0 : pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
1518 : : /* Note: no final wraparound check here. */
1519 : : return (struct mlx5_wqe_dseg *)pdst;
1520 : : }
1521 : 0 : pdst = (uint8_t *)txq->wqes;
1522 : 0 : buf += part;
1523 : : part = len;
1524 : : } while (true);
1525 : : }
1526 : :
1527 : : /**
1528 : : * Build the Data Segment of inlined data from single
1529 : : * segment packet with VLAN insertion.
1530 : : *
1531 : : * @param txq
1532 : : * Pointer to TX queue structure.
1533 : : * @param loc
1534 : : * Pointer to burst routine local context.
1535 : : * @param dseg
1536 : : * Pointer to the dseg fill with built Data Segment.
1537 : : * @param buf
1538 : : * Data buffer to point.
1539 : : * @param len
1540 : : * Data buffer length.
1541 : : * @param olx
1542 : : * Configured Tx offloads mask. It is fully defined at
1543 : : * compile time and may be used for optimization.
1544 : : *
1545 : : * @return
1546 : : * Pointer to the next Data Segment after inlined data.
1547 : : * Ring buffer wraparound check is needed.
1548 : : */
1549 : : static __rte_always_inline struct mlx5_wqe_dseg *
1550 : : mlx5_tx_dseg_vlan(struct mlx5_txq_data *__rte_restrict txq,
1551 : : struct mlx5_txq_local *__rte_restrict loc __rte_unused,
1552 : : struct mlx5_wqe_dseg *__rte_restrict dseg,
1553 : : uint8_t *buf,
1554 : : unsigned int len,
1555 : : unsigned int olx __rte_unused)
1556 : :
1557 : : {
1558 : : unsigned int part;
1559 : : uint8_t *pdst;
1560 : :
1561 : : MLX5_ASSERT(len > MLX5_ESEG_MIN_INLINE_SIZE);
1562 : : if (!MLX5_TXOFF_CONFIG(MPW)) {
1563 : : /* Store the descriptor byte counter for eMPW sessions. */
1564 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32
# # # # ]
1565 : : ((len + sizeof(struct rte_vlan_hdr)) |
1566 : : MLX5_ETH_WQE_DATA_INLINE);
1567 [ # # # # : 0 : pdst = &dseg->inline_data[0];
# # # # ]
1568 : : } else {
1569 : : /* The entire legacy MPW session counter is stored on close. */
1570 : : pdst = (uint8_t *)dseg;
1571 : : }
1572 : : memcpy(pdst, buf, MLX5_DSEG_MIN_INLINE_SIZE);
1573 : 0 : buf += MLX5_DSEG_MIN_INLINE_SIZE;
1574 : 0 : pdst += MLX5_DSEG_MIN_INLINE_SIZE;
1575 : 0 : len -= MLX5_DSEG_MIN_INLINE_SIZE;
1576 : : /* Insert VLAN ethertype + VLAN tag. Pointer is aligned. */
1577 : : MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
1578 [ # # # # : 0 : if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
# # # # ]
1579 : 0 : pdst = (uint8_t *)txq->wqes;
1580 [ # # # # : 0 : *(uint32_t *)pdst = rte_cpu_to_be_32((RTE_ETHER_TYPE_VLAN << 16) |
# # # # ]
1581 : : loc->mbuf->vlan_tci);
1582 : 0 : pdst += sizeof(struct rte_vlan_hdr);
1583 : : /*
1584 : : * The WQEBB space availability is checked by caller.
1585 : : * Here we should be aware of WQE ring buffer wraparound only.
1586 : : */
1587 : 0 : part = (uint8_t *)txq->wqes_end - pdst;
1588 : 0 : part = RTE_MIN(part, len);
1589 : : do {
1590 [ # # # # : 0 : rte_memcpy(pdst, buf, part);
# # # # ]
1591 : 0 : len -= part;
1592 [ # # # # : 0 : if (likely(!len)) {
# # # # ]
1593 : 0 : pdst += part;
1594 : : if (!MLX5_TXOFF_CONFIG(MPW))
1595 : 0 : pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
1596 : : /* Note: no final wraparound check here. */
1597 : : return (struct mlx5_wqe_dseg *)pdst;
1598 : : }
1599 : 0 : pdst = (uint8_t *)txq->wqes;
1600 : 0 : buf += part;
1601 : : part = len;
1602 : : } while (true);
1603 : : }
1604 : :
1605 : : /**
1606 : : * Build the Ethernet Segment with optionally inlined data with
1607 : : * VLAN insertion and following Data Segments (if any) from
1608 : : * multi-segment packet. Used by ordinary send and TSO.
1609 : : *
1610 : : * @param txq
1611 : : * Pointer to TX queue structure.
1612 : : * @param loc
1613 : : * Pointer to burst routine local context.
1614 : : * @param wqe
1615 : : * Pointer to WQE to fill with built Ethernet/Data Segments.
1616 : : * @param vlan
1617 : : * Length of VLAN header to insert, 0 means no VLAN insertion.
1618 : : * @param inlen
1619 : : * Data length to inline. For TSO this parameter specifies exact value,
1620 : : * for ordinary send routine can be aligned by caller to provide better WQE
1621 : : * space saving and data buffer start address alignment.
1622 : : * This length includes VLAN header being inserted.
1623 : : * @param tso
1624 : : * Zero means ordinary send, inlined data can be extended,
1625 : : * otherwise this is TSO, inlined data length is fixed.
1626 : : * @param olx
1627 : : * Configured Tx offloads mask. It is fully defined at
1628 : : * compile time and may be used for optimization.
1629 : : *
1630 : : * @return
1631 : : * Actual size of built WQE in segments.
1632 : : */
1633 : : static __rte_always_inline unsigned int
1634 : : mlx5_tx_mseg_build(struct mlx5_txq_data *__rte_restrict txq,
1635 : : struct mlx5_txq_local *__rte_restrict loc,
1636 : : struct mlx5_wqe *__rte_restrict wqe,
1637 : : unsigned int vlan,
1638 : : unsigned int inlen,
1639 : : unsigned int tso,
1640 : : unsigned int olx __rte_unused)
1641 : : {
1642 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
1643 : : unsigned int ds;
1644 : :
1645 : : MLX5_ASSERT((rte_pktmbuf_pkt_len(loc->mbuf) + vlan) >= inlen);
1646 : : loc->mbuf_nseg = NB_SEGS(loc->mbuf);
1647 : : loc->mbuf_off = 0;
1648 : :
1649 : : dseg = mlx5_tx_eseg_mdat(txq, loc, wqe, vlan, inlen, tso, olx);
1650 [ # # # # : 0 : if (!loc->mbuf_nseg)
# # # # #
# # # # #
# # # # #
# ]
1651 : 0 : goto dseg_done;
1652 : : /*
1653 : : * There are still some mbuf remaining, not inlined.
1654 : : * The first mbuf may be partially inlined and we
1655 : : * must process the possible non-zero data offset.
1656 : : */
1657 [ # # # # : 0 : if (loc->mbuf_off) {
# # # # #
# # # # #
# # # # #
# ]
1658 : : unsigned int dlen;
1659 : : uint8_t *dptr;
1660 : :
1661 : : /*
1662 : : * Exhausted packets must be dropped before.
1663 : : * Non-zero offset means there are some data
1664 : : * remained in the packet.
1665 : : */
1666 : : MLX5_ASSERT(loc->mbuf_off < rte_pktmbuf_data_len(loc->mbuf));
1667 : : MLX5_ASSERT(rte_pktmbuf_data_len(loc->mbuf));
1668 : 0 : dptr = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
1669 : : loc->mbuf_off);
1670 : 0 : dlen = rte_pktmbuf_data_len(loc->mbuf) - loc->mbuf_off;
1671 : : /*
1672 : : * Build the pointer/minimal Data Segment.
1673 : : * Do ring buffer wrapping check in advance.
1674 : : */
1675 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # # #
# # # # #
# ]
1676 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
1677 : : mlx5_tx_dseg_iptr(txq, loc, dseg, dptr, dlen, olx);
1678 : : /* Store the mbuf to be freed on completion. */
1679 : : MLX5_ASSERT(loc->elts_free);
1680 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
1681 : 0 : --loc->elts_free;
1682 : 0 : ++dseg;
1683 [ # # # # : 0 : if (--loc->mbuf_nseg == 0)
# # # # #
# # # # #
# # # # #
# ]
1684 : 0 : goto dseg_done;
1685 : 0 : loc->mbuf = loc->mbuf->next;
1686 : : loc->mbuf_off = 0;
1687 : : }
1688 : : do {
1689 [ # # # # : 0 : if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
# # # # #
# # # # #
# # # # #
# ]
1690 : : struct rte_mbuf *mbuf;
1691 : :
1692 : : /* Zero length segment found, just skip. */
1693 : : mbuf = loc->mbuf;
1694 : 0 : loc->mbuf = loc->mbuf->next;
1695 : : rte_pktmbuf_free_seg(mbuf);
1696 [ # # # # : 0 : if (--loc->mbuf_nseg == 0)
# # # # #
# # # # #
# # # # #
# ]
1697 : : break;
1698 : : } else {
1699 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # # #
# # # # #
# ]
1700 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
1701 : 0 : mlx5_tx_dseg_iptr
1702 : : (txq, loc, dseg,
1703 [ # # # # : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
# # # # #
# # # # #
# # # # #
# ]
1704 : : rte_pktmbuf_data_len(loc->mbuf), olx);
1705 : : MLX5_ASSERT(loc->elts_free);
1706 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
1707 : 0 : --loc->elts_free;
1708 : 0 : ++dseg;
1709 [ # # # # : 0 : if (--loc->mbuf_nseg == 0)
# # # # #
# # # # #
# # # # #
# ]
1710 : : break;
1711 : 0 : loc->mbuf = loc->mbuf->next;
1712 : : }
1713 : : } while (true);
1714 : :
1715 : 0 : dseg_done:
1716 : : /* Calculate actual segments used from the dseg pointer. */
1717 [ # # # # : 0 : if ((uintptr_t)wqe < (uintptr_t)dseg)
# # # # #
# # # # #
# # # # #
# ]
1718 : 0 : ds = ((uintptr_t)dseg - (uintptr_t)wqe) / MLX5_WSEG_SIZE;
1719 : : else
1720 : 0 : ds = (((uintptr_t)dseg - (uintptr_t)wqe) +
1721 : 0 : txq->wqe_s * MLX5_WQE_SIZE) / MLX5_WSEG_SIZE;
1722 : : return ds;
1723 : : }
1724 : :
1725 : : /**
1726 : : * The routine checks timestamp flag in the current packet,
1727 : : * and push WAIT WQE into the queue if scheduling is required.
1728 : : *
1729 : : * @param txq
1730 : : * Pointer to TX queue structure.
1731 : : * @param loc
1732 : : * Pointer to burst routine local context.
1733 : : * @param elts
1734 : : * Number of free elements in elts buffer to be checked, for zero
1735 : : * value the check is optimized out by compiler.
1736 : : * @param olx
1737 : : * Configured Tx offloads mask. It is fully defined at
1738 : : * compile time and may be used for optimization.
1739 : : *
1740 : : * @return
1741 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
1742 : : * MLX5_TXCMP_CODE_SINGLE - continue processing with the packet.
1743 : : * MLX5_TXCMP_CODE_MULTI - the WAIT inserted, continue processing.
1744 : : * Local context variables partially updated.
1745 : : */
1746 : : static __rte_always_inline enum mlx5_txcmp_code
1747 : : mlx5_tx_schedule_send(struct mlx5_txq_data *restrict txq,
1748 : : struct mlx5_txq_local *restrict loc,
1749 : : uint16_t elts,
1750 : : unsigned int olx)
1751 : : {
1752 : 0 : if (MLX5_TXOFF_CONFIG(TXPP) &&
1753 [ # # # # : 0 : loc->mbuf->ol_flags & txq->ts_mask) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1754 : : struct mlx5_dev_ctx_shared *sh;
1755 : : struct mlx5_wqe *wqe;
1756 : : uint64_t ts;
1757 : :
1758 : : /*
1759 : : * Estimate the required space quickly and roughly.
1760 : : * We would like to ensure the packet can be pushed
1761 : : * to the queue and we won't get the orphan WAIT WQE.
1762 : : */
1763 [ # # # # : 0 : if (loc->wqe_free <= MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1764 : : loc->elts_free < elts)
1765 : : return MLX5_TXCMP_CODE_EXIT;
1766 : : /* Convert the timestamp into completion to wait. */
1767 : 0 : ts = *RTE_MBUF_DYNFIELD(loc->mbuf, txq->ts_offset, uint64_t *);
1768 [ # # # # : 0 : if (txq->ts_last && ts < txq->ts_last)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1769 : 0 : rte_atomic_fetch_add_explicit(&txq->sh->txpp.err_ts_order,
1770 : : 1, rte_memory_order_relaxed);
1771 : 0 : txq->ts_last = ts;
1772 : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
1773 : 0 : sh = txq->sh;
1774 [ # # # # : 0 : if (txq->wait_on_time) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1775 : : /* The wait on time capability should be used. */
1776 [ # # # # : 0 : ts -= sh->txpp.skew;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1777 : : rte_pmd_mlx5_trace_tx_wait(ts);
1778 : : mlx5_tx_cseg_init(txq, loc, wqe,
1779 : : 1 + sizeof(struct mlx5_wqe_wseg) /
1780 : : MLX5_WSEG_SIZE,
1781 : : MLX5_OPCODE_WAIT |
1782 : : MLX5_OPC_MOD_WAIT_TIME << 24, olx);
1783 : : mlx5_tx_wseg_init(txq, loc, wqe, ts, olx);
1784 : : } else {
1785 : : /* Legacy cross-channel operation should be used. */
1786 : : int32_t wci;
1787 : :
1788 : : wci = mlx5_txpp_convert_tx_ts(sh, ts);
1789 [ # # # # : 0 : if (unlikely(wci < 0))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1790 : : return MLX5_TXCMP_CODE_SINGLE;
1791 : : /* Build the WAIT WQE with specified completion. */
1792 : : rte_pmd_mlx5_trace_tx_wait(ts - sh->txpp.skew);
1793 : : mlx5_tx_cseg_init(txq, loc, wqe,
1794 : : 1 + sizeof(struct mlx5_wqe_qseg) /
1795 : : MLX5_WSEG_SIZE,
1796 : : MLX5_OPCODE_WAIT |
1797 : : MLX5_OPC_MOD_WAIT_CQ_PI << 24, olx);
1798 [ # # # # : 0 : mlx5_tx_qseg_init(txq, loc, wqe, wci, olx);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1799 : : }
1800 : 0 : ++txq->wqe_ci;
1801 : 0 : --loc->wqe_free;
1802 : : return MLX5_TXCMP_CODE_MULTI;
1803 : : }
1804 : : return MLX5_TXCMP_CODE_SINGLE;
1805 : : }
1806 : :
1807 : : /**
1808 : : * Tx one packet function for multi-segment TSO. Supports all
1809 : : * types of Tx offloads, uses MLX5_OPCODE_TSO to build WQEs,
1810 : : * sends one packet per WQE.
1811 : : *
1812 : : * This routine is responsible for storing processed mbuf
1813 : : * into elts ring buffer and update elts_head.
1814 : : *
1815 : : * @param txq
1816 : : * Pointer to TX queue structure.
1817 : : * @param loc
1818 : : * Pointer to burst routine local context.
1819 : : * @param olx
1820 : : * Configured Tx offloads mask. It is fully defined at
1821 : : * compile time and may be used for optimization.
1822 : : *
1823 : : * @return
1824 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
1825 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
1826 : : * Local context variables partially updated.
1827 : : */
1828 : : static __rte_always_inline enum mlx5_txcmp_code
1829 : : mlx5_tx_packet_multi_tso(struct mlx5_txq_data *__rte_restrict txq,
1830 : : struct mlx5_txq_local *__rte_restrict loc,
1831 : : unsigned int olx)
1832 : : {
1833 : : struct mlx5_wqe *__rte_restrict wqe;
1834 : : unsigned int ds, dlen, inlen, ntcp, vlan = 0;
1835 : :
1836 : : MLX5_ASSERT(loc->elts_free >= NB_SEGS(loc->mbuf));
1837 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
1838 : : enum mlx5_txcmp_code wret;
1839 : :
1840 : : /* Generate WAIT for scheduling if requested. */
1841 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
1842 : : if (wret == MLX5_TXCMP_CODE_EXIT)
1843 : : return MLX5_TXCMP_CODE_EXIT;
1844 : : if (wret == MLX5_TXCMP_CODE_ERROR)
1845 : : return MLX5_TXCMP_CODE_ERROR;
1846 : : }
1847 : : /*
1848 : : * Calculate data length to be inlined to estimate
1849 : : * the required space in WQE ring buffer.
1850 : : */
1851 : 0 : dlen = rte_pktmbuf_pkt_len(loc->mbuf);
1852 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # # # #
# ]
1853 : : vlan = sizeof(struct rte_vlan_hdr);
1854 : 0 : inlen = loc->mbuf->l2_len + vlan +
1855 : 0 : loc->mbuf->l3_len + loc->mbuf->l4_len;
1856 [ # # # # : 0 : if (unlikely((!inlen || !loc->mbuf->tso_segsz)))
# # # # #
# # # # #
# # # # #
# # # #
# ]
1857 : : return MLX5_TXCMP_CODE_ERROR;
1858 [ # # # # : 0 : if (loc->mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
# # # # #
# # # ]
1859 : 0 : inlen += loc->mbuf->outer_l2_len + loc->mbuf->outer_l3_len;
1860 : : /* Packet must contain all TSO headers. */
1861 [ # # # # : 0 : if (unlikely(inlen > MLX5_MAX_TSO_HEADER ||
# # # # #
# # # # #
# # # # #
# # # #
# ]
1862 : : inlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
1863 : : inlen > (dlen + vlan)))
1864 : : return MLX5_TXCMP_CODE_ERROR;
1865 : : /*
1866 : : * Check whether there are enough free WQEBBs:
1867 : : * - Control Segment
1868 : : * - Ethernet Segment
1869 : : * - First Segment of inlined Ethernet data
1870 : : * - ... data continued ...
1871 : : * - Data Segments of pointer/min inline type
1872 : : */
1873 : 0 : ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
1874 : : MLX5_ESEG_MIN_INLINE_SIZE +
1875 : : MLX5_WSEG_SIZE +
1876 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
1877 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
# # # # #
# # # ]
1878 : : return MLX5_TXCMP_CODE_EXIT;
1879 : : /* Check for maximal WQE size. */
1880 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds))
# # # # #
# # # ]
1881 : : return MLX5_TXCMP_CODE_ERROR;
1882 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1883 : : /* Update sent data bytes/packets counters. */
1884 : 0 : ntcp = (dlen - (inlen - vlan) + loc->mbuf->tso_segsz - 1) /
1885 : : loc->mbuf->tso_segsz;
1886 : : /*
1887 : : * One will be added for mbuf itself at the end of the mlx5_tx_burst
1888 : : * from loc->pkts_sent field.
1889 : : */
1890 : 0 : --ntcp;
1891 : 0 : txq->stats.opackets += ntcp;
1892 : 0 : txq->stats.obytes += dlen + vlan + ntcp * inlen;
1893 : : #endif
1894 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # ]
1895 : : loc->wqe_last = wqe;
1896 : : mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_TSO, olx);
1897 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
1898 : : ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 1, olx);
1899 [ # # # # : 0 : wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
# # # # #
# # # ]
1900 : 0 : txq->wqe_ci += (ds + 3) / 4;
1901 : 0 : loc->wqe_free -= (ds + 3) / 4;
1902 : : return MLX5_TXCMP_CODE_MULTI;
1903 : : }
1904 : :
1905 : : /**
1906 : : * Tx one packet function for multi-segment SEND. Supports all types of Tx
1907 : : * offloads, uses MLX5_OPCODE_SEND to build WQEs, sends one packet per WQE,
1908 : : * without any data inlining in Ethernet Segment.
1909 : : *
1910 : : * This routine is responsible for storing processed mbuf
1911 : : * into elts ring buffer and update elts_head.
1912 : : *
1913 : : * @param txq
1914 : : * Pointer to TX queue structure.
1915 : : * @param loc
1916 : : * Pointer to burst routine local context.
1917 : : * @param olx
1918 : : * Configured Tx offloads mask. It is fully defined at
1919 : : * compile time and may be used for optimization.
1920 : : *
1921 : : * @return
1922 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
1923 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
1924 : : * Local context variables partially updated.
1925 : : */
1926 : : static __rte_always_inline enum mlx5_txcmp_code
1927 : : mlx5_tx_packet_multi_send(struct mlx5_txq_data *__rte_restrict txq,
1928 : : struct mlx5_txq_local *__rte_restrict loc,
1929 : : unsigned int olx)
1930 : : {
1931 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
1932 : : struct mlx5_wqe *__rte_restrict wqe;
1933 : : unsigned int ds, nseg;
1934 : :
1935 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
1936 : : MLX5_ASSERT(loc->elts_free >= NB_SEGS(loc->mbuf));
1937 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
1938 : : enum mlx5_txcmp_code wret;
1939 : :
1940 : : /* Generate WAIT for scheduling if requested. */
1941 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
1942 : : if (wret == MLX5_TXCMP_CODE_EXIT)
1943 : : return MLX5_TXCMP_CODE_EXIT;
1944 : : if (wret == MLX5_TXCMP_CODE_ERROR)
1945 : : return MLX5_TXCMP_CODE_ERROR;
1946 : : }
1947 : : /*
1948 : : * No inline at all, it means the CPU cycles saving is prioritized at
1949 : : * configuration, we should not copy any packet data to WQE.
1950 : : */
1951 : 0 : nseg = NB_SEGS(loc->mbuf);
1952 : 0 : ds = 2 + nseg;
1953 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
# # # # #
# # # ]
1954 : : return MLX5_TXCMP_CODE_EXIT;
1955 : : /* Check for maximal WQE size. */
1956 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds))
# # # # #
# # # ]
1957 : : return MLX5_TXCMP_CODE_ERROR;
1958 : : /*
1959 : : * Some Tx offloads may cause an error if packet is not long enough,
1960 : : * check against assumed minimal length.
1961 : : */
1962 [ # # # # : 0 : if (rte_pktmbuf_pkt_len(loc->mbuf) <= MLX5_ESEG_MIN_INLINE_SIZE)
# # # # #
# # # ]
1963 : : return MLX5_TXCMP_CODE_ERROR;
1964 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1965 : : /* Update sent data bytes counter. */
1966 : 0 : txq->stats.obytes += rte_pktmbuf_pkt_len(loc->mbuf);
1967 [ # # # # ]: 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
1968 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # # # #
# ]
1969 : 0 : txq->stats.obytes += sizeof(struct rte_vlan_hdr);
1970 : : #endif
1971 : : /*
1972 : : * SEND WQE, one WQEBB:
1973 : : * - Control Segment, SEND opcode
1974 : : * - Ethernet Segment, optional VLAN, no inline
1975 : : * - Data Segments, pointer only type
1976 : : */
1977 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # ]
1978 : : loc->wqe_last = wqe;
1979 : : mlx5_tx_cseg_init(txq, loc, wqe, ds, MLX5_OPCODE_SEND, olx);
1980 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
1981 : : mlx5_tx_eseg_none(txq, loc, wqe, olx);
1982 : 0 : dseg = &wqe->dseg[0];
1983 : : do {
1984 [ # # # # : 0 : if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
# # # # #
# # # ]
1985 : : struct rte_mbuf *mbuf;
1986 : :
1987 : : /*
1988 : : * Zero length segment found, have to correct total
1989 : : * size of WQE in segments.
1990 : : * It is supposed to be rare occasion, so in normal
1991 : : * case (no zero length segments) we avoid extra
1992 : : * writing to the Control Segment.
1993 : : */
1994 : 0 : --ds;
1995 : 0 : wqe->cseg.sq_ds -= RTE_BE32(1);
1996 : : mbuf = loc->mbuf;
1997 [ # # ]: 0 : loc->mbuf = mbuf->next;
1998 : : rte_pktmbuf_free_seg(mbuf);
1999 [ # # # # : 0 : if (--nseg == 0)
# # # # #
# # # ]
2000 : : break;
2001 : : } else {
2002 : 0 : mlx5_tx_dseg_ptr
2003 : : (txq, loc, dseg,
2004 [ # # # # : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
# # # # #
# # # ]
2005 : : rte_pktmbuf_data_len(loc->mbuf), olx);
2006 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2007 : 0 : --loc->elts_free;
2008 [ # # # # : 0 : if (--nseg == 0)
# # # # #
# # # ]
2009 : : break;
2010 : 0 : ++dseg;
2011 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # ]
2012 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2013 : 0 : loc->mbuf = loc->mbuf->next;
2014 : : }
2015 : : } while (true);
2016 : 0 : txq->wqe_ci += (ds + 3) / 4;
2017 : 0 : loc->wqe_free -= (ds + 3) / 4;
2018 : : return MLX5_TXCMP_CODE_MULTI;
2019 : : }
2020 : :
2021 : : /**
2022 : : * Tx one packet function for multi-segment SEND. Supports all
2023 : : * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
2024 : : * sends one packet per WQE, with data inlining in
2025 : : * Ethernet Segment and minimal Data Segments.
2026 : : *
2027 : : * This routine is responsible for storing processed mbuf
2028 : : * into elts ring buffer and update elts_head.
2029 : : *
2030 : : * @param txq
2031 : : * Pointer to TX queue structure.
2032 : : * @param loc
2033 : : * Pointer to burst routine local context.
2034 : : * @param olx
2035 : : * Configured Tx offloads mask. It is fully defined at
2036 : : * compile time and may be used for optimization.
2037 : : *
2038 : : * @return
2039 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2040 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2041 : : * Local context variables partially updated.
2042 : : */
2043 : : static __rte_always_inline enum mlx5_txcmp_code
2044 : : mlx5_tx_packet_multi_inline(struct mlx5_txq_data *__rte_restrict txq,
2045 : : struct mlx5_txq_local *__rte_restrict loc,
2046 : : unsigned int olx)
2047 : : {
2048 : : struct mlx5_wqe *__rte_restrict wqe;
2049 : : unsigned int ds, inlen, dlen, vlan = 0;
2050 : :
2051 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
2052 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
2053 : : MLX5_ASSERT(loc->elts_free >= NB_SEGS(loc->mbuf));
2054 : : /*
2055 : : * First calculate data length to be inlined
2056 : : * to estimate the required space for WQE.
2057 : : */
2058 : 0 : dlen = rte_pktmbuf_pkt_len(loc->mbuf);
2059 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # ]
2060 : : vlan = sizeof(struct rte_vlan_hdr);
2061 : 0 : inlen = dlen + vlan;
2062 : : /* Check against minimal length. */
2063 [ # # # # : 0 : if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
# # # # ]
2064 : : return MLX5_TXCMP_CODE_ERROR;
2065 : : MLX5_ASSERT(txq->inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
2066 [ # # # # : 0 : if (inlen > txq->inlen_send ||
# # # # ]
2067 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE) {
# # # # ]
2068 : : struct rte_mbuf *mbuf;
2069 : : unsigned int nxlen;
2070 : : uintptr_t start;
2071 : :
2072 : : mbuf = loc->mbuf;
2073 : 0 : nxlen = rte_pktmbuf_data_len(mbuf) + vlan;
2074 : : /*
2075 : : * Packet length exceeds the allowed inline data length,
2076 : : * check whether the minimal inlining is required.
2077 : : */
2078 [ # # # # : 0 : if (txq->inlen_mode) {
# # # # ]
2079 : : MLX5_ASSERT(txq->inlen_mode >=
2080 : : MLX5_ESEG_MIN_INLINE_SIZE);
2081 : : MLX5_ASSERT(txq->inlen_mode <= txq->inlen_send);
2082 : 0 : inlen = RTE_MIN(txq->inlen_mode, inlen);
2083 [ # # # # : 0 : } else if (vlan && !txq->vlan_en) {
# # # # #
# # # ]
2084 : : /*
2085 : : * VLAN insertion is requested and hardware does not
2086 : : * support the offload, will do with software inline.
2087 : : */
2088 : : inlen = MLX5_ESEG_MIN_INLINE_SIZE;
2089 [ # # # # : 0 : } else if (mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE ||
# # # # #
# # # # #
# # ]
2090 : : nxlen > txq->inlen_send) {
2091 : : return mlx5_tx_packet_multi_send(txq, loc, olx);
2092 [ # # # # : 0 : } else if (nxlen <= MLX5_ESEG_MIN_INLINE_SIZE) {
# # # # ]
2093 : : inlen = MLX5_ESEG_MIN_INLINE_SIZE;
2094 : : } else {
2095 : 0 : goto do_first;
2096 : : }
2097 [ # # # # : 0 : if (mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE)
# # # # ]
2098 : 0 : goto do_build;
2099 : : /*
2100 : : * Now we know the minimal amount of data is requested
2101 : : * to inline. Check whether we should inline the buffers
2102 : : * from the chain beginning to eliminate some mbufs.
2103 : : */
2104 [ # # # # : 0 : if (unlikely(nxlen <= txq->inlen_send)) {
# # # # ]
2105 : : /* We can inline first mbuf at least. */
2106 [ # # # # : 0 : if (nxlen < inlen) {
# # # # ]
2107 : : unsigned int smlen;
2108 : :
2109 : : /* Scan mbufs till inlen filled. */
2110 : : do {
2111 : : smlen = nxlen;
2112 : 0 : mbuf = NEXT(mbuf);
2113 : : MLX5_ASSERT(mbuf);
2114 : 0 : nxlen = rte_pktmbuf_data_len(mbuf);
2115 : 0 : nxlen += smlen;
2116 [ # # # # : 0 : } while (unlikely(nxlen < inlen));
# # # # ]
2117 [ # # # # : 0 : if (unlikely(nxlen > txq->inlen_send)) {
# # # # ]
2118 : : /* We cannot inline entire mbuf. */
2119 : 0 : smlen = inlen - smlen;
2120 : 0 : start = rte_pktmbuf_mtod_offset
2121 : : (mbuf, uintptr_t, smlen);
2122 : 0 : goto do_align;
2123 : : }
2124 : : }
2125 : 0 : do_first:
2126 : : do {
2127 : : inlen = nxlen;
2128 : 0 : mbuf = NEXT(mbuf);
2129 : : /* There should be not end of packet. */
2130 : : MLX5_ASSERT(mbuf);
2131 [ # # # # : 0 : if (mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE)
# # # # ]
2132 : : break;
2133 : 0 : nxlen = inlen + rte_pktmbuf_data_len(mbuf);
2134 [ # # # # : 0 : } while (unlikely(nxlen < txq->inlen_send));
# # # # ]
2135 : : }
2136 : 0 : start = rte_pktmbuf_mtod(mbuf, uintptr_t);
2137 : : /*
2138 : : * Check whether we can do inline to align start
2139 : : * address of data buffer to cacheline.
2140 : : */
2141 : 0 : do_align:
2142 : 0 : start = (~start + 1) & (RTE_CACHE_LINE_SIZE - 1);
2143 [ # # # # : 0 : if (unlikely(start)) {
# # # # ]
2144 : 0 : start += inlen;
2145 [ # # # # : 0 : if (start <= txq->inlen_send)
# # # # ]
2146 : 0 : inlen = start;
2147 : : }
2148 : : }
2149 : : /*
2150 : : * Check whether there are enough free WQEBBs:
2151 : : * - Control Segment
2152 : : * - Ethernet Segment
2153 : : * - First Segment of inlined Ethernet data
2154 : : * - ... data continued ...
2155 : : * - Data Segments of pointer/min inline type
2156 : : *
2157 : : * Estimate the number of Data Segments conservatively,
2158 : : * supposing no any mbufs is being freed during inlining.
2159 : : */
2160 [ # # # # : 0 : do_build:
# # # # ]
2161 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2162 : : enum mlx5_txcmp_code wret;
2163 : :
2164 : : /* Generate WAIT for scheduling if requested. */
2165 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
2166 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2167 : : return MLX5_TXCMP_CODE_EXIT;
2168 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2169 : : return MLX5_TXCMP_CODE_ERROR;
2170 : : }
2171 : : MLX5_ASSERT(inlen <= txq->inlen_send);
2172 : 0 : ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
2173 : : MLX5_ESEG_MIN_INLINE_SIZE +
2174 : : MLX5_WSEG_SIZE +
2175 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
2176 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
# # # # ]
2177 : : return MLX5_TXCMP_CODE_EXIT;
2178 : : /* Check for maximal WQE size. */
2179 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds)) {
# # # # ]
2180 : : /* Check if we can adjust the inline length. */
2181 [ # # # # : 0 : if (unlikely(txq->inlen_mode)) {
# # # # ]
2182 : 0 : ds = NB_SEGS(loc->mbuf) + 2 +
2183 : 0 : (txq->inlen_mode -
2184 : : MLX5_ESEG_MIN_INLINE_SIZE +
2185 : : MLX5_WSEG_SIZE +
2186 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
2187 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds))
# # # # ]
2188 : : return MLX5_TXCMP_CODE_ERROR;
2189 : : }
2190 : : /* We have lucky opportunity to adjust. */
2191 : 0 : inlen = RTE_MIN(inlen, MLX5_WQE_SIZE_MAX -
2192 : : MLX5_WSEG_SIZE * 2 -
2193 : : MLX5_WSEG_SIZE * NB_SEGS(loc->mbuf) -
2194 : : MLX5_WSEG_SIZE +
2195 : : MLX5_ESEG_MIN_INLINE_SIZE);
2196 : : }
2197 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2198 : : /* Update sent data bytes/packets counters. */
2199 : 0 : txq->stats.obytes += dlen + vlan;
2200 : : #endif
2201 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # ]
2202 : : loc->wqe_last = wqe;
2203 : : mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_SEND, olx);
2204 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
2205 : : ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 0, olx);
2206 [ # # # # : 0 : wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
# # # # ]
2207 : 0 : txq->wqe_ci += (ds + 3) / 4;
2208 : 0 : loc->wqe_free -= (ds + 3) / 4;
2209 : : return MLX5_TXCMP_CODE_MULTI;
2210 : : }
2211 : :
2212 : : /**
2213 : : * Tx burst function for multi-segment packets. Supports all
2214 : : * types of Tx offloads, uses MLX5_OPCODE_SEND/TSO to build WQEs,
2215 : : * sends one packet per WQE. Function stops sending if it
2216 : : * encounters the single-segment packet.
2217 : : *
2218 : : * This routine is responsible for storing processed mbuf
2219 : : * into elts ring buffer and update elts_head.
2220 : : *
2221 : : * @param txq
2222 : : * Pointer to TX queue structure.
2223 : : * @param[in] pkts
2224 : : * Packets to transmit.
2225 : : * @param pkts_n
2226 : : * Number of packets in array.
2227 : : * @param loc
2228 : : * Pointer to burst routine local context.
2229 : : * @param olx
2230 : : * Configured Tx offloads mask. It is fully defined at
2231 : : * compile time and may be used for optimization.
2232 : : *
2233 : : * @return
2234 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2235 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2236 : : * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
2237 : : * MLX5_TXCMP_CODE_TSO - TSO single-segment packet encountered.
2238 : : * Local context variables updated.
2239 : : */
2240 : : static __rte_always_inline enum mlx5_txcmp_code
2241 : : mlx5_tx_burst_mseg(struct mlx5_txq_data *__rte_restrict txq,
2242 : : struct rte_mbuf **__rte_restrict pkts,
2243 : : unsigned int pkts_n,
2244 : : struct mlx5_txq_local *__rte_restrict loc,
2245 : : unsigned int olx)
2246 : : {
2247 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2248 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2249 : 0 : pkts += loc->pkts_sent + 1;
2250 : 0 : pkts_n -= loc->pkts_sent;
2251 : 0 : for (;;) {
2252 : : enum mlx5_txcmp_code ret;
2253 : :
2254 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
2255 : : /*
2256 : : * Estimate the number of free elts quickly but conservatively.
2257 : : * Some segment may be fully inlined and freed,
2258 : : * ignore this here - precise estimation is costly.
2259 : : */
2260 [ # # # # : 0 : if (loc->elts_free < NB_SEGS(loc->mbuf))
# # # # #
# # # ]
2261 : : return MLX5_TXCMP_CODE_EXIT;
2262 : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
2263 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
# # # # #
# # # ]
2264 : : /* Proceed with multi-segment TSO. */
2265 : : ret = mlx5_tx_packet_multi_tso(txq, loc, olx);
2266 : : } else if (MLX5_TXOFF_CONFIG(INLINE)) {
2267 : : /* Proceed with multi-segment SEND with inlining. */
2268 : : ret = mlx5_tx_packet_multi_inline(txq, loc, olx);
2269 : : } else {
2270 : : /* Proceed with multi-segment SEND w/o inlining. */
2271 : : ret = mlx5_tx_packet_multi_send(txq, loc, olx);
2272 : : }
2273 : : if (ret == MLX5_TXCMP_CODE_EXIT)
2274 : : return MLX5_TXCMP_CODE_EXIT;
2275 : : if (ret == MLX5_TXCMP_CODE_ERROR)
2276 : : return MLX5_TXCMP_CODE_ERROR;
2277 : : /* WQE is built, go to the next packet. */
2278 : 0 : ++loc->pkts_sent;
2279 : 0 : --pkts_n;
2280 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2281 : : return MLX5_TXCMP_CODE_EXIT;
2282 : 0 : loc->mbuf = *pkts++;
2283 [ # # # # : 0 : if (pkts_n > 1)
# # # # #
# # # ]
2284 : 0 : rte_prefetch0(*pkts);
2285 [ # # # # : 0 : if (likely(NB_SEGS(loc->mbuf) > 1))
# # # # #
# # # ]
2286 : : continue;
2287 : : /* Here ends the series of multi-segment packets. */
2288 : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
2289 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG))
# # # # #
# # # ]
2290 : 0 : return MLX5_TXCMP_CODE_TSO;
2291 : : return MLX5_TXCMP_CODE_SINGLE;
2292 : : }
2293 : : MLX5_ASSERT(false);
2294 : : }
2295 : :
2296 : : /**
2297 : : * Tx burst function for single-segment packets with TSO.
2298 : : * Supports all types of Tx offloads, except multi-packets.
2299 : : * Uses MLX5_OPCODE_TSO to build WQEs, sends one packet per WQE.
2300 : : * Function stops sending if it encounters the multi-segment
2301 : : * packet or packet without TSO requested.
2302 : : *
2303 : : * The routine is responsible for storing processed mbuf into elts ring buffer
2304 : : * and update elts_head if inline offloads is requested due to possible early
2305 : : * freeing of the inlined mbufs (can not store pkts array in elts as a batch).
2306 : : *
2307 : : * @param txq
2308 : : * Pointer to TX queue structure.
2309 : : * @param[in] pkts
2310 : : * Packets to transmit.
2311 : : * @param pkts_n
2312 : : * Number of packets in array.
2313 : : * @param loc
2314 : : * Pointer to burst routine local context.
2315 : : * @param olx
2316 : : * Configured Tx offloads mask. It is fully defined at
2317 : : * compile time and may be used for optimization.
2318 : : *
2319 : : * @return
2320 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2321 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2322 : : * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
2323 : : * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
2324 : : * Local context variables updated.
2325 : : */
2326 : : static __rte_always_inline enum mlx5_txcmp_code
2327 : : mlx5_tx_burst_tso(struct mlx5_txq_data *__rte_restrict txq,
2328 : : struct rte_mbuf **__rte_restrict pkts,
2329 : : unsigned int pkts_n,
2330 : : struct mlx5_txq_local *__rte_restrict loc,
2331 : : unsigned int olx)
2332 : : {
2333 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2334 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2335 : 0 : pkts += loc->pkts_sent + 1;
2336 : 0 : pkts_n -= loc->pkts_sent;
2337 : : for (;;) {
2338 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
2339 : : struct mlx5_wqe *__rte_restrict wqe;
2340 : : unsigned int ds, dlen, hlen, ntcp, vlan = 0;
2341 : : uint8_t *dptr;
2342 : :
2343 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2344 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2345 : : enum mlx5_txcmp_code wret;
2346 : :
2347 : : /* Generate WAIT for scheduling if requested. */
2348 : : wret = mlx5_tx_schedule_send(txq, loc, 1, olx);
2349 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2350 : : return MLX5_TXCMP_CODE_EXIT;
2351 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2352 : : return MLX5_TXCMP_CODE_ERROR;
2353 : : }
2354 : 0 : dlen = rte_pktmbuf_data_len(loc->mbuf);
2355 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
2356 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
# # # # #
# ]
2357 : : vlan = sizeof(struct rte_vlan_hdr);
2358 : : }
2359 : : /*
2360 : : * First calculate the WQE size to check
2361 : : * whether we have enough space in ring buffer.
2362 : : */
2363 : 0 : hlen = loc->mbuf->l2_len + vlan +
2364 : 0 : loc->mbuf->l3_len + loc->mbuf->l4_len;
2365 [ # # # # : 0 : if (unlikely((!hlen || !loc->mbuf->tso_segsz)))
# # # # #
# # # # #
# # # # #
# # # #
# ]
2366 : : return MLX5_TXCMP_CODE_ERROR;
2367 [ # # # # : 0 : if (loc->mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
# # # # #
# # # ]
2368 : 0 : hlen += loc->mbuf->outer_l2_len +
2369 : 0 : loc->mbuf->outer_l3_len;
2370 : : /* Segment must contain all TSO headers. */
2371 [ # # # # : 0 : if (unlikely(hlen > MLX5_MAX_TSO_HEADER ||
# # # # #
# # # # #
# # # # #
# # # #
# ]
2372 : : hlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
2373 : : hlen > (dlen + vlan)))
2374 : : return MLX5_TXCMP_CODE_ERROR;
2375 : : /*
2376 : : * Check whether there are enough free WQEBBs:
2377 : : * - Control Segment
2378 : : * - Ethernet Segment
2379 : : * - First Segment of inlined Ethernet data
2380 : : * - ... data continued ...
2381 : : * - Finishing Data Segment of pointer type
2382 : : */
2383 : 0 : ds = 4 + (hlen - MLX5_ESEG_MIN_INLINE_SIZE +
2384 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
2385 [ # # # # : 0 : if (loc->wqe_free < ((ds + 3) / 4))
# # # # #
# # # ]
2386 : : return MLX5_TXCMP_CODE_EXIT;
2387 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2388 : : /* Update sent data bytes/packets counters. */
2389 : 0 : ntcp = (dlen + vlan - hlen +
2390 : 0 : loc->mbuf->tso_segsz - 1) /
2391 : : loc->mbuf->tso_segsz;
2392 : : /*
2393 : : * One will be added for mbuf itself at the end
2394 : : * of the mlx5_tx_burst from loc->pkts_sent field.
2395 : : */
2396 : 0 : --ntcp;
2397 : 0 : txq->stats.opackets += ntcp;
2398 : 0 : txq->stats.obytes += dlen + vlan + ntcp * hlen;
2399 : : #endif
2400 : : /*
2401 : : * Build the TSO WQE:
2402 : : * - Control Segment
2403 : : * - Ethernet Segment with hlen bytes inlined
2404 : : * - Data Segment of pointer type
2405 : : */
2406 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # ]
2407 : : loc->wqe_last = wqe;
2408 : : mlx5_tx_cseg_init(txq, loc, wqe, ds, MLX5_OPCODE_TSO, olx);
2409 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
2410 : : dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan, hlen, 1, olx);
2411 [ # # # # : 0 : dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) + hlen - vlan;
# # ]
2412 [ # # # # : 0 : dlen -= hlen - vlan;
# # # # #
# ]
2413 : : mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
2414 : : /*
2415 : : * WQE is built, update the loop parameters
2416 : : * and go to the next packet.
2417 : : */
2418 : 0 : txq->wqe_ci += (ds + 3) / 4;
2419 : 0 : loc->wqe_free -= (ds + 3) / 4;
2420 : : if (MLX5_TXOFF_CONFIG(INLINE))
2421 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2422 : 0 : --loc->elts_free;
2423 : 0 : ++loc->pkts_sent;
2424 : 0 : --pkts_n;
2425 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2426 : : return MLX5_TXCMP_CODE_EXIT;
2427 : 0 : loc->mbuf = *pkts++;
2428 [ # # # # : 0 : if (pkts_n > 1)
# # # # #
# # # ]
2429 : 0 : rte_prefetch0(*pkts);
2430 : 0 : if (MLX5_TXOFF_CONFIG(MULTI) &&
2431 [ # # # # : 0 : unlikely(NB_SEGS(loc->mbuf) > 1))
# # # # #
# # # ]
2432 : : return MLX5_TXCMP_CODE_MULTI;
2433 [ # # # # : 0 : if (likely(!(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)))
# # # # #
# # # ]
2434 : : return MLX5_TXCMP_CODE_SINGLE;
2435 : : /* Continue with the next TSO packet. */
2436 : : }
2437 : : MLX5_ASSERT(false);
2438 : : }
2439 : :
2440 : : /**
2441 : : * Analyze the packet and select the best method to send.
2442 : : *
2443 : : * @param txq
2444 : : * Pointer to TX queue structure.
2445 : : * @param loc
2446 : : * Pointer to burst routine local context.
2447 : : * @param olx
2448 : : * Configured Tx offloads mask. It is fully defined at
2449 : : * compile time and may be used for optimization.
2450 : : * @param newp
2451 : : * The predefined flag whether do complete check for
2452 : : * multi-segment packets and TSO.
2453 : : *
2454 : : * @return
2455 : : * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
2456 : : * MLX5_TXCMP_CODE_TSO - TSO required, use TSO/LSO.
2457 : : * MLX5_TXCMP_CODE_SINGLE - single-segment packet, use SEND.
2458 : : * MLX5_TXCMP_CODE_EMPW - single-segment packet, use MPW.
2459 : : */
2460 : : static __rte_always_inline enum mlx5_txcmp_code
2461 : : mlx5_tx_able_to_empw(struct mlx5_txq_data *__rte_restrict txq,
2462 : : struct mlx5_txq_local *__rte_restrict loc,
2463 : : unsigned int olx,
2464 : : bool newp)
2465 : : {
2466 : : /* Check for multi-segment packet. */
2467 : : if (newp &&
2468 : 0 : MLX5_TXOFF_CONFIG(MULTI) &&
2469 [ # # # # : 0 : unlikely(NB_SEGS(loc->mbuf) > 1))
# # # # #
# # # # #
# # # # ]
2470 : : return MLX5_TXCMP_CODE_MULTI;
2471 : : /* Check for TSO packet. */
2472 : : if (newp &&
2473 : 0 : MLX5_TXOFF_CONFIG(TSO) &&
2474 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG))
# # # # #
# # # # #
# # # # #
# # # #
# ]
2475 : : return MLX5_TXCMP_CODE_TSO;
2476 : : /* Check if eMPW is enabled at all. */
2477 : : if (!MLX5_TXOFF_CONFIG(EMPW))
2478 : : return MLX5_TXCMP_CODE_SINGLE;
2479 : : /* Check if eMPW can be engaged. */
2480 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
2481 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) &&
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
2482 : 0 : (!MLX5_TXOFF_CONFIG(INLINE) ||
2483 [ # # # # : 0 : unlikely((rte_pktmbuf_data_len(loc->mbuf) +
# # # # #
# # # # #
# # # # #
# # # #
# ]
2484 : : sizeof(struct rte_vlan_hdr)) > txq->inlen_empw))) {
2485 : : /*
2486 : : * eMPW does not support VLAN insertion offload, we have to
2487 : : * inline the entire packet but packet is too long for inlining.
2488 : : */
2489 : 0 : return MLX5_TXCMP_CODE_SINGLE;
2490 : : }
2491 : : return MLX5_TXCMP_CODE_EMPW;
2492 : : }
2493 : :
2494 : : /**
2495 : : * Check the next packet attributes to match with the eMPW batch ones.
2496 : : * In addition, for legacy MPW the packet length is checked either.
2497 : : *
2498 : : * @param txq
2499 : : * Pointer to TX queue structure.
2500 : : * @param es
2501 : : * Pointer to Ethernet Segment of eMPW batch.
2502 : : * @param loc
2503 : : * Pointer to burst routine local context.
2504 : : * @param dlen
2505 : : * Length of previous packet in MPW descriptor.
2506 : : * @param olx
2507 : : * Configured Tx offloads mask. It is fully defined at
2508 : : * compile time and may be used for optimization.
2509 : : *
2510 : : * @return
2511 : : * true - packet match with eMPW batch attributes.
2512 : : * false - no match, eMPW should be restarted.
2513 : : */
2514 : : static __rte_always_inline bool
2515 : : mlx5_tx_match_empw(struct mlx5_txq_data *__rte_restrict txq,
2516 : : struct mlx5_wqe_eseg *__rte_restrict es,
2517 : : struct mlx5_txq_local *__rte_restrict loc,
2518 : : uint32_t dlen,
2519 : : unsigned int olx)
2520 : : {
2521 : : uint8_t swp_flags = 0;
2522 : :
2523 : : /* Compare the checksum flags, if any. */
2524 : 0 : if (MLX5_TXOFF_CONFIG(CSUM) &&
2525 [ # # # # : 0 : txq_ol_cksum_to_cs(loc->mbuf) != es->cs_flags)
# # # # #
# # # ]
2526 : : return false;
2527 : : /* Compare the Software Parser offsets and flags. */
2528 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(SWP) &&
# # # # #
# # # ]
2529 [ # # # # : 0 : (es->swp_offs != txq_mbuf_to_swp(loc, &swp_flags, olx) ||
# # # # #
# # # ]
2530 [ # # # # : 0 : es->swp_flags != swp_flags))
# # # # #
# # # ]
2531 : : return false;
2532 : : /* Fill metadata field if needed. */
2533 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(METADATA) &&
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2534 : 0 : es->metadata != (loc->mbuf->ol_flags & RTE_MBUF_DYNFLAG_TX_METADATA ?
2535 [ # # # # : 0 : rte_cpu_to_be_32(*RTE_FLOW_DYNF_METADATA(loc->mbuf)) : 0))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2536 : : return false;
2537 : : /* Legacy MPW can send packets with the same length only. */
2538 : 0 : if (MLX5_TXOFF_CONFIG(MPW) &&
2539 [ # # # # : 0 : dlen != rte_pktmbuf_data_len(loc->mbuf))
# # # # ]
2540 : : return false;
2541 : : /* There must be no VLAN packets in eMPW loop. */
2542 : : if (MLX5_TXOFF_CONFIG(VLAN))
2543 : : MLX5_ASSERT(!(loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN));
2544 : : /* Check if the scheduling is requested. */
2545 : 0 : if (MLX5_TXOFF_CONFIG(TXPP) &&
2546 [ # # # # : 0 : loc->mbuf->ol_flags & txq->ts_mask)
# # # # #
# # # ]
2547 : : return false;
2548 : : return true;
2549 : : }
2550 : :
2551 : : /**
2552 : : * Update send loop variables and WQE for eMPW loop without data inlining.
2553 : : * Number of Data Segments is equal to the number of sent packets.
2554 : : *
2555 : : * @param txq
2556 : : * Pointer to TX queue structure.
2557 : : * @param loc
2558 : : * Pointer to burst routine local context.
2559 : : * @param ds
2560 : : * Number of packets/Data Segments/Packets.
2561 : : * @param slen
2562 : : * Accumulated statistics, bytes sent.
2563 : : * @param olx
2564 : : * Configured Tx offloads mask. It is fully defined at
2565 : : * compile time and may be used for optimization.
2566 : : *
2567 : : * @return
2568 : : * true - packet match with eMPW batch attributes.
2569 : : * false - no match, eMPW should be restarted.
2570 : : */
2571 : : static __rte_always_inline void
2572 : : mlx5_tx_sdone_empw(struct mlx5_txq_data *__rte_restrict txq,
2573 : : struct mlx5_txq_local *__rte_restrict loc,
2574 : : unsigned int ds,
2575 : : unsigned int slen,
2576 : : unsigned int olx __rte_unused)
2577 : : {
2578 : : MLX5_ASSERT(!MLX5_TXOFF_CONFIG(INLINE));
2579 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2580 : : /* Update sent data bytes counter. */
2581 : 0 : txq->stats.obytes += slen;
2582 : : #else
2583 : : (void)slen;
2584 : : #endif
2585 : 0 : loc->elts_free -= ds;
2586 : 0 : loc->pkts_sent += ds;
2587 : 0 : ds += 2;
2588 : 0 : loc->wqe_last->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
2589 : 0 : txq->wqe_ci += (ds + 3) / 4;
2590 : 0 : loc->wqe_free -= (ds + 3) / 4;
2591 : : }
2592 : :
2593 : : /**
2594 : : * Update send loop variables and WQE for eMPW loop with data inlining.
2595 : : * Gets the size of pushed descriptors and data to the WQE.
2596 : : *
2597 : : * @param txq
2598 : : * Pointer to TX queue structure.
2599 : : * @param loc
2600 : : * Pointer to burst routine local context.
2601 : : * @param len
2602 : : * Total size of descriptor/data in bytes.
2603 : : * @param slen
2604 : : * Accumulated statistics, data bytes sent.
2605 : : * @param wqem
2606 : : * The base WQE for the eMPW/MPW descriptor.
2607 : : * @param olx
2608 : : * Configured Tx offloads mask. It is fully defined at
2609 : : * compile time and may be used for optimization.
2610 : : *
2611 : : * @return
2612 : : * true - packet match with eMPW batch attributes.
2613 : : * false - no match, eMPW should be restarted.
2614 : : */
2615 : : static __rte_always_inline void
2616 : : mlx5_tx_idone_empw(struct mlx5_txq_data *__rte_restrict txq,
2617 : : struct mlx5_txq_local *__rte_restrict loc,
2618 : : unsigned int len,
2619 : : unsigned int slen,
2620 : : struct mlx5_wqe *__rte_restrict wqem,
2621 : : unsigned int olx __rte_unused)
2622 : : {
2623 : : struct mlx5_wqe_dseg *dseg = &wqem->dseg[0];
2624 : :
2625 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
2626 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2627 : : /* Update sent data bytes counter. */
2628 : 0 : txq->stats.obytes += slen;
2629 : : #else
2630 : : (void)slen;
2631 : : #endif
2632 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(MPW) && dseg->bcount == RTE_BE32(0)) {
# # # # ]
2633 : : /*
2634 : : * If the legacy MPW session contains the inline packets
2635 : : * we should set the only inline data segment length
2636 : : * and align the total length to the segment size.
2637 : : */
2638 : : MLX5_ASSERT(len > sizeof(dseg->bcount));
2639 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32((len - sizeof(dseg->bcount)) |
# # # # #
# # # #
# ]
2640 : : MLX5_ETH_WQE_DATA_INLINE);
2641 : 0 : len = (len + MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE + 2;
2642 : : } else {
2643 : : /*
2644 : : * The session is not legacy MPW or contains the
2645 : : * data buffer pointer segments.
2646 : : */
2647 : : MLX5_ASSERT((len % MLX5_WSEG_SIZE) == 0);
2648 : 0 : len = len / MLX5_WSEG_SIZE + 2;
2649 : : }
2650 [ # # # # : 0 : wqem->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | len);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2651 : 0 : txq->wqe_ci += (len + 3) / 4;
2652 : 0 : loc->wqe_free -= (len + 3) / 4;
2653 : : loc->wqe_last = wqem;
2654 : : }
2655 : :
2656 : : /**
2657 : : * The set of Tx burst functions for single-segment packets without TSO
2658 : : * and with Multi-Packet Writing feature support.
2659 : : * Supports all types of Tx offloads, except multi-packets and TSO.
2660 : : *
2661 : : * Uses MLX5_OPCODE_EMPW to build WQEs if possible and sends as many packet
2662 : : * per WQE as it can. If eMPW is not configured or packet can not be sent with
2663 : : * eMPW (VLAN insertion) the ordinary SEND opcode is used and only one packet
2664 : : * placed in WQE.
2665 : : *
2666 : : * Functions stop sending if it encounters the multi-segment packet or packet
2667 : : * with TSO requested.
2668 : : *
2669 : : * The routines are responsible for storing processed mbuf into elts ring buffer
2670 : : * and update elts_head if inlining offload is requested. Otherwise the copying
2671 : : * mbufs to elts can be postponed and completed at the end of burst routine.
2672 : : *
2673 : : * @param txq
2674 : : * Pointer to TX queue structure.
2675 : : * @param[in] pkts
2676 : : * Packets to transmit.
2677 : : * @param pkts_n
2678 : : * Number of packets in array.
2679 : : * @param loc
2680 : : * Pointer to burst routine local context.
2681 : : * @param olx
2682 : : * Configured Tx offloads mask. It is fully defined at
2683 : : * compile time and may be used for optimization.
2684 : : *
2685 : : * @return
2686 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2687 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2688 : : * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
2689 : : * MLX5_TXCMP_CODE_TSO - TSO packet encountered.
2690 : : * MLX5_TXCMP_CODE_SINGLE - used inside functions set.
2691 : : * MLX5_TXCMP_CODE_EMPW - used inside functions set.
2692 : : *
2693 : : * Local context variables updated.
2694 : : *
2695 : : *
2696 : : * The routine sends packets with MLX5_OPCODE_EMPW
2697 : : * without inlining, this is dedicated optimized branch.
2698 : : * No VLAN insertion is supported.
2699 : : */
2700 : : static __rte_always_inline enum mlx5_txcmp_code
2701 : : mlx5_tx_burst_empw_simple(struct mlx5_txq_data *__rte_restrict txq,
2702 : : struct rte_mbuf **__rte_restrict pkts,
2703 : : unsigned int pkts_n,
2704 : : struct mlx5_txq_local *__rte_restrict loc,
2705 : : unsigned int olx)
2706 : : {
2707 : : /*
2708 : : * Subroutine is the part of mlx5_tx_burst_single() and sends
2709 : : * single-segment packet with eMPW opcode without data inlining.
2710 : : */
2711 : : MLX5_ASSERT(!MLX5_TXOFF_CONFIG(INLINE));
2712 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(EMPW));
2713 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2714 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2715 : 0 : pkts += loc->pkts_sent + 1;
2716 : 0 : pkts_n -= loc->pkts_sent;
2717 : : for (;;) {
2718 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
2719 : : struct mlx5_wqe_eseg *__rte_restrict eseg;
2720 : : enum mlx5_txcmp_code ret;
2721 : : unsigned int part, loop;
2722 : : unsigned int slen = 0;
2723 : :
2724 : 0 : next_empw:
2725 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2726 : 0 : part = RTE_MIN(pkts_n, MLX5_TXOFF_CONFIG(MPW) ?
2727 : : MLX5_MPW_MAX_PACKETS :
2728 : : MLX5_EMPW_MAX_PACKETS);
2729 [ # # # # : 0 : if (unlikely(loc->elts_free < part)) {
# # # # #
# # # # #
# # ]
2730 : : /* We have no enough elts to save all mbufs. */
2731 [ # # # # : 0 : if (unlikely(loc->elts_free < MLX5_EMPW_MIN_PACKETS))
# # # # #
# # # # #
# # ]
2732 : : return MLX5_TXCMP_CODE_EXIT;
2733 : : /* But we still able to send at least minimal eMPW. */
2734 : : part = loc->elts_free;
2735 : : }
2736 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2737 : : enum mlx5_txcmp_code wret;
2738 : :
2739 : : /* Generate WAIT for scheduling if requested. */
2740 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
2741 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2742 : : return MLX5_TXCMP_CODE_EXIT;
2743 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2744 : : return MLX5_TXCMP_CODE_ERROR;
2745 : : }
2746 : : /* Check whether we have enough WQEs */
2747 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((2 + part + 3) / 4))) {
# # # # #
# # # # #
# # ]
2748 [ # # # # : 0 : if (unlikely(loc->wqe_free <
# # # # #
# # # # #
# # ]
2749 : : ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
2750 : : return MLX5_TXCMP_CODE_EXIT;
2751 : 0 : part = (loc->wqe_free * 4) - 2;
2752 : : }
2753 [ # # # # : 0 : if (likely(part > 1))
# # # # #
# # # # #
# # ]
2754 : 0 : rte_prefetch0(*pkts);
2755 : 0 : loc->wqe_last = txq->wqes + (txq->wqe_ci & txq->wqe_m);
2756 : : /*
2757 : : * Build eMPW title WQEBB:
2758 : : * - Control Segment, eMPW opcode
2759 : : * - Ethernet Segment, no inline
2760 : : */
2761 [ # # # # : 0 : mlx5_tx_cseg_init(txq, loc, loc->wqe_last, part + 2,
# # # # #
# # # # #
# # ]
2762 : : MLX5_OPCODE_ENHANCED_MPSW, olx);
2763 : : mlx5_tx_eseg_none(txq, loc, loc->wqe_last,
2764 : : olx & ~MLX5_TXOFF_CONFIG_VLAN);
2765 : : eseg = &loc->wqe_last->eseg;
2766 : 0 : dseg = &loc->wqe_last->dseg[0];
2767 : : loop = part;
2768 : : /* Store the packet length for legacy MPW. */
2769 : : if (MLX5_TXOFF_CONFIG(MPW))
2770 [ # # # # ]: 0 : eseg->mss = rte_cpu_to_be_16
2771 : : (rte_pktmbuf_data_len(loc->mbuf));
2772 : : for (;;) {
2773 : 0 : uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
2774 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2775 : : /* Update sent data bytes counter. */
2776 : 0 : slen += dlen;
2777 : : #endif
2778 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
2779 : : mlx5_tx_dseg_ptr
2780 : : (txq, loc, dseg,
2781 [ # # # # : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
# # # # #
# # # # #
# # ]
2782 : : dlen, olx);
2783 [ # # # # : 0 : if (unlikely(--loop == 0))
# # # # #
# # # # #
# # ]
2784 : : break;
2785 : 0 : loc->mbuf = *pkts++;
2786 [ # # # # : 0 : if (likely(loop > 1))
# # # # #
# # # # #
# # ]
2787 : 0 : rte_prefetch0(*pkts);
2788 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
2789 : : /*
2790 : : * Unroll the completion code to avoid
2791 : : * returning variable value - it results in
2792 : : * unoptimized sequent checking in caller.
2793 : : */
2794 : : if (ret == MLX5_TXCMP_CODE_MULTI) {
2795 [ # # # # : 0 : part -= loop;
# # ]
2796 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2797 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # ]
2798 : : !loc->wqe_free))
2799 : : return MLX5_TXCMP_CODE_EXIT;
2800 : : return MLX5_TXCMP_CODE_MULTI;
2801 : : }
2802 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2803 : : if (ret == MLX5_TXCMP_CODE_TSO) {
2804 [ # # # # : 0 : part -= loop;
# # ]
2805 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2806 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # ]
2807 : : !loc->wqe_free))
2808 : : return MLX5_TXCMP_CODE_EXIT;
2809 : : return MLX5_TXCMP_CODE_TSO;
2810 : : }
2811 : : if (ret == MLX5_TXCMP_CODE_SINGLE) {
2812 [ # # # # : 0 : part -= loop;
# # ]
2813 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2814 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # ]
2815 : : !loc->wqe_free))
2816 : : return MLX5_TXCMP_CODE_EXIT;
2817 : : return MLX5_TXCMP_CODE_SINGLE;
2818 : : }
2819 : : if (ret != MLX5_TXCMP_CODE_EMPW) {
2820 : : MLX5_ASSERT(false);
2821 : : part -= loop;
2822 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2823 : : return MLX5_TXCMP_CODE_ERROR;
2824 : : }
2825 : : /*
2826 : : * Check whether packet parameters coincide
2827 : : * within assumed eMPW batch:
2828 : : * - check sum settings
2829 : : * - metadata value
2830 : : * - software parser settings
2831 : : * - packets length (legacy MPW only)
2832 : : * - scheduling is not required
2833 : : */
2834 : : if (!mlx5_tx_match_empw(txq, eseg, loc, dlen, olx)) {
2835 : : MLX5_ASSERT(loop);
2836 [ # # # # : 0 : part -= loop;
# # # # #
# # # #
# ]
2837 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2838 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2839 : : !loc->wqe_free))
2840 : : return MLX5_TXCMP_CODE_EXIT;
2841 : 0 : pkts_n -= part;
2842 : 0 : goto next_empw;
2843 : : }
2844 : : /* Packet attributes match, continue the same eMPW. */
2845 : 0 : ++dseg;
2846 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # # #
# # ]
2847 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2848 : : }
2849 : : /* eMPW is built successfully, update loop parameters. */
2850 : : MLX5_ASSERT(!loop);
2851 : : MLX5_ASSERT(pkts_n >= part);
2852 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2853 : : /* Update sent data bytes counter. */
2854 : 0 : txq->stats.obytes += slen;
2855 : : #endif
2856 : 0 : loc->elts_free -= part;
2857 : 0 : loc->pkts_sent += part;
2858 : 0 : txq->wqe_ci += (2 + part + 3) / 4;
2859 : 0 : loc->wqe_free -= (2 + part + 3) / 4;
2860 : 0 : pkts_n -= part;
2861 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2862 : : return MLX5_TXCMP_CODE_EXIT;
2863 [ # # # # : 0 : loc->mbuf = *pkts++;
# # # # #
# ]
2864 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
2865 [ # # # # : 0 : if (unlikely(ret != MLX5_TXCMP_CODE_EMPW))
# # # # #
# ]
2866 : : return ret;
2867 : : /* Continue sending eMPW batches. */
2868 : : }
2869 : : MLX5_ASSERT(false);
2870 : : }
2871 : :
2872 : : /**
2873 : : * The routine sends packets with MLX5_OPCODE_EMPW
2874 : : * with inlining, optionally supports VLAN insertion.
2875 : : */
2876 : : static __rte_always_inline enum mlx5_txcmp_code
2877 : : mlx5_tx_burst_empw_inline(struct mlx5_txq_data *__rte_restrict txq,
2878 : : struct rte_mbuf **__rte_restrict pkts,
2879 : : unsigned int pkts_n,
2880 : : struct mlx5_txq_local *__rte_restrict loc,
2881 : : unsigned int olx)
2882 : : {
2883 : : /*
2884 : : * Subroutine is the part of mlx5_tx_burst_single() and sends
2885 : : * single-segment packet with eMPW opcode with data inlining.
2886 : : */
2887 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
2888 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(EMPW));
2889 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2890 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2891 : 0 : pkts += loc->pkts_sent + 1;
2892 : 0 : pkts_n -= loc->pkts_sent;
2893 : : for (;;) {
2894 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
2895 : : struct mlx5_wqe *__rte_restrict wqem;
2896 : : enum mlx5_txcmp_code ret;
2897 : : unsigned int room, part, nlim;
2898 : : unsigned int slen = 0;
2899 : :
2900 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2901 : : /*
2902 : : * Limits the amount of packets in one WQE
2903 : : * to improve CQE latency generation.
2904 : : */
2905 : 0 : nlim = RTE_MIN(pkts_n, MLX5_TXOFF_CONFIG(MPW) ?
2906 : : MLX5_MPW_INLINE_MAX_PACKETS :
2907 : : MLX5_EMPW_MAX_PACKETS);
2908 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2909 : : enum mlx5_txcmp_code wret;
2910 : :
2911 : : /* Generate WAIT for scheduling if requested. */
2912 [ # # # # : 0 : wret = mlx5_tx_schedule_send(txq, loc, nlim, olx);
# # # # ]
2913 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2914 : : return MLX5_TXCMP_CODE_EXIT;
2915 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2916 : : return MLX5_TXCMP_CODE_ERROR;
2917 : : }
2918 : : /* Check whether we have minimal amount WQEs */
2919 [ # # # # : 0 : if (unlikely(loc->wqe_free <
# # # # #
# # # #
# ]
2920 : : ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
2921 : : return MLX5_TXCMP_CODE_EXIT;
2922 [ # # # # : 0 : if (likely(pkts_n > 1))
# # # # #
# # # #
# ]
2923 : 0 : rte_prefetch0(*pkts);
2924 [ # # # # : 0 : wqem = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
2925 : : /*
2926 : : * Build eMPW title WQEBB:
2927 : : * - Control Segment, eMPW opcode, zero DS
2928 : : * - Ethernet Segment, no inline
2929 : : */
2930 : : mlx5_tx_cseg_init(txq, loc, wqem, 0,
2931 : : MLX5_OPCODE_ENHANCED_MPSW, olx);
2932 : : mlx5_tx_eseg_none(txq, loc, wqem,
2933 : : olx & ~MLX5_TXOFF_CONFIG_VLAN);
2934 : 0 : dseg = &wqem->dseg[0];
2935 : : /* Store the packet length for legacy MPW. */
2936 : : if (MLX5_TXOFF_CONFIG(MPW))
2937 [ # # # # ]: 0 : wqem->eseg.mss = rte_cpu_to_be_16
2938 : : (rte_pktmbuf_data_len(loc->mbuf));
2939 : 0 : room = RTE_MIN(MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE,
2940 : : loc->wqe_free) * MLX5_WQE_SIZE -
2941 : 0 : MLX5_WQE_CSEG_SIZE -
2942 : : MLX5_WQE_ESEG_SIZE;
2943 : : /* Limit the room for legacy MPW sessions for performance. */
2944 : : if (MLX5_TXOFF_CONFIG(MPW))
2945 : 0 : room = RTE_MIN(room,
2946 : : RTE_MAX(txq->inlen_empw +
2947 : : sizeof(dseg->bcount) +
2948 : : (MLX5_TXOFF_CONFIG(VLAN) ?
2949 : : sizeof(struct rte_vlan_hdr) : 0),
2950 : : MLX5_MPW_INLINE_MAX_PACKETS *
2951 : : MLX5_WQE_DSEG_SIZE));
2952 : : /* Build WQE till we have space, packets and resources. */
2953 : : part = room;
2954 : : for (;;) {
2955 : 0 : uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
2956 : 0 : uint8_t *dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2957 : : unsigned int tlen;
2958 : :
2959 : : MLX5_ASSERT(room >= MLX5_WQE_DSEG_SIZE);
2960 : : MLX5_ASSERT((room % MLX5_WQE_DSEG_SIZE) == 0);
2961 : : MLX5_ASSERT((uintptr_t)dseg < (uintptr_t)txq->wqes_end);
2962 : : /*
2963 : : * Some Tx offloads may cause an error if packet is not
2964 : : * long enough, check against assumed minimal length.
2965 : : */
2966 [ # # # # : 0 : if (unlikely(dlen <= MLX5_ESEG_MIN_INLINE_SIZE)) {
# # # # #
# # # #
# ]
2967 : 0 : part -= room;
2968 [ # # # # : 0 : if (unlikely(!part))
# # # # #
# # # #
# ]
2969 : : return MLX5_TXCMP_CODE_ERROR;
2970 : : /*
2971 : : * We have some successfully built
2972 : : * packet Data Segments to send.
2973 : : */
2974 : : mlx5_tx_idone_empw(txq, loc, part,
2975 : : slen, wqem, olx);
2976 : : return MLX5_TXCMP_CODE_ERROR;
2977 : : }
2978 : : /* Inline or not inline - that's the Question. */
2979 [ # # # # : 0 : if (dlen > txq->inlen_empw ||
# # # # #
# # # #
# ]
2980 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE)
# # # # #
# # # #
# ]
2981 [ # # # # : 0 : goto pointer_empw;
# # # # #
# # # #
# ]
2982 : : if (MLX5_TXOFF_CONFIG(MPW)) {
2983 [ # # # # ]: 0 : if (dlen > txq->inlen_send)
2984 : 0 : goto pointer_empw;
2985 : : tlen = dlen;
2986 [ # # # # ]: 0 : if (part == room) {
2987 : : /* Open new inline MPW session. */
2988 : 0 : tlen += sizeof(dseg->bcount);
2989 : 0 : dseg->bcount = RTE_BE32(0);
2990 : 0 : dseg = RTE_PTR_ADD
2991 : : (dseg, sizeof(dseg->bcount));
2992 : : } else {
2993 : : /*
2994 : : * No pointer and inline descriptor
2995 : : * intermix for legacy MPW sessions.
2996 : : */
2997 [ # # # # ]: 0 : if (wqem->dseg[0].bcount)
2998 : : break;
2999 : : }
3000 : : } else {
3001 : 0 : tlen = sizeof(dseg->bcount) + dlen;
3002 : : }
3003 : : /* Inline entire packet, optional VLAN insertion. */
3004 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
3005 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
# # # # ]
3006 : : /*
3007 : : * The packet length must be checked in
3008 : : * mlx5_tx_able_to_empw() and packet
3009 : : * fits into inline length guaranteed.
3010 : : */
3011 : : MLX5_ASSERT((dlen +
3012 : : sizeof(struct rte_vlan_hdr)) <=
3013 : : txq->inlen_empw);
3014 : 0 : tlen += sizeof(struct rte_vlan_hdr);
3015 [ # # # # : 0 : if (room < tlen)
# # # # ]
3016 : : break;
3017 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3018 : : dseg = mlx5_tx_dseg_vlan(txq, loc, dseg,
3019 : : dptr, dlen, olx);
3020 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3021 : : /* Update sent data bytes counter. */
3022 : 0 : slen += sizeof(struct rte_vlan_hdr);
3023 : : #endif
3024 : : } else {
3025 [ # # # # : 0 : if (room < tlen)
# # # # #
# # # #
# ]
3026 : : break;
3027 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3028 : : dseg = mlx5_tx_dseg_empw(txq, loc, dseg,
3029 : : dptr, dlen, olx);
3030 : : }
3031 : : if (!MLX5_TXOFF_CONFIG(MPW))
3032 : 0 : tlen = RTE_ALIGN(tlen, MLX5_WSEG_SIZE);
3033 : : MLX5_ASSERT(room >= tlen);
3034 : 0 : room -= tlen;
3035 : : /*
3036 : : * Packet data are completely inline,
3037 : : * we can try to free the packet.
3038 : : */
3039 [ # # # # : 0 : if (likely(loc->pkts_sent == loc->mbuf_free)) {
# # # # #
# # # #
# ]
3040 : : /*
3041 : : * All the packets from the burst beginning
3042 : : * are inline, we can free mbufs directly
3043 : : * from the origin array on tx_burst exit().
3044 : : */
3045 : 0 : loc->mbuf_free++;
3046 : 0 : goto next_mbuf;
3047 : : }
3048 : : /*
3049 : : * In order no to call rte_pktmbuf_free_seg() here,
3050 : : * in the most inner loop (that might be very
3051 : : * expensive) we just save the mbuf in elts.
3052 : : */
3053 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3054 : 0 : loc->elts_free--;
3055 : 0 : goto next_mbuf;
3056 : 0 : pointer_empw:
3057 : : /*
3058 : : * No pointer and inline descriptor
3059 : : * intermix for legacy MPW sessions.
3060 : : */
3061 [ # # # # ]: 0 : if (MLX5_TXOFF_CONFIG(MPW) &&
3062 : 0 : part != room &&
3063 [ # # # # ]: 0 : wqem->dseg[0].bcount == RTE_BE32(0))
3064 : : break;
3065 : : /*
3066 : : * Not inlinable VLAN packets are
3067 : : * proceeded outside of this routine.
3068 : : */
3069 : : MLX5_ASSERT(room >= MLX5_WQE_DSEG_SIZE);
3070 : : if (MLX5_TXOFF_CONFIG(VLAN))
3071 : : MLX5_ASSERT(!(loc->mbuf->ol_flags &
3072 : : RTE_MBUF_F_TX_VLAN));
3073 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3074 : : mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
3075 : : /* We have to store mbuf in elts.*/
3076 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3077 : 0 : loc->elts_free--;
3078 : 0 : room -= MLX5_WQE_DSEG_SIZE;
3079 : : /* Ring buffer wraparound is checked at the loop end.*/
3080 : 0 : ++dseg;
3081 : 0 : next_mbuf:
3082 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3083 : : /* Update sent data bytes counter. */
3084 : 0 : slen += dlen;
3085 : : #endif
3086 : 0 : loc->pkts_sent++;
3087 : 0 : pkts_n--;
3088 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
3089 : : /*
3090 : : * We have no resources/packets to
3091 : : * continue build descriptors.
3092 : : */
3093 [ # # # # : 0 : part -= room;
# # # # #
# # # #
# ]
3094 : : mlx5_tx_idone_empw(txq, loc, part,
3095 : : slen, wqem, olx);
3096 : : return MLX5_TXCMP_CODE_EXIT;
3097 : : }
3098 : 0 : loc->mbuf = *pkts++;
3099 [ # # # # : 0 : if (likely(pkts_n > 1))
# # # # #
# # # #
# ]
3100 : 0 : rte_prefetch0(*pkts);
3101 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3102 : : /*
3103 : : * Unroll the completion code to avoid
3104 : : * returning variable value - it results in
3105 : : * unoptimized sequent checking in caller.
3106 : : */
3107 : : if (ret == MLX5_TXCMP_CODE_MULTI) {
3108 [ # # # # : 0 : part -= room;
# # ]
3109 : : mlx5_tx_idone_empw(txq, loc, part,
3110 : : slen, wqem, olx);
3111 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # ]
3112 : : !loc->wqe_free))
3113 : : return MLX5_TXCMP_CODE_EXIT;
3114 : : return MLX5_TXCMP_CODE_MULTI;
3115 : : }
3116 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
3117 : : if (ret == MLX5_TXCMP_CODE_TSO) {
3118 [ # # # # : 0 : part -= room;
# # ]
3119 : : mlx5_tx_idone_empw(txq, loc, part,
3120 : : slen, wqem, olx);
3121 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # ]
3122 : : !loc->wqe_free))
3123 : : return MLX5_TXCMP_CODE_EXIT;
3124 : : return MLX5_TXCMP_CODE_TSO;
3125 : : }
3126 : : if (ret == MLX5_TXCMP_CODE_SINGLE) {
3127 [ # # # # : 0 : part -= room;
# # # # ]
3128 : : mlx5_tx_idone_empw(txq, loc, part,
3129 : : slen, wqem, olx);
3130 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # ]
3131 : : !loc->wqe_free))
3132 : : return MLX5_TXCMP_CODE_EXIT;
3133 : : return MLX5_TXCMP_CODE_SINGLE;
3134 : : }
3135 : : if (ret != MLX5_TXCMP_CODE_EMPW) {
3136 : : MLX5_ASSERT(false);
3137 : : part -= room;
3138 : : mlx5_tx_idone_empw(txq, loc, part,
3139 : : slen, wqem, olx);
3140 : : return MLX5_TXCMP_CODE_ERROR;
3141 : : }
3142 : : /* Check if we have minimal room left. */
3143 : 0 : nlim--;
3144 [ # # # # : 0 : if (unlikely(!nlim || room < MLX5_WQE_DSEG_SIZE))
# # # # #
# # # #
# ]
3145 : : break;
3146 : : /*
3147 : : * Check whether packet parameters coincide
3148 : : * within assumed eMPW batch:
3149 : : * - check sum settings
3150 : : * - metadata value
3151 : : * - software parser settings
3152 : : * - packets length (legacy MPW only)
3153 : : * - scheduling is not required
3154 : : */
3155 : : if (!mlx5_tx_match_empw(txq, &wqem->eseg,
3156 : : loc, dlen, olx))
3157 : : break;
3158 : : /* Packet attributes match, continue the same eMPW. */
3159 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # #
# ]
3160 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3161 : : }
3162 : : /*
3163 : : * We get here to close an existing eMPW
3164 : : * session and start the new one.
3165 : : */
3166 : : MLX5_ASSERT(pkts_n);
3167 : 0 : part -= room;
3168 [ # # # # : 0 : if (unlikely(!part))
# # # # #
# # # #
# ]
3169 : : return MLX5_TXCMP_CODE_EXIT;
3170 : : mlx5_tx_idone_empw(txq, loc, part, slen, wqem, olx);
3171 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
3172 : : !loc->wqe_free))
3173 : : return MLX5_TXCMP_CODE_EXIT;
3174 : : /* Continue the loop with new eMPW session. */
3175 : : }
3176 : : MLX5_ASSERT(false);
3177 : : }
3178 : :
3179 : : /**
3180 : : * The routine sends packets with ordinary MLX5_OPCODE_SEND.
3181 : : * Data inlining and VLAN insertion are supported.
3182 : : */
3183 : : static __rte_always_inline enum mlx5_txcmp_code
3184 : : mlx5_tx_burst_single_send(struct mlx5_txq_data *__rte_restrict txq,
3185 : : struct rte_mbuf **__rte_restrict pkts,
3186 : : unsigned int pkts_n,
3187 : : struct mlx5_txq_local *__rte_restrict loc,
3188 : : unsigned int olx)
3189 : : {
3190 : : /*
3191 : : * Subroutine is the part of mlx5_tx_burst_single()
3192 : : * and sends single-segment packet with SEND opcode.
3193 : : */
3194 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3195 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
3196 : 0 : pkts += loc->pkts_sent + 1;
3197 : 0 : pkts_n -= loc->pkts_sent;
3198 : : for (;;) {
3199 : : struct mlx5_wqe *__rte_restrict wqe;
3200 : : enum mlx5_txcmp_code ret;
3201 : :
3202 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
3203 : : MLX5_ASSERT(loc->elts_free);
3204 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
3205 : : enum mlx5_txcmp_code wret;
3206 : :
3207 : : /* Generate WAIT for scheduling if requested. */
3208 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
3209 : : if (wret == MLX5_TXCMP_CODE_EXIT)
3210 : : return MLX5_TXCMP_CODE_EXIT;
3211 : : if (wret == MLX5_TXCMP_CODE_ERROR)
3212 : : return MLX5_TXCMP_CODE_ERROR;
3213 : : }
3214 : : if (MLX5_TXOFF_CONFIG(INLINE)) {
3215 : : unsigned int inlen, vlan = 0;
3216 : :
3217 : 0 : inlen = rte_pktmbuf_data_len(loc->mbuf);
3218 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
3219 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
# # # # ]
3220 : : vlan = sizeof(struct rte_vlan_hdr);
3221 : 0 : inlen += vlan;
3222 : : }
3223 : : /*
3224 : : * If inlining is enabled at configuration time
3225 : : * the limit must be not less than minimal size.
3226 : : * Otherwise we would do extra check for data
3227 : : * size to avoid crashes due to length overflow.
3228 : : */
3229 : : MLX5_ASSERT(txq->inlen_send >=
3230 : : MLX5_ESEG_MIN_INLINE_SIZE);
3231 [ # # # # : 0 : if (inlen <= txq->inlen_send) {
# # # # #
# # # #
# ]
3232 : : unsigned int seg_n, wqe_n;
3233 : :
3234 : 0 : rte_prefetch0(rte_pktmbuf_mtod
3235 : : (loc->mbuf, uint8_t *));
3236 : : /* Check against minimal length. */
3237 [ # # # # : 0 : if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
# # # # #
# # # #
# ]
3238 : : return MLX5_TXCMP_CODE_ERROR;
3239 [ # # # # : 0 : if (loc->mbuf->ol_flags &
# # # # #
# # # #
# ]
3240 : : RTE_MBUF_F_TX_DYNF_NOINLINE) {
3241 : : /*
3242 : : * The hint flag not to inline packet
3243 : : * data is set. Check whether we can
3244 : : * follow the hint.
3245 : : */
3246 : : if ((!MLX5_TXOFF_CONFIG(EMPW) &&
3247 [ # # # # : 0 : txq->inlen_mode) ||
# # # # #
# # # #
# ]
3248 : : (MLX5_TXOFF_CONFIG(MPW) &&
3249 : : txq->inlen_mode)) {
3250 : : if (inlen <= txq->inlen_send)
3251 : 0 : goto single_inline;
3252 : : /*
3253 : : * The hardware requires the
3254 : : * minimal inline data header.
3255 : : */
3256 : : goto single_min_inline;
3257 : : }
3258 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
# # # # ]
3259 [ # # # # : 0 : vlan && !txq->vlan_en) {
# # # # ]
3260 : : /*
3261 : : * We must insert VLAN tag
3262 : : * by software means.
3263 : : */
3264 : 0 : goto single_part_inline;
3265 : : }
3266 : 0 : goto single_no_inline;
3267 : : }
3268 : 0 : single_inline:
3269 : : /*
3270 : : * Completely inlined packet data WQE:
3271 : : * - Control Segment, SEND opcode
3272 : : * - Ethernet Segment, no VLAN insertion
3273 : : * - Data inlined, VLAN optionally inserted
3274 : : * - Alignment to MLX5_WSEG_SIZE
3275 : : * Have to estimate amount of WQEBBs
3276 : : */
3277 : 0 : seg_n = (inlen + 3 * MLX5_WSEG_SIZE -
3278 : : MLX5_ESEG_MIN_INLINE_SIZE +
3279 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3280 : : /* Check if there are enough WQEBBs. */
3281 : 0 : wqe_n = (seg_n + 3) / 4;
3282 [ # # # # : 0 : if (wqe_n > loc->wqe_free)
# # # # #
# # # #
# ]
3283 : : return MLX5_TXCMP_CODE_EXIT;
3284 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
3285 : : loc->wqe_last = wqe;
3286 : : mlx5_tx_cseg_init(txq, loc, wqe, seg_n,
3287 : : MLX5_OPCODE_SEND, olx);
3288 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3289 : : mlx5_tx_eseg_data(txq, loc, wqe,
3290 : : vlan, inlen, 0, olx);
3291 : 0 : txq->wqe_ci += wqe_n;
3292 [ # # # # : 0 : loc->wqe_free -= wqe_n;
# # # # ]
3293 : : /*
3294 : : * Packet data are completely inlined,
3295 : : * free the packet immediately.
3296 : : */
3297 : : rte_pktmbuf_free_seg(loc->mbuf);
3298 : : } else if ((!MLX5_TXOFF_CONFIG(EMPW) ||
3299 : 0 : MLX5_TXOFF_CONFIG(MPW)) &&
3300 [ # # # # : 0 : txq->inlen_mode) {
# # # # #
# # # #
# ]
3301 : : /*
3302 : : * If minimal inlining is requested the eMPW
3303 : : * feature should be disabled due to data is
3304 : : * inlined into Ethernet Segment, which can
3305 : : * not contain inlined data for eMPW due to
3306 : : * segment shared for all packets.
3307 : : */
3308 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
3309 : : unsigned int ds;
3310 : : uint8_t *dptr;
3311 : :
3312 : : /*
3313 : : * The inline-mode settings require
3314 : : * to inline the specified amount of
3315 : : * data bytes to the Ethernet Segment.
3316 : : * We should check the free space in
3317 : : * WQE ring buffer to inline partially.
3318 : : */
3319 : 0 : single_min_inline:
3320 : : MLX5_ASSERT(txq->inlen_send >= txq->inlen_mode);
3321 : : MLX5_ASSERT(inlen > txq->inlen_mode);
3322 : : MLX5_ASSERT(txq->inlen_mode >=
3323 : : MLX5_ESEG_MIN_INLINE_SIZE);
3324 : : /*
3325 : : * Check whether there are enough free WQEBBs:
3326 : : * - Control Segment
3327 : : * - Ethernet Segment
3328 : : * - First Segment of inlined Ethernet data
3329 : : * - ... data continued ...
3330 : : * - Finishing Data Segment of pointer type
3331 : : */
3332 : 0 : ds = (MLX5_WQE_CSEG_SIZE +
3333 : : MLX5_WQE_ESEG_SIZE +
3334 : : MLX5_WQE_DSEG_SIZE +
3335 : 0 : txq->inlen_mode -
3336 : : MLX5_ESEG_MIN_INLINE_SIZE +
3337 : : MLX5_WQE_DSEG_SIZE +
3338 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3339 [ # # # # : 0 : if (loc->wqe_free < ((ds + 3) / 4))
# # # # #
# # # #
# ]
3340 : : return MLX5_TXCMP_CODE_EXIT;
3341 : : /*
3342 : : * Build the ordinary SEND WQE:
3343 : : * - Control Segment
3344 : : * - Ethernet Segment, inline inlen_mode bytes
3345 : : * - Data Segment of pointer type
3346 : : */
3347 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
3348 : : loc->wqe_last = wqe;
3349 : : mlx5_tx_cseg_init(txq, loc, wqe, ds,
3350 : : MLX5_OPCODE_SEND, olx);
3351 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3352 [ # # # # : 0 : dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan,
# # # # #
# # # #
# ]
3353 : : txq->inlen_mode,
3354 : : 0, olx);
3355 : 0 : dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
3356 : 0 : txq->inlen_mode - vlan;
3357 [ # # # # : 0 : inlen -= txq->inlen_mode;
# # # # #
# # # #
# ]
3358 : : mlx5_tx_dseg_ptr(txq, loc, dseg,
3359 : : dptr, inlen, olx);
3360 : : /*
3361 : : * WQE is built, update the loop parameters
3362 : : * and got to the next packet.
3363 : : */
3364 : 0 : txq->wqe_ci += (ds + 3) / 4;
3365 : 0 : loc->wqe_free -= (ds + 3) / 4;
3366 : : /* We have to store mbuf in elts.*/
3367 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
3368 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] =
3369 : : loc->mbuf;
3370 : 0 : --loc->elts_free;
3371 : : } else {
3372 : : uint8_t *dptr;
3373 : : unsigned int dlen;
3374 : :
3375 : : /*
3376 : : * Partially inlined packet data WQE, we have
3377 : : * some space in title WQEBB, we can fill it
3378 : : * with some packet data. It takes one WQEBB,
3379 : : * it is available, no extra space check:
3380 : : * - Control Segment, SEND opcode
3381 : : * - Ethernet Segment, no VLAN insertion
3382 : : * - MLX5_ESEG_MIN_INLINE_SIZE bytes of Data
3383 : : * - Data Segment, pointer type
3384 : : *
3385 : : * We also get here if VLAN insertion is not
3386 : : * supported by HW, the inline is enabled.
3387 : : */
3388 : 0 : single_part_inline:
3389 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
3390 : : loc->wqe_last = wqe;
3391 : : mlx5_tx_cseg_init(txq, loc, wqe, 4,
3392 : : MLX5_OPCODE_SEND, olx);
3393 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3394 : : mlx5_tx_eseg_dmin(txq, loc, wqe, vlan, olx);
3395 : 0 : dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
3396 : 0 : MLX5_ESEG_MIN_INLINE_SIZE - vlan;
3397 : : /*
3398 : : * The length check is performed above, by
3399 : : * comparing with txq->inlen_send. We should
3400 : : * not get overflow here.
3401 : : */
3402 : : MLX5_ASSERT(inlen > MLX5_ESEG_MIN_INLINE_SIZE);
3403 [ # # # # : 0 : dlen = inlen - MLX5_ESEG_MIN_INLINE_SIZE;
# # # # #
# # # #
# ]
3404 : : mlx5_tx_dseg_ptr(txq, loc, &wqe->dseg[1],
3405 : : dptr, dlen, olx);
3406 : 0 : ++txq->wqe_ci;
3407 : 0 : --loc->wqe_free;
3408 : : /* We have to store mbuf in elts.*/
3409 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
3410 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] =
3411 : : loc->mbuf;
3412 : 0 : --loc->elts_free;
3413 : : }
3414 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3415 : : /* Update sent data bytes counter. */
3416 : 0 : txq->stats.obytes += vlan +
3417 : 0 : rte_pktmbuf_data_len(loc->mbuf);
3418 : : #endif
3419 : : } else {
3420 : : /*
3421 : : * No inline at all, it means the CPU cycles saving
3422 : : * is prioritized at configuration, we should not
3423 : : * copy any packet data to WQE.
3424 : : *
3425 : : * SEND WQE, one WQEBB:
3426 : : * - Control Segment, SEND opcode
3427 : : * - Ethernet Segment, optional VLAN, no inline
3428 : : * - Data Segment, pointer type
3429 : : */
3430 : : single_no_inline:
3431 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3432 : : loc->wqe_last = wqe;
3433 : : mlx5_tx_cseg_init(txq, loc, wqe, 3,
3434 : : MLX5_OPCODE_SEND, olx);
3435 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3436 : : mlx5_tx_eseg_none(txq, loc, wqe, olx);
3437 : 0 : mlx5_tx_dseg_ptr
3438 : : (txq, loc, &wqe->dseg[0],
3439 : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3440 [ # # # # : 0 : rte_pktmbuf_data_len(loc->mbuf), olx);
# # # # #
# # # # #
# # # # #
# # # ]
3441 : 0 : ++txq->wqe_ci;
3442 : 0 : --loc->wqe_free;
3443 : : /*
3444 : : * We should not store mbuf pointer in elts
3445 : : * if no inlining is configured, this is done
3446 : : * by calling routine in a batch copy.
3447 : : */
3448 : : if (MLX5_TXOFF_CONFIG(INLINE))
3449 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] =
3450 : : loc->mbuf;
3451 : 0 : --loc->elts_free;
3452 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3453 : : /* Update sent data bytes counter. */
3454 : 0 : txq->stats.obytes += rte_pktmbuf_data_len(loc->mbuf);
3455 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
3456 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # # # #
# # # #
# ]
3457 : 0 : txq->stats.obytes +=
3458 : : sizeof(struct rte_vlan_hdr);
3459 : : #endif
3460 : : }
3461 : 0 : ++loc->pkts_sent;
3462 : 0 : --pkts_n;
3463 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3464 : : return MLX5_TXCMP_CODE_EXIT;
3465 : 0 : loc->mbuf = *pkts++;
3466 [ # # # # : 0 : if (pkts_n > 1)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3467 : 0 : rte_prefetch0(*pkts);
3468 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3469 [ # # # # : 0 : if (unlikely(ret != MLX5_TXCMP_CODE_SINGLE))
# # # # #
# # # #
# ]
3470 : : return ret;
3471 : : }
3472 : : MLX5_ASSERT(false);
3473 : : }
3474 : :
3475 : : static __rte_always_inline enum mlx5_txcmp_code
3476 : : mlx5_tx_burst_single(struct mlx5_txq_data *__rte_restrict txq,
3477 : : struct rte_mbuf **__rte_restrict pkts,
3478 : : unsigned int pkts_n,
3479 : : struct mlx5_txq_local *__rte_restrict loc,
3480 : : unsigned int olx)
3481 : : {
3482 : : enum mlx5_txcmp_code ret;
3483 : :
3484 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, false);
3485 : : if (ret == MLX5_TXCMP_CODE_SINGLE)
3486 : 0 : goto ordinary_send;
3487 : : MLX5_ASSERT(ret == MLX5_TXCMP_CODE_EMPW);
3488 : : for (;;) {
3489 : : /* Optimize for inline/no inline eMPW send. */
3490 : : ret = (MLX5_TXOFF_CONFIG(INLINE)) ?
3491 : : mlx5_tx_burst_empw_inline
3492 : : (txq, pkts, pkts_n, loc, olx) :
3493 : : mlx5_tx_burst_empw_simple
3494 : : (txq, pkts, pkts_n, loc, olx);
3495 [ # # # # : 0 : if (ret != MLX5_TXCMP_CODE_SINGLE)
# # ]
3496 : : return ret;
3497 : : /* The resources to send one packet should remain. */
3498 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3499 : 0 : ordinary_send:
3500 : : ret = mlx5_tx_burst_single_send(txq, pkts, pkts_n, loc, olx);
3501 : : MLX5_ASSERT(ret != MLX5_TXCMP_CODE_SINGLE);
3502 [ # # # # : 0 : if (ret != MLX5_TXCMP_CODE_EMPW)
# # # # #
# # # #
# ]
3503 : : return ret;
3504 : : /* The resources to send one packet should remain. */
3505 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3506 : : }
3507 : : }
3508 : :
3509 : : /**
3510 : : * DPDK Tx callback template. This is configured template used to generate
3511 : : * routines optimized for specified offload setup.
3512 : : * One of this generated functions is chosen at SQ configuration time.
3513 : : *
3514 : : * @param txq
3515 : : * Generic pointer to TX queue structure.
3516 : : * @param[in] pkts
3517 : : * Packets to transmit.
3518 : : * @param pkts_n
3519 : : * Number of packets in array.
3520 : : * @param olx
3521 : : * Configured offloads mask, presents the bits of MLX5_TXOFF_CONFIG_xxx
3522 : : * values. Should be static to take compile time static configuration
3523 : : * advantages.
3524 : : *
3525 : : * @return
3526 : : * Number of packets successfully transmitted (<= pkts_n).
3527 : : */
3528 : : static __rte_always_inline uint16_t
3529 : : mlx5_tx_burst_tmpl(struct mlx5_txq_data *__rte_restrict txq,
3530 : : struct rte_mbuf **__rte_restrict pkts,
3531 : : uint16_t pkts_n,
3532 : : unsigned int olx)
3533 : : {
3534 : : struct mlx5_txq_local loc;
3535 : : enum mlx5_txcmp_code ret;
3536 : : unsigned int part;
3537 : :
3538 : : MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
3539 : : MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
3540 [ # # # # : 0 : if (unlikely(!pkts_n))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3541 : : return 0;
3542 : : if (MLX5_TXOFF_CONFIG(INLINE))
3543 : : loc.mbuf_free = 0;
3544 : : loc.pkts_sent = 0;
3545 : : loc.pkts_copy = 0;
3546 : : loc.wqe_last = NULL;
3547 : :
3548 : 0 : send_loop:
3549 : : loc.pkts_loop = loc.pkts_sent;
3550 : : /*
3551 : : * Check if there are some CQEs, if any:
3552 : : * - process an encountered errors
3553 : : * - process the completed WQEs
3554 : : * - free related mbufs
3555 : : * - doorbell the NIC about processed CQEs
3556 : : */
3557 : 0 : rte_prefetch0(*(pkts + loc.pkts_sent));
3558 : 0 : mlx5_tx_handle_completion(txq);
3559 : : /*
3560 : : * Calculate the number of available resources - elts and WQEs.
3561 : : * There are two possible different scenarios:
3562 : : * - no data inlining into WQEs, one WQEBB may contains up to
3563 : : * four packets, in this case elts become scarce resource
3564 : : * - data inlining into WQEs, one packet may require multiple
3565 : : * WQEBBs, the WQEs become the limiting factor.
3566 : : */
3567 : : MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
3568 : 0 : loc.elts_free = txq->elts_s -
3569 : 0 : (uint16_t)(txq->elts_head - txq->elts_tail);
3570 : : MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
3571 : 0 : loc.wqe_free = txq->wqe_s -
3572 : 0 : (uint16_t)(txq->wqe_ci - txq->wqe_pi);
3573 [ # # # # : 0 : if (unlikely(!loc.elts_free || !loc.wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3574 : 0 : goto burst_exit;
3575 : : for (;;) {
3576 : : /*
3577 : : * Fetch the packet from array. Usually this is the first
3578 : : * packet in series of multi/single segment packets.
3579 : : */
3580 : 0 : loc.mbuf = *(pkts + loc.pkts_sent);
3581 : : /* Dedicated branch for multi-segment packets. */
3582 : 0 : if (MLX5_TXOFF_CONFIG(MULTI) &&
3583 [ # # # # : 0 : unlikely(NB_SEGS(loc.mbuf) > 1)) {
# # # # #
# # # ]
3584 : : /*
3585 : : * Multi-segment packet encountered.
3586 : : * Hardware is able to process it only
3587 : : * with SEND/TSO opcodes, one packet
3588 : : * per WQE, do it in dedicated routine.
3589 : : */
3590 : 0 : enter_send_multi:
3591 : : MLX5_ASSERT(loc.pkts_sent >= loc.pkts_copy);
3592 : 0 : part = loc.pkts_sent - loc.pkts_copy;
3593 [ # # # # : 0 : if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
# # ]
3594 : : /*
3595 : : * There are some single-segment mbufs not
3596 : : * stored in elts. The mbufs must be in the
3597 : : * same order as WQEs, so we must copy the
3598 : : * mbufs to elts here, before the coming
3599 : : * multi-segment packet mbufs is appended.
3600 : : */
3601 [ # # # # : 0 : mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy,
# # ]
3602 : : part, olx);
3603 : : loc.pkts_copy = loc.pkts_sent;
3604 : : }
3605 : : MLX5_ASSERT(pkts_n > loc.pkts_sent);
3606 : 0 : ret = mlx5_tx_burst_mseg(txq, pkts, pkts_n, &loc, olx);
3607 : : if (!MLX5_TXOFF_CONFIG(INLINE))
3608 : : loc.pkts_copy = loc.pkts_sent;
3609 : : /*
3610 : : * These returned code checks are supposed
3611 : : * to be optimized out due to routine inlining.
3612 : : */
3613 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_EXIT) {
# # # # #
# # # ]
3614 : : /*
3615 : : * The routine returns this code when
3616 : : * all packets are sent or there is no
3617 : : * enough resources to complete request.
3618 : : */
3619 : : break;
3620 : : }
3621 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_ERROR) {
# # # # #
# # # ]
3622 : : /*
3623 : : * The routine returns this code when some error
3624 : : * in the incoming packets format occurred.
3625 : : */
3626 : 0 : txq->stats.oerrors++;
3627 : 0 : break;
3628 : : }
3629 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_SINGLE) {
# # # # #
# # # ]
3630 : : /*
3631 : : * The single-segment packet was encountered
3632 : : * in the array, try to send it with the
3633 : : * best optimized way, possible engaging eMPW.
3634 : : */
3635 : 0 : goto enter_send_single;
3636 : : }
3637 : : if (MLX5_TXOFF_CONFIG(TSO) &&
3638 : : ret == MLX5_TXCMP_CODE_TSO) {
3639 : : /*
3640 : : * The single-segment TSO packet was
3641 : : * encountered in the array.
3642 : : */
3643 : 0 : goto enter_send_tso;
3644 : : }
3645 : : /* We must not get here. Something is going wrong. */
3646 : : MLX5_ASSERT(false);
3647 : : txq->stats.oerrors++;
3648 : : break;
3649 : : }
3650 : : /* Dedicated branch for single-segment TSO packets. */
3651 : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
3652 [ # # # # : 0 : unlikely(loc.mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
# # # # #
# # # ]
3653 : : /*
3654 : : * TSO might require special way for inlining
3655 : : * (dedicated parameters) and is sent with
3656 : : * MLX5_OPCODE_TSO opcode only, provide this
3657 : : * in dedicated branch.
3658 : : */
3659 : 0 : enter_send_tso:
3660 : : MLX5_ASSERT(NB_SEGS(loc.mbuf) == 1);
3661 : : MLX5_ASSERT(pkts_n > loc.pkts_sent);
3662 : 0 : ret = mlx5_tx_burst_tso(txq, pkts, pkts_n, &loc, olx);
3663 : : /*
3664 : : * These returned code checks are supposed
3665 : : * to be optimized out due to routine inlining.
3666 : : */
3667 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_EXIT)
# # # # #
# # # ]
3668 : : break;
3669 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_ERROR) {
# # # # #
# # # ]
3670 : 0 : txq->stats.oerrors++;
3671 : 0 : break;
3672 : : }
3673 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_SINGLE)
# # # # #
# # # ]
3674 : 0 : goto enter_send_single;
3675 : : if (MLX5_TXOFF_CONFIG(MULTI) &&
3676 : : ret == MLX5_TXCMP_CODE_MULTI) {
3677 : : /*
3678 : : * The multi-segment packet was
3679 : : * encountered in the array.
3680 : : */
3681 : 0 : goto enter_send_multi;
3682 : : }
3683 : : /* We must not get here. Something is going wrong. */
3684 : : MLX5_ASSERT(false);
3685 : : txq->stats.oerrors++;
3686 : : break;
3687 : : }
3688 : : /*
3689 : : * The dedicated branch for the single-segment packets
3690 : : * without TSO. Often these ones can be sent using
3691 : : * MLX5_OPCODE_EMPW with multiple packets in one WQE.
3692 : : * The routine builds the WQEs till it encounters
3693 : : * the TSO or multi-segment packet (in case if these
3694 : : * offloads are requested at SQ configuration time).
3695 : : */
3696 : 0 : enter_send_single:
3697 : : MLX5_ASSERT(pkts_n > loc.pkts_sent);
3698 [ # # # # : 0 : ret = mlx5_tx_burst_single(txq, pkts, pkts_n, &loc, olx);
# # # # #
# # # #
# ]
3699 : : /*
3700 : : * These returned code checks are supposed
3701 : : * to be optimized out due to routine inlining.
3702 : : */
3703 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_EXIT)
# # # # #
# # # # #
# # # # #
# ]
3704 : : break;
3705 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_ERROR) {
# # # # #
# ]
3706 : 0 : txq->stats.oerrors++;
3707 : 0 : break;
3708 : : }
3709 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(MULTI) &&
# # # # #
# # # ]
3710 : : ret == MLX5_TXCMP_CODE_MULTI) {
3711 : : /*
3712 : : * The multi-segment packet was
3713 : : * encountered in the array.
3714 : : */
3715 : 0 : goto enter_send_multi;
3716 : : }
3717 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
# # # # #
# # # ]
3718 : : ret == MLX5_TXCMP_CODE_TSO) {
3719 : : /*
3720 : : * The single-segment TSO packet was
3721 : : * encountered in the array.
3722 : : */
3723 : 0 : goto enter_send_tso;
3724 : : }
3725 : : /* We must not get here. Something is going wrong. */
3726 : : MLX5_ASSERT(false);
3727 : 0 : txq->stats.oerrors++;
3728 : 0 : break;
3729 : : }
3730 : : /*
3731 : : * Main Tx loop is completed, do the rest:
3732 : : * - set completion request if thresholds are reached
3733 : : * - doorbell the hardware
3734 : : * - copy the rest of mbufs to elts (if any)
3735 : : */
3736 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE) ||
3737 : : loc.pkts_sent >= loc.pkts_copy);
3738 : : /* Take a shortcut if nothing is sent. */
3739 [ # # # # : 0 : if (unlikely(loc.pkts_sent == loc.pkts_loop))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3740 : 0 : goto burst_exit;
3741 : : /* Request CQE generation if limits are reached. */
3742 : : if (MLX5_TXOFF_CONFIG(TXPP) && __rte_trace_point_fp_is_enabled())
3743 : : mlx5_tx_request_completion_trace(txq, &loc, olx);
3744 : : else
3745 : : mlx5_tx_request_completion(txq, &loc, olx);
3746 : : /*
3747 : : * Ring QP doorbell immediately after WQE building completion
3748 : : * to improve latencies. The pure software related data treatment
3749 : : * can be completed after doorbell. Tx CQEs for this SQ are
3750 : : * processed in this thread only by the polling.
3751 : : *
3752 : : * The rdma core library can map doorbell register in two ways,
3753 : : * depending on the environment variable "MLX5_SHUT_UP_BF":
3754 : : *
3755 : : * - as regular cached memory, the variable is either missing or
3756 : : * set to zero. This type of mapping may cause the significant
3757 : : * doorbell register writing latency and requires explicit memory
3758 : : * write barrier to mitigate this issue and prevent write combining.
3759 : : *
3760 : : * - as non-cached memory, the variable is present and set to not "0"
3761 : : * value. This type of mapping may cause performance impact under
3762 : : * heavy loading conditions but the explicit write memory barrier is
3763 : : * not required and it may improve core performance.
3764 : : *
3765 : : * - the legacy behaviour (prior 19.08 release) was to use some
3766 : : * heuristics to decide whether write memory barrier should
3767 : : * be performed. This behavior is supported with specifying
3768 : : * tx_db_nc=2, write barrier is skipped if application provides
3769 : : * the full recommended burst of packets, it supposes the next
3770 : : * packets are coming and the write barrier will be issued on
3771 : : * the next burst (after descriptor writing, at least).
3772 : : */
3773 : 0 : mlx5_doorbell_ring(mlx5_tx_bfreg(txq),
3774 : 0 : *(volatile uint64_t *)loc.wqe_last, txq->wqe_ci,
3775 [ # # # # : 0 : txq->qp_db, !txq->db_nc &&
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3776 [ # # # # : 0 : (!txq->db_heu || pkts_n % MLX5_TX_DEFAULT_BURST));
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3777 : : /* Not all of the mbufs may be stored into elts yet. */
3778 : : part = MLX5_TXOFF_CONFIG(INLINE) ? 0 : loc.pkts_sent - loc.pkts_copy;
3779 [ # # # # : 0 : if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
# # # # #
# # # # #
# # ]
3780 : : /*
3781 : : * There are some single-segment mbufs not stored in elts.
3782 : : * It can be only if the last packet was single-segment.
3783 : : * The copying is gathered into one place due to it is
3784 : : * a good opportunity to optimize that with SIMD.
3785 : : * Unfortunately if inlining is enabled the gaps in pointer
3786 : : * array may happen due to early freeing of the inlined mbufs.
3787 : : */
3788 [ # # # # : 0 : mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy, part, olx);
# # # # #
# # # # #
# # ]
3789 : : loc.pkts_copy = loc.pkts_sent;
3790 : : }
3791 : : MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
3792 : : MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
3793 [ # # # # : 0 : if (pkts_n > loc.pkts_sent) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3794 : : /*
3795 : : * If burst size is large there might be no enough CQE
3796 : : * fetched from completion queue and no enough resources
3797 : : * freed to send all the packets.
3798 : : */
3799 : 0 : goto send_loop;
3800 : : }
3801 : 0 : burst_exit:
3802 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3803 : : /* Increment sent packets counter. */
3804 : 0 : txq->stats.opackets += loc.pkts_sent;
3805 : : #endif
3806 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(INLINE) && loc.mbuf_free)
# # # # #
# # # #
# ]
3807 : 0 : __mlx5_tx_free_mbuf(txq, pkts, loc.mbuf_free);
3808 : : /* Trace productive bursts only. */
3809 : : if (__rte_trace_point_fp_is_enabled() && loc.pkts_sent)
3810 : : rte_pmd_mlx5_trace_tx_exit(mlx5_read_pcibar_clock_from_txq(txq),
3811 : : loc.pkts_sent, pkts_n);
3812 : : return loc.pkts_sent;
3813 : : }
3814 : :
3815 : : /**
3816 : : * Check whether given TxQ is external.
3817 : : *
3818 : : * @param dev
3819 : : * Pointer to Ethernet device.
3820 : : * @param queue_idx
3821 : : * Tx queue index.
3822 : : *
3823 : : * @return
3824 : : * True if is external TxQ, otherwise false.
3825 : : */
3826 : : static __rte_always_inline bool
3827 : : mlx5_is_external_txq(struct rte_eth_dev *dev, uint16_t queue_idx)
3828 : : {
3829 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3830 : : struct mlx5_external_q *txq;
3831 : :
3832 [ # # # # ]: 0 : if (!priv->ext_txqs || queue_idx < MLX5_EXTERNAL_TX_QUEUE_ID_MIN)
3833 : : return false;
3834 : 0 : txq = &priv->ext_txqs[queue_idx - MLX5_EXTERNAL_TX_QUEUE_ID_MIN];
3835 [ # # ]: 0 : return !!rte_atomic_load_explicit(&txq->refcnt, rte_memory_order_relaxed);
3836 : : }
3837 : :
3838 : : #endif /* RTE_PMD_MLX5_TX_H_ */
|