LCOV - code coverage report
Current view: top level - drivers/net/nfp - nfp_service.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 51 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 3 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                 :            :  * Copyright (c) 2023 Corigine, Inc.
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "nfp_service.h"
       7                 :            : 
       8                 :            : #include "nfpcore/nfp_cpp.h"
       9                 :            : #include "nfp_logs.h"
      10                 :            : 
      11                 :            : /* Disable service and try to get service status */
      12                 :            : #define NFP_SERVICE_DISABLE_WAIT_COUNT 3000
      13                 :            : 
      14                 :            : static int
      15                 :          0 : nfp_map_service(struct nfp_service_info *info)
      16                 :            : {
      17                 :            :         int32_t ret;
      18                 :            :         uint32_t slcore = 0;
      19                 :            :         int32_t slcore_count;
      20                 :            :         uint8_t service_count;
      21                 :            :         const char *service_name;
      22                 :            :         uint32_t slcore_array[RTE_MAX_LCORE];
      23                 :            :         uint8_t min_service_count = UINT8_MAX;
      24                 :            : 
      25                 :          0 :         slcore_count = rte_service_lcore_list(slcore_array, RTE_MAX_LCORE);
      26         [ #  # ]:          0 :         if (slcore_count <= 0) {
      27                 :          0 :                 PMD_DRV_LOG(DEBUG, "No service cores found");
      28                 :          0 :                 return -ENOENT;
      29                 :            :         }
      30                 :            : 
      31                 :            :         /*
      32                 :            :          * Find a service core with the least number of services already
      33                 :            :          * registered to it
      34                 :            :          */
      35         [ #  # ]:          0 :         while (slcore_count--) {
      36                 :          0 :                 service_count = rte_service_lcore_count_services(slcore_array[slcore_count]);
      37         [ #  # ]:          0 :                 if (service_count < min_service_count) {
      38                 :          0 :                         slcore = slcore_array[slcore_count];
      39                 :            :                         min_service_count = service_count;
      40                 :            :                 }
      41                 :            :         }
      42                 :            : 
      43                 :          0 :         service_name = rte_service_get_name(info->id);
      44                 :          0 :         PMD_INIT_LOG(INFO, "Mapping service %s to core %u", service_name, slcore);
      45                 :            : 
      46                 :          0 :         ret = rte_service_map_lcore_set(info->id, slcore, 1);
      47         [ #  # ]:          0 :         if (ret != 0) {
      48                 :          0 :                 PMD_DRV_LOG(DEBUG, "Could not map flower service");
      49                 :          0 :                 return -ENOENT;
      50                 :            :         }
      51                 :            : 
      52                 :          0 :         rte_service_runstate_set(info->id, 1);
      53                 :          0 :         rte_service_component_runstate_set(info->id, 1);
      54                 :          0 :         rte_service_lcore_start(slcore);
      55         [ #  # ]:          0 :         if (rte_service_may_be_active(slcore))
      56                 :          0 :                 PMD_DRV_LOG(INFO, "The service %s is running", service_name);
      57                 :            :         else
      58                 :          0 :                 PMD_DRV_LOG(ERR, "The service %s is not running", service_name);
      59                 :            : 
      60                 :          0 :         info->lcore = slcore;
      61                 :            : 
      62                 :          0 :         return 0;
      63                 :            : }
      64                 :            : 
      65                 :            : int
      66                 :          0 : nfp_service_enable(const struct rte_service_spec *service_spec,
      67                 :            :                 struct nfp_service_info *info)
      68                 :            : {
      69                 :            :         int ret;
      70                 :            : 
      71                 :            :         /* Register the service */
      72                 :          0 :         ret = rte_service_component_register(service_spec, &info->id);
      73         [ #  # ]:          0 :         if (ret != 0) {
      74                 :          0 :                 PMD_DRV_LOG(DEBUG, "Could not register %s", service_spec->name);
      75                 :          0 :                 return -EINVAL;
      76                 :            :         }
      77                 :            : 
      78                 :            :         /* Map it to available service core */
      79                 :          0 :         ret = nfp_map_service(info);
      80         [ #  # ]:          0 :         if (ret != 0) {
      81                 :          0 :                 PMD_DRV_LOG(DEBUG, "Could not map %s", service_spec->name);
      82                 :          0 :                 return -EINVAL;
      83                 :            :         }
      84                 :            : 
      85                 :          0 :         PMD_DRV_LOG(DEBUG, "Enable service %s successfully", service_spec->name);
      86                 :            : 
      87                 :          0 :         return 0;
      88                 :            : }
      89                 :            : 
      90                 :            : int
      91                 :          0 : nfp_service_disable(struct nfp_service_info *info)
      92                 :            : {
      93                 :            :         int ret;
      94                 :            :         uint32_t i;
      95                 :            :         const char *service_name;
      96                 :            : 
      97                 :          0 :         service_name = rte_service_get_name(info->id);
      98         [ #  # ]:          0 :         if (service_name == NULL) {
      99                 :          0 :                 PMD_DRV_LOG(ERR, "Could not find service %u", info->id);
     100                 :          0 :                 return -EINVAL;
     101                 :            :         }
     102                 :            : 
     103                 :          0 :         rte_service_runstate_set(info->id, 0);
     104                 :          0 :         rte_service_component_runstate_set(info->id, 0);
     105                 :            : 
     106         [ #  # ]:          0 :         for (i = 0; i < NFP_SERVICE_DISABLE_WAIT_COUNT; i++) {
     107         [ #  # ]:          0 :                 if (rte_service_may_be_active(info->id) == 0)
     108                 :            :                         break;
     109                 :            :                 rte_delay_ms(1);
     110                 :            :         }
     111                 :            : 
     112         [ #  # ]:          0 :         if (i == NFP_SERVICE_DISABLE_WAIT_COUNT)
     113                 :          0 :                 PMD_DRV_LOG(ERR, "Could not stop service %s", service_name);
     114                 :            : 
     115                 :          0 :         ret = rte_service_map_lcore_set(info->id, info->lcore, 0);
     116         [ #  # ]:          0 :         if (ret != 0) {
     117                 :          0 :                 PMD_DRV_LOG(DEBUG, "Could not unmap flower service");
     118                 :          0 :                 return -ENOENT;
     119                 :            :         }
     120                 :            : 
     121                 :          0 :         rte_service_component_unregister(info->id);
     122                 :            : 
     123                 :          0 :         return 0;
     124                 :            : }

Generated by: LCOV version 1.14