hal_internal.h 10 KB

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