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 : 0 : 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 : 0 : 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 : : #ifdef RTE_ARCH_STRICT_ALIGN
1441 : : MLX5_ASSERT(dst == RTE_PTR_ALIGN(dst, sizeof(uint32_t)));
1442 : : *(uint32_t *)dst = *(unaligned_uint32_t *)src;
1443 : : dst += sizeof(uint32_t);
1444 : : src += sizeof(uint32_t);
1445 : : *(uint32_t *)dst = *(unaligned_uint32_t *)src;
1446 : : dst += sizeof(uint32_t);
1447 : : src += sizeof(uint32_t);
1448 : : #else
1449 : 0 : *(uint64_t *)dst = *(unaligned_uint64_t *)src;
1450 : 0 : dst += sizeof(uint64_t);
1451 : 0 : src += sizeof(uint64_t);
1452 : : #endif
1453 : : }
1454 [ # # # # : 0 : if (len & 0x04) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1455 : 0 : *(uint32_t *)dst = *(unaligned_uint32_t *)src;
1456 : 0 : dst += sizeof(uint32_t);
1457 : 0 : src += sizeof(uint32_t);
1458 : : }
1459 [ # # # # : 0 : if (len & 0x02) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1460 : 0 : *(uint16_t *)dst = *(unaligned_uint16_t *)src;
1461 : 0 : dst += sizeof(uint16_t);
1462 : 0 : src += sizeof(uint16_t);
1463 : : }
1464 [ # # # # : 0 : if (len & 0x01)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1465 : 0 : *(uint8_t *)dst = *(uint8_t *)src;
1466 : : }
1467 : :
1468 : : /**
1469 : : * Build the Data Segment of inlined data from single
1470 : : * segment packet, no VLAN insertion.
1471 : : *
1472 : : * @param txq
1473 : : * Pointer to TX queue structure.
1474 : : * @param loc
1475 : : * Pointer to burst routine local context.
1476 : : * @param dseg
1477 : : * Pointer to WQE to fill with built Data Segment.
1478 : : * @param buf
1479 : : * Data buffer to point.
1480 : : * @param len
1481 : : * Data buffer length.
1482 : : * @param olx
1483 : : * Configured Tx offloads mask. It is fully defined at
1484 : : * compile time and may be used for optimization.
1485 : : *
1486 : : * @return
1487 : : * Pointer to the next Data Segment after inlined data.
1488 : : * Ring buffer wraparound check is needed. We do not do it here because it
1489 : : * may not be needed for the last packet in the eMPW session.
1490 : : */
1491 : : static __rte_always_inline struct mlx5_wqe_dseg *
1492 : : mlx5_tx_dseg_empw(struct mlx5_txq_data *__rte_restrict txq,
1493 : : struct mlx5_txq_local *__rte_restrict loc __rte_unused,
1494 : : struct mlx5_wqe_dseg *__rte_restrict dseg,
1495 : : uint8_t *buf,
1496 : : unsigned int len,
1497 : : unsigned int olx __rte_unused)
1498 : : {
1499 : : unsigned int part;
1500 : : uint8_t *pdst;
1501 : :
1502 : : if (!MLX5_TXOFF_CONFIG(MPW)) {
1503 : : /* Store the descriptor byte counter for eMPW sessions. */
1504 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32(len | MLX5_ETH_WQE_DATA_INLINE);
# # # # #
# # # #
# ]
1505 : 0 : pdst = &dseg->inline_data[0];
1506 : : } else {
1507 : : /* The entire legacy MPW session counter is stored on close. */
1508 : : pdst = (uint8_t *)dseg;
1509 : : }
1510 : : /*
1511 : : * The WQEBB space availability is checked by caller.
1512 : : * Here we should be aware of WQE ring buffer wraparound only.
1513 : : */
1514 : 0 : part = (uint8_t *)txq->wqes_end - pdst;
1515 : 0 : part = RTE_MIN(part, len);
1516 : : do {
1517 [ # # # # : 0 : rte_memcpy(pdst, buf, part);
# # # # #
# # # #
# ]
1518 : 0 : len -= part;
1519 [ # # # # : 0 : if (likely(!len)) {
# # # # #
# # # #
# ]
1520 : 0 : pdst += part;
1521 : : if (!MLX5_TXOFF_CONFIG(MPW))
1522 : 0 : pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
1523 : : /* Note: no final wraparound check here. */
1524 : : return (struct mlx5_wqe_dseg *)pdst;
1525 : : }
1526 : 0 : pdst = (uint8_t *)txq->wqes;
1527 : 0 : buf += part;
1528 : : part = len;
1529 : : } while (true);
1530 : : }
1531 : :
1532 : : /**
1533 : : * Build the Data Segment of inlined data from single
1534 : : * segment packet with VLAN insertion.
1535 : : *
1536 : : * @param txq
1537 : : * Pointer to TX queue structure.
1538 : : * @param loc
1539 : : * Pointer to burst routine local context.
1540 : : * @param dseg
1541 : : * Pointer to the dseg fill with built Data Segment.
1542 : : * @param buf
1543 : : * Data buffer to point.
1544 : : * @param len
1545 : : * Data buffer length.
1546 : : * @param olx
1547 : : * Configured Tx offloads mask. It is fully defined at
1548 : : * compile time and may be used for optimization.
1549 : : *
1550 : : * @return
1551 : : * Pointer to the next Data Segment after inlined data.
1552 : : * Ring buffer wraparound check is needed.
1553 : : */
1554 : : static __rte_always_inline struct mlx5_wqe_dseg *
1555 : : mlx5_tx_dseg_vlan(struct mlx5_txq_data *__rte_restrict txq,
1556 : : struct mlx5_txq_local *__rte_restrict loc __rte_unused,
1557 : : struct mlx5_wqe_dseg *__rte_restrict dseg,
1558 : : uint8_t *buf,
1559 : : unsigned int len,
1560 : : unsigned int olx __rte_unused)
1561 : :
1562 : : {
1563 : : unsigned int part;
1564 : : uint8_t *pdst;
1565 : :
1566 : : MLX5_ASSERT(len > MLX5_ESEG_MIN_INLINE_SIZE);
1567 : : if (!MLX5_TXOFF_CONFIG(MPW)) {
1568 : : /* Store the descriptor byte counter for eMPW sessions. */
1569 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32
# # # # ]
1570 : : ((len + sizeof(struct rte_vlan_hdr)) |
1571 : : MLX5_ETH_WQE_DATA_INLINE);
1572 [ # # # # : 0 : pdst = &dseg->inline_data[0];
# # # # ]
1573 : : } else {
1574 : : /* The entire legacy MPW session counter is stored on close. */
1575 : : pdst = (uint8_t *)dseg;
1576 : : }
1577 : : memcpy(pdst, buf, MLX5_DSEG_MIN_INLINE_SIZE);
1578 : 0 : buf += MLX5_DSEG_MIN_INLINE_SIZE;
1579 : 0 : pdst += MLX5_DSEG_MIN_INLINE_SIZE;
1580 : 0 : len -= MLX5_DSEG_MIN_INLINE_SIZE;
1581 : : /* Insert VLAN ethertype + VLAN tag. Pointer is aligned. */
1582 : : MLX5_ASSERT(pdst == RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE));
1583 [ # # # # : 0 : if (unlikely(pdst >= (uint8_t *)txq->wqes_end))
# # # # ]
1584 : 0 : pdst = (uint8_t *)txq->wqes;
1585 [ # # # # : 0 : *(uint32_t *)pdst = rte_cpu_to_be_32((RTE_ETHER_TYPE_VLAN << 16) |
# # # # ]
1586 : : loc->mbuf->vlan_tci);
1587 : 0 : pdst += sizeof(struct rte_vlan_hdr);
1588 : : /*
1589 : : * The WQEBB space availability is checked by caller.
1590 : : * Here we should be aware of WQE ring buffer wraparound only.
1591 : : */
1592 : 0 : part = (uint8_t *)txq->wqes_end - pdst;
1593 : 0 : part = RTE_MIN(part, len);
1594 : : do {
1595 [ # # # # : 0 : rte_memcpy(pdst, buf, part);
# # # # ]
1596 : 0 : len -= part;
1597 [ # # # # : 0 : if (likely(!len)) {
# # # # ]
1598 : 0 : pdst += part;
1599 : : if (!MLX5_TXOFF_CONFIG(MPW))
1600 : 0 : pdst = RTE_PTR_ALIGN(pdst, MLX5_WSEG_SIZE);
1601 : : /* Note: no final wraparound check here. */
1602 : : return (struct mlx5_wqe_dseg *)pdst;
1603 : : }
1604 : 0 : pdst = (uint8_t *)txq->wqes;
1605 : 0 : buf += part;
1606 : : part = len;
1607 : : } while (true);
1608 : : }
1609 : :
1610 : : /**
1611 : : * Build the Ethernet Segment with optionally inlined data with
1612 : : * VLAN insertion and following Data Segments (if any) from
1613 : : * multi-segment packet. Used by ordinary send and TSO.
1614 : : *
1615 : : * @param txq
1616 : : * Pointer to TX queue structure.
1617 : : * @param loc
1618 : : * Pointer to burst routine local context.
1619 : : * @param wqe
1620 : : * Pointer to WQE to fill with built Ethernet/Data Segments.
1621 : : * @param vlan
1622 : : * Length of VLAN header to insert, 0 means no VLAN insertion.
1623 : : * @param inlen
1624 : : * Data length to inline. For TSO this parameter specifies exact value,
1625 : : * for ordinary send routine can be aligned by caller to provide better WQE
1626 : : * space saving and data buffer start address alignment.
1627 : : * This length includes VLAN header being inserted.
1628 : : * @param tso
1629 : : * Zero means ordinary send, inlined data can be extended,
1630 : : * otherwise this is TSO, inlined data length is fixed.
1631 : : * @param olx
1632 : : * Configured Tx offloads mask. It is fully defined at
1633 : : * compile time and may be used for optimization.
1634 : : *
1635 : : * @return
1636 : : * Actual size of built WQE in segments.
1637 : : */
1638 : : static __rte_always_inline unsigned int
1639 : : mlx5_tx_mseg_build(struct mlx5_txq_data *__rte_restrict txq,
1640 : : struct mlx5_txq_local *__rte_restrict loc,
1641 : : struct mlx5_wqe *__rte_restrict wqe,
1642 : : unsigned int vlan,
1643 : : unsigned int inlen,
1644 : : unsigned int tso,
1645 : : unsigned int olx __rte_unused)
1646 : : {
1647 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
1648 : : unsigned int ds;
1649 : :
1650 : : MLX5_ASSERT((rte_pktmbuf_pkt_len(loc->mbuf) + vlan) >= inlen);
1651 : : loc->mbuf_nseg = NB_SEGS(loc->mbuf);
1652 : : loc->mbuf_off = 0;
1653 : :
1654 : : dseg = mlx5_tx_eseg_mdat(txq, loc, wqe, vlan, inlen, tso, olx);
1655 [ # # # # : 0 : if (!loc->mbuf_nseg)
# # # # #
# # # # #
# # # # #
# ]
1656 : 0 : goto dseg_done;
1657 : : /*
1658 : : * There are still some mbuf remaining, not inlined.
1659 : : * The first mbuf may be partially inlined and we
1660 : : * must process the possible non-zero data offset.
1661 : : */
1662 [ # # # # : 0 : if (loc->mbuf_off) {
# # # # #
# # # # #
# # # # #
# ]
1663 : : unsigned int dlen;
1664 : : uint8_t *dptr;
1665 : :
1666 : : /*
1667 : : * Exhausted packets must be dropped before.
1668 : : * Non-zero offset means there are some data
1669 : : * remained in the packet.
1670 : : */
1671 : : MLX5_ASSERT(loc->mbuf_off < rte_pktmbuf_data_len(loc->mbuf));
1672 : : MLX5_ASSERT(rte_pktmbuf_data_len(loc->mbuf));
1673 : 0 : dptr = rte_pktmbuf_mtod_offset(loc->mbuf, uint8_t *,
1674 : : loc->mbuf_off);
1675 : 0 : dlen = rte_pktmbuf_data_len(loc->mbuf) - loc->mbuf_off;
1676 : : /*
1677 : : * Build the pointer/minimal Data Segment.
1678 : : * Do ring buffer wrapping check in advance.
1679 : : */
1680 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # # #
# # # # #
# ]
1681 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
1682 : : mlx5_tx_dseg_iptr(txq, loc, dseg, dptr, dlen, olx);
1683 : : /* Store the mbuf to be freed on completion. */
1684 : : MLX5_ASSERT(loc->elts_free);
1685 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
1686 : 0 : --loc->elts_free;
1687 : 0 : ++dseg;
1688 [ # # # # : 0 : if (--loc->mbuf_nseg == 0)
# # # # #
# # # # #
# # # # #
# ]
1689 : 0 : goto dseg_done;
1690 : 0 : loc->mbuf = loc->mbuf->next;
1691 : : loc->mbuf_off = 0;
1692 : : }
1693 : : do {
1694 [ # # # # : 0 : if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
# # # # #
# # # # #
# # # # #
# ]
1695 : : struct rte_mbuf *mbuf;
1696 : :
1697 : : /* Zero length segment found, just skip. */
1698 : : mbuf = loc->mbuf;
1699 : 0 : loc->mbuf = loc->mbuf->next;
1700 : : rte_pktmbuf_free_seg(mbuf);
1701 [ # # # # : 0 : if (--loc->mbuf_nseg == 0)
# # # # #
# # # # #
# # # # #
# ]
1702 : : break;
1703 : : } else {
1704 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # # #
# # # # #
# ]
1705 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
1706 : 0 : mlx5_tx_dseg_iptr
1707 : : (txq, loc, dseg,
1708 [ # # # # : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
# # # # #
# # # # #
# # # # #
# ]
1709 : : rte_pktmbuf_data_len(loc->mbuf), olx);
1710 : : MLX5_ASSERT(loc->elts_free);
1711 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
1712 : 0 : --loc->elts_free;
1713 : 0 : ++dseg;
1714 [ # # # # : 0 : if (--loc->mbuf_nseg == 0)
# # # # #
# # # # #
# # # # #
# ]
1715 : : break;
1716 : 0 : loc->mbuf = loc->mbuf->next;
1717 : : }
1718 : : } while (true);
1719 : :
1720 : 0 : dseg_done:
1721 : : /* Calculate actual segments used from the dseg pointer. */
1722 [ # # # # : 0 : if ((uintptr_t)wqe < (uintptr_t)dseg)
# # # # #
# # # # #
# # # # #
# ]
1723 : 0 : ds = ((uintptr_t)dseg - (uintptr_t)wqe) / MLX5_WSEG_SIZE;
1724 : : else
1725 : 0 : ds = (((uintptr_t)dseg - (uintptr_t)wqe) +
1726 : 0 : txq->wqe_s * MLX5_WQE_SIZE) / MLX5_WSEG_SIZE;
1727 : : return ds;
1728 : : }
1729 : :
1730 : : /**
1731 : : * The routine checks timestamp flag in the current packet,
1732 : : * and push WAIT WQE into the queue if scheduling is required.
1733 : : *
1734 : : * @param txq
1735 : : * Pointer to TX queue structure.
1736 : : * @param loc
1737 : : * Pointer to burst routine local context.
1738 : : * @param elts
1739 : : * Number of free elements in elts buffer to be checked, for zero
1740 : : * value the check is optimized out by compiler.
1741 : : * @param olx
1742 : : * Configured Tx offloads mask. It is fully defined at
1743 : : * compile time and may be used for optimization.
1744 : : *
1745 : : * @return
1746 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
1747 : : * MLX5_TXCMP_CODE_SINGLE - continue processing with the packet.
1748 : : * MLX5_TXCMP_CODE_MULTI - the WAIT inserted, continue processing.
1749 : : * Local context variables partially updated.
1750 : : */
1751 : : static __rte_always_inline enum mlx5_txcmp_code
1752 : : mlx5_tx_schedule_send(struct mlx5_txq_data *restrict txq,
1753 : : struct mlx5_txq_local *restrict loc,
1754 : : uint16_t elts,
1755 : : unsigned int olx)
1756 : : {
1757 : 0 : if (MLX5_TXOFF_CONFIG(TXPP) &&
1758 [ # # # # : 0 : loc->mbuf->ol_flags & txq->ts_mask) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
1759 : : struct mlx5_dev_ctx_shared *sh;
1760 : : struct mlx5_wqe *wqe;
1761 : : uint64_t ts;
1762 : :
1763 : : /*
1764 : : * Estimate the required space quickly and roughly.
1765 : : * We would like to ensure the packet can be pushed
1766 : : * to the queue and we won't get the orphan WAIT WQE.
1767 : : */
1768 [ # # # # : 0 : if (loc->wqe_free <= MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1769 : : loc->elts_free < elts)
1770 : : return MLX5_TXCMP_CODE_EXIT;
1771 : : /* Convert the timestamp into completion to wait. */
1772 : 0 : ts = *RTE_MBUF_DYNFIELD(loc->mbuf, txq->ts_offset, uint64_t *);
1773 [ # # # # : 0 : if (txq->ts_last && ts < txq->ts_last)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # ]
1774 : 0 : rte_atomic_fetch_add_explicit(&txq->sh->txpp.err_ts_order,
1775 : : 1, rte_memory_order_relaxed);
1776 : 0 : txq->ts_last = ts;
1777 : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
1778 : 0 : sh = txq->sh;
1779 [ # # # # : 0 : if (txq->wait_on_time) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1780 : : /* The wait on time capability should be used. */
1781 [ # # # # : 0 : ts -= sh->txpp.skew;
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1782 : : rte_pmd_mlx5_trace_tx_wait(ts);
1783 : : mlx5_tx_cseg_init(txq, loc, wqe,
1784 : : 1 + sizeof(struct mlx5_wqe_wseg) /
1785 : : MLX5_WSEG_SIZE,
1786 : : MLX5_OPCODE_WAIT |
1787 : : MLX5_OPC_MOD_WAIT_TIME << 24, olx);
1788 : : mlx5_tx_wseg_init(txq, loc, wqe, ts, olx);
1789 : : } else {
1790 : : /* Legacy cross-channel operation should be used. */
1791 : : int32_t wci;
1792 : :
1793 : : wci = mlx5_txpp_convert_tx_ts(sh, ts);
1794 [ # # # # : 0 : if (unlikely(wci < 0))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1795 : : return MLX5_TXCMP_CODE_SINGLE;
1796 : : /* Build the WAIT WQE with specified completion. */
1797 : : rte_pmd_mlx5_trace_tx_wait(ts - sh->txpp.skew);
1798 : : mlx5_tx_cseg_init(txq, loc, wqe,
1799 : : 1 + sizeof(struct mlx5_wqe_qseg) /
1800 : : MLX5_WSEG_SIZE,
1801 : : MLX5_OPCODE_WAIT |
1802 : : MLX5_OPC_MOD_WAIT_CQ_PI << 24, olx);
1803 [ # # # # : 0 : mlx5_tx_qseg_init(txq, loc, wqe, wci, olx);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
1804 : : }
1805 : 0 : ++txq->wqe_ci;
1806 : 0 : --loc->wqe_free;
1807 : : return MLX5_TXCMP_CODE_MULTI;
1808 : : }
1809 : : return MLX5_TXCMP_CODE_SINGLE;
1810 : : }
1811 : :
1812 : : /**
1813 : : * Tx one packet function for multi-segment TSO. Supports all
1814 : : * types of Tx offloads, uses MLX5_OPCODE_TSO to build WQEs,
1815 : : * sends one packet per WQE.
1816 : : *
1817 : : * This routine is responsible for storing processed mbuf
1818 : : * into elts ring buffer and update elts_head.
1819 : : *
1820 : : * @param txq
1821 : : * Pointer to TX queue structure.
1822 : : * @param loc
1823 : : * Pointer to burst routine local context.
1824 : : * @param olx
1825 : : * Configured Tx offloads mask. It is fully defined at
1826 : : * compile time and may be used for optimization.
1827 : : *
1828 : : * @return
1829 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
1830 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
1831 : : * Local context variables partially updated.
1832 : : */
1833 : : static __rte_always_inline enum mlx5_txcmp_code
1834 : : mlx5_tx_packet_multi_tso(struct mlx5_txq_data *__rte_restrict txq,
1835 : : struct mlx5_txq_local *__rte_restrict loc,
1836 : : unsigned int olx)
1837 : : {
1838 : : struct mlx5_wqe *__rte_restrict wqe;
1839 : : unsigned int ds, dlen, inlen, ntcp, vlan = 0;
1840 : :
1841 : : MLX5_ASSERT(loc->elts_free >= NB_SEGS(loc->mbuf));
1842 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
1843 : : enum mlx5_txcmp_code wret;
1844 : :
1845 : : /* Generate WAIT for scheduling if requested. */
1846 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
1847 : : if (wret == MLX5_TXCMP_CODE_EXIT)
1848 : : return MLX5_TXCMP_CODE_EXIT;
1849 : : if (wret == MLX5_TXCMP_CODE_ERROR)
1850 : : return MLX5_TXCMP_CODE_ERROR;
1851 : : }
1852 : : /*
1853 : : * Calculate data length to be inlined to estimate
1854 : : * the required space in WQE ring buffer.
1855 : : */
1856 : 0 : dlen = rte_pktmbuf_pkt_len(loc->mbuf);
1857 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # # # #
# ]
1858 : : vlan = sizeof(struct rte_vlan_hdr);
1859 : 0 : inlen = loc->mbuf->l2_len + vlan +
1860 : 0 : loc->mbuf->l3_len + loc->mbuf->l4_len;
1861 [ # # # # : 0 : if (unlikely((!inlen || !loc->mbuf->tso_segsz)))
# # # # #
# # # # #
# # # # #
# # # #
# ]
1862 : : return MLX5_TXCMP_CODE_ERROR;
1863 [ # # # # : 0 : if (loc->mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
# # # # #
# # # ]
1864 : 0 : inlen += loc->mbuf->outer_l2_len + loc->mbuf->outer_l3_len;
1865 : : /* Packet must contain all TSO headers. */
1866 [ # # # # : 0 : if (unlikely(inlen > MLX5_MAX_TSO_HEADER ||
# # # # #
# # # # #
# # # # #
# # # #
# ]
1867 : : inlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
1868 : : inlen > (dlen + vlan)))
1869 : : return MLX5_TXCMP_CODE_ERROR;
1870 : : /*
1871 : : * Check whether there are enough free WQEBBs:
1872 : : * - Control Segment
1873 : : * - Ethernet Segment
1874 : : * - First Segment of inlined Ethernet data
1875 : : * - ... data continued ...
1876 : : * - Data Segments of pointer/min inline type
1877 : : */
1878 : 0 : ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
1879 : : MLX5_ESEG_MIN_INLINE_SIZE +
1880 : : MLX5_WSEG_SIZE +
1881 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
1882 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
# # # # #
# # # ]
1883 : : return MLX5_TXCMP_CODE_EXIT;
1884 : : /* Check for maximal WQE size. */
1885 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds))
# # # # #
# # # ]
1886 : : return MLX5_TXCMP_CODE_ERROR;
1887 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1888 : : /* Update sent data bytes/packets counters. */
1889 : 0 : ntcp = (dlen - (inlen - vlan) + loc->mbuf->tso_segsz - 1) /
1890 : : loc->mbuf->tso_segsz;
1891 : : /*
1892 : : * One will be added for mbuf itself at the end of the mlx5_tx_burst
1893 : : * from loc->pkts_sent field.
1894 : : */
1895 : 0 : --ntcp;
1896 : 0 : txq->stats.opackets += ntcp;
1897 : 0 : txq->stats.obytes += dlen + vlan + ntcp * inlen;
1898 : : #endif
1899 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # ]
1900 : : loc->wqe_last = wqe;
1901 : : mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_TSO, olx);
1902 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
1903 : : ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 1, olx);
1904 [ # # # # : 0 : wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
# # # # #
# # # ]
1905 : 0 : txq->wqe_ci += (ds + 3) / 4;
1906 : 0 : loc->wqe_free -= (ds + 3) / 4;
1907 : : return MLX5_TXCMP_CODE_MULTI;
1908 : : }
1909 : :
1910 : : /**
1911 : : * Tx one packet function for multi-segment SEND. Supports all types of Tx
1912 : : * offloads, uses MLX5_OPCODE_SEND to build WQEs, sends one packet per WQE,
1913 : : * without any data inlining in Ethernet Segment.
1914 : : *
1915 : : * This routine is responsible for storing processed mbuf
1916 : : * into elts ring buffer and update elts_head.
1917 : : *
1918 : : * @param txq
1919 : : * Pointer to TX queue structure.
1920 : : * @param loc
1921 : : * Pointer to burst routine local context.
1922 : : * @param olx
1923 : : * Configured Tx offloads mask. It is fully defined at
1924 : : * compile time and may be used for optimization.
1925 : : *
1926 : : * @return
1927 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
1928 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
1929 : : * Local context variables partially updated.
1930 : : */
1931 : : static __rte_always_inline enum mlx5_txcmp_code
1932 : : mlx5_tx_packet_multi_send(struct mlx5_txq_data *__rte_restrict txq,
1933 : : struct mlx5_txq_local *__rte_restrict loc,
1934 : : unsigned int olx)
1935 : : {
1936 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
1937 : : struct mlx5_wqe *__rte_restrict wqe;
1938 : : unsigned int ds, nseg;
1939 : :
1940 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
1941 : : MLX5_ASSERT(loc->elts_free >= NB_SEGS(loc->mbuf));
1942 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
1943 : : enum mlx5_txcmp_code wret;
1944 : :
1945 : : /* Generate WAIT for scheduling if requested. */
1946 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
1947 : : if (wret == MLX5_TXCMP_CODE_EXIT)
1948 : : return MLX5_TXCMP_CODE_EXIT;
1949 : : if (wret == MLX5_TXCMP_CODE_ERROR)
1950 : : return MLX5_TXCMP_CODE_ERROR;
1951 : : }
1952 : : /*
1953 : : * No inline at all, it means the CPU cycles saving is prioritized at
1954 : : * configuration, we should not copy any packet data to WQE.
1955 : : */
1956 : 0 : nseg = NB_SEGS(loc->mbuf);
1957 : 0 : ds = 2 + nseg;
1958 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
# # # # #
# # # ]
1959 : : return MLX5_TXCMP_CODE_EXIT;
1960 : : /* Check for maximal WQE size. */
1961 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds))
# # # # #
# # # ]
1962 : : return MLX5_TXCMP_CODE_ERROR;
1963 : : /*
1964 : : * Some Tx offloads may cause an error if packet is not long enough,
1965 : : * check against assumed minimal length.
1966 : : */
1967 [ # # # # : 0 : if (rte_pktmbuf_pkt_len(loc->mbuf) <= MLX5_ESEG_MIN_INLINE_SIZE)
# # # # #
# # # ]
1968 : : return MLX5_TXCMP_CODE_ERROR;
1969 : : #ifdef MLX5_PMD_SOFT_COUNTERS
1970 : : /* Update sent data bytes counter. */
1971 : 0 : txq->stats.obytes += rte_pktmbuf_pkt_len(loc->mbuf);
1972 [ # # # # ]: 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
1973 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # # # #
# ]
1974 : 0 : txq->stats.obytes += sizeof(struct rte_vlan_hdr);
1975 : : #endif
1976 : : /*
1977 : : * SEND WQE, one WQEBB:
1978 : : * - Control Segment, SEND opcode
1979 : : * - Ethernet Segment, optional VLAN, no inline
1980 : : * - Data Segments, pointer only type
1981 : : */
1982 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # ]
1983 : : loc->wqe_last = wqe;
1984 : : mlx5_tx_cseg_init(txq, loc, wqe, ds, MLX5_OPCODE_SEND, olx);
1985 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
1986 : : mlx5_tx_eseg_none(txq, loc, wqe, olx);
1987 : 0 : dseg = &wqe->dseg[0];
1988 : : do {
1989 [ # # # # : 0 : if (unlikely(!rte_pktmbuf_data_len(loc->mbuf))) {
# # # # #
# # # ]
1990 : : struct rte_mbuf *mbuf;
1991 : :
1992 : : /*
1993 : : * Zero length segment found, have to correct total
1994 : : * size of WQE in segments.
1995 : : * It is supposed to be rare occasion, so in normal
1996 : : * case (no zero length segments) we avoid extra
1997 : : * writing to the Control Segment.
1998 : : */
1999 : 0 : --ds;
2000 : 0 : wqe->cseg.sq_ds -= RTE_BE32(1);
2001 : : mbuf = loc->mbuf;
2002 [ # # ]: 0 : loc->mbuf = mbuf->next;
2003 : : rte_pktmbuf_free_seg(mbuf);
2004 [ # # # # : 0 : if (--nseg == 0)
# # # # #
# # # ]
2005 : : break;
2006 : : } else {
2007 : 0 : mlx5_tx_dseg_ptr
2008 : : (txq, loc, dseg,
2009 [ # # # # : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
# # # # #
# # # ]
2010 : : rte_pktmbuf_data_len(loc->mbuf), olx);
2011 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2012 : 0 : --loc->elts_free;
2013 [ # # # # : 0 : if (--nseg == 0)
# # # # #
# # # ]
2014 : : break;
2015 : 0 : ++dseg;
2016 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # ]
2017 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2018 : 0 : loc->mbuf = loc->mbuf->next;
2019 : : }
2020 : : } while (true);
2021 : 0 : txq->wqe_ci += (ds + 3) / 4;
2022 : 0 : loc->wqe_free -= (ds + 3) / 4;
2023 : : return MLX5_TXCMP_CODE_MULTI;
2024 : : }
2025 : :
2026 : : /**
2027 : : * Tx one packet function for multi-segment SEND. Supports all
2028 : : * types of Tx offloads, uses MLX5_OPCODE_SEND to build WQEs,
2029 : : * sends one packet per WQE, with data inlining in
2030 : : * Ethernet Segment and minimal Data Segments.
2031 : : *
2032 : : * This routine is responsible for storing processed mbuf
2033 : : * into elts ring buffer and update elts_head.
2034 : : *
2035 : : * @param txq
2036 : : * Pointer to TX queue structure.
2037 : : * @param loc
2038 : : * Pointer to burst routine local context.
2039 : : * @param olx
2040 : : * Configured Tx offloads mask. It is fully defined at
2041 : : * compile time and may be used for optimization.
2042 : : *
2043 : : * @return
2044 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2045 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2046 : : * Local context variables partially updated.
2047 : : */
2048 : : static __rte_always_inline enum mlx5_txcmp_code
2049 : : mlx5_tx_packet_multi_inline(struct mlx5_txq_data *__rte_restrict txq,
2050 : : struct mlx5_txq_local *__rte_restrict loc,
2051 : : unsigned int olx)
2052 : : {
2053 : : struct mlx5_wqe *__rte_restrict wqe;
2054 : : unsigned int ds, inlen, dlen, vlan = 0;
2055 : :
2056 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
2057 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
2058 : : MLX5_ASSERT(loc->elts_free >= NB_SEGS(loc->mbuf));
2059 : : /*
2060 : : * First calculate data length to be inlined
2061 : : * to estimate the required space for WQE.
2062 : : */
2063 : 0 : dlen = rte_pktmbuf_pkt_len(loc->mbuf);
2064 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) && loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # ]
2065 : : vlan = sizeof(struct rte_vlan_hdr);
2066 : 0 : inlen = dlen + vlan;
2067 : : /* Check against minimal length. */
2068 [ # # # # : 0 : if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
# # # # ]
2069 : : return MLX5_TXCMP_CODE_ERROR;
2070 : : MLX5_ASSERT(txq->inlen_send >= MLX5_ESEG_MIN_INLINE_SIZE);
2071 [ # # # # : 0 : if (inlen > txq->inlen_send ||
# # # # ]
2072 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE) {
# # # # ]
2073 : : struct rte_mbuf *mbuf;
2074 : : unsigned int nxlen;
2075 : : uintptr_t start;
2076 : :
2077 : : mbuf = loc->mbuf;
2078 : 0 : nxlen = rte_pktmbuf_data_len(mbuf) + vlan;
2079 : : /*
2080 : : * Packet length exceeds the allowed inline data length,
2081 : : * check whether the minimal inlining is required.
2082 : : */
2083 [ # # # # : 0 : if (txq->inlen_mode) {
# # # # ]
2084 : : MLX5_ASSERT(txq->inlen_mode >=
2085 : : MLX5_ESEG_MIN_INLINE_SIZE);
2086 : : MLX5_ASSERT(txq->inlen_mode <= txq->inlen_send);
2087 : 0 : inlen = RTE_MIN(txq->inlen_mode, inlen);
2088 [ # # # # : 0 : } else if (vlan && !txq->vlan_en) {
# # # # #
# # # ]
2089 : : /*
2090 : : * VLAN insertion is requested and hardware does not
2091 : : * support the offload, will do with software inline.
2092 : : */
2093 : : inlen = MLX5_ESEG_MIN_INLINE_SIZE;
2094 [ # # # # : 0 : } else if (mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE ||
# # # # #
# # # # #
# # ]
2095 : : nxlen > txq->inlen_send) {
2096 : : return mlx5_tx_packet_multi_send(txq, loc, olx);
2097 [ # # # # : 0 : } else if (nxlen <= MLX5_ESEG_MIN_INLINE_SIZE) {
# # # # ]
2098 : : inlen = MLX5_ESEG_MIN_INLINE_SIZE;
2099 : : } else {
2100 : 0 : goto do_first;
2101 : : }
2102 [ # # # # : 0 : if (mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE)
# # # # ]
2103 : 0 : goto do_build;
2104 : : /*
2105 : : * Now we know the minimal amount of data is requested
2106 : : * to inline. Check whether we should inline the buffers
2107 : : * from the chain beginning to eliminate some mbufs.
2108 : : */
2109 [ # # # # : 0 : if (unlikely(nxlen <= txq->inlen_send)) {
# # # # ]
2110 : : /* We can inline first mbuf at least. */
2111 [ # # # # : 0 : if (nxlen < inlen) {
# # # # ]
2112 : : unsigned int smlen;
2113 : :
2114 : : /* Scan mbufs till inlen filled. */
2115 : : do {
2116 : : smlen = nxlen;
2117 : 0 : mbuf = NEXT(mbuf);
2118 : : MLX5_ASSERT(mbuf);
2119 : 0 : nxlen = rte_pktmbuf_data_len(mbuf);
2120 : 0 : nxlen += smlen;
2121 [ # # # # : 0 : } while (unlikely(nxlen < inlen));
# # # # ]
2122 [ # # # # : 0 : if (unlikely(nxlen > txq->inlen_send)) {
# # # # ]
2123 : : /* We cannot inline entire mbuf. */
2124 : 0 : smlen = inlen - smlen;
2125 : 0 : start = rte_pktmbuf_mtod_offset
2126 : : (mbuf, uintptr_t, smlen);
2127 : 0 : goto do_align;
2128 : : }
2129 : : }
2130 : 0 : do_first:
2131 : : do {
2132 : : inlen = nxlen;
2133 : 0 : mbuf = NEXT(mbuf);
2134 : : /* There should be not end of packet. */
2135 : : MLX5_ASSERT(mbuf);
2136 [ # # # # : 0 : if (mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE)
# # # # ]
2137 : : break;
2138 : 0 : nxlen = inlen + rte_pktmbuf_data_len(mbuf);
2139 [ # # # # : 0 : } while (unlikely(nxlen < txq->inlen_send));
# # # # ]
2140 : : }
2141 : 0 : start = rte_pktmbuf_mtod(mbuf, uintptr_t);
2142 : : /*
2143 : : * Check whether we can do inline to align start
2144 : : * address of data buffer to cacheline.
2145 : : */
2146 : 0 : do_align:
2147 : 0 : start = (~start + 1) & (RTE_CACHE_LINE_SIZE - 1);
2148 [ # # # # : 0 : if (unlikely(start)) {
# # # # ]
2149 : 0 : start += inlen;
2150 [ # # # # : 0 : if (start <= txq->inlen_send)
# # # # ]
2151 : 0 : inlen = start;
2152 : : }
2153 : : }
2154 : : /*
2155 : : * Check whether there are enough free WQEBBs:
2156 : : * - Control Segment
2157 : : * - Ethernet Segment
2158 : : * - First Segment of inlined Ethernet data
2159 : : * - ... data continued ...
2160 : : * - Data Segments of pointer/min inline type
2161 : : *
2162 : : * Estimate the number of Data Segments conservatively,
2163 : : * supposing no any mbufs is being freed during inlining.
2164 : : */
2165 [ # # # # : 0 : do_build:
# # # # ]
2166 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2167 : : enum mlx5_txcmp_code wret;
2168 : :
2169 : : /* Generate WAIT for scheduling if requested. */
2170 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
2171 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2172 : : return MLX5_TXCMP_CODE_EXIT;
2173 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2174 : : return MLX5_TXCMP_CODE_ERROR;
2175 : : }
2176 : : MLX5_ASSERT(inlen <= txq->inlen_send);
2177 : 0 : ds = NB_SEGS(loc->mbuf) + 2 + (inlen -
2178 : : MLX5_ESEG_MIN_INLINE_SIZE +
2179 : : MLX5_WSEG_SIZE +
2180 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
2181 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((ds + 3) / 4)))
# # # # ]
2182 : : return MLX5_TXCMP_CODE_EXIT;
2183 : : /* Check for maximal WQE size. */
2184 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds)) {
# # # # ]
2185 : : /* Check if we can adjust the inline length. */
2186 [ # # # # : 0 : if (unlikely(txq->inlen_mode)) {
# # # # ]
2187 : 0 : ds = NB_SEGS(loc->mbuf) + 2 +
2188 : 0 : (txq->inlen_mode -
2189 : : MLX5_ESEG_MIN_INLINE_SIZE +
2190 : : MLX5_WSEG_SIZE +
2191 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
2192 [ # # # # : 0 : if (unlikely((MLX5_WQE_SIZE_MAX / MLX5_WSEG_SIZE) < ds))
# # # # ]
2193 : : return MLX5_TXCMP_CODE_ERROR;
2194 : : }
2195 : : /* We have lucky opportunity to adjust. */
2196 : 0 : inlen = RTE_MIN(inlen, MLX5_WQE_SIZE_MAX -
2197 : : MLX5_WSEG_SIZE * 2 -
2198 : : MLX5_WSEG_SIZE * NB_SEGS(loc->mbuf) -
2199 : : MLX5_WSEG_SIZE +
2200 : : MLX5_ESEG_MIN_INLINE_SIZE);
2201 : : }
2202 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2203 : : /* Update sent data bytes/packets counters. */
2204 : 0 : txq->stats.obytes += dlen + vlan;
2205 : : #endif
2206 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # ]
2207 : : loc->wqe_last = wqe;
2208 : : mlx5_tx_cseg_init(txq, loc, wqe, 0, MLX5_OPCODE_SEND, olx);
2209 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
2210 : : ds = mlx5_tx_mseg_build(txq, loc, wqe, vlan, inlen, 0, olx);
2211 [ # # # # : 0 : wqe->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
# # # # ]
2212 : 0 : txq->wqe_ci += (ds + 3) / 4;
2213 : 0 : loc->wqe_free -= (ds + 3) / 4;
2214 : : return MLX5_TXCMP_CODE_MULTI;
2215 : : }
2216 : :
2217 : : /**
2218 : : * Tx burst function for multi-segment packets. Supports all
2219 : : * types of Tx offloads, uses MLX5_OPCODE_SEND/TSO to build WQEs,
2220 : : * sends one packet per WQE. Function stops sending if it
2221 : : * encounters the single-segment packet.
2222 : : *
2223 : : * This routine is responsible for storing processed mbuf
2224 : : * into elts ring buffer and update elts_head.
2225 : : *
2226 : : * @param txq
2227 : : * Pointer to TX queue structure.
2228 : : * @param[in] pkts
2229 : : * Packets to transmit.
2230 : : * @param pkts_n
2231 : : * Number of packets in array.
2232 : : * @param loc
2233 : : * Pointer to burst routine local context.
2234 : : * @param olx
2235 : : * Configured Tx offloads mask. It is fully defined at
2236 : : * compile time and may be used for optimization.
2237 : : *
2238 : : * @return
2239 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2240 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2241 : : * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
2242 : : * MLX5_TXCMP_CODE_TSO - TSO single-segment packet encountered.
2243 : : * Local context variables updated.
2244 : : */
2245 : : static __rte_always_inline enum mlx5_txcmp_code
2246 : : mlx5_tx_burst_mseg(struct mlx5_txq_data *__rte_restrict txq,
2247 : : struct rte_mbuf **__rte_restrict pkts,
2248 : : unsigned int pkts_n,
2249 : : struct mlx5_txq_local *__rte_restrict loc,
2250 : : unsigned int olx)
2251 : : {
2252 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2253 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2254 : 0 : pkts += loc->pkts_sent + 1;
2255 : 0 : pkts_n -= loc->pkts_sent;
2256 : 0 : for (;;) {
2257 : : enum mlx5_txcmp_code ret;
2258 : :
2259 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) > 1);
2260 : : /*
2261 : : * Estimate the number of free elts quickly but conservatively.
2262 : : * Some segment may be fully inlined and freed,
2263 : : * ignore this here - precise estimation is costly.
2264 : : */
2265 [ # # # # : 0 : if (loc->elts_free < NB_SEGS(loc->mbuf))
# # # # #
# # # ]
2266 : : return MLX5_TXCMP_CODE_EXIT;
2267 : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
2268 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
# # # # #
# # # ]
2269 : : /* Proceed with multi-segment TSO. */
2270 : : ret = mlx5_tx_packet_multi_tso(txq, loc, olx);
2271 : : } else if (MLX5_TXOFF_CONFIG(INLINE)) {
2272 : : /* Proceed with multi-segment SEND with inlining. */
2273 : : ret = mlx5_tx_packet_multi_inline(txq, loc, olx);
2274 : : } else {
2275 : : /* Proceed with multi-segment SEND w/o inlining. */
2276 : : ret = mlx5_tx_packet_multi_send(txq, loc, olx);
2277 : : }
2278 : : if (ret == MLX5_TXCMP_CODE_EXIT)
2279 : : return MLX5_TXCMP_CODE_EXIT;
2280 : : if (ret == MLX5_TXCMP_CODE_ERROR)
2281 : : return MLX5_TXCMP_CODE_ERROR;
2282 : : /* WQE is built, go to the next packet. */
2283 : 0 : ++loc->pkts_sent;
2284 : 0 : --pkts_n;
2285 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2286 : : return MLX5_TXCMP_CODE_EXIT;
2287 : 0 : loc->mbuf = *pkts++;
2288 [ # # # # : 0 : if (pkts_n > 1)
# # # # #
# # # ]
2289 : 0 : rte_prefetch0(*pkts);
2290 [ # # # # : 0 : if (likely(NB_SEGS(loc->mbuf) > 1))
# # # # #
# # # ]
2291 : : continue;
2292 : : /* Here ends the series of multi-segment packets. */
2293 : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
2294 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG))
# # # # #
# # # ]
2295 : 0 : return MLX5_TXCMP_CODE_TSO;
2296 : : return MLX5_TXCMP_CODE_SINGLE;
2297 : : }
2298 : : MLX5_ASSERT(false);
2299 : : }
2300 : :
2301 : : /**
2302 : : * Tx burst function for single-segment packets with TSO.
2303 : : * Supports all types of Tx offloads, except multi-packets.
2304 : : * Uses MLX5_OPCODE_TSO to build WQEs, sends one packet per WQE.
2305 : : * Function stops sending if it encounters the multi-segment
2306 : : * packet or packet without TSO requested.
2307 : : *
2308 : : * The routine is responsible for storing processed mbuf into elts ring buffer
2309 : : * and update elts_head if inline offloads is requested due to possible early
2310 : : * freeing of the inlined mbufs (can not store pkts array in elts as a batch).
2311 : : *
2312 : : * @param txq
2313 : : * Pointer to TX queue structure.
2314 : : * @param[in] pkts
2315 : : * Packets to transmit.
2316 : : * @param pkts_n
2317 : : * Number of packets in array.
2318 : : * @param loc
2319 : : * Pointer to burst routine local context.
2320 : : * @param olx
2321 : : * Configured Tx offloads mask. It is fully defined at
2322 : : * compile time and may be used for optimization.
2323 : : *
2324 : : * @return
2325 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2326 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2327 : : * MLX5_TXCMP_CODE_SINGLE - single-segment packet encountered.
2328 : : * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
2329 : : * Local context variables updated.
2330 : : */
2331 : : static __rte_always_inline enum mlx5_txcmp_code
2332 : : mlx5_tx_burst_tso(struct mlx5_txq_data *__rte_restrict txq,
2333 : : struct rte_mbuf **__rte_restrict pkts,
2334 : : unsigned int pkts_n,
2335 : : struct mlx5_txq_local *__rte_restrict loc,
2336 : : unsigned int olx)
2337 : : {
2338 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2339 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2340 : 0 : pkts += loc->pkts_sent + 1;
2341 : 0 : pkts_n -= loc->pkts_sent;
2342 : : for (;;) {
2343 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
2344 : : struct mlx5_wqe *__rte_restrict wqe;
2345 : : unsigned int ds, dlen, hlen, ntcp, vlan = 0;
2346 : : uint8_t *dptr;
2347 : :
2348 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2349 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2350 : : enum mlx5_txcmp_code wret;
2351 : :
2352 : : /* Generate WAIT for scheduling if requested. */
2353 : : wret = mlx5_tx_schedule_send(txq, loc, 1, olx);
2354 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2355 : : return MLX5_TXCMP_CODE_EXIT;
2356 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2357 : : return MLX5_TXCMP_CODE_ERROR;
2358 : : }
2359 : 0 : dlen = rte_pktmbuf_data_len(loc->mbuf);
2360 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
2361 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
# # # # #
# ]
2362 : : vlan = sizeof(struct rte_vlan_hdr);
2363 : : }
2364 : : /*
2365 : : * First calculate the WQE size to check
2366 : : * whether we have enough space in ring buffer.
2367 : : */
2368 : 0 : hlen = loc->mbuf->l2_len + vlan +
2369 : 0 : loc->mbuf->l3_len + loc->mbuf->l4_len;
2370 [ # # # # : 0 : if (unlikely((!hlen || !loc->mbuf->tso_segsz)))
# # # # #
# # # # #
# # # # #
# # # #
# ]
2371 : : return MLX5_TXCMP_CODE_ERROR;
2372 [ # # # # : 0 : if (loc->mbuf->ol_flags & RTE_MBUF_F_TX_TUNNEL_MASK)
# # # # #
# # # ]
2373 : 0 : hlen += loc->mbuf->outer_l2_len +
2374 : 0 : loc->mbuf->outer_l3_len;
2375 : : /* Segment must contain all TSO headers. */
2376 [ # # # # : 0 : if (unlikely(hlen > MLX5_MAX_TSO_HEADER ||
# # # # #
# # # # #
# # # # #
# # # #
# ]
2377 : : hlen <= MLX5_ESEG_MIN_INLINE_SIZE ||
2378 : : hlen > (dlen + vlan)))
2379 : : return MLX5_TXCMP_CODE_ERROR;
2380 : : /*
2381 : : * Check whether there are enough free WQEBBs:
2382 : : * - Control Segment
2383 : : * - Ethernet Segment
2384 : : * - First Segment of inlined Ethernet data
2385 : : * - ... data continued ...
2386 : : * - Finishing Data Segment of pointer type
2387 : : */
2388 : 0 : ds = 4 + (hlen - MLX5_ESEG_MIN_INLINE_SIZE +
2389 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
2390 [ # # # # : 0 : if (loc->wqe_free < ((ds + 3) / 4))
# # # # #
# # # ]
2391 : : return MLX5_TXCMP_CODE_EXIT;
2392 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2393 : : /* Update sent data bytes/packets counters. */
2394 : 0 : ntcp = (dlen + vlan - hlen +
2395 : 0 : loc->mbuf->tso_segsz - 1) /
2396 : : loc->mbuf->tso_segsz;
2397 : : /*
2398 : : * One will be added for mbuf itself at the end
2399 : : * of the mlx5_tx_burst from loc->pkts_sent field.
2400 : : */
2401 : 0 : --ntcp;
2402 : 0 : txq->stats.opackets += ntcp;
2403 : 0 : txq->stats.obytes += dlen + vlan + ntcp * hlen;
2404 : : #endif
2405 : : /*
2406 : : * Build the TSO WQE:
2407 : : * - Control Segment
2408 : : * - Ethernet Segment with hlen bytes inlined
2409 : : * - Data Segment of pointer type
2410 : : */
2411 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # ]
2412 : : loc->wqe_last = wqe;
2413 : : mlx5_tx_cseg_init(txq, loc, wqe, ds, MLX5_OPCODE_TSO, olx);
2414 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
2415 : : dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan, hlen, 1, olx);
2416 [ # # # # : 0 : dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) + hlen - vlan;
# # ]
2417 [ # # # # : 0 : dlen -= hlen - vlan;
# # # # #
# ]
2418 : : mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
2419 : : /*
2420 : : * WQE is built, update the loop parameters
2421 : : * and go to the next packet.
2422 : : */
2423 : 0 : txq->wqe_ci += (ds + 3) / 4;
2424 : 0 : loc->wqe_free -= (ds + 3) / 4;
2425 : : if (MLX5_TXOFF_CONFIG(INLINE))
2426 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
2427 : 0 : --loc->elts_free;
2428 : 0 : ++loc->pkts_sent;
2429 : 0 : --pkts_n;
2430 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2431 : : return MLX5_TXCMP_CODE_EXIT;
2432 : 0 : loc->mbuf = *pkts++;
2433 [ # # # # : 0 : if (pkts_n > 1)
# # # # #
# # # ]
2434 : 0 : rte_prefetch0(*pkts);
2435 : 0 : if (MLX5_TXOFF_CONFIG(MULTI) &&
2436 [ # # # # : 0 : unlikely(NB_SEGS(loc->mbuf) > 1))
# # # # #
# # # ]
2437 : : return MLX5_TXCMP_CODE_MULTI;
2438 [ # # # # : 0 : if (likely(!(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)))
# # # # #
# # # ]
2439 : : return MLX5_TXCMP_CODE_SINGLE;
2440 : : /* Continue with the next TSO packet. */
2441 : : }
2442 : : MLX5_ASSERT(false);
2443 : : }
2444 : :
2445 : : /**
2446 : : * Analyze the packet and select the best method to send.
2447 : : *
2448 : : * @param txq
2449 : : * Pointer to TX queue structure.
2450 : : * @param loc
2451 : : * Pointer to burst routine local context.
2452 : : * @param olx
2453 : : * Configured Tx offloads mask. It is fully defined at
2454 : : * compile time and may be used for optimization.
2455 : : * @param newp
2456 : : * The predefined flag whether do complete check for
2457 : : * multi-segment packets and TSO.
2458 : : *
2459 : : * @return
2460 : : * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
2461 : : * MLX5_TXCMP_CODE_TSO - TSO required, use TSO/LSO.
2462 : : * MLX5_TXCMP_CODE_SINGLE - single-segment packet, use SEND.
2463 : : * MLX5_TXCMP_CODE_EMPW - single-segment packet, use MPW.
2464 : : */
2465 : : static __rte_always_inline enum mlx5_txcmp_code
2466 : : mlx5_tx_able_to_empw(struct mlx5_txq_data *__rte_restrict txq,
2467 : : struct mlx5_txq_local *__rte_restrict loc,
2468 : : unsigned int olx,
2469 : : bool newp)
2470 : : {
2471 : : /* Check for multi-segment packet. */
2472 : : if (newp &&
2473 : 0 : MLX5_TXOFF_CONFIG(MULTI) &&
2474 [ # # # # : 0 : unlikely(NB_SEGS(loc->mbuf) > 1))
# # # # #
# # # # #
# # # # ]
2475 : : return MLX5_TXCMP_CODE_MULTI;
2476 : : /* Check for TSO packet. */
2477 : : if (newp &&
2478 : 0 : MLX5_TXOFF_CONFIG(TSO) &&
2479 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG))
# # # # #
# # # # #
# # # # #
# # # #
# ]
2480 : : return MLX5_TXCMP_CODE_TSO;
2481 : : /* Check if eMPW is enabled at all. */
2482 : : if (!MLX5_TXOFF_CONFIG(EMPW))
2483 : : return MLX5_TXCMP_CODE_SINGLE;
2484 : : /* Check if eMPW can be engaged. */
2485 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
2486 [ # # # # : 0 : unlikely(loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) &&
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
2487 : 0 : (!MLX5_TXOFF_CONFIG(INLINE) ||
2488 [ # # # # : 0 : unlikely((rte_pktmbuf_data_len(loc->mbuf) +
# # # # #
# # # # #
# # # # #
# # # #
# ]
2489 : : sizeof(struct rte_vlan_hdr)) > txq->inlen_empw))) {
2490 : : /*
2491 : : * eMPW does not support VLAN insertion offload, we have to
2492 : : * inline the entire packet but packet is too long for inlining.
2493 : : */
2494 : 0 : return MLX5_TXCMP_CODE_SINGLE;
2495 : : }
2496 : : return MLX5_TXCMP_CODE_EMPW;
2497 : : }
2498 : :
2499 : : /**
2500 : : * Check the next packet attributes to match with the eMPW batch ones.
2501 : : * In addition, for legacy MPW the packet length is checked either.
2502 : : *
2503 : : * @param txq
2504 : : * Pointer to TX queue structure.
2505 : : * @param es
2506 : : * Pointer to Ethernet Segment of eMPW batch.
2507 : : * @param loc
2508 : : * Pointer to burst routine local context.
2509 : : * @param dlen
2510 : : * Length of previous packet in MPW descriptor.
2511 : : * @param olx
2512 : : * Configured Tx offloads mask. It is fully defined at
2513 : : * compile time and may be used for optimization.
2514 : : *
2515 : : * @return
2516 : : * true - packet match with eMPW batch attributes.
2517 : : * false - no match, eMPW should be restarted.
2518 : : */
2519 : : static __rte_always_inline bool
2520 : : mlx5_tx_match_empw(struct mlx5_txq_data *__rte_restrict txq,
2521 : : struct mlx5_wqe_eseg *__rte_restrict es,
2522 : : struct mlx5_txq_local *__rte_restrict loc,
2523 : : uint32_t dlen,
2524 : : unsigned int olx)
2525 : : {
2526 : : uint8_t swp_flags = 0;
2527 : :
2528 : : /* Compare the checksum flags, if any. */
2529 : 0 : if (MLX5_TXOFF_CONFIG(CSUM) &&
2530 [ # # # # : 0 : txq_ol_cksum_to_cs(loc->mbuf) != es->cs_flags)
# # # # #
# # # ]
2531 : : return false;
2532 : : /* Compare the Software Parser offsets and flags. */
2533 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(SWP) &&
# # # # #
# # # ]
2534 [ # # # # : 0 : (es->swp_offs != txq_mbuf_to_swp(loc, &swp_flags, olx) ||
# # # # #
# # # ]
2535 [ # # # # : 0 : es->swp_flags != swp_flags))
# # # # #
# # # ]
2536 : : return false;
2537 : : /* Fill metadata field if needed. */
2538 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(METADATA) &&
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2539 : 0 : es->metadata != (loc->mbuf->ol_flags & RTE_MBUF_DYNFLAG_TX_METADATA ?
2540 [ # # # # : 0 : rte_cpu_to_be_32(*RTE_FLOW_DYNF_METADATA(loc->mbuf)) : 0))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # ]
2541 : : return false;
2542 : : /* Legacy MPW can send packets with the same length only. */
2543 : 0 : if (MLX5_TXOFF_CONFIG(MPW) &&
2544 [ # # # # : 0 : dlen != rte_pktmbuf_data_len(loc->mbuf))
# # # # ]
2545 : : return false;
2546 : : /* There must be no VLAN packets in eMPW loop. */
2547 : : if (MLX5_TXOFF_CONFIG(VLAN))
2548 : : MLX5_ASSERT(!(loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN));
2549 : : /* Check if the scheduling is requested. */
2550 : 0 : if (MLX5_TXOFF_CONFIG(TXPP) &&
2551 [ # # # # : 0 : loc->mbuf->ol_flags & txq->ts_mask)
# # # # #
# # # ]
2552 : : return false;
2553 : : return true;
2554 : : }
2555 : :
2556 : : /**
2557 : : * Update send loop variables and WQE for eMPW loop without data inlining.
2558 : : * Number of Data Segments is equal to the number of sent packets.
2559 : : *
2560 : : * @param txq
2561 : : * Pointer to TX queue structure.
2562 : : * @param loc
2563 : : * Pointer to burst routine local context.
2564 : : * @param ds
2565 : : * Number of packets/Data Segments/Packets.
2566 : : * @param slen
2567 : : * Accumulated statistics, bytes sent.
2568 : : * @param olx
2569 : : * Configured Tx offloads mask. It is fully defined at
2570 : : * compile time and may be used for optimization.
2571 : : *
2572 : : * @return
2573 : : * true - packet match with eMPW batch attributes.
2574 : : * false - no match, eMPW should be restarted.
2575 : : */
2576 : : static __rte_always_inline void
2577 : : mlx5_tx_sdone_empw(struct mlx5_txq_data *__rte_restrict txq,
2578 : : struct mlx5_txq_local *__rte_restrict loc,
2579 : : unsigned int ds,
2580 : : unsigned int slen,
2581 : : unsigned int olx __rte_unused)
2582 : : {
2583 : : MLX5_ASSERT(!MLX5_TXOFF_CONFIG(INLINE));
2584 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2585 : : /* Update sent data bytes counter. */
2586 : 0 : txq->stats.obytes += slen;
2587 : : #else
2588 : : (void)slen;
2589 : : #endif
2590 : 0 : loc->elts_free -= ds;
2591 : 0 : loc->pkts_sent += ds;
2592 : 0 : ds += 2;
2593 : 0 : loc->wqe_last->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | ds);
2594 : 0 : txq->wqe_ci += (ds + 3) / 4;
2595 : 0 : loc->wqe_free -= (ds + 3) / 4;
2596 : : }
2597 : :
2598 : : /**
2599 : : * Update send loop variables and WQE for eMPW loop with data inlining.
2600 : : * Gets the size of pushed descriptors and data to the WQE.
2601 : : *
2602 : : * @param txq
2603 : : * Pointer to TX queue structure.
2604 : : * @param loc
2605 : : * Pointer to burst routine local context.
2606 : : * @param len
2607 : : * Total size of descriptor/data in bytes.
2608 : : * @param slen
2609 : : * Accumulated statistics, data bytes sent.
2610 : : * @param wqem
2611 : : * The base WQE for the eMPW/MPW descriptor.
2612 : : * @param olx
2613 : : * Configured Tx offloads mask. It is fully defined at
2614 : : * compile time and may be used for optimization.
2615 : : *
2616 : : * @return
2617 : : * true - packet match with eMPW batch attributes.
2618 : : * false - no match, eMPW should be restarted.
2619 : : */
2620 : : static __rte_always_inline void
2621 : : mlx5_tx_idone_empw(struct mlx5_txq_data *__rte_restrict txq,
2622 : : struct mlx5_txq_local *__rte_restrict loc,
2623 : : unsigned int len,
2624 : : unsigned int slen,
2625 : : struct mlx5_wqe *__rte_restrict wqem,
2626 : : unsigned int olx __rte_unused)
2627 : : {
2628 : : struct mlx5_wqe_dseg *dseg = &wqem->dseg[0];
2629 : :
2630 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
2631 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2632 : : /* Update sent data bytes counter. */
2633 : 0 : txq->stats.obytes += slen;
2634 : : #else
2635 : : (void)slen;
2636 : : #endif
2637 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(MPW) && dseg->bcount == RTE_BE32(0)) {
# # # # ]
2638 : : /*
2639 : : * If the legacy MPW session contains the inline packets
2640 : : * we should set the only inline data segment length
2641 : : * and align the total length to the segment size.
2642 : : */
2643 : : MLX5_ASSERT(len > sizeof(dseg->bcount));
2644 [ # # # # : 0 : dseg->bcount = rte_cpu_to_be_32((len - sizeof(dseg->bcount)) |
# # # # #
# # # #
# ]
2645 : : MLX5_ETH_WQE_DATA_INLINE);
2646 : 0 : len = (len + MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE + 2;
2647 : : } else {
2648 : : /*
2649 : : * The session is not legacy MPW or contains the
2650 : : * data buffer pointer segments.
2651 : : */
2652 : : MLX5_ASSERT((len % MLX5_WSEG_SIZE) == 0);
2653 : 0 : len = len / MLX5_WSEG_SIZE + 2;
2654 : : }
2655 [ # # # # : 0 : wqem->cseg.sq_ds = rte_cpu_to_be_32(txq->qp_num_8s | len);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2656 : 0 : txq->wqe_ci += (len + 3) / 4;
2657 : 0 : loc->wqe_free -= (len + 3) / 4;
2658 : : loc->wqe_last = wqem;
2659 : : }
2660 : :
2661 : : /**
2662 : : * The set of Tx burst functions for single-segment packets without TSO
2663 : : * and with Multi-Packet Writing feature support.
2664 : : * Supports all types of Tx offloads, except multi-packets and TSO.
2665 : : *
2666 : : * Uses MLX5_OPCODE_EMPW to build WQEs if possible and sends as many packet
2667 : : * per WQE as it can. If eMPW is not configured or packet can not be sent with
2668 : : * eMPW (VLAN insertion) the ordinary SEND opcode is used and only one packet
2669 : : * placed in WQE.
2670 : : *
2671 : : * Functions stop sending if it encounters the multi-segment packet or packet
2672 : : * with TSO requested.
2673 : : *
2674 : : * The routines are responsible for storing processed mbuf into elts ring buffer
2675 : : * and update elts_head if inlining offload is requested. Otherwise the copying
2676 : : * mbufs to elts can be postponed and completed at the end of burst routine.
2677 : : *
2678 : : * @param txq
2679 : : * Pointer to TX queue structure.
2680 : : * @param[in] pkts
2681 : : * Packets to transmit.
2682 : : * @param pkts_n
2683 : : * Number of packets in array.
2684 : : * @param loc
2685 : : * Pointer to burst routine local context.
2686 : : * @param olx
2687 : : * Configured Tx offloads mask. It is fully defined at
2688 : : * compile time and may be used for optimization.
2689 : : *
2690 : : * @return
2691 : : * MLX5_TXCMP_CODE_EXIT - sending is done or impossible.
2692 : : * MLX5_TXCMP_CODE_ERROR - some unrecoverable error occurred.
2693 : : * MLX5_TXCMP_CODE_MULTI - multi-segment packet encountered.
2694 : : * MLX5_TXCMP_CODE_TSO - TSO packet encountered.
2695 : : * MLX5_TXCMP_CODE_SINGLE - used inside functions set.
2696 : : * MLX5_TXCMP_CODE_EMPW - used inside functions set.
2697 : : *
2698 : : * Local context variables updated.
2699 : : *
2700 : : *
2701 : : * The routine sends packets with MLX5_OPCODE_EMPW
2702 : : * without inlining, this is dedicated optimized branch.
2703 : : * No VLAN insertion is supported.
2704 : : */
2705 : : static __rte_always_inline enum mlx5_txcmp_code
2706 : : mlx5_tx_burst_empw_simple(struct mlx5_txq_data *__rte_restrict txq,
2707 : : struct rte_mbuf **__rte_restrict pkts,
2708 : : unsigned int pkts_n,
2709 : : struct mlx5_txq_local *__rte_restrict loc,
2710 : : unsigned int olx)
2711 : : {
2712 : : /*
2713 : : * Subroutine is the part of mlx5_tx_burst_single() and sends
2714 : : * single-segment packet with eMPW opcode without data inlining.
2715 : : */
2716 : : MLX5_ASSERT(!MLX5_TXOFF_CONFIG(INLINE));
2717 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(EMPW));
2718 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2719 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2720 : 0 : pkts += loc->pkts_sent + 1;
2721 : 0 : pkts_n -= loc->pkts_sent;
2722 : : for (;;) {
2723 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
2724 : : struct mlx5_wqe_eseg *__rte_restrict eseg;
2725 : : enum mlx5_txcmp_code ret;
2726 : : unsigned int part, loop;
2727 : : unsigned int slen = 0;
2728 : :
2729 : 0 : next_empw:
2730 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2731 : 0 : part = RTE_MIN(pkts_n, MLX5_TXOFF_CONFIG(MPW) ?
2732 : : MLX5_MPW_MAX_PACKETS :
2733 : : MLX5_EMPW_MAX_PACKETS);
2734 [ # # # # : 0 : if (unlikely(loc->elts_free < part)) {
# # # # #
# # # # #
# # ]
2735 : : /* We have no enough elts to save all mbufs. */
2736 [ # # # # : 0 : if (unlikely(loc->elts_free < MLX5_EMPW_MIN_PACKETS))
# # # # #
# # # # #
# # ]
2737 : : return MLX5_TXCMP_CODE_EXIT;
2738 : : /* But we still able to send at least minimal eMPW. */
2739 : : part = loc->elts_free;
2740 : : }
2741 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2742 : : enum mlx5_txcmp_code wret;
2743 : :
2744 : : /* Generate WAIT for scheduling if requested. */
2745 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
2746 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2747 : : return MLX5_TXCMP_CODE_EXIT;
2748 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2749 : : return MLX5_TXCMP_CODE_ERROR;
2750 : : }
2751 : : /* Check whether we have enough WQEs */
2752 [ # # # # : 0 : if (unlikely(loc->wqe_free < ((2 + part + 3) / 4))) {
# # # # #
# # # # #
# # ]
2753 [ # # # # : 0 : if (unlikely(loc->wqe_free <
# # # # #
# # # # #
# # ]
2754 : : ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
2755 : : return MLX5_TXCMP_CODE_EXIT;
2756 : 0 : part = (loc->wqe_free * 4) - 2;
2757 : : }
2758 [ # # # # : 0 : if (likely(part > 1))
# # # # #
# # # # #
# # ]
2759 : 0 : rte_prefetch0(*pkts);
2760 : 0 : loc->wqe_last = txq->wqes + (txq->wqe_ci & txq->wqe_m);
2761 : : /*
2762 : : * Build eMPW title WQEBB:
2763 : : * - Control Segment, eMPW opcode
2764 : : * - Ethernet Segment, no inline
2765 : : */
2766 [ # # # # : 0 : mlx5_tx_cseg_init(txq, loc, loc->wqe_last, part + 2,
# # # # #
# # # # #
# # ]
2767 : : MLX5_OPCODE_ENHANCED_MPSW, olx);
2768 : : mlx5_tx_eseg_none(txq, loc, loc->wqe_last,
2769 : : olx & ~MLX5_TXOFF_CONFIG_VLAN);
2770 : : eseg = &loc->wqe_last->eseg;
2771 : 0 : dseg = &loc->wqe_last->dseg[0];
2772 : : loop = part;
2773 : : /* Store the packet length for legacy MPW. */
2774 : : if (MLX5_TXOFF_CONFIG(MPW))
2775 [ # # # # ]: 0 : eseg->mss = rte_cpu_to_be_16
2776 : : (rte_pktmbuf_data_len(loc->mbuf));
2777 : : for (;;) {
2778 : 0 : uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
2779 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2780 : : /* Update sent data bytes counter. */
2781 : 0 : slen += dlen;
2782 : : #endif
2783 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
2784 : : mlx5_tx_dseg_ptr
2785 : : (txq, loc, dseg,
2786 [ # # # # : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
# # # # #
# # # # #
# # ]
2787 : : dlen, olx);
2788 [ # # # # : 0 : if (unlikely(--loop == 0))
# # # # #
# # # # #
# # ]
2789 : : break;
2790 : 0 : loc->mbuf = *pkts++;
2791 [ # # # # : 0 : if (likely(loop > 1))
# # # # #
# # # # #
# # ]
2792 : 0 : rte_prefetch0(*pkts);
2793 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
2794 : : /*
2795 : : * Unroll the completion code to avoid
2796 : : * returning variable value - it results in
2797 : : * unoptimized sequent checking in caller.
2798 : : */
2799 : : if (ret == MLX5_TXCMP_CODE_MULTI) {
2800 [ # # # # : 0 : part -= loop;
# # ]
2801 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2802 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # ]
2803 : : !loc->wqe_free))
2804 : : return MLX5_TXCMP_CODE_EXIT;
2805 : : return MLX5_TXCMP_CODE_MULTI;
2806 : : }
2807 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2808 : : if (ret == MLX5_TXCMP_CODE_TSO) {
2809 [ # # # # : 0 : part -= loop;
# # ]
2810 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2811 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # ]
2812 : : !loc->wqe_free))
2813 : : return MLX5_TXCMP_CODE_EXIT;
2814 : : return MLX5_TXCMP_CODE_TSO;
2815 : : }
2816 : : if (ret == MLX5_TXCMP_CODE_SINGLE) {
2817 [ # # # # : 0 : part -= loop;
# # ]
2818 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2819 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # ]
2820 : : !loc->wqe_free))
2821 : : return MLX5_TXCMP_CODE_EXIT;
2822 : : return MLX5_TXCMP_CODE_SINGLE;
2823 : : }
2824 : : if (ret != MLX5_TXCMP_CODE_EMPW) {
2825 : : MLX5_ASSERT(false);
2826 : : part -= loop;
2827 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2828 : : return MLX5_TXCMP_CODE_ERROR;
2829 : : }
2830 : : /*
2831 : : * Check whether packet parameters coincide
2832 : : * within assumed eMPW batch:
2833 : : * - check sum settings
2834 : : * - metadata value
2835 : : * - software parser settings
2836 : : * - packets length (legacy MPW only)
2837 : : * - scheduling is not required
2838 : : */
2839 : : if (!mlx5_tx_match_empw(txq, eseg, loc, dlen, olx)) {
2840 : : MLX5_ASSERT(loop);
2841 [ # # # # : 0 : part -= loop;
# # # # #
# # # #
# ]
2842 : : mlx5_tx_sdone_empw(txq, loc, part, slen, olx);
2843 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2844 : : !loc->wqe_free))
2845 : : return MLX5_TXCMP_CODE_EXIT;
2846 : 0 : pkts_n -= part;
2847 : 0 : goto next_empw;
2848 : : }
2849 : : /* Packet attributes match, continue the same eMPW. */
2850 : 0 : ++dseg;
2851 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # # #
# # ]
2852 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
2853 : : }
2854 : : /* eMPW is built successfully, update loop parameters. */
2855 : : MLX5_ASSERT(!loop);
2856 : : MLX5_ASSERT(pkts_n >= part);
2857 : : #ifdef MLX5_PMD_SOFT_COUNTERS
2858 : : /* Update sent data bytes counter. */
2859 : 0 : txq->stats.obytes += slen;
2860 : : #endif
2861 : 0 : loc->elts_free -= part;
2862 : 0 : loc->pkts_sent += part;
2863 : 0 : txq->wqe_ci += (2 + part + 3) / 4;
2864 : 0 : loc->wqe_free -= (2 + part + 3) / 4;
2865 : 0 : pkts_n -= part;
2866 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
2867 : : return MLX5_TXCMP_CODE_EXIT;
2868 [ # # # # : 0 : loc->mbuf = *pkts++;
# # # # #
# ]
2869 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
2870 [ # # # # : 0 : if (unlikely(ret != MLX5_TXCMP_CODE_EMPW))
# # # # #
# ]
2871 : : return ret;
2872 : : /* Continue sending eMPW batches. */
2873 : : }
2874 : : MLX5_ASSERT(false);
2875 : : }
2876 : :
2877 : : /**
2878 : : * The routine sends packets with MLX5_OPCODE_EMPW
2879 : : * with inlining, optionally supports VLAN insertion.
2880 : : */
2881 : : static __rte_always_inline enum mlx5_txcmp_code
2882 : : mlx5_tx_burst_empw_inline(struct mlx5_txq_data *__rte_restrict txq,
2883 : : struct rte_mbuf **__rte_restrict pkts,
2884 : : unsigned int pkts_n,
2885 : : struct mlx5_txq_local *__rte_restrict loc,
2886 : : unsigned int olx)
2887 : : {
2888 : : /*
2889 : : * Subroutine is the part of mlx5_tx_burst_single() and sends
2890 : : * single-segment packet with eMPW opcode with data inlining.
2891 : : */
2892 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
2893 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(EMPW));
2894 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
2895 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
2896 : 0 : pkts += loc->pkts_sent + 1;
2897 : 0 : pkts_n -= loc->pkts_sent;
2898 : : for (;;) {
2899 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
2900 : : struct mlx5_wqe *__rte_restrict wqem;
2901 : : enum mlx5_txcmp_code ret;
2902 : : unsigned int room, part, nlim;
2903 : : unsigned int slen = 0;
2904 : :
2905 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
2906 : : /*
2907 : : * Limits the amount of packets in one WQE
2908 : : * to improve CQE latency generation.
2909 : : */
2910 : 0 : nlim = RTE_MIN(pkts_n, MLX5_TXOFF_CONFIG(MPW) ?
2911 : : MLX5_MPW_INLINE_MAX_PACKETS :
2912 : : MLX5_EMPW_MAX_PACKETS);
2913 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
2914 : : enum mlx5_txcmp_code wret;
2915 : :
2916 : : /* Generate WAIT for scheduling if requested. */
2917 [ # # # # : 0 : wret = mlx5_tx_schedule_send(txq, loc, nlim, olx);
# # # # ]
2918 : : if (wret == MLX5_TXCMP_CODE_EXIT)
2919 : : return MLX5_TXCMP_CODE_EXIT;
2920 : : if (wret == MLX5_TXCMP_CODE_ERROR)
2921 : : return MLX5_TXCMP_CODE_ERROR;
2922 : : }
2923 : : /* Check whether we have minimal amount WQEs */
2924 [ # # # # : 0 : if (unlikely(loc->wqe_free <
# # # # #
# # # #
# ]
2925 : : ((2 + MLX5_EMPW_MIN_PACKETS + 3) / 4)))
2926 : : return MLX5_TXCMP_CODE_EXIT;
2927 [ # # # # : 0 : if (likely(pkts_n > 1))
# # # # #
# # # #
# ]
2928 : 0 : rte_prefetch0(*pkts);
2929 [ # # # # : 0 : wqem = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
2930 : : /*
2931 : : * Build eMPW title WQEBB:
2932 : : * - Control Segment, eMPW opcode, zero DS
2933 : : * - Ethernet Segment, no inline
2934 : : */
2935 : : mlx5_tx_cseg_init(txq, loc, wqem, 0,
2936 : : MLX5_OPCODE_ENHANCED_MPSW, olx);
2937 : : mlx5_tx_eseg_none(txq, loc, wqem,
2938 : : olx & ~MLX5_TXOFF_CONFIG_VLAN);
2939 : 0 : dseg = &wqem->dseg[0];
2940 : : /* Store the packet length for legacy MPW. */
2941 : : if (MLX5_TXOFF_CONFIG(MPW))
2942 [ # # # # ]: 0 : wqem->eseg.mss = rte_cpu_to_be_16
2943 : : (rte_pktmbuf_data_len(loc->mbuf));
2944 : 0 : room = RTE_MIN(MLX5_WQE_SIZE_MAX / MLX5_WQE_SIZE,
2945 : : loc->wqe_free) * MLX5_WQE_SIZE -
2946 : 0 : MLX5_WQE_CSEG_SIZE -
2947 : : MLX5_WQE_ESEG_SIZE;
2948 : : /* Limit the room for legacy MPW sessions for performance. */
2949 : : if (MLX5_TXOFF_CONFIG(MPW))
2950 : 0 : room = RTE_MIN(room,
2951 : : RTE_MAX(txq->inlen_empw +
2952 : : sizeof(dseg->bcount) +
2953 : : (MLX5_TXOFF_CONFIG(VLAN) ?
2954 : : sizeof(struct rte_vlan_hdr) : 0),
2955 : : MLX5_MPW_INLINE_MAX_PACKETS *
2956 : : MLX5_WQE_DSEG_SIZE));
2957 : : /* Build WQE till we have space, packets and resources. */
2958 : : part = room;
2959 : : for (;;) {
2960 : 0 : uint32_t dlen = rte_pktmbuf_data_len(loc->mbuf);
2961 : 0 : uint8_t *dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *);
2962 : : unsigned int tlen;
2963 : :
2964 : : MLX5_ASSERT(room >= MLX5_WQE_DSEG_SIZE);
2965 : : MLX5_ASSERT((room % MLX5_WQE_DSEG_SIZE) == 0);
2966 : : MLX5_ASSERT((uintptr_t)dseg < (uintptr_t)txq->wqes_end);
2967 : : /*
2968 : : * Some Tx offloads may cause an error if packet is not
2969 : : * long enough, check against assumed minimal length.
2970 : : */
2971 [ # # # # : 0 : if (unlikely(dlen <= MLX5_ESEG_MIN_INLINE_SIZE)) {
# # # # #
# # # #
# ]
2972 : 0 : part -= room;
2973 [ # # # # : 0 : if (unlikely(!part))
# # # # #
# # # #
# ]
2974 : : return MLX5_TXCMP_CODE_ERROR;
2975 : : /*
2976 : : * We have some successfully built
2977 : : * packet Data Segments to send.
2978 : : */
2979 : : mlx5_tx_idone_empw(txq, loc, part,
2980 : : slen, wqem, olx);
2981 : : return MLX5_TXCMP_CODE_ERROR;
2982 : : }
2983 : : /* Inline or not inline - that's the Question. */
2984 [ # # # # : 0 : if (dlen > txq->inlen_empw ||
# # # # #
# # # #
# ]
2985 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_DYNF_NOINLINE)
# # # # #
# # # #
# ]
2986 [ # # # # : 0 : goto pointer_empw;
# # # # #
# # # #
# ]
2987 : : if (MLX5_TXOFF_CONFIG(MPW)) {
2988 [ # # # # ]: 0 : if (dlen > txq->inlen_send)
2989 : 0 : goto pointer_empw;
2990 : : tlen = dlen;
2991 [ # # # # ]: 0 : if (part == room) {
2992 : : /* Open new inline MPW session. */
2993 : 0 : tlen += sizeof(dseg->bcount);
2994 : 0 : dseg->bcount = RTE_BE32(0);
2995 : 0 : dseg = RTE_PTR_ADD
2996 : : (dseg, sizeof(dseg->bcount));
2997 : : } else {
2998 : : /*
2999 : : * No pointer and inline descriptor
3000 : : * intermix for legacy MPW sessions.
3001 : : */
3002 [ # # # # ]: 0 : if (wqem->dseg[0].bcount)
3003 : : break;
3004 : : }
3005 : : } else {
3006 : 0 : tlen = sizeof(dseg->bcount) + dlen;
3007 : : }
3008 : : /* Inline entire packet, optional VLAN insertion. */
3009 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
3010 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
# # # # ]
3011 : : /*
3012 : : * The packet length must be checked in
3013 : : * mlx5_tx_able_to_empw() and packet
3014 : : * fits into inline length guaranteed.
3015 : : */
3016 : : MLX5_ASSERT((dlen +
3017 : : sizeof(struct rte_vlan_hdr)) <=
3018 : : txq->inlen_empw);
3019 : 0 : tlen += sizeof(struct rte_vlan_hdr);
3020 [ # # # # : 0 : if (room < tlen)
# # # # ]
3021 : : break;
3022 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3023 : : dseg = mlx5_tx_dseg_vlan(txq, loc, dseg,
3024 : : dptr, dlen, olx);
3025 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3026 : : /* Update sent data bytes counter. */
3027 : 0 : slen += sizeof(struct rte_vlan_hdr);
3028 : : #endif
3029 : : } else {
3030 [ # # # # : 0 : if (room < tlen)
# # # # #
# # # #
# ]
3031 : : break;
3032 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3033 : : dseg = mlx5_tx_dseg_empw(txq, loc, dseg,
3034 : : dptr, dlen, olx);
3035 : : }
3036 : : if (!MLX5_TXOFF_CONFIG(MPW))
3037 : 0 : tlen = RTE_ALIGN(tlen, MLX5_WSEG_SIZE);
3038 : : MLX5_ASSERT(room >= tlen);
3039 : 0 : room -= tlen;
3040 : : /*
3041 : : * Packet data are completely inline,
3042 : : * we can try to free the packet.
3043 : : */
3044 [ # # # # : 0 : if (likely(loc->pkts_sent == loc->mbuf_free)) {
# # # # #
# # # #
# ]
3045 : : /*
3046 : : * All the packets from the burst beginning
3047 : : * are inline, we can free mbufs directly
3048 : : * from the origin array on tx_burst exit().
3049 : : */
3050 : 0 : loc->mbuf_free++;
3051 : 0 : goto next_mbuf;
3052 : : }
3053 : : /*
3054 : : * In order no to call rte_pktmbuf_free_seg() here,
3055 : : * in the most inner loop (that might be very
3056 : : * expensive) we just save the mbuf in elts.
3057 : : */
3058 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3059 : 0 : loc->elts_free--;
3060 : 0 : goto next_mbuf;
3061 : 0 : pointer_empw:
3062 : : /*
3063 : : * No pointer and inline descriptor
3064 : : * intermix for legacy MPW sessions.
3065 : : */
3066 [ # # # # ]: 0 : if (MLX5_TXOFF_CONFIG(MPW) &&
3067 : 0 : part != room &&
3068 [ # # # # ]: 0 : wqem->dseg[0].bcount == RTE_BE32(0))
3069 : : break;
3070 : : /*
3071 : : * Not inlinable VLAN packets are
3072 : : * proceeded outside of this routine.
3073 : : */
3074 : : MLX5_ASSERT(room >= MLX5_WQE_DSEG_SIZE);
3075 : : if (MLX5_TXOFF_CONFIG(VLAN))
3076 : : MLX5_ASSERT(!(loc->mbuf->ol_flags &
3077 : : RTE_MBUF_F_TX_VLAN));
3078 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3079 : : mlx5_tx_dseg_ptr(txq, loc, dseg, dptr, dlen, olx);
3080 : : /* We have to store mbuf in elts.*/
3081 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] = loc->mbuf;
3082 : 0 : loc->elts_free--;
3083 : 0 : room -= MLX5_WQE_DSEG_SIZE;
3084 : : /* Ring buffer wraparound is checked at the loop end.*/
3085 : 0 : ++dseg;
3086 : 0 : next_mbuf:
3087 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3088 : : /* Update sent data bytes counter. */
3089 : 0 : slen += dlen;
3090 : : #endif
3091 : 0 : loc->pkts_sent++;
3092 : 0 : pkts_n--;
3093 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free)) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
3094 : : /*
3095 : : * We have no resources/packets to
3096 : : * continue build descriptors.
3097 : : */
3098 [ # # # # : 0 : part -= room;
# # # # #
# # # #
# ]
3099 : : mlx5_tx_idone_empw(txq, loc, part,
3100 : : slen, wqem, olx);
3101 : : return MLX5_TXCMP_CODE_EXIT;
3102 : : }
3103 : 0 : loc->mbuf = *pkts++;
3104 [ # # # # : 0 : if (likely(pkts_n > 1))
# # # # #
# # # #
# ]
3105 : 0 : rte_prefetch0(*pkts);
3106 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3107 : : /*
3108 : : * Unroll the completion code to avoid
3109 : : * returning variable value - it results in
3110 : : * unoptimized sequent checking in caller.
3111 : : */
3112 : : if (ret == MLX5_TXCMP_CODE_MULTI) {
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_MULTI;
3120 : : }
3121 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
3122 : : if (ret == MLX5_TXCMP_CODE_TSO) {
3123 [ # # # # : 0 : part -= room;
# # ]
3124 : : mlx5_tx_idone_empw(txq, loc, part,
3125 : : slen, wqem, olx);
3126 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # ]
3127 : : !loc->wqe_free))
3128 : : return MLX5_TXCMP_CODE_EXIT;
3129 : : return MLX5_TXCMP_CODE_TSO;
3130 : : }
3131 : : if (ret == MLX5_TXCMP_CODE_SINGLE) {
3132 [ # # # # : 0 : part -= room;
# # # # ]
3133 : : mlx5_tx_idone_empw(txq, loc, part,
3134 : : slen, wqem, olx);
3135 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # ]
3136 : : !loc->wqe_free))
3137 : : return MLX5_TXCMP_CODE_EXIT;
3138 : : return MLX5_TXCMP_CODE_SINGLE;
3139 : : }
3140 : : if (ret != MLX5_TXCMP_CODE_EMPW) {
3141 : : MLX5_ASSERT(false);
3142 : : part -= room;
3143 : : mlx5_tx_idone_empw(txq, loc, part,
3144 : : slen, wqem, olx);
3145 : : return MLX5_TXCMP_CODE_ERROR;
3146 : : }
3147 : : /* Check if we have minimal room left. */
3148 : 0 : nlim--;
3149 [ # # # # : 0 : if (unlikely(!nlim || room < MLX5_WQE_DSEG_SIZE))
# # # # #
# # # #
# ]
3150 : : break;
3151 : : /*
3152 : : * Check whether packet parameters coincide
3153 : : * within assumed eMPW batch:
3154 : : * - check sum settings
3155 : : * - metadata value
3156 : : * - software parser settings
3157 : : * - packets length (legacy MPW only)
3158 : : * - scheduling is not required
3159 : : */
3160 : : if (!mlx5_tx_match_empw(txq, &wqem->eseg,
3161 : : loc, dlen, olx))
3162 : : break;
3163 : : /* Packet attributes match, continue the same eMPW. */
3164 [ # # # # : 0 : if ((uintptr_t)dseg >= (uintptr_t)txq->wqes_end)
# # # # #
# # # #
# ]
3165 : 0 : dseg = (struct mlx5_wqe_dseg *)txq->wqes;
3166 : : }
3167 : : /*
3168 : : * We get here to close an existing eMPW
3169 : : * session and start the new one.
3170 : : */
3171 : : MLX5_ASSERT(pkts_n);
3172 : 0 : part -= room;
3173 [ # # # # : 0 : if (unlikely(!part))
# # # # #
# # # #
# ]
3174 : : return MLX5_TXCMP_CODE_EXIT;
3175 : : mlx5_tx_idone_empw(txq, loc, part, slen, wqem, olx);
3176 [ # # # # : 0 : if (unlikely(!loc->elts_free ||
# # # # #
# # # # #
# # # # #
# # # # #
# # # # ]
3177 : : !loc->wqe_free))
3178 : : return MLX5_TXCMP_CODE_EXIT;
3179 : : /* Continue the loop with new eMPW session. */
3180 : : }
3181 : : MLX5_ASSERT(false);
3182 : : }
3183 : :
3184 : : /**
3185 : : * The routine sends packets with ordinary MLX5_OPCODE_SEND.
3186 : : * Data inlining and VLAN insertion are supported.
3187 : : */
3188 : : static __rte_always_inline enum mlx5_txcmp_code
3189 : : mlx5_tx_burst_single_send(struct mlx5_txq_data *__rte_restrict txq,
3190 : : struct rte_mbuf **__rte_restrict pkts,
3191 : : unsigned int pkts_n,
3192 : : struct mlx5_txq_local *__rte_restrict loc,
3193 : : unsigned int olx)
3194 : : {
3195 : : /*
3196 : : * Subroutine is the part of mlx5_tx_burst_single()
3197 : : * and sends single-segment packet with SEND opcode.
3198 : : */
3199 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3200 : : MLX5_ASSERT(pkts_n > loc->pkts_sent);
3201 : 0 : pkts += loc->pkts_sent + 1;
3202 : 0 : pkts_n -= loc->pkts_sent;
3203 : : for (;;) {
3204 : : struct mlx5_wqe *__rte_restrict wqe;
3205 : : enum mlx5_txcmp_code ret;
3206 : :
3207 : : MLX5_ASSERT(NB_SEGS(loc->mbuf) == 1);
3208 : : MLX5_ASSERT(loc->elts_free);
3209 : : if (MLX5_TXOFF_CONFIG(TXPP)) {
3210 : : enum mlx5_txcmp_code wret;
3211 : :
3212 : : /* Generate WAIT for scheduling if requested. */
3213 : : wret = mlx5_tx_schedule_send(txq, loc, 0, olx);
3214 : : if (wret == MLX5_TXCMP_CODE_EXIT)
3215 : : return MLX5_TXCMP_CODE_EXIT;
3216 : : if (wret == MLX5_TXCMP_CODE_ERROR)
3217 : : return MLX5_TXCMP_CODE_ERROR;
3218 : : }
3219 : : if (MLX5_TXOFF_CONFIG(INLINE)) {
3220 : : unsigned int inlen, vlan = 0;
3221 : :
3222 : 0 : inlen = rte_pktmbuf_data_len(loc->mbuf);
3223 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
3224 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN) {
# # # # ]
3225 : : vlan = sizeof(struct rte_vlan_hdr);
3226 : 0 : inlen += vlan;
3227 : : }
3228 : : /*
3229 : : * If inlining is enabled at configuration time
3230 : : * the limit must be not less than minimal size.
3231 : : * Otherwise we would do extra check for data
3232 : : * size to avoid crashes due to length overflow.
3233 : : */
3234 : : MLX5_ASSERT(txq->inlen_send >=
3235 : : MLX5_ESEG_MIN_INLINE_SIZE);
3236 [ # # # # : 0 : if (inlen <= txq->inlen_send) {
# # # # #
# # # #
# ]
3237 : : unsigned int seg_n, wqe_n;
3238 : :
3239 : 0 : rte_prefetch0(rte_pktmbuf_mtod
3240 : : (loc->mbuf, uint8_t *));
3241 : : /* Check against minimal length. */
3242 [ # # # # : 0 : if (inlen <= MLX5_ESEG_MIN_INLINE_SIZE)
# # # # #
# # # #
# ]
3243 : : return MLX5_TXCMP_CODE_ERROR;
3244 [ # # # # : 0 : if (loc->mbuf->ol_flags &
# # # # #
# # # #
# ]
3245 : : RTE_MBUF_F_TX_DYNF_NOINLINE) {
3246 : : /*
3247 : : * The hint flag not to inline packet
3248 : : * data is set. Check whether we can
3249 : : * follow the hint.
3250 : : */
3251 : : if ((!MLX5_TXOFF_CONFIG(EMPW) &&
3252 [ # # # # : 0 : txq->inlen_mode) ||
# # # # #
# # # #
# ]
3253 : : (MLX5_TXOFF_CONFIG(MPW) &&
3254 : : txq->inlen_mode)) {
3255 : : if (inlen <= txq->inlen_send)
3256 : 0 : goto single_inline;
3257 : : /*
3258 : : * The hardware requires the
3259 : : * minimal inline data header.
3260 : : */
3261 : : goto single_min_inline;
3262 : : }
3263 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
# # # # ]
3264 [ # # # # : 0 : vlan && !txq->vlan_en) {
# # # # ]
3265 : : /*
3266 : : * We must insert VLAN tag
3267 : : * by software means.
3268 : : */
3269 : 0 : goto single_part_inline;
3270 : : }
3271 : 0 : goto single_no_inline;
3272 : : }
3273 : 0 : single_inline:
3274 : : /*
3275 : : * Completely inlined packet data WQE:
3276 : : * - Control Segment, SEND opcode
3277 : : * - Ethernet Segment, no VLAN insertion
3278 : : * - Data inlined, VLAN optionally inserted
3279 : : * - Alignment to MLX5_WSEG_SIZE
3280 : : * Have to estimate amount of WQEBBs
3281 : : */
3282 : 0 : seg_n = (inlen + 3 * MLX5_WSEG_SIZE -
3283 : : MLX5_ESEG_MIN_INLINE_SIZE +
3284 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3285 : : /* Check if there are enough WQEBBs. */
3286 : 0 : wqe_n = (seg_n + 3) / 4;
3287 [ # # # # : 0 : if (wqe_n > loc->wqe_free)
# # # # #
# # # #
# ]
3288 : : return MLX5_TXCMP_CODE_EXIT;
3289 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
3290 : : loc->wqe_last = wqe;
3291 : : mlx5_tx_cseg_init(txq, loc, wqe, seg_n,
3292 : : MLX5_OPCODE_SEND, olx);
3293 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3294 : : mlx5_tx_eseg_data(txq, loc, wqe,
3295 : : vlan, inlen, 0, olx);
3296 : 0 : txq->wqe_ci += wqe_n;
3297 [ # # # # : 0 : loc->wqe_free -= wqe_n;
# # # # ]
3298 : : /*
3299 : : * Packet data are completely inlined,
3300 : : * free the packet immediately.
3301 : : */
3302 : : rte_pktmbuf_free_seg(loc->mbuf);
3303 : : } else if ((!MLX5_TXOFF_CONFIG(EMPW) ||
3304 : 0 : MLX5_TXOFF_CONFIG(MPW)) &&
3305 [ # # # # : 0 : txq->inlen_mode) {
# # # # #
# # # #
# ]
3306 : : /*
3307 : : * If minimal inlining is requested the eMPW
3308 : : * feature should be disabled due to data is
3309 : : * inlined into Ethernet Segment, which can
3310 : : * not contain inlined data for eMPW due to
3311 : : * segment shared for all packets.
3312 : : */
3313 : : struct mlx5_wqe_dseg *__rte_restrict dseg;
3314 : : unsigned int ds;
3315 : : uint8_t *dptr;
3316 : :
3317 : : /*
3318 : : * The inline-mode settings require
3319 : : * to inline the specified amount of
3320 : : * data bytes to the Ethernet Segment.
3321 : : * We should check the free space in
3322 : : * WQE ring buffer to inline partially.
3323 : : */
3324 : 0 : single_min_inline:
3325 : : MLX5_ASSERT(txq->inlen_send >= txq->inlen_mode);
3326 : : MLX5_ASSERT(inlen > txq->inlen_mode);
3327 : : MLX5_ASSERT(txq->inlen_mode >=
3328 : : MLX5_ESEG_MIN_INLINE_SIZE);
3329 : : /*
3330 : : * Check whether there are enough free WQEBBs:
3331 : : * - Control Segment
3332 : : * - Ethernet Segment
3333 : : * - First Segment of inlined Ethernet data
3334 : : * - ... data continued ...
3335 : : * - Finishing Data Segment of pointer type
3336 : : */
3337 : 0 : ds = (MLX5_WQE_CSEG_SIZE +
3338 : : MLX5_WQE_ESEG_SIZE +
3339 : : MLX5_WQE_DSEG_SIZE +
3340 : 0 : txq->inlen_mode -
3341 : : MLX5_ESEG_MIN_INLINE_SIZE +
3342 : : MLX5_WQE_DSEG_SIZE +
3343 : 0 : MLX5_WSEG_SIZE - 1) / MLX5_WSEG_SIZE;
3344 [ # # # # : 0 : if (loc->wqe_free < ((ds + 3) / 4))
# # # # #
# # # #
# ]
3345 : : return MLX5_TXCMP_CODE_EXIT;
3346 : : /*
3347 : : * Build the ordinary SEND WQE:
3348 : : * - Control Segment
3349 : : * - Ethernet Segment, inline inlen_mode bytes
3350 : : * - Data Segment of pointer type
3351 : : */
3352 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
3353 : : loc->wqe_last = wqe;
3354 : : mlx5_tx_cseg_init(txq, loc, wqe, ds,
3355 : : MLX5_OPCODE_SEND, olx);
3356 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3357 [ # # # # : 0 : dseg = mlx5_tx_eseg_data(txq, loc, wqe, vlan,
# # # # #
# # # #
# ]
3358 : : txq->inlen_mode,
3359 : : 0, olx);
3360 : 0 : dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
3361 : 0 : txq->inlen_mode - vlan;
3362 [ # # # # : 0 : inlen -= txq->inlen_mode;
# # # # #
# # # #
# ]
3363 : : mlx5_tx_dseg_ptr(txq, loc, dseg,
3364 : : dptr, inlen, olx);
3365 : : /*
3366 : : * WQE is built, update the loop parameters
3367 : : * and got to the next packet.
3368 : : */
3369 : 0 : txq->wqe_ci += (ds + 3) / 4;
3370 : 0 : loc->wqe_free -= (ds + 3) / 4;
3371 : : /* We have to store mbuf in elts.*/
3372 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
3373 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] =
3374 : : loc->mbuf;
3375 : 0 : --loc->elts_free;
3376 : : } else {
3377 : : uint8_t *dptr;
3378 : : unsigned int dlen;
3379 : :
3380 : : /*
3381 : : * Partially inlined packet data WQE, we have
3382 : : * some space in title WQEBB, we can fill it
3383 : : * with some packet data. It takes one WQEBB,
3384 : : * it is available, no extra space check:
3385 : : * - Control Segment, SEND opcode
3386 : : * - Ethernet Segment, no VLAN insertion
3387 : : * - MLX5_ESEG_MIN_INLINE_SIZE bytes of Data
3388 : : * - Data Segment, pointer type
3389 : : *
3390 : : * We also get here if VLAN insertion is not
3391 : : * supported by HW, the inline is enabled.
3392 : : */
3393 : 0 : single_part_inline:
3394 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # #
# ]
3395 : : loc->wqe_last = wqe;
3396 : : mlx5_tx_cseg_init(txq, loc, wqe, 4,
3397 : : MLX5_OPCODE_SEND, olx);
3398 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3399 : : mlx5_tx_eseg_dmin(txq, loc, wqe, vlan, olx);
3400 : 0 : dptr = rte_pktmbuf_mtod(loc->mbuf, uint8_t *) +
3401 : 0 : MLX5_ESEG_MIN_INLINE_SIZE - vlan;
3402 : : /*
3403 : : * The length check is performed above, by
3404 : : * comparing with txq->inlen_send. We should
3405 : : * not get overflow here.
3406 : : */
3407 : : MLX5_ASSERT(inlen > MLX5_ESEG_MIN_INLINE_SIZE);
3408 [ # # # # : 0 : dlen = inlen - MLX5_ESEG_MIN_INLINE_SIZE;
# # # # #
# # # #
# ]
3409 : : mlx5_tx_dseg_ptr(txq, loc, &wqe->dseg[1],
3410 : : dptr, dlen, olx);
3411 : 0 : ++txq->wqe_ci;
3412 : 0 : --loc->wqe_free;
3413 : : /* We have to store mbuf in elts.*/
3414 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE));
3415 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] =
3416 : : loc->mbuf;
3417 : 0 : --loc->elts_free;
3418 : : }
3419 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3420 : : /* Update sent data bytes counter. */
3421 : 0 : txq->stats.obytes += vlan +
3422 : 0 : rte_pktmbuf_data_len(loc->mbuf);
3423 : : #endif
3424 : : } else {
3425 : : /*
3426 : : * No inline at all, it means the CPU cycles saving
3427 : : * is prioritized at configuration, we should not
3428 : : * copy any packet data to WQE.
3429 : : *
3430 : : * SEND WQE, one WQEBB:
3431 : : * - Control Segment, SEND opcode
3432 : : * - Ethernet Segment, optional VLAN, no inline
3433 : : * - Data Segment, pointer type
3434 : : */
3435 : : single_no_inline:
3436 [ # # # # : 0 : wqe = txq->wqes + (txq->wqe_ci & txq->wqe_m);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3437 : : loc->wqe_last = wqe;
3438 : : mlx5_tx_cseg_init(txq, loc, wqe, 3,
3439 : : MLX5_OPCODE_SEND, olx);
3440 : : rte_pmd_mlx5_trace_tx_push(loc->mbuf, txq->wqe_ci);
3441 : : mlx5_tx_eseg_none(txq, loc, wqe, olx);
3442 : 0 : mlx5_tx_dseg_ptr
3443 : : (txq, loc, &wqe->dseg[0],
3444 : 0 : rte_pktmbuf_mtod(loc->mbuf, uint8_t *),
3445 [ # # # # : 0 : rte_pktmbuf_data_len(loc->mbuf), olx);
# # # # #
# # # # #
# # # # #
# # # ]
3446 : 0 : ++txq->wqe_ci;
3447 : 0 : --loc->wqe_free;
3448 : : /*
3449 : : * We should not store mbuf pointer in elts
3450 : : * if no inlining is configured, this is done
3451 : : * by calling routine in a batch copy.
3452 : : */
3453 : : if (MLX5_TXOFF_CONFIG(INLINE))
3454 : 0 : txq->elts[txq->elts_head++ & txq->elts_m] =
3455 : : loc->mbuf;
3456 : 0 : --loc->elts_free;
3457 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3458 : : /* Update sent data bytes counter. */
3459 : 0 : txq->stats.obytes += rte_pktmbuf_data_len(loc->mbuf);
3460 : 0 : if (MLX5_TXOFF_CONFIG(VLAN) &&
3461 [ # # # # : 0 : loc->mbuf->ol_flags & RTE_MBUF_F_TX_VLAN)
# # # # #
# # # #
# ]
3462 : 0 : txq->stats.obytes +=
3463 : : sizeof(struct rte_vlan_hdr);
3464 : : #endif
3465 : : }
3466 : 0 : ++loc->pkts_sent;
3467 : 0 : --pkts_n;
3468 [ # # # # : 0 : if (unlikely(!pkts_n || !loc->elts_free || !loc->wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3469 : : return MLX5_TXCMP_CODE_EXIT;
3470 : 0 : loc->mbuf = *pkts++;
3471 [ # # # # : 0 : if (pkts_n > 1)
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3472 : 0 : rte_prefetch0(*pkts);
3473 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, true);
3474 [ # # # # : 0 : if (unlikely(ret != MLX5_TXCMP_CODE_SINGLE))
# # # # #
# # # #
# ]
3475 : : return ret;
3476 : : }
3477 : : MLX5_ASSERT(false);
3478 : : }
3479 : :
3480 : : static __rte_always_inline enum mlx5_txcmp_code
3481 : : mlx5_tx_burst_single(struct mlx5_txq_data *__rte_restrict txq,
3482 : : struct rte_mbuf **__rte_restrict pkts,
3483 : : unsigned int pkts_n,
3484 : : struct mlx5_txq_local *__rte_restrict loc,
3485 : : unsigned int olx)
3486 : : {
3487 : : enum mlx5_txcmp_code ret;
3488 : :
3489 : : ret = mlx5_tx_able_to_empw(txq, loc, olx, false);
3490 : : if (ret == MLX5_TXCMP_CODE_SINGLE)
3491 : 0 : goto ordinary_send;
3492 : : MLX5_ASSERT(ret == MLX5_TXCMP_CODE_EMPW);
3493 : : for (;;) {
3494 : : /* Optimize for inline/no inline eMPW send. */
3495 : : ret = (MLX5_TXOFF_CONFIG(INLINE)) ?
3496 : : mlx5_tx_burst_empw_inline
3497 : : (txq, pkts, pkts_n, loc, olx) :
3498 : : mlx5_tx_burst_empw_simple
3499 : : (txq, pkts, pkts_n, loc, olx);
3500 [ # # # # : 0 : if (ret != MLX5_TXCMP_CODE_SINGLE)
# # ]
3501 : : return ret;
3502 : : /* The resources to send one packet should remain. */
3503 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3504 : 0 : ordinary_send:
3505 : : ret = mlx5_tx_burst_single_send(txq, pkts, pkts_n, loc, olx);
3506 : : MLX5_ASSERT(ret != MLX5_TXCMP_CODE_SINGLE);
3507 [ # # # # : 0 : if (ret != MLX5_TXCMP_CODE_EMPW)
# # # # #
# # # #
# ]
3508 : : return ret;
3509 : : /* The resources to send one packet should remain. */
3510 : : MLX5_ASSERT(loc->elts_free && loc->wqe_free);
3511 : : }
3512 : : }
3513 : :
3514 : : /**
3515 : : * DPDK Tx callback template. This is configured template used to generate
3516 : : * routines optimized for specified offload setup.
3517 : : * One of this generated functions is chosen at SQ configuration time.
3518 : : *
3519 : : * @param txq
3520 : : * Generic pointer to TX queue structure.
3521 : : * @param[in] pkts
3522 : : * Packets to transmit.
3523 : : * @param pkts_n
3524 : : * Number of packets in array.
3525 : : * @param olx
3526 : : * Configured offloads mask, presents the bits of MLX5_TXOFF_CONFIG_xxx
3527 : : * values. Should be static to take compile time static configuration
3528 : : * advantages.
3529 : : *
3530 : : * @return
3531 : : * Number of packets successfully transmitted (<= pkts_n).
3532 : : */
3533 : : static __rte_always_inline uint16_t
3534 : : mlx5_tx_burst_tmpl(struct mlx5_txq_data *__rte_restrict txq,
3535 : : struct rte_mbuf **__rte_restrict pkts,
3536 : : uint16_t pkts_n,
3537 : : unsigned int olx)
3538 : : {
3539 : : struct mlx5_txq_local loc;
3540 : : enum mlx5_txcmp_code ret;
3541 : : unsigned int part;
3542 : :
3543 : : MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
3544 : : MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
3545 [ # # # # : 0 : if (unlikely(!pkts_n))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3546 : : return 0;
3547 : : if (MLX5_TXOFF_CONFIG(INLINE))
3548 : : loc.mbuf_free = 0;
3549 : : loc.pkts_sent = 0;
3550 : : loc.pkts_copy = 0;
3551 : : loc.wqe_last = NULL;
3552 : :
3553 : 0 : send_loop:
3554 : : loc.pkts_loop = loc.pkts_sent;
3555 : : /*
3556 : : * Check if there are some CQEs, if any:
3557 : : * - process an encountered errors
3558 : : * - process the completed WQEs
3559 : : * - free related mbufs
3560 : : * - doorbell the NIC about processed CQEs
3561 : : */
3562 : 0 : rte_prefetch0(*(pkts + loc.pkts_sent));
3563 : 0 : mlx5_tx_handle_completion(txq);
3564 : : /*
3565 : : * Calculate the number of available resources - elts and WQEs.
3566 : : * There are two possible different scenarios:
3567 : : * - no data inlining into WQEs, one WQEBB may contains up to
3568 : : * four packets, in this case elts become scarce resource
3569 : : * - data inlining into WQEs, one packet may require multiple
3570 : : * WQEBBs, the WQEs become the limiting factor.
3571 : : */
3572 : : MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
3573 : 0 : loc.elts_free = txq->elts_s -
3574 : 0 : (uint16_t)(txq->elts_head - txq->elts_tail);
3575 : : MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
3576 : 0 : loc.wqe_free = txq->wqe_s -
3577 : 0 : (uint16_t)(txq->wqe_ci - txq->wqe_pi);
3578 [ # # # # : 0 : if (unlikely(!loc.elts_free || !loc.wqe_free))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3579 : 0 : goto burst_exit;
3580 : : for (;;) {
3581 : : /*
3582 : : * Fetch the packet from array. Usually this is the first
3583 : : * packet in series of multi/single segment packets.
3584 : : */
3585 : 0 : loc.mbuf = *(pkts + loc.pkts_sent);
3586 : : /* Dedicated branch for multi-segment packets. */
3587 : 0 : if (MLX5_TXOFF_CONFIG(MULTI) &&
3588 [ # # # # : 0 : unlikely(NB_SEGS(loc.mbuf) > 1)) {
# # # # #
# # # ]
3589 : : /*
3590 : : * Multi-segment packet encountered.
3591 : : * Hardware is able to process it only
3592 : : * with SEND/TSO opcodes, one packet
3593 : : * per WQE, do it in dedicated routine.
3594 : : */
3595 : 0 : enter_send_multi:
3596 : : MLX5_ASSERT(loc.pkts_sent >= loc.pkts_copy);
3597 : 0 : part = loc.pkts_sent - loc.pkts_copy;
3598 [ # # # # : 0 : if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
# # ]
3599 : : /*
3600 : : * There are some single-segment mbufs not
3601 : : * stored in elts. The mbufs must be in the
3602 : : * same order as WQEs, so we must copy the
3603 : : * mbufs to elts here, before the coming
3604 : : * multi-segment packet mbufs is appended.
3605 : : */
3606 [ # # # # : 0 : mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy,
# # ]
3607 : : part, olx);
3608 : : loc.pkts_copy = loc.pkts_sent;
3609 : : }
3610 : : MLX5_ASSERT(pkts_n > loc.pkts_sent);
3611 : 0 : ret = mlx5_tx_burst_mseg(txq, pkts, pkts_n, &loc, olx);
3612 : : if (!MLX5_TXOFF_CONFIG(INLINE))
3613 : : loc.pkts_copy = loc.pkts_sent;
3614 : : /*
3615 : : * These returned code checks are supposed
3616 : : * to be optimized out due to routine inlining.
3617 : : */
3618 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_EXIT) {
# # # # #
# # # ]
3619 : : /*
3620 : : * The routine returns this code when
3621 : : * all packets are sent or there is no
3622 : : * enough resources to complete request.
3623 : : */
3624 : : break;
3625 : : }
3626 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_ERROR) {
# # # # #
# # # ]
3627 : : /*
3628 : : * The routine returns this code when some error
3629 : : * in the incoming packets format occurred.
3630 : : */
3631 : 0 : txq->stats.oerrors++;
3632 : 0 : break;
3633 : : }
3634 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_SINGLE) {
# # # # #
# # # ]
3635 : : /*
3636 : : * The single-segment packet was encountered
3637 : : * in the array, try to send it with the
3638 : : * best optimized way, possible engaging eMPW.
3639 : : */
3640 : 0 : goto enter_send_single;
3641 : : }
3642 : : if (MLX5_TXOFF_CONFIG(TSO) &&
3643 : : ret == MLX5_TXCMP_CODE_TSO) {
3644 : : /*
3645 : : * The single-segment TSO packet was
3646 : : * encountered in the array.
3647 : : */
3648 : 0 : goto enter_send_tso;
3649 : : }
3650 : : /* We must not get here. Something is going wrong. */
3651 : : MLX5_ASSERT(false);
3652 : : txq->stats.oerrors++;
3653 : : break;
3654 : : }
3655 : : /* Dedicated branch for single-segment TSO packets. */
3656 : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
3657 [ # # # # : 0 : unlikely(loc.mbuf->ol_flags & RTE_MBUF_F_TX_TCP_SEG)) {
# # # # #
# # # ]
3658 : : /*
3659 : : * TSO might require special way for inlining
3660 : : * (dedicated parameters) and is sent with
3661 : : * MLX5_OPCODE_TSO opcode only, provide this
3662 : : * in dedicated branch.
3663 : : */
3664 : 0 : enter_send_tso:
3665 : : MLX5_ASSERT(NB_SEGS(loc.mbuf) == 1);
3666 : : MLX5_ASSERT(pkts_n > loc.pkts_sent);
3667 : 0 : ret = mlx5_tx_burst_tso(txq, pkts, pkts_n, &loc, olx);
3668 : : /*
3669 : : * These returned code checks are supposed
3670 : : * to be optimized out due to routine inlining.
3671 : : */
3672 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_EXIT)
# # # # #
# # # ]
3673 : : break;
3674 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_ERROR) {
# # # # #
# # # ]
3675 : 0 : txq->stats.oerrors++;
3676 : 0 : break;
3677 : : }
3678 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_SINGLE)
# # # # #
# # # ]
3679 : 0 : goto enter_send_single;
3680 : : if (MLX5_TXOFF_CONFIG(MULTI) &&
3681 : : ret == MLX5_TXCMP_CODE_MULTI) {
3682 : : /*
3683 : : * The multi-segment packet was
3684 : : * encountered in the array.
3685 : : */
3686 : 0 : goto enter_send_multi;
3687 : : }
3688 : : /* We must not get here. Something is going wrong. */
3689 : : MLX5_ASSERT(false);
3690 : : txq->stats.oerrors++;
3691 : : break;
3692 : : }
3693 : : /*
3694 : : * The dedicated branch for the single-segment packets
3695 : : * without TSO. Often these ones can be sent using
3696 : : * MLX5_OPCODE_EMPW with multiple packets in one WQE.
3697 : : * The routine builds the WQEs till it encounters
3698 : : * the TSO or multi-segment packet (in case if these
3699 : : * offloads are requested at SQ configuration time).
3700 : : */
3701 : 0 : enter_send_single:
3702 : : MLX5_ASSERT(pkts_n > loc.pkts_sent);
3703 [ # # # # : 0 : ret = mlx5_tx_burst_single(txq, pkts, pkts_n, &loc, olx);
# # # # #
# # # #
# ]
3704 : : /*
3705 : : * These returned code checks are supposed
3706 : : * to be optimized out due to routine inlining.
3707 : : */
3708 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_EXIT)
# # # # #
# # # # #
# # # # #
# ]
3709 : : break;
3710 [ # # # # : 0 : if (ret == MLX5_TXCMP_CODE_ERROR) {
# # # # #
# ]
3711 : 0 : txq->stats.oerrors++;
3712 : 0 : break;
3713 : : }
3714 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(MULTI) &&
# # # # #
# # # ]
3715 : : ret == MLX5_TXCMP_CODE_MULTI) {
3716 : : /*
3717 : : * The multi-segment packet was
3718 : : * encountered in the array.
3719 : : */
3720 : 0 : goto enter_send_multi;
3721 : : }
3722 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(TSO) &&
# # # # #
# # # ]
3723 : : ret == MLX5_TXCMP_CODE_TSO) {
3724 : : /*
3725 : : * The single-segment TSO packet was
3726 : : * encountered in the array.
3727 : : */
3728 : 0 : goto enter_send_tso;
3729 : : }
3730 : : /* We must not get here. Something is going wrong. */
3731 : : MLX5_ASSERT(false);
3732 : 0 : txq->stats.oerrors++;
3733 : 0 : break;
3734 : : }
3735 : : /*
3736 : : * Main Tx loop is completed, do the rest:
3737 : : * - set completion request if thresholds are reached
3738 : : * - doorbell the hardware
3739 : : * - copy the rest of mbufs to elts (if any)
3740 : : */
3741 : : MLX5_ASSERT(MLX5_TXOFF_CONFIG(INLINE) ||
3742 : : loc.pkts_sent >= loc.pkts_copy);
3743 : : /* Take a shortcut if nothing is sent. */
3744 [ # # # # : 0 : if (unlikely(loc.pkts_sent == loc.pkts_loop))
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3745 : 0 : goto burst_exit;
3746 : : /* Request CQE generation if limits are reached. */
3747 : : if (MLX5_TXOFF_CONFIG(TXPP) && __rte_trace_point_fp_is_enabled())
3748 : : mlx5_tx_request_completion_trace(txq, &loc, olx);
3749 : : else
3750 : : mlx5_tx_request_completion(txq, &loc, olx);
3751 : : /*
3752 : : * Ring QP doorbell immediately after WQE building completion
3753 : : * to improve latencies. The pure software related data treatment
3754 : : * can be completed after doorbell. Tx CQEs for this SQ are
3755 : : * processed in this thread only by the polling.
3756 : : *
3757 : : * The rdma core library can map doorbell register in two ways,
3758 : : * depending on the environment variable "MLX5_SHUT_UP_BF":
3759 : : *
3760 : : * - as regular cached memory, the variable is either missing or
3761 : : * set to zero. This type of mapping may cause the significant
3762 : : * doorbell register writing latency and requires explicit memory
3763 : : * write barrier to mitigate this issue and prevent write combining.
3764 : : *
3765 : : * - as non-cached memory, the variable is present and set to not "0"
3766 : : * value. This type of mapping may cause performance impact under
3767 : : * heavy loading conditions but the explicit write memory barrier is
3768 : : * not required and it may improve core performance.
3769 : : *
3770 : : * - the legacy behaviour (prior 19.08 release) was to use some
3771 : : * heuristics to decide whether write memory barrier should
3772 : : * be performed. This behavior is supported with specifying
3773 : : * tx_db_nc=2, write barrier is skipped if application provides
3774 : : * the full recommended burst of packets, it supposes the next
3775 : : * packets are coming and the write barrier will be issued on
3776 : : * the next burst (after descriptor writing, at least).
3777 : : */
3778 : 0 : mlx5_doorbell_ring(mlx5_tx_bfreg(txq),
3779 : 0 : *(volatile uint64_t *)loc.wqe_last, txq->wqe_ci,
3780 [ # # # # : 0 : txq->qp_db, !txq->db_nc &&
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3781 [ # # # # : 0 : (!txq->db_heu || pkts_n % MLX5_TX_DEFAULT_BURST));
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3782 : : /* Not all of the mbufs may be stored into elts yet. */
3783 : : part = MLX5_TXOFF_CONFIG(INLINE) ? 0 : loc.pkts_sent - loc.pkts_copy;
3784 [ # # # # : 0 : if (!MLX5_TXOFF_CONFIG(INLINE) && part) {
# # # # #
# # # # #
# # ]
3785 : : /*
3786 : : * There are some single-segment mbufs not stored in elts.
3787 : : * It can be only if the last packet was single-segment.
3788 : : * The copying is gathered into one place due to it is
3789 : : * a good opportunity to optimize that with SIMD.
3790 : : * Unfortunately if inlining is enabled the gaps in pointer
3791 : : * array may happen due to early freeing of the inlined mbufs.
3792 : : */
3793 [ # # # # : 0 : mlx5_tx_copy_elts(txq, pkts + loc.pkts_copy, part, olx);
# # # # #
# # # # #
# # ]
3794 : : loc.pkts_copy = loc.pkts_sent;
3795 : : }
3796 : : MLX5_ASSERT(txq->elts_s >= (uint16_t)(txq->elts_head - txq->elts_tail));
3797 : : MLX5_ASSERT(txq->wqe_s >= (uint16_t)(txq->wqe_ci - txq->wqe_pi));
3798 [ # # # # : 0 : if (pkts_n > loc.pkts_sent) {
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# ]
3799 : : /*
3800 : : * If burst size is large there might be no enough CQE
3801 : : * fetched from completion queue and no enough resources
3802 : : * freed to send all the packets.
3803 : : */
3804 : 0 : goto send_loop;
3805 : : }
3806 : 0 : burst_exit:
3807 : : #ifdef MLX5_PMD_SOFT_COUNTERS
3808 : : /* Increment sent packets counter. */
3809 : 0 : txq->stats.opackets += loc.pkts_sent;
3810 : : #endif
3811 [ # # # # : 0 : if (MLX5_TXOFF_CONFIG(INLINE) && loc.mbuf_free)
# # # # #
# # # #
# ]
3812 : 0 : __mlx5_tx_free_mbuf(txq, pkts, loc.mbuf_free);
3813 : : /* Trace productive bursts only. */
3814 : : if (__rte_trace_point_fp_is_enabled() && loc.pkts_sent)
3815 : : rte_pmd_mlx5_trace_tx_exit(mlx5_read_pcibar_clock_from_txq(txq),
3816 : : loc.pkts_sent, pkts_n);
3817 : : return loc.pkts_sent;
3818 : : }
3819 : :
3820 : : /**
3821 : : * Check whether given TxQ is external.
3822 : : *
3823 : : * @param dev
3824 : : * Pointer to Ethernet device.
3825 : : * @param queue_idx
3826 : : * Tx queue index.
3827 : : *
3828 : : * @return
3829 : : * True if is external TxQ, otherwise false.
3830 : : */
3831 : : static __rte_always_inline bool
3832 : : mlx5_is_external_txq(struct rte_eth_dev *dev, uint16_t queue_idx)
3833 : : {
3834 : 0 : struct mlx5_priv *priv = dev->data->dev_private;
3835 : : struct mlx5_external_q *txq;
3836 : :
3837 [ # # # # ]: 0 : if (!priv->ext_txqs || queue_idx < MLX5_EXTERNAL_TX_QUEUE_ID_MIN)
3838 : : return false;
3839 : 0 : txq = &priv->ext_txqs[queue_idx - MLX5_EXTERNAL_TX_QUEUE_ID_MIN];
3840 [ # # ]: 0 : return !!rte_atomic_load_explicit(&txq->refcnt, rte_memory_order_relaxed);
3841 : : }
3842 : :
3843 : : #endif /* RTE_PMD_MLX5_TX_H_ */
|