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 121 0.0 %
Date: 2024-03-01 20:19:12 Functions: 0 0 -
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 38 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                 :            :         struct rte_crypto_sym_op *sym_op = cop->sym;
      25                 :            : #ifdef LA_IPSEC_DEBUG
      26                 :            :         struct roc_ie_ot_tls_write_sa *write_sa;
      27                 :            : #endif
      28                 :          0 :         struct rte_mbuf *m_src = sym_op->m_src;
      29                 :            :         struct rte_mbuf *last_seg;
      30                 :            :         union cpt_inst_w4 w4;
      31                 :            :         void *m_data = NULL;
      32                 :            :         uint8_t *in_buffer;
      33                 :            : 
      34                 :            : #ifdef LA_IPSEC_DEBUG
      35                 :            :         write_sa = &sess->tls_rec.write_sa;
      36                 :            :         if (write_sa->w2.s.iv_at_cptr == ROC_IE_OT_TLS_IV_SRC_FROM_SA) {
      37                 :            : 
      38                 :            :                 uint8_t *iv = PLT_PTR_ADD(write_sa->cipher_key, 32);
      39                 :            : 
      40                 :            :                 if (write_sa->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_AES_GCM) {
      41                 :            :                         uint32_t *tmp;
      42                 :            : 
      43                 :            :                         /* For GCM, the IV and salt format will be like below:
      44                 :            :                          * iv[0-3]: lower bytes of IV in BE format.
      45                 :            :                          * iv[4-7]: salt / nonce.
      46                 :            :                          * iv[12-15]: upper bytes of IV in BE format.
      47                 :            :                          */
      48                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 4);
      49                 :            :                         tmp = (uint32_t *)iv;
      50                 :            :                         *tmp = rte_be_to_cpu_32(*tmp);
      51                 :            : 
      52                 :            :                         memcpy(iv + 12,
      53                 :            :                                rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset + 4), 4);
      54                 :            :                         tmp = (uint32_t *)(iv + 12);
      55                 :            :                         *tmp = rte_be_to_cpu_32(*tmp);
      56                 :            :                 } else if (write_sa->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_AES_CBC) {
      57                 :            :                         uint64_t *tmp;
      58                 :            : 
      59                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 16);
      60                 :            :                         tmp = (uint64_t *)iv;
      61                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      62                 :            :                         tmp = (uint64_t *)(iv + 8);
      63                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      64                 :            :                 } else if (write_sa->w2.s.cipher_select == ROC_IE_OT_TLS_CIPHER_3DES) {
      65                 :            :                         uint64_t *tmp;
      66                 :            : 
      67                 :            :                         memcpy(iv, rte_crypto_op_ctod_offset(cop, uint8_t *, sess->iv_offset), 8);
      68                 :            :                         tmp = (uint64_t *)iv;
      69                 :            :                         *tmp = rte_be_to_cpu_64(*tmp);
      70                 :            :                 }
      71                 :            : 
      72                 :            :                 /* Trigger CTX reload to fetch new data from DRAM */
      73                 :            :                 roc_cpt_lf_ctx_reload(lf, write_sa);
      74                 :            :                 rte_delay_ms(1);
      75                 :            :         }
      76                 :            : #else
      77                 :            :         RTE_SET_USED(lf);
      78                 :            : #endif
      79                 :            :         /* Single buffer direct mode */
      80         [ #  # ]:          0 :         if (likely(m_src->next == NULL)) {
      81                 :            :                 void *vaddr;
      82                 :            : 
      83         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(m_src) < sess->max_extended_len)) {
      84                 :          0 :                         plt_dp_err("Not enough tail room");
      85                 :          0 :                         return -ENOMEM;
      86                 :            :                 }
      87                 :            : 
      88                 :          0 :                 vaddr = rte_pktmbuf_mtod(m_src, void *);
      89                 :          0 :                 inst->dptr = (uint64_t)vaddr;
      90                 :          0 :                 inst->rptr = (uint64_t)vaddr;
      91                 :            : 
      92                 :          0 :                 w4.u64 = sess->inst.w4;
      93                 :          0 :                 w4.s.param1 = m_src->data_len;
      94                 :          0 :                 w4.s.dlen = m_src->data_len;
      95                 :            : 
      96                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
      97                 :          0 :                 w4.s.opcode_minor = sess->tls.enable_padding * cop->aux_flags * 8;
      98                 :            : 
      99                 :          0 :                 inst->w4.u64 = w4.u64;
     100         [ #  # ]:          0 :         } else if (is_sg_ver2 == false) {
     101                 :            :                 struct roc_sglist_comp *scatter_comp, *gather_comp;
     102                 :            :                 uint32_t g_size_bytes, s_size_bytes;
     103                 :            :                 uint32_t dlen;
     104                 :            :                 int i;
     105                 :            : 
     106                 :          0 :                 last_seg = rte_pktmbuf_lastseg(m_src);
     107                 :            : 
     108         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
     109                 :          0 :                         plt_dp_err("Not enough tail room (required: %d, available: %d)",
     110                 :            :                                    sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
     111                 :          0 :                         return -ENOMEM;
     112                 :            :                 }
     113                 :            : 
     114         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     115         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     116                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     117                 :          0 :                         return -ENOMEM;
     118                 :            :                 }
     119                 :            : 
     120                 :            :                 in_buffer = (uint8_t *)m_data;
     121                 :          0 :                 ((uint16_t *)in_buffer)[0] = 0;
     122                 :          0 :                 ((uint16_t *)in_buffer)[1] = 0;
     123                 :            : 
     124                 :            :                 /* Input Gather List */
     125                 :            :                 i = 0;
     126                 :          0 :                 gather_comp = (struct roc_sglist_comp *)((uint8_t *)in_buffer + 8);
     127                 :            : 
     128                 :          0 :                 i = fill_sg_comp_from_pkt(gather_comp, i, m_src);
     129         [ #  # ]:          0 :                 ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
     130                 :            : 
     131                 :          0 :                 g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     132                 :            : 
     133                 :            :                 i = 0;
     134                 :          0 :                 scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
     135                 :            : 
     136                 :          0 :                 i = fill_sg_comp_from_pkt(scatter_comp, i, m_src);
     137         [ #  # ]:          0 :                 ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
     138                 :            : 
     139                 :          0 :                 s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     140                 :            : 
     141                 :          0 :                 dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
     142                 :            : 
     143                 :          0 :                 inst->dptr = (uint64_t)in_buffer;
     144                 :          0 :                 inst->rptr = (uint64_t)in_buffer;
     145                 :            : 
     146                 :          0 :                 w4.u64 = sess->inst.w4;
     147                 :          0 :                 w4.s.dlen = dlen;
     148                 :          0 :                 w4.s.param1 = rte_pktmbuf_pkt_len(m_src);
     149                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
     150                 :          0 :                 w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
     151                 :          0 :                 w4.s.opcode_minor = sess->tls.enable_padding * cop->aux_flags * 8;
     152                 :            : 
     153                 :            :                 /* Output Scatter List */
     154                 :          0 :                 last_seg->data_len += sess->max_extended_len;
     155                 :          0 :                 inst->w4.u64 = w4.u64;
     156                 :            :         } else {
     157                 :            :                 struct roc_sg2list_comp *scatter_comp, *gather_comp;
     158                 :            :                 union cpt_inst_w5 cpt_inst_w5;
     159                 :            :                 union cpt_inst_w6 cpt_inst_w6;
     160                 :            :                 uint32_t g_size_bytes;
     161                 :            :                 int i;
     162                 :            : 
     163                 :          0 :                 last_seg = rte_pktmbuf_lastseg(m_src);
     164                 :            : 
     165         [ #  # ]:          0 :                 if (unlikely(rte_pktmbuf_tailroom(last_seg) < sess->max_extended_len)) {
     166                 :          0 :                         plt_dp_err("Not enough tail room (required: %d, available: %d)",
     167                 :            :                                    sess->max_extended_len, rte_pktmbuf_tailroom(last_seg));
     168                 :          0 :                         return -ENOMEM;
     169                 :            :                 }
     170                 :            : 
     171         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     172         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     173                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     174                 :          0 :                         return -ENOMEM;
     175                 :            :                 }
     176                 :            : 
     177                 :            :                 in_buffer = (uint8_t *)m_data;
     178                 :            :                 /* Input Gather List */
     179                 :            :                 i = 0;
     180                 :            :                 gather_comp = (struct roc_sg2list_comp *)((uint8_t *)in_buffer);
     181                 :          0 :                 i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
     182                 :            : 
     183                 :          0 :                 cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
     184                 :          0 :                 g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
     185                 :            : 
     186                 :            :                 i = 0;
     187                 :          0 :                 scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
     188                 :            : 
     189                 :          0 :                 i = fill_sg2_comp_from_pkt(scatter_comp, i, m_src);
     190                 :            : 
     191                 :          0 :                 cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
     192                 :            : 
     193                 :          0 :                 cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
     194                 :          0 :                 cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
     195                 :            : 
     196                 :          0 :                 inst->w5.u64 = cpt_inst_w5.u64;
     197                 :          0 :                 inst->w6.u64 = cpt_inst_w6.u64;
     198                 :          0 :                 w4.u64 = sess->inst.w4;
     199                 :          0 :                 w4.s.dlen = rte_pktmbuf_pkt_len(m_src);
     200                 :          0 :                 w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
     201                 :          0 :                 w4.s.opcode_minor = sess->tls.enable_padding * cop->aux_flags * 8;
     202                 :          0 :                 w4.s.param1 = w4.s.dlen;
     203                 :          0 :                 w4.s.param2 = cop->param1.tls_record.content_type;
     204                 :            :                 /* Output Scatter List */
     205                 :          0 :                 last_seg->data_len += sess->max_extended_len;
     206                 :          0 :                 inst->w4.u64 = w4.u64;
     207                 :            :         }
     208                 :            : 
     209                 :            :         return 0;
     210                 :            : }
     211                 :            : 
     212                 :            : static __rte_always_inline int
     213                 :            : process_tls_read(struct rte_crypto_op *cop, struct cn10k_sec_session *sess,
     214                 :            :                  struct cpt_qp_meta_info *m_info, struct cpt_inflight_req *infl_req,
     215                 :            :                  struct cpt_inst_s *inst, const bool is_sg_ver2)
     216                 :            : {
     217                 :            :         struct rte_crypto_sym_op *sym_op = cop->sym;
     218                 :          0 :         struct rte_mbuf *m_src = sym_op->m_src;
     219                 :            :         union cpt_inst_w4 w4;
     220                 :            :         uint8_t *in_buffer;
     221                 :            :         void *m_data;
     222                 :            : 
     223         [ #  # ]:          0 :         if (likely(m_src->next == NULL)) {
     224                 :            :                 void *vaddr;
     225                 :            : 
     226                 :          0 :                 vaddr = rte_pktmbuf_mtod(m_src, void *);
     227                 :            : 
     228                 :          0 :                 inst->dptr = (uint64_t)vaddr;
     229                 :          0 :                 inst->rptr = (uint64_t)vaddr;
     230                 :            : 
     231                 :          0 :                 w4.u64 = sess->inst.w4;
     232                 :          0 :                 w4.s.dlen = m_src->data_len;
     233                 :          0 :                 w4.s.param1 = m_src->data_len;
     234                 :          0 :                 inst->w4.u64 = w4.u64;
     235         [ #  # ]:          0 :         } else if (is_sg_ver2 == false) {
     236                 :            :                 struct roc_sglist_comp *scatter_comp, *gather_comp;
     237                 :            :                 uint32_t g_size_bytes, s_size_bytes;
     238                 :            :                 uint32_t dlen;
     239                 :            :                 int i;
     240                 :            : 
     241         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     242         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     243                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     244                 :          0 :                         return -ENOMEM;
     245                 :            :                 }
     246                 :            : 
     247                 :            :                 in_buffer = (uint8_t *)m_data;
     248                 :          0 :                 ((uint16_t *)in_buffer)[0] = 0;
     249                 :          0 :                 ((uint16_t *)in_buffer)[1] = 0;
     250                 :            : 
     251                 :            :                 /* Input Gather List */
     252                 :            :                 i = 0;
     253                 :          0 :                 gather_comp = (struct roc_sglist_comp *)((uint8_t *)in_buffer + 8);
     254                 :            : 
     255                 :          0 :                 i = fill_sg_comp_from_pkt(gather_comp, i, m_src);
     256         [ #  # ]:          0 :                 ((uint16_t *)in_buffer)[2] = rte_cpu_to_be_16(i);
     257                 :            : 
     258                 :          0 :                 g_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     259                 :            : 
     260                 :            :                 i = 0;
     261                 :          0 :                 scatter_comp = (struct roc_sglist_comp *)((uint8_t *)gather_comp + g_size_bytes);
     262                 :            : 
     263                 :          0 :                 i = fill_sg_comp_from_pkt(scatter_comp, i, m_src);
     264         [ #  # ]:          0 :                 ((uint16_t *)in_buffer)[3] = rte_cpu_to_be_16(i);
     265                 :            : 
     266                 :          0 :                 s_size_bytes = ((i + 3) / 4) * sizeof(struct roc_sglist_comp);
     267                 :            : 
     268                 :          0 :                 dlen = g_size_bytes + s_size_bytes + ROC_SG_LIST_HDR_SIZE;
     269                 :            : 
     270                 :          0 :                 inst->dptr = (uint64_t)in_buffer;
     271                 :          0 :                 inst->rptr = (uint64_t)in_buffer;
     272                 :            : 
     273                 :          0 :                 w4.u64 = sess->inst.w4;
     274                 :          0 :                 w4.s.dlen = dlen;
     275                 :          0 :                 w4.s.opcode_major |= (uint64_t)ROC_DMA_MODE_SG;
     276                 :          0 :                 w4.s.param1 = rte_pktmbuf_pkt_len(m_src);
     277                 :          0 :                 inst->w4.u64 = w4.u64;
     278                 :            :         } else {
     279                 :            :                 struct roc_sg2list_comp *scatter_comp, *gather_comp;
     280                 :            :                 union cpt_inst_w5 cpt_inst_w5;
     281                 :            :                 union cpt_inst_w6 cpt_inst_w6;
     282                 :            :                 uint32_t g_size_bytes;
     283                 :            :                 int i;
     284                 :            : 
     285         [ #  # ]:          0 :                 m_data = alloc_op_meta(NULL, m_info->mlen, m_info->pool, infl_req);
     286         [ #  # ]:          0 :                 if (unlikely(m_data == NULL)) {
     287                 :          0 :                         plt_dp_err("Error allocating meta buffer for request");
     288                 :          0 :                         return -ENOMEM;
     289                 :            :                 }
     290                 :            : 
     291                 :            :                 in_buffer = (uint8_t *)m_data;
     292                 :            :                 /* Input Gather List */
     293                 :            :                 i = 0;
     294                 :            : 
     295                 :            :                 gather_comp = (struct roc_sg2list_comp *)((uint8_t *)in_buffer);
     296                 :          0 :                 i = fill_sg2_comp_from_pkt(gather_comp, i, m_src);
     297                 :            : 
     298                 :          0 :                 cpt_inst_w5.s.gather_sz = ((i + 2) / 3);
     299                 :          0 :                 g_size_bytes = ((i + 2) / 3) * sizeof(struct roc_sg2list_comp);
     300                 :            : 
     301                 :            :                 i = 0;
     302                 :          0 :                 scatter_comp = (struct roc_sg2list_comp *)((uint8_t *)gather_comp + g_size_bytes);
     303                 :            : 
     304                 :          0 :                 i = fill_sg2_comp_from_pkt(scatter_comp, i, m_src);
     305                 :            : 
     306                 :          0 :                 cpt_inst_w6.s.scatter_sz = ((i + 2) / 3);
     307                 :            : 
     308                 :          0 :                 cpt_inst_w5.s.dptr = (uint64_t)gather_comp;
     309                 :          0 :                 cpt_inst_w6.s.rptr = (uint64_t)scatter_comp;
     310                 :            : 
     311                 :          0 :                 inst->w5.u64 = cpt_inst_w5.u64;
     312                 :          0 :                 inst->w6.u64 = cpt_inst_w6.u64;
     313                 :          0 :                 w4.u64 = sess->inst.w4;
     314                 :          0 :                 w4.s.dlen = rte_pktmbuf_pkt_len(m_src);
     315                 :          0 :                 w4.s.param1 = w4.s.dlen;
     316                 :          0 :                 w4.s.opcode_major &= (~(ROC_IE_OT_INPLACE_BIT));
     317                 :          0 :                 inst->w4.u64 = w4.u64;
     318                 :            :         }
     319                 :            : 
     320                 :            :         return 0;
     321                 :            : }
     322                 :            : #endif /* __CN10K_TLS_OPS_H__ */

Generated by: LCOV version 1.14