dp_tx_desc.h 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546
  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. }
  1158. }
  1159. #else
  1160. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  1161. struct dp_tx_desc_s *desc,
  1162. uint8_t allow_fast_comp)
  1163. {
  1164. }
  1165. #endif /* QCA_DP_TX_DESC_FAST_COMP_ENABLE */
  1166. /**
  1167. * dp_tx_desc_find() - find dp tx descriptor from pool/page/offset
  1168. * @soc: handle for the device sending the data
  1169. * @pool_id: pool id
  1170. * @page_id: page id
  1171. * @offset: offset from base address
  1172. * @spcl_pool: bit to indicate if this is a special pool
  1173. *
  1174. * Use page and offset to find the corresponding descriptor object in
  1175. * the given descriptor pool.
  1176. *
  1177. * Return: the descriptor object that has the specified ID
  1178. */
  1179. static inline
  1180. struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  1181. uint8_t pool_id, uint16_t page_id,
  1182. uint16_t offset, bool spcl_pool)
  1183. {
  1184. struct dp_tx_desc_pool_s *tx_desc_pool = NULL;
  1185. tx_desc_pool = spcl_pool ? dp_get_spcl_tx_desc_pool(soc, pool_id) :
  1186. dp_get_tx_desc_pool(soc, pool_id);
  1187. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  1188. tx_desc_pool->elem_size * offset;
  1189. }
  1190. /**
  1191. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  1192. * @soc: handle for the device sending the data
  1193. * @desc_pool_id: target pool id
  1194. *
  1195. * Return: None
  1196. */
  1197. static inline
  1198. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  1199. uint8_t desc_pool_id)
  1200. {
  1201. struct dp_tx_ext_desc_elem_s *c_elem;
  1202. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1203. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1204. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  1205. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1206. return NULL;
  1207. }
  1208. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  1209. soc->tx_ext_desc[desc_pool_id].freelist =
  1210. soc->tx_ext_desc[desc_pool_id].freelist->next;
  1211. soc->tx_ext_desc[desc_pool_id].num_free--;
  1212. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1213. return c_elem;
  1214. }
  1215. /**
  1216. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  1217. * @soc: handle for the device sending the data
  1218. * @elem: ext descriptor pointer should release
  1219. * @desc_pool_id: target pool id
  1220. *
  1221. * Return: None
  1222. */
  1223. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  1224. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  1225. {
  1226. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1227. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1228. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  1229. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  1230. soc->tx_ext_desc[desc_pool_id].num_free++;
  1231. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1232. return;
  1233. }
  1234. /**
  1235. * dp_tx_ext_desc_free_multiple() - Free multiple tx extension descriptor and
  1236. * attach it to free list
  1237. * @soc: Handle to DP SoC structure
  1238. * @desc_pool_id: pool id should pick up
  1239. * @elem: tx descriptor should be freed
  1240. * @num_free: number of descriptors should be freed
  1241. *
  1242. * Return: none
  1243. */
  1244. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  1245. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  1246. uint8_t num_free)
  1247. {
  1248. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  1249. uint8_t freed = num_free;
  1250. /* caller should always guarantee atleast list of num_free nodes */
  1251. qdf_assert_always(elem);
  1252. head = elem;
  1253. c_elem = head;
  1254. tail = head;
  1255. while (c_elem && freed) {
  1256. tail = c_elem;
  1257. c_elem = c_elem->next;
  1258. freed--;
  1259. }
  1260. /* caller should always guarantee atleast list of num_free nodes */
  1261. qdf_assert_always(tail);
  1262. desc_pool_id = dp_tx_ext_desc_pool_override(desc_pool_id);
  1263. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1264. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  1265. soc->tx_ext_desc[desc_pool_id].freelist = head;
  1266. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  1267. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  1268. return;
  1269. }
  1270. #if defined(FEATURE_TSO)
  1271. /**
  1272. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  1273. * @soc: device soc instance
  1274. * @pool_id: pool id should pick up tso descriptor
  1275. *
  1276. * Allocates a TSO segment element from the free list held in
  1277. * the soc
  1278. *
  1279. * Return: tso_seg, tso segment memory pointer
  1280. */
  1281. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  1282. struct dp_soc *soc, uint8_t pool_id)
  1283. {
  1284. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  1285. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  1286. if (soc->tx_tso_desc[pool_id].freelist) {
  1287. soc->tx_tso_desc[pool_id].num_free--;
  1288. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  1289. soc->tx_tso_desc[pool_id].freelist =
  1290. soc->tx_tso_desc[pool_id].freelist->next;
  1291. }
  1292. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  1293. return tso_seg;
  1294. }
  1295. /**
  1296. * dp_tx_tso_desc_free() - function to free a TSO segment
  1297. * @soc: device soc instance
  1298. * @pool_id: pool id should pick up tso descriptor
  1299. * @tso_seg: tso segment memory pointer
  1300. *
  1301. * Returns a TSO segment element to the free list held in the
  1302. * HTT pdev
  1303. *
  1304. * Return: none
  1305. */
  1306. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  1307. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  1308. {
  1309. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  1310. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  1311. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  1312. soc->tx_tso_desc[pool_id].num_free++;
  1313. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  1314. }
  1315. static inline
  1316. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  1317. uint8_t pool_id)
  1318. {
  1319. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  1320. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1321. if (soc->tx_tso_num_seg[pool_id].freelist) {
  1322. soc->tx_tso_num_seg[pool_id].num_free--;
  1323. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  1324. soc->tx_tso_num_seg[pool_id].freelist =
  1325. soc->tx_tso_num_seg[pool_id].freelist->next;
  1326. }
  1327. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1328. return tso_num_seg;
  1329. }
  1330. static inline
  1331. void dp_tso_num_seg_free(struct dp_soc *soc,
  1332. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  1333. {
  1334. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1335. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  1336. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  1337. soc->tx_tso_num_seg[pool_id].num_free++;
  1338. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  1339. }
  1340. #endif
  1341. /**
  1342. * dp_tx_me_alloc_buf() - Alloc descriptor from me pool
  1343. * @pdev: DP_PDEV handle for datapath
  1344. *
  1345. * Return: tx descriptor on success, NULL on error
  1346. */
  1347. static inline struct dp_tx_me_buf_t*
  1348. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  1349. {
  1350. struct dp_tx_me_buf_t *buf = NULL;
  1351. qdf_spin_lock_bh(&pdev->tx_mutex);
  1352. if (pdev->me_buf.freelist) {
  1353. buf = pdev->me_buf.freelist;
  1354. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  1355. pdev->me_buf.buf_in_use++;
  1356. } else {
  1357. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1358. "Error allocating memory in pool");
  1359. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1360. return NULL;
  1361. }
  1362. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1363. return buf;
  1364. }
  1365. /**
  1366. * dp_tx_me_free_buf() - Unmap the buffer holding the dest
  1367. * address, free me descriptor and add it to the free-pool
  1368. * @pdev: DP_PDEV handle for datapath
  1369. * @buf : Allocated ME BUF
  1370. *
  1371. * Return:void
  1372. */
  1373. static inline void
  1374. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  1375. {
  1376. /*
  1377. * If the buf containing mac address was mapped,
  1378. * it must be unmapped before freeing the me_buf.
  1379. * The "paddr_macbuf" member in the me_buf structure
  1380. * holds the mapped physical address and it must be
  1381. * set to 0 after unmapping.
  1382. */
  1383. if (buf->paddr_macbuf) {
  1384. qdf_mem_unmap_nbytes_single(pdev->soc->osdev,
  1385. buf->paddr_macbuf,
  1386. QDF_DMA_TO_DEVICE,
  1387. QDF_MAC_ADDR_SIZE);
  1388. buf->paddr_macbuf = 0;
  1389. }
  1390. qdf_spin_lock_bh(&pdev->tx_mutex);
  1391. buf->next = pdev->me_buf.freelist;
  1392. pdev->me_buf.freelist = buf;
  1393. pdev->me_buf.buf_in_use--;
  1394. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1395. }
  1396. #endif /* DP_TX_DESC_H */