LCOV - code coverage report
Current view: top level - drivers/net/cnxk - cn9k_ethdev_sec.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 188 0.0 %
Date: 2024-01-22 15:35:40 Functions: 0 7 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 102 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <rte_cryptodev.h>
       6                 :            : #include <rte_security.h>
       7                 :            : #include <rte_security_driver.h>
       8                 :            : 
       9                 :            : #include <cn9k_ethdev.h>
      10                 :            : #include <cnxk_security.h>
      11                 :            : 
      12                 :            : static struct rte_cryptodev_capabilities cn9k_eth_sec_crypto_caps[] = {
      13                 :            :         {       /* NULL (CIPHER) */
      14                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
      15                 :            :                 {.sym = {
      16                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
      17                 :            :                         {.cipher = {
      18                 :            :                                 .algo = RTE_CRYPTO_CIPHER_NULL,
      19                 :            :                                 .block_size = 1,
      20                 :            :                                 .key_size = {
      21                 :            :                                         .min = 0,
      22                 :            :                                         .max = 0,
      23                 :            :                                         .increment = 0
      24                 :            :                                 },
      25                 :            :                                 .iv_size = {
      26                 :            :                                         .min = 0,
      27                 :            :                                         .max = 0,
      28                 :            :                                         .increment = 0
      29                 :            :                                 }
      30                 :            :                         }, },
      31                 :            :                 }, }
      32                 :            :         },
      33                 :            :         {       /* DES  */
      34                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
      35                 :            :                 {.sym = {
      36                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
      37                 :            :                         {.cipher = {
      38                 :            :                                 .algo = RTE_CRYPTO_CIPHER_DES_CBC,
      39                 :            :                                 .block_size = 8,
      40                 :            :                                 .key_size = {
      41                 :            :                                         .min = 8,
      42                 :            :                                         .max = 8,
      43                 :            :                                         .increment = 0
      44                 :            :                                 },
      45                 :            :                                 .iv_size = {
      46                 :            :                                         .min = 8,
      47                 :            :                                         .max = 8,
      48                 :            :                                         .increment = 0
      49                 :            :                                 }
      50                 :            :                         }, },
      51                 :            :                 }, }
      52                 :            :         },
      53                 :            :         {       /* 3DES CBC  */
      54                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
      55                 :            :                 {.sym = {
      56                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
      57                 :            :                         {.cipher = {
      58                 :            :                                 .algo = RTE_CRYPTO_CIPHER_3DES_CBC,
      59                 :            :                                 .block_size = 8,
      60                 :            :                                 .key_size = {
      61                 :            :                                         .min = 24,
      62                 :            :                                         .max = 24,
      63                 :            :                                         .increment = 0
      64                 :            :                                 },
      65                 :            :                                 .iv_size = {
      66                 :            :                                         .min = 8,
      67                 :            :                                         .max = 16,
      68                 :            :                                         .increment = 8
      69                 :            :                                 }
      70                 :            :                         }, },
      71                 :            :                 }, }
      72                 :            :         },
      73                 :            :         {       /* AES GCM */
      74                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
      75                 :            :                 {.sym = {
      76                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
      77                 :            :                         {.aead = {
      78                 :            :                                 .algo = RTE_CRYPTO_AEAD_AES_GCM,
      79                 :            :                                 .block_size = 16,
      80                 :            :                                 .key_size = {
      81                 :            :                                         .min = 16,
      82                 :            :                                         .max = 32,
      83                 :            :                                         .increment = 8
      84                 :            :                                 },
      85                 :            :                                 .digest_size = {
      86                 :            :                                         .min = 16,
      87                 :            :                                         .max = 16,
      88                 :            :                                         .increment = 0
      89                 :            :                                 },
      90                 :            :                                 .aad_size = {
      91                 :            :                                         .min = 8,
      92                 :            :                                         .max = 12,
      93                 :            :                                         .increment = 4
      94                 :            :                                 },
      95                 :            :                                 .iv_size = {
      96                 :            :                                         .min = 12,
      97                 :            :                                         .max = 12,
      98                 :            :                                         .increment = 0
      99                 :            :                                 }
     100                 :            :                         }, }
     101                 :            :                 }, }
     102                 :            :         },
     103                 :            :         {       /* AES CCM */
     104                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     105                 :            :                 {.sym = {
     106                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AEAD,
     107                 :            :                         {.aead = {
     108                 :            :                                 .algo = RTE_CRYPTO_AEAD_AES_CCM,
     109                 :            :                                 .block_size = 16,
     110                 :            :                                 .key_size = {
     111                 :            :                                         .min = 16,
     112                 :            :                                         .max = 32,
     113                 :            :                                         .increment = 8
     114                 :            :                                 },
     115                 :            :                                 .digest_size = {
     116                 :            :                                         .min = 16,
     117                 :            :                                         .max = 16,
     118                 :            :                                         .increment = 0
     119                 :            :                                 },
     120                 :            :                                 .aad_size = {
     121                 :            :                                         .min = 8,
     122                 :            :                                         .max = 12,
     123                 :            :                                         .increment = 4
     124                 :            :                                 },
     125                 :            :                                 .iv_size = {
     126                 :            :                                         .min = 11,
     127                 :            :                                         .max = 13,
     128                 :            :                                         .increment = 1
     129                 :            :                                 }
     130                 :            :                         }, }
     131                 :            :                 }, }
     132                 :            :         },
     133                 :            :         {       /* AES CBC */
     134                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     135                 :            :                 {.sym = {
     136                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
     137                 :            :                         {.cipher = {
     138                 :            :                                 .algo = RTE_CRYPTO_CIPHER_AES_CBC,
     139                 :            :                                 .block_size = 16,
     140                 :            :                                 .key_size = {
     141                 :            :                                         .min = 16,
     142                 :            :                                         .max = 32,
     143                 :            :                                         .increment = 8
     144                 :            :                                 },
     145                 :            :                                 .iv_size = {
     146                 :            :                                         .min = 16,
     147                 :            :                                         .max = 16,
     148                 :            :                                         .increment = 0
     149                 :            :                                 }
     150                 :            :                         }, }
     151                 :            :                 }, }
     152                 :            :         },
     153                 :            :         {       /* AES CTR */
     154                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     155                 :            :                 {.sym = {
     156                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_CIPHER,
     157                 :            :                         {.cipher = {
     158                 :            :                                 .algo = RTE_CRYPTO_CIPHER_AES_CTR,
     159                 :            :                                 .block_size = 16,
     160                 :            :                                 .key_size = {
     161                 :            :                                         .min = 16,
     162                 :            :                                         .max = 32,
     163                 :            :                                         .increment = 8
     164                 :            :                                 },
     165                 :            :                                 .iv_size = {
     166                 :            :                                         .min = 12,
     167                 :            :                                         .max = 16,
     168                 :            :                                         .increment = 4
     169                 :            :                                 }
     170                 :            :                         }, }
     171                 :            :                 }, }
     172                 :            :         },
     173                 :            :         {       /* AES-XCBC */
     174                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     175                 :            :                 { .sym = {
     176                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     177                 :            :                         {.auth = {
     178                 :            :                                 .algo = RTE_CRYPTO_AUTH_AES_XCBC_MAC,
     179                 :            :                                 .block_size = 16,
     180                 :            :                                 .key_size = {
     181                 :            :                                         .min = 16,
     182                 :            :                                         .max = 16,
     183                 :            :                                         .increment = 0
     184                 :            :                                 },
     185                 :            :                                 .digest_size = {
     186                 :            :                                         .min = 12,
     187                 :            :                                         .max = 12,
     188                 :            :                                         .increment = 0,
     189                 :            :                                 },
     190                 :            :                         }, }
     191                 :            :                 }, }
     192                 :            :         },
     193                 :            :         {       /* AES GMAC (AUTH) */
     194                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     195                 :            :                 {.sym = {
     196                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     197                 :            :                         {.auth = {
     198                 :            :                                 .algo = RTE_CRYPTO_AUTH_AES_GMAC,
     199                 :            :                                 .block_size = 16,
     200                 :            :                                 .key_size = {
     201                 :            :                                         .min = 16,
     202                 :            :                                         .max = 32,
     203                 :            :                                         .increment = 8
     204                 :            :                                 },
     205                 :            :                                 .digest_size = {
     206                 :            :                                         .min = 8,
     207                 :            :                                         .max = 16,
     208                 :            :                                         .increment = 4
     209                 :            :                                 },
     210                 :            :                                 .iv_size = {
     211                 :            :                                         .min = 12,
     212                 :            :                                         .max = 12,
     213                 :            :                                         .increment = 0
     214                 :            :                                 }
     215                 :            :                         }, }
     216                 :            :                 }, }
     217                 :            :         },
     218                 :            :         {       /* MD5 HMAC */
     219                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     220                 :            :                 {.sym = {
     221                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     222                 :            :                         {.auth = {
     223                 :            :                                 .algo = RTE_CRYPTO_AUTH_MD5_HMAC,
     224                 :            :                                 .block_size = 64,
     225                 :            :                                 .key_size = {
     226                 :            :                                         .min = 16,
     227                 :            :                                         .max = 16,
     228                 :            :                                         .increment = 0
     229                 :            :                                 },
     230                 :            :                                 .digest_size = {
     231                 :            :                                         .min = 12,
     232                 :            :                                         .max = 12,
     233                 :            :                                         .increment = 0
     234                 :            :                                 },
     235                 :            :                         }, }
     236                 :            :                 }, }
     237                 :            :         },
     238                 :            :         {       /* SHA1 HMAC */
     239                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     240                 :            :                 {.sym = {
     241                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     242                 :            :                         {.auth = {
     243                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA1_HMAC,
     244                 :            :                                 .block_size = 64,
     245                 :            :                                 .key_size = {
     246                 :            :                                         .min = 20,
     247                 :            :                                         .max = 64,
     248                 :            :                                         .increment = 1
     249                 :            :                                 },
     250                 :            :                                 .digest_size = {
     251                 :            :                                         .min = 12,
     252                 :            :                                         .max = 12,
     253                 :            :                                         .increment = 0
     254                 :            :                                 },
     255                 :            :                         }, }
     256                 :            :                 }, }
     257                 :            :         },
     258                 :            :         {       /* SHA256 HMAC */
     259                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     260                 :            :                 {.sym = {
     261                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     262                 :            :                         {.auth = {
     263                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA256_HMAC,
     264                 :            :                                 .block_size = 64,
     265                 :            :                                 .key_size = {
     266                 :            :                                         .min = 1,
     267                 :            :                                         .max = 1024,
     268                 :            :                                         .increment = 1
     269                 :            :                                 },
     270                 :            :                                 .digest_size = {
     271                 :            :                                         .min = 16,
     272                 :            :                                         .max = 32,
     273                 :            :                                         .increment = 16
     274                 :            :                                 },
     275                 :            :                         }, }
     276                 :            :                 }, }
     277                 :            :         },
     278                 :            :         {       /* SHA384 HMAC */
     279                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     280                 :            :                 {.sym = {
     281                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     282                 :            :                         {.auth = {
     283                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA384_HMAC,
     284                 :            :                                 .block_size = 64,
     285                 :            :                                 .key_size = {
     286                 :            :                                         .min = 1,
     287                 :            :                                         .max = 1024,
     288                 :            :                                         .increment = 1
     289                 :            :                                 },
     290                 :            :                                 .digest_size = {
     291                 :            :                                         .min = 24,
     292                 :            :                                         .max = 48,
     293                 :            :                                         .increment = 24
     294                 :            :                                         },
     295                 :            :                         }, }
     296                 :            :                 }, }
     297                 :            :         },
     298                 :            :         {       /* SHA512 HMAC */
     299                 :            :                 .op = RTE_CRYPTO_OP_TYPE_SYMMETRIC,
     300                 :            :                 {.sym = {
     301                 :            :                         .xform_type = RTE_CRYPTO_SYM_XFORM_AUTH,
     302                 :            :                         {.auth = {
     303                 :            :                                 .algo = RTE_CRYPTO_AUTH_SHA512_HMAC,
     304                 :            :                                 .block_size = 128,
     305                 :            :                                 .key_size = {
     306                 :            :                                         .min = 1,
     307                 :            :                                         .max = 1024,
     308                 :            :                                         .increment = 1
     309                 :            :                                 },
     310                 :            :                                 .digest_size = {
     311                 :            :                                         .min = 32,
     312                 :            :                                         .max = 64,
     313                 :            :                                         .increment = 32
     314                 :            :                                 },
     315                 :            :                         }, }
     316                 :            :                 }, }
     317                 :            :         },
     318                 :            :         RTE_CRYPTODEV_END_OF_CAPABILITIES_LIST()
     319                 :            : };
     320                 :            : 
     321                 :            : static const struct rte_security_capability cn9k_eth_sec_capabilities[] = {
     322                 :            :         {       /* IPsec Inline Protocol ESP Tunnel Ingress */
     323                 :            :                 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
     324                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
     325                 :            :                 .ipsec = {
     326                 :            :                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
     327                 :            :                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
     328                 :            :                         .direction = RTE_SECURITY_IPSEC_SA_DIR_INGRESS,
     329                 :            :                         .replay_win_sz_max = CNXK_ON_AR_WIN_SIZE_MAX,
     330                 :            :                         .options = {
     331                 :            :                                         .udp_encap = 1,
     332                 :            :                                         .esn = 1
     333                 :            :                                 }
     334                 :            :                 },
     335                 :            :                 .crypto_capabilities = cn9k_eth_sec_crypto_caps,
     336                 :            :                 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
     337                 :            :         },
     338                 :            :         {       /* IPsec Inline Protocol ESP Tunnel Egress */
     339                 :            :                 .action = RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL,
     340                 :            :                 .protocol = RTE_SECURITY_PROTOCOL_IPSEC,
     341                 :            :                 .ipsec = {
     342                 :            :                         .proto = RTE_SECURITY_IPSEC_SA_PROTO_ESP,
     343                 :            :                         .mode = RTE_SECURITY_IPSEC_SA_MODE_TUNNEL,
     344                 :            :                         .direction = RTE_SECURITY_IPSEC_SA_DIR_EGRESS,
     345                 :            :                         .options = {
     346                 :            :                                         .udp_encap = 1,
     347                 :            :                                         .iv_gen_disable = 1,
     348                 :            :                                         .esn = 1
     349                 :            :                                 }
     350                 :            :                 },
     351                 :            :                 .crypto_capabilities = cn9k_eth_sec_crypto_caps,
     352                 :            :                 .ol_flags = RTE_SECURITY_TX_OLOAD_NEED_MDATA
     353                 :            :         },
     354                 :            :         {
     355                 :            :                 .action = RTE_SECURITY_ACTION_TYPE_NONE
     356                 :            :         }
     357                 :            : };
     358                 :            : 
     359                 :            : static inline int
     360                 :          0 : ar_window_init(struct cn9k_inb_priv_data *inb_priv)
     361                 :            : {
     362         [ #  # ]:          0 :         if (inb_priv->replay_win_sz > CNXK_ON_AR_WIN_SIZE_MAX) {
     363                 :          0 :                 plt_err("Replay window size:%u is not supported",
     364                 :            :                         inb_priv->replay_win_sz);
     365                 :          0 :                 return -ENOTSUP;
     366                 :            :         }
     367                 :            : 
     368                 :            :         rte_spinlock_init(&inb_priv->ar.lock);
     369                 :            :         /*
     370                 :            :          * Set window bottom to 1, base and top to size of
     371                 :            :          * window
     372                 :            :          */
     373                 :          0 :         inb_priv->ar.winb = 1;
     374                 :          0 :         inb_priv->ar.wint = inb_priv->replay_win_sz;
     375                 :          0 :         inb_priv->ar.base = inb_priv->replay_win_sz;
     376                 :            : 
     377                 :          0 :         return 0;
     378                 :            : }
     379                 :            : 
     380                 :            : static void
     381                 :          0 : outb_dbg_iv_update(struct roc_ie_on_common_sa *common_sa, const char *__iv_str)
     382                 :            : {
     383                 :          0 :         uint8_t *iv_dbg = common_sa->iv.aes_iv;
     384                 :          0 :         char *iv_str = strdup(__iv_str);
     385                 :            :         char *iv_b = NULL;
     386                 :            :         char *save;
     387                 :            :         int i, iv_len = ROC_IE_ON_MAX_IV_LEN;
     388                 :            : 
     389         [ #  # ]:          0 :         if (!iv_str)
     390                 :          0 :                 return;
     391                 :            : 
     392         [ #  # ]:          0 :         if (common_sa->ctl.enc_type == ROC_IE_OT_SA_ENC_AES_GCM ||
     393                 :          0 :             common_sa->ctl.enc_type == ROC_IE_OT_SA_ENC_AES_CTR ||
     394         [ #  # ]:          0 :             common_sa->ctl.enc_type == ROC_IE_OT_SA_ENC_AES_CCM ||
     395         [ #  # ]:          0 :             common_sa->ctl.auth_type == ROC_IE_OT_SA_AUTH_AES_GMAC) {
     396                 :          0 :                 iv_dbg = common_sa->iv.gcm.iv;
     397                 :            :                 iv_len = 8;
     398                 :            :         }
     399                 :            : 
     400                 :          0 :         memset(iv_dbg, 0, iv_len);
     401         [ #  # ]:          0 :         for (i = 0; i < iv_len; i++) {
     402         [ #  # ]:          0 :                 iv_b = strtok_r(i ? NULL : iv_str, ",", &save);
     403         [ #  # ]:          0 :                 if (!iv_b)
     404                 :            :                         break;
     405                 :          0 :                 iv_dbg[i] = strtoul(iv_b, NULL, 0);
     406                 :            :         }
     407                 :            : 
     408                 :          0 :         free(iv_str);
     409                 :            : }
     410                 :            : 
     411                 :            : static int
     412         [ #  # ]:          0 : cn9k_eth_sec_session_update(void *device,
     413                 :            :                             struct rte_security_session *sess,
     414                 :            :                             struct rte_security_session_conf *conf)
     415                 :            : {
     416                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
     417                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     418                 :            :         struct rte_security_ipsec_xform *ipsec;
     419                 :            :         struct cn9k_outb_priv_data *outb_priv;
     420                 :            :         struct cnxk_ipsec_outb_rlens *rlens;
     421                 :            :         struct cn9k_sec_sess_priv sess_priv;
     422                 :            :         struct rte_crypto_sym_xform *crypto;
     423                 :            :         struct cnxk_eth_sec_sess *eth_sec;
     424                 :            :         struct roc_ie_on_outb_sa *outb_sa;
     425                 :            :         rte_spinlock_t *lock;
     426                 :          0 :         char tbuf[128] = {0};
     427                 :            :         const char *iv_str;
     428                 :            :         uint32_t sa_idx;
     429                 :            :         int ctx_len;
     430                 :            :         int rc = 0;
     431                 :            : 
     432         [ #  # ]:          0 :         if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)
     433                 :            :                 return -ENOTSUP;
     434                 :            : 
     435         [ #  # ]:          0 :         if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
     436                 :            :                 return -ENOTSUP;
     437                 :            : 
     438         [ #  # ]:          0 :         if (rte_security_dynfield_register() < 0)
     439                 :            :                 return -ENOTSUP;
     440                 :            : 
     441                 :          0 :         ipsec = &conf->ipsec;
     442                 :          0 :         crypto = conf->crypto_xform;
     443                 :            : 
     444         [ #  # ]:          0 :         if (ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS)
     445                 :            :                 return -ENOTSUP;
     446                 :            : 
     447                 :          0 :         eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
     448         [ #  # ]:          0 :         if (!eth_sec)
     449                 :            :                 return -ENOENT;
     450                 :            : 
     451                 :          0 :         eth_sec->spi = conf->ipsec.spi;
     452                 :            : 
     453                 :          0 :         lock = &dev->outb.lock;
     454                 :            :         rte_spinlock_lock(lock);
     455                 :            : 
     456                 :          0 :         outb_sa = eth_sec->sa;
     457                 :            :         outb_priv = roc_nix_inl_on_ipsec_outb_sa_sw_rsvd(outb_sa);
     458                 :          0 :         sa_idx = outb_priv->sa_idx;
     459                 :            : 
     460                 :            :         /* Disable SA */
     461                 :          0 :         outb_sa->common_sa.ctl.valid = 0;
     462                 :            : 
     463                 :            :         /* Sync SA content */
     464                 :            :         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
     465                 :            : 
     466                 :          0 :         sess_priv.u64 = 0;
     467                 :            :         memset(outb_sa, 0, sizeof(struct roc_ie_on_outb_sa));
     468                 :            : 
     469                 :            :         /* Fill outbound sa params */
     470                 :          0 :         rc = cnxk_on_ipsec_outb_sa_create(ipsec, crypto, outb_sa);
     471         [ #  # ]:          0 :         if (rc < 0) {
     472                 :            :                 snprintf(tbuf, sizeof(tbuf),
     473                 :            :                          "Failed to init outbound sa, rc=%d", rc);
     474                 :          0 :                 rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
     475                 :          0 :                 goto exit;
     476                 :            :         }
     477                 :            : 
     478                 :            :         ctx_len = rc;
     479                 :          0 :         rc = roc_nix_inl_ctx_write(&dev->nix, outb_sa, outb_sa, false,
     480                 :            :                                    ctx_len);
     481         [ #  # ]:          0 :         if (rc) {
     482                 :            :                 snprintf(tbuf, sizeof(tbuf),
     483                 :            :                          "Failed to init outbound sa, rc=%d", rc);
     484                 :          0 :                 rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
     485                 :          0 :                 goto exit;
     486                 :            :         }
     487                 :            : 
     488                 :            :         /* When IV is provided by the application,
     489                 :            :          * copy the IV to context and enable explicit IV flag in context.
     490                 :            :          */
     491         [ #  # ]:          0 :         if (ipsec->options.iv_gen_disable == 1) {
     492                 :          0 :                 outb_sa->common_sa.ctl.explicit_iv_en = 1;
     493                 :          0 :                 iv_str = getenv("ETH_SEC_IV_OVR");
     494         [ #  # ]:          0 :                 if (iv_str)
     495                 :          0 :                         outb_dbg_iv_update(&outb_sa->common_sa, iv_str);
     496                 :            :         }
     497                 :            : 
     498                 :          0 :         outb_priv->userdata = conf->userdata;
     499                 :          0 :         outb_priv->eth_sec = eth_sec;
     500                 :            :         /* Start sequence number with 1 */
     501                 :          0 :         outb_priv->esn = ipsec->esn.value;
     502                 :            : 
     503         [ #  # ]:          0 :         memcpy(&outb_priv->nonce, outb_sa->common_sa.iv.gcm.nonce, 4);
     504         [ #  # ]:          0 :         if (outb_sa->common_sa.ctl.enc_type == ROC_IE_ON_SA_ENC_AES_GCM)
     505                 :          0 :                 outb_priv->copy_salt = 1;
     506                 :            : 
     507                 :          0 :         rlens = &outb_priv->rlens;
     508                 :            :         /* Save rlen info */
     509                 :          0 :         cnxk_ipsec_outb_rlens_get(rlens, ipsec, crypto);
     510                 :            : 
     511                 :          0 :         sess_priv.sa_idx = outb_priv->sa_idx;
     512                 :          0 :         sess_priv.roundup_byte = rlens->roundup_byte;
     513                 :          0 :         sess_priv.roundup_len = rlens->roundup_len;
     514                 :          0 :         sess_priv.partial_len = rlens->partial_len;
     515                 :            : 
     516                 :            :         /* Pointer from eth_sec -> outb_sa */
     517                 :          0 :         eth_sec->sa = outb_sa;
     518                 :          0 :         eth_sec->sess = sess;
     519                 :          0 :         eth_sec->sa_idx = sa_idx;
     520                 :          0 :         eth_sec->spi = ipsec->spi;
     521                 :            : 
     522                 :            :         /* Sync SA content */
     523                 :            :         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
     524                 :            : 
     525                 :            :         rte_spinlock_unlock(lock);
     526                 :            : 
     527                 :          0 :         plt_nix_dbg("Created outbound session with spi=%u, sa_idx=%u",
     528                 :            :                     eth_sec->spi, eth_sec->sa_idx);
     529                 :            : 
     530                 :            :         /*
     531                 :            :          * Update fast path info in priv area.
     532                 :            :          */
     533                 :          0 :         sess->fast_mdata = sess_priv.u64;
     534                 :            : 
     535                 :          0 :         return 0;
     536                 :          0 : exit:
     537                 :            :         rte_spinlock_unlock(lock);
     538         [ #  # ]:          0 :         if (rc)
     539                 :          0 :                 plt_err("%s", tbuf);
     540                 :            :         return rc;
     541                 :            : }
     542                 :            : 
     543                 :            : static int
     544                 :          0 : cn9k_eth_sec_session_create(void *device,
     545                 :            :                             struct rte_security_session_conf *conf,
     546                 :            :                             struct rte_security_session *sess)
     547                 :            : {
     548         [ #  # ]:          0 :         struct cnxk_eth_sec_sess *eth_sec = SECURITY_GET_SESS_PRIV(sess);
     549                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
     550                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     551                 :            :         struct rte_security_ipsec_xform *ipsec;
     552                 :            :         struct cn9k_sec_sess_priv sess_priv;
     553                 :            :         struct rte_crypto_sym_xform *crypto;
     554                 :          0 :         struct roc_nix *nix = &dev->nix;
     555                 :            :         rte_spinlock_t *lock;
     556                 :          0 :         char tbuf[128] = {0};
     557                 :            :         bool inbound;
     558                 :            :         int ctx_len;
     559                 :            :         int rc = 0;
     560                 :            : 
     561         [ #  # ]:          0 :         if (conf->action_type != RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL)
     562                 :            :                 return -ENOTSUP;
     563                 :            : 
     564         [ #  # ]:          0 :         if (conf->protocol != RTE_SECURITY_PROTOCOL_IPSEC)
     565                 :            :                 return -ENOTSUP;
     566                 :            : 
     567         [ #  # ]:          0 :         if (rte_security_dynfield_register() < 0)
     568                 :            :                 return -ENOTSUP;
     569                 :            : 
     570                 :          0 :         ipsec = &conf->ipsec;
     571                 :          0 :         crypto = conf->crypto_xform;
     572                 :          0 :         inbound = !!(ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_INGRESS);
     573                 :            : 
     574                 :            :         /* Search if a session already exists */
     575         [ #  # ]:          0 :         if (cnxk_eth_sec_sess_get_by_spi(dev, ipsec->spi, inbound)) {
     576         [ #  # ]:          0 :                 plt_err("%s SA with SPI %u already in use",
     577                 :            :                         inbound ? "Inbound" : "Outbound", ipsec->spi);
     578                 :          0 :                 return -EEXIST;
     579                 :            :         }
     580                 :            : 
     581         [ #  # ]:          0 :         lock = inbound ? &dev->inb.lock : &dev->outb.lock;
     582                 :            :         rte_spinlock_lock(lock);
     583                 :            : 
     584                 :            :         memset(eth_sec, 0, sizeof(struct cnxk_eth_sec_sess));
     585                 :          0 :         sess_priv.u64 = 0;
     586                 :            : 
     587         [ #  # ]:          0 :         if (!dev->outb.lf_base) {
     588                 :          0 :                 plt_err("Could not allocate security session private data");
     589                 :            :                 rte_spinlock_unlock(lock);
     590                 :          0 :                 return -ENOMEM;
     591                 :            :         }
     592                 :            : 
     593         [ #  # ]:          0 :         if (inbound) {
     594                 :            :                 struct cn9k_inb_priv_data *inb_priv;
     595                 :            :                 struct roc_ie_on_inb_sa *inb_sa;
     596                 :            :                 uint32_t spi_mask;
     597                 :            : 
     598                 :            :                 PLT_STATIC_ASSERT(sizeof(struct cn9k_inb_priv_data) <
     599                 :            :                                   ROC_NIX_INL_ON_IPSEC_INB_SW_RSVD);
     600                 :            : 
     601                 :          0 :                 spi_mask = roc_nix_inl_inb_spi_range(nix, false, NULL, NULL);
     602                 :            : 
     603                 :            :                 /* Get Inbound SA from NIX_RX_IPSEC_SA_BASE. Assume no inline
     604                 :            :                  * device always for CN9K.
     605                 :            :                  */
     606                 :          0 :                 inb_sa = (struct roc_ie_on_inb_sa *)roc_nix_inl_inb_sa_get(nix, false, ipsec->spi);
     607         [ #  # ]:          0 :                 if (!inb_sa) {
     608                 :            :                         snprintf(tbuf, sizeof(tbuf),
     609                 :            :                                  "Failed to create ingress sa");
     610                 :            :                         rc = -EFAULT;
     611                 :          0 :                         goto err;
     612                 :            :                 }
     613                 :            : 
     614                 :            :                 /* Check if SA is already in use */
     615         [ #  # ]:          0 :                 if (inb_sa->common_sa.ctl.valid) {
     616                 :          0 :                         snprintf(tbuf, sizeof(tbuf),
     617                 :            :                                  "Inbound SA with SPI %u already in use",
     618                 :            :                                  ipsec->spi);
     619                 :            :                         rc = -EBUSY;
     620                 :          0 :                         goto err;
     621                 :            :                 }
     622                 :            : 
     623                 :            :                 memset(inb_sa, 0, sizeof(struct roc_ie_on_inb_sa));
     624                 :            : 
     625                 :            :                 /* Fill inbound sa params */
     626                 :          0 :                 rc = cnxk_on_ipsec_inb_sa_create(ipsec, crypto, inb_sa);
     627         [ #  # ]:          0 :                 if (rc < 0) {
     628                 :            :                         snprintf(tbuf, sizeof(tbuf),
     629                 :            :                                  "Failed to init inbound sa, rc=%d", rc);
     630                 :          0 :                         goto err;
     631                 :            :                 }
     632                 :            : 
     633                 :            :                 ctx_len = rc;
     634                 :            :                 inb_priv = roc_nix_inl_on_ipsec_inb_sa_sw_rsvd(inb_sa);
     635                 :            :                 /* Back pointer to get eth_sec */
     636                 :          0 :                 inb_priv->eth_sec = eth_sec;
     637                 :            : 
     638                 :            :                 /* Save userdata in inb private area */
     639                 :          0 :                 inb_priv->userdata = conf->userdata;
     640                 :            : 
     641                 :          0 :                 inb_priv->replay_win_sz = ipsec->replay_win_sz;
     642         [ #  # ]:          0 :                 if (inb_priv->replay_win_sz) {
     643                 :          0 :                         rc = ar_window_init(inb_priv);
     644         [ #  # ]:          0 :                         if (rc)
     645                 :          0 :                                 goto err;
     646                 :            :                 }
     647                 :            : 
     648                 :            :                 /* Prepare session priv */
     649                 :          0 :                 sess_priv.inb_sa = 1;
     650                 :          0 :                 sess_priv.sa_idx = ipsec->spi & spi_mask;
     651                 :            : 
     652                 :            :                 /* Pointer from eth_sec -> inb_sa */
     653                 :          0 :                 eth_sec->sa = inb_sa;
     654                 :          0 :                 eth_sec->sess = sess;
     655                 :          0 :                 eth_sec->sa_idx = ipsec->spi & spi_mask;
     656                 :          0 :                 eth_sec->spi = ipsec->spi;
     657                 :          0 :                 eth_sec->inb = true;
     658                 :            : 
     659                 :          0 :                 TAILQ_INSERT_TAIL(&dev->inb.list, eth_sec, entry);
     660                 :          0 :                 dev->inb.nb_sess++;
     661                 :            :         } else {
     662                 :            :                 struct cn9k_outb_priv_data *outb_priv;
     663                 :          0 :                 uintptr_t sa_base = dev->outb.sa_base;
     664                 :            :                 struct cnxk_ipsec_outb_rlens *rlens;
     665                 :            :                 struct roc_ie_on_outb_sa *outb_sa;
     666                 :            :                 const char *iv_str;
     667                 :            :                 uint32_t sa_idx;
     668                 :            : 
     669                 :            :                 PLT_STATIC_ASSERT(sizeof(struct cn9k_outb_priv_data) <
     670                 :            :                                   ROC_NIX_INL_ON_IPSEC_OUTB_SW_RSVD);
     671                 :            : 
     672                 :            :                 /* Alloc an sa index */
     673                 :          0 :                 rc = cnxk_eth_outb_sa_idx_get(dev, &sa_idx, 0);
     674         [ #  # ]:          0 :                 if (rc)
     675                 :          0 :                         goto err;
     676                 :            : 
     677                 :          0 :                 outb_sa = roc_nix_inl_on_ipsec_outb_sa(sa_base, sa_idx);
     678                 :            :                 outb_priv = roc_nix_inl_on_ipsec_outb_sa_sw_rsvd(outb_sa);
     679                 :          0 :                 rlens = &outb_priv->rlens;
     680                 :            : 
     681                 :            :                 memset(outb_sa, 0, sizeof(struct roc_ie_on_outb_sa));
     682                 :            : 
     683                 :            :                 /* Fill outbound sa params */
     684                 :          0 :                 rc = cnxk_on_ipsec_outb_sa_create(ipsec, crypto, outb_sa);
     685         [ #  # ]:          0 :                 if (rc < 0) {
     686                 :            :                         snprintf(tbuf, sizeof(tbuf),
     687                 :            :                                  "Failed to init outbound sa, rc=%d", rc);
     688                 :          0 :                         rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
     689                 :          0 :                         goto err;
     690                 :            :                 }
     691                 :            : 
     692                 :            :                 ctx_len = rc;
     693                 :          0 :                 rc = roc_nix_inl_ctx_write(&dev->nix, outb_sa, outb_sa, inbound,
     694                 :            :                                            ctx_len);
     695         [ #  # ]:          0 :                 if (rc) {
     696                 :            :                         snprintf(tbuf, sizeof(tbuf),
     697                 :            :                                  "Failed to init outbound sa, rc=%d", rc);
     698                 :          0 :                         rc |= cnxk_eth_outb_sa_idx_put(dev, sa_idx);
     699                 :          0 :                         goto err;
     700                 :            :                 }
     701                 :            : 
     702                 :            :                 /* When IV is provided by the application,
     703                 :            :                  * copy the IV to context and enable explicit IV flag in context.
     704                 :            :                  */
     705         [ #  # ]:          0 :                 if (ipsec->options.iv_gen_disable == 1) {
     706                 :          0 :                         outb_sa->common_sa.ctl.explicit_iv_en = 1;
     707                 :          0 :                         iv_str = getenv("ETH_SEC_IV_OVR");
     708         [ #  # ]:          0 :                         if (iv_str)
     709                 :          0 :                                 outb_dbg_iv_update(&outb_sa->common_sa, iv_str);
     710                 :            :                 }
     711                 :            : 
     712                 :            :                 /* Save userdata */
     713                 :          0 :                 outb_priv->userdata = conf->userdata;
     714                 :          0 :                 outb_priv->sa_idx = sa_idx;
     715                 :          0 :                 outb_priv->eth_sec = eth_sec;
     716                 :            :                 /* Start sequence number with 1 */
     717                 :          0 :                 outb_priv->seq = 1;
     718                 :            : 
     719         [ #  # ]:          0 :                 memcpy(&outb_priv->nonce, outb_sa->common_sa.iv.gcm.nonce, 4);
     720         [ #  # ]:          0 :                 if (outb_sa->common_sa.ctl.enc_type == ROC_IE_ON_SA_ENC_AES_GCM)
     721                 :          0 :                         outb_priv->copy_salt = 1;
     722                 :            : 
     723                 :            :                 /* Save rlen info */
     724                 :          0 :                 cnxk_ipsec_outb_rlens_get(rlens, ipsec, crypto);
     725                 :            : 
     726                 :          0 :                 sess_priv.sa_idx = outb_priv->sa_idx;
     727                 :          0 :                 sess_priv.roundup_byte = rlens->roundup_byte;
     728                 :          0 :                 sess_priv.roundup_len = rlens->roundup_len;
     729                 :          0 :                 sess_priv.partial_len = rlens->partial_len;
     730                 :            : 
     731                 :            :                 /* Pointer from eth_sec -> outb_sa */
     732                 :          0 :                 eth_sec->sa = outb_sa;
     733                 :          0 :                 eth_sec->sess = sess;
     734                 :          0 :                 eth_sec->sa_idx = sa_idx;
     735                 :          0 :                 eth_sec->spi = ipsec->spi;
     736                 :            : 
     737                 :          0 :                 TAILQ_INSERT_TAIL(&dev->outb.list, eth_sec, entry);
     738                 :          0 :                 dev->outb.nb_sess++;
     739                 :            :         }
     740                 :            : 
     741                 :            :         /* Sync SA content */
     742                 :            :         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
     743                 :            : 
     744                 :            :         rte_spinlock_unlock(lock);
     745                 :            : 
     746         [ #  # ]:          0 :         plt_nix_dbg("Created %s session with spi=%u, sa_idx=%u",
     747                 :            :                     inbound ? "inbound" : "outbound", eth_sec->spi,
     748                 :            :                     eth_sec->sa_idx);
     749                 :            :         /*
     750                 :            :          * Update fast path info in priv area.
     751                 :            :          */
     752                 :          0 :         sess->fast_mdata = sess_priv.u64;
     753                 :            : 
     754                 :          0 :         return 0;
     755                 :          0 : err:
     756                 :            :         rte_spinlock_unlock(lock);
     757         [ #  # ]:          0 :         if (rc)
     758                 :          0 :                 plt_err("%s", tbuf);
     759                 :            :         return rc;
     760                 :            : }
     761                 :            : 
     762                 :            : static int
     763                 :          0 : cn9k_eth_sec_session_destroy(void *device, struct rte_security_session *sess)
     764                 :            : {
     765                 :            :         struct rte_eth_dev *eth_dev = (struct rte_eth_dev *)device;
     766                 :            :         struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
     767                 :            :         struct cnxk_eth_sec_sess *eth_sec;
     768                 :            :         struct roc_ie_on_outb_sa *outb_sa;
     769                 :            :         struct roc_ie_on_inb_sa *inb_sa;
     770                 :            :         rte_spinlock_t *lock;
     771                 :            : 
     772                 :          0 :         eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, sess);
     773         [ #  # ]:          0 :         if (!eth_sec)
     774                 :            :                 return -ENOENT;
     775                 :            : 
     776         [ #  # ]:          0 :         lock = eth_sec->inb ? &dev->inb.lock : &dev->outb.lock;
     777                 :            :         rte_spinlock_lock(lock);
     778                 :            : 
     779         [ #  # ]:          0 :         if (eth_sec->inb) {
     780                 :          0 :                 inb_sa = eth_sec->sa;
     781                 :            :                 /* Disable SA */
     782                 :          0 :                 inb_sa->common_sa.ctl.valid = 0;
     783                 :            : 
     784         [ #  # ]:          0 :                 TAILQ_REMOVE(&dev->inb.list, eth_sec, entry);
     785                 :          0 :                 dev->inb.nb_sess--;
     786                 :            :         } else {
     787                 :          0 :                 outb_sa = eth_sec->sa;
     788                 :            :                 /* Disable SA */
     789                 :          0 :                 outb_sa->common_sa.ctl.valid = 0;
     790                 :            : 
     791                 :            :                 /* Release Outbound SA index */
     792                 :          0 :                 cnxk_eth_outb_sa_idx_put(dev, eth_sec->sa_idx);
     793         [ #  # ]:          0 :                 TAILQ_REMOVE(&dev->outb.list, eth_sec, entry);
     794                 :          0 :                 dev->outb.nb_sess--;
     795                 :            :         }
     796                 :            : 
     797                 :            :         /* Sync SA content */
     798                 :            :         plt_atomic_thread_fence(__ATOMIC_ACQ_REL);
     799                 :            : 
     800                 :            :         rte_spinlock_unlock(lock);
     801                 :            : 
     802         [ #  # ]:          0 :         plt_nix_dbg("Destroyed %s session with spi=%u, sa_idx=%u",
     803                 :            :                     eth_sec->inb ? "inbound" : "outbound", eth_sec->spi,
     804                 :            :                     eth_sec->sa_idx);
     805                 :            : 
     806                 :          0 :         return 0;
     807                 :            : }
     808                 :            : 
     809                 :            : static const struct rte_security_capability *
     810                 :          0 : cn9k_eth_sec_capabilities_get(void *device __rte_unused)
     811                 :            : {
     812                 :          0 :         return cn9k_eth_sec_capabilities;
     813                 :            : }
     814                 :            : 
     815                 :            : void
     816                 :          0 : cn9k_eth_sec_ops_override(void)
     817                 :            : {
     818                 :            :         static int init_once;
     819                 :            : 
     820         [ #  # ]:          0 :         if (init_once)
     821                 :            :                 return;
     822                 :          0 :         init_once = 1;
     823                 :            : 
     824                 :            :         /* Update platform specific ops */
     825                 :          0 :         cnxk_eth_sec_ops.session_create = cn9k_eth_sec_session_create;
     826                 :          0 :         cnxk_eth_sec_ops.session_update = cn9k_eth_sec_session_update;
     827                 :          0 :         cnxk_eth_sec_ops.session_destroy = cn9k_eth_sec_session_destroy;
     828                 :          0 :         cnxk_eth_sec_ops.capabilities_get = cn9k_eth_sec_capabilities_get;
     829                 :            : }

Generated by: LCOV version 1.14