DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jie Hai <haijie1@huawei.com>
To: Thomas Monjalon <thomas@monjalon.net>,
	Ferruh Yigit <ferruh.yigit@amd.com>,
	Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Cc: <dev@dpdk.org>, <liudongdong3@huawei.com>
Subject: [PATCH 10/10] ethdev: support telemetry query VLAN info
Date: Tue, 30 May 2023 17:05:10 +0800	[thread overview]
Message-ID: <20230530090510.56812-11-haijie1@huawei.com> (raw)
In-Reply-To: <20230530090510.56812-1-haijie1@huawei.com>

This patch supports querying VLAN information by telemetry.
The command is like:
--> /ethdev/vlan,0
{
  "/ethdev/vlan": {
    "pvid": 0,
    "hw_vlan_reject_tagged": 0,
    "hw_vlan_reject_untagged": 0,
    "hw_vlan_insert_pvid": 0,
    "VLAN_STRIP": "off",
    "VLAN_EXTEND": "off",
    "QINQ_STRIP": "off",
    "VLAN_FILTER": "on",
    "vlan_num": 3,
    "vlan_ids": {
      "vlan_0_to_63": [
        1,
        20
      ],
      "vlan_192_to_255": [
        200
      ]
    }
  }
}

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

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index f7a84ae6c35d..ba3484d8e870 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -7659,6 +7659,118 @@ eth_dev_handle_port_fec(const char *cmd __rte_unused,
 	return 0;
 }
 
+static int
+eth_dev_add_vlan_id(int port_id, struct rte_tel_data *d)
+{
+	struct rte_tel_data *vlan_blks[64] = {NULL};
+	uint16_t vlan_num, vidx, vbit, num_blks;
+	char blk_name[RTE_TEL_MAX_STRING_LEN];
+	struct rte_vlan_filter_conf *vfc;
+	struct rte_tel_data *vlan_blk;
+	struct rte_tel_data *vd;
+	uint64_t bit_width;
+	uint64_t vlan_id;
+
+	vd = rte_tel_data_alloc();
+	if (vd == NULL)
+		return -ENOMEM;
+
+	vfc = &rte_eth_devices[port_id].data->vlan_filter_conf;
+	bit_width = CHAR_BIT * sizeof(uint64_t);
+	vlan_num = 0;
+	num_blks = 0;
+
+	rte_tel_data_start_dict(vd);
+	for (vidx = 0; vidx < RTE_DIM(vfc->ids); vidx++) {
+		if (vfc->ids[vidx] == 0)
+			continue;
+
+		vlan_blk = rte_tel_data_alloc();
+		if (vlan_blk == NULL)
+			goto free_all;
+
+		vlan_blks[num_blks] = vlan_blk;
+		num_blks++;
+		snprintf(blk_name, RTE_TEL_MAX_STRING_LEN, "vlan_%lu_to_%lu",
+			 bit_width * vidx, bit_width * (vidx + 1) - 1);
+		rte_tel_data_start_array(vlan_blk, RTE_TEL_UINT_VAL);
+		rte_tel_data_add_dict_container(vd, blk_name, vlan_blk, 0);
+
+		for (vbit = 0; vbit < bit_width; vbit++) {
+			if ((vfc->ids[vidx] & RTE_BIT64(vbit)) == 0)
+				continue;
+
+			vlan_id = bit_width * vidx + vbit;
+			rte_tel_data_add_array_uint(vlan_blk, vlan_id);
+			vlan_num++;
+		}
+	}
+
+	rte_tel_data_add_dict_uint(d, "vlan_num", vlan_num);
+	rte_tel_data_add_dict_container(d, "vlan_ids", vd, 0);
+
+	return 0;
+
+free_all:
+	while (num_blks-- > 0)
+		rte_tel_data_free(vlan_blks[num_blks]);
+
+	rte_tel_data_free(vd);
+	return -ENOMEM;
+}
+
+static int
+eth_dev_handle_port_vlan(const char *cmd __rte_unused,
+		const char *params,
+		struct rte_tel_data *d)
+{
+	struct rte_eth_txmode *txmode;
+	struct rte_eth_conf dev_conf;
+	unsigned long port_id;
+	int offload, ret;
+	char *end_param;
+
+	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\n");
+
+	if (port_id >= UINT16_MAX || !rte_eth_dev_is_valid_port(port_id))
+		return -EINVAL;
+
+	ret = rte_eth_dev_conf_get(port_id, &dev_conf);
+	if (ret != 0) {
+		RTE_ETHDEV_LOG(ERR,
+			"Failed to get device configuration, ret = %d\n", ret);
+		return ret;
+	}
+
+	txmode = &dev_conf.txmode;
+	rte_tel_data_start_dict(d);
+	rte_tel_data_add_dict_uint(d, "pvid", txmode->pvid);
+	rte_tel_data_add_dict_uint(d, "hw_vlan_reject_tagged",
+		txmode->hw_vlan_reject_tagged);
+	rte_tel_data_add_dict_uint(d, "hw_vlan_reject_untagged",
+		txmode->hw_vlan_reject_untagged);
+	rte_tel_data_add_dict_uint(d, "hw_vlan_insert_pvid",
+		txmode->hw_vlan_insert_pvid);
+
+	offload = rte_eth_dev_get_vlan_offload(port_id);
+	rte_tel_data_add_dict_string(d, "VLAN_STRIP",
+		((offload & RTE_ETH_VLAN_STRIP_OFFLOAD) != 0) ? "on" : "off");
+	rte_tel_data_add_dict_string(d, "VLAN_EXTEND",
+		((offload & RTE_ETH_VLAN_EXTEND_OFFLOAD) != 0) ? "on" : "off");
+	rte_tel_data_add_dict_string(d, "QINQ_STRIP",
+		((offload & RTE_ETH_QINQ_STRIP_OFFLOAD) != 0) ? "on" : "off");
+	rte_tel_data_add_dict_string(d, "VLAN_FILTER",
+		((offload & RTE_ETH_VLAN_FILTER_OFFLOAD) != 0) ? "on" : "off");
+
+	return eth_dev_add_vlan_id(port_id, d);
+}
+
 RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
 
 RTE_INIT(ethdev_init_telemetry)
@@ -7694,4 +7806,6 @@ RTE_INIT(ethdev_init_telemetry)
 			"Returns RSS info for a port. Parameters: unsigned port_id");
 	rte_telemetry_register_cmd("/ethdev/fec", eth_dev_handle_port_fec,
 			"Returns FEC info for a port. Parameters: unsigned port_id");
+	rte_telemetry_register_cmd("/ethdev/vlan", eth_dev_handle_port_vlan,
+			"Returns VLAN info for a port. Parameters: unsigned port_id");
 }
-- 
2.33.0


  parent reply	other threads:[~2023-05-30  9:08 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  9:05 [PATCH 00/10] support telemetry query ethdev info Jie Hai
2023-05-30  9:05 ` [PATCH 01/10] ethdev: support telemetry query MAC addresses Jie Hai
2023-06-01 14:39   ` Ferruh Yigit
2023-05-30  9:05 ` [PATCH 02/10] ethdev: support RxTx offload display Jie Hai
2023-05-30  9:05 ` [PATCH 03/10] ethdev: support telemetry query flow ctrl info Jie Hai
2023-05-30  9:05 ` [PATCH 04/10] ethdev: support telemetry query Rx queue info Jie Hai
2023-05-30  9:05 ` [PATCH 05/10] ethdev: support telemetry query Tx " Jie Hai
2023-05-30  9:05 ` [PATCH 06/10] ethdev: add firmware version in telemetry info command Jie Hai
2023-05-30  9:05 ` [PATCH 07/10] ethdev: support telemetry query DCB info Jie Hai
2023-05-30  9:05 ` [PATCH 08/10] ethdev: support telemetry query RSS info Jie Hai
2023-05-30  9:05 ` [PATCH 09/10] ethdev: support telemetry query FEC info Jie Hai
2023-05-30  9:05 ` Jie Hai [this message]
2023-06-01 12:05 ` [PATCH 00/10] support telemetry query ethdev info Ferruh Yigit
2023-06-01 12:23   ` Jie Hai
2023-06-01 14:36 ` Ferruh Yigit
2023-06-05  6:19   ` Jie Hai
2023-06-07  7:41 ` [PATCH v2 00/13] " Jie Hai
2023-06-07  7:41   ` [PATCH v2 01/13] ethdev: fix incorrect argument of calloc Jie Hai
2023-06-07 11:35     ` Ferruh Yigit
2023-06-07  7:41   ` [PATCH v2 02/13] ethdev: extract telemetry codes to a file Jie Hai
2023-06-07 11:37     ` Ferruh Yigit
2023-06-07  7:41   ` [PATCH v2 03/13] ethdev: extract codes parsing port ID as a function Jie Hai
2023-06-07 11:37     ` Ferruh Yigit
2023-06-07  7:41   ` [PATCH v2 04/13] ethdev: support telemetry query MAC addresses Jie Hai
2023-06-07  7:42   ` [PATCH v2 05/13] ethdev: support RxTx offload display Jie Hai
2023-06-07  7:42   ` [PATCH v2 06/13] ethdev: support telemetry query flow ctrl info Jie Hai
2023-06-07  7:42   ` [PATCH v2 07/13] ethdev: support telemetry query Rx queue info Jie Hai
2023-06-07  7:42   ` [PATCH v2 08/13] ethdev: support telemetry query Tx " Jie Hai
2023-06-07  7:42   ` [PATCH v2 09/13] ethdev: add firmware version in telemetry info command Jie Hai
2023-06-07  7:42   ` [PATCH v2 10/13] ethdev: support telemetry query DCB info Jie Hai
2023-06-07  7:42   ` [PATCH v2 11/13] ethdev: support telemetry query RSS info Jie Hai
2023-06-07 14:08     ` Ferruh Yigit
2023-06-07  7:42   ` [PATCH v2 12/13] ethdev: support telemetry query FEC info Jie Hai
2023-06-07  7:42   ` [PATCH v2 13/13] ethdev: support telemetry query VLAN info Jie Hai
2023-06-07 11:40   ` [PATCH v2 00/13] support telemetry query ethdev info Ferruh Yigit
2023-06-08  2:01     ` Jie Hai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230530090510.56812-11-haijie1@huawei.com \
    --to=haijie1@huawei.com \
    --cc=andrew.rybchenko@oktetlabs.ru \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    --cc=liudongdong3@huawei.com \
    --cc=thomas@monjalon.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).