hal_internal.h 11 KB

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