hal_api.h 39 KB

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