dp_tx_desc.h 28 KB

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