blob: 87040df06564ec1261cc5edc5b0e3cfc9b729f65 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001#ifndef __QCEDEV__H
2#define __QCEDEV__H
3
4#include <linux/types.h>
5#include <linux/ioctl.h>
6
7#define QCEDEV_MAX_SHA_BLOCK_SIZE 64
8#define QCEDEV_MAX_BEARER 31
9#define QCEDEV_MAX_KEY_SIZE 64
10#define QCEDEV_MAX_IV_SIZE 32
11
12#define QCEDEV_MAX_BUFFERS 16
13#define QCEDEV_MAX_SHA_DIGEST 32
14
15#define QCEDEV_USE_PMEM 1
16#define QCEDEV_NO_PMEM 0
17
18#define QCEDEV_AES_KEY_128 16
19#define QCEDEV_AES_KEY_192 24
20#define QCEDEV_AES_KEY_256 32
21/**
22*qcedev_oper_enum: Operation types
23* @QCEDEV_OPER_ENC: Encrypt
24* @QCEDEV_OPER_DEC: Decrypt
25* @QCEDEV_OPER_ENC_NO_KEY: Encrypt. Do not need key to be specified by
26* user. Key already set by an external processor.
27* @QCEDEV_OPER_DEC_NO_KEY: Decrypt. Do not need the key to be specified by
28* user. Key already set by an external processor.
29*/
30enum qcedev_oper_enum {
Mona Hossain5c8ea1f2011-07-28 15:11:29 -070031 QCEDEV_OPER_DEC = 0,
32 QCEDEV_OPER_ENC = 1,
33 QCEDEV_OPER_DEC_NO_KEY = 2,
34 QCEDEV_OPER_ENC_NO_KEY = 3,
35 QCEDEV_OPER_LAST
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036};
37
38/**
39*qcedev_oper_enum: Cipher algorithm types
40* @QCEDEV_ALG_DES: DES
41* @QCEDEV_ALG_3DES: 3DES
42* @QCEDEV_ALG_AES: AES
43*/
44enum qcedev_cipher_alg_enum {
45 QCEDEV_ALG_DES = 0,
46 QCEDEV_ALG_3DES = 1,
47 QCEDEV_ALG_AES = 2,
48 QCEDEV_ALG_LAST
49};
50
51/**
52*qcedev_cipher_mode_enum : AES mode
53* @QCEDEV_AES_MODE_CBC: CBC
54* @QCEDEV_AES_MODE_ECB: ECB
55* @QCEDEV_AES_MODE_CTR: CTR
56* @QCEDEV_AES_MODE_XTS: XTS
57* @QCEDEV_AES_MODE_CCM: CCM
58* @QCEDEV_DES_MODE_CBC: CBC
59* @QCEDEV_DES_MODE_ECB: ECB
60*/
61enum qcedev_cipher_mode_enum {
62 QCEDEV_AES_MODE_CBC = 0,
63 QCEDEV_AES_MODE_ECB = 1,
64 QCEDEV_AES_MODE_CTR = 2,
65 QCEDEV_AES_MODE_XTS = 3,
66 QCEDEV_AES_MODE_CCM = 4,
67 QCEDEV_DES_MODE_CBC = 5,
68 QCEDEV_DES_MODE_ECB = 6,
69 QCEDEV_AES_DES_MODE_LAST
70};
71
72/**
73*enum qcedev_sha_alg_enum : Secure Hashing Algorithm
74* @QCEDEV_ALG_SHA1: Digest returned: 20 bytes (160 bits)
75* @QCEDEV_ALG_SHA256: Digest returned: 32 bytes (256 bit)
76* @QCEDEV_ALG_SHA1_HMAC: HMAC returned 20 bytes (160 bits)
77* @QCEDEV_ALG_SHA256_HMAC: HMAC returned 32 bytes (256 bit)
78* @QCEDEV_ALG_AES_CMAC: Configurable MAC size
79*/
80enum qcedev_sha_alg_enum {
81 QCEDEV_ALG_SHA1 = 0,
82 QCEDEV_ALG_SHA256 = 1,
83 QCEDEV_ALG_SHA1_HMAC = 2,
84 QCEDEV_ALG_SHA256_HMAC = 3,
85 QCEDEV_ALG_AES_CMAC = 4,
86 QCEDEV_ALG_SHA_ALG_LAST
87};
88
89/**
90* struct buf_info - Buffer information
91* @offset: Offset from the base address of the buffer
92* (Used when buffer is allocated using PMEM)
93* @vaddr: Virtual buffer address pointer
94* @len: Size of the buffer
95*/
96struct buf_info {
Mona Hossain5c8ea1f2011-07-28 15:11:29 -070097 union {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070098 uint32_t offset;
99 uint8_t *vaddr;
100 };
101 uint32_t len;
102};
103
104/**
105* struct qcedev_vbuf_info - Source and destination Buffer information
106* @src: Array of buf_info for input/source
107* @dst: Array of buf_info for output/destination
108*/
109struct qcedev_vbuf_info {
110 struct buf_info src[QCEDEV_MAX_BUFFERS];
111 struct buf_info dst[QCEDEV_MAX_BUFFERS];
112};
113
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114/**
115* struct qcedev_pmem_info - Stores PMEM buffer information
116* @fd_src: Handle to /dev/adsp_pmem used to allocate
117* memory for input/src buffer
118* @src: Array of buf_info for input/source
119* @fd_dst: Handle to /dev/adsp_pmem used to allocate
120* memory for output/dst buffer
121* @dst: Array of buf_info for output/destination
122* @pmem_src_offset: The offset from input/src buffer
123* (allocated by PMEM)
124*/
Mona Hossain5c8ea1f2011-07-28 15:11:29 -0700125struct qcedev_pmem_info {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126 int fd_src;
127 struct buf_info src[QCEDEV_MAX_BUFFERS];
128 int fd_dst;
129 struct buf_info dst[QCEDEV_MAX_BUFFERS];
130};
131
132/**
133* struct qcedev_cipher_op_req - Holds the ciphering request information
134* @use_pmem (IN): Flag to indicate if buffer source is PMEM
135* QCEDEV_USE_PMEM/QCEDEV_NO_PMEM
136* @pmem (IN): Stores PMEM buffer information.
137* Refer struct qcedev_pmem_info
138* @vbuf (IN/OUT): Stores Source and destination Buffer information
139* Refer to struct qcedev_vbuf_info
140* @data_len (IN): Total Length of input/src and output/dst in bytes
141* @in_place_op (IN): Indicates whether the operation is inplace where
142* source == destination
143* When using PMEM allocated memory, must set this to 1
144* @enckey (IN): 128 bits of confidentiality key
145* enckey[0] bit 127-120, enckey[1] bit 119-112,..
146* enckey[15] bit 7-0
147* @encklen (IN): Length of the encryption key(set to 128 bits/16
148* bytes in the driver)
149* @iv (IN/OUT): Initialisation vector data
150* This is updated by the driver, incremented by
151* number of blocks encrypted/decrypted.
152* @ivlen (IN): Length of the IV
153* @byteoffset (IN): Offset in the Cipher BLOCK (applicable and to be set
154* for AES-128 CTR mode only)
155* @alg (IN): Type of ciphering algorithm: AES/DES/3DES
156* @mode (IN): Mode use when using AES algorithm: ECB/CBC/CTR
157* Apllicabel when using AES algorithm only
158* @op (IN): Type of operation: QCEDEV_OPER_DEC/QCEDEV_OPER_ENC or
159* QCEDEV_OPER_ENC_NO_KEY/QCEDEV_OPER_DEC_NO_KEY
160*
161*If use_pmem is set to 0, the driver assumes that memory was not allocated
162* via PMEM, and kernel will need to allocate memory and copy data from user
163* space buffer (data_src/dta_dst) and process accordingly and copy data back
164* to the user space buffer
165*
166* If use_pmem is set to 1, the driver assumes that memory was allocated via
167* PMEM.
168* The kernel driver will use the fd_src to determine the kernel virtual address
169* base that maps to the user space virtual address base for the buffer
170* allocated in user space.
171* The final input/src and output/dst buffer pointer will be determined
172* by adding the offsets to the kernel virtual addr.
173*
174* If use of hardware key is supported in the target, user can configure the
175* key paramters (encklen, enckey) to use the hardware key.
176* In order to use the hardware key, set encklen to 0 and set the enckey
177* data array to 0.
178*/
179struct qcedev_cipher_op_req {
180 uint8_t use_pmem;
Mona Hossain5c8ea1f2011-07-28 15:11:29 -0700181 union {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700182 struct qcedev_pmem_info pmem;
183 struct qcedev_vbuf_info vbuf;
184 };
185 uint32_t entries;
186 uint32_t data_len;
187 uint8_t in_place_op;
188 uint8_t enckey[QCEDEV_MAX_KEY_SIZE];
189 uint32_t encklen;
190 uint8_t iv[QCEDEV_MAX_IV_SIZE];
191 uint32_t ivlen;
192 uint32_t byteoffset;
193 enum qcedev_cipher_alg_enum alg;
194 enum qcedev_cipher_mode_enum mode;
195 enum qcedev_oper_enum op;
196};
197
198/**
199* struct qcedev_sha_op_req - Holds the hashing request information
200* @data (IN): Array of pointers to the data to be hashed
201* @entries (IN): Number of buf_info entries in the data array
202* @data_len (IN): Length of data to be hashed
203* @digest (IN/OUT): Returns the hashed data information
204* @diglen (OUT): Size of the hashed/digest data
205* @authkey (IN): Pointer to authentication key for HMAC
206* @authklen (IN): Size of the authentication key
207* @alg (IN): Secure Hash algorithm
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700208*/
209struct qcedev_sha_op_req {
210 struct buf_info data[QCEDEV_MAX_BUFFERS];
211 uint32_t entries;
212 uint32_t data_len;
213 uint8_t digest[QCEDEV_MAX_SHA_DIGEST];
214 uint32_t diglen;
215 uint8_t *authkey;
216 uint32_t authklen;
217 enum qcedev_sha_alg_enum alg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700218};
219
220
221#define QCEDEV_IOC_MAGIC 0x87
222
223#define QCEDEV_IOCTL_ENC_REQ \
224 _IOWR(QCEDEV_IOC_MAGIC, 1, struct qcedev_cipher_op_req)
225#define QCEDEV_IOCTL_DEC_REQ \
226 _IOWR(QCEDEV_IOC_MAGIC, 2, struct qcedev_cipher_op_req)
227#define QCEDEV_IOCTL_SHA_INIT_REQ \
228 _IOWR(QCEDEV_IOC_MAGIC, 3, struct qcedev_sha_op_req)
229#define QCEDEV_IOCTL_SHA_UPDATE_REQ \
230 _IOWR(QCEDEV_IOC_MAGIC, 4, struct qcedev_sha_op_req)
231#define QCEDEV_IOCTL_SHA_FINAL_REQ \
232 _IOWR(QCEDEV_IOC_MAGIC, 5, struct qcedev_sha_op_req)
233#define QCEDEV_IOCTL_GET_SHA_REQ \
234 _IOWR(QCEDEV_IOC_MAGIC, 6, struct qcedev_sha_op_req)
235#define QCEDEV_IOCTL_LOCK_CE \
236 _IO(QCEDEV_IOC_MAGIC, 7)
237#define QCEDEV_IOCTL_UNLOCK_CE \
238 _IO(QCEDEV_IOC_MAGIC, 8)
239#define QCEDEV_IOCTL_GET_CMAC_REQ \
240 _IOWR(QCEDEV_IOC_MAGIC, 9, struct qcedev_cipher_op_req)
241#endif /* _QCEDEV__H */