dp_tx_desc.h 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for
  6. * any purpose with or without fee is hereby granted, provided that the
  7. * above copyright notice and this permission notice appear in all
  8. * copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  11. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  12. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  13. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  14. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  15. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  16. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  17. * PERFORMANCE OF THIS SOFTWARE.
  18. */
  19. #ifndef DP_TX_DESC_H
  20. #define DP_TX_DESC_H
  21. #include "dp_types.h"
  22. #include "dp_tx.h"
  23. #include "dp_internal.h"
  24. /*
  25. * 21 bits cookie
  26. * 2 bits pool id 0 ~ 3,
  27. * 10 bits page id 0 ~ 1023
  28. * 5 bits offset id 0 ~ 31 (Desc size = 128, Num descs per page = 4096/128 = 32)
  29. */
  30. /* ???Ring ID needed??? */
  31. /* TODO: Need to revisit this change for Rhine */
  32. #ifdef WLAN_SOFTUMAC_SUPPORT
  33. #define DP_TX_DESC_ID_POOL_MASK 0x018000
  34. #define DP_TX_DESC_ID_POOL_OS 15
  35. #define DP_TX_DESC_ID_PAGE_MASK 0x007FF0
  36. #define DP_TX_DESC_ID_PAGE_OS 4
  37. #define DP_TX_DESC_ID_OFFSET_MASK 0x00000F
  38. #define DP_TX_DESC_ID_OFFSET_OS 0
  39. #else
  40. #define DP_TX_DESC_ID_POOL_MASK 0x018000
  41. #define DP_TX_DESC_ID_POOL_OS 15
  42. #define DP_TX_DESC_ID_PAGE_MASK 0x007FE0
  43. #define DP_TX_DESC_ID_PAGE_OS 5
  44. #define DP_TX_DESC_ID_OFFSET_MASK 0x00001F
  45. #define DP_TX_DESC_ID_OFFSET_OS 0
  46. #endif /* WLAN_SOFTUMAC_SUPPORT */
  47. /*
  48. * Compilation assert on tx desc size
  49. *
  50. * if assert is hit please update POOL_MASK,
  51. * PAGE_MASK according to updated size
  52. *
  53. * for current PAGE mask allowed size range of tx_desc
  54. * is between 128 and 256
  55. */
  56. QDF_COMPILE_TIME_ASSERT(dp_tx_desc_size,
  57. ((sizeof(struct dp_tx_desc_s)) <=
  58. (DP_BLOCKMEM_SIZE >> DP_TX_DESC_ID_PAGE_OS)) &&
  59. ((sizeof(struct dp_tx_desc_s)) >
  60. (DP_BLOCKMEM_SIZE >> (DP_TX_DESC_ID_PAGE_OS + 1)))
  61. );
  62. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  63. #define TX_DESC_LOCK_CREATE(lock)
  64. #define TX_DESC_LOCK_DESTROY(lock)
  65. #define TX_DESC_LOCK_LOCK(lock)
  66. #define TX_DESC_LOCK_UNLOCK(lock)
  67. #define IS_TX_DESC_POOL_STATUS_INACTIVE(pool) \
  68. ((pool)->status == FLOW_POOL_INACTIVE)
  69. #ifdef QCA_AC_BASED_FLOW_CONTROL
  70. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  71. dp_tx_flow_pool_member_clean(_tx_desc_pool)
  72. #else /* !QCA_AC_BASED_FLOW_CONTROL */
  73. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  74. do { \
  75. (_tx_desc_pool)->elem_size = 0; \
  76. (_tx_desc_pool)->freelist = NULL; \
  77. (_tx_desc_pool)->pool_size = 0; \
  78. (_tx_desc_pool)->avail_desc = 0; \
  79. (_tx_desc_pool)->start_th = 0; \
  80. (_tx_desc_pool)->stop_th = 0; \
  81. (_tx_desc_pool)->status = FLOW_POOL_INACTIVE; \
  82. } while (0)
  83. #endif /* QCA_AC_BASED_FLOW_CONTROL */
  84. #else /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  85. #define TX_DESC_LOCK_CREATE(lock) qdf_spinlock_create(lock)
  86. #define TX_DESC_LOCK_DESTROY(lock) qdf_spinlock_destroy(lock)
  87. #define TX_DESC_LOCK_LOCK(lock) qdf_spin_lock_bh(lock)
  88. #define TX_DESC_LOCK_UNLOCK(lock) qdf_spin_unlock_bh(lock)
  89. #define IS_TX_DESC_POOL_STATUS_INACTIVE(pool) (false)
  90. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  91. do { \
  92. (_tx_desc_pool)->elem_size = 0; \
  93. (_tx_desc_pool)->num_allocated = 0; \
  94. (_tx_desc_pool)->freelist = NULL; \
  95. (_tx_desc_pool)->elem_count = 0; \
  96. (_tx_desc_pool)->num_free = 0; \
  97. } while (0)
  98. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  99. #define MAX_POOL_BUFF_COUNT 10000
  100. #ifdef DP_TX_TRACKING
  101. static inline void dp_tx_desc_set_magic(struct dp_tx_desc_s *tx_desc,
  102. uint32_t magic_pattern)
  103. {
  104. tx_desc->magic = magic_pattern;
  105. }
  106. #else
  107. static inline void dp_tx_desc_set_magic(struct dp_tx_desc_s *tx_desc,
  108. uint32_t magic_pattern)
  109. {
  110. }
  111. #endif
  112. /**
  113. * dp_tx_desc_pool_alloc() - Allocate Tx Descriptor pool(s)
  114. * @soc: Handle to DP SoC structure
  115. * @pool_id: pool to allocate
  116. * @num_elem: Number of descriptor elements per pool
  117. *
  118. * This function allocates memory for SW tx descriptors
  119. * (used within host for tx data path).
  120. * The number of tx descriptors required will be large
  121. * since based on number of clients (1024 clients x 3 radios),
  122. * outstanding MSDUs stored in TQM queues and LMAC queues will be significantly
  123. * large.
  124. *
  125. * To avoid allocating a large contiguous memory, it uses multi_page_alloc qdf
  126. * function to allocate memory
  127. * in multiple pages. It then iterates through the memory allocated across pages
  128. * and links each descriptor
  129. * to next descriptor, taking care of page boundaries.
  130. *
  131. * Since WiFi 3.0 HW supports multiple Tx rings, multiple pools are allocated,
  132. * one for each ring;
  133. * This minimizes lock contention when hard_start_xmit is called
  134. * from multiple CPUs.
  135. * Alternately, multiple pools can be used for multiple VDEVs for VDEV level
  136. * flow control.
  137. *
  138. * Return: Status code. 0 for success.
  139. */
  140. QDF_STATUS dp_tx_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  141. uint32_t num_elem);
  142. /**
  143. * dp_tx_desc_pool_init() - Initialize Tx Descriptor pool(s)
  144. * @soc: Handle to DP SoC structure
  145. * @pool_id: pool to allocate
  146. * @num_elem: Number of descriptor elements per pool
  147. *
  148. * Return: QDF_STATUS_SUCCESS
  149. * QDF_STATUS_E_FAULT
  150. */
  151. QDF_STATUS dp_tx_desc_pool_init(struct dp_soc *soc, uint8_t pool_id,
  152. uint32_t num_elem);
  153. /**
  154. * dp_tx_desc_pool_free() - Free the tx dexcriptor pools
  155. * @soc: Handle to DP SoC structure
  156. * @pool_id: pool to free
  157. *
  158. */
  159. void dp_tx_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  160. /**
  161. * dp_tx_desc_pool_deinit() - de-initialize Tx Descriptor pool(s)
  162. * @soc: Handle to DP SoC structure
  163. * @pool_id: pool to de-initialize
  164. *
  165. */
  166. void dp_tx_desc_pool_deinit(struct dp_soc *soc, uint8_t pool_id);
  167. /**
  168. * dp_tx_ext_desc_pool_alloc_by_id() - allocate TX extension Descriptor pool
  169. * based on pool ID
  170. * @soc: Handle to DP SoC structure
  171. * @num_elem: Number of descriptor elements per pool
  172. * @pool_id: Pool ID
  173. *
  174. * Return - QDF_STATUS_SUCCESS
  175. * QDF_STATUS_E_NOMEM
  176. */
  177. QDF_STATUS dp_tx_ext_desc_pool_alloc_by_id(struct dp_soc *soc,
  178. uint32_t num_elem,
  179. uint8_t pool_id);
  180. /**
  181. * dp_tx_ext_desc_pool_alloc() - allocate Tx extension Descriptor pool(s)
  182. * @soc: Handle to DP SoC structure
  183. * @num_pool: Number of pools to allocate
  184. * @num_elem: Number of descriptor elements per pool
  185. *
  186. * Return: QDF_STATUS_SUCCESS
  187. * QDF_STATUS_E_NOMEM
  188. */
  189. QDF_STATUS dp_tx_ext_desc_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  190. uint32_t num_elem);
  191. /**
  192. * dp_tx_ext_desc_pool_init_by_id() - initialize Tx extension Descriptor pool
  193. * based on pool ID
  194. * @soc: Handle to DP SoC structure
  195. * @num_elem: Number of descriptor elements per pool
  196. * @pool_id: Pool ID
  197. *
  198. * Return - QDF_STATUS_SUCCESS
  199. * QDF_STATUS_E_FAULT
  200. */
  201. QDF_STATUS dp_tx_ext_desc_pool_init_by_id(struct dp_soc *soc, uint32_t num_elem,
  202. uint8_t pool_id);
  203. /**
  204. * dp_tx_ext_desc_pool_init() - initialize Tx extension Descriptor pool(s)
  205. * @soc: Handle to DP SoC structure
  206. * @num_pool: Number of pools to initialize
  207. * @num_elem: Number of descriptor elements per pool
  208. *
  209. * Return: QDF_STATUS_SUCCESS
  210. * QDF_STATUS_E_NOMEM
  211. */
  212. QDF_STATUS dp_tx_ext_desc_pool_init(struct dp_soc *soc, uint8_t num_pool,
  213. uint32_t num_elem);
  214. /**
  215. * dp_tx_ext_desc_pool_free_by_id() - free TX extension Descriptor pool
  216. * based on pool ID
  217. * @soc: Handle to DP SoC structure
  218. * @pool_id: Pool ID
  219. *
  220. */
  221. void dp_tx_ext_desc_pool_free_by_id(struct dp_soc *soc, uint8_t pool_id);
  222. /**
  223. * dp_tx_ext_desc_pool_free() - free Tx extension Descriptor pool(s)
  224. * @soc: Handle to DP SoC structure
  225. * @num_pool: Number of pools to free
  226. *
  227. */
  228. void dp_tx_ext_desc_pool_free(struct dp_soc *soc, uint8_t num_pool);
  229. /**
  230. * dp_tx_ext_desc_pool_deinit_by_id() - deinit Tx extension Descriptor pool
  231. * based on pool ID
  232. * @soc: Handle to DP SoC structure
  233. * @pool_id: Pool ID
  234. *
  235. */
  236. void dp_tx_ext_desc_pool_deinit_by_id(struct dp_soc *soc, uint8_t pool_id);
  237. /**
  238. * dp_tx_ext_desc_pool_deinit() - deinit Tx extension Descriptor pool(s)
  239. * @soc: Handle to DP SoC structure
  240. * @num_pool: Number of pools to de-initialize
  241. *
  242. */
  243. void dp_tx_ext_desc_pool_deinit(struct dp_soc *soc, uint8_t num_pool);
  244. /**
  245. * dp_tx_tso_desc_pool_alloc_by_id() - allocate TSO Descriptor pool based
  246. * on pool ID
  247. * @soc: Handle to DP SoC structure
  248. * @num_elem: Number of descriptor elements per pool
  249. * @pool_id: Pool ID
  250. *
  251. * Return - QDF_STATUS_SUCCESS
  252. * QDF_STATUS_E_NOMEM
  253. */
  254. QDF_STATUS dp_tx_tso_desc_pool_alloc_by_id(struct dp_soc *soc, uint32_t num_elem,
  255. uint8_t pool_id);
  256. /**
  257. * dp_tx_tso_desc_pool_alloc() - allocate TSO Descriptor pool(s)
  258. * @soc: Handle to DP SoC structure
  259. * @num_pool: Number of pools to allocate
  260. * @num_elem: Number of descriptor elements per pool
  261. *
  262. * Return: QDF_STATUS_SUCCESS
  263. * QDF_STATUS_E_NOMEM
  264. */
  265. QDF_STATUS dp_tx_tso_desc_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  266. uint32_t num_elem);
  267. /**
  268. * dp_tx_tso_desc_pool_init_by_id() - initialize TSO Descriptor pool
  269. * based on pool ID
  270. * @soc: Handle to DP SoC structure
  271. * @num_elem: Number of descriptor elements per pool
  272. * @pool_id: Pool ID
  273. *
  274. * Return - QDF_STATUS_SUCCESS
  275. * QDF_STATUS_E_NOMEM
  276. */
  277. QDF_STATUS dp_tx_tso_desc_pool_init_by_id(struct dp_soc *soc, uint32_t num_elem,
  278. uint8_t pool_id);
  279. /**
  280. * dp_tx_tso_desc_pool_init() - initialize TSO Descriptor pool(s)
  281. * @soc: Handle to DP SoC structure
  282. * @num_pool: Number of pools to initialize
  283. * @num_elem: Number of descriptor elements per pool
  284. *
  285. * Return: QDF_STATUS_SUCCESS
  286. * QDF_STATUS_E_NOMEM
  287. */
  288. QDF_STATUS dp_tx_tso_desc_pool_init(struct dp_soc *soc, uint8_t num_pool,
  289. uint32_t num_elem);
  290. /**
  291. * dp_tx_tso_desc_pool_free_by_id() - free TSO Descriptor pool based on pool ID
  292. * @soc: Handle to DP SoC structure
  293. * @pool_id: Pool ID
  294. */
  295. void dp_tx_tso_desc_pool_free_by_id(struct dp_soc *soc, uint8_t pool_id);
  296. /**
  297. * dp_tx_tso_desc_pool_free() - free TSO Descriptor pool(s)
  298. * @soc: Handle to DP SoC structure
  299. * @num_pool: Number of pools to free
  300. *
  301. */
  302. void dp_tx_tso_desc_pool_free(struct dp_soc *soc, uint8_t num_pool);
  303. /**
  304. * dp_tx_tso_desc_pool_deinit_by_id() - deinitialize TSO Descriptor pool
  305. * based on pool ID
  306. * @soc: Handle to DP SoC structure
  307. * @pool_id: Pool ID
  308. */
  309. void dp_tx_tso_desc_pool_deinit_by_id(struct dp_soc *soc, uint8_t pool_id);
  310. /**
  311. * dp_tx_tso_desc_pool_deinit() - deinitialize TSO Descriptor pool(s)
  312. * @soc: Handle to DP SoC structure
  313. * @num_pool: Number of pools to free
  314. *
  315. */
  316. void dp_tx_tso_desc_pool_deinit(struct dp_soc *soc, uint8_t num_pool);
  317. /**
  318. * dp_tx_tso_num_seg_pool_alloc_by_id() - Allocate descriptors that tracks the
  319. * fragments in each tso segment based on pool ID
  320. * @soc: handle to dp soc structure
  321. * @num_elem: total number of descriptors to be allocated
  322. * @pool_id: Pool ID
  323. *
  324. * Return - QDF_STATUS_SUCCESS
  325. * QDF_STATUS_E_NOMEM
  326. */
  327. QDF_STATUS dp_tx_tso_num_seg_pool_alloc_by_id(struct dp_soc *soc,
  328. uint32_t num_elem,
  329. uint8_t pool_id);
  330. /**
  331. * dp_tx_tso_num_seg_pool_alloc() - Allocate descriptors that tracks the
  332. * fragments in each tso segment
  333. *
  334. * @soc: handle to dp soc structure
  335. * @num_pool: number of pools to allocate
  336. * @num_elem: total number of descriptors to be allocated
  337. *
  338. * Return: QDF_STATUS_SUCCESS
  339. * QDF_STATUS_E_NOMEM
  340. */
  341. QDF_STATUS dp_tx_tso_num_seg_pool_alloc(struct dp_soc *soc, uint8_t num_pool,
  342. uint32_t num_elem);
  343. /**
  344. * dp_tx_tso_num_seg_pool_init_by_id() - Initialize descriptors that tracks the
  345. * fragments in each tso segment based on pool ID
  346. *
  347. * @soc: handle to dp soc structure
  348. * @num_elem: total number of descriptors to be initialized
  349. * @pool_id: Pool ID
  350. *
  351. * Return - QDF_STATUS_SUCCESS
  352. * QDF_STATUS_E_FAULT
  353. */
  354. QDF_STATUS dp_tx_tso_num_seg_pool_init_by_id(struct dp_soc *soc,
  355. uint32_t num_elem,
  356. uint8_t pool_id);
  357. /**
  358. * dp_tx_tso_num_seg_pool_init() - Initialize descriptors that tracks the
  359. * fragments in each tso segment
  360. *
  361. * @soc: handle to dp soc structure
  362. * @num_pool: number of pools to initialize
  363. * @num_elem: total number of descriptors to be initialized
  364. *
  365. * Return: QDF_STATUS_SUCCESS
  366. * QDF_STATUS_E_FAULT
  367. */
  368. QDF_STATUS dp_tx_tso_num_seg_pool_init(struct dp_soc *soc, uint8_t num_pool,
  369. uint32_t num_elem);
  370. /**
  371. * dp_tx_tso_num_seg_pool_free_by_id() - free descriptors that tracks the
  372. * fragments in each tso segment based on pool ID
  373. *
  374. * @soc: handle to dp soc structure
  375. * @pool_id: Pool ID
  376. */
  377. void dp_tx_tso_num_seg_pool_free_by_id(struct dp_soc *soc, uint8_t pool_id);
  378. /**
  379. * dp_tx_tso_num_seg_pool_free() - free descriptors that tracks the
  380. * fragments in each tso segment
  381. *
  382. * @soc: handle to dp soc structure
  383. * @num_pool: number of pools to free
  384. */
  385. void dp_tx_tso_num_seg_pool_free(struct dp_soc *soc, uint8_t num_pool);
  386. /**
  387. * dp_tx_tso_num_seg_pool_deinit_by_id() - de-initialize descriptors that tracks
  388. * the fragments in each tso segment based on pool ID
  389. * @soc: handle to dp soc structure
  390. * @pool_id: Pool ID
  391. */
  392. void dp_tx_tso_num_seg_pool_deinit_by_id(struct dp_soc *soc, uint8_t pool_id);
  393. /**
  394. * dp_tx_tso_num_seg_pool_deinit() - de-initialize descriptors that tracks the
  395. * fragments in each tso segment
  396. *
  397. * @soc: handle to dp soc structure
  398. * @num_pool: number of pools to de-initialize
  399. *
  400. * Return: QDF_STATUS_SUCCESS
  401. * QDF_STATUS_E_FAULT
  402. */
  403. void dp_tx_tso_num_seg_pool_deinit(struct dp_soc *soc, uint8_t num_pool);
  404. #ifdef DP_UMAC_HW_RESET_SUPPORT
  405. /**
  406. * dp_tx_desc_pool_cleanup() - Clean up the tx dexcriptor pools
  407. * @soc: Handle to DP SoC structure
  408. * @nbuf_list: nbuf list for delayed free
  409. *
  410. */
  411. void dp_tx_desc_pool_cleanup(struct dp_soc *soc, qdf_nbuf_t *nbuf_list);
  412. #endif
  413. /**
  414. * dp_tx_desc_clear() - Clear contents of tx desc
  415. * @tx_desc: descriptor to free
  416. *
  417. * Return: none
  418. */
  419. static inline void
  420. dp_tx_desc_clear(struct dp_tx_desc_s *tx_desc)
  421. {
  422. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  423. tx_desc->nbuf = NULL;
  424. tx_desc->flags = 0;
  425. tx_desc->next = NULL;
  426. }
  427. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  428. void dp_tx_flow_control_init(struct dp_soc *);
  429. void dp_tx_flow_control_deinit(struct dp_soc *);
  430. QDF_STATUS dp_txrx_register_pause_cb(struct cdp_soc_t *soc,
  431. tx_pause_callback pause_cb);
  432. QDF_STATUS dp_tx_flow_pool_map(struct cdp_soc_t *soc, uint8_t pdev_id,
  433. uint8_t vdev_id);
  434. void dp_tx_flow_pool_unmap(struct cdp_soc_t *handle, uint8_t pdev_id,
  435. uint8_t vdev_id);
  436. void dp_tx_clear_flow_pool_stats(struct dp_soc *soc);
  437. struct dp_tx_desc_pool_s *dp_tx_create_flow_pool(struct dp_soc *soc,
  438. uint8_t flow_pool_id, uint32_t flow_pool_size);
  439. QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev, uint8_t flow_id,
  440. uint8_t flow_type, uint8_t flow_pool_id, uint32_t flow_pool_size);
  441. void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev, uint8_t flow_id,
  442. uint8_t flow_type, uint8_t flow_pool_id);
  443. /**
  444. * dp_tx_get_desc_flow_pool() - get descriptor from flow pool
  445. * @pool: flow pool
  446. *
  447. * Caller needs to take lock and do sanity checks.
  448. *
  449. * Return: tx descriptor
  450. */
  451. static inline
  452. struct dp_tx_desc_s *dp_tx_get_desc_flow_pool(struct dp_tx_desc_pool_s *pool)
  453. {
  454. struct dp_tx_desc_s *tx_desc = pool->freelist;
  455. pool->freelist = pool->freelist->next;
  456. pool->avail_desc--;
  457. return tx_desc;
  458. }
  459. /**
  460. * dp_tx_put_desc_flow_pool() - put descriptor to flow pool freelist
  461. * @pool: flow pool
  462. * @tx_desc: tx descriptor
  463. *
  464. * Caller needs to take lock and do sanity checks.
  465. *
  466. * Return: none
  467. */
  468. static inline
  469. void dp_tx_put_desc_flow_pool(struct dp_tx_desc_pool_s *pool,
  470. struct dp_tx_desc_s *tx_desc)
  471. {
  472. tx_desc->next = pool->freelist;
  473. pool->freelist = tx_desc;
  474. pool->avail_desc++;
  475. }
  476. static inline void
  477. dp_tx_desc_free_list(struct dp_tx_desc_pool_s *pool,
  478. struct dp_tx_desc_s *head_desc,
  479. struct dp_tx_desc_s *tail_desc,
  480. uint32_t fast_desc_count)
  481. {
  482. }
  483. #ifdef QCA_AC_BASED_FLOW_CONTROL
  484. /**
  485. * dp_tx_flow_pool_member_clean() - Clean the members of TX flow pool
  486. * @pool: flow pool
  487. *
  488. * Return: None
  489. */
  490. static inline void
  491. dp_tx_flow_pool_member_clean(struct dp_tx_desc_pool_s *pool)
  492. {
  493. pool->elem_size = 0;
  494. pool->freelist = NULL;
  495. pool->pool_size = 0;
  496. pool->avail_desc = 0;
  497. qdf_mem_zero(pool->start_th, FL_TH_MAX);
  498. qdf_mem_zero(pool->stop_th, FL_TH_MAX);
  499. pool->status = FLOW_POOL_INACTIVE;
  500. }
  501. /**
  502. * dp_tx_is_threshold_reached() - Check if current avail desc meet threshold
  503. * @pool: flow pool
  504. * @avail_desc: available descriptor number
  505. *
  506. * Return: true if threshold is met, false if not
  507. */
  508. static inline bool
  509. dp_tx_is_threshold_reached(struct dp_tx_desc_pool_s *pool, uint16_t avail_desc)
  510. {
  511. if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_BE_BK]))
  512. return true;
  513. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_VI]))
  514. return true;
  515. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_VO]))
  516. return true;
  517. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_HI]))
  518. return true;
  519. else
  520. return false;
  521. }
  522. /**
  523. * dp_tx_adjust_flow_pool_state() - Adjust flow pool state
  524. * @soc: dp soc
  525. * @pool: flow pool
  526. */
  527. static inline void
  528. dp_tx_adjust_flow_pool_state(struct dp_soc *soc,
  529. struct dp_tx_desc_pool_s *pool)
  530. {
  531. if (pool->avail_desc > pool->stop_th[DP_TH_BE_BK]) {
  532. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  533. return;
  534. } else if (pool->avail_desc <= pool->stop_th[DP_TH_BE_BK] &&
  535. pool->avail_desc > pool->stop_th[DP_TH_VI]) {
  536. pool->status = FLOW_POOL_BE_BK_PAUSED;
  537. } else if (pool->avail_desc <= pool->stop_th[DP_TH_VI] &&
  538. pool->avail_desc > pool->stop_th[DP_TH_VO]) {
  539. pool->status = FLOW_POOL_VI_PAUSED;
  540. } else if (pool->avail_desc <= pool->stop_th[DP_TH_VO] &&
  541. pool->avail_desc > pool->stop_th[DP_TH_HI]) {
  542. pool->status = FLOW_POOL_VO_PAUSED;
  543. } else if (pool->avail_desc <= pool->stop_th[DP_TH_HI]) {
  544. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  545. }
  546. switch (pool->status) {
  547. case FLOW_POOL_ACTIVE_PAUSED:
  548. soc->pause_cb(pool->flow_pool_id,
  549. WLAN_NETIF_PRIORITY_QUEUE_OFF,
  550. WLAN_DATA_FLOW_CTRL_PRI);
  551. fallthrough;
  552. case FLOW_POOL_VO_PAUSED:
  553. soc->pause_cb(pool->flow_pool_id,
  554. WLAN_NETIF_VO_QUEUE_OFF,
  555. WLAN_DATA_FLOW_CTRL_VO);
  556. fallthrough;
  557. case FLOW_POOL_VI_PAUSED:
  558. soc->pause_cb(pool->flow_pool_id,
  559. WLAN_NETIF_VI_QUEUE_OFF,
  560. WLAN_DATA_FLOW_CTRL_VI);
  561. fallthrough;
  562. case FLOW_POOL_BE_BK_PAUSED:
  563. soc->pause_cb(pool->flow_pool_id,
  564. WLAN_NETIF_BE_BK_QUEUE_OFF,
  565. WLAN_DATA_FLOW_CTRL_BE_BK);
  566. break;
  567. default:
  568. dp_err("Invalid pool status:%u to adjust", pool->status);
  569. }
  570. }
  571. /**
  572. * dp_tx_desc_alloc() - Allocate a Software Tx descriptor from given pool
  573. * @soc: Handle to DP SoC structure
  574. * @desc_pool_id: ID of the flow control fool
  575. *
  576. * Return: TX descriptor allocated or NULL
  577. */
  578. static inline struct dp_tx_desc_s *
  579. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  580. {
  581. struct dp_tx_desc_s *tx_desc = NULL;
  582. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  583. bool is_pause = false;
  584. enum netif_action_type act = WLAN_NETIF_ACTION_TYPE_NONE;
  585. enum dp_fl_ctrl_threshold level = DP_TH_BE_BK;
  586. enum netif_reason_type reason;
  587. if (qdf_likely(pool)) {
  588. qdf_spin_lock_bh(&pool->flow_pool_lock);
  589. if (qdf_likely(pool->avail_desc &&
  590. pool->status != FLOW_POOL_INVALID &&
  591. pool->status != FLOW_POOL_INACTIVE)) {
  592. tx_desc = dp_tx_get_desc_flow_pool(pool);
  593. tx_desc->pool_id = desc_pool_id;
  594. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  595. dp_tx_desc_set_magic(tx_desc,
  596. DP_TX_MAGIC_PATTERN_INUSE);
  597. is_pause = dp_tx_is_threshold_reached(pool,
  598. pool->avail_desc);
  599. if (qdf_unlikely(pool->status ==
  600. FLOW_POOL_ACTIVE_UNPAUSED_REATTACH)) {
  601. dp_tx_adjust_flow_pool_state(soc, pool);
  602. is_pause = false;
  603. }
  604. if (qdf_unlikely(is_pause)) {
  605. switch (pool->status) {
  606. case FLOW_POOL_ACTIVE_UNPAUSED:
  607. /* pause network BE\BK queue */
  608. act = WLAN_NETIF_BE_BK_QUEUE_OFF;
  609. reason = WLAN_DATA_FLOW_CTRL_BE_BK;
  610. level = DP_TH_BE_BK;
  611. pool->status = FLOW_POOL_BE_BK_PAUSED;
  612. break;
  613. case FLOW_POOL_BE_BK_PAUSED:
  614. /* pause network VI queue */
  615. act = WLAN_NETIF_VI_QUEUE_OFF;
  616. reason = WLAN_DATA_FLOW_CTRL_VI;
  617. level = DP_TH_VI;
  618. pool->status = FLOW_POOL_VI_PAUSED;
  619. break;
  620. case FLOW_POOL_VI_PAUSED:
  621. /* pause network VO queue */
  622. act = WLAN_NETIF_VO_QUEUE_OFF;
  623. reason = WLAN_DATA_FLOW_CTRL_VO;
  624. level = DP_TH_VO;
  625. pool->status = FLOW_POOL_VO_PAUSED;
  626. break;
  627. case FLOW_POOL_VO_PAUSED:
  628. /* pause network HI PRI queue */
  629. act = WLAN_NETIF_PRIORITY_QUEUE_OFF;
  630. reason = WLAN_DATA_FLOW_CTRL_PRI;
  631. level = DP_TH_HI;
  632. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  633. break;
  634. case FLOW_POOL_ACTIVE_PAUSED:
  635. act = WLAN_NETIF_ACTION_TYPE_NONE;
  636. break;
  637. default:
  638. dp_err_rl("pool status is %d!",
  639. pool->status);
  640. break;
  641. }
  642. if (act != WLAN_NETIF_ACTION_TYPE_NONE) {
  643. pool->latest_pause_time[level] =
  644. qdf_get_system_timestamp();
  645. soc->pause_cb(desc_pool_id,
  646. act,
  647. reason);
  648. }
  649. }
  650. } else {
  651. pool->pkt_drop_no_desc++;
  652. }
  653. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  654. } else {
  655. dp_err_rl("NULL desc pool pool_id %d", desc_pool_id);
  656. soc->pool_stats.pkt_drop_no_pool++;
  657. }
  658. return tx_desc;
  659. }
  660. /**
  661. * dp_tx_desc_free() - Free a tx descriptor and attach it to free list
  662. * @soc: Handle to DP SoC structure
  663. * @tx_desc: the tx descriptor to be freed
  664. * @desc_pool_id: ID of the flow control pool
  665. *
  666. * Return: None
  667. */
  668. static inline void
  669. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  670. uint8_t desc_pool_id)
  671. {
  672. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  673. qdf_time_t unpause_time = qdf_get_system_timestamp(), pause_dur;
  674. enum netif_action_type act = WLAN_WAKE_ALL_NETIF_QUEUE;
  675. enum netif_reason_type reason;
  676. qdf_spin_lock_bh(&pool->flow_pool_lock);
  677. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  678. tx_desc->nbuf = NULL;
  679. tx_desc->flags = 0;
  680. dp_tx_desc_set_magic(tx_desc, DP_TX_MAGIC_PATTERN_FREE);
  681. dp_tx_put_desc_flow_pool(pool, tx_desc);
  682. switch (pool->status) {
  683. case FLOW_POOL_ACTIVE_PAUSED:
  684. if (pool->avail_desc > pool->start_th[DP_TH_HI]) {
  685. act = WLAN_NETIF_PRIORITY_QUEUE_ON;
  686. reason = WLAN_DATA_FLOW_CTRL_PRI;
  687. pool->status = FLOW_POOL_VO_PAUSED;
  688. /* Update maximum pause duration for HI queue */
  689. pause_dur = unpause_time -
  690. pool->latest_pause_time[DP_TH_HI];
  691. if (pool->max_pause_time[DP_TH_HI] < pause_dur)
  692. pool->max_pause_time[DP_TH_HI] = pause_dur;
  693. }
  694. break;
  695. case FLOW_POOL_VO_PAUSED:
  696. if (pool->avail_desc > pool->start_th[DP_TH_VO]) {
  697. act = WLAN_NETIF_VO_QUEUE_ON;
  698. reason = WLAN_DATA_FLOW_CTRL_VO;
  699. pool->status = FLOW_POOL_VI_PAUSED;
  700. /* Update maximum pause duration for VO queue */
  701. pause_dur = unpause_time -
  702. pool->latest_pause_time[DP_TH_VO];
  703. if (pool->max_pause_time[DP_TH_VO] < pause_dur)
  704. pool->max_pause_time[DP_TH_VO] = pause_dur;
  705. }
  706. break;
  707. case FLOW_POOL_VI_PAUSED:
  708. if (pool->avail_desc > pool->start_th[DP_TH_VI]) {
  709. act = WLAN_NETIF_VI_QUEUE_ON;
  710. reason = WLAN_DATA_FLOW_CTRL_VI;
  711. pool->status = FLOW_POOL_BE_BK_PAUSED;
  712. /* Update maximum pause duration for VI queue */
  713. pause_dur = unpause_time -
  714. pool->latest_pause_time[DP_TH_VI];
  715. if (pool->max_pause_time[DP_TH_VI] < pause_dur)
  716. pool->max_pause_time[DP_TH_VI] = pause_dur;
  717. }
  718. break;
  719. case FLOW_POOL_BE_BK_PAUSED:
  720. if (pool->avail_desc > pool->start_th[DP_TH_BE_BK]) {
  721. act = WLAN_NETIF_BE_BK_QUEUE_ON;
  722. reason = WLAN_DATA_FLOW_CTRL_BE_BK;
  723. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  724. /* Update maximum pause duration for BE_BK queue */
  725. pause_dur = unpause_time -
  726. pool->latest_pause_time[DP_TH_BE_BK];
  727. if (pool->max_pause_time[DP_TH_BE_BK] < pause_dur)
  728. pool->max_pause_time[DP_TH_BE_BK] = pause_dur;
  729. }
  730. break;
  731. case FLOW_POOL_INVALID:
  732. if (pool->avail_desc == pool->pool_size) {
  733. dp_tx_desc_pool_deinit(soc, desc_pool_id);
  734. dp_tx_desc_pool_free(soc, desc_pool_id);
  735. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  736. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  737. "%s %d pool is freed!!",
  738. __func__, __LINE__);
  739. return;
  740. }
  741. break;
  742. case FLOW_POOL_ACTIVE_UNPAUSED:
  743. break;
  744. default:
  745. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  746. "%s %d pool is INACTIVE State!!",
  747. __func__, __LINE__);
  748. break;
  749. };
  750. if (act != WLAN_WAKE_ALL_NETIF_QUEUE)
  751. soc->pause_cb(pool->flow_pool_id,
  752. act, reason);
  753. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  754. }
  755. #else /* QCA_AC_BASED_FLOW_CONTROL */
  756. static inline bool
  757. dp_tx_is_threshold_reached(struct dp_tx_desc_pool_s *pool, uint16_t avail_desc)
  758. {
  759. if (qdf_unlikely(avail_desc < pool->stop_th))
  760. return true;
  761. else
  762. return false;
  763. }
  764. /**
  765. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  766. * @soc: Handle to DP SoC structure
  767. * @desc_pool_id:
  768. *
  769. * Return: Tx descriptor or NULL
  770. */
  771. static inline struct dp_tx_desc_s *
  772. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  773. {
  774. struct dp_tx_desc_s *tx_desc = NULL;
  775. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  776. if (pool) {
  777. qdf_spin_lock_bh(&pool->flow_pool_lock);
  778. if (pool->status <= FLOW_POOL_ACTIVE_PAUSED &&
  779. pool->avail_desc) {
  780. tx_desc = dp_tx_get_desc_flow_pool(pool);
  781. tx_desc->pool_id = desc_pool_id;
  782. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  783. dp_tx_desc_set_magic(tx_desc,
  784. DP_TX_MAGIC_PATTERN_INUSE);
  785. if (qdf_unlikely(pool->avail_desc < pool->stop_th)) {
  786. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  787. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  788. /* pause network queues */
  789. soc->pause_cb(desc_pool_id,
  790. WLAN_STOP_ALL_NETIF_QUEUE,
  791. WLAN_DATA_FLOW_CONTROL);
  792. } else {
  793. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  794. }
  795. } else {
  796. pool->pkt_drop_no_desc++;
  797. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  798. }
  799. } else {
  800. soc->pool_stats.pkt_drop_no_pool++;
  801. }
  802. return tx_desc;
  803. }
  804. /**
  805. * dp_tx_desc_free() - Free a tx descriptor and attach it to free list
  806. * @soc: Handle to DP SoC structure
  807. * @tx_desc: Descriptor to free
  808. * @desc_pool_id: Descriptor pool Id
  809. *
  810. * Return: None
  811. */
  812. static inline void
  813. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  814. uint8_t desc_pool_id)
  815. {
  816. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  817. qdf_spin_lock_bh(&pool->flow_pool_lock);
  818. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  819. tx_desc->nbuf = NULL;
  820. tx_desc->flags = 0;
  821. dp_tx_desc_set_magic(tx_desc, DP_TX_MAGIC_PATTERN_FREE);
  822. dp_tx_put_desc_flow_pool(pool, tx_desc);
  823. switch (pool->status) {
  824. case FLOW_POOL_ACTIVE_PAUSED:
  825. if (pool->avail_desc > pool->start_th) {
  826. soc->pause_cb(pool->flow_pool_id,
  827. WLAN_WAKE_ALL_NETIF_QUEUE,
  828. WLAN_DATA_FLOW_CONTROL);
  829. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  830. }
  831. break;
  832. case FLOW_POOL_INVALID:
  833. if (pool->avail_desc == pool->pool_size) {
  834. dp_tx_desc_pool_deinit(soc, desc_pool_id);
  835. dp_tx_desc_pool_free(soc, desc_pool_id);
  836. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  837. qdf_print("%s %d pool is freed!!",
  838. __func__, __LINE__);
  839. return;
  840. }
  841. break;
  842. case FLOW_POOL_ACTIVE_UNPAUSED:
  843. break;
  844. default:
  845. qdf_print("%s %d pool is INACTIVE State!!",
  846. __func__, __LINE__);
  847. break;
  848. };
  849. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  850. }
  851. #endif /* QCA_AC_BASED_FLOW_CONTROL */
  852. static inline bool
  853. dp_tx_desc_thresh_reached(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  854. {
  855. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  856. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  857. DP_MOD_ID_CDP);
  858. struct dp_tx_desc_pool_s *pool;
  859. bool status;
  860. if (!vdev)
  861. return false;
  862. pool = vdev->pool;
  863. status = dp_tx_is_threshold_reached(pool, pool->avail_desc);
  864. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  865. return status;
  866. }
  867. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  868. static inline void dp_tx_flow_control_init(struct dp_soc *handle)
  869. {
  870. }
  871. static inline void dp_tx_flow_control_deinit(struct dp_soc *handle)
  872. {
  873. }
  874. static inline QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev,
  875. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id,
  876. uint32_t flow_pool_size)
  877. {
  878. return QDF_STATUS_SUCCESS;
  879. }
  880. static inline void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev,
  881. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id)
  882. {
  883. }
  884. #ifdef QCA_DP_TX_HW_SW_NBUF_DESC_PREFETCH
  885. static inline
  886. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  887. {
  888. if (tx_desc)
  889. prefetch(tx_desc);
  890. }
  891. #else
  892. static inline
  893. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  894. {
  895. }
  896. #endif
  897. /**
  898. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  899. * @soc: Handle to DP SoC structure
  900. * @desc_pool_id: pool id
  901. *
  902. * Return: Tx Descriptor or NULL
  903. */
  904. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  905. uint8_t desc_pool_id)
  906. {
  907. struct dp_tx_desc_s *tx_desc = NULL;
  908. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  909. TX_DESC_LOCK_LOCK(&pool->lock);
  910. tx_desc = pool->freelist;
  911. /* Pool is exhausted */
  912. if (!tx_desc) {
  913. TX_DESC_LOCK_UNLOCK(&pool->lock);
  914. return NULL;
  915. }
  916. pool->freelist = pool->freelist->next;
  917. pool->num_allocated++;
  918. pool->num_free--;
  919. dp_tx_prefetch_desc(pool->freelist);
  920. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  921. TX_DESC_LOCK_UNLOCK(&pool->lock);
  922. return tx_desc;
  923. }
  924. /**
  925. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  926. * from given pool
  927. * @soc: Handle to DP SoC structure
  928. * @desc_pool_id: pool id should pick up
  929. * @num_requested: number of required descriptor
  930. *
  931. * allocate multiple tx descriptor and make a link
  932. *
  933. * Return: first descriptor pointer or NULL
  934. */
  935. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  936. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  937. {
  938. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  939. uint8_t count;
  940. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  941. TX_DESC_LOCK_LOCK(&pool->lock);
  942. if ((num_requested == 0) ||
  943. (pool->num_free < num_requested)) {
  944. TX_DESC_LOCK_UNLOCK(&pool->lock);
  945. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  946. "%s, No Free Desc: Available(%d) num_requested(%d)",
  947. __func__, pool->num_free,
  948. num_requested);
  949. return NULL;
  950. }
  951. h_desc = pool->freelist;
  952. /* h_desc should never be NULL since num_free > requested */
  953. qdf_assert_always(h_desc);
  954. c_desc = h_desc;
  955. for (count = 0; count < (num_requested - 1); count++) {
  956. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  957. c_desc = c_desc->next;
  958. }
  959. pool->num_free -= count;
  960. pool->num_allocated += count;
  961. pool->freelist = c_desc->next;
  962. c_desc->next = NULL;
  963. TX_DESC_LOCK_UNLOCK(&pool->lock);
  964. return h_desc;
  965. }
  966. /**
  967. * dp_tx_desc_free() - Free a tx descriptor and attach it to free list
  968. * @soc: Handle to DP SoC structure
  969. * @tx_desc: descriptor to free
  970. * @desc_pool_id: ID of the free pool
  971. */
  972. static inline void
  973. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  974. uint8_t desc_pool_id)
  975. {
  976. struct dp_tx_desc_pool_s *pool = NULL;
  977. dp_tx_desc_clear(tx_desc);
  978. pool = &soc->tx_desc[desc_pool_id];
  979. TX_DESC_LOCK_LOCK(&pool->lock);
  980. tx_desc->next = pool->freelist;
  981. pool->freelist = tx_desc;
  982. pool->num_allocated--;
  983. pool->num_free++;
  984. TX_DESC_LOCK_UNLOCK(&pool->lock);
  985. }
  986. static inline void
  987. dp_tx_desc_free_list(struct dp_tx_desc_pool_s *pool,
  988. struct dp_tx_desc_s *head_desc,
  989. struct dp_tx_desc_s *tail_desc,
  990. uint32_t fast_desc_count)
  991. {
  992. TX_DESC_LOCK_LOCK(&pool->lock);
  993. pool->num_allocated -= fast_desc_count;
  994. pool->num_free += fast_desc_count;
  995. tail_desc->next = pool->freelist;
  996. pool->freelist = head_desc;
  997. TX_DESC_LOCK_UNLOCK(&pool->lock);
  998. }
  999. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  1000. #ifdef QCA_DP_TX_DESC_ID_CHECK
  1001. /**
  1002. * dp_tx_is_desc_id_valid() - check is the tx desc id valid
  1003. * @soc: Handle to DP SoC structure
  1004. * @tx_desc_id:
  1005. *
  1006. * Return: true or false
  1007. */
  1008. static inline bool
  1009. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  1010. {
  1011. uint8_t pool_id;
  1012. uint16_t page_id, offset;
  1013. struct dp_tx_desc_pool_s *pool;
  1014. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  1015. DP_TX_DESC_ID_POOL_OS;
  1016. /* Pool ID is out of limit */
  1017. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  1018. soc->wlan_cfg_ctx)) {
  1019. QDF_TRACE(QDF_MODULE_ID_DP,
  1020. QDF_TRACE_LEVEL_FATAL,
  1021. "%s:Tx Comp pool id %d not valid",
  1022. __func__,
  1023. pool_id);
  1024. goto warn_exit;
  1025. }
  1026. pool = &soc->tx_desc[pool_id];
  1027. /* the pool is freed */
  1028. if (IS_TX_DESC_POOL_STATUS_INACTIVE(pool)) {
  1029. QDF_TRACE(QDF_MODULE_ID_DP,
  1030. QDF_TRACE_LEVEL_FATAL,
  1031. "%s:the pool %d has been freed",
  1032. __func__,
  1033. pool_id);
  1034. goto warn_exit;
  1035. }
  1036. page_id = (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  1037. DP_TX_DESC_ID_PAGE_OS;
  1038. /* the page id is out of limit */
  1039. if (page_id >= pool->desc_pages.num_pages) {
  1040. QDF_TRACE(QDF_MODULE_ID_DP,
  1041. QDF_TRACE_LEVEL_FATAL,
  1042. "%s:the page id %d invalid, pool id %d, num_page %d",
  1043. __func__,
  1044. page_id,
  1045. pool_id,
  1046. pool->desc_pages.num_pages);
  1047. goto warn_exit;
  1048. }
  1049. offset = (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  1050. DP_TX_DESC_ID_OFFSET_OS;
  1051. /* the offset is out of limit */
  1052. if (offset >= pool->desc_pages.num_element_per_page) {
  1053. QDF_TRACE(QDF_MODULE_ID_DP,
  1054. QDF_TRACE_LEVEL_FATAL,
  1055. "%s:offset %d invalid, pool%d,num_elem_per_page %d",
  1056. __func__,
  1057. offset,
  1058. pool_id,
  1059. pool->desc_pages.num_element_per_page);
  1060. goto warn_exit;
  1061. }
  1062. return true;
  1063. warn_exit:
  1064. QDF_TRACE(QDF_MODULE_ID_DP,
  1065. QDF_TRACE_LEVEL_FATAL,
  1066. "%s:Tx desc id 0x%x not valid",
  1067. __func__,
  1068. tx_desc_id);
  1069. qdf_assert_always(0);
  1070. return false;
  1071. }
  1072. #else
  1073. static inline bool
  1074. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  1075. {
  1076. return true;
  1077. }
  1078. #endif /* QCA_DP_TX_DESC_ID_CHECK */
  1079. #ifdef QCA_DP_TX_DESC_FAST_COMP_ENABLE
  1080. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  1081. struct dp_tx_desc_s *desc,
  1082. uint8_t allow_fast_comp)
  1083. {
  1084. if (qdf_likely(!(desc->flags & DP_TX_DESC_FLAG_TO_FW)) &&
  1085. qdf_likely(allow_fast_comp)) {
  1086. desc->flags |= DP_TX_DESC_FLAG_SIMPLE;
  1087. }
  1088. }
  1089. #else
  1090. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  1091. struct dp_tx_desc_s *desc,
  1092. uint8_t allow_fast_comp)
  1093. {
  1094. }
  1095. #endif /* QCA_DP_TX_DESC_FAST_COMP_ENABLE */
  1096. /**
  1097. * dp_tx_desc_find() - find dp tx descriptor from pool/page/offset
  1098. * @soc: handle for the device sending the data
  1099. * @pool_id:
  1100. * @page_id:
  1101. * @offset:
  1102. *
  1103. * Use page and offset to find the corresponding descriptor object in
  1104. * the given descriptor pool.
  1105. *
  1106. * Return: the descriptor object that has the specified ID
  1107. */
  1108. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  1109. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  1110. {
  1111. struct dp_tx_desc_pool_s *tx_desc_pool = &soc->tx_desc[pool_id];
  1112. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  1113. tx_desc_pool->elem_size * offset;
  1114. }
  1115. /**
  1116. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  1117. * @soc: handle for the device sending the data
  1118. * @desc_pool_id: target pool id
  1119. *
  1120. * Return: None
  1121. */
  1122. static inline
  1123. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  1124. uint8_t desc_pool_id)
  1125. {
  1126. struct dp_tx_ext_desc_elem_s *c_elem;
  1127. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1128. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1129. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  1130. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1131. return NULL;
  1132. }
  1133. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  1134. soc->tx_ext_desc[desc_pool_id].freelist =
  1135. soc->tx_ext_desc[desc_pool_id].freelist->next;
  1136. soc->tx_ext_desc[desc_pool_id].num_free--;
  1137. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1138. return c_elem;
  1139. }
  1140. /**
  1141. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  1142. * @soc: handle for the device sending the data
  1143. * @elem: ext descriptor pointer should release
  1144. * @desc_pool_id: target pool id
  1145. *
  1146. * Return: None
  1147. */
  1148. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  1149. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  1150. {
  1151. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1152. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1153. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  1154. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  1155. soc->tx_ext_desc[desc_pool_id].num_free++;
  1156. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1157. return;
  1158. }
  1159. /**
  1160. * dp_tx_ext_desc_free_multiple() - Free multiple tx extension descriptor and
  1161. * attach it to free list
  1162. * @soc: Handle to DP SoC structure
  1163. * @desc_pool_id: pool id should pick up
  1164. * @elem: tx descriptor should be freed
  1165. * @num_free: number of descriptors should be freed
  1166. *
  1167. * Return: none
  1168. */
  1169. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  1170. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  1171. uint8_t num_free)
  1172. {
  1173. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  1174. uint8_t freed = num_free;
  1175. /* caller should always guarantee atleast list of num_free nodes */
  1176. qdf_assert_always(elem);
  1177. head = elem;
  1178. c_elem = head;
  1179. tail = head;
  1180. while (c_elem && freed) {
  1181. tail = c_elem;
  1182. c_elem = c_elem->next;
  1183. freed--;
  1184. }
  1185. /* caller should always guarantee atleast list of num_free nodes */
  1186. qdf_assert_always(tail);
  1187. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1188. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1189. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  1190. soc->tx_ext_desc[desc_pool_id].freelist = head;
  1191. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  1192. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1193. return;
  1194. }
  1195. #if defined(FEATURE_TSO)
  1196. /**
  1197. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  1198. * @soc: device soc instance
  1199. * @pool_id: pool id should pick up tso descriptor
  1200. *
  1201. * Allocates a TSO segment element from the free list held in
  1202. * the soc
  1203. *
  1204. * Return: tso_seg, tso segment memory pointer
  1205. */
  1206. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  1207. struct dp_soc *soc, uint8_t pool_id)
  1208. {
  1209. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  1210. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  1211. if (soc->tx_tso_desc[pool_id].freelist) {
  1212. soc->tx_tso_desc[pool_id].num_free--;
  1213. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  1214. soc->tx_tso_desc[pool_id].freelist =
  1215. soc->tx_tso_desc[pool_id].freelist->next;
  1216. }
  1217. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  1218. return tso_seg;
  1219. }
  1220. /**
  1221. * dp_tx_tso_desc_free() - function to free a TSO segment
  1222. * @soc: device soc instance
  1223. * @pool_id: pool id should pick up tso descriptor
  1224. * @tso_seg: tso segment memory pointer
  1225. *
  1226. * Returns a TSO segment element to the free list held in the
  1227. * HTT pdev
  1228. *
  1229. * Return: none
  1230. */
  1231. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  1232. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  1233. {
  1234. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  1235. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  1236. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  1237. soc->tx_tso_desc[pool_id].num_free++;
  1238. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  1239. }
  1240. static inline
  1241. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  1242. uint8_t pool_id)
  1243. {
  1244. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  1245. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1246. if (soc->tx_tso_num_seg[pool_id].freelist) {
  1247. soc->tx_tso_num_seg[pool_id].num_free--;
  1248. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  1249. soc->tx_tso_num_seg[pool_id].freelist =
  1250. soc->tx_tso_num_seg[pool_id].freelist->next;
  1251. }
  1252. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1253. return tso_num_seg;
  1254. }
  1255. static inline
  1256. void dp_tso_num_seg_free(struct dp_soc *soc,
  1257. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  1258. {
  1259. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1260. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  1261. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  1262. soc->tx_tso_num_seg[pool_id].num_free++;
  1263. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1264. }
  1265. #endif
  1266. /**
  1267. * dp_tx_me_alloc_buf() - Alloc descriptor from me pool
  1268. * @pdev: DP_PDEV handle for datapath
  1269. *
  1270. * Return: tx descriptor on success, NULL on error
  1271. */
  1272. static inline struct dp_tx_me_buf_t*
  1273. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  1274. {
  1275. struct dp_tx_me_buf_t *buf = NULL;
  1276. qdf_spin_lock_bh(&pdev->tx_mutex);
  1277. if (pdev->me_buf.freelist) {
  1278. buf = pdev->me_buf.freelist;
  1279. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  1280. pdev->me_buf.buf_in_use++;
  1281. } else {
  1282. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1283. "Error allocating memory in pool");
  1284. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1285. return NULL;
  1286. }
  1287. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1288. return buf;
  1289. }
  1290. /**
  1291. * dp_tx_me_free_buf() - Unmap the buffer holding the dest
  1292. * address, free me descriptor and add it to the free-pool
  1293. * @pdev: DP_PDEV handle for datapath
  1294. * @buf : Allocated ME BUF
  1295. *
  1296. * Return:void
  1297. */
  1298. static inline void
  1299. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  1300. {
  1301. /*
  1302. * If the buf containing mac address was mapped,
  1303. * it must be unmapped before freeing the me_buf.
  1304. * The "paddr_macbuf" member in the me_buf structure
  1305. * holds the mapped physical address and it must be
  1306. * set to 0 after unmapping.
  1307. */
  1308. if (buf->paddr_macbuf) {
  1309. qdf_mem_unmap_nbytes_single(pdev->soc->osdev,
  1310. buf->paddr_macbuf,
  1311. QDF_DMA_TO_DEVICE,
  1312. QDF_MAC_ADDR_SIZE);
  1313. buf->paddr_macbuf = 0;
  1314. }
  1315. qdf_spin_lock_bh(&pdev->tx_mutex);
  1316. buf->next = pdev->me_buf.freelist;
  1317. pdev->me_buf.freelist = buf;
  1318. pdev->me_buf.buf_in_use--;
  1319. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1320. }
  1321. #endif /* DP_TX_DESC_H */