sg_sw_qm2.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2015-2016 Freescale Semiconductor, Inc.
  3. * Copyright 2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the names of the above-listed copyright holders nor the
  13. * names of any contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. *
  17. * ALTERNATIVELY, this software may be distributed under the terms of the
  18. * GNU General Public License ("GPL") as published by the Free Software
  19. * Foundation, either version 2 of that License or (at your option) any
  20. * later version.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef _SG_SW_QM2_H_
  35. #define _SG_SW_QM2_H_
  36. #include <soc/fsl/dpaa2-fd.h>
  37. static inline void dma_to_qm_sg_one(struct dpaa2_sg_entry *qm_sg_ptr,
  38. dma_addr_t dma, u32 len, u16 offset)
  39. {
  40. dpaa2_sg_set_addr(qm_sg_ptr, dma);
  41. dpaa2_sg_set_format(qm_sg_ptr, dpaa2_sg_single);
  42. dpaa2_sg_set_final(qm_sg_ptr, false);
  43. dpaa2_sg_set_len(qm_sg_ptr, len);
  44. dpaa2_sg_set_bpid(qm_sg_ptr, 0);
  45. dpaa2_sg_set_offset(qm_sg_ptr, offset);
  46. }
  47. /*
  48. * convert scatterlist to h/w link table format
  49. * but does not have final bit; instead, returns last entry
  50. */
  51. static inline struct dpaa2_sg_entry *
  52. sg_to_qm_sg(struct scatterlist *sg, int sg_count,
  53. struct dpaa2_sg_entry *qm_sg_ptr, u16 offset)
  54. {
  55. while (sg_count && sg) {
  56. dma_to_qm_sg_one(qm_sg_ptr, sg_dma_address(sg),
  57. sg_dma_len(sg), offset);
  58. qm_sg_ptr++;
  59. sg = sg_next(sg);
  60. sg_count--;
  61. }
  62. return qm_sg_ptr - 1;
  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_qm_sg_last(struct scatterlist *sg, int sg_count,
  69. struct dpaa2_sg_entry *qm_sg_ptr,
  70. u16 offset)
  71. {
  72. qm_sg_ptr = sg_to_qm_sg(sg, sg_count, qm_sg_ptr, offset);
  73. dpaa2_sg_set_final(qm_sg_ptr, true);
  74. }
  75. #endif /* _SG_SW_QM2_H_ */