hal_api.h 32 KB

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