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

Generated by: LCOV version 1.14