dp_tx_desc.h 31 KB

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