knav_dma.h 5.1 KB

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