2 * Copyright (c) 2014, 2015 Netronome Systems, Inc.
5 * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 * vim:shiftwidth=8:noexpandtab
37 * @file dpdk/pmd/nfp_net.c
39 * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
44 #include <rte_byteorder.h>
45 #include <rte_common.h>
47 #include <rte_debug.h>
48 #include <rte_ethdev.h>
50 #include <rte_ether.h>
51 #include <rte_malloc.h>
52 #include <rte_memzone.h>
53 #include <rte_mempool.h>
54 #include <rte_version.h>
55 #include <rte_string_fns.h>
56 #include <rte_alarm.h>
57 #include <rte_spinlock.h>
59 #include "nfp_net_pmd.h"
60 #include "nfp_net_logs.h"
61 #include "nfp_net_ctrl.h"
64 static void nfp_net_close(struct rte_eth_dev *dev);
65 static int nfp_net_configure(struct rte_eth_dev *dev);
66 static void nfp_net_dev_interrupt_handler(struct rte_intr_handle *handle,
68 static void nfp_net_dev_interrupt_delayed_handler(void *param);
69 static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
70 static void nfp_net_infos_get(struct rte_eth_dev *dev,
71 struct rte_eth_dev_info *dev_info);
72 static int nfp_net_init(struct rte_eth_dev *eth_dev);
73 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
74 static void nfp_net_promisc_enable(struct rte_eth_dev *dev);
75 static void nfp_net_promisc_disable(struct rte_eth_dev *dev);
76 static int nfp_net_rx_fill_freelist(struct nfp_net_rxq *rxq);
77 static uint32_t nfp_net_rx_queue_count(struct rte_eth_dev *dev,
79 static uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
81 static void nfp_net_rx_queue_release(void *rxq);
82 static int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
83 uint16_t nb_desc, unsigned int socket_id,
84 const struct rte_eth_rxconf *rx_conf,
85 struct rte_mempool *mp);
86 static int nfp_net_tx_free_bufs(struct nfp_net_txq *txq);
87 static void nfp_net_tx_queue_release(void *txq);
88 static int nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
89 uint16_t nb_desc, unsigned int socket_id,
90 const struct rte_eth_txconf *tx_conf);
91 static int nfp_net_start(struct rte_eth_dev *dev);
92 static void nfp_net_stats_get(struct rte_eth_dev *dev,
93 struct rte_eth_stats *stats);
94 static void nfp_net_stats_reset(struct rte_eth_dev *dev);
95 static void nfp_net_stop(struct rte_eth_dev *dev);
96 static uint16_t nfp_net_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
100 * The offset of the queue controller queues in the PCIe Target. These
101 * happen to be at the same offset on the NFP6000 and the NFP3200 so
102 * we use a single macro here.
104 #define NFP_PCIE_QUEUE(_q) (0x80000 + (0x800 * ((_q) & 0xff)))
106 /* Maximum value which can be added to a queue with one transaction */
107 #define NFP_QCP_MAX_ADD 0x7f
109 #define RTE_MBUF_DMA_ADDR_DEFAULT(mb) \
110 (uint64_t)((mb)->buf_physaddr + RTE_PKTMBUF_HEADROOM)
112 /* nfp_qcp_ptr - Read or Write Pointer of a queue */
114 NFP_QCP_READ_PTR = 0,
119 * nfp_qcp_ptr_add - Add the value to the selected pointer of a queue
120 * @q: Base address for queue structure
121 * @ptr: Add to the Read or Write pointer
122 * @val: Value to add to the queue pointer
124 * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed.
127 nfp_qcp_ptr_add(uint8_t *q, enum nfp_qcp_ptr ptr, uint32_t val)
131 if (ptr == NFP_QCP_READ_PTR)
132 off = NFP_QCP_QUEUE_ADD_RPTR;
134 off = NFP_QCP_QUEUE_ADD_WPTR;
136 while (val > NFP_QCP_MAX_ADD) {
137 nn_writel(rte_cpu_to_le_32(NFP_QCP_MAX_ADD), q + off);
138 val -= NFP_QCP_MAX_ADD;
141 nn_writel(rte_cpu_to_le_32(val), q + off);
145 * nfp_qcp_read - Read the current Read/Write pointer value for a queue
146 * @q: Base address for queue structure
147 * @ptr: Read or Write pointer
149 static inline uint32_t
150 nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr)
155 if (ptr == NFP_QCP_READ_PTR)
156 off = NFP_QCP_QUEUE_STS_LO;
158 off = NFP_QCP_QUEUE_STS_HI;
160 val = rte_cpu_to_le_32(nn_readl(q + off));
162 if (ptr == NFP_QCP_READ_PTR)
163 return val & NFP_QCP_QUEUE_STS_LO_READPTR_mask;
165 return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask;
169 * Functions to read/write from/to Config BAR
170 * Performs any endian conversion necessary.
172 static inline uint8_t
173 nn_cfg_readb(struct nfp_net_hw *hw, int off)
175 return nn_readb(hw->ctrl_bar + off);
179 nn_cfg_writeb(struct nfp_net_hw *hw, int off, uint8_t val)
181 nn_writeb(val, hw->ctrl_bar + off);
184 static inline uint32_t
185 nn_cfg_readl(struct nfp_net_hw *hw, int off)
187 return rte_le_to_cpu_32(nn_readl(hw->ctrl_bar + off));
191 nn_cfg_writel(struct nfp_net_hw *hw, int off, uint32_t val)
193 nn_writel(rte_cpu_to_le_32(val), hw->ctrl_bar + off);
196 static inline uint64_t
197 nn_cfg_readq(struct nfp_net_hw *hw, int off)
199 return rte_le_to_cpu_64(nn_readq(hw->ctrl_bar + off));
203 nn_cfg_writeq(struct nfp_net_hw *hw, int off, uint64_t val)
205 nn_writeq(rte_cpu_to_le_64(val), hw->ctrl_bar + off);
208 /* Creating memzone for hardware rings. */
209 static const struct rte_memzone *
210 ring_dma_zone_reserve(struct rte_eth_dev *dev, const char *ring_name,
211 uint16_t queue_id, uint32_t ring_size, int socket_id)
213 char z_name[RTE_MEMZONE_NAMESIZE];
214 const struct rte_memzone *mz;
216 snprintf(z_name, sizeof(z_name), "%s_%s_%d_%d",
217 dev->driver->pci_drv.driver.name,
218 ring_name, dev->data->port_id, queue_id);
220 mz = rte_memzone_lookup(z_name);
224 return rte_memzone_reserve_aligned(z_name, ring_size, socket_id, 0,
229 * Atomically reads link status information from global structure rte_eth_dev.
232 * - Pointer to the structure rte_eth_dev to read from.
233 * - Pointer to the buffer to be saved with the link status.
236 * - On success, zero.
237 * - On failure, negative value.
240 nfp_net_dev_atomic_read_link_status(struct rte_eth_dev *dev,
241 struct rte_eth_link *link)
243 struct rte_eth_link *dst = link;
244 struct rte_eth_link *src = &dev->data->dev_link;
246 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
247 *(uint64_t *)src) == 0)
254 * Atomically writes the link status information into global
255 * structure rte_eth_dev.
258 * - Pointer to the structure rte_eth_dev to read from.
259 * - Pointer to the buffer to be saved with the link status.
262 * - On success, zero.
263 * - On failure, negative value.
266 nfp_net_dev_atomic_write_link_status(struct rte_eth_dev *dev,
267 struct rte_eth_link *link)
269 struct rte_eth_link *dst = &dev->data->dev_link;
270 struct rte_eth_link *src = link;
272 if (rte_atomic64_cmpset((uint64_t *)dst, *(uint64_t *)dst,
273 *(uint64_t *)src) == 0)
280 nfp_net_rx_queue_release_mbufs(struct nfp_net_rxq *rxq)
284 if (rxq->rxbufs == NULL)
287 for (i = 0; i < rxq->rx_count; i++) {
288 if (rxq->rxbufs[i].mbuf) {
289 rte_pktmbuf_free_seg(rxq->rxbufs[i].mbuf);
290 rxq->rxbufs[i].mbuf = NULL;
296 nfp_net_rx_queue_release(void *rx_queue)
298 struct nfp_net_rxq *rxq = rx_queue;
301 nfp_net_rx_queue_release_mbufs(rxq);
302 rte_free(rxq->rxbufs);
308 nfp_net_reset_rx_queue(struct nfp_net_rxq *rxq)
310 nfp_net_rx_queue_release_mbufs(rxq);
316 nfp_net_tx_queue_release_mbufs(struct nfp_net_txq *txq)
320 if (txq->txbufs == NULL)
323 for (i = 0; i < txq->tx_count; i++) {
324 if (txq->txbufs[i].mbuf) {
325 rte_pktmbuf_free(txq->txbufs[i].mbuf);
326 txq->txbufs[i].mbuf = NULL;
332 nfp_net_tx_queue_release(void *tx_queue)
334 struct nfp_net_txq *txq = tx_queue;
337 nfp_net_tx_queue_release_mbufs(txq);
338 rte_free(txq->txbufs);
344 nfp_net_reset_tx_queue(struct nfp_net_txq *txq)
346 nfp_net_tx_queue_release_mbufs(txq);
352 __nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t update)
356 struct timespec wait;
358 PMD_DRV_LOG(DEBUG, "Writing to the configuration queue (%p)...\n",
361 if (hw->qcp_cfg == NULL)
362 rte_panic("Bad configuration queue pointer\n");
364 nfp_qcp_ptr_add(hw->qcp_cfg, NFP_QCP_WRITE_PTR, 1);
367 wait.tv_nsec = 1000000;
369 PMD_DRV_LOG(DEBUG, "Polling for update ack...\n");
371 /* Poll update field, waiting for NFP to ack the config */
372 for (cnt = 0; ; cnt++) {
373 new = nn_cfg_readl(hw, NFP_NET_CFG_UPDATE);
376 if (new & NFP_NET_CFG_UPDATE_ERR) {
377 PMD_INIT_LOG(ERR, "Reconfig error: 0x%08x", new);
380 if (cnt >= NFP_NET_POLL_TIMEOUT) {
381 PMD_INIT_LOG(ERR, "Reconfig timeout for 0x%08x after"
382 " %dms", update, cnt);
383 rte_panic("Exiting\n");
385 nanosleep(&wait, 0); /* waiting for a 1ms */
387 PMD_DRV_LOG(DEBUG, "Ack DONE\n");
392 * Reconfigure the NIC
393 * @nn: device to reconfigure
394 * @ctrl: The value for the ctrl field in the BAR config
395 * @update: The value for the update field in the BAR config
397 * Write the update word to the BAR and ping the reconfig queue. Then poll
398 * until the firmware has acknowledged the update by zeroing the update word.
401 nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update)
405 PMD_DRV_LOG(DEBUG, "nfp_net_reconfig: ctrl=%08x update=%08x\n",
408 rte_spinlock_lock(&hw->reconfig_lock);
410 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, ctrl);
411 nn_cfg_writel(hw, NFP_NET_CFG_UPDATE, update);
415 err = __nfp_net_reconfig(hw, update);
417 rte_spinlock_unlock(&hw->reconfig_lock);
423 * Reconfig errors imply situations where they can be handled.
424 * Otherwise, rte_panic is called inside __nfp_net_reconfig
426 PMD_INIT_LOG(ERR, "Error nfp_net reconfig for ctrl: %x update: %x",
432 * Configure an Ethernet device. This function must be invoked first
433 * before any other function in the Ethernet API. This function can
434 * also be re-invoked when a device is in the stopped state.
437 nfp_net_configure(struct rte_eth_dev *dev)
439 struct rte_eth_conf *dev_conf;
440 struct rte_eth_rxmode *rxmode;
441 struct rte_eth_txmode *txmode;
442 uint32_t new_ctrl = 0;
444 struct nfp_net_hw *hw;
446 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
449 * A DPDK app sends info about how many queues to use and how
450 * those queues need to be configured. This is used by the
451 * DPDK core and it makes sure no more queues than those
452 * advertised by the driver are requested. This function is
453 * called after that internal process
456 PMD_INIT_LOG(DEBUG, "Configure");
458 dev_conf = &dev->data->dev_conf;
459 rxmode = &dev_conf->rxmode;
460 txmode = &dev_conf->txmode;
462 /* Checking TX mode */
463 if (txmode->mq_mode) {
464 PMD_INIT_LOG(INFO, "TX mq_mode DCB and VMDq not supported");
468 /* Checking RX mode */
469 if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
470 if (hw->cap & NFP_NET_CFG_CTRL_RSS) {
471 update = NFP_NET_CFG_UPDATE_RSS;
472 new_ctrl = NFP_NET_CFG_CTRL_RSS;
474 PMD_INIT_LOG(INFO, "RSS not supported");
479 if (rxmode->split_hdr_size) {
480 PMD_INIT_LOG(INFO, "rxmode does not support split header");
484 if (rxmode->hw_ip_checksum) {
485 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM) {
486 new_ctrl |= NFP_NET_CFG_CTRL_RXCSUM;
488 PMD_INIT_LOG(INFO, "RXCSUM not supported");
493 if (rxmode->hw_vlan_filter) {
494 PMD_INIT_LOG(INFO, "VLAN filter not supported");
498 if (rxmode->hw_vlan_strip) {
499 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN) {
500 new_ctrl |= NFP_NET_CFG_CTRL_RXVLAN;
502 PMD_INIT_LOG(INFO, "hw vlan strip not supported");
507 if (rxmode->hw_vlan_extend) {
508 PMD_INIT_LOG(INFO, "VLAN extended not supported");
512 /* Supporting VLAN insertion by default */
513 if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
514 new_ctrl |= NFP_NET_CFG_CTRL_TXVLAN;
516 if (rxmode->jumbo_frame)
517 /* this is handled in rte_eth_dev_configure */
519 if (rxmode->hw_strip_crc) {
520 PMD_INIT_LOG(INFO, "strip CRC not supported");
524 if (rxmode->enable_scatter) {
525 PMD_INIT_LOG(INFO, "Scatter not supported");
532 update |= NFP_NET_CFG_UPDATE_GEN;
534 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, new_ctrl);
535 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
544 nfp_net_enable_queues(struct rte_eth_dev *dev)
546 struct nfp_net_hw *hw;
547 uint64_t enabled_queues = 0;
550 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
552 /* Enabling the required TX queues in the device */
553 for (i = 0; i < dev->data->nb_tx_queues; i++)
554 enabled_queues |= (1 << i);
556 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, enabled_queues);
560 /* Enabling the required RX queues in the device */
561 for (i = 0; i < dev->data->nb_rx_queues; i++)
562 enabled_queues |= (1 << i);
564 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
568 nfp_net_disable_queues(struct rte_eth_dev *dev)
570 struct nfp_net_hw *hw;
571 uint32_t new_ctrl, update = 0;
573 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
575 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, 0);
576 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, 0);
578 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_ENABLE;
579 update = NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING |
580 NFP_NET_CFG_UPDATE_MSIX;
582 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
583 new_ctrl &= ~NFP_NET_CFG_CTRL_RINGCFG;
585 /* If an error when reconfig we avoid to change hw state */
586 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
593 nfp_net_rx_freelist_setup(struct rte_eth_dev *dev)
597 for (i = 0; i < dev->data->nb_rx_queues; i++) {
598 if (nfp_net_rx_fill_freelist(dev->data->rx_queues[i]) < 0)
605 nfp_net_params_setup(struct nfp_net_hw *hw)
607 nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
608 nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
612 nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
614 hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
617 static void nfp_net_read_mac(struct nfp_net_hw *hw)
621 tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
622 memcpy(&hw->mac_addr[0], &tmp, sizeof(struct ether_addr));
624 tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
625 memcpy(&hw->mac_addr[4], &tmp, 2);
629 nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
630 struct rte_intr_handle *intr_handle)
632 struct nfp_net_hw *hw;
635 if (!intr_handle->intr_vec) {
636 intr_handle->intr_vec =
637 rte_zmalloc("intr_vec",
638 dev->data->nb_rx_queues * sizeof(int), 0);
639 if (!intr_handle->intr_vec) {
640 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
641 " intr_vec", dev->data->nb_rx_queues);
646 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
648 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
649 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with UIO");
650 /* UIO just supports one queue and no LSC*/
651 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(0), 0);
653 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with VFIO");
654 for (i = 0; i < dev->data->nb_rx_queues; i++)
656 * The first msix vector is reserved for non
659 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(i), i + 1);
662 /* Avoiding TX interrupts */
663 hw->ctrl |= NFP_NET_CFG_CTRL_MSIX_TX_OFF;
668 nfp_net_start(struct rte_eth_dev *dev)
670 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
671 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
672 uint32_t new_ctrl, update = 0;
673 struct nfp_net_hw *hw;
674 uint32_t intr_vector;
677 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
679 PMD_INIT_LOG(DEBUG, "Start");
681 /* Disabling queues just in case... */
682 nfp_net_disable_queues(dev);
684 /* Writing configuration parameters in the device */
685 nfp_net_params_setup(hw);
687 /* Enabling the required queues in the device */
688 nfp_net_enable_queues(dev);
690 /* check and configure queue intr-vector mapping */
691 if (dev->data->dev_conf.intr_conf.rxq != 0) {
692 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
694 * Better not to share LSC with RX interrupts.
695 * Unregistering LSC interrupt handler
697 rte_intr_callback_unregister(&pci_dev->intr_handle,
698 nfp_net_dev_interrupt_handler, (void *)dev);
700 if (dev->data->nb_rx_queues > 1) {
701 PMD_INIT_LOG(ERR, "PMD rx interrupt only "
702 "supports 1 queue with UIO");
706 intr_vector = dev->data->nb_rx_queues;
707 if (rte_intr_efd_enable(intr_handle, intr_vector))
711 nfp_configure_rx_interrupt(dev, intr_handle);
713 rte_intr_enable(intr_handle);
716 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_ENABLE;
717 update = NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING;
719 /* Just configuring queues interrupts when necessary */
720 if (rte_intr_dp_is_en(intr_handle))
721 update |= NFP_NET_CFG_UPDATE_MSIX;
723 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
724 new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
726 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, new_ctrl);
727 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
731 * Allocating rte mbuffs for configured rx queues.
732 * This requires queues being enabled before
734 if (nfp_net_rx_freelist_setup(dev) < 0) {
745 * An error returned by this function should mean the app
746 * exiting and then the system releasing all the memory
747 * allocated even memory coming from hugepages.
749 * The device could be enabled at this point with some queues
750 * ready for getting packets. This is true if the call to
751 * nfp_net_rx_freelist_setup() succeeds for some queues but
752 * fails for subsequent queues.
754 * This should make the app exiting but better if we tell the
757 nfp_net_disable_queues(dev);
762 /* Stop device: disable rx and tx functions to allow for reconfiguring. */
764 nfp_net_stop(struct rte_eth_dev *dev)
768 PMD_INIT_LOG(DEBUG, "Stop");
770 nfp_net_disable_queues(dev);
773 for (i = 0; i < dev->data->nb_tx_queues; i++) {
774 nfp_net_reset_tx_queue(
775 (struct nfp_net_txq *)dev->data->tx_queues[i]);
778 for (i = 0; i < dev->data->nb_rx_queues; i++) {
779 nfp_net_reset_rx_queue(
780 (struct nfp_net_rxq *)dev->data->rx_queues[i]);
784 /* Reset and stop device. The device can not be restarted. */
786 nfp_net_close(struct rte_eth_dev *dev)
788 struct nfp_net_hw *hw;
789 struct rte_pci_device *pci_dev;
791 PMD_INIT_LOG(DEBUG, "Close");
793 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
794 pci_dev = RTE_DEV_TO_PCI(dev->device);
797 * We assume that the DPDK application is stopping all the
798 * threads/queues before calling the device close function.
803 rte_intr_disable(&pci_dev->intr_handle);
804 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
806 /* unregister callback func from eal lib */
807 rte_intr_callback_unregister(&pci_dev->intr_handle,
808 nfp_net_dev_interrupt_handler,
812 * The ixgbe PMD driver disables the pcie master on the
813 * device. The i40e does not...
818 nfp_net_promisc_enable(struct rte_eth_dev *dev)
820 uint32_t new_ctrl, update = 0;
821 struct nfp_net_hw *hw;
823 PMD_DRV_LOG(DEBUG, "Promiscuous mode enable\n");
825 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
827 if (!(hw->cap & NFP_NET_CFG_CTRL_PROMISC)) {
828 PMD_INIT_LOG(INFO, "Promiscuous mode not supported");
832 if (hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) {
833 PMD_DRV_LOG(INFO, "Promiscuous mode already enabled\n");
837 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_PROMISC;
838 update = NFP_NET_CFG_UPDATE_GEN;
841 * DPDK sets promiscuous mode on just after this call assuming
842 * it can not fail ...
844 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
851 nfp_net_promisc_disable(struct rte_eth_dev *dev)
853 uint32_t new_ctrl, update = 0;
854 struct nfp_net_hw *hw;
856 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
858 if ((hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) == 0) {
859 PMD_DRV_LOG(INFO, "Promiscuous mode already disabled\n");
863 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_PROMISC;
864 update = NFP_NET_CFG_UPDATE_GEN;
867 * DPDK sets promiscuous mode off just before this call
868 * assuming it can not fail ...
870 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
877 * return 0 means link status changed, -1 means not changed
879 * Wait to complete is needed as it can take up to 9 seconds to get the Link
883 nfp_net_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
885 struct nfp_net_hw *hw;
886 struct rte_eth_link link, old;
887 uint32_t nn_link_status;
889 static const uint32_t ls_to_ethtool[] = {
890 [NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = ETH_SPEED_NUM_NONE,
891 [NFP_NET_CFG_STS_LINK_RATE_UNKNOWN] = ETH_SPEED_NUM_NONE,
892 [NFP_NET_CFG_STS_LINK_RATE_1G] = ETH_SPEED_NUM_1G,
893 [NFP_NET_CFG_STS_LINK_RATE_10G] = ETH_SPEED_NUM_10G,
894 [NFP_NET_CFG_STS_LINK_RATE_25G] = ETH_SPEED_NUM_25G,
895 [NFP_NET_CFG_STS_LINK_RATE_40G] = ETH_SPEED_NUM_40G,
896 [NFP_NET_CFG_STS_LINK_RATE_50G] = ETH_SPEED_NUM_50G,
897 [NFP_NET_CFG_STS_LINK_RATE_100G] = ETH_SPEED_NUM_100G,
900 PMD_DRV_LOG(DEBUG, "Link update\n");
902 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
904 memset(&old, 0, sizeof(old));
905 nfp_net_dev_atomic_read_link_status(dev, &old);
907 nn_link_status = nn_cfg_readl(hw, NFP_NET_CFG_STS);
909 memset(&link, 0, sizeof(struct rte_eth_link));
911 if (nn_link_status & NFP_NET_CFG_STS_LINK)
912 link.link_status = ETH_LINK_UP;
914 link.link_duplex = ETH_LINK_FULL_DUPLEX;
916 nn_link_status = (nn_link_status >> NFP_NET_CFG_STS_LINK_RATE_SHIFT) &
917 NFP_NET_CFG_STS_LINK_RATE_MASK;
919 if ((NFD_CFG_MAJOR_VERSION_of(hw->ver) < 4) ||
920 ((NFD_CFG_MINOR_VERSION_of(hw->ver) == 4) &&
921 (NFD_CFG_MINOR_VERSION_of(hw->ver) == 0)))
922 /* We really do not know the speed wil old firmware */
923 link.link_speed = ETH_SPEED_NUM_NONE;
925 if (nn_link_status >= RTE_DIM(ls_to_ethtool))
926 link.link_speed = ETH_SPEED_NUM_NONE;
928 link.link_speed = ls_to_ethtool[nn_link_status];
931 if (old.link_status != link.link_status) {
932 nfp_net_dev_atomic_write_link_status(dev, &link);
933 if (link.link_status)
934 PMD_DRV_LOG(INFO, "NIC Link is Up\n");
936 PMD_DRV_LOG(INFO, "NIC Link is Down\n");
944 nfp_net_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
947 struct nfp_net_hw *hw;
948 struct rte_eth_stats nfp_dev_stats;
950 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
952 /* RTE_ETHDEV_QUEUE_STAT_CNTRS default value is 16 */
954 /* reading per RX ring stats */
955 for (i = 0; i < dev->data->nb_rx_queues; i++) {
956 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
959 nfp_dev_stats.q_ipackets[i] =
960 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
962 nfp_dev_stats.q_ipackets[i] -=
963 hw->eth_stats_base.q_ipackets[i];
965 nfp_dev_stats.q_ibytes[i] =
966 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
968 nfp_dev_stats.q_ibytes[i] -=
969 hw->eth_stats_base.q_ibytes[i];
972 /* reading per TX ring stats */
973 for (i = 0; i < dev->data->nb_tx_queues; i++) {
974 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
977 nfp_dev_stats.q_opackets[i] =
978 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
980 nfp_dev_stats.q_opackets[i] -=
981 hw->eth_stats_base.q_opackets[i];
983 nfp_dev_stats.q_obytes[i] =
984 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
986 nfp_dev_stats.q_obytes[i] -=
987 hw->eth_stats_base.q_obytes[i];
990 nfp_dev_stats.ipackets =
991 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
993 nfp_dev_stats.ipackets -= hw->eth_stats_base.ipackets;
995 nfp_dev_stats.ibytes =
996 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
998 nfp_dev_stats.ibytes -= hw->eth_stats_base.ibytes;
1000 nfp_dev_stats.opackets =
1001 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
1003 nfp_dev_stats.opackets -= hw->eth_stats_base.opackets;
1005 nfp_dev_stats.obytes =
1006 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
1008 nfp_dev_stats.obytes -= hw->eth_stats_base.obytes;
1010 /* reading general device stats */
1011 nfp_dev_stats.ierrors =
1012 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
1014 nfp_dev_stats.ierrors -= hw->eth_stats_base.ierrors;
1016 nfp_dev_stats.oerrors =
1017 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
1019 nfp_dev_stats.oerrors -= hw->eth_stats_base.oerrors;
1021 /* RX ring mbuf allocation failures */
1022 nfp_dev_stats.rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1024 nfp_dev_stats.imissed =
1025 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
1027 nfp_dev_stats.imissed -= hw->eth_stats_base.imissed;
1030 memcpy(stats, &nfp_dev_stats, sizeof(*stats));
1034 nfp_net_stats_reset(struct rte_eth_dev *dev)
1037 struct nfp_net_hw *hw;
1039 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1042 * hw->eth_stats_base records the per counter starting point.
1043 * Lets update it now
1046 /* reading per RX ring stats */
1047 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1048 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
1051 hw->eth_stats_base.q_ipackets[i] =
1052 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
1054 hw->eth_stats_base.q_ibytes[i] =
1055 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
1058 /* reading per TX ring stats */
1059 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1060 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
1063 hw->eth_stats_base.q_opackets[i] =
1064 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
1066 hw->eth_stats_base.q_obytes[i] =
1067 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
1070 hw->eth_stats_base.ipackets =
1071 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
1073 hw->eth_stats_base.ibytes =
1074 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
1076 hw->eth_stats_base.opackets =
1077 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
1079 hw->eth_stats_base.obytes =
1080 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
1082 /* reading general device stats */
1083 hw->eth_stats_base.ierrors =
1084 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
1086 hw->eth_stats_base.oerrors =
1087 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
1089 /* RX ring mbuf allocation failures */
1090 dev->data->rx_mbuf_alloc_failed = 0;
1092 hw->eth_stats_base.imissed =
1093 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
1097 nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1099 struct nfp_net_hw *hw;
1101 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1103 dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
1104 dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
1105 dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
1106 dev_info->min_rx_bufsize = ETHER_MIN_MTU;
1107 dev_info->max_rx_pktlen = hw->mtu;
1108 /* Next should change when PF support is implemented */
1109 dev_info->max_mac_addrs = 1;
1111 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN)
1112 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
1114 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM)
1115 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_IPV4_CKSUM |
1116 DEV_RX_OFFLOAD_UDP_CKSUM |
1117 DEV_RX_OFFLOAD_TCP_CKSUM;
1119 if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
1120 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
1122 if (hw->cap & NFP_NET_CFG_CTRL_TXCSUM)
1123 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_IPV4_CKSUM |
1124 DEV_TX_OFFLOAD_UDP_CKSUM |
1125 DEV_TX_OFFLOAD_TCP_CKSUM;
1127 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1129 .pthresh = DEFAULT_RX_PTHRESH,
1130 .hthresh = DEFAULT_RX_HTHRESH,
1131 .wthresh = DEFAULT_RX_WTHRESH,
1133 .rx_free_thresh = DEFAULT_RX_FREE_THRESH,
1137 dev_info->default_txconf = (struct rte_eth_txconf) {
1139 .pthresh = DEFAULT_TX_PTHRESH,
1140 .hthresh = DEFAULT_TX_HTHRESH,
1141 .wthresh = DEFAULT_TX_WTHRESH,
1143 .tx_free_thresh = DEFAULT_TX_FREE_THRESH,
1144 .tx_rs_thresh = DEFAULT_TX_RSBIT_THRESH,
1145 .txq_flags = ETH_TXQ_FLAGS_NOMULTSEGS |
1146 ETH_TXQ_FLAGS_NOOFFLOADS,
1149 dev_info->reta_size = NFP_NET_CFG_RSS_ITBL_SZ;
1150 dev_info->hash_key_size = NFP_NET_CFG_RSS_KEY_SZ;
1152 dev_info->speed_capa = ETH_SPEED_NUM_1G | ETH_LINK_SPEED_10G |
1153 ETH_SPEED_NUM_25G | ETH_SPEED_NUM_40G |
1154 ETH_SPEED_NUM_50G | ETH_LINK_SPEED_100G;
1156 if (hw->cap & NFP_NET_CFG_CTRL_LSO)
1157 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_TCP_TSO;
1160 static const uint32_t *
1161 nfp_net_supported_ptypes_get(struct rte_eth_dev *dev)
1163 static const uint32_t ptypes[] = {
1164 /* refers to nfp_net_set_hash() */
1165 RTE_PTYPE_INNER_L3_IPV4,
1166 RTE_PTYPE_INNER_L3_IPV6,
1167 RTE_PTYPE_INNER_L3_IPV6_EXT,
1168 RTE_PTYPE_INNER_L4_MASK,
1172 if (dev->rx_pkt_burst == nfp_net_recv_pkts)
1178 nfp_net_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_idx)
1180 struct nfp_net_rxq *rxq;
1181 struct nfp_net_rx_desc *rxds;
1185 rxq = (struct nfp_net_rxq *)dev->data->rx_queues[queue_idx];
1192 * Other PMDs are just checking the DD bit in intervals of 4
1193 * descriptors and counting all four if the first has the DD
1194 * bit on. Of course, this is not accurate but can be good for
1195 * perfomance. But ideally that should be done in descriptors
1196 * chunks belonging to the same cache line
1199 while (count < rxq->rx_count) {
1200 rxds = &rxq->rxds[idx];
1201 if ((rxds->rxd.meta_len_dd & PCIE_DESC_RX_DD) == 0)
1208 if ((idx) == rxq->rx_count)
1216 nfp_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1218 struct rte_pci_device *pci_dev;
1219 struct nfp_net_hw *hw;
1222 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1223 pci_dev = RTE_DEV_TO_PCI(dev->device);
1225 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1228 /* Make sure all updates are written before un-masking */
1230 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id),
1231 NFP_NET_CFG_ICR_UNMASKED);
1236 nfp_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1238 struct rte_pci_device *pci_dev;
1239 struct nfp_net_hw *hw;
1242 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1243 pci_dev = RTE_DEV_TO_PCI(dev->device);
1245 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1248 /* Make sure all updates are written before un-masking */
1250 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id), 0x1);
1255 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
1257 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
1258 struct rte_eth_link link;
1260 memset(&link, 0, sizeof(link));
1261 nfp_net_dev_atomic_read_link_status(dev, &link);
1262 if (link.link_status)
1263 RTE_LOG(INFO, PMD, "Port %d: Link Up - speed %u Mbps - %s\n",
1264 (int)(dev->data->port_id), (unsigned)link.link_speed,
1265 link.link_duplex == ETH_LINK_FULL_DUPLEX
1266 ? "full-duplex" : "half-duplex");
1268 RTE_LOG(INFO, PMD, " Port %d: Link Down\n",
1269 (int)(dev->data->port_id));
1271 RTE_LOG(INFO, PMD, "PCI Address: %04d:%02d:%02d:%d\n",
1272 pci_dev->addr.domain, pci_dev->addr.bus,
1273 pci_dev->addr.devid, pci_dev->addr.function);
1276 /* Interrupt configuration and handling */
1279 * nfp_net_irq_unmask - Unmask an interrupt
1281 * If MSI-X auto-masking is enabled clear the mask bit, otherwise
1282 * clear the ICR for the entry.
1285 nfp_net_irq_unmask(struct rte_eth_dev *dev)
1287 struct nfp_net_hw *hw;
1288 struct rte_pci_device *pci_dev;
1290 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1291 pci_dev = RTE_DEV_TO_PCI(dev->device);
1293 if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
1294 /* If MSI-X auto-masking is used, clear the entry */
1296 rte_intr_enable(&pci_dev->intr_handle);
1298 /* Make sure all updates are written before un-masking */
1300 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(NFP_NET_IRQ_LSC_IDX),
1301 NFP_NET_CFG_ICR_UNMASKED);
1306 nfp_net_dev_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
1310 struct rte_eth_link link;
1311 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1313 PMD_DRV_LOG(DEBUG, "We got a LSC interrupt!!!\n");
1315 /* get the link status */
1316 memset(&link, 0, sizeof(link));
1317 nfp_net_dev_atomic_read_link_status(dev, &link);
1319 nfp_net_link_update(dev, 0);
1322 if (!link.link_status) {
1323 /* handle it 1 sec later, wait it being stable */
1324 timeout = NFP_NET_LINK_UP_CHECK_TIMEOUT;
1325 /* likely to down */
1327 /* handle it 4 sec later, wait it being stable */
1328 timeout = NFP_NET_LINK_DOWN_CHECK_TIMEOUT;
1331 if (rte_eal_alarm_set(timeout * 1000,
1332 nfp_net_dev_interrupt_delayed_handler,
1334 RTE_LOG(ERR, PMD, "Error setting alarm");
1336 nfp_net_irq_unmask(dev);
1341 * Interrupt handler which shall be registered for alarm callback for delayed
1342 * handling specific interrupt to wait for the stable nic state. As the NIC
1343 * interrupt state is not stable for nfp after link is just down, it needs
1344 * to wait 4 seconds to get the stable status.
1346 * @param handle Pointer to interrupt handle.
1347 * @param param The address of parameter (struct rte_eth_dev *)
1352 nfp_net_dev_interrupt_delayed_handler(void *param)
1354 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1356 nfp_net_link_update(dev, 0);
1357 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1359 nfp_net_dev_link_status_print(dev);
1362 nfp_net_irq_unmask(dev);
1366 nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1368 struct nfp_net_hw *hw;
1370 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1372 /* check that mtu is within the allowed range */
1373 if ((mtu < ETHER_MIN_MTU) || ((uint32_t)mtu > hw->max_mtu))
1376 /* switch to jumbo mode if needed */
1377 if ((uint32_t)mtu > ETHER_MAX_LEN)
1378 dev->data->dev_conf.rxmode.jumbo_frame = 1;
1380 dev->data->dev_conf.rxmode.jumbo_frame = 0;
1382 /* update max frame size */
1383 dev->data->dev_conf.rxmode.max_rx_pkt_len = (uint32_t)mtu;
1385 /* writing to configuration space */
1386 nn_cfg_writel(hw, NFP_NET_CFG_MTU, (uint32_t)mtu);
1394 nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
1395 uint16_t queue_idx, uint16_t nb_desc,
1396 unsigned int socket_id,
1397 const struct rte_eth_rxconf *rx_conf,
1398 struct rte_mempool *mp)
1400 const struct rte_memzone *tz;
1401 struct nfp_net_rxq *rxq;
1402 struct nfp_net_hw *hw;
1404 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1406 PMD_INIT_FUNC_TRACE();
1408 /* Validating number of descriptors */
1409 if (((nb_desc * sizeof(struct nfp_net_rx_desc)) % 128) != 0 ||
1410 (nb_desc > NFP_NET_MAX_RX_DESC) ||
1411 (nb_desc < NFP_NET_MIN_RX_DESC)) {
1412 RTE_LOG(ERR, PMD, "Wrong nb_desc value\n");
1417 * Free memory prior to re-allocation if needed. This is the case after
1418 * calling nfp_net_stop
1420 if (dev->data->rx_queues[queue_idx]) {
1421 nfp_net_rx_queue_release(dev->data->rx_queues[queue_idx]);
1422 dev->data->rx_queues[queue_idx] = NULL;
1425 /* Allocating rx queue data structure */
1426 rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct nfp_net_rxq),
1427 RTE_CACHE_LINE_SIZE, socket_id);
1431 /* Hw queues mapping based on firmware confifguration */
1432 rxq->qidx = queue_idx;
1433 rxq->fl_qcidx = queue_idx * hw->stride_rx;
1434 rxq->rx_qcidx = rxq->fl_qcidx + (hw->stride_rx - 1);
1435 rxq->qcp_fl = hw->rx_bar + NFP_QCP_QUEUE_OFF(rxq->fl_qcidx);
1436 rxq->qcp_rx = hw->rx_bar + NFP_QCP_QUEUE_OFF(rxq->rx_qcidx);
1439 * Tracking mbuf size for detecting a potential mbuf overflow due to
1443 rxq->mbuf_size = rxq->mem_pool->elt_size;
1444 rxq->mbuf_size -= (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM);
1445 hw->flbufsz = rxq->mbuf_size;
1447 rxq->rx_count = nb_desc;
1448 rxq->port_id = dev->data->port_id;
1449 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1450 rxq->crc_len = (uint8_t) ((dev->data->dev_conf.rxmode.hw_strip_crc) ? 0
1452 rxq->drop_en = rx_conf->rx_drop_en;
1455 * Allocate RX ring hardware descriptors. A memzone large enough to
1456 * handle the maximum ring size is allocated in order to allow for
1457 * resizing in later calls to the queue setup function.
1459 tz = ring_dma_zone_reserve(dev, "rx_ring", queue_idx,
1460 sizeof(struct nfp_net_rx_desc) *
1461 NFP_NET_MAX_RX_DESC, socket_id);
1464 RTE_LOG(ERR, PMD, "Error allocatig rx dma\n");
1465 nfp_net_rx_queue_release(rxq);
1469 /* Saving physical and virtual addresses for the RX ring */
1470 rxq->dma = (uint64_t)tz->phys_addr;
1471 rxq->rxds = (struct nfp_net_rx_desc *)tz->addr;
1473 /* mbuf pointers array for referencing mbufs linked to RX descriptors */
1474 rxq->rxbufs = rte_zmalloc_socket("rxq->rxbufs",
1475 sizeof(*rxq->rxbufs) * nb_desc,
1476 RTE_CACHE_LINE_SIZE, socket_id);
1477 if (rxq->rxbufs == NULL) {
1478 nfp_net_rx_queue_release(rxq);
1482 PMD_RX_LOG(DEBUG, "rxbufs=%p hw_ring=%p dma_addr=0x%" PRIx64 "\n",
1483 rxq->rxbufs, rxq->rxds, (unsigned long int)rxq->dma);
1485 nfp_net_reset_rx_queue(rxq);
1487 dev->data->rx_queues[queue_idx] = rxq;
1491 * Telling the HW about the physical address of the RX ring and number
1492 * of descriptors in log2 format
1494 nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(queue_idx), rxq->dma);
1495 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_SZ(queue_idx), log2(nb_desc));
1501 nfp_net_rx_fill_freelist(struct nfp_net_rxq *rxq)
1503 struct nfp_net_rx_buff *rxe = rxq->rxbufs;
1507 PMD_RX_LOG(DEBUG, "nfp_net_rx_fill_freelist for %u descriptors\n",
1510 for (i = 0; i < rxq->rx_count; i++) {
1511 struct nfp_net_rx_desc *rxd;
1512 struct rte_mbuf *mbuf = rte_pktmbuf_alloc(rxq->mem_pool);
1515 RTE_LOG(ERR, PMD, "RX mbuf alloc failed queue_id=%u\n",
1516 (unsigned)rxq->qidx);
1520 dma_addr = rte_cpu_to_le_64(RTE_MBUF_DMA_ADDR_DEFAULT(mbuf));
1522 rxd = &rxq->rxds[i];
1524 rxd->fld.dma_addr_hi = (dma_addr >> 32) & 0xff;
1525 rxd->fld.dma_addr_lo = dma_addr & 0xffffffff;
1527 PMD_RX_LOG(DEBUG, "[%d]: %" PRIx64 "\n", i, dma_addr);
1530 /* Make sure all writes are flushed before telling the hardware */
1533 /* Not advertising the whole ring as the firmware gets confused if so */
1534 PMD_RX_LOG(DEBUG, "Increment FL write pointer in %u\n",
1537 nfp_qcp_ptr_add(rxq->qcp_fl, NFP_QCP_WRITE_PTR, rxq->rx_count - 1);
1543 nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
1544 uint16_t nb_desc, unsigned int socket_id,
1545 const struct rte_eth_txconf *tx_conf)
1547 const struct rte_memzone *tz;
1548 struct nfp_net_txq *txq;
1549 uint16_t tx_free_thresh;
1550 struct nfp_net_hw *hw;
1552 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1554 PMD_INIT_FUNC_TRACE();
1556 /* Validating number of descriptors */
1557 if (((nb_desc * sizeof(struct nfp_net_tx_desc)) % 128) != 0 ||
1558 (nb_desc > NFP_NET_MAX_TX_DESC) ||
1559 (nb_desc < NFP_NET_MIN_TX_DESC)) {
1560 RTE_LOG(ERR, PMD, "Wrong nb_desc value\n");
1564 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
1565 tx_conf->tx_free_thresh :
1566 DEFAULT_TX_FREE_THRESH);
1568 if (tx_free_thresh > (nb_desc)) {
1570 "tx_free_thresh must be less than the number of TX "
1571 "descriptors. (tx_free_thresh=%u port=%d "
1572 "queue=%d)\n", (unsigned int)tx_free_thresh,
1573 (int)dev->data->port_id, (int)queue_idx);
1578 * Free memory prior to re-allocation if needed. This is the case after
1579 * calling nfp_net_stop
1581 if (dev->data->tx_queues[queue_idx]) {
1582 PMD_TX_LOG(DEBUG, "Freeing memory prior to re-allocation %d\n",
1584 nfp_net_tx_queue_release(dev->data->tx_queues[queue_idx]);
1585 dev->data->tx_queues[queue_idx] = NULL;
1588 /* Allocating tx queue data structure */
1589 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nfp_net_txq),
1590 RTE_CACHE_LINE_SIZE, socket_id);
1592 RTE_LOG(ERR, PMD, "Error allocating tx dma\n");
1597 * Allocate TX ring hardware descriptors. A memzone large enough to
1598 * handle the maximum ring size is allocated in order to allow for
1599 * resizing in later calls to the queue setup function.
1601 tz = ring_dma_zone_reserve(dev, "tx_ring", queue_idx,
1602 sizeof(struct nfp_net_tx_desc) *
1603 NFP_NET_MAX_TX_DESC, socket_id);
1605 RTE_LOG(ERR, PMD, "Error allocating tx dma\n");
1606 nfp_net_tx_queue_release(txq);
1610 txq->tx_count = nb_desc;
1611 txq->tx_free_thresh = tx_free_thresh;
1612 txq->tx_pthresh = tx_conf->tx_thresh.pthresh;
1613 txq->tx_hthresh = tx_conf->tx_thresh.hthresh;
1614 txq->tx_wthresh = tx_conf->tx_thresh.wthresh;
1616 /* queue mapping based on firmware configuration */
1617 txq->qidx = queue_idx;
1618 txq->tx_qcidx = queue_idx * hw->stride_tx;
1619 txq->qcp_q = hw->tx_bar + NFP_QCP_QUEUE_OFF(txq->tx_qcidx);
1621 txq->port_id = dev->data->port_id;
1622 txq->txq_flags = tx_conf->txq_flags;
1624 /* Saving physical and virtual addresses for the TX ring */
1625 txq->dma = (uint64_t)tz->phys_addr;
1626 txq->txds = (struct nfp_net_tx_desc *)tz->addr;
1628 /* mbuf pointers array for referencing mbufs linked to TX descriptors */
1629 txq->txbufs = rte_zmalloc_socket("txq->txbufs",
1630 sizeof(*txq->txbufs) * nb_desc,
1631 RTE_CACHE_LINE_SIZE, socket_id);
1632 if (txq->txbufs == NULL) {
1633 nfp_net_tx_queue_release(txq);
1636 PMD_TX_LOG(DEBUG, "txbufs=%p hw_ring=%p dma_addr=0x%" PRIx64 "\n",
1637 txq->txbufs, txq->txds, (unsigned long int)txq->dma);
1639 nfp_net_reset_tx_queue(txq);
1641 dev->data->tx_queues[queue_idx] = txq;
1645 * Telling the HW about the physical address of the TX ring and number
1646 * of descriptors in log2 format
1648 nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(queue_idx), txq->dma);
1649 nn_cfg_writeb(hw, NFP_NET_CFG_TXR_SZ(queue_idx), log2(nb_desc));
1654 /* nfp_net_tx_tso - Set TX descriptor for TSO */
1656 nfp_net_tx_tso(struct nfp_net_txq *txq, struct nfp_net_tx_desc *txd,
1657 struct rte_mbuf *mb)
1660 struct nfp_net_hw *hw = txq->hw;
1662 if (!(hw->cap & NFP_NET_CFG_CTRL_LSO))
1665 ol_flags = mb->ol_flags;
1667 if (!(ol_flags & PKT_TX_TCP_SEG))
1670 txd->l4_offset = mb->l2_len + mb->l3_len + mb->l4_len;
1671 txd->lso = rte_cpu_to_le_16(mb->tso_segsz);
1672 txd->flags |= PCIE_DESC_TX_LSO;
1675 /* nfp_net_tx_cksum - Set TX CSUM offload flags in TX descriptor */
1677 nfp_net_tx_cksum(struct nfp_net_txq *txq, struct nfp_net_tx_desc *txd,
1678 struct rte_mbuf *mb)
1681 struct nfp_net_hw *hw = txq->hw;
1683 if (!(hw->cap & NFP_NET_CFG_CTRL_TXCSUM))
1686 ol_flags = mb->ol_flags;
1688 /* IPv6 does not need checksum */
1689 if (ol_flags & PKT_TX_IP_CKSUM)
1690 txd->flags |= PCIE_DESC_TX_IP4_CSUM;
1692 switch (ol_flags & PKT_TX_L4_MASK) {
1693 case PKT_TX_UDP_CKSUM:
1694 txd->flags |= PCIE_DESC_TX_UDP_CSUM;
1696 case PKT_TX_TCP_CKSUM:
1697 txd->flags |= PCIE_DESC_TX_TCP_CSUM;
1701 if (ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK))
1702 txd->flags |= PCIE_DESC_TX_CSUM;
1705 /* nfp_net_rx_cksum - set mbuf checksum flags based on RX descriptor flags */
1707 nfp_net_rx_cksum(struct nfp_net_rxq *rxq, struct nfp_net_rx_desc *rxd,
1708 struct rte_mbuf *mb)
1710 struct nfp_net_hw *hw = rxq->hw;
1712 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RXCSUM))
1715 /* If IPv4 and IP checksum error, fail */
1716 if ((rxd->rxd.flags & PCIE_DESC_RX_IP4_CSUM) &&
1717 !(rxd->rxd.flags & PCIE_DESC_RX_IP4_CSUM_OK))
1718 mb->ol_flags |= PKT_RX_IP_CKSUM_BAD;
1720 /* If neither UDP nor TCP return */
1721 if (!(rxd->rxd.flags & PCIE_DESC_RX_TCP_CSUM) &&
1722 !(rxd->rxd.flags & PCIE_DESC_RX_UDP_CSUM))
1725 if ((rxd->rxd.flags & PCIE_DESC_RX_TCP_CSUM) &&
1726 !(rxd->rxd.flags & PCIE_DESC_RX_TCP_CSUM_OK))
1727 mb->ol_flags |= PKT_RX_L4_CKSUM_BAD;
1729 if ((rxd->rxd.flags & PCIE_DESC_RX_UDP_CSUM) &&
1730 !(rxd->rxd.flags & PCIE_DESC_RX_UDP_CSUM_OK))
1731 mb->ol_flags |= PKT_RX_L4_CKSUM_BAD;
1734 #define NFP_HASH_OFFSET ((uint8_t *)mbuf->buf_addr + mbuf->data_off - 4)
1735 #define NFP_HASH_TYPE_OFFSET ((uint8_t *)mbuf->buf_addr + mbuf->data_off - 8)
1738 * nfp_net_set_hash - Set mbuf hash data
1740 * The RSS hash and hash-type are pre-pended to the packet data.
1741 * Extract and decode it and set the mbuf fields.
1744 nfp_net_set_hash(struct nfp_net_rxq *rxq, struct nfp_net_rx_desc *rxd,
1745 struct rte_mbuf *mbuf)
1749 struct nfp_net_hw *hw = rxq->hw;
1751 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1754 if (!(rxd->rxd.flags & PCIE_DESC_RX_RSS))
1757 hash = rte_be_to_cpu_32(*(uint32_t *)NFP_HASH_OFFSET);
1758 hash_type = rte_be_to_cpu_32(*(uint32_t *)NFP_HASH_TYPE_OFFSET);
1760 mbuf->hash.rss = hash;
1761 mbuf->ol_flags |= PKT_RX_RSS_HASH;
1763 switch (hash_type) {
1764 case NFP_NET_RSS_IPV4:
1765 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV4;
1767 case NFP_NET_RSS_IPV6:
1768 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6;
1770 case NFP_NET_RSS_IPV6_EX:
1771 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6_EXT;
1774 mbuf->packet_type |= RTE_PTYPE_INNER_L4_MASK;
1779 nfp_net_mbuf_alloc_failed(struct nfp_net_rxq *rxq)
1781 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
1784 #define NFP_DESC_META_LEN(d) (d->rxd.meta_len_dd & PCIE_DESC_RX_META_LEN_MASK)
1789 * There are some decissions to take:
1790 * 1) How to check DD RX descriptors bit
1791 * 2) How and when to allocate new mbufs
1793 * Current implementation checks just one single DD bit each loop. As each
1794 * descriptor is 8 bytes, it is likely a good idea to check descriptors in
1795 * a single cache line instead. Tests with this change have not shown any
1796 * performance improvement but it requires further investigation. For example,
1797 * depending on which descriptor is next, the number of descriptors could be
1798 * less than 8 for just checking those in the same cache line. This implies
1799 * extra work which could be counterproductive by itself. Indeed, last firmware
1800 * changes are just doing this: writing several descriptors with the DD bit
1801 * for saving PCIe bandwidth and DMA operations from the NFP.
1803 * Mbuf allocation is done when a new packet is received. Then the descriptor
1804 * is automatically linked with the new mbuf and the old one is given to the
1805 * user. The main drawback with this design is mbuf allocation is heavier than
1806 * using bulk allocations allowed by DPDK with rte_mempool_get_bulk. From the
1807 * cache point of view it does not seem allocating the mbuf early on as we are
1808 * doing now have any benefit at all. Again, tests with this change have not
1809 * shown any improvement. Also, rte_mempool_get_bulk returns all or nothing
1810 * so looking at the implications of this type of allocation should be studied
1815 nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
1817 struct nfp_net_rxq *rxq;
1818 struct nfp_net_rx_desc *rxds;
1819 struct nfp_net_rx_buff *rxb;
1820 struct nfp_net_hw *hw;
1821 struct rte_mbuf *mb;
1822 struct rte_mbuf *new_mb;
1828 if (unlikely(rxq == NULL)) {
1830 * DPDK just checks the queue is lower than max queues
1831 * enabled. But the queue needs to be configured
1833 RTE_LOG_DP(ERR, PMD, "RX Bad queue\n");
1841 while (avail < nb_pkts) {
1842 rxb = &rxq->rxbufs[rxq->rd_p];
1843 if (unlikely(rxb == NULL)) {
1844 RTE_LOG_DP(ERR, PMD, "rxb does not exist!\n");
1849 * Memory barrier to ensure that we won't do other
1850 * reads before the DD bit.
1854 rxds = &rxq->rxds[rxq->rd_p];
1855 if ((rxds->rxd.meta_len_dd & PCIE_DESC_RX_DD) == 0)
1859 * We got a packet. Let's alloc a new mbuff for refilling the
1860 * free descriptor ring as soon as possible
1862 new_mb = rte_pktmbuf_alloc(rxq->mem_pool);
1863 if (unlikely(new_mb == NULL)) {
1864 RTE_LOG_DP(DEBUG, PMD, "RX mbuf alloc failed port_id=%u "
1865 "queue_id=%u\n", (unsigned)rxq->port_id,
1866 (unsigned)rxq->qidx);
1867 nfp_net_mbuf_alloc_failed(rxq);
1874 * Grab the mbuff and refill the descriptor with the
1875 * previously allocated mbuff
1880 PMD_RX_LOG(DEBUG, "Packet len: %u, mbuf_size: %u\n",
1881 rxds->rxd.data_len, rxq->mbuf_size);
1883 /* Size of this segment */
1884 mb->data_len = rxds->rxd.data_len - NFP_DESC_META_LEN(rxds);
1885 /* Size of the whole packet. We just support 1 segment */
1886 mb->pkt_len = rxds->rxd.data_len - NFP_DESC_META_LEN(rxds);
1888 if (unlikely((mb->data_len + hw->rx_offset) >
1891 * This should not happen and the user has the
1892 * responsibility of avoiding it. But we have
1893 * to give some info about the error
1895 RTE_LOG_DP(ERR, PMD,
1896 "mbuf overflow likely due to the RX offset.\n"
1897 "\t\tYour mbuf size should have extra space for"
1898 " RX offset=%u bytes.\n"
1899 "\t\tCurrently you just have %u bytes available"
1900 " but the received packet is %u bytes long",
1902 rxq->mbuf_size - hw->rx_offset,
1907 /* Filling the received mbuff with packet info */
1909 mb->data_off = RTE_PKTMBUF_HEADROOM + hw->rx_offset;
1911 mb->data_off = RTE_PKTMBUF_HEADROOM +
1912 NFP_DESC_META_LEN(rxds);
1914 /* No scatter mode supported */
1918 /* Checking the RSS flag */
1919 nfp_net_set_hash(rxq, rxds, mb);
1921 /* Checking the checksum flag */
1922 nfp_net_rx_cksum(rxq, rxds, mb);
1924 if ((rxds->rxd.flags & PCIE_DESC_RX_VLAN) &&
1925 (hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN)) {
1926 mb->vlan_tci = rte_cpu_to_le_32(rxds->rxd.vlan);
1927 mb->ol_flags |= PKT_RX_VLAN_PKT | PKT_RX_VLAN_STRIPPED;
1930 /* Adding the mbuff to the mbuff array passed by the app */
1931 rx_pkts[avail++] = mb;
1933 /* Now resetting and updating the descriptor */
1936 dma_addr = rte_cpu_to_le_64(RTE_MBUF_DMA_ADDR_DEFAULT(new_mb));
1938 rxds->fld.dma_addr_hi = (dma_addr >> 32) & 0xff;
1939 rxds->fld.dma_addr_lo = dma_addr & 0xffffffff;
1942 if (unlikely(rxq->rd_p == rxq->rx_count)) /* wrapping?*/
1949 PMD_RX_LOG(DEBUG, "RX port_id=%u queue_id=%u, %d packets received\n",
1950 (unsigned)rxq->port_id, (unsigned)rxq->qidx, nb_hold);
1952 nb_hold += rxq->nb_rx_hold;
1955 * FL descriptors needs to be written before incrementing the
1956 * FL queue WR pointer
1959 if (nb_hold > rxq->rx_free_thresh) {
1960 PMD_RX_LOG(DEBUG, "port=%u queue=%u nb_hold=%u avail=%u\n",
1961 (unsigned)rxq->port_id, (unsigned)rxq->qidx,
1962 (unsigned)nb_hold, (unsigned)avail);
1963 nfp_qcp_ptr_add(rxq->qcp_fl, NFP_QCP_WRITE_PTR, nb_hold);
1966 rxq->nb_rx_hold = nb_hold;
1972 * nfp_net_tx_free_bufs - Check for descriptors with a complete
1974 * @txq: TX queue to work with
1975 * Returns number of descriptors freed
1978 nfp_net_tx_free_bufs(struct nfp_net_txq *txq)
1983 PMD_TX_LOG(DEBUG, "queue %u. Check for descriptor with a complete"
1984 " status\n", txq->qidx);
1986 /* Work out how many packets have been sent */
1987 qcp_rd_p = nfp_qcp_read(txq->qcp_q, NFP_QCP_READ_PTR);
1989 if (qcp_rd_p == txq->rd_p) {
1990 PMD_TX_LOG(DEBUG, "queue %u: It seems harrier is not sending "
1991 "packets (%u, %u)\n", txq->qidx,
1992 qcp_rd_p, txq->rd_p);
1996 if (qcp_rd_p > txq->rd_p)
1997 todo = qcp_rd_p - txq->rd_p;
1999 todo = qcp_rd_p + txq->tx_count - txq->rd_p;
2001 PMD_TX_LOG(DEBUG, "qcp_rd_p %u, txq->rd_p: %u, qcp->rd_p: %u\n",
2002 qcp_rd_p, txq->rd_p, txq->rd_p);
2008 if (unlikely(txq->rd_p >= txq->tx_count))
2009 txq->rd_p -= txq->tx_count;
2014 /* Leaving always free descriptors for avoiding wrapping confusion */
2016 uint32_t nfp_free_tx_desc(struct nfp_net_txq *txq)
2018 if (txq->wr_p >= txq->rd_p)
2019 return txq->tx_count - (txq->wr_p - txq->rd_p) - 8;
2021 return txq->rd_p - txq->wr_p - 8;
2025 * nfp_net_txq_full - Check if the TX queue free descriptors
2026 * is below tx_free_threshold
2028 * @txq: TX queue to check
2030 * This function uses the host copy* of read/write pointers
2033 uint32_t nfp_net_txq_full(struct nfp_net_txq *txq)
2035 return (nfp_free_tx_desc(txq) < txq->tx_free_thresh);
2039 nfp_net_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2041 struct nfp_net_txq *txq;
2042 struct nfp_net_hw *hw;
2043 struct nfp_net_tx_desc *txds, txd;
2044 struct rte_mbuf *pkt;
2046 int pkt_size, dma_size;
2047 uint16_t free_descs, issued_descs;
2048 struct rte_mbuf **lmbuf;
2053 txds = &txq->txds[txq->wr_p];
2055 PMD_TX_LOG(DEBUG, "working for queue %u at pos %d and %u packets\n",
2056 txq->qidx, txq->wr_p, nb_pkts);
2058 if ((nfp_free_tx_desc(txq) < nb_pkts) || (nfp_net_txq_full(txq)))
2059 nfp_net_tx_free_bufs(txq);
2061 free_descs = (uint16_t)nfp_free_tx_desc(txq);
2062 if (unlikely(free_descs == 0))
2069 PMD_TX_LOG(DEBUG, "queue: %u. Sending %u packets\n",
2070 txq->qidx, nb_pkts);
2071 /* Sending packets */
2072 while ((i < nb_pkts) && free_descs) {
2073 /* Grabbing the mbuf linked to the current descriptor */
2074 lmbuf = &txq->txbufs[txq->wr_p].mbuf;
2075 /* Warming the cache for releasing the mbuf later on */
2076 RTE_MBUF_PREFETCH_TO_FREE(*lmbuf);
2078 pkt = *(tx_pkts + i);
2080 if (unlikely((pkt->nb_segs > 1) &&
2081 !(hw->cap & NFP_NET_CFG_CTRL_GATHER))) {
2082 PMD_INIT_LOG(INFO, "NFP_NET_CFG_CTRL_GATHER not set");
2083 rte_panic("Multisegment packet unsupported\n");
2086 /* Checking if we have enough descriptors */
2087 if (unlikely(pkt->nb_segs > free_descs))
2091 * Checksum and VLAN flags just in the first descriptor for a
2092 * multisegment packet, but TSO info needs to be in all of them.
2094 nfp_net_tx_tso(txq, &txd, pkt);
2095 nfp_net_tx_cksum(txq, &txd, pkt);
2097 if ((pkt->ol_flags & PKT_TX_VLAN_PKT) &&
2098 (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)) {
2099 txd.flags |= PCIE_DESC_TX_VLAN;
2100 txd.vlan = pkt->vlan_tci;
2104 * mbuf data_len is the data in one segment and pkt_len data
2105 * in the whole packet. When the packet is just one segment,
2106 * then data_len = pkt_len
2108 pkt_size = pkt->pkt_len;
2110 /* Releasing mbuf which was prefetched above */
2112 rte_pktmbuf_free(*lmbuf);
2114 * Linking mbuf with descriptor for being released
2115 * next time descriptor is used
2120 /* Copying TSO, VLAN and cksum info */
2122 dma_size = pkt->data_len;
2123 dma_addr = rte_mbuf_data_dma_addr(pkt);
2124 PMD_TX_LOG(DEBUG, "Working with mbuf at dma address:"
2125 "%" PRIx64 "\n", dma_addr);
2127 /* Filling descriptors fields */
2128 txds->dma_len = dma_size;
2129 txds->data_len = pkt->pkt_len;
2130 txds->dma_addr_hi = (dma_addr >> 32) & 0xff;
2131 txds->dma_addr_lo = (dma_addr & 0xffffffff);
2132 ASSERT(free_descs > 0);
2136 if (unlikely(txq->wr_p == txq->tx_count)) /* wrapping?*/
2139 pkt_size -= dma_size;
2142 txds->offset_eop |= PCIE_DESC_TX_EOP;
2144 txds->offset_eop &= PCIE_DESC_TX_OFFSET_MASK;
2147 /* Referencing next free TX descriptor */
2148 txds = &txq->txds[txq->wr_p];
2155 /* Increment write pointers. Force memory write before we let HW know */
2157 nfp_qcp_ptr_add(txq->qcp_q, NFP_QCP_WRITE_PTR, issued_descs);
2163 nfp_net_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2165 uint32_t new_ctrl, update;
2166 struct nfp_net_hw *hw;
2168 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2171 if ((mask & ETH_VLAN_FILTER_OFFLOAD) ||
2172 (mask & ETH_VLAN_EXTEND_OFFLOAD))
2173 RTE_LOG(INFO, PMD, "No support for ETH_VLAN_FILTER_OFFLOAD or"
2174 " ETH_VLAN_EXTEND_OFFLOAD");
2176 /* Enable vlan strip if it is not configured yet */
2177 if ((mask & ETH_VLAN_STRIP_OFFLOAD) &&
2178 !(hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
2179 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_RXVLAN;
2181 /* Disable vlan strip just if it is configured */
2182 if (!(mask & ETH_VLAN_STRIP_OFFLOAD) &&
2183 (hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
2184 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_RXVLAN;
2189 update = NFP_NET_CFG_UPDATE_GEN;
2191 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
2194 hw->ctrl = new_ctrl;
2197 /* Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device */
2199 nfp_net_reta_update(struct rte_eth_dev *dev,
2200 struct rte_eth_rss_reta_entry64 *reta_conf,
2203 uint32_t reta, mask;
2207 struct nfp_net_hw *hw =
2208 NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2210 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
2213 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
2214 RTE_LOG(ERR, PMD, "The size of hash lookup table configured "
2215 "(%d) doesn't match the number hardware can supported "
2216 "(%d)\n", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
2221 * Update Redirection Table. There are 128 8bit-entries which can be
2222 * manage as 32 32bit-entries
2224 for (i = 0; i < reta_size; i += 4) {
2225 /* Handling 4 RSS entries per loop */
2226 idx = i / RTE_RETA_GROUP_SIZE;
2227 shift = i % RTE_RETA_GROUP_SIZE;
2228 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
2234 /* If all 4 entries were set, don't need read RETA register */
2236 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + i);
2238 for (j = 0; j < 4; j++) {
2239 if (!(mask & (0x1 << j)))
2242 /* Clearing the entry bits */
2243 reta &= ~(0xFF << (8 * j));
2244 reta |= reta_conf[idx].reta[shift + j] << (8 * j);
2246 nn_cfg_writel(hw, NFP_NET_CFG_RSS_ITBL + shift, reta);
2249 update = NFP_NET_CFG_UPDATE_RSS;
2251 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
2257 /* Query Redirection Table(RETA) of Receive Side Scaling of Ethernet device. */
2259 nfp_net_reta_query(struct rte_eth_dev *dev,
2260 struct rte_eth_rss_reta_entry64 *reta_conf,
2266 struct nfp_net_hw *hw;
2268 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2270 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
2273 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
2274 RTE_LOG(ERR, PMD, "The size of hash lookup table configured "
2275 "(%d) doesn't match the number hardware can supported "
2276 "(%d)\n", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
2281 * Reading Redirection Table. There are 128 8bit-entries which can be
2282 * manage as 32 32bit-entries
2284 for (i = 0; i < reta_size; i += 4) {
2285 /* Handling 4 RSS entries per loop */
2286 idx = i / RTE_RETA_GROUP_SIZE;
2287 shift = i % RTE_RETA_GROUP_SIZE;
2288 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
2293 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + shift);
2294 for (j = 0; j < 4; j++) {
2295 if (!(mask & (0x1 << j)))
2297 reta_conf->reta[shift + j] =
2298 (uint8_t)((reta >> (8 * j)) & 0xF);
2305 nfp_net_rss_hash_update(struct rte_eth_dev *dev,
2306 struct rte_eth_rss_conf *rss_conf)
2309 uint32_t cfg_rss_ctrl = 0;
2313 struct nfp_net_hw *hw;
2315 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2317 rss_hf = rss_conf->rss_hf;
2319 /* Checking if RSS is enabled */
2320 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS)) {
2321 if (rss_hf != 0) { /* Enable RSS? */
2322 RTE_LOG(ERR, PMD, "RSS unsupported\n");
2325 return 0; /* Nothing to do */
2328 if (rss_conf->rss_key_len > NFP_NET_CFG_RSS_KEY_SZ) {
2329 RTE_LOG(ERR, PMD, "hash key too long\n");
2333 if (rss_hf & ETH_RSS_IPV4)
2334 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4 |
2335 NFP_NET_CFG_RSS_IPV4_TCP |
2336 NFP_NET_CFG_RSS_IPV4_UDP;
2338 if (rss_hf & ETH_RSS_IPV6)
2339 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6 |
2340 NFP_NET_CFG_RSS_IPV6_TCP |
2341 NFP_NET_CFG_RSS_IPV6_UDP;
2343 /* configuring where to apply the RSS hash */
2344 nn_cfg_writel(hw, NFP_NET_CFG_RSS_CTRL, cfg_rss_ctrl);
2346 /* Writing the key byte a byte */
2347 for (i = 0; i < rss_conf->rss_key_len; i++) {
2348 memcpy(&key, &rss_conf->rss_key[i], 1);
2349 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY + i, key);
2352 /* Writing the key size */
2353 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY_SZ, rss_conf->rss_key_len);
2355 update = NFP_NET_CFG_UPDATE_RSS;
2357 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
2364 nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev,
2365 struct rte_eth_rss_conf *rss_conf)
2368 uint32_t cfg_rss_ctrl;
2371 struct nfp_net_hw *hw;
2373 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2375 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
2378 rss_hf = rss_conf->rss_hf;
2379 cfg_rss_ctrl = nn_cfg_readl(hw, NFP_NET_CFG_RSS_CTRL);
2381 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4)
2382 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV4_UDP;
2384 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_TCP)
2385 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
2387 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_TCP)
2388 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
2390 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_UDP)
2391 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
2393 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_UDP)
2394 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
2396 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6)
2397 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
2399 /* Reading the key size */
2400 rss_conf->rss_key_len = nn_cfg_readl(hw, NFP_NET_CFG_RSS_KEY_SZ);
2402 /* Reading the key byte a byte */
2403 for (i = 0; i < rss_conf->rss_key_len; i++) {
2404 key = nn_cfg_readb(hw, NFP_NET_CFG_RSS_KEY + i);
2405 memcpy(&rss_conf->rss_key[i], &key, 1);
2411 /* Initialise and register driver with DPDK Application */
2412 static const struct eth_dev_ops nfp_net_eth_dev_ops = {
2413 .dev_configure = nfp_net_configure,
2414 .dev_start = nfp_net_start,
2415 .dev_stop = nfp_net_stop,
2416 .dev_close = nfp_net_close,
2417 .promiscuous_enable = nfp_net_promisc_enable,
2418 .promiscuous_disable = nfp_net_promisc_disable,
2419 .link_update = nfp_net_link_update,
2420 .stats_get = nfp_net_stats_get,
2421 .stats_reset = nfp_net_stats_reset,
2422 .dev_infos_get = nfp_net_infos_get,
2423 .dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
2424 .mtu_set = nfp_net_dev_mtu_set,
2425 .vlan_offload_set = nfp_net_vlan_offload_set,
2426 .reta_update = nfp_net_reta_update,
2427 .reta_query = nfp_net_reta_query,
2428 .rss_hash_update = nfp_net_rss_hash_update,
2429 .rss_hash_conf_get = nfp_net_rss_hash_conf_get,
2430 .rx_queue_setup = nfp_net_rx_queue_setup,
2431 .rx_queue_release = nfp_net_rx_queue_release,
2432 .rx_queue_count = nfp_net_rx_queue_count,
2433 .tx_queue_setup = nfp_net_tx_queue_setup,
2434 .tx_queue_release = nfp_net_tx_queue_release,
2435 .rx_queue_intr_enable = nfp_rx_queue_intr_enable,
2436 .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
2440 nfp_net_init(struct rte_eth_dev *eth_dev)
2442 struct rte_pci_device *pci_dev;
2443 struct nfp_net_hw *hw;
2445 uint32_t tx_bar_off, rx_bar_off;
2449 PMD_INIT_FUNC_TRACE();
2451 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2453 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
2454 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
2455 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
2457 /* For secondary processes, the primary has done all the work */
2458 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2461 pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
2462 rte_eth_copy_pci_info(eth_dev, pci_dev);
2463 eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE;
2465 hw->device_id = pci_dev->id.device_id;
2466 hw->vendor_id = pci_dev->id.vendor_id;
2467 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2468 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2470 PMD_INIT_LOG(DEBUG, "nfp_net: device (%u:%u) %u:%u:%u:%u",
2471 pci_dev->id.vendor_id, pci_dev->id.device_id,
2472 pci_dev->addr.domain, pci_dev->addr.bus,
2473 pci_dev->addr.devid, pci_dev->addr.function);
2475 hw->ctrl_bar = (uint8_t *)pci_dev->mem_resource[0].addr;
2476 if (hw->ctrl_bar == NULL) {
2478 "hw->ctrl_bar is NULL. BAR0 not configured\n");
2481 hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
2482 hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
2484 /* Work out where in the BAR the queues start. */
2485 switch (pci_dev->id.device_id) {
2486 case PCI_DEVICE_ID_NFP6000_VF_NIC:
2487 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
2488 tx_bar_off = NFP_PCIE_QUEUE(start_q);
2489 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ);
2490 rx_bar_off = NFP_PCIE_QUEUE(start_q);
2493 RTE_LOG(ERR, PMD, "nfp_net: no device ID matching\n");
2497 PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%08x", tx_bar_off);
2498 PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%08x", rx_bar_off);
2500 hw->tx_bar = (uint8_t *)pci_dev->mem_resource[2].addr + tx_bar_off;
2501 hw->rx_bar = (uint8_t *)pci_dev->mem_resource[2].addr + rx_bar_off;
2503 PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p",
2504 hw->ctrl_bar, hw->tx_bar, hw->rx_bar);
2506 nfp_net_cfg_queue_setup(hw);
2508 /* Get some of the read-only fields from the config BAR */
2509 hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
2510 hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
2511 hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
2512 hw->mtu = hw->max_mtu;
2514 if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
2515 hw->rx_offset = NFP_NET_RX_OFFSET;
2517 hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
2519 PMD_INIT_LOG(INFO, "VER: %#x, Maximum supported MTU: %d",
2520 hw->ver, hw->max_mtu);
2521 PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s", hw->cap,
2522 hw->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "",
2523 hw->cap & NFP_NET_CFG_CTRL_RXCSUM ? "RXCSUM " : "",
2524 hw->cap & NFP_NET_CFG_CTRL_TXCSUM ? "TXCSUM " : "",
2525 hw->cap & NFP_NET_CFG_CTRL_RXVLAN ? "RXVLAN " : "",
2526 hw->cap & NFP_NET_CFG_CTRL_TXVLAN ? "TXVLAN " : "",
2527 hw->cap & NFP_NET_CFG_CTRL_SCATTER ? "SCATTER " : "",
2528 hw->cap & NFP_NET_CFG_CTRL_GATHER ? "GATHER " : "",
2529 hw->cap & NFP_NET_CFG_CTRL_LSO ? "TSO " : "",
2530 hw->cap & NFP_NET_CFG_CTRL_RSS ? "RSS " : "");
2534 hw->stride_rx = stride;
2535 hw->stride_tx = stride;
2537 PMD_INIT_LOG(INFO, "max_rx_queues: %u, max_tx_queues: %u",
2538 hw->max_rx_queues, hw->max_tx_queues);
2540 /* Initializing spinlock for reconfigs */
2541 rte_spinlock_init(&hw->reconfig_lock);
2543 /* Allocating memory for mac addr */
2544 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr", ETHER_ADDR_LEN, 0);
2545 if (eth_dev->data->mac_addrs == NULL) {
2546 PMD_INIT_LOG(ERR, "Failed to space for MAC address");
2550 nfp_net_read_mac(hw);
2552 if (!is_valid_assigned_ether_addr((struct ether_addr *)&hw->mac_addr))
2553 /* Using random mac addresses for VFs */
2554 eth_random_addr(&hw->mac_addr[0]);
2556 /* Copying mac address to DPDK eth_dev struct */
2557 ether_addr_copy((struct ether_addr *)hw->mac_addr,
2558 ð_dev->data->mac_addrs[0]);
2560 PMD_INIT_LOG(INFO, "port %d VendorID=0x%x DeviceID=0x%x "
2561 "mac=%02x:%02x:%02x:%02x:%02x:%02x",
2562 eth_dev->data->port_id, pci_dev->id.vendor_id,
2563 pci_dev->id.device_id,
2564 hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
2565 hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
2567 /* Registering LSC interrupt handler */
2568 rte_intr_callback_register(&pci_dev->intr_handle,
2569 nfp_net_dev_interrupt_handler,
2572 /* Telling the firmware about the LSC interrupt entry */
2573 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, NFP_NET_IRQ_LSC_IDX);
2575 /* Recording current stats counters values */
2576 nfp_net_stats_reset(eth_dev);
2581 static const struct rte_pci_id pci_id_nfp_net_map[] = {
2583 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2584 PCI_DEVICE_ID_NFP6000_PF_NIC)
2587 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2588 PCI_DEVICE_ID_NFP6000_VF_NIC)
2595 static struct eth_driver rte_nfp_net_pmd = {
2597 .id_table = pci_id_nfp_net_map,
2598 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2599 .probe = rte_eth_dev_pci_probe,
2600 .remove = rte_eth_dev_pci_remove,
2602 .eth_dev_init = nfp_net_init,
2603 .dev_private_size = sizeof(struct nfp_net_adapter),
2606 RTE_PMD_REGISTER_PCI(net_nfp, rte_nfp_net_pmd.pci_drv);
2607 RTE_PMD_REGISTER_PCI_TABLE(net_nfp, pci_id_nfp_net_map);
2608 RTE_PMD_REGISTER_KMOD_DEP(net_nfp, "* igb_uio | uio_pci_generic | vfio");
2612 * c-file-style: "Linux"
2613 * indent-tabs-mode: t