hal_internal.h 10 KB

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