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 */
74 RTE_ETHDEV_LOG(NOTICE, "Unsupported module type: %u\n", minfo.type);
82 ssf_add_dict_string(struct rte_tel_data *d, const char *name_str, const char *value_str)
84 struct tel_dict_entry *e = &d->data.dict[d->data_len];
86 if (d->type != RTE_TEL_DICT)
88 if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) {
89 RTE_ETHDEV_LOG(ERR, "data_len has exceeded the maximum number of inserts\n");
93 e->type = RTE_TEL_STRING_VAL;
94 /* append different values for same keys */
95 if (d->data_len > 0) {
96 struct tel_dict_entry *previous = &d->data.dict[d->data_len - 1];
97 if (strcmp(previous->name, name_str) == 0) {
98 strlcat(previous->value.sval, "; ", RTE_TEL_MAX_STRING_LEN);
99 strlcat(previous->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
103 strlcpy(e->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
104 strlcpy(e->name, name_str, RTE_TEL_MAX_STRING_LEN);
112 eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused, const char *params,
113 struct rte_tel_data *d)
118 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
122 port_id = strtoul(params, &end_param, 0);
125 RTE_ETHDEV_LOG(ERR, "Invalid argument, %d\n", errno);
129 if (*end_param != '\0')
130 RTE_ETHDEV_LOG(NOTICE,
131 "Extra parameters [%s] passed to ethdev telemetry command, ignoring\n",
134 rte_tel_data_start_dict(d);
136 sff_port_module_eeprom_parse(port_id, d);