hal_internal.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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 "qdf_mem.h"
  34. #include "wcss_seq_hwiobase.h"
  35. #include "tlv_hdr.h"
  36. #include "tlv_tag_def.h"
  37. #include "reo_destination_ring.h"
  38. #include "reo_reg_seq_hwioreg.h"
  39. #include "reo_entrance_ring.h"
  40. #include "reo_get_queue_stats.h"
  41. #include "reo_get_queue_stats_status.h"
  42. #include "tcl_data_cmd.h"
  43. #include "tcl_gse_cmd.h"
  44. #include "tcl_status_ring.h"
  45. #include "mac_tcl_reg_seq_hwioreg.h"
  46. #include "ce_src_desc.h"
  47. #include "ce_stat_desc.h"
  48. #include "wfss_ce_reg_seq_hwioreg.h"
  49. #include "wbm_link_descriptor_ring.h"
  50. #include "wbm_reg_seq_hwioreg.h"
  51. #include "wbm_buffer_ring.h"
  52. #include "wbm_release_ring.h"
  53. #include "rx_msdu_desc_info.h"
  54. #include "rx_mpdu_start.h"
  55. #include "rx_mpdu_end.h"
  56. #include "rx_msdu_start.h"
  57. #include "rx_msdu_end.h"
  58. #include "rx_attention.h"
  59. #include "tx_msdu_extension.h"
  60. #ifdef CONFIG_WIN
  61. #include "wcss_version.h"
  62. #endif
  63. /* TBD: This should be movded to shared HW header file */
  64. enum hal_srng_ring_id {
  65. /* UMAC rings */
  66. HAL_SRNG_REO2SW1 = 0,
  67. HAL_SRNG_REO2SW2 = 1,
  68. HAL_SRNG_REO2SW3 = 2,
  69. HAL_SRNG_REO2SW4 = 3,
  70. HAL_SRNG_REO2TCL = 4,
  71. HAL_SRNG_SW2REO = 5,
  72. /* 6-7 unused */
  73. HAL_SRNG_REO_CMD = 8,
  74. HAL_SRNG_REO_STATUS = 9,
  75. /* 10-15 unused */
  76. HAL_SRNG_SW2TCL1 = 16,
  77. HAL_SRNG_SW2TCL2 = 17,
  78. HAL_SRNG_SW2TCL3 = 18,
  79. HAL_SRNG_SW2TCL4 = 19, /* FW2TCL ring */
  80. /* 20-23 unused */
  81. HAL_SRNG_SW2TCL_CMD = 24,
  82. HAL_SRNG_TCL_STATUS = 25,
  83. /* 26-31 unused */
  84. HAL_SRNG_CE_0_SRC = 32,
  85. HAL_SRNG_CE_1_SRC = 33,
  86. HAL_SRNG_CE_2_SRC = 34,
  87. HAL_SRNG_CE_3_SRC = 35,
  88. HAL_SRNG_CE_4_SRC = 36,
  89. HAL_SRNG_CE_5_SRC = 37,
  90. HAL_SRNG_CE_6_SRC = 38,
  91. HAL_SRNG_CE_7_SRC = 39,
  92. HAL_SRNG_CE_8_SRC = 40,
  93. HAL_SRNG_CE_9_SRC = 41,
  94. HAL_SRNG_CE_10_SRC = 42,
  95. HAL_SRNG_CE_11_SRC = 43,
  96. /* 44-55 unused */
  97. HAL_SRNG_CE_0_DST = 56,
  98. HAL_SRNG_CE_1_DST = 57,
  99. HAL_SRNG_CE_2_DST = 58,
  100. HAL_SRNG_CE_3_DST = 59,
  101. HAL_SRNG_CE_4_DST = 60,
  102. HAL_SRNG_CE_5_DST = 61,
  103. HAL_SRNG_CE_6_DST = 62,
  104. HAL_SRNG_CE_7_DST = 63,
  105. HAL_SRNG_CE_8_DST = 64,
  106. HAL_SRNG_CE_9_DST = 65,
  107. HAL_SRNG_CE_10_DST = 66,
  108. HAL_SRNG_CE_11_DST = 67,
  109. /* 68-79 unused */
  110. HAL_SRNG_CE_0_DST_STATUS = 80,
  111. HAL_SRNG_CE_1_DST_STATUS = 81,
  112. HAL_SRNG_CE_2_DST_STATUS = 82,
  113. HAL_SRNG_CE_3_DST_STATUS = 83,
  114. HAL_SRNG_CE_4_DST_STATUS = 84,
  115. HAL_SRNG_CE_5_DST_STATUS = 85,
  116. HAL_SRNG_CE_6_DST_STATUS = 86,
  117. HAL_SRNG_CE_7_DST_STATUS = 87,
  118. HAL_SRNG_CE_8_DST_STATUS = 88,
  119. HAL_SRNG_CE_9_DST_STATUS = 89,
  120. HAL_SRNG_CE_10_DST_STATUS = 90,
  121. HAL_SRNG_CE_11_DST_STATUS = 91,
  122. /* 92-103 unused */
  123. HAL_SRNG_WBM_IDLE_LINK = 104,
  124. HAL_SRNG_WBM_SW_RELEASE = 105,
  125. HAL_SRNG_WBM2SW0_RELEASE = 106,
  126. HAL_SRNG_WBM2SW1_RELEASE = 107,
  127. HAL_SRNG_WBM2SW2_RELEASE = 108,
  128. HAL_SRNG_WBM2SW3_RELEASE = 109,
  129. /* 110-127 unused */
  130. HAL_SRNG_UMAC_ID_END = 127,
  131. /* LMAC rings - The following set will be replicated for each LMAC */
  132. HAL_SRNG_LMAC1_ID_START = 128,
  133. HAL_SRNG_WMAC1_SW2RXDMA0_BUF = HAL_SRNG_LMAC1_ID_START,
  134. HAL_SRNG_WMAC1_SW2RXDMA1_BUF = 129,
  135. HAL_SRNG_WMAC1_SW2RXDMA2_BUF = 130,
  136. HAL_SRNG_WMAC1_SW2RXDMA0_STATBUF = 131,
  137. HAL_SRNG_WMAC1_SW2RXDMA1_STATBUF = 132,
  138. HAL_SRNG_WMAC1_RXDMA2SW0 = 133,
  139. HAL_SRNG_WMAC1_RXDMA2SW1 = 134,
  140. /* 135-142 unused */
  141. HAL_SRNG_LMAC1_ID_END = 143
  142. };
  143. #define HAL_SRNG_REO_EXCEPTION HAL_SRNG_REO2SW1
  144. #define HAL_MAX_LMACS 3
  145. #define HAL_MAX_RINGS_PER_LMAC (HAL_SRNG_LMAC1_ID_END - HAL_SRNG_LMAC1_ID_START)
  146. #define HAL_MAX_LMAC_RINGS (HAL_MAX_LMACS * HAL_MAX_RINGS_PER_LMAC)
  147. #define HAL_SRNG_ID_MAX (HAL_SRNG_UMAC_ID_END + HAL_MAX_LMAC_RINGS)
  148. enum hal_srng_dir {
  149. HAL_SRNG_SRC_RING,
  150. HAL_SRNG_DST_RING
  151. };
  152. /* Lock wrappers for SRNG */
  153. #define hal_srng_lock_t qdf_spinlock_t
  154. #define SRNG_LOCK_INIT(_lock) qdf_spinlock_create(_lock)
  155. #define SRNG_LOCK(_lock) qdf_spinlock_acquire(_lock)
  156. #define SRNG_UNLOCK(_lock) qdf_spinlock_release(_lock)
  157. #define SRNG_LOCK_DESTROY(_lock) qdf_spinlock_destroy(_lock)
  158. #define MAX_SRNG_REG_GROUPS 2
  159. /* Common SRNG ring structure for source and destination rings */
  160. struct hal_srng {
  161. /* Unique SRNG ring ID */
  162. uint8_t ring_id;
  163. /* Ring initialization done */
  164. uint8_t initialized;
  165. /* Interrupt/MSI value assigned to this ring */
  166. int irq;
  167. /* Physical base address of the ring */
  168. qdf_dma_addr_t ring_base_paddr;
  169. /* Virtual base address of the ring */
  170. uint32_t *ring_base_vaddr;
  171. /* Number of entries in ring */
  172. uint32_t num_entries;
  173. /* Ring size */
  174. uint32_t ring_size;
  175. /* Ring size mask */
  176. uint32_t ring_size_mask;
  177. /* Size of ring entry */
  178. uint32_t entry_size;
  179. /* Interrupt timer threshold – in micro seconds */
  180. uint32_t intr_timer_thres_us;
  181. /* Interrupt batch counter threshold – in number of ring entries */
  182. uint32_t intr_batch_cntr_thres_entries;
  183. /* MSI Address */
  184. qdf_dma_addr_t msi_addr;
  185. /* MSI data */
  186. uint32_t msi_data;
  187. /* Misc flags */
  188. uint32_t flags;
  189. /* Lock for serializing ring index updates */
  190. hal_srng_lock_t lock;
  191. /* Start offset of SRNG register groups for this ring
  192. * TBD: See if this is required - register address can be derived
  193. * from ring ID
  194. */
  195. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  196. /* Source or Destination ring */
  197. enum hal_srng_dir ring_dir;
  198. union {
  199. struct {
  200. /* SW tail pointer */
  201. uint32_t tp;
  202. /* Shadow head pointer location to be updated by HW */
  203. uint32_t *hp_addr;
  204. /* Cached head pointer */
  205. uint32_t cached_hp;
  206. /* Tail pointer location to be updated by SW – This
  207. * will be a register address and need not be
  208. * accessed through SW structure */
  209. uint32_t *tp_addr;
  210. /* Current SW loop cnt */
  211. uint32_t loop_cnt;
  212. /* max transfer size */
  213. uint16_t max_buffer_length;
  214. } dst_ring;
  215. struct {
  216. /* SW head pointer */
  217. uint32_t hp;
  218. /* SW reap head pointer */
  219. uint32_t reap_hp;
  220. /* Shadow tail pointer location to be updated by HW */
  221. uint32_t *tp_addr;
  222. /* Cached tail pointer */
  223. uint32_t cached_tp;
  224. /* Head pointer location to be updated by SW – This
  225. * will be a register address and need not be accessed
  226. * through SW structure */
  227. uint32_t *hp_addr;
  228. /* Low threshold – in number of ring entries */
  229. uint32_t low_threshold;
  230. } src_ring;
  231. } u;
  232. };
  233. /* HW SRNG configuration table */
  234. struct hal_hw_srng_config {
  235. int start_ring_id;
  236. uint16_t max_rings;
  237. uint16_t entry_size;
  238. uint32_t reg_start[MAX_SRNG_REG_GROUPS];
  239. uint16_t reg_size[MAX_SRNG_REG_GROUPS];
  240. uint8_t lmac_ring;
  241. enum hal_srng_dir ring_dir;
  242. };
  243. /**
  244. * HAL context to be used to access SRNG APIs (currently used by data path
  245. * and transport (CE) modules)
  246. */
  247. struct hal_soc {
  248. /* HIF handle to access HW registers */
  249. void *hif_handle;
  250. /* QDF device handle */
  251. qdf_device_t qdf_dev;
  252. /* Device base address */
  253. void *dev_base_addr;
  254. /* HAL internal state for all SRNG rings.
  255. * TODO: See if this is required
  256. */
  257. struct hal_srng srng_list[HAL_SRNG_ID_MAX];
  258. /* Remote pointer memory for HW/FW updates */
  259. uint32_t *shadow_rdptr_mem_vaddr;
  260. qdf_dma_addr_t shadow_rdptr_mem_paddr;
  261. /* Shared memory for ring pointer updates from host to FW */
  262. uint32_t *shadow_wrptr_mem_vaddr;
  263. qdf_dma_addr_t shadow_wrptr_mem_paddr;
  264. };
  265. /* TODO: Check if the following can be provided directly by HW headers */
  266. #define SRNG_LOOP_CNT_MASK REO_DESTINATION_RING_15_LOOPING_COUNT_MASK
  267. #define SRNG_LOOP_CNT_LSB REO_DESTINATION_RING_15_LOOPING_COUNT_LSB
  268. #define HAL_SRNG_LMAC_RING 0x80000000
  269. #define HAL_DEFAULT_REO_TIMEOUT_MS 40 /* milliseconds */
  270. #define HAL_DESC_SET_FIELD(_desc, _word, _fld, _value) \
  271. ((_desc)[(_word ## _ ## _fld ## _OFFSET) >> 2] |= \
  272. ((_value) << _word ## _ ## _fld ## _LSB))
  273. #define HAL_SM(_reg, _fld, _val) \
  274. (((_val) << (_reg ## _ ## _fld ## _SHFT)) & \
  275. (_reg ## _ ## _fld ## _BMSK))
  276. #define HAL_MS(_reg, _fld, _val) \
  277. (((_val) & (_reg ## _ ## _fld ## _BMSK)) >> \
  278. (_reg ## _ ## _fld ## _SHFT))
  279. #define HAL_REG_WRITE(_soc, _reg, _value) \
  280. hif_write32_mb((_soc)->dev_base_addr + (_reg), (_value))
  281. #define HAL_REG_READ(_soc, _offset) \
  282. hif_read32_mb((_soc)->dev_base_addr + (_offset))
  283. #endif /* _HAL_INTERNAL_H_ */