[01/10] ethdev: support telemetry query MAC addresses
Checks
Commit Message
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
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?
@@ -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(ð_dev->data->mac_addrs[i]))
+ continue;
+
+ rte_ether_format_addr(mac_addr, sizeof(mac_addr),
+ ð_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");
}