drivers/net: add generic ethdev macro to get PCI device
[dpdk.git] / drivers / net / liquidio / lio_ethdev.c
index df91659..6fce88f 100644 (file)
@@ -32,6 +32,7 @@
  */
 
 #include <rte_ethdev.h>
+#include <rte_ethdev_pci.h>
 #include <rte_cycles.h>
 #include <rte_malloc.h>
 #include <rte_alarm.h>
@@ -936,6 +937,9 @@ lio_dev_link_update(struct rte_eth_dev *eth_dev,
        case LIO_LINK_SPEED_10000:
                link.link_speed = ETH_SPEED_NUM_10G;
                break;
+       case LIO_LINK_SPEED_25000:
+               link.link_speed = ETH_SPEED_NUM_25G;
+               break;
        default:
                link.link_speed = ETH_SPEED_NUM_NONE;
                link.link_duplex = ETH_LINK_HALF_DUPLEX;
@@ -1155,14 +1159,13 @@ void
 lio_dev_rx_queue_release(void *rxq)
 {
        struct lio_droq *droq = rxq;
-       struct lio_device *lio_dev = droq->lio_dev;
        int oq_no;
 
-       /* Run time queue deletion not supported */
-       if (lio_dev->port_configured)
-               return;
+       if (droq) {
+               /* Run time queue deletion not supported */
+               if (droq->lio_dev->port_configured)
+                       return;
 
-       if (droq != NULL) {
                oq_no = droq->q_no;
                lio_delete_droq_queue(droq->lio_dev, oq_no);
        }
@@ -1250,14 +1253,14 @@ void
 lio_dev_tx_queue_release(void *txq)
 {
        struct lio_instr_queue *tq = txq;
-       struct lio_device *lio_dev = tq->lio_dev;
        uint32_t fw_mapped_iq_no;
 
-       /* Run time queue deletion not supported */
-       if (lio_dev->port_configured)
-               return;
 
-       if (tq != NULL) {
+       if (tq) {
+               /* Run time queue deletion not supported */
+               if (tq->lio_dev->port_configured)
+                       return;
+
                /* Free sg_list */
                lio_delete_sglist(tq);
 
@@ -1955,7 +1958,7 @@ lio_eth_dev_uninit(struct rte_eth_dev *eth_dev)
 static int
 lio_eth_dev_init(struct rte_eth_dev *eth_dev)
 {
-       struct rte_pci_device *pdev = RTE_DEV_TO_PCI(eth_dev->device);
+       struct rte_pci_device *pdev = RTE_ETH_DEV_TO_PCI(eth_dev);
        struct lio_device *lio_dev = LIO_DEV(eth_dev);
 
        PMD_INIT_FUNC_TRACE();
@@ -2011,24 +2014,45 @@ lio_eth_dev_init(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
+static int
+lio_eth_dev_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
+                     struct rte_pci_device *pci_dev)
+{
+       struct rte_eth_dev *eth_dev;
+       int ret;
+
+       eth_dev = rte_eth_dev_pci_allocate(pci_dev,
+                                          sizeof(struct lio_device));
+       if (eth_dev == NULL)
+               return -ENOMEM;
+
+       ret = lio_eth_dev_init(eth_dev);
+       if (ret)
+               rte_eth_dev_pci_release(eth_dev);
+
+       return ret;
+}
+
+static int
+lio_eth_dev_pci_remove(struct rte_pci_device *pci_dev)
+{
+       return rte_eth_dev_pci_generic_remove(pci_dev,
+                                             lio_eth_dev_uninit);
+}
+
 /* Set of PCI devices this driver supports */
 static const struct rte_pci_id pci_id_liovf_map[] = {
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, LIO_CN23XX_VF_VID) },
        { .vendor_id = 0, /* sentinel */ }
 };
 
-static struct eth_driver rte_liovf_pmd = {
-       .pci_drv = {
-               .id_table       = pci_id_liovf_map,
-               .drv_flags      = RTE_PCI_DRV_NEED_MAPPING,
-               .probe          = rte_eth_dev_pci_probe,
-               .remove         = rte_eth_dev_pci_remove,
-       },
-       .eth_dev_init           = lio_eth_dev_init,
-       .eth_dev_uninit         = lio_eth_dev_uninit,
-       .dev_private_size       = sizeof(struct lio_device),
+static struct rte_pci_driver rte_liovf_pmd = {
+       .id_table       = pci_id_liovf_map,
+       .drv_flags      = RTE_PCI_DRV_NEED_MAPPING,
+       .probe          = lio_eth_dev_pci_probe,
+       .remove         = lio_eth_dev_pci_remove,
 };
 
-RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd.pci_drv);
+RTE_PMD_REGISTER_PCI(net_liovf, rte_liovf_pmd);
 RTE_PMD_REGISTER_PCI_TABLE(net_liovf, pci_id_liovf_map);
-RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio");
+RTE_PMD_REGISTER_KMOD_DEP(net_liovf, "* igb_uio | vfio-pci");