LCOV - code coverage report
Current view: top level - drivers/net/cnxk - cn20k_ethdev_sec.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 433 0.0 %
Date: 2026-04-01 20:02:27 Functions: 0 15 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 273 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2024 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_cryptodev.h>
       6                 :            : #include <rte_eventdev.h>
       7                 :            : #include <rte_pmd_cnxk.h>
       8                 :            : #include <rte_security.h>
       9                 :            : #include <rte_security_driver.h>
      10                 :            : 
      11                 :            : #include <cn20k_ethdev.h>
      12                 :            : #include <cn20k_rx.h>
      13                 :            : #include <cnxk_security.h>
      14                 :            : #include <roc_priv.h>
      15                 :            : 
      16                 :            : PLT_STATIC_ASSERT(offsetof(struct rte_pmd_cnxk_ipsec_inb_sa, ctx.ar_winbits) ==
      17                 :            :                   offsetof(struct roc_ow_ipsec_inb_sa, ctx.ar_winbits));
      18                 :            : 
      19                 :            : PLT_STATIC_ASSERT(offsetof(struct rte_pmd_cnxk_ipsec_outb_sa, ctx.mib_pkts) ==
      20                 :            :                   offsetof(struct roc_ow_ipsec_outb_sa, ctx.mib_pkts));
      21                 :            : 
      22                 :            : PLT_STATIC_ASSERT(RTE_PMD_CNXK_CTX_MAX_CKEY_LEN == ROC_CTX_MAX_CKEY_LEN);
      23                 :            : PLT_STATIC_ASSERT(RTE_PMD_CNXK_CTX_MAX_OPAD_IPAD_LEN == RTE_PMD_CNXK_CTX_MAX_OPAD_IPAD_LEN);
      24                 :            : 
      25                 :            : PLT_STATIC_ASSERT(RTE_PMD_CNXK_AR_WIN_SIZE_MIN == ROC_AR_WIN_SIZE_MIN);
      26                 :            : PLT_STATIC_ASSERT(RTE_PMD_CNXK_AR_WIN_SIZE_MAX == ROC_AR_WIN_SIZE_MAX);
      27                 :            : PLT_STATIC_ASSERT(RTE_PMD_CNXK_LOG_MIN_AR_WIN_SIZE_M1 == ROC_LOG_MIN_AR_WIN_SIZE_M1);
      28                 :            : PLT_STATIC_ASSERT(RTE_PMD_CNXK_AR_WINBITS_SZ == ROC_AR_WINBITS_SZ);
      29                 :            : 
      30                 :            : static struct rte_cryptodev_capabilities cn20k_eth_sec_crypto_caps[] = {
      31                 :            :         {       /* AES GCM */
      32                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
      33                 :            :                 {.sym = {
      34                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
      35                 :            :                         {.aead = {
      36                 :            :                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
      37                 :            :                                 .block_size = 16,
      38                 :            :                                 .key_size = {
      39                 :            :                                         .min = 16,
      40                 :            :                                         .max = 32,
      41                 :            :                                         .increment = 8
      42                 :            :                                 },
      43                 :            :                                 .digest_size = {
      44                 :            :                                         .min = 16,
      45                 :            :                                         .max = 16,
      46                 :            :                                         .increment = 0
      47                 :            :                                 },
      48                 :            :                                 .aad_size = {
      49                 :            :                                         .min = 8,
      50                 :            :                                         .max = 12,
      51                 :            :                                         .increment = 4
      52                 :            :                                 },
      53                 :            :                                 .iv_size = {
      54                 :            :                                         .min = 12,
      55                 :            :                                         .max = 12,
      56                 :            :                                         .increment = 0
      57                 :            :                                 }
      58                 :            :                         }, }
      59                 :            :                 }, }
      60                 :            :         },
      61                 :            :         {       /* AES CBC */
      62                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
      63                 :            :                 {.sym = {
      64                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
      65                 :            :                         {.cipher = {
      66                 :            :                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
      67                 :            :                                 .block_size = 16,
      68                 :            :                                 .key_size = {
      69                 :            :                                         .min = 16,
      70                 :            :                                         .max = 32,
      71                 :            :                                         .increment = 8
      72                 :            :                                 },
      73                 :            :                                 .iv_size = {
      74                 :            :                                         .min = 16,
      75                 :            :                                         .max = 16,
      76                 :            :                                         .increment = 0
      77                 :            :                                 }
      78                 :            :                         }, }
      79                 :            :                 }, }
      80                 :            :         },
      81                 :            :         {       /* AES CTR */
      82                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
      83                 :            :                 {.sym = {
      84                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
      85                 :            :                         {.cipher = {
      86                 :            :                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
      87                 :            :                                 .block_size = 16,
      88                 :            :                                 .key_size = {
      89                 :            :                                         .min = 16,
      90                 :            :                                         .max = 32,
      91                 :            :                                         .increment = 8
      92                 :            :                                 },
      93                 :            :                                 .iv_size = {
      94                 :            :                                         .min = 12,
      95                 :            :                                         .max = 16,
      96                 :            :                                         .increment = 4
      97                 :            :                                 }
      98                 :            :                         }, }
      99                 :            :                 }, }
     100                 :            :         },
     101                 :            :         {       /* 3DES CBC */
     102                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     103                 :            :                 {.sym = {
     104                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
     105                 :            :                         {.cipher = {
     106                 :            :                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
     107                 :            :                                 .block_size = 8,
     108                 :            :                                 .key_size = {
     109                 :            :                                         .min = 24,
     110                 :            :                                         .max = 24,
     111                 :            :                                         .increment = 0
     112                 :            :                                 },
     113                 :            :                                 .iv_size = {
     114                 :            :                                         .min = 8,
     115                 :            :                                         .max = 16,
     116                 :            :                                         .increment = 8
     117                 :            :                                 }
     118                 :            :                         }, }
     119                 :            :                 }, }
     120                 :            :         },
     121                 :            :         {       /* AES-XCBC */
     122                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     123                 :            :                 { .sym = {
     124                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     125                 :            :                         {.auth = {
     126                 :            :                                 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
     127                 :            :                                 .block_size = 16,
     128                 :            :                                 .key_size = {
     129                 :            :                                         .min = 16,
     130                 :            :                                         .max = 16,
     131                 :            :                                         .increment = 0
     132                 :            :                                 },
     133                 :            :                                 .digest_size = {
     134                 :            :                                         .min = 12,
     135                 :            :                                         .max = 12,
     136                 :            :                                         .increment = 0,
     137                 :            :                                 },
     138                 :            :                         }, }
     139                 :            :                 }, }
     140                 :            :         },
     141                 :            :         {       /* SHA1 HMAC */
     142                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     143                 :            :                 {.sym = {
     144                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     145                 :            :                         {.auth = {
     146                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
     147                 :            :                                 .block_size = 64,
     148                 :            :                                 .key_size = {
     149                 :            :                                         .min = 20,
     150                 :            :                                         .max = 64,
     151                 :            :                                         .increment = 1
     152                 :            :                                 },
     153                 :            :                                 .digest_size = {
     154                 :            :                                         .min = 12,
     155                 :            :                                         .max = 12,
     156                 :            :                                         .increment = 0
     157                 :            :                                 },
     158                 :            :                         }, }
     159                 :            :                 }, }
     160                 :            :         },
     161                 :            :         {       /* SHA256 HMAC */
     162                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     163                 :            :                 {.sym = {
     164                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     165                 :            :                         {.auth = {
     166                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
     167                 :            :                                 .block_size = 64,
     168                 :            :                                 .key_size = {
     169                 :            :                                         .min = 1,
     170                 :            :                                         .max = 1024,
     171                 :            :                                         .increment = 1
     172                 :            :                                 },
     173                 :            :                                 .digest_size = {
     174                 :            :                                         .min = 16,
     175                 :            :                                         .max = 32,
     176                 :            :                                         .increment = 16
     177                 :            :                                 },
     178                 :            :                         }, }
     179                 :            :                 }, }
     180                 :            :         },
     181                 :            :         {       /* SHA384 HMAC */
     182                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     183                 :            :                 {.sym = {
     184                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     185                 :            :                         {.auth = {
     186                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
     187                 :            :                                 .block_size = 64,
     188                 :            :                                 .key_size = {
     189                 :            :                                         .min = 1,
     190                 :            :                                         .max = 1024,
     191                 :            :                                         .increment = 1
     192                 :            :                                 },
     193                 :            :                                 .digest_size = {
     194                 :            :                                         .min = 24,
     195                 :            :                                         .max = 48,
     196                 :            :                                         .increment = 24
     197                 :            :                                         },
     198                 :            :                         }, }
     199                 :            :                 }, }
     200                 :            :         },
     201                 :            :         {       /* SHA512 HMAC */
     202                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     203                 :            :                 {.sym = {
     204                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     205                 :            :                         {.auth = {
     206                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
     207                 :            :                                 .block_size = 128,
     208                 :            :                                 .key_size = {
     209                 :            :                                         .min = 1,
     210                 :            :                                         .max = 1024,
     211                 :            :                                         .increment = 1
     212                 :            :                                 },
     213                 :            :                                 .digest_size = {
     214                 :            :                                         .min = 32,
     215                 :            :                                         .max = 64,
     216                 :            :                                         .increment = 32
     217                 :            :                                 },
     218                 :            :                         }, }
     219                 :            :                 }, }
     220                 :            :         },
     221                 :            :         {       /* AES GMAC (AUTH) */
     222                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     223                 :            :                 {.sym = {
     224                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     225                 :            :                         {.auth = {
     226                 :            :                                 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
     227                 :            :                                 .block_size = 16,
     228                 :            :                                 .key_size = {
     229                 :            :                                         .min = 16,
     230                 :            :                                         .max = 32,
     231                 :            :                                         .increment = 8
     232                 :            :                                 },
     233                 :            :                                 .digest_size = {
     234                 :            :                                         .min = 8,
     235                 :            :                                         .max = 16,
     236                 :            :                                         .increment = 4
     237                 :            :                                 },
     238                 :            :                                 .iv_size = {
     239                 :            :                                         .min = 12,
     240                 :            :                                         .max = 12,
     241                 :            :                                         .increment = 0
     242                 :            :                                 }
     243                 :            :                         }, }
     244                 :            :                 }, }
     245                 :            :         },
     246                 :            :         {       /* AES CCM */
     247                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     248                 :            :                 {.sym = {
     249                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
     250                 :            :                         {.aead = {
     251                 :            :                                 .algo = RTE_CRYPTO_AEAD_AES_CCM,
     252                 :            :                                 .block_size = 16,
     253                 :            :                                 .key_size = {
     254                 :            :                                         .min = 16,
     255                 :            :                                         .max = 32,
     256                 :            :                                         .increment = 8
     257                 :            :                                 },
     258                 :            :                                 .digest_size = {
     259                 :            :                                         .min = 16,
     260                 :            :                                         .max = 16,
     261                 :            :                                         .increment = 0
     262                 :            :                                 },
     263                 :            :                                 .aad_size = {
     264                 :            :                                         .min = 8,
     265                 :            :                                         .max = 12,
     266                 :            :                                         .increment = 4
     267                 :            :                                 },
     268                 :            :                                 .iv_size = {
     269                 :            :                                         .min = 11,
     270                 :            :                                         .max = 13,
     271                 :            :                                         .increment = 1
     272                 :            :                                 }
     273                 :            :                         }, }
     274                 :            :                 }, }
     275                 :            :         },
     276                 :            :         {       /* NULL (AUTH) */
     277                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     278                 :            :                 {.sym = {
     279                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     280                 :            :                         {.auth = {
     281                 :            :                                 .algo = RTE_CRYPTO_AUTH_NULL,
     282                 :            :                                 .block_size = 1,
     283                 :            :                                 .key_size = {
     284                 :            :                                         .min = 0,
     285                 :            :                                         .max = 0,
     286                 :            :                                         .increment = 0
     287                 :            :                                 },
     288                 :            :                                 .digest_size = {
     289                 :            :                                         .min = 0,
     290                 :            :                                         .max = 0,
     291                 :            :                                         .increment = 0
     292                 :            :                                 },
     293                 :            :                         }, },
     294                 :            :                 }, },
     295                 :            :         },
     296                 :            :         {       /* NULL (CIPHER) */
     297                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     298                 :            :                 {.sym = {
     299                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
     300                 :            :                         {.cipher = {
     301                 :            :                                 .algo = RTE_CRYPTO_CIPHER_NULL,
     302                 :            :                                 .block_size = 1,
     303                 :            :                                 .key_size = {
     304                 :            :                                         .min = 0,
     305                 :            :                                         .max = 0,
     306                 :            :                                         .increment = 0
     307                 :            :                                 },
     308                 :            :                                 .iv_size = {
     309                 :            :                                         .min = 0,
     310                 :            :                                         .max = 0,
     311                 :            :                                         .increment = 0
     312                 :            :                                 }
     313                 :            :                         }, },
     314                 :            :                 }, }
     315                 :            :         },
     316                 :            : 
     317                 :            :         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
     318                 :            : };
     319                 :            : 
     320                 :            : static const struct rte_security_capability cn20k_eth_sec_ipsec_capabilities[] = {
     321                 :            :         {       /* IPsec Inline Protocol ESP Tunnel Ingress */
     322                 :            :                 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
     323                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
     324                 :            :                 .ipsec = {
     325                 :            :                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
     326                 :            :                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
     327                 :            :                         .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
     328                 :            :                         .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
     329                 :            :                         .options = {
     330                 :            :                                 .udp_encap = 1,
     331                 :            :                                 .udp_ports_verify = 1,
     332                 :            :                                 .copy_df = 1,
     333                 :            :                                 .copy_dscp = 1,
     334                 :            :                                 .copy_flabel = 1,
     335                 :            :                                 .tunnel_hdr_verify = RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR,
     336                 :            :                                 .dec_ttl = 1,
     337                 :            :                                 .ip_csum_enable = 1,
     338                 :            :                                 .l4_csum_enable = 1,
     339                 :            :                                 .stats = 1,
     340                 :            :                                 .esn = 1,
     341                 :            :                                 .ingress_oop = 1,
     342                 :            :                         },
     343                 :            :                 },
     344                 :            :                 .crypto_capabilities = cn20k_eth_sec_crypto_caps,
     345                 :            :                 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
     346                 :            :         },
     347                 :            :         {       /* IPsec Inline Protocol ESP Tunnel Egress */
     348                 :            :                 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
     349                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
     350                 :            :                 .ipsec = {
     351                 :            :                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
     352                 :            :                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
     353                 :            :                         .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
     354                 :            :                         .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
     355                 :            :                         .options = {
     356                 :            :                                 .iv_gen_disable = 1,
     357                 :            :                                 .udp_encap = 1,
     358                 :            :                                 .udp_ports_verify = 1,
     359                 :            :                                 .copy_df = 1,
     360                 :            :                                 .copy_dscp = 1,
     361                 :            :                                 .copy_flabel = 1,
     362                 :            :                                 .dec_ttl = 1,
     363                 :            :                                 .ip_csum_enable = 1,
     364                 :            :                                 .l4_csum_enable = 1,
     365                 :            :                                 .stats = 1,
     366                 :            :                                 .esn = 1,
     367                 :            :                         },
     368                 :            :                 },
     369                 :            :                 .crypto_capabilities = cn20k_eth_sec_crypto_caps,
     370                 :            :                 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
     371                 :            :         },
     372                 :            :         {       /* IPsec Inline Protocol ESP Transport Egress */
     373                 :            :                 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
     374                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
     375                 :            :                 .ipsec = {
     376                 :            :                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
     377                 :            :                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
     378                 :            :                         .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
     379                 :            :                         .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
     380                 :            :                         .options = {
     381                 :            :                                 .iv_gen_disable = 1,
     382                 :            :                                 .udp_encap = 1,
     383                 :            :                                 .udp_ports_verify = 1,
     384                 :            :                                 .copy_df = 1,
     385                 :            :                                 .copy_dscp = 1,
     386                 :            :                                 .dec_ttl = 1,
     387                 :            :                                 .ip_csum_enable = 1,
     388                 :            :                                 .l4_csum_enable = 1,
     389                 :            :                                 .stats = 1,
     390                 :            :                                 .esn = 1,
     391                 :            :                                 .ingress_oop = 1,
     392                 :            :                         },
     393                 :            :                 },
     394                 :            :                 .crypto_capabilities = cn20k_eth_sec_crypto_caps,
     395                 :            :                 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
     396                 :            :         },
     397                 :            :         {       /* IPsec Inline Protocol ESP Transport Ingress */
     398                 :            :                 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
     399                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
     400                 :            :                 .ipsec = {
     401                 :            :                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
     402                 :            :                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT,
     403                 :            :                         .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
     404                 :            :                         .replay_win_sz_max = ROC_AR_WIN_SIZE_MAX,
     405                 :            :                         .options = {
     406                 :            :                                 .udp_encap = 1,
     407                 :            :                                 .udp_ports_verify = 1,
     408                 :            :                                 .copy_df = 1,
     409                 :            :                                 .copy_dscp = 1,
     410                 :            :                                 .dec_ttl = 1,
     411                 :            :                                 .ip_csum_enable = 1,
     412                 :            :                                 .l4_csum_enable = 1,
     413                 :            :                                 .stats = 1,
     414                 :            :                                 .esn = 1,
     415                 :            :                                 .ingress_oop = 1,
     416                 :            :                         },
     417                 :            :                 },
     418                 :            :                 .crypto_capabilities = cn20k_eth_sec_crypto_caps,
     419                 :            :                 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
     420                 :            :         },
     421                 :            : };
     422                 :            : 
     423                 :            : #define SEC_CAPS_LEN (RTE_DIM(cn20k_eth_sec_ipsec_capabilities) + 1)
     424                 :            : 
     425                 :            : static struct rte_security_capability cn20k_eth_sec_capabilities[SEC_CAPS_LEN];
     426                 :            : 
     427                 :            : static inline void
     428                 :            : cnxk_pktmbuf_free_no_cache(struct rte_mbuf *mbuf)
     429                 :            : {
     430                 :            :         struct rte_mbuf *next;
     431                 :            : 
     432   [ #  #  #  # ]:          0 :         if (!mbuf)
     433                 :            :                 return;
     434                 :            :         do {
     435                 :          0 :                 next = mbuf->next;
     436   [ #  #  #  # ]:          0 :                 roc_npa_aura_op_free(mbuf->pool->pool_id, 1, (rte_iova_t)mbuf);
     437                 :            :                 mbuf = next;
     438   [ #  #  #  # ]:          0 :         } while (mbuf != NULL);
     439                 :            : }
     440                 :            : 
     441                 :            : static void
     442         [ #  # ]:          0 : cn20k_eth_sec_post_event(struct rte_eth_dev *eth_dev, void *sa, enum nix_inl_event_type type,
     443                 :            :                          uint16_t uc_compcode, uint16_t compcode, struct rte_mbuf *mbuf)
     444                 :            : {
     445                 :            :         struct rte_eth_event_ipsec_desc desc;
     446                 :            :         struct cn20k_sec_sess_priv sess_priv;
     447                 :            :         struct cn20k_outb_priv_data *outb_priv;
     448                 :            :         struct cn20k_inb_priv_data *inb_priv;
     449                 :            :         static uint64_t warn_cnt;
     450                 :            :         uint64_t life_unit;
     451                 :            : 
     452                 :            :         memset(&desc, 0, sizeof(desc));
     453                 :          0 :         sess_priv.u64 = 0;
     454                 :            : 
     455         [ #  # ]:          0 :         if (type == NIX_INL_INB_CPT_CQ) {
     456                 :            :                 struct roc_ow_ipsec_inb_sa *inb_sa = (struct roc_ow_ipsec_inb_sa *)sa;
     457                 :            :                 inb_priv = roc_nix_inl_ow_ipsec_inb_sa_sw_rsvd(sa);
     458                 :          0 :                 desc.metadata = (uint64_t)inb_priv->userdata;
     459                 :          0 :                 life_unit = inb_sa->w2.s.life_unit;
     460                 :            :         } else {
     461                 :            :                 struct roc_ow_ipsec_outb_sa *outb_sa = (struct roc_ow_ipsec_outb_sa *)sa;
     462                 :            :                 outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(sa);
     463                 :          0 :                 desc.metadata = (uint64_t)outb_priv->userdata;
     464                 :          0 :                 life_unit = outb_sa->w2.s.life_unit;
     465                 :            :         }
     466                 :            : 
     467         [ #  # ]:          0 :         if (mbuf)
     468                 :          0 :                 sess_priv.u64 = *rte_security_dynfield(mbuf);
     469                 :            : 
     470   [ #  #  #  #  :          0 :         switch (uc_compcode) {
                      # ]
     471                 :          0 :         case ROC_IE_OW_UCC_ERR_SA_OVERFLOW:
     472                 :          0 :                 desc.subtype = RTE_ETH_EVENT_IPSEC_ESN_OVERFLOW;
     473                 :          0 :                 break;
     474                 :          0 :         case ROC_IE_OW_UCC_ERR_SA_EXPIRED:
     475         [ #  # ]:          0 :                 if (life_unit == ROC_IE_OW_SA_LIFE_UNIT_PKTS)
     476                 :          0 :                         desc.subtype = RTE_ETH_EVENT_IPSEC_SA_PKT_HARD_EXPIRY;
     477                 :            :                 else
     478                 :          0 :                         desc.subtype = RTE_ETH_EVENT_IPSEC_SA_BYTE_HARD_EXPIRY;
     479                 :            :                 break;
     480                 :          0 :         case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_FIRST:
     481                 :            :         case ROC_IE_OW_UCC_SUCCESS_SA_SOFTEXP_AGAIN:
     482         [ #  # ]:          0 :                 if (life_unit == ROC_IE_OW_SA_LIFE_UNIT_PKTS)
     483                 :          0 :                         desc.subtype = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
     484                 :            :                 else
     485                 :          0 :                         desc.subtype = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
     486                 :            :                 break;
     487                 :          0 :         case ROC_IE_OW_UCC_ERR_PKT_IP:
     488                 :          0 :                 warn_cnt++;
     489         [ #  # ]:          0 :                 if (warn_cnt % 10000 == 0)
     490                 :          0 :                         plt_warn("Outbound error, bad ip pkt, mbuf %p,"
     491                 :            :                                  "sa_index %u (total warnings %" PRIu64 ")",
     492                 :            :                                  mbuf, sess_priv.sa_idx, warn_cnt);
     493                 :          0 :                 desc.subtype = -uc_compcode;
     494                 :          0 :                 break;
     495                 :          0 :         default:
     496                 :          0 :                 warn_cnt++;
     497         [ #  # ]:          0 :                 if (warn_cnt % 10000 == 0)
     498                 :          0 :                         plt_warn("Outbound error, mbuf %p, sa_index %u,"
     499                 :            :                                  " compcode %x uc %x,"
     500                 :            :                                  " (total warnings %" PRIu64 ")",
     501                 :            :                                  mbuf, sess_priv.sa_idx, compcode, uc_compcode, warn_cnt);
     502                 :          0 :                 desc.subtype = -uc_compcode;
     503                 :          0 :                 break;
     504                 :            :         }
     505                 :            : 
     506                 :          0 :         rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_IPSEC, &desc);
     507                 :          0 : }
     508                 :            : 
     509                 :            : static const char *
     510                 :            : get_inl_event_type(enum nix_inl_event_type type)
     511                 :            : {
     512                 :          0 :         switch (type) {
     513                 :            :         case NIX_INL_OUTB_CPT_CQ:
     514                 :            :                 return "NIX_INL_OUTB_CPT_CQ";
     515                 :          0 :         case NIX_INL_INB_CPT_CQ:
     516                 :          0 :                 return "NIX_INL_INB_CPT_CQ";
     517                 :          0 :         case NIX_INL_SSO:
     518                 :          0 :                 return "NIX_INL_SSO";
     519                 :          0 :         case NIX_INL_SOFT_EXPIRY_THRD:
     520                 :          0 :                 return "NIX_INL_SOFT_EXPIRY_THRD";
     521                 :            : 
     522                 :          0 :         default:
     523                 :          0 :                 return "Unknown event";
     524                 :            :         }
     525                 :            : }
     526                 :            : 
     527                 :            : void
     528   [ #  #  #  #  :          0 : cn20k_eth_sec_sso_work_cb(uint64_t *gw, void *args, enum nix_inl_event_type type, void *cq_s,
                      # ]
     529                 :            :                           uint32_t port_id)
     530                 :            : {
     531                 :            :         struct rte_eth_event_ipsec_desc desc;
     532                 :            :         struct cn20k_sec_sess_priv sess_priv;
     533                 :            :         struct cn20k_outb_priv_data *outb_priv;
     534                 :            :         struct roc_ow_ipsec_outb_sa *outb_sa;
     535                 :            :         struct cpt_cn20k_res_s *res;
     536                 :            :         struct rte_eth_dev *eth_dev;
     537                 :            :         struct cnxk_eth_dev *dev;
     538                 :            :         uint16_t dlen_adj, rlen;
     539                 :            :         struct rte_mbuf *mbuf;
     540                 :            :         uintptr_t sa_base;
     541                 :            :         uintptr_t nixtx;
     542                 :            :         uint8_t port;
     543                 :            : 
     544                 :            :         RTE_SET_USED(args);
     545                 :          0 :         plt_nix_dbg("Received %s event", get_inl_event_type(type));
     546                 :            : 
     547      [ #  #  # ]:          0 :         switch ((gw[0] >> 28) & 0xF) {
     548                 :          0 :         case RTE_EVENT_TYPE_ETHDEV:
     549                 :            :                 /* Event from inbound inline dev due to IPSEC packet bad L4 */
     550                 :          0 :                 mbuf = (struct rte_mbuf *)(gw[1] - sizeof(struct rte_mbuf));
     551                 :          0 :                 plt_nix_dbg("Received mbuf %p from inline dev inbound", mbuf);
     552                 :            :                 cnxk_pktmbuf_free_no_cache(mbuf);
     553                 :          0 :                 return;
     554                 :          0 :         case RTE_EVENT_TYPE_CPU:
     555                 :            :                 /* Check for subtype */
     556         [ #  # ]:          0 :                 if (((gw[0] >> 20) & 0xFF) == CNXK_ETHDEV_SEC_OUTB_EV_SUB) {
     557                 :            :                         /* Event from outbound inline error */
     558                 :          0 :                         mbuf = (struct rte_mbuf *)gw[1];
     559                 :            :                         break;
     560                 :            :                 }
     561                 :            :                 /* Fall through */
     562                 :            :         default:
     563         [ #  # ]:          0 :                 if (type) {
     564                 :          0 :                         eth_dev = &rte_eth_devices[port_id];
     565                 :            :                         struct cpt_cq_s *cqs = (struct cpt_cq_s *)cq_s;
     566         [ #  # ]:          0 :                         if (type < NIX_INL_SSO) {
     567                 :          0 :                                 cn20k_eth_sec_post_event(eth_dev, args, type,
     568                 :          0 :                                                          (uint16_t)cqs->w0.s.uc_compcode,
     569                 :          0 :                                                          (uint16_t)cqs->w0.s.compcode, NULL);
     570                 :          0 :                                 return;
     571                 :            :                         }
     572         [ #  # ]:          0 :                         if (type == NIX_INL_SOFT_EXPIRY_THRD) {
     573                 :            :                                 outb_sa = (struct roc_ow_ipsec_outb_sa *)args;
     574                 :            :                                 outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(outb_sa);
     575                 :          0 :                                 desc.metadata = (uint64_t)outb_priv->userdata;
     576         [ #  # ]:          0 :                                 if (outb_sa->w2.s.life_unit == ROC_IE_OW_SA_LIFE_UNIT_PKTS)
     577                 :          0 :                                         desc.subtype = RTE_ETH_EVENT_IPSEC_SA_PKT_EXPIRY;
     578                 :            :                                 else
     579                 :          0 :                                         desc.subtype = RTE_ETH_EVENT_IPSEC_SA_BYTE_EXPIRY;
     580                 :            :                         }
     581                 :          0 :                         rte_eth_dev_callback_process(eth_dev, RTE_ETH_EVENT_IPSEC, &desc);
     582                 :            :                 } else {
     583                 :          0 :                         plt_err("Unknown event gw[0] = 0x%016lx, gw[1] = 0x%016lx", gw[0], gw[1]);
     584                 :            :                 }
     585                 :            :                 return;
     586                 :            :         }
     587                 :            : 
     588                 :            :         /* Get ethdev port from tag */
     589                 :          0 :         port = gw[0] & 0xFF;
     590                 :          0 :         eth_dev = &rte_eth_devices[port];
     591                 :            :         dev = cnxk_eth_pmd_priv(eth_dev);
     592                 :            : 
     593                 :          0 :         sess_priv.u64 = *rte_security_dynfield(mbuf);
     594                 :            :         /* Calculate dlen adj */
     595                 :          0 :         dlen_adj = mbuf->pkt_len - mbuf->l2_len;
     596                 :          0 :         rlen = (dlen_adj + sess_priv.roundup_len) + (sess_priv.roundup_byte - 1);
     597                 :          0 :         rlen &= ~(uint64_t)(sess_priv.roundup_byte - 1);
     598                 :          0 :         rlen += sess_priv.partial_len;
     599                 :          0 :         dlen_adj = rlen - dlen_adj;
     600                 :            : 
     601                 :            :         /* Find the res area residing on next cacheline after end of data */
     602                 :          0 :         nixtx = rte_pktmbuf_mtod(mbuf, uintptr_t) + mbuf->pkt_len + dlen_adj;
     603                 :            :         nixtx += BIT_ULL(7);
     604                 :          0 :         nixtx = (nixtx - 1) & ~(BIT_ULL(7) - 1);
     605                 :          0 :         res = (struct cpt_cn20k_res_s *)nixtx;
     606                 :            : 
     607                 :          0 :         plt_nix_dbg("Outbound error, mbuf %p, sa_index %u, compcode %x uc %x", mbuf,
     608                 :            :                     sess_priv.sa_idx, res->compcode, res->uc_compcode);
     609                 :            : 
     610                 :          0 :         sess_priv.u64 = *rte_security_dynfield(mbuf);
     611                 :            : 
     612                 :          0 :         sa_base = dev->outb.sa_base;
     613                 :          0 :         outb_sa = roc_nix_inl_ow_ipsec_outb_sa(sa_base, sess_priv.sa_idx);
     614                 :            : 
     615                 :          0 :         cn20k_eth_sec_post_event(eth_dev, outb_sa, type, res->uc_compcode, res->compcode, mbuf);
     616                 :            : 
     617                 :            :         cnxk_pktmbuf_free_no_cache(mbuf);
     618                 :            : }
     619                 :            : 
     620                 :            : static void
     621                 :          0 : outb_dbg_iv_update(struct roc_ow_ipsec_outb_sa *outb_sa, const char *__iv_str)
     622                 :            : {
     623                 :          0 :         uint8_t *iv_dbg = outb_sa->iv.iv_dbg;
     624                 :          0 :         char *iv_str = strdup(__iv_str);
     625                 :            :         char *iv_b = NULL, len = 16;
     626                 :            :         char *save;
     627                 :            :         int i;
     628                 :            : 
     629         [ #  # ]:          0 :         if (!iv_str)
     630                 :          0 :                 return;
     631                 :            : 
     632         [ #  # ]:          0 :         if (outb_sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM ||
     633                 :          0 :             outb_sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_CTR ||
     634         [ #  # ]:          0 :             outb_sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_CCM ||
     635         [ #  # ]:          0 :             outb_sa->w2.s.auth_type == ROC_IE_SA_AUTH_AES_GMAC) {
     636                 :          0 :                 memset(outb_sa->iv.s.iv_dbg1, 0, sizeof(outb_sa->iv.s.iv_dbg1));
     637                 :          0 :                 memset(outb_sa->iv.s.iv_dbg2, 0, sizeof(outb_sa->iv.s.iv_dbg2));
     638                 :            : 
     639                 :            :                 iv_dbg = outb_sa->iv.s.iv_dbg1;
     640         [ #  # ]:          0 :                 for (i = 0; i < 4; i++) {
     641         [ #  # ]:          0 :                         iv_b = strtok_r(i ? NULL : iv_str, ",", &save);
     642         [ #  # ]:          0 :                         if (!iv_b)
     643                 :            :                                 break;
     644                 :          0 :                         iv_dbg[i] = strtoul(iv_b, NULL, 0);
     645                 :            :                 }
     646         [ #  # ]:          0 :                 *(uint32_t *)iv_dbg = rte_be_to_cpu_32(*(uint32_t *)iv_dbg);
     647                 :            : 
     648                 :            :                 iv_dbg = outb_sa->iv.s.iv_dbg2;
     649         [ #  # ]:          0 :                 for (i = 0; i < 4; i++) {
     650                 :          0 :                         iv_b = strtok_r(NULL, ",", &save);
     651         [ #  # ]:          0 :                         if (!iv_b)
     652                 :            :                                 break;
     653                 :          0 :                         iv_dbg[i] = strtoul(iv_b, NULL, 0);
     654                 :            :                 }
     655         [ #  # ]:          0 :                 *(uint32_t *)iv_dbg = rte_be_to_cpu_32(*(uint32_t *)iv_dbg);
     656                 :            : 
     657                 :            :         } else {
     658                 :            :                 iv_dbg = outb_sa->iv.iv_dbg;
     659                 :            :                 memset(iv_dbg, 0, sizeof(outb_sa->iv.iv_dbg));
     660                 :            : 
     661         [ #  # ]:          0 :                 for (i = 0; i < len; i++) {
     662         [ #  # ]:          0 :                         iv_b = strtok_r(i ? NULL : iv_str, ",", &save);
     663         [ #  # ]:          0 :                         if (!iv_b)
     664                 :            :                                 break;
     665                 :          0 :                         iv_dbg[i] = strtoul(iv_b, NULL, 0);
     666                 :            :                 }
     667         [ #  # ]:          0 :                 *(uint64_t *)iv_dbg = rte_be_to_cpu_64(*(uint64_t *)iv_dbg);
     668         [ #  # ]:          0 :                 *(uint64_t *)&iv_dbg[8] = rte_be_to_cpu_64(*(uint64_t *)&iv_dbg[8]);
     669                 :            :         }
     670                 :            : 
     671                 :            :         /* Update source of IV */
     672                 :          0 :         outb_sa->w2.s.iv_src = ROC_IE_OW_SA_IV_SRC_FROM_SA;
     673                 :          0 :         free(iv_str);
     674                 :            : }
     675                 :            : 
     676                 :            : static void
     677                 :          0 : cn20k_eth_sec_inb_sa_misc_fill(struct roc_ow_ipsec_inb_sa *sa,
     678                 :            :                                struct rte_security_ipsec_xform *ipsec_xfrm)
     679                 :            : {
     680                 :            :         struct roc_ow_ipsec_inb_ctx_update_reg *ctx;
     681                 :            :         size_t offset;
     682                 :            : 
     683         [ #  # ]:          0 :         if (sa->w2.s.enc_type != ROC_IE_SA_ENC_AES_GCM)
     684                 :            :                 return;
     685                 :            : 
     686                 :            :         /* Update ctx push size for AES GCM */
     687                 :            :         offset = offsetof(struct roc_ow_ipsec_inb_sa, hmac_opad_ipad);
     688                 :            :         ctx = (struct roc_ow_ipsec_inb_ctx_update_reg *)((uint8_t *)sa + offset);
     689                 :          0 :         sa->w0.s.hw_ctx_off = offset / 8;
     690                 :          0 :         sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
     691                 :            : 
     692         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit)
     693                 :          0 :                 ctx->soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
     694                 :            : 
     695         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_soft_limit)
     696                 :          0 :                 ctx->soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
     697                 :            : 
     698         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_hard_limit)
     699                 :          0 :                 ctx->hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
     700                 :            : 
     701         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_hard_limit)
     702                 :          0 :                 ctx->hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
     703                 :            : }
     704                 :            : 
     705                 :            : static int
     706                 :          0 : cn20k_eth_sec_outb_sa_misc_fill(struct roc_nix *roc_nix, struct roc_ow_ipsec_outb_sa *sa,
     707                 :            :                                 void *sa_cptr, struct rte_security_ipsec_xform *ipsec_xfrm,
     708                 :            :                                 uint32_t sa_idx)
     709                 :            : {
     710                 :            :         struct roc_ow_ipsec_outb_ctx_update_reg *ctx;
     711                 :            :         uint64_t *ring_base, ring_addr;
     712                 :            :         size_t offset;
     713                 :            : 
     714         [ #  # ]:          0 :         if (sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM) {
     715                 :            :                 offset = offsetof(struct roc_ow_ipsec_outb_sa, hmac_opad_ipad);
     716                 :          0 :                 ctx = (struct roc_ow_ipsec_outb_ctx_update_reg *)((uint8_t *)sa + offset);
     717                 :          0 :                 sa->w0.s.hw_ctx_off = offset / 8;
     718                 :          0 :                 sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
     719                 :            : 
     720         [ #  # ]:          0 :                 if (ipsec_xfrm->esn.value)
     721                 :          0 :                         ctx->esn_val = ipsec_xfrm->esn.value - 1;
     722                 :            : 
     723         [ #  # ]:          0 :                 if (ipsec_xfrm->life.bytes_soft_limit)
     724                 :          0 :                         ctx->soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
     725                 :            : 
     726         [ #  # ]:          0 :                 if (ipsec_xfrm->life.packets_soft_limit)
     727                 :          0 :                         ctx->soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
     728                 :            : 
     729         [ #  # ]:          0 :                 if (ipsec_xfrm->life.bytes_hard_limit)
     730                 :          0 :                         ctx->hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
     731                 :            : 
     732         [ #  # ]:          0 :                 if (ipsec_xfrm->life.packets_hard_limit)
     733                 :          0 :                         ctx->hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
     734                 :            :         } else {
     735                 :          0 :                 ctx = &sa->ctx;
     736                 :            :         }
     737                 :            : 
     738         [ #  # ]:          0 :         if (roc_nix_inl_is_cq_ena(roc_nix))
     739                 :          0 :                 goto done;
     740                 :            : 
     741         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit | ipsec_xfrm->life.packets_soft_limit) {
     742                 :          0 :                 ring_base = roc_nix_inl_outb_ring_base_get(roc_nix);
     743         [ #  # ]:          0 :                 if (ring_base == NULL)
     744                 :            :                         return -ENOTSUP;
     745                 :            : 
     746                 :          0 :                 ring_addr = ring_base[sa_idx >> ROC_NIX_SOFT_EXP_ERR_RING_MAX_ENTRY_LOG2];
     747                 :          0 :                 ctx->err_ctl.s.mode = ROC_IE_OW_ERR_CTL_MODE_RING;
     748                 :          0 :                 ctx->err_ctl.s.address = ring_addr >> 3;
     749                 :          0 :                 sa->w0.s.ctx_id = ((uintptr_t)sa_cptr >> 51) & 0x1ff;
     750                 :            :         }
     751                 :          0 : done:
     752                 :            :         return 0;
     753                 :            : }
     754                 :            : 
     755                 :            : static int
     756         [ #  # ]:          0 : cn20k_eth_sec_session_create(void *device, struct rte_security_session_conf *conf,
     757                 :            :                              struct rte_security_session *sess)
     758                 :            : {
     759                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
     760                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     761                 :            :         struct rte_security_ipsec_xform *ipsec;
     762                 :            :         struct cn20k_sec_sess_priv sess_priv;
     763                 :            :         struct rte_crypto_sym_xform *crypto;
     764                 :          0 :         struct cnxk_eth_sec_sess *eth_sec = SECURITY_GET_SESS_PRIV(sess);
     765                 :          0 :         struct roc_nix *nix = &dev->nix;
     766                 :            :         bool inbound, inl_dev;
     767                 :            :         rte_spinlock_t *lock;
     768                 :          0 :         char tbuf[128] = {0};
     769                 :            :         int rc = 0;
     770                 :            : 
     771         [ #  # ]:          0 :         if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)
     772                 :            :                 return -ENOTSUP;
     773                 :            : 
     774         [ #  # ]:          0 :         if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
     775                 :            :                 return -ENOTSUP;
     776                 :            : 
     777         [ #  # ]:          0 :         if (nix->custom_inb_sa)
     778                 :            :                 return -ENOTSUP;
     779                 :            : 
     780         [ #  # ]:          0 :         if (rte_security_dynfield_register() < 0)
     781                 :            :                 return -ENOTSUP;
     782                 :            : 
     783   [ #  #  #  # ]:          0 :         if (conf->ipsec.options.ip_reassembly_en && dev->reass_dynfield_off < 0) {
     784         [ #  # ]:          0 :                 if (rte_eth_ip_reassembly_dynfield_register(&dev->reass_dynfield_off,
     785                 :            :                                                             &dev->reass_dynflag_bit) < 0)
     786                 :          0 :                         return -rte_errno;
     787                 :            :         }
     788                 :            : 
     789   [ #  #  #  # ]:          0 :         if (conf->ipsec.options.ingress_oop && rte_security_oop_dynfield_offset < 0) {
     790                 :            :                 /* Register for security OOP dynfield if required */
     791         [ #  # ]:          0 :                 if (rte_security_oop_dynfield_register() < 0)
     792                 :          0 :                         return -rte_errno;
     793                 :            :         }
     794                 :            : 
     795                 :            :         /* We cannot support inbound reassembly and OOP together */
     796         [ #  # ]:          0 :         if (conf->ipsec.options.ip_reassembly_en && conf->ipsec.options.ingress_oop) {
     797                 :          0 :                 plt_err("Cannot support Inbound reassembly and OOP together");
     798                 :          0 :                 return -ENOTSUP;
     799                 :            :         }
     800                 :            : 
     801                 :          0 :         ipsec = &conf->ipsec;
     802                 :          0 :         crypto = conf->crypto_xform;
     803                 :          0 :         inbound = !!(ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS);
     804         [ #  # ]:          0 :         inl_dev = !!dev->inb.inl_dev;
     805                 :            : 
     806                 :            :         memset(eth_sec, 0, sizeof(struct cnxk_eth_sec_sess));
     807                 :          0 :         sess_priv.u64 = 0;
     808                 :            : 
     809         [ #  # ]:          0 :         lock = inbound ? &dev->inb.lock : &dev->outb.lock;
     810                 :            :         rte_spinlock_lock(lock);
     811                 :            : 
     812                 :            :         /* Acquire lock on inline dev for inbound */
     813         [ #  # ]:          0 :         if (inbound && inl_dev)
     814                 :          0 :                 roc_nix_inl_dev_lock();
     815                 :            : 
     816         [ #  # ]:          0 :         if (inbound) {
     817                 :            :                 struct roc_ow_ipsec_inb_sa *inb_sa, *inb_sa_dptr;
     818                 :            :                 struct cn20k_inb_priv_data *inb_priv;
     819                 :            :                 uint32_t spi_mask;
     820                 :            :                 uintptr_t sa;
     821                 :            : 
     822                 :            :                 PLT_STATIC_ASSERT(sizeof(struct cn20k_inb_priv_data) <
     823                 :            :                                   ROC_NIX_INL_OW_IPSEC_INB_SW_RSVD);
     824                 :            : 
     825                 :          0 :                 spi_mask = roc_nix_inl_inb_spi_range(nix, inl_dev, NULL, NULL);
     826                 :            : 
     827                 :            :                 /* Search if a session already exits */
     828         [ #  # ]:          0 :                 if (cnxk_eth_sec_sess_get_by_sa_idx(dev, ipsec->spi & spi_mask, true)) {
     829                 :          0 :                         plt_err("Inbound SA with SPI/SA index %u already in use", ipsec->spi);
     830                 :            :                         rc = -EEXIST;
     831                 :          0 :                         goto err;
     832                 :            :                 }
     833                 :            : 
     834                 :            :                 /* Get Inbound SA from NIX_RX_IPSEC_SA_BASE */
     835                 :          0 :                 sa = roc_nix_inl_inb_sa_get(nix, inl_dev, ipsec->spi);
     836   [ #  #  #  # ]:          0 :                 if (!sa && dev->inb.inl_dev) {
     837                 :            :                         snprintf(tbuf, sizeof(tbuf),
     838                 :            :                                  "Failed to create ingress sa, inline dev "
     839                 :            :                                  "not found or spi not in range");
     840                 :            :                         rc = -ENOTSUP;
     841                 :          0 :                         goto err;
     842         [ #  # ]:          0 :                 } else if (!sa) {
     843                 :            :                         snprintf(tbuf, sizeof(tbuf), "Failed to create ingress sa");
     844                 :            :                         rc = -EFAULT;
     845                 :          0 :                         goto err;
     846                 :            :                 }
     847                 :            : 
     848                 :          0 :                 inb_sa = (struct roc_ow_ipsec_inb_sa *)sa;
     849                 :            : 
     850                 :            :                 /* Check if SA is already in use */
     851         [ #  # ]:          0 :                 if (inb_sa->w2.s.valid) {
     852                 :          0 :                         snprintf(tbuf, sizeof(tbuf), "Inbound SA with SPI %u already in use",
     853                 :            :                                  ipsec->spi);
     854                 :            :                         rc = -EBUSY;
     855                 :          0 :                         goto err;
     856                 :            :                 }
     857                 :            : 
     858                 :          0 :                 inb_sa_dptr = (struct roc_ow_ipsec_inb_sa *)dev->inb.sa_dptr;
     859                 :            :                 memset(inb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_inb_sa));
     860                 :            : 
     861                 :            :                 /* Fill inbound sa params */
     862                 :          0 :                 rc = cnxk_ow_ipsec_inb_sa_fill(inb_sa_dptr, ipsec, crypto, 0);
     863         [ #  # ]:          0 :                 if (rc) {
     864                 :            :                         snprintf(tbuf, sizeof(tbuf), "Failed to init inbound sa, rc=%d", rc);
     865                 :          0 :                         goto err;
     866                 :            :                 }
     867                 :            : 
     868                 :          0 :                 cn20k_eth_sec_inb_sa_misc_fill(inb_sa_dptr, ipsec);
     869                 :            : 
     870                 :            :                 inb_priv = roc_nix_inl_ow_ipsec_inb_sa_sw_rsvd(inb_sa);
     871                 :            :                 /* Back pointer to get eth_sec */
     872                 :          0 :                 inb_priv->eth_sec = eth_sec;
     873                 :            :                 /* Save userdata in inb private area */
     874                 :          0 :                 inb_priv->userdata = conf->userdata;
     875                 :            : 
     876                 :            :                 /* Save SA index/SPI in cookie for now */
     877                 :          0 :                 inb_sa_dptr->w1.s.cookie = ipsec->spi & spi_mask;
     878                 :            : 
     879         [ #  # ]:          0 :                 if (ipsec->options.stats == 1) {
     880                 :            :                         /* Enable mib counters */
     881                 :          0 :                         inb_sa_dptr->w0.s.count_mib_bytes = 1;
     882                 :          0 :                         inb_sa_dptr->w0.s.count_mib_pkts = 1;
     883                 :            :                 }
     884                 :            : 
     885                 :            :                 /* Prepare session priv */
     886                 :          0 :                 sess_priv.inb_sa = 1;
     887                 :          0 :                 sess_priv.sa_idx = ipsec->spi & spi_mask;
     888                 :            : 
     889                 :            :                 /* Pointer from eth_sec -> inb_sa */
     890                 :          0 :                 eth_sec->sa = inb_sa;
     891                 :          0 :                 eth_sec->sess = sess;
     892                 :          0 :                 eth_sec->sa_idx = ipsec->spi & spi_mask;
     893                 :          0 :                 eth_sec->spi = ipsec->spi;
     894                 :          0 :                 eth_sec->inl_dev = !!dev->inb.inl_dev;
     895                 :          0 :                 eth_sec->inb = true;
     896                 :          0 :                 eth_sec->inb_oop = !!ipsec->options.ingress_oop;
     897                 :            : 
     898                 :          0 :                 TAILQ_INSERT_TAIL(&dev->inb.list, eth_sec, entry);
     899                 :          0 :                 dev->inb.nb_sess++;
     900                 :            :                 /* Sync session in context cache */
     901                 :          0 :                 rc = roc_nix_inl_ctx_write(&dev->nix, inb_sa_dptr, eth_sec->sa, eth_sec->inb,
     902                 :            :                                            sizeof(struct roc_ow_ipsec_inb_sa));
     903         [ #  # ]:          0 :                 if (rc)
     904                 :          0 :                         goto err;
     905                 :            : 
     906         [ #  # ]:          0 :                 if (conf->ipsec.options.ip_reassembly_en) {
     907                 :          0 :                         inb_priv->reass_dynfield_off = dev->reass_dynfield_off;
     908                 :          0 :                         inb_priv->reass_dynflag_bit = dev->reass_dynflag_bit;
     909                 :            :                 }
     910                 :            : 
     911         [ #  # ]:          0 :                 if (ipsec->options.ingress_oop)
     912                 :          0 :                         dev->inb.nb_oop++;
     913                 :            : 
     914                 :            :                 /* Update function pointer to handle OOP sessions */
     915   [ #  #  #  # ]:          0 :                 if (dev->inb.nb_oop && !(dev->rx_offload_flags & NIX_RX_REAS_F)) {
     916                 :          0 :                         dev->rx_offload_flags |= NIX_RX_REAS_F;
     917                 :          0 :                         cn20k_eth_set_rx_function(eth_dev);
     918         [ #  # ]:          0 :                         if (cnxk_ethdev_rx_offload_cb)
     919                 :          0 :                                 cnxk_ethdev_rx_offload_cb(eth_dev->data->port_id, NIX_RX_REAS_F);
     920                 :            :                 }
     921                 :            :         } else {
     922                 :            :                 struct roc_ow_ipsec_outb_sa *outb_sa, *outb_sa_dptr;
     923                 :            :                 struct cn20k_outb_priv_data *outb_priv;
     924                 :            :                 struct cnxk_ipsec_outb_rlens *rlens;
     925                 :          0 :                 uint64_t sa_base = dev->outb.sa_base;
     926                 :            :                 const char *iv_str;
     927                 :            :                 uint32_t sa_idx;
     928                 :            : 
     929                 :            :                 PLT_STATIC_ASSERT(sizeof(struct cn20k_outb_priv_data) <
     930                 :            :                                   ROC_NIX_INL_OW_IPSEC_OUTB_SW_RSVD);
     931                 :            : 
     932                 :            :                 /* Alloc an sa index */
     933                 :          0 :                 rc = cnxk_eth_outb_sa_idx_get(dev, &sa_idx, ipsec->spi);
     934         [ #  # ]:          0 :                 if (rc)
     935                 :          0 :                         goto err;
     936                 :            : 
     937                 :          0 :                 outb_sa = roc_nix_inl_ow_ipsec_outb_sa(sa_base, sa_idx);
     938                 :            :                 outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(outb_sa);
     939                 :          0 :                 rlens = &outb_priv->rlens;
     940                 :            : 
     941                 :          0 :                 outb_sa_dptr = (struct roc_ow_ipsec_outb_sa *)dev->outb.sa_dptr;
     942                 :            :                 memset(outb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_outb_sa));
     943                 :            : 
     944                 :            :                 /* Fill outbound sa params */
     945                 :          0 :                 rc = cnxk_ow_ipsec_outb_sa_fill(outb_sa_dptr, ipsec, crypto, 0);
     946         [ #  # ]:          0 :                 if (rc) {
     947                 :            :                         snprintf(tbuf, sizeof(tbuf), "Failed to init outbound sa, rc=%d", rc);
     948                 :          0 :                         rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
     949                 :          0 :                         goto err;
     950                 :            :                 }
     951                 :            : 
     952         [ #  # ]:          0 :                 if (conf->ipsec.options.iv_gen_disable == 1) {
     953                 :          0 :                         iv_str = getenv("ETH_SEC_IV_OVR");
     954         [ #  # ]:          0 :                         if (iv_str)
     955                 :          0 :                                 outb_dbg_iv_update(outb_sa_dptr, iv_str);
     956                 :            :                 }
     957                 :            :                 /* Fill outbound sa misc params */
     958                 :          0 :                 rc = cn20k_eth_sec_outb_sa_misc_fill(&dev->nix, outb_sa_dptr, outb_sa, ipsec,
     959                 :            :                                                      sa_idx);
     960         [ #  # ]:          0 :                 if (rc) {
     961                 :            :                         snprintf(tbuf, sizeof(tbuf), "Failed to init outb sa misc params, rc=%d",
     962                 :            :                                  rc);
     963                 :          0 :                         rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
     964                 :          0 :                         goto err;
     965                 :            :                 }
     966                 :            : 
     967                 :            :                 /* Save userdata */
     968                 :          0 :                 outb_priv->userdata = conf->userdata;
     969                 :          0 :                 outb_priv->sa_idx = sa_idx;
     970                 :          0 :                 outb_priv->eth_sec = eth_sec;
     971                 :            : 
     972                 :            :                 /* Save rlen info */
     973                 :          0 :                 cnxk_ipsec_outb_rlens_get(rlens, ipsec, crypto);
     974                 :            : 
     975         [ #  # ]:          0 :                 if (ipsec->options.stats == 1) {
     976                 :            :                         /* Enable mib counters */
     977                 :          0 :                         outb_sa_dptr->w0.s.count_mib_bytes = 1;
     978                 :          0 :                         outb_sa_dptr->w0.s.count_mib_pkts = 1;
     979                 :            :                 }
     980                 :            : 
     981                 :            :                 /* Prepare session priv */
     982                 :          0 :                 sess_priv.sa_idx = outb_priv->sa_idx;
     983                 :          0 :                 sess_priv.roundup_byte = rlens->roundup_byte;
     984                 :          0 :                 sess_priv.roundup_len = rlens->roundup_len;
     985                 :          0 :                 sess_priv.partial_len = rlens->partial_len;
     986                 :          0 :                 sess_priv.mode = outb_sa_dptr->w2.s.ipsec_mode;
     987                 :          0 :                 sess_priv.outer_ip_ver = outb_sa_dptr->w2.s.outer_ip_ver;
     988                 :            :                 /* Propagate inner checksum enable from SA to fast path */
     989                 :          0 :                 sess_priv.chksum =
     990         [ #  # ]:          0 :                         (!ipsec->options.ip_csum_enable << 1 | !ipsec->options.l4_csum_enable);
     991                 :          0 :                 sess_priv.dec_ttl = ipsec->options.dec_ttl;
     992                 :          0 :                 sess_priv.cpt_cq_ena = roc_nix_inl_is_cq_ena(&dev->nix);
     993                 :            : 
     994                 :            :                 /* Pointer from eth_sec -> outb_sa */
     995                 :          0 :                 eth_sec->sa = outb_sa;
     996                 :          0 :                 eth_sec->sess = sess;
     997                 :          0 :                 eth_sec->sa_idx = sa_idx;
     998                 :          0 :                 eth_sec->spi = ipsec->spi;
     999                 :            : 
    1000                 :          0 :                 TAILQ_INSERT_TAIL(&dev->outb.list, eth_sec, entry);
    1001                 :          0 :                 dev->outb.nb_sess++;
    1002                 :            :                 /* Sync session in context cache */
    1003                 :          0 :                 rc = roc_nix_inl_ctx_write(&dev->nix, outb_sa_dptr, eth_sec->sa, eth_sec->inb,
    1004                 :            :                                            sizeof(struct roc_ow_ipsec_outb_sa));
    1005         [ #  # ]:          0 :                 if (rc)
    1006                 :          0 :                         goto err;
    1007                 :            :         }
    1008         [ #  # ]:          0 :         if (inbound && inl_dev)
    1009                 :          0 :                 roc_nix_inl_dev_unlock();
    1010                 :            :         rte_spinlock_unlock(lock);
    1011                 :            : 
    1012         [ #  # ]:          0 :         plt_nix_dbg("Created %s session with spi=%u, sa_idx=%u inl_dev=%u",
    1013                 :            :                     inbound ? "inbound" : "outbound", eth_sec->spi, eth_sec->sa_idx,
    1014                 :            :                     eth_sec->inl_dev);
    1015                 :            :         /*
    1016                 :            :          * Update fast path info in priv area.
    1017                 :            :          */
    1018                 :          0 :         sess->fast_mdata = sess_priv.u64;
    1019                 :            : 
    1020                 :          0 :         return 0;
    1021                 :          0 : err:
    1022         [ #  # ]:          0 :         if (inbound && inl_dev)
    1023                 :          0 :                 roc_nix_inl_dev_unlock();
    1024                 :            :         rte_spinlock_unlock(lock);
    1025                 :            : 
    1026         [ #  # ]:          0 :         if (rc)
    1027                 :          0 :                 plt_err("%s", tbuf);
    1028                 :            :         return rc;
    1029                 :            : }
    1030                 :            : 
    1031                 :            : static int
    1032                 :          0 : cn20k_eth_sec_session_destroy(void *device, struct rte_security_session *sess)
    1033                 :            : {
    1034                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
    1035                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1036                 :            :         struct cnxk_eth_sec_sess *eth_sec;
    1037                 :            :         rte_spinlock_t *lock;
    1038                 :            :         void *sa_dptr;
    1039                 :            : 
    1040                 :          0 :         eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
    1041         [ #  # ]:          0 :         if (!eth_sec)
    1042                 :            :                 return -ENOENT;
    1043         [ #  # ]:          0 :         if (dev->nix.custom_inb_sa)
    1044                 :            :                 return -ENOTSUP;
    1045                 :            : 
    1046         [ #  # ]:          0 :         lock = eth_sec->inb ? &dev->inb.lock : &dev->outb.lock;
    1047                 :            :         rte_spinlock_lock(lock);
    1048                 :            : 
    1049         [ #  # ]:          0 :         if (eth_sec->inl_dev)
    1050                 :          0 :                 roc_nix_inl_dev_lock();
    1051                 :            : 
    1052         [ #  # ]:          0 :         if (eth_sec->inb) {
    1053                 :            :                 /* Disable SA */
    1054                 :          0 :                 sa_dptr = dev->inb.sa_dptr;
    1055                 :          0 :                 roc_ow_ipsec_inb_sa_init(sa_dptr);
    1056                 :            : 
    1057                 :          0 :                 roc_nix_inl_ctx_write(&dev->nix, sa_dptr, eth_sec->sa, eth_sec->inb,
    1058                 :            :                                       sizeof(struct roc_ow_ipsec_inb_sa));
    1059         [ #  # ]:          0 :                 TAILQ_REMOVE(&dev->inb.list, eth_sec, entry);
    1060                 :          0 :                 dev->inb.nb_sess--;
    1061         [ #  # ]:          0 :                 if (eth_sec->inb_oop)
    1062                 :          0 :                         dev->inb.nb_oop--;
    1063                 :            : 
    1064                 :            :                 /* Clear offload flags if was used by OOP */
    1065   [ #  #  #  # ]:          0 :                 if (!dev->inb.nb_oop && !dev->inb.reass_en &&
    1066         [ #  # ]:          0 :                     dev->rx_offload_flags & NIX_RX_REAS_F) {
    1067                 :          0 :                         dev->rx_offload_flags &= ~NIX_RX_REAS_F;
    1068                 :          0 :                         cn20k_eth_set_rx_function(eth_dev);
    1069                 :            :                 }
    1070                 :            :         } else {
    1071                 :            :                 /* Disable SA */
    1072                 :          0 :                 sa_dptr = dev->outb.sa_dptr;
    1073                 :          0 :                 roc_ow_ipsec_outb_sa_init(sa_dptr);
    1074                 :            : 
    1075                 :          0 :                 roc_nix_inl_ctx_write(&dev->nix, sa_dptr, eth_sec->sa, eth_sec->inb,
    1076                 :            :                                       sizeof(struct roc_ow_ipsec_outb_sa));
    1077                 :            :                 /* Release Outbound SA index */
    1078                 :          0 :                 cnxk_eth_outb_sa_idx_put(dev, eth_sec->sa_idx);
    1079         [ #  # ]:          0 :                 TAILQ_REMOVE(&dev->outb.list, eth_sec, entry);
    1080                 :          0 :                 dev->outb.nb_sess--;
    1081                 :            :         }
    1082         [ #  # ]:          0 :         if (eth_sec->inl_dev)
    1083                 :          0 :                 roc_nix_inl_dev_unlock();
    1084                 :            : 
    1085                 :            :         rte_spinlock_unlock(lock);
    1086                 :            : 
    1087         [ #  # ]:          0 :         plt_nix_dbg("Destroyed %s session with spi=%u, sa_idx=%u, inl_dev=%u",
    1088                 :            :                     eth_sec->inb ? "inbound" : "outbound", eth_sec->spi, eth_sec->sa_idx,
    1089                 :            :                     eth_sec->inl_dev);
    1090                 :            : 
    1091                 :          0 :         return 0;
    1092                 :            : }
    1093                 :            : 
    1094                 :            : static const struct rte_security_capability *
    1095                 :          0 : cn20k_eth_sec_capabilities_get(void *device __rte_unused)
    1096                 :            : {
    1097                 :          0 :         return cn20k_eth_sec_capabilities;
    1098                 :            : }
    1099                 :            : 
    1100                 :            : static int
    1101         [ #  # ]:          0 : cn20k_eth_sec_session_update(void *device, struct rte_security_session *sess,
    1102                 :            :                              struct rte_security_session_conf *conf)
    1103                 :            : {
    1104                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
    1105                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1106                 :            :         struct rte_security_ipsec_xform *ipsec;
    1107                 :            :         struct cn20k_sec_sess_priv sess_priv;
    1108                 :            :         struct rte_crypto_sym_xform *crypto;
    1109                 :            :         struct cnxk_eth_sec_sess *eth_sec;
    1110                 :            :         bool inbound;
    1111                 :            :         int rc;
    1112                 :            : 
    1113         [ #  # ]:          0 :         if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL ||
    1114                 :            :             conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
    1115                 :            :                 return -ENOENT;
    1116                 :            : 
    1117                 :          0 :         ipsec = &conf->ipsec;
    1118                 :          0 :         crypto = conf->crypto_xform;
    1119                 :          0 :         inbound = !!(ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS);
    1120                 :            : 
    1121                 :          0 :         eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
    1122         [ #  # ]:          0 :         if (!eth_sec)
    1123                 :            :                 return -ENOENT;
    1124                 :            : 
    1125                 :          0 :         eth_sec->spi = conf->ipsec.spi;
    1126                 :            : 
    1127         [ #  # ]:          0 :         if (inbound) {
    1128                 :            :                 struct roc_ow_ipsec_inb_sa *inb_sa_dptr, *inb_sa;
    1129                 :            :                 struct cn20k_inb_priv_data *inb_priv;
    1130                 :            : 
    1131                 :          0 :                 inb_sa = eth_sec->sa;
    1132                 :            :                 inb_priv = roc_nix_inl_ow_ipsec_inb_sa_sw_rsvd(inb_sa);
    1133                 :          0 :                 inb_sa_dptr = (struct roc_ow_ipsec_inb_sa *)dev->inb.sa_dptr;
    1134                 :            :                 memset(inb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_inb_sa));
    1135                 :            : 
    1136                 :          0 :                 rc = cnxk_ow_ipsec_inb_sa_fill(inb_sa_dptr, ipsec, crypto, 0);
    1137         [ #  # ]:          0 :                 if (rc)
    1138                 :            :                         return -EINVAL;
    1139                 :            : 
    1140                 :          0 :                 cn20k_eth_sec_inb_sa_misc_fill(inb_sa_dptr, ipsec);
    1141                 :            : 
    1142                 :            :                 /* Use cookie for original data */
    1143                 :          0 :                 inb_sa_dptr->w1.s.cookie = inb_sa->w1.s.cookie;
    1144                 :            : 
    1145         [ #  # ]:          0 :                 if (ipsec->options.stats == 1) {
    1146                 :            :                         /* Enable mib counters */
    1147                 :          0 :                         inb_sa_dptr->w0.s.count_mib_bytes = 1;
    1148                 :          0 :                         inb_sa_dptr->w0.s.count_mib_pkts = 1;
    1149                 :            :                 }
    1150                 :            : 
    1151                 :          0 :                 rc = roc_nix_inl_ctx_write(&dev->nix, inb_sa_dptr, eth_sec->sa, eth_sec->inb,
    1152                 :            :                                            sizeof(struct roc_ow_ipsec_inb_sa));
    1153         [ #  # ]:          0 :                 if (rc)
    1154                 :            :                         return -EINVAL;
    1155                 :            : 
    1156                 :            :                 /* Save userdata in inb private area */
    1157                 :          0 :                 inb_priv->userdata = conf->userdata;
    1158                 :            :         } else {
    1159                 :            :                 struct roc_ow_ipsec_outb_sa *outb_sa_dptr, *outb_sa;
    1160                 :            :                 struct cn20k_outb_priv_data *outb_priv;
    1161                 :            :                 struct cnxk_ipsec_outb_rlens *rlens;
    1162                 :            : 
    1163                 :          0 :                 outb_sa = eth_sec->sa;
    1164                 :            :                 outb_priv = roc_nix_inl_ow_ipsec_outb_sa_sw_rsvd(outb_sa);
    1165                 :          0 :                 rlens = &outb_priv->rlens;
    1166                 :          0 :                 outb_sa_dptr = (struct roc_ow_ipsec_outb_sa *)dev->outb.sa_dptr;
    1167                 :            :                 memset(outb_sa_dptr, 0, sizeof(struct roc_ow_ipsec_outb_sa));
    1168                 :            : 
    1169                 :          0 :                 rc = cnxk_ow_ipsec_outb_sa_fill(outb_sa_dptr, ipsec, crypto, 0);
    1170         [ #  # ]:          0 :                 if (rc)
    1171                 :            :                         return -EINVAL;
    1172                 :            : 
    1173                 :            :                 /* Fill outbound sa misc params */
    1174                 :          0 :                 rc = cn20k_eth_sec_outb_sa_misc_fill(&dev->nix, outb_sa_dptr, outb_sa, ipsec,
    1175                 :            :                                                      eth_sec->sa_idx);
    1176         [ #  # ]:          0 :                 if (rc) {
    1177                 :          0 :                         plt_err("Failed to init outb sa misc params, rc=%d", rc);
    1178                 :          0 :                         return rc;
    1179                 :            :                 }
    1180                 :            : 
    1181                 :            :                 /* Save rlen info */
    1182                 :          0 :                 cnxk_ipsec_outb_rlens_get(rlens, ipsec, crypto);
    1183                 :            : 
    1184         [ #  # ]:          0 :                 if (ipsec->options.stats == 1) {
    1185                 :            :                         /* Enable mib counters */
    1186                 :          0 :                         outb_sa_dptr->w0.s.count_mib_bytes = 1;
    1187                 :          0 :                         outb_sa_dptr->w0.s.count_mib_pkts = 1;
    1188                 :            :                 }
    1189                 :            : 
    1190                 :          0 :                 sess_priv.u64 = 0;
    1191                 :          0 :                 sess_priv.sa_idx = outb_priv->sa_idx;
    1192                 :          0 :                 sess_priv.roundup_byte = rlens->roundup_byte;
    1193                 :          0 :                 sess_priv.roundup_len = rlens->roundup_len;
    1194                 :          0 :                 sess_priv.partial_len = rlens->partial_len;
    1195                 :          0 :                 sess_priv.mode = outb_sa_dptr->w2.s.ipsec_mode;
    1196                 :          0 :                 sess_priv.outer_ip_ver = outb_sa_dptr->w2.s.outer_ip_ver;
    1197                 :            :                 /* Propagate inner checksum enable from SA to fast path */
    1198                 :          0 :                 sess_priv.chksum =
    1199         [ #  # ]:          0 :                         (!ipsec->options.ip_csum_enable << 1 | !ipsec->options.l4_csum_enable);
    1200                 :          0 :                 sess_priv.dec_ttl = ipsec->options.dec_ttl;
    1201                 :            : 
    1202                 :          0 :                 sess_priv.cpt_cq_ena = roc_nix_inl_is_cq_ena(&dev->nix);
    1203                 :          0 :                 rc = roc_nix_inl_ctx_write(&dev->nix, outb_sa_dptr, eth_sec->sa, eth_sec->inb,
    1204                 :            :                                            sizeof(struct roc_ow_ipsec_outb_sa));
    1205         [ #  # ]:          0 :                 if (rc)
    1206                 :            :                         return -EINVAL;
    1207                 :            : 
    1208                 :            :                 /* Save userdata */
    1209                 :          0 :                 outb_priv->userdata = conf->userdata;
    1210                 :          0 :                 sess->fast_mdata = sess_priv.u64;
    1211                 :            :         }
    1212                 :            : 
    1213                 :            :         return 0;
    1214                 :            : }
    1215                 :            : 
    1216                 :            : static int
    1217                 :          0 : cn20k_eth_sec_session_stats_get(void *device, struct rte_security_session *sess,
    1218                 :            :                                 struct rte_security_stats *stats)
    1219                 :            : {
    1220                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
    1221                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1222                 :            :         struct cnxk_eth_sec_sess *eth_sec;
    1223                 :            :         size_t offset;
    1224                 :            :         int rc;
    1225                 :            : 
    1226                 :          0 :         eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
    1227         [ #  # ]:          0 :         if (eth_sec == NULL)
    1228                 :            :                 return -EINVAL;
    1229                 :            : 
    1230                 :          0 :         rc = roc_nix_inl_sa_sync(&dev->nix, eth_sec->sa, eth_sec->inb, ROC_NIX_INL_SA_OP_FLUSH);
    1231         [ #  # ]:          0 :         if (rc)
    1232                 :            :                 return -EINVAL;
    1233                 :            :         rte_delay_ms(1);
    1234                 :            : 
    1235                 :          0 :         stats->protocol = RTE_SECURITY_PROTOCOL_IPSEC;
    1236                 :            : 
    1237         [ #  # ]:          0 :         if (eth_sec->inb) {
    1238                 :          0 :                 struct roc_ow_ipsec_inb_sa *sa = (struct roc_ow_ipsec_inb_sa *)eth_sec->sa;
    1239                 :            :                 struct roc_ow_ipsec_inb_ctx_update_reg *ctx;
    1240                 :            : 
    1241         [ #  # ]:          0 :                 if (sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM) {
    1242                 :            :                         offset = offsetof(struct roc_ow_ipsec_inb_sa, hmac_opad_ipad);
    1243                 :          0 :                         ctx = (struct roc_ow_ipsec_inb_ctx_update_reg *)((uint8_t *)sa + offset);
    1244                 :            :                 } else {
    1245                 :          0 :                         ctx = &sa->ctx;
    1246                 :            :                 }
    1247                 :            : 
    1248                 :          0 :                 stats->ipsec.ipackets = ctx->mib_pkts;
    1249                 :          0 :                 stats->ipsec.ibytes = ctx->mib_octs;
    1250                 :            :         } else {
    1251                 :          0 :                 struct roc_ow_ipsec_outb_sa *sa = (struct roc_ow_ipsec_outb_sa *)eth_sec->sa;
    1252                 :            :                 struct roc_ow_ipsec_outb_ctx_update_reg *ctx;
    1253                 :            : 
    1254         [ #  # ]:          0 :                 if (sa->w2.s.enc_type == ROC_IE_SA_ENC_AES_GCM) {
    1255                 :            :                         offset = offsetof(struct roc_ow_ipsec_outb_sa, hmac_opad_ipad);
    1256                 :          0 :                         ctx = (struct roc_ow_ipsec_outb_ctx_update_reg *)((uint8_t *)sa + offset);
    1257                 :            :                 } else {
    1258                 :          0 :                         ctx = &sa->ctx;
    1259                 :            :                 }
    1260                 :            : 
    1261                 :          0 :                 stats->ipsec.opackets = ctx->mib_pkts;
    1262                 :          0 :                 stats->ipsec.obytes = ctx->mib_octs;
    1263                 :            :         }
    1264                 :            : 
    1265                 :            :         return 0;
    1266                 :            : }
    1267                 :            : 
    1268                 :            : static void
    1269                 :          0 : eth_sec_caps_add(struct rte_security_capability eth_sec_caps[], uint32_t *idx,
    1270                 :            :                  const struct rte_security_capability *caps, uint32_t nb_caps)
    1271                 :            : {
    1272         [ #  # ]:          0 :         PLT_VERIFY(*idx + nb_caps < SEC_CAPS_LEN);
    1273                 :            : 
    1274         [ #  # ]:          0 :         rte_memcpy(&eth_sec_caps[*idx], caps, nb_caps * sizeof(caps[0]));
    1275                 :          0 :         *idx += nb_caps;
    1276                 :          0 : }
    1277                 :            : 
    1278                 :            : static uint16_t __rte_hot
    1279                 :          0 : cn20k_eth_sec_inb_rx_inject(void *device, struct rte_mbuf **pkts,
    1280                 :            :                             struct rte_security_session **sess, uint16_t nb_pkts)
    1281                 :            : {
    1282                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
    1283                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1284                 :            : 
    1285                 :          0 :         return cn20k_nix_inj_pkts(sess, &dev->inj_cfg, pkts, nb_pkts);
    1286                 :            : }
    1287                 :            : 
    1288                 :            : static int
    1289                 :          0 : cn20k_eth_sec_rx_inject_config(void *device, uint16_t port_id, bool enable)
    1290                 :            : {
    1291                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
    1292                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
    1293                 :            :         uint64_t channel, pf_func, inj_match_id = 0xFFFFUL;
    1294                 :            :         struct cnxk_ethdev_inj_cfg *inj_cfg;
    1295                 :          0 :         struct roc_nix *nix = &dev->nix;
    1296                 :            :         struct roc_cpt_lf *inl_lf;
    1297                 :            :         uint64_t sa_base;
    1298                 :            : 
    1299         [ #  # ]:          0 :         if (!rte_eth_dev_is_valid_port(port_id))
    1300                 :            :                 return -EINVAL;
    1301                 :            : 
    1302         [ #  # ]:          0 :         if (eth_dev->data->dev_started || !eth_dev->data->dev_configured)
    1303                 :            :                 return -EBUSY;
    1304                 :            : 
    1305         [ #  # ]:          0 :         if (!roc_nix_inl_inb_rx_inject_enable(nix, dev->inb.inl_dev))
    1306                 :            :                 return -ENOTSUP;
    1307                 :            : 
    1308                 :          0 :         roc_idev_nix_rx_inject_set(port_id, enable);
    1309                 :            : 
    1310                 :          0 :         inl_lf = roc_nix_inl_inb_inj_lf_get(nix);
    1311         [ #  # ]:          0 :         if (!inl_lf)
    1312                 :            :                 return -ENOTSUP;
    1313                 :          0 :         sa_base = roc_nix_inl_inb_sa_base_get(nix, dev->inb.inl_dev);
    1314                 :            : 
    1315                 :            :         inj_cfg = &dev->inj_cfg;
    1316                 :          0 :         inj_cfg->sa_base = sa_base | eth_dev->data->port_id;
    1317                 :          0 :         inj_cfg->io_addr = inl_lf->io_addr;
    1318                 :          0 :         inj_cfg->lmt_base = nix->lmt_base;
    1319                 :          0 :         channel = roc_nix_get_base_chan(nix);
    1320                 :          0 :         pf_func = roc_idev_nix_inl_dev_pffunc_get();
    1321                 :          0 :         inj_cfg->cmd_w0 = pf_func << 48 | inj_match_id << 32 | channel << 4;
    1322                 :            : 
    1323                 :          0 :         return 0;
    1324                 :            : }
    1325                 :            : 
    1326                 :            : #define CPT_LMTST_BURST 32
    1327                 :            : static uint16_t
    1328                 :          0 : cn20k_inl_dev_submit(struct roc_nix_inl_dev_q *q, void *inst, uint16_t nb_inst)
    1329                 :            : {
    1330                 :          0 :         uintptr_t lbase = q->lmt_base;
    1331                 :            :         uint8_t lnum, shft, loff;
    1332                 :            :         uint16_t left, burst;
    1333                 :            :         rte_iova_t io_addr;
    1334                 :            :         uint16_t lmt_id;
    1335                 :            : 
    1336                 :            :         /* Check the flow control to avoid the queue overflow */
    1337         [ #  # ]:          0 :         if (cnxk_nix_inl_fc_check(q->fc_addr, &q->fc_addr_sw, q->nb_desc, nb_inst))
    1338                 :            :                 return 0;
    1339                 :            : 
    1340                 :            :         io_addr = q->io_addr;
    1341                 :            :         ROC_LMT_CPT_BASE_ID_GET(lbase, lmt_id);
    1342                 :            : 
    1343                 :            :         left = nb_inst;
    1344                 :          0 : again:
    1345                 :          0 :         burst = left > CPT_LMTST_BURST ? CPT_LMTST_BURST : left;
    1346                 :            : 
    1347                 :            :         lnum = 0;
    1348                 :            :         loff = 0;
    1349                 :            :         shft = 16;
    1350                 :          0 :         memcpy(PLT_PTR_CAST(lbase), inst, burst * sizeof(struct cpt_inst_s));
    1351                 :            :         loff = (burst % 2) ? 1 : 0;
    1352                 :            :         lnum = (burst / 2);
    1353                 :            :         shft = shft + (lnum * 3);
    1354                 :            : 
    1355                 :          0 :         left -= burst;
    1356                 :            :         cn20k_nix_sec_steorl(io_addr, lmt_id, lnum, loff, shft);
    1357                 :          0 :         rte_io_wmb();
    1358         [ #  # ]:          0 :         if (left) {
    1359                 :          0 :                 inst = RTE_PTR_ADD(inst, burst * sizeof(struct cpt_inst_s));
    1360                 :          0 :                 goto again;
    1361                 :            :         }
    1362                 :            :         return nb_inst;
    1363                 :            : }
    1364                 :            : 
    1365                 :            : void
    1366                 :          0 : cn20k_eth_sec_ops_override(void)
    1367                 :            : {
    1368                 :            :         static int init_once;
    1369                 :          0 :         uint32_t idx = 0;
    1370                 :            : 
    1371         [ #  # ]:          0 :         if (init_once)
    1372                 :          0 :                 return;
    1373         [ #  # ]:          0 :         init_once = 1;
    1374                 :            : 
    1375         [ #  # ]:          0 :         if (roc_feature_nix_has_inl_ipsec())
    1376                 :          0 :                 eth_sec_caps_add(cn20k_eth_sec_capabilities, &idx, cn20k_eth_sec_ipsec_capabilities,
    1377                 :            :                                  RTE_DIM(cn20k_eth_sec_ipsec_capabilities));
    1378                 :            : 
    1379                 :          0 :         cn20k_eth_sec_capabilities[idx].action = RTE_SECURITY_ACTION_TYPE_NONE;
    1380                 :            : 
    1381                 :            :         /* Update platform specific ops */
    1382                 :          0 :         cnxk_eth_sec_ops.session_create = cn20k_eth_sec_session_create;
    1383                 :          0 :         cnxk_eth_sec_ops.session_destroy = cn20k_eth_sec_session_destroy;
    1384                 :          0 :         cnxk_eth_sec_ops.capabilities_get = cn20k_eth_sec_capabilities_get;
    1385                 :          0 :         cnxk_eth_sec_ops.session_update = cn20k_eth_sec_session_update;
    1386                 :          0 :         cnxk_eth_sec_ops.session_stats_get = cn20k_eth_sec_session_stats_get;
    1387                 :          0 :         cnxk_eth_sec_ops.rx_inject_configure = cn20k_eth_sec_rx_inject_config;
    1388                 :          0 :         cnxk_eth_sec_ops.inb_pkt_rx_inject = cn20k_eth_sec_inb_rx_inject;
    1389                 :            : 
    1390                 :            :         /* Update platform specific rte_pmd_cnxk ops */
    1391                 :          0 :         cnxk_pmd_ops.inl_dev_submit = cn20k_inl_dev_submit;
    1392                 :            : }

Generated by: LCOV version 1.14