From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from wes1-so1.wedos.net (wes1-so1.wedos.net [46.28.106.15]) by dpdk.org (Postfix) with ESMTP id 1356F8E59 for ; Mon, 18 Jan 2016 17:05:14 +0100 (CET) Received: from pcviktorin.fit.vutbr.cz (pcviktorin.fit.vutbr.cz [147.229.13.147]) by wes1-so1.wedos.net (Postfix) with ESMTPSA id 3pkdHY5s0Pz5Gd; Mon, 18 Jan 2016 17:05:13 +0100 (CET) From: Jan Viktorin To: dev@dpdk.org Date: Mon, 18 Jan 2016 17:03:07 +0100 Message-Id: <1453132987-20564-7-git-send-email-viktorin@rehivetech.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1453132987-20564-1-git-send-email-viktorin@rehivetech.com> References: <1453132987-20564-1-git-send-email-viktorin@rehivetech.com> Cc: Jan Viktorin Subject: [dpdk-dev] [RFC 6/6] eal: move driver pointer from rte_pci_device to rte_bus_device X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Jan 2016 16:05:14 -0000 We define to_pci_driver helper macro here. Suggested-by: David Marchand Signed-off-by: Jan Viktorin --- app/test/virtual_pmd.c | 2 +- drivers/net/virtio/virtio_ethdev.c | 25 +++++++++++++++++-------- lib/librte_cryptodev/rte_cryptodev.c | 3 ++- lib/librte_eal/common/eal_common_pci.c | 4 ++-- lib/librte_eal/common/include/rte_dev.h | 1 + lib/librte_eal/common/include/rte_pci.h | 4 +++- lib/librte_ether/rte_ethdev.c | 10 ++++++---- 7 files changed, 32 insertions(+), 17 deletions(-) diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c index 0fe957f..c88972d 100644 --- a/app/test/virtual_pmd.c +++ b/app/test/virtual_pmd.c @@ -626,7 +626,7 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr, eth_dev->dev_ops = &dev_private->dev_ops; eth_dev->pci_dev = pci_dev; - eth_dev->pci_dev->driver = ð_drv->pci_drv; + eth_dev->pci_dev->dev.driver = ð_drv->pci_drv.drv; eth_dev->rx_pkt_burst = virtual_ethdev_rx_burst_success; eth_dev->tx_pkt_burst = virtual_ethdev_tx_burst_success; diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 1ee9f85..22a7849 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -487,11 +487,12 @@ virtio_dev_close(struct rte_eth_dev *dev) { struct virtio_hw *hw = dev->data->dev_private; struct rte_pci_device *pci_dev = dev->pci_dev; + struct rte_pci_driver *pci_drv = to_pci_driver(pci_dev->dev.driver); PMD_INIT_LOG(DEBUG, "virtio_dev_close"); /* reset the NIC */ - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) + if (pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC) vtpci_irq_config(hw, VIRTIO_MSI_NO_VECTOR); vtpci_reset(hw); hw->started = 0; @@ -1080,6 +1081,7 @@ virtio_has_msix(const struct rte_pci_addr *loc) /* Extract I/O port numbers from sysfs */ static int virtio_resource_init_by_uio(struct rte_pci_device *pci_dev) { + struct rte_pci_driver *pci_drv = to_pci_driver(pci_dev->dev.driver); char dirname[PATH_MAX]; char filename[PATH_MAX]; unsigned long start, size; @@ -1122,7 +1124,7 @@ static int virtio_resource_init_by_uio(struct rte_pci_device *pci_dev) } pci_dev->dev.intr_handle.type = RTE_INTR_HANDLE_UIO; - pci_dev->driver->drv_flags |= RTE_PCI_DRV_INTR_LSC; + pci_drv->drv_flags |= RTE_PCI_DRV_INTR_LSC; return 0; } @@ -1130,6 +1132,7 @@ static int virtio_resource_init_by_uio(struct rte_pci_device *pci_dev) /* Extract port I/O numbers from proc/ioports */ static int virtio_resource_init_by_ioports(struct rte_pci_device *pci_dev) { + struct rte_pci_driver *pci_drv = to_pci_driver(pci_dev->dev.driver); uint16_t start, end; int size; FILE *fp; @@ -1188,7 +1191,7 @@ static int virtio_resource_init_by_ioports(struct rte_pci_device *pci_dev) start, size); /* can't support lsc interrupt without uio */ - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC; + pci_drv->drv_flags &= ~RTE_PCI_DRV_INTR_LSC; return 0; } @@ -1265,6 +1268,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) struct virtio_net_config *config; struct virtio_net_config local_config; struct rte_pci_device *pci_dev; + struct rte_pci_driver *pci_drv; RTE_BUILD_BUG_ON(RTE_PKTMBUF_HEADROOM < sizeof(struct virtio_net_hdr)); @@ -1286,6 +1290,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) } pci_dev = eth_dev->pci_dev; + pci_drv = to_pci_driver(pci_dev->dev.driver); if (virtio_resource_init(pci_dev) < 0) return -1; @@ -1305,7 +1310,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) /* If host does not support status then disable LSC */ if (!vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) - pci_dev->driver->drv_flags &= ~RTE_PCI_DRV_INTR_LSC; + pci_drv->drv_flags &= ~RTE_PCI_DRV_INTR_LSC; rte_eth_copy_pci_info(eth_dev, pci_dev); @@ -1388,7 +1393,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) pci_dev->id.device_id); /* Setup interrupt callback */ - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) + if (pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC) rte_intr_callback_register(&pci_dev->dev.intr_handle, virtio_interrupt_handler, eth_dev); @@ -1401,6 +1406,7 @@ static int eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) { struct rte_pci_device *pci_dev; + struct rte_pci_driver *pci_drv; struct virtio_hw *hw = eth_dev->data->dev_private; PMD_INIT_FUNC_TRACE(); @@ -1413,6 +1419,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) virtio_dev_close(eth_dev); } pci_dev = eth_dev->pci_dev; + pci_drv = to_pci_driver(pci_dev->dev.driver); eth_dev->dev_ops = NULL; eth_dev->tx_pkt_burst = NULL; @@ -1424,7 +1431,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) eth_dev->data->mac_addrs = NULL; /* reset interrupt callback */ - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) + if (pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC) rte_intr_callback_unregister(&pci_dev->dev.intr_handle, virtio_interrupt_handler, eth_dev); @@ -1474,6 +1481,7 @@ virtio_dev_configure(struct rte_eth_dev *dev) const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode; struct virtio_hw *hw = dev->data->dev_private; struct rte_pci_device *pci_dev = dev->pci_dev; + struct rte_pci_driver *pci_drv = to_pci_driver(pci_dev->dev.driver); PMD_INIT_LOG(DEBUG, "configure"); @@ -1491,7 +1499,7 @@ virtio_dev_configure(struct rte_eth_dev *dev) return -ENOTSUP; } - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) + if (pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC) if (vtpci_irq_config(hw, 0) == VIRTIO_MSI_NO_VECTOR) { PMD_DRV_LOG(ERR, "failed to set config vector"); return -EBUSY; @@ -1507,10 +1515,11 @@ virtio_dev_start(struct rte_eth_dev *dev) uint16_t nb_queues, i; struct virtio_hw *hw = dev->data->dev_private; struct rte_pci_device *pci_dev = dev->pci_dev; + struct rte_pci_driver *pci_drv = to_pci_driver(pci_dev->dev.driver); /* check if lsc interrupt feature is enabled */ if (dev->data->dev_conf.intr_conf.lsc) { - if (!(pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC)) { + if (!(pci_drv->drv_flags & RTE_PCI_DRV_INTR_LSC)) { PMD_DRV_LOG(ERR, "link status not supported by host"); return -ENOTSUP; } diff --git a/lib/librte_cryptodev/rte_cryptodev.c b/lib/librte_cryptodev/rte_cryptodev.c index f09f67e..f1c9a4e 100644 --- a/lib/librte_cryptodev/rte_cryptodev.c +++ b/lib/librte_cryptodev/rte_cryptodev.c @@ -394,7 +394,8 @@ rte_cryptodev_uninit(struct rte_pci_device *pci_dev) if (cryptodev == NULL) return -ENODEV; - cryptodrv = (const struct rte_cryptodev_driver *)pci_dev->driver; + cryptodrv = (const struct rte_cryptodev_driver *) + to_pci_driver(pci_dev->dev.driver); if (cryptodrv == NULL) return -ENODEV; diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c index 4ac180d..8341a92 100644 --- a/lib/librte_eal/common/eal_common_pci.c +++ b/lib/librte_eal/common/eal_common_pci.c @@ -199,7 +199,7 @@ rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *d } /* reference driver structure */ - dev->driver = dr; + dev->dev.driver = &dr->drv; /* call the driver devinit() function */ return dr->devinit(dr, dev); @@ -250,7 +250,7 @@ rte_eal_pci_detach_dev(struct rte_pci_driver *dr, return -1; /* negative value is an error */ /* clear driver structure */ - dev->driver = NULL; + dev->dev.driver = NULL; if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) /* unmap resources for devices that use igb_uio */ diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index a481988..29655da 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -160,6 +160,7 @@ struct rte_devargs; struct rte_bus_device { const char *name; + struct rte_bus_driver *driver; struct rte_devargs *devargs; struct rte_intr_handle intr_handle; int numa_node; diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index e2c3073..f2360a7 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -161,7 +161,6 @@ struct rte_pci_device { struct rte_pci_addr addr; /**< PCI location. */ struct rte_pci_id id; /**< PCI ID. */ struct rte_pci_resource mem_resource[PCI_MAX_RESOURCE]; /**< PCI Memory Resource */ - struct rte_pci_driver *driver; /**< Associated driver */ uint16_t max_vfs; /**< sriov enable if not zero */ enum rte_kernel_driver kdrv; /**< Kernel driver passthrough */ struct rte_bus_device dev; /**< Generic device */ @@ -211,6 +210,9 @@ struct rte_pci_driver { struct rte_bus_driver drv; /**< Generic driver */ }; +#define to_pci_driver(busdrv) \ + container_of((busdrv), struct rte_pci_driver, drv) + /** Device needs PCI BAR mapping (done with either IGB_UIO or VFIO) */ #define RTE_PCI_DRV_NEED_MAPPING 0x0001 /** Device driver must be registered several times until failure - deprecated */ diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index b93fba8..17db470 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -315,7 +315,8 @@ rte_eth_dev_uninit(struct rte_pci_device *pci_dev) if (eth_dev == NULL) return -ENODEV; - eth_drv = (const struct eth_driver *)pci_dev->driver; + eth_drv = (const struct eth_driver *) + to_pci_driver(pci_dev->dev.driver); /* Invoke PMD device uninit function */ if (*eth_drv->eth_dev_uninit) { @@ -3223,6 +3224,7 @@ rte_eth_dev_get_dcb_info(uint8_t port_id, void rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_dev) { + struct rte_pci_driver *drv = to_pci_driver(pci_dev->dev.driver); if ((eth_dev == NULL) || (pci_dev == NULL)) { RTE_PMD_DEBUG_TRACE("NULL pointer eth_dev=%p pci_dev=%p\n", eth_dev, pci_dev); @@ -3230,12 +3232,12 @@ rte_eth_copy_pci_info(struct rte_eth_dev *eth_dev, struct rte_pci_device *pci_de } eth_dev->data->dev_flags = 0; - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_INTR_LSC) + if (drv->drv_flags & RTE_PCI_DRV_INTR_LSC) eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC; - if (pci_dev->driver->drv_flags & RTE_PCI_DRV_DETACHABLE) + if (drv->drv_flags & RTE_PCI_DRV_DETACHABLE) eth_dev->data->dev_flags |= RTE_ETH_DEV_DETACHABLE; eth_dev->data->kdrv = pci_dev->kdrv; eth_dev->data->numa_node = pci_dev->dev.numa_node; - eth_dev->data->drv_name = pci_dev->driver->name; + eth_dev->data->drv_name = pci_dev->dev.driver->name; } -- 2.7.0