dp_tx.c 42 KB

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