dp_tx_desc.h 31 KB

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