From patchwork Tue Dec 9 06:30:25 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 1880 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 3E2D980EA; Tue, 9 Dec 2014 07:31:49 +0100 (CET) Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by dpdk.org (Postfix) with ESMTP id 8097580EA for ; Tue, 9 Dec 2014 07:31:47 +0100 (CET) Received: by mail-pa0-f42.google.com with SMTP id et14so6824100pad.1 for ; Mon, 08 Dec 2014 22:31:46 -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=Fdb3fp6N1E4QKUdYTek72ejf1DX5wyNi9gyWa2+jOu8=; b=LX37Xmy2lSsPnhkq7Y8LN1HLbss2OsU3p7tKGyzHvkviPEuCapg5w+/cAd9jI9knQl KzL4ilRMuA1FljP2m/dLoeuU0J0/KjsOoY3OmzinObuhul3Zef4vMo/sE8+74nWMKhwm x13W2d5ecly3RLNby1Inn2/E5zP/bJVlFFzaf9/vlDDEq6gMizm/JKRgsnxyiXJczf9K J0U8jOaIEDRnCiiEEuG2Lpi3jeQu73A2WaD57djV38+yFR+kiboKzUFTKspOWF9fIcQa QhYJ+8Jm0AD4albIDxJpNPtBHEruTketiE7UqfLGQplfJ497fbKriyBeLn/d2CyKGl4w tqpw== X-Gm-Message-State: ALoCoQksLMdlkTj3Dz1cApA3oM/xFIhSiEXH8gOsG3xhVCMnOFfy/LZ9kvFjIMKas6ZfD/cZYQr+ X-Received: by 10.70.34.162 with SMTP id a2mr27367064pdj.123.1418106706888; Mon, 08 Dec 2014 22:31:46 -0800 (PST) Received: from eris.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id f12sm403088pat.43.2014.12.08.22.31.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Dec 2014 22:31:46 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 9 Dec 2014 15:30:25 +0900 Message-Id: <1418106629-22227-25-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418106629-22227-1-git-send-email-mukawa@igel.co.jp> References: <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> <1418106629-22227-1-git-send-email-mukawa@igel.co.jp> Cc: nakajima.yoshihiro@lab.ntt.co.jp, menrigh@brocade.com, masutani.hitoshi@lab.ntt.co.jp Subject: [dpdk-dev] [PATCH v3 24/28] eal/pci: Add port hotplug functions for physical devices. 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" The patch adds rte_eal_dev_attach_pdev() and rte_eal_dev_detach_pdev(). rte_eal_dev_attach_pdev() receives a PCI address of the device and returns an attached port number. rte_eal_dev_detach_pdev() receives a port number, and returns a PCI address actually detached. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/eal_common_dev.c | 64 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 26 ++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 4ea3502..9ff03ed 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -173,6 +173,70 @@ rte_eal_dev_find_and_invoke(const char *name, int type) return 1; } +/* attach the new physical device, then store port_id of the device */ +int +rte_eal_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id) +{ + uint8_t new_port_id; + struct rte_eth_dev devs[RTE_MAX_ETHPORTS]; + + if ((addr == NULL) || (port_id == NULL)) + goto err; + + /* save current port status */ + rte_eth_dev_save(devs); + /* re-construct pci_device_list */ + if (rte_eal_pci_scan()) + goto err; + /* invoke probe func of the driver can handle the new device */ + if (rte_eal_pci_probe_one(addr)) + goto err; + /* get port_id enabled by above procedures */ + if (rte_eth_dev_get_changed_port(devs, &new_port_id)) + goto err; + + *port_id = new_port_id; + return 0; +err: + RTE_LOG(ERR, EAL, "Drver, cannot attach the device\n"); + return -1; +} + +/* detach the new physical device, then store pci_addr of the device */ +int +rte_eal_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr) +{ + struct rte_pci_addr freed_addr; + struct rte_pci_addr vp; + + if (addr == NULL) + goto err; + + /* check whether the driver supports detach feature, or not */ + if (rte_eth_dev_check_detachable(port_id)) + goto err; + + /* get pci address by port id */ + if (rte_eth_dev_get_addr_by_port(port_id, &freed_addr)) + goto err; + + /* Zerod pci addr means the port comes from virtual device */ + vp.domain = vp.bus = vp.devid = vp.function = 0; + if (eal_compare_pci_addr(&vp, &freed_addr) == 0) + goto err; + + /* invoke close func of the driver, + * also remove the device from pci_device_list */ + if (rte_eal_pci_close_one(&freed_addr)) + goto err; + + *addr = freed_addr; + return 0; +err: + RTE_LOG(ERR, EAL, "Drver, cannot detach the device\n"); + return -1; +} + static void get_vdev_name(char *vdevargs) { diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 159d5a5..f0677cb 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -47,6 +47,7 @@ extern "C" { #endif #include +#include /** Double linked list of device drivers. */ TAILQ_HEAD(rte_driver_list, rte_driver); @@ -101,6 +102,19 @@ void rte_eal_driver_unregister(struct rte_driver *driver); #if defined(RTE_LIBRTE_EAL_HOTPLUG) && defined(RTE_LIBRTE_EAL_LINUXAPP) /** + * Attach a new physical device. + * + * @param addr + * A pointer to a pci address structure describing the new + * device to be attached. + * @param port_id + * A pointer to a port identifier actually attached. + * @return + * 0 on success and port_id is filled, negative on error + */ +int rte_eal_dev_attach_pdev(struct rte_pci_addr *addr, uint8_t *port_id); + +/** * Attach a new virtual device. * * @param vdevargs @@ -114,6 +128,18 @@ void rte_eal_driver_unregister(struct rte_driver *driver); int rte_eal_dev_attach_vdev(const char *vdevargs, uint8_t *port_id); /** + * Detach a physical device. + * + * @param port_id + * The port identifier of the physical device to detach. + * @param addr + * A pointer to a pci address structure actually detached. + * @return + * 0 on success and addr is filled, negative on error + */ +int rte_eal_dev_detach_pdev(uint8_t port_id, struct rte_pci_addr *addr); + +/** * Detach a virtual device. * * @param port_id