dp_rx_mon.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970
  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. */
  266. static inline void dp_mon_adjust_frag_len(uint32_t *total_len,
  267. uint32_t *frag_len)
  268. {
  269. if (*total_len >= (RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN)) {
  270. *frag_len = RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN;
  271. *total_len -= *frag_len;
  272. } else {
  273. *frag_len = *total_len;
  274. *total_len = 0;
  275. }
  276. }
  277. /**
  278. * dp_rx_mon_frag_adjust_frag_len() - MPDU and MSDU may spread across
  279. * multiple nbufs. This function is to return data length in
  280. * fragmented buffer.
  281. * It takes input as max_limit for any buffer(as it changes based
  282. * on decap type and buffer sequence in MSDU.
  283. *
  284. * If MSDU is divided into multiple buffer then below format will
  285. * be max limit.
  286. * Decap type Non-Raw
  287. *--------------------------------
  288. *| 1st | 2nd | ... | Last |
  289. *| 1662 | 1664 | 1664 | <=1664 |
  290. *--------------------------------
  291. * Decap type Raw
  292. *--------------------------------
  293. *| 1st | 2nd | ... | Last |
  294. *| 1664 | 1664 | 1664 | <=1664 |
  295. *--------------------------------
  296. *
  297. * It also calculate if current buffer has placeholder to keep padding byte.
  298. * --------------------------------
  299. * | MAX LIMIT(1662/1664) |
  300. * --------------------------------
  301. * | Actual Data | Pad byte Pholder |
  302. * --------------------------------
  303. *
  304. * @total_len: Remaining data length.
  305. * @frag_len: Data length in this fragment.
  306. * @max_limit: Max limit of current buffer/MSDU.
  307. */
  308. #ifdef DP_RX_MON_MEM_FRAG
  309. static inline
  310. void dp_rx_mon_frag_adjust_frag_len(uint32_t *total_len, uint32_t *frag_len,
  311. uint32_t max_limit)
  312. {
  313. if (*total_len >= max_limit) {
  314. *frag_len = max_limit;
  315. *total_len -= *frag_len;
  316. } else {
  317. *frag_len = *total_len;
  318. *total_len = 0;
  319. }
  320. }
  321. /**
  322. * DP_RX_MON_GET_NBUF_FROM_DESC() - Get nbuf from desc
  323. */
  324. #define DP_RX_MON_GET_NBUF_FROM_DESC(rx_desc) \
  325. NULL
  326. /**
  327. * dp_rx_mon_get_paddr_from_desc() - Get paddr from desc
  328. */
  329. static inline
  330. qdf_dma_addr_t dp_rx_mon_get_paddr_from_desc(struct dp_rx_desc *rx_desc)
  331. {
  332. return rx_desc->paddr_buf_start;
  333. }
  334. /**
  335. * DP_RX_MON_IS_BUFFER_ADDR_NULL() - Is Buffer received from hw is NULL
  336. */
  337. #define DP_RX_MON_IS_BUFFER_ADDR_NULL(rx_desc) \
  338. (!(rx_desc->rx_buf_start))
  339. #define DP_RX_MON_IS_MSDU_NOT_NULL(msdu) \
  340. true
  341. /**
  342. * dp_rx_mon_buffer_free() - Free nbuf or frag memory
  343. * Free nbuf if feature is disabled, else free frag.
  344. *
  345. * @rx_desc: Rx desc
  346. */
  347. static inline void
  348. dp_rx_mon_buffer_free(struct dp_rx_desc *rx_desc)
  349. {
  350. qdf_frag_free(rx_desc->rx_buf_start);
  351. }
  352. /**
  353. * dp_rx_mon_buffer_unmap() - Unmap nbuf or frag memory
  354. * Unmap nbuf if feature is disabled, else unmap frag.
  355. *
  356. * @soc: struct dp_soc *
  357. * @rx_desc: struct dp_rx_desc *
  358. * @size: Size to be unmapped
  359. */
  360. static inline void
  361. dp_rx_mon_buffer_unmap(struct dp_soc *soc, struct dp_rx_desc *rx_desc,
  362. uint16_t size)
  363. {
  364. qdf_mem_unmap_page(soc->osdev, rx_desc->paddr_buf_start,
  365. size, QDF_DMA_FROM_DEVICE);
  366. }
  367. /**
  368. * dp_rx_mon_alloc_parent_buffer() - Allocate parent buffer to hold
  369. * radiotap header and accommodate all frag memory in nr_frag.
  370. *
  371. * @head_msdu: Ptr to hold allocated Msdu
  372. *
  373. * Return: QDF_STATUS
  374. */
  375. static inline
  376. QDF_STATUS dp_rx_mon_alloc_parent_buffer(qdf_nbuf_t *head_msdu)
  377. {
  378. /* Headroom should accommodate radiotap header
  379. * and protocol and flow tag for all frag
  380. */
  381. /* --------------------------------------
  382. * | Protocol & Flow TAG | Radiotap header|
  383. * | 64 B | Length(128 B) |
  384. * --------------------------------------
  385. */
  386. *head_msdu = qdf_nbuf_alloc_no_recycler(DP_RX_MON_MAX_MONITOR_HEADER,
  387. DP_RX_MON_MAX_MONITOR_HEADER, 4);
  388. if (!(*head_msdu))
  389. return QDF_STATUS_E_FAILURE;
  390. /* Set *head_msdu->next as NULL as all msdus are
  391. * mapped via nr frags
  392. */
  393. qdf_nbuf_set_next(*head_msdu, NULL);
  394. return QDF_STATUS_SUCCESS;
  395. }
  396. /**
  397. * dp_rx_mon_parse_desc_buffer() - Parse desc buffer based.
  398. *
  399. * Below code will parse desc buffer, handle continuation frame,
  400. * adjust frag length and update l2_hdr_padding
  401. *
  402. * @soc : struct dp_soc*
  403. * @msdu_info : struct hal_rx_msdu_desc_info*
  404. * @is_frag_p : is_frag *
  405. * @total_frag_len_p : Remaining frag len to be updated
  406. * @frag_len_p : frag len
  407. * @l2_hdr_offset_p : l2 hdr offset
  408. * @rx_desc_tlv : rx_desc_tlv
  409. * @is_frag_non_raw_p : Non raw frag
  410. * @data : NBUF Data
  411. */
  412. static inline void
  413. dp_rx_mon_parse_desc_buffer(struct dp_soc *dp_soc,
  414. struct hal_rx_msdu_desc_info *msdu_info,
  415. bool *is_frag_p, uint32_t *total_frag_len_p,
  416. uint32_t *frag_len_p, uint16_t *l2_hdr_offset_p,
  417. qdf_frag_t rx_desc_tlv,
  418. bool *is_frag_non_raw_p, void *data)
  419. {
  420. struct hal_rx_mon_dest_buf_info frame_info;
  421. uint16_t tot_payload_len =
  422. RX_MONITOR_BUFFER_SIZE - RX_PKT_TLVS_LEN;
  423. if (msdu_info->msdu_flags & HAL_MSDU_F_MSDU_CONTINUATION) {
  424. /* First buffer of MSDU */
  425. if (!(*is_frag_p)) {
  426. /* Set total frag_len from msdu_len */
  427. *total_frag_len_p = msdu_info->msdu_len;
  428. *is_frag_p = true;
  429. if (HAL_HW_RX_DECAP_FORMAT_RAW ==
  430. HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc_tlv)) {
  431. *l2_hdr_offset_p =
  432. DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  433. frame_info.is_decap_raw = 1;
  434. } else {
  435. *l2_hdr_offset_p =
  436. DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  437. frame_info.is_decap_raw = 0;
  438. *is_frag_non_raw_p = true;
  439. }
  440. dp_rx_mon_frag_adjust_frag_len(total_frag_len_p,
  441. frag_len_p,
  442. tot_payload_len -
  443. *l2_hdr_offset_p);
  444. frame_info.first_buffer = 1;
  445. frame_info.last_buffer = 0;
  446. hal_rx_mon_dest_set_buffer_info_to_tlv(rx_desc_tlv,
  447. &frame_info);
  448. } else {
  449. /*
  450. * Continuation Middle frame
  451. * Here max limit will be same for Raw and Non raw case.
  452. */
  453. *l2_hdr_offset_p = DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  454. dp_rx_mon_frag_adjust_frag_len(total_frag_len_p,
  455. frag_len_p,
  456. tot_payload_len);
  457. /* Update frame info if is non raw frame */
  458. if (*is_frag_non_raw_p)
  459. frame_info.is_decap_raw = 0;
  460. else
  461. frame_info.is_decap_raw = 1;
  462. frame_info.first_buffer = 0;
  463. frame_info.last_buffer = 0;
  464. hal_rx_mon_dest_set_buffer_info_to_tlv(rx_desc_tlv,
  465. &frame_info);
  466. }
  467. } else {
  468. /**
  469. * Last buffer of MSDU spread among multiple buffer
  470. * Here max limit will be same for Raw and Non raw case.
  471. */
  472. if (*is_frag_p) {
  473. *l2_hdr_offset_p = DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  474. dp_rx_mon_frag_adjust_frag_len(total_frag_len_p,
  475. frag_len_p,
  476. tot_payload_len);
  477. /* Update frame info if is non raw frame */
  478. if (*is_frag_non_raw_p)
  479. frame_info.is_decap_raw = 0;
  480. else
  481. frame_info.is_decap_raw = 1;
  482. frame_info.first_buffer = 0;
  483. frame_info.last_buffer = 1;
  484. hal_rx_mon_dest_set_buffer_info_to_tlv(rx_desc_tlv,
  485. &frame_info);
  486. } else {
  487. /* MSDU with single buffer */
  488. *frag_len_p = msdu_info->msdu_len;
  489. if (HAL_HW_RX_DECAP_FORMAT_RAW ==
  490. HAL_RX_DESC_GET_DECAP_FORMAT(rx_desc_tlv)) {
  491. *l2_hdr_offset_p =
  492. DP_RX_MON_RAW_L2_HDR_PAD_BYTE;
  493. frame_info.is_decap_raw = 1;
  494. } else {
  495. *l2_hdr_offset_p =
  496. DP_RX_MON_NONRAW_L2_HDR_PAD_BYTE;
  497. frame_info.is_decap_raw = 0;
  498. }
  499. frame_info.first_buffer = 1;
  500. frame_info.last_buffer = 1;
  501. hal_rx_mon_dest_set_buffer_info_to_tlv(
  502. rx_desc_tlv, &frame_info);
  503. }
  504. /* Reset bool after complete processing of MSDU */
  505. *is_frag_p = false;
  506. *is_frag_non_raw_p = false;
  507. }
  508. }
  509. /**
  510. * dp_rx_mon_buffer_set_pktlen() - set pktlen for buffer
  511. */
  512. static inline void dp_rx_mon_buffer_set_pktlen(qdf_nbuf_t msdu, uint32_t size)
  513. {
  514. }
  515. /**
  516. * dp_rx_mon_add_msdu_to_list()- Add msdu to list and update head_msdu
  517. * It will add reaped buffer frag to nr frag of parent msdu.
  518. *
  519. * @head_msdu: NULL if first time called else &msdu
  520. * @msdu: Msdu where frag address needs to be added via nr_frag
  521. * @last: Used to traverse in list if this feature is disabled.
  522. * @rx_desc_tlv: Frag address
  523. * @frag_len: Frag len
  524. * @l2_hdr_offset: l2 hdr padding
  525. */
  526. static inline
  527. void dp_rx_mon_add_msdu_to_list(qdf_nbuf_t *head_msdu, qdf_nbuf_t msdu,
  528. qdf_nbuf_t *last, qdf_frag_t rx_desc_tlv,
  529. uint32_t frag_len, uint32_t l2_hdr_offset)
  530. {
  531. qdf_nbuf_add_rx_frag(rx_desc_tlv, *head_msdu, SIZE_OF_MONITOR_TLV,
  532. frag_len + l2_hdr_offset, RX_MONITOR_BUFFER_SIZE,
  533. false);
  534. }
  535. /**
  536. * dp_rx_mon_init_tail_msdu() - Initialize tail msdu
  537. *
  538. * @msdu: Msdu to be updated in tail_msdu
  539. * @last: last msdu
  540. * @tail_msdu: Last msdu
  541. */
  542. static inline
  543. void dp_rx_mon_init_tail_msdu(qdf_nbuf_t msdu, qdf_nbuf_t last,
  544. qdf_nbuf_t *tail_msdu)
  545. {
  546. }
  547. /**
  548. * dp_rx_mon_remove_raw_frame_fcs_len() - Remove FCS length for Raw Frame
  549. *
  550. * If feature is disabled, then removal happens in restitch logic.
  551. *
  552. * @head_msdu: Head msdu
  553. */
  554. static inline
  555. void dp_rx_mon_remove_raw_frame_fcs_len(qdf_nbuf_t *head_msdu)
  556. {
  557. qdf_frag_t addr;
  558. /* Strip FCS_LEN for Raw frame */
  559. if (head_msdu && *head_msdu) {
  560. addr = qdf_nbuf_get_frag_addr(*head_msdu, 0);
  561. addr -= SIZE_OF_MONITOR_TLV;
  562. if (HAL_RX_DESC_GET_DECAP_FORMAT(addr) ==
  563. HAL_HW_RX_DECAP_FORMAT_RAW) {
  564. qdf_nbuf_trim_add_frag_size(*head_msdu,
  565. qdf_nbuf_get_nr_frags(*head_msdu) - 1,
  566. -HAL_RX_FCS_LEN, 0);
  567. }
  568. }
  569. }
  570. /**
  571. * dp_rx_mon_get_buffer_data()- Get data from desc buffer
  572. * @rx_desc: desc
  573. *
  574. * Return address containing actual tlv content
  575. */
  576. static inline
  577. uint8_t *dp_rx_mon_get_buffer_data(struct dp_rx_desc *rx_desc)
  578. {
  579. return rx_desc->rx_buf_start;
  580. }
  581. /**
  582. * dp_rx_mon_get_nbuf_80211_hdr() - Get 80211 hdr from nbuf
  583. * @nbuf: qdf_nbuf_t
  584. *
  585. * This function must be called after moving radiotap header.
  586. *
  587. * Return: Ptr pointing to 80211 header or NULL.
  588. */
  589. static inline
  590. qdf_frag_t dp_rx_mon_get_nbuf_80211_hdr(qdf_nbuf_t nbuf)
  591. {
  592. /* Return NULL if nr_frag is Zero */
  593. if (!qdf_nbuf_get_nr_frags(nbuf))
  594. return NULL;
  595. return qdf_nbuf_get_frag_addr(nbuf, 0);
  596. }
  597. #else
  598. #define DP_RX_MON_GET_NBUF_FROM_DESC(rx_desc) \
  599. (rx_desc->nbuf)
  600. static inline
  601. qdf_dma_addr_t dp_rx_mon_get_paddr_from_desc(struct dp_rx_desc *rx_desc)
  602. {
  603. qdf_dma_addr_t paddr = 0;
  604. qdf_nbuf_t msdu = NULL;
  605. msdu = rx_desc->nbuf;
  606. if (msdu)
  607. paddr = qdf_nbuf_get_frag_paddr(msdu, 0);
  608. return paddr;
  609. }
  610. #define DP_RX_MON_IS_BUFFER_ADDR_NULL(rx_desc) \
  611. (!(rx_desc->nbuf))
  612. #define DP_RX_MON_IS_MSDU_NOT_NULL(msdu) \
  613. (msdu)
  614. static inline void
  615. dp_rx_mon_buffer_free(struct dp_rx_desc *rx_desc)
  616. {
  617. qdf_nbuf_free(rx_desc->nbuf);
  618. }
  619. static inline void
  620. dp_rx_mon_buffer_unmap(struct dp_soc *soc, struct dp_rx_desc *rx_desc,
  621. uint16_t size)
  622. {
  623. qdf_nbuf_unmap_nbytes_single(soc->osdev, rx_desc->nbuf,
  624. QDF_DMA_FROM_DEVICE, size);
  625. }
  626. static inline
  627. QDF_STATUS dp_rx_mon_alloc_parent_buffer(qdf_nbuf_t *head_msdu)
  628. {
  629. return QDF_STATUS_SUCCESS;
  630. }
  631. static inline void
  632. dp_rx_mon_parse_desc_buffer(struct dp_soc *dp_soc,
  633. struct hal_rx_msdu_desc_info *msdu_info,
  634. bool *is_frag_p, uint32_t *total_frag_len_p,
  635. uint32_t *frag_len_p, uint16_t *l2_hdr_offset_p,
  636. qdf_frag_t rx_desc_tlv,
  637. bool *is_frag_non_raw_p, void *data)
  638. {
  639. if (msdu_info->msdu_flags & HAL_MSDU_F_MSDU_CONTINUATION) {
  640. if (!*(is_frag_p)) {
  641. *total_frag_len_p = msdu_info->msdu_len;
  642. *is_frag_p = true;
  643. }
  644. dp_mon_adjust_frag_len(total_frag_len_p, frag_len_p);
  645. } else {
  646. if (*is_frag_p) {
  647. dp_mon_adjust_frag_len(
  648. total_frag_len_p, frag_len_p);
  649. } else {
  650. *frag_len_p = msdu_info->msdu_len;
  651. }
  652. *is_frag_p = false;
  653. }
  654. /*
  655. * HW structures call this L3 header padding
  656. * -- even though this is actually the offset
  657. * from the buffer beginning where the L2
  658. * header begins.
  659. */
  660. *l2_hdr_offset_p =
  661. hal_rx_msdu_end_l3_hdr_padding_get(dp_soc->hal_soc, data);
  662. }
  663. static inline void dp_rx_mon_buffer_set_pktlen(qdf_nbuf_t msdu, uint32_t size)
  664. {
  665. qdf_nbuf_set_pktlen(msdu, size);
  666. }
  667. static inline
  668. void dp_rx_mon_add_msdu_to_list(qdf_nbuf_t *head_msdu, qdf_nbuf_t msdu,
  669. qdf_nbuf_t *last, qdf_frag_t rx_desc_tlv,
  670. uint32_t frag_len, uint32_t l2_hdr_offset)
  671. {
  672. if (head_msdu && !*head_msdu) {
  673. *head_msdu = msdu;
  674. } else {
  675. if (*last)
  676. qdf_nbuf_set_next(*last, msdu);
  677. }
  678. *last = msdu;
  679. }
  680. static inline
  681. void dp_rx_mon_init_tail_msdu(qdf_nbuf_t msdu, qdf_nbuf_t last,
  682. qdf_nbuf_t *tail_msdu)
  683. {
  684. if (last)
  685. qdf_nbuf_set_next(last, NULL);
  686. *tail_msdu = msdu;
  687. }
  688. static inline
  689. void dp_rx_mon_remove_raw_frame_fcs_len(qdf_nbuf_t *head_msdu)
  690. {
  691. }
  692. static inline
  693. uint8_t *dp_rx_mon_get_buffer_data(struct dp_rx_desc *rx_desc)
  694. {
  695. qdf_nbuf_t msdu = NULL;
  696. uint8_t *data = NULL;
  697. msdu = rx_desc->nbuf;
  698. if (qdf_likely(msdu))
  699. data = qdf_nbuf_data(msdu);
  700. return data;
  701. }
  702. static inline
  703. qdf_frag_t dp_rx_mon_get_nbuf_80211_hdr(qdf_nbuf_t nbuf)
  704. {
  705. return qdf_nbuf_data(nbuf);
  706. }
  707. #endif
  708. /**
  709. * dp_rx_cookie_2_mon_link_desc() - Retrieve Link descriptor based on target
  710. * @pdev: core physical device context
  711. * @hal_buf_info: structure holding the buffer info
  712. * mac_id: mac number
  713. *
  714. * Return: link descriptor address
  715. */
  716. static inline
  717. void *dp_rx_cookie_2_mon_link_desc(struct dp_pdev *pdev,
  718. struct hal_buf_info buf_info,
  719. uint8_t mac_id)
  720. {
  721. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  722. return dp_rx_cookie_2_mon_link_desc_va(pdev, &buf_info,
  723. mac_id);
  724. return dp_rx_cookie_2_link_desc_va(pdev->soc, &buf_info);
  725. }
  726. /**
  727. * dp_rx_monitor_link_desc_return() - Return Link descriptor based on target
  728. * @pdev: core physical device context
  729. * @p_last_buf_addr_info: MPDU Link descriptor
  730. * mac_id: mac number
  731. *
  732. * Return: QDF_STATUS
  733. */
  734. static inline
  735. QDF_STATUS dp_rx_monitor_link_desc_return(struct dp_pdev *pdev,
  736. hal_buff_addrinfo_t
  737. p_last_buf_addr_info,
  738. uint8_t mac_id, uint8_t bm_action)
  739. {
  740. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  741. return dp_rx_mon_link_desc_return(pdev, p_last_buf_addr_info,
  742. mac_id);
  743. return dp_rx_link_desc_return_by_addr(pdev->soc, p_last_buf_addr_info,
  744. bm_action);
  745. }
  746. /**
  747. * dp_rxdma_get_mon_dst_ring() - Return the pointer to rxdma_err_dst_ring
  748. * or mon_dst_ring based on the target
  749. * @pdev: core physical device context
  750. * @mac_for_pdev: mac_id number
  751. *
  752. * Return: ring address
  753. */
  754. static inline
  755. void *dp_rxdma_get_mon_dst_ring(struct dp_pdev *pdev,
  756. uint8_t mac_for_pdev)
  757. {
  758. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  759. return pdev->soc->rxdma_mon_dst_ring[mac_for_pdev].hal_srng;
  760. return pdev->soc->rxdma_err_dst_ring[mac_for_pdev].hal_srng;
  761. }
  762. /**
  763. * dp_rxdma_get_mon_buf_ring() - Return monitor buf ring address
  764. * based on target
  765. * @pdev: core physical device context
  766. * @mac_for_pdev: mac id number
  767. *
  768. * Return: ring address
  769. */
  770. static inline
  771. struct dp_srng *dp_rxdma_get_mon_buf_ring(struct dp_pdev *pdev,
  772. uint8_t mac_for_pdev)
  773. {
  774. if (pdev->soc->wlan_cfg_ctx->rxdma1_enable)
  775. return &pdev->soc->rxdma_mon_buf_ring[mac_for_pdev];
  776. /* For MCL there is only 1 rx refill ring */
  777. return &pdev->soc->rx_refill_buf_ring[0];
  778. }
  779. /**
  780. * dp_rx_get_mon_desc_pool() - Return monitor descriptor pool
  781. * based on target
  782. * @soc: soc handle
  783. * @mac_id: mac id number
  784. * @pdev_id: pdev id number
  785. *
  786. * Return: descriptor pool address
  787. */
  788. static inline
  789. struct rx_desc_pool *dp_rx_get_mon_desc_pool(struct dp_soc *soc,
  790. uint8_t mac_id,
  791. uint8_t pdev_id)
  792. {
  793. if (soc->wlan_cfg_ctx->rxdma1_enable)
  794. return &soc->rx_desc_mon[mac_id];
  795. return &soc->rx_desc_buf[pdev_id];
  796. }
  797. /**
  798. * dp_rx_get_mon_desc() - Return Rx descriptor based on target
  799. * @soc: soc handle
  800. * @cookie: cookie value
  801. *
  802. * Return: Rx descriptor
  803. */
  804. static inline
  805. struct dp_rx_desc *dp_rx_get_mon_desc(struct dp_soc *soc,
  806. uint32_t cookie)
  807. {
  808. if (soc->wlan_cfg_ctx->rxdma1_enable)
  809. return dp_rx_cookie_2_va_mon_buf(soc, cookie);
  810. return dp_rx_cookie_2_va_rxdma_buf(soc, cookie);
  811. }
  812. #ifndef REMOVE_MON_DBG_STATS
  813. /*
  814. * dp_rx_mon_update_dbg_ppdu_stats() - Update status ring TLV count
  815. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  816. * @rx_mon_stats: monitor mode status/destination ring PPDU and MPDU count
  817. *
  818. * Update status ring PPDU start and end count. Keep track TLV state on
  819. * PPDU start and end to find out if start and end is matching. Keep
  820. * track missing PPDU start and end count. Keep track matching PPDU
  821. * start and end count.
  822. *
  823. * Return: None
  824. */
  825. static inline void
  826. dp_rx_mon_update_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  827. struct cdp_pdev_mon_stats *rx_mon_stats)
  828. {
  829. if (ppdu_info->rx_state ==
  830. HAL_RX_MON_PPDU_START) {
  831. rx_mon_stats->status_ppdu_start++;
  832. if (rx_mon_stats->status_ppdu_state
  833. != CDP_MON_PPDU_END)
  834. rx_mon_stats->status_ppdu_end_mis++;
  835. rx_mon_stats->status_ppdu_state
  836. = CDP_MON_PPDU_START;
  837. ppdu_info->rx_state = HAL_RX_MON_PPDU_RESET;
  838. } else if (ppdu_info->rx_state ==
  839. HAL_RX_MON_PPDU_END) {
  840. rx_mon_stats->status_ppdu_end++;
  841. if (rx_mon_stats->status_ppdu_state
  842. != CDP_MON_PPDU_START)
  843. rx_mon_stats->status_ppdu_start_mis++;
  844. else
  845. rx_mon_stats->status_ppdu_compl++;
  846. rx_mon_stats->status_ppdu_state
  847. = CDP_MON_PPDU_END;
  848. ppdu_info->rx_state = HAL_RX_MON_PPDU_RESET;
  849. }
  850. }
  851. /*
  852. * dp_rx_mon_init_dbg_ppdu_stats() - initialization for monitor mode stats
  853. * @ppdu_info: HAL RX PPDU info retrieved from status ring TLV
  854. * @rx_mon_stats: monitor mode status/destination ring PPDU and MPDU count
  855. *
  856. * Return: None
  857. */
  858. static inline void
  859. dp_rx_mon_init_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  860. struct cdp_pdev_mon_stats *rx_mon_stats)
  861. {
  862. ppdu_info->rx_state = HAL_RX_MON_PPDU_END;
  863. rx_mon_stats->status_ppdu_state
  864. = CDP_MON_PPDU_END;
  865. }
  866. #else
  867. static inline void
  868. dp_rx_mon_update_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  869. struct cdp_pdev_mon_stats *rx_mon_stats)
  870. {
  871. }
  872. static inline void
  873. dp_rx_mon_init_dbg_ppdu_stats(struct hal_rx_ppdu_info *ppdu_info,
  874. struct cdp_pdev_mon_stats *rx_mon_stats)
  875. {
  876. }
  877. #endif
  878. #endif