LCOV - code coverage report
Current view: top level - drivers/net/sfc - sfc_kvargs.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 35 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 24 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *
       3                 :            :  * Copyright(c) 2019-2021 Xilinx, Inc.
       4                 :            :  * Copyright(c) 2016-2019 Solarflare Communications Inc.
       5                 :            :  *
       6                 :            :  * This software was jointly developed between OKTET Labs (under contract
       7                 :            :  * for Solarflare) and Solarflare Communications, Inc.
       8                 :            :  */
       9                 :            : 
      10                 :            : #include <stdbool.h>
      11                 :            : #include <strings.h>
      12                 :            : 
      13                 :            : #include <rte_devargs.h>
      14                 :            : #include <rte_kvargs.h>
      15                 :            : 
      16                 :            : #include "sfc.h"
      17                 :            : #include "sfc_kvargs.h"
      18                 :            : 
      19                 :            : int
      20                 :          0 : sfc_kvargs_parse(struct sfc_adapter *sa)
      21                 :            : {
      22                 :          0 :         struct rte_eth_dev *eth_dev = (sa)->eth_dev;
      23                 :          0 :         struct rte_devargs *devargs = eth_dev->device->devargs;
      24                 :          0 :         const char **params = (const char *[]){
      25                 :            :                 SFC_KVARG_SWITCH_MODE,
      26                 :            :                 SFC_KVARG_REPRESENTOR,
      27                 :            :                 SFC_KVARG_STATS_UPDATE_PERIOD_MS,
      28                 :            :                 SFC_KVARG_PERF_PROFILE,
      29                 :            :                 SFC_KVARG_RX_DATAPATH,
      30                 :            :                 SFC_KVARG_TX_DATAPATH,
      31                 :            :                 SFC_KVARG_FW_VARIANT,
      32                 :            :                 SFC_KVARG_RXD_WAIT_TIMEOUT_NS,
      33                 :            :                 RTE_DEVARGS_KEY_CLASS,
      34                 :            :                 NULL,
      35                 :            :         };
      36                 :            : 
      37         [ #  # ]:          0 :         if (devargs == NULL)
      38                 :            :                 return 0;
      39                 :            : 
      40                 :          0 :         sa->kvargs = rte_kvargs_parse(devargs->args, params);
      41         [ #  # ]:          0 :         if (sa->kvargs == NULL)
      42                 :          0 :                 return EINVAL;
      43                 :            : 
      44                 :            :         return 0;
      45                 :            : }
      46                 :            : 
      47                 :            : void
      48                 :          0 : sfc_kvargs_cleanup(struct sfc_adapter *sa)
      49                 :            : {
      50                 :          0 :         rte_kvargs_free(sa->kvargs);
      51                 :          0 : }
      52                 :            : 
      53                 :            : static int
      54                 :            : sfc_kvarg_match_value(const char *value, const char * const *values,
      55                 :            :                       unsigned int n_values)
      56                 :            : {
      57                 :            :         unsigned int i;
      58                 :            : 
      59   [ #  #  #  # ]:          0 :         for (i = 0; i < n_values; ++i)
      60   [ #  #  #  # ]:          0 :                 if (strcasecmp(value, values[i]) == 0)
      61                 :            :                         return 1;
      62                 :            : 
      63                 :            :         return 0;
      64                 :            : }
      65                 :            : 
      66                 :            : int
      67                 :          0 : sfc_kvargs_process(struct sfc_adapter *sa, const char *key_match,
      68                 :            :                    arg_handler_t handler, void *opaque_arg)
      69                 :            : {
      70         [ #  # ]:          0 :         if (sa->kvargs == NULL)
      71                 :            :                 return 0;
      72                 :            : 
      73                 :          0 :         return -rte_kvargs_process(sa->kvargs, key_match, handler, opaque_arg);
      74                 :            : }
      75                 :            : 
      76                 :            : int
      77                 :          0 : sfc_kvargs_process_opt(struct sfc_adapter *sa, const char *key_match,
      78                 :            :                        arg_handler_t handler, void *opaque_arg)
      79                 :            : {
      80         [ #  # ]:          0 :         if (sa->kvargs == NULL)
      81                 :            :                 return 0;
      82                 :            : 
      83                 :          0 :         return -rte_kvargs_process_opt(sa->kvargs, key_match, handler, opaque_arg);
      84                 :            : }
      85                 :            : 
      86                 :            : int
      87                 :          0 : sfc_kvarg_bool_handler(__rte_unused const char *key,
      88                 :            :                        const char *value_str, void *opaque)
      89                 :            : {
      90                 :          0 :         const char * const true_strs[] = {
      91                 :            :                 "1", "y", "yes", "on", "true"
      92                 :            :         };
      93                 :          0 :         const char * const false_strs[] = {
      94                 :            :                 "0", "n", "no", "off", "false"
      95                 :            :         };
      96                 :            :         bool *value = opaque;
      97                 :            : 
      98         [ #  # ]:          0 :         if (sfc_kvarg_match_value(value_str, true_strs,
      99                 :            :                                   RTE_DIM(true_strs)))
     100                 :          0 :                 *value = true;
     101         [ #  # ]:          0 :         else if (sfc_kvarg_match_value(value_str, false_strs,
     102                 :            :                                        RTE_DIM(false_strs)))
     103                 :          0 :                 *value = false;
     104                 :            :         else
     105                 :            :                 return -EINVAL;
     106                 :            : 
     107                 :            :         return 0;
     108                 :            : }
     109                 :            : 
     110                 :            : int
     111                 :          0 : sfc_kvarg_long_handler(__rte_unused const char *key,
     112                 :            :                        const char *value_str, void *opaque)
     113                 :            : {
     114                 :            :         long value;
     115                 :            :         char *endptr;
     116                 :            : 
     117         [ #  # ]:          0 :         if (!opaque)
     118                 :            :                 return -EINVAL;
     119                 :            : 
     120                 :          0 :         value = strtol(value_str, &endptr, 0);
     121         [ #  # ]:          0 :         if (endptr == value_str)
     122                 :            :                 return -EINVAL;
     123                 :            : 
     124                 :          0 :         *(long *)opaque = value;
     125                 :            : 
     126                 :          0 :         return 0;
     127                 :            : }
     128                 :            : 
     129                 :            : int
     130                 :          0 : sfc_kvarg_string_handler(__rte_unused const char *key,
     131                 :            :                          const char *value_str, void *opaque)
     132                 :            : {
     133                 :          0 :         *(const char **)opaque = value_str;
     134                 :            : 
     135                 :          0 :         return 0;
     136                 :            : }

Generated by: LCOV version 1.14