dp_rx_mon.h 30 KB

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