dp_rx_mon_dest.c 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. /*
  2. * Copyright (c) 2017-2020 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 "hal_hw_headers.h"
  19. #include "dp_types.h"
  20. #include "dp_rx.h"
  21. #include "dp_peer.h"
  22. #include "hal_rx.h"
  23. #include "hal_api.h"
  24. #include "qdf_trace.h"
  25. #include "qdf_nbuf.h"
  26. #include "hal_api_mon.h"
  27. #include "dp_rx_mon.h"
  28. #include "wlan_cfg.h"
  29. #include "dp_internal.h"
  30. #include "dp_rx_buffer_pool.h"
  31. #ifdef WLAN_TX_PKT_CAPTURE_ENH
  32. #include "dp_rx_mon_feature.h"
  33. static inline void
  34. dp_handle_tx_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  35. qdf_nbuf_t mon_mpdu)
  36. {
  37. struct hal_rx_ppdu_info *ppdu_info = &pdev->ppdu_info;
  38. if (pdev->tx_capture_enabled
  39. == CDP_TX_ENH_CAPTURE_DISABLED)
  40. return;
  41. if ((ppdu_info->sw_frame_group_id ==
  42. HAL_MPDU_SW_FRAME_GROUP_CTRL_NDPA) ||
  43. (ppdu_info->sw_frame_group_id ==
  44. HAL_MPDU_SW_FRAME_GROUP_CTRL_BAR))
  45. dp_handle_tx_capture_from_dest(soc, pdev, mon_mpdu);
  46. }
  47. static void
  48. dp_tx_capture_get_user_id(struct dp_pdev *dp_pdev, void *rx_desc_tlv)
  49. {
  50. if (dp_pdev->tx_capture_enabled
  51. != CDP_TX_ENH_CAPTURE_DISABLED)
  52. dp_pdev->ppdu_info.rx_info.user_id =
  53. HAL_RX_HW_DESC_MPDU_USER_ID(rx_desc_tlv);
  54. }
  55. #else
  56. static inline void
  57. dp_handle_tx_capture(struct dp_soc *soc, struct dp_pdev *pdev,
  58. qdf_nbuf_t mon_mpdu)
  59. {
  60. }
  61. static void
  62. dp_tx_capture_get_user_id(struct dp_pdev *dp_pdev, void *rx_desc_tlv)
  63. {
  64. }
  65. #endif
  66. /*
  67. * The protocol flow tag size
  68. * if DP_RX_MON_MEM_FRAG is enabled.
  69. */
  70. #ifdef DP_RX_MON_MEM_FRAG
  71. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  72. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  73. #define DP_RX_MON_PF_TAG_TOT_LEN (64)
  74. #endif
  75. #endif
  76. /*
  77. * PPDU id is from 0 to 64k-1. PPDU id read from status ring and PPDU id
  78. * read from destination ring shall track each other. If the distance of
  79. * two ppdu id is less than 20000. It is assume no wrap around. Otherwise,
  80. * It is assume wrap around.
  81. */
  82. #define NOT_PPDU_ID_WRAP_AROUND 20000
  83. /*
  84. * The destination ring processing is stuck if the destrination is not
  85. * moving while status ring moves 16 ppdu. the destination ring processing
  86. * skips this destination ring ppdu as walkaround
  87. */
  88. #define MON_DEST_RING_STUCK_MAX_CNT 16
  89. /**
  90. * dp_rx_mon_link_desc_return() - Return a MPDU link descriptor to HW
  91. * (WBM), following error handling
  92. *
  93. * @dp_pdev: core txrx pdev context
  94. * @buf_addr_info: void pointer to monitor link descriptor buf addr info
  95. * Return: QDF_STATUS
  96. */
  97. QDF_STATUS
  98. dp_rx_mon_link_desc_return(struct dp_pdev *dp_pdev,
  99. hal_buff_addrinfo_t buf_addr_info, int mac_id)
  100. {
  101. struct dp_srng *dp_srng;
  102. hal_ring_handle_t hal_ring_hdl;
  103. hal_soc_handle_t hal_soc;
  104. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  105. void *src_srng_desc;
  106. hal_soc = dp_pdev->soc->hal_soc;
  107. dp_srng = &dp_pdev->soc->rxdma_mon_desc_ring[mac_id];
  108. hal_ring_hdl = dp_srng->hal_srng;
  109. qdf_assert(hal_ring_hdl);
  110. if (qdf_unlikely(hal_srng_access_start(hal_soc, hal_ring_hdl))) {
  111. /* TODO */
  112. /*
  113. * Need API to convert from hal_ring pointer to
  114. * Ring Type / Ring Id combo
  115. */
  116. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  117. "%s %d : \
  118. HAL RING Access For WBM Release SRNG Failed -- %pK",
  119. __func__, __LINE__, hal_ring_hdl);
  120. goto done;
  121. }
  122. src_srng_desc = hal_srng_src_get_next(hal_soc, hal_ring_hdl);
  123. if (qdf_likely(src_srng_desc)) {
  124. /* Return link descriptor through WBM ring (SW2WBM)*/
  125. hal_rx_mon_msdu_link_desc_set(hal_soc,
  126. src_srng_desc, buf_addr_info);
  127. status = QDF_STATUS_SUCCESS;
  128. } else {
  129. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  130. "%s %d -- Monitor Link Desc WBM Release Ring Full",
  131. __func__, __LINE__);
  132. }
  133. done:
  134. hal_srng_access_end(hal_soc, hal_ring_hdl);
  135. return status;
  136. }
  137. /**
  138. * dp_rx_mon_mpdu_pop() - Return a MPDU link descriptor to HW
  139. * (WBM), following error handling
  140. *
  141. * @soc: core DP main context
  142. * @mac_id: mac id which is one of 3 mac_ids
  143. * @rxdma_dst_ring_desc: void pointer to monitor link descriptor buf addr info
  144. * @head_msdu: head of msdu to be popped
  145. * @tail_msdu: tail of msdu to be popped
  146. * @npackets: number of packet to be popped
  147. * @ppdu_id: ppdu id of processing ppdu
  148. * @head: head of descs list to be freed
  149. * @tail: tail of decs list to be freed
  150. *
  151. * Return: number of msdu in MPDU to be popped
  152. */
  153. static inline uint32_t
  154. dp_rx_mon_mpdu_pop(struct dp_soc *soc, uint32_t mac_id,
  155. hal_rxdma_desc_t rxdma_dst_ring_desc, qdf_nbuf_t *head_msdu,
  156. qdf_nbuf_t *tail_msdu, uint32_t *npackets, uint32_t *ppdu_id,
  157. union dp_rx_desc_list_elem_t **head,
  158. union dp_rx_desc_list_elem_t **tail)
  159. {
  160. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  161. void *rx_desc_tlv;
  162. void *rx_msdu_link_desc;
  163. qdf_nbuf_t msdu;
  164. qdf_nbuf_t last;
  165. struct hal_rx_msdu_list msdu_list;
  166. uint16_t num_msdus;
  167. uint32_t rx_buf_size, rx_pkt_offset;
  168. struct hal_buf_info buf_info;
  169. uint32_t rx_bufs_used = 0;
  170. uint32_t msdu_ppdu_id, msdu_cnt;
  171. uint8_t *data = NULL;
  172. uint32_t i;
  173. uint32_t total_frag_len = 0, frag_len = 0;
  174. bool is_frag, is_first_msdu;
  175. bool drop_mpdu = false, is_frag_non_raw = false;
  176. uint8_t bm_action = HAL_BM_ACTION_PUT_IN_IDLE_LIST;
  177. qdf_dma_addr_t buf_paddr = 0;
  178. uint32_t rx_link_buf_info[HAL_RX_BUFFINFO_NUM_DWORDS];
  179. struct cdp_mon_status *rs;
  180. if (qdf_unlikely(!dp_pdev)) {
  181. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  182. "pdev is null for mac_id = %d", mac_id);
  183. return rx_bufs_used;
  184. }
  185. msdu = 0;
  186. last = NULL;
  187. hal_rx_reo_ent_buf_paddr_get(rxdma_dst_ring_desc, &buf_info, &msdu_cnt);
  188. rs = &dp_pdev->rx_mon_recv_status;
  189. rs->cdp_rs_rxdma_err = false;
  190. if ((hal_rx_reo_ent_rxdma_push_reason_get(rxdma_dst_ring_desc) ==
  191. HAL_RX_WBM_RXDMA_PSH_RSN_ERROR)) {
  192. uint8_t rxdma_err =
  193. hal_rx_reo_ent_rxdma_error_code_get(
  194. rxdma_dst_ring_desc);
  195. if (qdf_unlikely((rxdma_err == HAL_RXDMA_ERR_FLUSH_REQUEST) ||
  196. (rxdma_err == HAL_RXDMA_ERR_MPDU_LENGTH) ||
  197. (rxdma_err == HAL_RXDMA_ERR_OVERFLOW) ||
  198. (rxdma_err == HAL_RXDMA_ERR_FCS && dp_pdev->mcopy_mode))) {
  199. drop_mpdu = true;
  200. dp_pdev->rx_mon_stats.dest_mpdu_drop++;
  201. }
  202. rs->cdp_rs_rxdma_err = true;
  203. }
  204. is_frag = false;
  205. is_first_msdu = true;
  206. do {
  207. /* WAR for duplicate link descriptors received from HW */
  208. if (qdf_unlikely(dp_pdev->mon_last_linkdesc_paddr ==
  209. buf_info.paddr)) {
  210. dp_pdev->rx_mon_stats.dup_mon_linkdesc_cnt++;
  211. return rx_bufs_used;
  212. }
  213. rx_msdu_link_desc =
  214. dp_rx_cookie_2_mon_link_desc(dp_pdev,
  215. buf_info, mac_id);
  216. qdf_assert_always(rx_msdu_link_desc);
  217. hal_rx_msdu_list_get(soc->hal_soc, rx_msdu_link_desc,
  218. &msdu_list, &num_msdus);
  219. for (i = 0; i < num_msdus; i++) {
  220. uint16_t l2_hdr_offset;
  221. struct dp_rx_desc *rx_desc = NULL;
  222. struct rx_desc_pool *rx_desc_pool;
  223. rx_desc = dp_rx_get_mon_desc(soc,
  224. msdu_list.sw_cookie[i]);
  225. qdf_assert_always(rx_desc);
  226. msdu = DP_RX_MON_GET_NBUF_FROM_DESC(rx_desc);
  227. buf_paddr = dp_rx_mon_get_paddr_from_desc(rx_desc);
  228. /* WAR for duplicate buffers received from HW */
  229. if (qdf_unlikely(dp_pdev->mon_last_buf_cookie ==
  230. msdu_list.sw_cookie[i] ||
  231. DP_RX_MON_IS_BUFFER_ADDR_NULL(rx_desc) ||
  232. msdu_list.paddr[i] != buf_paddr ||
  233. !rx_desc->in_use)) {
  234. /* Skip duplicate buffer and drop subsequent
  235. * buffers in this MPDU
  236. */
  237. drop_mpdu = true;
  238. dp_pdev->rx_mon_stats.dup_mon_buf_cnt++;
  239. dp_pdev->mon_last_linkdesc_paddr =
  240. buf_info.paddr;
  241. continue;
  242. }
  243. if (rx_desc->unmapped == 0) {
  244. rx_desc_pool = dp_rx_get_mon_desc_pool(soc,
  245. mac_id,
  246. dp_pdev->pdev_id);
  247. dp_rx_mon_buffer_unmap(soc, rx_desc,
  248. rx_desc_pool->buf_size);
  249. rx_desc->unmapped = 1;
  250. }
  251. if (dp_rx_buffer_pool_refill(soc, msdu,
  252. rx_desc->pool_id)) {
  253. drop_mpdu = true;
  254. msdu = NULL;
  255. dp_pdev->mon_last_linkdesc_paddr =
  256. buf_info.paddr;
  257. goto next_msdu;
  258. }
  259. if (drop_mpdu) {
  260. dp_pdev->mon_last_linkdesc_paddr =
  261. buf_info.paddr;
  262. dp_rx_mon_buffer_free(rx_desc);
  263. msdu = NULL;
  264. goto next_msdu;
  265. }
  266. data = dp_rx_mon_get_buffer_data(rx_desc);
  267. rx_desc_tlv = HAL_RX_MON_DEST_GET_DESC(data);
  268. QDF_TRACE(QDF_MODULE_ID_DP,
  269. QDF_TRACE_LEVEL_DEBUG,
  270. "[%s] i=%d, ppdu_id=%x, num_msdus = %u",
  271. __func__, i, *ppdu_id, num_msdus);
  272. if (is_first_msdu) {
  273. if (!hal_rx_mpdu_start_tlv_tag_valid(
  274. soc->hal_soc,
  275. rx_desc_tlv)) {
  276. drop_mpdu = true;
  277. dp_rx_mon_buffer_free(rx_desc);
  278. msdu = NULL;
  279. dp_pdev->mon_last_linkdesc_paddr =
  280. buf_info.paddr;
  281. goto next_msdu;
  282. }
  283. msdu_ppdu_id = hal_rx_hw_desc_get_ppduid_get(
  284. soc->hal_soc,
  285. rx_desc_tlv,
  286. rxdma_dst_ring_desc);
  287. is_first_msdu = false;
  288. QDF_TRACE(QDF_MODULE_ID_DP,
  289. QDF_TRACE_LEVEL_DEBUG,
  290. "[%s] msdu_ppdu_id=%x",
  291. __func__, msdu_ppdu_id);
  292. if (*ppdu_id > msdu_ppdu_id)
  293. QDF_TRACE(QDF_MODULE_ID_DP,
  294. QDF_TRACE_LEVEL_DEBUG,
  295. "[%s][%d] ppdu_id=%d "
  296. "msdu_ppdu_id=%d",
  297. __func__, __LINE__, *ppdu_id,
  298. msdu_ppdu_id);
  299. if ((*ppdu_id < msdu_ppdu_id) && (
  300. (msdu_ppdu_id - *ppdu_id) <
  301. NOT_PPDU_ID_WRAP_AROUND)) {
  302. *ppdu_id = msdu_ppdu_id;
  303. return rx_bufs_used;
  304. } else if ((*ppdu_id > msdu_ppdu_id) && (
  305. (*ppdu_id - msdu_ppdu_id) >
  306. NOT_PPDU_ID_WRAP_AROUND)) {
  307. *ppdu_id = msdu_ppdu_id;
  308. return rx_bufs_used;
  309. }
  310. dp_tx_capture_get_user_id(dp_pdev,
  311. rx_desc_tlv);
  312. if (*ppdu_id == msdu_ppdu_id)
  313. dp_pdev->rx_mon_stats.ppdu_id_match++;
  314. else
  315. dp_pdev->rx_mon_stats.ppdu_id_mismatch
  316. ++;
  317. dp_pdev->mon_last_linkdesc_paddr =
  318. buf_info.paddr;
  319. if (dp_rx_mon_alloc_parent_buffer(head_msdu)
  320. != QDF_STATUS_SUCCESS) {
  321. DP_STATS_INC(dp_pdev,
  322. replenish.nbuf_alloc_fail,
  323. 1);
  324. qdf_frag_free(rx_desc_tlv);
  325. QDF_TRACE(QDF_MODULE_ID_DP,
  326. QDF_TRACE_LEVEL_DEBUG,
  327. "[%s] failed to allocate parent buffer to hold all frag",
  328. __func__);
  329. drop_mpdu = true;
  330. goto next_msdu;
  331. }
  332. }
  333. if (hal_rx_desc_is_first_msdu(soc->hal_soc,
  334. rx_desc_tlv))
  335. hal_rx_mon_hw_desc_get_mpdu_status(soc->hal_soc,
  336. rx_desc_tlv,
  337. &(dp_pdev->ppdu_info.rx_status));
  338. dp_rx_mon_parse_desc_buffer(soc,
  339. &(msdu_list.msdu_info[i]),
  340. &is_frag,
  341. &total_frag_len,
  342. &frag_len,
  343. &l2_hdr_offset,
  344. rx_desc_tlv,
  345. &is_frag_non_raw, data);
  346. if (!is_frag)
  347. msdu_cnt--;
  348. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  349. "%s total_len %u frag_len %u flags %u",
  350. __func__, total_frag_len, frag_len,
  351. msdu_list.msdu_info[i].msdu_flags);
  352. rx_pkt_offset = SIZE_OF_MONITOR_TLV;
  353. rx_buf_size = rx_pkt_offset + l2_hdr_offset
  354. + frag_len;
  355. dp_rx_mon_buffer_set_pktlen(msdu, rx_buf_size);
  356. #if 0
  357. /* Disble it.see packet on msdu done set to 0 */
  358. /*
  359. * Check if DMA completed -- msdu_done is the
  360. * last bit to be written
  361. */
  362. if (!hal_rx_attn_msdu_done_get(rx_desc_tlv)) {
  363. QDF_TRACE(QDF_MODULE_ID_DP,
  364. QDF_TRACE_LEVEL_ERROR,
  365. "%s:%d: Pkt Desc",
  366. __func__, __LINE__);
  367. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  368. QDF_TRACE_LEVEL_ERROR,
  369. rx_desc_tlv, 128);
  370. qdf_assert_always(0);
  371. }
  372. #endif
  373. QDF_TRACE(QDF_MODULE_ID_DP,
  374. QDF_TRACE_LEVEL_DEBUG,
  375. "%s: rx_pkt_offset=%d, l2_hdr_offset=%d, msdu_len=%d, frag_len %u",
  376. __func__, rx_pkt_offset, l2_hdr_offset,
  377. msdu_list.msdu_info[i].msdu_len,
  378. frag_len);
  379. dp_rx_mon_add_msdu_to_list(head_msdu, msdu, &last,
  380. rx_desc_tlv, frag_len,
  381. l2_hdr_offset);
  382. next_msdu:
  383. dp_pdev->mon_last_buf_cookie = msdu_list.sw_cookie[i];
  384. rx_bufs_used++;
  385. dp_rx_add_to_free_desc_list(head,
  386. tail, rx_desc);
  387. }
  388. /*
  389. * Store the current link buffer into to the local
  390. * structure to be used for release purpose.
  391. */
  392. hal_rxdma_buff_addr_info_set(rx_link_buf_info, buf_info.paddr,
  393. buf_info.sw_cookie, buf_info.rbm);
  394. hal_rx_mon_next_link_desc_get(rx_msdu_link_desc, &buf_info);
  395. if (dp_rx_monitor_link_desc_return(dp_pdev,
  396. (hal_buff_addrinfo_t)
  397. rx_link_buf_info,
  398. mac_id,
  399. bm_action)
  400. != QDF_STATUS_SUCCESS)
  401. dp_err_rl("monitor link desc return failed");
  402. } while (buf_info.paddr && msdu_cnt);
  403. dp_rx_mon_init_tail_msdu(msdu, last, tail_msdu);
  404. dp_rx_mon_remove_raw_frame_fcs_len(head_msdu);
  405. return rx_bufs_used;
  406. }
  407. static inline
  408. void dp_rx_msdus_set_payload(struct dp_soc *soc, qdf_nbuf_t msdu)
  409. {
  410. uint8_t *data;
  411. uint32_t rx_pkt_offset, l2_hdr_offset;
  412. data = qdf_nbuf_data(msdu);
  413. rx_pkt_offset = SIZE_OF_MONITOR_TLV;
  414. l2_hdr_offset = hal_rx_msdu_end_l3_hdr_padding_get(soc->hal_soc, data);
  415. qdf_nbuf_pull_head(msdu, rx_pkt_offset + l2_hdr_offset);
  416. }
  417. #ifdef DP_RX_MON_MEM_FRAG
  418. /**
  419. * dp_rx_mon_frag_restitch_mpdu_from_msdus() - Restitch logic to
  420. * convert to 802.3 header and adjust frag memory pointing to
  421. * dot3 header and payload in case of Non-Raw frame.
  422. *
  423. * @soc: struct dp_soc *
  424. * @mac_id: MAC id
  425. * @head_msdu: MPDU containing all MSDU as a frag
  426. * @rx_status: struct cdp_mon_status *
  427. *
  428. * Return: Adjusted nbuf containing MPDU worth info.
  429. */
  430. static inline
  431. qdf_nbuf_t dp_rx_mon_frag_restitch_mpdu_from_msdus(struct dp_soc *soc,
  432. uint32_t mac_id,
  433. qdf_nbuf_t head_msdu,
  434. struct cdp_mon_status *rx_status)
  435. {
  436. uint32_t wifi_hdr_len, sec_hdr_len, msdu_llc_len,
  437. mpdu_buf_len, decap_hdr_pull_bytes, dir,
  438. is_amsdu, amsdu_pad, frag_size, tot_msdu_len;
  439. qdf_frag_t rx_desc, rx_src_desc, rx_dest_desc, frag_addr;
  440. char *hdr_desc;
  441. uint8_t num_frags, frags_iter, l2_hdr_offset;
  442. struct ieee80211_frame *wh;
  443. struct ieee80211_qoscntl *qos;
  444. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  445. int16_t frag_page_offset = 0;
  446. struct hal_rx_mon_dest_buf_info buf_info;
  447. uint32_t pad_byte_pholder = 0;
  448. if (qdf_unlikely(!dp_pdev)) {
  449. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  450. "pdev is null for mac_id = %d", mac_id);
  451. return NULL;
  452. }
  453. qdf_mem_zero(&buf_info, sizeof(struct hal_rx_mon_dest_buf_info));
  454. if (!head_msdu)
  455. goto mpdu_stitch_fail;
  456. num_frags = qdf_nbuf_get_nr_frags(head_msdu);
  457. rx_desc = qdf_nbuf_get_frag_addr(head_msdu, 0) - SIZE_OF_MONITOR_TLV;
  458. if (HAL_RX_DESC_GET_MPDU_LENGTH_ERR(rx_desc)) {
  459. /* It looks like there is some issue on MPDU len err */
  460. /* Need further investigate if drop the packet */
  461. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  462. return NULL;
  463. }
  464. /* Look for FCS error */
  465. rx_desc =
  466. qdf_nbuf_get_frag_addr(head_msdu,
  467. num_frags - 1) - SIZE_OF_MONITOR_TLV;
  468. rx_status->cdp_rs_fcs_err = HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  469. dp_pdev->ppdu_info.rx_status.rs_fcs_err =
  470. HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  471. rx_desc = qdf_nbuf_get_frag_addr(head_msdu, 0) - SIZE_OF_MONITOR_TLV;
  472. hal_rx_mon_dest_get_buffer_info_from_tlv(rx_desc, &buf_info);
  473. /* Easy case - The MSDU status indicates that this is a non-decapped
  474. * packet in RAW mode.
  475. */
  476. if (buf_info.is_decap_raw == 1)
  477. goto mpdu_stitch_done;
  478. l2_hdr_offset = DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  479. /* Decap mode:
  480. * Calculate the amount of header in decapped packet to knock off based
  481. * on the decap type and the corresponding number of raw bytes to copy
  482. * status header
  483. */
  484. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  485. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  486. "[%s][%d] decap format not raw",
  487. __func__, __LINE__);
  488. /* Base size */
  489. wifi_hdr_len = sizeof(struct ieee80211_frame);
  490. wh = (struct ieee80211_frame *)hdr_desc;
  491. dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
  492. if (dir == IEEE80211_FC1_DIR_DSTODS)
  493. wifi_hdr_len += 6;
  494. is_amsdu = 0;
  495. if (wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) {
  496. qos = (struct ieee80211_qoscntl *)
  497. (hdr_desc + wifi_hdr_len);
  498. wifi_hdr_len += 2;
  499. is_amsdu = (qos->i_qos[0] & IEEE80211_QOS_AMSDU);
  500. }
  501. /*Calculate security header length based on 'Protected'
  502. * and 'EXT_IV' flag
  503. */
  504. if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
  505. char *iv = (char *)wh + wifi_hdr_len;
  506. if (iv[3] & KEY_EXTIV)
  507. sec_hdr_len = 8;
  508. else
  509. sec_hdr_len = 4;
  510. } else {
  511. sec_hdr_len = 0;
  512. }
  513. wifi_hdr_len += sec_hdr_len;
  514. /* MSDU related stuff LLC - AMSDU subframe header etc */
  515. msdu_llc_len = is_amsdu ? (14 + 8) : 8;
  516. mpdu_buf_len = wifi_hdr_len + msdu_llc_len;
  517. /* "Decap" header to remove from MSDU buffer */
  518. decap_hdr_pull_bytes = 14;
  519. amsdu_pad = 0;
  520. tot_msdu_len = 0;
  521. /*
  522. * keeping first MSDU ops outside of loop to avoid multiple
  523. * check handling
  524. */
  525. /* Construct src header */
  526. rx_src_desc = hdr_desc;
  527. /*
  528. * Update protocol and flow tag for MSDU
  529. * update frag index in ctx_idx field.
  530. * Reset head pointer data of nbuf before updating.
  531. */
  532. qdf_mem_zero(qdf_nbuf_head(head_msdu), DP_RX_MON_PF_TAG_TOT_LEN);
  533. QDF_NBUF_CB_RX_CTX_ID(head_msdu) = 0;
  534. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev, head_msdu, rx_desc);
  535. /* Construct destination address */
  536. frag_addr = qdf_nbuf_get_frag_addr(head_msdu, 0);
  537. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu, 0);
  538. /* We will come here in 2 scenario:
  539. * 1. First MSDU of MPDU with single buffer
  540. * 2. First buffer of First MSDU of MPDU with continuation
  541. *
  542. * ------------------------------------------------------------
  543. * | SINGLE BUFFER (<= RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN)|
  544. * ------------------------------------------------------------
  545. *
  546. * ------------------------------------------------------------
  547. * | First BUFFER with Continuation | ... |
  548. * | (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) | |
  549. * ------------------------------------------------------------
  550. */
  551. pad_byte_pholder =
  552. (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) - frag_size;
  553. /* Construct destination address
  554. * --------------------------------------------------------------
  555. * | RX_PKT_TLV | L2_HDR_PAD | Decap HDR | Payload |
  556. * | | / |
  557. * | >Frag address points here / |
  558. * | \ / |
  559. * | \ This bytes needs to / |
  560. * | \ removed to frame pkt / |
  561. * | ----------------------- |
  562. * | | |
  563. * | | |
  564. * | WIFI +LLC HDR will be added here <-| |
  565. * | | | |
  566. * | >Dest addr will point | |
  567. * | somewhere in this area | |
  568. * --------------------------------------------------------------
  569. */
  570. rx_dest_desc =
  571. (frag_addr + decap_hdr_pull_bytes + l2_hdr_offset) -
  572. mpdu_buf_len;
  573. /* Add WIFI and LLC header for 1st MSDU of MPDU */
  574. qdf_mem_copy(rx_dest_desc, rx_src_desc, mpdu_buf_len);
  575. frag_page_offset =
  576. (decap_hdr_pull_bytes + l2_hdr_offset) - mpdu_buf_len;
  577. qdf_nbuf_move_frag_page_offset(head_msdu, 0, frag_page_offset);
  578. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu, 0);
  579. if (buf_info.first_buffer && buf_info.last_buffer) {
  580. /* MSDU with single bufffer */
  581. amsdu_pad = frag_size & 0x3;
  582. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  583. if (amsdu_pad <= pad_byte_pholder) {
  584. qdf_nbuf_trim_add_frag_size(head_msdu, 0, amsdu_pad,
  585. 0);
  586. amsdu_pad = 0;
  587. }
  588. } else {
  589. /*
  590. * First buffer of Continuation frame and hence
  591. * amsdu_padding doesn't need to be added
  592. * Increase tot_msdu_len so that amsdu_pad byte
  593. * will be calculated for last frame of MSDU
  594. */
  595. tot_msdu_len = frag_size;
  596. amsdu_pad = 0;
  597. }
  598. /* Here amsdu_pad byte will have some value if 1sf buffer was
  599. * Single buffer MSDU and dint had pholder to adjust amsdu padding
  600. * byte in the end
  601. * So dont initialize to ZERO here
  602. */
  603. pad_byte_pholder = 0;
  604. for (frags_iter = 1; frags_iter < num_frags; frags_iter++) {
  605. /* Construct destination address
  606. * ----------------------------------------------------------
  607. * | RX_PKT_TLV | L2_HDR_PAD | Decap HDR | Payload | Pad |
  608. * | | (First buffer) | | |
  609. * | | / / |
  610. * | >Frag address points here / / |
  611. * | \ / / |
  612. * | \ This bytes needs to / / |
  613. * | \ removed to frame pkt/ / |
  614. * | ---------------------- / |
  615. * | | / Add |
  616. * | | / amsdu pad |
  617. * | LLC HDR will be added here <-| | Byte for |
  618. * | | | | last frame |
  619. * | >Dest addr will point | | if space |
  620. * | somewhere in this area | | available |
  621. * | And amsdu_pad will be created if | | |
  622. * | dint get added in last buffer | | |
  623. * | (First Buffer) | | |
  624. * ----------------------------------------------------------
  625. */
  626. frag_addr = qdf_nbuf_get_frag_addr(head_msdu, frags_iter);
  627. rx_desc = frag_addr - SIZE_OF_MONITOR_TLV;
  628. /*
  629. * Update protocol and flow tag for MSDU
  630. * update frag index in ctx_idx field
  631. */
  632. QDF_NBUF_CB_RX_CTX_ID(head_msdu) = frags_iter;
  633. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev,
  634. head_msdu, rx_desc);
  635. /* Read buffer info from stored data in tlvs */
  636. hal_rx_mon_dest_get_buffer_info_from_tlv(rx_desc,
  637. &buf_info);
  638. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu,
  639. frags_iter);
  640. /* If Middle buffer, dont add any header */
  641. if ((!buf_info.first_buffer) && (!buf_info.last_buffer)) {
  642. tot_msdu_len += frag_size;
  643. amsdu_pad = 0;
  644. pad_byte_pholder = 0;
  645. continue;
  646. }
  647. /* Calculate if current buffer has placeholder
  648. * to accommodate amsdu pad byte
  649. */
  650. pad_byte_pholder =
  651. (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) - frag_size;
  652. /*
  653. * We will come here only only three condition:
  654. * 1. Msdu with single Buffer
  655. * 2. First buffer in case MSDU is spread in multiple buffer
  656. * 3. Last buffer in case MSDU is spread in multiple buffer
  657. *
  658. * First buffER | Last buffer
  659. * Case 1: 1 | 1
  660. * Case 2: 1 | 0
  661. * Case 3: 0 | 1
  662. *
  663. * In 3rd case only l2_hdr_padding byte will be Zero and in
  664. * other case, It will be 2 Bytes.
  665. */
  666. if (buf_info.first_buffer)
  667. l2_hdr_offset = DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  668. else
  669. l2_hdr_offset = DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  670. if (buf_info.first_buffer) {
  671. /* Src addr from whre llc header needs to be copied */
  672. rx_src_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  673. /* Size of buffer with llc header */
  674. frag_size = frag_size -
  675. (l2_hdr_offset + decap_hdr_pull_bytes);
  676. frag_size += msdu_llc_len;
  677. /* Construct destination address */
  678. rx_dest_desc = frag_addr + decap_hdr_pull_bytes +
  679. l2_hdr_offset;
  680. rx_dest_desc = rx_dest_desc - (msdu_llc_len);
  681. qdf_mem_copy(rx_dest_desc, rx_src_desc, msdu_llc_len);
  682. /*
  683. * Calculate new page offset and create hole
  684. * if amsdu_pad required.
  685. */
  686. frag_page_offset = l2_hdr_offset +
  687. decap_hdr_pull_bytes;
  688. frag_page_offset = frag_page_offset -
  689. (msdu_llc_len + amsdu_pad);
  690. qdf_nbuf_move_frag_page_offset(head_msdu, frags_iter,
  691. frag_page_offset);
  692. tot_msdu_len = frag_size;
  693. /*
  694. * No amsdu padding required for first frame of
  695. * continuation buffer
  696. */
  697. if (!buf_info.last_buffer) {
  698. amsdu_pad = 0;
  699. continue;
  700. }
  701. } else {
  702. tot_msdu_len += frag_size;
  703. }
  704. /* Will reach to this place in only two case:
  705. * 1. Single buffer MSDU
  706. * 2. Last buffer of MSDU in case of multiple buffer MSDU
  707. */
  708. /* Check size of buffer if amsdu padding required */
  709. amsdu_pad = tot_msdu_len & 0x3;
  710. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  711. /* Create placeholder if current bufer can
  712. * accommodate padding.
  713. */
  714. if (amsdu_pad <= pad_byte_pholder) {
  715. qdf_nbuf_trim_add_frag_size(head_msdu, frags_iter,
  716. amsdu_pad, 0);
  717. amsdu_pad = 0;
  718. }
  719. /* reset tot_msdu_len */
  720. tot_msdu_len = 0;
  721. }
  722. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  723. "%s %d head_msdu %pK head_msdu->len %u",
  724. __func__, __LINE__,
  725. head_msdu, head_msdu->len);
  726. mpdu_stitch_done:
  727. return head_msdu;
  728. mpdu_stitch_fail:
  729. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  730. "%s mpdu_stitch_fail head_msdu %pK", __func__, head_msdu);
  731. return NULL;
  732. }
  733. #endif
  734. static inline
  735. qdf_nbuf_t dp_rx_mon_restitch_mpdu_from_msdus(struct dp_soc *soc,
  736. uint32_t mac_id, qdf_nbuf_t head_msdu, qdf_nbuf_t last_msdu,
  737. struct cdp_mon_status *rx_status)
  738. {
  739. qdf_nbuf_t msdu, mpdu_buf, prev_buf, msdu_orig, head_frag_list;
  740. uint32_t decap_format, wifi_hdr_len, sec_hdr_len, msdu_llc_len,
  741. mpdu_buf_len, decap_hdr_pull_bytes, frag_list_sum_len, dir,
  742. is_amsdu, is_first_frag, amsdu_pad;
  743. void *rx_desc;
  744. char *hdr_desc;
  745. unsigned char *dest;
  746. struct ieee80211_frame *wh;
  747. struct ieee80211_qoscntl *qos;
  748. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  749. head_frag_list = NULL;
  750. mpdu_buf = NULL;
  751. if (qdf_unlikely(!dp_pdev)) {
  752. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  753. "pdev is null for mac_id = %d", mac_id);
  754. return NULL;
  755. }
  756. /* The nbuf has been pulled just beyond the status and points to the
  757. * payload
  758. */
  759. if (!head_msdu)
  760. goto mpdu_stitch_fail;
  761. msdu_orig = head_msdu;
  762. rx_desc = qdf_nbuf_data(msdu_orig);
  763. if (HAL_RX_DESC_GET_MPDU_LENGTH_ERR(rx_desc)) {
  764. /* It looks like there is some issue on MPDU len err */
  765. /* Need further investigate if drop the packet */
  766. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  767. return NULL;
  768. }
  769. rx_desc = qdf_nbuf_data(last_msdu);
  770. rx_status->cdp_rs_fcs_err = HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  771. dp_pdev->ppdu_info.rx_status.rs_fcs_err =
  772. HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  773. /* Fill out the rx_status from the PPDU start and end fields */
  774. /* HAL_RX_GET_PPDU_STATUS(soc, mac_id, rx_status); */
  775. rx_desc = qdf_nbuf_data(head_msdu);
  776. decap_format = HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc);
  777. /* Easy case - The MSDU status indicates that this is a non-decapped
  778. * packet in RAW mode.
  779. */
  780. if (decap_format == HAL_HW_RX_DECAP_FORMAT_RAW) {
  781. /* Note that this path might suffer from headroom unavailabilty
  782. * - but the RX status is usually enough
  783. */
  784. dp_rx_msdus_set_payload(soc, head_msdu);
  785. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  786. "[%s][%d] decap format raw head %pK head->next %pK last_msdu %pK last_msdu->next %pK",
  787. __func__, __LINE__, head_msdu, head_msdu->next,
  788. last_msdu, last_msdu->next);
  789. mpdu_buf = head_msdu;
  790. prev_buf = mpdu_buf;
  791. frag_list_sum_len = 0;
  792. msdu = qdf_nbuf_next(head_msdu);
  793. is_first_frag = 1;
  794. while (msdu) {
  795. dp_rx_msdus_set_payload(soc, msdu);
  796. if (is_first_frag) {
  797. is_first_frag = 0;
  798. head_frag_list = msdu;
  799. }
  800. frag_list_sum_len += qdf_nbuf_len(msdu);
  801. /* Maintain the linking of the cloned MSDUS */
  802. qdf_nbuf_set_next_ext(prev_buf, msdu);
  803. /* Move to the next */
  804. prev_buf = msdu;
  805. msdu = qdf_nbuf_next(msdu);
  806. }
  807. qdf_nbuf_trim_tail(prev_buf, HAL_RX_FCS_LEN);
  808. /* If there were more fragments to this RAW frame */
  809. if (head_frag_list) {
  810. if (frag_list_sum_len <
  811. sizeof(struct ieee80211_frame_min_one)) {
  812. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  813. return NULL;
  814. }
  815. frag_list_sum_len -= HAL_RX_FCS_LEN;
  816. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  817. frag_list_sum_len);
  818. qdf_nbuf_set_next(mpdu_buf, NULL);
  819. }
  820. goto mpdu_stitch_done;
  821. }
  822. /* Decap mode:
  823. * Calculate the amount of header in decapped packet to knock off based
  824. * on the decap type and the corresponding number of raw bytes to copy
  825. * status header
  826. */
  827. rx_desc = qdf_nbuf_data(head_msdu);
  828. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  829. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  830. "[%s][%d] decap format not raw",
  831. __func__, __LINE__);
  832. /* Base size */
  833. wifi_hdr_len = sizeof(struct ieee80211_frame);
  834. wh = (struct ieee80211_frame *)hdr_desc;
  835. dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
  836. if (dir == IEEE80211_FC1_DIR_DSTODS)
  837. wifi_hdr_len += 6;
  838. is_amsdu = 0;
  839. if (wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) {
  840. qos = (struct ieee80211_qoscntl *)
  841. (hdr_desc + wifi_hdr_len);
  842. wifi_hdr_len += 2;
  843. is_amsdu = (qos->i_qos[0] & IEEE80211_QOS_AMSDU);
  844. }
  845. /*Calculate security header length based on 'Protected'
  846. * and 'EXT_IV' flag
  847. * */
  848. if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
  849. char *iv = (char *)wh + wifi_hdr_len;
  850. if (iv[3] & KEY_EXTIV)
  851. sec_hdr_len = 8;
  852. else
  853. sec_hdr_len = 4;
  854. } else {
  855. sec_hdr_len = 0;
  856. }
  857. wifi_hdr_len += sec_hdr_len;
  858. /* MSDU related stuff LLC - AMSDU subframe header etc */
  859. msdu_llc_len = is_amsdu ? (14 + 8) : 8;
  860. mpdu_buf_len = wifi_hdr_len + msdu_llc_len;
  861. /* "Decap" header to remove from MSDU buffer */
  862. decap_hdr_pull_bytes = 14;
  863. /* Allocate a new nbuf for holding the 802.11 header retrieved from the
  864. * status of the now decapped first msdu. Leave enough headroom for
  865. * accomodating any radio-tap /prism like PHY header
  866. */
  867. mpdu_buf = qdf_nbuf_alloc(soc->osdev,
  868. MAX_MONITOR_HEADER + mpdu_buf_len,
  869. MAX_MONITOR_HEADER, 4, FALSE);
  870. if (!mpdu_buf)
  871. goto mpdu_stitch_done;
  872. /* Copy the MPDU related header and enc headers into the first buffer
  873. * - Note that there can be a 2 byte pad between heaader and enc header
  874. */
  875. prev_buf = mpdu_buf;
  876. dest = qdf_nbuf_put_tail(prev_buf, wifi_hdr_len);
  877. if (!dest)
  878. goto mpdu_stitch_fail;
  879. qdf_mem_copy(dest, hdr_desc, wifi_hdr_len);
  880. hdr_desc += wifi_hdr_len;
  881. #if 0
  882. dest = qdf_nbuf_put_tail(prev_buf, sec_hdr_len);
  883. adf_os_mem_copy(dest, hdr_desc, sec_hdr_len);
  884. hdr_desc += sec_hdr_len;
  885. #endif
  886. /* The first LLC len is copied into the MPDU buffer */
  887. frag_list_sum_len = 0;
  888. msdu_orig = head_msdu;
  889. is_first_frag = 1;
  890. amsdu_pad = 0;
  891. while (msdu_orig) {
  892. /* TODO: intra AMSDU padding - do we need it ??? */
  893. msdu = msdu_orig;
  894. if (is_first_frag) {
  895. head_frag_list = msdu;
  896. } else {
  897. /* Reload the hdr ptr only on non-first MSDUs */
  898. rx_desc = qdf_nbuf_data(msdu_orig);
  899. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  900. }
  901. /* Copy this buffers MSDU related status into the prev buffer */
  902. if (is_first_frag) {
  903. is_first_frag = 0;
  904. }
  905. /* Update protocol and flow tag for MSDU */
  906. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev,
  907. msdu_orig, rx_desc);
  908. dest = qdf_nbuf_put_tail(prev_buf,
  909. msdu_llc_len + amsdu_pad);
  910. if (!dest)
  911. goto mpdu_stitch_fail;
  912. dest += amsdu_pad;
  913. qdf_mem_copy(dest, hdr_desc, msdu_llc_len);
  914. dp_rx_msdus_set_payload(soc, msdu);
  915. /* Push the MSDU buffer beyond the decap header */
  916. qdf_nbuf_pull_head(msdu, decap_hdr_pull_bytes);
  917. frag_list_sum_len += msdu_llc_len + qdf_nbuf_len(msdu)
  918. + amsdu_pad;
  919. /* Set up intra-AMSDU pad to be added to start of next buffer -
  920. * AMSDU pad is 4 byte pad on AMSDU subframe */
  921. amsdu_pad = (msdu_llc_len + qdf_nbuf_len(msdu)) & 0x3;
  922. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  923. /* TODO FIXME How do we handle MSDUs that have fraglist - Should
  924. * probably iterate all the frags cloning them along the way and
  925. * and also updating the prev_buf pointer
  926. */
  927. /* Move to the next */
  928. prev_buf = msdu;
  929. msdu_orig = qdf_nbuf_next(msdu_orig);
  930. }
  931. #if 0
  932. /* Add in the trailer section - encryption trailer + FCS */
  933. qdf_nbuf_put_tail(prev_buf, HAL_RX_FCS_LEN);
  934. frag_list_sum_len += HAL_RX_FCS_LEN;
  935. #endif
  936. frag_list_sum_len -= msdu_llc_len;
  937. /* TODO: Convert this to suitable adf routines */
  938. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  939. frag_list_sum_len);
  940. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  941. "%s %d mpdu_buf %pK mpdu_buf->len %u",
  942. __func__, __LINE__,
  943. mpdu_buf, mpdu_buf->len);
  944. mpdu_stitch_done:
  945. /* Check if this buffer contains the PPDU end status for TSF */
  946. /* Need revist this code to see where we can get tsf timestamp */
  947. #if 0
  948. /* PPDU end TLV will be retrieved from monitor status ring */
  949. last_mpdu =
  950. (*(((u_int32_t *)&rx_desc->attention)) &
  951. RX_ATTENTION_0_LAST_MPDU_MASK) >>
  952. RX_ATTENTION_0_LAST_MPDU_LSB;
  953. if (last_mpdu)
  954. rx_status->rs_tstamp.tsf = rx_desc->ppdu_end.tsf_timestamp;
  955. #endif
  956. return mpdu_buf;
  957. mpdu_stitch_fail:
  958. if ((mpdu_buf) && (decap_format != HAL_HW_RX_DECAP_FORMAT_RAW)) {
  959. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  960. "%s mpdu_stitch_fail mpdu_buf %pK",
  961. __func__, mpdu_buf);
  962. /* Free the head buffer */
  963. qdf_nbuf_free(mpdu_buf);
  964. }
  965. return NULL;
  966. }
  967. #ifdef DP_RX_MON_MEM_FRAG
  968. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  969. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  970. static inline
  971. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  972. struct dp_pdev *pdev,
  973. qdf_nbuf_t nbuf)
  974. {
  975. bool is_mon_protocol_flow_tag_enabled;
  976. if (qdf_unlikely(!soc || !pdev || !nbuf))
  977. return;
  978. /* Return if it dint came from mon Path */
  979. if (!qdf_nbuf_get_nr_frags(nbuf))
  980. return;
  981. is_mon_protocol_flow_tag_enabled =
  982. wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(soc->wlan_cfg_ctx);
  983. if (qdf_unlikely(!is_mon_protocol_flow_tag_enabled))
  984. return;
  985. if (qdf_likely(!pdev->is_rx_protocol_tagging_enabled))
  986. return;
  987. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) < DP_RX_MON_PF_TAG_TOT_LEN)) {
  988. dp_err("Nbuf avail Headroom[%d] < DP_RX_MON_PF_TAG_TOT_LEN[%d]",
  989. qdf_nbuf_headroom(nbuf), DP_RX_MON_PF_TAG_TOT_LEN);
  990. return;
  991. }
  992. qdf_nbuf_push_head(nbuf, DP_RX_MON_PF_TAG_TOT_LEN);
  993. qdf_mem_copy(qdf_nbuf_data(nbuf), qdf_nbuf_head(nbuf),
  994. DP_RX_MON_PF_TAG_TOT_LEN);
  995. qdf_nbuf_pull_head(nbuf, DP_RX_MON_PF_TAG_TOT_LEN);
  996. }
  997. #else
  998. static inline
  999. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  1000. struct dp_pdev *pdev,
  1001. qdf_nbuf_t nbuf)
  1002. {
  1003. }
  1004. #endif
  1005. #else
  1006. static inline
  1007. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  1008. struct dp_pdev *pdev,
  1009. qdf_nbuf_t nbuf)
  1010. {
  1011. }
  1012. #endif
  1013. /**
  1014. * dp_send_mgmt_packet_to_stack(): send indicataion to upper layers
  1015. *
  1016. * @soc: soc handle
  1017. * @nbuf: Mgmt packet
  1018. * @pdev: pdev handle
  1019. *
  1020. * Return: QDF_STATUS_SUCCESS on success
  1021. * QDF_STATUS_E_INVAL in error
  1022. */
  1023. #ifdef FEATURE_PERPKT_INFO
  1024. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  1025. qdf_nbuf_t nbuf,
  1026. struct dp_pdev *pdev)
  1027. {
  1028. uint32_t *nbuf_data;
  1029. struct ieee80211_frame *wh;
  1030. qdf_frag_t addr;
  1031. if (!nbuf)
  1032. return QDF_STATUS_E_INVAL;
  1033. /* Get addr pointing to80211 header */
  1034. addr = dp_rx_mon_get_nbuf_80211_hdr(nbuf);
  1035. if (qdf_unlikely(!addr)) {
  1036. qdf_nbuf_free(nbuf);
  1037. return QDF_STATUS_E_INVAL;
  1038. }
  1039. /*check if this is not a mgmt packet*/
  1040. wh = (struct ieee80211_frame *)addr;
  1041. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  1042. IEEE80211_FC0_TYPE_MGT) &&
  1043. ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  1044. IEEE80211_FC0_TYPE_CTL)) {
  1045. qdf_nbuf_free(nbuf);
  1046. return QDF_STATUS_E_INVAL;
  1047. }
  1048. nbuf_data = (uint32_t *)qdf_nbuf_push_head(nbuf, 4);
  1049. if (!nbuf_data) {
  1050. QDF_TRACE(QDF_MODULE_ID_DP,
  1051. QDF_TRACE_LEVEL_ERROR,
  1052. FL("No headroom"));
  1053. qdf_nbuf_free(nbuf);
  1054. return QDF_STATUS_E_INVAL;
  1055. }
  1056. *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
  1057. dp_rx_mon_update_pf_tag_to_buf_headroom(soc, pdev, nbuf);
  1058. dp_wdi_event_handler(WDI_EVENT_RX_MGMT_CTRL, soc, nbuf,
  1059. HTT_INVALID_PEER,
  1060. WDI_NO_VAL, pdev->pdev_id);
  1061. return QDF_STATUS_SUCCESS;
  1062. }
  1063. #else
  1064. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  1065. qdf_nbuf_t nbuf,
  1066. struct dp_pdev *pdev)
  1067. {
  1068. return QDF_STATUS_SUCCESS;
  1069. }
  1070. #endif
  1071. /**
  1072. * dp_rx_extract_radiotap_info(): Extract and populate information in
  1073. * struct mon_rx_status type
  1074. * @rx_status: Receive status
  1075. * @mon_rx_status: Monitor mode status
  1076. *
  1077. * Returns: None
  1078. */
  1079. static inline
  1080. void dp_rx_extract_radiotap_info(struct cdp_mon_status *rx_status,
  1081. struct mon_rx_status *rx_mon_status)
  1082. {
  1083. rx_mon_status->tsft = rx_status->cdp_rs_tstamp.cdp_tsf;
  1084. rx_mon_status->chan_freq = rx_status->rs_freq;
  1085. rx_mon_status->chan_num = rx_status->rs_channel;
  1086. rx_mon_status->chan_flags = rx_status->rs_flags;
  1087. rx_mon_status->rate = rx_status->rs_datarate;
  1088. /* TODO: rx_mon_status->ant_signal_db */
  1089. /* TODO: rx_mon_status->nr_ant */
  1090. rx_mon_status->mcs = rx_status->cdf_rs_rate_mcs;
  1091. rx_mon_status->is_stbc = rx_status->cdp_rs_stbc;
  1092. rx_mon_status->sgi = rx_status->cdp_rs_sgi;
  1093. /* TODO: rx_mon_status->ldpc */
  1094. /* TODO: rx_mon_status->beamformed */
  1095. /* TODO: rx_mon_status->vht_flags */
  1096. /* TODO: rx_mon_status->vht_flag_values1 */
  1097. }
  1098. #ifdef DP_RX_MON_MEM_FRAG
  1099. static inline
  1100. qdf_nbuf_t dp_rx_mon_restitch_mpdu(struct dp_soc *soc, uint32_t mac_id,
  1101. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu,
  1102. struct cdp_mon_status *rs)
  1103. {
  1104. if (qdf_nbuf_get_nr_frags(head_msdu))
  1105. return dp_rx_mon_frag_restitch_mpdu_from_msdus(soc, mac_id,
  1106. head_msdu, rs);
  1107. else
  1108. return dp_rx_mon_restitch_mpdu_from_msdus(soc, mac_id,
  1109. head_msdu,
  1110. tail_msdu, rs);
  1111. }
  1112. #else
  1113. static inline
  1114. qdf_nbuf_t dp_rx_mon_restitch_mpdu(struct dp_soc *soc, uint32_t mac_id,
  1115. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu,
  1116. struct cdp_mon_status *rs)
  1117. {
  1118. return dp_rx_mon_restitch_mpdu_from_msdus(soc, mac_id, head_msdu,
  1119. tail_msdu, rs);
  1120. }
  1121. #endif
  1122. /*
  1123. * dp_rx_mon_deliver(): function to deliver packets to stack
  1124. * @soc: DP soc
  1125. * @mac_id: MAC ID
  1126. * @head_msdu: head of msdu list
  1127. * @tail_msdu: tail of msdu list
  1128. *
  1129. * Return: status: 0 - Success, non-zero: Failure
  1130. */
  1131. QDF_STATUS dp_rx_mon_deliver(struct dp_soc *soc, uint32_t mac_id,
  1132. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu)
  1133. {
  1134. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1135. struct cdp_mon_status *rs = &pdev->rx_mon_recv_status;
  1136. qdf_nbuf_t mon_skb, skb_next;
  1137. qdf_nbuf_t mon_mpdu = NULL;
  1138. if (!pdev || (!pdev->monitor_vdev && !pdev->mcopy_mode))
  1139. goto mon_deliver_fail;
  1140. /* restitch mon MPDU for delivery via monitor interface */
  1141. mon_mpdu = dp_rx_mon_restitch_mpdu(soc, mac_id, head_msdu,
  1142. tail_msdu, rs);
  1143. /* monitor vap cannot be present when mcopy is enabled
  1144. * hence same skb can be consumed
  1145. */
  1146. if (pdev->mcopy_mode)
  1147. return dp_send_mgmt_packet_to_stack(soc, mon_mpdu, pdev);
  1148. if (mon_mpdu && pdev->monitor_vdev && pdev->monitor_vdev->osif_vdev &&
  1149. pdev->monitor_vdev->osif_rx_mon) {
  1150. pdev->ppdu_info.rx_status.ppdu_id =
  1151. pdev->ppdu_info.com_info.ppdu_id;
  1152. pdev->ppdu_info.rx_status.device_id = soc->device_id;
  1153. pdev->ppdu_info.rx_status.chan_noise_floor =
  1154. pdev->chan_noise_floor;
  1155. dp_handle_tx_capture(soc, pdev, mon_mpdu);
  1156. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status,
  1157. mon_mpdu,
  1158. qdf_nbuf_headroom(mon_mpdu))) {
  1159. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  1160. goto mon_deliver_fail;
  1161. }
  1162. dp_rx_mon_update_pf_tag_to_buf_headroom(soc, pdev, head_msdu);
  1163. pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  1164. mon_mpdu,
  1165. &pdev->ppdu_info.rx_status);
  1166. } else {
  1167. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1168. "[%s][%d] mon_mpdu=%pK monitor_vdev %pK osif_vdev %pK"
  1169. , __func__, __LINE__, mon_mpdu, pdev->monitor_vdev,
  1170. (pdev->monitor_vdev ? pdev->monitor_vdev->osif_vdev
  1171. : NULL));
  1172. goto mon_deliver_fail;
  1173. }
  1174. return QDF_STATUS_SUCCESS;
  1175. mon_deliver_fail:
  1176. mon_skb = head_msdu;
  1177. while (mon_skb) {
  1178. skb_next = qdf_nbuf_next(mon_skb);
  1179. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1180. "[%s][%d] mon_skb=%pK len %u", __func__,
  1181. __LINE__, mon_skb, mon_skb->len);
  1182. qdf_nbuf_free(mon_skb);
  1183. mon_skb = skb_next;
  1184. }
  1185. return QDF_STATUS_E_INVAL;
  1186. }
  1187. /**
  1188. * dp_rx_mon_deliver_non_std()
  1189. * @soc: core txrx main contex
  1190. * @mac_id: MAC ID
  1191. *
  1192. * This function delivers the radio tap and dummy MSDU
  1193. * into user layer application for preamble only PPDU.
  1194. *
  1195. * Return: QDF_STATUS
  1196. */
  1197. QDF_STATUS dp_rx_mon_deliver_non_std(struct dp_soc *soc,
  1198. uint32_t mac_id)
  1199. {
  1200. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1201. ol_txrx_rx_mon_fp osif_rx_mon;
  1202. qdf_nbuf_t dummy_msdu;
  1203. /* Sanity checking */
  1204. if (!pdev || !pdev->monitor_vdev || !pdev->monitor_vdev->osif_rx_mon)
  1205. goto mon_deliver_non_std_fail;
  1206. /* Generate a dummy skb_buff */
  1207. osif_rx_mon = pdev->monitor_vdev->osif_rx_mon;
  1208. dummy_msdu = qdf_nbuf_alloc(soc->osdev, MAX_MONITOR_HEADER,
  1209. MAX_MONITOR_HEADER, 4, FALSE);
  1210. if (!dummy_msdu)
  1211. goto allocate_dummy_msdu_fail;
  1212. qdf_nbuf_set_pktlen(dummy_msdu, 0);
  1213. qdf_nbuf_set_next(dummy_msdu, NULL);
  1214. pdev->ppdu_info.rx_status.ppdu_id =
  1215. pdev->ppdu_info.com_info.ppdu_id;
  1216. /* Apply the radio header to this dummy skb */
  1217. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status, dummy_msdu,
  1218. qdf_nbuf_headroom(dummy_msdu))) {
  1219. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  1220. qdf_nbuf_free(dummy_msdu);
  1221. goto mon_deliver_non_std_fail;
  1222. }
  1223. /* deliver to the user layer application */
  1224. osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  1225. dummy_msdu, NULL);
  1226. /* Clear rx_status*/
  1227. qdf_mem_zero(&pdev->ppdu_info.rx_status,
  1228. sizeof(pdev->ppdu_info.rx_status));
  1229. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1230. return QDF_STATUS_SUCCESS;
  1231. allocate_dummy_msdu_fail:
  1232. QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_DP, "[%s][%d] mon_skb=%pK ",
  1233. __func__, __LINE__, dummy_msdu);
  1234. mon_deliver_non_std_fail:
  1235. return QDF_STATUS_E_INVAL;
  1236. }
  1237. void dp_rx_mon_dest_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  1238. uint32_t mac_id, uint32_t quota)
  1239. {
  1240. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1241. uint8_t pdev_id;
  1242. hal_rxdma_desc_t rxdma_dst_ring_desc;
  1243. hal_soc_handle_t hal_soc;
  1244. void *mon_dst_srng;
  1245. union dp_rx_desc_list_elem_t *head = NULL;
  1246. union dp_rx_desc_list_elem_t *tail = NULL;
  1247. uint32_t ppdu_id;
  1248. uint32_t rx_bufs_used;
  1249. uint32_t mpdu_rx_bufs_used;
  1250. int mac_for_pdev = mac_id;
  1251. struct cdp_pdev_mon_stats *rx_mon_stats;
  1252. if (!pdev) {
  1253. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1254. "pdev is null for mac_id = %d", mac_id);
  1255. return;
  1256. }
  1257. mon_dst_srng = dp_rxdma_get_mon_dst_ring(pdev, mac_for_pdev);
  1258. if (!mon_dst_srng || !hal_srng_initialized(mon_dst_srng)) {
  1259. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1260. "%s %d : HAL Monitor Destination Ring Init Failed -- %pK",
  1261. __func__, __LINE__, mon_dst_srng);
  1262. return;
  1263. }
  1264. hal_soc = soc->hal_soc;
  1265. qdf_assert((hal_soc && pdev));
  1266. qdf_spin_lock_bh(&pdev->mon_lock);
  1267. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, mon_dst_srng))) {
  1268. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1269. "%s %d : HAL Monitor Destination Ring access Failed -- %pK",
  1270. __func__, __LINE__, mon_dst_srng);
  1271. return;
  1272. }
  1273. pdev_id = pdev->pdev_id;
  1274. ppdu_id = pdev->ppdu_info.com_info.ppdu_id;
  1275. rx_bufs_used = 0;
  1276. rx_mon_stats = &pdev->rx_mon_stats;
  1277. while (qdf_likely(rxdma_dst_ring_desc =
  1278. hal_srng_dst_peek(hal_soc, mon_dst_srng))) {
  1279. qdf_nbuf_t head_msdu, tail_msdu;
  1280. uint32_t npackets;
  1281. head_msdu = (qdf_nbuf_t) NULL;
  1282. tail_msdu = (qdf_nbuf_t) NULL;
  1283. mpdu_rx_bufs_used =
  1284. dp_rx_mon_mpdu_pop(soc, mac_id,
  1285. rxdma_dst_ring_desc,
  1286. &head_msdu, &tail_msdu,
  1287. &npackets, &ppdu_id,
  1288. &head, &tail);
  1289. rx_bufs_used += mpdu_rx_bufs_used;
  1290. if (mpdu_rx_bufs_used)
  1291. pdev->mon_dest_ring_stuck_cnt = 0;
  1292. else
  1293. pdev->mon_dest_ring_stuck_cnt++;
  1294. if (pdev->mon_dest_ring_stuck_cnt >
  1295. MON_DEST_RING_STUCK_MAX_CNT) {
  1296. dp_info("destination ring stuck");
  1297. dp_info("ppdu_id status=%d dest=%d",
  1298. pdev->ppdu_info.com_info.ppdu_id, ppdu_id);
  1299. rx_mon_stats->mon_rx_dest_stuck++;
  1300. pdev->ppdu_info.com_info.ppdu_id = ppdu_id;
  1301. continue;
  1302. }
  1303. if (ppdu_id != pdev->ppdu_info.com_info.ppdu_id) {
  1304. rx_mon_stats->stat_ring_ppdu_id_hist[
  1305. rx_mon_stats->ppdu_id_hist_idx] =
  1306. pdev->ppdu_info.com_info.ppdu_id;
  1307. rx_mon_stats->dest_ring_ppdu_id_hist[
  1308. rx_mon_stats->ppdu_id_hist_idx] = ppdu_id;
  1309. rx_mon_stats->ppdu_id_hist_idx =
  1310. (rx_mon_stats->ppdu_id_hist_idx + 1) &
  1311. (MAX_PPDU_ID_HIST - 1);
  1312. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1313. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  1314. sizeof(pdev->ppdu_info.rx_status));
  1315. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1316. "%s %d ppdu_id %x != ppdu_info.com_info.ppdu_id %x",
  1317. __func__, __LINE__,
  1318. ppdu_id, pdev->ppdu_info.com_info.ppdu_id);
  1319. break;
  1320. }
  1321. if (qdf_likely((head_msdu) &&
  1322. (DP_RX_MON_IS_MSDU_NOT_NULL(tail_msdu)))) {
  1323. rx_mon_stats->dest_mpdu_done++;
  1324. dp_rx_mon_deliver(soc, mac_id, head_msdu, tail_msdu);
  1325. }
  1326. rxdma_dst_ring_desc = hal_srng_dst_get_next(hal_soc,
  1327. mon_dst_srng);
  1328. }
  1329. dp_srng_access_end(int_ctx, soc, mon_dst_srng);
  1330. qdf_spin_unlock_bh(&pdev->mon_lock);
  1331. if (rx_bufs_used) {
  1332. rx_mon_stats->dest_ppdu_done++;
  1333. dp_rx_buffers_replenish(soc, mac_id,
  1334. dp_rxdma_get_mon_buf_ring(pdev,
  1335. mac_for_pdev),
  1336. dp_rx_get_mon_desc_pool(soc, mac_id,
  1337. pdev_id),
  1338. rx_bufs_used, &head, &tail);
  1339. }
  1340. }
  1341. QDF_STATUS
  1342. dp_rx_pdev_mon_buf_buffers_alloc(struct dp_pdev *pdev, uint32_t mac_id,
  1343. bool delayed_replenish)
  1344. {
  1345. uint8_t pdev_id = pdev->pdev_id;
  1346. struct dp_soc *soc = pdev->soc;
  1347. struct dp_srng *mon_buf_ring;
  1348. uint32_t num_entries;
  1349. struct rx_desc_pool *rx_desc_pool;
  1350. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1351. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1352. mon_buf_ring = dp_rxdma_get_mon_buf_ring(pdev, mac_id);
  1353. num_entries = mon_buf_ring->num_entries;
  1354. rx_desc_pool = dp_rx_get_mon_desc_pool(soc, mac_id, pdev_id);
  1355. dp_debug("Mon RX Desc Pool[%d] entries=%u", pdev_id, num_entries);
  1356. /* Replenish RXDMA monitor buffer ring with 8 buffers only
  1357. * delayed_replenish_entries is actually 8 but when we call
  1358. * dp_pdev_rx_buffers_attach() we pass 1 less than 8, hence
  1359. * added 1 to delayed_replenish_entries to ensure we have 8
  1360. * entries. Once the monitor VAP is configured we replenish
  1361. * the complete RXDMA monitor buffer ring.
  1362. */
  1363. if (delayed_replenish) {
  1364. num_entries = soc_cfg_ctx->delayed_replenish_entries + 1;
  1365. status = dp_pdev_rx_buffers_attach(soc, mac_id, mon_buf_ring,
  1366. rx_desc_pool,
  1367. num_entries - 1);
  1368. } else {
  1369. union dp_rx_desc_list_elem_t *tail = NULL;
  1370. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1371. status = dp_rx_buffers_replenish(soc, mac_id,
  1372. mon_buf_ring,
  1373. rx_desc_pool,
  1374. num_entries,
  1375. &desc_list,
  1376. &tail);
  1377. }
  1378. return status;
  1379. }
  1380. static QDF_STATUS
  1381. dp_rx_pdev_mon_cmn_buffers_alloc(struct dp_pdev *pdev, int mac_id)
  1382. {
  1383. struct dp_soc *soc = pdev->soc;
  1384. uint8_t pdev_id = pdev->pdev_id;
  1385. int mac_for_pdev;
  1386. bool delayed_replenish;
  1387. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1388. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1389. delayed_replenish = soc_cfg_ctx->delayed_replenish_entries ? 1 : 0;
  1390. mac_for_pdev = dp_get_lmac_id_for_pdev_id(pdev->soc, mac_id, pdev_id);
  1391. status = dp_rx_pdev_mon_status_buffers_alloc(pdev, mac_for_pdev);
  1392. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1393. dp_err("dp_rx_pdev_mon_status_desc_pool_alloc() failed");
  1394. goto fail;
  1395. }
  1396. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1397. return status;
  1398. status = dp_rx_pdev_mon_buf_buffers_alloc(pdev, mac_for_pdev,
  1399. delayed_replenish);
  1400. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1401. dp_err("dp_rx_pdev_mon_buf_desc_pool_alloc() failed");
  1402. goto mon_stat_buf_dealloc;
  1403. }
  1404. return status;
  1405. mon_stat_buf_dealloc:
  1406. dp_rx_pdev_mon_status_buffers_free(pdev, mac_for_pdev);
  1407. fail:
  1408. return status;
  1409. }
  1410. static void
  1411. dp_rx_pdev_mon_buf_desc_pool_init(struct dp_pdev *pdev, uint32_t mac_id)
  1412. {
  1413. uint8_t pdev_id = pdev->pdev_id;
  1414. struct dp_soc *soc = pdev->soc;
  1415. struct dp_srng *mon_buf_ring;
  1416. uint32_t num_entries;
  1417. struct rx_desc_pool *rx_desc_pool;
  1418. uint32_t rx_desc_pool_size;
  1419. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1420. mon_buf_ring = &soc->rxdma_mon_buf_ring[mac_id];
  1421. num_entries = mon_buf_ring->num_entries;
  1422. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1423. dp_debug("Mon RX Desc buf Pool[%d] init entries=%u",
  1424. pdev_id, num_entries);
  1425. rx_desc_pool_size = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc_cfg_ctx) *
  1426. num_entries;
  1427. rx_desc_pool->owner = HAL_RX_BUF_RBM_SW3_BM;
  1428. rx_desc_pool->buf_size = RX_MONITOR_BUFFER_SIZE;
  1429. rx_desc_pool->buf_alignment = RX_MONITOR_BUFFER_ALIGNMENT;
  1430. /* Enable frag processing if feature is enabled */
  1431. dp_rx_enable_mon_dest_frag(rx_desc_pool, true);
  1432. dp_rx_desc_pool_init(soc, mac_id, rx_desc_pool_size, rx_desc_pool);
  1433. pdev->mon_last_linkdesc_paddr = 0;
  1434. pdev->mon_last_buf_cookie = DP_RX_DESC_COOKIE_MAX + 1;
  1435. /* Attach full monitor mode resources */
  1436. dp_full_mon_attach(pdev);
  1437. }
  1438. static void
  1439. dp_rx_pdev_mon_cmn_desc_pool_init(struct dp_pdev *pdev, int mac_id)
  1440. {
  1441. struct dp_soc *soc = pdev->soc;
  1442. uint32_t mac_for_pdev;
  1443. mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev->pdev_id);
  1444. dp_rx_pdev_mon_status_desc_pool_init(pdev, mac_for_pdev);
  1445. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1446. return;
  1447. dp_rx_pdev_mon_buf_desc_pool_init(pdev, mac_for_pdev);
  1448. dp_link_desc_ring_replenish(soc, mac_for_pdev);
  1449. }
  1450. static void
  1451. dp_rx_pdev_mon_buf_desc_pool_deinit(struct dp_pdev *pdev, uint32_t mac_id)
  1452. {
  1453. uint8_t pdev_id = pdev->pdev_id;
  1454. struct dp_soc *soc = pdev->soc;
  1455. struct rx_desc_pool *rx_desc_pool;
  1456. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1457. dp_debug("Mon RX Desc buf Pool[%d] deinit", pdev_id);
  1458. dp_rx_desc_pool_deinit(soc, rx_desc_pool);
  1459. /* Detach full monitor mode resources */
  1460. dp_full_mon_detach(pdev);
  1461. }
  1462. static void
  1463. dp_rx_pdev_mon_cmn_desc_pool_deinit(struct dp_pdev *pdev, int mac_id)
  1464. {
  1465. struct dp_soc *soc = pdev->soc;
  1466. uint8_t pdev_id = pdev->pdev_id;
  1467. int mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1468. dp_rx_pdev_mon_status_desc_pool_deinit(pdev, mac_for_pdev);
  1469. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1470. return;
  1471. dp_rx_pdev_mon_buf_desc_pool_deinit(pdev, mac_for_pdev);
  1472. }
  1473. static void
  1474. dp_rx_pdev_mon_buf_desc_pool_free(struct dp_pdev *pdev, uint32_t mac_id)
  1475. {
  1476. uint8_t pdev_id = pdev->pdev_id;
  1477. struct dp_soc *soc = pdev->soc;
  1478. struct rx_desc_pool *rx_desc_pool;
  1479. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1480. dp_debug("Mon RX Buf Desc Pool Free pdev[%d]", pdev_id);
  1481. dp_rx_desc_pool_free(soc, rx_desc_pool);
  1482. }
  1483. static void
  1484. dp_rx_pdev_mon_cmn_desc_pool_free(struct dp_pdev *pdev, int mac_id)
  1485. {
  1486. struct dp_soc *soc = pdev->soc;
  1487. uint8_t pdev_id = pdev->pdev_id;
  1488. int mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1489. dp_rx_pdev_mon_status_desc_pool_free(pdev, mac_for_pdev);
  1490. dp_rx_pdev_mon_buf_desc_pool_free(pdev, mac_for_pdev);
  1491. dp_hw_link_desc_pool_banks_free(soc, mac_for_pdev);
  1492. }
  1493. void dp_rx_pdev_mon_buf_buffers_free(struct dp_pdev *pdev, uint32_t mac_id)
  1494. {
  1495. uint8_t pdev_id = pdev->pdev_id;
  1496. struct dp_soc *soc = pdev->soc;
  1497. struct rx_desc_pool *rx_desc_pool;
  1498. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1499. dp_debug("Mon RX Buf buffers Free pdev[%d]", pdev_id);
  1500. if (rx_desc_pool->rx_mon_dest_frag_enable)
  1501. dp_rx_desc_frag_free(soc, rx_desc_pool);
  1502. else
  1503. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  1504. }
  1505. static QDF_STATUS
  1506. dp_rx_pdev_mon_buf_desc_pool_alloc(struct dp_pdev *pdev, uint32_t mac_id)
  1507. {
  1508. uint8_t pdev_id = pdev->pdev_id;
  1509. struct dp_soc *soc = pdev->soc;
  1510. struct dp_srng *mon_buf_ring;
  1511. uint32_t num_entries;
  1512. struct rx_desc_pool *rx_desc_pool;
  1513. uint32_t rx_desc_pool_size;
  1514. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1515. mon_buf_ring = &soc->rxdma_mon_buf_ring[mac_id];
  1516. num_entries = mon_buf_ring->num_entries;
  1517. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1518. dp_debug("Mon RX Desc Pool[%d] entries=%u",
  1519. pdev_id, num_entries);
  1520. rx_desc_pool_size = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc_cfg_ctx) *
  1521. num_entries;
  1522. return dp_rx_desc_pool_alloc(soc, rx_desc_pool_size, rx_desc_pool);
  1523. }
  1524. static QDF_STATUS
  1525. dp_rx_pdev_mon_cmn_desc_pool_alloc(struct dp_pdev *pdev, int mac_id)
  1526. {
  1527. struct dp_soc *soc = pdev->soc;
  1528. uint8_t pdev_id = pdev->pdev_id;
  1529. uint32_t mac_for_pdev;
  1530. QDF_STATUS status;
  1531. mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1532. /* Allocate sw rx descriptor pool for monitor status ring */
  1533. status = dp_rx_pdev_mon_status_desc_pool_alloc(pdev, mac_for_pdev);
  1534. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1535. dp_err("dp_rx_pdev_mon_status_desc_pool_alloc() failed");
  1536. goto fail;
  1537. }
  1538. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1539. return status;
  1540. /* Allocate sw rx descriptor pool for monitor RxDMA buffer ring */
  1541. status = dp_rx_pdev_mon_buf_desc_pool_alloc(pdev, mac_for_pdev);
  1542. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1543. dp_err("dp_rx_pdev_mon_buf_desc_pool_alloc() failed");
  1544. goto mon_status_dealloc;
  1545. }
  1546. /* Allocate link descriptors for the monitor link descriptor ring */
  1547. status = dp_hw_link_desc_pool_banks_alloc(soc, mac_for_pdev);
  1548. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1549. dp_err("dp_hw_link_desc_pool_banks_alloc() failed");
  1550. goto mon_buf_dealloc;
  1551. }
  1552. return status;
  1553. mon_buf_dealloc:
  1554. dp_rx_pdev_mon_buf_desc_pool_free(pdev, mac_for_pdev);
  1555. mon_status_dealloc:
  1556. dp_rx_pdev_mon_status_desc_pool_free(pdev, mac_for_pdev);
  1557. fail:
  1558. return status;
  1559. }
  1560. static void
  1561. dp_rx_pdev_mon_cmn_buffers_free(struct dp_pdev *pdev, int mac_id)
  1562. {
  1563. uint8_t pdev_id = pdev->pdev_id;
  1564. struct dp_soc *soc = pdev->soc;
  1565. int mac_for_pdev;
  1566. mac_for_pdev = dp_get_lmac_id_for_pdev_id(pdev->soc, mac_id, pdev_id);
  1567. dp_rx_pdev_mon_status_buffers_free(pdev, mac_for_pdev);
  1568. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1569. return;
  1570. dp_rx_pdev_mon_buf_buffers_free(pdev, mac_for_pdev);
  1571. }
  1572. QDF_STATUS
  1573. dp_rx_pdev_mon_desc_pool_alloc(struct dp_pdev *pdev)
  1574. {
  1575. QDF_STATUS status;
  1576. int mac_id, count;
  1577. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1578. status = dp_rx_pdev_mon_cmn_desc_pool_alloc(pdev, mac_id);
  1579. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1580. QDF_TRACE(QDF_MODULE_ID_DP,
  1581. QDF_TRACE_LEVEL_ERROR, "%s: %d failed\n",
  1582. __func__, mac_id);
  1583. for (count = 0; count < mac_id; count++)
  1584. dp_rx_pdev_mon_cmn_desc_pool_free(pdev, count);
  1585. return status;
  1586. }
  1587. }
  1588. return status;
  1589. }
  1590. void
  1591. dp_rx_pdev_mon_desc_pool_init(struct dp_pdev *pdev)
  1592. {
  1593. int mac_id;
  1594. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1595. dp_rx_pdev_mon_cmn_desc_pool_init(pdev, mac_id);
  1596. qdf_spinlock_create(&pdev->mon_lock);
  1597. }
  1598. void
  1599. dp_rx_pdev_mon_desc_pool_deinit(struct dp_pdev *pdev)
  1600. {
  1601. int mac_id;
  1602. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1603. dp_rx_pdev_mon_cmn_desc_pool_deinit(pdev, mac_id);
  1604. qdf_spinlock_destroy(&pdev->mon_lock);
  1605. }
  1606. void dp_rx_pdev_mon_desc_pool_free(struct dp_pdev *pdev)
  1607. {
  1608. int mac_id;
  1609. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1610. dp_rx_pdev_mon_cmn_desc_pool_free(pdev, mac_id);
  1611. }
  1612. void
  1613. dp_rx_pdev_mon_buffers_free(struct dp_pdev *pdev)
  1614. {
  1615. int mac_id;
  1616. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1617. dp_rx_pdev_mon_cmn_buffers_free(pdev, mac_id);
  1618. }
  1619. QDF_STATUS
  1620. dp_rx_pdev_mon_buffers_alloc(struct dp_pdev *pdev)
  1621. {
  1622. int mac_id;
  1623. QDF_STATUS status;
  1624. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1625. status = dp_rx_pdev_mon_cmn_buffers_alloc(pdev, mac_id);
  1626. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1627. QDF_TRACE(QDF_MODULE_ID_DP,
  1628. QDF_TRACE_LEVEL_ERROR, "%s: %d failed\n",
  1629. __func__, mac_id);
  1630. return status;
  1631. }
  1632. }
  1633. return status;
  1634. }