knav_dma.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /*
  2. * Copyright (C) 2014 Texas Instruments Incorporated
  3. * Authors: Sandeep Nair <sandeep_n@ti.com
  4. * Cyril Chemparathy <cyril@ti.com
  5. Santosh Shilimkar <santosh.shilimkar@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation version 2.
  10. *
  11. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  12. * kind, whether express or implied; without even the implied warranty
  13. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. */
  16. #ifndef __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__
  17. #define __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__
  18. /*
  19. * PKTDMA descriptor manipulation macros for host packet descriptor
  20. */
  21. #define MASK(x) (BIT(x) - 1)
  22. #define KNAV_DMA_DESC_PKT_LEN_MASK MASK(22)
  23. #define KNAV_DMA_DESC_PKT_LEN_SHIFT 0
  24. #define KNAV_DMA_DESC_PS_INFO_IN_SOP BIT(22)
  25. #define KNAV_DMA_DESC_PS_INFO_IN_DESC 0
  26. #define KNAV_DMA_DESC_TAG_MASK MASK(8)
  27. #define KNAV_DMA_DESC_SAG_HI_SHIFT 24
  28. #define KNAV_DMA_DESC_STAG_LO_SHIFT 16
  29. #define KNAV_DMA_DESC_DTAG_HI_SHIFT 8
  30. #define KNAV_DMA_DESC_DTAG_LO_SHIFT 0
  31. #define KNAV_DMA_DESC_HAS_EPIB BIT(31)
  32. #define KNAV_DMA_DESC_NO_EPIB 0
  33. #define KNAV_DMA_DESC_PSLEN_SHIFT 24
  34. #define KNAV_DMA_DESC_PSLEN_MASK MASK(6)
  35. #define KNAV_DMA_DESC_ERR_FLAG_SHIFT 20
  36. #define KNAV_DMA_DESC_ERR_FLAG_MASK MASK(4)
  37. #define KNAV_DMA_DESC_PSFLAG_SHIFT 16
  38. #define KNAV_DMA_DESC_PSFLAG_MASK MASK(4)
  39. #define KNAV_DMA_DESC_RETQ_SHIFT 0
  40. #define KNAV_DMA_DESC_RETQ_MASK MASK(14)
  41. #define KNAV_DMA_DESC_BUF_LEN_MASK MASK(22)
  42. #define KNAV_DMA_NUM_EPIB_WORDS 4
  43. #define KNAV_DMA_NUM_PS_WORDS 16
  44. #define KNAV_DMA_FDQ_PER_CHAN 4
  45. /* Tx channel scheduling priority */
  46. enum knav_dma_tx_priority {
  47. DMA_PRIO_HIGH = 0,
  48. DMA_PRIO_MED_H,
  49. DMA_PRIO_MED_L,
  50. DMA_PRIO_LOW
  51. };
  52. /* Rx channel error handling mode during buffer starvation */
  53. enum knav_dma_rx_err_mode {
  54. DMA_DROP = 0,
  55. DMA_RETRY
  56. };
  57. /* Rx flow size threshold configuration */
  58. enum knav_dma_rx_thresholds {
  59. DMA_THRESH_NONE = 0,
  60. DMA_THRESH_0 = 1,
  61. DMA_THRESH_0_1 = 3,
  62. DMA_THRESH_0_1_2 = 7
  63. };
  64. /* Descriptor type */
  65. enum knav_dma_desc_type {
  66. DMA_DESC_HOST = 0,
  67. DMA_DESC_MONOLITHIC = 2
  68. };
  69. /**
  70. * struct knav_dma_tx_cfg: Tx channel configuration
  71. * @filt_einfo: Filter extended packet info
  72. * @filt_pswords: Filter PS words present
  73. * @knav_dma_tx_priority: Tx channel scheduling priority
  74. */
  75. struct knav_dma_tx_cfg {
  76. bool filt_einfo;
  77. bool filt_pswords;
  78. enum knav_dma_tx_priority priority;
  79. };
  80. /**
  81. * struct knav_dma_rx_cfg: Rx flow configuration
  82. * @einfo_present: Extended packet info present
  83. * @psinfo_present: PS words present
  84. * @knav_dma_rx_err_mode: Error during buffer starvation
  85. * @knav_dma_desc_type: Host or Monolithic desc
  86. * @psinfo_at_sop: PS word located at start of packet
  87. * @sop_offset: Start of packet offset
  88. * @dst_q: Destination queue for a given flow
  89. * @thresh: Rx flow size threshold
  90. * @fdq[]: Free desc Queue array
  91. * @sz_thresh0: RX packet size threshold 0
  92. * @sz_thresh1: RX packet size threshold 1
  93. * @sz_thresh2: RX packet size threshold 2
  94. */
  95. struct knav_dma_rx_cfg {
  96. bool einfo_present;
  97. bool psinfo_present;
  98. enum knav_dma_rx_err_mode err_mode;
  99. enum knav_dma_desc_type desc_type;
  100. bool psinfo_at_sop;
  101. unsigned int sop_offset;
  102. unsigned int dst_q;
  103. enum knav_dma_rx_thresholds thresh;
  104. unsigned int fdq[KNAV_DMA_FDQ_PER_CHAN];
  105. unsigned int sz_thresh0;
  106. unsigned int sz_thresh1;
  107. unsigned int sz_thresh2;
  108. };
  109. /**
  110. * struct knav_dma_cfg: Pktdma channel configuration
  111. * @sl_cfg: Slave configuration
  112. * @tx: Tx channel configuration
  113. * @rx: Rx flow configuration
  114. */
  115. struct knav_dma_cfg {
  116. enum dma_transfer_direction direction;
  117. union {
  118. struct knav_dma_tx_cfg tx;
  119. struct knav_dma_rx_cfg rx;
  120. } u;
  121. };
  122. /**
  123. * struct knav_dma_desc: Host packet descriptor layout
  124. * @desc_info: Descriptor information like id, type, length
  125. * @tag_info: Flow tag info written in during RX
  126. * @packet_info: Queue Manager, policy, flags etc
  127. * @buff_len: Buffer length in bytes
  128. * @buff: Buffer pointer
  129. * @next_desc: For chaining the descriptors
  130. * @orig_len: length since 'buff_len' can be overwritten
  131. * @orig_buff: buff pointer since 'buff' can be overwritten
  132. * @epib: Extended packet info block
  133. * @psdata: Protocol specific
  134. */
  135. struct knav_dma_desc {
  136. u32 desc_info;
  137. u32 tag_info;
  138. u32 packet_info;
  139. u32 buff_len;
  140. u32 buff;
  141. u32 next_desc;
  142. u32 orig_len;
  143. u32 orig_buff;
  144. u32 epib[KNAV_DMA_NUM_EPIB_WORDS];
  145. u32 psdata[KNAV_DMA_NUM_PS_WORDS];
  146. u32 pad[4];
  147. } ____cacheline_aligned;
  148. #if IS_ENABLED(CONFIG_KEYSTONE_NAVIGATOR_DMA)
  149. void *knav_dma_open_channel(struct device *dev, const char *name,
  150. struct knav_dma_cfg *config);
  151. void knav_dma_close_channel(void *channel);
  152. #else
  153. static inline void *knav_dma_open_channel(struct device *dev, const char *name,
  154. struct knav_dma_cfg *config)
  155. {
  156. return (void *) NULL;
  157. }
  158. static inline void knav_dma_close_channel(void *channel)
  159. {}
  160. #endif
  161. #endif /* __SOC_TI_KEYSTONE_NAVIGATOR_DMA_H__ */