dp_tx_desc.h 32 KB

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