From patchwork Fri Jan 30 05:42:39 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 2788 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 9A1F35ABE; Fri, 30 Jan 2015 06:45:56 +0100 (CET) Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by dpdk.org (Postfix) with ESMTP id A2F105AC9 for ; Fri, 30 Jan 2015 06:45:04 +0100 (CET) Received: by mail-pa0-f47.google.com with SMTP id lj1so48069523pab.6 for ; Thu, 29 Jan 2015 21:45:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=XaExSQnDMiFRfXeSZO9/EzV7jpI5Ltp0U4oqm19Hks8=; b=DWYPIqyeJbez1dOKmrdDfl+85xapcoSGtNqs4CcjCJdxWywseXB97j1MOdOid3vpzw P8plSEqUQlkikgpQxmZXtxjx3JbhSiz5H9TnblhldnbZPNYSFP6N/W4+clJf6jwLz2cr OWVAx25on6bVqt/Eh2MYzgsYctgFIX9JRSJ1P+aNHQcYteuku6cddj0GBEGcHrIi+M2T /zn/okmcfHSlsWXujt/s25FR26qsuFIuj/Y5cHjH5HQNEYM8AaYG0xQznGZm6g4sc/z3 4ycdBWQJsx3qz4uzOQwpkJlFYDdbMAgeEmdWOC5LQoUZfa321nWGztLOpOjbpwynE1cq a7Fw== X-Gm-Message-State: ALoCoQmT7Q1SS2EHrXuxJrpSC8OhTchqR+R3W+Z6Lc1E1tGD3jDE4gK/1k5nbd2l6jsWmaJE7nNg X-Received: by 10.68.164.194 with SMTP id ys2mr6513463pbb.20.1422596703890; Thu, 29 Jan 2015 21:45:03 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id ki4sm9482266pdb.34.2015.01.29.21.45.02 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 29 Jan 2015 21:45:03 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Fri, 30 Jan 2015 14:42:39 +0900 Message-Id: <1422596563-26310-12-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1422596563-26310-1-git-send-email-mukawa@igel.co.jp> References: <1421664027-17971-9-git-send-email-mukawa@igel.co.jp> <1422596563-26310-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v5 11/13] ethdev: Add one dev_type paramerter to rte_eth_dev_allocate 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This new parameter is needed to keep device type like physical or virtual. Port detaching processes are different between physical and virtual. This paramerter lets detaching function know a device type of the port. v4: - Fix comments of rte_eth_dev_type. Signed-off-by: Tetsuya Mukawa --- app/test/virtual_pmd.c | 2 +- lib/librte_ether/rte_ethdev.c | 14 ++++++++++++-- lib/librte_ether/rte_ethdev.h | 25 ++++++++++++++++++++++++- lib/librte_pmd_af_packet/rte_eth_af_packet.c | 2 +- lib/librte_pmd_bond/rte_eth_bond_api.c | 2 +- lib/librte_pmd_pcap/rte_eth_pcap.c | 2 +- lib/librte_pmd_ring/rte_eth_ring.c | 2 +- lib/librte_pmd_xenvirt/rte_eth_xenvirt.c | 2 +- 8 files changed, 42 insertions(+), 9 deletions(-) diff --git a/app/test/virtual_pmd.c b/app/test/virtual_pmd.c index 9fac95d..8d3a5ff 100644 --- a/app/test/virtual_pmd.c +++ b/app/test/virtual_pmd.c @@ -556,7 +556,7 @@ virtual_ethdev_create(const char *name, struct ether_addr *mac_addr, goto err; /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_PHYSICAL); if (eth_dev == NULL) goto err; diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 2acafc7..0c7fbb1 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -232,7 +232,7 @@ rte_eth_dev_allocate_new_port(void) } struct rte_eth_dev * -rte_eth_dev_allocate(const char *name) +rte_eth_dev_allocate(const char *name, enum rte_eth_dev_type type) { uint8_t port_id; struct rte_eth_dev *eth_dev; @@ -256,6 +256,7 @@ rte_eth_dev_allocate(const char *name) snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name); eth_dev->data->port_id = port_id; eth_dev->attached = DEV_CONNECTED; + eth_dev->dev_type = type; nb_ports++; return eth_dev; } @@ -276,6 +277,7 @@ rte_eth_dev_free(const char *name) } eth_dev->attached = 0; + eth_dev->dev_type = RTE_ETH_DEV_UNKNOWN; nb_ports--; return eth_dev; } @@ -296,7 +298,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "%d:%d.%d", pci_dev->addr.bus, pci_dev->addr.devid, pci_dev->addr.function); - eth_dev = rte_eth_dev_allocate(ethdev_name); + eth_dev = rte_eth_dev_allocate(ethdev_name, RTE_ETH_DEV_PHYSICAL); if (eth_dev == NULL) return -ENOMEM; @@ -428,6 +430,14 @@ rte_eth_dev_count(void) return (nb_ports); } +enum rte_eth_dev_type +rte_eth_dev_get_device_type(uint8_t port_id) +{ + if (rte_eth_dev_validate_port(port_id, NONE_TRACE) == DEV_INVALID) + return -1; + return rte_eth_devices[port_id].dev_type; +} + void rte_eth_dev_save(struct rte_eth_dev *devs) { diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index ebc48b0..83a4000 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1522,6 +1522,17 @@ struct eth_dev_ops { }; /** + * The eth device type + */ +enum rte_eth_dev_type { + RTE_ETH_DEV_UNKNOWN, /**< unknown device type */ + RTE_ETH_DEV_PHYSICAL, + /**< Physical function and Virtual function devices of NIC */ + RTE_ETH_DEV_VIRTUAL, /**< non hardware device */ + RTE_ETH_DEV_MAX /**< max value of this enum */ +}; + +/** * @internal * The generic data structure associated with each ethernet device. * @@ -1540,6 +1551,7 @@ struct rte_eth_dev { struct rte_pci_device *pci_dev; /**< PCI info. supplied by probing */ struct rte_eth_dev_cb_list callbacks; /**< User application callbacks */ uint8_t attached; /**< Flag indicating the port is attached */ + enum rte_eth_dev_type dev_type; /**< Flag indicating the device type */ }; struct rte_eth_dev_sriov { @@ -1617,6 +1629,15 @@ extern uint8_t rte_eth_dev_count(void); /** * Function for internal use by port hotplug functions. + * Get the device type to know whether the device is physical or virtual. + * @param port_id The pointer to the port id + * @return + * - Device type. + */ +extern enum rte_eth_dev_type rte_eth_dev_get_device_type(uint8_t port_id); + +/** + * Function for internal use by port hotplug functions. * Copies current ethdev structures to the specified pointer. * * @param devs The pointer to the ethdev structures @@ -1702,10 +1723,12 @@ extern struct rte_eth_dev *rte_eth_dev_allocated(const char *name); * to that slot for the driver to use. * * @param name Unique identifier name for each Ethernet device + * @param type Device type of this Ethernet device * @return * - Slot in the rte_dev_devices array for a new device; */ -struct rte_eth_dev *rte_eth_dev_allocate(const char *name); +struct rte_eth_dev *rte_eth_dev_allocate(const char *name, + enum rte_eth_dev_type type); /** * Function for internal use by dummy drivers primarily, e.g. ring-based diff --git a/lib/librte_pmd_af_packet/rte_eth_af_packet.c b/lib/librte_pmd_af_packet/rte_eth_af_packet.c index 1ffe1cd..80e9bdf 100644 --- a/lib/librte_pmd_af_packet/rte_eth_af_packet.c +++ b/lib/librte_pmd_af_packet/rte_eth_af_packet.c @@ -649,7 +649,7 @@ rte_pmd_init_internals(const char *name, } /* reserve an ethdev entry */ - *eth_dev = rte_eth_dev_allocate(name); + *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); if (*eth_dev == NULL) goto error; diff --git a/lib/librte_pmd_bond/rte_eth_bond_api.c b/lib/librte_pmd_bond/rte_eth_bond_api.c index 4ab3267..7a6a5f7 100644 --- a/lib/librte_pmd_bond/rte_eth_bond_api.c +++ b/lib/librte_pmd_bond/rte_eth_bond_api.c @@ -235,7 +235,7 @@ rte_eth_bond_create(const char *name, uint8_t mode, uint8_t socket_id) } /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); if (eth_dev == NULL) { RTE_BOND_LOG(ERR, "Unable to allocate rte_eth_dev"); goto err; diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_eth_pcap.c index d299288..af7fae8 100644 --- a/lib/librte_pmd_pcap/rte_eth_pcap.c +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c @@ -709,7 +709,7 @@ rte_pmd_init_internals(const char *name, const unsigned nb_rx_queues, goto error; /* reserve an ethdev entry */ - *eth_dev = rte_eth_dev_allocate(name); + *eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); if (*eth_dev == NULL) goto error; diff --git a/lib/librte_pmd_ring/rte_eth_ring.c b/lib/librte_pmd_ring/rte_eth_ring.c index f685f08..5876057 100644 --- a/lib/librte_pmd_ring/rte_eth_ring.c +++ b/lib/librte_pmd_ring/rte_eth_ring.c @@ -255,7 +255,7 @@ rte_eth_from_rings(const char *name, struct rte_ring *const rx_queues[], goto error; /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); if (eth_dev == NULL) goto error; diff --git a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c index 04e30c9..bc403d6 100644 --- a/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c +++ b/lib/librte_pmd_xenvirt/rte_eth_xenvirt.c @@ -648,7 +648,7 @@ eth_dev_xenvirt_create(const char *name, const char *params, goto err; /* reserve an ethdev entry */ - eth_dev = rte_eth_dev_allocate(name); + eth_dev = rte_eth_dev_allocate(name, RTE_ETH_DEV_VIRTUAL); if (eth_dev == NULL) goto err;