1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2015 Intel Corporation
6 #include <rte_ethdev_driver.h>
7 #include <rte_malloc.h>
10 #include "ixgbe_ethdev.h"
11 #include "ixgbe_rxtx.h"
12 #include "ixgbe_rxtx_vec_common.h"
14 #pragma GCC diagnostic ignored "-Wcast-qual"
17 ixgbe_rxq_rearm(struct ixgbe_rx_queue *rxq)
21 volatile union ixgbe_adv_rx_desc *rxdp;
22 struct ixgbe_rx_entry *rxep = &rxq->sw_ring[rxq->rxrearm_start];
23 struct rte_mbuf *mb0, *mb1;
24 uint64x2_t dma_addr0, dma_addr1;
25 uint64x2_t zero = vdupq_n_u64(0);
29 rxdp = rxq->rx_ring + rxq->rxrearm_start;
31 /* Pull 'n' more MBUFs into the software ring */
32 if (unlikely(rte_mempool_get_bulk(rxq->mb_pool,
34 RTE_IXGBE_RXQ_REARM_THRESH) < 0)) {
35 if (rxq->rxrearm_nb + RTE_IXGBE_RXQ_REARM_THRESH >=
37 for (i = 0; i < RTE_IXGBE_DESCS_PER_LOOP; i++) {
38 rxep[i].mbuf = &rxq->fake_mbuf;
39 vst1q_u64((uint64_t *)&rxdp[i].read,
43 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
44 RTE_IXGBE_RXQ_REARM_THRESH;
48 p = vld1_u8((uint8_t *)&rxq->mbuf_initializer);
50 /* Initialize the mbufs in vector, process 2 mbufs in one loop */
51 for (i = 0; i < RTE_IXGBE_RXQ_REARM_THRESH; i += 2, rxep += 2) {
56 * Flush mbuf with pkt template.
57 * Data to be rearmed is 6 bytes long.
59 vst1_u8((uint8_t *)&mb0->rearm_data, p);
60 paddr = mb0->buf_iova + RTE_PKTMBUF_HEADROOM;
61 dma_addr0 = vsetq_lane_u64(paddr, zero, 0);
62 /* flush desc with pa dma_addr */
63 vst1q_u64((uint64_t *)&rxdp++->read, dma_addr0);
65 vst1_u8((uint8_t *)&mb1->rearm_data, p);
66 paddr = mb1->buf_iova + RTE_PKTMBUF_HEADROOM;
67 dma_addr1 = vsetq_lane_u64(paddr, zero, 0);
68 vst1q_u64((uint64_t *)&rxdp++->read, dma_addr1);
71 rxq->rxrearm_start += RTE_IXGBE_RXQ_REARM_THRESH;
72 if (rxq->rxrearm_start >= rxq->nb_rx_desc)
73 rxq->rxrearm_start = 0;
75 rxq->rxrearm_nb -= RTE_IXGBE_RXQ_REARM_THRESH;
77 rx_id = (uint16_t)((rxq->rxrearm_start == 0) ?
78 (rxq->nb_rx_desc - 1) : (rxq->rxrearm_start - 1));
80 /* Update the tail pointer on the NIC */
81 IXGBE_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
84 #define VTAG_SHIFT (3)
87 desc_to_olflags_v(uint8x16x2_t sterr_tmp1, uint8x16x2_t sterr_tmp2,
88 uint8x16_t staterr, struct rte_mbuf **rx_pkts)
98 const uint8x16_t pkttype_msk = {
99 PKT_RX_VLAN, PKT_RX_VLAN,
100 PKT_RX_VLAN, PKT_RX_VLAN,
101 0x00, 0x00, 0x00, 0x00,
102 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00};
105 const uint8x16_t rsstype_msk = {
106 0x0F, 0x0F, 0x0F, 0x0F,
107 0x00, 0x00, 0x00, 0x00,
108 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00};
111 const uint8x16_t rss_flags = {
112 0, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH,
113 0, PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH,
114 PKT_RX_RSS_HASH, 0, 0, 0,
115 0, 0, 0, PKT_RX_FDIR};
117 ptype = vzipq_u8(sterr_tmp1.val[0], sterr_tmp2.val[0]).val[0];
118 ptype = vandq_u8(ptype, rsstype_msk);
119 ptype = vqtbl1q_u8(rss_flags, ptype);
121 vtag = vshrq_n_u8(staterr, VTAG_SHIFT);
122 vtag = vandq_u8(vtag, pkttype_msk);
123 vtag = vorrq_u8(ptype, vtag);
125 vol.word = vgetq_lane_u32(vreinterpretq_u32_u8(vtag), 0);
127 rx_pkts[0]->ol_flags = vol.e[0];
128 rx_pkts[1]->ol_flags = vol.e[1];
129 rx_pkts[2]->ol_flags = vol.e[2];
130 rx_pkts[3]->ol_flags = vol.e[3];
134 * vPMD raw receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
137 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
138 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
140 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
141 * - don't support ol_flags for rss and csum err
144 #define IXGBE_VPMD_DESC_EOP_MASK 0x02020202
145 #define IXGBE_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
147 static inline uint32_t
148 get_packet_type(uint32_t pkt_info,
150 uint32_t tunnel_check)
153 return RTE_PTYPE_UNKNOWN;
156 pkt_info &= IXGBE_PACKET_TYPE_MASK_TUNNEL;
157 return ptype_table_tn[pkt_info];
160 pkt_info &= IXGBE_PACKET_TYPE_MASK_82599;
161 return ptype_table[pkt_info];
165 desc_to_ptype_v(uint64x2_t descs[4], uint16_t pkt_type_mask,
166 struct rte_mbuf **rx_pkts)
168 uint32x4_t etqf_check, tunnel_check;
169 uint32x4_t etqf_mask = vdupq_n_u32(0x8000);
170 uint32x4_t tunnel_mask = vdupq_n_u32(0x10000);
171 uint32x4_t ptype_mask = vdupq_n_u32((uint32_t)pkt_type_mask);
172 uint32x4_t ptype0 = vzipq_u32(vreinterpretq_u32_u64(descs[0]),
173 vreinterpretq_u32_u64(descs[2])).val[0];
174 uint32x4_t ptype1 = vzipq_u32(vreinterpretq_u32_u64(descs[1]),
175 vreinterpretq_u32_u64(descs[3])).val[0];
177 /* interleave low 32 bits,
178 * now we have 4 ptypes in a NEON register
180 ptype0 = vzipq_u32(ptype0, ptype1).val[0];
183 etqf_check = vandq_u32(ptype0, etqf_mask);
184 /* mask tunnel bits */
185 tunnel_check = vandq_u32(ptype0, tunnel_mask);
187 /* shift right by IXGBE_PACKET_TYPE_SHIFT, and apply ptype mask */
188 ptype0 = vandq_u32(vshrq_n_u32(ptype0, IXGBE_PACKET_TYPE_SHIFT),
191 rx_pkts[0]->packet_type =
192 get_packet_type(vgetq_lane_u32(ptype0, 0),
193 vgetq_lane_u32(etqf_check, 0),
194 vgetq_lane_u32(tunnel_check, 0));
195 rx_pkts[1]->packet_type =
196 get_packet_type(vgetq_lane_u32(ptype0, 1),
197 vgetq_lane_u32(etqf_check, 1),
198 vgetq_lane_u32(tunnel_check, 1));
199 rx_pkts[2]->packet_type =
200 get_packet_type(vgetq_lane_u32(ptype0, 2),
201 vgetq_lane_u32(etqf_check, 2),
202 vgetq_lane_u32(tunnel_check, 2));
203 rx_pkts[3]->packet_type =
204 get_packet_type(vgetq_lane_u32(ptype0, 3),
205 vgetq_lane_u32(etqf_check, 3),
206 vgetq_lane_u32(tunnel_check, 3));
209 static inline uint16_t
210 _recv_raw_pkts_vec(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
211 uint16_t nb_pkts, uint8_t *split_packet)
213 volatile union ixgbe_adv_rx_desc *rxdp;
214 struct ixgbe_rx_entry *sw_ring;
215 uint16_t nb_pkts_recd;
217 uint8x16_t shuf_msk = {
219 0xFF, 0xFF, /* skip 32 bits pkt_type */
220 12, 13, /* octet 12~13, low 16 bits pkt_len */
221 0xFF, 0xFF, /* skip high 16 bits pkt_len, zero out */
222 12, 13, /* octet 12~13, 16 bits data_len */
223 14, 15, /* octet 14~15, low 16 bits vlan_macip */
224 4, 5, 6, 7 /* octet 4~7, 32bits rss */
226 uint16x8_t crc_adjust = {0, 0, rxq->crc_len, 0,
227 rxq->crc_len, 0, 0, 0};
229 /* nb_pkts shall be less equal than RTE_IXGBE_MAX_RX_BURST */
230 nb_pkts = RTE_MIN(nb_pkts, RTE_IXGBE_MAX_RX_BURST);
232 /* nb_pkts has to be floor-aligned to RTE_IXGBE_DESCS_PER_LOOP */
233 nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_IXGBE_DESCS_PER_LOOP);
235 /* Just the act of getting into the function from the application is
236 * going to cost about 7 cycles
238 rxdp = rxq->rx_ring + rxq->rx_tail;
240 rte_prefetch_non_temporal(rxdp);
242 /* See if we need to rearm the RX queue - gives the prefetch a bit
245 if (rxq->rxrearm_nb > RTE_IXGBE_RXQ_REARM_THRESH)
246 ixgbe_rxq_rearm(rxq);
248 /* Before we start moving massive data around, check to see if
249 * there is actually a packet available
251 if (!(rxdp->wb.upper.status_error &
252 rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
255 /* Cache is empty -> need to scan the buffer rings, but first move
256 * the next 'n' mbufs into the cache
258 sw_ring = &rxq->sw_ring[rxq->rx_tail];
260 /* A. load 4 packet in one loop
261 * B. copy 4 mbuf point from swring to rx_pkts
262 * C. calc the number of DD bits among the 4 packets
263 * [C*. extract the end-of-packet bit, if requested]
264 * D. fill info. from desc to mbuf
266 for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
267 pos += RTE_IXGBE_DESCS_PER_LOOP,
268 rxdp += RTE_IXGBE_DESCS_PER_LOOP) {
269 uint64x2_t descs[RTE_IXGBE_DESCS_PER_LOOP];
270 uint8x16_t pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
271 uint8x16x2_t sterr_tmp1, sterr_tmp2;
272 uint64x2_t mbp1, mbp2;
277 /* B.1 load 2 mbuf point */
278 mbp1 = vld1q_u64((uint64_t *)&sw_ring[pos]);
280 /* B.2 copy 2 mbuf point into rx_pkts */
281 vst1q_u64((uint64_t *)&rx_pkts[pos], mbp1);
283 /* B.1 load 2 mbuf point */
284 mbp2 = vld1q_u64((uint64_t *)&sw_ring[pos + 2]);
286 /* A. load 4 pkts descs */
287 descs[0] = vld1q_u64((uint64_t *)(rxdp));
288 descs[1] = vld1q_u64((uint64_t *)(rxdp + 1));
289 descs[2] = vld1q_u64((uint64_t *)(rxdp + 2));
290 descs[3] = vld1q_u64((uint64_t *)(rxdp + 3));
292 /* B.2 copy 2 mbuf point into rx_pkts */
293 vst1q_u64((uint64_t *)&rx_pkts[pos + 2], mbp2);
296 rte_mbuf_prefetch_part2(rx_pkts[pos]);
297 rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
298 rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
299 rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
302 /* D.1 pkt 3,4 convert format from desc to pktmbuf */
303 pkt_mb4 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[3]), shuf_msk);
304 pkt_mb3 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[2]), shuf_msk);
306 /* D.1 pkt 1,2 convert format from desc to pktmbuf */
307 pkt_mb2 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[1]), shuf_msk);
308 pkt_mb1 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[0]), shuf_msk);
310 /* C.1 4=>2 filter staterr info only */
311 sterr_tmp2 = vzipq_u8(vreinterpretq_u8_u64(descs[1]),
312 vreinterpretq_u8_u64(descs[3]));
313 /* C.1 4=>2 filter staterr info only */
314 sterr_tmp1 = vzipq_u8(vreinterpretq_u8_u64(descs[0]),
315 vreinterpretq_u8_u64(descs[2]));
317 /* C.2 get 4 pkts staterr value */
318 staterr = vzipq_u8(sterr_tmp1.val[1], sterr_tmp2.val[1]).val[0];
320 /* set ol_flags with vlan packet type */
321 desc_to_olflags_v(sterr_tmp1, sterr_tmp2, staterr,
324 /* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
325 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb4), crc_adjust);
326 pkt_mb4 = vreinterpretq_u8_u16(tmp);
327 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb3), crc_adjust);
328 pkt_mb3 = vreinterpretq_u8_u16(tmp);
330 /* D.3 copy final 3,4 data to rx_pkts */
331 vst1q_u8((void *)&rx_pkts[pos + 3]->rx_descriptor_fields1,
333 vst1q_u8((void *)&rx_pkts[pos + 2]->rx_descriptor_fields1,
336 /* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
337 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb2), crc_adjust);
338 pkt_mb2 = vreinterpretq_u8_u16(tmp);
339 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb1), crc_adjust);
340 pkt_mb1 = vreinterpretq_u8_u16(tmp);
342 /* C* extract and record EOP bit */
344 stat = vgetq_lane_u32(vreinterpretq_u32_u8(staterr), 0);
345 /* and with mask to extract bits, flipping 1-0 */
346 *(int *)split_packet = ~stat & IXGBE_VPMD_DESC_EOP_MASK;
348 split_packet += RTE_IXGBE_DESCS_PER_LOOP;
351 /* C.4 expand DD bit to saturate UINT8 */
352 staterr = vshlq_n_u8(staterr, IXGBE_UINT8_BIT - 1);
353 staterr = vreinterpretq_u8_s8
354 (vshrq_n_s8(vreinterpretq_s8_u8(staterr),
355 IXGBE_UINT8_BIT - 1));
356 stat = ~vgetq_lane_u32(vreinterpretq_u32_u8(staterr), 0);
358 rte_prefetch_non_temporal(rxdp + RTE_IXGBE_DESCS_PER_LOOP);
360 /* D.3 copy final 1,2 data to rx_pkts */
361 vst1q_u8((uint8_t *)&rx_pkts[pos + 1]->rx_descriptor_fields1,
363 vst1q_u8((uint8_t *)&rx_pkts[pos]->rx_descriptor_fields1,
366 desc_to_ptype_v(descs, rxq->pkt_type_mask, &rx_pkts[pos]);
368 /* C.5 calc available number of desc */
369 if (unlikely(stat == 0)) {
370 nb_pkts_recd += RTE_IXGBE_DESCS_PER_LOOP;
372 nb_pkts_recd += __builtin_ctz(stat) / IXGBE_UINT8_BIT;
377 /* Update our internal tail pointer */
378 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_pkts_recd);
379 rxq->rx_tail = (uint16_t)(rxq->rx_tail & (rxq->nb_rx_desc - 1));
380 rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
386 * vPMD receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
389 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
390 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
392 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
393 * - don't support ol_flags for rss and csum err
396 ixgbe_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
399 return _recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
403 * vPMD receive routine that reassembles scattered packets
406 * - don't support ol_flags for rss and csum err
407 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
408 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
410 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
413 ixgbe_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
416 struct ixgbe_rx_queue *rxq = rx_queue;
417 uint8_t split_flags[RTE_IXGBE_MAX_RX_BURST] = {0};
419 /* get some new buffers */
420 uint16_t nb_bufs = _recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
425 /* happy day case, full burst + no packets to be joined */
426 const uint64_t *split_fl64 = (uint64_t *)split_flags;
427 if (rxq->pkt_first_seg == NULL &&
428 split_fl64[0] == 0 && split_fl64[1] == 0 &&
429 split_fl64[2] == 0 && split_fl64[3] == 0)
432 /* reassemble any packets that need reassembly*/
434 if (rxq->pkt_first_seg == NULL) {
435 /* find the first split flag, and only reassemble then*/
436 while (i < nb_bufs && !split_flags[i])
440 rxq->pkt_first_seg = rx_pkts[i];
442 return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
447 vtx1(volatile union ixgbe_adv_tx_desc *txdp,
448 struct rte_mbuf *pkt, uint64_t flags)
450 uint64x2_t descriptor = {
451 pkt->buf_iova + pkt->data_off,
452 (uint64_t)pkt->pkt_len << 46 | flags | pkt->data_len};
454 vst1q_u64((uint64_t *)&txdp->read, descriptor);
458 vtx(volatile union ixgbe_adv_tx_desc *txdp,
459 struct rte_mbuf **pkt, uint16_t nb_pkts, uint64_t flags)
463 for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
464 vtx1(txdp, *pkt, flags);
468 ixgbe_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
471 struct ixgbe_tx_queue *txq = (struct ixgbe_tx_queue *)tx_queue;
472 volatile union ixgbe_adv_tx_desc *txdp;
473 struct ixgbe_tx_entry_v *txep;
474 uint16_t n, nb_commit, tx_id;
475 uint64_t flags = DCMD_DTYP_FLAGS;
476 uint64_t rs = IXGBE_ADVTXD_DCMD_RS | DCMD_DTYP_FLAGS;
479 /* cross rx_thresh boundary is not allowed */
480 nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
482 if (txq->nb_tx_free < txq->tx_free_thresh)
483 ixgbe_tx_free_bufs(txq);
485 nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
486 if (unlikely(nb_pkts == 0))
489 tx_id = txq->tx_tail;
490 txdp = &txq->tx_ring[tx_id];
491 txep = &txq->sw_ring_v[tx_id];
493 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
495 n = (uint16_t)(txq->nb_tx_desc - tx_id);
496 if (nb_commit >= n) {
497 tx_backlog_entry(txep, tx_pkts, n);
499 for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
500 vtx1(txdp, *tx_pkts, flags);
502 vtx1(txdp, *tx_pkts++, rs);
504 nb_commit = (uint16_t)(nb_commit - n);
507 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
509 /* avoid reach the end of ring */
510 txdp = &txq->tx_ring[tx_id];
511 txep = &txq->sw_ring_v[tx_id];
514 tx_backlog_entry(txep, tx_pkts, nb_commit);
516 vtx(txdp, tx_pkts, nb_commit, flags);
518 tx_id = (uint16_t)(tx_id + nb_commit);
519 if (tx_id > txq->tx_next_rs) {
520 txq->tx_ring[txq->tx_next_rs].read.cmd_type_len |=
521 rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
522 txq->tx_next_rs = (uint16_t)(txq->tx_next_rs +
526 txq->tx_tail = tx_id;
528 IXGBE_PCI_REG_WRITE(txq->tdt_reg_addr, txq->tx_tail);
533 static void __rte_cold
534 ixgbe_tx_queue_release_mbufs_vec(struct ixgbe_tx_queue *txq)
536 _ixgbe_tx_queue_release_mbufs_vec(txq);
540 ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue *rxq)
542 _ixgbe_rx_queue_release_mbufs_vec(rxq);
545 static void __rte_cold
546 ixgbe_tx_free_swring(struct ixgbe_tx_queue *txq)
548 _ixgbe_tx_free_swring_vec(txq);
551 static void __rte_cold
552 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
554 _ixgbe_reset_tx_queue_vec(txq);
557 static const struct ixgbe_txq_ops vec_txq_ops = {
558 .release_mbufs = ixgbe_tx_queue_release_mbufs_vec,
559 .free_swring = ixgbe_tx_free_swring,
560 .reset = ixgbe_reset_tx_queue,
564 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
566 return ixgbe_rxq_vec_setup_default(rxq);
570 ixgbe_txq_vec_setup(struct ixgbe_tx_queue *txq)
572 return ixgbe_txq_vec_setup_default(txq, &vec_txq_ops);
576 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
578 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
580 /* no csum error report support */
581 if (rxmode->offloads & DEV_RX_OFFLOAD_CHECKSUM)
584 return ixgbe_rx_vec_dev_conf_condition_check_default(dev);