dp_tx_desc.h 44 KB

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