dp_tx_desc.h 28 KB

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