cc_hw_queue_defs.h 17 KB

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