dp_tx.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833
  1. /*
  2. * Copyright (c) 2016-2017 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. #include "htt.h"
  19. #include "dp_tx.h"
  20. #include "dp_tx_desc.h"
  21. #include "dp_peer.h"
  22. #include "dp_types.h"
  23. #include "hal_tx.h"
  24. #include "qdf_mem.h"
  25. #include "qdf_nbuf.h"
  26. #include <wlan_cfg.h>
  27. #ifdef MESH_MODE_SUPPORT
  28. #include "if_meta_hdr.h"
  29. #endif
  30. #ifdef TX_PER_PDEV_DESC_POOL
  31. #define DP_TX_GET_DESC_POOL_ID(vdev) (vdev->pdev->pdev_id)
  32. #define DP_TX_GET_RING_ID(vdev) (vdev->pdev->pdev_id)
  33. #else
  34. #ifdef TX_PER_VDEV_DESC_POOL
  35. #define DP_TX_GET_DESC_POOL_ID(vdev) (vdev->vdev_id)
  36. #define DP_TX_GET_RING_ID(vdev) (vdev->pdev->pdev_id)
  37. #else
  38. #define DP_TX_GET_DESC_POOL_ID(vdev) qdf_get_cpu()
  39. #define DP_TX_GET_RING_ID(vdev) qdf_get_cpu()
  40. #endif /* TX_PER_VDEV_DESC_POOL */
  41. #endif /* TX_PER_PDEV_DESC_POOL */
  42. /* TODO Add support in TSO */
  43. #define DP_DESC_NUM_FRAG(x) 0
  44. /* disable TQM_BYPASS */
  45. #define TQM_BYPASS_WAR 0
  46. /*
  47. * default_dscp_tid_map - Default DSCP-TID mapping
  48. *
  49. * DSCP TID AC
  50. * 000000 0 WME_AC_BE
  51. * 001000 1 WME_AC_BK
  52. * 010000 1 WME_AC_BK
  53. * 011000 0 WME_AC_BE
  54. * 100000 5 WME_AC_VI
  55. * 101000 5 WME_AC_VI
  56. * 110000 6 WME_AC_VO
  57. * 111000 6 WME_AC_VO
  58. */
  59. static uint8_t default_dscp_tid_map[64] = {
  60. 0, 0, 0, 0, 0, 0, 0, 0,
  61. 1, 1, 1, 1, 1, 1, 1, 1,
  62. 1, 1, 1, 1, 1, 1, 1, 1,
  63. 0, 0, 0, 0, 0, 0, 0, 0,
  64. 5, 5, 5, 5, 5, 5, 5, 5,
  65. 5, 5, 5, 5, 5, 5, 5, 5,
  66. 6, 6, 6, 6, 6, 6, 6, 6,
  67. 6, 6, 6, 6, 6, 6, 6, 6,
  68. };
  69. /**
  70. * dp_tx_get_queue() - Returns Tx queue IDs to be used for this Tx frame
  71. * @vdev: DP Virtual device handle
  72. * @nbuf: Buffer pointer
  73. * @queue: queue ids container for nbuf
  74. *
  75. * TX packet queue has 2 instances, software descriptors id and dma ring id
  76. * Based on tx feature and hardware configuration queue id combination could be
  77. * different.
  78. * For example -
  79. * With XPS enabled,all TX descriptor pools and dma ring are assigned per cpu id
  80. * With no XPS,lock based resource protection, Descriptor pool ids are different
  81. * for each vdev, dma ring id will be same as single pdev id
  82. *
  83. * Return: None
  84. */
  85. static inline void dp_tx_get_queue(struct dp_vdev *vdev,
  86. qdf_nbuf_t nbuf, struct dp_tx_queue *queue)
  87. {
  88. queue->desc_pool_id = DP_TX_GET_DESC_POOL_ID(vdev);
  89. queue->ring_id = DP_TX_GET_RING_ID(vdev);
  90. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  91. "%s, pool_id:%d ring_id: %d\n",
  92. __func__, queue->desc_pool_id, queue->ring_id);
  93. return;
  94. }
  95. /**
  96. * dp_tx_desc_release() - Release Tx Descriptor
  97. * @tx_desc : Tx Descriptor
  98. * @desc_pool_id: Descriptor Pool ID
  99. *
  100. * Deallocate all resources attached to Tx descriptor and free the Tx
  101. * descriptor.
  102. *
  103. * Return:
  104. */
  105. static void
  106. dp_tx_desc_release(struct dp_tx_desc_s *tx_desc, uint8_t desc_pool_id)
  107. {
  108. struct dp_pdev *pdev = tx_desc->pdev;
  109. struct dp_soc *soc;
  110. uint8_t comp_status = 0;
  111. qdf_assert(pdev);
  112. soc = pdev->soc;
  113. DP_STATS_INC(tx_desc->vdev, tx_i.freed.num, 1);
  114. if (tx_desc->flags & DP_TX_DESC_FLAG_FRAG)
  115. dp_tx_ext_desc_free(soc, tx_desc->msdu_ext_desc, desc_pool_id);
  116. qdf_atomic_dec(&pdev->num_tx_outstanding);
  117. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  118. qdf_atomic_dec(&pdev->num_tx_exception);
  119. if (HAL_TX_COMP_RELEASE_SOURCE_TQM ==
  120. hal_tx_comp_get_buffer_source(&tx_desc->comp))
  121. comp_status = hal_tx_comp_get_release_reason(&tx_desc->comp);
  122. else
  123. comp_status = HAL_TX_COMP_RELEASE_REASON_FW;
  124. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  125. "Tx Completion Release desc %d status %d outstanding %d\n",
  126. tx_desc->id, comp_status,
  127. qdf_atomic_read(&pdev->num_tx_outstanding));
  128. dp_tx_desc_free(soc, tx_desc, desc_pool_id);
  129. return;
  130. }
  131. /**
  132. * dp_tx_htt_metadata_prepare() - Prepare HTT metadata for special frames
  133. * @vdev: DP vdev Handle
  134. * @nbuf: skb
  135. * @align_pad: Alignment Pad bytes to be added in frame header before adding HTT
  136. * metadata
  137. *
  138. * Prepares and fills HTT metadata in the frame pre-header for special frames
  139. * that should be transmitted using varying transmit parameters.
  140. * There are 2 VDEV modes that currently needs this special metadata -
  141. * 1) Mesh Mode
  142. * 2) DSRC Mode
  143. *
  144. * Return: HTT metadata size
  145. *
  146. */
  147. static uint8_t dp_tx_prepare_htt_metadata(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  148. uint8_t align_pad, uint32_t *meta_data)
  149. {
  150. struct htt_tx_msdu_desc_ext2_t *desc_ext =
  151. (struct htt_tx_msdu_desc_ext2_t *) meta_data;
  152. uint8_t htt_desc_size = 0;
  153. uint8_t *hdr = NULL;
  154. qdf_nbuf_unshare(nbuf);
  155. HTT_TX_TCL_METADATA_VALID_HTT_SET(vdev->htt_tcl_metadata, 1);
  156. /*
  157. * Metadata - HTT MSDU Extension header
  158. */
  159. htt_desc_size = sizeof(struct htt_tx_msdu_desc_ext2_t);
  160. if (vdev->mesh_vdev) {
  161. /* Fill and add HTT metaheader */
  162. hdr = qdf_nbuf_push_head(nbuf, htt_desc_size + align_pad);
  163. qdf_mem_copy(hdr, desc_ext, htt_desc_size);
  164. } else if (vdev->opmode == wlan_op_mode_ocb) {
  165. /* Todo - Add support for DSRC */
  166. }
  167. return htt_desc_size;
  168. }
  169. /**
  170. * dp_tx_prepare_ext_desc() - Allocate and prepare MSDU extension descriptor
  171. * @vdev: DP Vdev handle
  172. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  173. * @desc_pool_id: Descriptor Pool ID
  174. *
  175. * Return:
  176. */
  177. static
  178. struct dp_tx_ext_desc_elem_s *dp_tx_prepare_ext_desc(struct dp_vdev *vdev,
  179. struct dp_tx_msdu_info_s *msdu_info, uint8_t desc_pool_id)
  180. {
  181. uint8_t i;
  182. uint8_t cached_ext_desc[HAL_TX_EXT_DESC_WITH_META_DATA];
  183. struct dp_tx_seg_info_s *seg_info;
  184. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  185. struct dp_soc *soc = vdev->pdev->soc;
  186. /* Allocate an extension descriptor */
  187. msdu_ext_desc = dp_tx_ext_desc_alloc(soc, desc_pool_id);
  188. qdf_mem_zero(&cached_ext_desc[0], HAL_TX_EXT_DESC_WITH_META_DATA);
  189. if (!msdu_ext_desc)
  190. return NULL;
  191. if (qdf_unlikely(vdev->mesh_vdev)) {
  192. qdf_mem_copy(&cached_ext_desc[HAL_TX_EXTENSION_DESC_LEN_BYTES],
  193. &msdu_info->meta_data[0],
  194. sizeof(struct htt_tx_msdu_desc_ext2_t));
  195. qdf_atomic_inc(&vdev->pdev->num_tx_exception);
  196. }
  197. switch (msdu_info->frm_type) {
  198. case dp_tx_frm_sg:
  199. case dp_tx_frm_me:
  200. case dp_tx_frm_raw:
  201. seg_info = msdu_info->u.sg_info.curr_seg;
  202. /* Update the buffer pointers in MSDU Extension Descriptor */
  203. for (i = 0; i < seg_info->frag_cnt; i++) {
  204. hal_tx_ext_desc_set_buffer(&cached_ext_desc[0], i,
  205. seg_info->frags[i].paddr_lo,
  206. seg_info->frags[i].paddr_hi,
  207. seg_info->frags[i].len);
  208. }
  209. hal_tx_ext_desc_sync(&cached_ext_desc[0],
  210. msdu_ext_desc->vaddr);
  211. break;
  212. case dp_tx_frm_tso:
  213. /* Todo add support for TSO */
  214. break;
  215. default:
  216. break;
  217. }
  218. return msdu_ext_desc;
  219. }
  220. /**
  221. * dp_tx_desc_prepare_single - Allocate and prepare Tx descriptor
  222. * @vdev: DP vdev handle
  223. * @nbuf: skb
  224. * @desc_pool_id: Descriptor pool ID
  225. * Allocate and prepare Tx descriptor with msdu information.
  226. *
  227. * Return: Pointer to Tx Descriptor on success,
  228. * NULL on failure
  229. */
  230. static
  231. struct dp_tx_desc_s *dp_tx_prepare_desc_single(struct dp_vdev *vdev,
  232. qdf_nbuf_t nbuf, uint8_t desc_pool_id,
  233. uint32_t *meta_data)
  234. {
  235. QDF_STATUS status;
  236. uint8_t align_pad;
  237. uint8_t is_exception = 0;
  238. uint8_t htt_hdr_size;
  239. struct ether_header *eh;
  240. struct dp_tx_desc_s *tx_desc;
  241. struct dp_pdev *pdev = vdev->pdev;
  242. struct dp_soc *soc = pdev->soc;
  243. /* Flow control/Congestion Control processing */
  244. status = dp_tx_flow_control(vdev);
  245. if (QDF_STATUS_E_RESOURCES == status) {
  246. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  247. "%s Tx Resource Full\n", __func__);
  248. /* TODO Stop Tx Queues */
  249. }
  250. /* Allocate software Tx descriptor */
  251. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  252. if (qdf_unlikely(!tx_desc)) {
  253. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  254. "%s Tx Desc Alloc Failed\n", __func__);
  255. return NULL;
  256. }
  257. /* Flow control/Congestion Control counters */
  258. qdf_atomic_inc(&pdev->num_tx_outstanding);
  259. /* Initialize the SW tx descriptor */
  260. tx_desc->nbuf = nbuf;
  261. tx_desc->frm_type = dp_tx_frm_std;
  262. tx_desc->tx_encap_type = vdev->tx_encap_type;
  263. tx_desc->vdev = vdev;
  264. tx_desc->pdev = pdev;
  265. tx_desc->msdu_ext_desc = NULL;
  266. if (qdf_unlikely(QDF_STATUS_SUCCESS !=
  267. qdf_nbuf_map_nbytes_single(soc->osdev, nbuf,
  268. QDF_DMA_TO_DEVICE, qdf_nbuf_len(nbuf)))) {
  269. /* Handle failure */
  270. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  271. "qdf_nbuf_map_nbytes_single failed\n");
  272. goto failure;
  273. }
  274. align_pad = ((unsigned long) qdf_nbuf_mapped_paddr_get(nbuf)) & 0x7;
  275. tx_desc->pkt_offset = align_pad;
  276. /*
  277. * For special modes (vdev_type == ocb or mesh), data frames should be
  278. * transmitted using varying transmit parameters (tx spec) which include
  279. * transmit rate, power, priority, channel, channel bandwidth , nss etc.
  280. * These are filled in HTT MSDU descriptor and sent in frame pre-header.
  281. * These frames are sent as exception packets to firmware.
  282. */
  283. if (qdf_unlikely(vdev->mesh_vdev ||
  284. (vdev->opmode == wlan_op_mode_ocb))) {
  285. htt_hdr_size = dp_tx_prepare_htt_metadata(vdev, nbuf,
  286. align_pad, meta_data);
  287. tx_desc->pkt_offset += htt_hdr_size;
  288. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  289. is_exception = 1;
  290. }
  291. if (qdf_unlikely(vdev->nawds_enabled)) {
  292. eh = (struct ether_header *) qdf_nbuf_data(nbuf);
  293. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  294. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  295. is_exception = 1;
  296. }
  297. }
  298. #if !TQM_BYPASS_WAR
  299. if (is_exception)
  300. #endif
  301. {
  302. /* Temporary WAR due to TQM VP issues */
  303. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  304. qdf_atomic_inc(&pdev->num_tx_exception);
  305. }
  306. return tx_desc;
  307. failure:
  308. DP_STATS_INC_PKT(vdev, tx_i.dropped.dropped_pkt, 1,
  309. qdf_nbuf_len(nbuf));
  310. DP_STATS_INC(vdev, tx_i.dropped.dma_error, 1);
  311. dp_tx_desc_release(tx_desc, desc_pool_id);
  312. return NULL;
  313. }
  314. /**
  315. * dp_tx_desc_prepare- Allocate and prepare Tx descriptor for multisegment frame
  316. * @vdev: DP vdev handle
  317. * @nbuf: skb
  318. * @msdu_info: Info to be setup in MSDU descriptor and MSDU extension descriptor
  319. * @desc_pool_id : Descriptor Pool ID
  320. *
  321. * Allocate and prepare Tx descriptor with msdu and fragment descritor
  322. * information. For frames wth fragments, allocate and prepare
  323. * an MSDU extension descriptor
  324. *
  325. * Return: Pointer to Tx Descriptor on success,
  326. * NULL on failure
  327. */
  328. static struct dp_tx_desc_s *dp_tx_prepare_desc(struct dp_vdev *vdev,
  329. qdf_nbuf_t nbuf, struct dp_tx_msdu_info_s *msdu_info,
  330. uint8_t desc_pool_id)
  331. {
  332. struct dp_tx_desc_s *tx_desc;
  333. QDF_STATUS status;
  334. struct dp_tx_ext_desc_elem_s *msdu_ext_desc;
  335. struct dp_pdev *pdev = vdev->pdev;
  336. struct dp_soc *soc = pdev->soc;
  337. /* Flow control/Congestion Control processing */
  338. status = dp_tx_flow_control(vdev);
  339. if (QDF_STATUS_E_RESOURCES == status) {
  340. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  341. "%s Tx Resource Full\n", __func__);
  342. /* TODO Stop Tx Queues */
  343. }
  344. /* Allocate software Tx descriptor */
  345. tx_desc = dp_tx_desc_alloc(soc, desc_pool_id);
  346. if (!tx_desc)
  347. return NULL;
  348. /* Flow control/Congestion Control counters */
  349. qdf_atomic_inc(&pdev->num_tx_outstanding);
  350. /* Initialize the SW tx descriptor */
  351. tx_desc->nbuf = nbuf;
  352. tx_desc->frm_type = msdu_info->frm_type;
  353. tx_desc->tx_encap_type = vdev->tx_encap_type;
  354. tx_desc->vdev = vdev;
  355. tx_desc->pdev = pdev;
  356. tx_desc->pkt_offset = 0;
  357. /* Handle scattered frames - TSO/SG/ME */
  358. /* Allocate and prepare an extension descriptor for scattered frames */
  359. msdu_ext_desc = dp_tx_prepare_ext_desc(vdev, msdu_info, desc_pool_id);
  360. if (!msdu_ext_desc) {
  361. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  362. "%s Tx Extension Descriptor Alloc Fail\n",
  363. __func__);
  364. goto failure;
  365. }
  366. #if TQM_BYPASS_WAR
  367. /* Temporary WAR due to TQM VP issues */
  368. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  369. qdf_atomic_inc(&pdev->num_tx_exception);
  370. #endif
  371. if (qdf_unlikely(vdev->mesh_vdev))
  372. tx_desc->flags |= DP_TX_DESC_FLAG_TO_FW;
  373. tx_desc->msdu_ext_desc = msdu_ext_desc;
  374. tx_desc->flags |= DP_TX_DESC_FLAG_FRAG;
  375. return tx_desc;
  376. failure:
  377. DP_STATS_INC(vdev, tx_i.dropped.desc_na, 1);
  378. DP_STATS_INC_PKT(vdev, tx_i.dropped.dropped_pkt, 1,
  379. qdf_nbuf_len(nbuf));
  380. dp_tx_desc_release(tx_desc, desc_pool_id);
  381. return NULL;
  382. }
  383. /**
  384. * dp_tx_prepare_raw() - Prepare RAW packet TX
  385. * @vdev: DP vdev handle
  386. * @nbuf: buffer pointer
  387. * @seg_info: Pointer to Segment info Descriptor to be prepared
  388. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension
  389. * descriptor
  390. *
  391. * Return:
  392. */
  393. static qdf_nbuf_t dp_tx_prepare_raw(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  394. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  395. {
  396. qdf_nbuf_t curr_nbuf = NULL;
  397. uint16_t total_len = 0;
  398. int32_t i;
  399. struct dp_tx_sg_info_s *sg_info = &msdu_info->u.sg_info;
  400. if (QDF_STATUS_SUCCESS != qdf_nbuf_map_nbytes_single(vdev->osdev, nbuf,
  401. QDF_DMA_TO_DEVICE,
  402. qdf_nbuf_len(nbuf))) {
  403. qdf_print("dma map error\n");
  404. qdf_nbuf_free(nbuf);
  405. return NULL;
  406. }
  407. for (curr_nbuf = nbuf, i = 0; curr_nbuf;
  408. curr_nbuf = qdf_nbuf_next(nbuf), i++) {
  409. seg_info->frags[i].paddr_lo =
  410. qdf_nbuf_get_frag_paddr(curr_nbuf, 0);
  411. seg_info->frags[i].paddr_hi = 0x0;
  412. seg_info->frags[i].len = qdf_nbuf_len(curr_nbuf);
  413. seg_info->frags[i].vaddr = (void *) curr_nbuf;
  414. total_len += qdf_nbuf_len(curr_nbuf);
  415. }
  416. seg_info->frag_cnt = i;
  417. seg_info->total_len = total_len;
  418. seg_info->next = NULL;
  419. sg_info->curr_seg = seg_info;
  420. msdu_info->frm_type = dp_tx_frm_raw;
  421. msdu_info->num_seg = 1;
  422. return nbuf;
  423. }
  424. /**
  425. * dp_tx_hw_enqueue() - Enqueue to TCL HW for transmit
  426. * @soc: DP Soc Handle
  427. * @vdev: DP vdev handle
  428. * @tx_desc: Tx Descriptor Handle
  429. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  430. * @fw_metadata: Metadata to send to Target Firmware along with frame
  431. * @ring_id: Ring ID of H/W ring to which we enqueue the packet
  432. *
  433. * Gets the next free TCL HW DMA descriptor and sets up required parameters
  434. * from software Tx descriptor
  435. *
  436. * Return:
  437. */
  438. static QDF_STATUS dp_tx_hw_enqueue(struct dp_soc *soc, struct dp_vdev *vdev,
  439. struct dp_tx_desc_s *tx_desc, uint8_t tid,
  440. uint16_t fw_metadata, uint8_t ring_id)
  441. {
  442. uint8_t type;
  443. uint16_t length;
  444. void *hal_tx_desc, *hal_tx_desc_cached;
  445. qdf_dma_addr_t dma_addr;
  446. uint8_t cached_desc[HAL_TX_DESC_LEN_BYTES];
  447. /* Return Buffer Manager ID */
  448. uint8_t bm_id = ring_id;
  449. void *hal_srng = soc->tcl_data_ring[ring_id].hal_srng;
  450. hal_tx_desc_cached = (void *) cached_desc;
  451. qdf_mem_zero_outline(hal_tx_desc_cached, HAL_TX_DESC_LEN_BYTES);
  452. if (tx_desc->flags & DP_TX_DESC_FLAG_FRAG) {
  453. length = HAL_TX_EXTENSION_DESC_LEN_BYTES;
  454. type = HAL_TX_BUF_TYPE_EXT_DESC;
  455. dma_addr = tx_desc->msdu_ext_desc->paddr;
  456. } else {
  457. length = qdf_nbuf_len(tx_desc->nbuf);
  458. type = HAL_TX_BUF_TYPE_BUFFER;
  459. /**
  460. * For non-scatter regular frames, buffer pointer is directly
  461. * programmed in TCL input descriptor instead of using an MSDU
  462. * extension descriptor.For the direct buffer pointer case, HW
  463. * requirement is that descriptor should always point to a
  464. * 8-byte aligned address.
  465. * Alignment padding is already accounted in pkt_offset
  466. *
  467. */
  468. dma_addr = (qdf_nbuf_mapped_paddr_get(tx_desc->nbuf) -
  469. tx_desc->pkt_offset);
  470. }
  471. hal_tx_desc_set_fw_metadata(hal_tx_desc_cached, fw_metadata);
  472. hal_tx_desc_set_buf_addr(hal_tx_desc_cached,
  473. dma_addr , bm_id, tx_desc->id, type);
  474. hal_tx_desc_set_buf_length(hal_tx_desc_cached, length);
  475. hal_tx_desc_set_buf_offset(hal_tx_desc_cached, tx_desc->pkt_offset);
  476. hal_tx_desc_set_encap_type(hal_tx_desc_cached, tx_desc->tx_encap_type);
  477. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  478. "%s length:%d , type = %d, dma_addr %llx, offset %d\n",
  479. __func__, length, type, (uint64_t)dma_addr,
  480. tx_desc->pkt_offset);
  481. if (tx_desc->flags & DP_TX_DESC_FLAG_TO_FW)
  482. hal_tx_desc_set_to_fw(hal_tx_desc_cached, 1);
  483. /*
  484. * TODO
  485. * Fix this , this should be based on vdev opmode (AP or STA)
  486. * Enable both AddrX and AddrY flags for now
  487. */
  488. hal_tx_desc_set_addr_search_flags(hal_tx_desc_cached,
  489. HAL_TX_DESC_ADDRX_EN | HAL_TX_DESC_ADDRY_EN);
  490. if (qdf_nbuf_get_tx_cksum(tx_desc->nbuf) == QDF_NBUF_TX_CKSUM_TCP_UDP)
  491. hal_tx_desc_set_l4_checksum_en(hal_tx_desc_cached, 1);
  492. if (tid != HTT_TX_EXT_TID_INVALID)
  493. hal_tx_desc_set_hlos_tid(hal_tx_desc_cached, tid);
  494. if (tx_desc->flags & DP_TX_DESC_FLAG_MESH)
  495. hal_tx_desc_set_mesh_en(hal_tx_desc_cached, 1);
  496. /* Sync cached descriptor with HW */
  497. hal_tx_desc = hal_srng_src_get_next(soc->hal_soc, hal_srng);
  498. if (!hal_tx_desc) {
  499. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  500. "%s TCL ring full ring_id:%d\n", __func__, ring_id);
  501. DP_STATS_INC(soc, tx.tcl_ring_full[ring_id], 1);
  502. DP_STATS_INC(vdev, tx_i.dropped.ring_full, 1);
  503. DP_STATS_INC_PKT(vdev, tx_i.dropped.dropped_pkt, 1,
  504. length);
  505. hal_srng_access_end(soc->hal_soc,
  506. soc->tcl_data_ring[ring_id].hal_srng);
  507. return QDF_STATUS_E_RESOURCES;
  508. }
  509. tx_desc->flags |= DP_TX_DESC_FLAG_QUEUED_TX;
  510. hal_tx_desc_sync(hal_tx_desc_cached, hal_tx_desc);
  511. DP_STATS_INC_PKT(vdev, tx_i.processed, 1, length);
  512. return QDF_STATUS_SUCCESS;
  513. }
  514. /**
  515. * dp_tx_classify_tid() - Obtain TID to be used for this frame
  516. * @vdev: DP vdev handle
  517. * @nbuf: skb
  518. *
  519. * Extract the DSCP or PCP information from frame and map into TID value.
  520. * Software based TID classification is required when more than 2 DSCP-TID
  521. * mapping tables are needed.
  522. * Hardware supports 2 DSCP-TID mapping tables.
  523. *
  524. * Return:
  525. */
  526. static int dp_tx_classify_tid(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  527. struct dp_tx_msdu_info_s *msdu_info)
  528. {
  529. /* TODO */
  530. return 0;
  531. }
  532. /**
  533. * dp_tx_send_msdu_single() - Setup descriptor and enqueue single MSDU to TCL
  534. * @vdev: DP vdev handle
  535. * @nbuf: skb
  536. * @tid: TID from HLOS for overriding default DSCP-TID mapping
  537. * @tx_q: Tx queue to be used for this Tx frame
  538. *
  539. * Return: NULL on success,
  540. * nbuf when it fails to send
  541. */
  542. static qdf_nbuf_t dp_tx_send_msdu_single(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  543. uint8_t tid, struct dp_tx_queue *tx_q,
  544. uint32_t *meta_data)
  545. {
  546. struct dp_pdev *pdev = vdev->pdev;
  547. struct dp_soc *soc = pdev->soc;
  548. struct dp_tx_desc_s *tx_desc;
  549. QDF_STATUS status;
  550. void *hal_srng = soc->tcl_data_ring[tx_q->ring_id].hal_srng;
  551. /* Setup Tx descriptor for an MSDU, and MSDU extension descriptor */
  552. tx_desc = dp_tx_prepare_desc_single(vdev, nbuf, tx_q->desc_pool_id, meta_data);
  553. if (!tx_desc) {
  554. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  555. "%s Tx_desc prepare Fail vdev %p queue %d\n",
  556. __func__, vdev, tx_q->desc_pool_id);
  557. DP_STATS_INC(vdev, tx_i.dropped.desc_na, 1);
  558. goto fail_return;
  559. }
  560. if (qdf_unlikely(hal_srng_access_start(soc->hal_soc, hal_srng))) {
  561. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  562. "%s %d : HAL RING Access Failed -- %p\n",
  563. __func__, __LINE__, hal_srng);
  564. DP_STATS_INC(vdev, tx_i.dropped.ring_full, 1);
  565. goto fail_return;
  566. }
  567. /* Enqueue the Tx MSDU descriptor to HW for transmit */
  568. status = dp_tx_hw_enqueue(soc, vdev, tx_desc, tid,
  569. vdev->htt_tcl_metadata, tx_q->ring_id);
  570. if (status != QDF_STATUS_SUCCESS) {
  571. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  572. "%s Tx_hw_enqueue Fail tx_desc %p queue %d\n",
  573. __func__, tx_desc, tx_q->ring_id);
  574. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  575. DP_STATS_INC(vdev, tx_i.dropped.enqueue_fail, 1);
  576. goto fail_return;
  577. }
  578. hal_srng_access_end(soc->hal_soc, hal_srng);
  579. return NULL;
  580. fail_return:
  581. DP_STATS_INC_PKT(pdev, tx_i.dropped.dropped_pkt, 1,
  582. qdf_nbuf_len(nbuf));
  583. return nbuf;
  584. }
  585. /**
  586. * dp_tx_send_msdu_multiple() - Enqueue multiple MSDUs
  587. * @vdev: DP vdev handle
  588. * @nbuf: skb
  589. * @msdu_info: MSDU info to be setup in MSDU extension descriptor
  590. *
  591. * Prepare descriptors for multiple MSDUs (TSO segments) and enqueue to TCL
  592. *
  593. * Return: NULL on success,
  594. * nbuf when it fails to send
  595. */
  596. #if QDF_LOCK_STATS
  597. static noinline
  598. #else
  599. static
  600. #endif
  601. qdf_nbuf_t dp_tx_send_msdu_multiple(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  602. struct dp_tx_msdu_info_s *msdu_info)
  603. {
  604. uint8_t i;
  605. struct dp_pdev *pdev = vdev->pdev;
  606. struct dp_soc *soc = pdev->soc;
  607. struct dp_tx_desc_s *tx_desc;
  608. QDF_STATUS status;
  609. struct dp_tx_queue *tx_q = &msdu_info->tx_queue;
  610. void *hal_srng = soc->tcl_data_ring[tx_q->ring_id].hal_srng;
  611. if (qdf_unlikely(hal_srng_access_start(soc->hal_soc, hal_srng))) {
  612. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  613. "%s %d : HAL RING Access Failed -- %p\n",
  614. __func__, __LINE__, hal_srng);
  615. DP_STATS_INC(vdev, tx_i.dropped.ring_full, 1);
  616. DP_STATS_INC_PKT(vdev,
  617. tx_i.dropped.dropped_pkt, 1,
  618. qdf_nbuf_len(tx_desc->nbuf));
  619. return nbuf;
  620. }
  621. i = 0;
  622. /*
  623. * For each segment (maps to 1 MSDU) , prepare software and hardware
  624. * descriptors using information in msdu_info
  625. */
  626. while (i < msdu_info->num_seg) {
  627. /*
  628. * Setup Tx descriptor for an MSDU, and MSDU extension
  629. * descriptor
  630. */
  631. tx_desc = dp_tx_prepare_desc(vdev, nbuf, msdu_info,
  632. tx_q->desc_pool_id);
  633. if (!tx_desc) {
  634. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  635. "%s Tx_desc prepare Fail vdev %p queue %d\n",
  636. __func__, vdev, tx_q->desc_pool_id);
  637. DP_STATS_INC(vdev, tx_i.dropped.desc_na, 1);
  638. DP_STATS_INC_PKT(vdev,
  639. tx_i.dropped.dropped_pkt, 1,
  640. qdf_nbuf_len(tx_desc->nbuf));
  641. goto done;
  642. }
  643. /*
  644. * Enqueue the Tx MSDU descriptor to HW for transmit
  645. */
  646. status = dp_tx_hw_enqueue(soc, vdev, tx_desc, msdu_info->tid,
  647. vdev->htt_tcl_metadata, tx_q->ring_id);
  648. if (status != QDF_STATUS_SUCCESS) {
  649. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  650. "%s Tx_hw_enqueue Fail tx_desc %p queue %d\n",
  651. __func__, tx_desc, tx_q->ring_id);
  652. DP_STATS_INC(vdev, tx_i.dropped.enqueue_fail, 1);
  653. DP_STATS_INC_PKT(pdev,
  654. tx_i.dropped.dropped_pkt, 1,
  655. qdf_nbuf_len(tx_desc->nbuf));
  656. dp_tx_desc_release(tx_desc, tx_q->desc_pool_id);
  657. goto done;
  658. }
  659. /*
  660. * TODO
  661. * if tso_info structure can be modified to have curr_seg
  662. * as first element, following 2 blocks of code (for TSO and SG)
  663. * can be combined into 1
  664. */
  665. /*
  666. * For frames with multiple segments (TSO, ME), jump to next
  667. * segment.
  668. */
  669. if (msdu_info->frm_type == dp_tx_frm_tso) {
  670. if (msdu_info->u.tso_info.curr_seg->next) {
  671. msdu_info->u.tso_info.curr_seg =
  672. msdu_info->u.tso_info.curr_seg->next;
  673. /* Check with MCL if this is needed */
  674. /* nbuf = msdu_info->u.tso_info.curr_seg->nbuf; */
  675. }
  676. }
  677. /*
  678. * For Multicast-Unicast converted packets,
  679. * each converted frame (for a client) is represented as
  680. * 1 segment
  681. */
  682. if (msdu_info->frm_type == dp_tx_frm_sg) {
  683. if (msdu_info->u.sg_info.curr_seg->next) {
  684. msdu_info->u.sg_info.curr_seg =
  685. msdu_info->u.sg_info.curr_seg->next;
  686. nbuf = msdu_info->u.sg_info.curr_seg->nbuf;
  687. }
  688. }
  689. i++;
  690. }
  691. nbuf = NULL;
  692. done:
  693. hal_srng_access_end(soc->hal_soc, hal_srng);
  694. return nbuf;
  695. }
  696. /**
  697. * dp_tx_prepare_sg()- Extract SG info from NBUF and prepare msdu_info
  698. * for SG frames
  699. * @vdev: DP vdev handle
  700. * @nbuf: skb
  701. * @seg_info: Pointer to Segment info Descriptor to be prepared
  702. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  703. *
  704. * Return: NULL on success,
  705. * nbuf when it fails to send
  706. */
  707. static qdf_nbuf_t dp_tx_prepare_sg(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  708. struct dp_tx_seg_info_s *seg_info, struct dp_tx_msdu_info_s *msdu_info)
  709. {
  710. uint32_t cur_frag, nr_frags;
  711. qdf_dma_addr_t paddr;
  712. struct dp_tx_sg_info_s *sg_info;
  713. sg_info = &msdu_info->u.sg_info;
  714. nr_frags = qdf_nbuf_get_nr_frags(nbuf);
  715. if (QDF_STATUS_SUCCESS != qdf_nbuf_map_nbytes_single(vdev->osdev, nbuf,
  716. QDF_DMA_TO_DEVICE,
  717. qdf_nbuf_headlen(nbuf))) {
  718. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  719. "dma map error\n");
  720. qdf_nbuf_free(nbuf);
  721. return NULL;
  722. }
  723. seg_info->frags[0].paddr_lo = qdf_nbuf_get_frag_paddr(nbuf, 0);
  724. seg_info->frags[0].paddr_hi = 0;
  725. seg_info->frags[0].len = qdf_nbuf_headlen(nbuf);
  726. seg_info->frags[0].vaddr = (void *) nbuf;
  727. for (cur_frag = 0; cur_frag < nr_frags; cur_frag++) {
  728. if (QDF_STATUS_E_FAILURE == qdf_nbuf_frag_map(vdev->osdev,
  729. nbuf, 0, QDF_DMA_TO_DEVICE, cur_frag)) {
  730. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  731. "frag dma map error\n");
  732. qdf_nbuf_free(nbuf);
  733. return NULL;
  734. }
  735. paddr = qdf_nbuf_get_frag_paddr(nbuf, 0);
  736. seg_info->frags[cur_frag + 1].paddr_lo = paddr;
  737. seg_info->frags[cur_frag + 1].paddr_hi =
  738. ((uint64_t) paddr) >> 32;
  739. seg_info->frags[cur_frag + 1].len =
  740. qdf_nbuf_get_frag_size(nbuf, cur_frag);
  741. }
  742. seg_info->frag_cnt = (cur_frag + 1);
  743. seg_info->total_len = qdf_nbuf_len(nbuf);
  744. seg_info->next = NULL;
  745. sg_info->curr_seg = seg_info;
  746. msdu_info->frm_type = dp_tx_frm_sg;
  747. msdu_info->num_seg = 1;
  748. return nbuf;
  749. }
  750. #ifdef MESH_MODE_SUPPORT
  751. /**
  752. * dp_tx_extract_mesh_meta_data()- Extract mesh meta hdr info from nbuf
  753. and prepare msdu_info for mesh frames.
  754. * @vdev: DP vdev handle
  755. * @nbuf: skb
  756. * @msdu_info: MSDU info to be setup in MSDU descriptor and MSDU extension desc.
  757. *
  758. * Return: void
  759. */
  760. static
  761. void dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  762. struct dp_tx_msdu_info_s *msdu_info)
  763. {
  764. struct meta_hdr_s *mhdr;
  765. struct htt_tx_msdu_desc_ext2_t *meta_data =
  766. (struct htt_tx_msdu_desc_ext2_t *)&msdu_info->meta_data[0];
  767. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(nbuf);
  768. qdf_mem_set(meta_data, 0, sizeof(struct htt_tx_msdu_desc_ext2_t));
  769. if (!(mhdr->flags & METAHDR_FLAG_AUTO_RATE)) {
  770. meta_data->power = mhdr->power;
  771. meta_data->mcs_mask = mhdr->rates[0] & 0xF;
  772. meta_data->nss_mask = (mhdr->rates[0] >> 4) & 0x3;
  773. meta_data->pream_type = (mhdr->rates[0] >> 6) & 0x3;
  774. meta_data->retry_limit = mhdr->max_tries[0];
  775. meta_data->dyn_bw = 1;
  776. meta_data->valid_pwr = 1;
  777. meta_data->valid_mcs_mask = 1;
  778. meta_data->valid_nss_mask = 1;
  779. meta_data->valid_preamble_type = 1;
  780. meta_data->valid_retries = 1;
  781. meta_data->valid_bw_info = 1;
  782. }
  783. if (mhdr->flags & METAHDR_FLAG_NOENCRYPT) {
  784. meta_data->encrypt_type = 0;
  785. meta_data->valid_encrypt_type = 1;
  786. }
  787. if (mhdr->flags & METAHDR_FLAG_NOQOS)
  788. msdu_info->tid = HTT_TX_EXT_TID_NON_QOS_MCAST_BCAST;
  789. else
  790. msdu_info->tid = qdf_nbuf_get_priority(nbuf);
  791. meta_data->valid_key_flags = 1;
  792. meta_data->key_flags = (mhdr->keyix & 0x3);
  793. qdf_nbuf_pull_head(nbuf, sizeof(struct meta_hdr_s));
  794. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  795. "%s , Meta hdr %0x %0x %0x %0x %0x\n",
  796. __func__, msdu_info->meta_data[0],
  797. msdu_info->meta_data[1],
  798. msdu_info->meta_data[2],
  799. msdu_info->meta_data[3],
  800. msdu_info->meta_data[4]);
  801. return;
  802. }
  803. #else
  804. static
  805. void dp_tx_extract_mesh_meta_data(struct dp_vdev *vdev, qdf_nbuf_t nbuf,
  806. struct dp_tx_msdu_info_s *msdu_info)
  807. {
  808. }
  809. #endif
  810. /**
  811. * dp_tx_send() - Transmit a frame on a given VAP
  812. * @vap_dev: DP vdev handle
  813. * @nbuf: skb
  814. *
  815. * Entry point for Core Tx layer (DP_TX) invoked from
  816. * hard_start_xmit in OSIF/HDD or from dp_rx_process for intravap forwarding
  817. * cases
  818. *
  819. * Return: NULL on success,
  820. * nbuf when it fails to send
  821. */
  822. qdf_nbuf_t dp_tx_send(void *vap_dev, qdf_nbuf_t nbuf)
  823. {
  824. struct ether_header *eh;
  825. struct dp_tx_msdu_info_s msdu_info;
  826. struct dp_tx_seg_info_s seg_info;
  827. struct dp_vdev *vdev = (struct dp_vdev *) vap_dev;
  828. qdf_mem_set(&msdu_info, sizeof(msdu_info), 0x0);
  829. qdf_mem_set(&seg_info, sizeof(seg_info), 0x0);
  830. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  831. "%s , skb %0x:%0x:%0x:%0x:%0x:%0x\n",
  832. __func__, nbuf->data[0], nbuf->data[1], nbuf->data[2],
  833. nbuf->data[3], nbuf->data[4], nbuf->data[5]);
  834. /*
  835. * Set Default Host TID value to invalid TID
  836. * (TID override disabled)
  837. */
  838. msdu_info.tid = HTT_TX_EXT_TID_INVALID;
  839. DP_STATS_INC_PKT(vdev->pdev, tx_i.rcvd, 1, qdf_nbuf_len(nbuf));
  840. if (qdf_unlikely(vdev->mesh_vdev))
  841. dp_tx_extract_mesh_meta_data(vdev, nbuf, &msdu_info);
  842. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  843. "%s , skb %0x:%0x:%0x:%0x:%0x:%0x\n",
  844. __func__, nbuf->data[0], nbuf->data[1], nbuf->data[2],
  845. nbuf->data[3], nbuf->data[4], nbuf->data[5]);
  846. /*
  847. * Get HW Queue to use for this frame.
  848. * TCL supports upto 4 DMA rings, out of which 3 rings are
  849. * dedicated for data and 1 for command.
  850. * "queue_id" maps to one hardware ring.
  851. * With each ring, we also associate a unique Tx descriptor pool
  852. * to minimize lock contention for these resources.
  853. */
  854. dp_tx_get_queue(vdev, nbuf, &msdu_info.tx_queue);
  855. /*
  856. * TCL H/W supports 2 DSCP-TID mapping tables.
  857. * Table 1 - Default DSCP-TID mapping table
  858. * Table 2 - 1 DSCP-TID override table
  859. *
  860. * If we need a different DSCP-TID mapping for this vap,
  861. * call tid_classify to extract DSCP/ToS from frame and
  862. * map to a TID and store in msdu_info. This is later used
  863. * to fill in TCL Input descriptor (per-packet TID override).
  864. */
  865. if (vdev->dscp_tid_map_id > 1)
  866. dp_tx_classify_tid(vdev, nbuf, &msdu_info);
  867. /* Reset the control block */
  868. qdf_nbuf_reset_ctxt(nbuf);
  869. /*
  870. * Classify the frame and call corresponding
  871. * "prepare" function which extracts the segment (TSO)
  872. * and fragmentation information (for TSO , SG, ME, or Raw)
  873. * into MSDU_INFO structure which is later used to fill
  874. * SW and HW descriptors.
  875. */
  876. if (qdf_nbuf_is_tso(nbuf)) {
  877. /* dp_tx_prepare_tso(vdev, nbuf, &seg_info, &msdu_info); */
  878. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  879. "%s TSO frame %p\n", __func__, vdev);
  880. DP_STATS_INC_PKT(vdev, tx_i.tso.tso_pkt, 1,
  881. qdf_nbuf_len(nbuf));
  882. goto send_multiple;
  883. }
  884. /* SG */
  885. if (qdf_unlikely(qdf_nbuf_is_nonlinear(nbuf))) {
  886. nbuf = dp_tx_prepare_sg(vdev, nbuf, &seg_info, &msdu_info);
  887. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  888. "%s non-TSO SG frame %p\n", __func__, vdev);
  889. DP_STATS_INC_PKT(vdev, tx_i.sg.sg_pkt, 1,
  890. qdf_nbuf_len(nbuf));
  891. goto send_multiple;
  892. }
  893. /* Mcast to Ucast Conversion*/
  894. if (qdf_unlikely(vdev->mcast_enhancement_en == 1)) {
  895. eh = (struct ether_header *)qdf_nbuf_data(nbuf);
  896. if (DP_FRAME_IS_MULTICAST((eh)->ether_dhost)) {
  897. nbuf = dp_tx_prepare_me(vdev, nbuf, &msdu_info);
  898. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  899. "%s Mcast frm for ME %p\n", __func__, vdev);
  900. DP_STATS_INC_PKT(vdev,
  901. tx_i.mcast_en.mcast_pkt, 1,
  902. qdf_nbuf_len(nbuf));
  903. goto send_multiple;
  904. }
  905. }
  906. /* RAW */
  907. if (qdf_unlikely(vdev->tx_encap_type == htt_pkt_type_raw)) {
  908. nbuf = dp_tx_prepare_raw(vdev, nbuf, &seg_info, &msdu_info);
  909. if (nbuf == NULL)
  910. return NULL;
  911. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  912. "%s Raw frame %p\n", __func__, vdev);
  913. DP_STATS_INC_PKT(vdev, tx_i.raw_pkt, 1,
  914. qdf_nbuf_len(nbuf));
  915. goto send_multiple;
  916. }
  917. /* Single linear frame */
  918. /*
  919. * If nbuf is a simple linear frame, use send_single function to
  920. * prepare direct-buffer type TCL descriptor and enqueue to TCL
  921. * SRNG. There is no need to setup a MSDU extension descriptor.
  922. */
  923. nbuf = dp_tx_send_msdu_single(vdev, nbuf, msdu_info.tid,
  924. &msdu_info.tx_queue, msdu_info.meta_data);
  925. return nbuf;
  926. send_multiple:
  927. nbuf = dp_tx_send_msdu_multiple(vdev, nbuf, &msdu_info);
  928. return nbuf;
  929. }
  930. /**
  931. * dp_tx_reinject_handler() - Tx Reinject Handler
  932. * @tx_desc: software descriptor head pointer
  933. * @status : Tx completion status from HTT descriptor
  934. *
  935. * This function reinjects frames back to Target.
  936. * Todo - Host queue needs to be added
  937. *
  938. * Return: none
  939. */
  940. static
  941. void dp_tx_reinject_handler(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  942. {
  943. struct dp_vdev *vdev;
  944. vdev = tx_desc->vdev;
  945. qdf_assert(vdev);
  946. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  947. "%s Tx reinject path\n", __func__);
  948. DP_STATS_INC_PKT(vdev, tx_i.reinject_pkts, 1,
  949. qdf_nbuf_len(tx_desc->nbuf));
  950. if (qdf_unlikely(vdev->mesh_vdev)) {
  951. DP_TX_FREE_SINGLE_BUF(vdev->pdev->soc, tx_desc->nbuf);
  952. } else
  953. dp_tx_send(vdev, tx_desc->nbuf);
  954. dp_tx_desc_release(tx_desc, tx_desc->pool_id);
  955. }
  956. /**
  957. * dp_tx_inspect_handler() - Tx Inspect Handler
  958. * @tx_desc: software descriptor head pointer
  959. * @status : Tx completion status from HTT descriptor
  960. *
  961. * Handles Tx frames sent back to Host for inspection
  962. * (ProxyARP)
  963. *
  964. * Return: none
  965. */
  966. static void dp_tx_inspect_handler(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  967. {
  968. struct dp_soc *soc;
  969. struct dp_pdev *pdev = tx_desc->pdev;
  970. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  971. "%s Tx inspect path\n",
  972. __func__);
  973. qdf_assert(pdev);
  974. soc = pdev->soc;
  975. DP_STATS_INC_PKT(tx_desc->vdev, tx_i.inspect_pkts, 1,
  976. qdf_nbuf_len(tx_desc->nbuf));
  977. DP_TX_FREE_SINGLE_BUF(soc, tx_desc->nbuf);
  978. }
  979. /**
  980. * dp_tx_process_htt_completion() - Tx HTT Completion Indication Handler
  981. * @tx_desc: software descriptor head pointer
  982. * @status : Tx completion status from HTT descriptor
  983. *
  984. * This function will process HTT Tx indication messages from Target
  985. *
  986. * Return: none
  987. */
  988. static
  989. void dp_tx_process_htt_completion(struct dp_tx_desc_s *tx_desc, uint8_t *status)
  990. {
  991. uint8_t tx_status;
  992. struct dp_pdev *pdev;
  993. struct dp_soc *soc;
  994. uint32_t *htt_status_word = (uint32_t *) status;
  995. qdf_assert(tx_desc->pdev);
  996. pdev = tx_desc->pdev;
  997. soc = pdev->soc;
  998. tx_status = HTT_TX_WBM_COMPLETION_TX_STATUS_GET(htt_status_word[0]);
  999. switch (tx_status) {
  1000. case HTT_TX_FW2WBM_TX_STATUS_OK:
  1001. {
  1002. qdf_atomic_dec(&pdev->num_tx_exception);
  1003. DP_TX_FREE_SINGLE_BUF(soc, tx_desc->nbuf);
  1004. break;
  1005. }
  1006. case HTT_TX_FW2WBM_TX_STATUS_DROP:
  1007. case HTT_TX_FW2WBM_TX_STATUS_TTL:
  1008. {
  1009. qdf_atomic_dec(&pdev->num_tx_exception);
  1010. DP_STATS_INC_PKT(tx_desc->vdev, tx_i.dropped.dropped_pkt,
  1011. 1, qdf_nbuf_len(tx_desc->nbuf));
  1012. DP_TX_FREE_SINGLE_BUF(soc, tx_desc->nbuf);
  1013. break;
  1014. }
  1015. case HTT_TX_FW2WBM_TX_STATUS_REINJECT:
  1016. {
  1017. dp_tx_reinject_handler(tx_desc, status);
  1018. break;
  1019. }
  1020. case HTT_TX_FW2WBM_TX_STATUS_INSPECT:
  1021. {
  1022. dp_tx_inspect_handler(tx_desc, status);
  1023. break;
  1024. }
  1025. default:
  1026. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1027. "%s Invalid HTT tx_status %d\n",
  1028. __func__, tx_status);
  1029. break;
  1030. }
  1031. }
  1032. #ifdef MESH_MODE_SUPPORT
  1033. /**
  1034. * dp_tx_comp_fill_tx_completion_stats() - Fill per packet Tx completion stats
  1035. * in mesh meta header
  1036. * @tx_desc: software descriptor head pointer
  1037. * @ts: pointer to tx completion stats
  1038. * Return: none
  1039. */
  1040. static
  1041. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  1042. struct hal_tx_completion_status *ts)
  1043. {
  1044. struct meta_hdr_s *mhdr;
  1045. qdf_nbuf_t netbuf = tx_desc->nbuf;
  1046. if (!tx_desc->msdu_ext_desc) {
  1047. qdf_nbuf_pull_head(netbuf, tx_desc->pkt_offset);
  1048. }
  1049. qdf_nbuf_push_head(netbuf, sizeof(struct meta_hdr_s));
  1050. mhdr = (struct meta_hdr_s *)qdf_nbuf_data(netbuf);
  1051. mhdr->rssi = ts->ack_frame_rssi;
  1052. }
  1053. #else
  1054. static
  1055. void dp_tx_comp_fill_tx_completion_stats(struct dp_tx_desc_s *tx_desc,
  1056. struct hal_tx_completion_status *ts)
  1057. {
  1058. }
  1059. #endif
  1060. /**
  1061. * dp_tx_comp_process_tx_status() - Parse and Dump Tx completion status info
  1062. * @tx_desc: software descriptor head pointer
  1063. * @length: packet length
  1064. *
  1065. * Return: none
  1066. */
  1067. static inline void dp_tx_comp_process_tx_status(struct dp_tx_desc_s *tx_desc,
  1068. uint32_t length)
  1069. {
  1070. struct hal_tx_completion_status ts;
  1071. struct dp_soc *soc = NULL;
  1072. struct dp_vdev *vdev = tx_desc->vdev;
  1073. struct dp_peer *peer = NULL;
  1074. uint8_t comp_status = 0;
  1075. qdf_mem_zero(&ts, sizeof(struct hal_tx_completion_status));
  1076. hal_tx_comp_get_status(&tx_desc->comp, &ts);
  1077. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1078. "-------------------- \n"
  1079. "Tx Completion Stats: \n"
  1080. "-------------------- \n"
  1081. "ack_frame_rssi = %d \n"
  1082. "first_msdu = %d \n"
  1083. "last_msdu = %d \n"
  1084. "msdu_part_of_amsdu = %d \n"
  1085. "rate_stats valid = %d \n"
  1086. "bw = %d \n"
  1087. "pkt_type = %d \n"
  1088. "stbc = %d \n"
  1089. "ldpc = %d \n"
  1090. "sgi = %d \n"
  1091. "mcs = %d \n"
  1092. "ofdma = %d \n"
  1093. "tones_in_ru = %d \n"
  1094. "tsf = %d \n"
  1095. "ppdu_id = %d \n"
  1096. "transmit_cnt = %d \n"
  1097. "tid = %d \n"
  1098. "peer_id = %d \n",
  1099. ts.ack_frame_rssi, ts.first_msdu, ts.last_msdu,
  1100. ts.msdu_part_of_amsdu, ts.valid, ts.bw,
  1101. ts.pkt_type, ts.stbc, ts.ldpc, ts.sgi,
  1102. ts.mcs, ts.ofdma, ts.tones_in_ru, ts.tsf,
  1103. ts.ppdu_id, ts.transmit_cnt, ts.tid,
  1104. ts.peer_id);
  1105. if (qdf_unlikely(tx_desc->vdev->mesh_vdev))
  1106. dp_tx_comp_fill_tx_completion_stats(tx_desc, &ts);
  1107. if (!vdev) {
  1108. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1109. "invalid peer");
  1110. goto fail;
  1111. }
  1112. soc = tx_desc->vdev->pdev->soc;
  1113. peer = dp_peer_find_by_id(soc, ts.peer_id);
  1114. if (!peer) {
  1115. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1116. "invalid peer");
  1117. DP_STATS_INC_PKT(vdev->pdev, dropped.no_peer, 1, length);
  1118. goto out;
  1119. }
  1120. DP_STATS_INC_PKT(peer, tx.comp_pkt, 1, length);
  1121. if (HAL_TX_COMP_RELEASE_SOURCE_TQM ==
  1122. hal_tx_comp_get_buffer_source(&tx_desc->comp)) {
  1123. comp_status = hal_tx_comp_get_release_reason(&tx_desc->comp);
  1124. DP_STATS_INCC(peer, tx.dropped.mpdu_age_out, 1,
  1125. (comp_status == HAL_TX_TQM_RR_REM_CMD_AGED));
  1126. DP_STATS_INCC(peer, tx.dropped.fw_discard_reason1, 1,
  1127. (comp_status == HAL_TX_TQM_RR_FW_REASON1));
  1128. DP_STATS_INCC(peer, tx.dropped.fw_discard_reason2, 1,
  1129. (comp_status == HAL_TX_TQM_RR_FW_REASON2));
  1130. DP_STATS_INCC(peer, tx.dropped.fw_discard_reason3, 1,
  1131. (comp_status == HAL_TX_TQM_RR_FW_REASON3));
  1132. DP_STATS_INCC(peer, tx.tx_failed, 1,
  1133. comp_status != HAL_TX_TQM_RR_FRAME_ACKED);
  1134. if (comp_status == HAL_TX_TQM_RR_FRAME_ACKED) {
  1135. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1136. mcs_count[MAX_MCS], 1,
  1137. ((ts.mcs >= MAX_MCS_11A) && (ts.pkt_type
  1138. == DOT11_A)));
  1139. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1140. mcs_count[ts.mcs], 1,
  1141. ((ts.mcs <= MAX_MCS_11A) && (ts.pkt_type
  1142. == DOT11_A)));
  1143. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1144. mcs_count[MAX_MCS], 1,
  1145. ((ts.mcs >= MAX_MCS_11B)
  1146. && (ts.pkt_type == DOT11_B)));
  1147. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1148. mcs_count[ts.mcs], 1,
  1149. ((ts.mcs <= MAX_MCS_11B)
  1150. && (ts.pkt_type == DOT11_B)));
  1151. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1152. mcs_count[MAX_MCS], 1,
  1153. ((ts.mcs >= MAX_MCS_11A)
  1154. && (ts.pkt_type == DOT11_N)));
  1155. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1156. mcs_count[ts.mcs], 1,
  1157. ((ts.mcs <= MAX_MCS_11A)
  1158. && (ts.pkt_type == DOT11_N)));
  1159. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1160. mcs_count[MAX_MCS], 1,
  1161. ((ts.mcs >= MAX_MCS_11AC)
  1162. && (ts.pkt_type == DOT11_AC)));
  1163. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1164. mcs_count[ts.mcs], 1,
  1165. ((ts.mcs <= MAX_MCS_11AC)
  1166. && (ts.pkt_type == DOT11_AC)));
  1167. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1168. mcs_count[MAX_MCS], 1,
  1169. ((ts.mcs >= MAX_MCS)
  1170. && (ts.pkt_type == DOT11_AX)));
  1171. DP_STATS_INCC(peer, tx.pkt_type[ts.pkt_type].
  1172. mcs_count[ts.mcs], 1,
  1173. ((ts.mcs <= MAX_MCS)
  1174. && (ts.pkt_type == DOT11_AX)));
  1175. DP_STATS_INC(peer, tx.sgi_count[ts.sgi], 1);
  1176. DP_STATS_INC(peer, tx.bw[ts.bw], 1);
  1177. DP_STATS_UPD(peer, tx.last_ack_rssi, ts.ack_frame_rssi);
  1178. DP_STATS_INC(peer, tx.wme_ac_type[TID_TO_WME_AC(ts.tid)]
  1179. , 1);
  1180. DP_STATS_INC_PKT(peer, tx.tx_success, 1, length);
  1181. DP_STATS_INCC(peer, tx.stbc, 1, ts.stbc);
  1182. DP_STATS_INCC(peer, tx.ofdma, 1, ts.ofdma);
  1183. DP_STATS_INCC(peer, tx.ldpc, 1, ts.ldpc);
  1184. DP_STATS_INCC(peer, tx.non_amsdu_cnt, 1,
  1185. (ts.first_msdu && ts.last_msdu));
  1186. DP_STATS_INCC(peer, tx.amsdu_cnt, 1,
  1187. !(ts.first_msdu && ts.last_msdu));
  1188. DP_STATS_INCC(peer, tx.retries, 1, ts.transmit_cnt > 1);
  1189. }
  1190. }
  1191. /* TODO: This call is temporary.
  1192. * Stats update has to be attached to the HTT PPDU message
  1193. */
  1194. if (soc->cdp_soc.ol_ops->update_dp_stats)
  1195. soc->cdp_soc.ol_ops->update_dp_stats(vdev->pdev->osif_pdev,
  1196. &peer->stats, ts.peer_id, UPDATE_PEER_STATS);
  1197. out:
  1198. dp_aggregate_vdev_stats(tx_desc->vdev);
  1199. if (soc->cdp_soc.ol_ops->update_dp_stats)
  1200. soc->cdp_soc.ol_ops->update_dp_stats(vdev->pdev->osif_pdev,
  1201. &vdev->stats, vdev->vdev_id, UPDATE_VDEV_STATS);
  1202. fail:
  1203. return;
  1204. }
  1205. /**
  1206. * dp_tx_comp_process_desc() - Tx complete software descriptor handler
  1207. * @soc: core txrx main context
  1208. * @comp_head: software descriptor head pointer
  1209. *
  1210. * This function will process batch of descriptors reaped by dp_tx_comp_handler
  1211. * and release the software descriptors after processing is complete
  1212. *
  1213. * Return: none
  1214. */
  1215. static void dp_tx_comp_process_desc(struct dp_soc *soc,
  1216. struct dp_tx_desc_s *comp_head)
  1217. {
  1218. struct dp_tx_desc_s *desc;
  1219. struct dp_tx_desc_s *next;
  1220. struct hal_tx_completion_status ts = {0};
  1221. uint32_t length;
  1222. struct dp_peer *peer;
  1223. desc = comp_head;
  1224. while (desc) {
  1225. hal_tx_comp_get_status(&desc->comp, &ts);
  1226. peer = dp_peer_find_by_id(soc, ts.peer_id);
  1227. length = qdf_nbuf_len(desc->nbuf);
  1228. /* Error Handling */
  1229. if (hal_tx_comp_get_buffer_source(&desc->comp) ==
  1230. HAL_TX_COMP_RELEASE_SOURCE_FW) {
  1231. dp_tx_comp_process_exception(desc);
  1232. desc = desc->next;
  1233. continue;
  1234. }
  1235. /* Process Tx status in descriptor */
  1236. if (soc->process_tx_status ||
  1237. (desc->vdev && desc->vdev->mesh_vdev))
  1238. dp_tx_comp_process_tx_status(desc, length);
  1239. /* 0 : MSDU buffer, 1 : MLE */
  1240. if (desc->msdu_ext_desc) {
  1241. /* TSO free */
  1242. if (hal_tx_ext_desc_get_tso_enable(
  1243. desc->msdu_ext_desc->vaddr)) {
  1244. /* If remaining number of segment is 0
  1245. * actual TSO may unmap and free */
  1246. if (!DP_DESC_NUM_FRAG(desc)) {
  1247. qdf_nbuf_unmap(soc->osdev, desc->nbuf,
  1248. QDF_DMA_TO_DEVICE);
  1249. qdf_nbuf_free(desc->nbuf);
  1250. }
  1251. } else {
  1252. /* SG free */
  1253. /* Free buffer */
  1254. DP_TX_FREE_DMA_TO_DEVICE(soc, desc->vdev,
  1255. desc->nbuf);
  1256. }
  1257. } else {
  1258. /* Free buffer */
  1259. DP_TX_FREE_DMA_TO_DEVICE(soc, desc->vdev, desc->nbuf);
  1260. }
  1261. next = desc->next;
  1262. dp_tx_desc_release(desc, desc->pool_id);
  1263. desc = next;
  1264. }
  1265. }
  1266. /**
  1267. * dp_tx_comp_handler() - Tx completion handler
  1268. * @soc: core txrx main context
  1269. * @ring_id: completion ring id
  1270. * @budget: No. of packets/descriptors that can be serviced in one loop
  1271. *
  1272. * This function will collect hardware release ring element contents and
  1273. * handle descriptor contents. Based on contents, free packet or handle error
  1274. * conditions
  1275. *
  1276. * Return: none
  1277. */
  1278. uint32_t dp_tx_comp_handler(struct dp_soc *soc, uint32_t ring_id,
  1279. uint32_t budget)
  1280. {
  1281. void *tx_comp_hal_desc;
  1282. uint8_t buffer_src;
  1283. uint8_t pool_id;
  1284. uint32_t tx_desc_id;
  1285. struct dp_tx_desc_s *tx_desc = NULL;
  1286. struct dp_tx_desc_s *head_desc = NULL;
  1287. struct dp_tx_desc_s *tail_desc = NULL;
  1288. uint32_t num_processed;
  1289. void *hal_srng = soc->tx_comp_ring[ring_id].hal_srng;
  1290. if (qdf_unlikely(hal_srng_access_start(soc->hal_soc, hal_srng))) {
  1291. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1292. "%s %d : HAL RING Access Failed -- %p\n",
  1293. __func__, __LINE__, hal_srng);
  1294. return 0;
  1295. }
  1296. num_processed = 0;
  1297. /* Find head descriptor from completion ring */
  1298. while (qdf_likely(tx_comp_hal_desc =
  1299. hal_srng_dst_get_next(soc->hal_soc, hal_srng))) {
  1300. buffer_src = hal_tx_comp_get_buffer_source(tx_comp_hal_desc);
  1301. /* If this buffer was not released by TQM or FW, then it is not
  1302. * Tx completion indication, skip to next descriptor */
  1303. if ((buffer_src != HAL_TX_COMP_RELEASE_SOURCE_TQM) &&
  1304. (buffer_src != HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  1305. QDF_TRACE(QDF_MODULE_ID_DP,
  1306. QDF_TRACE_LEVEL_ERROR,
  1307. "Tx comp release_src != TQM | FW");
  1308. /* TODO Handle Freeing of the buffer in descriptor */
  1309. continue;
  1310. }
  1311. /* Get descriptor id */
  1312. tx_desc_id = hal_tx_comp_get_desc_id(tx_comp_hal_desc);
  1313. pool_id = (tx_desc_id & DP_TX_DESC_ID_POOL_MASK) >>
  1314. DP_TX_DESC_ID_POOL_OS;
  1315. /* Pool ID is out of limit. Error */
  1316. if (pool_id > wlan_cfg_get_num_tx_desc_pool(
  1317. soc->wlan_cfg_ctx)) {
  1318. QDF_TRACE(QDF_MODULE_ID_DP,
  1319. QDF_TRACE_LEVEL_FATAL,
  1320. "TX COMP pool id %d not valid",
  1321. pool_id);
  1322. /* Check if assert aborts execution, if not handle
  1323. * return here */
  1324. QDF_ASSERT(0);
  1325. }
  1326. /* Find Tx descriptor */
  1327. tx_desc = dp_tx_desc_find(soc, pool_id,
  1328. (tx_desc_id & DP_TX_DESC_ID_PAGE_MASK) >>
  1329. DP_TX_DESC_ID_PAGE_OS,
  1330. (tx_desc_id & DP_TX_DESC_ID_OFFSET_MASK) >>
  1331. DP_TX_DESC_ID_OFFSET_OS);
  1332. /* Pool id is not matching. Error */
  1333. if (tx_desc && (tx_desc->pool_id != pool_id)) {
  1334. QDF_TRACE(QDF_MODULE_ID_DP,
  1335. QDF_TRACE_LEVEL_FATAL,
  1336. "Tx Comp pool id %d not matched %d",
  1337. pool_id, tx_desc->pool_id);
  1338. /* Check if assert aborts execution, if not handle
  1339. * return here */
  1340. QDF_ASSERT(0);
  1341. }
  1342. if (!(tx_desc->flags & DP_TX_DESC_FLAG_ALLOCATED) ||
  1343. !(tx_desc->flags & DP_TX_DESC_FLAG_QUEUED_TX)) {
  1344. QDF_TRACE(QDF_MODULE_ID_DP,
  1345. QDF_TRACE_LEVEL_FATAL,
  1346. "Txdesc invalid, flgs = %x,id = %d",
  1347. tx_desc->flags, tx_desc_id);
  1348. /* TODO Handle Freeing of the buffer in this invalid
  1349. * descriptor */
  1350. continue;
  1351. }
  1352. /*
  1353. * If the release source is FW, process the HTT
  1354. * status
  1355. */
  1356. if (qdf_unlikely(buffer_src ==
  1357. HAL_TX_COMP_RELEASE_SOURCE_FW)) {
  1358. uint8_t htt_tx_status[HAL_TX_COMP_HTT_STATUS_LEN];
  1359. hal_tx_comp_get_htt_desc(tx_comp_hal_desc,
  1360. htt_tx_status);
  1361. dp_tx_process_htt_completion(tx_desc,
  1362. htt_tx_status);
  1363. } else {
  1364. tx_desc->next = NULL;
  1365. /* First ring descriptor on the cycle */
  1366. if (!head_desc) {
  1367. head_desc = tx_desc;
  1368. } else {
  1369. tail_desc->next = tx_desc;
  1370. }
  1371. tail_desc = tx_desc;
  1372. /* Collect hw completion contents */
  1373. hal_tx_comp_desc_sync(tx_comp_hal_desc,
  1374. &tx_desc->comp, soc->process_tx_status);
  1375. }
  1376. num_processed++;
  1377. /*
  1378. * Processed packet count is more than given quota
  1379. * stop to processing
  1380. */
  1381. if (num_processed >= budget)
  1382. break;
  1383. }
  1384. hal_srng_access_end(soc->hal_soc, hal_srng);
  1385. /* Process the reaped descriptors */
  1386. if (head_desc)
  1387. dp_tx_comp_process_desc(soc, head_desc);
  1388. return num_processed;
  1389. }
  1390. /**
  1391. * dp_tx_vdev_attach() - attach vdev to dp tx
  1392. * @vdev: virtual device instance
  1393. *
  1394. * Return: QDF_STATUS_SUCCESS: success
  1395. * QDF_STATUS_E_RESOURCES: Error return
  1396. */
  1397. QDF_STATUS dp_tx_vdev_attach(struct dp_vdev *vdev)
  1398. {
  1399. /*
  1400. * Fill HTT TCL Metadata with Vdev ID and MAC ID
  1401. */
  1402. HTT_TX_TCL_METADATA_TYPE_SET(vdev->htt_tcl_metadata,
  1403. HTT_TCL_METADATA_TYPE_VDEV_BASED);
  1404. HTT_TX_TCL_METADATA_VDEV_ID_SET(vdev->htt_tcl_metadata,
  1405. vdev->vdev_id);
  1406. HTT_TX_TCL_METADATA_PDEV_ID_SET(vdev->htt_tcl_metadata,
  1407. DP_SW2HW_MACID(vdev->pdev->pdev_id));
  1408. /*
  1409. * Set HTT Extension Valid bit to 0 by default
  1410. */
  1411. HTT_TX_TCL_METADATA_VALID_HTT_SET(vdev->htt_tcl_metadata, 0);
  1412. return QDF_STATUS_SUCCESS;
  1413. }
  1414. /**
  1415. * dp_tx_vdev_detach() - detach vdev from dp tx
  1416. * @vdev: virtual device instance
  1417. *
  1418. * Return: QDF_STATUS_SUCCESS: success
  1419. * QDF_STATUS_E_RESOURCES: Error return
  1420. */
  1421. QDF_STATUS dp_tx_vdev_detach(struct dp_vdev *vdev)
  1422. {
  1423. return QDF_STATUS_SUCCESS;
  1424. }
  1425. /**
  1426. * dp_tx_pdev_attach() - attach pdev to dp tx
  1427. * @pdev: physical device instance
  1428. *
  1429. * Return: QDF_STATUS_SUCCESS: success
  1430. * QDF_STATUS_E_RESOURCES: Error return
  1431. */
  1432. QDF_STATUS dp_tx_pdev_attach(struct dp_pdev *pdev)
  1433. {
  1434. struct dp_soc *soc = pdev->soc;
  1435. /* Initialize Flow control counters */
  1436. qdf_atomic_init(&pdev->num_tx_exception);
  1437. qdf_atomic_init(&pdev->num_tx_outstanding);
  1438. if (wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  1439. /* Initialize descriptors in TCL Ring */
  1440. hal_tx_init_data_ring(soc->hal_soc,
  1441. soc->tcl_data_ring[pdev->pdev_id].hal_srng);
  1442. }
  1443. return QDF_STATUS_SUCCESS;
  1444. }
  1445. /**
  1446. * dp_tx_pdev_detach() - detach pdev from dp tx
  1447. * @pdev: physical device instance
  1448. *
  1449. * Return: QDF_STATUS_SUCCESS: success
  1450. * QDF_STATUS_E_RESOURCES: Error return
  1451. */
  1452. QDF_STATUS dp_tx_pdev_detach(struct dp_pdev *pdev)
  1453. {
  1454. /* What should do here? */
  1455. return QDF_STATUS_SUCCESS;
  1456. }
  1457. /**
  1458. * dp_tx_soc_detach() - detach soc from dp tx
  1459. * @soc: core txrx main context
  1460. *
  1461. * This function will detach dp tx into main device context
  1462. * will free dp tx resource and initialize resources
  1463. *
  1464. * Return: QDF_STATUS_SUCCESS: success
  1465. * QDF_STATUS_E_RESOURCES: Error return
  1466. */
  1467. QDF_STATUS dp_tx_soc_detach(struct dp_soc *soc)
  1468. {
  1469. uint8_t num_pool;
  1470. uint16_t num_desc;
  1471. uint16_t num_ext_desc;
  1472. uint8_t i;
  1473. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  1474. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  1475. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  1476. for (i = 0; i < num_pool; i++) {
  1477. if (dp_tx_desc_pool_free(soc, i)) {
  1478. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1479. "%s Tx Desc Pool Free failed\n",
  1480. __func__);
  1481. return QDF_STATUS_E_RESOURCES;
  1482. }
  1483. }
  1484. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1485. "%s Tx Desc Pool Free num_pool = %d, descs = %d\n",
  1486. __func__, num_pool, num_desc);
  1487. for (i = 0; i < num_pool; i++) {
  1488. if (dp_tx_ext_desc_pool_free(soc, i)) {
  1489. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1490. "%s Tx Ext Desc Pool Free failed\n",
  1491. __func__);
  1492. return QDF_STATUS_E_RESOURCES;
  1493. }
  1494. }
  1495. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1496. "%s MSDU Ext Desc Pool %d Free descs = %d\n",
  1497. __func__, num_pool, num_ext_desc);
  1498. return QDF_STATUS_SUCCESS;
  1499. }
  1500. /**
  1501. * dp_tx_soc_attach() - attach soc to dp tx
  1502. * @soc: core txrx main context
  1503. *
  1504. * This function will attach dp tx into main device context
  1505. * will allocate dp tx resource and initialize resources
  1506. *
  1507. * Return: QDF_STATUS_SUCCESS: success
  1508. * QDF_STATUS_E_RESOURCES: Error return
  1509. */
  1510. QDF_STATUS dp_tx_soc_attach(struct dp_soc *soc)
  1511. {
  1512. uint8_t num_pool;
  1513. uint32_t num_desc;
  1514. uint32_t num_ext_desc;
  1515. uint8_t i;
  1516. num_pool = wlan_cfg_get_num_tx_desc_pool(soc->wlan_cfg_ctx);
  1517. num_desc = wlan_cfg_get_num_tx_desc(soc->wlan_cfg_ctx);
  1518. num_ext_desc = wlan_cfg_get_num_tx_ext_desc(soc->wlan_cfg_ctx);
  1519. /* Allocate software Tx descriptor pools */
  1520. for (i = 0; i < num_pool; i++) {
  1521. if (dp_tx_desc_pool_alloc(soc, i, num_desc)) {
  1522. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1523. "%s Tx Desc Pool alloc %d failed %p\n",
  1524. __func__, i, soc);
  1525. goto fail;
  1526. }
  1527. }
  1528. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1529. "%s Tx Desc Alloc num_pool = %d, descs = %d\n",
  1530. __func__, num_pool, num_desc);
  1531. /* Allocate extension tx descriptor pools */
  1532. for (i = 0; i < num_pool; i++) {
  1533. if (dp_tx_ext_desc_pool_alloc(soc, i, num_ext_desc)) {
  1534. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  1535. "MSDU Ext Desc Pool alloc %d failed %p\n",
  1536. i, soc);
  1537. goto fail;
  1538. }
  1539. }
  1540. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1541. "%s MSDU Ext Desc Alloc %d, descs = %d\n",
  1542. __func__, num_pool, num_ext_desc);
  1543. /* Initialize descriptors in TCL Rings */
  1544. if (!wlan_cfg_per_pdev_tx_ring(soc->wlan_cfg_ctx)) {
  1545. for (i = 0; i < soc->num_tcl_data_rings; i++) {
  1546. hal_tx_init_data_ring(soc->hal_soc,
  1547. soc->tcl_data_ring[i].hal_srng);
  1548. }
  1549. }
  1550. /*
  1551. * todo - Add a runtime config option to enable this.
  1552. */
  1553. /*
  1554. * Due to multiple issues on NPR EMU, enable it selectively
  1555. * only for NPR EMU, should be removed, once NPR platforms
  1556. * are stable.
  1557. */
  1558. soc->process_tx_status = 1;
  1559. /* Initialize Default DSCP-TID mapping table in TCL */
  1560. hal_tx_set_dscp_tid_map(soc->hal_soc, default_dscp_tid_map,
  1561. HAL_TX_DSCP_TID_MAP_TABLE_DEFAULT);
  1562. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_INFO,
  1563. "%s HAL Tx init Success\n", __func__);
  1564. return QDF_STATUS_SUCCESS;
  1565. fail:
  1566. /* Detach will take care of freeing only allocated resources */
  1567. dp_tx_soc_detach(soc);
  1568. return QDF_STATUS_E_RESOURCES;
  1569. }