From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pd0-f173.google.com (mail-pd0-f173.google.com [209.85.192.173]) by dpdk.org (Postfix) with ESMTP id 3CD36B4FA for ; Fri, 20 Feb 2015 07:40:22 +0100 (CET) Received: by pdjg10 with SMTP id g10so5610575pdj.1 for ; Thu, 19 Feb 2015 22:40:21 -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=sJKd5FN3Oyq5Ljjpix4/DD/raVaGqYh38EeTAxbHYgo=; b=EDe5H0w52VSBdycwUAaLO+P5OTLvfyBLVtkUzSkvV8nrseMlzK3hSyKVKfo/K+2zqc 5cRmK6HzPTFEVl9mB8IhxPxIDlufYXdpsFVynsZdWGcwjyj/zK/0X8fpEWri9MzAxTgu MwRpwJELrBM3CFw5RMWyFDex0ZXY2NTmv14tNUsmVsKb0HTeIbkiZ2+o9IqmT3XTWKo6 ARvHur6FPgP5QyciCe24D0p+jeEX/XOUkipYNUuPdY1joVieIO1E21peiE1XQsku7qO1 Ek/NZxc++1ujwTRFAaeSTmI+bmI82ewKs8w0eaqfI9VX8rUyCRMaFnNdMLzOAIPlm0a7 hV7Q== X-Gm-Message-State: ALoCoQnLxSwvUSxScbJLIAuqHhAqk4LfgOHM8TU8L3TPNE8AOek7GSoyrTD+XF7h+cMit38x9irZ X-Received: by 10.66.149.106 with SMTP id tz10mr14285850pab.90.1424414421683; Thu, 19 Feb 2015 22:40:21 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by mx.google.com with ESMTPSA id g7sm13769979pdm.4.2015.02.19.22.40.19 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Feb 2015 22:40:20 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org Date: Fri, 20 Feb 2015 15:39:44 +0900 Message-Id: <1424414390-18509-11-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1424414390-18509-1-git-send-email-mukawa@igel.co.jp> References: <1424060073-23484-2-git-send-email-mukawa@igel.co.jp> <1424414390-18509-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v10 10/14] eal/pci: Add a function to remove the entry of devargs list 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: Fri, 20 Feb 2015 06:40:22 -0000 The function removes the specified devargs entry from devargs_list. Also, the patch adds sanity checking to rte_eal_devargs_add(). v5: - Change function definition of rte_eal_devargs_remove(). v4: - Fix sanity check code. Signed-off-by: Tetsuya Mukawa --- lib/librte_eal/common/eal_common_devargs.c | 61 +++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_devargs.h | 21 ++++++++++ 2 files changed, 82 insertions(+) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 3aace08..06954c3 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -44,6 +44,36 @@ struct rte_devargs_list devargs_list = TAILQ_HEAD_INITIALIZER(devargs_list); + +/* find a entry specified by pci address or device name */ +static struct rte_devargs * +rte_eal_devargs_find(enum rte_devtype devtype, void *args) +{ + struct rte_devargs *devargs; + + if (args == NULL) + return NULL; + + TAILQ_FOREACH(devargs, &devargs_list, next) { + switch (devtype) { + case RTE_DEVTYPE_WHITELISTED_PCI: + case RTE_DEVTYPE_BLACKLISTED_PCI: + if (rte_eal_compare_pci_addr( + &devargs->pci.addr, args) == 0) + goto found; + break; + case RTE_DEVTYPE_VIRTUAL: + if (memcmp(&devargs->virtual.drv_name, args, + strlen((char *)args)) == 0) + goto found; + break; + } + } + return NULL; +found: + return devargs; +} + /* store a whitelist parameter for later parsing */ int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) @@ -88,6 +118,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) RTE_LOG(ERR, EAL, "invalid PCI identifier <%s>\n", buf); goto fail; } + /* make sure there is no same entry */ + if (rte_eal_devargs_find(devtype, &devargs->pci.addr)) { + RTE_LOG(ERR, EAL, + "device already registered: <%s>\n", buf); + return -1; + } break; case RTE_DEVTYPE_VIRTUAL: /* save driver name */ @@ -97,6 +133,12 @@ rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str) RTE_LOG(ERR, EAL, "driver name too large: <%s>\n", buf); goto fail; } + /* make sure there is no same entry */ + if (rte_eal_devargs_find(devtype, &devargs->virtual.drv_name)) { + RTE_LOG(ERR, EAL, + "device already registered: <%s>\n", buf); + return -1; + } break; } @@ -114,6 +156,25 @@ fail: return -1; } +/* remove it from the devargs_list */ +int +rte_eal_devargs_remove(enum rte_devtype devtype, void *args) +{ + struct rte_devargs *devargs; + + if (args == NULL) + return -EINVAL; + + devargs = rte_eal_devargs_find(devtype, args); + if (devargs == NULL) { + RTE_LOG(ERR, EAL, "device not found\n"); + return -ENODEV; + } + + TAILQ_REMOVE(&devargs_list, devargs, next); + return 0; +} + /* count the number of devices of a specified type */ unsigned int rte_eal_devargs_type_count(enum rte_devtype devtype) diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 996e180..abfa3b1 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -123,6 +123,27 @@ extern struct rte_devargs_list devargs_list; int rte_eal_devargs_add(enum rte_devtype devtype, const char *devargs_str); /** + * Remove a device from the user device list + * + * For PCI devices, the format of arguments string is "PCI_ADDR". It shouldn't + * involve parameters for the device. Example: "08:00.1". + * + * For virtual devices, the format of arguments string is "DRIVER_NAME*". It + * shouldn't involve parameters for the device. Example: "eth_ring". The + * validity of the driver name is not checked by this function, it is done + * when closing the drivers. + * + * @param devtype + * The type of the device. + * @param name + * The name of the device. + * + * @return + * - 0 on success, negative on error + */ +int rte_eal_devargs_remove(enum rte_devtype devtype, void *args); + +/** * Count the number of user devices of a specified type * * @param devtype -- 1.9.1