sg_sw_sec4.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. print_hex_dump_debug("sec4_sg_ptr@: ", DUMP_PREFIX_ADDRESS, 16, 4,
  35. sec4_sg_ptr, sizeof(struct sec4_sg_entry), 1);
  36. }
  37. /*
  38. * convert scatterlist to h/w link table format
  39. * but does not have final bit; instead, returns last entry
  40. */
  41. static inline struct sec4_sg_entry *
  42. sg_to_sec4_sg(struct scatterlist *sg, int len,
  43. struct sec4_sg_entry *sec4_sg_ptr, u16 offset)
  44. {
  45. int ent_len;
  46. while (len) {
  47. ent_len = min_t(int, sg_dma_len(sg), len);
  48. dma_to_sec4_sg_one(sec4_sg_ptr, sg_dma_address(sg), ent_len,
  49. offset);
  50. sec4_sg_ptr++;
  51. sg = sg_next(sg);
  52. len -= ent_len;
  53. }
  54. return sec4_sg_ptr - 1;
  55. }
  56. static inline void sg_to_sec4_set_last(struct sec4_sg_entry *sec4_sg_ptr)
  57. {
  58. if (caam_dpaa2)
  59. dpaa2_sg_set_final((struct dpaa2_sg_entry *)sec4_sg_ptr, true);
  60. else
  61. sec4_sg_ptr->len |= cpu_to_caam32(SEC4_SG_LEN_FIN);
  62. }
  63. /*
  64. * convert scatterlist to h/w link table format
  65. * scatterlist must have been previously dma mapped
  66. */
  67. static inline void sg_to_sec4_sg_last(struct scatterlist *sg, int len,
  68. struct sec4_sg_entry *sec4_sg_ptr,
  69. u16 offset)
  70. {
  71. sec4_sg_ptr = sg_to_sec4_sg(sg, len, sec4_sg_ptr, offset);
  72. sg_to_sec4_set_last(sec4_sg_ptr);
  73. }
  74. #endif /* _SG_SW_SEC4_H_ */