LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_sso.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 519 0.0 %
Date: 2024-04-01 19:00:53 Functions: 0 33 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 244 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\n");
     190                 :            :                 rc = -EIO;
     191                 :          0 :                 goto exit;
     192                 :            :         }
     193                 :            : 
     194                 :          0 :         roc_sso->max_hwgrp = rsrc_cnt->sso;
     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                 :            : void
     204                 :          0 : sso_hws_link_modify(uint8_t hws, uintptr_t base, struct plt_bitmap *bmp, uint16_t hwgrp[],
     205                 :            :                     uint16_t n, uint8_t set, uint16_t enable)
     206                 :            : {
     207                 :            :         uint64_t reg;
     208                 :            :         int i, j, k;
     209                 :            : 
     210                 :            :         i = 0;
     211         [ #  # ]:          0 :         while (n) {
     212                 :          0 :                 uint64_t mask[4] = {
     213                 :            :                         0x8000,
     214                 :            :                         0x8000,
     215                 :            :                         0x8000,
     216                 :            :                         0x8000,
     217                 :            :                 };
     218                 :            : 
     219                 :          0 :                 k = n % 4;
     220         [ #  # ]:          0 :                 k = k ? k : 4;
     221         [ #  # ]:          0 :                 for (j = 0; j < k; j++) {
     222                 :          0 :                         mask[j] = hwgrp[i + j] | (uint32_t)set << 12 | enable << 14;
     223         [ #  # ]:          0 :                         if (bmp) {
     224         [ #  # ]:          0 :                                 enable ? plt_bitmap_set(bmp, hwgrp[i + j]) :
     225                 :          0 :                                          plt_bitmap_clear(bmp, hwgrp[i + j]);
     226                 :            :                         }
     227                 :          0 :                         plt_sso_dbg("HWS %d Linked to HWGRP %d", hws,
     228                 :            :                                     hwgrp[i + j]);
     229                 :            :                 }
     230                 :            : 
     231                 :          0 :                 n -= j;
     232                 :          0 :                 i += j;
     233                 :          0 :                 reg = mask[0] | mask[1] << 16 | mask[2] << 32 | mask[3] << 48;
     234                 :          0 :                 plt_write64(reg, base + SSOW_LF_GWS_GRPMSK_CHG);
     235                 :            :         }
     236                 :          0 : }
     237                 :            : 
     238                 :            : static int
     239                 :          0 : sso_hws_link_modify_af(struct dev *dev, uint8_t hws, struct plt_bitmap *bmp, uint16_t hwgrp[],
     240                 :            :                        uint16_t n, uint8_t set, uint16_t enable)
     241                 :            : {
     242                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     243                 :            :         struct ssow_chng_mship *req;
     244                 :            :         int rc, i;
     245                 :            : 
     246                 :          0 :         req = mbox_alloc_msg_ssow_chng_mship(mbox);
     247         [ #  # ]:          0 :         if (req == NULL) {
     248                 :          0 :                 rc = mbox_process(mbox);
     249         [ #  # ]:          0 :                 if (rc) {
     250                 :            :                         mbox_put(mbox);
     251                 :          0 :                         return -EIO;
     252                 :            :                 }
     253                 :          0 :                 req = mbox_alloc_msg_ssow_chng_mship(mbox);
     254         [ #  # ]:          0 :                 if (req == NULL) {
     255                 :            :                         mbox_put(mbox);
     256                 :          0 :                         return -ENOSPC;
     257                 :            :                 }
     258                 :            :         }
     259                 :          0 :         req->enable = enable;
     260                 :          0 :         req->set = set;
     261                 :          0 :         req->hws = hws;
     262                 :          0 :         req->nb_hwgrps = n;
     263         [ #  # ]:          0 :         for (i = 0; i < n; i++)
     264                 :          0 :                 req->hwgrps[i] = hwgrp[i];
     265                 :          0 :         rc = mbox_process(mbox);
     266                 :            :         mbox_put(mbox);
     267         [ #  # ]:          0 :         if (rc == MBOX_MSG_INVALID)
     268                 :            :                 return rc;
     269         [ #  # ]:          0 :         if (rc)
     270                 :            :                 return -EIO;
     271                 :            : 
     272         [ #  # ]:          0 :         for (i = 0; i < n; i++)
     273         [ #  # ]:          0 :                 enable ? plt_bitmap_set(bmp, hwgrp[i]) :
     274                 :          0 :                          plt_bitmap_clear(bmp, hwgrp[i]);
     275                 :            : 
     276                 :            :         return 0;
     277                 :            : }
     278                 :            : 
     279                 :            : static int
     280                 :          0 : sso_msix_fill(struct roc_sso *roc_sso, uint16_t nb_hws, uint16_t nb_hwgrp)
     281                 :            : {
     282                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     283                 :            :         struct msix_offset_rsp *rsp;
     284                 :            :         struct dev *dev = &sso->dev;
     285                 :            :         int i, rc;
     286                 :            : 
     287                 :          0 :         mbox_alloc_msg_msix_offset(mbox_get(dev->mbox));
     288                 :          0 :         rc = mbox_process_msg(dev->mbox, (void **)&rsp);
     289         [ #  # ]:          0 :         if (rc) {
     290                 :            :                 rc = -EIO;
     291                 :          0 :                 goto exit;
     292                 :            :         }
     293                 :            : 
     294         [ #  # ]:          0 :         for (i = 0; i < nb_hws; i++)
     295                 :          0 :                 sso->hws_msix_offset[i] = rsp->ssow_msixoff[i];
     296         [ #  # ]:          0 :         for (i = 0; i < nb_hwgrp; i++)
     297                 :          0 :                 sso->hwgrp_msix_offset[i] = rsp->sso_msixoff[i];
     298                 :            : 
     299                 :            :         rc = 0;
     300                 :          0 : exit:
     301                 :          0 :         mbox_put(dev->mbox);
     302                 :          0 :         return rc;
     303                 :            : }
     304                 :            : 
     305                 :            : /* Public Functions. */
     306                 :            : uintptr_t
     307                 :          0 : roc_sso_hws_base_get(struct roc_sso *roc_sso, uint8_t hws)
     308                 :            : {
     309                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     310                 :            : 
     311                 :          0 :         return dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
     312                 :            : }
     313                 :            : 
     314                 :            : uintptr_t
     315                 :          0 : roc_sso_hwgrp_base_get(struct roc_sso *roc_sso, uint16_t hwgrp)
     316                 :            : {
     317                 :            :         struct dev *dev = &roc_sso_to_sso_priv(roc_sso)->dev;
     318                 :            : 
     319                 :          0 :         return dev->bar2 + (RVU_BLOCK_ADDR_SSO << 20 | hwgrp << 12);
     320                 :            : }
     321                 :            : 
     322                 :            : uint64_t
     323                 :          0 : roc_sso_ns_to_gw(uint64_t base, uint64_t ns)
     324                 :            : {
     325                 :            :         uint64_t current_us;
     326                 :            : 
     327                 :          0 :         current_us = plt_read64(base + SSOW_LF_GWS_NW_TIM);
     328                 :            :         /* From HRM, table 14-19:
     329                 :            :          * The SSOW_LF_GWS_NW_TIM[NW_TIM] period is specified in n-1 notation.
     330                 :            :          */
     331                 :            :         current_us += 1;
     332                 :            : 
     333                 :            :         /* From HRM, table 14-1:
     334                 :            :          * SSOW_LF_GWS_NW_TIM[NW_TIM] specifies the minimum timeout. The SSO
     335                 :            :          * hardware times out a GET_WORK request within 1 usec of the minimum
     336                 :            :          * timeout specified by SSOW_LF_GWS_NW_TIM[NW_TIM].
     337                 :            :          */
     338                 :          0 :         current_us += 1;
     339                 :          0 :         return PLT_MAX(1UL, (uint64_t)PLT_DIV_CEIL(ns, (current_us * 1E3)));
     340                 :            : }
     341                 :            : 
     342                 :            : int
     343                 :          0 : roc_sso_hws_link(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[], uint16_t nb_hwgrp,
     344                 :            :                  uint8_t set, bool use_mbox)
     345                 :            : {
     346                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     347                 :          0 :         struct dev *dev = &sso->dev;
     348                 :            :         uintptr_t base;
     349                 :            :         int rc;
     350                 :            : 
     351         [ #  # ]:          0 :         if (!nb_hwgrp)
     352                 :            :                 return 0;
     353                 :            : 
     354   [ #  #  #  # ]:          0 :         if (use_mbox && roc_model_is_cn10k()) {
     355                 :          0 :                 rc = sso_hws_link_modify_af(dev, hws, sso->link_map[hws], hwgrp, nb_hwgrp, set, 1);
     356         [ #  # ]:          0 :                 if (rc == MBOX_MSG_INVALID)
     357                 :          0 :                         goto lf_access;
     358         [ #  # ]:          0 :                 if (rc < 0)
     359                 :            :                         return 0;
     360                 :          0 :                 goto done;
     361                 :            :         }
     362                 :          0 : lf_access:
     363                 :          0 :         base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
     364                 :          0 :         sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 1);
     365                 :          0 : done:
     366                 :          0 :         return nb_hwgrp;
     367                 :            : }
     368                 :            : 
     369                 :            : int
     370                 :          0 : roc_sso_hws_unlink(struct roc_sso *roc_sso, uint8_t hws, uint16_t hwgrp[],
     371                 :            :                    uint16_t nb_hwgrp, uint8_t set, bool use_mbox)
     372                 :            : {
     373                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     374                 :          0 :         struct dev *dev = &sso->dev;
     375                 :            :         uintptr_t base;
     376                 :            :         int rc;
     377                 :            : 
     378         [ #  # ]:          0 :         if (!nb_hwgrp)
     379                 :            :                 return 0;
     380                 :            : 
     381   [ #  #  #  # ]:          0 :         if (use_mbox && roc_model_is_cn10k()) {
     382                 :          0 :                 rc = sso_hws_link_modify_af(dev, hws, sso->link_map[hws], hwgrp, nb_hwgrp, set, 0);
     383         [ #  # ]:          0 :                 if (rc == MBOX_MSG_INVALID)
     384                 :          0 :                         goto lf_access;
     385         [ #  # ]:          0 :                 if (rc < 0)
     386                 :            :                         return 0;
     387                 :          0 :                 goto done;
     388                 :            :         }
     389                 :          0 : lf_access:
     390                 :          0 :         base = dev->bar2 + (RVU_BLOCK_ADDR_SSOW << 20 | hws << 12);
     391                 :          0 :         sso_hws_link_modify(hws, base, sso->link_map[hws], hwgrp, nb_hwgrp, set, 0);
     392                 :          0 : done:
     393                 :          0 :         return nb_hwgrp;
     394                 :            : }
     395                 :            : 
     396                 :            : int
     397                 :          0 : roc_sso_hws_stats_get(struct roc_sso *roc_sso, uint8_t hws,
     398                 :            :                       struct roc_sso_hws_stats *stats)
     399                 :            : {
     400                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     401                 :            :         struct sso_hws_stats *req_rsp;
     402                 :            :         struct dev *dev = &sso->dev;
     403                 :            :         struct mbox *mbox;
     404                 :            :         int rc;
     405                 :            : 
     406                 :          0 :         mbox = mbox_get(dev->mbox);
     407                 :          0 :         req_rsp = (struct sso_hws_stats *)mbox_alloc_msg_sso_hws_get_stats(
     408                 :            :                 mbox);
     409         [ #  # ]:          0 :         if (req_rsp == NULL) {
     410                 :          0 :                 rc = mbox_process(mbox);
     411         [ #  # ]:          0 :                 if (rc) {
     412                 :            :                         rc = -EIO;
     413                 :          0 :                         goto fail;
     414                 :            :                 }
     415                 :          0 :                 req_rsp = (struct sso_hws_stats *)
     416                 :          0 :                         mbox_alloc_msg_sso_hws_get_stats(mbox);
     417         [ #  # ]:          0 :                 if (req_rsp == NULL) {
     418                 :            :                         rc = -ENOSPC;
     419                 :          0 :                         goto fail;
     420                 :            :                 }
     421                 :            :         }
     422                 :          0 :         req_rsp->hws = hws;
     423                 :            :         rc = mbox_process_msg(mbox, (void **)&req_rsp);
     424         [ #  # ]:          0 :         if (rc) {
     425                 :            :                 rc = -EIO;
     426                 :          0 :                 goto fail;
     427                 :            :         }
     428                 :            : 
     429                 :          0 :         stats->arbitration = req_rsp->arbitration;
     430                 :          0 : fail:
     431                 :            :         mbox_put(mbox);
     432                 :          0 :         return rc;
     433                 :            : }
     434                 :            : 
     435                 :            : void
     436                 :          0 : roc_sso_hws_gwc_invalidate(struct roc_sso *roc_sso, uint8_t *hws,
     437                 :            :                            uint8_t nb_hws)
     438                 :            : {
     439                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     440                 :            :         struct ssow_lf_inv_req *req;
     441                 :            :         struct dev *dev = &sso->dev;
     442                 :            :         struct mbox *mbox;
     443                 :            :         int i;
     444                 :            : 
     445         [ #  # ]:          0 :         if (!nb_hws)
     446                 :            :                 return;
     447                 :            : 
     448                 :          0 :         mbox = mbox_get(dev->mbox);
     449                 :          0 :         req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
     450         [ #  # ]:          0 :         if (req == NULL) {
     451                 :          0 :                 mbox_process(mbox);
     452                 :          0 :                 req = mbox_alloc_msg_sso_ws_cache_inv(mbox);
     453         [ #  # ]:          0 :                 if (req == NULL) {
     454                 :            :                         mbox_put(mbox);
     455                 :          0 :                         return;
     456                 :            :                 }
     457                 :            :         }
     458                 :          0 :         req->hdr.ver = SSOW_INVAL_SELECTIVE_VER;
     459                 :          0 :         req->nb_hws = nb_hws;
     460         [ #  # ]:          0 :         for (i = 0; i < nb_hws; i++)
     461                 :          0 :                 req->hws[i] = hws[i];
     462                 :          0 :         mbox_process(mbox);
     463                 :            :         mbox_put(mbox);
     464                 :            : }
     465                 :            : 
     466                 :            : int
     467                 :          0 : roc_sso_hwgrp_stats_get(struct roc_sso *roc_sso, uint8_t hwgrp,
     468                 :            :                         struct roc_sso_hwgrp_stats *stats)
     469                 :            : {
     470                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     471                 :            :         struct sso_grp_stats *req_rsp;
     472                 :            :         struct dev *dev = &sso->dev;
     473                 :            :         struct mbox *mbox;
     474                 :            :         int rc;
     475                 :            : 
     476                 :          0 :         mbox = mbox_get(dev->mbox);
     477                 :          0 :         req_rsp = (struct sso_grp_stats *)mbox_alloc_msg_sso_grp_get_stats(
     478                 :            :                 mbox);
     479         [ #  # ]:          0 :         if (req_rsp == NULL) {
     480                 :          0 :                 rc = mbox_process(mbox);
     481         [ #  # ]:          0 :                 if (rc) {
     482                 :            :                         rc = -EIO;
     483                 :          0 :                         goto fail;
     484                 :            :                 }
     485                 :          0 :                 req_rsp = (struct sso_grp_stats *)
     486                 :          0 :                         mbox_alloc_msg_sso_grp_get_stats(mbox);
     487         [ #  # ]:          0 :                 if (req_rsp == NULL) {
     488                 :            :                         rc = -ENOSPC;
     489                 :          0 :                         goto fail;
     490                 :            :                 }
     491                 :            :         }
     492                 :          0 :         req_rsp->grp = hwgrp;
     493                 :            :         rc = mbox_process_msg(mbox, (void **)&req_rsp);
     494         [ #  # ]:          0 :         if (rc) {
     495                 :            :                 rc = -EIO;
     496                 :          0 :                 goto fail;
     497                 :            :         }
     498                 :            : 
     499                 :          0 :         stats->aw_status = req_rsp->aw_status;
     500                 :          0 :         stats->dq_pc = req_rsp->dq_pc;
     501                 :          0 :         stats->ds_pc = req_rsp->ds_pc;
     502                 :          0 :         stats->ext_pc = req_rsp->ext_pc;
     503                 :          0 :         stats->page_cnt = req_rsp->page_cnt;
     504                 :          0 :         stats->ts_pc = req_rsp->ts_pc;
     505                 :          0 :         stats->wa_pc = req_rsp->wa_pc;
     506                 :          0 :         stats->ws_pc = req_rsp->ws_pc;
     507                 :            : 
     508                 :          0 : fail:
     509                 :            :         mbox_put(mbox);
     510                 :          0 :         return rc;
     511                 :            : }
     512                 :            : 
     513                 :            : int
     514                 :          0 : roc_sso_hwgrp_hws_link_status(struct roc_sso *roc_sso, uint8_t hws,
     515                 :            :                               uint16_t hwgrp)
     516                 :            : {
     517                 :            :         struct sso *sso;
     518                 :            : 
     519                 :            :         sso = roc_sso_to_sso_priv(roc_sso);
     520                 :          0 :         return plt_bitmap_get(sso->link_map[hws], hwgrp);
     521                 :            : }
     522                 :            : 
     523                 :            : int
     524                 :          0 : roc_sso_hwgrp_qos_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_qos *qos, uint16_t nb_qos)
     525                 :            : {
     526                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     527                 :            :         struct dev *dev = &sso->dev;
     528                 :            :         struct sso_grp_qos_cfg *req;
     529                 :            :         struct mbox *mbox;
     530                 :            :         int i, rc;
     531                 :            : 
     532         [ #  # ]:          0 :         if (!nb_qos)
     533                 :            :                 return 0;
     534                 :            : 
     535                 :          0 :         mbox = mbox_get(dev->mbox);
     536         [ #  # ]:          0 :         for (i = 0; i < nb_qos; i++) {
     537                 :          0 :                 uint8_t iaq_prcnt = qos[i].iaq_prcnt;
     538                 :          0 :                 uint8_t taq_prcnt = qos[i].taq_prcnt;
     539                 :            : 
     540                 :          0 :                 req = mbox_alloc_msg_sso_grp_qos_config(mbox);
     541         [ #  # ]:          0 :                 if (req == NULL) {
     542                 :          0 :                         rc = mbox_process(mbox);
     543         [ #  # ]:          0 :                         if (rc) {
     544                 :            :                                 rc = -EIO;
     545                 :          0 :                                 goto fail;
     546                 :            :                         }
     547                 :            : 
     548                 :          0 :                         req = mbox_alloc_msg_sso_grp_qos_config(mbox);
     549         [ #  # ]:          0 :                         if (req == NULL) {
     550                 :            :                                 rc = -ENOSPC;
     551                 :          0 :                                 goto fail;
     552                 :            :                         }
     553                 :            :                 }
     554                 :          0 :                 req->grp = qos[i].hwgrp;
     555         [ #  # ]:          0 :                 req->iaq_thr = (SSO_HWGRP_IAQ_MAX_THR_MASK *
     556                 :          0 :                                 (iaq_prcnt ? iaq_prcnt : 100)) /
     557                 :            :                                100;
     558         [ #  # ]:          0 :                 req->taq_thr = (SSO_HWGRP_TAQ_MAX_THR_MASK *
     559                 :          0 :                                 (taq_prcnt ? taq_prcnt : 100)) /
     560                 :            :                                100;
     561                 :            :         }
     562                 :            : 
     563                 :          0 :         rc = mbox_process(mbox);
     564         [ #  # ]:          0 :         if (rc)
     565                 :            :                 rc = -EIO;
     566                 :          0 : fail:
     567                 :            :         mbox_put(mbox);
     568                 :          0 :         return rc;
     569                 :            : }
     570                 :            : 
     571                 :            : int
     572                 :          0 : sso_hwgrp_init_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
     573                 :            :                         uint32_t nb_xae, uint32_t xae_waes,
     574                 :            :                         uint32_t xaq_buf_size, uint16_t nb_hwgrp)
     575                 :            : {
     576                 :            :         struct npa_pool_s pool;
     577                 :            :         struct npa_aura_s aura;
     578                 :            :         plt_iova_t iova;
     579                 :            :         uint32_t i;
     580                 :            :         int rc;
     581                 :            : 
     582         [ #  # ]:          0 :         if (xaq->mem != NULL) {
     583                 :          0 :                 rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
     584         [ #  # ]:          0 :                 if (rc < 0) {
     585                 :          0 :                         plt_err("Failed to release XAQ %d", rc);
     586                 :          0 :                         return rc;
     587                 :            :                 }
     588                 :          0 :                 roc_npa_pool_destroy(xaq->aura_handle);
     589                 :          0 :                 plt_free(xaq->fc);
     590                 :          0 :                 plt_free(xaq->mem);
     591                 :            :                 memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
     592                 :            :         }
     593                 :            : 
     594                 :          0 :         xaq->fc = plt_zmalloc(ROC_ALIGN, ROC_ALIGN);
     595         [ #  # ]:          0 :         if (xaq->fc == NULL) {
     596                 :          0 :                 plt_err("Failed to allocate XAQ FC");
     597                 :            :                 rc = -ENOMEM;
     598                 :          0 :                 goto fail;
     599                 :            :         }
     600                 :            : 
     601                 :          0 :         xaq->nb_xae = nb_xae;
     602                 :            : 
     603                 :            :         /** SSO will reserve up to 0x4 XAQ buffers per group when GetWork engine
     604                 :            :          * is inactive and it might prefetch an additional 0x3 buffers due to
     605                 :            :          * pipelining.
     606                 :            :          */
     607                 :          0 :         xaq->nb_xaq = (SSO_XAQ_CACHE_CNT * nb_hwgrp);
     608                 :          0 :         xaq->nb_xaq += (SSO_XAQ_RSVD_CNT * nb_hwgrp);
     609                 :          0 :         xaq->nb_xaq += PLT_MAX(1 + ((xaq->nb_xae - 1) / xae_waes), xaq->nb_xaq);
     610                 :          0 :         xaq->nb_xaq += SSO_XAQ_SLACK;
     611                 :            : 
     612                 :          0 :         xaq->mem = plt_zmalloc(xaq_buf_size * xaq->nb_xaq, xaq_buf_size);
     613         [ #  # ]:          0 :         if (xaq->mem == NULL) {
     614                 :          0 :                 plt_err("Failed to allocate XAQ mem");
     615                 :            :                 rc = -ENOMEM;
     616                 :          0 :                 goto free_fc;
     617                 :            :         }
     618                 :            : 
     619                 :            :         memset(&pool, 0, sizeof(struct npa_pool_s));
     620                 :          0 :         pool.nat_align = 1;
     621                 :            : 
     622                 :            :         memset(&aura, 0, sizeof(aura));
     623                 :          0 :         aura.fc_ena = 1;
     624                 :          0 :         aura.fc_addr = (uint64_t)xaq->fc;
     625                 :            :         aura.fc_hyst_bits = 0; /* Store count on all updates */
     626                 :          0 :         rc = roc_npa_pool_create(&xaq->aura_handle, xaq_buf_size, xaq->nb_xaq,
     627                 :            :                                  &aura, &pool, 0);
     628         [ #  # ]:          0 :         if (rc) {
     629                 :          0 :                 plt_err("Failed to create XAQ pool");
     630                 :          0 :                 goto npa_fail;
     631                 :            :         }
     632                 :            : 
     633                 :          0 :         iova = (uint64_t)xaq->mem;
     634         [ #  # ]:          0 :         for (i = 0; i < xaq->nb_xaq; i++) {
     635                 :          0 :                 roc_npa_aura_op_free(xaq->aura_handle, 0, iova);
     636                 :          0 :                 iova += xaq_buf_size;
     637                 :            :         }
     638                 :          0 :         roc_npa_pool_op_range_set(xaq->aura_handle, (uint64_t)xaq->mem, iova);
     639                 :            : 
     640                 :          0 :         if (roc_npa_aura_op_available_wait(xaq->aura_handle, xaq->nb_xaq, 0) !=
     641         [ #  # ]:          0 :             xaq->nb_xaq) {
     642                 :          0 :                 plt_err("Failed to free all pointers to the pool");
     643                 :            :                 rc = -ENOMEM;
     644                 :          0 :                 goto npa_fill_fail;
     645                 :            :         }
     646                 :            : 
     647                 :            :         /* When SW does addwork (enqueue) check if there is space in XAQ by
     648                 :            :          * comparing fc_addr above against the xaq_lmt calculated below.
     649                 :            :          * There should be a minimum headroom of 7 XAQs per HWGRP for SSO
     650                 :            :          * to request XAQ to cache them even before enqueue is called.
     651                 :            :          */
     652                 :          0 :         xaq->xaq_lmt = xaq->nb_xaq - (nb_hwgrp * SSO_XAQ_CACHE_CNT) - SSO_XAQ_SLACK;
     653                 :            : 
     654                 :          0 :         return 0;
     655                 :            : npa_fill_fail:
     656                 :          0 :         roc_npa_pool_destroy(xaq->aura_handle);
     657                 :          0 : npa_fail:
     658                 :          0 :         plt_free(xaq->mem);
     659                 :          0 : free_fc:
     660                 :          0 :         plt_free(xaq->fc);
     661                 :          0 : fail:
     662                 :            :         memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
     663                 :          0 :         return rc;
     664                 :            : }
     665                 :            : 
     666                 :            : int
     667                 :          0 : roc_sso_hwgrp_init_xaq_aura(struct roc_sso *roc_sso, uint32_t nb_xae)
     668                 :            : {
     669                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     670                 :          0 :         struct dev *dev = &sso->dev;
     671                 :            :         int rc;
     672                 :            : 
     673                 :          0 :         rc = sso_hwgrp_init_xaq_aura(dev, &roc_sso->xaq, nb_xae,
     674                 :            :                                      roc_sso->xae_waes, roc_sso->xaq_buf_size,
     675                 :          0 :                                      roc_sso->nb_hwgrp);
     676                 :          0 :         return rc;
     677                 :            : }
     678                 :            : 
     679                 :            : int
     680                 :          0 : sso_hwgrp_free_xaq_aura(struct dev *dev, struct roc_sso_xaq_data *xaq,
     681                 :            :                         uint16_t nb_hwgrp)
     682                 :            : {
     683                 :            :         int rc;
     684                 :            : 
     685         [ #  # ]:          0 :         if (xaq->mem != NULL) {
     686         [ #  # ]:          0 :                 if (nb_hwgrp) {
     687                 :          0 :                         rc = sso_hwgrp_release_xaq(dev, nb_hwgrp);
     688         [ #  # ]:          0 :                         if (rc < 0) {
     689                 :          0 :                                 plt_err("Failed to release XAQ %d", rc);
     690                 :          0 :                                 return rc;
     691                 :            :                         }
     692                 :            :                 }
     693                 :          0 :                 roc_npa_pool_destroy(xaq->aura_handle);
     694                 :          0 :                 plt_free(xaq->fc);
     695                 :          0 :                 plt_free(xaq->mem);
     696                 :            :         }
     697                 :            :         memset(xaq, 0, sizeof(struct roc_sso_xaq_data));
     698                 :            : 
     699                 :          0 :         return 0;
     700                 :            : }
     701                 :            : 
     702                 :            : int
     703                 :          0 : roc_sso_hwgrp_free_xaq_aura(struct roc_sso *roc_sso, uint16_t nb_hwgrp)
     704                 :            : {
     705                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     706                 :          0 :         struct dev *dev = &sso->dev;
     707                 :            :         int rc;
     708                 :            : 
     709                 :          0 :         rc = sso_hwgrp_free_xaq_aura(dev, &roc_sso->xaq, nb_hwgrp);
     710                 :          0 :         return rc;
     711                 :            : }
     712                 :            : 
     713                 :            : int
     714                 :          0 : sso_hwgrp_alloc_xaq(struct dev *dev, uint32_t npa_aura_id, uint16_t hwgrps)
     715                 :            : {
     716                 :            :         struct sso_hw_setconfig *req;
     717                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     718                 :            :         int rc = -ENOSPC;
     719                 :            : 
     720                 :          0 :         req = mbox_alloc_msg_sso_hw_setconfig(mbox);
     721         [ #  # ]:          0 :         if (req == NULL)
     722                 :          0 :                 goto exit;
     723                 :          0 :         req->npa_pf_func = idev_npa_pffunc_get();
     724                 :          0 :         req->npa_aura_id = npa_aura_id;
     725                 :          0 :         req->hwgrps = hwgrps;
     726                 :            : 
     727         [ #  # ]:          0 :         if (mbox_process(dev->mbox)) {
     728                 :            :                 rc = -EIO;
     729                 :          0 :                 goto exit;
     730                 :            :         }
     731                 :            : 
     732                 :            :         rc = 0;
     733                 :          0 : exit:
     734                 :            :         mbox_put(mbox);
     735                 :          0 :         return rc;
     736                 :            : }
     737                 :            : 
     738                 :            : int
     739                 :          0 : roc_sso_hwgrp_alloc_xaq(struct roc_sso *roc_sso, uint32_t npa_aura_id,
     740                 :            :                         uint16_t hwgrps)
     741                 :            : {
     742                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     743                 :          0 :         struct dev *dev = &sso->dev;
     744                 :            :         int rc;
     745                 :            : 
     746                 :          0 :         rc = sso_hwgrp_alloc_xaq(dev, npa_aura_id, hwgrps);
     747                 :          0 :         return rc;
     748                 :            : }
     749                 :            : 
     750                 :            : int
     751                 :          0 : sso_hwgrp_release_xaq(struct dev *dev, uint16_t hwgrps)
     752                 :            : {
     753                 :            :         struct sso_hw_xaq_release *req;
     754                 :          0 :         struct mbox *mbox = mbox_get(dev->mbox);
     755                 :            :         int rc;
     756                 :            : 
     757                 :          0 :         req = mbox_alloc_msg_sso_hw_release_xaq_aura(mbox);
     758         [ #  # ]:          0 :         if (req == NULL) {
     759                 :            :                 rc =  -EINVAL;
     760                 :          0 :                 goto exit;
     761                 :            :         }
     762                 :          0 :         req->hwgrps = hwgrps;
     763                 :            : 
     764         [ #  # ]:          0 :         if (mbox_process(mbox)) {
     765                 :            :                 rc = -EIO;
     766                 :          0 :                 goto exit;
     767                 :            :         }
     768                 :            : 
     769                 :            :         rc = 0;
     770                 :          0 : exit:
     771                 :            :         mbox_put(mbox);
     772                 :          0 :         return rc;
     773                 :            : }
     774                 :            : 
     775                 :            : int
     776                 :          0 : roc_sso_hwgrp_release_xaq(struct roc_sso *roc_sso, uint16_t hwgrps)
     777                 :            : {
     778                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     779                 :          0 :         struct dev *dev = &sso->dev;
     780                 :            :         int rc;
     781                 :            : 
     782         [ #  # ]:          0 :         if (!hwgrps)
     783                 :            :                 return 0;
     784                 :            : 
     785                 :          0 :         rc = sso_hwgrp_release_xaq(dev, hwgrps);
     786                 :          0 :         return rc;
     787                 :            : }
     788                 :            : 
     789                 :            : int
     790                 :          0 : roc_sso_hwgrp_set_priority(struct roc_sso *roc_sso, uint16_t hwgrp,
     791                 :            :                            uint8_t weight, uint8_t affinity, uint8_t priority)
     792                 :            : {
     793                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     794                 :            :         struct dev *dev = &sso->dev;
     795                 :            :         struct sso_grp_priority *req;
     796                 :            :         struct mbox *mbox;
     797                 :            :         int rc = -ENOSPC;
     798                 :            : 
     799                 :          0 :         mbox = mbox_get(dev->mbox);
     800                 :          0 :         req = mbox_alloc_msg_sso_grp_set_priority(mbox);
     801         [ #  # ]:          0 :         if (req == NULL)
     802                 :          0 :                 goto fail;
     803                 :          0 :         req->grp = hwgrp;
     804                 :          0 :         req->weight = weight;
     805                 :          0 :         req->affinity = affinity;
     806                 :          0 :         req->priority = priority;
     807                 :            : 
     808                 :          0 :         rc = mbox_process(mbox);
     809         [ #  # ]:          0 :         if (rc) {
     810                 :            :                 rc = -EIO;
     811                 :          0 :                 goto fail;
     812                 :            :         }
     813                 :            :         mbox_put(mbox);
     814                 :          0 :         plt_sso_dbg("HWGRP %d weight %d affinity %d priority %d", hwgrp, weight,
     815                 :            :                     affinity, priority);
     816                 :            : 
     817                 :          0 :         return 0;
     818                 :          0 : fail:
     819                 :            :         mbox_put(mbox);
     820                 :          0 :         return rc;
     821                 :            : }
     822                 :            : 
     823                 :            : static int
     824                 :          0 : sso_update_msix_vec_count(struct roc_sso *roc_sso, uint16_t sso_vec_cnt)
     825                 :            : {
     826                 :          0 :         struct plt_pci_device *pci_dev = roc_sso->pci_dev;
     827                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     828                 :            :         uint16_t mbox_vec_cnt, npa_vec_cnt;
     829                 :          0 :         struct dev *dev = &sso->dev;
     830                 :            :         struct idev_cfg *idev;
     831                 :            :         int rc;
     832                 :            : 
     833                 :          0 :         idev = idev_get_cfg();
     834         [ #  # ]:          0 :         if (idev == NULL)
     835                 :            :                 return -ENODEV;
     836                 :            : 
     837                 :            :         mbox_vec_cnt = RVU_PF_INT_VEC_AFPF_MBOX + 1;
     838                 :            : 
     839                 :            :         /* Allocating vectors for the first time */
     840         [ #  # ]:          0 :         if (plt_intr_max_intr_get(pci_dev->intr_handle) == 0) {
     841         [ #  # ]:          0 :                 npa_vec_cnt = idev->npa_refcnt ? 0 : NPA_LF_INT_VEC_POISON + 1;
     842                 :          0 :                 return dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt);
     843                 :            :         }
     844                 :            : 
     845         [ #  # ]:          0 :         npa_vec_cnt = (dev->npa.pci_dev == pci_dev) ? NPA_LF_INT_VEC_POISON + 1 : 0;
     846                 :            : 
     847                 :            :         /* Re-configure to include SSO vectors */
     848                 :          0 :         rc = dev_irq_reconfigure(pci_dev->intr_handle, mbox_vec_cnt + npa_vec_cnt + sso_vec_cnt);
     849         [ #  # ]:          0 :         if (rc)
     850                 :            :                 return rc;
     851                 :            : 
     852                 :          0 :         rc = dev_mbox_register_irq(pci_dev, dev);
     853         [ #  # ]:          0 :         if (rc)
     854                 :            :                 return rc;
     855                 :            : 
     856         [ #  # ]:          0 :         if (!dev_is_vf(dev)) {
     857                 :          0 :                 rc = dev_vf_flr_register_irqs(pci_dev, dev);
     858         [ #  # ]:          0 :                 if (rc)
     859                 :            :                         return rc;
     860                 :            :         }
     861                 :            : 
     862         [ #  # ]:          0 :         if (npa_vec_cnt)
     863                 :          0 :                 rc = npa_register_irqs(&dev->npa);
     864                 :            : 
     865                 :            :         return rc;
     866                 :            : }
     867                 :            : 
     868                 :            : int
     869                 :          0 : roc_sso_hwgrp_stash_config(struct roc_sso *roc_sso, struct roc_sso_hwgrp_stash *stash,
     870                 :            :                            uint16_t nb_stash)
     871                 :            : {
     872                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     873                 :            :         struct sso_grp_stash_cfg *req;
     874                 :            :         struct dev *dev = &sso->dev;
     875                 :            :         struct mbox *mbox;
     876                 :            :         int i, rc;
     877                 :            : 
     878         [ #  # ]:          0 :         if (!nb_stash)
     879                 :            :                 return 0;
     880                 :            : 
     881                 :          0 :         mbox = mbox_get(dev->mbox);
     882         [ #  # ]:          0 :         for (i = 0; i < nb_stash; i++) {
     883                 :          0 :                 req = mbox_alloc_msg_sso_grp_stash_config(mbox);
     884         [ #  # ]:          0 :                 if (req == NULL) {
     885                 :          0 :                         rc = mbox_process(mbox);
     886         [ #  # ]:          0 :                         if (rc) {
     887                 :            :                                 rc = -EIO;
     888                 :          0 :                                 goto fail;
     889                 :            :                         }
     890                 :            : 
     891                 :          0 :                         req = mbox_alloc_msg_sso_grp_stash_config(mbox);
     892         [ #  # ]:          0 :                         if (req == NULL) {
     893                 :            :                                 rc = -ENOSPC;
     894                 :          0 :                                 goto fail;
     895                 :            :                         }
     896                 :            :                 }
     897                 :          0 :                 req->ena = true;
     898                 :          0 :                 req->grp = stash[i].hwgrp;
     899                 :          0 :                 req->offset = stash[i].stash_offset;
     900                 :          0 :                 req->num_linesm1 = stash[i].stash_count - 1;
     901                 :            :         }
     902                 :            : 
     903                 :          0 :         rc = mbox_process(mbox);
     904         [ #  # ]:          0 :         if (rc)
     905                 :            :                 rc = -EIO;
     906                 :          0 : fail:
     907                 :            :         mbox_put(mbox);
     908                 :          0 :         return rc;
     909                 :            : }
     910                 :            : 
     911                 :            : int
     912                 :          0 : roc_sso_rsrc_init(struct roc_sso *roc_sso, uint8_t nb_hws, uint16_t nb_hwgrp, uint16_t nb_tim_lfs)
     913                 :            : {
     914                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
     915                 :            :         struct sso_lf_alloc_rsp *rsp_hwgrp;
     916                 :            :         uint16_t sso_vec_cnt, free_tim_lfs;
     917                 :            :         int rc;
     918                 :            : 
     919   [ #  #  #  # ]:          0 :         if (!nb_hwgrp || roc_sso->max_hwgrp < nb_hwgrp)
     920                 :            :                 return -ENOENT;
     921   [ #  #  #  # ]:          0 :         if (!nb_hws || roc_sso->max_hws < nb_hws)
     922                 :            :                 return -ENOENT;
     923                 :            : 
     924                 :          0 :         rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWS, nb_hws);
     925         [ #  # ]:          0 :         if (rc < 0) {
     926                 :          0 :                 plt_err("Unable to attach SSO HWS LFs");
     927                 :          0 :                 goto fail;
     928                 :            :         }
     929                 :            : 
     930                 :          0 :         rc = sso_rsrc_attach(roc_sso, SSO_LF_TYPE_HWGRP, nb_hwgrp);
     931         [ #  # ]:          0 :         if (rc < 0) {
     932                 :          0 :                 plt_err("Unable to attach SSO HWGRP LFs");
     933                 :          0 :                 goto hwgrp_atch_fail;
     934                 :            :         }
     935                 :            : 
     936                 :          0 :         rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWS, nb_hws, NULL);
     937         [ #  # ]:          0 :         if (rc < 0) {
     938                 :          0 :                 plt_err("Unable to alloc SSO HWS LFs");
     939                 :          0 :                 goto hws_alloc_fail;
     940                 :            :         }
     941                 :            : 
     942                 :          0 :         rc = sso_lf_alloc(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp,
     943                 :            :                           (void **)&rsp_hwgrp);
     944         [ #  # ]:          0 :         if (rc < 0) {
     945                 :          0 :                 plt_err("Unable to alloc SSO HWGRP Lfs");
     946                 :          0 :                 goto hwgrp_alloc_fail;
     947                 :            :         }
     948                 :            : 
     949                 :          0 :         roc_sso->xaq_buf_size = rsp_hwgrp->xaq_buf_size;
     950                 :          0 :         roc_sso->xae_waes = rsp_hwgrp->xaq_wq_entries;
     951                 :          0 :         roc_sso->iue = rsp_hwgrp->in_unit_entries;
     952                 :            : 
     953                 :          0 :         rc = sso_msix_fill(roc_sso, nb_hws, nb_hwgrp);
     954         [ #  # ]:          0 :         if (rc < 0) {
     955                 :          0 :                 plt_err("Unable to get MSIX offsets for SSO LFs");
     956                 :          0 :                 goto sso_msix_fail;
     957                 :            :         }
     958                 :            : 
     959                 :            :         /* 1 error interrupt per SSO HWS/HWGRP */
     960                 :          0 :         sso_vec_cnt = nb_hws + nb_hwgrp;
     961                 :            : 
     962         [ #  # ]:          0 :         if (sso->dev.roc_tim) {
     963                 :          0 :                 nb_tim_lfs = ((struct roc_tim *)sso->dev.roc_tim)->nb_lfs;
     964                 :            :         } else {
     965                 :          0 :                 rc = tim_free_lf_count_get(&sso->dev, &free_tim_lfs);
     966         [ #  # ]:          0 :                 if (rc < 0) {
     967                 :          0 :                         plt_err("Failed to get TIM resource count");
     968                 :          0 :                         goto sso_msix_fail;
     969                 :            :                 }
     970                 :            : 
     971                 :          0 :                 nb_tim_lfs = PLT_MIN(nb_tim_lfs, free_tim_lfs);
     972                 :            :         }
     973                 :            : 
     974                 :            :         /* 2 error interrupt per TIM LF */
     975                 :          0 :         sso_vec_cnt += 2 * nb_tim_lfs;
     976                 :            : 
     977                 :          0 :         rc = sso_update_msix_vec_count(roc_sso, sso_vec_cnt);
     978         [ #  # ]:          0 :         if (rc < 0) {
     979                 :          0 :                 plt_err("Failed to update SSO MSIX vector count");
     980                 :          0 :                 goto sso_msix_fail;
     981                 :            :         }
     982                 :            : 
     983                 :          0 :         rc = sso_register_irqs_priv(roc_sso, sso->pci_dev->intr_handle, nb_hws,
     984                 :            :                                     nb_hwgrp);
     985         [ #  # ]:          0 :         if (rc < 0) {
     986                 :          0 :                 plt_err("Failed to register SSO LF IRQs");
     987                 :          0 :                 goto sso_msix_fail;
     988                 :            :         }
     989                 :            : 
     990                 :          0 :         roc_sso->nb_hwgrp = nb_hwgrp;
     991                 :          0 :         roc_sso->nb_hws = nb_hws;
     992                 :            : 
     993                 :          0 :         return 0;
     994                 :          0 : sso_msix_fail:
     995                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, nb_hwgrp);
     996                 :          0 : hwgrp_alloc_fail:
     997                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, nb_hws);
     998                 :          0 : hws_alloc_fail:
     999                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
    1000                 :          0 : hwgrp_atch_fail:
    1001                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
    1002                 :            : fail:
    1003                 :            :         return rc;
    1004                 :            : }
    1005                 :            : 
    1006                 :            : void
    1007                 :          0 : roc_sso_rsrc_fini(struct roc_sso *roc_sso)
    1008                 :            : {
    1009                 :            :         struct sso *sso = roc_sso_to_sso_priv(roc_sso);
    1010                 :            : 
    1011         [ #  # ]:          0 :         if (!roc_sso->nb_hws && !roc_sso->nb_hwgrp)
    1012                 :            :                 return;
    1013                 :            : 
    1014                 :          0 :         sso_unregister_irqs_priv(roc_sso, sso->pci_dev->intr_handle,
    1015                 :          0 :                                  roc_sso->nb_hws, roc_sso->nb_hwgrp);
    1016                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWS, roc_sso->nb_hws);
    1017                 :          0 :         sso_lf_free(&sso->dev, SSO_LF_TYPE_HWGRP, roc_sso->nb_hwgrp);
    1018                 :            : 
    1019                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWS);
    1020                 :          0 :         sso_rsrc_detach(roc_sso, SSO_LF_TYPE_HWGRP);
    1021                 :            : 
    1022                 :          0 :         roc_sso->nb_hwgrp = 0;
    1023                 :          0 :         roc_sso->nb_hws = 0;
    1024                 :            : }
    1025                 :            : 
    1026                 :            : int
    1027                 :          0 : roc_sso_dev_init(struct roc_sso *roc_sso)
    1028                 :            : {
    1029                 :            :         struct plt_pci_device *pci_dev;
    1030                 :            :         uint32_t link_map_sz;
    1031                 :            :         struct sso *sso;
    1032                 :            :         void *link_mem;
    1033                 :            :         int i, rc;
    1034                 :            : 
    1035   [ #  #  #  # ]:          0 :         if (roc_sso == NULL || roc_sso->pci_dev == NULL)
    1036                 :            :                 return SSO_ERR_PARAM;
    1037                 :            : 
    1038                 :            :         PLT_STATIC_ASSERT(sizeof(struct sso) <= ROC_SSO_MEM_SZ);
    1039                 :            :         sso = roc_sso_to_sso_priv(roc_sso);
    1040                 :            :         memset(sso, 0, sizeof(*sso));
    1041                 :            :         pci_dev = roc_sso->pci_dev;
    1042                 :            : 
    1043                 :          0 :         rc = sso_update_msix_vec_count(roc_sso, 0);
    1044         [ #  # ]:          0 :         if (rc < 0) {
    1045                 :          0 :                 plt_err("Failed to set SSO MSIX vector count");
    1046                 :          0 :                 return rc;
    1047                 :            :         }
    1048                 :            : 
    1049                 :          0 :         rc = dev_init(&sso->dev, pci_dev);
    1050         [ #  # ]:          0 :         if (rc < 0) {
    1051                 :          0 :                 plt_err("Failed to init roc device");
    1052                 :          0 :                 goto fail;
    1053                 :            :         }
    1054                 :            : 
    1055                 :          0 :         rc = sso_rsrc_get(roc_sso);
    1056         [ #  # ]:          0 :         if (rc < 0) {
    1057                 :          0 :                 plt_err("Failed to get SSO resources");
    1058                 :          0 :                 goto rsrc_fail;
    1059                 :            :         }
    1060                 :            :         rc = -ENOMEM;
    1061                 :            : 
    1062         [ #  # ]:          0 :         if (roc_sso->max_hws) {
    1063                 :          0 :                 sso->link_map = plt_zmalloc(
    1064                 :            :                         sizeof(struct plt_bitmap *) * roc_sso->max_hws, 0);
    1065         [ #  # ]:          0 :                 if (sso->link_map == NULL) {
    1066                 :          0 :                         plt_err("Failed to allocate memory for link_map array");
    1067                 :          0 :                         goto rsrc_fail;
    1068                 :            :                 }
    1069                 :            : 
    1070                 :            :                 link_map_sz =
    1071                 :          0 :                         plt_bitmap_get_memory_footprint(roc_sso->max_hwgrp);
    1072                 :          0 :                 sso->link_map_mem =
    1073                 :          0 :                         plt_zmalloc(link_map_sz * roc_sso->max_hws, 0);
    1074         [ #  # ]:          0 :                 if (sso->link_map_mem == NULL) {
    1075                 :          0 :                         plt_err("Failed to get link_map memory");
    1076                 :          0 :                         goto rsrc_fail;
    1077                 :            :                 }
    1078                 :            : 
    1079                 :            :                 link_mem = sso->link_map_mem;
    1080                 :            : 
    1081         [ #  # ]:          0 :                 for (i = 0; i < roc_sso->max_hws; i++) {
    1082                 :          0 :                         sso->link_map[i] = plt_bitmap_init(
    1083                 :          0 :                                 roc_sso->max_hwgrp, link_mem, link_map_sz);
    1084         [ #  # ]:          0 :                         if (sso->link_map[i] == NULL) {
    1085                 :          0 :                                 plt_err("Failed to allocate link map");
    1086                 :          0 :                                 goto link_mem_free;
    1087                 :            :                         }
    1088                 :          0 :                         link_mem = PLT_PTR_ADD(link_mem, link_map_sz);
    1089                 :            :                 }
    1090                 :            :         }
    1091                 :          0 :         idev_sso_pffunc_set(sso->dev.pf_func);
    1092                 :          0 :         idev_sso_set(roc_sso);
    1093                 :          0 :         sso->pci_dev = pci_dev;
    1094                 :          0 :         sso->dev.drv_inited = true;
    1095                 :          0 :         roc_sso->lmt_base = sso->dev.lmt_base;
    1096                 :            : 
    1097                 :          0 :         return 0;
    1098                 :            : link_mem_free:
    1099                 :          0 :         plt_free(sso->link_map_mem);
    1100                 :          0 : rsrc_fail:
    1101                 :          0 :         rc |= dev_fini(&sso->dev, pci_dev);
    1102                 :            : fail:
    1103                 :            :         return rc;
    1104                 :            : }
    1105                 :            : 
    1106                 :            : int
    1107                 :          0 : roc_sso_dev_fini(struct roc_sso *roc_sso)
    1108                 :            : {
    1109                 :            :         struct sso *sso;
    1110                 :            : 
    1111                 :            :         sso = roc_sso_to_sso_priv(roc_sso);
    1112                 :          0 :         sso->dev.drv_inited = false;
    1113                 :            : 
    1114                 :          0 :         return dev_fini(&sso->dev, sso->pci_dev);
    1115                 :            : }

Generated by: LCOV version 1.14