/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright 2016 Broadcom3*/45/*6* This file contains SPU message definitions specific to SPU-M.7*/89#ifndef _SPUM_H_10#define _SPUM_H_1112#define SPU_CRYPTO_OPERATION_GENERIC 0x11314/* Length of STATUS field in tx and rx packets */15#define SPU_TX_STATUS_LEN 41617/* SPU-M error codes */18#define SPU_STATUS_MASK 0x0000FF0019#define SPU_STATUS_SUCCESS 0x0000000020#define SPU_STATUS_INVALID_ICV 0x000001002122#define SPU_STATUS_ERROR_FLAG 0x000200002324/* Request message. MH + EMH + BDESC + BD header */25#define SPU_REQ_FIXED_LEN 242627/*28* Max length of a SPU message header. Used to allocate a buffer where29* the SPU message header is constructed. Can be used for either a SPU-M30* header or a SPU2 header.31* For SPU-M, sum of the following:32* MH - 4 bytes33* EMH - 434* SCTX - 3 +35* max auth key len - 6436* max cipher key len - 264 (RC4)37* max IV len - 1638* BDESC - 1239* BD header - 440* Total: 37141*42* For SPU2, FMD_SIZE (32) plus lengths of hash and cipher keys,43* hash and cipher IVs. If SPU2 does not support RC4, then44*/45#define SPU_HEADER_ALLOC_LEN (SPU_REQ_FIXED_LEN + MAX_KEY_SIZE + \46MAX_KEY_SIZE + MAX_IV_SIZE)4748/*49* Response message header length. Normally MH, EMH, BD header, but when50* BD_SUPPRESS is used for hash requests, there is no BD header.51*/52#define SPU_RESP_HDR_LEN 1253#define SPU_HASH_RESP_HDR_LEN 85455/*56* Max value that can be represented in the Payload Length field of the BD57* header. This is a 16-bit field.58*/59#define SPUM_NS2_MAX_PAYLOAD (BIT(16) - 1)6061/*62* NSP SPU is limited to ~9KB because of FA2 FIFO size limitations;63* Set MAX_PAYLOAD to 8k to allow for addition of header, digest, etc.64* and stay within limitation.65*/6667#define SPUM_NSP_MAX_PAYLOAD 81926869/* Buffer Descriptor Header [BDESC]. SPU in big-endian mode. */70struct BDESC_HEADER {71__be16 offset_mac; /* word 0 [31-16] */72__be16 length_mac; /* word 0 [15-0] */73__be16 offset_crypto; /* word 1 [31-16] */74__be16 length_crypto; /* word 1 [15-0] */75__be16 offset_icv; /* word 2 [31-16] */76__be16 offset_iv; /* word 2 [15-0] */77};7879/* Buffer Data Header [BD]. SPU in big-endian mode. */80struct BD_HEADER {81__be16 size;82__be16 prev_length;83};8485/* Command Context Header. SPU-M in big endian mode. */86struct MHEADER {87u8 flags; /* [31:24] */88u8 op_code; /* [23:16] */89u16 reserved; /* [15:0] */90};9192/* MH header flags bits */93#define MH_SUPDT_PRES BIT(0)94#define MH_HASH_PRES BIT(2)95#define MH_BD_PRES BIT(3)96#define MH_MFM_PRES BIT(4)97#define MH_BDESC_PRES BIT(5)98#define MH_SCTX_PRES BIT(7)99100/* SCTX word 0 bit offsets and fields masks */101#define SCTX_SIZE 0x000000FF102103/* SCTX word 1 bit shifts and field masks */104#define UPDT_OFST 0x000000FF /* offset of SCTX updateable fld */105#define HASH_TYPE 0x00000300 /* hash alg operation type */106#define HASH_TYPE_SHIFT 8107#define HASH_MODE 0x00001C00 /* one of spu2_hash_mode */108#define HASH_MODE_SHIFT 10109#define HASH_ALG 0x0000E000 /* hash algorithm */110#define HASH_ALG_SHIFT 13111#define CIPHER_TYPE 0x00030000 /* encryption operation type */112#define CIPHER_TYPE_SHIFT 16113#define CIPHER_MODE 0x001C0000 /* encryption mode */114#define CIPHER_MODE_SHIFT 18115#define CIPHER_ALG 0x00E00000 /* encryption algo */116#define CIPHER_ALG_SHIFT 21117#define ICV_IS_512 BIT(27)118#define ICV_IS_512_SHIFT 27119#define CIPHER_ORDER BIT(30)120#define CIPHER_ORDER_SHIFT 30121#define CIPHER_INBOUND BIT(31)122#define CIPHER_INBOUND_SHIFT 31123124/* SCTX word 2 bit shifts and field masks */125#define EXP_IV_SIZE 0x7126#define IV_OFFSET BIT(3)127#define IV_OFFSET_SHIFT 3128#define GEN_IV BIT(5)129#define GEN_IV_SHIFT 5130#define EXPLICIT_IV BIT(6)131#define EXPLICIT_IV_SHIFT 6132#define SCTX_IV BIT(7)133#define SCTX_IV_SHIFT 7134#define ICV_SIZE 0x0F00135#define ICV_SIZE_SHIFT 8136#define CHECK_ICV BIT(12)137#define CHECK_ICV_SHIFT 12138#define INSERT_ICV BIT(13)139#define INSERT_ICV_SHIFT 13140#define BD_SUPPRESS BIT(19)141#define BD_SUPPRESS_SHIFT 19142143/* Generic Mode Security Context Structure [SCTX] */144struct SCTX {145/* word 0: protocol flags */146__be32 proto_flags;147148/* word 1: cipher flags */149__be32 cipher_flags;150151/* word 2: Extended cipher flags */152__be32 ecf;153154};155156struct SPUHEADER {157struct MHEADER mh;158u32 emh;159struct SCTX sa;160};161162#endif /* _SPUM_H_ */163164165