LCOV - code coverage report
Current view: top level - drivers/net/ntnic/ntutil - nt_service.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 38 0.0 %
Date: 2025-12-01 19:08:10 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 18 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2025 Napatech A/S
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_service.h>
       6                 :            : #include <rte_cycles.h>
       7                 :            : 
       8                 :            : #include "nt_service.h"
       9                 :            : #include "ntlog.h"
      10                 :            : 
      11                 :            : #define NT_SERVICE_UNKNOWN_ID (-1)
      12                 :            : 
      13                 :            : static struct nt_service g_nt_services[RTE_NTNIC_SERVICE_MAX] = {
      14                 :            :         [RTE_NTNIC_SERVICE_FLM_UPDATE] = {
      15                 :            :                 .tag = RTE_NTNIC_SERVICE_FLM_UPDATE,
      16                 :            :                 .id = NT_SERVICE_UNKNOWN_ID,
      17                 :            :                 .lcore = RTE_MAX_LCORE,
      18                 :            :                 .initialized = false,
      19                 :            :         },
      20                 :            :         [RTE_NTNIC_SERVICE_STAT] = {
      21                 :            :                 .tag = RTE_NTNIC_SERVICE_STAT,
      22                 :            :                 .id = NT_SERVICE_UNKNOWN_ID,
      23                 :            :                 .lcore = RTE_MAX_LCORE,
      24                 :            :                 .initialized = false,
      25                 :            :         },
      26                 :            :         [RTE_NTNIC_SERVICE_PORT_0_EVENT] = {
      27                 :            :                 .tag = RTE_NTNIC_SERVICE_PORT_0_EVENT,
      28                 :            :                 .id = NT_SERVICE_UNKNOWN_ID,
      29                 :            :                 .lcore = RTE_MAX_LCORE,
      30                 :            :                 .initialized = false,
      31                 :            :         },
      32                 :            :         [RTE_NTNIC_SERVICE_PORT_1_EVENT] = {
      33                 :            :                 .tag = RTE_NTNIC_SERVICE_PORT_1_EVENT,
      34                 :            :                 .id = NT_SERVICE_UNKNOWN_ID,
      35                 :            :                 .lcore = RTE_MAX_LCORE,
      36                 :            :                 .initialized = false,
      37                 :            :         },
      38                 :            :         [RTE_NTNIC_SERVICE_ADAPTER_MON] = {
      39                 :            :                 .tag = RTE_NTNIC_SERVICE_ADAPTER_MON,
      40                 :            :                 .id = NT_SERVICE_UNKNOWN_ID,
      41                 :            :                 .lcore = RTE_MAX_LCORE,
      42                 :            :                 .initialized = false,
      43                 :            :         },
      44                 :            : };
      45                 :            : 
      46                 :          0 : inline struct nt_service *nthw_service_get_info(const enum rte_ntnic_service_tag tag)
      47                 :            : {
      48         [ #  # ]:          0 :         if (tag < 0 || tag >= RTE_NTNIC_SERVICE_MAX)
      49                 :            :                 return NULL;
      50                 :            : 
      51                 :          0 :         return &g_nt_services[tag];
      52                 :            : }
      53                 :            : 
      54                 :          0 : int nthw_service_add(struct rte_service_spec *srv_spec, const enum rte_ntnic_service_tag tag)
      55                 :            : {
      56         [ #  # ]:          0 :         if (srv_spec == NULL || tag < 0 || tag >= RTE_NTNIC_SERVICE_MAX) {
      57                 :          0 :                 NT_LOG(ERR, NTNIC, "Invalid service specification or service tag");
      58                 :          0 :                 return -1;
      59                 :            :         }
      60                 :            : 
      61                 :          0 :         int ret = rte_service_component_register(srv_spec, &g_nt_services[tag].id);
      62         [ #  # ]:          0 :         if (ret < 0) {
      63                 :          0 :                 NT_LOG(ERR, NTNIC, "Failed to register service %s: error: %d",
      64                 :            :                            srv_spec->name, ret);
      65                 :          0 :                 return ret;
      66                 :            :         }
      67                 :            : 
      68                 :          0 :         const uint32_t service_id = g_nt_services[tag].id;
      69                 :            : 
      70                 :          0 :         NT_LOG(DBG, NTNIC, "Service %s registered with ID %u",
      71                 :            :                    srv_spec->name, service_id);
      72                 :            : 
      73                 :          0 :         rte_service_component_runstate_set(service_id, 1);
      74                 :            : 
      75                 :          0 :         ret = rte_service_runstate_set(service_id, 1);
      76         [ #  # ]:          0 :         if (ret < 0) {
      77                 :          0 :                 NT_LOG(ERR, NTNIC, "Failed to start service %s: error: %d",
      78                 :            :                            srv_spec->name, ret);
      79                 :          0 :                 rte_service_component_unregister(service_id);
      80                 :          0 :                 return ret;
      81                 :            :         }
      82                 :            : 
      83                 :            :         return 0;
      84                 :            : }
      85                 :            : 
      86                 :          0 : int nthw_service_del(const enum rte_ntnic_service_tag tag)
      87                 :            : {
      88         [ #  # ]:          0 :         if (tag < 0 || tag >= RTE_NTNIC_SERVICE_MAX) {
      89                 :          0 :                 NT_LOG(ERR, NTNIC, "Invalid service tag");
      90                 :          0 :                 return -1;
      91                 :            :         }
      92                 :            : 
      93                 :            :         struct nt_service *info = &g_nt_services[tag];
      94                 :            : 
      95                 :          0 :         const char *service_name = rte_service_get_name(info->id);
      96                 :            : 
      97                 :          0 :         rte_service_component_runstate_set(info->id, 0);
      98                 :            : 
      99                 :            :         const uint32_t timeout_count = 10000;
     100                 :            : 
     101         [ #  # ]:          0 :         for (uint32_t i = 0; i < timeout_count; i++) {
     102         [ #  # ]:          0 :                 if (rte_service_may_be_active(info->id) == 0)
     103                 :            :                         break;
     104                 :            :                 rte_delay_ms(1);
     105                 :            :         }
     106                 :            : 
     107                 :          0 :         int ret = rte_service_runstate_set(info->id, 0);
     108         [ #  # ]:          0 :         if (ret < 0) {
     109                 :          0 :                 NT_LOG(ERR, NTNIC, "Failed to stop service %s: error: %d",
     110                 :            :                            service_name, ret);
     111                 :          0 :                 return ret;
     112                 :            :         }
     113                 :            : 
     114                 :          0 :         ret = rte_service_component_unregister(info->id);
     115         [ #  # ]:          0 :         if (ret < 0) {
     116                 :          0 :                 NT_LOG(ERR, NTNIC, "Failed to unregister service %s: error: %d",
     117                 :            :                            service_name, ret);
     118                 :          0 :                 return ret;
     119                 :            :         }
     120                 :            : 
     121                 :          0 :         NT_LOG(DBG, NTNIC, "Service ID %d unregistered", info->id);
     122                 :            : 
     123                 :          0 :         g_nt_services[tag].id = NT_SERVICE_UNKNOWN_ID;
     124                 :            : 
     125                 :          0 :         return 0;
     126                 :            : }

Generated by: LCOV version 1.14