LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_nix.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 265 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 24 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 116 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "roc_api.h"
       6                 :            : #include "roc_priv.h"
       7                 :            : 
       8                 :            : bool
       9                 :          0 : roc_nix_is_lbk(struct roc_nix *roc_nix)
      10                 :            : {
      11                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      12                 :            : 
      13                 :          0 :         return nix->lbk_link;
      14                 :            : }
      15                 :            : 
      16                 :            : bool
      17                 :          0 : roc_nix_is_esw(struct roc_nix *roc_nix)
      18                 :            : {
      19                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      20                 :            : 
      21                 :          0 :         return nix->esw_link;
      22                 :            : }
      23                 :            : 
      24                 :            : int
      25                 :          0 : roc_nix_get_base_chan(struct roc_nix *roc_nix)
      26                 :            : {
      27                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      28                 :            : 
      29                 :          0 :         return nix->rx_chan_base;
      30                 :            : }
      31                 :            : 
      32                 :            : uint8_t
      33                 :          0 : roc_nix_get_rx_chan_cnt(struct roc_nix *roc_nix)
      34                 :            : {
      35                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      36                 :            : 
      37                 :          0 :         return nix->rx_chan_cnt;
      38                 :            : }
      39                 :            : 
      40                 :            : uint16_t
      41                 :          0 : roc_nix_get_vwqe_interval(struct roc_nix *roc_nix)
      42                 :            : {
      43                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      44                 :            : 
      45                 :          0 :         return nix->vwqe_interval;
      46                 :            : }
      47                 :            : 
      48                 :            : bool
      49                 :          0 : roc_nix_is_sdp(struct roc_nix *roc_nix)
      50                 :            : {
      51                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      52                 :            : 
      53                 :          0 :         return nix->sdp_link;
      54                 :            : }
      55                 :            : 
      56                 :            : bool
      57                 :          0 : roc_nix_is_pf(struct roc_nix *roc_nix)
      58                 :            : {
      59                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      60                 :            : 
      61                 :          0 :         return !dev_is_vf(&nix->dev);
      62                 :            : }
      63                 :            : 
      64                 :            : int
      65                 :          0 : roc_nix_get_pf(struct roc_nix *roc_nix)
      66                 :            : {
      67                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      68                 :            :         struct dev *dev = &nix->dev;
      69                 :            : 
      70         [ #  # ]:          0 :         return dev_get_pf(dev->pf_func);
      71                 :            : }
      72                 :            : 
      73                 :            : int
      74                 :          0 : roc_nix_get_vf(struct roc_nix *roc_nix)
      75                 :            : {
      76                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      77                 :            :         struct dev *dev = &nix->dev;
      78                 :            : 
      79         [ #  # ]:          0 :         return dev_get_vf(dev->pf_func);
      80                 :            : }
      81                 :            : 
      82                 :            : bool
      83                 :          0 : roc_nix_is_vf_or_sdp(struct roc_nix *roc_nix)
      84                 :            : {
      85                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      86                 :            : 
      87   [ #  #  #  # ]:          0 :         return (dev_is_vf(&nix->dev) != 0) || roc_nix_is_sdp(roc_nix);
      88                 :            : }
      89                 :            : 
      90                 :            : uint16_t
      91                 :          0 : roc_nix_get_pf_func(struct roc_nix *roc_nix)
      92                 :            : {
      93                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
      94                 :            :         struct dev *dev = &nix->dev;
      95                 :            : 
      96                 :          0 :         return dev->pf_func;
      97                 :            : }
      98                 :            : 
      99                 :            : int
     100                 :          0 : roc_nix_lf_inl_ipsec_cfg(struct roc_nix *roc_nix, struct roc_nix_ipsec_cfg *cfg,
     101                 :            :                          bool enb)
     102                 :            : {
     103                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     104                 :            :         struct nix_inline_ipsec_lf_cfg *lf_cfg;
     105                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     106                 :            :         int rc;
     107                 :            : 
     108                 :          0 :         lf_cfg = mbox_alloc_msg_nix_inline_ipsec_lf_cfg(mbox);
     109         [ #  # ]:          0 :         if (lf_cfg == NULL) {
     110                 :            :                 rc = -ENOSPC;
     111                 :          0 :                 goto exit;
     112                 :            :         }
     113                 :            : 
     114         [ #  # ]:          0 :         if (enb) {
     115                 :          0 :                 lf_cfg->enable = 1;
     116                 :          0 :                 lf_cfg->sa_base_addr = cfg->iova;
     117         [ #  # ]:          0 :                 lf_cfg->ipsec_cfg1.sa_idx_w = plt_log2_u32(cfg->max_sa);
     118                 :          0 :                 lf_cfg->ipsec_cfg0.lenm1_max = roc_nix_max_pkt_len(roc_nix) - 1;
     119                 :          0 :                 lf_cfg->ipsec_cfg1.sa_idx_max = cfg->max_sa - 1;
     120         [ #  # ]:          0 :                 lf_cfg->ipsec_cfg0.sa_pow2_size = plt_log2_u32(cfg->sa_size);
     121                 :          0 :                 lf_cfg->ipsec_cfg0.tag_const = cfg->tag_const;
     122                 :          0 :                 lf_cfg->ipsec_cfg0.tt = cfg->tt;
     123                 :            :         } else {
     124                 :          0 :                 lf_cfg->enable = 0;
     125                 :            :         }
     126                 :            : 
     127                 :          0 :         rc = mbox_process(mbox);
     128                 :          0 : exit:
     129                 :            :         mbox_put(mbox);
     130                 :          0 :         return rc;
     131                 :            : }
     132                 :            : 
     133                 :            : int
     134                 :          0 : roc_nix_cpt_ctx_cache_sync(struct roc_nix *roc_nix)
     135                 :            : {
     136                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     137                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     138                 :            :         struct msg_req *req;
     139                 :            :         int rc;
     140                 :            : 
     141                 :          0 :         req = mbox_alloc_msg_cpt_ctx_cache_sync(mbox);
     142         [ #  # ]:          0 :         if (req == NULL) {
     143                 :            :                 rc = -ENOSPC;
     144                 :          0 :                 goto exit;
     145                 :            :         }
     146                 :            : 
     147                 :          0 :         rc = mbox_process(mbox);
     148                 :          0 : exit:
     149                 :            :         mbox_put(mbox);
     150                 :          0 :         return rc;
     151                 :            : }
     152                 :            : 
     153                 :            : int
     154                 :          0 : roc_nix_max_pkt_len(struct roc_nix *roc_nix)
     155                 :            : {
     156                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     157                 :            : 
     158         [ #  # ]:          0 :         if (roc_nix_is_sdp(roc_nix)) {
     159         [ #  # ]:          0 :                 if (roc_errata_nix_sdp_send_has_mtu_size_16k())
     160                 :            :                         return NIX_SDP_16K_HW_FRS;
     161                 :          0 :                 return NIX_SDP_MAX_HW_FRS;
     162                 :            :         }
     163                 :            : 
     164         [ #  # ]:          0 :         if (roc_model_is_cn9k())
     165                 :            :                 return NIX_CN9K_MAX_HW_FRS;
     166                 :            : 
     167         [ #  # ]:          0 :         if (nix->lbk_link || nix->esw_link)
     168                 :          0 :                 return NIX_LBK_MAX_HW_FRS;
     169                 :            : 
     170                 :            :         return NIX_RPM_MAX_HW_FRS;
     171                 :            : }
     172                 :            : 
     173                 :            : int
     174                 :          0 : roc_nix_lf_alloc(struct roc_nix *roc_nix, uint32_t nb_rxq, uint32_t nb_txq,
     175                 :            :                  uint64_t rx_cfg)
     176                 :            : {
     177                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     178                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     179                 :            :         struct nix_lf_alloc_req *req;
     180                 :            :         struct nix_lf_alloc_rsp *rsp;
     181                 :            :         int rc = -ENOSPC;
     182                 :            : 
     183                 :          0 :         req = mbox_alloc_msg_nix_lf_alloc(mbox);
     184         [ #  # ]:          0 :         if (req == NULL)
     185                 :          0 :                 goto fail;
     186                 :          0 :         req->rq_cnt = nb_rxq;
     187                 :          0 :         req->sq_cnt = nb_txq;
     188         [ #  # ]:          0 :         if (roc_nix->tx_compl_ena)
     189                 :          0 :                 req->cq_cnt = nb_rxq + nb_txq;
     190                 :            :         else
     191                 :          0 :                 req->cq_cnt = nb_rxq;
     192                 :            :         /* XQESZ can be W64 or W16 */
     193                 :          0 :         req->xqe_sz = NIX_XQESZ_W16;
     194                 :          0 :         req->rss_sz = nix->reta_sz;
     195                 :          0 :         req->rss_grps = ROC_NIX_RSS_GRPS;
     196                 :          0 :         req->npa_func = idev_npa_pffunc_get();
     197                 :          0 :         req->sso_func = idev_sso_pffunc_get();
     198                 :          0 :         req->rx_cfg = rx_cfg;
     199   [ #  #  #  #  :          0 :         if (roc_nix_is_lbk(roc_nix) && roc_nix->enable_loop &&
                   #  # ]
     200                 :            :             roc_model_is_cn98xx())
     201                 :          0 :                 req->flags = NIX_LF_LBK_BLK_SEL;
     202                 :            : 
     203         [ #  # ]:          0 :         if (!roc_nix->rss_tag_as_xor)
     204                 :          0 :                 req->flags |= NIX_LF_RSS_TAG_LSB_AS_ADDER;
     205                 :            : 
     206                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     207         [ #  # ]:          0 :         if (rc)
     208                 :          0 :                 goto fail;
     209                 :            : 
     210                 :          0 :         nix->rx_cfg = rx_cfg;
     211                 :          0 :         nix->sqb_size = rsp->sqb_size;
     212                 :          0 :         nix->tx_chan_base = rsp->tx_chan_base;
     213                 :          0 :         nix->rx_chan_base = rsp->rx_chan_base;
     214   [ #  #  #  # ]:          0 :         if (roc_nix_is_lbk(roc_nix) && roc_nix->enable_loop)
     215                 :          0 :                 nix->tx_chan_base = rsp->rx_chan_base;
     216                 :          0 :         nix->rx_chan_cnt = rsp->rx_chan_cnt;
     217                 :          0 :         nix->tx_chan_cnt = rsp->tx_chan_cnt;
     218                 :          0 :         nix->lso_tsov4_idx = rsp->lso_tsov4_idx;
     219                 :          0 :         nix->lso_tsov6_idx = rsp->lso_tsov6_idx;
     220                 :          0 :         nix->lf_tx_stats = rsp->lf_tx_stats;
     221                 :          0 :         nix->lf_rx_stats = rsp->lf_rx_stats;
     222                 :          0 :         nix->cints = rsp->cints;
     223                 :          0 :         roc_nix->cints = rsp->cints;
     224                 :          0 :         nix->qints = rsp->qints;
     225                 :          0 :         nix->ptp_en = rsp->hw_rx_tstamp_en;
     226                 :          0 :         roc_nix->rx_ptp_ena = rsp->hw_rx_tstamp_en;
     227                 :          0 :         nix->cgx_links = rsp->cgx_links;
     228                 :          0 :         nix->lbk_links = rsp->lbk_links;
     229                 :          0 :         nix->sdp_links = rsp->sdp_links;
     230                 :          0 :         nix->tx_link = rsp->tx_link;
     231                 :          0 :         nix->nb_rx_queues = nb_rxq;
     232                 :          0 :         nix->nb_tx_queues = nb_txq;
     233                 :            : 
     234                 :          0 :         roc_idev_nix_rx_chan_set(roc_nix->port_id, rsp->rx_chan_base);
     235                 :            : 
     236                 :          0 :         nix->rqs = plt_zmalloc(sizeof(struct roc_nix_rq *) * nb_rxq, 0);
     237         [ #  # ]:          0 :         if (!nix->rqs) {
     238                 :            :                 rc = -ENOMEM;
     239                 :          0 :                 goto fail;
     240                 :            :         }
     241                 :            : 
     242                 :          0 :         nix->sqs = plt_zmalloc(sizeof(struct roc_nix_sq *) * nb_txq, 0);
     243         [ #  # ]:          0 :         if (!nix->sqs) {
     244                 :            :                 rc = -ENOMEM;
     245                 :          0 :                 goto fail;
     246                 :            :         }
     247                 :            : 
     248                 :          0 :         nix_tel_node_add(roc_nix);
     249                 :          0 : fail:
     250                 :            :         mbox_put(mbox);
     251                 :          0 :         return rc;
     252                 :            : }
     253                 :            : 
     254                 :            : int
     255                 :          0 : roc_nix_lf_free(struct roc_nix *roc_nix)
     256                 :            : {
     257                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     258                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     259                 :            :         struct nix_lf_free_req *req;
     260                 :            :         struct ndc_sync_op *ndc_req;
     261                 :            :         int rc = -ENOSPC;
     262                 :            : 
     263                 :          0 :         plt_free(nix->rqs);
     264                 :          0 :         plt_free(nix->sqs);
     265                 :          0 :         nix->rqs = NULL;
     266                 :          0 :         nix->sqs = NULL;
     267                 :            : 
     268                 :            :         /* Sync NDC-NIX for LF */
     269                 :          0 :         ndc_req = mbox_alloc_msg_ndc_sync_op(mbox);
     270         [ #  # ]:          0 :         if (ndc_req == NULL)
     271                 :          0 :                 goto exit;
     272                 :          0 :         ndc_req->nix_lf_tx_sync = 1;
     273                 :          0 :         ndc_req->nix_lf_rx_sync = 1;
     274                 :          0 :         rc = mbox_process(mbox);
     275         [ #  # ]:          0 :         if (rc)
     276                 :          0 :                 plt_err("Error on NDC-NIX-[TX, RX] LF sync, rc %d", rc);
     277                 :            : 
     278                 :          0 :         req = mbox_alloc_msg_nix_lf_free(mbox);
     279         [ #  # ]:          0 :         if (req == NULL) {
     280                 :            :                 rc = -ENOSPC;
     281                 :          0 :                 goto exit;
     282                 :            :         }
     283                 :            :         /* Let AF driver free all this nix lf's
     284                 :            :          * NPC entries allocated using NPC MBOX.
     285                 :            :          */
     286                 :          0 :         req->flags = 0;
     287                 :            : 
     288                 :          0 :         rc = mbox_process(mbox);
     289                 :          0 : exit:
     290                 :            :         mbox_put(mbox);
     291                 :          0 :         return rc;
     292                 :            : }
     293                 :            : 
     294                 :            : static inline int
     295                 :          0 : nix_lf_attach(struct dev *dev)
     296                 :            : {
     297                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     298                 :            :         struct rsrc_attach_req *req;
     299                 :            :         int rc = -ENOSPC;
     300                 :            : 
     301                 :            :         /* Attach NIX(lf) */
     302                 :          0 :         req = mbox_alloc_msg_attach_resources(mbox);
     303         [ #  # ]:          0 :         if (req == NULL)
     304                 :          0 :                 goto exit;
     305                 :          0 :         req->modify = true;
     306                 :          0 :         req->nixlf = true;
     307                 :            : 
     308                 :          0 :         rc = mbox_process(mbox);
     309                 :          0 : exit:
     310                 :            :         mbox_put(mbox);
     311                 :          0 :         return rc;
     312                 :            : }
     313                 :            : 
     314                 :            : static inline int
     315                 :          0 : nix_lf_get_msix_offset(struct dev *dev, struct nix *nix)
     316                 :            : {
     317                 :            :         struct msix_offset_rsp *msix_rsp;
     318                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     319                 :            :         int rc;
     320                 :            : 
     321                 :            :         /* Get MSIX vector offsets */
     322                 :          0 :         mbox_alloc_msg_msix_offset(mbox);
     323                 :            :         rc = mbox_process_msg(mbox, (void *)&msix_rsp);
     324         [ #  # ]:          0 :         if (rc == 0)
     325                 :          0 :                 nix->msixoff = msix_rsp->nix_msixoff;
     326                 :            : 
     327                 :            :         mbox_put(mbox);
     328                 :          0 :         return rc;
     329                 :            : }
     330                 :            : 
     331                 :            : static inline int
     332                 :          0 : nix_lf_detach(struct nix *nix)
     333                 :            : {
     334                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     335                 :            :         struct rsrc_detach_req *req;
     336                 :            :         int rc = -ENOSPC;
     337                 :            : 
     338                 :          0 :         req = mbox_alloc_msg_detach_resources(mbox);
     339         [ #  # ]:          0 :         if (req == NULL)
     340                 :          0 :                 goto exit;
     341                 :          0 :         req->partial = true;
     342                 :          0 :         req->nixlf = true;
     343                 :            : 
     344                 :          0 :         rc = mbox_process(mbox);
     345                 :          0 : exit:
     346                 :            :         mbox_put(mbox);
     347                 :          0 :         return rc;
     348                 :            : }
     349                 :            : 
     350                 :            : static int
     351                 :          0 : roc_nix_get_hw_info(struct roc_nix *roc_nix)
     352                 :            : {
     353                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     354                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     355                 :            :         struct nix_hw_info *hw_info;
     356                 :            :         int rc;
     357                 :            : 
     358                 :          0 :         mbox_alloc_msg_nix_get_hw_info(mbox);
     359                 :            :         rc = mbox_process_msg(mbox, (void *)&hw_info);
     360         [ #  # ]:          0 :         if (rc == 0) {
     361                 :          0 :                 nix->vwqe_interval = hw_info->vwqe_delay;
     362         [ #  # ]:          0 :                 if (nix->lbk_link || nix->esw_link)
     363                 :          0 :                         roc_nix->dwrr_mtu = hw_info->lbk_dwrr_mtu;
     364         [ #  # ]:          0 :                 else if (nix->sdp_link)
     365                 :          0 :                         roc_nix->dwrr_mtu = hw_info->sdp_dwrr_mtu;
     366                 :            :                 else
     367                 :          0 :                         roc_nix->dwrr_mtu = hw_info->rpm_dwrr_mtu;
     368                 :            :         }
     369                 :            : 
     370                 :            :         mbox_put(mbox);
     371                 :          0 :         return rc;
     372                 :            : }
     373                 :            : 
     374                 :            : static void
     375                 :            : sdp_lbk_id_update(struct plt_pci_device *pci_dev, struct nix *nix)
     376                 :            : {
     377                 :          0 :         nix->sdp_link = false;
     378                 :          0 :         nix->lbk_link = false;
     379                 :          0 :         nix->esw_link = false;
     380                 :            : 
     381                 :            :         /* Update SDP/LBK link based on PCI device id */
     382   [ #  #  #  # ]:          0 :         switch (pci_dev->id.device_id) {
     383                 :          0 :         case PCI_DEVID_CNXK_RVU_SDP_PF:
     384                 :            :         case PCI_DEVID_CNXK_RVU_SDP_VF:
     385                 :          0 :                 nix->sdp_link = true;
     386                 :          0 :                 break;
     387                 :          0 :         case PCI_DEVID_CNXK_RVU_AF_VF:
     388                 :          0 :                 nix->lbk_link = true;
     389                 :          0 :                 break;
     390                 :          0 :         case PCI_DEVID_CNXK_RVU_ESWITCH_VF:
     391                 :          0 :                 nix->esw_link = true;
     392                 :          0 :                 break;
     393                 :            :         default:
     394                 :            :                 break;
     395                 :            :         }
     396                 :            : }
     397                 :            : 
     398                 :            : uint64_t
     399         [ #  # ]:          0 : nix_get_blkaddr(struct dev *dev)
     400                 :            : {
     401                 :            :         uint64_t blkaddr;
     402                 :            :         uint64_t reg;
     403                 :            : 
     404                 :            :         /* Reading the discovery register to know which NIX is the LF
     405                 :            :          * attached to.
     406                 :            :          */
     407   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() || roc_model_is_cn10k()) {
     408         [ #  # ]:          0 :                 reg = plt_read64(dev->bar2 + RVU_PF_BLOCK_ADDRX_DISC(RVU_BLOCK_ADDR_NIX0));
     409         [ #  # ]:          0 :                 blkaddr = reg & 0x1FFULL ? RVU_BLOCK_ADDR_NIX0 : RVU_BLOCK_ADDR_NIX1;
     410                 :            :         } else {
     411                 :          0 :                 reg = plt_read64(dev->bar2 + RVU_PF_DISC);
     412                 :          0 :                 blkaddr = reg & BIT_ULL(RVU_BLOCK_ADDR_NIX0) ? RVU_BLOCK_ADDR_NIX0 :
     413                 :            :                         RVU_BLOCK_ADDR_NIX1;
     414                 :            :                 blkaddr = RVU_BLOCK_ADDR_NIX0;
     415                 :            :         }
     416                 :          0 :         return blkaddr;
     417                 :            : }
     418                 :            : 
     419                 :            : int
     420                 :          0 : roc_nix_dev_init(struct roc_nix *roc_nix)
     421                 :            : {
     422                 :            :         enum roc_nix_rss_reta_sz reta_sz;
     423                 :            :         struct plt_pci_device *pci_dev;
     424                 :            :         struct roc_nix_list *nix_list;
     425                 :            :         uint16_t max_sqb_count;
     426                 :            :         uint64_t blkaddr;
     427                 :            :         struct dev *dev;
     428                 :            :         struct nix *nix;
     429                 :            :         int rc;
     430                 :            : 
     431   [ #  #  #  # ]:          0 :         if (roc_nix == NULL || roc_nix->pci_dev == NULL)
     432                 :            :                 return NIX_ERR_PARAM;
     433                 :            : 
     434                 :          0 :         reta_sz = roc_nix->reta_sz;
     435   [ #  #  #  # ]:          0 :         if (reta_sz != 0 && reta_sz != 64 && reta_sz != 128 && reta_sz != 256)
     436                 :            :                 return NIX_ERR_PARAM;
     437                 :            : 
     438         [ #  # ]:          0 :         if (reta_sz == 0)
     439                 :            :                 reta_sz = ROC_NIX_RSS_RETA_SZ_64;
     440                 :            : 
     441                 :          0 :         max_sqb_count = roc_nix->max_sqb_count;
     442                 :          0 :         max_sqb_count = PLT_MIN(max_sqb_count, NIX_MAX_SQB);
     443                 :          0 :         max_sqb_count = PLT_MAX(max_sqb_count, NIX_MIN_SQB);
     444                 :          0 :         roc_nix->max_sqb_count = max_sqb_count;
     445                 :            : 
     446                 :            :         PLT_STATIC_ASSERT(sizeof(struct nix) <= ROC_NIX_MEM_SZ);
     447                 :            :         nix = roc_nix_to_nix_priv(roc_nix);
     448                 :            :         pci_dev = roc_nix->pci_dev;
     449                 :          0 :         dev = &nix->dev;
     450                 :            : 
     451                 :          0 :         nix_list = roc_idev_nix_list_get();
     452         [ #  # ]:          0 :         if (nix_list == NULL)
     453                 :            :                 return -EINVAL;
     454                 :            : 
     455                 :          0 :         TAILQ_INSERT_TAIL(nix_list, roc_nix, next);
     456                 :            : 
     457         [ #  # ]:          0 :         if (nix->dev.drv_inited)
     458                 :            :                 return 0;
     459                 :            : 
     460         [ #  # ]:          0 :         if (dev->mbox_active)
     461                 :          0 :                 goto skip_dev_init;
     462                 :            : 
     463                 :            :         memset(nix, 0, sizeof(*nix));
     464                 :            : 
     465                 :            :         /* Since 0 is a valid BPID, use -1 to represent invalid value. */
     466                 :          0 :         memset(nix->bpid, -1, sizeof(nix->bpid));
     467                 :            : 
     468                 :            :         /* Initialize device  */
     469                 :          0 :         rc = dev_init(dev, pci_dev);
     470         [ #  # ]:          0 :         if (rc) {
     471                 :          0 :                 plt_err("Failed to init roc device");
     472                 :          0 :                 goto fail;
     473                 :            :         }
     474                 :            : 
     475                 :          0 : skip_dev_init:
     476                 :          0 :         dev->roc_nix = roc_nix;
     477                 :            : 
     478                 :          0 :         nix->lmt_base = dev->lmt_base;
     479                 :            :         /* Expose base LMT line address for
     480                 :            :          * "Per Core LMT line" mode.
     481                 :            :          */
     482                 :          0 :         roc_nix->lmt_base = dev->lmt_base;
     483                 :            : 
     484                 :            :         /* Attach NIX LF */
     485                 :          0 :         rc = nix_lf_attach(dev);
     486         [ #  # ]:          0 :         if (rc)
     487                 :          0 :                 goto dev_fini;
     488                 :            : 
     489                 :          0 :         blkaddr = nix_get_blkaddr(dev);
     490                 :          0 :         nix->is_nix1 = (blkaddr == RVU_BLOCK_ADDR_NIX1);
     491                 :            : 
     492                 :            :         /* Calculating base address based on which NIX block LF
     493                 :            :          * is attached to.
     494                 :            :          */
     495                 :          0 :         nix->base = dev->bar2 + (blkaddr << 20);
     496                 :            : 
     497                 :            :         /* Get NIX MSIX offset */
     498                 :          0 :         rc = nix_lf_get_msix_offset(dev, nix);
     499         [ #  # ]:          0 :         if (rc)
     500                 :          0 :                 goto lf_detach;
     501                 :            : 
     502                 :            :         /* Update nix context */
     503                 :            :         sdp_lbk_id_update(pci_dev, nix);
     504                 :          0 :         nix->pci_dev = pci_dev;
     505                 :          0 :         nix->reta_sz = reta_sz;
     506                 :          0 :         nix->mtu = roc_nix_max_pkt_len(roc_nix);
     507                 :          0 :         nix->dmac_flt_idx = -1;
     508                 :            : 
     509                 :            :         /* Register error and ras interrupts */
     510                 :          0 :         rc = nix_register_irqs(nix);
     511         [ #  # ]:          0 :         if (rc)
     512                 :          0 :                 goto lf_detach;
     513                 :            : 
     514                 :          0 :         rc = nix_tm_conf_init(roc_nix);
     515         [ #  # ]:          0 :         if (rc)
     516                 :          0 :                 goto unregister_irqs;
     517                 :            : 
     518                 :            :         /* Get NIX HW info */
     519                 :          0 :         roc_nix_get_hw_info(roc_nix);
     520                 :          0 :         nix->dev.drv_inited = true;
     521                 :            : 
     522                 :          0 :         return 0;
     523                 :            : unregister_irqs:
     524                 :          0 :         nix_unregister_irqs(nix);
     525                 :          0 : lf_detach:
     526                 :          0 :         nix_lf_detach(nix);
     527                 :          0 : dev_fini:
     528                 :          0 :         rc |= dev_fini(dev, pci_dev);
     529                 :          0 : fail:
     530                 :          0 :         nix_tel_node_del(roc_nix);
     531                 :          0 :         return rc;
     532                 :            : }
     533                 :            : 
     534                 :            : int
     535         [ #  # ]:          0 : roc_nix_dev_fini(struct roc_nix *roc_nix)
     536                 :            : {
     537                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     538                 :            :         int rc = 0;
     539                 :            : 
     540                 :            :         if (nix == NULL)
     541                 :            :                 return NIX_ERR_PARAM;
     542                 :            : 
     543         [ #  # ]:          0 :         if (!nix->dev.drv_inited)
     544                 :          0 :                 goto fini;
     545                 :            : 
     546                 :          0 :         nix_tm_conf_fini(roc_nix);
     547                 :          0 :         nix_unregister_irqs(nix);
     548                 :            : 
     549                 :          0 :         rc = nix_lf_detach(nix);
     550                 :          0 :         nix->dev.drv_inited = false;
     551                 :          0 : fini:
     552                 :          0 :         rc |= dev_fini(&nix->dev, nix->pci_dev);
     553                 :            :         return rc;
     554                 :            : }
     555                 :            : 
     556                 :            : int
     557                 :          0 : roc_nix_max_rep_count(struct roc_nix *roc_nix)
     558                 :            : {
     559                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     560                 :            :         struct dev *dev = &nix->dev;
     561                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     562                 :            :         struct get_rep_cnt_rsp *rsp;
     563                 :            :         struct msg_req *req;
     564                 :            :         int rc, i;
     565                 :            : 
     566                 :          0 :         req = mbox_alloc_msg_get_rep_cnt(mbox);
     567         [ #  # ]:          0 :         if (!req) {
     568                 :            :                 rc = -ENOSPC;
     569                 :          0 :                 goto exit;
     570                 :            :         }
     571                 :            : 
     572                 :          0 :         req->hdr.pcifunc = roc_nix_get_pf_func(roc_nix);
     573                 :            : 
     574                 :            :         rc = mbox_process_msg(mbox, (void *)&rsp);
     575         [ #  # ]:          0 :         if (rc)
     576                 :          0 :                 goto exit;
     577                 :            : 
     578                 :          0 :         roc_nix->rep_cnt = rsp->rep_cnt;
     579         [ #  # ]:          0 :         for (i = 0; i < rsp->rep_cnt; i++)
     580                 :          0 :                 roc_nix->rep_pfvf_map[i] = rsp->rep_pfvf_map[i];
     581                 :            : 
     582                 :          0 : exit:
     583                 :            :         mbox_put(mbox);
     584                 :          0 :         return rc;
     585                 :            : }

Generated by: LCOV version 1.14