drivers/net: do not use ethdev driver
[dpdk.git] / drivers / net / thunderx / nicvf_ethdev.c
index 094c5d5..b0b9c3b 100644 (file)
@@ -41,7 +41,6 @@
 #include <inttypes.h>
 #include <netinet/in.h>
 #include <sys/queue.h>
-#include <sys/timerfd.h>
 
 #include <rte_alarm.h>
 #include <rte_atomic.h>
@@ -54,6 +53,7 @@
 #include <rte_eal.h>
 #include <rte_ether.h>
 #include <rte_ethdev.h>
+#include <rte_ethdev_pci.h>
 #include <rte_interrupts.h>
 #include <rte_log.h>
 #include <rte_memory.h>
@@ -145,16 +145,29 @@ nicvf_periodic_alarm_stop(void (fn)(void *), void *arg)
  * Return 0 means link status changed, -1 means not changed
  */
 static int
-nicvf_dev_link_update(struct rte_eth_dev *dev,
-                     int wait_to_complete __rte_unused)
+nicvf_dev_link_update(struct rte_eth_dev *dev, int wait_to_complete)
 {
+#define CHECK_INTERVAL 100  /* 100ms */
+#define MAX_CHECK_TIME 90   /* 9s (90 * 100ms) in total */
        struct rte_eth_link link;
        struct nicvf *nic = nicvf_pmd_priv(dev);
+       int i;
 
        PMD_INIT_FUNC_TRACE();
 
-       memset(&link, 0, sizeof(link));
-       nicvf_set_eth_link_status(nic, &link);
+       if (wait_to_complete) {
+               /* rte_eth_link_get() might need to wait up to 9 seconds */
+               for (i = 0; i < MAX_CHECK_TIME; i++) {
+                       memset(&link, 0, sizeof(link));
+                       nicvf_set_eth_link_status(nic, &link);
+                       if (link.link_status)
+                               break;
+                       rte_delay_ms(CHECK_INTERVAL);
+               }
+       } else {
+               memset(&link, 0, sizeof(link));
+               nicvf_set_eth_link_status(nic, &link);
+       }
        return nicvf_atomic_write_link_status(dev, &link);
 }
 
@@ -1335,9 +1348,12 @@ static void
 nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 {
        struct nicvf *nic = nicvf_pmd_priv(dev);
+       struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
 
        PMD_INIT_FUNC_TRACE();
 
+       dev_info->pci_dev = RTE_DEV_TO_PCI(dev->device);
+
        dev_info->min_rx_bufsize = ETHER_MIN_MTU;
        dev_info->max_rx_pktlen = NIC_HW_MAX_FRS;
        dev_info->max_rx_queues =
@@ -1345,7 +1361,7 @@ nicvf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->max_tx_queues =
                        (uint16_t)MAX_SND_QUEUES_PER_QS * (MAX_SQS_PER_VF + 1);
        dev_info->max_mac_addrs = 1;
-       dev_info->max_vfs = dev->pci_dev->max_vfs;
+       dev_info->max_vfs = pci_dev->max_vfs;
 
        dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
        dev_info->tx_offload_capa =
@@ -1407,7 +1423,7 @@ static int
 nicvf_vf_start(struct rte_eth_dev *dev, struct nicvf *nic, uint32_t rbdrsz)
 {
        int ret;
-       uint16_t qidx;
+       uint16_t qidx, data_off;
        uint32_t total_rxq_desc, nb_rbdr_desc, exp_buffs;
        uint64_t mbuf_phys_off = 0;
        struct nicvf_rxq *rxq;
@@ -1448,10 +1464,18 @@ nicvf_vf_start(struct rte_eth_dev *dev, struct nicvf *nic, uint32_t rbdrsz)
                                     nic->vf_id, qidx, rxq->pool->name);
                        return -ENOMEM;
                }
-               rxq->mbuf_phys_off -= nicvf_mbuff_meta_length(mbuf);
-               rxq->mbuf_phys_off -= RTE_PKTMBUF_HEADROOM;
+               data_off = nicvf_mbuff_meta_length(mbuf);
+               data_off += RTE_PKTMBUF_HEADROOM;
                rte_pktmbuf_free(mbuf);
 
+               if (data_off % RTE_CACHE_LINE_SIZE) {
+                       PMD_INIT_LOG(ERR, "%s: unaligned data_off=%d delta=%d",
+                               rxq->pool->name, data_off,
+                               data_off % RTE_CACHE_LINE_SIZE);
+                       return -EINVAL;
+               }
+               rxq->mbuf_phys_off -= data_off;
+
                if (mbuf_phys_off == 0)
                        mbuf_phys_off = rxq->mbuf_phys_off;
                if (mbuf_phys_off != rxq->mbuf_phys_off) {
@@ -1527,6 +1551,16 @@ nicvf_vf_start(struct rte_eth_dev *dev, struct nicvf *nic, uint32_t rbdrsz)
        /* Configure VLAN Strip */
        nicvf_vlan_hw_strip(nic, dev->data->dev_conf.rxmode.hw_vlan_strip);
 
+       /* Based on the packet type(IPv4 or IPv6), the nicvf HW aligns L3 data
+        * to the 64bit memory address.
+        * The alignment creates a hole in mbuf(between the end of headroom and
+        * packet data start). The new revision of the HW provides an option to
+        * disable the L3 alignment feature and make mbuf layout looks
+        * more like other NICs. For better application compatibility, disabling
+        * l3 alignment feature on the hardware revisions it supports
+        */
+       nicvf_apad_config(nic, false);
+
        /* Get queue ranges for this VF */
        nicvf_tx_range(dev, nic, &tx_start, &tx_end);
 
@@ -1965,7 +1999,7 @@ nicvf_eth_dev_init(struct rte_eth_dev *eth_dev)
                }
        }
 
-       pci_dev = eth_dev->pci_dev;
+       pci_dev = RTE_DEV_TO_PCI(eth_dev->device);
        rte_eth_copy_pci_info(eth_dev, pci_dev);
 
        nic->device_id = pci_dev->id.device_id;
@@ -2086,21 +2120,37 @@ static const struct rte_pci_id pci_id_nicvf_map[] = {
                .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
                .subsystem_device_id = PCI_SUB_DEVICE_ID_CN81XX_NICVF,
        },
+       {
+               .class_id = RTE_CLASS_ANY_ID,
+               .vendor_id = PCI_VENDOR_ID_CAVIUM,
+               .device_id = PCI_DEVICE_ID_THUNDERX_NICVF,
+               .subsystem_vendor_id = PCI_VENDOR_ID_CAVIUM,
+               .subsystem_device_id = PCI_SUB_DEVICE_ID_CN83XX_NICVF,
+       },
        {
                .vendor_id = 0,
        },
 };
 
-static struct eth_driver rte_nicvf_pmd = {
-       .pci_drv = {
-               .id_table = pci_id_nicvf_map,
-               .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
-               .probe = rte_eth_dev_pci_probe,
-               .remove = rte_eth_dev_pci_remove,
-       },
-       .eth_dev_init = nicvf_eth_dev_init,
-       .dev_private_size = sizeof(struct nicvf),
+static int nicvf_eth_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+       struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct nicvf),
+               nicvf_eth_dev_init);
+}
+
+static int nicvf_eth_pci_remove(struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
+}
+
+static struct rte_pci_driver rte_nicvf_pmd = {
+       .id_table = pci_id_nicvf_map,
+       .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_INTR_LSC,
+       .probe = nicvf_eth_pci_probe,
+       .remove = nicvf_eth_pci_remove,
 };
 
-RTE_PMD_REGISTER_PCI(net_thunderx, rte_nicvf_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI(net_thunderx, rte_nicvf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_thunderx, pci_id_nicvf_map);
+RTE_PMD_REGISTER_KMOD_DEP(net_thunderx, "* igb_uio | uio_pci_generic | vfio");