hal_internal.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * Copyright (c) 2016, The Linux Foundation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are
  6. * 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
  10. * copyright notice, this list of conditions and the following
  11. * disclaimer in the documentation and/or other materials provided
  12. * with the distribution.
  13. * * Neither the name of The Linux Foundation nor the names of its
  14. * contributors may be used to endorse or promote products derived
  15. * from this software without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
  18. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
  21. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  22. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  23. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  25. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  26. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
  27. * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef _HAL_INTERNAL_H_
  30. #define _HAL_INTERNAL_H_
  31. #include "qdf_types.h"
  32. #include "qdf_lock.h"
  33. #include "hw/reg_header/wcss/wcss_seq_hwiobase.h"
  34. #include "hw/reg_header/wcss/wcss_seq_hwioreg.h"
  35. #include "hw/data/common/sw_xml_headers.h"
  36. #include "hw/data/datastruct/reo_destination_ring.h"
  37. #include "hw/data/tlv_32/tcl_data_cmd.h"
  38. #include "hw/data/common/tlv_hdr.h"
  39. /* TBD: This should be movded to shared HW header file */
  40. enum hal_srng_ring_id {
  41. /* UMAC rings */
  42. HAL_SRNG_REO2SW1 = 0,
  43. HAL_SRNG_REO2SW2 = 1,
  44. HAL_SRNG_REO2SW3 = 2,
  45. HAL_SRNG_REO2SW4 = 3,
  46. HAL_SRNG_REO2TCL = 4,
  47. HAL_SRNG_SW2REO = 5,
  48. /* 6-7 unused */
  49. HAL_SRNG_REO_CMD = 8,
  50. HAL_SRNG_REO_STATUS = 9,
  51. /* 10-15 unused */
  52. HAL_SRNG_SW2TCL1 = 16,
  53. HAL_SRNG_SW2TCL2 = 17,
  54. HAL_SRNG_SW2TCL3 = 18,
  55. HAL_SRNG_SW2TCL4 = 19, /* FW2TCL ring */
  56. /* 20-23 unused */
  57. HAL_SRNG_SW2TCL_CMD = 24,
  58. HAL_SRNG_TCL_STATUS = 25,
  59. /* 26-31 unused */
  60. HAL_SRNG_CE_0_SRC = 32,
  61. HAL_SRNG_CE_1_SRC = 33,
  62. HAL_SRNG_CE_2_SRC = 34,
  63. HAL_SRNG_CE_3_SRC = 35,
  64. HAL_SRNG_CE_4_SRC = 36,
  65. HAL_SRNG_CE_5_SRC = 37,
  66. HAL_SRNG_CE_6_SRC = 38,
  67. HAL_SRNG_CE_7_SRC = 39,
  68. HAL_SRNG_CE_8_SRC = 40,
  69. HAL_SRNG_CE_9_SRC = 41,
  70. HAL_SRNG_CE_10_SRC = 42,
  71. HAL_SRNG_CE_11_SRC = 43,
  72. /* 44-55 unused */
  73. HAL_SRNG_CE_0_DST = 56,
  74. HAL_SRNG_CE_1_DST = 57,
  75. HAL_SRNG_CE_2_DST = 58,
  76. HAL_SRNG_CE_3_DST = 59,
  77. HAL_SRNG_CE_4_DST = 60,
  78. HAL_SRNG_CE_5_DST = 61,
  79. HAL_SRNG_CE_6_DST = 62,
  80. HAL_SRNG_CE_7_DST = 63,
  81. HAL_SRNG_CE_8_DST = 64,
  82. HAL_SRNG_CE_9_DST = 65,
  83. HAL_SRNG_CE_10_DST = 66,
  84. HAL_SRNG_CE_11_DST = 67,
  85. /* 68-79 unused */
  86. HAL_SRNG_CE_0_DST_STATUS = 80,
  87. HAL_SRNG_CE_1_DST_STATUS = 81,
  88. HAL_SRNG_CE_2_DST_STATUS = 82,
  89. HAL_SRNG_CE_3_DST_STATUS = 83,
  90. HAL_SRNG_CE_4_DST_STATUS = 84,
  91. HAL_SRNG_CE_5_DST_STATUS = 85,
  92. HAL_SRNG_CE_6_DST_STATUS = 86,
  93. HAL_SRNG_CE_7_DST_STATUS = 87,
  94. HAL_SRNG_CE_8_DST_STATUS = 88,
  95. HAL_SRNG_CE_9_DST_STATUS = 89,
  96. HAL_SRNG_CE_10_DST_STATUS = 90,
  97. HAL_SRNG_CE_11_DST_STATUS = 91,
  98. /* 92-103 unused */
  99. HAL_SRNG_WBM_IDLE_LINK = 104,
  100. HAL_SRNG_WBM_SW_RELEASE = 105,
  101. HAL_SRNG_WBM2SW0_RELEASE = 106,
  102. HAL_SRNG_WBM2SW1_RELEASE = 107,
  103. HAL_SRNG_WBM2SW2_RELEASE = 108,
  104. HAL_SRNG_WBM2SW3_RELEASE = 109,
  105. /* 110-127 unused */
  106. HAL_SRNG_UMAC_ID_END = 127,
  107. /* LMAC rings - The following set will be replicated for each LMAC */
  108. HAL_SRNG_LMAC1_ID_START = 128,
  109. HAL_SRNG_WMAC1_SW2RXDMA0_BUF = HAL_SRNG_LMAC1_ID_START,
  110. HAL_SRNG_WMAC1_SW2RXDMA1_BUF = 129,
  111. HAL_SRNG_WMAC1_SW2RXDMA0_STATBUF = 130,
  112. HAL_SRNG_WMAC1_SW2RXDMA1_STATBUF = 131,
  113. HAL_SRNG_WMAC1_RXDMA2SW0 = 132,
  114. HAL_SRNG_WMAC1_RXDMA2SW1 = 133,
  115. /* 134-142 unused */
  116. HAL_SRNG_LMAC1_ID_END = 143
  117. };
  118. #define HAL_SRNG_REO_EXCEPTION HAL_SRNG_REO2SW1
  119. #define HAL_MAX_LMACS 3
  120. #define HAL_MAX_RINGS_PER_LMAC (HAL_SRNG_LMAC1_ID_END - HAL_SRNG_LMAC1_ID_START)
  121. #define HAL_MAX_LMAC_RINGS (HAL_MAX_LMACS * HAL_MAX_RINGS_PER_LMAC)
  122. #define HAL_SRNG_ID_MAX (HAL_SRNG_UMAC_ID_END + HAL_MAX_LMAC_RINGS)
  123. enum hal_srng_dir {
  124. HAL_SRNG_SRC_RING,
  125. HAL_SRNG_DST_RING
  126. };
  127. /* Lock wrappers for SRNG */
  128. #define hal_srng_lock_t qdf_spinlock_t
  129. #define SRNG_LOCK_INIT(_lock) qdf_spinlock_create(_lock)
  130. #define SRNG_LOCK(_lock) qdf_spinlock_acquire(_lock)
  131. #define SRNG_UNLOCK(_lock) qdf_spinlock_release(_lock)
  132. #define SRNG_LOCK_DESTROY(_lock) qdf_spinlock_destroy(_lock)
  133. #define MAX_SRNG_REG_GROUPS 2
  134. /* Common SRNG ring structure for source and destination rings */
  135. struct hal_srng {
  136. /* Unique SRNG ring ID */
  137. uint8_t ring_id;
  138. /* Ring initialization done */
  139. uint8_t initialized;
  140. /* Interrupt/MSI value assigned to this ring */
  141. int irq;
  142. /* Physical base address of the ring */
  143. qdf_dma_addr_t ring_base_paddr;
  144. /* Virtual base address of the ring */
  145. uint32_t *ring_base_vaddr;
  146. /* Number of entries in ring */
  147. uint32_t num_entries;
  148. /* Ring size */
  149. uint32_t ring_size;
  150. /* Ring size mask */
  151. uint32_t ring_size_mask;
  152. /* Size of ring entry */
  153. uint32_t entry_size;
  154. /* Interrupt timer threshold – in micro seconds */
  155. uint32_t intr_timer_thres_us;
  156. /* Interrupt batch counter threshold – in number of ring entries */
  157. uint32_t intr_batch_cntr_thres_entries;
  158. /* MSI Address */
  159. qdf_dma_addr_t msi_addr;
  160. /* MSI data */
  161. uint32_t msi_data;
  162. /* Misc flags */
  163. uint32_t flags;
  164. /* Lock for serializing ring index updates */
  165. hal_srng_lock_t lock;
  166. /* Start offset of SRNG register groups for this ring
  167. * TBD: See if this is required - register address can be derived
  168. * from ring ID
  169. */
  170. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  171. /* Source or Destination ring */
  172. enum hal_srng_dir ring_dir;
  173. union {
  174. struct {
  175. /* SW tail pointer */
  176. uint32_t tp;
  177. /* Shadow head pointer location to be updated by HW */
  178. uint32_t *hp_addr;
  179. /* Cached head pointer */
  180. uint32_t cached_hp;
  181. /* Tail pointer location to be updated by SW – This
  182. * will be a register address and need not be
  183. * accessed through SW structure */
  184. uint32_t *tp_addr;
  185. /* Current SW loop cnt */
  186. int loop_cnt;
  187. } dst_ring;
  188. struct {
  189. /* SW head pointer */
  190. uint32_t hp;
  191. /* SW reap head pointer */
  192. uint32_t reap_hp;
  193. /* Shadow tail pointer location to be updated by HW */
  194. uint32_t *tp_addr;
  195. /* Cached tail pointer */
  196. uint32_t cached_tp;
  197. /* Head pointer location to be updated by SW – This
  198. * will be a register address and need not be accessed
  199. * through SW structure */
  200. uint32_t *hp_addr;
  201. /* Low threshold – in number of ring entries */
  202. uint32_t low_threshold;
  203. } src_ring;
  204. } u;
  205. };
  206. /* HW SRNG configuration table */
  207. struct hal_hw_srng_config {
  208. int start_ring_id;
  209. uint16_t max_rings;
  210. uint16_t entry_size;
  211. uint32_t reg_start[MAX_SRNG_REG_GROUPS];
  212. uint16_t reg_size[MAX_SRNG_REG_GROUPS];
  213. uint8_t lmac_ring;
  214. enum hal_srng_dir ring_dir;
  215. };
  216. /**
  217. * HAL context to be used to access SRNG APIs (currently used by data path
  218. * and transport (CE) modules)
  219. */
  220. struct hal_soc {
  221. /* HIF handle to access HW registers */
  222. void *hif_handle;
  223. /* QDF device handle */
  224. qdf_device_t qdf_dev;
  225. /* Device base address */
  226. void *dev_base_addr;
  227. /* HAL internal state for all SRNG rings.
  228. * TODO: See if this is required
  229. */
  230. struct hal_srng srng_list[HAL_SRNG_ID_MAX];
  231. /* Remote pointer memory for HW/FW updates */
  232. uint32_t *shadow_rdptr_mem_vaddr;
  233. qdf_dma_addr_t shadow_rdptr_mem_paddr;
  234. /* Shared memory for ring pointer updates from host to FW */
  235. uint32_t *shadow_wrptr_mem_vaddr;
  236. qdf_dma_addr_t shadow_wrptr_mem_paddr;
  237. };
  238. /* TODO: Check if the following can be provided directly by HW headers */
  239. #define SRNG_LOOP_CNT_MASK REO_DESTINATION_RING_15_LOOPING_COUNT_MASK
  240. #define SRNG_LOOP_CNT_LSB REO_DESTINATION_RING_15_LOOPING_COUNT_LSB
  241. #define HAL_SRNG_LMAC_RING 0x80000000
  242. #define HAL_DEFAULT_REO_TIMEOUT_MS 40 /* milliseconds */
  243. #define HAL_DESC_SET_FIELD(_desc, _word, _fld, _value) \
  244. ((_desc)[(_word ## _ ## _fld ## _OFFSET) >> 2] |= \
  245. ((_value) << _word ## _ ## _fld ## _LSB))
  246. #define HAL_SM(_reg, _fld, _val) \
  247. (((_val) << (_reg ## _ ## _fld ## _SHFT)) & \
  248. (_reg ## _ ## _fld ## _BMSK))
  249. #define HAL_MS(_reg, _fld, _val) \
  250. (((_val) & (_reg ## _ ## _fld ## _BMSK)) >> \
  251. (_reg ## _ ## _fld ## _SHFT))
  252. #define HAL_REG_WRITE(_soc, _reg, _value) \
  253. hif_write32_mb((_soc)->dev_base_addr + (_reg), (_value))
  254. #define HAL_REG_READ(_soc, _offset) \
  255. hif_read32_mb((_soc)->dev_base_addr + (_offset))
  256. #endif /* _HAL_INTERNAL_H_ */