LCOV - code coverage report
Current view: top level - drivers/net/sxe2 - sxe2_vsi.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 123 0.0 %
Date: 2026-06-01 18:36:17 Functions: 0 8 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 36 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (C), 2025, Wuxi Stars Micro System Technologies Co., Ltd.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_os.h>
       6                 :            : #include <rte_tailq.h>
       7                 :            : #include <rte_malloc.h>
       8                 :            : #include "sxe2_ethdev.h"
       9                 :            : #include "sxe2_vsi.h"
      10                 :            : #include "sxe2_common_log.h"
      11                 :            : #include "sxe2_cmd_chnl.h"
      12                 :            : 
      13                 :          0 : void sxe2_sw_vsi_ctx_hw_cap_set(struct sxe2_adapter *adapter,
      14                 :            :                 struct sxe2_drv_vsi_caps *vsi_caps)
      15                 :            : {
      16                 :          0 :         adapter->vsi_ctxt.dpdk_vsi_id = vsi_caps->dpdk_vsi_id;
      17                 :          0 :         adapter->vsi_ctxt.kernel_vsi_id = vsi_caps->kernel_vsi_id;
      18                 :          0 :         adapter->vsi_ctxt.vsi_type = vsi_caps->vsi_type;
      19                 :          0 : }
      20                 :            : 
      21                 :            : static struct sxe2_vsi *
      22                 :          0 : sxe2_vsi_node_alloc(struct sxe2_adapter *adapter, uint16_t vsi_id, uint16_t vsi_type)
      23                 :            : {
      24                 :          0 :         struct sxe2_vsi *vsi = NULL;
      25                 :          0 :         vsi = rte_zmalloc("sxe2_vsi", sizeof(*vsi), 0);
      26         [ #  # ]:          0 :         if (vsi == NULL) {
      27                 :          0 :                 PMD_LOG_ERR(DRV, "Failed to malloc vf vsi struct.");
      28                 :          0 :                 goto l_end;
      29                 :            :         }
      30                 :          0 :         vsi->adapter = adapter;
      31                 :            : 
      32                 :          0 :         vsi->vsi_id = vsi_id;
      33                 :          0 :         vsi->vsi_type = vsi_type;
      34                 :            : 
      35                 :          0 : l_end:
      36                 :          0 :         return vsi;
      37                 :            : }
      38                 :            : 
      39                 :          0 : static void sxe2_vsi_queues_num_set(struct sxe2_vsi *vsi, uint16_t num_queues, uint16_t base_idx)
      40                 :            : {
      41                 :          0 :         vsi->txqs.q_cnt = num_queues;
      42                 :          0 :         vsi->rxqs.q_cnt = num_queues;
      43                 :          0 :         vsi->txqs.base_idx_in_func = base_idx;
      44                 :          0 :         vsi->rxqs.base_idx_in_func = base_idx;
      45                 :            : }
      46                 :            : 
      47                 :          0 : static void sxe2_vsi_queues_cfg(struct sxe2_vsi *vsi)
      48                 :            : {
      49         [ #  # ]:          0 :         vsi->txqs.depth = vsi->txqs.depth ? : SXE2_DFLT_NUM_TX_DESC;
      50         [ #  # ]:          0 :         vsi->rxqs.depth = vsi->rxqs.depth ? : SXE2_DFLT_NUM_RX_DESC;
      51                 :            : 
      52                 :          0 :         PMD_LOG_INFO(DRV, "vsi:%u queue_cnt:%u txq_depth:%u rxq_depth:%u.",
      53                 :            :                         vsi->vsi_id, vsi->txqs.q_cnt,
      54                 :            :                         vsi->txqs.depth, vsi->rxqs.depth);
      55                 :          0 : }
      56                 :            : 
      57                 :          0 : static void sxe2_vsi_irqs_cfg(struct sxe2_vsi *vsi, uint16_t num_irqs, uint16_t base_idx)
      58                 :            : {
      59                 :          0 :         vsi->irqs.avail_cnt = num_irqs;
      60                 :          0 :         vsi->irqs.base_idx_in_pf = base_idx;
      61                 :          0 : }
      62                 :            : 
      63                 :          0 : static struct sxe2_vsi *sxe2_vsi_node_create(struct sxe2_adapter *adapter,
      64                 :            :                                              uint16_t vsi_id,
      65                 :            :                                              uint16_t vsi_type)
      66                 :            : {
      67                 :          0 :         struct sxe2_vsi *vsi = NULL;
      68                 :          0 :         uint16_t num_queues = 0;
      69                 :          0 :         uint16_t queue_base_idx = 0;
      70                 :          0 :         uint16_t num_irqs = 0;
      71                 :          0 :         uint16_t irq_base_idx = 0;
      72                 :            : 
      73                 :          0 :         vsi = sxe2_vsi_node_alloc(adapter, vsi_id, vsi_type);
      74         [ #  # ]:          0 :         if (vsi == NULL)
      75                 :          0 :                 goto l_end;
      76                 :            : 
      77         [ #  # ]:          0 :         if (vsi_type == SXE2_VSI_T_DPDK_PF ||
      78                 :            :                         vsi_type == SXE2_VSI_T_DPDK_VF) {
      79                 :          0 :                 num_queues = adapter->q_ctxt.qp_cnt_assign;
      80                 :          0 :                 queue_base_idx = adapter->q_ctxt.base_idx_in_pf;
      81                 :            : 
      82                 :          0 :                 num_irqs = adapter->irq_ctxt.max_cnt_hw;
      83                 :          0 :                 irq_base_idx = adapter->irq_ctxt.base_idx_in_func;
      84         [ #  # ]:          0 :         } else if (vsi_type == SXE2_VSI_T_DPDK_ESW) {
      85                 :          0 :                 num_queues = 1;
      86                 :          0 :                 num_irqs = 1;
      87                 :            :         }
      88                 :            : 
      89                 :          0 :         sxe2_vsi_queues_num_set(vsi, num_queues, queue_base_idx);
      90                 :            : 
      91                 :          0 :         sxe2_vsi_queues_cfg(vsi);
      92                 :            : 
      93                 :          0 :         sxe2_vsi_irqs_cfg(vsi, num_irqs, irq_base_idx);
      94                 :            : 
      95                 :          0 : l_end:
      96                 :          0 :         return vsi;
      97                 :            : }
      98                 :            : 
      99                 :          0 : static void sxe2_vsi_node_free(struct sxe2_vsi *vsi)
     100                 :            : {
     101                 :          0 :         if (!vsi)
     102                 :            :                 return;
     103                 :            : 
     104                 :          0 :         rte_free(vsi);
     105                 :          0 :         vsi = NULL;
     106                 :            : }
     107                 :            : 
     108                 :          0 : static int32_t sxe2_vsi_destroy(struct sxe2_adapter *adapter, struct sxe2_vsi *vsi)
     109                 :            : {
     110                 :          0 :         int32_t ret = 0;
     111                 :            : 
     112         [ #  # ]:          0 :         if (vsi == NULL) {
     113                 :          0 :                 PMD_LOG_INFO(DRV, "vsi is not created, no need to destroy.");
     114                 :          0 :                 goto l_end;
     115                 :            :         }
     116                 :            : 
     117         [ #  # ]:          0 :         if (vsi->vsi_type != SXE2_VSI_T_DPDK_ESW) {
     118                 :          0 :                 ret = sxe2_drv_vsi_del(adapter, vsi);
     119         [ #  # ]:          0 :                 if (ret) {
     120                 :          0 :                         PMD_LOG_ERR(DRV, "Failed to del vsi from fw, ret=%d", ret);
     121         [ #  # ]:          0 :                         if (ret == -EPERM)
     122                 :          0 :                                 goto l_free;
     123                 :          0 :                         goto l_end;
     124                 :            :                 }
     125                 :            :         }
     126                 :            : 
     127                 :          0 : l_free:
     128                 :          0 :         rte_free(vsi);
     129                 :          0 :         vsi = NULL;
     130                 :            : 
     131                 :          0 :         PMD_LOG_DEBUG(DRV, "vsi destroyed.");
     132                 :          0 : l_end:
     133                 :          0 :         return ret;
     134                 :            : }
     135                 :            : 
     136                 :          0 : static int32_t sxe2_main_vsi_create(struct sxe2_adapter *adapter)
     137                 :            : {
     138                 :          0 :         int32_t ret = 0;
     139                 :          0 :         uint16_t vsi_id = adapter->vsi_ctxt.dpdk_vsi_id;
     140                 :          0 :         uint16_t vsi_type = adapter->vsi_ctxt.vsi_type;
     141                 :          0 :         bool is_reused = (vsi_id != SXE2_INVALID_VSI_ID);
     142                 :            : 
     143                 :          0 :         PMD_INIT_FUNC_TRACE();
     144                 :            : 
     145         [ #  # ]:          0 :         if (!is_reused)
     146                 :            :                 vsi_type = SXE2_VSI_T_DPDK_PF;
     147                 :            :         else
     148                 :          0 :                 PMD_LOG_INFO(DRV, "Reusing existing HW vsi_id:%u", vsi_id);
     149                 :            : 
     150                 :          0 :         adapter->vsi_ctxt.main_vsi = sxe2_vsi_node_create(adapter, vsi_id, vsi_type);
     151         [ #  # ]:          0 :         if (adapter->vsi_ctxt.main_vsi == NULL) {
     152                 :          0 :                 PMD_LOG_ERR(DRV, "Failed to create vsi struct, ret=%d", ret);
     153                 :          0 :                 ret = -ENOMEM;
     154                 :          0 :                 goto l_end;
     155                 :            :         }
     156                 :            : 
     157         [ #  # ]:          0 :         if (!is_reused) {
     158                 :          0 :                 ret = sxe2_drv_vsi_add(adapter, adapter->vsi_ctxt.main_vsi);
     159         [ #  # ]:          0 :                 if (ret) {
     160                 :          0 :                         PMD_LOG_ERR(DRV, "Failed to config vsi to fw, ret=%d", ret);
     161                 :          0 :                         goto l_free_vsi;
     162                 :            :                 }
     163                 :            : 
     164                 :          0 :                 adapter->vsi_ctxt.dpdk_vsi_id = adapter->vsi_ctxt.main_vsi->vsi_id;
     165                 :          0 :                 PMD_LOG_DEBUG(DRV, "Successfully created and synced new VSI");
     166                 :            :         }
     167                 :            : 
     168                 :          0 :         goto l_end;
     169                 :            : 
     170                 :          0 : l_free_vsi:
     171         [ #  # ]:          0 :         sxe2_vsi_node_free(adapter->vsi_ctxt.main_vsi);
     172                 :          0 :         adapter->vsi_ctxt.main_vsi = NULL;
     173                 :          0 : l_end:
     174                 :          0 :         return ret;
     175                 :            : }
     176                 :            : 
     177                 :          0 : int32_t sxe2_vsi_init(struct rte_eth_dev *dev)
     178                 :            : {
     179                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     180                 :          0 :         int32_t ret = 0;
     181                 :            : 
     182                 :          0 :         PMD_INIT_FUNC_TRACE();
     183                 :            : 
     184                 :          0 :         ret = sxe2_main_vsi_create(adapter);
     185         [ #  # ]:          0 :         if (ret) {
     186                 :          0 :                 PMD_LOG_ERR(DRV, "Failed to create main VSI, ret=%d", ret);
     187                 :          0 :                 goto l_end;
     188                 :            :         }
     189                 :            : 
     190                 :          0 : l_end:
     191                 :          0 :         return ret;
     192                 :            : }
     193                 :            : 
     194                 :          0 : void sxe2_vsi_uninit(struct rte_eth_dev *dev)
     195                 :            : {
     196                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     197                 :          0 :         int32_t ret;
     198                 :            : 
     199         [ #  # ]:          0 :         if (adapter->vsi_ctxt.main_vsi == NULL) {
     200                 :          0 :                 PMD_LOG_INFO(DRV, "vsi is not created, no need to destroy.");
     201                 :          0 :                 goto l_end;
     202                 :            :         }
     203                 :            : 
     204                 :          0 :         ret = sxe2_vsi_destroy(adapter, adapter->vsi_ctxt.main_vsi);
     205         [ #  # ]:          0 :         if (ret) {
     206                 :          0 :                 PMD_LOG_ERR(DRV, "Failed to del vsi from fw, ret=%d", ret);
     207                 :          0 :                 goto l_end;
     208                 :            :         }
     209                 :            : 
     210                 :          0 :         PMD_LOG_DEBUG(DRV, "vsi destroyed.");
     211                 :            : 
     212                 :          0 : l_end:
     213                 :          0 :         return;
     214                 :            : }

Generated by: LCOV version 1.14