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);
76 case RTE_ETH_MODULE_SFF_8472:
77 sff_8079_show_all(einfo.data, d);
78 sff_8472_show_all(einfo.data, d);
80 case RTE_ETH_MODULE_SFF_8436:
81 case RTE_ETH_MODULE_SFF_8636:
82 sff_8636_show_all(einfo.data, einfo.length, d);
85 RTE_ETHDEV_LOG(NOTICE, "Unsupported module type: %u\n", minfo.type);
93 ssf_add_dict_string(struct rte_tel_data *d, const char *name_str, const char *value_str)
95 struct tel_dict_entry *e = &d->data.dict[d->data_len];
97 if (d->type != RTE_TEL_DICT)
99 if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) {
100 RTE_ETHDEV_LOG(ERR, "data_len has exceeded the maximum number of inserts\n");
104 e->type = RTE_TEL_STRING_VAL;
105 /* append different values for same keys */
106 if (d->data_len > 0) {
107 struct tel_dict_entry *previous = &d->data.dict[d->data_len - 1];
108 if (strcmp(previous->name, name_str) == 0) {
109 strlcat(previous->value.sval, "; ", RTE_TEL_MAX_STRING_LEN);
110 strlcat(previous->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
114 strlcpy(e->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
115 strlcpy(e->name, name_str, RTE_TEL_MAX_STRING_LEN);
123 eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused, const char *params,
124 struct rte_tel_data *d)
129 if (params == NULL || strlen(params) == 0 || !isdigit(*params))
133 port_id = strtoul(params, &end_param, 0);
136 RTE_ETHDEV_LOG(ERR, "Invalid argument, %d\n", errno);
140 if (*end_param != '\0')
141 RTE_ETHDEV_LOG(NOTICE,
142 "Extra parameters [%s] passed to ethdev telemetry command, ignoring\n",
145 rte_tel_data_start_dict(d);
147 sff_port_module_eeprom_parse(port_id, d);