1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell International Ltd.
3  */
4 
5 #include <rte_telemetry.h>
6 
7 #include "cnxk_ethdev.h"
8 
9 /* Macro to count no of words in eth_info_s size */
10 #define ETH_INFO_SZ                                                            \
11 	(RTE_ALIGN_CEIL(sizeof(struct eth_info_s), sizeof(uint64_t)) /         \
12 	 sizeof(uint64_t))
13 #define MACADDR_LEN 18
14 
15 static int
16 ethdev_tel_handle_info(const char *cmd __rte_unused,
17 		       const char *params __rte_unused, struct rte_tel_data *d)
18 {
19 	struct rte_eth_dev *eth_dev;
20 	struct rte_tel_data *i_data;
21 	struct cnxk_eth_dev *dev;
22 	union eth_info_u {
23 		struct eth_info_s {
24 			/** PF/VF information */
25 			uint16_t pf_func;
26 			uint8_t max_mac_entries;
27 			bool dmac_filter_ena;
28 			uint8_t dmac_filter_count;
29 			uint8_t ptype_disable;
30 			bool scalar_ena;
31 			bool ptp_ena;
32 			/* Platform specific offload flags */
33 			uint16_t rx_offload_flags;
34 			uint16_t tx_offload_flags;
35 		} info;
36 		uint64_t val[ETH_INFO_SZ];
37 	} eth_info;
38 	struct eth_info_s *info;
39 	unsigned int i, j = 0;
40 	int n_ports;
41 
42 	n_ports = rte_eth_dev_count_avail();
43 	if (!n_ports) {
44 		plt_err("No active ethernet ports found.");
45 		return -1;
46 	}
47 
48 	rte_tel_data_start_dict(d);
49 	rte_tel_data_add_dict_int(d, "n_ports", n_ports);
50 
51 	i_data = rte_tel_data_alloc();
52 	rte_tel_data_start_array(i_data, RTE_TEL_U64_VAL);
53 
54 	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
55 		/* Skip if port is unused */
56 		if (!rte_eth_dev_is_valid_port(i))
57 			continue;
58 
59 		eth_dev = &rte_eth_devices[i];
60 		if (eth_dev) {
61 			memset(&eth_info, 0, sizeof(eth_info));
62 			info = &eth_info.info;
63 			dev = cnxk_eth_pmd_priv(eth_dev);
64 			if (dev) {
65 				info->pf_func = roc_nix_get_pf_func(&dev->nix);
66 				info->max_mac_entries = dev->max_mac_entries;
67 				info->dmac_filter_ena = dev->dmac_filter_enable;
68 				info->dmac_filter_count =
69 					dev->dmac_filter_count;
70 				info->ptype_disable = dev->ptype_disable;
71 				info->scalar_ena = dev->scalar_ena;
72 				info->ptp_ena = dev->ptp_en;
73 				info->rx_offload_flags = dev->rx_offload_flags;
74 				info->tx_offload_flags = dev->tx_offload_flags;
75 			}
76 
77 			for (j = 0; j < ETH_INFO_SZ; j++)
78 				rte_tel_data_add_array_u64(i_data,
79 							   eth_info.val[j]);
80 
81 			j++;
82 		}
83 	}
84 
85 	rte_tel_data_add_dict_container(d, "info", i_data, 0);
86 	return 0;
87 }
88 
89 RTE_INIT(cnxk_ethdev_init_telemetry)
90 {
91 	rte_telemetry_register_cmd("/cnxk/ethdev/info", ethdev_tel_handle_info,
92 				   "Returns ethdev device information");
93 }
94