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

Generated by: LCOV version 1.14