xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_trace.h (revision 8b3dca18206e1a0461492f082fa6e270b092c035)
1 /*
2  * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022 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  * typedef 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  * typedef 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_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       50 /* 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  */
292 
293 enum  QDF_DP_TRACE_ID {
294 	QDF_DP_TRACE_INVALID,
295 	QDF_DP_TRACE_DROP_PACKET_RECORD,
296 	QDF_DP_TRACE_EAPOL_PACKET_RECORD,
297 	QDF_DP_TRACE_DHCP_PACKET_RECORD,
298 	QDF_DP_TRACE_ARP_PACKET_RECORD,
299 	QDF_DP_TRACE_MGMT_PACKET_RECORD,
300 	QDF_DP_TRACE_EVENT_RECORD,
301 	QDF_DP_TRACE_BASE_VERBOSITY,
302 	QDF_DP_TRACE_ICMP_PACKET_RECORD,
303 	QDF_DP_TRACE_ICMPv6_PACKET_RECORD,
304 	QDF_DP_TRACE_HDD_TX_TIMEOUT,
305 	QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT,
306 	QDF_DP_TRACE_TX_CREDIT_RECORD,
307 	QDF_DP_TRACE_ULTRA_LOW_VERBOSITY,
308 	QDF_DP_TRACE_TX_PACKET_RECORD,
309 	QDF_DP_TRACE_RX_PACKET_RECORD,
310 	QDF_DP_TRACE_HDD_TX_PACKET_RECORD,
311 	QDF_DP_TRACE_HDD_RX_PACKET_RECORD,
312 	QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD,
313 	QDF_DP_TRACE_LI_DP_RX_PACKET_RECORD,
314 	QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD,
315 	QDF_DP_TRACE_FREE_PACKET_PTR_RECORD,
316 	QDF_DP_TRACE_LOW_VERBOSITY,
317 	QDF_DP_TRACE_HDD_TX_PACKET_PTR_RECORD,
318 	QDF_DP_TRACE_TX_PACKET_PTR_RECORD,
319 	QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD,
320 	QDF_DP_TRACE_RX_PACKET_PTR_RECORD,
321 	QDF_DP_TRACE_RX_HDD_PACKET_PTR_RECORD,
322 	QDF_DP_TRACE_CE_PACKET_PTR_RECORD,
323 	QDF_DP_TRACE_CE_FAST_PACKET_PTR_RECORD,
324 	QDF_DP_TRACE_CE_FAST_PACKET_ERR_RECORD,
325 	QDF_DP_TRACE_RX_HTT_PACKET_PTR_RECORD,
326 	QDF_DP_TRACE_RX_OFFLOAD_HTT_PACKET_PTR_RECORD,
327 	QDF_DP_TRACE_RX_LI_DP_PACKET_PTR_RECORD,
328 	QDF_DP_TRACE_MED_VERBOSITY,
329 	QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD,
330 	QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD,
331 	QDF_DP_TRACE_TXRX_FAST_PACKET_PTR_RECORD,
332 	QDF_DP_TRACE_HTT_PACKET_PTR_RECORD,
333 	QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
334 	QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
335 	QDF_DP_TRACE_RX_TXRX_PACKET_PTR_RECORD,
336 	QDF_DP_TRACE_LI_DP_NULL_RX_PACKET_RECORD,
337 	QDF_DP_TRACE_HIGH_VERBOSITY,
338 	QDF_DP_TRACE_MAX
339 };
340 
341 /**
342  * qdf_proto_dir - direction
343  * @QDF_TX: TX direction
344  * @QDF_RX: RX direction
345  * @QDF_NA: not applicable
346  */
347 enum qdf_proto_dir {
348 	QDF_TX,
349 	QDF_RX,
350 	QDF_NA
351 };
352 
353 /**
354  * QDF_CREDIT_UPDATE_SOURCE - source of credit record
355  * @QDF_TX_SCHED: Tx scheduler
356  * @QDF_TX_COMP: TX completion
357  * @QDF_TX_CREDIT_UPDATE: credit update indication
358  * @QDF_HTT_ATTACH: HTT attach
359  * @QDF_TX_HTT_MSG: HTT TX message
360  */
361 enum QDF_CREDIT_UPDATE_SOURCE {
362 	QDF_TX_SCHED,
363 	QDF_TX_COMP,
364 	QDF_TX_CREDIT_UPDATE,
365 	QDF_HTT_ATTACH,
366 	QDF_TX_HTT_MSG
367 };
368 
369 /**
370  * QDF_CREDIT_OPERATION - operation on credit
371  * @QDF_CREDIT_INC: credit increment
372  * @QDF_CREDIT_DEC: credit decrement
373  * @QDF_CREDIT_ABS: Abosolute credit
374  * @QDF_OP_NA: Not applicable
375  */
376 enum QDF_CREDIT_OPERATION {
377 	QDF_CREDIT_INC,
378 	QDF_CREDIT_DEC,
379 	QDF_CREDIT_ABS,
380 	QDF_OP_NA
381 };
382 
383 /**
384  * struct qdf_dp_trace_ptr_buf - pointer record buffer
385  * @cookie: cookie value
386  * @msdu_id: msdu_id
387  * @status: completion status
388  */
389 struct qdf_dp_trace_ptr_buf {
390 	uint64_t cookie;
391 	uint16_t msdu_id;
392 	uint16_t status;
393 };
394 
395 /**
396  * struct qdf_dp_trace_proto_buf - proto packet buffer
397  * @sa: source address
398  * @da: destination address
399  * @vdev_id : vdev id
400  * @type: packet type
401  * @subtype: packet subtype
402  * @dir: direction
403  * @proto_priv_data: protocol private data
404  * can be stored in this.
405  */
406 struct qdf_dp_trace_proto_buf {
407 	struct qdf_mac_addr sa;
408 	struct qdf_mac_addr da;
409 	uint8_t vdev_id;
410 	uint8_t type;
411 	uint8_t subtype;
412 	uint8_t dir;
413 	/* for ICMP priv data is bit offset 38 to 42
414 	 * 38-40 ICMP_ICMP_ID and
415 	 * 40-42 ICMP_SEQ_NUM_OFFSET
416 	 */
417 	uint32_t proto_priv_data;
418 };
419 
420 /**
421  * struct qdf_dp_trace_mgmt_buf - mgmt packet buffer
422  * @vdev_id : vdev id
423  * @type: packet type
424  * @subtype: packet subtype
425  */
426 struct qdf_dp_trace_mgmt_buf {
427 	uint8_t vdev_id;
428 	uint8_t type;
429 	uint8_t subtype;
430 };
431 
432 /**
433  * struct qdf_dp_trace_credit_record - tx credit record
434  * @source: credit record source
435  * @operation: credit operation
436  * @delta: delta of credit
437  * @total_credits: total credit
438  * @g0_credit: group 0 credit
439  * @g1_credit: group 1 credit
440  */
441 struct qdf_dp_trace_credit_record {
442 	enum QDF_CREDIT_UPDATE_SOURCE source;
443 	enum QDF_CREDIT_OPERATION operation;
444 	int delta;
445 	int total_credits;
446 	int g0_credit;
447 	int g1_credit;
448 };
449 
450 /**
451  * struct qdf_dp_trace_event_buf - event buffer
452  * @vdev_id : vdev id
453  * @type: packet type
454  * @subtype: packet subtype
455  */
456 struct qdf_dp_trace_event_buf {
457 	uint8_t vdev_id;
458 	uint8_t type;
459 	uint8_t subtype;
460 };
461 
462 /**
463  * struct qdf_dp_trace_data_buf - nbuf data buffer
464  * @msdu_id : msdu id
465  */
466 struct qdf_dp_trace_data_buf {
467 	uint16_t msdu_id;
468 };
469 
470 /**
471  * struct qdf_dp_trace_record_s - Describes a record in DP trace
472  * @time: time when it got stored
473  * @code: Describes the particular event
474  * @data: buffer to store data
475  * @size: Length of the valid data stored in this record
476  * @pid : process id which stored the data in this record
477  */
478 struct qdf_dp_trace_record_s {
479 	uint64_t time;
480 	uint8_t code;
481 	uint8_t data[QDF_DP_TRACE_RECORD_SIZE];
482 	uint8_t size;
483 	uint32_t pid;
484 	uint8_t pdev_id;
485 };
486 
487 /**
488  * struct qdf_dp_trace_data - Parameters to configure/control DP trace
489  * @head: Position of first record
490  * @tail: Position of last record
491  * @num:  Current index
492  * @proto_bitmap: defines which protocol to be traced
493  * @no_of_record: defines every nth packet to be traced
494  * @num_records_to_dump: defines number of records to be dumped
495  * @dump_counter: counter to track number of records dumped
496  * @verbosity : defines verbosity level
497  * @ini_conf_verbosity: Configured verbosity from INI
498  * @enable: enable/disable DP trace
499  * @count: current packet number
500  * @live_mode_config: configuration as received during initialization
501  * @live_mode: current live mode, enabled or disabled, can be throttled based
502  *             on throughput
503  * @force_live_mode: flag to enable live mode all the time for all packets.
504  *                  This can be set/unset from userspace and overrides other
505  *                  live mode flags.
506  * @dynamic_verbosity_modify: Dynamic user configured verbosity overrides all
507  * @print_pkt_cnt: count of number of packets printed in live mode
508  * @high_tput_thresh: thresh beyond which live mode is turned off
509  * @thresh_time_limit: max time, in terms of BW timer intervals to wait,
510  *          for determining if high_tput_thresh has been crossed. ~1s
511  * @arp_req: stats for arp reqs
512  * @arp_resp: stats for arp resps
513  * @icmp_req: stats for icmp reqs
514  * @icmp_resp: stats for icmp resps
515  * @dhcp_disc: stats for dhcp discover msgs
516  * @dhcp_req: stats for dhcp req msgs
517  * @dhcp_off: stats for dhcp offer msgs
518  * @dhcp_ack: stats for dhcp ack msgs
519  * @dhcp_nack: stats for dhcp nack msgs
520  * @dhcp_others: stats for other dhcp pkts types
521  * @eapol_m1: stats for eapol m1
522  * @eapol_m2: stats for eapol m2
523  * @eapol_m3: stats for eapol m3
524  * @eapol_m4: stats for eapol m4
525  * @eapol_others: stats for other eapol pkt types
526  * @icmpv6_req: stats for icmpv6 reqs
527  * @icmpv6_resp: stats for icmpv6 resps
528  * @icmpv6_ns: stats for icmpv6 nss
529  * @icmpv6_na: stats for icmpv6 nas
530  * @icmpv6_rs: stats for icmpv6 rss
531  * @icmpv6_ra: stats for icmpv6 ras
532  * @proto_event_bitmap: defines which protocol to be diag logged.
533  *  refer QDF_NBUF_PKT_TRAC_TYPE_DNS to QDF_NBUF_PKT_TRAC_TYPE_ARP
534  *  for bitmap.
535  */
536 struct s_qdf_dp_trace_data {
537 	uint32_t head;
538 	uint32_t tail;
539 	uint32_t num;
540 	uint32_t proto_bitmap;
541 	uint8_t no_of_record;
542 	uint16_t num_records_to_dump;
543 	uint16_t dump_counter;
544 	uint8_t verbosity;
545 	uint8_t ini_conf_verbosity;
546 	bool enable;
547 	bool live_mode_config;
548 	bool live_mode;
549 	uint32_t curr_pos;
550 	uint32_t saved_tail;
551 	bool force_live_mode;
552 	bool dynamic_verbosity_modify;
553 	uint8_t print_pkt_cnt;
554 	uint8_t high_tput_thresh;
555 	uint16_t thresh_time_limit;
556 	/* Stats */
557 	uint32_t tx_count;
558 	uint32_t rx_count;
559 	u16 arp_req;
560 	u16 arp_resp;
561 	u16 dhcp_disc;
562 	u16 dhcp_req;
563 	u16 dhcp_off;
564 	u16 dhcp_ack;
565 	u16 dhcp_nack;
566 	u16 dhcp_others;
567 	u16 eapol_m1;
568 	u16 eapol_m2;
569 	u16 eapol_m3;
570 	u16 eapol_m4;
571 	u16 eapol_others;
572 	u16 icmp_req;
573 	u16 icmp_resp;
574 	u16 icmpv6_req;
575 	u16 icmpv6_resp;
576 	u16 icmpv6_ns;
577 	u16 icmpv6_na;
578 	u16 icmpv6_rs;
579 	u16 icmpv6_ra;
580 	uint32_t proto_event_bitmap;
581 };
582 
583 /**
584  * struct qdf_dpt_debugfs_state - state to control read to debugfs file
585  * @QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INVALID: invalid state
586  * @QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INIT: initial state
587  * @QDF_DPT_DEBUGFS_STATE_SHOW_IN_PROGRESS: read is in progress
588  * @QDF_DPT_DEBUGFS_STATE_SHOW_COMPLETE:  read complete
589  */
590 
591 enum qdf_dpt_debugfs_state {
592 	QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INVALID,
593 	QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INIT,
594 	QDF_DPT_DEBUGFS_STATE_SHOW_IN_PROGRESS,
595 	QDF_DPT_DEBUGFS_STATE_SHOW_COMPLETE,
596 };
597 
598 #define QDF_WIFI_MODULE_PARAMS_FILE "wifi_module_param.ini"
599 
600 typedef void (*tp_qdf_trace_cb)(void *p_mac, tp_qdf_trace_record, uint16_t);
601 typedef void (*tp_qdf_state_info_cb) (char **buf, uint16_t *size);
602 #ifdef WLAN_FEATURE_MEMDUMP_ENABLE
603 void qdf_register_debugcb_init(void);
604 void qdf_register_debug_callback(QDF_MODULE_ID module_id,
605 					tp_qdf_state_info_cb qdf_state_infocb);
606 QDF_STATUS qdf_state_info_dump_all(char *buf, uint16_t size,
607 			uint16_t *driver_dump_size);
608 #else /* WLAN_FEATURE_MEMDUMP_ENABLE */
609 static inline void qdf_register_debugcb_init(void)
610 {
611 }
612 #endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
613 
614 #ifdef TRACE_RECORD
615 void qdf_trace_register(QDF_MODULE_ID, tp_qdf_trace_cb);
616 void qdf_trace_init(void);
617 void qdf_trace_deinit(void);
618 void qdf_trace(uint8_t module, uint16_t code, uint16_t session, uint32_t data);
619 void qdf_trace_enable(uint32_t, uint8_t enable);
620 void qdf_trace_dump_all(void *, uint8_t, uint8_t, uint32_t, uint32_t);
621 QDF_STATUS qdf_trace_spin_lock_init(void);
622 #else
623 #ifndef QDF_TRACE_PRINT_ENABLE
624 static inline
625 void qdf_trace_init(void)
626 {
627 }
628 
629 static inline
630 void qdf_trace_deinit(void)
631 {
632 }
633 
634 static inline
635 void qdf_trace_enable(uint32_t bitmask_of_module_id, uint8_t enable)
636 {
637 }
638 
639 static inline
640 void qdf_trace(uint8_t module, uint16_t code, uint16_t session, uint32_t data)
641 {
642 }
643 
644 static inline
645 void qdf_trace_dump_all(void *p_mac, uint8_t code, uint8_t session,
646 			uint32_t count, uint32_t bitmask_of_module)
647 {
648 }
649 
650 static inline
651 QDF_STATUS qdf_trace_spin_lock_init(void)
652 {
653 	return QDF_STATUS_SUCCESS;
654 }
655 #endif
656 #endif
657 
658 #ifdef WLAN_MAX_LOGS_PER_SEC
659 /**
660  * qdf_detected_excessive_logging() - Excessive logging detected
661  *
662  * Track logging count using a quasi-tumbling window.
663  * If the max logging count for a given window is exceeded,
664  * return true else fails.
665  *
666  * Return: true/false
667  */
668 bool qdf_detected_excessive_logging(void);
669 
670 /**
671  * qdf_rl_print_count_set() - set the ratelimiting print count
672  * @rl_print_time: ratelimiting print count
673  *
674  * Return: none
675  */
676 void qdf_rl_print_count_set(uint32_t rl_print_count);
677 
678 /**
679  * qdf_rl_print_time_set() - set the ratelimiting print time
680  * @rl_print_time: ratelimiting print time
681  *
682  * Return: none
683  */
684 void qdf_rl_print_time_set(uint32_t rl_print_time);
685 
686 /**
687  * qdf_rl_print_supressed_log() - print the supressed logs count
688  *
689  * Return: none
690  */
691 void qdf_rl_print_supressed_log(void);
692 
693 /**
694  * qdf_rl_print_supressed_inc() - increment the supressed logs count
695  *
696  * Return: none
697  */
698 void qdf_rl_print_supressed_inc(void);
699 
700 #else /* WLAN_MAX_LOGS_PER_SEC */
701 static inline bool qdf_detected_excessive_logging(void)
702 {
703 	return false;
704 }
705 static inline void qdf_rl_print_count_set(uint32_t rl_print_count) {}
706 static inline void qdf_rl_print_time_set(uint32_t rl_print_time) {}
707 static inline void qdf_rl_print_supressed_log(void) {}
708 static inline void qdf_rl_print_supressed_inc(void) {}
709 #endif /* WLAN_MAX_LOGS_PER_SEC */
710 
711 #ifdef ENABLE_MTRACE_LOG
712 /**
713  * qdf_mtrace_log() - Logs a message tracepoint to DIAG
714  * Infrastructure.
715  * @src_module: Enum of source module (basically module id)
716  * from where the message with message_id is posted.
717  * @dst_module: Enum of destination module (basically module id)
718  * to which the message with message_id is posted.
719  * @message_id: Id of the message to be posted
720  * @vdev_id: Vdev Id
721  *
722  * This function logs to the DIAG Infrastructure a tracepoint for a
723  * message being sent from a source module to a destination module
724  * with a specific ID for the benefit of a specific vdev.
725  * For non-vdev messages vdev_id will be NO_SESSION
726  * Return: None
727  */
728 void qdf_mtrace_log(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
729 		    uint16_t message_id, uint8_t vdev_id);
730 #else
731 static inline
732 void qdf_mtrace_log(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
733 		    uint16_t message_id, uint8_t vdev_id)
734 {
735 }
736 #endif
737 
738 #ifdef TRACE_RECORD
739 /**
740  * qdf_mtrace() - puts the messages in to ring-buffer
741  * and logs a message tracepoint to DIAG Infrastructure.
742  * @src_module: Enum of source module (basically module id)
743  * from where the message with message_id is posted.
744  * @dst_module: Enum of destination module (basically module id)
745  * to which the message with message_id is posted.
746  * @message_id: Id of the message to be posted
747  * @vdev_id: Vdev Id
748  * @data: Actual message contents
749  *
750  * This function will be called from each module which wants to record the
751  * messages in circular queue. Before calling this function make sure you
752  * have registered your module with qdf through qdf_trace_register function.
753  * In addition of the recording the messages in circular queue this function
754  * will log the message tracepoint to the  DIAG infrastructure.
755  * these logs will be later used by post processing script.
756  *
757  * Return: None
758  */
759 void qdf_mtrace(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
760 		uint16_t message_id, uint8_t vdev_id, uint32_t data);
761 #else
762 static inline
763 void qdf_mtrace(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
764 		uint16_t message_id, uint8_t vdev_id, uint32_t data)
765 {
766 }
767 #endif
768 
769 #ifdef CONFIG_DP_TRACE
770 void qdf_dp_set_proto_bitmap(uint32_t val);
771 void qdf_dp_trace_set_verbosity(uint32_t val);
772 void qdf_dp_set_no_of_record(uint32_t val);
773 #define QDF_DP_TRACE_RECORD_INFO_LIVE (0x1)
774 #define QDF_DP_TRACE_RECORD_INFO_THROTTLED (0x1 << 1)
775 
776 /**
777  * qdf_dp_trace_log_pkt() - log packet type enabled through iwpriv
778  * @vdev_id: vdev_id
779  * @skb: skb pointer
780  * @dir: direction
781  * @pdev_id: pdev_id
782  *
783  * Return: true: some protocol was logged, false: no protocol was logged.
784  */
785 bool qdf_dp_trace_log_pkt(uint8_t vdev_id, struct sk_buff *skb,
786 			  enum qdf_proto_dir dir, uint8_t pdev_id);
787 
788 void qdf_dp_trace_init(bool live_mode_config, uint8_t thresh,
789 				uint16_t time_limit, uint8_t verbosity,
790 				uint32_t proto_bitmap);
791 void qdf_dp_trace_deinit(void);
792 void qdf_dp_trace_spin_lock_init(void);
793 void qdf_dp_trace_set_value(uint32_t proto_bitmap, uint8_t no_of_records,
794 			    uint8_t verbosity);
795 void qdf_dp_trace_set_track(qdf_nbuf_t nbuf, enum qdf_proto_dir dir);
796 void qdf_dp_trace(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code, uint8_t pdev_id,
797 			uint8_t *data, uint8_t size, enum qdf_proto_dir dir);
798 void qdf_dp_trace_dump_all(uint32_t count, uint8_t pdev_id);
799 
800 /**
801  * qdf_dpt_get_curr_pos_debugfs() - get curr position to start read
802  * @file: debugfs file to read
803  * @state: state to control read to debugfs file
804  *
805  * Return: curr pos
806  */
807 uint32_t qdf_dpt_get_curr_pos_debugfs(qdf_debugfs_file_t file,
808 				enum qdf_dpt_debugfs_state state);
809 /**
810  * qdf_dpt_dump_stats_debugfs() - dump DP Trace stats to debugfs file
811  * @file: debugfs file to read
812  * @curr_pos: curr position to start read
813  *
814  * Return: QDF_STATUS
815  */
816 QDF_STATUS qdf_dpt_dump_stats_debugfs(qdf_debugfs_file_t file,
817 				      uint32_t curr_pos);
818 
819 /**
820  * qdf_dpt_set_value_debugfs() - set value of DP Trace debugfs params
821  * @proto_bitmap: defines which protocol to be traced
822  * @no_of_record: defines every nth packet to be traced
823  * @verbosity : defines verbosity level
824  * @num_records_to_dump: defines number of records to be dumped
825  *
826  * Return: none
827  */
828 void qdf_dpt_set_value_debugfs(uint8_t proto_bitmap, uint8_t no_of_record,
829 			    uint8_t verbosity, uint16_t num_records_to_dump);
830 
831 
832 /**
833  * qdf_dp_trace_dump_stats() - dump DP Trace stats
834  *
835  * Return: none
836  */
837 void qdf_dp_trace_dump_stats(void);
838 typedef void (*tp_qdf_dp_trace_cb)(struct qdf_dp_trace_record_s*,
839 				   uint16_t, uint8_t, uint8_t info);
840 /**
841  * qdf_dp_display_record() - Displays a record in DP trace
842  * @record: pointer to a record in DP trace
843  * @index: record index
844  * @pdev_id: pdev id for the mgmt pkt
845  * @info: info used to display pkt (live mode, throttling)
846  *
847  * Return: None
848  */
849 void qdf_dp_display_record(struct qdf_dp_trace_record_s *record,
850 			   uint16_t index, uint8_t pdev_id,
851 			   uint8_t info);
852 
853 /**
854  * qdf_dp_display_ptr_record() - display record
855  * @record: dptrace record
856  * @rec_index: index
857  * @pdev_id: pdev id for the mgmt pkt
858  * @info: info used to display pkt (live mode, throttling)
859  *
860  * Return: none
861  */
862 void qdf_dp_display_ptr_record(struct qdf_dp_trace_record_s *record,
863 			       uint16_t rec_index, uint8_t pdev_id,
864 			       uint8_t info);
865 
866 /**
867  * qdf_dp_display_proto_pkt() - display proto packet
868  * @record: dptrace record
869  * @index: index
870  * @pdev_id: pdev id for the mgmt pkt
871  * @info: info used to display pkt (live mode, throttling)
872  *
873  * Return: none
874  */
875 void qdf_dp_display_proto_pkt(struct qdf_dp_trace_record_s *record,
876 			      uint16_t index, uint8_t pdev_id,
877 			      uint8_t info);
878 /**
879  * qdf_dp_display_data_pkt_record() - Displays a data packet in DP trace
880  * @record: pointer to a record in DP trace
881  * @rec_index: record index
882  * @pdev_id: pdev id
883  * @info: display info regarding record
884  *
885  * Return: None
886  */
887 void
888 qdf_dp_display_data_pkt_record(struct qdf_dp_trace_record_s *record,
889 			       uint16_t rec_index, uint8_t pdev_id,
890 			       uint8_t info);
891 
892 /**
893  * qdf_dp_get_status_from_htt() - Convert htt tx status to qdf dp status
894  * @status : htt_tx_status which needs to be converted
895  *
896  * Return : the status that from qdf_dp_tx_rx_status
897  */
898 enum qdf_dp_tx_rx_status qdf_dp_get_status_from_htt(uint8_t status);
899 /**
900  * qdf_dp_get_status_from_a_status() - Convert A_STATUS to qdf dp status
901  * @status : A_STATUS which needs to be converted
902  *
903  * Return : the status that from qdf_dp_tx_rx_status
904  */
905 enum qdf_dp_tx_rx_status qdf_dp_get_status_from_a_status(uint8_t status);
906 /**
907  * qdf_dp_trace_ptr() - record dptrace
908  * @code: dptrace code
909  * @pdev_id: pdev_id
910  * @data: data
911  * @size: size of data
912  * @msdu_id: msdu_id
913  * @status: return status
914  * @qdf_tx_status: qdf tx rx status
915  *
916  * Return: none
917  */
918 void qdf_dp_trace_ptr(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code,
919 		      uint8_t pdev_id, uint8_t *data, uint8_t size,
920 		      uint16_t msdu_id, uint16_t buf_arg_status,
921 		      enum qdf_dp_tx_rx_status qdf_tx_status);
922 void qdf_dp_trace_throttle_live_mode(bool high_bw_request);
923 
924 /**
925  * qdf_dp_trace_tput_policy() - Change verbosity based on the TPUT
926  * @is_data_traffic: Is traffic more than low TPUT threashould
927  *
928  * Return: None
929  */
930 void qdf_dp_trace_apply_tput_policy(bool is_data_traffic);
931 
932 /**
933  * qdf_dp_trace_data_pkt() - trace data packet
934  * @nbuf: nbuf which needs to be traced
935  * @pdev_id: pdev_id
936  * @code: QDF_DP_TRACE_ID for the packet (TX or RX)
937  * @msdu_id: tx desc id for the nbuf (Only applies to TX packets)
938  * @dir: TX or RX packet direction
939  *
940  * Return: None
941  */
942 void qdf_dp_trace_data_pkt(qdf_nbuf_t nbuf, uint8_t pdev_id,
943 			   enum QDF_DP_TRACE_ID code, uint16_t msdu_id,
944 			   enum qdf_proto_dir dir);
945 
946 uint32_t qdf_dp_get_proto_bitmap(void);
947 uint8_t qdf_dp_get_verbosity(void);
948 uint8_t qdf_dp_get_no_of_record(void);
949 
950 /**
951  * qdf_dp_trace_proto_pkt() - record proto packet
952  * @code: dptrace code
953  * @vdev_id: vdev id
954  * @sa: source mac address
955  * @da: destination mac address
956  * @type: proto type
957  * @subtype: proto subtype
958  * @dir: direction
959  * @pdev_id: pdev id
960  * @print: to print this proto pkt or not
961  * @proto_priv_data: protocol specific private
962  * data.
963  * Return: none
964  */
965 void
966 qdf_dp_trace_proto_pkt(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
967 	uint8_t *sa, uint8_t *da, enum qdf_proto_type type,
968 	enum qdf_proto_subtype subtype, enum qdf_proto_dir dir,
969 	uint8_t pdev_id, bool print, uint32_t proto_priv_data);
970 
971 void qdf_dp_trace_disable_live_mode(void);
972 void qdf_dp_trace_enable_live_mode(void);
973 void qdf_dp_trace_clear_buffer(void);
974 /**
975  * qdf_dp_trace_mgmt_pkt() - record mgmt packet
976  * @code: dptrace code
977  * @vdev_id: vdev id
978  * @pdev_id: pdev_id
979  * @type: proto type
980  * @subtype: proto subtype
981  *
982  * Return: none
983  */
984 void qdf_dp_trace_mgmt_pkt(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
985 			   uint8_t pdev_id, enum qdf_proto_type type,
986 			   enum qdf_proto_subtype subtype);
987 
988 /**
989  * qdf_dp_trace_credit_record() - record credit update
990  * @source: source of record
991  * @operation: credit operation
992  * @delta: credit delta
993  * @total_credits: total credit
994  * @g0_credit: group 0 credit
995  * @g1_credit: group 1 credit
996  */
997 void qdf_dp_trace_credit_record(enum QDF_CREDIT_UPDATE_SOURCE source,
998 				enum QDF_CREDIT_OPERATION operation,
999 				int delta, int total_credits,
1000 				int g0_credit, int g1_credit);
1001 
1002 /**
1003  * qdf_dp_display_mgmt_pkt() - display proto packet
1004  * @record: dptrace record
1005  * @index: index
1006  * @pdev_id: pdev id for the mgmt pkt
1007  * @info: info used to display pkt (live mode, throttling)
1008  *
1009  * Return: none
1010  */
1011 void qdf_dp_display_mgmt_pkt(struct qdf_dp_trace_record_s *record,
1012 			     uint16_t index, uint8_t pdev_id, uint8_t info);
1013 
1014 /**
1015  * qdf_dp_display_credit_record() - display credit record
1016  * @record: dptrace record
1017  * @index: index
1018  * @pdev_id: pdev id
1019  * @info: metadeta info
1020  */
1021 void qdf_dp_display_credit_record(struct qdf_dp_trace_record_s *record,
1022 				  uint16_t index, uint8_t pdev_id,
1023 				  uint8_t info);
1024 
1025 /**
1026  * qdf_dp_display_event_record() - display event records
1027  * @record: dptrace record
1028  * @index: index
1029  * @pdev_id: pdev id for the mgmt pkt
1030  * @info: info used to display pkt (live mode, throttling)
1031  *
1032  * Return: none
1033  */
1034 void qdf_dp_display_event_record(struct qdf_dp_trace_record_s *record,
1035 				 uint16_t index, uint8_t pdev_id, uint8_t info);
1036 
1037 void qdf_dp_trace_record_event(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
1038 			       uint8_t pdev_id, enum qdf_proto_type type,
1039 			       enum qdf_proto_subtype subtype);
1040 
1041 /**
1042  * qdf_dp_set_proto_event_bitmap() - Set the protocol event bitmap
1043  * @value: proto event bitmap value.
1044  *
1045  * QDF_NBUF_PKT_TRAC_TYPE_DNS       0x01
1046  * QDF_NBUF_PKT_TRAC_TYPE_EAPOL     0x02
1047  * QDF_NBUF_PKT_TRAC_TYPE_DHCP      0x04
1048  * QDF_NBUF_PKT_TRAC_TYPE_ARP       0x10
1049  *
1050  * Return: none
1051  */
1052 void qdf_dp_set_proto_event_bitmap(uint32_t value);
1053 
1054 /**
1055  * qdf_dp_log_proto_pkt_info() - Send diag log event
1056  * @sa: source MAC address
1057  * @da: destination MAC address
1058  * @type: pkt type
1059  * @subtype: pkt subtype
1060  * @dir: tx or rx
1061  * @msdu_id: msdu id
1062  * @status: status
1063  *
1064  * Return: none
1065  */
1066 void qdf_dp_log_proto_pkt_info(uint8_t *sa, uint8_t *da, uint8_t type,
1067 			       uint8_t subtype, uint8_t dir, uint16_t msdu_id,
1068 			       uint8_t status);
1069 
1070 /**
1071  * qdf_dp_track_noack_check() - Check if no ack count should be tracked for
1072  *  the configured protocol packet types
1073  * @nbuf: nbuf
1074  * @subtype: subtype of packet to be tracked
1075  *
1076  * Return: none
1077  */
1078 void qdf_dp_track_noack_check(qdf_nbuf_t nbuf, enum qdf_proto_subtype *subtype);
1079 #else
1080 static inline
1081 bool qdf_dp_trace_log_pkt(uint8_t vdev_id, struct sk_buff *skb,
1082 			  enum qdf_proto_dir dir, uint8_t pdev_id)
1083 {
1084 	return false;
1085 }
1086 static inline
1087 void qdf_dp_trace_init(bool live_mode_config, uint8_t thresh,
1088 				uint16_t time_limit, uint8_t verbosity,
1089 				uint32_t proto_bitmap)
1090 {
1091 }
1092 
1093 static inline
1094 void qdf_dp_trace_deinit(void)
1095 {
1096 }
1097 
1098 static inline
1099 void qdf_dp_trace_set_track(qdf_nbuf_t nbuf, enum qdf_proto_dir dir)
1100 {
1101 }
1102 static inline
1103 void qdf_dp_trace_set_value(uint32_t proto_bitmap, uint8_t no_of_records,
1104 			    uint8_t verbosity)
1105 {
1106 }
1107 
1108 static inline
1109 void qdf_dp_trace_dump_all(uint32_t count, uint8_t pdev_id)
1110 {
1111 }
1112 
1113 static inline
1114 uint32_t qdf_dpt_get_curr_pos_debugfs(qdf_debugfs_file_t file,
1115 				      enum qdf_dpt_debugfs_state state)
1116 {
1117 	return 0;
1118 }
1119 
1120 static inline
1121 QDF_STATUS qdf_dpt_dump_stats_debugfs(qdf_debugfs_file_t file,
1122 				      uint32_t curr_pos)
1123 {
1124 	return QDF_STATUS_SUCCESS;
1125 }
1126 
1127 static inline
1128 void qdf_dpt_set_value_debugfs(uint8_t proto_bitmap, uint8_t no_of_record,
1129 			    uint8_t verbosity, uint16_t num_records_to_dump)
1130 {
1131 }
1132 
1133 static inline void qdf_dp_trace_dump_stats(void)
1134 {
1135 }
1136 
1137 static inline
1138 void qdf_dp_trace_disable_live_mode(void)
1139 {
1140 }
1141 
1142 static inline
1143 void qdf_dp_trace_enable_live_mode(void)
1144 {
1145 }
1146 
1147 static inline
1148 void qdf_dp_trace_throttle_live_mode(bool high_bw_request)
1149 {
1150 }
1151 
1152 static inline
1153 void qdf_dp_trace_clear_buffer(void)
1154 {
1155 }
1156 
1157 static inline
1158 void qdf_dp_trace_apply_tput_policy(bool is_data_traffic)
1159 {
1160 }
1161 
1162 static inline
1163 void qdf_dp_trace_data_pkt(qdf_nbuf_t nbuf, uint8_t pdev_id,
1164 			   enum QDF_DP_TRACE_ID code, uint16_t msdu_id,
1165 			   enum qdf_proto_dir dir)
1166 {
1167 }
1168 
1169 static inline
1170 void qdf_dp_log_proto_pkt_info(uint8_t *sa, uint8_t *da, uint8_t type,
1171 			       uint8_t subtype, uint8_t dir, uint16_t msdu_id,
1172 			       uint8_t status)
1173 {
1174 }
1175 
1176 static inline
1177 void qdf_dp_track_noack_check(qdf_nbuf_t nbuf, enum qdf_proto_subtype *subtype)
1178 {
1179 }
1180 
1181 static inline
1182 enum qdf_dp_tx_rx_status qdf_dp_get_status_from_htt(uint8_t status)
1183 {
1184 	return QDF_TX_RX_STATUS_OK;
1185 }
1186 
1187 static inline
1188 enum qdf_dp_tx_rx_status qdf_dp_get_status_from_a_status(uint8_t status)
1189 {
1190 	return QDF_TX_RX_STATUS_OK;
1191 }
1192 #endif
1193 
1194 void qdf_trace_display(void);
1195 
1196 int __printf(3, 4) qdf_snprintf(char *str_buffer, unsigned int size,
1197 				char *str_format, ...);
1198 
1199 #define QDF_SNPRINTF qdf_snprintf
1200 
1201 #ifdef TSOSEG_DEBUG
1202 
1203 static inline void qdf_tso_seg_dbg_bug(char *msg)
1204 {
1205 	qdf_print("%s", msg);
1206 	QDF_BUG(0);
1207 };
1208 
1209 /**
1210  * qdf_tso_seg_dbg_init - initialize TSO segment debug structure
1211  * @tsoseg : structure to initialize
1212  *
1213  * TSO segment dbg structures are attached to qdf_tso_seg_elem_t
1214  * structures and are allocated only of TSOSEG_DEBUG is defined.
1215  * When allocated, at the time of the tso_seg_pool initialization,
1216  * which goes with tx_desc initialization (1:1), each structure holds
1217  * a number of (currently 16) history entries, basically describing
1218  * what operation has been performed on this particular tso_seg_elem.
1219  * This history buffer is a circular buffer and the current index is
1220  * held in an atomic variable called cur. It is incremented every
1221  * operation. Each of these operations are added with the function
1222  * qdf_tso_seg_dbg_record.
1223  * For each segment, this initialization function MUST be called PRIOR
1224  * TO any _dbg_record() function calls.
1225  * On free, qdf_tso_seg_elem structure is cleared (using qdf_tso_seg_dbg_zero)
1226  * which clears the tso_desc, BUT DOES NOT CLEAR THE HISTORY element.
1227  *
1228  * Return:
1229  *   None
1230  */
1231 static inline
1232 void qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t *tsoseg)
1233 {
1234 	tsoseg->dbg.txdesc = NULL;
1235 	qdf_atomic_init(&tsoseg->dbg.cur); /* history empty */
1236 }
1237 
1238 /**
1239  * qdf_tso_seg_dbg_record - add a history entry to TSO debug structure
1240  * @tsoseg : structure to initialize
1241  * @id     : operation ID (identifies the caller)
1242  *
1243  * Adds a history entry to the history circular buffer. Each entry
1244  * contains an operation id (caller, as currently each ID is used only
1245  * once in the source, so it directly identifies the src line that invoked
1246  * the recording.
1247  *
1248  * qdf_tso_seg_dbg_record CAN ONLY BE CALLED AFTER the entry is initialized
1249  * by qdf_tso_seg_dbg_init.
1250  *
1251  * The entry to be added is written at the location pointed by the atomic
1252  * variable called cur. Cur is an ever increasing atomic variable. It is
1253  * masked so that only the lower 4 bits are used (16 history entries).
1254  *
1255  * Return:
1256  *   int: the entry this record was recorded at
1257  */
1258 static inline
1259 int qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t *tsoseg, short id)
1260 {
1261 	int rc = -1;
1262 	unsigned int c;
1263 
1264 	qdf_assert(tsoseg);
1265 
1266 	if (id == TSOSEG_LOC_ALLOC) {
1267 		c = qdf_atomic_read(&tsoseg->dbg.cur);
1268 		/* dont crash on the very first alloc on the segment */
1269 		c &= 0x0f;
1270 		/* allow only INIT and FREE ops before ALLOC */
1271 		if (tsoseg->dbg.h[c].id >= id)
1272 			qdf_tso_seg_dbg_bug("Rogue TSO seg alloc");
1273 	}
1274 	c = qdf_atomic_inc_return(&tsoseg->dbg.cur);
1275 
1276 	c &= 0x0f;
1277 	tsoseg->dbg.h[c].ts = qdf_get_log_timestamp();
1278 	tsoseg->dbg.h[c].id = id;
1279 	rc = c;
1280 
1281 	return rc;
1282 };
1283 
1284 static inline void
1285 qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t *tsoseg, void *owner)
1286 {
1287 	if (tsoseg)
1288 		tsoseg->dbg.txdesc = owner;
1289 };
1290 
1291 static inline void
1292 qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t *tsoseg)
1293 {
1294 	memset(tsoseg, 0, offsetof(struct qdf_tso_seg_elem_t, dbg));
1295 	return;
1296 };
1297 
1298 #else
1299 static inline
1300 void qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t *tsoseg)
1301 {
1302 };
1303 static inline
1304 int qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t *tsoseg, short id)
1305 {
1306 	return 0;
1307 };
1308 static inline void qdf_tso_seg_dbg_bug(char *msg)
1309 {
1310 };
1311 static inline void
1312 qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t *tsoseg, void *owner)
1313 {
1314 };
1315 static inline int
1316 qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t *tsoseg)
1317 {
1318 	memset(tsoseg, 0, sizeof(struct qdf_tso_seg_elem_t));
1319 	return 0;
1320 };
1321 
1322 #endif /* TSOSEG_DEBUG */
1323 
1324 /**
1325  * qdf_trace_hex_dump() - externally called hex dump function
1326  * @module: Module identifier a member of the QDF_MODULE_ID enumeration that
1327  * identifies the module issuing the trace message.
1328  * @level: Trace level a member of the QDF_TRACE_LEVEL enumeration indicating
1329  * the severity of the condition causing the trace message to be
1330  * issued. More severe conditions are more likely to be logged.
1331  * @data: The base address of the buffer to be logged.
1332  * @buf_len: The size of the buffer to be logged.
1333  *
1334  * Checks the level of severity and accordingly prints the trace messages
1335  *
1336  * Return:  None
1337  */
1338 void qdf_trace_hex_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
1339 			void *data, int buf_len);
1340 
1341 /**
1342  * qdf_trace_hex_ascii_dump() - externally called hex and ascii dump function
1343  * @module: Module identifier a member of the QDF_MODULE_ID enumeration that
1344  * identifies the module issuing the trace message.
1345  * @level: Trace level a member of the QDF_TRACE_LEVEL enumeration indicating
1346  * the severity of the condition causing the trace message to be
1347  * issued. More severe conditions are more likely to be logged.
1348  * @data: The base address of the buffer to be logged.
1349  * @buf_len: The size of the buffer to be logged.
1350  *
1351  * Checks the level of severity and accordingly prints the trace messages
1352  *
1353  * Return:  None
1354  */
1355 void qdf_trace_hex_ascii_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
1356 			      void *data, int buf_len);
1357 
1358 #define ERROR_CODE                      -1
1359 #define QDF_MAX_NAME_SIZE               32
1360 #define MAX_PRINT_CONFIG_SUPPORTED      32
1361 
1362 #define MAX_SUPPORTED_CATEGORY QDF_MODULE_ID_MAX
1363 
1364 /**
1365  * qdf_set_pidx() - Sets the global qdf_pidx.
1366  * @pidx : Index of print control object assigned to the module
1367  *
1368  */
1369 void qdf_set_pidx(int pidx);
1370 
1371 /**
1372  * qdf_get_pidx() - Returns the global qdf_pidx.
1373  *
1374  * Return : Current qdf print index.
1375  */
1376 int qdf_get_pidx(void);
1377 /*
1378  * Shared print control index
1379  * for converged debug framework
1380  */
1381 
1382 #define QDF_PRINT_IDX_SHARED -1
1383 
1384 /**
1385  * QDF_PRINT_INFO() - Generic wrapper API for logging
1386  * @idx : Index of print control object
1387  * @module : Module identifier. A member of QDF_MODULE_ID enumeration that
1388  *           identifies the module issuing the trace message
1389  * @level : Trace level. A member of QDF_TRACE_LEVEL enumeration indicating
1390  *          the severity of the condition causing the trace message to be
1391  *          issued.
1392  * @str_format : Format string that contains the message to be logged.
1393  *
1394  *
1395  * This wrapper will be used for any generic logging messages. Wrapper will
1396  * compile a call to converged QDF trace message API.
1397  *
1398  * Return : Nothing
1399  *
1400  */
1401 void QDF_PRINT_INFO(unsigned int idx, QDF_MODULE_ID module,
1402 		    QDF_TRACE_LEVEL level,
1403 		    char *str_format, ...);
1404 
1405 /**
1406  * struct category_info  : Category information structure
1407  * @category_verbose_mask: Embeds information about category's verbose level
1408  */
1409 struct category_info {
1410 	uint16_t category_verbose_mask;
1411 };
1412 
1413 /**
1414  * struct category_name_info  : Category name information structure
1415  * @category_name_str: Embeds information about category name
1416  */
1417 struct category_name_info {
1418 	unsigned char category_name_str[QDF_MAX_NAME_SIZE];
1419 };
1420 
1421 /**
1422  * qdf_trace_msg_cmn()- Converged logging API
1423  * @idx: Index of print control object assigned to the module
1424  * @category: Category identifier. A member of the QDF_MODULE_ID enumeration
1425  *            that identifies the category issuing the trace message.
1426  * @verbose: Verbose level. A member of the QDF_TRACE_LEVEL enumeration
1427  *           indicating the severity of the condition causing the trace
1428  *           message to be issued. More severe conditions are more likely
1429  *           to be logged.
1430  * @str_format: Format string. The message to be logged. This format string
1431  *              contains printf-like replacement parameters, which follow this
1432  *              parameter in the variable argument list.
1433  * @val: Variable argument list part of the log message
1434  *
1435  * Return: nothing
1436  *
1437  */
1438 void qdf_trace_msg_cmn(unsigned int idx,
1439 			QDF_MODULE_ID category,
1440 			QDF_TRACE_LEVEL verbose,
1441 			const char *str_format,
1442 			va_list val);
1443 
1444 /**
1445  * struct qdf_print_ctrl: QDF Print Control structure
1446  *                        Statically allocated objects of print control
1447  *                        structure are declared that will support maximum of
1448  *                        32 print control objects. Any module that needs to
1449  *                        register to the print control framework needs to
1450  *                        obtain a print control object using
1451  *                        qdf_print_ctrl_register API. It will have to pass
1452  *                        pointer to category info structure, name and
1453  *                        custom print function to be used if required.
1454  * @name                : Optional name for the control object
1455  * @cat_info            : Array of category_info struct
1456  * @custom_print        : Custom print handler
1457  * @custom_ctxt         : Custom print context
1458  * @dbglvlmac_on        : Flag to enable/disable MAC level filtering
1459  * @in_use              : Boolean to indicate if control object is in use
1460  */
1461 struct qdf_print_ctrl {
1462 	char name[QDF_MAX_NAME_SIZE];
1463 	struct category_info cat_info[MAX_SUPPORTED_CATEGORY];
1464 	void (*custom_print)(void *ctxt, const char *fmt, va_list args);
1465 	void *custom_ctxt;
1466 #ifdef DBG_LVL_MAC_FILTERING
1467 	unsigned char dbglvlmac_on;
1468 #endif
1469 	bool in_use;
1470 };
1471 
1472 /**
1473  * qdf_print_ctrl_register() - Allocate QDF print control object, assign
1474  *                             pointer to category info or print control
1475  *                             structure and return the index to the callee
1476  * @cinfo                 : Pointer to array of category info structure
1477  * @custom_print_handler  : Pointer to custom print handler
1478  * @custom_ctx            : Pointer to custom context
1479  * @pctrl_name            : Pointer to print control object name
1480  *
1481  * Return                 : Index of qdf_print_ctrl structure
1482  *
1483  */
1484 int qdf_print_ctrl_register(const struct category_info *cinfo,
1485 			    void *custom_print_handler,
1486 			    void *custom_ctx,
1487 			    const char *pctrl_name);
1488 
1489 #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
1490 /**
1491  * qdf_update_module_param() - Update qdf module params
1492  *
1493  *
1494  * Read the file which has wifi module params, parse and update
1495  * qdf module params.
1496  *
1497  * Return: void
1498  */
1499 void qdf_initialize_module_param_from_ini(void);
1500 #else
1501 static inline
1502 void qdf_initialize_module_param_from_ini(void)
1503 {
1504 }
1505 #endif
1506 
1507 /**
1508  * qdf_shared_print_ctrl_init() - Initialize the shared print ctrl obj with
1509  *                                all categories set to the default level
1510  *
1511  * Return                 : void
1512  *
1513  */
1514 void qdf_shared_print_ctrl_init(void);
1515 
1516 /**
1517  * qdf_print_setup() - Setup default values to all the print control objects
1518  *
1519  * Register new print control object for the callee
1520  *
1521  * Return :             QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE
1522  *                      on failure
1523  */
1524 QDF_STATUS qdf_print_setup(void);
1525 
1526 /**
1527  * qdf_print_ctrl_cleanup() - Clean up a print control object
1528  *
1529  * Cleanup the print control object for the callee
1530  *
1531  * @pctrl : Index of print control object
1532  *
1533  * Return : QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE on failure
1534  */
1535 QDF_STATUS qdf_print_ctrl_cleanup(unsigned int idx);
1536 
1537 /**
1538  * qdf_print_ctrl_shared_cleanup() - Clean up of the shared object
1539  *
1540  * Cleanup the shared print-ctrl-object
1541  *
1542  * Return : void
1543  */
1544 void qdf_shared_print_ctrl_cleanup(void);
1545 
1546 /**
1547  * qdf_print_set_category_verbose() - Enable/Disable category for a
1548  *                                    print control object with
1549  *                                    user provided verbose level
1550  *
1551  * @idx : Index of the print control object assigned to callee
1552  * @category : Category information
1553  * @verbose: Verbose information
1554  * @is_set: Flag indicating if verbose level needs to be enabled or disabled
1555  *
1556  * Return : QDF_STATUS_SUCCESS for success and QDF_STATUS_E_FAILURE for failure
1557  */
1558 QDF_STATUS qdf_print_set_category_verbose(unsigned int idx,
1559 					  QDF_MODULE_ID category,
1560 					  QDF_TRACE_LEVEL verbose,
1561 					  bool is_set);
1562 
1563 /**
1564  * qdf_log_dump_at_kernel_level() - Enable/Disable printk call
1565  * @enable: Indicates whether printk is enabled in QDF_TRACE
1566  *
1567  * Return: void
1568  */
1569 void qdf_log_dump_at_kernel_level(bool enable);
1570 
1571 /**
1572  * qdf_logging_set_flush_timer() - Set the time period in which host logs
1573  *                                 should be flushed out to user-space
1574  * @milliseconds: milliseconds after which the logs should be flushed out to
1575  *                 user-space
1576  *
1577  * Return: QDF_STATUS_SUCCESS for success and QDF_STATUS_E_FAILURE for failure
1578  */
1579 int qdf_logging_set_flush_timer(uint32_t milliseconds);
1580 
1581 /**
1582  * qdf_logging_flush_logs() - Flush out the logs to user-space one time
1583  *
1584  * Return: void
1585  */
1586 void qdf_logging_flush_logs(void);
1587 
1588 /**
1589  * qdf_print_is_category_enabled() - Get category information for the
1590  *                                   print control object
1591  *
1592  * @idx : Index of print control object
1593  * @category : Category information
1594  *
1595  * Return : Verbose enabled(true) or disabled(false) or invalid input (false)
1596  */
1597 bool qdf_print_is_category_enabled(unsigned int idx,
1598 				   QDF_MODULE_ID category);
1599 
1600 /**
1601  * qdf_print_is_verbose_enabled() - Get verbose information of a category for
1602  *                                  the print control object
1603  *
1604  * @idx : Index of print control object
1605  * @category : Category information
1606  * @verbose : Verbose information
1607  *
1608  * Return : Verbose enabled(true) or disabled(false) or invalid input (false)
1609  */
1610 bool qdf_print_is_verbose_enabled(unsigned int idx,
1611 				  QDF_MODULE_ID category,
1612 				  QDF_TRACE_LEVEL verbose);
1613 
1614 /**
1615  * qdf_print_clean_node_flag() - Clean up node flag for print control object
1616  *
1617  * @idx : Index of print control object
1618  *
1619  * Return : None
1620  */
1621 void qdf_print_clean_node_flag(unsigned int idx);
1622 
1623 #ifdef DBG_LVL_MAC_FILTERING
1624 
1625 /**
1626  * qdf_print_set_node_flag() - Set flag to enable MAC level filtering
1627  *
1628  * @idx : Index of print control object
1629  * @enable : Enable/Disable bit sent by callee
1630  *
1631  * Return : QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE on Failure
1632  */
1633 QDF_STATUS qdf_print_set_node_flag(unsigned int idx,
1634 				   uint8_t enable);
1635 
1636 /**
1637  * qdf_print_get_node_flag() - Get flag that controls MAC level filtering
1638  *
1639  * @idx : Index of print control object
1640  *
1641  * Return : Flag that indicates enable(1) or disable(0) or invalid(-1)
1642  */
1643 bool qdf_print_get_node_flag(unsigned int idx);
1644 
1645 #endif
1646 
1647 #ifdef QCA_WIFI_MODULE_PARAMS_FROM_INI
1648 /**
1649  * qdf_module_param_handler() - Function to store module params
1650  *
1651  * @context : NULL, unused.
1652  * @key : Name of the module param
1653  * @value: Value of the module param
1654  *
1655  * Handler function to be called from qdf_ini_parse()
1656  * function when a valid parameter is found in a file.
1657  *
1658  * Return : QDF_STATUS_SUCCESS on Success
1659  */
1660 QDF_STATUS qdf_module_param_handler(void *context, const char *key,
1661 				    const char *value);
1662 #else
1663 static inline
1664 QDF_STATUS qdf_module_param_handler(void *context, const char *key,
1665 				    const char *value)
1666 {
1667 	return QDF_STATUS_SUCCESS;
1668 }
1669 #endif
1670 
1671 /**
1672  * qdf_logging_init() - Initialize msg logging functionality
1673  *
1674  *
1675  * Return : void
1676  */
1677 void qdf_logging_init(void);
1678 
1679 /**
1680  * qdf_logging_exit() - Cleanup msg logging functionality
1681  *
1682  *
1683  * Return : void
1684  */
1685 void qdf_logging_exit(void);
1686 
1687 #define QDF_SYMBOL_LEN __QDF_SYMBOL_LEN
1688 
1689 /**
1690  * qdf_sprint_symbol() - prints the name of a symbol into a string buffer
1691  * @buffer: the string buffer to print into
1692  * @addr: address of the symbol to lookup and print
1693  *
1694  * Return: number of characters printed
1695  */
1696 int qdf_sprint_symbol(char *buffer, void *addr);
1697 
1698 /**
1699  * qdf_minidump_init() - Initialize minidump functionality
1700  *
1701  *
1702  * Return: void
1703  */
1704 static inline
1705 void qdf_minidump_init(void)
1706 {
1707 	__qdf_minidump_init();
1708 }
1709 
1710 /**
1711  * qdf_minidump_deinit() - De-initialize minidump functionality
1712  *
1713  *
1714  * Return: void
1715  */
1716 static inline
1717 void qdf_minidump_deinit(void)
1718 {
1719 	__qdf_minidump_deinit();
1720 }
1721 
1722 /**
1723  * qdf_minidump_log() - Log memory address to be included in minidump
1724  * @start_addr: Start address of the memory to be dumped
1725  * @size: Size in bytes
1726  * @name: String to identify this entry
1727  */
1728 static inline
1729 void qdf_minidump_log(void *start_addr,
1730 		      const size_t size, const char *name)
1731 {
1732 	__qdf_minidump_log(start_addr, size, name);
1733 }
1734 
1735 /**
1736  * qdf_minidump_remove() - Remove memory address from minidump
1737  * @start_addr: Start address of the memory previously added
1738  * @size: Size in bytes
1739  * @name: String to identify this entry
1740  */
1741 static inline
1742 void qdf_minidump_remove(void *start_addr,
1743 			 const size_t size, const char *name)
1744 {
1745 	__qdf_minidump_remove(start_addr, size, name);
1746 }
1747 
1748 #endif /* __QDF_TRACE_H */
1749