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

Generated by: LCOV version 1.14