net/cnxk: update inline device in ethdev telemetry
[dpdk.git] / drivers / net / cnxk / cnxk_ethdev_telemetry.c
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                         uint16_t inl_dev_pf_func;
27                         uint8_t max_mac_entries;
28                         bool dmac_filter_ena;
29                         uint8_t dmac_filter_count;
30                         uint8_t ptype_disable;
31                         bool scalar_ena;
32                         bool ptp_ena;
33                         /* Platform specific offload flags */
34                         uint16_t rx_offload_flags;
35                         uint16_t tx_offload_flags;
36                 } info;
37                 uint64_t val[ETH_INFO_SZ];
38         } eth_info;
39         struct eth_info_s *info;
40         unsigned int i, j = 0;
41         int n_ports;
42
43         n_ports = rte_eth_dev_count_avail();
44         if (!n_ports) {
45                 plt_err("No active ethernet ports found.");
46                 return -1;
47         }
48
49         rte_tel_data_start_dict(d);
50         rte_tel_data_add_dict_int(d, "n_ports", n_ports);
51
52         i_data = rte_tel_data_alloc();
53         rte_tel_data_start_array(i_data, RTE_TEL_U64_VAL);
54
55         for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
56                 /* Skip if port is unused */
57                 if (!rte_eth_dev_is_valid_port(i))
58                         continue;
59
60                 eth_dev = &rte_eth_devices[i];
61                 if (eth_dev) {
62                         memset(&eth_info, 0, sizeof(eth_info));
63                         info = &eth_info.info;
64                         dev = cnxk_eth_pmd_priv(eth_dev);
65                         if (dev) {
66                                 info->inl_dev_pf_func =
67                                         roc_nix_inl_dev_pffunc_get();
68                                 info->pf_func = roc_nix_get_pf_func(&dev->nix);
69                                 info->max_mac_entries = dev->max_mac_entries;
70                                 info->dmac_filter_ena = dev->dmac_filter_enable;
71                                 info->dmac_filter_count =
72                                         dev->dmac_filter_count;
73                                 info->ptype_disable = dev->ptype_disable;
74                                 info->scalar_ena = dev->scalar_ena;
75                                 info->ptp_ena = dev->ptp_en;
76                                 info->rx_offload_flags = dev->rx_offload_flags;
77                                 info->tx_offload_flags = dev->tx_offload_flags;
78                         }
79
80                         for (j = 0; j < ETH_INFO_SZ; j++)
81                                 rte_tel_data_add_array_u64(i_data,
82                                                            eth_info.val[j]);
83
84                         j++;
85                 }
86         }
87
88         rte_tel_data_add_dict_container(d, "info", i_data, 0);
89         return 0;
90 }
91
92 RTE_INIT(cnxk_ethdev_init_telemetry)
93 {
94         rte_telemetry_register_cmd("/cnxk/ethdev/info", ethdev_tel_handle_info,
95                                    "Returns ethdev device information");
96 }