[01/10] ethdev: support telemetry query MAC addresses

Message ID 20230530090510.56812-2-haijie1@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Ferruh Yigit
Headers
Series support telemetry query ethdev info |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Jie Hai May 30, 2023, 9:05 a.m. UTC
  From: Dengdui Huang <huangdengdui@huawei.com>

This patch support telemetry query MAC addresses for a specific port.

The command is like:
--> /ethdev/macs,0
{
  "/ethdev/macs": [
    "00:18:2D:00:00:79",
    "00:18:2D:00:00:78",
    "00:18:2D:00:00:77"
  ]
}

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
---
 lib/ethdev/rte_ethdev.c | 44 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
  

Comments

Ferruh Yigit June 1, 2023, 2:39 p.m. UTC | #1
On 5/30/2023 10:05 AM, Jie Hai wrote:
> +static int
> +eth_dev_handle_port_macs(const char *cmd __rte_unused,
> +		const char *params,
> +		struct rte_tel_data *d)
> +{
> +	char mac_addr[RTE_ETHER_ADDR_FMT_SIZE];
> +	struct rte_eth_dev_info dev_info;
> +	struct rte_eth_dev *eth_dev;
> +	unsigned long port_id;
> +	char *end_param;
> +	uint32_t i;
> +	int ret;
> +
> +	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
> +		return -EINVAL;
> +
> +	port_id = strtoul(params, &end_param, 0);
> +	if (*end_param != '\0')
> +		RTE_ETHDEV_LOG(NOTICE,
> +			"Extra parameters passed to ethdev telemetry command, ignoring");
> +
> +	if (port_id >= UINT16_MAX)
> +		return -EINVAL;
> +

Above part is common in many telemetry handle functions, what about
extracting it as a function?
  

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index d46e74504e64..65e0101fc0eb 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -7032,6 +7032,48 @@  int rte_eth_dev_map_aggr_tx_affinity(uint16_t port_id, uint16_t tx_queue_id,
 	return ret;
 }
 
+static int
+eth_dev_handle_port_macs(const char *cmd __rte_unused,
+		const char *params,
+		struct rte_tel_data *d)
+{
+	char mac_addr[RTE_ETHER_ADDR_FMT_SIZE];
+	struct rte_eth_dev_info dev_info;
+	struct rte_eth_dev *eth_dev;
+	unsigned long port_id;
+	char *end_param;
+	uint32_t i;
+	int ret;
+
+	if (params == NULL || strlen(params) == 0 || !isdigit(*params))
+		return -EINVAL;
+
+	port_id = strtoul(params, &end_param, 0);
+	if (*end_param != '\0')
+		RTE_ETHDEV_LOG(NOTICE,
+			"Extra parameters passed to ethdev telemetry command, ignoring");
+
+	if (port_id >= UINT16_MAX)
+		return -EINVAL;
+
+	ret = rte_eth_dev_info_get(port_id, &dev_info);
+	if (ret != 0)
+		return ret;
+
+	eth_dev = &rte_eth_devices[port_id];
+	rte_tel_data_start_array(d, RTE_TEL_STRING_VAL);
+	for (i = 0; i < dev_info.max_mac_addrs; i++) {
+		if (rte_is_zero_ether_addr(&eth_dev->data->mac_addrs[i]))
+			continue;
+
+		rte_ether_format_addr(mac_addr, sizeof(mac_addr),
+			&eth_dev->data->mac_addrs[i]);
+		rte_tel_data_add_array_string(d, mac_addr);
+	}
+
+	return 0;
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
 
 RTE_INIT(ethdev_init_telemetry)
@@ -7053,4 +7095,6 @@  RTE_INIT(ethdev_init_telemetry)
 			"Returns the device info for a port. Parameters: int port_id");
 	rte_telemetry_register_cmd("/ethdev/module_eeprom", eth_dev_handle_port_module_eeprom,
 			"Returns module EEPROM info with SFF specs. Parameters: int port_id");
+	rte_telemetry_register_cmd("/ethdev/macs", eth_dev_handle_port_macs,
+			"Returns the MAC addresses for a port. Parameters: int port_id");
 }