dp_tx.c 42 KB

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