LCOV - code coverage report
Current view: top level - drivers/net/cnxk - cnxk_ethdev_sec.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 1 204 0.5 %
Date: 2024-04-01 19:00:53 Functions: 1 17 5.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 90 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <cnxk_ethdev.h>
       6                 :            : #include <cnxk_mempool.h>
       7                 :            : 
       8                 :            : #define CNXK_NIX_INL_META_POOL_NAME "NIX_INL_META_POOL"
       9                 :            : #define CN10K_HW_POOL_OPS_NAME "cn10k_hwpool_ops"
      10                 :            : 
      11                 :            : #define CNXK_NIX_INL_SELFTEST         "selftest"
      12                 :            : #define CNXK_NIX_INL_IPSEC_IN_MIN_SPI "ipsec_in_min_spi"
      13                 :            : #define CNXK_NIX_INL_IPSEC_IN_MAX_SPI "ipsec_in_max_spi"
      14                 :            : #define CNXK_INL_CPT_CHANNEL          "inl_cpt_channel"
      15                 :            : #define CNXK_NIX_INL_NB_META_BUFS     "nb_meta_bufs"
      16                 :            : #define CNXK_NIX_INL_META_BUF_SZ      "meta_buf_sz"
      17                 :            : #define CNXK_NIX_SOFT_EXP_POLL_FREQ   "soft_exp_poll_freq"
      18                 :            : #define CNXK_MAX_IPSEC_RULES    "max_ipsec_rules"
      19                 :            : #define CNXK_NIX_INL_RX_INJ_ENABLE      "rx_inj_ena"
      20                 :            : 
      21                 :            : /* Default soft expiry poll freq in usec */
      22                 :            : #define CNXK_NIX_SOFT_EXP_POLL_FREQ_DFLT 100
      23                 :            : 
      24                 :            : struct inl_cpt_channel {
      25                 :            :         bool is_multi_channel;
      26                 :            :         uint16_t channel;
      27                 :            :         uint16_t mask;
      28                 :            : };
      29                 :            : 
      30                 :            : #define CNXK_NIX_INL_DEV_NAME RTE_STR(cnxk_nix_inl_dev_)
      31                 :            : #define CNXK_NIX_INL_DEV_NAME_LEN                                              \
      32                 :            :         (sizeof(CNXK_NIX_INL_DEV_NAME) + PCI_PRI_STR_SIZE)
      33                 :            : 
      34                 :            : static inline int
      35                 :            : bitmap_ctzll(uint64_t slab)
      36                 :            : {
      37                 :          0 :         if (slab == 0)
      38                 :            :                 return 0;
      39                 :            : 
      40                 :          0 :         return rte_ctz64(slab);
      41                 :            : }
      42                 :            : 
      43                 :            : int
      44                 :          0 : cnxk_nix_inl_meta_pool_cb(uint64_t *aura_handle, uintptr_t *mpool, uint32_t buf_sz,
      45                 :            :                           uint32_t nb_bufs, bool destroy, const char *mempool_name)
      46                 :            : {
      47                 :            :         const char *mp_name = NULL;
      48                 :            :         struct rte_pktmbuf_pool_private mbp_priv;
      49                 :            :         struct rte_mempool *mp;
      50                 :            :         uint16_t first_skip;
      51                 :            :         int rc;
      52                 :            : 
      53                 :            :         /* Null Mempool name indicates to allocate Zero aura. */
      54         [ #  # ]:          0 :         if (!mempool_name)
      55                 :            :                 mp_name = CNXK_NIX_INL_META_POOL_NAME;
      56                 :            :         else
      57                 :            :                 mp_name = mempool_name;
      58                 :            : 
      59                 :            :         /* Destroy the mempool if requested */
      60         [ #  # ]:          0 :         if (destroy) {
      61                 :          0 :                 mp = rte_mempool_lookup(mp_name);
      62         [ #  # ]:          0 :                 if (!mp)
      63                 :            :                         return -ENOENT;
      64                 :            : 
      65         [ #  # ]:          0 :                 if (mp->pool_id != *aura_handle) {
      66                 :          0 :                         plt_err("Meta pool aura mismatch");
      67                 :          0 :                         return -EINVAL;
      68                 :            :                 }
      69                 :            : 
      70                 :          0 :                 rte_mempool_free(mp);
      71                 :            : 
      72                 :          0 :                 *aura_handle = 0;
      73                 :          0 :                 *mpool = 0;
      74                 :          0 :                 return 0;
      75                 :            :         }
      76                 :            : 
      77                 :            :         /* Need to make it similar to rte_pktmbuf_pool() for sake of OOP
      78                 :            :          * support.
      79                 :            :          */
      80                 :          0 :         mp = rte_mempool_create_empty(mp_name, nb_bufs, buf_sz, 0,
      81                 :            :                                       sizeof(struct rte_pktmbuf_pool_private),
      82                 :            :                                       SOCKET_ID_ANY, 0);
      83         [ #  # ]:          0 :         if (!mp) {
      84                 :          0 :                 plt_err("Failed to create inline meta pool");
      85                 :          0 :                 return -EIO;
      86                 :            :         }
      87                 :            : 
      88         [ #  # ]:          0 :         rc = rte_mempool_set_ops_byname(mp, rte_mbuf_platform_mempool_ops(),
      89                 :            :                                         mempool_name ?
      90                 :            :                                         NULL : PLT_PTR_CAST(CNXK_MEMPOOL_F_ZERO_AURA));
      91         [ #  # ]:          0 :         if (rc) {
      92                 :          0 :                 plt_err("Failed to setup mempool ops for meta, rc=%d", rc);
      93                 :          0 :                 goto free_mp;
      94                 :            :         }
      95                 :            : 
      96                 :            :         /* Init mempool private area */
      97                 :            :         first_skip = sizeof(struct rte_mbuf) + RTE_PKTMBUF_HEADROOM;
      98                 :            :         memset(&mbp_priv, 0, sizeof(mbp_priv));
      99                 :          0 :         mbp_priv.mbuf_data_room_size = (buf_sz - first_skip +
     100                 :            :                                         RTE_PKTMBUF_HEADROOM);
     101                 :          0 :         rte_pktmbuf_pool_init(mp, &mbp_priv);
     102                 :            : 
     103                 :            :         /* Populate buffer */
     104                 :          0 :         rc = rte_mempool_populate_default(mp);
     105         [ #  # ]:          0 :         if (rc < 0) {
     106                 :          0 :                 plt_err("Failed to create inline meta pool, rc=%d", rc);
     107                 :          0 :                 goto free_mp;
     108                 :            :         }
     109                 :            : 
     110                 :          0 :         rte_mempool_obj_iter(mp, rte_pktmbuf_init, NULL);
     111                 :          0 :         *aura_handle = mp->pool_id;
     112                 :          0 :         *mpool = (uintptr_t)mp;
     113                 :          0 :         return 0;
     114                 :          0 : free_mp:
     115                 :          0 :         rte_mempool_free(mp);
     116                 :          0 :         return rc;
     117                 :            : }
     118                 :            : 
     119                 :            : /* Create Aura and link with Global mempool for 1:N Pool:Aura case */
     120                 :            : int
     121                 :          0 : cnxk_nix_inl_custom_meta_pool_cb(uintptr_t pmpool, uintptr_t *mpool, const char *mempool_name,
     122                 :            :                                  uint64_t *aura_handle, uint32_t buf_sz, uint32_t nb_bufs,
     123                 :            :                                  bool destroy)
     124                 :            : {
     125                 :            :         struct rte_mempool *hp;
     126                 :            :         int rc;
     127                 :            : 
     128                 :            :         /* Destroy the mempool if requested */
     129         [ #  # ]:          0 :         if (destroy) {
     130                 :          0 :                 hp = rte_mempool_lookup(mempool_name);
     131         [ #  # ]:          0 :                 if (!hp)
     132                 :            :                         return -ENOENT;
     133                 :            : 
     134         [ #  # ]:          0 :                 if (hp->pool_id != *aura_handle) {
     135                 :          0 :                         plt_err("Meta pool aura mismatch");
     136                 :          0 :                         return -EINVAL;
     137                 :            :                 }
     138                 :            : 
     139                 :          0 :                 rte_mempool_free(hp);
     140                 :          0 :                 plt_free(hp->pool_config);
     141                 :            : 
     142                 :          0 :                 *aura_handle = 0;
     143                 :          0 :                 *mpool = 0;
     144                 :          0 :                 return 0;
     145                 :            :         }
     146                 :            : 
     147                 :            :         /* Need to make it similar to rte_pktmbuf_pool() for sake of OOP
     148                 :            :          * support.
     149                 :            :          */
     150                 :          0 :         hp = rte_mempool_create_empty(mempool_name, nb_bufs, buf_sz, 0,
     151                 :            :                                       sizeof(struct rte_pktmbuf_pool_private),
     152                 :            :                                       SOCKET_ID_ANY, 0);
     153         [ #  # ]:          0 :         if (!hp) {
     154                 :          0 :                 plt_err("Failed to create inline meta pool");
     155                 :          0 :                 return -EIO;
     156                 :            :         }
     157                 :            : 
     158                 :          0 :         rc = rte_mempool_set_ops_byname(hp, CN10K_HW_POOL_OPS_NAME, (void *)pmpool);
     159                 :            : 
     160         [ #  # ]:          0 :         if (rc) {
     161                 :          0 :                 plt_err("Failed to setup ops, rc=%d", rc);
     162                 :          0 :                 goto free_hp;
     163                 :            :         }
     164                 :            : 
     165                 :            :         /* Populate buffer */
     166                 :          0 :         rc = rte_mempool_populate_default(hp);
     167         [ #  # ]:          0 :         if (rc < 0) {
     168                 :          0 :                 plt_err("Failed to populate pool, rc=%d", rc);
     169                 :          0 :                 goto free_hp;
     170                 :            :         }
     171                 :            : 
     172                 :          0 :         *aura_handle = hp->pool_id;
     173                 :          0 :         *mpool = (uintptr_t)hp;
     174                 :          0 :         return 0;
     175                 :          0 : free_hp:
     176                 :          0 :         rte_mempool_free(hp);
     177                 :          0 :         return rc;
     178                 :            : }
     179                 :            : 
     180                 :            : static int
     181                 :          0 : parse_max_ipsec_rules(const char *key, const char *value, void *extra_args)
     182                 :            : {
     183                 :            :         RTE_SET_USED(key);
     184                 :            :         uint32_t val;
     185                 :            : 
     186                 :          0 :         val = atoi(value);
     187                 :            : 
     188         [ #  # ]:          0 :         if (val < 1 || val > 4095)
     189                 :            :                 return -EINVAL;
     190                 :            : 
     191                 :          0 :         *(uint32_t *)extra_args = val;
     192                 :            : 
     193                 :          0 :         return 0;
     194                 :            : }
     195                 :            : 
     196                 :            : static int
     197                 :          0 : parse_inl_rx_inj_ena(const char *key, const char *value, void *extra_args)
     198                 :            : {
     199                 :            :         RTE_SET_USED(key);
     200                 :            :         uint32_t val;
     201                 :            : 
     202                 :          0 :         val = atoi(value);
     203                 :            : 
     204                 :          0 :         *(uint8_t *)extra_args = !!(val == 1);
     205                 :            : 
     206                 :          0 :         return 0;
     207                 :            : }
     208                 :            : 
     209                 :            : int
     210                 :          0 : cnxk_eth_outb_sa_idx_get(struct cnxk_eth_dev *dev, uint32_t *idx_p,
     211                 :            :                          uint32_t spi)
     212                 :            : {
     213                 :            :         uint32_t pos, idx;
     214                 :            :         uint64_t slab;
     215                 :            :         int rc;
     216                 :            : 
     217         [ #  # ]:          0 :         if (!dev->outb.sa_bmap)
     218                 :            :                 return -ENOTSUP;
     219                 :            : 
     220                 :          0 :         pos = 0;
     221         [ #  # ]:          0 :         slab = 0;
     222                 :            :         /* Scan from the beginning */
     223                 :            :         plt_bitmap_scan_init(dev->outb.sa_bmap);
     224                 :            : 
     225         [ #  # ]:          0 :         if (dev->nix.custom_sa_action) {
     226         [ #  # ]:          0 :                 if (spi > dev->outb.max_sa)
     227                 :            :                         return -ENOTSUP;
     228                 :            :                 idx = spi;
     229                 :            :         } else {
     230                 :            :                 /* Scan bitmap to get the free sa index */
     231                 :          0 :                 rc = plt_bitmap_scan(dev->outb.sa_bmap, &pos, &slab);
     232                 :            :                 /* Empty bitmap */
     233         [ #  # ]:          0 :                 if (rc == 0) {
     234                 :          0 :                         plt_err("Outbound SA' exhausted, use 'ipsec_out_max_sa' "
     235                 :            :                                 "devargs to increase");
     236                 :          0 :                         return -ERANGE;
     237                 :            :                 }
     238                 :            : 
     239                 :            :                 /* Get free SA index */
     240         [ #  # ]:          0 :                 idx = pos + bitmap_ctzll(slab);
     241                 :            :         }
     242                 :          0 :         plt_bitmap_clear(dev->outb.sa_bmap, idx);
     243                 :          0 :         *idx_p = idx;
     244                 :          0 :         return 0;
     245                 :            : }
     246                 :            : 
     247                 :            : int
     248                 :          0 : cnxk_eth_outb_sa_idx_put(struct cnxk_eth_dev *dev, uint32_t idx)
     249                 :            : {
     250         [ #  # ]:          0 :         if (idx >= dev->outb.max_sa)
     251                 :            :                 return -EINVAL;
     252                 :            : 
     253                 :            :         /* Check if it is already free */
     254         [ #  # ]:          0 :         if (plt_bitmap_get(dev->outb.sa_bmap, idx))
     255                 :            :                 return -EINVAL;
     256                 :            : 
     257                 :            :         /* Mark index as free */
     258                 :          0 :         plt_bitmap_set(dev->outb.sa_bmap, idx);
     259                 :          0 :         return 0;
     260                 :            : }
     261                 :            : 
     262                 :            : struct cnxk_eth_sec_sess *
     263                 :          0 : cnxk_eth_sec_sess_get_by_spi(struct cnxk_eth_dev *dev, uint32_t spi, bool inb)
     264                 :            : {
     265                 :            :         struct cnxk_eth_sec_sess_list *list;
     266                 :            :         struct cnxk_eth_sec_sess *eth_sec;
     267                 :            : 
     268         [ #  # ]:          0 :         list = inb ? &dev->inb.list : &dev->outb.list;
     269         [ #  # ]:          0 :         TAILQ_FOREACH(eth_sec, list, entry) {
     270         [ #  # ]:          0 :                 if (eth_sec->spi == spi)
     271                 :          0 :                         return eth_sec;
     272                 :            :         }
     273                 :            : 
     274                 :            :         return NULL;
     275                 :            : }
     276                 :            : 
     277                 :            : struct cnxk_eth_sec_sess *
     278                 :          0 : cnxk_eth_sec_sess_get_by_sess(struct cnxk_eth_dev *dev,
     279                 :            :                               struct rte_security_session *sess)
     280                 :            : {
     281                 :            :         struct cnxk_eth_sec_sess *eth_sec = NULL;
     282                 :            : 
     283                 :            :         /* Search in inbound list */
     284         [ #  # ]:          0 :         TAILQ_FOREACH(eth_sec, &dev->inb.list, entry) {
     285         [ #  # ]:          0 :                 if (eth_sec->sess == sess)
     286                 :          0 :                         return eth_sec;
     287                 :            :         }
     288                 :            : 
     289                 :            :         /* Search in outbound list */
     290         [ #  # ]:          0 :         TAILQ_FOREACH(eth_sec, &dev->outb.list, entry) {
     291         [ #  # ]:          0 :                 if (eth_sec->sess == sess)
     292                 :          0 :                         return eth_sec;
     293                 :            :         }
     294                 :            : 
     295                 :            :         return NULL;
     296                 :            : }
     297                 :            : 
     298                 :            : static unsigned int
     299                 :          0 : cnxk_eth_sec_session_get_size(void *device __rte_unused)
     300                 :            : {
     301                 :          0 :         return RTE_MAX(sizeof(struct cnxk_macsec_sess), sizeof(struct cnxk_eth_sec_sess));
     302                 :            : }
     303                 :            : 
     304                 :            : struct rte_security_ops cnxk_eth_sec_ops = {
     305                 :            :         .session_get_size = cnxk_eth_sec_session_get_size
     306                 :            : };
     307                 :            : 
     308                 :            : static int
     309                 :          0 : parse_val_u32(const char *key, const char *value, void *extra_args)
     310                 :            : {
     311                 :            :         RTE_SET_USED(key);
     312                 :            :         uint32_t val;
     313                 :            : 
     314                 :          0 :         errno = 0;
     315                 :          0 :         val = strtoul(value, NULL, 0);
     316         [ #  # ]:          0 :         if (errno)
     317                 :            :                 val = 0;
     318                 :            : 
     319                 :          0 :         *(uint32_t *)extra_args = val;
     320                 :            : 
     321                 :          0 :         return 0;
     322                 :            : }
     323                 :            : 
     324                 :            : static int
     325                 :          0 : parse_selftest(const char *key, const char *value, void *extra_args)
     326                 :            : {
     327                 :            :         RTE_SET_USED(key);
     328                 :            :         uint32_t val;
     329                 :            : 
     330                 :          0 :         val = atoi(value);
     331                 :            : 
     332                 :          0 :         *(uint8_t *)extra_args = !!(val == 1);
     333                 :          0 :         return 0;
     334                 :            : }
     335                 :            : 
     336                 :            : static int
     337                 :          0 : parse_inl_cpt_channel(const char *key, const char *value, void *extra_args)
     338                 :            : {
     339                 :            :         RTE_SET_USED(key);
     340                 :            :         uint16_t chan = 0, mask = 0;
     341                 :          0 :         char *next = 0;
     342                 :            : 
     343                 :            :         /* next will point to the separator '/' */
     344                 :          0 :         chan = strtol(value, &next, 16);
     345                 :          0 :         mask = strtol(++next, 0, 16);
     346                 :            : 
     347         [ #  # ]:          0 :         if (chan > GENMASK(12, 0) || mask > GENMASK(12, 0))
     348                 :            :                 return -EINVAL;
     349                 :            : 
     350                 :          0 :         ((struct inl_cpt_channel *)extra_args)->channel = chan;
     351                 :          0 :         ((struct inl_cpt_channel *)extra_args)->mask = mask;
     352                 :          0 :         ((struct inl_cpt_channel *)extra_args)->is_multi_channel = true;
     353                 :            : 
     354                 :          0 :         return 0;
     355                 :            : }
     356                 :            : 
     357                 :            : static int
     358                 :          0 : nix_inl_parse_devargs(struct rte_devargs *devargs,
     359                 :            :                       struct roc_nix_inl_dev *inl_dev)
     360                 :            : {
     361                 :          0 :         uint32_t soft_exp_poll_freq = CNXK_NIX_SOFT_EXP_POLL_FREQ_DFLT;
     362                 :          0 :         uint32_t ipsec_in_max_spi = BIT(8) - 1;
     363                 :          0 :         uint32_t ipsec_in_min_spi = 0;
     364                 :            :         struct inl_cpt_channel cpt_channel;
     365                 :          0 :         uint32_t max_ipsec_rules = 0;
     366                 :            :         struct rte_kvargs *kvlist;
     367                 :          0 :         uint32_t nb_meta_bufs = 0;
     368                 :          0 :         uint32_t meta_buf_sz = 0;
     369                 :          0 :         uint8_t rx_inj_ena = 0;
     370         [ #  # ]:          0 :         uint8_t selftest = 0;
     371                 :            : 
     372                 :            :         memset(&cpt_channel, 0, sizeof(cpt_channel));
     373                 :            : 
     374         [ #  # ]:          0 :         if (devargs == NULL)
     375                 :          0 :                 goto null_devargs;
     376                 :            : 
     377                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, NULL);
     378         [ #  # ]:          0 :         if (kvlist == NULL)
     379                 :          0 :                 goto exit;
     380                 :            : 
     381                 :          0 :         rte_kvargs_process(kvlist, CNXK_NIX_INL_SELFTEST, &parse_selftest,
     382                 :            :                            &selftest);
     383                 :          0 :         rte_kvargs_process(kvlist, CNXK_NIX_INL_IPSEC_IN_MIN_SPI,
     384                 :            :                            &parse_val_u32, &ipsec_in_min_spi);
     385                 :          0 :         rte_kvargs_process(kvlist, CNXK_NIX_INL_IPSEC_IN_MAX_SPI,
     386                 :            :                            &parse_val_u32, &ipsec_in_max_spi);
     387                 :          0 :         rte_kvargs_process(kvlist, CNXK_INL_CPT_CHANNEL, &parse_inl_cpt_channel,
     388                 :            :                            &cpt_channel);
     389                 :          0 :         rte_kvargs_process(kvlist, CNXK_NIX_INL_NB_META_BUFS, &parse_val_u32,
     390                 :            :                            &nb_meta_bufs);
     391                 :          0 :         rte_kvargs_process(kvlist, CNXK_NIX_INL_META_BUF_SZ, &parse_val_u32,
     392                 :            :                            &meta_buf_sz);
     393                 :          0 :         rte_kvargs_process(kvlist, CNXK_NIX_SOFT_EXP_POLL_FREQ,
     394                 :            :                            &parse_val_u32, &soft_exp_poll_freq);
     395                 :          0 :         rte_kvargs_process(kvlist, CNXK_MAX_IPSEC_RULES, &parse_max_ipsec_rules, &max_ipsec_rules);
     396                 :          0 :         rte_kvargs_process(kvlist, CNXK_NIX_INL_RX_INJ_ENABLE, &parse_inl_rx_inj_ena, &rx_inj_ena);
     397                 :          0 :         rte_kvargs_free(kvlist);
     398                 :            : 
     399                 :          0 : null_devargs:
     400                 :          0 :         inl_dev->ipsec_in_min_spi = ipsec_in_min_spi;
     401                 :          0 :         inl_dev->ipsec_in_max_spi = ipsec_in_max_spi;
     402                 :          0 :         inl_dev->selftest = selftest;
     403                 :          0 :         inl_dev->channel = cpt_channel.channel;
     404                 :          0 :         inl_dev->chan_mask = cpt_channel.mask;
     405                 :          0 :         inl_dev->is_multi_channel = cpt_channel.is_multi_channel;
     406                 :          0 :         inl_dev->nb_meta_bufs = nb_meta_bufs;
     407                 :          0 :         inl_dev->meta_buf_sz = meta_buf_sz;
     408                 :          0 :         inl_dev->soft_exp_poll_freq = soft_exp_poll_freq;
     409         [ #  # ]:          0 :         inl_dev->max_ipsec_rules = max_ipsec_rules;
     410         [ #  # ]:          0 :         if (roc_feature_nix_has_rx_inject())
     411                 :          0 :                 inl_dev->rx_inj_ena = rx_inj_ena;
     412                 :            :         return 0;
     413                 :            : exit:
     414                 :          0 :         return -EINVAL;
     415                 :            : }
     416                 :            : 
     417                 :            : static inline char *
     418                 :          0 : nix_inl_dev_to_name(struct rte_pci_device *pci_dev, char *name)
     419                 :            : {
     420                 :          0 :         snprintf(name, CNXK_NIX_INL_DEV_NAME_LEN,
     421                 :            :                  CNXK_NIX_INL_DEV_NAME PCI_PRI_FMT, pci_dev->addr.domain,
     422                 :          0 :                  pci_dev->addr.bus, pci_dev->addr.devid,
     423                 :          0 :                  pci_dev->addr.function);
     424                 :            : 
     425                 :          0 :         return name;
     426                 :            : }
     427                 :            : 
     428                 :            : static int
     429                 :          0 : cnxk_nix_inl_dev_remove(struct rte_pci_device *pci_dev)
     430                 :            : {
     431                 :            :         char name[CNXK_NIX_INL_DEV_NAME_LEN];
     432                 :            :         const struct rte_memzone *mz;
     433                 :            :         struct roc_nix_inl_dev *dev;
     434                 :            :         int rc;
     435                 :            : 
     436         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     437                 :            :                 return 0;
     438                 :            : 
     439                 :          0 :         mz = rte_memzone_lookup(nix_inl_dev_to_name(pci_dev, name));
     440         [ #  # ]:          0 :         if (!mz)
     441                 :            :                 return 0;
     442                 :            : 
     443                 :          0 :         dev = mz->addr;
     444                 :            : 
     445                 :            :         /* Cleanup inline dev */
     446                 :          0 :         rc = roc_nix_inl_dev_fini(dev);
     447         [ #  # ]:          0 :         if (rc) {
     448                 :          0 :                 plt_err("Failed to cleanup inl dev, rc=%d(%s)", rc,
     449                 :            :                         roc_error_msg_get(rc));
     450                 :          0 :                 return rc;
     451                 :            :         }
     452                 :            : 
     453                 :          0 :         rte_memzone_free(mz);
     454                 :          0 :         return 0;
     455                 :            : }
     456                 :            : 
     457                 :            : static int
     458                 :          0 : cnxk_nix_inl_dev_probe(struct rte_pci_driver *pci_drv,
     459                 :            :                        struct rte_pci_device *pci_dev)
     460                 :            : {
     461                 :            :         char name[CNXK_NIX_INL_DEV_NAME_LEN];
     462                 :            :         struct roc_nix_inl_dev *inl_dev;
     463                 :            :         const struct rte_memzone *mz;
     464                 :            :         uint16_t wqe_skip;
     465                 :            :         int rc = -ENOMEM;
     466                 :            : 
     467                 :            :         RTE_SET_USED(pci_drv);
     468                 :            : 
     469                 :          0 :         rc = roc_plt_init();
     470         [ #  # ]:          0 :         if (rc) {
     471                 :          0 :                 plt_err("Failed to initialize platform model, rc=%d", rc);
     472                 :          0 :                 return rc;
     473                 :            :         }
     474                 :            : 
     475         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     476                 :            :                 return 0;
     477                 :            : 
     478                 :          0 :         mz = rte_memzone_reserve_aligned(nix_inl_dev_to_name(pci_dev, name),
     479                 :            :                                          sizeof(*inl_dev), SOCKET_ID_ANY, 0,
     480                 :            :                                          RTE_CACHE_LINE_SIZE);
     481         [ #  # ]:          0 :         if (mz == NULL)
     482                 :            :                 return rc;
     483                 :            : 
     484                 :          0 :         inl_dev = mz->addr;
     485                 :          0 :         inl_dev->pci_dev = pci_dev;
     486                 :            : 
     487                 :            :         /* Parse devargs string */
     488                 :          0 :         rc = nix_inl_parse_devargs(pci_dev->device.devargs, inl_dev);
     489         [ #  # ]:          0 :         if (rc) {
     490                 :          0 :                 plt_err("Failed to parse devargs rc=%d", rc);
     491                 :          0 :                 goto free_mem;
     492                 :            :         }
     493                 :            : 
     494                 :          0 :         inl_dev->attach_cptlf = true;
     495                 :            :         /* WQE skip is one for DPDK */
     496                 :            :         wqe_skip = RTE_ALIGN_CEIL(sizeof(struct rte_mbuf), ROC_CACHE_LINE_SZ);
     497                 :            :         wqe_skip = wqe_skip / ROC_CACHE_LINE_SZ;
     498                 :          0 :         inl_dev->wqe_skip = wqe_skip;
     499                 :          0 :         rc = roc_nix_inl_dev_init(inl_dev);
     500         [ #  # ]:          0 :         if (rc) {
     501                 :          0 :                 plt_err("Failed to init nix inl device, rc=%d(%s)", rc,
     502                 :            :                         roc_error_msg_get(rc));
     503                 :          0 :                 goto free_mem;
     504                 :            :         }
     505                 :            : 
     506                 :            :         return 0;
     507                 :          0 : free_mem:
     508                 :          0 :         rte_memzone_free(mz);
     509                 :          0 :         return rc;
     510                 :            : }
     511                 :            : 
     512                 :            : static const struct rte_pci_id cnxk_nix_inl_pci_map[] = {
     513                 :            :         {RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CNXK_RVU_NIX_INL_PF)},
     514                 :            :         {RTE_PCI_DEVICE(PCI_VENDOR_ID_CAVIUM, PCI_DEVID_CNXK_RVU_NIX_INL_VF)},
     515                 :            :         {
     516                 :            :                 .vendor_id = 0,
     517                 :            :         },
     518                 :            : };
     519                 :            : 
     520                 :            : static struct rte_pci_driver cnxk_nix_inl_pci = {
     521                 :            :         .id_table = cnxk_nix_inl_pci_map,
     522                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING | RTE_PCI_DRV_NEED_IOVA_AS_VA,
     523                 :            :         .probe = cnxk_nix_inl_dev_probe,
     524                 :            :         .remove = cnxk_nix_inl_dev_remove,
     525                 :            : };
     526                 :            : 
     527                 :        238 : RTE_PMD_REGISTER_PCI(cnxk_nix_inl, cnxk_nix_inl_pci);
     528                 :            : RTE_PMD_REGISTER_PCI_TABLE(cnxk_nix_inl, cnxk_nix_inl_pci_map);
     529                 :            : RTE_PMD_REGISTER_KMOD_DEP(cnxk_nix_inl, "vfio-pci");
     530                 :            : 
     531                 :            : RTE_PMD_REGISTER_PARAM_STRING(cnxk_nix_inl,
     532                 :            :                               CNXK_NIX_INL_SELFTEST "=1"
     533                 :            :                               CNXK_NIX_INL_IPSEC_IN_MIN_SPI "=<1-U32_MAX>"
     534                 :            :                               CNXK_NIX_INL_IPSEC_IN_MAX_SPI "=<1-U32_MAX>"
     535                 :            :                               CNXK_INL_CPT_CHANNEL "=<1-4095>/<1-4095>"
     536                 :            :                               CNXK_NIX_INL_NB_META_BUFS "=<1-U32_MAX>"
     537                 :            :                               CNXK_NIX_INL_META_BUF_SZ "=<1-U32_MAX>"
     538                 :            :                               CNXK_NIX_SOFT_EXP_POLL_FREQ "=<0-U32_MAX>"
     539                 :            :                               CNXK_MAX_IPSEC_RULES "=<1-4095>"
     540                 :            :                               CNXK_NIX_INL_RX_INJ_ENABLE "=1");

Generated by: LCOV version 1.14