ethdev: move info filling of PCI into drivers
[dpdk.git] / drivers / net / nfp / nfp_net.c
index d43db47..590ecb2 100644 (file)
@@ -607,18 +607,8 @@ nfp_net_rx_freelist_setup(struct rte_eth_dev *dev)
 static void
 nfp_net_params_setup(struct nfp_net_hw *hw)
 {
-       uint32_t *mac_address;
-
        nn_cfg_writel(hw, NFP_NET_CFG_MTU, hw->mtu);
        nn_cfg_writel(hw, NFP_NET_CFG_FLBUFSZ, hw->flbufsz);
-
-       /* A MAC address is 8 bytes long */
-       mac_address = (uint32_t *)(hw->mac_addr);
-
-       nn_cfg_writel(hw, NFP_NET_CFG_MACADDR,
-                     rte_cpu_to_be_32(*mac_address));
-       nn_cfg_writel(hw, NFP_NET_CFG_MACADDR + 4,
-                     rte_cpu_to_be_32(*(mac_address + 4)));
 }
 
 static void
@@ -627,6 +617,17 @@ nfp_net_cfg_queue_setup(struct nfp_net_hw *hw)
        hw->qcp_cfg = hw->tx_bar + NFP_QCP_QUEUE_ADDR_SZ;
 }
 
+static void nfp_net_read_mac(struct nfp_net_hw *hw)
+{
+       uint32_t tmp;
+
+       tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR));
+       memcpy(&hw->mac_addr[0], &tmp, sizeof(struct ether_addr));
+
+       tmp = rte_be_to_cpu_32(nn_cfg_readl(hw, NFP_NET_CFG_MACADDR + 4));
+       memcpy(&hw->mac_addr[4], &tmp, 2);
+}
+
 static int
 nfp_net_start(struct rte_eth_dev *dev)
 {
@@ -717,10 +718,12 @@ static void
 nfp_net_close(struct rte_eth_dev *dev)
 {
        struct nfp_net_hw *hw;
+       struct rte_pci_device *pci_dev;
 
        PMD_INIT_LOG(DEBUG, "Close\n");
 
        hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       pci_dev = dev->pci_dev;
 
        /*
         * We assume that the DPDK application is stopping all the
@@ -729,9 +732,14 @@ nfp_net_close(struct rte_eth_dev *dev)
 
        nfp_net_stop(dev);
 
-       rte_intr_disable(&dev->pci_dev->intr_handle);
+       rte_intr_disable(&pci_dev->intr_handle);
        nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
 
+       /* unregister callback func from eal lib */
+       rte_intr_callback_unregister(&pci_dev->intr_handle,
+                                    nfp_net_dev_interrupt_handler,
+                                    (void *)dev);
+
        /*
         * The ixgbe PMD driver disables the pcie master on the
         * device. The i40e does not...
@@ -1000,6 +1008,7 @@ nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 
        hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
+       dev_info->pci_dev = dev->pci_dev;
        dev_info->driver_name = dev->driver->pci_drv.driver.name;
        dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
        dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
@@ -1116,6 +1125,7 @@ nfp_net_rx_queue_count(struct rte_eth_dev *dev, uint16_t queue_idx)
 static void
 nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
 {
+       struct rte_pci_device *pci_dev = dev->pci_dev;
        struct rte_eth_link link;
 
        memset(&link, 0, sizeof(link));
@@ -1130,8 +1140,8 @@ nfp_net_dev_link_status_print(struct rte_eth_dev *dev)
                        (int)(dev->data->port_id));
 
        RTE_LOG(INFO, PMD, "PCI Address: %04d:%02d:%02d:%d\n",
-               dev->pci_dev->addr.domain, dev->pci_dev->addr.bus,
-               dev->pci_dev->addr.devid, dev->pci_dev->addr.function);
+               pci_dev->addr.domain, pci_dev->addr.bus,
+               pci_dev->addr.devid, pci_dev->addr.function);
 }
 
 /* Interrupt configuration and handling */
@@ -1146,13 +1156,15 @@ static void
 nfp_net_irq_unmask(struct rte_eth_dev *dev)
 {
        struct nfp_net_hw *hw;
+       struct rte_pci_device *pci_dev;
 
        hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
+       pci_dev = dev->pci_dev;
 
        if (hw->ctrl & NFP_NET_CFG_CTRL_MSIXAUTO) {
                /* If MSI-X auto-masking is used, clear the entry */
                rte_wmb();
-               rte_intr_enable(&dev->pci_dev->intr_handle);
+               rte_intr_enable(&pci_dev->intr_handle);
        } else {
                /* Make sure all updates are written before un-masking */
                rte_wmb();
@@ -1213,7 +1225,7 @@ nfp_net_dev_interrupt_delayed_handler(void *param)
        struct rte_eth_dev *dev = (struct rte_eth_dev *)param;
 
        nfp_net_link_update(dev, 0);
-       _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC);
+       _rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_INTR_LSC, NULL);
 
        nfp_net_dev_link_status_print(dev);
 
@@ -1701,7 +1713,7 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                 * DPDK just checks the queue is lower than max queues
                 * enabled. But the queue needs to be configured
                 */
-               RTE_LOG(ERR, PMD, "RX Bad queue\n");
+               RTE_LOG_DP(ERR, PMD, "RX Bad queue\n");
                return -EINVAL;
        }
 
@@ -1714,7 +1726,7 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
 
                rxb = &rxq->rxbufs[idx];
                if (unlikely(rxb == NULL)) {
-                       RTE_LOG(ERR, PMD, "rxb does not exist!\n");
+                       RTE_LOG_DP(ERR, PMD, "rxb does not exist!\n");
                        break;
                }
 
@@ -1734,7 +1746,7 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                 */
                new_mb = rte_pktmbuf_alloc(rxq->mem_pool);
                if (unlikely(new_mb == NULL)) {
-                       RTE_LOG(DEBUG, PMD, "RX mbuf alloc failed port_id=%u "
+                       RTE_LOG_DP(DEBUG, PMD, "RX mbuf alloc failed port_id=%u "
                                "queue_id=%u\n", (unsigned)rxq->port_id,
                                (unsigned)rxq->qidx);
                        nfp_net_mbuf_alloc_failed(rxq);
@@ -1765,7 +1777,7 @@ nfp_net_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, uint16_t nb_pkts)
                         * responsibility of avoiding it. But we have
                         * to give some info about the error
                         */
-                       RTE_LOG(ERR, PMD,
+                       RTE_LOG_DP(ERR, PMD,
                                "mbuf overflow likely due to the RX offset.\n"
                                "\t\tYour mbuf size should have extra space for"
                                " RX offset=%u bytes.\n"
@@ -2394,7 +2406,6 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
                     hw->cap & NFP_NET_CFG_CTRL_LSO     ? "TSO "     : "",
                     hw->cap & NFP_NET_CFG_CTRL_RSS     ? "RSS "     : "");
 
-       pci_dev = eth_dev->pci_dev;
        hw->ctrl = 0;
 
        hw->stride_rx = stride;
@@ -2413,12 +2424,15 @@ nfp_net_init(struct rte_eth_dev *eth_dev)
                return -ENOMEM;
        }
 
-       /* Using random mac addresses for VFs */
-       eth_random_addr(&hw->mac_addr[0]);
+       nfp_net_read_mac(hw);
+
+       if (!is_valid_assigned_ether_addr((struct ether_addr *)&hw->mac_addr))
+               /* Using random mac addresses for VFs */
+               eth_random_addr(&hw->mac_addr[0]);
 
        /* Copying mac address to DPDK eth_dev struct */
-       ether_addr_copy(&eth_dev->data->mac_addrs[0],
-                       (struct ether_addr *)hw->mac_addr);
+       ether_addr_copy((struct ether_addr *)hw->mac_addr,
+                       &eth_dev->data->mac_addrs[0]);
 
        PMD_INIT_LOG(INFO, "port %d VendorID=0x%x DeviceID=0x%x "
                     "mac=%02x:%02x:%02x:%02x:%02x:%02x",
@@ -2470,8 +2484,9 @@ static struct eth_driver rte_nfp_net_pmd = {
        .dev_private_size = sizeof(struct nfp_net_adapter),
 };
 
-DRIVER_REGISTER_PCI(net_nfp, rte_nfp_net_pmd.pci_drv);
-DRIVER_REGISTER_PCI_TABLE(net_nfp, pci_id_nfp_net_map);
+RTE_PMD_REGISTER_PCI(net_nfp, rte_nfp_net_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI_TABLE(net_nfp, pci_id_nfp_net_map);
+RTE_PMD_REGISTER_KMOD_DEP(net_nfp, "* igb_uio | uio_pci_generic | vfio");
 
 /*
  * Local variables: