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 if (i_data == NULL) 54 return -ENOMEM; 55 rte_tel_data_start_array(i_data, RTE_TEL_U64_VAL); 56 57 for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 58 /* Skip if port is unused */ 59 if (!rte_eth_dev_is_valid_port(i)) 60 continue; 61 62 eth_dev = &rte_eth_devices[i]; 63 if (eth_dev) { 64 memset(ð_info, 0, sizeof(eth_info)); 65 info = ð_info.info; 66 dev = cnxk_eth_pmd_priv(eth_dev); 67 if (dev) { 68 info->inl_dev_pf_func = 69 roc_nix_inl_dev_pffunc_get(); 70 info->pf_func = roc_nix_get_pf_func(&dev->nix); 71 info->max_mac_entries = dev->max_mac_entries; 72 info->dmac_filter_ena = dev->dmac_filter_enable; 73 info->dmac_filter_count = 74 dev->dmac_filter_count; 75 info->ptype_disable = dev->ptype_disable; 76 info->scalar_ena = dev->scalar_ena; 77 info->ptp_ena = dev->ptp_en; 78 info->rx_offload_flags = dev->rx_offload_flags; 79 info->tx_offload_flags = dev->tx_offload_flags; 80 } 81 82 for (j = 0; j < ETH_INFO_SZ; j++) 83 rte_tel_data_add_array_u64(i_data, 84 eth_info.val[j]); 85 86 j++; 87 } 88 } 89 90 rte_tel_data_add_dict_container(d, "info", i_data, 0); 91 return 0; 92 } 93 94 RTE_INIT(cnxk_ethdev_init_telemetry) 95 { 96 rte_telemetry_register_cmd("/cnxk/ethdev/info", ethdev_tel_handle_info, 97 "Returns ethdev device information"); 98 } 99