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 AFA44A0542; Sat, 9 Jul 2022 10:30:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id BCF4042B71; Sat, 9 Jul 2022 10:29:59 +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 A226442B96 for ; Sat, 9 Jul 2022 10:29:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1657355397; 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=gzqSbQriWwYI7/csEd/Pp8wlRQ2adEVA5uGLprkjekk=; b=CTIqGYcxcjdj6eOsvJHeDqHymEBS0m+wrGdyZU7nV8VHwixVYu9QKNOffYBIgb2g6oFm9c BJJ1YtsIRZBm84iK39sxa4btB5KWZjxOqttuOPVwUKWD6P5f42aKiLiRzv1M3PJW78QHgy 0Kvrc23n4bOs0QfO6dhUQGfqvGLzecQ= 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-650-4Q0glFlROoOjF5qlxos4-Q-1; Sat, 09 Jul 2022 04:29:53 -0400 X-MC-Unique: 4Q0glFlROoOjF5qlxos4-Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9AEB63806737; Sat, 9 Jul 2022 08:29:52 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id E860C2026D64; Sat, 9 Jul 2022 08:29:50 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: Maryam Tahhan , Reshma Pattan , Maxime Coquelin , Chenbo Xia , Ray Kinsella , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko Subject: [RFC v2 v2 28/29] dev: introduce device accessors Date: Sat, 9 Jul 2022 10:26:43 +0200 Message-Id: <20220709082644.664675-29-david.marchand@redhat.com> In-Reply-To: <20220709082644.664675-1-david.marchand@redhat.com> References: <20220628144643.1213026-1-david.marchand@redhat.com> <20220709082644.664675-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com 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 Prepare for making the device object opaque by adding accessors. Update existing "external" users. Signed-off-by: David Marchand --- app/proc-info/main.c | 6 ++-- examples/ethtool/lib/rte_ethtool.c | 2 +- examples/l3fwd/l3fwd_em.c | 4 +-- examples/l3fwd/l3fwd_fib.c | 8 ++--- examples/l3fwd/l3fwd_lpm.c | 4 +-- examples/vdpa/main.c | 16 ++++----- lib/eal/common/eal_common_dev.c | 24 ++++++++++++++ lib/eal/include/rte_dev.h | 53 ++++++++++++++++++++++++++++++ lib/eal/version.map | 4 +++ lib/ethdev/rte_ethdev.h | 2 +- 10 files changed, 102 insertions(+), 21 deletions(-) diff --git a/app/proc-info/main.c b/app/proc-info/main.c index 1bfba5f60d..d52ac8a038 100644 --- a/app/proc-info/main.c +++ b/app/proc-info/main.c @@ -755,7 +755,7 @@ show_port(void) } printf("\t -- driver %s device %s socket %d\n", - dev_info.driver_name, dev_info.device->name, + dev_info.driver_name, rte_dev_name(dev_info.device), rte_eth_dev_socket_id(i)); ret = rte_eth_dev_owner_get(i, &owner); @@ -1254,7 +1254,7 @@ show_crypto(void) rte_cryptodev_name_get(i), dev_info.driver_name, dev_info.driver_id, - dev_info.device->numa_node, + rte_dev_numa_node(dev_info.device), rte_cryptodev_queue_pair_count(i)); display_crypto_feature_info(dev_info.feature_flags); @@ -1466,7 +1466,7 @@ dump_regs(char *file_prefix) else printf("Device (%s) regs dumped successfully, " "driver:%s version:0X%08X\n", - dev_info.device->name, + rte_dev_name(dev_info.device), dev_info.driver_name, reg_info.version); fclose(fp_regs); diff --git a/examples/ethtool/lib/rte_ethtool.c b/examples/ethtool/lib/rte_ethtool.c index 88dc917b73..33acc5e3cc 100644 --- a/examples/ethtool/lib/rte_ethtool.c +++ b/examples/ethtool/lib/rte_ethtool.c @@ -49,7 +49,7 @@ rte_ethtool_get_drvinfo(uint16_t port_id, struct ethtool_drvinfo *drvinfo) strlcpy(drvinfo->driver, dev_info.driver_name, sizeof(drvinfo->driver)); strlcpy(drvinfo->version, rte_version(), sizeof(drvinfo->version)); - strlcpy(drvinfo->bus_info, dev_info.device->name, + strlcpy(drvinfo->bus_info, rte_dev_name(dev_info.device), sizeof(drvinfo->bus_info)); memset(®_info, 0, sizeof(reg_info)); diff --git a/examples/l3fwd/l3fwd_em.c b/examples/l3fwd/l3fwd_em.c index 10be24c61d..0531282a1f 100644 --- a/examples/l3fwd/l3fwd_em.c +++ b/examples/l3fwd/l3fwd_em.c @@ -403,7 +403,7 @@ populate_ipv4_flow_into_table(const struct rte_hash *h) em_route_base_v4[i].v4_key.port_dst, em_route_base_v4[i].v4_key.port_src, em_route_base_v4[i].v4_key.proto, - em_route_base_v4[i].if_out, dev_info.device->name); + em_route_base_v4[i].if_out, rte_dev_name(dev_info.device)); } printf("Hash: Adding 0x%" PRIx64 " keys\n", (uint64_t)route_num_v4); @@ -455,7 +455,7 @@ populate_ipv6_flow_into_table(const struct rte_hash *h) em_route_base_v6[i].v6_key.port_dst, em_route_base_v6[i].v6_key.port_src, em_route_base_v6[i].v6_key.proto, - em_route_base_v6[i].if_out, dev_info.device->name); + em_route_base_v6[i].if_out, rte_dev_name(dev_info.device)); } printf("Hash: Adding 0x%" PRIx64 "keys\n", (uint64_t)route_num_v6); diff --git a/examples/l3fwd/l3fwd_fib.c b/examples/l3fwd/l3fwd_fib.c index e02e4b3f5a..b82e0c0354 100644 --- a/examples/l3fwd/l3fwd_fib.c +++ b/examples/l3fwd/l3fwd_fib.c @@ -640,11 +640,11 @@ setup_fib(const int socketid) printf("FIB: Adding route %s / %d (%d) [%s]\n", abuf, route_base_v4[i].depth, route_base_v4[i].if_out, - dev_info.device->name); + rte_dev_name(dev_info.device)); } else { printf("FIB: IPv4 route added to port %d [%s]\n", route_base_v4[i].if_out, - dev_info.device->name); + rte_dev_name(dev_info.device)); } } /* >8 End of setup fib. */ @@ -695,11 +695,11 @@ setup_fib(const int socketid) printf("FIB: Adding route %s / %d (%d) [%s]\n", abuf, route_base_v6[i].depth, route_base_v6[i].if_out, - dev_info.device->name); + rte_dev_name(dev_info.device)); } else { printf("FIB: IPv6 route added to port %d [%s]\n", route_base_v6[i].if_out, - dev_info.device->name); + rte_dev_name(dev_info.device)); } } } diff --git a/examples/l3fwd/l3fwd_lpm.c b/examples/l3fwd/l3fwd_lpm.c index d1b850dd5b..22d7f61a42 100644 --- a/examples/l3fwd/l3fwd_lpm.c +++ b/examples/l3fwd/l3fwd_lpm.c @@ -598,7 +598,7 @@ setup_lpm(const int socketid) printf("LPM: Adding route %s / %d (%d) [%s]\n", inet_ntop(AF_INET, &in, abuf, sizeof(abuf)), route_base_v4[i].depth, - route_base_v4[i].if_out, dev_info.device->name); + route_base_v4[i].if_out, rte_dev_name(dev_info.device)); } /* create the LPM6 table */ @@ -642,7 +642,7 @@ setup_lpm(const int socketid) inet_ntop(AF_INET6, route_base_v6[i].ip_8, abuf, sizeof(abuf)), route_base_v6[i].depth, - route_base_v6[i].if_out, dev_info.device->name); + route_base_v6[i].if_out, rte_dev_name(dev_info.device)); } } diff --git a/examples/vdpa/main.c b/examples/vdpa/main.c index 7e11ef4e26..ee240dd15a 100644 --- a/examples/vdpa/main.c +++ b/examples/vdpa/main.c @@ -119,7 +119,7 @@ new_device(int vid) "Failed to get generic device for port %d\n", i); continue; } - printf("\nnew port %s, device : %s\n", ifname, dev->name); + printf("\nnew port %s, device : %s\n", ifname, rte_dev_name(dev)); vports[i].vid = vid; break; } @@ -149,7 +149,7 @@ destroy_device(int vid) continue; } - printf("\ndestroy port %s, device: %s\n", ifname, dev->name); + printf("\ndestroy port %s, device: %s\n", ifname, rte_dev_name(dev)); break; } } @@ -353,23 +353,23 @@ static void cmd_list_vdpa_devices_parsed( cmdline_printf(cl, "device name\tqueue num\tsupported features\n"); RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { - vdev = rte_vdpa_find_device_by_name(dev->name); + vdev = rte_vdpa_find_device_by_name(rte_dev_name(dev)); if (!vdev) continue; if (rte_vdpa_get_queue_num(vdev, &queue_num) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa queue number " - "for device %s.\n", dev->name); + "for device %s.\n", rte_dev_name(dev)); continue; } if (rte_vdpa_get_features(vdev, &features) < 0) { RTE_LOG(ERR, VDPA, "failed to get vdpa features " - "for device %s.\n", dev->name); + "for device %s.\n", rte_dev_name(dev)); continue; } cmdline_printf(cl, "%s\t\t%" PRIu32 "\t\t0x%" PRIx64 "\n", - dev->name, queue_num, features); + rte_dev_name(dev), queue_num, features); } } @@ -606,10 +606,10 @@ main(int argc, char *argv[]) cmdline_stdin_exit(cl); } else { RTE_DEV_FOREACH(dev, "class=vdpa", &dev_iter) { - vdev = rte_vdpa_find_device_by_name(dev->name); + vdev = rte_vdpa_find_device_by_name(rte_dev_name(dev)); if (vdev == NULL) { rte_panic("Failed to find vDPA dev for %s\n", - dev->name); + rte_dev_name(dev)); } vports[devcnt].dev = vdev; snprintf(vports[devcnt].ifname, MAX_PATH_LEN, "%s%d", diff --git a/lib/eal/common/eal_common_dev.c b/lib/eal/common/eal_common_dev.c index 5b64b80cb9..e2d77e02a5 100644 --- a/lib/eal/common/eal_common_dev.c +++ b/lib/eal/common/eal_common_dev.c @@ -25,6 +25,30 @@ rte_driver_name(const struct rte_driver *driver) return driver->name; } +const struct rte_bus * +rte_dev_bus(const struct rte_device *dev) +{ + return dev->bus; +} + +const struct rte_driver * +rte_dev_driver(const struct rte_device *dev) +{ + return dev->driver; +} + +const char * +rte_dev_name(const struct rte_device *dev) +{ + return dev->name; +} + +int +rte_dev_numa_node(const struct rte_device *dev) +{ + return dev->numa_node; +} + /** * The device event callback description. * diff --git a/lib/eal/include/rte_dev.h b/lib/eal/include/rte_dev.h index 875ecee371..a80447a645 100644 --- a/lib/eal/include/rte_dev.h +++ b/lib/eal/include/rte_dev.h @@ -23,6 +23,7 @@ extern "C" { #include #include +struct rte_bus; struct rte_driver; /** @@ -68,12 +69,64 @@ __rte_experimental const char * rte_driver_name(const struct rte_driver *driver); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * @param dev + * A pointer to a device structure. + * @return + * A pointer to this device bus. + */ +__rte_experimental +const struct rte_bus * +rte_dev_bus(const struct rte_device *dev); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * @param dev + * A pointer to a device structure. + * @return + * A pointer to this device driver. + */ +__rte_experimental +const struct rte_driver * +rte_dev_driver(const struct rte_device *dev); + +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * @param dev + * A pointer to a device structure. + * @return + * A pointer to this device name. + */ +__rte_experimental +const char * +rte_dev_name(const struct rte_device *dev); + /* * Internal identifier length * Sufficiently large to allow for UUID or PCI address */ #define RTE_DEV_NAME_MAX_LEN 64 +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice + * + * @param dev + * A pointer to a device structure. + * @return + * A pointer to this device numa node. + */ +__rte_experimental +int +rte_dev_numa_node(const struct rte_device *dev); + /** * A structure describing a generic device. */ diff --git a/lib/eal/version.map b/lib/eal/version.map index 54f85ab01f..660d3c7433 100644 --- a/lib/eal/version.map +++ b/lib/eal/version.map @@ -426,6 +426,10 @@ EXPERIMENTAL { # added in 22.11 rte_bus_name; rte_driver_name; + rte_dev_bus; + rte_dev_driver; + rte_dev_name; + rte_dev_numa_node; }; INTERNAL { diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index e9574f646f..2197525315 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -3380,7 +3380,7 @@ int rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma, * exists for the device and the rte_eth_dev 'dev' has been populated * successfully with a call to it: * - * driver_name = rte_driver_name(dev->device->driver) + * driver_name = rte_driver_name(rte_dev_driver(dev->device)); * nb_rx_queues = dev->data->nb_rx_queues * nb_tx_queues = dev->data->nb_tx_queues * dev_flags = &dev->data->dev_flags -- 2.36.1