2 * Copyright (c) 2014-2018 Netronome Systems, Inc.
5 * Small portions derived from code Copyright(c) 2010-2015 Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
10 * 1. Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution
17 * 3. Neither the name of the copyright holder nor the names of its
18 * contributors may be used to endorse or promote products derived from this
19 * software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
35 * vim:shiftwidth=8:noexpandtab
37 * @file dpdk/pmd/nfp_net.c
39 * Netronome vNIC DPDK Poll-Mode Driver: Main entry point
42 #include <rte_byteorder.h>
43 #include <rte_common.h>
45 #include <rte_debug.h>
46 #include <rte_ethdev_driver.h>
47 #include <rte_ethdev_pci.h>
49 #include <rte_ether.h>
50 #include <rte_malloc.h>
51 #include <rte_memzone.h>
52 #include <rte_mempool.h>
53 #include <rte_version.h>
54 #include <rte_string_fns.h>
55 #include <rte_alarm.h>
56 #include <rte_spinlock.h>
57 #include <rte_service_component.h>
59 #include "nfpcore/nfp_cpp.h"
60 #include "nfpcore/nfp_nffw.h"
61 #include "nfpcore/nfp_hwinfo.h"
62 #include "nfpcore/nfp_mip.h"
63 #include "nfpcore/nfp_rtsym.h"
64 #include "nfpcore/nfp_nsp.h"
66 #include "nfp_net_pmd.h"
67 #include "nfp_net_logs.h"
68 #include "nfp_net_ctrl.h"
70 #include <sys/types.h>
71 #include <sys/socket.h>
75 #include <sys/ioctl.h>
79 static void nfp_net_close(struct rte_eth_dev *dev);
80 static int nfp_net_configure(struct rte_eth_dev *dev);
81 static void nfp_net_dev_interrupt_handler(void *param);
82 static void nfp_net_dev_interrupt_delayed_handler(void *param);
83 static int nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu);
84 static int nfp_net_infos_get(struct rte_eth_dev *dev,
85 struct rte_eth_dev_info *dev_info);
86 static int nfp_net_init(struct rte_eth_dev *eth_dev);
87 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
88 static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
89 static int nfp_net_promisc_disable(struct rte_eth_dev *dev);
90 static int nfp_net_rx_fill_freelist(struct nfp_net_rxq *rxq);
91 static uint32_t nfp_net_rx_queue_count(struct rte_eth_dev *dev,
93 static uint16_t nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
95 static void nfp_net_rx_queue_release(void *rxq);
96 static int nfp_net_rx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
97 uint16_t nb_desc, unsigned int socket_id,
98 const struct rte_eth_rxconf *rx_conf,
99 struct rte_mempool *mp);
100 static int nfp_net_tx_free_bufs(struct nfp_net_txq *txq);
101 static void nfp_net_tx_queue_release(void *txq);
102 static int nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
103 uint16_t nb_desc, unsigned int socket_id,
104 const struct rte_eth_txconf *tx_conf);
105 static int nfp_net_start(struct rte_eth_dev *dev);
106 static int nfp_net_stats_get(struct rte_eth_dev *dev,
107 struct rte_eth_stats *stats);
108 static void nfp_net_stats_reset(struct rte_eth_dev *dev);
109 static void nfp_net_stop(struct rte_eth_dev *dev);
110 static uint16_t nfp_net_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
113 static int nfp_net_rss_config_default(struct rte_eth_dev *dev);
114 static int nfp_net_rss_hash_update(struct rte_eth_dev *dev,
115 struct rte_eth_rss_conf *rss_conf);
116 static int nfp_net_rss_reta_write(struct rte_eth_dev *dev,
117 struct rte_eth_rss_reta_entry64 *reta_conf,
119 static int nfp_net_rss_hash_write(struct rte_eth_dev *dev,
120 struct rte_eth_rss_conf *rss_conf);
121 static int nfp_set_mac_addr(struct rte_eth_dev *dev,
122 struct rte_ether_addr *mac_addr);
124 /* The offset of the queue controller queues in the PCIe Target */
125 #define NFP_PCIE_QUEUE(_q) (0x80000 + (NFP_QCP_QUEUE_ADDR_SZ * ((_q) & 0xff)))
127 /* Maximum value which can be added to a queue with one transaction */
128 #define NFP_QCP_MAX_ADD 0x7f
130 #define RTE_MBUF_DMA_ADDR_DEFAULT(mb) \
131 (uint64_t)((mb)->buf_iova + RTE_PKTMBUF_HEADROOM)
133 /* nfp_qcp_ptr - Read or Write Pointer of a queue */
135 NFP_QCP_READ_PTR = 0,
140 * nfp_qcp_ptr_add - Add the value to the selected pointer of a queue
141 * @q: Base address for queue structure
142 * @ptr: Add to the Read or Write pointer
143 * @val: Value to add to the queue pointer
145 * If @val is greater than @NFP_QCP_MAX_ADD multiple writes are performed.
148 nfp_qcp_ptr_add(uint8_t *q, enum nfp_qcp_ptr ptr, uint32_t val)
152 if (ptr == NFP_QCP_READ_PTR)
153 off = NFP_QCP_QUEUE_ADD_RPTR;
155 off = NFP_QCP_QUEUE_ADD_WPTR;
157 while (val > NFP_QCP_MAX_ADD) {
158 nn_writel(rte_cpu_to_le_32(NFP_QCP_MAX_ADD), q + off);
159 val -= NFP_QCP_MAX_ADD;
162 nn_writel(rte_cpu_to_le_32(val), q + off);
166 * nfp_qcp_read - Read the current Read/Write pointer value for a queue
167 * @q: Base address for queue structure
168 * @ptr: Read or Write pointer
170 static inline uint32_t
171 nfp_qcp_read(uint8_t *q, enum nfp_qcp_ptr ptr)
176 if (ptr == NFP_QCP_READ_PTR)
177 off = NFP_QCP_QUEUE_STS_LO;
179 off = NFP_QCP_QUEUE_STS_HI;
181 val = rte_cpu_to_le_32(nn_readl(q + off));
183 if (ptr == NFP_QCP_READ_PTR)
184 return val & NFP_QCP_QUEUE_STS_LO_READPTR_mask;
186 return val & NFP_QCP_QUEUE_STS_HI_WRITEPTR_mask;
190 * Functions to read/write from/to Config BAR
191 * Performs any endian conversion necessary.
193 static inline uint8_t
194 nn_cfg_readb(struct nfp_net_hw *hw, int off)
196 return nn_readb(hw->ctrl_bar + off);
200 nn_cfg_writeb(struct nfp_net_hw *hw, int off, uint8_t val)
202 nn_writeb(val, hw->ctrl_bar + off);
205 static inline uint32_t
206 nn_cfg_readl(struct nfp_net_hw *hw, int off)
208 return rte_le_to_cpu_32(nn_readl(hw->ctrl_bar + off));
212 nn_cfg_writel(struct nfp_net_hw *hw, int off, uint32_t val)
214 nn_writel(rte_cpu_to_le_32(val), hw->ctrl_bar + off);
217 static inline uint64_t
218 nn_cfg_readq(struct nfp_net_hw *hw, int off)
220 return rte_le_to_cpu_64(nn_readq(hw->ctrl_bar + off));
224 nn_cfg_writeq(struct nfp_net_hw *hw, int off, uint64_t val)
226 nn_writeq(rte_cpu_to_le_64(val), hw->ctrl_bar + off);
230 nfp_net_rx_queue_release_mbufs(struct nfp_net_rxq *rxq)
234 if (rxq->rxbufs == NULL)
237 for (i = 0; i < rxq->rx_count; i++) {
238 if (rxq->rxbufs[i].mbuf) {
239 rte_pktmbuf_free_seg(rxq->rxbufs[i].mbuf);
240 rxq->rxbufs[i].mbuf = NULL;
246 nfp_net_rx_queue_release(void *rx_queue)
248 struct nfp_net_rxq *rxq = rx_queue;
251 nfp_net_rx_queue_release_mbufs(rxq);
252 rte_free(rxq->rxbufs);
258 nfp_net_reset_rx_queue(struct nfp_net_rxq *rxq)
260 nfp_net_rx_queue_release_mbufs(rxq);
266 nfp_net_tx_queue_release_mbufs(struct nfp_net_txq *txq)
270 if (txq->txbufs == NULL)
273 for (i = 0; i < txq->tx_count; i++) {
274 if (txq->txbufs[i].mbuf) {
275 rte_pktmbuf_free_seg(txq->txbufs[i].mbuf);
276 txq->txbufs[i].mbuf = NULL;
282 nfp_net_tx_queue_release(void *tx_queue)
284 struct nfp_net_txq *txq = tx_queue;
287 nfp_net_tx_queue_release_mbufs(txq);
288 rte_free(txq->txbufs);
294 nfp_net_reset_tx_queue(struct nfp_net_txq *txq)
296 nfp_net_tx_queue_release_mbufs(txq);
302 __nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t update)
306 struct timespec wait;
308 PMD_DRV_LOG(DEBUG, "Writing to the configuration queue (%p)...",
311 if (hw->qcp_cfg == NULL)
312 rte_panic("Bad configuration queue pointer\n");
314 nfp_qcp_ptr_add(hw->qcp_cfg, NFP_QCP_WRITE_PTR, 1);
317 wait.tv_nsec = 1000000;
319 PMD_DRV_LOG(DEBUG, "Polling for update ack...");
321 /* Poll update field, waiting for NFP to ack the config */
322 for (cnt = 0; ; cnt++) {
323 new = nn_cfg_readl(hw, NFP_NET_CFG_UPDATE);
326 if (new & NFP_NET_CFG_UPDATE_ERR) {
327 PMD_INIT_LOG(ERR, "Reconfig error: 0x%08x", new);
330 if (cnt >= NFP_NET_POLL_TIMEOUT) {
331 PMD_INIT_LOG(ERR, "Reconfig timeout for 0x%08x after"
332 " %dms", update, cnt);
333 rte_panic("Exiting\n");
335 nanosleep(&wait, 0); /* waiting for a 1ms */
337 PMD_DRV_LOG(DEBUG, "Ack DONE");
342 * Reconfigure the NIC
343 * @nn: device to reconfigure
344 * @ctrl: The value for the ctrl field in the BAR config
345 * @update: The value for the update field in the BAR config
347 * Write the update word to the BAR and ping the reconfig queue. Then poll
348 * until the firmware has acknowledged the update by zeroing the update word.
351 nfp_net_reconfig(struct nfp_net_hw *hw, uint32_t ctrl, uint32_t update)
355 PMD_DRV_LOG(DEBUG, "nfp_net_reconfig: ctrl=%08x update=%08x",
358 rte_spinlock_lock(&hw->reconfig_lock);
360 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, ctrl);
361 nn_cfg_writel(hw, NFP_NET_CFG_UPDATE, update);
365 err = __nfp_net_reconfig(hw, update);
367 rte_spinlock_unlock(&hw->reconfig_lock);
373 * Reconfig errors imply situations where they can be handled.
374 * Otherwise, rte_panic is called inside __nfp_net_reconfig
376 PMD_INIT_LOG(ERR, "Error nfp_net reconfig for ctrl: %x update: %x",
382 * Configure an Ethernet device. This function must be invoked first
383 * before any other function in the Ethernet API. This function can
384 * also be re-invoked when a device is in the stopped state.
387 nfp_net_configure(struct rte_eth_dev *dev)
389 struct rte_eth_conf *dev_conf;
390 struct rte_eth_rxmode *rxmode;
391 struct rte_eth_txmode *txmode;
392 struct nfp_net_hw *hw;
394 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
397 * A DPDK app sends info about how many queues to use and how
398 * those queues need to be configured. This is used by the
399 * DPDK core and it makes sure no more queues than those
400 * advertised by the driver are requested. This function is
401 * called after that internal process
404 PMD_INIT_LOG(DEBUG, "Configure");
406 dev_conf = &dev->data->dev_conf;
407 rxmode = &dev_conf->rxmode;
408 txmode = &dev_conf->txmode;
410 /* Checking TX mode */
411 if (txmode->mq_mode) {
412 PMD_INIT_LOG(INFO, "TX mq_mode DCB and VMDq not supported");
416 /* Checking RX mode */
417 if (rxmode->mq_mode & ETH_MQ_RX_RSS &&
418 !(hw->cap & NFP_NET_CFG_CTRL_RSS)) {
419 PMD_INIT_LOG(INFO, "RSS not supported");
427 nfp_net_enable_queues(struct rte_eth_dev *dev)
429 struct nfp_net_hw *hw;
430 uint64_t enabled_queues = 0;
433 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
435 /* Enabling the required TX queues in the device */
436 for (i = 0; i < dev->data->nb_tx_queues; i++)
437 enabled_queues |= (1 << i);
439 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, enabled_queues);
443 /* Enabling the required RX queues in the device */
444 for (i = 0; i < dev->data->nb_rx_queues; i++)
445 enabled_queues |= (1 << i);
447 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, enabled_queues);
451 nfp_net_disable_queues(struct rte_eth_dev *dev)
453 struct nfp_net_hw *hw;
454 uint32_t new_ctrl, update = 0;
456 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
458 nn_cfg_writeq(hw, NFP_NET_CFG_TXRS_ENABLE, 0);
459 nn_cfg_writeq(hw, NFP_NET_CFG_RXRS_ENABLE, 0);
461 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_ENABLE;
462 update = NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING |
463 NFP_NET_CFG_UPDATE_MSIX;
465 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
466 new_ctrl &= ~NFP_NET_CFG_CTRL_RINGCFG;
468 /* If an error when reconfig we avoid to change hw state */
469 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
476 nfp_net_rx_freelist_setup(struct rte_eth_dev *dev)
480 for (i = 0; i < dev->data->nb_rx_queues; i++) {
481 if (nfp_net_rx_fill_freelist(dev->data->rx_queues[i]) < 0)
488 nfp_net_params_setup(struct nfp_net_hw *hw)
490 nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
491 nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
495 nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
497 hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
500 #define ETH_ADDR_LEN 6
503 nfp_eth_copy_mac(uint8_t *dst, const uint8_t *src)
507 for (i = 0; i < ETH_ADDR_LEN; i++)
512 nfp_net_pf_read_mac(struct nfp_net_hw *hw, int port)
514 struct nfp_eth_table *nfp_eth_table;
516 nfp_eth_table = nfp_eth_read_ports(hw->cpp);
518 * hw points to port0 private data. We need hw now pointing to
522 nfp_eth_copy_mac((uint8_t *)&hw->mac_addr,
523 (uint8_t *)&nfp_eth_table->ports[port].mac_addr);
530 nfp_net_vf_read_mac(struct nfp_net_hw *hw)
534 tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
535 memcpy(&hw->mac_addr[0], &tmp, 4);
537 tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
538 memcpy(&hw->mac_addr[4], &tmp, 2);
542 nfp_net_write_mac(struct nfp_net_hw *hw, uint8_t *mac)
544 uint32_t mac0 = *(uint32_t *)mac;
547 nn_writel(rte_cpu_to_be_32(mac0), hw->ctrl_bar + NFP_NET_CFG_MACADDR);
550 mac1 = *(uint16_t *)mac;
551 nn_writew(rte_cpu_to_be_16(mac1),
552 hw->ctrl_bar + NFP_NET_CFG_MACADDR + 6);
556 nfp_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr)
558 struct nfp_net_hw *hw;
559 uint32_t update, ctrl;
561 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
562 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
563 !(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR)) {
564 PMD_INIT_LOG(INFO, "MAC address unable to change when"
569 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
570 !(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
573 /* Writing new MAC to the specific port BAR address */
574 nfp_net_write_mac(hw, (uint8_t *)mac_addr);
576 /* Signal the NIC about the change */
577 update = NFP_NET_CFG_UPDATE_MACADDR;
579 if ((hw->ctrl & NFP_NET_CFG_CTRL_ENABLE) &&
580 (hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
581 ctrl |= NFP_NET_CFG_CTRL_LIVE_ADDR;
582 if (nfp_net_reconfig(hw, ctrl, update) < 0) {
583 PMD_INIT_LOG(INFO, "MAC address update failed");
590 nfp_configure_rx_interrupt(struct rte_eth_dev *dev,
591 struct rte_intr_handle *intr_handle)
593 struct nfp_net_hw *hw;
596 if (!intr_handle->intr_vec) {
597 intr_handle->intr_vec =
598 rte_zmalloc("intr_vec",
599 dev->data->nb_rx_queues * sizeof(int), 0);
600 if (!intr_handle->intr_vec) {
601 PMD_INIT_LOG(ERR, "Failed to allocate %d rx_queues"
602 " intr_vec", dev->data->nb_rx_queues);
607 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
609 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
610 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with UIO");
611 /* UIO just supports one queue and no LSC*/
612 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(0), 0);
613 intr_handle->intr_vec[0] = 0;
615 PMD_INIT_LOG(INFO, "VF: enabling RX interrupt with VFIO");
616 for (i = 0; i < dev->data->nb_rx_queues; i++) {
618 * The first msix vector is reserved for non
621 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_VEC(i), i + 1);
622 intr_handle->intr_vec[i] = i + 1;
623 PMD_INIT_LOG(DEBUG, "intr_vec[%d]= %d", i,
624 intr_handle->intr_vec[i]);
628 /* Avoiding TX interrupts */
629 hw->ctrl |= NFP_NET_CFG_CTRL_MSIX_TX_OFF;
634 nfp_check_offloads(struct rte_eth_dev *dev)
636 struct nfp_net_hw *hw;
637 struct rte_eth_conf *dev_conf;
638 struct rte_eth_rxmode *rxmode;
639 struct rte_eth_txmode *txmode;
642 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
644 dev_conf = &dev->data->dev_conf;
645 rxmode = &dev_conf->rxmode;
646 txmode = &dev_conf->txmode;
648 if (rxmode->offloads & DEV_RX_OFFLOAD_IPV4_CKSUM) {
649 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM)
650 ctrl |= NFP_NET_CFG_CTRL_RXCSUM;
653 if (rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP) {
654 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN)
655 ctrl |= NFP_NET_CFG_CTRL_RXVLAN;
658 if (rxmode->offloads & DEV_RX_OFFLOAD_JUMBO_FRAME)
659 hw->mtu = rxmode->max_rx_pkt_len;
661 if (txmode->offloads & DEV_TX_OFFLOAD_VLAN_INSERT)
662 ctrl |= NFP_NET_CFG_CTRL_TXVLAN;
665 if (hw->cap & NFP_NET_CFG_CTRL_L2BC)
666 ctrl |= NFP_NET_CFG_CTRL_L2BC;
669 if (hw->cap & NFP_NET_CFG_CTRL_L2MC)
670 ctrl |= NFP_NET_CFG_CTRL_L2MC;
672 /* TX checksum offload */
673 if (txmode->offloads & DEV_TX_OFFLOAD_IPV4_CKSUM ||
674 txmode->offloads & DEV_TX_OFFLOAD_UDP_CKSUM ||
675 txmode->offloads & DEV_TX_OFFLOAD_TCP_CKSUM)
676 ctrl |= NFP_NET_CFG_CTRL_TXCSUM;
679 if (txmode->offloads & DEV_TX_OFFLOAD_TCP_TSO) {
680 if (hw->cap & NFP_NET_CFG_CTRL_LSO)
681 ctrl |= NFP_NET_CFG_CTRL_LSO;
683 ctrl |= NFP_NET_CFG_CTRL_LSO2;
687 if (txmode->offloads & DEV_TX_OFFLOAD_MULTI_SEGS)
688 ctrl |= NFP_NET_CFG_CTRL_GATHER;
694 nfp_net_start(struct rte_eth_dev *dev)
696 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
697 struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
698 uint32_t new_ctrl, update = 0;
699 struct nfp_net_hw *hw;
700 struct rte_eth_conf *dev_conf;
701 struct rte_eth_rxmode *rxmode;
702 uint32_t intr_vector;
705 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
707 PMD_INIT_LOG(DEBUG, "Start");
709 /* Disabling queues just in case... */
710 nfp_net_disable_queues(dev);
712 /* Enabling the required queues in the device */
713 nfp_net_enable_queues(dev);
715 /* check and configure queue intr-vector mapping */
716 if (dev->data->dev_conf.intr_conf.rxq != 0) {
717 if (hw->pf_multiport_enabled) {
718 PMD_INIT_LOG(ERR, "PMD rx interrupt is not supported "
719 "with NFP multiport PF");
722 if (intr_handle->type == RTE_INTR_HANDLE_UIO) {
724 * Better not to share LSC with RX interrupts.
725 * Unregistering LSC interrupt handler
727 rte_intr_callback_unregister(&pci_dev->intr_handle,
728 nfp_net_dev_interrupt_handler, (void *)dev);
730 if (dev->data->nb_rx_queues > 1) {
731 PMD_INIT_LOG(ERR, "PMD rx interrupt only "
732 "supports 1 queue with UIO");
736 intr_vector = dev->data->nb_rx_queues;
737 if (rte_intr_efd_enable(intr_handle, intr_vector))
740 nfp_configure_rx_interrupt(dev, intr_handle);
741 update = NFP_NET_CFG_UPDATE_MSIX;
744 rte_intr_enable(intr_handle);
746 new_ctrl = nfp_check_offloads(dev);
748 /* Writing configuration parameters in the device */
749 nfp_net_params_setup(hw);
751 dev_conf = &dev->data->dev_conf;
752 rxmode = &dev_conf->rxmode;
754 if (rxmode->mq_mode & ETH_MQ_RX_RSS) {
755 nfp_net_rss_config_default(dev);
756 update |= NFP_NET_CFG_UPDATE_RSS;
757 new_ctrl |= NFP_NET_CFG_CTRL_RSS;
761 new_ctrl |= NFP_NET_CFG_CTRL_ENABLE;
763 update |= NFP_NET_CFG_UPDATE_GEN | NFP_NET_CFG_UPDATE_RING;
765 if (hw->cap & NFP_NET_CFG_CTRL_RINGCFG)
766 new_ctrl |= NFP_NET_CFG_CTRL_RINGCFG;
768 nn_cfg_writel(hw, NFP_NET_CFG_CTRL, new_ctrl);
769 if (nfp_net_reconfig(hw, new_ctrl, update) < 0)
773 * Allocating rte mbufs for configured rx queues.
774 * This requires queues being enabled before
776 if (nfp_net_rx_freelist_setup(dev) < 0) {
782 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
783 /* Configure the physical port up */
784 nfp_eth_set_configured(hw->cpp, hw->pf_port_idx, 1);
786 nfp_eth_set_configured(dev->process_private,
796 * An error returned by this function should mean the app
797 * exiting and then the system releasing all the memory
798 * allocated even memory coming from hugepages.
800 * The device could be enabled at this point with some queues
801 * ready for getting packets. This is true if the call to
802 * nfp_net_rx_freelist_setup() succeeds for some queues but
803 * fails for subsequent queues.
805 * This should make the app exiting but better if we tell the
808 nfp_net_disable_queues(dev);
813 /* Stop device: disable rx and tx functions to allow for reconfiguring. */
815 nfp_net_stop(struct rte_eth_dev *dev)
818 struct nfp_net_hw *hw;
820 PMD_INIT_LOG(DEBUG, "Stop");
822 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
824 nfp_net_disable_queues(dev);
827 for (i = 0; i < dev->data->nb_tx_queues; i++) {
828 nfp_net_reset_tx_queue(
829 (struct nfp_net_txq *)dev->data->tx_queues[i]);
832 for (i = 0; i < dev->data->nb_rx_queues; i++) {
833 nfp_net_reset_rx_queue(
834 (struct nfp_net_rxq *)dev->data->rx_queues[i]);
838 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
839 /* Configure the physical port down */
840 nfp_eth_set_configured(hw->cpp, hw->pf_port_idx, 0);
842 nfp_eth_set_configured(dev->process_private,
847 /* Set the link up. */
849 nfp_net_set_link_up(struct rte_eth_dev *dev)
851 struct nfp_net_hw *hw;
853 PMD_DRV_LOG(DEBUG, "Set link up");
855 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
860 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
861 /* Configure the physical port down */
862 return nfp_eth_set_configured(hw->cpp, hw->pf_port_idx, 1);
864 return nfp_eth_set_configured(dev->process_private,
868 /* Set the link down. */
870 nfp_net_set_link_down(struct rte_eth_dev *dev)
872 struct nfp_net_hw *hw;
874 PMD_DRV_LOG(DEBUG, "Set link down");
876 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
881 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
882 /* Configure the physical port down */
883 return nfp_eth_set_configured(hw->cpp, hw->pf_port_idx, 0);
885 return nfp_eth_set_configured(dev->process_private,
889 /* Reset and stop device. The device can not be restarted. */
891 nfp_net_close(struct rte_eth_dev *dev)
893 struct nfp_net_hw *hw;
894 struct rte_pci_device *pci_dev;
897 PMD_INIT_LOG(DEBUG, "Close");
899 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
900 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
903 * We assume that the DPDK application is stopping all the
904 * threads/queues before calling the device close function.
907 nfp_net_disable_queues(dev);
910 for (i = 0; i < dev->data->nb_tx_queues; i++) {
911 nfp_net_reset_tx_queue(
912 (struct nfp_net_txq *)dev->data->tx_queues[i]);
915 for (i = 0; i < dev->data->nb_rx_queues; i++) {
916 nfp_net_reset_rx_queue(
917 (struct nfp_net_rxq *)dev->data->rx_queues[i]);
920 rte_intr_disable(&pci_dev->intr_handle);
921 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
923 /* unregister callback func from eal lib */
924 rte_intr_callback_unregister(&pci_dev->intr_handle,
925 nfp_net_dev_interrupt_handler,
929 * The ixgbe PMD driver disables the pcie master on the
930 * device. The i40e does not...
935 nfp_net_promisc_enable(struct rte_eth_dev *dev)
937 uint32_t new_ctrl, update = 0;
938 struct nfp_net_hw *hw;
941 PMD_DRV_LOG(DEBUG, "Promiscuous mode enable");
943 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
945 if (!(hw->cap & NFP_NET_CFG_CTRL_PROMISC)) {
946 PMD_INIT_LOG(INFO, "Promiscuous mode not supported");
950 if (hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) {
951 PMD_DRV_LOG(INFO, "Promiscuous mode already enabled");
955 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_PROMISC;
956 update = NFP_NET_CFG_UPDATE_GEN;
959 * DPDK sets promiscuous mode on just after this call assuming
960 * it can not fail ...
962 ret = nfp_net_reconfig(hw, new_ctrl, update);
972 nfp_net_promisc_disable(struct rte_eth_dev *dev)
974 uint32_t new_ctrl, update = 0;
975 struct nfp_net_hw *hw;
978 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
980 if ((hw->ctrl & NFP_NET_CFG_CTRL_PROMISC) == 0) {
981 PMD_DRV_LOG(INFO, "Promiscuous mode already disabled");
985 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_PROMISC;
986 update = NFP_NET_CFG_UPDATE_GEN;
989 * DPDK sets promiscuous mode off just before this call
990 * assuming it can not fail ...
992 ret = nfp_net_reconfig(hw, new_ctrl, update);
1002 * return 0 means link status changed, -1 means not changed
1004 * Wait to complete is needed as it can take up to 9 seconds to get the Link
1008 nfp_net_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
1010 struct nfp_net_hw *hw;
1011 struct rte_eth_link link;
1012 uint32_t nn_link_status;
1015 static const uint32_t ls_to_ethtool[] = {
1016 [NFP_NET_CFG_STS_LINK_RATE_UNSUPPORTED] = ETH_SPEED_NUM_NONE,
1017 [NFP_NET_CFG_STS_LINK_RATE_UNKNOWN] = ETH_SPEED_NUM_NONE,
1018 [NFP_NET_CFG_STS_LINK_RATE_1G] = ETH_SPEED_NUM_1G,
1019 [NFP_NET_CFG_STS_LINK_RATE_10G] = ETH_SPEED_NUM_10G,
1020 [NFP_NET_CFG_STS_LINK_RATE_25G] = ETH_SPEED_NUM_25G,
1021 [NFP_NET_CFG_STS_LINK_RATE_40G] = ETH_SPEED_NUM_40G,
1022 [NFP_NET_CFG_STS_LINK_RATE_50G] = ETH_SPEED_NUM_50G,
1023 [NFP_NET_CFG_STS_LINK_RATE_100G] = ETH_SPEED_NUM_100G,
1026 PMD_DRV_LOG(DEBUG, "Link update");
1028 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1030 nn_link_status = nn_cfg_readl(hw, NFP_NET_CFG_STS);
1032 memset(&link, 0, sizeof(struct rte_eth_link));
1034 if (nn_link_status & NFP_NET_CFG_STS_LINK)
1035 link.link_status = ETH_LINK_UP;
1037 link.link_duplex = ETH_LINK_FULL_DUPLEX;
1039 nn_link_status = (nn_link_status >> NFP_NET_CFG_STS_LINK_RATE_SHIFT) &
1040 NFP_NET_CFG_STS_LINK_RATE_MASK;
1042 if (nn_link_status >= RTE_DIM(ls_to_ethtool))
1043 link.link_speed = ETH_SPEED_NUM_NONE;
1045 link.link_speed = ls_to_ethtool[nn_link_status];
1047 ret = rte_eth_linkstatus_set(dev, &link);
1049 if (link.link_status)
1050 PMD_DRV_LOG(INFO, "NIC Link is Up");
1052 PMD_DRV_LOG(INFO, "NIC Link is Down");
1058 nfp_net_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
1061 struct nfp_net_hw *hw;
1062 struct rte_eth_stats nfp_dev_stats;
1064 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1066 /* RTE_ETHDEV_QUEUE_STAT_CNTRS default value is 16 */
1068 memset(&nfp_dev_stats, 0, sizeof(nfp_dev_stats));
1070 /* reading per RX ring stats */
1071 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1072 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
1075 nfp_dev_stats.q_ipackets[i] =
1076 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
1078 nfp_dev_stats.q_ipackets[i] -=
1079 hw->eth_stats_base.q_ipackets[i];
1081 nfp_dev_stats.q_ibytes[i] =
1082 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
1084 nfp_dev_stats.q_ibytes[i] -=
1085 hw->eth_stats_base.q_ibytes[i];
1088 /* reading per TX ring stats */
1089 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1090 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
1093 nfp_dev_stats.q_opackets[i] =
1094 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
1096 nfp_dev_stats.q_opackets[i] -=
1097 hw->eth_stats_base.q_opackets[i];
1099 nfp_dev_stats.q_obytes[i] =
1100 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
1102 nfp_dev_stats.q_obytes[i] -=
1103 hw->eth_stats_base.q_obytes[i];
1106 nfp_dev_stats.ipackets =
1107 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
1109 nfp_dev_stats.ipackets -= hw->eth_stats_base.ipackets;
1111 nfp_dev_stats.ibytes =
1112 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
1114 nfp_dev_stats.ibytes -= hw->eth_stats_base.ibytes;
1116 nfp_dev_stats.opackets =
1117 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
1119 nfp_dev_stats.opackets -= hw->eth_stats_base.opackets;
1121 nfp_dev_stats.obytes =
1122 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
1124 nfp_dev_stats.obytes -= hw->eth_stats_base.obytes;
1126 /* reading general device stats */
1127 nfp_dev_stats.ierrors =
1128 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
1130 nfp_dev_stats.ierrors -= hw->eth_stats_base.ierrors;
1132 nfp_dev_stats.oerrors =
1133 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
1135 nfp_dev_stats.oerrors -= hw->eth_stats_base.oerrors;
1137 /* RX ring mbuf allocation failures */
1138 nfp_dev_stats.rx_nombuf = dev->data->rx_mbuf_alloc_failed;
1140 nfp_dev_stats.imissed =
1141 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
1143 nfp_dev_stats.imissed -= hw->eth_stats_base.imissed;
1146 memcpy(stats, &nfp_dev_stats, sizeof(*stats));
1153 nfp_net_stats_reset(struct rte_eth_dev *dev)
1156 struct nfp_net_hw *hw;
1158 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1161 * hw->eth_stats_base records the per counter starting point.
1162 * Lets update it now
1165 /* reading per RX ring stats */
1166 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1167 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
1170 hw->eth_stats_base.q_ipackets[i] =
1171 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i));
1173 hw->eth_stats_base.q_ibytes[i] =
1174 nn_cfg_readq(hw, NFP_NET_CFG_RXR_STATS(i) + 0x8);
1177 /* reading per TX ring stats */
1178 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1179 if (i == RTE_ETHDEV_QUEUE_STAT_CNTRS)
1182 hw->eth_stats_base.q_opackets[i] =
1183 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i));
1185 hw->eth_stats_base.q_obytes[i] =
1186 nn_cfg_readq(hw, NFP_NET_CFG_TXR_STATS(i) + 0x8);
1189 hw->eth_stats_base.ipackets =
1190 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_FRAMES);
1192 hw->eth_stats_base.ibytes =
1193 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_OCTETS);
1195 hw->eth_stats_base.opackets =
1196 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_FRAMES);
1198 hw->eth_stats_base.obytes =
1199 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_OCTETS);
1201 /* reading general device stats */
1202 hw->eth_stats_base.ierrors =
1203 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_ERRORS);
1205 hw->eth_stats_base.oerrors =
1206 nn_cfg_readq(hw, NFP_NET_CFG_STATS_TX_ERRORS);
1208 /* RX ring mbuf allocation failures */
1209 dev->data->rx_mbuf_alloc_failed = 0;
1211 hw->eth_stats_base.imissed =
1212 nn_cfg_readq(hw, NFP_NET_CFG_STATS_RX_DISCARDS);
1216 nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
1218 struct nfp_net_hw *hw;
1220 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1222 dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
1223 dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
1224 dev_info->min_rx_bufsize = RTE_ETHER_MIN_MTU;
1225 dev_info->max_rx_pktlen = hw->max_mtu;
1226 /* Next should change when PF support is implemented */
1227 dev_info->max_mac_addrs = 1;
1229 if (hw->cap & NFP_NET_CFG_CTRL_RXVLAN)
1230 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
1232 if (hw->cap & NFP_NET_CFG_CTRL_RXCSUM)
1233 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_IPV4_CKSUM |
1234 DEV_RX_OFFLOAD_UDP_CKSUM |
1235 DEV_RX_OFFLOAD_TCP_CKSUM;
1237 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1239 if (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)
1240 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_VLAN_INSERT;
1242 if (hw->cap & NFP_NET_CFG_CTRL_TXCSUM)
1243 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_IPV4_CKSUM |
1244 DEV_TX_OFFLOAD_UDP_CKSUM |
1245 DEV_TX_OFFLOAD_TCP_CKSUM;
1247 if (hw->cap & NFP_NET_CFG_CTRL_LSO_ANY)
1248 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_TCP_TSO;
1250 if (hw->cap & NFP_NET_CFG_CTRL_GATHER)
1251 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_MULTI_SEGS;
1253 dev_info->default_rxconf = (struct rte_eth_rxconf) {
1255 .pthresh = DEFAULT_RX_PTHRESH,
1256 .hthresh = DEFAULT_RX_HTHRESH,
1257 .wthresh = DEFAULT_RX_WTHRESH,
1259 .rx_free_thresh = DEFAULT_RX_FREE_THRESH,
1263 dev_info->default_txconf = (struct rte_eth_txconf) {
1265 .pthresh = DEFAULT_TX_PTHRESH,
1266 .hthresh = DEFAULT_TX_HTHRESH,
1267 .wthresh = DEFAULT_TX_WTHRESH,
1269 .tx_free_thresh = DEFAULT_TX_FREE_THRESH,
1270 .tx_rs_thresh = DEFAULT_TX_RSBIT_THRESH,
1273 dev_info->flow_type_rss_offloads = ETH_RSS_IPV4 |
1274 ETH_RSS_NONFRAG_IPV4_TCP |
1275 ETH_RSS_NONFRAG_IPV4_UDP |
1277 ETH_RSS_NONFRAG_IPV6_TCP |
1278 ETH_RSS_NONFRAG_IPV6_UDP;
1280 dev_info->reta_size = NFP_NET_CFG_RSS_ITBL_SZ;
1281 dev_info->hash_key_size = NFP_NET_CFG_RSS_KEY_SZ;
1283 dev_info->speed_capa = ETH_LINK_SPEED_1G | ETH_LINK_SPEED_10G |
1284 ETH_LINK_SPEED_25G | ETH_LINK_SPEED_40G |
1285 ETH_LINK_SPEED_50G | ETH_LINK_SPEED_100G;
1290 static const uint32_t *
1291 nfp_net_supported_ptypes_get(struct rte_eth_dev *dev)
1293 static const uint32_t ptypes[] = {
1294 /* refers to nfp_net_set_hash() */
1295 RTE_PTYPE_INNER_L3_IPV4,
1296 RTE_PTYPE_INNER_L3_IPV6,
1297 RTE_PTYPE_INNER_L3_IPV6_EXT,
1298 RTE_PTYPE_INNER_L4_MASK,
1302 if (dev->rx_pkt_burst == nfp_net_recv_pkts)
1308 nfp_net_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_idx)
1310 struct nfp_net_rxq *rxq;
1311 struct nfp_net_rx_desc *rxds;
1315 rxq = (struct nfp_net_rxq *)dev->data->rx_queues[queue_idx];
1322 * Other PMDs are just checking the DD bit in intervals of 4
1323 * descriptors and counting all four if the first has the DD
1324 * bit on. Of course, this is not accurate but can be good for
1325 * performance. But ideally that should be done in descriptors
1326 * chunks belonging to the same cache line
1329 while (count < rxq->rx_count) {
1330 rxds = &rxq->rxds[idx];
1331 if ((rxds->rxd.meta_len_dd & PCIE_DESC_RX_DD) == 0)
1338 if ((idx) == rxq->rx_count)
1346 nfp_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
1348 struct rte_pci_device *pci_dev;
1349 struct nfp_net_hw *hw;
1352 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1353 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1355 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1358 /* Make sure all updates are written before un-masking */
1360 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id),
1361 NFP_NET_CFG_ICR_UNMASKED);
1366 nfp_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
1368 struct rte_pci_device *pci_dev;
1369 struct nfp_net_hw *hw;
1372 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1373 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1375 if (pci_dev->intr_handle.type != RTE_INTR_HANDLE_UIO)
1378 /* Make sure all updates are written before un-masking */
1380 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(base + queue_id), 0x1);
1385 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
1387 struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1388 struct rte_eth_link link;
1390 rte_eth_linkstatus_get(dev, &link);
1391 if (link.link_status)
1392 PMD_DRV_LOG(INFO, "Port %d: Link Up - speed %u Mbps - %s",
1393 dev->data->port_id, link.link_speed,
1394 link.link_duplex == ETH_LINK_FULL_DUPLEX
1395 ? "full-duplex" : "half-duplex");
1397 PMD_DRV_LOG(INFO, " Port %d: Link Down",
1398 dev->data->port_id);
1400 PMD_DRV_LOG(INFO, "PCI Address: %04d:%02d:%02d:%d",
1401 pci_dev->addr.domain, pci_dev->addr.bus,
1402 pci_dev->addr.devid, pci_dev->addr.function);
1405 /* Interrupt configuration and handling */
1408 * nfp_net_irq_unmask - Unmask an interrupt
1410 * If MSI-X auto-masking is enabled clear the mask bit, otherwise
1411 * clear the ICR for the entry.
1414 nfp_net_irq_unmask(struct rte_eth_dev *dev)
1416 struct nfp_net_hw *hw;
1417 struct rte_pci_device *pci_dev;
1419 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1420 pci_dev = RTE_ETH_DEV_TO_PCI(dev);
1422 if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
1423 /* If MSI-X auto-masking is used, clear the entry */
1425 rte_intr_ack(&pci_dev->intr_handle);
1427 /* Make sure all updates are written before un-masking */
1429 nn_cfg_writeb(hw, NFP_NET_CFG_ICR(NFP_NET_IRQ_LSC_IDX),
1430 NFP_NET_CFG_ICR_UNMASKED);
1435 nfp_net_dev_interrupt_handler(void *param)
1438 struct rte_eth_link link;
1439 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1441 PMD_DRV_LOG(DEBUG, "We got a LSC interrupt!!!");
1443 rte_eth_linkstatus_get(dev, &link);
1445 nfp_net_link_update(dev, 0);
1448 if (!link.link_status) {
1449 /* handle it 1 sec later, wait it being stable */
1450 timeout = NFP_NET_LINK_UP_CHECK_TIMEOUT;
1451 /* likely to down */
1453 /* handle it 4 sec later, wait it being stable */
1454 timeout = NFP_NET_LINK_DOWN_CHECK_TIMEOUT;
1457 if (rte_eal_alarm_set(timeout * 1000,
1458 nfp_net_dev_interrupt_delayed_handler,
1460 PMD_INIT_LOG(ERR, "Error setting alarm");
1462 nfp_net_irq_unmask(dev);
1467 * Interrupt handler which shall be registered for alarm callback for delayed
1468 * handling specific interrupt to wait for the stable nic state. As the NIC
1469 * interrupt state is not stable for nfp after link is just down, it needs
1470 * to wait 4 seconds to get the stable status.
1472 * @param handle Pointer to interrupt handle.
1473 * @param param The address of parameter (struct rte_eth_dev *)
1478 nfp_net_dev_interrupt_delayed_handler(void *param)
1480 struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
1482 nfp_net_link_update(dev, 0);
1483 _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
1485 nfp_net_dev_link_status_print(dev);
1488 nfp_net_irq_unmask(dev);
1492 nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
1494 struct nfp_net_hw *hw;
1496 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1498 /* check that mtu is within the allowed range */
1499 if (mtu < RTE_ETHER_MIN_MTU || (uint32_t)mtu > hw->max_mtu)
1502 /* mtu setting is forbidden if port is started */
1503 if (dev->data->dev_started) {
1504 PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
1505 dev->data->port_id);
1509 /* switch to jumbo mode if needed */
1510 if ((uint32_t)mtu > RTE_ETHER_MAX_LEN)
1511 dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
1513 dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
1515 /* update max frame size */
1516 dev->data->dev_conf.rxmode.max_rx_pkt_len = (uint32_t)mtu;
1518 /* writing to configuration space */
1519 nn_cfg_writel(hw, NFP_NET_CFG_MTU, (uint32_t)mtu);
1527 nfp_net_rx_queue_setup(struct rte_eth_dev *dev,
1528 uint16_t queue_idx, uint16_t nb_desc,
1529 unsigned int socket_id,
1530 const struct rte_eth_rxconf *rx_conf,
1531 struct rte_mempool *mp)
1533 const struct rte_memzone *tz;
1534 struct nfp_net_rxq *rxq;
1535 struct nfp_net_hw *hw;
1537 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1539 PMD_INIT_FUNC_TRACE();
1541 /* Validating number of descriptors */
1542 if (((nb_desc * sizeof(struct nfp_net_rx_desc)) % 128) != 0 ||
1543 (nb_desc > NFP_NET_MAX_RX_DESC) ||
1544 (nb_desc < NFP_NET_MIN_RX_DESC)) {
1545 PMD_DRV_LOG(ERR, "Wrong nb_desc value");
1550 * Free memory prior to re-allocation if needed. This is the case after
1551 * calling nfp_net_stop
1553 if (dev->data->rx_queues[queue_idx]) {
1554 nfp_net_rx_queue_release(dev->data->rx_queues[queue_idx]);
1555 dev->data->rx_queues[queue_idx] = NULL;
1558 /* Allocating rx queue data structure */
1559 rxq = rte_zmalloc_socket("ethdev RX queue", sizeof(struct nfp_net_rxq),
1560 RTE_CACHE_LINE_SIZE, socket_id);
1564 /* Hw queues mapping based on firmware configuration */
1565 rxq->qidx = queue_idx;
1566 rxq->fl_qcidx = queue_idx * hw->stride_rx;
1567 rxq->rx_qcidx = rxq->fl_qcidx + (hw->stride_rx - 1);
1568 rxq->qcp_fl = hw->rx_bar + NFP_QCP_QUEUE_OFF(rxq->fl_qcidx);
1569 rxq->qcp_rx = hw->rx_bar + NFP_QCP_QUEUE_OFF(rxq->rx_qcidx);
1572 * Tracking mbuf size for detecting a potential mbuf overflow due to
1576 rxq->mbuf_size = rxq->mem_pool->elt_size;
1577 rxq->mbuf_size -= (sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM);
1578 hw->flbufsz = rxq->mbuf_size;
1580 rxq->rx_count = nb_desc;
1581 rxq->port_id = dev->data->port_id;
1582 rxq->rx_free_thresh = rx_conf->rx_free_thresh;
1583 rxq->drop_en = rx_conf->rx_drop_en;
1586 * Allocate RX ring hardware descriptors. A memzone large enough to
1587 * handle the maximum ring size is allocated in order to allow for
1588 * resizing in later calls to the queue setup function.
1590 tz = rte_eth_dma_zone_reserve(dev, "rx_ring", queue_idx,
1591 sizeof(struct nfp_net_rx_desc) *
1592 NFP_NET_MAX_RX_DESC, NFP_MEMZONE_ALIGN,
1596 PMD_DRV_LOG(ERR, "Error allocating rx dma");
1597 nfp_net_rx_queue_release(rxq);
1601 /* Saving physical and virtual addresses for the RX ring */
1602 rxq->dma = (uint64_t)tz->iova;
1603 rxq->rxds = (struct nfp_net_rx_desc *)tz->addr;
1605 /* mbuf pointers array for referencing mbufs linked to RX descriptors */
1606 rxq->rxbufs = rte_zmalloc_socket("rxq->rxbufs",
1607 sizeof(*rxq->rxbufs) * nb_desc,
1608 RTE_CACHE_LINE_SIZE, socket_id);
1609 if (rxq->rxbufs == NULL) {
1610 nfp_net_rx_queue_release(rxq);
1614 PMD_RX_LOG(DEBUG, "rxbufs=%p hw_ring=%p dma_addr=0x%" PRIx64,
1615 rxq->rxbufs, rxq->rxds, (unsigned long int)rxq->dma);
1617 nfp_net_reset_rx_queue(rxq);
1619 dev->data->rx_queues[queue_idx] = rxq;
1623 * Telling the HW about the physical address of the RX ring and number
1624 * of descriptors in log2 format
1626 nn_cfg_writeq(hw, NFP_NET_CFG_RXR_ADDR(queue_idx), rxq->dma);
1627 nn_cfg_writeb(hw, NFP_NET_CFG_RXR_SZ(queue_idx), rte_log2_u32(nb_desc));
1633 nfp_net_rx_fill_freelist(struct nfp_net_rxq *rxq)
1635 struct nfp_net_rx_buff *rxe = rxq->rxbufs;
1639 PMD_RX_LOG(DEBUG, "nfp_net_rx_fill_freelist for %u descriptors",
1642 for (i = 0; i < rxq->rx_count; i++) {
1643 struct nfp_net_rx_desc *rxd;
1644 struct rte_mbuf *mbuf = rte_pktmbuf_alloc(rxq->mem_pool);
1647 PMD_DRV_LOG(ERR, "RX mbuf alloc failed queue_id=%u",
1648 (unsigned)rxq->qidx);
1652 dma_addr = rte_cpu_to_le_64(RTE_MBUF_DMA_ADDR_DEFAULT(mbuf));
1654 rxd = &rxq->rxds[i];
1656 rxd->fld.dma_addr_hi = (dma_addr >> 32) & 0xff;
1657 rxd->fld.dma_addr_lo = dma_addr & 0xffffffff;
1659 PMD_RX_LOG(DEBUG, "[%d]: %" PRIx64, i, dma_addr);
1662 /* Make sure all writes are flushed before telling the hardware */
1665 /* Not advertising the whole ring as the firmware gets confused if so */
1666 PMD_RX_LOG(DEBUG, "Increment FL write pointer in %u",
1669 nfp_qcp_ptr_add(rxq->qcp_fl, NFP_QCP_WRITE_PTR, rxq->rx_count - 1);
1675 nfp_net_tx_queue_setup(struct rte_eth_dev *dev, uint16_t queue_idx,
1676 uint16_t nb_desc, unsigned int socket_id,
1677 const struct rte_eth_txconf *tx_conf)
1679 const struct rte_memzone *tz;
1680 struct nfp_net_txq *txq;
1681 uint16_t tx_free_thresh;
1682 struct nfp_net_hw *hw;
1684 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1686 PMD_INIT_FUNC_TRACE();
1688 /* Validating number of descriptors */
1689 if (((nb_desc * sizeof(struct nfp_net_tx_desc)) % 128) != 0 ||
1690 (nb_desc > NFP_NET_MAX_TX_DESC) ||
1691 (nb_desc < NFP_NET_MIN_TX_DESC)) {
1692 PMD_DRV_LOG(ERR, "Wrong nb_desc value");
1696 tx_free_thresh = (uint16_t)((tx_conf->tx_free_thresh) ?
1697 tx_conf->tx_free_thresh :
1698 DEFAULT_TX_FREE_THRESH);
1700 if (tx_free_thresh > (nb_desc)) {
1702 "tx_free_thresh must be less than the number of TX "
1703 "descriptors. (tx_free_thresh=%u port=%d "
1704 "queue=%d)", (unsigned int)tx_free_thresh,
1705 dev->data->port_id, (int)queue_idx);
1710 * Free memory prior to re-allocation if needed. This is the case after
1711 * calling nfp_net_stop
1713 if (dev->data->tx_queues[queue_idx]) {
1714 PMD_TX_LOG(DEBUG, "Freeing memory prior to re-allocation %d",
1716 nfp_net_tx_queue_release(dev->data->tx_queues[queue_idx]);
1717 dev->data->tx_queues[queue_idx] = NULL;
1720 /* Allocating tx queue data structure */
1721 txq = rte_zmalloc_socket("ethdev TX queue", sizeof(struct nfp_net_txq),
1722 RTE_CACHE_LINE_SIZE, socket_id);
1724 PMD_DRV_LOG(ERR, "Error allocating tx dma");
1729 * Allocate TX ring hardware descriptors. A memzone large enough to
1730 * handle the maximum ring size is allocated in order to allow for
1731 * resizing in later calls to the queue setup function.
1733 tz = rte_eth_dma_zone_reserve(dev, "tx_ring", queue_idx,
1734 sizeof(struct nfp_net_tx_desc) *
1735 NFP_NET_MAX_TX_DESC, NFP_MEMZONE_ALIGN,
1738 PMD_DRV_LOG(ERR, "Error allocating tx dma");
1739 nfp_net_tx_queue_release(txq);
1743 txq->tx_count = nb_desc;
1744 txq->tx_free_thresh = tx_free_thresh;
1745 txq->tx_pthresh = tx_conf->tx_thresh.pthresh;
1746 txq->tx_hthresh = tx_conf->tx_thresh.hthresh;
1747 txq->tx_wthresh = tx_conf->tx_thresh.wthresh;
1749 /* queue mapping based on firmware configuration */
1750 txq->qidx = queue_idx;
1751 txq->tx_qcidx = queue_idx * hw->stride_tx;
1752 txq->qcp_q = hw->tx_bar + NFP_QCP_QUEUE_OFF(txq->tx_qcidx);
1754 txq->port_id = dev->data->port_id;
1756 /* Saving physical and virtual addresses for the TX ring */
1757 txq->dma = (uint64_t)tz->iova;
1758 txq->txds = (struct nfp_net_tx_desc *)tz->addr;
1760 /* mbuf pointers array for referencing mbufs linked to TX descriptors */
1761 txq->txbufs = rte_zmalloc_socket("txq->txbufs",
1762 sizeof(*txq->txbufs) * nb_desc,
1763 RTE_CACHE_LINE_SIZE, socket_id);
1764 if (txq->txbufs == NULL) {
1765 nfp_net_tx_queue_release(txq);
1768 PMD_TX_LOG(DEBUG, "txbufs=%p hw_ring=%p dma_addr=0x%" PRIx64,
1769 txq->txbufs, txq->txds, (unsigned long int)txq->dma);
1771 nfp_net_reset_tx_queue(txq);
1773 dev->data->tx_queues[queue_idx] = txq;
1777 * Telling the HW about the physical address of the TX ring and number
1778 * of descriptors in log2 format
1780 nn_cfg_writeq(hw, NFP_NET_CFG_TXR_ADDR(queue_idx), txq->dma);
1781 nn_cfg_writeb(hw, NFP_NET_CFG_TXR_SZ(queue_idx), rte_log2_u32(nb_desc));
1786 /* nfp_net_tx_tso - Set TX descriptor for TSO */
1788 nfp_net_tx_tso(struct nfp_net_txq *txq, struct nfp_net_tx_desc *txd,
1789 struct rte_mbuf *mb)
1792 struct nfp_net_hw *hw = txq->hw;
1794 if (!(hw->cap & NFP_NET_CFG_CTRL_LSO_ANY))
1797 ol_flags = mb->ol_flags;
1799 if (!(ol_flags & PKT_TX_TCP_SEG))
1802 txd->l3_offset = mb->l2_len;
1803 txd->l4_offset = mb->l2_len + mb->l3_len;
1804 txd->lso_hdrlen = mb->l2_len + mb->l3_len + mb->l4_len;
1805 txd->mss = rte_cpu_to_le_16(mb->tso_segsz);
1806 txd->flags = PCIE_DESC_TX_LSO;
1813 txd->lso_hdrlen = 0;
1817 /* nfp_net_tx_cksum - Set TX CSUM offload flags in TX descriptor */
1819 nfp_net_tx_cksum(struct nfp_net_txq *txq, struct nfp_net_tx_desc *txd,
1820 struct rte_mbuf *mb)
1823 struct nfp_net_hw *hw = txq->hw;
1825 if (!(hw->cap & NFP_NET_CFG_CTRL_TXCSUM))
1828 ol_flags = mb->ol_flags;
1830 /* IPv6 does not need checksum */
1831 if (ol_flags & PKT_TX_IP_CKSUM)
1832 txd->flags |= PCIE_DESC_TX_IP4_CSUM;
1834 switch (ol_flags & PKT_TX_L4_MASK) {
1835 case PKT_TX_UDP_CKSUM:
1836 txd->flags |= PCIE_DESC_TX_UDP_CSUM;
1838 case PKT_TX_TCP_CKSUM:
1839 txd->flags |= PCIE_DESC_TX_TCP_CSUM;
1843 if (ol_flags & (PKT_TX_IP_CKSUM | PKT_TX_L4_MASK))
1844 txd->flags |= PCIE_DESC_TX_CSUM;
1847 /* nfp_net_rx_cksum - set mbuf checksum flags based on RX descriptor flags */
1849 nfp_net_rx_cksum(struct nfp_net_rxq *rxq, struct nfp_net_rx_desc *rxd,
1850 struct rte_mbuf *mb)
1852 struct nfp_net_hw *hw = rxq->hw;
1854 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RXCSUM))
1857 /* If IPv4 and IP checksum error, fail */
1858 if (unlikely((rxd->rxd.flags & PCIE_DESC_RX_IP4_CSUM) &&
1859 !(rxd->rxd.flags & PCIE_DESC_RX_IP4_CSUM_OK)))
1860 mb->ol_flags |= PKT_RX_IP_CKSUM_BAD;
1862 mb->ol_flags |= PKT_RX_IP_CKSUM_GOOD;
1864 /* If neither UDP nor TCP return */
1865 if (!(rxd->rxd.flags & PCIE_DESC_RX_TCP_CSUM) &&
1866 !(rxd->rxd.flags & PCIE_DESC_RX_UDP_CSUM))
1869 if (likely(rxd->rxd.flags & PCIE_DESC_RX_L4_CSUM_OK))
1870 mb->ol_flags |= PKT_RX_L4_CKSUM_GOOD;
1872 mb->ol_flags |= PKT_RX_L4_CKSUM_BAD;
1875 #define NFP_HASH_OFFSET ((uint8_t *)mbuf->buf_addr + mbuf->data_off - 4)
1876 #define NFP_HASH_TYPE_OFFSET ((uint8_t *)mbuf->buf_addr + mbuf->data_off - 8)
1878 #define NFP_DESC_META_LEN(d) (d->rxd.meta_len_dd & PCIE_DESC_RX_META_LEN_MASK)
1881 * nfp_net_set_hash - Set mbuf hash data
1883 * The RSS hash and hash-type are pre-pended to the packet data.
1884 * Extract and decode it and set the mbuf fields.
1887 nfp_net_set_hash(struct nfp_net_rxq *rxq, struct nfp_net_rx_desc *rxd,
1888 struct rte_mbuf *mbuf)
1890 struct nfp_net_hw *hw = rxq->hw;
1891 uint8_t *meta_offset;
1894 uint32_t hash_type = 0;
1896 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
1899 /* this is true for new firmwares */
1900 if (likely(((hw->cap & NFP_NET_CFG_CTRL_RSS2) ||
1901 (NFD_CFG_MAJOR_VERSION_of(hw->ver) == 4)) &&
1902 NFP_DESC_META_LEN(rxd))) {
1905 * <---- 32 bit ----->
1910 * ====================
1913 * Field type word contains up to 8 4bit field types
1914 * A 4bit field type refers to a data field word
1915 * A data field word can have several 4bit field types
1917 meta_offset = rte_pktmbuf_mtod(mbuf, uint8_t *);
1918 meta_offset -= NFP_DESC_META_LEN(rxd);
1919 meta_info = rte_be_to_cpu_32(*(uint32_t *)meta_offset);
1921 /* NFP PMD just supports metadata for hashing */
1922 switch (meta_info & NFP_NET_META_FIELD_MASK) {
1923 case NFP_NET_META_HASH:
1924 /* next field type is about the hash type */
1925 meta_info >>= NFP_NET_META_FIELD_SIZE;
1926 /* hash value is in the data field */
1927 hash = rte_be_to_cpu_32(*(uint32_t *)meta_offset);
1928 hash_type = meta_info & NFP_NET_META_FIELD_MASK;
1931 /* Unsupported metadata can be a performance issue */
1935 if (!(rxd->rxd.flags & PCIE_DESC_RX_RSS))
1938 hash = rte_be_to_cpu_32(*(uint32_t *)NFP_HASH_OFFSET);
1939 hash_type = rte_be_to_cpu_32(*(uint32_t *)NFP_HASH_TYPE_OFFSET);
1942 mbuf->hash.rss = hash;
1943 mbuf->ol_flags |= PKT_RX_RSS_HASH;
1945 switch (hash_type) {
1946 case NFP_NET_RSS_IPV4:
1947 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV4;
1949 case NFP_NET_RSS_IPV6:
1950 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6;
1952 case NFP_NET_RSS_IPV6_EX:
1953 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6_EXT;
1955 case NFP_NET_RSS_IPV4_TCP:
1956 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6_EXT;
1958 case NFP_NET_RSS_IPV6_TCP:
1959 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6_EXT;
1961 case NFP_NET_RSS_IPV4_UDP:
1962 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6_EXT;
1964 case NFP_NET_RSS_IPV6_UDP:
1965 mbuf->packet_type |= RTE_PTYPE_INNER_L3_IPV6_EXT;
1968 mbuf->packet_type |= RTE_PTYPE_INNER_L4_MASK;
1973 nfp_net_mbuf_alloc_failed(struct nfp_net_rxq *rxq)
1975 rte_eth_devices[rxq->port_id].data->rx_mbuf_alloc_failed++;
1978 #define NFP_DESC_META_LEN(d) (d->rxd.meta_len_dd & PCIE_DESC_RX_META_LEN_MASK)
1983 * There are some decisions to take:
1984 * 1) How to check DD RX descriptors bit
1985 * 2) How and when to allocate new mbufs
1987 * Current implementation checks just one single DD bit each loop. As each
1988 * descriptor is 8 bytes, it is likely a good idea to check descriptors in
1989 * a single cache line instead. Tests with this change have not shown any
1990 * performance improvement but it requires further investigation. For example,
1991 * depending on which descriptor is next, the number of descriptors could be
1992 * less than 8 for just checking those in the same cache line. This implies
1993 * extra work which could be counterproductive by itself. Indeed, last firmware
1994 * changes are just doing this: writing several descriptors with the DD bit
1995 * for saving PCIe bandwidth and DMA operations from the NFP.
1997 * Mbuf allocation is done when a new packet is received. Then the descriptor
1998 * is automatically linked with the new mbuf and the old one is given to the
1999 * user. The main drawback with this design is mbuf allocation is heavier than
2000 * using bulk allocations allowed by DPDK with rte_mempool_get_bulk. From the
2001 * cache point of view it does not seem allocating the mbuf early on as we are
2002 * doing now have any benefit at all. Again, tests with this change have not
2003 * shown any improvement. Also, rte_mempool_get_bulk returns all or nothing
2004 * so looking at the implications of this type of allocation should be studied
2009 nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
2011 struct nfp_net_rxq *rxq;
2012 struct nfp_net_rx_desc *rxds;
2013 struct nfp_net_rx_buff *rxb;
2014 struct nfp_net_hw *hw;
2015 struct rte_mbuf *mb;
2016 struct rte_mbuf *new_mb;
2022 if (unlikely(rxq == NULL)) {
2024 * DPDK just checks the queue is lower than max queues
2025 * enabled. But the queue needs to be configured
2027 RTE_LOG_DP(ERR, PMD, "RX Bad queue\n");
2035 while (avail < nb_pkts) {
2036 rxb = &rxq->rxbufs[rxq->rd_p];
2037 if (unlikely(rxb == NULL)) {
2038 RTE_LOG_DP(ERR, PMD, "rxb does not exist!\n");
2042 rxds = &rxq->rxds[rxq->rd_p];
2043 if ((rxds->rxd.meta_len_dd & PCIE_DESC_RX_DD) == 0)
2047 * Memory barrier to ensure that we won't do other
2048 * reads before the DD bit.
2053 * We got a packet. Let's alloc a new mbuf for refilling the
2054 * free descriptor ring as soon as possible
2056 new_mb = rte_pktmbuf_alloc(rxq->mem_pool);
2057 if (unlikely(new_mb == NULL)) {
2058 RTE_LOG_DP(DEBUG, PMD,
2059 "RX mbuf alloc failed port_id=%u queue_id=%u\n",
2060 rxq->port_id, (unsigned int)rxq->qidx);
2061 nfp_net_mbuf_alloc_failed(rxq);
2068 * Grab the mbuf and refill the descriptor with the
2069 * previously allocated mbuf
2074 PMD_RX_LOG(DEBUG, "Packet len: %u, mbuf_size: %u",
2075 rxds->rxd.data_len, rxq->mbuf_size);
2077 /* Size of this segment */
2078 mb->data_len = rxds->rxd.data_len - NFP_DESC_META_LEN(rxds);
2079 /* Size of the whole packet. We just support 1 segment */
2080 mb->pkt_len = rxds->rxd.data_len - NFP_DESC_META_LEN(rxds);
2082 if (unlikely((mb->data_len + hw->rx_offset) >
2085 * This should not happen and the user has the
2086 * responsibility of avoiding it. But we have
2087 * to give some info about the error
2089 RTE_LOG_DP(ERR, PMD,
2090 "mbuf overflow likely due to the RX offset.\n"
2091 "\t\tYour mbuf size should have extra space for"
2092 " RX offset=%u bytes.\n"
2093 "\t\tCurrently you just have %u bytes available"
2094 " but the received packet is %u bytes long",
2096 rxq->mbuf_size - hw->rx_offset,
2101 /* Filling the received mbuf with packet info */
2103 mb->data_off = RTE_PKTMBUF_HEADROOM + hw->rx_offset;
2105 mb->data_off = RTE_PKTMBUF_HEADROOM +
2106 NFP_DESC_META_LEN(rxds);
2108 /* No scatter mode supported */
2112 mb->port = rxq->port_id;
2114 /* Checking the RSS flag */
2115 nfp_net_set_hash(rxq, rxds, mb);
2117 /* Checking the checksum flag */
2118 nfp_net_rx_cksum(rxq, rxds, mb);
2120 if ((rxds->rxd.flags & PCIE_DESC_RX_VLAN) &&
2121 (hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN)) {
2122 mb->vlan_tci = rte_cpu_to_le_32(rxds->rxd.vlan);
2123 mb->ol_flags |= PKT_RX_VLAN | PKT_RX_VLAN_STRIPPED;
2126 /* Adding the mbuf to the mbuf array passed by the app */
2127 rx_pkts[avail++] = mb;
2129 /* Now resetting and updating the descriptor */
2132 dma_addr = rte_cpu_to_le_64(RTE_MBUF_DMA_ADDR_DEFAULT(new_mb));
2134 rxds->fld.dma_addr_hi = (dma_addr >> 32) & 0xff;
2135 rxds->fld.dma_addr_lo = dma_addr & 0xffffffff;
2138 if (unlikely(rxq->rd_p == rxq->rx_count)) /* wrapping?*/
2145 PMD_RX_LOG(DEBUG, "RX port_id=%u queue_id=%u, %d packets received",
2146 rxq->port_id, (unsigned int)rxq->qidx, nb_hold);
2148 nb_hold += rxq->nb_rx_hold;
2151 * FL descriptors needs to be written before incrementing the
2152 * FL queue WR pointer
2155 if (nb_hold > rxq->rx_free_thresh) {
2156 PMD_RX_LOG(DEBUG, "port=%u queue=%u nb_hold=%u avail=%u",
2157 rxq->port_id, (unsigned int)rxq->qidx,
2158 (unsigned)nb_hold, (unsigned)avail);
2159 nfp_qcp_ptr_add(rxq->qcp_fl, NFP_QCP_WRITE_PTR, nb_hold);
2162 rxq->nb_rx_hold = nb_hold;
2168 * nfp_net_tx_free_bufs - Check for descriptors with a complete
2170 * @txq: TX queue to work with
2171 * Returns number of descriptors freed
2174 nfp_net_tx_free_bufs(struct nfp_net_txq *txq)
2179 PMD_TX_LOG(DEBUG, "queue %u. Check for descriptor with a complete"
2180 " status", txq->qidx);
2182 /* Work out how many packets have been sent */
2183 qcp_rd_p = nfp_qcp_read(txq->qcp_q, NFP_QCP_READ_PTR);
2185 if (qcp_rd_p == txq->rd_p) {
2186 PMD_TX_LOG(DEBUG, "queue %u: It seems harrier is not sending "
2187 "packets (%u, %u)", txq->qidx,
2188 qcp_rd_p, txq->rd_p);
2192 if (qcp_rd_p > txq->rd_p)
2193 todo = qcp_rd_p - txq->rd_p;
2195 todo = qcp_rd_p + txq->tx_count - txq->rd_p;
2197 PMD_TX_LOG(DEBUG, "qcp_rd_p %u, txq->rd_p: %u, qcp->rd_p: %u",
2198 qcp_rd_p, txq->rd_p, txq->rd_p);
2204 if (unlikely(txq->rd_p >= txq->tx_count))
2205 txq->rd_p -= txq->tx_count;
2210 /* Leaving always free descriptors for avoiding wrapping confusion */
2212 uint32_t nfp_free_tx_desc(struct nfp_net_txq *txq)
2214 if (txq->wr_p >= txq->rd_p)
2215 return txq->tx_count - (txq->wr_p - txq->rd_p) - 8;
2217 return txq->rd_p - txq->wr_p - 8;
2221 * nfp_net_txq_full - Check if the TX queue free descriptors
2222 * is below tx_free_threshold
2224 * @txq: TX queue to check
2226 * This function uses the host copy* of read/write pointers
2229 uint32_t nfp_net_txq_full(struct nfp_net_txq *txq)
2231 return (nfp_free_tx_desc(txq) < txq->tx_free_thresh);
2235 nfp_net_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
2237 struct nfp_net_txq *txq;
2238 struct nfp_net_hw *hw;
2239 struct nfp_net_tx_desc *txds, txd;
2240 struct rte_mbuf *pkt;
2242 int pkt_size, dma_size;
2243 uint16_t free_descs, issued_descs;
2244 struct rte_mbuf **lmbuf;
2249 txds = &txq->txds[txq->wr_p];
2251 PMD_TX_LOG(DEBUG, "working for queue %u at pos %d and %u packets",
2252 txq->qidx, txq->wr_p, nb_pkts);
2254 if ((nfp_free_tx_desc(txq) < nb_pkts) || (nfp_net_txq_full(txq)))
2255 nfp_net_tx_free_bufs(txq);
2257 free_descs = (uint16_t)nfp_free_tx_desc(txq);
2258 if (unlikely(free_descs == 0))
2265 PMD_TX_LOG(DEBUG, "queue: %u. Sending %u packets",
2266 txq->qidx, nb_pkts);
2267 /* Sending packets */
2268 while ((i < nb_pkts) && free_descs) {
2269 /* Grabbing the mbuf linked to the current descriptor */
2270 lmbuf = &txq->txbufs[txq->wr_p].mbuf;
2271 /* Warming the cache for releasing the mbuf later on */
2272 RTE_MBUF_PREFETCH_TO_FREE(*lmbuf);
2274 pkt = *(tx_pkts + i);
2276 if (unlikely((pkt->nb_segs > 1) &&
2277 !(hw->cap & NFP_NET_CFG_CTRL_GATHER))) {
2278 PMD_INIT_LOG(INFO, "NFP_NET_CFG_CTRL_GATHER not set");
2279 rte_panic("Multisegment packet unsupported\n");
2282 /* Checking if we have enough descriptors */
2283 if (unlikely(pkt->nb_segs > free_descs))
2287 * Checksum and VLAN flags just in the first descriptor for a
2288 * multisegment packet, but TSO info needs to be in all of them.
2290 txd.data_len = pkt->pkt_len;
2291 nfp_net_tx_tso(txq, &txd, pkt);
2292 nfp_net_tx_cksum(txq, &txd, pkt);
2294 if ((pkt->ol_flags & PKT_TX_VLAN_PKT) &&
2295 (hw->cap & NFP_NET_CFG_CTRL_TXVLAN)) {
2296 txd.flags |= PCIE_DESC_TX_VLAN;
2297 txd.vlan = pkt->vlan_tci;
2301 * mbuf data_len is the data in one segment and pkt_len data
2302 * in the whole packet. When the packet is just one segment,
2303 * then data_len = pkt_len
2305 pkt_size = pkt->pkt_len;
2308 /* Copying TSO, VLAN and cksum info */
2311 /* Releasing mbuf used by this descriptor previously*/
2313 rte_pktmbuf_free_seg(*lmbuf);
2316 * Linking mbuf with descriptor for being released
2317 * next time descriptor is used
2321 dma_size = pkt->data_len;
2322 dma_addr = rte_mbuf_data_iova(pkt);
2323 PMD_TX_LOG(DEBUG, "Working with mbuf at dma address:"
2324 "%" PRIx64 "", dma_addr);
2326 /* Filling descriptors fields */
2327 txds->dma_len = dma_size;
2328 txds->data_len = txd.data_len;
2329 txds->dma_addr_hi = (dma_addr >> 32) & 0xff;
2330 txds->dma_addr_lo = (dma_addr & 0xffffffff);
2331 ASSERT(free_descs > 0);
2335 if (unlikely(txq->wr_p == txq->tx_count)) /* wrapping?*/
2338 pkt_size -= dma_size;
2341 * Making the EOP, packets with just one segment
2344 if (likely(!pkt_size))
2345 txds->offset_eop = PCIE_DESC_TX_EOP;
2347 txds->offset_eop = 0;
2350 /* Referencing next free TX descriptor */
2351 txds = &txq->txds[txq->wr_p];
2352 lmbuf = &txq->txbufs[txq->wr_p].mbuf;
2359 /* Increment write pointers. Force memory write before we let HW know */
2361 nfp_qcp_ptr_add(txq->qcp_q, NFP_QCP_WRITE_PTR, issued_descs);
2367 nfp_net_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2369 uint32_t new_ctrl, update;
2370 struct nfp_net_hw *hw;
2373 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2376 if ((mask & ETH_VLAN_FILTER_OFFLOAD) ||
2377 (mask & ETH_VLAN_EXTEND_OFFLOAD))
2378 PMD_DRV_LOG(INFO, "No support for ETH_VLAN_FILTER_OFFLOAD or"
2379 " ETH_VLAN_EXTEND_OFFLOAD");
2381 /* Enable vlan strip if it is not configured yet */
2382 if ((mask & ETH_VLAN_STRIP_OFFLOAD) &&
2383 !(hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
2384 new_ctrl = hw->ctrl | NFP_NET_CFG_CTRL_RXVLAN;
2386 /* Disable vlan strip just if it is configured */
2387 if (!(mask & ETH_VLAN_STRIP_OFFLOAD) &&
2388 (hw->ctrl & NFP_NET_CFG_CTRL_RXVLAN))
2389 new_ctrl = hw->ctrl & ~NFP_NET_CFG_CTRL_RXVLAN;
2394 update = NFP_NET_CFG_UPDATE_GEN;
2396 ret = nfp_net_reconfig(hw, new_ctrl, update);
2398 hw->ctrl = new_ctrl;
2404 nfp_net_rss_reta_write(struct rte_eth_dev *dev,
2405 struct rte_eth_rss_reta_entry64 *reta_conf,
2408 uint32_t reta, mask;
2411 struct nfp_net_hw *hw =
2412 NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2414 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
2415 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2416 "(%d) doesn't match the number hardware can supported "
2417 "(%d)", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
2422 * Update Redirection Table. There are 128 8bit-entries which can be
2423 * manage as 32 32bit-entries
2425 for (i = 0; i < reta_size; i += 4) {
2426 /* Handling 4 RSS entries per loop */
2427 idx = i / RTE_RETA_GROUP_SIZE;
2428 shift = i % RTE_RETA_GROUP_SIZE;
2429 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
2435 /* If all 4 entries were set, don't need read RETA register */
2437 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + i);
2439 for (j = 0; j < 4; j++) {
2440 if (!(mask & (0x1 << j)))
2443 /* Clearing the entry bits */
2444 reta &= ~(0xFF << (8 * j));
2445 reta |= reta_conf[idx].reta[shift + j] << (8 * j);
2447 nn_cfg_writel(hw, NFP_NET_CFG_RSS_ITBL + (idx * 64) + shift,
2453 /* Update Redirection Table(RETA) of Receive Side Scaling of Ethernet device */
2455 nfp_net_reta_update(struct rte_eth_dev *dev,
2456 struct rte_eth_rss_reta_entry64 *reta_conf,
2459 struct nfp_net_hw *hw =
2460 NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2464 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
2467 ret = nfp_net_rss_reta_write(dev, reta_conf, reta_size);
2471 update = NFP_NET_CFG_UPDATE_RSS;
2473 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
2479 /* Query Redirection Table(RETA) of Receive Side Scaling of Ethernet device. */
2481 nfp_net_reta_query(struct rte_eth_dev *dev,
2482 struct rte_eth_rss_reta_entry64 *reta_conf,
2488 struct nfp_net_hw *hw;
2490 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2492 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
2495 if (reta_size != NFP_NET_CFG_RSS_ITBL_SZ) {
2496 PMD_DRV_LOG(ERR, "The size of hash lookup table configured "
2497 "(%d) doesn't match the number hardware can supported "
2498 "(%d)", reta_size, NFP_NET_CFG_RSS_ITBL_SZ);
2503 * Reading Redirection Table. There are 128 8bit-entries which can be
2504 * manage as 32 32bit-entries
2506 for (i = 0; i < reta_size; i += 4) {
2507 /* Handling 4 RSS entries per loop */
2508 idx = i / RTE_RETA_GROUP_SIZE;
2509 shift = i % RTE_RETA_GROUP_SIZE;
2510 mask = (uint8_t)((reta_conf[idx].mask >> shift) & 0xF);
2515 reta = nn_cfg_readl(hw, NFP_NET_CFG_RSS_ITBL + (idx * 64) +
2517 for (j = 0; j < 4; j++) {
2518 if (!(mask & (0x1 << j)))
2520 reta_conf[idx].reta[shift + j] =
2521 (uint8_t)((reta >> (8 * j)) & 0xF);
2528 nfp_net_rss_hash_write(struct rte_eth_dev *dev,
2529 struct rte_eth_rss_conf *rss_conf)
2531 struct nfp_net_hw *hw;
2533 uint32_t cfg_rss_ctrl = 0;
2537 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2539 /* Writing the key byte a byte */
2540 for (i = 0; i < rss_conf->rss_key_len; i++) {
2541 memcpy(&key, &rss_conf->rss_key[i], 1);
2542 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY + i, key);
2545 rss_hf = rss_conf->rss_hf;
2547 if (rss_hf & ETH_RSS_IPV4)
2548 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4;
2550 if (rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
2551 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4_TCP;
2553 if (rss_hf & ETH_RSS_NONFRAG_IPV4_UDP)
2554 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV4_UDP;
2556 if (rss_hf & ETH_RSS_IPV6)
2557 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6;
2559 if (rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
2560 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6_TCP;
2562 if (rss_hf & ETH_RSS_NONFRAG_IPV6_UDP)
2563 cfg_rss_ctrl |= NFP_NET_CFG_RSS_IPV6_UDP;
2565 cfg_rss_ctrl |= NFP_NET_CFG_RSS_MASK;
2566 cfg_rss_ctrl |= NFP_NET_CFG_RSS_TOEPLITZ;
2568 /* configuring where to apply the RSS hash */
2569 nn_cfg_writel(hw, NFP_NET_CFG_RSS_CTRL, cfg_rss_ctrl);
2571 /* Writing the key size */
2572 nn_cfg_writeb(hw, NFP_NET_CFG_RSS_KEY_SZ, rss_conf->rss_key_len);
2578 nfp_net_rss_hash_update(struct rte_eth_dev *dev,
2579 struct rte_eth_rss_conf *rss_conf)
2583 struct nfp_net_hw *hw;
2585 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2587 rss_hf = rss_conf->rss_hf;
2589 /* Checking if RSS is enabled */
2590 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS)) {
2591 if (rss_hf != 0) { /* Enable RSS? */
2592 PMD_DRV_LOG(ERR, "RSS unsupported");
2595 return 0; /* Nothing to do */
2598 if (rss_conf->rss_key_len > NFP_NET_CFG_RSS_KEY_SZ) {
2599 PMD_DRV_LOG(ERR, "hash key too long");
2603 nfp_net_rss_hash_write(dev, rss_conf);
2605 update = NFP_NET_CFG_UPDATE_RSS;
2607 if (nfp_net_reconfig(hw, hw->ctrl, update) < 0)
2614 nfp_net_rss_hash_conf_get(struct rte_eth_dev *dev,
2615 struct rte_eth_rss_conf *rss_conf)
2618 uint32_t cfg_rss_ctrl;
2621 struct nfp_net_hw *hw;
2623 hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2625 if (!(hw->ctrl & NFP_NET_CFG_CTRL_RSS))
2628 rss_hf = rss_conf->rss_hf;
2629 cfg_rss_ctrl = nn_cfg_readl(hw, NFP_NET_CFG_RSS_CTRL);
2631 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4)
2632 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP | ETH_RSS_NONFRAG_IPV4_UDP;
2634 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_TCP)
2635 rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
2637 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_TCP)
2638 rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
2640 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV4_UDP)
2641 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP;
2643 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6_UDP)
2644 rss_hf |= ETH_RSS_NONFRAG_IPV6_UDP;
2646 if (cfg_rss_ctrl & NFP_NET_CFG_RSS_IPV6)
2647 rss_hf |= ETH_RSS_NONFRAG_IPV4_UDP | ETH_RSS_NONFRAG_IPV6_UDP;
2649 /* Reading the key size */
2650 rss_conf->rss_key_len = nn_cfg_readl(hw, NFP_NET_CFG_RSS_KEY_SZ);
2652 /* Reading the key byte a byte */
2653 for (i = 0; i < rss_conf->rss_key_len; i++) {
2654 key = nn_cfg_readb(hw, NFP_NET_CFG_RSS_KEY + i);
2655 memcpy(&rss_conf->rss_key[i], &key, 1);
2662 nfp_net_rss_config_default(struct rte_eth_dev *dev)
2664 struct rte_eth_conf *dev_conf;
2665 struct rte_eth_rss_conf rss_conf;
2666 struct rte_eth_rss_reta_entry64 nfp_reta_conf[2];
2667 uint16_t rx_queues = dev->data->nb_rx_queues;
2671 PMD_DRV_LOG(INFO, "setting default RSS conf for %u queues",
2674 nfp_reta_conf[0].mask = ~0x0;
2675 nfp_reta_conf[1].mask = ~0x0;
2678 for (i = 0; i < 0x40; i += 8) {
2679 for (j = i; j < (i + 8); j++) {
2680 nfp_reta_conf[0].reta[j] = queue;
2681 nfp_reta_conf[1].reta[j] = queue++;
2685 ret = nfp_net_rss_reta_write(dev, nfp_reta_conf, 0x80);
2689 dev_conf = &dev->data->dev_conf;
2691 PMD_DRV_LOG(INFO, "wrong rss conf");
2694 rss_conf = dev_conf->rx_adv_conf.rss_conf;
2696 ret = nfp_net_rss_hash_write(dev, &rss_conf);
2702 /* Initialise and register driver with DPDK Application */
2703 static const struct eth_dev_ops nfp_net_eth_dev_ops = {
2704 .dev_configure = nfp_net_configure,
2705 .dev_start = nfp_net_start,
2706 .dev_stop = nfp_net_stop,
2707 .dev_set_link_up = nfp_net_set_link_up,
2708 .dev_set_link_down = nfp_net_set_link_down,
2709 .dev_close = nfp_net_close,
2710 .promiscuous_enable = nfp_net_promisc_enable,
2711 .promiscuous_disable = nfp_net_promisc_disable,
2712 .link_update = nfp_net_link_update,
2713 .stats_get = nfp_net_stats_get,
2714 .stats_reset = nfp_net_stats_reset,
2715 .dev_infos_get = nfp_net_infos_get,
2716 .dev_supported_ptypes_get = nfp_net_supported_ptypes_get,
2717 .mtu_set = nfp_net_dev_mtu_set,
2718 .mac_addr_set = nfp_set_mac_addr,
2719 .vlan_offload_set = nfp_net_vlan_offload_set,
2720 .reta_update = nfp_net_reta_update,
2721 .reta_query = nfp_net_reta_query,
2722 .rss_hash_update = nfp_net_rss_hash_update,
2723 .rss_hash_conf_get = nfp_net_rss_hash_conf_get,
2724 .rx_queue_setup = nfp_net_rx_queue_setup,
2725 .rx_queue_release = nfp_net_rx_queue_release,
2726 .rx_queue_count = nfp_net_rx_queue_count,
2727 .tx_queue_setup = nfp_net_tx_queue_setup,
2728 .tx_queue_release = nfp_net_tx_queue_release,
2729 .rx_queue_intr_enable = nfp_rx_queue_intr_enable,
2730 .rx_queue_intr_disable = nfp_rx_queue_intr_disable,
2734 * All eth_dev created got its private data, but before nfp_net_init, that
2735 * private data is referencing private data for all the PF ports. This is due
2736 * to how the vNIC bars are mapped based on first port, so all ports need info
2737 * about port 0 private data. Inside nfp_net_init the private data pointer is
2738 * changed to the right address for each port once the bars have been mapped.
2740 * This functions helps to find out which port and therefore which offset
2741 * inside the private data array to use.
2744 get_pf_port_number(char *name)
2746 char *pf_str = name;
2749 while ((*pf_str != '_') && (*pf_str != '\0') && (size++ < 30))
2754 * This should not happen at all and it would mean major
2755 * implementation fault.
2757 rte_panic("nfp_net: problem with pf device name\n");
2759 /* Expecting _portX with X within [0,7] */
2762 return (int)strtol(pf_str, NULL, 10);
2766 nfp_net_init(struct rte_eth_dev *eth_dev)
2768 struct rte_pci_device *pci_dev;
2769 struct nfp_net_hw *hw, *hwport0;
2771 uint64_t tx_bar_off = 0, rx_bar_off = 0;
2777 PMD_INIT_FUNC_TRACE();
2779 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
2781 /* NFP can not handle DMA addresses requiring more than 40 bits */
2782 if (rte_mem_check_dma_mask(40)) {
2783 RTE_LOG(ERR, PMD, "device %s can not be used:",
2784 pci_dev->device.name);
2785 RTE_LOG(ERR, PMD, "\trestricted dma mask to 40 bits!\n");
2789 if ((pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) ||
2790 (pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC)) {
2791 port = get_pf_port_number(eth_dev->data->name);
2792 if (port < 0 || port > 7) {
2793 PMD_DRV_LOG(ERR, "Port value is wrong");
2797 PMD_INIT_LOG(DEBUG, "Working with PF port value %d", port);
2799 /* This points to port 0 private data */
2800 hwport0 = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2802 /* This points to the specific port private data */
2803 hw = &hwport0[port];
2805 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
2809 eth_dev->dev_ops = &nfp_net_eth_dev_ops;
2810 eth_dev->rx_pkt_burst = &nfp_net_recv_pkts;
2811 eth_dev->tx_pkt_burst = &nfp_net_xmit_pkts;
2813 /* For secondary processes, the primary has done all the work */
2814 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2817 rte_eth_copy_pci_info(eth_dev, pci_dev);
2819 hw->device_id = pci_dev->id.device_id;
2820 hw->vendor_id = pci_dev->id.vendor_id;
2821 hw->subsystem_device_id = pci_dev->id.subsystem_device_id;
2822 hw->subsystem_vendor_id = pci_dev->id.subsystem_vendor_id;
2824 PMD_INIT_LOG(DEBUG, "nfp_net: device (%u:%u) %u:%u:%u:%u",
2825 pci_dev->id.vendor_id, pci_dev->id.device_id,
2826 pci_dev->addr.domain, pci_dev->addr.bus,
2827 pci_dev->addr.devid, pci_dev->addr.function);
2829 hw->ctrl_bar = (uint8_t *)pci_dev->mem_resource[0].addr;
2830 if (hw->ctrl_bar == NULL) {
2832 "hw->ctrl_bar is NULL. BAR0 not configured");
2836 if (hw->is_pf && port == 0) {
2837 hw->ctrl_bar = nfp_rtsym_map(hw->sym_tbl, "_pf0_net_bar0",
2838 hw->total_ports * 32768,
2840 if (!hw->ctrl_bar) {
2841 printf("nfp_rtsym_map fails for _pf0_net_ctrl_bar");
2845 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
2849 if (!hwport0->ctrl_bar)
2852 /* address based on port0 offset */
2853 hw->ctrl_bar = hwport0->ctrl_bar +
2854 (port * NFP_PF_CSR_SLICE_SIZE);
2857 PMD_INIT_LOG(DEBUG, "ctrl bar: %p", hw->ctrl_bar);
2859 hw->max_rx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_RXRINGS);
2860 hw->max_tx_queues = nn_cfg_readl(hw, NFP_NET_CFG_MAX_TXRINGS);
2862 /* Work out where in the BAR the queues start. */
2863 switch (pci_dev->id.device_id) {
2864 case PCI_DEVICE_ID_NFP4000_PF_NIC:
2865 case PCI_DEVICE_ID_NFP6000_PF_NIC:
2866 case PCI_DEVICE_ID_NFP6000_VF_NIC:
2867 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_TXQ);
2868 tx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
2869 start_q = nn_cfg_readl(hw, NFP_NET_CFG_START_RXQ);
2870 rx_bar_off = (uint64_t)start_q * NFP_QCP_QUEUE_ADDR_SZ;
2873 PMD_DRV_LOG(ERR, "nfp_net: no device ID matching");
2875 goto dev_err_ctrl_map;
2878 PMD_INIT_LOG(DEBUG, "tx_bar_off: 0x%" PRIx64 "", tx_bar_off);
2879 PMD_INIT_LOG(DEBUG, "rx_bar_off: 0x%" PRIx64 "", rx_bar_off);
2881 if (hw->is_pf && port == 0) {
2882 /* configure access to tx/rx vNIC BARs */
2883 hwport0->hw_queues = nfp_cpp_map_area(hw->cpp, 0, 0,
2885 NFP_QCP_QUEUE_AREA_SZ,
2886 &hw->hwqueues_area);
2888 if (!hwport0->hw_queues) {
2889 printf("nfp_rtsym_map fails for net.qc");
2891 goto dev_err_ctrl_map;
2894 PMD_INIT_LOG(DEBUG, "tx/rx bar address: 0x%p",
2895 hwport0->hw_queues);
2899 hw->tx_bar = hwport0->hw_queues + tx_bar_off;
2900 hw->rx_bar = hwport0->hw_queues + rx_bar_off;
2901 eth_dev->data->dev_private = hw;
2903 hw->tx_bar = (uint8_t *)pci_dev->mem_resource[2].addr +
2905 hw->rx_bar = (uint8_t *)pci_dev->mem_resource[2].addr +
2909 PMD_INIT_LOG(DEBUG, "ctrl_bar: %p, tx_bar: %p, rx_bar: %p",
2910 hw->ctrl_bar, hw->tx_bar, hw->rx_bar);
2912 nfp_net_cfg_queue_setup(hw);
2914 /* Get some of the read-only fields from the config BAR */
2915 hw->ver = nn_cfg_readl(hw, NFP_NET_CFG_VERSION);
2916 hw->cap = nn_cfg_readl(hw, NFP_NET_CFG_CAP);
2917 hw->max_mtu = nn_cfg_readl(hw, NFP_NET_CFG_MAX_MTU);
2918 hw->mtu = RTE_ETHER_MTU;
2920 /* VLAN insertion is incompatible with LSOv2 */
2921 if (hw->cap & NFP_NET_CFG_CTRL_LSO2)
2922 hw->cap &= ~NFP_NET_CFG_CTRL_TXVLAN;
2924 if (NFD_CFG_MAJOR_VERSION_of(hw->ver) < 2)
2925 hw->rx_offset = NFP_NET_RX_OFFSET;
2927 hw->rx_offset = nn_cfg_readl(hw, NFP_NET_CFG_RX_OFFSET_ADDR);
2929 PMD_INIT_LOG(INFO, "VER: %u.%u, Maximum supported MTU: %d",
2930 NFD_CFG_MAJOR_VERSION_of(hw->ver),
2931 NFD_CFG_MINOR_VERSION_of(hw->ver), hw->max_mtu);
2933 PMD_INIT_LOG(INFO, "CAP: %#x, %s%s%s%s%s%s%s%s%s%s%s%s%s%s", hw->cap,
2934 hw->cap & NFP_NET_CFG_CTRL_PROMISC ? "PROMISC " : "",
2935 hw->cap & NFP_NET_CFG_CTRL_L2BC ? "L2BCFILT " : "",
2936 hw->cap & NFP_NET_CFG_CTRL_L2MC ? "L2MCFILT " : "",
2937 hw->cap & NFP_NET_CFG_CTRL_RXCSUM ? "RXCSUM " : "",
2938 hw->cap & NFP_NET_CFG_CTRL_TXCSUM ? "TXCSUM " : "",
2939 hw->cap & NFP_NET_CFG_CTRL_RXVLAN ? "RXVLAN " : "",
2940 hw->cap & NFP_NET_CFG_CTRL_TXVLAN ? "TXVLAN " : "",
2941 hw->cap & NFP_NET_CFG_CTRL_SCATTER ? "SCATTER " : "",
2942 hw->cap & NFP_NET_CFG_CTRL_GATHER ? "GATHER " : "",
2943 hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR ? "LIVE_ADDR " : "",
2944 hw->cap & NFP_NET_CFG_CTRL_LSO ? "TSO " : "",
2945 hw->cap & NFP_NET_CFG_CTRL_LSO2 ? "TSOv2 " : "",
2946 hw->cap & NFP_NET_CFG_CTRL_RSS ? "RSS " : "",
2947 hw->cap & NFP_NET_CFG_CTRL_RSS2 ? "RSSv2 " : "");
2951 hw->stride_rx = stride;
2952 hw->stride_tx = stride;
2954 PMD_INIT_LOG(INFO, "max_rx_queues: %u, max_tx_queues: %u",
2955 hw->max_rx_queues, hw->max_tx_queues);
2957 /* Initializing spinlock for reconfigs */
2958 rte_spinlock_init(&hw->reconfig_lock);
2960 /* Allocating memory for mac addr */
2961 eth_dev->data->mac_addrs = rte_zmalloc("mac_addr",
2962 RTE_ETHER_ADDR_LEN, 0);
2963 if (eth_dev->data->mac_addrs == NULL) {
2964 PMD_INIT_LOG(ERR, "Failed to space for MAC address");
2966 goto dev_err_queues_map;
2970 nfp_net_pf_read_mac(hwport0, port);
2971 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
2973 nfp_net_vf_read_mac(hw);
2976 if (!rte_is_valid_assigned_ether_addr(
2977 (struct rte_ether_addr *)&hw->mac_addr)) {
2978 PMD_INIT_LOG(INFO, "Using random mac address for port %d",
2980 /* Using random mac addresses for VFs */
2981 rte_eth_random_addr(&hw->mac_addr[0]);
2982 nfp_net_write_mac(hw, (uint8_t *)&hw->mac_addr);
2985 /* Copying mac address to DPDK eth_dev struct */
2986 rte_ether_addr_copy((struct rte_ether_addr *)hw->mac_addr,
2987 ð_dev->data->mac_addrs[0]);
2989 if (!(hw->cap & NFP_NET_CFG_CTRL_LIVE_ADDR))
2990 eth_dev->data->dev_flags |= RTE_ETH_DEV_NOLIVE_MAC_ADDR;
2992 PMD_INIT_LOG(INFO, "port %d VendorID=0x%x DeviceID=0x%x "
2993 "mac=%02x:%02x:%02x:%02x:%02x:%02x",
2994 eth_dev->data->port_id, pci_dev->id.vendor_id,
2995 pci_dev->id.device_id,
2996 hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
2997 hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
2999 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3000 /* Registering LSC interrupt handler */
3001 rte_intr_callback_register(&pci_dev->intr_handle,
3002 nfp_net_dev_interrupt_handler,
3004 /* Telling the firmware about the LSC interrupt entry */
3005 nn_cfg_writeb(hw, NFP_NET_CFG_LSC, NFP_NET_IRQ_LSC_IDX);
3006 /* Recording current stats counters values */
3007 nfp_net_stats_reset(eth_dev);
3013 nfp_cpp_area_free(hw->hwqueues_area);
3015 nfp_cpp_area_free(hw->ctrl_area);
3020 #define NFP_CPP_MEMIO_BOUNDARY (1 << 20)
3023 * Serving a write request to NFP from host programs. The request
3024 * sends the write size and the CPP target. The bridge makes use
3025 * of CPP interface handler configured by the PMD setup.
3028 nfp_cpp_bridge_serve_write(int sockfd, struct nfp_cpp *cpp)
3030 struct nfp_cpp_area *area;
3031 off_t offset, nfp_offset;
3032 uint32_t cpp_id, pos, len;
3033 uint32_t tmpbuf[16];
3034 size_t count, curlen, totlen = 0;
3037 PMD_CPP_LOG(DEBUG, "%s: offset size %lu, count_size: %lu\n", __func__,
3038 sizeof(off_t), sizeof(size_t));
3040 /* Reading the count param */
3041 err = recv(sockfd, &count, sizeof(off_t), 0);
3042 if (err != sizeof(off_t))
3047 /* Reading the offset param */
3048 err = recv(sockfd, &offset, sizeof(off_t), 0);
3049 if (err != sizeof(off_t))
3052 /* Obtain target's CPP ID and offset in target */
3053 cpp_id = (offset >> 40) << 8;
3054 nfp_offset = offset & ((1ull << 40) - 1);
3056 PMD_CPP_LOG(DEBUG, "%s: count %lu and offset %ld\n", __func__, count,
3058 PMD_CPP_LOG(DEBUG, "%s: cpp_id %08x and nfp_offset %ld\n", __func__,
3059 cpp_id, nfp_offset);
3061 /* Adjust length if not aligned */
3062 if (((nfp_offset + (off_t)count - 1) & ~(NFP_CPP_MEMIO_BOUNDARY - 1)) !=
3063 (nfp_offset & ~(NFP_CPP_MEMIO_BOUNDARY - 1))) {
3064 curlen = NFP_CPP_MEMIO_BOUNDARY -
3065 (nfp_offset & (NFP_CPP_MEMIO_BOUNDARY - 1));
3069 /* configure a CPP PCIe2CPP BAR for mapping the CPP target */
3070 area = nfp_cpp_area_alloc_with_name(cpp, cpp_id, "nfp.cdev",
3071 nfp_offset, curlen);
3073 RTE_LOG(ERR, PMD, "%s: area alloc fail\n", __func__);
3077 /* mapping the target */
3078 err = nfp_cpp_area_acquire(area);
3080 RTE_LOG(ERR, PMD, "area acquire failed\n");
3081 nfp_cpp_area_free(area);
3085 for (pos = 0; pos < curlen; pos += len) {
3087 if (len > sizeof(tmpbuf))
3088 len = sizeof(tmpbuf);
3090 PMD_CPP_LOG(DEBUG, "%s: Receive %u of %lu\n", __func__,
3092 err = recv(sockfd, tmpbuf, len, MSG_WAITALL);
3093 if (err != (int)len) {
3095 "%s: error when receiving, %d of %lu\n",
3096 __func__, err, count);
3097 nfp_cpp_area_release(area);
3098 nfp_cpp_area_free(area);
3101 err = nfp_cpp_area_write(area, pos, tmpbuf, len);
3103 RTE_LOG(ERR, PMD, "nfp_cpp_area_write error\n");
3104 nfp_cpp_area_release(area);
3105 nfp_cpp_area_free(area);
3112 nfp_cpp_area_release(area);
3113 nfp_cpp_area_free(area);
3116 curlen = (count > NFP_CPP_MEMIO_BOUNDARY) ?
3117 NFP_CPP_MEMIO_BOUNDARY : count;
3124 * Serving a read request to NFP from host programs. The request
3125 * sends the read size and the CPP target. The bridge makes use
3126 * of CPP interface handler configured by the PMD setup. The read
3127 * data is sent to the requester using the same socket.
3130 nfp_cpp_bridge_serve_read(int sockfd, struct nfp_cpp *cpp)
3132 struct nfp_cpp_area *area;
3133 off_t offset, nfp_offset;
3134 uint32_t cpp_id, pos, len;
3135 uint32_t tmpbuf[16];
3136 size_t count, curlen, totlen = 0;
3139 PMD_CPP_LOG(DEBUG, "%s: offset size %lu, count_size: %lu\n", __func__,
3140 sizeof(off_t), sizeof(size_t));
3142 /* Reading the count param */
3143 err = recv(sockfd, &count, sizeof(off_t), 0);
3144 if (err != sizeof(off_t))
3149 /* Reading the offset param */
3150 err = recv(sockfd, &offset, sizeof(off_t), 0);
3151 if (err != sizeof(off_t))
3154 /* Obtain target's CPP ID and offset in target */
3155 cpp_id = (offset >> 40) << 8;
3156 nfp_offset = offset & ((1ull << 40) - 1);
3158 PMD_CPP_LOG(DEBUG, "%s: count %lu and offset %ld\n", __func__, count,
3160 PMD_CPP_LOG(DEBUG, "%s: cpp_id %08x and nfp_offset %ld\n", __func__,
3161 cpp_id, nfp_offset);
3163 /* Adjust length if not aligned */
3164 if (((nfp_offset + (off_t)count - 1) & ~(NFP_CPP_MEMIO_BOUNDARY - 1)) !=
3165 (nfp_offset & ~(NFP_CPP_MEMIO_BOUNDARY - 1))) {
3166 curlen = NFP_CPP_MEMIO_BOUNDARY -
3167 (nfp_offset & (NFP_CPP_MEMIO_BOUNDARY - 1));
3171 area = nfp_cpp_area_alloc_with_name(cpp, cpp_id, "nfp.cdev",
3172 nfp_offset, curlen);
3174 RTE_LOG(ERR, PMD, "%s: area alloc failed\n", __func__);
3178 err = nfp_cpp_area_acquire(area);
3180 RTE_LOG(ERR, PMD, "area acquire failed\n");
3181 nfp_cpp_area_free(area);
3185 for (pos = 0; pos < curlen; pos += len) {
3187 if (len > sizeof(tmpbuf))
3188 len = sizeof(tmpbuf);
3190 err = nfp_cpp_area_read(area, pos, tmpbuf, len);
3192 RTE_LOG(ERR, PMD, "nfp_cpp_area_read error\n");
3193 nfp_cpp_area_release(area);
3194 nfp_cpp_area_free(area);
3197 PMD_CPP_LOG(DEBUG, "%s: sending %u of %lu\n", __func__,
3200 err = send(sockfd, tmpbuf, len, 0);
3201 if (err != (int)len) {
3203 "%s: error when sending: %d of %lu\n",
3204 __func__, err, count);
3205 nfp_cpp_area_release(area);
3206 nfp_cpp_area_free(area);
3213 nfp_cpp_area_release(area);
3214 nfp_cpp_area_free(area);
3217 curlen = (count > NFP_CPP_MEMIO_BOUNDARY) ?
3218 NFP_CPP_MEMIO_BOUNDARY : count;
3223 #define NFP_IOCTL 'n'
3224 #define NFP_IOCTL_CPP_IDENTIFICATION _IOW(NFP_IOCTL, 0x8f, uint32_t)
3226 * Serving a ioctl command from host NFP tools. This usually goes to
3227 * a kernel driver char driver but it is not available when the PF is
3228 * bound to the PMD. Currently just one ioctl command is served and it
3229 * does not require any CPP access at all.
3232 nfp_cpp_bridge_serve_ioctl(int sockfd, struct nfp_cpp *cpp)
3234 uint32_t cmd, ident_size, tmp;
3237 /* Reading now the IOCTL command */
3238 err = recv(sockfd, &cmd, 4, 0);
3240 RTE_LOG(ERR, PMD, "%s: read error from socket\n", __func__);
3244 /* Only supporting NFP_IOCTL_CPP_IDENTIFICATION */
3245 if (cmd != NFP_IOCTL_CPP_IDENTIFICATION) {
3246 RTE_LOG(ERR, PMD, "%s: unknown cmd %d\n", __func__, cmd);
3250 err = recv(sockfd, &ident_size, 4, 0);
3252 RTE_LOG(ERR, PMD, "%s: read error from socket\n", __func__);
3256 tmp = nfp_cpp_model(cpp);
3258 PMD_CPP_LOG(DEBUG, "%s: sending NFP model %08x\n", __func__, tmp);
3260 err = send(sockfd, &tmp, 4, 0);
3262 RTE_LOG(ERR, PMD, "%s: error writing to socket\n", __func__);
3266 tmp = cpp->interface;
3268 PMD_CPP_LOG(DEBUG, "%s: sending NFP interface %08x\n", __func__, tmp);
3270 err = send(sockfd, &tmp, 4, 0);
3272 RTE_LOG(ERR, PMD, "%s: error writing to socket\n", __func__);
3279 #define NFP_BRIDGE_OP_READ 20
3280 #define NFP_BRIDGE_OP_WRITE 30
3281 #define NFP_BRIDGE_OP_IOCTL 40
3284 * This is the code to be executed by a service core. The CPP bridge interface
3285 * is based on a unix socket and requests usually received by a kernel char
3286 * driver, read, write and ioctl, are handled by the CPP bridge. NFP host tools
3287 * can be executed with a wrapper library and LD_LIBRARY being completely
3288 * unaware of the CPP bridge performing the NFP kernel char driver for CPP
3292 nfp_cpp_bridge_service_func(void *args)
3294 struct sockaddr address;
3295 struct nfp_cpp *cpp = args;
3296 int sockfd, datafd, op, ret;
3298 unlink("/tmp/nfp_cpp");
3299 sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
3301 RTE_LOG(ERR, PMD, "%s: socket creation error. Service failed\n",
3306 memset(&address, 0, sizeof(struct sockaddr));
3308 address.sa_family = AF_UNIX;
3309 strcpy(address.sa_data, "/tmp/nfp_cpp");
3311 ret = bind(sockfd, (const struct sockaddr *)&address,
3312 sizeof(struct sockaddr));
3314 RTE_LOG(ERR, PMD, "%s: bind error (%d). Service failed\n",
3320 ret = listen(sockfd, 20);
3322 RTE_LOG(ERR, PMD, "%s: listen error(%d). Service failed\n",
3329 datafd = accept(sockfd, NULL, NULL);
3331 RTE_LOG(ERR, PMD, "%s: accept call error (%d)\n",
3333 RTE_LOG(ERR, PMD, "%s: service failed\n", __func__);
3339 ret = recv(datafd, &op, 4, 0);
3341 PMD_CPP_LOG(DEBUG, "%s: socket close\n",
3346 PMD_CPP_LOG(DEBUG, "%s: getting op %u\n", __func__, op);
3348 if (op == NFP_BRIDGE_OP_READ)
3349 nfp_cpp_bridge_serve_read(datafd, cpp);
3351 if (op == NFP_BRIDGE_OP_WRITE)
3352 nfp_cpp_bridge_serve_write(datafd, cpp);
3354 if (op == NFP_BRIDGE_OP_IOCTL)
3355 nfp_cpp_bridge_serve_ioctl(datafd, cpp);
3368 nfp_pf_create_dev(struct rte_pci_device *dev, int port, int ports,
3369 struct nfp_cpp *cpp, struct nfp_hwinfo *hwinfo,
3370 int phys_port, struct nfp_rtsym_table *sym_tbl, void **priv)
3372 struct rte_eth_dev *eth_dev;
3373 struct nfp_net_hw *hw = NULL;
3375 struct rte_service_spec service;
3378 port_name = rte_zmalloc("nfp_pf_port_name", 100, 0);
3383 snprintf(port_name, 100, "%s_port%d", dev->device.name, port);
3385 strlcat(port_name, dev->device.name, 100);
3388 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3389 eth_dev = rte_eth_dev_allocate(port_name);
3391 rte_free(port_name);
3395 *priv = rte_zmalloc(port_name,
3396 sizeof(struct nfp_net_adapter) *
3397 ports, RTE_CACHE_LINE_SIZE);
3399 rte_free(port_name);
3400 rte_eth_dev_release_port(eth_dev);
3404 eth_dev->data->dev_private = *priv;
3407 * dev_private pointing to port0 dev_private because we need
3408 * to configure vNIC bars based on port0 at nfp_net_init.
3409 * Then dev_private is adjusted per port.
3411 hw = (struct nfp_net_hw *)(eth_dev->data->dev_private) + port;
3413 hw->hwinfo = hwinfo;
3414 hw->sym_tbl = sym_tbl;
3415 hw->pf_port_idx = phys_port;
3418 hw->pf_multiport_enabled = 1;
3420 hw->total_ports = ports;
3422 eth_dev = rte_eth_dev_attach_secondary(port_name);
3424 RTE_LOG(ERR, EAL, "secondary process attach failed, "
3425 "ethdev doesn't exist");
3426 rte_free(port_name);
3429 eth_dev->process_private = cpp;
3432 eth_dev->device = &dev->device;
3433 rte_eth_copy_pci_info(eth_dev, dev);
3435 retval = nfp_net_init(eth_dev);
3441 rte_eth_dev_probing_finish(eth_dev);
3444 rte_free(port_name);
3448 * The rte_service needs to be created just once per PMD.
3449 * And the cpp handler needs to be linked to the service.
3450 * Secondary processes will be used for debugging DPDK apps
3451 * when requiring to use the CPP interface for accessing NFP
3452 * components. And the cpp handler for secondary processes is
3453 * available at this point.
3455 memset(&service, 0, sizeof(struct rte_service_spec));
3456 snprintf(service.name, sizeof(service.name), "nfp_cpp_service");
3457 service.callback = nfp_cpp_bridge_service_func;
3458 service.callback_userdata = (void *)cpp;
3460 hw = (struct nfp_net_hw *)(eth_dev->data->dev_private);
3462 if (rte_service_component_register(&service,
3463 &hw->nfp_cpp_service_id))
3464 RTE_LOG(ERR, PMD, "NFP CPP bridge service register() failed");
3466 RTE_LOG(DEBUG, PMD, "NFP CPP bridge service registered");
3472 rte_free(port_name);
3473 /* free ports private data if primary process */
3474 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
3475 rte_free(eth_dev->data->dev_private);
3477 rte_eth_dev_release_port(eth_dev);
3482 #define DEFAULT_FW_PATH "/lib/firmware/netronome"
3485 nfp_fw_upload(struct rte_pci_device *dev, struct nfp_nsp *nsp, char *card)
3487 struct nfp_cpp *cpp = nsp->cpp;
3492 struct stat file_stat;
3495 /* Looking for firmware file in order of priority */
3497 /* First try to find a firmware image specific for this device */
3498 snprintf(serial, sizeof(serial),
3499 "serial-%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x",
3500 cpp->serial[0], cpp->serial[1], cpp->serial[2], cpp->serial[3],
3501 cpp->serial[4], cpp->serial[5], cpp->interface >> 8,
3502 cpp->interface & 0xff);
3504 snprintf(fw_name, sizeof(fw_name), "%s/%s.nffw", DEFAULT_FW_PATH,
3507 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
3508 fw_f = open(fw_name, O_RDONLY);
3512 /* Then try the PCI name */
3513 snprintf(fw_name, sizeof(fw_name), "%s/pci-%s.nffw", DEFAULT_FW_PATH,
3516 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
3517 fw_f = open(fw_name, O_RDONLY);
3521 /* Finally try the card type and media */
3522 snprintf(fw_name, sizeof(fw_name), "%s/%s", DEFAULT_FW_PATH, card);
3523 PMD_DRV_LOG(DEBUG, "Trying with fw file: %s", fw_name);
3524 fw_f = open(fw_name, O_RDONLY);
3526 PMD_DRV_LOG(INFO, "Firmware file %s not found.", fw_name);
3531 if (fstat(fw_f, &file_stat) < 0) {
3532 PMD_DRV_LOG(INFO, "Firmware file %s size is unknown", fw_name);
3537 fsize = file_stat.st_size;
3538 PMD_DRV_LOG(INFO, "Firmware file found at %s with size: %" PRIu64 "",
3539 fw_name, (uint64_t)fsize);
3541 fw_buf = malloc((size_t)fsize);
3543 PMD_DRV_LOG(INFO, "malloc failed for fw buffer");
3547 memset(fw_buf, 0, fsize);
3549 bytes = read(fw_f, fw_buf, fsize);
3550 if (bytes != fsize) {
3551 PMD_DRV_LOG(INFO, "Reading fw to buffer failed."
3552 "Just %" PRIu64 " of %" PRIu64 " bytes read",
3553 (uint64_t)bytes, (uint64_t)fsize);
3559 PMD_DRV_LOG(INFO, "Uploading the firmware ...");
3560 nfp_nsp_load_fw(nsp, fw_buf, bytes);
3561 PMD_DRV_LOG(INFO, "Done");
3570 nfp_fw_setup(struct rte_pci_device *dev, struct nfp_cpp *cpp,
3571 struct nfp_eth_table *nfp_eth_table, struct nfp_hwinfo *hwinfo)
3573 struct nfp_nsp *nsp;
3574 const char *nfp_fw_model;
3575 char card_desc[100];
3578 nfp_fw_model = nfp_hwinfo_lookup(hwinfo, "assembly.partno");
3581 PMD_DRV_LOG(INFO, "firmware model found: %s", nfp_fw_model);
3583 PMD_DRV_LOG(ERR, "firmware model NOT found");
3587 if (nfp_eth_table->count == 0 || nfp_eth_table->count > 8) {
3588 PMD_DRV_LOG(ERR, "NFP ethernet table reports wrong ports: %u",
3589 nfp_eth_table->count);
3593 PMD_DRV_LOG(INFO, "NFP ethernet port table reports %u ports",
3594 nfp_eth_table->count);
3596 PMD_DRV_LOG(INFO, "Port speed: %u", nfp_eth_table->ports[0].speed);
3598 snprintf(card_desc, sizeof(card_desc), "nic_%s_%dx%d.nffw",
3599 nfp_fw_model, nfp_eth_table->count,
3600 nfp_eth_table->ports[0].speed / 1000);
3602 nsp = nfp_nsp_open(cpp);
3604 PMD_DRV_LOG(ERR, "NFP error when obtaining NSP handle");
3608 nfp_nsp_device_soft_reset(nsp);
3609 err = nfp_fw_upload(dev, nsp, card_desc);
3615 static int nfp_pf_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3616 struct rte_pci_device *dev)
3618 struct nfp_cpp *cpp;
3619 struct nfp_hwinfo *hwinfo;
3620 struct nfp_rtsym_table *sym_tbl;
3621 struct nfp_eth_table *nfp_eth_table = NULL;
3632 * When device bound to UIO, the device could be used, by mistake,
3633 * by two DPDK apps, and the UIO driver does not avoid it. This
3634 * could lead to a serious problem when configuring the NFP CPP
3635 * interface. Here we avoid this telling to the CPP init code to
3636 * use a lock file if UIO is being used.
3638 if (dev->kdrv == RTE_KDRV_VFIO)
3639 cpp = nfp_cpp_from_device_name(dev, 0);
3641 cpp = nfp_cpp_from_device_name(dev, 1);
3644 PMD_DRV_LOG(ERR, "A CPP handle can not be obtained");
3649 hwinfo = nfp_hwinfo_read(cpp);
3651 PMD_DRV_LOG(ERR, "Error reading hwinfo table");
3655 nfp_eth_table = nfp_eth_read_ports(cpp);
3656 if (!nfp_eth_table) {
3657 PMD_DRV_LOG(ERR, "Error reading NFP ethernet table");
3661 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
3662 if (nfp_fw_setup(dev, cpp, nfp_eth_table, hwinfo)) {
3663 PMD_DRV_LOG(INFO, "Error when uploading firmware");
3669 /* Now the symbol table should be there */
3670 sym_tbl = nfp_rtsym_table_read(cpp);
3672 PMD_DRV_LOG(ERR, "Something is wrong with the firmware"
3678 total_ports = nfp_rtsym_read_le(sym_tbl, "nfd_cfg_pf0_num_ports", &err);
3679 if (total_ports != (int)nfp_eth_table->count) {
3680 PMD_DRV_LOG(ERR, "Inconsistent number of ports");
3684 PMD_INIT_LOG(INFO, "Total pf ports: %d", total_ports);
3686 if (total_ports <= 0 || total_ports > 8) {
3687 PMD_DRV_LOG(ERR, "nfd_cfg_pf0_num_ports symbol with wrong value");
3692 for (i = 0; i < total_ports; i++) {
3693 ret = nfp_pf_create_dev(dev, i, total_ports, cpp, hwinfo,
3694 nfp_eth_table->ports[i].index,
3701 free(nfp_eth_table);
3705 int nfp_logtype_init;
3706 int nfp_logtype_driver;
3708 static const struct rte_pci_id pci_id_nfp_pf_net_map[] = {
3710 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
3711 PCI_DEVICE_ID_NFP4000_PF_NIC)
3714 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
3715 PCI_DEVICE_ID_NFP6000_PF_NIC)
3722 static const struct rte_pci_id pci_id_nfp_vf_net_map[] = {
3724 RTE_PCI_DEVICE(PCI_VENDOR_ID_NETRONOME,
3725 PCI_DEVICE_ID_NFP6000_VF_NIC)
3732 static int eth_nfp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
3733 struct rte_pci_device *pci_dev)
3735 return rte_eth_dev_pci_generic_probe(pci_dev,
3736 sizeof(struct nfp_net_adapter), nfp_net_init);
3739 static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
3741 struct rte_eth_dev *eth_dev;
3742 struct nfp_net_hw *hw, *hwport0;
3745 eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
3746 if ((pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) ||
3747 (pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC)) {
3748 port = get_pf_port_number(eth_dev->data->name);
3750 * hotplug is not possible with multiport PF although freeing
3751 * data structures can be done for first port.
3755 hwport0 = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
3756 hw = &hwport0[port];
3757 nfp_cpp_area_free(hw->ctrl_area);
3758 nfp_cpp_area_free(hw->hwqueues_area);
3761 nfp_cpp_free(hw->cpp);
3763 hw = NFP_NET_DEV_PRIVATE_TO_HW(eth_dev->data->dev_private);
3765 /* hotplug is not possible with multiport PF */
3766 if (hw->pf_multiport_enabled)
3768 return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
3771 static struct rte_pci_driver rte_nfp_net_pf_pmd = {
3772 .id_table = pci_id_nfp_pf_net_map,
3773 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
3774 .probe = nfp_pf_pci_probe,
3775 .remove = eth_nfp_pci_remove,
3778 static struct rte_pci_driver rte_nfp_net_vf_pmd = {
3779 .id_table = pci_id_nfp_vf_net_map,
3780 .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
3781 .probe = eth_nfp_pci_probe,
3782 .remove = eth_nfp_pci_remove,
3785 RTE_PMD_REGISTER_PCI(net_nfp_pf, rte_nfp_net_pf_pmd);
3786 RTE_PMD_REGISTER_PCI(net_nfp_vf, rte_nfp_net_vf_pmd);
3787 RTE_PMD_REGISTER_PCI_TABLE(net_nfp_pf, pci_id_nfp_pf_net_map);
3788 RTE_PMD_REGISTER_PCI_TABLE(net_nfp_vf, pci_id_nfp_vf_net_map);
3789 RTE_PMD_REGISTER_KMOD_DEP(net_nfp_pf, "* igb_uio | uio_pci_generic | vfio");
3790 RTE_PMD_REGISTER_KMOD_DEP(net_nfp_vf, "* igb_uio | uio_pci_generic | vfio");
3792 RTE_INIT(nfp_init_log)
3794 nfp_logtype_init = rte_log_register("pmd.net.nfp.init");
3795 if (nfp_logtype_init >= 0)
3796 rte_log_set_level(nfp_logtype_init, RTE_LOG_NOTICE);
3797 nfp_logtype_driver = rte_log_register("pmd.net.nfp.driver");
3798 if (nfp_logtype_driver >= 0)
3799 rte_log_set_level(nfp_logtype_driver, RTE_LOG_NOTICE);
3803 * c-file-style: "Linux"
3804 * indent-tabs-mode: t