dp_tx_desc.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552
  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. * @cleanup: cleanup the pool
  422. *
  423. */
  424. void dp_tx_desc_pool_cleanup(struct dp_soc *soc, qdf_nbuf_t *nbuf_list,
  425. bool cleanup);
  426. #endif
  427. /**
  428. * dp_tx_desc_clear() - Clear contents of tx desc
  429. * @tx_desc: descriptor to free
  430. *
  431. * Return: none
  432. */
  433. static inline void
  434. dp_tx_desc_clear(struct dp_tx_desc_s *tx_desc)
  435. {
  436. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  437. tx_desc->nbuf = NULL;
  438. tx_desc->flags = 0;
  439. tx_desc->next = NULL;
  440. }
  441. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  442. void dp_tx_flow_control_init(struct dp_soc *);
  443. void dp_tx_flow_control_deinit(struct dp_soc *);
  444. QDF_STATUS dp_txrx_register_pause_cb(struct cdp_soc_t *soc,
  445. tx_pause_callback pause_cb);
  446. QDF_STATUS dp_tx_flow_pool_map(struct cdp_soc_t *soc, uint8_t pdev_id,
  447. uint8_t vdev_id);
  448. void dp_tx_flow_pool_unmap(struct cdp_soc_t *handle, uint8_t pdev_id,
  449. uint8_t vdev_id);
  450. void dp_tx_clear_flow_pool_stats(struct dp_soc *soc);
  451. struct dp_tx_desc_pool_s *dp_tx_create_flow_pool(struct dp_soc *soc,
  452. uint8_t flow_pool_id, uint32_t flow_pool_size);
  453. QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev, uint8_t flow_id,
  454. uint8_t flow_type, uint8_t flow_pool_id, uint32_t flow_pool_size);
  455. void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev, uint8_t flow_id,
  456. uint8_t flow_type, uint8_t flow_pool_id);
  457. /**
  458. * dp_tx_get_desc_flow_pool() - get descriptor from flow pool
  459. * @pool: flow pool
  460. *
  461. * Caller needs to take lock and do sanity checks.
  462. *
  463. * Return: tx descriptor
  464. */
  465. static inline
  466. struct dp_tx_desc_s *dp_tx_get_desc_flow_pool(struct dp_tx_desc_pool_s *pool)
  467. {
  468. struct dp_tx_desc_s *tx_desc = pool->freelist;
  469. pool->freelist = pool->freelist->next;
  470. pool->avail_desc--;
  471. return tx_desc;
  472. }
  473. /**
  474. * dp_tx_put_desc_flow_pool() - put descriptor to flow pool freelist
  475. * @pool: flow pool
  476. * @tx_desc: tx descriptor
  477. *
  478. * Caller needs to take lock and do sanity checks.
  479. *
  480. * Return: none
  481. */
  482. static inline
  483. void dp_tx_put_desc_flow_pool(struct dp_tx_desc_pool_s *pool,
  484. struct dp_tx_desc_s *tx_desc)
  485. {
  486. tx_desc->next = pool->freelist;
  487. pool->freelist = tx_desc;
  488. pool->avail_desc++;
  489. }
  490. static inline void
  491. dp_tx_desc_free_list(struct dp_tx_desc_pool_s *pool,
  492. struct dp_tx_desc_s *head_desc,
  493. struct dp_tx_desc_s *tail_desc,
  494. uint32_t fast_desc_count)
  495. {
  496. }
  497. #ifdef QCA_AC_BASED_FLOW_CONTROL
  498. /**
  499. * dp_tx_flow_pool_member_clean() - Clean the members of TX flow pool
  500. * @pool: flow pool
  501. *
  502. * Return: None
  503. */
  504. static inline void
  505. dp_tx_flow_pool_member_clean(struct dp_tx_desc_pool_s *pool)
  506. {
  507. pool->elem_size = 0;
  508. pool->freelist = NULL;
  509. pool->pool_size = 0;
  510. pool->avail_desc = 0;
  511. qdf_mem_zero(pool->start_th, FL_TH_MAX);
  512. qdf_mem_zero(pool->stop_th, FL_TH_MAX);
  513. pool->status = FLOW_POOL_INACTIVE;
  514. }
  515. /**
  516. * dp_tx_is_threshold_reached() - Check if current avail desc meet threshold
  517. * @pool: flow pool
  518. * @avail_desc: available descriptor number
  519. *
  520. * Return: true if threshold is met, false if not
  521. */
  522. static inline bool
  523. dp_tx_is_threshold_reached(struct dp_tx_desc_pool_s *pool, uint16_t avail_desc)
  524. {
  525. if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_BE_BK]))
  526. return true;
  527. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_VI]))
  528. return true;
  529. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_VO]))
  530. return true;
  531. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_HI]))
  532. return true;
  533. else
  534. return false;
  535. }
  536. /**
  537. * dp_tx_adjust_flow_pool_state() - Adjust flow pool state
  538. * @soc: dp soc
  539. * @pool: flow pool
  540. */
  541. static inline void
  542. dp_tx_adjust_flow_pool_state(struct dp_soc *soc,
  543. struct dp_tx_desc_pool_s *pool)
  544. {
  545. if (pool->avail_desc > pool->stop_th[DP_TH_BE_BK]) {
  546. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  547. return;
  548. } else if (pool->avail_desc <= pool->stop_th[DP_TH_BE_BK] &&
  549. pool->avail_desc > pool->stop_th[DP_TH_VI]) {
  550. pool->status = FLOW_POOL_BE_BK_PAUSED;
  551. } else if (pool->avail_desc <= pool->stop_th[DP_TH_VI] &&
  552. pool->avail_desc > pool->stop_th[DP_TH_VO]) {
  553. pool->status = FLOW_POOL_VI_PAUSED;
  554. } else if (pool->avail_desc <= pool->stop_th[DP_TH_VO] &&
  555. pool->avail_desc > pool->stop_th[DP_TH_HI]) {
  556. pool->status = FLOW_POOL_VO_PAUSED;
  557. } else if (pool->avail_desc <= pool->stop_th[DP_TH_HI]) {
  558. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  559. }
  560. switch (pool->status) {
  561. case FLOW_POOL_ACTIVE_PAUSED:
  562. soc->pause_cb(pool->flow_pool_id,
  563. WLAN_NETIF_PRIORITY_QUEUE_OFF,
  564. WLAN_DATA_FLOW_CTRL_PRI);
  565. fallthrough;
  566. case FLOW_POOL_VO_PAUSED:
  567. soc->pause_cb(pool->flow_pool_id,
  568. WLAN_NETIF_VO_QUEUE_OFF,
  569. WLAN_DATA_FLOW_CTRL_VO);
  570. fallthrough;
  571. case FLOW_POOL_VI_PAUSED:
  572. soc->pause_cb(pool->flow_pool_id,
  573. WLAN_NETIF_VI_QUEUE_OFF,
  574. WLAN_DATA_FLOW_CTRL_VI);
  575. fallthrough;
  576. case FLOW_POOL_BE_BK_PAUSED:
  577. soc->pause_cb(pool->flow_pool_id,
  578. WLAN_NETIF_BE_BK_QUEUE_OFF,
  579. WLAN_DATA_FLOW_CTRL_BE_BK);
  580. break;
  581. default:
  582. dp_err("Invalid pool status:%u to adjust", pool->status);
  583. }
  584. }
  585. /**
  586. * dp_tx_desc_alloc() - Allocate a Software Tx descriptor from given pool
  587. * @soc: Handle to DP SoC structure
  588. * @desc_pool_id: ID of the flow control fool
  589. *
  590. * Return: TX descriptor allocated or NULL
  591. */
  592. static inline struct dp_tx_desc_s *
  593. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  594. {
  595. struct dp_tx_desc_s *tx_desc = NULL;
  596. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  597. bool is_pause = false;
  598. enum netif_action_type act = WLAN_NETIF_ACTION_TYPE_NONE;
  599. enum dp_fl_ctrl_threshold level = DP_TH_BE_BK;
  600. enum netif_reason_type reason;
  601. if (qdf_likely(pool)) {
  602. qdf_spin_lock_bh(&pool->flow_pool_lock);
  603. if (qdf_likely(pool->avail_desc &&
  604. pool->status != FLOW_POOL_INVALID &&
  605. pool->status != FLOW_POOL_INACTIVE)) {
  606. tx_desc = dp_tx_get_desc_flow_pool(pool);
  607. tx_desc->pool_id = desc_pool_id;
  608. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  609. dp_tx_desc_set_magic(tx_desc,
  610. DP_TX_MAGIC_PATTERN_INUSE);
  611. is_pause = dp_tx_is_threshold_reached(pool,
  612. pool->avail_desc);
  613. if (qdf_unlikely(pool->status ==
  614. FLOW_POOL_ACTIVE_UNPAUSED_REATTACH)) {
  615. dp_tx_adjust_flow_pool_state(soc, pool);
  616. is_pause = false;
  617. }
  618. if (qdf_unlikely(is_pause)) {
  619. switch (pool->status) {
  620. case FLOW_POOL_ACTIVE_UNPAUSED:
  621. /* pause network BE\BK queue */
  622. act = WLAN_NETIF_BE_BK_QUEUE_OFF;
  623. reason = WLAN_DATA_FLOW_CTRL_BE_BK;
  624. level = DP_TH_BE_BK;
  625. pool->status = FLOW_POOL_BE_BK_PAUSED;
  626. break;
  627. case FLOW_POOL_BE_BK_PAUSED:
  628. /* pause network VI queue */
  629. act = WLAN_NETIF_VI_QUEUE_OFF;
  630. reason = WLAN_DATA_FLOW_CTRL_VI;
  631. level = DP_TH_VI;
  632. pool->status = FLOW_POOL_VI_PAUSED;
  633. break;
  634. case FLOW_POOL_VI_PAUSED:
  635. /* pause network VO queue */
  636. act = WLAN_NETIF_VO_QUEUE_OFF;
  637. reason = WLAN_DATA_FLOW_CTRL_VO;
  638. level = DP_TH_VO;
  639. pool->status = FLOW_POOL_VO_PAUSED;
  640. break;
  641. case FLOW_POOL_VO_PAUSED:
  642. /* pause network HI PRI queue */
  643. act = WLAN_NETIF_PRIORITY_QUEUE_OFF;
  644. reason = WLAN_DATA_FLOW_CTRL_PRI;
  645. level = DP_TH_HI;
  646. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  647. break;
  648. case FLOW_POOL_ACTIVE_PAUSED:
  649. act = WLAN_NETIF_ACTION_TYPE_NONE;
  650. break;
  651. default:
  652. dp_err_rl("pool status is %d!",
  653. pool->status);
  654. break;
  655. }
  656. if (act != WLAN_NETIF_ACTION_TYPE_NONE) {
  657. pool->latest_pause_time[level] =
  658. qdf_get_system_timestamp();
  659. soc->pause_cb(desc_pool_id,
  660. act,
  661. reason);
  662. }
  663. }
  664. } else {
  665. pool->pkt_drop_no_desc++;
  666. }
  667. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  668. } else {
  669. dp_err_rl("NULL desc pool pool_id %d", desc_pool_id);
  670. soc->pool_stats.pkt_drop_no_pool++;
  671. }
  672. return tx_desc;
  673. }
  674. /**
  675. * dp_tx_desc_free() - Free a tx descriptor and attach it to free list
  676. * @soc: Handle to DP SoC structure
  677. * @tx_desc: the tx descriptor to be freed
  678. * @desc_pool_id: ID of the flow control pool
  679. *
  680. * Return: None
  681. */
  682. static inline void
  683. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  684. uint8_t desc_pool_id)
  685. {
  686. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  687. qdf_time_t unpause_time = qdf_get_system_timestamp(), pause_dur;
  688. enum netif_action_type act = WLAN_WAKE_ALL_NETIF_QUEUE;
  689. enum netif_reason_type reason;
  690. qdf_spin_lock_bh(&pool->flow_pool_lock);
  691. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  692. tx_desc->nbuf = NULL;
  693. tx_desc->flags = 0;
  694. dp_tx_desc_set_magic(tx_desc, DP_TX_MAGIC_PATTERN_FREE);
  695. dp_tx_put_desc_flow_pool(pool, tx_desc);
  696. switch (pool->status) {
  697. case FLOW_POOL_ACTIVE_PAUSED:
  698. if (pool->avail_desc > pool->start_th[DP_TH_HI]) {
  699. act = WLAN_NETIF_PRIORITY_QUEUE_ON;
  700. reason = WLAN_DATA_FLOW_CTRL_PRI;
  701. pool->status = FLOW_POOL_VO_PAUSED;
  702. /* Update maximum pause duration for HI queue */
  703. pause_dur = unpause_time -
  704. pool->latest_pause_time[DP_TH_HI];
  705. if (pool->max_pause_time[DP_TH_HI] < pause_dur)
  706. pool->max_pause_time[DP_TH_HI] = pause_dur;
  707. }
  708. break;
  709. case FLOW_POOL_VO_PAUSED:
  710. if (pool->avail_desc > pool->start_th[DP_TH_VO]) {
  711. act = WLAN_NETIF_VO_QUEUE_ON;
  712. reason = WLAN_DATA_FLOW_CTRL_VO;
  713. pool->status = FLOW_POOL_VI_PAUSED;
  714. /* Update maximum pause duration for VO queue */
  715. pause_dur = unpause_time -
  716. pool->latest_pause_time[DP_TH_VO];
  717. if (pool->max_pause_time[DP_TH_VO] < pause_dur)
  718. pool->max_pause_time[DP_TH_VO] = pause_dur;
  719. }
  720. break;
  721. case FLOW_POOL_VI_PAUSED:
  722. if (pool->avail_desc > pool->start_th[DP_TH_VI]) {
  723. act = WLAN_NETIF_VI_QUEUE_ON;
  724. reason = WLAN_DATA_FLOW_CTRL_VI;
  725. pool->status = FLOW_POOL_BE_BK_PAUSED;
  726. /* Update maximum pause duration for VI queue */
  727. pause_dur = unpause_time -
  728. pool->latest_pause_time[DP_TH_VI];
  729. if (pool->max_pause_time[DP_TH_VI] < pause_dur)
  730. pool->max_pause_time[DP_TH_VI] = pause_dur;
  731. }
  732. break;
  733. case FLOW_POOL_BE_BK_PAUSED:
  734. if (pool->avail_desc > pool->start_th[DP_TH_BE_BK]) {
  735. act = WLAN_NETIF_BE_BK_QUEUE_ON;
  736. reason = WLAN_DATA_FLOW_CTRL_BE_BK;
  737. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  738. /* Update maximum pause duration for BE_BK queue */
  739. pause_dur = unpause_time -
  740. pool->latest_pause_time[DP_TH_BE_BK];
  741. if (pool->max_pause_time[DP_TH_BE_BK] < pause_dur)
  742. pool->max_pause_time[DP_TH_BE_BK] = pause_dur;
  743. }
  744. break;
  745. case FLOW_POOL_INVALID:
  746. if (pool->avail_desc == pool->pool_size) {
  747. dp_tx_desc_pool_deinit(soc, desc_pool_id, false);
  748. dp_tx_desc_pool_free(soc, desc_pool_id, false);
  749. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  750. dp_err_rl("pool %d is freed!!", desc_pool_id);
  751. return;
  752. }
  753. break;
  754. case FLOW_POOL_ACTIVE_UNPAUSED:
  755. break;
  756. case FLOW_POOL_ACTIVE_UNPAUSED_REATTACH:
  757. fallthrough;
  758. default:
  759. dp_err_rl("pool %d status: %d",
  760. desc_pool_id, pool->status);
  761. break;
  762. };
  763. if (act != WLAN_WAKE_ALL_NETIF_QUEUE)
  764. soc->pause_cb(pool->flow_pool_id,
  765. act, reason);
  766. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  767. }
  768. static inline void
  769. dp_tx_spcl_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  770. uint8_t desc_pool_id)
  771. {
  772. }
  773. static inline struct dp_tx_desc_s *dp_tx_spcl_desc_alloc(struct dp_soc *soc,
  774. uint8_t desc_pool_id)
  775. {
  776. return NULL;
  777. }
  778. #else /* QCA_AC_BASED_FLOW_CONTROL */
  779. static inline bool
  780. dp_tx_is_threshold_reached(struct dp_tx_desc_pool_s *pool, uint16_t avail_desc)
  781. {
  782. if (qdf_unlikely(avail_desc < pool->stop_th))
  783. return true;
  784. else
  785. return false;
  786. }
  787. /**
  788. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  789. * @soc: Handle to DP SoC structure
  790. * @desc_pool_id:
  791. *
  792. * Return: Tx descriptor or NULL
  793. */
  794. static inline struct dp_tx_desc_s *
  795. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  796. {
  797. struct dp_tx_desc_s *tx_desc = NULL;
  798. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  799. if (pool) {
  800. qdf_spin_lock_bh(&pool->flow_pool_lock);
  801. if (pool->status <= FLOW_POOL_ACTIVE_PAUSED &&
  802. pool->avail_desc) {
  803. tx_desc = dp_tx_get_desc_flow_pool(pool);
  804. tx_desc->pool_id = desc_pool_id;
  805. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  806. dp_tx_desc_set_magic(tx_desc,
  807. DP_TX_MAGIC_PATTERN_INUSE);
  808. if (qdf_unlikely(pool->avail_desc < pool->stop_th)) {
  809. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  810. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  811. /* pause network queues */
  812. soc->pause_cb(desc_pool_id,
  813. WLAN_STOP_ALL_NETIF_QUEUE,
  814. WLAN_DATA_FLOW_CONTROL);
  815. } else {
  816. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  817. }
  818. } else {
  819. pool->pkt_drop_no_desc++;
  820. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  821. }
  822. } else {
  823. soc->pool_stats.pkt_drop_no_pool++;
  824. }
  825. return tx_desc;
  826. }
  827. static inline struct dp_tx_desc_s *dp_tx_spcl_desc_alloc(struct dp_soc *soc,
  828. uint8_t desc_pool_id)
  829. {
  830. return NULL;
  831. }
  832. /**
  833. * dp_tx_desc_free() - Free a tx descriptor and attach it to free list
  834. * @soc: Handle to DP SoC structure
  835. * @tx_desc: Descriptor to free
  836. * @desc_pool_id: Descriptor pool Id
  837. *
  838. * Return: None
  839. */
  840. static inline void
  841. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  842. uint8_t desc_pool_id)
  843. {
  844. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  845. qdf_spin_lock_bh(&pool->flow_pool_lock);
  846. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  847. tx_desc->nbuf = NULL;
  848. tx_desc->flags = 0;
  849. dp_tx_desc_set_magic(tx_desc, DP_TX_MAGIC_PATTERN_FREE);
  850. dp_tx_put_desc_flow_pool(pool, tx_desc);
  851. switch (pool->status) {
  852. case FLOW_POOL_ACTIVE_PAUSED:
  853. if (pool->avail_desc > pool->start_th) {
  854. soc->pause_cb(pool->flow_pool_id,
  855. WLAN_WAKE_ALL_NETIF_QUEUE,
  856. WLAN_DATA_FLOW_CONTROL);
  857. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  858. }
  859. break;
  860. case FLOW_POOL_INVALID:
  861. if (pool->avail_desc == pool->pool_size) {
  862. dp_tx_desc_pool_deinit(soc, desc_pool_id, false);
  863. dp_tx_desc_pool_free(soc, desc_pool_id, false);
  864. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  865. qdf_print("%s %d pool is freed!!",
  866. __func__, __LINE__);
  867. return;
  868. }
  869. break;
  870. case FLOW_POOL_ACTIVE_UNPAUSED:
  871. break;
  872. default:
  873. qdf_print("%s %d pool is INACTIVE State!!",
  874. __func__, __LINE__);
  875. break;
  876. };
  877. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  878. }
  879. static inline void
  880. dp_tx_spcl_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  881. uint8_t desc_pool_id)
  882. {
  883. }
  884. #endif /* QCA_AC_BASED_FLOW_CONTROL */
  885. static inline bool
  886. dp_tx_desc_thresh_reached(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  887. {
  888. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  889. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  890. DP_MOD_ID_CDP);
  891. struct dp_tx_desc_pool_s *pool;
  892. bool status;
  893. if (!vdev)
  894. return false;
  895. pool = vdev->pool;
  896. status = dp_tx_is_threshold_reached(pool, pool->avail_desc);
  897. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  898. return status;
  899. }
  900. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  901. static inline void dp_tx_flow_control_init(struct dp_soc *handle)
  902. {
  903. }
  904. static inline void dp_tx_flow_control_deinit(struct dp_soc *handle)
  905. {
  906. }
  907. static inline QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev,
  908. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id,
  909. uint32_t flow_pool_size)
  910. {
  911. return QDF_STATUS_SUCCESS;
  912. }
  913. static inline void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev,
  914. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id)
  915. {
  916. }
  917. #ifdef QCA_DP_TX_HW_SW_NBUF_DESC_PREFETCH
  918. static inline
  919. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  920. {
  921. if (tx_desc)
  922. prefetch(tx_desc);
  923. }
  924. #else
  925. static inline
  926. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  927. {
  928. }
  929. #endif
  930. /**
  931. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  932. * @soc: Handle to DP SoC structure
  933. * @desc_pool_id: pool id
  934. *
  935. * Return: Tx Descriptor or NULL
  936. */
  937. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  938. uint8_t desc_pool_id)
  939. {
  940. struct dp_tx_desc_s *tx_desc = NULL;
  941. struct dp_tx_desc_pool_s *pool = NULL;
  942. pool = dp_get_tx_desc_pool(soc, desc_pool_id);
  943. TX_DESC_LOCK_LOCK(&pool->lock);
  944. tx_desc = pool->freelist;
  945. /* Pool is exhausted */
  946. if (!tx_desc) {
  947. TX_DESC_LOCK_UNLOCK(&pool->lock);
  948. return NULL;
  949. }
  950. pool->freelist = pool->freelist->next;
  951. pool->num_allocated++;
  952. pool->num_free--;
  953. dp_tx_prefetch_desc(pool->freelist);
  954. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  955. TX_DESC_LOCK_UNLOCK(&pool->lock);
  956. return tx_desc;
  957. }
  958. static inline struct dp_tx_desc_s *dp_tx_spcl_desc_alloc(struct dp_soc *soc,
  959. uint8_t desc_pool_id)
  960. {
  961. struct dp_tx_desc_s *tx_desc = NULL;
  962. struct dp_tx_desc_pool_s *pool = NULL;
  963. pool = dp_get_spcl_tx_desc_pool(soc, desc_pool_id);
  964. TX_DESC_LOCK_LOCK(&pool->lock);
  965. tx_desc = pool->freelist;
  966. /* Pool is exhausted */
  967. if (!tx_desc) {
  968. TX_DESC_LOCK_UNLOCK(&pool->lock);
  969. return NULL;
  970. }
  971. pool->freelist = pool->freelist->next;
  972. pool->num_allocated++;
  973. pool->num_free--;
  974. dp_tx_prefetch_desc(pool->freelist);
  975. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  976. tx_desc->flags |= DP_TX_DESC_FLAG_SPECIAL;
  977. TX_DESC_LOCK_UNLOCK(&pool->lock);
  978. return tx_desc;
  979. }
  980. /**
  981. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  982. * from given pool
  983. * @soc: Handle to DP SoC structure
  984. * @desc_pool_id: pool id should pick up
  985. * @num_requested: number of required descriptor
  986. *
  987. * allocate multiple tx descriptor and make a link
  988. *
  989. * Return: first descriptor pointer or NULL
  990. */
  991. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  992. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  993. {
  994. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  995. uint8_t count;
  996. struct dp_tx_desc_pool_s *pool = NULL;
  997. pool = dp_get_tx_desc_pool(soc, desc_pool_id);
  998. TX_DESC_LOCK_LOCK(&pool->lock);
  999. if ((num_requested == 0) ||
  1000. (pool->num_free < num_requested)) {
  1001. TX_DESC_LOCK_UNLOCK(&pool->lock);
  1002. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1003. "%s, No Free Desc: Available(%d) num_requested(%d)",
  1004. __func__, pool->num_free,
  1005. num_requested);
  1006. return NULL;
  1007. }
  1008. h_desc = pool->freelist;
  1009. /* h_desc should never be NULL since num_free > requested */
  1010. qdf_assert_always(h_desc);
  1011. c_desc = h_desc;
  1012. for (count = 0; count < (num_requested - 1); count++) {
  1013. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  1014. c_desc = c_desc->next;
  1015. }
  1016. pool->num_free -= count;
  1017. pool->num_allocated += count;
  1018. pool->freelist = c_desc->next;
  1019. c_desc->next = NULL;
  1020. TX_DESC_LOCK_UNLOCK(&pool->lock);
  1021. return h_desc;
  1022. }
  1023. /**
  1024. * dp_tx_desc_free() - Free a tx descriptor and attach it to free list
  1025. * @soc: Handle to DP SoC structure
  1026. * @tx_desc: descriptor to free
  1027. * @desc_pool_id: ID of the free pool
  1028. */
  1029. static inline void
  1030. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  1031. uint8_t desc_pool_id)
  1032. {
  1033. struct dp_tx_desc_pool_s *pool = NULL;
  1034. dp_tx_desc_clear(tx_desc);
  1035. pool = dp_get_tx_desc_pool(soc, desc_pool_id);
  1036. TX_DESC_LOCK_LOCK(&pool->lock);
  1037. tx_desc->next = pool->freelist;
  1038. pool->freelist = tx_desc;
  1039. pool->num_allocated--;
  1040. pool->num_free++;
  1041. TX_DESC_LOCK_UNLOCK(&pool->lock);
  1042. }
  1043. static inline void
  1044. dp_tx_spcl_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  1045. uint8_t desc_pool_id)
  1046. {
  1047. struct dp_tx_desc_pool_s *pool = NULL;
  1048. dp_tx_desc_clear(tx_desc);
  1049. pool = dp_get_spcl_tx_desc_pool(soc, desc_pool_id);
  1050. TX_DESC_LOCK_LOCK(&pool->lock);
  1051. tx_desc->next = pool->freelist;
  1052. pool->freelist = tx_desc;
  1053. pool->num_allocated--;
  1054. pool->num_free++;
  1055. TX_DESC_LOCK_UNLOCK(&pool->lock);
  1056. }
  1057. static inline void
  1058. dp_tx_desc_free_list(struct dp_tx_desc_pool_s *pool,
  1059. struct dp_tx_desc_s *head_desc,
  1060. struct dp_tx_desc_s *tail_desc,
  1061. uint32_t fast_desc_count)
  1062. {
  1063. TX_DESC_LOCK_LOCK(&pool->lock);
  1064. pool->num_allocated -= fast_desc_count;
  1065. pool->num_free += fast_desc_count;
  1066. tail_desc->next = pool->freelist;
  1067. pool->freelist = head_desc;
  1068. TX_DESC_LOCK_UNLOCK(&pool->lock);
  1069. }
  1070. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  1071. #ifdef QCA_DP_TX_DESC_ID_CHECK
  1072. /**
  1073. * dp_tx_is_desc_id_valid() - check is the tx desc id valid
  1074. * @soc: Handle to DP SoC structure
  1075. * @tx_desc_id:
  1076. *
  1077. * Return: true or false
  1078. */
  1079. static inline bool
  1080. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  1081. {
  1082. uint8_t pool_id;
  1083. uint16_t page_id, offset;
  1084. struct dp_tx_desc_pool_s *pool;
  1085. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  1086. DP_TX_DESC_ID_POOL_OS;
  1087. /* Pool ID is out of limit */
  1088. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  1089. soc->wlan_cfg_ctx)) {
  1090. QDF_TRACE(QDF_MODULE_ID_DP,
  1091. QDF_TRACE_LEVEL_FATAL,
  1092. "%s:Tx Comp pool id %d not valid",
  1093. __func__,
  1094. pool_id);
  1095. goto warn_exit;
  1096. }
  1097. pool = &soc->tx_desc[pool_id];
  1098. /* the pool is freed */
  1099. if (IS_TX_DESC_POOL_STATUS_INACTIVE(pool)) {
  1100. QDF_TRACE(QDF_MODULE_ID_DP,
  1101. QDF_TRACE_LEVEL_FATAL,
  1102. "%s:the pool %d has been freed",
  1103. __func__,
  1104. pool_id);
  1105. goto warn_exit;
  1106. }
  1107. page_id = (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  1108. DP_TX_DESC_ID_PAGE_OS;
  1109. /* the page id is out of limit */
  1110. if (page_id >= pool->desc_pages.num_pages) {
  1111. QDF_TRACE(QDF_MODULE_ID_DP,
  1112. QDF_TRACE_LEVEL_FATAL,
  1113. "%s:the page id %d invalid, pool id %d, num_page %d",
  1114. __func__,
  1115. page_id,
  1116. pool_id,
  1117. pool->desc_pages.num_pages);
  1118. goto warn_exit;
  1119. }
  1120. offset = (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  1121. DP_TX_DESC_ID_OFFSET_OS;
  1122. /* the offset is out of limit */
  1123. if (offset >= pool->desc_pages.num_element_per_page) {
  1124. QDF_TRACE(QDF_MODULE_ID_DP,
  1125. QDF_TRACE_LEVEL_FATAL,
  1126. "%s:offset %d invalid, pool%d,num_elem_per_page %d",
  1127. __func__,
  1128. offset,
  1129. pool_id,
  1130. pool->desc_pages.num_element_per_page);
  1131. goto warn_exit;
  1132. }
  1133. return true;
  1134. warn_exit:
  1135. QDF_TRACE(QDF_MODULE_ID_DP,
  1136. QDF_TRACE_LEVEL_FATAL,
  1137. "%s:Tx desc id 0x%x not valid",
  1138. __func__,
  1139. tx_desc_id);
  1140. qdf_assert_always(0);
  1141. return false;
  1142. }
  1143. #else
  1144. static inline bool
  1145. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  1146. {
  1147. return true;
  1148. }
  1149. #endif /* QCA_DP_TX_DESC_ID_CHECK */
  1150. #ifdef QCA_DP_TX_DESC_FAST_COMP_ENABLE
  1151. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  1152. struct dp_tx_desc_s *desc,
  1153. uint8_t allow_fast_comp)
  1154. {
  1155. if (qdf_likely(!(desc->flags & DP_TX_DESC_FLAG_TO_FW)) &&
  1156. qdf_likely(allow_fast_comp))
  1157. desc->flags |= DP_TX_DESC_FLAG_SIMPLE;
  1158. if (qdf_likely(desc->nbuf->is_from_recycler) &&
  1159. qdf_likely(desc->nbuf->fast_xmit))
  1160. desc->flags |= DP_TX_DESC_FLAG_FAST;
  1161. }
  1162. #else
  1163. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  1164. struct dp_tx_desc_s *desc,
  1165. uint8_t allow_fast_comp)
  1166. {
  1167. }
  1168. #endif /* QCA_DP_TX_DESC_FAST_COMP_ENABLE */
  1169. /**
  1170. * dp_tx_desc_find() - find dp tx descriptor from pool/page/offset
  1171. * @soc: handle for the device sending the data
  1172. * @pool_id: pool id
  1173. * @page_id: page id
  1174. * @offset: offset from base address
  1175. * @spcl_pool: bit to indicate if this is a special pool
  1176. *
  1177. * Use page and offset to find the corresponding descriptor object in
  1178. * the given descriptor pool.
  1179. *
  1180. * Return: the descriptor object that has the specified ID
  1181. */
  1182. static inline
  1183. struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  1184. uint8_t pool_id, uint16_t page_id,
  1185. uint16_t offset, bool spcl_pool)
  1186. {
  1187. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  1188. tx_desc_pool = spcl_pool ? dp_get_spcl_tx_desc_pool(soc, pool_id) :
  1189. dp_get_tx_desc_pool(soc, pool_id);
  1190. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  1191. tx_desc_pool->elem_size * offset;
  1192. }
  1193. /**
  1194. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  1195. * @soc: handle for the device sending the data
  1196. * @desc_pool_id: target pool id
  1197. *
  1198. * Return: None
  1199. */
  1200. static inline
  1201. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  1202. uint8_t desc_pool_id)
  1203. {
  1204. struct dp_tx_ext_desc_elem_s *c_elem;
  1205. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1206. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1207. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  1208. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1209. return NULL;
  1210. }
  1211. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  1212. soc->tx_ext_desc[desc_pool_id].freelist =
  1213. soc->tx_ext_desc[desc_pool_id].freelist->next;
  1214. soc->tx_ext_desc[desc_pool_id].num_free--;
  1215. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1216. return c_elem;
  1217. }
  1218. /**
  1219. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  1220. * @soc: handle for the device sending the data
  1221. * @elem: ext descriptor pointer should release
  1222. * @desc_pool_id: target pool id
  1223. *
  1224. * Return: None
  1225. */
  1226. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  1227. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  1228. {
  1229. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1230. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1231. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  1232. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  1233. soc->tx_ext_desc[desc_pool_id].num_free++;
  1234. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1235. return;
  1236. }
  1237. /**
  1238. * dp_tx_ext_desc_free_multiple() - Free multiple tx extension descriptor and
  1239. * attach it to free list
  1240. * @soc: Handle to DP SoC structure
  1241. * @desc_pool_id: pool id should pick up
  1242. * @elem: tx descriptor should be freed
  1243. * @num_free: number of descriptors should be freed
  1244. *
  1245. * Return: none
  1246. */
  1247. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  1248. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  1249. uint8_t num_free)
  1250. {
  1251. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  1252. uint8_t freed = num_free;
  1253. /* caller should always guarantee atleast list of num_free nodes */
  1254. qdf_assert_always(elem);
  1255. head = elem;
  1256. c_elem = head;
  1257. tail = head;
  1258. while (c_elem && freed) {
  1259. tail = c_elem;
  1260. c_elem = c_elem->next;
  1261. freed--;
  1262. }
  1263. /* caller should always guarantee atleast list of num_free nodes */
  1264. qdf_assert_always(tail);
  1265. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1266. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1267. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  1268. soc->tx_ext_desc[desc_pool_id].freelist = head;
  1269. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  1270. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1271. return;
  1272. }
  1273. #if defined(FEATURE_TSO)
  1274. /**
  1275. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  1276. * @soc: device soc instance
  1277. * @pool_id: pool id should pick up tso descriptor
  1278. *
  1279. * Allocates a TSO segment element from the free list held in
  1280. * the soc
  1281. *
  1282. * Return: tso_seg, tso segment memory pointer
  1283. */
  1284. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  1285. struct dp_soc *soc, uint8_t pool_id)
  1286. {
  1287. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  1288. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  1289. if (soc->tx_tso_desc[pool_id].freelist) {
  1290. soc->tx_tso_desc[pool_id].num_free--;
  1291. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  1292. soc->tx_tso_desc[pool_id].freelist =
  1293. soc->tx_tso_desc[pool_id].freelist->next;
  1294. }
  1295. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  1296. return tso_seg;
  1297. }
  1298. /**
  1299. * dp_tx_tso_desc_free() - function to free a TSO segment
  1300. * @soc: device soc instance
  1301. * @pool_id: pool id should pick up tso descriptor
  1302. * @tso_seg: tso segment memory pointer
  1303. *
  1304. * Returns a TSO segment element to the free list held in the
  1305. * HTT pdev
  1306. *
  1307. * Return: none
  1308. */
  1309. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  1310. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  1311. {
  1312. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  1313. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  1314. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  1315. soc->tx_tso_desc[pool_id].num_free++;
  1316. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  1317. }
  1318. static inline
  1319. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  1320. uint8_t pool_id)
  1321. {
  1322. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  1323. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1324. if (soc->tx_tso_num_seg[pool_id].freelist) {
  1325. soc->tx_tso_num_seg[pool_id].num_free--;
  1326. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  1327. soc->tx_tso_num_seg[pool_id].freelist =
  1328. soc->tx_tso_num_seg[pool_id].freelist->next;
  1329. }
  1330. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1331. return tso_num_seg;
  1332. }
  1333. static inline
  1334. void dp_tso_num_seg_free(struct dp_soc *soc,
  1335. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  1336. {
  1337. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1338. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  1339. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  1340. soc->tx_tso_num_seg[pool_id].num_free++;
  1341. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1342. }
  1343. #endif
  1344. /**
  1345. * dp_tx_me_alloc_buf() - Alloc descriptor from me pool
  1346. * @pdev: DP_PDEV handle for datapath
  1347. *
  1348. * Return: tx descriptor on success, NULL on error
  1349. */
  1350. static inline struct dp_tx_me_buf_t*
  1351. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  1352. {
  1353. struct dp_tx_me_buf_t *buf = NULL;
  1354. qdf_spin_lock_bh(&pdev->tx_mutex);
  1355. if (pdev->me_buf.freelist) {
  1356. buf = pdev->me_buf.freelist;
  1357. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  1358. pdev->me_buf.buf_in_use++;
  1359. } else {
  1360. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1361. "Error allocating memory in pool");
  1362. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1363. return NULL;
  1364. }
  1365. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1366. return buf;
  1367. }
  1368. /**
  1369. * dp_tx_me_free_buf() - Unmap the buffer holding the dest
  1370. * address, free me descriptor and add it to the free-pool
  1371. * @pdev: DP_PDEV handle for datapath
  1372. * @buf : Allocated ME BUF
  1373. *
  1374. * Return:void
  1375. */
  1376. static inline void
  1377. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  1378. {
  1379. /*
  1380. * If the buf containing mac address was mapped,
  1381. * it must be unmapped before freeing the me_buf.
  1382. * The "paddr_macbuf" member in the me_buf structure
  1383. * holds the mapped physical address and it must be
  1384. * set to 0 after unmapping.
  1385. */
  1386. if (buf->paddr_macbuf) {
  1387. qdf_mem_unmap_nbytes_single(pdev->soc->osdev,
  1388. buf->paddr_macbuf,
  1389. QDF_DMA_TO_DEVICE,
  1390. QDF_MAC_ADDR_SIZE);
  1391. buf->paddr_macbuf = 0;
  1392. }
  1393. qdf_spin_lock_bh(&pdev->tx_mutex);
  1394. buf->next = pdev->me_buf.freelist;
  1395. pdev->me_buf.freelist = buf;
  1396. pdev->me_buf.buf_in_use--;
  1397. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1398. }
  1399. #endif /* DP_TX_DESC_H */