1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018 Aquantia Corporation
5 #include <rte_malloc.h>
6 #include <rte_ethdev_driver.h>
9 #include "atl_ethdev.h"
10 #include "atl_hw_regs.h"
13 #include "hw_atl/hw_atl_llh.h"
14 #include "hw_atl/hw_atl_b0.h"
15 #include "hw_atl/hw_atl_b0_internal.h"
17 #define ATL_TX_CKSUM_OFFLOAD_MASK ( \
22 #define ATL_TX_OFFLOAD_MASK ( \
30 #define ATL_TX_OFFLOAD_NOTSUP_MASK \
31 (PKT_TX_OFFLOAD_MASK ^ ATL_TX_OFFLOAD_MASK)
34 * Structure associated with each descriptor of the RX ring of a RX queue.
37 struct rte_mbuf *mbuf;
41 * Structure associated with each descriptor of the TX ring of a TX queue.
44 struct rte_mbuf *mbuf;
50 * Structure associated with each RX queue.
53 struct rte_mempool *mb_pool;
54 struct hw_atl_rxd_s *hw_ring;
55 uint64_t hw_ring_phys_addr;
56 struct atl_rx_entry *sw_ring;
60 uint16_t rx_free_thresh;
69 * Structure associated with each TX queue.
72 struct hw_atl_txd_s *hw_ring;
73 uint64_t hw_ring_phys_addr;
74 struct atl_tx_entry *sw_ring;
80 uint16_t tx_free_thresh;
85 atl_reset_rx_queue(struct atl_rx_queue *rxq)
87 struct hw_atl_rxd_s *rxd = NULL;
90 PMD_INIT_FUNC_TRACE();
92 for (i = 0; i < rxq->nb_rx_desc; i++) {
93 rxd = (struct hw_atl_rxd_s *)&rxq->hw_ring[i];
102 atl_rx_queue_setup(struct rte_eth_dev *dev, uint16_t rx_queue_id,
103 uint16_t nb_rx_desc, unsigned int socket_id,
104 const struct rte_eth_rxconf *rx_conf,
105 struct rte_mempool *mb_pool)
107 struct atl_rx_queue *rxq;
108 const struct rte_memzone *mz;
110 PMD_INIT_FUNC_TRACE();
112 /* make sure a valid number of descriptors have been requested */
113 if (nb_rx_desc < AQ_HW_MIN_RX_RING_SIZE ||
114 nb_rx_desc > AQ_HW_MAX_RX_RING_SIZE) {
115 PMD_INIT_LOG(ERR, "Number of Rx descriptors must be "
116 "less than or equal to %d, "
117 "greater than or equal to %d", AQ_HW_MAX_RX_RING_SIZE,
118 AQ_HW_MIN_RX_RING_SIZE);
123 * if this queue existed already, free the associated memory. The
124 * queue cannot be reused in case we need to allocate memory on
125 * different socket than was previously used.
127 if (dev->data->rx_queues[rx_queue_id] != NULL) {
128 atl_rx_queue_release(dev->data->rx_queues[rx_queue_id]);
129 dev->data->rx_queues[rx_queue_id] = NULL;
132 /* allocate memory for the queue structure */
133 rxq = rte_zmalloc_socket("atlantic Rx queue", sizeof(*rxq),
134 RTE_CACHE_LINE_SIZE, socket_id);
136 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
141 rxq->mb_pool = mb_pool;
142 rxq->nb_rx_desc = nb_rx_desc;
143 rxq->port_id = dev->data->port_id;
144 rxq->queue_id = rx_queue_id;
145 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
147 rxq->l3_csum_enabled = dev->data->dev_conf.rxmode.offloads &
148 DEV_RX_OFFLOAD_IPV4_CKSUM;
149 rxq->l4_csum_enabled = dev->data->dev_conf.rxmode.offloads &
150 (DEV_RX_OFFLOAD_UDP_CKSUM | DEV_RX_OFFLOAD_TCP_CKSUM);
151 if (dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_KEEP_CRC)
152 PMD_DRV_LOG(ERR, "PMD does not support KEEP_CRC offload");
154 /* allocate memory for the software ring */
155 rxq->sw_ring = rte_zmalloc_socket("atlantic sw rx ring",
156 nb_rx_desc * sizeof(struct atl_rx_entry),
157 RTE_CACHE_LINE_SIZE, socket_id);
158 if (rxq->sw_ring == NULL) {
160 "Port %d: Cannot allocate software ring for queue %d",
161 rxq->port_id, rxq->queue_id);
167 * allocate memory for the hardware descriptor ring. A memzone large
168 * enough to hold the maximum ring size is requested to allow for
169 * resizing in later calls to the queue setup function.
171 mz = rte_eth_dma_zone_reserve(dev, "rx hw_ring", rx_queue_id,
173 sizeof(struct hw_atl_rxd_s),
177 "Port %d: Cannot allocate hardware ring for queue %d",
178 rxq->port_id, rxq->queue_id);
179 rte_free(rxq->sw_ring);
183 rxq->hw_ring = mz->addr;
184 rxq->hw_ring_phys_addr = mz->iova;
186 atl_reset_rx_queue(rxq);
188 dev->data->rx_queues[rx_queue_id] = rxq;
193 atl_reset_tx_queue(struct atl_tx_queue *txq)
195 struct atl_tx_entry *tx_entry;
196 union hw_atl_txc_s *txc;
199 PMD_INIT_FUNC_TRACE();
202 PMD_DRV_LOG(ERR, "Pointer to txq is NULL");
206 tx_entry = txq->sw_ring;
208 for (i = 0; i < txq->nb_tx_desc; i++) {
209 txc = (union hw_atl_txc_s *)&txq->hw_ring[i];
214 for (i = 0; i < txq->nb_tx_desc; i++) {
215 txq->hw_ring[i].dd = 1;
216 tx_entry[i].mbuf = NULL;
221 txq->tx_free = txq->nb_tx_desc - 1;
225 atl_tx_queue_setup(struct rte_eth_dev *dev, uint16_t tx_queue_id,
226 uint16_t nb_tx_desc, unsigned int socket_id,
227 const struct rte_eth_txconf *tx_conf)
229 struct atl_tx_queue *txq;
230 const struct rte_memzone *mz;
232 PMD_INIT_FUNC_TRACE();
234 /* make sure a valid number of descriptors have been requested */
235 if (nb_tx_desc < AQ_HW_MIN_TX_RING_SIZE ||
236 nb_tx_desc > AQ_HW_MAX_TX_RING_SIZE) {
237 PMD_INIT_LOG(ERR, "Number of Tx descriptors must be "
238 "less than or equal to %d, "
239 "greater than or equal to %d", AQ_HW_MAX_TX_RING_SIZE,
240 AQ_HW_MIN_TX_RING_SIZE);
245 * if this queue existed already, free the associated memory. The
246 * queue cannot be reused in case we need to allocate memory on
247 * different socket than was previously used.
249 if (dev->data->tx_queues[tx_queue_id] != NULL) {
250 atl_tx_queue_release(dev->data->tx_queues[tx_queue_id]);
251 dev->data->tx_queues[tx_queue_id] = NULL;
254 /* allocate memory for the queue structure */
255 txq = rte_zmalloc_socket("atlantic Tx queue", sizeof(*txq),
256 RTE_CACHE_LINE_SIZE, socket_id);
258 PMD_INIT_LOG(ERR, "Cannot allocate queue structure");
263 txq->nb_tx_desc = nb_tx_desc;
264 txq->port_id = dev->data->port_id;
265 txq->queue_id = tx_queue_id;
266 txq->tx_free_thresh = tx_conf->tx_free_thresh;
269 /* allocate memory for the software ring */
270 txq->sw_ring = rte_zmalloc_socket("atlantic sw tx ring",
271 nb_tx_desc * sizeof(struct atl_tx_entry),
272 RTE_CACHE_LINE_SIZE, socket_id);
273 if (txq->sw_ring == NULL) {
275 "Port %d: Cannot allocate software ring for queue %d",
276 txq->port_id, txq->queue_id);
282 * allocate memory for the hardware descriptor ring. A memzone large
283 * enough to hold the maximum ring size is requested to allow for
284 * resizing in later calls to the queue setup function.
286 mz = rte_eth_dma_zone_reserve(dev, "tx hw_ring", tx_queue_id,
287 HW_ATL_B0_MAX_TXD * sizeof(struct hw_atl_txd_s),
291 "Port %d: Cannot allocate hardware ring for queue %d",
292 txq->port_id, txq->queue_id);
293 rte_free(txq->sw_ring);
297 txq->hw_ring = mz->addr;
298 txq->hw_ring_phys_addr = mz->iova;
300 atl_reset_tx_queue(txq);
302 dev->data->tx_queues[tx_queue_id] = txq;
307 atl_tx_init(struct rte_eth_dev *eth_dev)
309 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
310 struct atl_tx_queue *txq;
311 uint64_t base_addr = 0;
315 PMD_INIT_FUNC_TRACE();
317 for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
318 txq = eth_dev->data->tx_queues[i];
319 base_addr = txq->hw_ring_phys_addr;
321 err = hw_atl_b0_hw_ring_tx_init(hw, base_addr,
328 "Port %d: Cannot init TX queue %d",
329 txq->port_id, txq->queue_id);
338 atl_rx_init(struct rte_eth_dev *eth_dev)
340 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
341 struct aq_rss_parameters *rss_params = &hw->aq_nic_cfg->aq_rss;
342 struct atl_rx_queue *rxq;
343 uint64_t base_addr = 0;
347 PMD_INIT_FUNC_TRACE();
349 for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
350 rxq = eth_dev->data->rx_queues[i];
351 base_addr = rxq->hw_ring_phys_addr;
353 /* Take requested pool mbuf size and adapt
354 * descriptor buffer to best fit
356 int buff_size = rte_pktmbuf_data_room_size(rxq->mb_pool) -
357 RTE_PKTMBUF_HEADROOM;
359 buff_size = RTE_ALIGN_FLOOR(buff_size, 1024);
360 if (buff_size > HW_ATL_B0_RXD_BUF_SIZE_MAX) {
361 PMD_INIT_LOG(WARNING,
362 "Port %d queue %d: mem pool buff size is too big\n",
363 rxq->port_id, rxq->queue_id);
364 buff_size = HW_ATL_B0_RXD_BUF_SIZE_MAX;
366 if (buff_size < 1024) {
368 "Port %d queue %d: mem pool buff size is too small\n",
369 rxq->port_id, rxq->queue_id);
372 rxq->buff_size = buff_size;
374 err = hw_atl_b0_hw_ring_rx_init(hw, base_addr, rxq->queue_id,
375 rxq->nb_rx_desc, buff_size, 0,
379 PMD_INIT_LOG(ERR, "Port %d: Cannot init RX queue %d",
380 rxq->port_id, rxq->queue_id);
385 for (i = rss_params->indirection_table_size; i--;)
386 rss_params->indirection_table[i] = i &
387 (eth_dev->data->nb_rx_queues - 1);
388 hw_atl_b0_hw_rss_set(hw, rss_params);
393 atl_alloc_rx_queue_mbufs(struct atl_rx_queue *rxq)
395 struct atl_rx_entry *rx_entry = rxq->sw_ring;
396 struct hw_atl_rxd_s *rxd;
397 uint64_t dma_addr = 0;
400 PMD_INIT_FUNC_TRACE();
403 for (i = 0; i < rxq->nb_rx_desc; i++) {
404 struct rte_mbuf *mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
408 "Port %d: mbuf alloc failed for rx queue %d",
409 rxq->port_id, rxq->queue_id);
413 mbuf->data_off = RTE_PKTMBUF_HEADROOM;
414 mbuf->port = rxq->port_id;
416 dma_addr = rte_cpu_to_le_64(rte_mbuf_data_iova_default(mbuf));
417 rxd = (struct hw_atl_rxd_s *)&rxq->hw_ring[i];
418 rxd->buf_addr = dma_addr;
420 rx_entry[i].mbuf = mbuf;
427 atl_rx_queue_release_mbufs(struct atl_rx_queue *rxq)
431 PMD_INIT_FUNC_TRACE();
433 if (rxq->sw_ring != NULL) {
434 for (i = 0; i < rxq->nb_rx_desc; i++) {
435 if (rxq->sw_ring[i].mbuf != NULL) {
436 rte_pktmbuf_free_seg(rxq->sw_ring[i].mbuf);
437 rxq->sw_ring[i].mbuf = NULL;
444 atl_rx_queue_start(struct rte_eth_dev *dev, uint16_t rx_queue_id)
446 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
447 struct atl_rx_queue *rxq = NULL;
449 PMD_INIT_FUNC_TRACE();
451 if (rx_queue_id < dev->data->nb_rx_queues) {
452 rxq = dev->data->rx_queues[rx_queue_id];
454 if (atl_alloc_rx_queue_mbufs(rxq) != 0) {
456 "Port %d: Allocate mbufs for queue %d failed",
457 rxq->port_id, rxq->queue_id);
461 hw_atl_b0_hw_ring_rx_start(hw, rx_queue_id);
464 hw_atl_reg_rx_dma_desc_tail_ptr_set(hw, rxq->nb_rx_desc - 1,
466 dev->data->rx_queue_state[rx_queue_id] =
467 RTE_ETH_QUEUE_STATE_STARTED;
476 atl_rx_queue_stop(struct rte_eth_dev *dev, uint16_t rx_queue_id)
478 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
479 struct atl_rx_queue *rxq = NULL;
481 PMD_INIT_FUNC_TRACE();
483 if (rx_queue_id < dev->data->nb_rx_queues) {
484 rxq = dev->data->rx_queues[rx_queue_id];
486 hw_atl_b0_hw_ring_rx_stop(hw, rx_queue_id);
488 atl_rx_queue_release_mbufs(rxq);
489 atl_reset_rx_queue(rxq);
491 dev->data->rx_queue_state[rx_queue_id] =
492 RTE_ETH_QUEUE_STATE_STOPPED;
501 atl_rx_queue_release(void *rx_queue)
503 PMD_INIT_FUNC_TRACE();
505 if (rx_queue != NULL) {
506 struct atl_rx_queue *rxq = (struct atl_rx_queue *)rx_queue;
508 atl_rx_queue_release_mbufs(rxq);
509 rte_free(rxq->sw_ring);
515 atl_tx_queue_release_mbufs(struct atl_tx_queue *txq)
519 PMD_INIT_FUNC_TRACE();
521 if (txq->sw_ring != NULL) {
522 for (i = 0; i < txq->nb_tx_desc; i++) {
523 if (txq->sw_ring[i].mbuf != NULL) {
524 rte_pktmbuf_free_seg(txq->sw_ring[i].mbuf);
525 txq->sw_ring[i].mbuf = NULL;
532 atl_tx_queue_start(struct rte_eth_dev *dev, uint16_t tx_queue_id)
534 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
536 PMD_INIT_FUNC_TRACE();
538 if (tx_queue_id < dev->data->nb_tx_queues) {
539 hw_atl_b0_hw_ring_tx_start(hw, tx_queue_id);
542 hw_atl_b0_hw_tx_ring_tail_update(hw, 0, tx_queue_id);
543 dev->data->tx_queue_state[tx_queue_id] =
544 RTE_ETH_QUEUE_STATE_STARTED;
553 atl_tx_queue_stop(struct rte_eth_dev *dev, uint16_t tx_queue_id)
555 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
556 struct atl_tx_queue *txq;
558 PMD_INIT_FUNC_TRACE();
560 txq = dev->data->tx_queues[tx_queue_id];
562 hw_atl_b0_hw_ring_tx_stop(hw, tx_queue_id);
564 atl_tx_queue_release_mbufs(txq);
565 atl_reset_tx_queue(txq);
566 dev->data->tx_queue_state[tx_queue_id] = RTE_ETH_QUEUE_STATE_STOPPED;
572 atl_tx_queue_release(void *tx_queue)
574 PMD_INIT_FUNC_TRACE();
576 if (tx_queue != NULL) {
577 struct atl_tx_queue *txq = (struct atl_tx_queue *)tx_queue;
579 atl_tx_queue_release_mbufs(txq);
580 rte_free(txq->sw_ring);
586 atl_free_queues(struct rte_eth_dev *dev)
590 PMD_INIT_FUNC_TRACE();
592 for (i = 0; i < dev->data->nb_rx_queues; i++) {
593 atl_rx_queue_release(dev->data->rx_queues[i]);
594 dev->data->rx_queues[i] = 0;
596 dev->data->nb_rx_queues = 0;
598 for (i = 0; i < dev->data->nb_tx_queues; i++) {
599 atl_tx_queue_release(dev->data->tx_queues[i]);
600 dev->data->tx_queues[i] = 0;
602 dev->data->nb_tx_queues = 0;
606 atl_start_queues(struct rte_eth_dev *dev)
610 PMD_INIT_FUNC_TRACE();
612 for (i = 0; i < dev->data->nb_tx_queues; i++) {
613 if (atl_tx_queue_start(dev, i) != 0) {
615 "Port %d: Start Tx queue %d failed",
616 dev->data->port_id, i);
621 for (i = 0; i < dev->data->nb_rx_queues; i++) {
622 if (atl_rx_queue_start(dev, i) != 0) {
624 "Port %d: Start Rx queue %d failed",
625 dev->data->port_id, i);
634 atl_stop_queues(struct rte_eth_dev *dev)
638 PMD_INIT_FUNC_TRACE();
640 for (i = 0; i < dev->data->nb_tx_queues; i++) {
641 if (atl_tx_queue_stop(dev, i) != 0) {
643 "Port %d: Stop Tx queue %d failed",
644 dev->data->port_id, i);
649 for (i = 0; i < dev->data->nb_rx_queues; i++) {
650 if (atl_rx_queue_stop(dev, i) != 0) {
652 "Port %d: Stop Rx queue %d failed",
653 dev->data->port_id, i);
662 atl_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
663 struct rte_eth_rxq_info *qinfo)
665 struct atl_rx_queue *rxq;
667 PMD_INIT_FUNC_TRACE();
669 rxq = dev->data->rx_queues[queue_id];
671 qinfo->mp = rxq->mb_pool;
672 qinfo->scattered_rx = dev->data->scattered_rx;
673 qinfo->nb_desc = rxq->nb_rx_desc;
677 atl_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
678 struct rte_eth_txq_info *qinfo)
680 struct atl_tx_queue *txq;
682 PMD_INIT_FUNC_TRACE();
684 txq = dev->data->tx_queues[queue_id];
686 qinfo->nb_desc = txq->nb_tx_desc;
689 /* Return Rx queue avail count */
692 atl_rx_queue_count(struct rte_eth_dev *dev, uint16_t rx_queue_id)
694 struct atl_rx_queue *rxq;
696 PMD_INIT_FUNC_TRACE();
698 if (rx_queue_id >= dev->data->nb_rx_queues) {
699 PMD_DRV_LOG(ERR, "Invalid RX queue id=%d", rx_queue_id);
703 rxq = dev->data->rx_queues[rx_queue_id];
708 return rxq->nb_rx_desc - rxq->nb_rx_hold;
712 atl_dev_rx_descriptor_status(void *rx_queue, uint16_t offset)
714 struct atl_rx_queue *rxq = rx_queue;
715 struct hw_atl_rxd_wb_s *rxd;
718 PMD_INIT_FUNC_TRACE();
720 if (unlikely(offset >= rxq->nb_rx_desc))
723 if (offset >= rxq->nb_rx_desc - rxq->nb_rx_hold)
724 return RTE_ETH_RX_DESC_UNAVAIL;
726 idx = rxq->rx_tail + offset;
728 if (idx >= rxq->nb_rx_desc)
729 idx -= rxq->nb_rx_desc;
731 rxd = (struct hw_atl_rxd_wb_s *)&rxq->hw_ring[idx];
734 return RTE_ETH_RX_DESC_DONE;
736 return RTE_ETH_RX_DESC_AVAIL;
740 atl_dev_tx_descriptor_status(void *tx_queue, uint16_t offset)
742 struct atl_tx_queue *txq = tx_queue;
743 struct hw_atl_txd_s *txd;
746 PMD_INIT_FUNC_TRACE();
748 if (unlikely(offset >= txq->nb_tx_desc))
751 idx = txq->tx_tail + offset;
753 if (idx >= txq->nb_tx_desc)
754 idx -= txq->nb_tx_desc;
756 txd = &txq->hw_ring[idx];
759 return RTE_ETH_TX_DESC_DONE;
761 return RTE_ETH_TX_DESC_FULL;
765 atl_rx_enable_intr(struct rte_eth_dev *dev, uint16_t queue_id, bool enable)
767 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
768 struct atl_rx_queue *rxq;
770 PMD_INIT_FUNC_TRACE();
772 if (queue_id >= dev->data->nb_rx_queues) {
773 PMD_DRV_LOG(ERR, "Invalid RX queue id=%d", queue_id);
777 rxq = dev->data->rx_queues[queue_id];
782 /* Mapping interrupt vector */
783 hw_atl_itr_irq_map_en_rx_set(hw, enable, queue_id);
789 atl_dev_rx_queue_intr_enable(struct rte_eth_dev *eth_dev, uint16_t queue_id)
791 return atl_rx_enable_intr(eth_dev, queue_id, true);
795 atl_dev_rx_queue_intr_disable(struct rte_eth_dev *eth_dev, uint16_t queue_id)
797 return atl_rx_enable_intr(eth_dev, queue_id, false);
801 atl_prep_pkts(__rte_unused void *tx_queue, struct rte_mbuf **tx_pkts,
808 PMD_INIT_FUNC_TRACE();
810 for (i = 0; i < nb_pkts; i++) {
812 ol_flags = m->ol_flags;
814 if (m->nb_segs > AQ_HW_MAX_SEGS_SIZE) {
819 if (ol_flags & ATL_TX_OFFLOAD_NOTSUP_MASK) {
824 #ifdef RTE_LIBRTE_ETHDEV_DEBUG
825 ret = rte_validate_tx_offload(m);
831 ret = rte_net_intel_cksum_prepare(m);
842 atl_desc_to_offload_flags(struct atl_rx_queue *rxq,
843 struct hw_atl_rxd_wb_s *rxd_wb)
845 uint64_t mbuf_flags = 0;
847 PMD_INIT_FUNC_TRACE();
850 if (rxq->l3_csum_enabled && ((rxd_wb->pkt_type & 0x3) == 0)) {
851 /* IPv4 csum error ? */
852 if (rxd_wb->rx_stat & BIT(1))
853 mbuf_flags |= PKT_RX_IP_CKSUM_BAD;
855 mbuf_flags |= PKT_RX_IP_CKSUM_GOOD;
857 mbuf_flags |= PKT_RX_IP_CKSUM_UNKNOWN;
860 /* CSUM calculated ? */
861 if (rxq->l4_csum_enabled && (rxd_wb->rx_stat & BIT(3))) {
862 if (rxd_wb->rx_stat & BIT(2))
863 mbuf_flags |= PKT_RX_L4_CKSUM_BAD;
865 mbuf_flags |= PKT_RX_L4_CKSUM_GOOD;
867 mbuf_flags |= PKT_RX_L4_CKSUM_UNKNOWN;
874 atl_desc_to_pkt_type(struct hw_atl_rxd_wb_s *rxd_wb)
876 uint32_t type = RTE_PTYPE_UNKNOWN;
877 uint16_t l2_l3_type = rxd_wb->pkt_type & 0x3;
878 uint16_t l4_type = (rxd_wb->pkt_type & 0x1C) >> 2;
880 switch (l2_l3_type) {
882 type = RTE_PTYPE_L3_IPV4;
885 type = RTE_PTYPE_L3_IPV6;
888 type = RTE_PTYPE_L2_ETHER;
891 type = RTE_PTYPE_L2_ETHER_ARP;
897 type |= RTE_PTYPE_L4_TCP;
900 type |= RTE_PTYPE_L4_UDP;
903 type |= RTE_PTYPE_L4_SCTP;
906 type |= RTE_PTYPE_L4_ICMP;
910 if (rxd_wb->pkt_type & BIT(5))
911 type |= RTE_PTYPE_L2_ETHER_VLAN;
917 atl_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
919 struct atl_rx_queue *rxq = (struct atl_rx_queue *)rx_queue;
920 struct rte_eth_dev *dev = &rte_eth_devices[rxq->port_id];
921 struct atl_adapter *adapter =
922 ATL_DEV_TO_ADAPTER(&rte_eth_devices[rxq->port_id]);
923 struct aq_hw_s *hw = ATL_DEV_PRIVATE_TO_HW(adapter);
924 struct aq_hw_cfg_s *cfg =
925 ATL_DEV_PRIVATE_TO_CFG(dev->data->dev_private);
926 struct atl_rx_entry *sw_ring = rxq->sw_ring;
928 struct rte_mbuf *new_mbuf;
929 struct rte_mbuf *rx_mbuf, *rx_mbuf_prev, *rx_mbuf_first;
930 struct atl_rx_entry *rx_entry;
932 uint16_t nb_hold = 0;
933 struct hw_atl_rxd_wb_s rxd_wb;
934 struct hw_atl_rxd_s *rxd = NULL;
935 uint16_t tail = rxq->rx_tail;
937 uint16_t pkt_len = 0;
939 while (nb_rx < nb_pkts) {
940 uint16_t eop_tail = tail;
942 rxd = (struct hw_atl_rxd_s *)&rxq->hw_ring[tail];
943 rxd_wb = *(struct hw_atl_rxd_wb_s *)rxd;
945 if (!rxd_wb.dd) { /* RxD is not done */
949 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u tail=%u "
950 "eop=0x%x pkt_len=%u hash=0x%x hash_type=0x%x",
951 (unsigned int)rxq->port_id,
952 (unsigned int)rxq->queue_id,
953 (unsigned int)tail, (unsigned int)rxd_wb.eop,
954 (unsigned int)rte_le_to_cpu_16(rxd_wb.pkt_len),
955 rxd_wb.rss_hash, rxd_wb.rss_type);
957 /* RxD is not done */
960 struct hw_atl_rxd_wb_s *eop_rxwbd;
962 eop_tail = (eop_tail + 1) % rxq->nb_rx_desc;
963 eop_rxwbd = (struct hw_atl_rxd_wb_s *)
964 &rxq->hw_ring[eop_tail];
965 if (!eop_rxwbd->dd) {
966 /* no EOP received yet */
970 if (eop_rxwbd->dd && eop_rxwbd->eop)
974 if (eop_tail == tail)
978 rx_mbuf_first = NULL;
980 /* Run through packet segments */
982 new_mbuf = rte_mbuf_raw_alloc(rxq->mb_pool);
983 if (new_mbuf == NULL) {
985 "RX mbuf alloc failed port_id=%u "
986 "queue_id=%u", (unsigned int)rxq->port_id,
987 (unsigned int)rxq->queue_id);
988 dev->data->rx_mbuf_alloc_failed++;
989 adapter->sw_stats.rx_nombuf++;
994 rx_entry = &sw_ring[tail];
996 rx_mbuf = rx_entry->mbuf;
997 rx_entry->mbuf = new_mbuf;
998 dma_addr = rte_cpu_to_le_64(
999 rte_mbuf_data_iova_default(new_mbuf));
1001 /* setup RX descriptor */
1003 rxd->buf_addr = dma_addr;
1006 * Initialize the returned mbuf.
1007 * 1) setup generic mbuf fields:
1008 * - number of segments,
1011 * - RX port identifier.
1012 * 2) integrate hardware offload data, if any:
1013 * < - RSS flag & hash,
1014 * - IP checksum flag,
1015 * - VLAN TCI, if any,
1018 pkt_len = (uint16_t)rte_le_to_cpu_16(rxd_wb.pkt_len);
1019 rx_mbuf->data_off = RTE_PKTMBUF_HEADROOM;
1020 rte_prefetch1((char *)rx_mbuf->buf_addr +
1022 rx_mbuf->nb_segs = 0;
1023 rx_mbuf->next = NULL;
1024 rx_mbuf->pkt_len = pkt_len;
1025 rx_mbuf->data_len = pkt_len;
1027 u16 remainder_len = pkt_len % rxq->buff_size;
1029 remainder_len = rxq->buff_size;
1030 rx_mbuf->data_len = remainder_len;
1032 rx_mbuf->data_len = pkt_len > rxq->buff_size ?
1033 rxq->buff_size : pkt_len;
1035 rx_mbuf->port = rxq->port_id;
1037 rx_mbuf->hash.rss = rxd_wb.rss_hash;
1039 rx_mbuf->vlan_tci = rxd_wb.vlan;
1042 atl_desc_to_offload_flags(rxq, &rxd_wb);
1044 rx_mbuf->packet_type = atl_desc_to_pkt_type(&rxd_wb);
1046 if (rx_mbuf->packet_type & RTE_PTYPE_L2_ETHER_VLAN) {
1047 rx_mbuf->ol_flags |= PKT_RX_VLAN;
1048 rx_mbuf->vlan_tci = rxd_wb.vlan;
1050 if (cfg->vlan_strip)
1051 rx_mbuf->ol_flags |=
1052 PKT_RX_VLAN_STRIPPED;
1056 rx_mbuf_first = rx_mbuf;
1057 rx_mbuf_first->nb_segs++;
1060 rx_mbuf_prev->next = rx_mbuf;
1061 rx_mbuf_prev = rx_mbuf;
1063 tail = (tail + 1) % rxq->nb_rx_desc;
1064 /* Prefetch next mbufs */
1065 rte_prefetch0(sw_ring[tail].mbuf);
1066 if ((tail & 0x3) == 0) {
1067 rte_prefetch0(&sw_ring[tail]);
1068 rte_prefetch0(&sw_ring[tail]);
1071 /* filled mbuf_first */
1074 rxd = (struct hw_atl_rxd_s *)&rxq->hw_ring[tail];
1075 rxd_wb = *(struct hw_atl_rxd_wb_s *)rxd;
1079 * Store the mbuf address into the next entry of the array
1080 * of returned packets.
1082 rx_pkts[nb_rx++] = rx_mbuf_first;
1083 adapter->sw_stats.q_ipackets[rxq->queue_id]++;
1084 adapter->sw_stats.q_ibytes[rxq->queue_id] +=
1085 rx_mbuf_first->pkt_len;
1087 PMD_RX_LOG(DEBUG, "add mbuf segs=%d pkt_len=%d",
1088 rx_mbuf_first->nb_segs,
1089 rx_mbuf_first->pkt_len);
1094 rxq->rx_tail = tail;
1097 * If the number of free RX descriptors is greater than the RX free
1098 * threshold of the queue, advance the Receive Descriptor Tail (RDT)
1100 * Update the RDT with the value of the last processed RX descriptor
1101 * minus 1, to guarantee that the RDT register is never equal to the
1102 * RDH register, which creates a "full" ring situtation from the
1103 * hardware point of view...
1105 nb_hold = (uint16_t)(nb_hold + rxq->nb_rx_hold);
1106 if (nb_hold > rxq->rx_free_thresh) {
1107 PMD_RX_LOG(DEBUG, "port_id=%u queue_id=%u rx_tail=%u "
1108 "nb_hold=%u nb_rx=%u",
1109 (unsigned int)rxq->port_id, (unsigned int)rxq->queue_id,
1110 (unsigned int)tail, (unsigned int)nb_hold,
1111 (unsigned int)nb_rx);
1112 tail = (uint16_t)((tail == 0) ?
1113 (rxq->nb_rx_desc - 1) : (tail - 1));
1115 hw_atl_reg_rx_dma_desc_tail_ptr_set(hw, tail, rxq->queue_id);
1120 rxq->nb_rx_hold = nb_hold;
1126 atl_xmit_cleanup(struct atl_tx_queue *txq)
1128 struct atl_tx_entry *sw_ring;
1129 struct hw_atl_txd_s *txd;
1133 sw_ring = txq->sw_ring;
1134 int head = txq->tx_head;
1138 for (i = 0, cnt = head; ; i++) {
1139 txd = &txq->hw_ring[cnt];
1144 cnt = (cnt + 1) % txq->nb_tx_desc;
1145 if (cnt == txq->tx_tail)
1153 txd = &txq->hw_ring[head];
1155 struct atl_tx_entry *rx_entry = &sw_ring[head];
1157 if (rx_entry->mbuf) {
1158 rte_pktmbuf_free_seg(rx_entry->mbuf);
1159 rx_entry->mbuf = NULL;
1168 head = (head + 1) % txq->nb_tx_desc;
1172 txq->tx_head = head;
1177 atl_tso_setup(struct rte_mbuf *tx_pkt, union hw_atl_txc_s *txc)
1179 uint32_t tx_cmd = 0;
1180 uint64_t ol_flags = tx_pkt->ol_flags;
1182 if (ol_flags & PKT_TX_TCP_SEG) {
1183 tx_cmd |= tx_desc_cmd_lso | tx_desc_cmd_l4cs;
1187 if (ol_flags & PKT_TX_IPV6)
1190 txc->l2_len = tx_pkt->l2_len;
1191 txc->l3_len = tx_pkt->l3_len;
1192 txc->l4_len = tx_pkt->l4_len;
1194 txc->mss_len = tx_pkt->tso_segsz;
1197 if (ol_flags & PKT_TX_VLAN) {
1198 tx_cmd |= tx_desc_cmd_vlan;
1199 txc->vlan_tag = tx_pkt->vlan_tci;
1203 txc->type = tx_desc_type_ctx;
1211 atl_setup_csum_offload(struct rte_mbuf *mbuf, struct hw_atl_txd_s *txd,
1214 txd->cmd |= tx_desc_cmd_fcs;
1215 txd->cmd |= (mbuf->ol_flags & PKT_TX_IP_CKSUM) ? tx_desc_cmd_ipv4 : 0;
1216 /* L4 csum requested */
1217 txd->cmd |= (mbuf->ol_flags & PKT_TX_L4_MASK) ? tx_desc_cmd_l4cs : 0;
1222 atl_xmit_pkt(struct aq_hw_s *hw, struct atl_tx_queue *txq,
1223 struct rte_mbuf *tx_pkt)
1225 struct atl_adapter *adapter =
1226 ATL_DEV_TO_ADAPTER(&rte_eth_devices[txq->port_id]);
1227 uint32_t pay_len = 0;
1229 struct atl_tx_entry *tx_entry;
1230 uint64_t buf_dma_addr;
1231 struct rte_mbuf *m_seg;
1232 union hw_atl_txc_s *txc = NULL;
1233 struct hw_atl_txd_s *txd = NULL;
1237 tail = txq->tx_tail;
1239 txc = (union hw_atl_txc_s *)&txq->hw_ring[tail];
1244 tx_cmd = atl_tso_setup(tx_pkt, txc);
1247 /* We've consumed the first desc, adjust counters */
1248 tail = (tail + 1) % txq->nb_tx_desc;
1249 txq->tx_tail = tail;
1252 txd = &txq->hw_ring[tail];
1255 txd = (struct hw_atl_txd_s *)txc;
1258 txd->ct_en = !!tx_cmd;
1260 txd->type = tx_desc_type_desc;
1262 atl_setup_csum_offload(tx_pkt, txd, tx_cmd);
1267 pay_len = tx_pkt->pkt_len;
1269 txd->pay_len = pay_len;
1271 for (m_seg = tx_pkt; m_seg; m_seg = m_seg->next) {
1272 if (desc_count > 0) {
1273 txd = &txq->hw_ring[tail];
1277 buf_dma_addr = rte_mbuf_data_iova(m_seg);
1278 txd->buf_addr = rte_cpu_to_le_64(buf_dma_addr);
1280 txd->type = tx_desc_type_desc;
1281 txd->len = m_seg->data_len;
1282 txd->pay_len = pay_len;
1284 /* Store mbuf for freeing later */
1285 tx_entry = &txq->sw_ring[tail];
1288 rte_pktmbuf_free_seg(tx_entry->mbuf);
1289 tx_entry->mbuf = m_seg;
1291 tail = (tail + 1) % txq->nb_tx_desc;
1296 // Last descriptor requires EOP and WB
1298 txd->cmd |= tx_desc_cmd_wb;
1300 hw_atl_b0_hw_tx_ring_tail_update(hw, tail, txq->queue_id);
1302 txq->tx_tail = tail;
1304 txq->tx_free -= desc_count;
1306 adapter->sw_stats.q_opackets[txq->queue_id]++;
1307 adapter->sw_stats.q_obytes[txq->queue_id] += pay_len;
1311 atl_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
1313 struct rte_eth_dev *dev = NULL;
1314 struct aq_hw_s *hw = NULL;
1315 struct atl_tx_queue *txq = tx_queue;
1316 struct rte_mbuf *tx_pkt;
1319 dev = &rte_eth_devices[txq->port_id];
1320 hw = ATL_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1323 "port %d txq %d pkts: %d tx_free=%d tx_tail=%d tx_head=%d",
1324 txq->port_id, txq->queue_id, nb_pkts, txq->tx_free,
1325 txq->tx_tail, txq->tx_head);
1327 for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
1328 tx_pkt = *tx_pkts++;
1330 /* Clean Tx queue if needed */
1331 if (txq->tx_free < txq->tx_free_thresh)
1332 atl_xmit_cleanup(txq);
1334 /* Check if we have enough free descriptors */
1335 if (txq->tx_free < tx_pkt->nb_segs)
1338 /* check mbuf is valid */
1339 if ((tx_pkt->nb_segs == 0) ||
1340 ((tx_pkt->nb_segs > 1) && (tx_pkt->next == NULL)))
1343 /* Send the packet */
1344 atl_xmit_pkt(hw, txq, tx_pkt);
1347 PMD_TX_LOG(DEBUG, "atl_xmit_pkts %d transmitted", nb_tx);