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

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2025 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef __CN20K_TLS_OPS_H__
       6                 :            : #define __CN20K_TLS_OPS_H__
       7                 :            : 
       8                 :            : #include <rte_crypto_sym.h>
       9                 :            : #include <rte_security.h>
      10                 :            : 
      11                 :            : #include "roc_ie.h"
      12                 :            : 
      13                 :            : #include "cn20k_cryptodev.h"
      14                 :            : #include "cn20k_cryptodev_sec.h"
      15                 :            : #include "cnxk_cryptodev.h"
      16                 :            : #include "cnxk_cryptodev_ops.h"
      17                 :            : #include "cnxk_sg.h"
      18                 :            : 
      19                 :            : static __rte_always_inline int
      20                 :            : process_tls_write(struct roc_cpt_lf *lf, struct rte_crypto_op *cop, struct cn20k_sec_session *sess,
      21                 :            :                   struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
      22                 :            :                   struct cpt_inst_s *inst)
      23                 :            : {
      24                 :          0 :         struct cn20k_tls_opt tls_opt = sess->tls_opt;
      25                 :            :         struct rte_crypto_sym_op *sym_op = cop->sym;
      26                 :            : #ifdef LA_IPSEC_DEBUG
      27                 :            :         struct roc_ie_ow_tls_write_sa *write_sa;
      28                 :            : #endif
      29                 :          0 :         struct rte_mbuf *m_src = sym_op->m_src;
      30                 :          0 :         struct rte_mbuf *m_dst = sym_op->m_dst;
      31                 :            :         uint32_t pad_len, pad_bytes;
      32                 :            :         struct rte_mbuf *last_seg;
      33                 :            :         union cpt_inst_w4 w4;
      34                 :            :         void *m_data = NULL;
      35                 :            :         uint8_t *in_buffer;
      36                 :            : 
      37                 :          0 :         pad_bytes = (cop->aux_flags * 8) > 0xff ? 0xff : (cop->aux_flags * 8);
      38                 :          0 :         pad_len = (pad_bytes >> tls_opt.pad_shift) * tls_opt.enable_padding;
      39                 :            : 
      40                 :            : #ifdef LA_IPSEC_DEBUG
      41                 :            :         write_sa = sess->tls_rec.write_sa;
      42                 :            :         if (write_sa == NULL) {
      43                 :            :                 return -EINVAL;
      44                 :            :         }
      45                 :            : 
      46                 :            :         if (write_sa->w2.s.iv_at_cptr == ROC_IE_OW_TLS_IV_SRC_FROM_SA) {
      47                 :            : 
      48                 :            :                 uint8_t *iv = PLT_PTR_ADD(write_sa->cipher_key, 32);
      49                 :            : 
      50                 :            :                 if (write_sa->w2.s.cipher_select == ROC_IE_OW_TLS_CIPHER_AES_GCM) {
      51                 :            :                         uint32_t *tmp;
      52                 :            : 
      53                 :            :                         /* For GCM, the IV and salt format will be like below:
      54                 :            :                          * iv[0-3]: lower bytes of IV in BE format.
      55                 :            :                          * iv[4-7]: salt / nonce.
      56                 :            :                          * iv[12-15]: upper bytes of IV in BE format.
      57                 :            :                          */
      58                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 4);
      59                 :            :                         tmp = (uint32_t *)iv;
      60                 :            :                         *tmp = rte_be_to_cpu_32(*tmp);
      61                 :            : 
      62                 :            :                         memcpy(iv + 12,
      63                 :            :                                rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset + 4), 4);
      64                 :            :                         tmp = (uint32_t *)(iv + 12);
      65                 :            :                         *tmp = rte_be_to_cpu_32(*tmp);
      66                 :            :                 } else if (write_sa->w2.s.cipher_select == ROC_IE_OW_TLS_CIPHER_AES_CBC) {
      67                 :            :                         uint64_t *tmp;
      68                 :            : 
      69                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 16);
      70                 :            :                         tmp = (uint64_t *)iv;
      71                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      72                 :            :                         tmp = (uint64_t *)(iv + 8);
      73                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      74                 :            :                 } else if (write_sa->w2.s.cipher_select == ROC_IE_OW_TLS_CIPHER_3DES) {
      75                 :            :                         uint64_t *tmp;
      76                 :            : 
      77                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 8);
      78                 :            :                         tmp = (uint64_t *)iv;
      79                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      80                 :            :                 }
      81                 :            : 
      82                 :            :                 /* Trigger CTX reload to fetch new data from DRAM */
      83                 :            :                 roc_cpt_lf_ctx_reload(lf, write_sa);
      84                 :            :                 rte_delay_ms(1);
      85                 :            :         }
      86                 :            : #else
      87                 :            :         RTE_SET_USED(lf);
      88                 :            : #endif
      89                 :            :         /* Single buffer direct mode */
      90         [ #  # ]:          0 :         if (likely(m_src->next == NULL)) {
      91                 :            :                 void *vaddr;
      92                 :            : 
      93         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(m_src) < sess->max_extended_len)) {
      94                 :          0 :                         plt_dp_err("Not enough tail room");
      95                 :          0 :                         return -ENOMEM;
      96                 :            :                 }
      97                 :            : 
      98                 :          0 :                 vaddr = rte_pktmbuf_mtod(m_src, void *);
      99                 :          0 :                 inst->dptr = (uint64_t)vaddr;
     100                 :          0 :                 inst->rptr = (uint64_t)vaddr;
     101                 :            : 
     102                 :          0 :                 w4.u64 = sess->inst.w4;
     103                 :          0 :                 w4.s.param1 = m_src->data_len;
     104                 :          0 :                 w4.s.dlen = m_src->data_len;
     105                 :            : 
     106                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
     107                 :          0 :                 w4.s.opcode_minor = pad_len;
     108                 :            : 
     109                 :          0 :                 inst->w4.u64 = w4.u64;
     110                 :            :         } else {
     111                 :            :                 struct roc_sg2list_comp *scatter_comp, *gather_comp;
     112                 :            :                 union cpt_inst_w5 cpt_inst_w5;
     113                 :            :                 union cpt_inst_w6 cpt_inst_w6;
     114                 :            :                 uint32_t g_size_bytes;
     115                 :            :                 int i;
     116                 :            : 
     117                 :          0 :                 last_seg = rte_pktmbuf_lastseg(m_src);
     118                 :            : 
     119         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
     120                 :          0 :                         plt_dp_err("Not enough tail room (required: %d, available: %d)",
     121                 :            :                                    sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
     122                 :          0 :                         return -ENOMEM;
     123                 :            :                 }
     124                 :            : 
     125         [ #  # ]:          0 :                 if (unlikely(m_src->nb_segs > ROC_SG2_MAX_PTRS)) {
     126                 :          0 :                         plt_dp_err("Exceeds max supported components. Reduce segments");
     127                 :          0 :                         return -1;
     128                 :            :                 }
     129                 :            : 
     130         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     131         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     132                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     133                 :          0 :                         return -ENOMEM;
     134                 :            :                 }
     135                 :            : 
     136                 :            :                 in_buffer = (uint8_t *)m_data;
     137                 :            :                 /* Input Gather List */
     138                 :            :                 i = 0;
     139                 :            :                 gather_comp = (struct roc_sg2list_comp *)((uint8_t *)in_buffer);
     140                 :          0 :                 i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
     141                 :            : 
     142                 :          0 :                 cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
     143                 :          0 :                 g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
     144                 :            : 
     145                 :            :                 /* Output Scatter List */
     146                 :          0 :                 last_seg->data_len += sess->max_extended_len + pad_bytes;
     147                 :            :                 i = 0;
     148                 :          0 :                 scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
     149                 :            : 
     150         [ #  # ]:          0 :                 if (m_dst == NULL)
     151                 :            :                         m_dst = m_src;
     152                 :          0 :                 i = fill_sg2_comp_from_pkt(scatter_comp, i, m_dst);
     153                 :            : 
     154                 :          0 :                 cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
     155                 :            : 
     156                 :          0 :                 cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
     157                 :          0 :                 cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
     158                 :            : 
     159                 :          0 :                 inst->w5.u64 = cpt_inst_w5.u64;
     160                 :          0 :                 inst->w6.u64 = cpt_inst_w6.u64;
     161                 :          0 :                 w4.u64 = sess->inst.w4;
     162                 :          0 :                 w4.s.dlen = rte_pktmbuf_pkt_len(m_src);
     163                 :          0 :                 w4.s.opcode_major &= (~(ROC_IE_OW_INPLACE_BIT));
     164                 :          0 :                 w4.s.opcode_minor = pad_len;
     165                 :          0 :                 w4.s.param1 = w4.s.dlen;
     166                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
     167                 :          0 :                 inst->w4.u64 = w4.u64;
     168                 :            :         }
     169                 :            : 
     170                 :            :         return 0;
     171                 :            : }
     172                 :            : 
     173                 :            : static __rte_always_inline int
     174                 :            : process_tls_read(struct rte_crypto_op *cop, struct cn20k_sec_session *sess,
     175                 :            :                  struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
     176                 :            :                  struct cpt_inst_s *inst)
     177                 :            : {
     178                 :            :         struct rte_crypto_sym_op *sym_op = cop->sym;
     179                 :          0 :         struct rte_mbuf *m_src = sym_op->m_src;
     180                 :          0 :         struct rte_mbuf *m_dst = sym_op->m_dst;
     181                 :            :         union cpt_inst_w4 w4;
     182                 :            :         uint8_t *in_buffer;
     183                 :            :         void *m_data;
     184                 :            : 
     185         [ #  # ]:          0 :         if (likely(m_src->next == NULL)) {
     186                 :            :                 void *vaddr;
     187                 :            : 
     188                 :          0 :                 vaddr = rte_pktmbuf_mtod(m_src, void *);
     189                 :            : 
     190                 :          0 :                 inst->dptr = (uint64_t)vaddr;
     191                 :          0 :                 inst->rptr = (uint64_t)vaddr;
     192                 :            : 
     193                 :          0 :                 w4.u64 = sess->inst.w4;
     194                 :          0 :                 w4.s.dlen = m_src->data_len;
     195                 :          0 :                 w4.s.param1 = m_src->data_len;
     196                 :          0 :                 inst->w4.u64 = w4.u64;
     197                 :            :         } else {
     198                 :            :                 struct roc_sg2list_comp *scatter_comp, *gather_comp;
     199                 :          0 :                 int tail_len = sess->tls_opt.tail_fetch_len * 16;
     200                 :          0 :                 int pkt_len = rte_pktmbuf_pkt_len(m_src);
     201                 :            :                 union cpt_inst_w5 cpt_inst_w5;
     202                 :            :                 union cpt_inst_w6 cpt_inst_w6;
     203                 :            :                 uint32_t g_size_bytes;
     204                 :            :                 int i;
     205                 :            : 
     206         [ #  # ]:          0 :                 if (unlikely(m_src->nb_segs > ROC_SG2_MAX_PTRS)) {
     207                 :          0 :                         plt_dp_err("Exceeds max supported components. Reduce segments");
     208                 :          0 :                         return -1;
     209                 :            :                 }
     210                 :            : 
     211         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     212         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     213                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     214                 :          0 :                         return -ENOMEM;
     215                 :            :                 }
     216                 :            : 
     217                 :            :                 in_buffer = (uint8_t *)m_data;
     218                 :            :                 /* Input Gather List */
     219                 :            :                 i = 0;
     220                 :            : 
     221                 :            :                 /* First 32 bytes in m_data are rsvd for tail fetch.
     222                 :            :                  * SG list start from 32 byte onwards.
     223                 :            :                  */
     224                 :          0 :                 gather_comp = (struct roc_sg2list_comp *)((uint8_t *)(in_buffer + 32));
     225                 :            : 
     226                 :            :                 /* Add the last blocks as first gather component for tail fetch. */
     227         [ #  # ]:          0 :                 if (tail_len) {
     228                 :            :                         const uint8_t *output;
     229                 :            : 
     230                 :          0 :                         output = rte_pktmbuf_read(m_src, pkt_len - tail_len, tail_len, in_buffer);
     231         [ #  # ]:          0 :                         if (output != in_buffer)
     232         [ #  # ]:          0 :                                 rte_memcpy(in_buffer, output, tail_len);
     233                 :          0 :                         i = fill_sg2_comp(gather_comp, i, (uint64_t)in_buffer, tail_len);
     234                 :            :                 }
     235                 :            : 
     236                 :          0 :                 i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
     237                 :            : 
     238                 :          0 :                 cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
     239                 :          0 :                 g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
     240                 :            : 
     241                 :            :                 i = 0;
     242                 :          0 :                 scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
     243                 :            : 
     244         [ #  # ]:          0 :                 if (m_dst == NULL)
     245                 :            :                         m_dst = m_src;
     246                 :          0 :                 i = fill_sg2_comp_from_pkt(scatter_comp, i, m_dst);
     247                 :            : 
     248                 :          0 :                 cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
     249                 :            : 
     250                 :          0 :                 cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
     251                 :          0 :                 cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
     252                 :            : 
     253                 :          0 :                 inst->w5.u64 = cpt_inst_w5.u64;
     254                 :          0 :                 inst->w6.u64 = cpt_inst_w6.u64;
     255                 :          0 :                 w4.u64 = sess->inst.w4;
     256                 :          0 :                 w4.s.dlen = pkt_len + tail_len;
     257                 :          0 :                 w4.s.param1 = w4.s.dlen;
     258                 :          0 :                 w4.s.opcode_major &= (~(ROC_IE_OW_INPLACE_BIT));
     259                 :          0 :                 inst->w4.u64 = w4.u64;
     260                 :            :         }
     261                 :            : 
     262                 :            :         return 0;
     263                 :            : }
     264                 :            : #endif /* __CN20K_TLS_OPS_H__ */

Generated by: LCOV version 1.14