dp_rx_mon.h 25 KB

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