hal_api.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493
  1. /*
  2. * Copyright (c) 2016-2019 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_API_H_
  19. #define _HAL_API_H_
  20. #include "qdf_types.h"
  21. #include "qdf_util.h"
  22. #include "hal_internal.h"
  23. #define MAX_UNWINDOWED_ADDRESS 0x80000
  24. #ifdef QCA_WIFI_QCA6390
  25. #define WINDOW_ENABLE_BIT 0x40000000
  26. #else
  27. #define WINDOW_ENABLE_BIT 0x80000000
  28. #endif
  29. #define WINDOW_REG_ADDRESS 0x310C
  30. #define WINDOW_SHIFT 19
  31. #define WINDOW_VALUE_MASK 0x3F
  32. #define WINDOW_START MAX_UNWINDOWED_ADDRESS
  33. #define WINDOW_RANGE_MASK 0x7FFFF
  34. /*
  35. * BAR + 4K is always accessible, any access outside this
  36. * space requires force wake procedure.
  37. * OFFSET = 4K - 32 bytes = 0x4063
  38. */
  39. #define MAPPED_REF_OFF 0x4063
  40. #define FORCE_WAKE_DELAY_TIMEOUT 50
  41. #define FORCE_WAKE_DELAY_MS 5
  42. #ifdef ENABLE_VERBOSE_DEBUG
  43. static inline void
  44. hal_set_verbose_debug(bool flag)
  45. {
  46. is_hal_verbose_debug_enabled = flag;
  47. }
  48. #endif
  49. #ifndef QCA_WIFI_QCA6390
  50. static inline int hal_force_wake_request(struct hal_soc *soc)
  51. {
  52. return 0;
  53. }
  54. static inline int hal_force_wake_release(struct hal_soc *soc)
  55. {
  56. return 0;
  57. }
  58. #else
  59. static inline int hal_force_wake_request(struct hal_soc *soc)
  60. {
  61. uint32_t timeout = 0;
  62. if (pld_force_wake_request(soc->qdf_dev->dev)) {
  63. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  64. "%s: Request send failed \n", __func__);
  65. return -EINVAL;
  66. }
  67. while (!pld_is_device_awake(soc->qdf_dev->dev) &&
  68. timeout <= FORCE_WAKE_DELAY_TIMEOUT) {
  69. mdelay(FORCE_WAKE_DELAY_MS);
  70. timeout += FORCE_WAKE_DELAY_MS;
  71. }
  72. if (pld_is_device_awake(soc->qdf_dev->dev) == true)
  73. return 0;
  74. else
  75. return -ETIMEDOUT;
  76. }
  77. static inline int hal_force_wake_release(struct hal_soc *soc)
  78. {
  79. return pld_force_wake_release(soc->qdf_dev->dev);
  80. }
  81. #endif
  82. static inline void hal_select_window(struct hal_soc *hal_soc, uint32_t offset)
  83. {
  84. uint32_t window = (offset >> WINDOW_SHIFT) & WINDOW_VALUE_MASK;
  85. if (window != hal_soc->register_window) {
  86. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_REG_ADDRESS,
  87. WINDOW_ENABLE_BIT | window);
  88. hal_soc->register_window = window;
  89. }
  90. }
  91. /**
  92. * note1: WINDOW_RANGE_MASK = (1 << WINDOW_SHIFT) -1
  93. * note2: 1 << WINDOW_SHIFT = MAX_UNWINDOWED_ADDRESS
  94. * note3: WINDOW_VALUE_MASK = big enough that trying to write past that window
  95. * would be a bug
  96. */
  97. #ifndef QCA_WIFI_QCA6390
  98. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  99. uint32_t value)
  100. {
  101. if (!hal_soc->use_register_windowing ||
  102. offset < MAX_UNWINDOWED_ADDRESS) {
  103. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  104. } else {
  105. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  106. hal_select_window(hal_soc, offset);
  107. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  108. (offset & WINDOW_RANGE_MASK), value);
  109. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  110. }
  111. }
  112. #else
  113. static inline void hal_write32_mb(struct hal_soc *hal_soc, uint32_t offset,
  114. uint32_t value)
  115. {
  116. if ((offset > MAPPED_REF_OFF) &&
  117. hal_force_wake_request(hal_soc)) {
  118. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  119. "%s: Wake up request failed\n", __func__);
  120. return;
  121. }
  122. if (!hal_soc->use_register_windowing ||
  123. offset < MAX_UNWINDOWED_ADDRESS) {
  124. qdf_iowrite32(hal_soc->dev_base_addr + offset, value);
  125. } else {
  126. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  127. hal_select_window(hal_soc, offset);
  128. qdf_iowrite32(hal_soc->dev_base_addr + WINDOW_START +
  129. (offset & WINDOW_RANGE_MASK), value);
  130. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  131. }
  132. if ((offset > MAPPED_REF_OFF) &&
  133. hal_force_wake_release(hal_soc))
  134. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  135. "%s: Wake up release failed\n", __func__);
  136. }
  137. #endif
  138. /**
  139. * hal_write_address_32_mb - write a value to a register
  140. *
  141. */
  142. static inline void hal_write_address_32_mb(struct hal_soc *hal_soc,
  143. void __iomem *addr, uint32_t value)
  144. {
  145. uint32_t offset;
  146. if (!hal_soc->use_register_windowing)
  147. return qdf_iowrite32(addr, value);
  148. offset = addr - hal_soc->dev_base_addr;
  149. hal_write32_mb(hal_soc, offset, value);
  150. }
  151. #ifndef QCA_WIFI_QCA6390
  152. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  153. {
  154. uint32_t ret;
  155. if (!hal_soc->use_register_windowing ||
  156. offset < MAX_UNWINDOWED_ADDRESS) {
  157. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  158. }
  159. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  160. hal_select_window(hal_soc, offset);
  161. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  162. (offset & WINDOW_RANGE_MASK));
  163. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  164. return ret;
  165. }
  166. /**
  167. * hal_read_address_32_mb() - Read 32-bit value from the register
  168. * @soc: soc handle
  169. * @addr: register address to read
  170. *
  171. * Return: 32-bit value
  172. */
  173. static inline uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  174. void __iomem *addr)
  175. {
  176. uint32_t offset;
  177. uint32_t ret;
  178. if (!soc->use_register_windowing)
  179. return qdf_ioread32(addr);
  180. offset = addr - soc->dev_base_addr;
  181. ret = hal_read32_mb(soc, offset);
  182. return ret;
  183. }
  184. #else
  185. static inline uint32_t hal_read32_mb(struct hal_soc *hal_soc, uint32_t offset)
  186. {
  187. uint32_t ret;
  188. if ((offset > MAPPED_REF_OFF) &&
  189. hal_force_wake_request(hal_soc)) {
  190. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  191. "%s: Wake up request failed\n", __func__);
  192. return -EINVAL;
  193. }
  194. if (!hal_soc->use_register_windowing ||
  195. offset < MAX_UNWINDOWED_ADDRESS) {
  196. return qdf_ioread32(hal_soc->dev_base_addr + offset);
  197. }
  198. qdf_spin_lock_irqsave(&hal_soc->register_access_lock);
  199. hal_select_window(hal_soc, offset);
  200. ret = qdf_ioread32(hal_soc->dev_base_addr + WINDOW_START +
  201. (offset & WINDOW_RANGE_MASK));
  202. qdf_spin_unlock_irqrestore(&hal_soc->register_access_lock);
  203. if ((offset > MAPPED_REF_OFF) &&
  204. hal_force_wake_release(hal_soc))
  205. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  206. "%s: Wake up release failed\n", __func__);
  207. return ret;
  208. }
  209. static inline uint32_t hal_read_address_32_mb(struct hal_soc *soc,
  210. void __iomem *addr)
  211. {
  212. uint32_t offset;
  213. uint32_t ret;
  214. if (!soc->use_register_windowing)
  215. return qdf_ioread32(addr);
  216. offset = addr - soc->dev_base_addr;
  217. ret = hal_read32_mb(soc, offset);
  218. return ret;
  219. }
  220. #endif
  221. #include "hif_io32.h"
  222. /**
  223. * hal_attach - Initialize HAL layer
  224. * @hif_handle: Opaque HIF handle
  225. * @qdf_dev: QDF device
  226. *
  227. * Return: Opaque HAL SOC handle
  228. * NULL on failure (if given ring is not available)
  229. *
  230. * This function should be called as part of HIF initialization (for accessing
  231. * copy engines). DP layer will get hal_soc handle using hif_get_hal_handle()
  232. */
  233. extern void *hal_attach(void *hif_handle, qdf_device_t qdf_dev);
  234. /**
  235. * hal_detach - Detach HAL layer
  236. * @hal_soc: HAL SOC handle
  237. *
  238. * This function should be called as part of HIF detach
  239. *
  240. */
  241. extern void hal_detach(void *hal_soc);
  242. /* SRNG type to be passed in APIs hal_srng_get_entrysize and hal_srng_setup */
  243. enum hal_ring_type {
  244. REO_DST = 0,
  245. REO_EXCEPTION = 1,
  246. REO_REINJECT = 2,
  247. REO_CMD = 3,
  248. REO_STATUS = 4,
  249. TCL_DATA = 5,
  250. TCL_CMD = 6,
  251. TCL_STATUS = 7,
  252. CE_SRC = 8,
  253. CE_DST = 9,
  254. CE_DST_STATUS = 10,
  255. WBM_IDLE_LINK = 11,
  256. SW2WBM_RELEASE = 12,
  257. WBM2SW_RELEASE = 13,
  258. RXDMA_BUF = 14,
  259. RXDMA_DST = 15,
  260. RXDMA_MONITOR_BUF = 16,
  261. RXDMA_MONITOR_STATUS = 17,
  262. RXDMA_MONITOR_DST = 18,
  263. RXDMA_MONITOR_DESC = 19,
  264. DIR_BUF_RX_DMA_SRC = 20,
  265. #ifdef WLAN_FEATURE_CIF_CFR
  266. WIFI_POS_SRC,
  267. #endif
  268. MAX_RING_TYPES
  269. };
  270. #define HAL_SRNG_LMAC_RING 0x80000000
  271. /* SRNG flags passed in hal_srng_params.flags */
  272. #define HAL_SRNG_MSI_SWAP 0x00000008
  273. #define HAL_SRNG_RING_PTR_SWAP 0x00000010
  274. #define HAL_SRNG_DATA_TLV_SWAP 0x00000020
  275. #define HAL_SRNG_LOW_THRES_INTR_ENABLE 0x00010000
  276. #define HAL_SRNG_MSI_INTR 0x00020000
  277. #define HAL_SRNG_CACHED_DESC 0x00040000
  278. #define PN_SIZE_24 0
  279. #define PN_SIZE_48 1
  280. #define PN_SIZE_128 2
  281. /**
  282. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  283. * used by callers for calculating the size of memory to be allocated before
  284. * calling hal_srng_setup to setup the ring
  285. *
  286. * @hal_soc: Opaque HAL SOC handle
  287. * @ring_type: one of the types from hal_ring_type
  288. *
  289. */
  290. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  291. /**
  292. * hal_srng_max_entries - Returns maximum possible number of ring entries
  293. * @hal_soc: Opaque HAL SOC handle
  294. * @ring_type: one of the types from hal_ring_type
  295. *
  296. * Return: Maximum number of entries for the given ring_type
  297. */
  298. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  299. /**
  300. * hal_srng_dump - Dump ring status
  301. * @srng: hal srng pointer
  302. */
  303. void hal_srng_dump(struct hal_srng *srng);
  304. /**
  305. * hal_srng_get_dir - Returns the direction of the ring
  306. * @hal_soc: Opaque HAL SOC handle
  307. * @ring_type: one of the types from hal_ring_type
  308. *
  309. * Return: Ring direction
  310. */
  311. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  312. /* HAL memory information */
  313. struct hal_mem_info {
  314. /* dev base virutal addr */
  315. void *dev_base_addr;
  316. /* dev base physical addr */
  317. void *dev_base_paddr;
  318. /* Remote virtual pointer memory for HW/FW updates */
  319. void *shadow_rdptr_mem_vaddr;
  320. /* Remote physical pointer memory for HW/FW updates */
  321. void *shadow_rdptr_mem_paddr;
  322. /* Shared memory for ring pointer updates from host to FW */
  323. void *shadow_wrptr_mem_vaddr;
  324. /* Shared physical memory for ring pointer updates from host to FW */
  325. void *shadow_wrptr_mem_paddr;
  326. };
  327. /* SRNG parameters to be passed to hal_srng_setup */
  328. struct hal_srng_params {
  329. /* Physical base address of the ring */
  330. qdf_dma_addr_t ring_base_paddr;
  331. /* Virtual base address of the ring */
  332. void *ring_base_vaddr;
  333. /* Number of entries in ring */
  334. uint32_t num_entries;
  335. /* max transfer length */
  336. uint16_t max_buffer_length;
  337. /* MSI Address */
  338. qdf_dma_addr_t msi_addr;
  339. /* MSI data */
  340. uint32_t msi_data;
  341. /* Interrupt timer threshold – in micro seconds */
  342. uint32_t intr_timer_thres_us;
  343. /* Interrupt batch counter threshold – in number of ring entries */
  344. uint32_t intr_batch_cntr_thres_entries;
  345. /* Low threshold – in number of ring entries
  346. * (valid for src rings only)
  347. */
  348. uint32_t low_threshold;
  349. /* Misc flags */
  350. uint32_t flags;
  351. /* Unique ring id */
  352. uint8_t ring_id;
  353. /* Source or Destination ring */
  354. enum hal_srng_dir ring_dir;
  355. /* Size of ring entry */
  356. uint32_t entry_size;
  357. /* hw register base address */
  358. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  359. };
  360. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  361. * @hal_soc: hal handle
  362. *
  363. * Return: QDF_STATUS_OK on success
  364. */
  365. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  366. /* hal_set_one_shadow_config() - add a config for the specified ring
  367. * @hal_soc: hal handle
  368. * @ring_type: ring type
  369. * @ring_num: ring num
  370. *
  371. * The ring type and ring num uniquely specify the ring. After this call,
  372. * the hp/tp will be added as the next entry int the shadow register
  373. * configuration table. The hal code will use the shadow register address
  374. * in place of the hp/tp address.
  375. *
  376. * This function is exposed, so that the CE module can skip configuring shadow
  377. * registers for unused ring and rings assigned to the firmware.
  378. *
  379. * Return: QDF_STATUS_OK on success
  380. */
  381. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  382. int ring_num);
  383. /**
  384. * hal_get_shadow_config() - retrieve the config table
  385. * @hal_soc: hal handle
  386. * @shadow_config: will point to the table after
  387. * @num_shadow_registers_configured: will contain the number of valid entries
  388. */
  389. extern void hal_get_shadow_config(void *hal_soc,
  390. struct pld_shadow_reg_v2_cfg **shadow_config,
  391. int *num_shadow_registers_configured);
  392. /**
  393. * hal_srng_setup - Initialize HW SRNG ring.
  394. *
  395. * @hal_soc: Opaque HAL SOC handle
  396. * @ring_type: one of the types from hal_ring_type
  397. * @ring_num: Ring number if there are multiple rings of
  398. * same type (staring from 0)
  399. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  400. * @ring_params: SRNG ring params in hal_srng_params structure.
  401. * Callers are expected to allocate contiguous ring memory of size
  402. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  403. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  404. * structure. Ring base address should be 8 byte aligned and size of each ring
  405. * entry should be queried using the API hal_srng_get_entrysize
  406. *
  407. * Return: Opaque pointer to ring on success
  408. * NULL on failure (if given ring is not available)
  409. */
  410. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  411. int mac_id, struct hal_srng_params *ring_params);
  412. /* Remapping ids of REO rings */
  413. #define REO_REMAP_TCL 0
  414. #define REO_REMAP_SW1 1
  415. #define REO_REMAP_SW2 2
  416. #define REO_REMAP_SW3 3
  417. #define REO_REMAP_SW4 4
  418. #define REO_REMAP_RELEASE 5
  419. #define REO_REMAP_FW 6
  420. #define REO_REMAP_UNUSED 7
  421. /*
  422. * currently this macro only works for IX0 since all the rings we are remapping
  423. * can be remapped from HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  424. */
  425. #define HAL_REO_REMAP_VAL(_ORIGINAL_DEST, _NEW_DEST) \
  426. HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST)
  427. /* allow the destination macros to be expanded */
  428. #define HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST) \
  429. (_NEW_DEST << \
  430. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  431. _ORIGINAL_DEST ## _SHFT))
  432. /**
  433. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  434. * @hal: HAL SOC handle
  435. * @read: boolean value to indicate if read or write
  436. * @ix0: pointer to store IX0 reg value
  437. * @ix1: pointer to store IX1 reg value
  438. * @ix2: pointer to store IX2 reg value
  439. * @ix3: pointer to store IX3 reg value
  440. */
  441. extern void hal_reo_read_write_ctrl_ix(struct hal_soc *hal, bool read,
  442. uint32_t *ix0, uint32_t *ix1,
  443. uint32_t *ix2, uint32_t *ix3);
  444. /**
  445. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  446. * @sring: sring pointer
  447. * @paddr: physical address
  448. */
  449. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  450. /**
  451. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  452. * @srng: sring pointer
  453. * @vaddr: virtual address
  454. */
  455. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  456. /**
  457. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  458. * @hal_soc: Opaque HAL SOC handle
  459. * @hal_srng: Opaque HAL SRNG pointer
  460. */
  461. extern void hal_srng_cleanup(void *hal_soc, void *hal_srng);
  462. static inline bool hal_srng_initialized(void *hal_ring)
  463. {
  464. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  465. return !!srng->initialized;
  466. }
  467. /**
  468. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  469. * @hal_soc: Opaque HAL SOC handle
  470. * @hal_ring: Destination ring pointer
  471. *
  472. * Caller takes responsibility for any locking needs.
  473. *
  474. * Return: Opaque pointer for next ring entry; NULL on failire
  475. */
  476. static inline
  477. void *hal_srng_dst_peek(void *hal_soc, void *hal_ring)
  478. {
  479. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  480. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  481. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  482. return NULL;
  483. }
  484. /**
  485. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  486. * hal_srng_access_start if locked access is required
  487. *
  488. * @hal_soc: Opaque HAL SOC handle
  489. * @hal_ring: Ring pointer (Source or Destination ring)
  490. *
  491. * Return: 0 on success; error on failire
  492. */
  493. static inline int hal_srng_access_start_unlocked(void *hal_soc, void *hal_ring)
  494. {
  495. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  496. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  497. uint32_t *desc;
  498. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  499. srng->u.src_ring.cached_tp =
  500. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  501. else {
  502. srng->u.dst_ring.cached_hp =
  503. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  504. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  505. desc = hal_srng_dst_peek(hal_soc, hal_ring);
  506. if (qdf_likely(desc)) {
  507. qdf_mem_dma_cache_sync(soc->qdf_dev,
  508. qdf_mem_virt_to_phys
  509. (desc),
  510. QDF_DMA_FROM_DEVICE,
  511. (srng->entry_size *
  512. sizeof(uint32_t)));
  513. qdf_prefetch(desc);
  514. }
  515. }
  516. }
  517. return 0;
  518. }
  519. /**
  520. * hal_srng_access_start - Start (locked) ring access
  521. *
  522. * @hal_soc: Opaque HAL SOC handle
  523. * @hal_ring: Ring pointer (Source or Destination ring)
  524. *
  525. * Return: 0 on success; error on failire
  526. */
  527. static inline int hal_srng_access_start(void *hal_soc, void *hal_ring)
  528. {
  529. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  530. if (qdf_unlikely(!hal_ring)) {
  531. qdf_print("Error: Invalid hal_ring\n");
  532. return -EINVAL;
  533. }
  534. SRNG_LOCK(&(srng->lock));
  535. return hal_srng_access_start_unlocked(hal_soc, hal_ring);
  536. }
  537. /**
  538. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  539. * cached tail pointer
  540. *
  541. * @hal_soc: Opaque HAL SOC handle
  542. * @hal_ring: Destination ring pointer
  543. *
  544. * Return: Opaque pointer for next ring entry; NULL on failire
  545. */
  546. static inline void *hal_srng_dst_get_next(void *hal_soc, void *hal_ring)
  547. {
  548. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  549. struct hal_soc *soc = (struct hal_soc *)hal_soc;
  550. uint32_t *desc;
  551. uint32_t *desc_next;
  552. uint32_t tp;
  553. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) {
  554. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  555. /* TODO: Using % is expensive, but we have to do this since
  556. * size of some SRNG rings is not power of 2 (due to descriptor
  557. * sizes). Need to create separate API for rings used
  558. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  559. * SW2RXDMA and CE rings)
  560. */
  561. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  562. srng->ring_size;
  563. if (srng->flags & HAL_SRNG_CACHED_DESC) {
  564. tp = srng->u.dst_ring.tp;
  565. desc_next = &srng->ring_base_vaddr[tp];
  566. qdf_mem_dma_cache_sync(soc->qdf_dev,
  567. qdf_mem_virt_to_phys(desc_next),
  568. QDF_DMA_FROM_DEVICE,
  569. (srng->entry_size *
  570. sizeof(uint32_t)));
  571. qdf_prefetch(desc_next);
  572. }
  573. return (void *)desc;
  574. }
  575. return NULL;
  576. }
  577. /**
  578. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  579. * cached head pointer
  580. *
  581. * @hal_soc: Opaque HAL SOC handle
  582. * @hal_ring: Destination ring pointer
  583. *
  584. * Return: Opaque pointer for next ring entry; NULL on failire
  585. */
  586. static inline void *hal_srng_dst_get_next_hp(void *hal_soc, void *hal_ring)
  587. {
  588. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  589. uint32_t *desc;
  590. /* TODO: Using % is expensive, but we have to do this since
  591. * size of some SRNG rings is not power of 2 (due to descriptor
  592. * sizes). Need to create separate API for rings used
  593. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  594. * SW2RXDMA and CE rings)
  595. */
  596. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  597. srng->ring_size;
  598. if (next_hp != srng->u.dst_ring.tp) {
  599. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  600. srng->u.dst_ring.cached_hp = next_hp;
  601. return (void *)desc;
  602. }
  603. return NULL;
  604. }
  605. /**
  606. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  607. * @hal_soc: Opaque HAL SOC handle
  608. * @hal_ring: Destination ring pointer
  609. *
  610. * Sync cached head pointer with HW.
  611. * Caller takes responsibility for any locking needs.
  612. *
  613. * Return: Opaque pointer for next ring entry; NULL on failire
  614. */
  615. static inline
  616. void *hal_srng_dst_peek_sync(void *hal_soc, void *hal_ring)
  617. {
  618. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  619. srng->u.dst_ring.cached_hp =
  620. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  621. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  622. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  623. return NULL;
  624. }
  625. /**
  626. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  627. * @hal_soc: Opaque HAL SOC handle
  628. * @hal_ring: Destination ring pointer
  629. *
  630. * Sync cached head pointer with HW.
  631. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  632. *
  633. * Return: Opaque pointer for next ring entry; NULL on failire
  634. */
  635. static inline
  636. void *hal_srng_dst_peek_sync_locked(void *hal_soc, void *hal_ring)
  637. {
  638. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  639. void *ring_desc_ptr = NULL;
  640. if (qdf_unlikely(!hal_ring)) {
  641. qdf_print("Error: Invalid hal_ring\n");
  642. return NULL;
  643. }
  644. SRNG_LOCK(&srng->lock);
  645. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc, hal_ring);
  646. SRNG_UNLOCK(&srng->lock);
  647. return ring_desc_ptr;
  648. }
  649. /**
  650. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  651. * by SW) in destination ring
  652. *
  653. * @hal_soc: Opaque HAL SOC handle
  654. * @hal_ring: Destination ring pointer
  655. * @sync_hw_ptr: Sync cached head pointer with HW
  656. *
  657. */
  658. static inline uint32_t hal_srng_dst_num_valid(void *hal_soc, void *hal_ring,
  659. int sync_hw_ptr)
  660. {
  661. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  662. uint32_t hp;
  663. uint32_t tp = srng->u.dst_ring.tp;
  664. if (sync_hw_ptr) {
  665. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  666. srng->u.dst_ring.cached_hp = hp;
  667. } else {
  668. hp = srng->u.dst_ring.cached_hp;
  669. }
  670. if (hp >= tp)
  671. return (hp - tp) / srng->entry_size;
  672. else
  673. return (srng->ring_size - tp + hp) / srng->entry_size;
  674. }
  675. /**
  676. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  677. * pointer. This can be used to release any buffers associated with completed
  678. * ring entries. Note that this should not be used for posting new descriptor
  679. * entries. Posting of new entries should be done only using
  680. * hal_srng_src_get_next_reaped when this function is used for reaping.
  681. *
  682. * @hal_soc: Opaque HAL SOC handle
  683. * @hal_ring: Source ring pointer
  684. *
  685. * Return: Opaque pointer for next ring entry; NULL on failire
  686. */
  687. static inline void *hal_srng_src_reap_next(void *hal_soc, void *hal_ring)
  688. {
  689. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  690. uint32_t *desc;
  691. /* TODO: Using % is expensive, but we have to do this since
  692. * size of some SRNG rings is not power of 2 (due to descriptor
  693. * sizes). Need to create separate API for rings used
  694. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  695. * SW2RXDMA and CE rings)
  696. */
  697. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  698. srng->ring_size;
  699. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  700. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  701. srng->u.src_ring.reap_hp = next_reap_hp;
  702. return (void *)desc;
  703. }
  704. return NULL;
  705. }
  706. /**
  707. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  708. * already reaped using hal_srng_src_reap_next, for posting new entries to
  709. * the ring
  710. *
  711. * @hal_soc: Opaque HAL SOC handle
  712. * @hal_ring: Source ring pointer
  713. *
  714. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  715. */
  716. static inline void *hal_srng_src_get_next_reaped(void *hal_soc, void *hal_ring)
  717. {
  718. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  719. uint32_t *desc;
  720. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  721. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  722. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  723. srng->ring_size;
  724. return (void *)desc;
  725. }
  726. return NULL;
  727. }
  728. /**
  729. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  730. * move reap pointer. This API is used in detach path to release any buffers
  731. * associated with ring entries which are pending reap.
  732. *
  733. * @hal_soc: Opaque HAL SOC handle
  734. * @hal_ring: Source ring pointer
  735. *
  736. * Return: Opaque pointer for next ring entry; NULL on failire
  737. */
  738. static inline void *hal_srng_src_pending_reap_next(void *hal_soc, void *hal_ring)
  739. {
  740. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  741. uint32_t *desc;
  742. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  743. srng->ring_size;
  744. if (next_reap_hp != srng->u.src_ring.hp) {
  745. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  746. srng->u.src_ring.reap_hp = next_reap_hp;
  747. return (void *)desc;
  748. }
  749. return NULL;
  750. }
  751. /**
  752. * hal_srng_src_done_val -
  753. *
  754. * @hal_soc: Opaque HAL SOC handle
  755. * @hal_ring: Source ring pointer
  756. *
  757. * Return: Opaque pointer for next ring entry; NULL on failire
  758. */
  759. static inline uint32_t hal_srng_src_done_val(void *hal_soc, void *hal_ring)
  760. {
  761. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  762. /* TODO: Using % is expensive, but we have to do this since
  763. * size of some SRNG rings is not power of 2 (due to descriptor
  764. * sizes). Need to create separate API for rings used
  765. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  766. * SW2RXDMA and CE rings)
  767. */
  768. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  769. srng->ring_size;
  770. if (next_reap_hp == srng->u.src_ring.cached_tp)
  771. return 0;
  772. if (srng->u.src_ring.cached_tp > next_reap_hp)
  773. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  774. srng->entry_size;
  775. else
  776. return ((srng->ring_size - next_reap_hp) +
  777. srng->u.src_ring.cached_tp) / srng->entry_size;
  778. }
  779. /**
  780. * hal_get_entrysize_from_srng() - Retrieve ring entry size
  781. * @hal_ring: Source ring pointer
  782. *
  783. * Return: uint8_t
  784. */
  785. static inline
  786. uint8_t hal_get_entrysize_from_srng(void *hal_ring)
  787. {
  788. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  789. return srng->entry_size;
  790. }
  791. /**
  792. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  793. * @hal_soc: Opaque HAL SOC handle
  794. * @hal_ring: Source ring pointer
  795. * @tailp: Tail Pointer
  796. * @headp: Head Pointer
  797. *
  798. * Return: Update tail pointer and head pointer in arguments.
  799. */
  800. static inline void hal_get_sw_hptp(void *hal_soc, void *hal_ring,
  801. uint32_t *tailp, uint32_t *headp)
  802. {
  803. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  804. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  805. *headp = srng->u.src_ring.hp;
  806. *tailp = *srng->u.src_ring.tp_addr;
  807. } else {
  808. *tailp = srng->u.dst_ring.tp;
  809. *headp = *srng->u.dst_ring.hp_addr;
  810. }
  811. }
  812. /**
  813. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  814. *
  815. * @hal_soc: Opaque HAL SOC handle
  816. * @hal_ring: Source ring pointer
  817. *
  818. * Return: Opaque pointer for next ring entry; NULL on failire
  819. */
  820. static inline void *hal_srng_src_get_next(void *hal_soc, void *hal_ring)
  821. {
  822. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  823. uint32_t *desc;
  824. /* TODO: Using % is expensive, but we have to do this since
  825. * size of some SRNG rings is not power of 2 (due to descriptor
  826. * sizes). Need to create separate API for rings used
  827. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  828. * SW2RXDMA and CE rings)
  829. */
  830. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  831. srng->ring_size;
  832. if (next_hp != srng->u.src_ring.cached_tp) {
  833. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  834. srng->u.src_ring.hp = next_hp;
  835. /* TODO: Since reap function is not used by all rings, we can
  836. * remove the following update of reap_hp in this function
  837. * if we can ensure that only hal_srng_src_get_next_reaped
  838. * is used for the rings requiring reap functionality
  839. */
  840. srng->u.src_ring.reap_hp = next_hp;
  841. return (void *)desc;
  842. }
  843. return NULL;
  844. }
  845. /**
  846. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  847. * hal_srng_src_get_next should be called subsequently to move the head pointer
  848. *
  849. * @hal_soc: Opaque HAL SOC handle
  850. * @hal_ring: Source ring pointer
  851. *
  852. * Return: Opaque pointer for next ring entry; NULL on failire
  853. */
  854. static inline void *hal_srng_src_peek(void *hal_soc, void *hal_ring)
  855. {
  856. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  857. uint32_t *desc;
  858. /* TODO: Using % is expensive, but we have to do this since
  859. * size of some SRNG rings is not power of 2 (due to descriptor
  860. * sizes). Need to create separate API for rings used
  861. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  862. * SW2RXDMA and CE rings)
  863. */
  864. if (((srng->u.src_ring.hp + srng->entry_size) %
  865. srng->ring_size) != srng->u.src_ring.cached_tp) {
  866. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  867. return (void *)desc;
  868. }
  869. return NULL;
  870. }
  871. /**
  872. * hal_srng_src_num_avail - Returns number of available entries in src ring
  873. *
  874. * @hal_soc: Opaque HAL SOC handle
  875. * @hal_ring: Source ring pointer
  876. * @sync_hw_ptr: Sync cached tail pointer with HW
  877. *
  878. */
  879. static inline uint32_t hal_srng_src_num_avail(void *hal_soc,
  880. void *hal_ring, int sync_hw_ptr)
  881. {
  882. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  883. uint32_t tp;
  884. uint32_t hp = srng->u.src_ring.hp;
  885. if (sync_hw_ptr) {
  886. tp = *(srng->u.src_ring.tp_addr);
  887. srng->u.src_ring.cached_tp = tp;
  888. } else {
  889. tp = srng->u.src_ring.cached_tp;
  890. }
  891. if (tp > hp)
  892. return ((tp - hp) / srng->entry_size) - 1;
  893. else
  894. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  895. }
  896. /**
  897. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  898. * ring head/tail pointers to HW.
  899. * This should be used only if hal_srng_access_start_unlocked to start ring
  900. * access
  901. *
  902. * @hal_soc: Opaque HAL SOC handle
  903. * @hal_ring: Ring pointer (Source or Destination ring)
  904. *
  905. * Return: 0 on success; error on failire
  906. */
  907. static inline void hal_srng_access_end_unlocked(void *hal_soc, void *hal_ring)
  908. {
  909. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  910. /* TODO: See if we need a write memory barrier here */
  911. if (srng->flags & HAL_SRNG_LMAC_RING) {
  912. /* For LMAC rings, ring pointer updates are done through FW and
  913. * hence written to a shared memory location that is read by FW
  914. */
  915. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  916. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  917. } else {
  918. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  919. }
  920. } else {
  921. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  922. hal_write_address_32_mb(hal_soc,
  923. srng->u.src_ring.hp_addr,
  924. srng->u.src_ring.hp);
  925. else
  926. hal_write_address_32_mb(hal_soc,
  927. srng->u.dst_ring.tp_addr,
  928. srng->u.dst_ring.tp);
  929. }
  930. }
  931. /**
  932. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  933. * pointers to HW
  934. * This should be used only if hal_srng_access_start to start ring access
  935. *
  936. * @hal_soc: Opaque HAL SOC handle
  937. * @hal_ring: Ring pointer (Source or Destination ring)
  938. *
  939. * Return: 0 on success; error on failire
  940. */
  941. static inline void hal_srng_access_end(void *hal_soc, void *hal_ring)
  942. {
  943. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  944. if (qdf_unlikely(!hal_ring)) {
  945. qdf_print("Error: Invalid hal_ring\n");
  946. return;
  947. }
  948. hal_srng_access_end_unlocked(hal_soc, hal_ring);
  949. SRNG_UNLOCK(&(srng->lock));
  950. }
  951. /**
  952. * hal_srng_access_end_reap - Unlock ring access
  953. * This should be used only if hal_srng_access_start to start ring access
  954. * and should be used only while reaping SRC ring completions
  955. *
  956. * @hal_soc: Opaque HAL SOC handle
  957. * @hal_ring: Ring pointer (Source or Destination ring)
  958. *
  959. * Return: 0 on success; error on failire
  960. */
  961. static inline void hal_srng_access_end_reap(void *hal_soc, void *hal_ring)
  962. {
  963. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  964. SRNG_UNLOCK(&(srng->lock));
  965. }
  966. /* TODO: Check if the following definitions is available in HW headers */
  967. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  968. #define NUM_MPDUS_PER_LINK_DESC 6
  969. #define NUM_MSDUS_PER_LINK_DESC 7
  970. #define REO_QUEUE_DESC_ALIGN 128
  971. #define LINK_DESC_ALIGN 128
  972. #define ADDRESS_MATCH_TAG_VAL 0x5
  973. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  974. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  975. */
  976. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  977. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  978. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  979. * should be specified in 16 word units. But the number of bits defined for
  980. * this field in HW header files is 5.
  981. */
  982. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  983. /**
  984. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  985. * in an idle list
  986. *
  987. * @hal_soc: Opaque HAL SOC handle
  988. *
  989. */
  990. static inline uint32_t hal_idle_list_scatter_buf_size(void *hal_soc)
  991. {
  992. return WBM_IDLE_SCATTER_BUF_SIZE;
  993. }
  994. /**
  995. * hal_get_link_desc_size - Get the size of each link descriptor
  996. *
  997. * @hal_soc: Opaque HAL SOC handle
  998. *
  999. */
  1000. static inline uint32_t hal_get_link_desc_size(struct hal_soc *hal_soc)
  1001. {
  1002. if (!hal_soc || !hal_soc->ops) {
  1003. qdf_print("Error: Invalid ops\n");
  1004. QDF_BUG(0);
  1005. return -EINVAL;
  1006. }
  1007. if (!hal_soc->ops->hal_get_link_desc_size) {
  1008. qdf_print("Error: Invalid function pointer\n");
  1009. QDF_BUG(0);
  1010. return -EINVAL;
  1011. }
  1012. return hal_soc->ops->hal_get_link_desc_size();
  1013. }
  1014. /**
  1015. * hal_get_link_desc_align - Get the required start address alignment for
  1016. * link descriptors
  1017. *
  1018. * @hal_soc: Opaque HAL SOC handle
  1019. *
  1020. */
  1021. static inline uint32_t hal_get_link_desc_align(void *hal_soc)
  1022. {
  1023. return LINK_DESC_ALIGN;
  1024. }
  1025. /**
  1026. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  1027. *
  1028. * @hal_soc: Opaque HAL SOC handle
  1029. *
  1030. */
  1031. static inline uint32_t hal_num_mpdus_per_link_desc(void *hal_soc)
  1032. {
  1033. return NUM_MPDUS_PER_LINK_DESC;
  1034. }
  1035. /**
  1036. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  1037. *
  1038. * @hal_soc: Opaque HAL SOC handle
  1039. *
  1040. */
  1041. static inline uint32_t hal_num_msdus_per_link_desc(void *hal_soc)
  1042. {
  1043. return NUM_MSDUS_PER_LINK_DESC;
  1044. }
  1045. /**
  1046. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1047. * descriptor can hold
  1048. *
  1049. * @hal_soc: Opaque HAL SOC handle
  1050. *
  1051. */
  1052. static inline uint32_t hal_num_mpdu_links_per_queue_desc(void *hal_soc)
  1053. {
  1054. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1055. }
  1056. /**
  1057. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1058. * that the given buffer size
  1059. *
  1060. * @hal_soc: Opaque HAL SOC handle
  1061. * @scatter_buf_size: Size of scatter buffer
  1062. *
  1063. */
  1064. static inline uint32_t hal_idle_scatter_buf_num_entries(void *hal_soc,
  1065. uint32_t scatter_buf_size)
  1066. {
  1067. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1068. hal_srng_get_entrysize(hal_soc, WBM_IDLE_LINK);
  1069. }
  1070. /**
  1071. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1072. * each given buffer size
  1073. *
  1074. * @hal_soc: Opaque HAL SOC handle
  1075. * @total_mem: size of memory to be scattered
  1076. * @scatter_buf_size: Size of scatter buffer
  1077. *
  1078. */
  1079. static inline uint32_t hal_idle_list_num_scatter_bufs(void *hal_soc,
  1080. uint32_t total_mem, uint32_t scatter_buf_size)
  1081. {
  1082. uint8_t rem = (total_mem % (scatter_buf_size -
  1083. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1084. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1085. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1086. return num_scatter_bufs;
  1087. }
  1088. /* REO parameters to be passed to hal_reo_setup */
  1089. struct hal_reo_params {
  1090. /** rx hash steering enabled or disabled */
  1091. bool rx_hash_enabled;
  1092. /** reo remap 1 register */
  1093. uint32_t remap1;
  1094. /** reo remap 2 register */
  1095. uint32_t remap2;
  1096. /** fragment destination ring */
  1097. uint8_t frag_dst_ring;
  1098. /** padding */
  1099. uint8_t padding[3];
  1100. };
  1101. enum hal_pn_type {
  1102. HAL_PN_NONE,
  1103. HAL_PN_WPA,
  1104. HAL_PN_WAPI_EVEN,
  1105. HAL_PN_WAPI_UNEVEN,
  1106. };
  1107. #define HAL_RX_MAX_BA_WINDOW 256
  1108. /**
  1109. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1110. * queue descriptors
  1111. *
  1112. * @hal_soc: Opaque HAL SOC handle
  1113. *
  1114. */
  1115. static inline uint32_t hal_get_reo_qdesc_align(void *hal_soc)
  1116. {
  1117. return REO_QUEUE_DESC_ALIGN;
  1118. }
  1119. /**
  1120. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1121. *
  1122. * @hal_soc: Opaque HAL SOC handle
  1123. * @ba_window_size: BlockAck window size
  1124. * @start_seq: Starting sequence number
  1125. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1126. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1127. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1128. *
  1129. */
  1130. extern void hal_reo_qdesc_setup(void *hal_soc, int tid, uint32_t ba_window_size,
  1131. uint32_t start_seq, void *hw_qdesc_vaddr, qdf_dma_addr_t hw_qdesc_paddr,
  1132. int pn_type);
  1133. /**
  1134. * hal_srng_get_hp_addr - Get head pointer physical address
  1135. *
  1136. * @hal_soc: Opaque HAL SOC handle
  1137. * @hal_ring: Ring pointer (Source or Destination ring)
  1138. *
  1139. */
  1140. static inline qdf_dma_addr_t hal_srng_get_hp_addr(void *hal_soc, void *hal_ring)
  1141. {
  1142. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1143. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1144. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1145. return hal->shadow_wrptr_mem_paddr +
  1146. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1147. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1148. } else {
  1149. return hal->shadow_rdptr_mem_paddr +
  1150. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1151. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1152. }
  1153. }
  1154. /**
  1155. * hal_srng_get_tp_addr - Get tail pointer physical address
  1156. *
  1157. * @hal_soc: Opaque HAL SOC handle
  1158. * @hal_ring: Ring pointer (Source or Destination ring)
  1159. *
  1160. */
  1161. static inline qdf_dma_addr_t hal_srng_get_tp_addr(void *hal_soc, void *hal_ring)
  1162. {
  1163. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1164. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1165. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1166. return hal->shadow_rdptr_mem_paddr +
  1167. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1168. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1169. } else {
  1170. return hal->shadow_wrptr_mem_paddr +
  1171. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1172. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1173. }
  1174. }
  1175. /**
  1176. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1177. *
  1178. * @hal_soc: Opaque HAL SOC handle
  1179. * @hal_ring: Ring pointer (Source or Destination ring)
  1180. * @ring_params: SRNG parameters will be returned through this structure
  1181. */
  1182. extern void hal_get_srng_params(void *hal_soc, void *hal_ring,
  1183. struct hal_srng_params *ring_params);
  1184. /**
  1185. * hal_mem_info - Retrieve hal memory base address
  1186. *
  1187. * @hal_soc: Opaque HAL SOC handle
  1188. * @mem: pointer to structure to be updated with hal mem info
  1189. */
  1190. extern void hal_get_meminfo(void *hal_soc,struct hal_mem_info *mem );
  1191. /**
  1192. * hal_get_target_type - Return target type
  1193. *
  1194. * @hal_soc: Opaque HAL SOC handle
  1195. */
  1196. uint32_t hal_get_target_type(struct hal_soc *hal);
  1197. /**
  1198. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1199. *
  1200. * @hal_soc: Opaque HAL SOC handle
  1201. * @ac: Access category
  1202. * @value: timeout duration in millisec
  1203. */
  1204. void hal_get_ba_aging_timeout(void *hal_soc, uint8_t ac,
  1205. uint32_t *value);
  1206. /**
  1207. * hal_set_aging_timeout - Set BA aging timeout
  1208. *
  1209. * @hal_soc: Opaque HAL SOC handle
  1210. * @ac: Access category in millisec
  1211. * @value: timeout duration value
  1212. */
  1213. void hal_set_ba_aging_timeout(void *hal_soc, uint8_t ac,
  1214. uint32_t value);
  1215. /**
  1216. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1217. * destination ring HW
  1218. * @hal_soc: HAL SOC handle
  1219. * @srng: SRNG ring pointer
  1220. */
  1221. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1222. struct hal_srng *srng)
  1223. {
  1224. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1225. }
  1226. /**
  1227. * hal_srng_src_hw_init - Private function to initialize SRNG
  1228. * source ring HW
  1229. * @hal_soc: HAL SOC handle
  1230. * @srng: SRNG ring pointer
  1231. */
  1232. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1233. struct hal_srng *srng)
  1234. {
  1235. hal->ops->hal_srng_src_hw_init(hal, srng);
  1236. }
  1237. /**
  1238. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  1239. * @hal_soc: Opaque HAL SOC handle
  1240. * @hal_ring: Source ring pointer
  1241. * @headp: Head Pointer
  1242. * @tailp: Tail Pointer
  1243. * @ring_type: Ring
  1244. *
  1245. * Return: Update tail pointer and head pointer in arguments.
  1246. */
  1247. static inline void hal_get_hw_hptp(struct hal_soc *hal, void *hal_ring,
  1248. uint32_t *headp, uint32_t *tailp,
  1249. uint8_t ring_type)
  1250. {
  1251. hal->ops->hal_get_hw_hptp(hal, hal_ring, headp, tailp, ring_type);
  1252. }
  1253. /**
  1254. * hal_reo_setup - Initialize HW REO block
  1255. *
  1256. * @hal_soc: Opaque HAL SOC handle
  1257. * @reo_params: parameters needed by HAL for REO config
  1258. */
  1259. static inline void hal_reo_setup(void *halsoc,
  1260. void *reoparams)
  1261. {
  1262. struct hal_soc *hal_soc = (struct hal_soc *)halsoc;
  1263. hal_soc->ops->hal_reo_setup(halsoc, reoparams);
  1264. }
  1265. /**
  1266. * hal_setup_link_idle_list - Setup scattered idle list using the
  1267. * buffer list provided
  1268. *
  1269. * @hal_soc: Opaque HAL SOC handle
  1270. * @scatter_bufs_base_paddr: Array of physical base addresses
  1271. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1272. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1273. * @scatter_buf_size: Size of each scatter buffer
  1274. * @last_buf_end_offset: Offset to the last entry
  1275. * @num_entries: Total entries of all scatter bufs
  1276. *
  1277. */
  1278. static inline void hal_setup_link_idle_list(void *halsoc,
  1279. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1280. void *scatter_bufs_base_vaddr[], uint32_t num_scatter_bufs,
  1281. uint32_t scatter_buf_size, uint32_t last_buf_end_offset,
  1282. uint32_t num_entries)
  1283. {
  1284. struct hal_soc *hal_soc = (struct hal_soc *)halsoc;
  1285. hal_soc->ops->hal_setup_link_idle_list(halsoc, scatter_bufs_base_paddr,
  1286. scatter_bufs_base_vaddr, num_scatter_bufs,
  1287. scatter_buf_size, last_buf_end_offset,
  1288. num_entries);
  1289. }
  1290. /**
  1291. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  1292. *
  1293. * @hal_soc: Opaque HAL SOC handle
  1294. * @hal_ring: Source ring pointer
  1295. * @ring_desc: Opaque ring descriptor handle
  1296. */
  1297. static inline void hal_srng_dump_ring_desc(struct hal_soc *hal, void *hal_ring,
  1298. void *ring_desc)
  1299. {
  1300. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1301. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
  1302. ring_desc, (srng->entry_size << 2));
  1303. }
  1304. /**
  1305. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  1306. *
  1307. * @hal_soc: Opaque HAL SOC handle
  1308. * @hal_ring: Source ring pointer
  1309. */
  1310. static inline void hal_srng_dump_ring(struct hal_soc *hal, void *hal_ring)
  1311. {
  1312. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1313. uint32_t *desc;
  1314. uint32_t tp, i;
  1315. tp = srng->u.dst_ring.tp;
  1316. for (i = 0; i < 128; i++) {
  1317. if (!tp)
  1318. tp = srng->ring_size;
  1319. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  1320. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  1321. QDF_TRACE_LEVEL_DEBUG,
  1322. desc, (srng->entry_size << 2));
  1323. tp -= srng->entry_size;
  1324. }
  1325. }
  1326. #endif /* _HAL_APIH_ */