4 * Copyright 2017 6WIND S.A.
5 * Copyright 2017 Mellanox.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of 6WIND S.A. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <smmintrin.h>
41 /* ISO C doesn't support unnamed structs/unions, disabling -pedantic. */
43 #pragma GCC diagnostic ignored "-Wpedantic"
45 #include <infiniband/verbs.h>
46 #include <infiniband/mlx5_hw.h>
47 #include <infiniband/arch.h>
49 #pragma GCC diagnostic error "-Wpedantic"
52 /* DPDK headers don't like -pedantic. */
54 #pragma GCC diagnostic ignored "-Wpedantic"
57 #include <rte_mempool.h>
58 #include <rte_prefetch.h>
60 #pragma GCC diagnostic error "-Wpedantic"
64 #include "mlx5_utils.h"
65 #include "mlx5_rxtx.h"
66 #include "mlx5_autoconf.h"
67 #include "mlx5_defs.h"
70 #ifndef __INTEL_COMPILER
71 #pragma GCC diagnostic ignored "-Wcast-qual"
75 * Fill in buffer descriptors in a multi-packet send descriptor.
78 * Pointer to TX queue structure.
80 * Pointer to buffer descriptor to be writen.
82 * Pointer to array of packets to be sent.
84 * Number of packets to be filled.
87 txq_wr_dseg_v(struct txq *txq, __m128i *dseg,
88 struct rte_mbuf **pkts, unsigned int n)
92 const __m128i shuf_mask_dseg =
93 _mm_set_epi8(8, 9, 10, 11, /* addr, bswap64 */
95 7, 6, 5, 4, /* lkey */
96 0, 1, 2, 3 /* length, bswap32 */);
97 #ifdef MLX5_PMD_SOFT_COUNTERS
101 for (pos = 0; pos < n; ++pos, ++dseg) {
103 struct rte_mbuf *pkt = pkts[pos];
105 addr = rte_pktmbuf_mtod(pkt, uintptr_t);
106 desc = _mm_set_epi32(addr >> 32,
108 mlx5_tx_mb2mr(txq, pkt),
110 desc = _mm_shuffle_epi8(desc, shuf_mask_dseg);
111 _mm_store_si128(dseg, desc);
112 #ifdef MLX5_PMD_SOFT_COUNTERS
113 tx_byte += DATA_LEN(pkt);
116 #ifdef MLX5_PMD_SOFT_COUNTERS
117 txq->stats.obytes += tx_byte;
122 * Count the number of continuous single segment packets. The first packet must
123 * be a single segment packet.
126 * Pointer to array of packets.
131 * Number of continuous single segment packets.
133 static inline unsigned int
134 txq_check_multiseg(struct rte_mbuf **pkts, uint16_t pkts_n)
140 assert(NB_SEGS(pkts[0]) == 1);
141 /* Count the number of continuous single segment packets. */
142 for (pos = 1; pos < pkts_n; ++pos)
143 if (NB_SEGS(pkts[pos]) > 1)
149 * Count the number of packets having same ol_flags and calculate cs_flags.
152 * Pointer to TX queue structure.
154 * Pointer to array of packets.
158 * Pointer of flags to be returned.
161 * Number of packets having same ol_flags.
163 static inline unsigned int
164 txq_calc_offload(struct txq *txq, struct rte_mbuf **pkts, uint16_t pkts_n,
168 const uint64_t ol_mask =
169 PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM |
170 PKT_TX_UDP_CKSUM | PKT_TX_TUNNEL_GRE |
171 PKT_TX_TUNNEL_VXLAN | PKT_TX_OUTER_IP_CKSUM;
175 /* Count the number of packets having same ol_flags. */
176 for (pos = 1; pos < pkts_n; ++pos)
177 if ((pkts[pos]->ol_flags ^ pkts[0]->ol_flags) & ol_mask)
179 /* Should open another MPW session for the rest. */
180 if (pkts[0]->ol_flags &
181 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
182 const uint64_t is_tunneled =
185 PKT_TX_TUNNEL_VXLAN);
187 if (is_tunneled && txq->tunnel_en) {
188 *cs_flags = MLX5_ETH_WQE_L3_INNER_CSUM |
189 MLX5_ETH_WQE_L4_INNER_CSUM;
190 if (pkts[0]->ol_flags & PKT_TX_OUTER_IP_CKSUM)
191 *cs_flags |= MLX5_ETH_WQE_L3_CSUM;
193 *cs_flags = MLX5_ETH_WQE_L3_CSUM |
194 MLX5_ETH_WQE_L4_CSUM;
201 * Send multi-segmented packets until it encounters a single segment packet in
205 * Pointer to TX queue structure.
207 * Pointer to array of packets to be sent.
209 * Number of packets to be sent.
212 * Number of packets successfully transmitted (<= pkts_n).
215 txq_scatter_v(struct txq *txq, struct rte_mbuf **pkts, uint16_t pkts_n)
217 uint16_t elts_head = txq->elts_head;
218 const uint16_t elts_n = 1 << txq->elts_n;
219 const uint16_t elts_m = elts_n - 1;
220 const uint16_t wq_n = 1 << txq->wqe_n;
221 const uint16_t wq_mask = wq_n - 1;
222 const unsigned int nb_dword_per_wqebb =
223 MLX5_WQE_SIZE / MLX5_WQE_DWORD_SIZE;
224 const unsigned int nb_dword_in_hdr =
225 sizeof(struct mlx5_wqe) / MLX5_WQE_DWORD_SIZE;
227 volatile struct mlx5_wqe *wqe = NULL;
229 assert(elts_n > pkts_n);
230 mlx5_tx_complete(txq);
231 if (unlikely(!pkts_n))
233 for (n = 0; n < pkts_n; ++n) {
234 struct rte_mbuf *buf = pkts[n];
235 unsigned int segs_n = buf->nb_segs;
236 unsigned int ds = nb_dword_in_hdr;
237 unsigned int len = PKT_LEN(buf);
238 uint16_t wqe_ci = txq->wqe_ci;
239 const __m128i shuf_mask_ctrl =
240 _mm_set_epi8(15, 14, 13, 12,
241 8, 9, 10, 11, /* bswap32 */
242 4, 5, 6, 7, /* bswap32 */
243 0, 1, 2, 3 /* bswap32 */);
244 uint8_t cs_flags = 0;
247 __m128i *t_wqe, *dseg;
251 max_elts = elts_n - (elts_head - txq->elts_tail);
252 max_wqe = wq_n - (txq->wqe_ci - txq->wqe_pi);
254 * A MPW session consumes 2 WQEs at most to
255 * include MLX5_MPW_DSEG_MAX pointers.
258 max_elts < segs_n || max_wqe < 2)
260 wqe = &((volatile struct mlx5_wqe64 *)
261 txq->wqes)[wqe_ci & wq_mask].hdr;
263 (PKT_TX_IP_CKSUM | PKT_TX_TCP_CKSUM | PKT_TX_UDP_CKSUM)) {
264 const uint64_t is_tunneled = buf->ol_flags &
266 PKT_TX_TUNNEL_VXLAN);
268 if (is_tunneled && txq->tunnel_en) {
269 cs_flags = MLX5_ETH_WQE_L3_INNER_CSUM |
270 MLX5_ETH_WQE_L4_INNER_CSUM;
271 if (buf->ol_flags & PKT_TX_OUTER_IP_CKSUM)
272 cs_flags |= MLX5_ETH_WQE_L3_CSUM;
274 cs_flags = MLX5_ETH_WQE_L3_CSUM |
275 MLX5_ETH_WQE_L4_CSUM;
278 /* Title WQEBB pointer. */
279 t_wqe = (__m128i *)wqe;
280 dseg = (__m128i *)(wqe + 1);
282 if (!(ds++ % nb_dword_per_wqebb)) {
284 &((volatile struct mlx5_wqe64 *)
285 txq->wqes)[++wqe_ci & wq_mask];
287 txq_wr_dseg_v(txq, dseg++, &buf, 1);
288 (*txq->elts)[elts_head++ & elts_m] = buf;
292 /* Fill CTRL in the header. */
293 ctrl = _mm_set_epi32(0, 0, txq->qp_num_8s | ds,
294 MLX5_OPC_MOD_MPW << 24 |
295 txq->wqe_ci << 8 | MLX5_OPCODE_TSO);
296 ctrl = _mm_shuffle_epi8(ctrl, shuf_mask_ctrl);
297 _mm_store_si128(t_wqe, ctrl);
298 /* Fill ESEG in the header. */
299 _mm_store_si128(t_wqe + 1,
300 _mm_set_epi16(0, 0, 0, 0,
301 htons(len), cs_flags,
303 txq->wqe_ci = wqe_ci;
307 txq->elts_comp += (uint16_t)(elts_head - txq->elts_head);
308 txq->elts_head = elts_head;
309 if (txq->elts_comp >= MLX5_TX_COMP_THRESH) {
310 wqe->ctrl[2] = htonl(8);
311 wqe->ctrl[3] = txq->elts_head;
315 #ifdef MLX5_PMD_SOFT_COUNTERS
316 txq->stats.opackets += n;
318 mlx5_tx_dbrec(txq, wqe);
323 * Send burst of packets with Enhanced MPW. If it encounters a multi-seg packet,
324 * it returns to make it processed by txq_scatter_v(). All the packets in
325 * the pkts list should be single segment packets having same offload flags.
326 * This must be checked by txq_check_multiseg() and txq_calc_offload().
329 * Pointer to TX queue structure.
331 * Pointer to array of packets to be sent.
333 * Number of packets to be sent (<= MLX5_VPMD_TX_MAX_BURST).
335 * Checksum offload flags to be written in the descriptor.
338 * Number of packets successfully transmitted (<= pkts_n).
340 static inline uint16_t
341 txq_burst_v(struct txq *txq, struct rte_mbuf **pkts, uint16_t pkts_n,
344 struct rte_mbuf **elts;
345 uint16_t elts_head = txq->elts_head;
346 const uint16_t elts_n = 1 << txq->elts_n;
347 const uint16_t elts_m = elts_n - 1;
348 const unsigned int nb_dword_per_wqebb =
349 MLX5_WQE_SIZE / MLX5_WQE_DWORD_SIZE;
350 const unsigned int nb_dword_in_hdr =
351 sizeof(struct mlx5_wqe) / MLX5_WQE_DWORD_SIZE;
356 uint32_t comp_req = 0;
357 const uint16_t wq_n = 1 << txq->wqe_n;
358 const uint16_t wq_mask = wq_n - 1;
359 uint16_t wq_idx = txq->wqe_ci & wq_mask;
360 volatile struct mlx5_wqe64 *wq =
361 &((volatile struct mlx5_wqe64 *)txq->wqes)[wq_idx];
362 volatile struct mlx5_wqe *wqe = (volatile struct mlx5_wqe *)wq;
363 const __m128i shuf_mask_ctrl =
364 _mm_set_epi8(15, 14, 13, 12,
365 8, 9, 10, 11, /* bswap32 */
366 4, 5, 6, 7, /* bswap32 */
367 0, 1, 2, 3 /* bswap32 */);
368 __m128i *t_wqe, *dseg;
371 /* Make sure all packets can fit into a single WQE. */
372 assert(elts_n > pkts_n);
373 mlx5_tx_complete(txq);
374 max_elts = (elts_n - (elts_head - txq->elts_tail));
375 max_wqe = (1u << txq->wqe_n) - (txq->wqe_ci - txq->wqe_pi);
376 pkts_n = RTE_MIN((unsigned int)RTE_MIN(pkts_n, max_wqe), max_elts);
377 if (unlikely(!pkts_n))
379 elts = &(*txq->elts)[elts_head & elts_m];
380 /* Loop for available tailroom first. */
381 n = RTE_MIN(elts_n - (elts_head & elts_m), pkts_n);
382 for (pos = 0; pos < (n & -2); pos += 2)
383 _mm_storeu_si128((__m128i *)&elts[pos],
384 _mm_loadu_si128((__m128i *)&pkts[pos]));
386 elts[pos] = pkts[pos];
387 /* Check if it crosses the end of the queue. */
388 if (unlikely(n < pkts_n)) {
389 elts = &(*txq->elts)[0];
390 for (pos = 0; pos < pkts_n - n; ++pos)
391 elts[pos] = pkts[n + pos];
393 txq->elts_head += pkts_n;
394 /* Save title WQEBB pointer. */
395 t_wqe = (__m128i *)wqe;
396 dseg = (__m128i *)(wqe + 1);
397 /* Calculate the number of entries to the end. */
399 (wq_n - wq_idx) * nb_dword_per_wqebb - nb_dword_in_hdr,
402 txq_wr_dseg_v(txq, dseg, pkts, n);
403 /* Check if it crosses the end of the queue. */
405 dseg = (__m128i *)txq->wqes;
406 txq_wr_dseg_v(txq, dseg, &pkts[n], pkts_n - n);
408 if (txq->elts_comp + pkts_n < MLX5_TX_COMP_THRESH) {
409 txq->elts_comp += pkts_n;
411 /* Request a completion. */
416 /* Fill CTRL in the header. */
417 ctrl = _mm_set_epi32(txq->elts_head, comp_req,
418 txq->qp_num_8s | (pkts_n + 2),
419 MLX5_OPC_MOD_ENHANCED_MPSW << 24 |
420 txq->wqe_ci << 8 | MLX5_OPCODE_ENHANCED_MPSW);
421 ctrl = _mm_shuffle_epi8(ctrl, shuf_mask_ctrl);
422 _mm_store_si128(t_wqe, ctrl);
423 /* Fill ESEG in the header. */
424 _mm_store_si128(t_wqe + 1,
425 _mm_set_epi8(0, 0, 0, 0,
429 #ifdef MLX5_PMD_SOFT_COUNTERS
430 txq->stats.opackets += pkts_n;
432 txq->wqe_ci += (nb_dword_in_hdr + pkts_n + (nb_dword_per_wqebb - 1)) /
434 /* Ring QP doorbell. */
435 mlx5_tx_dbrec(txq, wqe);
440 * DPDK callback for vectorized TX.
443 * Generic pointer to TX queue structure.
445 * Packets to transmit.
447 * Number of packets in array.
450 * Number of packets successfully transmitted (<= pkts_n).
453 mlx5_tx_burst_raw_vec(void *dpdk_txq, struct rte_mbuf **pkts,
456 struct txq *txq = (struct txq *)dpdk_txq;
459 while (pkts_n > nb_tx) {
463 n = RTE_MIN((uint16_t)(pkts_n - nb_tx), MLX5_VPMD_TX_MAX_BURST);
464 ret = txq_burst_v(txq, &pkts[nb_tx], n, 0);
473 * DPDK callback for vectorized TX with multi-seg packets and offload.
476 * Generic pointer to TX queue structure.
478 * Packets to transmit.
480 * Number of packets in array.
483 * Number of packets successfully transmitted (<= pkts_n).
486 mlx5_tx_burst_vec(void *dpdk_txq, struct rte_mbuf **pkts, uint16_t pkts_n)
488 struct txq *txq = (struct txq *)dpdk_txq;
491 while (pkts_n > nb_tx) {
492 uint8_t cs_flags = 0;
496 /* Transmit multi-seg packets in the head of pkts list. */
497 if (!(txq->flags & ETH_TXQ_FLAGS_NOMULTSEGS) &&
498 NB_SEGS(pkts[nb_tx]) > 1)
499 nb_tx += txq_scatter_v(txq,
502 n = RTE_MIN((uint16_t)(pkts_n - nb_tx), MLX5_VPMD_TX_MAX_BURST);
503 if (!(txq->flags & ETH_TXQ_FLAGS_NOMULTSEGS))
504 n = txq_check_multiseg(&pkts[nb_tx], n);
505 if (!(txq->flags & ETH_TXQ_FLAGS_NOOFFLOADS))
506 n = txq_calc_offload(txq, &pkts[nb_tx], n, &cs_flags);
507 ret = txq_burst_v(txq, &pkts[nb_tx], n, cs_flags);
516 * Store free buffers to RX SW ring.
519 * Pointer to RX queue structure.
521 * Pointer to array of packets to be stored.
523 * Number of packets to be stored.
526 rxq_copy_mbuf_v(struct rxq *rxq, struct rte_mbuf **pkts, uint16_t n)
528 const uint16_t q_mask = (1 << rxq->elts_n) - 1;
529 struct rte_mbuf **elts = &(*rxq->elts)[rxq->rq_pi & q_mask];
533 for (pos = 0; pos < p; pos += 2) {
536 mbp = _mm_loadu_si128((__m128i *)&elts[pos]);
537 _mm_storeu_si128((__m128i *)&pkts[pos], mbp);
540 pkts[pos] = elts[pos];
544 * Replenish buffers for RX in bulk.
547 * Pointer to RX queue structure.
549 * Number of buffers to be replenished.
552 rxq_replenish_bulk_mbuf(struct rxq *rxq, uint16_t n)
554 const uint16_t q_n = 1 << rxq->elts_n;
555 const uint16_t q_mask = q_n - 1;
556 const uint16_t elts_idx = rxq->rq_ci & q_mask;
557 struct rte_mbuf **elts = &(*rxq->elts)[elts_idx];
558 volatile struct mlx5_wqe_data_seg *wq = &(*rxq->wqes)[elts_idx];
561 assert(n >= MLX5_VPMD_RXQ_RPLNSH_THRESH);
562 assert(n <= (uint16_t)(q_n - (rxq->rq_ci - rxq->rq_pi)));
563 assert(MLX5_VPMD_RXQ_RPLNSH_THRESH > MLX5_VPMD_DESCS_PER_LOOP);
564 /* Not to cross queue end. */
565 n = RTE_MIN(n - MLX5_VPMD_DESCS_PER_LOOP, q_n - elts_idx);
566 if (rte_mempool_get_bulk(rxq->mp, (void *)elts, n) < 0) {
567 rxq->stats.rx_nombuf += n;
570 for (i = 0; i < n; ++i)
571 wq[i].addr = htonll(rte_pktmbuf_mtod(elts[i], uintptr_t));
574 *rxq->rq_db = htonl(rxq->rq_ci);
578 * Decompress a compressed completion and fill in mbufs in RX SW ring with data
579 * extracted from the title completion descriptor.
582 * Pointer to RX queue structure.
584 * Pointer to completion array having a compressed completion at first.
586 * Pointer to SW ring to be filled. The first mbuf has to be pre-built from
587 * the title completion descriptor to be copied to the rest of mbufs.
590 rxq_cq_decompress_v(struct rxq *rxq,
591 volatile struct mlx5_cqe *cq,
592 struct rte_mbuf **elts)
594 volatile struct mlx5_mini_cqe8 *mcq = (void *)(cq + 1);
595 struct rte_mbuf *t_pkt = elts[0]; /* Title packet is pre-built. */
598 unsigned int inv = 0;
599 /* Mask to shuffle from extracted mini CQE to mbuf. */
600 const __m128i shuf_mask1 =
601 _mm_set_epi8(0, 1, 2, 3, /* rss, bswap32 */
602 -1, -1, /* skip vlan_tci */
603 6, 7, /* data_len, bswap16 */
604 -1, -1, 6, 7, /* pkt_len, bswap16 */
605 -1, -1, -1, -1 /* skip packet_type */);
606 const __m128i shuf_mask2 =
607 _mm_set_epi8(8, 9, 10, 11, /* rss, bswap32 */
608 -1, -1, /* skip vlan_tci */
609 14, 15, /* data_len, bswap16 */
610 -1, -1, 14, 15, /* pkt_len, bswap16 */
611 -1, -1, -1, -1 /* skip packet_type */);
612 /* Restore the compressed count. Must be 16 bits. */
613 const uint16_t mcqe_n = t_pkt->data_len +
614 (rxq->crc_present * ETHER_CRC_LEN);
615 const __m128i rearm =
616 _mm_loadu_si128((__m128i *)&t_pkt->rearm_data);
618 _mm_loadu_si128((__m128i *)&t_pkt->rx_descriptor_fields1);
619 const __m128i crc_adj =
620 _mm_set_epi16(0, 0, 0,
621 rxq->crc_present * ETHER_CRC_LEN,
623 rxq->crc_present * ETHER_CRC_LEN,
625 const uint32_t flow_tag = t_pkt->hash.fdir.hi;
626 #ifdef MLX5_PMD_SOFT_COUNTERS
627 const __m128i zero = _mm_setzero_si128();
628 const __m128i ones = _mm_cmpeq_epi32(zero, zero);
629 uint32_t rcvd_byte = 0;
630 /* Mask to shuffle byte_cnt to add up stats. Do bswap16 for all. */
631 const __m128i len_shuf_mask =
632 _mm_set_epi8(-1, -1, -1, -1,
638 /* Compile time sanity check for this function. */
639 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
640 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
641 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
642 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
643 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, hash) !=
644 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 12);
646 * A. load mCQEs into a 128bit register.
647 * B. store rearm data to mbuf.
648 * C. combine data from mCQEs with rx_descriptor_fields1.
649 * D. store rx_descriptor_fields1.
650 * E. store flow tag (rte_flow mark).
652 for (pos = 0; pos < mcqe_n; ) {
653 __m128i mcqe1, mcqe2;
654 __m128i rxdf1, rxdf2;
655 #ifdef MLX5_PMD_SOFT_COUNTERS
656 __m128i byte_cnt, invalid_mask;
659 if (!(pos & 0x7) && pos + 8 < mcqe_n)
660 rte_prefetch0((void *)(cq + pos + 8));
661 /* A.1 load mCQEs into a 128bit register. */
662 mcqe1 = _mm_loadu_si128((__m128i *)&mcq[pos % 8]);
663 mcqe2 = _mm_loadu_si128((__m128i *)&mcq[pos % 8 + 2]);
664 /* B.1 store rearm data to mbuf. */
665 _mm_storeu_si128((__m128i *)&elts[pos]->rearm_data, rearm);
666 _mm_storeu_si128((__m128i *)&elts[pos + 1]->rearm_data, rearm);
667 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
668 rxdf1 = _mm_shuffle_epi8(mcqe1, shuf_mask1);
669 rxdf2 = _mm_shuffle_epi8(mcqe1, shuf_mask2);
670 rxdf1 = _mm_sub_epi16(rxdf1, crc_adj);
671 rxdf2 = _mm_sub_epi16(rxdf2, crc_adj);
672 rxdf1 = _mm_blend_epi16(rxdf1, rxdf, 0x23);
673 rxdf2 = _mm_blend_epi16(rxdf2, rxdf, 0x23);
674 /* D.1 store rx_descriptor_fields1. */
675 _mm_storeu_si128((__m128i *)
676 &elts[pos]->rx_descriptor_fields1,
678 _mm_storeu_si128((__m128i *)
679 &elts[pos + 1]->rx_descriptor_fields1,
681 /* B.1 store rearm data to mbuf. */
682 _mm_storeu_si128((__m128i *)&elts[pos + 2]->rearm_data, rearm);
683 _mm_storeu_si128((__m128i *)&elts[pos + 3]->rearm_data, rearm);
684 /* C.1 combine data from mCQEs with rx_descriptor_fields1. */
685 rxdf1 = _mm_shuffle_epi8(mcqe2, shuf_mask1);
686 rxdf2 = _mm_shuffle_epi8(mcqe2, shuf_mask2);
687 rxdf1 = _mm_sub_epi16(rxdf1, crc_adj);
688 rxdf2 = _mm_sub_epi16(rxdf2, crc_adj);
689 rxdf1 = _mm_blend_epi16(rxdf1, rxdf, 0x23);
690 rxdf2 = _mm_blend_epi16(rxdf2, rxdf, 0x23);
691 /* D.1 store rx_descriptor_fields1. */
692 _mm_storeu_si128((__m128i *)
693 &elts[pos + 2]->rx_descriptor_fields1,
695 _mm_storeu_si128((__m128i *)
696 &elts[pos + 3]->rx_descriptor_fields1,
698 #ifdef MLX5_PMD_SOFT_COUNTERS
699 invalid_mask = _mm_set_epi64x(0,
701 sizeof(uint16_t) * 8);
702 invalid_mask = _mm_sll_epi64(ones, invalid_mask);
703 mcqe1 = _mm_srli_si128(mcqe1, 4);
704 byte_cnt = _mm_blend_epi16(mcqe1, mcqe2, 0xcc);
705 byte_cnt = _mm_shuffle_epi8(byte_cnt, len_shuf_mask);
706 byte_cnt = _mm_andnot_si128(invalid_mask, byte_cnt);
707 byte_cnt = _mm_hadd_epi16(byte_cnt, zero);
708 rcvd_byte += _mm_cvtsi128_si64(_mm_hadd_epi16(byte_cnt, zero));
711 /* E.1 store flow tag (rte_flow mark). */
712 elts[pos]->hash.fdir.hi = flow_tag;
713 elts[pos + 1]->hash.fdir.hi = flow_tag;
714 elts[pos + 2]->hash.fdir.hi = flow_tag;
715 elts[pos + 3]->hash.fdir.hi = flow_tag;
717 pos += MLX5_VPMD_DESCS_PER_LOOP;
718 /* Move to next CQE and invalidate consumed CQEs. */
719 if (!(pos & 0x7) && pos < mcqe_n) {
720 mcq = (void *)(cq + pos);
721 for (i = 0; i < 8; ++i)
722 cq[inv++].op_own = MLX5_CQE_INVALIDATE;
725 /* Invalidate the rest of CQEs. */
726 for (; inv < mcqe_n; ++inv)
727 cq[inv].op_own = MLX5_CQE_INVALIDATE;
728 #ifdef MLX5_PMD_SOFT_COUNTERS
729 rxq->stats.ipackets += mcqe_n;
730 rxq->stats.ibytes += rcvd_byte;
732 rxq->cq_ci += mcqe_n;
736 * Calculate packet type and offload flag for mbuf and store it.
739 * Pointer to RX queue structure.
741 * Array of four 16bytes completions extracted from the original completion
744 * Opcode vector having responder error status. Each field is 4B.
746 * Pointer to array of packets to be filled.
749 rxq_cq_to_ptype_oflags_v(struct rxq *rxq, __m128i cqes[4], __m128i op_err,
750 struct rte_mbuf **pkts)
752 __m128i pinfo0, pinfo1;
753 __m128i pinfo, ptype;
754 __m128i ol_flags = _mm_set1_epi32(rxq->rss_hash * PKT_RX_RSS_HASH);
756 const __m128i zero = _mm_setzero_si128();
757 const __m128i ptype_mask =
758 _mm_set_epi32(0xfd06, 0xfd06, 0xfd06, 0xfd06);
759 const __m128i ptype_ol_mask =
760 _mm_set_epi32(0x106, 0x106, 0x106, 0x106);
761 const __m128i pinfo_mask =
762 _mm_set_epi32(0x3, 0x3, 0x3, 0x3);
763 const __m128i cv_flag_sel =
764 _mm_set_epi8(0, 0, 0, 0, 0, 0, 0, 0, 0,
765 (uint8_t)((PKT_RX_IP_CKSUM_GOOD |
766 PKT_RX_L4_CKSUM_GOOD) >> 1),
768 (uint8_t)(PKT_RX_L4_CKSUM_GOOD >> 1),
770 (uint8_t)(PKT_RX_IP_CKSUM_GOOD >> 1),
771 (uint8_t)(PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED),
773 const __m128i cv_mask =
774 _mm_set_epi32(PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
775 PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED,
776 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
777 PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED,
778 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
779 PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED,
780 PKT_RX_IP_CKSUM_GOOD | PKT_RX_L4_CKSUM_GOOD |
781 PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED);
782 const __m128i mbuf_init =
783 _mm_loadl_epi64((__m128i *)&rxq->mbuf_initializer);
784 __m128i rearm0, rearm1, rearm2, rearm3;
786 /* Extract pkt_info field. */
787 pinfo0 = _mm_unpacklo_epi32(cqes[0], cqes[1]);
788 pinfo1 = _mm_unpacklo_epi32(cqes[2], cqes[3]);
789 pinfo = _mm_unpacklo_epi64(pinfo0, pinfo1);
790 /* Extract hdr_type_etc field. */
791 pinfo0 = _mm_unpackhi_epi32(cqes[0], cqes[1]);
792 pinfo1 = _mm_unpackhi_epi32(cqes[2], cqes[3]);
793 ptype = _mm_unpacklo_epi64(pinfo0, pinfo1);
795 const __m128i pinfo_ft_mask =
796 _mm_set_epi32(0xffffff00, 0xffffff00,
797 0xffffff00, 0xffffff00);
798 const __m128i fdir_flags = _mm_set1_epi32(PKT_RX_FDIR);
799 const __m128i fdir_id_flags = _mm_set1_epi32(PKT_RX_FDIR_ID);
800 __m128i flow_tag, invalid_mask;
802 flow_tag = _mm_and_si128(pinfo, pinfo_ft_mask);
803 /* Check if flow tag is non-zero then set PKT_RX_FDIR. */
804 invalid_mask = _mm_cmpeq_epi32(flow_tag, zero);
805 ol_flags = _mm_or_si128(ol_flags,
806 _mm_andnot_si128(invalid_mask,
808 /* Mask out invalid entries. */
809 flow_tag = _mm_andnot_si128(invalid_mask, flow_tag);
810 /* Check if flow tag MLX5_FLOW_MARK_DEFAULT. */
811 ol_flags = _mm_or_si128(ol_flags,
813 _mm_cmpeq_epi32(flow_tag,
818 * Merge the two fields to generate the following:
822 * bit[11:10] = l3_hdr_type
823 * bit[14:12] = l4_hdr_type
826 * bit[17] = outer_l3_type
828 ptype = _mm_and_si128(ptype, ptype_mask);
829 pinfo = _mm_and_si128(pinfo, pinfo_mask);
830 pinfo = _mm_slli_epi32(pinfo, 16);
831 ptype = _mm_or_si128(ptype, pinfo);
832 ptype = _mm_srli_epi32(ptype, 10);
833 ptype = _mm_packs_epi32(ptype, zero);
834 /* Errored packets will have RTE_PTYPE_ALL_MASK. */
835 op_err = _mm_srli_epi16(op_err, 8);
836 ptype = _mm_or_si128(ptype, op_err);
837 pkts[0]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 0)];
838 pkts[1]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 2)];
839 pkts[2]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 4)];
840 pkts[3]->packet_type = mlx5_ptype_table[_mm_extract_epi8(ptype, 6)];
841 /* Fill flags for checksum and VLAN. */
842 pinfo = _mm_and_si128(pinfo, ptype_ol_mask);
843 pinfo = _mm_shuffle_epi8(cv_flag_sel, pinfo);
844 /* Locate checksum flags at byte[2:1] and merge with VLAN flags. */
845 cv_flags = _mm_slli_epi32(pinfo, 9);
846 cv_flags = _mm_or_si128(pinfo, cv_flags);
847 /* Move back flags to start from byte[0]. */
848 cv_flags = _mm_srli_epi32(cv_flags, 8);
849 /* Mask out garbage bits. */
850 cv_flags = _mm_and_si128(cv_flags, cv_mask);
851 /* Merge to ol_flags. */
852 ol_flags = _mm_or_si128(ol_flags, cv_flags);
853 /* Merge mbuf_init and ol_flags. */
854 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, ol_flags) !=
855 offsetof(struct rte_mbuf, rearm_data) + 8);
856 rearm0 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(ol_flags, 8), 0x30);
857 rearm1 = _mm_blend_epi16(mbuf_init, _mm_slli_si128(ol_flags, 4), 0x30);
858 rearm2 = _mm_blend_epi16(mbuf_init, ol_flags, 0x30);
859 rearm3 = _mm_blend_epi16(mbuf_init, _mm_srli_si128(ol_flags, 4), 0x30);
860 /* Write 8B rearm_data and 8B ol_flags. */
861 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, rearm_data) !=
862 RTE_ALIGN(offsetof(struct rte_mbuf, rearm_data), 16));
863 _mm_store_si128((__m128i *)&pkts[0]->rearm_data, rearm0);
864 _mm_store_si128((__m128i *)&pkts[1]->rearm_data, rearm1);
865 _mm_store_si128((__m128i *)&pkts[2]->rearm_data, rearm2);
866 _mm_store_si128((__m128i *)&pkts[3]->rearm_data, rearm3);
870 * Skip error packets.
873 * Pointer to RX queue structure.
875 * Array to store received packets.
877 * Maximum number of packets in array.
880 * Number of packets successfully received (<= pkts_n).
883 rxq_handle_pending_error(struct rxq *rxq, struct rte_mbuf **pkts,
889 for (i = 0; i < pkts_n; ++i) {
890 struct rte_mbuf *pkt = pkts[i];
892 if (pkt->packet_type == RTE_PTYPE_ALL_MASK)
893 rte_pktmbuf_free_seg(pkt);
897 rxq->stats.idropped += (pkts_n - n);
898 rxq->pending_err = 0;
903 * Receive burst of packets. An errored completion also consumes a mbuf, but the
904 * packet_type is set to be RTE_PTYPE_ALL_MASK. Marked mbufs should be freed
905 * before returning to application.
908 * Pointer to RX queue structure.
910 * Array to store received packets.
912 * Maximum number of packets in array.
915 * Number of packets received including errors (<= pkts_n).
917 static inline uint16_t
918 rxq_burst_v(struct rxq *rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
920 const uint16_t q_n = 1 << rxq->cqe_n;
921 const uint16_t q_mask = q_n - 1;
922 volatile struct mlx5_cqe *cq;
923 struct rte_mbuf **elts;
927 uint64_t comp_idx = MLX5_VPMD_DESCS_PER_LOOP;
928 uint16_t nocmp_n = 0;
929 uint16_t rcvd_pkt = 0;
930 unsigned int cq_idx = rxq->cq_ci & q_mask;
931 unsigned int elts_idx;
932 unsigned int ownership = !!(rxq->cq_ci & (q_mask + 1));
933 const __m128i owner_check =
934 _mm_set_epi64x(0x0100000001000000LL, 0x0100000001000000LL);
935 const __m128i opcode_check =
936 _mm_set_epi64x(0xf0000000f0000000LL, 0xf0000000f0000000LL);
937 const __m128i format_check =
938 _mm_set_epi64x(0x0c0000000c000000LL, 0x0c0000000c000000LL);
939 const __m128i resp_err_check =
940 _mm_set_epi64x(0xe0000000e0000000LL, 0xe0000000e0000000LL);
941 #ifdef MLX5_PMD_SOFT_COUNTERS
942 uint32_t rcvd_byte = 0;
943 /* Mask to shuffle byte_cnt to add up stats. Do bswap16 for all. */
944 const __m128i len_shuf_mask =
945 _mm_set_epi8(-1, -1, -1, -1,
950 /* Mask to shuffle from extracted CQE to mbuf. */
951 const __m128i shuf_mask =
952 _mm_set_epi8(-1, 3, 2, 1, /* fdir.hi */
953 12, 13, 14, 15, /* rss, bswap32 */
954 10, 11, /* vlan_tci, bswap16 */
955 4, 5, /* data_len, bswap16 */
956 -1, -1, /* zero out 2nd half of pkt_len */
957 4, 5 /* pkt_len, bswap16 */);
958 /* Mask to blend from the last Qword to the first DQword. */
959 const __m128i blend_mask =
960 _mm_set_epi8(-1, -1, -1, -1,
964 const __m128i zero = _mm_setzero_si128();
965 const __m128i ones = _mm_cmpeq_epi32(zero, zero);
966 const __m128i crc_adj =
967 _mm_set_epi16(0, 0, 0, 0, 0,
968 rxq->crc_present * ETHER_CRC_LEN,
970 rxq->crc_present * ETHER_CRC_LEN);
971 const __m128i flow_mark_adj = _mm_set_epi32(rxq->mark * (-1), 0, 0, 0);
973 /* Compile time sanity check for this function. */
974 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pkt_len) !=
975 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 4);
976 RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_len) !=
977 offsetof(struct rte_mbuf, rx_descriptor_fields1) + 8);
978 RTE_BUILD_BUG_ON(offsetof(struct mlx5_cqe, pkt_info) != 0);
979 RTE_BUILD_BUG_ON(offsetof(struct mlx5_cqe, rx_hash_res) !=
980 offsetof(struct mlx5_cqe, pkt_info) + 12);
981 RTE_BUILD_BUG_ON(offsetof(struct mlx5_cqe, rsvd1) +
982 sizeof(((struct mlx5_cqe *)0)->rsvd1) !=
983 offsetof(struct mlx5_cqe, hdr_type_etc));
984 RTE_BUILD_BUG_ON(offsetof(struct mlx5_cqe, vlan_info) !=
985 offsetof(struct mlx5_cqe, hdr_type_etc) + 2);
986 RTE_BUILD_BUG_ON(offsetof(struct mlx5_cqe, rsvd2) +
987 sizeof(((struct mlx5_cqe *)0)->rsvd2) !=
988 offsetof(struct mlx5_cqe, byte_cnt));
989 RTE_BUILD_BUG_ON(offsetof(struct mlx5_cqe, sop_drop_qpn) !=
990 RTE_ALIGN(offsetof(struct mlx5_cqe, sop_drop_qpn), 8));
991 RTE_BUILD_BUG_ON(offsetof(struct mlx5_cqe, op_own) !=
992 offsetof(struct mlx5_cqe, sop_drop_qpn) + 7);
993 assert(rxq->sges_n == 0);
994 assert(rxq->cqe_n == rxq->elts_n);
995 cq = &(*rxq->cqes)[cq_idx];
997 rte_prefetch0(cq + 1);
998 rte_prefetch0(cq + 2);
999 rte_prefetch0(cq + 3);
1000 pkts_n = RTE_MIN(pkts_n, MLX5_VPMD_RX_MAX_BURST);
1003 * rq_ci >= cq_ci >= rq_pi
1004 * Definition of indexes:
1005 * rq_ci - cq_ci := # of buffers owned by HW (posted).
1006 * cq_ci - rq_pi := # of buffers not returned to app (decompressed).
1007 * N - (rq_ci - rq_pi) := # of buffers consumed (to be replenished).
1009 repl_n = q_n - (rxq->rq_ci - rxq->rq_pi);
1010 if (repl_n >= MLX5_VPMD_RXQ_RPLNSH_THRESH)
1011 rxq_replenish_bulk_mbuf(rxq, repl_n);
1012 /* See if there're unreturned mbufs from compressed CQE. */
1013 rcvd_pkt = rxq->cq_ci - rxq->rq_pi;
1015 rcvd_pkt = RTE_MIN(rcvd_pkt, pkts_n);
1016 rxq_copy_mbuf_v(rxq, pkts, rcvd_pkt);
1017 rxq->rq_pi += rcvd_pkt;
1020 elts_idx = rxq->rq_pi & q_mask;
1021 elts = &(*rxq->elts)[elts_idx];
1022 /* Not to overflow pkts array. */
1023 pkts_n = RTE_ALIGN_FLOOR(pkts_n - rcvd_pkt, MLX5_VPMD_DESCS_PER_LOOP);
1024 /* Not to cross queue end. */
1025 pkts_n = RTE_MIN(pkts_n, q_n - elts_idx);
1028 /* At this point, there shouldn't be any remained packets. */
1029 assert(rxq->rq_pi == rxq->cq_ci);
1031 * A. load first Qword (8bytes) in one loop.
1032 * B. copy 4 mbuf pointers from elts ring to returing pkts.
1033 * C. load remained CQE data and extract necessary fields.
1034 * Final 16bytes cqes[] extracted from original 64bytes CQE has the
1035 * following structure:
1038 * uint8_t flow_tag[3];
1039 * uint16_t byte_cnt;
1042 * uint16_t hdr_type_etc;
1043 * uint16_t vlan_info;
1044 * uint32_t rx_has_res;
1047 * E. get valid CQEs.
1048 * F. find compressed CQE.
1052 pos += MLX5_VPMD_DESCS_PER_LOOP) {
1053 __m128i cqes[MLX5_VPMD_DESCS_PER_LOOP];
1054 __m128i cqe_tmp1, cqe_tmp2;
1055 __m128i pkt_mb0, pkt_mb1, pkt_mb2, pkt_mb3;
1056 __m128i op_own, op_own_tmp1, op_own_tmp2;
1057 __m128i opcode, owner_mask, invalid_mask;
1060 #ifdef MLX5_PMD_SOFT_COUNTERS
1064 __m128i p = _mm_set_epi16(0, 0, 0, 0, 3, 2, 1, 0);
1065 unsigned int p1, p2, p3;
1067 /* Prefetch next 4 CQEs. */
1068 if (pkts_n - pos >= 2 * MLX5_VPMD_DESCS_PER_LOOP) {
1069 rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP]);
1070 rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 1]);
1071 rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 2]);
1072 rte_prefetch0(&cq[pos + MLX5_VPMD_DESCS_PER_LOOP + 3]);
1074 /* A.0 do not cross the end of CQ. */
1075 mask = _mm_set_epi64x(0, (pkts_n - pos) * sizeof(uint16_t) * 8);
1076 mask = _mm_sll_epi64(ones, mask);
1077 p = _mm_andnot_si128(mask, p);
1078 /* A.1 load cqes. */
1079 p3 = _mm_extract_epi16(p, 3);
1080 cqes[3] = _mm_loadl_epi64((__m128i *)
1081 &cq[pos + p3].sop_drop_qpn);
1082 rte_compiler_barrier();
1083 p2 = _mm_extract_epi16(p, 2);
1084 cqes[2] = _mm_loadl_epi64((__m128i *)
1085 &cq[pos + p2].sop_drop_qpn);
1086 rte_compiler_barrier();
1087 /* B.1 load mbuf pointers. */
1088 mbp1 = _mm_loadu_si128((__m128i *)&elts[pos]);
1089 mbp2 = _mm_loadu_si128((__m128i *)&elts[pos + 2]);
1090 /* A.1 load a block having op_own. */
1091 p1 = _mm_extract_epi16(p, 1);
1092 cqes[1] = _mm_loadl_epi64((__m128i *)
1093 &cq[pos + p1].sop_drop_qpn);
1094 rte_compiler_barrier();
1095 cqes[0] = _mm_loadl_epi64((__m128i *)
1096 &cq[pos].sop_drop_qpn);
1097 /* B.2 copy mbuf pointers. */
1098 _mm_storeu_si128((__m128i *)&pkts[pos], mbp1);
1099 _mm_storeu_si128((__m128i *)&pkts[pos + 2], mbp2);
1100 rte_compiler_barrier();
1101 /* C.1 load remained CQE data and extract necessary fields. */
1102 cqe_tmp2 = _mm_load_si128((__m128i *)&cq[pos + p3]);
1103 cqe_tmp1 = _mm_load_si128((__m128i *)&cq[pos + p2]);
1104 cqes[3] = _mm_blendv_epi8(cqes[3], cqe_tmp2, blend_mask);
1105 cqes[2] = _mm_blendv_epi8(cqes[2], cqe_tmp1, blend_mask);
1106 cqe_tmp2 = _mm_loadu_si128((__m128i *)&cq[pos + p3].rsvd1[3]);
1107 cqe_tmp1 = _mm_loadu_si128((__m128i *)&cq[pos + p2].rsvd1[3]);
1108 cqes[3] = _mm_blend_epi16(cqes[3], cqe_tmp2, 0x30);
1109 cqes[2] = _mm_blend_epi16(cqes[2], cqe_tmp1, 0x30);
1110 cqe_tmp2 = _mm_loadl_epi64((__m128i *)&cq[pos + p3].rsvd2[10]);
1111 cqe_tmp1 = _mm_loadl_epi64((__m128i *)&cq[pos + p2].rsvd2[10]);
1112 cqes[3] = _mm_blend_epi16(cqes[3], cqe_tmp2, 0x04);
1113 cqes[2] = _mm_blend_epi16(cqes[2], cqe_tmp1, 0x04);
1114 /* C.2 generate final structure for mbuf with swapping bytes. */
1115 pkt_mb3 = _mm_shuffle_epi8(cqes[3], shuf_mask);
1116 pkt_mb2 = _mm_shuffle_epi8(cqes[2], shuf_mask);
1117 /* C.3 adjust CRC length. */
1118 pkt_mb3 = _mm_sub_epi16(pkt_mb3, crc_adj);
1119 pkt_mb2 = _mm_sub_epi16(pkt_mb2, crc_adj);
1120 /* C.4 adjust flow mark. */
1121 pkt_mb3 = _mm_add_epi32(pkt_mb3, flow_mark_adj);
1122 pkt_mb2 = _mm_add_epi32(pkt_mb2, flow_mark_adj);
1123 /* D.1 fill in mbuf - rx_descriptor_fields1. */
1124 _mm_storeu_si128((void *)&pkts[pos + 3]->pkt_len, pkt_mb3);
1125 _mm_storeu_si128((void *)&pkts[pos + 2]->pkt_len, pkt_mb2);
1126 /* E.1 extract op_own field. */
1127 op_own_tmp2 = _mm_unpacklo_epi32(cqes[2], cqes[3]);
1128 /* C.1 load remained CQE data and extract necessary fields. */
1129 cqe_tmp2 = _mm_load_si128((__m128i *)&cq[pos + p1]);
1130 cqe_tmp1 = _mm_load_si128((__m128i *)&cq[pos]);
1131 cqes[1] = _mm_blendv_epi8(cqes[1], cqe_tmp2, blend_mask);
1132 cqes[0] = _mm_blendv_epi8(cqes[0], cqe_tmp1, blend_mask);
1133 cqe_tmp2 = _mm_loadu_si128((__m128i *)&cq[pos + p1].rsvd1[3]);
1134 cqe_tmp1 = _mm_loadu_si128((__m128i *)&cq[pos].rsvd1[3]);
1135 cqes[1] = _mm_blend_epi16(cqes[1], cqe_tmp2, 0x30);
1136 cqes[0] = _mm_blend_epi16(cqes[0], cqe_tmp1, 0x30);
1137 cqe_tmp2 = _mm_loadl_epi64((__m128i *)&cq[pos + p1].rsvd2[10]);
1138 cqe_tmp1 = _mm_loadl_epi64((__m128i *)&cq[pos].rsvd2[10]);
1139 cqes[1] = _mm_blend_epi16(cqes[1], cqe_tmp2, 0x04);
1140 cqes[0] = _mm_blend_epi16(cqes[0], cqe_tmp1, 0x04);
1141 /* C.2 generate final structure for mbuf with swapping bytes. */
1142 pkt_mb1 = _mm_shuffle_epi8(cqes[1], shuf_mask);
1143 pkt_mb0 = _mm_shuffle_epi8(cqes[0], shuf_mask);
1144 /* C.3 adjust CRC length. */
1145 pkt_mb1 = _mm_sub_epi16(pkt_mb1, crc_adj);
1146 pkt_mb0 = _mm_sub_epi16(pkt_mb0, crc_adj);
1147 /* C.4 adjust flow mark. */
1148 pkt_mb1 = _mm_add_epi32(pkt_mb1, flow_mark_adj);
1149 pkt_mb0 = _mm_add_epi32(pkt_mb0, flow_mark_adj);
1150 /* E.1 extract op_own byte. */
1151 op_own_tmp1 = _mm_unpacklo_epi32(cqes[0], cqes[1]);
1152 op_own = _mm_unpackhi_epi64(op_own_tmp1, op_own_tmp2);
1153 /* D.1 fill in mbuf - rx_descriptor_fields1. */
1154 _mm_storeu_si128((void *)&pkts[pos + 1]->pkt_len, pkt_mb1);
1155 _mm_storeu_si128((void *)&pkts[pos]->pkt_len, pkt_mb0);
1156 /* E.2 flip owner bit to mark CQEs from last round. */
1157 owner_mask = _mm_and_si128(op_own, owner_check);
1159 owner_mask = _mm_xor_si128(owner_mask, owner_check);
1160 owner_mask = _mm_cmpeq_epi32(owner_mask, owner_check);
1161 owner_mask = _mm_packs_epi32(owner_mask, zero);
1162 /* E.3 get mask for invalidated CQEs. */
1163 opcode = _mm_and_si128(op_own, opcode_check);
1164 invalid_mask = _mm_cmpeq_epi32(opcode_check, opcode);
1165 invalid_mask = _mm_packs_epi32(invalid_mask, zero);
1166 /* E.4 mask out beyond boundary. */
1167 invalid_mask = _mm_or_si128(invalid_mask, mask);
1168 /* E.5 merge invalid_mask with invalid owner. */
1169 invalid_mask = _mm_or_si128(invalid_mask, owner_mask);
1170 /* F.1 find compressed CQE format. */
1171 comp_mask = _mm_and_si128(op_own, format_check);
1172 comp_mask = _mm_cmpeq_epi32(comp_mask, format_check);
1173 comp_mask = _mm_packs_epi32(comp_mask, zero);
1174 /* F.2 mask out invalid entries. */
1175 comp_mask = _mm_andnot_si128(invalid_mask, comp_mask);
1176 comp_idx = _mm_cvtsi128_si64(comp_mask);
1177 /* F.3 get the first compressed CQE. */
1178 comp_idx = comp_idx ?
1179 __builtin_ctzll(comp_idx) /
1180 (sizeof(uint16_t) * 8) :
1181 MLX5_VPMD_DESCS_PER_LOOP;
1182 /* E.6 mask out entries after the compressed CQE. */
1183 mask = _mm_set_epi64x(0, comp_idx * sizeof(uint16_t) * 8);
1184 mask = _mm_sll_epi64(ones, mask);
1185 invalid_mask = _mm_or_si128(invalid_mask, mask);
1186 /* E.7 count non-compressed valid CQEs. */
1187 n = _mm_cvtsi128_si64(invalid_mask);
1188 n = n ? __builtin_ctzll(n) / (sizeof(uint16_t) * 8) :
1189 MLX5_VPMD_DESCS_PER_LOOP;
1191 /* D.2 get the final invalid mask. */
1192 mask = _mm_set_epi64x(0, n * sizeof(uint16_t) * 8);
1193 mask = _mm_sll_epi64(ones, mask);
1194 invalid_mask = _mm_or_si128(invalid_mask, mask);
1195 /* D.3 check error in opcode. */
1196 opcode = _mm_cmpeq_epi32(resp_err_check, opcode);
1197 opcode = _mm_packs_epi32(opcode, zero);
1198 opcode = _mm_andnot_si128(invalid_mask, opcode);
1199 /* D.4 mark if any error is set */
1200 rxq->pending_err |= !!_mm_cvtsi128_si64(opcode);
1201 /* D.5 fill in mbuf - rearm_data and packet_type. */
1202 rxq_cq_to_ptype_oflags_v(rxq, cqes, opcode, &pkts[pos]);
1203 #ifdef MLX5_PMD_SOFT_COUNTERS
1204 /* Add up received bytes count. */
1205 byte_cnt = _mm_shuffle_epi8(op_own, len_shuf_mask);
1206 byte_cnt = _mm_andnot_si128(invalid_mask, byte_cnt);
1207 byte_cnt = _mm_hadd_epi16(byte_cnt, zero);
1208 rcvd_byte += _mm_cvtsi128_si64(_mm_hadd_epi16(byte_cnt, zero));
1211 * Break the loop unless more valid CQE is expected, or if
1212 * there's a compressed CQE.
1214 if (n != MLX5_VPMD_DESCS_PER_LOOP)
1217 /* If no new CQE seen, return without updating cq_db. */
1218 if (unlikely(!nocmp_n && comp_idx == MLX5_VPMD_DESCS_PER_LOOP))
1220 /* Update the consumer indexes for non-compressed CQEs. */
1221 assert(nocmp_n <= pkts_n);
1222 rxq->cq_ci += nocmp_n;
1223 rxq->rq_pi += nocmp_n;
1224 rcvd_pkt += nocmp_n;
1225 #ifdef MLX5_PMD_SOFT_COUNTERS
1226 rxq->stats.ipackets += nocmp_n;
1227 rxq->stats.ibytes += rcvd_byte;
1229 /* Decompress the last CQE if compressed. */
1230 if (comp_idx < MLX5_VPMD_DESCS_PER_LOOP && comp_idx == n) {
1231 assert(comp_idx == (nocmp_n % MLX5_VPMD_DESCS_PER_LOOP));
1232 rxq_cq_decompress_v(rxq, &cq[nocmp_n], &elts[nocmp_n]);
1233 /* Return more packets if needed. */
1234 if (nocmp_n < pkts_n) {
1235 uint16_t n = rxq->cq_ci - rxq->rq_pi;
1237 n = RTE_MIN(n, pkts_n - nocmp_n);
1238 rxq_copy_mbuf_v(rxq, &pkts[nocmp_n], n);
1244 *rxq->cq_db = htonl(rxq->cq_ci);
1249 * DPDK callback for vectorized RX.
1252 * Generic pointer to RX queue structure.
1254 * Array to store received packets.
1256 * Maximum number of packets in array.
1259 * Number of packets successfully received (<= pkts_n).
1262 mlx5_rx_burst_vec(void *dpdk_rxq, struct rte_mbuf **pkts, uint16_t pkts_n)
1264 struct rxq *rxq = dpdk_rxq;
1267 nb_rx = rxq_burst_v(rxq, pkts, pkts_n);
1268 if (unlikely(rxq->pending_err))
1269 nb_rx = rxq_handle_pending_error(rxq, pkts, nb_rx);
1274 * Check Tx queue flags are set for raw vectorized Tx.
1277 * Pointer to private structure.
1280 * 1 if supported, negative errno value if not.
1282 int __attribute__((cold))
1283 priv_check_raw_vec_tx_support(struct priv *priv)
1287 /* All the configured queues should support. */
1288 for (i = 0; i < priv->txqs_n; ++i) {
1289 struct txq *txq = (*priv->txqs)[i];
1291 if (!(txq->flags & ETH_TXQ_FLAGS_NOMULTSEGS) ||
1292 !(txq->flags & ETH_TXQ_FLAGS_NOOFFLOADS))
1295 if (i != priv->txqs_n)
1301 * Check a device can support vectorized TX.
1304 * Pointer to private structure.
1307 * 1 if supported, negative errno value if not.
1309 int __attribute__((cold))
1310 priv_check_vec_tx_support(struct priv *priv)
1312 if (priv->txqs_n > MLX5_VPMD_MIN_TXQS ||
1313 priv->mps != MLX5_MPW_ENHANCED ||
1320 * Check a RX queue can support vectorized RX.
1323 * Pointer to RX queue.
1326 * 1 if supported, negative errno value if not.
1328 int __attribute__((cold))
1329 rxq_check_vec_support(struct rxq *rxq)
1331 if (rxq->sges_n != 0)
1337 * Check a device can support vectorized RX.
1340 * Pointer to private structure.
1343 * 1 if supported, negative errno value if not.
1345 int __attribute__((cold))
1346 priv_check_vec_rx_support(struct priv *priv)
1350 /* All the configured queues should support. */
1351 for (i = 0; i < priv->rxqs_n; ++i) {
1352 struct rxq *rxq = (*priv->rxqs)[i];
1354 if (rxq_check_vec_support(rxq) < 0)
1357 if (i != priv->rxqs_n)
1363 * Prepare for vectorized RX.
1366 * Pointer to private structure.
1369 priv_prep_vec_rx_function(struct priv *priv)
1373 for (i = 0; i < priv->rxqs_n; ++i) {
1374 struct rxq *rxq = (*priv->rxqs)[i];
1375 struct rte_mbuf *mbuf_init = &rxq->fake_mbuf;
1376 const uint16_t desc = 1 << rxq->elts_n;
1379 assert(rxq->elts_n == rxq->cqe_n);
1380 /* Initialize default rearm_data for vPMD. */
1381 mbuf_init->data_off = RTE_PKTMBUF_HEADROOM;
1382 rte_mbuf_refcnt_set(mbuf_init, 1);
1383 mbuf_init->nb_segs = 1;
1384 mbuf_init->port = rxq->port_id;
1386 * prevent compiler reordering:
1387 * rearm_data covers previous fields.
1389 rte_compiler_barrier();
1390 rxq->mbuf_initializer =
1391 *(uint64_t *)&mbuf_init->rearm_data;
1392 /* Padding with a fake mbuf for vectorized Rx. */
1393 for (j = 0; j < MLX5_VPMD_DESCS_PER_LOOP; ++j)
1394 (*rxq->elts)[desc + j] = &rxq->fake_mbuf;
1395 /* Mark that it need to be cleaned up for rxq_alloc_elts(). */