dp_tx_desc.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930
  1. /*
  2. * Copyright (c) 2016-2018 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_WAKE_NON_PRIORITY_QUEUE;
  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. default:
  240. QDF_TRACE(QDF_MODULE_ID_DP,
  241. QDF_TRACE_LEVEL_ERROR,
  242. "%s %d pool is %d status!",
  243. __func__, __LINE__,
  244. pool->status);
  245. break;
  246. }
  247. pool->latest_pause_time[level] =
  248. qdf_get_system_timestamp();
  249. soc->pause_cb(desc_pool_id,
  250. act, WLAN_DATA_FLOW_CONTROL);
  251. }
  252. } else {
  253. pool->pkt_drop_no_desc++;
  254. }
  255. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  256. } else {
  257. soc->pool_stats.pkt_drop_no_pool++;
  258. }
  259. return tx_desc;
  260. }
  261. /**
  262. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  263. *
  264. * @soc: Handle to DP SoC structure
  265. * @tx_desc: the tx descriptor to be freed
  266. * @desc_pool_id: ID of the flow control fool
  267. *
  268. * Return: None
  269. */
  270. static inline void
  271. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  272. uint8_t desc_pool_id)
  273. {
  274. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  275. qdf_time_t unpause_time = qdf_get_system_timestamp(), pause_dur;
  276. enum netif_action_type act = WLAN_WAKE_ALL_NETIF_QUEUE;
  277. qdf_spin_lock_bh(&pool->flow_pool_lock);
  278. tx_desc->flags = 0;
  279. dp_tx_put_desc_flow_pool(pool, tx_desc);
  280. switch (pool->status) {
  281. case FLOW_POOL_ACTIVE_PAUSED:
  282. if (pool->avail_desc > pool->start_th[DP_TH_HI]) {
  283. act = WLAN_NETIF_PRIORITY_QUEUE_ON;
  284. pool->status = FLOW_POOL_VO_PAUSED;
  285. /* Update maxinum pause duration for HI queue */
  286. pause_dur = unpause_time -
  287. pool->latest_pause_time[DP_TH_HI];
  288. if (pool->max_pause_time[DP_TH_HI] < pause_dur)
  289. pool->max_pause_time[DP_TH_HI] = pause_dur;
  290. }
  291. break;
  292. case FLOW_POOL_VO_PAUSED:
  293. if (pool->avail_desc > pool->start_th[DP_TH_VO]) {
  294. act = WLAN_NETIF_VO_QUEUE_ON;
  295. pool->status = FLOW_POOL_VI_PAUSED;
  296. /* Update maxinum pause duration for VO queue */
  297. pause_dur = unpause_time -
  298. pool->latest_pause_time[DP_TH_VO];
  299. if (pool->max_pause_time[DP_TH_VO] < pause_dur)
  300. pool->max_pause_time[DP_TH_VO] = pause_dur;
  301. }
  302. break;
  303. case FLOW_POOL_VI_PAUSED:
  304. if (pool->avail_desc > pool->start_th[DP_TH_VI]) {
  305. act = WLAN_NETIF_VI_QUEUE_ON;
  306. pool->status = FLOW_POOL_BE_BK_PAUSED;
  307. /* Update maxinum pause duration for VI queue */
  308. pause_dur = unpause_time -
  309. pool->latest_pause_time[DP_TH_VI];
  310. if (pool->max_pause_time[DP_TH_VI] < pause_dur)
  311. pool->max_pause_time[DP_TH_VI] = pause_dur;
  312. }
  313. break;
  314. case FLOW_POOL_BE_BK_PAUSED:
  315. if (pool->avail_desc > pool->start_th[DP_TH_BE_BK]) {
  316. act = WLAN_WAKE_NON_PRIORITY_QUEUE;
  317. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  318. /* Update maxinum pause duration for BE_BK queue */
  319. pause_dur = unpause_time -
  320. pool->latest_pause_time[DP_TH_BE_BK];
  321. if (pool->max_pause_time[DP_TH_BE_BK] < pause_dur)
  322. pool->max_pause_time[DP_TH_BE_BK] = pause_dur;
  323. }
  324. break;
  325. case FLOW_POOL_INVALID:
  326. if (pool->avail_desc == pool->pool_size) {
  327. dp_tx_desc_pool_free(soc, desc_pool_id);
  328. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  329. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  330. "%s %d pool is freed!!",
  331. __func__, __LINE__);
  332. return;
  333. }
  334. break;
  335. case FLOW_POOL_ACTIVE_UNPAUSED:
  336. break;
  337. default:
  338. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  339. "%s %d pool is INACTIVE State!!",
  340. __func__, __LINE__);
  341. break;
  342. };
  343. if (act != WLAN_WAKE_ALL_NETIF_QUEUE)
  344. soc->pause_cb(pool->flow_pool_id,
  345. act, WLAN_DATA_FLOW_CONTROL);
  346. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  347. }
  348. #else /* QCA_AC_BASED_FLOW_CONTROL */
  349. /**
  350. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  351. *
  352. * @soc Handle to DP SoC structure
  353. * @pool_id
  354. *
  355. * Return:
  356. */
  357. static inline struct dp_tx_desc_s *
  358. dp_tx_desc_alloc(struct dp_soc *soc, uint8_t desc_pool_id)
  359. {
  360. struct dp_tx_desc_s *tx_desc = NULL;
  361. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  362. if (pool) {
  363. qdf_spin_lock_bh(&pool->flow_pool_lock);
  364. if (pool->status <= FLOW_POOL_ACTIVE_PAUSED &&
  365. pool->avail_desc) {
  366. tx_desc = dp_tx_get_desc_flow_pool(pool);
  367. tx_desc->pool_id = desc_pool_id;
  368. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  369. if (qdf_unlikely(pool->avail_desc < pool->stop_th)) {
  370. pool->status = FLOW_POOL_ACTIVE_PAUSED;
  371. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  372. /* pause network queues */
  373. soc->pause_cb(desc_pool_id,
  374. WLAN_STOP_ALL_NETIF_QUEUE,
  375. WLAN_DATA_FLOW_CONTROL);
  376. } else {
  377. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  378. }
  379. /*
  380. * If one packet is going to be sent, PM usage count
  381. * needs to be incremented by one to prevent future
  382. * runtime suspend. This should be tied with the
  383. * success of allocating one descriptor. It will be
  384. * decremented after the packet has been sent.
  385. */
  386. hif_pm_runtime_get_noresume(soc->hif_handle);
  387. } else {
  388. pool->pkt_drop_no_desc++;
  389. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  390. }
  391. } else {
  392. soc->pool_stats.pkt_drop_no_pool++;
  393. }
  394. return tx_desc;
  395. }
  396. /**
  397. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  398. *
  399. * @soc Handle to DP SoC structure
  400. * @pool_id
  401. * @tx_desc
  402. *
  403. * Return: None
  404. */
  405. static inline void
  406. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  407. uint8_t desc_pool_id)
  408. {
  409. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  410. qdf_spin_lock_bh(&pool->flow_pool_lock);
  411. tx_desc->flags = 0;
  412. dp_tx_put_desc_flow_pool(pool, tx_desc);
  413. switch (pool->status) {
  414. case FLOW_POOL_ACTIVE_PAUSED:
  415. if (pool->avail_desc > pool->start_th) {
  416. soc->pause_cb(pool->flow_pool_id,
  417. WLAN_WAKE_ALL_NETIF_QUEUE,
  418. WLAN_DATA_FLOW_CONTROL);
  419. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  420. }
  421. break;
  422. case FLOW_POOL_INVALID:
  423. if (pool->avail_desc == pool->pool_size) {
  424. dp_tx_desc_pool_free(soc, desc_pool_id);
  425. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  426. qdf_print("%s %d pool is freed!!",
  427. __func__, __LINE__);
  428. goto out;
  429. }
  430. break;
  431. case FLOW_POOL_ACTIVE_UNPAUSED:
  432. break;
  433. default:
  434. qdf_print("%s %d pool is INACTIVE State!!",
  435. __func__, __LINE__);
  436. break;
  437. };
  438. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  439. out:
  440. /**
  441. * Decrement PM usage count if the packet has been sent. This
  442. * should be tied with the success of freeing one descriptor.
  443. */
  444. hif_pm_runtime_put(soc->hif_handle);
  445. }
  446. #endif /* QCA_AC_BASED_FLOW_CONTROL */
  447. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  448. static inline void dp_tx_flow_control_init(struct dp_soc *handle)
  449. {
  450. }
  451. static inline void dp_tx_flow_control_deinit(struct dp_soc *handle)
  452. {
  453. }
  454. static inline QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev,
  455. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id,
  456. uint16_t flow_pool_size)
  457. {
  458. return QDF_STATUS_SUCCESS;
  459. }
  460. static inline void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev,
  461. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id)
  462. {
  463. }
  464. /**
  465. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  466. *
  467. * @param soc Handle to DP SoC structure
  468. * @param pool_id
  469. *
  470. * Return:
  471. */
  472. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  473. uint8_t desc_pool_id)
  474. {
  475. struct dp_tx_desc_s *tx_desc = NULL;
  476. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  477. tx_desc = soc->tx_desc[desc_pool_id].freelist;
  478. /* Pool is exhausted */
  479. if (!tx_desc) {
  480. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  481. return NULL;
  482. }
  483. soc->tx_desc[desc_pool_id].freelist =
  484. soc->tx_desc[desc_pool_id].freelist->next;
  485. soc->tx_desc[desc_pool_id].num_allocated++;
  486. soc->tx_desc[desc_pool_id].num_free--;
  487. tx_desc->timestamp = qdf_ktime_to_ms(qdf_ktime_get());
  488. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  489. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  490. return tx_desc;
  491. }
  492. /**
  493. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  494. * from given pool
  495. * @soc: Handle to DP SoC structure
  496. * @pool_id: pool id should pick up
  497. * @num_requested: number of required descriptor
  498. *
  499. * allocate multiple tx descriptor and make a link
  500. *
  501. * Return: h_desc first descriptor pointer
  502. */
  503. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  504. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  505. {
  506. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  507. uint8_t count;
  508. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  509. if ((num_requested == 0) ||
  510. (soc->tx_desc[desc_pool_id].num_free < num_requested)) {
  511. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  512. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  513. "%s, No Free Desc: Available(%d) num_requested(%d)",
  514. __func__, soc->tx_desc[desc_pool_id].num_free,
  515. num_requested);
  516. return NULL;
  517. }
  518. h_desc = soc->tx_desc[desc_pool_id].freelist;
  519. /* h_desc should never be NULL since num_free > requested */
  520. qdf_assert_always(h_desc);
  521. c_desc = h_desc;
  522. for (count = 0; count < (num_requested - 1); count++) {
  523. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  524. c_desc = c_desc->next;
  525. }
  526. soc->tx_desc[desc_pool_id].num_free -= count;
  527. soc->tx_desc[desc_pool_id].num_allocated += count;
  528. soc->tx_desc[desc_pool_id].freelist = c_desc->next;
  529. c_desc->next = NULL;
  530. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  531. return h_desc;
  532. }
  533. /**
  534. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  535. *
  536. * @soc Handle to DP SoC structure
  537. * @pool_id
  538. * @tx_desc
  539. */
  540. static inline void
  541. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  542. uint8_t desc_pool_id)
  543. {
  544. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  545. tx_desc->vdev = NULL;
  546. tx_desc->nbuf = NULL;
  547. tx_desc->flags = 0;
  548. tx_desc->next = soc->tx_desc[desc_pool_id].freelist;
  549. soc->tx_desc[desc_pool_id].freelist = tx_desc;
  550. soc->tx_desc[desc_pool_id].num_allocated--;
  551. soc->tx_desc[desc_pool_id].num_free++;
  552. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  553. }
  554. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  555. #ifdef QCA_DP_TX_DESC_ID_CHECK
  556. /**
  557. * dp_tx_is_desc_id_valid() - check is the tx desc id valid
  558. *
  559. * @soc Handle to DP SoC structure
  560. * @tx_desc_id
  561. *
  562. * Return: true or false
  563. */
  564. static inline bool
  565. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  566. {
  567. uint8_t pool_id;
  568. uint16_t page_id, offset;
  569. struct dp_tx_desc_pool_s *pool;
  570. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  571. DP_TX_DESC_ID_POOL_OS;
  572. /* Pool ID is out of limit */
  573. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  574. soc->wlan_cfg_ctx)) {
  575. QDF_TRACE(QDF_MODULE_ID_DP,
  576. QDF_TRACE_LEVEL_FATAL,
  577. "%s:Tx Comp pool id %d not valid",
  578. __func__,
  579. pool_id);
  580. goto warn_exit;
  581. }
  582. pool = &soc->tx_desc[pool_id];
  583. /* the pool is freed */
  584. if (IS_TX_DESC_POOL_STATUS_INACTIVE(pool)) {
  585. QDF_TRACE(QDF_MODULE_ID_DP,
  586. QDF_TRACE_LEVEL_FATAL,
  587. "%s:the pool %d has been freed",
  588. __func__,
  589. pool_id);
  590. goto warn_exit;
  591. }
  592. page_id = (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  593. DP_TX_DESC_ID_PAGE_OS;
  594. /* the page id is out of limit */
  595. if (page_id >= pool->desc_pages.num_pages) {
  596. QDF_TRACE(QDF_MODULE_ID_DP,
  597. QDF_TRACE_LEVEL_FATAL,
  598. "%s:the page id %d invalid, pool id %d, num_page %d",
  599. __func__,
  600. page_id,
  601. pool_id,
  602. pool->desc_pages.num_pages);
  603. goto warn_exit;
  604. }
  605. offset = (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  606. DP_TX_DESC_ID_OFFSET_OS;
  607. /* the offset is out of limit */
  608. if (offset >= pool->desc_pages.num_element_per_page) {
  609. QDF_TRACE(QDF_MODULE_ID_DP,
  610. QDF_TRACE_LEVEL_FATAL,
  611. "%s:offset %d invalid, pool%d,num_elem_per_page %d",
  612. __func__,
  613. offset,
  614. pool_id,
  615. pool->desc_pages.num_element_per_page);
  616. goto warn_exit;
  617. }
  618. return true;
  619. warn_exit:
  620. QDF_TRACE(QDF_MODULE_ID_DP,
  621. QDF_TRACE_LEVEL_FATAL,
  622. "%s:Tx desc id 0x%x not valid",
  623. __func__,
  624. tx_desc_id);
  625. qdf_assert_always(0);
  626. return false;
  627. }
  628. #else
  629. static inline bool
  630. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  631. {
  632. return true;
  633. }
  634. #endif /* QCA_DP_TX_DESC_ID_CHECK */
  635. /**
  636. * dp_tx_desc_find() - find dp tx descriptor from cokie
  637. * @soc - handle for the device sending the data
  638. * @tx_desc_id - the ID of the descriptor in question
  639. * @return the descriptor object that has the specified ID
  640. *
  641. * Use a tx descriptor ID to find the corresponding descriptor object.
  642. *
  643. */
  644. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  645. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  646. {
  647. struct dp_tx_desc_pool_s *tx_desc_pool = &((soc)->tx_desc[(pool_id)]);
  648. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  649. tx_desc_pool->elem_size * offset;
  650. }
  651. /**
  652. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  653. * @soc: handle for the device sending the data
  654. * @pool_id: target pool id
  655. *
  656. * Return: None
  657. */
  658. static inline
  659. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  660. uint8_t desc_pool_id)
  661. {
  662. struct dp_tx_ext_desc_elem_s *c_elem;
  663. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  664. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  665. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  666. return NULL;
  667. }
  668. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  669. soc->tx_ext_desc[desc_pool_id].freelist =
  670. soc->tx_ext_desc[desc_pool_id].freelist->next;
  671. soc->tx_ext_desc[desc_pool_id].num_free--;
  672. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  673. return c_elem;
  674. }
  675. /**
  676. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  677. * @soc: handle for the device sending the data
  678. * @pool_id: target pool id
  679. * @elem: ext descriptor pointer should release
  680. *
  681. * Return: None
  682. */
  683. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  684. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  685. {
  686. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  687. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  688. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  689. soc->tx_ext_desc[desc_pool_id].num_free++;
  690. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  691. return;
  692. }
  693. /**
  694. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  695. * attach it to free list
  696. * @soc: Handle to DP SoC structure
  697. * @desc_pool_id: pool id should pick up
  698. * @elem: tx descriptor should be freed
  699. * @num_free: number of descriptors should be freed
  700. *
  701. * Return: none
  702. */
  703. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  704. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  705. uint8_t num_free)
  706. {
  707. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  708. uint8_t freed = num_free;
  709. /* caller should always guarantee atleast list of num_free nodes */
  710. qdf_assert_always(head);
  711. head = elem;
  712. c_elem = head;
  713. tail = head;
  714. while (c_elem && freed) {
  715. tail = c_elem;
  716. c_elem = c_elem->next;
  717. freed--;
  718. }
  719. /* caller should always guarantee atleast list of num_free nodes */
  720. qdf_assert_always(tail);
  721. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  722. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  723. soc->tx_ext_desc[desc_pool_id].freelist = head;
  724. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  725. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  726. return;
  727. }
  728. #if defined(FEATURE_TSO)
  729. /**
  730. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  731. * @soc: device soc instance
  732. * @pool_id: pool id should pick up tso descriptor
  733. *
  734. * Allocates a TSO segment element from the free list held in
  735. * the soc
  736. *
  737. * Return: tso_seg, tso segment memory pointer
  738. */
  739. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  740. struct dp_soc *soc, uint8_t pool_id)
  741. {
  742. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  743. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  744. if (soc->tx_tso_desc[pool_id].freelist) {
  745. soc->tx_tso_desc[pool_id].num_free--;
  746. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  747. soc->tx_tso_desc[pool_id].freelist =
  748. soc->tx_tso_desc[pool_id].freelist->next;
  749. }
  750. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  751. return tso_seg;
  752. }
  753. /**
  754. * dp_tx_tso_desc_free() - function to free a TSO segment
  755. * @soc: device soc instance
  756. * @pool_id: pool id should pick up tso descriptor
  757. * @tso_seg: tso segment memory pointer
  758. *
  759. * Returns a TSO segment element to the free list held in the
  760. * HTT pdev
  761. *
  762. * Return: none
  763. */
  764. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  765. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  766. {
  767. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  768. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  769. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  770. soc->tx_tso_desc[pool_id].num_free++;
  771. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  772. }
  773. static inline
  774. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  775. uint8_t pool_id)
  776. {
  777. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  778. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  779. if (soc->tx_tso_num_seg[pool_id].freelist) {
  780. soc->tx_tso_num_seg[pool_id].num_free--;
  781. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  782. soc->tx_tso_num_seg[pool_id].freelist =
  783. soc->tx_tso_num_seg[pool_id].freelist->next;
  784. }
  785. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  786. return tso_num_seg;
  787. }
  788. static inline
  789. void dp_tso_num_seg_free(struct dp_soc *soc,
  790. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  791. {
  792. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  793. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  794. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  795. soc->tx_tso_num_seg[pool_id].num_free++;
  796. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  797. }
  798. #endif
  799. /*
  800. * dp_tx_me_alloc_buf() Alloc descriptor from me pool
  801. * @pdev DP_PDEV handle for datapath
  802. *
  803. * Return:dp_tx_me_buf_t(buf)
  804. */
  805. static inline struct dp_tx_me_buf_t*
  806. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  807. {
  808. struct dp_tx_me_buf_t *buf = NULL;
  809. qdf_spin_lock_bh(&pdev->tx_mutex);
  810. if (pdev->me_buf.freelist) {
  811. buf = pdev->me_buf.freelist;
  812. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  813. pdev->me_buf.buf_in_use++;
  814. } else {
  815. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  816. "Error allocating memory in pool");
  817. qdf_spin_unlock_bh(&pdev->tx_mutex);
  818. return NULL;
  819. }
  820. qdf_spin_unlock_bh(&pdev->tx_mutex);
  821. return buf;
  822. }
  823. /*
  824. * dp_tx_me_free_buf() - Free me descriptor and add it to pool
  825. * @pdev: DP_PDEV handle for datapath
  826. * @buf : Allocated ME BUF
  827. *
  828. * Return:void
  829. */
  830. static inline void
  831. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  832. {
  833. qdf_spin_lock_bh(&pdev->tx_mutex);
  834. buf->next = pdev->me_buf.freelist;
  835. pdev->me_buf.freelist = buf;
  836. pdev->me_buf.buf_in_use--;
  837. qdf_spin_unlock_bh(&pdev->tx_mutex);
  838. }
  839. #endif /* DP_TX_DESC_H */