sg_sw_sec4.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * CAAM/SEC 4.x functions for using scatterlists in caam driver
  4. *
  5. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  6. *
  7. */
  8. #ifndef _SG_SW_SEC4_H_
  9. #define _SG_SW_SEC4_H_
  10. #include "ctrl.h"
  11. #include "regs.h"
  12. #include "sg_sw_qm2.h"
  13. #include <soc/fsl/dpaa2-fd.h>
  14. struct sec4_sg_entry {
  15. u64 ptr;
  16. u32 len;
  17. u32 bpid_offset;
  18. };
  19. /*
  20. * convert single dma address to h/w link table format
  21. */
  22. static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
  23. dma_addr_t dma, u32 len, u16 offset)
  24. {
  25. if (caam_dpaa2) {
  26. dma_to_qm_sg_one((struct dpaa2_sg_entry *)sec4_sg_ptr, dma, len,
  27. offset);
  28. } else {
  29. sec4_sg_ptr->ptr = cpu_to_caam_dma64(dma);
  30. sec4_sg_ptr->len = cpu_to_caam32(len);
  31. sec4_sg_ptr->bpid_offset = cpu_to_caam32(offset &
  32. SEC4_SG_OFFSET_MASK);
  33. }
  34. #ifdef DEBUG
  35. print_hex_dump(KERN_ERR, "sec4_sg_ptr@: ",
  36. DUMP_PREFIX_ADDRESS, 16, 4, sec4_sg_ptr,
  37. sizeof(struct sec4_sg_entry), 1);
  38. #endif
  39. }
  40. /*
  41. * convert scatterlist to h/w link table format
  42. * but does not have final bit; instead, returns last entry
  43. */
  44. static inline struct sec4_sg_entry *
  45. sg_to_sec4_sg(struct scatterlist *sg, int sg_count,
  46. struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
  47. {
  48. while (sg_count) {
  49. dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg),
  50. sg_dma_len(sg), offset);
  51. sec4_sg_ptr++;
  52. sg = sg_next(sg);
  53. sg_count--;
  54. }
  55. return sec4_sg_ptr - 1;
  56. }
  57. static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
  58. {
  59. if (caam_dpaa2)
  60. dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
  61. else
  62. sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
  63. }
  64. /*
  65. * convert scatterlist to h/w link table format
  66. * scatterlist must have been previously dma mapped
  67. */
  68. static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int sg_count,
  69. struct sec4_sg_entry *sec4_sg_ptr,
  70. u16 offset)
  71. {
  72. sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset);
  73. sg_to_sec4_set_last(sec4_sg_ptr);
  74. }
  75. #endif /* _SG_SW_SEC4_H_ */