1  /*
2   * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3   * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4   *
5   * Permission to use, copy, modify, and/or distribute this software for
6   * any purpose with or without fee is hereby granted, provided that the
7   * above copyright notice and this permission notice appear in all
8   * copies.
9   *
10   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11   * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12   * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13   * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14   * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15   * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16   * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17   * PERFORMANCE OF THIS SOFTWARE.
18   */
19  
20  #if !defined(__QDF_TRACE_H)
21  #define __QDF_TRACE_H
22  
23  /**
24   *  DOC: qdf_trace
25   *  QCA driver framework trace APIs
26   *  Trace, logging, and debugging definitions and APIs
27   */
28  
29  /* Include Files */
30  #include  <qdf_types.h>         /* For QDF_MODULE_ID... */
31  #include  <qdf_status.h>
32  #include  <qdf_nbuf.h>
33  #include  <i_qdf_types.h>
34  #include <qdf_debugfs.h>
35  
36  
37  /* Type declarations */
38  
39  #ifdef LOG_LINE_NUMBER
40  #define FL(x)    "%s: %d: " x, __func__, __LINE__
41  #else
42  #define FL(x)    "%s: " x, __func__
43  #endif
44  
45  #define QDF_TRACE_BUFFER_SIZE (512)
46  
47  /*
48   * Extracts the 8-bit group id from the wmi command id by performing the
49   * reverse operation of WMI_CMD_GRP_START_ID
50   */
51  #define QDF_WMI_MTRACE_GRP_ID(message_id) (((message_id) >> 12) & 0xFF)
52  /*
53   * Number of bits reserved for WMI mtrace command id
54   */
55   #define QDF_WMI_MTRACE_CMD_NUM_BITS 7
56  /*
57   * Extracts the 7-bit group specific command id from the wmi command id
58   */
59  #define QDF_WMI_MTRACE_CMD_ID(message_id) ((message_id) & 0x7F)
60  
61  #ifdef QDF_TRACE_PRINT_ENABLE
62  #define QDF_DEFAULT_TRACE_LEVEL (1 << QDF_TRACE_LEVEL_INFO)
63  #endif
64  
65  #define QDF_CATEGORY_INFO_U16(val) (((val >> 16) & 0x0000FFFF))
66  #define QDF_TRACE_LEVEL_INFO_L16(val) (val & 0x0000FFFF)
67  
68  typedef int (qdf_abstract_print)(void *priv, const char *fmt, ...);
69  
70  /*
71   * Log levels
72   */
73  #define QDF_DEBUG_FUNCTRACE     0x01
74  #define QDF_DEBUG_LEVEL0        0x02
75  #define QDF_DEBUG_LEVEL1        0x04
76  #define QDF_DEBUG_LEVEL2        0x08
77  #define QDF_DEBUG_LEVEL3        0x10
78  #define QDF_DEBUG_ERROR         0x20
79  #define QDF_DEBUG_CFG           0x40
80  
81  /*
82   * Rate limit based on pkt prototype
83   */
84  #define QDF_MAX_DHCP_PKTS_PER_SEC       (20)
85  #define QDF_MAX_EAPOL_PKTS_PER_SEC      (50)
86  #define QDF_MAX_ARP_PKTS_PER_SEC        (5)
87  #define QDF_MAX_DNS_PKTS_PER_SEC        (5)
88  #define QDF_MAX_OTHER_PKTS_PER_SEC      (1)
89  
90  /* DP Trace Implementation */
91  #ifdef CONFIG_DP_TRACE
92  #define DPTRACE(p) p
93  #define DPTRACE_PRINT(args...) \
94  	QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_DEBUG, args)
95  #else
96  #define DPTRACE(p)
97  #define DPTRACE_PRINT(args...)
98  #endif
99  
100  /* By default Data Path module will have all log levels enabled, except debug
101   * log level. Debug level will be left up to the framework or user space modules
102   * to be enabled when issue is detected
103   */
104  #define QDF_DATA_PATH_TRACE_LEVEL \
105  	((1 << QDF_TRACE_LEVEL_FATAL) | (1 << QDF_TRACE_LEVEL_ERROR) | \
106  	(1 << QDF_TRACE_LEVEL_WARN) | (1 << QDF_TRACE_LEVEL_INFO) | \
107  	(1 << QDF_TRACE_LEVEL_INFO_HIGH) | (1 << QDF_TRACE_LEVEL_INFO_MED) | \
108  	(1 << QDF_TRACE_LEVEL_INFO_LOW))
109  
110  /* Preprocessor definitions and constants */
111  #define ASSERT_BUFFER_SIZE (512)
112  
113  #ifndef MAX_QDF_TRACE_RECORDS
114  #define MAX_QDF_TRACE_RECORDS 4000
115  #endif
116  
117  #define QDF_TRACE_DEFAULT_PDEV_ID 0xff
118  #define INVALID_QDF_TRACE_ADDR 0xffffffff
119  #define DEFAULT_QDF_TRACE_DUMP_COUNT 0
120  #define QDF_TRACE_DEFAULT_MSDU_ID 0
121  
122  /*
123   * first parameter to iwpriv command - dump_dp_trace
124   * iwpriv wlan0 dump_dp_trace 0 0 -> dump full buffer
125   * iwpriv wlan0 dump_dp_trace 1 0 -> enable live view mode
126   * iwpriv wlan0 dump_dp_trace 2 0 -> clear dp trace buffer
127   * iwpriv wlan0 dump_dp_trace 3 0 -> disable live view mode
128   */
129  #define DUMP_DP_TRACE			0
130  #define ENABLE_DP_TRACE_LIVE_MODE	1
131  #define CLEAR_DP_TRACE_BUFFER		2
132  #define DISABLE_DP_TRACE_LIVE_MODE	3
133  
134  
135  #ifdef TRACE_RECORD
136  
137  #define MTRACE(p) p
138  
139  #else
140  #define MTRACE(p) do { } while (0)
141  
142  #endif
143  #define NO_SESSION 0xFF
144  
145  /**
146   * struct qdf_trace_record_s - keep trace record
147   * @qtime: qtimer ticks
148   * @time: user timestamp
149   * @module: module name
150   * @code: hold record of code
151   * @session: hold record of session
152   * @data: hold data
153   * @pid: hold pid of the process
154   */
155  typedef struct qdf_trace_record_s {
156  	uint64_t qtime;
157  	char time[18];
158  	uint8_t module;
159  	uint16_t code;
160  	uint16_t session;
161  	uint32_t data;
162  	uint32_t pid;
163  } qdf_trace_record_t, *tp_qdf_trace_record;
164  
165  /**
166   * struct s_qdf_trace_data - MTRACE logs are stored in ring buffer
167   * @head: position of first record
168   * @tail: position of last record
169   * @num: count of total record
170   * @num_since_last_dump: count from last dump
171   * @enable: config for controlling the trace
172   * @dump_count: Dump after number of records reach this number
173   */
174  typedef struct s_qdf_trace_data {
175  	uint32_t head;
176  	uint32_t tail;
177  	uint32_t num;
178  	uint16_t num_since_last_dump;
179  	uint8_t enable;
180  	uint16_t dump_count;
181  } t_qdf_trace_data;
182  
183  #ifdef CONNECTIVITY_DIAG_EVENT
184  /**
185   * enum diag_dp_tx_rx_status - TX/RX packet status
186   * @DIAG_TX_RX_STATUS_INVALID: default invalid status
187   * @DIAG_TX_RX_STATUS_OK: successfully sent + acked
188   * @DIAG_TX_RX_STATUS_FW_DISCARD: queued but not sent over air
189   * @DIAG_TX_RX_STATUS_NO_ACK: packet sent but no ack received
190   * @DIAG_TX_RX_STATUS_DROP: packet dropped due to congestion
191   * @DIAG_TX_RX_STATUS_DOWNLOAD_SUCC: packet delivered to target
192   * @DIAG_TX_RX_STATUS_DEFAULT: default status
193   * @DIAG_TX_RX_STATUS_MAX:
194   */
195  enum diag_dp_tx_rx_status {
196  	DIAG_TX_RX_STATUS_INVALID,
197  	DIAG_TX_RX_STATUS_OK,
198  	DIAG_TX_RX_STATUS_FW_DISCARD,
199  	DIAG_TX_RX_STATUS_NO_ACK,
200  	DIAG_TX_RX_STATUS_DROP,
201  	DIAG_TX_RX_STATUS_DOWNLOAD_SUCC,
202  	DIAG_TX_RX_STATUS_DEFAULT,
203  	DIAG_TX_RX_STATUS_MAX
204  };
205  
206  /**
207   * enum diag_tx_status - Used by attribute
208   * @DIAG_TX_STATUS_FAIL: Indicates frame is not sent over the air.
209   * @DIAG_TX_STATUS_NO_ACK: Indicates packet sent but acknowledgment
210   * is not received.
211   * @DIAG_TX_STATUS_ACK: Indicates the frame is successfully sent and
212   * acknowledged.
213   */
214  enum diag_tx_status {
215  	DIAG_TX_STATUS_FAIL = 1,
216  	DIAG_TX_STATUS_NO_ACK = 2,
217  	DIAG_TX_STATUS_ACK = 3
218  };
219  
220  /**
221   * wlan_get_diag_tx_status() - Gives the diag logging specific tx status
222   * @tx_status: fw specific TX status
223   *
224   * Returns TX status specified in enum diag_tx_status
225   */
226  enum diag_tx_status wlan_get_diag_tx_status(enum qdf_dp_tx_rx_status tx_status);
227  #endif
228  
229  #define CASE_RETURN_STRING(str) case ((str)): return (uint8_t *)(# str);
230  
231  #ifndef MAX_QDF_DP_TRACE_RECORDS
232  #define MAX_QDF_DP_TRACE_RECORDS       2000
233  #endif
234  
235  #define QDF_DP_TRACE_RECORD_SIZE       66 /* bytes */
236  #define INVALID_QDF_DP_TRACE_ADDR      0xffffffff
237  #define QDF_DP_TRACE_VERBOSITY_HIGH		4
238  #define QDF_DP_TRACE_VERBOSITY_MEDIUM		3
239  #define QDF_DP_TRACE_VERBOSITY_LOW		2
240  #define QDF_DP_TRACE_VERBOSITY_ULTRA_LOW	1
241  #define QDF_DP_TRACE_VERBOSITY_BASE		0
242  
243  /**
244   * enum QDF_DP_TRACE_ID - Generic ID to identify various events in data path
245   * @QDF_DP_TRACE_INVALID: invalid
246   * @QDF_DP_TRACE_DROP_PACKET_RECORD: record drop packet
247   * @QDF_DP_TRACE_EAPOL_PACKET_RECORD: record EAPOL packet
248   * @QDF_DP_TRACE_DHCP_PACKET_RECORD: record DHCP packet
249   * @QDF_DP_TRACE_ARP_PACKET_RECORD: record ARP packet
250   * @QDF_DP_TRACE_MGMT_PACKET_RECORD: record MGMT pacekt
251   * @QDF_DP_TRACE_EVENT_RECORD: record events
252   * @QDF_DP_TRACE_BASE_VERBOSITY: below this are part of base verbosity
253   * @QDF_DP_TRACE_ICMP_PACKET_RECORD: record ICMP packet
254   * @QDF_DP_TRACE_ICMPv6_PACKET_RECORD: record ICMPv6 packet
255   * @QDF_DP_TRACE_HDD_TX_TIMEOUT: HDD tx timeout
256   * @QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT: SOFTAP HDD tx timeout
257   * @QDF_DP_TRACE_TX_CREDIT_RECORD: credit update record
258   * @QDF_DP_TRACE_ULTRA_LOW_VERBOSITY: Below this is not logged for >4PPS
259   * @QDF_DP_TRACE_TX_PACKET_RECORD: record 32 bytes of tx pkt at any layer
260   * @QDF_DP_TRACE_RX_PACKET_RECORD: record 32 bytes of rx pkt at any layer
261   * @QDF_DP_TRACE_HDD_TX_PACKET_RECORD: record 32 bytes of tx pkt at HDD
262   * @QDF_DP_TRACE_HDD_RX_PACKET_RECORD: record 32 bytes of rx pkt at HDD
263   * @QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD: record data bytes of tx pkt at LI_DP
264   * @QDF_DP_TRACE_LI_DP_RX_PACKET_RECORD: record data bytes of rx pkt at LI_DP
265   * @QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD: tx completion ptr record for
266   *						lithium
267   * @QDF_DP_TRACE_FREE_PACKET_PTR_RECORD: tx completion ptr record
268   * @QDF_DP_TRACE_LOW_VERBOSITY: below this are part of low verbosity
269   * @QDF_DP_TRACE_HDD_TX_PACKET_PTR_RECORD: HDD layer ptr record
270   * @QDF_DP_TRACE_TX_PACKET_PTR_RECORD: DP component Tx ptr record
271   * @QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD: Lithium DP layer ptr record
272   * @QDF_DP_TRACE_RX_PACKET_PTR_RECORD: DP component Rx ptr record
273   * @QDF_DP_TRACE_RX_HDD_PACKET_PTR_RECORD: HDD RX record
274   * @QDF_DP_TRACE_CE_PACKET_PTR_RECORD: CE layer ptr record
275   * @QDF_DP_TRACE_CE_FAST_PACKET_PTR_RECORD: CE fastpath ptr record
276   * @QDF_DP_TRACE_CE_FAST_PACKET_ERR_RECORD: CE fastpath error record
277   * @QDF_DP_TRACE_RX_HTT_PACKET_PTR_RECORD: HTT RX record
278   * @QDF_DP_TRACE_RX_OFFLOAD_HTT_PACKET_PTR_RECORD: HTT RX offload record
279   * @QDF_DP_TRACE_RX_LI_DP_PACKET_PTR_RECORD: Lithium DP RX record
280   * @QDF_DP_TRACE_MED_VERBOSITY: below this are part of med verbosity
281   * @QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD: tx queue ptr record
282   * @QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD: txrx packet ptr record
283   * @QDF_DP_TRACE_TXRX_FAST_PACKET_PTR_RECORD: txrx fast path record
284   * @QDF_DP_TRACE_HTT_PACKET_PTR_RECORD: htt packet ptr record
285   * @QDF_DP_TRACE_HTC_PACKET_PTR_RECORD: htc packet ptr record
286   * @QDF_DP_TRACE_HIF_PACKET_PTR_RECORD: hif packet ptr record
287   * @QDF_DP_TRACE_RX_TXRX_PACKET_PTR_RECORD: txrx packet ptr record
288   * @QDF_DP_TRACE_LI_DP_NULL_RX_PACKET_RECORD:
289   *		record data bytes of rx null_queue pkt at LI_DP
290   * @QDF_DP_TRACE_HIGH_VERBOSITY: below this are part of high verbosity
291   * @QDF_DP_TRACE_MAX: Max enumeration
292   */
293  
294  enum  QDF_DP_TRACE_ID {
295  	QDF_DP_TRACE_INVALID,
296  	QDF_DP_TRACE_DROP_PACKET_RECORD,
297  	QDF_DP_TRACE_EAPOL_PACKET_RECORD,
298  	QDF_DP_TRACE_DHCP_PACKET_RECORD,
299  	QDF_DP_TRACE_ARP_PACKET_RECORD,
300  	QDF_DP_TRACE_MGMT_PACKET_RECORD,
301  	QDF_DP_TRACE_EVENT_RECORD,
302  	QDF_DP_TRACE_BASE_VERBOSITY,
303  	QDF_DP_TRACE_ICMP_PACKET_RECORD,
304  	QDF_DP_TRACE_ICMPv6_PACKET_RECORD,
305  	QDF_DP_TRACE_HDD_TX_TIMEOUT,
306  	QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT,
307  	QDF_DP_TRACE_TX_CREDIT_RECORD,
308  	QDF_DP_TRACE_ULTRA_LOW_VERBOSITY,
309  	QDF_DP_TRACE_TX_PACKET_RECORD,
310  	QDF_DP_TRACE_RX_PACKET_RECORD,
311  	QDF_DP_TRACE_HDD_TX_PACKET_RECORD,
312  	QDF_DP_TRACE_HDD_RX_PACKET_RECORD,
313  	QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD,
314  	QDF_DP_TRACE_LI_DP_RX_PACKET_RECORD,
315  	QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD,
316  	QDF_DP_TRACE_FREE_PACKET_PTR_RECORD,
317  	QDF_DP_TRACE_LOW_VERBOSITY,
318  	QDF_DP_TRACE_HDD_TX_PACKET_PTR_RECORD,
319  	QDF_DP_TRACE_TX_PACKET_PTR_RECORD,
320  	QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD,
321  	QDF_DP_TRACE_RX_PACKET_PTR_RECORD,
322  	QDF_DP_TRACE_RX_HDD_PACKET_PTR_RECORD,
323  	QDF_DP_TRACE_CE_PACKET_PTR_RECORD,
324  	QDF_DP_TRACE_CE_FAST_PACKET_PTR_RECORD,
325  	QDF_DP_TRACE_CE_FAST_PACKET_ERR_RECORD,
326  	QDF_DP_TRACE_RX_HTT_PACKET_PTR_RECORD,
327  	QDF_DP_TRACE_RX_OFFLOAD_HTT_PACKET_PTR_RECORD,
328  	QDF_DP_TRACE_RX_LI_DP_PACKET_PTR_RECORD,
329  	QDF_DP_TRACE_MED_VERBOSITY,
330  	QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD,
331  	QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD,
332  	QDF_DP_TRACE_TXRX_FAST_PACKET_PTR_RECORD,
333  	QDF_DP_TRACE_HTT_PACKET_PTR_RECORD,
334  	QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
335  	QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
336  	QDF_DP_TRACE_RX_TXRX_PACKET_PTR_RECORD,
337  	QDF_DP_TRACE_LI_DP_NULL_RX_PACKET_RECORD,
338  	QDF_DP_TRACE_HIGH_VERBOSITY,
339  	QDF_DP_TRACE_MAX
340  };
341  
342  /**
343   * enum qdf_proto_dir - direction
344   * @QDF_TX: TX direction
345   * @QDF_RX: RX direction
346   * @QDF_NA: not applicable
347   */
348  enum qdf_proto_dir {
349  	QDF_TX,
350  	QDF_RX,
351  	QDF_NA
352  };
353  
354  /**
355   * enum QDF_CREDIT_UPDATE_SOURCE - source of credit record
356   * @QDF_TX_SCHED: Tx scheduler
357   * @QDF_TX_COMP: TX completion
358   * @QDF_TX_CREDIT_UPDATE: credit update indication
359   * @QDF_HTT_ATTACH: HTT attach
360   * @QDF_TX_HTT_MSG: HTT TX message
361   */
362  enum QDF_CREDIT_UPDATE_SOURCE {
363  	QDF_TX_SCHED,
364  	QDF_TX_COMP,
365  	QDF_TX_CREDIT_UPDATE,
366  	QDF_HTT_ATTACH,
367  	QDF_TX_HTT_MSG
368  };
369  
370  /**
371   * enum QDF_CREDIT_OPERATION - operation on credit
372   * @QDF_CREDIT_INC: credit increment
373   * @QDF_CREDIT_DEC: credit decrement
374   * @QDF_CREDIT_ABS: Abosolute credit
375   * @QDF_OP_NA: Not applicable
376   */
377  enum QDF_CREDIT_OPERATION {
378  	QDF_CREDIT_INC,
379  	QDF_CREDIT_DEC,
380  	QDF_CREDIT_ABS,
381  	QDF_OP_NA
382  };
383  
384  /**
385   * struct qdf_dp_trace_ptr_buf - pointer record buffer
386   * @cookie: cookie value
387   * @msdu_id: msdu_id
388   * @status: completion status
389   */
390  struct qdf_dp_trace_ptr_buf {
391  	uint64_t cookie;
392  	uint16_t msdu_id;
393  	uint16_t status;
394  };
395  
396  /**
397   * struct qdf_dp_trace_proto_cmn - common info in proto packet
398   * @vdev_id: vdev id
399   * @type: packet type
400   * @subtype: packet subtype
401   * @proto_priv_data: protocol private data
402   * can be stored in this.
403   * @mpdu_seq: 802.11 MPDU sequence number
404   */
405  struct qdf_dp_trace_proto_cmn {
406  	uint8_t vdev_id;
407  	uint8_t type;
408  	uint8_t subtype;
409  	uint32_t proto_priv_data;
410  	uint16_t mpdu_seq;
411  };
412  
413  /**
414   * struct qdf_dp_trace_proto_buf - proto packet buffer
415   * @sa: source address
416   * @da: destination address
417   * @dir: direction
418   * @cmn_info: common info
419   */
420  struct qdf_dp_trace_proto_buf {
421  	struct qdf_mac_addr sa;
422  	struct qdf_mac_addr da;
423  	uint8_t dir;
424  	struct qdf_dp_trace_proto_cmn cmn_info;
425  };
426  
427  /**
428   * struct qdf_dp_trace_mgmt_buf - mgmt packet buffer
429   * @vdev_id: vdev id
430   * @type: packet type
431   * @subtype: packet subtype
432   */
433  struct qdf_dp_trace_mgmt_buf {
434  	uint8_t vdev_id;
435  	uint8_t type;
436  	uint8_t subtype;
437  };
438  
439  /**
440   * struct qdf_dp_trace_credit_record - tx credit record
441   * @source: credit record source
442   * @operation: credit operation
443   * @delta: delta of credit
444   * @total_credits: total credit
445   * @g0_credit: group 0 credit
446   * @g1_credit: group 1 credit
447   */
448  struct qdf_dp_trace_credit_record {
449  	enum QDF_CREDIT_UPDATE_SOURCE source;
450  	enum QDF_CREDIT_OPERATION operation;
451  	int delta;
452  	int total_credits;
453  	int g0_credit;
454  	int g1_credit;
455  };
456  
457  /**
458   * struct qdf_dp_trace_event_buf - event buffer
459   * @vdev_id: vdev id
460   * @type: packet type
461   * @subtype: packet subtype
462   */
463  struct qdf_dp_trace_event_buf {
464  	uint8_t vdev_id;
465  	uint8_t type;
466  	uint8_t subtype;
467  };
468  
469  /**
470   * struct qdf_dp_trace_data_buf - nbuf data buffer
471   * @msdu_id: msdu id
472   */
473  struct qdf_dp_trace_data_buf {
474  	uint16_t msdu_id;
475  };
476  
477  /**
478   * struct qdf_dp_trace_record_s - Describes a record in DP trace
479   * @time: time when it got stored
480   * @code: Describes the particular event
481   * @data: buffer to store data
482   * @size: Length of the valid data stored in this record
483   * @pid: process id which stored the data in this record
484   * @pdev_id: pdev associated with the event
485   */
486  struct qdf_dp_trace_record_s {
487  	uint64_t time;
488  	uint8_t code;
489  	uint8_t data[QDF_DP_TRACE_RECORD_SIZE];
490  	uint8_t size;
491  	uint32_t pid;
492  	uint8_t pdev_id;
493  };
494  
495  /**
496   * struct s_qdf_dp_trace_data - Parameters to configure/control DP trace
497   * @head: Position of first record
498   * @tail: Position of last record
499   * @num:  Current index
500   * @proto_bitmap: defines which protocol to be traced
501   * @no_of_record: defines every nth packet to be traced
502   * @num_records_to_dump: defines number of records to be dumped
503   * @dump_counter: counter to track number of records dumped
504   * @verbosity: defines verbosity level
505   * @ini_conf_verbosity: Configured verbosity from INI
506   * @enable: enable/disable DP trace
507   * @count: current packet number
508   * @live_mode_config: configuration as received during initialization
509   * @live_mode: current live mode, enabled or disabled, can be throttled based
510   *             on throughput
511   * @curr_pos:
512   * @saved_tail:
513   * @force_live_mode: flag to enable live mode all the time for all packets.
514   *                  This can be set/unset from userspace and overrides other
515   *                  live mode flags.
516   * @dynamic_verbosity_modify: Dynamic user configured verbosity overrides all
517   * @print_pkt_cnt: count of number of packets printed in live mode
518   * @high_tput_thresh: thresh beyond which live mode is turned off
519   * @thresh_time_limit: max time, in terms of BW timer intervals to wait,
520   *          for determining if high_tput_thresh has been crossed. ~1s
521   * @tx_count: tx counter
522   * @rx_count: rx counter
523   * @arp_req: stats for arp reqs
524   * @arp_resp: stats for arp resps
525   * @icmp_req: stats for icmp reqs
526   * @icmp_resp: stats for icmp resps
527   * @dhcp_disc: stats for dhcp discover msgs
528   * @dhcp_req: stats for dhcp req msgs
529   * @dhcp_off: stats for dhcp offer msgs
530   * @dhcp_ack: stats for dhcp ack msgs
531   * @dhcp_nack: stats for dhcp nack msgs
532   * @dhcp_others: stats for other dhcp pkts types
533   * @eapol_m1: stats for eapol m1
534   * @eapol_m2: stats for eapol m2
535   * @eapol_m3: stats for eapol m3
536   * @eapol_m4: stats for eapol m4
537   * @eapol_others: stats for other eapol pkt types
538   * @icmpv6_req: stats for icmpv6 reqs
539   * @icmpv6_resp: stats for icmpv6 resps
540   * @icmpv6_ns: stats for icmpv6 nss
541   * @icmpv6_na: stats for icmpv6 nas
542   * @icmpv6_rs: stats for icmpv6 rss
543   * @icmpv6_ra: stats for icmpv6 ras
544   * @proto_event_bitmap: defines which protocol to be diag logged.
545   *  refer QDF_NBUF_PKT_TRAC_TYPE_DNS to QDF_NBUF_PKT_TRAC_TYPE_ARP
546   *  for bitmap.
547   */
548  struct s_qdf_dp_trace_data {
549  	uint32_t head;
550  	uint32_t tail;
551  	uint32_t num;
552  	uint32_t proto_bitmap;
553  	uint8_t no_of_record;
554  	uint16_t num_records_to_dump;
555  	uint16_t dump_counter;
556  	uint8_t verbosity;
557  	uint8_t ini_conf_verbosity;
558  	bool enable;
559  	bool live_mode_config;
560  	bool live_mode;
561  	uint32_t curr_pos;
562  	uint32_t saved_tail;
563  	bool force_live_mode;
564  	bool dynamic_verbosity_modify;
565  	uint8_t print_pkt_cnt;
566  	uint8_t high_tput_thresh;
567  	uint16_t thresh_time_limit;
568  	/* Stats */
569  	uint32_t tx_count;
570  	uint32_t rx_count;
571  	u16 arp_req;
572  	u16 arp_resp;
573  	u16 dhcp_disc;
574  	u16 dhcp_req;
575  	u16 dhcp_off;
576  	u16 dhcp_ack;
577  	u16 dhcp_nack;
578  	u16 dhcp_others;
579  	u16 eapol_m1;
580  	u16 eapol_m2;
581  	u16 eapol_m3;
582  	u16 eapol_m4;
583  	u16 eapol_others;
584  	u16 icmp_req;
585  	u16 icmp_resp;
586  	u16 icmpv6_req;
587  	u16 icmpv6_resp;
588  	u16 icmpv6_ns;
589  	u16 icmpv6_na;
590  	u16 icmpv6_rs;
591  	u16 icmpv6_ra;
592  	uint32_t proto_event_bitmap;
593  };
594  
595  /**
596   * enum qdf_dpt_debugfs_state - state to control read to debugfs file
597   * @QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INVALID: invalid state
598   * @QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INIT: initial state
599   * @QDF_DPT_DEBUGFS_STATE_SHOW_IN_PROGRESS: read is in progress
600   * @QDF_DPT_DEBUGFS_STATE_SHOW_COMPLETE:  read complete
601   */
602  
603  enum qdf_dpt_debugfs_state {
604  	QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INVALID,
605  	QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INIT,
606  	QDF_DPT_DEBUGFS_STATE_SHOW_IN_PROGRESS,
607  	QDF_DPT_DEBUGFS_STATE_SHOW_COMPLETE,
608  };
609  
610  #define QDF_WIFI_MODULE_PARAMS_FILE "wifi_module_param.ini"
611  
612  typedef void (*tp_qdf_trace_cb)(void *p_mac, tp_qdf_trace_record, uint16_t);
613  typedef void (*tp_qdf_state_info_cb) (char **buf, uint16_t *size);
614  #ifdef WLAN_FEATURE_MEMDUMP_ENABLE
615  
616  /**
617   * qdf_register_debugcb_init() - initializes debug callbacks
618   * to NULL
619   *
620   * Return: None
621   */
622  void qdf_register_debugcb_init(void);
623  
624  /**
625   * qdf_register_debug_callback() - stores callback handlers to print
626   * state information
627   * @module_id: module id of layer
628   * @qdf_state_infocb: callback to be registered
629   *
630   * This function is used to store callback handlers to print
631   * state information
632   *
633   * Return: None
634   */
635  void qdf_register_debug_callback(QDF_MODULE_ID module_id,
636  					tp_qdf_state_info_cb qdf_state_infocb);
637  
638  /**
639   * qdf_state_info_dump_all() - it invokes callback of layer which registered
640   * its callback to print its state information.
641   * @buf:  buffer pointer to be passed
642   * @size:  size of buffer to be filled
643   * @driver_dump_size: actual size of buffer used
644   *
645   * Return: QDF_STATUS_SUCCESS on success
646   */
647  QDF_STATUS qdf_state_info_dump_all(char *buf, uint16_t size,
648  				   uint16_t *driver_dump_size);
649  #else /* WLAN_FEATURE_MEMDUMP_ENABLE */
qdf_register_debugcb_init(void)650  static inline void qdf_register_debugcb_init(void)
651  {
652  }
653  #endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
654  
655  #ifdef TRACE_RECORD
656  /**
657   * qdf_trace_register() - registers the call back functions
658   * @module_id: enum value of module
659   * @qdf_trace_callback: call back functions to display the messages in
660   * particular format.
661   *
662   * Registers the call back functions to display the messages in particular
663   * format mentioned in these call back functions. This functions should be
664   * called by interested module in their init part as we will be ready to
665   * register as soon as modules are up.
666   *
667   * Return: None
668   */
669  void qdf_trace_register(QDF_MODULE_ID module_id,
670  			tp_qdf_trace_cb qdf_trace_callback);
671  
672  /**
673   * qdf_trace_init() - initializes qdf trace structures and variables
674   *
675   * Called immediately after cds_preopen, so that we can start recording HDD
676   * events ASAP.
677   *
678   * Return: None
679   */
680  void qdf_trace_init(void);
681  
682  /**
683   * qdf_trace_deinit() - frees memory allocated dynamically
684   *
685   * Called from cds_deinit, so that we can free the memory and resets
686   * the variables
687   *
688   * Return: None
689   */
690  void qdf_trace_deinit(void);
691  
692  /**
693   * qdf_trace() - puts the messages in to ring-buffer
694   * @module: Enum of module, basically module id.
695   * @code: Code to be recorded
696   * @session: Session ID of the log
697   * @data: Actual message contents
698   *
699   * This function will be called from each module who wants record the messages
700   * in circular queue. Before calling this functions make sure you have
701   * registered your module with qdf through qdf_trace_register function.
702   *
703   * Return: None
704   */
705  void qdf_trace(uint8_t module, uint16_t code, uint16_t session, uint32_t data);
706  
707  /**
708   * qdf_trace_enable() - Enable MTRACE for specific modules
709   * @bitmask_of_module_id: Bitmask according to enum of the modules.
710   *  32[dec] = 0010 0000 [bin] <enum of HDD is 5>
711   *  64[dec] = 0100 0000 [bin] <enum of SME is 6>
712   *  128[dec] = 1000 0000 [bin] <enum of PE is 7>
713   * @enable: can be true or false true implies enabling MTRACE false implies
714   *		disabling MTRACE.
715   *
716   * Enable MTRACE for specific modules whose bits are set in bitmask and enable
717   * is true. if enable is false it disables MTRACE for that module. set the
718   * bitmask according to enum value of the modules.
719   * This functions will be called when you issue ioctl as mentioned following
720   * [iwpriv wlan0 setdumplog <value> <enable>].
721   * <value> - Decimal number, i.e. 64 decimal value shows only SME module,
722   * 128 decimal value shows only PE module, 192 decimal value shows PE and SME.
723   *
724   * Return: None
725   */
726  void qdf_trace_enable(uint32_t bitmask_of_module_id, uint8_t enable);
727  
728  /**
729   * qdf_trace_dump_all() - Dump data from ring buffer via call back functions
730   * registered with QDF
731   * @p_mac: Context of particular module
732   * @code: Reason code
733   * @session: Session id of log
734   * @count: Number of lines to dump starting from tail to head
735   * @bitmask_of_module: Bitmask according to enum of the modules.
736   *
737   * This function will be called up on issuing ioctl call as mentioned following
738   * [iwpriv wlan0 dumplog 0 0 <n> <bitmask_of_module>]
739   *
740   * <n> - number lines to dump starting from tail to head.
741   *
742   * <bitmask_of_module> - if anybody wants to know how many messages were
743   * recorded for particular module/s mentioned by setbit in bitmask from last
744   * <n> messages. It is optional, if you don't provide then it will dump
745   * everything from buffer.
746   *
747   * Return: None
748   */
749  void qdf_trace_dump_all(void *p_mac, uint8_t code, uint8_t session,
750  			uint32_t count, uint32_t bitmask_of_module);
751  
752  /**
753   * qdf_trace_spin_lock_init() - initializes the lock variable before use
754   *
755   * This function will be called from cds_alloc_global_context, we will have lock
756   * available to use ASAP
757   *
758   * Return: None
759   */
760  QDF_STATUS qdf_trace_spin_lock_init(void);
761  #else
762  #ifndef QDF_TRACE_PRINT_ENABLE
763  static inline
qdf_trace_init(void)764  void qdf_trace_init(void)
765  {
766  }
767  
768  static inline
qdf_trace_deinit(void)769  void qdf_trace_deinit(void)
770  {
771  }
772  
773  static inline
qdf_trace_enable(uint32_t bitmask_of_module_id,uint8_t enable)774  void qdf_trace_enable(uint32_t bitmask_of_module_id, uint8_t enable)
775  {
776  }
777  
778  static inline
qdf_trace(uint8_t module,uint16_t code,uint16_t session,uint32_t data)779  void qdf_trace(uint8_t module, uint16_t code, uint16_t session, uint32_t data)
780  {
781  }
782  
783  static inline
qdf_trace_dump_all(void * p_mac,uint8_t code,uint8_t session,uint32_t count,uint32_t bitmask_of_module)784  void qdf_trace_dump_all(void *p_mac, uint8_t code, uint8_t session,
785  			uint32_t count, uint32_t bitmask_of_module)
786  {
787  }
788  
789  static inline
qdf_trace_spin_lock_init(void)790  QDF_STATUS qdf_trace_spin_lock_init(void)
791  {
792  	return QDF_STATUS_SUCCESS;
793  }
794  #endif
795  #endif
796  
797  #ifdef WLAN_MAX_LOGS_PER_SEC
798  /**
799   * qdf_detected_excessive_logging() - Excessive logging detected
800   *
801   * Track logging count using a quasi-tumbling window.
802   * If the max logging count for a given window is exceeded,
803   * return true else fails.
804   *
805   * Return: true/false
806   */
807  bool qdf_detected_excessive_logging(void);
808  
809  /**
810   * qdf_rl_print_count_set() - set the ratelimiting print count
811   * @rl_print_count: ratelimiting print count
812   *
813   * Return: none
814   */
815  void qdf_rl_print_count_set(uint32_t rl_print_count);
816  
817  /**
818   * qdf_rl_print_time_set() - set the ratelimiting print time
819   * @rl_print_time: ratelimiting print time
820   *
821   * Return: none
822   */
823  void qdf_rl_print_time_set(uint32_t rl_print_time);
824  
825  /**
826   * qdf_rl_print_suppressed_log() - print the suppressed logs count
827   *
828   * Return: none
829   */
830  void qdf_rl_print_suppressed_log(void);
831  
832  /**
833   * qdf_rl_print_suppressed_inc() - increment the suppressed logs count
834   *
835   * Return: none
836   */
837  void qdf_rl_print_suppressed_inc(void);
838  
839  #else /* WLAN_MAX_LOGS_PER_SEC */
qdf_detected_excessive_logging(void)840  static inline bool qdf_detected_excessive_logging(void)
841  {
842  	return false;
843  }
qdf_rl_print_count_set(uint32_t rl_print_count)844  static inline void qdf_rl_print_count_set(uint32_t rl_print_count) {}
qdf_rl_print_time_set(uint32_t rl_print_time)845  static inline void qdf_rl_print_time_set(uint32_t rl_print_time) {}
qdf_rl_print_suppressed_log(void)846  static inline void qdf_rl_print_suppressed_log(void) {}
qdf_rl_print_suppressed_inc(void)847  static inline void qdf_rl_print_suppressed_inc(void) {}
848  #endif /* WLAN_MAX_LOGS_PER_SEC */
849  
850  #ifdef ENABLE_MTRACE_LOG
851  /**
852   * qdf_mtrace_log() - Logs a message tracepoint to DIAG
853   * Infrastructure.
854   * @src_module: Enum of source module (basically module id)
855   * from where the message with message_id is posted.
856   * @dst_module: Enum of destination module (basically module id)
857   * to which the message with message_id is posted.
858   * @message_id: Id of the message to be posted
859   * @vdev_id: Vdev Id
860   *
861   * This function logs to the DIAG Infrastructure a tracepoint for a
862   * message being sent from a source module to a destination module
863   * with a specific ID for the benefit of a specific vdev.
864   * For non-vdev messages vdev_id will be NO_SESSION
865   * Return: None
866   */
867  void qdf_mtrace_log(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
868  		    uint16_t message_id, uint8_t vdev_id);
869  #else
870  static inline
qdf_mtrace_log(QDF_MODULE_ID src_module,QDF_MODULE_ID dst_module,uint16_t message_id,uint8_t vdev_id)871  void qdf_mtrace_log(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
872  		    uint16_t message_id, uint8_t vdev_id)
873  {
874  }
875  #endif
876  
877  #ifdef TRACE_RECORD
878  /**
879   * qdf_mtrace() - puts the messages in to ring-buffer
880   * and logs a message tracepoint to DIAG Infrastructure.
881   * @src_module: Enum of source module (basically module id)
882   * from where the message with message_id is posted.
883   * @dst_module: Enum of destination module (basically module id)
884   * to which the message with message_id is posted.
885   * @message_id: Id of the message to be posted
886   * @vdev_id: Vdev Id
887   * @data: Actual message contents
888   *
889   * This function will be called from each module which wants to record the
890   * messages in circular queue. Before calling this function make sure you
891   * have registered your module with qdf through qdf_trace_register function.
892   * In addition of the recording the messages in circular queue this function
893   * will log the message tracepoint to the  DIAG infrastructure.
894   * these logs will be later used by post processing script.
895   *
896   * Return: None
897   */
898  void qdf_mtrace(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
899  		uint16_t message_id, uint8_t vdev_id, uint32_t data);
900  #else
901  static inline
qdf_mtrace(QDF_MODULE_ID src_module,QDF_MODULE_ID dst_module,uint16_t message_id,uint8_t vdev_id,uint32_t data)902  void qdf_mtrace(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
903  		uint16_t message_id, uint8_t vdev_id, uint32_t data)
904  {
905  }
906  #endif
907  
908  #ifdef CONFIG_DP_TRACE
909  /**
910   * qdf_dp_set_proto_bitmap() - set dp trace proto bitmap
911   * @val: unsigned bitmap to set
912   *
913   * Return: proto bitmap
914   */
915  void qdf_dp_set_proto_bitmap(uint32_t val);
916  
917  /**
918   * qdf_dp_trace_set_verbosity() - set verbosity value
919   * @val: Value to set
920   *
921   * Return: Null
922   */
923  void qdf_dp_trace_set_verbosity(uint32_t val);
924  
925  /**
926   * qdf_dp_set_no_of_record() - set dp trace no_of_record
927   * @val: unsigned no_of_record to set
928   *
929   * Return: null
930   */
931  void qdf_dp_set_no_of_record(uint32_t val);
932  
933  #define QDF_DP_TRACE_RECORD_INFO_LIVE (0x1)
934  #define QDF_DP_TRACE_RECORD_INFO_THROTTLED (0x1 << 1)
935  
936  /**
937   * qdf_dp_trace_log_pkt() - log packet type enabled through iwpriv
938   * @vdev_id: vdev_id
939   * @skb: skb pointer
940   * @dir: direction
941   * @pdev_id: pdev_id
942   * @op_mode: Vdev Operation mode
943   *
944   * Return: true: some protocol was logged, false: no protocol was logged.
945   */
946  bool qdf_dp_trace_log_pkt(uint8_t vdev_id, struct sk_buff *skb,
947  			  enum qdf_proto_dir dir, uint8_t pdev_id,
948  			  enum QDF_OPMODE op_mode);
949  
950  /**
951   * qdf_dp_trace_init() - enables the DP trace
952   * @live_mode_config: live mode configuration
953   * @thresh: high throughput threshold for disabling live mode
954   * @time_limit: max time to wait before deciding if thresh is crossed
955   * @verbosity: dptrace verbosity level
956   * @proto_bitmap: bitmap to enable/disable specific protocols
957   *
958   * Called during driver load to init dptrace
959   *
960   * A brief note on the 'thresh' param -
961   * Total # of packets received in a bandwidth timer interval beyond which
962   * DP Trace logging for data packets (including ICMP) will be disabled.
963   * In memory logging will still continue for these packets. Other packets for
964   * which proto.bitmap is set will continue to be recorded in logs and in memory.
965   *
966   * Return: None
967   */
968  void qdf_dp_trace_init(bool live_mode_config, uint8_t thresh,
969  		       uint16_t time_limit, uint8_t verbosity,
970  		       uint32_t proto_bitmap);
971  
972  void qdf_dp_trace_deinit(void);
973  
974  /**
975   * qdf_dp_trace_spin_lock_init() - initializes the lock variable before use
976   * This function will be called from cds_alloc_global_context, we will have lock
977   * available to use ASAP
978   *
979   * Return: None
980   */
981  void qdf_dp_trace_spin_lock_init(void);
982  
983  /**
984   * qdf_dp_trace_set_value() - Configure the value to control DP trace
985   * @proto_bitmap: defines the protocol to be tracked
986   * @no_of_records: defines the nth packet which is traced
987   * @verbosity: defines the verbosity level
988   *
989   * Return: None
990   */
991  void qdf_dp_trace_set_value(uint32_t proto_bitmap, uint8_t no_of_records,
992  			    uint8_t verbosity);
993  
994  /**
995   * qdf_dp_trace_set_track() - Marks whether the packet needs to be traced
996   * @nbuf: defines the netbuf
997   * @dir: direction
998   *
999   * Return: None
1000   */
1001  void qdf_dp_trace_set_track(qdf_nbuf_t nbuf, enum qdf_proto_dir dir);
1002  
1003  /**
1004   * qdf_dp_trace() - Stores the data in buffer
1005   * @nbuf: defines the netbuf
1006   * @code: defines the event
1007   * @pdev_id: pdev_id
1008   * @data: defines the data to be stored
1009   * @size: defines the size of the data record
1010   * @dir: direction
1011   *
1012   * Return: None
1013   */
1014  void qdf_dp_trace(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code, uint8_t pdev_id,
1015  		  uint8_t *data, uint8_t size, enum qdf_proto_dir dir);
1016  
1017  /**
1018   * qdf_dp_trace_dump_all() - Dump data from ring buffer via call back functions
1019   * registered with QDF
1020   * @count: Number of lines to dump starting from tail to head
1021   * @pdev_id: pdev_id
1022   *
1023   * Return: None
1024   */
1025  void qdf_dp_trace_dump_all(uint32_t count, uint8_t pdev_id);
1026  
1027  /**
1028   * qdf_dpt_get_curr_pos_debugfs() - get curr position to start read
1029   * @file: debugfs file to read
1030   * @state: state to control read to debugfs file
1031   *
1032   * Return: curr pos
1033   */
1034  uint32_t qdf_dpt_get_curr_pos_debugfs(qdf_debugfs_file_t file,
1035  				enum qdf_dpt_debugfs_state state);
1036  /**
1037   * qdf_dpt_dump_stats_debugfs() - dump DP Trace stats to debugfs file
1038   * @file: debugfs file to read
1039   * @curr_pos: curr position to start read
1040   *
1041   * Return: QDF_STATUS
1042   */
1043  QDF_STATUS qdf_dpt_dump_stats_debugfs(qdf_debugfs_file_t file,
1044  				      uint32_t curr_pos);
1045  
1046  /**
1047   * qdf_dpt_set_value_debugfs() - set value of DP Trace debugfs params
1048   * @proto_bitmap: defines which protocol to be traced
1049   * @no_of_record: defines every nth packet to be traced
1050   * @verbosity: defines verbosity level
1051   * @num_records_to_dump: defines number of records to be dumped
1052   *
1053   * Return: none
1054   */
1055  void qdf_dpt_set_value_debugfs(uint8_t proto_bitmap, uint8_t no_of_record,
1056  			    uint8_t verbosity, uint16_t num_records_to_dump);
1057  
1058  
1059  /**
1060   * qdf_dp_trace_dump_stats() - dump DP Trace stats
1061   *
1062   * Return: none
1063   */
1064  void qdf_dp_trace_dump_stats(void);
1065  typedef void (*tp_qdf_dp_trace_cb)(struct qdf_dp_trace_record_s*,
1066  				   uint16_t, uint8_t, uint8_t info);
1067  /**
1068   * qdf_dp_display_record() - Displays a record in DP trace
1069   * @record: pointer to a record in DP trace
1070   * @index: record index
1071   * @pdev_id: pdev id for the mgmt pkt
1072   * @info: info used to display pkt (live mode, throttling)
1073   *
1074   * Return: None
1075   */
1076  void qdf_dp_display_record(struct qdf_dp_trace_record_s *record,
1077  			   uint16_t index, uint8_t pdev_id,
1078  			   uint8_t info);
1079  
1080  /**
1081   * qdf_dp_display_ptr_record() - display record
1082   * @record: dptrace record
1083   * @rec_index: index
1084   * @pdev_id: pdev id for the mgmt pkt
1085   * @info: info used to display pkt (live mode, throttling)
1086   *
1087   * Return: none
1088   */
1089  void qdf_dp_display_ptr_record(struct qdf_dp_trace_record_s *record,
1090  			       uint16_t rec_index, uint8_t pdev_id,
1091  			       uint8_t info);
1092  
1093  /**
1094   * qdf_dp_display_proto_pkt() - display proto packet
1095   * @record: dptrace record
1096   * @index: index
1097   * @pdev_id: pdev id for the mgmt pkt
1098   * @info: info used to display pkt (live mode, throttling)
1099   *
1100   * Return: none
1101   */
1102  void qdf_dp_display_proto_pkt(struct qdf_dp_trace_record_s *record,
1103  			      uint16_t index, uint8_t pdev_id,
1104  			      uint8_t info);
1105  /**
1106   * qdf_dp_display_data_pkt_record() - Displays a data packet in DP trace
1107   * @record: pointer to a record in DP trace
1108   * @rec_index: record index
1109   * @pdev_id: pdev id
1110   * @info: display info regarding record
1111   *
1112   * Return: None
1113   */
1114  void
1115  qdf_dp_display_data_pkt_record(struct qdf_dp_trace_record_s *record,
1116  			       uint16_t rec_index, uint8_t pdev_id,
1117  			       uint8_t info);
1118  
1119  /**
1120   * qdf_dp_get_status_from_htt() - Convert htt tx status to qdf dp status
1121   * @status: htt_tx_status which needs to be converted
1122   *
1123   * Return: the status that from qdf_dp_tx_rx_status
1124   */
1125  enum qdf_dp_tx_rx_status qdf_dp_get_status_from_htt(uint8_t status);
1126  
1127  /**
1128   * qdf_dp_get_status_from_a_status() - Convert A_STATUS to qdf dp status
1129   * @status: A_STATUS which needs to be converted
1130   *
1131   * Return: the status that from qdf_dp_tx_rx_status
1132   */
1133  enum qdf_dp_tx_rx_status qdf_dp_get_status_from_a_status(uint8_t status);
1134  
1135  /**
1136   * qdf_dp_trace_ptr() - record dptrace
1137   * @nbuf: network buffer
1138   * @code: dptrace code
1139   * @pdev_id: pdev_id
1140   * @data: data
1141   * @size: size of data
1142   * @msdu_id: msdu_id
1143   * @buf_arg_status: return status
1144   * @qdf_tx_status: qdf tx rx status
1145   * @op_mode: Vdev Operation mode
1146   *
1147   * Return: none
1148   */
1149  void qdf_dp_trace_ptr(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code,
1150  		      uint8_t pdev_id, uint8_t *data, uint8_t size,
1151  		      uint16_t msdu_id, uint16_t buf_arg_status,
1152  		      enum qdf_dp_tx_rx_status qdf_tx_status,
1153  		      enum QDF_OPMODE op_mode);
1154  
1155  /**
1156   * qdf_dp_trace_throttle_live_mode() - Throttle DP Trace live mode
1157   * @high_bw_request: whether this is a high BW req or not
1158   *
1159   * The function tries to prevent excessive logging into the live buffer by
1160   * having an upper limit on number of packets that can be logged per second.
1161   *
1162   * The intention is to allow occasional pings and data packets and really low
1163   * throughput levels while suppressing bursts and higher throughput levels so
1164   * that we donot hog the live buffer.
1165   *
1166   * If the number of packets printed in a particular second exceeds the thresh,
1167   * disable printing in the next second.
1168   *
1169   * Return: None
1170   */
1171  void qdf_dp_trace_throttle_live_mode(bool high_bw_request);
1172  
1173  /**
1174   * qdf_dp_trace_apply_tput_policy() - Change verbosity based on the TPUT
1175   * @is_data_traffic: Is traffic more than low TPUT threashould
1176   *
1177   * Return: None
1178   */
1179  void qdf_dp_trace_apply_tput_policy(bool is_data_traffic);
1180  
1181  /**
1182   * qdf_dp_trace_data_pkt() - trace data packet
1183   * @nbuf: nbuf which needs to be traced
1184   * @pdev_id: pdev_id
1185   * @code: QDF_DP_TRACE_ID for the packet (TX or RX)
1186   * @msdu_id: tx desc id for the nbuf (Only applies to TX packets)
1187   * @dir: TX or RX packet direction
1188   *
1189   * Return: None
1190   */
1191  void qdf_dp_trace_data_pkt(qdf_nbuf_t nbuf, uint8_t pdev_id,
1192  			   enum QDF_DP_TRACE_ID code, uint16_t msdu_id,
1193  			   enum qdf_proto_dir dir);
1194  
1195  /**
1196   * qdf_dp_get_proto_bitmap() - get dp trace proto bitmap
1197   *
1198   * Return: proto bitmap
1199   */
1200  uint32_t qdf_dp_get_proto_bitmap(void);
1201  
1202  uint8_t qdf_dp_get_verbosity(void);
1203  
1204  /**
1205   * qdf_dp_get_no_of_record() - get dp trace no_of_record
1206   *
1207   * Return: number of records
1208   */
1209  uint8_t qdf_dp_get_no_of_record(void);
1210  
1211  /**
1212   * qdf_dp_trace_proto_pkt() - record proto packet
1213   * @code: dptrace code
1214   * @sa: source mac address
1215   * @da: destination mac address
1216   * @dir: direction
1217   * @pdev_id: pdev id
1218   * @print: to print this proto pkt or not
1219   * @cmn_info: common info for proto pkt
1220   *
1221   * Return: none
1222   */
1223  void
1224  qdf_dp_trace_proto_pkt(enum QDF_DP_TRACE_ID code,
1225  		       uint8_t *sa, uint8_t *da,
1226  		       enum qdf_proto_dir dir,
1227  		       uint8_t pdev_id, bool print,
1228  		       struct qdf_dp_trace_proto_cmn *cmn_info);
1229  
1230  /**
1231   * qdf_dp_trace_disable_live_mode() - disable live mode for dptrace
1232   *
1233   * Return: none
1234   */
1235  void qdf_dp_trace_disable_live_mode(void);
1236  
1237  /**
1238   * qdf_dp_trace_enable_live_mode() - enable live mode for dptrace
1239   *
1240   * Return: none
1241   */
1242  void qdf_dp_trace_enable_live_mode(void);
1243  
1244  /**
1245   * qdf_dp_trace_clear_buffer() - clear dp trace buffer
1246   *
1247   * Return: none
1248   */
1249  void qdf_dp_trace_clear_buffer(void);
1250  
1251  /**
1252   * qdf_dp_trace_mgmt_pkt() - record mgmt packet
1253   * @code: dptrace code
1254   * @vdev_id: vdev id
1255   * @pdev_id: pdev_id
1256   * @type: proto type
1257   * @subtype: proto subtype
1258   *
1259   * Return: none
1260   */
1261  void qdf_dp_trace_mgmt_pkt(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
1262  			   uint8_t pdev_id, enum qdf_proto_type type,
1263  			   enum qdf_proto_subtype subtype);
1264  
1265  /**
1266   * qdf_dp_trace_credit_record() - record credit update
1267   * @source: source of record
1268   * @operation: credit operation
1269   * @delta: credit delta
1270   * @total_credits: total credit
1271   * @g0_credit: group 0 credit
1272   * @g1_credit: group 1 credit
1273   */
1274  void qdf_dp_trace_credit_record(enum QDF_CREDIT_UPDATE_SOURCE source,
1275  				enum QDF_CREDIT_OPERATION operation,
1276  				int delta, int total_credits,
1277  				int g0_credit, int g1_credit);
1278  
1279  /**
1280   * qdf_dp_display_mgmt_pkt() - display proto packet
1281   * @record: dptrace record
1282   * @index: index
1283   * @pdev_id: pdev id for the mgmt pkt
1284   * @info: info used to display pkt (live mode, throttling)
1285   *
1286   * Return: none
1287   */
1288  void qdf_dp_display_mgmt_pkt(struct qdf_dp_trace_record_s *record,
1289  			     uint16_t index, uint8_t pdev_id, uint8_t info);
1290  
1291  /**
1292   * qdf_dp_display_credit_record() - display credit record
1293   * @record: dptrace record
1294   * @index: index
1295   * @pdev_id: pdev id
1296   * @info: metadeta info
1297   */
1298  void qdf_dp_display_credit_record(struct qdf_dp_trace_record_s *record,
1299  				  uint16_t index, uint8_t pdev_id,
1300  				  uint8_t info);
1301  
1302  /**
1303   * qdf_dp_display_event_record() - display event records
1304   * @record: dptrace record
1305   * @index: index
1306   * @pdev_id: pdev id for the mgmt pkt
1307   * @info: info used to display pkt (live mode, throttling)
1308   *
1309   * Return: none
1310   */
1311  void qdf_dp_display_event_record(struct qdf_dp_trace_record_s *record,
1312  				 uint16_t index, uint8_t pdev_id, uint8_t info);
1313  
1314  /**
1315   * qdf_dp_trace_record_event() - record events
1316   * @code: dptrace code
1317   * @vdev_id: vdev id
1318   * @pdev_id: pdev_id
1319   * @type: proto type
1320   * @subtype: proto subtype
1321   *
1322   * Return: none
1323   */
1324  void qdf_dp_trace_record_event(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
1325  			       uint8_t pdev_id, enum qdf_proto_type type,
1326  			       enum qdf_proto_subtype subtype);
1327  
1328  /**
1329   * qdf_dp_set_proto_event_bitmap() - Set the protocol event bitmap
1330   * @value: proto event bitmap value.
1331   *
1332   * QDF_NBUF_PKT_TRAC_TYPE_DNS       0x01
1333   * QDF_NBUF_PKT_TRAC_TYPE_EAPOL     0x02
1334   * QDF_NBUF_PKT_TRAC_TYPE_DHCP      0x04
1335   * QDF_NBUF_PKT_TRAC_TYPE_ARP       0x10
1336   *
1337   * Return: none
1338   */
1339  void qdf_dp_set_proto_event_bitmap(uint32_t value);
1340  
1341  /**
1342   * qdf_dp_log_proto_pkt_info() - Send diag log event
1343   * @sa: source MAC address
1344   * @da: destination MAC address
1345   * @type: pkt type
1346   * @subtype: pkt subtype
1347   * @dir: tx or rx
1348   * @msdu_id: msdu id
1349   * @status: status
1350   *
1351   * Return: none
1352   */
1353  void qdf_dp_log_proto_pkt_info(uint8_t *sa, uint8_t *da, uint8_t type,
1354  			       uint8_t subtype, uint8_t dir, uint16_t msdu_id,
1355  			       uint8_t status);
1356  
1357  /**
1358   * qdf_dp_track_noack_check() - Check if no ack count should be tracked for
1359   *  the configured protocol packet types
1360   * @nbuf: nbuf
1361   * @subtype: subtype of packet to be tracked
1362   *
1363   * Return: none
1364   */
1365  void qdf_dp_track_noack_check(qdf_nbuf_t nbuf, enum qdf_proto_subtype *subtype);
1366  #else
1367  static inline
qdf_dp_trace_log_pkt(uint8_t vdev_id,struct sk_buff * skb,enum qdf_proto_dir dir,uint8_t pdev_id,enum QDF_OPMODE op_mode)1368  bool qdf_dp_trace_log_pkt(uint8_t vdev_id, struct sk_buff *skb,
1369  			  enum qdf_proto_dir dir, uint8_t pdev_id,
1370  			  enum QDF_OPMODE op_mode)
1371  {
1372  	return false;
1373  }
1374  static inline
qdf_dp_trace_init(bool live_mode_config,uint8_t thresh,uint16_t time_limit,uint8_t verbosity,uint32_t proto_bitmap)1375  void qdf_dp_trace_init(bool live_mode_config, uint8_t thresh,
1376  				uint16_t time_limit, uint8_t verbosity,
1377  				uint32_t proto_bitmap)
1378  {
1379  }
1380  
1381  static inline
qdf_dp_trace_deinit(void)1382  void qdf_dp_trace_deinit(void)
1383  {
1384  }
1385  
1386  static inline
qdf_dp_trace_set_track(qdf_nbuf_t nbuf,enum qdf_proto_dir dir)1387  void qdf_dp_trace_set_track(qdf_nbuf_t nbuf, enum qdf_proto_dir dir)
1388  {
1389  }
1390  static inline
qdf_dp_trace_set_value(uint32_t proto_bitmap,uint8_t no_of_records,uint8_t verbosity)1391  void qdf_dp_trace_set_value(uint32_t proto_bitmap, uint8_t no_of_records,
1392  			    uint8_t verbosity)
1393  {
1394  }
1395  
1396  static inline
qdf_dp_trace_dump_all(uint32_t count,uint8_t pdev_id)1397  void qdf_dp_trace_dump_all(uint32_t count, uint8_t pdev_id)
1398  {
1399  }
1400  
1401  static inline
qdf_dpt_get_curr_pos_debugfs(qdf_debugfs_file_t file,enum qdf_dpt_debugfs_state state)1402  uint32_t qdf_dpt_get_curr_pos_debugfs(qdf_debugfs_file_t file,
1403  				      enum qdf_dpt_debugfs_state state)
1404  {
1405  	return 0;
1406  }
1407  
1408  static inline
qdf_dpt_dump_stats_debugfs(qdf_debugfs_file_t file,uint32_t curr_pos)1409  QDF_STATUS qdf_dpt_dump_stats_debugfs(qdf_debugfs_file_t file,
1410  				      uint32_t curr_pos)
1411  {
1412  	return QDF_STATUS_SUCCESS;
1413  }
1414  
1415  static inline
qdf_dpt_set_value_debugfs(uint8_t proto_bitmap,uint8_t no_of_record,uint8_t verbosity,uint16_t num_records_to_dump)1416  void qdf_dpt_set_value_debugfs(uint8_t proto_bitmap, uint8_t no_of_record,
1417  			    uint8_t verbosity, uint16_t num_records_to_dump)
1418  {
1419  }
1420  
qdf_dp_trace_dump_stats(void)1421  static inline void qdf_dp_trace_dump_stats(void)
1422  {
1423  }
1424  
1425  static inline
qdf_dp_trace_disable_live_mode(void)1426  void qdf_dp_trace_disable_live_mode(void)
1427  {
1428  }
1429  
1430  static inline
qdf_dp_trace_enable_live_mode(void)1431  void qdf_dp_trace_enable_live_mode(void)
1432  {
1433  }
1434  
1435  static inline
qdf_dp_trace_throttle_live_mode(bool high_bw_request)1436  void qdf_dp_trace_throttle_live_mode(bool high_bw_request)
1437  {
1438  }
1439  
1440  static inline
qdf_dp_trace_clear_buffer(void)1441  void qdf_dp_trace_clear_buffer(void)
1442  {
1443  }
1444  
1445  static inline
qdf_dp_trace_apply_tput_policy(bool is_data_traffic)1446  void qdf_dp_trace_apply_tput_policy(bool is_data_traffic)
1447  {
1448  }
1449  
1450  static inline
qdf_dp_trace_data_pkt(qdf_nbuf_t nbuf,uint8_t pdev_id,enum QDF_DP_TRACE_ID code,uint16_t msdu_id,enum qdf_proto_dir dir)1451  void qdf_dp_trace_data_pkt(qdf_nbuf_t nbuf, uint8_t pdev_id,
1452  			   enum QDF_DP_TRACE_ID code, uint16_t msdu_id,
1453  			   enum qdf_proto_dir dir)
1454  {
1455  }
1456  
1457  static inline
qdf_dp_log_proto_pkt_info(uint8_t * sa,uint8_t * da,uint8_t type,uint8_t subtype,uint8_t dir,uint16_t msdu_id,uint8_t status)1458  void qdf_dp_log_proto_pkt_info(uint8_t *sa, uint8_t *da, uint8_t type,
1459  			       uint8_t subtype, uint8_t dir, uint16_t msdu_id,
1460  			       uint8_t status)
1461  {
1462  }
1463  
1464  static inline
qdf_dp_track_noack_check(qdf_nbuf_t nbuf,enum qdf_proto_subtype * subtype)1465  void qdf_dp_track_noack_check(qdf_nbuf_t nbuf, enum qdf_proto_subtype *subtype)
1466  {
1467  }
1468  
1469  static inline
qdf_dp_get_status_from_htt(uint8_t status)1470  enum qdf_dp_tx_rx_status qdf_dp_get_status_from_htt(uint8_t status)
1471  {
1472  	return QDF_TX_RX_STATUS_OK;
1473  }
1474  
1475  static inline
qdf_dp_get_status_from_a_status(uint8_t status)1476  enum qdf_dp_tx_rx_status qdf_dp_get_status_from_a_status(uint8_t status)
1477  {
1478  	return QDF_TX_RX_STATUS_OK;
1479  }
1480  #endif
1481  
1482  /**
1483   * qdf_trace_display() - Display trace
1484   *
1485   * Return:  None
1486   */
1487  void qdf_trace_display(void);
1488  
1489  /**
1490   * qdf_snprintf() - wrapper function to snprintf
1491   * @str_buffer: string Buffer
1492   * @size: defines the size of the data record
1493   * @str_format: Format string in which the message to be logged. This format
1494   * string contains printf-like replacement parameters, which follow
1495   * this parameter in the variable argument list.
1496   *
1497   * Return: num of bytes written to buffer
1498   */
1499  int __printf(3, 4) qdf_snprintf(char *str_buffer, unsigned int size,
1500  				char *str_format, ...);
1501  
1502  #define QDF_SNPRINTF qdf_snprintf
1503  
1504  #ifdef TSOSEG_DEBUG
1505  
qdf_tso_seg_dbg_bug(char * msg)1506  static inline void qdf_tso_seg_dbg_bug(char *msg)
1507  {
1508  	qdf_print("%s", msg);
1509  	QDF_BUG(0);
1510  };
1511  
1512  /**
1513   * qdf_tso_seg_dbg_init - initialize TSO segment debug structure
1514   * @tsoseg: structure to initialize
1515   *
1516   * TSO segment dbg structures are attached to qdf_tso_seg_elem_t
1517   * structures and are allocated only of TSOSEG_DEBUG is defined.
1518   * When allocated, at the time of the tso_seg_pool initialization,
1519   * which goes with tx_desc initialization (1:1), each structure holds
1520   * a number of (currently 16) history entries, basically describing
1521   * what operation has been performed on this particular tso_seg_elem.
1522   * This history buffer is a circular buffer and the current index is
1523   * held in an atomic variable called cur. It is incremented every
1524   * operation. Each of these operations are added with the function
1525   * qdf_tso_seg_dbg_record.
1526   * For each segment, this initialization function MUST be called PRIOR
1527   * TO any _dbg_record() function calls.
1528   * On free, qdf_tso_seg_elem structure is cleared (using qdf_tso_seg_dbg_zero)
1529   * which clears the tso_desc, BUT DOES NOT CLEAR THE HISTORY element.
1530   *
1531   * Return:
1532   *   None
1533   */
1534  static inline
qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t * tsoseg)1535  void qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t *tsoseg)
1536  {
1537  	tsoseg->dbg.txdesc = NULL;
1538  	qdf_atomic_init(&tsoseg->dbg.cur); /* history empty */
1539  }
1540  
1541  /**
1542   * qdf_tso_seg_dbg_record - add a history entry to TSO debug structure
1543   * @tsoseg: structure to initialize
1544   * @id: operation ID (identifies the caller)
1545   *
1546   * Adds a history entry to the history circular buffer. Each entry
1547   * contains an operation id (caller, as currently each ID is used only
1548   * once in the source, so it directly identifies the src line that invoked
1549   * the recording.
1550   *
1551   * qdf_tso_seg_dbg_record CAN ONLY BE CALLED AFTER the entry is initialized
1552   * by qdf_tso_seg_dbg_init.
1553   *
1554   * The entry to be added is written at the location pointed by the atomic
1555   * variable called cur. Cur is an ever increasing atomic variable. It is
1556   * masked so that only the lower 4 bits are used (16 history entries).
1557   *
1558   * Return:
1559   *   int: the entry this record was recorded at
1560   */
1561  static inline
qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t * tsoseg,short id)1562  int qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t *tsoseg, short id)
1563  {
1564  	int rc = -1;
1565  	unsigned int c;
1566  
1567  	qdf_assert(tsoseg);
1568  
1569  	if (id == TSOSEG_LOC_ALLOC) {
1570  		c = qdf_atomic_read(&tsoseg->dbg.cur);
1571  		/* dont crash on the very first alloc on the segment */
1572  		c &= 0x0f;
1573  		/* allow only INIT and FREE ops before ALLOC */
1574  		if (tsoseg->dbg.h[c].id >= id)
1575  			qdf_tso_seg_dbg_bug("Rogue TSO seg alloc");
1576  	}
1577  	c = qdf_atomic_inc_return(&tsoseg->dbg.cur);
1578  
1579  	c &= 0x0f;
1580  	tsoseg->dbg.h[c].ts = qdf_get_log_timestamp();
1581  	tsoseg->dbg.h[c].id = id;
1582  	rc = c;
1583  
1584  	return rc;
1585  };
1586  
1587  static inline void
qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t * tsoseg,void * owner)1588  qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t *tsoseg, void *owner)
1589  {
1590  	if (tsoseg)
1591  		tsoseg->dbg.txdesc = owner;
1592  };
1593  
1594  static inline void
qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t * tsoseg)1595  qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t *tsoseg)
1596  {
1597  	memset(tsoseg, 0, offsetof(struct qdf_tso_seg_elem_t, dbg));
1598  	return;
1599  };
1600  
1601  #else
1602  static inline
qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t * tsoseg)1603  void qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t *tsoseg)
1604  {
1605  };
1606  static inline
qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t * tsoseg,short id)1607  int qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t *tsoseg, short id)
1608  {
1609  	return 0;
1610  };
qdf_tso_seg_dbg_bug(char * msg)1611  static inline void qdf_tso_seg_dbg_bug(char *msg)
1612  {
1613  };
1614  static inline void
qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t * tsoseg,void * owner)1615  qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t *tsoseg, void *owner)
1616  {
1617  };
1618  static inline int
qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t * tsoseg)1619  qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t *tsoseg)
1620  {
1621  	memset(tsoseg, 0, sizeof(struct qdf_tso_seg_elem_t));
1622  	return 0;
1623  };
1624  
1625  #endif /* TSOSEG_DEBUG */
1626  
1627  /**
1628   * qdf_trace_hex_dump() - externally called hex dump function
1629   * @module: Module identifier a member of the QDF_MODULE_ID enumeration that
1630   * identifies the module issuing the trace message.
1631   * @level: Trace level a member of the QDF_TRACE_LEVEL enumeration indicating
1632   * the severity of the condition causing the trace message to be
1633   * issued. More severe conditions are more likely to be logged.
1634   * @data: The base address of the buffer to be logged.
1635   * @buf_len: The size of the buffer to be logged.
1636   *
1637   * Checks the level of severity and accordingly prints the trace messages
1638   *
1639   * Return:  None
1640   */
1641  void qdf_trace_hex_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
1642  			void *data, int buf_len);
1643  
1644  /**
1645   * qdf_trace_hex_ascii_dump() - externally called hex and ascii dump function
1646   * @module: Module identifier a member of the QDF_MODULE_ID enumeration that
1647   * identifies the module issuing the trace message.
1648   * @level: Trace level a member of the QDF_TRACE_LEVEL enumeration indicating
1649   * the severity of the condition causing the trace message to be
1650   * issued. More severe conditions are more likely to be logged.
1651   * @data: The base address of the buffer to be logged.
1652   * @buf_len: The size of the buffer to be logged.
1653   *
1654   * Checks the level of severity and accordingly prints the trace messages
1655   *
1656   * Return:  None
1657   */
1658  void qdf_trace_hex_ascii_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
1659  			      void *data, int buf_len);
1660  
1661  #define ERROR_CODE                      -1
1662  #define QDF_MAX_NAME_SIZE               32
1663  #define MAX_PRINT_CONFIG_SUPPORTED      32
1664  
1665  #define MAX_SUPPORTED_CATEGORY QDF_MODULE_ID_MAX
1666  
1667  /**
1668   * qdf_set_pidx() - Sets the global qdf_pidx.
1669   * @pidx: Index of print control object assigned to the module
1670   *
1671   */
1672  void qdf_set_pidx(int pidx);
1673  
1674  /**
1675   * qdf_get_pidx() - Returns the global qdf_pidx.
1676   *
1677   * Return: Current qdf print index.
1678   */
1679  int qdf_get_pidx(void);
1680  /*
1681   * Shared print control index
1682   * for converged debug framework
1683   */
1684  
1685  #define QDF_PRINT_IDX_SHARED -1
1686  
1687  /**
1688   * QDF_PRINT_INFO() - Generic wrapper API for logging
1689   * @idx: Index of print control object
1690   * @module: Module identifier. A member of QDF_MODULE_ID enumeration that
1691   *           identifies the module issuing the trace message
1692   * @level: Trace level. A member of QDF_TRACE_LEVEL enumeration indicating
1693   *          the severity of the condition causing the trace message to be
1694   *          issued.
1695   * @str_format: Format string that contains the message to be logged.
1696   *
1697   *
1698   * This wrapper will be used for any generic logging messages. Wrapper will
1699   * compile a call to converged QDF trace message API.
1700   *
1701   * Return: Nothing
1702   *
1703   */
1704  void QDF_PRINT_INFO(unsigned int idx, QDF_MODULE_ID module,
1705  		    QDF_TRACE_LEVEL level,
1706  		    char *str_format, ...);
1707  
1708  /**
1709   * struct category_info - Category information structure
1710   * @category_verbose_mask: Embeds information about category's verbose level
1711   */
1712  struct category_info {
1713  	uint16_t category_verbose_mask;
1714  };
1715  
1716  /**
1717   * struct category_name_info - Category name information structure
1718   * @category_name_str: Embeds information about category name
1719   */
1720  struct category_name_info {
1721  	unsigned char category_name_str[QDF_MAX_NAME_SIZE];
1722  };
1723  
1724  /**
1725   * qdf_trace_msg_cmn() - Converged logging API
1726   * @idx: Index of print control object assigned to the module
1727   * @category: Category identifier. A member of the QDF_MODULE_ID enumeration
1728   *            that identifies the category issuing the trace message.
1729   * @verbose: Verbose level. A member of the QDF_TRACE_LEVEL enumeration
1730   *           indicating the severity of the condition causing the trace
1731   *           message to be issued. More severe conditions are more likely
1732   *           to be logged.
1733   * @str_format: Format string. The message to be logged. This format string
1734   *              contains printf-like replacement parameters, which follow this
1735   *              parameter in the variable argument list.
1736   * @val: Variable argument list part of the log message
1737   *
1738   * Return: nothing
1739   *
1740   */
1741  void qdf_trace_msg_cmn(unsigned int idx,
1742  			QDF_MODULE_ID category,
1743  			QDF_TRACE_LEVEL verbose,
1744  			const char *str_format,
1745  			va_list val);
1746  
1747  /**
1748   * struct qdf_print_ctrl - QDF Print Control structure
1749   *                        Statically allocated objects of print control
1750   *                        structure are declared that will support maximum of
1751   *                        32 print control objects. Any module that needs to
1752   *                        register to the print control framework needs to
1753   *                        obtain a print control object using
1754   *                        qdf_print_ctrl_register API. It will have to pass
1755   *                        pointer to category info structure, name and
1756   *                        custom print function to be used if required.
1757   * @name:                 Optional name for the control object
1758   * @cat_info:             Array of category_info struct
1759   * @custom_print:         Custom print handler
1760   * @custom_ctxt:          Custom print context
1761   * @dbglvlmac_on:         Flag to enable/disable MAC level filtering
1762   * @in_use:               Boolean to indicate if control object is in use
1763   */
1764  struct qdf_print_ctrl {
1765  	char name[QDF_MAX_NAME_SIZE];
1766  	struct category_info cat_info[MAX_SUPPORTED_CATEGORY];
1767  	void (*custom_print)(void *ctxt, const char *fmt, va_list args);
1768  	void *custom_ctxt;
1769  #ifdef DBG_LVL_MAC_FILTERING
1770  	unsigned char dbglvlmac_on;
1771  #endif
1772  	bool in_use;
1773  };
1774  
1775  /**
1776   * qdf_print_ctrl_register() - Allocate QDF print control object, assign
1777   *                             pointer to category info or print control
1778   *                             structure and return the index to the callee
1779   * @cinfo:                 Pointer to array of category info structure
1780   * @custom_print_handler:  Pointer to custom print handler
1781   * @custom_ctx:            Pointer to custom context
1782   * @pctrl_name:            Pointer to print control object name
1783   *
1784   * Return: Index of qdf_print_ctrl structure
1785   *
1786   */
1787  int qdf_print_ctrl_register(const struct category_info *cinfo,
1788  			    void *custom_print_handler,
1789  			    void *custom_ctx,
1790  			    const char *pctrl_name);
1791  
1792  #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
1793  /**
1794   * qdf_initialize_module_param_from_ini() - Update qdf module params
1795   *
1796   * Read the file which has wifi module params, parse and update
1797   * qdf module params.
1798   *
1799   * Return: void
1800   */
1801  void qdf_initialize_module_param_from_ini(void);
1802  #else
1803  static inline
qdf_initialize_module_param_from_ini(void)1804  void qdf_initialize_module_param_from_ini(void)
1805  {
1806  }
1807  #endif
1808  
1809  /**
1810   * qdf_shared_print_ctrl_init() - Initialize the shared print ctrl obj with
1811   *                                all categories set to the default level
1812   *
1813   * Return: void
1814   *
1815   */
1816  void qdf_shared_print_ctrl_init(void);
1817  
1818  /**
1819   * qdf_print_setup() - Setup default values to all the print control objects
1820   *
1821   * Register new print control object for the callee
1822   *
1823   * Return:             QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE
1824   *                      on failure
1825   */
1826  QDF_STATUS qdf_print_setup(void);
1827  
1828  /**
1829   * qdf_print_ctrl_cleanup() - Clean up a print control object
1830   * @idx: Index of print control object
1831   *
1832   * Cleanup the print control object for the callee
1833   *
1834   * Return: QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE on failure
1835   */
1836  QDF_STATUS qdf_print_ctrl_cleanup(unsigned int idx);
1837  
1838  /**
1839   * qdf_shared_print_ctrl_cleanup() - Clean up of the shared object
1840   *
1841   * Cleanup the shared print-ctrl-object
1842   *
1843   * Return: void
1844   */
1845  void qdf_shared_print_ctrl_cleanup(void);
1846  
1847  /**
1848   * qdf_print_set_category_verbose() - Enable/Disable category for a
1849   *                                    print control object with
1850   *                                    user provided verbose level
1851   * @idx: Index of the print control object assigned to callee
1852   * @category: Category information
1853   * @verbose: Verbose information
1854   * @is_set: Flag indicating if verbose level needs to be enabled or disabled
1855   *
1856   * Return: QDF_STATUS_SUCCESS for success and QDF_STATUS_E_FAILURE for failure
1857   */
1858  QDF_STATUS qdf_print_set_category_verbose(unsigned int idx,
1859  					  QDF_MODULE_ID category,
1860  					  QDF_TRACE_LEVEL verbose,
1861  					  bool is_set);
1862  
1863  /**
1864   * qdf_log_dump_at_kernel_level() - Enable/Disable printk call
1865   * @enable: Indicates whether printk is enabled in QDF_TRACE
1866   *
1867   * Return: void
1868   */
1869  void qdf_log_dump_at_kernel_level(bool enable);
1870  
1871  /**
1872   * qdf_logging_set_flush_timer() - Set the time period in which host logs
1873   *                                 should be flushed out to user-space
1874   * @milliseconds: milliseconds after which the logs should be flushed out to
1875   *                 user-space
1876   *
1877   * Return: QDF_STATUS_SUCCESS for success and QDF_STATUS_E_FAILURE for failure
1878   */
1879  int qdf_logging_set_flush_timer(uint32_t milliseconds);
1880  
1881  /**
1882   * qdf_logging_flush_logs() - Flush out the logs to user-space one time
1883   *
1884   * Return: void
1885   */
1886  void qdf_logging_flush_logs(void);
1887  
1888  /**
1889   * qdf_print_get_category_verbose() - Get category verbose information for the
1890   *                                    print control object
1891   *
1892   * @idx: Index of print control object
1893   * @category: Category information
1894   *
1895   * Return: Verbose value for the particular category
1896   */
1897  QDF_TRACE_LEVEL qdf_print_get_category_verbose(unsigned int idx,
1898  					       QDF_MODULE_ID category);
1899  
1900  /**
1901   * qdf_print_is_category_enabled() - Get category information for the
1902   *                                   print control object
1903   *
1904   * @idx: Index of print control object
1905   * @category: Category information
1906   *
1907   * Return: Verbose enabled(true) or disabled(false) or invalid input (false)
1908   */
1909  bool qdf_print_is_category_enabled(unsigned int idx,
1910  				   QDF_MODULE_ID category);
1911  
1912  /**
1913   * qdf_print_is_verbose_enabled() - Get verbose information of a category for
1914   *                                  the print control object
1915   *
1916   * @idx: Index of print control object
1917   * @category: Category information
1918   * @verbose: Verbose information
1919   *
1920   * Return: Verbose enabled(true) or disabled(false) or invalid input (false)
1921   */
1922  bool qdf_print_is_verbose_enabled(unsigned int idx,
1923  				  QDF_MODULE_ID category,
1924  				  QDF_TRACE_LEVEL verbose);
1925  
1926  /**
1927   * qdf_print_clean_node_flag() - Clean up node flag for print control object
1928   *
1929   * @idx: Index of print control object
1930   *
1931   * Return: None
1932   */
1933  void qdf_print_clean_node_flag(unsigned int idx);
1934  
1935  #ifdef DBG_LVL_MAC_FILTERING
1936  
1937  /**
1938   * qdf_print_set_node_flag() - Set flag to enable MAC level filtering
1939   *
1940   * @idx: Index of print control object
1941   * @enable: Enable/Disable bit sent by callee
1942   *
1943   * Return: QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE on Failure
1944   */
1945  QDF_STATUS qdf_print_set_node_flag(unsigned int idx,
1946  				   uint8_t enable);
1947  
1948  /**
1949   * qdf_print_get_node_flag() - Get flag that controls MAC level filtering
1950   *
1951   * @idx: Index of print control object
1952   *
1953   * Return: Flag that indicates enable(1) or disable(0) or invalid(-1)
1954   */
1955  bool qdf_print_get_node_flag(unsigned int idx);
1956  
1957  #endif
1958  
1959  #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
1960  /**
1961   * qdf_module_param_handler() - Function to store module params
1962   *
1963   * @context: NULL, unused.
1964   * @key: Name of the module param
1965   * @value: Value of the module param
1966   *
1967   * Handler function to be called from qdf_ini_parse()
1968   * function when a valid parameter is found in a file.
1969   *
1970   * Return: QDF_STATUS_SUCCESS on Success
1971   */
1972  QDF_STATUS qdf_module_param_handler(void *context, const char *key,
1973  				    const char *value);
1974  #else
1975  static inline
qdf_module_param_handler(void * context,const char * key,const char * value)1976  QDF_STATUS qdf_module_param_handler(void *context, const char *key,
1977  				    const char *value)
1978  {
1979  	return QDF_STATUS_SUCCESS;
1980  }
1981  #endif
1982  
1983  /**
1984   * qdf_logging_init() - Initialize msg logging functionality
1985   *
1986   * Return: void
1987   */
1988  void qdf_logging_init(void);
1989  
1990  /**
1991   * qdf_logging_exit() - Cleanup msg logging functionality
1992   *
1993   * Return: void
1994   */
1995  void qdf_logging_exit(void);
1996  
1997  #define QDF_SYMBOL_LEN __QDF_SYMBOL_LEN
1998  
1999  /**
2000   * qdf_sprint_symbol() - prints the name of a symbol into a string buffer
2001   * @buffer: the string buffer to print into
2002   * @addr: address of the symbol to lookup and print
2003   *
2004   * Return: number of characters printed
2005   */
2006  int qdf_sprint_symbol(char *buffer, void *addr);
2007  
2008  /**
2009   * qdf_minidump_init() - Initialize minidump functionality
2010   *
2011   *
2012   * Return: void
2013   */
2014  static inline
qdf_minidump_init(void)2015  void qdf_minidump_init(void)
2016  {
2017  	__qdf_minidump_init();
2018  }
2019  
2020  /**
2021   * qdf_minidump_deinit() - De-initialize minidump functionality
2022   *
2023   *
2024   * Return: void
2025   */
2026  static inline
qdf_minidump_deinit(void)2027  void qdf_minidump_deinit(void)
2028  {
2029  	__qdf_minidump_deinit();
2030  }
2031  
2032  /**
2033   * qdf_minidump_log() - Log memory address to be included in minidump
2034   * @start_addr: Start address of the memory to be dumped
2035   * @size: Size in bytes
2036   * @name: String to identify this entry
2037   */
2038  static inline
qdf_minidump_log(void * start_addr,const size_t size,const char * name)2039  void qdf_minidump_log(void *start_addr,
2040  		      const size_t size, const char *name)
2041  {
2042  	__qdf_minidump_log(start_addr, size, name);
2043  }
2044  
2045  /**
2046   * qdf_minidump_remove() - Remove memory address from minidump
2047   * @start_addr: Start address of the memory previously added
2048   * @size: Size in bytes
2049   * @name: String to identify this entry
2050   */
2051  static inline
qdf_minidump_remove(void * start_addr,const size_t size,const char * name)2052  void qdf_minidump_remove(void *start_addr,
2053  			 const size_t size, const char *name)
2054  {
2055  	__qdf_minidump_remove(start_addr, size, name);
2056  }
2057  
2058  #endif /* __QDF_TRACE_H */
2059