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