dp_tx.c 45 KB

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