LCOV - code coverage report
Current view: top level - drivers/crypto/cnxk - cn10k_tls_ops.h (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 143 0.0 %
Date: 2025-01-02 22:41:34 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 56 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2024 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #ifndef __CN10K_TLS_OPS_H__
       6                 :            : #define __CN10K_TLS_OPS_H__
       7                 :            : 
       8                 :            : #include <rte_crypto_sym.h>
       9                 :            : #include <rte_security.h>
      10                 :            : 
      11                 :            : #include "roc_ie.h"
      12                 :            : 
      13                 :            : #include "cn10k_cryptodev.h"
      14                 :            : #include "cn10k_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 cn10k_sec_session *sess,
      21                 :            :                   struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
      22                 :            :                   struct cpt_inst_s *inst, const bool is_sg_ver2)
      23                 :            : {
      24                 :          0 :         struct cn10k_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_ot_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->w2.s.iv_at_cptr == ROC_IE_OT_TLS_IV_SRC_FROM_SA) {
      43                 :            : 
      44                 :            :                 uint8_t *iv = PLT_PTR_ADD(write_sa->cipher_key, 32);
      45                 :            : 
      46                 :            :                 if (write_sa->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_AES_GCM) {
      47                 :            :                         uint32_t *tmp;
      48                 :            : 
      49                 :            :                         /* For GCM, the IV and salt format will be like below:
      50                 :            :                          * iv[0-3]: lower bytes of IV in BE format.
      51                 :            :                          * iv[4-7]: salt / nonce.
      52                 :            :                          * iv[12-15]: upper bytes of IV in BE format.
      53                 :            :                          */
      54                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 4);
      55                 :            :                         tmp = (uint32_t *)iv;
      56                 :            :                         *tmp = rte_be_to_cpu_32(*tmp);
      57                 :            : 
      58                 :            :                         memcpy(iv + 12,
      59                 :            :                                rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset + 4), 4);
      60                 :            :                         tmp = (uint32_t *)(iv + 12);
      61                 :            :                         *tmp = rte_be_to_cpu_32(*tmp);
      62                 :            :                 } else if (write_sa->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_AES_CBC) {
      63                 :            :                         uint64_t *tmp;
      64                 :            : 
      65                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 16);
      66                 :            :                         tmp = (uint64_t *)iv;
      67                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      68                 :            :                         tmp = (uint64_t *)(iv + 8);
      69                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      70                 :            :                 } else if (write_sa->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_3DES) {
      71                 :            :                         uint64_t *tmp;
      72                 :            : 
      73                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 8);
      74                 :            :                         tmp = (uint64_t *)iv;
      75                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      76                 :            :                 }
      77                 :            : 
      78                 :            :                 /* Trigger CTX reload to fetch new data from DRAM */
      79                 :            :                 roc_cpt_lf_ctx_reload(lf, write_sa);
      80                 :            :                 rte_delay_ms(1);
      81                 :            :         }
      82                 :            : #else
      83                 :            :         RTE_SET_USED(lf);
      84                 :            : #endif
      85                 :            :         /* Single buffer direct mode */
      86         [ #  # ]:          0 :         if (likely(m_src->next == NULL)) {
      87                 :            :                 void *vaddr;
      88                 :            : 
      89         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(m_src) < sess->max_extended_len)) {
      90                 :          0 :                         plt_dp_err("Not enough tail room");
      91                 :          0 :                         return -ENOMEM;
      92                 :            :                 }
      93                 :            : 
      94                 :          0 :                 vaddr = rte_pktmbuf_mtod(m_src, void *);
      95                 :          0 :                 inst->dptr = (uint64_t)vaddr;
      96                 :          0 :                 inst->rptr = (uint64_t)vaddr;
      97                 :            : 
      98                 :          0 :                 w4.u64 = sess->inst.w4;
      99                 :          0 :                 w4.s.param1 = m_src->data_len;
     100                 :          0 :                 w4.s.dlen = m_src->data_len;
     101                 :            : 
     102                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
     103                 :          0 :                 w4.s.opcode_minor = pad_len;
     104                 :            : 
     105                 :          0 :                 inst->w4.u64 = w4.u64;
     106         [ #  # ]:          0 :         } else if (is_sg_ver2 == false) {
     107                 :            :                 struct roc_sglist_comp *scatter_comp, *gather_comp;
     108                 :            :                 uint32_t g_size_bytes, s_size_bytes;
     109                 :            :                 uint32_t dlen;
     110                 :            :                 int i;
     111                 :            : 
     112                 :          0 :                 last_seg = rte_pktmbuf_lastseg(m_src);
     113                 :            : 
     114         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
     115                 :          0 :                         plt_dp_err("Not enough tail room (required: %d, available: %d)",
     116                 :            :                                    sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
     117                 :          0 :                         return -ENOMEM;
     118                 :            :                 }
     119                 :            : 
     120         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     121         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     122                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     123                 :          0 :                         return -ENOMEM;
     124                 :            :                 }
     125                 :            : 
     126                 :            :                 in_buffer = (uint8_t *)m_data;
     127                 :          0 :                 ((uint16_t *)in_buffer)[0] = 0;
     128                 :          0 :                 ((uint16_t *)in_buffer)[1] = 0;
     129                 :            : 
     130                 :            :                 /* Input Gather List */
     131                 :            :                 i = 0;
     132                 :          0 :                 gather_comp = (struct roc_sglist_comp *)((uint8_t *)in_buffer + 8);
     133                 :            : 
     134                 :          0 :                 i = fill_sg_comp_from_pkt(gather_comp, i, m_src);
     135         [ #  # ]:          0 :                 ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
     136                 :            : 
     137                 :          0 :                 g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     138                 :            : 
     139                 :            :                 i = 0;
     140                 :          0 :                 scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
     141                 :            : 
     142                 :          0 :                 i = fill_sg_comp_from_pkt(scatter_comp, i, m_src);
     143         [ #  # ]:          0 :                 ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
     144                 :            : 
     145                 :          0 :                 s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     146                 :            : 
     147                 :          0 :                 dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
     148                 :            : 
     149                 :          0 :                 inst->dptr = (uint64_t)in_buffer;
     150                 :          0 :                 inst->rptr = (uint64_t)in_buffer;
     151                 :            : 
     152                 :          0 :                 w4.u64 = sess->inst.w4;
     153                 :          0 :                 w4.s.dlen = dlen;
     154                 :          0 :                 w4.s.param1 = rte_pktmbuf_pkt_len(m_src);
     155                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
     156                 :          0 :                 w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
     157                 :          0 :                 w4.s.opcode_minor = pad_len;
     158                 :            : 
     159                 :            :                 /* Output Scatter List */
     160                 :          0 :                 last_seg->data_len += sess->max_extended_len + pad_bytes;
     161                 :          0 :                 inst->w4.u64 = w4.u64;
     162                 :            :         } else {
     163                 :            :                 struct roc_sg2list_comp *scatter_comp, *gather_comp;
     164                 :            :                 union cpt_inst_w5 cpt_inst_w5;
     165                 :            :                 union cpt_inst_w6 cpt_inst_w6;
     166                 :            :                 uint32_t g_size_bytes;
     167                 :            :                 int i;
     168                 :            : 
     169                 :          0 :                 last_seg = rte_pktmbuf_lastseg(m_src);
     170                 :            : 
     171         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
     172                 :          0 :                         plt_dp_err("Not enough tail room (required: %d, available: %d)",
     173                 :            :                                    sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
     174                 :          0 :                         return -ENOMEM;
     175                 :            :                 }
     176                 :            : 
     177         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     178         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     179                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     180                 :          0 :                         return -ENOMEM;
     181                 :            :                 }
     182                 :            : 
     183                 :            :                 in_buffer = (uint8_t *)m_data;
     184                 :            :                 /* Input Gather List */
     185                 :            :                 i = 0;
     186                 :            :                 gather_comp = (struct roc_sg2list_comp *)((uint8_t *)in_buffer);
     187                 :          0 :                 i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
     188                 :            : 
     189                 :          0 :                 cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
     190                 :          0 :                 g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
     191                 :            : 
     192                 :            :                 i = 0;
     193                 :          0 :                 scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
     194                 :            : 
     195         [ #  # ]:          0 :                 if (m_dst == NULL)
     196                 :            :                         m_dst = m_src;
     197                 :          0 :                 i = fill_sg2_comp_from_pkt(scatter_comp, i, m_dst);
     198                 :            : 
     199                 :          0 :                 cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
     200                 :            : 
     201                 :          0 :                 cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
     202                 :          0 :                 cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
     203                 :            : 
     204                 :          0 :                 inst->w5.u64 = cpt_inst_w5.u64;
     205                 :          0 :                 inst->w6.u64 = cpt_inst_w6.u64;
     206                 :          0 :                 w4.u64 = sess->inst.w4;
     207                 :          0 :                 w4.s.dlen = rte_pktmbuf_pkt_len(m_src);
     208                 :          0 :                 w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
     209                 :          0 :                 w4.s.opcode_minor = pad_len;
     210                 :          0 :                 w4.s.param1 = w4.s.dlen;
     211                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
     212                 :            :                 /* Output Scatter List */
     213                 :          0 :                 last_seg->data_len += sess->max_extended_len + pad_bytes;
     214                 :          0 :                 inst->w4.u64 = w4.u64;
     215                 :            :         }
     216                 :            : 
     217                 :            :         return 0;
     218                 :            : }
     219                 :            : 
     220                 :            : static __rte_always_inline int
     221                 :            : process_tls_read(struct rte_crypto_op *cop, struct cn10k_sec_session *sess,
     222                 :            :                  struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
     223                 :            :                  struct cpt_inst_s *inst, const bool is_sg_ver2)
     224                 :            : {
     225                 :            :         struct rte_crypto_sym_op *sym_op = cop->sym;
     226                 :          0 :         struct rte_mbuf *m_src = sym_op->m_src;
     227                 :          0 :         struct rte_mbuf *m_dst = sym_op->m_dst;
     228                 :            :         union cpt_inst_w4 w4;
     229                 :            :         uint8_t *in_buffer;
     230                 :            :         void *m_data;
     231                 :            : 
     232         [ #  # ]:          0 :         if (likely(m_src->next == NULL)) {
     233                 :            :                 void *vaddr;
     234                 :            : 
     235                 :          0 :                 vaddr = rte_pktmbuf_mtod(m_src, void *);
     236                 :            : 
     237                 :          0 :                 inst->dptr = (uint64_t)vaddr;
     238                 :          0 :                 inst->rptr = (uint64_t)vaddr;
     239                 :            : 
     240                 :          0 :                 w4.u64 = sess->inst.w4;
     241                 :          0 :                 w4.s.dlen = m_src->data_len;
     242                 :          0 :                 w4.s.param1 = m_src->data_len;
     243                 :          0 :                 inst->w4.u64 = w4.u64;
     244         [ #  # ]:          0 :         } else if (is_sg_ver2 == false) {
     245                 :            :                 struct roc_sglist_comp *scatter_comp, *gather_comp;
     246                 :          0 :                 int tail_len = sess->tls_opt.tail_fetch_len * 16;
     247                 :          0 :                 int pkt_len = rte_pktmbuf_pkt_len(m_src);
     248                 :            :                 uint32_t g_size_bytes, s_size_bytes;
     249                 :            :                 uint16_t *sg_hdr;
     250                 :            :                 uint32_t dlen;
     251                 :            :                 int i;
     252                 :            : 
     253         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     254         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     255                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     256                 :          0 :                         return -ENOMEM;
     257                 :            :                 }
     258                 :            : 
     259                 :            :                 /* Input Gather List */
     260                 :            :                 in_buffer = (uint8_t *)m_data;
     261                 :            :                 sg_hdr = (uint16_t *)(in_buffer + 32);
     262                 :          0 :                 gather_comp = (struct roc_sglist_comp *)((uint8_t *)sg_hdr + 8);
     263                 :            :                 i = 0;
     264                 :            :                 /* Add the last blocks as first gather component for tail fetch. */
     265         [ #  # ]:          0 :                 if (tail_len) {
     266                 :            :                         const uint8_t *output;
     267                 :            : 
     268                 :          0 :                         output = rte_pktmbuf_read(m_src, pkt_len - tail_len, tail_len, in_buffer);
     269         [ #  # ]:          0 :                         if (output != in_buffer)
     270         [ #  # ]:          0 :                                 rte_memcpy(in_buffer, output, tail_len);
     271         [ #  # ]:          0 :                         i = fill_sg_comp(gather_comp, i, (uint64_t)in_buffer, tail_len);
     272                 :            :                 }
     273                 :            : 
     274                 :          0 :                 sg_hdr[0] = 0;
     275                 :          0 :                 sg_hdr[1] = 0;
     276                 :          0 :                 i = fill_sg_comp_from_pkt(gather_comp, i, m_src);
     277         [ #  # ]:          0 :                 sg_hdr[2] = rte_cpu_to_be_16(i);
     278                 :            : 
     279                 :          0 :                 g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     280                 :            : 
     281                 :            :                 i = 0;
     282                 :          0 :                 scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
     283                 :            : 
     284                 :          0 :                 i = fill_sg_comp_from_pkt(scatter_comp, i, m_src);
     285         [ #  # ]:          0 :                 sg_hdr[3] = rte_cpu_to_be_16(i);
     286                 :            : 
     287                 :          0 :                 s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     288                 :            : 
     289                 :          0 :                 dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
     290                 :            : 
     291                 :          0 :                 inst->dptr = (uint64_t)in_buffer;
     292                 :          0 :                 inst->rptr = (uint64_t)in_buffer;
     293                 :            : 
     294                 :          0 :                 w4.u64 = sess->inst.w4;
     295                 :          0 :                 w4.s.dlen = dlen;
     296                 :          0 :                 w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
     297                 :          0 :                 w4.s.param1 = pkt_len;
     298                 :          0 :                 inst->w4.u64 = w4.u64;
     299                 :            :         } else {
     300                 :            :                 struct roc_sg2list_comp *scatter_comp, *gather_comp;
     301                 :          0 :                 int tail_len = sess->tls_opt.tail_fetch_len * 16;
     302                 :          0 :                 int pkt_len = rte_pktmbuf_pkt_len(m_src);
     303                 :            :                 union cpt_inst_w5 cpt_inst_w5;
     304                 :            :                 union cpt_inst_w6 cpt_inst_w6;
     305                 :            :                 uint32_t g_size_bytes;
     306                 :            :                 int i;
     307                 :            : 
     308         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     309         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     310                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     311                 :          0 :                         return -ENOMEM;
     312                 :            :                 }
     313                 :            : 
     314                 :            :                 in_buffer = (uint8_t *)m_data;
     315                 :            :                 /* Input Gather List */
     316                 :            :                 i = 0;
     317                 :            : 
     318                 :            :                 /* First 32 bytes in m_data are rsvd for tail fetch.
     319                 :            :                  * SG list start from 32 byte onwards.
     320                 :            :                  */
     321                 :          0 :                 gather_comp = (struct roc_sg2list_comp *)((uint8_t *)(in_buffer + 32));
     322                 :            : 
     323                 :            :                 /* Add the last blocks as first gather component for tail fetch. */
     324         [ #  # ]:          0 :                 if (tail_len) {
     325                 :            :                         const uint8_t *output;
     326                 :            : 
     327                 :          0 :                         output = rte_pktmbuf_read(m_src, pkt_len - tail_len, tail_len, in_buffer);
     328         [ #  # ]:          0 :                         if (output != in_buffer)
     329         [ #  # ]:          0 :                                 rte_memcpy(in_buffer, output, tail_len);
     330                 :          0 :                         i = fill_sg2_comp(gather_comp, i, (uint64_t)in_buffer, tail_len);
     331                 :            :                 }
     332                 :            : 
     333                 :          0 :                 i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
     334                 :            : 
     335                 :          0 :                 cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
     336                 :          0 :                 g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
     337                 :            : 
     338                 :            :                 i = 0;
     339                 :          0 :                 scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
     340                 :            : 
     341         [ #  # ]:          0 :                 if (m_dst == NULL)
     342                 :            :                         m_dst = m_src;
     343                 :          0 :                 i = fill_sg2_comp_from_pkt(scatter_comp, i, m_dst);
     344                 :            : 
     345                 :          0 :                 cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
     346                 :            : 
     347                 :          0 :                 cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
     348                 :          0 :                 cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
     349                 :            : 
     350                 :          0 :                 inst->w5.u64 = cpt_inst_w5.u64;
     351                 :          0 :                 inst->w6.u64 = cpt_inst_w6.u64;
     352                 :          0 :                 w4.u64 = sess->inst.w4;
     353                 :          0 :                 w4.s.dlen = pkt_len + tail_len;
     354                 :          0 :                 w4.s.param1 = w4.s.dlen;
     355                 :          0 :                 w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
     356                 :          0 :                 inst->w4.u64 = w4.u64;
     357                 :            :         }
     358                 :            : 
     359                 :            :         return 0;
     360                 :            : }
     361                 :            : #endif /* __CN10K_TLS_OPS_H__ */

Generated by: LCOV version 1.14