sg_sw_sec4.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * CAAM/SEC 4.x functions for using scatterlists in caam driver
  3. *
  4. * Copyright 2008-2011 Freescale Semiconductor, Inc.
  5. *
  6. */
  7. struct sec4_sg_entry;
  8. /*
  9. * convert single dma address to h/w link table format
  10. */
  11. static inline void dma_to_sec4_sg_one(struct sec4_sg_entry *sec4_sg_ptr,
  12. dma_addr_t dma, u32 len, u32 offset)
  13. {
  14. sec4_sg_ptr->ptr = dma;
  15. sec4_sg_ptr->len = len;
  16. sec4_sg_ptr->buf_pool_id = 0;
  17. sec4_sg_ptr->offset = offset;
  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, u32 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. u32 offset)
  48. {
  49. sec4_sg_ptr = sg_to_sec4_sg(sg, sg_count, sec4_sg_ptr, offset);
  50. sec4_sg_ptr->len |= 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. }