dp_tx_desc.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114
  1. /*
  2. * Copyright (c) 2016-2021 The Linux Foundation. All rights reserved.
  3. * Copyright (c) 2021-2022 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. #define DP_TX_DESC_ID_POOL_MASK 0x018000
  32. #define DP_TX_DESC_ID_POOL_OS 15
  33. #define DP_TX_DESC_ID_PAGE_MASK 0x007FE0
  34. #define DP_TX_DESC_ID_PAGE_OS 5
  35. #define DP_TX_DESC_ID_OFFSET_MASK 0x00001F
  36. #define DP_TX_DESC_ID_OFFSET_OS 0
  37. /**
  38. * Compilation assert on tx desc size
  39. *
  40. * if assert is hit please update POOL_MASK,
  41. * PAGE_MASK according to updated size
  42. *
  43. * for current PAGE mask allowed size range of tx_desc
  44. * is between 128 and 256
  45. */
  46. QDF_COMPILE_TIME_ASSERT(dp_tx_desc_size,
  47. ((sizeof(struct dp_tx_desc_s)) <=
  48. (DP_BLOCKMEM_SIZE >> DP_TX_DESC_ID_PAGE_OS)) &&
  49. ((sizeof(struct dp_tx_desc_s)) >
  50. (DP_BLOCKMEM_SIZE >> (DP_TX_DESC_ID_PAGE_OS + 1)))
  51. );
  52. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  53. #define TX_DESC_LOCK_CREATE(lock)
  54. #define TX_DESC_LOCK_DESTROY(lock)
  55. #define TX_DESC_LOCK_LOCK(lock)
  56. #define TX_DESC_LOCK_UNLOCK(lock)
  57. #define IS_TX_DESC_POOL_STATUS_INACTIVE(pool) \
  58. ((pool)->status == FLOW_POOL_INACTIVE)
  59. #ifdef QCA_AC_BASED_FLOW_CONTROL
  60. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  61. dp_tx_flow_pool_member_clean(_tx_desc_pool)
  62. #else /* !QCA_AC_BASED_FLOW_CONTROL */
  63. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  64. do { \
  65. (_tx_desc_pool)->elem_size = 0; \
  66. (_tx_desc_pool)->freelist = NULL; \
  67. (_tx_desc_pool)->pool_size = 0; \
  68. (_tx_desc_pool)->avail_desc = 0; \
  69. (_tx_desc_pool)->start_th = 0; \
  70. (_tx_desc_pool)->stop_th = 0; \
  71. (_tx_desc_pool)->status = FLOW_POOL_INACTIVE; \
  72. } while (0)
  73. #endif /* QCA_AC_BASED_FLOW_CONTROL */
  74. #else /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  75. #define TX_DESC_LOCK_CREATE(lock) qdf_spinlock_create(lock)
  76. #define TX_DESC_LOCK_DESTROY(lock) qdf_spinlock_destroy(lock)
  77. #define TX_DESC_LOCK_LOCK(lock) qdf_spin_lock_bh(lock)
  78. #define TX_DESC_LOCK_UNLOCK(lock) qdf_spin_unlock_bh(lock)
  79. #define IS_TX_DESC_POOL_STATUS_INACTIVE(pool) (false)
  80. #define TX_DESC_POOL_MEMBER_CLEAN(_tx_desc_pool) \
  81. do { \
  82. (_tx_desc_pool)->elem_size = 0; \
  83. (_tx_desc_pool)->num_allocated = 0; \
  84. (_tx_desc_pool)->freelist = NULL; \
  85. (_tx_desc_pool)->elem_count = 0; \
  86. (_tx_desc_pool)->num_free = 0; \
  87. } while (0)
  88. #endif /* !QCA_LL_TX_FLOW_CONTROL_V2 */
  89. #define MAX_POOL_BUFF_COUNT 10000
  90. #ifdef DP_TX_TRACKING
  91. static inline void dp_tx_desc_set_magic(struct dp_tx_desc_s *tx_desc,
  92. uint32_t magic_pattern)
  93. {
  94. tx_desc->magic = magic_pattern;
  95. }
  96. #else
  97. static inline void dp_tx_desc_set_magic(struct dp_tx_desc_s *tx_desc,
  98. uint32_t magic_pattern)
  99. {
  100. }
  101. #endif
  102. QDF_STATUS dp_tx_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  103. uint32_t num_elem);
  104. QDF_STATUS dp_tx_desc_pool_init(struct dp_soc *soc, uint8_t pool_id,
  105. uint32_t num_elem);
  106. void dp_tx_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  107. void dp_tx_desc_pool_deinit(struct dp_soc *soc, uint8_t pool_id);
  108. QDF_STATUS dp_tx_ext_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  109. uint32_t num_elem);
  110. QDF_STATUS dp_tx_ext_desc_pool_init(struct dp_soc *soc, uint8_t pool_id,
  111. uint32_t num_elem);
  112. void dp_tx_ext_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  113. void dp_tx_ext_desc_pool_deinit(struct dp_soc *soc, uint8_t pool_id);
  114. QDF_STATUS dp_tx_tso_desc_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  115. uint32_t num_elem);
  116. QDF_STATUS dp_tx_tso_desc_pool_init(struct dp_soc *soc, uint8_t pool_id,
  117. uint32_t num_elem);
  118. void dp_tx_tso_desc_pool_free(struct dp_soc *soc, uint8_t pool_id);
  119. void dp_tx_tso_desc_pool_deinit(struct dp_soc *soc, uint8_t pool_id);
  120. QDF_STATUS dp_tx_tso_num_seg_pool_alloc(struct dp_soc *soc, uint8_t pool_id,
  121. uint32_t num_elem);
  122. QDF_STATUS dp_tx_tso_num_seg_pool_init(struct dp_soc *soc, uint8_t pool_id,
  123. uint32_t num_elem);
  124. void dp_tx_tso_num_seg_pool_free(struct dp_soc *soc, uint8_t pool_id);
  125. void dp_tx_tso_num_seg_pool_deinit(struct dp_soc *soc, uint8_t pool_id);
  126. #ifdef DP_UMAC_HW_RESET_SUPPORT
  127. void dp_tx_desc_pool_cleanup(struct dp_soc *soc, qdf_nbuf_t *nbuf_list);
  128. #endif
  129. #ifdef QCA_LL_TX_FLOW_CONTROL_V2
  130. void dp_tx_flow_control_init(struct dp_soc *);
  131. void dp_tx_flow_control_deinit(struct dp_soc *);
  132. QDF_STATUS dp_txrx_register_pause_cb(struct cdp_soc_t *soc,
  133. tx_pause_callback pause_cb);
  134. QDF_STATUS dp_tx_flow_pool_map(struct cdp_soc_t *soc, uint8_t pdev_id,
  135. uint8_t vdev_id);
  136. void dp_tx_flow_pool_unmap(struct cdp_soc_t *handle, uint8_t pdev_id,
  137. uint8_t vdev_id);
  138. void dp_tx_clear_flow_pool_stats(struct dp_soc *soc);
  139. struct dp_tx_desc_pool_s *dp_tx_create_flow_pool(struct dp_soc *soc,
  140. uint8_t flow_pool_id, uint32_t flow_pool_size);
  141. QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev, uint8_t flow_id,
  142. uint8_t flow_type, uint8_t flow_pool_id, uint32_t flow_pool_size);
  143. void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev, uint8_t flow_id,
  144. uint8_t flow_type, uint8_t flow_pool_id);
  145. /**
  146. * dp_tx_get_desc_flow_pool() - get descriptor from flow pool
  147. * @pool: flow pool
  148. *
  149. * Caller needs to take lock and do sanity checks.
  150. *
  151. * Return: tx descriptor
  152. */
  153. static inline
  154. struct dp_tx_desc_s *dp_tx_get_desc_flow_pool(struct dp_tx_desc_pool_s *pool)
  155. {
  156. struct dp_tx_desc_s *tx_desc = pool->freelist;
  157. pool->freelist = pool->freelist->next;
  158. pool->avail_desc--;
  159. return tx_desc;
  160. }
  161. /**
  162. * ol_tx_put_desc_flow_pool() - put descriptor to flow pool freelist
  163. * @pool: flow pool
  164. * @tx_desc: tx descriptor
  165. *
  166. * Caller needs to take lock and do sanity checks.
  167. *
  168. * Return: none
  169. */
  170. static inline
  171. void dp_tx_put_desc_flow_pool(struct dp_tx_desc_pool_s *pool,
  172. struct dp_tx_desc_s *tx_desc)
  173. {
  174. tx_desc->next = pool->freelist;
  175. pool->freelist = tx_desc;
  176. pool->avail_desc++;
  177. }
  178. #ifdef QCA_AC_BASED_FLOW_CONTROL
  179. /**
  180. * dp_tx_flow_pool_member_clean() - Clean the members of TX flow pool
  181. *
  182. * @pool: flow pool
  183. *
  184. * Return: None
  185. */
  186. static inline void
  187. dp_tx_flow_pool_member_clean(struct dp_tx_desc_pool_s *pool)
  188. {
  189. pool->elem_size = 0;
  190. pool->freelist = NULL;
  191. pool->pool_size = 0;
  192. pool->avail_desc = 0;
  193. qdf_mem_zero(pool->start_th, FL_TH_MAX);
  194. qdf_mem_zero(pool->stop_th, FL_TH_MAX);
  195. pool->status = FLOW_POOL_INACTIVE;
  196. }
  197. /**
  198. * dp_tx_is_threshold_reached() - Check if current avail desc meet threshold
  199. *
  200. * @pool: flow pool
  201. * @avail_desc: available descriptor number
  202. *
  203. * Return: true if threshold is met, false if not
  204. */
  205. static inline bool
  206. dp_tx_is_threshold_reached(struct dp_tx_desc_pool_s *pool, uint16_t avail_desc)
  207. {
  208. if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_BE_BK]))
  209. return true;
  210. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_VI]))
  211. return true;
  212. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_VO]))
  213. return true;
  214. else if (qdf_unlikely(avail_desc == pool->stop_th[DP_TH_HI]))
  215. return true;
  216. else
  217. return false;
  218. }
  219. /**
  220. * dp_tx_adjust_flow_pool_state() - Adjust flow pool state
  221. *
  222. * @soc: dp soc
  223. * @pool: flow pool
  224. */
  225. static inline void
  226. dp_tx_adjust_flow_pool_state(struct dp_soc *soc,
  227. struct dp_tx_desc_pool_s *pool)
  228. {
  229. if (pool->avail_desc > pool->stop_th[DP_TH_BE_BK]) {
  230. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  231. return;
  232. } else if (pool->avail_desc <= pool->stop_th[DP_TH_BE_BK] &&
  233. pool->avail_desc > pool->stop_th[DP_TH_VI]) {
  234. pool->status = FLOW_POOL_BE_BK_PAUSED;
  235. } else if (pool->avail_desc <= pool->stop_th[DP_TH_VI] &&
  236. pool->avail_desc > pool->stop_th[DP_TH_VO]) {
  237. pool->status = FLOW_POOL_VI_PAUSED;
  238. } else if (pool->avail_desc <= pool->stop_th[DP_TH_VO] &&
  239. pool->avail_desc > pool->stop_th[DP_TH_HI]) {
  240. pool->status = FLOW_POOL_VO_PAUSED;
  241. } else if (pool->avail_desc <= pool->stop_th[DP_TH_HI]) {
  242. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  243. }
  244. switch (pool->status) {
  245. case FLOW_POOL_ACTIVE_PAUSED:
  246. soc->pause_cb(pool->flow_pool_id,
  247. WLAN_NETIF_PRIORITY_QUEUE_OFF,
  248. WLAN_DATA_FLOW_CTRL_PRI);
  249. fallthrough;
  250. case FLOW_POOL_VO_PAUSED:
  251. soc->pause_cb(pool->flow_pool_id,
  252. WLAN_NETIF_VO_QUEUE_OFF,
  253. WLAN_DATA_FLOW_CTRL_VO);
  254. fallthrough;
  255. case FLOW_POOL_VI_PAUSED:
  256. soc->pause_cb(pool->flow_pool_id,
  257. WLAN_NETIF_VI_QUEUE_OFF,
  258. WLAN_DATA_FLOW_CTRL_VI);
  259. fallthrough;
  260. case FLOW_POOL_BE_BK_PAUSED:
  261. soc->pause_cb(pool->flow_pool_id,
  262. WLAN_NETIF_BE_BK_QUEUE_OFF,
  263. WLAN_DATA_FLOW_CTRL_BE_BK);
  264. break;
  265. default:
  266. dp_err("Invalid pool staus:%u to adjust", pool->status);
  267. }
  268. }
  269. /**
  270. * dp_tx_desc_alloc() - Allocate a Software Tx descriptor from given pool
  271. *
  272. * @soc: Handle to DP SoC structure
  273. * @desc_pool_id: ID of the flow control fool
  274. *
  275. * Return: TX descriptor allocated or NULL
  276. */
  277. static inline struct dp_tx_desc_s *
  278. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  279. {
  280. struct dp_tx_desc_s *tx_desc = NULL;
  281. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  282. bool is_pause = false;
  283. enum netif_action_type act = WLAN_NETIF_ACTION_TYPE_NONE;
  284. enum dp_fl_ctrl_threshold level = DP_TH_BE_BK;
  285. enum netif_reason_type reason;
  286. if (qdf_likely(pool)) {
  287. qdf_spin_lock_bh(&pool->flow_pool_lock);
  288. if (qdf_likely(pool->avail_desc &&
  289. pool->status != FLOW_POOL_INVALID &&
  290. pool->status != FLOW_POOL_INACTIVE)) {
  291. tx_desc = dp_tx_get_desc_flow_pool(pool);
  292. tx_desc->pool_id = desc_pool_id;
  293. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  294. dp_tx_desc_set_magic(tx_desc,
  295. DP_TX_MAGIC_PATTERN_INUSE);
  296. is_pause = dp_tx_is_threshold_reached(pool,
  297. pool->avail_desc);
  298. if (qdf_unlikely(pool->status ==
  299. FLOW_POOL_ACTIVE_UNPAUSED_REATTACH)) {
  300. dp_tx_adjust_flow_pool_state(soc, pool);
  301. is_pause = false;
  302. }
  303. if (qdf_unlikely(is_pause)) {
  304. switch (pool->status) {
  305. case FLOW_POOL_ACTIVE_UNPAUSED:
  306. /* pause network BE\BK queue */
  307. act = WLAN_NETIF_BE_BK_QUEUE_OFF;
  308. reason = WLAN_DATA_FLOW_CTRL_BE_BK;
  309. level = DP_TH_BE_BK;
  310. pool->status = FLOW_POOL_BE_BK_PAUSED;
  311. break;
  312. case FLOW_POOL_BE_BK_PAUSED:
  313. /* pause network VI queue */
  314. act = WLAN_NETIF_VI_QUEUE_OFF;
  315. reason = WLAN_DATA_FLOW_CTRL_VI;
  316. level = DP_TH_VI;
  317. pool->status = FLOW_POOL_VI_PAUSED;
  318. break;
  319. case FLOW_POOL_VI_PAUSED:
  320. /* pause network VO queue */
  321. act = WLAN_NETIF_VO_QUEUE_OFF;
  322. reason = WLAN_DATA_FLOW_CTRL_VO;
  323. level = DP_TH_VO;
  324. pool->status = FLOW_POOL_VO_PAUSED;
  325. break;
  326. case FLOW_POOL_VO_PAUSED:
  327. /* pause network HI PRI queue */
  328. act = WLAN_NETIF_PRIORITY_QUEUE_OFF;
  329. reason = WLAN_DATA_FLOW_CTRL_PRI;
  330. level = DP_TH_HI;
  331. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  332. break;
  333. case FLOW_POOL_ACTIVE_PAUSED:
  334. act = WLAN_NETIF_ACTION_TYPE_NONE;
  335. break;
  336. default:
  337. dp_err_rl("pool status is %d!",
  338. pool->status);
  339. break;
  340. }
  341. if (act != WLAN_NETIF_ACTION_TYPE_NONE) {
  342. pool->latest_pause_time[level] =
  343. qdf_get_system_timestamp();
  344. soc->pause_cb(desc_pool_id,
  345. act,
  346. reason);
  347. }
  348. }
  349. } else {
  350. pool->pkt_drop_no_desc++;
  351. }
  352. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  353. } else {
  354. soc->pool_stats.pkt_drop_no_pool++;
  355. }
  356. return tx_desc;
  357. }
  358. /**
  359. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  360. *
  361. * @soc: Handle to DP SoC structure
  362. * @tx_desc: the tx descriptor to be freed
  363. * @desc_pool_id: ID of the flow control fool
  364. *
  365. * Return: None
  366. */
  367. static inline void
  368. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  369. uint8_t desc_pool_id)
  370. {
  371. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  372. qdf_time_t unpause_time = qdf_get_system_timestamp(), pause_dur;
  373. enum netif_action_type act = WLAN_WAKE_ALL_NETIF_QUEUE;
  374. enum netif_reason_type reason;
  375. qdf_spin_lock_bh(&pool->flow_pool_lock);
  376. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  377. tx_desc->nbuf = NULL;
  378. tx_desc->flags = 0;
  379. dp_tx_desc_set_magic(tx_desc, DP_TX_MAGIC_PATTERN_FREE);
  380. dp_tx_put_desc_flow_pool(pool, tx_desc);
  381. switch (pool->status) {
  382. case FLOW_POOL_ACTIVE_PAUSED:
  383. if (pool->avail_desc > pool->start_th[DP_TH_HI]) {
  384. act = WLAN_NETIF_PRIORITY_QUEUE_ON;
  385. reason = WLAN_DATA_FLOW_CTRL_PRI;
  386. pool->status = FLOW_POOL_VO_PAUSED;
  387. /* Update maxinum pause duration for HI queue */
  388. pause_dur = unpause_time -
  389. pool->latest_pause_time[DP_TH_HI];
  390. if (pool->max_pause_time[DP_TH_HI] < pause_dur)
  391. pool->max_pause_time[DP_TH_HI] = pause_dur;
  392. }
  393. break;
  394. case FLOW_POOL_VO_PAUSED:
  395. if (pool->avail_desc > pool->start_th[DP_TH_VO]) {
  396. act = WLAN_NETIF_VO_QUEUE_ON;
  397. reason = WLAN_DATA_FLOW_CTRL_VO;
  398. pool->status = FLOW_POOL_VI_PAUSED;
  399. /* Update maxinum pause duration for VO queue */
  400. pause_dur = unpause_time -
  401. pool->latest_pause_time[DP_TH_VO];
  402. if (pool->max_pause_time[DP_TH_VO] < pause_dur)
  403. pool->max_pause_time[DP_TH_VO] = pause_dur;
  404. }
  405. break;
  406. case FLOW_POOL_VI_PAUSED:
  407. if (pool->avail_desc > pool->start_th[DP_TH_VI]) {
  408. act = WLAN_NETIF_VI_QUEUE_ON;
  409. reason = WLAN_DATA_FLOW_CTRL_VI;
  410. pool->status = FLOW_POOL_BE_BK_PAUSED;
  411. /* Update maxinum pause duration for VI queue */
  412. pause_dur = unpause_time -
  413. pool->latest_pause_time[DP_TH_VI];
  414. if (pool->max_pause_time[DP_TH_VI] < pause_dur)
  415. pool->max_pause_time[DP_TH_VI] = pause_dur;
  416. }
  417. break;
  418. case FLOW_POOL_BE_BK_PAUSED:
  419. if (pool->avail_desc > pool->start_th[DP_TH_BE_BK]) {
  420. act = WLAN_NETIF_BE_BK_QUEUE_ON;
  421. reason = WLAN_DATA_FLOW_CTRL_BE_BK;
  422. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  423. /* Update maxinum pause duration for BE_BK queue */
  424. pause_dur = unpause_time -
  425. pool->latest_pause_time[DP_TH_BE_BK];
  426. if (pool->max_pause_time[DP_TH_BE_BK] < pause_dur)
  427. pool->max_pause_time[DP_TH_BE_BK] = pause_dur;
  428. }
  429. break;
  430. case FLOW_POOL_INVALID:
  431. if (pool->avail_desc == pool->pool_size) {
  432. dp_tx_desc_pool_deinit(soc, desc_pool_id);
  433. dp_tx_desc_pool_free(soc, desc_pool_id);
  434. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  435. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  436. "%s %d pool is freed!!",
  437. __func__, __LINE__);
  438. return;
  439. }
  440. break;
  441. case FLOW_POOL_ACTIVE_UNPAUSED:
  442. break;
  443. default:
  444. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  445. "%s %d pool is INACTIVE State!!",
  446. __func__, __LINE__);
  447. break;
  448. };
  449. if (act != WLAN_WAKE_ALL_NETIF_QUEUE)
  450. soc->pause_cb(pool->flow_pool_id,
  451. act, reason);
  452. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  453. }
  454. #else /* QCA_AC_BASED_FLOW_CONTROL */
  455. static inline bool
  456. dp_tx_is_threshold_reached(struct dp_tx_desc_pool_s *pool, uint16_t avail_desc)
  457. {
  458. if (qdf_unlikely(avail_desc < pool->stop_th))
  459. return true;
  460. else
  461. return false;
  462. }
  463. /**
  464. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  465. *
  466. * @soc Handle to DP SoC structure
  467. * @pool_id
  468. *
  469. * Return:
  470. */
  471. static inline struct dp_tx_desc_s *
  472. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  473. {
  474. struct dp_tx_desc_s *tx_desc = NULL;
  475. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  476. if (pool) {
  477. qdf_spin_lock_bh(&pool->flow_pool_lock);
  478. if (pool->status <= FLOW_POOL_ACTIVE_PAUSED &&
  479. pool->avail_desc) {
  480. tx_desc = dp_tx_get_desc_flow_pool(pool);
  481. tx_desc->pool_id = desc_pool_id;
  482. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  483. dp_tx_desc_set_magic(tx_desc,
  484. DP_TX_MAGIC_PATTERN_INUSE);
  485. if (qdf_unlikely(pool->avail_desc < pool->stop_th)) {
  486. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  487. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  488. /* pause network queues */
  489. soc->pause_cb(desc_pool_id,
  490. WLAN_STOP_ALL_NETIF_QUEUE,
  491. WLAN_DATA_FLOW_CONTROL);
  492. } else {
  493. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  494. }
  495. } else {
  496. pool->pkt_drop_no_desc++;
  497. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  498. }
  499. } else {
  500. soc->pool_stats.pkt_drop_no_pool++;
  501. }
  502. return tx_desc;
  503. }
  504. /**
  505. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  506. *
  507. * @soc Handle to DP SoC structure
  508. * @pool_id
  509. * @tx_desc
  510. *
  511. * Return: None
  512. */
  513. static inline void
  514. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  515. uint8_t desc_pool_id)
  516. {
  517. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  518. qdf_spin_lock_bh(&pool->flow_pool_lock);
  519. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  520. tx_desc->nbuf = NULL;
  521. tx_desc->flags = 0;
  522. dp_tx_desc_set_magic(tx_desc, DP_TX_MAGIC_PATTERN_FREE);
  523. dp_tx_put_desc_flow_pool(pool, tx_desc);
  524. switch (pool->status) {
  525. case FLOW_POOL_ACTIVE_PAUSED:
  526. if (pool->avail_desc > pool->start_th) {
  527. soc->pause_cb(pool->flow_pool_id,
  528. WLAN_WAKE_ALL_NETIF_QUEUE,
  529. WLAN_DATA_FLOW_CONTROL);
  530. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  531. }
  532. break;
  533. case FLOW_POOL_INVALID:
  534. if (pool->avail_desc == pool->pool_size) {
  535. dp_tx_desc_pool_deinit(soc, desc_pool_id);
  536. dp_tx_desc_pool_free(soc, desc_pool_id);
  537. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  538. qdf_print("%s %d pool is freed!!",
  539. __func__, __LINE__);
  540. return;
  541. }
  542. break;
  543. case FLOW_POOL_ACTIVE_UNPAUSED:
  544. break;
  545. default:
  546. qdf_print("%s %d pool is INACTIVE State!!",
  547. __func__, __LINE__);
  548. break;
  549. };
  550. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  551. }
  552. #endif /* QCA_AC_BASED_FLOW_CONTROL */
  553. static inline bool
  554. dp_tx_desc_thresh_reached(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  555. {
  556. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  557. struct dp_vdev *vdev = dp_vdev_get_ref_by_id(soc, vdev_id,
  558. DP_MOD_ID_CDP);
  559. struct dp_tx_desc_pool_s *pool;
  560. bool status;
  561. if (!vdev)
  562. return false;
  563. pool = vdev->pool;
  564. status = dp_tx_is_threshold_reached(pool, pool->avail_desc);
  565. dp_vdev_unref_delete(soc, vdev, DP_MOD_ID_CDP);
  566. return status;
  567. }
  568. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  569. static inline void dp_tx_flow_control_init(struct dp_soc *handle)
  570. {
  571. }
  572. static inline void dp_tx_flow_control_deinit(struct dp_soc *handle)
  573. {
  574. }
  575. static inline QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev,
  576. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id,
  577. uint32_t flow_pool_size)
  578. {
  579. return QDF_STATUS_SUCCESS;
  580. }
  581. static inline void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev,
  582. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id)
  583. {
  584. }
  585. #ifdef QCA_DP_TX_HW_SW_NBUF_DESC_PREFETCH
  586. static inline
  587. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  588. {
  589. if (tx_desc)
  590. prefetch(tx_desc);
  591. }
  592. #else
  593. static inline
  594. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  595. {
  596. }
  597. #endif
  598. /**
  599. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  600. *
  601. * @param soc Handle to DP SoC structure
  602. * @param pool_id
  603. *
  604. * Return:
  605. */
  606. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  607. uint8_t desc_pool_id)
  608. {
  609. struct dp_tx_desc_s *tx_desc = NULL;
  610. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  611. TX_DESC_LOCK_LOCK(&pool->lock);
  612. tx_desc = pool->freelist;
  613. /* Pool is exhausted */
  614. if (!tx_desc) {
  615. TX_DESC_LOCK_UNLOCK(&pool->lock);
  616. return NULL;
  617. }
  618. pool->freelist = pool->freelist->next;
  619. pool->num_allocated++;
  620. pool->num_free--;
  621. dp_tx_prefetch_desc(pool->freelist);
  622. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  623. TX_DESC_LOCK_UNLOCK(&pool->lock);
  624. return tx_desc;
  625. }
  626. /**
  627. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  628. * from given pool
  629. * @soc: Handle to DP SoC structure
  630. * @pool_id: pool id should pick up
  631. * @num_requested: number of required descriptor
  632. *
  633. * allocate multiple tx descriptor and make a link
  634. *
  635. * Return: h_desc first descriptor pointer
  636. */
  637. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  638. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  639. {
  640. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  641. uint8_t count;
  642. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  643. TX_DESC_LOCK_LOCK(&pool->lock);
  644. if ((num_requested == 0) ||
  645. (pool->num_free < num_requested)) {
  646. TX_DESC_LOCK_UNLOCK(&pool->lock);
  647. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  648. "%s, No Free Desc: Available(%d) num_requested(%d)",
  649. __func__, pool->num_free,
  650. num_requested);
  651. return NULL;
  652. }
  653. h_desc = pool->freelist;
  654. /* h_desc should never be NULL since num_free > requested */
  655. qdf_assert_always(h_desc);
  656. c_desc = h_desc;
  657. for (count = 0; count < (num_requested - 1); count++) {
  658. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  659. c_desc = c_desc->next;
  660. }
  661. pool->num_free -= count;
  662. pool->num_allocated += count;
  663. pool->freelist = c_desc->next;
  664. c_desc->next = NULL;
  665. TX_DESC_LOCK_UNLOCK(&pool->lock);
  666. return h_desc;
  667. }
  668. /**
  669. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  670. *
  671. * @soc Handle to DP SoC structure
  672. * @pool_id
  673. * @tx_desc
  674. */
  675. static inline void
  676. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  677. uint8_t desc_pool_id)
  678. {
  679. struct dp_tx_desc_pool_s *pool = NULL;
  680. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  681. tx_desc->nbuf = NULL;
  682. tx_desc->flags = 0;
  683. pool = &soc->tx_desc[desc_pool_id];
  684. TX_DESC_LOCK_LOCK(&pool->lock);
  685. tx_desc->next = pool->freelist;
  686. pool->freelist = tx_desc;
  687. pool->num_allocated--;
  688. pool->num_free++;
  689. TX_DESC_LOCK_UNLOCK(&pool->lock);
  690. }
  691. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  692. #ifdef QCA_DP_TX_DESC_ID_CHECK
  693. /**
  694. * dp_tx_is_desc_id_valid() - check is the tx desc id valid
  695. *
  696. * @soc Handle to DP SoC structure
  697. * @tx_desc_id
  698. *
  699. * Return: true or false
  700. */
  701. static inline bool
  702. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  703. {
  704. uint8_t pool_id;
  705. uint16_t page_id, offset;
  706. struct dp_tx_desc_pool_s *pool;
  707. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  708. DP_TX_DESC_ID_POOL_OS;
  709. /* Pool ID is out of limit */
  710. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  711. soc->wlan_cfg_ctx)) {
  712. QDF_TRACE(QDF_MODULE_ID_DP,
  713. QDF_TRACE_LEVEL_FATAL,
  714. "%s:Tx Comp pool id %d not valid",
  715. __func__,
  716. pool_id);
  717. goto warn_exit;
  718. }
  719. pool = &soc->tx_desc[pool_id];
  720. /* the pool is freed */
  721. if (IS_TX_DESC_POOL_STATUS_INACTIVE(pool)) {
  722. QDF_TRACE(QDF_MODULE_ID_DP,
  723. QDF_TRACE_LEVEL_FATAL,
  724. "%s:the pool %d has been freed",
  725. __func__,
  726. pool_id);
  727. goto warn_exit;
  728. }
  729. page_id = (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  730. DP_TX_DESC_ID_PAGE_OS;
  731. /* the page id is out of limit */
  732. if (page_id >= pool->desc_pages.num_pages) {
  733. QDF_TRACE(QDF_MODULE_ID_DP,
  734. QDF_TRACE_LEVEL_FATAL,
  735. "%s:the page id %d invalid, pool id %d, num_page %d",
  736. __func__,
  737. page_id,
  738. pool_id,
  739. pool->desc_pages.num_pages);
  740. goto warn_exit;
  741. }
  742. offset = (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  743. DP_TX_DESC_ID_OFFSET_OS;
  744. /* the offset is out of limit */
  745. if (offset >= pool->desc_pages.num_element_per_page) {
  746. QDF_TRACE(QDF_MODULE_ID_DP,
  747. QDF_TRACE_LEVEL_FATAL,
  748. "%s:offset %d invalid, pool%d,num_elem_per_page %d",
  749. __func__,
  750. offset,
  751. pool_id,
  752. pool->desc_pages.num_element_per_page);
  753. goto warn_exit;
  754. }
  755. return true;
  756. warn_exit:
  757. QDF_TRACE(QDF_MODULE_ID_DP,
  758. QDF_TRACE_LEVEL_FATAL,
  759. "%s:Tx desc id 0x%x not valid",
  760. __func__,
  761. tx_desc_id);
  762. qdf_assert_always(0);
  763. return false;
  764. }
  765. #else
  766. static inline bool
  767. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  768. {
  769. return true;
  770. }
  771. #endif /* QCA_DP_TX_DESC_ID_CHECK */
  772. #ifdef QCA_DP_TX_DESC_FAST_COMP_ENABLE
  773. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  774. struct dp_tx_desc_s *desc,
  775. uint8_t allow_fast_comp)
  776. {
  777. if (qdf_likely(!(desc->flags & DP_TX_DESC_FLAG_TO_FW)) &&
  778. qdf_likely(allow_fast_comp)) {
  779. desc->flags |= DP_TX_DESC_FLAG_SIMPLE;
  780. }
  781. }
  782. #else
  783. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  784. struct dp_tx_desc_s *desc,
  785. uint8_t allow_fast_comp)
  786. {
  787. }
  788. #endif /* QCA_DP_TX_DESC_FAST_COMP_ENABLE */
  789. /**
  790. * dp_tx_desc_find() - find dp tx descriptor from cokie
  791. * @soc - handle for the device sending the data
  792. * @tx_desc_id - the ID of the descriptor in question
  793. * @return the descriptor object that has the specified ID
  794. *
  795. * Use a tx descriptor ID to find the corresponding descriptor object.
  796. *
  797. */
  798. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  799. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  800. {
  801. struct dp_tx_desc_pool_s *tx_desc_pool = &soc->tx_desc[pool_id];
  802. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  803. tx_desc_pool->elem_size * offset;
  804. }
  805. /**
  806. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  807. * @soc: handle for the device sending the data
  808. * @pool_id: target pool id
  809. *
  810. * Return: None
  811. */
  812. static inline
  813. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  814. uint8_t desc_pool_id)
  815. {
  816. struct dp_tx_ext_desc_elem_s *c_elem;
  817. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  818. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  819. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  820. return NULL;
  821. }
  822. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  823. soc->tx_ext_desc[desc_pool_id].freelist =
  824. soc->tx_ext_desc[desc_pool_id].freelist->next;
  825. soc->tx_ext_desc[desc_pool_id].num_free--;
  826. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  827. return c_elem;
  828. }
  829. /**
  830. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  831. * @soc: handle for the device sending the data
  832. * @pool_id: target pool id
  833. * @elem: ext descriptor pointer should release
  834. *
  835. * Return: None
  836. */
  837. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  838. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  839. {
  840. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  841. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  842. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  843. soc->tx_ext_desc[desc_pool_id].num_free++;
  844. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  845. return;
  846. }
  847. /**
  848. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  849. * attach it to free list
  850. * @soc: Handle to DP SoC structure
  851. * @desc_pool_id: pool id should pick up
  852. * @elem: tx descriptor should be freed
  853. * @num_free: number of descriptors should be freed
  854. *
  855. * Return: none
  856. */
  857. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  858. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  859. uint8_t num_free)
  860. {
  861. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  862. uint8_t freed = num_free;
  863. /* caller should always guarantee atleast list of num_free nodes */
  864. qdf_assert_always(elem);
  865. head = elem;
  866. c_elem = head;
  867. tail = head;
  868. while (c_elem && freed) {
  869. tail = c_elem;
  870. c_elem = c_elem->next;
  871. freed--;
  872. }
  873. /* caller should always guarantee atleast list of num_free nodes */
  874. qdf_assert_always(tail);
  875. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  876. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  877. soc->tx_ext_desc[desc_pool_id].freelist = head;
  878. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  879. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  880. return;
  881. }
  882. #if defined(FEATURE_TSO)
  883. /**
  884. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  885. * @soc: device soc instance
  886. * @pool_id: pool id should pick up tso descriptor
  887. *
  888. * Allocates a TSO segment element from the free list held in
  889. * the soc
  890. *
  891. * Return: tso_seg, tso segment memory pointer
  892. */
  893. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  894. struct dp_soc *soc, uint8_t pool_id)
  895. {
  896. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  897. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  898. if (soc->tx_tso_desc[pool_id].freelist) {
  899. soc->tx_tso_desc[pool_id].num_free--;
  900. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  901. soc->tx_tso_desc[pool_id].freelist =
  902. soc->tx_tso_desc[pool_id].freelist->next;
  903. }
  904. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  905. return tso_seg;
  906. }
  907. /**
  908. * dp_tx_tso_desc_free() - function to free a TSO segment
  909. * @soc: device soc instance
  910. * @pool_id: pool id should pick up tso descriptor
  911. * @tso_seg: tso segment memory pointer
  912. *
  913. * Returns a TSO segment element to the free list held in the
  914. * HTT pdev
  915. *
  916. * Return: none
  917. */
  918. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  919. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  920. {
  921. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  922. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  923. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  924. soc->tx_tso_desc[pool_id].num_free++;
  925. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  926. }
  927. static inline
  928. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  929. uint8_t pool_id)
  930. {
  931. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  932. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  933. if (soc->tx_tso_num_seg[pool_id].freelist) {
  934. soc->tx_tso_num_seg[pool_id].num_free--;
  935. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  936. soc->tx_tso_num_seg[pool_id].freelist =
  937. soc->tx_tso_num_seg[pool_id].freelist->next;
  938. }
  939. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  940. return tso_num_seg;
  941. }
  942. static inline
  943. void dp_tso_num_seg_free(struct dp_soc *soc,
  944. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  945. {
  946. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  947. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  948. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  949. soc->tx_tso_num_seg[pool_id].num_free++;
  950. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  951. }
  952. #endif
  953. /*
  954. * dp_tx_me_alloc_buf() Alloc descriptor from me pool
  955. * @pdev DP_PDEV handle for datapath
  956. *
  957. * Return:dp_tx_me_buf_t(buf)
  958. */
  959. static inline struct dp_tx_me_buf_t*
  960. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  961. {
  962. struct dp_tx_me_buf_t *buf = NULL;
  963. qdf_spin_lock_bh(&pdev->tx_mutex);
  964. if (pdev->me_buf.freelist) {
  965. buf = pdev->me_buf.freelist;
  966. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  967. pdev->me_buf.buf_in_use++;
  968. } else {
  969. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  970. "Error allocating memory in pool");
  971. qdf_spin_unlock_bh(&pdev->tx_mutex);
  972. return NULL;
  973. }
  974. qdf_spin_unlock_bh(&pdev->tx_mutex);
  975. return buf;
  976. }
  977. /*
  978. * dp_tx_me_free_buf() - Unmap the buffer holding the dest
  979. * address, free me descriptor and add it to the free-pool
  980. * @pdev: DP_PDEV handle for datapath
  981. * @buf : Allocated ME BUF
  982. *
  983. * Return:void
  984. */
  985. static inline void
  986. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  987. {
  988. /*
  989. * If the buf containing mac address was mapped,
  990. * it must be unmapped before freeing the me_buf.
  991. * The "paddr_macbuf" member in the me_buf structure
  992. * holds the mapped physical address and it must be
  993. * set to 0 after unmapping.
  994. */
  995. if (buf->paddr_macbuf) {
  996. qdf_mem_unmap_nbytes_single(pdev->soc->osdev,
  997. buf->paddr_macbuf,
  998. QDF_DMA_TO_DEVICE,
  999. QDF_MAC_ADDR_SIZE);
  1000. buf->paddr_macbuf = 0;
  1001. }
  1002. qdf_spin_lock_bh(&pdev->tx_mutex);
  1003. buf->next = pdev->me_buf.freelist;
  1004. pdev->me_buf.freelist = buf;
  1005. pdev->me_buf.buf_in_use--;
  1006. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1007. }
  1008. #endif /* DP_TX_DESC_H */