dp_tx.c 42 KB

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