LCOV - code coverage report
Current view: top level - drivers/common/cnxk - roc_nix_inl.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 1262 0.0 %
Date: 2026-07-01 18:02:41 Functions: 0 65 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 917 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                 :            : uint32_t soft_exp_consumer_cnt;
       9                 :            : roc_nix_inl_meta_pool_cb_t meta_pool_cb;
      10                 :            : roc_nix_inl_custom_meta_pool_cb_t custom_meta_pool_cb;
      11                 :            : 
      12                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_ON_IPSEC_INB_SA_SZ ==
      13                 :            :                   1UL << ROC_NIX_INL_ON_IPSEC_INB_SA_SZ_LOG2);
      14                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_ON_IPSEC_INB_SA_SZ == 1024);
      15                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ ==
      16                 :            :                   1UL << ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ_LOG2);
      17                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ ==
      18                 :            :                   1UL << ROC_NIX_INL_OT_IPSEC_INB_SA_SZ_LOG2);
      19                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ == 1024);
      20                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ ==
      21                 :            :                   1UL << ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ_LOG2);
      22                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ == ROC_NIX_INL_OW_IPSEC_INB_SA_SZ);
      23                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_INB_SA_SZ == ROC_NIX_INL_ON_IPSEC_INB_SA_SZ);
      24                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ == ROC_NIX_INL_OW_IPSEC_OUTB_SA_SZ);
      25                 :            : PLT_STATIC_ASSERT(ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ == ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ);
      26                 :            : 
      27                 :            : static int
      28                 :          0 : nix_inl_meta_aura_destroy(struct roc_nix *roc_nix)
      29                 :            : {
      30                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
      31                 :            :         struct idev_nix_inl_cfg *inl_cfg;
      32                 :          0 :         char mempool_name[24] = {'\0'};
      33                 :            :         char *mp_name = NULL;
      34                 :            :         uint64_t *meta_aura;
      35                 :            :         int rc;
      36                 :            : 
      37         [ #  # ]:          0 :         if (!idev)
      38                 :            :                 return -EINVAL;
      39                 :            : 
      40                 :            :         inl_cfg = &idev->inl_cfg;
      41                 :            : 
      42   [ #  #  #  # ]:          0 :         if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena) {
      43                 :          0 :                 meta_aura = &inl_cfg->meta_aura;
      44                 :            :         } else {
      45                 :          0 :                 meta_aura = &roc_nix->meta_aura_handle;
      46                 :          0 :                 snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
      47                 :          0 :                          roc_nix->port_id + 1);
      48                 :            :                 mp_name = mempool_name;
      49                 :            :         }
      50                 :            : 
      51                 :            :         /* Destroy existing Meta aura */
      52         [ #  # ]:          0 :         if (*meta_aura) {
      53                 :            :                 uint64_t avail, limit;
      54                 :            : 
      55                 :            :                 /* Check if all buffers are back to pool */
      56                 :            :                 avail = roc_npa_aura_op_available(*meta_aura);
      57                 :            :                 limit = roc_npa_aura_op_limit_get(*meta_aura);
      58                 :            :                 if (avail != limit)
      59                 :            :                         plt_warn("Not all buffers are back to meta pool,"
      60                 :            :                                  " %" PRIu64 " != %" PRIu64, avail, limit);
      61                 :            : 
      62                 :          0 :                 rc = meta_pool_cb(meta_aura, &roc_nix->meta_mempool, 0, 0, true, mp_name);
      63         [ #  # ]:          0 :                 if (rc) {
      64                 :          0 :                         plt_err("Failed to destroy meta aura, rc=%d", rc);
      65                 :          0 :                         return rc;
      66                 :            :                 }
      67                 :            : 
      68         [ #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena) {
      69                 :          0 :                         inl_cfg->meta_aura = 0;
      70                 :          0 :                         inl_cfg->buf_sz = 0;
      71                 :          0 :                         inl_cfg->nb_bufs = 0;
      72                 :            :                 } else
      73                 :          0 :                         roc_nix->buf_sz = 0;
      74                 :            :         }
      75                 :            : 
      76                 :            :         return 0;
      77                 :            : }
      78                 :            : 
      79                 :            : static int
      80                 :          0 : nix_inl_meta_aura_create(struct idev_cfg *idev, struct roc_nix *roc_nix, uint16_t first_skip,
      81                 :            :                          uint64_t *meta_aura, bool is_local_metaaura)
      82                 :            : {
      83                 :            :         uint64_t mask = BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC);
      84                 :            :         struct idev_nix_inl_cfg *inl_cfg;
      85                 :            :         struct nix_inl_dev *nix_inl_dev;
      86                 :          0 :         int port_id = roc_nix->port_id;
      87                 :          0 :         char mempool_name[24] = {'\0'};
      88                 :            :         struct roc_nix_rq *inl_rq;
      89                 :            :         uint32_t nb_bufs, buf_sz;
      90                 :            :         char *mp_name = NULL;
      91                 :            :         uint16_t inl_rq_id;
      92                 :            :         uintptr_t mp;
      93                 :            :         int rc;
      94                 :            : 
      95                 :            :         inl_cfg = &idev->inl_cfg;
      96                 :          0 :         nix_inl_dev = idev->nix_inl_dev;
      97                 :            : 
      98         [ #  # ]:          0 :         if (is_local_metaaura) {
      99                 :            :                 /* Per LF Meta Aura */
     100                 :            :                 inl_rq_id = nix_inl_dev->nb_rqs > 1 ? port_id : 0;
     101                 :            :                 inl_rq = &nix_inl_dev->rqs[inl_rq_id];
     102                 :            : 
     103                 :            :                 nb_bufs = roc_npa_aura_op_limit_get(inl_rq->aura_handle);
     104                 :            :                 if (inl_rq->spb_ena)
     105                 :            :                         nb_bufs += roc_npa_aura_op_limit_get(inl_rq->spb_aura_handle);
     106                 :            : 
     107                 :            :                 /* Override meta buf size from NIX devargs if present */
     108         [ #  # ]:          0 :                 if (roc_nix->meta_buf_sz) {
     109                 :            :                         buf_sz = roc_nix->meta_buf_sz;
     110                 :            :                 } else {
     111                 :            :                         buf_sz = NIX_INL_META_SIZE;
     112         [ #  # ]:          0 :                         buf_sz += roc_nix->def_first_skip ? roc_nix->def_first_skip : first_skip;
     113                 :            :                 }
     114                 :            : 
     115                 :            :                 /* Create Metapool name */
     116                 :          0 :                 snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
     117                 :            :                          roc_nix->port_id + 1);
     118                 :            :                 mp_name = mempool_name;
     119                 :            :         } else {
     120                 :            :                 /* Global Meta Aura (Aura 0) */
     121                 :            :                 /* Override meta buf count from devargs if present */
     122   [ #  #  #  # ]:          0 :                 if (nix_inl_dev && nix_inl_dev->nb_meta_bufs)
     123                 :            :                         nb_bufs = nix_inl_dev->nb_meta_bufs;
     124                 :            :                 else
     125                 :          0 :                         nb_bufs = roc_npa_buf_type_limit_get(mask);
     126                 :            : 
     127                 :            :                 /* Override meta buf size from devargs if present */
     128   [ #  #  #  # ]:          0 :                 if (nix_inl_dev && nix_inl_dev->meta_buf_sz)
     129                 :            :                         buf_sz = nix_inl_dev->meta_buf_sz;
     130                 :            :                 else
     131                 :          0 :                         buf_sz = first_skip + NIX_INL_META_SIZE;
     132                 :            :         }
     133                 :            : 
     134                 :            :         /* Allocate meta aura */
     135                 :          0 :         rc = meta_pool_cb(meta_aura, &mp, buf_sz, nb_bufs, false, mp_name);
     136         [ #  # ]:          0 :         if (rc) {
     137                 :          0 :                 plt_err("Failed to allocate meta aura, rc=%d", rc);
     138                 :          0 :                 return rc;
     139                 :            :         }
     140                 :          0 :         roc_nix->meta_mempool = mp;
     141                 :            : 
     142                 :          0 :         plt_nix_dbg("Created meta aura %p(%s)for port %d", (void *)*meta_aura, mp_name,
     143                 :            :                     roc_nix->port_id);
     144                 :            : 
     145         [ #  # ]:          0 :         if (!is_local_metaaura) {
     146                 :          0 :                 inl_cfg->buf_sz = buf_sz;
     147                 :          0 :                 inl_cfg->nb_bufs = nb_bufs;
     148                 :          0 :                 inl_cfg->meta_mempool = mp;
     149                 :            :         } else
     150                 :          0 :                 roc_nix->buf_sz = buf_sz;
     151                 :            : 
     152                 :            :         return 0;
     153                 :            : }
     154                 :            : 
     155                 :            : static int
     156                 :          0 : nix_inl_custom_meta_aura_destroy(struct roc_nix *roc_nix)
     157                 :            : {
     158                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     159                 :            :         struct idev_nix_inl_cfg *inl_cfg;
     160                 :          0 :         char mempool_name[24] = {'\0'};
     161                 :            :         char *mp_name = NULL;
     162                 :            :         uint64_t *meta_aura;
     163                 :            :         int rc;
     164                 :            : 
     165         [ #  # ]:          0 :         if (!idev)
     166                 :            :                 return -EINVAL;
     167                 :            : 
     168                 :            :         inl_cfg = &idev->inl_cfg;
     169                 :          0 :         meta_aura = &roc_nix->meta_aura_handle;
     170                 :          0 :         snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
     171         [ #  # ]:          0 :                  roc_nix->port_id + 1);
     172                 :            :         mp_name = mempool_name;
     173                 :            : 
     174                 :            :         /* Destroy existing Meta aura */
     175         [ #  # ]:          0 :         if (*meta_aura) {
     176                 :            :                 uint64_t avail, limit;
     177                 :            : 
     178                 :            :                 /* Check if all buffers are back to pool */
     179                 :            :                 avail = roc_npa_aura_op_available(*meta_aura);
     180                 :            :                 limit = roc_npa_aura_op_limit_get(*meta_aura);
     181                 :            :                 if (avail != limit)
     182                 :            :                         plt_warn("Not all buffers are back to meta pool,"
     183                 :            :                                  " %" PRIu64 " != %" PRIu64, avail, limit);
     184                 :            : 
     185                 :          0 :                 rc = custom_meta_pool_cb(inl_cfg->meta_mempool, &roc_nix->meta_mempool, mp_name,
     186                 :            :                                          meta_aura, 0, 0, true);
     187         [ #  # ]:          0 :                 if (rc) {
     188                 :          0 :                         plt_err("Failed to destroy meta aura, rc=%d", rc);
     189                 :          0 :                         return rc;
     190                 :            :                 }
     191                 :            : 
     192                 :          0 :                 roc_nix->buf_sz = 0;
     193                 :            :         }
     194                 :            : 
     195                 :            :         return 0;
     196                 :            : }
     197                 :            : 
     198                 :            : static int
     199                 :          0 : nix_inl_custom_meta_aura_create(struct idev_cfg *idev, struct roc_nix *roc_nix, uint16_t first_skip,
     200                 :            :                                 uint64_t *meta_aura)
     201                 :            : {
     202                 :            :         uint64_t mask = BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC);
     203                 :            :         struct idev_nix_inl_cfg *inl_cfg;
     204                 :            :         struct nix_inl_dev *nix_inl_dev;
     205                 :          0 :         char mempool_name[24] = {'\0'};
     206                 :            :         uint32_t nb_bufs, buf_sz;
     207                 :            :         char *mp_name = NULL;
     208                 :            :         uintptr_t mp;
     209                 :            :         int rc;
     210                 :            : 
     211                 :            :         inl_cfg = &idev->inl_cfg;
     212                 :          0 :         nix_inl_dev = idev->nix_inl_dev;
     213                 :            : 
     214                 :            :         /* Override meta buf count from devargs if present */
     215   [ #  #  #  # ]:          0 :         if (nix_inl_dev && nix_inl_dev->nb_meta_bufs)
     216                 :            :                 nb_bufs = nix_inl_dev->nb_meta_bufs;
     217                 :            :         else
     218                 :          0 :                 nb_bufs = roc_npa_buf_type_limit_get(mask);
     219                 :            : 
     220                 :            :         /* Override meta buf size from devargs if present */
     221   [ #  #  #  # ]:          0 :         if (nix_inl_dev && nix_inl_dev->meta_buf_sz)
     222                 :            :                 buf_sz = nix_inl_dev->meta_buf_sz;
     223                 :            :         else
     224                 :          0 :                 buf_sz = first_skip + NIX_INL_META_SIZE;
     225                 :            : 
     226                 :            :         /* Create Metapool name */
     227                 :          0 :         snprintf(mempool_name, sizeof(mempool_name), "NIX_INL_META_POOL_%d",
     228                 :          0 :                  roc_nix->port_id + 1);
     229                 :            :         mp_name = mempool_name;
     230                 :            : 
     231                 :            :         /* Allocate meta aura */
     232                 :          0 :         rc = custom_meta_pool_cb(inl_cfg->meta_mempool, &mp, mp_name, meta_aura,
     233                 :            :                                  buf_sz, nb_bufs, false);
     234         [ #  # ]:          0 :         if (rc) {
     235                 :          0 :                 plt_err("Failed to allocate meta aura, rc=%d", rc);
     236                 :          0 :                 return rc;
     237                 :            :         }
     238                 :            : 
     239                 :            :         /* Overwrite */
     240                 :          0 :         roc_nix->meta_mempool = mp;
     241                 :          0 :         roc_nix->buf_sz = buf_sz;
     242                 :            : 
     243                 :          0 :         return 0;
     244                 :            : }
     245                 :            : 
     246                 :            : static int
     247                 :          0 : nix_inl_global_meta_buffer_validate(struct idev_cfg *idev, struct roc_nix_rq *rq)
     248                 :            : {
     249                 :            :         struct idev_nix_inl_cfg *inl_cfg;
     250                 :            :         uint32_t actual, expected;
     251                 :            :         uint64_t mask, type_mask;
     252                 :            : 
     253                 :            :         inl_cfg = &idev->inl_cfg;
     254                 :            :         /* Validate if we have enough meta buffers */
     255                 :            :         mask = BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC);
     256                 :          0 :         expected = roc_npa_buf_type_limit_get(mask);
     257                 :          0 :         actual = inl_cfg->nb_bufs;
     258                 :            : 
     259         [ #  # ]:          0 :         if (actual < expected) {
     260                 :          0 :                 plt_err("Insufficient buffers in meta aura %u < %u (expected)",
     261                 :            :                         actual, expected);
     262                 :          0 :                 return -EIO;
     263                 :            :         }
     264                 :            : 
     265                 :            :         /* Validate if we have enough space for meta buffer */
     266         [ #  # ]:          0 :         if (rq->first_skip + NIX_INL_META_SIZE > inl_cfg->buf_sz) {
     267                 :          0 :                 plt_err("Meta buffer size %u not sufficient to meet RQ first skip %u",
     268                 :            :                         inl_cfg->buf_sz, rq->first_skip);
     269                 :          0 :                 return -EIO;
     270                 :            :         }
     271                 :            : 
     272                 :            :         /* Validate if we have enough VWQE buffers */
     273         [ #  # ]:          0 :         if (rq->vwqe_ena) {
     274                 :          0 :                 actual = roc_npa_aura_op_limit_get(rq->vwqe_aura_handle);
     275                 :            : 
     276                 :          0 :                 type_mask = roc_npa_buf_type_mask(rq->vwqe_aura_handle);
     277         [ #  # ]:          0 :                 if (type_mask & BIT_ULL(ROC_NPA_BUF_TYPE_VWQE_IPSEC) &&
     278                 :            :                     type_mask & BIT_ULL(ROC_NPA_BUF_TYPE_VWQE)) {
     279                 :            :                         /* VWQE aura shared b/w Inline enabled and non Inline
     280                 :            :                          * enabled ports needs enough buffers to store all the
     281                 :            :                          * packet buffers, one per vwqe.
     282                 :            :                          */
     283                 :            :                         mask = (BIT_ULL(ROC_NPA_BUF_TYPE_PACKET_IPSEC) |
     284                 :            :                                 BIT_ULL(ROC_NPA_BUF_TYPE_PACKET));
     285                 :          0 :                         expected = roc_npa_buf_type_limit_get(mask);
     286                 :            : 
     287         [ #  # ]:          0 :                         if (actual < expected) {
     288                 :          0 :                                 plt_err("VWQE aura shared b/w Inline inbound and non-Inline "
     289                 :            :                                         "ports needs vwqe bufs(%u) minimum of all pkt bufs (%u)",
     290                 :            :                                         actual, expected);
     291                 :          0 :                                 return -EIO;
     292                 :            :                         }
     293                 :            :                 } else {
     294                 :            :                         /* VWQE aura not shared b/w Inline and non Inline ports have relaxed
     295                 :            :                          * requirement of match all the meta buffers.
     296                 :            :                          */
     297                 :          0 :                         expected = inl_cfg->nb_bufs;
     298                 :            : 
     299         [ #  # ]:          0 :                         if (actual < expected) {
     300                 :          0 :                                 plt_err("VWQE aura not shared b/w Inline inbound and non-Inline "
     301                 :            :                                         "ports needs vwqe bufs(%u) minimum of all meta bufs (%u)",
     302                 :            :                                         actual, expected);
     303                 :          0 :                                 return -EIO;
     304                 :            :                         }
     305                 :            :                 }
     306                 :            :         }
     307                 :            :         return 0;
     308                 :            : }
     309                 :            : 
     310                 :            : static int
     311                 :          0 : nix_inl_local_meta_buffer_validate(struct roc_nix *roc_nix, struct roc_nix_rq *rq)
     312                 :            : {
     313                 :            :         uint32_t buf_sz = NIX_INL_META_SIZE;
     314                 :            : 
     315         [ #  # ]:          0 :         buf_sz += roc_nix->def_first_skip ? roc_nix->def_first_skip : rq->first_skip;
     316                 :            : 
     317                 :            :         /* Validate if we have enough space for meta buffer */
     318   [ #  #  #  # ]:          0 :         if (roc_nix->buf_sz && (buf_sz > roc_nix->buf_sz)) {
     319                 :          0 :                 plt_err("Meta buffer size %u is not sufficient to meet minimum required %u",
     320                 :            :                         roc_nix->buf_sz, buf_sz);
     321                 :          0 :                 return -EIO;
     322                 :            :         }
     323                 :            : 
     324                 :            :         /* TODO: Validate VWQE buffers */
     325                 :            : 
     326                 :            :         return 0;
     327                 :            : }
     328                 :            : 
     329                 :            : int
     330                 :          0 : roc_nix_inl_meta_aura_check(struct roc_nix *roc_nix, struct roc_nix_rq *rq)
     331                 :            : {
     332                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     333                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     334                 :            :         struct idev_nix_inl_cfg *inl_cfg;
     335                 :            :         bool is_local_metaaura;
     336                 :            :         bool aura_setup = false;
     337                 :            :         uint64_t *meta_aura;
     338                 :            :         int rc;
     339                 :            : 
     340   [ #  #  #  # ]:          0 :         if (!idev || !meta_pool_cb)
     341                 :            :                 return -EFAULT;
     342                 :            : 
     343                 :            :         inl_cfg = &idev->inl_cfg;
     344                 :            : 
     345                 :            :         /* Create meta aura if not present */
     346   [ #  #  #  # ]:          0 :         if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena) {
     347                 :          0 :                 meta_aura = &inl_cfg->meta_aura;
     348                 :          0 :                 is_local_metaaura = false;
     349                 :            :         } else {
     350                 :          0 :                 meta_aura = &roc_nix->meta_aura_handle;
     351                 :            :                 is_local_metaaura = true;
     352                 :            :         }
     353                 :            : 
     354         [ #  # ]:          0 :         if (!(*meta_aura)) {
     355                 :          0 :                 rc = nix_inl_meta_aura_create(idev, roc_nix, rq->first_skip, meta_aura,
     356                 :            :                                               is_local_metaaura);
     357         [ #  # ]:          0 :                 if (rc)
     358                 :            :                         return rc;
     359                 :            : 
     360                 :            :                 aura_setup = true;
     361                 :            :         }
     362                 :            : 
     363         [ #  # ]:          0 :         if (roc_nix->custom_meta_aura_ena) {
     364                 :            :                 /* Create metaura for 1:N pool:aura */
     365         [ #  # ]:          0 :                 if (!custom_meta_pool_cb)
     366                 :            :                         return -EFAULT;
     367                 :            : 
     368                 :          0 :                 meta_aura = &roc_nix->meta_aura_handle;
     369         [ #  # ]:          0 :                 if (!(*meta_aura)) {
     370                 :          0 :                         rc = nix_inl_custom_meta_aura_create(idev, roc_nix, rq->first_skip,
     371                 :            :                                                              meta_aura);
     372         [ #  # ]:          0 :                         if (rc)
     373                 :            :                                 return rc;
     374                 :            : 
     375                 :            :                         aura_setup = true;
     376                 :            :                 }
     377                 :            :         }
     378                 :            : 
     379                 :            :         /* Update rq meta aura handle */
     380                 :          0 :         rq->meta_aura_handle = *meta_aura;
     381                 :            : 
     382         [ #  # ]:          0 :         if (roc_nix->local_meta_aura_ena) {
     383                 :          0 :                 rc = nix_inl_local_meta_buffer_validate(roc_nix, rq);
     384         [ #  # ]:          0 :                 if (rc)
     385                 :            :                         return rc;
     386                 :            : 
     387                 :            :                 /* Check for TC config on RQ 0 when local meta aura is used as
     388                 :            :                  * inline meta aura creation is delayed.
     389                 :            :                  */
     390   [ #  #  #  #  :          0 :                 if (aura_setup && nix->rqs[0] && nix->rqs[0]->tc != ROC_NIX_PFC_CLASS_INVALID)
                   #  # ]
     391                 :          0 :                         roc_nix_fc_npa_bp_cfg(roc_nix, roc_nix->meta_aura_handle,
     392                 :            :                                               true, false, nix->rqs[0]->tc, ROC_NIX_AURA_THRESH);
     393                 :            :         } else {
     394                 :          0 :                 rc = nix_inl_global_meta_buffer_validate(idev, rq);
     395         [ #  # ]:          0 :                 if (rc)
     396                 :          0 :                         return rc;
     397                 :            :         }
     398                 :            : 
     399                 :            :         return 0;
     400                 :            : }
     401                 :            : 
     402                 :            : static int
     403                 :          0 : nix_inl_inb_ipsec_sa_tbl_setup(struct roc_nix *roc_nix)
     404                 :            : {
     405                 :          0 :         uint32_t ipsec_in_min_spi = roc_nix->ipsec_in_min_spi;
     406                 :          0 :         uint32_t ipsec_in_max_spi = roc_nix->ipsec_in_max_spi;
     407                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     408                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     409                 :            :         struct nix_inl_dev *inl_dev = NULL;
     410                 :            :         uint64_t max_sa, i, sa_pow2_sz;
     411                 :            :         uint64_t sa_idx_w, lenm1_max;
     412                 :            :         uint64_t res_addr_offset;
     413                 :            :         uint8_t profile_id = 0;
     414                 :            :         struct mbox *mbox;
     415                 :            :         size_t inb_sa_sz;
     416                 :            :         void *sa;
     417                 :            :         int rc;
     418                 :            : 
     419                 :            :         /* Setup default IPsec profile */
     420         [ #  # ]:          0 :         if (roc_feature_nix_has_inl_profile()) {
     421                 :          0 :                 rc = nix_inl_setup_dflt_ipsec_profile(&nix->dev, &nix->ipsec_prof_id);
     422         [ #  # ]:          0 :                 if (rc)
     423                 :            :                         return rc;
     424                 :          0 :                 profile_id = nix->ipsec_prof_id;
     425                 :            :         }
     426                 :            : 
     427                 :          0 :         mbox = mbox_get(nix->dev.mbox);
     428                 :            : 
     429         [ #  # ]:          0 :         max_sa = plt_align32pow2(ipsec_in_max_spi - ipsec_in_min_spi + 1);
     430                 :            : 
     431                 :            :         /* CN9K SA size is different */
     432         [ #  # ]:          0 :         if (roc_nix->custom_inb_sa)
     433                 :            :                 inb_sa_sz = ROC_NIX_INL_INB_CUSTOM_SA_SZ;
     434                 :            :         else
     435                 :            :                 inb_sa_sz = ROC_NIX_INL_IPSEC_INB_SA_SZ;
     436                 :            : 
     437                 :            :         /* Alloc contiguous memory for Inbound SA's */
     438                 :          0 :         nix->inb_sa_sz[profile_id] = inb_sa_sz;
     439                 :          0 :         nix->inb_sa_max[profile_id] = max_sa;
     440                 :          0 :         nix->inb_spi_mask = max_sa - 1;
     441                 :          0 :         nix->inb_sa_base[profile_id] = plt_zmalloc(inb_sa_sz * max_sa, ROC_NIX_INL_SA_BASE_ALIGN);
     442         [ #  # ]:          0 :         if (!nix->inb_sa_base[profile_id]) {
     443                 :            :                 rc = -ENOMEM;
     444                 :          0 :                 plt_err("Failed to allocate memory for Inbound SA");
     445                 :          0 :                 goto exit;
     446                 :            :         }
     447                 :            : 
     448         [ #  # ]:          0 :         sa_pow2_sz = plt_log2_u32(inb_sa_sz);
     449                 :          0 :         sa_idx_w = plt_log2_u32(max_sa);
     450         [ #  # ]:          0 :         lenm1_max = roc_nix_max_pkt_len(roc_nix) - 1;
     451                 :            : 
     452         [ #  # ]:          0 :         if (!roc_model_is_cn9k()) {
     453         [ #  # ]:          0 :                 for (i = 0; i < max_sa; i++) {
     454         [ #  # ]:          0 :                         sa = ((uint8_t *)nix->inb_sa_base[profile_id]) + (i * inb_sa_sz);
     455         [ #  # ]:          0 :                         if (roc_model_is_cn10k())
     456                 :          0 :                                 roc_ot_ipsec_inb_sa_init(sa);
     457                 :            :                         else
     458                 :          0 :                                 roc_ow_ipsec_inb_sa_init(sa);
     459                 :            :                 }
     460                 :            :         }
     461                 :            : 
     462   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() || roc_model_is_cn10k()) {
     463                 :            :                 struct nix_inline_ipsec_lf_cfg *lf_cfg;
     464                 :            : 
     465                 :            :                 /* Setup device specific inb SA table */
     466                 :          0 :                 lf_cfg = mbox_alloc_msg_nix_inline_ipsec_lf_cfg(mbox);
     467         [ #  # ]:          0 :                 if (lf_cfg == NULL) {
     468                 :            :                         rc = -ENOSPC;
     469                 :          0 :                         plt_err("Failed to alloc nix inline ipsec lf cfg mbox msg");
     470                 :          0 :                         goto free_mem;
     471                 :            :                 }
     472                 :            : 
     473                 :          0 :                 lf_cfg->enable = 1;
     474                 :          0 :                 lf_cfg->sa_base_addr = (uintptr_t)nix->inb_sa_base[profile_id];
     475                 :          0 :                 lf_cfg->ipsec_cfg1.sa_idx_w = sa_idx_w;
     476                 :          0 :                 lf_cfg->ipsec_cfg0.lenm1_max = lenm1_max;
     477                 :          0 :                 lf_cfg->ipsec_cfg1.sa_idx_max = max_sa - 1;
     478                 :          0 :                 lf_cfg->ipsec_cfg0.sa_pow2_size = sa_pow2_sz;
     479                 :          0 :                 lf_cfg->ipsec_cfg0.tag_const = 0;
     480                 :          0 :                 lf_cfg->ipsec_cfg0.tt = SSO_TT_ORDERED;
     481         [ #  # ]:          0 :                 if (roc_nix->res_addr_offset) {
     482                 :          0 :                         lf_cfg->ipsec_cfg0_ext.res_addr_offset_valid = 1;
     483                 :          0 :                         lf_cfg->ipsec_cfg0_ext.res_addr_offset =
     484                 :          0 :                                 (roc_nix->res_addr_offset & 0x80) | abs(roc_nix->res_addr_offset);
     485                 :            :                 }
     486                 :            :         } else {
     487                 :            :                 struct nix_rx_inl_lf_cfg_req *lf_cfg;
     488                 :            :                 uint64_t def_cptq = 0;
     489                 :            :                 uint64_t cpt_cq_ena = 0;
     490                 :            : 
     491                 :            :                 /* Setup device specific inb SA table */
     492                 :          0 :                 lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
     493         [ #  # ]:          0 :                 if (lf_cfg == NULL) {
     494                 :            :                         rc = -ENOSPC;
     495                 :          0 :                         plt_err("Failed to alloc nix inline ipsec lf cfg mbox msg");
     496                 :          0 :                         goto free_mem;
     497                 :            :                 }
     498                 :            : 
     499                 :            :                 /*TODO default cptq */
     500   [ #  #  #  # ]:          0 :                 if (idev && idev->nix_inl_dev) {
     501                 :            :                         inl_dev = idev->nix_inl_dev;
     502         [ #  # ]:          0 :                         if (!inl_dev->nb_inb_cptlfs)
     503                 :            :                                 def_cptq = 0;
     504                 :            :                         else
     505                 :          0 :                                 def_cptq = inl_dev->nix_inb_qids[inl_dev->inb_cpt_lf_id];
     506                 :            :                 }
     507                 :            : 
     508                 :          0 :                 res_addr_offset = (uint64_t)(inl_dev->res_addr_offset & 0xFF) << 48;
     509         [ #  # ]:          0 :                 if (res_addr_offset)
     510                 :          0 :                         res_addr_offset |= (1UL << 56);
     511                 :            : 
     512                 :          0 :                 cpt_cq_ena = (uint64_t)inl_dev->cpt_cq_ena << 63;
     513                 :          0 :                 lf_cfg->enable = 1;
     514                 :          0 :                 lf_cfg->profile_id = profile_id; /* IPsec profile is 0th one */
     515                 :          0 :                 lf_cfg->rx_inline_sa_base = (uintptr_t)nix->inb_sa_base[profile_id] | cpt_cq_ena;
     516                 :          0 :                 lf_cfg->rx_inline_cfg0 =
     517                 :          0 :                         ((def_cptq << 57) | res_addr_offset | ((uint64_t)SSO_TT_ORDERED << 44) |
     518                 :          0 :                          (sa_pow2_sz << 16) | lenm1_max);
     519                 :          0 :                 lf_cfg->rx_inline_cfg1 = (max_sa - 1) | (sa_idx_w << 32);
     520                 :            :         }
     521                 :            : 
     522                 :          0 :         rc = mbox_process(mbox);
     523         [ #  # ]:          0 :         if (rc) {
     524                 :          0 :                 plt_err("Failed to setup NIX Inbound SA conf, rc=%d", rc);
     525                 :          0 :                 goto free_mem;
     526                 :            :         }
     527                 :            : 
     528                 :            :         mbox_put(mbox);
     529                 :          0 :         return 0;
     530                 :          0 : free_mem:
     531                 :          0 :         plt_free(nix->inb_sa_base[profile_id]);
     532                 :          0 :         nix->inb_sa_base[profile_id] = NULL;
     533                 :          0 : exit:
     534                 :            :         mbox_put(mbox);
     535                 :          0 :         return rc;
     536                 :            : }
     537                 :            : 
     538                 :            : static int
     539                 :          0 : nix_inl_ipsec_sa_tbl_release(struct roc_nix *roc_nix)
     540                 :            : {
     541                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     542                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     543                 :            :         uint8_t profile_id = 0;
     544                 :            :         int rc;
     545                 :            : 
     546   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() || roc_model_is_cn10k()) {
     547                 :            :                 struct nix_inline_ipsec_lf_cfg *lf_cfg;
     548                 :            : 
     549                 :          0 :                 lf_cfg = mbox_alloc_msg_nix_inline_ipsec_lf_cfg(mbox);
     550         [ #  # ]:          0 :                 if (lf_cfg == NULL) {
     551                 :            :                         rc = -ENOSPC;
     552                 :          0 :                         goto exit;
     553                 :            :                 }
     554                 :            : 
     555                 :          0 :                 lf_cfg->enable = 0;
     556                 :            :         } else {
     557                 :            :                 struct nix_rx_inl_lf_cfg_req *lf_cfg;
     558                 :            : 
     559                 :          0 :                 profile_id = nix->ipsec_prof_id;
     560                 :          0 :                 lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
     561         [ #  # ]:          0 :                 if (!lf_cfg) {
     562                 :            :                         rc = -ENOSPC;
     563                 :          0 :                         goto exit;
     564                 :            :                 }
     565                 :            : 
     566                 :          0 :                 lf_cfg->enable = 0;
     567                 :          0 :                 lf_cfg->profile_id = profile_id; /* IPsec profile is 0th one */
     568                 :            :         }
     569                 :            : 
     570                 :          0 :         rc = mbox_process(mbox);
     571         [ #  # ]:          0 :         if (rc) {
     572                 :          0 :                 plt_err("Failed to cleanup NIX Inbound SA conf, rc=%d", rc);
     573                 :          0 :                 goto exit;
     574                 :            :         }
     575                 :            : 
     576                 :          0 :         plt_free(nix->inb_sa_base[profile_id]);
     577                 :          0 :         nix->inb_sa_base[profile_id] = NULL;
     578                 :          0 : exit:
     579                 :            :         mbox_put(mbox);
     580                 :          0 :         return rc;
     581                 :            : }
     582                 :            : 
     583                 :            : static int
     584                 :          0 : nix_inl_reass_inb_sa_tbl_setup(struct roc_nix *roc_nix)
     585                 :            : {
     586                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     587                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     588                 :            :         struct nix_rx_inl_lf_cfg_req *lf_cfg;
     589                 :            :         struct nix_inl_dev *inl_dev = NULL;
     590                 :            :         uint64_t max_sa = 1, sa_pow2_sz;
     591                 :            :         uint64_t sa_idx_w, lenm1_max;
     592                 :            :         uint64_t res_addr_offset = 0;
     593                 :            :         uint64_t cpt_cq_ena = 0;
     594                 :            :         uint64_t def_cptq = 0;
     595                 :            :         size_t inb_sa_sz = ROC_NIX_INL_OW_IPSEC_INB_SA_SZ;
     596                 :            :         uint8_t profile_id;
     597                 :            :         struct mbox *mbox;
     598                 :            :         void *sa;
     599                 :            :         int rc;
     600                 :            : 
     601         [ #  # ]:          0 :         if (!roc_nix->reass_ena)
     602                 :            :                 return 0;
     603                 :            : 
     604                 :          0 :         rc = nix_inl_setup_reass_profile(&nix->dev, &nix->reass_prof_id);
     605         [ #  # ]:          0 :         if (rc)
     606                 :            :                 return rc;
     607                 :            : 
     608                 :          0 :         profile_id = nix->reass_prof_id;
     609                 :          0 :         nix->inb_sa_sz[profile_id] = inb_sa_sz;
     610                 :          0 :         nix->inb_sa_max[profile_id] = max_sa;
     611                 :          0 :         nix->inb_spi_mask = 1;
     612                 :          0 :         nix->inb_sa_base[profile_id] = plt_zmalloc(inb_sa_sz * max_sa, ROC_NIX_INL_SA_BASE_ALIGN);
     613         [ #  # ]:          0 :         if (!nix->inb_sa_base[profile_id]) {
     614                 :          0 :                 plt_err("Failed to allocate memory for reassembly Inbound SA");
     615                 :          0 :                 return -ENOMEM;
     616                 :            :         }
     617                 :            : 
     618                 :            :         sa = ((uint8_t *)nix->inb_sa_base[profile_id]);
     619                 :          0 :         roc_ow_reass_inb_sa_init(sa);
     620                 :            : 
     621                 :          0 :         mbox = mbox_get(nix->dev.mbox);
     622                 :            :         /* Setup device specific inb SA table */
     623                 :          0 :         lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
     624         [ #  # ]:          0 :         if (lf_cfg == NULL) {
     625                 :            :                 rc = -ENOSPC;
     626                 :          0 :                 plt_err("Failed to alloc nix inline reassembly lf cfg mbox msg");
     627                 :          0 :                 goto free_mem;
     628                 :            :         }
     629                 :            : 
     630                 :            :         sa_pow2_sz = plt_log2_u32(inb_sa_sz);
     631                 :            :         sa_idx_w = plt_log2_u32(max_sa);
     632                 :          0 :         lenm1_max = roc_nix_max_pkt_len(roc_nix) - 1;
     633                 :            : 
     634   [ #  #  #  # ]:          0 :         if (idev && idev->nix_inl_dev) {
     635                 :            :                 inl_dev = idev->nix_inl_dev;
     636         [ #  # ]:          0 :                 if (inl_dev->nb_inb_cptlfs)
     637                 :          0 :                         def_cptq = inl_dev->nix_inb_qids[inl_dev->inb_cpt_lf_id];
     638                 :          0 :                 res_addr_offset = (uint64_t)(inl_dev->res_addr_offset & 0xFF) << 48;
     639         [ #  # ]:          0 :                 if (res_addr_offset)
     640                 :          0 :                         res_addr_offset |= (1UL << 56);
     641                 :            :         }
     642                 :            : 
     643                 :          0 :         cpt_cq_ena = (uint64_t)inl_dev->cpt_cq_ena << 63;
     644                 :          0 :         lf_cfg->enable = 1;
     645                 :          0 :         lf_cfg->profile_id = profile_id;
     646                 :          0 :         lf_cfg->rx_inline_sa_base = (uintptr_t)nix->inb_sa_base[profile_id] | cpt_cq_ena;
     647                 :          0 :         lf_cfg->rx_inline_cfg0 =
     648                 :          0 :                 ((def_cptq << 57) | res_addr_offset | ((uint64_t)SSO_TT_ORDERED << 44) |
     649                 :          0 :                  (sa_pow2_sz << 16) | lenm1_max);
     650                 :          0 :         lf_cfg->rx_inline_cfg1 = (max_sa - 1) | (sa_idx_w << 32);
     651                 :            : 
     652                 :          0 :         rc = mbox_process(mbox);
     653         [ #  # ]:          0 :         if (rc) {
     654                 :          0 :                 plt_err("Failed to setup NIX Inbound reassembly SA conf, rc=%d", rc);
     655                 :          0 :                 goto free_mem;
     656                 :            :         }
     657                 :            : 
     658                 :            :         mbox_put(mbox);
     659                 :          0 :         return 0;
     660                 :            : 
     661                 :          0 : free_mem:
     662                 :          0 :         plt_free(nix->inb_sa_base[profile_id]);
     663                 :          0 :         nix->inb_sa_base[profile_id] = NULL;
     664                 :            :         mbox_put(mbox);
     665                 :          0 :         return rc;
     666                 :            : }
     667                 :            : 
     668                 :            : static int
     669                 :          0 : nix_inl_reass_sa_tbl_release(struct roc_nix *roc_nix)
     670                 :            : {
     671                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     672                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     673                 :            :         struct nix_rx_inl_lf_cfg_req *lf_cfg;
     674                 :            :         uint8_t profile_id;
     675                 :            :         int rc;
     676                 :            : 
     677         [ #  # ]:          0 :         if (!roc_nix->reass_ena)
     678                 :            :                 return 0;
     679                 :            : 
     680                 :          0 :         lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
     681         [ #  # ]:          0 :         if (!lf_cfg) {
     682                 :            :                 rc = -ENOSPC;
     683                 :          0 :                 goto exit;
     684                 :            :         }
     685                 :            : 
     686                 :          0 :         profile_id = nix->reass_prof_id;
     687                 :            : 
     688                 :          0 :         lf_cfg->enable = 0;
     689                 :          0 :         lf_cfg->profile_id = profile_id;
     690                 :          0 :         rc = mbox_process(mbox);
     691         [ #  # ]:          0 :         if (rc) {
     692                 :          0 :                 plt_err("Failed to cleanup NIX Inbound Reassembly SA conf, rc=%d", rc);
     693                 :          0 :                 goto exit;
     694                 :            :         }
     695                 :            : 
     696                 :          0 :         plt_free(nix->inb_sa_base[profile_id]);
     697                 :          0 :         nix->inb_sa_base[profile_id] = NULL;
     698                 :          0 : exit:
     699                 :            :         mbox_put(mbox);
     700                 :          0 :         return rc;
     701                 :            : }
     702                 :            : 
     703                 :            : struct roc_cpt_lf *
     704                 :          0 : roc_nix_inl_outb_lf_base_get(struct roc_nix *roc_nix)
     705                 :            : {
     706                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     707                 :            : 
     708                 :            :         /* NIX Inline config needs to be done */
     709   [ #  #  #  # ]:          0 :         if (!nix->inl_outb_ena || !nix->cpt_lf_base)
     710                 :          0 :                 return NULL;
     711                 :            : 
     712                 :            :         return (struct roc_cpt_lf *)nix->cpt_lf_base;
     713                 :            : }
     714                 :            : 
     715                 :            : struct roc_cpt_lf *
     716                 :          0 : roc_nix_inl_inb_inj_lf_get(struct roc_nix *roc_nix)
     717                 :            : {
     718                 :            :         struct nix *nix;
     719                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     720                 :            :         struct nix_inl_dev *inl_dev = NULL;
     721                 :            :         struct roc_cpt_lf *lf = NULL;
     722                 :            : 
     723         [ #  # ]:          0 :         if (!idev)
     724                 :            :                 return NULL;
     725                 :            : 
     726                 :          0 :         inl_dev = idev->nix_inl_dev;
     727                 :            : 
     728         [ #  # ]:          0 :         if (!inl_dev && roc_nix == NULL)
     729                 :            :                 return NULL;
     730                 :            : 
     731                 :            :         nix = roc_nix_to_nix_priv(roc_nix);
     732                 :            : 
     733   [ #  #  #  #  :          0 :         if (nix->inb_inl_dev && inl_dev && inl_dev->attach_cptlf &&
                   #  # ]
     734         [ #  # ]:          0 :             inl_dev->rx_inj_ena)
     735                 :          0 :                 return &inl_dev->cpt_lf[inl_dev->nb_cptlf - 1];
     736                 :            : 
     737                 :          0 :         lf = roc_nix_inl_outb_lf_base_get(roc_nix);
     738         [ #  # ]:          0 :         if (lf)
     739                 :          0 :                 lf += roc_nix->outb_nb_crypto_qs;
     740                 :            :         return lf;
     741                 :            : }
     742                 :            : 
     743                 :            : uintptr_t
     744                 :          0 : roc_nix_inl_outb_sa_base_get(struct roc_nix *roc_nix)
     745                 :            : {
     746                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     747                 :            : 
     748                 :          0 :         return (uintptr_t)nix->outb_sa_base;
     749                 :            : }
     750                 :            : 
     751                 :            : uintptr_t
     752                 :          0 : roc_nix_inl_inb_sa_base_get(struct roc_nix *roc_nix, bool inb_inl_dev)
     753                 :            : {
     754                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     755                 :            :         struct nix_inl_dev *inl_dev;
     756                 :            :         struct nix *nix = NULL;
     757                 :            : 
     758         [ #  # ]:          0 :         if (idev == NULL)
     759                 :            :                 return 0;
     760                 :            : 
     761         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
     762                 :            :                 return -EINVAL;
     763                 :            : 
     764         [ #  # ]:          0 :         if (roc_nix) {
     765                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     766         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
     767                 :            :                         return 0;
     768                 :            :         }
     769                 :            : 
     770         [ #  # ]:          0 :         if (inb_inl_dev) {
     771                 :          0 :                 inl_dev = idev->nix_inl_dev;
     772                 :            :                 /* Return inline dev sa base */
     773         [ #  # ]:          0 :                 if (inl_dev)
     774                 :          0 :                         return (uintptr_t)inl_dev->inb_sa_base[inl_dev->ipsec_prof_id];
     775                 :            :                 return 0;
     776                 :            :         }
     777                 :            : 
     778                 :          0 :         return (uintptr_t)nix->inb_sa_base[nix->ipsec_prof_id];
     779                 :            : }
     780                 :            : 
     781                 :            : uintptr_t
     782                 :          0 : roc_nix_inl_inb_prof_sa_base_get(struct roc_nix *roc_nix, bool inb_inl_dev, uint16_t profile_id)
     783                 :            : {
     784                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     785                 :            :         struct nix_inl_dev *inl_dev;
     786                 :            :         struct nix *nix = NULL;
     787                 :            : 
     788                 :            :         /* Validate profile_id range */
     789         [ #  # ]:          0 :         if (profile_id >= ROC_NIX_INL_PROFILE_CNT) {
     790                 :          0 :                 plt_err("Invalid profile_id %u, must be < %u", profile_id, ROC_NIX_INL_PROFILE_CNT);
     791                 :          0 :                 return 0;
     792                 :            :         }
     793                 :            : 
     794         [ #  # ]:          0 :         if (idev == NULL)
     795                 :            :                 return 0;
     796                 :            : 
     797         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
     798                 :            :                 return 0;
     799                 :            : 
     800         [ #  # ]:          0 :         if (roc_nix) {
     801                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     802         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
     803                 :            :                         return 0;
     804                 :            :         }
     805                 :            : 
     806         [ #  # ]:          0 :         if (inb_inl_dev) {
     807                 :          0 :                 inl_dev = idev->nix_inl_dev;
     808                 :            :                 /* Return inline dev sa base for the specified profile */
     809         [ #  # ]:          0 :                 if (inl_dev)
     810                 :          0 :                         return (uintptr_t)inl_dev->inb_sa_base[profile_id];
     811                 :            :                 return 0;
     812                 :            :         }
     813                 :            : 
     814                 :            :         /* Return NIX sa base for the specified profile */
     815                 :          0 :         return (uintptr_t)nix->inb_sa_base[profile_id];
     816                 :            : }
     817                 :            : 
     818                 :            : uint16_t
     819                 :          0 : roc_nix_inl_inb_ipsec_profile_id_get(struct roc_nix *roc_nix, bool inb_inl_dev)
     820                 :            : {
     821                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     822                 :            :         struct nix_inl_dev *inl_dev;
     823                 :            :         struct nix *nix = NULL;
     824                 :            : 
     825         [ #  # ]:          0 :         if (idev == NULL)
     826                 :            :                 return 0;
     827                 :            : 
     828         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
     829                 :            :                 return -EINVAL;
     830                 :            : 
     831         [ #  # ]:          0 :         if (roc_nix) {
     832                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     833         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
     834                 :            :                         return 0;
     835                 :            :         }
     836                 :            : 
     837         [ #  # ]:          0 :         if (inb_inl_dev) {
     838                 :          0 :                 inl_dev = idev->nix_inl_dev;
     839                 :            :                 /* Return inline Ipsec profile ID */
     840         [ #  # ]:          0 :                 if (inl_dev)
     841                 :          0 :                         return inl_dev->ipsec_prof_id;
     842                 :            :                 return 0;
     843                 :            :         }
     844                 :            : 
     845                 :          0 :         return nix->ipsec_prof_id;
     846                 :            : }
     847                 :            : 
     848                 :            : uint16_t
     849                 :          0 : roc_nix_inl_inb_reass_profile_id_get(struct roc_nix *roc_nix, bool inb_inl_dev)
     850                 :            : {
     851                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     852                 :            :         struct nix_inl_dev *inl_dev;
     853                 :            :         struct nix *nix = NULL;
     854                 :            : 
     855         [ #  # ]:          0 :         if (idev == NULL)
     856                 :            :                 return 0;
     857                 :            : 
     858         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
     859                 :            :                 return -EINVAL;
     860                 :            : 
     861         [ #  # ]:          0 :         if (roc_nix) {
     862                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     863         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
     864                 :            :                         return 0;
     865                 :            :         }
     866                 :            : 
     867         [ #  # ]:          0 :         if (inb_inl_dev) {
     868                 :          0 :                 inl_dev = idev->nix_inl_dev;
     869                 :            :                 /* Return inline reassembly profile ID */
     870         [ #  # ]:          0 :                 if (inl_dev)
     871                 :          0 :                         return inl_dev->reass_prof_id;
     872                 :            :                 return 0;
     873                 :            :         }
     874                 :            : 
     875                 :          0 :         return nix->reass_prof_id;
     876                 :            : }
     877                 :            : 
     878                 :            : static int
     879                 :          0 : nix_inl_custom_profile_sa_tbl_setup(struct roc_nix *roc_nix, uint32_t sa_size, uint32_t max_sa,
     880                 :            :                                     uint16_t profile_id)
     881                 :            : {
     882                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     883                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     884                 :            :         struct nix_inl_dev *inl_dev = NULL;
     885                 :            :         struct nix_rx_inl_lf_cfg_req *lf_cfg;
     886                 :            :         uint64_t res_addr_offset = 0;
     887                 :            :         uint64_t cpt_cq_ena = 0;
     888                 :            :         uint32_t inb_sa_sz;
     889                 :            :         uint32_t lenm1_max;
     890                 :            :         uint64_t def_cptq = 0;
     891                 :            :         struct mbox *mbox;
     892                 :            :         uint8_t sa_pow2_sz;
     893                 :            :         uint8_t sa_w;
     894                 :            :         int rc = 0;
     895                 :            : 
     896                 :            :         /* Validate profile_id range */
     897         [ #  # ]:          0 :         if (profile_id >= ROC_NIX_INL_PROFILE_CNT) {
     898                 :          0 :                 plt_err("Invalid profile_id %u, must be < %u", profile_id, ROC_NIX_INL_PROFILE_CNT);
     899                 :          0 :                 return -EINVAL;
     900                 :            :         }
     901                 :            : 
     902                 :            :         /* Use sa_size parameter if provided, otherwise use default */
     903         [ #  # ]:          0 :         if (sa_size > 0)
     904                 :            :                 inb_sa_sz = sa_size;
     905                 :            :         else
     906                 :            :                 inb_sa_sz = ROC_NIX_INL_OW_IPSEC_INB_SA_SZ;
     907                 :            : 
     908                 :            :         /* Validate max_sa is provided */
     909         [ #  # ]:          0 :         if (max_sa == 0) {
     910                 :          0 :                 plt_err("max_sa must be greater than 0 for profile %u", profile_id);
     911                 :          0 :                 return -EINVAL;
     912                 :            :         }
     913                 :            : 
     914                 :            :         /* Update max_sa */
     915                 :          0 :         nix->inb_sa_max[profile_id] = max_sa;
     916                 :            : 
     917                 :          0 :         nix->inb_sa_sz[profile_id] = inb_sa_sz;
     918                 :          0 :         nix->inb_sa_base[profile_id] = plt_zmalloc(inb_sa_sz * max_sa, ROC_NIX_INL_SA_BASE_ALIGN);
     919         [ #  # ]:          0 :         if (!nix->inb_sa_base[profile_id]) {
     920                 :          0 :                 plt_err("Failed to allocate memory for Inbound SA for profile %u", profile_id);
     921                 :            :                 rc = -ENOMEM;
     922                 :          0 :                 goto exit;
     923                 :            :         }
     924                 :            : 
     925                 :          0 :         mbox = mbox_get(nix->dev.mbox);
     926                 :          0 :         lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
     927         [ #  # ]:          0 :         if (lf_cfg == NULL) {
     928                 :            :                 rc = -ENOSPC;
     929                 :          0 :                 goto free_mem;
     930                 :            :         }
     931                 :            : 
     932                 :            :         lenm1_max = NIX_RPM_MAX_HW_FRS - 1;
     933                 :            :         sa_w = plt_log2_u32(max_sa);
     934                 :            :         sa_pow2_sz = plt_log2_u32(inb_sa_sz);
     935                 :            : 
     936                 :            :         /* Get default CPT queue from inline device if available */
     937   [ #  #  #  # ]:          0 :         if (idev && idev->nix_inl_dev) {
     938                 :            :                 inl_dev = idev->nix_inl_dev;
     939         [ #  # ]:          0 :                 if (!inl_dev->nb_inb_cptlfs)
     940                 :            :                         def_cptq = 0;
     941                 :            :                 else
     942                 :          0 :                         def_cptq = inl_dev->nix_inb_qids[inl_dev->inb_cpt_lf_id];
     943                 :            : 
     944                 :          0 :                 res_addr_offset = (uint64_t)(inl_dev->res_addr_offset & 0xFF) << 48;
     945         [ #  # ]:          0 :                 if (res_addr_offset)
     946                 :          0 :                         res_addr_offset |= (1UL << 56);
     947                 :            : 
     948                 :          0 :                 cpt_cq_ena = (uint64_t)inl_dev->cpt_cq_ena << 63;
     949                 :            :         }
     950                 :            : 
     951                 :          0 :         lf_cfg->enable = 1;
     952                 :          0 :         lf_cfg->profile_id = profile_id;
     953                 :          0 :         lf_cfg->rx_inline_sa_base = (uintptr_t)nix->inb_sa_base[profile_id] | cpt_cq_ena;
     954                 :          0 :         lf_cfg->rx_inline_cfg0 = ((uint64_t)def_cptq << 57) | res_addr_offset |
     955                 :          0 :                                  ((uint64_t)SSO_TT_ORDERED << 44) | (sa_pow2_sz << 16) | lenm1_max;
     956                 :          0 :         lf_cfg->rx_inline_cfg1 = (max_sa - 1) | ((uint64_t)sa_w << 32);
     957                 :            : 
     958                 :          0 :         rc = mbox_process(mbox);
     959         [ #  # ]:          0 :         if (rc) {
     960                 :          0 :                 plt_err("Failed to setup NIX Inbound SA conf of profile=%u, rc=%d", profile_id, rc);
     961                 :          0 :                 goto free_mem;
     962                 :            :         }
     963                 :            : 
     964                 :            :         mbox_put(mbox);
     965                 :          0 :         return rc;
     966                 :            : 
     967                 :          0 : free_mem:
     968                 :            :         mbox_put(mbox);
     969                 :          0 :         plt_free(nix->inb_sa_base[profile_id]);
     970                 :          0 :         nix->inb_sa_base[profile_id] = NULL;
     971                 :            : exit:
     972                 :            :         return rc;
     973                 :            : }
     974                 :            : 
     975                 :            : int
     976                 :          0 : roc_nix_inl_custom_profile_setup(struct roc_nix *roc_nix, uint64_t def_cfg, uint64_t gen_cfg,
     977                 :            :                                  uint64_t extract_cfg, const uint64_t *prot_field_cfg,
     978                 :            :                                  uint32_t sa_size, uint32_t max_sa, bool is_inline,
     979                 :            :                                  uint16_t *profile_id)
     980                 :            : {
     981                 :            :         struct nix_rx_inl_profile_cfg_req *req;
     982                 :            :         struct nix_rx_inl_profile_cfg_rsp *rsp;
     983                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     984                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     985                 :            :         struct nix_inl_dev *inl_dev = NULL;
     986                 :            :         struct mbox *mbox;
     987                 :            :         int rc = 0;
     988                 :            :         int i;
     989                 :            : 
     990         [ #  # ]:          0 :         if (roc_nix == NULL || profile_id == NULL)
     991                 :            :                 return -EINVAL;
     992                 :            : 
     993         [ #  # ]:          0 :         if (!nix->inl_inb_ena)
     994                 :            :                 return -ENOTSUP;
     995                 :            : 
     996                 :            :         /* Get inline device - required for custom profiles */
     997   [ #  #  #  # ]:          0 :         if (!idev || !idev->nix_inl_dev) {
     998                 :          0 :                 plt_err("nix_inl_dev not available for custom profile setup");
     999                 :          0 :                 return -ENODEV;
    1000                 :            :         }
    1001                 :            : 
    1002                 :            :         inl_dev = idev->nix_inl_dev;
    1003                 :            : 
    1004                 :            :         /* Use inline device mbox if is_inline is true, otherwise use nix mbox */
    1005         [ #  # ]:          0 :         if (is_inline)
    1006                 :          0 :                 mbox = mbox_get(inl_dev->dev.mbox);
    1007                 :            :         else
    1008                 :          0 :                 mbox = mbox_get(nix->dev.mbox);
    1009                 :            : 
    1010                 :          0 :         req = mbox_alloc_msg_nix_rx_inl_profile_cfg(mbox);
    1011         [ #  # ]:          0 :         if (req == NULL) {
    1012                 :            :                 rc = -ENOSPC;
    1013         [ #  # ]:          0 :                 plt_err("Failed to alloc %s profile cfg mbox msg",
    1014                 :            :                         is_inline ? "inline device" : "nix device");
    1015                 :            :                 mbox_put(mbox);
    1016                 :          0 :                 goto exit;
    1017                 :            :         }
    1018                 :            : 
    1019                 :          0 :         req->def_cfg = def_cfg;
    1020                 :          0 :         req->gen_cfg = gen_cfg;
    1021                 :          0 :         req->extract_cfg = extract_cfg;
    1022         [ #  # ]:          0 :         for (i = 0; i < NIX_RX_INL_PROFILE_PROTO_CNT; i++)
    1023                 :          0 :                 req->prot_field_cfg[i] = prot_field_cfg[i];
    1024                 :            : 
    1025                 :            :         rc = mbox_process_msg(mbox, (void **)&rsp);
    1026         [ #  # ]:          0 :         if (rc) {
    1027         [ #  # ]:          0 :                 plt_err("Failed to setup %s custom profile, rc=%d",
    1028                 :            :                         is_inline ? "inline device" : "nix device", rc);
    1029                 :            :                 mbox_put(mbox);
    1030                 :          0 :                 goto exit;
    1031                 :            :         }
    1032                 :            : 
    1033                 :          0 :         *profile_id = rsp->profile_id;
    1034                 :            : 
    1035                 :            :         /* Validate returned profile_id */
    1036         [ #  # ]:          0 :         if (*profile_id >= ROC_NIX_INL_PROFILE_CNT) {
    1037                 :          0 :                 plt_err("Hardware returned invalid profile_id %u", *profile_id);
    1038                 :            :                 mbox_put(mbox);
    1039                 :            :                 rc = -EINVAL;
    1040                 :          0 :                 goto exit;
    1041                 :            :         }
    1042                 :            : 
    1043         [ #  # ]:          0 :         plt_info("%s custom profile %u created", is_inline ? "Inline device" : "NIX device",
    1044                 :            :                  *profile_id);
    1045                 :            :         mbox_put(mbox);
    1046                 :            : 
    1047         [ #  # ]:          0 :         if (is_inline)
    1048                 :          0 :                 rc = nix_inl_dev_profile_config(inl_dev, sa_size, max_sa, *profile_id);
    1049                 :            :         else
    1050                 :          0 :                 rc = nix_inl_custom_profile_sa_tbl_setup(roc_nix, sa_size, max_sa, *profile_id);
    1051                 :            : 
    1052         [ #  # ]:          0 :         if (rc) {
    1053                 :          0 :                 plt_err("Failed to configure custom profile %u, rc=%d", *profile_id, rc);
    1054                 :            :                 /* Release the allocated profile on failure */
    1055                 :          0 :                 roc_nix_inl_custom_profile_release(roc_nix, *profile_id, is_inline);
    1056                 :            :         }
    1057                 :            : 
    1058                 :          0 : exit:
    1059                 :            :         return rc;
    1060                 :            : }
    1061                 :            : 
    1062                 :            : int
    1063                 :          0 : roc_nix_inl_custom_profile_release(struct roc_nix *roc_nix, uint16_t profile_id, bool is_inline)
    1064                 :            : {
    1065                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1066                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1067                 :            :         struct nix_inl_dev *inl_dev = NULL;
    1068                 :            :         struct nix_rx_inl_lf_cfg_req *lf_cfg;
    1069                 :            :         struct mbox *mbox;
    1070                 :            :         int rc = 0;
    1071                 :            : 
    1072         [ #  # ]:          0 :         if (roc_nix == NULL)
    1073                 :            :                 return -EINVAL;
    1074                 :            : 
    1075         [ #  # ]:          0 :         if (!nix->inl_inb_ena)
    1076                 :            :                 return -ENOTSUP;
    1077                 :            : 
    1078                 :            :         /* Validate profile_id range */
    1079         [ #  # ]:          0 :         if (profile_id >= ROC_NIX_INL_PROFILE_CNT) {
    1080                 :          0 :                 plt_err("Invalid profile_id %u, must be < %u", profile_id, ROC_NIX_INL_PROFILE_CNT);
    1081                 :          0 :                 return -EINVAL;
    1082                 :            :         }
    1083                 :            : 
    1084         [ #  # ]:          0 :         if (is_inline) {
    1085                 :            :                 /* Get inline device for inline mode */
    1086   [ #  #  #  # ]:          0 :                 if (!idev || !idev->nix_inl_dev) {
    1087                 :          0 :                         plt_err("nix_inl_dev not available for custom profile release");
    1088                 :          0 :                         return -ENODEV;
    1089                 :            :                 }
    1090                 :            :                 inl_dev = idev->nix_inl_dev;
    1091                 :          0 :                 mbox = mbox_get(inl_dev->dev.mbox);
    1092                 :            :         } else {
    1093                 :            :                 /* Use NIX device mbox for non-inline mode */
    1094                 :          0 :                 mbox = mbox_get(nix->dev.mbox);
    1095                 :            :         }
    1096                 :            : 
    1097                 :          0 :         lf_cfg = mbox_alloc_msg_nix_rx_inl_lf_cfg(mbox);
    1098         [ #  # ]:          0 :         if (lf_cfg == NULL) {
    1099                 :            :                 rc = -ENOSPC;
    1100                 :          0 :                 plt_err("Failed to alloc profile release mbox msg");
    1101                 :            :                 mbox_put(mbox);
    1102                 :          0 :                 goto exit;
    1103                 :            :         }
    1104                 :            : 
    1105                 :          0 :         lf_cfg->enable = 0;
    1106                 :          0 :         lf_cfg->profile_id = profile_id;
    1107                 :          0 :         rc = mbox_process(mbox);
    1108         [ #  # ]:          0 :         if (rc) {
    1109                 :          0 :                 plt_err("Failed to cleanup NIX Inbound profile=%u SA conf, rc=%d", profile_id, rc);
    1110                 :            :                 mbox_put(mbox);
    1111                 :          0 :                 goto exit;
    1112                 :            :         }
    1113                 :            : 
    1114                 :            :         /* Free SA base memory */
    1115         [ #  # ]:          0 :         if (is_inline) {
    1116         [ #  # ]:          0 :                 if (inl_dev->inb_sa_base[profile_id]) {
    1117                 :          0 :                         plt_free(inl_dev->inb_sa_base[profile_id]);
    1118                 :          0 :                         inl_dev->inb_sa_base[profile_id] = NULL;
    1119                 :            :                 }
    1120                 :            :         } else {
    1121         [ #  # ]:          0 :                 if (nix->inb_sa_base[profile_id]) {
    1122                 :          0 :                         plt_free(nix->inb_sa_base[profile_id]);
    1123                 :          0 :                         nix->inb_sa_base[profile_id] = NULL;
    1124                 :            :                 }
    1125                 :            :         }
    1126                 :            : 
    1127                 :            :         mbox_put(mbox);
    1128         [ #  # ]:          0 :         plt_info("%s custom profile %u released", is_inline ? "Inline device" : "NIX device",
    1129                 :            :                  profile_id);
    1130                 :            : 
    1131                 :            : exit:
    1132                 :            :         return rc;
    1133                 :            : }
    1134                 :            : 
    1135                 :            : bool
    1136                 :          0 : roc_nix_inl_inb_rx_inject_enable(struct roc_nix *roc_nix, bool inb_inl_dev)
    1137                 :            : {
    1138                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1139                 :            :         struct nix_inl_dev *inl_dev;
    1140                 :            :         struct nix *nix = NULL;
    1141                 :            : 
    1142         [ #  # ]:          0 :         if (idev == NULL)
    1143                 :            :                 return 0;
    1144                 :            : 
    1145         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
    1146                 :            :                 return 0;
    1147                 :            : 
    1148         [ #  # ]:          0 :         if (roc_nix) {
    1149                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    1150         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
    1151                 :            :                         return 0;
    1152                 :            :         }
    1153                 :            : 
    1154         [ #  # ]:          0 :         if (inb_inl_dev) {
    1155                 :          0 :                 inl_dev = idev->nix_inl_dev;
    1156   [ #  #  #  #  :          0 :                 if (inl_dev && inl_dev->attach_cptlf && inl_dev->rx_inj_ena && roc_nix &&
             #  #  #  # ]
    1157         [ #  # ]:          0 :                     roc_nix->rx_inj_ena)
    1158                 :            :                         return true;
    1159                 :            :         }
    1160                 :            : 
    1161   [ #  #  #  # ]:          0 :         return roc_nix ? roc_nix->rx_inj_ena : 0;
    1162                 :            : }
    1163                 :            : 
    1164                 :            : uint32_t
    1165                 :          0 : roc_nix_inl_inb_spi_range(struct roc_nix *roc_nix, bool inb_inl_dev,
    1166                 :            :                           uint32_t *min_spi, uint32_t *max_spi)
    1167                 :            : {
    1168                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1169                 :            :         uint32_t min = 0, max = 0, mask = 0;
    1170                 :            :         struct nix_inl_dev *inl_dev;
    1171                 :            :         struct nix *nix = NULL;
    1172                 :            : 
    1173         [ #  # ]:          0 :         if (idev == NULL)
    1174                 :            :                 return 0;
    1175                 :            : 
    1176         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
    1177                 :            :                 return -EINVAL;
    1178                 :            : 
    1179                 :          0 :         inl_dev = idev->nix_inl_dev;
    1180         [ #  # ]:          0 :         if (inb_inl_dev) {
    1181         [ #  # ]:          0 :                 if (inl_dev == NULL)
    1182                 :          0 :                         goto exit;
    1183                 :          0 :                 min = inl_dev->ipsec_in_min_spi;
    1184                 :          0 :                 max = inl_dev->ipsec_in_max_spi;
    1185                 :          0 :                 mask = inl_dev->inb_spi_mask;
    1186                 :            :         } else {
    1187                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    1188         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
    1189                 :          0 :                         goto exit;
    1190                 :          0 :                 min = roc_nix->ipsec_in_min_spi;
    1191                 :          0 :                 max = roc_nix->ipsec_in_max_spi;
    1192                 :          0 :                 mask = nix->inb_spi_mask;
    1193                 :            :         }
    1194                 :          0 : exit:
    1195         [ #  # ]:          0 :         if (min_spi)
    1196                 :          0 :                 *min_spi = min;
    1197         [ #  # ]:          0 :         if (max_spi)
    1198                 :          0 :                 *max_spi = max;
    1199                 :            :         return mask;
    1200                 :            : }
    1201                 :            : 
    1202                 :            : uint32_t
    1203                 :          0 : roc_nix_inl_inb_sa_sz(struct roc_nix *roc_nix, bool inl_dev_sa)
    1204                 :            : {
    1205                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1206                 :            :         struct nix_inl_dev *inl_dev;
    1207                 :            :         struct nix *nix;
    1208                 :            : 
    1209         [ #  # ]:          0 :         if (idev == NULL)
    1210                 :            :                 return 0;
    1211                 :            : 
    1212         [ #  # ]:          0 :         if (!inl_dev_sa && roc_nix == NULL)
    1213                 :            :                 return -EINVAL;
    1214                 :            : 
    1215         [ #  # ]:          0 :         if (roc_nix) {
    1216                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    1217         [ #  # ]:          0 :                 if (!inl_dev_sa)
    1218                 :          0 :                         return nix->inb_sa_sz[nix->ipsec_prof_id];
    1219                 :            :         }
    1220                 :            : 
    1221         [ #  # ]:          0 :         if (inl_dev_sa) {
    1222                 :          0 :                 inl_dev = idev->nix_inl_dev;
    1223         [ #  # ]:          0 :                 if (inl_dev)
    1224                 :          0 :                         return inl_dev->inb_sa_sz[inl_dev->ipsec_prof_id];
    1225                 :            :         }
    1226                 :            : 
    1227                 :            :         return 0;
    1228                 :            : }
    1229                 :            : 
    1230                 :            : uintptr_t
    1231                 :          0 : roc_nix_inl_inb_sa_get(struct roc_nix *roc_nix, bool inb_inl_dev, uint32_t spi)
    1232                 :            : {
    1233                 :          0 :         uint32_t max_spi = 0, min_spi = 0, mask;
    1234                 :            :         uintptr_t sa_base;
    1235                 :            :         uint64_t sz;
    1236                 :            : 
    1237                 :          0 :         sa_base = roc_nix_inl_inb_sa_base_get(roc_nix, inb_inl_dev);
    1238                 :            :         /* Check if SA base exists */
    1239         [ #  # ]:          0 :         if (!sa_base)
    1240                 :            :                 return 0;
    1241                 :            : 
    1242                 :            :         /* Get SA size */
    1243                 :          0 :         sz = roc_nix_inl_inb_sa_sz(roc_nix, inb_inl_dev);
    1244         [ #  # ]:          0 :         if (!sz)
    1245                 :            :                 return 0;
    1246                 :            : 
    1247   [ #  #  #  # ]:          0 :         if (roc_nix && roc_nix->custom_sa_action)
    1248                 :          0 :                 return (sa_base + (spi * sz));
    1249                 :            : 
    1250                 :            :         /* Check if SPI is in range */
    1251                 :          0 :         mask = roc_nix_inl_inb_spi_range(roc_nix, inb_inl_dev, &min_spi,
    1252                 :            :                                          &max_spi);
    1253   [ #  #  #  # ]:          0 :         if (spi > max_spi || spi < min_spi)
    1254                 :          0 :                 plt_nix_dbg("Inbound SA SPI %u not in range (%u..%u)", spi,
    1255                 :            :                          min_spi, max_spi);
    1256                 :            : 
    1257                 :            :         /* Basic logic of SPI->SA for now */
    1258                 :          0 :         return (sa_base + ((spi & mask) * sz));
    1259                 :            : }
    1260                 :            : 
    1261                 :            : int
    1262                 :          0 : roc_nix_reassembly_configure(struct roc_cpt_rxc_time_cfg *req_cfg, uint32_t max_wait_time)
    1263                 :            : {
    1264                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1265                 :            :         struct nix_inl_dev *inl_dev = NULL;
    1266                 :            :         struct cpt_rxc_time_cfg_req *req;
    1267                 :            :         struct roc_cpt_rxc_time_cfg cfg;
    1268                 :            :         struct roc_cpt *roc_cpt;
    1269                 :            :         struct mbox *mbox;
    1270                 :            :         uint32_t val;
    1271                 :            :         int rc;
    1272                 :            : 
    1273         [ #  # ]:          0 :         if (!idev)
    1274                 :            :                 return -EFAULT;
    1275                 :            : 
    1276                 :          0 :         cfg.zombie_limit =
    1277         [ #  # ]:          0 :                 req_cfg->zombie_limit ? req_cfg->zombie_limit : ROC_NIX_INL_REAS_ZOMBIE_LIMIT;
    1278                 :          0 :         cfg.zombie_thres =
    1279         [ #  # ]:          0 :                 req_cfg->zombie_thres ? req_cfg->zombie_thres : ROC_NIX_INL_REAS_ZOMBIE_THRESHOLD;
    1280         [ #  # ]:          0 :         cfg.active_thres =
    1281         [ #  # ]:          0 :                 req_cfg->active_thres ? req_cfg->active_thres : ROC_NIX_INL_REAS_ACTIVE_THRESHOLD;
    1282                 :            : 
    1283         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
    1284                 :          0 :                 roc_cpt = idev->cpt;
    1285         [ #  # ]:          0 :                 if (!roc_cpt) {
    1286                 :          0 :                         plt_err("Cryptodev not probed");
    1287                 :          0 :                         return -ENOTSUP;
    1288                 :            :                 }
    1289                 :            : 
    1290         [ #  # ]:          0 :                 val = max_wait_time ? (max_wait_time * 1000 / ROC_NIX_INL_REAS_ACTIVE_LIMIT) : 0;
    1291         [ #  # ]:          0 :                 cfg.step = req_cfg->step ? req_cfg->step : val;
    1292         [ #  # ]:          0 :                 cfg.active_limit = req_cfg->active_limit ? req_cfg->active_limit :
    1293                 :            :                                                            ROC_NIX_INL_REAS_ACTIVE_LIMIT;
    1294                 :            : 
    1295                 :          0 :                 return roc_cpt_rxc_time_cfg(roc_cpt, &cfg);
    1296                 :            :         }
    1297                 :            : 
    1298                 :          0 :         inl_dev = idev->nix_inl_dev;
    1299         [ #  # ]:          0 :         if (!inl_dev) {
    1300                 :          0 :                 plt_err("Cannot support RXC config, inlinedev is not probed");
    1301                 :          0 :                 return -ENOTSUP;
    1302                 :            :         }
    1303                 :            : 
    1304                 :          0 :         mbox = mbox_get((&inl_dev->dev)->mbox);
    1305                 :            : 
    1306                 :          0 :         req = mbox_alloc_msg_cpt_rxc_time_cfg(mbox);
    1307         [ #  # ]:          0 :         if (req == NULL) {
    1308                 :            :                 rc = -ENOSPC;
    1309                 :          0 :                 goto exit;
    1310                 :            :         }
    1311                 :            : 
    1312                 :            :         /* For CN20K, Configure step size fix and active limit per RXC queue,
    1313                 :            :          * Default CPT_AF_RXC_TIME_CFG::AGE_STEP will be 1ms, so max reassembly
    1314                 :            :          * timeout can be up to 4095 ms.
    1315                 :            :          */
    1316         [ #  # ]:          0 :         cfg.step = req_cfg->step ? req_cfg->step : ROC_NIX_INL_REAS_STEP_DFLT;
    1317         [ #  # ]:          0 :         val = max_wait_time ? (max_wait_time * 1000 / cfg.step) : 0;
    1318         [ #  # ]:          0 :         cfg.active_limit = req_cfg->active_limit ? req_cfg->active_limit : val;
    1319         [ #  # ]:          0 :         if (cfg.active_limit > ROC_NIX_INL_REAS_ACTIVE_LIMIT)
    1320                 :          0 :                 cfg.active_limit = ROC_NIX_INL_REAS_ACTIVE_LIMIT;
    1321                 :            : 
    1322                 :          0 :         req->blkaddr = 0;
    1323                 :          0 :         req->queue_id = inl_dev->nix_inb_qids[inl_dev->inb_cpt_lf_id];
    1324                 :          0 :         req->step = cfg.step;
    1325                 :          0 :         req->zombie_limit = cfg.zombie_limit;
    1326                 :          0 :         req->zombie_thres = cfg.zombie_thres;
    1327                 :          0 :         req->active_limit = cfg.active_limit;
    1328                 :          0 :         req->active_thres = cfg.active_thres;
    1329                 :          0 :         req->cpt_af_rxc_que_cfg = ROC_NIX_INL_RXC_QUE_BLK_THR << 32;
    1330                 :            : 
    1331                 :          0 :         rc = mbox_process(mbox);
    1332                 :          0 : exit:
    1333                 :            :         mbox_put(mbox);
    1334                 :          0 :         return rc;
    1335                 :            : }
    1336                 :            : 
    1337                 :            : static void
    1338                 :          0 : nix_inl_rq_mask_init(struct nix_rq_cpt_field_mask_cfg_req *msk_req, uint8_t first_skip)
    1339                 :            : {
    1340                 :            :         int i;
    1341                 :            : 
    1342         [ #  # ]:          0 :         for (i = 0; i < RQ_CTX_MASK_MAX; i++)
    1343                 :          0 :                 msk_req->rq_ctx_word_mask[i] = 0xFFFFFFFFFFFFFFFF;
    1344                 :            : 
    1345                 :          0 :         msk_req->rq_set.len_ol3_dis = 1;
    1346                 :          0 :         msk_req->rq_set.len_ol4_dis = 1;
    1347                 :          0 :         msk_req->rq_set.len_il3_dis = 1;
    1348                 :            : 
    1349                 :          0 :         msk_req->rq_set.len_il4_dis = 1;
    1350                 :          0 :         msk_req->rq_set.csum_ol4_dis = 1;
    1351                 :          0 :         msk_req->rq_set.csum_il4_dis = 1;
    1352                 :            : 
    1353                 :          0 :         msk_req->rq_set.lenerr_dis = 1;
    1354                 :          0 :         msk_req->rq_set.port_ol4_dis = 1;
    1355                 :          0 :         msk_req->rq_set.port_il4_dis = 1;
    1356                 :            : 
    1357                 :          0 :         msk_req->rq_set.lpb_drop_ena = 0;
    1358                 :          0 :         msk_req->rq_set.spb_drop_ena = 0;
    1359                 :          0 :         msk_req->rq_set.xqe_drop_ena = 0;
    1360                 :          0 :         msk_req->rq_set.spb_ena = 1;
    1361         [ #  # ]:          0 :         if (first_skip)
    1362                 :          0 :                 msk_req->rq_set.first_skip = first_skip;
    1363                 :            : 
    1364         [ #  # ]:          0 :         if (!roc_feature_nix_has_second_pass_drop()) {
    1365                 :          0 :                 msk_req->rq_set.ena = 1;
    1366                 :          0 :                 msk_req->rq_set.rq_int_ena = 1;
    1367                 :          0 :                 msk_req->rq_mask.ena = 0;
    1368                 :          0 :                 msk_req->rq_mask.rq_int_ena = 0;
    1369                 :            :         }
    1370                 :            : 
    1371                 :          0 :         msk_req->rq_mask.len_ol3_dis = 0;
    1372                 :          0 :         msk_req->rq_mask.len_ol4_dis = 0;
    1373                 :          0 :         msk_req->rq_mask.len_il3_dis = 0;
    1374                 :            : 
    1375                 :          0 :         msk_req->rq_mask.len_il4_dis = 0;
    1376                 :          0 :         msk_req->rq_mask.csum_ol4_dis = 0;
    1377                 :          0 :         msk_req->rq_mask.csum_il4_dis = 0;
    1378                 :            : 
    1379                 :          0 :         msk_req->rq_mask.lenerr_dis = 0;
    1380                 :          0 :         msk_req->rq_mask.port_ol4_dis = 0;
    1381                 :          0 :         msk_req->rq_mask.port_il4_dis = 0;
    1382                 :            : 
    1383                 :          0 :         msk_req->rq_mask.lpb_drop_ena = 0;
    1384                 :          0 :         msk_req->rq_mask.spb_drop_ena = 0;
    1385                 :          0 :         msk_req->rq_mask.xqe_drop_ena = 0;
    1386                 :          0 :         msk_req->rq_mask.spb_ena = 0;
    1387         [ #  # ]:          0 :         if (first_skip)
    1388                 :          0 :                 msk_req->rq_mask.first_skip = 0;
    1389                 :          0 : }
    1390                 :            : 
    1391                 :            : static int
    1392                 :          0 : nix_inl_legacy_rq_mask_setup(struct roc_nix *roc_nix, bool enable)
    1393                 :            : {
    1394                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1395                 :            :         struct nix_rq_cpt_field_mask_cfg_req *msk_req;
    1396                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1397                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
    1398                 :            :         struct idev_nix_inl_cfg *inl_cfg;
    1399                 :            :         uint64_t aura_handle;
    1400                 :            :         int rc = -ENOSPC;
    1401                 :            :         uint32_t buf_sz;
    1402                 :            : 
    1403         [ #  # ]:          0 :         if (!idev)
    1404                 :          0 :                 goto exit;
    1405                 :            : 
    1406                 :            :         inl_cfg = &idev->inl_cfg;
    1407                 :          0 :         msk_req = mbox_alloc_msg_nix_lf_inline_rq_cfg(mbox);
    1408         [ #  # ]:          0 :         if (msk_req == NULL)
    1409                 :          0 :                 goto exit;
    1410                 :            : 
    1411                 :          0 :         nix_inl_rq_mask_init(msk_req, 0);
    1412         [ #  # ]:          0 :         if (roc_nix->local_meta_aura_ena) {
    1413                 :          0 :                 aura_handle = roc_nix->meta_aura_handle;
    1414                 :          0 :                 buf_sz = roc_nix->buf_sz;
    1415         [ #  # ]:          0 :                 if (!aura_handle && enable) {
    1416                 :          0 :                         plt_err("NULL meta aura handle");
    1417                 :          0 :                         goto exit;
    1418                 :            :                 }
    1419                 :            :         } else {
    1420                 :          0 :                 aura_handle = roc_npa_zero_aura_handle();
    1421                 :          0 :                 buf_sz = inl_cfg->buf_sz;
    1422                 :            :         }
    1423                 :            : 
    1424                 :          0 :         msk_req->ipsec_cfg1_inline_replay.spb_cpt_aura = roc_npa_aura_handle_to_aura(aura_handle);
    1425                 :          0 :         msk_req->ipsec_cfg1_inline_replay.rq_mask_enable = enable;
    1426                 :          0 :         msk_req->ipsec_cfg1_inline_replay.spb_cpt_sizem1 = (buf_sz >> 7) - 1;
    1427                 :          0 :         msk_req->ipsec_cfg1_inline_replay.spb_cpt_enable = enable;
    1428                 :            : 
    1429                 :          0 :         rc = mbox_process(mbox);
    1430                 :          0 : exit:
    1431                 :            :         mbox_put(mbox);
    1432                 :          0 :         return rc;
    1433                 :            : }
    1434                 :            : 
    1435                 :            : static int
    1436         [ #  # ]:          0 : nix_inl_rq_mask_cfg(struct roc_nix *roc_nix, bool enable)
    1437                 :            : {
    1438                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1439                 :            :         struct nix_rq_cpt_field_mask_cfg_req *msk_req;
    1440                 :            :         uint64_t aura_handle;
    1441                 :            :         uint8_t first_skip;
    1442                 :            :         struct mbox *mbox;
    1443                 :            :         int rc = -ENOSPC;
    1444                 :            :         uint64_t buf_sz;
    1445                 :            : 
    1446         [ #  # ]:          0 :         if (roc_model_is_cn9k() | roc_model_is_cn10k())
    1447                 :          0 :                 return nix_inl_legacy_rq_mask_setup(roc_nix, enable);
    1448                 :            : 
    1449                 :          0 :         mbox = mbox_get((&nix->dev)->mbox);
    1450                 :            :         /* RQ mask alloc and setup */
    1451                 :          0 :         msk_req = mbox_alloc_msg_nix_lf_inline_rq_cfg(mbox);
    1452         [ #  # ]:          0 :         if (msk_req == NULL)
    1453                 :          0 :                 goto exit;
    1454                 :            : 
    1455         [ #  # ]:          0 :         first_skip = roc_nix->def_first_skip ? (roc_nix->def_first_skip / 8) : 0;
    1456                 :          0 :         nix_inl_rq_mask_init(msk_req, first_skip);
    1457                 :            : 
    1458         [ #  # ]:          0 :         if (roc_nix->local_meta_aura_ena) {
    1459                 :          0 :                 aura_handle = roc_nix->meta_aura_handle;
    1460                 :          0 :                 buf_sz = roc_nix->buf_sz;
    1461         [ #  # ]:          0 :                 if (!aura_handle && enable) {
    1462                 :          0 :                         plt_err("NULL meta aura handle");
    1463                 :            :                         rc = -EINVAL;
    1464                 :          0 :                         goto exit;
    1465                 :            :                 }
    1466                 :            : 
    1467                 :            :                 /* SPB setup */
    1468                 :          0 :                 msk_req->ipsec_cfg1_inline_replay.spb_cpt_aura =
    1469                 :            :                         roc_npa_aura_handle_to_aura(aura_handle);
    1470                 :          0 :                 msk_req->ipsec_cfg1_inline_replay.rq_mask_enable = enable;
    1471                 :          0 :                 msk_req->ipsec_cfg1_inline_replay.spb_cpt_sizem1 = (buf_sz >> 7) - 1;
    1472                 :          0 :                 msk_req->ipsec_cfg1_inline_replay.spb_cpt_enable = enable;
    1473                 :            :         }
    1474                 :            : 
    1475                 :          0 :         rc = mbox_process(mbox);
    1476         [ #  # ]:          0 :         if (rc)
    1477                 :          0 :                 plt_err("Failed to setup NIX Inline RQ mask, rc=%d", rc);
    1478                 :            : 
    1479                 :          0 : exit:
    1480                 :            :         mbox_put(mbox);
    1481                 :          0 :         return rc;
    1482                 :            : }
    1483                 :            : 
    1484                 :            : static void
    1485                 :          0 : nix_inl_eng_caps_get(struct nix *nix)
    1486                 :            : {
    1487                 :          0 :         struct roc_cpt_lf *lf = nix->cpt_lf_base;
    1488                 :          0 :         uintptr_t lmt_base = lf->lmt_base;
    1489                 :            :         union cpt_res_s res, *hw_res;
    1490                 :            :         struct cpt_inst_s inst;
    1491                 :            :         uint64_t *rptr;
    1492                 :            : 
    1493                 :          0 :         hw_res = plt_zmalloc(sizeof(*hw_res), ROC_CPT_RES_ALIGN);
    1494         [ #  # ]:          0 :         if (hw_res == NULL) {
    1495                 :          0 :                 plt_err("Couldn't allocate memory for result address");
    1496                 :          0 :                 return;
    1497                 :            :         }
    1498                 :            : 
    1499                 :          0 :         rptr = plt_zmalloc(ROC_ALIGN, 0);
    1500         [ #  # ]:          0 :         if (rptr == NULL) {
    1501                 :          0 :                 plt_err("Couldn't allocate memory for rptr");
    1502                 :          0 :                 plt_free(hw_res);
    1503                 :          0 :                 return;
    1504                 :            :         }
    1505                 :            : 
    1506                 :            :         /* Fill CPT_INST_S for LOAD_FVC/HW_CRYPTO_SUPPORT microcode op */
    1507                 :            :         memset(&inst, 0, sizeof(struct cpt_inst_s));
    1508                 :          0 :         inst.res_addr = (uint64_t)hw_res;
    1509                 :          0 :         inst.rptr = (uint64_t)rptr;
    1510                 :          0 :         inst.w4.s.opcode_major = ROC_LOADFVC_MAJOR_OP;
    1511                 :          0 :         inst.w4.s.opcode_minor = ROC_LOADFVC_MINOR_OP;
    1512                 :            : 
    1513                 :            :         /* SE engine group ID is same for all platform */
    1514                 :            :         inst.w7.s.egrp = ROC_CPT_DFLT_ENG_GRP_SE;
    1515                 :            : 
    1516                 :            :         /* Use 1 min timeout for the poll */
    1517         [ #  # ]:          0 :         const uint64_t timeout = plt_tsc_cycles() + 60 * plt_tsc_hz();
    1518                 :            : 
    1519         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    1520                 :            :                 uint64_t lmt_status;
    1521                 :            : 
    1522                 :          0 :                 hw_res->cn9k.compcode = CPT_COMP_NOT_DONE;
    1523                 :          0 :                 plt_io_wmb();
    1524                 :            : 
    1525                 :            :                 do {
    1526                 :            :                         roc_lmt_mov_seg((void *)lmt_base, &inst, 4);
    1527                 :            :                         lmt_status = roc_lmt_submit_ldeor(lf->io_addr);
    1528                 :            :                 } while (lmt_status == 0);
    1529                 :            : 
    1530                 :            :                 /* Wait until CPT instruction completes */
    1531                 :            :                 do {
    1532                 :            :                         res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
    1533                 :            :                         if (unlikely(plt_tsc_cycles() > timeout))
    1534                 :            :                                 break;
    1535                 :            :                 } while (res.cn9k.compcode == CPT_COMP_NOT_DONE);
    1536                 :            : 
    1537                 :            :                 if (res.cn9k.compcode != CPT_COMP_GOOD) {
    1538                 :            :                         plt_err("LOAD FVC operation timed out");
    1539                 :            :                         return;
    1540                 :            :                 }
    1541         [ #  # ]:          0 :         } else if (roc_model_is_cn10k()) {
    1542                 :            :                 uint64_t lmt_arg, io_addr;
    1543                 :            :                 uint16_t lmt_id;
    1544                 :            : 
    1545                 :          0 :                 hw_res->cn10k.compcode = CPT_COMP_NOT_DONE;
    1546                 :            : 
    1547                 :            :                 /* Use this reserved LMT line as no one else is using it */
    1548                 :          0 :                 lmt_id = roc_plt_control_lmt_id_get();
    1549                 :          0 :                 lmt_base += ((uint64_t)lmt_id << ROC_LMT_LINE_SIZE_LOG2);
    1550                 :            : 
    1551                 :          0 :                 memcpy((void *)lmt_base, &inst, sizeof(inst));
    1552                 :            : 
    1553                 :            :                 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (uint64_t)lmt_id;
    1554                 :            :                 io_addr = lf->io_addr | ROC_CN10K_CPT_INST_DW_M1 << 4;
    1555                 :            : 
    1556                 :            :                 roc_lmt_submit_steorl(lmt_arg, io_addr);
    1557                 :          0 :                 plt_io_wmb();
    1558                 :            : 
    1559                 :            :                 /* Wait until CPT instruction completes */
    1560                 :            :                 do {
    1561                 :          0 :                         res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
    1562         [ #  # ]:          0 :                         if (unlikely(plt_tsc_cycles() > timeout))
    1563                 :            :                                 break;
    1564         [ #  # ]:          0 :                 } while (res.cn10k.compcode == CPT_COMP_NOT_DONE);
    1565                 :            : 
    1566         [ #  # ]:          0 :                 if (res.cn10k.compcode != CPT_COMP_GOOD || res.cn10k.uc_compcode) {
    1567                 :          0 :                         plt_err("LOAD FVC operation timed out");
    1568                 :          0 :                         goto exit;
    1569                 :            :                 }
    1570                 :            :         } else {
    1571                 :            :                 uint64_t lmt_arg, io_addr;
    1572                 :            :                 uint16_t lmt_id;
    1573                 :            : 
    1574                 :          0 :                 hw_res->cn20k.compcode = CPT_COMP_NOT_DONE;
    1575                 :            : 
    1576                 :            :                 /* Use this reserved LMT line as no one else is using it */
    1577                 :          0 :                 lmt_id = roc_plt_control_lmt_id_get();
    1578                 :          0 :                 lmt_base += ((uint64_t)lmt_id << ROC_LMT_LINE_SIZE_LOG2);
    1579                 :            : 
    1580                 :          0 :                 memcpy((void *)lmt_base, &inst, sizeof(inst));
    1581                 :            : 
    1582                 :            :                 lmt_arg = ROC_CN20K_CPT_LMT_ARG | (uint64_t)lmt_id;
    1583                 :            :                 io_addr = lf->io_addr | ROC_CN20K_CPT_INST_DW_M1 << 4;
    1584                 :            : 
    1585                 :            :                 roc_lmt_submit_steorl(lmt_arg, io_addr);
    1586                 :          0 :                 plt_io_wmb();
    1587                 :            : 
    1588                 :            :                 /* Wait until CPT instruction completes */
    1589                 :            :                 do {
    1590                 :          0 :                         res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
    1591         [ #  # ]:          0 :                         if (unlikely(plt_tsc_cycles() > timeout))
    1592                 :            :                                 break;
    1593         [ #  # ]:          0 :                 } while (res.cn20k.compcode == CPT_COMP_NOT_DONE);
    1594                 :            : 
    1595         [ #  # ]:          0 :                 if (res.cn20k.compcode != CPT_COMP_GOOD || res.cn20k.uc_compcode) {
    1596                 :          0 :                         plt_err("LOAD FVC operation timed out");
    1597                 :          0 :                         goto exit;
    1598                 :            :                 }
    1599                 :            :         }
    1600                 :            : 
    1601         [ #  # ]:          0 :         nix->cpt_eng_caps = plt_be_to_cpu_64(*rptr);
    1602                 :          0 : exit:
    1603                 :          0 :         plt_free(rptr);
    1604                 :          0 :         plt_free(hw_res);
    1605                 :            : }
    1606                 :            : 
    1607                 :            : static int
    1608                 :          0 : nix_inl_legacy_inb_init(struct roc_nix *roc_nix)
    1609                 :            : {
    1610                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1611                 :          0 :         struct roc_cpt_inline_ipsec_inb_cfg cfg = {0};
    1612                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1613                 :            :         uint16_t bpids[ROC_NIX_MAX_BPID_CNT];
    1614                 :            :         struct roc_cpt *roc_cpt;
    1615                 :            :         int rc;
    1616                 :            : 
    1617         [ #  # ]:          0 :         if (idev == NULL)
    1618                 :            :                 return -ENOTSUP;
    1619                 :            : 
    1620                 :            :         /* Unless we have another mechanism to trigger
    1621                 :            :          * onetime Inline config in CPTPF, we cannot
    1622                 :            :          * support without CPT being probed.
    1623                 :            :          */
    1624                 :          0 :         roc_cpt = idev->cpt;
    1625         [ #  # ]:          0 :         if (!roc_cpt) {
    1626                 :          0 :                 plt_err("Cannot support inline inbound, cryptodev not probed");
    1627                 :          0 :                 return -ENOTSUP;
    1628                 :            :         }
    1629                 :            : 
    1630         [ #  # ]:          0 :         nix->ipsec_prof_id = 0;
    1631                 :            :         memset(&cfg, 0, sizeof(cfg));
    1632         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    1633                 :          0 :                 cfg.param1 = (ROC_ONF_IPSEC_INB_MAX_L2_SZ >> 3) & 0xf;
    1634                 :          0 :                 cfg.param2 = ROC_IE_ON_INB_IKEV2_SINGLE_SA_SUPPORT;
    1635                 :          0 :                 cfg.opcode =
    1636                 :            :                         ((ROC_IE_ON_INB_MAX_CTX_LEN << 8) |
    1637                 :            :                          (ROC_IE_ON_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6)));
    1638                 :            :         } else {
    1639                 :            :                 union roc_ot_ipsec_inb_param1 u;
    1640                 :            : 
    1641                 :            :                 u.u16 = 0;
    1642                 :            :                 u.s.esp_trailer_disable = 1;
    1643                 :          0 :                 cfg.param1 = u.u16;
    1644                 :            :                 cfg.param2 = 0;
    1645                 :          0 :                 cfg.opcode = (ROC_IE_OT_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6));
    1646                 :            : 
    1647         [ #  # ]:          0 :                 if (roc_nix->custom_inb_sa) {
    1648                 :          0 :                         cfg.param1 = roc_nix->inb_cfg_param1;
    1649                 :          0 :                         cfg.param2 = roc_nix->inb_cfg_param2;
    1650                 :            :                 }
    1651                 :          0 :                 rc = roc_nix_bpids_alloc(roc_nix, ROC_NIX_INTF_TYPE_CPT_NIX, 1, bpids);
    1652         [ #  # ]:          0 :                 if (rc > 0) {
    1653                 :          0 :                         nix->cpt_nixbpid = bpids[0];
    1654                 :          0 :                         cfg.bpid = nix->cpt_nixbpid;
    1655                 :            :                 }
    1656                 :            : 
    1657         [ #  # ]:          0 :                 if (roc_errata_cpt_has_ctx_fetch_issue()) {
    1658                 :          0 :                         cfg.ctx_ilen_valid = true;
    1659                 :          0 :                         cfg.ctx_ilen = (ROC_NIX_INL_OT_IPSEC_INB_HW_SZ / 128) - 1;
    1660                 :            :                 }
    1661                 :            :         }
    1662                 :            : 
    1663                 :            :         /* Do onetime Inbound Inline config in CPTPF */
    1664                 :          0 :         rc = roc_cpt_inline_ipsec_inb_cfg(roc_cpt, &cfg);
    1665         [ #  # ]:          0 :         if (rc && rc != -EEXIST) {
    1666                 :          0 :                 plt_err("Failed to setup inbound lf, rc=%d", rc);
    1667                 :          0 :                 return rc;
    1668                 :            :         }
    1669                 :          0 :         nix->cpt_eng_caps = roc_cpt->hw_caps[CPT_ENG_TYPE_SE].u;
    1670                 :            : 
    1671                 :            :         /* Setup Inbound SA table */
    1672                 :          0 :         rc = nix_inl_inb_ipsec_sa_tbl_setup(roc_nix);
    1673         [ #  # ]:          0 :         if (rc)
    1674                 :            :                 return rc;
    1675                 :            : 
    1676   [ #  #  #  # ]:          0 :         if (!roc_model_is_cn9k() && !roc_errata_nix_no_meta_aura()) {
    1677                 :          0 :                 nix->need_meta_aura = true;
    1678   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
    1679                 :          0 :                         idev->inl_cfg.refs++;
    1680                 :            :         }
    1681                 :            : 
    1682                 :          0 :         nix->inl_inb_ena = true;
    1683                 :          0 :         return 0;
    1684                 :            : }
    1685                 :            : 
    1686                 :            : static int
    1687                 :          0 : nix_inl_inb_init(struct roc_nix *roc_nix)
    1688                 :            : {
    1689                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1690                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1691                 :            :         struct nix_inl_dev *inl_dev;
    1692                 :            :         int rc;
    1693                 :            : 
    1694         [ #  # ]:          0 :         if (idev == NULL)
    1695                 :            :                 return -ENOTSUP;
    1696                 :            : 
    1697                 :          0 :         inl_dev = idev->nix_inl_dev;
    1698                 :            : 
    1699   [ #  #  #  # ]:          0 :         if (!inl_dev || !inl_dev->nb_inb_cptlfs) {
    1700                 :          0 :                 plt_err("Cannot support inline inbound without inline dev");
    1701                 :          0 :                 return -ENOTSUP;
    1702                 :            :         }
    1703                 :            : 
    1704                 :            :         /* FIXME get engine caps from inline device */
    1705                 :          0 :         nix->cpt_eng_caps = 0;
    1706                 :            : 
    1707                 :            :         /* Setup Inbound SA table */
    1708                 :          0 :         rc = nix_inl_inb_ipsec_sa_tbl_setup(roc_nix);
    1709         [ #  # ]:          0 :         if (rc)
    1710                 :            :                 return rc;
    1711                 :            : 
    1712         [ #  # ]:          0 :         if (roc_nix->reass_ena) {
    1713                 :          0 :                 rc = nix_inl_reass_inb_sa_tbl_setup(roc_nix);
    1714         [ #  # ]:          0 :                 if (rc)
    1715                 :            :                         return rc;
    1716                 :            :         }
    1717                 :            : 
    1718   [ #  #  #  # ]:          0 :         if (roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena) {
    1719                 :          0 :                 nix->need_meta_aura = true;
    1720                 :            : 
    1721         [ #  # ]:          0 :                 if (roc_nix->custom_meta_aura_ena)
    1722                 :          0 :                         idev->inl_cfg.refs++;
    1723                 :            :         }
    1724                 :            : 
    1725                 :          0 :         nix->inl_inb_ena = true;
    1726                 :          0 :         return 0;
    1727                 :            : }
    1728                 :            : 
    1729                 :            : int
    1730         [ #  # ]:          0 : roc_nix_inl_inb_init(struct roc_nix *roc_nix)
    1731                 :            : {
    1732   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() || roc_model_is_cn10k())
    1733                 :          0 :                 return nix_inl_legacy_inb_init(roc_nix);
    1734                 :            : 
    1735                 :          0 :         return nix_inl_inb_init(roc_nix);
    1736                 :            : }
    1737                 :            : int
    1738                 :          0 : roc_nix_inl_inb_fini(struct roc_nix *roc_nix)
    1739                 :            : {
    1740                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1741                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1742                 :            :         int rc;
    1743                 :            : 
    1744         [ #  # ]:          0 :         if (!nix->inl_inb_ena)
    1745                 :            :                 return 0;
    1746                 :            : 
    1747         [ #  # ]:          0 :         if (!idev)
    1748                 :            :                 return -EFAULT;
    1749                 :            : 
    1750                 :          0 :         nix->inl_inb_ena = false;
    1751                 :            : 
    1752         [ #  # ]:          0 :         if (nix->need_meta_aura) {
    1753                 :          0 :                 nix->need_meta_aura = false;
    1754   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
    1755                 :          0 :                         idev->inl_cfg.refs--;
    1756                 :            : 
    1757         [ #  # ]:          0 :                 if (roc_nix->custom_meta_aura_ena)
    1758                 :          0 :                         nix_inl_custom_meta_aura_destroy(roc_nix);
    1759                 :            : 
    1760         [ #  # ]:          0 :                 if (!idev->inl_cfg.refs)
    1761                 :          0 :                         nix_inl_meta_aura_destroy(roc_nix);
    1762                 :            :         }
    1763                 :            : 
    1764         [ #  # ]:          0 :         if (roc_feature_nix_has_inl_rq_mask()) {
    1765                 :          0 :                 rc = nix_inl_rq_mask_cfg(roc_nix, false);
    1766         [ #  # ]:          0 :                 if (rc) {
    1767                 :          0 :                         plt_err("Failed to get rq mask rc=%d", rc);
    1768                 :          0 :                         return rc;
    1769                 :            :                 }
    1770                 :            :         }
    1771                 :            : 
    1772                 :            :         /* Flush Inbound CTX cache entries */
    1773                 :          0 :         roc_nix_cpt_ctx_cache_sync(roc_nix);
    1774                 :            : 
    1775         [ #  # ]:          0 :         if (roc_nix->reass_ena)
    1776                 :          0 :                 nix_inl_reass_sa_tbl_release(roc_nix);
    1777                 :            : 
    1778                 :            :         /* Disable Inbound SA */
    1779                 :          0 :         return nix_inl_ipsec_sa_tbl_release(roc_nix);
    1780                 :            : }
    1781                 :            : 
    1782                 :            : int
    1783                 :          0 : roc_nix_inl_outb_init(struct roc_nix *roc_nix)
    1784                 :            : {
    1785                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1786                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1787                 :            :         struct roc_cpt_lf *lf_base, *lf;
    1788                 :          0 :         struct dev *dev = &nix->dev;
    1789                 :            :         struct msix_offset_rsp *rsp;
    1790                 :            :         struct nix_inl_dev *inl_dev;
    1791                 :            :         bool ctx_ilen_valid = false;
    1792                 :            :         size_t sa_sz, ring_sz;
    1793                 :            :         uint8_t ctx_ilen = 0;
    1794                 :            :         bool rx_inj = false;
    1795                 :            :         uint16_t sso_pffunc;
    1796                 :            :         uint8_t eng_grpmask;
    1797                 :            :         uint64_t blkaddr, i;
    1798                 :            :         uint64_t *ring_base;
    1799                 :            :         uint16_t nb_lf;
    1800                 :            :         void *sa_base;
    1801                 :            :         int j, rc;
    1802                 :            :         void *sa;
    1803                 :            : 
    1804         [ #  # ]:          0 :         if (idev == NULL)
    1805                 :            :                 return -ENOTSUP;
    1806                 :            : 
    1807                 :          0 :         nb_lf = roc_nix->outb_nb_crypto_qs;
    1808         [ #  # ]:          0 :         blkaddr = nix->is_nix1 ? RVU_BLOCK_ADDR_CPT1 : RVU_BLOCK_ADDR_CPT0;
    1809                 :            : 
    1810                 :            :         /* Retrieve inline device if present */
    1811                 :          0 :         inl_dev = idev->nix_inl_dev;
    1812   [ #  #  #  #  :          0 :         if (roc_nix->rx_inj_ena && !(nix->inb_inl_dev && inl_dev && inl_dev->attach_cptlf &&
             #  #  #  # ]
    1813         [ #  # ]:          0 :                                      inl_dev->rx_inj_ena)) {
    1814                 :          0 :                 nb_lf++;
    1815                 :            :                 rx_inj = true;
    1816                 :            :         }
    1817                 :            : 
    1818         [ #  # ]:          0 :         sso_pffunc = inl_dev ? inl_dev->dev.pf_func : idev_sso_pffunc_get();
    1819                 :            :         /* Use sso_pffunc if explicitly requested */
    1820         [ #  # ]:          0 :         if (roc_nix->ipsec_out_sso_pffunc)
    1821                 :          0 :                 sso_pffunc = idev_sso_pffunc_get();
    1822                 :            : 
    1823         [ #  # ]:          0 :         if (!sso_pffunc) {
    1824                 :          0 :                 plt_err("Failed to setup inline outb, need either "
    1825                 :            :                         "inline device or sso device");
    1826                 :          0 :                 return -ENOTSUP;
    1827                 :            :         }
    1828                 :            : 
    1829                 :            :         /* Attach CPT LF for outbound */
    1830                 :          0 :         rc = cpt_lfs_attach(dev, blkaddr, true, nb_lf);
    1831         [ #  # ]:          0 :         if (rc) {
    1832                 :          0 :                 plt_err("Failed to attach CPT LF for inline outb, rc=%d", rc);
    1833                 :          0 :                 return rc;
    1834                 :            :         }
    1835                 :            : 
    1836   [ #  #  #  # ]:          0 :         if (!roc_model_is_cn9k() && roc_errata_cpt_has_ctx_fetch_issue()) {
    1837                 :            :                 ctx_ilen = (ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ / 128) - 1;
    1838                 :            :                 ctx_ilen_valid = true;
    1839                 :            :         }
    1840                 :            : 
    1841   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() || roc_model_is_cn10k())
    1842                 :            :                 eng_grpmask = (1ULL << ROC_LEGACY_CPT_DFLT_ENG_GRP_SE |
    1843                 :            :                                1ULL << ROC_LEGACY_CPT_DFLT_ENG_GRP_SE_IE |
    1844                 :            :                                1ULL << ROC_LEGACY_CPT_DFLT_ENG_GRP_AE);
    1845                 :            :         else
    1846                 :            :                 eng_grpmask = (1ULL << ROC_CPT_DFLT_ENG_GRP_SE | 1ULL << ROC_CPT_DFLT_ENG_GRP_AE);
    1847                 :            : 
    1848                 :            :         /* Alloc CPT LF */
    1849                 :          0 :         rc = cpt_lfs_alloc(dev, eng_grpmask, blkaddr,
    1850                 :          0 :                            !roc_nix->ipsec_out_sso_pffunc, ctx_ilen_valid, ctx_ilen,
    1851                 :          0 :                            rx_inj, nb_lf - 1);
    1852         [ #  # ]:          0 :         if (rc) {
    1853                 :          0 :                 plt_err("Failed to alloc CPT LF resources, rc=%d", rc);
    1854                 :          0 :                 goto lf_detach;
    1855                 :            :         }
    1856                 :            : 
    1857                 :            :         /* Get msix offsets */
    1858                 :          0 :         rc = cpt_get_msix_offset(dev, &rsp);
    1859         [ #  # ]:          0 :         if (rc) {
    1860                 :          0 :                 plt_err("Failed to get CPT LF msix offset, rc=%d", rc);
    1861                 :          0 :                 goto lf_free;
    1862                 :            :         }
    1863                 :            : 
    1864                 :          0 :         mbox_memcpy(nix->cpt_msixoff,
    1865         [ #  # ]:          0 :                     nix->is_nix1 ? rsp->cpt1_lf_msixoff : rsp->cptlf_msixoff,
    1866                 :            :                     sizeof(nix->cpt_msixoff));
    1867                 :            : 
    1868                 :            :         /* Alloc required num of cpt lfs */
    1869                 :          0 :         lf_base = plt_zmalloc(nb_lf * sizeof(struct roc_cpt_lf), 0);
    1870         [ #  # ]:          0 :         if (!lf_base) {
    1871                 :          0 :                 plt_err("Failed to alloc cpt lf memory");
    1872                 :            :                 rc = -ENOMEM;
    1873                 :          0 :                 goto lf_free;
    1874                 :            :         }
    1875                 :            : 
    1876                 :            :         /* Initialize CPT LF's */
    1877         [ #  # ]:          0 :         for (i = 0; i < nb_lf; i++) {
    1878                 :          0 :                 lf = &lf_base[i];
    1879                 :            : 
    1880                 :          0 :                 lf->lf_id = i;
    1881                 :          0 :                 lf->nb_desc = roc_nix->outb_nb_desc;
    1882                 :          0 :                 lf->dev = &nix->dev;
    1883                 :          0 :                 lf->msixoff = nix->cpt_msixoff[i];
    1884         [ #  # ]:          0 :                 lf->pci_dev = nix->pci_dev;
    1885                 :            : 
    1886         [ #  # ]:          0 :                 if (roc_feature_nix_has_cpt_cq_support()) {
    1887   [ #  #  #  # ]:          0 :                         if (inl_dev && inl_dev->cpt_cq_ena) {
    1888                 :          0 :                                 lf->dq_ack_ena = true;
    1889                 :          0 :                                 lf->cpt_cq_ena = true;
    1890                 :          0 :                                 lf->cq_entry_size = 0;
    1891                 :          0 :                                 lf->cq_all = 0;
    1892                 :          0 :                                 lf->cq_size = lf->nb_desc;
    1893                 :          0 :                                 lf->cq_head = 1;
    1894                 :            :                         }
    1895                 :            :                 }
    1896                 :            : 
    1897                 :            :                 /* Setup CPT LF instruction queue */
    1898                 :          0 :                 rc = cpt_lf_init(lf, lf->cpt_cq_ena);
    1899         [ #  # ]:          0 :                 if (rc) {
    1900                 :          0 :                         plt_err("Failed to initialize CPT LF, rc=%d", rc);
    1901                 :          0 :                         goto lf_fini;
    1902                 :            :                 }
    1903                 :            : 
    1904                 :            :                 /* Associate this CPT LF with NIX PFFUNC */
    1905                 :          0 :                 rc = cpt_lf_outb_cfg(dev, sso_pffunc, nix->dev.pf_func, i,
    1906                 :            :                                      true);
    1907         [ #  # ]:          0 :                 if (rc) {
    1908                 :          0 :                         plt_err("Failed to setup CPT LF->(NIX,SSO) link, rc=%d",
    1909                 :            :                                 rc);
    1910                 :          0 :                         goto lf_fini;
    1911                 :            :                 }
    1912                 :            : 
    1913                 :            :                 /* Enable IQ */
    1914                 :          0 :                 roc_cpt_iq_enable(lf);
    1915                 :            :                 /* Enable CQ */
    1916         [ #  # ]:          0 :                 if (lf->cpt_cq_ena) {
    1917                 :          0 :                         rc = cpt_lf_register_irqs(lf, cpt_lf_misc_irq, nix_inl_cpt_done_irq);
    1918         [ #  # ]:          0 :                         if (rc)
    1919                 :          0 :                                 goto lf_fini;
    1920                 :          0 :                         roc_cpt_cq_enable(lf);
    1921                 :            :                 }
    1922                 :            :         }
    1923                 :            : 
    1924         [ #  # ]:          0 :         if (!roc_nix->ipsec_out_max_sa)
    1925                 :          0 :                 goto skip_sa_alloc;
    1926                 :            : 
    1927                 :            :         sa_sz = ROC_NIX_INL_IPSEC_OUTB_SA_SZ;
    1928                 :            : 
    1929                 :            :         /* Alloc contiguous memory of outbound SA */
    1930                 :          0 :         sa_base = plt_zmalloc(sa_sz * roc_nix->ipsec_out_max_sa,
    1931                 :            :                               ROC_NIX_INL_SA_BASE_ALIGN);
    1932         [ #  # ]:          0 :         if (!sa_base) {
    1933                 :          0 :                 plt_err("Outbound SA base alloc failed");
    1934                 :          0 :                 goto lf_fini;
    1935                 :            :         }
    1936                 :            : 
    1937         [ #  # ]:          0 :         if (!roc_model_is_cn9k()) {
    1938         [ #  # ]:          0 :                 for (i = 0; i < roc_nix->ipsec_out_max_sa; i++) {
    1939         [ #  # ]:          0 :                         sa = ((uint8_t *)sa_base) + (i * sa_sz);
    1940         [ #  # ]:          0 :                         if (roc_model_is_cn10k())
    1941                 :          0 :                                 roc_ot_ipsec_outb_sa_init(sa);
    1942                 :            :                         else
    1943                 :          0 :                                 roc_ow_ipsec_outb_sa_init(sa);
    1944                 :            :                 }
    1945                 :            :         }
    1946                 :          0 :         nix->outb_sa_base = sa_base;
    1947                 :          0 :         nix->outb_sa_sz = sa_sz;
    1948                 :            : 
    1949                 :          0 : skip_sa_alloc:
    1950                 :            : 
    1951                 :          0 :         nix->cpt_lf_base = lf_base;
    1952                 :          0 :         nix->nb_cpt_lf = nb_lf;
    1953                 :          0 :         nix->outb_err_sso_pffunc = sso_pffunc;
    1954                 :          0 :         nix->inl_outb_ena = true;
    1955                 :          0 :         nix->outb_se_ring_cnt =
    1956                 :          0 :                 roc_nix->ipsec_out_max_sa / ROC_IPSEC_ERR_RING_MAX_ENTRY + 1;
    1957                 :          0 :         nix->outb_se_ring_base =
    1958                 :          0 :                 roc_nix->port_id * ROC_NIX_SOFT_EXP_PER_PORT_MAX_RINGS;
    1959                 :            : 
    1960                 :            :         /* Fetch engine capabilities */
    1961                 :          0 :         nix_inl_eng_caps_get(nix);
    1962                 :            : 
    1963   [ #  #  #  # ]:          0 :         if (inl_dev == NULL || !inl_dev->set_soft_exp_poll) {
    1964                 :          0 :                 nix->outb_se_ring_cnt = 0;
    1965                 :          0 :                 return 0;
    1966                 :            :         }
    1967                 :            : 
    1968                 :            :         /* Allocate memory to be used as a ring buffer to poll for
    1969                 :            :          * soft expiry event from ucode
    1970                 :            :          */
    1971                 :            :         ring_sz = (ROC_IPSEC_ERR_RING_MAX_ENTRY + 1) * sizeof(uint64_t);
    1972                 :          0 :         ring_base = inl_dev->sa_soft_exp_ring;
    1973         [ #  # ]:          0 :         for (i = 0; i < nix->outb_se_ring_cnt; i++) {
    1974                 :          0 :                 ring_base[nix->outb_se_ring_base + i] =
    1975                 :          0 :                         PLT_U64_CAST(plt_zmalloc(ring_sz, 0));
    1976         [ #  # ]:          0 :                 if (!ring_base[nix->outb_se_ring_base + i]) {
    1977                 :          0 :                         plt_err("Couldn't allocate memory for soft exp ring");
    1978         [ #  # ]:          0 :                         while (i--)
    1979                 :          0 :                                 plt_free(PLT_PTR_CAST(
    1980                 :            :                                         ring_base[nix->outb_se_ring_base + i]));
    1981                 :            :                         rc = -ENOMEM;
    1982                 :          0 :                         goto lf_fini;
    1983                 :            :                 }
    1984                 :            :         }
    1985                 :            : 
    1986                 :            :         return 0;
    1987                 :            : 
    1988                 :          0 : lf_fini:
    1989         [ #  # ]:          0 :         for (j = i - 1; j >= 0; j--) {
    1990                 :          0 :                 lf = &lf_base[j];
    1991                 :          0 :                 cpt_lf_fini(lf, lf->cpt_cq_ena);
    1992         [ #  # ]:          0 :                 if (lf->cpt_cq_ena)
    1993                 :          0 :                         cpt_lf_unregister_irqs(lf, cpt_lf_misc_irq, nix_inl_cpt_done_irq);
    1994                 :            :         }
    1995                 :          0 :         plt_free(lf_base);
    1996                 :          0 : lf_free:
    1997                 :          0 :         rc |= cpt_lfs_free(dev);
    1998                 :          0 : lf_detach:
    1999                 :          0 :         rc |= cpt_lfs_detach(dev);
    2000                 :          0 :         return rc;
    2001                 :            : }
    2002                 :            : 
    2003                 :            : int
    2004                 :          0 : roc_nix_inl_outb_fini(struct roc_nix *roc_nix)
    2005                 :            : {
    2006                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2007                 :          0 :         struct roc_cpt_lf *lf_base = nix->cpt_lf_base;
    2008                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2009                 :          0 :         struct dev *dev = &nix->dev;
    2010                 :            :         struct nix_inl_dev *inl_dev;
    2011                 :            :         struct roc_cpt_lf *lf;
    2012                 :            :         uint64_t *ring_base;
    2013                 :            :         int i, rc, ret = 0;
    2014                 :            : 
    2015         [ #  # ]:          0 :         if (!nix->inl_outb_ena)
    2016                 :            :                 return 0;
    2017                 :            : 
    2018                 :          0 :         nix->inl_outb_ena = false;
    2019                 :            : 
    2020                 :            :         /* Cleanup CPT LF instruction queue */
    2021         [ #  # ]:          0 :         for (i = 0; i < nix->nb_cpt_lf; i++) {
    2022                 :          0 :                 lf = &lf_base[i];
    2023                 :          0 :                 cpt_lf_fini(lf, lf->cpt_cq_ena);
    2024         [ #  # ]:          0 :                 if (lf->cpt_cq_ena)
    2025                 :          0 :                         cpt_lf_unregister_irqs(lf, cpt_lf_misc_irq, nix_inl_cpt_done_irq);
    2026                 :            :         }
    2027                 :            :         /* Free LF resources */
    2028                 :          0 :         rc = cpt_lfs_free(dev);
    2029         [ #  # ]:          0 :         if (rc)
    2030                 :          0 :                 plt_err("Failed to free CPT LF resources, rc=%d", rc);
    2031                 :            :         ret |= rc;
    2032                 :            : 
    2033                 :            :         /* Detach LF */
    2034                 :          0 :         rc = cpt_lfs_detach(dev);
    2035         [ #  # ]:          0 :         if (rc)
    2036                 :          0 :                 plt_err("Failed to detach CPT LF, rc=%d", rc);
    2037                 :            : 
    2038                 :            :         /* Free LF memory */
    2039                 :          0 :         plt_free(lf_base);
    2040                 :          0 :         nix->cpt_lf_base = NULL;
    2041                 :          0 :         nix->nb_cpt_lf = 0;
    2042                 :            : 
    2043                 :            :         /* Free outbound SA base */
    2044                 :          0 :         plt_free(nix->outb_sa_base);
    2045                 :          0 :         nix->outb_sa_base = NULL;
    2046                 :            : 
    2047   [ #  #  #  #  :          0 :         if (idev && idev->nix_inl_dev && nix->outb_se_ring_cnt) {
                   #  # ]
    2048                 :            :                 inl_dev = idev->nix_inl_dev;
    2049                 :          0 :                 ring_base = inl_dev->sa_soft_exp_ring;
    2050                 :          0 :                 ring_base += nix->outb_se_ring_base;
    2051                 :            : 
    2052         [ #  # ]:          0 :                 for (i = 0; i < nix->outb_se_ring_cnt; i++) {
    2053         [ #  # ]:          0 :                         if (ring_base[i])
    2054                 :          0 :                                 plt_free(PLT_PTR_CAST(ring_base[i]));
    2055                 :            :                 }
    2056                 :            :         }
    2057                 :            : 
    2058                 :          0 :         ret |= rc;
    2059                 :          0 :         return ret;
    2060                 :            : }
    2061                 :            : 
    2062                 :            : bool
    2063                 :          0 : roc_nix_inl_dev_is_probed(void)
    2064                 :            : {
    2065                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2066                 :            : 
    2067         [ #  # ]:          0 :         if (idev == NULL)
    2068                 :            :                 return 0;
    2069                 :            : 
    2070                 :          0 :         return !!idev->nix_inl_dev;
    2071                 :            : }
    2072                 :            : 
    2073                 :            : bool
    2074                 :          0 : roc_nix_inl_dev_is_multi_channel(void)
    2075                 :            : {
    2076                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2077                 :            :         struct nix_inl_dev *inl_dev;
    2078                 :            : 
    2079   [ #  #  #  # ]:          0 :         if (idev == NULL || !idev->nix_inl_dev)
    2080                 :            :                 return false;
    2081                 :            : 
    2082                 :            :         inl_dev = idev->nix_inl_dev;
    2083                 :          0 :         return inl_dev->is_multi_channel;
    2084                 :            : }
    2085                 :            : 
    2086                 :            : bool
    2087                 :          0 : roc_nix_inl_inb_is_enabled(struct roc_nix *roc_nix)
    2088                 :            : {
    2089                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2090                 :            : 
    2091                 :          0 :         return nix->inl_inb_ena;
    2092                 :            : }
    2093                 :            : 
    2094                 :            : bool
    2095                 :          0 : roc_nix_inl_outb_is_enabled(struct roc_nix *roc_nix)
    2096                 :            : {
    2097                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2098                 :            : 
    2099                 :          0 :         return nix->inl_outb_ena;
    2100                 :            : }
    2101                 :            : 
    2102                 :            : int
    2103                 :          0 : roc_nix_inl_dev_rq_get(struct roc_nix_rq *rq, bool enable)
    2104                 :            : {
    2105                 :          0 :         struct nix *nix = roc_nix_to_nix_priv(rq->roc_nix);
    2106                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2107                 :          0 :         int port_id = rq->roc_nix->port_id;
    2108                 :            :         struct nix_inl_dev *inl_dev;
    2109                 :            :         struct roc_nix_rq *inl_rq;
    2110                 :            :         uint16_t inl_rq_id;
    2111                 :            :         struct mbox *mbox;
    2112                 :            :         struct dev *dev;
    2113                 :            :         int rc;
    2114                 :            : 
    2115         [ #  # ]:          0 :         if (idev == NULL)
    2116                 :            :                 return 0;
    2117                 :            : 
    2118                 :            :         /* Update meta aura handle in RQ */
    2119         [ #  # ]:          0 :         if (nix->need_meta_aura)
    2120                 :          0 :                 rq->meta_aura_handle = roc_npa_zero_aura_handle();
    2121                 :            : 
    2122                 :          0 :         inl_dev = idev->nix_inl_dev;
    2123                 :            :         /* Nothing to do if no inline device */
    2124         [ #  # ]:          0 :         if (!inl_dev)
    2125                 :            :                 return 0;
    2126                 :            : 
    2127                 :            :         /* Check if this RQ is already holding reference */
    2128         [ #  # ]:          0 :         if (rq->inl_dev_refs)
    2129                 :            :                 return 0;
    2130                 :            : 
    2131         [ #  # ]:          0 :         inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
    2132                 :          0 :         dev = &inl_dev->dev;
    2133                 :          0 :         inl_rq = &inl_dev->rqs[inl_rq_id];
    2134                 :            : 
    2135                 :            :         /* Just take reference if already inited */
    2136         [ #  # ]:          0 :         if (inl_rq->inl_dev_refs) {
    2137                 :          0 :                 inl_rq->inl_dev_refs++;
    2138                 :          0 :                 rq->inl_dev_refs = 1;
    2139                 :          0 :                 return 0;
    2140                 :            :         }
    2141                 :            :         memset(inl_rq, 0, sizeof(struct roc_nix_rq));
    2142                 :            : 
    2143                 :            :         /* Take RQ pool attributes from the first ethdev RQ */
    2144                 :          0 :         inl_rq->qid = inl_rq_id;
    2145                 :          0 :         inl_rq->aura_handle = rq->aura_handle;
    2146                 :          0 :         inl_rq->first_skip = rq->first_skip;
    2147                 :          0 :         inl_rq->later_skip = rq->later_skip;
    2148                 :          0 :         inl_rq->lpb_size = rq->lpb_size;
    2149                 :          0 :         inl_rq->spb_ena = rq->spb_ena;
    2150                 :          0 :         inl_rq->spb_aura_handle = rq->spb_aura_handle;
    2151                 :          0 :         inl_rq->spb_size = rq->spb_size;
    2152                 :          0 :         inl_rq->pb_caching = rq->pb_caching;
    2153         [ #  # ]:          0 :         inl_rq->wqe_caching = rq->wqe_caching;
    2154                 :            : 
    2155         [ #  # ]:          0 :         if (roc_errata_nix_no_meta_aura()) {
    2156                 :            :                 uint64_t aura_limit =
    2157                 :            :                         roc_npa_aura_op_limit_get(inl_rq->aura_handle);
    2158                 :            :                 uint64_t aura_shift = plt_log2_u32(aura_limit);
    2159                 :            :                 uint64_t aura_drop, drop_pc;
    2160                 :            : 
    2161                 :          0 :                 inl_rq->lpb_drop_ena = true;
    2162                 :            : 
    2163                 :            :                 if (aura_shift < 8)
    2164                 :            :                         aura_shift = 0;
    2165                 :            :                 else
    2166                 :            :                         aura_shift = aura_shift - 8;
    2167                 :            : 
    2168                 :            :                 /* Set first pass RQ to drop after part of buffers are in
    2169                 :            :                  * use to avoid metabuf alloc failure. This is needed as long
    2170                 :            :                  * as we cannot use different aura.
    2171                 :            :                  */
    2172                 :            :                 drop_pc = inl_dev->lpb_drop_pc;
    2173                 :            :                 aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
    2174                 :          0 :                 roc_npa_aura_drop_set(inl_rq->aura_handle, aura_drop, true);
    2175                 :            :         }
    2176                 :            : 
    2177   [ #  #  #  # ]:          0 :         if (roc_errata_nix_no_meta_aura() && inl_rq->spb_ena) {
    2178                 :            :                 uint64_t aura_limit =
    2179                 :          0 :                         roc_npa_aura_op_limit_get(inl_rq->spb_aura_handle);
    2180                 :            :                 uint64_t aura_shift = plt_log2_u32(aura_limit);
    2181                 :            :                 uint64_t aura_drop, drop_pc;
    2182                 :            : 
    2183                 :          0 :                 inl_rq->spb_drop_ena = true;
    2184                 :            : 
    2185                 :            :                 if (aura_shift < 8)
    2186                 :            :                         aura_shift = 0;
    2187                 :            :                 else
    2188                 :            :                         aura_shift = aura_shift - 8;
    2189                 :            : 
    2190                 :            :                 /* Set first pass RQ to drop after part of buffers are in
    2191                 :            :                  * use to avoid metabuf alloc failure. This is needed as long
    2192                 :            :                  * as we cannot use different aura.
    2193                 :            :                  */
    2194                 :            :                 drop_pc = inl_dev->spb_drop_pc;
    2195                 :            :                 aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
    2196                 :          0 :                 roc_npa_aura_drop_set(inl_rq->spb_aura_handle, aura_drop, true);
    2197                 :            :         }
    2198                 :            : 
    2199                 :            :         /* Enable IPSec */
    2200                 :          0 :         inl_rq->ipsech_ena = true;
    2201                 :            : 
    2202                 :          0 :         inl_rq->flow_tag_width = 20;
    2203                 :            :         /* Special tag mask */
    2204                 :          0 :         inl_rq->tag_mask = rq->tag_mask;
    2205                 :          0 :         inl_rq->tt = SSO_TT_ORDERED;
    2206                 :          0 :         inl_rq->hwgrp = 0;
    2207                 :          0 :         inl_rq->wqe_skip = inl_dev->wqe_skip;
    2208                 :          0 :         inl_rq->sso_ena = true;
    2209                 :            : 
    2210                 :            :         /* Prepare and send RQ init mbox */
    2211                 :          0 :         mbox = mbox_get(dev->mbox);
    2212         [ #  # ]:          0 :         if (roc_model_is_cn9k())
    2213                 :          0 :                 rc = nix_rq_cn9k_cfg(dev, inl_rq, inl_dev->qints, false, enable);
    2214         [ #  # ]:          0 :         else if (roc_model_is_cn10k())
    2215                 :          0 :                 rc = nix_rq_cn10k_cfg(dev, inl_rq, inl_dev->qints, false, enable);
    2216                 :            :         else
    2217                 :          0 :                 rc = nix_rq_cfg(dev, inl_rq, inl_dev->qints, false, enable);
    2218         [ #  # ]:          0 :         if (rc) {
    2219                 :          0 :                 plt_err("Failed to prepare aq_enq msg, rc=%d", rc);
    2220                 :            :                 mbox_put(mbox);
    2221                 :          0 :                 return rc;
    2222                 :            :         }
    2223                 :            : 
    2224                 :          0 :         rc = mbox_process(dev->mbox);
    2225         [ #  # ]:          0 :         if (rc) {
    2226                 :          0 :                 plt_err("Failed to send aq_enq msg, rc=%d", rc);
    2227                 :            :                 mbox_put(mbox);
    2228                 :          0 :                 return rc;
    2229                 :            :         }
    2230                 :            :         mbox_put(mbox);
    2231                 :            : 
    2232                 :            :         /* Check meta aura */
    2233   [ #  #  #  # ]:          0 :         if (enable && nix->need_meta_aura) {
    2234                 :          0 :                 rc = roc_nix_inl_meta_aura_check(rq->roc_nix, rq);
    2235         [ #  # ]:          0 :                 if (rc)
    2236                 :            :                         return rc;
    2237                 :            :         }
    2238                 :            : 
    2239                 :          0 :         inl_rq->inl_dev_refs++;
    2240                 :          0 :         rq->inl_dev_refs = 1;
    2241                 :          0 :         return 0;
    2242                 :            : }
    2243                 :            : 
    2244                 :            : int
    2245                 :          0 : roc_nix_inl_dev_rq_put(struct roc_nix_rq *rq)
    2246                 :            : {
    2247                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2248                 :          0 :         int port_id = rq->roc_nix->port_id;
    2249                 :            :         struct nix_inl_dev *inl_dev;
    2250                 :            :         struct roc_nix_rq *inl_rq;
    2251                 :            :         uint16_t inl_rq_id;
    2252                 :            :         struct dev *dev;
    2253                 :            :         int rc;
    2254                 :            : 
    2255         [ #  # ]:          0 :         if (idev == NULL)
    2256                 :            :                 return 0;
    2257                 :            : 
    2258                 :          0 :         rq->meta_aura_handle = 0;
    2259         [ #  # ]:          0 :         if (!rq->inl_dev_refs)
    2260                 :            :                 return 0;
    2261                 :            : 
    2262                 :          0 :         inl_dev = idev->nix_inl_dev;
    2263                 :            :         /* Inline device should be there if we have ref */
    2264         [ #  # ]:          0 :         if (!inl_dev) {
    2265                 :          0 :                 plt_err("Failed to find inline device with refs");
    2266                 :          0 :                 return -EFAULT;
    2267                 :            :         }
    2268                 :            : 
    2269                 :          0 :         dev = &inl_dev->dev;
    2270         [ #  # ]:          0 :         inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
    2271                 :          0 :         inl_rq = &inl_dev->rqs[inl_rq_id];
    2272                 :            : 
    2273                 :          0 :         rq->inl_dev_refs = 0;
    2274                 :          0 :         inl_rq->inl_dev_refs--;
    2275         [ #  # ]:          0 :         if (inl_rq->inl_dev_refs)
    2276                 :            :                 return 0;
    2277                 :            : 
    2278                 :            :         /* There are no more references, disable RQ */
    2279                 :          0 :         rc = nix_rq_ena_dis(dev, inl_rq, false);
    2280         [ #  # ]:          0 :         if (rc)
    2281                 :          0 :                 plt_err("Failed to disable inline device rq, rc=%d", rc);
    2282                 :            : 
    2283                 :          0 :         roc_npa_aura_drop_set(inl_rq->aura_handle, 0, false);
    2284         [ #  # ]:          0 :         if (inl_rq->spb_ena)
    2285                 :          0 :                 roc_npa_aura_drop_set(inl_rq->spb_aura_handle, 0, false);
    2286                 :            : 
    2287                 :            :         /* Flush NIX LF for CN10K */
    2288                 :          0 :         nix_rq_vwqe_flush(rq, inl_dev->vwqe_interval);
    2289                 :            : 
    2290                 :          0 :         return rc;
    2291                 :            : }
    2292                 :            : 
    2293                 :            : int
    2294                 :          0 : roc_nix_inl_rq_ena_dis(struct roc_nix *roc_nix, bool enable)
    2295                 :            : {
    2296                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2297                 :          0 :         struct roc_nix_rq *inl_rq = roc_nix_inl_dev_rq(roc_nix);
    2298                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2299                 :            :         struct nix_inl_dev *inl_dev;
    2300                 :            :         int rc;
    2301                 :            : 
    2302         [ #  # ]:          0 :         if (!idev)
    2303                 :            :                 return -EFAULT;
    2304                 :            : 
    2305   [ #  #  #  # ]:          0 :         if (roc_feature_nix_has_inl_rq_mask() && enable) {
    2306                 :          0 :                 rc = nix_inl_rq_mask_cfg(roc_nix, enable);
    2307         [ #  # ]:          0 :                 if (rc) {
    2308                 :          0 :                         plt_err("Failed to get rq mask rc=%d", rc);
    2309                 :          0 :                         return rc;
    2310                 :            :                 }
    2311                 :            :         }
    2312                 :            : 
    2313         [ #  # ]:          0 :         if (nix->inb_inl_dev) {
    2314   [ #  #  #  # ]:          0 :                 if (!inl_rq || !idev->nix_inl_dev)
    2315                 :            :                         return -EFAULT;
    2316                 :            : 
    2317                 :            :                 inl_dev = idev->nix_inl_dev;
    2318                 :            : 
    2319         [ #  # ]:          0 :                 if (!roc_model_is_cn10k()) {
    2320         [ #  # ]:          0 :                         if (inl_rq->spb_ena) {
    2321                 :            :                                 rc = -EINVAL;
    2322                 :          0 :                                 plt_err("inline RQ enable is not supported rc=%d", rc);
    2323                 :          0 :                                 return rc;
    2324                 :            :                         }
    2325                 :            :                 }
    2326                 :            : 
    2327                 :          0 :                 rc = nix_rq_ena_dis(&inl_dev->dev, inl_rq, enable);
    2328         [ #  # ]:          0 :                 if (rc)
    2329                 :            :                         return rc;
    2330                 :            : 
    2331   [ #  #  #  # ]:          0 :                 if (enable && nix->need_meta_aura)
    2332                 :          0 :                         return roc_nix_inl_meta_aura_check(roc_nix, inl_rq);
    2333                 :            :         }
    2334                 :            :         return 0;
    2335                 :            : }
    2336                 :            : 
    2337                 :            : void
    2338                 :          0 : roc_nix_inb_mode_set(struct roc_nix *roc_nix, bool use_inl_dev)
    2339                 :            : {
    2340                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2341                 :            : 
    2342                 :            :         /* Info used by NPC flow rule add */
    2343                 :          0 :         nix->inb_inl_dev = use_inl_dev;
    2344                 :          0 : }
    2345                 :            : 
    2346                 :            : void
    2347                 :          0 : roc_nix_inl_inb_set(struct roc_nix *roc_nix, bool ena)
    2348                 :            : {
    2349                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2350                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2351                 :            : 
    2352         [ #  # ]:          0 :         if (!idev)
    2353                 :            :                 return;
    2354                 :            :         /* Need to set here for cases when inbound SA table is
    2355                 :            :          * managed outside RoC.
    2356                 :            :          */
    2357         [ #  # ]:          0 :         nix->inl_inb_ena = ena;
    2358                 :            : 
    2359   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() || roc_errata_nix_no_meta_aura())
    2360                 :            :                 return;
    2361                 :            : 
    2362         [ #  # ]:          0 :         if (ena) {
    2363                 :          0 :                 nix->need_meta_aura = true;
    2364   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
    2365                 :          0 :                         idev->inl_cfg.refs++;
    2366         [ #  # ]:          0 :         } else if (nix->need_meta_aura) {
    2367                 :          0 :                 nix->need_meta_aura = false;
    2368   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
    2369                 :          0 :                         idev->inl_cfg.refs--;
    2370                 :            : 
    2371         [ #  # ]:          0 :                 if (roc_nix->custom_meta_aura_ena)
    2372                 :          0 :                         nix_inl_custom_meta_aura_destroy(roc_nix);
    2373                 :            : 
    2374         [ #  # ]:          0 :                 if (!idev->inl_cfg.refs)
    2375                 :          0 :                         nix_inl_meta_aura_destroy(roc_nix);
    2376                 :            :         }
    2377                 :            : }
    2378                 :            : 
    2379                 :            : int
    2380                 :          0 : roc_nix_inl_outb_soft_exp_poll_switch(struct roc_nix *roc_nix, bool poll)
    2381                 :            : {
    2382                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2383                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2384                 :            :         struct nix_inl_dev *inl_dev;
    2385                 :            :         uint16_t ring_idx, i;
    2386                 :            : 
    2387   [ #  #  #  # ]:          0 :         if (!idev || !idev->nix_inl_dev)
    2388                 :            :                 return 0;
    2389                 :            : 
    2390                 :            :         inl_dev = idev->nix_inl_dev;
    2391                 :            : 
    2392         [ #  # ]:          0 :         for (i = 0; i < nix->outb_se_ring_cnt; i++) {
    2393                 :          0 :                 ring_idx = nix->outb_se_ring_base + i;
    2394                 :            : 
    2395         [ #  # ]:          0 :                 if (poll)
    2396                 :          0 :                         plt_bitmap_set(inl_dev->soft_exp_ring_bmap, ring_idx);
    2397                 :            :                 else
    2398                 :          0 :                         plt_bitmap_clear(inl_dev->soft_exp_ring_bmap, ring_idx);
    2399                 :            :         }
    2400                 :            : 
    2401         [ #  # ]:          0 :         if (poll)
    2402                 :          0 :                 soft_exp_consumer_cnt++;
    2403                 :            :         else
    2404                 :          0 :                 soft_exp_consumer_cnt--;
    2405                 :            : 
    2406                 :            :         return 0;
    2407                 :            : }
    2408                 :            : 
    2409                 :            : bool
    2410                 :          0 : roc_nix_inb_is_with_inl_dev(struct roc_nix *roc_nix)
    2411                 :            : {
    2412                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2413                 :            : 
    2414                 :          0 :         return nix->inb_inl_dev;
    2415                 :            : }
    2416                 :            : 
    2417                 :            : struct roc_nix_rq *
    2418                 :          0 : roc_nix_inl_dev_rq(struct roc_nix *roc_nix)
    2419                 :            : {
    2420                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2421                 :          0 :         int port_id = roc_nix->port_id;
    2422                 :            :         struct nix_inl_dev *inl_dev;
    2423                 :            :         struct roc_nix_rq *inl_rq;
    2424                 :            :         uint16_t inl_rq_id;
    2425                 :            : 
    2426         [ #  # ]:          0 :         if (idev != NULL) {
    2427                 :          0 :                 inl_dev = idev->nix_inl_dev;
    2428         [ #  # ]:          0 :                 if (inl_dev != NULL) {
    2429         [ #  # ]:          0 :                         inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
    2430                 :          0 :                         inl_rq = &inl_dev->rqs[inl_rq_id];
    2431         [ #  # ]:          0 :                         if (inl_rq->inl_dev_refs)
    2432                 :          0 :                                 return inl_rq;
    2433                 :            :                 }
    2434                 :            :         }
    2435                 :            : 
    2436                 :            :         return NULL;
    2437                 :            : }
    2438                 :            : 
    2439                 :            : uint16_t __roc_api
    2440                 :          0 : roc_nix_inl_outb_sso_pffunc_get(struct roc_nix *roc_nix)
    2441                 :            : {
    2442                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2443                 :            : 
    2444                 :          0 :         return nix->outb_err_sso_pffunc;
    2445                 :            : }
    2446                 :            : 
    2447                 :            : int
    2448                 :          0 : roc_nix_inl_cb_register(roc_nix_inl_sso_work_cb_t cb, void *args)
    2449                 :            : {
    2450                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2451                 :            :         struct nix_inl_dev *inl_dev;
    2452                 :            : 
    2453         [ #  # ]:          0 :         if (idev == NULL)
    2454                 :            :                 return -EIO;
    2455                 :            : 
    2456                 :          0 :         inl_dev = idev->nix_inl_dev;
    2457         [ #  # ]:          0 :         if (!inl_dev)
    2458                 :            :                 return -EIO;
    2459                 :            : 
    2460                 :            :         /* Be silent if registration called with same cb and args */
    2461   [ #  #  #  # ]:          0 :         if (inl_dev->work_cb == cb && inl_dev->cb_args == args)
    2462                 :            :                 return 0;
    2463                 :            : 
    2464                 :            :         /* Don't allow registration again if registered with different cb */
    2465         [ #  # ]:          0 :         if (inl_dev->work_cb)
    2466                 :            :                 return -EBUSY;
    2467                 :            : 
    2468                 :          0 :         inl_dev->work_cb = cb;
    2469                 :          0 :         inl_dev->cb_args = args;
    2470                 :          0 :         return 0;
    2471                 :            : }
    2472                 :            : 
    2473                 :            : int
    2474                 :          0 : roc_nix_inl_cb_unregister(roc_nix_inl_sso_work_cb_t cb, void *args)
    2475                 :            : {
    2476                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2477                 :            :         struct nix_inl_dev *inl_dev;
    2478                 :            : 
    2479         [ #  # ]:          0 :         if (idev == NULL)
    2480                 :            :                 return -ENOENT;
    2481                 :            : 
    2482                 :          0 :         inl_dev = idev->nix_inl_dev;
    2483         [ #  # ]:          0 :         if (!inl_dev)
    2484                 :            :                 return -ENOENT;
    2485                 :            : 
    2486   [ #  #  #  # ]:          0 :         if (inl_dev->work_cb != cb || inl_dev->cb_args != args)
    2487                 :            :                 return -EINVAL;
    2488                 :            : 
    2489                 :          0 :         inl_dev->work_cb = NULL;
    2490                 :          0 :         inl_dev->cb_args = NULL;
    2491                 :          0 :         return 0;
    2492                 :            : }
    2493                 :            : 
    2494                 :            : int
    2495                 :          0 : roc_nix_inl_inb_tag_update(struct roc_nix *roc_nix, uint32_t tag_const,
    2496                 :            :                            uint8_t tt)
    2497                 :            : {
    2498                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2499                 :            :         struct roc_nix_ipsec_cfg cfg;
    2500                 :            : 
    2501                 :            :         /* Be silent if inline inbound not enabled */
    2502         [ #  # ]:          0 :         if (!nix->inl_inb_ena)
    2503                 :            :                 return 0;
    2504                 :            : 
    2505                 :            :         memset(&cfg, 0, sizeof(cfg));
    2506                 :          0 :         cfg.sa_size = nix->inb_sa_sz[nix->ipsec_prof_id];
    2507                 :          0 :         cfg.iova = (uintptr_t)nix->inb_sa_base[nix->ipsec_prof_id];
    2508                 :          0 :         cfg.max_sa = nix->inb_spi_mask + 1;
    2509                 :          0 :         cfg.tt = tt;
    2510                 :          0 :         cfg.tag_const = tag_const;
    2511         [ #  # ]:          0 :         if (roc_nix->res_addr_offset)
    2512                 :          0 :                 cfg.res_addr_offset = roc_nix->res_addr_offset;
    2513                 :            : 
    2514                 :          0 :         return roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
    2515                 :            : }
    2516                 :            : 
    2517                 :            : int
    2518                 :          0 : roc_nix_inl_sa_sync(struct roc_nix *roc_nix, void *sa, bool inb,
    2519                 :            :                     enum roc_nix_inl_sa_sync_op op)
    2520                 :            : {
    2521                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2522                 :            :         struct nix_inl_dev *inl_dev = NULL;
    2523                 :            :         struct roc_cpt_lf *outb_lf = NULL;
    2524                 :            :         union cpt_lf_ctx_reload reload;
    2525                 :            :         union cpt_lf_ctx_flush flush;
    2526                 :            :         union cpt_lf_ctx_err err;
    2527                 :            :         union cpt_lf_ctx_inval inval;
    2528                 :            :         bool get_inl_lf = true;
    2529                 :            :         uintptr_t rbase;
    2530                 :            :         struct nix *nix;
    2531                 :            : 
    2532                 :            :         /* Nothing much to do on cn9k */
    2533         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    2534                 :            :                 plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
    2535                 :          0 :                 return 0;
    2536                 :            :         }
    2537                 :            : 
    2538         [ #  # ]:          0 :         if (idev)
    2539                 :          0 :                 inl_dev = idev->nix_inl_dev;
    2540                 :            : 
    2541   [ #  #  #  # ]:          0 :         if ((!inl_dev && roc_nix == NULL) || sa == NULL)
    2542                 :            :                 return -EINVAL;
    2543                 :            : 
    2544         [ #  # ]:          0 :         if (roc_nix) {
    2545                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    2546                 :          0 :                 outb_lf = nix->cpt_lf_base;
    2547   [ #  #  #  # ]:          0 :                 if (inb && !nix->inb_inl_dev)
    2548                 :            :                         get_inl_lf = false;
    2549                 :            :         }
    2550                 :            : 
    2551         [ #  # ]:          0 :         if (inb && get_inl_lf) {
    2552                 :            :                 outb_lf = NULL;
    2553   [ #  #  #  # ]:          0 :                 if (inl_dev && inl_dev->attach_cptlf)
    2554                 :          0 :                         outb_lf = &inl_dev->cpt_lf[0];
    2555                 :            :         }
    2556                 :            : 
    2557         [ #  # ]:          0 :         if (outb_lf) {
    2558                 :          0 :                 rbase = outb_lf->rbase;
    2559                 :            : 
    2560                 :          0 :                 flush.u = 0;
    2561                 :          0 :                 reload.u = 0;
    2562                 :          0 :                 inval.u = 0;
    2563   [ #  #  #  # ]:          0 :                 switch (op) {
    2564                 :            :                 case ROC_NIX_INL_SA_OP_FLUSH_INVAL:
    2565         [ #  # ]:          0 :                         if (!roc_model_is_cn10k()) {
    2566                 :          0 :                                 inval.s.cptr = ((uintptr_t)sa) >> 7;
    2567                 :          0 :                                 plt_write64(inval.u, rbase + CPT_LF_CTX_INVAL);
    2568                 :            :                                 break;
    2569                 :            :                         }
    2570                 :            : 
    2571                 :          0 :                         flush.s.inval = 1;
    2572                 :            :                         /* fall through */
    2573                 :          0 :                 case ROC_NIX_INL_SA_OP_FLUSH:
    2574                 :          0 :                         flush.s.cptr = ((uintptr_t)sa) >> 7;
    2575         [ #  # ]:          0 :                         plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
    2576                 :            :                         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
    2577                 :            :                         /* Read a CSR to ensure that the FLUSH operation is complete */
    2578         [ #  # ]:          0 :                         err.u = plt_read64(rbase + CPT_LF_CTX_ERR);
    2579                 :            : 
    2580         [ #  # ]:          0 :                         if (err.s.flush_st_flt) {
    2581                 :          0 :                                 plt_warn("CTX flush could not complete");
    2582                 :          0 :                                 return -EIO;
    2583                 :            :                         }
    2584                 :            :                         break;
    2585                 :          0 :                 case ROC_NIX_INL_SA_OP_RELOAD:
    2586                 :          0 :                         reload.s.cptr = ((uintptr_t)sa) >> 7;
    2587                 :          0 :                         plt_write64(reload.u, rbase + CPT_LF_CTX_RELOAD);
    2588                 :            :                         break;
    2589                 :            :                 default:
    2590                 :            :                         return -EINVAL;
    2591                 :            :                 }
    2592                 :          0 :                 return 0;
    2593                 :            :         }
    2594                 :          0 :         plt_err("Could not get CPT LF for SA sync");
    2595                 :          0 :         return -ENOTSUP;
    2596                 :            : }
    2597                 :            : 
    2598                 :            : int
    2599                 :          0 : roc_nix_inl_ctx_write(struct roc_nix *roc_nix, void *sa_dptr, void *sa_cptr,
    2600                 :            :                       bool inb, uint16_t sa_len)
    2601                 :            : {
    2602                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2603                 :            :         struct nix_inl_dev *inl_dev = NULL;
    2604                 :            :         struct roc_cpt_lf *outb_lf = NULL;
    2605                 :            :         union cpt_lf_ctx_flush flush;
    2606                 :            :         union cpt_lf_ctx_inval inval;
    2607                 :            :         union cpt_lf_ctx_err err;
    2608                 :            :         bool get_inl_lf = true;
    2609                 :            :         uintptr_t rbase;
    2610                 :            :         struct nix *nix;
    2611                 :            :         uint64_t *sa;
    2612                 :            :         int rc;
    2613                 :            : 
    2614                 :            :         /* Nothing much to do on cn9k */
    2615         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    2616                 :            :                 return 0;
    2617                 :            :         }
    2618         [ #  # ]:          0 :         if (idev)
    2619                 :          0 :                 inl_dev = idev->nix_inl_dev;
    2620                 :            : 
    2621   [ #  #  #  # ]:          0 :         if ((!inl_dev && roc_nix == NULL) || sa_dptr == NULL || sa_cptr == NULL)
    2622                 :            :                 return -EINVAL;
    2623                 :            : 
    2624         [ #  # ]:          0 :         if (roc_nix) {
    2625   [ #  #  #  #  :          0 :                 if (inb && roc_nix->custom_inb_sa && sa_len > ROC_NIX_INL_INB_CUSTOM_SA_SZ) {
                   #  # ]
    2626                 :          0 :                         plt_nix_dbg("SA length: %u is more than allocated length: %u", sa_len,
    2627                 :            :                                     ROC_NIX_INL_INB_CUSTOM_SA_SZ);
    2628                 :          0 :                         return -EINVAL;
    2629                 :            :                 }
    2630                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    2631                 :          0 :                 outb_lf = nix->cpt_lf_base;
    2632                 :            : 
    2633   [ #  #  #  # ]:          0 :                 if (inb && !nix->inb_inl_dev)
    2634                 :            :                         get_inl_lf = false;
    2635                 :            :         }
    2636                 :            : 
    2637         [ #  # ]:          0 :         if (inb && get_inl_lf) {
    2638                 :            :                 outb_lf = NULL;
    2639   [ #  #  #  # ]:          0 :                 if (inl_dev && inl_dev->attach_cptlf)
    2640                 :          0 :                         outb_lf = &inl_dev->cpt_lf[0];
    2641                 :            :         }
    2642                 :            : 
    2643         [ #  # ]:          0 :         if (outb_lf == NULL)
    2644                 :          0 :                 goto exit;
    2645                 :            : 
    2646   [ #  #  #  #  :          0 :         if (roc_model_is_cn10k() || (roc_nix && roc_nix->use_write_sa)) {
                   #  # ]
    2647                 :          0 :                 rbase = outb_lf->rbase;
    2648                 :          0 :                 flush.u = 0;
    2649                 :            : 
    2650                 :          0 :                 rc = roc_cpt_ctx_write(outb_lf, sa_dptr, sa_cptr, sa_len);
    2651         [ #  # ]:          0 :                 if (rc)
    2652                 :            :                         return rc;
    2653                 :            :                 /* Trigger CTX flush to write dirty data back to DRAM */
    2654                 :          0 :                 flush.s.cptr = ((uintptr_t)sa_cptr) >> 7;
    2655         [ #  # ]:          0 :                 plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
    2656                 :            : 
    2657                 :            :                 plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
    2658                 :            : 
    2659                 :            :                 /* Read a CSR to ensure that the FLUSH operation is complete */
    2660         [ #  # ]:          0 :                 err.u = plt_read64(rbase + CPT_LF_CTX_ERR);
    2661                 :            : 
    2662         [ #  # ]:          0 :                 if (err.s.flush_st_flt)
    2663                 :          0 :                         plt_warn("CTX flush could not complete");
    2664                 :          0 :                 return 0;
    2665                 :            :         } else {
    2666                 :            :                 sa = sa_dptr;
    2667                 :            : 
    2668                 :            :                 /* Clear bit 58 aop_valid */
    2669                 :          0 :                 sa[0] &= ~(1ULL << 58);
    2670                 :          0 :                 memcpy(sa_cptr, sa_dptr, sa_len);
    2671                 :          0 :                 plt_io_wmb();
    2672                 :            : 
    2673                 :            :                 /* Trigger CTX invalidate */
    2674                 :          0 :                 rbase = outb_lf->rbase;
    2675                 :          0 :                 inval.u = 0;
    2676                 :          0 :                 inval.s.cptr = ((uintptr_t)sa_cptr) >> 7;
    2677                 :          0 :                 plt_write64(inval.u, rbase + CPT_LF_CTX_INVAL);
    2678                 :            : 
    2679                 :            :                 /* Set bit 58 aop_valid */
    2680                 :            :                 sa = sa_cptr;
    2681                 :          0 :                 sa[0] |= (1ULL << 58);
    2682                 :          0 :                 plt_io_wmb();
    2683                 :            : 
    2684                 :          0 :                 return 0;
    2685                 :            :         }
    2686                 :            : 
    2687                 :            : exit:
    2688                 :          0 :         plt_nix_dbg("Could not get CPT LF for CTX write");
    2689                 :          0 :         return -ENOTSUP;
    2690                 :            : }
    2691                 :            : 
    2692                 :            : static inline int
    2693                 :          0 : nix_inl_dev_cpt_lf_stats_get(struct roc_nix *roc_nix, struct roc_nix_cpt_lf_stats *stats,
    2694                 :            :                              uint16_t idx)
    2695                 :            : {
    2696                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2697                 :            :         struct nix_inl_dev *inl_dev = NULL;
    2698                 :            :         struct roc_cpt_lf *lf = NULL;
    2699                 :            : 
    2700                 :            :         PLT_SET_USED(roc_nix);
    2701         [ #  # ]:          0 :         if (idev)
    2702                 :          0 :                 inl_dev = idev->nix_inl_dev;
    2703                 :            : 
    2704   [ #  #  #  # ]:          0 :         if (inl_dev && inl_dev->attach_cptlf) {
    2705         [ #  # ]:          0 :                 if (idx >= inl_dev->nb_cptlf) {
    2706                 :          0 :                         plt_err("Invalid idx: %u total lfs: %d", idx, inl_dev->nb_cptlf);
    2707                 :          0 :                         return -EINVAL;
    2708                 :            :                 }
    2709                 :          0 :                 lf = &inl_dev->cpt_lf[idx];
    2710                 :            :         } else {
    2711                 :          0 :                 plt_err("No CPT LF(s) are found for Inline Device");
    2712                 :          0 :                 return -EINVAL;
    2713                 :            :         }
    2714                 :          0 :         stats->enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
    2715                 :          0 :         stats->enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
    2716                 :          0 :         stats->dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
    2717                 :          0 :         stats->dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
    2718                 :            : 
    2719                 :          0 :         return 0;
    2720                 :            : }
    2721                 :            : 
    2722                 :            : static inline int
    2723                 :          0 : nix_eth_dev_cpt_lf_stats_get(struct roc_nix *roc_nix, struct roc_nix_cpt_lf_stats *stats,
    2724                 :            :                              uint16_t idx)
    2725                 :            : {
    2726                 :            :         struct roc_cpt_lf *lf;
    2727                 :            :         struct nix *nix;
    2728                 :            : 
    2729         [ #  # ]:          0 :         if (!roc_nix)
    2730                 :            :                 return -EINVAL;
    2731                 :            :         nix = roc_nix_to_nix_priv(roc_nix);
    2732         [ #  # ]:          0 :         if (idx >= nix->nb_cpt_lf) {
    2733                 :          0 :                 plt_err("Invalid idx: %u total lfs: %d", idx, nix->nb_cpt_lf);
    2734                 :          0 :                 return -EINVAL;
    2735                 :            :         }
    2736                 :          0 :         lf = &nix->cpt_lf_base[idx];
    2737                 :          0 :         stats->enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
    2738                 :          0 :         stats->enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
    2739                 :          0 :         stats->dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
    2740                 :          0 :         stats->dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
    2741                 :            : 
    2742                 :          0 :         return 0;
    2743                 :            : }
    2744                 :            : 
    2745                 :            : int
    2746                 :          0 : roc_nix_inl_cpt_lf_stats_get(struct roc_nix *roc_nix, enum roc_nix_cpt_lf_stats_type type,
    2747                 :            :                              struct roc_nix_cpt_lf_stats *stats, uint16_t idx)
    2748                 :            : {
    2749      [ #  #  # ]:          0 :         switch (type) {
    2750                 :          0 :         case ROC_NIX_CPT_LF_STATS_INL_DEV:
    2751                 :          0 :                 return nix_inl_dev_cpt_lf_stats_get(roc_nix, stats, idx);
    2752                 :          0 :         case ROC_NIX_CPT_LF_STATS_ETHDEV:
    2753                 :          0 :                 return nix_eth_dev_cpt_lf_stats_get(roc_nix, stats, idx);
    2754                 :            :         default:
    2755                 :            :                 return -EINVAL;
    2756                 :            :         }
    2757                 :            : }
    2758                 :            : 
    2759                 :            : static int
    2760                 :          0 : nix_inl_ts_pkind_set(struct roc_nix *roc_nix, bool ts_ena, bool inb_inl_dev, uint8_t profile_id)
    2761                 :            : {
    2762                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2763                 :            :         struct nix_inl_dev *inl_dev = NULL;
    2764                 :            :         void *sa, *sa_base = NULL;
    2765                 :            :         struct nix *nix = NULL;
    2766                 :            :         uint32_t rq_refs = 0;
    2767                 :            :         uint16_t max_sa = 0;
    2768                 :            :         uint8_t pkind = 0;
    2769                 :            :         size_t inb_sa_sz;
    2770                 :            :         int i;
    2771                 :            : 
    2772         [ #  # ]:          0 :         if (roc_model_is_cn9k())
    2773                 :            :                 return 0;
    2774                 :            : 
    2775   [ #  #  #  # ]:          0 :         if (!inb_inl_dev && (roc_nix == NULL) && profile_id >= ROC_NIX_INL_PROFILE_CNT)
    2776                 :            :                 return -EINVAL;
    2777                 :            : 
    2778         [ #  # ]:          0 :         if (inb_inl_dev) {
    2779   [ #  #  #  # ]:          0 :                 if ((idev == NULL) || (idev->nix_inl_dev == NULL))
    2780                 :            :                         return 0;
    2781                 :            :                 inl_dev = idev->nix_inl_dev;
    2782                 :            :         } else {
    2783                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    2784         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
    2785                 :            :                         return 0;
    2786                 :            : 
    2787                 :          0 :                 sa_base = nix->inb_sa_base[profile_id];
    2788         [ #  # ]:          0 :                 if (sa_base == NULL)
    2789                 :            :                         return 0;
    2790                 :          0 :                 inb_sa_sz = nix->inb_sa_sz[profile_id];
    2791                 :          0 :                 max_sa = nix->inb_sa_max[profile_id];
    2792                 :            :         }
    2793                 :            : 
    2794         [ #  # ]:          0 :         if (inl_dev) {
    2795         [ #  # ]:          0 :                 for (i = 0; i < inl_dev->nb_rqs; i++)
    2796                 :          0 :                         rq_refs += inl_dev->rqs[i].inl_dev_refs;
    2797                 :            : 
    2798         [ #  # ]:          0 :                 if (rq_refs == 0) {
    2799                 :          0 :                         sa_base = inl_dev->inb_sa_base[profile_id];
    2800         [ #  # ]:          0 :                         if (sa_base == NULL)
    2801                 :            :                                 return 0;
    2802                 :          0 :                         inl_dev->ts_ena = ts_ena;
    2803                 :          0 :                         max_sa = inl_dev->inb_sa_max[profile_id];
    2804                 :          0 :                         inb_sa_sz = inl_dev->inb_sa_sz[profile_id];
    2805         [ #  # ]:          0 :                 } else if (inl_dev->ts_ena != ts_ena) {
    2806         [ #  # ]:          0 :                         if (inl_dev->ts_ena)
    2807                 :          0 :                                 plt_err("Inline device is already configured with TS enable");
    2808                 :            :                         else
    2809                 :          0 :                                 plt_err("Inline device is already configured with TS disable");
    2810                 :          0 :                         return -ENOTSUP;
    2811                 :            :                 } else {
    2812                 :            :                         return 0;
    2813                 :            :                 }
    2814                 :            :         }
    2815                 :            : 
    2816         [ #  # ]:          0 :         pkind = ts_ena ? ROC_IE_OT_CPT_TS_PKIND : ROC_IE_OT_CPT_PKIND;
    2817                 :            : 
    2818                 :            :         sa = (uint8_t *)sa_base;
    2819         [ #  # ]:          0 :         if (pkind == ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind)
    2820                 :            :                 return 0;
    2821                 :            : 
    2822         [ #  # ]:          0 :         for (i = 0; i < max_sa; i++) {
    2823                 :          0 :                 sa = ((uint8_t *)sa_base) + (i * inb_sa_sz);
    2824                 :          0 :                 ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind = pkind;
    2825                 :            :         }
    2826                 :            :         return 0;
    2827                 :            : }
    2828                 :            : 
    2829                 :            : int
    2830                 :          0 : roc_nix_inl_ts_pkind_set(struct roc_nix *roc_nix, bool ts_ena, bool inb_inl_dev, uint8_t profile_id)
    2831                 :            : {
    2832                 :            :         int cnt = 0;
    2833                 :            : 
    2834         [ #  # ]:          0 :         if (profile_id < ROC_NIX_INL_PROFILE_CNT) {
    2835                 :          0 :                 return nix_inl_ts_pkind_set(roc_nix, ts_ena, inb_inl_dev, profile_id);
    2836         [ #  # ]:          0 :         } else if (profile_id == 0xFF) {
    2837                 :            :                 /* Configure for all valid profiles */
    2838         [ #  # ]:          0 :                 for (cnt = 0; cnt < ROC_NIX_INL_PROFILE_CNT; cnt++)
    2839         [ #  # ]:          0 :                         if (nix_inl_ts_pkind_set(roc_nix, ts_ena, inb_inl_dev, cnt))
    2840                 :            :                                 return -EINVAL;
    2841                 :            :                 return 0;
    2842                 :            :         }
    2843                 :            : 
    2844                 :          0 :         plt_err("Invalid NIX inline profile_id: %u", profile_id);
    2845                 :          0 :         return -EINVAL;
    2846                 :            : }
    2847                 :            : 
    2848                 :            : void
    2849                 :          0 : roc_nix_inl_dev_lock(void)
    2850                 :            : {
    2851                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2852                 :            : 
    2853         [ #  # ]:          0 :         if (idev != NULL)
    2854                 :          0 :                 plt_spinlock_lock(&idev->nix_inl_dev_lock);
    2855                 :          0 : }
    2856                 :            : 
    2857                 :            : void
    2858                 :          0 : roc_nix_inl_dev_unlock(void)
    2859                 :            : {
    2860                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2861                 :            : 
    2862         [ #  # ]:          0 :         if (idev != NULL)
    2863                 :          0 :                 plt_spinlock_unlock(&idev->nix_inl_dev_lock);
    2864                 :          0 : }
    2865                 :            : 
    2866                 :            : void
    2867                 :          0 : roc_nix_inl_meta_pool_cb_register(roc_nix_inl_meta_pool_cb_t cb)
    2868                 :            : {
    2869                 :          0 :         meta_pool_cb = cb;
    2870                 :          0 : }
    2871                 :            : 
    2872                 :            : uint64_t
    2873                 :          0 : roc_nix_inl_eng_caps_get(struct roc_nix *roc_nix)
    2874                 :            : {
    2875                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    2876                 :            : 
    2877                 :          0 :         return nix->cpt_eng_caps;
    2878                 :            : }
    2879                 :            : 
    2880                 :            : void
    2881                 :          0 : roc_nix_inl_custom_meta_pool_cb_register(roc_nix_inl_custom_meta_pool_cb_t cb)
    2882                 :            : {
    2883                 :          0 :         custom_meta_pool_cb = cb;
    2884                 :          0 : }
    2885                 :            : 
    2886                 :            : uint8_t
    2887                 :          0 : roc_nix_inl_is_cq_ena(struct roc_nix *roc_nix)
    2888                 :            : {
    2889                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    2890                 :            :         struct nix_inl_dev *inl_dev;
    2891                 :            : 
    2892                 :            :         PLT_SET_USED(roc_nix);
    2893         [ #  # ]:          0 :         if (idev != NULL) {
    2894                 :          0 :                 inl_dev = idev->nix_inl_dev;
    2895         [ #  # ]:          0 :                 if (inl_dev)
    2896                 :          0 :                         return inl_dev->cpt_cq_ena;
    2897                 :            :                 else
    2898                 :            :                         return 0;
    2899                 :            :         } else {
    2900                 :            :                 return 0;
    2901                 :            :         }
    2902                 :            : }

Generated by: LCOV version 1.14