dp_tx_desc.h 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  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. #ifdef QCA_DP_TX_HW_SW_NBUF_DESC_PREFETCH
  581. static inline
  582. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  583. {
  584. if (tx_desc)
  585. prefetch(tx_desc);
  586. }
  587. #else
  588. static inline
  589. void dp_tx_prefetch_desc(struct dp_tx_desc_s *tx_desc)
  590. {
  591. }
  592. #endif
  593. /**
  594. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  595. *
  596. * @param soc Handle to DP SoC structure
  597. * @param pool_id
  598. *
  599. * Return:
  600. */
  601. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  602. uint8_t desc_pool_id)
  603. {
  604. struct dp_tx_desc_s *tx_desc = NULL;
  605. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  606. TX_DESC_LOCK_LOCK(&pool->lock);
  607. tx_desc = pool->freelist;
  608. /* Pool is exhausted */
  609. if (!tx_desc) {
  610. TX_DESC_LOCK_UNLOCK(&pool->lock);
  611. return NULL;
  612. }
  613. pool->freelist = pool->freelist->next;
  614. pool->num_allocated++;
  615. pool->num_free--;
  616. dp_tx_prefetch_desc(pool->freelist);
  617. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  618. TX_DESC_LOCK_UNLOCK(&pool->lock);
  619. return tx_desc;
  620. }
  621. /**
  622. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  623. * from given pool
  624. * @soc: Handle to DP SoC structure
  625. * @pool_id: pool id should pick up
  626. * @num_requested: number of required descriptor
  627. *
  628. * allocate multiple tx descriptor and make a link
  629. *
  630. * Return: h_desc first descriptor pointer
  631. */
  632. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  633. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  634. {
  635. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  636. uint8_t count;
  637. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  638. TX_DESC_LOCK_LOCK(&pool->lock);
  639. if ((num_requested == 0) ||
  640. (pool->num_free < num_requested)) {
  641. TX_DESC_LOCK_UNLOCK(&pool->lock);
  642. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  643. "%s, No Free Desc: Available(%d) num_requested(%d)",
  644. __func__, pool->num_free,
  645. num_requested);
  646. return NULL;
  647. }
  648. h_desc = pool->freelist;
  649. /* h_desc should never be NULL since num_free > requested */
  650. qdf_assert_always(h_desc);
  651. c_desc = h_desc;
  652. for (count = 0; count < (num_requested - 1); count++) {
  653. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  654. c_desc = c_desc->next;
  655. }
  656. pool->num_free -= count;
  657. pool->num_allocated += count;
  658. pool->freelist = c_desc->next;
  659. c_desc->next = NULL;
  660. TX_DESC_LOCK_UNLOCK(&pool->lock);
  661. return h_desc;
  662. }
  663. /**
  664. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  665. *
  666. * @soc Handle to DP SoC structure
  667. * @pool_id
  668. * @tx_desc
  669. */
  670. static inline void
  671. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  672. uint8_t desc_pool_id)
  673. {
  674. struct dp_tx_desc_pool_s *pool = NULL;
  675. tx_desc->vdev_id = DP_INVALID_VDEV_ID;
  676. tx_desc->nbuf = NULL;
  677. tx_desc->flags = 0;
  678. pool = &soc->tx_desc[desc_pool_id];
  679. TX_DESC_LOCK_LOCK(&pool->lock);
  680. tx_desc->next = pool->freelist;
  681. pool->freelist = tx_desc;
  682. pool->num_allocated--;
  683. pool->num_free++;
  684. TX_DESC_LOCK_UNLOCK(&pool->lock);
  685. }
  686. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  687. #ifdef QCA_DP_TX_DESC_ID_CHECK
  688. /**
  689. * dp_tx_is_desc_id_valid() - check is the tx desc id valid
  690. *
  691. * @soc Handle to DP SoC structure
  692. * @tx_desc_id
  693. *
  694. * Return: true or false
  695. */
  696. static inline bool
  697. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  698. {
  699. uint8_t pool_id;
  700. uint16_t page_id, offset;
  701. struct dp_tx_desc_pool_s *pool;
  702. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  703. DP_TX_DESC_ID_POOL_OS;
  704. /* Pool ID is out of limit */
  705. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  706. soc->wlan_cfg_ctx)) {
  707. QDF_TRACE(QDF_MODULE_ID_DP,
  708. QDF_TRACE_LEVEL_FATAL,
  709. "%s:Tx Comp pool id %d not valid",
  710. __func__,
  711. pool_id);
  712. goto warn_exit;
  713. }
  714. pool = &soc->tx_desc[pool_id];
  715. /* the pool is freed */
  716. if (IS_TX_DESC_POOL_STATUS_INACTIVE(pool)) {
  717. QDF_TRACE(QDF_MODULE_ID_DP,
  718. QDF_TRACE_LEVEL_FATAL,
  719. "%s:the pool %d has been freed",
  720. __func__,
  721. pool_id);
  722. goto warn_exit;
  723. }
  724. page_id = (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  725. DP_TX_DESC_ID_PAGE_OS;
  726. /* the page id is out of limit */
  727. if (page_id >= pool->desc_pages.num_pages) {
  728. QDF_TRACE(QDF_MODULE_ID_DP,
  729. QDF_TRACE_LEVEL_FATAL,
  730. "%s:the page id %d invalid, pool id %d, num_page %d",
  731. __func__,
  732. page_id,
  733. pool_id,
  734. pool->desc_pages.num_pages);
  735. goto warn_exit;
  736. }
  737. offset = (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  738. DP_TX_DESC_ID_OFFSET_OS;
  739. /* the offset is out of limit */
  740. if (offset >= pool->desc_pages.num_element_per_page) {
  741. QDF_TRACE(QDF_MODULE_ID_DP,
  742. QDF_TRACE_LEVEL_FATAL,
  743. "%s:offset %d invalid, pool%d,num_elem_per_page %d",
  744. __func__,
  745. offset,
  746. pool_id,
  747. pool->desc_pages.num_element_per_page);
  748. goto warn_exit;
  749. }
  750. return true;
  751. warn_exit:
  752. QDF_TRACE(QDF_MODULE_ID_DP,
  753. QDF_TRACE_LEVEL_FATAL,
  754. "%s:Tx desc id 0x%x not valid",
  755. __func__,
  756. tx_desc_id);
  757. qdf_assert_always(0);
  758. return false;
  759. }
  760. #else
  761. static inline bool
  762. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  763. {
  764. return true;
  765. }
  766. #endif /* QCA_DP_TX_DESC_ID_CHECK */
  767. #ifdef QCA_DP_TX_DESC_FAST_COMP_ENABLE
  768. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  769. struct dp_tx_desc_s *desc,
  770. uint8_t allow_fast_comp)
  771. {
  772. if (qdf_likely(!(desc->flags & DP_TX_DESC_FLAG_TO_FW)) &&
  773. qdf_likely(allow_fast_comp)) {
  774. desc->flags |= DP_TX_DESC_FLAG_SIMPLE;
  775. }
  776. }
  777. #else
  778. static inline void dp_tx_desc_update_fast_comp_flag(struct dp_soc *soc,
  779. struct dp_tx_desc_s *desc,
  780. uint8_t allow_fast_comp)
  781. {
  782. }
  783. #endif /* QCA_DP_TX_DESC_FAST_COMP_ENABLE */
  784. /**
  785. * dp_tx_desc_find() - find dp tx descriptor from cokie
  786. * @soc - handle for the device sending the data
  787. * @tx_desc_id - the ID of the descriptor in question
  788. * @return the descriptor object that has the specified ID
  789. *
  790. * Use a tx descriptor ID to find the corresponding descriptor object.
  791. *
  792. */
  793. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  794. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  795. {
  796. struct dp_tx_desc_pool_s *tx_desc_pool = &soc->tx_desc[pool_id];
  797. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  798. tx_desc_pool->elem_size * offset;
  799. }
  800. /**
  801. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  802. * @soc: handle for the device sending the data
  803. * @pool_id: target pool id
  804. *
  805. * Return: None
  806. */
  807. static inline
  808. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  809. uint8_t desc_pool_id)
  810. {
  811. struct dp_tx_ext_desc_elem_s *c_elem;
  812. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  813. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  814. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  815. return NULL;
  816. }
  817. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  818. soc->tx_ext_desc[desc_pool_id].freelist =
  819. soc->tx_ext_desc[desc_pool_id].freelist->next;
  820. soc->tx_ext_desc[desc_pool_id].num_free--;
  821. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  822. return c_elem;
  823. }
  824. /**
  825. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  826. * @soc: handle for the device sending the data
  827. * @pool_id: target pool id
  828. * @elem: ext descriptor pointer should release
  829. *
  830. * Return: None
  831. */
  832. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  833. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  834. {
  835. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  836. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  837. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  838. soc->tx_ext_desc[desc_pool_id].num_free++;
  839. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  840. return;
  841. }
  842. /**
  843. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  844. * attach it to free list
  845. * @soc: Handle to DP SoC structure
  846. * @desc_pool_id: pool id should pick up
  847. * @elem: tx descriptor should be freed
  848. * @num_free: number of descriptors should be freed
  849. *
  850. * Return: none
  851. */
  852. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  853. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  854. uint8_t num_free)
  855. {
  856. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  857. uint8_t freed = num_free;
  858. /* caller should always guarantee atleast list of num_free nodes */
  859. qdf_assert_always(elem);
  860. head = elem;
  861. c_elem = head;
  862. tail = head;
  863. while (c_elem && freed) {
  864. tail = c_elem;
  865. c_elem = c_elem->next;
  866. freed--;
  867. }
  868. /* caller should always guarantee atleast list of num_free nodes */
  869. qdf_assert_always(tail);
  870. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  871. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  872. soc->tx_ext_desc[desc_pool_id].freelist = head;
  873. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  874. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  875. return;
  876. }
  877. #if defined(FEATURE_TSO)
  878. /**
  879. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  880. * @soc: device soc instance
  881. * @pool_id: pool id should pick up tso descriptor
  882. *
  883. * Allocates a TSO segment element from the free list held in
  884. * the soc
  885. *
  886. * Return: tso_seg, tso segment memory pointer
  887. */
  888. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  889. struct dp_soc *soc, uint8_t pool_id)
  890. {
  891. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  892. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  893. if (soc->tx_tso_desc[pool_id].freelist) {
  894. soc->tx_tso_desc[pool_id].num_free--;
  895. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  896. soc->tx_tso_desc[pool_id].freelist =
  897. soc->tx_tso_desc[pool_id].freelist->next;
  898. }
  899. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  900. return tso_seg;
  901. }
  902. /**
  903. * dp_tx_tso_desc_free() - function to free a TSO segment
  904. * @soc: device soc instance
  905. * @pool_id: pool id should pick up tso descriptor
  906. * @tso_seg: tso segment memory pointer
  907. *
  908. * Returns a TSO segment element to the free list held in the
  909. * HTT pdev
  910. *
  911. * Return: none
  912. */
  913. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  914. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  915. {
  916. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  917. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  918. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  919. soc->tx_tso_desc[pool_id].num_free++;
  920. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  921. }
  922. static inline
  923. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  924. uint8_t pool_id)
  925. {
  926. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  927. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  928. if (soc->tx_tso_num_seg[pool_id].freelist) {
  929. soc->tx_tso_num_seg[pool_id].num_free--;
  930. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  931. soc->tx_tso_num_seg[pool_id].freelist =
  932. soc->tx_tso_num_seg[pool_id].freelist->next;
  933. }
  934. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  935. return tso_num_seg;
  936. }
  937. static inline
  938. void dp_tso_num_seg_free(struct dp_soc *soc,
  939. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  940. {
  941. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  942. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  943. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  944. soc->tx_tso_num_seg[pool_id].num_free++;
  945. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  946. }
  947. #endif
  948. /*
  949. * dp_tx_me_alloc_buf() Alloc descriptor from me pool
  950. * @pdev DP_PDEV handle for datapath
  951. *
  952. * Return:dp_tx_me_buf_t(buf)
  953. */
  954. static inline struct dp_tx_me_buf_t*
  955. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  956. {
  957. struct dp_tx_me_buf_t *buf = NULL;
  958. qdf_spin_lock_bh(&pdev->tx_mutex);
  959. if (pdev->me_buf.freelist) {
  960. buf = pdev->me_buf.freelist;
  961. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  962. pdev->me_buf.buf_in_use++;
  963. } else {
  964. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  965. "Error allocating memory in pool");
  966. qdf_spin_unlock_bh(&pdev->tx_mutex);
  967. return NULL;
  968. }
  969. qdf_spin_unlock_bh(&pdev->tx_mutex);
  970. return buf;
  971. }
  972. /*
  973. * dp_tx_me_free_buf() - Unmap the buffer holding the dest
  974. * address, free me descriptor and add it to the free-pool
  975. * @pdev: DP_PDEV handle for datapath
  976. * @buf : Allocated ME BUF
  977. *
  978. * Return:void
  979. */
  980. static inline void
  981. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  982. {
  983. /*
  984. * If the buf containing mac address was mapped,
  985. * it must be unmapped before freeing the me_buf.
  986. * The "paddr_macbuf" member in the me_buf structure
  987. * holds the mapped physical address and it must be
  988. * set to 0 after unmapping.
  989. */
  990. if (buf->paddr_macbuf) {
  991. qdf_mem_unmap_nbytes_single(pdev->soc->osdev,
  992. buf->paddr_macbuf,
  993. QDF_DMA_TO_DEVICE,
  994. QDF_MAC_ADDR_SIZE);
  995. buf->paddr_macbuf = 0;
  996. }
  997. qdf_spin_lock_bh(&pdev->tx_mutex);
  998. buf->next = pdev->me_buf.freelist;
  999. pdev->me_buf.freelist = buf;
  1000. pdev->me_buf.buf_in_use--;
  1001. qdf_spin_unlock_bh(&pdev->tx_mutex);
  1002. }
  1003. #endif /* DP_TX_DESC_H */