cc_hw_queue_defs.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
  3. #ifndef __CC_HW_QUEUE_DEFS_H__
  4. #define __CC_HW_QUEUE_DEFS_H__
  5. #include <linux/types.h>
  6. #include "cc_kernel_regs.h"
  7. #include <linux/bitfield.h>
  8. /******************************************************************************
  9. * DEFINITIONS
  10. ******************************************************************************/
  11. #define HW_DESC_SIZE_WORDS 6
  12. /* Define max. available slots in HW queue */
  13. #define HW_QUEUE_SLOTS_MAX 15
  14. #define CC_REG_LOW(word, name) \
  15. (CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SHIFT)
  16. #define CC_REG_HIGH(word, name) \
  17. (CC_REG_LOW(word, name) + \
  18. CC_DSCRPTR_QUEUE_WORD ## word ## _ ## name ## _BIT_SIZE - 1)
  19. #define CC_GENMASK(word, name) \
  20. GENMASK(CC_REG_HIGH(word, name), CC_REG_LOW(word, name))
  21. #define WORD0_VALUE CC_GENMASK(0, VALUE)
  22. #define WORD0_CPP_CIPHER_MODE CC_GENMASK(0, CPP_CIPHER_MODE)
  23. #define WORD1_DIN_CONST_VALUE CC_GENMASK(1, DIN_CONST_VALUE)
  24. #define WORD1_DIN_DMA_MODE CC_GENMASK(1, DIN_DMA_MODE)
  25. #define WORD1_DIN_SIZE CC_GENMASK(1, DIN_SIZE)
  26. #define WORD1_NOT_LAST CC_GENMASK(1, NOT_LAST)
  27. #define WORD1_NS_BIT CC_GENMASK(1, NS_BIT)
  28. #define WORD1_LOCK_QUEUE CC_GENMASK(1, LOCK_QUEUE)
  29. #define WORD2_VALUE CC_GENMASK(2, VALUE)
  30. #define WORD3_DOUT_DMA_MODE CC_GENMASK(3, DOUT_DMA_MODE)
  31. #define WORD3_DOUT_LAST_IND CC_GENMASK(3, DOUT_LAST_IND)
  32. #define WORD3_DOUT_SIZE CC_GENMASK(3, DOUT_SIZE)
  33. #define WORD3_HASH_XOR_BIT CC_GENMASK(3, HASH_XOR_BIT)
  34. #define WORD3_NS_BIT CC_GENMASK(3, NS_BIT)
  35. #define WORD3_QUEUE_LAST_IND CC_GENMASK(3, QUEUE_LAST_IND)
  36. #define WORD4_ACK_NEEDED CC_GENMASK(4, ACK_NEEDED)
  37. #define WORD4_AES_SEL_N_HASH CC_GENMASK(4, AES_SEL_N_HASH)
  38. #define WORD4_AES_XOR_CRYPTO_KEY CC_GENMASK(4, AES_XOR_CRYPTO_KEY)
  39. #define WORD4_BYTES_SWAP CC_GENMASK(4, BYTES_SWAP)
  40. #define WORD4_CIPHER_CONF0 CC_GENMASK(4, CIPHER_CONF0)
  41. #define WORD4_CIPHER_CONF1 CC_GENMASK(4, CIPHER_CONF1)
  42. #define WORD4_CIPHER_CONF2 CC_GENMASK(4, CIPHER_CONF2)
  43. #define WORD4_CIPHER_DO CC_GENMASK(4, CIPHER_DO)
  44. #define WORD4_CIPHER_MODE CC_GENMASK(4, CIPHER_MODE)
  45. #define WORD4_CMAC_SIZE0 CC_GENMASK(4, CMAC_SIZE0)
  46. #define WORD4_DATA_FLOW_MODE CC_GENMASK(4, DATA_FLOW_MODE)
  47. #define WORD4_KEY_SIZE CC_GENMASK(4, KEY_SIZE)
  48. #define WORD4_SETUP_OPERATION CC_GENMASK(4, SETUP_OPERATION)
  49. #define WORD5_DIN_ADDR_HIGH CC_GENMASK(5, DIN_ADDR_HIGH)
  50. #define WORD5_DOUT_ADDR_HIGH CC_GENMASK(5, DOUT_ADDR_HIGH)
  51. /******************************************************************************
  52. * TYPE DEFINITIONS
  53. ******************************************************************************/
  54. struct cc_hw_desc {
  55. union {
  56. u32 word[HW_DESC_SIZE_WORDS];
  57. u16 hword[HW_DESC_SIZE_WORDS * 2];
  58. };
  59. };
  60. enum cc_axi_sec {
  61. AXI_SECURE = 0,
  62. AXI_NOT_SECURE = 1
  63. };
  64. enum cc_desc_direction {
  65. DESC_DIRECTION_ILLEGAL = -1,
  66. DESC_DIRECTION_ENCRYPT_ENCRYPT = 0,
  67. DESC_DIRECTION_DECRYPT_DECRYPT = 1,
  68. DESC_DIRECTION_DECRYPT_ENCRYPT = 3,
  69. DESC_DIRECTION_END = S32_MAX,
  70. };
  71. enum cc_dma_mode {
  72. DMA_MODE_NULL = -1,
  73. NO_DMA = 0,
  74. DMA_SRAM = 1,
  75. DMA_DLLI = 2,
  76. DMA_MLLI = 3,
  77. DMA_MODE_END = S32_MAX,
  78. };
  79. enum cc_flow_mode {
  80. FLOW_MODE_NULL = -1,
  81. /* data flows */
  82. BYPASS = 0,
  83. DIN_AES_DOUT = 1,
  84. AES_to_HASH = 2,
  85. AES_and_HASH = 3,
  86. DIN_DES_DOUT = 4,
  87. DES_to_HASH = 5,
  88. DES_and_HASH = 6,
  89. DIN_HASH = 7,
  90. DIN_HASH_and_BYPASS = 8,
  91. AESMAC_and_BYPASS = 9,
  92. AES_to_HASH_and_DOUT = 10,
  93. DIN_RC4_DOUT = 11,
  94. DES_to_HASH_and_DOUT = 12,
  95. AES_to_AES_to_HASH_and_DOUT = 13,
  96. AES_to_AES_to_HASH = 14,
  97. AES_to_HASH_and_AES = 15,
  98. DIN_SM4_DOUT = 16,
  99. DIN_AES_AESMAC = 17,
  100. HASH_to_DOUT = 18,
  101. /* setup flows */
  102. S_DIN_to_AES = 32,
  103. S_DIN_to_AES2 = 33,
  104. S_DIN_to_DES = 34,
  105. S_DIN_to_RC4 = 35,
  106. S_DIN_to_SM4 = 36,
  107. S_DIN_to_HASH = 37,
  108. S_AES_to_DOUT = 38,
  109. S_AES2_to_DOUT = 39,
  110. S_SM4_to_DOUT = 40,
  111. S_RC4_to_DOUT = 41,
  112. S_DES_to_DOUT = 42,
  113. S_HASH_to_DOUT = 43,
  114. SET_FLOW_ID = 44,
  115. FLOW_MODE_END = S32_MAX,
  116. };
  117. enum cc_setup_op {
  118. SETUP_LOAD_NOP = 0,
  119. SETUP_LOAD_STATE0 = 1,
  120. SETUP_LOAD_STATE1 = 2,
  121. SETUP_LOAD_STATE2 = 3,
  122. SETUP_LOAD_KEY0 = 4,
  123. SETUP_LOAD_XEX_KEY = 5,
  124. SETUP_WRITE_STATE0 = 8,
  125. SETUP_WRITE_STATE1 = 9,
  126. SETUP_WRITE_STATE2 = 10,
  127. SETUP_WRITE_STATE3 = 11,
  128. SETUP_OP_END = S32_MAX,
  129. };
  130. enum cc_hash_conf_pad {
  131. HASH_PADDING_DISABLED = 0,
  132. HASH_PADDING_ENABLED = 1,
  133. HASH_DIGEST_RESULT_LITTLE_ENDIAN = 2,
  134. HASH_CONFIG1_PADDING_RESERVE32 = S32_MAX,
  135. };
  136. enum cc_aes_mac_selector {
  137. AES_SK = 1,
  138. AES_CMAC_INIT = 2,
  139. AES_CMAC_SIZE0 = 3,
  140. AES_MAC_END = S32_MAX,
  141. };
  142. #define HW_KEY_MASK_CIPHER_DO 0x3
  143. #define HW_KEY_SHIFT_CIPHER_CFG2 2
  144. /* HwCryptoKey[1:0] is mapped to cipher_do[1:0] */
  145. /* HwCryptoKey[2:3] is mapped to cipher_config2[1:0] */
  146. enum cc_hw_crypto_key {
  147. USER_KEY = 0, /* 0x0000 */
  148. ROOT_KEY = 1, /* 0x0001 */
  149. PROVISIONING_KEY = 2, /* 0x0010 */ /* ==KCP */
  150. SESSION_KEY = 3, /* 0x0011 */
  151. RESERVED_KEY = 4, /* NA */
  152. PLATFORM_KEY = 5, /* 0x0101 */
  153. CUSTOMER_KEY = 6, /* 0x0110 */
  154. KFDE0_KEY = 7, /* 0x0111 */
  155. KFDE1_KEY = 9, /* 0x1001 */
  156. KFDE2_KEY = 10, /* 0x1010 */
  157. KFDE3_KEY = 11, /* 0x1011 */
  158. END_OF_KEYS = S32_MAX,
  159. };
  160. #define CC_NUM_HW_KEY_SLOTS 4
  161. #define CC_FIRST_HW_KEY_SLOT 0
  162. #define CC_LAST_HW_KEY_SLOT (CC_FIRST_HW_KEY_SLOT + CC_NUM_HW_KEY_SLOTS - 1)
  163. #define CC_NUM_CPP_KEY_SLOTS 8
  164. #define CC_FIRST_CPP_KEY_SLOT 16
  165. #define CC_LAST_CPP_KEY_SLOT (CC_FIRST_CPP_KEY_SLOT + \
  166. CC_NUM_CPP_KEY_SLOTS - 1)
  167. enum cc_hw_aes_key_size {
  168. AES_128_KEY = 0,
  169. AES_192_KEY = 1,
  170. AES_256_KEY = 2,
  171. END_OF_AES_KEYS = S32_MAX,
  172. };
  173. enum cc_hash_cipher_pad {
  174. DO_NOT_PAD = 0,
  175. DO_PAD = 1,
  176. HASH_CIPHER_DO_PADDING_RESERVE32 = S32_MAX,
  177. };
  178. #define CC_CPP_DIN_ADDR 0xFF00FF00UL
  179. #define CC_CPP_DIN_SIZE 0xFF00FFUL
  180. /*****************************/
  181. /* Descriptor packing macros */
  182. /*****************************/
  183. /*
  184. * Init a HW descriptor struct
  185. * @pdesc: pointer HW descriptor struct
  186. */
  187. static inline void hw_desc_init(struct cc_hw_desc *pdesc)
  188. {
  189. memset(pdesc, 0, sizeof(struct cc_hw_desc));
  190. }
  191. /*
  192. * Indicates the end of current HW descriptors flow and release the HW engines.
  193. *
  194. * @pdesc: pointer HW descriptor struct
  195. */
  196. static inline void set_queue_last_ind_bit(struct cc_hw_desc *pdesc)
  197. {
  198. pdesc->word[3] |= FIELD_PREP(WORD3_QUEUE_LAST_IND, 1);
  199. }
  200. /*
  201. * Set the DIN field of a HW descriptors
  202. *
  203. * @pdesc: pointer HW descriptor struct
  204. * @dma_mode: dmaMode The DMA mode: NO_DMA, SRAM, DLLI, MLLI, CONSTANT
  205. * @addr: dinAdr DIN address
  206. * @size: Data size in bytes
  207. * @axi_sec: AXI secure bit
  208. */
  209. static inline void set_din_type(struct cc_hw_desc *pdesc,
  210. enum cc_dma_mode dma_mode, dma_addr_t addr,
  211. u32 size, enum cc_axi_sec axi_sec)
  212. {
  213. pdesc->word[0] = (u32)addr;
  214. #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
  215. pdesc->word[5] |= FIELD_PREP(WORD5_DIN_ADDR_HIGH, ((u16)(addr >> 32)));
  216. #endif
  217. pdesc->word[1] |= FIELD_PREP(WORD1_DIN_DMA_MODE, dma_mode) |
  218. FIELD_PREP(WORD1_DIN_SIZE, size) |
  219. FIELD_PREP(WORD1_NS_BIT, axi_sec);
  220. }
  221. /*
  222. * Set the DIN field of a HW descriptors to NO DMA mode.
  223. * Used for NOP descriptor, register patches and other special modes.
  224. *
  225. * @pdesc: pointer HW descriptor struct
  226. * @addr: DIN address
  227. * @size: Data size in bytes
  228. */
  229. static inline void set_din_no_dma(struct cc_hw_desc *pdesc, u32 addr, u32 size)
  230. {
  231. pdesc->word[0] = addr;
  232. pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size);
  233. }
  234. /*
  235. * Setup the special CPP descriptor
  236. *
  237. * @pdesc: pointer HW descriptor struct
  238. * @alg: cipher used (AES / SM4)
  239. * @mode: mode used (CTR or CBC)
  240. * @slot: slot number
  241. * @ksize: key size
  242. */
  243. static inline void set_cpp_crypto_key(struct cc_hw_desc *pdesc, u8 slot)
  244. {
  245. pdesc->word[0] |= CC_CPP_DIN_ADDR;
  246. pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, CC_CPP_DIN_SIZE);
  247. pdesc->word[1] |= FIELD_PREP(WORD1_LOCK_QUEUE, 1);
  248. pdesc->word[4] |= FIELD_PREP(WORD4_SETUP_OPERATION, slot);
  249. }
  250. /*
  251. * Set the DIN field of a HW descriptors to SRAM mode.
  252. * Note: No need to check SRAM alignment since host requests do not use SRAM and
  253. * adaptor will enforce alignment check.
  254. *
  255. * @pdesc: pointer HW descriptor struct
  256. * @addr: DIN address
  257. * @size Data size in bytes
  258. */
  259. static inline void set_din_sram(struct cc_hw_desc *pdesc, dma_addr_t addr,
  260. u32 size)
  261. {
  262. pdesc->word[0] = (u32)addr;
  263. pdesc->word[1] |= FIELD_PREP(WORD1_DIN_SIZE, size) |
  264. FIELD_PREP(WORD1_DIN_DMA_MODE, DMA_SRAM);
  265. }
  266. /*
  267. * Set the DIN field of a HW descriptors to CONST mode
  268. *
  269. * @pdesc: pointer HW descriptor struct
  270. * @val: DIN const value
  271. * @size: Data size in bytes
  272. */
  273. static inline void set_din_const(struct cc_hw_desc *pdesc, u32 val, u32 size)
  274. {
  275. pdesc->word[0] = val;
  276. pdesc->word[1] |= FIELD_PREP(WORD1_DIN_CONST_VALUE, 1) |
  277. FIELD_PREP(WORD1_DIN_DMA_MODE, DMA_SRAM) |
  278. FIELD_PREP(WORD1_DIN_SIZE, size);
  279. }
  280. /*
  281. * Set the DIN not last input data indicator
  282. *
  283. * @pdesc: pointer HW descriptor struct
  284. */
  285. static inline void set_din_not_last_indication(struct cc_hw_desc *pdesc)
  286. {
  287. pdesc->word[1] |= FIELD_PREP(WORD1_NOT_LAST, 1);
  288. }
  289. /*
  290. * Set the DOUT field of a HW descriptors
  291. *
  292. * @pdesc: pointer HW descriptor struct
  293. * @dma_mode: The DMA mode: NO_DMA, SRAM, DLLI, MLLI, CONSTANT
  294. * @addr: DOUT address
  295. * @size: Data size in bytes
  296. * @axi_sec: AXI secure bit
  297. */
  298. static inline void set_dout_type(struct cc_hw_desc *pdesc,
  299. enum cc_dma_mode dma_mode, dma_addr_t addr,
  300. u32 size, enum cc_axi_sec axi_sec)
  301. {
  302. pdesc->word[2] = (u32)addr;
  303. #ifdef CONFIG_ARCH_DMA_ADDR_T_64BIT
  304. pdesc->word[5] |= FIELD_PREP(WORD5_DOUT_ADDR_HIGH, ((u16)(addr >> 32)));
  305. #endif
  306. pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_DMA_MODE, dma_mode) |
  307. FIELD_PREP(WORD3_DOUT_SIZE, size) |
  308. FIELD_PREP(WORD3_NS_BIT, axi_sec);
  309. }
  310. /*
  311. * Set the DOUT field of a HW descriptors to DLLI type
  312. * The LAST INDICATION is provided by the user
  313. *
  314. * @pdesc pointer HW descriptor struct
  315. * @addr: DOUT address
  316. * @size: Data size in bytes
  317. * @last_ind: The last indication bit
  318. * @axi_sec: AXI secure bit
  319. */
  320. static inline void set_dout_dlli(struct cc_hw_desc *pdesc, dma_addr_t addr,
  321. u32 size, enum cc_axi_sec axi_sec,
  322. u32 last_ind)
  323. {
  324. set_dout_type(pdesc, DMA_DLLI, addr, size, axi_sec);
  325. pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_LAST_IND, last_ind);
  326. }
  327. /*
  328. * Set the DOUT field of a HW descriptors to DLLI type
  329. * The LAST INDICATION is provided by the user
  330. *
  331. * @pdesc: pointer HW descriptor struct
  332. * @addr: DOUT address
  333. * @size: Data size in bytes
  334. * @last_ind: The last indication bit
  335. * @axi_sec: AXI secure bit
  336. */
  337. static inline void set_dout_mlli(struct cc_hw_desc *pdesc, dma_addr_t addr,
  338. u32 size, enum cc_axi_sec axi_sec,
  339. bool last_ind)
  340. {
  341. set_dout_type(pdesc, DMA_MLLI, addr, size, axi_sec);
  342. pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_LAST_IND, last_ind);
  343. }
  344. /*
  345. * Set the DOUT field of a HW descriptors to NO DMA mode.
  346. * Used for NOP descriptor, register patches and other special modes.
  347. *
  348. * @pdesc: pointer HW descriptor struct
  349. * @addr: DOUT address
  350. * @size: Data size in bytes
  351. * @write_enable: Enables a write operation to a register
  352. */
  353. static inline void set_dout_no_dma(struct cc_hw_desc *pdesc, u32 addr,
  354. u32 size, bool write_enable)
  355. {
  356. pdesc->word[2] = addr;
  357. pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_SIZE, size) |
  358. FIELD_PREP(WORD3_DOUT_LAST_IND, write_enable);
  359. }
  360. /*
  361. * Set the word for the XOR operation.
  362. *
  363. * @pdesc: pointer HW descriptor struct
  364. * @val: xor data value
  365. */
  366. static inline void set_xor_val(struct cc_hw_desc *pdesc, u32 val)
  367. {
  368. pdesc->word[2] = val;
  369. }
  370. /*
  371. * Sets the XOR indicator bit in the descriptor
  372. *
  373. * @pdesc: pointer HW descriptor struct
  374. */
  375. static inline void set_xor_active(struct cc_hw_desc *pdesc)
  376. {
  377. pdesc->word[3] |= FIELD_PREP(WORD3_HASH_XOR_BIT, 1);
  378. }
  379. /*
  380. * Select the AES engine instead of HASH engine when setting up combined mode
  381. * with AES XCBC MAC
  382. *
  383. * @pdesc: pointer HW descriptor struct
  384. */
  385. static inline void set_aes_not_hash_mode(struct cc_hw_desc *pdesc)
  386. {
  387. pdesc->word[4] |= FIELD_PREP(WORD4_AES_SEL_N_HASH, 1);
  388. }
  389. /*
  390. * Set aes xor crypto key, this in some secenrios select SM3 engine
  391. *
  392. * @pdesc: pointer HW descriptor struct
  393. */
  394. static inline void set_aes_xor_crypto_key(struct cc_hw_desc *pdesc)
  395. {
  396. pdesc->word[4] |= FIELD_PREP(WORD4_AES_XOR_CRYPTO_KEY, 1);
  397. }
  398. /*
  399. * Set the DOUT field of a HW descriptors to SRAM mode
  400. * Note: No need to check SRAM alignment since host requests do not use SRAM and
  401. * adaptor will enforce alignment check.
  402. *
  403. * @pdesc: pointer HW descriptor struct
  404. * @addr: DOUT address
  405. * @size: Data size in bytes
  406. */
  407. static inline void set_dout_sram(struct cc_hw_desc *pdesc, u32 addr, u32 size)
  408. {
  409. pdesc->word[2] = addr;
  410. pdesc->word[3] |= FIELD_PREP(WORD3_DOUT_DMA_MODE, DMA_SRAM) |
  411. FIELD_PREP(WORD3_DOUT_SIZE, size);
  412. }
  413. /*
  414. * Sets the data unit size for XEX mode in data_out_addr[15:0]
  415. *
  416. * @pdesc: pDesc pointer HW descriptor struct
  417. * @size: data unit size for XEX mode
  418. */
  419. static inline void set_xex_data_unit_size(struct cc_hw_desc *pdesc, u32 size)
  420. {
  421. pdesc->word[2] = size;
  422. }
  423. /*
  424. * Set the number of rounds for Multi2 in data_out_addr[15:0]
  425. *
  426. * @pdesc: pointer HW descriptor struct
  427. * @num: number of rounds for Multi2
  428. */
  429. static inline void set_multi2_num_rounds(struct cc_hw_desc *pdesc, u32 num)
  430. {
  431. pdesc->word[2] = num;
  432. }
  433. /*
  434. * Set the flow mode.
  435. *
  436. * @pdesc: pointer HW descriptor struct
  437. * @mode: Any one of the modes defined in [CC7x-DESC]
  438. */
  439. static inline void set_flow_mode(struct cc_hw_desc *pdesc,
  440. enum cc_flow_mode mode)
  441. {
  442. pdesc->word[4] |= FIELD_PREP(WORD4_DATA_FLOW_MODE, mode);
  443. }
  444. /*
  445. * Set the cipher mode.
  446. *
  447. * @pdesc: pointer HW descriptor struct
  448. * @mode: Any one of the modes defined in [CC7x-DESC]
  449. */
  450. static inline void set_cipher_mode(struct cc_hw_desc *pdesc, int mode)
  451. {
  452. pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_MODE, mode);
  453. }
  454. /*
  455. * Set the cipher mode for hash algorithms.
  456. *
  457. * @pdesc: pointer HW descriptor struct
  458. * @cipher_mode: Any one of the modes defined in [CC7x-DESC]
  459. * @hash_mode: specifies which hash is being handled
  460. */
  461. static inline void set_hash_cipher_mode(struct cc_hw_desc *pdesc,
  462. enum drv_cipher_mode cipher_mode,
  463. enum drv_hash_mode hash_mode)
  464. {
  465. set_cipher_mode(pdesc, cipher_mode);
  466. if (hash_mode == DRV_HASH_SM3)
  467. set_aes_xor_crypto_key(pdesc);
  468. }
  469. /*
  470. * Set the cipher configuration fields.
  471. *
  472. * @pdesc: pointer HW descriptor struct
  473. * @mode: Any one of the modes defined in [CC7x-DESC]
  474. */
  475. static inline void set_cipher_config0(struct cc_hw_desc *pdesc, int mode)
  476. {
  477. pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_CONF0, mode);
  478. }
  479. /*
  480. * Set the cipher configuration fields.
  481. *
  482. * @pdesc: pointer HW descriptor struct
  483. * @config: Any one of the modes defined in [CC7x-DESC]
  484. */
  485. static inline void set_cipher_config1(struct cc_hw_desc *pdesc,
  486. enum cc_hash_conf_pad config)
  487. {
  488. pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_CONF1, config);
  489. }
  490. /*
  491. * Set HW key configuration fields.
  492. *
  493. * @pdesc: pointer HW descriptor struct
  494. * @hw_key: The HW key slot asdefined in enum cc_hw_crypto_key
  495. */
  496. static inline void set_hw_crypto_key(struct cc_hw_desc *pdesc,
  497. enum cc_hw_crypto_key hw_key)
  498. {
  499. pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_DO,
  500. (hw_key & HW_KEY_MASK_CIPHER_DO)) |
  501. FIELD_PREP(WORD4_CIPHER_CONF2,
  502. (hw_key >> HW_KEY_SHIFT_CIPHER_CFG2));
  503. }
  504. /*
  505. * Set byte order of all setup-finalize descriptors.
  506. *
  507. * @pdesc: pointer HW descriptor struct
  508. * @config: Any one of the modes defined in [CC7x-DESC]
  509. */
  510. static inline void set_bytes_swap(struct cc_hw_desc *pdesc, bool config)
  511. {
  512. pdesc->word[4] |= FIELD_PREP(WORD4_BYTES_SWAP, config);
  513. }
  514. /*
  515. * Set CMAC_SIZE0 mode.
  516. *
  517. * @pdesc: pointer HW descriptor struct
  518. */
  519. static inline void set_cmac_size0_mode(struct cc_hw_desc *pdesc)
  520. {
  521. pdesc->word[4] |= FIELD_PREP(WORD4_CMAC_SIZE0, 1);
  522. }
  523. /*
  524. * Set key size descriptor field.
  525. *
  526. * @pdesc: pointer HW descriptor struct
  527. * @size: key size in bytes (NOT size code)
  528. */
  529. static inline void set_key_size(struct cc_hw_desc *pdesc, u32 size)
  530. {
  531. pdesc->word[4] |= FIELD_PREP(WORD4_KEY_SIZE, size);
  532. }
  533. /*
  534. * Set AES key size.
  535. *
  536. * @pdesc: pointer HW descriptor struct
  537. * @size: key size in bytes (NOT size code)
  538. */
  539. static inline void set_key_size_aes(struct cc_hw_desc *pdesc, u32 size)
  540. {
  541. set_key_size(pdesc, ((size >> 3) - 2));
  542. }
  543. /*
  544. * Set DES key size.
  545. *
  546. * @pdesc: pointer HW descriptor struct
  547. * @size: key size in bytes (NOT size code)
  548. */
  549. static inline void set_key_size_des(struct cc_hw_desc *pdesc, u32 size)
  550. {
  551. set_key_size(pdesc, ((size >> 3) - 1));
  552. }
  553. /*
  554. * Set the descriptor setup mode
  555. *
  556. * @pdesc: pointer HW descriptor struct
  557. * @mode: Any one of the setup modes defined in [CC7x-DESC]
  558. */
  559. static inline void set_setup_mode(struct cc_hw_desc *pdesc,
  560. enum cc_setup_op mode)
  561. {
  562. pdesc->word[4] |= FIELD_PREP(WORD4_SETUP_OPERATION, mode);
  563. }
  564. /*
  565. * Set the descriptor cipher DO
  566. *
  567. * @pdesc: pointer HW descriptor struct
  568. * @config: Any one of the cipher do defined in [CC7x-DESC]
  569. */
  570. static inline void set_cipher_do(struct cc_hw_desc *pdesc,
  571. enum cc_hash_cipher_pad config)
  572. {
  573. pdesc->word[4] |= FIELD_PREP(WORD4_CIPHER_DO,
  574. (config & HW_KEY_MASK_CIPHER_DO));
  575. }
  576. #endif /*__CC_HW_QUEUE_DEFS_H__*/