162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright 2016 Broadcom
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci/*
762306a36Sopenharmony_ci * This file contains SPU message definitions specific to SPU-M.
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef _SPUM_H_
1162306a36Sopenharmony_ci#define _SPUM_H_
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#define SPU_CRYPTO_OPERATION_GENERIC	0x1
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/* Length of STATUS field in tx and rx packets */
1662306a36Sopenharmony_ci#define SPU_TX_STATUS_LEN  4
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci/* SPU-M error codes */
1962306a36Sopenharmony_ci#define SPU_STATUS_MASK                 0x0000FF00
2062306a36Sopenharmony_ci#define SPU_STATUS_SUCCESS              0x00000000
2162306a36Sopenharmony_ci#define SPU_STATUS_INVALID_ICV          0x00000100
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ci#define SPU_STATUS_ERROR_FLAG           0x00020000
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci/* Request message. MH + EMH + BDESC + BD header */
2662306a36Sopenharmony_ci#define SPU_REQ_FIXED_LEN 24
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/*
2962306a36Sopenharmony_ci * Max length of a SPU message header. Used to allocate a buffer where
3062306a36Sopenharmony_ci * the SPU message header is constructed. Can be used for either a SPU-M
3162306a36Sopenharmony_ci * header or a SPU2 header.
3262306a36Sopenharmony_ci * For SPU-M, sum of the following:
3362306a36Sopenharmony_ci *    MH - 4 bytes
3462306a36Sopenharmony_ci *    EMH - 4
3562306a36Sopenharmony_ci *    SCTX - 3 +
3662306a36Sopenharmony_ci *      max auth key len - 64
3762306a36Sopenharmony_ci *      max cipher key len - 264 (RC4)
3862306a36Sopenharmony_ci *      max IV len - 16
3962306a36Sopenharmony_ci *    BDESC - 12
4062306a36Sopenharmony_ci *    BD header - 4
4162306a36Sopenharmony_ci * Total:  371
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci * For SPU2, FMD_SIZE (32) plus lengths of hash and cipher keys,
4462306a36Sopenharmony_ci * hash and cipher IVs. If SPU2 does not support RC4, then
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_ci#define SPU_HEADER_ALLOC_LEN  (SPU_REQ_FIXED_LEN + MAX_KEY_SIZE + \
4762306a36Sopenharmony_ci				MAX_KEY_SIZE + MAX_IV_SIZE)
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci/*
5062306a36Sopenharmony_ci * Response message header length. Normally MH, EMH, BD header, but when
5162306a36Sopenharmony_ci * BD_SUPPRESS is used for hash requests, there is no BD header.
5262306a36Sopenharmony_ci */
5362306a36Sopenharmony_ci#define SPU_RESP_HDR_LEN 12
5462306a36Sopenharmony_ci#define SPU_HASH_RESP_HDR_LEN 8
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci/*
5762306a36Sopenharmony_ci * Max value that can be represented in the Payload Length field of the BD
5862306a36Sopenharmony_ci * header. This is a 16-bit field.
5962306a36Sopenharmony_ci */
6062306a36Sopenharmony_ci#define SPUM_NS2_MAX_PAYLOAD  (BIT(16) - 1)
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci/*
6362306a36Sopenharmony_ci * NSP SPU is limited to ~9KB because of FA2 FIFO size limitations;
6462306a36Sopenharmony_ci * Set MAX_PAYLOAD to 8k to allow for addition of header, digest, etc.
6562306a36Sopenharmony_ci * and stay within limitation.
6662306a36Sopenharmony_ci */
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define SPUM_NSP_MAX_PAYLOAD	8192
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci/* Buffer Descriptor Header [BDESC]. SPU in big-endian mode. */
7162306a36Sopenharmony_cistruct BDESC_HEADER {
7262306a36Sopenharmony_ci	__be16 offset_mac;		/* word 0 [31-16] */
7362306a36Sopenharmony_ci	__be16 length_mac;		/* word 0 [15-0]  */
7462306a36Sopenharmony_ci	__be16 offset_crypto;		/* word 1 [31-16] */
7562306a36Sopenharmony_ci	__be16 length_crypto;		/* word 1 [15-0]  */
7662306a36Sopenharmony_ci	__be16 offset_icv;		/* word 2 [31-16] */
7762306a36Sopenharmony_ci	__be16 offset_iv;		/* word 2 [15-0]  */
7862306a36Sopenharmony_ci};
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci/* Buffer Data Header [BD]. SPU in big-endian mode. */
8162306a36Sopenharmony_cistruct BD_HEADER {
8262306a36Sopenharmony_ci	__be16 size;
8362306a36Sopenharmony_ci	__be16 prev_length;
8462306a36Sopenharmony_ci};
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci/* Command Context Header. SPU-M in big endian mode. */
8762306a36Sopenharmony_cistruct MHEADER {
8862306a36Sopenharmony_ci	u8 flags;	/* [31:24] */
8962306a36Sopenharmony_ci	u8 op_code;	/* [23:16] */
9062306a36Sopenharmony_ci	u16 reserved;	/* [15:0] */
9162306a36Sopenharmony_ci};
9262306a36Sopenharmony_ci
9362306a36Sopenharmony_ci/* MH header flags bits */
9462306a36Sopenharmony_ci#define MH_SUPDT_PRES   BIT(0)
9562306a36Sopenharmony_ci#define MH_HASH_PRES    BIT(2)
9662306a36Sopenharmony_ci#define MH_BD_PRES      BIT(3)
9762306a36Sopenharmony_ci#define MH_MFM_PRES     BIT(4)
9862306a36Sopenharmony_ci#define MH_BDESC_PRES   BIT(5)
9962306a36Sopenharmony_ci#define MH_SCTX_PRES	BIT(7)
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* SCTX word 0 bit offsets and fields masks */
10262306a36Sopenharmony_ci#define SCTX_SIZE               0x000000FF
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci/* SCTX word 1 bit shifts and field masks */
10562306a36Sopenharmony_ci#define  UPDT_OFST              0x000000FF   /* offset of SCTX updateable fld */
10662306a36Sopenharmony_ci#define  HASH_TYPE              0x00000300   /* hash alg operation type */
10762306a36Sopenharmony_ci#define  HASH_TYPE_SHIFT                 8
10862306a36Sopenharmony_ci#define  HASH_MODE              0x00001C00   /* one of spu2_hash_mode */
10962306a36Sopenharmony_ci#define  HASH_MODE_SHIFT                10
11062306a36Sopenharmony_ci#define  HASH_ALG               0x0000E000   /* hash algorithm */
11162306a36Sopenharmony_ci#define  HASH_ALG_SHIFT                 13
11262306a36Sopenharmony_ci#define  CIPHER_TYPE            0x00030000   /* encryption operation type */
11362306a36Sopenharmony_ci#define  CIPHER_TYPE_SHIFT              16
11462306a36Sopenharmony_ci#define  CIPHER_MODE            0x001C0000   /* encryption mode */
11562306a36Sopenharmony_ci#define  CIPHER_MODE_SHIFT              18
11662306a36Sopenharmony_ci#define  CIPHER_ALG             0x00E00000   /* encryption algo */
11762306a36Sopenharmony_ci#define  CIPHER_ALG_SHIFT               21
11862306a36Sopenharmony_ci#define  ICV_IS_512                BIT(27)
11962306a36Sopenharmony_ci#define  ICV_IS_512_SHIFT		27
12062306a36Sopenharmony_ci#define  CIPHER_ORDER               BIT(30)
12162306a36Sopenharmony_ci#define  CIPHER_ORDER_SHIFT             30
12262306a36Sopenharmony_ci#define  CIPHER_INBOUND             BIT(31)
12362306a36Sopenharmony_ci#define  CIPHER_INBOUND_SHIFT           31
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ci/* SCTX word 2 bit shifts and field masks */
12662306a36Sopenharmony_ci#define  EXP_IV_SIZE                   0x7
12762306a36Sopenharmony_ci#define  IV_OFFSET                   BIT(3)
12862306a36Sopenharmony_ci#define  IV_OFFSET_SHIFT                 3
12962306a36Sopenharmony_ci#define  GEN_IV                      BIT(5)
13062306a36Sopenharmony_ci#define  GEN_IV_SHIFT                    5
13162306a36Sopenharmony_ci#define  EXPLICIT_IV                 BIT(6)
13262306a36Sopenharmony_ci#define  EXPLICIT_IV_SHIFT               6
13362306a36Sopenharmony_ci#define  SCTX_IV                     BIT(7)
13462306a36Sopenharmony_ci#define  SCTX_IV_SHIFT                   7
13562306a36Sopenharmony_ci#define  ICV_SIZE                   0x0F00
13662306a36Sopenharmony_ci#define  ICV_SIZE_SHIFT                  8
13762306a36Sopenharmony_ci#define  CHECK_ICV                  BIT(12)
13862306a36Sopenharmony_ci#define  CHECK_ICV_SHIFT                12
13962306a36Sopenharmony_ci#define  INSERT_ICV                 BIT(13)
14062306a36Sopenharmony_ci#define  INSERT_ICV_SHIFT               13
14162306a36Sopenharmony_ci#define  BD_SUPPRESS                BIT(19)
14262306a36Sopenharmony_ci#define  BD_SUPPRESS_SHIFT              19
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci/* Generic Mode Security Context Structure [SCTX] */
14562306a36Sopenharmony_cistruct SCTX {
14662306a36Sopenharmony_ci/* word 0: protocol flags */
14762306a36Sopenharmony_ci	__be32 proto_flags;
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci/* word 1: cipher flags */
15062306a36Sopenharmony_ci	__be32 cipher_flags;
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/* word 2: Extended cipher flags */
15362306a36Sopenharmony_ci	__be32 ecf;
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci};
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_cistruct SPUHEADER {
15862306a36Sopenharmony_ci	struct MHEADER mh;
15962306a36Sopenharmony_ci	u32 emh;
16062306a36Sopenharmony_ci	struct SCTX sa;
16162306a36Sopenharmony_ci};
16262306a36Sopenharmony_ci
16362306a36Sopenharmony_ci#endif /* _SPUM_H_ */
164