bus: introduce accessors

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 <david.marchand@redhat.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
This commit is contained in:
David Marchand 2022-07-28 17:26:34 +02:00
parent 770ebc060e
commit 148c51a3de
7 changed files with 41 additions and 18 deletions

View File

@ -644,7 +644,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)
@ -655,7 +655,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 : "");

View File

@ -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;
}

View File

@ -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) &&

View File

@ -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

View File

@ -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)

View File

@ -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.
*

View File

@ -425,6 +425,9 @@ EXPERIMENTAL {
rte_thread_self;
rte_thread_set_affinity_by_id;
rte_thread_set_priority;
# added in 22.11
rte_bus_name;
};
INTERNAL {