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 848 0.0 %
Date: 2024-12-01 18:57:19 Functions: 0 51 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 599 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_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                 :            :         struct roc_nix_ipsec_cfg cfg;
     399                 :            :         uint64_t max_sa, i;
     400                 :            :         size_t inb_sa_sz;
     401                 :            :         void *sa;
     402                 :            :         int rc;
     403                 :            : 
     404         [ #  # ]:          0 :         max_sa = plt_align32pow2(ipsec_in_max_spi - ipsec_in_min_spi + 1);
     405                 :            : 
     406                 :            :         /* CN9K SA size is different */
     407         [ #  # ]:          0 :         if (roc_model_is_cn9k())
     408                 :            :                 inb_sa_sz = ROC_NIX_INL_ON_IPSEC_INB_SA_SZ;
     409         [ #  # ]:          0 :         else if (roc_nix->custom_inb_sa)
     410                 :            :                 inb_sa_sz = ROC_NIX_INL_INB_CUSTOM_SA_SZ;
     411                 :            :         else
     412                 :            :                 inb_sa_sz = ROC_NIX_INL_OT_IPSEC_INB_SA_SZ;
     413                 :            : 
     414                 :            :         /* Alloc contiguous memory for Inbound SA's */
     415                 :          0 :         nix->inb_sa_sz = inb_sa_sz;
     416                 :          0 :         nix->inb_spi_mask = max_sa - 1;
     417                 :          0 :         nix->inb_sa_base = plt_zmalloc(inb_sa_sz * max_sa,
     418                 :            :                                        ROC_NIX_INL_SA_BASE_ALIGN);
     419         [ #  # ]:          0 :         if (!nix->inb_sa_base) {
     420                 :          0 :                 plt_err("Failed to allocate memory for Inbound SA");
     421                 :          0 :                 return -ENOMEM;
     422                 :            :         }
     423         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
     424         [ #  # ]:          0 :                 for (i = 0; i < max_sa; i++) {
     425                 :          0 :                         sa = ((uint8_t *)nix->inb_sa_base) + (i * inb_sa_sz);
     426                 :          0 :                         roc_ot_ipsec_inb_sa_init(sa, true);
     427                 :            :                 }
     428                 :            :         }
     429                 :            : 
     430                 :            :         memset(&cfg, 0, sizeof(cfg));
     431                 :          0 :         cfg.sa_size = inb_sa_sz;
     432                 :          0 :         cfg.iova = (uintptr_t)nix->inb_sa_base;
     433                 :          0 :         cfg.max_sa = max_sa;
     434                 :            :         cfg.tt = SSO_TT_ORDERED;
     435                 :            : 
     436                 :            :         /* Setup device specific inb SA table */
     437                 :          0 :         rc = roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
     438         [ #  # ]:          0 :         if (rc) {
     439                 :          0 :                 plt_err("Failed to setup NIX Inbound SA conf, rc=%d", rc);
     440                 :          0 :                 goto free_mem;
     441                 :            :         }
     442                 :            : 
     443                 :            :         return 0;
     444                 :            : free_mem:
     445                 :          0 :         plt_free(nix->inb_sa_base);
     446                 :          0 :         nix->inb_sa_base = NULL;
     447                 :          0 :         return rc;
     448                 :            : }
     449                 :            : 
     450                 :            : static int
     451                 :          0 : nix_inl_sa_tbl_release(struct roc_nix *roc_nix)
     452                 :            : {
     453                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     454                 :            :         int rc;
     455                 :            : 
     456                 :          0 :         rc = roc_nix_lf_inl_ipsec_cfg(roc_nix, NULL, false);
     457         [ #  # ]:          0 :         if (rc) {
     458                 :          0 :                 plt_err("Failed to disable Inbound inline ipsec, rc=%d", rc);
     459                 :          0 :                 return rc;
     460                 :            :         }
     461                 :            : 
     462                 :          0 :         plt_free(nix->inb_sa_base);
     463                 :          0 :         nix->inb_sa_base = NULL;
     464                 :          0 :         return 0;
     465                 :            : }
     466                 :            : 
     467                 :            : struct roc_cpt_lf *
     468                 :          0 : roc_nix_inl_outb_lf_base_get(struct roc_nix *roc_nix)
     469                 :            : {
     470                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     471                 :            : 
     472                 :            :         /* NIX Inline config needs to be done */
     473   [ #  #  #  # ]:          0 :         if (!nix->inl_outb_ena || !nix->cpt_lf_base)
     474                 :          0 :                 return NULL;
     475                 :            : 
     476                 :            :         return (struct roc_cpt_lf *)nix->cpt_lf_base;
     477                 :            : }
     478                 :            : 
     479                 :            : struct roc_cpt_lf *
     480                 :          0 : roc_nix_inl_inb_inj_lf_get(struct roc_nix *roc_nix)
     481                 :            : {
     482                 :            :         struct nix *nix;
     483                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     484                 :            :         struct nix_inl_dev *inl_dev = NULL;
     485                 :            :         struct roc_cpt_lf *lf = NULL;
     486                 :            : 
     487         [ #  # ]:          0 :         if (!idev)
     488                 :            :                 return NULL;
     489                 :            : 
     490                 :          0 :         inl_dev = idev->nix_inl_dev;
     491                 :            : 
     492         [ #  # ]:          0 :         if (!inl_dev && roc_nix == NULL)
     493                 :            :                 return NULL;
     494                 :            : 
     495                 :            :         nix = roc_nix_to_nix_priv(roc_nix);
     496                 :            : 
     497   [ #  #  #  #  :          0 :         if (nix->inb_inl_dev && inl_dev && inl_dev->attach_cptlf &&
                   #  # ]
     498         [ #  # ]:          0 :             inl_dev->rx_inj_ena)
     499                 :          0 :                 return &inl_dev->cpt_lf[inl_dev->nb_cptlf - 1];
     500                 :            : 
     501                 :          0 :         lf = roc_nix_inl_outb_lf_base_get(roc_nix);
     502         [ #  # ]:          0 :         if (lf)
     503                 :          0 :                 lf += roc_nix->outb_nb_crypto_qs;
     504                 :            :         return lf;
     505                 :            : }
     506                 :            : 
     507                 :            : uintptr_t
     508                 :          0 : roc_nix_inl_outb_sa_base_get(struct roc_nix *roc_nix)
     509                 :            : {
     510                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     511                 :            : 
     512                 :          0 :         return (uintptr_t)nix->outb_sa_base;
     513                 :            : }
     514                 :            : 
     515                 :            : uintptr_t
     516                 :          0 : roc_nix_inl_inb_sa_base_get(struct roc_nix *roc_nix, bool inb_inl_dev)
     517                 :            : {
     518                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     519                 :            :         struct nix_inl_dev *inl_dev;
     520                 :            :         struct nix *nix = NULL;
     521                 :            : 
     522         [ #  # ]:          0 :         if (idev == NULL)
     523                 :            :                 return 0;
     524                 :            : 
     525         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
     526                 :            :                 return -EINVAL;
     527                 :            : 
     528         [ #  # ]:          0 :         if (roc_nix) {
     529                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     530         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
     531                 :            :                         return 0;
     532                 :            :         }
     533                 :            : 
     534         [ #  # ]:          0 :         if (inb_inl_dev) {
     535                 :          0 :                 inl_dev = idev->nix_inl_dev;
     536                 :            :                 /* Return inline dev sa base */
     537         [ #  # ]:          0 :                 if (inl_dev)
     538                 :          0 :                         return (uintptr_t)inl_dev->inb_sa_base;
     539                 :            :                 return 0;
     540                 :            :         }
     541                 :            : 
     542                 :          0 :         return (uintptr_t)nix->inb_sa_base;
     543                 :            : }
     544                 :            : 
     545                 :            : bool
     546                 :          0 : roc_nix_inl_inb_rx_inject_enable(struct roc_nix *roc_nix, bool inb_inl_dev)
     547                 :            : {
     548                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     549                 :            :         struct nix_inl_dev *inl_dev;
     550                 :            :         struct nix *nix = NULL;
     551                 :            : 
     552         [ #  # ]:          0 :         if (idev == NULL)
     553                 :            :                 return 0;
     554                 :            : 
     555         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
     556                 :            :                 return 0;
     557                 :            : 
     558         [ #  # ]:          0 :         if (roc_nix) {
     559                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     560         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
     561                 :            :                         return 0;
     562                 :            :         }
     563                 :            : 
     564         [ #  # ]:          0 :         if (inb_inl_dev) {
     565                 :          0 :                 inl_dev = idev->nix_inl_dev;
     566   [ #  #  #  #  :          0 :                 if (inl_dev && inl_dev->attach_cptlf && inl_dev->rx_inj_ena &&
                   #  # ]
     567         [ #  # ]:          0 :                     roc_nix->rx_inj_ena)
     568                 :            :                         return true;
     569                 :            :         }
     570                 :            : 
     571                 :          0 :         return roc_nix->rx_inj_ena;
     572                 :            : }
     573                 :            : 
     574                 :            : uint32_t
     575                 :          0 : roc_nix_inl_inb_spi_range(struct roc_nix *roc_nix, bool inb_inl_dev,
     576                 :            :                           uint32_t *min_spi, uint32_t *max_spi)
     577                 :            : {
     578                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     579                 :            :         uint32_t min = 0, max = 0, mask = 0;
     580                 :            :         struct nix_inl_dev *inl_dev;
     581                 :            :         struct nix *nix = NULL;
     582                 :            : 
     583         [ #  # ]:          0 :         if (idev == NULL)
     584                 :            :                 return 0;
     585                 :            : 
     586         [ #  # ]:          0 :         if (!inb_inl_dev && roc_nix == NULL)
     587                 :            :                 return -EINVAL;
     588                 :            : 
     589                 :          0 :         inl_dev = idev->nix_inl_dev;
     590         [ #  # ]:          0 :         if (inb_inl_dev) {
     591         [ #  # ]:          0 :                 if (inl_dev == NULL)
     592                 :          0 :                         goto exit;
     593                 :          0 :                 min = inl_dev->ipsec_in_min_spi;
     594                 :          0 :                 max = inl_dev->ipsec_in_max_spi;
     595                 :          0 :                 mask = inl_dev->inb_spi_mask;
     596                 :            :         } else {
     597                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     598         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
     599                 :          0 :                         goto exit;
     600                 :          0 :                 min = roc_nix->ipsec_in_min_spi;
     601                 :          0 :                 max = roc_nix->ipsec_in_max_spi;
     602                 :          0 :                 mask = nix->inb_spi_mask;
     603                 :            :         }
     604                 :          0 : exit:
     605         [ #  # ]:          0 :         if (min_spi)
     606                 :          0 :                 *min_spi = min;
     607         [ #  # ]:          0 :         if (max_spi)
     608                 :          0 :                 *max_spi = max;
     609                 :            :         return mask;
     610                 :            : }
     611                 :            : 
     612                 :            : uint32_t
     613                 :          0 : roc_nix_inl_inb_sa_sz(struct roc_nix *roc_nix, bool inl_dev_sa)
     614                 :            : {
     615                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     616                 :            :         struct nix_inl_dev *inl_dev;
     617                 :            :         struct nix *nix;
     618                 :            : 
     619         [ #  # ]:          0 :         if (idev == NULL)
     620                 :            :                 return 0;
     621                 :            : 
     622         [ #  # ]:          0 :         if (!inl_dev_sa && roc_nix == NULL)
     623                 :            :                 return -EINVAL;
     624                 :            : 
     625         [ #  # ]:          0 :         if (roc_nix) {
     626                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
     627         [ #  # ]:          0 :                 if (!inl_dev_sa)
     628                 :          0 :                         return nix->inb_sa_sz;
     629                 :            :         }
     630                 :            : 
     631         [ #  # ]:          0 :         if (inl_dev_sa) {
     632                 :          0 :                 inl_dev = idev->nix_inl_dev;
     633         [ #  # ]:          0 :                 if (inl_dev)
     634                 :          0 :                         return inl_dev->inb_sa_sz;
     635                 :            :         }
     636                 :            : 
     637                 :            :         return 0;
     638                 :            : }
     639                 :            : 
     640                 :            : uintptr_t
     641                 :          0 : roc_nix_inl_inb_sa_get(struct roc_nix *roc_nix, bool inb_inl_dev, uint32_t spi)
     642                 :            : {
     643                 :          0 :         uint32_t max_spi = 0, min_spi = 0, mask;
     644                 :            :         uintptr_t sa_base;
     645                 :            :         uint64_t sz;
     646                 :            : 
     647                 :          0 :         sa_base = roc_nix_inl_inb_sa_base_get(roc_nix, inb_inl_dev);
     648                 :            :         /* Check if SA base exists */
     649         [ #  # ]:          0 :         if (!sa_base)
     650                 :            :                 return 0;
     651                 :            : 
     652                 :            :         /* Get SA size */
     653                 :          0 :         sz = roc_nix_inl_inb_sa_sz(roc_nix, inb_inl_dev);
     654         [ #  # ]:          0 :         if (!sz)
     655                 :            :                 return 0;
     656                 :            : 
     657   [ #  #  #  # ]:          0 :         if (roc_nix && roc_nix->custom_sa_action)
     658                 :          0 :                 return (sa_base + (spi * sz));
     659                 :            : 
     660                 :            :         /* Check if SPI is in range */
     661                 :          0 :         mask = roc_nix_inl_inb_spi_range(roc_nix, inb_inl_dev, &min_spi,
     662                 :            :                                          &max_spi);
     663   [ #  #  #  # ]:          0 :         if (spi > max_spi || spi < min_spi)
     664                 :          0 :                 plt_nix_dbg("Inbound SA SPI %u not in range (%u..%u)", spi,
     665                 :            :                          min_spi, max_spi);
     666                 :            : 
     667                 :            :         /* Basic logic of SPI->SA for now */
     668                 :          0 :         return (sa_base + ((spi & mask) * sz));
     669                 :            : }
     670                 :            : 
     671                 :            : int
     672                 :          0 : roc_nix_reassembly_configure(uint32_t max_wait_time, uint16_t max_frags)
     673                 :            : {
     674                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     675                 :            :         struct roc_cpt *roc_cpt;
     676                 :            :         struct roc_cpt_rxc_time_cfg cfg;
     677                 :            : 
     678         [ #  # ]:          0 :         if (!idev)
     679                 :            :                 return -EFAULT;
     680                 :            : 
     681                 :            :         PLT_SET_USED(max_frags);
     682                 :            : 
     683                 :          0 :         roc_cpt = idev->cpt;
     684         [ #  # ]:          0 :         if (!roc_cpt) {
     685                 :          0 :                 plt_err("Cannot support inline inbound, cryptodev not probed");
     686                 :          0 :                 return -ENOTSUP;
     687                 :            :         }
     688                 :            : 
     689                 :          0 :         cfg.step = (max_wait_time * 1000 / ROC_NIX_INL_REAS_ACTIVE_LIMIT);
     690                 :          0 :         cfg.zombie_limit = ROC_NIX_INL_REAS_ZOMBIE_LIMIT;
     691                 :          0 :         cfg.zombie_thres = ROC_NIX_INL_REAS_ZOMBIE_THRESHOLD;
     692                 :          0 :         cfg.active_limit = ROC_NIX_INL_REAS_ACTIVE_LIMIT;
     693                 :          0 :         cfg.active_thres = ROC_NIX_INL_REAS_ACTIVE_THRESHOLD;
     694                 :            : 
     695                 :          0 :         return roc_cpt_rxc_time_cfg(roc_cpt, &cfg);
     696                 :            : }
     697                 :            : 
     698                 :            : static int
     699                 :          0 : nix_inl_rq_mask_cfg(struct roc_nix *roc_nix, bool enable)
     700                 :            : {
     701                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     702                 :            :         struct nix_rq_cpt_field_mask_cfg_req *msk_req;
     703                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     704                 :          0 :         struct mbox *mbox = mbox_get((&nix->dev)->mbox);
     705                 :            :         struct idev_nix_inl_cfg *inl_cfg;
     706                 :            :         uint64_t aura_handle;
     707                 :            :         int rc = -ENOSPC;
     708                 :            :         uint32_t buf_sz;
     709                 :            :         int i;
     710                 :            : 
     711         [ #  # ]:          0 :         if (!idev)
     712                 :          0 :                 goto exit;
     713                 :            : 
     714                 :            :         inl_cfg = &idev->inl_cfg;
     715                 :          0 :         msk_req = mbox_alloc_msg_nix_lf_inline_rq_cfg(mbox);
     716         [ #  # ]:          0 :         if (msk_req == NULL)
     717                 :          0 :                 goto exit;
     718                 :            : 
     719         [ #  # ]:          0 :         for (i = 0; i < RQ_CTX_MASK_MAX; i++)
     720                 :          0 :                 msk_req->rq_ctx_word_mask[i] = 0xFFFFFFFFFFFFFFFF;
     721                 :            : 
     722                 :          0 :         msk_req->rq_set.len_ol3_dis = 1;
     723                 :          0 :         msk_req->rq_set.len_ol4_dis = 1;
     724                 :          0 :         msk_req->rq_set.len_il3_dis = 1;
     725                 :            : 
     726                 :          0 :         msk_req->rq_set.len_il4_dis = 1;
     727                 :          0 :         msk_req->rq_set.csum_ol4_dis = 1;
     728                 :          0 :         msk_req->rq_set.csum_il4_dis = 1;
     729                 :            : 
     730                 :          0 :         msk_req->rq_set.lenerr_dis = 1;
     731                 :          0 :         msk_req->rq_set.port_ol4_dis = 1;
     732                 :          0 :         msk_req->rq_set.port_il4_dis = 1;
     733                 :            : 
     734                 :          0 :         msk_req->rq_set.lpb_drop_ena = 0;
     735                 :          0 :         msk_req->rq_set.spb_drop_ena = 0;
     736                 :          0 :         msk_req->rq_set.xqe_drop_ena = 0;
     737                 :          0 :         msk_req->rq_set.spb_ena = 1;
     738                 :            : 
     739                 :            :         if (!roc_feature_nix_has_second_pass_drop()) {
     740                 :          0 :                 msk_req->rq_set.ena = 1;
     741                 :          0 :                 msk_req->rq_set.rq_int_ena = 1;
     742                 :          0 :                 msk_req->rq_mask.ena = 0;
     743                 :          0 :                 msk_req->rq_mask.rq_int_ena = 0;
     744                 :            :         }
     745                 :            : 
     746                 :          0 :         msk_req->rq_mask.len_ol3_dis = 0;
     747                 :          0 :         msk_req->rq_mask.len_ol4_dis = 0;
     748                 :          0 :         msk_req->rq_mask.len_il3_dis = 0;
     749                 :            : 
     750                 :          0 :         msk_req->rq_mask.len_il4_dis = 0;
     751                 :          0 :         msk_req->rq_mask.csum_ol4_dis = 0;
     752                 :          0 :         msk_req->rq_mask.csum_il4_dis = 0;
     753                 :            : 
     754                 :          0 :         msk_req->rq_mask.lenerr_dis = 0;
     755                 :          0 :         msk_req->rq_mask.port_ol4_dis = 0;
     756                 :          0 :         msk_req->rq_mask.port_il4_dis = 0;
     757                 :            : 
     758                 :          0 :         msk_req->rq_mask.lpb_drop_ena = 0;
     759                 :          0 :         msk_req->rq_mask.spb_drop_ena = 0;
     760                 :          0 :         msk_req->rq_mask.xqe_drop_ena = 0;
     761                 :          0 :         msk_req->rq_mask.spb_ena = 0;
     762                 :            : 
     763         [ #  # ]:          0 :         if (roc_nix->local_meta_aura_ena) {
     764                 :          0 :                 aura_handle = roc_nix->meta_aura_handle;
     765                 :          0 :                 buf_sz = roc_nix->buf_sz;
     766         [ #  # ]:          0 :                 if (!aura_handle && enable) {
     767                 :          0 :                         plt_err("NULL meta aura handle");
     768                 :          0 :                         goto exit;
     769                 :            :                 }
     770                 :            :         } else {
     771                 :          0 :                 aura_handle = roc_npa_zero_aura_handle();
     772                 :          0 :                 buf_sz = inl_cfg->buf_sz;
     773                 :            :         }
     774                 :            : 
     775                 :          0 :         msk_req->ipsec_cfg1.spb_cpt_aura = roc_npa_aura_handle_to_aura(aura_handle);
     776                 :          0 :         msk_req->ipsec_cfg1.rq_mask_enable = enable;
     777                 :          0 :         msk_req->ipsec_cfg1.spb_cpt_sizem1 = (buf_sz >> 7) - 1;
     778                 :          0 :         msk_req->ipsec_cfg1.spb_cpt_enable = enable;
     779                 :            : 
     780                 :          0 :         rc = mbox_process(mbox);
     781                 :          0 : exit:
     782                 :            :         mbox_put(mbox);
     783                 :          0 :         return rc;
     784                 :            : }
     785                 :            : 
     786                 :            : static void
     787                 :          0 : nix_inl_eng_caps_get(struct nix *nix)
     788                 :            : {
     789                 :          0 :         struct roc_cpt_lf *lf = nix->cpt_lf_base;
     790                 :          0 :         uintptr_t lmt_base = lf->lmt_base;
     791                 :            :         union cpt_res_s res, *hw_res;
     792                 :            :         struct cpt_inst_s inst;
     793                 :            :         uint64_t *rptr;
     794                 :            : 
     795                 :          0 :         hw_res = plt_zmalloc(sizeof(*hw_res), ROC_CPT_RES_ALIGN);
     796         [ #  # ]:          0 :         if (hw_res == NULL) {
     797                 :          0 :                 plt_err("Couldn't allocate memory for result address");
     798                 :          0 :                 return;
     799                 :            :         }
     800                 :            : 
     801                 :          0 :         rptr = plt_zmalloc(ROC_ALIGN, 0);
     802         [ #  # ]:          0 :         if (rptr == NULL) {
     803                 :          0 :                 plt_err("Couldn't allocate memory for rptr");
     804                 :          0 :                 plt_free(hw_res);
     805                 :          0 :                 return;
     806                 :            :         }
     807                 :            : 
     808                 :            :         /* Fill CPT_INST_S for LOAD_FVC/HW_CRYPTO_SUPPORT microcode op */
     809                 :            :         memset(&inst, 0, sizeof(struct cpt_inst_s));
     810                 :          0 :         inst.res_addr = (uint64_t)hw_res;
     811                 :          0 :         inst.rptr = (uint64_t)rptr;
     812                 :          0 :         inst.w4.s.opcode_major = ROC_LOADFVC_MAJOR_OP;
     813                 :          0 :         inst.w4.s.opcode_minor = ROC_LOADFVC_MINOR_OP;
     814                 :            :         inst.w7.s.egrp = ROC_CPT_DFLT_ENG_GRP_SE;
     815                 :            : 
     816                 :            :         /* Use 1 min timeout for the poll */
     817         [ #  # ]:          0 :         const uint64_t timeout = plt_tsc_cycles() + 60 * plt_tsc_hz();
     818                 :            : 
     819         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     820                 :            :                 uint64_t lmt_status;
     821                 :            : 
     822                 :          0 :                 hw_res->cn9k.compcode = CPT_COMP_NOT_DONE;
     823                 :          0 :                 plt_io_wmb();
     824                 :            : 
     825                 :            :                 do {
     826                 :            :                         roc_lmt_mov_seg((void *)lmt_base, &inst, 4);
     827                 :            :                         lmt_status = roc_lmt_submit_ldeor(lf->io_addr);
     828                 :            :                 } while (lmt_status != 0);
     829                 :            : 
     830                 :            :                 /* Wait until CPT instruction completes */
     831                 :            :                 do {
     832                 :          0 :                         res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
     833         [ #  # ]:          0 :                         if (unlikely(plt_tsc_cycles() > timeout))
     834                 :            :                                 break;
     835         [ #  # ]:          0 :                 } while (res.cn9k.compcode == CPT_COMP_NOT_DONE);
     836                 :            : 
     837         [ #  # ]:          0 :                 if (res.cn9k.compcode != CPT_COMP_GOOD) {
     838                 :          0 :                         plt_err("LOAD FVC operation timed out");
     839                 :          0 :                         return;
     840                 :            :                 }
     841                 :            :         } else {
     842                 :            :                 uint64_t lmt_arg, io_addr;
     843                 :            :                 uint16_t lmt_id;
     844                 :            : 
     845                 :          0 :                 hw_res->cn10k.compcode = CPT_COMP_NOT_DONE;
     846                 :            : 
     847                 :            :                 /* Use this reserved LMT line as no one else is using it */
     848                 :          0 :                 lmt_id = roc_plt_control_lmt_id_get();
     849                 :          0 :                 lmt_base += ((uint64_t)lmt_id << ROC_LMT_LINE_SIZE_LOG2);
     850                 :            : 
     851                 :          0 :                 memcpy((void *)lmt_base, &inst, sizeof(inst));
     852                 :            : 
     853                 :            :                 lmt_arg = ROC_CN10K_CPT_LMT_ARG | (uint64_t)lmt_id;
     854                 :            :                 io_addr = lf->io_addr | ROC_CN10K_CPT_INST_DW_M1 << 4;
     855                 :            : 
     856                 :            :                 roc_lmt_submit_steorl(lmt_arg, io_addr);
     857                 :          0 :                 plt_io_wmb();
     858                 :            : 
     859                 :            :                 /* Wait until CPT instruction completes */
     860                 :            :                 do {
     861                 :          0 :                         res.u64[0] = __atomic_load_n(&hw_res->u64[0], __ATOMIC_RELAXED);
     862         [ #  # ]:          0 :                         if (unlikely(plt_tsc_cycles() > timeout))
     863                 :            :                                 break;
     864         [ #  # ]:          0 :                 } while (res.cn10k.compcode == CPT_COMP_NOT_DONE);
     865                 :            : 
     866         [ #  # ]:          0 :                 if (res.cn10k.compcode != CPT_COMP_GOOD || res.cn10k.uc_compcode) {
     867                 :          0 :                         plt_err("LOAD FVC operation timed out");
     868                 :          0 :                         goto exit;
     869                 :            :                 }
     870                 :            :         }
     871                 :            : 
     872         [ #  # ]:          0 :         nix->cpt_eng_caps = plt_be_to_cpu_64(*rptr);
     873                 :          0 : exit:
     874                 :          0 :         plt_free(rptr);
     875                 :          0 :         plt_free(hw_res);
     876                 :            : }
     877                 :            : 
     878                 :            : int
     879                 :          0 : roc_nix_inl_inb_init(struct roc_nix *roc_nix)
     880                 :            : {
     881                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     882                 :            :         struct roc_cpt_inline_ipsec_inb_cfg cfg;
     883                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     884                 :            :         uint16_t bpids[ROC_NIX_MAX_BPID_CNT];
     885                 :            :         struct roc_cpt *roc_cpt;
     886                 :            :         int rc;
     887                 :            : 
     888         [ #  # ]:          0 :         if (idev == NULL)
     889                 :            :                 return -ENOTSUP;
     890                 :            : 
     891                 :            :         /* Unless we have another mechanism to trigger
     892                 :            :          * onetime Inline config in CPTPF, we cannot
     893                 :            :          * support without CPT being probed.
     894                 :            :          */
     895                 :          0 :         roc_cpt = idev->cpt;
     896         [ #  # ]:          0 :         if (!roc_cpt) {
     897                 :          0 :                 plt_err("Cannot support inline inbound, cryptodev not probed");
     898                 :          0 :                 return -ENOTSUP;
     899                 :            :         }
     900                 :            : 
     901         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
     902                 :          0 :                 cfg.param1 = (ROC_ONF_IPSEC_INB_MAX_L2_SZ >> 3) & 0xf;
     903                 :          0 :                 cfg.param2 = ROC_IE_ON_INB_IKEV2_SINGLE_SA_SUPPORT;
     904                 :          0 :                 cfg.opcode =
     905                 :            :                         ((ROC_IE_ON_INB_MAX_CTX_LEN << 8) |
     906                 :            :                          (ROC_IE_ON_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6)));
     907                 :            :         } else {
     908                 :            :                 union roc_ot_ipsec_inb_param1 u;
     909                 :            : 
     910                 :            :                 u.u16 = 0;
     911                 :            :                 u.s.esp_trailer_disable = 1;
     912                 :          0 :                 cfg.param1 = u.u16;
     913                 :          0 :                 cfg.param2 = 0;
     914                 :          0 :                 cfg.opcode = (ROC_IE_OT_MAJOR_OP_PROCESS_INBOUND_IPSEC | (1 << 6));
     915                 :            : 
     916         [ #  # ]:          0 :                 if (roc_nix->custom_inb_sa) {
     917                 :          0 :                         cfg.param1 = roc_nix->inb_cfg_param1;
     918                 :          0 :                         cfg.param2 = roc_nix->inb_cfg_param2;
     919                 :            :                 }
     920                 :          0 :                 rc = roc_nix_bpids_alloc(roc_nix, ROC_NIX_INTF_TYPE_CPT_NIX, 1, bpids);
     921         [ #  # ]:          0 :                 if (rc > 0) {
     922                 :          0 :                         nix->cpt_nixbpid = bpids[0];
     923                 :          0 :                         cfg.bpid = nix->cpt_nixbpid;
     924                 :            :                 }
     925                 :            : 
     926         [ #  # ]:          0 :                 if (roc_errata_cpt_has_ctx_fetch_issue()) {
     927                 :          0 :                         cfg.ctx_ilen_valid = true;
     928                 :          0 :                         cfg.ctx_ilen = (ROC_NIX_INL_OT_IPSEC_INB_HW_SZ / 128) - 1;
     929                 :            :                 }
     930                 :            :         }
     931                 :            : 
     932                 :            :         /* Do onetime Inbound Inline config in CPTPF */
     933                 :          0 :         rc = roc_cpt_inline_ipsec_inb_cfg(roc_cpt, &cfg);
     934         [ #  # ]:          0 :         if (rc && rc != -EEXIST) {
     935                 :          0 :                 plt_err("Failed to setup inbound lf, rc=%d", rc);
     936                 :          0 :                 return rc;
     937                 :            :         }
     938                 :          0 :         nix->cpt_eng_caps = roc_cpt->hw_caps[CPT_ENG_TYPE_SE].u;
     939                 :            : 
     940                 :            :         /* Setup Inbound SA table */
     941                 :          0 :         rc = nix_inl_inb_sa_tbl_setup(roc_nix);
     942         [ #  # ]:          0 :         if (rc)
     943                 :            :                 return rc;
     944                 :            : 
     945   [ #  #  #  # ]:          0 :         if (!roc_model_is_cn9k() && !roc_errata_nix_no_meta_aura()) {
     946                 :          0 :                 nix->need_meta_aura = true;
     947   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
     948                 :          0 :                         idev->inl_cfg.refs++;
     949                 :            :         }
     950                 :            : 
     951                 :          0 :         nix->inl_inb_ena = true;
     952                 :          0 :         return 0;
     953                 :            : }
     954                 :            : 
     955                 :            : int
     956                 :          0 : roc_nix_inl_inb_fini(struct roc_nix *roc_nix)
     957                 :            : {
     958                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
     959                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
     960                 :            :         int rc;
     961                 :            : 
     962         [ #  # ]:          0 :         if (!nix->inl_inb_ena)
     963                 :            :                 return 0;
     964                 :            : 
     965         [ #  # ]:          0 :         if (!idev)
     966                 :            :                 return -EFAULT;
     967                 :            : 
     968                 :          0 :         nix->inl_inb_ena = false;
     969                 :            : 
     970         [ #  # ]:          0 :         if (nix->need_meta_aura) {
     971                 :          0 :                 nix->need_meta_aura = false;
     972   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
     973                 :          0 :                         idev->inl_cfg.refs--;
     974                 :            : 
     975         [ #  # ]:          0 :                 if (roc_nix->custom_meta_aura_ena)
     976                 :          0 :                         nix_inl_custom_meta_aura_destroy(roc_nix);
     977                 :            : 
     978         [ #  # ]:          0 :                 if (!idev->inl_cfg.refs)
     979                 :          0 :                         nix_inl_meta_aura_destroy(roc_nix);
     980                 :            :         }
     981                 :            : 
     982         [ #  # ]:          0 :         if (roc_feature_nix_has_inl_rq_mask()) {
     983                 :          0 :                 rc = nix_inl_rq_mask_cfg(roc_nix, false);
     984         [ #  # ]:          0 :                 if (rc) {
     985                 :          0 :                         plt_err("Failed to get rq mask rc=%d", rc);
     986                 :          0 :                         return rc;
     987                 :            :                 }
     988                 :            :         }
     989                 :            : 
     990                 :            :         /* Flush Inbound CTX cache entries */
     991                 :          0 :         roc_nix_cpt_ctx_cache_sync(roc_nix);
     992                 :            : 
     993                 :            :         /* Disable Inbound SA */
     994                 :          0 :         return nix_inl_sa_tbl_release(roc_nix);
     995                 :            : }
     996                 :            : 
     997                 :            : int
     998                 :          0 : roc_nix_inl_outb_init(struct roc_nix *roc_nix)
     999                 :            : {
    1000                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1001                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1002                 :            :         struct roc_cpt_lf *lf_base, *lf;
    1003                 :          0 :         struct dev *dev = &nix->dev;
    1004                 :            :         struct msix_offset_rsp *rsp;
    1005                 :            :         struct nix_inl_dev *inl_dev;
    1006                 :            :         bool ctx_ilen_valid = false;
    1007                 :            :         size_t sa_sz, ring_sz;
    1008                 :            :         uint8_t ctx_ilen = 0;
    1009                 :            :         bool rx_inj = false;
    1010                 :            :         uint16_t sso_pffunc;
    1011                 :            :         uint8_t eng_grpmask;
    1012                 :            :         uint64_t blkaddr, i;
    1013                 :            :         uint64_t *ring_base;
    1014                 :            :         uint16_t nb_lf;
    1015                 :            :         void *sa_base;
    1016                 :            :         int j, rc;
    1017                 :            :         void *sa;
    1018                 :            : 
    1019         [ #  # ]:          0 :         if (idev == NULL)
    1020                 :            :                 return -ENOTSUP;
    1021                 :            : 
    1022                 :          0 :         nb_lf = roc_nix->outb_nb_crypto_qs;
    1023         [ #  # ]:          0 :         blkaddr = nix->is_nix1 ? RVU_BLOCK_ADDR_CPT1 : RVU_BLOCK_ADDR_CPT0;
    1024                 :            : 
    1025                 :            :         /* Retrieve inline device if present */
    1026                 :          0 :         inl_dev = idev->nix_inl_dev;
    1027   [ #  #  #  #  :          0 :         if (roc_nix->rx_inj_ena && !(nix->inb_inl_dev && inl_dev && inl_dev->attach_cptlf &&
             #  #  #  # ]
    1028         [ #  # ]:          0 :                                      inl_dev->rx_inj_ena)) {
    1029                 :          0 :                 nb_lf++;
    1030                 :            :                 rx_inj = true;
    1031                 :            :         }
    1032                 :            : 
    1033         [ #  # ]:          0 :         sso_pffunc = inl_dev ? inl_dev->dev.pf_func : idev_sso_pffunc_get();
    1034                 :            :         /* Use sso_pffunc if explicitly requested */
    1035         [ #  # ]:          0 :         if (roc_nix->ipsec_out_sso_pffunc)
    1036                 :          0 :                 sso_pffunc = idev_sso_pffunc_get();
    1037                 :            : 
    1038         [ #  # ]:          0 :         if (!sso_pffunc) {
    1039                 :          0 :                 plt_err("Failed to setup inline outb, need either "
    1040                 :            :                         "inline device or sso device");
    1041                 :          0 :                 return -ENOTSUP;
    1042                 :            :         }
    1043                 :            : 
    1044                 :            :         /* Attach CPT LF for outbound */
    1045                 :          0 :         rc = cpt_lfs_attach(dev, blkaddr, true, nb_lf);
    1046         [ #  # ]:          0 :         if (rc) {
    1047                 :          0 :                 plt_err("Failed to attach CPT LF for inline outb, rc=%d", rc);
    1048                 :          0 :                 return rc;
    1049                 :            :         }
    1050                 :            : 
    1051   [ #  #  #  # ]:          0 :         if (!roc_model_is_cn9k() && roc_errata_cpt_has_ctx_fetch_issue()) {
    1052                 :            :                 ctx_ilen = (ROC_NIX_INL_OT_IPSEC_OUTB_HW_SZ / 128) - 1;
    1053                 :            :                 ctx_ilen_valid = true;
    1054                 :            :         }
    1055                 :            : 
    1056                 :            :         /* Alloc CPT LF */
    1057                 :            :         eng_grpmask = (1ULL << ROC_CPT_DFLT_ENG_GRP_SE |
    1058                 :            :                        1ULL << ROC_CPT_DFLT_ENG_GRP_SE_IE |
    1059                 :            :                        1ULL << ROC_CPT_DFLT_ENG_GRP_AE);
    1060                 :          0 :         rc = cpt_lfs_alloc(dev, eng_grpmask, blkaddr,
    1061                 :          0 :                            !roc_nix->ipsec_out_sso_pffunc, ctx_ilen_valid, ctx_ilen,
    1062                 :          0 :                            rx_inj, nb_lf - 1);
    1063         [ #  # ]:          0 :         if (rc) {
    1064                 :          0 :                 plt_err("Failed to alloc CPT LF resources, rc=%d", rc);
    1065                 :          0 :                 goto lf_detach;
    1066                 :            :         }
    1067                 :            : 
    1068                 :            :         /* Get msix offsets */
    1069                 :          0 :         rc = cpt_get_msix_offset(dev, &rsp);
    1070         [ #  # ]:          0 :         if (rc) {
    1071                 :          0 :                 plt_err("Failed to get CPT LF msix offset, rc=%d", rc);
    1072                 :          0 :                 goto lf_free;
    1073                 :            :         }
    1074                 :            : 
    1075                 :          0 :         mbox_memcpy(nix->cpt_msixoff,
    1076         [ #  # ]:          0 :                     nix->is_nix1 ? rsp->cpt1_lf_msixoff : rsp->cptlf_msixoff,
    1077                 :            :                     sizeof(nix->cpt_msixoff));
    1078                 :            : 
    1079                 :            :         /* Alloc required num of cpt lfs */
    1080                 :          0 :         lf_base = plt_zmalloc(nb_lf * sizeof(struct roc_cpt_lf), 0);
    1081         [ #  # ]:          0 :         if (!lf_base) {
    1082                 :          0 :                 plt_err("Failed to alloc cpt lf memory");
    1083                 :            :                 rc = -ENOMEM;
    1084                 :          0 :                 goto lf_free;
    1085                 :            :         }
    1086                 :            : 
    1087                 :            :         /* Initialize CPT LF's */
    1088         [ #  # ]:          0 :         for (i = 0; i < nb_lf; i++) {
    1089                 :          0 :                 lf = &lf_base[i];
    1090                 :            : 
    1091                 :          0 :                 lf->lf_id = i;
    1092                 :          0 :                 lf->nb_desc = roc_nix->outb_nb_desc;
    1093                 :          0 :                 lf->dev = &nix->dev;
    1094                 :          0 :                 lf->msixoff = nix->cpt_msixoff[i];
    1095                 :          0 :                 lf->pci_dev = nix->pci_dev;
    1096                 :            : 
    1097                 :            :                 /* Setup CPT LF instruction queue */
    1098                 :          0 :                 rc = cpt_lf_init(lf);
    1099         [ #  # ]:          0 :                 if (rc) {
    1100                 :          0 :                         plt_err("Failed to initialize CPT LF, rc=%d", rc);
    1101                 :          0 :                         goto lf_fini;
    1102                 :            :                 }
    1103                 :            : 
    1104                 :            :                 /* Associate this CPT LF with NIX PFFUNC */
    1105                 :          0 :                 rc = cpt_lf_outb_cfg(dev, sso_pffunc, nix->dev.pf_func, i,
    1106                 :            :                                      true);
    1107         [ #  # ]:          0 :                 if (rc) {
    1108                 :          0 :                         plt_err("Failed to setup CPT LF->(NIX,SSO) link, rc=%d",
    1109                 :            :                                 rc);
    1110                 :          0 :                         goto lf_fini;
    1111                 :            :                 }
    1112                 :            : 
    1113                 :            :                 /* Enable IQ */
    1114                 :          0 :                 roc_cpt_iq_enable(lf);
    1115                 :            :         }
    1116                 :            : 
    1117         [ #  # ]:          0 :         if (!roc_nix->ipsec_out_max_sa)
    1118                 :          0 :                 goto skip_sa_alloc;
    1119                 :            : 
    1120                 :            :         /* CN9K SA size is different */
    1121                 :            :         if (roc_model_is_cn9k())
    1122                 :            :                 sa_sz = ROC_NIX_INL_ON_IPSEC_OUTB_SA_SZ;
    1123                 :            :         else
    1124                 :            :                 sa_sz = ROC_NIX_INL_OT_IPSEC_OUTB_SA_SZ;
    1125                 :            :         /* Alloc contiguous memory of outbound SA */
    1126                 :          0 :         sa_base = plt_zmalloc(sa_sz * roc_nix->ipsec_out_max_sa,
    1127                 :            :                               ROC_NIX_INL_SA_BASE_ALIGN);
    1128         [ #  # ]:          0 :         if (!sa_base) {
    1129                 :          0 :                 plt_err("Outbound SA base alloc failed");
    1130                 :          0 :                 goto lf_fini;
    1131                 :            :         }
    1132         [ #  # ]:          0 :         if (roc_model_is_cn10k()) {
    1133         [ #  # ]:          0 :                 for (i = 0; i < roc_nix->ipsec_out_max_sa; i++) {
    1134                 :          0 :                         sa = ((uint8_t *)sa_base) + (i * sa_sz);
    1135                 :          0 :                         roc_ot_ipsec_outb_sa_init(sa);
    1136                 :            :                 }
    1137                 :            :         }
    1138                 :          0 :         nix->outb_sa_base = sa_base;
    1139                 :          0 :         nix->outb_sa_sz = sa_sz;
    1140                 :            : 
    1141                 :          0 : skip_sa_alloc:
    1142                 :            : 
    1143                 :          0 :         nix->cpt_lf_base = lf_base;
    1144                 :          0 :         nix->nb_cpt_lf = nb_lf;
    1145                 :          0 :         nix->outb_err_sso_pffunc = sso_pffunc;
    1146                 :          0 :         nix->inl_outb_ena = true;
    1147                 :          0 :         nix->outb_se_ring_cnt =
    1148                 :          0 :                 roc_nix->ipsec_out_max_sa / ROC_IPSEC_ERR_RING_MAX_ENTRY + 1;
    1149                 :          0 :         nix->outb_se_ring_base =
    1150                 :          0 :                 roc_nix->port_id * ROC_NIX_SOFT_EXP_PER_PORT_MAX_RINGS;
    1151                 :            : 
    1152   [ #  #  #  # ]:          0 :         if (inl_dev == NULL || !inl_dev->set_soft_exp_poll) {
    1153                 :          0 :                 nix->outb_se_ring_cnt = 0;
    1154                 :          0 :                 return 0;
    1155                 :            :         }
    1156                 :            : 
    1157                 :            :         /* Allocate memory to be used as a ring buffer to poll for
    1158                 :            :          * soft expiry event from ucode
    1159                 :            :          */
    1160                 :            :         ring_sz = (ROC_IPSEC_ERR_RING_MAX_ENTRY + 1) * sizeof(uint64_t);
    1161                 :          0 :         ring_base = inl_dev->sa_soft_exp_ring;
    1162         [ #  # ]:          0 :         for (i = 0; i < nix->outb_se_ring_cnt; i++) {
    1163                 :          0 :                 ring_base[nix->outb_se_ring_base + i] =
    1164                 :          0 :                         PLT_U64_CAST(plt_zmalloc(ring_sz, 0));
    1165         [ #  # ]:          0 :                 if (!ring_base[nix->outb_se_ring_base + i]) {
    1166                 :          0 :                         plt_err("Couldn't allocate memory for soft exp ring");
    1167         [ #  # ]:          0 :                         while (i--)
    1168                 :          0 :                                 plt_free(PLT_PTR_CAST(
    1169                 :            :                                         ring_base[nix->outb_se_ring_base + i]));
    1170                 :            :                         rc = -ENOMEM;
    1171                 :          0 :                         goto lf_fini;
    1172                 :            :                 }
    1173                 :            :         }
    1174                 :            : 
    1175                 :            :         /* Fetch engine capabilities */
    1176                 :          0 :         nix_inl_eng_caps_get(nix);
    1177                 :          0 :         return 0;
    1178                 :            : 
    1179                 :          0 : lf_fini:
    1180         [ #  # ]:          0 :         for (j = i - 1; j >= 0; j--)
    1181                 :          0 :                 cpt_lf_fini(&lf_base[j]);
    1182                 :          0 :         plt_free(lf_base);
    1183                 :          0 : lf_free:
    1184                 :          0 :         rc |= cpt_lfs_free(dev);
    1185                 :          0 : lf_detach:
    1186                 :          0 :         rc |= cpt_lfs_detach(dev);
    1187                 :          0 :         return rc;
    1188                 :            : }
    1189                 :            : 
    1190                 :            : int
    1191                 :          0 : roc_nix_inl_outb_fini(struct roc_nix *roc_nix)
    1192                 :            : {
    1193                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1194                 :          0 :         struct roc_cpt_lf *lf_base = nix->cpt_lf_base;
    1195                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1196                 :          0 :         struct dev *dev = &nix->dev;
    1197                 :            :         struct nix_inl_dev *inl_dev;
    1198                 :            :         uint64_t *ring_base;
    1199                 :            :         int i, rc, ret = 0;
    1200                 :            : 
    1201         [ #  # ]:          0 :         if (!nix->inl_outb_ena)
    1202                 :            :                 return 0;
    1203                 :            : 
    1204                 :          0 :         nix->inl_outb_ena = false;
    1205                 :            : 
    1206                 :            :         /* Cleanup CPT LF instruction queue */
    1207         [ #  # ]:          0 :         for (i = 0; i < nix->nb_cpt_lf; i++)
    1208                 :          0 :                 cpt_lf_fini(&lf_base[i]);
    1209                 :            : 
    1210                 :            :         /* Free LF resources */
    1211                 :          0 :         rc = cpt_lfs_free(dev);
    1212         [ #  # ]:          0 :         if (rc)
    1213                 :          0 :                 plt_err("Failed to free CPT LF resources, rc=%d", rc);
    1214                 :            :         ret |= rc;
    1215                 :            : 
    1216                 :            :         /* Detach LF */
    1217                 :          0 :         rc = cpt_lfs_detach(dev);
    1218         [ #  # ]:          0 :         if (rc)
    1219                 :          0 :                 plt_err("Failed to detach CPT LF, rc=%d", rc);
    1220                 :            : 
    1221                 :            :         /* Free LF memory */
    1222                 :          0 :         plt_free(lf_base);
    1223                 :          0 :         nix->cpt_lf_base = NULL;
    1224                 :          0 :         nix->nb_cpt_lf = 0;
    1225                 :            : 
    1226                 :            :         /* Free outbound SA base */
    1227                 :          0 :         plt_free(nix->outb_sa_base);
    1228                 :          0 :         nix->outb_sa_base = NULL;
    1229                 :            : 
    1230   [ #  #  #  #  :          0 :         if (idev && idev->nix_inl_dev && nix->outb_se_ring_cnt) {
                   #  # ]
    1231                 :            :                 inl_dev = idev->nix_inl_dev;
    1232                 :          0 :                 ring_base = inl_dev->sa_soft_exp_ring;
    1233                 :          0 :                 ring_base += nix->outb_se_ring_base;
    1234                 :            : 
    1235         [ #  # ]:          0 :                 for (i = 0; i < nix->outb_se_ring_cnt; i++) {
    1236         [ #  # ]:          0 :                         if (ring_base[i])
    1237                 :          0 :                                 plt_free(PLT_PTR_CAST(ring_base[i]));
    1238                 :            :                 }
    1239                 :            :         }
    1240                 :            : 
    1241                 :          0 :         ret |= rc;
    1242                 :          0 :         return ret;
    1243                 :            : }
    1244                 :            : 
    1245                 :            : bool
    1246                 :          0 : roc_nix_inl_dev_is_probed(void)
    1247                 :            : {
    1248                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1249                 :            : 
    1250         [ #  # ]:          0 :         if (idev == NULL)
    1251                 :            :                 return 0;
    1252                 :            : 
    1253                 :          0 :         return !!idev->nix_inl_dev;
    1254                 :            : }
    1255                 :            : 
    1256                 :            : bool
    1257                 :          0 : roc_nix_inl_dev_is_multi_channel(void)
    1258                 :            : {
    1259                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1260                 :            :         struct nix_inl_dev *inl_dev;
    1261                 :            : 
    1262   [ #  #  #  # ]:          0 :         if (idev == NULL || !idev->nix_inl_dev)
    1263                 :            :                 return false;
    1264                 :            : 
    1265                 :            :         inl_dev = idev->nix_inl_dev;
    1266                 :          0 :         return inl_dev->is_multi_channel;
    1267                 :            : }
    1268                 :            : 
    1269                 :            : bool
    1270                 :          0 : roc_nix_inl_inb_is_enabled(struct roc_nix *roc_nix)
    1271                 :            : {
    1272                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1273                 :            : 
    1274                 :          0 :         return nix->inl_inb_ena;
    1275                 :            : }
    1276                 :            : 
    1277                 :            : bool
    1278                 :          0 : roc_nix_inl_outb_is_enabled(struct roc_nix *roc_nix)
    1279                 :            : {
    1280                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1281                 :            : 
    1282                 :          0 :         return nix->inl_outb_ena;
    1283                 :            : }
    1284                 :            : 
    1285                 :            : int
    1286                 :          0 : roc_nix_inl_dev_rq_get(struct roc_nix_rq *rq, bool enable)
    1287                 :            : {
    1288                 :          0 :         struct nix *nix = roc_nix_to_nix_priv(rq->roc_nix);
    1289                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1290                 :          0 :         int port_id = rq->roc_nix->port_id;
    1291                 :            :         struct nix_inl_dev *inl_dev;
    1292                 :            :         struct roc_nix_rq *inl_rq;
    1293                 :            :         uint16_t inl_rq_id;
    1294                 :            :         struct mbox *mbox;
    1295                 :            :         struct dev *dev;
    1296                 :            :         int rc;
    1297                 :            : 
    1298         [ #  # ]:          0 :         if (idev == NULL)
    1299                 :            :                 return 0;
    1300                 :            : 
    1301                 :            :         /* Update meta aura handle in RQ */
    1302         [ #  # ]:          0 :         if (nix->need_meta_aura)
    1303                 :          0 :                 rq->meta_aura_handle = roc_npa_zero_aura_handle();
    1304                 :            : 
    1305                 :          0 :         inl_dev = idev->nix_inl_dev;
    1306                 :            :         /* Nothing to do if no inline device */
    1307         [ #  # ]:          0 :         if (!inl_dev)
    1308                 :            :                 return 0;
    1309                 :            : 
    1310                 :            :         /* Check if this RQ is already holding reference */
    1311         [ #  # ]:          0 :         if (rq->inl_dev_refs)
    1312                 :            :                 return 0;
    1313                 :            : 
    1314         [ #  # ]:          0 :         inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
    1315                 :          0 :         dev = &inl_dev->dev;
    1316                 :          0 :         inl_rq = &inl_dev->rqs[inl_rq_id];
    1317                 :            : 
    1318                 :            :         /* Just take reference if already inited */
    1319         [ #  # ]:          0 :         if (inl_rq->inl_dev_refs) {
    1320                 :          0 :                 inl_rq->inl_dev_refs++;
    1321                 :          0 :                 rq->inl_dev_refs = 1;
    1322                 :          0 :                 return 0;
    1323                 :            :         }
    1324                 :            :         memset(inl_rq, 0, sizeof(struct roc_nix_rq));
    1325                 :            : 
    1326                 :            :         /* Take RQ pool attributes from the first ethdev RQ */
    1327                 :          0 :         inl_rq->qid = inl_rq_id;
    1328                 :          0 :         inl_rq->aura_handle = rq->aura_handle;
    1329                 :          0 :         inl_rq->first_skip = rq->first_skip;
    1330                 :          0 :         inl_rq->later_skip = rq->later_skip;
    1331                 :          0 :         inl_rq->lpb_size = rq->lpb_size;
    1332                 :          0 :         inl_rq->spb_ena = rq->spb_ena;
    1333                 :          0 :         inl_rq->spb_aura_handle = rq->spb_aura_handle;
    1334         [ #  # ]:          0 :         inl_rq->spb_size = rq->spb_size;
    1335                 :            : 
    1336         [ #  # ]:          0 :         if (roc_errata_nix_no_meta_aura()) {
    1337                 :            :                 uint64_t aura_limit =
    1338                 :            :                         roc_npa_aura_op_limit_get(inl_rq->aura_handle);
    1339                 :            :                 uint64_t aura_shift = plt_log2_u32(aura_limit);
    1340                 :            :                 uint64_t aura_drop, drop_pc;
    1341                 :            : 
    1342                 :          0 :                 inl_rq->lpb_drop_ena = true;
    1343                 :            : 
    1344                 :            :                 if (aura_shift < 8)
    1345                 :            :                         aura_shift = 0;
    1346                 :            :                 else
    1347                 :            :                         aura_shift = aura_shift - 8;
    1348                 :            : 
    1349                 :            :                 /* Set first pass RQ to drop after part of buffers are in
    1350                 :            :                  * use to avoid metabuf alloc failure. This is needed as long
    1351                 :            :                  * as we cannot use different aura.
    1352                 :            :                  */
    1353                 :            :                 drop_pc = inl_dev->lpb_drop_pc;
    1354                 :            :                 aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
    1355                 :          0 :                 roc_npa_aura_drop_set(inl_rq->aura_handle, aura_drop, true);
    1356                 :            :         }
    1357                 :            : 
    1358   [ #  #  #  # ]:          0 :         if (roc_errata_nix_no_meta_aura() && inl_rq->spb_ena) {
    1359                 :            :                 uint64_t aura_limit =
    1360                 :          0 :                         roc_npa_aura_op_limit_get(inl_rq->spb_aura_handle);
    1361                 :            :                 uint64_t aura_shift = plt_log2_u32(aura_limit);
    1362                 :            :                 uint64_t aura_drop, drop_pc;
    1363                 :            : 
    1364                 :          0 :                 inl_rq->spb_drop_ena = true;
    1365                 :            : 
    1366                 :            :                 if (aura_shift < 8)
    1367                 :            :                         aura_shift = 0;
    1368                 :            :                 else
    1369                 :            :                         aura_shift = aura_shift - 8;
    1370                 :            : 
    1371                 :            :                 /* Set first pass RQ to drop after part of buffers are in
    1372                 :            :                  * use to avoid metabuf alloc failure. This is needed as long
    1373                 :            :                  * as we cannot use different aura.
    1374                 :            :                  */
    1375                 :            :                 drop_pc = inl_dev->spb_drop_pc;
    1376                 :            :                 aura_drop = ((aura_limit * drop_pc) / 100) >> aura_shift;
    1377                 :          0 :                 roc_npa_aura_drop_set(inl_rq->spb_aura_handle, aura_drop, true);
    1378                 :            :         }
    1379                 :            : 
    1380                 :            :         /* Enable IPSec */
    1381                 :          0 :         inl_rq->ipsech_ena = true;
    1382                 :            : 
    1383                 :          0 :         inl_rq->flow_tag_width = 20;
    1384                 :            :         /* Special tag mask */
    1385                 :          0 :         inl_rq->tag_mask = rq->tag_mask;
    1386                 :          0 :         inl_rq->tt = SSO_TT_ORDERED;
    1387                 :          0 :         inl_rq->hwgrp = 0;
    1388                 :          0 :         inl_rq->wqe_skip = inl_dev->wqe_skip;
    1389                 :          0 :         inl_rq->sso_ena = true;
    1390                 :            : 
    1391                 :            :         /* Prepare and send RQ init mbox */
    1392                 :          0 :         mbox = mbox_get(dev->mbox);
    1393         [ #  # ]:          0 :         if (roc_model_is_cn9k())
    1394                 :          0 :                 rc = nix_rq_cn9k_cfg(dev, inl_rq, inl_dev->qints, false, enable);
    1395         [ #  # ]:          0 :         else if (roc_model_is_cn10k())
    1396                 :          0 :                 rc = nix_rq_cn10k_cfg(dev, inl_rq, inl_dev->qints, false, enable);
    1397                 :            :         else
    1398                 :          0 :                 rc = nix_rq_cfg(dev, inl_rq, inl_dev->qints, false, enable);
    1399         [ #  # ]:          0 :         if (rc) {
    1400                 :          0 :                 plt_err("Failed to prepare aq_enq msg, rc=%d", rc);
    1401                 :            :                 mbox_put(mbox);
    1402                 :          0 :                 return rc;
    1403                 :            :         }
    1404                 :            : 
    1405                 :          0 :         rc = mbox_process(dev->mbox);
    1406         [ #  # ]:          0 :         if (rc) {
    1407                 :          0 :                 plt_err("Failed to send aq_enq msg, rc=%d", rc);
    1408                 :            :                 mbox_put(mbox);
    1409                 :          0 :                 return rc;
    1410                 :            :         }
    1411                 :            :         mbox_put(mbox);
    1412                 :            : 
    1413                 :            :         /* Check meta aura */
    1414   [ #  #  #  # ]:          0 :         if (enable && nix->need_meta_aura) {
    1415                 :          0 :                 rc = roc_nix_inl_meta_aura_check(rq->roc_nix, rq);
    1416         [ #  # ]:          0 :                 if (rc)
    1417                 :            :                         return rc;
    1418                 :            :         }
    1419                 :            : 
    1420                 :          0 :         inl_rq->inl_dev_refs++;
    1421                 :          0 :         rq->inl_dev_refs = 1;
    1422                 :          0 :         return 0;
    1423                 :            : }
    1424                 :            : 
    1425                 :            : int
    1426                 :          0 : roc_nix_inl_dev_rq_put(struct roc_nix_rq *rq)
    1427                 :            : {
    1428                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1429                 :          0 :         int port_id = rq->roc_nix->port_id;
    1430                 :            :         struct nix_inl_dev *inl_dev;
    1431                 :            :         struct roc_nix_rq *inl_rq;
    1432                 :            :         uint16_t inl_rq_id;
    1433                 :            :         struct dev *dev;
    1434                 :            :         int rc;
    1435                 :            : 
    1436         [ #  # ]:          0 :         if (idev == NULL)
    1437                 :            :                 return 0;
    1438                 :            : 
    1439                 :          0 :         rq->meta_aura_handle = 0;
    1440         [ #  # ]:          0 :         if (!rq->inl_dev_refs)
    1441                 :            :                 return 0;
    1442                 :            : 
    1443                 :          0 :         inl_dev = idev->nix_inl_dev;
    1444                 :            :         /* Inline device should be there if we have ref */
    1445         [ #  # ]:          0 :         if (!inl_dev) {
    1446                 :          0 :                 plt_err("Failed to find inline device with refs");
    1447                 :          0 :                 return -EFAULT;
    1448                 :            :         }
    1449                 :            : 
    1450                 :          0 :         dev = &inl_dev->dev;
    1451         [ #  # ]:          0 :         inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
    1452                 :          0 :         inl_rq = &inl_dev->rqs[inl_rq_id];
    1453                 :            : 
    1454                 :          0 :         rq->inl_dev_refs = 0;
    1455                 :          0 :         inl_rq->inl_dev_refs--;
    1456         [ #  # ]:          0 :         if (inl_rq->inl_dev_refs)
    1457                 :            :                 return 0;
    1458                 :            : 
    1459                 :            :         /* There are no more references, disable RQ */
    1460                 :          0 :         rc = nix_rq_ena_dis(dev, inl_rq, false);
    1461         [ #  # ]:          0 :         if (rc)
    1462                 :          0 :                 plt_err("Failed to disable inline device rq, rc=%d", rc);
    1463                 :            : 
    1464                 :          0 :         roc_npa_aura_drop_set(inl_rq->aura_handle, 0, false);
    1465         [ #  # ]:          0 :         if (inl_rq->spb_ena)
    1466                 :          0 :                 roc_npa_aura_drop_set(inl_rq->spb_aura_handle, 0, false);
    1467                 :            : 
    1468                 :            :         /* Flush NIX LF for CN10K */
    1469                 :          0 :         nix_rq_vwqe_flush(rq, inl_dev->vwqe_interval);
    1470                 :            : 
    1471                 :          0 :         return rc;
    1472                 :            : }
    1473                 :            : 
    1474                 :            : int
    1475                 :          0 : roc_nix_inl_rq_ena_dis(struct roc_nix *roc_nix, bool enable)
    1476                 :            : {
    1477                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1478                 :          0 :         struct roc_nix_rq *inl_rq = roc_nix_inl_dev_rq(roc_nix);
    1479                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1480                 :            :         struct nix_inl_dev *inl_dev;
    1481                 :            :         int rc;
    1482                 :            : 
    1483         [ #  # ]:          0 :         if (!idev)
    1484                 :            :                 return -EFAULT;
    1485                 :            : 
    1486   [ #  #  #  # ]:          0 :         if (roc_feature_nix_has_inl_rq_mask() && enable) {
    1487                 :          0 :                 rc = nix_inl_rq_mask_cfg(roc_nix, enable);
    1488         [ #  # ]:          0 :                 if (rc) {
    1489                 :          0 :                         plt_err("Failed to get rq mask rc=%d", rc);
    1490                 :          0 :                         return rc;
    1491                 :            :                 }
    1492                 :            :         }
    1493                 :            : 
    1494         [ #  # ]:          0 :         if (nix->inb_inl_dev) {
    1495   [ #  #  #  # ]:          0 :                 if (!inl_rq || !idev->nix_inl_dev)
    1496                 :            :                         return -EFAULT;
    1497                 :            : 
    1498                 :            :                 inl_dev = idev->nix_inl_dev;
    1499                 :            : 
    1500                 :          0 :                 rc = nix_rq_ena_dis(&inl_dev->dev, inl_rq, enable);
    1501         [ #  # ]:          0 :                 if (rc)
    1502                 :            :                         return rc;
    1503                 :            : 
    1504   [ #  #  #  # ]:          0 :                 if (enable && nix->need_meta_aura)
    1505                 :          0 :                         return roc_nix_inl_meta_aura_check(roc_nix, inl_rq);
    1506                 :            :         }
    1507                 :            :         return 0;
    1508                 :            : }
    1509                 :            : 
    1510                 :            : void
    1511                 :          0 : roc_nix_inb_mode_set(struct roc_nix *roc_nix, bool use_inl_dev)
    1512                 :            : {
    1513                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1514                 :            : 
    1515                 :            :         /* Info used by NPC flow rule add */
    1516                 :          0 :         nix->inb_inl_dev = use_inl_dev;
    1517                 :          0 : }
    1518                 :            : 
    1519                 :            : void
    1520                 :          0 : roc_nix_inl_inb_set(struct roc_nix *roc_nix, bool ena)
    1521                 :            : {
    1522                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1523                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1524                 :            : 
    1525         [ #  # ]:          0 :         if (!idev)
    1526                 :            :                 return;
    1527                 :            :         /* Need to set here for cases when inbound SA table is
    1528                 :            :          * managed outside RoC.
    1529                 :            :          */
    1530         [ #  # ]:          0 :         nix->inl_inb_ena = ena;
    1531                 :            : 
    1532   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() || roc_errata_nix_no_meta_aura())
    1533                 :            :                 return;
    1534                 :            : 
    1535         [ #  # ]:          0 :         if (ena) {
    1536                 :          0 :                 nix->need_meta_aura = true;
    1537   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
    1538                 :          0 :                         idev->inl_cfg.refs++;
    1539         [ #  # ]:          0 :         } else if (nix->need_meta_aura) {
    1540                 :          0 :                 nix->need_meta_aura = false;
    1541   [ #  #  #  # ]:          0 :                 if (!roc_nix->local_meta_aura_ena || roc_nix->custom_meta_aura_ena)
    1542                 :          0 :                         idev->inl_cfg.refs--;
    1543                 :            : 
    1544         [ #  # ]:          0 :                 if (roc_nix->custom_meta_aura_ena)
    1545                 :          0 :                         nix_inl_custom_meta_aura_destroy(roc_nix);
    1546                 :            : 
    1547         [ #  # ]:          0 :                 if (!idev->inl_cfg.refs)
    1548                 :          0 :                         nix_inl_meta_aura_destroy(roc_nix);
    1549                 :            :         }
    1550                 :            : }
    1551                 :            : 
    1552                 :            : int
    1553                 :          0 : roc_nix_inl_outb_soft_exp_poll_switch(struct roc_nix *roc_nix, bool poll)
    1554                 :            : {
    1555                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1556                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1557                 :            :         struct nix_inl_dev *inl_dev;
    1558                 :            :         uint16_t ring_idx, i;
    1559                 :            : 
    1560   [ #  #  #  # ]:          0 :         if (!idev || !idev->nix_inl_dev)
    1561                 :            :                 return 0;
    1562                 :            : 
    1563                 :            :         inl_dev = idev->nix_inl_dev;
    1564                 :            : 
    1565         [ #  # ]:          0 :         for (i = 0; i < nix->outb_se_ring_cnt; i++) {
    1566                 :          0 :                 ring_idx = nix->outb_se_ring_base + i;
    1567                 :            : 
    1568         [ #  # ]:          0 :                 if (poll)
    1569                 :          0 :                         plt_bitmap_set(inl_dev->soft_exp_ring_bmap, ring_idx);
    1570                 :            :                 else
    1571                 :          0 :                         plt_bitmap_clear(inl_dev->soft_exp_ring_bmap, ring_idx);
    1572                 :            :         }
    1573                 :            : 
    1574         [ #  # ]:          0 :         if (poll)
    1575                 :          0 :                 soft_exp_consumer_cnt++;
    1576                 :            :         else
    1577                 :          0 :                 soft_exp_consumer_cnt--;
    1578                 :            : 
    1579                 :            :         return 0;
    1580                 :            : }
    1581                 :            : 
    1582                 :            : bool
    1583                 :          0 : roc_nix_inb_is_with_inl_dev(struct roc_nix *roc_nix)
    1584                 :            : {
    1585                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1586                 :            : 
    1587                 :          0 :         return nix->inb_inl_dev;
    1588                 :            : }
    1589                 :            : 
    1590                 :            : struct roc_nix_rq *
    1591                 :          0 : roc_nix_inl_dev_rq(struct roc_nix *roc_nix)
    1592                 :            : {
    1593                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1594                 :          0 :         int port_id = roc_nix->port_id;
    1595                 :            :         struct nix_inl_dev *inl_dev;
    1596                 :            :         struct roc_nix_rq *inl_rq;
    1597                 :            :         uint16_t inl_rq_id;
    1598                 :            : 
    1599         [ #  # ]:          0 :         if (idev != NULL) {
    1600                 :          0 :                 inl_dev = idev->nix_inl_dev;
    1601         [ #  # ]:          0 :                 if (inl_dev != NULL) {
    1602         [ #  # ]:          0 :                         inl_rq_id = inl_dev->nb_rqs > 1 ? port_id : 0;
    1603                 :          0 :                         inl_rq = &inl_dev->rqs[inl_rq_id];
    1604         [ #  # ]:          0 :                         if (inl_rq->inl_dev_refs)
    1605                 :          0 :                                 return inl_rq;
    1606                 :            :                 }
    1607                 :            :         }
    1608                 :            : 
    1609                 :            :         return NULL;
    1610                 :            : }
    1611                 :            : 
    1612                 :            : uint16_t __roc_api
    1613                 :          0 : roc_nix_inl_outb_sso_pffunc_get(struct roc_nix *roc_nix)
    1614                 :            : {
    1615                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1616                 :            : 
    1617                 :          0 :         return nix->outb_err_sso_pffunc;
    1618                 :            : }
    1619                 :            : 
    1620                 :            : int
    1621                 :          0 : roc_nix_inl_cb_register(roc_nix_inl_sso_work_cb_t cb, void *args)
    1622                 :            : {
    1623                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1624                 :            :         struct nix_inl_dev *inl_dev;
    1625                 :            : 
    1626         [ #  # ]:          0 :         if (idev == NULL)
    1627                 :            :                 return -EIO;
    1628                 :            : 
    1629                 :          0 :         inl_dev = idev->nix_inl_dev;
    1630         [ #  # ]:          0 :         if (!inl_dev)
    1631                 :            :                 return -EIO;
    1632                 :            : 
    1633                 :            :         /* Be silent if registration called with same cb and args */
    1634   [ #  #  #  # ]:          0 :         if (inl_dev->work_cb == cb && inl_dev->cb_args == args)
    1635                 :            :                 return 0;
    1636                 :            : 
    1637                 :            :         /* Don't allow registration again if registered with different cb */
    1638         [ #  # ]:          0 :         if (inl_dev->work_cb)
    1639                 :            :                 return -EBUSY;
    1640                 :            : 
    1641                 :          0 :         inl_dev->work_cb = cb;
    1642                 :          0 :         inl_dev->cb_args = args;
    1643                 :          0 :         return 0;
    1644                 :            : }
    1645                 :            : 
    1646                 :            : int
    1647                 :          0 : roc_nix_inl_cb_unregister(roc_nix_inl_sso_work_cb_t cb, void *args)
    1648                 :            : {
    1649                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1650                 :            :         struct nix_inl_dev *inl_dev;
    1651                 :            : 
    1652         [ #  # ]:          0 :         if (idev == NULL)
    1653                 :            :                 return -ENOENT;
    1654                 :            : 
    1655                 :          0 :         inl_dev = idev->nix_inl_dev;
    1656         [ #  # ]:          0 :         if (!inl_dev)
    1657                 :            :                 return -ENOENT;
    1658                 :            : 
    1659   [ #  #  #  # ]:          0 :         if (inl_dev->work_cb != cb || inl_dev->cb_args != args)
    1660                 :            :                 return -EINVAL;
    1661                 :            : 
    1662                 :          0 :         inl_dev->work_cb = NULL;
    1663                 :          0 :         inl_dev->cb_args = NULL;
    1664                 :          0 :         return 0;
    1665                 :            : }
    1666                 :            : 
    1667                 :            : int
    1668                 :          0 : roc_nix_inl_inb_tag_update(struct roc_nix *roc_nix, uint32_t tag_const,
    1669                 :            :                            uint8_t tt)
    1670                 :            : {
    1671                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1672                 :            :         struct roc_nix_ipsec_cfg cfg;
    1673                 :            : 
    1674                 :            :         /* Be silent if inline inbound not enabled */
    1675         [ #  # ]:          0 :         if (!nix->inl_inb_ena)
    1676                 :            :                 return 0;
    1677                 :            : 
    1678                 :            :         memset(&cfg, 0, sizeof(cfg));
    1679                 :          0 :         cfg.sa_size = nix->inb_sa_sz;
    1680                 :          0 :         cfg.iova = (uintptr_t)nix->inb_sa_base;
    1681                 :          0 :         cfg.max_sa = nix->inb_spi_mask + 1;
    1682                 :          0 :         cfg.tt = tt;
    1683                 :          0 :         cfg.tag_const = tag_const;
    1684                 :            : 
    1685                 :          0 :         return roc_nix_lf_inl_ipsec_cfg(roc_nix, &cfg, true);
    1686                 :            : }
    1687                 :            : 
    1688                 :            : int
    1689                 :          0 : roc_nix_inl_sa_sync(struct roc_nix *roc_nix, void *sa, bool inb,
    1690                 :            :                     enum roc_nix_inl_sa_sync_op op)
    1691                 :            : {
    1692                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1693                 :            :         struct nix_inl_dev *inl_dev = NULL;
    1694                 :            :         struct roc_cpt_lf *outb_lf = NULL;
    1695                 :            :         union cpt_lf_ctx_reload reload;
    1696                 :            :         union cpt_lf_ctx_flush flush;
    1697                 :            :         union cpt_lf_ctx_err err;
    1698                 :            :         bool get_inl_lf = true;
    1699                 :            :         uintptr_t rbase;
    1700                 :            :         struct nix *nix;
    1701                 :            : 
    1702                 :            :         /* Nothing much to do on cn9k */
    1703         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    1704                 :            :                 plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
    1705                 :          0 :                 return 0;
    1706                 :            :         }
    1707                 :            : 
    1708         [ #  # ]:          0 :         if (idev)
    1709                 :          0 :                 inl_dev = idev->nix_inl_dev;
    1710                 :            : 
    1711         [ #  # ]:          0 :         if (!inl_dev && roc_nix == NULL)
    1712                 :            :                 return -EINVAL;
    1713                 :            : 
    1714         [ #  # ]:          0 :         if (roc_nix) {
    1715                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    1716                 :          0 :                 outb_lf = nix->cpt_lf_base;
    1717   [ #  #  #  # ]:          0 :                 if (inb && !nix->inb_inl_dev)
    1718                 :            :                         get_inl_lf = false;
    1719                 :            :         }
    1720                 :            : 
    1721         [ #  # ]:          0 :         if (inb && get_inl_lf) {
    1722                 :            :                 outb_lf = NULL;
    1723   [ #  #  #  # ]:          0 :                 if (inl_dev && inl_dev->attach_cptlf)
    1724                 :          0 :                         outb_lf = &inl_dev->cpt_lf[0];
    1725                 :            :         }
    1726                 :            : 
    1727         [ #  # ]:          0 :         if (outb_lf) {
    1728                 :          0 :                 rbase = outb_lf->rbase;
    1729                 :            : 
    1730                 :          0 :                 flush.u = 0;
    1731                 :          0 :                 reload.u = 0;
    1732   [ #  #  #  # ]:          0 :                 switch (op) {
    1733                 :          0 :                 case ROC_NIX_INL_SA_OP_FLUSH_INVAL:
    1734                 :          0 :                         flush.s.inval = 1;
    1735                 :            :                         /* fall through */
    1736                 :          0 :                 case ROC_NIX_INL_SA_OP_FLUSH:
    1737                 :          0 :                         flush.s.cptr = ((uintptr_t)sa) >> 7;
    1738         [ #  # ]:          0 :                         plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
    1739                 :            :                         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
    1740                 :            :                         /* Read a CSR to ensure that the FLUSH operation is complete */
    1741         [ #  # ]:          0 :                         err.u = plt_read64(rbase + CPT_LF_CTX_ERR);
    1742                 :            : 
    1743         [ #  # ]:          0 :                         if (err.s.flush_st_flt) {
    1744                 :          0 :                                 plt_warn("CTX flush could not complete");
    1745                 :          0 :                                 return -EIO;
    1746                 :            :                         }
    1747                 :            :                         break;
    1748                 :          0 :                 case ROC_NIX_INL_SA_OP_RELOAD:
    1749                 :          0 :                         reload.s.cptr = ((uintptr_t)sa) >> 7;
    1750                 :          0 :                         plt_write64(reload.u, rbase + CPT_LF_CTX_RELOAD);
    1751                 :            :                         break;
    1752                 :            :                 default:
    1753                 :            :                         return -EINVAL;
    1754                 :            :                 }
    1755                 :          0 :                 return 0;
    1756                 :            :         }
    1757                 :          0 :         plt_err("Could not get CPT LF for SA sync");
    1758                 :          0 :         return -ENOTSUP;
    1759                 :            : }
    1760                 :            : 
    1761                 :            : int
    1762                 :          0 : roc_nix_inl_ctx_write(struct roc_nix *roc_nix, void *sa_dptr, void *sa_cptr,
    1763                 :            :                       bool inb, uint16_t sa_len)
    1764                 :            : {
    1765                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1766                 :            :         struct nix_inl_dev *inl_dev = NULL;
    1767                 :            :         struct roc_cpt_lf *outb_lf = NULL;
    1768                 :            :         union cpt_lf_ctx_flush flush;
    1769                 :            :         union cpt_lf_ctx_err err;
    1770                 :            :         bool get_inl_lf = true;
    1771                 :            :         uintptr_t rbase;
    1772                 :            :         struct nix *nix;
    1773                 :            :         int rc;
    1774                 :            : 
    1775                 :            :         /* Nothing much to do on cn9k */
    1776         [ #  # ]:          0 :         if (roc_model_is_cn9k()) {
    1777                 :            :                 return 0;
    1778                 :            :         }
    1779         [ #  # ]:          0 :         if (idev)
    1780                 :          0 :                 inl_dev = idev->nix_inl_dev;
    1781                 :            : 
    1782         [ #  # ]:          0 :         if (!inl_dev && roc_nix == NULL)
    1783                 :            :                 return -EINVAL;
    1784                 :            : 
    1785         [ #  # ]:          0 :         if (roc_nix) {
    1786   [ #  #  #  #  :          0 :                 if (inb && roc_nix->custom_inb_sa && sa_len > ROC_NIX_INL_INB_CUSTOM_SA_SZ) {
                   #  # ]
    1787                 :          0 :                         plt_nix_dbg("SA length: %u is more than allocated length: %u", sa_len,
    1788                 :            :                                     ROC_NIX_INL_INB_CUSTOM_SA_SZ);
    1789                 :          0 :                         return -EINVAL;
    1790                 :            :                 }
    1791                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    1792                 :          0 :                 outb_lf = nix->cpt_lf_base;
    1793                 :            : 
    1794   [ #  #  #  # ]:          0 :                 if (inb && !nix->inb_inl_dev)
    1795                 :            :                         get_inl_lf = false;
    1796                 :            :         }
    1797                 :            : 
    1798         [ #  # ]:          0 :         if (inb && get_inl_lf) {
    1799                 :            :                 outb_lf = NULL;
    1800   [ #  #  #  # ]:          0 :                 if (inl_dev && inl_dev->attach_cptlf)
    1801                 :          0 :                         outb_lf = &inl_dev->cpt_lf[0];
    1802                 :            :         }
    1803                 :            : 
    1804         [ #  # ]:          0 :         if (outb_lf) {
    1805                 :          0 :                 rbase = outb_lf->rbase;
    1806                 :          0 :                 flush.u = 0;
    1807                 :            : 
    1808                 :          0 :                 rc = roc_cpt_ctx_write(outb_lf, sa_dptr, sa_cptr, sa_len);
    1809         [ #  # ]:          0 :                 if (rc)
    1810                 :            :                         return rc;
    1811                 :            :                 /* Trigger CTX flush to write dirty data back to DRAM */
    1812                 :          0 :                 flush.s.cptr = ((uintptr_t)sa_cptr) >> 7;
    1813         [ #  # ]:          0 :                 plt_write64(flush.u, rbase + CPT_LF_CTX_FLUSH);
    1814                 :            : 
    1815                 :            :                 plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
    1816                 :            : 
    1817                 :            :                 /* Read a CSR to ensure that the FLUSH operation is complete */
    1818         [ #  # ]:          0 :                 err.u = plt_read64(rbase + CPT_LF_CTX_ERR);
    1819                 :            : 
    1820         [ #  # ]:          0 :                 if (err.s.flush_st_flt)
    1821                 :          0 :                         plt_warn("CTX flush could not complete");
    1822                 :          0 :                 return 0;
    1823                 :            :         }
    1824                 :          0 :         plt_nix_dbg("Could not get CPT LF for CTX write");
    1825                 :          0 :         return -ENOTSUP;
    1826                 :            : }
    1827                 :            : 
    1828                 :            : static inline int
    1829                 :          0 : nix_inl_dev_cpt_lf_stats_get(struct roc_nix *roc_nix, struct roc_nix_cpt_lf_stats *stats,
    1830                 :            :                              uint16_t idx)
    1831                 :            : {
    1832                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1833                 :            :         struct nix_inl_dev *inl_dev = NULL;
    1834                 :            :         struct roc_cpt_lf *lf = NULL;
    1835                 :            : 
    1836                 :            :         PLT_SET_USED(roc_nix);
    1837         [ #  # ]:          0 :         if (idev)
    1838                 :          0 :                 inl_dev = idev->nix_inl_dev;
    1839                 :            : 
    1840   [ #  #  #  # ]:          0 :         if (inl_dev && inl_dev->attach_cptlf) {
    1841         [ #  # ]:          0 :                 if (idx >= inl_dev->nb_cptlf) {
    1842                 :          0 :                         plt_err("Invalid idx: %u total lfs: %d", idx, inl_dev->nb_cptlf);
    1843                 :          0 :                         return -EINVAL;
    1844                 :            :                 }
    1845                 :          0 :                 lf = &inl_dev->cpt_lf[idx];
    1846                 :            :         } else {
    1847                 :          0 :                 plt_err("No CPT LF(s) are found for Inline Device");
    1848                 :          0 :                 return -EINVAL;
    1849                 :            :         }
    1850                 :          0 :         stats->enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
    1851                 :          0 :         stats->enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
    1852                 :          0 :         stats->dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
    1853                 :          0 :         stats->dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
    1854                 :            : 
    1855                 :          0 :         return 0;
    1856                 :            : }
    1857                 :            : 
    1858                 :            : static inline int
    1859                 :          0 : nix_eth_dev_cpt_lf_stats_get(struct roc_nix *roc_nix, struct roc_nix_cpt_lf_stats *stats,
    1860                 :            :                              uint16_t idx)
    1861                 :            : {
    1862                 :            :         struct roc_cpt_lf *lf;
    1863                 :            :         struct nix *nix;
    1864                 :            : 
    1865         [ #  # ]:          0 :         if (!roc_nix)
    1866                 :            :                 return -EINVAL;
    1867                 :            :         nix = roc_nix_to_nix_priv(roc_nix);
    1868         [ #  # ]:          0 :         if (idx >= nix->nb_cpt_lf) {
    1869                 :          0 :                 plt_err("Invalid idx: %u total lfs: %d", idx, nix->nb_cpt_lf);
    1870                 :          0 :                 return -EINVAL;
    1871                 :            :         }
    1872                 :          0 :         lf = &nix->cpt_lf_base[idx];
    1873                 :          0 :         stats->enc_pkts = plt_read64(lf->rbase + CPT_LF_CTX_ENC_PKT_CNT);
    1874                 :          0 :         stats->enc_bytes = plt_read64(lf->rbase + CPT_LF_CTX_ENC_BYTE_CNT);
    1875                 :          0 :         stats->dec_pkts = plt_read64(lf->rbase + CPT_LF_CTX_DEC_PKT_CNT);
    1876                 :          0 :         stats->dec_bytes = plt_read64(lf->rbase + CPT_LF_CTX_DEC_BYTE_CNT);
    1877                 :            : 
    1878                 :          0 :         return 0;
    1879                 :            : }
    1880                 :            : 
    1881                 :            : int
    1882                 :          0 : roc_nix_inl_cpt_lf_stats_get(struct roc_nix *roc_nix, enum roc_nix_cpt_lf_stats_type type,
    1883                 :            :                              struct roc_nix_cpt_lf_stats *stats, uint16_t idx)
    1884                 :            : {
    1885      [ #  #  # ]:          0 :         switch (type) {
    1886                 :          0 :         case ROC_NIX_CPT_LF_STATS_INL_DEV:
    1887                 :          0 :                 return nix_inl_dev_cpt_lf_stats_get(roc_nix, stats, idx);
    1888                 :          0 :         case ROC_NIX_CPT_LF_STATS_ETHDEV:
    1889                 :          0 :                 return nix_eth_dev_cpt_lf_stats_get(roc_nix, stats, idx);
    1890                 :            :         default:
    1891                 :            :                 return -EINVAL;
    1892                 :            :         }
    1893                 :            : }
    1894                 :            : 
    1895                 :            : int
    1896                 :          0 : roc_nix_inl_ts_pkind_set(struct roc_nix *roc_nix, bool ts_ena, bool inb_inl_dev)
    1897                 :            : {
    1898                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1899                 :            :         struct nix_inl_dev *inl_dev = NULL;
    1900                 :            :         void *sa, *sa_base = NULL;
    1901                 :            :         struct nix *nix = NULL;
    1902                 :            :         uint16_t max_spi = 0;
    1903                 :            :         uint32_t rq_refs = 0;
    1904                 :            :         uint8_t pkind = 0;
    1905                 :            :         size_t inb_sa_sz;
    1906                 :            :         int i;
    1907                 :            : 
    1908         [ #  # ]:          0 :         if (roc_model_is_cn9k())
    1909                 :            :                 return 0;
    1910                 :            : 
    1911         [ #  # ]:          0 :         if (!inb_inl_dev && (roc_nix == NULL))
    1912                 :            :                 return -EINVAL;
    1913                 :            : 
    1914         [ #  # ]:          0 :         if (inb_inl_dev) {
    1915   [ #  #  #  # ]:          0 :                 if ((idev == NULL) || (idev->nix_inl_dev == NULL))
    1916                 :            :                         return 0;
    1917                 :            :                 inl_dev = idev->nix_inl_dev;
    1918                 :            :         } else {
    1919                 :            :                 nix = roc_nix_to_nix_priv(roc_nix);
    1920         [ #  # ]:          0 :                 if (!nix->inl_inb_ena)
    1921                 :            :                         return 0;
    1922                 :          0 :                 sa_base = nix->inb_sa_base;
    1923                 :          0 :                 inb_sa_sz = nix->inb_sa_sz;
    1924                 :          0 :                 max_spi = roc_nix->ipsec_in_max_spi;
    1925                 :            :         }
    1926                 :            : 
    1927         [ #  # ]:          0 :         if (inl_dev) {
    1928         [ #  # ]:          0 :                 for (i = 0; i < inl_dev->nb_rqs; i++)
    1929                 :          0 :                         rq_refs += inl_dev->rqs[i].inl_dev_refs;
    1930                 :            : 
    1931         [ #  # ]:          0 :                 if (rq_refs == 0) {
    1932                 :          0 :                         inl_dev->ts_ena = ts_ena;
    1933                 :          0 :                         max_spi = inl_dev->ipsec_in_max_spi;
    1934                 :          0 :                         sa_base = inl_dev->inb_sa_base;
    1935                 :          0 :                         inb_sa_sz = inl_dev->inb_sa_sz;
    1936         [ #  # ]:          0 :                 } else if (inl_dev->ts_ena != ts_ena) {
    1937         [ #  # ]:          0 :                         if (inl_dev->ts_ena)
    1938                 :          0 :                                 plt_err("Inline device is already configured with TS enable");
    1939                 :            :                         else
    1940                 :          0 :                                 plt_err("Inline device is already configured with TS disable");
    1941                 :          0 :                         return -ENOTSUP;
    1942                 :            :                 } else {
    1943                 :            :                         return 0;
    1944                 :            :                 }
    1945                 :            :         }
    1946                 :            : 
    1947         [ #  # ]:          0 :         pkind = ts_ena ? ROC_IE_OT_CPT_TS_PKIND : ROC_IE_OT_CPT_PKIND;
    1948                 :            : 
    1949                 :            :         sa = (uint8_t *)sa_base;
    1950         [ #  # ]:          0 :         if (pkind == ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind)
    1951                 :            :                 return 0;
    1952                 :            : 
    1953         [ #  # ]:          0 :         for (i = 0; i < max_spi; i++) {
    1954                 :          0 :                 sa = ((uint8_t *)sa_base) + (i * inb_sa_sz);
    1955                 :          0 :                 ((struct roc_ot_ipsec_inb_sa *)sa)->w0.s.pkind = pkind;
    1956                 :            :         }
    1957                 :            :         return 0;
    1958                 :            : }
    1959                 :            : 
    1960                 :            : void
    1961                 :          0 : roc_nix_inl_dev_lock(void)
    1962                 :            : {
    1963                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1964                 :            : 
    1965         [ #  # ]:          0 :         if (idev != NULL)
    1966                 :          0 :                 plt_spinlock_lock(&idev->nix_inl_dev_lock);
    1967                 :          0 : }
    1968                 :            : 
    1969                 :            : void
    1970                 :          0 : roc_nix_inl_dev_unlock(void)
    1971                 :            : {
    1972                 :          0 :         struct idev_cfg *idev = idev_get_cfg();
    1973                 :            : 
    1974         [ #  # ]:          0 :         if (idev != NULL)
    1975                 :          0 :                 plt_spinlock_unlock(&idev->nix_inl_dev_lock);
    1976                 :          0 : }
    1977                 :            : 
    1978                 :            : void
    1979                 :          0 : roc_nix_inl_meta_pool_cb_register(roc_nix_inl_meta_pool_cb_t cb)
    1980                 :            : {
    1981                 :          0 :         meta_pool_cb = cb;
    1982                 :          0 : }
    1983                 :            : 
    1984                 :            : uint64_t
    1985                 :          0 : roc_nix_inl_eng_caps_get(struct roc_nix *roc_nix)
    1986                 :            : {
    1987                 :            :         struct nix *nix = roc_nix_to_nix_priv(roc_nix);
    1988                 :            : 
    1989                 :          0 :         return nix->cpt_eng_caps;
    1990                 :            : }
    1991                 :            : 
    1992                 :            : void
    1993                 :          0 : roc_nix_inl_custom_meta_pool_cb_register(roc_nix_inl_custom_meta_pool_cb_t cb)
    1994                 :            : {
    1995                 :          0 :         custom_meta_pool_cb = cb;
    1996                 :          0 : }

Generated by: LCOV version 1.14