LCOV - code coverage report
Current view: top level - drivers/net/cnxk - cnxk_ethdev_sec_telemetry.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 3 107 2.8 %
Date: 2024-01-22 16:13:49 Functions: 1 6 16.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 44 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2022 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <ctype.h>
       6                 :            : 
       7                 :            : #include <rte_telemetry.h>
       8                 :            : 
       9                 :            : #include <roc_api.h>
      10                 :            : 
      11                 :            : #include "cnxk_ethdev.h"
      12                 :            : 
      13                 :            : #define STR_MAXLEN 20
      14                 :            : #define W0_MAXLEN  21
      15                 :            : 
      16                 :            : static int
      17                 :          0 : copy_outb_sa_9k(struct rte_tel_data *d, uint32_t i, void *sa)
      18                 :            : {
      19                 :            :         union {
      20                 :            :                 struct roc_ie_on_sa_ctl ctl;
      21                 :            :                 uint64_t u64;
      22                 :            :         } w0;
      23                 :            :         struct roc_ie_on_outb_sa *out_sa;
      24                 :            :         char strw0[W0_MAXLEN];
      25                 :            :         char str[STR_MAXLEN];
      26                 :            : 
      27                 :            :         out_sa = (struct roc_ie_on_outb_sa *)sa;
      28                 :          0 :         w0.ctl = out_sa->common_sa.ctl;
      29                 :            : 
      30                 :            :         snprintf(str, sizeof(str), "outsa_w0_%u", i);
      31                 :            :         snprintf(strw0, sizeof(strw0), "%" PRIu64, w0.u64);
      32                 :          0 :         rte_tel_data_add_dict_string(d, str, strw0);
      33                 :            : 
      34                 :          0 :         return 0;
      35                 :            : }
      36                 :            : 
      37                 :            : static int
      38                 :          0 : copy_inb_sa_9k(struct rte_tel_data *d, uint32_t i, void *sa)
      39                 :            : {
      40                 :            :         union {
      41                 :            :                 struct roc_ie_on_sa_ctl ctl;
      42                 :            :                 uint64_t u64;
      43                 :            :         } w0;
      44                 :            :         struct roc_ie_on_inb_sa *in_sa;
      45                 :            :         char strw0[W0_MAXLEN];
      46                 :            :         char str[STR_MAXLEN];
      47                 :            : 
      48                 :            :         in_sa = (struct roc_ie_on_inb_sa *)sa;
      49                 :          0 :         w0.ctl = in_sa->common_sa.ctl;
      50                 :            : 
      51                 :            :         snprintf(str, sizeof(str), "insa_w0_%u", i);
      52                 :            :         snprintf(strw0, sizeof(strw0), "%" PRIu64, w0.u64);
      53                 :          0 :         rte_tel_data_add_dict_string(d, str, strw0);
      54                 :            : 
      55                 :            :         snprintf(str, sizeof(str), "insa_esnh_%u", i);
      56                 :          0 :         rte_tel_data_add_dict_uint(d, str, in_sa->common_sa.seq_t.th);
      57                 :            : 
      58                 :            :         snprintf(str, sizeof(str), "insa_esnl_%u", i);
      59                 :          0 :         rte_tel_data_add_dict_uint(d, str, in_sa->common_sa.seq_t.tl);
      60                 :            : 
      61                 :          0 :         return 0;
      62                 :            : }
      63                 :            : 
      64                 :            : static int
      65                 :          0 : copy_outb_sa_10k(struct rte_tel_data *d, uint32_t i, void *sa)
      66                 :            : {
      67                 :            :         struct roc_ot_ipsec_outb_sa *out_sa;
      68                 :            :         struct rte_tel_data *outer_hdr;
      69                 :            :         char str[STR_MAXLEN];
      70                 :            :         char s64[W0_MAXLEN];
      71                 :            :         uint32_t j;
      72                 :            : 
      73                 :            :         out_sa = (struct roc_ot_ipsec_outb_sa *)sa;
      74                 :            : 
      75                 :            :         snprintf(str, sizeof(str), "outsa_w0_%u", i);
      76                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->w0.u64);
      77                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
      78                 :            : 
      79                 :            :         snprintf(str, sizeof(str), "outsa_w1_%u", i);
      80                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->w1.u64);
      81                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
      82                 :            : 
      83                 :            :         snprintf(str, sizeof(str), "outsa_w2_%u", i);
      84                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->w2.u64);
      85                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
      86                 :            : 
      87                 :            :         snprintf(str, sizeof(str), "outsa_w10_%u", i);
      88                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->w10.u64);
      89                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
      90                 :            : 
      91                 :          0 :         outer_hdr = rte_tel_data_alloc();
      92         [ #  # ]:          0 :         if (!outer_hdr) {
      93                 :          0 :                 plt_err("Could not allocate space for outer header");
      94                 :          0 :                 return -ENOMEM;
      95                 :            :         }
      96                 :            : 
      97                 :          0 :         rte_tel_data_start_array(outer_hdr, RTE_TEL_UINT_VAL);
      98                 :            : 
      99         [ #  # ]:          0 :         for (j = 0; j < RTE_DIM(out_sa->outer_hdr.ipv6.src_addr); j++)
     100                 :          0 :                 rte_tel_data_add_array_uint(outer_hdr,
     101                 :          0 :                                             out_sa->outer_hdr.ipv6.src_addr[j]);
     102                 :            : 
     103         [ #  # ]:          0 :         for (j = 0; j < RTE_DIM(out_sa->outer_hdr.ipv6.dst_addr); j++)
     104                 :          0 :                 rte_tel_data_add_array_uint(outer_hdr,
     105                 :          0 :                                             out_sa->outer_hdr.ipv6.dst_addr[j]);
     106                 :            : 
     107                 :            :         snprintf(str, sizeof(str), "outsa_outer_hdr_%u", i);
     108                 :          0 :         rte_tel_data_add_dict_container(d, str, outer_hdr, 0);
     109                 :            : 
     110                 :            :         snprintf(str, sizeof(str), "outsa_errctl_%u", i);
     111                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->ctx.err_ctl.u64);
     112                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     113                 :            : 
     114                 :            :         snprintf(str, sizeof(str), "outsa_esnval_%u", i);
     115                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->ctx.esn_val);
     116                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     117                 :            : 
     118                 :            :         snprintf(str, sizeof(str), "outsa_hl_%u", i);
     119                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->ctx.hard_life);
     120                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     121                 :            : 
     122                 :            :         snprintf(str, sizeof(str), "outsa_sl_%u", i);
     123                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->ctx.soft_life);
     124                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     125                 :            : 
     126                 :            :         snprintf(str, sizeof(str), "outsa_octs_%u", i);
     127                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->ctx.mib_octs);
     128                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     129                 :            : 
     130                 :            :         snprintf(str, sizeof(str), "outsa_pkts_%u", i);
     131                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, out_sa->ctx.mib_pkts);
     132                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     133                 :            : 
     134                 :          0 :         return 0;
     135                 :            : }
     136                 :            : 
     137                 :            : static int
     138                 :          0 : copy_inb_sa_10k(struct rte_tel_data *d, uint32_t i, void *sa)
     139                 :            : {
     140                 :            :         struct roc_ot_ipsec_inb_sa *in_sa;
     141                 :            :         struct rte_tel_data *outer_hdr;
     142                 :            :         char str[STR_MAXLEN];
     143                 :            :         char s64[W0_MAXLEN];
     144                 :            :         uint32_t j;
     145                 :            : 
     146                 :            :         in_sa = (struct roc_ot_ipsec_inb_sa *)sa;
     147                 :            : 
     148                 :            :         snprintf(str, sizeof(str), "insa_w0_%u", i);
     149                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->w0.u64);
     150                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     151                 :            : 
     152                 :            :         snprintf(str, sizeof(str), "insa_w1_%u", i);
     153                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->w1.u64);
     154                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     155                 :            : 
     156                 :            :         snprintf(str, sizeof(str), "insa_w2_%u", i);
     157                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->w2.u64);
     158                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     159                 :            : 
     160                 :            :         snprintf(str, sizeof(str), "insa_w10_%u", i);
     161                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->w10.u64);
     162                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     163                 :            : 
     164                 :          0 :         outer_hdr = rte_tel_data_alloc();
     165         [ #  # ]:          0 :         if (!outer_hdr) {
     166                 :          0 :                 plt_err("Could not allocate space for outer header");
     167                 :          0 :                 return -ENOMEM;
     168                 :            :         }
     169                 :            : 
     170                 :          0 :         rte_tel_data_start_array(outer_hdr, RTE_TEL_UINT_VAL);
     171                 :            : 
     172         [ #  # ]:          0 :         for (j = 0; j < RTE_DIM(in_sa->outer_hdr.ipv6.src_addr); j++)
     173                 :          0 :                 rte_tel_data_add_array_uint(outer_hdr,
     174                 :          0 :                                             in_sa->outer_hdr.ipv6.src_addr[j]);
     175                 :            : 
     176         [ #  # ]:          0 :         for (j = 0; j < RTE_DIM(in_sa->outer_hdr.ipv6.dst_addr); j++)
     177                 :          0 :                 rte_tel_data_add_array_uint(outer_hdr,
     178                 :          0 :                                             in_sa->outer_hdr.ipv6.dst_addr[j]);
     179                 :            : 
     180                 :            :         snprintf(str, sizeof(str), "insa_outer_hdr_%u", i);
     181                 :          0 :         rte_tel_data_add_dict_container(d, str, outer_hdr, 0);
     182                 :            : 
     183                 :            :         snprintf(str, sizeof(str), "insa_arbase_%u", i);
     184                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->ctx.ar_base);
     185                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     186                 :            : 
     187                 :            :         snprintf(str, sizeof(str), "insa_ar_validm_%u", i);
     188                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->ctx.ar_valid_mask);
     189                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     190                 :            : 
     191                 :            :         snprintf(str, sizeof(str), "insa_hl_%u", i);
     192                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->ctx.hard_life);
     193                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     194                 :            : 
     195                 :            :         snprintf(str, sizeof(str), "insa_sl_%u", i);
     196                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->ctx.soft_life);
     197                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     198                 :            : 
     199                 :            :         snprintf(str, sizeof(str), "insa_octs_%u", i);
     200                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->ctx.mib_octs);
     201                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     202                 :            : 
     203                 :            :         snprintf(str, sizeof(str), "insa_pkts_%u", i);
     204                 :          0 :         snprintf(s64, sizeof(s64), "%" PRIu64, in_sa->ctx.mib_pkts);
     205                 :          0 :         rte_tel_data_add_dict_string(d, str, s64);
     206                 :            : 
     207                 :          0 :         return 0;
     208                 :            : }
     209                 :            : 
     210                 :            : static int
     211                 :          0 : ethdev_sec_tel_handle_info(const char *cmd __rte_unused, const char *params,
     212                 :            :                            struct rte_tel_data *d)
     213                 :            : {
     214                 :            :         struct cnxk_eth_sec_sess *eth_sec, *tvar;
     215                 :            :         struct rte_eth_dev *eth_dev;
     216                 :            :         struct cnxk_eth_dev *dev;
     217                 :            :         uint16_t port_id;
     218                 :            :         char *end_p;
     219                 :            :         uint32_t i;
     220                 :            :         int ret;
     221                 :            : 
     222   [ #  #  #  #  :          0 :         if (params == NULL || strlen(params) == 0 || !isdigit(*params))
                   #  # ]
     223                 :            :                 return -EINVAL;
     224                 :            : 
     225                 :          0 :         port_id = strtoul(params, &end_p, 0);
     226         [ #  # ]:          0 :         if (errno != 0)
     227                 :            :                 return -EINVAL;
     228                 :            : 
     229         [ #  # ]:          0 :         if (*end_p != '\0')
     230                 :          0 :                 plt_err("Extra parameters passed to telemetry, ignoring it");
     231                 :            : 
     232         [ #  # ]:          0 :         if (!rte_eth_dev_is_valid_port(port_id)) {
     233                 :          0 :                 plt_err("Invalid port id %u", port_id);
     234                 :          0 :                 return -EINVAL;
     235                 :            :         }
     236                 :            : 
     237                 :            :         eth_dev = &rte_eth_devices[port_id];
     238                 :            :         if (!eth_dev) {
     239                 :            :                 plt_err("Ethdev not available");
     240                 :            :                 return -EINVAL;
     241                 :            :         }
     242                 :            : 
     243                 :            :         dev = cnxk_eth_pmd_priv(eth_dev);
     244                 :            : 
     245                 :          0 :         rte_tel_data_start_dict(d);
     246                 :            : 
     247                 :          0 :         rte_tel_data_add_dict_int(d, "nb_outb_sa", dev->outb.nb_sess);
     248                 :            : 
     249                 :            :         i = 0;
     250         [ #  # ]:          0 :         if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY) {
     251                 :            :                 tvar = NULL;
     252   [ #  #  #  # ]:          0 :                 RTE_TAILQ_FOREACH_SAFE(eth_sec, &dev->outb.list, entry, tvar) {
     253         [ #  # ]:          0 :                         if (roc_model_is_cn10k())
     254                 :          0 :                                 ret = copy_outb_sa_10k(d, i++, eth_sec->sa);
     255                 :            :                         else
     256                 :          0 :                                 ret = copy_outb_sa_9k(d, i++, eth_sec->sa);
     257         [ #  # ]:          0 :                         if (ret < 0)
     258                 :          0 :                                 return ret;
     259                 :            :                 }
     260                 :            :         }
     261                 :            : 
     262                 :          0 :         rte_tel_data_add_dict_int(d, "nb_inb_sa", dev->inb.nb_sess);
     263                 :            : 
     264                 :            :         i = 0;
     265         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
     266                 :            :                 tvar = NULL;
     267   [ #  #  #  # ]:          0 :                 RTE_TAILQ_FOREACH_SAFE(eth_sec, &dev->inb.list, entry, tvar) {
     268         [ #  # ]:          0 :                         if (roc_model_is_cn10k())
     269                 :          0 :                                 ret = copy_inb_sa_10k(d, i++, eth_sec->sa);
     270                 :            :                         else
     271                 :          0 :                                 ret = copy_inb_sa_9k(d, i++, eth_sec->sa);
     272         [ #  # ]:          0 :                         if (ret < 0)
     273                 :          0 :                                 return ret;
     274                 :            :                 }
     275                 :            :         }
     276                 :            : 
     277                 :            :         return 0;
     278                 :            : }
     279                 :            : 
     280                 :        235 : RTE_INIT(cnxk_ipsec_init_telemetry)
     281                 :            : {
     282                 :        235 :         rte_telemetry_register_cmd("/cnxk/ipsec/info",
     283                 :            :                                    ethdev_sec_tel_handle_info,
     284                 :            :                                    "Returns ipsec info. Parameters: port id");
     285                 :        235 : }

Generated by: LCOV version 1.14