From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f47.google.com (mail-pa0-f47.google.com [209.85.220.47]) by dpdk.org (Postfix) with ESMTP id 0CFE458EE for ; Tue, 4 Nov 2014 04:37:00 +0100 (CET) Received: by mail-pa0-f47.google.com with SMTP id kx10so13537088pab.20 for ; Mon, 03 Nov 2014 19:46:17 -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=ZcyhlQNKnHVrmy4XAI92zSYtYsyreFYSSqtzkISLpyo=; b=E4d4hbpmn0wzBmBKp5EXgoIOF0cZ2MP6bqia7n5bCDZ3PvKDQjwCNeewsiXmNsJ18U x3EWAHnIwkDByNMkw7o0y+i3t/D3rxGN4prr1yFearUfKsJz3fAclXwKnBa0JT7qw/qF iIFYoUSXI3ADMX+CZVmUxPwN2HqiyGm+1gprCaJtzOc2Y7D6jQlfskW+4K9C1Bt14/xF ZFv35Z+GrLti7QEBYX1RWz8YBzvUj1nNPqXCIslFc3L2V/C0HxjgMQGKfDmGnqhelXnD i4DkQK9nrMtYCFdyC8E918BAhqW7ZeGdt0BcXk4/Wj6pOlxiPLfkWx+AJUgt3j4ZGgpb ZoVw== X-Gm-Message-State: ALoCoQko4LEsJOnG26EtlFACEUuR9v6EyEdRLHS/YooOI3tK02frRAUrxB/9Q4UUg5cBSWA04XtX X-Received: by 10.66.226.235 with SMTP id rv11mr46361328pac.41.1415072777117; Mon, 03 Nov 2014 19:46:17 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id jc3sm18430580pbb.49.2014.11.03.19.46.15 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 03 Nov 2014 19:46:16 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 4 Nov 2014 12:45:22 +0900 Message-Id: <1415072748-31937-3-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1415072748-31937-1-git-send-email-mukawa@igel.co.jp> References: <1414572576-21371-1-git-send-email-mukawa@igel.co.jp> <1415072748-31937-1-git-send-email-mukawa@igel.co.jp> Cc: nakajima.yoshihiro@lab.ntt.co.jp, masutani.hitoshi@lab.ntt.co.jp Subject: [dpdk-dev] [RFC PATCH v2 02/28] 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: Tue, 04 Nov 2014 03:37:01 -0000 To remove assumption, do like followings. - Add 'attached' member to rte_eth_dev structure. This member is used for indicating the port is attached, or not. - Add rte_eth_dev_allocate_new_port(). This function is used for allocating new port. Signed-off-by: Tetsuya Mukawa --- lib/librte_ether/rte_ethdev.c | 24 ++++++++++++++++++++---- lib/librte_ether/rte_ethdev.h | 5 +++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/librte_ether/rte_ethdev.c b/lib/librte_ether/rte_ethdev.c index ff1c769..e37a25a 100644 --- a/lib/librte_ether/rte_ethdev.c +++ b/lib/librte_ether/rte_ethdev.c @@ -208,12 +208,25 @@ rte_eth_dev_allocated(const char *name) return NULL; } +static uint8_t +rte_eth_dev_allocate_new_port(void) +{ + unsigned i; + + for (i = 0; i < RTE_MAX_ETHPORTS; i++) + if (!rte_eth_devices[i].attached) + 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_allocate_new_port(); + if (port_id == RTE_MAX_ETHPORTS) { PMD_DEBUG_TRACE("Reached maximum number of Ethernet ports\n"); return NULL; } @@ -226,10 +239,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 = 1; + nb_ports++; return eth_dev; } @@ -283,6 +298,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 = 0; nb_ports--; return diag; } diff --git a/lib/librte_ether/rte_ethdev.h b/lib/librte_ether/rte_ethdev.h index 8bf274d..5d3956a 100644 --- a/lib/librte_ether/rte_ethdev.h +++ b/lib/librte_ether/rte_ethdev.h @@ -1534,6 +1534,7 @@ struct eth_dev_ops { * process, while the actual configuration data for the device is shared. */ struct rte_eth_dev { + uint8_t attached; /**< Flag indicating the port is attached */ eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */ eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */ struct rte_eth_dev_data *data; /**< Pointer to device data */ @@ -1606,6 +1607,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