From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by dpdk.org (Postfix) with ESMTP id 31198B422 for ; Mon, 23 Feb 2015 06:09:57 +0100 (CET) Received: by padhz1 with SMTP id hz1so24606547pad.9 for ; Sun, 22 Feb 2015 21:09:56 -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=XTBwxrKZWUP6DdLqBDCNXVYVbRwUD1OS1CJgchb0sQk=; b=bB0aFrU8/7UBCYG95GzNbmaB60d9ZDZ11kLfLjSGjA32ZJuYB6iCI8C3MKBqvSh/Jj pyfUXVk0b92GvkzGYuP92sqV+RkvxdnKKAGcxKbpi4c1fFnd3z4X7pc2Q4p73joEEqvT 1HRhiKYwUsHKPf8iBjhGeeEZCjvc6WCNHjbMpsnmFEHLZVLc+pNEudx+D9rgoNmicS0B lbKj9xot5XilzviBnqpw2FUMUF/mKy86PwwHdSwykuX9jS6mjiUDwJndgEohYYZbUjLh +dvjzfFYx6SZUR18TZ4bH375U9UP/sIYxrpMuOLIS4e0VWIIR58b7jNETui37nGTKGcb Y4XQ== X-Gm-Message-State: ALoCoQm+xcnx8ErR2WND2NV7DoJsS7tvD+NeKnjA+HD0ihOLzr5TSXn2QLQM1hHAOsVbx8A2iLjR X-Received: by 10.66.141.71 with SMTP id rm7mr16019396pab.114.1424668196606; Sun, 22 Feb 2015 21:09:56 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id dc4sm12978066pbb.55.2015.02.22.21.09.54 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 22 Feb 2015 21:09:55 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Mon, 23 Feb 2015 14:09:20 +0900 Message-Id: <1424668171-8695-5-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424668171-8695-1-git-send-email-mukawa@igel.co.jp> References: <1424414390-18509-6-git-send-email-mukawa@igel.co.jp> <1424668171-8695-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v11 04/13] eal/pci, ethdev: Remove assumption that port will not be detached 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, 23 Feb 2015 05:09:57 -0000 To remove assumption, do like followings. This patch adds "RTE_PCI_DRV_DETACHABLE" to drv_flags of rte_pci_driver structure. The flags indicate the driver can detach devices at runtime. Also, remove assumption that port will not be detached. To remove the assumption. - Add 'attached' member to rte_eth_dev structure. This member is used for indicating the port is attached, or not. DEV_ATTACHED indicates a port is attached. DEV_DETACHED indicates a port is detached. - Add rte_eth_dev_allocate_new_port(). This function is used for allocating new port. v9: - DEV_INVALID/VALID are removed. - DEV_DISCONNECTED is replaced by DEV_DETACHED. - DEV_CONNECTED is replaced by DEV_ATTACHED. - rte_eth_dev_allocate_new_port() is renamed to rte_eth_dev_find_free_port(). - rte_eth_dev_validate_port() is renamed to rte_eth_dev_is_valid_port(). - rte_eth_dev_is_valid_port() is changed not to handle log toggle. - Fix commit log to describe DEV_ATACHED and DEV_DETACHED. (Thanks to Thomas Monjalon) v8: - NONE_TRACE is changed to NO_TRACE. (Thanks to Iremonger, Bernard) v5: - Change parameters of rte_eth_dev_validate_port() to cleanup code. v4: - Use braces with 'for' loop. - Fix indent of 'if' statement. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/include/rte_pci.h | 2 + lib/librte_ether/rte_ethdev.c | 248 ++++++++++++++++++++------------ lib/librte_ether/rte_ethdev.h | 5 + 3 files changed, 164 insertions(+), 91 deletions(-) diff --git a/lib/librte_eal/common/include/rte_pci.h b/lib/librte_eal/common/include/rte_pci.h index 5e0ba00..ffd13d9 100644 --- a/lib/librte_eal/common/include/rte_pci.h +++ b/lib/librte_eal/common/include/rte_pci.h @@ -210,6 +210,8 @@ struct rte_pci_driver { #define RTE_PCI_DRV_FORCE_UNBIND 0x0004 /** Device driver supports link state interrupt */ #define RTE_PCI_DRV_INTR_LSC 0x0008 +/** Device driver supports detaching capability */ +#define RTE_PCI_DRV_DETACHABLE 0x0010 /**< Internal use only - Macro used by pci addr parsing functions **/ #define GET_PCIADDR_FIELD(in, fd, lim, dlm) \ diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index 27bbb0b..0e1e5c9 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -175,6 +175,11 @@ enum { STAT_QMAP_RX }; +enum { + DEV_DETACHED = 0, + DEV_ATTACHED +}; + static inline void rte_eth_dev_data_alloc(void) { @@ -201,19 +206,34 @@ rte_eth_dev_allocated(const char *name) { unsigned i; - for (i = 0; i < nb_ports; i++) { - if (strcmp(rte_eth_devices[i].data->name, name) == 0) + for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + if ((rte_eth_devices[i].attached == DEV_ATTACHED) && + strcmp(rte_eth_devices[i].data->name, name) == 0) return &rte_eth_devices[i]; } return NULL; } +static uint8_t +rte_eth_dev_find_free_port(void) +{ + unsigned i; + + for (i = 0; i < RTE_MAX_ETHPORTS; i++) { + if (rte_eth_devices[i].attached == DEV_DETACHED) + return i; + } + return RTE_MAX_ETHPORTS; +} + struct rte_eth_dev * rte_eth_dev_allocate(const char *name) { + uint8_t port_id; struct rte_eth_dev *eth_dev; - if (nb_ports == RTE_MAX_ETHPORTS) { + port_id = rte_eth_dev_find_free_port(); + if (port_id == RTE_MAX_ETHPORTS) { PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n"); return NULL; } @@ -226,10 +246,12 @@ rte_eth_dev_allocate(const char *name) return NULL; } - eth_dev = &rte_eth_devices[nb_ports]; - eth_dev->data = &rte_eth_dev_data[nb_ports]; + eth_dev = &rte_eth_devices[port_id]; + eth_dev->data = &rte_eth_dev_data[port_id]; snprintf(eth_dev->data->name, sizeof(eth_dev->data->name), "%s", name); - eth_dev->data->port_id = nb_ports++; + eth_dev->data->port_id = port_id; + eth_dev->attached = DEV_ATTACHED; + nb_ports++; return eth_dev; } @@ -283,6 +305,7 @@ rte_eth_dev_init(struct rte_pci_driver *pci_drv, (unsigned) pci_dev->id.device_id); if (rte_eal_process_type() == RTE_PROC_PRIMARY) rte_free(eth_dev->data->dev_private); + eth_dev->attached = DEV_DETACHED; nb_ports--; return diag; } @@ -308,10 +331,20 @@ rte_eth_driver_register(struct eth_driver *eth_drv) rte_eal_pci_register(ð_drv->pci_drv); } +static int +rte_eth_dev_is_valid_port(uint8_t port_id) +{ + if (port_id >= RTE_MAX_ETHPORTS || + rte_eth_devices[port_id].attached != DEV_ATTACHED) + return 0; + else + return 1; +} + int rte_eth_dev_socket_id(uint8_t port_id) { - if (port_id >= nb_ports) + if (!rte_eth_dev_is_valid_port(port_id)) return -1; return rte_eth_devices[port_id].pci_dev->numa_node; } @@ -369,7 +402,7 @@ rte_eth_dev_rx_queue_start(uint8_t port_id, uint16_t rx_queue_id) * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -EINVAL; } @@ -395,7 +428,7 @@ rte_eth_dev_rx_queue_stop(uint8_t port_id, uint16_t rx_queue_id) * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -EINVAL; } @@ -421,7 +454,7 @@ rte_eth_dev_tx_queue_start(uint8_t port_id, uint16_t tx_queue_id) * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -EINVAL; } @@ -447,7 +480,7 @@ rte_eth_dev_tx_queue_stop(uint8_t port_id, uint16_t tx_queue_id) * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -EINVAL; } @@ -703,10 +736,11 @@ rte_eth_dev_configure(uint8_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports || port_id >= RTE_MAX_ETHPORTS) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-EINVAL); } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); @@ -888,10 +922,11 @@ rte_eth_dev_start(uint8_t port_id) * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { - PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id); + if (!rte_eth_dev_is_valid_port(port_id)) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-EINVAL); } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP); @@ -927,10 +962,11 @@ rte_eth_dev_stop(uint8_t port_id) * in a multi-process setup*/ PROC_PRIMARY_OR_RET(); - if (port_id >= nb_ports) { - PMD_DEBUG_TRACE("Invalid port_id=%" PRIu8 "\n", port_id); + if (!rte_eth_dev_is_valid_port(port_id)) { + PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_RET(*dev->dev_ops->dev_stop); @@ -955,10 +991,11 @@ rte_eth_dev_set_link_up(uint8_t port_id) * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -EINVAL; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP); @@ -974,10 +1011,11 @@ rte_eth_dev_set_link_down(uint8_t port_id) * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -EINVAL; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP); @@ -993,7 +1031,7 @@ rte_eth_dev_close(uint8_t port_id) * in a multi-process setup*/ PROC_PRIMARY_OR_RET(); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } @@ -1021,10 +1059,11 @@ rte_eth_rx_queue_setup(uint8_t port_id, uint16_t rx_queue_id, * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-EINVAL); } + dev = &rte_eth_devices[port_id]; if (rx_queue_id >= dev->data->nb_rx_queues) { PMD_DEBUG_TRACE("Invalid RX queue_id=%d\n", rx_queue_id); @@ -1094,10 +1133,11 @@ rte_eth_tx_queue_setup(uint8_t port_id, uint16_t tx_queue_id, * in a multi-process setup*/ PROC_PRIMARY_OR_ERR_RET(-E_RTE_SECONDARY); - if (port_id >= RTE_MAX_ETHPORTS || port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-EINVAL); } + dev = &rte_eth_devices[port_id]; if (tx_queue_id >= dev->data->nb_tx_queues) { PMD_DEBUG_TRACE("Invalid TX queue_id=%d\n", tx_queue_id); @@ -1127,10 +1167,11 @@ rte_eth_promiscuous_enable(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_enable); @@ -1143,10 +1184,11 @@ rte_eth_promiscuous_disable(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_RET(*dev->dev_ops->promiscuous_disable); @@ -1159,7 +1201,7 @@ rte_eth_promiscuous_get(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -1; } @@ -1173,10 +1215,11 @@ rte_eth_allmulticast_enable(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable); @@ -1189,10 +1232,11 @@ rte_eth_allmulticast_disable(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable); @@ -1205,7 +1249,7 @@ rte_eth_allmulticast_get(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -1; } @@ -1233,10 +1277,11 @@ rte_eth_link_get(uint8_t port_id, struct rte_eth_link *eth_link) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; if (dev->data->dev_conf.intr_conf.lsc != 0) @@ -1253,10 +1298,11 @@ rte_eth_link_get_nowait(uint8_t port_id, struct rte_eth_link *eth_link) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; if (dev->data->dev_conf.intr_conf.lsc != 0) @@ -1273,10 +1319,11 @@ rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + dev = &rte_eth_devices[port_id]; memset(stats, 0, sizeof(*stats)); @@ -1291,10 +1338,11 @@ rte_eth_stats_reset(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_RET(*dev->dev_ops->stats_reset); @@ -1312,10 +1360,11 @@ rte_eth_xstats_get(uint8_t port_id, struct rte_eth_xstats *xstats, uint64_t val; char *stats_ptr; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -1; } + dev = &rte_eth_devices[port_id]; /* implemented by the driver */ @@ -1381,10 +1430,11 @@ rte_eth_xstats_reset(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; /* implemented by the driver */ @@ -1403,10 +1453,11 @@ set_queue_stats_mapping(uint8_t port_id, uint16_t queue_id, uint8_t stat_idx, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -ENODEV; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP); @@ -1438,10 +1489,11 @@ rte_eth_dev_info_get(uint8_t port_id, struct rte_eth_dev_info *dev_info) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); @@ -1458,10 +1510,11 @@ rte_eth_macaddr_get(uint8_t port_id, struct ether_addr *mac_addr) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return; } + dev = &rte_eth_devices[port_id]; ether_addr_copy(&dev->data->mac_addrs[0], mac_addr); } @@ -1472,7 +1525,7 @@ rte_eth_dev_get_mtu(uint8_t port_id, uint16_t *mtu) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1488,7 +1541,7 @@ rte_eth_dev_set_mtu(uint8_t port_id, uint16_t mtu) int ret; struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1508,10 +1561,11 @@ rte_eth_dev_vlan_filter(uint8_t port_id, uint16_t vlan_id, int on) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + dev = &rte_eth_devices[port_id]; if (! (dev->data->dev_conf.rxmode.hw_vlan_filter)) { PMD_DEBUG_TRACE("port %d: vlan-filtering disabled\n", port_id); @@ -1533,7 +1587,7 @@ rte_eth_dev_set_vlan_strip_on_queue(uint8_t port_id, uint16_t rx_queue_id, int o { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1555,7 +1609,7 @@ rte_eth_dev_set_vlan_ether_type(uint8_t port_id, uint16_t tpid) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1575,7 +1629,7 @@ rte_eth_dev_set_vlan_offload(uint8_t port_id, int offload_mask) int mask = 0; int cur, org = 0; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1620,7 +1674,7 @@ rte_eth_dev_get_vlan_offload(uint8_t port_id) struct rte_eth_dev *dev; int ret = 0; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1644,10 +1698,11 @@ rte_eth_dev_set_vlan_pvid(uint8_t port_id, uint16_t pvid, int on) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP); (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on); @@ -1662,7 +1717,7 @@ rte_eth_dev_fdir_add_signature_filter(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1696,7 +1751,7 @@ rte_eth_dev_fdir_update_signature_filter(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1730,7 +1785,7 @@ rte_eth_dev_fdir_remove_signature_filter(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1761,7 +1816,7 @@ rte_eth_dev_fdir_get_infos(uint8_t port_id, struct rte_eth_fdir *fdir) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1786,7 +1841,7 @@ rte_eth_dev_fdir_add_perfect_filter(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1826,7 +1881,7 @@ rte_eth_dev_fdir_update_perfect_filter(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1864,7 +1919,7 @@ rte_eth_dev_fdir_remove_perfect_filter(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1900,7 +1955,7 @@ rte_eth_dev_fdir_set_masks(uint8_t port_id, struct rte_fdir_masks *fdir_mask) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1920,7 +1975,7 @@ rte_eth_dev_flow_ctrl_get(uint8_t port_id, struct rte_eth_fc_conf *fc_conf) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1936,7 +1991,7 @@ rte_eth_dev_flow_ctrl_set(uint8_t port_id, struct rte_eth_fc_conf *fc_conf) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -1956,7 +2011,7 @@ rte_eth_dev_priority_flow_ctrl_set(uint8_t port_id, struct rte_eth_pfc_conf *pfc { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2035,7 +2090,7 @@ rte_eth_dev_rss_reta_update(uint8_t port_id, struct rte_eth_dev *dev; int ret; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -ENODEV; } @@ -2086,10 +2141,11 @@ rte_eth_dev_rss_hash_update(uint8_t port_id, struct rte_eth_rss_conf *rss_conf) struct rte_eth_dev *dev; uint16_t rss_hash_protos; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + rss_hash_protos = rss_conf->rss_hf; if ((rss_hash_protos != 0) && ((rss_hash_protos & ETH_RSS_PROTO_MASK) == 0)) { @@ -2108,10 +2164,11 @@ rte_eth_dev_rss_hash_conf_get(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP); return (*dev->dev_ops->rss_hash_conf_get)(dev, rss_conf); @@ -2123,7 +2180,7 @@ rte_eth_dev_udp_tunnel_add(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -ENODEV; } @@ -2149,10 +2206,11 @@ rte_eth_dev_udp_tunnel_delete(uint8_t port_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -ENODEV; } + dev = &rte_eth_devices[port_id]; if (udp_tunnel == NULL) { @@ -2174,7 +2232,7 @@ rte_eth_led_on(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2189,7 +2247,7 @@ rte_eth_led_off(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2229,10 +2287,11 @@ rte_eth_dev_mac_addr_add(uint8_t port_id, struct ether_addr *addr, int index; uint64_t pool_mask; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP); @@ -2280,10 +2339,11 @@ rte_eth_dev_mac_addr_remove(uint8_t port_id, struct ether_addr *addr) struct rte_eth_dev *dev; int index; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP); @@ -2314,7 +2374,7 @@ rte_eth_dev_set_vf_rxmode(uint8_t port_id, uint16_t vf, struct rte_eth_dev *dev; struct rte_eth_dev_info dev_info; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("set VF RX mode:Invalid port_id=%d\n", port_id); return (-ENODEV); @@ -2369,7 +2429,7 @@ rte_eth_dev_uc_hash_table_set(uint8_t port_id, struct ether_addr *addr, int ret; struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n", port_id); return (-ENODEV); @@ -2422,7 +2482,7 @@ rte_eth_dev_uc_all_hash_table_set(uint8_t port_id, uint8_t on) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("unicast hash setting:Invalid port_id=%d\n", port_id); return (-ENODEV); @@ -2441,7 +2501,7 @@ rte_eth_dev_set_vf_rx(uint8_t port_id,uint16_t vf, uint8_t on) struct rte_eth_dev *dev; struct rte_eth_dev_info dev_info; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2467,7 +2527,7 @@ rte_eth_dev_set_vf_tx(uint8_t port_id,uint16_t vf, uint8_t on) struct rte_eth_dev *dev; struct rte_eth_dev_info dev_info; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("set pool tx:Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2492,7 +2552,7 @@ rte_eth_dev_set_vf_vlan_filter(uint8_t port_id, uint16_t vlan_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("VF VLAN filter:invalid port id=%d\n", port_id); return (-ENODEV); @@ -2523,7 +2583,7 @@ int rte_eth_set_queue_rate_limit(uint8_t port_id, uint16_t queue_idx, struct rte_eth_dev_info dev_info; struct rte_eth_link link; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("set queue rate limit:invalid port id=%d\n", port_id); return -ENODEV; @@ -2560,7 +2620,7 @@ int rte_eth_set_vf_rate_limit(uint8_t port_id, uint16_t vf, uint16_t tx_rate, if (q_msk == 0) return 0; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("set VF rate limit:invalid port id=%d\n", port_id); return -ENODEV; @@ -2594,7 +2654,7 @@ rte_eth_mirror_rule_set(uint8_t port_id, { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2635,7 +2695,7 @@ rte_eth_mirror_rule_reset(uint8_t port_id, uint8_t rule_id) { struct rte_eth_dev *dev = &rte_eth_devices[port_id]; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2660,10 +2720,11 @@ rte_eth_rx_burst(uint8_t port_id, uint16_t queue_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return 0; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->rx_pkt_burst, 0); if (queue_id >= dev->data->nb_rx_queues) { @@ -2680,10 +2741,11 @@ rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return 0; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->tx_pkt_burst, 0); @@ -2700,10 +2762,11 @@ rte_eth_rx_queue_count(uint8_t port_id, uint16_t queue_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return 0; } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_count, 0); return (*dev->dev_ops->rx_queue_count)(dev, queue_id); @@ -2714,10 +2777,11 @@ rte_eth_rx_descriptor_done(uint8_t port_id, uint16_t queue_id, uint16_t offset) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } + dev = &rte_eth_devices[port_id]; FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_descriptor_done, -ENOTSUP); return (*dev->dev_ops->rx_descriptor_done)( \ @@ -2735,7 +2799,8 @@ rte_eth_dev_callback_register(uint8_t port_id, if (!cb_fn) return (-EINVAL); - if (port_id >= nb_ports) { + + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-EINVAL); } @@ -2775,7 +2840,8 @@ rte_eth_dev_callback_unregister(uint8_t port_id, if (!cb_fn) return (-EINVAL); - if (port_id >= nb_ports) { + + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-EINVAL); } @@ -2835,7 +2901,7 @@ int rte_eth_dev_bypass_init(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2855,7 +2921,7 @@ rte_eth_dev_bypass_state_show(uint8_t port_id, uint32_t *state) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2874,7 +2940,7 @@ rte_eth_dev_bypass_state_set(uint8_t port_id, uint32_t *new_state) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2894,7 +2960,7 @@ rte_eth_dev_bypass_event_show(uint8_t port_id, uint32_t event, uint32_t *state) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2914,7 +2980,7 @@ rte_eth_dev_bypass_event_store(uint8_t port_id, uint32_t event, uint32_t state) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2934,7 +3000,7 @@ rte_eth_dev_wd_timeout_store(uint8_t port_id, uint32_t timeout) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2954,7 +3020,7 @@ rte_eth_dev_bypass_ver_show(uint8_t port_id, uint32_t *ver) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2974,7 +3040,7 @@ rte_eth_dev_bypass_wd_timeout_show(uint8_t port_id, uint32_t *wd_timeout) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -2994,7 +3060,7 @@ rte_eth_dev_bypass_wd_reset(uint8_t port_id) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return (-ENODEV); } @@ -3015,7 +3081,7 @@ rte_eth_dev_filter_supported(uint8_t port_id, enum rte_filter_type filter_type) { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -ENODEV; } @@ -3032,7 +3098,7 @@ rte_eth_dev_filter_ctrl(uint8_t port_id, enum rte_filter_type filter_type, { struct rte_eth_dev *dev; - if (port_id >= nb_ports) { + if (!rte_eth_dev_is_valid_port(port_id)) { PMD_DEBUG_TRACE("Invalid port_id=%d\n", port_id); return -ENODEV; } diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 4acd595..ef31bda 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1399,6 +1399,7 @@ struct rte_eth_dev { struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */ 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 */ }; struct rte_eth_dev_sriov { @@ -1464,6 +1465,10 @@ extern struct rte_eth_dev rte_eth_devices[]; * initialized by the [matching] Ethernet driver during the PCI probing phase. * All devices whose port identifier is in the range * [0, rte_eth_dev_count() - 1] can be operated on by network applications. + * immediately after invoking rte_eal_init(). + * If the application unplugs a port using hotplug function, The enabled port + * numbers may be noncontiguous. In the case, the applications need to manage + * enabled port by themselves. * * @return * - The total number of usable Ethernet devices. -- 1.9.1