dp_tx_desc.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  1. /*
  2. * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for
  5. * any purpose with or without fee is hereby granted, provided that the
  6. * above copyright notice and this permission notice appear in all
  7. * copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
  10. * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
  11. * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
  12. * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  13. * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  14. * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  16. * PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. #ifndef DP_TX_DESC_H
  19. #define DP_TX_DESC_H
  20. #include "dp_types.h"
  21. #include "dp_tx.h"
  22. #include "dp_internal.h"
  23. /**
  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(soc->hif_handle);
  387. } else {
  388. pool->pkt_drop_no_desc++;
  389. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  390. }
  391. } else {
  392. soc->pool_stats.pkt_drop_no_pool++;
  393. }
  394. return tx_desc;
  395. }
  396. /**
  397. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  398. *
  399. * @soc Handle to DP SoC structure
  400. * @pool_id
  401. * @tx_desc
  402. *
  403. * Return: None
  404. */
  405. static inline void
  406. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  407. uint8_t desc_pool_id)
  408. {
  409. struct dp_tx_desc_pool_s *pool = &soc->tx_desc[desc_pool_id];
  410. qdf_spin_lock_bh(&pool->flow_pool_lock);
  411. tx_desc->vdev = NULL;
  412. tx_desc->nbuf = NULL;
  413. tx_desc->flags = 0;
  414. dp_tx_put_desc_flow_pool(pool, tx_desc);
  415. switch (pool->status) {
  416. case FLOW_POOL_ACTIVE_PAUSED:
  417. if (pool->avail_desc > pool->start_th) {
  418. soc->pause_cb(pool->flow_pool_id,
  419. WLAN_WAKE_ALL_NETIF_QUEUE,
  420. WLAN_DATA_FLOW_CONTROL);
  421. pool->status = FLOW_POOL_ACTIVE_UNPAUSED;
  422. }
  423. break;
  424. case FLOW_POOL_INVALID:
  425. if (pool->avail_desc == pool->pool_size) {
  426. dp_tx_desc_pool_free(soc, desc_pool_id);
  427. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  428. qdf_print("%s %d pool is freed!!",
  429. __func__, __LINE__);
  430. goto out;
  431. }
  432. break;
  433. case FLOW_POOL_ACTIVE_UNPAUSED:
  434. break;
  435. default:
  436. qdf_print("%s %d pool is INACTIVE State!!",
  437. __func__, __LINE__);
  438. break;
  439. };
  440. qdf_spin_unlock_bh(&pool->flow_pool_lock);
  441. out:
  442. /**
  443. * Decrement PM usage count if the packet has been sent. This
  444. * should be tied with the success of freeing one descriptor.
  445. */
  446. hif_pm_runtime_put(soc->hif_handle);
  447. }
  448. #endif /* QCA_AC_BASED_FLOW_CONTROL */
  449. static inline bool
  450. dp_tx_desc_thresh_reached(struct cdp_soc_t *soc_hdl, uint8_t vdev_id)
  451. {
  452. struct dp_soc *soc = cdp_soc_t_to_dp_soc(soc_hdl);
  453. struct dp_vdev *vdev = dp_get_vdev_from_soc_vdev_id_wifi3(soc,
  454. vdev_id);
  455. struct dp_tx_desc_pool_s *pool;
  456. if (!vdev)
  457. return false;
  458. pool = vdev->pool;
  459. return dp_tx_is_threshold_reached(pool, pool->avail_desc);
  460. }
  461. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  462. static inline void dp_tx_flow_control_init(struct dp_soc *handle)
  463. {
  464. }
  465. static inline void dp_tx_flow_control_deinit(struct dp_soc *handle)
  466. {
  467. }
  468. static inline QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev,
  469. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id,
  470. uint16_t flow_pool_size)
  471. {
  472. return QDF_STATUS_SUCCESS;
  473. }
  474. static inline void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev,
  475. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id)
  476. {
  477. }
  478. /**
  479. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  480. *
  481. * @param soc Handle to DP SoC structure
  482. * @param pool_id
  483. *
  484. * Return:
  485. */
  486. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  487. uint8_t desc_pool_id)
  488. {
  489. struct dp_tx_desc_s *tx_desc = NULL;
  490. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  491. tx_desc = soc->tx_desc[desc_pool_id].freelist;
  492. /* Pool is exhausted */
  493. if (!tx_desc) {
  494. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  495. return NULL;
  496. }
  497. soc->tx_desc[desc_pool_id].freelist =
  498. soc->tx_desc[desc_pool_id].freelist->next;
  499. soc->tx_desc[desc_pool_id].num_allocated++;
  500. soc->tx_desc[desc_pool_id].num_free--;
  501. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  502. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  503. return tx_desc;
  504. }
  505. /**
  506. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  507. * from given pool
  508. * @soc: Handle to DP SoC structure
  509. * @pool_id: pool id should pick up
  510. * @num_requested: number of required descriptor
  511. *
  512. * allocate multiple tx descriptor and make a link
  513. *
  514. * Return: h_desc first descriptor pointer
  515. */
  516. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  517. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  518. {
  519. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  520. uint8_t count;
  521. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  522. if ((num_requested == 0) ||
  523. (soc->tx_desc[desc_pool_id].num_free < num_requested)) {
  524. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  525. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  526. "%s, No Free Desc: Available(%d) num_requested(%d)",
  527. __func__, soc->tx_desc[desc_pool_id].num_free,
  528. num_requested);
  529. return NULL;
  530. }
  531. h_desc = soc->tx_desc[desc_pool_id].freelist;
  532. /* h_desc should never be NULL since num_free > requested */
  533. qdf_assert_always(h_desc);
  534. c_desc = h_desc;
  535. for (count = 0; count < (num_requested - 1); count++) {
  536. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  537. c_desc = c_desc->next;
  538. }
  539. soc->tx_desc[desc_pool_id].num_free -= count;
  540. soc->tx_desc[desc_pool_id].num_allocated += count;
  541. soc->tx_desc[desc_pool_id].freelist = c_desc->next;
  542. c_desc->next = NULL;
  543. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  544. return h_desc;
  545. }
  546. /**
  547. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  548. *
  549. * @soc Handle to DP SoC structure
  550. * @pool_id
  551. * @tx_desc
  552. */
  553. static inline void
  554. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  555. uint8_t desc_pool_id)
  556. {
  557. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  558. tx_desc->vdev = NULL;
  559. tx_desc->nbuf = NULL;
  560. tx_desc->flags = 0;
  561. tx_desc->next = soc->tx_desc[desc_pool_id].freelist;
  562. soc->tx_desc[desc_pool_id].freelist = tx_desc;
  563. soc->tx_desc[desc_pool_id].num_allocated--;
  564. soc->tx_desc[desc_pool_id].num_free++;
  565. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  566. }
  567. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  568. #ifdef QCA_DP_TX_DESC_ID_CHECK
  569. /**
  570. * dp_tx_is_desc_id_valid() - check is the tx desc id valid
  571. *
  572. * @soc Handle to DP SoC structure
  573. * @tx_desc_id
  574. *
  575. * Return: true or false
  576. */
  577. static inline bool
  578. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  579. {
  580. uint8_t pool_id;
  581. uint16_t page_id, offset;
  582. struct dp_tx_desc_pool_s *pool;
  583. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  584. DP_TX_DESC_ID_POOL_OS;
  585. /* Pool ID is out of limit */
  586. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  587. soc->wlan_cfg_ctx)) {
  588. QDF_TRACE(QDF_MODULE_ID_DP,
  589. QDF_TRACE_LEVEL_FATAL,
  590. "%s:Tx Comp pool id %d not valid",
  591. __func__,
  592. pool_id);
  593. goto warn_exit;
  594. }
  595. pool = &soc->tx_desc[pool_id];
  596. /* the pool is freed */
  597. if (IS_TX_DESC_POOL_STATUS_INACTIVE(pool)) {
  598. QDF_TRACE(QDF_MODULE_ID_DP,
  599. QDF_TRACE_LEVEL_FATAL,
  600. "%s:the pool %d has been freed",
  601. __func__,
  602. pool_id);
  603. goto warn_exit;
  604. }
  605. page_id = (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  606. DP_TX_DESC_ID_PAGE_OS;
  607. /* the page id is out of limit */
  608. if (page_id >= pool->desc_pages.num_pages) {
  609. QDF_TRACE(QDF_MODULE_ID_DP,
  610. QDF_TRACE_LEVEL_FATAL,
  611. "%s:the page id %d invalid, pool id %d, num_page %d",
  612. __func__,
  613. page_id,
  614. pool_id,
  615. pool->desc_pages.num_pages);
  616. goto warn_exit;
  617. }
  618. offset = (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  619. DP_TX_DESC_ID_OFFSET_OS;
  620. /* the offset is out of limit */
  621. if (offset >= pool->desc_pages.num_element_per_page) {
  622. QDF_TRACE(QDF_MODULE_ID_DP,
  623. QDF_TRACE_LEVEL_FATAL,
  624. "%s:offset %d invalid, pool%d,num_elem_per_page %d",
  625. __func__,
  626. offset,
  627. pool_id,
  628. pool->desc_pages.num_element_per_page);
  629. goto warn_exit;
  630. }
  631. return true;
  632. warn_exit:
  633. QDF_TRACE(QDF_MODULE_ID_DP,
  634. QDF_TRACE_LEVEL_FATAL,
  635. "%s:Tx desc id 0x%x not valid",
  636. __func__,
  637. tx_desc_id);
  638. qdf_assert_always(0);
  639. return false;
  640. }
  641. #else
  642. static inline bool
  643. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  644. {
  645. return true;
  646. }
  647. #endif /* QCA_DP_TX_DESC_ID_CHECK */
  648. /**
  649. * dp_tx_desc_find() - find dp tx descriptor from cokie
  650. * @soc - handle for the device sending the data
  651. * @tx_desc_id - the ID of the descriptor in question
  652. * @return the descriptor object that has the specified ID
  653. *
  654. * Use a tx descriptor ID to find the corresponding descriptor object.
  655. *
  656. */
  657. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  658. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  659. {
  660. struct dp_tx_desc_pool_s *tx_desc_pool = &((soc)->tx_desc[(pool_id)]);
  661. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  662. tx_desc_pool->elem_size * offset;
  663. }
  664. /**
  665. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  666. * @soc: handle for the device sending the data
  667. * @pool_id: target pool id
  668. *
  669. * Return: None
  670. */
  671. static inline
  672. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  673. uint8_t desc_pool_id)
  674. {
  675. struct dp_tx_ext_desc_elem_s *c_elem;
  676. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  677. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  678. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  679. return NULL;
  680. }
  681. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  682. soc->tx_ext_desc[desc_pool_id].freelist =
  683. soc->tx_ext_desc[desc_pool_id].freelist->next;
  684. soc->tx_ext_desc[desc_pool_id].num_free--;
  685. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  686. return c_elem;
  687. }
  688. /**
  689. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  690. * @soc: handle for the device sending the data
  691. * @pool_id: target pool id
  692. * @elem: ext descriptor pointer should release
  693. *
  694. * Return: None
  695. */
  696. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  697. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  698. {
  699. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  700. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  701. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  702. soc->tx_ext_desc[desc_pool_id].num_free++;
  703. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  704. return;
  705. }
  706. /**
  707. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  708. * attach it to free list
  709. * @soc: Handle to DP SoC structure
  710. * @desc_pool_id: pool id should pick up
  711. * @elem: tx descriptor should be freed
  712. * @num_free: number of descriptors should be freed
  713. *
  714. * Return: none
  715. */
  716. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  717. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  718. uint8_t num_free)
  719. {
  720. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  721. uint8_t freed = num_free;
  722. /* caller should always guarantee atleast list of num_free nodes */
  723. qdf_assert_always(elem);
  724. head = elem;
  725. c_elem = head;
  726. tail = head;
  727. while (c_elem && freed) {
  728. tail = c_elem;
  729. c_elem = c_elem->next;
  730. freed--;
  731. }
  732. /* caller should always guarantee atleast list of num_free nodes */
  733. qdf_assert_always(tail);
  734. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  735. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  736. soc->tx_ext_desc[desc_pool_id].freelist = head;
  737. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  738. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  739. return;
  740. }
  741. #if defined(FEATURE_TSO)
  742. /**
  743. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  744. * @soc: device soc instance
  745. * @pool_id: pool id should pick up tso descriptor
  746. *
  747. * Allocates a TSO segment element from the free list held in
  748. * the soc
  749. *
  750. * Return: tso_seg, tso segment memory pointer
  751. */
  752. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  753. struct dp_soc *soc, uint8_t pool_id)
  754. {
  755. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  756. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  757. if (soc->tx_tso_desc[pool_id].freelist) {
  758. soc->tx_tso_desc[pool_id].num_free--;
  759. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  760. soc->tx_tso_desc[pool_id].freelist =
  761. soc->tx_tso_desc[pool_id].freelist->next;
  762. }
  763. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  764. return tso_seg;
  765. }
  766. /**
  767. * dp_tx_tso_desc_free() - function to free a TSO segment
  768. * @soc: device soc instance
  769. * @pool_id: pool id should pick up tso descriptor
  770. * @tso_seg: tso segment memory pointer
  771. *
  772. * Returns a TSO segment element to the free list held in the
  773. * HTT pdev
  774. *
  775. * Return: none
  776. */
  777. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  778. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  779. {
  780. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  781. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  782. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  783. soc->tx_tso_desc[pool_id].num_free++;
  784. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  785. }
  786. static inline
  787. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  788. uint8_t pool_id)
  789. {
  790. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  791. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  792. if (soc->tx_tso_num_seg[pool_id].freelist) {
  793. soc->tx_tso_num_seg[pool_id].num_free--;
  794. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  795. soc->tx_tso_num_seg[pool_id].freelist =
  796. soc->tx_tso_num_seg[pool_id].freelist->next;
  797. }
  798. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  799. return tso_num_seg;
  800. }
  801. static inline
  802. void dp_tso_num_seg_free(struct dp_soc *soc,
  803. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  804. {
  805. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  806. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  807. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  808. soc->tx_tso_num_seg[pool_id].num_free++;
  809. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  810. }
  811. #endif
  812. /*
  813. * dp_tx_me_alloc_buf() Alloc descriptor from me pool
  814. * @pdev DP_PDEV handle for datapath
  815. *
  816. * Return:dp_tx_me_buf_t(buf)
  817. */
  818. static inline struct dp_tx_me_buf_t*
  819. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  820. {
  821. struct dp_tx_me_buf_t *buf = NULL;
  822. qdf_spin_lock_bh(&pdev->tx_mutex);
  823. if (pdev->me_buf.freelist) {
  824. buf = pdev->me_buf.freelist;
  825. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  826. pdev->me_buf.buf_in_use++;
  827. } else {
  828. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  829. "Error allocating memory in pool");
  830. qdf_spin_unlock_bh(&pdev->tx_mutex);
  831. return NULL;
  832. }
  833. qdf_spin_unlock_bh(&pdev->tx_mutex);
  834. return buf;
  835. }
  836. /*
  837. * dp_tx_me_free_buf() - Free me descriptor and add it to pool
  838. * @pdev: DP_PDEV handle for datapath
  839. * @buf : Allocated ME BUF
  840. *
  841. * Return:void
  842. */
  843. static inline void
  844. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  845. {
  846. qdf_spin_lock_bh(&pdev->tx_mutex);
  847. buf->next = pdev->me_buf.freelist;
  848. pdev->me_buf.freelist = buf;
  849. pdev->me_buf.buf_in_use--;
  850. qdf_spin_unlock_bh(&pdev->tx_mutex);
  851. }
  852. #endif /* DP_TX_DESC_H */