hal_api.h 41 KB

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