sg_sw_sec4.h 2.0 KB

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