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
147 #define IXGBE_UINT8_BIT (CHAR_BIT * sizeof(uint8_t))
149 static inline uint16_t
150 _recv_raw_pkts_vec(struct ixgbe_rx_queue *rxq, struct rte_mbuf **rx_pkts,
151 uint16_t nb_pkts, uint8_t *split_packet)
153 volatile union ixgbe_adv_rx_desc *rxdp;
154 struct ixgbe_rx_entry *sw_ring;
155 uint16_t nb_pkts_recd;
157 uint8x16_t shuf_msk = {
159 0xFF, 0xFF, /* skip 32 bits pkt_type */
160 12, 13, /* octet 12~13, low 16 bits pkt_len */
161 0xFF, 0xFF, /* skip high 16 bits pkt_len, zero out */
162 12, 13, /* octet 12~13, 16 bits data_len */
163 14, 15, /* octet 14~15, low 16 bits vlan_macip */
164 4, 5, 6, 7 /* octet 4~7, 32bits rss */
166 uint16x8_t crc_adjust = {0, 0, rxq->crc_len, 0,
167 rxq->crc_len, 0, 0, 0};
169 /* nb_pkts shall be less equal than RTE_IXGBE_MAX_RX_BURST */
170 nb_pkts = RTE_MIN(nb_pkts, RTE_IXGBE_MAX_RX_BURST);
172 /* nb_pkts has to be floor-aligned to RTE_IXGBE_DESCS_PER_LOOP */
173 nb_pkts = RTE_ALIGN_FLOOR(nb_pkts, RTE_IXGBE_DESCS_PER_LOOP);
175 /* Just the act of getting into the function from the application is
176 * going to cost about 7 cycles
178 rxdp = rxq->rx_ring + rxq->rx_tail;
180 rte_prefetch_non_temporal(rxdp);
182 /* See if we need to rearm the RX queue - gives the prefetch a bit
185 if (rxq->rxrearm_nb > RTE_IXGBE_RXQ_REARM_THRESH)
186 ixgbe_rxq_rearm(rxq);
188 /* Before we start moving massive data around, check to see if
189 * there is actually a packet available
191 if (!(rxdp->wb.upper.status_error &
192 rte_cpu_to_le_32(IXGBE_RXDADV_STAT_DD)))
195 /* Cache is empty -> need to scan the buffer rings, but first move
196 * the next 'n' mbufs into the cache
198 sw_ring = &rxq->sw_ring[rxq->rx_tail];
200 /* A. load 4 packet in one loop
201 * B. copy 4 mbuf point from swring to rx_pkts
202 * C. calc the number of DD bits among the 4 packets
203 * [C*. extract the end-of-packet bit, if requested]
204 * D. fill info. from desc to mbuf
206 for (pos = 0, nb_pkts_recd = 0; pos < nb_pkts;
207 pos += RTE_IXGBE_DESCS_PER_LOOP,
208 rxdp += RTE_IXGBE_DESCS_PER_LOOP) {
209 uint64x2_t descs[RTE_IXGBE_DESCS_PER_LOOP];
210 uint8x16_t pkt_mb1, pkt_mb2, pkt_mb3, pkt_mb4;
211 uint8x16x2_t sterr_tmp1, sterr_tmp2;
212 uint64x2_t mbp1, mbp2;
217 /* B.1 load 2 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 2 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));
232 /* B.2 copy 2 mbuf point into rx_pkts */
233 vst1q_u64((uint64_t *)&rx_pkts[pos + 2], mbp2);
236 rte_mbuf_prefetch_part2(rx_pkts[pos]);
237 rte_mbuf_prefetch_part2(rx_pkts[pos + 1]);
238 rte_mbuf_prefetch_part2(rx_pkts[pos + 2]);
239 rte_mbuf_prefetch_part2(rx_pkts[pos + 3]);
242 /* D.1 pkt 3,4 convert format from desc to pktmbuf */
243 pkt_mb4 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[3]), shuf_msk);
244 pkt_mb3 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[2]), shuf_msk);
246 /* D.1 pkt 1,2 convert format from desc to pktmbuf */
247 pkt_mb2 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[1]), shuf_msk);
248 pkt_mb1 = vqtbl1q_u8(vreinterpretq_u8_u64(descs[0]), shuf_msk);
250 /* C.1 4=>2 filter staterr info only */
251 sterr_tmp2 = vzipq_u8(vreinterpretq_u8_u64(descs[1]),
252 vreinterpretq_u8_u64(descs[3]));
253 /* C.1 4=>2 filter staterr info only */
254 sterr_tmp1 = vzipq_u8(vreinterpretq_u8_u64(descs[0]),
255 vreinterpretq_u8_u64(descs[2]));
257 /* C.2 get 4 pkts staterr value */
258 staterr = vzipq_u8(sterr_tmp1.val[1], sterr_tmp2.val[1]).val[0];
260 /* set ol_flags with vlan packet type */
261 desc_to_olflags_v(sterr_tmp1, sterr_tmp2, staterr,
264 /* D.2 pkt 3,4 set in_port/nb_seg and remove crc */
265 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb4), crc_adjust);
266 pkt_mb4 = vreinterpretq_u8_u16(tmp);
267 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb3), crc_adjust);
268 pkt_mb3 = vreinterpretq_u8_u16(tmp);
270 /* D.3 copy final 3,4 data to rx_pkts */
271 vst1q_u8((void *)&rx_pkts[pos + 3]->rx_descriptor_fields1,
273 vst1q_u8((void *)&rx_pkts[pos + 2]->rx_descriptor_fields1,
276 /* D.2 pkt 1,2 set in_port/nb_seg and remove crc */
277 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb2), crc_adjust);
278 pkt_mb2 = vreinterpretq_u8_u16(tmp);
279 tmp = vsubq_u16(vreinterpretq_u16_u8(pkt_mb1), crc_adjust);
280 pkt_mb1 = vreinterpretq_u8_u16(tmp);
282 /* C* extract and record EOP bit */
284 stat = vgetq_lane_u32(vreinterpretq_u32_u8(staterr), 0);
285 /* and with mask to extract bits, flipping 1-0 */
286 *(int *)split_packet = ~stat & IXGBE_VPMD_DESC_EOP_MASK;
288 split_packet += RTE_IXGBE_DESCS_PER_LOOP;
291 /* C.4 expand DD bit to saturate UINT8 */
292 staterr = vshlq_n_u8(staterr, IXGBE_UINT8_BIT - 1);
293 staterr = vreinterpretq_u8_s8
294 (vshrq_n_s8(vreinterpretq_s8_u8(staterr),
295 IXGBE_UINT8_BIT - 1));
296 stat = ~vgetq_lane_u32(vreinterpretq_u32_u8(staterr), 0);
298 rte_prefetch_non_temporal(rxdp + RTE_IXGBE_DESCS_PER_LOOP);
300 /* D.3 copy final 1,2 data to rx_pkts */
301 vst1q_u8((uint8_t *)&rx_pkts[pos + 1]->rx_descriptor_fields1,
303 vst1q_u8((uint8_t *)&rx_pkts[pos]->rx_descriptor_fields1,
306 /* C.5 calc available number of desc */
307 if (unlikely(stat == 0)) {
308 nb_pkts_recd += RTE_IXGBE_DESCS_PER_LOOP;
310 nb_pkts_recd += __builtin_ctz(stat) / IXGBE_UINT8_BIT;
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])
378 rxq->pkt_first_seg = rx_pkts[i];
380 return i + reassemble_packets(rxq, &rx_pkts[i], nb_bufs - i,
385 vtx1(volatile union ixgbe_adv_tx_desc *txdp,
386 struct rte_mbuf *pkt, uint64_t flags)
388 uint64x2_t descriptor = {
389 pkt->buf_iova + pkt->data_off,
390 (uint64_t)pkt->pkt_len << 46 | flags | pkt->data_len};
392 vst1q_u64((uint64_t *)&txdp->read, descriptor);
396 vtx(volatile union ixgbe_adv_tx_desc *txdp,
397 struct rte_mbuf **pkt, uint16_t nb_pkts, uint64_t flags)
401 for (i = 0; i < nb_pkts; ++i, ++txdp, ++pkt)
402 vtx1(txdp, *pkt, flags);
406 ixgbe_xmit_fixed_burst_vec(void *tx_queue, struct rte_mbuf **tx_pkts,
409 struct ixgbe_tx_queue *txq = (struct ixgbe_tx_queue *)tx_queue;
410 volatile union ixgbe_adv_tx_desc *txdp;
411 struct ixgbe_tx_entry_v *txep;
412 uint16_t n, nb_commit, tx_id;
413 uint64_t flags = DCMD_DTYP_FLAGS;
414 uint64_t rs = IXGBE_ADVTXD_DCMD_RS | DCMD_DTYP_FLAGS;
417 /* cross rx_thresh boundary is not allowed */
418 nb_pkts = RTE_MIN(nb_pkts, txq->tx_rs_thresh);
420 if (txq->nb_tx_free < txq->tx_free_thresh)
421 ixgbe_tx_free_bufs(txq);
423 nb_commit = nb_pkts = (uint16_t)RTE_MIN(txq->nb_tx_free, nb_pkts);
424 if (unlikely(nb_pkts == 0))
427 tx_id = txq->tx_tail;
428 txdp = &txq->tx_ring[tx_id];
429 txep = &txq->sw_ring_v[tx_id];
431 txq->nb_tx_free = (uint16_t)(txq->nb_tx_free - nb_pkts);
433 n = (uint16_t)(txq->nb_tx_desc - tx_id);
434 if (nb_commit >= n) {
435 tx_backlog_entry(txep, tx_pkts, n);
437 for (i = 0; i < n - 1; ++i, ++tx_pkts, ++txdp)
438 vtx1(txdp, *tx_pkts, flags);
440 vtx1(txdp, *tx_pkts++, rs);
442 nb_commit = (uint16_t)(nb_commit - n);
445 txq->tx_next_rs = (uint16_t)(txq->tx_rs_thresh - 1);
447 /* avoid reach the end of ring */
448 txdp = &txq->tx_ring[tx_id];
449 txep = &txq->sw_ring_v[tx_id];
452 tx_backlog_entry(txep, tx_pkts, nb_commit);
454 vtx(txdp, tx_pkts, nb_commit, flags);
456 tx_id = (uint16_t)(tx_id + nb_commit);
457 if (tx_id > txq->tx_next_rs) {
458 txq->tx_ring[txq->tx_next_rs].read.cmd_type_len |=
459 rte_cpu_to_le_32(IXGBE_ADVTXD_DCMD_RS);
460 txq->tx_next_rs = (uint16_t)(txq->tx_next_rs +
464 txq->tx_tail = tx_id;
466 IXGBE_PCI_REG_WRITE(txq->tdt_reg_addr, txq->tx_tail);
471 static void __attribute__((cold))
472 ixgbe_tx_queue_release_mbufs_vec(struct ixgbe_tx_queue *txq)
474 _ixgbe_tx_queue_release_mbufs_vec(txq);
477 void __attribute__((cold))
478 ixgbe_rx_queue_release_mbufs_vec(struct ixgbe_rx_queue *rxq)
480 _ixgbe_rx_queue_release_mbufs_vec(rxq);
483 static void __attribute__((cold))
484 ixgbe_tx_free_swring(struct ixgbe_tx_queue *txq)
486 _ixgbe_tx_free_swring_vec(txq);
489 static void __attribute__((cold))
490 ixgbe_reset_tx_queue(struct ixgbe_tx_queue *txq)
492 _ixgbe_reset_tx_queue_vec(txq);
495 static const struct ixgbe_txq_ops vec_txq_ops = {
496 .release_mbufs = ixgbe_tx_queue_release_mbufs_vec,
497 .free_swring = ixgbe_tx_free_swring,
498 .reset = ixgbe_reset_tx_queue,
501 int __attribute__((cold))
502 ixgbe_rxq_vec_setup(struct ixgbe_rx_queue *rxq)
504 return ixgbe_rxq_vec_setup_default(rxq);
507 int __attribute__((cold))
508 ixgbe_txq_vec_setup(struct ixgbe_tx_queue *txq)
510 return ixgbe_txq_vec_setup_default(txq, &vec_txq_ops);
513 int __attribute__((cold))
514 ixgbe_rx_vec_dev_conf_condition_check(struct rte_eth_dev *dev)
516 struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
518 /* no csum error report support */
519 if (rxmode->offloads & DEV_RX_OFFLOAD_CHECKSUM)
522 return ixgbe_rx_vec_dev_conf_condition_check_default(dev);