dp_tx.c 42 KB

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