dp_tx_desc.h 31 KB

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