1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2014-2021 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_ethdev.c
13 * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
16 #include <rte_common.h>
17 #include <ethdev_driver.h>
18 #include <ethdev_pci.h>
20 #include <rte_ether.h>
21 #include <rte_malloc.h>
22 #include <rte_memzone.h>
23 #include <rte_mempool.h>
24 #include <rte_service_component.h>
25 #include <rte_alarm.h>
26 #include "eal_firmware.h"
28 #include "nfpcore/nfp_cpp.h"
29 #include "nfpcore/nfp_nffw.h"
30 #include "nfpcore/nfp_hwinfo.h"
31 #include "nfpcore/nfp_mip.h"
32 #include "nfpcore/nfp_rtsym.h"
33 #include "nfpcore/nfp_nsp.h"
35 #include "nfp_common.h"
39 #include "nfp_cpp_bridge.h"
42 static int nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port);
43 static int nfp_net_start(struct rte_eth_dev *dev);
44 static int nfp_net_stop(struct rte_eth_dev *dev);
45 static int nfp_net_set_link_up(struct rte_eth_dev *dev);
46 static int nfp_net_set_link_down(struct rte_eth_dev *dev);
47 static int nfp_net_close(struct rte_eth_dev *dev);
48 static int nfp_net_init(struct rte_eth_dev *eth_dev);
49 static int nfp_fw_upload(struct rte_pci_device *dev,
50 struct nfp_nsp *nsp, char *card);
51 static int nfp_fw_setup(struct rte_pci_device *dev,
53 struct nfp_eth_table *nfp_eth_table,
54 struct nfp_hwinfo *hwinfo);
55 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
56 static int nfp_pf_init(struct rte_pci_device *pci_dev);
57 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev);
58 static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
59 struct rte_pci_device *dev);
60 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
61 static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev);
64 nfp_net_pf_read_mac(struct nfp_pf_dev *pf_dev, int port)
66 struct nfp_eth_table *nfp_eth_table;
67 struct nfp_net_hw *hw = NULL;
69 /* Grab a pointer to the correct physical port */
70 hw = pf_dev->ports[port];
72 nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
74 nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
75 (uint8_t *)&nfp_eth_table->ports[port].mac_addr);
82 nfp_net_start(struct rte_eth_dev *dev)
84 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
85 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
86 uint32_t new_ctrl, update = 0;
87 struct nfp_net_hw *hw;
88 struct nfp_pf_dev *pf_dev;
89 struct rte_eth_conf *dev_conf;
90 struct rte_eth_rxmode *rxmode;
94 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
95 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
97 PMD_INIT_LOG(DEBUG, "Start");
99 /* Disabling queues just in case... */
100 nfp_net_disable_queues(dev);
102 /* Enabling the required queues in the device */
103 nfp_net_enable_queues(dev);
105 /* check and configure queue intr-vector mapping */
106 if (dev->data->dev_conf.intr_conf.rxq != 0) {
107 if (pf_dev->multiport) {
108 PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
109 "with NFP multiport PF");
112 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
114 * Better not to share LSC with RX interrupts.
115 * Unregistering LSC interrupt handler
117 rte_intr_callback_unregister(&pci_dev->intr_handle,
118 nfp_net_dev_interrupt_handler, (void *)dev);
120 if (dev->data->nb_rx_queues > 1) {
121 PMD_INIT_LOG(ERR, "PMD rx interrupt only "
122 "supports 1 queue with UIO");
126 intr_vector = dev->data->nb_rx_queues;
127 if (rte_intr_efd_enable(intr_handle, intr_vector))
130 nfp_configure_rx_interrupt(dev, intr_handle);
131 update = NFP_NET_CFG_UPDATE_MSIX;
134 rte_intr_enable(intr_handle);
136 new_ctrl = nfp_check_offloads(dev);
138 /* Writing configuration parameters in the device */
139 nfp_net_params_setup(hw);
141 dev_conf = &dev->data->dev_conf;
142 rxmode = &dev_conf->rxmode;
144 if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
145 nfp_net_rss_config_default(dev);
146 update |= NFP_NET_CFG_UPDATE_RSS;
147 new_ctrl |= NFP_NET_CFG_CTRL_RSS;
151 new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
153 update |= NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING;
155 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
156 new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
158 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, new_ctrl);
159 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
163 * Allocating rte mbufs for configured rx queues.
164 * This requires queues being enabled before
166 if (nfp_net_rx_freelist_setup(dev) < 0) {
171 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
172 /* Configure the physical port up */
173 nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
175 nfp_eth_set_configured(dev->process_private,
184 * An error returned by this function should mean the app
185 * exiting and then the system releasing all the memory
186 * allocated even memory coming from hugepages.
188 * The device could be enabled at this point with some queues
189 * ready for getting packets. This is true if the call to
190 * nfp_net_rx_freelist_setup() succeeds for some queues but
191 * fails for subsequent queues.
193 * This should make the app exiting but better if we tell the
196 nfp_net_disable_queues(dev);
201 /* Stop device: disable rx and tx functions to allow for reconfiguring. */
203 nfp_net_stop(struct rte_eth_dev *dev)
206 struct nfp_net_hw *hw;
207 struct nfp_net_txq *this_tx_q;
208 struct nfp_net_rxq *this_rx_q;
210 PMD_INIT_LOG(DEBUG, "Stop");
212 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
214 nfp_net_disable_queues(dev);
217 for (i = 0; i < dev->data->nb_tx_queues; i++) {
218 this_tx_q = (struct nfp_net_txq *)dev->data->tx_queues[i];
219 nfp_net_reset_tx_queue(this_tx_q);
222 for (i = 0; i < dev->data->nb_rx_queues; i++) {
223 this_rx_q = (struct nfp_net_rxq *)dev->data->rx_queues[i];
224 nfp_net_reset_rx_queue(this_rx_q);
227 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
228 /* Configure the physical port down */
229 nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
231 nfp_eth_set_configured(dev->process_private,
237 /* Set the link up. */
239 nfp_net_set_link_up(struct rte_eth_dev *dev)
241 struct nfp_net_hw *hw;
243 PMD_DRV_LOG(DEBUG, "Set link up");
245 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
247 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
248 /* Configure the physical port down */
249 return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 1);
251 return nfp_eth_set_configured(dev->process_private,
255 /* Set the link down. */
257 nfp_net_set_link_down(struct rte_eth_dev *dev)
259 struct nfp_net_hw *hw;
261 PMD_DRV_LOG(DEBUG, "Set link down");
263 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
265 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
266 /* Configure the physical port down */
267 return nfp_eth_set_configured(hw->cpp, hw->nfp_idx, 0);
269 return nfp_eth_set_configured(dev->process_private,
273 /* Reset and stop device. The device can not be restarted. */
275 nfp_net_close(struct rte_eth_dev *dev)
277 struct nfp_net_hw *hw;
278 struct rte_pci_device *pci_dev;
279 struct nfp_pf_dev *pf_dev;
280 struct nfp_net_txq *this_tx_q;
281 struct nfp_net_rxq *this_rx_q;
284 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
287 PMD_INIT_LOG(DEBUG, "Close");
289 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
290 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
291 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
294 * We assume that the DPDK application is stopping all the
295 * threads/queues before calling the device close function.
298 nfp_net_disable_queues(dev);
301 for (i = 0; i < dev->data->nb_tx_queues; i++) {
302 this_tx_q = (struct nfp_net_txq *)dev->data->tx_queues[i];
303 nfp_net_reset_tx_queue(this_tx_q);
306 for (i = 0; i < dev->data->nb_rx_queues; i++) {
307 this_rx_q = (struct nfp_net_rxq *)dev->data->rx_queues[i];
308 nfp_net_reset_rx_queue(this_rx_q);
311 /* Cancel possible impending LSC work here before releasing the port*/
312 rte_eal_alarm_cancel(nfp_net_dev_interrupt_delayed_handler,
315 /* Only free PF resources after all physical ports have been closed */
316 /* Mark this port as unused and free device priv resources*/
317 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
318 pf_dev->ports[hw->idx] = NULL;
319 rte_eth_dev_release_port(dev);
321 for (i = 0; i < pf_dev->total_phyports; i++) {
322 /* Check to see if ports are still in use */
323 if (pf_dev->ports[i])
327 /* Now it is safe to free all PF resources */
328 PMD_INIT_LOG(INFO, "Freeing PF resources");
329 nfp_cpp_area_free(pf_dev->ctrl_area);
330 nfp_cpp_area_free(pf_dev->hwqueues_area);
331 free(pf_dev->hwinfo);
332 free(pf_dev->sym_tbl);
333 nfp_cpp_free(pf_dev->cpp);
336 rte_intr_disable(&pci_dev->intr_handle);
338 /* unregister callback func from eal lib */
339 rte_intr_callback_unregister(&pci_dev->intr_handle,
340 nfp_net_dev_interrupt_handler,
344 * The ixgbe PMD driver disables the pcie master on the
345 * device. The i40e does not...
351 /* Initialise and register driver with DPDK Application */
352 static const struct eth_dev_ops nfp_net_eth_dev_ops = {
353 .dev_configure = nfp_net_configure,
354 .dev_start = nfp_net_start,
355 .dev_stop = nfp_net_stop,
356 .dev_set_link_up = nfp_net_set_link_up,
357 .dev_set_link_down = nfp_net_set_link_down,
358 .dev_close = nfp_net_close,
359 .promiscuous_enable = nfp_net_promisc_enable,
360 .promiscuous_disable = nfp_net_promisc_disable,
361 .link_update = nfp_net_link_update,
362 .stats_get = nfp_net_stats_get,
363 .stats_reset = nfp_net_stats_reset,
364 .dev_infos_get = nfp_net_infos_get,
365 .dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
366 .mtu_set = nfp_net_dev_mtu_set,
367 .mac_addr_set = nfp_set_mac_addr,
368 .vlan_offload_set = nfp_net_vlan_offload_set,
369 .reta_update = nfp_net_reta_update,
370 .reta_query = nfp_net_reta_query,
371 .rss_hash_update = nfp_net_rss_hash_update,
372 .rss_hash_conf_get = nfp_net_rss_hash_conf_get,
373 .rx_queue_setup = nfp_net_rx_queue_setup,
374 .rx_queue_release = nfp_net_rx_queue_release,
375 .tx_queue_setup = nfp_net_tx_queue_setup,
376 .tx_queue_release = nfp_net_tx_queue_release,
377 .rx_queue_intr_enable = nfp_rx_queue_intr_enable,
378 .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
382 nfp_net_init(struct rte_eth_dev *eth_dev)
384 struct rte_pci_device *pci_dev;
385 struct nfp_pf_dev *pf_dev;
386 struct nfp_net_hw *hw;
387 struct rte_ether_addr *tmp_ether_addr;
389 uint64_t tx_bar_off = 0, rx_bar_off = 0;
395 PMD_INIT_FUNC_TRACE();
397 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
399 /* Use backpointer here to the PF of this eth_dev */
400 pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(eth_dev->data->dev_private);
402 /* NFP can not handle DMA addresses requiring more than 40 bits */
403 if (rte_mem_check_dma_mask(40)) {
404 RTE_LOG(ERR, PMD, "device %s can not be used:",
405 pci_dev->device.name);
406 RTE_LOG(ERR, PMD, "\trestricted dma mask to 40 bits!\n");
410 port = ((struct nfp_net_hw *)eth_dev->data->dev_private)->idx;
411 if (port < 0 || port > 7) {
412 PMD_DRV_LOG(ERR, "Port value is wrong");
416 /* Use PF array of physical ports to get pointer to
419 hw = pf_dev->ports[port];
421 PMD_INIT_LOG(DEBUG, "Working with physical port number: %d, "
422 "NFP internal port number: %d",
425 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
426 eth_dev->rx_queue_count = nfp_net_rx_queue_count;
427 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
428 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
430 /* For secondary processes, the primary has done all the work */
431 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
434 rte_eth_copy_pci_info(eth_dev, pci_dev);
436 hw->device_id = pci_dev->id.device_id;
437 hw->vendor_id = pci_dev->id.vendor_id;
438 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
439 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
441 PMD_INIT_LOG(DEBUG, "nfp_net: device (%u:%u) %u:%u:%u:%u",
442 pci_dev->id.vendor_id, pci_dev->id.device_id,
443 pci_dev->addr.domain, pci_dev->addr.bus,
444 pci_dev->addr.devid, pci_dev->addr.function);
446 hw->ctrl_bar = (uint8_t *)pci_dev->mem_resource[0].addr;
447 if (hw->ctrl_bar == NULL) {
449 "hw->ctrl_bar is NULL. BAR0 not configured");
454 hw->ctrl_bar = pf_dev->ctrl_bar;
456 if (!pf_dev->ctrl_bar)
458 /* Use port offset in pf ctrl_bar for this
461 hw->ctrl_bar = pf_dev->ctrl_bar +
462 (port * NFP_PF_CSR_SLICE_SIZE);
465 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
467 hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
468 hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
470 /* Work out where in the BAR the queues start. */
471 switch (pci_dev->id.device_id) {
472 case PCI_DEVICE_ID_NFP4000_PF_NIC:
473 case PCI_DEVICE_ID_NFP6000_PF_NIC:
474 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
475 tx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
476 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ);
477 rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
480 PMD_DRV_LOG(ERR, "nfp_net: no device ID matching");
482 goto dev_err_ctrl_map;
485 PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off);
486 PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off);
488 hw->tx_bar = pf_dev->hw_queues + tx_bar_off;
489 hw->rx_bar = pf_dev->hw_queues + rx_bar_off;
490 eth_dev->data->dev_private = hw;
492 PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p",
493 hw->ctrl_bar, hw->tx_bar, hw->rx_bar);
495 nfp_net_cfg_queue_setup(hw);
497 /* Get some of the read-only fields from the config BAR */
498 hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
499 hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
500 hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
501 hw->mtu = RTE_ETHER_MTU;
503 /* VLAN insertion is incompatible with LSOv2 */
504 if (hw->cap & NFP_NET_CFG_CTRL_LSO2)
505 hw->cap &= ~NFP_NET_CFG_CTRL_TXVLAN;
507 if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
508 hw->rx_offset = NFP_NET_RX_OFFSET;
510 hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
512 PMD_INIT_LOG(INFO, "VER: %u.%u, Maximum supported MTU: %d",
513 NFD_CFG_MAJOR_VERSION_of(hw->ver),
514 NFD_CFG_MINOR_VERSION_of(hw->ver), hw->max_mtu);
516 PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s%s%s%s%s%s", hw->cap,
517 hw->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "",
518 hw->cap & NFP_NET_CFG_CTRL_L2BC ? "L2BCFILT " : "",
519 hw->cap & NFP_NET_CFG_CTRL_L2MC ? "L2MCFILT " : "",
520 hw->cap & NFP_NET_CFG_CTRL_RXCSUM ? "RXCSUM " : "",
521 hw->cap & NFP_NET_CFG_CTRL_TXCSUM ? "TXCSUM " : "",
522 hw->cap & NFP_NET_CFG_CTRL_RXVLAN ? "RXVLAN " : "",
523 hw->cap & NFP_NET_CFG_CTRL_TXVLAN ? "TXVLAN " : "",
524 hw->cap & NFP_NET_CFG_CTRL_SCATTER ? "SCATTER " : "",
525 hw->cap & NFP_NET_CFG_CTRL_GATHER ? "GATHER " : "",
526 hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR ? "LIVE_ADDR " : "",
527 hw->cap & NFP_NET_CFG_CTRL_LSO ? "TSO " : "",
528 hw->cap & NFP_NET_CFG_CTRL_LSO2 ? "TSOv2 " : "",
529 hw->cap & NFP_NET_CFG_CTRL_RSS ? "RSS " : "",
530 hw->cap & NFP_NET_CFG_CTRL_RSS2 ? "RSSv2 " : "");
534 hw->stride_rx = stride;
535 hw->stride_tx = stride;
537 PMD_INIT_LOG(INFO, "max_rx_queues: %u, max_tx_queues: %u",
538 hw->max_rx_queues, hw->max_tx_queues);
540 /* Initializing spinlock for reconfigs */
541 rte_spinlock_init(&hw->reconfig_lock);
543 /* Allocating memory for mac addr */
544 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
545 RTE_ETHER_ADDR_LEN, 0);
546 if (eth_dev->data->mac_addrs == NULL) {
547 PMD_INIT_LOG(ERR, "Failed to space for MAC address");
549 goto dev_err_queues_map;
552 nfp_net_pf_read_mac(pf_dev, port);
553 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
555 tmp_ether_addr = (struct rte_ether_addr *)&hw->mac_addr;
556 if (!rte_is_valid_assigned_ether_addr(tmp_ether_addr)) {
557 PMD_INIT_LOG(INFO, "Using random mac address for port %d",
559 /* Using random mac addresses for VFs */
560 rte_eth_random_addr(&hw->mac_addr[0]);
561 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
564 /* Copying mac address to DPDK eth_dev struct */
565 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
566 ð_dev->data->mac_addrs[0]);
568 if (!(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
569 eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
571 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
573 PMD_INIT_LOG(INFO, "port %d VendorID=0x%x DeviceID=0x%x "
574 "mac=" RTE_ETHER_ADDR_PRT_FMT,
575 eth_dev->data->port_id, pci_dev->id.vendor_id,
576 pci_dev->id.device_id,
577 hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
578 hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
580 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
581 /* Registering LSC interrupt handler */
582 rte_intr_callback_register(&pci_dev->intr_handle,
583 nfp_net_dev_interrupt_handler,
585 /* Telling the firmware about the LSC interrupt entry */
586 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, NFP_NET_IRQ_LSC_IDX);
587 /* Recording current stats counters values */
588 nfp_net_stats_reset(eth_dev);
594 nfp_cpp_area_free(hw->hwqueues_area);
596 nfp_cpp_area_free(hw->ctrl_area);
601 #define DEFAULT_FW_PATH "/lib/firmware/netronome"
604 nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card)
606 struct nfp_cpp *cpp = nsp->cpp;
612 /* Looking for firmware file in order of priority */
614 /* First try to find a firmware image specific for this device */
615 snprintf(serial, sizeof(serial),
616 "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
617 cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3],
618 cpp->serial[4], cpp->serial[5], cpp->interface >> 8,
619 cpp->interface & 0xff);
621 snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH,
624 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
625 if (rte_firmware_read(fw_name, &fw_buf, &fsize) == 0)
627 /* Then try the PCI name */
628 snprintf(fw_name, sizeof(fw_name), "%s/pci-%s.nffw", DEFAULT_FW_PATH,
631 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
632 if (rte_firmware_read(fw_name, &fw_buf, &fsize) == 0)
635 /* Finally try the card type and media */
636 snprintf(fw_name, sizeof(fw_name), "%s/%s", DEFAULT_FW_PATH, card);
637 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
638 if (rte_firmware_read(fw_name, &fw_buf, &fsize) < 0) {
639 PMD_DRV_LOG(INFO, "Firmware file %s not found.", fw_name);
644 PMD_DRV_LOG(INFO, "Firmware file found at %s with size: %zu",
646 PMD_DRV_LOG(INFO, "Uploading the firmware ...");
647 nfp_nsp_load_fw(nsp, fw_buf, fsize);
648 PMD_DRV_LOG(INFO, "Done");
656 nfp_fw_setup(struct rte_pci_device *dev, struct nfp_cpp *cpp,
657 struct nfp_eth_table *nfp_eth_table, struct nfp_hwinfo *hwinfo)
660 const char *nfp_fw_model;
664 nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "assembly.partno");
667 PMD_DRV_LOG(INFO, "firmware model found: %s", nfp_fw_model);
669 PMD_DRV_LOG(ERR, "firmware model NOT found");
673 if (nfp_eth_table->count == 0 || nfp_eth_table->count > 8) {
674 PMD_DRV_LOG(ERR, "NFP ethernet table reports wrong ports: %u",
675 nfp_eth_table->count);
679 PMD_DRV_LOG(INFO, "NFP ethernet port table reports %u ports",
680 nfp_eth_table->count);
682 PMD_DRV_LOG(INFO, "Port speed: %u", nfp_eth_table->ports[0].speed);
684 snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
685 nfp_fw_model, nfp_eth_table->count,
686 nfp_eth_table->ports[0].speed / 1000);
688 nsp = nfp_nsp_open(cpp);
690 PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle");
694 nfp_nsp_device_soft_reset(nsp);
695 err = nfp_fw_upload(dev, nsp, card_desc);
701 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev)
703 struct nfp_net_hw *hw;
704 struct rte_eth_dev *eth_dev;
705 struct nfp_eth_table *nfp_eth_table = NULL;
709 nfp_eth_table = nfp_eth_read_ports(pf_dev->cpp);
710 if (!nfp_eth_table) {
711 PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
716 /* Loop through all physical ports on PF */
717 for (i = 0; i < pf_dev->total_phyports; i++) {
718 const unsigned int numa_node = rte_socket_id();
719 char port_name[RTE_ETH_NAME_MAX_LEN];
721 snprintf(port_name, sizeof(port_name), "%s_port%d",
722 pf_dev->pci_dev->device.name, i);
724 /* Allocate a eth_dev for this phyport */
725 eth_dev = rte_eth_dev_allocate(port_name);
731 /* Allocate memory for this phyport */
732 eth_dev->data->dev_private =
733 rte_zmalloc_socket(port_name, sizeof(struct nfp_net_hw),
734 RTE_CACHE_LINE_SIZE, numa_node);
735 if (!eth_dev->data->dev_private) {
737 rte_eth_dev_release_port(eth_dev);
741 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
743 /* Add this device to the PF's array of physical ports */
744 pf_dev->ports[i] = hw;
747 hw->cpp = pf_dev->cpp;
748 hw->eth_dev = eth_dev;
750 hw->nfp_idx = nfp_eth_table->ports[i].index;
751 hw->is_phyport = true;
753 eth_dev->device = &pf_dev->pci_dev->device;
755 /* ctrl/tx/rx BAR mappings and remaining init happens in
758 ret = nfp_net_init(eth_dev);
765 rte_eth_dev_probing_finish(eth_dev);
767 } /* End loop, all ports on this PF */
769 goto eth_table_cleanup;
772 for (i = 0; i < pf_dev->total_phyports; i++) {
773 if (pf_dev->ports[i] && pf_dev->ports[i]->eth_dev) {
774 struct rte_eth_dev *tmp_dev;
775 tmp_dev = pf_dev->ports[i]->eth_dev;
776 rte_eth_dev_release_port(tmp_dev);
777 pf_dev->ports[i] = NULL;
786 static int nfp_pf_init(struct rte_pci_device *pci_dev)
788 struct nfp_pf_dev *pf_dev = NULL;
790 struct nfp_hwinfo *hwinfo;
791 struct nfp_rtsym_table *sym_tbl;
792 struct nfp_eth_table *nfp_eth_table = NULL;
793 char name[RTE_ETH_NAME_MAX_LEN];
802 * When device bound to UIO, the device could be used, by mistake,
803 * by two DPDK apps, and the UIO driver does not avoid it. This
804 * could lead to a serious problem when configuring the NFP CPP
805 * interface. Here we avoid this telling to the CPP init code to
806 * use a lock file if UIO is being used.
808 if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
809 cpp = nfp_cpp_from_device_name(pci_dev, 0);
811 cpp = nfp_cpp_from_device_name(pci_dev, 1);
814 PMD_INIT_LOG(ERR, "A CPP handle can not be obtained");
819 hwinfo = nfp_hwinfo_read(cpp);
821 PMD_INIT_LOG(ERR, "Error reading hwinfo table");
826 nfp_eth_table = nfp_eth_read_ports(cpp);
827 if (!nfp_eth_table) {
828 PMD_INIT_LOG(ERR, "Error reading NFP ethernet table");
833 if (nfp_fw_setup(pci_dev, cpp, nfp_eth_table, hwinfo)) {
834 PMD_INIT_LOG(ERR, "Error when uploading firmware");
836 goto eth_table_cleanup;
839 /* Now the symbol table should be there */
840 sym_tbl = nfp_rtsym_table_read(cpp);
842 PMD_INIT_LOG(ERR, "Something is wrong with the firmware"
845 goto eth_table_cleanup;
848 total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
849 if (total_ports != (int)nfp_eth_table->count) {
850 PMD_DRV_LOG(ERR, "Inconsistent number of ports");
852 goto sym_tbl_cleanup;
855 PMD_INIT_LOG(INFO, "Total physical ports: %d", total_ports);
857 if (total_ports <= 0 || total_ports > 8) {
858 PMD_INIT_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value");
860 goto sym_tbl_cleanup;
862 /* Allocate memory for the PF "device" */
863 snprintf(name, sizeof(name), "nfp_pf%d", 0);
864 pf_dev = rte_zmalloc(name, sizeof(*pf_dev), 0);
867 goto sym_tbl_cleanup;
870 /* Populate the newly created PF device */
872 pf_dev->hwinfo = hwinfo;
873 pf_dev->sym_tbl = sym_tbl;
874 pf_dev->total_phyports = total_ports;
877 pf_dev->multiport = true;
879 pf_dev->pci_dev = pci_dev;
881 /* Map the symbol table */
882 pf_dev->ctrl_bar = nfp_rtsym_map(pf_dev->sym_tbl, "_pf0_net_bar0",
883 pf_dev->total_phyports * 32768,
885 if (!pf_dev->ctrl_bar) {
886 PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for _pf0_net_ctrl_bar");
891 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", pf_dev->ctrl_bar);
893 /* configure access to tx/rx vNIC BARs */
894 pf_dev->hw_queues = nfp_cpp_map_area(pf_dev->cpp, 0, 0,
896 NFP_QCP_QUEUE_AREA_SZ,
897 &pf_dev->hwqueues_area);
898 if (!pf_dev->hw_queues) {
899 PMD_INIT_LOG(ERR, "nfp_rtsym_map fails for net.qc");
901 goto ctrl_area_cleanup;
904 PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p", pf_dev->hw_queues);
906 /* Initialize and prep physical ports now
907 * This will loop through all physical ports
909 ret = nfp_init_phyports(pf_dev);
911 PMD_INIT_LOG(ERR, "Could not create physical ports");
912 goto hwqueues_cleanup;
915 /* register the CPP bridge service here for primary use */
916 nfp_register_cpp_service(pf_dev->cpp);
921 nfp_cpp_area_free(pf_dev->hwqueues_area);
923 nfp_cpp_area_free(pf_dev->ctrl_area);
937 * When attaching to the NFP4000/6000 PF on a secondary process there
938 * is no need to initialise the PF again. Only minimal work is required
941 static int nfp_pf_secondary_init(struct rte_pci_device *pci_dev)
944 struct nfp_rtsym_table *sym_tbl;
953 * When device bound to UIO, the device could be used, by mistake,
954 * by two DPDK apps, and the UIO driver does not avoid it. This
955 * could lead to a serious problem when configuring the NFP CPP
956 * interface. Here we avoid this telling to the CPP init code to
957 * use a lock file if UIO is being used.
959 if (pci_dev->kdrv == RTE_PCI_KDRV_VFIO)
960 cpp = nfp_cpp_from_device_name(pci_dev, 0);
962 cpp = nfp_cpp_from_device_name(pci_dev, 1);
965 PMD_INIT_LOG(ERR, "A CPP handle can not be obtained");
970 * We don't have access to the PF created in the primary process
971 * here so we have to read the number of ports from firmware
973 sym_tbl = nfp_rtsym_table_read(cpp);
975 PMD_INIT_LOG(ERR, "Something is wrong with the firmware"
980 total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
982 for (i = 0; i < total_ports; i++) {
983 struct rte_eth_dev *eth_dev;
984 char port_name[RTE_ETH_NAME_MAX_LEN];
986 snprintf(port_name, sizeof(port_name), "%s_port%d",
987 pci_dev->device.name, i);
989 PMD_DRV_LOG(DEBUG, "Secondary attaching to port %s",
991 eth_dev = rte_eth_dev_attach_secondary(port_name);
994 "secondary process attach failed, "
995 "ethdev doesn't exist");
998 eth_dev->process_private = cpp;
999 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
1000 eth_dev->rx_queue_count = nfp_net_rx_queue_count;
1001 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
1002 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
1003 rte_eth_dev_probing_finish(eth_dev);
1006 /* Register the CPP bridge service for the secondary too */
1007 nfp_register_cpp_service(cpp);
1012 static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1013 struct rte_pci_device *dev)
1015 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
1016 return nfp_pf_init(dev);
1018 return nfp_pf_secondary_init(dev);
1021 static const struct rte_pci_id pci_id_nfp_pf_net_map[] = {
1023 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
1024 PCI_DEVICE_ID_NFP4000_PF_NIC)
1027 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
1028 PCI_DEVICE_ID_NFP6000_PF_NIC)
1035 static int nfp_pci_uninit(struct rte_eth_dev *eth_dev)
1037 struct rte_pci_device *pci_dev;
1040 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1042 /* Free up all physical ports under PF */
1043 RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
1044 rte_eth_dev_close(port_id);
1046 * Ports can be closed and freed but hotplugging is not
1047 * currently supported
1052 static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
1054 return rte_eth_dev_pci_generic_remove(pci_dev, nfp_pci_uninit);
1057 static struct rte_pci_driver rte_nfp_net_pf_pmd = {
1058 .id_table = pci_id_nfp_pf_net_map,
1059 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
1060 .probe = nfp_pf_pci_probe,
1061 .remove = eth_nfp_pci_remove,
1064 RTE_PMD_REGISTER_PCI(net_nfp_pf, rte_nfp_net_pf_pmd);
1065 RTE_PMD_REGISTER_PCI_TABLE(net_nfp_pf, pci_id_nfp_pf_net_map);
1066 RTE_PMD_REGISTER_KMOD_DEP(net_nfp_pf, "* igb_uio | uio_pci_generic | vfio");
1069 * c-file-style: "Linux"
1070 * indent-tabs-mode: t