dp_tx_desc.h 43 KB

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