dp_tx.c 42 KB

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