dp_tx_desc.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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, struct cdp_pdev *pdev,
  92. uint8_t vdev_id);
  93. void dp_tx_flow_pool_unmap(struct cdp_soc_t *soc, struct cdp_pdev *pdev,
  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_vdev *vdev)
  451. {
  452. struct dp_vdev *dp_vdev = (struct dp_vdev *)vdev;
  453. struct dp_tx_desc_pool_s *pool;
  454. if (!vdev)
  455. return false;
  456. pool = dp_vdev->pool;
  457. return dp_tx_is_threshold_reached(pool, pool->avail_desc);
  458. }
  459. #else /* QCA_LL_TX_FLOW_CONTROL_V2 */
  460. static inline void dp_tx_flow_control_init(struct dp_soc *handle)
  461. {
  462. }
  463. static inline void dp_tx_flow_control_deinit(struct dp_soc *handle)
  464. {
  465. }
  466. static inline QDF_STATUS dp_tx_flow_pool_map_handler(struct dp_pdev *pdev,
  467. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id,
  468. uint16_t flow_pool_size)
  469. {
  470. return QDF_STATUS_SUCCESS;
  471. }
  472. static inline void dp_tx_flow_pool_unmap_handler(struct dp_pdev *pdev,
  473. uint8_t flow_id, uint8_t flow_type, uint8_t flow_pool_id)
  474. {
  475. }
  476. /**
  477. * dp_tx_desc_alloc() - Allocate a Software Tx Descriptor from given pool
  478. *
  479. * @param soc Handle to DP SoC structure
  480. * @param pool_id
  481. *
  482. * Return:
  483. */
  484. static inline struct dp_tx_desc_s *dp_tx_desc_alloc(struct dp_soc *soc,
  485. uint8_t desc_pool_id)
  486. {
  487. struct dp_tx_desc_s *tx_desc = NULL;
  488. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  489. tx_desc = soc->tx_desc[desc_pool_id].freelist;
  490. /* Pool is exhausted */
  491. if (!tx_desc) {
  492. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  493. return NULL;
  494. }
  495. soc->tx_desc[desc_pool_id].freelist =
  496. soc->tx_desc[desc_pool_id].freelist->next;
  497. soc->tx_desc[desc_pool_id].num_allocated++;
  498. soc->tx_desc[desc_pool_id].num_free--;
  499. tx_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  500. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  501. return tx_desc;
  502. }
  503. /**
  504. * dp_tx_desc_alloc_multiple() - Allocate batch of software Tx Descriptors
  505. * from given pool
  506. * @soc: Handle to DP SoC structure
  507. * @pool_id: pool id should pick up
  508. * @num_requested: number of required descriptor
  509. *
  510. * allocate multiple tx descriptor and make a link
  511. *
  512. * Return: h_desc first descriptor pointer
  513. */
  514. static inline struct dp_tx_desc_s *dp_tx_desc_alloc_multiple(
  515. struct dp_soc *soc, uint8_t desc_pool_id, uint8_t num_requested)
  516. {
  517. struct dp_tx_desc_s *c_desc = NULL, *h_desc = NULL;
  518. uint8_t count;
  519. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  520. if ((num_requested == 0) ||
  521. (soc->tx_desc[desc_pool_id].num_free < num_requested)) {
  522. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  523. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  524. "%s, No Free Desc: Available(%d) num_requested(%d)",
  525. __func__, soc->tx_desc[desc_pool_id].num_free,
  526. num_requested);
  527. return NULL;
  528. }
  529. h_desc = soc->tx_desc[desc_pool_id].freelist;
  530. /* h_desc should never be NULL since num_free > requested */
  531. qdf_assert_always(h_desc);
  532. c_desc = h_desc;
  533. for (count = 0; count < (num_requested - 1); count++) {
  534. c_desc->flags = DP_TX_DESC_FLAG_ALLOCATED;
  535. c_desc = c_desc->next;
  536. }
  537. soc->tx_desc[desc_pool_id].num_free -= count;
  538. soc->tx_desc[desc_pool_id].num_allocated += count;
  539. soc->tx_desc[desc_pool_id].freelist = c_desc->next;
  540. c_desc->next = NULL;
  541. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  542. return h_desc;
  543. }
  544. /**
  545. * dp_tx_desc_free() - Fee a tx descriptor and attach it to free list
  546. *
  547. * @soc Handle to DP SoC structure
  548. * @pool_id
  549. * @tx_desc
  550. */
  551. static inline void
  552. dp_tx_desc_free(struct dp_soc *soc, struct dp_tx_desc_s *tx_desc,
  553. uint8_t desc_pool_id)
  554. {
  555. TX_DESC_LOCK_LOCK(&soc->tx_desc[desc_pool_id].lock);
  556. tx_desc->vdev = NULL;
  557. tx_desc->nbuf = NULL;
  558. tx_desc->flags = 0;
  559. tx_desc->next = soc->tx_desc[desc_pool_id].freelist;
  560. soc->tx_desc[desc_pool_id].freelist = tx_desc;
  561. soc->tx_desc[desc_pool_id].num_allocated--;
  562. soc->tx_desc[desc_pool_id].num_free++;
  563. TX_DESC_LOCK_UNLOCK(&soc->tx_desc[desc_pool_id].lock);
  564. }
  565. #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
  566. #ifdef QCA_DP_TX_DESC_ID_CHECK
  567. /**
  568. * dp_tx_is_desc_id_valid() - check is the tx desc id valid
  569. *
  570. * @soc Handle to DP SoC structure
  571. * @tx_desc_id
  572. *
  573. * Return: true or false
  574. */
  575. static inline bool
  576. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  577. {
  578. uint8_t pool_id;
  579. uint16_t page_id, offset;
  580. struct dp_tx_desc_pool_s *pool;
  581. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  582. DP_TX_DESC_ID_POOL_OS;
  583. /* Pool ID is out of limit */
  584. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  585. soc->wlan_cfg_ctx)) {
  586. QDF_TRACE(QDF_MODULE_ID_DP,
  587. QDF_TRACE_LEVEL_FATAL,
  588. "%s:Tx Comp pool id %d not valid",
  589. __func__,
  590. pool_id);
  591. goto warn_exit;
  592. }
  593. pool = &soc->tx_desc[pool_id];
  594. /* the pool is freed */
  595. if (IS_TX_DESC_POOL_STATUS_INACTIVE(pool)) {
  596. QDF_TRACE(QDF_MODULE_ID_DP,
  597. QDF_TRACE_LEVEL_FATAL,
  598. "%s:the pool %d has been freed",
  599. __func__,
  600. pool_id);
  601. goto warn_exit;
  602. }
  603. page_id = (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  604. DP_TX_DESC_ID_PAGE_OS;
  605. /* the page id is out of limit */
  606. if (page_id >= pool->desc_pages.num_pages) {
  607. QDF_TRACE(QDF_MODULE_ID_DP,
  608. QDF_TRACE_LEVEL_FATAL,
  609. "%s:the page id %d invalid, pool id %d, num_page %d",
  610. __func__,
  611. page_id,
  612. pool_id,
  613. pool->desc_pages.num_pages);
  614. goto warn_exit;
  615. }
  616. offset = (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  617. DP_TX_DESC_ID_OFFSET_OS;
  618. /* the offset is out of limit */
  619. if (offset >= pool->desc_pages.num_element_per_page) {
  620. QDF_TRACE(QDF_MODULE_ID_DP,
  621. QDF_TRACE_LEVEL_FATAL,
  622. "%s:offset %d invalid, pool%d,num_elem_per_page %d",
  623. __func__,
  624. offset,
  625. pool_id,
  626. pool->desc_pages.num_element_per_page);
  627. goto warn_exit;
  628. }
  629. return true;
  630. warn_exit:
  631. QDF_TRACE(QDF_MODULE_ID_DP,
  632. QDF_TRACE_LEVEL_FATAL,
  633. "%s:Tx desc id 0x%x not valid",
  634. __func__,
  635. tx_desc_id);
  636. qdf_assert_always(0);
  637. return false;
  638. }
  639. #else
  640. static inline bool
  641. dp_tx_is_desc_id_valid(struct dp_soc *soc, uint32_t tx_desc_id)
  642. {
  643. return true;
  644. }
  645. #endif /* QCA_DP_TX_DESC_ID_CHECK */
  646. /**
  647. * dp_tx_desc_find() - find dp tx descriptor from cokie
  648. * @soc - handle for the device sending the data
  649. * @tx_desc_id - the ID of the descriptor in question
  650. * @return the descriptor object that has the specified ID
  651. *
  652. * Use a tx descriptor ID to find the corresponding descriptor object.
  653. *
  654. */
  655. static inline struct dp_tx_desc_s *dp_tx_desc_find(struct dp_soc *soc,
  656. uint8_t pool_id, uint16_t page_id, uint16_t offset)
  657. {
  658. struct dp_tx_desc_pool_s *tx_desc_pool = &((soc)->tx_desc[(pool_id)]);
  659. return tx_desc_pool->desc_pages.cacheable_pages[page_id] +
  660. tx_desc_pool->elem_size * offset;
  661. }
  662. /**
  663. * dp_tx_ext_desc_alloc() - Get tx extension descriptor from pool
  664. * @soc: handle for the device sending the data
  665. * @pool_id: target pool id
  666. *
  667. * Return: None
  668. */
  669. static inline
  670. struct dp_tx_ext_desc_elem_s *dp_tx_ext_desc_alloc(struct dp_soc *soc,
  671. uint8_t desc_pool_id)
  672. {
  673. struct dp_tx_ext_desc_elem_s *c_elem;
  674. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  675. if (soc->tx_ext_desc[desc_pool_id].num_free <= 0) {
  676. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  677. return NULL;
  678. }
  679. c_elem = soc->tx_ext_desc[desc_pool_id].freelist;
  680. soc->tx_ext_desc[desc_pool_id].freelist =
  681. soc->tx_ext_desc[desc_pool_id].freelist->next;
  682. soc->tx_ext_desc[desc_pool_id].num_free--;
  683. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  684. return c_elem;
  685. }
  686. /**
  687. * dp_tx_ext_desc_free() - Release tx extension descriptor to the pool
  688. * @soc: handle for the device sending the data
  689. * @pool_id: target pool id
  690. * @elem: ext descriptor pointer should release
  691. *
  692. * Return: None
  693. */
  694. static inline void dp_tx_ext_desc_free(struct dp_soc *soc,
  695. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id)
  696. {
  697. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  698. elem->next = soc->tx_ext_desc[desc_pool_id].freelist;
  699. soc->tx_ext_desc[desc_pool_id].freelist = elem;
  700. soc->tx_ext_desc[desc_pool_id].num_free++;
  701. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  702. return;
  703. }
  704. /**
  705. * dp_tx_ext_desc_free_multiple() - Fee multiple tx extension descriptor and
  706. * attach it to free list
  707. * @soc: Handle to DP SoC structure
  708. * @desc_pool_id: pool id should pick up
  709. * @elem: tx descriptor should be freed
  710. * @num_free: number of descriptors should be freed
  711. *
  712. * Return: none
  713. */
  714. static inline void dp_tx_ext_desc_free_multiple(struct dp_soc *soc,
  715. struct dp_tx_ext_desc_elem_s *elem, uint8_t desc_pool_id,
  716. uint8_t num_free)
  717. {
  718. struct dp_tx_ext_desc_elem_s *head, *tail, *c_elem;
  719. uint8_t freed = num_free;
  720. /* caller should always guarantee atleast list of num_free nodes */
  721. qdf_assert_always(head);
  722. head = elem;
  723. c_elem = head;
  724. tail = head;
  725. while (c_elem && freed) {
  726. tail = c_elem;
  727. c_elem = c_elem->next;
  728. freed--;
  729. }
  730. /* caller should always guarantee atleast list of num_free nodes */
  731. qdf_assert_always(tail);
  732. qdf_spin_lock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  733. tail->next = soc->tx_ext_desc[desc_pool_id].freelist;
  734. soc->tx_ext_desc[desc_pool_id].freelist = head;
  735. soc->tx_ext_desc[desc_pool_id].num_free += num_free;
  736. qdf_spin_unlock_bh(&soc->tx_ext_desc[desc_pool_id].lock);
  737. return;
  738. }
  739. #if defined(FEATURE_TSO)
  740. /**
  741. * dp_tx_tso_desc_alloc() - function to allocate a TSO segment
  742. * @soc: device soc instance
  743. * @pool_id: pool id should pick up tso descriptor
  744. *
  745. * Allocates a TSO segment element from the free list held in
  746. * the soc
  747. *
  748. * Return: tso_seg, tso segment memory pointer
  749. */
  750. static inline struct qdf_tso_seg_elem_t *dp_tx_tso_desc_alloc(
  751. struct dp_soc *soc, uint8_t pool_id)
  752. {
  753. struct qdf_tso_seg_elem_t *tso_seg = NULL;
  754. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  755. if (soc->tx_tso_desc[pool_id].freelist) {
  756. soc->tx_tso_desc[pool_id].num_free--;
  757. tso_seg = soc->tx_tso_desc[pool_id].freelist;
  758. soc->tx_tso_desc[pool_id].freelist =
  759. soc->tx_tso_desc[pool_id].freelist->next;
  760. }
  761. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  762. return tso_seg;
  763. }
  764. /**
  765. * dp_tx_tso_desc_free() - function to free a TSO segment
  766. * @soc: device soc instance
  767. * @pool_id: pool id should pick up tso descriptor
  768. * @tso_seg: tso segment memory pointer
  769. *
  770. * Returns a TSO segment element to the free list held in the
  771. * HTT pdev
  772. *
  773. * Return: none
  774. */
  775. static inline void dp_tx_tso_desc_free(struct dp_soc *soc,
  776. uint8_t pool_id, struct qdf_tso_seg_elem_t *tso_seg)
  777. {
  778. qdf_spin_lock_bh(&soc->tx_tso_desc[pool_id].lock);
  779. tso_seg->next = soc->tx_tso_desc[pool_id].freelist;
  780. soc->tx_tso_desc[pool_id].freelist = tso_seg;
  781. soc->tx_tso_desc[pool_id].num_free++;
  782. qdf_spin_unlock_bh(&soc->tx_tso_desc[pool_id].lock);
  783. }
  784. static inline
  785. struct qdf_tso_num_seg_elem_t *dp_tso_num_seg_alloc(struct dp_soc *soc,
  786. uint8_t pool_id)
  787. {
  788. struct qdf_tso_num_seg_elem_t *tso_num_seg = NULL;
  789. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  790. if (soc->tx_tso_num_seg[pool_id].freelist) {
  791. soc->tx_tso_num_seg[pool_id].num_free--;
  792. tso_num_seg = soc->tx_tso_num_seg[pool_id].freelist;
  793. soc->tx_tso_num_seg[pool_id].freelist =
  794. soc->tx_tso_num_seg[pool_id].freelist->next;
  795. }
  796. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  797. return tso_num_seg;
  798. }
  799. static inline
  800. void dp_tso_num_seg_free(struct dp_soc *soc,
  801. uint8_t pool_id, struct qdf_tso_num_seg_elem_t *tso_num_seg)
  802. {
  803. qdf_spin_lock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  804. tso_num_seg->next = soc->tx_tso_num_seg[pool_id].freelist;
  805. soc->tx_tso_num_seg[pool_id].freelist = tso_num_seg;
  806. soc->tx_tso_num_seg[pool_id].num_free++;
  807. qdf_spin_unlock_bh(&soc->tx_tso_num_seg[pool_id].lock);
  808. }
  809. #endif
  810. /*
  811. * dp_tx_me_alloc_buf() Alloc descriptor from me pool
  812. * @pdev DP_PDEV handle for datapath
  813. *
  814. * Return:dp_tx_me_buf_t(buf)
  815. */
  816. static inline struct dp_tx_me_buf_t*
  817. dp_tx_me_alloc_buf(struct dp_pdev *pdev)
  818. {
  819. struct dp_tx_me_buf_t *buf = NULL;
  820. qdf_spin_lock_bh(&pdev->tx_mutex);
  821. if (pdev->me_buf.freelist) {
  822. buf = pdev->me_buf.freelist;
  823. pdev->me_buf.freelist = pdev->me_buf.freelist->next;
  824. pdev->me_buf.buf_in_use++;
  825. } else {
  826. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  827. "Error allocating memory in pool");
  828. qdf_spin_unlock_bh(&pdev->tx_mutex);
  829. return NULL;
  830. }
  831. qdf_spin_unlock_bh(&pdev->tx_mutex);
  832. return buf;
  833. }
  834. /*
  835. * dp_tx_me_free_buf() - Free me descriptor and add it to pool
  836. * @pdev: DP_PDEV handle for datapath
  837. * @buf : Allocated ME BUF
  838. *
  839. * Return:void
  840. */
  841. static inline void
  842. dp_tx_me_free_buf(struct dp_pdev *pdev, struct dp_tx_me_buf_t *buf)
  843. {
  844. qdf_spin_lock_bh(&pdev->tx_mutex);
  845. buf->next = pdev->me_buf.freelist;
  846. pdev->me_buf.freelist = buf;
  847. pdev->me_buf.buf_in_use--;
  848. qdf_spin_unlock_bh(&pdev->tx_mutex);
  849. }
  850. #endif /* DP_TX_DESC_H */