LCOV - code coverage report
Current view: top level - drivers/net/ntnic - rte_pmd_ntnic.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 43 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 20 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 <eal_export.h>
       6                 :            : #include <rte_service.h>
       7                 :            : #include <rte_pmd_ntnic.h>
       8                 :            : 
       9                 :            : #include <stdint.h>
      10                 :            : 
      11                 :            : #include "nt_service.h"
      12                 :            : #include "ntlog.h"
      13                 :            : 
      14                 :          0 : static int nthw_service_is_mapped_to_lcore(enum rte_ntnic_service_tag tag)
      15                 :            : {
      16                 :          0 :         struct nt_service *service = nthw_service_get_info(tag);
      17                 :            : 
      18                 :          0 :         uint32_t cores[RTE_MAX_LCORE] = {0};
      19                 :          0 :         int32_t lcore_count = rte_service_lcore_list(cores, RTE_MAX_LCORE);
      20                 :            : 
      21         [ #  # ]:          0 :         for (int32_t i = 0; i < lcore_count; i++) {
      22         [ #  # ]:          0 :                 if (rte_service_map_lcore_get(service->id, cores[i]))
      23                 :          0 :                         return cores[i];
      24                 :            :         }
      25                 :            :         return RTE_MAX_LCORE;
      26                 :            : }
      27                 :            : 
      28                 :            : 
      29                 :            : RTE_EXPORT_SYMBOL(rte_pmd_ntnic_service_set_lcore)
      30                 :          0 : int rte_pmd_ntnic_service_set_lcore(enum rte_ntnic_service_tag tag, uint32_t lcore_id)
      31                 :            : {
      32         [ #  # ]:          0 :         if (tag < 0 || tag >= RTE_NTNIC_SERVICE_MAX || lcore_id >= RTE_MAX_LCORE) {
      33                 :          0 :                 NT_LOG(ERR, NTNIC, "Invalid service tag or lcore ID");
      34                 :          0 :                 return -1;
      35                 :            :         }
      36                 :            : 
      37                 :          0 :         struct nt_service *srv = nthw_service_get_info(tag);
      38                 :          0 :         const char *service_name = rte_service_get_name(srv->id);
      39                 :            : 
      40                 :          0 :         uint32_t service_core = nthw_service_is_mapped_to_lcore(tag);
      41                 :            : 
      42         [ #  # ]:          0 :         if (service_core != RTE_MAX_LCORE) {
      43                 :          0 :                 NT_LOG(WRN, NTNIC, "Service %s[id=%u] is already mapped to lcore: %u", service_name,
      44                 :            :                         srv->id, service_core);
      45                 :            :                 /* Mapping by application has higher priority then 1:1 default mapping.
      46                 :            :                  * Disable previous mapping and do remapping to new lcore.
      47                 :            :                  */
      48                 :            : 
      49                 :          0 :                 rte_service_runstate_set(srv->id, 0);
      50                 :            : 
      51                 :          0 :                 NT_SERVICE_SET_STATE(srv, false);
      52                 :            : 
      53                 :            :                 int timeout_count = 10000;
      54                 :            : 
      55         [ #  # ]:          0 :                 while (rte_service_may_be_active(srv->id) != 0) {
      56         [ #  # ]:          0 :                         if (--timeout_count <= 0) {
      57                 :          0 :                                 NT_LOG(ERR, NTNIC, "Failed to stop service %s[id=%d] on lcore %u",
      58                 :            :                                         service_name, srv->id, service_core);
      59                 :          0 :                                 return -1;
      60                 :            :                         }
      61                 :            :                         rte_delay_ms(1);
      62                 :            :                 }
      63                 :            : 
      64                 :          0 :                 rte_service_map_lcore_set(srv->id, service_core, 0);
      65                 :          0 :                 rte_service_runstate_set(srv->id, 1);
      66                 :            :         }
      67                 :            : 
      68                 :          0 :         int ret = rte_service_lcore_add(lcore_id);
      69         [ #  # ]:          0 :         if (ret < 0 && ret != -EALREADY) {
      70                 :          0 :                 NT_LOG(ERR, NTNIC, "Failed to add service lcore %u for service %s: error: %d",
      71                 :            :                            lcore_id, service_name, ret);
      72                 :          0 :                 return ret;
      73                 :            :         }
      74                 :            : 
      75                 :          0 :         ret = rte_service_map_lcore_set(srv->id, lcore_id, 1);
      76         [ #  # ]:          0 :         if (ret < 0) {
      77                 :          0 :                 NT_LOG(ERR, NTNIC, "Failed to map service %s to lcore %u: error: %d",
      78                 :            :                            service_name, lcore_id, ret);
      79                 :          0 :                 return ret;
      80                 :            :         }
      81                 :            : 
      82                 :          0 :         NT_LOG(DBG, NTNIC, "Service %s[id=%d] is mapped to lcore %u", service_name, srv->id,
      83                 :            :                 lcore_id);
      84                 :            : 
      85                 :          0 :         return 0;
      86                 :            : }
      87                 :            : 
      88                 :            : RTE_EXPORT_SYMBOL(rte_pmd_ntnic_service_get_id)
      89                 :          0 : int rte_pmd_ntnic_service_get_id(enum rte_ntnic_service_tag tag)
      90                 :            : {
      91         [ #  # ]:          0 :         if (tag < 0 || tag >= RTE_NTNIC_SERVICE_MAX) {
      92                 :          0 :                 NT_LOG(ERR, NTNIC, "Invalid service tag");
      93                 :          0 :                 return -1;
      94                 :            :         }
      95                 :            : 
      96                 :          0 :         struct nt_service *service = nthw_service_get_info(tag);
      97         [ #  # ]:          0 :         if (service == NULL) {
      98                 :          0 :                 NT_LOG(ERR, NTNIC, "Service with tag %d not found", tag);
      99                 :          0 :                 return -1;
     100                 :            :         }
     101                 :            : 
     102                 :          0 :         return service->id;
     103                 :            : }

Generated by: LCOV version 1.14