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