[v2,06/13] ethdev: support telemetry query flow ctrl info

Message ID 20230607074209.4798-7-haijie1@huawei.com (mailing list archive)
State Accepted, 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 June 7, 2023, 7:42 a.m. UTC
  This patch supports telemetry querying flow control info.
The command is like:
--> /ethdev/flow_ctrl,0
{
  "/ethdev/flow_ctrl": {
    "high_waterline": "0x0",
    "low_waterline": "0x0",
    "pause_time": "0xffff",
    "send_xon": "off",
    "mac_ctrl_frame_fwd": "off",
    "rx_pause": "off",
    "tx_pause": "off",
    "autoneg": "off"
  }
}

Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 lib/ethdev/rte_ethdev_telemetry.c | 44 +++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
  

Patch

diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c
index 3b6060a7356a..9847aa528f14 100644
--- a/lib/ethdev/rte_ethdev_telemetry.c
+++ b/lib/ethdev/rte_ethdev_telemetry.c
@@ -408,6 +408,48 @@  eth_dev_handle_port_macs(const char *cmd __rte_unused,
 	return 0;
 }
 
+static int
+eth_dev_handle_port_flow_ctrl(const char *cmd __rte_unused,
+		const char *params,
+		struct rte_tel_data *d)
+{
+	struct rte_eth_fc_conf fc_conf;
+	uint16_t port_id;
+	char *end_param;
+	bool rx_fc_en;
+	bool tx_fc_en;
+	int ret;
+
+	ret = eth_dev_parse_port_params(params, &port_id, &end_param, false);
+	if (ret < 0)
+		return ret;
+
+	ret = rte_eth_dev_flow_ctrl_get(port_id, &fc_conf);
+	if (ret != 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Failed to get flow ctrl info, ret = %d\n", ret);
+		return ret;
+	}
+
+	rx_fc_en = fc_conf.mode == RTE_ETH_FC_RX_PAUSE ||
+		   fc_conf.mode == RTE_ETH_FC_FULL;
+	tx_fc_en = fc_conf.mode == RTE_ETH_FC_TX_PAUSE ||
+		   fc_conf.mode == RTE_ETH_FC_FULL;
+
+	rte_tel_data_start_dict(d);
+	rte_tel_data_add_dict_uint_hex(d, "high_waterline", fc_conf.high_water, 0);
+	rte_tel_data_add_dict_uint_hex(d, "low_waterline", fc_conf.low_water, 0);
+	rte_tel_data_add_dict_uint_hex(d, "pause_time", fc_conf.pause_time, 0);
+	rte_tel_data_add_dict_string(d, "send_xon", fc_conf.send_xon ? "on" : "off");
+	rte_tel_data_add_dict_string(d, "mac_ctrl_frame_fwd",
+			fc_conf.mac_ctrl_frame_fwd ? "on" : "off");
+	rte_tel_data_add_dict_string(d, "rx_pause", rx_fc_en ? "on" : "off");
+	rte_tel_data_add_dict_string(d, "tx_pause", tx_fc_en ? "on" : "off");
+	rte_tel_data_add_dict_string(d, "autoneg", fc_conf.autoneg ? "on" : "off");
+
+	return 0;
+}
+
 RTE_INIT(ethdev_init_telemetry)
 {
 	rte_telemetry_register_cmd("/ethdev/list", eth_dev_handle_port_list,
@@ -429,4 +471,6 @@  RTE_INIT(ethdev_init_telemetry)
 			"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");
+	rte_telemetry_register_cmd("/ethdev/flow_ctrl", eth_dev_handle_port_flow_ctrl,
+			"Returns flow ctrl info for a port. Parameters: int port_id");
 }