LCOV - code coverage report
Current view: top level - drivers/net/sxe2 - sxe2_ethdev_repr.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 337 0.0 %
Date: 2026-08-01 17:54:00 Functions: 0 16 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 84 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 "sxe2_ethdev_repr.h"
       6                 :            : #include "sxe2_ethdev.h"
       7                 :            : #include "sxe2_common.h"
       8                 :            : #include "sxe2_common_log.h"
       9                 :            : #include "sxe2_tx.h"
      10                 :            : #include "sxe2_rx.h"
      11                 :            : #include "sxe2_txrx.h"
      12                 :            : #include "sxe2_switchdev.h"
      13                 :            : #include "sxe2_mp.h"
      14                 :            : #include "sxe2_dump.h"
      15                 :            : #include "sxe2_stats.h"
      16                 :            : #include "sxe2_flow.h"
      17                 :            : 
      18                 :            : static struct sxe2_pci_map_addr_info sxe2_net_map_addr_info_repr[SXE2_PCI_MAP_RES_MAX_COUNT] = {
      19                 :            :         {0, 0, 0},
      20                 :            :         { SXE2_TXQ_LEGACY_DBLL(0), 0, 4},
      21                 :            :         { SXE2_RXQ_TAIL(0), 0, 4},
      22                 :            :         { SXE2_VF_DYN_CTL(0), 0, 4},
      23                 :            :         { SXE2_VF_INT_ITR(0, 0), 0, 4},
      24                 :            :         { SXE2_BAR4_MSIX_CTL(0), 4, 0x10},
      25                 :            : };
      26                 :            : 
      27                 :            : static void sxe2_repr_dev_uinit(struct rte_eth_dev *dev);
      28                 :            : 
      29                 :          0 : static int32_t sxe2_repr_promisc_enable(struct rte_eth_dev *dev __rte_unused)
      30                 :            : {
      31                 :          0 :         return 0;
      32                 :            : }
      33                 :          0 : static int32_t sxe2_repr_promisc_disable(struct rte_eth_dev *dev __rte_unused)
      34                 :            : {
      35                 :          0 :         return 0;
      36                 :            : }
      37                 :          0 : static int32_t sxe2_repr_allmulti_enable(struct rte_eth_dev *dev __rte_unused)
      38                 :            : {
      39                 :          0 :         return 0;
      40                 :            : }
      41                 :          0 : static int32_t sxe2_repr_allmulti_disable(struct rte_eth_dev *dev __rte_unused)
      42                 :            : {
      43                 :          0 :         return 0;
      44                 :            : }
      45                 :            : 
      46                 :          0 : static int32_t sxe2_repr_dev_configure(struct rte_eth_dev *dev)
      47                 :            : {
      48                 :          0 :         dev->data->mtu = SXE2_FRAME_SIZE_MAX - SXE2_ETH_OVERHEAD;
      49                 :          0 :         return 0;
      50                 :            : }
      51                 :            : 
      52                 :          0 : static int32_t sxe2_repr_dev_start(struct rte_eth_dev *dev)
      53                 :            : {
      54                 :          0 :         int32_t ret = 0;
      55                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
      56                 :          0 :         PMD_INIT_FUNC_TRACE();
      57                 :            : 
      58                 :          0 :         ret = sxe2_queues_init(dev);
      59         [ #  # ]:          0 :         if (ret) {
      60                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to init queues.");
      61                 :          0 :                 goto l_end;
      62                 :            :         }
      63                 :            : 
      64                 :          0 :         sxe2_rx_mode_func_set(dev);
      65                 :          0 :         sxe2_tx_mode_func_set(dev);
      66                 :            : 
      67                 :          0 :         ret = sxe2_link_update_init(dev);
      68         [ #  # ]:          0 :         if (ret) {
      69                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to initialize link update, ret:%d", ret);
      70                 :          0 :                 goto l_end;
      71                 :            :         }
      72                 :            : 
      73                 :          0 :         ret = sxe2_repr_rxq_intr_enable(dev);
      74         [ #  # ]:          0 :         if (ret) {
      75                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to enable rx queue intr");
      76                 :          0 :                 goto l_end;
      77                 :            :         }
      78                 :            : 
      79                 :          0 :         ret = sxe2_queues_start(dev);
      80         [ #  # ]:          0 :         if (ret) {
      81                 :          0 :                 PMD_LOG_ERR(INIT, "enable queues failed");
      82                 :          0 :                 goto l_start_queues_err;
      83                 :            :         }
      84                 :            : 
      85                 :          0 :         dev->data->dev_started = 1;
      86                 :          0 :         adapter->started = 1;
      87                 :          0 :         goto l_end;
      88                 :          0 : l_start_queues_err:
      89                 :          0 :         (void)sxe2_rxq_intr_disable(dev);
      90                 :          0 : l_end:
      91                 :          0 :         return ret;
      92                 :            : }
      93                 :            : 
      94                 :          0 : static int32_t sxe2_repr_dev_stop(struct rte_eth_dev *dev)
      95                 :            : {
      96                 :          0 :         int32_t ret = 0;
      97                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
      98                 :          0 :         PMD_INIT_FUNC_TRACE();
      99                 :            : 
     100         [ #  # ]:          0 :         if (adapter->started == 0)
     101                 :          0 :                 goto l_end;
     102                 :            : 
     103                 :          0 :         sxe2_repr_rxq_intr_disable(dev);
     104                 :            : 
     105                 :          0 :         sxe2_txqs_all_stop(dev);
     106                 :          0 :         sxe2_rxqs_all_stop(dev);
     107                 :            : 
     108                 :          0 :         dev->data->dev_started = 0;
     109                 :          0 :         adapter->started = 0;
     110                 :          0 : l_end:
     111                 :          0 :         return ret;
     112                 :            : }
     113                 :            : 
     114                 :          0 : static int32_t sxe2_repr_dev_close(struct rte_eth_dev *dev)
     115                 :            : {
     116                 :          0 :         PMD_DEV_LOG_INFO(SXE2_DEV_PRIVATE_TO_ADAPTER(dev),
     117                 :            :                          INIT, "repr close");
     118         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY) {
     119                 :          0 :                 sxe2_mp_uninit(dev);
     120                 :          0 :                 goto l_end;
     121                 :            :         }
     122                 :          0 :         (void)sxe2_repr_dev_stop(dev);
     123                 :          0 :         (void)sxe2_queues_release(dev);
     124                 :          0 :         sxe2_mp_uninit(dev);
     125                 :          0 :         sxe2_repr_dev_uinit(dev);
     126                 :          0 : l_end:
     127                 :          0 :         return 0;
     128                 :            : }
     129                 :            : 
     130                 :          0 : static int32_t sxe2_repr_dev_infos_get(struct rte_eth_dev *dev,
     131                 :            :                         struct rte_eth_dev_info *dev_info)
     132                 :            : {
     133                 :          0 :         dev_info->max_rx_queues = 1;
     134                 :          0 :         dev_info->max_tx_queues = 1;
     135                 :          0 :         dev_info->min_rx_bufsize = SXE2_MIN_BUF_SIZE;
     136                 :          0 :         dev_info->max_rx_pktlen = SXE2_FRAME_SIZE_MAX;
     137                 :          0 :         dev_info->max_lro_pkt_size = SXE2_FRAME_SIZE_MAX * SXE2_RX_LRO_DESC_MAX_NUM;
     138                 :          0 :         dev_info->max_mtu = dev_info->max_rx_pktlen - SXE2_ETH_OVERHEAD;
     139                 :          0 :         dev_info->min_mtu = RTE_ETHER_MIN_MTU;
     140                 :          0 :         dev_info->max_mac_addrs = SXE2_NUM_MACADDR_MAX;
     141                 :            : 
     142                 :          0 :         dev_info->rx_offload_capa =
     143                 :            :                 RTE_ETH_RX_OFFLOAD_KEEP_CRC |
     144                 :            :                 RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
     145                 :            :                 RTE_ETH_RX_OFFLOAD_UDP_CKSUM |
     146                 :            :                 RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
     147                 :            :                 RTE_ETH_RX_OFFLOAD_SCTP_CKSUM |
     148                 :            :                 RTE_ETH_RX_OFFLOAD_OUTER_IPV4_CKSUM;
     149                 :          0 :         dev_info->tx_offload_capa =
     150                 :            :                 RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
     151                 :            :                 RTE_ETH_TX_OFFLOAD_UDP_CKSUM |
     152                 :            :                 RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
     153                 :            :                 RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
     154                 :            :                 RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
     155                 :            :                 RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM;
     156                 :            : 
     157                 :          0 :         dev_info->tx_queue_offload_capa = RTE_ETH_TX_OFFLOAD_MBUF_FAST_FREE;
     158                 :            : 
     159                 :          0 :         dev_info->default_rxconf = (struct rte_eth_rxconf) {
     160                 :            :                 .rx_thresh = {
     161                 :            :                         .pthresh = SXE2_DEFAULT_RX_PTHRESH,
     162                 :            :                         .hthresh = SXE2_DEFAULT_RX_HTHRESH,
     163                 :            :                         .wthresh = SXE2_DEFAULT_RX_WTHRESH,
     164                 :            :                 },
     165                 :            :                 .rx_free_thresh = SXE2_DEFAULT_RX_FREE_THRESH,
     166                 :            :                 .rx_drop_en = 0,
     167                 :            :                 .offloads = 0,
     168                 :            :         };
     169                 :            : 
     170                 :          0 :         dev_info->default_txconf = (struct rte_eth_txconf) {
     171                 :            :                 .tx_thresh = {
     172                 :            :                         .pthresh = SXE2_DEFAULT_TX_PTHRESH,
     173                 :            :                         .hthresh = SXE2_DEFAULT_TX_HTHRESH,
     174                 :            :                         .wthresh = SXE2_DEFAULT_TX_WTHRESH,
     175                 :            :                 },
     176                 :            :                 .tx_free_thresh = SXE2_DEFAULT_TX_FREE_THRESH,
     177                 :            :                 .tx_rs_thresh = SXE2_DEFAULT_TX_RSBIT_THRESH,
     178                 :            :                 .offloads = 0,
     179                 :            :         };
     180                 :            : 
     181                 :          0 :         dev_info->rx_desc_lim = (struct rte_eth_desc_lim) {
     182                 :            :                 .nb_max = SXE2_MAX_RING_DESC,
     183                 :            :                 .nb_min = SXE2_MIN_RING_DESC,
     184                 :            :                 .nb_align = SXE2_ALIGN,
     185                 :            :         };
     186                 :            : 
     187                 :          0 :         dev_info->tx_desc_lim = (struct rte_eth_desc_lim) {
     188                 :            :                 .nb_max = SXE2_MAX_RING_DESC,
     189                 :            :                 .nb_min = SXE2_MIN_RING_DESC,
     190                 :            :                 .nb_align = SXE2_ALIGN,
     191                 :            :                 .nb_mtu_seg_max = SXE2_TX_MTU_SEG_MAX,
     192                 :            :                 .nb_seg_max = SXE2_MAX_RING_DESC,
     193                 :            :         };
     194                 :            : 
     195                 :          0 :         dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G | RTE_ETH_LINK_SPEED_25G |
     196                 :            :                          RTE_ETH_LINK_SPEED_50G | RTE_ETH_LINK_SPEED_100G;
     197                 :            : 
     198                 :          0 :         dev_info->nb_rx_queues = dev->data->nb_rx_queues;
     199                 :          0 :         dev_info->nb_tx_queues = dev->data->nb_tx_queues;
     200                 :            : 
     201                 :          0 :         dev_info->default_rxportconf.burst_size = SXE2_RX_MAX_BURST;
     202                 :          0 :         dev_info->default_txportconf.burst_size = SXE2_TX_MAX_BURST;
     203                 :          0 :         dev_info->default_rxportconf.nb_queues = 1;
     204                 :          0 :         dev_info->default_txportconf.nb_queues = 1;
     205                 :          0 :         dev_info->default_rxportconf.ring_size = SXE2_RING_SIZE_MIN;
     206                 :          0 :         dev_info->default_txportconf.ring_size = SXE2_RING_SIZE_MIN;
     207                 :            : 
     208                 :          0 :         dev_info->rx_seg_capa.offset_allowed = false;
     209                 :            : 
     210                 :          0 :         dev_info->rx_seg_capa.offset_align_log2 = false;
     211                 :            : 
     212                 :          0 :         return 0;
     213                 :            : }
     214                 :            : 
     215                 :            : static const struct eth_dev_ops sxe2_switchdev_repr_dev_ops = {
     216                 :            :         .dev_configure              = sxe2_repr_dev_configure,
     217                 :            : 
     218                 :            :         .dev_start                  = sxe2_repr_dev_start,
     219                 :            :         .dev_stop                   = sxe2_repr_dev_stop,
     220                 :            : 
     221                 :            :         .rx_queue_start             = sxe2_rx_queue_start,
     222                 :            :         .rx_queue_stop              = sxe2_rx_queue_stop,
     223                 :            :         .tx_queue_start             = sxe2_tx_queue_start,
     224                 :            :         .tx_queue_stop              = sxe2_tx_queue_stop,
     225                 :            :         .rx_queue_setup             = sxe2_rx_queue_setup,
     226                 :            :         .rx_queue_release           = sxe2_rx_queue_release,
     227                 :            :         .tx_queue_setup             = sxe2_tx_queue_setup,
     228                 :            :         .tx_queue_release           = sxe2_tx_queue_release,
     229                 :            : 
     230                 :            :         .dev_close                  = sxe2_repr_dev_close,
     231                 :            :         .dev_infos_get              = sxe2_repr_dev_infos_get,
     232                 :            :         .dev_supported_ptypes_get   = sxe2_dev_supported_ptypes_get,
     233                 :            :         .link_update                = sxe2_link_update,
     234                 :            : 
     235                 :            :         .promiscuous_enable         = sxe2_repr_promisc_enable,
     236                 :            :         .promiscuous_disable        = sxe2_repr_promisc_disable,
     237                 :            :         .allmulticast_enable        = sxe2_repr_allmulti_enable,
     238                 :            :         .allmulticast_disable       = sxe2_repr_allmulti_disable,
     239                 :            : 
     240                 :            :         .eth_dev_priv_dump          = sxe2_eth_dev_priv_dump,
     241                 :            : 
     242                 :            :         .stats_get                  = sxe2_stats_info_get,
     243                 :            :         .stats_reset                = sxe2_stats_info_reset,
     244                 :            :         .xstats_get                 = sxe2_xstats_info_get,
     245                 :            :         .xstats_get_names           = sxe2_xstats_names_get,
     246                 :            :         .xstats_reset               = sxe2_stats_info_reset,
     247                 :            : };
     248                 :            : 
     249                 :          0 : void sxe2_repr_all_close(struct rte_eth_dev *dev)
     250                 :            : {
     251                 :          0 :         uint16_t vf_id;
     252                 :          0 :         struct rte_eth_dev *repr_eth_dev = NULL;
     253                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     254                 :            : 
     255         [ #  # ]:          0 :         if (adapter->repr_ctxt.nb_repr_vf) {
     256         [ #  # ]:          0 :                 for (vf_id = 0; vf_id < adapter->repr_ctxt.nb_repr_vf; vf_id++) {
     257                 :          0 :                         repr_eth_dev = adapter->repr_ctxt.vf_rep_eth_dev[vf_id];
     258   [ #  #  #  # ]:          0 :                         if (!repr_eth_dev || repr_eth_dev->data->dev_started == 0)
     259                 :          0 :                                 continue;
     260                 :            : 
     261                 :          0 :                         (void)rte_eth_dev_stop(repr_eth_dev->data->port_id);
     262                 :          0 :                         (void)rte_eth_dev_close(repr_eth_dev->data->port_id);
     263                 :            :                 }
     264                 :            :         }
     265                 :          0 : }
     266                 :            : 
     267                 :          0 : static void sxe2_repr_adapter_init(struct rte_eth_dev *dev_repr,
     268                 :            :                                    struct sxe2_adapter *parent_adapter,
     269                 :            :                                    uint16_t repr_id)
     270                 :            : {
     271                 :          0 :         struct sxe2_adapter *adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev_repr);
     272                 :            : 
     273                 :          0 :         dev_repr->data->backer_port_id = parent_adapter->dev_port_id;
     274                 :          0 :         dev_repr->data->representor_id = repr_id;
     275                 :          0 :         dev_repr->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
     276                 :            : 
     277                 :          0 :         adapter->is_dev_repr = true;
     278                 :          0 :         adapter->dev_port_id = dev_repr->data->port_id;
     279                 :          0 :         adapter->dev_type = parent_adapter->dev_type;
     280                 :          0 :         adapter->switchdev_info.is_switchdev = parent_adapter->switchdev_info.is_switchdev;
     281                 :          0 :         adapter->port_idx = parent_adapter->port_idx;
     282                 :          0 :         adapter->pf_idx = parent_adapter->pf_idx;
     283                 :          0 :         adapter->dev_info.pci = parent_adapter->dev_info.pci;
     284                 :          0 :         adapter->dev_info.fw = parent_adapter->dev_info.fw;
     285                 :          0 : }
     286                 :            : 
     287                 :          0 : static int32_t sxe2_repr_eth_init(struct rte_eth_dev *dev)
     288                 :            : {
     289                 :          0 :         int32_t ret = 0;
     290                 :            : 
     291                 :          0 :         ret = sxe2_filter_init(dev);
     292         [ #  # ]:          0 :         if (ret) {
     293                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to initialize l2 filter, ret:%d", ret);
     294                 :          0 :                 goto l_end;
     295                 :            :         }
     296                 :          0 :         ret = sxe2_link_update_init(dev);
     297         [ #  # ]:          0 :         if (ret) {
     298                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to initialize link update, ret:%d", ret);
     299                 :          0 :                 goto l_end;
     300                 :            :         }
     301                 :            : 
     302                 :          0 :         ret = sxe2_mac_addr_init(dev);
     303         [ #  # ]:          0 :         if (ret != 0) {
     304                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to initialize mac address, ret:%d", ret);
     305                 :          0 :                 goto l_end;
     306                 :            :         }
     307                 :            : 
     308                 :          0 : l_end:
     309                 :          0 :         return ret;
     310                 :            : }
     311                 :            : 
     312                 :          0 : static int32_t sxe2_repr_dev_pci_map_init(struct rte_eth_dev *dev)
     313                 :            : {
     314                 :          0 :         struct sxe2_adapter *rep_adapter = SXE2_DEV_PRIVATE_TO_ADAPTER(dev);
     315                 :          0 :         struct sxe2_pci_map_context *map_ctxt = &rep_adapter->map_ctxt;
     316                 :          0 :         struct sxe2_pci_map_bar_info *bar_info = NULL;
     317                 :          0 :         struct sxe2_pci_map_segment_info *seg_info = NULL;
     318                 :          0 :         uint16_t txq_cnt = rep_adapter->q_ctxt.qp_cnt_assign;
     319                 :          0 :         uint16_t txq_base = rep_adapter->q_ctxt.base_idx_in_pf;
     320                 :          0 :         uint16_t rxq_cnt = rep_adapter->q_ctxt.qp_cnt_assign;
     321                 :          0 :         uint16_t rxq_base = rep_adapter->q_ctxt.base_idx_in_pf;
     322                 :          0 :         uint16_t irq_cnt = rep_adapter->irq_ctxt.max_cnt_hw;
     323                 :          0 :         uint16_t irq_base = rep_adapter->irq_ctxt.base_idx_in_func;
     324                 :          0 :         int32_t ret = 0;
     325                 :            : 
     326                 :          0 :         PMD_INIT_FUNC_TRACE();
     327                 :            : 
     328                 :          0 :         rep_adapter->dev_info.dev_data = dev->data;
     329                 :            : 
     330                 :          0 :         map_ctxt->bar_cnt = 2;
     331                 :            : 
     332                 :          0 :         bar_info = rte_zmalloc("repr_bar_info",
     333                 :            :                         sizeof(struct sxe2_pci_map_bar_info) * map_ctxt->bar_cnt, 0);
     334         [ #  # ]:          0 :         if (bar_info == NULL) {
     335                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to alloc bar_info");
     336                 :          0 :                 ret = -ENOMEM;
     337                 :          0 :                 goto l_end;
     338                 :            :         }
     339                 :          0 :         bar_info[0].bar_idx = 0;
     340                 :          0 :         bar_info[0].map_cnt = SXE2_PCI_MAP_RES_MAX_COUNT;
     341                 :          0 :         seg_info = rte_zmalloc("repr_seg_info_bar0",
     342                 :            :                         sizeof(struct sxe2_pci_map_segment_info) * bar_info[0].map_cnt, 0);
     343         [ #  # ]:          0 :         if (seg_info == NULL) {
     344                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to alloc seg_info");
     345                 :          0 :                 ret = -ENOMEM;
     346                 :          0 :                 goto l_free_bar;
     347                 :            :         }
     348                 :            : 
     349                 :          0 :         bar_info[0].seg_info = seg_info;
     350                 :            : 
     351                 :          0 :         bar_info[1].bar_idx = 4;
     352                 :          0 :         bar_info[1].map_cnt = SXE2_PCI_MAP_RES_MAX_COUNT;
     353                 :          0 :         seg_info = rte_zmalloc("repr_seg_info_bar4",
     354                 :            :                         sizeof(struct sxe2_pci_map_segment_info) * bar_info[1].map_cnt,
     355                 :            :                         0);
     356         [ #  # ]:          0 :         if (!seg_info) {
     357                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to alloc seg_info");
     358                 :          0 :                 ret = -ENOMEM;
     359                 :          0 :                 goto l_free_seg0;
     360                 :            :         }
     361                 :            : 
     362                 :          0 :         bar_info[1].seg_info = seg_info;
     363                 :          0 :         map_ctxt->bar_info = bar_info;
     364                 :            : 
     365                 :          0 :         map_ctxt->addr_info = sxe2_net_map_addr_info_repr;
     366                 :            : 
     367                 :          0 :         ret = sxe2_dev_pci_res_seg_map(rep_adapter, SXE2_PCI_MAP_RES_DOORBELL_TX,
     368                 :            :                         txq_cnt, txq_base);
     369         [ #  # ]:          0 :         if (ret != 0) {
     370                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to map txq doorbell addr, ret=%d", ret);
     371                 :          0 :                 goto l_free_seg1;
     372                 :            :         }
     373                 :            : 
     374                 :          0 :         ret = sxe2_dev_pci_res_seg_map(rep_adapter, SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL,
     375                 :            :                         rxq_cnt, rxq_base);
     376         [ #  # ]:          0 :         if (ret != 0) {
     377                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to map rxq tail doorbell addr, ret=%d", ret);
     378                 :          0 :                 goto l_free_txq;
     379                 :            :         }
     380                 :            : 
     381                 :          0 :         ret = sxe2_dev_pci_res_seg_map(rep_adapter, SXE2_PCI_MAP_RES_IRQ_DYN,
     382                 :            :                         irq_cnt, irq_base);
     383         [ #  # ]:          0 :         if (ret != 0) {
     384                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to map irq dyn addr, ret=%d", ret);
     385                 :          0 :                 goto l_free_rxq_tail;
     386                 :            :         }
     387                 :            : 
     388                 :          0 :         ret = sxe2_dev_pci_res_seg_map(rep_adapter, SXE2_PCI_MAP_RES_IRQ_ITR,
     389                 :            :                         irq_cnt, irq_base);
     390         [ #  # ]:          0 :         if (ret != 0) {
     391                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to map irq itr addr, ret=%d", ret);
     392                 :          0 :                 goto l_free_irq_dyn;
     393                 :            :         }
     394                 :            : 
     395                 :          0 :         ret = sxe2_dev_pci_res_seg_map(rep_adapter, SXE2_PCI_MAP_RES_IRQ_MSIX,
     396                 :            :                         irq_cnt, irq_base);
     397         [ #  # ]:          0 :         if (ret != 0) {
     398                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to map irq msix addr, ret=%d", ret);
     399                 :          0 :                 goto l_free_irq_itr;
     400                 :            :         }
     401                 :          0 :         goto l_end;
     402                 :            : 
     403                 :          0 : l_free_irq_itr:
     404                 :          0 :         (void)sxe2_dev_pci_seg_unmap(rep_adapter, SXE2_PCI_MAP_RES_IRQ_ITR);
     405                 :          0 : l_free_irq_dyn:
     406                 :          0 :         (void)sxe2_dev_pci_seg_unmap(rep_adapter, SXE2_PCI_MAP_RES_IRQ_DYN);
     407                 :          0 : l_free_rxq_tail:
     408                 :          0 :         (void)sxe2_dev_pci_seg_unmap(rep_adapter, SXE2_PCI_MAP_RES_DOORBELL_RX_TAIL);
     409                 :          0 : l_free_txq:
     410                 :          0 :         (void)sxe2_dev_pci_seg_unmap(rep_adapter, SXE2_PCI_MAP_RES_DOORBELL_TX);
     411                 :          0 : l_free_seg1:
     412         [ #  # ]:          0 :         if (bar_info[1].seg_info) {
     413                 :          0 :                 rte_free(bar_info[1].seg_info);
     414                 :          0 :                 bar_info[1].seg_info = NULL;
     415                 :            :         }
     416                 :          0 : l_free_seg0:
     417         [ #  # ]:          0 :         if (bar_info[0].seg_info) {
     418                 :          0 :                 rte_free(bar_info[0].seg_info);
     419                 :          0 :                 bar_info[0].seg_info = NULL;
     420                 :            :         }
     421                 :          0 : l_free_bar:
     422                 :          0 :         if (bar_info) {
     423                 :          0 :                 rte_free(bar_info);
     424                 :          0 :                 bar_info = NULL;
     425                 :            :         }
     426                 :          0 : l_end:
     427                 :          0 :         return ret;
     428                 :            : }
     429                 :            : 
     430                 :          0 : int32_t sxe2_repr_dev_init(struct rte_eth_dev *dev,
     431                 :            :                            struct sxe2_adapter *parent_adapter,
     432                 :            :                            uint16_t repr_id)
     433                 :            : {
     434                 :          0 :         int32_t ret = 0;
     435                 :            : 
     436                 :          0 :         PMD_INIT_FUNC_TRACE();
     437                 :            : 
     438                 :          0 :         sxe2_set_common_function(dev);
     439                 :            : 
     440                 :          0 :         sxe2_repr_adapter_init(dev, parent_adapter, repr_id);
     441                 :            : 
     442                 :          0 :         dev->dev_ops = &sxe2_switchdev_repr_dev_ops;
     443                 :            : 
     444                 :          0 :         ret = sxe2_vsi_repr_main_vsi_create(dev, parent_adapter, repr_id);
     445         [ #  # ]:          0 :         if (ret) {
     446                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to create representor main vsi, ret=[%d]", ret);
     447                 :          0 :                 goto l_end;
     448                 :            :         }
     449                 :            : 
     450                 :          0 :         ret = sxe2_switchdev_repr_private_data_init(dev, parent_adapter, repr_id);
     451         [ #  # ]:          0 :         if (ret) {
     452                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to fill representor private data, ret=[%d]", ret);
     453                 :          0 :                 goto l_init_priv_data_err;
     454                 :            :         }
     455                 :            : 
     456                 :          0 :         ret = sxe2_repr_dev_pci_map_init(dev);
     457         [ #  # ]:          0 :         if (ret) {
     458                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to pci addr map, ret=[%d]", ret);
     459                 :          0 :                 goto l_init_pci_error;
     460                 :            :         }
     461                 :            : 
     462                 :          0 :         ret = sxe2_switchdev_dev_info_init(dev, parent_adapter);
     463         [ #  # ]:          0 :         if (ret) {
     464                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to get device info, ret=[%d]", ret);
     465                 :          0 :                 goto l_init_dev_info_err;
     466                 :            :         }
     467                 :            : 
     468                 :          0 :         ret = sxe2_flow_init(dev);
     469         [ #  # ]:          0 :         if (ret) {
     470                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to init flow, ret=%d", ret);
     471                 :          0 :                 goto l_init_flow_err;
     472                 :            :         }
     473                 :            : 
     474                 :          0 :         ret = sxe2_repr_eth_init(dev);
     475         [ #  # ]:          0 :         if (ret) {
     476                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to init device, status = %d", ret);
     477                 :          0 :                 goto l_init_eth_err;
     478                 :            :         }
     479                 :            : 
     480                 :          0 :         ret = sxe2_sw_irq_ctxt_init(dev);
     481         [ #  # ]:          0 :         if (ret) {
     482                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to initialize sw parameters, ret=[%d]", ret);
     483                 :          0 :                 goto l_init_sw_err;
     484                 :            :         }
     485                 :            : 
     486                 :          0 :         goto l_end;
     487                 :            : 
     488                 :          0 : l_init_sw_err:
     489                 :          0 :         sxe2_eth_uinit(dev);
     490                 :          0 : l_init_eth_err:
     491                 :          0 :         (void)sxe2_flow_uninit(dev);
     492                 :          0 : l_init_flow_err:
     493                 :          0 : l_init_dev_info_err:
     494                 :          0 :         sxe2_dev_pci_map_uinit(dev);
     495                 :          0 : l_init_pci_error:
     496                 :          0 :         (void)sxe2_switchdev_uninit(dev);
     497                 :          0 : l_init_priv_data_err:
     498                 :          0 :         sxe2_vsi_repr_main_vsi_destroy(dev);
     499                 :          0 : l_end:
     500                 :          0 :         return ret;
     501                 :            : }
     502                 :            : 
     503                 :          0 : static void sxe2_repr_dev_uinit(struct rte_eth_dev *dev)
     504                 :            : {
     505                 :          0 :         sxe2_eth_uinit(dev);
     506                 :          0 :         (void)sxe2_flow_uninit(dev);
     507                 :          0 :         sxe2_dev_pci_map_uinit(dev);
     508                 :          0 :         (void)sxe2_switchdev_uninit(dev);
     509                 :          0 :         sxe2_vsi_repr_main_vsi_destroy(dev);
     510                 :          0 : }
     511                 :            : 
     512                 :          0 : int32_t sxe2_switchdev_repr_devs_init(struct sxe2_adapter *adapter,
     513                 :            :                                   struct rte_eth_devargs *req_eth_da)
     514                 :            : {
     515                 :          0 :         struct rte_eth_dev *eth_dev = NULL;
     516                 :          0 :         int32_t ret;
     517                 :          0 :         uint16_t repr_idx = 0, tmp_repr_idx = 0;
     518                 :          0 :         char name[RTE_ETH_NAME_MAX_LEN];
     519                 :            : 
     520         [ #  # ]:          0 :         if (req_eth_da->nb_representor_ports == 0) {
     521                 :          0 :                 ret = 0;
     522                 :          0 :                 goto l_end;
     523                 :            :         }
     524                 :            : 
     525         [ #  # ]:          0 :         if (req_eth_da->nb_representor_ports > adapter->repr_ctxt.nb_vf) {
     526                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to create repr vsi, nb_representor_ports=%d, nb_vf=%d",
     527                 :            :                             req_eth_da->nb_representor_ports, adapter->repr_ctxt.nb_vf);
     528                 :          0 :                 ret = -EINVAL;
     529                 :          0 :                 goto l_end;
     530                 :            :         }
     531                 :            : 
     532                 :          0 :         ret = sxe2_other_vsi_create(adapter, req_eth_da->nb_representor_ports);
     533         [ #  # ]:          0 :         if (ret) {
     534                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to create representor vsi, ret=%d", ret);
     535                 :          0 :                 goto l_release_port;
     536                 :            :         }
     537                 :            : 
     538                 :          0 :         adapter->repr_ctxt.vf_rep_eth_dev = rte_zmalloc("sxe2_repr_ethdev",
     539                 :          0 :                         req_eth_da->nb_representor_ports * sizeof(struct rte_eth_dev *), 0);
     540         [ #  # ]:          0 :         if (adapter->repr_ctxt.vf_rep_eth_dev == NULL) {
     541                 :          0 :                 PMD_LOG_ERR(INIT, "Failed to malloc representor eth dev.");
     542                 :          0 :                 ret = -ENOMEM;
     543                 :          0 :                 goto l_release_port;
     544                 :            :         }
     545                 :            : 
     546         [ #  # ]:          0 :         for (repr_idx = 0; repr_idx < req_eth_da->nb_representor_ports; ++repr_idx) {
     547                 :          0 :                 snprintf(name, sizeof(name), "sxe2_representor_c%dpf%d%s%u",
     548                 :          0 :                          adapter->pf_idx, adapter->pf_idx,
     549                 :            :                          "vf",
     550                 :          0 :                          req_eth_da->representor_ports[repr_idx]);
     551                 :            : 
     552                 :          0 :                 eth_dev = rte_eth_dev_allocate(name);
     553         [ #  # ]:          0 :                 if (!eth_dev) {
     554                 :          0 :                         ret = -ENOMEM;
     555                 :          0 :                         goto l_release_port;
     556                 :            :                 }
     557                 :          0 :                 eth_dev->data->dev_private = rte_zmalloc_socket(name,
     558                 :            :                         sizeof(struct sxe2_adapter),
     559                 :            :                         RTE_CACHE_LINE_SIZE,
     560                 :          0 :                         rte_socket_id());
     561                 :            : 
     562         [ #  # ]:          0 :                 if (!eth_dev->data->dev_private) {
     563                 :          0 :                         rte_eth_dev_release_port(eth_dev);
     564                 :          0 :                         ret = -ENOMEM;
     565                 :          0 :                         goto l_release_port;
     566                 :            :                 }
     567                 :            : 
     568                 :          0 :                 eth_dev->device = rte_eth_devices[adapter->dev_info.dev_data->port_id].device;
     569                 :            : 
     570                 :          0 :                 ret = sxe2_repr_dev_init(eth_dev, adapter,
     571                 :          0 :                                          req_eth_da->representor_ports[repr_idx]);
     572         [ #  # ]:          0 :                 if (ret) {
     573                 :          0 :                         PMD_LOG_ERR(INIT, "Sxe2 dev init failed, ret=%d", ret);
     574                 :          0 :                         rte_eth_dev_release_port(eth_dev);
     575                 :          0 :                         goto l_release_port;
     576                 :            :                 }
     577                 :            : 
     578                 :          0 :                 eth_dev->intr_handle = rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
     579         [ #  # ]:          0 :                 if (eth_dev->intr_handle == NULL) {
     580                 :          0 :                         PMD_LOG_ERR(INIT, "Sxe2 dev init representor intr_handle failed");
     581                 :          0 :                         ret = -ENOMEM;
     582                 :          0 :                         sxe2_repr_dev_uinit(eth_dev);
     583                 :          0 :                         rte_eth_dev_release_port(eth_dev);
     584                 :          0 :                         goto l_release_port;
     585                 :            :                 }
     586                 :          0 :                 adapter->repr_ctxt.vf_rep_eth_dev[repr_idx] = eth_dev;
     587                 :          0 :                 rte_eth_dev_probing_finish(eth_dev);
     588                 :            :         }
     589                 :          0 :         adapter->repr_ctxt.nb_repr_vf = req_eth_da->nb_representor_ports;
     590                 :          0 :         goto l_end;
     591                 :            : 
     592                 :          0 : l_release_port:
     593         [ #  # ]:          0 :         for (tmp_repr_idx = 0; tmp_repr_idx < repr_idx; ++tmp_repr_idx) {
     594                 :          0 :                 struct rte_eth_dev *rep_dev = adapter->repr_ctxt.vf_rep_eth_dev[tmp_repr_idx];
     595         [ #  # ]:          0 :                 if (rep_dev) {
     596                 :          0 :                         sxe2_repr_dev_uinit(rep_dev);
     597         [ #  # ]:          0 :                         if (rep_dev->intr_handle)
     598                 :          0 :                                 rte_intr_instance_free(rep_dev->intr_handle);
     599                 :          0 :                         rte_eth_dev_release_port(rep_dev);
     600                 :          0 :                         adapter->repr_ctxt.vf_rep_eth_dev[tmp_repr_idx] = NULL;
     601                 :            :                 }
     602                 :            :         }
     603                 :            : 
     604                 :          0 :         rte_free(adapter->repr_ctxt.vf_rep_eth_dev);
     605                 :          0 :         adapter->repr_ctxt.vf_rep_eth_dev = NULL;
     606                 :            : 
     607                 :          0 : l_end:
     608                 :          0 :         return ret;
     609                 :            : }

Generated by: LCOV version 1.14