dp_tx_desc.h 32 KB

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