From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f53.google.com (mail-pa0-f53.google.com [209.85.220.53]) by dpdk.org (Postfix) with ESMTP id 510A97E23 for ; Tue, 9 Dec 2014 04:43:51 +0100 (CET) Received: by mail-pa0-f53.google.com with SMTP id kq14so6526167pab.12 for ; Mon, 08 Dec 2014 19:43:50 -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=NfBNBvNHYBPOUB28bRd+TL/+LF/0lus4geLqHeZjrFI=; b=k3hDcfhZMQayRn+nJbzK8me09/Yo8qhWMA44ocdv+JARuYYAyraSj+y1/8YSqIP2At hBiLPvWwCH7ZX6SgOYNZdm+lXzt7cz0r8M2garteNPJkzsa26pOjX22t1ZW+PFjdJH9p AxBGsRK1ryHVIpimjRVMXbZwTXbRd3wT92vThOi1uWvAtTXCvC2nanX3Ilyq1Sd6WQ82 249ocV5WVVBMuOELDkkPi0X7vjLaV20Q+G3F3x8O/6Q32hd5IY0gyk0knBQzinzY/iHG u5AeE8udmH7a8eUsMkKPDDUzIuDp9/lue8hVAUFUgN52BPKzqF3O8yWrM4W1QsaF6Qsm DSMw== X-Gm-Message-State: ALoCoQnx2ulJPQGGXp+JPTYawc+x25BSguS7fmB7NquLmjhjGD+BbGdUheLSZLhl73pz0cH5qvYs X-Received: by 10.67.14.231 with SMTP id fj7mr1456192pad.80.1418096630603; Mon, 08 Dec 2014 19:43:50 -0800 (PST) Received: from eris.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id xx2sm2185pab.17.2014.12.08.19.43.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 08 Dec 2014 19:43:50 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Tue, 9 Dec 2014 12:42:39 +0900 Message-Id: <1418096571-27531-17-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1418096571-27531-1-git-send-email-mukawa@igel.co.jp> References: <1416474399-16851-1-git-send-email-mukawa@igel.co.jp> <1418096571-27531-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 v2 16/28] 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: , X-List-Received-Date: Tue, 09 Dec 2014 03:43:52 -0000 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 | 86 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 29 +++++++++++ 2 files changed, 115 insertions(+) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index f573a54..4ea3502 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -172,4 +172,90 @@ rte_eal_dev_find_and_invoke(const char *name, int type) } return 1; } + +static void +get_vdev_name(char *vdevargs) +{ + char *sep; + + if (vdevargs == NULL) + return; + + /* 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]; + + if ((vdevargs == NULL) || (port_id == NULL)) + goto err0; + + args = strdup(vdevargs); + if (args == NULL) + goto err0; + + /* 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 err1; + /* 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_find_and_invoke(args, INVOKE_PROBE)) + goto err2; + /* get port_id enabled by above procedures */ + if (rte_eth_dev_get_changed_port(devs, &new_port_id)) + goto err2; + + free(args); + *port_id = new_port_id; + return 0; +err2: + rte_eal_devargs_remove(RTE_DEVTYPE_VIRTUAL, args); +err1: + free(args); +err0: + RTE_LOG(ERR, EAL, "Drver, cannot detach the device\n"); + 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]; + + if (vdevname == NULL) + goto err; + + /* 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_find_and_invoke(name, INVOKE_CLOSE)) + 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 */ -- 1.9.1