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>
9 #include "ixgbe_ethdev.h"
10 #include "ixgbe_rxtx.h"
11 #include "ixgbe_rxtx_vec_common.h"
15 #pragma GCC diagnostic ignored "-Wcast-qual"
18 ixgbe_rxq_rearm(struct ixgbe_rx_queue *rxq)
22 volatile union ixgbe_adv_rx_desc *rxdp;
23 struct ixgbe_rx_entry *rxep = &rxq->sw_ring[rxq->rxrearm_start];
24 struct rte_mbuf *mb0, *mb1;
25 uint64x2_t dma_addr0, dma_addr1;
26 uint64x2_t zero = vdupq_n_u64(0);
30 rxdp = rxq->rx_ring + rxq->rxrearm_start;
32 /* Pull 'n' more MBUFs into the software ring */
33 if (unlikely(rte_mempool_get_bulk(rxq->mb_pool,
35 RTE_IXGBE_RXQ_REARM_THRESH) < 0)) {
36 if (rxq->rxrearm_nb + RTE_IXGBE_RXQ_REARM_THRESH >=
38 for (i = 0; i < RTE_IXGBE_DESCS_PER_LOOP; i++) {
39 rxep[i].mbuf = &rxq->fake_mbuf;
40 vst1q_u64((uint64_t *)&rxdp[i].read,
44 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed +=
45 RTE_IXGBE_RXQ_REARM_THRESH;
49 p = vld1_u8((uint8_t *)&rxq->mbuf_initializer);
51 /* Initialize the mbufs in vector, process 2 mbufs in one loop */
52 for (i = 0; i < RTE_IXGBE_RXQ_REARM_THRESH; i += 2, rxep += 2) {
57 * Flush mbuf with pkt template.
58 * Data to be rearmed is 6 bytes long.
60 vst1_u8((uint8_t *)&mb0->rearm_data, p);
61 paddr = mb0->buf_iova + RTE_PKTMBUF_HEADROOM;
62 dma_addr0 = vsetq_lane_u64(paddr, zero, 0);
63 /* flush desc with pa dma_addr */
64 vst1q_u64((uint64_t *)&rxdp++->read, dma_addr0);
66 vst1_u8((uint8_t *)&mb1->rearm_data, p);
67 paddr = mb1->buf_iova + RTE_PKTMBUF_HEADROOM;
68 dma_addr1 = vsetq_lane_u64(paddr, zero, 0);
69 vst1q_u64((uint64_t *)&rxdp++->read, dma_addr1);
72 rxq->rxrearm_start += RTE_IXGBE_RXQ_REARM_THRESH;
73 if (rxq->rxrearm_start >= rxq->nb_rx_desc)
74 rxq->rxrearm_start = 0;
76 rxq->rxrearm_nb -= RTE_IXGBE_RXQ_REARM_THRESH;
78 rx_id = (uint16_t)((rxq->rxrearm_start == 0) ?
79 (rxq->nb_rx_desc - 1) : (rxq->rxrearm_start - 1));
81 /* Update the tail pointer on the NIC */
82 IXGBE_PCI_REG_WRITE(rxq->rdt_reg_addr, rx_id);
85 #define VTAG_SHIFT (3)
88 desc_to_olflags_v(uint8x16x2_t sterr_tmp1, uint8x16x2_t sterr_tmp2,
89 uint8x16_t staterr, struct rte_mbuf **rx_pkts)
99 const uint8x16_t pkttype_msk = {
100 PKT_RX_VLAN, PKT_RX_VLAN,
101 PKT_RX_VLAN, PKT_RX_VLAN,
102 0x00, 0x00, 0x00, 0x00,
103 0x00, 0x00, 0x00, 0x00,
104 0x00, 0x00, 0x00, 0x00};
106 const uint8x16_t rsstype_msk = {
107 0x0F, 0x0F, 0x0F, 0x0F,
108 0x00, 0x00, 0x00, 0x00,
109 0x00, 0x00, 0x00, 0x00,
110 0x00, 0x00, 0x00, 0x00};
112 const uint8x16_t rss_flags = {
113 0, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH, PKT_RX_RSS_HASH,
114 0, PKT_RX_RSS_HASH, 0, PKT_RX_RSS_HASH,
115 PKT_RX_RSS_HASH, 0, 0, 0,
116 0, 0, 0, PKT_RX_FDIR};
118 ptype = vzipq_u8(sterr_tmp1.val[0], sterr_tmp2.val[0]).val[0];
119 ptype = vandq_u8(ptype, rsstype_msk);
120 ptype = vqtbl1q_u8(rss_flags, ptype);
122 vtag = vshrq_n_u8(staterr, VTAG_SHIFT);
123 vtag = vandq_u8(vtag, pkttype_msk);
124 vtag = vorrq_u8(ptype, vtag);
126 vol.word = vgetq_lane_u32(vreinterpretq_u32_u8(vtag), 0);
128 rx_pkts[0]->ol_flags = vol.e[0];
129 rx_pkts[1]->ol_flags = vol.e[1];
130 rx_pkts[2]->ol_flags = vol.e[2];
131 rx_pkts[3]->ol_flags = vol.e[3];
135 * vPMD raw receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
138 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
139 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
141 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
142 * - don't support ol_flags for rss and csum err
145 #define IXGBE_VPMD_DESC_DD_MASK 0x01010101
146 #define IXGBE_VPMD_DESC_EOP_MASK 0x02020202
148 static inline uint16_t
149 _recv_raw_pkts_vec(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
150 uint16_t nb_pkts, uint8_t *split_packet)
152 volatile union ixgbe_adv_rx_desc *rxdp;
153 struct ixgbe_rx_entry *sw_ring;
154 uint16_t nb_pkts_recd;
156 uint8x16_t shuf_msk = {
158 0xFF, 0xFF, /* skip 32 bits pkt_type */
159 12, 13, /* octet 12~13, low 16 bits pkt_len */
160 0xFF, 0xFF, /* skip high 16 bits pkt_len, zero out */
161 12, 13, /* octet 12~13, 16 bits data_len */
162 14, 15, /* octet 14~15, low 16 bits vlan_macip */
163 4, 5, 6, 7 /* octet 4~7, 32bits rss */
165 uint16x8_t crc_adjust = {0, 0, rxq->crc_len, 0,
166 rxq->crc_len, 0, 0, 0};
168 /* nb_pkts shall be less equal than RTE_IXGBE_MAX_RX_BURST */
169 nb_pkts = RTE_MIN(nb_pkts, RTE_IXGBE_MAX_RX_BURST);
171 /* nb_pkts has to be floor-aligned to RTE_IXGBE_DESCS_PER_LOOP */
172 nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_IXGBE_DESCS_PER_LOOP);
174 /* Just the act of getting into the function from the application is
175 * going to cost about 7 cycles
177 rxdp = rxq->rx_ring + rxq->rx_tail;
179 rte_prefetch_non_temporal(rxdp);
181 /* See if we need to rearm the RX queue - gives the prefetch a bit
184 if (rxq->rxrearm_nb > RTE_IXGBE_RXQ_REARM_THRESH)
185 ixgbe_rxq_rearm(rxq);
187 /* Before we start moving massive data around, check to see if
188 * there is actually a packet available
190 if (!(rxdp->wb.upper.status_error &
191 rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
194 /* Cache is empty -> need to scan the buffer rings, but first move
195 * the next 'n' mbufs into the cache
197 sw_ring = &rxq->sw_ring[rxq->rx_tail];
199 /* A. load 4 packet in one loop
200 * B. copy 4 mbuf point from swring to rx_pkts
201 * C. calc the number of DD bits among the 4 packets
202 * [C*. extract the end-of-packet bit, if requested]
203 * D. fill info. from desc to mbuf
205 for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
206 pos += RTE_IXGBE_DESCS_PER_LOOP,
207 rxdp += RTE_IXGBE_DESCS_PER_LOOP) {
208 uint64x2_t descs[RTE_IXGBE_DESCS_PER_LOOP];
209 uint8x16_t pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
210 uint8x16x2_t sterr_tmp1, sterr_tmp2;
211 uint64x2_t mbp1, mbp2;
217 /* B.1 load 1 mbuf point */
218 mbp1 = vld1q_u64((uint64_t *)&sw_ring[pos]);
220 /* B.2 copy 2 mbuf point into rx_pkts */
221 vst1q_u64((uint64_t *)&rx_pkts[pos], mbp1);
223 /* B.1 load 1 mbuf point */
224 mbp2 = vld1q_u64((uint64_t *)&sw_ring[pos + 2]);
226 /* A. load 4 pkts descs */
227 descs[0] = vld1q_u64((uint64_t *)(rxdp));
228 descs[1] = vld1q_u64((uint64_t *)(rxdp + 1));
229 descs[2] = vld1q_u64((uint64_t *)(rxdp + 2));
230 descs[3] = vld1q_u64((uint64_t *)(rxdp + 3));
233 /* B.2 copy 2 mbuf point into rx_pkts */
234 vst1q_u64((uint64_t *)&rx_pkts[pos + 2], mbp2);
237 rte_mbuf_prefetch_part2(rx_pkts[pos]);
238 rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
239 rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
240 rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
243 /* D.1 pkt 3,4 convert format from desc to pktmbuf */
244 pkt_mb4 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[3]), shuf_msk);
245 pkt_mb3 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[2]), shuf_msk);
247 /* D.1 pkt 1,2 convert format from desc to pktmbuf */
248 pkt_mb2 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[1]), shuf_msk);
249 pkt_mb1 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[0]), shuf_msk);
251 /* C.1 4=>2 filter staterr info only */
252 sterr_tmp2 = vzipq_u8(vreinterpretq_u8_u64(descs[1]),
253 vreinterpretq_u8_u64(descs[3]));
254 /* C.1 4=>2 filter staterr info only */
255 sterr_tmp1 = vzipq_u8(vreinterpretq_u8_u64(descs[0]),
256 vreinterpretq_u8_u64(descs[2]));
258 /* C.2 get 4 pkts staterr value */
259 staterr = vzipq_u8(sterr_tmp1.val[1], sterr_tmp2.val[1]).val[0];
260 stat = vgetq_lane_u32(vreinterpretq_u32_u8(staterr), 0);
262 /* set ol_flags with vlan packet type */
263 desc_to_olflags_v(sterr_tmp1, sterr_tmp2, staterr,
266 /* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
267 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb4), crc_adjust);
268 pkt_mb4 = vreinterpretq_u8_u16(tmp);
269 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb3), crc_adjust);
270 pkt_mb3 = vreinterpretq_u8_u16(tmp);
272 /* D.3 copy final 3,4 data to rx_pkts */
273 vst1q_u8((void *)&rx_pkts[pos + 3]->rx_descriptor_fields1,
275 vst1q_u8((void *)&rx_pkts[pos + 2]->rx_descriptor_fields1,
278 /* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
279 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb2), crc_adjust);
280 pkt_mb2 = vreinterpretq_u8_u16(tmp);
281 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb1), crc_adjust);
282 pkt_mb1 = vreinterpretq_u8_u16(tmp);
284 /* C* extract and record EOP bit */
286 /* and with mask to extract bits, flipping 1-0 */
287 *(int *)split_packet = ~stat & IXGBE_VPMD_DESC_EOP_MASK;
289 split_packet += RTE_IXGBE_DESCS_PER_LOOP;
292 rte_prefetch_non_temporal(rxdp + RTE_IXGBE_DESCS_PER_LOOP);
294 /* D.3 copy final 1,2 data to rx_pkts */
295 vst1q_u8((uint8_t *)&rx_pkts[pos + 1]->rx_descriptor_fields1,
297 vst1q_u8((uint8_t *)&rx_pkts[pos]->rx_descriptor_fields1,
300 stat &= IXGBE_VPMD_DESC_DD_MASK;
302 /* C.4 calc avaialbe number of desc */
303 if (likely(stat != IXGBE_VPMD_DESC_DD_MASK)) {
304 while (stat & 0x01) {
311 nb_pkts_recd += RTE_IXGBE_DESCS_PER_LOOP;
315 /* Update our internal tail pointer */
316 rxq->rx_tail = (uint16_t)(rxq->rx_tail + nb_pkts_recd);
317 rxq->rx_tail = (uint16_t)(rxq->rx_tail & (rxq->nb_rx_desc - 1));
318 rxq->rxrearm_nb = (uint16_t)(rxq->rxrearm_nb + nb_pkts_recd);
324 * vPMD receive routine, only accept(nb_pkts >= RTE_IXGBE_DESCS_PER_LOOP)
327 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
328 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
330 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
331 * - don't support ol_flags for rss and csum err
334 ixgbe_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
337 return _recv_raw_pkts_vec(rx_queue, rx_pkts, nb_pkts, NULL);
341 * vPMD receive routine that reassembles scattered packets
344 * - don't support ol_flags for rss and csum err
345 * - nb_pkts < RTE_IXGBE_DESCS_PER_LOOP, just return no packet
346 * - nb_pkts > RTE_IXGBE_MAX_RX_BURST, only scan RTE_IXGBE_MAX_RX_BURST
348 * - floor align nb_pkts to a RTE_IXGBE_DESC_PER_LOOP power-of-two
351 ixgbe_recv_scattered_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
354 struct ixgbe_rx_queue *rxq = rx_queue;
355 uint8_t split_flags[RTE_IXGBE_MAX_RX_BURST] = {0};
357 /* get some new buffers */
358 uint16_t nb_bufs = _recv_raw_pkts_vec(rxq, rx_pkts, nb_pkts,
363 /* happy day case, full burst + no packets to be joined */
364 const uint64_t *split_fl64 = (uint64_t *)split_flags;
365 if (rxq->pkt_first_seg == NULL &&
366 split_fl64[0] == 0 && split_fl64[1] == 0 &&
367 split_fl64[2] == 0 && split_fl64[3] == 0)
370 /* reassemble any packets that need reassembly*/
372 if (rxq->pkt_first_seg == NULL) {
373 /* find the first split flag, and only reassemble then*/
374 while (i < nb_bufs && !split_flags[i])
379 return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
384 vtx1(volatile union ixgbe_adv_tx_desc *txdp,
385 struct rte_mbuf *pkt, uint64_t flags)
387 uint64x2_t descriptor = {
388 pkt->buf_iova + pkt->data_off,
389 (uint64_t)pkt->pkt_len << 46 | flags | pkt->data_len};
391 vst1q_u64((uint64_t *)&txdp->read, descriptor);
395 vtx(volatile union ixgbe_adv_tx_desc *txdp,
396 struct rte_mbuf **pkt, uint16_t nb_pkts, uint64_t flags)
400 for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
401 vtx1(txdp, *pkt, flags);
405 ixgbe_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
408 struct ixgbe_tx_queue *txq = (struct ixgbe_tx_queue *)tx_queue;
409 volatile union ixgbe_adv_tx_desc *txdp;
410 struct ixgbe_tx_entry_v *txep;
411 uint16_t n, nb_commit, tx_id;
412 uint64_t flags = DCMD_DTYP_FLAGS;
413 uint64_t rs = IXGBE_ADVTXD_DCMD_RS | DCMD_DTYP_FLAGS;
416 /* cross rx_thresh boundary is not allowed */
417 nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
419 if (txq->nb_tx_free < txq->tx_free_thresh)
420 ixgbe_tx_free_bufs(txq);
422 nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
423 if (unlikely(nb_pkts == 0))
426 tx_id = txq->tx_tail;
427 txdp = &txq->tx_ring[tx_id];
428 txep = &txq->sw_ring_v[tx_id];
430 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
432 n = (uint16_t)(txq->nb_tx_desc - tx_id);
433 if (nb_commit >= n) {
434 tx_backlog_entry(txep, tx_pkts, n);
436 for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
437 vtx1(txdp, *tx_pkts, flags);
439 vtx1(txdp, *tx_pkts++, rs);
441 nb_commit = (uint16_t)(nb_commit - n);
444 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
446 /* avoid reach the end of ring */
447 txdp = &txq->tx_ring[tx_id];
448 txep = &txq->sw_ring_v[tx_id];
451 tx_backlog_entry(txep, tx_pkts, nb_commit);
453 vtx(txdp, tx_pkts, nb_commit, flags);
455 tx_id = (uint16_t)(tx_id + nb_commit);
456 if (tx_id > txq->tx_next_rs) {
457 txq->tx_ring[txq->tx_next_rs].read.cmd_type_len |=
458 rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
459 txq->tx_next_rs = (uint16_t)(txq->tx_next_rs +
463 txq->tx_tail = tx_id;
465 IXGBE_PCI_REG_WRITE(txq->tdt_reg_addr, txq->tx_tail);
470 static void __attribute__((cold))
471 ixgbe_tx_queue_release_mbufs_vec(struct ixgbe_tx_queue *txq)
473 _ixgbe_tx_queue_release_mbufs_vec(txq);
476 void __attribute__((cold))
477 ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue *rxq)
479 _ixgbe_rx_queue_release_mbufs_vec(rxq);
482 static void __attribute__((cold))
483 ixgbe_tx_free_swring(struct ixgbe_tx_queue *txq)
485 _ixgbe_tx_free_swring_vec(txq);
488 static void __attribute__((cold))
489 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
491 _ixgbe_reset_tx_queue_vec(txq);
494 static const struct ixgbe_txq_ops vec_txq_ops = {
495 .release_mbufs = ixgbe_tx_queue_release_mbufs_vec,
496 .free_swring = ixgbe_tx_free_swring,
497 .reset = ixgbe_reset_tx_queue,
500 int __attribute__((cold))
501 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
503 return ixgbe_rxq_vec_setup_default(rxq);
506 int __attribute__((cold))
507 ixgbe_txq_vec_setup(struct ixgbe_tx_queue *txq)
509 return ixgbe_txq_vec_setup_default(txq, &vec_txq_ops);
512 int __attribute__((cold))
513 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
515 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
517 /* no csum error report support */
518 if (rxmode->offloads & DEV_RX_OFFLOAD_CHECKSUM)
521 return ixgbe_rx_vec_dev_conf_condition_check_default(dev);