dp_tx_desc.h 29 KB

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