dp_tx.c 41 KB

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