LCOV - code coverage report
Current view: top level - drivers/common/cnxk - cnxk_security.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 885 0.0 %
Date: 2026-11-01 19:11:22 Functions: 0 22 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 576 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <eal_export.h>
       6                 :            : #include <rte_udp.h>
       7                 :            : 
       8                 :            : #include "roc_api.h"
       9                 :            : 
      10                 :            : #include "cnxk_security.h"
      11                 :            : 
      12                 :            : static int
      13                 :          0 : ot_ipsec_sa_common_param_fill(union roc_ot_ipsec_sa_word2 *w2, uint8_t *cipher_key,
      14                 :            :                               uint8_t *salt_key, uint8_t *hmac_opad_ipad,
      15                 :            :                               struct rte_security_ipsec_xform *ipsec_xfrm,
      16                 :            :                               struct rte_crypto_sym_xform *crypto_xfrm)
      17                 :            : {
      18                 :            :         struct rte_crypto_sym_xform *auth_xfrm, *cipher_xfrm;
      19                 :            :         const uint8_t *key = NULL;
      20                 :            :         uint8_t ccm_flag = 0;
      21                 :            :         uint32_t *tmp_salt;
      22                 :            :         uint64_t *tmp_key;
      23                 :            :         int i, length = 0;
      24                 :            : 
      25                 :            :         /* Set direction */
      26         [ #  # ]:          0 :         if (ipsec_xfrm->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
      27                 :          0 :                 w2->s.dir = ROC_IE_SA_DIR_OUTBOUND;
      28                 :            :         else
      29                 :          0 :                 w2->s.dir = ROC_IE_SA_DIR_INBOUND;
      30                 :            : 
      31         [ #  # ]:          0 :         if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
      32                 :            :                 auth_xfrm = crypto_xfrm;
      33                 :          0 :                 cipher_xfrm = crypto_xfrm->next;
      34                 :            :         } else {
      35                 :            :                 cipher_xfrm = crypto_xfrm;
      36                 :          0 :                 auth_xfrm = crypto_xfrm->next;
      37                 :            :         }
      38                 :            : 
      39                 :            :         /* Set protocol - ESP vs AH */
      40      [ #  #  # ]:          0 :         switch (ipsec_xfrm->proto) {
      41                 :          0 :         case RTE_SECURITY_IPSEC_SA_PROTO_ESP:
      42                 :          0 :                 w2->s.protocol = ROC_IE_SA_PROTOCOL_ESP;
      43                 :          0 :                 break;
      44                 :          0 :         case RTE_SECURITY_IPSEC_SA_PROTO_AH:
      45                 :          0 :                 w2->s.protocol = ROC_IE_SA_PROTOCOL_AH;
      46                 :          0 :                 break;
      47                 :            :         default:
      48                 :            :                 return -EINVAL;
      49                 :            :         }
      50                 :            : 
      51                 :            :         /* Set mode - transport vs tunnel */
      52      [ #  #  # ]:          0 :         switch (ipsec_xfrm->mode) {
      53                 :          0 :         case RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT:
      54                 :          0 :                 w2->s.mode = ROC_IE_SA_MODE_TRANSPORT;
      55                 :          0 :                 break;
      56                 :          0 :         case RTE_SECURITY_IPSEC_SA_MODE_TUNNEL:
      57                 :          0 :                 w2->s.mode = ROC_IE_SA_MODE_TUNNEL;
      58                 :          0 :                 break;
      59                 :            :         default:
      60                 :            :                 return -EINVAL;
      61                 :            :         }
      62                 :            : 
      63                 :            :         /* Set encryption algorithm */
      64         [ #  # ]:          0 :         if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
      65                 :          0 :                 key = crypto_xfrm->aead.key.data;
      66                 :          0 :                 length = crypto_xfrm->aead.key.length;
      67                 :            : 
      68      [ #  #  # ]:          0 :                 switch (crypto_xfrm->aead.algo) {
      69                 :          0 :                 case RTE_CRYPTO_AEAD_AES_GCM:
      70                 :          0 :                         w2->s.enc_type = ROC_IE_SA_ENC_AES_GCM;
      71                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_NULL;
      72         [ #  # ]:          0 :                         memcpy(salt_key, &ipsec_xfrm->salt, 4);
      73                 :            :                         tmp_salt = (uint32_t *)salt_key;
      74         [ #  # ]:          0 :                         *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
      75                 :          0 :                         break;
      76                 :          0 :                 case RTE_CRYPTO_AEAD_AES_CCM:
      77                 :          0 :                         w2->s.enc_type = ROC_IE_SA_ENC_AES_CCM;
      78                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_NULL;
      79                 :            :                         ccm_flag = 0x07 & ~ROC_CPT_AES_CCM_CTR_LEN;
      80                 :          0 :                         *salt_key = ccm_flag;
      81         [ #  # ]:          0 :                         memcpy(PLT_PTR_ADD(salt_key, 1), &ipsec_xfrm->salt, 3);
      82                 :            :                         tmp_salt = (uint32_t *)salt_key;
      83         [ #  # ]:          0 :                         *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
      84                 :          0 :                         break;
      85                 :            :                 default:
      86                 :            :                         return -ENOTSUP;
      87                 :            :                 }
      88                 :            :         } else {
      89         [ #  # ]:          0 :                 if (cipher_xfrm != NULL) {
      90   [ #  #  #  #  :          0 :                         switch (cipher_xfrm->cipher.algo) {
                      # ]
      91                 :          0 :                         case RTE_CRYPTO_CIPHER_NULL:
      92                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_NULL;
      93                 :          0 :                                 break;
      94                 :          0 :                         case RTE_CRYPTO_CIPHER_AES_CBC:
      95                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_AES_CBC;
      96                 :          0 :                                 break;
      97                 :          0 :                         case RTE_CRYPTO_CIPHER_AES_CTR:
      98                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_AES_CTR;
      99         [ #  # ]:          0 :                                 memcpy(salt_key, &ipsec_xfrm->salt, 4);
     100                 :            :                                 tmp_salt = (uint32_t *)salt_key;
     101         [ #  # ]:          0 :                                 *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
     102                 :          0 :                                 break;
     103                 :          0 :                         case RTE_CRYPTO_CIPHER_3DES_CBC:
     104                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_3DES_CBC;
     105                 :          0 :                                 break;
     106                 :            :                         default:
     107                 :            :                                 return -ENOTSUP;
     108                 :            :                         }
     109                 :            : 
     110                 :          0 :                         key = cipher_xfrm->cipher.key.data;
     111                 :          0 :                         length = cipher_xfrm->cipher.key.length;
     112                 :            :                 }
     113                 :            : 
     114   [ #  #  #  #  :          0 :                 switch (auth_xfrm->auth.algo) {
             #  #  #  # ]
     115                 :          0 :                 case RTE_CRYPTO_AUTH_NULL:
     116   [ #  #  #  # ]:          0 :                         if (w2->s.dir == ROC_IE_SA_DIR_INBOUND && ipsec_xfrm->replay_win_sz) {
     117                 :          0 :                                 plt_err("anti-replay can't be supported with integrity service disabled");
     118                 :          0 :                                 return -EINVAL;
     119                 :            :                         }
     120                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_NULL;
     121                 :          0 :                         break;
     122                 :          0 :                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
     123                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA1;
     124                 :          0 :                         break;
     125                 :          0 :                 case RTE_CRYPTO_AUTH_SHA256_HMAC:
     126                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA2_256;
     127                 :          0 :                         break;
     128                 :          0 :                 case RTE_CRYPTO_AUTH_SHA384_HMAC:
     129                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA2_384;
     130                 :          0 :                         break;
     131                 :          0 :                 case RTE_CRYPTO_AUTH_SHA512_HMAC:
     132                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA2_512;
     133                 :          0 :                         break;
     134                 :          0 :                 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
     135                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_AES_XCBC_128;
     136                 :          0 :                         break;
     137                 :          0 :                 case RTE_CRYPTO_AUTH_AES_GMAC:
     138                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_AES_GMAC;
     139                 :          0 :                         key = auth_xfrm->auth.key.data;
     140                 :          0 :                         length = auth_xfrm->auth.key.length;
     141         [ #  # ]:          0 :                         memcpy(salt_key, &ipsec_xfrm->salt, 4);
     142                 :            :                         tmp_salt = (uint32_t *)salt_key;
     143         [ #  # ]:          0 :                         *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
     144                 :          0 :                         break;
     145                 :            :                 default:
     146                 :            :                         return -ENOTSUP;
     147                 :            :                 }
     148                 :            : 
     149         [ #  # ]:          0 :                 if (auth_xfrm->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
     150                 :          0 :                         const uint8_t *auth_key = auth_xfrm->auth.key.data;
     151                 :          0 :                         roc_aes_xcbc_key_derive(auth_key, hmac_opad_ipad);
     152                 :            :                 } else {
     153                 :          0 :                         roc_se_hmac_opad_ipad_gen(w2->s.auth_type, auth_xfrm->auth.key.data,
     154                 :          0 :                                                   auth_xfrm->auth.key.length, &hmac_opad_ipad[0],
     155                 :            :                                                   ROC_SE_IPSEC);
     156                 :            :                 }
     157                 :            : 
     158                 :            :                 tmp_key = (uint64_t *)hmac_opad_ipad;
     159                 :            :                 for (i = 0;
     160         [ #  # ]:          0 :                      i < (int)(ROC_CTX_MAX_OPAD_IPAD_LEN / sizeof(uint64_t));
     161                 :          0 :                      i++)
     162         [ #  # ]:          0 :                         tmp_key[i] = rte_be_to_cpu_64(tmp_key[i]);
     163                 :            : 
     164                 :            :         }
     165                 :            : 
     166                 :            :         /* Set encapsulation type */
     167         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_encap)
     168                 :          0 :                 w2->s.encap_type = ROC_IE_OT_SA_ENCAP_UDP;
     169                 :            : 
     170                 :          0 :         w2->s.spi = ipsec_xfrm->spi;
     171                 :            : 
     172         [ #  # ]:          0 :         if (key != NULL && length != 0) {
     173         [ #  # ]:          0 :                 if (length > ROC_CTX_MAX_CKEY_LEN) {
     174                 :          0 :                         plt_err("Invalid cipher key length");
     175                 :          0 :                         return -EINVAL;
     176                 :            :                 }
     177                 :            :                 /* Validate key length and set AES key len before copy to avoid overflow */
     178                 :          0 :                 if (w2->s.enc_type == ROC_IE_SA_ENC_AES_CBC ||
     179                 :            :                     w2->s.enc_type == ROC_IE_SA_ENC_AES_CTR ||
     180         [ #  # ]:          0 :                     w2->s.enc_type == ROC_IE_SA_ENC_AES_GCM ||
     181                 :          0 :                     w2->s.enc_type == ROC_IE_SA_ENC_AES_CCM ||
     182         [ #  # ]:          0 :                     w2->s.auth_type == ROC_IE_SA_AUTH_AES_GMAC) {
     183   [ #  #  #  # ]:          0 :                         switch (length) {
     184                 :          0 :                         case ROC_CPT_AES128_KEY_LEN:
     185                 :          0 :                                 w2->s.aes_key_len = ROC_IE_SA_AES_KEY_LEN_128;
     186                 :          0 :                                 break;
     187                 :          0 :                         case ROC_CPT_AES192_KEY_LEN:
     188                 :          0 :                                 w2->s.aes_key_len = ROC_IE_SA_AES_KEY_LEN_192;
     189                 :          0 :                                 break;
     190                 :          0 :                         case ROC_CPT_AES256_KEY_LEN:
     191                 :          0 :                                 w2->s.aes_key_len = ROC_IE_SA_AES_KEY_LEN_256;
     192                 :          0 :                                 break;
     193                 :          0 :                         default:
     194                 :          0 :                                 plt_err("Invalid AES key length");
     195                 :          0 :                                 return -EINVAL;
     196                 :            :                         }
     197                 :            :                 }
     198   [ #  #  #  # ]:          0 :                 if (w2->s.enc_type == ROC_IE_SA_ENC_DES_CBC && length != ROC_CPT_DES_KEY_LEN) {
     199                 :          0 :                         plt_err("Invalid DES key length");
     200                 :          0 :                         return -EINVAL;
     201                 :            :                 }
     202   [ #  #  #  # ]:          0 :                 if (w2->s.enc_type == ROC_IE_SA_ENC_3DES_CBC && length != ROC_CPT_DES3_KEY_LEN) {
     203                 :          0 :                         plt_err("Invalid 3DES key length");
     204                 :          0 :                         return -EINVAL;
     205                 :            :                 }
     206                 :            :                 /* Copy encryption key */
     207                 :          0 :                 memcpy(cipher_key, key, length);
     208                 :            :                 tmp_key = (uint64_t *)cipher_key;
     209         [ #  # ]:          0 :                 for (i = 0; i < (int)(ROC_CTX_MAX_CKEY_LEN / sizeof(uint64_t)); i++)
     210         [ #  # ]:          0 :                         tmp_key[i] = rte_be_to_cpu_64(tmp_key[i]);
     211                 :            :         }
     212                 :            : 
     213   [ #  #  #  # ]:          0 :         if (ipsec_xfrm->life.packets_soft_limit != 0 || ipsec_xfrm->life.packets_hard_limit != 0) {
     214         [ #  # ]:          0 :                 if (ipsec_xfrm->life.bytes_soft_limit != 0 ||
     215         [ #  # ]:          0 :                     ipsec_xfrm->life.bytes_hard_limit != 0) {
     216                 :          0 :                         plt_err("Expiry tracking with both packets & bytes is not supported");
     217                 :          0 :                         return -EINVAL;
     218                 :            :                 }
     219                 :          0 :                 w2->s.life_unit = ROC_IE_OT_SA_LIFE_UNIT_PKTS;
     220                 :            :         }
     221                 :            : 
     222         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit != 0 ||
     223         [ #  # ]:          0 :             ipsec_xfrm->life.bytes_hard_limit != 0) {
     224         [ #  # ]:          0 :                 if (ipsec_xfrm->life.packets_soft_limit != 0 ||
     225         [ #  # ]:          0 :                     ipsec_xfrm->life.packets_hard_limit != 0) {
     226                 :          0 :                         plt_err("Expiry tracking with both packets & bytes is not supported");
     227                 :          0 :                         return -EINVAL;
     228                 :            :                 }
     229                 :          0 :                 w2->s.life_unit = ROC_IE_OT_SA_LIFE_UNIT_OCTETS;
     230                 :            :         }
     231                 :            : 
     232                 :            :         return 0;
     233                 :            : }
     234                 :            : 
     235                 :            : static size_t
     236                 :            : ot_ipsec_inb_ctx_size(struct roc_ot_ipsec_inb_sa *sa)
     237                 :            : {
     238                 :            :         size_t size;
     239                 :            : 
     240                 :            :         /* Variable based on Anti-replay Window */
     241                 :            :         size = offsetof(struct roc_ot_ipsec_inb_sa, ctx) +
     242                 :            :                offsetof(struct roc_ot_ipsec_inb_ctx_update_reg, ar_winbits);
     243                 :            : 
     244                 :          0 :         if (sa->w0.s.ar_win)
     245                 :          0 :                 size += (1 << (sa->w0.s.ar_win - 1)) * sizeof(uint64_t);
     246                 :            : 
     247                 :            :         return size;
     248                 :            : }
     249                 :            : 
     250                 :            : static void
     251                 :          0 : ot_ipsec_update_ipv6_addr_endianness(uint64_t *addr)
     252                 :            : {
     253         [ #  # ]:          0 :         *addr = rte_be_to_cpu_64(*addr);
     254                 :            :         addr++;
     255         [ #  # ]:          0 :         *addr = rte_be_to_cpu_64(*addr);
     256                 :          0 : }
     257                 :            : 
     258                 :            : static int
     259                 :          0 : ot_ipsec_inb_tunnel_hdr_fill(struct roc_ot_ipsec_inb_sa *sa,
     260                 :            :                              struct rte_security_ipsec_xform *ipsec_xfrm)
     261                 :            : {
     262                 :            :         struct rte_security_ipsec_tunnel_param *tunnel;
     263                 :            : 
     264         [ #  # ]:          0 :         if (ipsec_xfrm->mode != RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
     265                 :            :                 return 0;
     266                 :            : 
     267         [ #  # ]:          0 :         if (ipsec_xfrm->options.tunnel_hdr_verify == 0)
     268                 :            :                 return 0;
     269                 :            : 
     270                 :            :         tunnel = &ipsec_xfrm->tunnel;
     271                 :            : 
     272      [ #  #  # ]:          0 :         switch (tunnel->type) {
     273                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV4:
     274                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
     275         [ #  # ]:          0 :                 memcpy(&sa->outer_hdr.ipv4.src_addr, &tunnel->ipv4.src_ip,
     276                 :            :                        sizeof(struct in_addr));
     277                 :          0 :                 memcpy(&sa->outer_hdr.ipv4.dst_addr, &tunnel->ipv4.dst_ip,
     278                 :            :                        sizeof(struct in_addr));
     279                 :            : 
     280                 :            :                 /* IP Source and Dest are in LE/CPU endian */
     281                 :          0 :                 sa->outer_hdr.ipv4.src_addr =
     282         [ #  # ]:          0 :                         rte_be_to_cpu_32(sa->outer_hdr.ipv4.src_addr);
     283                 :          0 :                 sa->outer_hdr.ipv4.dst_addr =
     284         [ #  # ]:          0 :                         rte_be_to_cpu_32(sa->outer_hdr.ipv4.dst_addr);
     285                 :            : 
     286                 :          0 :                 break;
     287                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV6:
     288                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_6;
     289                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.src_addr, &tunnel->ipv6.src_addr,
     290                 :            :                        sizeof(sa->outer_hdr.ipv6.src_addr));
     291                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.dst_addr, &tunnel->ipv6.dst_addr,
     292                 :            :                        sizeof(sa->outer_hdr.ipv6.dst_addr));
     293                 :            : 
     294                 :            :                 /* IP Source and Dest are in LE/CPU endian */
     295                 :          0 :                 ot_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.src_addr);
     296                 :          0 :                 ot_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.dst_addr);
     297                 :            : 
     298                 :          0 :                 break;
     299                 :            :         default:
     300                 :            :                 return -EINVAL;
     301                 :            :         }
     302                 :            : 
     303      [ #  #  # ]:          0 :         switch (ipsec_xfrm->options.tunnel_hdr_verify) {
     304                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR:
     305                 :          0 :                 sa->w2.s.ip_hdr_verify = ROC_IE_OT_SA_IP_HDR_VERIFY_DST_ADDR;
     306                 :          0 :                 break;
     307                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR:
     308                 :          0 :                 sa->w2.s.ip_hdr_verify =
     309                 :            :                         ROC_IE_OT_SA_IP_HDR_VERIFY_SRC_DST_ADDR;
     310                 :          0 :                 break;
     311                 :            :         default:
     312                 :            :                 return -ENOTSUP;
     313                 :            :         }
     314                 :            : 
     315                 :            :         return 0;
     316                 :            : }
     317                 :            : 
     318                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ot_ipsec_inb_sa_fill)
     319                 :            : int
     320                 :          0 : cnxk_ot_ipsec_inb_sa_fill(struct roc_ot_ipsec_inb_sa *sa,
     321                 :            :                           struct rte_security_ipsec_xform *ipsec_xfrm,
     322                 :            :                           struct rte_crypto_sym_xform *crypto_xfrm, uint8_t ctx_ilen)
     323                 :            : {
     324                 :            :         uint16_t sport = 4500, dport = 4500;
     325                 :            :         union roc_ot_ipsec_sa_word2 w2;
     326                 :            :         uint32_t replay_win_sz;
     327                 :            :         size_t offset;
     328                 :            :         int rc;
     329                 :            : 
     330                 :            :         /* Initialize the SA */
     331                 :          0 :         roc_ot_ipsec_inb_sa_init(sa);
     332                 :            : 
     333                 :          0 :         w2.u64 = sa->w2.u64;
     334                 :          0 :         rc = ot_ipsec_sa_common_param_fill(&w2, sa->cipher_key, sa->w8.s.salt,
     335                 :          0 :                                            sa->hmac_opad_ipad, ipsec_xfrm,
     336                 :            :                                            crypto_xfrm);
     337         [ #  # ]:          0 :         if (rc)
     338                 :            :                 return rc;
     339                 :            : 
     340                 :            :         /* Updata common word2 data */
     341                 :          0 :         sa->w2.u64 = w2.u64;
     342                 :            : 
     343                 :            :         /* Only support power-of-two window sizes supported */
     344                 :          0 :         replay_win_sz = ipsec_xfrm->replay_win_sz;
     345         [ #  # ]:          0 :         if (replay_win_sz) {
     346         [ #  # ]:          0 :                 if (!rte_is_power_of_2(replay_win_sz) ||
     347                 :            :                     replay_win_sz > ROC_AR_WIN_SIZE_MAX)
     348                 :            :                         return -ENOTSUP;
     349                 :            : 
     350                 :          0 :                 sa->w0.s.ar_win = rte_log2_u32(replay_win_sz) - 5;
     351                 :            :         }
     352                 :            : 
     353                 :          0 :         rc = ot_ipsec_inb_tunnel_hdr_fill(sa, ipsec_xfrm);
     354         [ #  # ]:          0 :         if (rc)
     355                 :            :                 return rc;
     356                 :            : 
     357                 :            :         /* Default options for pkt_out and pkt_fmt are with
     358                 :            :          * second pass meta and no defrag.
     359                 :            :          */
     360                 :          0 :         sa->w0.s.pkt_format = ROC_IE_OT_SA_PKT_FMT_META;
     361                 :          0 :         sa->w0.s.pkt_output = ROC_IE_OT_SA_PKT_OUTPUT_NO_FRAG;
     362                 :          0 :         sa->w0.s.pkind = ROC_IE_OT_CPT_PKIND;
     363                 :            : 
     364         [ #  # ]:          0 :         if (ipsec_xfrm->options.ip_reassembly_en)
     365                 :          0 :                 sa->w0.s.pkt_output = ROC_IE_OT_SA_PKT_OUTPUT_HW_BASED_DEFRAG;
     366                 :            : 
     367                 :            :         /* ESN */
     368                 :          0 :         sa->w2.s.esn_en = !!ipsec_xfrm->options.esn;
     369         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_encap) {
     370         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.sport)
     371                 :            :                         sport = ipsec_xfrm->udp.sport;
     372                 :            : 
     373         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.dport)
     374                 :            :                         dport = ipsec_xfrm->udp.dport;
     375                 :            : 
     376                 :          0 :                 sa->w10.s.udp_src_port = sport;
     377                 :          0 :                 sa->w10.s.udp_dst_port = dport;
     378                 :            :         }
     379                 :            : 
     380         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_ports_verify)
     381                 :          0 :                 sa->w2.s.udp_ports_verify = 1;
     382                 :            : 
     383                 :            :         offset = offsetof(struct roc_ot_ipsec_inb_sa, ctx);
     384                 :            :         /* Word offset for HW managed SA field */
     385                 :          0 :         sa->w0.s.hw_ctx_off = offset / 8;
     386                 :            :         /* Context push size for inbound spans up to hw_ctx including
     387                 :            :          * ar_base field, in 8b units
     388                 :            :          */
     389         [ #  # ]:          0 :         sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
     390                 :            :         /* Entire context size in 128B units */
     391                 :          0 :         sa->w0.s.ctx_size =
     392                 :          0 :                 (PLT_ALIGN_CEIL(ot_ipsec_inb_ctx_size(sa), ROC_CTX_UNIT_128B) /
     393                 :          0 :                  ROC_CTX_UNIT_128B) -
     394                 :            :                 1;
     395                 :            : 
     396         [ #  # ]:          0 :         if (sa->w0.s.ctx_size < ctx_ilen)
     397                 :          0 :                 sa->w0.s.ctx_size = ctx_ilen;
     398                 :            : 
     399                 :            :         /**
     400                 :            :          * CPT MC triggers expiry when counter value changes from 2 to 1. To
     401                 :            :          * mitigate this behaviour add 1 to the life counter values provided.
     402                 :            :          */
     403                 :            : 
     404         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit) {
     405                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
     406                 :          0 :                 sa->w0.s.soft_life_dec = 1;
     407                 :            :         }
     408                 :            : 
     409         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_soft_limit) {
     410                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
     411                 :          0 :                 sa->w0.s.soft_life_dec = 1;
     412                 :            :         }
     413                 :            : 
     414         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_hard_limit) {
     415                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
     416                 :          0 :                 sa->w0.s.hard_life_dec = 1;
     417                 :            :         }
     418                 :            : 
     419         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_hard_limit) {
     420                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
     421                 :          0 :                 sa->w0.s.hard_life_dec = 1;
     422                 :            :         }
     423                 :            : 
     424                 :            :         rte_wmb();
     425                 :            : 
     426                 :            :         /* Enable SA */
     427                 :          0 :         sa->w2.s.valid = 1;
     428                 :          0 :         return 0;
     429                 :            : }
     430                 :            : 
     431                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ot_ipsec_outb_sa_fill)
     432                 :            : int
     433                 :          0 : cnxk_ot_ipsec_outb_sa_fill(struct roc_ot_ipsec_outb_sa *sa,
     434                 :            :                            struct rte_security_ipsec_xform *ipsec_xfrm,
     435                 :            :                            struct rte_crypto_sym_xform *crypto_xfrm, uint8_t ctx_ilen)
     436                 :            : {
     437                 :            :         struct rte_security_ipsec_tunnel_param *tunnel = &ipsec_xfrm->tunnel;
     438                 :            :         uint16_t sport = 4500, dport = 4500;
     439                 :            :         union roc_ot_ipsec_sa_word2 w2;
     440                 :            :         size_t offset;
     441                 :            :         int rc;
     442                 :            : 
     443                 :            :         /* Initialize the SA */
     444                 :          0 :         roc_ot_ipsec_outb_sa_init(sa);
     445                 :            : 
     446                 :          0 :         w2.u64 = 0;
     447                 :          0 :         rc = ot_ipsec_sa_common_param_fill(&w2, sa->cipher_key, sa->iv.s.salt,
     448                 :          0 :                                            sa->hmac_opad_ipad, ipsec_xfrm,
     449                 :            :                                            crypto_xfrm);
     450         [ #  # ]:          0 :         if (rc)
     451                 :            :                 return rc;
     452                 :            : 
     453                 :            :         /* Update common word2 data */
     454                 :          0 :         sa->w2.u64 = w2.u64;
     455                 :            : 
     456         [ #  # ]:          0 :         if (ipsec_xfrm->mode != RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
     457                 :          0 :                 goto skip_tunnel_info;
     458                 :            : 
     459                 :            :         /* Tunnel header info */
     460      [ #  #  # ]:          0 :         switch (tunnel->type) {
     461                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV4:
     462                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
     463         [ #  # ]:          0 :                 memcpy(&sa->outer_hdr.ipv4.src_addr, &tunnel->ipv4.src_ip,
     464                 :            :                        sizeof(struct in_addr));
     465                 :          0 :                 memcpy(&sa->outer_hdr.ipv4.dst_addr, &tunnel->ipv4.dst_ip,
     466                 :            :                        sizeof(struct in_addr));
     467                 :            : 
     468                 :            :                 /* IP Source and Dest seems to be in LE/CPU endian */
     469                 :          0 :                 sa->outer_hdr.ipv4.src_addr =
     470         [ #  # ]:          0 :                         rte_be_to_cpu_32(sa->outer_hdr.ipv4.src_addr);
     471                 :          0 :                 sa->outer_hdr.ipv4.dst_addr =
     472         [ #  # ]:          0 :                         rte_be_to_cpu_32(sa->outer_hdr.ipv4.dst_addr);
     473                 :            : 
     474                 :            :                 /* Outer header DF bit source */
     475         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_df) {
     476                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src =
     477                 :            :                                 ROC_IE_OT_SA_COPY_FROM_SA;
     478                 :          0 :                         sa->w10.s.ipv4_df_or_ipv6_flw_lbl = tunnel->ipv4.df;
     479                 :            :                 } else {
     480                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src =
     481                 :            :                                 ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
     482                 :            :                 }
     483                 :            : 
     484                 :            :                 /* Outer header DSCP source */
     485         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_dscp) {
     486                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_SA;
     487                 :          0 :                         sa->w10.s.dscp = tunnel->ipv4.dscp;
     488                 :            :                 } else {
     489                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
     490                 :            :                 }
     491                 :            :                 break;
     492                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV6:
     493                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_6;
     494                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.src_addr, &tunnel->ipv6.src_addr,
     495                 :            :                        sizeof(sa->outer_hdr.ipv6.src_addr));
     496                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.dst_addr, &tunnel->ipv6.dst_addr,
     497                 :            :                        sizeof(sa->outer_hdr.ipv6.dst_addr));
     498                 :            : 
     499                 :            :                 /* IP Source and Dest are in LE/CPU endian */
     500                 :          0 :                 ot_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.src_addr);
     501                 :          0 :                 ot_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.dst_addr);
     502                 :            : 
     503                 :            :                 /* Outer header flow label source */
     504         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_flabel) {
     505                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src =
     506                 :            :                                 ROC_IE_OT_SA_COPY_FROM_SA;
     507                 :            : 
     508                 :          0 :                         sa->w10.s.ipv4_df_or_ipv6_flw_lbl = tunnel->ipv6.flabel;
     509                 :            :                 } else {
     510                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src =
     511                 :            :                                 ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
     512                 :            :                 }
     513                 :            : 
     514                 :            :                 /* Outer header DSCP source */
     515         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_dscp) {
     516                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_SA;
     517                 :          0 :                         sa->w10.s.dscp = tunnel->ipv6.dscp;
     518                 :            :                 } else {
     519                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
     520                 :            :                 }
     521                 :            :                 break;
     522                 :            :         default:
     523                 :            :                 return -EINVAL;
     524                 :            :         }
     525                 :            : 
     526                 :          0 : skip_tunnel_info:
     527                 :            :         /* ESN */
     528                 :          0 :         sa->w0.s.esn_en = !!ipsec_xfrm->options.esn;
     529                 :            : 
     530         [ #  # ]:          0 :         if (ipsec_xfrm->esn.value)
     531                 :          0 :                 sa->ctx.esn_val = ipsec_xfrm->esn.value - 1;
     532                 :            : 
     533         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_encap) {
     534         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.sport)
     535                 :            :                         sport = ipsec_xfrm->udp.sport;
     536                 :            : 
     537         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.dport)
     538                 :            :                         dport = ipsec_xfrm->udp.dport;
     539                 :            : 
     540                 :          0 :                 sa->w10.s.udp_src_port = sport;
     541                 :          0 :                 sa->w10.s.udp_dst_port = dport;
     542                 :            :         }
     543                 :            : 
     544                 :            :         offset = offsetof(struct roc_ot_ipsec_outb_sa, ctx);
     545                 :            :         /* Word offset for HW managed SA field */
     546                 :          0 :         sa->w0.s.hw_ctx_off = offset / 8;
     547                 :            : 
     548                 :            :         /* Context push size is up to err ctl in HW ctx */
     549                 :          0 :         sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
     550                 :            : 
     551                 :            :         /* Entire context size in 128B units */
     552                 :            :         offset = sizeof(struct roc_ot_ipsec_outb_sa);
     553                 :          0 :         sa->w0.s.ctx_size = (PLT_ALIGN_CEIL(offset, ROC_CTX_UNIT_128B) /
     554                 :            :                              ROC_CTX_UNIT_128B) -
     555                 :            :                             1;
     556                 :            : 
     557         [ #  # ]:          0 :         if (sa->w0.s.ctx_size < ctx_ilen)
     558                 :          0 :                 sa->w0.s.ctx_size = ctx_ilen;
     559                 :            : 
     560                 :            :         /* IPID gen */
     561                 :          0 :         sa->w2.s.ipid_gen = 1;
     562                 :            : 
     563                 :            :         /**
     564                 :            :          * CPT MC triggers expiry when counter value changes from 2 to 1. To
     565                 :            :          * mitigate this behaviour add 1 to the life counter values provided.
     566                 :            :          */
     567                 :            : 
     568         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit) {
     569                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
     570                 :          0 :                 sa->w0.s.soft_life_dec = 1;
     571                 :            :         }
     572                 :            : 
     573         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_soft_limit) {
     574                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
     575                 :          0 :                 sa->w0.s.soft_life_dec = 1;
     576                 :            :         }
     577                 :            : 
     578         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_hard_limit) {
     579                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
     580                 :          0 :                 sa->w0.s.hard_life_dec = 1;
     581                 :            :         }
     582                 :            : 
     583         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_hard_limit) {
     584                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
     585                 :          0 :                 sa->w0.s.hard_life_dec = 1;
     586                 :            :         }
     587                 :            : 
     588                 :            :         /* There are two words of CPT_CTX_HW_S for ucode to skip */
     589                 :          0 :         sa->w0.s.ctx_hdr_size = 1;
     590                 :          0 :         sa->w0.s.aop_valid = 1;
     591                 :            : 
     592                 :            :         rte_wmb();
     593                 :            : 
     594                 :            :         /* Enable SA */
     595                 :          0 :         sa->w2.s.valid = 1;
     596                 :          0 :         return 0;
     597                 :            : }
     598                 :            : 
     599                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ot_ipsec_inb_sa_valid)
     600                 :            : bool
     601                 :          0 : cnxk_ot_ipsec_inb_sa_valid(struct roc_ot_ipsec_inb_sa *sa)
     602                 :            : {
     603                 :          0 :         return !!sa->w2.s.valid;
     604                 :            : }
     605                 :            : 
     606                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ot_ipsec_outb_sa_valid)
     607                 :            : bool
     608                 :          0 : cnxk_ot_ipsec_outb_sa_valid(struct roc_ot_ipsec_outb_sa *sa)
     609                 :            : {
     610                 :          0 :         return !!sa->w2.s.valid;
     611                 :            : }
     612                 :            : 
     613                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ow_ipsec_inb_sa_valid)
     614                 :            : bool
     615                 :          0 : cnxk_ow_ipsec_inb_sa_valid(struct roc_ow_ipsec_inb_sa *sa)
     616                 :            : {
     617                 :          0 :         return !!sa->w2.s.valid;
     618                 :            : }
     619                 :            : 
     620                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ow_ipsec_outb_sa_valid)
     621                 :            : bool
     622                 :          0 : cnxk_ow_ipsec_outb_sa_valid(struct roc_ow_ipsec_outb_sa *sa)
     623                 :            : {
     624                 :          0 :         return !!sa->w2.s.valid;
     625                 :            : }
     626                 :            : 
     627                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ipsec_ivlen_get)
     628                 :            : uint8_t
     629                 :          0 : cnxk_ipsec_ivlen_get(enum rte_crypto_cipher_algorithm c_algo,
     630                 :            :                      enum rte_crypto_auth_algorithm a_algo,
     631                 :            :                      enum rte_crypto_aead_algorithm aead_algo)
     632                 :            : {
     633                 :            :         uint8_t ivlen = 0;
     634                 :            : 
     635         [ #  # ]:          0 :         if ((aead_algo == RTE_CRYPTO_AEAD_AES_GCM) || (aead_algo == RTE_CRYPTO_AEAD_AES_CCM))
     636                 :            :                 ivlen = 8;
     637                 :            : 
     638   [ #  #  #  # ]:          0 :         switch (c_algo) {
     639                 :          0 :         case RTE_CRYPTO_CIPHER_AES_CTR:
     640                 :            :                 ivlen = 8;
     641                 :          0 :                 break;
     642                 :          0 :         case RTE_CRYPTO_CIPHER_DES_CBC:
     643                 :            :         case RTE_CRYPTO_CIPHER_3DES_CBC:
     644                 :            :                 ivlen = ROC_CPT_DES_BLOCK_LENGTH;
     645                 :          0 :                 break;
     646                 :          0 :         case RTE_CRYPTO_CIPHER_AES_CBC:
     647                 :            :                 ivlen = ROC_CPT_AES_BLOCK_LENGTH;
     648                 :          0 :                 break;
     649                 :            :         default:
     650                 :            :                 break;
     651                 :            :         }
     652                 :            : 
     653         [ #  # ]:          0 :         switch (a_algo) {
     654                 :          0 :         case RTE_CRYPTO_AUTH_AES_GMAC:
     655                 :            :                 ivlen = 8;
     656                 :          0 :                 break;
     657                 :            :         default:
     658                 :            :                 break;
     659                 :            :         }
     660                 :            : 
     661                 :          0 :         return ivlen;
     662                 :            : }
     663                 :            : 
     664                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ipsec_icvlen_get)
     665                 :            : uint8_t
     666         [ #  # ]:          0 : cnxk_ipsec_icvlen_get(enum rte_crypto_cipher_algorithm c_algo,
     667                 :            :                       enum rte_crypto_auth_algorithm a_algo,
     668                 :            :                       enum rte_crypto_aead_algorithm aead_algo)
     669                 :            : {
     670                 :            :         uint8_t icv = 0;
     671                 :            : 
     672                 :            :         (void)c_algo;
     673                 :            : 
     674                 :            :         switch (a_algo) {
     675                 :            :         case RTE_CRYPTO_AUTH_NULL:
     676                 :            :                 icv = 0;
     677                 :            :                 break;
     678                 :            :         case RTE_CRYPTO_AUTH_MD5_HMAC:
     679                 :            :         case RTE_CRYPTO_AUTH_SHA1_HMAC:
     680                 :            :                 icv = 12;
     681                 :            :                 break;
     682                 :            :         case RTE_CRYPTO_AUTH_SHA256_HMAC:
     683                 :            :         case RTE_CRYPTO_AUTH_AES_GMAC:
     684                 :            :                 icv = 16;
     685                 :            :                 break;
     686                 :            :         case RTE_CRYPTO_AUTH_SHA384_HMAC:
     687                 :            :                 icv = 24;
     688                 :            :                 break;
     689                 :            :         case RTE_CRYPTO_AUTH_SHA512_HMAC:
     690                 :            :                 icv = 32;
     691                 :            :                 break;
     692                 :            :         case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
     693                 :            :                 icv = 12;
     694                 :            :                 break;
     695                 :            :         default:
     696                 :            :                 break;
     697                 :            :         }
     698                 :            : 
     699         [ #  # ]:          0 :         switch (aead_algo) {
     700                 :          0 :         case RTE_CRYPTO_AEAD_AES_GCM:
     701                 :            :         case RTE_CRYPTO_AEAD_AES_CCM:
     702                 :            :                 icv = 16;
     703                 :          0 :                 break;
     704                 :            :         default:
     705                 :            :                 break;
     706                 :            :         }
     707                 :            : 
     708                 :          0 :         return icv;
     709                 :            : }
     710                 :            : 
     711                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ipsec_outb_roundup_byte)
     712                 :            : uint8_t
     713                 :          0 : cnxk_ipsec_outb_roundup_byte(enum rte_crypto_cipher_algorithm c_algo,
     714                 :            :                              enum rte_crypto_aead_algorithm aead_algo)
     715                 :            : {
     716                 :            :         uint8_t roundup_byte = 4;
     717                 :            : 
     718         [ #  # ]:          0 :         if ((aead_algo == RTE_CRYPTO_AEAD_AES_GCM) || (aead_algo == RTE_CRYPTO_AEAD_AES_CCM))
     719                 :            :                 return roundup_byte;
     720                 :            : 
     721      [ #  #  # ]:          0 :         switch (c_algo) {
     722                 :            :         case RTE_CRYPTO_CIPHER_AES_CTR:
     723                 :            :                 roundup_byte = 4;
     724                 :            :                 break;
     725                 :          0 :         case RTE_CRYPTO_CIPHER_AES_CBC:
     726                 :            :                 roundup_byte = 16;
     727                 :          0 :                 break;
     728                 :          0 :         case RTE_CRYPTO_CIPHER_DES_CBC:
     729                 :            :         case RTE_CRYPTO_CIPHER_3DES_CBC:
     730                 :            :                 roundup_byte = 8;
     731                 :          0 :                 break;
     732                 :            :         case RTE_CRYPTO_CIPHER_NULL:
     733                 :            :                 roundup_byte = 4;
     734                 :            :                 break;
     735                 :            :         default:
     736                 :            :                 break;
     737                 :            :         }
     738                 :            : 
     739                 :            :         return roundup_byte;
     740                 :            : }
     741                 :            : 
     742                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ipsec_outb_rlens_get)
     743                 :            : int
     744         [ #  # ]:          0 : cnxk_ipsec_outb_rlens_get(struct cnxk_ipsec_outb_rlens *rlens,
     745                 :            :                           struct rte_security_ipsec_xform *ipsec_xfrm,
     746                 :            :                           struct rte_crypto_sym_xform *crypto_xfrm)
     747                 :            : {
     748                 :            :         struct rte_security_ipsec_tunnel_param *tunnel = &ipsec_xfrm->tunnel;
     749                 :            :         enum rte_crypto_cipher_algorithm c_algo = RTE_CRYPTO_CIPHER_NULL;
     750                 :            :         enum rte_crypto_auth_algorithm a_algo = RTE_CRYPTO_AUTH_NULL;
     751                 :            :         enum rte_crypto_aead_algorithm aead_algo = 0;
     752                 :            :         uint16_t partial_len = 0;
     753                 :            :         uint8_t roundup_byte = 0;
     754                 :            :         int8_t roundup_len = 0;
     755                 :            : 
     756                 :            :         memset(rlens, 0, sizeof(struct cnxk_ipsec_outb_rlens));
     757                 :            : 
     758                 :            :         /* Get Cipher and Auth algo */
     759         [ #  # ]:          0 :         if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
     760                 :          0 :                 aead_algo = crypto_xfrm->aead.algo;
     761                 :            :         } else {
     762         [ #  # ]:          0 :                 if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_CIPHER)
     763                 :          0 :                         c_algo = crypto_xfrm->cipher.algo;
     764                 :            :                 else
     765                 :          0 :                         a_algo = crypto_xfrm->auth.algo;
     766                 :            : 
     767         [ #  # ]:          0 :                 if (crypto_xfrm->next) {
     768         [ #  # ]:          0 :                         if (crypto_xfrm->next->type ==
     769                 :            :                             RTE_CRYPTO_SYM_XFORM_CIPHER)
     770                 :          0 :                                 c_algo = crypto_xfrm->next->cipher.algo;
     771                 :            :                         else
     772                 :          0 :                                 a_algo = crypto_xfrm->next->auth.algo;
     773                 :            :                 }
     774                 :            :         }
     775                 :            : 
     776         [ #  # ]:          0 :         if (ipsec_xfrm->proto == RTE_SECURITY_IPSEC_SA_PROTO_ESP) {
     777                 :            :                 partial_len = ROC_CPT_ESP_HDR_LEN;
     778                 :            :                 roundup_len = ROC_CPT_ESP_TRL_LEN;
     779                 :            :         } else {
     780                 :            :                 partial_len = ROC_CPT_AH_HDR_LEN;
     781                 :            :         }
     782                 :            : 
     783         [ #  # ]:          0 :         if (ipsec_xfrm->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
     784         [ #  # ]:          0 :                 if (tunnel->type == RTE_SECURITY_IPSEC_TUNNEL_IPV4)
     785                 :          0 :                         partial_len += ROC_CPT_TUNNEL_IPV4_HDR_LEN;
     786                 :            :                 else
     787                 :          0 :                         partial_len += ROC_CPT_TUNNEL_IPV6_HDR_LEN;
     788                 :            :         }
     789                 :            : 
     790                 :          0 :         partial_len += cnxk_ipsec_ivlen_get(c_algo, a_algo, aead_algo);
     791                 :          0 :         partial_len += cnxk_ipsec_icvlen_get(c_algo, a_algo, aead_algo);
     792                 :          0 :         roundup_byte = cnxk_ipsec_outb_roundup_byte(c_algo, aead_algo);
     793                 :            : 
     794         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_encap)
     795                 :          0 :                 partial_len += sizeof(struct rte_udp_hdr);
     796                 :            : 
     797                 :          0 :         rlens->partial_len = partial_len;
     798                 :          0 :         rlens->roundup_len = roundup_len;
     799                 :          0 :         rlens->roundup_byte = roundup_byte;
     800                 :          0 :         rlens->max_extended_len = partial_len + roundup_len + roundup_byte;
     801                 :          0 :         return 0;
     802                 :            : }
     803                 :            : 
     804                 :            : static inline int
     805                 :          0 : on_ipsec_sa_ctl_set(struct rte_security_ipsec_xform *ipsec,
     806                 :            :                     struct rte_crypto_sym_xform *crypto_xform,
     807                 :            :                     struct roc_ie_on_sa_ctl *ctl)
     808                 :            : {
     809                 :            :         struct rte_crypto_sym_xform *cipher_xform, *auth_xform;
     810                 :            :         int aes_key_len = 0;
     811                 :            : 
     812         [ #  # ]:          0 :         if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
     813                 :            :                 auth_xform = crypto_xform;
     814                 :          0 :                 cipher_xform = crypto_xform->next;
     815                 :            :         } else {
     816                 :            :                 cipher_xform = crypto_xform;
     817                 :          0 :                 auth_xform = crypto_xform->next;
     818                 :            :         }
     819                 :            : 
     820         [ #  # ]:          0 :         if (ipsec->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
     821                 :          0 :                 ctl->direction = ROC_IE_SA_DIR_OUTBOUND;
     822                 :            :         else
     823                 :          0 :                 ctl->direction = ROC_IE_SA_DIR_INBOUND;
     824                 :            : 
     825         [ #  # ]:          0 :         if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
     826         [ #  # ]:          0 :                 if (ipsec->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4)
     827                 :          0 :                         ctl->outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
     828         [ #  # ]:          0 :                 else if (ipsec->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV6)
     829                 :          0 :                         ctl->outer_ip_ver = ROC_IE_SA_IP_VERSION_6;
     830                 :            :                 else
     831                 :            :                         return -EINVAL;
     832                 :            :         }
     833                 :            : 
     834         [ #  # ]:          0 :         if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT) {
     835                 :          0 :                 ctl->ipsec_mode = ROC_IE_SA_MODE_TRANSPORT;
     836                 :          0 :                 ctl->outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
     837         [ #  # ]:          0 :         } else if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
     838                 :          0 :                 ctl->ipsec_mode = ROC_IE_SA_MODE_TUNNEL;
     839                 :            :         else
     840                 :            :                 return -EINVAL;
     841                 :            : 
     842         [ #  # ]:          0 :         if (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_AH)
     843                 :          0 :                 ctl->ipsec_proto = ROC_IE_SA_PROTOCOL_AH;
     844         [ #  # ]:          0 :         else if (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_ESP)
     845                 :          0 :                 ctl->ipsec_proto = ROC_IE_SA_PROTOCOL_ESP;
     846                 :            :         else
     847                 :            :                 return -EINVAL;
     848                 :            : 
     849         [ #  # ]:          0 :         if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
     850      [ #  #  # ]:          0 :                 switch (crypto_xform->aead.algo) {
     851                 :          0 :                 case RTE_CRYPTO_AEAD_AES_GCM:
     852                 :          0 :                         ctl->enc_type = ROC_IE_SA_ENC_AES_GCM;
     853                 :          0 :                         aes_key_len = crypto_xform->aead.key.length;
     854                 :          0 :                         break;
     855                 :          0 :                 case RTE_CRYPTO_AEAD_AES_CCM:
     856                 :          0 :                         ctl->enc_type = ROC_IE_SA_ENC_AES_CCM;
     857                 :          0 :                         aes_key_len = crypto_xform->aead.key.length;
     858                 :          0 :                         break;
     859                 :          0 :                 default:
     860                 :          0 :                         plt_err("Unsupported AEAD algorithm");
     861                 :          0 :                         return -ENOTSUP;
     862                 :            :                 }
     863                 :            :         } else {
     864         [ #  # ]:          0 :                 if (cipher_xform != NULL) {
     865   [ #  #  #  #  :          0 :                         switch (cipher_xform->cipher.algo) {
                   #  # ]
     866                 :          0 :                         case RTE_CRYPTO_CIPHER_NULL:
     867                 :          0 :                                 ctl->enc_type = ROC_IE_SA_ENC_NULL;
     868                 :          0 :                                 break;
     869                 :          0 :                         case RTE_CRYPTO_CIPHER_DES_CBC:
     870                 :          0 :                                 ctl->enc_type = ROC_IE_SA_ENC_DES_CBC;
     871                 :          0 :                                 aes_key_len = cipher_xform->cipher.key.length;
     872                 :          0 :                                 break;
     873                 :          0 :                         case RTE_CRYPTO_CIPHER_3DES_CBC:
     874                 :          0 :                                 ctl->enc_type = ROC_IE_SA_ENC_3DES_CBC;
     875                 :          0 :                                 aes_key_len = cipher_xform->cipher.key.length;
     876                 :          0 :                                 break;
     877                 :          0 :                         case RTE_CRYPTO_CIPHER_AES_CBC:
     878                 :          0 :                                 ctl->enc_type = ROC_IE_SA_ENC_AES_CBC;
     879                 :          0 :                                 aes_key_len = cipher_xform->cipher.key.length;
     880                 :          0 :                                 break;
     881                 :          0 :                         case RTE_CRYPTO_CIPHER_AES_CTR:
     882                 :          0 :                                 ctl->enc_type = ROC_IE_SA_ENC_AES_CTR;
     883                 :          0 :                                 aes_key_len = cipher_xform->cipher.key.length;
     884                 :          0 :                                 break;
     885                 :          0 :                         default:
     886                 :          0 :                                 plt_err("Unsupported cipher algorithm");
     887                 :          0 :                                 return -ENOTSUP;
     888                 :            :                         }
     889                 :            :                 }
     890                 :            : 
     891   [ #  #  #  #  :          0 :                 switch (auth_xform->auth.algo) {
          #  #  #  #  #  
                      # ]
     892                 :          0 :                 case RTE_CRYPTO_AUTH_NULL:
     893                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_NULL;
     894                 :          0 :                         break;
     895                 :          0 :                 case RTE_CRYPTO_AUTH_MD5_HMAC:
     896                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_MD5;
     897                 :          0 :                         break;
     898                 :          0 :                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
     899                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_SHA1;
     900                 :          0 :                         break;
     901                 :          0 :                 case RTE_CRYPTO_AUTH_SHA224_HMAC:
     902                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_SHA2_224;
     903                 :          0 :                         break;
     904                 :          0 :                 case RTE_CRYPTO_AUTH_SHA256_HMAC:
     905                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_SHA2_256;
     906                 :          0 :                         break;
     907                 :          0 :                 case RTE_CRYPTO_AUTH_SHA384_HMAC:
     908                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_SHA2_384;
     909                 :          0 :                         break;
     910                 :          0 :                 case RTE_CRYPTO_AUTH_SHA512_HMAC:
     911                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_SHA2_512;
     912                 :          0 :                         break;
     913                 :          0 :                 case RTE_CRYPTO_AUTH_AES_GMAC:
     914                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_AES_GMAC;
     915                 :          0 :                         aes_key_len = auth_xform->auth.key.length;
     916                 :          0 :                         break;
     917                 :          0 :                 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
     918                 :          0 :                         ctl->auth_type = ROC_IE_SA_AUTH_AES_XCBC_128;
     919                 :          0 :                         break;
     920                 :          0 :                 default:
     921                 :          0 :                         plt_err("Unsupported auth algorithm");
     922                 :          0 :                         return -ENOTSUP;
     923                 :            :                 }
     924                 :            :         }
     925                 :            : 
     926                 :            :         /* Validate and set AES key length before copy */
     927                 :          0 :         if (ctl->enc_type == ROC_IE_SA_ENC_AES_CBC || ctl->enc_type == ROC_IE_SA_ENC_AES_CTR ||
     928         [ #  # ]:          0 :             ctl->enc_type == ROC_IE_SA_ENC_AES_GCM || ctl->enc_type == ROC_IE_SA_ENC_AES_CCM ||
     929         [ #  # ]:          0 :             ctl->auth_type == ROC_IE_SA_AUTH_AES_GMAC) {
     930   [ #  #  #  # ]:          0 :                 switch (aes_key_len) {
     931                 :          0 :                 case ROC_CPT_AES128_KEY_LEN:
     932                 :          0 :                         ctl->aes_key_len = ROC_IE_SA_AES_KEY_LEN_128;
     933                 :          0 :                         break;
     934                 :          0 :                 case ROC_CPT_AES192_KEY_LEN:
     935                 :          0 :                         ctl->aes_key_len = ROC_IE_SA_AES_KEY_LEN_192;
     936                 :          0 :                         break;
     937                 :          0 :                 case ROC_CPT_AES256_KEY_LEN:
     938                 :          0 :                         ctl->aes_key_len = ROC_IE_SA_AES_KEY_LEN_256;
     939                 :          0 :                         break;
     940                 :          0 :                 default:
     941                 :          0 :                         plt_err("Invalid AES key length");
     942                 :          0 :                         return -EINVAL;
     943                 :            :                 }
     944                 :            :         }
     945   [ #  #  #  # ]:          0 :         if (ctl->enc_type == ROC_IE_SA_ENC_DES_CBC && aes_key_len != ROC_CPT_DES_KEY_LEN) {
     946                 :          0 :                 plt_err("Invalid DES key length");
     947                 :          0 :                 return -EINVAL;
     948                 :            :         }
     949   [ #  #  #  # ]:          0 :         if (ctl->enc_type == ROC_IE_SA_ENC_3DES_CBC && aes_key_len != ROC_CPT_DES3_KEY_LEN) {
     950                 :          0 :                 plt_err("Invalid 3DES key length");
     951                 :          0 :                 return -EINVAL;
     952                 :            :         }
     953                 :            : 
     954         [ #  # ]:          0 :         if (ipsec->options.esn)
     955                 :          0 :                 ctl->esn_en = 1;
     956                 :            : 
     957         [ #  # ]:          0 :         if (ipsec->options.udp_encap == 1)
     958                 :          0 :                 ctl->encap_type = ROC_IE_ON_SA_ENCAP_UDP;
     959                 :            : 
     960                 :          0 :         ctl->copy_df = ipsec->options.copy_df;
     961                 :            : 
     962         [ #  # ]:          0 :         ctl->spi = rte_cpu_to_be_32(ipsec->spi);
     963                 :            : 
     964                 :          0 :         rte_io_wmb();
     965                 :            : 
     966                 :          0 :         ctl->valid = 1;
     967                 :            : 
     968                 :          0 :         return 0;
     969                 :            : }
     970                 :            : 
     971                 :            : static inline int
     972                 :          0 : on_fill_ipsec_common_sa(struct rte_security_ipsec_xform *ipsec,
     973                 :            :                         struct rte_crypto_sym_xform *crypto_xform,
     974                 :            :                         struct roc_ie_on_common_sa *common_sa)
     975                 :            : {
     976                 :            :         struct rte_crypto_sym_xform *cipher_xform, *auth_xform;
     977                 :            :         const uint8_t *cipher_key;
     978                 :            :         int cipher_key_len = 0;
     979                 :            :         uint8_t ccm_flag = 0;
     980                 :            :         int ret;
     981                 :            : 
     982                 :          0 :         ret = on_ipsec_sa_ctl_set(ipsec, crypto_xform, &common_sa->ctl);
     983         [ #  # ]:          0 :         if (ret)
     984                 :            :                 return ret;
     985                 :            : 
     986         [ #  # ]:          0 :         if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
     987                 :            :                 auth_xform = crypto_xform;
     988                 :          0 :                 cipher_xform = crypto_xform->next;
     989                 :            :         } else {
     990                 :            :                 cipher_xform = crypto_xform;
     991                 :          0 :                 auth_xform = crypto_xform->next;
     992                 :            :         }
     993                 :            : 
     994         [ #  # ]:          0 :         if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
     995         [ #  # ]:          0 :                 if (crypto_xform->aead.algo == RTE_CRYPTO_AEAD_AES_GCM)
     996                 :          0 :                         memcpy(common_sa->iv.gcm.nonce, &ipsec->salt, 4);
     997         [ #  # ]:          0 :                 else if (crypto_xform->aead.algo == RTE_CRYPTO_AEAD_AES_CCM) {
     998                 :            :                         ccm_flag = 0x07 & ~ROC_CPT_AES_CCM_CTR_LEN;
     999                 :          0 :                         *common_sa->iv.gcm.nonce = ccm_flag;
    1000                 :          0 :                         memcpy(PLT_PTR_ADD(common_sa->iv.gcm.nonce, 1), &ipsec->salt, 3);
    1001                 :            :                 }
    1002                 :          0 :                 cipher_key = crypto_xform->aead.key.data;
    1003                 :          0 :                 cipher_key_len = crypto_xform->aead.key.length;
    1004                 :            :         } else {
    1005         [ #  # ]:          0 :                 if (cipher_xform) {
    1006         [ #  # ]:          0 :                         if (cipher_xform->cipher.algo == RTE_CRYPTO_CIPHER_AES_CTR)
    1007                 :          0 :                                 memcpy(common_sa->iv.gcm.nonce, &ipsec->salt, 4);
    1008                 :          0 :                         cipher_key = cipher_xform->cipher.key.data;
    1009                 :          0 :                         cipher_key_len = cipher_xform->cipher.key.length;
    1010                 :            :                 }
    1011                 :            : 
    1012         [ #  # ]:          0 :                 if (auth_xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) {
    1013                 :          0 :                         memcpy(common_sa->iv.gcm.nonce, &ipsec->salt, 4);
    1014                 :          0 :                         cipher_key = auth_xform->auth.key.data;
    1015                 :          0 :                         cipher_key_len = auth_xform->auth.key.length;
    1016                 :            :                 }
    1017                 :            :         }
    1018                 :            : 
    1019         [ #  # ]:          0 :         if (cipher_key_len != 0) {
    1020         [ #  # ]:          0 :                 if (cipher_key_len > (int)sizeof(common_sa->cipher_key)) {
    1021                 :          0 :                         plt_err("Invalid cipher key length");
    1022                 :          0 :                         return -EINVAL;
    1023                 :            :                 }
    1024                 :          0 :                 memcpy(common_sa->cipher_key, cipher_key, cipher_key_len);
    1025                 :            :         }
    1026                 :            : 
    1027                 :            :         return 0;
    1028                 :            : }
    1029                 :            : 
    1030                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_on_ipsec_outb_sa_create)
    1031                 :            : int
    1032                 :          0 : cnxk_on_ipsec_outb_sa_create(struct rte_security_ipsec_xform *ipsec,
    1033                 :            :                              struct rte_crypto_sym_xform *crypto_xform,
    1034                 :            :                              struct roc_ie_on_outb_sa *out_sa)
    1035                 :            : {
    1036                 :            :         struct roc_ie_on_ip_template *template = NULL;
    1037                 :            :         struct rte_crypto_sym_xform *auth_xform;
    1038                 :            :         struct roc_ie_on_sa_ctl *ctl;
    1039                 :            :         struct rte_ipv6_hdr *ip6;
    1040                 :            :         struct rte_ipv4_hdr *ip4;
    1041                 :            :         uint16_t sport, dport;
    1042                 :            :         size_t ctx_len;
    1043                 :            :         int ret;
    1044                 :            : 
    1045                 :            :         ctl = &out_sa->common_sa.ctl;
    1046                 :            : 
    1047         [ #  # ]:          0 :         if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AUTH)
    1048                 :            :                 auth_xform = crypto_xform;
    1049                 :            :         else
    1050                 :          0 :                 auth_xform = crypto_xform->next;
    1051                 :            : 
    1052                 :          0 :         ret = on_fill_ipsec_common_sa(ipsec, crypto_xform, &out_sa->common_sa);
    1053         [ #  # ]:          0 :         if (ret)
    1054                 :            :                 return ret;
    1055                 :            : 
    1056         [ #  # ]:          0 :         if (ctl->enc_type == ROC_IE_SA_ENC_AES_GCM || ctl->enc_type == ROC_IE_SA_ENC_AES_CCM ||
    1057   [ #  #  #  # ]:          0 :             ctl->auth_type == ROC_IE_SA_AUTH_NULL || ctl->auth_type == ROC_IE_SA_AUTH_AES_GMAC) {
    1058                 :          0 :                 template = &out_sa->aes_gcm.template;
    1059                 :          0 :                 ctx_len = offsetof(struct roc_ie_on_outb_sa, aes_gcm.template);
    1060                 :            :         } else {
    1061   [ #  #  #  # ]:          0 :                 switch (ctl->auth_type) {
    1062                 :          0 :                 case ROC_IE_SA_AUTH_MD5:
    1063                 :            :                 case ROC_IE_SA_AUTH_SHA1:
    1064                 :          0 :                         template = &out_sa->sha1.template;
    1065                 :            :                         ctx_len = offsetof(struct roc_ie_on_outb_sa, sha1.template);
    1066                 :          0 :                         break;
    1067                 :          0 :                 case ROC_IE_SA_AUTH_SHA2_256:
    1068                 :            :                 case ROC_IE_SA_AUTH_SHA2_384:
    1069                 :            :                 case ROC_IE_SA_AUTH_SHA2_512:
    1070                 :          0 :                         template = &out_sa->sha2.template;
    1071                 :            :                         ctx_len = offsetof(struct roc_ie_on_outb_sa, sha2.template);
    1072                 :          0 :                         break;
    1073                 :          0 :                 case ROC_IE_SA_AUTH_AES_XCBC_128:
    1074                 :          0 :                         template = &out_sa->aes_xcbc.template;
    1075                 :            :                         ctx_len = offsetof(struct roc_ie_on_outb_sa, aes_xcbc.template);
    1076                 :          0 :                         break;
    1077                 :          0 :                 default:
    1078                 :          0 :                         plt_err("Unsupported auth algorithm");
    1079                 :          0 :                         return -EINVAL;
    1080                 :            :                 }
    1081                 :            :         }
    1082                 :            : 
    1083                 :            :         ip4 = (struct rte_ipv4_hdr *)&template->ip4.ipv4_hdr;
    1084                 :            : 
    1085                 :            :         sport = 4500;
    1086                 :            :         dport = 4500;
    1087                 :            : 
    1088                 :            :         /* If custom port values are provided, Overwrite default port values. */
    1089         [ #  # ]:          0 :         if (ipsec->options.udp_encap) {
    1090                 :            : 
    1091         [ #  # ]:          0 :                 if (ipsec->udp.sport)
    1092                 :            :                         sport = ipsec->udp.sport;
    1093                 :            : 
    1094         [ #  # ]:          0 :                 if (ipsec->udp.dport)
    1095                 :            :                         dport = ipsec->udp.dport;
    1096                 :            : 
    1097                 :          0 :                 ip4->next_proto_id = IPPROTO_UDP;
    1098         [ #  # ]:          0 :                 template->ip4.udp_src = rte_be_to_cpu_16(sport);
    1099         [ #  # ]:          0 :                 template->ip4.udp_dst = rte_be_to_cpu_16(dport);
    1100                 :            :         } else {
    1101         [ #  # ]:          0 :                 if (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_AH)
    1102                 :          0 :                         ip4->next_proto_id = IPPROTO_AH;
    1103                 :            :                 else
    1104                 :          0 :                         ip4->next_proto_id = IPPROTO_ESP;
    1105                 :            :         }
    1106                 :            : 
    1107         [ #  # ]:          0 :         if (ipsec->mode == RTE_SECURITY_IPSEC_SA_MODE_TUNNEL) {
    1108         [ #  # ]:          0 :                 if (ipsec->tunnel.type == RTE_SECURITY_IPSEC_TUNNEL_IPV4) {
    1109                 :            :                         uint16_t frag_off = 0;
    1110                 :            : 
    1111                 :          0 :                         ctx_len += sizeof(template->ip4);
    1112                 :            : 
    1113                 :          0 :                         ip4->version_ihl = RTE_IPV4_VHL_DEF;
    1114         [ #  # ]:          0 :                         ip4->time_to_live = ipsec->tunnel.ipv4.ttl ?
    1115                 :            :                                                     ipsec->tunnel.ipv4.ttl :
    1116                 :            :                                                     0x40;
    1117                 :          0 :                         ip4->type_of_service |= (ipsec->tunnel.ipv4.dscp << 2);
    1118         [ #  # ]:          0 :                         if (ipsec->tunnel.ipv4.df)
    1119                 :            :                                 frag_off |= RTE_IPV4_HDR_DF_FLAG;
    1120         [ #  # ]:          0 :                         ip4->fragment_offset = rte_cpu_to_be_16(frag_off);
    1121                 :            : 
    1122                 :          0 :                         memcpy(&ip4->src_addr, &ipsec->tunnel.ipv4.src_ip,
    1123                 :            :                                sizeof(struct in_addr));
    1124                 :          0 :                         memcpy(&ip4->dst_addr, &ipsec->tunnel.ipv4.dst_ip,
    1125                 :            :                                sizeof(struct in_addr));
    1126         [ #  # ]:          0 :                 } else if (ipsec->tunnel.type ==
    1127                 :            :                            RTE_SECURITY_IPSEC_TUNNEL_IPV6) {
    1128                 :          0 :                         ctx_len += sizeof(template->ip6);
    1129                 :            : 
    1130                 :            :                         ip6 = (struct rte_ipv6_hdr *)&template->ip6.ipv6_hdr;
    1131         [ #  # ]:          0 :                         if (ipsec->options.udp_encap) {
    1132                 :          0 :                                 ip6->proto = IPPROTO_UDP;
    1133         [ #  # ]:          0 :                                 template->ip6.udp_src = rte_be_to_cpu_16(sport);
    1134         [ #  # ]:          0 :                                 template->ip6.udp_dst = rte_be_to_cpu_16(dport);
    1135                 :            :                         } else {
    1136         [ #  # ]:          0 :                                 ip6->proto = (ipsec->proto == RTE_SECURITY_IPSEC_SA_PROTO_ESP) ?
    1137                 :            :                                                               IPPROTO_ESP :
    1138                 :            :                                                               IPPROTO_AH;
    1139                 :            :                         }
    1140                 :          0 :                         ip6->vtc_flow =
    1141         [ #  # ]:          0 :                                 rte_cpu_to_be_32(0x60000000 |
    1142                 :            :                                                  ((ipsec->tunnel.ipv6.dscp
    1143                 :            :                                                    << RTE_IPV6_HDR_TC_SHIFT) &
    1144                 :            :                                                   RTE_IPV6_HDR_TC_MASK) |
    1145                 :            :                                                  ((ipsec->tunnel.ipv6.flabel
    1146                 :            :                                                    << RTE_IPV6_HDR_FL_SHIFT) &
    1147                 :            :                                                   RTE_IPV6_HDR_FL_MASK));
    1148         [ #  # ]:          0 :                         ip6->hop_limits = ipsec->tunnel.ipv6.hlimit ?
    1149                 :            :                                                   ipsec->tunnel.ipv6.hlimit :
    1150                 :            :                                                   0x40;
    1151                 :          0 :                         ip6->src_addr = ipsec->tunnel.ipv6.src_addr;
    1152                 :          0 :                         ip6->dst_addr = ipsec->tunnel.ipv6.dst_addr;
    1153                 :            :                 }
    1154                 :            :         } else
    1155                 :          0 :                 ctx_len += sizeof(template->ip4);
    1156                 :            : 
    1157                 :          0 :         ctx_len = RTE_ALIGN_CEIL(ctx_len, 8);
    1158                 :            : 
    1159         [ #  # ]:          0 :         if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_AEAD) {
    1160                 :          0 :                 uint8_t *hmac_opad_ipad = (uint8_t *)&out_sa->sha2;
    1161                 :            : 
    1162         [ #  # ]:          0 :                 if (auth_xform->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
    1163                 :          0 :                         const uint8_t *auth_key = auth_xform->auth.key.data;
    1164                 :            : 
    1165                 :          0 :                         roc_aes_xcbc_key_derive(auth_key, hmac_opad_ipad);
    1166         [ #  # ]:          0 :                 } else if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_NULL) {
    1167                 :          0 :                         roc_se_hmac_opad_ipad_gen(
    1168                 :          0 :                                 out_sa->common_sa.ctl.auth_type, auth_xform->auth.key.data,
    1169                 :          0 :                                 auth_xform->auth.key.length, &hmac_opad_ipad[0], ROC_SE_IPSEC);
    1170                 :            :                 }
    1171                 :            :         }
    1172                 :            : 
    1173                 :          0 :         return ctx_len;
    1174                 :            : }
    1175                 :            : 
    1176                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_on_ipsec_inb_sa_create)
    1177                 :            : int
    1178                 :          0 : cnxk_on_ipsec_inb_sa_create(struct rte_security_ipsec_xform *ipsec,
    1179                 :            :                             struct rte_crypto_sym_xform *crypto_xform,
    1180                 :            :                             struct roc_ie_on_inb_sa *in_sa)
    1181                 :            : {
    1182                 :            :         struct rte_crypto_sym_xform *auth_xform = crypto_xform;
    1183                 :            :         const uint8_t *auth_key;
    1184                 :            :         int auth_key_len = 0;
    1185                 :            :         size_t ctx_len = 0;
    1186                 :            :         int ret;
    1187                 :            : 
    1188                 :          0 :         ret = on_fill_ipsec_common_sa(ipsec, crypto_xform, &in_sa->common_sa);
    1189         [ #  # ]:          0 :         if (ret)
    1190                 :            :                 return ret;
    1191                 :            : 
    1192         [ #  # ]:          0 :         if (crypto_xform->type != RTE_CRYPTO_SYM_XFORM_AEAD &&
    1193   [ #  #  #  # ]:          0 :             crypto_xform->auth.algo == RTE_CRYPTO_AUTH_NULL && ipsec->replay_win_sz) {
    1194                 :          0 :                 plt_err("anti-replay can't be supported with integrity service disabled");
    1195                 :          0 :                 return -EINVAL;
    1196                 :            :         }
    1197         [ #  # ]:          0 :         if (crypto_xform->type == RTE_CRYPTO_SYM_XFORM_AEAD ||
    1198   [ #  #  #  # ]:          0 :             auth_xform->auth.algo == RTE_CRYPTO_AUTH_NULL ||
    1199                 :            :             auth_xform->auth.algo == RTE_CRYPTO_AUTH_AES_GMAC) {
    1200                 :            :                 ctx_len = offsetof(struct roc_ie_on_inb_sa, sha1_or_gcm.hmac_key[0]);
    1201                 :            :         } else {
    1202                 :          0 :                 uint8_t *hmac_opad_ipad = (uint8_t *)&in_sa->sha2;
    1203                 :          0 :                 auth_key = auth_xform->auth.key.data;
    1204                 :          0 :                 auth_key_len = auth_xform->auth.key.length;
    1205                 :            : 
    1206   [ #  #  #  # ]:          0 :                 switch (auth_xform->auth.algo) {
    1207                 :            :                 case RTE_CRYPTO_AUTH_NULL:
    1208                 :            :                         break;
    1209                 :          0 :                 case RTE_CRYPTO_AUTH_MD5_HMAC:
    1210                 :            :                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
    1211         [ #  # ]:          0 :                         if (auth_key_len > (int)sizeof(in_sa->sha1_or_gcm.hmac_key)) {
    1212                 :          0 :                                 plt_err("Auth key len %d exceeds max %zu for algo %u", auth_key_len,
    1213                 :            :                                         sizeof(in_sa->sha1_or_gcm.hmac_key), auth_xform->auth.algo);
    1214                 :          0 :                                 return -EINVAL;
    1215                 :            :                         }
    1216                 :          0 :                         memcpy(in_sa->sha1_or_gcm.hmac_key, auth_key, auth_key_len);
    1217                 :            :                         ctx_len = offsetof(struct roc_ie_on_inb_sa, sha1_or_gcm.selector);
    1218                 :          0 :                         break;
    1219                 :          0 :                 case RTE_CRYPTO_AUTH_SHA256_HMAC:
    1220                 :            :                 case RTE_CRYPTO_AUTH_SHA384_HMAC:
    1221                 :            :                 case RTE_CRYPTO_AUTH_SHA512_HMAC:
    1222         [ #  # ]:          0 :                         if (auth_key_len > (int)sizeof(in_sa->sha2.hmac_key)) {
    1223                 :          0 :                                 plt_err("Auth key len %d exceeds max %zu for algo %u", auth_key_len,
    1224                 :            :                                         sizeof(in_sa->sha2.hmac_key), auth_xform->auth.algo);
    1225                 :          0 :                                 return -EINVAL;
    1226                 :            :                         }
    1227                 :          0 :                         memcpy(in_sa->sha2.hmac_key, auth_key, auth_key_len);
    1228                 :            :                         ctx_len = offsetof(struct roc_ie_on_inb_sa, sha2.selector);
    1229                 :          0 :                         break;
    1230                 :          0 :                 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
    1231         [ #  # ]:          0 :                         if (auth_key_len > (int)sizeof(in_sa->aes_xcbc.key)) {
    1232                 :          0 :                                 plt_err("Auth key len %d exceeds max %zu for algo %u", auth_key_len,
    1233                 :            :                                         sizeof(in_sa->aes_xcbc.key), auth_xform->auth.algo);
    1234                 :          0 :                                 return -EINVAL;
    1235                 :            :                         }
    1236                 :          0 :                         memcpy(in_sa->aes_xcbc.key, auth_key, auth_key_len);
    1237                 :            :                         ctx_len = offsetof(struct roc_ie_on_inb_sa, aes_xcbc.selector);
    1238                 :          0 :                         break;
    1239                 :          0 :                 default:
    1240                 :          0 :                         plt_err("Unsupported auth algorithm %u", auth_xform->auth.algo);
    1241                 :          0 :                         return -ENOTSUP;
    1242                 :            :                 }
    1243         [ #  # ]:          0 :                 if (auth_xform->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
    1244                 :          0 :                         const uint8_t *auth_key = auth_xform->auth.key.data;
    1245                 :            : 
    1246                 :          0 :                         roc_aes_xcbc_key_derive(auth_key, hmac_opad_ipad);
    1247         [ #  # ]:          0 :                 } else if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_NULL) {
    1248                 :          0 :                         roc_se_hmac_opad_ipad_gen(
    1249                 :          0 :                                 in_sa->common_sa.ctl.auth_type, auth_xform->auth.key.data,
    1250                 :          0 :                                 auth_xform->auth.key.length, &hmac_opad_ipad[0], ROC_SE_IPSEC);
    1251                 :            :                 }
    1252                 :            :         }
    1253                 :            : 
    1254                 :          0 :         return ctx_len;
    1255                 :            : }
    1256                 :            : 
    1257                 :            : static int
    1258                 :          0 : ow_ipsec_sa_common_param_fill(union roc_ow_ipsec_sa_word2 *w2, uint8_t *cipher_key,
    1259                 :            :                               uint8_t *salt_key, uint8_t *hmac_opad_ipad,
    1260                 :            :                               struct rte_security_ipsec_xform *ipsec_xfrm,
    1261                 :            :                               struct rte_crypto_sym_xform *crypto_xfrm)
    1262                 :            : {
    1263                 :            :         struct rte_crypto_sym_xform *auth_xfrm, *cipher_xfrm;
    1264                 :            :         const uint8_t *key = NULL;
    1265                 :            :         uint8_t ccm_flag = 0;
    1266                 :            :         uint32_t *tmp_salt;
    1267                 :            :         uint64_t *tmp_key;
    1268                 :            :         int i, length = 0;
    1269                 :            : 
    1270                 :            :         /* Set direction */
    1271         [ #  # ]:          0 :         if (ipsec_xfrm->direction == RTE_SECURITY_IPSEC_SA_DIR_EGRESS)
    1272                 :          0 :                 w2->s.dir = ROC_IE_SA_DIR_OUTBOUND;
    1273                 :            :         else
    1274                 :          0 :                 w2->s.dir = ROC_IE_SA_DIR_INBOUND;
    1275                 :            : 
    1276         [ #  # ]:          0 :         if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AUTH) {
    1277                 :            :                 auth_xfrm = crypto_xfrm;
    1278                 :          0 :                 cipher_xfrm = crypto_xfrm->next;
    1279                 :            :         } else {
    1280                 :            :                 cipher_xfrm = crypto_xfrm;
    1281                 :          0 :                 auth_xfrm = crypto_xfrm->next;
    1282                 :            :         }
    1283                 :            : 
    1284                 :            :         /* Set protocol - ESP vs AH */
    1285      [ #  #  # ]:          0 :         switch (ipsec_xfrm->proto) {
    1286                 :          0 :         case RTE_SECURITY_IPSEC_SA_PROTO_ESP:
    1287                 :          0 :                 w2->s.protocol = ROC_IE_SA_PROTOCOL_ESP;
    1288                 :          0 :                 break;
    1289                 :          0 :         case RTE_SECURITY_IPSEC_SA_PROTO_AH:
    1290                 :          0 :                 w2->s.protocol = ROC_IE_SA_PROTOCOL_AH;
    1291                 :          0 :                 break;
    1292                 :            :         default:
    1293                 :            :                 return -EINVAL;
    1294                 :            :         }
    1295                 :            : 
    1296                 :            :         /* Set mode - transport vs tunnel */
    1297      [ #  #  # ]:          0 :         switch (ipsec_xfrm->mode) {
    1298                 :          0 :         case RTE_SECURITY_IPSEC_SA_MODE_TRANSPORT:
    1299                 :          0 :                 w2->s.mode = ROC_IE_SA_MODE_TRANSPORT;
    1300                 :          0 :                 break;
    1301                 :          0 :         case RTE_SECURITY_IPSEC_SA_MODE_TUNNEL:
    1302                 :          0 :                 w2->s.mode = ROC_IE_SA_MODE_TUNNEL;
    1303                 :          0 :                 break;
    1304                 :            :         default:
    1305                 :            :                 return -EINVAL;
    1306                 :            :         }
    1307                 :            : 
    1308                 :            :         /* Set encryption algorithm */
    1309         [ #  # ]:          0 :         if (crypto_xfrm->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
    1310                 :          0 :                 key = crypto_xfrm->aead.key.data;
    1311                 :          0 :                 length = crypto_xfrm->aead.key.length;
    1312                 :            : 
    1313      [ #  #  # ]:          0 :                 switch (crypto_xfrm->aead.algo) {
    1314                 :          0 :                 case RTE_CRYPTO_AEAD_AES_GCM:
    1315                 :          0 :                         w2->s.enc_type = ROC_IE_SA_ENC_AES_GCM;
    1316                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_NULL;
    1317         [ #  # ]:          0 :                         memcpy(salt_key, &ipsec_xfrm->salt, 4);
    1318                 :            :                         tmp_salt = (uint32_t *)salt_key;
    1319         [ #  # ]:          0 :                         *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
    1320                 :          0 :                         break;
    1321                 :          0 :                 case RTE_CRYPTO_AEAD_AES_CCM:
    1322                 :          0 :                         w2->s.enc_type = ROC_IE_SA_ENC_AES_CCM;
    1323                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_NULL;
    1324                 :            :                         ccm_flag = 0x07 & ~ROC_CPT_AES_CCM_CTR_LEN;
    1325                 :          0 :                         *salt_key = ccm_flag;
    1326         [ #  # ]:          0 :                         memcpy(PLT_PTR_ADD(salt_key, 1), &ipsec_xfrm->salt, 3);
    1327                 :            :                         tmp_salt = (uint32_t *)salt_key;
    1328         [ #  # ]:          0 :                         *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
    1329                 :          0 :                         break;
    1330                 :            :                 default:
    1331                 :            :                         return -ENOTSUP;
    1332                 :            :                 }
    1333                 :            :         } else {
    1334         [ #  # ]:          0 :                 if (cipher_xfrm != NULL) {
    1335   [ #  #  #  #  :          0 :                         switch (cipher_xfrm->cipher.algo) {
                      # ]
    1336                 :          0 :                         case RTE_CRYPTO_CIPHER_NULL:
    1337                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_NULL;
    1338                 :          0 :                                 break;
    1339                 :          0 :                         case RTE_CRYPTO_CIPHER_AES_CBC:
    1340                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_AES_CBC;
    1341                 :          0 :                                 break;
    1342                 :          0 :                         case RTE_CRYPTO_CIPHER_AES_CTR:
    1343                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_AES_CTR;
    1344         [ #  # ]:          0 :                                 memcpy(salt_key, &ipsec_xfrm->salt, 4);
    1345                 :            :                                 tmp_salt = (uint32_t *)salt_key;
    1346         [ #  # ]:          0 :                                 *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
    1347                 :          0 :                                 break;
    1348                 :          0 :                         case RTE_CRYPTO_CIPHER_3DES_CBC:
    1349                 :          0 :                                 w2->s.enc_type = ROC_IE_SA_ENC_3DES_CBC;
    1350                 :          0 :                                 break;
    1351                 :            :                         default:
    1352                 :            :                                 return -ENOTSUP;
    1353                 :            :                         }
    1354                 :            : 
    1355                 :          0 :                         key = cipher_xfrm->cipher.key.data;
    1356                 :          0 :                         length = cipher_xfrm->cipher.key.length;
    1357                 :            :                 }
    1358                 :            : 
    1359   [ #  #  #  #  :          0 :                 switch (auth_xfrm->auth.algo) {
             #  #  #  # ]
    1360                 :          0 :                 case RTE_CRYPTO_AUTH_NULL:
    1361   [ #  #  #  # ]:          0 :                         if (w2->s.dir == ROC_IE_SA_DIR_INBOUND && ipsec_xfrm->replay_win_sz) {
    1362                 :          0 :                                 plt_err("anti-replay can't be supported with integrity service disabled");
    1363                 :          0 :                                 return -EINVAL;
    1364                 :            :                         }
    1365                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_NULL;
    1366                 :          0 :                         break;
    1367                 :          0 :                 case RTE_CRYPTO_AUTH_SHA1_HMAC:
    1368                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA1;
    1369                 :          0 :                         break;
    1370                 :          0 :                 case RTE_CRYPTO_AUTH_SHA256_HMAC:
    1371                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA2_256;
    1372                 :          0 :                         break;
    1373                 :          0 :                 case RTE_CRYPTO_AUTH_SHA384_HMAC:
    1374                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA2_384;
    1375                 :          0 :                         break;
    1376                 :          0 :                 case RTE_CRYPTO_AUTH_SHA512_HMAC:
    1377                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_SHA2_512;
    1378                 :          0 :                         break;
    1379                 :          0 :                 case RTE_CRYPTO_AUTH_AES_XCBC_MAC:
    1380                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_AES_XCBC_128;
    1381                 :          0 :                         break;
    1382                 :          0 :                 case RTE_CRYPTO_AUTH_AES_GMAC:
    1383                 :          0 :                         w2->s.auth_type = ROC_IE_SA_AUTH_AES_GMAC;
    1384                 :          0 :                         key = auth_xfrm->auth.key.data;
    1385                 :          0 :                         length = auth_xfrm->auth.key.length;
    1386         [ #  # ]:          0 :                         memcpy(salt_key, &ipsec_xfrm->salt, 4);
    1387                 :            :                         tmp_salt = (uint32_t *)salt_key;
    1388         [ #  # ]:          0 :                         *tmp_salt = rte_be_to_cpu_32(*tmp_salt);
    1389                 :          0 :                         break;
    1390                 :            :                 default:
    1391                 :            :                         return -ENOTSUP;
    1392                 :            :                 }
    1393                 :            : 
    1394         [ #  # ]:          0 :                 if (auth_xfrm->auth.algo == RTE_CRYPTO_AUTH_AES_XCBC_MAC) {
    1395                 :          0 :                         const uint8_t *auth_key = auth_xfrm->auth.key.data;
    1396                 :          0 :                         roc_aes_xcbc_key_derive(auth_key, hmac_opad_ipad);
    1397                 :            :                 } else {
    1398                 :          0 :                         roc_se_hmac_opad_ipad_gen(w2->s.auth_type, auth_xfrm->auth.key.data,
    1399                 :          0 :                                                   auth_xfrm->auth.key.length, &hmac_opad_ipad[0],
    1400                 :            :                                                   ROC_SE_IPSEC);
    1401                 :            :                 }
    1402                 :            : 
    1403                 :            :                 tmp_key = (uint64_t *)hmac_opad_ipad;
    1404         [ #  # ]:          0 :                 for (i = 0; i < (int)(ROC_CTX_MAX_OPAD_IPAD_LEN / sizeof(uint64_t)); i++)
    1405         [ #  # ]:          0 :                         tmp_key[i] = rte_be_to_cpu_64(tmp_key[i]);
    1406                 :            :         }
    1407                 :            : 
    1408                 :            :         /* Set encapsulation type */
    1409         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_encap)
    1410                 :          0 :                 w2->s.encap_type = ROC_IE_OT_SA_ENCAP_UDP;
    1411                 :            : 
    1412                 :          0 :         w2->s.spi = ipsec_xfrm->spi;
    1413                 :            : 
    1414         [ #  # ]:          0 :         if (key != NULL && length != 0) {
    1415         [ #  # ]:          0 :                 if (length > ROC_CTX_MAX_CKEY_LEN) {
    1416                 :          0 :                         plt_err("Invalid cipher key length");
    1417                 :          0 :                         return -EINVAL;
    1418                 :            :                 }
    1419                 :            :                 /* Validate key length and set AES key len before copy to avoid overflow */
    1420                 :          0 :                 if (w2->s.enc_type == ROC_IE_SA_ENC_AES_CBC ||
    1421                 :            :                     w2->s.enc_type == ROC_IE_SA_ENC_AES_CTR ||
    1422         [ #  # ]:          0 :                     w2->s.enc_type == ROC_IE_SA_ENC_AES_GCM ||
    1423                 :          0 :                     w2->s.enc_type == ROC_IE_SA_ENC_AES_CCM ||
    1424         [ #  # ]:          0 :                     w2->s.auth_type == ROC_IE_SA_AUTH_AES_GMAC) {
    1425   [ #  #  #  # ]:          0 :                         switch (length) {
    1426                 :          0 :                         case ROC_CPT_AES128_KEY_LEN:
    1427                 :          0 :                                 w2->s.aes_key_len = ROC_IE_SA_AES_KEY_LEN_128;
    1428                 :          0 :                                 break;
    1429                 :          0 :                         case ROC_CPT_AES192_KEY_LEN:
    1430                 :          0 :                                 w2->s.aes_key_len = ROC_IE_SA_AES_KEY_LEN_192;
    1431                 :          0 :                                 break;
    1432                 :          0 :                         case ROC_CPT_AES256_KEY_LEN:
    1433                 :          0 :                                 w2->s.aes_key_len = ROC_IE_SA_AES_KEY_LEN_256;
    1434                 :          0 :                                 break;
    1435                 :          0 :                         default:
    1436                 :          0 :                                 plt_err("Invalid AES key length");
    1437                 :          0 :                                 return -EINVAL;
    1438                 :            :                         }
    1439                 :            :                 }
    1440   [ #  #  #  # ]:          0 :                 if (w2->s.enc_type == ROC_IE_SA_ENC_DES_CBC && length != ROC_CPT_DES_KEY_LEN) {
    1441                 :          0 :                         plt_err("Invalid DES key length");
    1442                 :          0 :                         return -EINVAL;
    1443                 :            :                 }
    1444   [ #  #  #  # ]:          0 :                 if (w2->s.enc_type == ROC_IE_SA_ENC_3DES_CBC && length != ROC_CPT_DES3_KEY_LEN) {
    1445                 :          0 :                         plt_err("Invalid 3DES key length");
    1446                 :          0 :                         return -EINVAL;
    1447                 :            :                 }
    1448                 :            :                 /* Copy encryption key */
    1449                 :          0 :                 memcpy(cipher_key, key, length);
    1450                 :            :                 tmp_key = (uint64_t *)cipher_key;
    1451         [ #  # ]:          0 :                 for (i = 0; i < (int)(ROC_CTX_MAX_CKEY_LEN / sizeof(uint64_t)); i++)
    1452         [ #  # ]:          0 :                         tmp_key[i] = rte_be_to_cpu_64(tmp_key[i]);
    1453                 :            :         }
    1454                 :            : 
    1455   [ #  #  #  # ]:          0 :         if (ipsec_xfrm->life.packets_soft_limit != 0 || ipsec_xfrm->life.packets_hard_limit != 0) {
    1456         [ #  # ]:          0 :                 if (ipsec_xfrm->life.bytes_soft_limit != 0 ||
    1457         [ #  # ]:          0 :                     ipsec_xfrm->life.bytes_hard_limit != 0) {
    1458                 :          0 :                         plt_err("Expiry tracking with both packets & bytes is not supported");
    1459                 :          0 :                         return -EINVAL;
    1460                 :            :                 }
    1461                 :          0 :                 w2->s.life_unit = ROC_IE_OW_SA_LIFE_UNIT_PKTS;
    1462                 :            :         }
    1463                 :            : 
    1464   [ #  #  #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit != 0 || ipsec_xfrm->life.bytes_hard_limit != 0) {
    1465         [ #  # ]:          0 :                 if (ipsec_xfrm->life.packets_soft_limit != 0 ||
    1466         [ #  # ]:          0 :                     ipsec_xfrm->life.packets_hard_limit != 0) {
    1467                 :          0 :                         plt_err("Expiry tracking with both packets & bytes is not supported");
    1468                 :          0 :                         return -EINVAL;
    1469                 :            :                 }
    1470                 :          0 :                 w2->s.life_unit = ROC_IE_OW_SA_LIFE_UNIT_OCTETS;
    1471                 :            :         }
    1472                 :            : 
    1473                 :            :         return 0;
    1474                 :            : }
    1475                 :            : 
    1476                 :            : static size_t
    1477                 :            : ow_ipsec_inb_ctx_size(struct roc_ow_ipsec_inb_sa *sa)
    1478                 :            : {
    1479                 :            :         size_t size;
    1480                 :            : 
    1481                 :            :         /* Variable based on Anti-replay Window */
    1482                 :            :         size = offsetof(struct roc_ow_ipsec_inb_sa, ctx) +
    1483                 :            :                offsetof(struct roc_ow_ipsec_inb_ctx_update_reg, ar_winbits);
    1484                 :            : 
    1485                 :          0 :         if (sa->w0.s.ar_win)
    1486                 :          0 :                 size += (1 << (sa->w0.s.ar_win - 1)) * sizeof(uint64_t);
    1487                 :            : 
    1488                 :            :         return size;
    1489                 :            : }
    1490                 :            : 
    1491                 :            : static void
    1492                 :          0 : ow_ipsec_update_ipv6_addr_endianness(uint64_t *addr)
    1493                 :            : {
    1494         [ #  # ]:          0 :         *addr = rte_be_to_cpu_64(*addr);
    1495                 :            :         addr++;
    1496         [ #  # ]:          0 :         *addr = rte_be_to_cpu_64(*addr);
    1497                 :          0 : }
    1498                 :            : 
    1499                 :            : static int
    1500                 :          0 : ow_ipsec_inb_tunnel_hdr_fill(struct roc_ow_ipsec_inb_sa *sa,
    1501                 :            :                              struct rte_security_ipsec_xform *ipsec_xfrm)
    1502                 :            : {
    1503                 :            :         struct rte_security_ipsec_tunnel_param *tunnel;
    1504                 :            : 
    1505         [ #  # ]:          0 :         if (ipsec_xfrm->mode != RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
    1506                 :            :                 return 0;
    1507                 :            : 
    1508         [ #  # ]:          0 :         if (ipsec_xfrm->options.tunnel_hdr_verify == 0)
    1509                 :            :                 return 0;
    1510                 :            : 
    1511                 :            :         tunnel = &ipsec_xfrm->tunnel;
    1512                 :            : 
    1513      [ #  #  # ]:          0 :         switch (tunnel->type) {
    1514                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV4:
    1515                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
    1516         [ #  # ]:          0 :                 memcpy(&sa->outer_hdr.ipv4.src_addr, &tunnel->ipv4.src_ip, sizeof(struct in_addr));
    1517                 :          0 :                 memcpy(&sa->outer_hdr.ipv4.dst_addr, &tunnel->ipv4.dst_ip, sizeof(struct in_addr));
    1518                 :            : 
    1519                 :            :                 /* IP Source and Dest are in LE/CPU endian */
    1520         [ #  # ]:          0 :                 sa->outer_hdr.ipv4.src_addr = rte_be_to_cpu_32(sa->outer_hdr.ipv4.src_addr);
    1521         [ #  # ]:          0 :                 sa->outer_hdr.ipv4.dst_addr = rte_be_to_cpu_32(sa->outer_hdr.ipv4.dst_addr);
    1522                 :            : 
    1523                 :          0 :                 break;
    1524                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV6:
    1525                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_6;
    1526                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.src_addr, &tunnel->ipv6.src_addr,
    1527                 :            :                        sizeof(struct in6_addr));
    1528                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.dst_addr, &tunnel->ipv6.dst_addr,
    1529                 :            :                        sizeof(struct in6_addr));
    1530                 :            : 
    1531                 :            :                 /* IP Source and Dest are in LE/CPU endian */
    1532                 :          0 :                 ow_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.src_addr);
    1533                 :          0 :                 ow_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.dst_addr);
    1534                 :            : 
    1535                 :          0 :                 break;
    1536                 :            :         default:
    1537                 :            :                 return -EINVAL;
    1538                 :            :         }
    1539                 :            : 
    1540      [ #  #  # ]:          0 :         switch (ipsec_xfrm->options.tunnel_hdr_verify) {
    1541                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_VERIFY_DST_ADDR:
    1542                 :          0 :                 sa->w2.s.ip_hdr_verify = ROC_IE_OT_SA_IP_HDR_VERIFY_DST_ADDR;
    1543                 :          0 :                 break;
    1544                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_VERIFY_SRC_DST_ADDR:
    1545                 :          0 :                 sa->w2.s.ip_hdr_verify = ROC_IE_OT_SA_IP_HDR_VERIFY_SRC_DST_ADDR;
    1546                 :          0 :                 break;
    1547                 :            :         default:
    1548                 :            :                 return -ENOTSUP;
    1549                 :            :         }
    1550                 :            : 
    1551                 :            :         return 0;
    1552                 :            : }
    1553                 :            : 
    1554                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ow_ipsec_inb_sa_fill)
    1555                 :            : int
    1556                 :          0 : cnxk_ow_ipsec_inb_sa_fill(struct roc_ow_ipsec_inb_sa *sa,
    1557                 :            :                           struct rte_security_ipsec_xform *ipsec_xfrm,
    1558                 :            :                           struct rte_crypto_sym_xform *crypto_xfrm, uint8_t ctx_ilen)
    1559                 :            : {
    1560                 :            :         uint16_t sport = 4500, dport = 4500;
    1561                 :            :         union roc_ow_ipsec_sa_word2 w2;
    1562                 :            :         uint32_t replay_win_sz;
    1563                 :            :         size_t offset;
    1564                 :            :         int rc;
    1565                 :            : 
    1566                 :            :         /* Initialize the SA */
    1567                 :          0 :         roc_ow_ipsec_inb_sa_init(sa);
    1568                 :            : 
    1569                 :          0 :         w2.u64 = 0;
    1570                 :          0 :         rc = ow_ipsec_sa_common_param_fill(&w2, sa->cipher_key, sa->w8.s.salt, sa->hmac_opad_ipad,
    1571                 :            :                                            ipsec_xfrm, crypto_xfrm);
    1572         [ #  # ]:          0 :         if (rc)
    1573                 :            :                 return rc;
    1574                 :            : 
    1575                 :            :         /* Updata common word2 data */
    1576                 :          0 :         sa->w2.u64 = w2.u64;
    1577                 :            : 
    1578                 :            :         /* Only support power-of-two window sizes supported */
    1579                 :          0 :         replay_win_sz = ipsec_xfrm->replay_win_sz;
    1580         [ #  # ]:          0 :         if (replay_win_sz) {
    1581         [ #  # ]:          0 :                 if (!rte_is_power_of_2(replay_win_sz) || replay_win_sz > ROC_AR_WIN_SIZE_MAX)
    1582                 :            :                         return -ENOTSUP;
    1583                 :            : 
    1584                 :          0 :                 sa->w0.s.ar_win = rte_log2_u32(replay_win_sz) - 5;
    1585                 :            :         }
    1586                 :            : 
    1587                 :          0 :         rc = ow_ipsec_inb_tunnel_hdr_fill(sa, ipsec_xfrm);
    1588         [ #  # ]:          0 :         if (rc)
    1589                 :            :                 return rc;
    1590                 :            : 
    1591                 :            :         /* Default options for pkt_out and pkt_fmt are with
    1592                 :            :          * second pass meta and no defrag.
    1593                 :            :          */
    1594                 :          0 :         sa->w0.s.pkt_format = ROC_IE_OT_SA_PKT_FMT_META;
    1595                 :          0 :         sa->w0.s.pkt_output = ROC_IE_OT_SA_PKT_OUTPUT_NO_FRAG;
    1596                 :          0 :         sa->w0.s.pkind = ROC_IE_OT_CPT_PKIND;
    1597                 :            : 
    1598         [ #  # ]:          0 :         if (ipsec_xfrm->options.ip_reassembly_en)
    1599                 :          0 :                 sa->w0.s.pkt_output = ROC_IE_OT_SA_PKT_OUTPUT_HW_BASED_DEFRAG;
    1600                 :            : 
    1601                 :            :         /* ESN */
    1602                 :          0 :         sa->w2.s.esn_en = !!ipsec_xfrm->options.esn;
    1603         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_encap) {
    1604         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.sport)
    1605                 :            :                         sport = ipsec_xfrm->udp.sport;
    1606                 :            : 
    1607         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.dport)
    1608                 :            :                         dport = ipsec_xfrm->udp.dport;
    1609                 :            : 
    1610                 :          0 :                 sa->w10.s.udp_src_port = sport;
    1611                 :          0 :                 sa->w10.s.udp_dst_port = dport;
    1612                 :            :         }
    1613                 :            : 
    1614         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_ports_verify)
    1615                 :          0 :                 sa->w2.s.udp_ports_verify = 1;
    1616                 :            : 
    1617                 :            :         offset = offsetof(struct roc_ow_ipsec_inb_sa, ctx);
    1618                 :            :         /* Word offset for HW managed SA field */
    1619                 :          0 :         sa->w0.s.hw_ctx_off = offset / 8;
    1620                 :            :         /* Context push size for inbound spans up to hw_ctx including
    1621                 :            :          * ar_base field, in 8b units
    1622                 :            :          */
    1623         [ #  # ]:          0 :         sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
    1624                 :            :         /* Entire context size in 128B units */
    1625                 :          0 :         sa->w0.s.ctx_size =
    1626                 :          0 :                 (PLT_ALIGN_CEIL(ow_ipsec_inb_ctx_size(sa), ROC_CTX_UNIT_128B) / ROC_CTX_UNIT_128B) -
    1627                 :            :                 1;
    1628                 :            : 
    1629         [ #  # ]:          0 :         if (sa->w0.s.ctx_size < ctx_ilen)
    1630                 :          0 :                 sa->w0.s.ctx_size = ctx_ilen;
    1631                 :            : 
    1632                 :            :         /**
    1633                 :            :          * CPT MC triggers expiry when counter value changes from 2 to 1. To
    1634                 :            :          * mitigate this behaviour add 1 to the life counter values provided.
    1635                 :            :          */
    1636                 :            : 
    1637         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit) {
    1638                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
    1639                 :          0 :                 sa->w0.s.soft_life_dec = 1;
    1640                 :            :         }
    1641                 :            : 
    1642         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_soft_limit) {
    1643                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
    1644                 :          0 :                 sa->w0.s.soft_life_dec = 1;
    1645                 :            :         }
    1646                 :            : 
    1647         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_hard_limit) {
    1648                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
    1649                 :          0 :                 sa->w0.s.hard_life_dec = 1;
    1650                 :            :         }
    1651                 :            : 
    1652         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_hard_limit) {
    1653                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
    1654                 :          0 :                 sa->w0.s.hard_life_dec = 1;
    1655                 :            :         }
    1656                 :            : 
    1657                 :            :         rte_wmb();
    1658                 :            : 
    1659                 :            :         /* Enable SA */
    1660                 :          0 :         sa->w2.s.valid = 1;
    1661                 :          0 :         return 0;
    1662                 :            : }
    1663                 :            : 
    1664                 :            : RTE_EXPORT_INTERNAL_SYMBOL(cnxk_ow_ipsec_outb_sa_fill)
    1665                 :            : int
    1666                 :          0 : cnxk_ow_ipsec_outb_sa_fill(struct roc_ow_ipsec_outb_sa *sa,
    1667                 :            :                            struct rte_security_ipsec_xform *ipsec_xfrm,
    1668                 :            :                            struct rte_crypto_sym_xform *crypto_xfrm, uint8_t ctx_ilen)
    1669                 :            : {
    1670                 :            :         struct rte_security_ipsec_tunnel_param *tunnel = &ipsec_xfrm->tunnel;
    1671                 :            :         uint16_t sport = 4500, dport = 4500;
    1672                 :            :         union roc_ow_ipsec_sa_word2 w2;
    1673                 :            :         size_t offset;
    1674                 :            :         int rc;
    1675                 :            : 
    1676                 :            :         /* Initialize the SA */
    1677                 :          0 :         roc_ow_ipsec_outb_sa_init(sa);
    1678                 :            : 
    1679                 :          0 :         w2.u64 = 0;
    1680                 :          0 :         rc = ow_ipsec_sa_common_param_fill(&w2, sa->cipher_key, sa->iv.s.salt, sa->hmac_opad_ipad,
    1681                 :            :                                            ipsec_xfrm, crypto_xfrm);
    1682         [ #  # ]:          0 :         if (rc)
    1683                 :            :                 return rc;
    1684                 :            : 
    1685                 :            :         /* Update common word2 data */
    1686                 :          0 :         sa->w2.u64 = w2.u64;
    1687                 :            : 
    1688         [ #  # ]:          0 :         if (ipsec_xfrm->mode != RTE_SECURITY_IPSEC_SA_MODE_TUNNEL)
    1689                 :          0 :                 goto skip_tunnel_info;
    1690                 :            : 
    1691                 :            :         /* Tunnel header info */
    1692      [ #  #  # ]:          0 :         switch (tunnel->type) {
    1693                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV4:
    1694                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_4;
    1695         [ #  # ]:          0 :                 memcpy(&sa->outer_hdr.ipv4.src_addr, &tunnel->ipv4.src_ip, sizeof(struct in_addr));
    1696                 :          0 :                 memcpy(&sa->outer_hdr.ipv4.dst_addr, &tunnel->ipv4.dst_ip, sizeof(struct in_addr));
    1697                 :            : 
    1698                 :            :                 /* IP Source and Dest seems to be in LE/CPU endian */
    1699         [ #  # ]:          0 :                 sa->outer_hdr.ipv4.src_addr = rte_be_to_cpu_32(sa->outer_hdr.ipv4.src_addr);
    1700         [ #  # ]:          0 :                 sa->outer_hdr.ipv4.dst_addr = rte_be_to_cpu_32(sa->outer_hdr.ipv4.dst_addr);
    1701                 :            : 
    1702                 :            :                 /* Outer header DF bit source */
    1703         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_df) {
    1704                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src = ROC_IE_OT_SA_COPY_FROM_SA;
    1705                 :          0 :                         sa->w10.s.ipv4_df_or_ipv6_flw_lbl = tunnel->ipv4.df;
    1706                 :            :                 } else {
    1707                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src =
    1708                 :            :                                 ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
    1709                 :            :                 }
    1710                 :            : 
    1711                 :            :                 /* Outer header DSCP source */
    1712         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_dscp) {
    1713                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_SA;
    1714                 :          0 :                         sa->w10.s.dscp = tunnel->ipv4.dscp;
    1715                 :            :                 } else {
    1716                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
    1717                 :            :                 }
    1718                 :            :                 break;
    1719                 :          0 :         case RTE_SECURITY_IPSEC_TUNNEL_IPV6:
    1720                 :          0 :                 sa->w2.s.outer_ip_ver = ROC_IE_SA_IP_VERSION_6;
    1721                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.src_addr, &tunnel->ipv6.src_addr,
    1722                 :            :                        sizeof(struct in6_addr));
    1723                 :          0 :                 memcpy(&sa->outer_hdr.ipv6.dst_addr, &tunnel->ipv6.dst_addr,
    1724                 :            :                        sizeof(struct in6_addr));
    1725                 :            : 
    1726                 :            :                 /* IP Source and Dest are in LE/CPU endian */
    1727                 :          0 :                 ow_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.src_addr);
    1728                 :          0 :                 ow_ipsec_update_ipv6_addr_endianness((uint64_t *)&sa->outer_hdr.ipv6.dst_addr);
    1729                 :            : 
    1730                 :            :                 /* Outer header flow label source */
    1731         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_flabel) {
    1732                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src = ROC_IE_OT_SA_COPY_FROM_SA;
    1733                 :            : 
    1734                 :          0 :                         sa->w10.s.ipv4_df_or_ipv6_flw_lbl = tunnel->ipv6.flabel;
    1735                 :            :                 } else {
    1736                 :          0 :                         sa->w2.s.ipv4_df_src_or_ipv6_flw_lbl_src =
    1737                 :            :                                 ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
    1738                 :            :                 }
    1739                 :            : 
    1740                 :            :                 /* Outer header DSCP source */
    1741         [ #  # ]:          0 :                 if (!ipsec_xfrm->options.copy_dscp) {
    1742                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_SA;
    1743                 :          0 :                         sa->w10.s.dscp = tunnel->ipv6.dscp;
    1744                 :            :                 } else {
    1745                 :          0 :                         sa->w2.s.dscp_src = ROC_IE_OT_SA_COPY_FROM_INNER_IP_HDR;
    1746                 :            :                 }
    1747                 :            :                 break;
    1748                 :            :         default:
    1749                 :            :                 return -EINVAL;
    1750                 :            :         }
    1751                 :            : 
    1752                 :          0 : skip_tunnel_info:
    1753                 :            :         /* ESN */
    1754                 :          0 :         sa->w0.s.esn_en = !!ipsec_xfrm->options.esn;
    1755                 :            : 
    1756         [ #  # ]:          0 :         if (ipsec_xfrm->esn.value)
    1757                 :          0 :                 sa->ctx.esn_val = ipsec_xfrm->esn.value - 1;
    1758                 :            : 
    1759         [ #  # ]:          0 :         if (ipsec_xfrm->options.udp_encap) {
    1760         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.sport)
    1761                 :            :                         sport = ipsec_xfrm->udp.sport;
    1762                 :            : 
    1763         [ #  # ]:          0 :                 if (ipsec_xfrm->udp.dport)
    1764                 :            :                         dport = ipsec_xfrm->udp.dport;
    1765                 :            : 
    1766                 :          0 :                 sa->w10.s.udp_src_port = sport;
    1767                 :          0 :                 sa->w10.s.udp_dst_port = dport;
    1768                 :            :         }
    1769                 :            : 
    1770                 :            :         offset = offsetof(struct roc_ow_ipsec_outb_sa, ctx);
    1771                 :            :         /* Word offset for HW managed SA field */
    1772                 :          0 :         sa->w0.s.hw_ctx_off = offset / 8;
    1773                 :            : 
    1774                 :            :         /* Context push size is up to err ctl in HW ctx */
    1775                 :          0 :         sa->w0.s.ctx_push_size = sa->w0.s.hw_ctx_off + 1;
    1776                 :            : 
    1777                 :            :         /* Entire context size in 128B units */
    1778                 :            :         offset = sizeof(struct roc_ow_ipsec_outb_sa);
    1779                 :          0 :         sa->w0.s.ctx_size = (PLT_ALIGN_CEIL(offset, ROC_CTX_UNIT_128B) / ROC_CTX_UNIT_128B) - 1;
    1780                 :            : 
    1781                 :            :         /* IPID gen */
    1782                 :          0 :         sa->w2.s.ipid_gen = 1;
    1783                 :            : 
    1784         [ #  # ]:          0 :         if (sa->w0.s.ctx_size < ctx_ilen)
    1785                 :          0 :                 sa->w0.s.ctx_size = ctx_ilen;
    1786                 :            : 
    1787                 :            :         /**
    1788                 :            :          * CPT MC triggers expiry when counter value changes from 2 to 1. To
    1789                 :            :          * mitigate this behaviour add 1 to the life counter values provided.
    1790                 :            :          */
    1791                 :            : 
    1792         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_soft_limit) {
    1793                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.bytes_soft_limit + 1;
    1794                 :          0 :                 sa->w0.s.soft_life_dec = 1;
    1795                 :            :         }
    1796                 :            : 
    1797         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_soft_limit) {
    1798                 :          0 :                 sa->ctx.soft_life = ipsec_xfrm->life.packets_soft_limit + 1;
    1799                 :          0 :                 sa->w0.s.soft_life_dec = 1;
    1800                 :            :         }
    1801                 :            : 
    1802         [ #  # ]:          0 :         if (ipsec_xfrm->life.bytes_hard_limit) {
    1803                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.bytes_hard_limit + 1;
    1804                 :          0 :                 sa->w0.s.hard_life_dec = 1;
    1805                 :            :         }
    1806                 :            : 
    1807         [ #  # ]:          0 :         if (ipsec_xfrm->life.packets_hard_limit) {
    1808                 :          0 :                 sa->ctx.hard_life = ipsec_xfrm->life.packets_hard_limit + 1;
    1809                 :          0 :                 sa->w0.s.hard_life_dec = 1;
    1810                 :            :         }
    1811                 :            : 
    1812                 :            :         /* There are two words of CPT_CTX_HW_S for ucode to skip */
    1813                 :          0 :         sa->w0.s.ctx_hdr_size = 1;
    1814                 :          0 :         sa->w0.s.aop_valid = 1;
    1815                 :            : 
    1816                 :            :         rte_wmb();
    1817                 :            : 
    1818                 :            :         /* Enable SA */
    1819                 :          0 :         sa->w2.s.valid = 1;
    1820                 :          0 :         return 0;
    1821                 :            : }

Generated by: LCOV version 1.14