descs_com.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*******************************************************************************
  2. Header File to describe Normal/enhanced descriptor functions used for RING
  3. and CHAINED modes.
  4. Copyright(C) 2011 STMicroelectronics Ltd
  5. It defines all the functions used to handle the normal/enhanced
  6. descriptors in case of the DMA is configured to work in chained or
  7. in ring mode.
  8. This program is free software; you can redistribute it and/or modify it
  9. under the terms and conditions of the GNU General Public License,
  10. version 2, as published by the Free Software Foundation.
  11. This program is distributed in the hope it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. more details.
  15. The full GNU General Public License is included in this distribution in
  16. the file called "COPYING".
  17. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  18. *******************************************************************************/
  19. #ifndef __DESC_COM_H__
  20. #define __DESC_COM_H__
  21. /* Specific functions used for Ring mode */
  22. /* Enhanced descriptors */
  23. static inline void ehn_desc_rx_set_on_ring(struct dma_desc *p, int end,
  24. int bfsize)
  25. {
  26. if (bfsize == BUF_SIZE_16KiB)
  27. p->des1 |= cpu_to_le32((BUF_SIZE_8KiB
  28. << ERDES1_BUFFER2_SIZE_SHIFT)
  29. & ERDES1_BUFFER2_SIZE_MASK);
  30. if (end)
  31. p->des1 |= cpu_to_le32(ERDES1_END_RING);
  32. }
  33. static inline void enh_desc_end_tx_desc_on_ring(struct dma_desc *p, int end)
  34. {
  35. if (end)
  36. p->des0 |= cpu_to_le32(ETDES0_END_RING);
  37. else
  38. p->des0 &= cpu_to_le32(~ETDES0_END_RING);
  39. }
  40. static inline void enh_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
  41. {
  42. if (unlikely(len > BUF_SIZE_4KiB)) {
  43. p->des1 |= cpu_to_le32((((len - BUF_SIZE_4KiB)
  44. << ETDES1_BUFFER2_SIZE_SHIFT)
  45. & ETDES1_BUFFER2_SIZE_MASK) | (BUF_SIZE_4KiB
  46. & ETDES1_BUFFER1_SIZE_MASK));
  47. } else
  48. p->des1 |= cpu_to_le32((len & ETDES1_BUFFER1_SIZE_MASK));
  49. }
  50. /* Normal descriptors */
  51. static inline void ndesc_rx_set_on_ring(struct dma_desc *p, int end, int bfsize)
  52. {
  53. if (bfsize >= BUF_SIZE_2KiB) {
  54. int bfsize2;
  55. bfsize2 = min(bfsize - BUF_SIZE_2KiB + 1, BUF_SIZE_2KiB - 1);
  56. p->des1 |= cpu_to_le32((bfsize2 << RDES1_BUFFER2_SIZE_SHIFT)
  57. & RDES1_BUFFER2_SIZE_MASK);
  58. }
  59. if (end)
  60. p->des1 |= cpu_to_le32(RDES1_END_RING);
  61. }
  62. static inline void ndesc_end_tx_desc_on_ring(struct dma_desc *p, int end)
  63. {
  64. if (end)
  65. p->des1 |= cpu_to_le32(TDES1_END_RING);
  66. else
  67. p->des1 &= cpu_to_le32(~TDES1_END_RING);
  68. }
  69. static inline void norm_set_tx_desc_len_on_ring(struct dma_desc *p, int len)
  70. {
  71. if (unlikely(len > BUF_SIZE_2KiB)) {
  72. unsigned int buffer1 = (BUF_SIZE_2KiB - 1)
  73. & TDES1_BUFFER1_SIZE_MASK;
  74. p->des1 |= cpu_to_le32((((len - buffer1)
  75. << TDES1_BUFFER2_SIZE_SHIFT)
  76. & TDES1_BUFFER2_SIZE_MASK) | buffer1);
  77. } else
  78. p->des1 |= cpu_to_le32((len & TDES1_BUFFER1_SIZE_MASK));
  79. }
  80. /* Specific functions used for Chain mode */
  81. /* Enhanced descriptors */
  82. static inline void ehn_desc_rx_set_on_chain(struct dma_desc *p)
  83. {
  84. p->des1 |= cpu_to_le32(ERDES1_SECOND_ADDRESS_CHAINED);
  85. }
  86. static inline void enh_desc_end_tx_desc_on_chain(struct dma_desc *p)
  87. {
  88. p->des0 |= cpu_to_le32(ETDES0_SECOND_ADDRESS_CHAINED);
  89. }
  90. static inline void enh_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
  91. {
  92. p->des1 |= cpu_to_le32(len & ETDES1_BUFFER1_SIZE_MASK);
  93. }
  94. /* Normal descriptors */
  95. static inline void ndesc_rx_set_on_chain(struct dma_desc *p, int end)
  96. {
  97. p->des1 |= cpu_to_le32(RDES1_SECOND_ADDRESS_CHAINED);
  98. }
  99. static inline void ndesc_tx_set_on_chain(struct dma_desc *p)
  100. {
  101. p->des1 |= cpu_to_le32(TDES1_SECOND_ADDRESS_CHAINED);
  102. }
  103. static inline void norm_set_tx_desc_len_on_chain(struct dma_desc *p, int len)
  104. {
  105. p->des1 |= cpu_to_le32(len & TDES1_BUFFER1_SIZE_MASK);
  106. }
  107. #endif /* __DESC_COM_H__ */