LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_sso.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 659 0.0 %
Date: 2025-03-01 20:23:48 Functions: 0 40 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 320 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                 :            : #define SSO_XAQ_CACHE_CNT (0x3)
       9                 :            : #define SSO_XAQ_RSVD_CNT  (0x4)
      10                 :            : #define SSO_XAQ_SLACK     (16)
      11                 :            : 
      12                 :            : /* Private functions. */
      13                 :            : int
      14                 :          0 : sso_lf_alloc(struct dev *dev, enum sso_lf_type lf_type, uint16_t nb_lf,
      15                 :            :              void **rsp)
      16                 :            : {
      17                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      18                 :            :         int rc = -ENOSPC;
      19                 :            : 
      20         [ #  # ]:          0 :         if (!nb_lf) {
      21                 :            :                 mbox_put(mbox);
      22                 :          0 :                 return 0;
      23                 :            :         }
      24                 :            : 
      25      [ #  #  # ]:          0 :         switch (lf_type) {
      26                 :          0 :         case SSO_LF_TYPE_HWS: {
      27                 :            :                 struct ssow_lf_alloc_req *req;
      28                 :            : 
      29                 :          0 :                 req = mbox_alloc_msg_ssow_lf_alloc(mbox);
      30         [ #  # ]:          0 :                 if (req == NULL)
      31                 :          0 :                         goto exit;
      32                 :          0 :                 req->hws = nb_lf;
      33                 :          0 :         } break;
      34                 :          0 :         case SSO_LF_TYPE_HWGRP: {
      35                 :            :                 struct sso_lf_alloc_req *req;
      36                 :            : 
      37                 :          0 :                 req = mbox_alloc_msg_sso_lf_alloc(mbox);
      38         [ #  # ]:          0 :                 if (req == NULL)
      39                 :          0 :                         goto exit;
      40                 :          0 :                 req->hwgrps = nb_lf;
      41                 :          0 :         } break;
      42                 :            :         default:
      43                 :            :                 break;
      44                 :            :         }
      45                 :            : 
      46                 :            :         rc = mbox_process_msg(mbox, rsp);
      47         [ #  # ]:          0 :         if (rc) {
      48                 :            :                 rc = -EIO;
      49                 :          0 :                 goto exit;
      50                 :            :         }
      51                 :            : 
      52                 :            :         rc = 0;
      53                 :          0 : exit:
      54                 :            :         mbox_put(mbox);
      55                 :          0 :         return rc;
      56                 :            : }
      57                 :            : 
      58                 :            : int
      59                 :          0 : sso_lf_free(struct dev *dev, enum sso_lf_type lf_type, uint16_t nb_lf)
      60                 :            : {
      61                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
      62                 :            :         int rc = -ENOSPC;
      63                 :            : 
      64         [ #  # ]:          0 :         if (!nb_lf) {
      65                 :            :                 mbox_put(mbox);
      66                 :          0 :                 return 0;
      67                 :            :         }
      68                 :            : 
      69      [ #  #  # ]:          0 :         switch (lf_type) {
      70                 :          0 :         case SSO_LF_TYPE_HWS: {
      71                 :            :                 struct ssow_lf_free_req *req;
      72                 :            : 
      73                 :          0 :                 req = mbox_alloc_msg_ssow_lf_free(mbox);
      74         [ #  # ]:          0 :                 if (req == NULL)
      75                 :          0 :                         goto exit;
      76                 :          0 :                 req->hws = nb_lf;
      77                 :          0 :         } break;
      78                 :          0 :         case SSO_LF_TYPE_HWGRP: {
      79                 :            :                 struct sso_lf_free_req *req;
      80                 :            : 
      81                 :          0 :                 req = mbox_alloc_msg_sso_lf_free(mbox);
      82         [ #  # ]:          0 :                 if (req == NULL)
      83                 :          0 :                         goto exit;
      84                 :          0 :                 req->hwgrps = nb_lf;
      85                 :          0 :         } break;
      86                 :            :         default:
      87                 :            :                 break;
      88                 :            :         }
      89                 :            : 
      90                 :          0 :         rc = mbox_process(mbox);
      91         [ #  # ]:          0 :         if (rc) {
      92                 :            :                 rc = -EIO;
      93                 :          0 :                 goto exit;
      94                 :            :         }
      95                 :            : 
      96                 :            :         rc = 0;
      97                 :          0 : exit:
      98                 :            :         mbox_put(mbox);
      99                 :          0 :         return rc;
     100                 :            : }
     101                 :            : 
     102                 :            : static int
     103                 :          0 : sso_rsrc_attach(struct roc_sso *roc_sso, enum sso_lf_type lf_type,
     104                 :            :                 uint16_t nb_lf)
     105                 :            : {
     106                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     107                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     108                 :            :         struct rsrc_attach_req *req;
     109                 :            :         int rc = -ENOSPC;
     110                 :            : 
     111         [ #  # ]:          0 :         if (!nb_lf) {
     112                 :            :                 mbox_put(mbox);
     113                 :          0 :                 return 0;
     114                 :            :         }
     115                 :            : 
     116                 :          0 :         req = mbox_alloc_msg_attach_resources(mbox);
     117         [ #  # ]:          0 :         if (req == NULL)
     118                 :          0 :                 goto exit;
     119      [ #  #  # ]:          0 :         switch (lf_type) {
     120                 :          0 :         case SSO_LF_TYPE_HWS:
     121                 :          0 :                 req->ssow = nb_lf;
     122                 :          0 :                 break;
     123                 :          0 :         case SSO_LF_TYPE_HWGRP:
     124                 :          0 :                 req->sso = nb_lf;
     125                 :          0 :                 break;
     126                 :          0 :         default:
     127                 :            :                 rc = SSO_ERR_PARAM;
     128                 :          0 :                 goto exit;
     129                 :            :         }
     130                 :            : 
     131                 :          0 :         req->modify = true;
     132         [ #  # ]:          0 :         if (mbox_process(mbox)) {
     133                 :            :                 rc = -EIO;
     134                 :          0 :                 goto exit;
     135                 :            :         }
     136                 :            : 
     137                 :            :         rc = 0;
     138                 :          0 : exit:
     139                 :            :         mbox_put(mbox);
     140                 :          0 :         return rc;
     141                 :            : }
     142                 :            : 
     143                 :            : static int
     144                 :          0 : sso_rsrc_detach(struct roc_sso *roc_sso, enum sso_lf_type lf_type)
     145                 :            : {
     146                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     147                 :            :         struct rsrc_detach_req *req;
     148                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     149                 :            :         int rc = -ENOSPC;
     150                 :            : 
     151                 :          0 :         req = mbox_alloc_msg_detach_resources(mbox);
     152         [ #  # ]:          0 :         if (req == NULL)
     153                 :          0 :                 goto exit;
     154      [ #  #  # ]:          0 :         switch (lf_type) {
     155                 :          0 :         case SSO_LF_TYPE_HWS:
     156                 :          0 :                 req->ssow = true;
     157                 :          0 :                 break;
     158                 :          0 :         case SSO_LF_TYPE_HWGRP:
     159                 :          0 :                 req->sso = true;
     160                 :          0 :                 break;
     161                 :          0 :         default:
     162                 :            :                 rc = SSO_ERR_PARAM;
     163                 :          0 :                 goto exit;
     164                 :            :         }
     165                 :            : 
     166                 :          0 :         req->partial = true;
     167         [ #  # ]:          0 :         if (mbox_process(mbox)) {
     168                 :            :                 rc = -EIO;
     169                 :          0 :                 goto exit;
     170                 :            :         }
     171                 :            : 
     172                 :            :         rc = 0;
     173                 :          0 : exit:
     174                 :            :         mbox_put(mbox);
     175                 :          0 :         return rc;
     176                 :            : }
     177                 :            : 
     178                 :            : static int
     179                 :          0 : sso_rsrc_get(struct roc_sso *roc_sso)
     180                 :            : {
     181                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     182                 :            :         struct free_rsrcs_rsp *rsrc_cnt;
     183                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     184                 :            :         int rc;
     185                 :            : 
     186                 :          0 :         mbox_alloc_msg_free_rsrc_cnt(mbox);
     187                 :            :         rc = mbox_process_msg(mbox, (void **)&rsrc_cnt);
     188         [ #  # ]:          0 :         if (rc) {
     189                 :          0 :                 plt_err("Failed to get free resource count");
     190                 :            :                 rc = -EIO;
     191                 :          0 :                 goto exit;
     192                 :            :         }
     193                 :            : 
     194         [ #  # ]:          0 :         roc_sso->max_hwgrp = PLT_MIN(rsrc_cnt->sso, roc_sso->feat.hwgrps_per_pf);
     195                 :          0 :         roc_sso->max_hws = rsrc_cnt->ssow;
     196                 :            : 
     197                 :            :         rc = 0;
     198                 :          0 : exit:
     199                 :            :         mbox_put(mbox);
     200                 :          0 :         return rc;
     201                 :            : }
     202                 :            : 
     203                 :            : static int
     204                 :          0 : sso_hw_info_get(struct roc_sso *roc_sso)
     205                 :            : {
     206                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     207                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     208                 :            :         struct sso_hw_info *rsp;
     209                 :            :         int rc;
     210                 :            : 
     211                 :          0 :         mbox_alloc_msg_sso_get_hw_info(mbox);
     212                 :            :         rc = mbox_process_msg(mbox, (void **)&rsp);
     213         [ #  # ]:          0 :         if (rc && rc != MBOX_MSG_INVALID) {
     214                 :          0 :                 plt_err("Failed to get SSO HW info");
     215                 :            :                 rc = -EIO;
     216                 :          0 :                 goto exit;
     217                 :            :         }
     218                 :            : 
     219         [ #  # ]:          0 :         if (rc == MBOX_MSG_INVALID) {
     220                 :          0 :                 roc_sso->feat.hwgrps_per_pf = ROC_SSO_MAX_HWGRP_PER_PF;
     221                 :            :         } else {
     222                 :          0 :                 mbox_memcpy(&roc_sso->feat, &rsp->feat, sizeof(roc_sso->feat));
     223                 :            : 
     224         [ #  # ]:          0 :                 if (!roc_sso->feat.hwgrps_per_pf)
     225                 :          0 :                         roc_sso->feat.hwgrps_per_pf = ROC_SSO_MAX_HWGRP_PER_PF;
     226                 :            :         }
     227                 :            : 
     228                 :            :         rc = 0;
     229                 :          0 : exit:
     230                 :            :         mbox_put(mbox);
     231                 :          0 :         return rc;
     232                 :            : }
     233                 :            : 
     234                 :            : void
     235                 :          0 : sso_hws_link_modify(uint8_t hws, uintptr_t base, struct plt_bitmap *bmp, uint16_t hwgrp[],
     236                 :            :                     uint16_t n, uint8_t set, uint16_t enable)
     237                 :            : {
     238                 :            :         uint64_t reg;
     239                 :            :         int i, j, k;
     240                 :            : 
     241                 :            :         i = 0;
     242         [ #  # ]:          0 :         while (n) {
     243                 :          0 :                 uint64_t mask[4] = {
     244                 :            :                         0x8000,
     245                 :            :                         0x8000,
     246                 :            :                         0x8000,
     247                 :            :                         0x8000,
     248                 :            :                 };
     249                 :            : 
     250                 :          0 :                 k = n % 4;
     251         [ #  # ]:          0 :                 k = k ? k : 4;
     252         [ #  # ]:          0 :                 for (j = 0; j < k; j++) {
     253                 :          0 :                         mask[j] = hwgrp[i + j] | (uint32_t)set << 12 | enable << 14;
     254         [ #  # ]:          0 :                         if (bmp) {
     255         [ #  # ]:          0 :                                 enable ? plt_bitmap_set(bmp, hwgrp[i + j]) :
     256                 :          0 :                                          plt_bitmap_clear(bmp, hwgrp[i + j]);
     257                 :            :                         }
     258                 :          0 :                         plt_sso_dbg("HWS %d Linked to HWGRP %d", hws,
     259                 :            :                                     hwgrp[i + j]);
     260                 :            :                 }
     261                 :            : 
     262                 :          0 :                 n -= j;
     263                 :          0 :                 i += j;
     264                 :          0 :                 reg = mask[0] | mask[1] << 16 | mask[2] << 32 | mask[3] << 48;
     265                 :          0 :                 plt_write64(reg, base + SSOW_LF_GWS_GRPMSK_CHG);
     266                 :            :         }
     267                 :          0 : }
     268                 :            : 
     269                 :            : static int
     270                 :          0 : sso_hws_link_modify_af(struct dev *dev, uint8_t hws, struct plt_bitmap *bmp, uint16_t hwgrp[],
     271                 :            :                        uint16_t n, uint8_t set, uint16_t enable)
     272                 :            : {
     273                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     274                 :            :         struct ssow_chng_mship *req;
     275                 :            :         int rc, i;
     276                 :            : 
     277                 :          0 :         req = mbox_alloc_msg_ssow_chng_mship(mbox);
     278         [ #  # ]:          0 :         if (req == NULL) {
     279                 :          0 :                 rc = mbox_process(mbox);
     280         [ #  # ]:          0 :                 if (rc) {
     281                 :            :                         mbox_put(mbox);
     282                 :          0 :                         return -EIO;
     283                 :            :                 }
     284                 :          0 :                 req = mbox_alloc_msg_ssow_chng_mship(mbox);
     285         [ #  # ]:          0 :                 if (req == NULL) {
     286                 :            :                         mbox_put(mbox);
     287                 :          0 :                         return -ENOSPC;
     288                 :            :                 }
     289                 :            :         }
     290                 :          0 :         req->enable = enable;
     291                 :          0 :         req->set = set;
     292                 :          0 :         req->hws = hws;
     293                 :          0 :         req->nb_hwgrps = n;
     294         [ #  # ]:          0 :         for (i = 0; i < n; i++)
     295                 :          0 :                 req->hwgrps[i] = hwgrp[i];
     296                 :          0 :         rc = mbox_process(mbox);
     297                 :            :         mbox_put(mbox);
     298         [ #  # ]:          0 :         if (rc == MBOX_MSG_INVALID)
     299                 :            :                 return rc;
     300         [ #  # ]:          0 :         if (rc)
     301                 :            :                 return -EIO;
     302                 :            : 
     303         [ #  # ]:          0 :         for (i = 0; i < n; i++)
     304         [ #  # ]:          0 :                 enable ? plt_bitmap_set(bmp, hwgrp[i]) :
     305                 :          0 :                          plt_bitmap_clear(bmp, hwgrp[i]);
     306                 :            : 
     307                 :            :         return 0;
     308                 :            : }
     309                 :            : 
     310                 :            : static int
     311                 :          0 : sso_msix_fill(struct roc_sso *roc_sso, uint16_t nb_hws, uint16_t nb_hwgrp)
     312                 :            : {
     313                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     314                 :            :         struct msix_offset_rsp *rsp;
     315                 :            :         struct dev *dev = &sso->dev;
     316                 :            :         int i, rc;
     317                 :            : 
     318                 :          0 :         mbox_alloc_msg_msix_offset(mbox_get(dev->mbox));
     319                 :          0 :         rc = mbox_process_msg(dev->mbox, (void **)&rsp);
     320         [ #  # ]:          0 :         if (rc) {
     321                 :            :                 rc = -EIO;
     322                 :          0 :                 goto exit;
     323                 :            :         }
     324                 :            : 
     325         [ #  # ]:          0 :         for (i = 0; i < nb_hws; i++)
     326                 :          0 :                 sso->hws_msix_offset[i] = rsp->ssow_msixoff[i];
     327         [ #  # ]:          0 :         for (i = 0; i < nb_hwgrp; i++)
     328                 :          0 :                 sso->hwgrp_msix_offset[i] = rsp->sso_msixoff[i];
     329                 :            : 
     330                 :            :         rc = 0;
     331                 :          0 : exit:
     332                 :          0 :         mbox_put(dev->mbox);
     333                 :          0 :         return rc;
     334                 :            : }
     335                 :            : 
     336                 :            : /* Public Functions. */
     337                 :            : uintptr_t
     338                 :          0 : roc_sso_hws_base_get(struct roc_sso *roc_sso, uint8_t hws)
     339                 :            : {
     340                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     341                 :            : 
     342                 :          0 :         return dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
     343                 :            : }
     344                 :            : 
     345                 :            : uintptr_t
     346                 :          0 : roc_sso_hwgrp_base_get(struct roc_sso *roc_sso, uint16_t hwgrp)
     347                 :            : {
     348                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     349                 :            : 
     350                 :          0 :         return dev->bar2 + (RVU_BLOCK_ADDR_SSO << 20 | hwgrp << 12);
     351                 :            : }
     352                 :            : 
     353                 :            : uint16_t
     354                 :          0 : roc_sso_pf_func_get(void)
     355                 :            : {
     356                 :          0 :         return idev_sso_pffunc_get();
     357                 :            : }
     358                 :            : 
     359                 :            : uint64_t
     360                 :          0 : roc_sso_ns_to_gw(uint64_t base, uint64_t ns)
     361                 :            : {
     362                 :            :         uint64_t current_us;
     363                 :            : 
     364                 :          0 :         current_us = plt_read64(base + SSOW_LF_GWS_NW_TIM);
     365                 :            :         /* From HRM, table 14-19:
     366                 :            :          * The SSOW_LF_GWS_NW_TIM[NW_TIM] period is specified in n-1 notation.
     367                 :            :          */
     368                 :            :         current_us += 1;
     369                 :            : 
     370                 :            :         /* From HRM, table 14-1:
     371                 :            :          * SSOW_LF_GWS_NW_TIM[NW_TIM] specifies the minimum timeout. The SSO
     372                 :            :          * hardware times out a GET_WORK request within 1 usec of the minimum
     373                 :            :          * timeout specified by SSOW_LF_GWS_NW_TIM[NW_TIM].
     374                 :            :          */
     375                 :          0 :         current_us += 1;
     376                 :          0 :         return PLT_MAX(1UL, (uint64_t)PLT_DIV_CEIL(ns, (current_us * 1E3)));
     377                 :            : }
     378                 :            : 
     379                 :            : int
     380                 :          0 : roc_sso_hws_link(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[], uint16_t nb_hwgrp,
     381                 :            :                  uint8_t set, bool use_mbox)
     382                 :            : {
     383                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     384                 :          0 :         struct dev *dev = &sso->dev;
     385                 :            :         uintptr_t base;
     386                 :            :         int rc;
     387                 :            : 
     388         [ #  # ]:          0 :         if (!nb_hwgrp)
     389                 :            :                 return 0;
     390                 :            : 
     391   [ #  #  #  # ]:          0 :         if (use_mbox && roc_model_is_cn10k()) {
     392                 :          0 :                 rc = sso_hws_link_modify_af(dev, hws, sso->link_map[hws], hwgrp, nb_hwgrp, set, 1);
     393         [ #  # ]:          0 :                 if (rc == MBOX_MSG_INVALID)
     394                 :          0 :                         goto lf_access;
     395         [ #  # ]:          0 :                 if (rc < 0)
     396                 :            :                         return 0;
     397                 :          0 :                 goto done;
     398                 :            :         }
     399                 :          0 : lf_access:
     400                 :          0 :         base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
     401                 :          0 :         sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 1);
     402                 :          0 : done:
     403                 :          0 :         return nb_hwgrp;
     404                 :            : }
     405                 :            : 
     406                 :            : int
     407                 :          0 : roc_sso_hws_unlink(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[],
     408                 :            :                    uint16_t nb_hwgrp, uint8_t set, bool use_mbox)
     409                 :            : {
     410                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     411                 :          0 :         struct dev *dev = &sso->dev;
     412                 :            :         uintptr_t base;
     413                 :            :         int rc;
     414                 :            : 
     415         [ #  # ]:          0 :         if (!nb_hwgrp)
     416                 :            :                 return 0;
     417                 :            : 
     418   [ #  #  #  # ]:          0 :         if (use_mbox && roc_model_is_cn10k()) {
     419                 :          0 :                 rc = sso_hws_link_modify_af(dev, hws, sso->link_map[hws], hwgrp, nb_hwgrp, set, 0);
     420         [ #  # ]:          0 :                 if (rc == MBOX_MSG_INVALID)
     421                 :          0 :                         goto lf_access;
     422         [ #  # ]:          0 :                 if (rc < 0)
     423                 :            :                         return 0;
     424                 :          0 :                 goto done;
     425                 :            :         }
     426                 :          0 : lf_access:
     427                 :          0 :         base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
     428                 :          0 :         sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 0);
     429                 :          0 : done:
     430                 :          0 :         return nb_hwgrp;
     431                 :            : }
     432                 :            : 
     433                 :            : int
     434                 :          0 : roc_sso_hws_stats_get(struct roc_sso *roc_sso, uint8_t hws,
     435                 :            :                       struct roc_sso_hws_stats *stats)
     436                 :            : {
     437                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     438                 :            :         struct sso_hws_stats *req_rsp;
     439                 :            :         struct dev *dev = &sso->dev;
     440                 :            :         struct mbox *mbox;
     441                 :            :         int rc;
     442                 :            : 
     443                 :          0 :         mbox = mbox_get(dev->mbox);
     444                 :          0 :         req_rsp = (struct sso_hws_stats *)mbox_alloc_msg_sso_hws_get_stats(
     445                 :            :                 mbox);
     446         [ #  # ]:          0 :         if (req_rsp == NULL) {
     447                 :          0 :                 rc = mbox_process(mbox);
     448         [ #  # ]:          0 :                 if (rc) {
     449                 :            :                         rc = -EIO;
     450                 :          0 :                         goto fail;
     451                 :            :                 }
     452                 :          0 :                 req_rsp = (struct sso_hws_stats *)
     453                 :          0 :                         mbox_alloc_msg_sso_hws_get_stats(mbox);
     454         [ #  # ]:          0 :                 if (req_rsp == NULL) {
     455                 :            :                         rc = -ENOSPC;
     456                 :          0 :                         goto fail;
     457                 :            :                 }
     458                 :            :         }
     459                 :          0 :         req_rsp->hws = hws;
     460                 :            :         rc = mbox_process_msg(mbox, (void **)&req_rsp);
     461         [ #  # ]:          0 :         if (rc) {
     462                 :            :                 rc = -EIO;
     463                 :          0 :                 goto fail;
     464                 :            :         }
     465                 :            : 
     466                 :          0 :         stats->arbitration = req_rsp->arbitration;
     467                 :          0 : fail:
     468                 :            :         mbox_put(mbox);
     469                 :          0 :         return rc;
     470                 :            : }
     471                 :            : 
     472                 :            : void
     473                 :          0 : roc_sso_hws_gwc_invalidate(struct roc_sso *roc_sso, uint8_t *hws,
     474                 :            :                            uint8_t nb_hws)
     475                 :            : {
     476                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     477                 :            :         struct ssow_lf_inv_req *req;
     478                 :            :         struct dev *dev = &sso->dev;
     479                 :            :         struct mbox *mbox;
     480                 :            :         int i;
     481                 :            : 
     482         [ #  # ]:          0 :         if (!nb_hws)
     483                 :            :                 return;
     484                 :            : 
     485                 :          0 :         mbox = mbox_get(dev->mbox);
     486                 :          0 :         req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
     487         [ #  # ]:          0 :         if (req == NULL) {
     488                 :          0 :                 mbox_process(mbox);
     489                 :          0 :                 req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
     490         [ #  # ]:          0 :                 if (req == NULL) {
     491                 :            :                         mbox_put(mbox);
     492                 :          0 :                         return;
     493                 :            :                 }
     494                 :            :         }
     495                 :          0 :         req->hdr.ver = SSOW_INVAL_SELECTIVE_VER;
     496                 :          0 :         req->nb_hws = nb_hws;
     497         [ #  # ]:          0 :         for (i = 0; i < nb_hws; i++)
     498                 :          0 :                 req->hws[i] = hws[i];
     499                 :          0 :         mbox_process(mbox);
     500                 :            :         mbox_put(mbox);
     501                 :            : }
     502                 :            : 
     503                 :            : static void
     504                 :          0 : sso_agq_op_wait(struct roc_sso *roc_sso, uint16_t hwgrp)
     505                 :            : {
     506                 :            :         uint64_t reg;
     507                 :            : 
     508                 :          0 :         reg = plt_read64(roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
     509         [ #  # ]:          0 :         while (reg & BIT_ULL(2)) {
     510                 :          0 :                 plt_delay_us(100);
     511                 :          0 :                 reg = plt_read64(roc_sso_hwgrp_base_get(roc_sso, hwgrp) +
     512                 :            :                                  SSO_LF_GGRP_AGGR_CTX_INSTOP);
     513                 :            :         }
     514                 :          0 : }
     515                 :            : 
     516                 :            : int
     517                 :          0 : roc_sso_hwgrp_agq_alloc(struct roc_sso *roc_sso, uint16_t hwgrp, struct roc_sso_agq_data *data)
     518                 :            : {
     519                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     520                 :            :         struct sso_aggr_setconfig *req;
     521                 :            :         struct sso_agq_ctx *ctx;
     522                 :            :         uint32_t cnt, off;
     523                 :            :         struct mbox *mbox;
     524                 :            :         uintptr_t ptr;
     525                 :            :         uint64_t reg;
     526                 :            :         int rc;
     527                 :            : 
     528         [ #  # ]:          0 :         if (sso->agg_mem[hwgrp] == 0) {
     529                 :          0 :                 mbox = mbox_get(sso->dev.mbox);
     530                 :          0 :                 req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
     531         [ #  # ]:          0 :                 if (req == NULL) {
     532                 :          0 :                         mbox_process(mbox);
     533                 :          0 :                         req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
     534         [ #  # ]:          0 :                         if (req == NULL) {
     535                 :          0 :                                 plt_err("Failed to allocate AGQ config mbox.");
     536                 :            :                                 mbox_put(mbox);
     537                 :          0 :                                 return -EIO;
     538                 :            :                         }
     539                 :            :                 }
     540                 :            : 
     541                 :          0 :                 req->hwgrp = hwgrp;
     542                 :          0 :                 req->npa_pf_func = idev_npa_pffunc_get();
     543                 :          0 :                 rc = mbox_process(mbox);
     544         [ #  # ]:          0 :                 if (rc < 0) {
     545                 :          0 :                         plt_err("Failed to set HWGRP AGQ config rc=%d", rc);
     546                 :            :                         mbox_put(mbox);
     547                 :          0 :                         return rc;
     548                 :            :                 }
     549                 :            : 
     550                 :            :                 mbox_put(mbox);
     551                 :            : 
     552                 :          0 :                 sso->agg_mem[hwgrp] =
     553                 :          0 :                         (uintptr_t)plt_zmalloc(SSO_AGGR_MIN_CTX * sizeof(struct sso_agq_ctx),
     554                 :            :                                                roc_model_optimal_align_sz());
     555         [ #  # ]:          0 :                 if (sso->agg_mem[hwgrp] == 0)
     556                 :            :                         return -ENOMEM;
     557                 :          0 :                 sso->agg_cnt[hwgrp] = SSO_AGGR_MIN_CTX;
     558                 :          0 :                 sso->agg_used[hwgrp] = 0;
     559                 :            :                 plt_wmb();
     560                 :          0 :                 plt_write64(sso->agg_mem[hwgrp],
     561                 :            :                             roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_BASE);
     562                 :            :                 reg = (plt_log2_u32(SSO_AGGR_MIN_CTX) - 6) << 16;
     563                 :            :                 reg |= (SSO_AGGR_DEF_TMO << 4) | 1;
     564                 :          0 :                 plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
     565                 :            :         }
     566                 :            : 
     567         [ #  # ]:          0 :         if (sso->agg_cnt[hwgrp] >= SSO_AGGR_MAX_CTX)
     568                 :            :                 return -ENOSPC;
     569                 :            : 
     570         [ #  # ]:          0 :         if (sso->agg_cnt[hwgrp] == sso->agg_used[hwgrp]) {
     571                 :          0 :                 ptr = sso->agg_mem[hwgrp];
     572         [ #  # ]:          0 :                 cnt = sso->agg_cnt[hwgrp] << 1;
     573                 :          0 :                 sso->agg_mem[hwgrp] = (uintptr_t)plt_zmalloc(cnt * sizeof(struct sso_agq_ctx),
     574                 :            :                                                              roc_model_optimal_align_sz());
     575         [ #  # ]:          0 :                 if (sso->agg_mem[hwgrp] == 0) {
     576                 :          0 :                         sso->agg_mem[hwgrp] = ptr;
     577                 :          0 :                         return -ENOMEM;
     578                 :            :                 }
     579                 :            : 
     580                 :          0 :                 memcpy((void *)sso->agg_mem[hwgrp], (void *)ptr,
     581                 :          0 :                        sso->agg_cnt[hwgrp] * sizeof(struct sso_agq_ctx));
     582                 :            :                 plt_wmb();
     583                 :          0 :                 sso_agq_op_wait(roc_sso, hwgrp);
     584                 :            :                 /* Base address has changed, evict old entries. */
     585                 :          0 :                 plt_write64(sso->agg_mem[hwgrp],
     586                 :            :                             roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_BASE);
     587         [ #  # ]:          0 :                 reg = plt_read64(roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
     588         [ #  # ]:          0 :                 reg &= ~GENMASK_ULL(19, 16);
     589                 :          0 :                 reg |= (uint64_t)(plt_log2_u32(cnt) - 6) << 16;
     590                 :          0 :                 plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
     591                 :            :                 reg = SSO_LF_AGGR_INSTOP_GLOBAL_EVICT << 4;
     592                 :          0 :                 plt_write64(reg,
     593                 :            :                             roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
     594                 :          0 :                 sso_agq_op_wait(roc_sso, hwgrp);
     595                 :          0 :                 plt_free((void *)ptr);
     596                 :            : 
     597                 :          0 :                 sso->agg_cnt[hwgrp] = cnt;
     598                 :          0 :                 off = sso->agg_used[hwgrp];
     599                 :            :         } else {
     600                 :          0 :                 ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
     601         [ #  # ]:          0 :                 for (cnt = 0; cnt < sso->agg_cnt[hwgrp]; cnt++) {
     602         [ #  # ]:          0 :                         if (!ctx[cnt].ena)
     603                 :            :                                 break;
     604                 :            :                 }
     605         [ #  # ]:          0 :                 if (cnt == sso->agg_cnt[hwgrp])
     606                 :            :                         return -EINVAL;
     607                 :            :                 off = cnt;
     608                 :            :         }
     609                 :            : 
     610                 :          0 :         ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
     611                 :          0 :         ctx += off;
     612                 :          0 :         ctx->ena = 1;
     613                 :          0 :         ctx->tt = data->tt;
     614                 :          0 :         ctx->tag = data->tag;
     615                 :          0 :         ctx->swqe_tag = data->stag;
     616                 :          0 :         ctx->cnt_ena = data->cnt_ena;
     617                 :          0 :         ctx->xqe_type = data->xqe_type;
     618                 :          0 :         ctx->vtimewait = data->vwqe_wait_tmo;
     619                 :          0 :         ctx->vwqe_aura = data->vwqe_aura;
     620                 :          0 :         ctx->max_vsize_exp = data->vwqe_max_sz_exp - 2;
     621                 :            : 
     622                 :            :         plt_wmb();
     623                 :          0 :         sso->agg_used[hwgrp]++;
     624                 :            : 
     625                 :          0 :         return 0;
     626                 :            : }
     627                 :            : 
     628                 :            : void
     629                 :          0 : roc_sso_hwgrp_agq_free(struct roc_sso *roc_sso, uint16_t hwgrp, uint32_t agq_id)
     630                 :            : {
     631                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     632                 :            :         struct sso_agq_ctx *ctx;
     633                 :            :         uint64_t reg;
     634                 :            : 
     635                 :          0 :         ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
     636                 :          0 :         ctx += agq_id;
     637                 :            : 
     638         [ #  # ]:          0 :         if (!ctx->ena)
     639                 :            :                 return;
     640                 :            : 
     641                 :            :         reg = SSO_LF_AGGR_INSTOP_FLUSH << 4;
     642                 :          0 :         reg |= (uint64_t)(agq_id << 8);
     643                 :            : 
     644                 :          0 :         plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
     645                 :          0 :         sso_agq_op_wait(roc_sso, hwgrp);
     646                 :            : 
     647                 :            :         memset(ctx, 0, sizeof(struct sso_agq_ctx));
     648                 :            :         plt_wmb();
     649                 :          0 :         sso->agg_used[hwgrp]--;
     650                 :            : 
     651                 :            :         /* Flush the context from CTX Cache */
     652                 :            :         reg = SSO_LF_AGGR_INSTOP_EVICT << 4;
     653                 :          0 :         reg |= (uint64_t)(agq_id << 8);
     654                 :            : 
     655                 :          0 :         plt_write64(reg, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_INSTOP);
     656                 :          0 :         sso_agq_op_wait(roc_sso, hwgrp);
     657                 :            : }
     658                 :            : 
     659                 :            : void
     660                 :          0 : roc_sso_hwgrp_agq_release(struct roc_sso *roc_sso, uint16_t hwgrp)
     661                 :            : {
     662                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     663                 :            :         struct sso_aggr_setconfig *req;
     664                 :            :         struct sso_agq_ctx *ctx;
     665                 :            :         struct mbox *mbox;
     666                 :            :         uint32_t cnt;
     667                 :            :         int rc;
     668                 :            : 
     669         [ #  # ]:          0 :         if (!roc_sso->feat.eva_present)
     670                 :            :                 return;
     671                 :            : 
     672                 :          0 :         plt_write64(0, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CFG);
     673                 :          0 :         ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
     674         [ #  # ]:          0 :         for (cnt = 0; cnt < sso->agg_cnt[hwgrp]; cnt++) {
     675         [ #  # ]:          0 :                 if (!ctx[cnt].ena)
     676                 :          0 :                         continue;
     677                 :          0 :                 roc_sso_hwgrp_agq_free(roc_sso, hwgrp, cnt);
     678                 :            :         }
     679                 :            : 
     680                 :          0 :         plt_write64(0, roc_sso_hwgrp_base_get(roc_sso, hwgrp) + SSO_LF_GGRP_AGGR_CTX_BASE);
     681                 :          0 :         plt_free((void *)sso->agg_mem[hwgrp]);
     682                 :          0 :         sso->agg_mem[hwgrp] = 0;
     683                 :          0 :         sso->agg_cnt[hwgrp] = 0;
     684                 :          0 :         sso->agg_used[hwgrp] = 0;
     685                 :            : 
     686                 :          0 :         mbox = mbox_get(sso->dev.mbox);
     687                 :          0 :         req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
     688         [ #  # ]:          0 :         if (req == NULL) {
     689                 :          0 :                 mbox_process(mbox);
     690                 :          0 :                 req = mbox_alloc_msg_sso_aggr_setconfig(mbox);
     691         [ #  # ]:          0 :                 if (req == NULL) {
     692                 :          0 :                         plt_err("Failed to allocate AGQ config mbox.");
     693                 :            :                         mbox_put(mbox);
     694                 :          0 :                         return;
     695                 :            :                 }
     696                 :            :         }
     697                 :            : 
     698                 :          0 :         req->hwgrp = hwgrp;
     699                 :          0 :         req->npa_pf_func = 0;
     700                 :          0 :         rc = mbox_process(mbox);
     701         [ #  # ]:          0 :         if (rc < 0)
     702                 :          0 :                 plt_err("Failed to set HWGRP AGQ config rc=%d", rc);
     703                 :            :         mbox_put(mbox);
     704                 :            : }
     705                 :            : 
     706                 :            : uint32_t
     707                 :          0 : roc_sso_hwgrp_agq_from_tag(struct roc_sso *roc_sso, uint16_t hwgrp, uint32_t tag_mask,
     708                 :            :                            uint8_t xqe_type)
     709                 :            : {
     710                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     711                 :            :         struct sso_agq_ctx *ctx;
     712                 :            :         uint32_t i;
     713                 :            : 
     714                 :            :         plt_rmb();
     715                 :          0 :         ctx = (struct sso_agq_ctx *)sso->agg_mem[hwgrp];
     716         [ #  # ]:          0 :         for (i = 0; i < sso->agg_used[hwgrp]; i++) {
     717         [ #  # ]:          0 :                 if (!ctx[i].ena)
     718                 :          0 :                         continue;
     719   [ #  #  #  # ]:          0 :                 if (ctx[i].tag == tag_mask && ctx[i].xqe_type == xqe_type)
     720                 :          0 :                         return i;
     721                 :            :         }
     722                 :            : 
     723                 :            :         return UINT32_MAX;
     724                 :            : }
     725                 :            : 
     726                 :            : int
     727                 :          0 : roc_sso_hwgrp_stats_get(struct roc_sso *roc_sso, uint16_t hwgrp, struct roc_sso_hwgrp_stats *stats)
     728                 :            : {
     729                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     730                 :            :         struct sso_grp_stats *req_rsp;
     731                 :            :         struct dev *dev = &sso->dev;
     732                 :            :         struct mbox *mbox;
     733                 :            :         int rc;
     734                 :            : 
     735                 :          0 :         mbox = mbox_get(dev->mbox);
     736                 :          0 :         req_rsp = (struct sso_grp_stats *)mbox_alloc_msg_sso_grp_get_stats(
     737                 :            :                 mbox);
     738         [ #  # ]:          0 :         if (req_rsp == NULL) {
     739                 :          0 :                 rc = mbox_process(mbox);
     740         [ #  # ]:          0 :                 if (rc) {
     741                 :            :                         rc = -EIO;
     742                 :          0 :                         goto fail;
     743                 :            :                 }
     744                 :          0 :                 req_rsp = (struct sso_grp_stats *)
     745                 :          0 :                         mbox_alloc_msg_sso_grp_get_stats(mbox);
     746         [ #  # ]:          0 :                 if (req_rsp == NULL) {
     747                 :            :                         rc = -ENOSPC;
     748                 :          0 :                         goto fail;
     749                 :            :                 }
     750                 :            :         }
     751                 :          0 :         req_rsp->grp = hwgrp;
     752                 :            :         rc = mbox_process_msg(mbox, (void **)&req_rsp);
     753         [ #  # ]:          0 :         if (rc) {
     754                 :            :                 rc = -EIO;
     755                 :          0 :                 goto fail;
     756                 :            :         }
     757                 :            : 
     758                 :          0 :         stats->aw_status = req_rsp->aw_status;
     759                 :          0 :         stats->dq_pc = req_rsp->dq_pc;
     760                 :          0 :         stats->ds_pc = req_rsp->ds_pc;
     761                 :          0 :         stats->ext_pc = req_rsp->ext_pc;
     762                 :          0 :         stats->page_cnt = req_rsp->page_cnt;
     763                 :          0 :         stats->ts_pc = req_rsp->ts_pc;
     764                 :          0 :         stats->wa_pc = req_rsp->wa_pc;
     765                 :          0 :         stats->ws_pc = req_rsp->ws_pc;
     766                 :            : 
     767                 :          0 : fail:
     768                 :            :         mbox_put(mbox);
     769                 :          0 :         return rc;
     770                 :            : }
     771                 :            : 
     772                 :            : int
     773                 :          0 : roc_sso_hwgrp_hws_link_status(struct roc_sso *roc_sso, uint8_t hws,
     774                 :            :                               uint16_t hwgrp)
     775                 :            : {
     776                 :            :         struct sso *sso;
     777                 :            : 
     778                 :            :         sso = roc_sso_to_sso_priv(roc_sso);
     779                 :          0 :         return plt_bitmap_get(sso->link_map[hws], hwgrp);
     780                 :            : }
     781                 :            : 
     782                 :            : int
     783                 :          0 : roc_sso_hwgrp_qos_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_qos *qos, uint16_t nb_qos)
     784                 :            : {
     785                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     786                 :            :         struct dev *dev = &sso->dev;
     787                 :            :         struct sso_grp_qos_cfg *req;
     788                 :            :         struct mbox *mbox;
     789                 :            :         int i, rc;
     790                 :            : 
     791         [ #  # ]:          0 :         if (!nb_qos)
     792                 :            :                 return 0;
     793                 :            : 
     794                 :          0 :         mbox = mbox_get(dev->mbox);
     795         [ #  # ]:          0 :         for (i = 0; i < nb_qos; i++) {
     796                 :          0 :                 uint8_t iaq_prcnt = qos[i].iaq_prcnt;
     797                 :          0 :                 uint8_t taq_prcnt = qos[i].taq_prcnt;
     798                 :            : 
     799                 :          0 :                 req = mbox_alloc_msg_sso_grp_qos_config(mbox);
     800         [ #  # ]:          0 :                 if (req == NULL) {
     801                 :          0 :                         rc = mbox_process(mbox);
     802         [ #  # ]:          0 :                         if (rc) {
     803                 :            :                                 rc = -EIO;
     804                 :          0 :                                 goto fail;
     805                 :            :                         }
     806                 :            : 
     807                 :          0 :                         req = mbox_alloc_msg_sso_grp_qos_config(mbox);
     808         [ #  # ]:          0 :                         if (req == NULL) {
     809                 :            :                                 rc = -ENOSPC;
     810                 :          0 :                                 goto fail;
     811                 :            :                         }
     812                 :            :                 }
     813                 :          0 :                 req->grp = qos[i].hwgrp;
     814         [ #  # ]:          0 :                 req->iaq_thr = (SSO_HWGRP_IAQ_MAX_THR_MASK *
     815                 :          0 :                                 (iaq_prcnt ? iaq_prcnt : 100)) /
     816                 :            :                                100;
     817         [ #  # ]:          0 :                 req->taq_thr = (SSO_HWGRP_TAQ_MAX_THR_MASK *
     818                 :          0 :                                 (taq_prcnt ? taq_prcnt : 100)) /
     819                 :            :                                100;
     820                 :            :         }
     821                 :            : 
     822                 :          0 :         rc = mbox_process(mbox);
     823         [ #  # ]:          0 :         if (rc)
     824                 :            :                 rc = -EIO;
     825                 :          0 : fail:
     826                 :            :         mbox_put(mbox);
     827                 :          0 :         return rc;
     828                 :            : }
     829                 :            : 
     830                 :            : int
     831                 :          0 : sso_hwgrp_init_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
     832                 :            :                         uint32_t nb_xae, uint32_t xae_waes,
     833                 :            :                         uint32_t xaq_buf_size, uint16_t nb_hwgrp)
     834                 :            : {
     835                 :            :         struct npa_pool_s pool;
     836                 :            :         struct npa_aura_s aura;
     837                 :            :         plt_iova_t iova;
     838                 :            :         uint32_t i;
     839                 :            :         int rc;
     840                 :            : 
     841         [ #  # ]:          0 :         if (xaq->mem != NULL) {
     842                 :          0 :                 rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
     843         [ #  # ]:          0 :                 if (rc < 0) {
     844                 :          0 :                         plt_err("Failed to release XAQ %d", rc);
     845                 :          0 :                         return rc;
     846                 :            :                 }
     847                 :          0 :                 roc_npa_pool_destroy(xaq->aura_handle);
     848                 :          0 :                 plt_free(xaq->fc);
     849                 :          0 :                 plt_free(xaq->mem);
     850                 :            :                 memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
     851                 :            :         }
     852                 :            : 
     853                 :          0 :         xaq->fc = plt_zmalloc(ROC_ALIGN, ROC_ALIGN);
     854         [ #  # ]:          0 :         if (xaq->fc == NULL) {
     855                 :          0 :                 plt_err("Failed to allocate XAQ FC");
     856                 :            :                 rc = -ENOMEM;
     857                 :          0 :                 goto fail;
     858                 :            :         }
     859                 :            : 
     860                 :          0 :         xaq->nb_xae = nb_xae;
     861                 :            : 
     862                 :            :         /** SSO will reserve up to 0x4 XAQ buffers per group when GetWork engine
     863                 :            :          * is inactive and it might prefetch an additional 0x3 buffers due to
     864                 :            :          * pipelining.
     865                 :            :          */
     866                 :          0 :         xaq->nb_xaq = (SSO_XAQ_CACHE_CNT * nb_hwgrp);
     867                 :          0 :         xaq->nb_xaq += (SSO_XAQ_RSVD_CNT * nb_hwgrp);
     868                 :          0 :         xaq->nb_xaq += PLT_MAX(1 + ((xaq->nb_xae - 1) / xae_waes), xaq->nb_xaq);
     869                 :          0 :         xaq->nb_xaq += SSO_XAQ_SLACK;
     870                 :            : 
     871                 :          0 :         xaq->mem = plt_zmalloc(xaq_buf_size * xaq->nb_xaq, xaq_buf_size);
     872         [ #  # ]:          0 :         if (xaq->mem == NULL) {
     873                 :          0 :                 plt_err("Failed to allocate XAQ mem");
     874                 :            :                 rc = -ENOMEM;
     875                 :          0 :                 goto free_fc;
     876                 :            :         }
     877                 :            : 
     878                 :            :         memset(&pool, 0, sizeof(struct npa_pool_s));
     879                 :          0 :         pool.nat_align = 1;
     880                 :            : 
     881                 :            :         memset(&aura, 0, sizeof(aura));
     882                 :          0 :         aura.fc_ena = 1;
     883                 :          0 :         aura.fc_addr = (uint64_t)xaq->fc;
     884                 :            :         aura.fc_hyst_bits = 0; /* Store count on all updates */
     885                 :          0 :         rc = roc_npa_pool_create(&xaq->aura_handle, xaq_buf_size, xaq->nb_xaq,
     886                 :            :                                  &aura, &pool, 0);
     887         [ #  # ]:          0 :         if (rc) {
     888                 :          0 :                 plt_err("Failed to create XAQ pool");
     889                 :          0 :                 goto npa_fail;
     890                 :            :         }
     891                 :            : 
     892                 :          0 :         iova = (uint64_t)xaq->mem;
     893         [ #  # ]:          0 :         for (i = 0; i < xaq->nb_xaq; i++) {
     894                 :          0 :                 roc_npa_aura_op_free(xaq->aura_handle, 0, iova);
     895                 :          0 :                 iova += xaq_buf_size;
     896                 :            :         }
     897                 :          0 :         roc_npa_pool_op_range_set(xaq->aura_handle, (uint64_t)xaq->mem, iova);
     898                 :            : 
     899                 :          0 :         if (roc_npa_aura_op_available_wait(xaq->aura_handle, xaq->nb_xaq, 0) !=
     900         [ #  # ]:          0 :             xaq->nb_xaq) {
     901                 :          0 :                 plt_err("Failed to free all pointers to the pool");
     902                 :            :                 rc = -ENOMEM;
     903                 :          0 :                 goto npa_fill_fail;
     904                 :            :         }
     905                 :            : 
     906                 :            :         /* When SW does addwork (enqueue) check if there is space in XAQ by
     907                 :            :          * comparing fc_addr above against the xaq_lmt calculated below.
     908                 :            :          * There should be a minimum headroom of 7 XAQs per HWGRP for SSO
     909                 :            :          * to request XAQ to cache them even before enqueue is called.
     910                 :            :          */
     911                 :          0 :         xaq->xaq_lmt = xaq->nb_xaq - (nb_hwgrp * SSO_XAQ_CACHE_CNT) - SSO_XAQ_SLACK;
     912                 :            : 
     913                 :          0 :         return 0;
     914                 :            : npa_fill_fail:
     915                 :          0 :         roc_npa_pool_destroy(xaq->aura_handle);
     916                 :          0 : npa_fail:
     917                 :          0 :         plt_free(xaq->mem);
     918                 :          0 : free_fc:
     919                 :          0 :         plt_free(xaq->fc);
     920                 :          0 : fail:
     921                 :            :         memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
     922                 :          0 :         return rc;
     923                 :            : }
     924                 :            : 
     925                 :            : int
     926                 :          0 : roc_sso_hwgrp_init_xaq_aura(struct roc_sso *roc_sso, uint32_t nb_xae)
     927                 :            : {
     928                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     929                 :          0 :         struct dev *dev = &sso->dev;
     930                 :            :         int rc;
     931                 :            : 
     932                 :          0 :         rc = sso_hwgrp_init_xaq_aura(dev, &roc_sso->xaq, nb_xae, roc_sso->feat.xaq_wq_entries,
     933                 :          0 :                                      roc_sso->feat.xaq_buf_size, roc_sso->nb_hwgrp);
     934                 :          0 :         return rc;
     935                 :            : }
     936                 :            : 
     937                 :            : int
     938                 :          0 : sso_hwgrp_free_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
     939                 :            :                         uint16_t nb_hwgrp)
     940                 :            : {
     941                 :            :         int rc;
     942                 :            : 
     943         [ #  # ]:          0 :         if (xaq->mem != NULL) {
     944         [ #  # ]:          0 :                 if (nb_hwgrp) {
     945                 :          0 :                         rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
     946         [ #  # ]:          0 :                         if (rc < 0) {
     947                 :          0 :                                 plt_err("Failed to release XAQ %d", rc);
     948                 :          0 :                                 return rc;
     949                 :            :                         }
     950                 :            :                 }
     951                 :          0 :                 roc_npa_pool_destroy(xaq->aura_handle);
     952                 :          0 :                 plt_free(xaq->fc);
     953                 :          0 :                 plt_free(xaq->mem);
     954                 :            :         }
     955                 :            :         memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
     956                 :            : 
     957                 :          0 :         return 0;
     958                 :            : }
     959                 :            : 
     960                 :            : int
     961                 :          0 : roc_sso_hwgrp_free_xaq_aura(struct roc_sso *roc_sso, uint16_t nb_hwgrp)
     962                 :            : {
     963                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     964                 :          0 :         struct dev *dev = &sso->dev;
     965                 :            :         int rc;
     966                 :            : 
     967                 :          0 :         rc = sso_hwgrp_free_xaq_aura(dev, &roc_sso->xaq, nb_hwgrp);
     968                 :          0 :         return rc;
     969                 :            : }
     970                 :            : 
     971                 :            : int
     972                 :          0 : sso_hwgrp_alloc_xaq(struct dev *dev, uint32_t npa_aura_id, uint16_t hwgrps)
     973                 :            : {
     974                 :            :         struct sso_hw_setconfig *req;
     975                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     976                 :            :         int rc = -ENOSPC;
     977                 :            : 
     978                 :          0 :         req = mbox_alloc_msg_sso_hw_setconfig(mbox);
     979         [ #  # ]:          0 :         if (req == NULL)
     980                 :          0 :                 goto exit;
     981                 :          0 :         req->npa_pf_func = idev_npa_pffunc_get();
     982                 :          0 :         req->npa_aura_id = npa_aura_id;
     983                 :          0 :         req->hwgrps = hwgrps;
     984                 :            : 
     985         [ #  # ]:          0 :         if (mbox_process(dev->mbox)) {
     986                 :            :                 rc = -EIO;
     987                 :          0 :                 goto exit;
     988                 :            :         }
     989                 :            : 
     990                 :            :         rc = 0;
     991                 :          0 : exit:
     992                 :            :         mbox_put(mbox);
     993                 :          0 :         return rc;
     994                 :            : }
     995                 :            : 
     996                 :            : int
     997                 :          0 : roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
     998                 :            :                         uint16_t hwgrps)
     999                 :            : {
    1000                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1001                 :          0 :         struct dev *dev = &sso->dev;
    1002                 :            :         int rc;
    1003                 :            : 
    1004                 :          0 :         rc = sso_hwgrp_alloc_xaq(dev, npa_aura_id, hwgrps);
    1005                 :          0 :         return rc;
    1006                 :            : }
    1007                 :            : 
    1008                 :            : int
    1009                 :          0 : sso_hwgrp_release_xaq(struct dev *dev, uint16_t hwgrps)
    1010                 :            : {
    1011                 :            :         struct sso_hw_xaq_release *req;
    1012                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
    1013                 :            :         int rc;
    1014                 :            : 
    1015                 :          0 :         req = mbox_alloc_msg_sso_hw_release_xaq_aura(mbox);
    1016         [ #  # ]:          0 :         if (req == NULL) {
    1017                 :            :                 rc =  -EINVAL;
    1018                 :          0 :                 goto exit;
    1019                 :            :         }
    1020                 :          0 :         req->hwgrps = hwgrps;
    1021                 :            : 
    1022         [ #  # ]:          0 :         if (mbox_process(mbox)) {
    1023                 :            :                 rc = -EIO;
    1024                 :          0 :                 goto exit;
    1025                 :            :         }
    1026                 :            : 
    1027                 :            :         rc = 0;
    1028                 :          0 : exit:
    1029                 :            :         mbox_put(mbox);
    1030                 :          0 :         return rc;
    1031                 :            : }
    1032                 :            : 
    1033                 :            : int
    1034                 :          0 : roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
    1035                 :            : {
    1036                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1037                 :          0 :         struct dev *dev = &sso->dev;
    1038                 :            :         int rc;
    1039                 :            : 
    1040         [ #  # ]:          0 :         if (!hwgrps)
    1041                 :            :                 return 0;
    1042                 :            : 
    1043                 :          0 :         rc = sso_hwgrp_release_xaq(dev, hwgrps);
    1044                 :          0 :         return rc;
    1045                 :            : }
    1046                 :            : 
    1047                 :            : int
    1048                 :          0 : roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso, uint16_t hwgrp,
    1049                 :            :                            uint8_t weight, uint8_t affinity, uint8_t priority)
    1050                 :            : {
    1051                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1052                 :            :         struct dev *dev = &sso->dev;
    1053                 :            :         struct sso_grp_priority *req;
    1054                 :            :         struct mbox *mbox;
    1055                 :            :         int rc = -ENOSPC;
    1056                 :            : 
    1057                 :          0 :         mbox = mbox_get(dev->mbox);
    1058                 :          0 :         req = mbox_alloc_msg_sso_grp_set_priority(mbox);
    1059         [ #  # ]:          0 :         if (req == NULL)
    1060                 :          0 :                 goto fail;
    1061                 :          0 :         req->grp = hwgrp;
    1062                 :          0 :         req->weight = weight;
    1063                 :          0 :         req->affinity = affinity;
    1064                 :          0 :         req->priority = priority;
    1065                 :            : 
    1066                 :          0 :         rc = mbox_process(mbox);
    1067         [ #  # ]:          0 :         if (rc) {
    1068                 :            :                 rc = -EIO;
    1069                 :          0 :                 goto fail;
    1070                 :            :         }
    1071                 :            :         mbox_put(mbox);
    1072                 :          0 :         plt_sso_dbg("HWGRP %d weight %d affinity %d priority %d", hwgrp, weight,
    1073                 :            :                     affinity, priority);
    1074                 :            : 
    1075                 :          0 :         return 0;
    1076                 :          0 : fail:
    1077                 :            :         mbox_put(mbox);
    1078                 :          0 :         return rc;
    1079                 :            : }
    1080                 :            : 
    1081                 :            : static int
    1082                 :          0 : sso_update_msix_vec_count(struct roc_sso *roc_sso, uint16_t sso_vec_cnt)
    1083                 :            : {
    1084                 :          0 :         struct plt_pci_device *pci_dev = roc_sso->pci_dev;
    1085                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1086                 :            :         uint16_t mbox_vec_cnt, npa_vec_cnt;
    1087                 :          0 :         struct dev *dev = &sso->dev;
    1088                 :            :         struct idev_cfg *idev;
    1089                 :            :         int rc;
    1090                 :            : 
    1091                 :          0 :         idev = idev_get_cfg();
    1092         [ #  # ]:          0 :         if (idev == NULL)
    1093                 :            :                 return -ENODEV;
    1094                 :            : 
    1095         [ #  # ]:          0 :         if (roc_model_is_cn20k())
    1096                 :            :                 mbox_vec_cnt = RVU_MBOX_PF_INT_VEC_AFPF_MBOX + 1;
    1097                 :            :         else
    1098                 :            :                 mbox_vec_cnt = RVU_PF_INT_VEC_AFPF_MBOX + 1;
    1099                 :            : 
    1100                 :            :         /* Allocating vectors for the first time */
    1101         [ #  # ]:          0 :         if (plt_intr_max_intr_get(pci_dev->intr_handle) == 0) {
    1102         [ #  # ]:          0 :                 npa_vec_cnt = idev->npa_refcnt ? 0 : NPA_LF_INT_VEC_POISON + 1;
    1103                 :          0 :                 return dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt);
    1104                 :            :         }
    1105                 :            : 
    1106                 :            :         /* Before re-configuring unregister irqs */
    1107         [ #  # ]:          0 :         npa_vec_cnt = (dev->npa.pci_dev == pci_dev) ? NPA_LF_INT_VEC_POISON + 1 : 0;
    1108                 :            :         if (npa_vec_cnt)
    1109                 :          0 :                 npa_unregister_irqs(&dev->npa);
    1110                 :            : 
    1111                 :          0 :         dev_mbox_unregister_irq(pci_dev, dev);
    1112         [ #  # ]:          0 :         if (!dev_is_vf(dev))
    1113                 :          0 :                 dev_vf_flr_unregister_irqs(pci_dev, dev);
    1114                 :            : 
    1115                 :            :         /* Re-configure to include SSO vectors */
    1116                 :          0 :         rc = dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt + sso_vec_cnt);
    1117         [ #  # ]:          0 :         if (rc)
    1118                 :            :                 return rc;
    1119                 :            : 
    1120                 :          0 :         rc = dev_mbox_register_irq(pci_dev, dev);
    1121         [ #  # ]:          0 :         if (rc)
    1122                 :            :                 return rc;
    1123                 :            : 
    1124         [ #  # ]:          0 :         if (!dev_is_vf(dev)) {
    1125                 :          0 :                 rc = dev_vf_flr_register_irqs(pci_dev, dev);
    1126         [ #  # ]:          0 :                 if (rc)
    1127                 :            :                         return rc;
    1128                 :            :         }
    1129                 :            : 
    1130         [ #  # ]:          0 :         if (npa_vec_cnt)
    1131                 :          0 :                 rc = npa_register_irqs(&dev->npa);
    1132                 :            : 
    1133                 :            :         return rc;
    1134                 :            : }
    1135                 :            : 
    1136                 :            : int
    1137                 :          0 : roc_sso_hwgrp_stash_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_stash *stash,
    1138                 :            :                            uint16_t nb_stash)
    1139                 :            : {
    1140                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1141                 :            :         struct sso_grp_stash_cfg *req;
    1142                 :            :         struct dev *dev = &sso->dev;
    1143                 :            :         struct mbox *mbox;
    1144                 :            :         int i, rc;
    1145                 :            : 
    1146         [ #  # ]:          0 :         if (!nb_stash)
    1147                 :            :                 return 0;
    1148                 :            : 
    1149                 :          0 :         mbox = mbox_get(dev->mbox);
    1150         [ #  # ]:          0 :         for (i = 0; i < nb_stash; i++) {
    1151                 :          0 :                 req = mbox_alloc_msg_sso_grp_stash_config(mbox);
    1152         [ #  # ]:          0 :                 if (req == NULL) {
    1153                 :          0 :                         rc = mbox_process(mbox);
    1154         [ #  # ]:          0 :                         if (rc) {
    1155                 :            :                                 rc = -EIO;
    1156                 :          0 :                                 goto fail;
    1157                 :            :                         }
    1158                 :            : 
    1159                 :          0 :                         req = mbox_alloc_msg_sso_grp_stash_config(mbox);
    1160         [ #  # ]:          0 :                         if (req == NULL) {
    1161                 :            :                                 rc = -ENOSPC;
    1162                 :          0 :                                 goto fail;
    1163                 :            :                         }
    1164                 :            :                 }
    1165                 :          0 :                 req->ena = true;
    1166                 :          0 :                 req->grp = stash[i].hwgrp;
    1167                 :          0 :                 req->offset = stash[i].stash_offset;
    1168                 :          0 :                 req->num_linesm1 = stash[i].stash_count - 1;
    1169                 :            :         }
    1170                 :            : 
    1171                 :          0 :         rc = mbox_process(mbox);
    1172         [ #  # ]:          0 :         if (rc)
    1173                 :            :                 rc = -EIO;
    1174                 :          0 : fail:
    1175                 :            :         mbox_put(mbox);
    1176                 :          0 :         return rc;
    1177                 :            : }
    1178                 :            : 
    1179                 :            : int
    1180                 :          0 : roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp, uint16_t nb_tim_lfs)
    1181                 :            : {
    1182                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1183                 :            :         struct sso_lf_alloc_rsp *rsp_hwgrp;
    1184                 :            :         uint16_t sso_vec_cnt, free_tim_lfs;
    1185                 :            :         int rc;
    1186                 :            : 
    1187   [ #  #  #  # ]:          0 :         if (!nb_hwgrp || roc_sso->max_hwgrp < nb_hwgrp)
    1188                 :            :                 return -ENOENT;
    1189   [ #  #  #  # ]:          0 :         if (!nb_hws || roc_sso->max_hws < nb_hws)
    1190                 :            :                 return -ENOENT;
    1191                 :            : 
    1192                 :          0 :         rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWS, nb_hws);
    1193         [ #  # ]:          0 :         if (rc < 0) {
    1194                 :          0 :                 plt_err("Unable to attach SSO HWS LFs");
    1195                 :          0 :                 goto fail;
    1196                 :            :         }
    1197                 :            : 
    1198                 :          0 :         rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWGRP, nb_hwgrp);
    1199         [ #  # ]:          0 :         if (rc < 0) {
    1200                 :          0 :                 plt_err("Unable to attach SSO HWGRP LFs");
    1201                 :          0 :                 goto hwgrp_atch_fail;
    1202                 :            :         }
    1203                 :            : 
    1204                 :          0 :         rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWS, nb_hws, NULL);
    1205         [ #  # ]:          0 :         if (rc < 0) {
    1206                 :          0 :                 plt_err("Unable to alloc SSO HWS LFs");
    1207                 :          0 :                 goto hws_alloc_fail;
    1208                 :            :         }
    1209                 :            : 
    1210                 :          0 :         rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp,
    1211                 :            :                           (void **)&rsp_hwgrp);
    1212         [ #  # ]:          0 :         if (rc < 0) {
    1213                 :          0 :                 plt_err("Unable to alloc SSO HWGRP Lfs");
    1214                 :          0 :                 goto hwgrp_alloc_fail;
    1215                 :            :         }
    1216                 :            : 
    1217   [ #  #  #  #  :          0 :         if (!roc_sso->feat.xaq_buf_size || !roc_sso->feat.xaq_wq_entries || !roc_sso->feat.iue) {
                   #  # ]
    1218                 :          0 :                 roc_sso->feat.xaq_buf_size = rsp_hwgrp->xaq_buf_size;
    1219                 :          0 :                 roc_sso->feat.xaq_wq_entries = rsp_hwgrp->xaq_wq_entries;
    1220                 :          0 :                 roc_sso->feat.iue = rsp_hwgrp->in_unit_entries;
    1221                 :            :         }
    1222                 :            : 
    1223                 :          0 :         rc = sso_msix_fill(roc_sso, nb_hws, nb_hwgrp);
    1224         [ #  # ]:          0 :         if (rc < 0) {
    1225                 :          0 :                 plt_err("Unable to get MSIX offsets for SSO LFs");
    1226                 :          0 :                 goto sso_msix_fail;
    1227                 :            :         }
    1228                 :            : 
    1229                 :            :         /* 1 error interrupt per SSO HWS/HWGRP */
    1230                 :          0 :         sso_vec_cnt = nb_hws + nb_hwgrp;
    1231                 :            : 
    1232         [ #  # ]:          0 :         if (sso->dev.roc_tim) {
    1233                 :          0 :                 nb_tim_lfs = ((struct roc_tim *)sso->dev.roc_tim)->nb_lfs;
    1234                 :            :         } else {
    1235                 :          0 :                 rc = tim_free_lf_count_get(&sso->dev, &free_tim_lfs);
    1236         [ #  # ]:          0 :                 if (rc < 0) {
    1237                 :          0 :                         plt_err("Failed to get TIM resource count");
    1238                 :          0 :                         goto sso_msix_fail;
    1239                 :            :                 }
    1240                 :            : 
    1241                 :          0 :                 nb_tim_lfs = PLT_MIN(nb_tim_lfs, free_tim_lfs);
    1242                 :            :         }
    1243                 :            : 
    1244                 :            :         /* 2 error interrupt per TIM LF */
    1245         [ #  # ]:          0 :         if (roc_model_is_cn20k())
    1246                 :          0 :                 sso_vec_cnt += 3 * nb_tim_lfs;
    1247                 :            :         else
    1248                 :          0 :                 sso_vec_cnt += 2 * nb_tim_lfs;
    1249                 :            : 
    1250                 :          0 :         rc = sso_update_msix_vec_count(roc_sso, sso_vec_cnt);
    1251         [ #  # ]:          0 :         if (rc < 0) {
    1252                 :          0 :                 plt_err("Failed to update SSO MSIX vector count");
    1253                 :          0 :                 goto sso_msix_fail;
    1254                 :            :         }
    1255                 :            : 
    1256                 :          0 :         rc = sso_register_irqs_priv(roc_sso, sso->pci_dev->intr_handle, nb_hws,
    1257                 :            :                                     nb_hwgrp);
    1258         [ #  # ]:          0 :         if (rc < 0) {
    1259                 :          0 :                 plt_err("Failed to register SSO LF IRQs");
    1260                 :          0 :                 goto sso_msix_fail;
    1261                 :            :         }
    1262                 :            : 
    1263                 :          0 :         roc_sso->nb_hwgrp = nb_hwgrp;
    1264                 :          0 :         roc_sso->nb_hws = nb_hws;
    1265                 :            : 
    1266                 :          0 :         return 0;
    1267                 :          0 : sso_msix_fail:
    1268                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp);
    1269                 :          0 : hwgrp_alloc_fail:
    1270                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, nb_hws);
    1271                 :          0 : hws_alloc_fail:
    1272                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
    1273                 :          0 : hwgrp_atch_fail:
    1274                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
    1275                 :            : fail:
    1276                 :            :         return rc;
    1277                 :            : }
    1278                 :            : 
    1279                 :            : void
    1280                 :          0 : roc_sso_rsrc_fini(struct roc_sso *roc_sso)
    1281                 :            : {
    1282                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1283                 :            :         uint32_t cnt;
    1284                 :            : 
    1285         [ #  # ]:          0 :         if (!roc_sso->nb_hws && !roc_sso->nb_hwgrp)
    1286                 :            :                 return;
    1287                 :            : 
    1288         [ #  # ]:          0 :         for (cnt = 0; cnt < roc_sso->nb_hwgrp; cnt++)
    1289                 :          0 :                 roc_sso_hwgrp_agq_release(roc_sso, cnt);
    1290                 :            : 
    1291                 :          0 :         sso_unregister_irqs_priv(roc_sso, sso->pci_dev->intr_handle,
    1292                 :          0 :                                  roc_sso->nb_hws, roc_sso->nb_hwgrp);
    1293                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, roc_sso->nb_hws);
    1294                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, roc_sso->nb_hwgrp);
    1295                 :            : 
    1296                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
    1297                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
    1298                 :            : 
    1299                 :          0 :         roc_sso->nb_hwgrp = 0;
    1300                 :          0 :         roc_sso->nb_hws = 0;
    1301                 :            : }
    1302                 :            : 
    1303                 :            : int
    1304                 :          0 : roc_sso_dev_init(struct roc_sso *roc_sso)
    1305                 :            : {
    1306                 :            :         struct plt_pci_device *pci_dev;
    1307                 :            :         uint32_t link_map_sz;
    1308                 :            :         struct sso *sso;
    1309                 :            :         void *link_mem;
    1310                 :            :         int i, rc;
    1311                 :            : 
    1312   [ #  #  #  # ]:          0 :         if (roc_sso == NULL || roc_sso->pci_dev == NULL)
    1313                 :            :                 return SSO_ERR_PARAM;
    1314                 :            : 
    1315                 :            :         PLT_STATIC_ASSERT(sizeof(struct sso) <= ROC_SSO_MEM_SZ);
    1316                 :            :         sso = roc_sso_to_sso_priv(roc_sso);
    1317                 :            :         memset(sso, 0, sizeof(*sso));
    1318                 :            :         pci_dev = roc_sso->pci_dev;
    1319                 :            : 
    1320                 :          0 :         rc = sso_update_msix_vec_count(roc_sso, 0);
    1321         [ #  # ]:          0 :         if (rc < 0) {
    1322                 :          0 :                 plt_err("Failed to set SSO MSIX vector count");
    1323                 :          0 :                 return rc;
    1324                 :            :         }
    1325                 :            : 
    1326                 :          0 :         rc = dev_init(&sso->dev, pci_dev);
    1327         [ #  # ]:          0 :         if (rc < 0) {
    1328                 :          0 :                 plt_err("Failed to init roc device");
    1329                 :          0 :                 goto fail;
    1330                 :            :         }
    1331                 :            : 
    1332                 :          0 :         rc = sso_hw_info_get(roc_sso);
    1333         [ #  # ]:          0 :         if (rc < 0) {
    1334                 :          0 :                 plt_err("Failed to get SSO HW info");
    1335                 :          0 :                 goto fail;
    1336                 :            :         }
    1337                 :            : 
    1338                 :          0 :         rc = sso_rsrc_get(roc_sso);
    1339         [ #  # ]:          0 :         if (rc < 0) {
    1340                 :          0 :                 plt_err("Failed to get SSO resources");
    1341                 :          0 :                 goto rsrc_fail;
    1342                 :            :         }
    1343                 :            :         rc = -ENOMEM;
    1344                 :            : 
    1345         [ #  # ]:          0 :         if (roc_sso->max_hws) {
    1346                 :          0 :                 sso->link_map = plt_zmalloc(
    1347                 :            :                         sizeof(struct plt_bitmap *) * roc_sso->max_hws, 0);
    1348         [ #  # ]:          0 :                 if (sso->link_map == NULL) {
    1349                 :          0 :                         plt_err("Failed to allocate memory for link_map array");
    1350                 :          0 :                         goto rsrc_fail;
    1351                 :            :                 }
    1352                 :            : 
    1353                 :            :                 link_map_sz =
    1354                 :          0 :                         plt_bitmap_get_memory_footprint(roc_sso->max_hwgrp);
    1355                 :          0 :                 sso->link_map_mem =
    1356                 :          0 :                         plt_zmalloc(link_map_sz * roc_sso->max_hws, 0);
    1357         [ #  # ]:          0 :                 if (sso->link_map_mem == NULL) {
    1358                 :          0 :                         plt_err("Failed to get link_map memory");
    1359                 :          0 :                         goto rsrc_fail;
    1360                 :            :                 }
    1361                 :            : 
    1362                 :            :                 link_mem = sso->link_map_mem;
    1363                 :            : 
    1364         [ #  # ]:          0 :                 for (i = 0; i < roc_sso->max_hws; i++) {
    1365                 :          0 :                         sso->link_map[i] = plt_bitmap_init(
    1366                 :          0 :                                 roc_sso->max_hwgrp, link_mem, link_map_sz);
    1367         [ #  # ]:          0 :                         if (sso->link_map[i] == NULL) {
    1368                 :          0 :                                 plt_err("Failed to allocate link map");
    1369                 :          0 :                                 goto link_mem_free;
    1370                 :            :                         }
    1371                 :          0 :                         link_mem = PLT_PTR_ADD(link_mem, link_map_sz);
    1372                 :            :                 }
    1373                 :            :         }
    1374                 :          0 :         idev_sso_pffunc_set(sso->dev.pf_func);
    1375                 :          0 :         idev_sso_set(roc_sso);
    1376                 :          0 :         sso->pci_dev = pci_dev;
    1377                 :          0 :         sso->dev.drv_inited = true;
    1378                 :          0 :         roc_sso->lmt_base = sso->dev.lmt_base;
    1379                 :            : 
    1380                 :          0 :         return 0;
    1381                 :            : link_mem_free:
    1382                 :          0 :         plt_free(sso->link_map_mem);
    1383                 :          0 : rsrc_fail:
    1384                 :          0 :         rc |= dev_fini(&sso->dev, pci_dev);
    1385                 :            : fail:
    1386                 :            :         return rc;
    1387                 :            : }
    1388                 :            : 
    1389                 :            : int
    1390                 :          0 : roc_sso_dev_fini(struct roc_sso *roc_sso)
    1391                 :            : {
    1392                 :            :         struct sso *sso;
    1393                 :            : 
    1394                 :            :         sso = roc_sso_to_sso_priv(roc_sso);
    1395                 :          0 :         sso->dev.drv_inited = false;
    1396                 :            : 
    1397                 :          0 :         return dev_fini(&sso->dev, sso->pci_dev);
    1398                 :            : }

Generated by: LCOV version 1.14