1cb849fc5SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
29d12ba86SRob Rice /*
39d12ba86SRob Rice * Copyright 2016 Broadcom
49d12ba86SRob Rice */
59d12ba86SRob Rice
69d12ba86SRob Rice /*
79d12ba86SRob Rice * This file works with the SPU2 version of the SPU. SPU2 has different message
89d12ba86SRob Rice * formats than the previous version of the SPU. All SPU message format
99d12ba86SRob Rice * differences should be hidden in the spux.c,h files.
109d12ba86SRob Rice */
119d12ba86SRob Rice
129d12ba86SRob Rice #include <linux/kernel.h>
139d12ba86SRob Rice #include <linux/string.h>
149d12ba86SRob Rice
159d12ba86SRob Rice #include "util.h"
169d12ba86SRob Rice #include "spu.h"
179d12ba86SRob Rice #include "spu2.h"
189d12ba86SRob Rice
199d12ba86SRob Rice #define SPU2_TX_STATUS_LEN 0 /* SPU2 has no STATUS in input packet */
209d12ba86SRob Rice
219d12ba86SRob Rice /*
229d12ba86SRob Rice * Controlled by pkt_stat_cnt field in CRYPTO_SS_SPU0_CORE_SPU2_CONTROL0
239d12ba86SRob Rice * register. Defaults to 2.
249d12ba86SRob Rice */
259d12ba86SRob Rice #define SPU2_RX_STATUS_LEN 2
269d12ba86SRob Rice
279d12ba86SRob Rice enum spu2_proto_sel {
289d12ba86SRob Rice SPU2_PROTO_RESV = 0,
299d12ba86SRob Rice SPU2_MACSEC_SECTAG8_ECB = 1,
309d12ba86SRob Rice SPU2_MACSEC_SECTAG8_SCB = 2,
319d12ba86SRob Rice SPU2_MACSEC_SECTAG16 = 3,
329d12ba86SRob Rice SPU2_MACSEC_SECTAG16_8_XPN = 4,
339d12ba86SRob Rice SPU2_IPSEC = 5,
349d12ba86SRob Rice SPU2_IPSEC_ESN = 6,
359d12ba86SRob Rice SPU2_TLS_CIPHER = 7,
369d12ba86SRob Rice SPU2_TLS_AEAD = 8,
379d12ba86SRob Rice SPU2_DTLS_CIPHER = 9,
389d12ba86SRob Rice SPU2_DTLS_AEAD = 10
399d12ba86SRob Rice };
409d12ba86SRob Rice
41dd508618SYueHaibing static char *spu2_cipher_type_names[] = { "None", "AES128", "AES192", "AES256",
429d12ba86SRob Rice "DES", "3DES"
439d12ba86SRob Rice };
449d12ba86SRob Rice
45dd508618SYueHaibing static char *spu2_cipher_mode_names[] = { "ECB", "CBC", "CTR", "CFB", "OFB",
46dd508618SYueHaibing "XTS", "CCM", "GCM"
479d12ba86SRob Rice };
489d12ba86SRob Rice
49dd508618SYueHaibing static char *spu2_hash_type_names[] = { "None", "AES128", "AES192", "AES256",
509d12ba86SRob Rice "Reserved", "Reserved", "MD5", "SHA1", "SHA224", "SHA256", "SHA384",
519d12ba86SRob Rice "SHA512", "SHA512/224", "SHA512/256", "SHA3-224", "SHA3-256",
529d12ba86SRob Rice "SHA3-384", "SHA3-512"
539d12ba86SRob Rice };
549d12ba86SRob Rice
55dd508618SYueHaibing static char *spu2_hash_mode_names[] = { "CMAC", "CBC-MAC", "XCBC-MAC", "HMAC",
569d12ba86SRob Rice "Rabin", "CCM", "GCM", "Reserved"
579d12ba86SRob Rice };
589d12ba86SRob Rice
spu2_ciph_type_name(enum spu2_cipher_type cipher_type)599d12ba86SRob Rice static char *spu2_ciph_type_name(enum spu2_cipher_type cipher_type)
609d12ba86SRob Rice {
619d12ba86SRob Rice if (cipher_type >= SPU2_CIPHER_TYPE_LAST)
629d12ba86SRob Rice return "Reserved";
639d12ba86SRob Rice return spu2_cipher_type_names[cipher_type];
649d12ba86SRob Rice }
659d12ba86SRob Rice
spu2_ciph_mode_name(enum spu2_cipher_mode cipher_mode)669d12ba86SRob Rice static char *spu2_ciph_mode_name(enum spu2_cipher_mode cipher_mode)
679d12ba86SRob Rice {
689d12ba86SRob Rice if (cipher_mode >= SPU2_CIPHER_MODE_LAST)
699d12ba86SRob Rice return "Reserved";
709d12ba86SRob Rice return spu2_cipher_mode_names[cipher_mode];
719d12ba86SRob Rice }
729d12ba86SRob Rice
spu2_hash_type_name(enum spu2_hash_type hash_type)739d12ba86SRob Rice static char *spu2_hash_type_name(enum spu2_hash_type hash_type)
749d12ba86SRob Rice {
759d12ba86SRob Rice if (hash_type >= SPU2_HASH_TYPE_LAST)
769d12ba86SRob Rice return "Reserved";
779d12ba86SRob Rice return spu2_hash_type_names[hash_type];
789d12ba86SRob Rice }
799d12ba86SRob Rice
spu2_hash_mode_name(enum spu2_hash_mode hash_mode)809d12ba86SRob Rice static char *spu2_hash_mode_name(enum spu2_hash_mode hash_mode)
819d12ba86SRob Rice {
829d12ba86SRob Rice if (hash_mode >= SPU2_HASH_MODE_LAST)
839d12ba86SRob Rice return "Reserved";
849d12ba86SRob Rice return spu2_hash_mode_names[hash_mode];
859d12ba86SRob Rice }
869d12ba86SRob Rice
879d12ba86SRob Rice /*
889d12ba86SRob Rice * Convert from a software cipher mode value to the corresponding value
899d12ba86SRob Rice * for SPU2.
909d12ba86SRob Rice */
spu2_cipher_mode_xlate(enum spu_cipher_mode cipher_mode,enum spu2_cipher_mode * spu2_mode)919d12ba86SRob Rice static int spu2_cipher_mode_xlate(enum spu_cipher_mode cipher_mode,
929d12ba86SRob Rice enum spu2_cipher_mode *spu2_mode)
939d12ba86SRob Rice {
949d12ba86SRob Rice switch (cipher_mode) {
959d12ba86SRob Rice case CIPHER_MODE_ECB:
969d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_ECB;
979d12ba86SRob Rice break;
989d12ba86SRob Rice case CIPHER_MODE_CBC:
999d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_CBC;
1009d12ba86SRob Rice break;
1019d12ba86SRob Rice case CIPHER_MODE_OFB:
1029d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_OFB;
1039d12ba86SRob Rice break;
1049d12ba86SRob Rice case CIPHER_MODE_CFB:
1059d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_CFB;
1069d12ba86SRob Rice break;
1079d12ba86SRob Rice case CIPHER_MODE_CTR:
1089d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_CTR;
1099d12ba86SRob Rice break;
1109d12ba86SRob Rice case CIPHER_MODE_CCM:
1119d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_CCM;
1129d12ba86SRob Rice break;
1139d12ba86SRob Rice case CIPHER_MODE_GCM:
1149d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_GCM;
1159d12ba86SRob Rice break;
1169d12ba86SRob Rice case CIPHER_MODE_XTS:
1179d12ba86SRob Rice *spu2_mode = SPU2_CIPHER_MODE_XTS;
1189d12ba86SRob Rice break;
1199d12ba86SRob Rice default:
1209d12ba86SRob Rice return -EINVAL;
1219d12ba86SRob Rice }
1229d12ba86SRob Rice return 0;
1239d12ba86SRob Rice }
1249d12ba86SRob Rice
1259d12ba86SRob Rice /**
1269d12ba86SRob Rice * spu2_cipher_xlate() - Convert a cipher {alg/mode/type} triple to a SPU2
1279d12ba86SRob Rice * cipher type and mode.
1289d12ba86SRob Rice * @cipher_alg: [in] cipher algorithm value from software enumeration
1299d12ba86SRob Rice * @cipher_mode: [in] cipher mode value from software enumeration
1309d12ba86SRob Rice * @cipher_type: [in] cipher type value from software enumeration
1319d12ba86SRob Rice * @spu2_type: [out] cipher type value used by spu2 hardware
1329d12ba86SRob Rice * @spu2_mode: [out] cipher mode value used by spu2 hardware
1339d12ba86SRob Rice *
1349d12ba86SRob Rice * Return: 0 if successful
1359d12ba86SRob Rice */
spu2_cipher_xlate(enum spu_cipher_alg cipher_alg,enum spu_cipher_mode cipher_mode,enum spu_cipher_type cipher_type,enum spu2_cipher_type * spu2_type,enum spu2_cipher_mode * spu2_mode)1369d12ba86SRob Rice static int spu2_cipher_xlate(enum spu_cipher_alg cipher_alg,
1379d12ba86SRob Rice enum spu_cipher_mode cipher_mode,
1389d12ba86SRob Rice enum spu_cipher_type cipher_type,
1399d12ba86SRob Rice enum spu2_cipher_type *spu2_type,
1409d12ba86SRob Rice enum spu2_cipher_mode *spu2_mode)
1419d12ba86SRob Rice {
1429d12ba86SRob Rice int err;
1439d12ba86SRob Rice
1449d12ba86SRob Rice err = spu2_cipher_mode_xlate(cipher_mode, spu2_mode);
1459d12ba86SRob Rice if (err) {
1469d12ba86SRob Rice flow_log("Invalid cipher mode %d\n", cipher_mode);
1479d12ba86SRob Rice return err;
1489d12ba86SRob Rice }
1499d12ba86SRob Rice
1509d12ba86SRob Rice switch (cipher_alg) {
1519d12ba86SRob Rice case CIPHER_ALG_NONE:
1529d12ba86SRob Rice *spu2_type = SPU2_CIPHER_TYPE_NONE;
1539d12ba86SRob Rice break;
1549d12ba86SRob Rice case CIPHER_ALG_RC4:
1559d12ba86SRob Rice /* SPU2 does not support RC4 */
1569d12ba86SRob Rice err = -EINVAL;
1579d12ba86SRob Rice *spu2_type = SPU2_CIPHER_TYPE_NONE;
1589d12ba86SRob Rice break;
1599d12ba86SRob Rice case CIPHER_ALG_DES:
1609d12ba86SRob Rice *spu2_type = SPU2_CIPHER_TYPE_DES;
1619d12ba86SRob Rice break;
1629d12ba86SRob Rice case CIPHER_ALG_3DES:
1639d12ba86SRob Rice *spu2_type = SPU2_CIPHER_TYPE_3DES;
1649d12ba86SRob Rice break;
1659d12ba86SRob Rice case CIPHER_ALG_AES:
1669d12ba86SRob Rice switch (cipher_type) {
1679d12ba86SRob Rice case CIPHER_TYPE_AES128:
1689d12ba86SRob Rice *spu2_type = SPU2_CIPHER_TYPE_AES128;
1699d12ba86SRob Rice break;
1709d12ba86SRob Rice case CIPHER_TYPE_AES192:
1719d12ba86SRob Rice *spu2_type = SPU2_CIPHER_TYPE_AES192;
1729d12ba86SRob Rice break;
1739d12ba86SRob Rice case CIPHER_TYPE_AES256:
1749d12ba86SRob Rice *spu2_type = SPU2_CIPHER_TYPE_AES256;
1759d12ba86SRob Rice break;
1769d12ba86SRob Rice default:
1779d12ba86SRob Rice err = -EINVAL;
1789d12ba86SRob Rice }
1799d12ba86SRob Rice break;
1809d12ba86SRob Rice case CIPHER_ALG_LAST:
1819d12ba86SRob Rice default:
1829d12ba86SRob Rice err = -EINVAL;
1839d12ba86SRob Rice break;
1849d12ba86SRob Rice }
1859d12ba86SRob Rice
1869d12ba86SRob Rice if (err)
1879d12ba86SRob Rice flow_log("Invalid cipher alg %d or type %d\n",
1889d12ba86SRob Rice cipher_alg, cipher_type);
1899d12ba86SRob Rice return err;
1909d12ba86SRob Rice }
1919d12ba86SRob Rice
1929d12ba86SRob Rice /*
1939d12ba86SRob Rice * Convert from a software hash mode value to the corresponding value
1949d12ba86SRob Rice * for SPU2. Note that HASH_MODE_NONE and HASH_MODE_XCBC have the same value.
1959d12ba86SRob Rice */
spu2_hash_mode_xlate(enum hash_mode hash_mode,enum spu2_hash_mode * spu2_mode)1969d12ba86SRob Rice static int spu2_hash_mode_xlate(enum hash_mode hash_mode,
1979d12ba86SRob Rice enum spu2_hash_mode *spu2_mode)
1989d12ba86SRob Rice {
1999d12ba86SRob Rice switch (hash_mode) {
2009d12ba86SRob Rice case HASH_MODE_XCBC:
2019d12ba86SRob Rice *spu2_mode = SPU2_HASH_MODE_XCBC_MAC;
2029d12ba86SRob Rice break;
2039d12ba86SRob Rice case HASH_MODE_CMAC:
2049d12ba86SRob Rice *spu2_mode = SPU2_HASH_MODE_CMAC;
2059d12ba86SRob Rice break;
2069d12ba86SRob Rice case HASH_MODE_HMAC:
2079d12ba86SRob Rice *spu2_mode = SPU2_HASH_MODE_HMAC;
2089d12ba86SRob Rice break;
2099d12ba86SRob Rice case HASH_MODE_CCM:
2109d12ba86SRob Rice *spu2_mode = SPU2_HASH_MODE_CCM;
2119d12ba86SRob Rice break;
2129d12ba86SRob Rice case HASH_MODE_GCM:
2139d12ba86SRob Rice *spu2_mode = SPU2_HASH_MODE_GCM;
2149d12ba86SRob Rice break;
2159d12ba86SRob Rice default:
2169d12ba86SRob Rice return -EINVAL;
2179d12ba86SRob Rice }
2189d12ba86SRob Rice return 0;
2199d12ba86SRob Rice }
2209d12ba86SRob Rice
2219d12ba86SRob Rice /**
2229d12ba86SRob Rice * spu2_hash_xlate() - Convert a hash {alg/mode/type} triple to a SPU2 hash type
2239d12ba86SRob Rice * and mode.
2249d12ba86SRob Rice * @hash_alg: [in] hash algorithm value from software enumeration
2259d12ba86SRob Rice * @hash_mode: [in] hash mode value from software enumeration
2269d12ba86SRob Rice * @hash_type: [in] hash type value from software enumeration
2279d12ba86SRob Rice * @ciph_type: [in] cipher type value from software enumeration
2289d12ba86SRob Rice * @spu2_type: [out] hash type value used by SPU2 hardware
2299d12ba86SRob Rice * @spu2_mode: [out] hash mode value used by SPU2 hardware
2309d12ba86SRob Rice *
2319d12ba86SRob Rice * Return: 0 if successful
2329d12ba86SRob Rice */
2339d12ba86SRob Rice static int
spu2_hash_xlate(enum hash_alg hash_alg,enum hash_mode hash_mode,enum hash_type hash_type,enum spu_cipher_type ciph_type,enum spu2_hash_type * spu2_type,enum spu2_hash_mode * spu2_mode)2349d12ba86SRob Rice spu2_hash_xlate(enum hash_alg hash_alg, enum hash_mode hash_mode,
2359d12ba86SRob Rice enum hash_type hash_type, enum spu_cipher_type ciph_type,
2369d12ba86SRob Rice enum spu2_hash_type *spu2_type, enum spu2_hash_mode *spu2_mode)
2379d12ba86SRob Rice {
2389d12ba86SRob Rice int err;
2399d12ba86SRob Rice
2409d12ba86SRob Rice err = spu2_hash_mode_xlate(hash_mode, spu2_mode);
2419d12ba86SRob Rice if (err) {
2429d12ba86SRob Rice flow_log("Invalid hash mode %d\n", hash_mode);
2439d12ba86SRob Rice return err;
2449d12ba86SRob Rice }
2459d12ba86SRob Rice
2469d12ba86SRob Rice switch (hash_alg) {
2479d12ba86SRob Rice case HASH_ALG_NONE:
2489d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_NONE;
2499d12ba86SRob Rice break;
2509d12ba86SRob Rice case HASH_ALG_MD5:
2519d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_MD5;
2529d12ba86SRob Rice break;
2539d12ba86SRob Rice case HASH_ALG_SHA1:
2549d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA1;
2559d12ba86SRob Rice break;
2569d12ba86SRob Rice case HASH_ALG_SHA224:
2579d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA224;
2589d12ba86SRob Rice break;
2599d12ba86SRob Rice case HASH_ALG_SHA256:
2609d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA256;
2619d12ba86SRob Rice break;
2629d12ba86SRob Rice case HASH_ALG_SHA384:
2639d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA384;
2649d12ba86SRob Rice break;
2659d12ba86SRob Rice case HASH_ALG_SHA512:
2669d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA512;
2679d12ba86SRob Rice break;
2689d12ba86SRob Rice case HASH_ALG_AES:
2699d12ba86SRob Rice switch (ciph_type) {
2709d12ba86SRob Rice case CIPHER_TYPE_AES128:
2719d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_AES128;
2729d12ba86SRob Rice break;
2739d12ba86SRob Rice case CIPHER_TYPE_AES192:
2749d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_AES192;
2759d12ba86SRob Rice break;
2769d12ba86SRob Rice case CIPHER_TYPE_AES256:
2779d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_AES256;
2789d12ba86SRob Rice break;
2799d12ba86SRob Rice default:
2809d12ba86SRob Rice err = -EINVAL;
2819d12ba86SRob Rice }
2829d12ba86SRob Rice break;
2839d12ba86SRob Rice case HASH_ALG_SHA3_224:
2849d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA3_224;
2859d12ba86SRob Rice break;
2869d12ba86SRob Rice case HASH_ALG_SHA3_256:
2879d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA3_256;
2889d12ba86SRob Rice break;
2899d12ba86SRob Rice case HASH_ALG_SHA3_384:
2909d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA3_384;
2919d12ba86SRob Rice break;
2929d12ba86SRob Rice case HASH_ALG_SHA3_512:
2939d12ba86SRob Rice *spu2_type = SPU2_HASH_TYPE_SHA3_512;
294a7e6e5d8Sraveendra padasalagi break;
2959d12ba86SRob Rice case HASH_ALG_LAST:
2969d12ba86SRob Rice default:
2979d12ba86SRob Rice err = -EINVAL;
2989d12ba86SRob Rice break;
2999d12ba86SRob Rice }
3009d12ba86SRob Rice
3019d12ba86SRob Rice if (err)
3029d12ba86SRob Rice flow_log("Invalid hash alg %d or type %d\n",
3039d12ba86SRob Rice hash_alg, hash_type);
3049d12ba86SRob Rice return err;
3059d12ba86SRob Rice }
3069d12ba86SRob Rice
3079d12ba86SRob Rice /* Dump FMD ctrl0. The ctrl0 input is in host byte order */
spu2_dump_fmd_ctrl0(u64 ctrl0)3089d12ba86SRob Rice static void spu2_dump_fmd_ctrl0(u64 ctrl0)
3099d12ba86SRob Rice {
3109d12ba86SRob Rice enum spu2_cipher_type ciph_type;
3119d12ba86SRob Rice enum spu2_cipher_mode ciph_mode;
3129d12ba86SRob Rice enum spu2_hash_type hash_type;
3139d12ba86SRob Rice enum spu2_hash_mode hash_mode;
3149d12ba86SRob Rice char *ciph_name;
3159d12ba86SRob Rice char *ciph_mode_name;
3169d12ba86SRob Rice char *hash_name;
3179d12ba86SRob Rice char *hash_mode_name;
3189d12ba86SRob Rice u8 cfb;
3199d12ba86SRob Rice u8 proto;
3209d12ba86SRob Rice
3219d12ba86SRob Rice packet_log(" FMD CTRL0 %#16llx\n", ctrl0);
3229d12ba86SRob Rice if (ctrl0 & SPU2_CIPH_ENCRYPT_EN)
3239d12ba86SRob Rice packet_log(" encrypt\n");
3249d12ba86SRob Rice else
3259d12ba86SRob Rice packet_log(" decrypt\n");
3269d12ba86SRob Rice
3279d12ba86SRob Rice ciph_type = (ctrl0 & SPU2_CIPH_TYPE) >> SPU2_CIPH_TYPE_SHIFT;
3289d12ba86SRob Rice ciph_name = spu2_ciph_type_name(ciph_type);
3299d12ba86SRob Rice packet_log(" Cipher type: %s\n", ciph_name);
3309d12ba86SRob Rice
3319d12ba86SRob Rice if (ciph_type != SPU2_CIPHER_TYPE_NONE) {
3329d12ba86SRob Rice ciph_mode = (ctrl0 & SPU2_CIPH_MODE) >> SPU2_CIPH_MODE_SHIFT;
3339d12ba86SRob Rice ciph_mode_name = spu2_ciph_mode_name(ciph_mode);
3349d12ba86SRob Rice packet_log(" Cipher mode: %s\n", ciph_mode_name);
3359d12ba86SRob Rice }
3369d12ba86SRob Rice
3379d12ba86SRob Rice cfb = (ctrl0 & SPU2_CFB_MASK) >> SPU2_CFB_MASK_SHIFT;
3389d12ba86SRob Rice packet_log(" CFB %#x\n", cfb);
3399d12ba86SRob Rice
3409d12ba86SRob Rice proto = (ctrl0 & SPU2_PROTO_SEL) >> SPU2_PROTO_SEL_SHIFT;
3419d12ba86SRob Rice packet_log(" protocol %#x\n", proto);
3429d12ba86SRob Rice
3439d12ba86SRob Rice if (ctrl0 & SPU2_HASH_FIRST)
3449d12ba86SRob Rice packet_log(" hash first\n");
3459d12ba86SRob Rice else
3469d12ba86SRob Rice packet_log(" cipher first\n");
3479d12ba86SRob Rice
3489d12ba86SRob Rice if (ctrl0 & SPU2_CHK_TAG)
3499d12ba86SRob Rice packet_log(" check tag\n");
3509d12ba86SRob Rice
3519d12ba86SRob Rice hash_type = (ctrl0 & SPU2_HASH_TYPE) >> SPU2_HASH_TYPE_SHIFT;
3529d12ba86SRob Rice hash_name = spu2_hash_type_name(hash_type);
3539d12ba86SRob Rice packet_log(" Hash type: %s\n", hash_name);
3549d12ba86SRob Rice
3559d12ba86SRob Rice if (hash_type != SPU2_HASH_TYPE_NONE) {
3569d12ba86SRob Rice hash_mode = (ctrl0 & SPU2_HASH_MODE) >> SPU2_HASH_MODE_SHIFT;
3579d12ba86SRob Rice hash_mode_name = spu2_hash_mode_name(hash_mode);
3589d12ba86SRob Rice packet_log(" Hash mode: %s\n", hash_mode_name);
3599d12ba86SRob Rice }
3609d12ba86SRob Rice
3619d12ba86SRob Rice if (ctrl0 & SPU2_CIPH_PAD_EN) {
3629d12ba86SRob Rice packet_log(" Cipher pad: %#2llx\n",
3639d12ba86SRob Rice (ctrl0 & SPU2_CIPH_PAD) >> SPU2_CIPH_PAD_SHIFT);
3649d12ba86SRob Rice }
3659d12ba86SRob Rice }
3669d12ba86SRob Rice
3679d12ba86SRob Rice /* Dump FMD ctrl1. The ctrl1 input is in host byte order */
spu2_dump_fmd_ctrl1(u64 ctrl1)3689d12ba86SRob Rice static void spu2_dump_fmd_ctrl1(u64 ctrl1)
3699d12ba86SRob Rice {
3709d12ba86SRob Rice u8 hash_key_len;
3719d12ba86SRob Rice u8 ciph_key_len;
3729d12ba86SRob Rice u8 ret_iv_len;
3739d12ba86SRob Rice u8 iv_offset;
3749d12ba86SRob Rice u8 iv_len;
3759d12ba86SRob Rice u8 hash_tag_len;
3769d12ba86SRob Rice u8 ret_md;
3779d12ba86SRob Rice
3789d12ba86SRob Rice packet_log(" FMD CTRL1 %#16llx\n", ctrl1);
3799d12ba86SRob Rice if (ctrl1 & SPU2_TAG_LOC)
3809d12ba86SRob Rice packet_log(" Tag after payload\n");
3819d12ba86SRob Rice
3829d12ba86SRob Rice packet_log(" Msg includes ");
3839d12ba86SRob Rice if (ctrl1 & SPU2_HAS_FR_DATA)
3849d12ba86SRob Rice packet_log("FD ");
3859d12ba86SRob Rice if (ctrl1 & SPU2_HAS_AAD1)
3869d12ba86SRob Rice packet_log("AAD1 ");
3879d12ba86SRob Rice if (ctrl1 & SPU2_HAS_NAAD)
3889d12ba86SRob Rice packet_log("NAAD ");
3899d12ba86SRob Rice if (ctrl1 & SPU2_HAS_AAD2)
3909d12ba86SRob Rice packet_log("AAD2 ");
3919d12ba86SRob Rice if (ctrl1 & SPU2_HAS_ESN)
3929d12ba86SRob Rice packet_log("ESN ");
3939d12ba86SRob Rice packet_log("\n");
3949d12ba86SRob Rice
3959d12ba86SRob Rice hash_key_len = (ctrl1 & SPU2_HASH_KEY_LEN) >> SPU2_HASH_KEY_LEN_SHIFT;
3969d12ba86SRob Rice packet_log(" Hash key len %u\n", hash_key_len);
3979d12ba86SRob Rice
3989d12ba86SRob Rice ciph_key_len = (ctrl1 & SPU2_CIPH_KEY_LEN) >> SPU2_CIPH_KEY_LEN_SHIFT;
3999d12ba86SRob Rice packet_log(" Cipher key len %u\n", ciph_key_len);
4009d12ba86SRob Rice
4019d12ba86SRob Rice if (ctrl1 & SPU2_GENIV)
4029d12ba86SRob Rice packet_log(" Generate IV\n");
4039d12ba86SRob Rice
4049d12ba86SRob Rice if (ctrl1 & SPU2_HASH_IV)
4059d12ba86SRob Rice packet_log(" IV included in hash\n");
4069d12ba86SRob Rice
4079d12ba86SRob Rice if (ctrl1 & SPU2_RET_IV)
4089d12ba86SRob Rice packet_log(" Return IV in output before payload\n");
4099d12ba86SRob Rice
4109d12ba86SRob Rice ret_iv_len = (ctrl1 & SPU2_RET_IV_LEN) >> SPU2_RET_IV_LEN_SHIFT;
4119d12ba86SRob Rice packet_log(" Length of returned IV %u bytes\n",
4129d12ba86SRob Rice ret_iv_len ? ret_iv_len : 16);
4139d12ba86SRob Rice
4149d12ba86SRob Rice iv_offset = (ctrl1 & SPU2_IV_OFFSET) >> SPU2_IV_OFFSET_SHIFT;
4159d12ba86SRob Rice packet_log(" IV offset %u\n", iv_offset);
4169d12ba86SRob Rice
4179d12ba86SRob Rice iv_len = (ctrl1 & SPU2_IV_LEN) >> SPU2_IV_LEN_SHIFT;
4189d12ba86SRob Rice packet_log(" Input IV len %u bytes\n", iv_len);
4199d12ba86SRob Rice
4209d12ba86SRob Rice hash_tag_len = (ctrl1 & SPU2_HASH_TAG_LEN) >> SPU2_HASH_TAG_LEN_SHIFT;
4219d12ba86SRob Rice packet_log(" Hash tag length %u bytes\n", hash_tag_len);
4229d12ba86SRob Rice
4239d12ba86SRob Rice packet_log(" Return ");
4249d12ba86SRob Rice ret_md = (ctrl1 & SPU2_RETURN_MD) >> SPU2_RETURN_MD_SHIFT;
4259d12ba86SRob Rice if (ret_md)
4269d12ba86SRob Rice packet_log("FMD ");
4279d12ba86SRob Rice if (ret_md == SPU2_RET_FMD_OMD)
4289d12ba86SRob Rice packet_log("OMD ");
4299d12ba86SRob Rice else if (ret_md == SPU2_RET_FMD_OMD_IV)
4309d12ba86SRob Rice packet_log("OMD IV ");
4319d12ba86SRob Rice if (ctrl1 & SPU2_RETURN_FD)
4329d12ba86SRob Rice packet_log("FD ");
4339d12ba86SRob Rice if (ctrl1 & SPU2_RETURN_AAD1)
4349d12ba86SRob Rice packet_log("AAD1 ");
4359d12ba86SRob Rice if (ctrl1 & SPU2_RETURN_NAAD)
4369d12ba86SRob Rice packet_log("NAAD ");
4379d12ba86SRob Rice if (ctrl1 & SPU2_RETURN_AAD2)
4389d12ba86SRob Rice packet_log("AAD2 ");
4399d12ba86SRob Rice if (ctrl1 & SPU2_RETURN_PAY)
4409d12ba86SRob Rice packet_log("Payload");
4419d12ba86SRob Rice packet_log("\n");
4429d12ba86SRob Rice }
4439d12ba86SRob Rice
4449d12ba86SRob Rice /* Dump FMD ctrl2. The ctrl2 input is in host byte order */
spu2_dump_fmd_ctrl2(u64 ctrl2)4459d12ba86SRob Rice static void spu2_dump_fmd_ctrl2(u64 ctrl2)
4469d12ba86SRob Rice {
4479d12ba86SRob Rice packet_log(" FMD CTRL2 %#16llx\n", ctrl2);
4489d12ba86SRob Rice
4499d12ba86SRob Rice packet_log(" AAD1 offset %llu length %llu bytes\n",
4509d12ba86SRob Rice ctrl2 & SPU2_AAD1_OFFSET,
4519d12ba86SRob Rice (ctrl2 & SPU2_AAD1_LEN) >> SPU2_AAD1_LEN_SHIFT);
4529d12ba86SRob Rice packet_log(" AAD2 offset %llu\n",
4539d12ba86SRob Rice (ctrl2 & SPU2_AAD2_OFFSET) >> SPU2_AAD2_OFFSET_SHIFT);
4549d12ba86SRob Rice packet_log(" Payload offset %llu\n",
4559d12ba86SRob Rice (ctrl2 & SPU2_PL_OFFSET) >> SPU2_PL_OFFSET_SHIFT);
4569d12ba86SRob Rice }
4579d12ba86SRob Rice
4589d12ba86SRob Rice /* Dump FMD ctrl3. The ctrl3 input is in host byte order */
spu2_dump_fmd_ctrl3(u64 ctrl3)4599d12ba86SRob Rice static void spu2_dump_fmd_ctrl3(u64 ctrl3)
4609d12ba86SRob Rice {
4619d12ba86SRob Rice packet_log(" FMD CTRL3 %#16llx\n", ctrl3);
4629d12ba86SRob Rice
4639d12ba86SRob Rice packet_log(" Payload length %llu bytes\n", ctrl3 & SPU2_PL_LEN);
4649d12ba86SRob Rice packet_log(" TLS length %llu bytes\n",
4659d12ba86SRob Rice (ctrl3 & SPU2_TLS_LEN) >> SPU2_TLS_LEN_SHIFT);
4669d12ba86SRob Rice }
4679d12ba86SRob Rice
spu2_dump_fmd(struct SPU2_FMD * fmd)4689d12ba86SRob Rice static void spu2_dump_fmd(struct SPU2_FMD *fmd)
4699d12ba86SRob Rice {
4709d12ba86SRob Rice spu2_dump_fmd_ctrl0(le64_to_cpu(fmd->ctrl0));
4719d12ba86SRob Rice spu2_dump_fmd_ctrl1(le64_to_cpu(fmd->ctrl1));
4729d12ba86SRob Rice spu2_dump_fmd_ctrl2(le64_to_cpu(fmd->ctrl2));
4739d12ba86SRob Rice spu2_dump_fmd_ctrl3(le64_to_cpu(fmd->ctrl3));
4749d12ba86SRob Rice }
4759d12ba86SRob Rice
spu2_dump_omd(u8 * omd,u16 hash_key_len,u16 ciph_key_len,u16 hash_iv_len,u16 ciph_iv_len)4769d12ba86SRob Rice static void spu2_dump_omd(u8 *omd, u16 hash_key_len, u16 ciph_key_len,
4779d12ba86SRob Rice u16 hash_iv_len, u16 ciph_iv_len)
4789d12ba86SRob Rice {
4799d12ba86SRob Rice u8 *ptr = omd;
4809d12ba86SRob Rice
4819d12ba86SRob Rice packet_log(" OMD:\n");
4829d12ba86SRob Rice
4839d12ba86SRob Rice if (hash_key_len) {
4849d12ba86SRob Rice packet_log(" Hash Key Length %u bytes\n", hash_key_len);
4859d12ba86SRob Rice packet_dump(" KEY: ", ptr, hash_key_len);
4869d12ba86SRob Rice ptr += hash_key_len;
4879d12ba86SRob Rice }
4889d12ba86SRob Rice
4899d12ba86SRob Rice if (ciph_key_len) {
4909d12ba86SRob Rice packet_log(" Cipher Key Length %u bytes\n", ciph_key_len);
4919d12ba86SRob Rice packet_dump(" KEY: ", ptr, ciph_key_len);
4929d12ba86SRob Rice ptr += ciph_key_len;
4939d12ba86SRob Rice }
4949d12ba86SRob Rice
4959d12ba86SRob Rice if (hash_iv_len) {
4969d12ba86SRob Rice packet_log(" Hash IV Length %u bytes\n", hash_iv_len);
4979d12ba86SRob Rice packet_dump(" hash IV: ", ptr, hash_iv_len);
498*d0f14ae2SAleksandr Mishin ptr += hash_iv_len;
4999d12ba86SRob Rice }
5009d12ba86SRob Rice
5019d12ba86SRob Rice if (ciph_iv_len) {
5029d12ba86SRob Rice packet_log(" Cipher IV Length %u bytes\n", ciph_iv_len);
5039d12ba86SRob Rice packet_dump(" cipher IV: ", ptr, ciph_iv_len);
5049d12ba86SRob Rice }
5059d12ba86SRob Rice }
5069d12ba86SRob Rice
5079d12ba86SRob Rice /* Dump a SPU2 header for debug */
spu2_dump_msg_hdr(u8 * buf,unsigned int buf_len)5089d12ba86SRob Rice void spu2_dump_msg_hdr(u8 *buf, unsigned int buf_len)
5099d12ba86SRob Rice {
5109d12ba86SRob Rice struct SPU2_FMD *fmd = (struct SPU2_FMD *)buf;
5119d12ba86SRob Rice u8 *omd;
5129d12ba86SRob Rice u64 ctrl1;
5139d12ba86SRob Rice u16 hash_key_len;
5149d12ba86SRob Rice u16 ciph_key_len;
5159d12ba86SRob Rice u16 hash_iv_len;
5169d12ba86SRob Rice u16 ciph_iv_len;
5179d12ba86SRob Rice u16 omd_len;
5189d12ba86SRob Rice
5199d12ba86SRob Rice packet_log("\n");
5209d12ba86SRob Rice packet_log("SPU2 message header %p len: %u\n", buf, buf_len);
5219d12ba86SRob Rice
5229d12ba86SRob Rice spu2_dump_fmd(fmd);
5239d12ba86SRob Rice omd = (u8 *)(fmd + 1);
5249d12ba86SRob Rice
5259d12ba86SRob Rice ctrl1 = le64_to_cpu(fmd->ctrl1);
5269d12ba86SRob Rice hash_key_len = (ctrl1 & SPU2_HASH_KEY_LEN) >> SPU2_HASH_KEY_LEN_SHIFT;
5279d12ba86SRob Rice ciph_key_len = (ctrl1 & SPU2_CIPH_KEY_LEN) >> SPU2_CIPH_KEY_LEN_SHIFT;
5289d12ba86SRob Rice hash_iv_len = 0;
5299d12ba86SRob Rice ciph_iv_len = (ctrl1 & SPU2_IV_LEN) >> SPU2_IV_LEN_SHIFT;
5309d12ba86SRob Rice spu2_dump_omd(omd, hash_key_len, ciph_key_len, hash_iv_len,
5319d12ba86SRob Rice ciph_iv_len);
5329d12ba86SRob Rice
5339d12ba86SRob Rice /* Double check sanity */
5349d12ba86SRob Rice omd_len = hash_key_len + ciph_key_len + hash_iv_len + ciph_iv_len;
5359d12ba86SRob Rice if (FMD_SIZE + omd_len != buf_len) {
5369d12ba86SRob Rice packet_log
5379d12ba86SRob Rice (" Packet parsed incorrectly. buf_len %u, sum of MD %zu\n",
5389d12ba86SRob Rice buf_len, FMD_SIZE + omd_len);
5399d12ba86SRob Rice }
5409d12ba86SRob Rice packet_log("\n");
5419d12ba86SRob Rice }
5429d12ba86SRob Rice
5439d12ba86SRob Rice /**
5449d12ba86SRob Rice * spu2_fmd_init() - At setkey time, initialize the fixed meta data for
545a9c01cd6SArd Biesheuvel * subsequent skcipher requests for this context.
54685a557cbSLee Jones * @fmd: Start of FMD field to be written
54785a557cbSLee Jones * @spu2_type: Cipher algorithm
5489d12ba86SRob Rice * @spu2_mode: Cipher mode
5499d12ba86SRob Rice * @cipher_key_len: Length of cipher key, in bytes
5509d12ba86SRob Rice * @cipher_iv_len: Length of cipher initialization vector, in bytes
5519d12ba86SRob Rice *
5529d12ba86SRob Rice * Return: 0 (success)
5539d12ba86SRob Rice */
spu2_fmd_init(struct SPU2_FMD * fmd,enum spu2_cipher_type spu2_type,enum spu2_cipher_mode spu2_mode,u32 cipher_key_len,u32 cipher_iv_len)5549d12ba86SRob Rice static int spu2_fmd_init(struct SPU2_FMD *fmd,
5559d12ba86SRob Rice enum spu2_cipher_type spu2_type,
5569d12ba86SRob Rice enum spu2_cipher_mode spu2_mode,
5579d12ba86SRob Rice u32 cipher_key_len, u32 cipher_iv_len)
5589d12ba86SRob Rice {
5599d12ba86SRob Rice u64 ctrl0;
5609d12ba86SRob Rice u64 ctrl1;
5619d12ba86SRob Rice u64 ctrl2;
5629d12ba86SRob Rice u64 ctrl3;
5639d12ba86SRob Rice u32 aad1_offset;
5649d12ba86SRob Rice u32 aad2_offset;
5659d12ba86SRob Rice u16 aad1_len = 0;
5669d12ba86SRob Rice u64 payload_offset;
5679d12ba86SRob Rice
5689d12ba86SRob Rice ctrl0 = (spu2_type << SPU2_CIPH_TYPE_SHIFT) |
5699d12ba86SRob Rice (spu2_mode << SPU2_CIPH_MODE_SHIFT);
5709d12ba86SRob Rice
5719d12ba86SRob Rice ctrl1 = (cipher_key_len << SPU2_CIPH_KEY_LEN_SHIFT) |
5729d12ba86SRob Rice ((u64)cipher_iv_len << SPU2_IV_LEN_SHIFT) |
5739d12ba86SRob Rice ((u64)SPU2_RET_FMD_ONLY << SPU2_RETURN_MD_SHIFT) | SPU2_RETURN_PAY;
5749d12ba86SRob Rice
5759d12ba86SRob Rice /*
5769d12ba86SRob Rice * AAD1 offset is from start of FD. FD length is always 0 for this
5779d12ba86SRob Rice * driver. So AAD1_offset is always 0.
5789d12ba86SRob Rice */
5799d12ba86SRob Rice aad1_offset = 0;
5809d12ba86SRob Rice aad2_offset = aad1_offset;
5819d12ba86SRob Rice payload_offset = 0;
5829d12ba86SRob Rice ctrl2 = aad1_offset |
5839d12ba86SRob Rice (aad1_len << SPU2_AAD1_LEN_SHIFT) |
5849d12ba86SRob Rice (aad2_offset << SPU2_AAD2_OFFSET_SHIFT) |
5859d12ba86SRob Rice (payload_offset << SPU2_PL_OFFSET_SHIFT);
5869d12ba86SRob Rice
5879d12ba86SRob Rice ctrl3 = 0;
5889d12ba86SRob Rice
5899d12ba86SRob Rice fmd->ctrl0 = cpu_to_le64(ctrl0);
5909d12ba86SRob Rice fmd->ctrl1 = cpu_to_le64(ctrl1);
5919d12ba86SRob Rice fmd->ctrl2 = cpu_to_le64(ctrl2);
5929d12ba86SRob Rice fmd->ctrl3 = cpu_to_le64(ctrl3);
5939d12ba86SRob Rice
5949d12ba86SRob Rice return 0;
5959d12ba86SRob Rice }
5969d12ba86SRob Rice
5979d12ba86SRob Rice /**
5989d12ba86SRob Rice * spu2_fmd_ctrl0_write() - Write ctrl0 field in fixed metadata (FMD) field of
5999d12ba86SRob Rice * SPU request packet.
6009d12ba86SRob Rice * @fmd: Start of FMD field to be written
6019d12ba86SRob Rice * @is_inbound: true if decrypting. false if encrypting.
60285a557cbSLee Jones * @auth_first: true if alg authenticates before encrypting
6039d12ba86SRob Rice * @protocol: protocol selector
6049d12ba86SRob Rice * @cipher_type: cipher algorithm
6059d12ba86SRob Rice * @cipher_mode: cipher mode
6069d12ba86SRob Rice * @auth_type: authentication type
6079d12ba86SRob Rice * @auth_mode: authentication mode
6089d12ba86SRob Rice */
spu2_fmd_ctrl0_write(struct SPU2_FMD * fmd,bool is_inbound,bool auth_first,enum spu2_proto_sel protocol,enum spu2_cipher_type cipher_type,enum spu2_cipher_mode cipher_mode,enum spu2_hash_type auth_type,enum spu2_hash_mode auth_mode)6099d12ba86SRob Rice static void spu2_fmd_ctrl0_write(struct SPU2_FMD *fmd,
6109d12ba86SRob Rice bool is_inbound, bool auth_first,
6119d12ba86SRob Rice enum spu2_proto_sel protocol,
6129d12ba86SRob Rice enum spu2_cipher_type cipher_type,
6139d12ba86SRob Rice enum spu2_cipher_mode cipher_mode,
6149d12ba86SRob Rice enum spu2_hash_type auth_type,
6159d12ba86SRob Rice enum spu2_hash_mode auth_mode)
6169d12ba86SRob Rice {
6179d12ba86SRob Rice u64 ctrl0 = 0;
6189d12ba86SRob Rice
6199d12ba86SRob Rice if ((cipher_type != SPU2_CIPHER_TYPE_NONE) && !is_inbound)
6209d12ba86SRob Rice ctrl0 |= SPU2_CIPH_ENCRYPT_EN;
6219d12ba86SRob Rice
6229d12ba86SRob Rice ctrl0 |= ((u64)cipher_type << SPU2_CIPH_TYPE_SHIFT) |
6239d12ba86SRob Rice ((u64)cipher_mode << SPU2_CIPH_MODE_SHIFT);
6249d12ba86SRob Rice
6259d12ba86SRob Rice if (protocol)
6269d12ba86SRob Rice ctrl0 |= (u64)protocol << SPU2_PROTO_SEL_SHIFT;
6279d12ba86SRob Rice
6289d12ba86SRob Rice if (auth_first)
6299d12ba86SRob Rice ctrl0 |= SPU2_HASH_FIRST;
6309d12ba86SRob Rice
6319d12ba86SRob Rice if (is_inbound && (auth_type != SPU2_HASH_TYPE_NONE))
6329d12ba86SRob Rice ctrl0 |= SPU2_CHK_TAG;
6339d12ba86SRob Rice
6349d12ba86SRob Rice ctrl0 |= (((u64)auth_type << SPU2_HASH_TYPE_SHIFT) |
6359d12ba86SRob Rice ((u64)auth_mode << SPU2_HASH_MODE_SHIFT));
6369d12ba86SRob Rice
6379d12ba86SRob Rice fmd->ctrl0 = cpu_to_le64(ctrl0);
6389d12ba86SRob Rice }
6399d12ba86SRob Rice
6409d12ba86SRob Rice /**
6419d12ba86SRob Rice * spu2_fmd_ctrl1_write() - Write ctrl1 field in fixed metadata (FMD) field of
6429d12ba86SRob Rice * SPU request packet.
6439d12ba86SRob Rice * @fmd: Start of FMD field to be written
64485a557cbSLee Jones * @is_inbound: true if decrypting. false if encrypting.
6459d12ba86SRob Rice * @assoc_size: Length of additional associated data, in bytes
6469d12ba86SRob Rice * @auth_key_len: Length of authentication key, in bytes
6479d12ba86SRob Rice * @cipher_key_len: Length of cipher key, in bytes
6489d12ba86SRob Rice * @gen_iv: If true, hw generates IV and returns in response
6499d12ba86SRob Rice * @hash_iv: IV participates in hash. Used for IPSEC and TLS.
6509d12ba86SRob Rice * @return_iv: Return IV in output packet before payload
6519d12ba86SRob Rice * @ret_iv_len: Length of IV returned from SPU, in bytes
6529d12ba86SRob Rice * @ret_iv_offset: Offset into full IV of start of returned IV
6539d12ba86SRob Rice * @cipher_iv_len: Length of input cipher IV, in bytes
6549d12ba86SRob Rice * @digest_size: Length of digest (aka, hash tag or ICV), in bytes
6559d12ba86SRob Rice * @return_payload: Return payload in SPU response
6569d12ba86SRob Rice * @return_md : return metadata in SPU response
6579d12ba86SRob Rice *
6589d12ba86SRob Rice * Packet can have AAD2 w/o AAD1. For algorithms currently supported,
6599d12ba86SRob Rice * associated data goes in AAD2.
6609d12ba86SRob Rice */
spu2_fmd_ctrl1_write(struct SPU2_FMD * fmd,bool is_inbound,u64 assoc_size,u64 auth_key_len,u64 cipher_key_len,bool gen_iv,bool hash_iv,bool return_iv,u64 ret_iv_len,u64 ret_iv_offset,u64 cipher_iv_len,u64 digest_size,bool return_payload,bool return_md)6619d12ba86SRob Rice static void spu2_fmd_ctrl1_write(struct SPU2_FMD *fmd, bool is_inbound,
6629d12ba86SRob Rice u64 assoc_size,
6639d12ba86SRob Rice u64 auth_key_len, u64 cipher_key_len,
6649d12ba86SRob Rice bool gen_iv, bool hash_iv, bool return_iv,
6659d12ba86SRob Rice u64 ret_iv_len, u64 ret_iv_offset,
6669d12ba86SRob Rice u64 cipher_iv_len, u64 digest_size,
6679d12ba86SRob Rice bool return_payload, bool return_md)
6689d12ba86SRob Rice {
6699d12ba86SRob Rice u64 ctrl1 = 0;
6709d12ba86SRob Rice
6719d12ba86SRob Rice if (is_inbound && digest_size)
6729d12ba86SRob Rice ctrl1 |= SPU2_TAG_LOC;
6739d12ba86SRob Rice
6749d12ba86SRob Rice if (assoc_size) {
6759d12ba86SRob Rice ctrl1 |= SPU2_HAS_AAD2;
6769d12ba86SRob Rice ctrl1 |= SPU2_RETURN_AAD2; /* need aad2 for gcm aes esp */
6779d12ba86SRob Rice }
6789d12ba86SRob Rice
6799d12ba86SRob Rice if (auth_key_len)
6809d12ba86SRob Rice ctrl1 |= ((auth_key_len << SPU2_HASH_KEY_LEN_SHIFT) &
6819d12ba86SRob Rice SPU2_HASH_KEY_LEN);
6829d12ba86SRob Rice
6839d12ba86SRob Rice if (cipher_key_len)
6849d12ba86SRob Rice ctrl1 |= ((cipher_key_len << SPU2_CIPH_KEY_LEN_SHIFT) &
6859d12ba86SRob Rice SPU2_CIPH_KEY_LEN);
6869d12ba86SRob Rice
6879d12ba86SRob Rice if (gen_iv)
6889d12ba86SRob Rice ctrl1 |= SPU2_GENIV;
6899d12ba86SRob Rice
6909d12ba86SRob Rice if (hash_iv)
6919d12ba86SRob Rice ctrl1 |= SPU2_HASH_IV;
6929d12ba86SRob Rice
6939d12ba86SRob Rice if (return_iv) {
6949d12ba86SRob Rice ctrl1 |= SPU2_RET_IV;
6959d12ba86SRob Rice ctrl1 |= ret_iv_len << SPU2_RET_IV_LEN_SHIFT;
6969d12ba86SRob Rice ctrl1 |= ret_iv_offset << SPU2_IV_OFFSET_SHIFT;
6979d12ba86SRob Rice }
6989d12ba86SRob Rice
6999d12ba86SRob Rice ctrl1 |= ((cipher_iv_len << SPU2_IV_LEN_SHIFT) & SPU2_IV_LEN);
7009d12ba86SRob Rice
7019d12ba86SRob Rice if (digest_size)
7029d12ba86SRob Rice ctrl1 |= ((digest_size << SPU2_HASH_TAG_LEN_SHIFT) &
7039d12ba86SRob Rice SPU2_HASH_TAG_LEN);
7049d12ba86SRob Rice
7059d12ba86SRob Rice /* Let's ask for the output pkt to include FMD, but don't need to
7069d12ba86SRob Rice * get keys and IVs back in OMD.
7079d12ba86SRob Rice */
7089d12ba86SRob Rice if (return_md)
7099d12ba86SRob Rice ctrl1 |= ((u64)SPU2_RET_FMD_ONLY << SPU2_RETURN_MD_SHIFT);
7109d12ba86SRob Rice else
7119d12ba86SRob Rice ctrl1 |= ((u64)SPU2_RET_NO_MD << SPU2_RETURN_MD_SHIFT);
7129d12ba86SRob Rice
7139d12ba86SRob Rice /* Crypto API does not get assoc data back. So no need for AAD2. */
7149d12ba86SRob Rice
7159d12ba86SRob Rice if (return_payload)
7169d12ba86SRob Rice ctrl1 |= SPU2_RETURN_PAY;
7179d12ba86SRob Rice
7189d12ba86SRob Rice fmd->ctrl1 = cpu_to_le64(ctrl1);
7199d12ba86SRob Rice }
7209d12ba86SRob Rice
7219d12ba86SRob Rice /**
7229d12ba86SRob Rice * spu2_fmd_ctrl2_write() - Set the ctrl2 field in the fixed metadata field of
7239d12ba86SRob Rice * SPU2 header.
7249d12ba86SRob Rice * @fmd: Start of FMD field to be written
7259d12ba86SRob Rice * @cipher_offset: Number of bytes from Start of Packet (end of FD field) where
7269d12ba86SRob Rice * data to be encrypted or decrypted begins
7279d12ba86SRob Rice * @auth_key_len: Length of authentication key, in bytes
7289d12ba86SRob Rice * @auth_iv_len: Length of authentication initialization vector, in bytes
7299d12ba86SRob Rice * @cipher_key_len: Length of cipher key, in bytes
7309d12ba86SRob Rice * @cipher_iv_len: Length of cipher IV, in bytes
7319d12ba86SRob Rice */
spu2_fmd_ctrl2_write(struct SPU2_FMD * fmd,u64 cipher_offset,u64 auth_key_len,u64 auth_iv_len,u64 cipher_key_len,u64 cipher_iv_len)7329d12ba86SRob Rice static void spu2_fmd_ctrl2_write(struct SPU2_FMD *fmd, u64 cipher_offset,
7339d12ba86SRob Rice u64 auth_key_len, u64 auth_iv_len,
7349d12ba86SRob Rice u64 cipher_key_len, u64 cipher_iv_len)
7359d12ba86SRob Rice {
7369d12ba86SRob Rice u64 ctrl2;
7379d12ba86SRob Rice u64 aad1_offset;
7389d12ba86SRob Rice u64 aad2_offset;
7399d12ba86SRob Rice u16 aad1_len = 0;
7409d12ba86SRob Rice u64 payload_offset;
7419d12ba86SRob Rice
7429d12ba86SRob Rice /* AAD1 offset is from start of FD. FD length always 0. */
7439d12ba86SRob Rice aad1_offset = 0;
7449d12ba86SRob Rice
7459d12ba86SRob Rice aad2_offset = aad1_offset;
7469d12ba86SRob Rice payload_offset = cipher_offset;
7479d12ba86SRob Rice ctrl2 = aad1_offset |
7489d12ba86SRob Rice (aad1_len << SPU2_AAD1_LEN_SHIFT) |
7499d12ba86SRob Rice (aad2_offset << SPU2_AAD2_OFFSET_SHIFT) |
7509d12ba86SRob Rice (payload_offset << SPU2_PL_OFFSET_SHIFT);
7519d12ba86SRob Rice
7529d12ba86SRob Rice fmd->ctrl2 = cpu_to_le64(ctrl2);
7539d12ba86SRob Rice }
7549d12ba86SRob Rice
7559d12ba86SRob Rice /**
7569d12ba86SRob Rice * spu2_fmd_ctrl3_write() - Set the ctrl3 field in FMD
7579d12ba86SRob Rice * @fmd: Fixed meta data. First field in SPU2 msg header.
7589d12ba86SRob Rice * @payload_len: Length of payload, in bytes
7599d12ba86SRob Rice */
spu2_fmd_ctrl3_write(struct SPU2_FMD * fmd,u64 payload_len)7609d12ba86SRob Rice static void spu2_fmd_ctrl3_write(struct SPU2_FMD *fmd, u64 payload_len)
7619d12ba86SRob Rice {
7629d12ba86SRob Rice u64 ctrl3;
7639d12ba86SRob Rice
7649d12ba86SRob Rice ctrl3 = payload_len & SPU2_PL_LEN;
7659d12ba86SRob Rice
7669d12ba86SRob Rice fmd->ctrl3 = cpu_to_le64(ctrl3);
7679d12ba86SRob Rice }
7689d12ba86SRob Rice
7699d12ba86SRob Rice /**
7709d12ba86SRob Rice * spu2_ctx_max_payload() - Determine the maximum length of the payload for a
7719d12ba86SRob Rice * SPU message for a given cipher and hash alg context.
7729d12ba86SRob Rice * @cipher_alg: The cipher algorithm
7739d12ba86SRob Rice * @cipher_mode: The cipher mode
7749d12ba86SRob Rice * @blocksize: The size of a block of data for this algo
7759d12ba86SRob Rice *
7769d12ba86SRob Rice * For SPU2, the hardware generally ignores the PayloadLen field in ctrl3 of
7779d12ba86SRob Rice * FMD and just keeps computing until it receives a DMA descriptor with the EOF
7789d12ba86SRob Rice * flag set. So we consider the max payload to be infinite. AES CCM is an
7799d12ba86SRob Rice * exception.
7809d12ba86SRob Rice *
7819d12ba86SRob Rice * Return: Max payload length in bytes
7829d12ba86SRob Rice */
spu2_ctx_max_payload(enum spu_cipher_alg cipher_alg,enum spu_cipher_mode cipher_mode,unsigned int blocksize)7839d12ba86SRob Rice u32 spu2_ctx_max_payload(enum spu_cipher_alg cipher_alg,
7849d12ba86SRob Rice enum spu_cipher_mode cipher_mode,
7859d12ba86SRob Rice unsigned int blocksize)
7869d12ba86SRob Rice {
7879d12ba86SRob Rice if ((cipher_alg == CIPHER_ALG_AES) &&
7889d12ba86SRob Rice (cipher_mode == CIPHER_MODE_CCM)) {
7899d12ba86SRob Rice u32 excess = SPU2_MAX_PAYLOAD % blocksize;
7909d12ba86SRob Rice
7919d12ba86SRob Rice return SPU2_MAX_PAYLOAD - excess;
7929d12ba86SRob Rice } else {
7939d12ba86SRob Rice return SPU_MAX_PAYLOAD_INF;
7949d12ba86SRob Rice }
7959d12ba86SRob Rice }
7969d12ba86SRob Rice
7979d12ba86SRob Rice /**
79885a557cbSLee Jones * spu2_payload_length() - Given a SPU2 message header, extract the payload
7999d12ba86SRob Rice * length.
8009d12ba86SRob Rice * @spu_hdr: Start of SPU message header (FMD)
8019d12ba86SRob Rice *
8029d12ba86SRob Rice * Return: payload length, in bytes
8039d12ba86SRob Rice */
spu2_payload_length(u8 * spu_hdr)8049d12ba86SRob Rice u32 spu2_payload_length(u8 *spu_hdr)
8059d12ba86SRob Rice {
8069d12ba86SRob Rice struct SPU2_FMD *fmd = (struct SPU2_FMD *)spu_hdr;
8079d12ba86SRob Rice u32 pl_len;
8089d12ba86SRob Rice u64 ctrl3;
8099d12ba86SRob Rice
8109d12ba86SRob Rice ctrl3 = le64_to_cpu(fmd->ctrl3);
8119d12ba86SRob Rice pl_len = ctrl3 & SPU2_PL_LEN;
8129d12ba86SRob Rice
8139d12ba86SRob Rice return pl_len;
8149d12ba86SRob Rice }
8159d12ba86SRob Rice
8169d12ba86SRob Rice /**
81785a557cbSLee Jones * spu2_response_hdr_len() - Determine the expected length of a SPU response
8189d12ba86SRob Rice * header.
8199d12ba86SRob Rice * @auth_key_len: Length of authentication key, in bytes
8209d12ba86SRob Rice * @enc_key_len: Length of encryption key, in bytes
82185a557cbSLee Jones * @is_hash: Unused
8229d12ba86SRob Rice *
8239d12ba86SRob Rice * For SPU2, includes just FMD. OMD is never requested.
8249d12ba86SRob Rice *
8259d12ba86SRob Rice * Return: Length of FMD, in bytes
8269d12ba86SRob Rice */
spu2_response_hdr_len(u16 auth_key_len,u16 enc_key_len,bool is_hash)8279d12ba86SRob Rice u16 spu2_response_hdr_len(u16 auth_key_len, u16 enc_key_len, bool is_hash)
8289d12ba86SRob Rice {
8299d12ba86SRob Rice return FMD_SIZE;
8309d12ba86SRob Rice }
8319d12ba86SRob Rice
8329d12ba86SRob Rice /**
83385a557cbSLee Jones * spu2_hash_pad_len() - Calculate the length of hash padding required to extend
8349d12ba86SRob Rice * data to a full block size.
8359d12ba86SRob Rice * @hash_alg: hash algorithm
8369d12ba86SRob Rice * @hash_mode: hash mode
8379d12ba86SRob Rice * @chunksize: length of data, in bytes
8389d12ba86SRob Rice * @hash_block_size: size of a hash block, in bytes
8399d12ba86SRob Rice *
8409d12ba86SRob Rice * SPU2 hardware does all hash padding
8419d12ba86SRob Rice *
8429d12ba86SRob Rice * Return: length of hash pad in bytes
8439d12ba86SRob Rice */
spu2_hash_pad_len(enum hash_alg hash_alg,enum hash_mode hash_mode,u32 chunksize,u16 hash_block_size)8449d12ba86SRob Rice u16 spu2_hash_pad_len(enum hash_alg hash_alg, enum hash_mode hash_mode,
8459d12ba86SRob Rice u32 chunksize, u16 hash_block_size)
8469d12ba86SRob Rice {
8479d12ba86SRob Rice return 0;
8489d12ba86SRob Rice }
8499d12ba86SRob Rice
8509d12ba86SRob Rice /**
85185a557cbSLee Jones * spu2_gcm_ccm_pad_len() - Determine the length of GCM/CCM padding for either
8529d12ba86SRob Rice * the AAD field or the data.
85385a557cbSLee Jones * @cipher_mode: Unused
85485a557cbSLee Jones * @data_size: Unused
8559d12ba86SRob Rice *
8569d12ba86SRob Rice * Return: 0. Unlike SPU-M, SPU2 hardware does any GCM/CCM padding required.
8579d12ba86SRob Rice */
spu2_gcm_ccm_pad_len(enum spu_cipher_mode cipher_mode,unsigned int data_size)8589d12ba86SRob Rice u32 spu2_gcm_ccm_pad_len(enum spu_cipher_mode cipher_mode,
8599d12ba86SRob Rice unsigned int data_size)
8609d12ba86SRob Rice {
8619d12ba86SRob Rice return 0;
8629d12ba86SRob Rice }
8639d12ba86SRob Rice
8649d12ba86SRob Rice /**
86585a557cbSLee Jones * spu2_assoc_resp_len() - Determine the size of the AAD2 buffer needed to catch
8669d12ba86SRob Rice * associated data in a SPU2 output packet.
8679d12ba86SRob Rice * @cipher_mode: cipher mode
8689d12ba86SRob Rice * @assoc_len: length of additional associated data, in bytes
8699d12ba86SRob Rice * @iv_len: length of initialization vector, in bytes
8709d12ba86SRob Rice * @is_encrypt: true if encrypting. false if decrypt.
8719d12ba86SRob Rice *
8729d12ba86SRob Rice * Return: Length of buffer to catch associated data in response
8739d12ba86SRob Rice */
spu2_assoc_resp_len(enum spu_cipher_mode cipher_mode,unsigned int assoc_len,unsigned int iv_len,bool is_encrypt)8749d12ba86SRob Rice u32 spu2_assoc_resp_len(enum spu_cipher_mode cipher_mode,
8759d12ba86SRob Rice unsigned int assoc_len, unsigned int iv_len,
8769d12ba86SRob Rice bool is_encrypt)
8779d12ba86SRob Rice {
8789d12ba86SRob Rice u32 resp_len = assoc_len;
8799d12ba86SRob Rice
8809d12ba86SRob Rice if (is_encrypt)
8819d12ba86SRob Rice /* gcm aes esp has to write 8-byte IV in response */
8829d12ba86SRob Rice resp_len += iv_len;
8839d12ba86SRob Rice return resp_len;
8849d12ba86SRob Rice }
8859d12ba86SRob Rice
88685a557cbSLee Jones /**
88785a557cbSLee Jones * spu2_aead_ivlen() - Calculate the length of the AEAD IV to be included
8889d12ba86SRob Rice * in a SPU request after the AAD and before the payload.
8899d12ba86SRob Rice * @cipher_mode: cipher mode
89085a557cbSLee Jones * @iv_len: initialization vector length in bytes
8919d12ba86SRob Rice *
8929d12ba86SRob Rice * For SPU2, AEAD IV is included in OMD and does not need to be repeated
8939d12ba86SRob Rice * prior to the payload.
8949d12ba86SRob Rice *
8959d12ba86SRob Rice * Return: Length of AEAD IV in bytes
8969d12ba86SRob Rice */
spu2_aead_ivlen(enum spu_cipher_mode cipher_mode,u16 iv_len)8979d12ba86SRob Rice u8 spu2_aead_ivlen(enum spu_cipher_mode cipher_mode, u16 iv_len)
8989d12ba86SRob Rice {
8999d12ba86SRob Rice return 0;
9009d12ba86SRob Rice }
9019d12ba86SRob Rice
9029d12ba86SRob Rice /**
9039d12ba86SRob Rice * spu2_hash_type() - Determine the type of hash operation.
9049d12ba86SRob Rice * @src_sent: The number of bytes in the current request that have already
9059d12ba86SRob Rice * been sent to the SPU to be hashed.
9069d12ba86SRob Rice *
9079d12ba86SRob Rice * SPU2 always does a FULL hash operation
9089d12ba86SRob Rice */
spu2_hash_type(u32 src_sent)9099d12ba86SRob Rice enum hash_type spu2_hash_type(u32 src_sent)
9109d12ba86SRob Rice {
9119d12ba86SRob Rice return HASH_TYPE_FULL;
9129d12ba86SRob Rice }
9139d12ba86SRob Rice
9149d12ba86SRob Rice /**
9159d12ba86SRob Rice * spu2_digest_size() - Determine the size of a hash digest to expect the SPU to
9169d12ba86SRob Rice * return.
91785a557cbSLee Jones * @alg_digest_size: Number of bytes in the final digest for the given algo
91885a557cbSLee Jones * @alg: The hash algorithm
91985a557cbSLee Jones * @htype: Type of hash operation (init, update, full, etc)
9209d12ba86SRob Rice *
9219d12ba86SRob Rice */
spu2_digest_size(u32 alg_digest_size,enum hash_alg alg,enum hash_type htype)9229d12ba86SRob Rice u32 spu2_digest_size(u32 alg_digest_size, enum hash_alg alg,
9239d12ba86SRob Rice enum hash_type htype)
9249d12ba86SRob Rice {
9259d12ba86SRob Rice return alg_digest_size;
9269d12ba86SRob Rice }
9279d12ba86SRob Rice
9289d12ba86SRob Rice /**
92985a557cbSLee Jones * spu2_create_request() - Build a SPU2 request message header, includint FMD and
9309d12ba86SRob Rice * OMD.
9319d12ba86SRob Rice * @spu_hdr: Start of buffer where SPU request header is to be written
9329d12ba86SRob Rice * @req_opts: SPU request message options
9339d12ba86SRob Rice * @cipher_parms: Parameters related to cipher algorithm
9349d12ba86SRob Rice * @hash_parms: Parameters related to hash algorithm
9359d12ba86SRob Rice * @aead_parms: Parameters related to AEAD operation
9369d12ba86SRob Rice * @data_size: Length of data to be encrypted or authenticated. If AEAD, does
9379d12ba86SRob Rice * not include length of AAD.
9389d12ba86SRob Rice *
9399d12ba86SRob Rice * Construct the message starting at spu_hdr. Caller should allocate this buffer
9409d12ba86SRob Rice * in DMA-able memory at least SPU_HEADER_ALLOC_LEN bytes long.
9419d12ba86SRob Rice *
9429d12ba86SRob Rice * Return: the length of the SPU header in bytes. 0 if an error occurs.
9439d12ba86SRob Rice */
spu2_create_request(u8 * spu_hdr,struct spu_request_opts * req_opts,struct spu_cipher_parms * cipher_parms,struct spu_hash_parms * hash_parms,struct spu_aead_parms * aead_parms,unsigned int data_size)9449d12ba86SRob Rice u32 spu2_create_request(u8 *spu_hdr,
9459d12ba86SRob Rice struct spu_request_opts *req_opts,
9469d12ba86SRob Rice struct spu_cipher_parms *cipher_parms,
9479d12ba86SRob Rice struct spu_hash_parms *hash_parms,
9489d12ba86SRob Rice struct spu_aead_parms *aead_parms,
9499d12ba86SRob Rice unsigned int data_size)
9509d12ba86SRob Rice {
9519d12ba86SRob Rice struct SPU2_FMD *fmd;
9529d12ba86SRob Rice u8 *ptr;
9539d12ba86SRob Rice unsigned int buf_len;
9549d12ba86SRob Rice int err;
9559d12ba86SRob Rice enum spu2_cipher_type spu2_ciph_type = SPU2_CIPHER_TYPE_NONE;
9569d12ba86SRob Rice enum spu2_cipher_mode spu2_ciph_mode;
9579d12ba86SRob Rice enum spu2_hash_type spu2_auth_type = SPU2_HASH_TYPE_NONE;
9589d12ba86SRob Rice enum spu2_hash_mode spu2_auth_mode;
9599d12ba86SRob Rice bool return_md = true;
9609d12ba86SRob Rice enum spu2_proto_sel proto = SPU2_PROTO_RESV;
9619d12ba86SRob Rice
9629d12ba86SRob Rice /* size of the payload */
9639d12ba86SRob Rice unsigned int payload_len =
9649d12ba86SRob Rice hash_parms->prebuf_len + data_size + hash_parms->pad_len -
9659d12ba86SRob Rice ((req_opts->is_aead && req_opts->is_inbound) ?
9669d12ba86SRob Rice hash_parms->digestsize : 0);
9679d12ba86SRob Rice
9689d12ba86SRob Rice /* offset of prebuf or data from start of AAD2 */
9699d12ba86SRob Rice unsigned int cipher_offset = aead_parms->assoc_size +
9709d12ba86SRob Rice aead_parms->aad_pad_len + aead_parms->iv_len;
9719d12ba86SRob Rice
9729d12ba86SRob Rice /* total size of the data following OMD (without STAT word padding) */
9739d12ba86SRob Rice unsigned int real_db_size = spu_real_db_size(aead_parms->assoc_size,
9749d12ba86SRob Rice aead_parms->iv_len,
9759d12ba86SRob Rice hash_parms->prebuf_len,
9769d12ba86SRob Rice data_size,
9779d12ba86SRob Rice aead_parms->aad_pad_len,
9789d12ba86SRob Rice aead_parms->data_pad_len,
9799d12ba86SRob Rice hash_parms->pad_len);
9809d12ba86SRob Rice unsigned int assoc_size = aead_parms->assoc_size;
9819d12ba86SRob Rice
9829d12ba86SRob Rice if (req_opts->is_aead &&
9839d12ba86SRob Rice (cipher_parms->alg == CIPHER_ALG_AES) &&
9849d12ba86SRob Rice (cipher_parms->mode == CIPHER_MODE_GCM))
9859d12ba86SRob Rice /*
9869d12ba86SRob Rice * On SPU 2, aes gcm cipher first on encrypt, auth first on
9879d12ba86SRob Rice * decrypt
9889d12ba86SRob Rice */
9899d12ba86SRob Rice req_opts->auth_first = req_opts->is_inbound;
9909d12ba86SRob Rice
9919d12ba86SRob Rice /* and do opposite for ccm (auth 1st on encrypt) */
9929d12ba86SRob Rice if (req_opts->is_aead &&
9939d12ba86SRob Rice (cipher_parms->alg == CIPHER_ALG_AES) &&
9949d12ba86SRob Rice (cipher_parms->mode == CIPHER_MODE_CCM))
9959d12ba86SRob Rice req_opts->auth_first = !req_opts->is_inbound;
9969d12ba86SRob Rice
9979d12ba86SRob Rice flow_log("%s()\n", __func__);
9989d12ba86SRob Rice flow_log(" in:%u authFirst:%u\n",
9999d12ba86SRob Rice req_opts->is_inbound, req_opts->auth_first);
10009d12ba86SRob Rice flow_log(" cipher alg:%u mode:%u type %u\n", cipher_parms->alg,
10019d12ba86SRob Rice cipher_parms->mode, cipher_parms->type);
10029d12ba86SRob Rice flow_log(" is_esp: %s\n", req_opts->is_esp ? "yes" : "no");
10039d12ba86SRob Rice flow_log(" key: %d\n", cipher_parms->key_len);
10049d12ba86SRob Rice flow_dump(" key: ", cipher_parms->key_buf, cipher_parms->key_len);
10059d12ba86SRob Rice flow_log(" iv: %d\n", cipher_parms->iv_len);
10069d12ba86SRob Rice flow_dump(" iv: ", cipher_parms->iv_buf, cipher_parms->iv_len);
10079d12ba86SRob Rice flow_log(" auth alg:%u mode:%u type %u\n",
10089d12ba86SRob Rice hash_parms->alg, hash_parms->mode, hash_parms->type);
10099d12ba86SRob Rice flow_log(" digestsize: %u\n", hash_parms->digestsize);
10109d12ba86SRob Rice flow_log(" authkey: %d\n", hash_parms->key_len);
10119d12ba86SRob Rice flow_dump(" authkey: ", hash_parms->key_buf, hash_parms->key_len);
10129d12ba86SRob Rice flow_log(" assoc_size:%u\n", assoc_size);
10139d12ba86SRob Rice flow_log(" prebuf_len:%u\n", hash_parms->prebuf_len);
10149d12ba86SRob Rice flow_log(" data_size:%u\n", data_size);
10159d12ba86SRob Rice flow_log(" hash_pad_len:%u\n", hash_parms->pad_len);
10169d12ba86SRob Rice flow_log(" real_db_size:%u\n", real_db_size);
10179d12ba86SRob Rice flow_log(" cipher_offset:%u payload_len:%u\n",
10189d12ba86SRob Rice cipher_offset, payload_len);
10199d12ba86SRob Rice flow_log(" aead_iv: %u\n", aead_parms->iv_len);
10209d12ba86SRob Rice
10219d12ba86SRob Rice /* Convert to spu2 values for cipher alg, hash alg */
10229d12ba86SRob Rice err = spu2_cipher_xlate(cipher_parms->alg, cipher_parms->mode,
10239d12ba86SRob Rice cipher_parms->type,
10249d12ba86SRob Rice &spu2_ciph_type, &spu2_ciph_mode);
10259d12ba86SRob Rice
10269d12ba86SRob Rice /* If we are doing GCM hashing only - either via rfc4543 transform
10279d12ba86SRob Rice * or because we happen to do GCM with AAD only and no payload - we
10289d12ba86SRob Rice * need to configure hardware to use hash key rather than cipher key
10299d12ba86SRob Rice * and put data into payload. This is because unlike SPU-M, running
10309d12ba86SRob Rice * GCM cipher with 0 size payload is not permitted.
10319d12ba86SRob Rice */
10329d12ba86SRob Rice if ((req_opts->is_rfc4543) ||
10339d12ba86SRob Rice ((spu2_ciph_mode == SPU2_CIPHER_MODE_GCM) &&
10349d12ba86SRob Rice (payload_len == 0))) {
10359d12ba86SRob Rice /* Use hashing (only) and set up hash key */
10369d12ba86SRob Rice spu2_ciph_type = SPU2_CIPHER_TYPE_NONE;
10379d12ba86SRob Rice hash_parms->key_len = cipher_parms->key_len;
10389d12ba86SRob Rice memcpy(hash_parms->key_buf, cipher_parms->key_buf,
10399d12ba86SRob Rice cipher_parms->key_len);
10409d12ba86SRob Rice cipher_parms->key_len = 0;
10419d12ba86SRob Rice
10429d12ba86SRob Rice if (req_opts->is_rfc4543)
10439d12ba86SRob Rice payload_len += assoc_size;
10449d12ba86SRob Rice else
10459d12ba86SRob Rice payload_len = assoc_size;
10469d12ba86SRob Rice cipher_offset = 0;
10479d12ba86SRob Rice assoc_size = 0;
10489d12ba86SRob Rice }
10499d12ba86SRob Rice
10509d12ba86SRob Rice if (err)
10519d12ba86SRob Rice return 0;
10529d12ba86SRob Rice
10539d12ba86SRob Rice flow_log("spu2 cipher type %s, cipher mode %s\n",
10549d12ba86SRob Rice spu2_ciph_type_name(spu2_ciph_type),
10559d12ba86SRob Rice spu2_ciph_mode_name(spu2_ciph_mode));
10569d12ba86SRob Rice
10579d12ba86SRob Rice err = spu2_hash_xlate(hash_parms->alg, hash_parms->mode,
10589d12ba86SRob Rice hash_parms->type,
10599d12ba86SRob Rice cipher_parms->type,
10609d12ba86SRob Rice &spu2_auth_type, &spu2_auth_mode);
10619d12ba86SRob Rice if (err)
10629d12ba86SRob Rice return 0;
10639d12ba86SRob Rice
10649d12ba86SRob Rice flow_log("spu2 hash type %s, hash mode %s\n",
10659d12ba86SRob Rice spu2_hash_type_name(spu2_auth_type),
10669d12ba86SRob Rice spu2_hash_mode_name(spu2_auth_mode));
10679d12ba86SRob Rice
10689d12ba86SRob Rice fmd = (struct SPU2_FMD *)spu_hdr;
10699d12ba86SRob Rice
10709d12ba86SRob Rice spu2_fmd_ctrl0_write(fmd, req_opts->is_inbound, req_opts->auth_first,
10719d12ba86SRob Rice proto, spu2_ciph_type, spu2_ciph_mode,
10729d12ba86SRob Rice spu2_auth_type, spu2_auth_mode);
10739d12ba86SRob Rice
10749d12ba86SRob Rice spu2_fmd_ctrl1_write(fmd, req_opts->is_inbound, assoc_size,
10759d12ba86SRob Rice hash_parms->key_len, cipher_parms->key_len,
10769d12ba86SRob Rice false, false,
10779d12ba86SRob Rice aead_parms->return_iv, aead_parms->ret_iv_len,
10789d12ba86SRob Rice aead_parms->ret_iv_off,
10799d12ba86SRob Rice cipher_parms->iv_len, hash_parms->digestsize,
10809d12ba86SRob Rice !req_opts->bd_suppress, return_md);
10819d12ba86SRob Rice
10829d12ba86SRob Rice spu2_fmd_ctrl2_write(fmd, cipher_offset, hash_parms->key_len, 0,
10839d12ba86SRob Rice cipher_parms->key_len, cipher_parms->iv_len);
10849d12ba86SRob Rice
10859d12ba86SRob Rice spu2_fmd_ctrl3_write(fmd, payload_len);
10869d12ba86SRob Rice
10879d12ba86SRob Rice ptr = (u8 *)(fmd + 1);
10889d12ba86SRob Rice buf_len = sizeof(struct SPU2_FMD);
10899d12ba86SRob Rice
10909d12ba86SRob Rice /* Write OMD */
10919d12ba86SRob Rice if (hash_parms->key_len) {
10929d12ba86SRob Rice memcpy(ptr, hash_parms->key_buf, hash_parms->key_len);
10939d12ba86SRob Rice ptr += hash_parms->key_len;
10949d12ba86SRob Rice buf_len += hash_parms->key_len;
10959d12ba86SRob Rice }
10969d12ba86SRob Rice if (cipher_parms->key_len) {
10979d12ba86SRob Rice memcpy(ptr, cipher_parms->key_buf, cipher_parms->key_len);
10989d12ba86SRob Rice ptr += cipher_parms->key_len;
10999d12ba86SRob Rice buf_len += cipher_parms->key_len;
11009d12ba86SRob Rice }
11019d12ba86SRob Rice if (cipher_parms->iv_len) {
11029d12ba86SRob Rice memcpy(ptr, cipher_parms->iv_buf, cipher_parms->iv_len);
11039d12ba86SRob Rice ptr += cipher_parms->iv_len;
11049d12ba86SRob Rice buf_len += cipher_parms->iv_len;
11059d12ba86SRob Rice }
11069d12ba86SRob Rice
11079d12ba86SRob Rice packet_dump(" SPU request header: ", spu_hdr, buf_len);
11089d12ba86SRob Rice
11099d12ba86SRob Rice return buf_len;
11109d12ba86SRob Rice }
11119d12ba86SRob Rice
11129d12ba86SRob Rice /**
111385a557cbSLee Jones * spu2_cipher_req_init() - Build an skcipher SPU2 request message header,
11149d12ba86SRob Rice * including FMD and OMD.
11159d12ba86SRob Rice * @spu_hdr: Location of start of SPU request (FMD field)
11169d12ba86SRob Rice * @cipher_parms: Parameters describing cipher request
11179d12ba86SRob Rice *
11189d12ba86SRob Rice * Called at setkey time to initialize a msg header that can be reused for all
1119a9c01cd6SArd Biesheuvel * subsequent skcipher requests. Construct the message starting at spu_hdr.
11209d12ba86SRob Rice * Caller should allocate this buffer in DMA-able memory at least
11219d12ba86SRob Rice * SPU_HEADER_ALLOC_LEN bytes long.
11229d12ba86SRob Rice *
11239d12ba86SRob Rice * Return: the total length of the SPU header (FMD and OMD) in bytes. 0 if an
11249d12ba86SRob Rice * error occurs.
11259d12ba86SRob Rice */
spu2_cipher_req_init(u8 * spu_hdr,struct spu_cipher_parms * cipher_parms)11269d12ba86SRob Rice u16 spu2_cipher_req_init(u8 *spu_hdr, struct spu_cipher_parms *cipher_parms)
11279d12ba86SRob Rice {
11289d12ba86SRob Rice struct SPU2_FMD *fmd;
11299d12ba86SRob Rice u8 *omd;
11309d12ba86SRob Rice enum spu2_cipher_type spu2_type = SPU2_CIPHER_TYPE_NONE;
11319d12ba86SRob Rice enum spu2_cipher_mode spu2_mode;
11329d12ba86SRob Rice int err;
11339d12ba86SRob Rice
11349d12ba86SRob Rice flow_log("%s()\n", __func__);
11359d12ba86SRob Rice flow_log(" cipher alg:%u mode:%u type %u\n", cipher_parms->alg,
11369d12ba86SRob Rice cipher_parms->mode, cipher_parms->type);
11379d12ba86SRob Rice flow_log(" cipher_iv_len: %u\n", cipher_parms->iv_len);
11389d12ba86SRob Rice flow_log(" key: %d\n", cipher_parms->key_len);
11399d12ba86SRob Rice flow_dump(" key: ", cipher_parms->key_buf, cipher_parms->key_len);
11409d12ba86SRob Rice
11419d12ba86SRob Rice /* Convert to spu2 values */
11429d12ba86SRob Rice err = spu2_cipher_xlate(cipher_parms->alg, cipher_parms->mode,
11439d12ba86SRob Rice cipher_parms->type, &spu2_type, &spu2_mode);
11449d12ba86SRob Rice if (err)
11459d12ba86SRob Rice return 0;
11469d12ba86SRob Rice
11479d12ba86SRob Rice flow_log("spu2 cipher type %s, cipher mode %s\n",
11489d12ba86SRob Rice spu2_ciph_type_name(spu2_type),
11499d12ba86SRob Rice spu2_ciph_mode_name(spu2_mode));
11509d12ba86SRob Rice
11519d12ba86SRob Rice /* Construct the FMD header */
11529d12ba86SRob Rice fmd = (struct SPU2_FMD *)spu_hdr;
11539d12ba86SRob Rice err = spu2_fmd_init(fmd, spu2_type, spu2_mode, cipher_parms->key_len,
11549d12ba86SRob Rice cipher_parms->iv_len);
11559d12ba86SRob Rice if (err)
11569d12ba86SRob Rice return 0;
11579d12ba86SRob Rice
11589d12ba86SRob Rice /* Write cipher key to OMD */
11599d12ba86SRob Rice omd = (u8 *)(fmd + 1);
11609d12ba86SRob Rice if (cipher_parms->key_buf && cipher_parms->key_len)
11619d12ba86SRob Rice memcpy(omd, cipher_parms->key_buf, cipher_parms->key_len);
11629d12ba86SRob Rice
11639d12ba86SRob Rice packet_dump(" SPU request header: ", spu_hdr,
11649d12ba86SRob Rice FMD_SIZE + cipher_parms->key_len + cipher_parms->iv_len);
11659d12ba86SRob Rice
11669d12ba86SRob Rice return FMD_SIZE + cipher_parms->key_len + cipher_parms->iv_len;
11679d12ba86SRob Rice }
11689d12ba86SRob Rice
11699d12ba86SRob Rice /**
117085a557cbSLee Jones * spu2_cipher_req_finish() - Finish building a SPU request message header for a
11719d12ba86SRob Rice * block cipher request.
11729d12ba86SRob Rice * @spu_hdr: Start of the request message header (MH field)
11739d12ba86SRob Rice * @spu_req_hdr_len: Length in bytes of the SPU request header
117485a557cbSLee Jones * @is_inbound: 0 encrypt, 1 decrypt
11759d12ba86SRob Rice * @cipher_parms: Parameters describing cipher operation to be performed
11769d12ba86SRob Rice * @data_size: Length of the data in the BD field
11779d12ba86SRob Rice *
11789d12ba86SRob Rice * Assumes much of the header was already filled in at setkey() time in
11799d12ba86SRob Rice * spu_cipher_req_init().
11801dbab6b1SArd Biesheuvel * spu_cipher_req_init() fills in the encryption key.
11819d12ba86SRob Rice */
spu2_cipher_req_finish(u8 * spu_hdr,u16 spu_req_hdr_len,unsigned int is_inbound,struct spu_cipher_parms * cipher_parms,unsigned int data_size)11829d12ba86SRob Rice void spu2_cipher_req_finish(u8 *spu_hdr,
11839d12ba86SRob Rice u16 spu_req_hdr_len,
11849d12ba86SRob Rice unsigned int is_inbound,
11859d12ba86SRob Rice struct spu_cipher_parms *cipher_parms,
11869d12ba86SRob Rice unsigned int data_size)
11879d12ba86SRob Rice {
11889d12ba86SRob Rice struct SPU2_FMD *fmd;
11899d12ba86SRob Rice u8 *omd; /* start of optional metadata */
11909d12ba86SRob Rice u64 ctrl0;
11919d12ba86SRob Rice u64 ctrl3;
11929d12ba86SRob Rice
11939d12ba86SRob Rice flow_log("%s()\n", __func__);
11949d12ba86SRob Rice flow_log(" in: %u\n", is_inbound);
11959d12ba86SRob Rice flow_log(" cipher alg: %u, cipher_type: %u\n", cipher_parms->alg,
11969d12ba86SRob Rice cipher_parms->type);
11979d12ba86SRob Rice flow_log(" iv len: %d\n", cipher_parms->iv_len);
11989d12ba86SRob Rice flow_dump(" iv: ", cipher_parms->iv_buf, cipher_parms->iv_len);
11999d12ba86SRob Rice flow_log(" data_size: %u\n", data_size);
12009d12ba86SRob Rice
12019d12ba86SRob Rice fmd = (struct SPU2_FMD *)spu_hdr;
12029d12ba86SRob Rice omd = (u8 *)(fmd + 1);
12039d12ba86SRob Rice
12049d12ba86SRob Rice /*
12059d12ba86SRob Rice * FMD ctrl0 was initialized at setkey time. update it to indicate
12069d12ba86SRob Rice * whether we are encrypting or decrypting.
12079d12ba86SRob Rice */
12089d12ba86SRob Rice ctrl0 = le64_to_cpu(fmd->ctrl0);
12099d12ba86SRob Rice if (is_inbound)
12109d12ba86SRob Rice ctrl0 &= ~SPU2_CIPH_ENCRYPT_EN; /* decrypt */
12119d12ba86SRob Rice else
12129d12ba86SRob Rice ctrl0 |= SPU2_CIPH_ENCRYPT_EN; /* encrypt */
12139d12ba86SRob Rice fmd->ctrl0 = cpu_to_le64(ctrl0);
12149d12ba86SRob Rice
12159d12ba86SRob Rice if (cipher_parms->alg && cipher_parms->iv_buf && cipher_parms->iv_len) {
12169d12ba86SRob Rice /* cipher iv provided so put it in here */
12179d12ba86SRob Rice memcpy(omd + cipher_parms->key_len, cipher_parms->iv_buf,
12189d12ba86SRob Rice cipher_parms->iv_len);
12199d12ba86SRob Rice }
12209d12ba86SRob Rice
12219d12ba86SRob Rice ctrl3 = le64_to_cpu(fmd->ctrl3);
12229d12ba86SRob Rice data_size &= SPU2_PL_LEN;
12239d12ba86SRob Rice ctrl3 |= data_size;
12249d12ba86SRob Rice fmd->ctrl3 = cpu_to_le64(ctrl3);
12259d12ba86SRob Rice
12269d12ba86SRob Rice packet_dump(" SPU request header: ", spu_hdr, spu_req_hdr_len);
12279d12ba86SRob Rice }
12289d12ba86SRob Rice
12299d12ba86SRob Rice /**
123085a557cbSLee Jones * spu2_request_pad() - Create pad bytes at the end of the data.
12319d12ba86SRob Rice * @pad_start: Start of buffer where pad bytes are to be written
12329d12ba86SRob Rice * @gcm_padding: Length of GCM padding, in bytes
12339d12ba86SRob Rice * @hash_pad_len: Number of bytes of padding extend data to full block
12349d12ba86SRob Rice * @auth_alg: Authentication algorithm
12359d12ba86SRob Rice * @auth_mode: Authentication mode
12369d12ba86SRob Rice * @total_sent: Length inserted at end of hash pad
12379d12ba86SRob Rice * @status_padding: Number of bytes of padding to align STATUS word
12389d12ba86SRob Rice *
12399d12ba86SRob Rice * There may be three forms of pad:
12409d12ba86SRob Rice * 1. GCM pad - for GCM mode ciphers, pad to 16-byte alignment
12419d12ba86SRob Rice * 2. hash pad - pad to a block length, with 0x80 data terminator and
12429d12ba86SRob Rice * size at the end
12439d12ba86SRob Rice * 3. STAT pad - to ensure the STAT field is 4-byte aligned
12449d12ba86SRob Rice */
spu2_request_pad(u8 * pad_start,u32 gcm_padding,u32 hash_pad_len,enum hash_alg auth_alg,enum hash_mode auth_mode,unsigned int total_sent,u32 status_padding)12459d12ba86SRob Rice void spu2_request_pad(u8 *pad_start, u32 gcm_padding, u32 hash_pad_len,
12469d12ba86SRob Rice enum hash_alg auth_alg, enum hash_mode auth_mode,
12479d12ba86SRob Rice unsigned int total_sent, u32 status_padding)
12489d12ba86SRob Rice {
12499d12ba86SRob Rice u8 *ptr = pad_start;
12509d12ba86SRob Rice
12519d12ba86SRob Rice /* fix data alignent for GCM */
12529d12ba86SRob Rice if (gcm_padding > 0) {
12539d12ba86SRob Rice flow_log(" GCM: padding to 16 byte alignment: %u bytes\n",
12549d12ba86SRob Rice gcm_padding);
12559d12ba86SRob Rice memset(ptr, 0, gcm_padding);
12569d12ba86SRob Rice ptr += gcm_padding;
12579d12ba86SRob Rice }
12589d12ba86SRob Rice
12599d12ba86SRob Rice if (hash_pad_len > 0) {
12609d12ba86SRob Rice /* clear the padding section */
12619d12ba86SRob Rice memset(ptr, 0, hash_pad_len);
12629d12ba86SRob Rice
12639d12ba86SRob Rice /* terminate the data */
12649d12ba86SRob Rice *ptr = 0x80;
12659d12ba86SRob Rice ptr += (hash_pad_len - sizeof(u64));
12669d12ba86SRob Rice
12679d12ba86SRob Rice /* add the size at the end as required per alg */
12689d12ba86SRob Rice if (auth_alg == HASH_ALG_MD5)
12695a17eae4SHerbert Xu *(__le64 *)ptr = cpu_to_le64(total_sent * 8ull);
12709d12ba86SRob Rice else /* SHA1, SHA2-224, SHA2-256 */
12715a17eae4SHerbert Xu *(__be64 *)ptr = cpu_to_be64(total_sent * 8ull);
12729d12ba86SRob Rice ptr += sizeof(u64);
12739d12ba86SRob Rice }
12749d12ba86SRob Rice
12759d12ba86SRob Rice /* pad to a 4byte alignment for STAT */
12769d12ba86SRob Rice if (status_padding > 0) {
12779d12ba86SRob Rice flow_log(" STAT: padding to 4 byte alignment: %u bytes\n",
12789d12ba86SRob Rice status_padding);
12799d12ba86SRob Rice
12809d12ba86SRob Rice memset(ptr, 0, status_padding);
12819d12ba86SRob Rice ptr += status_padding;
12829d12ba86SRob Rice }
12839d12ba86SRob Rice }
12849d12ba86SRob Rice
12859d12ba86SRob Rice /**
12869d12ba86SRob Rice * spu2_xts_tweak_in_payload() - Indicate that SPU2 does NOT place the XTS
12879d12ba86SRob Rice * tweak field in the packet payload (it uses IV instead)
12889d12ba86SRob Rice *
12899d12ba86SRob Rice * Return: 0
12909d12ba86SRob Rice */
spu2_xts_tweak_in_payload(void)12919d12ba86SRob Rice u8 spu2_xts_tweak_in_payload(void)
12929d12ba86SRob Rice {
12939d12ba86SRob Rice return 0;
12949d12ba86SRob Rice }
12959d12ba86SRob Rice
12969d12ba86SRob Rice /**
12979d12ba86SRob Rice * spu2_tx_status_len() - Return the length of the STATUS field in a SPU
12989d12ba86SRob Rice * response message.
12999d12ba86SRob Rice *
13009d12ba86SRob Rice * Return: Length of STATUS field in bytes.
13019d12ba86SRob Rice */
spu2_tx_status_len(void)13029d12ba86SRob Rice u8 spu2_tx_status_len(void)
13039d12ba86SRob Rice {
13049d12ba86SRob Rice return SPU2_TX_STATUS_LEN;
13059d12ba86SRob Rice }
13069d12ba86SRob Rice
13079d12ba86SRob Rice /**
13089d12ba86SRob Rice * spu2_rx_status_len() - Return the length of the STATUS field in a SPU
13099d12ba86SRob Rice * response message.
13109d12ba86SRob Rice *
13119d12ba86SRob Rice * Return: Length of STATUS field in bytes.
13129d12ba86SRob Rice */
spu2_rx_status_len(void)13139d12ba86SRob Rice u8 spu2_rx_status_len(void)
13149d12ba86SRob Rice {
13159d12ba86SRob Rice return SPU2_RX_STATUS_LEN;
13169d12ba86SRob Rice }
13179d12ba86SRob Rice
13189d12ba86SRob Rice /**
131985a557cbSLee Jones * spu2_status_process() - Process the status from a SPU response message.
13209d12ba86SRob Rice * @statp: start of STATUS word
13219d12ba86SRob Rice *
13229d12ba86SRob Rice * Return: 0 - if status is good and response should be processed
13239d12ba86SRob Rice * !0 - status indicates an error and response is invalid
13249d12ba86SRob Rice */
spu2_status_process(u8 * statp)13259d12ba86SRob Rice int spu2_status_process(u8 *statp)
13269d12ba86SRob Rice {
13279d12ba86SRob Rice /* SPU2 status is 2 bytes by default - SPU_RX_STATUS_LEN */
13289d12ba86SRob Rice u16 status = le16_to_cpu(*(__le16 *)statp);
13299d12ba86SRob Rice
13309d12ba86SRob Rice if (status == 0)
13319d12ba86SRob Rice return 0;
13329d12ba86SRob Rice
13339d12ba86SRob Rice flow_log("rx status is %#x\n", status);
13349d12ba86SRob Rice if (status == SPU2_INVALID_ICV)
13359d12ba86SRob Rice return SPU_INVALID_ICV;
13369d12ba86SRob Rice
13379d12ba86SRob Rice return -EBADMSG;
13389d12ba86SRob Rice }
13399d12ba86SRob Rice
13409d12ba86SRob Rice /**
13419d12ba86SRob Rice * spu2_ccm_update_iv() - Update the IV as per the requirements for CCM mode.
13429d12ba86SRob Rice *
13439d12ba86SRob Rice * @digestsize: Digest size of this request
13449d12ba86SRob Rice * @cipher_parms: (pointer to) cipher parmaeters, includes IV buf & IV len
13459d12ba86SRob Rice * @assoclen: Length of AAD data
13469d12ba86SRob Rice * @chunksize: length of input data to be sent in this req
13479d12ba86SRob Rice * @is_encrypt: true if this is an output/encrypt operation
13489d12ba86SRob Rice * @is_esp: true if this is an ESP / RFC4309 operation
13499d12ba86SRob Rice *
13509d12ba86SRob Rice */
spu2_ccm_update_iv(unsigned int digestsize,struct spu_cipher_parms * cipher_parms,unsigned int assoclen,unsigned int chunksize,bool is_encrypt,bool is_esp)13519d12ba86SRob Rice void spu2_ccm_update_iv(unsigned int digestsize,
13529d12ba86SRob Rice struct spu_cipher_parms *cipher_parms,
13539d12ba86SRob Rice unsigned int assoclen, unsigned int chunksize,
13549d12ba86SRob Rice bool is_encrypt, bool is_esp)
13559d12ba86SRob Rice {
13569d12ba86SRob Rice int L; /* size of length field, in bytes */
13579d12ba86SRob Rice
13589d12ba86SRob Rice /*
13599d12ba86SRob Rice * In RFC4309 mode, L is fixed at 4 bytes; otherwise, IV from
13609d12ba86SRob Rice * testmgr contains (L-1) in bottom 3 bits of first byte,
13619d12ba86SRob Rice * per RFC 3610.
13629d12ba86SRob Rice */
13639d12ba86SRob Rice if (is_esp)
13649d12ba86SRob Rice L = CCM_ESP_L_VALUE;
13659d12ba86SRob Rice else
13669d12ba86SRob Rice L = ((cipher_parms->iv_buf[0] & CCM_B0_L_PRIME) >>
13679d12ba86SRob Rice CCM_B0_L_PRIME_SHIFT) + 1;
13689d12ba86SRob Rice
13699d12ba86SRob Rice /* SPU2 doesn't want these length bytes nor the first byte... */
13709d12ba86SRob Rice cipher_parms->iv_len -= (1 + L);
13719d12ba86SRob Rice memmove(cipher_parms->iv_buf, &cipher_parms->iv_buf[1],
13729d12ba86SRob Rice cipher_parms->iv_len);
13739d12ba86SRob Rice }
13749d12ba86SRob Rice
13759d12ba86SRob Rice /**
13769d12ba86SRob Rice * spu2_wordalign_padlen() - SPU2 does not require padding.
13779d12ba86SRob Rice * @data_size: length of data field in bytes
13789d12ba86SRob Rice *
13799d12ba86SRob Rice * Return: length of status field padding, in bytes (always 0 on SPU2)
13809d12ba86SRob Rice */
spu2_wordalign_padlen(u32 data_size)13819d12ba86SRob Rice u32 spu2_wordalign_padlen(u32 data_size)
13829d12ba86SRob Rice {
13839d12ba86SRob Rice return 0;
13849d12ba86SRob Rice }
1385