dp_tx.c 41 KB

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