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 dot3 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. * @pf_tag: Memory to store Protocol flow tag for every MSDU
  428. *
  429. * Return: Adjusted nbuf containing MPDU worth info.
  430. */
  431. static inline
  432. qdf_nbuf_t dp_rx_mon_frag_restitch_mpdu_from_msdus(struct dp_soc *soc,
  433. uint32_t mac_id,
  434. qdf_nbuf_t head_msdu,
  435. qdf_nbuf_t last_msdu,
  436. struct cdp_mon_status *rx_status)
  437. {
  438. uint32_t wifi_hdr_len, sec_hdr_len, msdu_llc_len,
  439. mpdu_buf_len, decap_hdr_pull_bytes, dir,
  440. is_amsdu, amsdu_pad, frag_size, tot_msdu_len;
  441. qdf_frag_t rx_desc, rx_src_desc, rx_dest_desc, frag_addr;
  442. char *hdr_desc;
  443. uint8_t num_frags, frags_iter, l2_hdr_offset;
  444. struct ieee80211_frame *wh;
  445. struct ieee80211_qoscntl *qos;
  446. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  447. int16_t frag_page_offset = 0;
  448. struct hal_rx_mon_dest_buf_info buf_info;
  449. uint32_t pad_byte_pholder = 0;
  450. if (qdf_unlikely(!dp_pdev)) {
  451. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  452. "pdev is null for mac_id = %d", mac_id);
  453. return NULL;
  454. }
  455. qdf_mem_zero(&buf_info, sizeof(struct hal_rx_mon_dest_buf_info));
  456. if (!head_msdu)
  457. goto mpdu_stitch_fail;
  458. num_frags = qdf_nbuf_get_nr_frags(head_msdu);
  459. rx_desc = qdf_nbuf_get_frag_addr(head_msdu, 0) - SIZE_OF_MONITOR_TLV;
  460. if (HAL_RX_DESC_GET_MPDU_LENGTH_ERR(rx_desc)) {
  461. /* It looks like there is some issue on MPDU len err */
  462. /* Need further investigate if drop the packet */
  463. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  464. return NULL;
  465. }
  466. /* Look for FCS error */
  467. rx_desc =
  468. qdf_nbuf_get_frag_addr(head_msdu,
  469. num_frags - 1) - SIZE_OF_MONITOR_TLV;
  470. rx_status->cdp_rs_fcs_err = HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  471. dp_pdev->ppdu_info.rx_status.rs_fcs_err =
  472. HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  473. rx_desc = qdf_nbuf_get_frag_addr(head_msdu, 0) - SIZE_OF_MONITOR_TLV;
  474. hal_rx_mon_dest_get_buffer_info_from_tlv(rx_desc, &buf_info);
  475. /* Easy case - The MSDU status indicates that this is a non-decapped
  476. * packet in RAW mode.
  477. */
  478. if (buf_info.is_decap_raw == 1)
  479. goto mpdu_stitch_done;
  480. l2_hdr_offset = DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  481. /* Decap mode:
  482. * Calculate the amount of header in decapped packet to knock off based
  483. * on the decap type and the corresponding number of raw bytes to copy
  484. * status header
  485. */
  486. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  487. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  488. "[%s][%d] decap format not raw",
  489. __func__, __LINE__);
  490. /* Base size */
  491. wifi_hdr_len = sizeof(struct ieee80211_frame);
  492. wh = (struct ieee80211_frame *)hdr_desc;
  493. dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
  494. if (dir == IEEE80211_FC1_DIR_DSTODS)
  495. wifi_hdr_len += 6;
  496. is_amsdu = 0;
  497. if (wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) {
  498. qos = (struct ieee80211_qoscntl *)
  499. (hdr_desc + wifi_hdr_len);
  500. wifi_hdr_len += 2;
  501. is_amsdu = (qos->i_qos[0] & IEEE80211_QOS_AMSDU);
  502. }
  503. /*Calculate security header length based on 'Protected'
  504. * and 'EXT_IV' flag
  505. */
  506. if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
  507. char *iv = (char *)wh + wifi_hdr_len;
  508. if (iv[3] & KEY_EXTIV)
  509. sec_hdr_len = 8;
  510. else
  511. sec_hdr_len = 4;
  512. } else {
  513. sec_hdr_len = 0;
  514. }
  515. wifi_hdr_len += sec_hdr_len;
  516. /* MSDU related stuff LLC - AMSDU subframe header etc */
  517. msdu_llc_len = is_amsdu ? (14 + 8) : 8;
  518. mpdu_buf_len = wifi_hdr_len + msdu_llc_len;
  519. /* "Decap" header to remove from MSDU buffer */
  520. decap_hdr_pull_bytes = 14;
  521. amsdu_pad = 0;
  522. tot_msdu_len = 0;
  523. /*
  524. * keeping first MSDU ops outside of loop to avoid multiple
  525. * check handling
  526. */
  527. /* Construct src header */
  528. rx_src_desc = hdr_desc;
  529. /*
  530. * Update protocol and flow tag for MSDU
  531. * update frag index in ctx_idx field.
  532. * Reset head pointer data of nbuf before updating.
  533. */
  534. qdf_mem_zero(qdf_nbuf_head(head_msdu), DP_RX_MON_PF_TAG_TOT_LEN);
  535. QDF_NBUF_CB_RX_CTX_ID(head_msdu) = 0;
  536. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev, head_msdu, rx_desc);
  537. /* Construct destination address */
  538. frag_addr = qdf_nbuf_get_frag_addr(head_msdu, 0);
  539. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu, 0);
  540. /* We will come here in 2 scenario:
  541. * 1. First MSDU of MPDU with single buffer
  542. * 2. First buffer of First MSDU of MPDU with continuation
  543. *
  544. * ------------------------------------------------------------
  545. * | SINGLE BUFFER (<= RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN)|
  546. * ------------------------------------------------------------
  547. *
  548. * ------------------------------------------------------------
  549. * | First BUFFER with Continuation | ... |
  550. * | (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) | |
  551. * ------------------------------------------------------------
  552. */
  553. pad_byte_pholder =
  554. (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) - frag_size;
  555. /* Construct destination address
  556. * --------------------------------------------------------------
  557. * | RX_PKT_TLV | L2_HDR_PAD | Decap HDR | Payload |
  558. * | | / |
  559. * | >Frag address points here / |
  560. * | \ / |
  561. * | \ This bytes needs to / |
  562. * | \ removed to frame pkt / |
  563. * | ----------------------- |
  564. * | | |
  565. * | | |
  566. * | WIFI +LLC HDR will be added here <-| |
  567. * | | | |
  568. * | >Dest addr will point | |
  569. * | somewhere in this area | |
  570. * --------------------------------------------------------------
  571. */
  572. rx_dest_desc =
  573. (frag_addr + decap_hdr_pull_bytes + l2_hdr_offset) -
  574. mpdu_buf_len;
  575. /* Add WIFI and LLC header for 1st MSDU of MPDU */
  576. qdf_mem_copy(rx_dest_desc, rx_src_desc, mpdu_buf_len);
  577. frag_page_offset =
  578. (decap_hdr_pull_bytes + l2_hdr_offset) - mpdu_buf_len;
  579. qdf_nbuf_move_frag_page_offset(head_msdu, 0, frag_page_offset);
  580. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu, 0);
  581. if (buf_info.first_buffer && buf_info.last_buffer) {
  582. /* MSDU with single bufffer */
  583. amsdu_pad = frag_size & 0x3;
  584. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  585. if (amsdu_pad <= pad_byte_pholder) {
  586. qdf_nbuf_trim_add_frag_size(head_msdu, 0, amsdu_pad,
  587. 0);
  588. amsdu_pad = 0;
  589. }
  590. } else {
  591. /*
  592. * First buffer of Continuation frame and hence
  593. * amsdu_padding doesn't need to be added
  594. * Increase tot_msdu_len so that amsdu_pad byte
  595. * will be calculated for last frame of MSDU
  596. */
  597. tot_msdu_len = frag_size;
  598. amsdu_pad = 0;
  599. }
  600. /* Here amsdu_pad byte will have some value if 1sf buffer was
  601. * Single buffer MSDU and dint had pholder to adjust amsdu padding
  602. * byte in the end
  603. * So dont initialize to ZERO here
  604. */
  605. pad_byte_pholder = 0;
  606. for (frags_iter = 1; frags_iter < num_frags; frags_iter++) {
  607. /* Construct destination address
  608. * ----------------------------------------------------------
  609. * | RX_PKT_TLV | L2_HDR_PAD | Decap HDR | Payload | Pad |
  610. * | | (First buffer) | | |
  611. * | | / / |
  612. * | >Frag address points here / / |
  613. * | \ / / |
  614. * | \ This bytes needs to / / |
  615. * | \ removed to frame pkt/ / |
  616. * | ---------------------- / |
  617. * | | / Add |
  618. * | | / amsdu pad |
  619. * | LLC HDR will be added here <-| | Byte for |
  620. * | | | | last frame |
  621. * | >Dest addr will point | | if space |
  622. * | somewhere in this area | | available |
  623. * | And amsdu_pad will be created if | | |
  624. * | dint get added in last buffer | | |
  625. * | (First Buffer) | | |
  626. * ----------------------------------------------------------
  627. */
  628. frag_addr = qdf_nbuf_get_frag_addr(head_msdu, frags_iter);
  629. rx_desc = frag_addr - SIZE_OF_MONITOR_TLV;
  630. /*
  631. * Update protocol and flow tag for MSDU
  632. * update frag index in ctx_idx field
  633. */
  634. QDF_NBUF_CB_RX_CTX_ID(head_msdu) = frags_iter;
  635. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev,
  636. head_msdu, rx_desc);
  637. /* Read buffer info from stored data in tlvs */
  638. hal_rx_mon_dest_get_buffer_info_from_tlv(rx_desc,
  639. &buf_info);
  640. frag_size = qdf_nbuf_get_frag_size_by_idx(head_msdu,
  641. frags_iter);
  642. /* If Middle buffer, dont add any header */
  643. if ((!buf_info.first_buffer) && (!buf_info.last_buffer)) {
  644. tot_msdu_len += frag_size;
  645. amsdu_pad = 0;
  646. pad_byte_pholder = 0;
  647. continue;
  648. }
  649. /* Calculate if current buffer has placeholder
  650. * to accommodate amsdu pad byte
  651. */
  652. pad_byte_pholder =
  653. (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN) - frag_size;
  654. /*
  655. * We will come here only only three condition:
  656. * 1. Msdu with single Buffer
  657. * 2. First buffer in case MSDU is spread in multiple buffer
  658. * 3. Last buffer in case MSDU is spread in multiple buffer
  659. *
  660. * First buffER | Last buffer
  661. * Case 1: 1 | 1
  662. * Case 2: 1 | 0
  663. * Case 3: 0 | 1
  664. *
  665. * In 3rd case only l2_hdr_padding byte will be Zero and in
  666. * other case, It will be 2 Bytes.
  667. */
  668. if (buf_info.first_buffer)
  669. l2_hdr_offset = DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  670. else
  671. l2_hdr_offset = DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  672. if (buf_info.first_buffer) {
  673. /* Src addr from whre llc header needs to be copied */
  674. rx_src_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  675. /* Size of buffer with llc header */
  676. frag_size = frag_size -
  677. (l2_hdr_offset + decap_hdr_pull_bytes);
  678. frag_size += msdu_llc_len;
  679. /* Construct destination address */
  680. rx_dest_desc = frag_addr + decap_hdr_pull_bytes +
  681. l2_hdr_offset;
  682. rx_dest_desc = rx_dest_desc - (msdu_llc_len);
  683. qdf_mem_copy(rx_dest_desc, rx_src_desc, msdu_llc_len);
  684. /*
  685. * Calculate new page offset and create hole
  686. * if amsdu_pad required.
  687. */
  688. frag_page_offset = l2_hdr_offset +
  689. decap_hdr_pull_bytes;
  690. frag_page_offset = frag_page_offset -
  691. (msdu_llc_len + amsdu_pad);
  692. qdf_nbuf_move_frag_page_offset(head_msdu, frags_iter,
  693. frag_page_offset);
  694. tot_msdu_len = frag_size;
  695. /*
  696. * No amsdu padding required for first frame of
  697. * continuation buffer
  698. */
  699. if (!buf_info.last_buffer) {
  700. amsdu_pad = 0;
  701. continue;
  702. }
  703. } else {
  704. tot_msdu_len += frag_size;
  705. }
  706. /* Will reach to this place in only two case:
  707. * 1. Single buffer MSDU
  708. * 2. Last buffer of MSDU in case of multiple buffer MSDU
  709. */
  710. /* Check size of buffer if amsdu padding required */
  711. amsdu_pad = tot_msdu_len & 0x3;
  712. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  713. /* Create placeholder if current bufer can
  714. * accommodate padding.
  715. */
  716. if (amsdu_pad <= pad_byte_pholder) {
  717. qdf_nbuf_trim_add_frag_size(head_msdu, frags_iter,
  718. amsdu_pad, 0);
  719. amsdu_pad = 0;
  720. }
  721. /* reset tot_msdu_len */
  722. tot_msdu_len = 0;
  723. }
  724. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  725. "%s %d head_msdu %pK head_msdu->len %u",
  726. __func__, __LINE__,
  727. head_msdu, head_msdu->len);
  728. mpdu_stitch_done:
  729. return head_msdu;
  730. mpdu_stitch_fail:
  731. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  732. "%s mpdu_stitch_fail head_msdu %pK", __func__, head_msdu);
  733. return NULL;
  734. }
  735. #endif
  736. static inline
  737. qdf_nbuf_t dp_rx_mon_restitch_mpdu_from_msdus(struct dp_soc *soc,
  738. uint32_t mac_id, qdf_nbuf_t head_msdu, qdf_nbuf_t last_msdu,
  739. struct cdp_mon_status *rx_status)
  740. {
  741. qdf_nbuf_t msdu, mpdu_buf, prev_buf, msdu_orig, head_frag_list;
  742. uint32_t decap_format, wifi_hdr_len, sec_hdr_len, msdu_llc_len,
  743. mpdu_buf_len, decap_hdr_pull_bytes, frag_list_sum_len, dir,
  744. is_amsdu, is_first_frag, amsdu_pad;
  745. void *rx_desc;
  746. char *hdr_desc;
  747. unsigned char *dest;
  748. struct ieee80211_frame *wh;
  749. struct ieee80211_qoscntl *qos;
  750. struct dp_pdev *dp_pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  751. head_frag_list = NULL;
  752. mpdu_buf = NULL;
  753. if (qdf_unlikely(!dp_pdev)) {
  754. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  755. "pdev is null for mac_id = %d", mac_id);
  756. return NULL;
  757. }
  758. /* The nbuf has been pulled just beyond the status and points to the
  759. * payload
  760. */
  761. if (!head_msdu)
  762. goto mpdu_stitch_fail;
  763. msdu_orig = head_msdu;
  764. rx_desc = qdf_nbuf_data(msdu_orig);
  765. if (HAL_RX_DESC_GET_MPDU_LENGTH_ERR(rx_desc)) {
  766. /* It looks like there is some issue on MPDU len err */
  767. /* Need further investigate if drop the packet */
  768. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  769. return NULL;
  770. }
  771. rx_desc = qdf_nbuf_data(last_msdu);
  772. rx_status->cdp_rs_fcs_err = HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  773. dp_pdev->ppdu_info.rx_status.rs_fcs_err =
  774. HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  775. /* Fill out the rx_status from the PPDU start and end fields */
  776. /* HAL_RX_GET_PPDU_STATUS(soc, mac_id, rx_status); */
  777. rx_desc = qdf_nbuf_data(head_msdu);
  778. decap_format = HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc);
  779. /* Easy case - The MSDU status indicates that this is a non-decapped
  780. * packet in RAW mode.
  781. */
  782. if (decap_format == HAL_HW_RX_DECAP_FORMAT_RAW) {
  783. /* Note that this path might suffer from headroom unavailabilty
  784. * - but the RX status is usually enough
  785. */
  786. dp_rx_msdus_set_payload(soc, head_msdu);
  787. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  788. "[%s][%d] decap format raw head %pK head->next %pK last_msdu %pK last_msdu->next %pK",
  789. __func__, __LINE__, head_msdu, head_msdu->next,
  790. last_msdu, last_msdu->next);
  791. mpdu_buf = head_msdu;
  792. prev_buf = mpdu_buf;
  793. frag_list_sum_len = 0;
  794. msdu = qdf_nbuf_next(head_msdu);
  795. is_first_frag = 1;
  796. while (msdu) {
  797. dp_rx_msdus_set_payload(soc, msdu);
  798. if (is_first_frag) {
  799. is_first_frag = 0;
  800. head_frag_list = msdu;
  801. }
  802. frag_list_sum_len += qdf_nbuf_len(msdu);
  803. /* Maintain the linking of the cloned MSDUS */
  804. qdf_nbuf_set_next_ext(prev_buf, msdu);
  805. /* Move to the next */
  806. prev_buf = msdu;
  807. msdu = qdf_nbuf_next(msdu);
  808. }
  809. qdf_nbuf_trim_tail(prev_buf, HAL_RX_FCS_LEN);
  810. /* If there were more fragments to this RAW frame */
  811. if (head_frag_list) {
  812. if (frag_list_sum_len <
  813. sizeof(struct ieee80211_frame_min_one)) {
  814. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  815. return NULL;
  816. }
  817. frag_list_sum_len -= HAL_RX_FCS_LEN;
  818. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  819. frag_list_sum_len);
  820. qdf_nbuf_set_next(mpdu_buf, NULL);
  821. }
  822. goto mpdu_stitch_done;
  823. }
  824. /* Decap mode:
  825. * Calculate the amount of header in decapped packet to knock off based
  826. * on the decap type and the corresponding number of raw bytes to copy
  827. * status header
  828. */
  829. rx_desc = qdf_nbuf_data(head_msdu);
  830. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  831. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  832. "[%s][%d] decap format not raw",
  833. __func__, __LINE__);
  834. /* Base size */
  835. wifi_hdr_len = sizeof(struct ieee80211_frame);
  836. wh = (struct ieee80211_frame *)hdr_desc;
  837. dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
  838. if (dir == IEEE80211_FC1_DIR_DSTODS)
  839. wifi_hdr_len += 6;
  840. is_amsdu = 0;
  841. if (wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) {
  842. qos = (struct ieee80211_qoscntl *)
  843. (hdr_desc + wifi_hdr_len);
  844. wifi_hdr_len += 2;
  845. is_amsdu = (qos->i_qos[0] & IEEE80211_QOS_AMSDU);
  846. }
  847. /*Calculate security header length based on 'Protected'
  848. * and 'EXT_IV' flag
  849. * */
  850. if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
  851. char *iv = (char *)wh + wifi_hdr_len;
  852. if (iv[3] & KEY_EXTIV)
  853. sec_hdr_len = 8;
  854. else
  855. sec_hdr_len = 4;
  856. } else {
  857. sec_hdr_len = 0;
  858. }
  859. wifi_hdr_len += sec_hdr_len;
  860. /* MSDU related stuff LLC - AMSDU subframe header etc */
  861. msdu_llc_len = is_amsdu ? (14 + 8) : 8;
  862. mpdu_buf_len = wifi_hdr_len + msdu_llc_len;
  863. /* "Decap" header to remove from MSDU buffer */
  864. decap_hdr_pull_bytes = 14;
  865. /* Allocate a new nbuf for holding the 802.11 header retrieved from the
  866. * status of the now decapped first msdu. Leave enough headroom for
  867. * accomodating any radio-tap /prism like PHY header
  868. */
  869. mpdu_buf = qdf_nbuf_alloc(soc->osdev,
  870. MAX_MONITOR_HEADER + mpdu_buf_len,
  871. MAX_MONITOR_HEADER, 4, FALSE);
  872. if (!mpdu_buf)
  873. goto mpdu_stitch_done;
  874. /* Copy the MPDU related header and enc headers into the first buffer
  875. * - Note that there can be a 2 byte pad between heaader and enc header
  876. */
  877. prev_buf = mpdu_buf;
  878. dest = qdf_nbuf_put_tail(prev_buf, wifi_hdr_len);
  879. if (!dest)
  880. goto mpdu_stitch_fail;
  881. qdf_mem_copy(dest, hdr_desc, wifi_hdr_len);
  882. hdr_desc += wifi_hdr_len;
  883. #if 0
  884. dest = qdf_nbuf_put_tail(prev_buf, sec_hdr_len);
  885. adf_os_mem_copy(dest, hdr_desc, sec_hdr_len);
  886. hdr_desc += sec_hdr_len;
  887. #endif
  888. /* The first LLC len is copied into the MPDU buffer */
  889. frag_list_sum_len = 0;
  890. msdu_orig = head_msdu;
  891. is_first_frag = 1;
  892. amsdu_pad = 0;
  893. while (msdu_orig) {
  894. /* TODO: intra AMSDU padding - do we need it ??? */
  895. msdu = msdu_orig;
  896. if (is_first_frag) {
  897. head_frag_list = msdu;
  898. } else {
  899. /* Reload the hdr ptr only on non-first MSDUs */
  900. rx_desc = qdf_nbuf_data(msdu_orig);
  901. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  902. }
  903. /* Copy this buffers MSDU related status into the prev buffer */
  904. if (is_first_frag) {
  905. is_first_frag = 0;
  906. }
  907. /* Update protocol and flow tag for MSDU */
  908. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev,
  909. msdu_orig, rx_desc);
  910. dest = qdf_nbuf_put_tail(prev_buf,
  911. msdu_llc_len + amsdu_pad);
  912. if (!dest)
  913. goto mpdu_stitch_fail;
  914. dest += amsdu_pad;
  915. qdf_mem_copy(dest, hdr_desc, msdu_llc_len);
  916. dp_rx_msdus_set_payload(soc, msdu);
  917. /* Push the MSDU buffer beyond the decap header */
  918. qdf_nbuf_pull_head(msdu, decap_hdr_pull_bytes);
  919. frag_list_sum_len += msdu_llc_len + qdf_nbuf_len(msdu)
  920. + amsdu_pad;
  921. /* Set up intra-AMSDU pad to be added to start of next buffer -
  922. * AMSDU pad is 4 byte pad on AMSDU subframe */
  923. amsdu_pad = (msdu_llc_len + qdf_nbuf_len(msdu)) & 0x3;
  924. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  925. /* TODO FIXME How do we handle MSDUs that have fraglist - Should
  926. * probably iterate all the frags cloning them along the way and
  927. * and also updating the prev_buf pointer
  928. */
  929. /* Move to the next */
  930. prev_buf = msdu;
  931. msdu_orig = qdf_nbuf_next(msdu_orig);
  932. }
  933. #if 0
  934. /* Add in the trailer section - encryption trailer + FCS */
  935. qdf_nbuf_put_tail(prev_buf, HAL_RX_FCS_LEN);
  936. frag_list_sum_len += HAL_RX_FCS_LEN;
  937. #endif
  938. frag_list_sum_len -= msdu_llc_len;
  939. /* TODO: Convert this to suitable adf routines */
  940. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  941. frag_list_sum_len);
  942. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  943. "%s %d mpdu_buf %pK mpdu_buf->len %u",
  944. __func__, __LINE__,
  945. mpdu_buf, mpdu_buf->len);
  946. mpdu_stitch_done:
  947. /* Check if this buffer contains the PPDU end status for TSF */
  948. /* Need revist this code to see where we can get tsf timestamp */
  949. #if 0
  950. /* PPDU end TLV will be retrieved from monitor status ring */
  951. last_mpdu =
  952. (*(((u_int32_t *)&rx_desc->attention)) &
  953. RX_ATTENTION_0_LAST_MPDU_MASK) >>
  954. RX_ATTENTION_0_LAST_MPDU_LSB;
  955. if (last_mpdu)
  956. rx_status->rs_tstamp.tsf = rx_desc->ppdu_end.tsf_timestamp;
  957. #endif
  958. return mpdu_buf;
  959. mpdu_stitch_fail:
  960. if ((mpdu_buf) && (decap_format != HAL_HW_RX_DECAP_FORMAT_RAW)) {
  961. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  962. "%s mpdu_stitch_fail mpdu_buf %pK",
  963. __func__, mpdu_buf);
  964. /* Free the head buffer */
  965. qdf_nbuf_free(mpdu_buf);
  966. }
  967. return NULL;
  968. }
  969. #ifdef DP_RX_MON_MEM_FRAG
  970. #if defined(WLAN_SUPPORT_RX_PROTOCOL_TYPE_TAG) ||\
  971. defined(WLAN_SUPPORT_RX_FLOW_TAG)
  972. static inline
  973. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  974. struct dp_pdev *pdev,
  975. qdf_nbuf_t nbuf)
  976. {
  977. bool is_mon_protocol_flow_tag_enabled;
  978. if (qdf_unlikely(!soc || !pdev || !nbuf))
  979. return;
  980. /* Return if it dint came from mon Path */
  981. if (!qdf_nbuf_get_nr_frags(nbuf))
  982. return;
  983. is_mon_protocol_flow_tag_enabled =
  984. wlan_cfg_is_rx_mon_protocol_flow_tag_enabled(soc->wlan_cfg_ctx);
  985. if (qdf_unlikely(!is_mon_protocol_flow_tag_enabled))
  986. return;
  987. if (qdf_likely(!pdev->is_rx_protocol_tagging_enabled))
  988. return;
  989. if (qdf_unlikely(qdf_nbuf_headroom(nbuf) < DP_RX_MON_PF_TAG_TOT_LEN)) {
  990. dp_err("Nbuf avail Headroom[%d] < DP_RX_MON_PF_TAG_TOT_LEN[%d]",
  991. qdf_nbuf_headroom(nbuf), DP_RX_MON_PF_TAG_TOT_LEN);
  992. return;
  993. }
  994. qdf_nbuf_push_head(nbuf, DP_RX_MON_PF_TAG_TOT_LEN);
  995. qdf_mem_copy(qdf_nbuf_data(nbuf), qdf_nbuf_head(nbuf),
  996. DP_RX_MON_PF_TAG_TOT_LEN);
  997. qdf_nbuf_pull_head(nbuf, DP_RX_MON_PF_TAG_TOT_LEN);
  998. }
  999. #else
  1000. static inline
  1001. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  1002. struct dp_pdev *pdev,
  1003. qdf_nbuf_t nbuf)
  1004. {
  1005. }
  1006. #endif
  1007. #else
  1008. static inline
  1009. void dp_rx_mon_update_pf_tag_to_buf_headroom(struct dp_soc *soc,
  1010. struct dp_pdev *pdev,
  1011. qdf_nbuf_t nbuf)
  1012. {
  1013. }
  1014. #endif
  1015. /**
  1016. * dp_send_mgmt_packet_to_stack(): send indicataion to upper layers
  1017. *
  1018. * @soc: soc handle
  1019. * @nbuf: Mgmt packet
  1020. * @pdev: pdev handle
  1021. *
  1022. * Return: QDF_STATUS_SUCCESS on success
  1023. * QDF_STATUS_E_INVAL in error
  1024. */
  1025. #ifdef FEATURE_PERPKT_INFO
  1026. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  1027. qdf_nbuf_t nbuf,
  1028. struct dp_pdev *pdev)
  1029. {
  1030. uint32_t *nbuf_data;
  1031. struct ieee80211_frame *wh;
  1032. if (!nbuf)
  1033. return QDF_STATUS_E_INVAL;
  1034. /*check if this is not a mgmt packet*/
  1035. wh = (struct ieee80211_frame *)qdf_nbuf_data(nbuf);
  1036. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  1037. IEEE80211_FC0_TYPE_MGT) &&
  1038. ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  1039. IEEE80211_FC0_TYPE_CTL)) {
  1040. qdf_nbuf_free(nbuf);
  1041. return QDF_STATUS_E_INVAL;
  1042. }
  1043. nbuf_data = (uint32_t *)qdf_nbuf_push_head(nbuf, 4);
  1044. if (!nbuf_data) {
  1045. QDF_TRACE(QDF_MODULE_ID_DP,
  1046. QDF_TRACE_LEVEL_ERROR,
  1047. FL("No headroom"));
  1048. qdf_nbuf_free(nbuf);
  1049. return QDF_STATUS_E_INVAL;
  1050. }
  1051. *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
  1052. dp_rx_mon_update_pf_tag_to_buf_headroom(soc, pdev, nbuf);
  1053. dp_wdi_event_handler(WDI_EVENT_RX_MGMT_CTRL, soc, nbuf,
  1054. HTT_INVALID_PEER,
  1055. WDI_NO_VAL, pdev->pdev_id);
  1056. return QDF_STATUS_SUCCESS;
  1057. }
  1058. #else
  1059. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  1060. qdf_nbuf_t nbuf,
  1061. struct dp_pdev *pdev)
  1062. {
  1063. return QDF_STATUS_SUCCESS;
  1064. }
  1065. #endif
  1066. /**
  1067. * dp_rx_extract_radiotap_info(): Extract and populate information in
  1068. * struct mon_rx_status type
  1069. * @rx_status: Receive status
  1070. * @mon_rx_status: Monitor mode status
  1071. *
  1072. * Returns: None
  1073. */
  1074. static inline
  1075. void dp_rx_extract_radiotap_info(struct cdp_mon_status *rx_status,
  1076. struct mon_rx_status *rx_mon_status)
  1077. {
  1078. rx_mon_status->tsft = rx_status->cdp_rs_tstamp.cdp_tsf;
  1079. rx_mon_status->chan_freq = rx_status->rs_freq;
  1080. rx_mon_status->chan_num = rx_status->rs_channel;
  1081. rx_mon_status->chan_flags = rx_status->rs_flags;
  1082. rx_mon_status->rate = rx_status->rs_datarate;
  1083. /* TODO: rx_mon_status->ant_signal_db */
  1084. /* TODO: rx_mon_status->nr_ant */
  1085. rx_mon_status->mcs = rx_status->cdf_rs_rate_mcs;
  1086. rx_mon_status->is_stbc = rx_status->cdp_rs_stbc;
  1087. rx_mon_status->sgi = rx_status->cdp_rs_sgi;
  1088. /* TODO: rx_mon_status->ldpc */
  1089. /* TODO: rx_mon_status->beamformed */
  1090. /* TODO: rx_mon_status->vht_flags */
  1091. /* TODO: rx_mon_status->vht_flag_values1 */
  1092. }
  1093. #ifdef DP_RX_MON_MEM_FRAG
  1094. static inline
  1095. qdf_nbuf_t dp_rx_mon_restitch_mpdu(struct dp_soc *soc, uint32_t mac_id,
  1096. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu,
  1097. struct cdp_mon_status *rs)
  1098. {
  1099. if (qdf_nbuf_get_nr_frags(head_msdu))
  1100. return dp_rx_mon_frag_restitch_mpdu_from_msdus(soc, mac_id,
  1101. head_msdu,
  1102. tail_msdu, rs);
  1103. else
  1104. return dp_rx_mon_restitch_mpdu_from_msdus(soc, mac_id,
  1105. head_msdu,
  1106. tail_msdu, rs);
  1107. }
  1108. #else
  1109. static inline
  1110. qdf_nbuf_t dp_rx_mon_restitch_mpdu(struct dp_soc *soc, uint32_t mac_id,
  1111. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu,
  1112. struct cdp_mon_status *rs)
  1113. {
  1114. return dp_rx_mon_restitch_mpdu_from_msdus(soc, mac_id, head_msdu,
  1115. tail_msdu, rs);
  1116. }
  1117. #endif
  1118. /*
  1119. * dp_rx_mon_deliver(): function to deliver packets to stack
  1120. * @soc: DP soc
  1121. * @mac_id: MAC ID
  1122. * @head_msdu: head of msdu list
  1123. * @tail_msdu: tail of msdu list
  1124. *
  1125. * Return: status: 0 - Success, non-zero: Failure
  1126. */
  1127. QDF_STATUS dp_rx_mon_deliver(struct dp_soc *soc, uint32_t mac_id,
  1128. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu)
  1129. {
  1130. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1131. struct cdp_mon_status *rs = &pdev->rx_mon_recv_status;
  1132. qdf_nbuf_t mon_skb, skb_next;
  1133. qdf_nbuf_t mon_mpdu = NULL;
  1134. if (!pdev || (!pdev->monitor_vdev && !pdev->mcopy_mode))
  1135. goto mon_deliver_fail;
  1136. /* restitch mon MPDU for delivery via monitor interface */
  1137. mon_mpdu = dp_rx_mon_restitch_mpdu(soc, mac_id, head_msdu,
  1138. tail_msdu, rs);
  1139. /* monitor vap cannot be present when mcopy is enabled
  1140. * hence same skb can be consumed
  1141. */
  1142. if (pdev->mcopy_mode)
  1143. return dp_send_mgmt_packet_to_stack(soc, mon_mpdu, pdev);
  1144. if (mon_mpdu && pdev->monitor_vdev && pdev->monitor_vdev->osif_vdev &&
  1145. pdev->monitor_vdev->osif_rx_mon) {
  1146. pdev->ppdu_info.rx_status.ppdu_id =
  1147. pdev->ppdu_info.com_info.ppdu_id;
  1148. pdev->ppdu_info.rx_status.device_id = soc->device_id;
  1149. pdev->ppdu_info.rx_status.chan_noise_floor =
  1150. pdev->chan_noise_floor;
  1151. dp_handle_tx_capture(soc, pdev, mon_mpdu);
  1152. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status,
  1153. mon_mpdu,
  1154. qdf_nbuf_headroom(mon_mpdu))) {
  1155. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  1156. goto mon_deliver_fail;
  1157. }
  1158. dp_rx_mon_update_pf_tag_to_buf_headroom(soc, pdev, head_msdu);
  1159. pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  1160. mon_mpdu,
  1161. &pdev->ppdu_info.rx_status);
  1162. } else {
  1163. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1164. "[%s][%d] mon_mpdu=%pK monitor_vdev %pK osif_vdev %pK"
  1165. , __func__, __LINE__, mon_mpdu, pdev->monitor_vdev,
  1166. (pdev->monitor_vdev ? pdev->monitor_vdev->osif_vdev
  1167. : NULL));
  1168. goto mon_deliver_fail;
  1169. }
  1170. return QDF_STATUS_SUCCESS;
  1171. mon_deliver_fail:
  1172. mon_skb = head_msdu;
  1173. while (mon_skb) {
  1174. skb_next = qdf_nbuf_next(mon_skb);
  1175. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1176. "[%s][%d] mon_skb=%pK len %u", __func__,
  1177. __LINE__, mon_skb, mon_skb->len);
  1178. qdf_nbuf_free(mon_skb);
  1179. mon_skb = skb_next;
  1180. }
  1181. return QDF_STATUS_E_INVAL;
  1182. }
  1183. /**
  1184. * dp_rx_mon_deliver_non_std()
  1185. * @soc: core txrx main contex
  1186. * @mac_id: MAC ID
  1187. *
  1188. * This function delivers the radio tap and dummy MSDU
  1189. * into user layer application for preamble only PPDU.
  1190. *
  1191. * Return: QDF_STATUS
  1192. */
  1193. QDF_STATUS dp_rx_mon_deliver_non_std(struct dp_soc *soc,
  1194. uint32_t mac_id)
  1195. {
  1196. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1197. ol_txrx_rx_mon_fp osif_rx_mon;
  1198. qdf_nbuf_t dummy_msdu;
  1199. /* Sanity checking */
  1200. if (!pdev || !pdev->monitor_vdev || !pdev->monitor_vdev->osif_rx_mon)
  1201. goto mon_deliver_non_std_fail;
  1202. /* Generate a dummy skb_buff */
  1203. osif_rx_mon = pdev->monitor_vdev->osif_rx_mon;
  1204. dummy_msdu = qdf_nbuf_alloc(soc->osdev, MAX_MONITOR_HEADER,
  1205. MAX_MONITOR_HEADER, 4, FALSE);
  1206. if (!dummy_msdu)
  1207. goto allocate_dummy_msdu_fail;
  1208. qdf_nbuf_set_pktlen(dummy_msdu, 0);
  1209. qdf_nbuf_set_next(dummy_msdu, NULL);
  1210. pdev->ppdu_info.rx_status.ppdu_id =
  1211. pdev->ppdu_info.com_info.ppdu_id;
  1212. /* Apply the radio header to this dummy skb */
  1213. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status, dummy_msdu,
  1214. qdf_nbuf_headroom(dummy_msdu))) {
  1215. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  1216. qdf_nbuf_free(dummy_msdu);
  1217. goto mon_deliver_non_std_fail;
  1218. }
  1219. /* deliver to the user layer application */
  1220. osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  1221. dummy_msdu, NULL);
  1222. /* Clear rx_status*/
  1223. qdf_mem_zero(&pdev->ppdu_info.rx_status,
  1224. sizeof(pdev->ppdu_info.rx_status));
  1225. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1226. return QDF_STATUS_SUCCESS;
  1227. allocate_dummy_msdu_fail:
  1228. QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_DP, "[%s][%d] mon_skb=%pK ",
  1229. __func__, __LINE__, dummy_msdu);
  1230. mon_deliver_non_std_fail:
  1231. return QDF_STATUS_E_INVAL;
  1232. }
  1233. void dp_rx_mon_dest_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  1234. uint32_t mac_id, uint32_t quota)
  1235. {
  1236. struct dp_pdev *pdev = dp_get_pdev_for_lmac_id(soc, mac_id);
  1237. uint8_t pdev_id;
  1238. hal_rxdma_desc_t rxdma_dst_ring_desc;
  1239. hal_soc_handle_t hal_soc;
  1240. void *mon_dst_srng;
  1241. union dp_rx_desc_list_elem_t *head = NULL;
  1242. union dp_rx_desc_list_elem_t *tail = NULL;
  1243. uint32_t ppdu_id;
  1244. uint32_t rx_bufs_used;
  1245. uint32_t mpdu_rx_bufs_used;
  1246. int mac_for_pdev = mac_id;
  1247. struct cdp_pdev_mon_stats *rx_mon_stats;
  1248. if (!pdev) {
  1249. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1250. "pdev is null for mac_id = %d", mac_id);
  1251. return;
  1252. }
  1253. mon_dst_srng = dp_rxdma_get_mon_dst_ring(pdev, mac_for_pdev);
  1254. if (!mon_dst_srng || !hal_srng_initialized(mon_dst_srng)) {
  1255. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1256. "%s %d : HAL Monitor Destination Ring Init Failed -- %pK",
  1257. __func__, __LINE__, mon_dst_srng);
  1258. return;
  1259. }
  1260. hal_soc = soc->hal_soc;
  1261. qdf_assert((hal_soc && pdev));
  1262. qdf_spin_lock_bh(&pdev->mon_lock);
  1263. if (qdf_unlikely(dp_srng_access_start(int_ctx, soc, mon_dst_srng))) {
  1264. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  1265. "%s %d : HAL Monitor Destination Ring access Failed -- %pK",
  1266. __func__, __LINE__, mon_dst_srng);
  1267. return;
  1268. }
  1269. pdev_id = pdev->pdev_id;
  1270. ppdu_id = pdev->ppdu_info.com_info.ppdu_id;
  1271. rx_bufs_used = 0;
  1272. rx_mon_stats = &pdev->rx_mon_stats;
  1273. while (qdf_likely(rxdma_dst_ring_desc =
  1274. hal_srng_dst_peek(hal_soc, mon_dst_srng))) {
  1275. qdf_nbuf_t head_msdu, tail_msdu;
  1276. uint32_t npackets;
  1277. head_msdu = (qdf_nbuf_t) NULL;
  1278. tail_msdu = (qdf_nbuf_t) NULL;
  1279. mpdu_rx_bufs_used =
  1280. dp_rx_mon_mpdu_pop(soc, mac_id,
  1281. rxdma_dst_ring_desc,
  1282. &head_msdu, &tail_msdu,
  1283. &npackets, &ppdu_id,
  1284. &head, &tail);
  1285. rx_bufs_used += mpdu_rx_bufs_used;
  1286. if (mpdu_rx_bufs_used)
  1287. pdev->mon_dest_ring_stuck_cnt = 0;
  1288. else
  1289. pdev->mon_dest_ring_stuck_cnt++;
  1290. if (pdev->mon_dest_ring_stuck_cnt >
  1291. MON_DEST_RING_STUCK_MAX_CNT) {
  1292. dp_info("destination ring stuck");
  1293. dp_info("ppdu_id status=%d dest=%d",
  1294. pdev->ppdu_info.com_info.ppdu_id, ppdu_id);
  1295. rx_mon_stats->mon_rx_dest_stuck++;
  1296. pdev->ppdu_info.com_info.ppdu_id = ppdu_id;
  1297. continue;
  1298. }
  1299. if (ppdu_id != pdev->ppdu_info.com_info.ppdu_id) {
  1300. rx_mon_stats->stat_ring_ppdu_id_hist[
  1301. rx_mon_stats->ppdu_id_hist_idx] =
  1302. pdev->ppdu_info.com_info.ppdu_id;
  1303. rx_mon_stats->dest_ring_ppdu_id_hist[
  1304. rx_mon_stats->ppdu_id_hist_idx] = ppdu_id;
  1305. rx_mon_stats->ppdu_id_hist_idx =
  1306. (rx_mon_stats->ppdu_id_hist_idx + 1) &
  1307. (MAX_PPDU_ID_HIST - 1);
  1308. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  1309. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  1310. sizeof(pdev->ppdu_info.rx_status));
  1311. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  1312. "%s %d ppdu_id %x != ppdu_info.com_info.ppdu_id %x",
  1313. __func__, __LINE__,
  1314. ppdu_id, pdev->ppdu_info.com_info.ppdu_id);
  1315. break;
  1316. }
  1317. if (qdf_likely((head_msdu) &&
  1318. (DP_RX_MON_IS_MSDU_NOT_NULL(tail_msdu)))) {
  1319. rx_mon_stats->dest_mpdu_done++;
  1320. dp_rx_mon_deliver(soc, mac_id, head_msdu, tail_msdu);
  1321. }
  1322. rxdma_dst_ring_desc = hal_srng_dst_get_next(hal_soc,
  1323. mon_dst_srng);
  1324. }
  1325. dp_srng_access_end(int_ctx, soc, mon_dst_srng);
  1326. qdf_spin_unlock_bh(&pdev->mon_lock);
  1327. if (rx_bufs_used) {
  1328. rx_mon_stats->dest_ppdu_done++;
  1329. dp_rx_buffers_replenish(soc, mac_id,
  1330. dp_rxdma_get_mon_buf_ring(pdev,
  1331. mac_for_pdev),
  1332. dp_rx_get_mon_desc_pool(soc, mac_id,
  1333. pdev_id),
  1334. rx_bufs_used, &head, &tail);
  1335. }
  1336. }
  1337. QDF_STATUS
  1338. dp_rx_pdev_mon_buf_buffers_alloc(struct dp_pdev *pdev, uint32_t mac_id,
  1339. bool delayed_replenish)
  1340. {
  1341. uint8_t pdev_id = pdev->pdev_id;
  1342. struct dp_soc *soc = pdev->soc;
  1343. struct dp_srng *mon_buf_ring;
  1344. uint32_t num_entries;
  1345. struct rx_desc_pool *rx_desc_pool;
  1346. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1347. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1348. mon_buf_ring = dp_rxdma_get_mon_buf_ring(pdev, mac_id);
  1349. num_entries = mon_buf_ring->num_entries;
  1350. rx_desc_pool = dp_rx_get_mon_desc_pool(soc, mac_id, pdev_id);
  1351. dp_debug("Mon RX Desc Pool[%d] entries=%u", pdev_id, num_entries);
  1352. /* Replenish RXDMA monitor buffer ring with 8 buffers only
  1353. * delayed_replenish_entries is actually 8 but when we call
  1354. * dp_pdev_rx_buffers_attach() we pass 1 less than 8, hence
  1355. * added 1 to delayed_replenish_entries to ensure we have 8
  1356. * entries. Once the monitor VAP is configured we replenish
  1357. * the complete RXDMA monitor buffer ring.
  1358. */
  1359. if (delayed_replenish) {
  1360. num_entries = soc_cfg_ctx->delayed_replenish_entries + 1;
  1361. status = dp_pdev_rx_buffers_attach(soc, mac_id, mon_buf_ring,
  1362. rx_desc_pool,
  1363. num_entries - 1);
  1364. } else {
  1365. union dp_rx_desc_list_elem_t *tail = NULL;
  1366. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1367. status = dp_rx_buffers_replenish(soc, mac_id,
  1368. mon_buf_ring,
  1369. rx_desc_pool,
  1370. num_entries,
  1371. &desc_list,
  1372. &tail);
  1373. }
  1374. return status;
  1375. }
  1376. static QDF_STATUS
  1377. dp_rx_pdev_mon_cmn_buffers_alloc(struct dp_pdev *pdev, int mac_id)
  1378. {
  1379. struct dp_soc *soc = pdev->soc;
  1380. uint8_t pdev_id = pdev->pdev_id;
  1381. int mac_for_pdev;
  1382. bool delayed_replenish;
  1383. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1384. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1385. delayed_replenish = soc_cfg_ctx->delayed_replenish_entries ? 1 : 0;
  1386. mac_for_pdev = dp_get_lmac_id_for_pdev_id(pdev->soc, mac_id, pdev_id);
  1387. status = dp_rx_pdev_mon_status_buffers_alloc(pdev, mac_for_pdev);
  1388. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1389. dp_err("%s: dp_rx_pdev_mon_status_desc_pool_alloc() failed",
  1390. __func__);
  1391. goto fail;
  1392. }
  1393. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1394. return status;
  1395. status = dp_rx_pdev_mon_buf_buffers_alloc(pdev, mac_for_pdev,
  1396. delayed_replenish);
  1397. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1398. dp_err("%s: dp_rx_pdev_mon_buf_desc_pool_alloc() failed\n",
  1399. __func__);
  1400. goto mon_stat_buf_dealloc;
  1401. }
  1402. return status;
  1403. mon_stat_buf_dealloc:
  1404. dp_rx_pdev_mon_status_buffers_free(pdev, mac_for_pdev);
  1405. fail:
  1406. return status;
  1407. }
  1408. static void
  1409. dp_rx_pdev_mon_buf_desc_pool_init(struct dp_pdev *pdev, uint32_t mac_id)
  1410. {
  1411. uint8_t pdev_id = pdev->pdev_id;
  1412. struct dp_soc *soc = pdev->soc;
  1413. struct dp_srng *mon_buf_ring;
  1414. uint32_t num_entries;
  1415. struct rx_desc_pool *rx_desc_pool;
  1416. uint32_t rx_desc_pool_size;
  1417. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1418. mon_buf_ring = &soc->rxdma_mon_buf_ring[mac_id];
  1419. num_entries = mon_buf_ring->num_entries;
  1420. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1421. dp_debug("Mon RX Desc buf Pool[%d] init entries=%u",
  1422. pdev_id, num_entries);
  1423. rx_desc_pool_size = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc_cfg_ctx) *
  1424. num_entries;
  1425. rx_desc_pool->owner = HAL_RX_BUF_RBM_SW3_BM;
  1426. rx_desc_pool->buf_size = RX_MONITOR_BUFFER_SIZE;
  1427. rx_desc_pool->buf_alignment = RX_MONITOR_BUFFER_ALIGNMENT;
  1428. /* Enable frag processing if feature is enabled */
  1429. dp_rx_enable_mon_dest_frag(rx_desc_pool, true);
  1430. dp_rx_desc_pool_init(soc, mac_id, rx_desc_pool_size, rx_desc_pool);
  1431. pdev->mon_last_linkdesc_paddr = 0;
  1432. pdev->mon_last_buf_cookie = DP_RX_DESC_COOKIE_MAX + 1;
  1433. /* Attach full monitor mode resources */
  1434. dp_full_mon_attach(pdev);
  1435. }
  1436. static void
  1437. dp_rx_pdev_mon_cmn_desc_pool_init(struct dp_pdev *pdev, int mac_id)
  1438. {
  1439. struct dp_soc *soc = pdev->soc;
  1440. uint32_t mac_for_pdev;
  1441. mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev->pdev_id);
  1442. dp_rx_pdev_mon_status_desc_pool_init(pdev, mac_for_pdev);
  1443. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1444. return;
  1445. dp_rx_pdev_mon_buf_desc_pool_init(pdev, mac_for_pdev);
  1446. dp_link_desc_ring_replenish(soc, mac_for_pdev);
  1447. }
  1448. static void
  1449. dp_rx_pdev_mon_buf_desc_pool_deinit(struct dp_pdev *pdev, uint32_t mac_id)
  1450. {
  1451. uint8_t pdev_id = pdev->pdev_id;
  1452. struct dp_soc *soc = pdev->soc;
  1453. struct rx_desc_pool *rx_desc_pool;
  1454. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1455. dp_debug("Mon RX Desc buf Pool[%d] deinit", pdev_id);
  1456. dp_rx_desc_pool_deinit(soc, rx_desc_pool);
  1457. /* Detach full monitor mode resources */
  1458. dp_full_mon_detach(pdev);
  1459. }
  1460. static void
  1461. dp_rx_pdev_mon_cmn_desc_pool_deinit(struct dp_pdev *pdev, int mac_id)
  1462. {
  1463. struct dp_soc *soc = pdev->soc;
  1464. uint8_t pdev_id = pdev->pdev_id;
  1465. int mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1466. dp_rx_pdev_mon_status_desc_pool_deinit(pdev, mac_for_pdev);
  1467. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1468. return;
  1469. dp_rx_pdev_mon_buf_desc_pool_deinit(pdev, mac_for_pdev);
  1470. }
  1471. static void
  1472. dp_rx_pdev_mon_buf_desc_pool_free(struct dp_pdev *pdev, uint32_t mac_id)
  1473. {
  1474. uint8_t pdev_id = pdev->pdev_id;
  1475. struct dp_soc *soc = pdev->soc;
  1476. struct rx_desc_pool *rx_desc_pool;
  1477. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1478. dp_debug("Mon RX Buf Desc Pool Free pdev[%d]", pdev_id);
  1479. dp_rx_desc_pool_free(soc, rx_desc_pool);
  1480. }
  1481. static void
  1482. dp_rx_pdev_mon_cmn_desc_pool_free(struct dp_pdev *pdev, int mac_id)
  1483. {
  1484. struct dp_soc *soc = pdev->soc;
  1485. uint8_t pdev_id = pdev->pdev_id;
  1486. int mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1487. dp_rx_pdev_mon_status_desc_pool_free(pdev, mac_for_pdev);
  1488. dp_rx_pdev_mon_buf_desc_pool_free(pdev, mac_for_pdev);
  1489. dp_hw_link_desc_pool_banks_free(soc, mac_for_pdev);
  1490. }
  1491. void dp_rx_pdev_mon_buf_buffers_free(struct dp_pdev *pdev, uint32_t mac_id)
  1492. {
  1493. uint8_t pdev_id = pdev->pdev_id;
  1494. struct dp_soc *soc = pdev->soc;
  1495. struct rx_desc_pool *rx_desc_pool;
  1496. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1497. dp_debug("Mon RX Buf buffers Free pdev[%d]", pdev_id);
  1498. if (rx_desc_pool->rx_mon_dest_frag_enable)
  1499. dp_rx_desc_frag_free(soc, rx_desc_pool);
  1500. else
  1501. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  1502. }
  1503. static QDF_STATUS
  1504. dp_rx_pdev_mon_buf_desc_pool_alloc(struct dp_pdev *pdev, uint32_t mac_id)
  1505. {
  1506. uint8_t pdev_id = pdev->pdev_id;
  1507. struct dp_soc *soc = pdev->soc;
  1508. struct dp_srng *mon_buf_ring;
  1509. uint32_t num_entries;
  1510. struct rx_desc_pool *rx_desc_pool;
  1511. uint32_t rx_desc_pool_size;
  1512. struct wlan_cfg_dp_soc_ctxt *soc_cfg_ctx = soc->wlan_cfg_ctx;
  1513. mon_buf_ring = &soc->rxdma_mon_buf_ring[mac_id];
  1514. num_entries = mon_buf_ring->num_entries;
  1515. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1516. dp_debug("Mon RX Desc Pool[%d] entries=%u",
  1517. pdev_id, num_entries);
  1518. rx_desc_pool_size = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc_cfg_ctx) *
  1519. num_entries;
  1520. return dp_rx_desc_pool_alloc(soc, rx_desc_pool_size, rx_desc_pool);
  1521. }
  1522. static QDF_STATUS
  1523. dp_rx_pdev_mon_cmn_desc_pool_alloc(struct dp_pdev *pdev, int mac_id)
  1524. {
  1525. struct dp_soc *soc = pdev->soc;
  1526. uint8_t pdev_id = pdev->pdev_id;
  1527. uint32_t mac_for_pdev;
  1528. QDF_STATUS status;
  1529. mac_for_pdev = dp_get_lmac_id_for_pdev_id(soc, mac_id, pdev_id);
  1530. /* Allocate sw rx descriptor pool for monitor status ring */
  1531. status = dp_rx_pdev_mon_status_desc_pool_alloc(pdev, mac_for_pdev);
  1532. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1533. dp_err("%s: dp_rx_pdev_mon_status_desc_pool_alloc() failed",
  1534. __func__);
  1535. goto fail;
  1536. }
  1537. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1538. return status;
  1539. /* Allocate sw rx descriptor pool for monitor RxDMA buffer ring */
  1540. status = dp_rx_pdev_mon_buf_desc_pool_alloc(pdev, mac_for_pdev);
  1541. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1542. dp_err("%s: dp_rx_pdev_mon_buf_desc_pool_alloc() failed\n",
  1543. __func__);
  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("%s: dp_hw_link_desc_pool_banks_alloc() failed",
  1550. __func__);
  1551. goto mon_buf_dealloc;
  1552. }
  1553. return status;
  1554. mon_buf_dealloc:
  1555. dp_rx_pdev_mon_buf_desc_pool_free(pdev, mac_for_pdev);
  1556. mon_status_dealloc:
  1557. dp_rx_pdev_mon_status_desc_pool_free(pdev, mac_for_pdev);
  1558. fail:
  1559. return status;
  1560. }
  1561. static void
  1562. dp_rx_pdev_mon_cmn_buffers_free(struct dp_pdev *pdev, int mac_id)
  1563. {
  1564. uint8_t pdev_id = pdev->pdev_id;
  1565. struct dp_soc *soc = pdev->soc;
  1566. int mac_for_pdev;
  1567. mac_for_pdev = dp_get_lmac_id_for_pdev_id(pdev->soc, mac_id, pdev_id);
  1568. dp_rx_pdev_mon_status_buffers_free(pdev, mac_for_pdev);
  1569. if (!soc->wlan_cfg_ctx->rxdma1_enable)
  1570. return;
  1571. dp_rx_pdev_mon_buf_buffers_free(pdev, mac_for_pdev);
  1572. }
  1573. QDF_STATUS
  1574. dp_rx_pdev_mon_desc_pool_alloc(struct dp_pdev *pdev)
  1575. {
  1576. QDF_STATUS status;
  1577. int mac_id, count;
  1578. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1579. status = dp_rx_pdev_mon_cmn_desc_pool_alloc(pdev, mac_id);
  1580. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1581. QDF_TRACE(QDF_MODULE_ID_DP,
  1582. QDF_TRACE_LEVEL_ERROR, "%s: %d failed\n",
  1583. __func__, mac_id);
  1584. for (count = 0; count < mac_id; count++)
  1585. dp_rx_pdev_mon_cmn_desc_pool_free(pdev, count);
  1586. return status;
  1587. }
  1588. }
  1589. return status;
  1590. }
  1591. void
  1592. dp_rx_pdev_mon_desc_pool_init(struct dp_pdev *pdev)
  1593. {
  1594. int mac_id;
  1595. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1596. dp_rx_pdev_mon_cmn_desc_pool_init(pdev, mac_id);
  1597. qdf_spinlock_create(&pdev->mon_lock);
  1598. }
  1599. void
  1600. dp_rx_pdev_mon_desc_pool_deinit(struct dp_pdev *pdev)
  1601. {
  1602. int mac_id;
  1603. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1604. dp_rx_pdev_mon_cmn_desc_pool_deinit(pdev, mac_id);
  1605. qdf_spinlock_destroy(&pdev->mon_lock);
  1606. }
  1607. void dp_rx_pdev_mon_desc_pool_free(struct dp_pdev *pdev)
  1608. {
  1609. int mac_id;
  1610. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1611. dp_rx_pdev_mon_cmn_desc_pool_free(pdev, mac_id);
  1612. }
  1613. void
  1614. dp_rx_pdev_mon_buffers_free(struct dp_pdev *pdev)
  1615. {
  1616. int mac_id;
  1617. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++)
  1618. dp_rx_pdev_mon_cmn_buffers_free(pdev, mac_id);
  1619. }
  1620. QDF_STATUS
  1621. dp_rx_pdev_mon_buffers_alloc(struct dp_pdev *pdev)
  1622. {
  1623. int mac_id;
  1624. QDF_STATUS status;
  1625. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1626. status = dp_rx_pdev_mon_cmn_buffers_alloc(pdev, mac_id);
  1627. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1628. QDF_TRACE(QDF_MODULE_ID_DP,
  1629. QDF_TRACE_LEVEL_ERROR, "%s: %d failed\n",
  1630. __func__, mac_id);
  1631. return status;
  1632. }
  1633. }
  1634. return status;
  1635. }