From patchwork Thu Oct 18 01:35:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47015 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D02501B115; Thu, 18 Oct 2018 03:35:26 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 7F6415F4D for ; Thu, 18 Oct 2018 03:35:23 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 2256C21DB2; Wed, 17 Oct 2018 21:35:23 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; s=mesmtp; bh=ET7Tz4LmbD1BVE9CWVNC8uTfisBGLDmprnxDCoWCzQw=; b=HVY04QBrHlC+ ph5OdHKseAjKNyzJcREhx4+jKZPnp38Hk9UbolCcymP/2PkNIpcLYMi/fCZDdU8C bX8q7GOnf9/CgeoiFHswagCMuY0AcYwZnPisgmJDh9DC8jPuW73eo88dkMeV5zXK HhFVt3CtKwVG2FyBgFmfVZCTKsjA8Us= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=ET7Tz4LmbD1BVE9CWVNC8uTfisBGLDmprnxDCoWCz Qw=; b=YRQThH1+tc43SsQakV2Uh5F+1sxN0CxjtCKyyCz0SJ2P2dxmgGcRQDo5c 9n5/ennQNYqo7RdXI1d5N7vlDg5hbAz1/vy/dn4W30rfrJ7xlNaoNk72epR7f3ms sV0vYDowcqxr0+0tdZtxsOI/7RbuBlKxIBkJyIIbJsn+R6XOuosPCDMJ/At9avjQ C13L5Z4w1ZN0nV3RnAE25NBx9XAWg0944hhEqcMPoHDBZq48nRX6ZKo6Sh/mmnTT wWnQXpjao/zRFkVqrVKy+RBdjgYbC8z3Xdgb/emXCOgrz4OYGv80YhLN/r6nLBE/ 6TwA6seYJnu7dl8oSkXMfcSANnlYg== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 0E9CEE4240; Wed, 17 Oct 2018 21:35:21 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:16 +0200 Message-Id: <20181018013522.11253-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 1/7] bus/vdev: add iteration filter on name X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" A virtual device can be matched with following syntax: bus=vdev,name=X Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- drivers/bus/vdev/vdev_params.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c index da270f2ec..6f74704d1 100644 --- a/drivers/bus/vdev/vdev_params.c +++ b/drivers/bus/vdev/vdev_params.c @@ -2,6 +2,8 @@ * Copyright 2018 Gaƫtan Rivet */ +#include + #include #include #include @@ -11,10 +13,12 @@ #include "vdev_private.h" enum vdev_params { + RTE_VDEV_PARAM_NAME, RTE_VDEV_PARAM_MAX, }; static const char * const vdev_params_keys[] = { + [RTE_VDEV_PARAM_NAME] = "name", [RTE_VDEV_PARAM_MAX] = NULL, }; @@ -22,10 +26,21 @@ static int vdev_dev_match(const struct rte_device *dev, const void *_kvlist) { + int ret; const struct rte_kvargs *kvlist = _kvlist; + char *name; + + /* cannot pass const dev->name to rte_kvargs_process() */ + name = strdup(dev->name); + if (name == NULL) + return -1; + ret = rte_kvargs_process(kvlist, + vdev_params_keys[RTE_VDEV_PARAM_NAME], + rte_kvargs_strcmp, name); + free(name); + if (ret != 0) + return -1; - (void) kvlist; - (void) dev; return 0; } From patchwork Thu Oct 18 01:35:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47016 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id D6C4B1B10F; Thu, 18 Oct 2018 03:35:38 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 5E76C5F4D for ; Thu, 18 Oct 2018 03:35:24 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0643E21FC0; Wed, 17 Oct 2018 21:35:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=KTewqNV/je 5neMfXUD0itcS7NiJIWSXdxYFv1k6ZIv8=; b=BjoBQUEWYRNTOKEgTT9LATvD/Q WZxjt+IkkLdGdsV154UfIfVAwvRfPS3nN+OvzdkEfRIK1msKuK31ahQ9gYmT7cZf EwC/vheCrR6FmKRscZD/WmxinNaeGyGki4jvuEssQSwyvDL1K01SGnyWvgMWddcN duIiBDoagfanvKdI0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=KTewqNV/je5neMfXUD0itcS7NiJIWSXdxYFv1k6ZIv8=; b=tSov9UXz lUehZ1hkBhqrQdmgqAPRA92obd4cxlMeXQCsFlk8p4PxUADZJ788Zzx3fFTEtvHR R3ZPE6Y5yga2rIoiSqtgjARFVVEinw5psQyx/8a8mVpXKHM7uNboncdPsJXZMv1k J1pMgXddzvDJJixjWoijgCVKGX9l9651YVxy1ALp154t/dZyziONXkYk3Xc+3yFY fctPWxBusiMZxn/TVPJ6nlvZJ9Hu9dmL9sqRnYl/zKeLxtYb/P0H9xJ1rCBx6lZz RyhAmLQKgLxmJFHyKp2F/Kj6mqXfH9bmgbSaDqjXjycQJ+3uyLupHjAnkWuUtlL0 mEWV/6i8upGQlA== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id EFBDAE462B; Wed, 17 Oct 2018 21:35:22 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:17 +0200 Message-Id: <20181018013522.11253-3-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 2/7] ethdev: add iterator to match devargs input X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The iterator will return the ethdev port ids matching a devargs string. It is recommended to use the macro RTE_ETH_FOREACH_MATCHING_DEV() for usage convenience. The class string is prefixed with '+' in order to skip the validation of the parameter keys. It is tolerated for the compatibility with the old (current) syntax where all parameters (bus, class and driver) are mixed in the same string without any delimiter. Thanks to this compatibility prefix, the driver parameters will be skipped during the ethdev parsing, and not considered invalid. A macro is introduced in rte_common.h to workaround a const field. This hack is needed to free const strings in the iterator. It is preferred to keep the const for these fields, because it gives a hint that they are not changed at each iteration. Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- lib/librte_eal/common/include/rte_common.h | 6 + lib/librte_ethdev/ethdev_private.c | 10 +- lib/librte_ethdev/ethdev_private.h | 6 + lib/librte_ethdev/rte_class_eth.c | 7 +- lib/librte_ethdev/rte_ethdev.c | 123 +++++++++++++++++++++ lib/librte_ethdev/rte_ethdev.h | 79 +++++++++++++ lib/librte_ethdev/rte_ethdev_version.map | 3 + 7 files changed, 232 insertions(+), 2 deletions(-) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 069c13ec7..e3c0407a9 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -164,6 +164,12 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) */ #define RTE_PTR_DIFF(ptr1, ptr2) ((uintptr_t)(ptr1) - (uintptr_t)(ptr2)) +/** + * Workaround to cast a const field of a structure to non-const type. + */ +#define RTE_CAST_FIELD(var, field, type) \ + (*(type *)((uintptr_t)(var) + offsetof(typeof(*(var)), field))) + /*********** Macros/static functions for doing alignment ********/ diff --git a/lib/librte_ethdev/ethdev_private.c b/lib/librte_ethdev/ethdev_private.c index 768c8b2ed..acc787dba 100644 --- a/lib/librte_ethdev/ethdev_private.c +++ b/lib/librte_ethdev/ethdev_private.c @@ -5,6 +5,14 @@ #include "rte_ethdev.h" #include "ethdev_private.h" +uint16_t +eth_dev_to_id(const struct rte_eth_dev *dev) +{ + if (dev == NULL) + return RTE_MAX_ETHPORTS; + return dev - rte_eth_devices; +} + struct rte_eth_dev * eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, const void *data) @@ -18,7 +26,7 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, start > &rte_eth_devices[RTE_MAX_ETHPORTS])) return NULL; if (start != NULL) - idx = start - &rte_eth_devices[0] + 1; + idx = eth_dev_to_id(start) + 1; else idx = 0; for (; idx < RTE_MAX_ETHPORTS; idx++) { diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h index 0f5c6d5c4..e67cf6831 100644 --- a/lib/librte_ethdev/ethdev_private.h +++ b/lib/librte_ethdev/ethdev_private.h @@ -11,6 +11,12 @@ extern "C" { #endif +/* + * Convert rte_eth_dev pointer to port id. + * NULL will be translated to RTE_MAX_ETHPORTS. + */ +uint16_t eth_dev_to_id(const struct rte_eth_dev *dev); + /* Generic rte_eth_dev comparison function. */ typedef int (*rte_eth_cmp_t)(const struct rte_eth_dev *, const void *); diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index 84b646291..c04279ec6 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -57,9 +57,14 @@ eth_dev_iterate(const void *start, { struct rte_kvargs *kvargs = NULL; struct rte_eth_dev *edev = NULL; + const char * const *valid_keys = NULL; if (str != NULL) { - kvargs = rte_kvargs_parse(str, eth_params_keys); + if (str[0] == '+') /* no validation of keys */ + str++; + else + valid_keys = eth_params_keys; + kvargs = rte_kvargs_parse(str, valid_keys); if (kvargs == NULL) { RTE_LOG(ERR, EAL, "cannot parse argument list\n"); rte_errno = EINVAL; diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 987ba5ab1..45f3f883a 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -36,11 +36,13 @@ #include #include #include +#include #include "rte_ether.h" #include "rte_ethdev.h" #include "rte_ethdev_driver.h" #include "ethdev_profile.h" +#include "ethdev_private.h" int rte_eth_dev_logtype; @@ -184,6 +186,127 @@ enum { STAT_QMAP_RX }; +int __rte_experimental +rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) +{ + int ret; + struct rte_devargs devargs = {.args = NULL}; + const char *bus_param_key; + char *bus_str = NULL; + char *cls_str = NULL; + int str_size; + + memset(iter, 0, sizeof(*iter)); + + /* + * The devargs string may use various syntaxes: + * - 0000:08:00.0,representor=[1-3] + * - pci:0000:06:00.0,representor=[0,5] + * A new syntax is in development (not yet supported): + * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z + */ + + /* Split bus, device and parameters. */ + ret = rte_devargs_parse(&devargs, devargs_str); + if (ret != 0) + goto error; + + /* + * Assume parameters of old syntax can match only at ethdev level. + * Extra parameters will be ignored, thanks to "+" prefix. + */ + str_size = strlen(devargs.args) + 2; + cls_str = malloc(str_size); + if (cls_str == NULL) { + ret = -ENOMEM; + goto error; + } + ret = snprintf(cls_str, str_size, "+%s", devargs.args); + if (ret != str_size - 1) { + ret = -EINVAL; + goto error; + } + iter->cls_str = cls_str; + free(devargs.args); /* allocated by rte_devargs_parse() */ + devargs.args = NULL; + + iter->bus = devargs.bus; + if (iter->bus->dev_iterate == NULL) { + ret = -ENOTSUP; + goto error; + } + + /* Convert bus args to new syntax for use with new API dev_iterate. */ + if (strcmp(iter->bus->name, "vdev") == 0) { + bus_param_key = "name"; + } else if (strcmp(iter->bus->name, "pci") == 0) { + bus_param_key = "addr"; + } else { + ret = -ENOTSUP; + goto error; + } + str_size = strlen(bus_param_key) + strlen(devargs.name) + 2; + bus_str = malloc(str_size); + if (bus_str == NULL) { + ret = -ENOMEM; + goto error; + } + ret = snprintf(bus_str, str_size, "%s=%s", + bus_param_key, devargs.name); + if (ret != str_size - 1) { + ret = -EINVAL; + goto error; + } + iter->bus_str = bus_str; + + iter->cls = rte_class_find_by_name("eth"); + return 0; + +error: + if (ret == -ENOTSUP) + RTE_LOG(ERR, EAL, "Bus %s does not support iterating.\n", + iter->bus->name); + free(devargs.args); + free(bus_str); + free(cls_str); + return ret; +} + +uint16_t __rte_experimental +rte_eth_iterator_next(struct rte_dev_iterator *iter) +{ + if (iter->cls == NULL) /* invalid ethdev iterator */ + return RTE_MAX_ETHPORTS; + + do { /* loop to try all matching rte_device */ + /* If not in middle of rte_eth_dev iteration, */ + if (iter->class_device == NULL) { + /* get next rte_device to try. */ + iter->device = iter->bus->dev_iterate( + iter->device, iter->bus_str, iter); + if (iter->device == NULL) + break; /* no more rte_device candidate */ + } + /* A device is matching bus part, need to check ethdev part. */ + iter->class_device = iter->cls->dev_iterate( + iter->class_device, iter->cls_str, iter); + if (iter->class_device != NULL) + return eth_dev_to_id(iter->class_device); /* match */ + } while (1); /* need to try next rte_device */ + + /* No more ethdev port to iterate. */ + rte_eth_iterator_cleanup(iter); + return RTE_MAX_ETHPORTS; +} + +void __rte_experimental +rte_eth_iterator_cleanup(struct rte_dev_iterator *iter) +{ + free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */ + free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */ + memset(iter, 0, sizeof(*iter)); +} + uint16_t rte_eth_find_next(uint16_t port_id) { diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index dcdeb184b..3c3684b63 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -166,6 +166,85 @@ extern int rte_eth_dev_logtype; struct rte_mbuf; +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Initializes a device iterator. + * + * This iterator allows accessing a list of devices matching some devargs. + * + * @param iter + * Device iterator handle initialized by the function. + * The fields bus_str and cls_str might be dynamically allocated, + * and could be freed by calling rte_eth_iterator_cleanup(). + * + * @param devargs + * Device description string. + * + * @return + * 0 on successful initialization, negative otherwise. + */ +__rte_experimental +int rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Iterates on devices with devargs filter. + * The ownership is not checked. + * + * The next port id is returned, and the iterator is updated. + * + * @param iter + * Device iterator handle initialized by rte_eth_iterator_init(). + * Some fields bus_str and cls_str might be freed when no more port is found, + * by calling rte_eth_iterator_cleanup(). + * + * @return + * A port id if found, RTE_MAX_ETHPORTS otherwise. + */ +__rte_experimental +uint16_t rte_eth_iterator_next(struct rte_dev_iterator *iter); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Free some allocated fields of the iterator. + * + * This function is automatically called by rte_eth_iterator_next() + * on the last iteration (i.e. when no more matching port is found). + * + * It is safe to call this function twice; it will do nothing more. + * + * @param iter + * Device iterator handle initialized by rte_eth_iterator_init(). + * The fields bus_str and cls_str are freed if needed. + */ +__rte_experimental +void rte_eth_iterator_cleanup(struct rte_dev_iterator *iter); + +/** + * Macro to iterate over all ethdev ports matching some devargs. + * + * If a break is done before the end of the loop, + * the function rte_eth_iterator_cleanup() must be called. + * + * @param id + * Iterated port id of type uint16_t. + * @param devargs + * Device parameters input as string of type char*. + * @param iter + * Iterator handle of type struct rte_dev_iterator, used internally. + */ +#define RTE_ETH_FOREACH_MATCHING_DEV(id, devargs, iter) \ + for (rte_eth_iterator_init(iter, devargs), \ + id = rte_eth_iterator_next(iter); \ + id != RTE_MAX_ETHPORTS; \ + id = rte_eth_iterator_next(iter)) + /** * A structure used to retrieve statistics for an Ethernet port. * Not all statistics fields in struct rte_eth_stats are supported diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index dfa122c1a..399380ad3 100644 --- a/lib/librte_ethdev/rte_ethdev_version.map +++ b/lib/librte_ethdev/rte_ethdev_version.map @@ -238,6 +238,9 @@ EXPERIMENTAL { rte_eth_dev_rx_intr_ctl_q_get_fd; rte_eth_dev_rx_offload_name; rte_eth_dev_tx_offload_name; + rte_eth_iterator_cleanup; + rte_eth_iterator_init; + rte_eth_iterator_next; rte_eth_switch_domain_alloc; rte_eth_switch_domain_free; rte_flow_conv; From patchwork Thu Oct 18 01:35:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47017 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 89BF41B142; Thu, 18 Oct 2018 03:35:40 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 4C7525F4D for ; Thu, 18 Oct 2018 03:35:25 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id E61A022086; Wed, 17 Oct 2018 21:35:24 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:24 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=b4RsT7W19y m5BL7Q5vpa4QEqzqRbKP/FwPR9n7otv2w=; b=Fs+r9dHpG+Dg45KP8WHciFnazO GMgmBi8wyGgADL6m0RvZDjHT4kQaX8aGB4FcMneuJPsLe8vRQoKGZklGjig2ssBj eBitM/Ewsox2S1tgO7yLl7jq2n8mXGmCD+CRXLWTVKDQy3QvLPDlQEibi3i09Ydo hA8XNImxdhzHflrrU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=b4RsT7W19ym5BL7Q5vpa4QEqzqRbKP/FwPR9n7otv2w=; b=nS3nMdFD RdHwJh1woLr/TA9mnhxiWKWMsQ5Ha/hq6gzMlQjRtsiGHsMFvZMv47zZwsTzXA3J LlN+VXGZNMduV2xo31TZEytA58cUwsCXCXl744N7lmZUFh/B6xMEZ0f3vzOhpDJi QBuUv1cpYvIu+zpnwFa+poz09IE8kBHOeErKeK6GRgiHf2zR8ff1GYwJoLbsiVWH ii6v66w1RD494Q4No4OKYfqmWCwcfjyQtzYeYwSC18jq06xgUvzBMgkZvA7BbiLS tqnfb7CIsr7rcnpjzs5k0m9rn+7ta4QRaBcvKZ3ekYU0rHu6FQ8im57p+rPKK7gQ Q4fper/iPCSznA== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id DD66AE4240; Wed, 17 Oct 2018 21:35:23 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:18 +0200 Message-Id: <20181018013522.11253-4-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 3/7] ethdev: allow iterating with pure class filter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If no rte_device is given in the iterator, eth_dev_match() is looking at all ports without any restriction, except the ethdev kvargs filter. It allows to iterate with a devargs filter referencing only some ethdev parameters. The format (from the new devargs syntax) is: class=eth,paramY=Y Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- lib/librte_ethdev/rte_class_eth.c | 2 +- lib/librte_ethdev/rte_ethdev.c | 25 ++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index c04279ec6..58fed694b 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -42,7 +42,7 @@ eth_dev_match(const struct rte_eth_dev *edev, if (edev->state == RTE_ETH_DEV_UNUSED) return -1; - if (edev->device != arg->device) + if (arg->device != NULL && arg->device != edev->device) return -1; if (kvlist == NULL) /* Empty string matches everything. */ diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 45f3f883a..20100723d 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -202,10 +202,24 @@ rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) * The devargs string may use various syntaxes: * - 0000:08:00.0,representor=[1-3] * - pci:0000:06:00.0,representor=[0,5] + * - class=eth,mac=00:11:22:33:44:55 * A new syntax is in development (not yet supported): * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z */ + /* + * Handle pure class filter (i.e. without any bus-level argument), + * from future new syntax. + * rte_devargs_parse() is not yet supporting the new syntax, + * that's why this simple case is temporarily parsed here. + */ +#define iter_anybus_str "class=eth," + if (strncmp(devargs_str, iter_anybus_str, + strlen(iter_anybus_str)) == 0) { + iter->cls_str = devargs_str + strlen(iter_anybus_str); + goto end; + } + /* Split bus, device and parameters. */ ret = rte_devargs_parse(&devargs, devargs_str); if (ret != 0) @@ -259,6 +273,7 @@ rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) } iter->bus_str = bus_str; +end: iter->cls = rte_class_find_by_name("eth"); return 0; @@ -279,8 +294,10 @@ rte_eth_iterator_next(struct rte_dev_iterator *iter) return RTE_MAX_ETHPORTS; do { /* loop to try all matching rte_device */ - /* If not in middle of rte_eth_dev iteration, */ - if (iter->class_device == NULL) { + /* If not pure ethdev filter and */ + if (iter->bus != NULL && + /* not in middle of rte_eth_dev iteration, */ + iter->class_device == NULL) { /* get next rte_device to try. */ iter->device = iter->bus->dev_iterate( iter->device, iter->bus_str, iter); @@ -292,7 +309,7 @@ rte_eth_iterator_next(struct rte_dev_iterator *iter) iter->class_device, iter->cls_str, iter); if (iter->class_device != NULL) return eth_dev_to_id(iter->class_device); /* match */ - } while (1); /* need to try next rte_device */ + } while (iter->bus != NULL); /* need to try next rte_device */ /* No more ethdev port to iterate. */ rte_eth_iterator_cleanup(iter); @@ -302,6 +319,8 @@ rte_eth_iterator_next(struct rte_dev_iterator *iter) void __rte_experimental rte_eth_iterator_cleanup(struct rte_dev_iterator *iter) { + if (iter->bus_str == NULL) + return; /* nothing to free in pure class filter */ free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */ free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */ memset(iter, 0, sizeof(*iter)); From patchwork Thu Oct 18 01:35:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47018 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 553FF1B14C; Thu, 18 Oct 2018 03:35:42 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 2FF581B113 for ; Thu, 18 Oct 2018 03:35:26 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id CEB4121F86; Wed, 17 Oct 2018 21:35:25 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=xHdGx5nlWB cK2orD7tyqifxmzZRTx536xUTbg1ZtRhs=; b=LiGdkOHK85WZDvKQlK2HppcnQo N2E8QlZ64JHarPJk+CHFOR30baCGwaC0gndoVE4ZqUklqjGmYKNfv1tBorQXheBY N1A4GvMDfvIR36MEtUCnBjcM5gLT4kuqJ9HyWkQLnP+j3RgofI9/diQdM0vj5g1J RjWhCJq6q7wPJbrGk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=xHdGx5nlWBcK2orD7tyqifxmzZRTx536xUTbg1ZtRhs=; b=s5+VdKOf og63wfe8S1HPppSAZGKlWH37tS/v96VWX5i+5QOfG8Meb7/AJAyBqqQ4kLaSG4/c u9IrzMOBzA8V+Xh3Z1d8oV7oOa7HxVl57l0N9lNXrD+oC91LfwF7ch/RGXbJtlMx NDekySlozyDAifmMdwfCy3pmV7vUgXZZHB59CykH4KWedG4VkAQHgMYH37Vs69RV vCUt8Yj8NR7twkyjWAAlozQdJnq4DPXH/NMdfRnPwZa+pTDH7N4hGvSsD58bET7F 3qYSZM4bYf2ynWOu3Z5KKtoLgV2w0EKNp4f6QwTvEaaBKwd+rDifQJXywNj2WO/U IBuOK+7oBf2zlQ== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id C2B4BE462B; Wed, 17 Oct 2018 21:35:24 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:19 +0200 Message-Id: <20181018013522.11253-5-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 4/7] doc: replace doxygen example in contribution guide X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The provided example of doxygen header is about a deprecated function. It is replaced by rte_spinlock_trylock() which is small and good enough for the purpose. Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- doc/guides/contributing/documentation.rst | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/doc/guides/contributing/documentation.rst b/doc/guides/contributing/documentation.rst index 097575ad7..0165990ed 100644 --- a/doc/guides/contributing/documentation.rst +++ b/doc/guides/contributing/documentation.rst @@ -615,19 +615,14 @@ The following are some guidelines for use of Doxygen in the DPDK API documentati .. code-block:: c /** - * Attach a new Ethernet device specified by arguments. - * - * @param devargs - * A pointer to a strings array describing the new device - * to be attached. The strings should be a pci address like - * `0000:01:00.0` or **virtual** device name like `net_pcap0`. - * @param port_id - * A pointer to a port identifier actually attached. + * Try to take the lock. * + * @param sl + * A pointer to the spinlock. * @return - * 0 on success and port_id is filled, negative on error. + * 1 if the lock is successfully taken; 0 otherwise. */ - int rte_eth_dev_attach(const char *devargs, uint8_t *port_id); + int rte_spinlock_trylock(rte_spinlock_t *sl); * Doxygen supports Markdown style syntax such as bold, italics, fixed width text and lists. For example the second line in the ``devargs`` parameter in the previous example will be rendered as: From patchwork Thu Oct 18 01:35:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47019 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 28E221B156; Thu, 18 Oct 2018 03:35:44 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 90C431B11D for ; Thu, 18 Oct 2018 03:35:27 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 03A2021DB2; Wed, 17 Oct 2018 21:35:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=p0qQ4j6XmM tC968BPOvyFsdIRMmzkFF1xr0Xf5Z4RgE=; b=PWzQKBXqwAwabiHGwlX/Ip7cxi /x9XC4/T/mxjpV6lc8NzI/p/2hJ63UVXdivq3qfub9APaqG6gkNMH/devMwgkXKt JUse2nxSa/tVx6jvUWbMrC4MmyomsP3WkItEcfOWPPimX9l7XC91A1cmE9UrTiEc zp7uJpxPM2DBNw7Nc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=p0qQ4j6XmMtC968BPOvyFsdIRMmzkFF1xr0Xf5Z4RgE=; b=NplV+7Jc v4vJ5hz7QYP44U5sTW/1BsU52JXUukmt7qTqQyPk784CSq/u+/xFo435UOF15+Nl 4MRWXdac8fyBgfZG0iGFuOdFbbioJwgU3Kn/tzJei6kqNpoABVdppvSX/93Bieg6 EOwRvebHMsQ4XtSGIVy1/YE1rJf1yJytfcjZfCs3+wkmluDrwHL/rTAjGhBzNqiV JN+9i+Tjl2UjphynEXUS+MJ4Ki7d6rTIW1etEF9n8x3hHsX51pOGoTpucGNsvPYc LVS6Gl+p0SKOfKafN/GfAd6SkwvIrH2o2hr3fw/CCVydydq7np015R8hl80Lnl93 xPlQSGMJaH8bfg== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id ABAD5E4240; Wed, 17 Oct 2018 21:35:25 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:20 +0200 Message-Id: <20181018013522.11253-6-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 5/7] ethdev: remove deprecated attach/detach functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The hotplug attach/detach features are implemented in EAL layer. There is a new ethdev iterator to retrieve ports from ethdev layer. As announced earlier, the (buggy) ethdev functions are now removed. Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- app/test-pmd/testpmd.c | 20 +++- doc/guides/prog_guide/index.rst | 1 - .../prog_guide/port_hotplug_framework.rst | 106 ------------------ doc/guides/rel_notes/deprecation.rst | 7 -- doc/guides/rel_notes/release_18_11.rst | 8 +- drivers/net/virtio/virtio_user_ethdev.c | 1 - lib/librte_ethdev/Makefile | 2 +- lib/librte_ethdev/meson.build | 2 +- lib/librte_ethdev/rte_ethdev.c | 81 ------------- lib/librte_ethdev/rte_ethdev.h | 31 ----- lib/librte_ethdev/rte_ethdev_version.map | 2 - 11 files changed, 24 insertions(+), 237 deletions(-) delete mode 100644 doc/guides/prog_guide/port_hotplug_framework.rst diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 2bd3fd986..f241ce363 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -481,6 +481,7 @@ struct nvgre_encap_conf nvgre_encap_conf = { }; /* Forward function declarations */ +static void setup_attached_port(portid_t pi); static void map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port); static void check_all_ports_link_status(uint32_t port_mask); @@ -2295,7 +2296,7 @@ void attach_port(char *identifier) { portid_t pi = 0; - unsigned int socket_id; + struct rte_dev_iterator iterator; printf("Attaching a new port...\n"); @@ -2304,8 +2305,19 @@ attach_port(char *identifier) return; } - if (rte_eth_dev_attach(identifier, &pi)) + if (rte_dev_probe(identifier) != 0) { + TESTPMD_LOG(ERR, "Failed to attach port %s\n", identifier); return; + } + + RTE_ETH_FOREACH_MATCHING_DEV(pi, identifier, &iterator) + setup_attached_port(pi); +} + +static void +setup_attached_port(portid_t pi) +{ + unsigned int socket_id; socket_id = (unsigned)rte_eth_dev_socket_id(pi); /* if socket_id is invalid, set to 0 */ @@ -2328,8 +2340,6 @@ attach_port(char *identifier) void detach_port(portid_t port_id) { - char name[RTE_ETH_NAME_MAX_LEN]; - printf("Detaching a port...\n"); if (ports[port_id].port_status != RTE_PORT_CLOSED) { @@ -2342,7 +2352,7 @@ detach_port(portid_t port_id) port_flow_flush(port_id); } - if (rte_eth_dev_detach(port_id, name)) { + if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) { TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id); return; } diff --git a/doc/guides/prog_guide/index.rst b/doc/guides/prog_guide/index.rst index c81d9c54f..2086e2442 100644 --- a/doc/guides/prog_guide/index.rst +++ b/doc/guides/prog_guide/index.rst @@ -53,7 +53,6 @@ Programmer's Guide packet_framework vhost_lib metrics_lib - port_hotplug_framework bpf_lib source_org dev_kit_build_system diff --git a/doc/guides/prog_guide/port_hotplug_framework.rst b/doc/guides/prog_guide/port_hotplug_framework.rst deleted file mode 100644 index fb0efc18f..000000000 --- a/doc/guides/prog_guide/port_hotplug_framework.rst +++ /dev/null @@ -1,106 +0,0 @@ -.. BSD LICENSE - Copyright(c) 2015 IGEL Co.,Ltd. All rights reserved. - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - * Neither the name of IGEL Co.,Ltd. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -Port Hotplug Framework -====================== - -The Port Hotplug Framework provides DPDK applications with the ability to -attach and detach ports at runtime. Because the framework depends on PMD -implementation, the ports that PMDs cannot handle are out of scope of this -framework. Furthermore, after detaching a port from a DPDK application, the -framework doesn't provide a way for removing the devices from the system. -For the ports backed by a physical NIC, the kernel will need to support PCI -Hotplug feature. - -Overview --------- - -The basic requirements of the Port Hotplug Framework are: - -* DPDK applications that use the Port Hotplug Framework must manage their - own ports. - - The Port Hotplug Framework is implemented to allow DPDK applications to - manage ports. For example, when DPDK applications call the port attach - function, the attached port number is returned. DPDK applications can - also detach the port by port number. - -* Kernel support is needed for attaching or detaching physical device - ports. - - To attach new physical device ports, the device will be recognized by - userspace driver I/O framework in kernel at first. Then DPDK - applications can call the Port Hotplug functions to attach the ports. - For detaching, steps are vice versa. - -* Before detaching, they must be stopped and closed. - - DPDK applications must call "rte_eth_dev_stop()" and - "rte_eth_dev_close()" APIs before detaching ports. These functions will - start finalization sequence of the PMDs. - -* The framework doesn't affect legacy DPDK applications behavior. - - If the Port Hotplug functions aren't called, all legacy DPDK apps can - still work without modifications. - -Port Hotplug API overview -------------------------- - -* Attaching a port - - "rte_eth_dev_attach()" API attaches a port to DPDK application, and - returns the attached port number. Before calling the API, the device - should be recognized by an userspace driver I/O framework. The API - receives a pci address like "0000:01:00.0" or a virtual device name - like "net_pcap0,iface=eth0". In the case of virtual device name, the - format is the same as the general "--vdev" option of DPDK. - -* Detaching a port - - "rte_eth_dev_detach()" API detaches a port from DPDK application, and - returns a pci address of the detached device or a virtual device name - of the device. - -Reference ---------- - - "testpmd" supports the Port Hotplug Framework. - -Limitations ------------ - -* The Port Hotplug APIs are not thread safe. - -* The framework can only be enabled with Linux. BSD is not supported. - -* Not all PMDs support detaching feature. - The underlying bus must support hot-unplug. If not supported, - the function ``rte_eth_dev_detach()`` will return negative ENOTSUP. diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 9f825f09e..6b51c9d28 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -49,13 +49,6 @@ Deprecation Notices Target release for removal of the legacy API will be defined once most PMDs have switched to rte_flow. -* ethdev: In v18.11 ``rte_eth_dev_attach()`` and ``rte_eth_dev_detach()`` - will be removed. - Hotplug functions ``rte_eal_hotplug_add()`` and ``rte_eal_hotplug_remove()`` - should be used instread. - Function ``rte_eth_dev_get_port_by_name()`` may be used to find - identifier of the added port. - * eal: In v18.11 ``rte_eal_dev_attach()`` and ``rte_eal_dev_detach()`` will be removed. Hotplug functions ``rte_eal_hotplug_add()`` and ``rte_eal_hotplug_remove()`` diff --git a/doc/guides/rel_notes/release_18_11.rst b/doc/guides/rel_notes/release_18_11.rst index b982ca80e..45fb88449 100644 --- a/doc/guides/rel_notes/release_18_11.rst +++ b/doc/guides/rel_notes/release_18_11.rst @@ -215,6 +215,12 @@ API Changes functions were deprecated since 17.05 and are replaced by ``rte_mbuf_raw_free()`` and ``rte_pktmbuf_prefree_seg()``. +* ethdev: The deprecated functions attach/detach were removed in 18.11. + ``rte_eth_dev_attach`` can be replaced by ``RTE_ETH_FOREACH_MATCHING_DEV`` + and ``rte_dev_probe`` or ``rte_eal_hotplug_add``. + ``rte_eth_dev_detach`` can be replaced by + ``rte_dev_remove`` or ``rte_eal_hotplug_remove``. + * ethdev: A call to ``rte_eth_dev_release_port()`` has been added in ``rte_eth_dev_close()``. As a consequence, a closed port is freed and seen as invalid because of its state ``RTE_ETH_DEV_UNUSED``. @@ -319,7 +325,7 @@ The libraries prepended with a plus sign were incremented in this version. librte_cryptodev.so.5 librte_distributor.so.1 + librte_eal.so.9 - librte_ethdev.so.10 + + librte_ethdev.so.11 + librte_eventdev.so.6 librte_flow_classify.so.1 librte_gro.so.1 diff --git a/drivers/net/virtio/virtio_user_ethdev.c b/drivers/net/virtio/virtio_user_ethdev.c index 420364b7a..b51cbc85b 100644 --- a/drivers/net/virtio/virtio_user_ethdev.c +++ b/drivers/net/virtio/virtio_user_ethdev.c @@ -635,7 +635,6 @@ virtio_user_pmd_probe(struct rte_vdev_device *dev) return ret; } -/** Called by rte_eth_dev_detach() */ static int virtio_user_pmd_remove(struct rte_vdev_device *vdev) { diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index d720dd207..e27bcd5ac 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/Makefile @@ -16,7 +16,7 @@ LDLIBS += -lrte_mbuf -lrte_kvargs EXPORT_MAP := rte_ethdev_version.map -LIBABIVER := 10 +LIBABIVER := 11 SRCS-y += ethdev_private.c SRCS-y += rte_ethdev.c diff --git a/lib/librte_ethdev/meson.build b/lib/librte_ethdev/meson.build index 172e302f0..6783013fd 100644 --- a/lib/librte_ethdev/meson.build +++ b/lib/librte_ethdev/meson.build @@ -2,7 +2,7 @@ # Copyright(c) 2017 Intel Corporation name = 'ethdev' -version = 10 +version = 11 allow_experimental_apis = true sources = files('ethdev_private.c', 'ethdev_profile.c', diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 20100723d..a89da5c1b 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -802,87 +802,6 @@ eth_err(uint16_t port_id, int ret) return ret; } -/* attach the new device, then store port_id of the device */ -int -rte_eth_dev_attach(const char *devargs, uint16_t *port_id) -{ - int current = rte_eth_dev_count_total(); - struct rte_devargs da; - int ret = -1; - - memset(&da, 0, sizeof(da)); - - if ((devargs == NULL) || (port_id == NULL)) { - ret = -EINVAL; - goto err; - } - - /* parse devargs */ - if (rte_devargs_parse(&da, devargs)) - goto err; - - ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args); - if (ret < 0) - goto err; - - /* no point looking at the port count if no port exists */ - if (!rte_eth_dev_count_total()) { - RTE_ETHDEV_LOG(ERR, "No port found for device (%s)\n", da.name); - ret = -1; - goto err; - } - - /* if nothing happened, there is a bug here, since some driver told us - * it did attach a device, but did not create a port. - * FIXME: race condition in case of plug-out of another device - */ - if (current == rte_eth_dev_count_total()) { - ret = -1; - goto err; - } - - *port_id = eth_dev_last_created_port; - ret = 0; - -err: - free(da.args); - return ret; -} - -/* detach the device, then store the name of the device */ -int -rte_eth_dev_detach(uint16_t port_id, char *name __rte_unused) -{ - struct rte_device *dev; - struct rte_bus *bus; - uint32_t dev_flags; - int ret = -1; - - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -EINVAL); - - dev_flags = rte_eth_devices[port_id].data->dev_flags; - if (dev_flags & RTE_ETH_DEV_BONDED_SLAVE) { - RTE_ETHDEV_LOG(ERR, - "Port %"PRIu16" is bonded, cannot detach\n", port_id); - return -ENOTSUP; - } - - dev = rte_eth_devices[port_id].device; - if (dev == NULL) - return -EINVAL; - - bus = rte_bus_find_by_device(dev); - if (bus == NULL) - return -ENOENT; - - ret = rte_eal_hotplug_remove(bus->name, dev->name); - if (ret < 0) - return ret; - - rte_eth_dev_release_port(&rte_eth_devices[port_id]); - return 0; -} - static int rte_eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) { diff --git a/lib/librte_ethdev/rte_ethdev.h b/lib/librte_ethdev/rte_ethdev.h index 3c3684b63..d29cef73b 100644 --- a/lib/librte_ethdev/rte_ethdev.h +++ b/lib/librte_ethdev/rte_ethdev.h @@ -1499,37 +1499,6 @@ uint16_t rte_eth_dev_count_avail(void); */ uint16_t __rte_experimental rte_eth_dev_count_total(void); -/** - * Attach a new Ethernet device specified by arguments. - * - * @param devargs - * A pointer to a strings array describing the new device - * to be attached. The strings should be a pci address like - * '0000:01:00.0' or virtual device name like 'net_pcap0'. - * @param port_id - * A pointer to a port identifier actually attached. - * @return - * 0 on success and port_id is filled, negative on error - */ -__rte_deprecated -int rte_eth_dev_attach(const char *devargs, uint16_t *port_id); - -/** - * Detach a Ethernet device specified by port identifier. - * This function must be called when the device is in the - * closed state. - * - * @param port_id - * The port identifier of the device to detach. - * @param devname - * A pointer to a buffer that will be filled with the device name. - * This buffer must be at least RTE_DEV_NAME_MAX_LEN long. - * @return - * 0 on success and devname is filled, negative on error - */ -__rte_deprecated -int rte_eth_dev_detach(uint16_t port_id, char *devname); - /** * Convert a numerical speed in Mbps to a bitmap flag that can be used in * the bitmap link_speeds of the struct rte_eth_conf diff --git a/lib/librte_ethdev/rte_ethdev_version.map b/lib/librte_ethdev/rte_ethdev_version.map index 399380ad3..8038d4e5b 100644 --- a/lib/librte_ethdev/rte_ethdev_version.map +++ b/lib/librte_ethdev/rte_ethdev_version.map @@ -8,14 +8,12 @@ DPDK_2.2 { rte_eth_allmulticast_get; rte_eth_dev_allocate; rte_eth_dev_allocated; - rte_eth_dev_attach; rte_eth_dev_callback_register; rte_eth_dev_callback_unregister; rte_eth_dev_close; rte_eth_dev_configure; rte_eth_dev_count; rte_eth_dev_default_mac_addr_set; - rte_eth_dev_detach; rte_eth_dev_filter_supported; rte_eth_dev_flow_ctrl_get; rte_eth_dev_flow_ctrl_set; From patchwork Thu Oct 18 01:35:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47020 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 448761B16F; Thu, 18 Oct 2018 03:35:46 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 469D71B124 for ; Thu, 18 Oct 2018 03:35:28 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id E624421FC0; Wed, 17 Oct 2018 21:35:27 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=by+8TLXGnN iOF2UrINi46BHRCfJff6l+GBdMOf8e4E0=; b=ZAKmu5TFhGw8+x32sCMyqXl4np pYfzOstsm94lpSVZJ6050uasQBnc+8YsNLesiH78lB3CMvp3Rh4ZMnX7NCNzfnI4 k1lYoYMvC4yGZXvJ8odoLu/ytu7/lGgSJZAdAKJ09oqhYLVX+i1alY/iX+lqVMRm oz0ZAgSuvA01ZLjf4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=by+8TLXGnNiOF2UrINi46BHRCfJff6l+GBdMOf8e4E0=; b=SdSLw68m G+9qi003NgQR89Di9E8IsJ3ITrdTOvDLNu3Td0fsQS1ZeI1bcsW4nb3IM2liPhoP q0zdJIvDA0MrIBNRp3xh4R29F5xABSJU3tt0b/q3UavrqksQ9QHgd9wrKLZbRfI1 BUaPXInuzBD7EXJHmIQxeldcsV6CZZr1vRwyUUBrtSHEqM/D2cPGNlaU4Py4eACn uACSoSV8nJ2VPLUvFB5AZNVUff1YvONnoUmx9ff5z6INkYxOZcjnjjnZHU2rnvsg WhXitR6O4DXxvSLiGJSCHxkYwhy2RTn1pOAqrUmgTWp9i+56oOWe4gfbMI6i8pHE 6IcmlZ2RKoUZEA== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id C40D3E4893; Wed, 17 Oct 2018 21:35:26 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:21 +0200 Message-Id: <20181018013522.11253-7-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 6/7] eal: remove deprecated attach/detach functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" These hotplug functions were deprecated and have some new replacements. As announced earlier, the oldest ones are now removed. Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- doc/guides/rel_notes/deprecation.rst | 5 --- doc/guides/rel_notes/release_18_11.rst | 6 +++ lib/librte_eal/common/eal_common_dev.c | 53 ------------------------- lib/librte_eal/common/include/rte_dev.h | 27 ------------- lib/librte_eal/rte_eal_version.map | 2 - 5 files changed, 6 insertions(+), 87 deletions(-) diff --git a/doc/guides/rel_notes/deprecation.rst b/doc/guides/rel_notes/deprecation.rst index 6b51c9d28..34b28234c 100644 --- a/doc/guides/rel_notes/deprecation.rst +++ b/doc/guides/rel_notes/deprecation.rst @@ -49,11 +49,6 @@ Deprecation Notices Target release for removal of the legacy API will be defined once most PMDs have switched to rte_flow. -* eal: In v18.11 ``rte_eal_dev_attach()`` and ``rte_eal_dev_detach()`` - will be removed. - Hotplug functions ``rte_eal_hotplug_add()`` and ``rte_eal_hotplug_remove()`` - should be used directly. - * pdump: As we changed to use generic IPC, some changes in APIs and structure are expected in subsequent release. diff --git a/doc/guides/rel_notes/release_18_11.rst b/doc/guides/rel_notes/release_18_11.rst index 45fb88449..fabae3696 100644 --- a/doc/guides/rel_notes/release_18_11.rst +++ b/doc/guides/rel_notes/release_18_11.rst @@ -206,6 +206,12 @@ API Changes * eal: The parameters of the function ``rte_devargs_remove()`` have changed from bus and device names to ``struct rte_devargs``. +* eal: The deprecated functions attach/detach were removed in 18.11. + ``rte_eal_dev_attach`` can be replaced by + ``rte_dev_probe`` or ``rte_eal_hotplug_add``. + ``rte_eal_dev_detach`` can be replaced by + ``rte_dev_remove`` or ``rte_eal_hotplug_remove``. + * eal: The scope of ``rte_eal_hotplug_add()``/``rte_dev_probe()`` and ``rte_eal_hotplug_remove()``/``rte_dev_remove()`` is extended. In multi-process model, they will guarantee that the device is diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 8b0844af1..ad59f26cd 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -83,59 +83,6 @@ rte_dev_is_probed(const struct rte_device *dev) return dev->driver != NULL; } -int rte_eal_dev_attach(const char *name, const char *devargs) -{ - struct rte_bus *bus; - - if (name == NULL || devargs == NULL) { - RTE_LOG(ERR, EAL, "Invalid device or arguments provided\n"); - return -EINVAL; - } - - bus = rte_bus_find_by_device_name(name); - if (bus == NULL) { - RTE_LOG(ERR, EAL, "Unable to find a bus for the device '%s'\n", - name); - return -EINVAL; - } - if (strcmp(bus->name, "pci") == 0 || strcmp(bus->name, "vdev") == 0) - return rte_eal_hotplug_add(bus->name, name, devargs); - - RTE_LOG(ERR, EAL, - "Device attach is only supported for PCI and vdev devices.\n"); - - return -ENOTSUP; -} - -int rte_eal_dev_detach(struct rte_device *dev) -{ - struct rte_bus *bus; - int ret; - - if (dev == NULL) { - RTE_LOG(ERR, EAL, "Invalid device provided.\n"); - return -EINVAL; - } - - bus = rte_bus_find_by_device(dev); - if (bus == NULL) { - RTE_LOG(ERR, EAL, "Cannot find bus for device (%s)\n", - dev->name); - return -EINVAL; - } - - if (bus->unplug == NULL) { - RTE_LOG(ERR, EAL, "Bus function not supported\n"); - return -ENOTSUP; - } - - ret = bus->unplug(dev); - if (ret) - RTE_LOG(ERR, EAL, "Driver cannot detach the device (%s)\n", - dev->name); - return ret; -} - /* helper function to build devargs, caller should free the memory */ static int build_devargs(const char *busname, const char *devname, diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 4e549e802..cd6c187cc 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -176,33 +176,6 @@ struct rte_device { __rte_experimental int rte_dev_is_probed(const struct rte_device *dev); -/** - * Attach a device to a registered driver. - * - * @param name - * The device name, that refers to a pci device (or some private - * way of designating a vdev device). Based on this device name, eal - * will identify a driver capable of handling it and pass it to the - * driver probing function. - * @param devargs - * Device arguments to be passed to the driver. - * @return - * 0 on success, negative on error. - */ -__rte_deprecated -int rte_eal_dev_attach(const char *name, const char *devargs); - -/** - * Detach a device from its driver. - * - * @param dev - * A pointer to a rte_device structure. - * @return - * 0 on success, negative on error. - */ -__rte_deprecated -int rte_eal_dev_detach(struct rte_device *dev); - /** * Hotplug add a given device to a specific bus. * diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 08e3bc268..32fe2ba40 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -130,8 +130,6 @@ DPDK_16.11 { rte_delay_us_block; rte_delay_us_callback_register; - rte_eal_dev_attach; - rte_eal_dev_detach; } DPDK_16.07; From patchwork Thu Oct 18 01:35:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 47021 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 0CEEE1B17C; Thu, 18 Oct 2018 03:35:48 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id E10581B101 for ; Thu, 18 Oct 2018 03:35:29 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B2CBA21DB2; Wed, 17 Oct 2018 21:35:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 17 Oct 2018 21:35:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=D9Ihj3EnPt ovhk89ZPPtoi+Cda+qhiSumBUHE1u8nHo=; b=OKEhWNcsYTGjMa74kUydNcLPP6 vPjVFLeZS/lk7zyXXyQ/lYWcI8+DGUuOaFxamxVLffi+OlbJRr2NRS58s+PsbVRz qNJYOLSYKfB3tHl5fL8DOdQCjWLZpWswlzZMDWLhvPBJfeZ20rSVd1Cky0wrkH/p ED9ZfWrscByx8uQ24= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=D9Ihj3EnPtovhk89ZPPtoi+Cda+qhiSumBUHE1u8nHo=; b=dWRhBx4o jARjLk3vXEF7RJ/BpO1EDRthk5Yz+bIcJdF9I2WzpbRBT3iEWcXZ5nYrq7rUR1Lx LlUutfIf82nK9Y3ObrzAUQPhu+v6R6H0MHf+3nEIjYB+Vd1EdgKSy/A4zVCGG5UY 2n0to6xlIp8sDSsERlO+I7lYDNaaB3P6ZEfAVC41qUdKA5x0vNwrGR9xOt7Qbqdn scNSAuedg5IKlApW915HgBu+D1Fli+Kgk5Ew+Ft7turn3LqSIAyBI19YaF9xqeHR giWZhnKRPDz+a2Mvuxc572hYJxxHjaoQU8m9qtep66tqaY8Is2pTlUS5sB3bd/bY BTZA8iFr+QzrWg== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id AE1EAE4240; Wed, 17 Oct 2018 21:35:27 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, wisamm@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com Date: Thu, 18 Oct 2018 03:35:22 +0200 Message-Id: <20181018013522.11253-8-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181018013522.11253-1-thomas@monjalon.net> References: <20181007222554.4886-1-thomas@monjalon.net> <20181018013522.11253-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v5 7/7] app/testpmd: check not detaching device twice X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The command "port detach" is removing the EAL rte_device of the ethdev port specified as parameter. After detaching, the pointer, which maps a port to its device, is resetted. This way, it is possible to check whether a port is still associated to a (not removed) device. Signed-off-by: Thomas Monjalon --- app/test-pmd/testpmd.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index f241ce363..3093d3306 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -2340,8 +2340,17 @@ setup_attached_port(portid_t pi) void detach_port(portid_t port_id) { + struct rte_device *dev; + portid_t sibling; + printf("Detaching a port...\n"); + dev = rte_eth_devices[port_id].device; + if (dev == NULL) { + printf("Device already removed\n"); + return; + } + if (ports[port_id].port_status != RTE_PORT_CLOSED) { if (ports[port_id].port_status != RTE_PORT_STOPPED) { printf("Port not stopped\n"); @@ -2352,10 +2361,14 @@ detach_port(portid_t port_id) port_flow_flush(port_id); } - if (rte_dev_remove(rte_eth_devices[port_id].device) != 0) { + if (rte_dev_remove(dev) != 0) { TESTPMD_LOG(ERR, "Failed to detach port %u\n", port_id); return; } + /* reset mapping between old ports and removed device */ + for (sibling = 0; sibling < RTE_MAX_ETHPORTS; sibling++) + if (rte_eth_devices[sibling].device == dev) + rte_eth_devices[sibling].device = NULL; remove_unused_fwd_ports();