dp_tx_desc.h 31 KB

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