Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright 2016 Broadcom
0004  */
0005 
0006 /*
0007  * This file contains SPU message definitions specific to SPU-M.
0008  */
0009 
0010 #ifndef _SPUM_H_
0011 #define _SPUM_H_
0012 
0013 #define SPU_CRYPTO_OPERATION_GENERIC    0x1
0014 
0015 /* Length of STATUS field in tx and rx packets */
0016 #define SPU_TX_STATUS_LEN  4
0017 
0018 /* SPU-M error codes */
0019 #define SPU_STATUS_MASK                 0x0000FF00
0020 #define SPU_STATUS_SUCCESS              0x00000000
0021 #define SPU_STATUS_INVALID_ICV          0x00000100
0022 
0023 #define SPU_STATUS_ERROR_FLAG           0x00020000
0024 
0025 /* Request message. MH + EMH + BDESC + BD header */
0026 #define SPU_REQ_FIXED_LEN 24
0027 
0028 /*
0029  * Max length of a SPU message header. Used to allocate a buffer where
0030  * the SPU message header is constructed. Can be used for either a SPU-M
0031  * header or a SPU2 header.
0032  * For SPU-M, sum of the following:
0033  *    MH - 4 bytes
0034  *    EMH - 4
0035  *    SCTX - 3 +
0036  *      max auth key len - 64
0037  *      max cipher key len - 264 (RC4)
0038  *      max IV len - 16
0039  *    BDESC - 12
0040  *    BD header - 4
0041  * Total:  371
0042  *
0043  * For SPU2, FMD_SIZE (32) plus lengths of hash and cipher keys,
0044  * hash and cipher IVs. If SPU2 does not support RC4, then
0045  */
0046 #define SPU_HEADER_ALLOC_LEN  (SPU_REQ_FIXED_LEN + MAX_KEY_SIZE + \
0047                 MAX_KEY_SIZE + MAX_IV_SIZE)
0048 
0049 /*
0050  * Response message header length. Normally MH, EMH, BD header, but when
0051  * BD_SUPPRESS is used for hash requests, there is no BD header.
0052  */
0053 #define SPU_RESP_HDR_LEN 12
0054 #define SPU_HASH_RESP_HDR_LEN 8
0055 
0056 /*
0057  * Max value that can be represented in the Payload Length field of the BD
0058  * header. This is a 16-bit field.
0059  */
0060 #define SPUM_NS2_MAX_PAYLOAD  (BIT(16) - 1)
0061 
0062 /*
0063  * NSP SPU is limited to ~9KB because of FA2 FIFO size limitations;
0064  * Set MAX_PAYLOAD to 8k to allow for addition of header, digest, etc.
0065  * and stay within limitation.
0066  */
0067 
0068 #define SPUM_NSP_MAX_PAYLOAD    8192
0069 
0070 /* Buffer Descriptor Header [BDESC]. SPU in big-endian mode. */
0071 struct BDESC_HEADER {
0072     __be16 offset_mac;      /* word 0 [31-16] */
0073     __be16 length_mac;      /* word 0 [15-0]  */
0074     __be16 offset_crypto;       /* word 1 [31-16] */
0075     __be16 length_crypto;       /* word 1 [15-0]  */
0076     __be16 offset_icv;      /* word 2 [31-16] */
0077     __be16 offset_iv;       /* word 2 [15-0]  */
0078 };
0079 
0080 /* Buffer Data Header [BD]. SPU in big-endian mode. */
0081 struct BD_HEADER {
0082     __be16 size;
0083     __be16 prev_length;
0084 };
0085 
0086 /* Command Context Header. SPU-M in big endian mode. */
0087 struct MHEADER {
0088     u8 flags;   /* [31:24] */
0089     u8 op_code; /* [23:16] */
0090     u16 reserved;   /* [15:0] */
0091 };
0092 
0093 /* MH header flags bits */
0094 #define MH_SUPDT_PRES   BIT(0)
0095 #define MH_HASH_PRES    BIT(2)
0096 #define MH_BD_PRES      BIT(3)
0097 #define MH_MFM_PRES     BIT(4)
0098 #define MH_BDESC_PRES   BIT(5)
0099 #define MH_SCTX_PRES    BIT(7)
0100 
0101 /* SCTX word 0 bit offsets and fields masks */
0102 #define SCTX_SIZE               0x000000FF
0103 
0104 /* SCTX word 1 bit shifts and field masks */
0105 #define  UPDT_OFST              0x000000FF   /* offset of SCTX updateable fld */
0106 #define  HASH_TYPE              0x00000300   /* hash alg operation type */
0107 #define  HASH_TYPE_SHIFT                 8
0108 #define  HASH_MODE              0x00001C00   /* one of spu2_hash_mode */
0109 #define  HASH_MODE_SHIFT                10
0110 #define  HASH_ALG               0x0000E000   /* hash algorithm */
0111 #define  HASH_ALG_SHIFT                 13
0112 #define  CIPHER_TYPE            0x00030000   /* encryption operation type */
0113 #define  CIPHER_TYPE_SHIFT              16
0114 #define  CIPHER_MODE            0x001C0000   /* encryption mode */
0115 #define  CIPHER_MODE_SHIFT              18
0116 #define  CIPHER_ALG             0x00E00000   /* encryption algo */
0117 #define  CIPHER_ALG_SHIFT               21
0118 #define  ICV_IS_512                BIT(27)
0119 #define  ICV_IS_512_SHIFT       27
0120 #define  CIPHER_ORDER               BIT(30)
0121 #define  CIPHER_ORDER_SHIFT             30
0122 #define  CIPHER_INBOUND             BIT(31)
0123 #define  CIPHER_INBOUND_SHIFT           31
0124 
0125 /* SCTX word 2 bit shifts and field masks */
0126 #define  EXP_IV_SIZE                   0x7
0127 #define  IV_OFFSET                   BIT(3)
0128 #define  IV_OFFSET_SHIFT                 3
0129 #define  GEN_IV                      BIT(5)
0130 #define  GEN_IV_SHIFT                    5
0131 #define  EXPLICIT_IV                 BIT(6)
0132 #define  EXPLICIT_IV_SHIFT               6
0133 #define  SCTX_IV                     BIT(7)
0134 #define  SCTX_IV_SHIFT                   7
0135 #define  ICV_SIZE                   0x0F00
0136 #define  ICV_SIZE_SHIFT                  8
0137 #define  CHECK_ICV                  BIT(12)
0138 #define  CHECK_ICV_SHIFT                12
0139 #define  INSERT_ICV                 BIT(13)
0140 #define  INSERT_ICV_SHIFT               13
0141 #define  BD_SUPPRESS                BIT(19)
0142 #define  BD_SUPPRESS_SHIFT              19
0143 
0144 /* Generic Mode Security Context Structure [SCTX] */
0145 struct SCTX {
0146 /* word 0: protocol flags */
0147     __be32 proto_flags;
0148 
0149 /* word 1: cipher flags */
0150     __be32 cipher_flags;
0151 
0152 /* word 2: Extended cipher flags */
0153     __be32 ecf;
0154 
0155 };
0156 
0157 struct SPUHEADER {
0158     struct MHEADER mh;
0159     u32 emh;
0160     struct SCTX sa;
0161 };
0162 
0163 #endif /* _SPUM_H_ */