1b0200065SNishad Kamdar /* SPDX-License-Identifier: GPL-2.0 */ 25377265fSHao Fang /* Copyright (c) 2016-2017 HiSilicon Limited. */ 3915e4e84SJonathan Cameron 4915e4e84SJonathan Cameron #ifndef _SEC_DRV_H_ 5915e4e84SJonathan Cameron #define _SEC_DRV_H_ 6915e4e84SJonathan Cameron 7915e4e84SJonathan Cameron #include <crypto/algapi.h> 8915e4e84SJonathan Cameron #include <linux/kfifo.h> 9915e4e84SJonathan Cameron 10915e4e84SJonathan Cameron #define SEC_MAX_SGE_NUM 64 11915e4e84SJonathan Cameron #define SEC_HW_RING_NUM 3 12915e4e84SJonathan Cameron 13915e4e84SJonathan Cameron #define SEC_CMD_RING 0 14915e4e84SJonathan Cameron #define SEC_OUTORDER_RING 1 15915e4e84SJonathan Cameron #define SEC_DBG_RING 2 16915e4e84SJonathan Cameron 17915e4e84SJonathan Cameron /* A reasonable length to balance memory use against flexibility */ 18915e4e84SJonathan Cameron #define SEC_QUEUE_LEN 512 19915e4e84SJonathan Cameron 20915e4e84SJonathan Cameron #define SEC_MAX_SGE_NUM 64 21915e4e84SJonathan Cameron 22915e4e84SJonathan Cameron struct sec_bd_info { 23915e4e84SJonathan Cameron #define SEC_BD_W0_T_LEN_M GENMASK(4, 0) 24915e4e84SJonathan Cameron #define SEC_BD_W0_T_LEN_S 0 25915e4e84SJonathan Cameron 26915e4e84SJonathan Cameron #define SEC_BD_W0_C_WIDTH_M GENMASK(6, 5) 27915e4e84SJonathan Cameron #define SEC_BD_W0_C_WIDTH_S 5 28915e4e84SJonathan Cameron #define SEC_C_WIDTH_AES_128BIT 0 29915e4e84SJonathan Cameron #define SEC_C_WIDTH_AES_8BIT 1 30915e4e84SJonathan Cameron #define SEC_C_WIDTH_AES_1BIT 2 31915e4e84SJonathan Cameron #define SEC_C_WIDTH_DES_64BIT 0 32915e4e84SJonathan Cameron #define SEC_C_WIDTH_DES_8BIT 1 33915e4e84SJonathan Cameron #define SEC_C_WIDTH_DES_1BIT 2 34915e4e84SJonathan Cameron 35915e4e84SJonathan Cameron #define SEC_BD_W0_C_MODE_M GENMASK(9, 7) 36915e4e84SJonathan Cameron #define SEC_BD_W0_C_MODE_S 7 37915e4e84SJonathan Cameron #define SEC_C_MODE_ECB 0 38915e4e84SJonathan Cameron #define SEC_C_MODE_CBC 1 39915e4e84SJonathan Cameron #define SEC_C_MODE_CTR 4 40915e4e84SJonathan Cameron #define SEC_C_MODE_CCM 5 41915e4e84SJonathan Cameron #define SEC_C_MODE_GCM 6 42915e4e84SJonathan Cameron #define SEC_C_MODE_XTS 7 43915e4e84SJonathan Cameron 44915e4e84SJonathan Cameron #define SEC_BD_W0_SEQ BIT(10) 45915e4e84SJonathan Cameron #define SEC_BD_W0_DE BIT(11) 46915e4e84SJonathan Cameron #define SEC_BD_W0_DAT_SKIP_M GENMASK(13, 12) 47915e4e84SJonathan Cameron #define SEC_BD_W0_DAT_SKIP_S 12 48915e4e84SJonathan Cameron #define SEC_BD_W0_C_GRAN_SIZE_19_16_M GENMASK(17, 14) 49915e4e84SJonathan Cameron #define SEC_BD_W0_C_GRAN_SIZE_19_16_S 14 50915e4e84SJonathan Cameron 51915e4e84SJonathan Cameron #define SEC_BD_W0_CIPHER_M GENMASK(19, 18) 52915e4e84SJonathan Cameron #define SEC_BD_W0_CIPHER_S 18 53915e4e84SJonathan Cameron #define SEC_CIPHER_NULL 0 54915e4e84SJonathan Cameron #define SEC_CIPHER_ENCRYPT 1 55915e4e84SJonathan Cameron #define SEC_CIPHER_DECRYPT 2 56915e4e84SJonathan Cameron 57915e4e84SJonathan Cameron #define SEC_BD_W0_AUTH_M GENMASK(21, 20) 58915e4e84SJonathan Cameron #define SEC_BD_W0_AUTH_S 20 59915e4e84SJonathan Cameron #define SEC_AUTH_NULL 0 60915e4e84SJonathan Cameron #define SEC_AUTH_MAC 1 61915e4e84SJonathan Cameron #define SEC_AUTH_VERIF 2 62915e4e84SJonathan Cameron 63915e4e84SJonathan Cameron #define SEC_BD_W0_AI_GEN BIT(22) 64915e4e84SJonathan Cameron #define SEC_BD_W0_CI_GEN BIT(23) 65915e4e84SJonathan Cameron #define SEC_BD_W0_NO_HPAD BIT(24) 66915e4e84SJonathan Cameron #define SEC_BD_W0_HM_M GENMASK(26, 25) 67915e4e84SJonathan Cameron #define SEC_BD_W0_HM_S 25 68915e4e84SJonathan Cameron #define SEC_BD_W0_ICV_OR_SKEY_EN_M GENMASK(28, 27) 69915e4e84SJonathan Cameron #define SEC_BD_W0_ICV_OR_SKEY_EN_S 27 70915e4e84SJonathan Cameron 71915e4e84SJonathan Cameron /* Multi purpose field - gran size bits for send, flag for recv */ 72915e4e84SJonathan Cameron #define SEC_BD_W0_FLAG_M GENMASK(30, 29) 73915e4e84SJonathan Cameron #define SEC_BD_W0_C_GRAN_SIZE_21_20_M GENMASK(30, 29) 74915e4e84SJonathan Cameron #define SEC_BD_W0_FLAG_S 29 75915e4e84SJonathan Cameron #define SEC_BD_W0_C_GRAN_SIZE_21_20_S 29 76915e4e84SJonathan Cameron 77915e4e84SJonathan Cameron #define SEC_BD_W0_DONE BIT(31) 78915e4e84SJonathan Cameron u32 w0; 79915e4e84SJonathan Cameron 80915e4e84SJonathan Cameron #define SEC_BD_W1_AUTH_GRAN_SIZE_M GENMASK(21, 0) 81915e4e84SJonathan Cameron #define SEC_BD_W1_AUTH_GRAN_SIZE_S 0 82915e4e84SJonathan Cameron #define SEC_BD_W1_M_KEY_EN BIT(22) 83915e4e84SJonathan Cameron #define SEC_BD_W1_BD_INVALID BIT(23) 84915e4e84SJonathan Cameron #define SEC_BD_W1_ADDR_TYPE BIT(24) 85915e4e84SJonathan Cameron 86915e4e84SJonathan Cameron #define SEC_BD_W1_A_ALG_M GENMASK(28, 25) 87915e4e84SJonathan Cameron #define SEC_BD_W1_A_ALG_S 25 88915e4e84SJonathan Cameron #define SEC_A_ALG_SHA1 0 89915e4e84SJonathan Cameron #define SEC_A_ALG_SHA256 1 90915e4e84SJonathan Cameron #define SEC_A_ALG_MD5 2 91915e4e84SJonathan Cameron #define SEC_A_ALG_SHA224 3 92915e4e84SJonathan Cameron #define SEC_A_ALG_HMAC_SHA1 8 93915e4e84SJonathan Cameron #define SEC_A_ALG_HMAC_SHA224 10 94915e4e84SJonathan Cameron #define SEC_A_ALG_HMAC_SHA256 11 95915e4e84SJonathan Cameron #define SEC_A_ALG_HMAC_MD5 12 96915e4e84SJonathan Cameron #define SEC_A_ALG_AES_XCBC 13 97915e4e84SJonathan Cameron #define SEC_A_ALG_AES_CMAC 14 98915e4e84SJonathan Cameron 99915e4e84SJonathan Cameron #define SEC_BD_W1_C_ALG_M GENMASK(31, 29) 100915e4e84SJonathan Cameron #define SEC_BD_W1_C_ALG_S 29 101915e4e84SJonathan Cameron #define SEC_C_ALG_DES 0 102915e4e84SJonathan Cameron #define SEC_C_ALG_3DES 1 103915e4e84SJonathan Cameron #define SEC_C_ALG_AES 2 104915e4e84SJonathan Cameron 105915e4e84SJonathan Cameron u32 w1; 106915e4e84SJonathan Cameron 107915e4e84SJonathan Cameron #define SEC_BD_W2_C_GRAN_SIZE_15_0_M GENMASK(15, 0) 108915e4e84SJonathan Cameron #define SEC_BD_W2_C_GRAN_SIZE_15_0_S 0 109915e4e84SJonathan Cameron #define SEC_BD_W2_GRAN_NUM_M GENMASK(31, 16) 110915e4e84SJonathan Cameron #define SEC_BD_W2_GRAN_NUM_S 16 111915e4e84SJonathan Cameron u32 w2; 112915e4e84SJonathan Cameron 113915e4e84SJonathan Cameron #define SEC_BD_W3_AUTH_LEN_OFFSET_M GENMASK(9, 0) 114915e4e84SJonathan Cameron #define SEC_BD_W3_AUTH_LEN_OFFSET_S 0 115915e4e84SJonathan Cameron #define SEC_BD_W3_CIPHER_LEN_OFFSET_M GENMASK(19, 10) 116915e4e84SJonathan Cameron #define SEC_BD_W3_CIPHER_LEN_OFFSET_S 10 117915e4e84SJonathan Cameron #define SEC_BD_W3_MAC_LEN_M GENMASK(24, 20) 118915e4e84SJonathan Cameron #define SEC_BD_W3_MAC_LEN_S 20 119915e4e84SJonathan Cameron #define SEC_BD_W3_A_KEY_LEN_M GENMASK(29, 25) 120915e4e84SJonathan Cameron #define SEC_BD_W3_A_KEY_LEN_S 25 121915e4e84SJonathan Cameron #define SEC_BD_W3_C_KEY_LEN_M GENMASK(31, 30) 122915e4e84SJonathan Cameron #define SEC_BD_W3_C_KEY_LEN_S 30 123915e4e84SJonathan Cameron #define SEC_KEY_LEN_AES_128 0 124915e4e84SJonathan Cameron #define SEC_KEY_LEN_AES_192 1 125915e4e84SJonathan Cameron #define SEC_KEY_LEN_AES_256 2 126915e4e84SJonathan Cameron #define SEC_KEY_LEN_DES 1 127915e4e84SJonathan Cameron #define SEC_KEY_LEN_3DES_3_KEY 1 128915e4e84SJonathan Cameron #define SEC_KEY_LEN_3DES_2_KEY 3 129915e4e84SJonathan Cameron u32 w3; 130915e4e84SJonathan Cameron 131915e4e84SJonathan Cameron /* W4,5 */ 132915e4e84SJonathan Cameron union { 133915e4e84SJonathan Cameron u32 authkey_addr_lo; 134915e4e84SJonathan Cameron u32 authiv_addr_lo; 135915e4e84SJonathan Cameron }; 136915e4e84SJonathan Cameron union { 137915e4e84SJonathan Cameron u32 authkey_addr_hi; 138915e4e84SJonathan Cameron u32 authiv_addr_hi; 139915e4e84SJonathan Cameron }; 140915e4e84SJonathan Cameron 141915e4e84SJonathan Cameron /* W6,7 */ 142915e4e84SJonathan Cameron u32 cipher_key_addr_lo; 143915e4e84SJonathan Cameron u32 cipher_key_addr_hi; 144915e4e84SJonathan Cameron 145915e4e84SJonathan Cameron /* W8,9 */ 146915e4e84SJonathan Cameron u32 cipher_iv_addr_lo; 147915e4e84SJonathan Cameron u32 cipher_iv_addr_hi; 148915e4e84SJonathan Cameron 149915e4e84SJonathan Cameron /* W10,11 */ 150915e4e84SJonathan Cameron u32 data_addr_lo; 151915e4e84SJonathan Cameron u32 data_addr_hi; 152915e4e84SJonathan Cameron 153915e4e84SJonathan Cameron /* W12,13 */ 154915e4e84SJonathan Cameron u32 mac_addr_lo; 155915e4e84SJonathan Cameron u32 mac_addr_hi; 156915e4e84SJonathan Cameron 157915e4e84SJonathan Cameron /* W14,15 */ 158915e4e84SJonathan Cameron u32 cipher_destin_addr_lo; 159915e4e84SJonathan Cameron u32 cipher_destin_addr_hi; 160915e4e84SJonathan Cameron }; 161915e4e84SJonathan Cameron 162915e4e84SJonathan Cameron enum sec_mem_region { 163915e4e84SJonathan Cameron SEC_COMMON = 0, 164915e4e84SJonathan Cameron SEC_SAA, 165915e4e84SJonathan Cameron SEC_NUM_ADDR_REGIONS 166915e4e84SJonathan Cameron }; 167915e4e84SJonathan Cameron 168915e4e84SJonathan Cameron #define SEC_NAME_SIZE 64 169915e4e84SJonathan Cameron #define SEC_Q_NUM 16 170915e4e84SJonathan Cameron 171915e4e84SJonathan Cameron 172915e4e84SJonathan Cameron /** 173915e4e84SJonathan Cameron * struct sec_queue_ring_cmd - store information about a SEC HW cmd ring 174915e4e84SJonathan Cameron * @used: Local counter used to cheaply establish if the ring is empty. 175915e4e84SJonathan Cameron * @lock: Protect against simultaneous adjusting of the read and write pointers. 176915e4e84SJonathan Cameron * @vaddr: Virtual address for the ram pages used for the ring. 177915e4e84SJonathan Cameron * @paddr: Physical address of the dma mapped region of ram used for the ring. 178915e4e84SJonathan Cameron * @callback: Callback function called on a ring element completing. 179915e4e84SJonathan Cameron */ 180915e4e84SJonathan Cameron struct sec_queue_ring_cmd { 181915e4e84SJonathan Cameron atomic_t used; 182915e4e84SJonathan Cameron struct mutex lock; 183915e4e84SJonathan Cameron struct sec_bd_info *vaddr; 184915e4e84SJonathan Cameron dma_addr_t paddr; 185915e4e84SJonathan Cameron void (*callback)(struct sec_bd_info *resp, void *ctx); 186915e4e84SJonathan Cameron }; 187915e4e84SJonathan Cameron 188915e4e84SJonathan Cameron struct sec_debug_bd_info; 189915e4e84SJonathan Cameron struct sec_queue_ring_db { 190915e4e84SJonathan Cameron struct sec_debug_bd_info *vaddr; 191915e4e84SJonathan Cameron dma_addr_t paddr; 192915e4e84SJonathan Cameron }; 193915e4e84SJonathan Cameron 194915e4e84SJonathan Cameron struct sec_out_bd_info; 195915e4e84SJonathan Cameron struct sec_queue_ring_cq { 196915e4e84SJonathan Cameron struct sec_out_bd_info *vaddr; 197915e4e84SJonathan Cameron dma_addr_t paddr; 198915e4e84SJonathan Cameron }; 199915e4e84SJonathan Cameron 200915e4e84SJonathan Cameron struct sec_dev_info; 201915e4e84SJonathan Cameron 202915e4e84SJonathan Cameron enum sec_cipher_alg { 203915e4e84SJonathan Cameron SEC_C_DES_ECB_64, 204915e4e84SJonathan Cameron SEC_C_DES_CBC_64, 205915e4e84SJonathan Cameron 206915e4e84SJonathan Cameron SEC_C_3DES_ECB_192_3KEY, 207915e4e84SJonathan Cameron SEC_C_3DES_ECB_192_2KEY, 208915e4e84SJonathan Cameron 209915e4e84SJonathan Cameron SEC_C_3DES_CBC_192_3KEY, 210915e4e84SJonathan Cameron SEC_C_3DES_CBC_192_2KEY, 211915e4e84SJonathan Cameron 212915e4e84SJonathan Cameron SEC_C_AES_ECB_128, 213915e4e84SJonathan Cameron SEC_C_AES_ECB_192, 214915e4e84SJonathan Cameron SEC_C_AES_ECB_256, 215915e4e84SJonathan Cameron 216915e4e84SJonathan Cameron SEC_C_AES_CBC_128, 217915e4e84SJonathan Cameron SEC_C_AES_CBC_192, 218915e4e84SJonathan Cameron SEC_C_AES_CBC_256, 219915e4e84SJonathan Cameron 220915e4e84SJonathan Cameron SEC_C_AES_CTR_128, 221915e4e84SJonathan Cameron SEC_C_AES_CTR_192, 222915e4e84SJonathan Cameron SEC_C_AES_CTR_256, 223915e4e84SJonathan Cameron 224915e4e84SJonathan Cameron SEC_C_AES_XTS_128, 225915e4e84SJonathan Cameron SEC_C_AES_XTS_256, 226915e4e84SJonathan Cameron 227915e4e84SJonathan Cameron SEC_C_NULL, 228915e4e84SJonathan Cameron }; 229915e4e84SJonathan Cameron 230915e4e84SJonathan Cameron /** 231915e4e84SJonathan Cameron * struct sec_alg_tfm_ctx - hardware specific tranformation context 232915e4e84SJonathan Cameron * @cipher_alg: Cipher algorithm enabled include encryption mode. 233915e4e84SJonathan Cameron * @key: Key storage if required. 234915e4e84SJonathan Cameron * @pkey: DMA address for the key storage. 235915e4e84SJonathan Cameron * @req_template: Request template to save time on setup. 236915e4e84SJonathan Cameron * @queue: The hardware queue associated with this tfm context. 237915e4e84SJonathan Cameron * @lock: Protect key and pkey to ensure they are consistent 238915e4e84SJonathan Cameron * @auth_buf: Current context buffer for auth operations. 239915e4e84SJonathan Cameron * @backlog: The backlog queue used for cases where our buffers aren't 240915e4e84SJonathan Cameron * large enough. 241915e4e84SJonathan Cameron */ 242915e4e84SJonathan Cameron struct sec_alg_tfm_ctx { 243915e4e84SJonathan Cameron enum sec_cipher_alg cipher_alg; 244915e4e84SJonathan Cameron u8 *key; 245915e4e84SJonathan Cameron dma_addr_t pkey; 246915e4e84SJonathan Cameron struct sec_bd_info req_template; 247915e4e84SJonathan Cameron struct sec_queue *queue; 248915e4e84SJonathan Cameron struct mutex lock; 249915e4e84SJonathan Cameron u8 *auth_buf; 250915e4e84SJonathan Cameron struct list_head backlog; 251915e4e84SJonathan Cameron }; 252915e4e84SJonathan Cameron 253915e4e84SJonathan Cameron /** 254915e4e84SJonathan Cameron * struct sec_request - data associate with a single crypto request 255915e4e84SJonathan Cameron * @elements: List of subparts of this request (hardware size restriction) 256915e4e84SJonathan Cameron * @num_elements: The number of subparts (used as an optimization) 257915e4e84SJonathan Cameron * @lock: Protect elements of this structure against concurrent change. 258915e4e84SJonathan Cameron * @tfm_ctx: hardware specific context. 259915e4e84SJonathan Cameron * @len_in: length of in sgl from upper layers 260915e4e84SJonathan Cameron * @len_out: length of out sgl from upper layers 261915e4e84SJonathan Cameron * @dma_iv: initialization vector - phsyical address 262915e4e84SJonathan Cameron * @err: store used to track errors across subelements of this request. 263915e4e84SJonathan Cameron * @req_base: pointer to base element of associate crypto context. 264915e4e84SJonathan Cameron * This is needed to allow shared handling skcipher, ahash etc. 265915e4e84SJonathan Cameron * @cb: completion callback. 266915e4e84SJonathan Cameron * @backlog_head: list head to allow backlog maintenance. 267915e4e84SJonathan Cameron * 268915e4e84SJonathan Cameron * The hardware is limited in the maximum size of data that it can 269915e4e84SJonathan Cameron * process from a single BD. Typically this is fairly large (32MB) 270915e4e84SJonathan Cameron * but still requires the complexity of splitting the incoming 271915e4e84SJonathan Cameron * skreq up into a number of elements complete with appropriate 272915e4e84SJonathan Cameron * iv chaining. 273915e4e84SJonathan Cameron */ 274915e4e84SJonathan Cameron struct sec_request { 275915e4e84SJonathan Cameron struct list_head elements; 276915e4e84SJonathan Cameron int num_elements; 277915e4e84SJonathan Cameron struct mutex lock; 278915e4e84SJonathan Cameron struct sec_alg_tfm_ctx *tfm_ctx; 279915e4e84SJonathan Cameron int len_in; 280915e4e84SJonathan Cameron int len_out; 281915e4e84SJonathan Cameron dma_addr_t dma_iv; 282915e4e84SJonathan Cameron int err; 283915e4e84SJonathan Cameron struct crypto_async_request *req_base; 284915e4e84SJonathan Cameron void (*cb)(struct sec_bd_info *resp, struct crypto_async_request *req); 285915e4e84SJonathan Cameron struct list_head backlog_head; 286915e4e84SJonathan Cameron }; 287915e4e84SJonathan Cameron 288915e4e84SJonathan Cameron /** 289915e4e84SJonathan Cameron * struct sec_request_el - A subpart of a request. 290915e4e84SJonathan Cameron * @head: allow us to attach this to the list in the sec_request 291915e4e84SJonathan Cameron * @req: hardware block descriptor corresponding to this request subpart 292915e4e84SJonathan Cameron * @in: hardware sgl for input - virtual address 293915e4e84SJonathan Cameron * @dma_in: hardware sgl for input - physical address 294915e4e84SJonathan Cameron * @sgl_in: scatterlist for this request subpart 295915e4e84SJonathan Cameron * @out: hardware sgl for output - virtual address 296915e4e84SJonathan Cameron * @dma_out: hardware sgl for output - physical address 297915e4e84SJonathan Cameron * @sgl_out: scatterlist for this request subpart 298915e4e84SJonathan Cameron * @sec_req: The request which this subpart forms a part of 299915e4e84SJonathan Cameron * @el_length: Number of bytes in this subpart. Needed to locate 300915e4e84SJonathan Cameron * last ivsize chunk for iv chaining. 301915e4e84SJonathan Cameron */ 302915e4e84SJonathan Cameron struct sec_request_el { 303915e4e84SJonathan Cameron struct list_head head; 304915e4e84SJonathan Cameron struct sec_bd_info req; 305915e4e84SJonathan Cameron struct sec_hw_sgl *in; 306915e4e84SJonathan Cameron dma_addr_t dma_in; 307915e4e84SJonathan Cameron struct scatterlist *sgl_in; 308915e4e84SJonathan Cameron struct sec_hw_sgl *out; 309915e4e84SJonathan Cameron dma_addr_t dma_out; 310915e4e84SJonathan Cameron struct scatterlist *sgl_out; 311915e4e84SJonathan Cameron struct sec_request *sec_req; 312915e4e84SJonathan Cameron size_t el_length; 313915e4e84SJonathan Cameron }; 314915e4e84SJonathan Cameron 315915e4e84SJonathan Cameron /** 316915e4e84SJonathan Cameron * struct sec_queue - All the information about a HW queue 317915e4e84SJonathan Cameron * @dev_info: The parent SEC device to which this queue belongs. 318915e4e84SJonathan Cameron * @task_irq: Completion interrupt for the queue. 319915e4e84SJonathan Cameron * @name: Human readable queue description also used as irq name. 320915e4e84SJonathan Cameron * @ring: The several HW rings associated with one queue. 321915e4e84SJonathan Cameron * @regs: The iomapped device registers 322915e4e84SJonathan Cameron * @queue_id: Index of the queue used for naming and resource selection. 323915e4e84SJonathan Cameron * @in_use: Flag to say if the queue is in use. 324915e4e84SJonathan Cameron * @expected: The next expected element to finish assuming we were in order. 325915e4e84SJonathan Cameron * @uprocessed: A bitmap to track which OoO elements are done but not handled. 326915e4e84SJonathan Cameron * @softqueue: A software queue used when chaining requirements prevent direct 327915e4e84SJonathan Cameron * use of the hardware queues. 328915e4e84SJonathan Cameron * @havesoftqueue: A flag to say we have a queues - as we may need one for the 329915e4e84SJonathan Cameron * current mode. 330915e4e84SJonathan Cameron * @queuelock: Protect the soft queue from concurrent changes to avoid some 331915e4e84SJonathan Cameron * potential loss of data races. 332915e4e84SJonathan Cameron * @shadow: Pointers back to the shadow copy of the hardware ring element 333915e4e84SJonathan Cameron * need because we can't store any context reference in the bd element. 334915e4e84SJonathan Cameron */ 335915e4e84SJonathan Cameron struct sec_queue { 336915e4e84SJonathan Cameron struct sec_dev_info *dev_info; 337915e4e84SJonathan Cameron int task_irq; 338915e4e84SJonathan Cameron char name[SEC_NAME_SIZE]; 339915e4e84SJonathan Cameron struct sec_queue_ring_cmd ring_cmd; 340915e4e84SJonathan Cameron struct sec_queue_ring_cq ring_cq; 341915e4e84SJonathan Cameron struct sec_queue_ring_db ring_db; 342915e4e84SJonathan Cameron void __iomem *regs; 343915e4e84SJonathan Cameron u32 queue_id; 344915e4e84SJonathan Cameron bool in_use; 345915e4e84SJonathan Cameron int expected; 346915e4e84SJonathan Cameron 347915e4e84SJonathan Cameron DECLARE_BITMAP(unprocessed, SEC_QUEUE_LEN); 348915e4e84SJonathan Cameron DECLARE_KFIFO_PTR(softqueue, typeof(struct sec_request_el *)); 349915e4e84SJonathan Cameron bool havesoftqueue; 350*68740ab5SZhengchao Shao spinlock_t queuelock; 351915e4e84SJonathan Cameron void *shadow[SEC_QUEUE_LEN]; 352915e4e84SJonathan Cameron }; 353915e4e84SJonathan Cameron 354915e4e84SJonathan Cameron /** 355915e4e84SJonathan Cameron * struct sec_hw_sge: Track each of the 64 element SEC HW SGL entries 356915e4e84SJonathan Cameron * @buf: The IOV dma address for this entry. 357915e4e84SJonathan Cameron * @len: Length of this IOV. 358915e4e84SJonathan Cameron * @pad: Reserved space. 359915e4e84SJonathan Cameron */ 360915e4e84SJonathan Cameron struct sec_hw_sge { 361915e4e84SJonathan Cameron dma_addr_t buf; 362915e4e84SJonathan Cameron unsigned int len; 363915e4e84SJonathan Cameron unsigned int pad; 364915e4e84SJonathan Cameron }; 365915e4e84SJonathan Cameron 366915e4e84SJonathan Cameron /** 367915e4e84SJonathan Cameron * struct sec_hw_sgl: One hardware SGL entry. 368915e4e84SJonathan Cameron * @next_sgl: The next entry if we need to chain dma address. Null if last. 369915e4e84SJonathan Cameron * @entry_sum_in_chain: The full count of SGEs - only matters for first SGL. 370915e4e84SJonathan Cameron * @entry_sum_in_sgl: The number of SGEs in this SGL element. 371915e4e84SJonathan Cameron * @flag: Unused in skciphers. 372915e4e84SJonathan Cameron * @serial_num: Unsued in skciphers. 373915e4e84SJonathan Cameron * @cpuid: Currently unused. 374915e4e84SJonathan Cameron * @data_bytes_in_sgl: Count of bytes from all SGEs in this SGL. 375915e4e84SJonathan Cameron * @next: Virtual address used to stash the next sgl - useful in completion. 376915e4e84SJonathan Cameron * @reserved: A reserved field not currently used. 377915e4e84SJonathan Cameron * @sge_entries: The (up to) 64 Scatter Gather Entries, representing IOVs. 378915e4e84SJonathan Cameron * @node: Currently unused. 379915e4e84SJonathan Cameron */ 380915e4e84SJonathan Cameron struct sec_hw_sgl { 381915e4e84SJonathan Cameron dma_addr_t next_sgl; 382915e4e84SJonathan Cameron u16 entry_sum_in_chain; 383915e4e84SJonathan Cameron u16 entry_sum_in_sgl; 384915e4e84SJonathan Cameron u32 flag; 385915e4e84SJonathan Cameron u64 serial_num; 386915e4e84SJonathan Cameron u32 cpuid; 387915e4e84SJonathan Cameron u32 data_bytes_in_sgl; 388915e4e84SJonathan Cameron struct sec_hw_sgl *next; 389915e4e84SJonathan Cameron u64 reserved; 390915e4e84SJonathan Cameron struct sec_hw_sge sge_entries[SEC_MAX_SGE_NUM]; 391915e4e84SJonathan Cameron u8 node[16]; 392915e4e84SJonathan Cameron }; 393915e4e84SJonathan Cameron 394915e4e84SJonathan Cameron struct dma_pool; 395915e4e84SJonathan Cameron 396915e4e84SJonathan Cameron /** 397915e4e84SJonathan Cameron * struct sec_dev_info: The full SEC unit comprising queues and processors. 398915e4e84SJonathan Cameron * @sec_id: Index used to track which SEC this is when more than one is present. 399915e4e84SJonathan Cameron * @num_saas: The number of backed processors enabled. 400915e4e84SJonathan Cameron * @regs: iomapped register regions shared by whole SEC unit. 401915e4e84SJonathan Cameron * @dev_lock: Protects concurrent queue allocation / freeing for the SEC. 402915e4e84SJonathan Cameron * @queues: The 16 queues that this SEC instance provides. 403915e4e84SJonathan Cameron * @dev: Device pointer. 404915e4e84SJonathan Cameron * @hw_sgl_pool: DMA pool used to mimise mapping for the scatter gather lists. 405915e4e84SJonathan Cameron */ 406915e4e84SJonathan Cameron struct sec_dev_info { 407915e4e84SJonathan Cameron int sec_id; 408915e4e84SJonathan Cameron int num_saas; 409915e4e84SJonathan Cameron void __iomem *regs[SEC_NUM_ADDR_REGIONS]; 410915e4e84SJonathan Cameron struct mutex dev_lock; 411915e4e84SJonathan Cameron int queues_in_use; 412915e4e84SJonathan Cameron struct sec_queue queues[SEC_Q_NUM]; 413915e4e84SJonathan Cameron struct device *dev; 414915e4e84SJonathan Cameron struct dma_pool *hw_sgl_pool; 415915e4e84SJonathan Cameron }; 416915e4e84SJonathan Cameron 417915e4e84SJonathan Cameron int sec_queue_send(struct sec_queue *queue, struct sec_bd_info *msg, void *ctx); 418915e4e84SJonathan Cameron bool sec_queue_can_enqueue(struct sec_queue *queue, int num); 419915e4e84SJonathan Cameron int sec_queue_stop_release(struct sec_queue *queue); 420915e4e84SJonathan Cameron struct sec_queue *sec_queue_alloc_start_safe(void); 421915e4e84SJonathan Cameron bool sec_queue_empty(struct sec_queue *queue); 422915e4e84SJonathan Cameron 423915e4e84SJonathan Cameron /* Algorithm specific elements from sec_algs.c */ 424915e4e84SJonathan Cameron void sec_alg_callback(struct sec_bd_info *resp, void *ctx); 425915e4e84SJonathan Cameron int sec_algs_register(void); 426915e4e84SJonathan Cameron void sec_algs_unregister(void); 427915e4e84SJonathan Cameron 428915e4e84SJonathan Cameron #endif /* _SEC_DRV_H_ */ 429