dp_tx_desc.h 26 KB

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