From patchwork Tue Jun 26 16:56:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41587 X-Patchwork-Delegate: thomas@monjalon.net 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 259B81BDEB; Tue, 26 Jun 2018 18:56:51 +0200 (CEST) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id 4C6331BDDE for ; Tue, 26 Jun 2018 18:56:48 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id e18-v6so17976170wrs.5 for ; Tue, 26 Jun 2018 09:56:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=cmYNR272NrQQU/ClBRXU0Ogls9o1jmYrTFobQ2Nviak=; b=SWez8MWLh0tz0mGbhXDziXLjVEJ2yiGkXaLyx3hMHGNwIIVXz/TdhY4EOwUq2FYsDg L0GFWoDEjYmjAyXCRo12hjI2+PdykE7WtNw8S9g/S0aySQOtaJcW7xYeOrhBNCLR/7Oe tSV7BxqSO+yFHZ79A4CnYjmhUYTXlQ0GJRIdpyPRj6ETWkfCm9ibcdfflHyWPRPq+soE hDQvO+LWs/NFFZbYSXLEa8X1FbPxe+xrUyizG+IY2IOt7aflDi4c3Ea38S+XoKG2+ZHV N9J8M6WRwTgEZUauVN4v1w3+UaYP08VpTcx9EZpBP+puxjAhlXUr328pCAAz0JcoEdbB w1kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=cmYNR272NrQQU/ClBRXU0Ogls9o1jmYrTFobQ2Nviak=; b=j+MYE81qbPCeNbTCz0EuLrSSiiFh5CgoKmt3sklYJui2UsG1U5XSkXhryPhEA5UbJx YgydKnwiW+EMgYaRH6/pdUpKiwJXsy7bxcNjOvZuREPBhK+npIQwtrYXX9oTN8aRCnpO uE9NY0VMqX5aHQWGLuvcfGN8YxIQPLdjLbH+UyvbNIkGMMpaJvSoS4tAMxqOhUA98Ahp C0QX8Aooo/78DJczcrUh7g7iNjPWGRt2dEna8plyhe7j94teCUzgYALdcSYUYmPABLBE kSOge1goNh9qfQV04eyEQr6cp4v49mv41e21t4o/NA8AORiXDdVcjl7/AF1U6OqKBjaP hhqg== X-Gm-Message-State: APt69E0xSJNsDMlWTMW2xIYDcpiTnt9JVVmBN3O1y5Jiwj3wpcNWsnY6 rLJGi4YuoFnCODdMTJubXlSMcDUX X-Google-Smtp-Source: AAOMgpcUNzI5xiTCYhwWegA62ixZrHIcXIiO4EVi4Ph44nbq7A3Koqrb0u4V0jGP5Pf0nQ+w+pHRRA== X-Received: by 2002:adf:a963:: with SMTP id u90-v6mr986862wrc.248.1530032207509; Tue, 26 Jun 2018 09:56:47 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:46 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:04 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 01/21] devargs: add non-variadic parsing function 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" rte_devargs_parse becomes non-variadic, rte_devargs_parsef becomes the variadic version, to be used to compose device strings. Signed-off-by: Gaetan Rivet --- drivers/net/failsafe/failsafe_args.c | 2 +- drivers/net/failsafe/failsafe_eal.c | 2 +- lib/librte_eal/common/eal_common_dev.c | 4 +-- lib/librte_eal/common/eal_common_devargs.c | 42 ++++++++++++++++++++++------- lib/librte_eal/common/include/rte_devargs.h | 40 +++++++++++++++++++++++++-- lib/librte_eal/rte_eal_version.map | 1 + lib/librte_ethdev/rte_ethdev.c | 2 +- 7 files changed, 76 insertions(+), 17 deletions(-) diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c index 2c002b164..626883ce2 100644 --- a/drivers/net/failsafe/failsafe_args.c +++ b/drivers/net/failsafe/failsafe_args.c @@ -63,7 +63,7 @@ fs_parse_device(struct sub_device *sdev, char *args) d = &sdev->devargs; DEBUG("%s", args); - ret = rte_devargs_parse(d, "%s", args); + ret = rte_devargs_parse(d, args); if (ret) { DEBUG("devargs parsing failed with code %d", ret); return ret; diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c index 5672f3961..ce1633f13 100644 --- a/drivers/net/failsafe/failsafe_eal.c +++ b/drivers/net/failsafe/failsafe_eal.c @@ -86,7 +86,7 @@ fs_bus_init(struct rte_eth_dev *dev) else snprintf(devstr, sizeof(devstr), "%s", rte_eth_devices[pid].device->name); - ret = rte_devargs_parse(da, "%s", devstr); + ret = rte_devargs_parse(da, devstr); if (ret) { ERROR("Probed devargs parsing failed with code" " %d", ret); diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 61cb3b162..ce4b51469 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -138,8 +138,8 @@ int __rte_experimental rte_eal_hotplug_add(const char *busname, const char *devn if (da == NULL) return -ENOMEM; - ret = rte_devargs_parse(da, "%s:%s,%s", - busname, devname, devargs); + ret = rte_devargs_parsef(da, "%s:%s,%s", + busname, devname, devargs); if (ret) goto err_devarg; diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index b0434158b..0a83beb94 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -62,24 +62,18 @@ bus_name_cmp(const struct rte_bus *bus, const void *name) return strncmp(bus->name, name, strlen(bus->name)); } -int __rte_experimental -rte_devargs_parse(struct rte_devargs *da, const char *format, ...) +__rte_experimental +int +rte_devargs_parse(struct rte_devargs *da, const char *dev) { struct rte_bus *bus = NULL; - va_list ap; - va_start(ap, format); - char dev[vsnprintf(NULL, 0, format, ap) + 1]; const char *devname; const size_t maxlen = sizeof(da->name); size_t i; - va_end(ap); if (da == NULL) return -EINVAL; - va_start(ap, format); - vsnprintf(dev, sizeof(dev), format, ap); - va_end(ap); /* Retrieve eventual bus info */ do { devname = dev; @@ -124,6 +118,34 @@ rte_devargs_parse(struct rte_devargs *da, const char *format, ...) return 0; } +__rte_experimental +int +rte_devargs_parsef(struct rte_devargs *da, const char *format, ...) +{ + va_list ap; + size_t len; + char *dev; + + if (da == NULL) + return -EINVAL; + + va_start(ap, format); + len = vsnprintf(NULL, 0, format, ap); + va_end(ap); + + dev = calloc(1, len + 1); + if (dev == NULL) { + fprintf(stderr, "ERROR: not enough memory to parse device\n"); + return -ENOMEM; + } + + va_start(ap, format); + vsnprintf(dev, len, format, ap); + va_end(ap); + + return rte_devargs_parse(da, dev); +} + int __rte_experimental rte_devargs_insert(struct rte_devargs *da) { @@ -150,7 +172,7 @@ rte_devargs_add(enum rte_devtype devtype, const char *devargs_str) if (devargs == NULL) goto fail; - if (rte_devargs_parse(devargs, "%s", dev)) + if (rte_devargs_parse(devargs, dev)) goto fail; devargs->type = devtype; bus = devargs->bus; diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 58fbd90a2..6c3b6326b 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -96,6 +96,42 @@ int rte_eal_parse_devargs_str(const char *devargs_str, * in argument. Store which bus will handle the device, its name * and the eventual device parameters. * + * The syntax is: + * + * bus:device_identifier,arg1=val1,arg2=val2 + * + * where "bus:" is the bus name followed by any character separator. + * The bus name is optional. If no bus name is specified, each bus + * will attempt to recognize the device identifier. The first one + * to succeed will be used. + * + * Examples: + * + * pci:0000:05.00.0,arg=val + * 05.00.0,arg=val + * vdev:net_ring0 + * + * @param da + * The devargs structure holding the device information. + * + * @param dev + * String describing a device. + * + * @return + * - 0 on success. + * - Negative errno on error. + */ +__rte_experimental +int +rte_devargs_parse(struct rte_devargs *da, const char *dev); + +/** + * Parse a device string. + * + * Verify that a bus is capable of handling the device passed + * in argument. Store which bus will handle the device, its name + * and the eventual device parameters. + * * The device string is built with a printf-like syntax. * * The syntax is: @@ -124,8 +160,8 @@ int rte_eal_parse_devargs_str(const char *devargs_str, */ __rte_experimental int -rte_devargs_parse(struct rte_devargs *da, - const char *format, ...) +rte_devargs_parsef(struct rte_devargs *da, + const char *format, ...) __attribute__((format(printf, 2, 0))); /** diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index f7dd0e7bc..1c4db72fa 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -254,6 +254,7 @@ EXPERIMENTAL { rte_devargs_insert; rte_devargs_next; rte_devargs_parse; + rte_devargs_parsef; rte_devargs_remove; rte_devargs_type_count; rte_eal_cleanup; diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index a9977df97..cce20d9ae 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -654,7 +654,7 @@ rte_eth_dev_attach(const char *devargs, uint16_t *port_id) } /* parse devargs */ - if (rte_devargs_parse(&da, "%s", devargs)) + if (rte_devargs_parse(&da, devargs)) goto err; ret = rte_eal_hotplug_add(da.bus->name, da.name, da.args); From patchwork Tue Jun 26 16:56:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41588 X-Patchwork-Delegate: thomas@monjalon.net 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 4D43E1BDF4; Tue, 26 Jun 2018 18:56:53 +0200 (CEST) Received: from mail-wr0-f171.google.com (mail-wr0-f171.google.com [209.85.128.171]) by dpdk.org (Postfix) with ESMTP id D6B2C1BDE8 for ; Tue, 26 Jun 2018 18:56:49 +0200 (CEST) Received: by mail-wr0-f171.google.com with SMTP id a12-v6so17991710wro.1 for ; Tue, 26 Jun 2018 09:56:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Sxhmophs5PVz/xsld34wfEMmtmHs37kn7M6i/VqwFqg=; b=0apWkXi70gu686sapQru4h0bGiB87dxk8TpeNvezDS0g5H2fGnFTK03pbz82OaBy6U Xbl9eZ/8NZ5czTE20YRsmOVzzuUnIIX8qnqy+6OYKbZ62QL68zyDxyRcZ2jgKp9k4g9o UsIvRu5niDK2kesFr09y8cev/YpTkbz9itabd5PlMxUoKqkP21EzxzHHs6O+fturjq/N +eHCI+SuZ3x22REElfZMhC5n6Wx8qV9zgei4mUwhFESPimbZjQWw220xHnbqmwmwr4KI dEiakaH1RGCEK5Rkm0v+dZ1cneX6SNHBx/oKs06B3zlpwsTSnXLwlBwvRrVfmg/VIQIL LLCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Sxhmophs5PVz/xsld34wfEMmtmHs37kn7M6i/VqwFqg=; b=CBvwsslQ4Dysw7hcA5yWZmtHRtbaIcLMMP5RgFv78YO+MSkNuUL+0U7+f6RAOJpUnF SIFQy1TXfknZI9sxdNzOpqR2AiPV5ei3Dcz8HuLCYh999KH9FnCFpEIe28JybOdi9rUe g4+PS9Zkbpnht/WuEPOO24N2EriF0sfADEMxeXYePouBRQhQJ/5EHQsTNsWGSkKM69jJ AaWg0+g65SRUTIvArElapJJprJYdMHIroFOvCb4KQMghUo7PPxKDrlwHAp5LxNxUXVJV EefIorhdwp69WaNtmQJyXiYIFMv0mfcQFa8B6ebYjzaD8UlDP8rKADgZVK/D8nvu8p9T 2KQg== X-Gm-Message-State: APt69E2HFgKANunP1HwdqKJ8gzxuFkQ/YsDcP7P95c5E2S4RDnAMgkJ2 M3PRKXrI0T1vEE3SYY926idO4W4k X-Google-Smtp-Source: AAOMgpfYWNcP5z6uraEs9naYXnTKu5h1dZbKCT4kBSpvFEdmKb8hF8miRgUim15lw1KYKZmDYHtrRA== X-Received: by 2002:adf:8877:: with SMTP id e52-v6mr2342719wre.30.1530032209156; Tue, 26 Jun 2018 09:56:49 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:47 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:05 +0200 Message-Id: <2b4e8b141af3441110df81dc52e616263ed44d98.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 02/21] kvargs: build before EAL 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" Signed-off-by: Gaetan Rivet --- lib/Makefile | 3 +-- lib/librte_kvargs/Makefile | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index d82462ba2..e8e903c8f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -4,6 +4,7 @@ include $(RTE_SDK)/mk/rte.vars.mk DIRS-y += librte_compat +DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal DIRS-$(CONFIG_RTE_LIBRTE_PCI) += librte_pci DEPDIRS-librte_pci := librte_eal @@ -76,8 +77,6 @@ DEPDIRS-librte_flow_classify := librte_net librte_table librte_acl DIRS-$(CONFIG_RTE_LIBRTE_SCHED) += librte_sched DEPDIRS-librte_sched := librte_eal librte_mempool librte_mbuf librte_net DEPDIRS-librte_sched += librte_timer -DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs -DEPDIRS-librte_kvargs := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_DISTRIBUTOR) += librte_distributor DEPDIRS-librte_distributor := librte_eal librte_mbuf librte_ethdev DIRS-$(CONFIG_RTE_LIBRTE_PORT) += librte_port diff --git a/lib/librte_kvargs/Makefile b/lib/librte_kvargs/Makefile index 39d5ac33d..875939547 100644 --- a/lib/librte_kvargs/Makefile +++ b/lib/librte_kvargs/Makefile @@ -7,7 +7,7 @@ include $(RTE_SDK)/mk/rte.vars.mk LIB = librte_kvargs.a CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -LDLIBS += -lrte_eal +CFLAGS += -I$(RTE_SDK)/lib/librte_eal/common/include EXPORT_MAP := rte_kvargs_version.map From patchwork Tue Jun 26 16:56:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41589 X-Patchwork-Delegate: thomas@monjalon.net 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 EEF5A1BDFD; Tue, 26 Jun 2018 18:56:54 +0200 (CEST) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id C97101BDEF for ; Tue, 26 Jun 2018 18:56:51 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id p1-v6so2378957wrs.9 for ; Tue, 26 Jun 2018 09:56:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=4Pp1SBn6FM9HL5D1utQNkIos2CC45rmcLx9EwDEf7Ls=; b=zCmXOR/u7ZOLt0cNDyvDVwjsd5d+E4g4iGOTA2ADA0L+VRGAB9UQw1nAlphGw/8/Qr YNvDeWVNW9w0PZxmI5AYQiGm79I5LvSuC+QkuKTgF6V9L+y2DDSC/fEqDIi2oQgCrMpF vnu1O8vJ19RNMWcyqpKKt91WOqVD52CHbvkQcOOTayQx2sHmBQNc6aJyoxrFs754LlnI s2aoeL5Jj60CcD46Tbj/GMAZLZgDjjNMsye3ErfPk3tkpIMvCm0iRa1BPKjQRKXcoD7U v6PHYVwmzgzx+WXvxrj0ze49Jye4mQyS7VBxXnSfjmSO7PF1QxeSd+5hoaHGaWrctL9C lWoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=4Pp1SBn6FM9HL5D1utQNkIos2CC45rmcLx9EwDEf7Ls=; b=TFnk4v9QVo/NhOCs3RH/Dne9wWjvSJkqZVF8FvN7qblMovaRhoI47LtiFQl6E0ScIJ Hgii+2106SYKub1Z0NsDN6kH7f01UJn8u81W/sfiatqOPQNNJNzVB3E0JtrXh8Aa/r+1 18avP67LTuoab6UH7Fa2Jc0FvtA7VIPBJ+Jrx8bL01ar/+urERcYu9gAoCiHdduxtvTb vP82+syH6DfxZiFGxvxCdOFOf2Vs/sLfLDW55eSe3+tXb9ciMOppbgodVM7mQ6wEVoqT Xj99eUHFc86XgVYuenERQj3nJu5DS4/RUqVwu8tuGnBpnXWtsuXXO/9U0XJ1XbhqJ5PA 0nbg== X-Gm-Message-State: APt69E106BA1N3NhzVzuf8xdJSeKz0ul7b5nl/bDJ7hOslUKTZowtOxt IEZ1Xt9SaQu1+vrbcsUmKiNiNZAR X-Google-Smtp-Source: AAOMgpcBO3LksjaFmj83jENmQ+vSV8ND+IDz7IeVJEcIHcaVRnhHEsgxgQ9Q3Q4bjJ1mmRDE4D/QZg== X-Received: by 2002:adf:e987:: with SMTP id h7-v6mr2182862wrm.102.1530032210767; Tue, 26 Jun 2018 09:56:50 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:49 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:06 +0200 Message-Id: <5eb09a42ed1bba9cb47960a759823f8130f39e24.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 03/21] kvargs: introduce a more flexible parsing function 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" This function permits defining additional terminating characters, ending the parsing to arbitrary delimiters. Signed-off-by: Gaetan Rivet --- lib/Makefile | 1 + lib/librte_kvargs/rte_kvargs.c | 25 +++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs.h | 30 ++++++++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs_version.map | 7 +++++++ 4 files changed, 63 insertions(+) diff --git a/lib/Makefile b/lib/Makefile index e8e903c8f..8a65525cd 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,6 +5,7 @@ include $(RTE_SDK)/mk/rte.vars.mk DIRS-y += librte_compat DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs +DEPDIRS-librte_kvargs := librte_compat DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal DIRS-$(CONFIG_RTE_LIBRTE_PCI) += librte_pci DEPDIRS-librte_pci := librte_eal diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index d92a5f9dc..cfbee3bd9 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -180,3 +180,28 @@ rte_kvargs_parse(const char *args, const char * const valid_keys[]) return kvlist; } + +__rte_experimental +struct rte_kvargs * +rte_kvargs_parse2(const char *args, const char * const valid_keys[], + const char *valid_ends) +{ + struct rte_kvargs *kvlist = NULL; + char *copy; + size_t len; + + if (valid_ends == NULL) + return rte_kvargs_parse(args, valid_keys); + + copy = strdup(args); + if (copy == NULL) + return NULL; + + len = strcspn(copy, valid_ends); + copy[len] = '\0'; + + kvlist = rte_kvargs_parse(copy, valid_keys); + + free(copy); + return kvlist; +} diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h index 51b8120b8..defdf10e4 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -72,6 +72,36 @@ struct rte_kvargs *rte_kvargs_parse(const char *args, const char *const valid_keys[]); /** + * Allocate a rte_kvargs and store key/value associations from a string. + * This version will consider any byte from valid_ends as a possible + * terminating character, and will not parse beyond any of their occurence. + * + * The function allocates and fills an rte_kvargs structure from a given + * string whose format is key1=value1,key2=value2,... + * + * The structure can be freed with rte_kvargs_free(). + * + * @param args + * The input string containing the key/value associations + * + * @param valid_keys + * A list of valid keys (table of const char *, the last must be NULL). + * This argument is ignored if NULL + * + * @param valid_ends + * Acceptable terminating characters. + * If NULL, the behavior is the same as ``rte_kvargs_parse``. + * + * @return + * - A pointer to an allocated rte_kvargs structure on success + * - NULL on error + */ +__rte_experimental +struct rte_kvargs *rte_kvargs_parse2(const char *args, + const char *const valid_keys[], + const char *valid_ends); + +/** * Free a rte_kvargs structure * * Free a rte_kvargs structure previously allocated with diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map index 2030ec46c..b9fe44b98 100644 --- a/lib/librte_kvargs/rte_kvargs_version.map +++ b/lib/librte_kvargs/rte_kvargs_version.map @@ -8,3 +8,10 @@ DPDK_2.0 { local: *; }; + +EXPERIMENTAL { + global: + + rte_kvargs_parse2; + +} DPDK_2.0; From patchwork Tue Jun 26 16:56:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41590 X-Patchwork-Delegate: thomas@monjalon.net 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 DCCAE1BE04; Tue, 26 Jun 2018 18:56:56 +0200 (CEST) Received: from mail-wr0-f172.google.com (mail-wr0-f172.google.com [209.85.128.172]) by dpdk.org (Postfix) with ESMTP id A217E1BDF1 for ; Tue, 26 Jun 2018 18:56:52 +0200 (CEST) Received: by mail-wr0-f172.google.com with SMTP id c13-v6so8020126wrq.2 for ; Tue, 26 Jun 2018 09:56:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=kjK0X93uJ8qR12GsXLADuXLvB/fMaIlBtKWcJvWWVLY=; b=OM8spMOyE7QfVGZsyYrE0vrinBAa5l3Rbb45v3pCqoawStzP2MspeRz1+gNKSOXMI9 0dxQRKvpFLqvanVxhgHi4k3rpZ01yYlcm1CzMgtnl4rSJxmCbE4zSb7QEjW/E3d6vkS6 pQzxGDWrnUGIdpScEZvVKRN9EMV6bC/EnX+Ylh98lalKnQoO5lrzrcpFeoxfWwdB1voM oP1nhaF+LqhvoiyP/cabo1E5ecAEALsSnffDVwQ5Liel+8TtAplQsGysFDC1kFNgBBfb 3Rq/Qr3bp1lGRFIBm6rgRuR7L+r3+nLhUTq1mxLrdx2xuE7zAMGmVlCCjN82OalIoX53 R7LA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=kjK0X93uJ8qR12GsXLADuXLvB/fMaIlBtKWcJvWWVLY=; b=PLoJUJtoGJAlAVnTfsrgeApTYFbW0eB8UxCrozNfd41oIZEh8Y/XDPUugZLWqzP0/d ck+oVYqSNLbvUpYYbbO6dCzZxrbp5gRzOTyClOYLPprr5aEqRTTZVm0xU1mojQaDQpwN xhDuq9mxW3r7FdnZ9pVZ2uq6JztdbsBaOLn3JvYiT1uJFaakouDce5pDUBmx5KV/nyvn sU7VPSJeQhM8W+Mynw0SpL1a1UnZauYLhr+EEWOuFQV3XLVNjvC5qXsStpTWxI7YWdaM 6OzZmLADAZAy0aYuDAEbd7KZ3C1HsQOlEjE4sGyGGkU4tJRE8kEKVFEG/XXUQkReG8F8 lwIg== X-Gm-Message-State: APt69E3ll3DX3uhcgR5OWMTjhnEyxdd+PoVpr0cd13NSlxHULLV9SVE7 XpIJIJjCQ7qz6kre6/qjK/7DSCzP X-Google-Smtp-Source: AAOMgpcjFfQ5xZT4mp7tLdKzR0tuDYqlDH0n/YdQT4Oq+UuKVz1iPPzZiuFoU2UlH2lSYqXW9+0eQg== X-Received: by 2002:adf:df86:: with SMTP id z6-v6mr2139835wrl.113.1530032211938; Tue, 26 Jun 2018 09:56:51 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:51 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:07 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 04/21] eal: introduce dtor macros 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" Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_common.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 434adfd45..0dd832728 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -112,6 +112,29 @@ static void __attribute__((constructor(RTE_PRIO(prio)), used)) func(void) RTE_INIT_PRIO(func, LAST) /** + * Run after main() with low priority. + * + * @param func + * Destructor function name. + * @param prio + * Priority number must be above 100. + * Lowest number is the last to run. + */ +#define RTE_FINI_PRIO(func, prio) \ +static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) + +/** + * Run after main() with high priority. + * + * The destructor will be run *before* prioritized destructors. + * + * @param func + * Destructor function name. + */ +#define RTE_FINI(func) \ + RTE_FINI_PRIO(func, LAST) + +/** * Force a function to be inlined */ #define __rte_always_inline inline __attribute__((always_inline)) From patchwork Tue Jun 26 16:56:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41592 X-Patchwork-Delegate: thomas@monjalon.net 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 3A7741BE16; Tue, 26 Jun 2018 18:57:01 +0200 (CEST) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id A9AE31BE01 for ; Tue, 26 Jun 2018 18:56:55 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id k16-v6so17990798wro.0 for ; Tue, 26 Jun 2018 09:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:in-reply-to:references:content-transfer-encoding; bh=ySzzXmGMGcnSxjboLdxOcA2Xkn0pD9CSdoQ29+UPRDw=; b=tr6et1ge0pbJ0a29bQmX+ot+fw/kWMrJ+bHPA5Bo6qHwxaYlMjvLX7K0+Sfyrroxr0 mKNaobPX63vlOvXS0F5KvfW8yXBBuqltezuYOF88Y7HJh8wFj/nAlRouK3nnsR4bdXa4 Frk1U5IMjh23AIeYzF63MA8BA7RJWa3tbF59f2o8FsV6fOo6a0ajPW68LKc/p6yfp8Zq xNHmSYz4Df50vg66Mh3Xepm09VWDTF2nDo6p+beVHldE+9ASpQJxmZjLHBxiXmIFL0Zx nZqKFhO4O37qAkgV68BNvn1NV1rHBXh/EswoqYENt+F6N4NuLfwuABsmMgPW3jFDXzMX aVLA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:in-reply-to:references :content-transfer-encoding; bh=ySzzXmGMGcnSxjboLdxOcA2Xkn0pD9CSdoQ29+UPRDw=; b=ptI0PZlr4yDU0sRqcnHM6bc3KtBf8FbUihTFzGwYsjxSMgspKu+bGK6UNF0oq6Kq4/ BtAQewS/QKl0yhdGluRHO5G7hIVq53VkzcPteof84JEtqZh69tRbrKyXv3UcCVq8kPTv Ma3+HfQW1zbZiPsOL4vR/79PLIXA+Y2xsYgSNGba3WQjED1Vtxu9TLw5ntyyo9MP7Btg LETyemH+g4tk3+1qXLf4lsbISbrkMGy2w1yc81a2zaR4CQN4u/1aSMrb5rKjf4noDbdv L9E7/m0LcJbjas4KC3AWeuSGP8eqCT1PvQL11mDB3htS//si3j3zcY9Qk1UglMGE/dYb k4sA== X-Gm-Message-State: APt69E1JAnIfYVh5xK3erTsXvza0SImSx4sMFMr3nY6dKQlTj7P1dlui gXYbDcQApksu9ZRtKkBnJ2Cv0NXe X-Google-Smtp-Source: AAOMgpd6KJ6Xot+kl0km5ogE845666klulX8/fwd4UzmKNrh0Tq+eE2xgYsxvjrBZOgxQGMv3jfbhg== X-Received: by 2002:a5d:4a4d:: with SMTP id v13-v6mr2215713wrs.91.1530032213628; Tue, 26 Jun 2018 09:56:53 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:52 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:08 +0200 Message-Id: <51ec54f47a03ce6dcf79a44252383a8fe7bac863.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 05/21] eal: introduce device class abstraction 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" Signed-off-by: Gaetan Rivet --- lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/Makefile | 2 +- lib/librte_eal/common/eal_common_class.c | 62 +++++++++++++++ lib/librte_eal/common/include/rte_class.h | 121 +++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_common.h | 1 + lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/rte_eal_version.map | 2 + 7 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 lib/librte_eal/common/eal_common_class.c create mode 100644 lib/librte_eal/common/include/rte_class.h diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile index 3fd33f1e4..b0a1c880a 100644 --- a/lib/librte_eal/bsdapp/eal/Makefile +++ b/lib/librte_eal/bsdapp/eal/Makefile @@ -52,6 +52,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_hypervisor.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_string_fns.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_devargs.c +SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_class.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_bus.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_EXEC_ENV_BSDAPP) += eal_common_options.c diff --git a/lib/librte_eal/common/Makefile b/lib/librte_eal/common/Makefile index 48f870f24..750653093 100644 --- a/lib/librte_eal/common/Makefile +++ b/lib/librte_eal/common/Makefile @@ -11,7 +11,7 @@ INC += rte_per_lcore.h rte_random.h INC += rte_tailq.h rte_interrupts.h rte_alarm.h INC += rte_string_fns.h rte_version.h INC += rte_eal_memconfig.h rte_malloc_heap.h -INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h +INC += rte_hexdump.h rte_devargs.h rte_bus.h rte_dev.h rte_class.h INC += rte_pci_dev_feature_defs.h rte_pci_dev_features.h INC += rte_malloc.h rte_keepalive.h rte_time.h INC += rte_service.h rte_service_component.h diff --git a/lib/librte_eal/common/eal_common_class.c b/lib/librte_eal/common/eal_common_class.c new file mode 100644 index 000000000..aed4dd8fb --- /dev/null +++ b/lib/librte_eal/common/eal_common_class.c @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Gaëtan Rivet + */ + +#include +#include +#include + +#include +#include + +struct rte_class_list rte_class_list = + TAILQ_HEAD_INITIALIZER(rte_class_list); + +__rte_experimental void +rte_class_register(struct rte_class *class) +{ + RTE_VERIFY(class); + RTE_VERIFY(class->name && strlen(class->name)); + + TAILQ_INSERT_TAIL(&rte_class_list, class, next); + RTE_LOG(DEBUG, EAL, "Registered [%s] device class.\n", class->name); +} + +__rte_experimental void +rte_class_unregister(struct rte_class *class) +{ + TAILQ_REMOVE(&rte_class_list, class, next); + RTE_LOG(DEBUG, EAL, "Unregistered [%s] device class.\n", class->name); +} + +struct rte_class * +rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp, + const void *data) +{ + struct rte_class *cls; + + if (start != NULL) + cls = TAILQ_NEXT(start, next); + else + cls = TAILQ_FIRST(&rte_class_list); + while (cls != NULL) { + if (cmp(cls, data) == 0) + break; + cls = TAILQ_NEXT(cls, next); + } + return cls; +} + +static int +cmp_class_name(const struct rte_class *class, const void *_name) +{ + const char *name = _name; + + return strcmp(class->name, name); +} + +struct rte_class * +rte_class_find_by_name(const char *name) +{ + return rte_class_find(NULL, cmp_class_name, (const void *)name); +} diff --git a/lib/librte_eal/common/include/rte_class.h b/lib/librte_eal/common/include/rte_class.h new file mode 100644 index 000000000..b5e550a34 --- /dev/null +++ b/lib/librte_eal/common/include/rte_class.h @@ -0,0 +1,121 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Gaëtan Rivet + */ + +#ifndef _RTE_CLASS_H_ +#define _RTE_CLASS_H_ + +/** + * @file + * + * DPDK device class interface. + * + * This file exposes API and interfaces of device classes. + */ + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +#include + +/** Double linked list of classes */ +TAILQ_HEAD(rte_class_list, rte_class); + +/** + * A structure describing a generic device class. + */ +struct rte_class { + TAILQ_ENTRY(rte_class) next; /**< Next device class in linked list */ + const char *name; /**< Name of the class */ +}; + +/** + * Class comparison function. + * + * @param cls + * Class under test. + * + * @param data + * Data to compare against. + * + * @return + * 0 if the class matches the data. + * !0 if the class does not match. + * <0 if ordering is possible and the class is lower than the data. + * >0 if ordering is possible and the class is greater than the data. + */ +typedef int (*rte_class_cmp_t)(const struct rte_class *cls, const void *data); + +/** + * Class iterator to find a particular class. + * + * This function compares each registered class to find one that matches + * the data passed as parameter. + * + * If the comparison function returns zero this function will stop iterating + * over any more classes. To continue a search the class of a previous search + * can be passed via the start parameter. + * + * @param start + * Starting point for the iteration. + * + * @param cmp + * Comparison function. + * + * @param data + * Data to pass to comparison function. + * + * @return + * A pointer to a rte_class structure or NULL in case no class matches + */ +struct rte_class * +rte_class_find(const struct rte_class *start, rte_class_cmp_t cmp, + const void *data); + +/** + * Find the registered class for a given name. + */ +struct rte_class * +rte_class_find_by_name(const char *name); + +/** + * Register a Class handle. + * + * @param + * A pointer to a rte_class structure describing the class + * to be registered. + */ +__rte_experimental +void rte_class_register(struct rte_class *cls); + +/** + * Unregister a Class handle. + * + * @param class + * A pointer to a rte_class structure describing the class + * to be unregistered. + */ +__rte_experimental +void rte_class_unregister(struct rte_class *cls); + +/** + * Helper for Class registration. + * The constructor has lower priority than Bus constructors. + * The constructor has higher priority than PMD constructors. + */ +#define RTE_REGISTER_CLASS(nm, cls) \ +RTE_INIT_PRIO(classinitfn_ ##nm, CLASS); \ +static void classinitfn_ ##nm(void) \ +{\ + (cls).name = RTE_STR(nm);\ + rte_class_register(&cls); \ +} + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_CLASS_H_ */ diff --git a/lib/librte_eal/common/include/rte_common.h b/lib/librte_eal/common/include/rte_common.h index 0dd832728..a2e8e6e32 100644 --- a/lib/librte_eal/common/include/rte_common.h +++ b/lib/librte_eal/common/include/rte_common.h @@ -83,6 +83,7 @@ typedef uint16_t unaligned_uint16_t; #define RTE_PRIORITY_LOG 101 #define RTE_PRIORITY_BUS 110 +#define RTE_PRIORITY_CLASS 120 #define RTE_PRIORITY_LAST 65535 #define RTE_PRIO(prio) \ diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index 3719ec9d7..babc8617a 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -60,6 +60,7 @@ SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_hypervisor.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_string_fns.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_hexdump.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_devargs.c +SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_class.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_bus.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_dev.c SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += eal_common_options.c diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 1c4db72fa..19d36b4c7 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -244,6 +244,8 @@ DPDK_18.05 { EXPERIMENTAL { global: + rte_class_register; + rte_class_unregister; rte_ctrl_thread_create; rte_dev_event_callback_register; rte_dev_event_callback_unregister; From patchwork Tue Jun 26 16:56:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41591 X-Patchwork-Delegate: thomas@monjalon.net 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 0B90C1BE0D; Tue, 26 Jun 2018 18:56:59 +0200 (CEST) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by dpdk.org (Postfix) with ESMTP id 7B1851BE00 for ; Tue, 26 Jun 2018 18:56:55 +0200 (CEST) Received: by mail-wm0-f48.google.com with SMTP id l15-v6so15794231wmc.1 for ; Tue, 26 Jun 2018 09:56:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=28DRsv+QYAFHOkQRiCRQvubzBQLopqiLihNLEKJfEhQ=; b=R+paQGn6SqpX9XOmRNpktsGs/3hA9CkdBXQ9DiQU+1Ryc3BxgIRh1eONDf9yYeYwLj CPFwbeuLDnpi1JWIQ+Mwro/g8EkZ2e0pgqZfpTu8tKQiHF9UeThZA7v4t3yNdFYmPky+ fL4trfJDQ816oz0NuZwfJVT0P3P9tHG30qrqK+q352ErHb6Y5jcsefVt5AXSywskJgNw MaNtN6k6tpj2DGLS/M2Kj9Aqrlum/yDJMpx/AnNQYPqxyhVoavZsLSKyDlwuP8ju1ItP 5OYHxBpRQJKg82uvhUgGP/dR72TJLm/f5BlQJGnx9Itk5VmGVwxjPqUJ8XWH/iuOleJz +Z6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=28DRsv+QYAFHOkQRiCRQvubzBQLopqiLihNLEKJfEhQ=; b=C6nc2VD60VkfLVAQaMbL/bYWq4/cFtRfxEnowZnNtJ0OC3CJ7EMUqmfa2tlczaqUnL j8dp5p7g/Sthy29ZT1UttSCe9FrFnkKBOHJEdQl1IfIHfv+c/0WzDQdNUCIySpik/o/E knJ7/ytvMVxBgU39FISYvs6+RTh5q0Vjtmrwb2B5poW4LcZGSRxTR8DyCHplyLawGM5e cOtLw1aVjThF8iv5ok0mkRuJuw2VUiqyiwhlcDbjlKL1+QfSFKQmpFnS5gHPlFyL4h8N OLs4AO8UHc0yEgqx+790R5AK2P8HyFAE4HbVk+71TUCSTMJLNN/yeK67P/6asRuiXKPR L/SQ== X-Gm-Message-State: APt69E2ORy51zEOT5VhNmEWuXanin8+OWB8pa3fUbz2+lwa94H8y4pgV WTvIa5BoKfK5JNmS5XdHO4RF2ld0 X-Google-Smtp-Source: AAOMgpfpsZyZXS1RovbcBvwYTAPfkynBdPneW7qNgmZIrf4y56U+qWq8myfF9v2qntASauiRFej8uA== X-Received: by 2002:a1c:17d4:: with SMTP id 203-v6mr2233554wmx.75.1530032214753; Tue, 26 Jun 2018 09:56:54 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:53 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:09 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 06/21] eal/class: register destructor 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" Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_class.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/librte_eal/common/include/rte_class.h b/lib/librte_eal/common/include/rte_class.h index b5e550a34..e8176f5e1 100644 --- a/lib/librte_eal/common/include/rte_class.h +++ b/lib/librte_eal/common/include/rte_class.h @@ -112,6 +112,11 @@ static void classinitfn_ ##nm(void) \ {\ (cls).name = RTE_STR(nm);\ rte_class_register(&cls); \ +} \ +RTE_FINI_PRIO(classfinifn_ ##nm, CLASS); \ +static void classfinifn_ ##nm(void) \ +{ \ + rte_class_unregister(&cls); \ } #ifdef __cplusplus From patchwork Tue Jun 26 16:56:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41593 X-Patchwork-Delegate: thomas@monjalon.net 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 A3CBE1BE1D; Tue, 26 Jun 2018 18:57:03 +0200 (CEST) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 1B3891BE06 for ; Tue, 26 Jun 2018 18:56:57 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id e16-v6so2752065wmd.0 for ; Tue, 26 Jun 2018 09:56:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=JiGoqkJjNRKoNIo30pwQ3qEnkhOjDh/K3fTAwhD+xtQ=; b=DwGYK9Rng9uj/QPObjvpp8kt86m2lrUkaFB96bCH1r/yv+/S1pshJSDOHBavTFWiJC xaMewRsWTwcHENmXALs2wEa2L117tx2cruL55jZ9gvPXEqa6AwAXvtEfOsUK9fJpQrTv Wojcoh9Jx/XKAJDN1zawYdsD+OujcXaCb8hi9M49If3SUg/T/rJo7ex/DAiwe2tbM898 8ZxxvlaXPqjgBZ58aKj9bvcWQCBGMb+DRDCQBFcaEXMAYvODthAU4cTe5pmgEfeAWehR a22/AXb5AF9i4+hs8pdfN5Hkoy3oxF1tDRKN8ei+I2yxFgnFYQTRaJL50gkEy3zUfzu2 1lVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=JiGoqkJjNRKoNIo30pwQ3qEnkhOjDh/K3fTAwhD+xtQ=; b=m9mjNQ8qJ/cicGljgBzFZHcB5Vvbm52JF3TJGnvx+10V8XGQEPG2mOrWqNlXG5Y+s2 9sOST3qXFod604VnpC5pV4BpOhxpvH6jHhAUEPBjGArXR0fSbnzldkhW2o2GJ45B5QEp EXDkJjoILnm4D/MLLRUrE7XmOXMaaHIooEybel0Tht7j2P+HivaF5P2SUpfszvXMsUZC vz4UYckuDGJQW7Xcitd4AgZE+JSRRmPUJCafzSkNa3JjjgFwOWElUCWj44vbkgbvb98Z qkFLKlretiBeZvUkFs4bg7C2MaxCfOwJDd4mp5MGnToGIpgEH2r1hbAB2rhv/gJiQaqx Tj0Q== X-Gm-Message-State: APt69E12DpXhNTrz2ZfCd37CU08FKrgJEK4EQjkRI08WxoPvpKPUNhm6 TgxO8v0Jg8LtOmO9/RUl7NVCIw2e X-Google-Smtp-Source: AAOMgpd7pqogDp+2R6NlKKQhrYrvjkoZNBDTYCoMLQK7T/gWmqYWvYUO7shWrLKDpTbXdyWXiXLbJw== X-Received: by 2002:a1c:2489:: with SMTP id k131-v6mr2396501wmk.114.1530032216215; Tue, 26 Jun 2018 09:56:56 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:55 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:10 +0200 Message-Id: <0ce131421cf2386dec4393d848a15a365c9698d4.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 07/21] devargs: add function to parse device layers 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" This function is private to the EAL. It is used to parse each layers in a device description string, and store the result in an rte_devargs structure. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_devargs.c | 144 ++++++++++++++++++++++++++++ lib/librte_eal/common/eal_private.h | 27 ++++++ lib/librte_eal/common/include/rte_devargs.h | 13 ++- 3 files changed, 181 insertions(+), 3 deletions(-) diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c index 0a83beb94..9fee2153f 100644 --- a/lib/librte_eal/common/eal_common_devargs.c +++ b/lib/librte_eal/common/eal_common_devargs.c @@ -13,9 +13,13 @@ #include #include +#include +#include #include #include #include +#include +#include #include #include "eal_private.h" @@ -56,6 +60,146 @@ rte_eal_parse_devargs_str(const char *devargs_str, return 0; } +static size_t +devargs_layer_count(const char *s) +{ + size_t i = s ? 1 : 0; + + while (s != NULL && s[0] != '\0') { + i += s[0] == '/'; + s++; + } + return i; +} + +int +rte_devargs_layers_parse(struct rte_devargs *da, + const char *devstr) +{ + struct { + const char *key; + const char *str; + struct rte_kvargs *kvlist; + } layers[] = { + { "bus=", NULL, NULL, }, + { "class=", NULL, NULL, }, + { "driver=", NULL, NULL, }, + }; + struct rte_kvargs_pair *kv = NULL; + struct rte_class *cls = NULL; + struct rte_bus *bus = NULL; + const char *s = devstr; + size_t nblayer; + size_t i = 0; + int ret = 0; + + /* Split each sub-lists. */ + nblayer = devargs_layer_count(devstr); + if (nblayer > RTE_DIM(layers)) { + RTE_LOG(ERR, EAL, "Invalid format: too many layers (%zu)\n", + nblayer); + ret = -E2BIG; + goto get_out; + } + + /* If the devargs points the devstr + * as source data, then it should not allocate + * anything and keep referring only to it. + */ + if (da->data != devstr) { + da->data = strdup(devstr); + if (da->data == NULL) { + RTE_LOG(ERR, EAL, "OOM\n"); + ret = -ENOMEM; + goto get_out; + } + s = da->data; + } + + while (s != NULL) { + if (strncmp(layers[i].key, s, + strlen(layers[i].key)) && + /* The last layer is free-form. + * The "driver" key is not required (but accepted). + */ + i != RTE_DIM(layers) - 1) + goto next_layer; + layers[i].str = s; + layers[i].kvlist = rte_kvargs_parse2(s, NULL, "/"); + if (layers[i].kvlist == NULL) { + RTE_LOG(ERR, EAL, "Could not parse %s\n", s); + ret = -EINVAL; + goto get_out; + } + s = strchr(s, '/'); + if (s != NULL) + s++; +next_layer: + if (i >= RTE_DIM(layers)) { + RTE_LOG(ERR, EAL, "Unrecognized layer %s\n", s); + ret = -EINVAL; + goto get_out; + } + i++; + } + + /* Parse each sub-list. */ + for (i = 0; i < RTE_DIM(layers); i++) { + if (layers[i].kvlist == NULL) + continue; + kv = &layers[i].kvlist->pairs[0]; + if (strcmp(kv->key, "bus") == 0) { + bus = rte_bus_find_by_name(kv->value); + if (bus == NULL) { + RTE_LOG(ERR, EAL, "Could not find bus \"%s\"\n", + kv->value); + ret = -EFAULT; + goto get_out; + } + } else if (strcmp(kv->key, "class") == 0) { + cls = rte_class_find_by_name(kv->value); + if (cls == NULL) { + RTE_LOG(ERR, EAL, "Could not find class \"%s\"\n", + kv->value); + ret = -EFAULT; + goto get_out; + } + } else if (strcmp(kv->key, "driver") == 0) { + /* Ignore */ + continue; + } + } + + /* Fill devargs fields. */ + da->busstr = layers[0].str; + da->clsstr = layers[1].str; + da->drvstr = layers[2].str; + da->bus = bus; + da->cls = cls; + + /* If we own the data, clean up a bit + * the several layers string, to ease + * their parsing afterward. + */ + if (da->data != devstr) { + char *s = (void*)(intptr_t)(da->data); + + while ((s = strchr(s, '/'))) { + *s = '\0'; + s++; + } + } + +get_out: + for (i = 0; i < RTE_DIM(layers); i++) { + if (layers[i].kvlist) + rte_kvargs_free(layers[i].kvlist); + } + if (ret != 0) + rte_errno = -ret; + return ret; +} + static int bus_name_cmp(const struct rte_bus *bus, const void *name) { diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h index bdadc4d50..c4c9283c8 100644 --- a/lib/librte_eal/common/eal_private.h +++ b/lib/librte_eal/common/eal_private.h @@ -258,4 +258,31 @@ int rte_mp_channel_init(void); */ void dev_callback_process(char *device_name, enum rte_dev_event_type event); +/** + * @internal + * Parse a device string and store its information in an + * rte_devargs structure. + * + * Note: if the "data" field of da points to devstr, + * then no dynamic allocation is performed and the rte_devargs + * can be safely discarded. + * + * Otherwise ``data`` will hold a workable copy of devstr, that will be + * used by layers descriptors within rte_devargs. In this case, + * any rte_devargs should be cleaned-up before being freed. + * + * @param da + * rte_devargs structure to fill. + * + * @param devstr + * Device string. + * + * @return + * 0 on success. + * Negative errno values on error (rte_errno is set). + */ +int +rte_devargs_layers_parse(struct rte_devargs *da, + const char *devstr); + #endif /* _EAL_PRIVATE_H_ */ diff --git a/lib/librte_eal/common/include/rte_devargs.h b/lib/librte_eal/common/include/rte_devargs.h index 6c3b6326b..148600258 100644 --- a/lib/librte_eal/common/include/rte_devargs.h +++ b/lib/librte_eal/common/include/rte_devargs.h @@ -51,12 +51,19 @@ struct rte_devargs { enum rte_devtype type; /** Device policy. */ enum rte_dev_policy policy; - /** Bus handle for the device. */ - struct rte_bus *bus; /** Name of the device. */ char name[RTE_DEV_NAME_MAX_LEN]; + RTE_STD_C11 + union { /** Arguments string as given by user or "" for no argument. */ - char *args; + char *args; + const char *drvstr; + }; + struct rte_bus *bus; /**< bus handle. */ + struct rte_class *cls; /**< class handle. */ + const char *busstr; /**< bus-related part of device string. */ + const char *clsstr; /**< bus-related part of device string. */ + const char *data; /**< Device string storage. */ }; /** From patchwork Tue Jun 26 16:56:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41594 X-Patchwork-Delegate: thomas@monjalon.net 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 9F4D71BE27; Tue, 26 Jun 2018 18:57:06 +0200 (CEST) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by dpdk.org (Postfix) with ESMTP id D649F1BE09 for ; Tue, 26 Jun 2018 18:56:58 +0200 (CEST) Received: by mail-wr0-f195.google.com with SMTP id e18-v6so17976672wrs.5 for ; Tue, 26 Jun 2018 09:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=+PtSwL92xvH7QaDOLlLEBP1myR80ZkQw2JwqGJe+bOA=; b=DYMQUxEnkiy1QinlUZowWV1sxiCYf9fGtwsOT+6etbhZmVa+KhdaIVHdSQYDqu8o9+ /fL8Pcn112NsGB88FmlO/x/2z34yluzPaVK4m6rA1BSHs90Bp7P6TxDCX5vPczjivWuo y39s+eNoh9CkRJlokNMCLTt+c6MHTE6Ns9II6RPfNpn7ObqkvMqxVZGbxt5F6HbsgFHA RKUQsjuaAIW21I4QQI/Tkm6cXh0+tjjqlfQe7Zsk/HdQY/Y3PlATf1tTYitFkkzLGdX5 HM+8qJlKCSM5FYEBKO4Rs5gr1Tah/KP45WfaTDEtROKi5qPlHhOUEb33C/kPRTMM0gD8 7n0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=+PtSwL92xvH7QaDOLlLEBP1myR80ZkQw2JwqGJe+bOA=; b=gaZv6jWUyY1RXGV7hkK6HUfR9aibgQnp2fjU4V2ADM2OGUBGTRKkECphM02oPOlcCZ 6Rk588XbuRLLX0Tn+qIZzi4/6dgdsmXZvL2BUnuDrtDRz73tqbAMMCHmmqVoma8F8hvA kEwlO3WIzNU0eo6Rl2A9rbhEHqzSUxmgDg5AYDl1TwrvDxOl/bGpRW51IQRRyCiNCyuM CB+vgDls293DHsxk//YvO+FKF3cjZB6LcOmtmPehNHNhNKowxF7BSiFpDwosl0nswX+V 0yRQt10IxlvnQ55xZLlu5UrErPMTp2pWquNFkqXAKBkKyGAjYslzuMY7aehzWCRXE3SG IKVQ== X-Gm-Message-State: APt69E0Ihc/G35tq51JekUqHg3xFlOJxPPWrJOqml+8S9ATJUdwOPQRu w2hOSKiuKOBrtw5ellycRYz5uQ1j X-Google-Smtp-Source: AAOMgpcvZ/dGpy7FQENM+vEvKs6t9VJvEDNNMHjyBQXHcBzqRogJsJvotEVrwCiDK9vC/2URkB2XnA== X-Received: by 2002:adf:a963:: with SMTP id u90-v6mr987421wrc.248.1530032218065; Tue, 26 Jun 2018 09:56:58 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:56 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:11 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 08/21] eal/dev: add device iterator interface 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 device iterator allows iterating over a set of devices. This set is defined by the two descriptions offered, * rte_bus * rte_class Only one description can be provided, or both. It is not allowed to provide no description at all. Each layer of abstraction then performs a filter based on the description provided. This filtering allows iterating on their internal set of devices, stopping when a match is valid and returning the current iteration context. This context allows starting the next iteration from the same point and going forward. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_dev.h | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 3879ff3ca..120df729f 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -285,6 +285,53 @@ __attribute__((used)) = str static const char DRV_EXP_TAG(name, kmod_dep_export)[] \ __attribute__((used)) = str +/** + * Iteration context. + * + * This context carries over the current iteration state. + */ +struct rte_dev_iterator { + const char *devstr; /**< device string. */ + const char *busstr; /**< bus-related part of device string. */ + const char *clsstr; /**< class-related part of device string. */ + struct rte_bus *bus; /**< bus handle. */ + struct rte_class *cls; /**< class handle. */ + struct rte_device *device; /**< current position. */ + void *class_device; /**< additional specialized context. */ +}; + +/** + * Device iteration function. + * + * Find the next device matching properties passed in parameters. + * The function takes an additional ``start`` parameter, that is + * used as starting context when relevant. + * + * The function returns the current element in the iteration. + * This return value will potentially be used as a start parameter + * in subsequent calls to the function. + * + * The additional iterator parameter is only there if a specific + * implementation needs additional context. It must not be modified by + * the iteration function itself. + * + * @param start + * Starting iteration context. + * + * @param devstr + * Device description string. + * + * @param it + * Device iterator. + * + * @return + * The address of the current element matching the device description + * string. + */ +typedef void *(*rte_dev_iterate_t)(const void *start, + const char *devstr, + const struct rte_dev_iterator *it); + #ifdef __cplusplus } #endif From patchwork Tue Jun 26 16:56:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41595 X-Patchwork-Delegate: thomas@monjalon.net 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 D8CB01BE33; Tue, 26 Jun 2018 18:57:10 +0200 (CEST) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id 584DD1BE0E for ; Tue, 26 Jun 2018 18:57:00 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id k6-v6so17966618wrp.4 for ; Tue, 26 Jun 2018 09:57:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=m51DksV4EXmxmvGMaTfKNA+K9/HIFbvWXpWsebu3ZoE=; b=kuD0vLUZsyy4dmoopu1G7bJee8n/EDfiLLxlo9KwnKpu2VZMPxv640NOUoOOgbgAWc wZZt8P2tJX++GJehauT+XZDKkGVCst8nLF5nldUOGkPV52zBtZqsRoQIu7tGGISuaYX/ 2tWtxBHJPQ0r2YakyNzQddQ+UoK2UzBDmiwMPzaGtYUk0QzG4byMGg8/Iod7k+7gjemv o/A6fOgbNZX1wDIsTcJCcjy4Ahu/nqcTHJM/TzutHtkrXGquioVe5QTj34O0lvguyR87 M0hWv4leGhV6zJEJz7rmRJ6Hzm1cbGx9joppmEqs+eLR9tcxs6cxLo+3otsoGvC0nnX8 qJlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=m51DksV4EXmxmvGMaTfKNA+K9/HIFbvWXpWsebu3ZoE=; b=T/ve/VD4/1AFcFrTqUgXQU05DcA87nX1LORfdXEyXU65dKrGPxa9KY26/mLrLO2zXY 4n9zXJPpi24dJb3OjG4foYjbxrzTQ56fDmyDZ/g0op5WL7k/6J54UwoBqJmnXGWToX4T Xz4SCf7fjylaVGGv7DtcDszVJwH7r3Yc/UOV/pawCDC+ZEZi3tGRlpp0FYQ6hhtTSJ6X Emk7b1/AXUco52HPZeT/A3ykM3cqe67Y/vjxhgqZfeclOOk85+oj7zGV0zJhg/78kP1b wFzmsA5WMjCkCDlCDhQig2sRCaIfMmOvyrPQzLv2swupXY8iwcVF85z4VFRRjOHhY7WE I4nQ== X-Gm-Message-State: APt69E3ki7ZHhDcKJiMw1x/qn8kq1vpZOhfVsAiKyJEBXsMy/SxWCAj0 Ud96xfYk7uGBvqQdMgCNguDLFolM X-Google-Smtp-Source: AAOMgpeQAWMODHmSDR/JNWweVqVkopjBdjD45ISRBQOxrDw3t1iAU0nXwNj0k/aA/7IOm12k7WCCuQ== X-Received: by 2002:adf:984e:: with SMTP id v72-v6mr2180232wrb.180.1530032219646; Tue, 26 Jun 2018 09:56:59 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:58 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:12 +0200 Message-Id: <9c285781f619fdeebc617e4c7742086a307c5f47.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 09/21] eal/class: add device iteration 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" Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_class.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/librte_eal/common/include/rte_class.h b/lib/librte_eal/common/include/rte_class.h index e8176f5e1..9d5b06807 100644 --- a/lib/librte_eal/common/include/rte_class.h +++ b/lib/librte_eal/common/include/rte_class.h @@ -30,6 +30,7 @@ TAILQ_HEAD(rte_class_list, rte_class); struct rte_class { TAILQ_ENTRY(rte_class) next; /**< Next device class in linked list */ const char *name; /**< Name of the class */ + rte_dev_iterate_t dev_iterate; /**< Device iterator. */ }; /** From patchwork Tue Jun 26 16:56:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41596 X-Patchwork-Delegate: thomas@monjalon.net 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 034EB1BE3A; Tue, 26 Jun 2018 18:57:13 +0200 (CEST) Received: from mail-wr0-f169.google.com (mail-wr0-f169.google.com [209.85.128.169]) by dpdk.org (Postfix) with ESMTP id 1B25F1BE1A for ; Tue, 26 Jun 2018 18:57:02 +0200 (CEST) Received: by mail-wr0-f169.google.com with SMTP id c5-v6so6812934wrs.10 for ; Tue, 26 Jun 2018 09:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=YSgkLfXIGBP0HLLW+kBNZ/fjgYR4K7+Gu92zfmB4V9Y=; b=M08qGPU+J2WzuNOB4P7IEz/yvGTwBHqabAJb84jiHJGPR63kKC1RvR65zpBKEnUPrm 0D6pmB37sgFb3pNmQL2+/3qyim4TyGaLLowZYrT1YCBpI64Z7aIW6NB7fsltp13z3sJb ZRiggI5PWPO/lp2G2u0PUOXyfne+s2lMJGuVzlzLfPKZ8Dhx/zsnlkDAWr1tudIPuPyH sefEECCx0Bv/hsaEUb8rF0Gat8AYptcFDulm/SBDBO3+lAT8NdEaHzPSquE0pcFkQU/O tkllFjIu3cO6/dFIFeZLcuYR68bODuZrGfrwgJfg51i/ukj0SDXSkvBcwoirjukwKuFN GVlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=YSgkLfXIGBP0HLLW+kBNZ/fjgYR4K7+Gu92zfmB4V9Y=; b=iGH5uWbWq6Jyx2STdL9tglno/4tCZJVadYmRV8SClRMXP5BcvoLhUskTzJlEDp93YM Cb6b0UNYYoor6ueuQSkgRY2YvgpFLV5ufaPoU/YRPgKZ9KvY4BE78cMRx2tyO4KgEy+B 8BZD6H7ElLyjTe9h0z+FNauK8Wh2ELzRPdOKmqEllUgheMKJTy6+iznbPP/uf+5acd8h okJ1+X0AgV+klnK8HIEsAbZmcy2Ei/jwYSCz1gck0UVRXMcjH/DRBTAUS84/4Cp/XkdY q5vO1wP58BzWSjgq1EXocqGdy5PDiR4cQCXlXsTQwISaeeM2rlBaxw4KlcVv/GANk3VO fh7Q== X-Gm-Message-State: APt69E1lOEHIxcfO+0BRvXtS3rHI/KvwThDGJFW2nQh63GtsVLvmcDNg AgmTwAPwpcQrgZObU6/Du0Hc5rnJ X-Google-Smtp-Source: AAOMgpeNRBDd7oMn4aiHaZLz3Lmuu6Q/Wh8XI2RxH1CPjqAqbxCqsLiziTXla8V9zyrZ0zAmoSHH3Q== X-Received: by 2002:adf:8f2e:: with SMTP id p43-v6mr81307wrb.193.1530032221473; Tue, 26 Jun 2018 09:57:01 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.56.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:59 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:13 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 10/21] eal/bus: add device iteration 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" Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/include/rte_bus.h | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/librte_eal/common/include/rte_bus.h b/lib/librte_eal/common/include/rte_bus.h index eb9eded4e..747baf140 100644 --- a/lib/librte_eal/common/include/rte_bus.h +++ b/lib/librte_eal/common/include/rte_bus.h @@ -211,6 +211,7 @@ struct rte_bus { rte_bus_parse_t parse; /**< Parse a device name */ struct rte_bus_conf conf; /**< Bus configuration */ rte_bus_get_iommu_class_t get_iommu_class; /**< Get iommu class */ + rte_dev_iterate_t dev_iterate; /**< Device iterator. */ }; /** From patchwork Tue Jun 26 16:56:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41597 X-Patchwork-Delegate: thomas@monjalon.net 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 6D8481BE49; Tue, 26 Jun 2018 18:57:18 +0200 (CEST) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 3F62C1BE21 for ; Tue, 26 Jun 2018 18:57:04 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id l15-v6so15794560wmc.1 for ; Tue, 26 Jun 2018 09:57:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=CQP7HwETJDS1+r4uLUc7OtartxXupr/yoyp7uskGZdo=; b=opZOC7kuDGLpvedNVf1V+OTQdWBWcDyN03gPMrd48AXzDg5iSnM6iwmMBNEiLmk9QM jj8ilWAgfd/E6moM2IaDRTLaOWmQXxlUgVKHMT5vGNocZQRJTS6jZ8HO8wNU44Ht4s0r XUyce+SQMc4ee4lbmki5SeFeE9YU+C9XrAGJxjJdNAdS8I9ducHiiyHsOXxA0Zyhd/ht 5xkoXIsjbXU1UCH1qkhrSIkeU90uKEJvT++WZSt1mHDEE2x1KricwK8nFWm4mH4vx/QY /9CDUNPzFh/L3uH3kMMxsBDTWZSPhP5n0WX3ubgPEbDJ5jLMVbn7ia777HsOUFGPCe+p UC8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=CQP7HwETJDS1+r4uLUc7OtartxXupr/yoyp7uskGZdo=; b=PQjM4dTDj54Y9IbLvLbIXXq/IPTlDap53giz1CE6ya68LpJcTlrutxD/2j2d1EGk1o Q6e9ojP1qjClNfEYowd+Ztil6jt8YxHRMPDOpNgPxvYRW7Ys/qW0FjgYY02rAbEWuSsC cT50q2ZTzsjZLy3ImQwYDwizGREI59lZVGIDvlytY2GRpHX1bIJ5vKSzn++EzZr6CXs8 wnoE7SCvwZe93fZ1JD5UJx24wl/cAHaeJeourMqdo2oBCAGYNZ72gO7YqfW+OlmmoYHM V4YhCwb7VkEu+PbgIuE4f1BssAY/kL2Vph/wUabO7lYkJYC0eNa68cB2fa+TRmRreuoR BTwQ== X-Gm-Message-State: APt69E2iRtFi0HN0u0M+bAD+uDqRv7kWK9bNMtnZGGMwfzI6RD5/T+4A 20yDKlB5CGtpgcpnswo8HzeDMUqp X-Google-Smtp-Source: AAOMgpdqF0kGlM7+5s84LqTP8AJqLVrjZaDdi/Hqd/G0yxpfo9jKPtYqDZz5Rm+Ep4hJM7kJVt3NBg== X-Received: by 2002:a1c:e846:: with SMTP id f67-v6mr2265522wmh.63.1530032223480; Tue, 26 Jun 2018 09:57:03 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:01 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:14 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 11/21] eal/dev: implement device iteration initialization 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" Parse a device description. Split this description in their relevant part for each layers. No dynamic allocation is performed. Signed-off-by: Gaetan Rivet --- lib/Makefile | 1 + lib/librte_eal/bsdapp/eal/Makefile | 1 + lib/librte_eal/common/eal_common_dev.c | 55 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 24 ++++++++++++++ lib/librte_eal/linuxapp/eal/Makefile | 1 + lib/librte_eal/rte_eal_version.map | 1 + 6 files changed, 83 insertions(+) diff --git a/lib/Makefile b/lib/Makefile index 8a65525cd..afa604e20 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -7,6 +7,7 @@ DIRS-y += librte_compat DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs DEPDIRS-librte_kvargs := librte_compat DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal +DEPDIRS-librte_eal := librte_kvargs DIRS-$(CONFIG_RTE_LIBRTE_PCI) += librte_pci DEPDIRS-librte_pci := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_RING) += librte_ring diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile index b0a1c880a..67b10ae0d 100644 --- a/lib/librte_eal/bsdapp/eal/Makefile +++ b/lib/librte_eal/bsdapp/eal/Makefile @@ -18,6 +18,7 @@ CFLAGS += $(WERROR_FLAGS) -O3 LDLIBS += -lexecinfo LDLIBS += -lpthread LDLIBS += -lgcc_s +LDLIBS += -lrte_kvargs EXPORT_MAP := ../../rte_eal_version.map diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index ce4b51469..5b7956d17 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -10,9 +10,12 @@ #include #include +#include #include #include #include +#include +#include #include #include #include @@ -343,3 +346,55 @@ dev_callback_process(char *device_name, enum rte_dev_event_type event) } rte_spinlock_unlock(&dev_event_lock); } + +__rte_experimental +int +rte_dev_iterator_init(struct rte_dev_iterator *it, + const char *devstr) +{ + struct rte_devargs da; + struct rte_class *cls = NULL; + struct rte_bus *bus = NULL; + + /* Having both busstr and clsstr NULL is illegal, + * marking this iterator as invalid unless + * everything goes well. + */ + it->busstr = NULL; + it->clsstr = NULL; + + da.data = devstr; + if (rte_devargs_layers_parse(&da, devstr)) + goto get_out; + + bus = da.bus; + cls = da.cls; + /* The string should have at least + * one layer specified. + */ + if (bus == NULL && cls == NULL) { + RTE_LOG(ERR, EAL, + "Either bus or class must be specified.\n"); + rte_errno = EINVAL; + goto get_out; + } + if (bus != NULL && bus->dev_iterate == NULL) { + RTE_LOG(ERR, EAL, "Bus %s not supported\n", bus->name); + rte_errno = ENOTSUP; + goto get_out; + } + if (cls != NULL && cls->dev_iterate == NULL) { + RTE_LOG(ERR, EAL, "Class %s not supported\n", cls->name); + rte_errno = ENOTSUP; + goto get_out; + } + it->busstr = da.busstr; + it->clsstr = da.clsstr; + it->devstr = devstr; + it->bus = bus; + it->cls = cls; + it->device = NULL; + it->class_device = NULL; +get_out: + return -rte_errno; +} diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 120df729f..7b7bd83bc 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -332,6 +332,30 @@ typedef void *(*rte_dev_iterate_t)(const void *start, const char *devstr, const struct rte_dev_iterator *it); +/** + * Initializes a device iterator. + * + * This iterator allows accessing a list of devices matching a criteria. + * The device matching is made among all buses and classes currently registered, + * filtered by the device description given as parameter. + * + * This function will not allocate any memory. It is safe to stop the + * iteration at any moment and let the iterator go out of context. + * + * @param it + * Device iterator handle. + * + * @param str + * Device description string. + * + * @return + * 0 on successful initialization. + * <0 on error. + */ +__rte_experimental +int +rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile index babc8617a..885c48110 100644 --- a/lib/librte_eal/linuxapp/eal/Makefile +++ b/lib/librte_eal/linuxapp/eal/Makefile @@ -27,6 +27,7 @@ LDLIBS += -lrt ifeq ($(CONFIG_RTE_EAL_NUMA_AWARE_HUGEPAGES),y) LDLIBS += -lnuma endif +LDLIBS += -lrte_kvargs # specific to linuxapp exec-env SRCS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) := eal.c diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 19d36b4c7..ac04120d6 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -251,6 +251,7 @@ EXPERIMENTAL { rte_dev_event_callback_unregister; rte_dev_event_monitor_start; rte_dev_event_monitor_stop; + rte_dev_iterator_init; rte_devargs_add; rte_devargs_dump; rte_devargs_insert; From patchwork Tue Jun 26 16:56:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41598 X-Patchwork-Delegate: thomas@monjalon.net 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 E63B31BE4B; Tue, 26 Jun 2018 18:57:20 +0200 (CEST) Received: from mail-wm0-f48.google.com (mail-wm0-f48.google.com [74.125.82.48]) by dpdk.org (Postfix) with ESMTP id D2B121BE2A for ; Tue, 26 Jun 2018 18:57:05 +0200 (CEST) Received: by mail-wm0-f48.google.com with SMTP id e16-v6so2752538wmd.0 for ; Tue, 26 Jun 2018 09:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=jiFQq/b0N6qwpPp/G+JTyFUUQLrdWExhtKcMvZahrTY=; b=aBbX5dfllxr2uqz5ipAqs84ZhnBwcQDPh9/H/kYPcdiyibII9LMDEORGYU2q8gToBl jSvROA9LgJykt91BcbeK1am9hmFlzHzhSFDl4FAX7scKIr/04QbgroYEX7qw8npMbplM 2d4ZX4o7WTKX1iGIxS0xyfZCnwIlxujF+dhZWRRPM9VXu/9BDKYO4xZwRnT5SFmbXIga 4p3vCHFnbHKvnGeieff5wBsbBV8uDFLhAA9OaLaBJ0SJaDR61/zwCsc5BNPmKtHk9lBT xlWUYLK+X6UKEXTHi2D81lQaULjOlMoctHPOZEskM0SY1qvn9ZQlC2OcxvZOxsOW+0Gt 1bUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=jiFQq/b0N6qwpPp/G+JTyFUUQLrdWExhtKcMvZahrTY=; b=Q9I8GMfyUBADWJuf1wCfzT9P9lGePQF9oZKg59j4se0B8urrD06+t07h0uHAsQuaJT FFZ83ttzmpvdIT/JyfEI9U1mLA3xi5i5jl9FfHoDj8FMAxOeasoZSND3IlHqDhaQb8nv sVAioyas36ZxixPR2e2iGbnYdX+uWITRD+G9ijSPNps6I0/YXS//xMS7AaUebFTH9UAU Q0MVzizHbHmMVjZW4ATeS6WQM4Ty2B9AP73mmEMxlwRL9HCNEinksx5Qgn1jDr+uF0wT smHoCkbNmvIxhMkHfGbGhTyZdvoTM0GXMxO/OmI95m2JkA0EX9TohbkwfyGEz5njdmas EdMw== X-Gm-Message-State: APt69E3zJCeohsCJYL0tV7pCUNjyL5oqBqmJd8Km69bD9VY6jBug2NST 9s36x4j1+6/KJVAn1ZANyNkbsO/c X-Google-Smtp-Source: AAOMgpe2ygQzxKIvVN3UdPWjlyFkNFUckl0H21FnIHqFQeeSULTGrTinINGa+9JGatgWYvV9m5kMNw== X-Received: by 2002:a1c:3a91:: with SMTP id h139-v6mr2330324wma.94.1530032224997; Tue, 26 Jun 2018 09:57:04 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:03 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:15 +0200 Message-Id: <37f7849559bafea9b2e52475a7c30ecad6d7f3a3.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 12/21] eal/dev: implement device iteration 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" Use the iteration hooks in the abstraction layers to perform the requested filtering on the internal device lists. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 168 ++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 26 +++++ lib/librte_eal/rte_eal_version.map | 1 + 3 files changed, 195 insertions(+) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 5b7956d17..3d486a841 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -45,6 +45,28 @@ static struct dev_event_cb_list dev_event_cbs; /* spinlock for device callbacks */ static rte_spinlock_t dev_event_lock = RTE_SPINLOCK_INITIALIZER; +struct dev_next_ctx { + struct rte_dev_iterator *it; + const char *busstr; + const char *clsstr; +}; + +#define CTX(it, busstr, clsstr) \ + (&(const struct dev_next_ctx){ \ + .it = it, \ + .busstr = busstr, \ + .clsstr = clsstr, \ + }) + +#define ITCTX(ptr) \ + (((struct dev_next_ctx *)(intptr_t)ptr)->it) + +#define BUSCTX(ptr) \ + (((struct dev_next_ctx *)(intptr_t)ptr)->busstr) + +#define CLSCTX(ptr) \ + (((struct dev_next_ctx *)(intptr_t)ptr)->clsstr) + static int cmp_detached_dev_name(const struct rte_device *dev, const void *_name) { @@ -398,3 +420,149 @@ rte_dev_iterator_init(struct rte_dev_iterator *it, get_out: return -rte_errno; } + +static char * +dev_str_sane_copy(const char *str) +{ + size_t end; + char *copy; + + end = strcspn(str, ",/"); + if (str[end] == ',') { + copy = strdup(&str[end + 1]); + } else { + /* '/' or '\0' */ + copy = strdup(""); + } + if (copy == NULL) { + rte_errno = ENOMEM; + } else { + char *slash; + + slash = strchr(copy, '/'); + if (slash != NULL) + slash[0] = '\0'; + } + return copy; +} + +static int +class_next_dev_cmp(const struct rte_class *cls, + const void *ctx) +{ + struct rte_dev_iterator *it; + const char *clsstr = NULL; + void *dev; + + if (cls->dev_iterate == NULL) + return 1; + it = ITCTX(ctx); + clsstr = CLSCTX(ctx); + dev = it->class_device; + /* it->clsstr != NULL means a class + * was specified in the devstr. + */ + if (it->clsstr != NULL && cls != it->cls) + return 1; + /* If an error occurred previously, + * no need to test further. + */ + if (rte_errno != 0) + return -1; + dev = cls->dev_iterate(dev, clsstr, it); + it->class_device = dev; + return dev == NULL; +} + +static int +bus_next_dev_cmp(const struct rte_bus *bus, + const void *ctx) +{ + struct rte_device *dev = NULL; + struct rte_class *cls = NULL; + struct rte_dev_iterator *it; + const char *busstr = NULL; + + if (bus->dev_iterate == NULL) + return 1; + it = ITCTX(ctx); + busstr = BUSCTX(ctx); + dev = it->device; + /* it->busstr != NULL means a bus + * was specified in the devstr. + */ + if (it->busstr != NULL && bus != it->bus) + return 1; + /* If an error occurred previously, + * no need to test further. + */ + if (rte_errno != 0) + return -1; + if (it->clsstr == NULL) { + dev = bus->dev_iterate(dev, busstr, it); + goto end; + } + /* clsstr != NULL */ + if (dev == NULL) { +next_dev_on_bus: + dev = bus->dev_iterate(dev, busstr, it); + it->device = dev; + } + if (dev == NULL) + return 1; + if (it->cls != NULL) + cls = TAILQ_PREV(it->cls, rte_class_list, next); + cls = rte_class_find(cls, class_next_dev_cmp, ctx); + if (cls != NULL) { + it->cls = cls; + goto end; + } + goto next_dev_on_bus; +end: + it->device = dev; + return dev == NULL; +} +__rte_experimental +struct rte_device * +rte_dev_iterator_next(struct rte_dev_iterator *it) +{ + struct rte_bus *bus = NULL; + int old_errno = rte_errno; + char *busstr = NULL; + char *clsstr = NULL; + + rte_errno = 0; + if (it->busstr == NULL && it->clsstr == NULL) { + /* Invalid iterator. */ + rte_errno = EINVAL; + return NULL; + } + if (it->bus != NULL) + bus = TAILQ_PREV(it->bus, rte_bus_list, next); + if (it->busstr != NULL) { + busstr = dev_str_sane_copy(it->busstr); + if (busstr == NULL) + goto out; + } + if (it->clsstr != NULL) { + clsstr = dev_str_sane_copy(it->clsstr); + if (clsstr == NULL) + goto out; + } + while ((bus = rte_bus_find(bus, bus_next_dev_cmp, + CTX(it, busstr, clsstr)))) { + if (it->device != NULL) { + it->bus = bus; + goto out; + } + if (it->busstr != NULL || + rte_errno != 0) + break; + } + if (rte_errno == 0) + rte_errno = old_errno; +out: + free(busstr); + free(clsstr); + return it->device; +} diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index 7b7bd83bc..1553c0970 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -356,6 +356,32 @@ __rte_experimental int rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str); +/** + * Iterates on a device iterator. + * + * Generates a new rte_device handle corresponding to the next element + * in the list described in comprehension by the iterator. + * + * The next object is returned, and the iterator is updated. + * + * @param it + * Device iterator handle. + * + * @return + * An rte_device handle if found. + * NULL if an error occurred (rte_errno is set). + * NULL if no device could be found (rte_errno is not set). + */ +__rte_experimental +struct rte_device * +rte_dev_iterator_next(struct rte_dev_iterator *it); + +#define RTE_DEV_FOREACH(dev, devstr, it) \ + for (rte_dev_iterator_init(it, devstr), \ + dev = rte_dev_iterator_next(it); \ + dev != NULL; \ + dev = rte_dev_iterator_next(it)) + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index ac04120d6..4cd5ab3df 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -252,6 +252,7 @@ EXPERIMENTAL { rte_dev_event_monitor_start; rte_dev_event_monitor_stop; rte_dev_iterator_init; + rte_dev_iterator_next; rte_devargs_add; rte_devargs_dump; rte_devargs_insert; From patchwork Tue Jun 26 16:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41599 X-Patchwork-Delegate: thomas@monjalon.net 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 5EC361BE51; Tue, 26 Jun 2018 18:57:23 +0200 (CEST) Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by dpdk.org (Postfix) with ESMTP id 5DFDD1BE34 for ; Tue, 26 Jun 2018 18:57:07 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id v16-v6so2772349wmv.5 for ; Tue, 26 Jun 2018 09:57:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=iknt2bA9XbpG/yfyyUjUBtsvNWBmFKd1jZVBbdQY5kY=; b=XN7sw+M5eHUBhC9uPC1dPOkv4io0KGBGrPG1ekSnxAUdhfuDiwkDCtWGymqdxOSlLm EhQC+vkaDzDLHgZYmjSmHHasykMaqADAerUGx37gOS2N2jYASrXuzg9wUSUwYj7qWoGy B53b+X8uESIpqAEjbKcf63VvO5sMdL0EsvZPW6riguLQi1f7N3+/TVity7k50DAxGyXr GJB5O8fjFpdbHxUIpNOLAeRIqIUbFp672ClJrShu0zQd3NcKX3dRNuUjkIBs/r8wEdvf qXaPHpZo4b4LsQ0lzneFTb2BiWDalGFckcczsrn+7wNTpG786NHar1upHIlAX4eeCKFz VrVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=iknt2bA9XbpG/yfyyUjUBtsvNWBmFKd1jZVBbdQY5kY=; b=AJEet+WWq3PU7yi3g4NiTxYXRP5xCGoVw+q9yAm3oA6mr8pmm0UYwRdesxu+ECQcQd GoD1vS4endf8fhU1VIlr9qCK8b+EyMiIcTa9WPDNqRlS+WJeWGmVK/vJpTV647ZUFUZQ nReMbmBQRHBu29N4aY0snTdkX2LY3AhVcM8/5eFfP8dfPkmRwAPgsACpYF744WazEC3G ur7S4RaKATjzylkxBnR7JFgBg1Ccw1ISpWtgd7uom8dASmXBJo6ACZkspDAJaqikTujI FClOn3VV2eTd3UHRY8Qni56udVwo+QFEcvNC5azg0Z2e/9wyU0IbnDc+m1dPnkiEZRpi NsxA== X-Gm-Message-State: APt69E1nHnJyTAyvUHepW815sgTe58ti+KEWMU/irq9iYkrJGSi2lpYc nf/GP3Q37ygq9CLvqe/X9uqPYdDX X-Google-Smtp-Source: AAOMgpcrxFyZATu/goLoS9HkDci7I6xB14xXcZEDacgpSiIs+dZdOFGII1m4F+8KxJMpboF6PJGpXg== X-Received: by 2002:a1c:a845:: with SMTP id r66-v6mr2395491wme.2.1530032226641; Tue, 26 Jun 2018 09:57:06 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:05 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:16 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 13/21] kvargs: add generic string matching callback 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" This function can be used as a callback to rte_kvargs_process. This should reduce code duplication. Signed-off-by: Gaetan Rivet --- lib/librte_kvargs/rte_kvargs.c | 10 ++++++++++ lib/librte_kvargs/rte_kvargs.h | 28 ++++++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs_version.map | 1 + 3 files changed, 39 insertions(+) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index cfbee3bd9..cf24b939e 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -205,3 +205,13 @@ rte_kvargs_parse2(const char *args, const char * const valid_keys[], free(copy); return kvlist; } + +__rte_experimental +int +rte_kvargs_strcmp(const char *key __rte_unused, + const char *value, void *opaque) +{ + const char *str = opaque; + + return -abs(strcmp(str, value)); +} diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h index defdf10e4..5c065c3a8 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -25,6 +25,8 @@ extern "C" { #endif +#include + /** Maximum number of key/value associations */ #define RTE_KVARGS_MAX 32 @@ -151,6 +153,32 @@ int rte_kvargs_process(const struct rte_kvargs *kvlist, unsigned rte_kvargs_count(const struct rte_kvargs *kvlist, const char *key_match); +/** + * Generic kvarg handler for string comparison. + * + * This function can be used for a generic string comparison processing + * on a list of kvargs. + * + * @param key + * kvarg pair key. + * + * @param value + * kvarg pair value. + * + * @param opaque + * Opaque pointer to a string. + * + * @return + * 0 if the strings match. + * !0 otherwise or on error. + * + * Unless strcmp, comparison ordering is not kept. + * In order for rte_kvargs_process to stop processing on match error, + * a negative value is returned even if strcmp had returned a positive one. + */ +__rte_experimental +int rte_kvargs_strcmp(const char *key, const char *value, void *opaque); + #ifdef __cplusplus } #endif diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map index b9fe44b98..6a41a6b65 100644 --- a/lib/librte_kvargs/rte_kvargs_version.map +++ b/lib/librte_kvargs/rte_kvargs_version.map @@ -13,5 +13,6 @@ EXPERIMENTAL { global: rte_kvargs_parse2; + rte_kvargs_strcmp; } DPDK_2.0; From patchwork Tue Jun 26 16:56:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41600 X-Patchwork-Delegate: thomas@monjalon.net 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 87A581BE5B; Tue, 26 Jun 2018 18:57:25 +0200 (CEST) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by dpdk.org (Postfix) with ESMTP id 270931BE34 for ; Tue, 26 Jun 2018 18:57:09 +0200 (CEST) Received: by mail-wm0-f65.google.com with SMTP id e16-v6so2752692wmd.0 for ; Tue, 26 Jun 2018 09:57:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:in-reply-to:references:content-transfer-encoding; bh=ydSY601hq76jMizrUeFI14A1ri4rxjg+FVNkF8UBklw=; b=B4/pbq03l4aOokupEXGSh1UojhiqNZJ7LklObY7+2CxnnI1AETd063lDErT/sDwl/T KOpZpLFd+Ai1ipjDLmisFEb5ueAIJRkTNq6K9emrneIe0Ru8Fqp7Jd2OHTAmdjG1e74V r+lCs1Zji2c1n6ylAWBM62f8PUKiSTnf3gRxyQuwkQKv/7v0kB94SBoADqKNDKX4/QeH BBP43qDY+sjpUBT9KKHDdQ5FDq822eb3D+sNzNncfgDM/1EKC0mJQL6HXKD8QOJvy0/1 /6cjfuyD5AITNzZd3Vmorch8vegmuZoOFqKLU5Fp0b2Zp9L+cNumTpSaAk4UZE0N1js5 E1eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:in-reply-to:references :content-transfer-encoding; bh=ydSY601hq76jMizrUeFI14A1ri4rxjg+FVNkF8UBklw=; b=TiGef3SrdTjWDNKrL0+HdHSAtqMlpgBqjnD6B5ePDn5X+FrnjcOXzVjwo2taEYE33e SHXCg3KS8GqY4HAFohz3IhARlJyaHTMQLiw6nVirPsoqZ8yuJNJzSeJP2+DfU9bEeeW2 bLHWDz6Ln1A61agRDpKWenAYl7jpe/HwQNRSeOoMx2lZHK6iyJoKrXpL55Yd5hAHmKo4 HBdv1S7e7vF32QcBXH95+Y2gfpaVrNjbxdIf+7m6tSyF+5cIdv2L5nPLgmSt8WErV6rC nlWMwjTYDcPBbzQk2pddFl46ye7dX0/reCbbEnmJb13rNi09pg9ArSNvBJpWN3h+OJDX o6pw== X-Gm-Message-State: APt69E0ax9fxQ40d+Bh+OitR3ENliKiCYjhfelx0A4TUVl08EpcVgMeq x/0He1GmbbC3A9p0xIeOeB8VTUN9 X-Google-Smtp-Source: AAOMgpdH5gJgVwaVNWJnp8w1FNZtFjDuU/37TxOQ8WVnt1oCqnFpeb58z2VLfLjMEK9182pVigqUxw== X-Received: by 2002:a1c:9c4c:: with SMTP id f73-v6mr2182793wme.141.1530032228173; Tue, 26 Jun 2018 09:57:08 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:06 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:17 +0200 Message-Id: <5a51d7bfcb530cf482e383cdffb07f540244c833.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 14/21] bus/pci: implement device iteration and comparison 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" Signed-off-by: Gaetan Rivet --- drivers/bus/pci/Makefile | 3 ++- drivers/bus/pci/pci_common.c | 3 +-- drivers/bus/pci/pci_params.c | 53 ++++++++++++++++++++++++++++++++++++++++++++ drivers/bus/pci/private.h | 25 +++++++++++++++++++++ 4 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 drivers/bus/pci/pci_params.c diff --git a/drivers/bus/pci/Makefile b/drivers/bus/pci/Makefile index cf373068a..4de953f8f 100644 --- a/drivers/bus/pci/Makefile +++ b/drivers/bus/pci/Makefile @@ -26,10 +26,11 @@ CFLAGS += -I$(RTE_SDK)/lib/librte_eal/$(SYSTEM)app/eal CFLAGS += -DALLOW_EXPERIMENTAL_API LDLIBS += -lrte_eal -lrte_mbuf -lrte_mempool -lrte_ring -LDLIBS += -lrte_ethdev -lrte_pci +LDLIBS += -lrte_ethdev -lrte_pci -lrte_kvargs include $(RTE_SDK)/drivers/bus/pci/$(SYSTEM)/Makefile SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) := $(addprefix $(SYSTEM)/,$(SRCS)) +SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) += pci_params.c SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) += pci_common.c SRCS-$(CONFIG_RTE_LIBRTE_PCI_BUS) += pci_common_uio.c diff --git a/drivers/bus/pci/pci_common.c b/drivers/bus/pci/pci_common.c index 7215aaec3..3c84207ff 100644 --- a/drivers/bus/pci/pci_common.c +++ b/drivers/bus/pci/pci_common.c @@ -26,8 +26,6 @@ #include "private.h" -extern struct rte_pci_bus rte_pci_bus; - #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices" const char *rte_pci_get_sysfs_path(void) @@ -502,6 +500,7 @@ struct rte_pci_bus rte_pci_bus = { .unplug = pci_unplug, .parse = pci_parse, .get_iommu_class = rte_pci_get_iommu_class, + .dev_iterate = rte_pci_dev_iterate, }, .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list), .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list), diff --git a/drivers/bus/pci/pci_params.c b/drivers/bus/pci/pci_params.c new file mode 100644 index 000000000..0fde75803 --- /dev/null +++ b/drivers/bus/pci/pci_params.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Gaëtan Rivet + */ + +#include +#include +#include +#include +#include + +#include "private.h" + +enum pci_params { + RTE_PCI_PARAMS_MAX, +}; + +static const char * const pci_params_keys[] = { + [RTE_PCI_PARAMS_MAX] = NULL, +}; + +static int +pci_dev_match(const struct rte_device *dev, + const void *_kvlist) +{ + const struct rte_kvargs *kvlist = _kvlist; + + (void) dev; + (void) kvlist; + return 0; +} + +void * +rte_pci_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it __rte_unused) +{ + rte_bus_find_device_t find_device; + struct rte_kvargs *kvargs = NULL; + struct rte_device *dev; + + if (str != NULL) { + kvargs = rte_kvargs_parse(str, pci_params_keys); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + rte_errno = EINVAL; + return NULL; + } + } + find_device = rte_pci_bus.bus.find_device; + dev = find_device(start, pci_dev_match, kvargs); + rte_kvargs_free(kvargs); + return dev; +} diff --git a/drivers/bus/pci/private.h b/drivers/bus/pci/private.h index 88fa587e7..eafaeedc7 100644 --- a/drivers/bus/pci/private.h +++ b/drivers/bus/pci/private.h @@ -10,6 +10,8 @@ #include #include +extern struct rte_pci_bus rte_pci_bus; + struct rte_pci_driver; struct rte_pci_device; @@ -216,4 +218,27 @@ rte_pci_match(const struct rte_pci_driver *pci_drv, enum rte_iova_mode rte_pci_get_iommu_class(void); +/* + * Iterate over internal devices, + * matching any device against the provided + * string. + * + * @param start + * Iteration starting point. + * + * @param str + * Device string to match against. + * + * @param it + * (unused) iterator structure. + * + * @return + * A pointer to the next matching device if any. + * NULL otherwise. + */ +void * +rte_pci_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it); + #endif /* _PCI_PRIVATE_H_ */ From patchwork Tue Jun 26 16:56:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41601 X-Patchwork-Delegate: thomas@monjalon.net 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 914EB1BE6B; Tue, 26 Jun 2018 18:57:28 +0200 (CEST) Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id 9D3161BE35 for ; Tue, 26 Jun 2018 18:57:10 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id h10-v6so17957357wrq.8 for ; Tue, 26 Jun 2018 09:57:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=GDAM0+BY9zdzKzqAvSmkL7Cyo+VOwFhWZYWz8JjTZ8Y=; b=NKWNB+YBiahRQ5JviHwIGTIcPPFspQuHUYeTZV/QkDuy9pJrrsOnqI9Yz81KtzaQHU UYx+MDz6Pwc6/M4zNF/VJ67HX607ykVAuHeE6jD99sh8EH3fvYbexC8WSWpc94BgkR9z snoGHjf+aT/JLsrs5FNU0mLVvAvgwap34ccI4J//psHHmrj1YNJ7MUhEGd8SIHEXazC6 fSwMRyxNyrQXkVFWAyvJYVU6KfHzry2vI8cDwuOINdDuLX4LyL07bU1qERFg+Tq2q+eE MZitUJ2nlkJNEwSu7czZfkzQDjqke1UY5lIdl5FxKNk9+6arh4mDbaHyR6Nm2+1ZDslX ADUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=GDAM0+BY9zdzKzqAvSmkL7Cyo+VOwFhWZYWz8JjTZ8Y=; b=q39Qi6ozzB4TYmi1nXZWWnvPsZqcjtx9kVlfMemmU74asu9mBpGppIEo+G0678BhT2 77kaLkN5yTcvaZysAkEs9fsnpy3hD663ddWrpFlbxlCIHo4gxXKqzvPvl5Ou7YLHGQY1 /3KZX+Dyr19f97I/MpexufoCoZD2mYUd93UroqDbP1nRHaKa/60EWI/mDmLUEQ8DMEtz +lmzQPtM2+vDhgkaDP74vORbTjzPx7FHbm47EzsLosOxCJlqc9VIKsTdXk6UmZILMGs3 y6lUqqZYDrv1lMkTPyq9iMuIJ9Q380gO7pFeIaiEonvNJ5HXIzTjSyvNROFDbleBISXf AlwQ== X-Gm-Message-State: APt69E2IVAWMx7b3d+2GmR6K//d8qcSpTMh1HcCjDnDOsiRuNzeHPtnt PAHxuX3Fe9eZYlp2KFecemN9slVC X-Google-Smtp-Source: AAOMgpeaIf/SI2vEzXQqSwTJEmdrLz/i8ixjpvR2wqToWHDkmqCXW5iXnCtIOKfkcHWHuR8iaHYclg== X-Received: by 2002:adf:9562:: with SMTP id 89-v6mr2084748wrs.99.1530032229883; Tue, 26 Jun 2018 09:57:09 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:08 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:18 +0200 Message-Id: <5cd7358f94dd18f4861df37df97148e21ec8b293.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 15/21] bus/pci: add device matching field id 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 PCI bus can now parse a matching field "id" as follows: "bus=pci,id=0000:00:00.0" or "bus=pci,id=00:00.0" Signed-off-by: Gaetan Rivet --- drivers/bus/pci/pci_params.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/bus/pci/pci_params.c b/drivers/bus/pci/pci_params.c index 0fde75803..7630d4845 100644 --- a/drivers/bus/pci/pci_params.c +++ b/drivers/bus/pci/pci_params.c @@ -3,6 +3,7 @@ */ #include +#include #include #include #include @@ -11,21 +12,45 @@ #include "private.h" enum pci_params { + RTE_PCI_PARAMS_ID, RTE_PCI_PARAMS_MAX, }; static const char * const pci_params_keys[] = { + [RTE_PCI_PARAMS_ID] = "id", [RTE_PCI_PARAMS_MAX] = NULL, }; static int +pci_addr_kv_cmp(const char *key __rte_unused, + const char *value, + void *_addr2) +{ + struct rte_pci_addr _addr1; + struct rte_pci_addr *addr1 = &_addr1; + struct rte_pci_addr *addr2 = _addr2; + + if (rte_pci_addr_parse(value, addr1)) + return -1; + return -abs(rte_pci_addr_cmp(addr1, addr2)); +} + +static int pci_dev_match(const struct rte_device *dev, const void *_kvlist) { const struct rte_kvargs *kvlist = _kvlist; + const struct rte_pci_device *pdev; - (void) dev; - (void) kvlist; + if (kvlist == NULL) + /* Empty string matches everything. */ + return 0; + pdev = RTE_DEV_TO_PCI_CONST(dev); + /* if any field does not match. */ + if (rte_kvargs_process(kvlist, "id", + &pci_addr_kv_cmp, + (void *)(intptr_t)&pdev->addr)) + return 1; return 0; } From patchwork Tue Jun 26 16:56:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41602 X-Patchwork-Delegate: thomas@monjalon.net 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 3785A1BE74; Tue, 26 Jun 2018 18:57:31 +0200 (CEST) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by dpdk.org (Postfix) with ESMTP id 65D841BDEC for ; Tue, 26 Jun 2018 18:57:12 +0200 (CEST) Received: by mail-wm0-f68.google.com with SMTP id z13-v6so2597921wma.5 for ; Tue, 26 Jun 2018 09:57:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:in-reply-to:references:content-transfer-encoding; bh=6zLB/7Lvj/weV9uPcrzjEA180HzB3jVsaOXY8Z/yJZQ=; b=P1Xm7k7O+qvFUva/haIQO3C+MxOB30TqbNq08aLcznDP0j0eEvgvotcciwK9SvWcJ+ G66Fhh5OTdrkrxniXS7u030K0pxsigYF9VcztMILFpRTjirfa2QgDTnOEbM0bWxpPlRs sccXRn6o0dpk0uc3OIgzfEUcj7jL3+DHQgGYLvmYWYBspC+FqpHoIZT80al6ekz2hmi7 Zhbt8rOJAc3gpH54tFWI4//SFUnWYyFZoB9uCCXF5fHOn89Cm5PMlhiVN8xoqvb9tdiN /pMy9ptbgbll+DtqVOFBhZIUg8+ZErP0N9BE/NuVP32RhPfjOzS7N/LoEuzplin3eQnx nR/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:in-reply-to:references :content-transfer-encoding; bh=6zLB/7Lvj/weV9uPcrzjEA180HzB3jVsaOXY8Z/yJZQ=; b=aGS/LYPFuwGY7NmFaLs53+yq7ZpxK2RfAll2OWDNg+W3VyyKCPfrziTY5D8CQA2n8W j+Gy8HKf8qmQs5RHmuMRqVDX7EN7HXrjTl/hqgCeSafRwH6406hYT7t83zufdU5lz64d 2p5CXeiI7IV/HhcXy0PYt1cs6rIcdGIH8ayTOzr5lBOTZu6cq25FTYRf5UehH155IM9D T3aLyryOaksUTk4wOq86xcbU0+I2JU8EILtF4JGJbXpb0ER21lzUSwI0J4lQDy+3HmWW CKpicdUwocpcEW7Q6OepDe0BJt9swDh7bR0x6iCY9WB0oW2zq83nh1MTXR4Fh1Ml3Yye oxrQ== X-Gm-Message-State: APt69E0KBevCpSo81sxn/Z8ZVIlFlPqL252xQOXBINTe0TFPOggfCVaO FM2omX5KuMJ4eDioR96f/xeHjafQ X-Google-Smtp-Source: AAOMgpeNQU/uk7cNM6m4MqSzMMpXpyg/1+LxN4ceRBebR2gDhDDHIS+iWfUJd9Aw6xASmYUR6kOd3g== X-Received: by 2002:a1c:8410:: with SMTP id g16-v6mr2272696wmd.26.1530032231626; Tue, 26 Jun 2018 09:57:11 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:10 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:19 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 16/21] bus/vdev: implement device iteration 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" Signed-off-by: Gaetan Rivet --- drivers/bus/vdev/Makefile | 3 ++- drivers/bus/vdev/vdev.c | 10 ++++---- drivers/bus/vdev/vdev_params.c | 51 +++++++++++++++++++++++++++++++++++++++++ drivers/bus/vdev/vdev_private.h | 26 +++++++++++++++++++++ 4 files changed, 85 insertions(+), 5 deletions(-) create mode 100644 drivers/bus/vdev/vdev_params.c create mode 100644 drivers/bus/vdev/vdev_private.h diff --git a/drivers/bus/vdev/Makefile b/drivers/bus/vdev/Makefile index bd0bb8955..1f9cd7ebe 100644 --- a/drivers/bus/vdev/Makefile +++ b/drivers/bus/vdev/Makefile @@ -19,8 +19,9 @@ EXPORT_MAP := rte_bus_vdev_version.map LIBABIVER := 1 SRCS-y += vdev.c +SRCS-y += vdev_params.c -LDLIBS += -lrte_eal +LDLIBS += -lrte_eal -lrte_kvargs # # Export include files diff --git a/drivers/bus/vdev/vdev.c b/drivers/bus/vdev/vdev.c index 6139dd551..e8518833d 100644 --- a/drivers/bus/vdev/vdev.c +++ b/drivers/bus/vdev/vdev.c @@ -23,6 +23,7 @@ #include "rte_bus_vdev.h" #include "vdev_logs.h" +#include "vdev_private.h" #define VDEV_MP_KEY "bus_vdev_mp" @@ -493,9 +494,9 @@ vdev_probe(void) return ret; } -static struct rte_device * -vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, - const void *data) +struct rte_device * +rte_vdev_find_device(const struct rte_device *start, rte_dev_cmp_t cmp, + const void *data) { const struct rte_vdev_device *vstart; struct rte_vdev_device *dev; @@ -532,10 +533,11 @@ vdev_unplug(struct rte_device *dev) static struct rte_bus rte_vdev_bus = { .scan = vdev_scan, .probe = vdev_probe, - .find_device = vdev_find_device, + .find_device = rte_vdev_find_device, .plug = vdev_plug, .unplug = vdev_unplug, .parse = vdev_parse, + .dev_iterate = rte_vdev_dev_iterate, }; RTE_REGISTER_BUS(vdev, rte_vdev_bus); diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c new file mode 100644 index 000000000..842a4684e --- /dev/null +++ b/drivers/bus/vdev/vdev_params.c @@ -0,0 +1,51 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Gaëtan Rivet + */ + +#include +#include +#include +#include + +#include "vdev_logs.h" +#include "vdev_private.h" + +enum vdev_params { + RTE_VDEV_PARAMS_MAX, +}; + +static const char * const vdev_params_keys[] = { + [RTE_VDEV_PARAMS_MAX] = NULL, +}; + +static int +vdev_dev_match(const struct rte_device *dev, + const void *_kvlist) +{ + const struct rte_kvargs *kvlist = _kvlist; + + (void) kvlist; + (void) dev; + return 0; +} + +void * +rte_vdev_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it __rte_unused) +{ + struct rte_kvargs *kvargs = NULL; + struct rte_device *dev; + + if (str != NULL) { + kvargs = rte_kvargs_parse(str, vdev_params_keys); + if (kvargs == NULL) { + VDEV_LOG(ERR, "cannot parse argument list\n"); + rte_errno = EINVAL; + return NULL; + } + } + dev = rte_vdev_find_device(start, vdev_dev_match, kvargs); + rte_kvargs_free(kvargs); + return dev; +} diff --git a/drivers/bus/vdev/vdev_private.h b/drivers/bus/vdev/vdev_private.h new file mode 100644 index 000000000..ba6dc48ff --- /dev/null +++ b/drivers/bus/vdev/vdev_private.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2018 Gaëtan Rivet + */ + +#ifndef _VDEV_PRIVATE_H_ +#define _VDEV_PRIVATE_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +struct rte_device * +rte_vdev_find_device(const struct rte_device *start, + rte_dev_cmp_t cmp, + const void *data); + +void * +rte_vdev_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it); + +#ifdef __cplusplus +} +#endif + +#endif /* _VDEV_PRIVATE_H_ */ From patchwork Tue Jun 26 16:56:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41603 X-Patchwork-Delegate: thomas@monjalon.net 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 191E11BE0C; Tue, 26 Jun 2018 18:57:34 +0200 (CEST) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id DD5B41BE39 for ; Tue, 26 Jun 2018 18:57:13 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id 69-v6so2579693wmf.3 for ; Tue, 26 Jun 2018 09:57:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=asEL7KDRrDSON5+PzJnFF6wFSrQ+kM9WHbufKyn5N6Q=; b=N8pglJplSF4S0X8rw3UoOegpceBZmwP70wqd8qfib7vT5Wf10faeQmCIO5fdRXZeZ3 RtKn0pZ4XqWKi3p1hpVicw5vyG4e4BaaeVtJrbcHeeLr1vCqmR7qIy4aB61Ag9decbeU c62NgCl4l4VvuANMXOw8Ml8CGkVzk7bpby+2ziHvhyUhj7dOiOVEJ6afzJ4ldySgnO44 tFVLbiHrbhcM0Y8yxpdMu4YRUqIhkrIpwvB5WMRiaBEnfdHB24vIzbab27bvjzEncB6b PqeRcnuqiH2sRO61EauaDgHJA2iI9jsXoPQU4lk4i4HmPdWl7dXQ6q8DHGfvnleLjzE9 CBUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=asEL7KDRrDSON5+PzJnFF6wFSrQ+kM9WHbufKyn5N6Q=; b=uBalPHzxAGXTXSJUoFIH0zMuflfxatdf7ooNKFNCseKBggTwqp4V8u6btZyHgfizBK bNr/Wo86ESV6GJNMIIKZwC/6K3VcbfP6HzpMlTUsJ8xlsaFbNgLtF58UIKahQqYesMVU 5mPYCwf45dEpyIZY/rCKnthqSjApqPOsh1INdkfhkO7lR9+zf1cdVRFm56cWIStR+aiv Vtkfmdqg+6c3yEmaElImSvNOmgVS8z7UJkioFf27Qwkyj+tKilv5cxnirulHp0k8cgSe zII+AOsAbm5jYfR4NRbILgJwFBJRWDY3EkjKs4PxqLea4scvgV145wmzdMuestTCBp2T JbCQ== X-Gm-Message-State: APt69E019Z2TrobkLXnoIdtz7bhfqtXvOLGNYb4TosaThqTiooF6SXHM 9wck5UedJ3majT6yKFFZhG21JwPY X-Google-Smtp-Source: AAOMgpffx4woH8SrnnNQ3C0pdgtgmjZzglV2wPWCQjcUYm5HbY7c+m0LS3D7pAAN7RzLC6GVxMRcow== X-Received: by 2002:a1c:2489:: with SMTP id k131-v6mr2397342wmk.114.1530032233158; Tue, 26 Jun 2018 09:57:13 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:11 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:20 +0200 Message-Id: <9f28896afeadb352e2ab8ccc0e59d47769ebba08.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 17/21] bus/vdev: add device matching field driver 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 vdev bus parses a field "driver", matching a vdev driver name with one passed as follows: "bus=vdev,driver=xxxx" Signed-off-by: Gaetan Rivet --- drivers/bus/vdev/vdev_params.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/bus/vdev/vdev_params.c b/drivers/bus/vdev/vdev_params.c index 842a4684e..2f55f451f 100644 --- a/drivers/bus/vdev/vdev_params.c +++ b/drivers/bus/vdev/vdev_params.c @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -11,10 +12,12 @@ #include "vdev_private.h" enum vdev_params { + RTE_VDEV_PARAMS_DRIVER, RTE_VDEV_PARAMS_MAX, }; static const char * const vdev_params_keys[] = { + [RTE_VDEV_PARAMS_DRIVER] = "driver", [RTE_VDEV_PARAMS_MAX] = NULL, }; @@ -23,9 +26,17 @@ vdev_dev_match(const struct rte_device *dev, const void *_kvlist) { const struct rte_kvargs *kvlist = _kvlist; + const struct rte_vdev_device *vdev; - (void) kvlist; - (void) dev; + if (kvlist == NULL) + /* Empty string matches everything. */ + return 0; + vdev = RTE_DEV_TO_VDEV_CONST(dev); + /* if any field does not match. */ + if (rte_kvargs_process(kvlist, "driver", + rte_kvargs_strcmp, + (void *)(intptr_t)vdev->device.driver->name)) + return -1; return 0; } From patchwork Tue Jun 26 16:56:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41604 X-Patchwork-Delegate: thomas@monjalon.net 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 2A5221BE87; Tue, 26 Jun 2018 18:57:36 +0200 (CEST) Received: from mail-wm0-f47.google.com (mail-wm0-f47.google.com [74.125.82.47]) by dpdk.org (Postfix) with ESMTP id 4B7F61BDFE for ; Tue, 26 Jun 2018 18:57:16 +0200 (CEST) Received: by mail-wm0-f47.google.com with SMTP id x6-v6so2745959wmc.3 for ; Tue, 26 Jun 2018 09:57:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:in-reply-to:references:content-transfer-encoding; bh=lUsn9elOsx36tiyiVi1gKRkyWM8pEbQruUHMhEz7E2Q=; b=ZHiG5u408Ca1dpgMmTaO3wgelmn2ZAvaZQBf+FhMdW14R344pZcCdc3kfCikern7It oJTvtk3821rZJ7+NJMpQTeAQxM0TygvCzZqtJ4hW16PYnOm1MSvRPGZNsRbpmJHnijbu vKB9nhAI7Z+5dA5TcARbrtEQu8JmSDnHeCez0DXaJX097E7KPjqsqarItJp39Dovpr8k L7AWGjfJTIxFdPPR0a/tN1J5uyf7Ww/0fUElcR7fGbLQGeQYXO5YqJhEdOSdayd1K+Yh kZWNTkpz1hyz7WalZvpuqzrcNb1eCrwrc7GEMusVcN+yF0l9CGobdmCcxtE570NQcCJc 3f1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:in-reply-to:references :content-transfer-encoding; bh=lUsn9elOsx36tiyiVi1gKRkyWM8pEbQruUHMhEz7E2Q=; b=jiqYJoaI/DbxLiVSmJHy4T5LY7wHTRSuQrk2ohXDWD8Dwy6GoFUaW7oCgW12ZG8To0 H2yev0K5r8Dv5L+UeldUnvW8t3MiTiX5CL0LmXIe197D7s8nvVq+3GUY5r6OZIed4Hab GIfc+q28G+JH+xL1DdH6Qozy9PvS/eXtxlZZuD0Gs2ClpgUJJGS/AD5qtUxeM37g0HXJ Oh0qSrq4Obpmqy2FB/iDx0JjH0YaxWIL2xZsM8g4jaZYGaIvl+5Xj3HoHU4KvmZGDy0V TnLXtT6YkRTX6Ob0uOGXJWxvTwSgMPoK3+Xcg8+kFh/eG/38iefrzJSHAUMJBCpP01R8 2kEA== X-Gm-Message-State: APt69E3yY5R1S6OZbCLqqMEZINr4SsAZzOvWph7a9c7rnHK/V8ZZWdg/ MYNhAK65s+SaZgmRrezUgqJF4CTG X-Google-Smtp-Source: AAOMgpdPtwOOXinrs87CQXj6P/Wjw0e9FCUONpnDagRfRI1+5yieBC1O49rNM4v4AxRDok1F8M1iUA== X-Received: by 2002:a1c:d004:: with SMTP id h4-v6mr2212655wmg.151.1530032235528; Tue, 26 Jun 2018 09:57:15 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:13 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:21 +0200 Message-Id: <025c636181f114d302cce9f00819c9a03098de0b.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 18/21] ethdev: add private generic device iterator 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" This iterator can be customized with a comparison function that will trigger a stopping condition. It can be leveraged to write several different iterators that have similar but non-identical purposes. It is private to librte_ethdev. Signed-off-by: Gaetan Rivet --- lib/librte_ethdev/Makefile | 1 + lib/librte_ethdev/eth_private.c | 31 +++++++++++++++++++++++++++++++ lib/librte_ethdev/eth_private.h | 26 ++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 lib/librte_ethdev/eth_private.c create mode 100644 lib/librte_ethdev/eth_private.h diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index c2f2f7d82..2fa133fbc 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/Makefile @@ -18,6 +18,7 @@ EXPORT_MAP := rte_ethdev_version.map LIBABIVER := 9 +SRCS-y += eth_private.c SRCS-y += rte_ethdev.c SRCS-y += rte_flow.c SRCS-y += rte_tm.c diff --git a/lib/librte_ethdev/eth_private.c b/lib/librte_ethdev/eth_private.c new file mode 100644 index 000000000..d565568a0 --- /dev/null +++ b/lib/librte_ethdev/eth_private.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Gaëtan Rivet + */ + +#include "rte_ethdev.h" +#include "eth_private.h" + +struct rte_eth_dev * +eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, + const void *data) +{ + struct rte_eth_dev *edev; + ptrdiff_t idx; + + /* Avoid Undefined Behaviour */ + if (start != NULL && + (start < &rte_eth_devices[0] || + start > &rte_eth_devices[RTE_MAX_ETHPORTS])) + return NULL; + if (start != NULL) + idx = start - &rte_eth_devices[0] + 1; + else + idx = 0; + for (; idx < RTE_MAX_ETHPORTS; idx++) { + edev = &rte_eth_devices[idx]; + if (cmp(edev, data) == 0) + return edev; + } + return NULL; +} + diff --git a/lib/librte_ethdev/eth_private.h b/lib/librte_ethdev/eth_private.h new file mode 100644 index 000000000..0f5c6d5c4 --- /dev/null +++ b/lib/librte_ethdev/eth_private.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Gaëtan Rivet + */ + +#ifndef _RTE_ETH_PRIVATE_H_ +#define _RTE_ETH_PRIVATE_H_ + +#include "rte_ethdev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Generic rte_eth_dev comparison function. */ +typedef int (*rte_eth_cmp_t)(const struct rte_eth_dev *, const void *); + +/* Generic rte_eth_dev iterator. */ +struct rte_eth_dev * +eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp, + const void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_ETH_PRIVATE_H_ */ From patchwork Tue Jun 26 16:56:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41605 X-Patchwork-Delegate: thomas@monjalon.net 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 618211BE8E; Tue, 26 Jun 2018 18:57:38 +0200 (CEST) Received: from mail-wm0-f42.google.com (mail-wm0-f42.google.com [74.125.82.42]) by dpdk.org (Postfix) with ESMTP id C9F8C1BE3C for ; Tue, 26 Jun 2018 18:57:17 +0200 (CEST) Received: by mail-wm0-f42.google.com with SMTP id z137-v6so2619238wmc.0 for ; Tue, 26 Jun 2018 09:57:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:in-reply-to:references:content-transfer-encoding; bh=rZKGiEjUpkRjzJrFoVp0UVqkqGWKBiX/7X7BIuix/FY=; b=u35BBWQeCAOSjqSTeybtLs0u/1LyxdjyyhGtni4U+tDCmE/3vP6PWxp9DyIIbs9Aca m0yB64Z9s9PPrbHD46y5kAXE2Glrw2MuXaC0bcDzXns6SSXQgU9360CCOlQCAsB1naXi DYlF6THxgCgvGVvkZn+H0Z3IfmpQACE0au8y0aBb6AFx5DaSMT2LFlUUcHVVpCKUznZI 0azf9dDwUeHBC9Seef2X9Z7SfQWOPeRxfcU59rAYtdRFbCNiW9JMF4i+Wp+FgGDdw323 7o8rKe2cP52jznRuxv7Sy1+dpWwaqcQ7efVmI46FZJ+zokR/uUyaZ/oD0rl85xeLOTNt 1sBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:in-reply-to:references :content-transfer-encoding; bh=rZKGiEjUpkRjzJrFoVp0UVqkqGWKBiX/7X7BIuix/FY=; b=VAFrVgLCRYpELjvPJzUP+nKMtg1OPaIZ7sHteOf+XeKFmeU9lLFBlTQppVU27ckCEx DvUYk/QNN8M/tL1wTxIaMi5HTXxL/dCcZK1YObXL0F7EoCQuuafsUGR5qWo2O5mLcL59 V3GyLufxpTihwc26H/HibW3CCKPljT5DCBVX6tMn688tkz9X2qZSO5AHn2Si6TiKzoNL HWGuZcqJnGp1IhHaABLRtfLoQTqShScriGrVLk8jS+OsCUZNkM3N0cjMkBGVwM3WG98J G6P4wHHb+/zJ9SdPzRRmeZkS1mDspvNfrwR6B1Ik7pq1bGY2dXIzi4GakP6jwl3gzsiu 9JqA== X-Gm-Message-State: APt69E3iJfy2bER+Qq522kQGyLgVF5Obw3j4F9rKotGHHnvjnMf7slg5 xR7A0a0hBFBneOAj1si+MiIPWhH0 X-Google-Smtp-Source: AAOMgpcVXMot7jbF/ITSdcKRJ491bV/2KbwY1YhUvmJYNvjA8zJc1hQn707hANaCAPfElyYd/3P31w== X-Received: by 2002:a1c:afc3:: with SMTP id y186-v6mr2178591wme.87.1530032237114; Tue, 26 Jun 2018 09:57:17 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:15 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:22 +0200 Message-Id: <0f91387fadd8142c2427f8ce621d25a310088bd2.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 19/21] ethdev: register ether layer as a class 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" Signed-off-by: Gaetan Rivet --- lib/librte_ethdev/Makefile | 3 +- lib/librte_ethdev/rte_class_eth.c | 79 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 lib/librte_ethdev/rte_class_eth.c diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index 2fa133fbc..d4c3a8d06 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/Makefile @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring -LDLIBS += -lrte_mbuf +LDLIBS += -lrte_mbuf -lrte_kvargs EXPORT_MAP := rte_ethdev_version.map @@ -20,6 +20,7 @@ LIBABIVER := 9 SRCS-y += eth_private.c SRCS-y += rte_ethdev.c +SRCS-y += rte_class_eth.c SRCS-y += rte_flow.c SRCS-y += rte_tm.c SRCS-y += rte_mtr.c diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c new file mode 100644 index 000000000..32c736d32 --- /dev/null +++ b/lib/librte_ethdev/rte_class_eth.c @@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Gaëtan Rivet + */ + +#include + +#include +#include +#include +#include +#include + +#include "rte_ethdev.h" +#include "rte_ethdev_core.h" +#include "eth_private.h" + +enum eth_params { + RTE_ETH_PARAMS_MAX, +}; + +static const char * const eth_params_keys[] = { + [RTE_ETH_PARAMS_MAX] = NULL, +}; + +struct eth_dev_match_arg { + struct rte_device *device; + struct rte_kvargs *kvlist; +}; + +#define eth_dev_match_arg(d, k) \ + (&(const struct eth_dev_match_arg) { \ + .device = (d), \ + .kvlist = (k), \ + }) + +static int +eth_dev_match(const struct rte_eth_dev *edev, + const void *_arg) +{ + const struct eth_dev_match_arg *arg = _arg; + const struct rte_kvargs *kvlist = arg->kvlist; + + if (edev->state == RTE_ETH_DEV_UNUSED) + return -1; + if (edev->device != arg->device) + return -1; + if (kvlist == NULL) + /* Empty string matches everything. */ + return 0; + return 0; +} + +static void * +eth_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it) +{ + struct rte_kvargs *kvargs = NULL; + struct rte_eth_dev *edev = NULL; + + if (str != NULL) { + kvargs = rte_kvargs_parse(str, eth_params_keys); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + rte_errno = EINVAL; + return NULL; + } + } + edev = eth_find_device(start, eth_dev_match, + eth_dev_match_arg(it->device, kvargs)); + rte_kvargs_free(kvargs); + return edev; +} + +struct rte_class rte_class_eth = { + .dev_iterate = eth_dev_iterate, +}; + +RTE_REGISTER_CLASS(eth, rte_class_eth); From patchwork Tue Jun 26 16:56:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41606 X-Patchwork-Delegate: thomas@monjalon.net 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 A86E51BE97; Tue, 26 Jun 2018 18:57:40 +0200 (CEST) Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by dpdk.org (Postfix) with ESMTP id AE9EB1BE05 for ; Tue, 26 Jun 2018 18:57:19 +0200 (CEST) Received: by mail-wr0-f194.google.com with SMTP id l14-v6so12902401wrq.13 for ; Tue, 26 Jun 2018 09:57:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=un2v2GEX2SYq994wd9ePKkFEbROYL9EMUomtxevCaA4=; b=lZPM6tVYOro6j/QpYPhUAGretwS//Ben/cdvcO4r10XGFGtxCGEn2SpGUVlOxU+DMP HsFyXhFeYW3/ZlY8bD7GJV5mRgqbpubBW3cR/CmhFqOsewCHbWauiItsBAbvN8EkMybh OjulAvNYGeiO8ZOuSadk4oPJApslR2cj72nLOGfr+e4437wu2lopFwEwC8Iun+v3t6db PMSg/Ez8LFV7BPCevjp77ttQZhfRGT6IAhOJ2USvRUjwf8K/wjD6NDib2uZFvFAR1s/q umzgywO+wvVzw3Upmag1vX/MqHzvX9QgaDhlH7AZ+FO2975CxadWrHmWCDSW4zKd1/i+ +UNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=un2v2GEX2SYq994wd9ePKkFEbROYL9EMUomtxevCaA4=; b=uFrfkjyldmHu5eSKw0GF5Jmt6vgq05P0LlS6bwlW9PP3iXazh5jfEZLCtr0gHzXj+e +OzeJxA8n00MJfn2I8I1vJUOc4MJ3XYjhESyD8HYKd8Rc4RFqGy1Krt9AmDUh+Uxp81L wd/eVY+zYMUJcPtdkh91Hwv5Rf3HRwtiMCohdmLuELFk6QSu00zkDLkaBSAgfblL/+V3 KDi41xvpBzRFO4FdIfHbfv7zabiI4a5sP6FNPyDiNTOMz/yDwRiNYp89QQSOGieLZx0a TKuJnU9z1kQoVd/QhxGeP8qCjBPjSwnvlujX4EyYtktIYDDyvjE36GzeSDfakogH0TO3 X84Q== X-Gm-Message-State: APt69E3PG6C+2n3P3E2oWUo4ZP7nfKFYB5rSilacejS7O6pb3JnVfESz VPDmbjL/BBdE5WPJDB6/4nMtUsm/ X-Google-Smtp-Source: AAOMgpdXRotmZHJmhG8nWkjKkOTli48lFvMFOzOBemHzTWN020HHvpR6jRs+iNtLknmB7whsLD4yRg== X-Received: by 2002:adf:ea87:: with SMTP id s7-v6mr2085533wrm.150.1530032238946; Tue, 26 Jun 2018 09:57:18 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:17 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:23 +0200 Message-Id: <0d4ff3bf642e7f3f2ade47fdd81d85560d5fee16.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 20/21] ethdev: add device matching field 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" The eth device class can now parse a field name, matching the eth_dev name with one passed as "class=eth,name=xxxxxx" Signed-off-by: Gaetan Rivet --- lib/librte_ethdev/rte_class_eth.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index 32c736d32..d8d8e8845 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -15,10 +15,12 @@ #include "eth_private.h" enum eth_params { + RTE_ETH_PARAMS_NAME, RTE_ETH_PARAMS_MAX, }; static const char * const eth_params_keys[] = { + [RTE_ETH_PARAMS_NAME] = "name", [RTE_ETH_PARAMS_MAX] = NULL, }; @@ -39,6 +41,7 @@ eth_dev_match(const struct rte_eth_dev *edev, { const struct eth_dev_match_arg *arg = _arg; const struct rte_kvargs *kvlist = arg->kvlist; + struct rte_eth_dev_data *data; if (edev->state == RTE_ETH_DEV_UNUSED) return -1; @@ -47,6 +50,10 @@ eth_dev_match(const struct rte_eth_dev *edev, if (kvlist == NULL) /* Empty string matches everything. */ return 0; + data = edev->data; + if (rte_kvargs_process(kvlist, "name", + rte_kvargs_strcmp, data->name)) + return -1; return 0; } From patchwork Tue Jun 26 16:56:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41607 X-Patchwork-Delegate: thomas@monjalon.net 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 F23CA1BE39; Tue, 26 Jun 2018 18:57:42 +0200 (CEST) Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by dpdk.org (Postfix) with ESMTP id 543E31BE06 for ; Tue, 26 Jun 2018 18:57:21 +0200 (CEST) Received: by mail-wr0-f195.google.com with SMTP id g18-v6so17971845wro.7 for ; Tue, 26 Jun 2018 09:57:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=6Va4VvRZm1pXP5GZA+tCZs8WXVQWe4r8P0STi+lICn0=; b=a1jUwuvDOVvwLw0RADX2OYvMhtTxEIa4bKW2dx+PoJP/ymrzuJjsA5UdyQHXbcjUJU /1VeMfQYk4C+Imdi1HGaJEUPT8juRNMD51j4nFZfuj3y/qZMqFcOosisMEuIzFUB5kyY Rz9BvJsoW4VnNMD7UHtmAX9QIoAQIzPADwX3gXJlBEVT0iPUewh3rbUrh8bA8IhYDDII S3i5ZCMUIhganL1XQGLIPSiCc11x0QtbDnW4bKxRGrreDWGP1EDKIjcoMcH8+sExQJwg 6sY8oCxsD9kTGB+tPCvAduAnS5LNP+0B4wiNGEct0IfEqOrsWyU1wRIz+Yrfw5LG7CFi TDCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=6Va4VvRZm1pXP5GZA+tCZs8WXVQWe4r8P0STi+lICn0=; b=Yx4NAE1ivYsbyK7y+gmC+KZaN9ozGU9RQ5yrMx3PMbLOljWw42yTb1ZJxbdLEGFOIu UxO2nxho27grd89HG37ldZllhI0/P5/PI4oPGqxDGs66G8TPoqVjqhAArTEpqOBNT3Cp 7goVDG+cKFb/qkyyzZba5n0oEwqwfPuE+NmskGEW7WCx2hip7zZPc4roDyYTItrhLvQx m2xerZ/wrvyzDFS60DS84I9X8UFSFnbY7fwOzIJVsic45U1fI7Xep0E/an83owvPcv8+ 2WTfaDkqqxMDPWT4k31RzaZW2XMdmrAbchArSzUzt68vbmJ2l9QPg8PtOHa0NayjkfgT Bxyg== X-Gm-Message-State: APt69E0MsguyNe2u4IBD5uSqSH8h6wcrXU+kT7xBtam3Epb6AvCK1l6t eT4vf8PF/8uzjBYkCAYwye9cna8z X-Google-Smtp-Source: AAOMgpfeSc6j3dFgf4EnFdqOc7wxvTO/9XCE7zkUTQ6Ic71ua3Ol0I0Mqt2fViCGXYHmqtZRKFDv2w== X-Received: by 2002:adf:f783:: with SMTP id q3-v6mr1365937wrp.108.1530032240588; Tue, 26 Jun 2018 09:57:20 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id p5-v6sm2680880wre.83.2018.06.26.09.57.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:57:19 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:24 +0200 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 21/21] app/testpmd: add show device command 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 new interactive command is offered: show device This commands lists all rte_device element matching the device description. e.g.: show device bus=pci show device bus=vdev show device bus=vdev/class=eth show device bus=vdev,driver=net_ring/class=eth show device bus=vdev/class=eth,name=net_ring0 These devices may not be otherwise useful, some buses will spawn devices to keep track of their assets without having a driver to use them. Signed-off-by: Gaetan Rivet --- app/test-pmd/cmdline.c | 51 +++++++++++++++++++++++++++++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 24 ++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 27e2aa8c8..872492b88 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -7083,6 +7083,56 @@ cmdline_parse_inst_t cmd_showportall = { }, }; +/* *** SHOW DEVICE INFO *** */ +struct cmd_showdevice_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t device; + cmdline_fixed_string_t filter; +}; + +static void +cmd_showdevice_dump_device(const struct rte_device *dev) +{ + const struct rte_driver *drv = dev->driver; + + printf("0x%p: %s:%s\n", (const void *)dev, dev->name, + drv ? drv->name : ""); +} + +static void cmd_showdevice_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_showdevice_result *res = parsed_result; + struct rte_dev_iterator it; + const struct rte_device *dev; + + RTE_DEV_FOREACH(dev, res->filter, &it) + cmd_showdevice_dump_device(dev); +} + +cmdline_parse_token_string_t cmd_showdevice_show = + TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, + show, "show"); +cmdline_parse_token_string_t cmd_showdevice_device = + TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, + device, "device"); +cmdline_parse_token_string_t cmd_showdevice_filter = + TOKEN_STRING_INITIALIZER(struct cmd_showdevice_result, + filter, NULL); + +cmdline_parse_inst_t cmd_showdevice = { + .f = cmd_showdevice_parsed, + .data = NULL, + .help_str = "show device ", + .tokens = { + (void *)&cmd_showdevice_show, + (void *)&cmd_showdevice_device, + (void *)&cmd_showdevice_filter, + NULL, + }, +}; + /* *** SHOW PORT INFO *** */ struct cmd_showport_result { cmdline_fixed_string_t show; @@ -17262,6 +17312,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_help_long, (cmdline_parse_inst_t *)&cmd_quit, (cmdline_parse_inst_t *)&cmd_load_from_file, + (cmdline_parse_inst_t *)&cmd_showdevice, (cmdline_parse_inst_t *)&cmd_showport, (cmdline_parse_inst_t *)&cmd_showqueue, (cmdline_parse_inst_t *)&cmd_showportall, diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 0d6fd50ca..4f1009a3a 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -2628,6 +2628,30 @@ set the traffic management default hierarchy on the port:: testpmd> set port tm hierarchy default (port_id) +Device functions +---------------- + +Show devices +~~~~~~~~~~~~ + +Display any registered devices:: + + testpmd> show device + +where: + +* ``device_string``: Device description string, of the format + + layer[/layer[/layer]] + + where one layer is in the form + + layer_key=layer_name[,key1=value1[,...]] + + Valid layer keys are ``bus`` and ``class``. + Their respective values is defined by registered ``bus`` and ``class`` + drivers. + Filter Functions ----------------