sg_sw_sec4.h 2.1 KB

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