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_pci_uninit(struct rte_eth_dev *eth_dev);
62 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
63 static int nfp_net_stop(struct rte_eth_dev *dev);
64 static int nfp_fw_setup(struct rte_pci_device *dev,
66 struct nfp_eth_table *nfp_eth_table,
67 struct nfp_hwinfo *hwinfo);
70 __nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t update)
76 PMD_DRV_LOG(DEBUG, "Writing to the configuration queue (%p)...",
79 if (hw->qcp_cfg == NULL)
80 rte_panic("Bad configuration queue pointer\n");
82 nfp_qcp_ptr_add(hw->qcp_cfg, NFP_QCP_WRITE_PTR, 1);
85 wait.tv_nsec = 1000000;
87 PMD_DRV_LOG(DEBUG, "Polling for update ack...");
89 /* Poll update field, waiting for NFP to ack the config */
90 for (cnt = 0; ; cnt++) {
91 new = nn_cfg_readl(hw, NFP_NET_CFG_UPDATE);
94 if (new & NFP_NET_CFG_UPDATE_ERR) {
95 PMD_INIT_LOG(ERR, "Reconfig error: 0x%08x", new);
98 if (cnt >= NFP_NET_POLL_TIMEOUT) {
99 PMD_INIT_LOG(ERR, "Reconfig timeout for 0x%08x after"
100 " %dms", update, cnt);
101 rte_panic("Exiting\n");
103 nanosleep(&wait, 0); /* waiting for a 1ms */
105 PMD_DRV_LOG(DEBUG, "Ack DONE");
110 * Reconfigure the NIC
111 * @nn: device to reconfigure
112 * @ctrl: The value for the ctrl field in the BAR config
113 * @update: The value for the update field in the BAR config
115 * Write the update word to the BAR and ping the reconfig queue. Then poll
116 * until the firmware has acknowledged the update by zeroing the update word.
119 nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update)
123 PMD_DRV_LOG(DEBUG, "nfp_net_reconfig: ctrl=%08x update=%08x",
126 rte_spinlock_lock(&hw->reconfig_lock);
128 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, ctrl);
129 nn_cfg_writel(hw, NFP_NET_CFG_UPDATE, update);
133 err = __nfp_net_reconfig(hw, update);
135 rte_spinlock_unlock(&hw->reconfig_lock);
141 * Reconfig errors imply situations where they can be handled.
142 * Otherwise, rte_panic is called inside __nfp_net_reconfig
144 PMD_INIT_LOG(ERR, "Error nfp_net reconfig for ctrl: %x update: %x",
150 * Configure an Ethernet device. This function must be invoked first
151 * before any other function in the Ethernet API. This function can
152 * also be re-invoked when a device is in the stopped state.
155 nfp_net_configure(struct rte_eth_dev *dev)
157 struct rte_eth_conf *dev_conf;
158 struct rte_eth_rxmode *rxmode;
159 struct rte_eth_txmode *txmode;
160 struct nfp_net_hw *hw;
162 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
165 * A DPDK app sends info about how many queues to use and how
166 * those queues need to be configured. This is used by the
167 * DPDK core and it makes sure no more queues than those
168 * advertised by the driver are requested. This function is
169 * called after that internal process
172 PMD_INIT_LOG(DEBUG, "Configure");
174 dev_conf = &dev->data->dev_conf;
175 rxmode = &dev_conf->rxmode;
176 txmode = &dev_conf->txmode;
178 if (rxmode->mq_mode & ETH_MQ_RX_RSS_FLAG)
179 rxmode->offloads |= DEV_RX_OFFLOAD_RSS_HASH;
181 /* Checking TX mode */
182 if (txmode->mq_mode) {
183 PMD_INIT_LOG(INFO, "TX mq_mode DCB and VMDq not supported");
187 /* Checking RX mode */
188 if (rxmode->mq_mode & ETH_MQ_RX_RSS &&
189 !(hw->cap & NFP_NET_CFG_CTRL_RSS)) {
190 PMD_INIT_LOG(INFO, "RSS not supported");
198 nfp_net_enable_queues(struct rte_eth_dev *dev)
200 struct nfp_net_hw *hw;
201 uint64_t enabled_queues = 0;
204 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
206 /* Enabling the required TX queues in the device */
207 for (i = 0; i < dev->data->nb_tx_queues; i++)
208 enabled_queues |= (1 << i);
210 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, enabled_queues);
214 /* Enabling the required RX queues in the device */
215 for (i = 0; i < dev->data->nb_rx_queues; i++)
216 enabled_queues |= (1 << i);
218 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
222 nfp_net_disable_queues(struct rte_eth_dev *dev)
224 struct nfp_net_hw *hw;
225 uint32_t new_ctrl, update = 0;
227 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
229 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, 0);
230 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, 0);
232 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_ENABLE;
233 update = NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING |
234 NFP_NET_CFG_UPDATE_MSIX;
236 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
237 new_ctrl &= ~NFP_NET_CFG_CTRL_RINGCFG;
239 /* If an error when reconfig we avoid to change hw state */
240 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
247 nfp_net_params_setup(struct nfp_net_hw *hw)
249 nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
250 nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
254 nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
256 hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
259 #define ETH_ADDR_LEN 6
262 nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
266 for (i = 0; i < ETH_ADDR_LEN; i++)
271 nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port)
273 struct nfp_eth_table *nfp_eth_table;
274 struct nfp_net_hw *hw = NULL;
276 /* Grab a pointer to the correct physical port */
277 hw = pf_dev->ports[port];
279 nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
281 nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
282 (uint8_t *)&nfp_eth_table->ports[port].mac_addr);
289 nfp_net_vf_read_mac(struct nfp_net_hw *hw)
293 tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
294 memcpy(&hw->mac_addr[0], &tmp, 4);
296 tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
297 memcpy(&hw->mac_addr[4], &tmp, 2);
301 nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
303 uint32_t mac0 = *(uint32_t *)mac;
306 nn_writel(rte_cpu_to_be_32(mac0), hw->ctrl_bar + NFP_NET_CFG_MACADDR);
309 mac1 = *(uint16_t *)mac;
310 nn_writew(rte_cpu_to_be_16(mac1),
311 hw->ctrl_bar + NFP_NET_CFG_MACADDR + 6);
315 nfp_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
317 struct nfp_net_hw *hw;
318 uint32_t update, ctrl;
320 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
321 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
322 !(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR)) {
323 PMD_INIT_LOG(INFO, "MAC address unable to change when"
328 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
329 !(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
332 /* Writing new MAC to the specific port BAR address */
333 nfp_net_write_mac(hw, (uint8_t *)mac_addr);
335 /* Signal the NIC about the change */
336 update = NFP_NET_CFG_UPDATE_MACADDR;
338 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
339 (hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
340 ctrl |= NFP_NET_CFG_CTRL_LIVE_ADDR;
341 if (nfp_net_reconfig(hw, ctrl, update) < 0) {
342 PMD_INIT_LOG(INFO, "MAC address update failed");
349 nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
350 struct rte_intr_handle *intr_handle)
352 struct nfp_net_hw *hw;
355 if (!intr_handle->intr_vec) {
356 intr_handle->intr_vec =
357 rte_zmalloc("intr_vec",
358 dev->data->nb_rx_queues * sizeof(int), 0);
359 if (!intr_handle->intr_vec) {
360 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
361 " intr_vec", dev->data->nb_rx_queues);
366 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
368 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
369 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with UIO");
370 /* UIO just supports one queue and no LSC*/
371 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(0), 0);
372 intr_handle->intr_vec[0] = 0;
374 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with VFIO");
375 for (i = 0; i < dev->data->nb_rx_queues; i++) {
377 * The first msix vector is reserved for non
380 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(i), i + 1);
381 intr_handle->intr_vec[i] = i + 1;
382 PMD_INIT_LOG(DEBUG, "intr_vec[%d]= %d", i,
383 intr_handle->intr_vec[i]);
387 /* Avoiding TX interrupts */
388 hw->ctrl |= NFP_NET_CFG_CTRL_MSIX_TX_OFF;
393 nfp_check_offloads(struct rte_eth_dev *dev)
395 struct nfp_net_hw *hw;
396 struct rte_eth_conf *dev_conf;
397 struct rte_eth_rxmode *rxmode;
398 struct rte_eth_txmode *txmode;
401 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
403 dev_conf = &dev->data->dev_conf;
404 rxmode = &dev_conf->rxmode;
405 txmode = &dev_conf->txmode;
407 if (rxmode->offloads & DEV_RX_OFFLOAD_IPV4_CKSUM) {
408 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM)
409 ctrl |= NFP_NET_CFG_CTRL_RXCSUM;
412 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
413 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN)
414 ctrl |= NFP_NET_CFG_CTRL_RXVLAN;
417 if (rxmode->offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
418 hw->mtu = rxmode->max_rx_pkt_len;
420 if (txmode->offloads & DEV_TX_OFFLOAD_VLAN_INSERT)
421 ctrl |= NFP_NET_CFG_CTRL_TXVLAN;
424 if (hw->cap & NFP_NET_CFG_CTRL_L2BC)
425 ctrl |= NFP_NET_CFG_CTRL_L2BC;
428 if (hw->cap & NFP_NET_CFG_CTRL_L2MC)
429 ctrl |= NFP_NET_CFG_CTRL_L2MC;
431 /* TX checksum offload */
432 if (txmode->offloads & DEV_TX_OFFLOAD_IPV4_CKSUM ||
433 txmode->offloads & DEV_TX_OFFLOAD_UDP_CKSUM ||
434 txmode->offloads & DEV_TX_OFFLOAD_TCP_CKSUM)
435 ctrl |= NFP_NET_CFG_CTRL_TXCSUM;
438 if (txmode->offloads & DEV_TX_OFFLOAD_TCP_TSO) {
439 if (hw->cap & NFP_NET_CFG_CTRL_LSO)
440 ctrl |= NFP_NET_CFG_CTRL_LSO;
442 ctrl |= NFP_NET_CFG_CTRL_LSO2;
446 if (txmode->offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
447 ctrl |= NFP_NET_CFG_CTRL_GATHER;
453 nfp_net_start(struct rte_eth_dev *dev)
455 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
456 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
457 uint32_t new_ctrl, update = 0;
458 struct nfp_net_hw *hw;
459 struct nfp_pf_dev *pf_dev;
460 struct rte_eth_conf *dev_conf;
461 struct rte_eth_rxmode *rxmode;
462 uint32_t intr_vector;
465 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
466 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
468 PMD_INIT_LOG(DEBUG, "Start");
470 /* Disabling queues just in case... */
471 nfp_net_disable_queues(dev);
473 /* Enabling the required queues in the device */
474 nfp_net_enable_queues(dev);
476 /* check and configure queue intr-vector mapping */
477 if (dev->data->dev_conf.intr_conf.rxq != 0) {
478 if (pf_dev->multiport) {
479 PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
480 "with NFP multiport PF");
483 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
485 * Better not to share LSC with RX interrupts.
486 * Unregistering LSC interrupt handler
488 rte_intr_callback_unregister(&pci_dev->intr_handle,
489 nfp_net_dev_interrupt_handler, (void *)dev);
491 if (dev->data->nb_rx_queues > 1) {
492 PMD_INIT_LOG(ERR, "PMD rx interrupt only "
493 "supports 1 queue with UIO");
497 intr_vector = dev->data->nb_rx_queues;
498 if (rte_intr_efd_enable(intr_handle, intr_vector))
501 nfp_configure_rx_interrupt(dev, intr_handle);
502 update = NFP_NET_CFG_UPDATE_MSIX;
505 rte_intr_enable(intr_handle);
507 new_ctrl = nfp_check_offloads(dev);
509 /* Writing configuration parameters in the device */
510 nfp_net_params_setup(hw);
512 dev_conf = &dev->data->dev_conf;
513 rxmode = &dev_conf->rxmode;
515 if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
516 nfp_net_rss_config_default(dev);
517 update |= NFP_NET_CFG_UPDATE_RSS;
518 new_ctrl |= NFP_NET_CFG_CTRL_RSS;
522 new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
524 update |= NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING;
526 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
527 new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
529 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, new_ctrl);
530 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
534 * Allocating rte mbufs for configured rx queues.
535 * This requires queues being enabled before
537 if (nfp_net_rx_freelist_setup(dev) < 0) {
542 if (hw->is_phyport) {
543 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
544 /* Configure the physical port up */
545 nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
547 nfp_eth_set_configured(dev->process_private,
557 * An error returned by this function should mean the app
558 * exiting and then the system releasing all the memory
559 * allocated even memory coming from hugepages.
561 * The device could be enabled at this point with some queues
562 * ready for getting packets. This is true if the call to
563 * nfp_net_rx_freelist_setup() succeeds for some queues but
564 * fails for subsequent queues.
566 * This should make the app exiting but better if we tell the
569 nfp_net_disable_queues(dev);
574 /* Stop device: disable rx and tx functions to allow for reconfiguring. */
576 nfp_net_stop(struct rte_eth_dev *dev)
579 struct nfp_net_hw *hw;
581 PMD_INIT_LOG(DEBUG, "Stop");
583 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
585 nfp_net_disable_queues(dev);
588 for (i = 0; i < dev->data->nb_tx_queues; i++) {
589 nfp_net_reset_tx_queue(
590 (struct nfp_net_txq *)dev->data->tx_queues[i]);
593 for (i = 0; i < dev->data->nb_rx_queues; i++) {
594 nfp_net_reset_rx_queue(
595 (struct nfp_net_rxq *)dev->data->rx_queues[i]);
598 if (hw->is_phyport) {
599 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
600 /* Configure the physical port down */
601 nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
603 nfp_eth_set_configured(dev->process_private,
610 /* Set the link up. */
612 nfp_net_set_link_up(struct rte_eth_dev *dev)
614 struct nfp_net_hw *hw;
616 PMD_DRV_LOG(DEBUG, "Set link up");
618 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
623 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
624 /* Configure the physical port down */
625 return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
627 return nfp_eth_set_configured(dev->process_private,
631 /* Set the link down. */
633 nfp_net_set_link_down(struct rte_eth_dev *dev)
635 struct nfp_net_hw *hw;
637 PMD_DRV_LOG(DEBUG, "Set link down");
639 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
644 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
645 /* Configure the physical port down */
646 return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
648 return nfp_eth_set_configured(dev->process_private,
652 /* Reset and stop device. The device can not be restarted. */
654 nfp_net_close(struct rte_eth_dev *dev)
656 struct nfp_net_hw *hw;
657 struct rte_pci_device *pci_dev;
660 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
663 PMD_INIT_LOG(DEBUG, "Close");
665 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
666 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
669 * We assume that the DPDK application is stopping all the
670 * threads/queues before calling the device close function.
673 nfp_net_disable_queues(dev);
676 for (i = 0; i < dev->data->nb_tx_queues; i++) {
677 nfp_net_reset_tx_queue(
678 (struct nfp_net_txq *)dev->data->tx_queues[i]);
681 for (i = 0; i < dev->data->nb_rx_queues; i++) {
682 nfp_net_reset_rx_queue(
683 (struct nfp_net_rxq *)dev->data->rx_queues[i]);
686 /* Only free PF resources after all physical ports have been closed */
687 if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
688 pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
689 struct nfp_pf_dev *pf_dev;
690 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
692 /* Mark this port as unused and free device priv resources*/
693 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
694 pf_dev->ports[hw->idx] = NULL;
695 rte_eth_dev_release_port(dev);
697 for (i = 0; i < pf_dev->total_phyports; i++) {
698 /* Check to see if ports are still in use */
699 if (pf_dev->ports[i])
703 /* Now it is safe to free all PF resources */
704 PMD_INIT_LOG(INFO, "Freeing PF resources");
705 nfp_cpp_area_free(pf_dev->ctrl_area);
706 nfp_cpp_area_free(pf_dev->hwqueues_area);
707 free(pf_dev->hwinfo);
708 free(pf_dev->sym_tbl);
709 nfp_cpp_free(pf_dev->cpp);
713 rte_intr_disable(&pci_dev->intr_handle);
715 /* unregister callback func from eal lib */
716 rte_intr_callback_unregister(&pci_dev->intr_handle,
717 nfp_net_dev_interrupt_handler,
721 * The ixgbe PMD driver disables the pcie master on the
722 * device. The i40e does not...
729 nfp_net_promisc_enable(struct rte_eth_dev *dev)
731 uint32_t new_ctrl, update = 0;
732 struct nfp_net_hw *hw;
735 PMD_DRV_LOG(DEBUG, "Promiscuous mode enable");
737 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
739 if (!(hw->cap & NFP_NET_CFG_CTRL_PROMISC)) {
740 PMD_INIT_LOG(INFO, "Promiscuous mode not supported");
744 if (hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) {
745 PMD_DRV_LOG(INFO, "Promiscuous mode already enabled");
749 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_PROMISC;
750 update = NFP_NET_CFG_UPDATE_GEN;
753 * DPDK sets promiscuous mode on just after this call assuming
754 * it can not fail ...
756 ret = nfp_net_reconfig(hw, new_ctrl, update);
766 nfp_net_promisc_disable(struct rte_eth_dev *dev)
768 uint32_t new_ctrl, update = 0;
769 struct nfp_net_hw *hw;
772 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
774 if ((hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) == 0) {
775 PMD_DRV_LOG(INFO, "Promiscuous mode already disabled");
779 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_PROMISC;
780 update = NFP_NET_CFG_UPDATE_GEN;
783 * DPDK sets promiscuous mode off just before this call
784 * assuming it can not fail ...
786 ret = nfp_net_reconfig(hw, new_ctrl, update);
796 * return 0 means link status changed, -1 means not changed
798 * Wait to complete is needed as it can take up to 9 seconds to get the Link
802 nfp_net_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
804 struct nfp_net_hw *hw;
805 struct rte_eth_link link;
806 uint32_t nn_link_status;
809 static const uint32_t ls_to_ethtool[] = {
810 [NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = ETH_SPEED_NUM_NONE,
811 [NFP_NET_CFG_STS_LINK_RATE_UNKNOWN] = ETH_SPEED_NUM_NONE,
812 [NFP_NET_CFG_STS_LINK_RATE_1G] = ETH_SPEED_NUM_1G,
813 [NFP_NET_CFG_STS_LINK_RATE_10G] = ETH_SPEED_NUM_10G,
814 [NFP_NET_CFG_STS_LINK_RATE_25G] = ETH_SPEED_NUM_25G,
815 [NFP_NET_CFG_STS_LINK_RATE_40G] = ETH_SPEED_NUM_40G,
816 [NFP_NET_CFG_STS_LINK_RATE_50G] = ETH_SPEED_NUM_50G,
817 [NFP_NET_CFG_STS_LINK_RATE_100G] = ETH_SPEED_NUM_100G,
820 PMD_DRV_LOG(DEBUG, "Link update");
822 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
824 nn_link_status = nn_cfg_readl(hw, NFP_NET_CFG_STS);
826 memset(&link, 0, sizeof(struct rte_eth_link));
828 if (nn_link_status & NFP_NET_CFG_STS_LINK)
829 link.link_status = ETH_LINK_UP;
831 link.link_duplex = ETH_LINK_FULL_DUPLEX;
833 nn_link_status = (nn_link_status >> NFP_NET_CFG_STS_LINK_RATE_SHIFT) &
834 NFP_NET_CFG_STS_LINK_RATE_MASK;
836 if (nn_link_status >= RTE_DIM(ls_to_ethtool))
837 link.link_speed = ETH_SPEED_NUM_NONE;
839 link.link_speed = ls_to_ethtool[nn_link_status];
841 ret = rte_eth_linkstatus_set(dev, &link);
843 if (link.link_status)
844 PMD_DRV_LOG(INFO, "NIC Link is Up");
846 PMD_DRV_LOG(INFO, "NIC Link is Down");
852 nfp_net_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
855 struct nfp_net_hw *hw;
856 struct rte_eth_stats nfp_dev_stats;
858 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
860 /* RTE_ETHDEV_QUEUE_STAT_CNTRS default value is 16 */
862 memset(&nfp_dev_stats, 0, sizeof(nfp_dev_stats));
864 /* reading per RX ring stats */
865 for (i = 0; i < dev->data->nb_rx_queues; i++) {
866 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
869 nfp_dev_stats.q_ipackets[i] =
870 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
872 nfp_dev_stats.q_ipackets[i] -=
873 hw->eth_stats_base.q_ipackets[i];
875 nfp_dev_stats.q_ibytes[i] =
876 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
878 nfp_dev_stats.q_ibytes[i] -=
879 hw->eth_stats_base.q_ibytes[i];
882 /* reading per TX ring stats */
883 for (i = 0; i < dev->data->nb_tx_queues; i++) {
884 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
887 nfp_dev_stats.q_opackets[i] =
888 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
890 nfp_dev_stats.q_opackets[i] -=
891 hw->eth_stats_base.q_opackets[i];
893 nfp_dev_stats.q_obytes[i] =
894 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
896 nfp_dev_stats.q_obytes[i] -=
897 hw->eth_stats_base.q_obytes[i];
900 nfp_dev_stats.ipackets =
901 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
903 nfp_dev_stats.ipackets -= hw->eth_stats_base.ipackets;
905 nfp_dev_stats.ibytes =
906 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
908 nfp_dev_stats.ibytes -= hw->eth_stats_base.ibytes;
910 nfp_dev_stats.opackets =
911 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
913 nfp_dev_stats.opackets -= hw->eth_stats_base.opackets;
915 nfp_dev_stats.obytes =
916 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
918 nfp_dev_stats.obytes -= hw->eth_stats_base.obytes;
920 /* reading general device stats */
921 nfp_dev_stats.ierrors =
922 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
924 nfp_dev_stats.ierrors -= hw->eth_stats_base.ierrors;
926 nfp_dev_stats.oerrors =
927 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
929 nfp_dev_stats.oerrors -= hw->eth_stats_base.oerrors;
931 /* RX ring mbuf allocation failures */
932 nfp_dev_stats.rx_nombuf = dev->data->rx_mbuf_alloc_failed;
934 nfp_dev_stats.imissed =
935 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
937 nfp_dev_stats.imissed -= hw->eth_stats_base.imissed;
940 memcpy(stats, &nfp_dev_stats, sizeof(*stats));
947 nfp_net_stats_reset(struct rte_eth_dev *dev)
950 struct nfp_net_hw *hw;
952 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
955 * hw->eth_stats_base records the per counter starting point.
959 /* reading per RX ring stats */
960 for (i = 0; i < dev->data->nb_rx_queues; i++) {
961 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
964 hw->eth_stats_base.q_ipackets[i] =
965 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
967 hw->eth_stats_base.q_ibytes[i] =
968 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
971 /* reading per TX ring stats */
972 for (i = 0; i < dev->data->nb_tx_queues; i++) {
973 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
976 hw->eth_stats_base.q_opackets[i] =
977 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
979 hw->eth_stats_base.q_obytes[i] =
980 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
983 hw->eth_stats_base.ipackets =
984 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
986 hw->eth_stats_base.ibytes =
987 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
989 hw->eth_stats_base.opackets =
990 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
992 hw->eth_stats_base.obytes =
993 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
995 /* reading general device stats */
996 hw->eth_stats_base.ierrors =
997 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
999 hw->eth_stats_base.oerrors =
1000 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
1002 /* RX ring mbuf allocation failures */
1003 dev->data->rx_mbuf_alloc_failed = 0;
1005 hw->eth_stats_base.imissed =
1006 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
1012 nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1014 struct nfp_net_hw *hw;
1016 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1018 dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
1019 dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
1020 dev_info->min_rx_bufsize = RTE_ETHER_MIN_MTU;
1021 dev_info->max_rx_pktlen = hw->max_mtu;
1022 /* Next should change when PF support is implemented */
1023 dev_info->max_mac_addrs = 1;
1025 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN)
1026 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
1028 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM)
1029 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_IPV4_CKSUM |
1030 DEV_RX_OFFLOAD_UDP_CKSUM |
1031 DEV_RX_OFFLOAD_TCP_CKSUM;
1033 if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
1034 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
1036 if (hw->cap & NFP_NET_CFG_CTRL_TXCSUM)
1037 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_IPV4_CKSUM |
1038 DEV_TX_OFFLOAD_UDP_CKSUM |
1039 DEV_TX_OFFLOAD_TCP_CKSUM;
1041 if (hw->cap & NFP_NET_CFG_CTRL_LSO_ANY)
1042 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_TCP_TSO;
1044 if (hw->cap & NFP_NET_CFG_CTRL_GATHER)
1045 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_MULTI_SEGS;
1047 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1049 .pthresh = DEFAULT_RX_PTHRESH,
1050 .hthresh = DEFAULT_RX_HTHRESH,
1051 .wthresh = DEFAULT_RX_WTHRESH,
1053 .rx_free_thresh = DEFAULT_RX_FREE_THRESH,
1057 dev_info->default_txconf = (struct rte_eth_txconf) {
1059 .pthresh = DEFAULT_TX_PTHRESH,
1060 .hthresh = DEFAULT_TX_HTHRESH,
1061 .wthresh = DEFAULT_TX_WTHRESH,
1063 .tx_free_thresh = DEFAULT_TX_FREE_THRESH,
1064 .tx_rs_thresh = DEFAULT_TX_RSBIT_THRESH,
1067 dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
1068 .nb_max = NFP_NET_MAX_RX_DESC,
1069 .nb_min = NFP_NET_MIN_RX_DESC,
1070 .nb_align = NFP_ALIGN_RING_DESC,
1073 dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
1074 .nb_max = NFP_NET_MAX_TX_DESC,
1075 .nb_min = NFP_NET_MIN_TX_DESC,
1076 .nb_align = NFP_ALIGN_RING_DESC,
1077 .nb_seg_max = NFP_TX_MAX_SEG,
1078 .nb_mtu_seg_max = NFP_TX_MAX_MTU_SEG,
1081 /* All NFP devices support jumbo frames */
1082 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1084 if (hw->cap & NFP_NET_CFG_CTRL_RSS) {
1085 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_RSS_HASH;
1087 dev_info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1088 ETH_RSS_NONFRAG_IPV4_TCP |
1089 ETH_RSS_NONFRAG_IPV4_UDP |
1091 ETH_RSS_NONFRAG_IPV6_TCP |
1092 ETH_RSS_NONFRAG_IPV6_UDP;
1094 dev_info->reta_size = NFP_NET_CFG_RSS_ITBL_SZ;
1095 dev_info->hash_key_size = NFP_NET_CFG_RSS_KEY_SZ;
1098 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
1099 ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
1100 ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G;
1106 nfp_net_supported_ptypes_get(struct rte_eth_dev *dev)
1108 static const uint32_t ptypes[] = {
1109 /* refers to nfp_net_set_hash() */
1110 RTE_PTYPE_INNER_L3_IPV4,
1111 RTE_PTYPE_INNER_L3_IPV6,
1112 RTE_PTYPE_INNER_L3_IPV6_EXT,
1113 RTE_PTYPE_INNER_L4_MASK,
1117 if (dev->rx_pkt_burst == nfp_net_recv_pkts)
1123 nfp_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1125 struct rte_pci_device *pci_dev;
1126 struct nfp_net_hw *hw;
1129 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1130 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1132 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1135 /* Make sure all updates are written before un-masking */
1137 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id),
1138 NFP_NET_CFG_ICR_UNMASKED);
1143 nfp_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1145 struct rte_pci_device *pci_dev;
1146 struct nfp_net_hw *hw;
1149 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1150 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1152 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1155 /* Make sure all updates are written before un-masking */
1157 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id), 0x1);
1162 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
1164 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1165 struct rte_eth_link link;
1167 rte_eth_linkstatus_get(dev, &link);
1168 if (link.link_status)
1169 PMD_DRV_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
1170 dev->data->port_id, link.link_speed,
1171 link.link_duplex == ETH_LINK_FULL_DUPLEX
1172 ? "full-duplex" : "half-duplex");
1174 PMD_DRV_LOG(INFO, " Port %d: Link Down",
1175 dev->data->port_id);
1177 PMD_DRV_LOG(INFO, "PCI Address: " PCI_PRI_FMT,
1178 pci_dev->addr.domain, pci_dev->addr.bus,
1179 pci_dev->addr.devid, pci_dev->addr.function);
1182 /* Interrupt configuration and handling */
1185 * nfp_net_irq_unmask - Unmask an interrupt
1187 * If MSI-X auto-masking is enabled clear the mask bit, otherwise
1188 * clear the ICR for the entry.
1191 nfp_net_irq_unmask(struct rte_eth_dev *dev)
1193 struct nfp_net_hw *hw;
1194 struct rte_pci_device *pci_dev;
1196 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1197 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1199 if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
1200 /* If MSI-X auto-masking is used, clear the entry */
1202 rte_intr_ack(&pci_dev->intr_handle);
1204 /* Make sure all updates are written before un-masking */
1206 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(NFP_NET_IRQ_LSC_IDX),
1207 NFP_NET_CFG_ICR_UNMASKED);
1212 * Interrupt handler which shall be registered for alarm callback for delayed
1213 * handling specific interrupt to wait for the stable nic state. As the NIC
1214 * interrupt state is not stable for nfp after link is just down, it needs
1215 * to wait 4 seconds to get the stable status.
1217 * @param handle Pointer to interrupt handle.
1218 * @param param The address of parameter (struct rte_eth_dev *)
1223 nfp_net_dev_interrupt_delayed_handler(void *param)
1225 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1227 nfp_net_link_update(dev, 0);
1228 rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1230 nfp_net_dev_link_status_print(dev);
1233 nfp_net_irq_unmask(dev);
1237 nfp_net_dev_interrupt_handler(void *param)
1240 struct rte_eth_link link;
1241 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1243 PMD_DRV_LOG(DEBUG, "We got a LSC interrupt!!!");
1245 rte_eth_linkstatus_get(dev, &link);
1247 nfp_net_link_update(dev, 0);
1250 if (!link.link_status) {
1251 /* handle it 1 sec later, wait it being stable */
1252 timeout = NFP_NET_LINK_UP_CHECK_TIMEOUT;
1253 /* likely to down */
1255 /* handle it 4 sec later, wait it being stable */
1256 timeout = NFP_NET_LINK_DOWN_CHECK_TIMEOUT;
1259 if (rte_eal_alarm_set(timeout * 1000,
1260 nfp_net_dev_interrupt_delayed_handler,
1262 PMD_INIT_LOG(ERR, "Error setting alarm");
1264 nfp_net_irq_unmask(dev);
1269 nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1271 struct nfp_net_hw *hw;
1273 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1275 /* check that mtu is within the allowed range */
1276 if (mtu < RTE_ETHER_MIN_MTU || (uint32_t)mtu > hw->max_mtu)
1279 /* mtu setting is forbidden if port is started */
1280 if (dev->data->dev_started) {
1281 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
1282 dev->data->port_id);
1286 /* switch to jumbo mode if needed */
1287 if ((uint32_t)mtu > RTE_ETHER_MTU)
1288 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1290 dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1292 /* update max frame size */
1293 dev->data->dev_conf.rxmode.max_rx_pkt_len = (uint32_t)mtu;
1295 /* writing to configuration space */
1296 nn_cfg_writel(hw, NFP_NET_CFG_MTU, (uint32_t)mtu);
1304 nfp_net_vlan_offload_set(struct rte_eth_dev *dev, int mask)
1306 uint32_t new_ctrl, update;
1307 struct nfp_net_hw *hw;
1310 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1313 /* Enable vlan strip if it is not configured yet */
1314 if ((mask & ETH_VLAN_STRIP_OFFLOAD) &&
1315 !(hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
1316 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_RXVLAN;
1318 /* Disable vlan strip just if it is configured */
1319 if (!(mask & ETH_VLAN_STRIP_OFFLOAD) &&
1320 (hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
1321 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_RXVLAN;
1326 update = NFP_NET_CFG_UPDATE_GEN;
1328 ret = nfp_net_reconfig(hw, new_ctrl, update);
1330 hw->ctrl = new_ctrl;
1336 nfp_net_rss_reta_write(struct rte_eth_dev *dev,
1337 struct rte_eth_rss_reta_entry64 *reta_conf,
1340 uint32_t reta, mask;
1343 struct nfp_net_hw *hw =
1344 NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1346 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
1347 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1348 "(%d) doesn't match the number hardware can supported "
1349 "(%d)", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
1354 * Update Redirection Table. There are 128 8bit-entries which can be
1355 * manage as 32 32bit-entries
1357 for (i = 0; i < reta_size; i += 4) {
1358 /* Handling 4 RSS entries per loop */
1359 idx = i / RTE_RETA_GROUP_SIZE;
1360 shift = i % RTE_RETA_GROUP_SIZE;
1361 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
1367 /* If all 4 entries were set, don't need read RETA register */
1369 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + i);
1371 for (j = 0; j < 4; j++) {
1372 if (!(mask & (0x1 << j)))
1375 /* Clearing the entry bits */
1376 reta &= ~(0xFF << (8 * j));
1377 reta |= reta_conf[idx].reta[shift + j] << (8 * j);
1379 nn_cfg_writel(hw, NFP_NET_CFG_RSS_ITBL + (idx * 64) + shift,
1385 /* Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device */
1387 nfp_net_reta_update(struct rte_eth_dev *dev,
1388 struct rte_eth_rss_reta_entry64 *reta_conf,
1391 struct nfp_net_hw *hw =
1392 NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1396 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1399 ret = nfp_net_rss_reta_write(dev, reta_conf, reta_size);
1403 update = NFP_NET_CFG_UPDATE_RSS;
1405 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
1411 /* Query Redirection Table(RETA) of Receive Side Scaling of Ethernet device. */
1413 nfp_net_reta_query(struct rte_eth_dev *dev,
1414 struct rte_eth_rss_reta_entry64 *reta_conf,
1420 struct nfp_net_hw *hw;
1422 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1424 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1427 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
1428 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
1429 "(%d) doesn't match the number hardware can supported "
1430 "(%d)", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
1435 * Reading Redirection Table. There are 128 8bit-entries which can be
1436 * manage as 32 32bit-entries
1438 for (i = 0; i < reta_size; i += 4) {
1439 /* Handling 4 RSS entries per loop */
1440 idx = i / RTE_RETA_GROUP_SIZE;
1441 shift = i % RTE_RETA_GROUP_SIZE;
1442 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
1447 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + (idx * 64) +
1449 for (j = 0; j < 4; j++) {
1450 if (!(mask & (0x1 << j)))
1452 reta_conf[idx].reta[shift + j] =
1453 (uint8_t)((reta >> (8 * j)) & 0xF);
1460 nfp_net_rss_hash_write(struct rte_eth_dev *dev,
1461 struct rte_eth_rss_conf *rss_conf)
1463 struct nfp_net_hw *hw;
1465 uint32_t cfg_rss_ctrl = 0;
1469 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1471 /* Writing the key byte a byte */
1472 for (i = 0; i < rss_conf->rss_key_len; i++) {
1473 memcpy(&key, &rss_conf->rss_key[i], 1);
1474 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY + i, key);
1477 rss_hf = rss_conf->rss_hf;
1479 if (rss_hf & ETH_RSS_IPV4)
1480 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4;
1482 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
1483 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4_TCP;
1485 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
1486 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4_UDP;
1488 if (rss_hf & ETH_RSS_IPV6)
1489 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6;
1491 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
1492 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6_TCP;
1494 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
1495 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6_UDP;
1497 cfg_rss_ctrl |= NFP_NET_CFG_RSS_MASK;
1498 cfg_rss_ctrl |= NFP_NET_CFG_RSS_TOEPLITZ;
1500 /* configuring where to apply the RSS hash */
1501 nn_cfg_writel(hw, NFP_NET_CFG_RSS_CTRL, cfg_rss_ctrl);
1503 /* Writing the key size */
1504 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY_SZ, rss_conf->rss_key_len);
1510 nfp_net_rss_hash_update(struct rte_eth_dev *dev,
1511 struct rte_eth_rss_conf *rss_conf)
1515 struct nfp_net_hw *hw;
1517 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1519 rss_hf = rss_conf->rss_hf;
1521 /* Checking if RSS is enabled */
1522 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS)) {
1523 if (rss_hf != 0) { /* Enable RSS? */
1524 PMD_DRV_LOG(ERR, "RSS unsupported");
1527 return 0; /* Nothing to do */
1530 if (rss_conf->rss_key_len > NFP_NET_CFG_RSS_KEY_SZ) {
1531 PMD_DRV_LOG(ERR, "hash key too long");
1535 nfp_net_rss_hash_write(dev, rss_conf);
1537 update = NFP_NET_CFG_UPDATE_RSS;
1539 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
1546 nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev,
1547 struct rte_eth_rss_conf *rss_conf)
1550 uint32_t cfg_rss_ctrl;
1553 struct nfp_net_hw *hw;
1555 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1557 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1560 rss_hf = rss_conf->rss_hf;
1561 cfg_rss_ctrl = nn_cfg_readl(hw, NFP_NET_CFG_RSS_CTRL);
1563 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4)
1564 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV4_UDP;
1566 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_TCP)
1567 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
1569 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_TCP)
1570 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
1572 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_UDP)
1573 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
1575 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_UDP)
1576 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
1578 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6)
1579 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
1581 /* Propagate current RSS hash functions to caller */
1582 rss_conf->rss_hf = rss_hf;
1584 /* Reading the key size */
1585 rss_conf->rss_key_len = nn_cfg_readl(hw, NFP_NET_CFG_RSS_KEY_SZ);
1587 /* Reading the key byte a byte */
1588 for (i = 0; i < rss_conf->rss_key_len; i++) {
1589 key = nn_cfg_readb(hw, NFP_NET_CFG_RSS_KEY + i);
1590 memcpy(&rss_conf->rss_key[i], &key, 1);
1597 nfp_net_rss_config_default(struct rte_eth_dev *dev)
1599 struct rte_eth_conf *dev_conf;
1600 struct rte_eth_rss_conf rss_conf;
1601 struct rte_eth_rss_reta_entry64 nfp_reta_conf[2];
1602 uint16_t rx_queues = dev->data->nb_rx_queues;
1606 PMD_DRV_LOG(INFO, "setting default RSS conf for %u queues",
1609 nfp_reta_conf[0].mask = ~0x0;
1610 nfp_reta_conf[1].mask = ~0x0;
1613 for (i = 0; i < 0x40; i += 8) {
1614 for (j = i; j < (i + 8); j++) {
1615 nfp_reta_conf[0].reta[j] = queue;
1616 nfp_reta_conf[1].reta[j] = queue++;
1620 ret = nfp_net_rss_reta_write(dev, nfp_reta_conf, 0x80);
1624 dev_conf = &dev->data->dev_conf;
1626 PMD_DRV_LOG(INFO, "wrong rss conf");
1629 rss_conf = dev_conf->rx_adv_conf.rss_conf;
1631 ret = nfp_net_rss_hash_write(dev, &rss_conf);
1637 /* Initialise and register driver with DPDK Application */
1638 static const struct eth_dev_ops nfp_net_eth_dev_ops = {
1639 .dev_configure = nfp_net_configure,
1640 .dev_start = nfp_net_start,
1641 .dev_stop = nfp_net_stop,
1642 .dev_set_link_up = nfp_net_set_link_up,
1643 .dev_set_link_down = nfp_net_set_link_down,
1644 .dev_close = nfp_net_close,
1645 .promiscuous_enable = nfp_net_promisc_enable,
1646 .promiscuous_disable = nfp_net_promisc_disable,
1647 .link_update = nfp_net_link_update,
1648 .stats_get = nfp_net_stats_get,
1649 .stats_reset = nfp_net_stats_reset,
1650 .dev_infos_get = nfp_net_infos_get,
1651 .dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
1652 .mtu_set = nfp_net_dev_mtu_set,
1653 .mac_addr_set = nfp_set_mac_addr,
1654 .vlan_offload_set = nfp_net_vlan_offload_set,
1655 .reta_update = nfp_net_reta_update,
1656 .reta_query = nfp_net_reta_query,
1657 .rss_hash_update = nfp_net_rss_hash_update,
1658 .rss_hash_conf_get = nfp_net_rss_hash_conf_get,
1659 .rx_queue_setup = nfp_net_rx_queue_setup,
1660 .rx_queue_release = nfp_net_rx_queue_release,
1661 .tx_queue_setup = nfp_net_tx_queue_setup,
1662 .tx_queue_release = nfp_net_tx_queue_release,
1663 .rx_queue_intr_enable = nfp_rx_queue_intr_enable,
1664 .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
1669 nfp_net_init(struct rte_eth_dev *eth_dev)
1671 struct rte_pci_device *pci_dev;
1672 struct nfp_pf_dev *pf_dev;
1673 struct nfp_net_hw *hw;
1675 uint64_t tx_bar_off = 0, rx_bar_off = 0;
1681 PMD_INIT_FUNC_TRACE();
1683 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1685 /* Use backpointer here to the PF of this eth_dev */
1686 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(eth_dev->data->dev_private);
1688 /* NFP can not handle DMA addresses requiring more than 40 bits */
1689 if (rte_mem_check_dma_mask(40)) {
1690 RTE_LOG(ERR, PMD, "device %s can not be used:",
1691 pci_dev->device.name);
1692 RTE_LOG(ERR, PMD, "\trestricted dma mask to 40 bits!\n");
1696 if ((pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) ||
1697 (pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC)) {
1698 port = ((struct nfp_net_hw *)eth_dev->data->dev_private)->idx;
1699 if (port < 0 || port > 7) {
1700 PMD_DRV_LOG(ERR, "Port value is wrong");
1704 /* Use PF array of physical ports to get pointer to
1705 * this specific port
1707 hw = pf_dev->ports[port];
1709 PMD_INIT_LOG(DEBUG, "Working with physical port number: %d, "
1710 "NFP internal port number: %d",
1714 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
1717 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
1718 eth_dev->rx_queue_count = nfp_net_rx_queue_count;
1719 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
1720 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
1722 /* For secondary processes, the primary has done all the work */
1723 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1726 rte_eth_copy_pci_info(eth_dev, pci_dev);
1728 hw->device_id = pci_dev->id.device_id;
1729 hw->vendor_id = pci_dev->id.vendor_id;
1730 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
1731 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
1733 PMD_INIT_LOG(DEBUG, "nfp_net: device (%u:%u) %u:%u:%u:%u",
1734 pci_dev->id.vendor_id, pci_dev->id.device_id,
1735 pci_dev->addr.domain, pci_dev->addr.bus,
1736 pci_dev->addr.devid, pci_dev->addr.function);
1738 hw->ctrl_bar = (uint8_t *)pci_dev->mem_resource[0].addr;
1739 if (hw->ctrl_bar == NULL) {
1741 "hw->ctrl_bar is NULL. BAR0 not configured");
1745 if (hw->is_phyport) {
1747 hw->ctrl_bar = pf_dev->ctrl_bar;
1749 if (!pf_dev->ctrl_bar)
1751 /* Use port offset in pf ctrl_bar for this
1754 hw->ctrl_bar = pf_dev->ctrl_bar +
1755 (port * NFP_PF_CSR_SLICE_SIZE);
1759 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
1761 hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
1762 hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
1764 /* Work out where in the BAR the queues start. */
1765 switch (pci_dev->id.device_id) {
1766 case PCI_DEVICE_ID_NFP4000_PF_NIC:
1767 case PCI_DEVICE_ID_NFP6000_PF_NIC:
1768 case PCI_DEVICE_ID_NFP6000_VF_NIC:
1769 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
1770 tx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
1771 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ);
1772 rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
1775 PMD_DRV_LOG(ERR, "nfp_net: no device ID matching");
1777 goto dev_err_ctrl_map;
1780 PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off);
1781 PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off);
1783 if (hw->is_phyport) {
1784 hw->tx_bar = pf_dev->hw_queues + tx_bar_off;
1785 hw->rx_bar = pf_dev->hw_queues + rx_bar_off;
1786 eth_dev->data->dev_private = hw;
1788 hw->tx_bar = (uint8_t *)pci_dev->mem_resource[2].addr +
1790 hw->rx_bar = (uint8_t *)pci_dev->mem_resource[2].addr +
1794 PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p",
1795 hw->ctrl_bar, hw->tx_bar, hw->rx_bar);
1797 nfp_net_cfg_queue_setup(hw);
1799 /* Get some of the read-only fields from the config BAR */
1800 hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
1801 hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
1802 hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
1803 hw->mtu = RTE_ETHER_MTU;
1805 /* VLAN insertion is incompatible with LSOv2 */
1806 if (hw->cap & NFP_NET_CFG_CTRL_LSO2)
1807 hw->cap &= ~NFP_NET_CFG_CTRL_TXVLAN;
1809 if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
1810 hw->rx_offset = NFP_NET_RX_OFFSET;
1812 hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
1814 PMD_INIT_LOG(INFO, "VER: %u.%u, Maximum supported MTU: %d",
1815 NFD_CFG_MAJOR_VERSION_of(hw->ver),
1816 NFD_CFG_MINOR_VERSION_of(hw->ver), hw->max_mtu);
1818 PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s%s%s%s%s%s", hw->cap,
1819 hw->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "",
1820 hw->cap & NFP_NET_CFG_CTRL_L2BC ? "L2BCFILT " : "",
1821 hw->cap & NFP_NET_CFG_CTRL_L2MC ? "L2MCFILT " : "",
1822 hw->cap & NFP_NET_CFG_CTRL_RXCSUM ? "RXCSUM " : "",
1823 hw->cap & NFP_NET_CFG_CTRL_TXCSUM ? "TXCSUM " : "",
1824 hw->cap & NFP_NET_CFG_CTRL_RXVLAN ? "RXVLAN " : "",
1825 hw->cap & NFP_NET_CFG_CTRL_TXVLAN ? "TXVLAN " : "",
1826 hw->cap & NFP_NET_CFG_CTRL_SCATTER ? "SCATTER " : "",
1827 hw->cap & NFP_NET_CFG_CTRL_GATHER ? "GATHER " : "",
1828 hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR ? "LIVE_ADDR " : "",
1829 hw->cap & NFP_NET_CFG_CTRL_LSO ? "TSO " : "",
1830 hw->cap & NFP_NET_CFG_CTRL_LSO2 ? "TSOv2 " : "",
1831 hw->cap & NFP_NET_CFG_CTRL_RSS ? "RSS " : "",
1832 hw->cap & NFP_NET_CFG_CTRL_RSS2 ? "RSSv2 " : "");
1836 hw->stride_rx = stride;
1837 hw->stride_tx = stride;
1839 PMD_INIT_LOG(INFO, "max_rx_queues: %u, max_tx_queues: %u",
1840 hw->max_rx_queues, hw->max_tx_queues);
1842 /* Initializing spinlock for reconfigs */
1843 rte_spinlock_init(&hw->reconfig_lock);
1845 /* Allocating memory for mac addr */
1846 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
1847 RTE_ETHER_ADDR_LEN, 0);
1848 if (eth_dev->data->mac_addrs == NULL) {
1849 PMD_INIT_LOG(ERR, "Failed to space for MAC address");
1851 goto dev_err_queues_map;
1854 if (hw->is_phyport) {
1855 nfp_net_pf_read_mac(pf_dev, port);
1856 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
1858 nfp_net_vf_read_mac(hw);
1861 if (!rte_is_valid_assigned_ether_addr(
1862 (struct rte_ether_addr *)&hw->mac_addr)) {
1863 PMD_INIT_LOG(INFO, "Using random mac address for port %d",
1865 /* Using random mac addresses for VFs */
1866 rte_eth_random_addr(&hw->mac_addr[0]);
1867 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
1870 /* Copying mac address to DPDK eth_dev struct */
1871 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
1872 ð_dev->data->mac_addrs[0]);
1874 if (!(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
1875 eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
1877 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1879 PMD_INIT_LOG(INFO, "port %d VendorID=0x%x DeviceID=0x%x "
1880 "mac=%02x:%02x:%02x:%02x:%02x:%02x",
1881 eth_dev->data->port_id, pci_dev->id.vendor_id,
1882 pci_dev->id.device_id,
1883 hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
1884 hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
1886 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1887 /* Registering LSC interrupt handler */
1888 rte_intr_callback_register(&pci_dev->intr_handle,
1889 nfp_net_dev_interrupt_handler,
1891 /* Telling the firmware about the LSC interrupt entry */
1892 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, NFP_NET_IRQ_LSC_IDX);
1893 /* Recording current stats counters values */
1894 nfp_net_stats_reset(eth_dev);
1900 nfp_cpp_area_free(hw->hwqueues_area);
1902 nfp_cpp_area_free(hw->ctrl_area);
1907 #define DEFAULT_FW_PATH "/lib/firmware/netronome"
1910 nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card)
1912 struct nfp_cpp *cpp = nsp->cpp;
1918 /* Looking for firmware file in order of priority */
1920 /* First try to find a firmware image specific for this device */
1921 snprintf(serial, sizeof(serial),
1922 "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
1923 cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3],
1924 cpp->serial[4], cpp->serial[5], cpp->interface >> 8,
1925 cpp->interface & 0xff);
1927 snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH,
1929 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
1930 if (rte_firmware_read(fw_name, &fw_buf, &fsize) == 0)
1933 /* Then try the PCI name */
1934 snprintf(fw_name, sizeof(fw_name), "%s/pci-%s.nffw", DEFAULT_FW_PATH,
1936 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
1937 if (rte_firmware_read(fw_name, &fw_buf, &fsize) == 0)
1940 /* Finally try the card type and media */
1941 snprintf(fw_name, sizeof(fw_name), "%s/%s", DEFAULT_FW_PATH, card);
1942 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
1943 if (rte_firmware_read(fw_name, &fw_buf, &fsize) < 0) {
1944 PMD_DRV_LOG(INFO, "Firmware file %s not found.", fw_name);
1949 PMD_DRV_LOG(INFO, "Firmware file found at %s with size: %zu",
1952 PMD_DRV_LOG(INFO, "Uploading the firmware ...");
1953 nfp_nsp_load_fw(nsp, fw_buf, fsize);
1954 PMD_DRV_LOG(INFO, "Done");
1961 nfp_fw_setup(struct rte_pci_device *dev, struct nfp_cpp *cpp,
1962 struct nfp_eth_table *nfp_eth_table, struct nfp_hwinfo *hwinfo)
1964 struct nfp_nsp *nsp;
1965 const char *nfp_fw_model;
1966 char card_desc[100];
1969 nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "assembly.partno");
1972 PMD_DRV_LOG(INFO, "firmware model found: %s", nfp_fw_model);
1974 PMD_DRV_LOG(ERR, "firmware model NOT found");
1978 if (nfp_eth_table->count == 0 || nfp_eth_table->count > 8) {
1979 PMD_DRV_LOG(ERR, "NFP ethernet table reports wrong ports: %u",
1980 nfp_eth_table->count);
1984 PMD_DRV_LOG(INFO, "NFP ethernet port table reports %u ports",
1985 nfp_eth_table->count);
1987 PMD_DRV_LOG(INFO, "Port speed: %u", nfp_eth_table->ports[0].speed);
1989 snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
1990 nfp_fw_model, nfp_eth_table->count,
1991 nfp_eth_table->ports[0].speed / 1000);
1993 nsp = nfp_nsp_open(cpp);
1995 PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle");
1999 nfp_nsp_device_soft_reset(nsp);
2000 err = nfp_fw_upload(dev, nsp, card_desc);
2006 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
2008 struct nfp_net_hw *hw;
2009 struct rte_eth_dev *eth_dev;
2010 struct nfp_eth_table *nfp_eth_table = NULL;
2014 nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
2015 if (!nfp_eth_table) {
2016 PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
2021 /* Loop through all physical ports on PF */
2022 for (i = 0; i < pf_dev->total_phyports; i++) {
2023 const unsigned int numa_node = rte_socket_id();
2024 char port_name[RTE_ETH_NAME_MAX_LEN];
2026 snprintf(port_name, sizeof(port_name), "%s_port%d",
2027 pf_dev->pci_dev->device.name, i);
2029 /* Allocate a eth_dev for this phyport */
2030 eth_dev = rte_eth_dev_allocate(port_name);
2036 /* Allocate memory for this phyport */
2037 eth_dev->data->dev_private =
2038 rte_zmalloc_socket(port_name, sizeof(struct nfp_net_hw),
2039 RTE_CACHE_LINE_SIZE, numa_node);
2040 if (!eth_dev->data->dev_private) {
2042 rte_eth_dev_release_port(eth_dev);
2046 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2048 /* Add this device to the PF's array of physical ports */
2049 pf_dev->ports[i] = hw;
2051 hw->pf_dev = pf_dev;
2052 hw->cpp = pf_dev->cpp;
2053 hw->eth_dev = eth_dev;
2055 hw->nfp_idx = nfp_eth_table->ports[i].index;
2056 hw->is_phyport = true;
2058 eth_dev->device = &pf_dev->pci_dev->device;
2060 /* ctrl/tx/rx BAR mappings and remaining init happens in
2063 ret = nfp_net_init(eth_dev);
2070 rte_eth_dev_probing_finish(eth_dev);
2072 } /* End loop, all ports on this PF */
2074 goto eth_table_cleanup;
2077 for (i = 0; i < pf_dev->total_phyports; i++) {
2078 if (pf_dev->ports[i] && pf_dev->ports[i]->eth_dev) {
2079 struct rte_eth_dev *tmp_dev;
2080 tmp_dev = pf_dev->ports[i]->eth_dev;
2081 rte_eth_dev_release_port(tmp_dev);
2082 pf_dev->ports[i] = NULL;
2086 free(nfp_eth_table);
2091 static int nfp_pf_init(struct rte_pci_device *pci_dev)
2093 struct nfp_pf_dev *pf_dev = NULL;
2094 struct nfp_cpp *cpp;
2095 struct nfp_hwinfo *hwinfo;
2096 struct nfp_rtsym_table *sym_tbl;
2097 struct nfp_eth_table *nfp_eth_table = NULL;
2098 char name[RTE_ETH_NAME_MAX_LEN];
2107 * When device bound to UIO, the device could be used, by mistake,
2108 * by two DPDK apps, and the UIO driver does not avoid it. This
2109 * could lead to a serious problem when configuring the NFP CPP
2110 * interface. Here we avoid this telling to the CPP init code to
2111 * use a lock file if UIO is being used.
2113 if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
2114 cpp = nfp_cpp_from_device_name(pci_dev, 0);
2116 cpp = nfp_cpp_from_device_name(pci_dev, 1);
2119 PMD_INIT_LOG(ERR, "A CPP handle can not be obtained");
2124 hwinfo = nfp_hwinfo_read(cpp);
2126 PMD_INIT_LOG(ERR, "Error reading hwinfo table");
2131 nfp_eth_table = nfp_eth_read_ports(cpp);
2132 if (!nfp_eth_table) {
2133 PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
2135 goto hwinfo_cleanup;
2138 if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo)) {
2139 PMD_INIT_LOG(ERR, "Error when uploading firmware");
2141 goto eth_table_cleanup;
2144 /* Now the symbol table should be there */
2145 sym_tbl = nfp_rtsym_table_read(cpp);
2147 PMD_INIT_LOG(ERR, "Something is wrong with the firmware"
2150 goto eth_table_cleanup;
2153 total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
2154 if (total_ports != (int)nfp_eth_table->count) {
2155 PMD_DRV_LOG(ERR, "Inconsistent number of ports");
2157 goto sym_tbl_cleanup;
2160 PMD_INIT_LOG(INFO, "Total physical ports: %d", total_ports);
2162 if (total_ports <= 0 || total_ports > 8) {
2163 PMD_INIT_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value");
2165 goto sym_tbl_cleanup;
2167 /* Allocate memory for the PF "device" */
2168 snprintf(name, sizeof(name), "nfp_pf%d", 0);
2169 pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
2172 goto sym_tbl_cleanup;
2175 /* Populate the newly created PF device */
2177 pf_dev->hwinfo = hwinfo;
2178 pf_dev->sym_tbl = sym_tbl;
2179 pf_dev->total_phyports = total_ports;
2181 if (total_ports > 1)
2182 pf_dev->multiport = true;
2184 pf_dev->pci_dev = pci_dev;
2186 /* Map the symbol table */
2187 pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0",
2188 pf_dev->total_phyports * 32768,
2189 &pf_dev->ctrl_area);
2190 if (!pf_dev->ctrl_bar) {
2191 PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for _pf0_net_ctrl_bar");
2196 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar);
2198 /* configure access to tx/rx vNIC BARs */
2199 pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, 0, 0,
2201 NFP_QCP_QUEUE_AREA_SZ,
2202 &pf_dev->hwqueues_area);
2203 if (!pf_dev->hw_queues) {
2204 PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc");
2206 goto ctrl_area_cleanup;
2209 PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues);
2211 /* Initialize and prep physical ports now
2212 * This will loop through all physical ports
2214 ret = nfp_init_phyports(pf_dev);
2216 PMD_INIT_LOG(ERR, "Could not create physical ports");
2217 goto hwqueues_cleanup;
2220 /* register the CPP bridge service here for primary use */
2221 nfp_register_cpp_service(pf_dev->cpp);
2226 nfp_cpp_area_free(pf_dev->hwqueues_area);
2228 nfp_cpp_area_free(pf_dev->ctrl_area);
2234 free(nfp_eth_table);
2242 * When attaching to the NFP4000/6000 PF on a secondary process there
2243 * is no need to initialize the PF again. Only minimal work is required
2246 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
2248 struct nfp_cpp *cpp;
2249 struct nfp_rtsym_table *sym_tbl;
2258 * When device bound to UIO, the device could be used, by mistake,
2259 * by two DPDK apps, and the UIO driver does not avoid it. This
2260 * could lead to a serious problem when configuring the NFP CPP
2261 * interface. Here we avoid this telling to the CPP init code to
2262 * use a lock file if UIO is being used.
2264 if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
2265 cpp = nfp_cpp_from_device_name(pci_dev, 0);
2267 cpp = nfp_cpp_from_device_name(pci_dev, 1);
2270 PMD_INIT_LOG(ERR, "A CPP handle can not be obtained");
2275 * We don't have access to the PF created in the primary process
2276 * here so we have to read the number of ports from firmware
2278 sym_tbl = nfp_rtsym_table_read(cpp);
2280 PMD_INIT_LOG(ERR, "Something is wrong with the firmware"
2285 total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
2287 for (i = 0; i < total_ports; i++) {
2288 struct rte_eth_dev *eth_dev;
2289 char port_name[RTE_ETH_NAME_MAX_LEN];
2291 snprintf(port_name, sizeof(port_name), "%s_port%d",
2292 pci_dev->device.name, i);
2294 PMD_DRV_LOG(DEBUG, "Secondary attaching to port %s",
2296 eth_dev = rte_eth_dev_attach_secondary(port_name);
2299 "secondary process attach failed, "
2300 "ethdev doesn't exist");
2303 eth_dev->process_private = cpp;
2304 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
2305 eth_dev->rx_queue_count = nfp_net_rx_queue_count;
2306 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
2307 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
2308 rte_eth_dev_probing_finish(eth_dev);
2311 /* Register the CPP bridge service for the secondary too */
2312 nfp_register_cpp_service(cpp);
2317 static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2318 struct rte_pci_device *dev)
2320 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2321 return nfp_pf_init(dev);
2323 return nfp_pf_secondary_init(dev);
2326 static const struct rte_pci_id pci_id_nfp_pf_net_map[] = {
2328 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2329 PCI_DEVICE_ID_NFP4000_PF_NIC)
2332 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2333 PCI_DEVICE_ID_NFP6000_PF_NIC)
2340 static const struct rte_pci_id pci_id_nfp_vf_net_map[] = {
2342 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
2343 PCI_DEVICE_ID_NFP6000_VF_NIC)
2350 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev)
2352 struct rte_pci_device *pci_dev;
2355 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2357 if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
2358 pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
2359 /* Free up all physical ports under PF */
2360 RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
2361 rte_eth_dev_close(port_id);
2363 * Ports can be closed and freed but hotplugging is not
2364 * currently supported
2369 /* VF cleanup, just free private port data */
2370 return nfp_net_close(eth_dev);
2373 static int eth_nfp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
2374 struct rte_pci_device *pci_dev)
2376 return rte_eth_dev_pci_generic_probe(pci_dev,
2377 sizeof(struct nfp_net_adapter), nfp_net_init);
2380 static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
2382 return rte_eth_dev_pci_generic_remove(pci_dev, nfp_pci_uninit);
2385 static struct rte_pci_driver rte_nfp_net_pf_pmd = {
2386 .id_table = pci_id_nfp_pf_net_map,
2387 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2388 .probe = nfp_pf_pci_probe,
2389 .remove = eth_nfp_pci_remove,
2392 static struct rte_pci_driver rte_nfp_net_vf_pmd = {
2393 .id_table = pci_id_nfp_vf_net_map,
2394 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
2395 .probe = eth_nfp_pci_probe,
2396 .remove = eth_nfp_pci_remove,
2399 RTE_PMD_REGISTER_PCI(net_nfp_pf, rte_nfp_net_pf_pmd);
2400 RTE_PMD_REGISTER_PCI(net_nfp_vf, rte_nfp_net_vf_pmd);
2401 RTE_PMD_REGISTER_PCI_TABLE(net_nfp_pf, pci_id_nfp_pf_net_map);
2402 RTE_PMD_REGISTER_PCI_TABLE(net_nfp_vf, pci_id_nfp_vf_net_map);
2403 RTE_PMD_REGISTER_KMOD_DEP(net_nfp_pf, "* igb_uio | uio_pci_generic | vfio");
2404 RTE_PMD_REGISTER_KMOD_DEP(net_nfp_vf, "* igb_uio | uio_pci_generic | vfio");
2405 RTE_LOG_REGISTER_SUFFIX(nfp_logtype_init, init, NOTICE);
2406 RTE_LOG_REGISTER_SUFFIX(nfp_logtype_driver, driver, NOTICE);
2409 * c-file-style: "Linux"
2410 * indent-tabs-mode: t