dp_rx_mon_dest.c 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746
  1. /*
  2. * Copyright (c) 2017-2019 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. /* The maxinum buffer length allocated for radio tap */
  31. #define MAX_MONITOR_HEADER (512)
  32. /*
  33. * PPDU id is from 0 to 64k-1. PPDU id read from status ring and PPDU id
  34. * read from destination ring shall track each other. If the distance of
  35. * two ppdu id is less than 20000. It is assume no wrap around. Otherwise,
  36. * It is assume wrap around.
  37. */
  38. #define NOT_PPDU_ID_WRAP_AROUND 20000
  39. /*
  40. * The destination ring processing is stuck if the destrination is not
  41. * moving while status ring moves 16 ppdu. the destination ring processing
  42. * skips this destination ring ppdu as walkaround
  43. */
  44. #define MON_DEST_RING_STUCK_MAX_CNT 16
  45. /**
  46. * dp_rx_mon_link_desc_return() - Return a MPDU link descriptor to HW
  47. * (WBM), following error handling
  48. *
  49. * @dp_pdev: core txrx pdev context
  50. * @buf_addr_info: void pointer to monitor link descriptor buf addr info
  51. * Return: QDF_STATUS
  52. */
  53. static QDF_STATUS
  54. dp_rx_mon_link_desc_return(struct dp_pdev *dp_pdev,
  55. void *buf_addr_info, int mac_id)
  56. {
  57. struct dp_srng *dp_srng;
  58. hal_ring_handle_t hal_ring_hdl;
  59. hal_soc_handle_t hal_soc;
  60. QDF_STATUS status = QDF_STATUS_E_FAILURE;
  61. void *src_srng_desc;
  62. int mac_for_pdev = dp_get_mac_id_for_mac(dp_pdev->soc, mac_id);
  63. hal_soc = dp_pdev->soc->hal_soc;
  64. dp_srng = &dp_pdev->rxdma_mon_desc_ring[mac_for_pdev];
  65. hal_ring_hdl = dp_srng->hal_srng;
  66. qdf_assert(hal_ring_hdl);
  67. if (qdf_unlikely(hal_srng_access_start(hal_soc, hal_ring_hdl))) {
  68. /* TODO */
  69. /*
  70. * Need API to convert from hal_ring pointer to
  71. * Ring Type / Ring Id combo
  72. */
  73. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  74. "%s %d : \
  75. HAL RING Access For WBM Release SRNG Failed -- %pK",
  76. __func__, __LINE__, hal_ring_hdl);
  77. goto done;
  78. }
  79. src_srng_desc = hal_srng_src_get_next(hal_soc, hal_ring_hdl);
  80. if (qdf_likely(src_srng_desc)) {
  81. /* Return link descriptor through WBM ring (SW2WBM)*/
  82. hal_rx_mon_msdu_link_desc_set(hal_soc,
  83. src_srng_desc, buf_addr_info);
  84. status = QDF_STATUS_SUCCESS;
  85. } else {
  86. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  87. "%s %d -- Monitor Link Desc WBM Release Ring Full",
  88. __func__, __LINE__);
  89. }
  90. done:
  91. hal_srng_access_end(hal_soc, hal_ring_hdl);
  92. return status;
  93. }
  94. /**
  95. * dp_mon_adjust_frag_len() - MPDU and MSDU may spread across
  96. * multiple nbufs. This function
  97. * is to return data length in
  98. * fragmented buffer
  99. *
  100. * @total_len: pointer to remaining data length.
  101. * @frag_len: pointer to data length in this fragment.
  102. */
  103. static inline void dp_mon_adjust_frag_len(uint32_t *total_len,
  104. uint32_t *frag_len)
  105. {
  106. if (*total_len >= (RX_BUFFER_SIZE - RX_PKT_TLVS_LEN)) {
  107. *frag_len = RX_BUFFER_SIZE - RX_PKT_TLVS_LEN;
  108. *total_len -= *frag_len;
  109. } else {
  110. *frag_len = *total_len;
  111. *total_len = 0;
  112. }
  113. }
  114. /**
  115. * dp_rx_cookie_2_mon_link_desc() - Retrieve Link descriptor based on target
  116. * @pdev: core physical device context
  117. * @hal_buf_info: structure holding the buffer info
  118. * mac_id: mac number
  119. *
  120. * Return: link descriptor address
  121. */
  122. static inline
  123. void *dp_rx_cookie_2_mon_link_desc(struct dp_pdev *pdev,
  124. struct hal_buf_info buf_info,
  125. uint8_t mac_id)
  126. {
  127. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  128. return dp_rx_cookie_2_mon_link_desc_va(pdev, &buf_info,
  129. mac_id);
  130. return dp_rx_cookie_2_link_desc_va(pdev->soc, &buf_info);
  131. }
  132. /**
  133. * dp_rx_monitor_link_desc_return() - Return Link descriptor based on target
  134. * @pdev: core physical device context
  135. * @p_last_buf_addr_info: MPDU Link descriptor
  136. * mac_id: mac number
  137. *
  138. * Return: QDF_STATUS
  139. */
  140. static inline
  141. QDF_STATUS dp_rx_monitor_link_desc_return(struct dp_pdev *pdev,
  142. void *p_last_buf_addr_info,
  143. uint8_t mac_id, uint8_t bm_action)
  144. {
  145. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  146. return dp_rx_mon_link_desc_return(pdev, p_last_buf_addr_info,
  147. mac_id);
  148. return dp_rx_link_desc_return(pdev->soc, p_last_buf_addr_info,
  149. bm_action);
  150. }
  151. /**
  152. * dp_rxdma_get_mon_dst_ring() - Return the pointer to rxdma_err_dst_ring
  153. * or mon_dst_ring based on the target
  154. * @pdev: core physical device context
  155. * @mac_for_pdev: mac_id number
  156. *
  157. * Return: ring address
  158. */
  159. static inline
  160. void *dp_rxdma_get_mon_dst_ring(struct dp_pdev *pdev,
  161. uint8_t mac_for_pdev)
  162. {
  163. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  164. return pdev->rxdma_mon_dst_ring[mac_for_pdev].hal_srng;
  165. return pdev->rxdma_err_dst_ring[mac_for_pdev].hal_srng;
  166. }
  167. /**
  168. * dp_rxdma_get_mon_buf_ring() - Return monitor buf ring address
  169. * based on target
  170. * @pdev: core physical device context
  171. * @mac_for_pdev: mac id number
  172. *
  173. * Return: ring address
  174. */
  175. static inline
  176. struct dp_srng *dp_rxdma_get_mon_buf_ring(struct dp_pdev *pdev,
  177. uint8_t mac_for_pdev)
  178. {
  179. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  180. return &pdev->rxdma_mon_buf_ring[mac_for_pdev];
  181. return &pdev->rx_refill_buf_ring;
  182. }
  183. /**
  184. * dp_rx_get_mon_desc_pool() - Return monitor descriptor pool
  185. * based on target
  186. * @soc: soc handle
  187. * @mac_id: mac id number
  188. * @pdev_id: pdev id number
  189. *
  190. * Return: descriptor pool address
  191. */
  192. static inline
  193. struct rx_desc_pool *dp_rx_get_mon_desc_pool(struct dp_soc *soc,
  194. uint8_t mac_id,
  195. uint8_t pdev_id)
  196. {
  197. if (soc->wlan_cfg_ctx->rxdma1_enable)
  198. return &soc->rx_desc_mon[mac_id];
  199. return &soc->rx_desc_buf[pdev_id];
  200. }
  201. /**
  202. * dp_rx_get_mon_desc() - Return Rx descriptor based on target
  203. * @soc: soc handle
  204. * @cookie: cookie value
  205. *
  206. * Return: Rx descriptor
  207. */
  208. static inline
  209. struct dp_rx_desc *dp_rx_get_mon_desc(struct dp_soc *soc,
  210. uint32_t cookie)
  211. {
  212. if (soc->wlan_cfg_ctx->rxdma1_enable)
  213. return dp_rx_cookie_2_va_mon_buf(soc, cookie);
  214. return dp_rx_cookie_2_va_rxdma_buf(soc, cookie);
  215. }
  216. /**
  217. * dp_rx_mon_mpdu_pop() - Return a MPDU link descriptor to HW
  218. * (WBM), following error handling
  219. *
  220. * @soc: core DP main context
  221. * @mac_id: mac id which is one of 3 mac_ids
  222. * @rxdma_dst_ring_desc: void pointer to monitor link descriptor buf addr info
  223. * @head_msdu: head of msdu to be popped
  224. * @tail_msdu: tail of msdu to be popped
  225. * @npackets: number of packet to be popped
  226. * @ppdu_id: ppdu id of processing ppdu
  227. * @head: head of descs list to be freed
  228. * @tail: tail of decs list to be freed
  229. *
  230. * Return: number of msdu in MPDU to be popped
  231. */
  232. static inline uint32_t
  233. dp_rx_mon_mpdu_pop(struct dp_soc *soc, uint32_t mac_id,
  234. hal_rxdma_desc_t rxdma_dst_ring_desc, qdf_nbuf_t *head_msdu,
  235. qdf_nbuf_t *tail_msdu, uint32_t *npackets, uint32_t *ppdu_id,
  236. union dp_rx_desc_list_elem_t **head,
  237. union dp_rx_desc_list_elem_t **tail)
  238. {
  239. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  240. void *rx_desc_tlv;
  241. void *rx_msdu_link_desc;
  242. qdf_nbuf_t msdu;
  243. qdf_nbuf_t last;
  244. struct hal_rx_msdu_list msdu_list;
  245. uint16_t num_msdus;
  246. uint32_t rx_buf_size, rx_pkt_offset;
  247. struct hal_buf_info buf_info;
  248. void *p_buf_addr_info;
  249. void *p_last_buf_addr_info;
  250. uint32_t rx_bufs_used = 0;
  251. uint32_t msdu_ppdu_id, msdu_cnt;
  252. uint8_t *data;
  253. uint32_t i;
  254. uint32_t total_frag_len = 0, frag_len = 0;
  255. bool is_frag, is_first_msdu;
  256. bool drop_mpdu = false;
  257. uint8_t bm_action = HAL_BM_ACTION_PUT_IN_IDLE_LIST;
  258. uint64_t nbuf_paddr = 0;
  259. msdu = 0;
  260. last = NULL;
  261. hal_rx_reo_ent_buf_paddr_get(rxdma_dst_ring_desc, &buf_info,
  262. &p_last_buf_addr_info, &msdu_cnt);
  263. if ((hal_rx_reo_ent_rxdma_push_reason_get(rxdma_dst_ring_desc) ==
  264. HAL_RX_WBM_RXDMA_PSH_RSN_ERROR)) {
  265. uint8_t rxdma_err =
  266. hal_rx_reo_ent_rxdma_error_code_get(
  267. rxdma_dst_ring_desc);
  268. if (qdf_unlikely((rxdma_err == HAL_RXDMA_ERR_FLUSH_REQUEST) ||
  269. (rxdma_err == HAL_RXDMA_ERR_MPDU_LENGTH) ||
  270. (rxdma_err == HAL_RXDMA_ERR_OVERFLOW))) {
  271. drop_mpdu = true;
  272. dp_pdev->rx_mon_stats.dest_mpdu_drop++;
  273. }
  274. }
  275. is_frag = false;
  276. is_first_msdu = true;
  277. do {
  278. /* WAR for duplicate link descriptors received from HW */
  279. if (qdf_unlikely(dp_pdev->mon_last_linkdesc_paddr ==
  280. buf_info.paddr)) {
  281. dp_pdev->rx_mon_stats.dup_mon_linkdesc_cnt++;
  282. return rx_bufs_used;
  283. }
  284. rx_msdu_link_desc =
  285. dp_rx_cookie_2_mon_link_desc(dp_pdev,
  286. buf_info, mac_id);
  287. qdf_assert(rx_msdu_link_desc);
  288. hal_rx_msdu_list_get(soc->hal_soc, rx_msdu_link_desc,
  289. &msdu_list, &num_msdus);
  290. for (i = 0; i < num_msdus; i++) {
  291. uint32_t l2_hdr_offset;
  292. struct dp_rx_desc *rx_desc = NULL;
  293. rx_desc = dp_rx_get_mon_desc(soc,
  294. msdu_list.sw_cookie[i]);
  295. qdf_assert_always(rx_desc);
  296. msdu = rx_desc->nbuf;
  297. if (msdu)
  298. nbuf_paddr = qdf_nbuf_get_frag_paddr(msdu, 0);
  299. /* WAR for duplicate buffers received from HW */
  300. if (qdf_unlikely(dp_pdev->mon_last_buf_cookie ==
  301. msdu_list.sw_cookie[i] ||
  302. !msdu ||
  303. msdu_list.paddr[i] != nbuf_paddr ||
  304. !rx_desc->in_use)) {
  305. /* Skip duplicate buffer and drop subsequent
  306. * buffers in this MPDU
  307. */
  308. drop_mpdu = true;
  309. dp_pdev->rx_mon_stats.dup_mon_buf_cnt++;
  310. dp_pdev->mon_last_linkdesc_paddr =
  311. buf_info.paddr;
  312. continue;
  313. }
  314. if (rx_desc->unmapped == 0) {
  315. qdf_nbuf_unmap_single(soc->osdev, msdu,
  316. QDF_DMA_FROM_DEVICE);
  317. rx_desc->unmapped = 1;
  318. }
  319. if (drop_mpdu) {
  320. dp_pdev->mon_last_linkdesc_paddr =
  321. buf_info.paddr;
  322. qdf_nbuf_free(msdu);
  323. msdu = NULL;
  324. goto next_msdu;
  325. }
  326. data = qdf_nbuf_data(msdu);
  327. rx_desc_tlv = HAL_RX_MON_DEST_GET_DESC(data);
  328. QDF_TRACE(QDF_MODULE_ID_DP,
  329. QDF_TRACE_LEVEL_DEBUG,
  330. "[%s] i=%d, ppdu_id=%x, num_msdus = %u",
  331. __func__, i, *ppdu_id, num_msdus);
  332. if (is_first_msdu) {
  333. if (!HAL_RX_HW_DESC_MPDU_VALID(
  334. rx_desc_tlv)) {
  335. drop_mpdu = true;
  336. qdf_nbuf_free(msdu);
  337. msdu = NULL;
  338. dp_pdev->mon_last_linkdesc_paddr =
  339. buf_info.paddr;
  340. goto next_msdu;
  341. }
  342. msdu_ppdu_id = hal_rx_hw_desc_get_ppduid_get(
  343. soc->hal_soc,
  344. rx_desc_tlv);
  345. is_first_msdu = false;
  346. QDF_TRACE(QDF_MODULE_ID_DP,
  347. QDF_TRACE_LEVEL_DEBUG,
  348. "[%s] msdu_ppdu_id=%x",
  349. __func__, msdu_ppdu_id);
  350. if (*ppdu_id > msdu_ppdu_id)
  351. QDF_TRACE(QDF_MODULE_ID_DP,
  352. QDF_TRACE_LEVEL_DEBUG,
  353. "[%s][%d] ppdu_id=%d "
  354. "msdu_ppdu_id=%d",
  355. __func__, __LINE__, *ppdu_id,
  356. msdu_ppdu_id);
  357. if ((*ppdu_id < msdu_ppdu_id) && (
  358. (msdu_ppdu_id - *ppdu_id) <
  359. NOT_PPDU_ID_WRAP_AROUND)) {
  360. *ppdu_id = msdu_ppdu_id;
  361. return rx_bufs_used;
  362. } else if ((*ppdu_id > msdu_ppdu_id) && (
  363. (*ppdu_id - msdu_ppdu_id) >
  364. NOT_PPDU_ID_WRAP_AROUND)) {
  365. *ppdu_id = msdu_ppdu_id;
  366. return rx_bufs_used;
  367. }
  368. dp_pdev->mon_last_linkdesc_paddr =
  369. buf_info.paddr;
  370. }
  371. if (hal_rx_desc_is_first_msdu(soc->hal_soc,
  372. rx_desc_tlv))
  373. hal_rx_mon_hw_desc_get_mpdu_status(soc->hal_soc,
  374. rx_desc_tlv,
  375. &(dp_pdev->ppdu_info.rx_status));
  376. if (msdu_list.msdu_info[i].msdu_flags &
  377. HAL_MSDU_F_MSDU_CONTINUATION) {
  378. if (!is_frag) {
  379. total_frag_len =
  380. msdu_list.msdu_info[i].msdu_len;
  381. is_frag = true;
  382. }
  383. dp_mon_adjust_frag_len(
  384. &total_frag_len, &frag_len);
  385. } else {
  386. if (is_frag) {
  387. dp_mon_adjust_frag_len(
  388. &total_frag_len, &frag_len);
  389. } else {
  390. frag_len =
  391. msdu_list.msdu_info[i].msdu_len;
  392. }
  393. is_frag = false;
  394. msdu_cnt--;
  395. }
  396. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  397. "%s total_len %u frag_len %u flags %u",
  398. __func__, total_frag_len, frag_len,
  399. msdu_list.msdu_info[i].msdu_flags);
  400. rx_pkt_offset = HAL_RX_MON_HW_RX_DESC_SIZE();
  401. /*
  402. * HW structures call this L3 header padding
  403. * -- even though this is actually the offset
  404. * from the buffer beginning where the L2
  405. * header begins.
  406. */
  407. l2_hdr_offset =
  408. hal_rx_msdu_end_l3_hdr_padding_get(soc->hal_soc, data);
  409. rx_buf_size = rx_pkt_offset + l2_hdr_offset
  410. + frag_len;
  411. qdf_nbuf_set_pktlen(msdu, rx_buf_size);
  412. #if 0
  413. /* Disble it.see packet on msdu done set to 0 */
  414. /*
  415. * Check if DMA completed -- msdu_done is the
  416. * last bit to be written
  417. */
  418. if (!hal_rx_attn_msdu_done_get(rx_desc_tlv)) {
  419. QDF_TRACE(QDF_MODULE_ID_DP,
  420. QDF_TRACE_LEVEL_ERROR,
  421. "%s:%d: Pkt Desc",
  422. __func__, __LINE__);
  423. QDF_TRACE_HEX_DUMP(QDF_MODULE_ID_DP,
  424. QDF_TRACE_LEVEL_ERROR,
  425. rx_desc_tlv, 128);
  426. qdf_assert_always(0);
  427. }
  428. #endif
  429. QDF_TRACE(QDF_MODULE_ID_DP,
  430. QDF_TRACE_LEVEL_DEBUG,
  431. "%s: rx_pkt_offset=%d, l2_hdr_offset=%d, msdu_len=%d, addr=%pK skb->len %u",
  432. __func__, rx_pkt_offset, l2_hdr_offset,
  433. msdu_list.msdu_info[i].msdu_len,
  434. qdf_nbuf_data(msdu),
  435. (uint32_t)qdf_nbuf_len(msdu));
  436. if (head_msdu && !*head_msdu) {
  437. *head_msdu = msdu;
  438. } else {
  439. if (last)
  440. qdf_nbuf_set_next(last, msdu);
  441. }
  442. last = msdu;
  443. next_msdu:
  444. dp_pdev->mon_last_buf_cookie = msdu_list.sw_cookie[i];
  445. rx_bufs_used++;
  446. dp_rx_add_to_free_desc_list(head,
  447. tail, rx_desc);
  448. }
  449. hal_rx_mon_next_link_desc_get(rx_msdu_link_desc, &buf_info,
  450. &p_buf_addr_info);
  451. if (dp_rx_monitor_link_desc_return(dp_pdev,
  452. p_last_buf_addr_info,
  453. mac_id,
  454. bm_action)
  455. != QDF_STATUS_SUCCESS)
  456. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  457. "dp_rx_monitor_link_desc_return failed");
  458. p_last_buf_addr_info = p_buf_addr_info;
  459. } while (buf_info.paddr && msdu_cnt);
  460. if (last)
  461. qdf_nbuf_set_next(last, NULL);
  462. *tail_msdu = msdu;
  463. return rx_bufs_used;
  464. }
  465. static inline
  466. void dp_rx_msdus_set_payload(struct dp_soc *soc, qdf_nbuf_t msdu)
  467. {
  468. uint8_t *data;
  469. uint32_t rx_pkt_offset, l2_hdr_offset;
  470. data = qdf_nbuf_data(msdu);
  471. rx_pkt_offset = HAL_RX_MON_HW_RX_DESC_SIZE();
  472. l2_hdr_offset = hal_rx_msdu_end_l3_hdr_padding_get(soc->hal_soc, data);
  473. qdf_nbuf_pull_head(msdu, rx_pkt_offset + l2_hdr_offset);
  474. }
  475. static inline
  476. qdf_nbuf_t dp_rx_mon_restitch_mpdu_from_msdus(struct dp_soc *soc,
  477. uint32_t mac_id, qdf_nbuf_t head_msdu, qdf_nbuf_t last_msdu,
  478. struct cdp_mon_status *rx_status)
  479. {
  480. qdf_nbuf_t msdu, mpdu_buf, prev_buf, msdu_orig, head_frag_list;
  481. uint32_t decap_format, wifi_hdr_len, sec_hdr_len, msdu_llc_len,
  482. mpdu_buf_len, decap_hdr_pull_bytes, frag_list_sum_len, dir,
  483. is_amsdu, is_first_frag, amsdu_pad;
  484. void *rx_desc;
  485. char *hdr_desc;
  486. unsigned char *dest;
  487. struct ieee80211_frame *wh;
  488. struct ieee80211_qoscntl *qos;
  489. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  490. head_frag_list = NULL;
  491. mpdu_buf = NULL;
  492. /* The nbuf has been pulled just beyond the status and points to the
  493. * payload
  494. */
  495. if (!head_msdu)
  496. goto mpdu_stitch_fail;
  497. msdu_orig = head_msdu;
  498. rx_desc = qdf_nbuf_data(msdu_orig);
  499. if (HAL_RX_DESC_GET_MPDU_LENGTH_ERR(rx_desc)) {
  500. /* It looks like there is some issue on MPDU len err */
  501. /* Need further investigate if drop the packet */
  502. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  503. return NULL;
  504. }
  505. rx_desc = qdf_nbuf_data(last_msdu);
  506. rx_status->cdp_rs_fcs_err = HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  507. dp_pdev->ppdu_info.rx_status.rs_fcs_err =
  508. HAL_RX_DESC_GET_MPDU_FCS_ERR(rx_desc);
  509. /* Fill out the rx_status from the PPDU start and end fields */
  510. /* HAL_RX_GET_PPDU_STATUS(soc, mac_id, rx_status); */
  511. rx_desc = qdf_nbuf_data(head_msdu);
  512. decap_format = HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc);
  513. /* Easy case - The MSDU status indicates that this is a non-decapped
  514. * packet in RAW mode.
  515. */
  516. if (decap_format == HAL_HW_RX_DECAP_FORMAT_RAW) {
  517. /* Note that this path might suffer from headroom unavailabilty
  518. * - but the RX status is usually enough
  519. */
  520. dp_rx_msdus_set_payload(soc, head_msdu);
  521. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  522. "[%s][%d] decap format raw head %pK head->next %pK last_msdu %pK last_msdu->next %pK",
  523. __func__, __LINE__, head_msdu, head_msdu->next,
  524. last_msdu, last_msdu->next);
  525. mpdu_buf = head_msdu;
  526. prev_buf = mpdu_buf;
  527. frag_list_sum_len = 0;
  528. msdu = qdf_nbuf_next(head_msdu);
  529. is_first_frag = 1;
  530. while (msdu) {
  531. dp_rx_msdus_set_payload(soc, msdu);
  532. if (is_first_frag) {
  533. is_first_frag = 0;
  534. head_frag_list = msdu;
  535. }
  536. frag_list_sum_len += qdf_nbuf_len(msdu);
  537. /* Maintain the linking of the cloned MSDUS */
  538. qdf_nbuf_set_next_ext(prev_buf, msdu);
  539. /* Move to the next */
  540. prev_buf = msdu;
  541. msdu = qdf_nbuf_next(msdu);
  542. }
  543. qdf_nbuf_trim_tail(prev_buf, HAL_RX_FCS_LEN);
  544. /* If there were more fragments to this RAW frame */
  545. if (head_frag_list) {
  546. if (frag_list_sum_len <
  547. sizeof(struct ieee80211_frame_min_one)) {
  548. DP_STATS_INC(dp_pdev, dropped.mon_rx_drop, 1);
  549. return NULL;
  550. }
  551. frag_list_sum_len -= HAL_RX_FCS_LEN;
  552. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  553. frag_list_sum_len);
  554. qdf_nbuf_set_next(mpdu_buf, NULL);
  555. }
  556. goto mpdu_stitch_done;
  557. }
  558. /* Decap mode:
  559. * Calculate the amount of header in decapped packet to knock off based
  560. * on the decap type and the corresponding number of raw bytes to copy
  561. * status header
  562. */
  563. rx_desc = qdf_nbuf_data(head_msdu);
  564. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  565. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  566. "[%s][%d] decap format not raw",
  567. __func__, __LINE__);
  568. /* Base size */
  569. wifi_hdr_len = sizeof(struct ieee80211_frame);
  570. wh = (struct ieee80211_frame *)hdr_desc;
  571. dir = wh->i_fc[1] & IEEE80211_FC1_DIR_MASK;
  572. if (dir == IEEE80211_FC1_DIR_DSTODS)
  573. wifi_hdr_len += 6;
  574. is_amsdu = 0;
  575. if (wh->i_fc[0] & QDF_IEEE80211_FC0_SUBTYPE_QOS) {
  576. qos = (struct ieee80211_qoscntl *)
  577. (hdr_desc + wifi_hdr_len);
  578. wifi_hdr_len += 2;
  579. is_amsdu = (qos->i_qos[0] & IEEE80211_QOS_AMSDU);
  580. }
  581. /*Calculate security header length based on 'Protected'
  582. * and 'EXT_IV' flag
  583. * */
  584. if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
  585. char *iv = (char *)wh + wifi_hdr_len;
  586. if (iv[3] & KEY_EXTIV)
  587. sec_hdr_len = 8;
  588. else
  589. sec_hdr_len = 4;
  590. } else {
  591. sec_hdr_len = 0;
  592. }
  593. wifi_hdr_len += sec_hdr_len;
  594. /* MSDU related stuff LLC - AMSDU subframe header etc */
  595. msdu_llc_len = is_amsdu ? (14 + 8) : 8;
  596. mpdu_buf_len = wifi_hdr_len + msdu_llc_len;
  597. /* "Decap" header to remove from MSDU buffer */
  598. decap_hdr_pull_bytes = 14;
  599. /* Allocate a new nbuf for holding the 802.11 header retrieved from the
  600. * status of the now decapped first msdu. Leave enough headroom for
  601. * accomodating any radio-tap /prism like PHY header
  602. */
  603. mpdu_buf = qdf_nbuf_alloc(soc->osdev,
  604. MAX_MONITOR_HEADER + mpdu_buf_len,
  605. MAX_MONITOR_HEADER, 4, FALSE);
  606. if (!mpdu_buf)
  607. goto mpdu_stitch_done;
  608. /* Copy the MPDU related header and enc headers into the first buffer
  609. * - Note that there can be a 2 byte pad between heaader and enc header
  610. */
  611. prev_buf = mpdu_buf;
  612. dest = qdf_nbuf_put_tail(prev_buf, wifi_hdr_len);
  613. if (!dest)
  614. goto mpdu_stitch_fail;
  615. qdf_mem_copy(dest, hdr_desc, wifi_hdr_len);
  616. hdr_desc += wifi_hdr_len;
  617. #if 0
  618. dest = qdf_nbuf_put_tail(prev_buf, sec_hdr_len);
  619. adf_os_mem_copy(dest, hdr_desc, sec_hdr_len);
  620. hdr_desc += sec_hdr_len;
  621. #endif
  622. /* The first LLC len is copied into the MPDU buffer */
  623. frag_list_sum_len = 0;
  624. msdu_orig = head_msdu;
  625. is_first_frag = 1;
  626. amsdu_pad = 0;
  627. while (msdu_orig) {
  628. /* TODO: intra AMSDU padding - do we need it ??? */
  629. msdu = msdu_orig;
  630. if (is_first_frag) {
  631. head_frag_list = msdu;
  632. } else {
  633. /* Reload the hdr ptr only on non-first MSDUs */
  634. rx_desc = qdf_nbuf_data(msdu_orig);
  635. hdr_desc = HAL_RX_DESC_GET_80211_HDR(rx_desc);
  636. }
  637. /* Copy this buffers MSDU related status into the prev buffer */
  638. if (is_first_frag) {
  639. is_first_frag = 0;
  640. }
  641. /* Update protocol and flow tag for MSDU */
  642. dp_rx_mon_update_protocol_flow_tag(soc, dp_pdev,
  643. msdu_orig, rx_desc);
  644. dest = qdf_nbuf_put_tail(prev_buf,
  645. msdu_llc_len + amsdu_pad);
  646. if (!dest)
  647. goto mpdu_stitch_fail;
  648. dest += amsdu_pad;
  649. qdf_mem_copy(dest, hdr_desc, msdu_llc_len);
  650. dp_rx_msdus_set_payload(soc, msdu);
  651. /* Push the MSDU buffer beyond the decap header */
  652. qdf_nbuf_pull_head(msdu, decap_hdr_pull_bytes);
  653. frag_list_sum_len += msdu_llc_len + qdf_nbuf_len(msdu)
  654. + amsdu_pad;
  655. /* Set up intra-AMSDU pad to be added to start of next buffer -
  656. * AMSDU pad is 4 byte pad on AMSDU subframe */
  657. amsdu_pad = (msdu_llc_len + qdf_nbuf_len(msdu)) & 0x3;
  658. amsdu_pad = amsdu_pad ? (4 - amsdu_pad) : 0;
  659. /* TODO FIXME How do we handle MSDUs that have fraglist - Should
  660. * probably iterate all the frags cloning them along the way and
  661. * and also updating the prev_buf pointer
  662. */
  663. /* Move to the next */
  664. prev_buf = msdu;
  665. msdu_orig = qdf_nbuf_next(msdu_orig);
  666. }
  667. #if 0
  668. /* Add in the trailer section - encryption trailer + FCS */
  669. qdf_nbuf_put_tail(prev_buf, HAL_RX_FCS_LEN);
  670. frag_list_sum_len += HAL_RX_FCS_LEN;
  671. #endif
  672. frag_list_sum_len -= msdu_llc_len;
  673. /* TODO: Convert this to suitable adf routines */
  674. qdf_nbuf_append_ext_list(mpdu_buf, head_frag_list,
  675. frag_list_sum_len);
  676. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  677. "%s %d mpdu_buf %pK mpdu_buf->len %u",
  678. __func__, __LINE__,
  679. mpdu_buf, mpdu_buf->len);
  680. mpdu_stitch_done:
  681. /* Check if this buffer contains the PPDU end status for TSF */
  682. /* Need revist this code to see where we can get tsf timestamp */
  683. #if 0
  684. /* PPDU end TLV will be retrieved from monitor status ring */
  685. last_mpdu =
  686. (*(((u_int32_t *)&rx_desc->attention)) &
  687. RX_ATTENTION_0_LAST_MPDU_MASK) >>
  688. RX_ATTENTION_0_LAST_MPDU_LSB;
  689. if (last_mpdu)
  690. rx_status->rs_tstamp.tsf = rx_desc->ppdu_end.tsf_timestamp;
  691. #endif
  692. return mpdu_buf;
  693. mpdu_stitch_fail:
  694. if ((mpdu_buf) && (decap_format != HAL_HW_RX_DECAP_FORMAT_RAW)) {
  695. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_ERROR,
  696. "%s mpdu_stitch_fail mpdu_buf %pK",
  697. __func__, mpdu_buf);
  698. /* Free the head buffer */
  699. qdf_nbuf_free(mpdu_buf);
  700. }
  701. return NULL;
  702. }
  703. /**
  704. * dp_send_mgmt_packet_to_stack(): send indicataion to upper layers
  705. *
  706. * @soc: soc handle
  707. * @nbuf: Mgmt packet
  708. * @pdev: pdev handle
  709. *
  710. * Return: QDF_STATUS_SUCCESS on success
  711. * QDF_STATUS_E_INVAL in error
  712. */
  713. #ifdef FEATURE_PERPKT_INFO
  714. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  715. qdf_nbuf_t nbuf,
  716. struct dp_pdev *pdev)
  717. {
  718. uint32_t *nbuf_data;
  719. struct ieee80211_frame *wh;
  720. if (!nbuf)
  721. return QDF_STATUS_E_INVAL;
  722. /*check if this is not a mgmt packet*/
  723. wh = (struct ieee80211_frame *)qdf_nbuf_data(nbuf);
  724. if (((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  725. IEEE80211_FC0_TYPE_MGT) &&
  726. ((wh->i_fc[0] & IEEE80211_FC0_TYPE_MASK) !=
  727. IEEE80211_FC0_TYPE_CTL)) {
  728. qdf_nbuf_free(nbuf);
  729. return QDF_STATUS_E_INVAL;
  730. }
  731. nbuf_data = (uint32_t *)qdf_nbuf_push_head(nbuf, 4);
  732. if (!nbuf_data) {
  733. QDF_TRACE(QDF_MODULE_ID_DP,
  734. QDF_TRACE_LEVEL_ERROR,
  735. FL("No headroom"));
  736. qdf_nbuf_free(nbuf);
  737. return QDF_STATUS_E_INVAL;
  738. }
  739. *nbuf_data = pdev->ppdu_info.com_info.ppdu_id;
  740. dp_wdi_event_handler(WDI_EVENT_RX_MGMT_CTRL, soc, nbuf,
  741. HTT_INVALID_PEER,
  742. WDI_NO_VAL, pdev->pdev_id);
  743. return QDF_STATUS_SUCCESS;
  744. }
  745. #else
  746. static inline QDF_STATUS dp_send_mgmt_packet_to_stack(struct dp_soc *soc,
  747. qdf_nbuf_t nbuf,
  748. struct dp_pdev *pdev)
  749. {
  750. return QDF_STATUS_SUCCESS;
  751. }
  752. #endif
  753. /**
  754. * dp_rx_extract_radiotap_info(): Extract and populate information in
  755. * struct mon_rx_status type
  756. * @rx_status: Receive status
  757. * @mon_rx_status: Monitor mode status
  758. *
  759. * Returns: None
  760. */
  761. static inline
  762. void dp_rx_extract_radiotap_info(struct cdp_mon_status *rx_status,
  763. struct mon_rx_status *rx_mon_status)
  764. {
  765. rx_mon_status->tsft = rx_status->cdp_rs_tstamp.cdp_tsf;
  766. rx_mon_status->chan_freq = rx_status->rs_freq;
  767. rx_mon_status->chan_num = rx_status->rs_channel;
  768. rx_mon_status->chan_flags = rx_status->rs_flags;
  769. rx_mon_status->rate = rx_status->rs_datarate;
  770. /* TODO: rx_mon_status->ant_signal_db */
  771. /* TODO: rx_mon_status->nr_ant */
  772. rx_mon_status->mcs = rx_status->cdf_rs_rate_mcs;
  773. rx_mon_status->is_stbc = rx_status->cdp_rs_stbc;
  774. rx_mon_status->sgi = rx_status->cdp_rs_sgi;
  775. /* TODO: rx_mon_status->ldpc */
  776. /* TODO: rx_mon_status->beamformed */
  777. /* TODO: rx_mon_status->vht_flags */
  778. /* TODO: rx_mon_status->vht_flag_values1 */
  779. }
  780. /*
  781. * dp_rx_mon_deliver(): function to deliver packets to stack
  782. * @soc: DP soc
  783. * @mac_id: MAC ID
  784. * @head_msdu: head of msdu list
  785. * @tail_msdu: tail of msdu list
  786. *
  787. * Return: status: 0 - Success, non-zero: Failure
  788. */
  789. QDF_STATUS dp_rx_mon_deliver(struct dp_soc *soc, uint32_t mac_id,
  790. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu)
  791. {
  792. struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  793. struct cdp_mon_status *rs = &pdev->rx_mon_recv_status;
  794. qdf_nbuf_t mon_skb, skb_next;
  795. qdf_nbuf_t mon_mpdu = NULL;
  796. if (!pdev->monitor_vdev && !pdev->mcopy_mode)
  797. goto mon_deliver_fail;
  798. /* restitch mon MPDU for delivery via monitor interface */
  799. mon_mpdu = dp_rx_mon_restitch_mpdu_from_msdus(soc, mac_id, head_msdu,
  800. tail_msdu, rs);
  801. /* monitor vap cannot be present when mcopy is enabled
  802. * hence same skb can be consumed
  803. */
  804. if (pdev->mcopy_mode)
  805. return dp_send_mgmt_packet_to_stack(soc, mon_mpdu, pdev);
  806. if (mon_mpdu && pdev->monitor_vdev && pdev->monitor_vdev->osif_vdev &&
  807. pdev->monitor_vdev->osif_rx_mon) {
  808. pdev->ppdu_info.rx_status.ppdu_id =
  809. pdev->ppdu_info.com_info.ppdu_id;
  810. pdev->ppdu_info.rx_status.device_id = soc->device_id;
  811. pdev->ppdu_info.rx_status.chan_noise_floor =
  812. pdev->chan_noise_floor;
  813. /*
  814. * if chan_num is not fetched correctly from ppdu RX TLV,
  815. * get it from pdev saved.
  816. */
  817. if (pdev->ppdu_info.rx_status.chan_num == 0)
  818. pdev->ppdu_info.rx_status.chan_num = pdev->mon_chan_num;
  819. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status,
  820. mon_mpdu,
  821. qdf_nbuf_headroom(mon_mpdu))) {
  822. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  823. goto mon_deliver_fail;
  824. }
  825. pdev->monitor_vdev->osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  826. mon_mpdu,
  827. &pdev->ppdu_info.rx_status);
  828. } else {
  829. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  830. "[%s][%d] mon_mpdu=%pK monitor_vdev %pK osif_vdev %pK"
  831. , __func__, __LINE__, mon_mpdu, pdev->monitor_vdev,
  832. (pdev->monitor_vdev ? pdev->monitor_vdev->osif_vdev
  833. : NULL));
  834. goto mon_deliver_fail;
  835. }
  836. return QDF_STATUS_SUCCESS;
  837. mon_deliver_fail:
  838. mon_skb = head_msdu;
  839. while (mon_skb) {
  840. skb_next = qdf_nbuf_next(mon_skb);
  841. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  842. "[%s][%d] mon_skb=%pK len %u", __func__,
  843. __LINE__, mon_skb, mon_skb->len);
  844. qdf_nbuf_free(mon_skb);
  845. mon_skb = skb_next;
  846. }
  847. return QDF_STATUS_E_INVAL;
  848. }
  849. /**
  850. * dp_rx_mon_deliver_non_std()
  851. * @soc: core txrx main contex
  852. * @mac_id: MAC ID
  853. *
  854. * This function delivers the radio tap and dummy MSDU
  855. * into user layer application for preamble only PPDU.
  856. *
  857. * Return: QDF_STATUS
  858. */
  859. QDF_STATUS dp_rx_mon_deliver_non_std(struct dp_soc *soc,
  860. uint32_t mac_id)
  861. {
  862. struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  863. ol_txrx_rx_mon_fp osif_rx_mon;
  864. qdf_nbuf_t dummy_msdu;
  865. /* Sanity checking */
  866. if ((!pdev->monitor_vdev) || (!pdev->monitor_vdev->osif_rx_mon))
  867. goto mon_deliver_non_std_fail;
  868. /* Generate a dummy skb_buff */
  869. osif_rx_mon = pdev->monitor_vdev->osif_rx_mon;
  870. dummy_msdu = qdf_nbuf_alloc(soc->osdev, MAX_MONITOR_HEADER,
  871. MAX_MONITOR_HEADER, 4, FALSE);
  872. if (!dummy_msdu)
  873. goto allocate_dummy_msdu_fail;
  874. qdf_nbuf_set_pktlen(dummy_msdu, 0);
  875. qdf_nbuf_set_next(dummy_msdu, NULL);
  876. pdev->ppdu_info.rx_status.ppdu_id =
  877. pdev->ppdu_info.com_info.ppdu_id;
  878. /* Apply the radio header to this dummy skb */
  879. if (!qdf_nbuf_update_radiotap(&pdev->ppdu_info.rx_status, dummy_msdu,
  880. qdf_nbuf_headroom(dummy_msdu))) {
  881. DP_STATS_INC(pdev, dropped.mon_radiotap_update_err, 1);
  882. qdf_nbuf_free(dummy_msdu);
  883. goto mon_deliver_non_std_fail;
  884. }
  885. /* deliver to the user layer application */
  886. osif_rx_mon(pdev->monitor_vdev->osif_vdev,
  887. dummy_msdu, NULL);
  888. /* Clear rx_status*/
  889. qdf_mem_zero(&pdev->ppdu_info.rx_status,
  890. sizeof(pdev->ppdu_info.rx_status));
  891. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  892. return QDF_STATUS_SUCCESS;
  893. allocate_dummy_msdu_fail:
  894. QDF_TRACE_DEBUG_RL(QDF_MODULE_ID_DP, "[%s][%d] mon_skb=%pK ",
  895. __func__, __LINE__, dummy_msdu);
  896. mon_deliver_non_std_fail:
  897. return QDF_STATUS_E_INVAL;
  898. }
  899. /**
  900. * dp_rx_mon_dest_process() - Brain of the Rx processing functionality
  901. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  902. * @soc: core txrx main contex
  903. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  904. * @quota: No. of units (packets) that can be serviced in one shot.
  905. *
  906. * This function implements the core of Rx functionality. This is
  907. * expected to handle only non-error frames.
  908. *
  909. * Return: none
  910. */
  911. void dp_rx_mon_dest_process(struct dp_soc *soc, uint32_t mac_id, uint32_t quota)
  912. {
  913. struct dp_pdev *pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  914. uint8_t pdev_id;
  915. hal_rxdma_desc_t rxdma_dst_ring_desc;
  916. hal_soc_handle_t hal_soc;
  917. void *mon_dst_srng;
  918. union dp_rx_desc_list_elem_t *head = NULL;
  919. union dp_rx_desc_list_elem_t *tail = NULL;
  920. uint32_t ppdu_id;
  921. uint32_t rx_bufs_used;
  922. uint32_t mpdu_rx_bufs_used;
  923. int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
  924. struct cdp_pdev_mon_stats *rx_mon_stats;
  925. mon_dst_srng = dp_rxdma_get_mon_dst_ring(pdev, mac_for_pdev);
  926. if (!mon_dst_srng || !hal_srng_initialized(mon_dst_srng)) {
  927. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  928. "%s %d : HAL Monitor Destination Ring Init Failed -- %pK",
  929. __func__, __LINE__, mon_dst_srng);
  930. return;
  931. }
  932. hal_soc = soc->hal_soc;
  933. qdf_assert((hal_soc && pdev));
  934. qdf_spin_lock_bh(&pdev->mon_lock);
  935. if (qdf_unlikely(hal_srng_access_start(hal_soc, mon_dst_srng))) {
  936. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_ERROR,
  937. "%s %d : HAL Monitor Destination Ring access Failed -- %pK",
  938. __func__, __LINE__, mon_dst_srng);
  939. return;
  940. }
  941. pdev_id = pdev->pdev_id;
  942. ppdu_id = pdev->ppdu_info.com_info.ppdu_id;
  943. rx_bufs_used = 0;
  944. rx_mon_stats = &pdev->rx_mon_stats;
  945. while (qdf_likely(rxdma_dst_ring_desc =
  946. hal_srng_dst_peek(hal_soc, mon_dst_srng))) {
  947. qdf_nbuf_t head_msdu, tail_msdu;
  948. uint32_t npackets;
  949. head_msdu = (qdf_nbuf_t) NULL;
  950. tail_msdu = (qdf_nbuf_t) NULL;
  951. mpdu_rx_bufs_used =
  952. dp_rx_mon_mpdu_pop(soc, mac_id,
  953. rxdma_dst_ring_desc,
  954. &head_msdu, &tail_msdu,
  955. &npackets, &ppdu_id,
  956. &head, &tail);
  957. rx_bufs_used += mpdu_rx_bufs_used;
  958. if (mpdu_rx_bufs_used)
  959. pdev->mon_dest_ring_stuck_cnt = 0;
  960. else
  961. pdev->mon_dest_ring_stuck_cnt++;
  962. if (pdev->mon_dest_ring_stuck_cnt >
  963. MON_DEST_RING_STUCK_MAX_CNT) {
  964. dp_err("destination ring stuck");
  965. dp_err("ppdu_id status=%d dest=%d",
  966. pdev->ppdu_info.com_info.ppdu_id, ppdu_id);
  967. rx_mon_stats->mon_rx_dest_stuck++;
  968. pdev->ppdu_info.com_info.ppdu_id = ppdu_id;
  969. continue;
  970. }
  971. if (ppdu_id != pdev->ppdu_info.com_info.ppdu_id) {
  972. rx_mon_stats->stat_ring_ppdu_id_hist[
  973. rx_mon_stats->ppdu_id_hist_idx] =
  974. pdev->ppdu_info.com_info.ppdu_id;
  975. rx_mon_stats->dest_ring_ppdu_id_hist[
  976. rx_mon_stats->ppdu_id_hist_idx] = ppdu_id;
  977. rx_mon_stats->ppdu_id_hist_idx =
  978. (rx_mon_stats->ppdu_id_hist_idx + 1) &
  979. (MAX_PPDU_ID_HIST - 1);
  980. pdev->mon_ppdu_status = DP_PPDU_STATUS_START;
  981. qdf_mem_zero(&(pdev->ppdu_info.rx_status),
  982. sizeof(pdev->ppdu_info.rx_status));
  983. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_DEBUG,
  984. "%s %d ppdu_id %x != ppdu_info.com_info .ppdu_id %x",
  985. __func__, __LINE__,
  986. ppdu_id, pdev->ppdu_info.com_info.ppdu_id);
  987. break;
  988. }
  989. if (qdf_likely((head_msdu) && (tail_msdu))) {
  990. rx_mon_stats->dest_mpdu_done++;
  991. dp_rx_mon_deliver(soc, mac_id, head_msdu, tail_msdu);
  992. }
  993. rxdma_dst_ring_desc = hal_srng_dst_get_next(hal_soc,
  994. mon_dst_srng);
  995. }
  996. hal_srng_access_end(hal_soc, mon_dst_srng);
  997. qdf_spin_unlock_bh(&pdev->mon_lock);
  998. if (rx_bufs_used) {
  999. rx_mon_stats->dest_ppdu_done++;
  1000. dp_rx_buffers_replenish(soc, mac_id,
  1001. dp_rxdma_get_mon_buf_ring(pdev,
  1002. mac_for_pdev),
  1003. dp_rx_get_mon_desc_pool(soc, mac_id,
  1004. pdev_id),
  1005. rx_bufs_used, &head, &tail);
  1006. }
  1007. }
  1008. #ifndef DISABLE_MON_CONFIG
  1009. #if !defined(QCA_WIFI_QCA6390) && !defined(QCA_WIFI_QCA6490)
  1010. /**
  1011. * dp_rx_pdev_mon_buf_attach() - Allocate the monitor descriptor pool
  1012. *
  1013. * @pdev: physical device handle
  1014. * @mac_id: mac id
  1015. *
  1016. * Return: QDF_STATUS
  1017. */
  1018. #define MON_BUF_MIN_ALLOC_ENTRIES 128
  1019. static QDF_STATUS
  1020. dp_rx_pdev_mon_buf_attach(struct dp_pdev *pdev, int mac_id) {
  1021. uint8_t pdev_id = pdev->pdev_id;
  1022. struct dp_soc *soc = pdev->soc;
  1023. struct dp_srng *mon_buf_ring;
  1024. uint32_t num_entries;
  1025. struct rx_desc_pool *rx_desc_pool;
  1026. QDF_STATUS status = QDF_STATUS_SUCCESS;
  1027. uint8_t mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
  1028. uint32_t rx_desc_pool_size, replenish_size;
  1029. mon_buf_ring = &pdev->rxdma_mon_buf_ring[mac_for_pdev];
  1030. num_entries = mon_buf_ring->num_entries;
  1031. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1032. dp_debug("Mon RX Desc Pool[%d] entries=%u",
  1033. pdev_id, num_entries);
  1034. rx_desc_pool_size = wlan_cfg_get_dp_soc_rx_sw_desc_weight(soc->wlan_cfg_ctx) * num_entries;
  1035. status = dp_rx_desc_pool_alloc(soc, mac_id, rx_desc_pool_size,
  1036. rx_desc_pool);
  1037. if (!QDF_IS_STATUS_SUCCESS(status))
  1038. return status;
  1039. rx_desc_pool->owner = HAL_RX_BUF_RBM_SW3_BM;
  1040. replenish_size = ((num_entries - 1) < MON_BUF_MIN_ALLOC_ENTRIES) ?
  1041. (num_entries - 1) : MON_BUF_MIN_ALLOC_ENTRIES;
  1042. status = dp_pdev_rx_buffers_attach(soc, mac_id, mon_buf_ring,
  1043. rx_desc_pool, replenish_size);
  1044. return status;
  1045. }
  1046. static QDF_STATUS
  1047. dp_rx_pdev_mon_buf_detach(struct dp_pdev *pdev, int mac_id)
  1048. {
  1049. struct dp_soc *soc = pdev->soc;
  1050. struct rx_desc_pool *rx_desc_pool;
  1051. rx_desc_pool = &soc->rx_desc_mon[mac_id];
  1052. if (rx_desc_pool->pool_size != 0) {
  1053. if (!dp_is_soc_reinit(soc))
  1054. dp_rx_desc_nbuf_and_pool_free(soc, mac_id,
  1055. rx_desc_pool);
  1056. else
  1057. dp_rx_desc_nbuf_free(soc, rx_desc_pool);
  1058. }
  1059. return QDF_STATUS_SUCCESS;
  1060. }
  1061. /**
  1062. * dp_mon_link_desc_pool_setup(): Allocate and setup link descriptor pool
  1063. * that will be used by HW for various link
  1064. * and queue descriptorsand managed by WBM
  1065. *
  1066. * @soc: soc handle
  1067. * @mac_id: mac id
  1068. *
  1069. * Return: QDF_STATUS
  1070. */
  1071. static
  1072. QDF_STATUS dp_mon_link_desc_pool_setup(struct dp_soc *soc, uint32_t mac_id)
  1073. {
  1074. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  1075. int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
  1076. int link_desc_size = hal_get_link_desc_size(soc->hal_soc);
  1077. int link_desc_align = hal_get_link_desc_align(soc->hal_soc);
  1078. uint32_t max_alloc_size = wlan_cfg_max_alloc_size(soc->wlan_cfg_ctx);
  1079. uint32_t total_link_descs, total_mem_size;
  1080. uint32_t num_link_desc_banks;
  1081. uint32_t last_bank_size = 0;
  1082. uint32_t entry_size, num_entries;
  1083. void *mon_desc_srng;
  1084. uint32_t num_replenish_buf;
  1085. struct dp_srng *dp_srng;
  1086. int i;
  1087. qdf_dma_addr_t *baseaddr = NULL;
  1088. dp_srng = &dp_pdev->rxdma_mon_desc_ring[mac_for_pdev];
  1089. num_entries = dp_srng->alloc_size/hal_srng_get_entrysize(
  1090. soc->hal_soc, RXDMA_MONITOR_DESC);
  1091. /* Round up to power of 2 */
  1092. total_link_descs = 1;
  1093. while (total_link_descs < num_entries)
  1094. total_link_descs <<= 1;
  1095. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_INFO_HIGH,
  1096. "%s: total_link_descs: %u, link_desc_size: %d",
  1097. __func__, total_link_descs, link_desc_size);
  1098. total_mem_size = total_link_descs * link_desc_size;
  1099. total_mem_size += link_desc_align;
  1100. if (total_mem_size <= max_alloc_size) {
  1101. num_link_desc_banks = 0;
  1102. last_bank_size = total_mem_size;
  1103. } else {
  1104. num_link_desc_banks = (total_mem_size) /
  1105. (max_alloc_size - link_desc_align);
  1106. last_bank_size = total_mem_size %
  1107. (max_alloc_size - link_desc_align);
  1108. }
  1109. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  1110. "%s: total_mem_size: %d, num_link_desc_banks: %u",
  1111. __func__, total_mem_size, num_link_desc_banks);
  1112. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  1113. "%s: max_alloc_size: %d last_bank_size: %d",
  1114. __func__, max_alloc_size, last_bank_size);
  1115. for (i = 0; i < num_link_desc_banks; i++) {
  1116. baseaddr = &dp_pdev->link_desc_banks[mac_for_pdev][i].
  1117. base_paddr_unaligned;
  1118. if (!dp_is_soc_reinit(soc)) {
  1119. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1120. base_vaddr_unaligned =
  1121. qdf_mem_alloc_consistent(soc->osdev,
  1122. soc->osdev->dev,
  1123. max_alloc_size,
  1124. baseaddr);
  1125. if (!dp_pdev->link_desc_banks[mac_for_pdev][i].
  1126. base_vaddr_unaligned) {
  1127. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1128. QDF_TRACE_LEVEL_ERROR,
  1129. "%s: Link desc mem alloc failed",
  1130. __func__);
  1131. goto fail;
  1132. }
  1133. }
  1134. dp_pdev->link_desc_banks[mac_for_pdev][i].size = max_alloc_size;
  1135. dp_pdev->link_desc_banks[mac_for_pdev][i].base_vaddr =
  1136. (void *)((unsigned long)
  1137. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1138. base_vaddr_unaligned) +
  1139. ((unsigned long)
  1140. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1141. base_vaddr_unaligned) %
  1142. link_desc_align));
  1143. dp_pdev->link_desc_banks[mac_for_pdev][i].base_paddr =
  1144. (unsigned long)
  1145. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1146. base_paddr_unaligned) +
  1147. ((unsigned long)
  1148. (dp_pdev->link_desc_banks[mac_for_pdev][i].base_vaddr) -
  1149. (unsigned long)
  1150. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1151. base_vaddr_unaligned));
  1152. }
  1153. if (last_bank_size) {
  1154. /* Allocate last bank in case total memory required is not exact
  1155. * multiple of max_alloc_size
  1156. */
  1157. baseaddr = &dp_pdev->link_desc_banks[mac_for_pdev][i].
  1158. base_paddr_unaligned;
  1159. if (!dp_is_soc_reinit(soc)) {
  1160. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1161. base_vaddr_unaligned =
  1162. qdf_mem_alloc_consistent(soc->osdev,
  1163. soc->osdev->dev,
  1164. last_bank_size,
  1165. baseaddr);
  1166. if (!dp_pdev->link_desc_banks[mac_for_pdev][i].
  1167. base_vaddr_unaligned) {
  1168. QDF_TRACE(QDF_MODULE_ID_TXRX,
  1169. QDF_TRACE_LEVEL_ERROR,
  1170. "%s: alloc fail:mon link desc pool",
  1171. __func__);
  1172. goto fail;
  1173. }
  1174. }
  1175. dp_pdev->link_desc_banks[mac_for_pdev][i].size = last_bank_size;
  1176. dp_pdev->link_desc_banks[mac_for_pdev][i].base_vaddr =
  1177. (void *)((unsigned long)
  1178. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1179. base_vaddr_unaligned) +
  1180. ((unsigned long)
  1181. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1182. base_vaddr_unaligned) %
  1183. link_desc_align));
  1184. dp_pdev->link_desc_banks[mac_for_pdev][i].base_paddr =
  1185. (unsigned long)
  1186. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1187. base_paddr_unaligned) +
  1188. ((unsigned long)
  1189. (dp_pdev->link_desc_banks[mac_for_pdev][i].base_vaddr) -
  1190. (unsigned long)
  1191. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1192. base_vaddr_unaligned));
  1193. }
  1194. /* Allocate and setup link descriptor idle list for HW internal use */
  1195. entry_size = hal_srng_get_entrysize(soc->hal_soc, RXDMA_MONITOR_DESC);
  1196. total_mem_size = entry_size * total_link_descs;
  1197. mon_desc_srng = dp_pdev->rxdma_mon_desc_ring[mac_for_pdev].hal_srng;
  1198. num_replenish_buf = 0;
  1199. if (total_mem_size <= max_alloc_size) {
  1200. void *desc;
  1201. for (i = 0;
  1202. i < MAX_MON_LINK_DESC_BANKS &&
  1203. dp_pdev->link_desc_banks[mac_for_pdev][i].base_paddr;
  1204. i++) {
  1205. uint32_t num_entries =
  1206. (dp_pdev->link_desc_banks[mac_for_pdev][i].size -
  1207. (unsigned long)
  1208. (dp_pdev->link_desc_banks[mac_for_pdev][i].base_vaddr) -
  1209. (unsigned long)
  1210. (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1211. base_vaddr_unaligned)) / link_desc_size;
  1212. unsigned long paddr =
  1213. (unsigned long)
  1214. (dp_pdev->link_desc_banks[mac_for_pdev][i].base_paddr);
  1215. unsigned long vaddr =
  1216. (unsigned long)
  1217. (dp_pdev->link_desc_banks[mac_for_pdev][i].base_vaddr);
  1218. hal_srng_access_start_unlocked(soc->hal_soc,
  1219. mon_desc_srng);
  1220. while (num_entries && (desc =
  1221. hal_srng_src_get_next(soc->hal_soc,
  1222. mon_desc_srng))) {
  1223. hal_set_link_desc_addr(desc, i, paddr);
  1224. num_entries--;
  1225. num_replenish_buf++;
  1226. paddr += link_desc_size;
  1227. vaddr += link_desc_size;
  1228. }
  1229. hal_srng_access_end_unlocked(soc->hal_soc,
  1230. mon_desc_srng);
  1231. }
  1232. } else {
  1233. qdf_assert(0);
  1234. }
  1235. QDF_TRACE(QDF_MODULE_ID_TXRX, QDF_TRACE_LEVEL_WARN,
  1236. "%s: successfully replenished %d buffer",
  1237. __func__, num_replenish_buf);
  1238. return QDF_STATUS_SUCCESS;
  1239. fail:
  1240. for (i = 0; i < MAX_MON_LINK_DESC_BANKS; i++) {
  1241. if (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1242. base_vaddr_unaligned) {
  1243. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  1244. dp_pdev->link_desc_banks[mac_for_pdev][i].size,
  1245. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1246. base_vaddr_unaligned,
  1247. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1248. base_paddr_unaligned, 0);
  1249. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1250. base_vaddr_unaligned = NULL;
  1251. }
  1252. }
  1253. return QDF_STATUS_E_FAILURE;
  1254. }
  1255. /*
  1256. * Free link descriptor pool that was setup HW
  1257. */
  1258. static
  1259. void dp_mon_link_desc_pool_cleanup(struct dp_soc *soc, uint32_t mac_id)
  1260. {
  1261. struct dp_pdev *dp_pdev = dp_get_pdev_for_mac_id(soc, mac_id);
  1262. int mac_for_pdev = dp_get_mac_id_for_mac(soc, mac_id);
  1263. int i;
  1264. for (i = 0; i < MAX_MON_LINK_DESC_BANKS; i++) {
  1265. if (dp_pdev->link_desc_banks[mac_for_pdev][i].
  1266. base_vaddr_unaligned) {
  1267. qdf_mem_free_consistent(soc->osdev, soc->osdev->dev,
  1268. dp_pdev->link_desc_banks[mac_for_pdev][i].size,
  1269. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1270. base_vaddr_unaligned,
  1271. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1272. base_paddr_unaligned, 0);
  1273. dp_pdev->link_desc_banks[mac_for_pdev][i].
  1274. base_vaddr_unaligned = NULL;
  1275. }
  1276. }
  1277. }
  1278. /**
  1279. * dp_mon_buf_delayed_replenish() - Helper routine to replenish monitor dest buf
  1280. * @pdev: DP pdev object
  1281. *
  1282. * Return: None
  1283. */
  1284. void dp_mon_buf_delayed_replenish(struct dp_pdev *pdev)
  1285. {
  1286. struct dp_soc *soc;
  1287. uint32_t mac_for_pdev;
  1288. union dp_rx_desc_list_elem_t *tail = NULL;
  1289. union dp_rx_desc_list_elem_t *desc_list = NULL;
  1290. uint32_t num_entries;
  1291. uint32_t mac_id, id;
  1292. soc = pdev->soc;
  1293. num_entries = wlan_cfg_get_dma_mon_buf_ring_size(pdev->wlan_cfg_ctx);
  1294. for (id = 0; id < NUM_RXDMA_RINGS_PER_PDEV; id++) {
  1295. mac_for_pdev = dp_get_mac_id_for_pdev(id,
  1296. pdev->pdev_id);
  1297. /*
  1298. * Map mac_for_pdev appropriately for both MCL & WIN,
  1299. * since MCL have multiple mon buf rings and WIN just
  1300. * has one mon buffer ring, below API helps identify
  1301. * accurate buffer_ring for both cases
  1302. *
  1303. */
  1304. mac_id = dp_get_mac_id_for_mac(soc, mac_for_pdev);
  1305. dp_rx_buffers_replenish(soc, mac_for_pdev,
  1306. dp_rxdma_get_mon_buf_ring(pdev,
  1307. mac_id),
  1308. dp_rx_get_mon_desc_pool(soc,
  1309. mac_for_pdev,
  1310. pdev->pdev_id),
  1311. num_entries, &desc_list, &tail);
  1312. }
  1313. }
  1314. #else
  1315. static
  1316. QDF_STATUS dp_mon_link_desc_pool_setup(struct dp_soc *soc, uint32_t mac_id)
  1317. {
  1318. return QDF_STATUS_SUCCESS;
  1319. }
  1320. static QDF_STATUS
  1321. dp_rx_pdev_mon_buf_attach(struct dp_pdev *pdev, int mac_id)
  1322. {
  1323. return QDF_STATUS_SUCCESS;
  1324. }
  1325. static
  1326. void dp_mon_link_desc_pool_cleanup(struct dp_soc *soc, uint32_t mac_id)
  1327. {
  1328. }
  1329. static QDF_STATUS
  1330. dp_rx_pdev_mon_buf_detach(struct dp_pdev *pdev, int mac_id)
  1331. {
  1332. return QDF_STATUS_SUCCESS;
  1333. }
  1334. void dp_mon_buf_delayed_replenish(struct dp_pdev *pdev)
  1335. {}
  1336. #endif
  1337. /**
  1338. * dp_rx_pdev_mon_cmn_detach() - detach dp rx for monitor mode
  1339. * @pdev: core txrx pdev context
  1340. * @mac_id: mac_id for which deinit is to be done
  1341. *
  1342. * This function will free DP Rx resources for
  1343. * monitor mode
  1344. *
  1345. * Return: QDF_STATUS_SUCCESS: success
  1346. * QDF_STATUS_E_RESOURCES: Error return
  1347. */
  1348. static QDF_STATUS
  1349. dp_rx_pdev_mon_cmn_detach(struct dp_pdev *pdev, int mac_id) {
  1350. struct dp_soc *soc = pdev->soc;
  1351. uint8_t pdev_id = pdev->pdev_id;
  1352. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  1353. dp_mon_link_desc_pool_cleanup(soc, mac_for_pdev);
  1354. dp_rx_pdev_mon_status_detach(pdev, mac_for_pdev);
  1355. dp_rx_pdev_mon_buf_detach(pdev, mac_for_pdev);
  1356. return QDF_STATUS_SUCCESS;
  1357. }
  1358. /**
  1359. * dp_rx_pdev_mon_cmn_attach() - attach DP RX for monitor mode
  1360. * @pdev: core txrx pdev context
  1361. * @mac_id: mac_id for which init is to be done
  1362. *
  1363. * This function Will allocate dp rx resource and
  1364. * initialize resources for monitor mode.
  1365. *
  1366. * Return: QDF_STATUS_SUCCESS: success
  1367. * QDF_STATUS_E_RESOURCES: Error return
  1368. */
  1369. static QDF_STATUS
  1370. dp_rx_pdev_mon_cmn_attach(struct dp_pdev *pdev, int mac_id) {
  1371. struct dp_soc *soc = pdev->soc;
  1372. uint8_t pdev_id = pdev->pdev_id;
  1373. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  1374. QDF_STATUS status;
  1375. status = dp_rx_pdev_mon_buf_attach(pdev, mac_for_pdev);
  1376. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1377. dp_err("%s: dp_rx_pdev_mon_buf_attach() failed\n", __func__);
  1378. goto fail;
  1379. }
  1380. status = dp_rx_pdev_mon_status_attach(pdev, mac_for_pdev);
  1381. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1382. dp_err("%s: dp_rx_pdev_mon_status_attach() failed", __func__);
  1383. goto mon_buf_detach;
  1384. }
  1385. status = dp_mon_link_desc_pool_setup(soc, mac_for_pdev);
  1386. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1387. dp_err("%s: dp_mon_link_desc_pool_setup() failed", __func__);
  1388. goto mon_status_detach;
  1389. }
  1390. return status;
  1391. mon_status_detach:
  1392. dp_rx_pdev_mon_status_detach(pdev, mac_for_pdev);
  1393. mon_buf_detach:
  1394. dp_rx_pdev_mon_buf_detach(pdev, mac_for_pdev);
  1395. fail:
  1396. return status;
  1397. }
  1398. /**
  1399. * dp_rx_pdev_mon_attach() - attach DP RX for monitor mode
  1400. * @pdev: core txrx pdev context
  1401. *
  1402. * This function will attach a DP RX for monitor mode instance into
  1403. * the main device (SOC) context. Will allocate dp rx resource and
  1404. * initialize resources.
  1405. *
  1406. * Return: QDF_STATUS_SUCCESS: success
  1407. * QDF_STATUS_E_RESOURCES: Error return
  1408. */
  1409. QDF_STATUS
  1410. dp_rx_pdev_mon_attach(struct dp_pdev *pdev) {
  1411. QDF_STATUS status;
  1412. uint8_t pdev_id = pdev->pdev_id;
  1413. int mac_id;
  1414. QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_WARN,
  1415. "%s: pdev attach id=%d", __func__, pdev_id);
  1416. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1417. status = dp_rx_pdev_mon_cmn_attach(pdev, mac_id);
  1418. if (!QDF_IS_STATUS_SUCCESS(status)) {
  1419. QDF_TRACE(QDF_MODULE_ID_DP,
  1420. QDF_TRACE_LEVEL_ERROR,
  1421. "%s: dp_rx_pdev_mon_cmn_attach(%d) failed\n",
  1422. __func__, mac_id);
  1423. goto fail;
  1424. }
  1425. }
  1426. pdev->mon_last_linkdesc_paddr = 0;
  1427. pdev->mon_last_buf_cookie = DP_RX_DESC_COOKIE_MAX + 1;
  1428. qdf_spinlock_create(&pdev->mon_lock);
  1429. return QDF_STATUS_SUCCESS;
  1430. fail:
  1431. for (mac_id = mac_id - 1; mac_id >= 0; mac_id--)
  1432. dp_rx_pdev_mon_cmn_detach(pdev, mac_id);
  1433. return status;
  1434. }
  1435. QDF_STATUS
  1436. dp_mon_link_free(struct dp_pdev *pdev) {
  1437. uint8_t pdev_id = pdev->pdev_id;
  1438. struct dp_soc *soc = pdev->soc;
  1439. int mac_id;
  1440. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1441. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  1442. dp_mon_link_desc_pool_cleanup(soc, mac_for_pdev);
  1443. }
  1444. return QDF_STATUS_SUCCESS;
  1445. }
  1446. /**
  1447. * dp_rx_pdev_mon_detach() - detach dp rx for monitor mode
  1448. * @pdev: core txrx pdev context
  1449. *
  1450. * This function will detach DP RX for monitor mode from
  1451. * main device context. will free DP Rx resources for
  1452. * monitor mode
  1453. *
  1454. * Return: QDF_STATUS_SUCCESS: success
  1455. * QDF_STATUS_E_RESOURCES: Error return
  1456. */
  1457. QDF_STATUS
  1458. dp_rx_pdev_mon_detach(struct dp_pdev *pdev) {
  1459. uint8_t pdev_id = pdev->pdev_id;
  1460. int mac_id;
  1461. qdf_spinlock_destroy(&pdev->mon_lock);
  1462. for (mac_id = 0; mac_id < NUM_RXDMA_RINGS_PER_PDEV; mac_id++) {
  1463. int mac_for_pdev = dp_get_mac_id_for_pdev(mac_id, pdev_id);
  1464. dp_rx_pdev_mon_status_detach(pdev, mac_for_pdev);
  1465. dp_rx_pdev_mon_buf_detach(pdev, mac_for_pdev);
  1466. }
  1467. return QDF_STATUS_SUCCESS;
  1468. }
  1469. #else
  1470. QDF_STATUS
  1471. dp_rx_pdev_mon_attach(struct dp_pdev *pdev) {
  1472. return QDF_STATUS_SUCCESS;
  1473. }
  1474. QDF_STATUS
  1475. dp_rx_pdev_mon_detach(struct dp_pdev *pdev) {
  1476. return QDF_STATUS_SUCCESS;
  1477. }
  1478. QDF_STATUS
  1479. dp_mon_link_free(struct dp_pdev *pdev) {
  1480. return QDF_STATUS_SUCCESS;
  1481. }
  1482. void dp_mon_buf_delayed_replenish(struct dp_pdev *pdev)
  1483. {}
  1484. #endif /* DISABLE_MON_CONFIG */