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

Generated by: LCOV version 1.14