1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2014-2018 Netronome Systems, Inc.
5 * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
9 * vim:shiftwidth=8:noexpandtab
11 * @file dpdk/pmd/nfp_net.c
13 * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
16 #include <rte_byteorder.h>
17 #include <rte_common.h>
19 #include <rte_debug.h>
20 #include <ethdev_driver.h>
21 #include <ethdev_pci.h>
23 #include <rte_ether.h>
24 #include <rte_malloc.h>
25 #include <rte_memzone.h>
26 #include <rte_mempool.h>
27 #include <rte_version.h>
28 #include <rte_string_fns.h>
29 #include <rte_alarm.h>
30 #include <rte_spinlock.h>
31 #include <rte_service_component.h>
33 #include "eal_firmware.h"
35 #include "nfpcore/nfp_cpp.h"
36 #include "nfpcore/nfp_nffw.h"
37 #include "nfpcore/nfp_hwinfo.h"
38 #include "nfpcore/nfp_mip.h"
39 #include "nfpcore/nfp_rtsym.h"
40 #include "nfpcore/nfp_nsp.h"
42 #include "nfp_net_pmd.h"
44 #include "nfp_net_logs.h"
45 #include "nfp_net_ctrl.h"
46 #include "nfp_cpp_bridge.h"
48 #include <sys/types.h>
49 #include <sys/socket.h>
53 #include <sys/ioctl.h>
57 static int nfp_net_close(struct rte_eth_dev *dev);
58 static int nfp_net_init(struct rte_eth_dev *eth_dev);
59 static int nfp_pf_init(struct rte_pci_device *pci_dev);
60 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
61 static int nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port);
62 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
63 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
64 static int nfp_net_stop(struct rte_eth_dev *dev);
65 static int nfp_fw_setup(struct rte_pci_device *dev,
67 struct nfp_eth_table *nfp_eth_table,
68 struct nfp_hwinfo *hwinfo);
71 __nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t update)
77 PMD_DRV_LOG(DEBUG, "Writing to the configuration queue (%p)...",
80 if (hw->qcp_cfg == NULL)
81 rte_panic("Bad configuration queue pointer\n");
83 nfp_qcp_ptr_add(hw->qcp_cfg, NFP_QCP_WRITE_PTR, 1);
86 wait.tv_nsec = 1000000;
88 PMD_DRV_LOG(DEBUG, "Polling for update ack...");
90 /* Poll update field, waiting for NFP to ack the config */
91 for (cnt = 0; ; cnt++) {
92 new = nn_cfg_readl(hw, NFP_NET_CFG_UPDATE);
95 if (new & NFP_NET_CFG_UPDATE_ERR) {
96 PMD_INIT_LOG(ERR, "Reconfig error: 0x%08x", new);
99 if (cnt >= NFP_NET_POLL_TIMEOUT) {
100 PMD_INIT_LOG(ERR, "Reconfig timeout for 0x%08x after"
101 " %dms", update, cnt);
102 rte_panic("Exiting\n");
104 nanosleep(&wait, 0); /* waiting for a 1ms */
106 PMD_DRV_LOG(DEBUG, "Ack DONE");
111 * Reconfigure the NIC
112 * @nn: device to reconfigure
113 * @ctrl: The value for the ctrl field in the BAR config
114 * @update: The value for the update field in the BAR config
116 * Write the update word to the BAR and ping the reconfig queue. Then poll
117 * until the firmware has acknowledged the update by zeroing the update word.
120 nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update)
124 PMD_DRV_LOG(DEBUG, "nfp_net_reconfig: ctrl=%08x update=%08x",
127 rte_spinlock_lock(&hw->reconfig_lock);
129 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, ctrl);
130 nn_cfg_writel(hw, NFP_NET_CFG_UPDATE, update);
134 err = __nfp_net_reconfig(hw, update);
136 rte_spinlock_unlock(&hw->reconfig_lock);
142 * Reconfig errors imply situations where they can be handled.
143 * Otherwise, rte_panic is called inside __nfp_net_reconfig
145 PMD_INIT_LOG(ERR, "Error nfp_net reconfig for ctrl: %x update: %x",
151 * Configure an Ethernet device. This function must be invoked first
152 * before any other function in the Ethernet API. This function can
153 * also be re-invoked when a device is in the stopped state.
156 nfp_net_configure(struct rte_eth_dev *dev)
158 struct rte_eth_conf *dev_conf;
159 struct rte_eth_rxmode *rxmode;
160 struct rte_eth_txmode *txmode;
161 struct nfp_net_hw *hw;
163 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
166 * A DPDK app sends info about how many queues to use and how
167 * those queues need to be configured. This is used by the
168 * DPDK core and it makes sure no more queues than those
169 * advertised by the driver are requested. This function is
170 * called after that internal process
173 PMD_INIT_LOG(DEBUG, "Configure");
175 dev_conf = &dev->data->dev_conf;
176 rxmode = &dev_conf->rxmode;
177 txmode = &dev_conf->txmode;
179 if (rxmode->mq_mode & ETH_MQ_RX_RSS_FLAG)
180 rxmode->offloads |= DEV_RX_OFFLOAD_RSS_HASH;
182 /* Checking TX mode */
183 if (txmode->mq_mode) {
184 PMD_INIT_LOG(INFO, "TX mq_mode DCB and VMDq not supported");
188 /* Checking RX mode */
189 if (rxmode->mq_mode & ETH_MQ_RX_RSS &&
190 !(hw->cap & NFP_NET_CFG_CTRL_RSS)) {
191 PMD_INIT_LOG(INFO, "RSS not supported");
199 nfp_net_enable_queues(struct rte_eth_dev *dev)
201 struct nfp_net_hw *hw;
202 uint64_t enabled_queues = 0;
205 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
207 /* Enabling the required TX queues in the device */
208 for (i = 0; i < dev->data->nb_tx_queues; i++)
209 enabled_queues |= (1 << i);
211 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, enabled_queues);
215 /* Enabling the required RX queues in the device */
216 for (i = 0; i < dev->data->nb_rx_queues; i++)
217 enabled_queues |= (1 << i);
219 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
223 nfp_net_disable_queues(struct rte_eth_dev *dev)
225 struct nfp_net_hw *hw;
226 uint32_t new_ctrl, update = 0;
228 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
230 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, 0);
231 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, 0);
233 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_ENABLE;
234 update = NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING |
235 NFP_NET_CFG_UPDATE_MSIX;
237 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
238 new_ctrl &= ~NFP_NET_CFG_CTRL_RINGCFG;
240 /* If an error when reconfig we avoid to change hw state */
241 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
248 nfp_net_params_setup(struct nfp_net_hw *hw)
250 nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
251 nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
255 nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
257 hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
260 #define ETH_ADDR_LEN 6
263 nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
267 for (i = 0; i < ETH_ADDR_LEN; i++)
272 nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port)
274 struct nfp_eth_table *nfp_eth_table;
275 struct nfp_net_hw *hw = NULL;
277 /* Grab a pointer to the correct physical port */
278 hw = pf_dev->ports[port];
280 nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
282 nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
283 (uint8_t *)&nfp_eth_table->ports[port].mac_addr);
290 nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
292 uint32_t mac0 = *(uint32_t *)mac;
295 nn_writel(rte_cpu_to_be_32(mac0), hw->ctrl_bar + NFP_NET_CFG_MACADDR);
298 mac1 = *(uint16_t *)mac;
299 nn_writew(rte_cpu_to_be_16(mac1),
300 hw->ctrl_bar + NFP_NET_CFG_MACADDR + 6);
304 nfp_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
306 struct nfp_net_hw *hw;
307 uint32_t update, ctrl;
309 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
310 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
311 !(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR)) {
312 PMD_INIT_LOG(INFO, "MAC address unable to change when"
317 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
318 !(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
321 /* Writing new MAC to the specific port BAR address */
322 nfp_net_write_mac(hw, (uint8_t *)mac_addr);
324 /* Signal the NIC about the change */
325 update = NFP_NET_CFG_UPDATE_MACADDR;
327 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
328 (hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
329 ctrl |= NFP_NET_CFG_CTRL_LIVE_ADDR;
330 if (nfp_net_reconfig(hw, ctrl, update) < 0) {
331 PMD_INIT_LOG(INFO, "MAC address update failed");
338 nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
339 struct rte_intr_handle *intr_handle)
341 struct nfp_net_hw *hw;
344 if (!intr_handle->intr_vec) {
345 intr_handle->intr_vec =
346 rte_zmalloc("intr_vec",
347 dev->data->nb_rx_queues * sizeof(int), 0);
348 if (!intr_handle->intr_vec) {
349 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
350 " intr_vec", dev->data->nb_rx_queues);
355 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
357 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
358 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with UIO");
359 /* UIO just supports one queue and no LSC*/
360 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(0), 0);
361 intr_handle->intr_vec[0] = 0;
363 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with VFIO");
364 for (i = 0; i < dev->data->nb_rx_queues; i++) {
366 * The first msix vector is reserved for non
369 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(i), i + 1);
370 intr_handle->intr_vec[i] = i + 1;
371 PMD_INIT_LOG(DEBUG, "intr_vec[%d]= %d", i,
372 intr_handle->intr_vec[i]);
376 /* Avoiding TX interrupts */
377 hw->ctrl |= NFP_NET_CFG_CTRL_MSIX_TX_OFF;
382 nfp_check_offloads(struct rte_eth_dev *dev)
384 struct nfp_net_hw *hw;
385 struct rte_eth_conf *dev_conf;
386 struct rte_eth_rxmode *rxmode;
387 struct rte_eth_txmode *txmode;
390 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
392 dev_conf = &dev->data->dev_conf;
393 rxmode = &dev_conf->rxmode;
394 txmode = &dev_conf->txmode;
396 if (rxmode->offloads & DEV_RX_OFFLOAD_IPV4_CKSUM) {
397 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM)
398 ctrl |= NFP_NET_CFG_CTRL_RXCSUM;
401 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
402 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN)
403 ctrl |= NFP_NET_CFG_CTRL_RXVLAN;
406 if (rxmode->offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
407 hw->mtu = rxmode->max_rx_pkt_len;
409 if (txmode->offloads & DEV_TX_OFFLOAD_VLAN_INSERT)
410 ctrl |= NFP_NET_CFG_CTRL_TXVLAN;
413 if (hw->cap & NFP_NET_CFG_CTRL_L2BC)
414 ctrl |= NFP_NET_CFG_CTRL_L2BC;
417 if (hw->cap & NFP_NET_CFG_CTRL_L2MC)
418 ctrl |= NFP_NET_CFG_CTRL_L2MC;
420 /* TX checksum offload */
421 if (txmode->offloads & DEV_TX_OFFLOAD_IPV4_CKSUM ||
422 txmode->offloads & DEV_TX_OFFLOAD_UDP_CKSUM ||
423 txmode->offloads & DEV_TX_OFFLOAD_TCP_CKSUM)
424 ctrl |= NFP_NET_CFG_CTRL_TXCSUM;
427 if (txmode->offloads & DEV_TX_OFFLOAD_TCP_TSO) {
428 if (hw->cap & NFP_NET_CFG_CTRL_LSO)
429 ctrl |= NFP_NET_CFG_CTRL_LSO;
431 ctrl |= NFP_NET_CFG_CTRL_LSO2;
435 if (txmode->offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
436 ctrl |= NFP_NET_CFG_CTRL_GATHER;
442 nfp_net_start(struct rte_eth_dev *dev)
444 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
445 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
446 uint32_t new_ctrl, update = 0;
447 struct nfp_net_hw *hw;
448 struct nfp_pf_dev *pf_dev;
449 struct rte_eth_conf *dev_conf;
450 struct rte_eth_rxmode *rxmode;
451 uint32_t intr_vector;
454 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
455 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
457 PMD_INIT_LOG(DEBUG, "Start");
459 /* Disabling queues just in case... */
460 nfp_net_disable_queues(dev);
462 /* Enabling the required queues in the device */
463 nfp_net_enable_queues(dev);
465 /* check and configure queue intr-vector mapping */
466 if (dev->data->dev_conf.intr_conf.rxq != 0) {
467 if (pf_dev->multiport) {
468 PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
469 "with NFP multiport PF");
472 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
474 * Better not to share LSC with RX interrupts.
475 * Unregistering LSC interrupt handler
477 rte_intr_callback_unregister(&pci_dev->intr_handle,
478 nfp_net_dev_interrupt_handler, (void *)dev);
480 if (dev->data->nb_rx_queues > 1) {
481 PMD_INIT_LOG(ERR, "PMD rx interrupt only "
482 "supports 1 queue with UIO");
486 intr_vector = dev->data->nb_rx_queues;
487 if (rte_intr_efd_enable(intr_handle, intr_vector))
490 nfp_configure_rx_interrupt(dev, intr_handle);
491 update = NFP_NET_CFG_UPDATE_MSIX;
494 rte_intr_enable(intr_handle);
496 new_ctrl = nfp_check_offloads(dev);
498 /* Writing configuration parameters in the device */
499 nfp_net_params_setup(hw);
501 dev_conf = &dev->data->dev_conf;
502 rxmode = &dev_conf->rxmode;
504 if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
505 nfp_net_rss_config_default(dev);
506 update |= NFP_NET_CFG_UPDATE_RSS;
507 new_ctrl |= NFP_NET_CFG_CTRL_RSS;
511 new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
513 update |= NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING;
515 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
516 new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
518 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, new_ctrl);
519 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
523 * Allocating rte mbufs for configured rx queues.
524 * This requires queues being enabled before
526 if (nfp_net_rx_freelist_setup(dev) < 0) {
531 if (hw->is_phyport) {
532 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
533 /* Configure the physical port up */
534 nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
536 nfp_eth_set_configured(dev->process_private,
546 * An error returned by this function should mean the app
547 * exiting and then the system releasing all the memory
548 * allocated even memory coming from hugepages.
550 * The device could be enabled at this point with some queues
551 * ready for getting packets. This is true if the call to
552 * nfp_net_rx_freelist_setup() succeeds for some queues but
553 * fails for subsequent queues.
555 * This should make the app exiting but better if we tell the
558 nfp_net_disable_queues(dev);
563 /* Stop device: disable rx and tx functions to allow for reconfiguring. */
565 nfp_net_stop(struct rte_eth_dev *dev)
568 struct nfp_net_hw *hw;
570 PMD_INIT_LOG(DEBUG, "Stop");
572 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
574 nfp_net_disable_queues(dev);
577 for (i = 0; i < dev->data->nb_tx_queues; i++) {
578 nfp_net_reset_tx_queue(
579 (struct nfp_net_txq *)dev->data->tx_queues[i]);
582 for (i = 0; i < dev->data->nb_rx_queues; i++) {
583 nfp_net_reset_rx_queue(
584 (struct nfp_net_rxq *)dev->data->rx_queues[i]);
587 if (hw->is_phyport) {
588 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
589 /* Configure the physical port down */
590 nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
592 nfp_eth_set_configured(dev->process_private,
599 /* Set the link up. */
601 nfp_net_set_link_up(struct rte_eth_dev *dev)
603 struct nfp_net_hw *hw;
605 PMD_DRV_LOG(DEBUG, "Set link up");
607 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
612 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
613 /* Configure the physical port down */
614 return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
616 return nfp_eth_set_configured(dev->process_private,
620 /* Set the link down. */
622 nfp_net_set_link_down(struct rte_eth_dev *dev)
624 struct nfp_net_hw *hw;
626 PMD_DRV_LOG(DEBUG, "Set link down");
628 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
633 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
634 /* Configure the physical port down */
635 return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
637 return nfp_eth_set_configured(dev->process_private,
641 /* Reset and stop device. The device can not be restarted. */
643 nfp_net_close(struct rte_eth_dev *dev)
645 struct nfp_net_hw *hw;
646 struct rte_pci_device *pci_dev;
649 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
652 PMD_INIT_LOG(DEBUG, "Close");
654 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
655 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
658 * We assume that the DPDK application is stopping all the
659 * threads/queues before calling the device close function.
662 nfp_net_disable_queues(dev);
665 for (i = 0; i < dev->data->nb_tx_queues; i++) {
666 nfp_net_reset_tx_queue(
667 (struct nfp_net_txq *)dev->data->tx_queues[i]);
670 for (i = 0; i < dev->data->nb_rx_queues; i++) {
671 nfp_net_reset_rx_queue(
672 (struct nfp_net_rxq *)dev->data->rx_queues[i]);
675 /* Only free PF resources after all physical ports have been closed */
676 if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
677 pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
678 struct nfp_pf_dev *pf_dev;
679 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
681 /* Mark this port as unused and free device priv resources*/
682 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
683 pf_dev->ports[hw->idx] = NULL;
684 rte_eth_dev_release_port(dev);
686 for (i = 0; i < pf_dev->total_phyports; i++) {
687 /* Check to see if ports are still in use */
688 if (pf_dev->ports[i])
692 /* Now it is safe to free all PF resources */
693 PMD_INIT_LOG(INFO, "Freeing PF resources");
694 nfp_cpp_area_free(pf_dev->ctrl_area);
695 nfp_cpp_area_free(pf_dev->hwqueues_area);
696 free(pf_dev->hwinfo);
697 free(pf_dev->sym_tbl);
698 nfp_cpp_free(pf_dev->cpp);
702 rte_intr_disable(&pci_dev->intr_handle);
704 /* unregister callback func from eal lib */
705 rte_intr_callback_unregister(&pci_dev->intr_handle,
706 nfp_net_dev_interrupt_handler,
710 * The ixgbe PMD driver disables the pcie master on the
711 * device. The i40e does not...
718 nfp_net_promisc_enable(struct rte_eth_dev *dev)
720 uint32_t new_ctrl, update = 0;
721 struct nfp_net_hw *hw;
724 PMD_DRV_LOG(DEBUG, "Promiscuous mode enable");
726 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
728 if (!(hw->cap & NFP_NET_CFG_CTRL_PROMISC)) {
729 PMD_INIT_LOG(INFO, "Promiscuous mode not supported");
733 if (hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) {
734 PMD_DRV_LOG(INFO, "Promiscuous mode already enabled");
738 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_PROMISC;
739 update = NFP_NET_CFG_UPDATE_GEN;
742 * DPDK sets promiscuous mode on just after this call assuming
743 * it can not fail ...
745 ret = nfp_net_reconfig(hw, new_ctrl, update);
755 nfp_net_promisc_disable(struct rte_eth_dev *dev)
757 uint32_t new_ctrl, update = 0;
758 struct nfp_net_hw *hw;
761 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
763 if ((hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) == 0) {
764 PMD_DRV_LOG(INFO, "Promiscuous mode already disabled");
768 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_PROMISC;
769 update = NFP_NET_CFG_UPDATE_GEN;
772 * DPDK sets promiscuous mode off just before this call
773 * assuming it can not fail ...
775 ret = nfp_net_reconfig(hw, new_ctrl, update);
785 * return 0 means link status changed, -1 means not changed
787 * Wait to complete is needed as it can take up to 9 seconds to get the Link
791 nfp_net_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
793 struct nfp_net_hw *hw;
794 struct rte_eth_link link;
795 uint32_t nn_link_status;
798 static const uint32_t ls_to_ethtool[] = {
799 [NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = ETH_SPEED_NUM_NONE,
800 [NFP_NET_CFG_STS_LINK_RATE_UNKNOWN] = ETH_SPEED_NUM_NONE,
801 [NFP_NET_CFG_STS_LINK_RATE_1G] = ETH_SPEED_NUM_1G,
802 [NFP_NET_CFG_STS_LINK_RATE_10G] = ETH_SPEED_NUM_10G,
803 [NFP_NET_CFG_STS_LINK_RATE_25G] = ETH_SPEED_NUM_25G,
804 [NFP_NET_CFG_STS_LINK_RATE_40G] = ETH_SPEED_NUM_40G,
805 [NFP_NET_CFG_STS_LINK_RATE_50G] = ETH_SPEED_NUM_50G,
806 [NFP_NET_CFG_STS_LINK_RATE_100G] = ETH_SPEED_NUM_100G,
809 PMD_DRV_LOG(DEBUG, "Link update");
811 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
813 nn_link_status = nn_cfg_readl(hw, NFP_NET_CFG_STS);
815 memset(&link, 0, sizeof(struct rte_eth_link));
817 if (nn_link_status & NFP_NET_CFG_STS_LINK)
818 link.link_status = ETH_LINK_UP;
820 link.link_duplex = ETH_LINK_FULL_DUPLEX;
822 nn_link_status = (nn_link_status >> NFP_NET_CFG_STS_LINK_RATE_SHIFT) &
823 NFP_NET_CFG_STS_LINK_RATE_MASK;
825 if (nn_link_status >= RTE_DIM(ls_to_ethtool))
826 link.link_speed = ETH_SPEED_NUM_NONE;
828 link.link_speed = ls_to_ethtool[nn_link_status];
830 ret = rte_eth_linkstatus_set(dev, &link);
832 if (link.link_status)
833 PMD_DRV_LOG(INFO, "NIC Link is Up");
835 PMD_DRV_LOG(INFO, "NIC Link is Down");
841 nfp_net_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
844 struct nfp_net_hw *hw;
845 struct rte_eth_stats nfp_dev_stats;
847 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
849 /* RTE_ETHDEV_QUEUE_STAT_CNTRS default value is 16 */
851 memset(&nfp_dev_stats, 0, sizeof(nfp_dev_stats));
853 /* reading per RX ring stats */
854 for (i = 0; i < dev->data->nb_rx_queues; i++) {
855 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
858 nfp_dev_stats.q_ipackets[i] =
859 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
861 nfp_dev_stats.q_ipackets[i] -=
862 hw->eth_stats_base.q_ipackets[i];
864 nfp_dev_stats.q_ibytes[i] =
865 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
867 nfp_dev_stats.q_ibytes[i] -=
868 hw->eth_stats_base.q_ibytes[i];
871 /* reading per TX ring stats */
872 for (i = 0; i < dev->data->nb_tx_queues; i++) {
873 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
876 nfp_dev_stats.q_opackets[i] =
877 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
879 nfp_dev_stats.q_opackets[i] -=
880 hw->eth_stats_base.q_opackets[i];
882 nfp_dev_stats.q_obytes[i] =
883 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
885 nfp_dev_stats.q_obytes[i] -=
886 hw->eth_stats_base.q_obytes[i];
889 nfp_dev_stats.ipackets =
890 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
892 nfp_dev_stats.ipackets -= hw->eth_stats_base.ipackets;
894 nfp_dev_stats.ibytes =
895 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
897 nfp_dev_stats.ibytes -= hw->eth_stats_base.ibytes;
899 nfp_dev_stats.opackets =
900 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
902 nfp_dev_stats.opackets -= hw->eth_stats_base.opackets;
904 nfp_dev_stats.obytes =
905 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
907 nfp_dev_stats.obytes -= hw->eth_stats_base.obytes;
909 /* reading general device stats */
910 nfp_dev_stats.ierrors =
911 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
913 nfp_dev_stats.ierrors -= hw->eth_stats_base.ierrors;
915 nfp_dev_stats.oerrors =
916 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
918 nfp_dev_stats.oerrors -= hw->eth_stats_base.oerrors;
920 /* RX ring mbuf allocation failures */
921 nfp_dev_stats.rx_nombuf = dev->data->rx_mbuf_alloc_failed;
923 nfp_dev_stats.imissed =
924 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
926 nfp_dev_stats.imissed -= hw->eth_stats_base.imissed;
929 memcpy(stats, &nfp_dev_stats, sizeof(*stats));
936 nfp_net_stats_reset(struct rte_eth_dev *dev)
939 struct nfp_net_hw *hw;
941 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
944 * hw->eth_stats_base records the per counter starting point.
948 /* reading per RX ring stats */
949 for (i = 0; i < dev->data->nb_rx_queues; i++) {
950 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
953 hw->eth_stats_base.q_ipackets[i] =
954 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
956 hw->eth_stats_base.q_ibytes[i] =
957 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
960 /* reading per TX ring stats */
961 for (i = 0; i < dev->data->nb_tx_queues; i++) {
962 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
965 hw->eth_stats_base.q_opackets[i] =
966 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
968 hw->eth_stats_base.q_obytes[i] =
969 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
972 hw->eth_stats_base.ipackets =
973 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
975 hw->eth_stats_base.ibytes =
976 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
978 hw->eth_stats_base.opackets =
979 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
981 hw->eth_stats_base.obytes =
982 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
984 /* reading general device stats */
985 hw->eth_stats_base.ierrors =
986 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
988 hw->eth_stats_base.oerrors =
989 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
991 /* RX ring mbuf allocation failures */
992 dev->data->rx_mbuf_alloc_failed = 0;
994 hw->eth_stats_base.imissed =
995 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
1001 nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1003 struct nfp_net_hw *hw;
1005 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1007 dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
1008 dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
1009 dev_info->min_rx_bufsize = RTE_ETHER_MIN_MTU;
1010 dev_info->max_rx_pktlen = hw->max_mtu;
1011 /* Next should change when PF support is implemented */
1012 dev_info->max_mac_addrs = 1;
1014 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN)
1015 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
1017 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM)
1018 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_IPV4_CKSUM |
1019 DEV_RX_OFFLOAD_UDP_CKSUM |
1020 DEV_RX_OFFLOAD_TCP_CKSUM;
1022 if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
1023 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
1025 if (hw->cap & NFP_NET_CFG_CTRL_TXCSUM)
1026 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_IPV4_CKSUM |
1027 DEV_TX_OFFLOAD_UDP_CKSUM |
1028 DEV_TX_OFFLOAD_TCP_CKSUM;
1030 if (hw->cap & NFP_NET_CFG_CTRL_LSO_ANY)
1031 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_TCP_TSO;
1033 if (hw->cap & NFP_NET_CFG_CTRL_GATHER)
1034 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_MULTI_SEGS;
1036 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1038 .pthresh = DEFAULT_RX_PTHRESH,
1039 .hthresh = DEFAULT_RX_HTHRESH,
1040 .wthresh = DEFAULT_RX_WTHRESH,
1042 .rx_free_thresh = DEFAULT_RX_FREE_THRESH,
1046 dev_info->default_txconf = (struct rte_eth_txconf) {
1048 .pthresh = DEFAULT_TX_PTHRESH,
1049 .hthresh = DEFAULT_TX_HTHRESH,
1050 .wthresh = DEFAULT_TX_WTHRESH,
1052 .tx_free_thresh = DEFAULT_TX_FREE_THRESH,
1053 .tx_rs_thresh = DEFAULT_TX_RSBIT_THRESH,
1056 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1057 .nb_max = NFP_NET_MAX_RX_DESC,
1058 .nb_min = NFP_NET_MIN_RX_DESC,
1059 .nb_align = NFP_ALIGN_RING_DESC,
1062 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1063 .nb_max = NFP_NET_MAX_TX_DESC,
1064 .nb_min = NFP_NET_MIN_TX_DESC,
1065 .nb_align = NFP_ALIGN_RING_DESC,
1066 .nb_seg_max = NFP_TX_MAX_SEG,
1067 .nb_mtu_seg_max = NFP_TX_MAX_MTU_SEG,
1070 /* All NFP devices support jumbo frames */
1071 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1073 if (hw->cap & NFP_NET_CFG_CTRL_RSS) {
1074 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_RSS_HASH;
1076 dev_info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1077 ETH_RSS_NONFRAG_IPV4_TCP |
1078 ETH_RSS_NONFRAG_IPV4_UDP |
1080 ETH_RSS_NONFRAG_IPV6_TCP |
1081 ETH_RSS_NONFRAG_IPV6_UDP;
1083 dev_info->reta_size = NFP_NET_CFG_RSS_ITBL_SZ;
1084 dev_info->hash_key_size = NFP_NET_CFG_RSS_KEY_SZ;
1087 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
1088 ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
1089 ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G;
1095 nfp_net_supported_ptypes_get(struct rte_eth_dev *dev)
1097 static const uint32_t ptypes[] = {
1098 /* refers to nfp_net_set_hash() */
1099 RTE_PTYPE_INNER_L3_IPV4,
1100 RTE_PTYPE_INNER_L3_IPV6,
1101 RTE_PTYPE_INNER_L3_IPV6_EXT,
1102 RTE_PTYPE_INNER_L4_MASK,
1106 if (dev->rx_pkt_burst == nfp_net_recv_pkts)
1112 nfp_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1114 struct rte_pci_device *pci_dev;
1115 struct nfp_net_hw *hw;
1118 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1119 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1121 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1124 /* Make sure all updates are written before un-masking */
1126 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id),
1127 NFP_NET_CFG_ICR_UNMASKED);
1132 nfp_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1134 struct rte_pci_device *pci_dev;
1135 struct nfp_net_hw *hw;
1138 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1139 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1141 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1144 /* Make sure all updates are written before un-masking */
1146 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id), 0x1);
1151 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
1153 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1154 struct rte_eth_link link;
1156 rte_eth_linkstatus_get(dev, &link);
1157 if (link.link_status)
1158 PMD_DRV_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
1159 dev->data->port_id, link.link_speed,
1160 link.link_duplex == ETH_LINK_FULL_DUPLEX
1161 ? "full-duplex" : "half-duplex");
1163 PMD_DRV_LOG(INFO, " Port %d: Link Down",
1164 dev->data->port_id);
1166 PMD_DRV_LOG(INFO, "PCI Address: " PCI_PRI_FMT,
1167 pci_dev->addr.domain, pci_dev->addr.bus,
1168 pci_dev->addr.devid, pci_dev->addr.function);
1171 /* Interrupt configuration and handling */
1174 * nfp_net_irq_unmask - Unmask an interrupt
1176 * If MSI-X auto-masking is enabled clear the mask bit, otherwise
1177 * clear the ICR for the entry.
1180 nfp_net_irq_unmask(struct rte_eth_dev *dev)
1182 struct nfp_net_hw *hw;
1183 struct rte_pci_device *pci_dev;
1185 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1186 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1188 if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
1189 /* If MSI-X auto-masking is used, clear the entry */
1191 rte_intr_ack(&pci_dev->intr_handle);
1193 /* Make sure all updates are written before un-masking */
1195 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(NFP_NET_IRQ_LSC_IDX),
1196 NFP_NET_CFG_ICR_UNMASKED);
1201 * Interrupt handler which shall be registered for alarm callback for delayed
1202 * handling specific interrupt to wait for the stable nic state. As the NIC
1203 * interrupt state is not stable for nfp after link is just down, it needs
1204 * to wait 4 seconds to get the stable status.
1206 * @param handle Pointer to interrupt handle.
1207 * @param param The address of parameter (struct rte_eth_dev *)
1212 nfp_net_dev_interrupt_delayed_handler(void *param)
1214 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1216 nfp_net_link_update(dev, 0);
1217 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1219 nfp_net_dev_link_status_print(dev);
1222 nfp_net_irq_unmask(dev);
1226 nfp_net_dev_interrupt_handler(void *param)
1229 struct rte_eth_link link;
1230 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1232 PMD_DRV_LOG(DEBUG, "We got a LSC interrupt!!!");
1234 rte_eth_linkstatus_get(dev, &link);
1236 nfp_net_link_update(dev, 0);
1239 if (!link.link_status) {
1240 /* handle it 1 sec later, wait it being stable */
1241 timeout = NFP_NET_LINK_UP_CHECK_TIMEOUT;
1242 /* likely to down */
1244 /* handle it 4 sec later, wait it being stable */
1245 timeout = NFP_NET_LINK_DOWN_CHECK_TIMEOUT;
1248 if (rte_eal_alarm_set(timeout * 1000,
1249 nfp_net_dev_interrupt_delayed_handler,
1251 PMD_INIT_LOG(ERR, "Error setting alarm");
1253 nfp_net_irq_unmask(dev);
1258 nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1260 struct nfp_net_hw *hw;
1262 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1264 /* check that mtu is within the allowed range */
1265 if (mtu < RTE_ETHER_MIN_MTU || (uint32_t)mtu > hw->max_mtu)
1268 /* mtu setting is forbidden if port is started */
1269 if (dev->data->dev_started) {
1270 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
1271 dev->data->port_id);
1275 /* switch to jumbo mode if needed */
1276 if ((uint32_t)mtu > RTE_ETHER_MTU)
1277 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1279 dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1281 /* update max frame size */
1282 dev->data->dev_conf.rxmode.max_rx_pkt_len = (uint32_t)mtu;
1284 /* writing to configuration space */
1285 nn_cfg_writel(hw, NFP_NET_CFG_MTU, (uint32_t)mtu);
1293 nfp_net_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1295 uint32_t new_ctrl, update;
1296 struct nfp_net_hw *hw;
1299 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1302 /* Enable vlan strip if it is not configured yet */
1303 if ((mask & ETH_VLAN_STRIP_OFFLOAD) &&
1304 !(hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
1305 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_RXVLAN;
1307 /* Disable vlan strip just if it is configured */
1308 if (!(mask & ETH_VLAN_STRIP_OFFLOAD) &&
1309 (hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
1310 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_RXVLAN;
1315 update = NFP_NET_CFG_UPDATE_GEN;
1317 ret = nfp_net_reconfig(hw, new_ctrl, update);
1319 hw->ctrl = new_ctrl;
1325 nfp_net_rss_reta_write(struct rte_eth_dev *dev,
1326 struct rte_eth_rss_reta_entry64 *reta_conf,
1329 uint32_t reta, mask;
1332 struct nfp_net_hw *hw =
1333 NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1335 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
1336 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1337 "(%d) doesn't match the number hardware can supported "
1338 "(%d)", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
1343 * Update Redirection Table. There are 128 8bit-entries which can be
1344 * manage as 32 32bit-entries
1346 for (i = 0; i < reta_size; i += 4) {
1347 /* Handling 4 RSS entries per loop */
1348 idx = i / RTE_RETA_GROUP_SIZE;
1349 shift = i % RTE_RETA_GROUP_SIZE;
1350 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
1356 /* If all 4 entries were set, don't need read RETA register */
1358 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + i);
1360 for (j = 0; j < 4; j++) {
1361 if (!(mask & (0x1 << j)))
1364 /* Clearing the entry bits */
1365 reta &= ~(0xFF << (8 * j));
1366 reta |= reta_conf[idx].reta[shift + j] << (8 * j);
1368 nn_cfg_writel(hw, NFP_NET_CFG_RSS_ITBL + (idx * 64) + shift,
1374 /* Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device */
1376 nfp_net_reta_update(struct rte_eth_dev *dev,
1377 struct rte_eth_rss_reta_entry64 *reta_conf,
1380 struct nfp_net_hw *hw =
1381 NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1385 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1388 ret = nfp_net_rss_reta_write(dev, reta_conf, reta_size);
1392 update = NFP_NET_CFG_UPDATE_RSS;
1394 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
1400 /* Query Redirection Table(RETA) of Receive Side Scaling of Ethernet device. */
1402 nfp_net_reta_query(struct rte_eth_dev *dev,
1403 struct rte_eth_rss_reta_entry64 *reta_conf,
1409 struct nfp_net_hw *hw;
1411 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1413 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1416 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
1417 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1418 "(%d) doesn't match the number hardware can supported "
1419 "(%d)", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
1424 * Reading Redirection Table. There are 128 8bit-entries which can be
1425 * manage as 32 32bit-entries
1427 for (i = 0; i < reta_size; i += 4) {
1428 /* Handling 4 RSS entries per loop */
1429 idx = i / RTE_RETA_GROUP_SIZE;
1430 shift = i % RTE_RETA_GROUP_SIZE;
1431 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
1436 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + (idx * 64) +
1438 for (j = 0; j < 4; j++) {
1439 if (!(mask & (0x1 << j)))
1441 reta_conf[idx].reta[shift + j] =
1442 (uint8_t)((reta >> (8 * j)) & 0xF);
1449 nfp_net_rss_hash_write(struct rte_eth_dev *dev,
1450 struct rte_eth_rss_conf *rss_conf)
1452 struct nfp_net_hw *hw;
1454 uint32_t cfg_rss_ctrl = 0;
1458 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1460 /* Writing the key byte a byte */
1461 for (i = 0; i < rss_conf->rss_key_len; i++) {
1462 memcpy(&key, &rss_conf->rss_key[i], 1);
1463 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY + i, key);
1466 rss_hf = rss_conf->rss_hf;
1468 if (rss_hf & ETH_RSS_IPV4)
1469 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4;
1471 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
1472 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4_TCP;
1474 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
1475 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4_UDP;
1477 if (rss_hf & ETH_RSS_IPV6)
1478 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6;
1480 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
1481 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6_TCP;
1483 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
1484 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6_UDP;
1486 cfg_rss_ctrl |= NFP_NET_CFG_RSS_MASK;
1487 cfg_rss_ctrl |= NFP_NET_CFG_RSS_TOEPLITZ;
1489 /* configuring where to apply the RSS hash */
1490 nn_cfg_writel(hw, NFP_NET_CFG_RSS_CTRL, cfg_rss_ctrl);
1492 /* Writing the key size */
1493 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY_SZ, rss_conf->rss_key_len);
1499 nfp_net_rss_hash_update(struct rte_eth_dev *dev,
1500 struct rte_eth_rss_conf *rss_conf)
1504 struct nfp_net_hw *hw;
1506 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1508 rss_hf = rss_conf->rss_hf;
1510 /* Checking if RSS is enabled */
1511 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS)) {
1512 if (rss_hf != 0) { /* Enable RSS? */
1513 PMD_DRV_LOG(ERR, "RSS unsupported");
1516 return 0; /* Nothing to do */
1519 if (rss_conf->rss_key_len > NFP_NET_CFG_RSS_KEY_SZ) {
1520 PMD_DRV_LOG(ERR, "hash key too long");
1524 nfp_net_rss_hash_write(dev, rss_conf);
1526 update = NFP_NET_CFG_UPDATE_RSS;
1528 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
1535 nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev,
1536 struct rte_eth_rss_conf *rss_conf)
1539 uint32_t cfg_rss_ctrl;
1542 struct nfp_net_hw *hw;
1544 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1546 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1549 rss_hf = rss_conf->rss_hf;
1550 cfg_rss_ctrl = nn_cfg_readl(hw, NFP_NET_CFG_RSS_CTRL);
1552 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4)
1553 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV4_UDP;
1555 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_TCP)
1556 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
1558 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_TCP)
1559 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
1561 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_UDP)
1562 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
1564 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_UDP)
1565 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
1567 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6)
1568 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
1570 /* Propagate current RSS hash functions to caller */
1571 rss_conf->rss_hf = rss_hf;
1573 /* Reading the key size */
1574 rss_conf->rss_key_len = nn_cfg_readl(hw, NFP_NET_CFG_RSS_KEY_SZ);
1576 /* Reading the key byte a byte */
1577 for (i = 0; i < rss_conf->rss_key_len; i++) {
1578 key = nn_cfg_readb(hw, NFP_NET_CFG_RSS_KEY + i);
1579 memcpy(&rss_conf->rss_key[i], &key, 1);
1586 nfp_net_rss_config_default(struct rte_eth_dev *dev)
1588 struct rte_eth_conf *dev_conf;
1589 struct rte_eth_rss_conf rss_conf;
1590 struct rte_eth_rss_reta_entry64 nfp_reta_conf[2];
1591 uint16_t rx_queues = dev->data->nb_rx_queues;
1595 PMD_DRV_LOG(INFO, "setting default RSS conf for %u queues",
1598 nfp_reta_conf[0].mask = ~0x0;
1599 nfp_reta_conf[1].mask = ~0x0;
1602 for (i = 0; i < 0x40; i += 8) {
1603 for (j = i; j < (i + 8); j++) {
1604 nfp_reta_conf[0].reta[j] = queue;
1605 nfp_reta_conf[1].reta[j] = queue++;
1609 ret = nfp_net_rss_reta_write(dev, nfp_reta_conf, 0x80);
1613 dev_conf = &dev->data->dev_conf;
1615 PMD_DRV_LOG(INFO, "wrong rss conf");
1618 rss_conf = dev_conf->rx_adv_conf.rss_conf;
1620 ret = nfp_net_rss_hash_write(dev, &rss_conf);
1626 /* Initialise and register driver with DPDK Application */
1627 static const struct eth_dev_ops nfp_net_eth_dev_ops = {
1628 .dev_configure = nfp_net_configure,
1629 .dev_start = nfp_net_start,
1630 .dev_stop = nfp_net_stop,
1631 .dev_set_link_up = nfp_net_set_link_up,
1632 .dev_set_link_down = nfp_net_set_link_down,
1633 .dev_close = nfp_net_close,
1634 .promiscuous_enable = nfp_net_promisc_enable,
1635 .promiscuous_disable = nfp_net_promisc_disable,
1636 .link_update = nfp_net_link_update,
1637 .stats_get = nfp_net_stats_get,
1638 .stats_reset = nfp_net_stats_reset,
1639 .dev_infos_get = nfp_net_infos_get,
1640 .dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
1641 .mtu_set = nfp_net_dev_mtu_set,
1642 .mac_addr_set = nfp_set_mac_addr,
1643 .vlan_offload_set = nfp_net_vlan_offload_set,
1644 .reta_update = nfp_net_reta_update,
1645 .reta_query = nfp_net_reta_query,
1646 .rss_hash_update = nfp_net_rss_hash_update,
1647 .rss_hash_conf_get = nfp_net_rss_hash_conf_get,
1648 .rx_queue_setup = nfp_net_rx_queue_setup,
1649 .rx_queue_release = nfp_net_rx_queue_release,
1650 .tx_queue_setup = nfp_net_tx_queue_setup,
1651 .tx_queue_release = nfp_net_tx_queue_release,
1652 .rx_queue_intr_enable = nfp_rx_queue_intr_enable,
1653 .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
1658 nfp_net_init(struct rte_eth_dev *eth_dev)
1660 struct rte_pci_device *pci_dev;
1661 struct nfp_pf_dev *pf_dev;
1662 struct nfp_net_hw *hw;
1664 uint64_t tx_bar_off = 0, rx_bar_off = 0;
1670 PMD_INIT_FUNC_TRACE();
1672 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1674 /* Use backpointer here to the PF of this eth_dev */
1675 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(eth_dev->data->dev_private);
1677 /* NFP can not handle DMA addresses requiring more than 40 bits */
1678 if (rte_mem_check_dma_mask(40)) {
1679 RTE_LOG(ERR, PMD, "device %s can not be used:",
1680 pci_dev->device.name);
1681 RTE_LOG(ERR, PMD, "\trestricted dma mask to 40 bits!\n");
1685 if ((pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) ||
1686 (pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC)) {
1687 port = ((struct nfp_net_hw *)eth_dev->data->dev_private)->idx;
1688 if (port < 0 || port > 7) {
1689 PMD_DRV_LOG(ERR, "Port value is wrong");
1693 /* Use PF array of physical ports to get pointer to
1694 * this specific port
1696 hw = pf_dev->ports[port];
1698 PMD_INIT_LOG(DEBUG, "Working with physical port number: %d, "
1699 "NFP internal port number: %d",
1703 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1706 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
1707 eth_dev->rx_queue_count = nfp_net_rx_queue_count;
1708 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
1709 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
1711 /* For secondary processes, the primary has done all the work */
1712 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1715 rte_eth_copy_pci_info(eth_dev, pci_dev);
1717 hw->device_id = pci_dev->id.device_id;
1718 hw->vendor_id = pci_dev->id.vendor_id;
1719 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1720 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1722 PMD_INIT_LOG(DEBUG, "nfp_net: device (%u:%u) %u:%u:%u:%u",
1723 pci_dev->id.vendor_id, pci_dev->id.device_id,
1724 pci_dev->addr.domain, pci_dev->addr.bus,
1725 pci_dev->addr.devid, pci_dev->addr.function);
1727 hw->ctrl_bar = (uint8_t *)pci_dev->mem_resource[0].addr;
1728 if (hw->ctrl_bar == NULL) {
1730 "hw->ctrl_bar is NULL. BAR0 not configured");
1734 if (hw->is_phyport) {
1736 hw->ctrl_bar = pf_dev->ctrl_bar;
1738 if (!pf_dev->ctrl_bar)
1740 /* Use port offset in pf ctrl_bar for this
1743 hw->ctrl_bar = pf_dev->ctrl_bar +
1744 (port * NFP_PF_CSR_SLICE_SIZE);
1748 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
1750 hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
1751 hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
1753 /* Work out where in the BAR the queues start. */
1754 switch (pci_dev->id.device_id) {
1755 case PCI_DEVICE_ID_NFP4000_PF_NIC:
1756 case PCI_DEVICE_ID_NFP6000_PF_NIC:
1757 case PCI_DEVICE_ID_NFP6000_VF_NIC:
1758 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
1759 tx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
1760 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ);
1761 rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
1764 PMD_DRV_LOG(ERR, "nfp_net: no device ID matching");
1766 goto dev_err_ctrl_map;
1769 PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off);
1770 PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off);
1772 if (hw->is_phyport) {
1773 hw->tx_bar = pf_dev->hw_queues + tx_bar_off;
1774 hw->rx_bar = pf_dev->hw_queues + rx_bar_off;
1775 eth_dev->data->dev_private = hw;
1777 hw->tx_bar = (uint8_t *)pci_dev->mem_resource[2].addr +
1779 hw->rx_bar = (uint8_t *)pci_dev->mem_resource[2].addr +
1783 PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p",
1784 hw->ctrl_bar, hw->tx_bar, hw->rx_bar);
1786 nfp_net_cfg_queue_setup(hw);
1788 /* Get some of the read-only fields from the config BAR */
1789 hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
1790 hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
1791 hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
1792 hw->mtu = RTE_ETHER_MTU;
1794 /* VLAN insertion is incompatible with LSOv2 */
1795 if (hw->cap & NFP_NET_CFG_CTRL_LSO2)
1796 hw->cap &= ~NFP_NET_CFG_CTRL_TXVLAN;
1798 if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
1799 hw->rx_offset = NFP_NET_RX_OFFSET;
1801 hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
1803 PMD_INIT_LOG(INFO, "VER: %u.%u, Maximum supported MTU: %d",
1804 NFD_CFG_MAJOR_VERSION_of(hw->ver),
1805 NFD_CFG_MINOR_VERSION_of(hw->ver), hw->max_mtu);
1807 PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s%s%s%s%s%s", hw->cap,
1808 hw->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "",
1809 hw->cap & NFP_NET_CFG_CTRL_L2BC ? "L2BCFILT " : "",
1810 hw->cap & NFP_NET_CFG_CTRL_L2MC ? "L2MCFILT " : "",
1811 hw->cap & NFP_NET_CFG_CTRL_RXCSUM ? "RXCSUM " : "",
1812 hw->cap & NFP_NET_CFG_CTRL_TXCSUM ? "TXCSUM " : "",
1813 hw->cap & NFP_NET_CFG_CTRL_RXVLAN ? "RXVLAN " : "",
1814 hw->cap & NFP_NET_CFG_CTRL_TXVLAN ? "TXVLAN " : "",
1815 hw->cap & NFP_NET_CFG_CTRL_SCATTER ? "SCATTER " : "",
1816 hw->cap & NFP_NET_CFG_CTRL_GATHER ? "GATHER " : "",
1817 hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR ? "LIVE_ADDR " : "",
1818 hw->cap & NFP_NET_CFG_CTRL_LSO ? "TSO " : "",
1819 hw->cap & NFP_NET_CFG_CTRL_LSO2 ? "TSOv2 " : "",
1820 hw->cap & NFP_NET_CFG_CTRL_RSS ? "RSS " : "",
1821 hw->cap & NFP_NET_CFG_CTRL_RSS2 ? "RSSv2 " : "");
1825 hw->stride_rx = stride;
1826 hw->stride_tx = stride;
1828 PMD_INIT_LOG(INFO, "max_rx_queues: %u, max_tx_queues: %u",
1829 hw->max_rx_queues, hw->max_tx_queues);
1831 /* Initializing spinlock for reconfigs */
1832 rte_spinlock_init(&hw->reconfig_lock);
1834 /* Allocating memory for mac addr */
1835 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
1836 RTE_ETHER_ADDR_LEN, 0);
1837 if (eth_dev->data->mac_addrs == NULL) {
1838 PMD_INIT_LOG(ERR, "Failed to space for MAC address");
1840 goto dev_err_queues_map;
1843 if (hw->is_phyport) {
1844 nfp_net_pf_read_mac(pf_dev, port);
1845 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
1848 if (!rte_is_valid_assigned_ether_addr(
1849 (struct rte_ether_addr *)&hw->mac_addr)) {
1850 PMD_INIT_LOG(INFO, "Using random mac address for port %d",
1852 /* Using random mac addresses for VFs */
1853 rte_eth_random_addr(&hw->mac_addr[0]);
1854 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
1857 /* Copying mac address to DPDK eth_dev struct */
1858 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
1859 ð_dev->data->mac_addrs[0]);
1861 if (!(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
1862 eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
1864 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1866 PMD_INIT_LOG(INFO, "port %d VendorID=0x%x DeviceID=0x%x "
1867 "mac=%02x:%02x:%02x:%02x:%02x:%02x",
1868 eth_dev->data->port_id, pci_dev->id.vendor_id,
1869 pci_dev->id.device_id,
1870 hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
1871 hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
1873 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1874 /* Registering LSC interrupt handler */
1875 rte_intr_callback_register(&pci_dev->intr_handle,
1876 nfp_net_dev_interrupt_handler,
1878 /* Telling the firmware about the LSC interrupt entry */
1879 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, NFP_NET_IRQ_LSC_IDX);
1880 /* Recording current stats counters values */
1881 nfp_net_stats_reset(eth_dev);
1887 nfp_cpp_area_free(hw->hwqueues_area);
1889 nfp_cpp_area_free(hw->ctrl_area);
1894 #define DEFAULT_FW_PATH "/lib/firmware/netronome"
1897 nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card)
1899 struct nfp_cpp *cpp = nsp->cpp;
1905 /* Looking for firmware file in order of priority */
1907 /* First try to find a firmware image specific for this device */
1908 snprintf(serial, sizeof(serial),
1909 "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
1910 cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3],
1911 cpp->serial[4], cpp->serial[5], cpp->interface >> 8,
1912 cpp->interface & 0xff);
1914 snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH,
1916 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
1917 if (rte_firmware_read(fw_name, &fw_buf, &fsize) == 0)
1920 /* Then try the PCI name */
1921 snprintf(fw_name, sizeof(fw_name), "%s/pci-%s.nffw", DEFAULT_FW_PATH,
1923 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
1924 if (rte_firmware_read(fw_name, &fw_buf, &fsize) == 0)
1927 /* Finally try the card type and media */
1928 snprintf(fw_name, sizeof(fw_name), "%s/%s", DEFAULT_FW_PATH, card);
1929 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
1930 if (rte_firmware_read(fw_name, &fw_buf, &fsize) < 0) {
1931 PMD_DRV_LOG(INFO, "Firmware file %s not found.", fw_name);
1936 PMD_DRV_LOG(INFO, "Firmware file found at %s with size: %zu",
1939 PMD_DRV_LOG(INFO, "Uploading the firmware ...");
1940 nfp_nsp_load_fw(nsp, fw_buf, fsize);
1941 PMD_DRV_LOG(INFO, "Done");
1948 nfp_fw_setup(struct rte_pci_device *dev, struct nfp_cpp *cpp,
1949 struct nfp_eth_table *nfp_eth_table, struct nfp_hwinfo *hwinfo)
1951 struct nfp_nsp *nsp;
1952 const char *nfp_fw_model;
1953 char card_desc[100];
1956 nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "assembly.partno");
1959 PMD_DRV_LOG(INFO, "firmware model found: %s", nfp_fw_model);
1961 PMD_DRV_LOG(ERR, "firmware model NOT found");
1965 if (nfp_eth_table->count == 0 || nfp_eth_table->count > 8) {
1966 PMD_DRV_LOG(ERR, "NFP ethernet table reports wrong ports: %u",
1967 nfp_eth_table->count);
1971 PMD_DRV_LOG(INFO, "NFP ethernet port table reports %u ports",
1972 nfp_eth_table->count);
1974 PMD_DRV_LOG(INFO, "Port speed: %u", nfp_eth_table->ports[0].speed);
1976 snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
1977 nfp_fw_model, nfp_eth_table->count,
1978 nfp_eth_table->ports[0].speed / 1000);
1980 nsp = nfp_nsp_open(cpp);
1982 PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle");
1986 nfp_nsp_device_soft_reset(nsp);
1987 err = nfp_fw_upload(dev, nsp, card_desc);
1993 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
1995 struct nfp_net_hw *hw;
1996 struct rte_eth_dev *eth_dev;
1997 struct nfp_eth_table *nfp_eth_table = NULL;
2001 nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
2002 if (!nfp_eth_table) {
2003 PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
2008 /* Loop through all physical ports on PF */
2009 for (i = 0; i < pf_dev->total_phyports; i++) {
2010 const unsigned int numa_node = rte_socket_id();
2011 char port_name[RTE_ETH_NAME_MAX_LEN];
2013 snprintf(port_name, sizeof(port_name), "%s_port%d",
2014 pf_dev->pci_dev->device.name, i);
2016 /* Allocate a eth_dev for this phyport */
2017 eth_dev = rte_eth_dev_allocate(port_name);
2023 /* Allocate memory for this phyport */
2024 eth_dev->data->dev_private =
2025 rte_zmalloc_socket(port_name, sizeof(struct nfp_net_hw),
2026 RTE_CACHE_LINE_SIZE, numa_node);
2027 if (!eth_dev->data->dev_private) {
2029 rte_eth_dev_release_port(eth_dev);
2033 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2035 /* Add this device to the PF's array of physical ports */
2036 pf_dev->ports[i] = hw;
2038 hw->pf_dev = pf_dev;
2039 hw->cpp = pf_dev->cpp;
2040 hw->eth_dev = eth_dev;
2042 hw->nfp_idx = nfp_eth_table->ports[i].index;
2043 hw->is_phyport = true;
2045 eth_dev->device = &pf_dev->pci_dev->device;
2047 /* ctrl/tx/rx BAR mappings and remaining init happens in
2050 ret = nfp_net_init(eth_dev);
2057 rte_eth_dev_probing_finish(eth_dev);
2059 } /* End loop, all ports on this PF */
2061 goto eth_table_cleanup;
2064 for (i = 0; i < pf_dev->total_phyports; i++) {
2065 if (pf_dev->ports[i] && pf_dev->ports[i]->eth_dev) {
2066 struct rte_eth_dev *tmp_dev;
2067 tmp_dev = pf_dev->ports[i]->eth_dev;
2068 rte_eth_dev_release_port(tmp_dev);
2069 pf_dev->ports[i] = NULL;
2073 free(nfp_eth_table);
2078 static int nfp_pf_init(struct rte_pci_device *pci_dev)
2080 struct nfp_pf_dev *pf_dev = NULL;
2081 struct nfp_cpp *cpp;
2082 struct nfp_hwinfo *hwinfo;
2083 struct nfp_rtsym_table *sym_tbl;
2084 struct nfp_eth_table *nfp_eth_table = NULL;
2085 char name[RTE_ETH_NAME_MAX_LEN];
2094 * When device bound to UIO, the device could be used, by mistake,
2095 * by two DPDK apps, and the UIO driver does not avoid it. This
2096 * could lead to a serious problem when configuring the NFP CPP
2097 * interface. Here we avoid this telling to the CPP init code to
2098 * use a lock file if UIO is being used.
2100 if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
2101 cpp = nfp_cpp_from_device_name(pci_dev, 0);
2103 cpp = nfp_cpp_from_device_name(pci_dev, 1);
2106 PMD_INIT_LOG(ERR, "A CPP handle can not be obtained");
2111 hwinfo = nfp_hwinfo_read(cpp);
2113 PMD_INIT_LOG(ERR, "Error reading hwinfo table");
2118 nfp_eth_table = nfp_eth_read_ports(cpp);
2119 if (!nfp_eth_table) {
2120 PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
2122 goto hwinfo_cleanup;
2125 if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo)) {
2126 PMD_INIT_LOG(ERR, "Error when uploading firmware");
2128 goto eth_table_cleanup;
2131 /* Now the symbol table should be there */
2132 sym_tbl = nfp_rtsym_table_read(cpp);
2134 PMD_INIT_LOG(ERR, "Something is wrong with the firmware"
2137 goto eth_table_cleanup;
2140 total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
2141 if (total_ports != (int)nfp_eth_table->count) {
2142 PMD_DRV_LOG(ERR, "Inconsistent number of ports");
2144 goto sym_tbl_cleanup;
2147 PMD_INIT_LOG(INFO, "Total physical ports: %d", total_ports);
2149 if (total_ports <= 0 || total_ports > 8) {
2150 PMD_INIT_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value");
2152 goto sym_tbl_cleanup;
2154 /* Allocate memory for the PF "device" */
2155 snprintf(name, sizeof(name), "nfp_pf%d", 0);
2156 pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
2159 goto sym_tbl_cleanup;
2162 /* Populate the newly created PF device */
2164 pf_dev->hwinfo = hwinfo;
2165 pf_dev->sym_tbl = sym_tbl;
2166 pf_dev->total_phyports = total_ports;
2168 if (total_ports > 1)
2169 pf_dev->multiport = true;
2171 pf_dev->pci_dev = pci_dev;
2173 /* Map the symbol table */
2174 pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0",
2175 pf_dev->total_phyports * 32768,
2176 &pf_dev->ctrl_area);
2177 if (!pf_dev->ctrl_bar) {
2178 PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for _pf0_net_ctrl_bar");
2183 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar);
2185 /* configure access to tx/rx vNIC BARs */
2186 pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, 0, 0,
2188 NFP_QCP_QUEUE_AREA_SZ,
2189 &pf_dev->hwqueues_area);
2190 if (!pf_dev->hw_queues) {
2191 PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc");
2193 goto ctrl_area_cleanup;
2196 PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues);
2198 /* Initialize and prep physical ports now
2199 * This will loop through all physical ports
2201 ret = nfp_init_phyports(pf_dev);
2203 PMD_INIT_LOG(ERR, "Could not create physical ports");
2204 goto hwqueues_cleanup;
2207 /* register the CPP bridge service here for primary use */
2208 nfp_register_cpp_service(pf_dev->cpp);
2213 nfp_cpp_area_free(pf_dev->hwqueues_area);
2215 nfp_cpp_area_free(pf_dev->ctrl_area);
2221 free(nfp_eth_table);
2229 * When attaching to the NFP4000/6000 PF on a secondary process there
2230 * is no need to initialize the PF again. Only minimal work is required
2233 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
2235 struct nfp_cpp *cpp;
2236 struct nfp_rtsym_table *sym_tbl;
2245 * When device bound to UIO, the device could be used, by mistake,
2246 * by two DPDK apps, and the UIO driver does not avoid it. This
2247 * could lead to a serious problem when configuring the NFP CPP
2248 * interface. Here we avoid this telling to the CPP init code to
2249 * use a lock file if UIO is being used.
2251 if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
2252 cpp = nfp_cpp_from_device_name(pci_dev, 0);
2254 cpp = nfp_cpp_from_device_name(pci_dev, 1);
2257 PMD_INIT_LOG(ERR, "A CPP handle can not be obtained");
2262 * We don't have access to the PF created in the primary process
2263 * here so we have to read the number of ports from firmware
2265 sym_tbl = nfp_rtsym_table_read(cpp);
2267 PMD_INIT_LOG(ERR, "Something is wrong with the firmware"
2272 total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
2274 for (i = 0; i < total_ports; i++) {
2275 struct rte_eth_dev *eth_dev;
2276 char port_name[RTE_ETH_NAME_MAX_LEN];
2278 snprintf(port_name, sizeof(port_name), "%s_port%d",
2279 pci_dev->device.name, i);
2281 PMD_DRV_LOG(DEBUG, "Secondary attaching to port %s",
2283 eth_dev = rte_eth_dev_attach_secondary(port_name);
2286 "secondary process attach failed, "
2287 "ethdev doesn't exist");
2290 eth_dev->process_private = cpp;
2291 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
2292 eth_dev->rx_queue_count = nfp_net_rx_queue_count;
2293 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
2294 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
2295 rte_eth_dev_probing_finish(eth_dev);
2298 /* Register the CPP bridge service for the secondary too */
2299 nfp_register_cpp_service(cpp);
2304 static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2305 struct rte_pci_device *dev)
2307 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2308 return nfp_pf_init(dev);
2310 return nfp_pf_secondary_init(dev);
2313 static const struct rte_pci_id pci_id_nfp_pf_net_map[] = {
2315 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2316 PCI_DEVICE_ID_NFP4000_PF_NIC)
2319 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2320 PCI_DEVICE_ID_NFP6000_PF_NIC)
2327 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev)
2329 struct rte_pci_device *pci_dev;
2332 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2334 if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
2335 pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
2336 /* Free up all physical ports under PF */
2337 RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
2338 rte_eth_dev_close(port_id);
2340 * Ports can be closed and freed but hotplugging is not
2341 * currently supported
2346 /* VF cleanup, just free private port data */
2347 return nfp_net_close(eth_dev);
2350 static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
2352 return rte_eth_dev_pci_generic_remove(pci_dev, nfp_pci_uninit);
2355 static struct rte_pci_driver rte_nfp_net_pf_pmd = {
2356 .id_table = pci_id_nfp_pf_net_map,
2357 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2358 .probe = nfp_pf_pci_probe,
2359 .remove = eth_nfp_pci_remove,
2362 RTE_PMD_REGISTER_PCI(net_nfp_pf, rte_nfp_net_pf_pmd);
2363 RTE_PMD_REGISTER_PCI_TABLE(net_nfp_pf, pci_id_nfp_pf_net_map);
2364 RTE_PMD_REGISTER_KMOD_DEP(net_nfp_pf, "* igb_uio | uio_pci_generic | vfio");
2365 RTE_LOG_REGISTER_SUFFIX(nfp_logtype_init, init, NOTICE);
2366 RTE_LOG_REGISTER_SUFFIX(nfp_logtype_driver, driver, NOTICE);
2369 * c-file-style: "Linux"
2370 * indent-tabs-mode: t