hal_api.h 41 KB

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