1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2022 Intel Corporation
7 #include "rte_ethdev.h"
8 #include <rte_common.h>
9 #include "sff_telemetry.h"
10 #include <telemetry_data.h>
13 sff_port_module_eeprom_parse(uint16_t port_id, struct rte_tel_data *d)
15 struct rte_eth_dev_module_info minfo;
16 struct rte_dev_eeprom_info einfo;
20 RTE_ETHDEV_LOG(ERR, "Dict invalid\n");
24 ret = rte_eth_dev_get_module_info(port_id, &minfo);
28 RTE_ETHDEV_LOG(ERR, "Port index %d invalid\n", port_id);
31 RTE_ETHDEV_LOG(ERR, "Operation not supported by device\n");
34 RTE_ETHDEV_LOG(ERR, "Device is removed\n");
37 RTE_ETHDEV_LOG(ERR, "Unable to get port module info, %d\n", ret);
44 einfo.length = minfo.eeprom_len;
45 einfo.data = calloc(1, minfo.eeprom_len);
46 if (einfo.data == NULL) {
47 RTE_ETHDEV_LOG(ERR, "Allocation of port %u EEPROM data failed\n", port_id);
51 ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
55 RTE_ETHDEV_LOG(ERR, "Port index %d invalid\n", port_id);
58 RTE_ETHDEV_LOG(ERR, "Operation not supported by device\n");
61 RTE_ETHDEV_LOG(ERR, "Device is removed\n");
64 RTE_ETHDEV_LOG(ERR, "Unable to get port module EEPROM, %d\n", ret);
72 /* parsing module EEPROM data base on different module type */
73 case RTE_ETH_MODULE_SFF_8079:
74 sff_8079_show_all(einfo.data, d);
77 RTE_ETHDEV_LOG(NOTICE, "Unsupported module type: %u\n", minfo.type);
85 ssf_add_dict_string(struct rte_tel_data *d, const char *name_str, const char *value_str)
87 struct tel_dict_entry *e = &d->data.dict[d->data_len];
89 if (d->type != RTE_TEL_DICT)
91 if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) {
92 RTE_ETHDEV_LOG(ERR, "data_len has exceeded the maximum number of inserts\n");
96 e->type = RTE_TEL_STRING_VAL;
97 /* append different values for same keys */
98 if (d->data_len > 0) {
99 struct tel_dict_entry *previous = &d->data.dict[d->data_len - 1];
100 if (strcmp(previous->name, name_str) == 0) {
101 strlcat(previous->value.sval, "; ", RTE_TEL_MAX_STRING_LEN);
102 strlcat(previous->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
106 strlcpy(e->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
107 strlcpy(e->name, name_str, RTE_TEL_MAX_STRING_LEN);
115 eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused, const char *params,
116 struct rte_tel_data *d)
121 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
125 port_id = strtoul(params, &end_param, 0);
128 RTE_ETHDEV_LOG(ERR, "Invalid argument, %d\n", errno);
132 if (*end_param != '\0')
133 RTE_ETHDEV_LOG(NOTICE,
134 "Extra parameters [%s] passed to ethdev telemetry command, ignoring\n",
137 rte_tel_data_start_dict(d);
139 sff_port_module_eeprom_parse(port_id, d);