From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-it0-f52.google.com (mail-it0-f52.google.com [209.85.214.52]) by dpdk.org (Postfix) with ESMTP id DF3A0FABC for ; Mon, 19 Dec 2016 23:00:03 +0100 (CET) Received: by mail-it0-f52.google.com with SMTP id c20so69153676itb.0 for ; Mon, 19 Dec 2016 14:00:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VOfHgnza8vGjCo/v2N1SZVNi+J9BD1KoPVd2XnscwXA=; b=hRZ7L5PYkG3Ex25peCeOtXnSpsbn6IIfDECWs5ByA33rF4uPu9swdMwQoIIkXQVWPz fgcR1aFgkKOKAXa0q1A48Zy5mUWvM69oTy0KjTGbVmMi5w4FKF5oxlxif6tzeWaiLZRe WplZgNEPxVqsNy4srFIBTKsji55+MLWixA5cRs5CDEOFtvAHRPAHunYuwPh4/SzQVnkX T5O7bTS7hbG5215tU7Z6BLnNW+L6jVBK9NQ4H2dD0AHhm/9k6f8JG7FJOmzKbb2AWqpo LQAeGMLZLnfK+cRE7QcDB87e6FUW1UGzRKzEQ8NEWuUHVoNFoTDNrExIXt1Vd+WrzJyB VNmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VOfHgnza8vGjCo/v2N1SZVNi+J9BD1KoPVd2XnscwXA=; b=snsaPYvF4cx+PUlRdS5mjLOORn/Fh5pnSp4WzuNuSFtqEBUONA7NV46wqS5OqFA5i4 bHX3BpVhKEYqoPG1906jIj3hV+i+fXIHVO6emibqfIqbgJcmQFV2/LPrzPWhYSSyiRPI R+tllkJy91epXrVjkWv8cIB2oCJP/+X4n/KnFYmE77EjeH5rNjyf2PegioGWgU+dAlz4 J+KmgMVT4JjIjIknm1TWNYWr+0ymLMvgVAWqm16bZeIjuZTXn8WkjcZ2EXKCsF4KCeOf rKEbYVP0V7psIB+RAF9j+V4zX9pjAWr6JyGO/GKHPWpC2LJFHd5lQwwQTSjeo+c5P5GW x7KQ== X-Gm-Message-State: AKaTC00mtJvP3duXnn/FHhqv2NAdK5ZQ8Z89VGpUOAahSUQfPuVI0J739Zutdn8WOJKE7Q== X-Received: by 10.36.84.138 with SMTP id t132mr17351563ita.103.1482184803282; Mon, 19 Dec 2016 14:00:03 -0800 (PST) Received: from xeon-e3.wavecable.com (204-195-18-65.wavecable.com. [204.195.18.65]) by smtp.gmail.com with ESMTPSA id p20sm8270581itc.2.2016.12.19.14.00.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Dec 2016 14:00:02 -0800 (PST) From: Stephen Hemminger X-Google-Original-From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger Date: Mon, 19 Dec 2016 13:59:41 -0800 Message-Id: <20161219215944.17226-11-sthemmin@microsoft.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20161219215944.17226-1-sthemmin@microsoft.com> References: <20161219215944.17226-1-sthemmin@microsoft.com> Subject: [dpdk-dev] [PATCH 10/13] virtio: localize mapping from rte_eth to pci X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Dec 2016 22:00:04 -0000 Use one function to get mapping from rte_eth_dev to pci_device. Safely handle some possible misconfiguration of virtio_user related to link state interrupt. Signed-off-by: Stephen Hemminger --- drivers/net/virtio/virtio_ethdev.c | 90 ++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c index 079fd6c8..4db4568a 100644 --- a/drivers/net/virtio/virtio_ethdev.c +++ b/drivers/net/virtio/virtio_ethdev.c @@ -152,6 +152,20 @@ static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = { #define VIRTIO_NB_TXQ_XSTATS (sizeof(rte_virtio_txq_stat_strings) / \ sizeof(rte_virtio_txq_stat_strings[0])) +static inline struct rte_pci_device * +virtio_dev_to_pci(struct rte_eth_dev *eth_dev) +{ + return eth_dev->pci_dev; +} + +static inline struct rte_intr_handle * +virtio_dev_to_intr_handle(struct rte_eth_dev *eth_dev) +{ + struct rte_pci_device *pci_dev = virtio_dev_to_pci(eth_dev); + + return pci_dev ? &pci_dev->intr_handle : NULL; +} + static int virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl, int *dlen, int pkt_num) @@ -1151,7 +1165,7 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features) * if link state changed. */ static void -virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle, +virtio_interrupt_handler(struct rte_intr_handle *intr_handle, void *param) { struct rte_eth_dev *dev = param; @@ -1162,7 +1176,7 @@ virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle, isr = vtpci_isr(hw); PMD_DRV_LOG(INFO, "interrupt status = %#x", isr); - if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) + if (rte_intr_enable(intr_handle) < 0) PMD_DRV_LOG(ERR, "interrupt enable failed"); if (isr & VIRTIO_PCI_ISR_CONFIG) { @@ -1190,7 +1204,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) struct virtio_hw *hw = eth_dev->data->dev_private; struct virtio_net_config *config; struct virtio_net_config local_config; - struct rte_pci_device *pci_dev = eth_dev->pci_dev; + struct rte_pci_device *pci_dev; int ret; /* Reset the device although not necessary at startup */ @@ -1210,7 +1224,9 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) else eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC; - rte_eth_copy_pci_info(eth_dev, pci_dev); + pci_dev = virtio_dev_to_pci(eth_dev); + if (pci_dev) + rte_eth_copy_pci_info(eth_dev, pci_dev); rx_func_get(eth_dev); @@ -1278,10 +1294,9 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features) return ret; vtpci_reinit_complete(hw); - if (pci_dev) - PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x", - eth_dev->data->port_id, pci_dev->id.vendor_id, - pci_dev->id.device_id); + PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x", + eth_dev->data->port_id, pci_dev->id.vendor_id, + pci_dev->id.device_id); return 0; } @@ -1294,7 +1309,7 @@ int eth_virtio_dev_init(struct rte_eth_dev *eth_dev) { struct virtio_hw *hw = eth_dev->data->dev_private; - struct rte_pci_device *pci_dev; + struct rte_pci_device *pci_dev = virtio_dev_to_pci(eth_dev); uint32_t dev_flags = RTE_ETH_DEV_DETACHABLE; int ret; @@ -1317,8 +1332,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) return -ENOMEM; } - pci_dev = eth_dev->pci_dev; - if (pci_dev) { ret = vtpci_init(pci_dev, hw, &dev_flags); if (ret) @@ -1333,9 +1346,19 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) return ret; /* Setup interrupt callback */ - if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) - rte_intr_callback_register(&pci_dev->intr_handle, - virtio_interrupt_handler, eth_dev); + if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) { + struct rte_intr_handle *intr_handle + = virtio_dev_to_intr_handle(eth_dev); + + if (!intr_handle) { + PMD_INIT_LOG(ERR, + "Link state option not valid without pci"); + return -EINVAL; + } + + rte_intr_callback_register(intr_handle, + virtio_interrupt_handler, eth_dev); + } return 0; } @@ -1343,7 +1366,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev) static int eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) { - struct rte_pci_device *pci_dev; + struct rte_pci_device *pci_dev = virtio_dev_to_pci(eth_dev); PMD_INIT_FUNC_TRACE(); @@ -1352,7 +1375,6 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) virtio_dev_stop(eth_dev); virtio_dev_close(eth_dev); - pci_dev = eth_dev->pci_dev; eth_dev->dev_ops = NULL; eth_dev->tx_pkt_burst = NULL; @@ -1362,11 +1384,18 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev) eth_dev->data->mac_addrs = NULL; /* reset interrupt callback */ - if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) - rte_intr_callback_unregister(&pci_dev->intr_handle, - virtio_interrupt_handler, - eth_dev); - rte_eal_pci_unmap_device(pci_dev); + if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) { + struct rte_intr_handle *intr_handle + = virtio_dev_to_intr_handle(eth_dev); + + if (intr_handle) + rte_intr_callback_unregister(intr_handle, + virtio_interrupt_handler, + eth_dev); + } + + if (pci_dev) + rte_eal_pci_unmap_device(pci_dev); PMD_INIT_LOG(DEBUG, "dev_uninit completed"); @@ -1476,12 +1505,20 @@ virtio_dev_start(struct rte_eth_dev *dev) /* check if lsc interrupt feature is enabled */ if (dev->data->dev_conf.intr_conf.lsc) { + struct rte_intr_handle *intr_handle + = virtio_dev_to_intr_handle(dev); + + if (!intr_handle) { + PMD_DRV_LOG(ERR, "link status not supported by bus"); + return -ENOTSUP; + } + if (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)) { PMD_DRV_LOG(ERR, "link status not supported by host"); return -ENOTSUP; } - if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) { + if (rte_intr_enable(intr_handle) < 0) { PMD_DRV_LOG(ERR, "interrupt enable failed"); return -EIO; } @@ -1573,12 +1610,13 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev) static void virtio_dev_stop(struct rte_eth_dev *dev) { + struct rte_intr_handle *intr_handle = virtio_dev_to_intr_handle(dev); struct rte_eth_link link; PMD_INIT_LOG(DEBUG, "stop"); - if (dev->data->dev_conf.intr_conf.lsc) - rte_intr_disable(&dev->pci_dev->intr_handle); + if (dev->data->dev_conf.intr_conf.lsc && intr_handle) + rte_intr_disable(intr_handle); memset(&link, 0, sizeof(link)); virtio_dev_atomic_write_link_status(dev, &link); @@ -1624,9 +1662,7 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) uint64_t tso_mask; struct virtio_hw *hw = dev->data->dev_private; - if (dev->pci_dev) - dev_info->driver_name = dev->driver->pci_drv.driver.name; - else + if (!dev->pci_dev) dev_info->driver_name = "virtio_user PMD"; dev_info->max_rx_queues = RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES); -- 2.11.0