From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 81BC3A0032; Wed, 14 Sep 2022 10:01:22 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1804D42BA6; Wed, 14 Sep 2022 10:00:31 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 1B43D42B87 for ; Wed, 14 Sep 2022 10:00:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663142429; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Mn8fsdHkypFzGoIQ9dAz7KKQGo+3Lo5iiIS8SIqhd+I=; b=isl+IxLOgg63FKjVnnAMhi4YwAY6kVMZDKrbsVaZCmfPxfIvhwFTAe9G4vn5HGkod3HSUJ beFrBgcln+/Qcd8awft3y5+VoyFR7UZKtI+Ow54AL/ooh6TJSYzD9IJwkwL537QPeqwLug MOjZjdjreCcp06I7e/0JXvnHMV6Jf3A= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-50-hSfQJLlPNp6qYIok78NcJw-1; Wed, 14 Sep 2022 04:00:28 -0400 X-MC-Unique: hSfQJLlPNp6qYIok78NcJw-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20005294EDCA; Wed, 14 Sep 2022 08:00:28 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id B9FE440C6EC4; Wed, 14 Sep 2022 08:00:26 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, bruce.richardson@intel.com, Aman Singh , Yuying Zhang , Anatoly Burakov , Ray Kinsella Subject: [PATCH v6 20/27] bus: introduce accessors Date: Wed, 14 Sep 2022 09:58:34 +0200 Message-Id: <20220914075841.51555-21-david.marchand@redhat.com> In-Reply-To: <20220914075841.51555-1-david.marchand@redhat.com> References: <20220628144643.1213026-1-david.marchand@redhat.com> <20220914075841.51555-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Add helpers to get a rte_bus object details. This will be used externally. Internal users may still dereference a rte_bus object. Signed-off-by: David Marchand Acked-by: Bruce Richardson --- Changes since RFC v1: - changed approach: only external users are updated, --- app/test-pmd/config.c | 4 +-- app/test-pmd/testpmd.c | 4 +-- app/test/test_devargs.c | 4 +-- examples/multi_process/hotplug_mp/commands.c | 4 +-- lib/eal/common/eal_common_bus.c | 26 ++++++++++++-------- lib/eal/include/rte_bus.h | 14 +++++++++++ lib/eal/version.map | 3 +++ 7 files changed, 41 insertions(+), 18 deletions(-) diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index d988429f24..7bd28ee3e8 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -642,7 +642,7 @@ device_infos_display(const char *identifier) if (identifier && da.bus != next) continue; - snprintf(devstr, sizeof(devstr), "bus=%s", next->name); + snprintf(devstr, sizeof(devstr), "bus=%s", rte_bus_name(next)); RTE_DEV_FOREACH(dev, devstr, &dev_iter) { if (!dev->driver) @@ -653,7 +653,7 @@ device_infos_display(const char *identifier) continue; printf("\n%s Infos for device %s %s\n", info_border, dev->name, info_border); - printf("Bus name: %s", dev->bus->name); + printf("Bus name: %s", rte_bus_name(dev->bus)); printf("\nDriver name: %s", dev->driver->name); printf("\nDevargs: %s", dev->devargs ? dev->devargs->args : ""); diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 510e0be624..c7d1fa2719 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -3507,9 +3507,9 @@ detach_devargs(char *identifier) } } - if (rte_eal_hotplug_remove(da.bus->name, da.name) != 0) { + if (rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name) != 0) { TESTPMD_LOG(ERR, "Failed to detach device %s(%s)\n", - da.name, da.bus->name); + da.name, rte_bus_name(da.bus)); rte_devargs_reset(&da); return; } diff --git a/app/test/test_devargs.c b/app/test/test_devargs.c index 16621285d2..ac5bc34c18 100644 --- a/app/test/test_devargs.c +++ b/app/test/test_devargs.c @@ -98,9 +98,9 @@ test_valid_devargs_cases(const struct devargs_case *list, size_t n) list[i].bus_kv) != 0) goto fail; if (list[i].bus != NULL && - strcmp(da.bus->name, list[i].bus) != 0) { + strcmp(rte_bus_name(da.bus), list[i].bus) != 0) { printf("rte_devargs_parse(%s) bus name (%s) not expected (%s)\n", - list[i].devargs, da.bus->name, list[i].bus); + list[i].devargs, rte_bus_name(da.bus), list[i].bus); goto fail; } if ((list[i].class_kv > 0 || list[i].class != NULL) && diff --git a/examples/multi_process/hotplug_mp/commands.c b/examples/multi_process/hotplug_mp/commands.c index da8b5e5924..88f44e00a0 100644 --- a/examples/multi_process/hotplug_mp/commands.c +++ b/examples/multi_process/hotplug_mp/commands.c @@ -126,7 +126,7 @@ static void cmd_dev_attach_parsed(void *parsed_result, return; } - if (!rte_eal_hotplug_add(da.bus->name, da.name, da.args)) + if (!rte_eal_hotplug_add(rte_bus_name(da.bus), da.name, da.args)) cmdline_printf(cl, "attached device %s\n", da.name); else cmdline_printf(cl, "failed to attached device %s\n", @@ -173,7 +173,7 @@ static void cmd_dev_detach_parsed(void *parsed_result, } printf("detaching...\n"); - if (!rte_eal_hotplug_remove(da.bus->name, da.name)) + if (!rte_eal_hotplug_remove(rte_bus_name(da.bus), da.name)) cmdline_printf(cl, "detached device %s\n", da.name); else diff --git a/lib/eal/common/eal_common_bus.c b/lib/eal/common/eal_common_bus.c index baa5b532af..cbf382f967 100644 --- a/lib/eal/common/eal_common_bus.c +++ b/lib/eal/common/eal_common_bus.c @@ -16,11 +16,17 @@ static struct rte_bus_list rte_bus_list = TAILQ_HEAD_INITIALIZER(rte_bus_list); +const char * +rte_bus_name(const struct rte_bus *bus) +{ + return bus->name; +} + void rte_bus_register(struct rte_bus *bus) { RTE_VERIFY(bus); - RTE_VERIFY(bus->name && strlen(bus->name)); + RTE_VERIFY(rte_bus_name(bus) && strlen(rte_bus_name(bus))); /* A bus should mandatorily have the scan implemented */ RTE_VERIFY(bus->scan); RTE_VERIFY(bus->probe); @@ -29,14 +35,14 @@ rte_bus_register(struct rte_bus *bus) RTE_VERIFY(!bus->plug || bus->unplug); TAILQ_INSERT_TAIL(&rte_bus_list, bus, next); - RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", bus->name); + RTE_LOG(DEBUG, EAL, "Registered [%s] bus.\n", rte_bus_name(bus)); } void rte_bus_unregister(struct rte_bus *bus) { TAILQ_REMOVE(&rte_bus_list, bus, next); - RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", bus->name); + RTE_LOG(DEBUG, EAL, "Unregistered [%s] bus.\n", rte_bus_name(bus)); } /* Scan all the buses for registered devices */ @@ -50,7 +56,7 @@ rte_bus_scan(void) ret = bus->scan(); if (ret) RTE_LOG(ERR, EAL, "Scan for (%s) bus failed.\n", - bus->name); + rte_bus_name(bus)); } return 0; @@ -64,7 +70,7 @@ rte_bus_probe(void) struct rte_bus *bus, *vbus = NULL; TAILQ_FOREACH(bus, &rte_bus_list, next) { - if (!strcmp(bus->name, "vdev")) { + if (!strcmp(rte_bus_name(bus), "vdev")) { vbus = bus; continue; } @@ -72,14 +78,14 @@ rte_bus_probe(void) ret = bus->probe(); if (ret) RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n", - bus->name); + rte_bus_name(bus)); } if (vbus) { ret = vbus->probe(); if (ret) RTE_LOG(ERR, EAL, "Bus (%s) probe failed.\n", - vbus->name); + rte_bus_name(vbus)); } return 0; @@ -92,7 +98,7 @@ bus_dump_one(FILE *f, struct rte_bus *bus) int ret; /* For now, dump only the bus name */ - ret = fprintf(f, " %s\n", bus->name); + ret = fprintf(f, " %s\n", rte_bus_name(bus)); /* Error in case of inability in writing to stream */ if (ret < 0) @@ -163,7 +169,7 @@ cmp_bus_name(const struct rte_bus *bus, const void *_name) { const char *name = _name; - return strcmp(bus->name, name); + return strcmp(rte_bus_name(bus), name); } struct rte_bus * @@ -213,7 +219,7 @@ rte_bus_get_iommu_class(void) bus_iova_mode = bus->get_iommu_class(); RTE_LOG(DEBUG, EAL, "Bus %s wants IOVA as '%s'\n", - bus->name, + rte_bus_name(bus), bus_iova_mode == RTE_IOVA_DC ? "DC" : (bus_iova_mode == RTE_IOVA_PA ? "PA" : "VA")); if (bus_iova_mode == RTE_IOVA_PA) diff --git a/lib/eal/include/rte_bus.h b/lib/eal/include/rte_bus.h index 17edaa37c9..3848b44db0 100644 --- a/lib/eal/include/rte_bus.h +++ b/lib/eal/include/rte_bus.h @@ -266,6 +266,20 @@ struct rte_bus { }; +/** + * Retrieve a bus name. + * + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * @param bus + * A pointer to a rte_bus structure. + * @return + * A pointer to the bus name string. + */ +__rte_experimental +const char *rte_bus_name(const struct rte_bus *bus); + /** * Register a Bus handler. * diff --git a/lib/eal/version.map b/lib/eal/version.map index 1f293e768b..aa53064db1 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -424,6 +424,9 @@ EXPERIMENTAL { rte_thread_self; rte_thread_set_affinity_by_id; rte_thread_set_priority; + + # added in 22.11 + rte_bus_name; }; INTERNAL { -- 2.37.3