desc_constr.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * caam descriptor construction helper functions
  4. *
  5. * Copyright 2008-2012 Freescale Semiconductor, Inc.
  6. */
  7. #ifndef DESC_CONSTR_H
  8. #define DESC_CONSTR_H
  9. #include "desc.h"
  10. #include "regs.h"
  11. #define IMMEDIATE (1 << 23)
  12. #define CAAM_CMD_SZ sizeof(u32)
  13. #define CAAM_PTR_SZ sizeof(dma_addr_t)
  14. #define CAAM_DESC_BYTES_MAX (CAAM_CMD_SZ * MAX_CAAM_DESCSIZE)
  15. #define DESC_JOB_IO_LEN (CAAM_CMD_SZ * 5 + CAAM_PTR_SZ * 3)
  16. #ifdef DEBUG
  17. #define PRINT_POS do { printk(KERN_DEBUG "%02d: %s\n", desc_len(desc),\
  18. &__func__[sizeof("append")]); } while (0)
  19. #else
  20. #define PRINT_POS
  21. #endif
  22. #define SET_OK_NO_PROP_ERRORS (IMMEDIATE | LDST_CLASS_DECO | \
  23. LDST_SRCDST_WORD_DECOCTRL | \
  24. (LDOFF_CHG_SHARE_OK_NO_PROP << \
  25. LDST_OFFSET_SHIFT))
  26. #define DISABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
  27. LDST_SRCDST_WORD_DECOCTRL | \
  28. (LDOFF_DISABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
  29. #define ENABLE_AUTO_INFO_FIFO (IMMEDIATE | LDST_CLASS_DECO | \
  30. LDST_SRCDST_WORD_DECOCTRL | \
  31. (LDOFF_ENABLE_AUTO_NFIFO << LDST_OFFSET_SHIFT))
  32. extern bool caam_little_end;
  33. static inline int desc_len(u32 * const desc)
  34. {
  35. return caam32_to_cpu(*desc) & HDR_DESCLEN_MASK;
  36. }
  37. static inline int desc_bytes(void * const desc)
  38. {
  39. return desc_len(desc) * CAAM_CMD_SZ;
  40. }
  41. static inline u32 *desc_end(u32 * const desc)
  42. {
  43. return desc + desc_len(desc);
  44. }
  45. static inline void *sh_desc_pdb(u32 * const desc)
  46. {
  47. return desc + 1;
  48. }
  49. static inline void init_desc(u32 * const desc, u32 options)
  50. {
  51. *desc = cpu_to_caam32((options | HDR_ONE) + 1);
  52. }
  53. static inline void init_sh_desc(u32 * const desc, u32 options)
  54. {
  55. PRINT_POS;
  56. init_desc(desc, CMD_SHARED_DESC_HDR | options);
  57. }
  58. static inline void init_sh_desc_pdb(u32 * const desc, u32 options,
  59. size_t pdb_bytes)
  60. {
  61. u32 pdb_len = (pdb_bytes + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
  62. init_sh_desc(desc, (((pdb_len + 1) << HDR_START_IDX_SHIFT) + pdb_len) |
  63. options);
  64. }
  65. static inline void init_job_desc(u32 * const desc, u32 options)
  66. {
  67. init_desc(desc, CMD_DESC_HDR | options);
  68. }
  69. static inline void init_job_desc_pdb(u32 * const desc, u32 options,
  70. size_t pdb_bytes)
  71. {
  72. u32 pdb_len = (pdb_bytes + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ;
  73. init_job_desc(desc, (((pdb_len + 1) << HDR_START_IDX_SHIFT)) | options);
  74. }
  75. static inline void append_ptr(u32 * const desc, dma_addr_t ptr)
  76. {
  77. dma_addr_t *offset = (dma_addr_t *)desc_end(desc);
  78. *offset = cpu_to_caam_dma(ptr);
  79. (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) +
  80. CAAM_PTR_SZ / CAAM_CMD_SZ);
  81. }
  82. static inline void init_job_desc_shared(u32 * const desc, dma_addr_t ptr,
  83. int len, u32 options)
  84. {
  85. PRINT_POS;
  86. init_job_desc(desc, HDR_SHARED | options |
  87. (len << HDR_START_IDX_SHIFT));
  88. append_ptr(desc, ptr);
  89. }
  90. static inline void append_data(u32 * const desc, const void *data, int len)
  91. {
  92. u32 *offset = desc_end(desc);
  93. if (len) /* avoid sparse warning: memcpy with byte count of 0 */
  94. memcpy(offset, data, len);
  95. (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) +
  96. (len + CAAM_CMD_SZ - 1) / CAAM_CMD_SZ);
  97. }
  98. static inline void append_cmd(u32 * const desc, u32 command)
  99. {
  100. u32 *cmd = desc_end(desc);
  101. *cmd = cpu_to_caam32(command);
  102. (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + 1);
  103. }
  104. #define append_u32 append_cmd
  105. static inline void append_u64(u32 * const desc, u64 data)
  106. {
  107. u32 *offset = desc_end(desc);
  108. /* Only 32-bit alignment is guaranteed in descriptor buffer */
  109. if (caam_little_end) {
  110. *offset = cpu_to_caam32(lower_32_bits(data));
  111. *(++offset) = cpu_to_caam32(upper_32_bits(data));
  112. } else {
  113. *offset = cpu_to_caam32(upper_32_bits(data));
  114. *(++offset) = cpu_to_caam32(lower_32_bits(data));
  115. }
  116. (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + 2);
  117. }
  118. /* Write command without affecting header, and return pointer to next word */
  119. static inline u32 *write_cmd(u32 * const desc, u32 command)
  120. {
  121. *desc = cpu_to_caam32(command);
  122. return desc + 1;
  123. }
  124. static inline void append_cmd_ptr(u32 * const desc, dma_addr_t ptr, int len,
  125. u32 command)
  126. {
  127. append_cmd(desc, command | len);
  128. append_ptr(desc, ptr);
  129. }
  130. /* Write length after pointer, rather than inside command */
  131. static inline void append_cmd_ptr_extlen(u32 * const desc, dma_addr_t ptr,
  132. unsigned int len, u32 command)
  133. {
  134. append_cmd(desc, command);
  135. if (!(command & (SQIN_RTO | SQIN_PRE)))
  136. append_ptr(desc, ptr);
  137. append_cmd(desc, len);
  138. }
  139. static inline void append_cmd_data(u32 * const desc, const void *data, int len,
  140. u32 command)
  141. {
  142. append_cmd(desc, command | IMMEDIATE | len);
  143. append_data(desc, data, len);
  144. }
  145. #define APPEND_CMD_RET(cmd, op) \
  146. static inline u32 *append_##cmd(u32 * const desc, u32 options) \
  147. { \
  148. u32 *cmd = desc_end(desc); \
  149. PRINT_POS; \
  150. append_cmd(desc, CMD_##op | options); \
  151. return cmd; \
  152. }
  153. APPEND_CMD_RET(jump, JUMP)
  154. APPEND_CMD_RET(move, MOVE)
  155. static inline void set_jump_tgt_here(u32 * const desc, u32 *jump_cmd)
  156. {
  157. *jump_cmd = cpu_to_caam32(caam32_to_cpu(*jump_cmd) |
  158. (desc_len(desc) - (jump_cmd - desc)));
  159. }
  160. static inline void set_move_tgt_here(u32 * const desc, u32 *move_cmd)
  161. {
  162. u32 val = caam32_to_cpu(*move_cmd);
  163. val &= ~MOVE_OFFSET_MASK;
  164. val |= (desc_len(desc) << (MOVE_OFFSET_SHIFT + 2)) & MOVE_OFFSET_MASK;
  165. *move_cmd = cpu_to_caam32(val);
  166. }
  167. #define APPEND_CMD(cmd, op) \
  168. static inline void append_##cmd(u32 * const desc, u32 options) \
  169. { \
  170. PRINT_POS; \
  171. append_cmd(desc, CMD_##op | options); \
  172. }
  173. APPEND_CMD(operation, OPERATION)
  174. #define APPEND_CMD_LEN(cmd, op) \
  175. static inline void append_##cmd(u32 * const desc, unsigned int len, \
  176. u32 options) \
  177. { \
  178. PRINT_POS; \
  179. append_cmd(desc, CMD_##op | len | options); \
  180. }
  181. APPEND_CMD_LEN(seq_load, SEQ_LOAD)
  182. APPEND_CMD_LEN(seq_store, SEQ_STORE)
  183. APPEND_CMD_LEN(seq_fifo_load, SEQ_FIFO_LOAD)
  184. APPEND_CMD_LEN(seq_fifo_store, SEQ_FIFO_STORE)
  185. #define APPEND_CMD_PTR(cmd, op) \
  186. static inline void append_##cmd(u32 * const desc, dma_addr_t ptr, \
  187. unsigned int len, u32 options) \
  188. { \
  189. PRINT_POS; \
  190. append_cmd_ptr(desc, ptr, len, CMD_##op | options); \
  191. }
  192. APPEND_CMD_PTR(key, KEY)
  193. APPEND_CMD_PTR(load, LOAD)
  194. APPEND_CMD_PTR(fifo_load, FIFO_LOAD)
  195. APPEND_CMD_PTR(fifo_store, FIFO_STORE)
  196. static inline void append_store(u32 * const desc, dma_addr_t ptr,
  197. unsigned int len, u32 options)
  198. {
  199. u32 cmd_src;
  200. cmd_src = options & LDST_SRCDST_MASK;
  201. append_cmd(desc, CMD_STORE | options | len);
  202. /* The following options do not require pointer */
  203. if (!(cmd_src == LDST_SRCDST_WORD_DESCBUF_SHARED ||
  204. cmd_src == LDST_SRCDST_WORD_DESCBUF_JOB ||
  205. cmd_src == LDST_SRCDST_WORD_DESCBUF_JOB_WE ||
  206. cmd_src == LDST_SRCDST_WORD_DESCBUF_SHARED_WE))
  207. append_ptr(desc, ptr);
  208. }
  209. #define APPEND_SEQ_PTR_INTLEN(cmd, op) \
  210. static inline void append_seq_##cmd##_ptr_intlen(u32 * const desc, \
  211. dma_addr_t ptr, \
  212. unsigned int len, \
  213. u32 options) \
  214. { \
  215. PRINT_POS; \
  216. if (options & (SQIN_RTO | SQIN_PRE)) \
  217. append_cmd(desc, CMD_SEQ_##op##_PTR | len | options); \
  218. else \
  219. append_cmd_ptr(desc, ptr, len, CMD_SEQ_##op##_PTR | options); \
  220. }
  221. APPEND_SEQ_PTR_INTLEN(in, IN)
  222. APPEND_SEQ_PTR_INTLEN(out, OUT)
  223. #define APPEND_CMD_PTR_TO_IMM(cmd, op) \
  224. static inline void append_##cmd##_as_imm(u32 * const desc, const void *data, \
  225. unsigned int len, u32 options) \
  226. { \
  227. PRINT_POS; \
  228. append_cmd_data(desc, data, len, CMD_##op | options); \
  229. }
  230. APPEND_CMD_PTR_TO_IMM(load, LOAD);
  231. APPEND_CMD_PTR_TO_IMM(fifo_load, FIFO_LOAD);
  232. #define APPEND_CMD_PTR_EXTLEN(cmd, op) \
  233. static inline void append_##cmd##_extlen(u32 * const desc, dma_addr_t ptr, \
  234. unsigned int len, u32 options) \
  235. { \
  236. PRINT_POS; \
  237. append_cmd_ptr_extlen(desc, ptr, len, CMD_##op | SQIN_EXT | options); \
  238. }
  239. APPEND_CMD_PTR_EXTLEN(seq_in_ptr, SEQ_IN_PTR)
  240. APPEND_CMD_PTR_EXTLEN(seq_out_ptr, SEQ_OUT_PTR)
  241. /*
  242. * Determine whether to store length internally or externally depending on
  243. * the size of its type
  244. */
  245. #define APPEND_CMD_PTR_LEN(cmd, op, type) \
  246. static inline void append_##cmd(u32 * const desc, dma_addr_t ptr, \
  247. type len, u32 options) \
  248. { \
  249. PRINT_POS; \
  250. if (sizeof(type) > sizeof(u16)) \
  251. append_##cmd##_extlen(desc, ptr, len, options); \
  252. else \
  253. append_##cmd##_intlen(desc, ptr, len, options); \
  254. }
  255. APPEND_CMD_PTR_LEN(seq_in_ptr, SEQ_IN_PTR, u32)
  256. APPEND_CMD_PTR_LEN(seq_out_ptr, SEQ_OUT_PTR, u32)
  257. /*
  258. * 2nd variant for commands whose specified immediate length differs
  259. * from length of immediate data provided, e.g., split keys
  260. */
  261. #define APPEND_CMD_PTR_TO_IMM2(cmd, op) \
  262. static inline void append_##cmd##_as_imm(u32 * const desc, const void *data, \
  263. unsigned int data_len, \
  264. unsigned int len, u32 options) \
  265. { \
  266. PRINT_POS; \
  267. append_cmd(desc, CMD_##op | IMMEDIATE | len | options); \
  268. append_data(desc, data, data_len); \
  269. }
  270. APPEND_CMD_PTR_TO_IMM2(key, KEY);
  271. #define APPEND_CMD_RAW_IMM(cmd, op, type) \
  272. static inline void append_##cmd##_imm_##type(u32 * const desc, type immediate, \
  273. u32 options) \
  274. { \
  275. PRINT_POS; \
  276. append_cmd(desc, CMD_##op | IMMEDIATE | options | sizeof(type)); \
  277. append_cmd(desc, immediate); \
  278. }
  279. APPEND_CMD_RAW_IMM(load, LOAD, u32);
  280. /*
  281. * ee - endianness
  282. * size - size of immediate type in bytes
  283. */
  284. #define APPEND_CMD_RAW_IMM2(cmd, op, ee, size) \
  285. static inline void append_##cmd##_imm_##ee##size(u32 *desc, \
  286. u##size immediate, \
  287. u32 options) \
  288. { \
  289. __##ee##size data = cpu_to_##ee##size(immediate); \
  290. PRINT_POS; \
  291. append_cmd(desc, CMD_##op | IMMEDIATE | options | sizeof(data)); \
  292. append_data(desc, &data, sizeof(data)); \
  293. }
  294. APPEND_CMD_RAW_IMM2(load, LOAD, be, 32);
  295. /*
  296. * Append math command. Only the last part of destination and source need to
  297. * be specified
  298. */
  299. #define APPEND_MATH(op, desc, dest, src_0, src_1, len) \
  300. append_cmd(desc, CMD_MATH | MATH_FUN_##op | MATH_DEST_##dest | \
  301. MATH_SRC0_##src_0 | MATH_SRC1_##src_1 | (u32)len);
  302. #define append_math_add(desc, dest, src0, src1, len) \
  303. APPEND_MATH(ADD, desc, dest, src0, src1, len)
  304. #define append_math_sub(desc, dest, src0, src1, len) \
  305. APPEND_MATH(SUB, desc, dest, src0, src1, len)
  306. #define append_math_add_c(desc, dest, src0, src1, len) \
  307. APPEND_MATH(ADDC, desc, dest, src0, src1, len)
  308. #define append_math_sub_b(desc, dest, src0, src1, len) \
  309. APPEND_MATH(SUBB, desc, dest, src0, src1, len)
  310. #define append_math_and(desc, dest, src0, src1, len) \
  311. APPEND_MATH(AND, desc, dest, src0, src1, len)
  312. #define append_math_or(desc, dest, src0, src1, len) \
  313. APPEND_MATH(OR, desc, dest, src0, src1, len)
  314. #define append_math_xor(desc, dest, src0, src1, len) \
  315. APPEND_MATH(XOR, desc, dest, src0, src1, len)
  316. #define append_math_lshift(desc, dest, src0, src1, len) \
  317. APPEND_MATH(LSHIFT, desc, dest, src0, src1, len)
  318. #define append_math_rshift(desc, dest, src0, src1, len) \
  319. APPEND_MATH(RSHIFT, desc, dest, src0, src1, len)
  320. #define append_math_ldshift(desc, dest, src0, src1, len) \
  321. APPEND_MATH(SHLD, desc, dest, src0, src1, len)
  322. /* Exactly one source is IMM. Data is passed in as u32 value */
  323. #define APPEND_MATH_IMM_u32(op, desc, dest, src_0, src_1, data) \
  324. do { \
  325. APPEND_MATH(op, desc, dest, src_0, src_1, CAAM_CMD_SZ); \
  326. append_cmd(desc, data); \
  327. } while (0)
  328. #define append_math_add_imm_u32(desc, dest, src0, src1, data) \
  329. APPEND_MATH_IMM_u32(ADD, desc, dest, src0, src1, data)
  330. #define append_math_sub_imm_u32(desc, dest, src0, src1, data) \
  331. APPEND_MATH_IMM_u32(SUB, desc, dest, src0, src1, data)
  332. #define append_math_add_c_imm_u32(desc, dest, src0, src1, data) \
  333. APPEND_MATH_IMM_u32(ADDC, desc, dest, src0, src1, data)
  334. #define append_math_sub_b_imm_u32(desc, dest, src0, src1, data) \
  335. APPEND_MATH_IMM_u32(SUBB, desc, dest, src0, src1, data)
  336. #define append_math_and_imm_u32(desc, dest, src0, src1, data) \
  337. APPEND_MATH_IMM_u32(AND, desc, dest, src0, src1, data)
  338. #define append_math_or_imm_u32(desc, dest, src0, src1, data) \
  339. APPEND_MATH_IMM_u32(OR, desc, dest, src0, src1, data)
  340. #define append_math_xor_imm_u32(desc, dest, src0, src1, data) \
  341. APPEND_MATH_IMM_u32(XOR, desc, dest, src0, src1, data)
  342. #define append_math_lshift_imm_u32(desc, dest, src0, src1, data) \
  343. APPEND_MATH_IMM_u32(LSHIFT, desc, dest, src0, src1, data)
  344. #define append_math_rshift_imm_u32(desc, dest, src0, src1, data) \
  345. APPEND_MATH_IMM_u32(RSHIFT, desc, dest, src0, src1, data)
  346. /* Exactly one source is IMM. Data is passed in as u64 value */
  347. #define APPEND_MATH_IMM_u64(op, desc, dest, src_0, src_1, data) \
  348. do { \
  349. u32 upper = (data >> 16) >> 16; \
  350. APPEND_MATH(op, desc, dest, src_0, src_1, CAAM_CMD_SZ * 2 | \
  351. (upper ? 0 : MATH_IFB)); \
  352. if (upper) \
  353. append_u64(desc, data); \
  354. else \
  355. append_u32(desc, lower_32_bits(data)); \
  356. } while (0)
  357. #define append_math_add_imm_u64(desc, dest, src0, src1, data) \
  358. APPEND_MATH_IMM_u64(ADD, desc, dest, src0, src1, data)
  359. #define append_math_sub_imm_u64(desc, dest, src0, src1, data) \
  360. APPEND_MATH_IMM_u64(SUB, desc, dest, src0, src1, data)
  361. #define append_math_add_c_imm_u64(desc, dest, src0, src1, data) \
  362. APPEND_MATH_IMM_u64(ADDC, desc, dest, src0, src1, data)
  363. #define append_math_sub_b_imm_u64(desc, dest, src0, src1, data) \
  364. APPEND_MATH_IMM_u64(SUBB, desc, dest, src0, src1, data)
  365. #define append_math_and_imm_u64(desc, dest, src0, src1, data) \
  366. APPEND_MATH_IMM_u64(AND, desc, dest, src0, src1, data)
  367. #define append_math_or_imm_u64(desc, dest, src0, src1, data) \
  368. APPEND_MATH_IMM_u64(OR, desc, dest, src0, src1, data)
  369. #define append_math_xor_imm_u64(desc, dest, src0, src1, data) \
  370. APPEND_MATH_IMM_u64(XOR, desc, dest, src0, src1, data)
  371. #define append_math_lshift_imm_u64(desc, dest, src0, src1, data) \
  372. APPEND_MATH_IMM_u64(LSHIFT, desc, dest, src0, src1, data)
  373. #define append_math_rshift_imm_u64(desc, dest, src0, src1, data) \
  374. APPEND_MATH_IMM_u64(RSHIFT, desc, dest, src0, src1, data)
  375. /**
  376. * struct alginfo - Container for algorithm details
  377. * @algtype: algorithm selector; for valid values, see documentation of the
  378. * functions where it is used.
  379. * @keylen: length of the provided algorithm key, in bytes
  380. * @keylen_pad: padded length of the provided algorithm key, in bytes
  381. * @key: address where algorithm key resides; virtual address if key_inline
  382. * is true, dma (bus) address if key_inline is false.
  383. * @key_inline: true - key can be inlined in the descriptor; false - key is
  384. * referenced by the descriptor
  385. */
  386. struct alginfo {
  387. u32 algtype;
  388. unsigned int keylen;
  389. unsigned int keylen_pad;
  390. union {
  391. dma_addr_t key_dma;
  392. const void *key_virt;
  393. };
  394. bool key_inline;
  395. };
  396. /**
  397. * desc_inline_query() - Provide indications on which data items can be inlined
  398. * and which shall be referenced in a shared descriptor.
  399. * @sd_base_len: Shared descriptor base length - bytes consumed by the commands,
  400. * excluding the data items to be inlined (or corresponding
  401. * pointer if an item is not inlined). Each cnstr_* function that
  402. * generates descriptors should have a define mentioning
  403. * corresponding length.
  404. * @jd_len: Maximum length of the job descriptor(s) that will be used
  405. * together with the shared descriptor.
  406. * @data_len: Array of lengths of the data items trying to be inlined
  407. * @inl_mask: 32bit mask with bit x = 1 if data item x can be inlined, 0
  408. * otherwise.
  409. * @count: Number of data items (size of @data_len array); must be <= 32
  410. *
  411. * Return: 0 if data can be inlined / referenced, negative value if not. If 0,
  412. * check @inl_mask for details.
  413. */
  414. static inline int desc_inline_query(unsigned int sd_base_len,
  415. unsigned int jd_len, unsigned int *data_len,
  416. u32 *inl_mask, unsigned int count)
  417. {
  418. int rem_bytes = (int)(CAAM_DESC_BYTES_MAX - sd_base_len - jd_len);
  419. unsigned int i;
  420. *inl_mask = 0;
  421. for (i = 0; (i < count) && (rem_bytes > 0); i++) {
  422. if (rem_bytes - (int)(data_len[i] +
  423. (count - i - 1) * CAAM_PTR_SZ) >= 0) {
  424. rem_bytes -= data_len[i];
  425. *inl_mask |= (1 << i);
  426. } else {
  427. rem_bytes -= CAAM_PTR_SZ;
  428. }
  429. }
  430. return (rem_bytes >= 0) ? 0 : -1;
  431. }
  432. /**
  433. * append_proto_dkp - Derived Key Protocol (DKP): key -> split key
  434. * @desc: pointer to buffer used for descriptor construction
  435. * @adata: pointer to authentication transform definitions.
  436. * keylen should be the length of initial key, while keylen_pad
  437. * the length of the derived (split) key.
  438. * Valid algorithm values - one of OP_ALG_ALGSEL_{MD5, SHA1, SHA224,
  439. * SHA256, SHA384, SHA512}.
  440. */
  441. static inline void append_proto_dkp(u32 * const desc, struct alginfo *adata)
  442. {
  443. u32 protid;
  444. /*
  445. * Quick & dirty translation from OP_ALG_ALGSEL_{MD5, SHA*}
  446. * to OP_PCLID_DKP_{MD5, SHA*}
  447. */
  448. protid = (adata->algtype & OP_ALG_ALGSEL_SUBMASK) |
  449. (0x20 << OP_ALG_ALGSEL_SHIFT);
  450. if (adata->key_inline) {
  451. int words;
  452. append_operation(desc, OP_TYPE_UNI_PROTOCOL | protid |
  453. OP_PCL_DKP_SRC_IMM | OP_PCL_DKP_DST_IMM |
  454. adata->keylen);
  455. append_data(desc, adata->key_virt, adata->keylen);
  456. /* Reserve space in descriptor buffer for the derived key */
  457. words = (ALIGN(adata->keylen_pad, CAAM_CMD_SZ) -
  458. ALIGN(adata->keylen, CAAM_CMD_SZ)) / CAAM_CMD_SZ;
  459. if (words)
  460. (*desc) = cpu_to_caam32(caam32_to_cpu(*desc) + words);
  461. } else {
  462. append_operation(desc, OP_TYPE_UNI_PROTOCOL | protid |
  463. OP_PCL_DKP_SRC_PTR | OP_PCL_DKP_DST_PTR |
  464. adata->keylen);
  465. append_ptr(desc, adata->key_dma);
  466. }
  467. }
  468. #endif /* DESC_CONSTR_H */