net/octeontx2: support 24B custom L2 header parsing
[dpdk.git] / drivers / common / dpaax / caamflib / desc / algo.h
index 83dbb80..41cac5a 100644 (file)
@@ -1,7 +1,7 @@
 /* SPDX-License-Identifier: (BSD-3-Clause OR GPL-2.0)
  *
  * Copyright 2008-2016 Freescale Semiconductor Inc.
- * Copyright 2016,2019 NXP
+ * Copyright 2016,2019-2020 NXP
  *
  */
 
@@ -289,12 +289,12 @@ cnstr_shdsc_snow_f9(uint32_t *descbuf, bool ps, bool swap,
 static inline int
 cnstr_shdsc_blkcipher(uint32_t *descbuf, bool ps, bool swap,
                      enum rta_share_type share,
-                     struct alginfo *cipherdata, uint8_t *iv,
+                     struct alginfo *cipherdata,
                      uint32_t ivlen, uint8_t dir)
 {
        struct program prg;
        struct program *p = &prg;
-       uint32_t iv_off = 0;
+       uint32_t iv_off = 0, counter;
        const bool need_dk = (dir == DIR_DEC) &&
                             (cipherdata->algtype == OP_ALG_ALGSEL_AES) &&
                             (cipherdata->algmode == OP_ALG_AAI_CBC);
@@ -336,12 +336,17 @@ cnstr_shdsc_blkcipher(uint32_t *descbuf, bool ps, bool swap,
        if (cipherdata->algmode == OP_ALG_AAI_CTR)
                iv_off = 16;
 
-       if (iv)
-               /* IV load, convert size */
-               LOAD(p, (uintptr_t)iv, CONTEXT1, iv_off, ivlen, IMMED | COPY);
-       else
-               /* IV is present first before the actual message */
-               SEQLOAD(p, CONTEXT1, iv_off, ivlen, 0);
+       /* IV is present first before the actual message */
+       SEQLOAD(p, CONTEXT1, iv_off, ivlen, 0);
+
+       /* If IV len is less than 16 bytes, set 'counter' as 1 */
+       if (cipherdata->algmode == OP_ALG_AAI_CTR && ivlen < 16) {
+               counter = 1;
+               if (!swap)
+                       counter = swab32(1);
+
+               LOAD(p, counter, CONTEXT1, (iv_off + ivlen), 16 - ivlen, IMMED);
+       }
 
        MATHB(p, SEQINSZ, SUB, MATH2, VSEQINSZ, 4, 0);
        MATHB(p, SEQINSZ, SUB, MATH2, VSEQOUTSZ, 4, 0);
@@ -461,6 +466,90 @@ cnstr_shdsc_hmac(uint32_t *descbuf, bool ps, bool swap,
        return PROGRAM_FINALIZE(p);
 }
 
+/**
+ * cnstr_shdsc_hash - HASH shared
+ * @descbuf: pointer to descriptor-under-construction buffer
+ * @ps: if 36/40bit addressing is desired, this parameter must be true
+ * @swap: must be true when core endianness doesn't match SEC endianness
+ * @share: sharing type of shared descriptor
+ * @authdata: pointer to authentication transform definitions;
+ *            message digest algorithm: OP_ALG_ALGSEL_MD5/ SHA1-512.
+ * @do_icv: 0 if ICV checking is not desired, any other value if ICV checking
+ *          is needed for all the packets processed by this shared descriptor
+ * @trunc_len: Length of the truncated ICV to be written in the output buffer, 0
+ *             if no truncation is needed
+ *
+ * Note: There's no support for keys longer than the block size of the
+ * underlying hash function, according to the selected algorithm.
+ *
+ * Return: size of descriptor written in words or negative number on error
+ */
+static inline int
+cnstr_shdsc_hash(uint32_t *descbuf, bool ps, bool swap,
+                enum rta_share_type share,
+                struct alginfo *authdata, uint8_t do_icv,
+                uint8_t trunc_len)
+{
+       struct program prg;
+       struct program *p = &prg;
+       uint8_t storelen, opicv, dir;
+
+       /* Compute fixed-size store based on alg selection */
+       switch (authdata->algtype) {
+       case OP_ALG_ALGSEL_MD5:
+               storelen = 16;
+               break;
+       case OP_ALG_ALGSEL_SHA1:
+               storelen = 20;
+               break;
+       case OP_ALG_ALGSEL_SHA224:
+               storelen = 28;
+               break;
+       case OP_ALG_ALGSEL_SHA256:
+               storelen = 32;
+               break;
+       case OP_ALG_ALGSEL_SHA384:
+               storelen = 48;
+               break;
+       case OP_ALG_ALGSEL_SHA512:
+               storelen = 64;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       trunc_len = trunc_len && (trunc_len < storelen) ? trunc_len : storelen;
+
+       opicv = do_icv ? ICV_CHECK_ENABLE : ICV_CHECK_DISABLE;
+       dir = do_icv ? DIR_DEC : DIR_ENC;
+
+       PROGRAM_CNTXT_INIT(p, descbuf, 0);
+       if (swap)
+               PROGRAM_SET_BSWAP(p);
+       if (ps)
+               PROGRAM_SET_36BIT_ADDR(p);
+       SHR_HDR(p, share, 1, SC);
+
+       /* Do operation */
+       /* compute sequences */
+       if (opicv == ICV_CHECK_ENABLE)
+               MATHB(p, SEQINSZ, SUB, trunc_len, VSEQINSZ, 4, IMMED2);
+       else
+               MATHB(p, SEQINSZ, SUB, MATH2, VSEQINSZ, 4, 0);
+
+       ALG_OPERATION(p, authdata->algtype,
+                     OP_ALG_AAI_HASH,
+                     OP_ALG_AS_INITFINAL, opicv, dir);
+       SEQFIFOLOAD(p, MSG2, 0, VLF | LAST2);
+
+       if (opicv == ICV_CHECK_ENABLE)
+               SEQFIFOLOAD(p, ICV2, trunc_len, LAST2);
+       else
+               SEQSTORE(p, CONTEXT2, 0, trunc_len, 0);
+
+       return PROGRAM_FINALIZE(p);
+}
+
 /**
  * cnstr_shdsc_kasumi_f8 - KASUMI F8 (Confidentiality) as a shared descriptor
  *                         (ETSI "Document 1: f8 and f9 specification")