From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6AFE642C4A; Wed, 7 Jun 2023 09:46:44 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E927442D93; Wed, 7 Jun 2023 09:45:41 +0200 (CEST) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id D653342D1D for ; Wed, 7 Jun 2023 09:45:29 +0200 (CEST) Received: from kwepemi500020.china.huawei.com (unknown [172.30.72.55]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4QbfTQ2SGkztQcV; Wed, 7 Jun 2023 15:43:06 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by kwepemi500020.china.huawei.com (7.221.188.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Wed, 7 Jun 2023 15:45:28 +0800 From: Jie Hai To: Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko CC: , Subject: [PATCH v2 13/13] ethdev: support telemetry query VLAN info Date: Wed, 7 Jun 2023 15:42:08 +0800 Message-ID: <20230607074209.4798-14-haijie1@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230607074209.4798-1-haijie1@huawei.com> References: <20230530090510.56812-1-haijie1@huawei.com> <20230607074209.4798-1-haijie1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemi500020.china.huawei.com (7.221.188.8) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org 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 --- lib/ethdev/rte_ethdev_telemetry.c | 107 ++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/lib/ethdev/rte_ethdev_telemetry.c b/lib/ethdev/rte_ethdev_telemetry.c index 764cf8f203fb..d11597596921 100644 --- a/lib/ethdev/rte_ethdev_telemetry.c +++ b/lib/ethdev/rte_ethdev_telemetry.c @@ -920,6 +920,111 @@ 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_%"PRIu64"_to_%"PRIu64"", + 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; + uint16_t port_id; + int offload, ret; + char *end_param; + + ret = eth_dev_parse_port_params(params, &port_id, &end_param, false); + if (ret < 0) + return ret; + + 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_INIT(ethdev_init_telemetry) { rte_telemetry_register_cmd("/ethdev/list", eth_dev_handle_port_list, @@ -953,4 +1058,6 @@ RTE_INIT(ethdev_init_telemetry) "Returns RSS info for a port. Parameters: int port_id"); rte_telemetry_register_cmd("/ethdev/fec", eth_dev_handle_port_fec, "Returns FEC info for a port. Parameters: int port_id"); + rte_telemetry_register_cmd("/ethdev/vlan", eth_dev_handle_port_vlan, + "Returns VLAN info for a port. Parameters: int port_id"); } -- 2.33.0