LCOV - code coverage report
Current view: top level - lib/ethdev - sff_telemetry.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 20 78 25.6 %
Date: 2026-11-01 19:11:22 Functions: 2 3 66.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 40 27.5 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2022 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <ctype.h>
       6                 :            : #include <errno.h>
       7                 :            : #include <stdlib.h>
       8                 :            : 
       9                 :            : #include "rte_ethdev.h"
      10                 :            : #include <rte_common.h>
      11                 :            : #include "sff_common.h"
      12                 :            : #include "sff_telemetry.h"
      13                 :            : #include <telemetry_data.h>
      14                 :            : 
      15                 :            : static void
      16                 :          0 : sff_tel_add_field(const char *name_str, const char *value_str, void *arg)
      17                 :            : {
      18                 :            :         struct rte_tel_data *d = arg;
      19                 :          0 :         struct tel_dict_entry *e = &d->data.dict[d->data_len];
      20                 :            : 
      21         [ #  # ]:          0 :         if (d->type != TEL_DICT)
      22                 :            :                 return;
      23         [ #  # ]:          0 :         if (d->data_len >= RTE_TEL_MAX_DICT_ENTRIES) {
      24                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "data_len has exceeded the maximum number of inserts");
      25                 :          0 :                 return;
      26                 :            :         }
      27                 :            : 
      28                 :          0 :         e->type = RTE_TEL_STRING_VAL;
      29                 :            :         /* append different values for same keys */
      30         [ #  # ]:          0 :         if (d->data_len > 0) {
      31                 :          0 :                 struct tel_dict_entry *previous = &d->data.dict[d->data_len - 1];
      32         [ #  # ]:          0 :                 if (strcmp(previous->name, name_str) == 0) {
      33                 :          0 :                         strlcat(previous->value.sval, "; ", RTE_TEL_MAX_STRING_LEN);
      34                 :          0 :                         strlcat(previous->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
      35                 :          0 :                         return;
      36                 :            :                 }
      37                 :            :         }
      38                 :          0 :         strlcpy(e->value.sval, value_str, RTE_TEL_MAX_STRING_LEN);
      39                 :          0 :         strlcpy(e->name, name_str, RTE_TEL_MAX_STRING_LEN);
      40                 :          0 :         d->data_len++;
      41                 :            : }
      42                 :            : 
      43                 :            : static void
      44                 :          1 : sff_port_module_eeprom_parse(uint16_t port_id, struct rte_tel_data *d)
      45                 :            : {
      46                 :          1 :         struct sff_output out = { .field_cb = sff_tel_add_field, .arg = d };
      47                 :            :         struct rte_eth_dev_module_info minfo;
      48                 :            :         struct rte_dev_eeprom_info einfo;
      49                 :            :         int ret;
      50                 :            : 
      51         [ -  + ]:          1 :         if (d == NULL) {
      52                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Dict invalid");
      53                 :          1 :                 return;
      54                 :            :         }
      55                 :            : 
      56                 :          1 :         ret = rte_eth_dev_get_module_info(port_id, &minfo);
      57         [ +  - ]:          1 :         if (ret != 0) {
      58   [ -  +  -  - ]:          1 :                 switch (ret) {
      59                 :          0 :                 case -ENODEV:
      60                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Port index %d invalid", port_id);
      61                 :          0 :                         break;
      62                 :          1 :                 case -ENOTSUP:
      63                 :          1 :                         RTE_ETHDEV_LOG_LINE(ERR, "Operation not supported by device");
      64                 :          1 :                         break;
      65                 :          0 :                 case -EIO:
      66                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Device is removed");
      67                 :          0 :                         break;
      68                 :          0 :                 default:
      69                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Unable to get port module info, %d", ret);
      70                 :          0 :                         break;
      71                 :            :                 }
      72                 :          1 :                 return;
      73                 :            :         }
      74                 :            : 
      75                 :          0 :         einfo.offset = 0;
      76                 :          0 :         einfo.length = minfo.eeprom_len;
      77                 :          0 :         einfo.data = calloc(1, minfo.eeprom_len);
      78         [ #  # ]:          0 :         if (einfo.data == NULL) {
      79                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Allocation of port %u EEPROM data failed", port_id);
      80                 :          0 :                 return;
      81                 :            :         }
      82                 :            : 
      83                 :          0 :         ret = rte_eth_dev_get_module_eeprom(port_id, &einfo);
      84         [ #  # ]:          0 :         if (ret != 0) {
      85   [ #  #  #  # ]:          0 :                 switch (ret) {
      86                 :          0 :                 case -ENODEV:
      87                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Port index %d invalid", port_id);
      88                 :          0 :                         break;
      89                 :          0 :                 case -ENOTSUP:
      90                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Operation not supported by device");
      91                 :          0 :                         break;
      92                 :          0 :                 case -EIO:
      93                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Device is removed");
      94                 :          0 :                         break;
      95                 :          0 :                 default:
      96                 :          0 :                         RTE_ETHDEV_LOG_LINE(ERR, "Unable to get port module EEPROM, %d", ret);
      97                 :          0 :                         break;
      98                 :            :                 }
      99                 :          0 :                 free(einfo.data);
     100                 :          0 :                 return;
     101                 :            :         }
     102                 :            : 
     103                 :          0 :         ret = sff_decode_module_eeprom(minfo.type, einfo.data, einfo.length, &out);
     104         [ #  # ]:          0 :         if (ret == -ENOTSUP)
     105                 :          0 :                 RTE_ETHDEV_LOG_LINE(NOTICE, "Unsupported module type: %u", minfo.type);
     106         [ #  # ]:          0 :         else if (ret != 0)
     107                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Port %u module EEPROM is too short: %u bytes",
     108                 :            :                         port_id, einfo.length);
     109                 :            : 
     110                 :          0 :         free(einfo.data);
     111                 :            : }
     112                 :            : 
     113                 :            : int
     114                 :          3 : eth_dev_handle_port_module_eeprom(const char *cmd __rte_unused, const char *params,
     115                 :            :                                   struct rte_tel_data *d)
     116                 :            : {
     117                 :            :         char *end_param;
     118                 :            :         uint64_t port_id;
     119                 :            : 
     120   [ +  +  +  -  :          3 :         if (params == NULL || strlen(params) == 0 || !isdigit(*params))
                   +  + ]
     121                 :            :                 return -1;
     122                 :            : 
     123                 :          1 :         errno = 0;
     124                 :          1 :         port_id = strtoul(params, &end_param, 0);
     125                 :            : 
     126   [ +  -  -  + ]:          1 :         if (errno != 0 || port_id >= UINT16_MAX) {
     127                 :          0 :                 RTE_ETHDEV_LOG_LINE(ERR, "Invalid argument, %d", errno);
     128                 :          0 :                 return -1;
     129                 :            :         }
     130                 :            : 
     131         [ -  + ]:          1 :         if (*end_param != '\0')
     132                 :          0 :                 RTE_ETHDEV_LOG_LINE(NOTICE,
     133                 :            :                         "Extra parameters [%s] passed to ethdev telemetry command, ignoring",
     134                 :            :                                 end_param);
     135                 :            : 
     136                 :          1 :         rte_tel_data_start_dict(d);
     137                 :            : 
     138                 :          1 :         sff_port_module_eeprom_parse(port_id, d);
     139                 :            : 
     140                 :          1 :         return 0;
     141                 :            : }

Generated by: LCOV version 1.14