18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright 2016 Broadcom 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci/* 78c2ecf20Sopenharmony_ci * This file contains SPU message definitions specific to SPU-M. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _SPUM_H_ 118c2ecf20Sopenharmony_ci#define _SPUM_H_ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define SPU_CRYPTO_OPERATION_GENERIC 0x1 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* Length of STATUS field in tx and rx packets */ 168c2ecf20Sopenharmony_ci#define SPU_TX_STATUS_LEN 4 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci/* SPU-M error codes */ 198c2ecf20Sopenharmony_ci#define SPU_STATUS_MASK 0x0000FF00 208c2ecf20Sopenharmony_ci#define SPU_STATUS_SUCCESS 0x00000000 218c2ecf20Sopenharmony_ci#define SPU_STATUS_INVALID_ICV 0x00000100 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci#define SPU_STATUS_ERROR_FLAG 0x00020000 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_ci/* Request message. MH + EMH + BDESC + BD header */ 268c2ecf20Sopenharmony_ci#define SPU_REQ_FIXED_LEN 24 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci/* 298c2ecf20Sopenharmony_ci * Max length of a SPU message header. Used to allocate a buffer where 308c2ecf20Sopenharmony_ci * the SPU message header is constructed. Can be used for either a SPU-M 318c2ecf20Sopenharmony_ci * header or a SPU2 header. 328c2ecf20Sopenharmony_ci * For SPU-M, sum of the following: 338c2ecf20Sopenharmony_ci * MH - 4 bytes 348c2ecf20Sopenharmony_ci * EMH - 4 358c2ecf20Sopenharmony_ci * SCTX - 3 + 368c2ecf20Sopenharmony_ci * max auth key len - 64 378c2ecf20Sopenharmony_ci * max cipher key len - 264 (RC4) 388c2ecf20Sopenharmony_ci * max IV len - 16 398c2ecf20Sopenharmony_ci * BDESC - 12 408c2ecf20Sopenharmony_ci * BD header - 4 418c2ecf20Sopenharmony_ci * Total: 371 428c2ecf20Sopenharmony_ci * 438c2ecf20Sopenharmony_ci * For SPU2, FMD_SIZE (32) plus lengths of hash and cipher keys, 448c2ecf20Sopenharmony_ci * hash and cipher IVs. If SPU2 does not support RC4, then 458c2ecf20Sopenharmony_ci */ 468c2ecf20Sopenharmony_ci#define SPU_HEADER_ALLOC_LEN (SPU_REQ_FIXED_LEN + MAX_KEY_SIZE + \ 478c2ecf20Sopenharmony_ci MAX_KEY_SIZE + MAX_IV_SIZE) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* 508c2ecf20Sopenharmony_ci * Response message header length. Normally MH, EMH, BD header, but when 518c2ecf20Sopenharmony_ci * BD_SUPPRESS is used for hash requests, there is no BD header. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_ci#define SPU_RESP_HDR_LEN 12 548c2ecf20Sopenharmony_ci#define SPU_HASH_RESP_HDR_LEN 8 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci/* 578c2ecf20Sopenharmony_ci * Max value that can be represented in the Payload Length field of the BD 588c2ecf20Sopenharmony_ci * header. This is a 16-bit field. 598c2ecf20Sopenharmony_ci */ 608c2ecf20Sopenharmony_ci#define SPUM_NS2_MAX_PAYLOAD (BIT(16) - 1) 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ci/* 638c2ecf20Sopenharmony_ci * NSP SPU is limited to ~9KB because of FA2 FIFO size limitations; 648c2ecf20Sopenharmony_ci * Set MAX_PAYLOAD to 8k to allow for addition of header, digest, etc. 658c2ecf20Sopenharmony_ci * and stay within limitation. 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci#define SPUM_NSP_MAX_PAYLOAD 8192 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* Buffer Descriptor Header [BDESC]. SPU in big-endian mode. */ 718c2ecf20Sopenharmony_cistruct BDESC_HEADER { 728c2ecf20Sopenharmony_ci u16 offset_mac; /* word 0 [31-16] */ 738c2ecf20Sopenharmony_ci u16 length_mac; /* word 0 [15-0] */ 748c2ecf20Sopenharmony_ci u16 offset_crypto; /* word 1 [31-16] */ 758c2ecf20Sopenharmony_ci u16 length_crypto; /* word 1 [15-0] */ 768c2ecf20Sopenharmony_ci u16 offset_icv; /* word 2 [31-16] */ 778c2ecf20Sopenharmony_ci u16 offset_iv; /* word 2 [15-0] */ 788c2ecf20Sopenharmony_ci}; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci/* Buffer Data Header [BD]. SPU in big-endian mode. */ 818c2ecf20Sopenharmony_cistruct BD_HEADER { 828c2ecf20Sopenharmony_ci u16 size; 838c2ecf20Sopenharmony_ci u16 prev_length; 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci/* Command Context Header. SPU-M in big endian mode. */ 878c2ecf20Sopenharmony_cistruct MHEADER { 888c2ecf20Sopenharmony_ci u8 flags; /* [31:24] */ 898c2ecf20Sopenharmony_ci u8 op_code; /* [23:16] */ 908c2ecf20Sopenharmony_ci u16 reserved; /* [15:0] */ 918c2ecf20Sopenharmony_ci}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_ci/* MH header flags bits */ 948c2ecf20Sopenharmony_ci#define MH_SUPDT_PRES BIT(0) 958c2ecf20Sopenharmony_ci#define MH_HASH_PRES BIT(2) 968c2ecf20Sopenharmony_ci#define MH_BD_PRES BIT(3) 978c2ecf20Sopenharmony_ci#define MH_MFM_PRES BIT(4) 988c2ecf20Sopenharmony_ci#define MH_BDESC_PRES BIT(5) 998c2ecf20Sopenharmony_ci#define MH_SCTX_PRES BIT(7) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* SCTX word 0 bit offsets and fields masks */ 1028c2ecf20Sopenharmony_ci#define SCTX_SIZE 0x000000FF 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* SCTX word 1 bit shifts and field masks */ 1058c2ecf20Sopenharmony_ci#define UPDT_OFST 0x000000FF /* offset of SCTX updateable fld */ 1068c2ecf20Sopenharmony_ci#define HASH_TYPE 0x00000300 /* hash alg operation type */ 1078c2ecf20Sopenharmony_ci#define HASH_TYPE_SHIFT 8 1088c2ecf20Sopenharmony_ci#define HASH_MODE 0x00001C00 /* one of spu2_hash_mode */ 1098c2ecf20Sopenharmony_ci#define HASH_MODE_SHIFT 10 1108c2ecf20Sopenharmony_ci#define HASH_ALG 0x0000E000 /* hash algorithm */ 1118c2ecf20Sopenharmony_ci#define HASH_ALG_SHIFT 13 1128c2ecf20Sopenharmony_ci#define CIPHER_TYPE 0x00030000 /* encryption operation type */ 1138c2ecf20Sopenharmony_ci#define CIPHER_TYPE_SHIFT 16 1148c2ecf20Sopenharmony_ci#define CIPHER_MODE 0x001C0000 /* encryption mode */ 1158c2ecf20Sopenharmony_ci#define CIPHER_MODE_SHIFT 18 1168c2ecf20Sopenharmony_ci#define CIPHER_ALG 0x00E00000 /* encryption algo */ 1178c2ecf20Sopenharmony_ci#define CIPHER_ALG_SHIFT 21 1188c2ecf20Sopenharmony_ci#define ICV_IS_512 BIT(27) 1198c2ecf20Sopenharmony_ci#define ICV_IS_512_SHIFT 27 1208c2ecf20Sopenharmony_ci#define CIPHER_ORDER BIT(30) 1218c2ecf20Sopenharmony_ci#define CIPHER_ORDER_SHIFT 30 1228c2ecf20Sopenharmony_ci#define CIPHER_INBOUND BIT(31) 1238c2ecf20Sopenharmony_ci#define CIPHER_INBOUND_SHIFT 31 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci/* SCTX word 2 bit shifts and field masks */ 1268c2ecf20Sopenharmony_ci#define EXP_IV_SIZE 0x7 1278c2ecf20Sopenharmony_ci#define IV_OFFSET BIT(3) 1288c2ecf20Sopenharmony_ci#define IV_OFFSET_SHIFT 3 1298c2ecf20Sopenharmony_ci#define GEN_IV BIT(5) 1308c2ecf20Sopenharmony_ci#define GEN_IV_SHIFT 5 1318c2ecf20Sopenharmony_ci#define EXPLICIT_IV BIT(6) 1328c2ecf20Sopenharmony_ci#define EXPLICIT_IV_SHIFT 6 1338c2ecf20Sopenharmony_ci#define SCTX_IV BIT(7) 1348c2ecf20Sopenharmony_ci#define SCTX_IV_SHIFT 7 1358c2ecf20Sopenharmony_ci#define ICV_SIZE 0x0F00 1368c2ecf20Sopenharmony_ci#define ICV_SIZE_SHIFT 8 1378c2ecf20Sopenharmony_ci#define CHECK_ICV BIT(12) 1388c2ecf20Sopenharmony_ci#define CHECK_ICV_SHIFT 12 1398c2ecf20Sopenharmony_ci#define INSERT_ICV BIT(13) 1408c2ecf20Sopenharmony_ci#define INSERT_ICV_SHIFT 13 1418c2ecf20Sopenharmony_ci#define BD_SUPPRESS BIT(19) 1428c2ecf20Sopenharmony_ci#define BD_SUPPRESS_SHIFT 19 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci/* Generic Mode Security Context Structure [SCTX] */ 1458c2ecf20Sopenharmony_cistruct SCTX { 1468c2ecf20Sopenharmony_ci/* word 0: protocol flags */ 1478c2ecf20Sopenharmony_ci u32 proto_flags; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_ci/* word 1: cipher flags */ 1508c2ecf20Sopenharmony_ci u32 cipher_flags; 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci/* word 2: Extended cipher flags */ 1538c2ecf20Sopenharmony_ci u32 ecf; 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci}; 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_cistruct SPUHEADER { 1588c2ecf20Sopenharmony_ci struct MHEADER mh; 1598c2ecf20Sopenharmony_ci u32 emh; 1608c2ecf20Sopenharmony_ci struct SCTX sa; 1618c2ecf20Sopenharmony_ci}; 1628c2ecf20Sopenharmony_ci 1638c2ecf20Sopenharmony_ci#endif /* _SPUM_H_ */ 164