hal_api.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  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 PN_SIZE_24 0
  278. #define PN_SIZE_48 1
  279. #define PN_SIZE_128 2
  280. /**
  281. * hal_srng_get_entrysize - Returns size of ring entry in bytes. Should be
  282. * used by callers for calculating the size of memory to be allocated before
  283. * calling hal_srng_setup to setup the ring
  284. *
  285. * @hal_soc: Opaque HAL SOC handle
  286. * @ring_type: one of the types from hal_ring_type
  287. *
  288. */
  289. extern uint32_t hal_srng_get_entrysize(void *hal_soc, int ring_type);
  290. /**
  291. * hal_srng_max_entries - Returns maximum possible number of ring entries
  292. * @hal_soc: Opaque HAL SOC handle
  293. * @ring_type: one of the types from hal_ring_type
  294. *
  295. * Return: Maximum number of entries for the given ring_type
  296. */
  297. uint32_t hal_srng_max_entries(void *hal_soc, int ring_type);
  298. /**
  299. * hal_srng_dump - Dump ring status
  300. * @srng: hal srng pointer
  301. */
  302. void hal_srng_dump(struct hal_srng *srng);
  303. /**
  304. * hal_srng_get_dir - Returns the direction of the ring
  305. * @hal_soc: Opaque HAL SOC handle
  306. * @ring_type: one of the types from hal_ring_type
  307. *
  308. * Return: Ring direction
  309. */
  310. enum hal_srng_dir hal_srng_get_dir(void *hal_soc, int ring_type);
  311. /* HAL memory information */
  312. struct hal_mem_info {
  313. /* dev base virutal addr */
  314. void *dev_base_addr;
  315. /* dev base physical addr */
  316. void *dev_base_paddr;
  317. /* Remote virtual pointer memory for HW/FW updates */
  318. void *shadow_rdptr_mem_vaddr;
  319. /* Remote physical pointer memory for HW/FW updates */
  320. void *shadow_rdptr_mem_paddr;
  321. /* Shared memory for ring pointer updates from host to FW */
  322. void *shadow_wrptr_mem_vaddr;
  323. /* Shared physical memory for ring pointer updates from host to FW */
  324. void *shadow_wrptr_mem_paddr;
  325. };
  326. /* SRNG parameters to be passed to hal_srng_setup */
  327. struct hal_srng_params {
  328. /* Physical base address of the ring */
  329. qdf_dma_addr_t ring_base_paddr;
  330. /* Virtual base address of the ring */
  331. void *ring_base_vaddr;
  332. /* Number of entries in ring */
  333. uint32_t num_entries;
  334. /* max transfer length */
  335. uint16_t max_buffer_length;
  336. /* MSI Address */
  337. qdf_dma_addr_t msi_addr;
  338. /* MSI data */
  339. uint32_t msi_data;
  340. /* Interrupt timer threshold – in micro seconds */
  341. uint32_t intr_timer_thres_us;
  342. /* Interrupt batch counter threshold – in number of ring entries */
  343. uint32_t intr_batch_cntr_thres_entries;
  344. /* Low threshold – in number of ring entries
  345. * (valid for src rings only)
  346. */
  347. uint32_t low_threshold;
  348. /* Misc flags */
  349. uint32_t flags;
  350. /* Unique ring id */
  351. uint8_t ring_id;
  352. /* Source or Destination ring */
  353. enum hal_srng_dir ring_dir;
  354. /* Size of ring entry */
  355. uint32_t entry_size;
  356. /* hw register base address */
  357. void *hwreg_base[MAX_SRNG_REG_GROUPS];
  358. };
  359. /* hal_construct_shadow_config() - initialize the shadow registers for dp rings
  360. * @hal_soc: hal handle
  361. *
  362. * Return: QDF_STATUS_OK on success
  363. */
  364. extern QDF_STATUS hal_construct_shadow_config(void *hal_soc);
  365. /* hal_set_one_shadow_config() - add a config for the specified ring
  366. * @hal_soc: hal handle
  367. * @ring_type: ring type
  368. * @ring_num: ring num
  369. *
  370. * The ring type and ring num uniquely specify the ring. After this call,
  371. * the hp/tp will be added as the next entry int the shadow register
  372. * configuration table. The hal code will use the shadow register address
  373. * in place of the hp/tp address.
  374. *
  375. * This function is exposed, so that the CE module can skip configuring shadow
  376. * registers for unused ring and rings assigned to the firmware.
  377. *
  378. * Return: QDF_STATUS_OK on success
  379. */
  380. extern QDF_STATUS hal_set_one_shadow_config(void *hal_soc, int ring_type,
  381. int ring_num);
  382. /**
  383. * hal_get_shadow_config() - retrieve the config table
  384. * @hal_soc: hal handle
  385. * @shadow_config: will point to the table after
  386. * @num_shadow_registers_configured: will contain the number of valid entries
  387. */
  388. extern void hal_get_shadow_config(void *hal_soc,
  389. struct pld_shadow_reg_v2_cfg **shadow_config,
  390. int *num_shadow_registers_configured);
  391. /**
  392. * hal_srng_setup - Initialize HW SRNG ring.
  393. *
  394. * @hal_soc: Opaque HAL SOC handle
  395. * @ring_type: one of the types from hal_ring_type
  396. * @ring_num: Ring number if there are multiple rings of
  397. * same type (staring from 0)
  398. * @mac_id: valid MAC Id should be passed if ring type is one of lmac rings
  399. * @ring_params: SRNG ring params in hal_srng_params structure.
  400. * Callers are expected to allocate contiguous ring memory of size
  401. * 'num_entries * entry_size' bytes and pass the physical and virtual base
  402. * addresses through 'ring_base_paddr' and 'ring_base_vaddr' in hal_srng_params
  403. * structure. Ring base address should be 8 byte aligned and size of each ring
  404. * entry should be queried using the API hal_srng_get_entrysize
  405. *
  406. * Return: Opaque pointer to ring on success
  407. * NULL on failure (if given ring is not available)
  408. */
  409. extern void *hal_srng_setup(void *hal_soc, int ring_type, int ring_num,
  410. int mac_id, struct hal_srng_params *ring_params);
  411. /* Remapping ids of REO rings */
  412. #define REO_REMAP_TCL 0
  413. #define REO_REMAP_SW1 1
  414. #define REO_REMAP_SW2 2
  415. #define REO_REMAP_SW3 3
  416. #define REO_REMAP_SW4 4
  417. #define REO_REMAP_RELEASE 5
  418. #define REO_REMAP_FW 6
  419. #define REO_REMAP_UNUSED 7
  420. /*
  421. * currently this macro only works for IX0 since all the rings we are remapping
  422. * can be remapped from HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0
  423. */
  424. #define HAL_REO_REMAP_VAL(_ORIGINAL_DEST, _NEW_DEST) \
  425. HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST)
  426. /* allow the destination macros to be expanded */
  427. #define HAL_REO_REMAP_VAL_(_ORIGINAL_DEST, _NEW_DEST) \
  428. (_NEW_DEST << \
  429. (HWIO_REO_R0_DESTINATION_RING_CTRL_IX_0_DEST_RING_MAPPING_ ## \
  430. _ORIGINAL_DEST ## _SHFT))
  431. /**
  432. * hal_reo_read_write_ctrl_ix - Read or write REO_DESTINATION_RING_CTRL_IX
  433. * @hal: HAL SOC handle
  434. * @read: boolean value to indicate if read or write
  435. * @ix0: pointer to store IX0 reg value
  436. * @ix1: pointer to store IX1 reg value
  437. * @ix2: pointer to store IX2 reg value
  438. * @ix3: pointer to store IX3 reg value
  439. */
  440. extern void hal_reo_read_write_ctrl_ix(struct hal_soc *hal, bool read,
  441. uint32_t *ix0, uint32_t *ix1,
  442. uint32_t *ix2, uint32_t *ix3);
  443. /**
  444. * hal_srng_set_hp_paddr() - Set physical address to dest SRNG head pointer
  445. * @sring: sring pointer
  446. * @paddr: physical address
  447. */
  448. extern void hal_srng_dst_set_hp_paddr(struct hal_srng *sring, uint64_t paddr);
  449. /**
  450. * hal_srng_dst_init_hp() - Initilaize head pointer with cached head pointer
  451. * @srng: sring pointer
  452. * @vaddr: virtual address
  453. */
  454. extern void hal_srng_dst_init_hp(struct hal_srng *srng, uint32_t *vaddr);
  455. /**
  456. * hal_srng_cleanup - Deinitialize HW SRNG ring.
  457. * @hal_soc: Opaque HAL SOC handle
  458. * @hal_srng: Opaque HAL SRNG pointer
  459. */
  460. extern void hal_srng_cleanup(void *hal_soc, void *hal_srng);
  461. static inline bool hal_srng_initialized(void *hal_ring)
  462. {
  463. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  464. return !!srng->initialized;
  465. }
  466. /**
  467. * hal_srng_access_start_unlocked - Start ring access (unlocked). Should use
  468. * hal_srng_access_start if locked access is required
  469. *
  470. * @hal_soc: Opaque HAL SOC handle
  471. * @hal_ring: Ring pointer (Source or Destination ring)
  472. *
  473. * Return: 0 on success; error on failire
  474. */
  475. static inline int hal_srng_access_start_unlocked(void *hal_soc, void *hal_ring)
  476. {
  477. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  478. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  479. srng->u.src_ring.cached_tp =
  480. *(volatile uint32_t *)(srng->u.src_ring.tp_addr);
  481. else
  482. srng->u.dst_ring.cached_hp =
  483. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  484. return 0;
  485. }
  486. /**
  487. * hal_srng_access_start - Start (locked) ring access
  488. *
  489. * @hal_soc: Opaque HAL SOC handle
  490. * @hal_ring: Ring pointer (Source or Destination ring)
  491. *
  492. * Return: 0 on success; error on failire
  493. */
  494. static inline int hal_srng_access_start(void *hal_soc, void *hal_ring)
  495. {
  496. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  497. if (qdf_unlikely(!hal_ring)) {
  498. qdf_print("Error: Invalid hal_ring\n");
  499. return -EINVAL;
  500. }
  501. SRNG_LOCK(&(srng->lock));
  502. return hal_srng_access_start_unlocked(hal_soc, hal_ring);
  503. }
  504. /**
  505. * hal_srng_dst_get_next - Get next entry from a destination ring and move
  506. * cached tail pointer
  507. *
  508. * @hal_soc: Opaque HAL SOC handle
  509. * @hal_ring: Destination ring pointer
  510. *
  511. * Return: Opaque pointer for next ring entry; NULL on failire
  512. */
  513. static inline void *hal_srng_dst_get_next(void *hal_soc, void *hal_ring)
  514. {
  515. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  516. uint32_t *desc;
  517. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp) {
  518. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  519. /* TODO: Using % is expensive, but we have to do this since
  520. * size of some SRNG rings is not power of 2 (due to descriptor
  521. * sizes). Need to create separate API for rings used
  522. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  523. * SW2RXDMA and CE rings)
  524. */
  525. srng->u.dst_ring.tp = (srng->u.dst_ring.tp + srng->entry_size) %
  526. srng->ring_size;
  527. return (void *)desc;
  528. }
  529. return NULL;
  530. }
  531. /**
  532. * hal_srng_dst_get_next_hp - Get next entry from a destination ring and move
  533. * cached head pointer
  534. *
  535. * @hal_soc: Opaque HAL SOC handle
  536. * @hal_ring: Destination ring pointer
  537. *
  538. * Return: Opaque pointer for next ring entry; NULL on failire
  539. */
  540. static inline void *hal_srng_dst_get_next_hp(void *hal_soc, void *hal_ring)
  541. {
  542. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  543. uint32_t *desc;
  544. /* TODO: Using % is expensive, but we have to do this since
  545. * size of some SRNG rings is not power of 2 (due to descriptor
  546. * sizes). Need to create separate API for rings used
  547. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  548. * SW2RXDMA and CE rings)
  549. */
  550. uint32_t next_hp = (srng->u.dst_ring.cached_hp + srng->entry_size) %
  551. srng->ring_size;
  552. if (next_hp != srng->u.dst_ring.tp) {
  553. desc = &(srng->ring_base_vaddr[srng->u.dst_ring.cached_hp]);
  554. srng->u.dst_ring.cached_hp = next_hp;
  555. return (void *)desc;
  556. }
  557. return NULL;
  558. }
  559. /**
  560. * hal_srng_dst_peek - Check if there are any entries in the ring (peek)
  561. * @hal_soc: Opaque HAL SOC handle
  562. * @hal_ring: Destination ring pointer
  563. *
  564. * Caller takes responsibility for any locking needs.
  565. *
  566. * Return: Opaque pointer for next ring entry; NULL on failire
  567. */
  568. static inline
  569. void *hal_srng_dst_peek(void *hal_soc, void *hal_ring)
  570. {
  571. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  572. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  573. return (void *)(&srng->ring_base_vaddr[srng->u.dst_ring.tp]);
  574. return NULL;
  575. }
  576. /**
  577. * hal_srng_dst_peek_sync - Check if there are any entries in the ring (peek)
  578. * @hal_soc: Opaque HAL SOC handle
  579. * @hal_ring: Destination ring pointer
  580. *
  581. * Sync cached head pointer with HW.
  582. * Caller takes responsibility for any locking needs.
  583. *
  584. * Return: Opaque pointer for next ring entry; NULL on failire
  585. */
  586. static inline
  587. void *hal_srng_dst_peek_sync(void *hal_soc, void *hal_ring)
  588. {
  589. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  590. srng->u.dst_ring.cached_hp =
  591. *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  592. if (srng->u.dst_ring.tp != srng->u.dst_ring.cached_hp)
  593. return (void *)(&(srng->ring_base_vaddr[srng->u.dst_ring.tp]));
  594. return NULL;
  595. }
  596. /**
  597. * hal_srng_dst_peek_sync_locked - Peek for any entries in the ring
  598. * @hal_soc: Opaque HAL SOC handle
  599. * @hal_ring: Destination ring pointer
  600. *
  601. * Sync cached head pointer with HW.
  602. * This function takes up SRNG_LOCK. Should not be called with SRNG lock held.
  603. *
  604. * Return: Opaque pointer for next ring entry; NULL on failire
  605. */
  606. static inline
  607. void *hal_srng_dst_peek_sync_locked(void *hal_soc, void *hal_ring)
  608. {
  609. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  610. void *ring_desc_ptr = NULL;
  611. if (qdf_unlikely(!hal_ring)) {
  612. qdf_print("Error: Invalid hal_ring\n");
  613. return NULL;
  614. }
  615. SRNG_LOCK(&srng->lock);
  616. ring_desc_ptr = hal_srng_dst_peek_sync(hal_soc, hal_ring);
  617. SRNG_UNLOCK(&srng->lock);
  618. return ring_desc_ptr;
  619. }
  620. /**
  621. * hal_srng_dst_num_valid - Returns number of valid entries (to be processed
  622. * by SW) in destination ring
  623. *
  624. * @hal_soc: Opaque HAL SOC handle
  625. * @hal_ring: Destination ring pointer
  626. * @sync_hw_ptr: Sync cached head pointer with HW
  627. *
  628. */
  629. static inline uint32_t hal_srng_dst_num_valid(void *hal_soc, void *hal_ring,
  630. int sync_hw_ptr)
  631. {
  632. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  633. uint32_t hp;
  634. uint32_t tp = srng->u.dst_ring.tp;
  635. if (sync_hw_ptr) {
  636. hp = *(volatile uint32_t *)(srng->u.dst_ring.hp_addr);
  637. srng->u.dst_ring.cached_hp = hp;
  638. } else {
  639. hp = srng->u.dst_ring.cached_hp;
  640. }
  641. if (hp >= tp)
  642. return (hp - tp) / srng->entry_size;
  643. else
  644. return (srng->ring_size - tp + hp) / srng->entry_size;
  645. }
  646. /**
  647. * hal_srng_src_reap_next - Reap next entry from a source ring and move reap
  648. * pointer. This can be used to release any buffers associated with completed
  649. * ring entries. Note that this should not be used for posting new descriptor
  650. * entries. Posting of new entries should be done only using
  651. * hal_srng_src_get_next_reaped when this function is used for reaping.
  652. *
  653. * @hal_soc: Opaque HAL SOC handle
  654. * @hal_ring: Source ring pointer
  655. *
  656. * Return: Opaque pointer for next ring entry; NULL on failire
  657. */
  658. static inline void *hal_srng_src_reap_next(void *hal_soc, void *hal_ring)
  659. {
  660. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  661. uint32_t *desc;
  662. /* TODO: Using % is expensive, but we have to do this since
  663. * size of some SRNG rings is not power of 2 (due to descriptor
  664. * sizes). Need to create separate API for rings used
  665. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  666. * SW2RXDMA and CE rings)
  667. */
  668. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  669. srng->ring_size;
  670. if (next_reap_hp != srng->u.src_ring.cached_tp) {
  671. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  672. srng->u.src_ring.reap_hp = next_reap_hp;
  673. return (void *)desc;
  674. }
  675. return NULL;
  676. }
  677. /**
  678. * hal_srng_src_get_next_reaped - Get next entry from a source ring that is
  679. * already reaped using hal_srng_src_reap_next, for posting new entries to
  680. * the ring
  681. *
  682. * @hal_soc: Opaque HAL SOC handle
  683. * @hal_ring: Source ring pointer
  684. *
  685. * Return: Opaque pointer for next (reaped) source ring entry; NULL on failire
  686. */
  687. static inline void *hal_srng_src_get_next_reaped(void *hal_soc, void *hal_ring)
  688. {
  689. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  690. uint32_t *desc;
  691. if (srng->u.src_ring.hp != srng->u.src_ring.reap_hp) {
  692. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  693. srng->u.src_ring.hp = (srng->u.src_ring.hp + srng->entry_size) %
  694. srng->ring_size;
  695. return (void *)desc;
  696. }
  697. return NULL;
  698. }
  699. /**
  700. * hal_srng_src_pending_reap_next - Reap next entry from a source ring and
  701. * move reap pointer. This API is used in detach path to release any buffers
  702. * associated with ring entries which are pending reap.
  703. *
  704. * @hal_soc: Opaque HAL SOC handle
  705. * @hal_ring: Source ring pointer
  706. *
  707. * Return: Opaque pointer for next ring entry; NULL on failire
  708. */
  709. static inline void *hal_srng_src_pending_reap_next(void *hal_soc, void *hal_ring)
  710. {
  711. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  712. uint32_t *desc;
  713. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  714. srng->ring_size;
  715. if (next_reap_hp != srng->u.src_ring.hp) {
  716. desc = &(srng->ring_base_vaddr[next_reap_hp]);
  717. srng->u.src_ring.reap_hp = next_reap_hp;
  718. return (void *)desc;
  719. }
  720. return NULL;
  721. }
  722. /**
  723. * hal_srng_src_done_val -
  724. *
  725. * @hal_soc: Opaque HAL SOC handle
  726. * @hal_ring: Source ring pointer
  727. *
  728. * Return: Opaque pointer for next ring entry; NULL on failire
  729. */
  730. static inline uint32_t hal_srng_src_done_val(void *hal_soc, void *hal_ring)
  731. {
  732. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  733. /* TODO: Using % is expensive, but we have to do this since
  734. * size of some SRNG rings is not power of 2 (due to descriptor
  735. * sizes). Need to create separate API for rings used
  736. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  737. * SW2RXDMA and CE rings)
  738. */
  739. uint32_t next_reap_hp = (srng->u.src_ring.reap_hp + srng->entry_size) %
  740. srng->ring_size;
  741. if (next_reap_hp == srng->u.src_ring.cached_tp)
  742. return 0;
  743. if (srng->u.src_ring.cached_tp > next_reap_hp)
  744. return (srng->u.src_ring.cached_tp - next_reap_hp) /
  745. srng->entry_size;
  746. else
  747. return ((srng->ring_size - next_reap_hp) +
  748. srng->u.src_ring.cached_tp) / srng->entry_size;
  749. }
  750. /**
  751. * hal_get_sw_hptp - Get SW head and tail pointer location for any ring
  752. * @hal_soc: Opaque HAL SOC handle
  753. * @hal_ring: Source ring pointer
  754. * @tailp: Tail Pointer
  755. * @headp: Head Pointer
  756. *
  757. * Return: Update tail pointer and head pointer in arguments.
  758. */
  759. static inline void hal_get_sw_hptp(void *hal_soc, void *hal_ring,
  760. uint32_t *tailp, uint32_t *headp)
  761. {
  762. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  763. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  764. *headp = srng->u.src_ring.hp / srng->entry_size;
  765. *tailp = *(srng->u.src_ring.tp_addr) / srng->entry_size;
  766. } else {
  767. *tailp = srng->u.dst_ring.tp / srng->entry_size;
  768. *headp = *(srng->u.dst_ring.hp_addr) / srng->entry_size;
  769. }
  770. }
  771. /**
  772. * hal_srng_src_get_next - Get next entry from a source ring and move cached tail pointer
  773. *
  774. * @hal_soc: Opaque HAL SOC handle
  775. * @hal_ring: Source ring pointer
  776. *
  777. * Return: Opaque pointer for next ring entry; NULL on failire
  778. */
  779. static inline void *hal_srng_src_get_next(void *hal_soc, void *hal_ring)
  780. {
  781. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  782. uint32_t *desc;
  783. /* TODO: Using % is expensive, but we have to do this since
  784. * size of some SRNG rings is not power of 2 (due to descriptor
  785. * sizes). Need to create separate API for rings used
  786. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  787. * SW2RXDMA and CE rings)
  788. */
  789. uint32_t next_hp = (srng->u.src_ring.hp + srng->entry_size) %
  790. srng->ring_size;
  791. if (next_hp != srng->u.src_ring.cached_tp) {
  792. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  793. srng->u.src_ring.hp = next_hp;
  794. /* TODO: Since reap function is not used by all rings, we can
  795. * remove the following update of reap_hp in this function
  796. * if we can ensure that only hal_srng_src_get_next_reaped
  797. * is used for the rings requiring reap functionality
  798. */
  799. srng->u.src_ring.reap_hp = next_hp;
  800. return (void *)desc;
  801. }
  802. return NULL;
  803. }
  804. /**
  805. * hal_srng_src_peek - Get next entry from a ring without moving head pointer.
  806. * hal_srng_src_get_next should be called subsequently to move the head pointer
  807. *
  808. * @hal_soc: Opaque HAL SOC handle
  809. * @hal_ring: Source ring pointer
  810. *
  811. * Return: Opaque pointer for next ring entry; NULL on failire
  812. */
  813. static inline void *hal_srng_src_peek(void *hal_soc, void *hal_ring)
  814. {
  815. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  816. uint32_t *desc;
  817. /* TODO: Using % is expensive, but we have to do this since
  818. * size of some SRNG rings is not power of 2 (due to descriptor
  819. * sizes). Need to create separate API for rings used
  820. * per-packet, with sizes power of 2 (TCL2SW, REO2SW,
  821. * SW2RXDMA and CE rings)
  822. */
  823. if (((srng->u.src_ring.hp + srng->entry_size) %
  824. srng->ring_size) != srng->u.src_ring.cached_tp) {
  825. desc = &(srng->ring_base_vaddr[srng->u.src_ring.hp]);
  826. return (void *)desc;
  827. }
  828. return NULL;
  829. }
  830. /**
  831. * hal_srng_src_num_avail - Returns number of available entries in src ring
  832. *
  833. * @hal_soc: Opaque HAL SOC handle
  834. * @hal_ring: Source ring pointer
  835. * @sync_hw_ptr: Sync cached tail pointer with HW
  836. *
  837. */
  838. static inline uint32_t hal_srng_src_num_avail(void *hal_soc,
  839. void *hal_ring, int sync_hw_ptr)
  840. {
  841. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  842. uint32_t tp;
  843. uint32_t hp = srng->u.src_ring.hp;
  844. if (sync_hw_ptr) {
  845. tp = *(srng->u.src_ring.tp_addr);
  846. srng->u.src_ring.cached_tp = tp;
  847. } else {
  848. tp = srng->u.src_ring.cached_tp;
  849. }
  850. if (tp > hp)
  851. return ((tp - hp) / srng->entry_size) - 1;
  852. else
  853. return ((srng->ring_size - hp + tp) / srng->entry_size) - 1;
  854. }
  855. /**
  856. * hal_srng_access_end_unlocked - End ring access (unlocked) - update cached
  857. * ring head/tail pointers to HW.
  858. * This should be used only if hal_srng_access_start_unlocked to start ring
  859. * access
  860. *
  861. * @hal_soc: Opaque HAL SOC handle
  862. * @hal_ring: Ring pointer (Source or Destination ring)
  863. *
  864. * Return: 0 on success; error on failire
  865. */
  866. static inline void hal_srng_access_end_unlocked(void *hal_soc, void *hal_ring)
  867. {
  868. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  869. /* TODO: See if we need a write memory barrier here */
  870. if (srng->flags & HAL_SRNG_LMAC_RING) {
  871. /* For LMAC rings, ring pointer updates are done through FW and
  872. * hence written to a shared memory location that is read by FW
  873. */
  874. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  875. *(srng->u.src_ring.hp_addr) = srng->u.src_ring.hp;
  876. } else {
  877. *(srng->u.dst_ring.tp_addr) = srng->u.dst_ring.tp;
  878. }
  879. } else {
  880. if (srng->ring_dir == HAL_SRNG_SRC_RING)
  881. hal_write_address_32_mb(hal_soc,
  882. srng->u.src_ring.hp_addr,
  883. srng->u.src_ring.hp);
  884. else
  885. hal_write_address_32_mb(hal_soc,
  886. srng->u.dst_ring.tp_addr,
  887. srng->u.dst_ring.tp);
  888. }
  889. }
  890. /**
  891. * hal_srng_access_end - Unlock ring access and update cached ring head/tail
  892. * pointers to HW
  893. * This should be used only if hal_srng_access_start to start ring access
  894. *
  895. * @hal_soc: Opaque HAL SOC handle
  896. * @hal_ring: Ring pointer (Source or Destination ring)
  897. *
  898. * Return: 0 on success; error on failire
  899. */
  900. static inline void hal_srng_access_end(void *hal_soc, void *hal_ring)
  901. {
  902. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  903. if (qdf_unlikely(!hal_ring)) {
  904. qdf_print("Error: Invalid hal_ring\n");
  905. return;
  906. }
  907. hal_srng_access_end_unlocked(hal_soc, hal_ring);
  908. SRNG_UNLOCK(&(srng->lock));
  909. }
  910. /**
  911. * hal_srng_access_end_reap - Unlock ring access
  912. * This should be used only if hal_srng_access_start to start ring access
  913. * and should be used only while reaping SRC ring completions
  914. *
  915. * @hal_soc: Opaque HAL SOC handle
  916. * @hal_ring: Ring pointer (Source or Destination ring)
  917. *
  918. * Return: 0 on success; error on failire
  919. */
  920. static inline void hal_srng_access_end_reap(void *hal_soc, void *hal_ring)
  921. {
  922. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  923. SRNG_UNLOCK(&(srng->lock));
  924. }
  925. /* TODO: Check if the following definitions is available in HW headers */
  926. #define WBM_IDLE_SCATTER_BUF_SIZE 32704
  927. #define NUM_MPDUS_PER_LINK_DESC 6
  928. #define NUM_MSDUS_PER_LINK_DESC 7
  929. #define REO_QUEUE_DESC_ALIGN 128
  930. #define LINK_DESC_ALIGN 128
  931. #define ADDRESS_MATCH_TAG_VAL 0x5
  932. /* Number of mpdu link pointers is 9 in case of TX_MPDU_QUEUE_HEAD and 14 in
  933. * of TX_MPDU_QUEUE_EXT. We are defining a common average count here
  934. */
  935. #define NUM_MPDU_LINKS_PER_QUEUE_DESC 12
  936. /* TODO: Check with HW team on the scatter buffer size supported. As per WBM
  937. * MLD, scatter_buffer_size in IDLE_LIST_CONTROL register is 9 bits and size
  938. * should be specified in 16 word units. But the number of bits defined for
  939. * this field in HW header files is 5.
  940. */
  941. #define WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE 8
  942. /**
  943. * hal_idle_list_scatter_buf_size - Get the size of each scatter buffer
  944. * in an idle list
  945. *
  946. * @hal_soc: Opaque HAL SOC handle
  947. *
  948. */
  949. static inline uint32_t hal_idle_list_scatter_buf_size(void *hal_soc)
  950. {
  951. return WBM_IDLE_SCATTER_BUF_SIZE;
  952. }
  953. /**
  954. * hal_get_link_desc_size - Get the size of each link descriptor
  955. *
  956. * @hal_soc: Opaque HAL SOC handle
  957. *
  958. */
  959. static inline uint32_t hal_get_link_desc_size(struct hal_soc *hal_soc)
  960. {
  961. if (!hal_soc || !hal_soc->ops) {
  962. qdf_print("Error: Invalid ops\n");
  963. QDF_BUG(0);
  964. return -EINVAL;
  965. }
  966. if (!hal_soc->ops->hal_get_link_desc_size) {
  967. qdf_print("Error: Invalid function pointer\n");
  968. QDF_BUG(0);
  969. return -EINVAL;
  970. }
  971. return hal_soc->ops->hal_get_link_desc_size();
  972. }
  973. /**
  974. * hal_get_link_desc_align - Get the required start address alignment for
  975. * link descriptors
  976. *
  977. * @hal_soc: Opaque HAL SOC handle
  978. *
  979. */
  980. static inline uint32_t hal_get_link_desc_align(void *hal_soc)
  981. {
  982. return LINK_DESC_ALIGN;
  983. }
  984. /**
  985. * hal_num_mpdus_per_link_desc - Get number of mpdus each link desc can hold
  986. *
  987. * @hal_soc: Opaque HAL SOC handle
  988. *
  989. */
  990. static inline uint32_t hal_num_mpdus_per_link_desc(void *hal_soc)
  991. {
  992. return NUM_MPDUS_PER_LINK_DESC;
  993. }
  994. /**
  995. * hal_num_msdus_per_link_desc - Get number of msdus each link desc can hold
  996. *
  997. * @hal_soc: Opaque HAL SOC handle
  998. *
  999. */
  1000. static inline uint32_t hal_num_msdus_per_link_desc(void *hal_soc)
  1001. {
  1002. return NUM_MSDUS_PER_LINK_DESC;
  1003. }
  1004. /**
  1005. * hal_num_mpdu_links_per_queue_desc - Get number of mpdu links each queue
  1006. * descriptor can hold
  1007. *
  1008. * @hal_soc: Opaque HAL SOC handle
  1009. *
  1010. */
  1011. static inline uint32_t hal_num_mpdu_links_per_queue_desc(void *hal_soc)
  1012. {
  1013. return NUM_MPDU_LINKS_PER_QUEUE_DESC;
  1014. }
  1015. /**
  1016. * hal_idle_list_scatter_buf_num_entries - Get the number of link desc entries
  1017. * that the given buffer size
  1018. *
  1019. * @hal_soc: Opaque HAL SOC handle
  1020. * @scatter_buf_size: Size of scatter buffer
  1021. *
  1022. */
  1023. static inline uint32_t hal_idle_scatter_buf_num_entries(void *hal_soc,
  1024. uint32_t scatter_buf_size)
  1025. {
  1026. return (scatter_buf_size - WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE) /
  1027. hal_srng_get_entrysize(hal_soc, WBM_IDLE_LINK);
  1028. }
  1029. /**
  1030. * hal_idle_list_num_scatter_bufs - Get the number of sctater buffer
  1031. * each given buffer size
  1032. *
  1033. * @hal_soc: Opaque HAL SOC handle
  1034. * @total_mem: size of memory to be scattered
  1035. * @scatter_buf_size: Size of scatter buffer
  1036. *
  1037. */
  1038. static inline uint32_t hal_idle_list_num_scatter_bufs(void *hal_soc,
  1039. uint32_t total_mem, uint32_t scatter_buf_size)
  1040. {
  1041. uint8_t rem = (total_mem % (scatter_buf_size -
  1042. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) ? 1 : 0;
  1043. uint32_t num_scatter_bufs = (total_mem / (scatter_buf_size -
  1044. WBM_IDLE_SCATTER_BUF_NEXT_PTR_SIZE)) + rem;
  1045. return num_scatter_bufs;
  1046. }
  1047. /* REO parameters to be passed to hal_reo_setup */
  1048. struct hal_reo_params {
  1049. /** rx hash steering enabled or disabled */
  1050. bool rx_hash_enabled;
  1051. /** reo remap 1 register */
  1052. uint32_t remap1;
  1053. /** reo remap 2 register */
  1054. uint32_t remap2;
  1055. /** fragment destination ring */
  1056. uint8_t frag_dst_ring;
  1057. /** padding */
  1058. uint8_t padding[3];
  1059. };
  1060. enum hal_pn_type {
  1061. HAL_PN_NONE,
  1062. HAL_PN_WPA,
  1063. HAL_PN_WAPI_EVEN,
  1064. HAL_PN_WAPI_UNEVEN,
  1065. };
  1066. #define HAL_RX_MAX_BA_WINDOW 256
  1067. /**
  1068. * hal_get_reo_qdesc_align - Get start address alignment for reo
  1069. * queue descriptors
  1070. *
  1071. * @hal_soc: Opaque HAL SOC handle
  1072. *
  1073. */
  1074. static inline uint32_t hal_get_reo_qdesc_align(void *hal_soc)
  1075. {
  1076. return REO_QUEUE_DESC_ALIGN;
  1077. }
  1078. /**
  1079. * hal_reo_qdesc_setup - Setup HW REO queue descriptor
  1080. *
  1081. * @hal_soc: Opaque HAL SOC handle
  1082. * @ba_window_size: BlockAck window size
  1083. * @start_seq: Starting sequence number
  1084. * @hw_qdesc_vaddr: Virtual address of REO queue descriptor memory
  1085. * @hw_qdesc_paddr: Physical address of REO queue descriptor memory
  1086. * @pn_type: PN type (one of the types defined in 'enum hal_pn_type')
  1087. *
  1088. */
  1089. extern void hal_reo_qdesc_setup(void *hal_soc, int tid, uint32_t ba_window_size,
  1090. uint32_t start_seq, void *hw_qdesc_vaddr, qdf_dma_addr_t hw_qdesc_paddr,
  1091. int pn_type);
  1092. /**
  1093. * hal_srng_get_hp_addr - Get head pointer physical address
  1094. *
  1095. * @hal_soc: Opaque HAL SOC handle
  1096. * @hal_ring: Ring pointer (Source or Destination ring)
  1097. *
  1098. */
  1099. static inline qdf_dma_addr_t hal_srng_get_hp_addr(void *hal_soc, void *hal_ring)
  1100. {
  1101. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1102. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1103. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1104. return hal->shadow_wrptr_mem_paddr +
  1105. ((unsigned long)(srng->u.src_ring.hp_addr) -
  1106. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1107. } else {
  1108. return hal->shadow_rdptr_mem_paddr +
  1109. ((unsigned long)(srng->u.dst_ring.hp_addr) -
  1110. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1111. }
  1112. }
  1113. /**
  1114. * hal_srng_get_tp_addr - Get tail pointer physical address
  1115. *
  1116. * @hal_soc: Opaque HAL SOC handle
  1117. * @hal_ring: Ring pointer (Source or Destination ring)
  1118. *
  1119. */
  1120. static inline qdf_dma_addr_t hal_srng_get_tp_addr(void *hal_soc, void *hal_ring)
  1121. {
  1122. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1123. struct hal_soc *hal = (struct hal_soc *)hal_soc;
  1124. if (srng->ring_dir == HAL_SRNG_SRC_RING) {
  1125. return hal->shadow_rdptr_mem_paddr +
  1126. ((unsigned long)(srng->u.src_ring.tp_addr) -
  1127. (unsigned long)(hal->shadow_rdptr_mem_vaddr));
  1128. } else {
  1129. return hal->shadow_wrptr_mem_paddr +
  1130. ((unsigned long)(srng->u.dst_ring.tp_addr) -
  1131. (unsigned long)(hal->shadow_wrptr_mem_vaddr));
  1132. }
  1133. }
  1134. /**
  1135. * hal_get_srng_params - Retrieve SRNG parameters for a given ring from HAL
  1136. *
  1137. * @hal_soc: Opaque HAL SOC handle
  1138. * @hal_ring: Ring pointer (Source or Destination ring)
  1139. * @ring_params: SRNG parameters will be returned through this structure
  1140. */
  1141. extern void hal_get_srng_params(void *hal_soc, void *hal_ring,
  1142. struct hal_srng_params *ring_params);
  1143. /**
  1144. * hal_mem_info - Retrieve hal memory base address
  1145. *
  1146. * @hal_soc: Opaque HAL SOC handle
  1147. * @mem: pointer to structure to be updated with hal mem info
  1148. */
  1149. extern void hal_get_meminfo(void *hal_soc,struct hal_mem_info *mem );
  1150. /**
  1151. * hal_get_target_type - Return target type
  1152. *
  1153. * @hal_soc: Opaque HAL SOC handle
  1154. */
  1155. uint32_t hal_get_target_type(struct hal_soc *hal);
  1156. /**
  1157. * hal_get_ba_aging_timeout - Retrieve BA aging timeout
  1158. *
  1159. * @hal_soc: Opaque HAL SOC handle
  1160. * @ac: Access category
  1161. * @value: timeout duration in millisec
  1162. */
  1163. void hal_get_ba_aging_timeout(void *hal_soc, uint8_t ac,
  1164. uint32_t *value);
  1165. /**
  1166. * hal_set_aging_timeout - Set BA aging timeout
  1167. *
  1168. * @hal_soc: Opaque HAL SOC handle
  1169. * @ac: Access category in millisec
  1170. * @value: timeout duration value
  1171. */
  1172. void hal_set_ba_aging_timeout(void *hal_soc, uint8_t ac,
  1173. uint32_t value);
  1174. /**
  1175. * hal_srng_dst_hw_init - Private function to initialize SRNG
  1176. * destination ring HW
  1177. * @hal_soc: HAL SOC handle
  1178. * @srng: SRNG ring pointer
  1179. */
  1180. static inline void hal_srng_dst_hw_init(struct hal_soc *hal,
  1181. struct hal_srng *srng)
  1182. {
  1183. hal->ops->hal_srng_dst_hw_init(hal, srng);
  1184. }
  1185. /**
  1186. * hal_srng_src_hw_init - Private function to initialize SRNG
  1187. * source ring HW
  1188. * @hal_soc: HAL SOC handle
  1189. * @srng: SRNG ring pointer
  1190. */
  1191. static inline void hal_srng_src_hw_init(struct hal_soc *hal,
  1192. struct hal_srng *srng)
  1193. {
  1194. hal->ops->hal_srng_src_hw_init(hal, srng);
  1195. }
  1196. /**
  1197. * hal_get_hw_hptp() - Get HW head and tail pointer value for any ring
  1198. * @hal_soc: Opaque HAL SOC handle
  1199. * @hal_ring: Source ring pointer
  1200. * @headp: Head Pointer
  1201. * @tailp: Tail Pointer
  1202. * @ring_type: Ring
  1203. *
  1204. * Return: Update tail pointer and head pointer in arguments.
  1205. */
  1206. static inline void hal_get_hw_hptp(struct hal_soc *hal, void *hal_ring,
  1207. uint32_t *headp, uint32_t *tailp,
  1208. uint8_t ring_type)
  1209. {
  1210. hal->ops->hal_get_hw_hptp(hal, hal_ring, headp, tailp, ring_type);
  1211. }
  1212. /**
  1213. * hal_reo_setup - Initialize HW REO block
  1214. *
  1215. * @hal_soc: Opaque HAL SOC handle
  1216. * @reo_params: parameters needed by HAL for REO config
  1217. */
  1218. static inline void hal_reo_setup(void *halsoc,
  1219. void *reoparams)
  1220. {
  1221. struct hal_soc *hal_soc = (struct hal_soc *)halsoc;
  1222. hal_soc->ops->hal_reo_setup(halsoc, reoparams);
  1223. }
  1224. /**
  1225. * hal_setup_link_idle_list - Setup scattered idle list using the
  1226. * buffer list provided
  1227. *
  1228. * @hal_soc: Opaque HAL SOC handle
  1229. * @scatter_bufs_base_paddr: Array of physical base addresses
  1230. * @scatter_bufs_base_vaddr: Array of virtual base addresses
  1231. * @num_scatter_bufs: Number of scatter buffers in the above lists
  1232. * @scatter_buf_size: Size of each scatter buffer
  1233. * @last_buf_end_offset: Offset to the last entry
  1234. * @num_entries: Total entries of all scatter bufs
  1235. *
  1236. */
  1237. static inline void hal_setup_link_idle_list(void *halsoc,
  1238. qdf_dma_addr_t scatter_bufs_base_paddr[],
  1239. void *scatter_bufs_base_vaddr[], uint32_t num_scatter_bufs,
  1240. uint32_t scatter_buf_size, uint32_t last_buf_end_offset,
  1241. uint32_t num_entries)
  1242. {
  1243. struct hal_soc *hal_soc = (struct hal_soc *)halsoc;
  1244. hal_soc->ops->hal_setup_link_idle_list(halsoc, scatter_bufs_base_paddr,
  1245. scatter_bufs_base_vaddr, num_scatter_bufs,
  1246. scatter_buf_size, last_buf_end_offset,
  1247. num_entries);
  1248. }
  1249. /**
  1250. * hal_srng_dump_ring_desc() - Dump ring descriptor info
  1251. *
  1252. * @hal_soc: Opaque HAL SOC handle
  1253. * @hal_ring: Source ring pointer
  1254. * @ring_desc: Opaque ring descriptor handle
  1255. */
  1256. static inline void hal_srng_dump_ring_desc(struct hal_soc *hal, void *hal_ring,
  1257. void *ring_desc)
  1258. {
  1259. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1260. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,
  1261. ring_desc, (srng->entry_size << 2));
  1262. }
  1263. /**
  1264. * hal_srng_dump_ring() - Dump last 128 descs of the ring
  1265. *
  1266. * @hal_soc: Opaque HAL SOC handle
  1267. * @hal_ring: Source ring pointer
  1268. */
  1269. static inline void hal_srng_dump_ring(struct hal_soc *hal, void *hal_ring)
  1270. {
  1271. struct hal_srng *srng = (struct hal_srng *)hal_ring;
  1272. uint32_t *desc;
  1273. uint32_t tp, i;
  1274. tp = srng->u.dst_ring.tp;
  1275. for (i = 0; i < 128; i++) {
  1276. if (!tp)
  1277. tp = srng->ring_size;
  1278. desc = &srng->ring_base_vaddr[tp - srng->entry_size];
  1279. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  1280. QDF_TRACE_LEVEL_DEBUG,
  1281. desc, (srng->entry_size << 2));
  1282. tp -= srng->entry_size;
  1283. }
  1284. }
  1285. #endif /* _HAL_APIH_ */