LCOV - code coverage report
Current view: top level - drivers/net/cnxk - cnxk_ethdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1015 0.0 %
Date: 2025-02-01 18:54:23 Functions: 0 40 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 578 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : #include <cnxk_ethdev.h>
       5                 :            : 
       6                 :            : #include <rte_eventdev.h>
       7                 :            : #include <rte_pmd_cnxk.h>
       8                 :            : 
       9                 :            : #define CNXK_NIX_CQ_INL_CLAMP_MAX (64UL * 1024UL)
      10                 :            : 
      11                 :            : #define NIX_TM_DFLT_RR_WT 71
      12                 :            : 
      13                 :            : const char *
      14                 :          0 : rte_pmd_cnxk_model_str_get(void)
      15                 :            : {
      16                 :          0 :         return roc_model->name;
      17                 :            : }
      18                 :            : 
      19                 :            : static inline uint64_t
      20                 :            : nix_get_rx_offload_capa(struct cnxk_eth_dev *dev)
      21                 :            : {
      22                 :            :         uint64_t capa = CNXK_NIX_RX_OFFLOAD_CAPA;
      23                 :            : 
      24         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(&dev->nix) ||
      25         [ #  # ]:          0 :             dev->npc.switch_header_type == ROC_PRIV_FLAGS_HIGIG)
      26                 :            :                 capa &= ~RTE_ETH_RX_OFFLOAD_TIMESTAMP;
      27                 :            : 
      28                 :            :         return capa;
      29                 :            : }
      30                 :            : 
      31                 :            : static inline uint64_t
      32                 :            : nix_get_tx_offload_capa(struct cnxk_eth_dev *dev)
      33                 :            : {
      34                 :            :         RTE_SET_USED(dev);
      35                 :            :         return CNXK_NIX_TX_OFFLOAD_CAPA;
      36                 :            : }
      37                 :            : 
      38                 :            : static inline uint32_t
      39                 :          0 : nix_get_speed_capa(struct cnxk_eth_dev *dev)
      40                 :            : {
      41                 :            :         uint32_t speed_capa;
      42                 :            : 
      43                 :            :         /* Auto negotiation disabled */
      44                 :            :         speed_capa = RTE_ETH_LINK_SPEED_FIXED;
      45   [ #  #  #  # ]:          0 :         if (!roc_nix_is_vf_or_sdp(&dev->nix) && !roc_nix_is_lbk(&dev->nix)) {
      46                 :            :                 speed_capa |= RTE_ETH_LINK_SPEED_1G | RTE_ETH_LINK_SPEED_10G |
      47                 :            :                               RTE_ETH_LINK_SPEED_25G | RTE_ETH_LINK_SPEED_40G |
      48                 :            :                               RTE_ETH_LINK_SPEED_50G | RTE_ETH_LINK_SPEED_100G;
      49                 :            :         }
      50                 :            : 
      51                 :          0 :         return speed_capa;
      52                 :            : }
      53                 :            : 
      54                 :            : static uint32_t
      55         [ #  # ]:          0 : nix_inl_cq_sz_clamp_up(struct roc_nix *nix, struct rte_mempool *mp,
      56                 :            :                        uint32_t nb_desc)
      57                 :            : {
      58                 :            :         struct roc_nix_rq *inl_rq;
      59                 :            :         uint64_t limit;
      60                 :            : 
      61                 :            :         /* For CN10KB and above, LBP needs minimum CQ size */
      62         [ #  # ]:          0 :         if (!roc_errata_cpt_hang_on_x2p_bp())
      63                 :          0 :                 return RTE_MAX(nb_desc, (uint32_t)4096);
      64                 :            : 
      65                 :            :         /* CQ should be able to hold all buffers in first pass RQ's aura
      66                 :            :          * this RQ's aura.
      67                 :            :          */
      68                 :          0 :         inl_rq = roc_nix_inl_dev_rq(nix);
      69                 :            :         if (!inl_rq) {
      70                 :            :                 /* This itself is going to be inline RQ's aura */
      71                 :            :                 limit = roc_npa_aura_op_limit_get(mp->pool_id);
      72                 :            :         } else {
      73                 :            :                 limit = roc_npa_aura_op_limit_get(inl_rq->aura_handle);
      74                 :            :                 /* Also add this RQ's aura if it is different */
      75                 :            :                 if (inl_rq->aura_handle != mp->pool_id)
      76                 :            :                         limit += roc_npa_aura_op_limit_get(mp->pool_id);
      77                 :            :         }
      78                 :          0 :         nb_desc = PLT_MAX(limit + 1, nb_desc);
      79         [ #  # ]:          0 :         if (nb_desc > CNXK_NIX_CQ_INL_CLAMP_MAX) {
      80                 :          0 :                 plt_warn("Could not setup CQ size to accommodate"
      81                 :            :                          " all buffers in related auras (%" PRIu64 ")",
      82                 :            :                          limit);
      83                 :            :                 nb_desc = CNXK_NIX_CQ_INL_CLAMP_MAX;
      84                 :            :         }
      85                 :            :         return nb_desc;
      86                 :            : }
      87                 :            : 
      88                 :            : int
      89                 :          0 : cnxk_nix_inb_mode_set(struct cnxk_eth_dev *dev, bool use_inl_dev)
      90                 :            : {
      91                 :          0 :         struct roc_nix *nix = &dev->nix;
      92                 :            : 
      93                 :          0 :         plt_nix_dbg("Security sessions(%u) still active, inl=%u!!!",
      94                 :            :                     dev->inb.nb_sess, !!dev->inb.inl_dev);
      95                 :            : 
      96                 :            :         /* Change the mode */
      97                 :          0 :         dev->inb.inl_dev = use_inl_dev;
      98                 :            : 
      99                 :            :         /* Update RoC for NPC rule insertion */
     100                 :          0 :         roc_nix_inb_mode_set(nix, use_inl_dev);
     101                 :            : 
     102                 :            :         /* Setup lookup mem */
     103                 :          0 :         return cnxk_nix_lookup_mem_sa_base_set(dev);
     104                 :            : }
     105                 :            : 
     106                 :            : static int
     107                 :          0 : nix_security_setup(struct cnxk_eth_dev *dev)
     108                 :            : {
     109                 :          0 :         struct roc_nix *nix = &dev->nix;
     110                 :            :         int i, rc = 0;
     111                 :            : 
     112         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
     113                 :            :                 /* Setup minimum SA table when inline device is used */
     114         [ #  # ]:          0 :                 nix->ipsec_in_min_spi = dev->inb.no_inl_dev ? dev->inb.min_spi : 0;
     115         [ #  # ]:          0 :                 nix->ipsec_in_max_spi = dev->inb.no_inl_dev ? dev->inb.max_spi : 1;
     116                 :            : 
     117                 :            :                 /* Enable custom meta aura when multi-chan is used */
     118   [ #  #  #  # ]:          0 :                 if (nix->local_meta_aura_ena && roc_nix_inl_dev_is_multi_channel() &&
     119         [ #  # ]:          0 :                     !dev->inb.custom_meta_aura_dis)
     120                 :          0 :                         nix->custom_meta_aura_ena = true;
     121                 :            : 
     122                 :            :                 /* Setup Inline Inbound */
     123                 :          0 :                 rc = roc_nix_inl_inb_init(nix);
     124         [ #  # ]:          0 :                 if (rc) {
     125                 :          0 :                         plt_err("Failed to initialize nix inline inb, rc=%d",
     126                 :            :                                 rc);
     127                 :          0 :                         return rc;
     128                 :            :                 }
     129                 :            : 
     130                 :            :                 /* By default pick using inline device for poll mode.
     131                 :            :                  * Will be overridden when event mode rq's are setup.
     132                 :            :                  */
     133                 :          0 :                 cnxk_nix_inb_mode_set(dev, !dev->inb.no_inl_dev);
     134                 :            : 
     135                 :            :                 /* Allocate memory to be used as dptr for CPT ucode
     136                 :            :                  * WRITE_SA op.
     137                 :            :                  */
     138                 :          0 :                 dev->inb.sa_dptr =
     139                 :          0 :                         plt_zmalloc(ROC_NIX_INL_OT_IPSEC_INB_HW_SZ, 0);
     140         [ #  # ]:          0 :                 if (!dev->inb.sa_dptr) {
     141                 :          0 :                         plt_err("Couldn't allocate memory for SA dptr");
     142                 :            :                         rc = -ENOMEM;
     143                 :          0 :                         goto cleanup;
     144                 :            :                 }
     145                 :          0 :                 dev->inb.inl_dev_q = roc_nix_inl_dev_qptr_get(0);
     146                 :            :         }
     147                 :            : 
     148         [ #  # ]:          0 :         if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY ||
     149         [ #  # ]:          0 :             dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
     150                 :            :                 struct plt_bitmap *bmap;
     151                 :            :                 size_t bmap_sz;
     152                 :            :                 void *mem;
     153                 :            : 
     154                 :            :                 /* Setup enough descriptors for all tx queues */
     155                 :          0 :                 nix->outb_nb_desc = dev->outb.nb_desc;
     156                 :          0 :                 nix->outb_nb_crypto_qs = dev->outb.nb_crypto_qs;
     157                 :            : 
     158                 :            :                 /* Setup Inline Outbound */
     159                 :          0 :                 rc = roc_nix_inl_outb_init(nix);
     160         [ #  # ]:          0 :                 if (rc) {
     161                 :          0 :                         plt_err("Failed to initialize nix inline outb, rc=%d",
     162                 :            :                                 rc);
     163                 :          0 :                         goto sa_dptr_free;
     164                 :            :                 }
     165                 :            : 
     166                 :          0 :                 dev->outb.lf_base = roc_nix_inl_outb_lf_base_get(nix);
     167                 :            : 
     168                 :            :                 /* Skip the rest if DEV_TX_OFFLOAD_SECURITY is not enabled */
     169         [ #  # ]:          0 :                 if (!(dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY))
     170                 :            :                         return 0;
     171                 :            : 
     172                 :            :                 /* Allocate memory to be used as dptr for CPT ucode
     173                 :            :                  * WRITE_SA op.
     174                 :            :                  */
     175                 :          0 :                 dev->outb.sa_dptr =
     176                 :          0 :                         plt_zmalloc(ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ, 0);
     177         [ #  # ]:          0 :                 if (!dev->outb.sa_dptr) {
     178                 :          0 :                         plt_err("Couldn't allocate memory for SA dptr");
     179                 :            :                         rc = -ENOMEM;
     180                 :          0 :                         goto sa_dptr_free;
     181                 :            :                 }
     182                 :            : 
     183                 :            :                 rc = -ENOMEM;
     184                 :            :                 /* Allocate a bitmap to alloc and free sa indexes */
     185                 :          0 :                 bmap_sz = plt_bitmap_get_memory_footprint(dev->outb.max_sa);
     186                 :          0 :                 mem = plt_zmalloc(bmap_sz, PLT_CACHE_LINE_SIZE);
     187         [ #  # ]:          0 :                 if (mem == NULL) {
     188                 :          0 :                         plt_err("Outbound SA bmap alloc failed");
     189                 :            : 
     190                 :          0 :                         rc |= roc_nix_inl_outb_fini(nix);
     191                 :          0 :                         goto sa_dptr_free;
     192                 :            :                 }
     193                 :            : 
     194                 :            :                 rc = -EIO;
     195                 :          0 :                 bmap = plt_bitmap_init(dev->outb.max_sa, mem, bmap_sz);
     196         [ #  # ]:          0 :                 if (!bmap) {
     197                 :          0 :                         plt_err("Outbound SA bmap init failed");
     198                 :            : 
     199                 :          0 :                         rc |= roc_nix_inl_outb_fini(nix);
     200                 :          0 :                         plt_free(mem);
     201                 :          0 :                         goto sa_dptr_free;
     202                 :            :                 }
     203                 :            : 
     204         [ #  # ]:          0 :                 for (i = 0; i < dev->outb.max_sa; i++)
     205                 :          0 :                         plt_bitmap_set(bmap, i);
     206                 :            : 
     207                 :          0 :                 dev->outb.sa_base = roc_nix_inl_outb_sa_base_get(nix);
     208                 :          0 :                 dev->outb.sa_bmap_mem = mem;
     209                 :          0 :                 dev->outb.sa_bmap = bmap;
     210                 :            : 
     211                 :          0 :                 dev->outb.fc_sw_mem = plt_zmalloc(dev->outb.nb_crypto_qs *
     212                 :            :                                                           RTE_CACHE_LINE_SIZE,
     213                 :            :                                                   RTE_CACHE_LINE_SIZE);
     214         [ #  # ]:          0 :                 if (!dev->outb.fc_sw_mem) {
     215                 :          0 :                         plt_err("Outbound fc sw mem alloc failed");
     216                 :          0 :                         goto sa_bmap_free;
     217                 :            :                 }
     218                 :            : 
     219                 :          0 :                 dev->outb.cpt_eng_caps = roc_nix_inl_eng_caps_get(nix);
     220                 :            :         }
     221                 :            :         return 0;
     222                 :            : 
     223                 :            : sa_bmap_free:
     224                 :          0 :         plt_free(dev->outb.sa_bmap_mem);
     225                 :          0 : sa_dptr_free:
     226         [ #  # ]:          0 :         if (dev->inb.sa_dptr)
     227                 :          0 :                 plt_free(dev->inb.sa_dptr);
     228         [ #  # ]:          0 :         if (dev->outb.sa_dptr)
     229                 :          0 :                 plt_free(dev->outb.sa_dptr);
     230                 :          0 : cleanup:
     231         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
     232                 :          0 :                 rc |= roc_nix_inl_inb_fini(nix);
     233                 :            :         return rc;
     234                 :            : }
     235                 :            : 
     236                 :            : static int
     237                 :          0 : nix_meter_fini(struct cnxk_eth_dev *dev)
     238                 :            : {
     239                 :            :         struct cnxk_meter_node *next_mtr = NULL;
     240                 :          0 :         struct roc_nix_bpf_objs profs = {0};
     241                 :            :         struct cnxk_meter_node *mtr = NULL;
     242                 :            :         struct cnxk_mtr *fms = &dev->mtr;
     243                 :          0 :         struct roc_nix *nix = &dev->nix;
     244                 :            :         struct roc_nix_rq *rq;
     245                 :            :         uint32_t i;
     246                 :            :         int rc = 0;
     247                 :            : 
     248         [ #  # ]:          0 :         RTE_TAILQ_FOREACH_SAFE(mtr, fms, next, next_mtr) {
     249         [ #  # ]:          0 :                 for (i = 0; i < mtr->rq_num; i++) {
     250                 :          0 :                         rq = &dev->rqs[mtr->rq_id[i]];
     251                 :          0 :                         rc |= roc_nix_bpf_ena_dis(nix, mtr->bpf_id, rq, false);
     252                 :            :                 }
     253                 :            : 
     254                 :          0 :                 profs.level = mtr->level;
     255                 :          0 :                 profs.count = 1;
     256                 :          0 :                 profs.ids[0] = mtr->bpf_id;
     257                 :          0 :                 rc = roc_nix_bpf_free(nix, &profs, 1);
     258                 :            : 
     259         [ #  # ]:          0 :                 if (rc)
     260                 :          0 :                         return rc;
     261                 :            : 
     262         [ #  # ]:          0 :                 TAILQ_REMOVE(fms, mtr, next);
     263                 :          0 :                 plt_free(mtr);
     264                 :            :         }
     265                 :            :         return 0;
     266                 :            : }
     267                 :            : 
     268                 :            : static int
     269                 :          0 : nix_security_release(struct cnxk_eth_dev *dev)
     270                 :            : {
     271                 :          0 :         struct rte_eth_dev *eth_dev = dev->eth_dev;
     272                 :            :         struct cnxk_eth_sec_sess *eth_sec, *tvar;
     273                 :          0 :         struct roc_nix *nix = &dev->nix;
     274                 :            :         int rc, ret = 0;
     275                 :            : 
     276                 :            :         /* Cleanup Inline inbound */
     277         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
     278                 :            :                 /* Destroy inbound sessions */
     279                 :            :                 tvar = NULL;
     280         [ #  # ]:          0 :                 RTE_TAILQ_FOREACH_SAFE(eth_sec, &dev->inb.list, entry, tvar)
     281                 :          0 :                         cnxk_eth_sec_ops.session_destroy(eth_dev,
     282                 :            :                                                          eth_sec->sess);
     283                 :            : 
     284                 :            :                 /* Clear lookup mem */
     285                 :          0 :                 cnxk_nix_lookup_mem_sa_base_clear(dev);
     286                 :            : 
     287                 :          0 :                 rc = roc_nix_inl_inb_fini(nix);
     288         [ #  # ]:          0 :                 if (rc)
     289                 :          0 :                         plt_err("Failed to cleanup nix inline inb, rc=%d", rc);
     290                 :            :                 ret |= rc;
     291                 :            : 
     292                 :          0 :                 cnxk_nix_lookup_mem_metapool_clear(dev);
     293                 :            : 
     294         [ #  # ]:          0 :                 if (dev->inb.sa_dptr) {
     295                 :          0 :                         plt_free(dev->inb.sa_dptr);
     296                 :          0 :                         dev->inb.sa_dptr = NULL;
     297                 :            :                 }
     298                 :            :         }
     299                 :            : 
     300                 :            :         /* Cleanup Inline outbound */
     301         [ #  # ]:          0 :         if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY ||
     302         [ #  # ]:          0 :             dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
     303                 :            :                 /* Destroy outbound sessions */
     304                 :            :                 tvar = NULL;
     305         [ #  # ]:          0 :                 RTE_TAILQ_FOREACH_SAFE(eth_sec, &dev->outb.list, entry, tvar)
     306                 :          0 :                         cnxk_eth_sec_ops.session_destroy(eth_dev,
     307                 :            :                                                          eth_sec->sess);
     308                 :            : 
     309                 :          0 :                 rc = roc_nix_inl_outb_fini(nix);
     310         [ #  # ]:          0 :                 if (rc)
     311                 :          0 :                         plt_err("Failed to cleanup nix inline outb, rc=%d", rc);
     312                 :          0 :                 ret |= rc;
     313                 :            : 
     314                 :            :                 plt_bitmap_free(dev->outb.sa_bmap);
     315                 :          0 :                 plt_free(dev->outb.sa_bmap_mem);
     316                 :          0 :                 dev->outb.sa_bmap = NULL;
     317                 :          0 :                 dev->outb.sa_bmap_mem = NULL;
     318         [ #  # ]:          0 :                 if (dev->outb.sa_dptr) {
     319                 :          0 :                         plt_free(dev->outb.sa_dptr);
     320                 :          0 :                         dev->outb.sa_dptr = NULL;
     321                 :            :                 }
     322                 :            : 
     323                 :          0 :                 plt_free(dev->outb.fc_sw_mem);
     324                 :          0 :                 dev->outb.fc_sw_mem = NULL;
     325                 :            :         }
     326                 :            : 
     327                 :          0 :         dev->inb.inl_dev = false;
     328                 :          0 :         roc_nix_inb_mode_set(nix, false);
     329                 :          0 :         dev->nb_rxq_sso = 0;
     330                 :          0 :         dev->inb.nb_sess = 0;
     331                 :          0 :         dev->outb.nb_sess = 0;
     332                 :          0 :         return ret;
     333                 :            : }
     334                 :            : 
     335                 :            : static void
     336                 :          0 : nix_enable_mseg_on_jumbo(struct cnxk_eth_rxq_sp *rxq)
     337                 :            : {
     338                 :            :         struct rte_pktmbuf_pool_private *mbp_priv;
     339                 :            :         struct rte_eth_dev *eth_dev;
     340                 :            :         struct cnxk_eth_dev *dev;
     341                 :            :         uint32_t buffsz;
     342                 :            : 
     343                 :          0 :         dev = rxq->dev;
     344                 :          0 :         eth_dev = dev->eth_dev;
     345                 :            : 
     346                 :            :         /* Get rx buffer size */
     347         [ #  # ]:          0 :         mbp_priv = rte_mempool_get_priv(rxq->qconf.mp);
     348                 :          0 :         buffsz = mbp_priv->mbuf_data_room_size - RTE_PKTMBUF_HEADROOM;
     349                 :            : 
     350         [ #  # ]:          0 :         if (eth_dev->data->mtu + (uint32_t)CNXK_NIX_L2_OVERHEAD > buffsz) {
     351                 :          0 :                 dev->rx_offloads |= RTE_ETH_RX_OFFLOAD_SCATTER;
     352                 :          0 :                 dev->tx_offloads |= RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
     353                 :            :         }
     354                 :          0 : }
     355                 :            : 
     356                 :            : int
     357                 :          0 : nix_recalc_mtu(struct rte_eth_dev *eth_dev)
     358                 :            : {
     359                 :          0 :         struct rte_eth_dev_data *data = eth_dev->data;
     360                 :            :         struct cnxk_eth_rxq_sp *rxq;
     361                 :            :         int rc;
     362                 :            : 
     363                 :          0 :         rxq = ((struct cnxk_eth_rxq_sp *)data->rx_queues[0]) - 1;
     364                 :            :         /* Setup scatter mode if needed by jumbo */
     365                 :          0 :         nix_enable_mseg_on_jumbo(rxq);
     366                 :            : 
     367                 :          0 :         rc = cnxk_nix_mtu_set(eth_dev, data->mtu);
     368         [ #  # ]:          0 :         if (rc)
     369                 :          0 :                 plt_err("Failed to set default MTU size, rc=%d", rc);
     370                 :            : 
     371                 :          0 :         return rc;
     372                 :            : }
     373                 :            : 
     374                 :            : static int
     375                 :          0 : nix_init_flow_ctrl_config(struct rte_eth_dev *eth_dev)
     376                 :            : {
     377                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     378                 :            :         enum roc_nix_fc_mode fc_mode = ROC_NIX_FC_FULL;
     379                 :            :         struct cnxk_fc_cfg *fc = &dev->fc_cfg;
     380                 :            :         int rc;
     381                 :            : 
     382   [ #  #  #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(&dev->nix) && !roc_nix_is_lbk(&dev->nix))
     383                 :            :                 return 0;
     384                 :            : 
     385                 :            :         /* To avoid Link credit deadlock on Ax, disable Tx FC if it's enabled */
     386         [ #  # ]:          0 :         if (roc_model_is_cn96_ax() &&
     387         [ #  # ]:          0 :             dev->npc.switch_header_type != ROC_PRIV_FLAGS_HIGIG)
     388                 :            :                 fc_mode = ROC_NIX_FC_TX;
     389                 :            : 
     390                 :            :         /* By default enable flow control */
     391                 :          0 :         rc = roc_nix_fc_mode_set(&dev->nix, fc_mode);
     392         [ #  # ]:          0 :         if (rc)
     393                 :            :                 return rc;
     394                 :            : 
     395         [ #  # ]:          0 :         fc->mode = (fc_mode == ROC_NIX_FC_FULL) ? RTE_ETH_FC_FULL : RTE_ETH_FC_TX_PAUSE;
     396                 :          0 :         fc->rx_pause = (fc->mode == RTE_ETH_FC_FULL) || (fc->mode == RTE_ETH_FC_RX_PAUSE);
     397                 :          0 :         fc->tx_pause = (fc->mode == RTE_ETH_FC_FULL) || (fc->mode == RTE_ETH_FC_TX_PAUSE);
     398                 :          0 :         return rc;
     399                 :            : }
     400                 :            : 
     401                 :            : static int
     402                 :          0 : nix_update_flow_ctrl_config(struct rte_eth_dev *eth_dev)
     403                 :            : {
     404                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     405                 :            :         struct cnxk_fc_cfg *fc = &dev->fc_cfg;
     406                 :          0 :         struct rte_eth_fc_conf fc_cfg = {0};
     407                 :            : 
     408   [ #  #  #  # ]:          0 :         if (roc_nix_is_sdp(&dev->nix) || roc_nix_is_esw(&dev->nix))
     409                 :          0 :                 return 0;
     410                 :            : 
     411                 :            :         /* Don't do anything if PFC is enabled */
     412         [ #  # ]:          0 :         if (dev->pfc_cfg.rx_pause_en || dev->pfc_cfg.tx_pause_en)
     413                 :            :                 return 0;
     414                 :            : 
     415         [ #  # ]:          0 :         fc_cfg.mode = fc->mode;
     416                 :            : 
     417                 :            :         /* To avoid Link credit deadlock on Ax, disable Tx FC if it's enabled */
     418         [ #  # ]:          0 :         if (roc_model_is_cn96_ax() &&
     419         [ #  # ]:          0 :             dev->npc.switch_header_type != ROC_PRIV_FLAGS_HIGIG &&
     420         [ #  # ]:          0 :             (fc_cfg.mode == RTE_ETH_FC_FULL || fc_cfg.mode == RTE_ETH_FC_RX_PAUSE)) {
     421                 :          0 :                 fc_cfg.mode =
     422                 :          0 :                                 (fc_cfg.mode == RTE_ETH_FC_FULL ||
     423                 :            :                                 fc_cfg.mode == RTE_ETH_FC_TX_PAUSE) ?
     424         [ #  # ]:          0 :                                 RTE_ETH_FC_TX_PAUSE : RTE_ETH_FC_NONE;
     425                 :            :         }
     426                 :            : 
     427                 :          0 :         return cnxk_nix_flow_ctrl_set(eth_dev, &fc_cfg);
     428                 :            : }
     429                 :            : 
     430                 :            : uint64_t
     431                 :          0 : cnxk_nix_rxq_mbuf_setup(struct cnxk_eth_dev *dev)
     432                 :            : {
     433                 :          0 :         uint16_t port_id = dev->eth_dev->data->port_id;
     434                 :            :         struct rte_mbuf mb_def;
     435                 :            :         uint64_t *tmp;
     436                 :            : 
     437                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, data_off) % 8 != 0);
     438                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, refcnt) -
     439                 :            :                                  offsetof(struct rte_mbuf, data_off) !=
     440                 :            :                          2);
     441                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, nb_segs) -
     442                 :            :                                  offsetof(struct rte_mbuf, data_off) !=
     443                 :            :                          4);
     444                 :            :         RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, port) -
     445                 :            :                                  offsetof(struct rte_mbuf, data_off) !=
     446                 :            :                          6);
     447                 :          0 :         mb_def.nb_segs = 1;
     448                 :          0 :         mb_def.data_off = RTE_PKTMBUF_HEADROOM +
     449                 :          0 :                           (dev->ptp_en * CNXK_NIX_TIMESYNC_RX_OFFSET);
     450                 :          0 :         mb_def.port = port_id;
     451                 :            :         rte_mbuf_refcnt_set(&mb_def, 1);
     452                 :            : 
     453                 :            :         /* Prevent compiler reordering: rearm_data covers previous fields */
     454                 :          0 :         rte_compiler_barrier();
     455                 :            :         tmp = (uint64_t *)&mb_def.rearm_data;
     456                 :            : 
     457                 :          0 :         return *tmp;
     458                 :            : }
     459                 :            : 
     460                 :            : static inline uint8_t
     461                 :            : nix_sq_max_sqe_sz(struct cnxk_eth_dev *dev)
     462                 :            : {
     463                 :            :         /*
     464                 :            :          * Maximum three segments can be supported with W8, Choose
     465                 :            :          * NIX_MAXSQESZ_W16 for multi segment offload.
     466                 :            :          */
     467                 :          0 :         if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_MULTI_SEGS)
     468                 :            :                 return NIX_MAXSQESZ_W16;
     469                 :            :         else
     470                 :          0 :                 return NIX_MAXSQESZ_W8;
     471                 :            : }
     472                 :            : 
     473                 :            : int
     474         [ #  # ]:          0 : cnxk_nix_tx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
     475                 :            :                         uint16_t nb_desc, uint16_t fp_tx_q_sz,
     476                 :            :                         const struct rte_eth_txconf *tx_conf)
     477                 :            : {
     478                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     479                 :          0 :         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
     480                 :            :         struct roc_nix *nix = &dev->nix;
     481                 :            :         struct cnxk_eth_txq_sp *txq_sp;
     482                 :            :         struct roc_nix_cq *cq;
     483                 :            :         struct roc_nix_sq *sq;
     484                 :            :         size_t txq_sz;
     485                 :            :         int rc;
     486                 :            : 
     487                 :            :         /* Free memory prior to re-allocation if needed. */
     488         [ #  # ]:          0 :         if (eth_dev->data->tx_queues[qid] != NULL) {
     489                 :          0 :                 plt_nix_dbg("Freeing memory prior to re-allocation %d", qid);
     490                 :          0 :                 dev_ops->tx_queue_release(eth_dev, qid);
     491                 :          0 :                 eth_dev->data->tx_queues[qid] = NULL;
     492                 :            :         }
     493                 :            : 
     494                 :            :         /* When Tx Security offload is enabled, increase tx desc count by
     495                 :            :          * max possible outbound desc count.
     496                 :            :          */
     497         [ #  # ]:          0 :         if (dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY)
     498                 :          0 :                 nb_desc += dev->outb.nb_desc;
     499                 :            : 
     500                 :            :         /* Setup ROC SQ */
     501                 :          0 :         sq = &dev->sqs[qid];
     502                 :          0 :         sq->qid = qid;
     503         [ #  # ]:          0 :         sq->nb_desc = nb_desc;
     504                 :          0 :         sq->max_sqe_sz = nix_sq_max_sqe_sz(dev);
     505         [ #  # ]:          0 :         if (sq->nb_desc >= CNXK_NIX_DEF_SQ_COUNT)
     506                 :          0 :                 sq->fc_hyst_bits = 0x1;
     507                 :            : 
     508         [ #  # ]:          0 :         if (nix->tx_compl_ena) {
     509                 :          0 :                 sq->cqid = sq->qid + dev->nb_rxq;
     510                 :          0 :                 sq->cq_ena = 1;
     511                 :          0 :                 cq = &dev->cqs[sq->cqid];
     512                 :          0 :                 cq->qid = sq->cqid;
     513                 :          0 :                 cq->nb_desc = nb_desc;
     514                 :          0 :                 rc = roc_nix_cq_init(&dev->nix, cq);
     515         [ #  # ]:          0 :                 if (rc) {
     516                 :          0 :                         plt_err("Failed to init cq=%d, rc=%d", cq->qid, rc);
     517                 :          0 :                         return rc;
     518                 :            :                 }
     519                 :            :         }
     520                 :            : 
     521                 :          0 :         rc = roc_nix_sq_init(&dev->nix, sq);
     522         [ #  # ]:          0 :         if (rc) {
     523                 :          0 :                 plt_err("Failed to init sq=%d, rc=%d", qid, rc);
     524                 :          0 :                 return rc;
     525                 :            :         }
     526                 :            : 
     527                 :            :         rc = -ENOMEM;
     528                 :          0 :         txq_sz = sizeof(struct cnxk_eth_txq_sp) + fp_tx_q_sz;
     529                 :          0 :         txq_sp = plt_zmalloc(txq_sz, PLT_CACHE_LINE_SIZE);
     530         [ #  # ]:          0 :         if (!txq_sp) {
     531                 :          0 :                 plt_err("Failed to alloc tx queue mem");
     532                 :          0 :                 rc |= roc_nix_sq_fini(sq);
     533                 :          0 :                 return rc;
     534                 :            :         }
     535                 :            : 
     536                 :          0 :         txq_sp->dev = dev;
     537                 :          0 :         txq_sp->qid = qid;
     538                 :          0 :         txq_sp->qconf.conf.tx = *tx_conf;
     539                 :            :         /* Queue config should reflect global offloads */
     540                 :          0 :         txq_sp->qconf.conf.tx.offloads = dev->tx_offloads;
     541                 :          0 :         txq_sp->qconf.nb_desc = nb_desc;
     542                 :            : 
     543                 :          0 :         plt_nix_dbg("sq=%d fc=%p offload=0x%" PRIx64 " lmt_addr=%p"
     544                 :            :                     " nb_sqb_bufs=%d sqes_per_sqb_log2=%d",
     545                 :            :                     qid, sq->fc, dev->tx_offloads, sq->lmt_addr,
     546                 :            :                     sq->nb_sqb_bufs, sq->sqes_per_sqb_log2);
     547                 :            : 
     548                 :            :         /* Store start of fast path area */
     549                 :          0 :         eth_dev->data->tx_queues[qid] = txq_sp + 1;
     550                 :          0 :         eth_dev->data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
     551                 :          0 :         return 0;
     552                 :            : }
     553                 :            : 
     554                 :            : void
     555                 :          0 : cnxk_nix_tx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
     556                 :            : {
     557                 :          0 :         void *txq = eth_dev->data->tx_queues[qid];
     558                 :            :         struct cnxk_eth_txq_sp *txq_sp;
     559                 :            :         struct cnxk_eth_dev *dev;
     560                 :            :         struct roc_nix_sq *sq;
     561                 :            :         int rc;
     562                 :            : 
     563         [ #  # ]:          0 :         if (!txq)
     564                 :            :                 return;
     565                 :            : 
     566                 :            :         txq_sp = cnxk_eth_txq_to_sp(txq);
     567                 :            : 
     568                 :          0 :         dev = txq_sp->dev;
     569                 :            : 
     570                 :          0 :         plt_nix_dbg("Releasing txq %u", qid);
     571                 :            : 
     572                 :            :         /* Cleanup ROC SQ */
     573                 :          0 :         sq = &dev->sqs[qid];
     574                 :          0 :         rc = roc_nix_sq_fini(sq);
     575         [ #  # ]:          0 :         if (rc)
     576                 :          0 :                 plt_err("Failed to cleanup sq, rc=%d", rc);
     577                 :            : 
     578                 :            :         /* Finally free */
     579                 :          0 :         plt_free(txq_sp);
     580                 :            : }
     581                 :            : 
     582                 :            : static int
     583                 :          0 : cnxk_nix_process_rx_conf(const struct rte_eth_rxconf *rx_conf,
     584                 :            :                          struct rte_mempool **lpb_pool,
     585                 :            :                          struct rte_mempool **spb_pool)
     586                 :            : {
     587                 :            :         struct rte_mempool *pool0;
     588                 :            :         struct rte_mempool *pool1;
     589                 :          0 :         struct rte_mempool **mp = rx_conf->rx_mempools;
     590                 :            :         const char *platform_ops;
     591                 :            :         struct rte_mempool_ops *ops;
     592                 :            : 
     593         [ #  # ]:          0 :         if (*lpb_pool ||
     594         [ #  # ]:          0 :             rx_conf->rx_nmempool != CNXK_NIX_NUM_POOLS_MAX) {
     595                 :          0 :                 plt_err("invalid arguments");
     596                 :          0 :                 return -EINVAL;
     597                 :            :         }
     598                 :            : 
     599   [ #  #  #  #  :          0 :         if (mp == NULL || mp[0] == NULL || mp[1] == NULL) {
                   #  # ]
     600                 :          0 :                 plt_err("invalid memory pools");
     601                 :          0 :                 return -EINVAL;
     602                 :            :         }
     603                 :            : 
     604                 :            :         pool0 = mp[0];
     605                 :            :         pool1 = mp[1];
     606                 :            : 
     607         [ #  # ]:          0 :         if (pool0->elt_size > pool1->elt_size) {
     608                 :          0 :                 *lpb_pool = pool0;
     609                 :          0 :                 *spb_pool = pool1;
     610                 :            : 
     611                 :            :         } else {
     612                 :          0 :                 *lpb_pool = pool1;
     613                 :          0 :                 *spb_pool = pool0;
     614                 :            :         }
     615                 :            : 
     616         [ #  # ]:          0 :         if ((*spb_pool)->pool_id == 0) {
     617                 :          0 :                 plt_err("Invalid pool_id");
     618                 :          0 :                 return -EINVAL;
     619                 :            :         }
     620                 :            : 
     621                 :          0 :         platform_ops = rte_mbuf_platform_mempool_ops();
     622         [ #  # ]:          0 :         ops = rte_mempool_get_ops((*spb_pool)->ops_index);
     623         [ #  # ]:          0 :         if (strncmp(ops->name, platform_ops, RTE_MEMPOOL_OPS_NAMESIZE)) {
     624                 :          0 :                 plt_err("mempool ops should be of cnxk_npa type");
     625                 :          0 :                 return -EINVAL;
     626                 :            :         }
     627                 :            : 
     628                 :          0 :         plt_info("spb_pool:%s lpb_pool:%s lpb_len:%u spb_len:%u", (*spb_pool)->name,
     629                 :            :                  (*lpb_pool)->name, (*lpb_pool)->elt_size, (*spb_pool)->elt_size);
     630                 :            : 
     631                 :          0 :         return 0;
     632                 :            : }
     633                 :            : 
     634                 :            : int
     635         [ #  # ]:          0 : cnxk_nix_rx_queue_setup(struct rte_eth_dev *eth_dev, uint16_t qid,
     636                 :            :                         uint32_t nb_desc, uint16_t fp_rx_q_sz,
     637                 :            :                         const struct rte_eth_rxconf *rx_conf,
     638                 :            :                         struct rte_mempool *mp)
     639                 :            : {
     640                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     641                 :          0 :         struct roc_nix *nix = &dev->nix;
     642                 :            :         struct cnxk_eth_rxq_sp *rxq_sp;
     643                 :            :         struct rte_mempool_ops *ops;
     644                 :            :         const char *platform_ops;
     645                 :            :         struct roc_nix_rq *rq;
     646                 :            :         struct roc_nix_cq *cq;
     647                 :            :         uint16_t first_skip;
     648                 :            :         uint16_t wqe_skip;
     649                 :            :         int rc = -EINVAL;
     650                 :            :         size_t rxq_sz;
     651                 :          0 :         struct rte_mempool *lpb_pool = mp;
     652                 :          0 :         struct rte_mempool *spb_pool = NULL;
     653                 :            : 
     654                 :            :         /* Sanity checks */
     655         [ #  # ]:          0 :         if (rx_conf->rx_deferred_start == 1) {
     656                 :          0 :                 plt_err("Deferred Rx start is not supported");
     657                 :          0 :                 goto fail;
     658                 :            :         }
     659                 :            : 
     660         [ #  # ]:          0 :         if (rx_conf->rx_nmempool > 0) {
     661                 :          0 :                 rc = cnxk_nix_process_rx_conf(rx_conf, &lpb_pool, &spb_pool);
     662         [ #  # ]:          0 :                 if (rc)
     663                 :          0 :                         goto fail;
     664                 :            :         }
     665                 :            : 
     666                 :          0 :         platform_ops = rte_mbuf_platform_mempool_ops();
     667                 :            :         /* This driver needs cnxk_npa mempool ops to work */
     668         [ #  # ]:          0 :         ops = rte_mempool_get_ops(lpb_pool->ops_index);
     669         [ #  # ]:          0 :         if (strncmp(ops->name, platform_ops, RTE_MEMPOOL_OPS_NAMESIZE)) {
     670                 :          0 :                 plt_err("mempool ops should be of cnxk_npa type");
     671                 :          0 :                 goto fail;
     672                 :            :         }
     673                 :            : 
     674         [ #  # ]:          0 :         if (lpb_pool->pool_id == 0) {
     675                 :          0 :                 plt_err("Invalid pool_id");
     676                 :          0 :                 goto fail;
     677                 :            :         }
     678                 :            : 
     679                 :            :         /* Free memory prior to re-allocation if needed */
     680         [ #  # ]:          0 :         if (eth_dev->data->rx_queues[qid] != NULL) {
     681                 :          0 :                 const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
     682                 :            : 
     683                 :          0 :                 plt_nix_dbg("Freeing memory prior to re-allocation %d", qid);
     684                 :          0 :                 dev_ops->rx_queue_release(eth_dev, qid);
     685                 :          0 :                 eth_dev->data->rx_queues[qid] = NULL;
     686                 :            :         }
     687                 :            : 
     688                 :            :         /* Its a no-op when inline device is not used */
     689         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY ||
     690         [ #  # ]:          0 :             dev->tx_offloads & RTE_ETH_TX_OFFLOAD_SECURITY)
     691                 :          0 :                 roc_nix_inl_dev_xaq_realloc(lpb_pool->pool_id);
     692                 :            : 
     693                 :            :         /* Increase CQ size to Aura size to avoid CQ overflow and
     694                 :            :          * then CPT buffer leak.
     695                 :            :          */
     696         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
     697                 :          0 :                 nb_desc = nix_inl_cq_sz_clamp_up(nix, lpb_pool, nb_desc);
     698                 :            : 
     699                 :            :         /* Setup ROC CQ */
     700                 :          0 :         cq = &dev->cqs[qid];
     701                 :          0 :         cq->qid = qid;
     702                 :          0 :         cq->nb_desc = nb_desc;
     703                 :          0 :         rc = roc_nix_cq_init(&dev->nix, cq);
     704         [ #  # ]:          0 :         if (rc) {
     705                 :          0 :                 plt_err("Failed to init roc cq for rq=%d, rc=%d", qid, rc);
     706                 :          0 :                 goto fail;
     707                 :            :         }
     708                 :            : 
     709                 :            :         /* Setup ROC RQ */
     710                 :          0 :         rq = &dev->rqs[qid];
     711                 :          0 :         rq->qid = qid;
     712                 :          0 :         rq->cqid = cq->qid;
     713                 :          0 :         rq->aura_handle = lpb_pool->pool_id;
     714                 :          0 :         rq->flow_tag_width = 32;
     715         [ #  # ]:          0 :         rq->sso_ena = false;
     716                 :            : 
     717                 :            :         /* Calculate first mbuf skip */
     718                 :            :         first_skip = (sizeof(struct rte_mbuf));
     719                 :            :         first_skip += RTE_PKTMBUF_HEADROOM;
     720                 :          0 :         first_skip += rte_pktmbuf_priv_size(lpb_pool);
     721                 :          0 :         rq->first_skip = first_skip;
     722                 :          0 :         rq->later_skip = sizeof(struct rte_mbuf) + rte_pktmbuf_priv_size(lpb_pool);
     723         [ #  # ]:          0 :         rq->lpb_size = lpb_pool->elt_size;
     724         [ #  # ]:          0 :         if (roc_errata_nix_no_meta_aura())
     725                 :          0 :                 rq->lpb_drop_ena = !(dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY);
     726                 :            : 
     727                 :            :         /* Enable Inline IPSec on RQ, will not be used for Poll mode */
     728   [ #  #  #  # ]:          0 :         if (roc_nix_inl_inb_is_enabled(nix) && !dev->inb.inl_dev) {
     729                 :          0 :                 rq->ipsech_ena = true;
     730                 :            :                 /* WQE skip is needed when poll mode is enabled in CN10KA_B0 and above
     731                 :            :                  * for Inline IPsec traffic to CQ without inline device.
     732                 :            :                  */
     733                 :            :                 wqe_skip = RTE_ALIGN_CEIL(sizeof(struct rte_mbuf), ROC_CACHE_LINE_SZ);
     734                 :            :                 wqe_skip = wqe_skip / ROC_CACHE_LINE_SZ;
     735                 :          0 :                 rq->wqe_skip = wqe_skip;
     736                 :            :         }
     737                 :            : 
     738         [ #  # ]:          0 :         if (spb_pool) {
     739                 :          0 :                 rq->spb_ena = 1;
     740                 :          0 :                 rq->spb_aura_handle = spb_pool->pool_id;
     741                 :          0 :                 rq->spb_size = spb_pool->elt_size;
     742                 :            :         }
     743                 :            : 
     744                 :          0 :         rc = roc_nix_rq_init(&dev->nix, rq, !!eth_dev->data->dev_started);
     745         [ #  # ]:          0 :         if (rc) {
     746                 :          0 :                 plt_err("Failed to init roc rq for rq=%d, rc=%d", qid, rc);
     747                 :          0 :                 goto cq_fini;
     748                 :            :         }
     749                 :            : 
     750                 :            :         /* Allocate and setup fast path rx queue */
     751                 :            :         rc = -ENOMEM;
     752                 :          0 :         rxq_sz = sizeof(struct cnxk_eth_rxq_sp) + fp_rx_q_sz;
     753                 :          0 :         rxq_sp = plt_zmalloc(rxq_sz, PLT_CACHE_LINE_SIZE);
     754         [ #  # ]:          0 :         if (!rxq_sp) {
     755                 :          0 :                 plt_err("Failed to alloc rx queue for rq=%d", qid);
     756                 :          0 :                 goto rq_fini;
     757                 :            :         }
     758                 :            : 
     759                 :            :         /* Setup slow path fields */
     760                 :          0 :         rxq_sp->dev = dev;
     761                 :          0 :         rxq_sp->qid = qid;
     762                 :          0 :         rxq_sp->qconf.conf.rx = *rx_conf;
     763                 :            :         /* Queue config should reflect global offloads */
     764                 :          0 :         rxq_sp->qconf.conf.rx.offloads = dev->rx_offloads;
     765                 :          0 :         rxq_sp->qconf.nb_desc = nb_desc;
     766                 :          0 :         rxq_sp->qconf.mp = lpb_pool;
     767                 :          0 :         rxq_sp->tc = 0;
     768                 :          0 :         rxq_sp->tx_pause = (dev->fc_cfg.mode == RTE_ETH_FC_FULL ||
     769                 :            :                             dev->fc_cfg.mode == RTE_ETH_FC_TX_PAUSE);
     770                 :            : 
     771         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
     772                 :            :                 /* Pass a tagmask used to handle error packets in inline device.
     773                 :            :                  * Ethdev rq's tag_mask field will be overwritten later
     774                 :            :                  * when sso is setup.
     775                 :            :                  */
     776                 :          0 :                 rq->tag_mask =
     777                 :            :                         0x0FF00000 | ((uint32_t)RTE_EVENT_TYPE_ETHDEV << 28);
     778                 :            : 
     779                 :            :                 /* Setup rq reference for inline dev if present */
     780                 :          0 :                 rc = roc_nix_inl_dev_rq_get(rq, !!eth_dev->data->dev_started);
     781         [ #  # ]:          0 :                 if (rc)
     782                 :          0 :                         goto free_mem;
     783                 :            :         }
     784                 :            : 
     785                 :          0 :         plt_nix_dbg("rq=%d pool=%s nb_desc=%d->%d", qid, lpb_pool->name, nb_desc,
     786                 :            :                     cq->nb_desc);
     787                 :            : 
     788                 :            :         /* Store start of fast path area */
     789                 :          0 :         eth_dev->data->rx_queues[qid] = rxq_sp + 1;
     790                 :          0 :         eth_dev->data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
     791                 :            : 
     792                 :            :         /* Calculating delta and freq mult between PTP HI clock and tsc.
     793                 :            :          * These are needed in deriving raw clock value from tsc counter.
     794                 :            :          * read_clock eth op returns raw clock value.
     795                 :            :          */
     796   [ #  #  #  # ]:          0 :         if ((dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) || dev->ptp_en) {
     797                 :          0 :                 rc = cnxk_nix_tsc_convert(dev);
     798         [ #  # ]:          0 :                 if (rc) {
     799                 :          0 :                         plt_err("Failed to calculate delta and freq mult");
     800                 :          0 :                         goto rq_fini;
     801                 :            :                 }
     802                 :            :         }
     803                 :            : 
     804                 :            :         return 0;
     805                 :            : free_mem:
     806                 :          0 :         plt_free(rxq_sp);
     807                 :          0 : rq_fini:
     808                 :          0 :         rc |= roc_nix_rq_fini(rq);
     809                 :          0 : cq_fini:
     810                 :          0 :         rc |= roc_nix_cq_fini(cq);
     811                 :            : fail:
     812                 :            :         return rc;
     813                 :            : }
     814                 :            : 
     815                 :            : static void
     816                 :          0 : cnxk_nix_rx_queue_release(struct rte_eth_dev *eth_dev, uint16_t qid)
     817                 :            : {
     818                 :          0 :         void *rxq = eth_dev->data->rx_queues[qid];
     819                 :            :         struct cnxk_eth_rxq_sp *rxq_sp;
     820                 :            :         struct cnxk_eth_dev *dev;
     821                 :            :         struct roc_nix_rq *rq;
     822                 :            :         struct roc_nix_cq *cq;
     823                 :            :         int rc;
     824                 :            : 
     825         [ #  # ]:          0 :         if (!rxq)
     826                 :            :                 return;
     827                 :            : 
     828                 :            :         rxq_sp = cnxk_eth_rxq_to_sp(rxq);
     829                 :          0 :         dev = rxq_sp->dev;
     830                 :          0 :         rq = &dev->rqs[qid];
     831                 :            : 
     832                 :          0 :         plt_nix_dbg("Releasing rxq %u", qid);
     833                 :            : 
     834                 :            :         /* Release rq reference for inline dev if present */
     835         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
     836                 :          0 :                 roc_nix_inl_dev_rq_put(rq);
     837                 :            : 
     838                 :            :         /* Cleanup ROC RQ */
     839                 :          0 :         rc = roc_nix_rq_fini(rq);
     840         [ #  # ]:          0 :         if (rc)
     841                 :          0 :                 plt_err("Failed to cleanup rq, rc=%d", rc);
     842                 :            : 
     843                 :            :         /* Cleanup ROC CQ */
     844                 :          0 :         cq = &dev->cqs[qid];
     845                 :          0 :         rc = roc_nix_cq_fini(cq);
     846         [ #  # ]:          0 :         if (rc)
     847                 :          0 :                 plt_err("Failed to cleanup cq, rc=%d", rc);
     848                 :            : 
     849                 :            :         /* Finally free fast path area */
     850                 :          0 :         plt_free(rxq_sp);
     851                 :            : }
     852                 :            : 
     853                 :            : uint32_t
     854                 :          0 : cnxk_rss_ethdev_to_nix(struct cnxk_eth_dev *dev, uint64_t ethdev_rss,
     855                 :            :                        uint8_t rss_level)
     856                 :            : {
     857                 :          0 :         uint32_t flow_key_type[RSS_MAX_LEVELS][6] = {
     858                 :            :                 {FLOW_KEY_TYPE_IPV4, FLOW_KEY_TYPE_IPV6, FLOW_KEY_TYPE_TCP,
     859                 :            :                  FLOW_KEY_TYPE_UDP, FLOW_KEY_TYPE_SCTP, FLOW_KEY_TYPE_ETH_DMAC},
     860                 :            :                 {FLOW_KEY_TYPE_INNR_IPV4, FLOW_KEY_TYPE_INNR_IPV6,
     861                 :            :                  FLOW_KEY_TYPE_INNR_TCP, FLOW_KEY_TYPE_INNR_UDP,
     862                 :            :                  FLOW_KEY_TYPE_INNR_SCTP, FLOW_KEY_TYPE_INNR_ETH_DMAC},
     863                 :            :                 {FLOW_KEY_TYPE_IPV4 | FLOW_KEY_TYPE_INNR_IPV4,
     864                 :            :                  FLOW_KEY_TYPE_IPV6 | FLOW_KEY_TYPE_INNR_IPV6,
     865                 :            :                  FLOW_KEY_TYPE_TCP | FLOW_KEY_TYPE_INNR_TCP,
     866                 :            :                  FLOW_KEY_TYPE_UDP | FLOW_KEY_TYPE_INNR_UDP,
     867                 :            :                  FLOW_KEY_TYPE_SCTP | FLOW_KEY_TYPE_INNR_SCTP,
     868                 :            :                  FLOW_KEY_TYPE_ETH_DMAC | FLOW_KEY_TYPE_INNR_ETH_DMAC}
     869                 :            :         };
     870                 :            :         uint32_t flowkey_cfg = 0;
     871                 :            : 
     872                 :          0 :         dev->ethdev_rss_hf = ethdev_rss;
     873                 :            : 
     874         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_L2_PAYLOAD &&
     875         [ #  # ]:          0 :             dev->npc.switch_header_type == ROC_PRIV_FLAGS_LEN_90B) {
     876                 :            :                 flowkey_cfg |= FLOW_KEY_TYPE_CH_LEN_90B;
     877                 :            :         }
     878                 :            : 
     879         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_C_VLAN)
     880                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_VLAN;
     881                 :            : 
     882         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_L3_SRC_ONLY)
     883                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_L3_SRC;
     884                 :            : 
     885         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_L3_DST_ONLY)
     886                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_L3_DST;
     887                 :            : 
     888         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_L4_SRC_ONLY)
     889                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_L4_SRC;
     890                 :            : 
     891         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_L4_DST_ONLY)
     892                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_L4_DST;
     893                 :            : 
     894         [ #  # ]:          0 :         if (ethdev_rss & RSS_IPV4_ENABLE)
     895                 :          0 :                 flowkey_cfg |= flow_key_type[rss_level][RSS_IPV4_INDEX];
     896                 :            : 
     897         [ #  # ]:          0 :         if (ethdev_rss & RSS_IPV6_ENABLE)
     898                 :          0 :                 flowkey_cfg |= flow_key_type[rss_level][RSS_IPV6_INDEX];
     899                 :            : 
     900         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_TCP)
     901                 :          0 :                 flowkey_cfg |= flow_key_type[rss_level][RSS_TCP_INDEX];
     902                 :            : 
     903         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_UDP)
     904                 :          0 :                 flowkey_cfg |= flow_key_type[rss_level][RSS_UDP_INDEX];
     905                 :            : 
     906         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_SCTP)
     907                 :          0 :                 flowkey_cfg |= flow_key_type[rss_level][RSS_SCTP_INDEX];
     908                 :            : 
     909         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_L2_PAYLOAD)
     910                 :          0 :                 flowkey_cfg |= flow_key_type[rss_level][RSS_DMAC_INDEX];
     911                 :            : 
     912         [ #  # ]:          0 :         if (ethdev_rss & RSS_IPV6_EX_ENABLE)
     913                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_IPV6_EXT;
     914                 :            : 
     915         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_PORT)
     916                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_PORT;
     917                 :            : 
     918         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_NVGRE)
     919                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_NVGRE;
     920                 :            : 
     921         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_VXLAN)
     922                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_VXLAN;
     923                 :            : 
     924         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_GENEVE)
     925                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_GENEVE;
     926                 :            : 
     927         [ #  # ]:          0 :         if (ethdev_rss & RTE_ETH_RSS_GTPU)
     928                 :          0 :                 flowkey_cfg |= FLOW_KEY_TYPE_GTPU;
     929                 :            : 
     930                 :          0 :         return flowkey_cfg;
     931                 :            : }
     932                 :            : 
     933                 :            : static int
     934                 :          0 : nix_rxchan_cfg_disable(struct cnxk_eth_dev *dev)
     935                 :            : {
     936                 :          0 :         struct roc_nix *nix = &dev->nix;
     937                 :            :         struct roc_nix_fc_cfg fc_cfg;
     938                 :            :         int rc;
     939                 :            : 
     940         [ #  # ]:          0 :         if (!roc_nix_is_lbk(nix))
     941                 :            :                 return 0;
     942                 :            : 
     943                 :            :         memset(&fc_cfg, 0, sizeof(struct roc_nix_fc_cfg));
     944                 :            :         fc_cfg.type = ROC_NIX_FC_RXCHAN_CFG;
     945                 :            :         fc_cfg.rxchan_cfg.enable = false;
     946                 :          0 :         rc = roc_nix_fc_config_set(nix, &fc_cfg);
     947         [ #  # ]:          0 :         if (rc) {
     948                 :          0 :                 plt_err("Failed to setup flow control, rc=%d(%s)", rc, roc_error_msg_get(rc));
     949                 :          0 :                 return rc;
     950                 :            :         }
     951                 :            :         return 0;
     952                 :            : }
     953                 :            : 
     954                 :            : static void
     955                 :          0 : nix_free_queue_mem(struct cnxk_eth_dev *dev)
     956                 :            : {
     957                 :          0 :         plt_free(dev->rqs);
     958                 :          0 :         plt_free(dev->cqs);
     959                 :          0 :         plt_free(dev->sqs);
     960                 :          0 :         dev->rqs = NULL;
     961                 :          0 :         dev->cqs = NULL;
     962                 :          0 :         dev->sqs = NULL;
     963                 :          0 : }
     964                 :            : 
     965                 :            : static int
     966                 :          0 : nix_ingress_policer_setup(struct cnxk_eth_dev *dev)
     967                 :            : {
     968                 :          0 :         struct rte_eth_dev *eth_dev = dev->eth_dev;
     969                 :            :         int rc = 0;
     970                 :            : 
     971                 :          0 :         TAILQ_INIT(&dev->mtr_profiles);
     972                 :          0 :         TAILQ_INIT(&dev->mtr_policy);
     973                 :          0 :         TAILQ_INIT(&dev->mtr);
     974                 :            : 
     975         [ #  # ]:          0 :         if (eth_dev->dev_ops->mtr_ops_get == NULL)
     976                 :            :                 return rc;
     977                 :            : 
     978                 :          0 :         return nix_mtr_capabilities_init(eth_dev);
     979                 :            : }
     980                 :            : 
     981                 :            : static int
     982                 :          0 : nix_rss_default_setup(struct cnxk_eth_dev *dev)
     983                 :            : {
     984                 :          0 :         struct rte_eth_dev *eth_dev = dev->eth_dev;
     985                 :            :         uint8_t rss_hash_level;
     986                 :            :         uint32_t flowkey_cfg;
     987                 :            :         uint64_t rss_hf;
     988                 :            : 
     989                 :          0 :         rss_hf = eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf;
     990                 :          0 :         rss_hash_level = RTE_ETH_RSS_LEVEL(rss_hf);
     991         [ #  # ]:          0 :         if (rss_hash_level)
     992                 :          0 :                 rss_hash_level -= 1;
     993                 :            : 
     994                 :          0 :         flowkey_cfg = cnxk_rss_ethdev_to_nix(dev, rss_hf, rss_hash_level);
     995                 :          0 :         return roc_nix_rss_default_setup(&dev->nix, flowkey_cfg);
     996                 :            : }
     997                 :            : 
     998                 :            : static int
     999         [ #  # ]:          0 : nix_store_queue_cfg_and_then_release(struct rte_eth_dev *eth_dev)
    1000                 :            : {
    1001                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1002                 :          0 :         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
    1003                 :            :         struct cnxk_eth_qconf *tx_qconf = NULL;
    1004                 :            :         struct cnxk_eth_qconf *rx_qconf = NULL;
    1005                 :            :         struct cnxk_eth_rxq_sp *rxq_sp;
    1006                 :            :         struct cnxk_eth_txq_sp *txq_sp;
    1007                 :            :         int i, nb_rxq, nb_txq;
    1008                 :            :         void **txq, **rxq;
    1009                 :            : 
    1010                 :          0 :         nb_rxq = RTE_MIN(dev->nb_rxq, eth_dev->data->nb_rx_queues);
    1011                 :          0 :         nb_txq = RTE_MIN(dev->nb_txq, eth_dev->data->nb_tx_queues);
    1012                 :            : 
    1013                 :          0 :         tx_qconf = malloc(nb_txq * sizeof(*tx_qconf));
    1014         [ #  # ]:          0 :         if (tx_qconf == NULL) {
    1015                 :          0 :                 plt_err("Failed to allocate memory for tx_qconf");
    1016                 :          0 :                 goto fail;
    1017                 :            :         }
    1018                 :            : 
    1019                 :          0 :         rx_qconf = malloc(nb_rxq * sizeof(*rx_qconf));
    1020         [ #  # ]:          0 :         if (rx_qconf == NULL) {
    1021                 :          0 :                 plt_err("Failed to allocate memory for rx_qconf");
    1022                 :          0 :                 goto fail;
    1023                 :            :         }
    1024                 :            : 
    1025                 :          0 :         txq = eth_dev->data->tx_queues;
    1026         [ #  # ]:          0 :         for (i = 0; i < nb_txq; i++) {
    1027         [ #  # ]:          0 :                 if (txq[i] == NULL) {
    1028                 :          0 :                         tx_qconf[i].valid = false;
    1029                 :          0 :                         plt_info("txq[%d] is already released", i);
    1030                 :          0 :                         continue;
    1031                 :            :                 }
    1032                 :            :                 txq_sp = cnxk_eth_txq_to_sp(txq[i]);
    1033                 :          0 :                 memcpy(&tx_qconf[i], &txq_sp->qconf, sizeof(*tx_qconf));
    1034                 :          0 :                 tx_qconf[i].valid = true;
    1035                 :          0 :                 dev_ops->tx_queue_release(eth_dev, i);
    1036                 :          0 :                 eth_dev->data->tx_queues[i] = NULL;
    1037                 :            :         }
    1038                 :            : 
    1039                 :          0 :         rxq = eth_dev->data->rx_queues;
    1040         [ #  # ]:          0 :         for (i = 0; i < nb_rxq; i++) {
    1041         [ #  # ]:          0 :                 if (rxq[i] == NULL) {
    1042                 :          0 :                         rx_qconf[i].valid = false;
    1043                 :          0 :                         plt_info("rxq[%d] is already released", i);
    1044                 :          0 :                         continue;
    1045                 :            :                 }
    1046                 :            :                 rxq_sp = cnxk_eth_rxq_to_sp(rxq[i]);
    1047                 :          0 :                 memcpy(&rx_qconf[i], &rxq_sp->qconf, sizeof(*rx_qconf));
    1048                 :          0 :                 rx_qconf[i].valid = true;
    1049                 :          0 :                 dev_ops->rx_queue_release(eth_dev, i);
    1050                 :          0 :                 eth_dev->data->rx_queues[i] = NULL;
    1051                 :            :         }
    1052                 :            : 
    1053                 :          0 :         dev->tx_qconf = tx_qconf;
    1054                 :          0 :         dev->rx_qconf = rx_qconf;
    1055                 :          0 :         return 0;
    1056                 :            : 
    1057                 :          0 : fail:
    1058                 :          0 :         free(tx_qconf);
    1059                 :            :         free(rx_qconf);
    1060                 :          0 :         return -ENOMEM;
    1061                 :            : }
    1062                 :            : 
    1063                 :            : static int
    1064                 :          0 : nix_restore_queue_cfg(struct rte_eth_dev *eth_dev)
    1065                 :            : {
    1066                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1067                 :          0 :         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
    1068                 :          0 :         struct cnxk_eth_qconf *tx_qconf = dev->tx_qconf;
    1069                 :          0 :         struct cnxk_eth_qconf *rx_qconf = dev->rx_qconf;
    1070                 :            :         int rc, i, nb_rxq, nb_txq;
    1071                 :            : 
    1072                 :          0 :         nb_rxq = RTE_MIN(dev->nb_rxq, eth_dev->data->nb_rx_queues);
    1073                 :          0 :         nb_txq = RTE_MIN(dev->nb_txq, eth_dev->data->nb_tx_queues);
    1074                 :            : 
    1075                 :            :         rc = -ENOMEM;
    1076                 :            :         /* Setup tx & rx queues with previous configuration so
    1077                 :            :          * that the queues can be functional in cases like ports
    1078                 :            :          * are started without re configuring queues.
    1079                 :            :          *
    1080                 :            :          * Usual re config sequence is like below:
    1081                 :            :          * port_configure() {
    1082                 :            :          *      if(reconfigure) {
    1083                 :            :          *              queue_release()
    1084                 :            :          *              queue_setup()
    1085                 :            :          *      }
    1086                 :            :          *      queue_configure() {
    1087                 :            :          *              queue_release()
    1088                 :            :          *              queue_setup()
    1089                 :            :          *      }
    1090                 :            :          * }
    1091                 :            :          * port_start()
    1092                 :            :          *
    1093                 :            :          * In some application's control path, queue_configure() would
    1094                 :            :          * NOT be invoked for TXQs/RXQs in port_configure().
    1095                 :            :          * In such cases, queues can be functional after start as the
    1096                 :            :          * queues are already setup in port_configure().
    1097                 :            :          */
    1098         [ #  # ]:          0 :         for (i = 0; i < nb_txq; i++) {
    1099         [ #  # ]:          0 :                 if (!tx_qconf[i].valid)
    1100                 :          0 :                         continue;
    1101                 :          0 :                 rc = dev_ops->tx_queue_setup(eth_dev, i, tx_qconf[i].nb_desc, 0,
    1102                 :          0 :                                              &tx_qconf[i].conf.tx);
    1103         [ #  # ]:          0 :                 if (rc) {
    1104                 :          0 :                         plt_err("Failed to setup tx queue rc=%d", rc);
    1105         [ #  # ]:          0 :                         for (i -= 1; i >= 0; i--)
    1106                 :          0 :                                 dev_ops->tx_queue_release(eth_dev, i);
    1107                 :          0 :                         goto fail;
    1108                 :            :                 }
    1109                 :            :         }
    1110                 :            : 
    1111                 :          0 :         free(tx_qconf);
    1112                 :            :         tx_qconf = NULL;
    1113                 :            : 
    1114         [ #  # ]:          0 :         for (i = 0; i < nb_rxq; i++) {
    1115         [ #  # ]:          0 :                 if (!rx_qconf[i].valid)
    1116                 :          0 :                         continue;
    1117                 :          0 :                 rc = dev_ops->rx_queue_setup(eth_dev, i, rx_qconf[i].nb_desc, 0,
    1118                 :          0 :                                              &rx_qconf[i].conf.rx,
    1119                 :            :                                              rx_qconf[i].mp);
    1120         [ #  # ]:          0 :                 if (rc) {
    1121                 :          0 :                         plt_err("Failed to setup rx queue rc=%d", rc);
    1122         [ #  # ]:          0 :                         for (i -= 1; i >= 0; i--)
    1123                 :          0 :                                 dev_ops->rx_queue_release(eth_dev, i);
    1124                 :          0 :                         goto tx_queue_release;
    1125                 :            :                 }
    1126                 :            :         }
    1127                 :            : 
    1128                 :          0 :         free(rx_qconf);
    1129                 :            :         rx_qconf = NULL;
    1130                 :            : 
    1131                 :          0 :         return 0;
    1132                 :            : 
    1133                 :            : tx_queue_release:
    1134         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
    1135                 :          0 :                 dev_ops->tx_queue_release(eth_dev, i);
    1136                 :          0 : fail:
    1137                 :          0 :         free(tx_qconf);
    1138                 :          0 :         free(rx_qconf);
    1139                 :            : 
    1140                 :          0 :         return rc;
    1141                 :            : }
    1142                 :            : 
    1143                 :            : static void
    1144                 :            : nix_set_nop_rxtx_function(struct rte_eth_dev *eth_dev)
    1145                 :            : {
    1146                 :            :         /* These dummy functions are required for supporting
    1147                 :            :          * some applications which reconfigure queues without
    1148                 :            :          * stopping tx burst and rx burst threads.
    1149                 :            :          * When the queues context is saved, txq/rxqs are released
    1150                 :            :          * which caused app crash since rx/tx burst is still
    1151                 :            :          * on different lcores
    1152                 :            :          */
    1153                 :          0 :         eth_dev->tx_pkt_burst = rte_eth_pkt_burst_dummy;
    1154                 :          0 :         eth_dev->rx_pkt_burst = rte_eth_pkt_burst_dummy;
    1155                 :            :         rte_mb();
    1156                 :            : }
    1157                 :            : 
    1158                 :            : static int
    1159                 :          0 : nix_lso_tun_fmt_update(struct cnxk_eth_dev *dev)
    1160                 :            : {
    1161                 :            :         uint8_t udp_tun[ROC_NIX_LSO_TUN_MAX];
    1162                 :            :         uint8_t tun[ROC_NIX_LSO_TUN_MAX];
    1163                 :          0 :         struct roc_nix *nix = &dev->nix;
    1164                 :            :         int rc;
    1165                 :            : 
    1166                 :          0 :         rc = roc_nix_lso_fmt_get(nix, udp_tun, tun);
    1167         [ #  # ]:          0 :         if (rc)
    1168                 :            :                 return rc;
    1169                 :            : 
    1170                 :          0 :         dev->lso_tun_fmt = ((uint64_t)tun[ROC_NIX_LSO_TUN_V4V4] |
    1171                 :          0 :                             (uint64_t)tun[ROC_NIX_LSO_TUN_V4V6] << 8 |
    1172                 :          0 :                             (uint64_t)tun[ROC_NIX_LSO_TUN_V6V4] << 16 |
    1173                 :          0 :                             (uint64_t)tun[ROC_NIX_LSO_TUN_V6V6] << 24);
    1174                 :            : 
    1175                 :          0 :         dev->lso_tun_fmt |= ((uint64_t)udp_tun[ROC_NIX_LSO_TUN_V4V4] << 32 |
    1176                 :          0 :                              (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V4V6] << 40 |
    1177                 :          0 :                              (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V6V4] << 48 |
    1178                 :          0 :                              (uint64_t)udp_tun[ROC_NIX_LSO_TUN_V6V6] << 56);
    1179                 :          0 :         return 0;
    1180                 :            : }
    1181                 :            : 
    1182                 :            : static int
    1183                 :          0 : nix_lso_fmt_setup(struct cnxk_eth_dev *dev)
    1184                 :            : {
    1185                 :          0 :         struct roc_nix *nix = &dev->nix;
    1186                 :            :         int rc;
    1187                 :            : 
    1188                 :            :         /* Nothing much to do if offload is not enabled */
    1189         [ #  # ]:          0 :         if (!(dev->tx_offloads &
    1190                 :            :               (RTE_ETH_TX_OFFLOAD_TCP_TSO | RTE_ETH_TX_OFFLOAD_VXLAN_TNL_TSO |
    1191                 :            :                RTE_ETH_TX_OFFLOAD_GENEVE_TNL_TSO | RTE_ETH_TX_OFFLOAD_GRE_TNL_TSO)))
    1192                 :            :                 return 0;
    1193                 :            : 
    1194                 :            :         /* Setup LSO formats in AF. Its a no-op if other ethdev has
    1195                 :            :          * already set it up
    1196                 :            :          */
    1197                 :          0 :         rc = roc_nix_lso_fmt_setup(nix);
    1198         [ #  # ]:          0 :         if (rc)
    1199                 :            :                 return rc;
    1200                 :            : 
    1201                 :          0 :         return nix_lso_tun_fmt_update(dev);
    1202                 :            : }
    1203                 :            : 
    1204                 :            : int
    1205                 :          0 : cnxk_nix_configure(struct rte_eth_dev *eth_dev)
    1206                 :            : {
    1207                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1208                 :            :         struct rte_eth_dev_data *data = eth_dev->data;
    1209                 :            :         struct rte_eth_conf *conf = &data->dev_conf;
    1210                 :            :         struct rte_eth_rxmode *rxmode = &conf->rxmode;
    1211                 :            :         struct rte_eth_txmode *txmode = &conf->txmode;
    1212                 :            :         char ea_fmt[RTE_ETHER_ADDR_FMT_SIZE];
    1213                 :          0 :         struct roc_nix_fc_cfg fc_cfg = {0};
    1214                 :          0 :         struct roc_nix *nix = &dev->nix;
    1215                 :            :         uint16_t nb_rxq, nb_txq, nb_cq;
    1216                 :            :         struct rte_ether_addr *ea;
    1217                 :            :         uint64_t rx_cfg;
    1218                 :            :         void *qs;
    1219                 :            :         int rc;
    1220                 :            : 
    1221                 :            :         rc = -EINVAL;
    1222                 :            : 
    1223                 :            :         /* Sanity checks */
    1224         [ #  # ]:          0 :         if (rte_eal_has_hugepages() == 0) {
    1225                 :          0 :                 plt_err("Huge page is not configured");
    1226                 :          0 :                 goto fail_configure;
    1227                 :            :         }
    1228                 :            : 
    1229         [ #  # ]:          0 :         if (conf->dcb_capability_en == 1) {
    1230                 :          0 :                 plt_err("dcb enable is not supported");
    1231                 :          0 :                 goto fail_configure;
    1232                 :            :         }
    1233                 :            : 
    1234         [ #  # ]:          0 :         if (rxmode->mq_mode != RTE_ETH_MQ_RX_NONE &&
    1235                 :            :             rxmode->mq_mode != RTE_ETH_MQ_RX_RSS) {
    1236                 :          0 :                 plt_err("Unsupported mq rx mode %d", rxmode->mq_mode);
    1237                 :          0 :                 goto fail_configure;
    1238                 :            :         }
    1239                 :            : 
    1240         [ #  # ]:          0 :         if (txmode->mq_mode != RTE_ETH_MQ_TX_NONE) {
    1241                 :          0 :                 plt_err("Unsupported mq tx mode %d", txmode->mq_mode);
    1242                 :          0 :                 goto fail_configure;
    1243                 :            :         }
    1244                 :            : 
    1245                 :            :         /* Free the resources allocated from the previous configure */
    1246         [ #  # ]:          0 :         if (dev->configured == 1) {
    1247                 :            :                 /* Unregister queue irq's */
    1248                 :          0 :                 roc_nix_unregister_queue_irqs(nix);
    1249                 :            : 
    1250                 :            :                 /* Unregister CQ irqs if present */
    1251         [ #  # ]:          0 :                 if (eth_dev->data->dev_conf.intr_conf.rxq)
    1252                 :          0 :                         roc_nix_unregister_cq_irqs(nix);
    1253                 :            : 
    1254                 :            :                 /* Set no-op functions */
    1255                 :            :                 nix_set_nop_rxtx_function(eth_dev);
    1256                 :            :                 /* Store queue config for later */
    1257                 :          0 :                 rc = nix_store_queue_cfg_and_then_release(eth_dev);
    1258         [ #  # ]:          0 :                 if (rc)
    1259                 :          0 :                         goto fail_configure;
    1260                 :            : 
    1261                 :            :                 /* Disable and free rte_meter entries */
    1262                 :          0 :                 rc = nix_meter_fini(dev);
    1263         [ #  # ]:          0 :                 if (rc)
    1264                 :          0 :                         goto fail_configure;
    1265                 :            : 
    1266                 :            :                 /* Cleanup security support */
    1267                 :          0 :                 rc = nix_security_release(dev);
    1268         [ #  # ]:          0 :                 if (rc)
    1269                 :          0 :                         goto fail_configure;
    1270                 :            : 
    1271                 :          0 :                 roc_nix_tm_fini(nix);
    1272                 :          0 :                 nix_rxchan_cfg_disable(dev);
    1273                 :          0 :                 roc_nix_lf_free(nix);
    1274                 :            :         }
    1275                 :            : 
    1276                 :          0 :         dev->rx_offloads = rxmode->offloads;
    1277                 :          0 :         dev->tx_offloads = txmode->offloads;
    1278                 :            : 
    1279         [ #  # ]:          0 :         if (nix->custom_inb_sa)
    1280                 :          0 :                 dev->rx_offloads |= RTE_ETH_RX_OFFLOAD_SECURITY;
    1281                 :            : 
    1282                 :            :         /* Prepare rx cfg */
    1283                 :            :         rx_cfg = ROC_NIX_LF_RX_CFG_DIS_APAD;
    1284         [ #  # ]:          0 :         if (dev->rx_offloads &
    1285                 :            :             (RTE_ETH_RX_OFFLOAD_TCP_CKSUM | RTE_ETH_RX_OFFLOAD_UDP_CKSUM)) {
    1286                 :            :                 rx_cfg |= ROC_NIX_LF_RX_CFG_CSUM_OL4;
    1287                 :            :                 rx_cfg |= ROC_NIX_LF_RX_CFG_CSUM_IL4;
    1288                 :            :         }
    1289         [ #  # ]:          0 :         rx_cfg |= (ROC_NIX_LF_RX_CFG_DROP_RE | ROC_NIX_LF_RX_CFG_L2_LEN_ERR |
    1290                 :            :                    ROC_NIX_LF_RX_CFG_LEN_IL4 | ROC_NIX_LF_RX_CFG_LEN_IL3 |
    1291                 :            :                    ROC_NIX_LF_RX_CFG_LEN_OL4 | ROC_NIX_LF_RX_CFG_LEN_OL3);
    1292                 :            : 
    1293                 :            :         rx_cfg &= (ROC_NIX_LF_RX_CFG_RX_ERROR_MASK);
    1294                 :            : 
    1295         [ #  # ]:          0 :         if (roc_feature_nix_has_drop_re_mask())
    1296                 :          0 :                 rx_cfg |= (ROC_NIX_RE_CRC8_PCH | ROC_NIX_RE_MACSEC);
    1297                 :            : 
    1298         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
    1299                 :          0 :                 rx_cfg |= ROC_NIX_LF_RX_CFG_IP6_UDP_OPT;
    1300                 :            :                 /* Disable drop re if rx offload security is enabled and
    1301                 :            :                  * platform does not support it.
    1302                 :            :                  */
    1303         [ #  # ]:          0 :                 if (dev->ipsecd_drop_re_dis)
    1304                 :          0 :                         rx_cfg &= ~(ROC_NIX_LF_RX_CFG_DROP_RE);
    1305                 :            :         }
    1306                 :            : 
    1307                 :          0 :         nb_rxq = RTE_MAX(data->nb_rx_queues, 1);
    1308                 :          0 :         nb_txq = RTE_MAX(data->nb_tx_queues, 1);
    1309                 :            : 
    1310         [ #  # ]:          0 :         if (roc_nix_is_lbk(nix))
    1311                 :          0 :                 nix->enable_loop = eth_dev->data->dev_conf.lpbk_mode;
    1312                 :            : 
    1313                 :          0 :         nix->tx_compl_ena = dev->tx_compl_ena;
    1314                 :            : 
    1315                 :            :         /* Alloc a nix lf */
    1316                 :          0 :         rc = roc_nix_lf_alloc(nix, nb_rxq, nb_txq, rx_cfg);
    1317         [ #  # ]:          0 :         if (rc) {
    1318                 :          0 :                 plt_err("Failed to init nix_lf rc=%d", rc);
    1319                 :          0 :                 goto fail_configure;
    1320                 :            :         }
    1321                 :            : 
    1322         [ #  # ]:          0 :         if (!roc_nix_is_vf_or_sdp(nix)) {
    1323                 :            :                 /* Sync same MAC address to CGX/RPM table */
    1324                 :          0 :                 rc = roc_nix_mac_addr_set(nix, dev->mac_addr);
    1325         [ #  # ]:          0 :                 if (rc) {
    1326                 :          0 :                         plt_err("Failed to set mac addr, rc=%d", rc);
    1327                 :          0 :                         goto fail_configure;
    1328                 :            :                 }
    1329                 :            :         }
    1330                 :            : 
    1331                 :            :         /* Check if ptp is enable in PF owning this VF*/
    1332   [ #  #  #  # ]:          0 :         if (!roc_nix_is_pf(nix) && (!roc_nix_is_sdp(nix)))
    1333                 :          0 :                 dev->ptp_en = roc_nix_ptp_is_enable(nix);
    1334                 :            : 
    1335                 :          0 :         dev->npc.channel = roc_nix_get_base_chan(nix);
    1336                 :            : 
    1337                 :          0 :         nb_rxq = data->nb_rx_queues;
    1338                 :          0 :         nb_txq = data->nb_tx_queues;
    1339                 :            :         nb_cq = nb_rxq;
    1340         [ #  # ]:          0 :         if (nix->tx_compl_ena)
    1341                 :          0 :                 nb_cq += nb_txq;
    1342                 :            :         rc = -ENOMEM;
    1343         [ #  # ]:          0 :         if (nb_rxq) {
    1344                 :            :                 /* Allocate memory for roc rq's and cq's */
    1345                 :          0 :                 qs = plt_zmalloc(sizeof(struct roc_nix_rq) * nb_rxq, 0);
    1346         [ #  # ]:          0 :                 if (!qs) {
    1347                 :          0 :                         plt_err("Failed to alloc rqs");
    1348                 :          0 :                         goto free_nix_lf;
    1349                 :            :                 }
    1350                 :          0 :                 dev->rqs = qs;
    1351                 :            :         }
    1352                 :            : 
    1353         [ #  # ]:          0 :         if (nb_txq) {
    1354                 :            :                 /* Allocate memory for roc sq's */
    1355                 :          0 :                 qs = plt_zmalloc(sizeof(struct roc_nix_sq) * nb_txq, 0);
    1356         [ #  # ]:          0 :                 if (!qs) {
    1357                 :          0 :                         plt_err("Failed to alloc sqs");
    1358                 :          0 :                         goto free_nix_lf;
    1359                 :            :                 }
    1360                 :          0 :                 dev->sqs = qs;
    1361                 :            :         }
    1362                 :            : 
    1363         [ #  # ]:          0 :         if (nb_cq) {
    1364                 :          0 :                 qs = plt_zmalloc(sizeof(struct roc_nix_cq) * nb_cq, 0);
    1365         [ #  # ]:          0 :                 if (!qs) {
    1366                 :          0 :                         plt_err("Failed to alloc cqs");
    1367                 :          0 :                         goto free_nix_lf;
    1368                 :            :                 }
    1369                 :          0 :                 dev->cqs = qs;
    1370                 :            :         }
    1371                 :            : 
    1372                 :            :         /* Re-enable NIX LF error interrupts */
    1373                 :          0 :         roc_nix_err_intr_ena_dis(nix, true);
    1374                 :          0 :         roc_nix_ras_intr_ena_dis(nix, true);
    1375                 :            : 
    1376         [ #  # ]:          0 :         if (nix->rx_ptp_ena &&
    1377         [ #  # ]:          0 :             dev->npc.switch_header_type == ROC_PRIV_FLAGS_HIGIG) {
    1378                 :          0 :                 plt_err("Both PTP and switch header enabled");
    1379                 :          0 :                 goto free_nix_lf;
    1380                 :            :         }
    1381                 :            : 
    1382                 :          0 :         rc = roc_nix_switch_hdr_set(nix, dev->npc.switch_header_type,
    1383                 :          0 :                                     dev->npc.pre_l2_size_offset,
    1384                 :          0 :                                     dev->npc.pre_l2_size_offset_mask,
    1385                 :          0 :                                     dev->npc.pre_l2_size_shift_dir);
    1386         [ #  # ]:          0 :         if (rc) {
    1387                 :          0 :                 plt_err("Failed to enable switch type nix_lf rc=%d", rc);
    1388                 :          0 :                 goto free_nix_lf;
    1389                 :            :         }
    1390                 :            : 
    1391                 :            :         /* Setup LSO if needed */
    1392                 :          0 :         rc = nix_lso_fmt_setup(dev);
    1393         [ #  # ]:          0 :         if (rc) {
    1394                 :          0 :                 plt_err("Failed to setup nix lso format fields, rc=%d", rc);
    1395                 :          0 :                 goto free_nix_lf;
    1396                 :            :         }
    1397                 :            : 
    1398                 :            :         /* Configure RSS */
    1399                 :          0 :         rc = nix_rss_default_setup(dev);
    1400         [ #  # ]:          0 :         if (rc) {
    1401                 :          0 :                 plt_err("Failed to configure rss rc=%d", rc);
    1402                 :          0 :                 goto free_nix_lf;
    1403                 :            :         }
    1404                 :            : 
    1405                 :            :         /* Overwrite default RSS setup if requested by user */
    1406                 :          0 :         rc = cnxk_nix_rss_hash_update(eth_dev, &conf->rx_adv_conf.rss_conf);
    1407         [ #  # ]:          0 :         if (rc) {
    1408                 :          0 :                 plt_err("Failed to configure rss rc=%d", rc);
    1409                 :          0 :                 goto free_nix_lf;
    1410                 :            :         }
    1411                 :            : 
    1412                 :            :         /* Init the default TM scheduler hierarchy */
    1413                 :          0 :         rc = roc_nix_tm_init(nix);
    1414         [ #  # ]:          0 :         if (rc) {
    1415                 :          0 :                 plt_err("Failed to init traffic manager, rc=%d", rc);
    1416                 :          0 :                 goto free_nix_lf;
    1417                 :            :         }
    1418                 :            : 
    1419                 :          0 :         rc = nix_ingress_policer_setup(dev);
    1420         [ #  # ]:          0 :         if (rc) {
    1421                 :          0 :                 plt_err("Failed to setup ingress policer rc=%d", rc);
    1422                 :          0 :                 goto free_nix_lf;
    1423                 :            :         }
    1424                 :            : 
    1425                 :          0 :         rc = roc_nix_tm_hierarchy_enable(nix, ROC_NIX_TM_DEFAULT, false);
    1426         [ #  # ]:          0 :         if (rc) {
    1427                 :          0 :                 plt_err("Failed to enable default tm hierarchy, rc=%d", rc);
    1428                 :          0 :                 goto tm_fini;
    1429                 :            :         }
    1430                 :            : 
    1431                 :            :         /* Register queue IRQs */
    1432                 :          0 :         rc = roc_nix_register_queue_irqs(nix);
    1433         [ #  # ]:          0 :         if (rc) {
    1434                 :          0 :                 plt_err("Failed to register queue interrupts rc=%d", rc);
    1435                 :          0 :                 goto tm_fini;
    1436                 :            :         }
    1437                 :            : 
    1438                 :            :         /* Register cq IRQs */
    1439         [ #  # ]:          0 :         if (eth_dev->data->dev_conf.intr_conf.rxq) {
    1440         [ #  # ]:          0 :                 if (eth_dev->data->nb_rx_queues > dev->nix.cints) {
    1441                 :          0 :                         plt_err("Rx interrupt cannot be enabled, rxq > %d",
    1442                 :            :                                 dev->nix.cints);
    1443                 :          0 :                         goto q_irq_fini;
    1444                 :            :                 }
    1445                 :            :                 /* Rx interrupt feature cannot work with vector mode because,
    1446                 :            :                  * vector mode does not process packets unless min 4 pkts are
    1447                 :            :                  * received, while cq interrupts are generated even for 1 pkt
    1448                 :            :                  * in the CQ.
    1449                 :            :                  */
    1450                 :          0 :                 dev->scalar_ena = true;
    1451                 :            : 
    1452                 :          0 :                 rc = roc_nix_register_cq_irqs(nix);
    1453         [ #  # ]:          0 :                 if (rc) {
    1454                 :          0 :                         plt_err("Failed to register CQ interrupts rc=%d", rc);
    1455                 :          0 :                         goto q_irq_fini;
    1456                 :            :                 }
    1457                 :            :         }
    1458                 :            : 
    1459         [ #  # ]:          0 :         if (roc_nix_is_lbk(nix))
    1460                 :          0 :                 goto skip_lbk_setup;
    1461                 :            : 
    1462                 :            :         /* Configure loop back mode */
    1463                 :          0 :         rc = roc_nix_mac_loopback_enable(nix,
    1464                 :          0 :                                          eth_dev->data->dev_conf.lpbk_mode);
    1465         [ #  # ]:          0 :         if (rc) {
    1466                 :          0 :                 plt_err("Failed to configure cgx loop back mode rc=%d", rc);
    1467                 :          0 :                 goto cq_fini;
    1468                 :            :         }
    1469                 :            : 
    1470                 :          0 : skip_lbk_setup:
    1471                 :            :         /* Setup Inline security support */
    1472                 :          0 :         rc = nix_security_setup(dev);
    1473         [ #  # ]:          0 :         if (rc)
    1474                 :          0 :                 goto cq_fini;
    1475                 :            : 
    1476                 :            :         /* Init flow control configuration */
    1477         [ #  # ]:          0 :         if (!roc_nix_is_esw(nix)) {
    1478                 :          0 :                 fc_cfg.type = ROC_NIX_FC_RXCHAN_CFG;
    1479                 :          0 :                 fc_cfg.rxchan_cfg.enable = true;
    1480                 :          0 :                 rc = roc_nix_fc_config_set(nix, &fc_cfg);
    1481         [ #  # ]:          0 :                 if (rc) {
    1482                 :          0 :                         plt_err("Failed to initialize flow control rc=%d", rc);
    1483                 :          0 :                         goto cq_fini;
    1484                 :            :                 }
    1485                 :            :         }
    1486                 :            : 
    1487                 :            :         /* Update flow control configuration to PMD */
    1488                 :          0 :         rc = nix_init_flow_ctrl_config(eth_dev);
    1489         [ #  # ]:          0 :         if (rc) {
    1490                 :          0 :                 plt_err("Failed to initialize flow control rc=%d", rc);
    1491                 :          0 :                 goto cq_fini;
    1492                 :            :         }
    1493                 :            : 
    1494                 :            :         /*
    1495                 :            :          * Restore queue config when reconfigure followed by
    1496                 :            :          * reconfigure and no queue configure invoked from application case.
    1497                 :            :          */
    1498         [ #  # ]:          0 :         if (dev->configured == 1) {
    1499                 :          0 :                 rc = nix_restore_queue_cfg(eth_dev);
    1500         [ #  # ]:          0 :                 if (rc)
    1501                 :          0 :                         goto sec_release;
    1502                 :            :         }
    1503                 :            : 
    1504                 :            :         /* Update the mac address */
    1505                 :          0 :         ea = eth_dev->data->mac_addrs;
    1506         [ #  # ]:          0 :         memcpy(ea, dev->mac_addr, RTE_ETHER_ADDR_LEN);
    1507         [ #  # ]:          0 :         if (rte_is_zero_ether_addr(ea))
    1508                 :          0 :                 rte_eth_random_addr((uint8_t *)ea);
    1509                 :            : 
    1510                 :          0 :         rte_ether_format_addr(ea_fmt, RTE_ETHER_ADDR_FMT_SIZE, ea);
    1511                 :            : 
    1512                 :          0 :         plt_nix_dbg("Configured port%d mac=%s nb_rxq=%d nb_txq=%d"
    1513                 :            :                     " rx_offloads=0x%" PRIx64 " tx_offloads=0x%" PRIx64 "",
    1514                 :            :                     eth_dev->data->port_id, ea_fmt, nb_rxq, nb_txq,
    1515                 :            :                     dev->rx_offloads, dev->tx_offloads);
    1516                 :            : 
    1517                 :            :         /* All good */
    1518                 :          0 :         dev->configured = 1;
    1519                 :          0 :         dev->nb_rxq = data->nb_rx_queues;
    1520                 :          0 :         dev->nb_txq = data->nb_tx_queues;
    1521                 :          0 :         return 0;
    1522                 :            : 
    1523                 :            : sec_release:
    1524                 :          0 :         rc |= nix_security_release(dev);
    1525                 :          0 : cq_fini:
    1526                 :          0 :         roc_nix_unregister_cq_irqs(nix);
    1527                 :          0 : q_irq_fini:
    1528                 :          0 :         roc_nix_unregister_queue_irqs(nix);
    1529                 :          0 : tm_fini:
    1530                 :          0 :         roc_nix_tm_fini(nix);
    1531                 :          0 : free_nix_lf:
    1532                 :          0 :         nix_free_queue_mem(dev);
    1533                 :          0 :         rc |= nix_rxchan_cfg_disable(dev);
    1534                 :          0 :         rc |= roc_nix_lf_free(nix);
    1535                 :          0 : fail_configure:
    1536                 :          0 :         dev->configured = 0;
    1537                 :          0 :         return rc;
    1538                 :            : }
    1539                 :            : 
    1540                 :            : int
    1541         [ #  # ]:          0 : cnxk_nix_tx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qid)
    1542                 :            : {
    1543                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1544                 :            :         struct rte_eth_dev_data *data = eth_dev->data;
    1545                 :          0 :         struct roc_nix_sq *sq = &dev->sqs[qid];
    1546                 :            :         int rc = -EINVAL;
    1547                 :            : 
    1548         [ #  # ]:          0 :         if (data->tx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STARTED)
    1549                 :            :                 return 0;
    1550                 :            : 
    1551                 :          0 :         rc = roc_nix_sq_ena_dis(sq, true);
    1552         [ #  # ]:          0 :         if (rc) {
    1553                 :          0 :                 plt_err("Failed to enable sq aura fc, txq=%u, rc=%d", qid, rc);
    1554                 :          0 :                 goto done;
    1555                 :            :         }
    1556                 :            : 
    1557                 :          0 :         data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STARTED;
    1558                 :            : done:
    1559                 :            :         return rc;
    1560                 :            : }
    1561                 :            : 
    1562                 :            : int
    1563         [ #  # ]:          0 : cnxk_nix_tx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qid)
    1564                 :            : {
    1565                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1566                 :            :         struct rte_eth_dev_data *data = eth_dev->data;
    1567                 :          0 :         struct roc_nix_sq *sq = &dev->sqs[qid];
    1568                 :            :         int rc;
    1569                 :            : 
    1570         [ #  # ]:          0 :         if (data->tx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STOPPED)
    1571                 :            :                 return 0;
    1572                 :            : 
    1573                 :          0 :         rc = roc_nix_sq_ena_dis(sq, false);
    1574         [ #  # ]:          0 :         if (rc) {
    1575                 :          0 :                 plt_err("Failed to disable sqb aura fc, txq=%u, rc=%d", qid,
    1576                 :            :                         rc);
    1577                 :          0 :                 goto done;
    1578                 :            :         }
    1579                 :            : 
    1580                 :          0 :         data->tx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
    1581                 :            : done:
    1582                 :            :         return rc;
    1583                 :            : }
    1584                 :            : 
    1585                 :            : static int
    1586         [ #  # ]:          0 : cnxk_nix_rx_queue_start(struct rte_eth_dev *eth_dev, uint16_t qid)
    1587                 :            : {
    1588                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1589                 :            :         struct rte_eth_dev_data *data = eth_dev->data;
    1590                 :          0 :         struct roc_nix_rq *rq = &dev->rqs[qid];
    1591                 :            :         int rc;
    1592                 :            : 
    1593         [ #  # ]:          0 :         if (data->rx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STARTED)
    1594                 :            :                 return 0;
    1595                 :            : 
    1596                 :          0 :         rc = roc_nix_rq_ena_dis(rq, true);
    1597         [ #  # ]:          0 :         if (rc) {
    1598                 :          0 :                 plt_err("Failed to enable rxq=%u, rc=%d", qid, rc);
    1599                 :          0 :                 goto done;
    1600                 :            :         }
    1601                 :            : 
    1602                 :          0 :         data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STARTED;
    1603                 :            : done:
    1604                 :            :         return rc;
    1605                 :            : }
    1606                 :            : 
    1607                 :            : static int
    1608         [ #  # ]:          0 : cnxk_nix_rx_queue_stop(struct rte_eth_dev *eth_dev, uint16_t qid)
    1609                 :            : {
    1610                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1611                 :            :         struct rte_eth_dev_data *data = eth_dev->data;
    1612                 :          0 :         struct roc_nix_rq *rq = &dev->rqs[qid];
    1613                 :            :         int rc;
    1614                 :            : 
    1615         [ #  # ]:          0 :         if (data->rx_queue_state[qid] == RTE_ETH_QUEUE_STATE_STOPPED)
    1616                 :            :                 return 0;
    1617                 :            : 
    1618                 :          0 :         rc = roc_nix_rq_ena_dis(rq, false);
    1619         [ #  # ]:          0 :         if (rc) {
    1620                 :          0 :                 plt_err("Failed to disable rxq=%u, rc=%d", qid, rc);
    1621                 :          0 :                 goto done;
    1622                 :            :         }
    1623                 :            : 
    1624                 :          0 :         data->rx_queue_state[qid] = RTE_ETH_QUEUE_STATE_STOPPED;
    1625                 :            : done:
    1626                 :            :         return rc;
    1627                 :            : }
    1628                 :            : 
    1629                 :            : static int
    1630         [ #  # ]:          0 : cnxk_nix_dev_stop(struct rte_eth_dev *eth_dev)
    1631                 :            : {
    1632                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1633                 :          0 :         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
    1634                 :            :         struct rte_mbuf *rx_pkts[32];
    1635                 :            :         struct rte_eth_link link;
    1636                 :            :         int count, i, j, rc;
    1637                 :            :         void *rxq;
    1638                 :            : 
    1639                 :            :         /* In case of Inline IPSec, will need to avoid disabling the MCAM rules and NPC Rx
    1640                 :            :          * in this routine to continue processing of second pass inflight packets if any.
    1641                 :            :          * Drop of second pass packets will leak first pass buffers on some platforms
    1642                 :            :          * due to hardware limitations.
    1643                 :            :          */
    1644                 :          0 :         if (roc_feature_nix_has_second_pass_drop() ||
    1645         [ #  # ]:          0 :             !(dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)) {
    1646                 :            :                 /* Disable all the NPC entries */
    1647                 :          0 :                 rc = roc_npc_mcam_enable_all_entries(&dev->npc, 0);
    1648         [ #  # ]:          0 :                 if (rc)
    1649                 :            :                         return rc;
    1650                 :            : 
    1651                 :            :                 /* Disable Rx via NPC */
    1652                 :          0 :                 roc_nix_npc_rx_ena_dis(&dev->nix, false);
    1653                 :            :         }
    1654                 :            : 
    1655                 :            :         /* Stop link change events */
    1656         [ #  # ]:          0 :         if (!roc_nix_is_vf_or_sdp(&dev->nix))
    1657                 :          0 :                 roc_nix_mac_link_event_start_stop(&dev->nix, false);
    1658                 :            : 
    1659                 :          0 :         roc_nix_inl_outb_soft_exp_poll_switch(&dev->nix, false);
    1660                 :            : 
    1661                 :            :         /* Stop inline device RQ first */
    1662         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY)
    1663                 :          0 :                 roc_nix_inl_rq_ena_dis(&dev->nix, false);
    1664                 :            : 
    1665                 :            :         /* Stop rx queues and free up pkts pending */
    1666         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
    1667                 :          0 :                 rc = dev_ops->rx_queue_stop(eth_dev, i);
    1668         [ #  # ]:          0 :                 if (rc)
    1669                 :          0 :                         continue;
    1670                 :            : 
    1671                 :          0 :                 rxq = eth_dev->data->rx_queues[i];
    1672                 :          0 :                 count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
    1673         [ #  # ]:          0 :                 while (count) {
    1674         [ #  # ]:          0 :                         for (j = 0; j < count; j++)
    1675                 :          0 :                                 rte_pktmbuf_free(rx_pkts[j]);
    1676                 :          0 :                         count = dev->rx_pkt_burst_no_offload(rxq, rx_pkts, 32);
    1677                 :            :                 }
    1678                 :            :         }
    1679                 :            : 
    1680                 :            :         /* Stop tx queues  */
    1681         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
    1682                 :          0 :                 dev_ops->tx_queue_stop(eth_dev, i);
    1683                 :            : 
    1684                 :            :         /* Bring down link status internally */
    1685                 :            :         memset(&link, 0, sizeof(link));
    1686                 :          0 :         rte_eth_linkstatus_set(eth_dev, &link);
    1687                 :            : 
    1688                 :          0 :         return 0;
    1689                 :            : }
    1690                 :            : 
    1691                 :            : int
    1692         [ #  # ]:          0 : cnxk_nix_dev_start(struct rte_eth_dev *eth_dev)
    1693                 :            : {
    1694                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1695                 :            :         int rc, i;
    1696                 :            : 
    1697   [ #  #  #  # ]:          0 :         if (eth_dev->data->nb_rx_queues != 0 && !dev->ptp_en) {
    1698                 :          0 :                 rc = nix_recalc_mtu(eth_dev);
    1699         [ #  # ]:          0 :                 if (rc)
    1700                 :            :                         return rc;
    1701                 :            :         }
    1702                 :            : 
    1703                 :            :         /* Start rx queues */
    1704         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
    1705                 :          0 :                 rc = cnxk_nix_rx_queue_start(eth_dev, i);
    1706         [ #  # ]:          0 :                 if (rc)
    1707                 :          0 :                         return rc;
    1708                 :            :         }
    1709                 :            : 
    1710         [ #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_SECURITY) {
    1711                 :          0 :                 rc = roc_nix_inl_rq_ena_dis(&dev->nix, true);
    1712         [ #  # ]:          0 :                 if (rc) {
    1713                 :          0 :                         plt_err("Failed to enable Inline device RQ, rc=%d", rc);
    1714                 :          0 :                         return rc;
    1715                 :            :                 }
    1716                 :            :         }
    1717                 :            : 
    1718                 :            :         /* Start tx queues  */
    1719         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
    1720                 :          0 :                 rc = cnxk_nix_tx_queue_start(eth_dev, i);
    1721         [ #  # ]:          0 :                 if (rc)
    1722                 :          0 :                         return rc;
    1723                 :            :         }
    1724                 :            : 
    1725                 :            :         /* Update Flow control configuration */
    1726                 :          0 :         rc = nix_update_flow_ctrl_config(eth_dev);
    1727         [ #  # ]:          0 :         if (rc) {
    1728                 :          0 :                 plt_err("Failed to enable flow control. error code(%d)", rc);
    1729                 :          0 :                 return rc;
    1730                 :            :         }
    1731                 :            : 
    1732                 :            :         /* Enable Rx in NPC */
    1733                 :          0 :         rc = roc_nix_npc_rx_ena_dis(&dev->nix, true);
    1734         [ #  # ]:          0 :         if (rc) {
    1735                 :          0 :                 plt_err("Failed to enable NPC rx %d", rc);
    1736                 :          0 :                 return rc;
    1737                 :            :         }
    1738                 :            : 
    1739                 :          0 :         rc = roc_npc_mcam_enable_all_entries(&dev->npc, 1);
    1740         [ #  # ]:          0 :         if (rc) {
    1741                 :          0 :                 plt_err("Failed to enable NPC entries %d", rc);
    1742                 :          0 :                 return rc;
    1743                 :            :         }
    1744                 :            : 
    1745                 :          0 :         cnxk_nix_toggle_flag_link_cfg(dev, true);
    1746                 :            : 
    1747                 :            :         /* Start link change events */
    1748         [ #  # ]:          0 :         if (!roc_nix_is_vf_or_sdp(&dev->nix)) {
    1749                 :          0 :                 rc = roc_nix_mac_link_event_start_stop(&dev->nix, true);
    1750         [ #  # ]:          0 :                 if (rc) {
    1751                 :          0 :                         plt_err("Failed to start cgx link event %d", rc);
    1752                 :          0 :                         goto rx_disable;
    1753                 :            :                 }
    1754                 :            :         }
    1755                 :            : 
    1756                 :            :         /* Enable PTP if it is requested by the user or already
    1757                 :            :          * enabled on PF owning this VF
    1758                 :            :          */
    1759         [ #  # ]:          0 :         memset(&dev->tstamp, 0, sizeof(struct cnxk_timesync_info));
    1760   [ #  #  #  # ]:          0 :         if ((dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP) || dev->ptp_en)
    1761                 :          0 :                 cnxk_eth_dev_ops.timesync_enable(eth_dev);
    1762                 :            :         else
    1763                 :          0 :                 cnxk_eth_dev_ops.timesync_disable(eth_dev);
    1764                 :            : 
    1765   [ #  #  #  # ]:          0 :         if (dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP || dev->ptp_en) {
    1766                 :          0 :                 rc = rte_mbuf_dyn_rx_timestamp_register
    1767                 :            :                         (&dev->tstamp.tstamp_dynfield_offset,
    1768                 :            :                          &dev->tstamp.rx_tstamp_dynflag);
    1769         [ #  # ]:          0 :                 if (rc != 0) {
    1770                 :          0 :                         plt_err("Failed to register Rx timestamp field/flag");
    1771                 :          0 :                         goto rx_disable;
    1772                 :            :                 }
    1773                 :            :         }
    1774                 :            : 
    1775                 :          0 :         cnxk_nix_toggle_flag_link_cfg(dev, false);
    1776                 :            : 
    1777                 :          0 :         roc_nix_inl_outb_soft_exp_poll_switch(&dev->nix, true);
    1778                 :            : 
    1779                 :          0 :         return 0;
    1780                 :            : 
    1781                 :          0 : rx_disable:
    1782                 :          0 :         roc_nix_npc_rx_ena_dis(&dev->nix, false);
    1783                 :          0 :         cnxk_nix_toggle_flag_link_cfg(dev, false);
    1784                 :          0 :         return rc;
    1785                 :            : }
    1786                 :            : 
    1787                 :            : static int cnxk_nix_dev_reset(struct rte_eth_dev *eth_dev);
    1788                 :            : static int cnxk_nix_dev_close(struct rte_eth_dev *eth_dev);
    1789                 :            : 
    1790                 :            : /* CNXK platform independent eth dev ops */
    1791                 :            : struct eth_dev_ops cnxk_eth_dev_ops = {
    1792                 :            :         .mtu_set = cnxk_nix_mtu_set,
    1793                 :            :         .mac_addr_add = cnxk_nix_mac_addr_add,
    1794                 :            :         .mac_addr_remove = cnxk_nix_mac_addr_del,
    1795                 :            :         .mac_addr_set = cnxk_nix_mac_addr_set,
    1796                 :            :         .dev_infos_get = cnxk_nix_info_get,
    1797                 :            :         .link_update = cnxk_nix_link_update,
    1798                 :            :         .tx_queue_release = cnxk_nix_tx_queue_release,
    1799                 :            :         .rx_queue_release = cnxk_nix_rx_queue_release,
    1800                 :            :         .dev_stop = cnxk_nix_dev_stop,
    1801                 :            :         .dev_close = cnxk_nix_dev_close,
    1802                 :            :         .dev_reset = cnxk_nix_dev_reset,
    1803                 :            :         .tx_queue_start = cnxk_nix_tx_queue_start,
    1804                 :            :         .rx_queue_start = cnxk_nix_rx_queue_start,
    1805                 :            :         .rx_queue_stop = cnxk_nix_rx_queue_stop,
    1806                 :            :         .dev_supported_ptypes_get = cnxk_nix_supported_ptypes_get,
    1807                 :            :         .promiscuous_enable = cnxk_nix_promisc_enable,
    1808                 :            :         .promiscuous_disable = cnxk_nix_promisc_disable,
    1809                 :            :         .allmulticast_enable = cnxk_nix_allmulticast_enable,
    1810                 :            :         .allmulticast_disable = cnxk_nix_allmulticast_disable,
    1811                 :            :         .rx_burst_mode_get = cnxk_nix_rx_burst_mode_get,
    1812                 :            :         .tx_burst_mode_get = cnxk_nix_tx_burst_mode_get,
    1813                 :            :         .flow_ctrl_get = cnxk_nix_flow_ctrl_get,
    1814                 :            :         .flow_ctrl_set = cnxk_nix_flow_ctrl_set,
    1815                 :            :         .priority_flow_ctrl_queue_config =
    1816                 :            :                                 cnxk_nix_priority_flow_ctrl_queue_config,
    1817                 :            :         .priority_flow_ctrl_queue_info_get =
    1818                 :            :                                 cnxk_nix_priority_flow_ctrl_queue_info_get,
    1819                 :            :         .dev_set_link_up = cnxk_nix_set_link_up,
    1820                 :            :         .dev_set_link_down = cnxk_nix_set_link_down,
    1821                 :            :         .get_module_info = cnxk_nix_get_module_info,
    1822                 :            :         .get_module_eeprom = cnxk_nix_get_module_eeprom,
    1823                 :            :         .rx_queue_intr_enable = cnxk_nix_rx_queue_intr_enable,
    1824                 :            :         .rx_queue_intr_disable = cnxk_nix_rx_queue_intr_disable,
    1825                 :            :         .pool_ops_supported = cnxk_nix_pool_ops_supported,
    1826                 :            :         .queue_stats_mapping_set = cnxk_nix_queue_stats_mapping,
    1827                 :            :         .stats_get = cnxk_nix_stats_get,
    1828                 :            :         .stats_reset = cnxk_nix_stats_reset,
    1829                 :            :         .xstats_get = cnxk_nix_xstats_get,
    1830                 :            :         .xstats_get_names = cnxk_nix_xstats_get_names,
    1831                 :            :         .xstats_reset = cnxk_nix_xstats_reset,
    1832                 :            :         .xstats_get_by_id = cnxk_nix_xstats_get_by_id,
    1833                 :            :         .xstats_get_names_by_id = cnxk_nix_xstats_get_names_by_id,
    1834                 :            :         .fw_version_get = cnxk_nix_fw_version_get,
    1835                 :            :         .rxq_info_get = cnxk_nix_rxq_info_get,
    1836                 :            :         .txq_info_get = cnxk_nix_txq_info_get,
    1837                 :            :         .tx_done_cleanup = cnxk_nix_tx_done_cleanup,
    1838                 :            :         .flow_ops_get = cnxk_nix_flow_ops_get,
    1839                 :            :         .get_reg = cnxk_nix_dev_get_reg,
    1840                 :            :         .timesync_read_rx_timestamp = cnxk_nix_timesync_read_rx_timestamp,
    1841                 :            :         .timesync_read_tx_timestamp = cnxk_nix_timesync_read_tx_timestamp,
    1842                 :            :         .timesync_read_time = cnxk_nix_timesync_read_time,
    1843                 :            :         .timesync_write_time = cnxk_nix_timesync_write_time,
    1844                 :            :         .timesync_adjust_time = cnxk_nix_timesync_adjust_time,
    1845                 :            :         .read_clock = cnxk_nix_read_clock,
    1846                 :            :         .reta_update = cnxk_nix_reta_update,
    1847                 :            :         .reta_query = cnxk_nix_reta_query,
    1848                 :            :         .rss_hash_update = cnxk_nix_rss_hash_update,
    1849                 :            :         .rss_hash_conf_get = cnxk_nix_rss_hash_conf_get,
    1850                 :            :         .set_mc_addr_list = cnxk_nix_mc_addr_list_configure,
    1851                 :            :         .set_queue_rate_limit = cnxk_nix_tm_set_queue_rate_limit,
    1852                 :            :         .tm_ops_get = cnxk_nix_tm_ops_get,
    1853                 :            :         .mtr_ops_get = cnxk_nix_mtr_ops_get,
    1854                 :            :         .eth_dev_priv_dump  = cnxk_nix_eth_dev_priv_dump,
    1855                 :            :         .cman_info_get = cnxk_nix_cman_info_get,
    1856                 :            :         .cman_config_init = cnxk_nix_cman_config_init,
    1857                 :            :         .cman_config_set = cnxk_nix_cman_config_set,
    1858                 :            :         .cman_config_get = cnxk_nix_cman_config_get,
    1859                 :            :         .eth_tx_descriptor_dump = cnxk_nix_tx_descriptor_dump,
    1860                 :            : };
    1861                 :            : 
    1862                 :            : void
    1863                 :          0 : cnxk_eth_dev_q_err_cb(struct roc_nix *nix, void *data)
    1864                 :            : {
    1865                 :            :         struct cnxk_eth_dev *dev = (struct cnxk_eth_dev *)nix;
    1866                 :          0 :         struct rte_eth_dev *eth_dev = dev->eth_dev;
    1867                 :            : 
    1868                 :            :         /* Set the flag and execute application callbacks */
    1869                 :          0 :         rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_INTR_RESET, data);
    1870                 :          0 : }
    1871                 :            : 
    1872                 :            : static int
    1873                 :          0 : cnxk_eth_dev_init(struct rte_eth_dev *eth_dev)
    1874                 :            : {
    1875                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1876                 :            :         struct rte_security_ctx *sec_ctx;
    1877                 :          0 :         struct roc_nix *nix = &dev->nix;
    1878                 :            :         struct rte_pci_device *pci_dev;
    1879                 :            :         int rc, max_entries;
    1880                 :            : 
    1881                 :          0 :         eth_dev->dev_ops = &cnxk_eth_dev_ops;
    1882                 :          0 :         eth_dev->rx_queue_count = cnxk_nix_rx_queue_count;
    1883                 :          0 :         eth_dev->rx_descriptor_status = cnxk_nix_rx_descriptor_status;
    1884                 :          0 :         eth_dev->tx_descriptor_status = cnxk_nix_tx_descriptor_status;
    1885                 :            : 
    1886                 :            :         /* Alloc security context */
    1887                 :          0 :         sec_ctx = plt_zmalloc(sizeof(struct rte_security_ctx), 0);
    1888         [ #  # ]:          0 :         if (!sec_ctx)
    1889                 :            :                 return -ENOMEM;
    1890                 :          0 :         sec_ctx->device = eth_dev;
    1891                 :          0 :         sec_ctx->ops = &cnxk_eth_sec_ops;
    1892                 :          0 :         sec_ctx->flags = RTE_SEC_CTX_F_FAST_SET_MDATA;
    1893                 :          0 :         eth_dev->security_ctx = sec_ctx;
    1894                 :            : 
    1895                 :            :         /* For secondary processes, the primary has done all the work */
    1896         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    1897                 :            :                 return 0;
    1898                 :            : 
    1899                 :          0 :         pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
    1900                 :          0 :         rte_eth_copy_pci_info(eth_dev, pci_dev);
    1901                 :            : 
    1902                 :            :         /* Parse devargs string */
    1903                 :          0 :         rc = cnxk_ethdev_parse_devargs(eth_dev->device->devargs, dev);
    1904         [ #  # ]:          0 :         if (rc) {
    1905                 :          0 :                 plt_err("Failed to parse devargs rc=%d", rc);
    1906                 :          0 :                 goto error;
    1907                 :            :         }
    1908                 :            : 
    1909                 :            :         /* Initialize base roc nix */
    1910                 :          0 :         nix->pci_dev = pci_dev;
    1911                 :          0 :         nix->hw_vlan_ins = true;
    1912                 :          0 :         nix->port_id = eth_dev->data->port_id;
    1913                 :            :         /* For better performance set default VF root schedule weight */
    1914         [ #  # ]:          0 :         nix->root_sched_weight = NIX_TM_DFLT_RR_WT;
    1915         [ #  # ]:          0 :         if (roc_feature_nix_has_own_meta_aura())
    1916                 :          0 :                 nix->local_meta_aura_ena = true;
    1917                 :          0 :         rc = roc_nix_dev_init(nix);
    1918         [ #  # ]:          0 :         if (rc) {
    1919                 :          0 :                 plt_err("Failed to initialize roc nix rc=%d", rc);
    1920                 :          0 :                 goto error;
    1921                 :            :         }
    1922                 :            : 
    1923                 :            :         /* Register up msg callbacks */
    1924                 :          0 :         roc_nix_mac_link_cb_register(nix, cnxk_eth_dev_link_status_cb);
    1925                 :            : 
    1926                 :            :         /* Register up msg callbacks */
    1927                 :          0 :         roc_nix_mac_link_info_get_cb_register(nix,
    1928                 :            :                                               cnxk_eth_dev_link_status_get_cb);
    1929                 :            : 
    1930                 :            :         /* Register up msg callbacks */
    1931                 :          0 :         roc_nix_q_err_cb_register(nix, cnxk_eth_dev_q_err_cb);
    1932                 :            : 
    1933                 :            :         /* Register callback for inline meta pool create */
    1934                 :          0 :         roc_nix_inl_meta_pool_cb_register(cnxk_nix_inl_meta_pool_cb);
    1935                 :            : 
    1936                 :            :         /* Register callback for inline meta pool create 1:N pool:aura */
    1937                 :          0 :         roc_nix_inl_custom_meta_pool_cb_register(cnxk_nix_inl_custom_meta_pool_cb);
    1938                 :            : 
    1939                 :          0 :         dev->eth_dev = eth_dev;
    1940                 :          0 :         dev->configured = 0;
    1941                 :          0 :         dev->ptype_disable = 0;
    1942                 :          0 :         dev->proto = RTE_MTR_COLOR_IN_PROTO_OUTER_VLAN;
    1943                 :            : 
    1944                 :          0 :         TAILQ_INIT(&dev->inb.list);
    1945                 :          0 :         TAILQ_INIT(&dev->outb.list);
    1946                 :            :         rte_spinlock_init(&dev->inb.lock);
    1947                 :            :         rte_spinlock_init(&dev->outb.lock);
    1948                 :            : 
    1949                 :            :         /* For vfs, returned max_entries will be 0. but to keep default mac
    1950                 :            :          * address, one entry must be allocated. so setting up to 1.
    1951                 :            :          */
    1952         [ #  # ]:          0 :         if (roc_nix_is_vf_or_sdp(nix))
    1953                 :            :                 max_entries = 1;
    1954                 :            :         else
    1955                 :          0 :                 max_entries = roc_nix_mac_max_entries_get(nix);
    1956                 :            : 
    1957         [ #  # ]:          0 :         if (max_entries <= 0) {
    1958                 :          0 :                 plt_err("Failed to get max entries for mac addr");
    1959                 :            :                 rc = -ENOTSUP;
    1960                 :          0 :                 goto dev_fini;
    1961                 :            :         }
    1962                 :            : 
    1963                 :          0 :         eth_dev->data->mac_addrs =
    1964                 :          0 :                 rte_zmalloc("mac_addr", max_entries * RTE_ETHER_ADDR_LEN, 0);
    1965         [ #  # ]:          0 :         if (eth_dev->data->mac_addrs == NULL) {
    1966                 :          0 :                 plt_err("Failed to allocate memory for mac addr");
    1967                 :            :                 rc = -ENOMEM;
    1968                 :          0 :                 goto dev_fini;
    1969                 :            :         }
    1970                 :            : 
    1971                 :          0 :         dev->dmac_idx_map = rte_zmalloc("dmac_idx_map", max_entries * sizeof(int), 0);
    1972         [ #  # ]:          0 :         if (dev->dmac_idx_map == NULL) {
    1973                 :          0 :                 plt_err("Failed to allocate memory for dmac idx map");
    1974                 :            :                 rc = -ENOMEM;
    1975                 :          0 :                 goto free_mac_addrs;
    1976                 :            :         }
    1977                 :            : 
    1978                 :          0 :         dev->max_mac_entries = max_entries;
    1979                 :          0 :         dev->dmac_filter_count = 1;
    1980                 :            : 
    1981                 :            :         /* Get mac address */
    1982                 :          0 :         rc = roc_nix_npc_mac_addr_get(nix, dev->mac_addr);
    1983         [ #  # ]:          0 :         if (rc) {
    1984                 :          0 :                 plt_err("Failed to get mac addr, rc=%d", rc);
    1985                 :          0 :                 goto free_mac_addrs;
    1986                 :            :         }
    1987                 :            : 
    1988                 :            :         /* Update the mac address */
    1989                 :          0 :         memcpy(eth_dev->data->mac_addrs, dev->mac_addr, RTE_ETHER_ADDR_LEN);
    1990                 :            : 
    1991                 :            :         /* Union of all capabilities supported by CNXK.
    1992                 :            :          * Platform specific capabilities will be
    1993                 :            :          * updated later.
    1994                 :            :          */
    1995                 :          0 :         dev->rx_offload_capa = nix_get_rx_offload_capa(dev);
    1996                 :          0 :         dev->tx_offload_capa = nix_get_tx_offload_capa(dev);
    1997                 :          0 :         dev->speed_capa = nix_get_speed_capa(dev);
    1998                 :            : 
    1999                 :            :         /* Initialize roc npc */
    2000                 :          0 :         dev->npc.roc_nix = nix;
    2001                 :          0 :         rc = roc_npc_init(&dev->npc);
    2002         [ #  # ]:          0 :         if (rc)
    2003                 :          0 :                 goto free_mac_addrs;
    2004                 :            : 
    2005         [ #  # ]:          0 :         if (roc_feature_nix_has_macsec()) {
    2006                 :          0 :                 rc = cnxk_mcs_dev_init(dev, 0);
    2007         [ #  # ]:          0 :                 if (rc) {
    2008                 :          0 :                         plt_err("Failed to init MCS");
    2009                 :          0 :                         goto free_mac_addrs;
    2010                 :            :                 }
    2011                 :          0 :                 dev->rx_offload_capa |= RTE_ETH_RX_OFFLOAD_MACSEC_STRIP;
    2012                 :          0 :                 dev->tx_offload_capa |= RTE_ETH_TX_OFFLOAD_MACSEC_INSERT;
    2013                 :            : 
    2014                 :          0 :                 TAILQ_INIT(&dev->mcs_list);
    2015                 :            :         }
    2016                 :            : 
    2017                 :            :         /* Reserve a switch domain for eswitch device */
    2018         [ #  # ]:          0 :         if (pci_dev->id.device_id == PCI_DEVID_CNXK_RVU_ESWITCH_VF) {
    2019                 :          0 :                 eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR;
    2020                 :          0 :                 rc = rte_eth_switch_domain_alloc(&dev->switch_domain_id);
    2021         [ #  # ]:          0 :                 if (rc) {
    2022                 :          0 :                         plt_err("Failed to alloc switch domain: %d", rc);
    2023                 :          0 :                         goto free_mac_addrs;
    2024                 :            :                 }
    2025                 :            :         }
    2026                 :            : 
    2027                 :          0 :         plt_nix_dbg("Port=%d pf=%d vf=%d ver=%s hwcap=0x%" PRIx64 " rxoffload_capa=0x%" PRIx64
    2028                 :            :                     " txoffload_capa=0x%" PRIx64,
    2029                 :            :                     eth_dev->data->port_id, roc_nix_get_pf(nix), roc_nix_get_vf(nix),
    2030                 :            :                     CNXK_ETH_DEV_PMD_VERSION, dev->hwcap, dev->rx_offload_capa,
    2031                 :            :                     dev->tx_offload_capa);
    2032                 :          0 :         return 0;
    2033                 :            : 
    2034                 :          0 : free_mac_addrs:
    2035                 :          0 :         rte_free(eth_dev->data->mac_addrs);
    2036                 :          0 :         rte_free(dev->dmac_idx_map);
    2037                 :          0 : dev_fini:
    2038                 :          0 :         roc_nix_dev_fini(nix);
    2039                 :          0 : error:
    2040                 :          0 :         plt_err("Failed to init nix eth_dev rc=%d", rc);
    2041                 :          0 :         return rc;
    2042                 :            : }
    2043                 :            : 
    2044                 :            : static int
    2045                 :          0 : cnxk_eth_dev_uninit(struct rte_eth_dev *eth_dev, bool reset)
    2046                 :            : {
    2047                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    2048                 :          0 :         const struct eth_dev_ops *dev_ops = eth_dev->dev_ops;
    2049                 :            :         struct cnxk_pfc_cfg *pfc_cfg = &dev->pfc_cfg;
    2050                 :            :         struct cnxk_fc_cfg *fc_cfg = &dev->fc_cfg;
    2051                 :            :         struct rte_eth_pfc_queue_conf pfc_conf;
    2052                 :          0 :         struct roc_nix *nix = &dev->nix;
    2053                 :            :         struct rte_eth_fc_conf fc_conf;
    2054                 :            :         int rc, i;
    2055                 :            : 
    2056                 :          0 :         plt_free(eth_dev->security_ctx);
    2057                 :          0 :         eth_dev->security_ctx = NULL;
    2058                 :            : 
    2059                 :            :         /* Nothing to be done for secondary processes */
    2060         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    2061                 :            :                 return 0;
    2062                 :            : 
    2063                 :            :         /* Disable switch hdr pkind */
    2064                 :          0 :         roc_nix_switch_hdr_set(&dev->nix, 0, 0, 0, 0);
    2065                 :            : 
    2066                 :            :         /* Clear the flag since we are closing down */
    2067                 :          0 :         dev->configured = 0;
    2068                 :            : 
    2069                 :            :         /* Disable all the NPC entries */
    2070                 :          0 :         rc = roc_npc_mcam_enable_all_entries(&dev->npc, 0);
    2071         [ #  # ]:          0 :         if (rc)
    2072                 :            :                 return rc;
    2073                 :            : 
    2074                 :          0 :         roc_nix_npc_rx_ena_dis(nix, false);
    2075                 :            : 
    2076                 :            :         /* Restore 802.3 Flow control configuration */
    2077                 :            :         memset(&pfc_conf, 0, sizeof(struct rte_eth_pfc_queue_conf));
    2078                 :            :         memset(&fc_conf, 0, sizeof(struct rte_eth_fc_conf));
    2079         [ #  # ]:          0 :         if (fc_cfg->rx_pause || fc_cfg->tx_pause) {
    2080                 :            :                 fc_conf.mode = RTE_ETH_FC_NONE;
    2081                 :          0 :                 rc = cnxk_nix_flow_ctrl_set(eth_dev, &fc_conf);
    2082         [ #  # ]:          0 :                 if (rc < 0)
    2083                 :          0 :                         plt_err("Failed to reset control flow. error code(%d)",
    2084                 :            :                                         rc);
    2085                 :            :         }
    2086   [ #  #  #  # ]:          0 :         if (pfc_cfg->rx_pause_en || pfc_cfg->tx_pause_en) {
    2087         [ #  # ]:          0 :                 for (i = 0; i < RTE_MAX(eth_dev->data->nb_rx_queues,
    2088                 :            :                                         eth_dev->data->nb_tx_queues);
    2089                 :          0 :                      i++) {
    2090                 :          0 :                         pfc_conf.mode = RTE_ETH_FC_NONE;
    2091                 :          0 :                         pfc_conf.rx_pause.tc = ROC_NIX_PFC_CLASS_INVALID;
    2092                 :          0 :                         pfc_conf.rx_pause.tx_qid = i;
    2093                 :          0 :                         pfc_conf.tx_pause.tc = ROC_NIX_PFC_CLASS_INVALID;
    2094                 :          0 :                         pfc_conf.tx_pause.rx_qid = i;
    2095                 :          0 :                         rc = cnxk_nix_priority_flow_ctrl_queue_config(eth_dev,
    2096                 :            :                                         &pfc_conf);
    2097         [ #  # ]:          0 :                         if (rc && rc != -ENOTSUP)
    2098                 :          0 :                                 plt_err("Failed to reset PFC. error code(%d)", rc);
    2099                 :            :                 }
    2100                 :            :         }
    2101                 :            : 
    2102                 :            :         /* Free switch domain ID reserved for eswitch device */
    2103   [ #  #  #  # ]:          0 :         if ((eth_dev->data->dev_flags & RTE_ETH_DEV_REPRESENTOR) &&
    2104                 :          0 :             rte_eth_switch_domain_free(dev->switch_domain_id))
    2105                 :          0 :                 plt_err("Failed to free switch domain");
    2106                 :            : 
    2107                 :            :         /* Disable and free rte_meter entries */
    2108                 :          0 :         nix_meter_fini(dev);
    2109                 :            : 
    2110                 :            :         /* Disable and free rte_flow entries */
    2111                 :          0 :         roc_npc_fini(&dev->npc);
    2112                 :            : 
    2113                 :            :         /* Disable link status events */
    2114                 :          0 :         roc_nix_mac_link_event_start_stop(nix, false);
    2115                 :            : 
    2116                 :            :         /* Unregister the link update op, this is required to stop VFs from
    2117                 :            :          * receiving link status updates on exit path.
    2118                 :            :          */
    2119                 :          0 :         roc_nix_mac_link_cb_unregister(nix);
    2120                 :            : 
    2121                 :            :         /* Free up SQs */
    2122         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_tx_queues; i++) {
    2123                 :          0 :                 dev_ops->tx_queue_release(eth_dev, i);
    2124                 :          0 :                 eth_dev->data->tx_queues[i] = NULL;
    2125                 :            :         }
    2126                 :          0 :         eth_dev->data->nb_tx_queues = 0;
    2127                 :            : 
    2128                 :            :         /* Free up RQ's and CQ's */
    2129         [ #  # ]:          0 :         for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
    2130                 :          0 :                 dev_ops->rx_queue_release(eth_dev, i);
    2131                 :          0 :                 eth_dev->data->rx_queues[i] = NULL;
    2132                 :            :         }
    2133         [ #  # ]:          0 :         eth_dev->data->nb_rx_queues = 0;
    2134                 :            : 
    2135         [ #  # ]:          0 :         if (roc_feature_nix_has_macsec())
    2136                 :          0 :                 cnxk_mcs_dev_fini(dev);
    2137                 :            : 
    2138                 :            :         /* Free security resources */
    2139                 :          0 :         nix_security_release(dev);
    2140                 :            : 
    2141                 :            :         /* Free tm resources */
    2142                 :          0 :         roc_nix_tm_fini(nix);
    2143                 :            : 
    2144                 :            :         /* Unregister queue irqs */
    2145                 :          0 :         roc_nix_unregister_queue_irqs(nix);
    2146                 :            : 
    2147                 :            :         /* Unregister cq irqs */
    2148         [ #  # ]:          0 :         if (eth_dev->data->dev_conf.intr_conf.rxq)
    2149                 :          0 :                 roc_nix_unregister_cq_irqs(nix);
    2150                 :            : 
    2151                 :            :         /* Free ROC RQ's, SQ's and CQ's memory */
    2152                 :          0 :         nix_free_queue_mem(dev);
    2153                 :            : 
    2154                 :            :         /* free nix bpid */
    2155                 :          0 :         rc = nix_rxchan_cfg_disable(dev);
    2156         [ #  # ]:          0 :         if (rc)
    2157                 :          0 :                 plt_err("Failed to free nix bpid, rc=%d", rc);
    2158                 :            : 
    2159                 :            :         /* Free nix lf resources */
    2160                 :          0 :         rc = roc_nix_lf_free(nix);
    2161         [ #  # ]:          0 :         if (rc)
    2162                 :          0 :                 plt_err("Failed to free nix lf, rc=%d", rc);
    2163                 :            : 
    2164                 :          0 :         rte_free(dev->dmac_idx_map);
    2165                 :          0 :         dev->dmac_idx_map = NULL;
    2166                 :            : 
    2167                 :          0 :         rte_free(eth_dev->data->mac_addrs);
    2168                 :          0 :         eth_dev->data->mac_addrs = NULL;
    2169                 :            : 
    2170                 :          0 :         rc = roc_nix_dev_fini(nix);
    2171                 :            :         /* Can be freed later by PMD if NPA LF is in use */
    2172         [ #  # ]:          0 :         if (rc == -EAGAIN) {
    2173         [ #  # ]:          0 :                 if (!reset)
    2174                 :          0 :                         eth_dev->data->dev_private = NULL;
    2175                 :          0 :                 return 0;
    2176         [ #  # ]:          0 :         } else if (rc) {
    2177                 :          0 :                 plt_err("Failed in nix dev fini, rc=%d", rc);
    2178                 :            :         }
    2179                 :            : 
    2180                 :            :         return rc;
    2181                 :            : }
    2182                 :            : 
    2183                 :            : static int
    2184                 :          0 : cnxk_nix_dev_close(struct rte_eth_dev *eth_dev)
    2185                 :            : {
    2186                 :          0 :         cnxk_eth_dev_uninit(eth_dev, false);
    2187                 :          0 :         return 0;
    2188                 :            : }
    2189                 :            : 
    2190                 :            : static int
    2191                 :          0 : cnxk_nix_dev_reset(struct rte_eth_dev *eth_dev)
    2192                 :            : {
    2193                 :            :         int rc;
    2194                 :            : 
    2195                 :          0 :         rc = cnxk_eth_dev_uninit(eth_dev, true);
    2196         [ #  # ]:          0 :         if (rc)
    2197                 :            :                 return rc;
    2198                 :            : 
    2199                 :          0 :         return cnxk_eth_dev_init(eth_dev);
    2200                 :            : }
    2201                 :            : 
    2202                 :            : int
    2203                 :          0 : cnxk_nix_remove(struct rte_pci_device *pci_dev)
    2204                 :            : {
    2205                 :            :         struct rte_eth_dev *eth_dev;
    2206                 :            :         struct roc_nix *nix;
    2207                 :            :         int rc = -EINVAL;
    2208                 :            : 
    2209                 :          0 :         eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
    2210         [ #  # ]:          0 :         if (eth_dev) {
    2211                 :            :                 /* Cleanup eth dev */
    2212                 :          0 :                 rc = cnxk_eth_dev_uninit(eth_dev, false);
    2213         [ #  # ]:          0 :                 if (rc)
    2214                 :            :                         return rc;
    2215                 :            : 
    2216                 :          0 :                 rte_eth_dev_release_port(eth_dev);
    2217                 :            :         }
    2218                 :            : 
    2219                 :            :         /* Nothing to be done for secondary processes */
    2220         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
    2221                 :            :                 return 0;
    2222                 :            : 
    2223                 :            :         /* Check if this device is hosting common resource */
    2224                 :          0 :         nix = roc_idev_npa_nix_get();
    2225   [ #  #  #  # ]:          0 :         if (!nix || nix->pci_dev != pci_dev)
    2226                 :            :                 return 0;
    2227                 :            : 
    2228                 :            :         /* Try nix fini now */
    2229                 :          0 :         rc = roc_nix_dev_fini(nix);
    2230         [ #  # ]:          0 :         if (rc == -EAGAIN) {
    2231                 :          0 :                 plt_info("%s: common resource in use by other devices",
    2232                 :            :                          pci_dev->name);
    2233                 :          0 :                 goto exit;
    2234         [ #  # ]:          0 :         } else if (rc) {
    2235                 :          0 :                 plt_err("Failed in nix dev fini, rc=%d", rc);
    2236                 :          0 :                 goto exit;
    2237                 :            :         }
    2238                 :            : 
    2239                 :            :         /* Free device pointer as rte_ethdev does not have it anymore */
    2240                 :          0 :         rte_free(nix);
    2241                 :            : exit:
    2242                 :            :         return rc;
    2243                 :            : }
    2244                 :            : 
    2245                 :            : int
    2246                 :          0 : cnxk_nix_probe(struct rte_pci_driver *pci_drv, struct rte_pci_device *pci_dev)
    2247                 :            : {
    2248                 :            :         int rc;
    2249                 :            : 
    2250                 :            :         RTE_SET_USED(pci_drv);
    2251                 :            : 
    2252                 :          0 :         rc = rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct cnxk_eth_dev),
    2253                 :            :                                            cnxk_eth_dev_init);
    2254                 :            : 
    2255                 :            :         /* On error on secondary, recheck if port exists in primary or
    2256                 :            :          * in mid of detach state.
    2257                 :            :          */
    2258   [ #  #  #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY && rc)
    2259         [ #  # ]:          0 :                 if (!rte_eth_dev_allocated(pci_dev->device.name))
    2260                 :          0 :                         return 0;
    2261                 :            :         return rc;
    2262                 :            : }

Generated by: LCOV version 1.14