From patchwork Thu Nov 20 09:06:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 1379 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 3D4E67FA4; Thu, 20 Nov 2014 09:57:31 +0100 (CET) Received: from mail-pd0-f176.google.com (mail-pd0-f176.google.com [209.85.192.176]) by dpdk.org (Postfix) with ESMTP id 1992F7FA4 for ; Thu, 20 Nov 2014 09:57:28 +0100 (CET) Received: by mail-pd0-f176.google.com with SMTP id y10so2693790pdj.21 for ; Thu, 20 Nov 2014 01:07: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=o8VlmeirWW55m3m5ei2+hNphCsqtOCh/+KctSOhy4Qw=; b=A8rSALqIj2XFGWtviugiJsa6d67YXmODsFIVcSctCC7F8aXhRaH/SxicJW/KgpCV3f NXYUO/RaAgdTEjMMqmw2fyiLvr0v13DDEB/ljKBzqGdcsTwOPw3h+kpdlh+5x8Q5UjW5 0dTougotBdOA+dU04OrIvFf+ubgOkJcf5OctGh/2SVoWyHpj1HT133Sn97qigu54Abmk zbVtdF04PvuySYp9wZFx37J5SgRHDtRdlkOBj9Unom8giwsJi9Fk08wgVs+DmryaSOVM 7qYyFugcbkNBfuOkDuLxE6NLAqHBjn82PjHeP3lit/cMrSuo33Iqg18ui37EU8hAyqkz z10Q== X-Gm-Message-State: ALoCoQng5aZFfMgbOODDTQxuREsXDFW047rsy8OnhprLhkYbrZVz+pWMOLq9Be0KHeJPnkLJw3QE X-Received: by 10.70.118.165 with SMTP id kn5mr27786432pdb.140.1416474476850; Thu, 20 Nov 2014 01:07:56 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id a6sm1432407pbu.64.2014.11.20.01.07.54 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Nov 2014 01:07:56 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Thu, 20 Nov 2014 18:06:30 +0900 Message-Id: <1416474399-16851-17-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> References: <1414572576-21371-1-git-send-email-mukawa@igel.co.jp> <1416474399-16851-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 16/25] eal/pci: Add port hotplug functions for virtual 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_vdev() and rte_eal_dev_detach_vdev(). rte_eal_dev_attach_vdev() receives virtual device name and parameters, and returns an attached port number. rte_eal_dev_detach_vdev() receives a port number, and returns device name actually detached. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/eal_common_dev.c | 76 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 29 +++++++++++++ 2 files changed, 105 insertions(+) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 183d65b..0518e3c 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -180,4 +180,80 @@ rte_eal_dev_close_one(const char *name) { return rte_eal_dev_find_and_invoke(name, INVOKE_CLOSE); } + +static void +get_vdev_name(char *vdevargs) +{ + char *sep; + + /* set the first ',' to '\0' to split name and arguments */ + sep = strchr(vdevargs, ','); + if (sep != NULL) + sep[0] = '\0'; +} + +/* attach the new virtual device, then store port_id of the device */ +int +rte_eal_dev_attach_vdev(const char *vdevargs, uint8_t *port_id) +{ + char *args; + uint8_t new_port_id; + struct rte_eth_dev devs[RTE_MAX_ETHPORTS]; + + args = strdup(vdevargs); + if (args == NULL) + return -1; + + /* save current port status */ + rte_eth_dev_save(devs); + /* add the vdevargs to devargs_list */ + if (rte_eal_devargs_add(RTE_DEVTYPE_VIRTUAL, args)) + goto err0; + /* parse vdevargs, then retrieve device name */ + get_vdev_name(args); + /* walk around dev_driver_list to find the driver of the device, + * then invoke probe function o the driver */ + if (rte_eal_dev_init_one(args)) + goto err1; + /* get port_id enabled by above procedures */ + if (rte_eth_dev_get_changed_port(devs, &new_port_id)) + goto err1; + + free(args); + *port_id = new_port_id; + return 0; +err1: + rte_eal_devargs_remove(RTE_DEVTYPE_VIRTUAL, args); +err0: + RTE_LOG(ERR, EAL, "Drver, cannot detach the device\n"); + free(args); + return -1; +} + +/* detach the new virtual device, then store the name of the device */ +int +rte_eal_dev_detach_vdev(uint8_t port_id, char *vdevname) +{ + char name[RTE_ETH_NAME_MAX_LEN]; + + /* check whether the driver supports detach feature, or not */ + if (!rte_eth_dev_check_detachable(port_id)) + goto err; + + /* get device name by port id */ + if (rte_eth_dev_get_name_by_port(port_id, name)) + goto err; + /* walk around dev_driver_list to find the driver of the device, + * then invoke close function o the driver */ + if (rte_eal_dev_close_one(name)) + goto err; + /* remove the vdevname from devargs_list */ + rte_eal_devargs_remove(RTE_DEVTYPE_VIRTUAL, name); + + strncpy(vdevname, name, sizeof(name)); + return 0; +err: + RTE_LOG(ERR, EAL, "Drver, cannot detach the device\n"); + return -1; +} #endif /* RTE_LIBRTE_EAL_HOTPLUG & RTE_LIBRTE_EAL_LINUXAPP */ diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 71d40c3..159d5a5 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -98,6 +98,35 @@ void rte_eal_driver_register(struct rte_driver *driver); */ void rte_eal_driver_unregister(struct rte_driver *driver); +#if defined(RTE_LIBRTE_EAL_HOTPLUG) && defined(RTE_LIBRTE_EAL_LINUXAPP) + +/** + * Attach a new virtual device. + * + * @param vdevargs + * A pointer to a strings array 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_vdev(const char *vdevargs, uint8_t *port_id); + +/** + * Detach a virtual device. + * + * @param port_id + * The port identifier of the virtual device to detach. + * @param addr + * A pointer to a virtual device name actually detached. + * @return + * 0 on success and vdevname is filled, negative on error + */ +int rte_eal_dev_detach_vdev(uint8_t port_id, char *vdevname); + +#endif /* RTE_LIBRTE_EAL_HOTPLUG & RTE_LIBRTE_EAL_LINUXAPP */ + /** * Initalize all the registered drivers in this process */