hal_internal.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef _HAL_INTERNAL_H_
  19. #define _HAL_INTERNAL_H_
  20. #include "qdf_types.h"
  21. #include "qdf_atomic.h"
  22. #include "qdf_lock.h"
  23. #include "qdf_mem.h"
  24. #include "qdf_nbuf.h"
  25. #include "pld_common.h"
  26. #if defined(FEATURE_HAL_DELAYED_REG_WRITE) || \
  27. defined(FEATURE_HAL_DELAYED_REG_WRITE_V2)
  28. #include "qdf_defer.h"
  29. #include "qdf_timer.h"
  30. #endif
  31. #define hal_alert(params...) QDF_TRACE_FATAL(QDF_MODULE_ID_HAL, params)
  32. #define hal_err(params...) QDF_TRACE_ERROR(QDF_MODULE_ID_HAL, params)
  33. #define hal_warn(params...) QDF_TRACE_WARN(QDF_MODULE_ID_HAL, params)
  34. #define hal_info(params...) QDF_TRACE_INFO(QDF_MODULE_ID_HAL, params)
  35. #define hal_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_HAL, params)
  36. #define hal_alert_rl(params...) QDF_TRACE_FATAL_RL(QDF_MODULE_ID_HAL, params)
  37. #define hal_err_rl(params...) QDF_TRACE_ERROR_RL(QDF_MODULE_ID_HAL, params)
  38. #define hal_warn_rl(params...) QDF_TRACE_WARN_RL(QDF_MODULE_ID_HAL, params)
  39. #define hal_info_rl(params...) QDF_TRACE_INFO_RL(QDF_MODULE_ID_HAL, params)
  40. #define hal_debug_rl(params...) QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_HAL, params)
  41. #ifdef ENABLE_VERBOSE_DEBUG
  42. extern bool is_hal_verbose_debug_enabled;
  43. #define hal_verbose_debug(params...) \
  44. if (unlikely(is_hal_verbose_debug_enabled)) \
  45. do {\
  46. QDF_TRACE_DEBUG(QDF_MODULE_ID_HAL, params); \
  47. } while (0)
  48. #define hal_verbose_hex_dump(params...) \
  49. if (unlikely(is_hal_verbose_debug_enabled)) \
  50. do {\
  51. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HAL, \
  52. QDF_TRACE_LEVEL_DEBUG, \
  53. params); \
  54. } while (0)
  55. #else
  56. #define hal_verbose_debug(params...) QDF_TRACE_DEBUG(QDF_MODULE_ID_HAL, params)
  57. #define hal_verbose_hex_dump(params...) \
  58. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_HAL, QDF_TRACE_LEVEL_DEBUG, \
  59. params)
  60. #endif
  61. /*
  62. * dp_hal_soc - opaque handle for DP HAL soc
  63. */
  64. struct hal_soc_handle;
  65. typedef struct hal_soc_handle *hal_soc_handle_t;
  66. /**
  67. * hal_ring_desc - opaque handle for DP ring descriptor
  68. */
  69. struct hal_ring_desc;
  70. typedef struct hal_ring_desc *hal_ring_desc_t;
  71. /**
  72. * hal_link_desc - opaque handle for DP link descriptor
  73. */
  74. struct hal_link_desc;
  75. typedef struct hal_link_desc *hal_link_desc_t;
  76. /**
  77. * hal_rxdma_desc - opaque handle for DP rxdma dst ring descriptor
  78. */
  79. struct hal_rxdma_desc;
  80. typedef struct hal_rxdma_desc *hal_rxdma_desc_t;
  81. /**
  82. * hal_buff_addrinfo - opaque handle for DP buffer address info
  83. */
  84. struct hal_buff_addrinfo;
  85. typedef struct hal_buff_addrinfo *hal_buff_addrinfo_t;
  86. /**
  87. * hal_rx_mon_desc_info - opaque handle for sw monitor ring desc info
  88. */
  89. struct hal_rx_mon_desc_info;
  90. typedef struct hal_rx_mon_desc_info *hal_rx_mon_desc_info_t;
  91. /* TBD: This should be movded to shared HW header file */
  92. enum hal_srng_ring_id {
  93. /* UMAC rings */
  94. HAL_SRNG_REO2SW1 = 0,
  95. HAL_SRNG_REO2SW2 = 1,
  96. HAL_SRNG_REO2SW3 = 2,
  97. HAL_SRNG_REO2SW4 = 3,
  98. HAL_SRNG_REO2TCL = 4,
  99. HAL_SRNG_SW2REO = 5,
  100. /* 6-7 unused */
  101. HAL_SRNG_REO_CMD = 8,
  102. HAL_SRNG_REO_STATUS = 9,
  103. /* 10-15 unused */
  104. HAL_SRNG_SW2TCL1 = 16,
  105. HAL_SRNG_SW2TCL2 = 17,
  106. HAL_SRNG_SW2TCL3 = 18,
  107. HAL_SRNG_SW2TCL4 = 19, /* FW2TCL ring */
  108. /* 20-23 unused */
  109. HAL_SRNG_SW2TCL_CMD = 24,
  110. HAL_SRNG_TCL_STATUS = 25,
  111. /* 26-31 unused */
  112. HAL_SRNG_CE_0_SRC = 32,
  113. HAL_SRNG_CE_1_SRC = 33,
  114. HAL_SRNG_CE_2_SRC = 34,
  115. HAL_SRNG_CE_3_SRC = 35,
  116. HAL_SRNG_CE_4_SRC = 36,
  117. HAL_SRNG_CE_5_SRC = 37,
  118. HAL_SRNG_CE_6_SRC = 38,
  119. HAL_SRNG_CE_7_SRC = 39,
  120. HAL_SRNG_CE_8_SRC = 40,
  121. HAL_SRNG_CE_9_SRC = 41,
  122. HAL_SRNG_CE_10_SRC = 42,
  123. HAL_SRNG_CE_11_SRC = 43,
  124. /* 44-55 unused */
  125. HAL_SRNG_CE_0_DST = 56,
  126. HAL_SRNG_CE_1_DST = 57,
  127. HAL_SRNG_CE_2_DST = 58,
  128. HAL_SRNG_CE_3_DST = 59,
  129. HAL_SRNG_CE_4_DST = 60,
  130. HAL_SRNG_CE_5_DST = 61,
  131. HAL_SRNG_CE_6_DST = 62,
  132. HAL_SRNG_CE_7_DST = 63,
  133. HAL_SRNG_CE_8_DST = 64,
  134. HAL_SRNG_CE_9_DST = 65,
  135. HAL_SRNG_CE_10_DST = 66,
  136. HAL_SRNG_CE_11_DST = 67,
  137. /* 68-79 unused */
  138. HAL_SRNG_CE_0_DST_STATUS = 80,
  139. HAL_SRNG_CE_1_DST_STATUS = 81,
  140. HAL_SRNG_CE_2_DST_STATUS = 82,
  141. HAL_SRNG_CE_3_DST_STATUS = 83,
  142. HAL_SRNG_CE_4_DST_STATUS = 84,
  143. HAL_SRNG_CE_5_DST_STATUS = 85,
  144. HAL_SRNG_CE_6_DST_STATUS = 86,
  145. HAL_SRNG_CE_7_DST_STATUS = 87,
  146. HAL_SRNG_CE_8_DST_STATUS = 88,
  147. HAL_SRNG_CE_9_DST_STATUS = 89,
  148. HAL_SRNG_CE_10_DST_STATUS = 90,
  149. HAL_SRNG_CE_11_DST_STATUS = 91,
  150. /* 92-103 unused */
  151. HAL_SRNG_WBM_IDLE_LINK = 104,
  152. HAL_SRNG_WBM_SW_RELEASE = 105,
  153. HAL_SRNG_WBM2SW0_RELEASE = 106,
  154. HAL_SRNG_WBM2SW1_RELEASE = 107,
  155. HAL_SRNG_WBM2SW2_RELEASE = 108,
  156. HAL_SRNG_WBM2SW3_RELEASE = 109,
  157. /* 110-127 unused */
  158. HAL_SRNG_UMAC_ID_END = 127,
  159. /* LMAC rings - The following set will be replicated for each LMAC */
  160. HAL_SRNG_LMAC1_ID_START = 128,
  161. HAL_SRNG_WMAC1_SW2RXDMA0_BUF0 = HAL_SRNG_LMAC1_ID_START,
  162. #ifdef IPA_OFFLOAD
  163. HAL_SRNG_WMAC1_SW2RXDMA0_BUF1 = (HAL_SRNG_LMAC1_ID_START + 1),
  164. HAL_SRNG_WMAC1_SW2RXDMA0_BUF2 = (HAL_SRNG_LMAC1_ID_START + 2),
  165. HAL_SRNG_WMAC1_SW2RXDMA1_BUF = (HAL_SRNG_WMAC1_SW2RXDMA0_BUF2 + 1),
  166. #else
  167. HAL_SRNG_WMAC1_SW2RXDMA1_BUF = (HAL_SRNG_WMAC1_SW2RXDMA0_BUF0 + 1),
  168. #endif
  169. HAL_SRNG_WMAC1_SW2RXDMA2_BUF = (HAL_SRNG_WMAC1_SW2RXDMA1_BUF + 1),
  170. HAL_SRNG_WMAC1_SW2RXDMA0_STATBUF = (HAL_SRNG_WMAC1_SW2RXDMA2_BUF + 1),
  171. HAL_SRNG_WMAC1_SW2RXDMA1_STATBUF =
  172. (HAL_SRNG_WMAC1_SW2RXDMA0_STATBUF + 1),
  173. HAL_SRNG_WMAC1_RXDMA2SW0 = (HAL_SRNG_WMAC1_SW2RXDMA1_STATBUF + 1),
  174. HAL_SRNG_WMAC1_RXDMA2SW1 = (HAL_SRNG_WMAC1_RXDMA2SW0 + 1),
  175. HAL_SRNG_WMAC1_SW2RXDMA1_DESC = (HAL_SRNG_WMAC1_RXDMA2SW1 + 1),
  176. #ifdef WLAN_FEATURE_CIF_CFR
  177. HAL_SRNG_WIFI_POS_SRC_DMA_RING = (HAL_SRNG_WMAC1_SW2RXDMA1_DESC + 1),
  178. HAL_SRNG_DIR_BUF_RX_SRC_DMA_RING = (HAL_SRNG_WIFI_POS_SRC_DMA_RING + 1),
  179. #else
  180. HAL_SRNG_DIR_BUF_RX_SRC_DMA_RING = (HAL_SRNG_WMAC1_SW2RXDMA1_DESC + 1),
  181. #endif
  182. /* -142 unused */
  183. HAL_SRNG_LMAC1_ID_END = 143
  184. };
  185. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  186. enum hal_ring_type {
  187. REO_DST = 0,
  188. REO_EXCEPTION = 1,
  189. REO_REINJECT = 2,
  190. REO_CMD = 3,
  191. REO_STATUS = 4,
  192. TCL_DATA = 5,
  193. TCL_CMD_CREDIT = 6,
  194. TCL_STATUS = 7,
  195. CE_SRC = 8,
  196. CE_DST = 9,
  197. CE_DST_STATUS = 10,
  198. WBM_IDLE_LINK = 11,
  199. SW2WBM_RELEASE = 12,
  200. WBM2SW_RELEASE = 13,
  201. RXDMA_BUF = 14,
  202. RXDMA_DST = 15,
  203. RXDMA_MONITOR_BUF = 16,
  204. RXDMA_MONITOR_STATUS = 17,
  205. RXDMA_MONITOR_DST = 18,
  206. RXDMA_MONITOR_DESC = 19,
  207. DIR_BUF_RX_DMA_SRC = 20,
  208. #ifdef WLAN_FEATURE_CIF_CFR
  209. WIFI_POS_SRC,
  210. #endif
  211. MAX_RING_TYPES
  212. };
  213. #define HAL_RXDMA_MAX_RING_SIZE 0xFFFF
  214. #define HAL_MAX_LMACS 3
  215. #define HAL_MAX_RINGS_PER_LMAC (HAL_SRNG_LMAC1_ID_END - HAL_SRNG_LMAC1_ID_START)
  216. #define HAL_MAX_LMAC_RINGS (HAL_MAX_LMACS * HAL_MAX_RINGS_PER_LMAC)
  217. #define HAL_SRNG_ID_MAX (HAL_SRNG_UMAC_ID_END + HAL_MAX_LMAC_RINGS)
  218. enum hal_srng_dir {
  219. HAL_SRNG_SRC_RING,
  220. HAL_SRNG_DST_RING
  221. };
  222. /* Lock wrappers for SRNG */
  223. #define hal_srng_lock_t qdf_spinlock_t
  224. #define SRNG_LOCK_INIT(_lock) qdf_spinlock_create(_lock)
  225. #define SRNG_LOCK(_lock) qdf_spin_lock_bh(_lock)
  226. #define SRNG_TRY_LOCK(_lock) qdf_spin_trylock_bh(_lock)
  227. #define SRNG_UNLOCK(_lock) qdf_spin_unlock_bh(_lock)
  228. #define SRNG_LOCK_DESTROY(_lock) qdf_spinlock_destroy(_lock)
  229. struct hal_soc;
  230. /**
  231. * dp_hal_ring - opaque handle for DP HAL SRNG
  232. */
  233. struct hal_ring_handle;
  234. typedef struct hal_ring_handle *hal_ring_handle_t;
  235. #define MAX_SRNG_REG_GROUPS 2
  236. /* Hal Srng bit mask
  237. * HAL_SRNG_FLUSH_EVENT: SRNG HP TP flush in case of link down
  238. */
  239. #define HAL_SRNG_FLUSH_EVENT BIT(0)
  240. #if defined(FEATURE_HAL_DELAYED_REG_WRITE) || \
  241. defined(FEATURE_HAL_DELAYED_REG_WRITE_V2)
  242. /**
  243. * struct hal_reg_write_q_elem - delayed register write queue element
  244. * @srng: hal_srng queued for a delayed write
  245. * @addr: iomem address of the register
  246. * @enqueue_val: register value at the time of delayed write enqueue
  247. * @dequeue_val: register value at the time of delayed write dequeue
  248. * @valid: whether this entry is valid or not
  249. * @enqueue_time: enqueue time (qdf_log_timestamp)
  250. * @work_scheduled_time: work scheduled time (qdf_log_timestamp)
  251. * @dequeue_time: dequeue time (qdf_log_timestamp)
  252. */
  253. struct hal_reg_write_q_elem {
  254. struct hal_srng *srng;
  255. void __iomem *addr;
  256. uint32_t enqueue_val;
  257. uint32_t dequeue_val;
  258. uint8_t valid;
  259. qdf_time_t enqueue_time;
  260. qdf_time_t work_scheduled_time;
  261. qdf_time_t dequeue_time;
  262. };
  263. /**
  264. * struct hal_reg_write_srng_stats - srng stats to keep track of register writes
  265. * @enqueues: writes enqueued to delayed work
  266. * @dequeues: writes dequeued from delayed work (not written yet)
  267. * @coalesces: writes not enqueued since srng is already queued up
  268. * @direct: writes not enqueued and written to register directly
  269. */
  270. struct hal_reg_write_srng_stats {
  271. uint32_t enqueues;
  272. uint32_t dequeues;
  273. uint32_t coalesces;
  274. uint32_t direct;
  275. };
  276. /**
  277. * enum hal_reg_sched_delay - ENUM for write sched delay histogram
  278. * @REG_WRITE_SCHED_DELAY_SUB_100us: index for delay < 100us
  279. * @REG_WRITE_SCHED_DELAY_SUB_1000us: index for delay < 1000us
  280. * @REG_WRITE_SCHED_DELAY_SUB_5000us: index for delay < 5000us
  281. * @REG_WRITE_SCHED_DELAY_GT_5000us: index for delay >= 5000us
  282. * @REG_WRITE_SCHED_DELAY_HIST_MAX: Max value (nnsize of histogram array)
  283. */
  284. enum hal_reg_sched_delay {
  285. REG_WRITE_SCHED_DELAY_SUB_100us,
  286. REG_WRITE_SCHED_DELAY_SUB_1000us,
  287. REG_WRITE_SCHED_DELAY_SUB_5000us,
  288. REG_WRITE_SCHED_DELAY_GT_5000us,
  289. REG_WRITE_SCHED_DELAY_HIST_MAX,
  290. };
  291. /**
  292. * struct hal_reg_write_soc_stats - soc stats to keep track of register writes
  293. * @enqueues: writes enqueued to delayed work
  294. * @dequeues: writes dequeued from delayed work (not written yet)
  295. * @coalesces: writes not enqueued since srng is already queued up
  296. * @direct: writes not enqueud and writted to register directly
  297. * @prevent_l1_fails: prevent l1 API failed
  298. * @q_depth: current queue depth in delayed register write queue
  299. * @max_q_depth: maximum queue for delayed register write queue
  300. * @sched_delay: = kernel work sched delay + bus wakeup delay, histogram
  301. */
  302. struct hal_reg_write_soc_stats {
  303. qdf_atomic_t enqueues;
  304. uint32_t dequeues;
  305. qdf_atomic_t coalesces;
  306. qdf_atomic_t direct;
  307. uint32_t prevent_l1_fails;
  308. qdf_atomic_t q_depth;
  309. uint32_t max_q_depth;
  310. uint32_t sched_delay[REG_WRITE_SCHED_DELAY_HIST_MAX];
  311. };
  312. #ifdef FEATURE_HAL_DELAYED_REG_WRITE_V2
  313. struct hal_reg_write_tcl_stats {
  314. uint32_t wq_delayed;
  315. uint32_t wq_direct;
  316. uint32_t timer_enq;
  317. uint32_t timer_direct;
  318. uint32_t enq_timer_set;
  319. uint32_t direct_timer_set;
  320. uint32_t timer_reset;
  321. qdf_time_t enq_time;
  322. qdf_time_t deq_time;
  323. uint32_t sched_delay[REG_WRITE_SCHED_DELAY_HIST_MAX];
  324. };
  325. #endif
  326. #endif
  327. /* Common SRNG ring structure for source and destination rings */
  328. struct hal_srng {
  329. /* Unique SRNG ring ID */
  330. uint8_t ring_id;
  331. /* Ring initialization done */
  332. uint8_t initialized;
  333. /* Interrupt/MSI value assigned to this ring */
  334. int irq;
  335. /* Physical base address of the ring */
  336. qdf_dma_addr_t ring_base_paddr;
  337. /* Virtual base address of the ring */
  338. uint32_t *ring_base_vaddr;
  339. /* Number of entries in ring */
  340. uint32_t num_entries;
  341. /* Ring size */
  342. uint32_t ring_size;
  343. /* Ring size mask */
  344. uint32_t ring_size_mask;
  345. /* Size of ring entry */
  346. uint32_t entry_size;
  347. /* Interrupt timer threshold – in micro seconds */
  348. uint32_t intr_timer_thres_us;
  349. /* Interrupt batch counter threshold – in number of ring entries */
  350. uint32_t intr_batch_cntr_thres_entries;
  351. /* Applicable only for CE dest ring */
  352. uint32_t prefetch_timer;
  353. /* MSI Address */
  354. qdf_dma_addr_t msi_addr;
  355. /* MSI data */
  356. uint32_t msi_data;
  357. /* Misc flags */
  358. uint32_t flags;
  359. /* Lock for serializing ring index updates */
  360. hal_srng_lock_t lock;
  361. /* Start offset of SRNG register groups for this ring
  362. * TBD: See if this is required - register address can be derived
  363. * from ring ID
  364. */
  365. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  366. /* Ring type/name */
  367. enum hal_ring_type ring_type;
  368. /* Source or Destination ring */
  369. enum hal_srng_dir ring_dir;
  370. union {
  371. struct {
  372. /* SW tail pointer */
  373. uint32_t tp;
  374. /* Shadow head pointer location to be updated by HW */
  375. uint32_t *hp_addr;
  376. /* Cached head pointer */
  377. uint32_t cached_hp;
  378. /* Tail pointer location to be updated by SW – This
  379. * will be a register address and need not be
  380. * accessed through SW structure */
  381. uint32_t *tp_addr;
  382. /* Current SW loop cnt */
  383. uint32_t loop_cnt;
  384. /* max transfer size */
  385. uint16_t max_buffer_length;
  386. } dst_ring;
  387. struct {
  388. /* SW head pointer */
  389. uint32_t hp;
  390. /* SW reap head pointer */
  391. uint32_t reap_hp;
  392. /* Shadow tail pointer location to be updated by HW */
  393. uint32_t *tp_addr;
  394. /* Cached tail pointer */
  395. uint32_t cached_tp;
  396. /* Head pointer location to be updated by SW – This
  397. * will be a register address and need not be accessed
  398. * through SW structure */
  399. uint32_t *hp_addr;
  400. /* Low threshold – in number of ring entries */
  401. uint32_t low_threshold;
  402. } src_ring;
  403. } u;
  404. struct hal_soc *hal_soc;
  405. /* Number of times hp/tp updated in runtime resume */
  406. uint32_t flush_count;
  407. /* hal srng event flag*/
  408. unsigned long srng_event;
  409. /* last flushed time stamp */
  410. uint64_t last_flush_ts;
  411. #if defined(FEATURE_HAL_DELAYED_REG_WRITE) || \
  412. defined(FEATURE_HAL_DELAYED_REG_WRITE_V2)
  413. /* Previous hp/tp (based on ring dir) value written to the reg */
  414. uint32_t last_reg_wr_val;
  415. /* flag to indicate whether srng is already queued for delayed write */
  416. uint8_t reg_write_in_progress;
  417. /* srng specific delayed write stats */
  418. struct hal_reg_write_srng_stats wstats;
  419. #endif
  420. };
  421. /* HW SRNG configuration table */
  422. struct hal_hw_srng_config {
  423. int start_ring_id;
  424. uint16_t max_rings;
  425. uint16_t entry_size;
  426. uint32_t reg_start[MAX_SRNG_REG_GROUPS];
  427. uint16_t reg_size[MAX_SRNG_REG_GROUPS];
  428. uint8_t lmac_ring;
  429. enum hal_srng_dir ring_dir;
  430. uint32_t max_size;
  431. };
  432. #define MAX_SHADOW_REGISTERS 36
  433. #define MAX_GENERIC_SHADOW_REG 5
  434. /**
  435. * struct shadow_reg_config - Hal soc structure that contains
  436. * the list of generic shadow registers
  437. * @target_register: target reg offset
  438. * @shadow_config_index: shadow config index in shadow config
  439. * list sent to FW
  440. * @va: virtual addr of shadow reg
  441. *
  442. * This structure holds the generic registers that are mapped to
  443. * the shadow region and holds the mapping of the target
  444. * register offset to shadow config index provided to FW during
  445. * init
  446. */
  447. struct shadow_reg_config {
  448. uint32_t target_register;
  449. int shadow_config_index;
  450. uint64_t va;
  451. };
  452. /* REO parameters to be passed to hal_reo_setup */
  453. struct hal_reo_params {
  454. /** rx hash steering enabled or disabled */
  455. bool rx_hash_enabled;
  456. /** reo remap 1 register */
  457. uint32_t remap1;
  458. /** reo remap 2 register */
  459. uint32_t remap2;
  460. /** fragment destination ring */
  461. uint8_t frag_dst_ring;
  462. /* Destination for alternate */
  463. uint8_t alt_dst_ind_0;
  464. /** padding */
  465. uint8_t padding[2];
  466. };
  467. struct hal_hw_txrx_ops {
  468. /* init and setup */
  469. void (*hal_srng_dst_hw_init)(struct hal_soc *hal,
  470. struct hal_srng *srng);
  471. void (*hal_srng_src_hw_init)(struct hal_soc *hal,
  472. struct hal_srng *srng);
  473. void (*hal_get_hw_hptp)(struct hal_soc *hal,
  474. hal_ring_handle_t hal_ring_hdl,
  475. uint32_t *headp, uint32_t *tailp,
  476. uint8_t ring_type);
  477. void (*hal_reo_setup)(struct hal_soc *hal_soc, void *reoparams);
  478. void (*hal_setup_link_idle_list)(
  479. struct hal_soc *hal_soc,
  480. qdf_dma_addr_t scatter_bufs_base_paddr[],
  481. void *scatter_bufs_base_vaddr[],
  482. uint32_t num_scatter_bufs,
  483. uint32_t scatter_buf_size,
  484. uint32_t last_buf_end_offset,
  485. uint32_t num_entries);
  486. qdf_iomem_t (*hal_get_window_address)(struct hal_soc *hal_soc,
  487. qdf_iomem_t addr);
  488. void (*hal_reo_set_err_dst_remap)(void *hal_soc);
  489. /* tx */
  490. void (*hal_tx_desc_set_dscp_tid_table_id)(void *desc, uint8_t id);
  491. void (*hal_tx_set_dscp_tid_map)(struct hal_soc *hal_soc, uint8_t *map,
  492. uint8_t id);
  493. void (*hal_tx_update_dscp_tid)(struct hal_soc *hal_soc, uint8_t tid,
  494. uint8_t id,
  495. uint8_t dscp);
  496. void (*hal_tx_desc_set_lmac_id)(void *desc, uint8_t lmac_id);
  497. void (*hal_tx_desc_set_buf_addr)(void *desc, dma_addr_t paddr,
  498. uint8_t pool_id, uint32_t desc_id, uint8_t type);
  499. void (*hal_tx_desc_set_search_type)(void *desc, uint8_t search_type);
  500. void (*hal_tx_desc_set_search_index)(void *desc, uint32_t search_index);
  501. void (*hal_tx_desc_set_cache_set_num)(void *desc, uint8_t search_index);
  502. void (*hal_tx_comp_get_status)(void *desc, void *ts,
  503. struct hal_soc *hal);
  504. uint8_t (*hal_tx_comp_get_release_reason)(void *hal_desc);
  505. uint8_t (*hal_get_wbm_internal_error)(void *hal_desc);
  506. void (*hal_tx_desc_set_mesh_en)(void *desc, uint8_t en);
  507. void (*hal_tx_init_cmd_credit_ring)(hal_soc_handle_t hal_soc_hdl,
  508. hal_ring_handle_t hal_ring_hdl);
  509. /* rx */
  510. uint32_t (*hal_rx_msdu_start_nss_get)(uint8_t *);
  511. void (*hal_rx_mon_hw_desc_get_mpdu_status)(void *hw_desc_addr,
  512. struct mon_rx_status *rs);
  513. uint8_t (*hal_rx_get_tlv)(void *rx_tlv);
  514. void (*hal_rx_proc_phyrx_other_receive_info_tlv)(void *rx_tlv_hdr,
  515. void *ppdu_info_handle);
  516. void (*hal_rx_dump_msdu_start_tlv)(void *msdu_start, uint8_t dbg_level);
  517. void (*hal_rx_dump_msdu_end_tlv)(void *msdu_end,
  518. uint8_t dbg_level);
  519. uint32_t (*hal_get_link_desc_size)(void);
  520. uint32_t (*hal_rx_mpdu_start_tid_get)(uint8_t *buf);
  521. uint32_t (*hal_rx_msdu_start_reception_type_get)(uint8_t *buf);
  522. uint16_t (*hal_rx_msdu_end_da_idx_get)(uint8_t *buf);
  523. void* (*hal_rx_msdu_desc_info_get_ptr)(void *msdu_details_ptr);
  524. void* (*hal_rx_link_desc_msdu0_ptr)(void *msdu_link_ptr);
  525. void (*hal_reo_status_get_header)(uint32_t *d, int b, void *h);
  526. uint32_t (*hal_rx_status_get_tlv_info)(void *rx_tlv_hdr,
  527. void *ppdu_info,
  528. hal_soc_handle_t hal_soc_hdl,
  529. qdf_nbuf_t nbuf);
  530. void (*hal_rx_wbm_err_info_get)(void *wbm_desc,
  531. void *wbm_er_info);
  532. void (*hal_rx_dump_mpdu_start_tlv)(void *mpdustart,
  533. uint8_t dbg_level);
  534. void (*hal_tx_set_pcp_tid_map)(struct hal_soc *hal_soc, uint8_t *map);
  535. void (*hal_tx_update_pcp_tid_map)(struct hal_soc *hal_soc, uint8_t pcp,
  536. uint8_t id);
  537. void (*hal_tx_set_tidmap_prty)(struct hal_soc *hal_soc, uint8_t prio);
  538. uint8_t (*hal_rx_get_rx_fragment_number)(uint8_t *buf);
  539. uint8_t (*hal_rx_msdu_end_da_is_mcbc_get)(uint8_t *buf);
  540. uint8_t (*hal_rx_msdu_end_sa_is_valid_get)(uint8_t *buf);
  541. uint16_t (*hal_rx_msdu_end_sa_idx_get)(uint8_t *buf);
  542. uint32_t (*hal_rx_desc_is_first_msdu)(void *hw_desc_addr);
  543. uint32_t (*hal_rx_msdu_end_l3_hdr_padding_get)(uint8_t *buf);
  544. uint32_t (*hal_rx_encryption_info_valid)(uint8_t *buf);
  545. void (*hal_rx_print_pn)(uint8_t *buf);
  546. uint8_t (*hal_rx_msdu_end_first_msdu_get)(uint8_t *buf);
  547. uint8_t (*hal_rx_msdu_end_da_is_valid_get)(uint8_t *buf);
  548. uint8_t (*hal_rx_msdu_end_last_msdu_get)(uint8_t *buf);
  549. bool (*hal_rx_get_mpdu_mac_ad4_valid)(uint8_t *buf);
  550. uint32_t (*hal_rx_mpdu_start_sw_peer_id_get)(uint8_t *buf);
  551. uint32_t (*hal_rx_mpdu_get_to_ds)(uint8_t *buf);
  552. uint32_t (*hal_rx_mpdu_get_fr_ds)(uint8_t *buf);
  553. uint8_t (*hal_rx_get_mpdu_frame_control_valid)(uint8_t *buf);
  554. QDF_STATUS
  555. (*hal_rx_mpdu_get_addr1)(uint8_t *buf, uint8_t *mac_addr);
  556. QDF_STATUS
  557. (*hal_rx_mpdu_get_addr2)(uint8_t *buf, uint8_t *mac_addr);
  558. QDF_STATUS
  559. (*hal_rx_mpdu_get_addr3)(uint8_t *buf, uint8_t *mac_addr);
  560. QDF_STATUS
  561. (*hal_rx_mpdu_get_addr4)(uint8_t *buf, uint8_t *mac_addr);
  562. uint8_t (*hal_rx_get_mpdu_sequence_control_valid)(uint8_t *buf);
  563. bool (*hal_rx_is_unicast)(uint8_t *buf);
  564. uint32_t (*hal_rx_tid_get)(hal_soc_handle_t hal_soc_hdl, uint8_t *buf);
  565. uint32_t (*hal_rx_hw_desc_get_ppduid_get)(void *rx_tlv_hdr,
  566. void *rxdma_dst_ring_desc);
  567. uint32_t (*hal_rx_mpdu_start_mpdu_qos_control_valid_get)(uint8_t *buf);
  568. uint32_t (*hal_rx_msdu_end_sa_sw_peer_id_get)(uint8_t *buf);
  569. void * (*hal_rx_msdu0_buffer_addr_lsb)(void *link_desc_addr);
  570. void * (*hal_rx_msdu_desc_info_ptr_get)(void *msdu0);
  571. void * (*hal_ent_mpdu_desc_info)(void *hw_addr);
  572. void * (*hal_dst_mpdu_desc_info)(void *hw_addr);
  573. uint8_t (*hal_rx_get_fc_valid)(uint8_t *buf);
  574. uint8_t (*hal_rx_get_to_ds_flag)(uint8_t *buf);
  575. uint8_t (*hal_rx_get_mac_addr2_valid)(uint8_t *buf);
  576. uint8_t (*hal_rx_get_filter_category)(uint8_t *buf);
  577. uint32_t (*hal_rx_get_ppdu_id)(uint8_t *buf);
  578. void (*hal_reo_config)(struct hal_soc *soc,
  579. uint32_t reg_val,
  580. struct hal_reo_params *reo_params);
  581. uint32_t (*hal_rx_msdu_flow_idx_get)(uint8_t *buf);
  582. bool (*hal_rx_msdu_flow_idx_invalid)(uint8_t *buf);
  583. bool (*hal_rx_msdu_flow_idx_timeout)(uint8_t *buf);
  584. uint32_t (*hal_rx_msdu_fse_metadata_get)(uint8_t *buf);
  585. uint16_t (*hal_rx_msdu_cce_metadata_get)(uint8_t *buf);
  586. void
  587. (*hal_rx_msdu_get_flow_params)(
  588. uint8_t *buf,
  589. bool *flow_invalid,
  590. bool *flow_timeout,
  591. uint32_t *flow_index);
  592. uint16_t (*hal_rx_tlv_get_tcp_chksum)(uint8_t *buf);
  593. uint16_t (*hal_rx_get_rx_sequence)(uint8_t *buf);
  594. void (*hal_rx_get_bb_info)(void *rx_tlv, void *ppdu_info_handle);
  595. void (*hal_rx_get_rtt_info)(void *rx_tlv, void *ppdu_info_handle);
  596. void (*hal_rx_msdu_packet_metadata_get)(uint8_t *buf,
  597. void *msdu_pkt_metadata);
  598. uint16_t (*hal_rx_get_fisa_cumulative_l4_checksum)(uint8_t *buf);
  599. uint16_t (*hal_rx_get_fisa_cumulative_ip_length)(uint8_t *buf);
  600. bool (*hal_rx_get_udp_proto)(uint8_t *buf);
  601. bool (*hal_rx_get_fisa_flow_agg_continuation)(uint8_t *buf);
  602. uint8_t (*hal_rx_get_fisa_flow_agg_count)(uint8_t *buf);
  603. bool (*hal_rx_get_fisa_timeout)(uint8_t *buf);
  604. uint8_t (*hal_rx_mpdu_start_tlv_tag_valid)(void *rx_tlv_hdr);
  605. void (*hal_rx_sw_mon_desc_info_get)(hal_ring_desc_t rxdma_dst_ring_desc,
  606. hal_rx_mon_desc_info_t mon_desc_info);
  607. uint8_t (*hal_rx_wbm_err_msdu_continuation_get)(void *ring_desc);
  608. uint32_t (*hal_rx_msdu_end_offset_get)(void);
  609. uint32_t (*hal_rx_attn_offset_get)(void);
  610. uint32_t (*hal_rx_msdu_start_offset_get)(void);
  611. uint32_t (*hal_rx_mpdu_start_offset_get)(void);
  612. uint32_t (*hal_rx_mpdu_end_offset_get)(void);
  613. uint32_t (*hal_rx_pkt_tlv_offset_get)(void);
  614. void * (*hal_rx_flow_setup_fse)(uint8_t *rx_fst,
  615. uint32_t table_offset,
  616. uint8_t *rx_flow);
  617. void (*hal_compute_reo_remap_ix2_ix3)(uint32_t *ring,
  618. uint32_t num_rings,
  619. uint32_t *remap1,
  620. uint32_t *remap2);
  621. uint32_t (*hal_rx_flow_setup_cmem_fse)(
  622. struct hal_soc *soc, uint32_t cmem_ba,
  623. uint32_t table_offset, uint8_t *rx_flow);
  624. uint32_t (*hal_rx_flow_get_cmem_fse_ts)(struct hal_soc *soc,
  625. uint32_t fse_offset);
  626. void (*hal_rx_flow_get_cmem_fse)(struct hal_soc *soc,
  627. uint32_t fse_offset,
  628. uint32_t *fse, qdf_size_t len);
  629. void (*hal_rx_msdu_get_reo_destination_indication)(uint8_t *buf,
  630. uint32_t *reo_destination_indication);
  631. };
  632. /**
  633. * struct hal_soc_stats - Hal layer stats
  634. * @reg_write_fail: number of failed register writes
  635. * @wstats: delayed register write stats
  636. * @shadow_reg_write_fail: shadow reg write failure stats
  637. * @shadow_reg_write_succ: shadow reg write success stats
  638. *
  639. * This structure holds all the statistics at HAL layer.
  640. */
  641. struct hal_soc_stats {
  642. uint32_t reg_write_fail;
  643. #if defined(FEATURE_HAL_DELAYED_REG_WRITE) || \
  644. defined(FEATURE_HAL_DELAYED_REG_WRITE_V2)
  645. struct hal_reg_write_soc_stats wstats;
  646. #endif
  647. #ifdef GENERIC_SHADOW_REGISTER_ACCESS_ENABLE
  648. uint32_t shadow_reg_write_fail;
  649. uint32_t shadow_reg_write_succ;
  650. #endif
  651. };
  652. #ifdef ENABLE_HAL_REG_WR_HISTORY
  653. /* The history size should always be a power of 2 */
  654. #define HAL_REG_WRITE_HIST_SIZE 8
  655. /**
  656. * struct hal_reg_write_fail_entry - Record of
  657. * register write which failed.
  658. * @timestamp: timestamp of reg write failure
  659. * @reg_offset: offset of register where the write failed
  660. * @write_val: the value which was to be written
  661. * @read_val: the value read back from the register after write
  662. */
  663. struct hal_reg_write_fail_entry {
  664. uint64_t timestamp;
  665. uint32_t reg_offset;
  666. uint32_t write_val;
  667. uint32_t read_val;
  668. };
  669. /**
  670. * struct hal_reg_write_fail_history - Hal layer history
  671. * of all the register write failures.
  672. * @index: index to add the new record
  673. * @record: array of all the records in history
  674. *
  675. * This structure holds the history of register write
  676. * failures at HAL layer.
  677. */
  678. struct hal_reg_write_fail_history {
  679. qdf_atomic_t index;
  680. struct hal_reg_write_fail_entry record[HAL_REG_WRITE_HIST_SIZE];
  681. };
  682. #endif
  683. /**
  684. * struct hal_soc - HAL context to be used to access SRNG APIs
  685. * (currently used by data path and
  686. * transport (CE) modules)
  687. * @list_shadow_reg_config: array of generic regs mapped to
  688. * shadow regs
  689. * @num_generic_shadow_regs_configured: number of generic regs
  690. * mapped to shadow regs
  691. */
  692. struct hal_soc {
  693. /* HIF handle to access HW registers */
  694. struct hif_opaque_softc *hif_handle;
  695. /* QDF device handle */
  696. qdf_device_t qdf_dev;
  697. /* Device base address */
  698. void *dev_base_addr;
  699. /* Device base address for ce - qca5018 target */
  700. void *dev_base_addr_ce;
  701. /* HAL internal state for all SRNG rings.
  702. * TODO: See if this is required
  703. */
  704. struct hal_srng srng_list[HAL_SRNG_ID_MAX];
  705. /* Remote pointer memory for HW/FW updates */
  706. uint32_t *shadow_rdptr_mem_vaddr;
  707. qdf_dma_addr_t shadow_rdptr_mem_paddr;
  708. /* Shared memory for ring pointer updates from host to FW */
  709. uint32_t *shadow_wrptr_mem_vaddr;
  710. qdf_dma_addr_t shadow_wrptr_mem_paddr;
  711. /* REO blocking resource index */
  712. uint8_t reo_res_bitmap;
  713. uint8_t index;
  714. uint32_t target_type;
  715. /* shadow register configuration */
  716. struct pld_shadow_reg_v2_cfg shadow_config[MAX_SHADOW_REGISTERS];
  717. int num_shadow_registers_configured;
  718. bool use_register_windowing;
  719. uint32_t register_window;
  720. qdf_spinlock_t register_access_lock;
  721. /* Static window map configuration for multiple window write*/
  722. bool static_window_map;
  723. /* srng table */
  724. struct hal_hw_srng_config *hw_srng_table;
  725. int32_t *hal_hw_reg_offset;
  726. struct hal_hw_txrx_ops *ops;
  727. /* Indicate srngs initialization */
  728. bool init_phase;
  729. /* Hal level stats */
  730. struct hal_soc_stats stats;
  731. #ifdef ENABLE_HAL_REG_WR_HISTORY
  732. struct hal_reg_write_fail_history *reg_wr_fail_hist;
  733. #endif
  734. #ifdef FEATURE_HAL_DELAYED_REG_WRITE
  735. /* queue(array) to hold register writes */
  736. struct hal_reg_write_q_elem *reg_write_queue;
  737. /* delayed work to be queued into workqueue */
  738. qdf_work_t reg_write_work;
  739. /* workqueue for delayed register writes */
  740. qdf_workqueue_t *reg_write_wq;
  741. /* write index used by caller to enqueue delayed work */
  742. qdf_atomic_t write_idx;
  743. /* read index used by worker thread to dequeue/write registers */
  744. uint32_t read_idx;
  745. #endif /*FEATURE_HAL_DELAYED_REG_WRITE */
  746. #ifdef FEATURE_HAL_DELAYED_REG_WRITE_V2
  747. /* delayed work for TCL reg write to be queued into workqueue */
  748. qdf_work_t tcl_reg_write_work;
  749. /* workqueue for TCL delayed register writes */
  750. qdf_workqueue_t *tcl_reg_write_wq;
  751. /* flag denotes whether TCL delayed write work is active */
  752. qdf_atomic_t tcl_work_active;
  753. /* flag indiactes TCL write happening from direct context */
  754. bool tcl_direct;
  755. /* timer to handle the pending TCL reg writes */
  756. qdf_timer_t tcl_reg_write_timer;
  757. /* stats related to TCL reg write */
  758. struct hal_reg_write_tcl_stats tcl_stats;
  759. #endif /* FEATURE_HAL_DELAYED_REG_WRITE_V2 */
  760. qdf_atomic_t active_work_cnt;
  761. #ifdef GENERIC_SHADOW_REGISTER_ACCESS_ENABLE
  762. struct shadow_reg_config
  763. list_shadow_reg_config[MAX_GENERIC_SHADOW_REG];
  764. int num_generic_shadow_regs_configured;
  765. #endif
  766. };
  767. #if defined(FEATURE_HAL_DELAYED_REG_WRITE) || \
  768. defined(FEATURE_HAL_DELAYED_REG_WRITE_V2)
  769. /**
  770. * hal_delayed_reg_write() - delayed regiter write
  771. * @hal_soc: HAL soc handle
  772. * @srng: hal srng
  773. * @addr: iomem address
  774. * @value: value to be written
  775. *
  776. * Return: none
  777. */
  778. void hal_delayed_reg_write(struct hal_soc *hal_soc,
  779. struct hal_srng *srng,
  780. void __iomem *addr,
  781. uint32_t value);
  782. #endif
  783. void hal_qca6750_attach(struct hal_soc *hal_soc);
  784. void hal_qca6490_attach(struct hal_soc *hal_soc);
  785. void hal_qca6390_attach(struct hal_soc *hal_soc);
  786. void hal_qca6290_attach(struct hal_soc *hal_soc);
  787. void hal_qca8074_attach(struct hal_soc *hal_soc);
  788. /*
  789. * hal_soc_to_dp_hal_roc - API to convert hal_soc to opaque
  790. * dp_hal_soc handle type
  791. * @hal_soc - hal_soc type
  792. *
  793. * Return: hal_soc_handle_t type
  794. */
  795. static inline
  796. hal_soc_handle_t hal_soc_to_hal_soc_handle(struct hal_soc *hal_soc)
  797. {
  798. return (hal_soc_handle_t)hal_soc;
  799. }
  800. /*
  801. * hal_srng_to_hal_ring_handle - API to convert hal_srng to opaque
  802. * dp_hal_ring handle type
  803. * @hal_srng - hal_srng type
  804. *
  805. * Return: hal_ring_handle_t type
  806. */
  807. static inline
  808. hal_ring_handle_t hal_srng_to_hal_ring_handle(struct hal_srng *hal_srng)
  809. {
  810. return (hal_ring_handle_t)hal_srng;
  811. }
  812. /*
  813. * hal_ring_handle_to_hal_srng - API to convert dp_hal_ring to hal_srng handle
  814. * @hal_ring - hal_ring_handle_t type
  815. *
  816. * Return: hal_srng pointer type
  817. */
  818. static inline
  819. struct hal_srng *hal_ring_handle_to_hal_srng(hal_ring_handle_t hal_ring)
  820. {
  821. return (struct hal_srng *)hal_ring;
  822. }
  823. #endif /* _HAL_INTERNAL_H_ */