dp_tx_desc.h 27 KB

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