From 632be32735107a09672a897b6123b8dc4d15b6ae Mon Sep 17 00:00:00 2001 From: Jie Wang Date: Thu, 14 Oct 2021 18:31:23 +0800 Subject: [PATCH] ethdev: add API to get device configuration The driver may change offloads info into dev->data->dev_conf in dev_configure which may cause apps use outdated values. Add a new API to get actual device configuration. Signed-off-by: Jie Wang Acked-by: Andrew Rybchenko Reviewed-by: Ferruh Yigit --- doc/guides/rel_notes/release_21_11.rst | 4 ++++ lib/ethdev/rte_ethdev.c | 20 ++++++++++++++++++++ lib/ethdev/rte_ethdev.h | 18 ++++++++++++++++++ lib/ethdev/version.map | 1 + 4 files changed, 43 insertions(+) diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst index 69ec19264c..3129741841 100644 --- a/doc/guides/rel_notes/release_21_11.rst +++ b/doc/guides/rel_notes/release_21_11.rst @@ -103,6 +103,10 @@ New Features * Default VLAN strip behavior was changed. VLAN tag won't be stripped unless ``DEV_RX_OFFLOAD_VLAN_STRIP`` offload is enabled. +* **Added API to get device configuration in ethdev.** + + Added an ethdev API which can help users get device configuration. + * **Updated AF_XDP PMD.** * Disabled secondary process support. diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 24269468dd..66f905c822 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -3420,6 +3420,26 @@ rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info) return 0; } +int +rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf) +{ + struct rte_eth_dev *dev; + + RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); + dev = &rte_eth_devices[port_id]; + + if (dev_conf == NULL) { + RTE_ETHDEV_LOG(ERR, + "Cannot get ethdev port %u configuration to NULL\n", + port_id); + return -EINVAL; + } + + memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf)); + + return 0; +} + int rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask, uint32_t *ptypes, int num) diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 934066f6b9..b7db29405e 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -3076,6 +3076,24 @@ int rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma, */ int rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info); +/** + * @warning + * @b EXPERIMENTAL: this API may change without prior notice. + * + * Retrieve the configuration of an Ethernet device. + * + * @param port_id + * The port identifier of the Ethernet device. + * @param dev_conf + * Location for Ethernet device configuration to be filled in. + * @return + * - (0) if successful. + * - (-ENODEV) if *port_id* invalid. + * - (-EINVAL) if bad parameter. + */ +__rte_experimental +int rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf); + /** * Retrieve the firmware version of a device. * diff --git a/lib/ethdev/version.map b/lib/ethdev/version.map index 6c68d97c9c..5e6f59c6d3 100644 --- a/lib/ethdev/version.map +++ b/lib/ethdev/version.map @@ -249,6 +249,7 @@ EXPERIMENTAL { rte_mtr_meter_policy_validate; # added in 21.11 + rte_eth_dev_conf_get; rte_eth_macaddrs_get; rte_eth_rx_metadata_negotiate; rte_flow_pick_transfer_proxy; -- 2.20.1