dp_rx_mon.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. /*
  2. * Copyright (c) 2016-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. #ifndef _DP_RX_MON_H_
  19. #define _DP_RX_MON_H_
  20. /*
  21. * MON_BUF_MIN_ENTRIES macro defines minimum number of network buffers
  22. * to be refilled in the RXDMA monitor buffer ring at init, remaining
  23. * buffers are replenished at the time of monitor vap creation
  24. */
  25. #define MON_BUF_MIN_ENTRIES 64
  26. /*
  27. * The maximum headroom reserved for monitor destination buffer to
  28. * accomodate radiotap header and protocol flow tag
  29. */
  30. #ifdef DP_RX_MON_MEM_FRAG
  31. /*
  32. *----------------------------------
  33. *| Reserve | PF Tag | Radiotap hdr|
  34. *| 64B | 64B | 128B |
  35. *----------------------------------
  36. * Reserved 64B is used to fill Protocol & Flow tag before writing into
  37. * actual offset, data gets written to actual offset after updating
  38. * radiotap HDR.
  39. */
  40. #define DP_RX_MON_MAX_MONITOR_HEADER (256)
  41. #else
  42. #define DP_RX_MON_MAX_MONITOR_HEADER (512)
  43. #endif
  44. /* The maximum buffer length allocated for radiotap for monitor status buffer */
  45. #define MAX_MONITOR_HEADER (512)
  46. /* l2 header pad byte in case of Raw frame is Zero and 2 in non raw */
  47. #define DP_RX_MON_RAW_L2_HDR_PAD_BYTE (0)
  48. #define DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE (2)
  49. /**
  50. * enum dp_mon_reap_status - monitor status ring ppdu status
  51. *
  52. * @DP_MON_STATUS_NO_DMA - DMA not done for status ring entry
  53. * @DP_MON_STATUS_MATCH - status and dest ppdu id mathes
  54. * @DP_MON_STATUS_LAG - status ppdu id is lagging
  55. * @DP_MON_STATUS_LEAD - status ppdu id is leading
  56. * @DP_MON_STATUS_REPLENISH - status ring entry is NULL
  57. */
  58. enum dp_mon_reap_status {
  59. DP_MON_STATUS_NO_DMA,
  60. DP_MON_STATUS_MATCH,
  61. DP_MON_STATUS_LAG,
  62. DP_MON_STATUS_LEAD,
  63. DP_MON_STATUS_REPLENISH
  64. };
  65. /*
  66. * dp_rx_mon_status_process() - Process monitor status ring and
  67. * TLV in status ring.
  68. *
  69. * @soc: core txrx main context
  70. * @int_ctx: interrupt context
  71. * @mac_id: mac_id which is one of 3 mac_ids
  72. * @quota: No. of ring entry that can be serviced in one shot.
  73. * Return: uint32_t: No. of ring entry that is processed.
  74. */
  75. uint32_t
  76. dp_rx_mon_status_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  77. uint32_t mac_id, uint32_t quota);
  78. /**
  79. * dp_rx_mon_dest_process() - Brain of the Rx processing functionality
  80. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  81. * @soc: core txrx main contex
  82. * @int_ctx: interrupt context
  83. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  84. * @quota: No. of units (packets) that can be serviced in one shot.
  85. *
  86. * This function implements the core of Rx functionality. This is
  87. * expected to handle only non-error frames.
  88. *
  89. * Return: none
  90. */
  91. void dp_rx_mon_dest_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  92. uint32_t mac_id, uint32_t quota);
  93. QDF_STATUS dp_rx_pdev_mon_desc_pool_alloc(struct dp_pdev *pdev);
  94. QDF_STATUS dp_rx_pdev_mon_buffers_alloc(struct dp_pdev *pdev);
  95. void dp_rx_pdev_mon_buffers_free(struct dp_pdev *pdev);
  96. void dp_rx_pdev_mon_desc_pool_init(struct dp_pdev *pdev);
  97. void dp_rx_pdev_mon_desc_pool_deinit(struct dp_pdev *pdev);
  98. void dp_rx_pdev_mon_desc_pool_free(struct dp_pdev *pdev);
  99. void dp_rx_pdev_mon_buf_buffers_free(struct dp_pdev *pdev, uint32_t mac_id);
  100. QDF_STATUS dp_rx_pdev_mon_status_buffers_alloc(struct dp_pdev *pdev,
  101. uint32_t mac_id);
  102. QDF_STATUS dp_rx_pdev_mon_status_desc_pool_alloc(struct dp_pdev *pdev,
  103. uint32_t mac_id);
  104. void dp_rx_pdev_mon_status_desc_pool_init(struct dp_pdev *pdev,
  105. uint32_t mac_id);
  106. void dp_rx_pdev_mon_status_desc_pool_deinit(struct dp_pdev *pdev,
  107. uint32_t mac_id);
  108. void dp_rx_pdev_mon_status_desc_pool_free(struct dp_pdev *pdev,
  109. uint32_t mac_id);
  110. void dp_rx_pdev_mon_status_buffers_free(struct dp_pdev *pdev, uint32_t mac_id);
  111. QDF_STATUS
  112. dp_rx_pdev_mon_buf_buffers_alloc(struct dp_pdev *pdev, uint32_t mac_id,
  113. bool delayed_replenish);
  114. /**
  115. * dp_rx_mon_handle_status_buf_done () - Handle DMA not done case for
  116. * monitor status ring
  117. *
  118. * @pdev: DP pdev handle
  119. * @mon_status_srng: Monitor status SRNG
  120. *
  121. * Return: enum dp_mon_reap_status
  122. */
  123. enum dp_mon_reap_status
  124. dp_rx_mon_handle_status_buf_done(struct dp_pdev *pdev,
  125. void *mon_status_srng);
  126. #ifdef QCA_SUPPORT_FULL_MON
  127. /**
  128. * dp_full_mon_attach() - Full monitor mode attach
  129. * This API initilises full monitor mode resources
  130. *
  131. * @pdev: dp pdev object
  132. *
  133. * Return: void
  134. *
  135. */
  136. void dp_full_mon_attach(struct dp_pdev *pdev);
  137. /**
  138. * dp_full_mon_detach() - Full monitor mode attach
  139. * This API deinitilises full monitor mode resources
  140. *
  141. * @pdev: dp pdev object
  142. *
  143. * Return: void
  144. *
  145. */
  146. void dp_full_mon_detach(struct dp_pdev *pdev);
  147. /**
  148. * dp_rx_mon_process ()- API to process monitor destination ring for
  149. * full monitor mode
  150. *
  151. * @soc: dp soc handle
  152. * @int_ctx: interrupt context
  153. * @mac_id: lmac id
  154. * @quota: No. of ring entry that can be serviced in one shot.
  155. */
  156. uint32_t dp_rx_mon_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  157. uint32_t mac_id, uint32_t quota);
  158. #else
  159. /**
  160. * dp_full_mon_attach() - attach full monitor mode resources
  161. * @pdev: Datapath PDEV handle
  162. *
  163. * Return: void
  164. */
  165. static inline void dp_full_mon_attach(struct dp_pdev *pdev)
  166. {
  167. }
  168. /**
  169. * dp_full_mon_detach() - detach full monitor mode resources
  170. * @pdev: Datapath PDEV handle
  171. *
  172. * Return: void
  173. *
  174. */
  175. static inline void dp_full_mon_detach(struct dp_pdev *pdev)
  176. {
  177. }
  178. #endif
  179. /**
  180. * dp_reset_monitor_mode() - Disable monitor mode
  181. * @pdev_handle: Datapath PDEV handle
  182. *
  183. * Return: QDF_STATUS
  184. */
  185. QDF_STATUS dp_reset_monitor_mode(struct cdp_soc_t *soc_hdl,
  186. uint8_t pdev_id,
  187. uint8_t smart_monitor);
  188. /**
  189. * dp_mon_link_free() - free monitor link desc pool
  190. * @pdev: core txrx pdev context
  191. *
  192. * This function will release DP link desc pool for monitor mode from
  193. * main device context.
  194. *
  195. * Return: QDF_STATUS_SUCCESS: success
  196. * QDF_STATUS_E_RESOURCES: Error return
  197. */
  198. QDF_STATUS dp_mon_link_free(struct dp_pdev *pdev);
  199. /**
  200. * dp_mon_process() - Main monitor mode processing roution.
  201. * @soc: core txrx main context
  202. * @int_ctx: interrupt context
  203. * @mac_id: mac_id which is one of 3 mac_ids
  204. * @quota: No. of status ring entry that can be serviced in one shot.
  205. *
  206. * This call monitor status ring process then monitor
  207. * destination ring process.
  208. * Called from the bottom half (tasklet/NET_RX_SOFTIRQ)
  209. *
  210. * Return: uint32_t: No. of ring entry that is processed.
  211. */
  212. uint32_t dp_mon_process(struct dp_soc *soc, struct dp_intr *int_ctx,
  213. uint32_t mac_id, uint32_t quota);
  214. QDF_STATUS dp_rx_mon_deliver(struct dp_soc *soc, uint32_t mac_id,
  215. qdf_nbuf_t head_msdu, qdf_nbuf_t tail_msdu);
  216. /*
  217. * dp_rx_mon_deliver_non_std() - deliver frames for non standard path
  218. * @soc: core txrx main contex
  219. * @mac_id: MAC ID
  220. *
  221. * This function delivers the radio tap and dummy MSDU
  222. * into user layer application for preamble only PPDU.
  223. *
  224. * Return: Operation status
  225. */
  226. QDF_STATUS dp_rx_mon_deliver_non_std(struct dp_soc *soc, uint32_t mac_id);
  227. /**
  228. * dp_rxdma_err_process() - RxDMA error processing functionality
  229. * @soc: core txrx main contex
  230. * @mac_id: mac id which is one of 3 mac_ids
  231. * @hal_ring: opaque pointer to the HAL Rx Ring, which will be serviced
  232. * @quota: No. of units (packets) that can be serviced in one shot.
  233. *
  234. * Return: num of buffers processed
  235. */
  236. uint32_t dp_rxdma_err_process(struct dp_intr *int_ctx, struct dp_soc *soc,
  237. uint32_t mac_id, uint32_t quota);
  238. /**
  239. * dp_mon_buf_delayed_replenish() - Helper routine to replenish monitor dest buf
  240. * @pdev: DP pdev object
  241. *
  242. * Return: None
  243. */
  244. void dp_mon_buf_delayed_replenish(struct dp_pdev *pdev);
  245. /**
  246. * dp_rx_mon_link_desc_return() - Return a MPDU link descriptor to HW
  247. * (WBM), following error handling
  248. *
  249. * @dp_pdev: core txrx pdev context
  250. * @buf_addr_info: void pointer to monitor link descriptor buf addr info
  251. * Return: QDF_STATUS
  252. */
  253. QDF_STATUS
  254. dp_rx_mon_link_desc_return(struct dp_pdev *dp_pdev,
  255. hal_buff_addrinfo_t buf_addr_info,
  256. int mac_id);
  257. /**
  258. * dp_mon_adjust_frag_len() - MPDU and MSDU may spread across
  259. * multiple nbufs. This function
  260. * is to return data length in
  261. * fragmented buffer
  262. *
  263. * @total_len: pointer to remaining data length.
  264. * @frag_len: pointer to data length in this fragment.
  265. * @l2_hdr_pad: l2 header padding
  266. */
  267. static inline void dp_mon_adjust_frag_len(uint32_t *total_len,
  268. uint32_t *frag_len,
  269. uint16_t l2_hdr_pad)
  270. {
  271. if (*total_len >= (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN)) {
  272. *frag_len = RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN -
  273. l2_hdr_pad;
  274. *total_len -= *frag_len;
  275. } else {
  276. *frag_len = *total_len;
  277. *total_len = 0;
  278. }
  279. }
  280. /**
  281. * dp_rx_mon_frag_adjust_frag_len() - MPDU and MSDU may spread across
  282. * multiple nbufs. This function is to return data length in
  283. * fragmented buffer.
  284. * It takes input as max_limit for any buffer(as it changes based
  285. * on decap type and buffer sequence in MSDU.
  286. *
  287. * If MSDU is divided into multiple buffer then below format will
  288. * be max limit.
  289. * Decap type Non-Raw
  290. *--------------------------------
  291. *| 1st | 2nd | ... | Last |
  292. *| 1662 | 1664 | 1664 | <=1664 |
  293. *--------------------------------
  294. * Decap type Raw
  295. *--------------------------------
  296. *| 1st | 2nd | ... | Last |
  297. *| 1664 | 1664 | 1664 | <=1664 |
  298. *--------------------------------
  299. *
  300. * It also calculate if current buffer has placeholder to keep padding byte.
  301. * --------------------------------
  302. * | MAX LIMIT(1662/1664) |
  303. * --------------------------------
  304. * | Actual Data | Pad byte Pholder |
  305. * --------------------------------
  306. *
  307. * @total_len: Remaining data length.
  308. * @frag_len: Data length in this fragment.
  309. * @max_limit: Max limit of current buffer/MSDU.
  310. */
  311. #ifdef DP_RX_MON_MEM_FRAG
  312. static inline
  313. void dp_rx_mon_frag_adjust_frag_len(uint32_t *total_len, uint32_t *frag_len,
  314. uint32_t max_limit)
  315. {
  316. if (*total_len >= max_limit) {
  317. *frag_len = max_limit;
  318. *total_len -= *frag_len;
  319. } else {
  320. *frag_len = *total_len;
  321. *total_len = 0;
  322. }
  323. }
  324. /**
  325. * DP_RX_MON_GET_NBUF_FROM_DESC() - Get nbuf from desc
  326. */
  327. #define DP_RX_MON_GET_NBUF_FROM_DESC(rx_desc) \
  328. NULL
  329. /**
  330. * dp_rx_mon_get_paddr_from_desc() - Get paddr from desc
  331. */
  332. static inline
  333. qdf_dma_addr_t dp_rx_mon_get_paddr_from_desc(struct dp_rx_desc *rx_desc)
  334. {
  335. return rx_desc->paddr_buf_start;
  336. }
  337. /**
  338. * DP_RX_MON_IS_BUFFER_ADDR_NULL() - Is Buffer received from hw is NULL
  339. */
  340. #define DP_RX_MON_IS_BUFFER_ADDR_NULL(rx_desc) \
  341. (!(rx_desc->rx_buf_start))
  342. #define DP_RX_MON_IS_MSDU_NOT_NULL(msdu) \
  343. true
  344. /**
  345. * dp_rx_mon_buffer_free() - Free nbuf or frag memory
  346. * Free nbuf if feature is disabled, else free frag.
  347. *
  348. * @rx_desc: Rx desc
  349. */
  350. static inline void
  351. dp_rx_mon_buffer_free(struct dp_rx_desc *rx_desc)
  352. {
  353. qdf_frag_free(rx_desc->rx_buf_start);
  354. }
  355. /**
  356. * dp_rx_mon_buffer_unmap() - Unmap nbuf or frag memory
  357. * Unmap nbuf if feature is disabled, else unmap frag.
  358. *
  359. * @soc: struct dp_soc *
  360. * @rx_desc: struct dp_rx_desc *
  361. * @size: Size to be unmapped
  362. */
  363. static inline void
  364. dp_rx_mon_buffer_unmap(struct dp_soc *soc, struct dp_rx_desc *rx_desc,
  365. uint16_t size)
  366. {
  367. qdf_mem_unmap_page(soc->osdev, rx_desc->paddr_buf_start,
  368. size, QDF_DMA_FROM_DEVICE);
  369. }
  370. /**
  371. * dp_rx_mon_alloc_parent_buffer() - Allocate parent buffer to hold
  372. * radiotap header and accommodate all frag memory in nr_frag.
  373. *
  374. * @head_msdu: Ptr to hold allocated Msdu
  375. *
  376. * Return: QDF_STATUS
  377. */
  378. static inline
  379. QDF_STATUS dp_rx_mon_alloc_parent_buffer(qdf_nbuf_t *head_msdu)
  380. {
  381. /* Headroom should accommodate radiotap header
  382. * and protocol and flow tag for all frag
  383. */
  384. /* --------------------------------------
  385. * | Protocol & Flow TAG | Radiotap header|
  386. * | 64 B | Length(128 B) |
  387. * --------------------------------------
  388. */
  389. *head_msdu = qdf_nbuf_alloc_no_recycler(DP_RX_MON_MAX_MONITOR_HEADER,
  390. DP_RX_MON_MAX_MONITOR_HEADER, 4);
  391. if (!(*head_msdu))
  392. return QDF_STATUS_E_FAILURE;
  393. /* Set *head_msdu->next as NULL as all msdus are
  394. * mapped via nr frags
  395. */
  396. qdf_nbuf_set_next(*head_msdu, NULL);
  397. return QDF_STATUS_SUCCESS;
  398. }
  399. /**
  400. * dp_rx_mon_parse_desc_buffer() - Parse desc buffer based.
  401. *
  402. * Below code will parse desc buffer, handle continuation frame,
  403. * adjust frag length and update l2_hdr_padding
  404. *
  405. * @soc : struct dp_soc*
  406. * @msdu_info : struct hal_rx_msdu_desc_info*
  407. * @is_frag_p : is_frag *
  408. * @total_frag_len_p : Remaining frag len to be updated
  409. * @frag_len_p : frag len
  410. * @l2_hdr_offset_p : l2 hdr offset
  411. * @rx_desc_tlv : rx_desc_tlv
  412. * @is_frag_non_raw_p : Non raw frag
  413. * @data : NBUF Data
  414. */
  415. static inline void
  416. dp_rx_mon_parse_desc_buffer(struct dp_soc *dp_soc,
  417. struct hal_rx_msdu_desc_info *msdu_info,
  418. bool *is_frag_p, uint32_t *total_frag_len_p,
  419. uint32_t *frag_len_p, uint16_t *l2_hdr_offset_p,
  420. qdf_frag_t rx_desc_tlv,
  421. bool *is_frag_non_raw_p, void *data)
  422. {
  423. struct hal_rx_mon_dest_buf_info frame_info;
  424. uint16_t tot_payload_len =
  425. RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN;
  426. if (msdu_info->msdu_flags & HAL_MSDU_F_MSDU_CONTINUATION) {
  427. /* First buffer of MSDU */
  428. if (!(*is_frag_p)) {
  429. /* Set total frag_len from msdu_len */
  430. *total_frag_len_p = msdu_info->msdu_len;
  431. *is_frag_p = true;
  432. if (HAL_HW_RX_DECAP_FORMAT_RAW ==
  433. HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc_tlv)) {
  434. *l2_hdr_offset_p =
  435. DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  436. frame_info.is_decap_raw = 1;
  437. } else {
  438. *l2_hdr_offset_p =
  439. DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  440. frame_info.is_decap_raw = 0;
  441. *is_frag_non_raw_p = true;
  442. }
  443. dp_rx_mon_frag_adjust_frag_len(total_frag_len_p,
  444. frag_len_p,
  445. tot_payload_len -
  446. *l2_hdr_offset_p);
  447. frame_info.first_buffer = 1;
  448. frame_info.last_buffer = 0;
  449. hal_rx_mon_dest_set_buffer_info_to_tlv(rx_desc_tlv,
  450. &frame_info);
  451. } else {
  452. /*
  453. * Continuation Middle frame
  454. * Here max limit will be same for Raw and Non raw case.
  455. */
  456. *l2_hdr_offset_p = DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  457. dp_rx_mon_frag_adjust_frag_len(total_frag_len_p,
  458. frag_len_p,
  459. tot_payload_len);
  460. /* Update frame info if is non raw frame */
  461. if (*is_frag_non_raw_p)
  462. frame_info.is_decap_raw = 0;
  463. else
  464. frame_info.is_decap_raw = 1;
  465. frame_info.first_buffer = 0;
  466. frame_info.last_buffer = 0;
  467. hal_rx_mon_dest_set_buffer_info_to_tlv(rx_desc_tlv,
  468. &frame_info);
  469. }
  470. } else {
  471. /**
  472. * Last buffer of MSDU spread among multiple buffer
  473. * Here max limit will be same for Raw and Non raw case.
  474. */
  475. if (*is_frag_p) {
  476. *l2_hdr_offset_p = DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  477. dp_rx_mon_frag_adjust_frag_len(total_frag_len_p,
  478. frag_len_p,
  479. tot_payload_len);
  480. /* Update frame info if is non raw frame */
  481. if (*is_frag_non_raw_p)
  482. frame_info.is_decap_raw = 0;
  483. else
  484. frame_info.is_decap_raw = 1;
  485. frame_info.first_buffer = 0;
  486. frame_info.last_buffer = 1;
  487. hal_rx_mon_dest_set_buffer_info_to_tlv(rx_desc_tlv,
  488. &frame_info);
  489. } else {
  490. /* MSDU with single buffer */
  491. *frag_len_p = msdu_info->msdu_len;
  492. if (HAL_HW_RX_DECAP_FORMAT_RAW ==
  493. HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc_tlv)) {
  494. *l2_hdr_offset_p =
  495. DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  496. frame_info.is_decap_raw = 1;
  497. } else {
  498. *l2_hdr_offset_p =
  499. DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  500. frame_info.is_decap_raw = 0;
  501. }
  502. frame_info.first_buffer = 1;
  503. frame_info.last_buffer = 1;
  504. hal_rx_mon_dest_set_buffer_info_to_tlv(
  505. rx_desc_tlv, &frame_info);
  506. }
  507. /* Reset bool after complete processing of MSDU */
  508. *is_frag_p = false;
  509. *is_frag_non_raw_p = false;
  510. }
  511. }
  512. /**
  513. * dp_rx_mon_buffer_set_pktlen() - set pktlen for buffer
  514. */
  515. static inline void dp_rx_mon_buffer_set_pktlen(qdf_nbuf_t msdu, uint32_t size)
  516. {
  517. }
  518. /**
  519. * dp_rx_mon_add_msdu_to_list()- Add msdu to list and update head_msdu
  520. * It will add reaped buffer frag to nr frag of parent msdu.
  521. *
  522. * @head_msdu: NULL if first time called else &msdu
  523. * @msdu: Msdu where frag address needs to be added via nr_frag
  524. * @last: Used to traverse in list if this feature is disabled.
  525. * @rx_desc_tlv: Frag address
  526. * @frag_len: Frag len
  527. * @l2_hdr_offset: l2 hdr padding
  528. */
  529. static inline
  530. void dp_rx_mon_add_msdu_to_list(qdf_nbuf_t *head_msdu, qdf_nbuf_t msdu,
  531. qdf_nbuf_t *last, qdf_frag_t rx_desc_tlv,
  532. uint32_t frag_len, uint32_t l2_hdr_offset)
  533. {
  534. qdf_nbuf_add_rx_frag(rx_desc_tlv, *head_msdu, SIZE_OF_MONITOR_TLV,
  535. frag_len + l2_hdr_offset, RX_MONITOR_BUFFER_SIZE,
  536. false);
  537. }
  538. /**
  539. * dp_rx_mon_init_tail_msdu() - Initialize tail msdu
  540. *
  541. * @msdu: Msdu to be updated in tail_msdu
  542. * @last: last msdu
  543. * @tail_msdu: Last msdu
  544. */
  545. static inline
  546. void dp_rx_mon_init_tail_msdu(qdf_nbuf_t msdu, qdf_nbuf_t last,
  547. qdf_nbuf_t *tail_msdu)
  548. {
  549. }
  550. /**
  551. * dp_rx_mon_remove_raw_frame_fcs_len() - Remove FCS length for Raw Frame
  552. *
  553. * If feature is disabled, then removal happens in restitch logic.
  554. *
  555. * @head_msdu: Head msdu
  556. */
  557. static inline
  558. void dp_rx_mon_remove_raw_frame_fcs_len(qdf_nbuf_t *head_msdu)
  559. {
  560. qdf_frag_t addr;
  561. /* Strip FCS_LEN for Raw frame */
  562. if (head_msdu && *head_msdu) {
  563. addr = qdf_nbuf_get_frag_addr(*head_msdu, 0);
  564. addr -= SIZE_OF_MONITOR_TLV;
  565. if (HAL_RX_DESC_GET_DECAP_FORMAT(addr) ==
  566. HAL_HW_RX_DECAP_FORMAT_RAW) {
  567. qdf_nbuf_trim_add_frag_size(*head_msdu,
  568. qdf_nbuf_get_nr_frags(*head_msdu) - 1,
  569. -HAL_RX_FCS_LEN, 0);
  570. }
  571. }
  572. }
  573. /**
  574. * dp_rx_mon_get_buffer_data()- Get data from desc buffer
  575. * @rx_desc: desc
  576. *
  577. * Return address containing actual tlv content
  578. */
  579. static inline
  580. uint8_t *dp_rx_mon_get_buffer_data(struct dp_rx_desc *rx_desc)
  581. {
  582. return rx_desc->rx_buf_start;
  583. }
  584. /**
  585. * dp_rx_mon_get_nbuf_80211_hdr() - Get 80211 hdr from nbuf
  586. * @nbuf: qdf_nbuf_t
  587. *
  588. * This function must be called after moving radiotap header.
  589. *
  590. * Return: Ptr pointing to 80211 header or NULL.
  591. */
  592. static inline
  593. qdf_frag_t dp_rx_mon_get_nbuf_80211_hdr(qdf_nbuf_t nbuf)
  594. {
  595. /* Return NULL if nr_frag is Zero */
  596. if (!qdf_nbuf_get_nr_frags(nbuf))
  597. return NULL;
  598. return qdf_nbuf_get_frag_addr(nbuf, 0);
  599. }
  600. #else
  601. #define DP_RX_MON_GET_NBUF_FROM_DESC(rx_desc) \
  602. (rx_desc->nbuf)
  603. static inline
  604. qdf_dma_addr_t dp_rx_mon_get_paddr_from_desc(struct dp_rx_desc *rx_desc)
  605. {
  606. qdf_dma_addr_t paddr = 0;
  607. qdf_nbuf_t msdu = NULL;
  608. msdu = rx_desc->nbuf;
  609. if (msdu)
  610. paddr = qdf_nbuf_get_frag_paddr(msdu, 0);
  611. return paddr;
  612. }
  613. #define DP_RX_MON_IS_BUFFER_ADDR_NULL(rx_desc) \
  614. (!(rx_desc->nbuf))
  615. #define DP_RX_MON_IS_MSDU_NOT_NULL(msdu) \
  616. (msdu)
  617. static inline void
  618. dp_rx_mon_buffer_free(struct dp_rx_desc *rx_desc)
  619. {
  620. qdf_nbuf_free(rx_desc->nbuf);
  621. }
  622. static inline void
  623. dp_rx_mon_buffer_unmap(struct dp_soc *soc, struct dp_rx_desc *rx_desc,
  624. uint16_t size)
  625. {
  626. qdf_nbuf_unmap_nbytes_single(soc->osdev, rx_desc->nbuf,
  627. QDF_DMA_FROM_DEVICE, size);
  628. }
  629. static inline
  630. QDF_STATUS dp_rx_mon_alloc_parent_buffer(qdf_nbuf_t *head_msdu)
  631. {
  632. return QDF_STATUS_SUCCESS;
  633. }
  634. static inline void
  635. dp_rx_mon_parse_desc_buffer(struct dp_soc *dp_soc,
  636. struct hal_rx_msdu_desc_info *msdu_info,
  637. bool *is_frag_p, uint32_t *total_frag_len_p,
  638. uint32_t *frag_len_p, uint16_t *l2_hdr_offset_p,
  639. qdf_frag_t rx_desc_tlv,
  640. bool *is_frag_non_raw_p, void *data)
  641. {
  642. /*
  643. * HW structures call this L3 header padding
  644. * -- even though this is actually the offset
  645. * from the buffer beginning where the L2
  646. * header begins.
  647. */
  648. *l2_hdr_offset_p =
  649. hal_rx_msdu_end_l3_hdr_padding_get(dp_soc->hal_soc, data);
  650. if (msdu_info->msdu_flags & HAL_MSDU_F_MSDU_CONTINUATION) {
  651. if (!*(is_frag_p)) {
  652. *total_frag_len_p = msdu_info->msdu_len;
  653. *is_frag_p = true;
  654. }
  655. dp_mon_adjust_frag_len(total_frag_len_p, frag_len_p,
  656. *l2_hdr_offset_p);
  657. } else {
  658. if (*is_frag_p) {
  659. dp_mon_adjust_frag_len(total_frag_len_p, frag_len_p,
  660. *l2_hdr_offset_p);
  661. } else {
  662. *frag_len_p = msdu_info->msdu_len;
  663. }
  664. *is_frag_p = false;
  665. }
  666. }
  667. static inline void dp_rx_mon_buffer_set_pktlen(qdf_nbuf_t msdu, uint32_t size)
  668. {
  669. qdf_nbuf_set_pktlen(msdu, size);
  670. }
  671. static inline
  672. void dp_rx_mon_add_msdu_to_list(qdf_nbuf_t *head_msdu, qdf_nbuf_t msdu,
  673. qdf_nbuf_t *last, qdf_frag_t rx_desc_tlv,
  674. uint32_t frag_len, uint32_t l2_hdr_offset)
  675. {
  676. if (head_msdu && !*head_msdu) {
  677. *head_msdu = msdu;
  678. } else {
  679. if (*last)
  680. qdf_nbuf_set_next(*last, msdu);
  681. }
  682. *last = msdu;
  683. }
  684. static inline
  685. void dp_rx_mon_init_tail_msdu(qdf_nbuf_t msdu, qdf_nbuf_t last,
  686. qdf_nbuf_t *tail_msdu)
  687. {
  688. if (last)
  689. qdf_nbuf_set_next(last, NULL);
  690. *tail_msdu = msdu;
  691. }
  692. static inline
  693. void dp_rx_mon_remove_raw_frame_fcs_len(qdf_nbuf_t *head_msdu)
  694. {
  695. }
  696. static inline
  697. uint8_t *dp_rx_mon_get_buffer_data(struct dp_rx_desc *rx_desc)
  698. {
  699. qdf_nbuf_t msdu = NULL;
  700. uint8_t *data = NULL;
  701. msdu = rx_desc->nbuf;
  702. if (qdf_likely(msdu))
  703. data = qdf_nbuf_data(msdu);
  704. return data;
  705. }
  706. static inline
  707. qdf_frag_t dp_rx_mon_get_nbuf_80211_hdr(qdf_nbuf_t nbuf)
  708. {
  709. return qdf_nbuf_data(nbuf);
  710. }
  711. #endif
  712. /**
  713. * dp_rx_cookie_2_mon_link_desc() - Retrieve Link descriptor based on target
  714. * @pdev: core physical device context
  715. * @hal_buf_info: structure holding the buffer info
  716. * mac_id: mac number
  717. *
  718. * Return: link descriptor address
  719. */
  720. static inline
  721. void *dp_rx_cookie_2_mon_link_desc(struct dp_pdev *pdev,
  722. struct hal_buf_info buf_info,
  723. uint8_t mac_id)
  724. {
  725. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  726. return dp_rx_cookie_2_mon_link_desc_va(pdev, &buf_info,
  727. mac_id);
  728. return dp_rx_cookie_2_link_desc_va(pdev->soc, &buf_info);
  729. }
  730. /**
  731. * dp_rx_monitor_link_desc_return() - Return Link descriptor based on target
  732. * @pdev: core physical device context
  733. * @p_last_buf_addr_info: MPDU Link descriptor
  734. * mac_id: mac number
  735. *
  736. * Return: QDF_STATUS
  737. */
  738. static inline
  739. QDF_STATUS dp_rx_monitor_link_desc_return(struct dp_pdev *pdev,
  740. hal_buff_addrinfo_t
  741. p_last_buf_addr_info,
  742. uint8_t mac_id, uint8_t bm_action)
  743. {
  744. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  745. return dp_rx_mon_link_desc_return(pdev, p_last_buf_addr_info,
  746. mac_id);
  747. return dp_rx_link_desc_return_by_addr(pdev->soc, p_last_buf_addr_info,
  748. bm_action);
  749. }
  750. /**
  751. * dp_rxdma_get_mon_dst_ring() - Return the pointer to rxdma_err_dst_ring
  752. * or mon_dst_ring based on the target
  753. * @pdev: core physical device context
  754. * @mac_for_pdev: mac_id number
  755. *
  756. * Return: ring address
  757. */
  758. static inline
  759. void *dp_rxdma_get_mon_dst_ring(struct dp_pdev *pdev,
  760. uint8_t mac_for_pdev)
  761. {
  762. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  763. return pdev->soc->rxdma_mon_dst_ring[mac_for_pdev].hal_srng;
  764. return pdev->soc->rxdma_err_dst_ring[mac_for_pdev].hal_srng;
  765. }
  766. /**
  767. * dp_rxdma_get_mon_buf_ring() - Return monitor buf ring address
  768. * based on target
  769. * @pdev: core physical device context
  770. * @mac_for_pdev: mac id number
  771. *
  772. * Return: ring address
  773. */
  774. static inline
  775. struct dp_srng *dp_rxdma_get_mon_buf_ring(struct dp_pdev *pdev,
  776. uint8_t mac_for_pdev)
  777. {
  778. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  779. return &pdev->soc->rxdma_mon_buf_ring[mac_for_pdev];
  780. /* For MCL there is only 1 rx refill ring */
  781. return &pdev->soc->rx_refill_buf_ring[0];
  782. }
  783. /**
  784. * dp_rx_get_mon_desc_pool() - Return monitor descriptor pool
  785. * based on target
  786. * @soc: soc handle
  787. * @mac_id: mac id number
  788. * @pdev_id: pdev id number
  789. *
  790. * Return: descriptor pool address
  791. */
  792. static inline
  793. struct rx_desc_pool *dp_rx_get_mon_desc_pool(struct dp_soc *soc,
  794. uint8_t mac_id,
  795. uint8_t pdev_id)
  796. {
  797. if (soc->wlan_cfg_ctx->rxdma1_enable)
  798. return &soc->rx_desc_mon[mac_id];
  799. return &soc->rx_desc_buf[pdev_id];
  800. }
  801. /**
  802. * dp_rx_get_mon_desc() - Return Rx descriptor based on target
  803. * @soc: soc handle
  804. * @cookie: cookie value
  805. *
  806. * Return: Rx descriptor
  807. */
  808. static inline
  809. struct dp_rx_desc *dp_rx_get_mon_desc(struct dp_soc *soc,
  810. uint32_t cookie)
  811. {
  812. if (soc->wlan_cfg_ctx->rxdma1_enable)
  813. return dp_rx_cookie_2_va_mon_buf(soc, cookie);
  814. return dp_rx_cookie_2_va_rxdma_buf(soc, cookie);
  815. }
  816. #ifndef REMOVE_MON_DBG_STATS
  817. /*
  818. * dp_rx_mon_update_dbg_ppdu_stats() - Update status ring TLV count
  819. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  820. * @rx_mon_stats: monitor mode status/destination ring PPDU and MPDU count
  821. *
  822. * Update status ring PPDU start and end count. Keep track TLV state on
  823. * PPDU start and end to find out if start and end is matching. Keep
  824. * track missing PPDU start and end count. Keep track matching PPDU
  825. * start and end count.
  826. *
  827. * Return: None
  828. */
  829. static inline void
  830. dp_rx_mon_update_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  831. struct cdp_pdev_mon_stats *rx_mon_stats)
  832. {
  833. if (ppdu_info->rx_state ==
  834. HAL_RX_MON_PPDU_START) {
  835. rx_mon_stats->status_ppdu_start++;
  836. if (rx_mon_stats->status_ppdu_state
  837. != CDP_MON_PPDU_END)
  838. rx_mon_stats->status_ppdu_end_mis++;
  839. rx_mon_stats->status_ppdu_state
  840. = CDP_MON_PPDU_START;
  841. ppdu_info->rx_state = HAL_RX_MON_PPDU_RESET;
  842. } else if (ppdu_info->rx_state ==
  843. HAL_RX_MON_PPDU_END) {
  844. rx_mon_stats->status_ppdu_end++;
  845. if (rx_mon_stats->status_ppdu_state
  846. != CDP_MON_PPDU_START)
  847. rx_mon_stats->status_ppdu_start_mis++;
  848. else
  849. rx_mon_stats->status_ppdu_compl++;
  850. rx_mon_stats->status_ppdu_state
  851. = CDP_MON_PPDU_END;
  852. ppdu_info->rx_state = HAL_RX_MON_PPDU_RESET;
  853. }
  854. }
  855. /*
  856. * dp_rx_mon_init_dbg_ppdu_stats() - initialization for monitor mode stats
  857. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  858. * @rx_mon_stats: monitor mode status/destination ring PPDU and MPDU count
  859. *
  860. * Return: None
  861. */
  862. static inline void
  863. dp_rx_mon_init_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  864. struct cdp_pdev_mon_stats *rx_mon_stats)
  865. {
  866. ppdu_info->rx_state = HAL_RX_MON_PPDU_END;
  867. rx_mon_stats->status_ppdu_state
  868. = CDP_MON_PPDU_END;
  869. }
  870. #else
  871. static inline void
  872. dp_rx_mon_update_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  873. struct cdp_pdev_mon_stats *rx_mon_stats)
  874. {
  875. }
  876. static inline void
  877. dp_rx_mon_init_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  878. struct cdp_pdev_mon_stats *rx_mon_stats)
  879. {
  880. }
  881. #endif
  882. #endif