hal_api.h 44 KB

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