xref: /wlan-dirver/qca-wifi-host-cmn/qdf/inc/qdf_trace.h (revision f28396d060cff5c6519f883cb28ae0116ce479f1)
1 /*
2  * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for
5  * any purpose with or without fee is hereby granted, provided that the
6  * above copyright notice and this permission notice appear in all
7  * copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16  * PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #if !defined(__QDF_TRACE_H)
20 #define __QDF_TRACE_H
21 
22 /**
23  *  DOC: qdf_trace
24  *  QCA driver framework trace APIs
25  *  Trace, logging, and debugging definitions and APIs
26  */
27 
28 /* Include Files */
29 #include  <qdf_types.h>         /* For QDF_MODULE_ID... */
30 #include  <stdarg.h>            /* For va_list... */
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 #define FL(x)    "%s: %d: " x, __func__, __LINE__
40 
41 #define QDF_TRACE_BUFFER_SIZE (512)
42 
43 /*
44  * Extracts the 8-bit group id from the wmi command id by performing the
45  * reverse operation of WMI_CMD_GRP_START_ID
46  */
47 #define QDF_WMI_MTRACE_GRP_ID(message_id) (((message_id) >> 12) & 0xFF)
48 /*
49  * Number of bits reserved for WMI mtrace command id
50  */
51  #define QDF_WMI_MTRACE_CMD_NUM_BITS 7
52 /*
53  * Extracts the 7-bit group specific command id from the wmi command id
54  */
55 #define QDF_WMI_MTRACE_CMD_ID(message_id) ((message_id) & 0x7F)
56 
57 #ifdef QDF_TRACE_PRINT_ENABLE
58 #define QDF_DEFAULT_TRACE_LEVEL (1 << QDF_TRACE_LEVEL_INFO)
59 #endif
60 
61 #define QDF_CATEGORY_INFO_U16(val) (((val >> 16) & 0x0000FFFF))
62 #define QDF_TRACE_LEVEL_INFO_L16(val) (val & 0x0000FFFF)
63 
64 typedef int (qdf_abstract_print)(void *priv, const char *fmt, ...);
65 
66 /*
67  * Log levels
68  */
69 #define QDF_DEBUG_FUNCTRACE     0x01
70 #define QDF_DEBUG_LEVEL0        0x02
71 #define QDF_DEBUG_LEVEL1        0x04
72 #define QDF_DEBUG_LEVEL2        0x08
73 #define QDF_DEBUG_LEVEL3        0x10
74 #define QDF_DEBUG_ERROR         0x20
75 #define QDF_DEBUG_CFG           0x40
76 
77 /*
78  * Rate limit based on pkt prototype
79  */
80 #define QDF_MAX_DHCP_PKTS_PER_SEC       (10)
81 #define QDF_MAX_EAPOL_PKTS_PER_SEC      (10)
82 #define QDF_MAX_ARP_PKTS_PER_SEC        (5)
83 #define QDF_MAX_DNS_PKTS_PER_SEC        (5)
84 #define QDF_MAX_OTHER_PKTS_PER_SEC      (1)
85 
86 /* DP Trace Implementation */
87 #ifdef CONFIG_DP_TRACE
88 #define DPTRACE(p) p
89 #define DPTRACE_PRINT(args...) \
90 	QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_DEBUG, args)
91 #else
92 #define DPTRACE(p)
93 #define DPTRACE_PRINT(args...)
94 #endif
95 
96 /* By default Data Path module will have all log levels enabled, except debug
97  * log level. Debug level will be left up to the framework or user space modules
98  * to be enabled when issue is detected
99  */
100 #define QDF_DATA_PATH_TRACE_LEVEL \
101 	((1 << QDF_TRACE_LEVEL_FATAL) | (1 << QDF_TRACE_LEVEL_ERROR) | \
102 	(1 << QDF_TRACE_LEVEL_WARN) | (1 << QDF_TRACE_LEVEL_INFO) | \
103 	(1 << QDF_TRACE_LEVEL_INFO_HIGH) | (1 << QDF_TRACE_LEVEL_INFO_MED) | \
104 	(1 << QDF_TRACE_LEVEL_INFO_LOW))
105 
106 /* Preprocessor definitions and constants */
107 #define ASSERT_BUFFER_SIZE (512)
108 
109 #ifndef MAX_QDF_TRACE_RECORDS
110 #define MAX_QDF_TRACE_RECORDS 4000
111 #endif
112 
113 #define QDF_TRACE_DEFAULT_PDEV_ID 0xff
114 #define INVALID_QDF_TRACE_ADDR 0xffffffff
115 #define DEFAULT_QDF_TRACE_DUMP_COUNT 0
116 #define QDF_TRACE_DEFAULT_MSDU_ID 0
117 
118 /*
119  * first parameter to iwpriv command - dump_dp_trace
120  * iwpriv wlan0 dump_dp_trace 0 0 -> dump full buffer
121  * iwpriv wlan0 dump_dp_trace 1 0 -> enable live view mode
122  * iwpriv wlan0 dump_dp_trace 2 0 -> clear dp trace buffer
123  * iwpriv wlan0 dump_dp_trace 3 0 -> disable live view mode
124  */
125 #define DUMP_DP_TRACE			0
126 #define ENABLE_DP_TRACE_LIVE_MODE	1
127 #define CLEAR_DP_TRACE_BUFFER		2
128 #define DISABLE_DP_TRACE_LIVE_MODE	3
129 
130 
131 #ifdef TRACE_RECORD
132 
133 #define MTRACE(p) p
134 
135 #else
136 #define MTRACE(p) do { } while (0)
137 
138 #endif
139 #define NO_SESSION 0xFF
140 
141 /**
142  * typedef struct qdf_trace_record_s - keep trace record
143  * @qtime: qtimer ticks
144  * @time: user timestamp
145  * @module: module name
146  * @code: hold record of code
147  * @session: hold record of session
148  * @data: hold data
149  * @pid: hold pid of the process
150  */
151 typedef struct qdf_trace_record_s {
152 	uint64_t qtime;
153 	char time[18];
154 	uint8_t module;
155 	uint8_t code;
156 	uint16_t session;
157 	uint32_t data;
158 	uint32_t pid;
159 } qdf_trace_record_t, *tp_qdf_trace_record;
160 
161 /**
162  * typedef struct s_qdf_trace_data - MTRACE logs are stored in ring buffer
163  * @head: position of first record
164  * @tail: position of last record
165  * @num: count of total record
166  * @num_since_last_dump: count from last dump
167  * @enable: config for controlling the trace
168  * @dump_count: Dump after number of records reach this number
169  */
170 typedef struct s_qdf_trace_data {
171 	uint32_t head;
172 	uint32_t tail;
173 	uint32_t num;
174 	uint16_t num_since_last_dump;
175 	uint8_t enable;
176 	uint16_t dump_count;
177 } t_qdf_trace_data;
178 
179 #define CASE_RETURN_STRING(str) case ((str)): return (uint8_t *)(# str);
180 
181 #ifndef MAX_QDF_DP_TRACE_RECORDS
182 #define MAX_QDF_DP_TRACE_RECORDS       2000
183 #endif
184 
185 #define QDF_DP_TRACE_RECORD_SIZE       40
186 #define INVALID_QDF_DP_TRACE_ADDR      0xffffffff
187 #define QDF_DP_TRACE_VERBOSITY_HIGH		4
188 #define QDF_DP_TRACE_VERBOSITY_MEDIUM		3
189 #define QDF_DP_TRACE_VERBOSITY_LOW		2
190 #define QDF_DP_TRACE_VERBOSITY_ULTRA_LOW	1
191 #define QDF_DP_TRACE_VERBOSITY_BASE		0
192 
193 /**
194  * enum QDF_DP_TRACE_ID - Generic ID to identify various events in data path
195  * @QDF_DP_TRACE_INVALID - invalid
196  * @QDF_DP_TRACE_DROP_PACKET_RECORD - record drop packet
197  * @QDF_DP_TRACE_EAPOL_PACKET_RECORD - record EAPOL packet
198  * @QDF_DP_TRACE_DHCP_PACKET_RECORD - record DHCP packet
199  * @QDF_DP_TRACE_ARP_PACKET_RECORD - record ARP packet
200  * @QDF_DP_TRACE_MGMT_PACKET_RECORD - record MGMT pacekt
201  * @QDF_DP_TRACE_EVENT_RECORD - record events
202  * @QDF_DP_TRACE_BASE_VERBOSITY - below this are part of base verbosity
203  * @QDF_DP_TRACE_ICMP_PACKET_RECORD - record ICMP packet
204  * @QDF_DP_TRACE_ICMPv6_PACKET_RECORD - record ICMPv6 packet
205  * @QDF_DP_TRACE_HDD_TX_TIMEOUT - HDD tx timeout
206  * @QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT- SOFTAP HDD tx timeout
207  * @QDF_DP_TRACE_TX_CREDIT_RECORD - credit update record
208  * @QDF_DP_TRACE_ULTRA_LOW_VERBOSITY - Below this is not logged for >4PPS
209  * @QDF_DP_TRACE_TX_PACKET_RECORD - record 32 bytes of tx pkt at any layer
210  * @QDF_DP_TRACE_RX_PACKET_RECORD - record 32 bytes of rx pkt at any layer
211  * @QDF_DP_TRACE_HDD_TX_PACKET_RECORD - record 32 bytes of tx pkt at HDD
212  * @QDF_DP_TRACE_HDD_RX_PACKET_RECORD - record 32 bytes of rx pkt at HDD
213  * @QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD - record data bytes of tx pkt at LI_DP
214  * @QDF_DP_TRACE_LI_DP_RX_PACKET_RECORD - record data bytes of rx pkt at LI_DP
215  * @QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD - tx completion ptr record for
216  *						lithium
217  * @QDF_DP_TRACE_FREE_PACKET_PTR_RECORD - tx completion ptr record
218  * @QDF_DP_TRACE_LOW_VERBOSITY - below this are part of low verbosity
219  * @QDF_DP_TRACE_HDD_TX_PACKET_PTR_RECORD - HDD layer ptr record
220  * @QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD - Lithium DP layer ptr record
221  * @QDF_DP_TRACE_RX_HDD_PACKET_PTR_RECORD - HDD RX record
222  * @QDF_DP_TRACE_CE_PACKET_PTR_RECORD - CE layer ptr record
223  * @QDF_DP_TRACE_CE_FAST_PACKET_PTR_RECORD- CE fastpath ptr record
224  * @QDF_DP_TRACE_CE_FAST_PACKET_ERR_RECORD- CE fastpath error record
225  * @QDF_DP_TRACE_RX_HTT_PACKET_PTR_RECORD - HTT RX record
226  * @QDF_DP_TRACE_RX_OFFLOAD_HTT_PACKET_PTR_RECORD- HTT RX offload record
227  * @QDF_DP_TRACE_RX_LI_DP_PACKET_PTR_RECORD - Lithium DP RX record
228  * @QDF_DP_TRACE_MED_VERBOSITY - below this are part of med verbosity
229  * @QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD -tx queue ptr record
230  * @QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD - txrx packet ptr record
231  * @QDF_DP_TRACE_TXRX_FAST_PACKET_PTR_RECORD - txrx fast path record
232  * @QDF_DP_TRACE_HTT_PACKET_PTR_RECORD - htt packet ptr record
233  * @QDF_DP_TRACE_HTC_PACKET_PTR_RECORD - htc packet ptr record
234  * @QDF_DP_TRACE_HIF_PACKET_PTR_RECORD - hif packet ptr record
235  * @QDF_DP_TRACE_RX_TXRX_PACKET_PTR_RECORD - txrx packet ptr record
236  * @QDF_DP_TRACE_LI_DP_NULL_RX_PACKET_RECORD
237  *		- record data bytes of rx null_queue pkt at LI_DP
238  * @QDF_DP_TRACE_HIGH_VERBOSITY - below this are part of high verbosity
239  */
240 
241 enum  QDF_DP_TRACE_ID {
242 	QDF_DP_TRACE_INVALID,
243 	QDF_DP_TRACE_DROP_PACKET_RECORD,
244 	QDF_DP_TRACE_EAPOL_PACKET_RECORD,
245 	QDF_DP_TRACE_DHCP_PACKET_RECORD,
246 	QDF_DP_TRACE_ARP_PACKET_RECORD,
247 	QDF_DP_TRACE_MGMT_PACKET_RECORD,
248 	QDF_DP_TRACE_EVENT_RECORD,
249 	QDF_DP_TRACE_BASE_VERBOSITY,
250 	QDF_DP_TRACE_ICMP_PACKET_RECORD,
251 	QDF_DP_TRACE_ICMPv6_PACKET_RECORD,
252 	QDF_DP_TRACE_HDD_TX_TIMEOUT,
253 	QDF_DP_TRACE_HDD_SOFTAP_TX_TIMEOUT,
254 	QDF_DP_TRACE_TX_CREDIT_RECORD,
255 	QDF_DP_TRACE_ULTRA_LOW_VERBOSITY,
256 	QDF_DP_TRACE_TX_PACKET_RECORD,
257 	QDF_DP_TRACE_RX_PACKET_RECORD,
258 	QDF_DP_TRACE_HDD_TX_PACKET_RECORD,
259 	QDF_DP_TRACE_HDD_RX_PACKET_RECORD,
260 	QDF_DP_TRACE_LI_DP_TX_PACKET_RECORD,
261 	QDF_DP_TRACE_LI_DP_RX_PACKET_RECORD,
262 	QDF_DP_TRACE_LI_DP_FREE_PACKET_PTR_RECORD,
263 	QDF_DP_TRACE_FREE_PACKET_PTR_RECORD,
264 	QDF_DP_TRACE_LOW_VERBOSITY,
265 	QDF_DP_TRACE_HDD_TX_PACKET_PTR_RECORD,
266 	QDF_DP_TRACE_LI_DP_TX_PACKET_PTR_RECORD,
267 	QDF_DP_TRACE_RX_HDD_PACKET_PTR_RECORD,
268 	QDF_DP_TRACE_CE_PACKET_PTR_RECORD,
269 	QDF_DP_TRACE_CE_FAST_PACKET_PTR_RECORD,
270 	QDF_DP_TRACE_CE_FAST_PACKET_ERR_RECORD,
271 	QDF_DP_TRACE_RX_HTT_PACKET_PTR_RECORD,
272 	QDF_DP_TRACE_RX_OFFLOAD_HTT_PACKET_PTR_RECORD,
273 	QDF_DP_TRACE_RX_LI_DP_PACKET_PTR_RECORD,
274 	QDF_DP_TRACE_MED_VERBOSITY,
275 	QDF_DP_TRACE_TXRX_QUEUE_PACKET_PTR_RECORD,
276 	QDF_DP_TRACE_TXRX_PACKET_PTR_RECORD,
277 	QDF_DP_TRACE_TXRX_FAST_PACKET_PTR_RECORD,
278 	QDF_DP_TRACE_HTT_PACKET_PTR_RECORD,
279 	QDF_DP_TRACE_HTC_PACKET_PTR_RECORD,
280 	QDF_DP_TRACE_HIF_PACKET_PTR_RECORD,
281 	QDF_DP_TRACE_RX_TXRX_PACKET_PTR_RECORD,
282 	QDF_DP_TRACE_LI_DP_NULL_RX_PACKET_RECORD,
283 	QDF_DP_TRACE_HIGH_VERBOSITY,
284 	QDF_DP_TRACE_MAX
285 };
286 
287 /**
288  * qdf_proto_dir - direction
289  * @QDF_TX: TX direction
290  * @QDF_RX: RX direction
291  * @QDF_NA: not applicable
292  */
293 enum qdf_proto_dir {
294 	QDF_TX,
295 	QDF_RX,
296 	QDF_NA
297 };
298 
299 /**
300  * QDF_CREDIT_UPDATE_SOURCE - source of credit record
301  * @QDF_TX_SCHED: Tx scheduler
302  * @QDF_TX_COMP: TX completion
303  * @QDF_TX_CREDIT_UPDATE: credit update indication
304  * @QDF_HTT_ATTACH: HTT attach
305  * @QDF_TX_HTT_MSG: HTT TX message
306  */
307 enum QDF_CREDIT_UPDATE_SOURCE {
308 	QDF_TX_SCHED,
309 	QDF_TX_COMP,
310 	QDF_TX_CREDIT_UPDATE,
311 	QDF_HTT_ATTACH,
312 	QDF_TX_HTT_MSG
313 };
314 
315 /**
316  * QDF_CREDIT_OPERATION - operation on credit
317  * @QDF_CREDIT_INC: credit increment
318  * @QDF_CREDIT_DEC: credit decrement
319  * @QDF_CREDIT_ABS: Abosolute credit
320  * @QDF_OP_NA: Not applicable
321  */
322 enum QDF_CREDIT_OPERATION {
323 	QDF_CREDIT_INC,
324 	QDF_CREDIT_DEC,
325 	QDF_CREDIT_ABS,
326 	QDF_OP_NA
327 };
328 
329 /**
330  * struct qdf_dp_trace_ptr_buf - pointer record buffer
331  * @cookie: cookie value
332  * @msdu_id: msdu_id
333  * @status: completion status
334  */
335 struct qdf_dp_trace_ptr_buf {
336 	uint64_t cookie;
337 	uint16_t msdu_id;
338 	uint16_t status;
339 };
340 
341 /**
342  * struct qdf_dp_trace_proto_buf - proto packet buffer
343  * @sa: source address
344  * @da: destination address
345  * @vdev_id : vdev id
346  * @type: packet type
347  * @subtype: packet subtype
348  * @dir: direction
349  */
350 struct qdf_dp_trace_proto_buf {
351 	struct qdf_mac_addr sa;
352 	struct qdf_mac_addr da;
353 	uint8_t vdev_id;
354 	uint8_t type;
355 	uint8_t subtype;
356 	uint8_t dir;
357 };
358 
359 /**
360  * struct qdf_dp_trace_mgmt_buf - mgmt packet buffer
361  * @vdev_id : vdev id
362  * @type: packet type
363  * @subtype: packet subtype
364  */
365 struct qdf_dp_trace_mgmt_buf {
366 	uint8_t vdev_id;
367 	uint8_t type;
368 	uint8_t subtype;
369 };
370 
371 /**
372  * struct qdf_dp_trace_credit_record - tx credit record
373  * @source: credit record source
374  * @operation: credit operation
375  * @delta: delta of credit
376  * @total_credits: total credit
377  * @g0_credit: group 0 credit
378  * @g1_credit: group 1 credit
379  */
380 struct qdf_dp_trace_credit_record {
381 	enum QDF_CREDIT_UPDATE_SOURCE source;
382 	enum QDF_CREDIT_OPERATION operation;
383 	int delta;
384 	int total_credits;
385 	int g0_credit;
386 	int g1_credit;
387 };
388 
389 /**
390  * struct qdf_dp_trace_event_buf - event buffer
391  * @vdev_id : vdev id
392  * @type: packet type
393  * @subtype: packet subtype
394  */
395 struct qdf_dp_trace_event_buf {
396 	uint8_t vdev_id;
397 	uint8_t type;
398 	uint8_t subtype;
399 };
400 
401 /**
402  * struct qdf_dp_trace_data_buf - nbuf data buffer
403  * @msdu_id : msdu id
404  */
405 struct qdf_dp_trace_data_buf {
406 	uint16_t msdu_id;
407 };
408 
409 /**
410  * struct qdf_dp_trace_record_s - Describes a record in DP trace
411  * @time: time when it got stored
412  * @code: Describes the particular event
413  * @data: buffer to store data
414  * @size: Length of the valid data stored in this record
415  * @pid : process id which stored the data in this record
416  */
417 struct qdf_dp_trace_record_s {
418 	uint64_t time;
419 	uint8_t code;
420 	uint8_t data[QDF_DP_TRACE_RECORD_SIZE];
421 	uint8_t size;
422 	uint32_t pid;
423 	uint8_t pdev_id;
424 };
425 
426 /**
427  * struct qdf_dp_trace_data - Parameters to configure/control DP trace
428  * @head: Position of first record
429  * @tail: Position of last record
430  * @num:  Current index
431  * @proto_bitmap: defines which protocol to be traced
432  * @no_of_record: defines every nth packet to be traced
433  * @num_records_to_dump: defines number of records to be dumped
434  * @dump_counter: counter to track number of records dumped
435  * @verbosity : defines verbosity level
436  * @ini_conf_verbosity: Configured verbosity from INI
437  * @enable: enable/disable DP trace
438  * @count: current packet number
439  * @live_mode_config: configuration as received during initialization
440  * @live_mode: current live mode, enabled or disabled, can be throttled based
441  *             on throughput
442  * @force_live_mode: flag to enable live mode all the time for all packets.
443  *                  This can be set/unset from userspace and overrides other
444  *                  live mode flags.
445  * @dynamic_verbosity_modify: Dynamic user configured verbosity overrides all
446  * @print_pkt_cnt: count of number of packets printed in live mode
447  * @high_tput_thresh: thresh beyond which live mode is turned off
448  * @thresh_time_limit: max time, in terms of BW timer intervals to wait,
449  *          for determining if high_tput_thresh has been crossed. ~1s
450  * @arp_req: stats for arp reqs
451  * @arp_resp: stats for arp resps
452  * @icmp_req: stats for icmp reqs
453  * @icmp_resp: stats for icmp resps
454  * @dhcp_disc: stats for dhcp discover msgs
455  * @dhcp_req: stats for dhcp req msgs
456  * @dhcp_off: stats for dhcp offer msgs
457  * @dhcp_ack: stats for dhcp ack msgs
458  * @dhcp_nack: stats for dhcp nack msgs
459  * @dhcp_others: stats for other dhcp pkts types
460  * @eapol_m1: stats for eapol m1
461  * @eapol_m2: stats for eapol m2
462  * @eapol_m3: stats for eapol m3
463  * @eapol_m4: stats for eapol m4
464  * @eapol_others: stats for other eapol pkt types
465  * @icmpv6_req: stats for icmpv6 reqs
466  * @icmpv6_resp: stats for icmpv6 resps
467  * @icmpv6_ns: stats for icmpv6 nss
468  * @icmpv6_na: stats for icmpv6 nas
469  * @icmpv6_rs: stats for icmpv6 rss
470  * @icmpv6_ra: stats for icmpv6 ras
471  * @proto_event_bitmap: defines which protocol to be diag logged.
472  *  refer QDF_NBUF_PKT_TRAC_TYPE_DNS to QDF_NBUF_PKT_TRAC_TYPE_ARP
473  *  for bitmap.
474  */
475 struct s_qdf_dp_trace_data {
476 	uint32_t head;
477 	uint32_t tail;
478 	uint32_t num;
479 	uint32_t proto_bitmap;
480 	uint8_t no_of_record;
481 	uint16_t num_records_to_dump;
482 	uint16_t dump_counter;
483 	uint8_t verbosity;
484 	uint8_t ini_conf_verbosity;
485 	bool enable;
486 	bool live_mode_config;
487 	bool live_mode;
488 	uint32_t curr_pos;
489 	uint32_t saved_tail;
490 	bool force_live_mode;
491 	bool dynamic_verbosity_modify;
492 	uint8_t print_pkt_cnt;
493 	uint8_t high_tput_thresh;
494 	uint16_t thresh_time_limit;
495 	/* Stats */
496 	uint32_t tx_count;
497 	uint32_t rx_count;
498 	u16 arp_req;
499 	u16 arp_resp;
500 	u16 dhcp_disc;
501 	u16 dhcp_req;
502 	u16 dhcp_off;
503 	u16 dhcp_ack;
504 	u16 dhcp_nack;
505 	u16 dhcp_others;
506 	u16 eapol_m1;
507 	u16 eapol_m2;
508 	u16 eapol_m3;
509 	u16 eapol_m4;
510 	u16 eapol_others;
511 	u16 icmp_req;
512 	u16 icmp_resp;
513 	u16 icmpv6_req;
514 	u16 icmpv6_resp;
515 	u16 icmpv6_ns;
516 	u16 icmpv6_na;
517 	u16 icmpv6_rs;
518 	u16 icmpv6_ra;
519 	uint32_t proto_event_bitmap;
520 };
521 
522 /**
523  * struct qdf_dpt_debugfs_state - state to control read to debugfs file
524  * @QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INVALID: invalid state
525  * @QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INIT: initial state
526  * @QDF_DPT_DEBUGFS_STATE_SHOW_IN_PROGRESS: read is in progress
527  * @QDF_DPT_DEBUGFS_STATE_SHOW_COMPLETE:  read complete
528  */
529 
530 enum qdf_dpt_debugfs_state {
531 	QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INVALID,
532 	QDF_DPT_DEBUGFS_STATE_SHOW_STATE_INIT,
533 	QDF_DPT_DEBUGFS_STATE_SHOW_IN_PROGRESS,
534 	QDF_DPT_DEBUGFS_STATE_SHOW_COMPLETE,
535 };
536 
537 typedef void (*tp_qdf_trace_cb)(void *p_mac, tp_qdf_trace_record, uint16_t);
538 typedef void (*tp_qdf_state_info_cb) (char **buf, uint16_t *size);
539 #ifdef WLAN_FEATURE_MEMDUMP_ENABLE
540 void qdf_register_debugcb_init(void);
541 void qdf_register_debug_callback(QDF_MODULE_ID module_id,
542 					tp_qdf_state_info_cb qdf_state_infocb);
543 QDF_STATUS qdf_state_info_dump_all(char *buf, uint16_t size,
544 			uint16_t *driver_dump_size);
545 #else /* WLAN_FEATURE_MEMDUMP_ENABLE */
546 static inline void qdf_register_debugcb_init(void)
547 {
548 }
549 #endif /* WLAN_FEATURE_MEMDUMP_ENABLE */
550 
551 #ifdef TRACE_RECORD
552 void qdf_trace_register(QDF_MODULE_ID, tp_qdf_trace_cb);
553 void qdf_trace_init(void);
554 void qdf_trace_deinit(void);
555 void qdf_trace(uint8_t module, uint8_t code, uint16_t session, uint32_t data);
556 void qdf_trace_enable(uint32_t, uint8_t enable);
557 void qdf_trace_dump_all(void *, uint8_t, uint8_t, uint32_t, uint32_t);
558 QDF_STATUS qdf_trace_spin_lock_init(void);
559 #else
560 #ifndef QDF_TRACE_PRINT_ENABLE
561 static inline
562 void qdf_trace_init(void)
563 {
564 }
565 
566 static inline
567 void qdf_trace_deinit(void)
568 {
569 }
570 
571 static inline
572 void qdf_trace_enable(uint32_t bitmask_of_module_id, uint8_t enable)
573 {
574 }
575 
576 static inline
577 void qdf_trace(uint8_t module, uint8_t code, uint16_t session, uint32_t data)
578 {
579 }
580 
581 static inline
582 void qdf_trace_dump_all(void *p_mac, uint8_t code, uint8_t session,
583 			uint32_t count, uint32_t bitmask_of_module)
584 {
585 }
586 
587 static inline
588 QDF_STATUS qdf_trace_spin_lock_init(void)
589 {
590 	return QDF_STATUS_SUCCESS;
591 }
592 #endif
593 #endif
594 
595 #ifdef ENABLE_MTRACE_LOG
596 /**
597  * qdf_mtrace_log() - Logs a message tracepoint to DIAG
598  * Infrastructure.
599  * @src_module: Enum of source module (basically module id)
600  * from where the message with message_id is posted.
601  * @dst_module: Enum of destination module (basically module id)
602  * to which the message with message_id is posted.
603  * @message_id: Id of the message to be posted
604  * @vdev_id: Vdev Id
605  *
606  * This function logs to the DIAG Infrastructure a tracepoint for a
607  * message being sent from a source module to a destination module
608  * with a specific ID for the benefit of a specific vdev.
609  * For non-vdev messages vdev_id will be NO_SESSION
610  * Return: None
611  */
612 void qdf_mtrace_log(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
613 		    uint16_t message_id, uint8_t vdev_id);
614 #else
615 static inline
616 void qdf_mtrace_log(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
617 		    uint16_t message_id, uint8_t vdev_id)
618 {
619 }
620 #endif
621 
622 #ifdef TRACE_RECORD
623 /**
624  * qdf_mtrace() - puts the messages in to ring-buffer
625  * and logs a message tracepoint to DIAG Infrastructure.
626  * @src_module: Enum of source module (basically module id)
627  * from where the message with message_id is posted.
628  * @dst_module: Enum of destination module (basically module id)
629  * to which the message with message_id is posted.
630  * @message_id: Id of the message to be posted
631  * @vdev_id: Vdev Id
632  * @data: Actual message contents
633  *
634  * This function will be called from each module which wants to record the
635  * messages in circular queue. Before calling this function make sure you
636  * have registered your module with qdf through qdf_trace_register function.
637  * In addition of the recording the messages in circular queue this function
638  * will log the message tracepoint to the  DIAG infrastructure.
639  * these logs will be later used by post processing script.
640  *
641  * Return: None
642  */
643 void qdf_mtrace(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
644 		uint16_t message_id, uint8_t vdev_id, uint32_t data);
645 #else
646 static inline
647 void qdf_mtrace(QDF_MODULE_ID src_module, QDF_MODULE_ID dst_module,
648 		uint16_t message_id, uint8_t vdev_id, uint32_t data)
649 {
650 }
651 #endif
652 
653 #ifdef CONFIG_DP_TRACE
654 void qdf_dp_set_proto_bitmap(uint32_t val);
655 void qdf_dp_trace_set_verbosity(uint32_t val);
656 void qdf_dp_set_no_of_record(uint32_t val);
657 #define QDF_DP_TRACE_RECORD_INFO_LIVE (0x1)
658 #define QDF_DP_TRACE_RECORD_INFO_THROTTLED (0x1 << 1)
659 
660 /**
661  * qdf_dp_trace_log_pkt() - log packet type enabled through iwpriv
662  * @vdev_id: vdev_id
663  * @skb: skb pointer
664  * @dir: direction
665  * @pdev_id: pdev_id
666  *
667  * Return: true: some protocol was logged, false: no protocol was logged.
668  */
669 bool qdf_dp_trace_log_pkt(uint8_t vdev_id, struct sk_buff *skb,
670 			  enum qdf_proto_dir dir, uint8_t pdev_id);
671 
672 void qdf_dp_trace_init(bool live_mode_config, uint8_t thresh,
673 				uint16_t time_limit, uint8_t verbosity,
674 				uint32_t proto_bitmap);
675 void qdf_dp_trace_deinit(void);
676 void qdf_dp_trace_spin_lock_init(void);
677 void qdf_dp_trace_set_value(uint32_t proto_bitmap, uint8_t no_of_records,
678 			    uint8_t verbosity);
679 void qdf_dp_trace_set_track(qdf_nbuf_t nbuf, enum qdf_proto_dir dir);
680 void qdf_dp_trace(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code, uint8_t pdev_id,
681 			uint8_t *data, uint8_t size, enum qdf_proto_dir dir);
682 void qdf_dp_trace_dump_all(uint32_t count, uint8_t pdev_id);
683 
684 /**
685  * qdf_dpt_get_curr_pos_debugfs() - get curr position to start read
686  * @file: debugfs file to read
687  * @state: state to control read to debugfs file
688  *
689  * Return: curr pos
690  */
691 uint32_t qdf_dpt_get_curr_pos_debugfs(qdf_debugfs_file_t file,
692 				enum qdf_dpt_debugfs_state state);
693 /**
694  * qdf_dpt_dump_stats_debugfs() - dump DP Trace stats to debugfs file
695  * @file: debugfs file to read
696  * @curr_pos: curr position to start read
697  *
698  * Return: QDF_STATUS
699  */
700 QDF_STATUS qdf_dpt_dump_stats_debugfs(qdf_debugfs_file_t file,
701 				      uint32_t curr_pos);
702 
703 /**
704  * qdf_dpt_set_value_debugfs() - set value of DP Trace debugfs params
705  * @proto_bitmap: defines which protocol to be traced
706  * @no_of_record: defines every nth packet to be traced
707  * @verbosity : defines verbosity level
708  * @num_records_to_dump: defines number of records to be dumped
709  *
710  * Return: none
711  */
712 void qdf_dpt_set_value_debugfs(uint8_t proto_bitmap, uint8_t no_of_record,
713 			    uint8_t verbosity, uint16_t num_records_to_dump);
714 
715 
716 /**
717  * qdf_dp_trace_dump_stats() - dump DP Trace stats
718  *
719  * Return: none
720  */
721 void qdf_dp_trace_dump_stats(void);
722 typedef void (*tp_qdf_dp_trace_cb)(struct qdf_dp_trace_record_s*,
723 				   uint16_t, uint8_t, uint8_t info);
724 /**
725  * qdf_dp_display_record() - Displays a record in DP trace
726  * @record: pointer to a record in DP trace
727  * @index: record index
728  * @pdev_id: pdev id for the mgmt pkt
729  * @info: info used to display pkt (live mode, throttling)
730  *
731  * Return: None
732  */
733 void qdf_dp_display_record(struct qdf_dp_trace_record_s *record,
734 			   uint16_t index, uint8_t pdev_id,
735 			   uint8_t info);
736 
737 /**
738  * qdf_dp_display_ptr_record() - display record
739  * @record: dptrace record
740  * @rec_index: index
741  * @pdev_id: pdev id for the mgmt pkt
742  * @info: info used to display pkt (live mode, throttling)
743  *
744  * Return: none
745  */
746 void qdf_dp_display_ptr_record(struct qdf_dp_trace_record_s *record,
747 			       uint16_t rec_index, uint8_t pdev_id,
748 			       uint8_t info);
749 
750 /**
751  * qdf_dp_display_proto_pkt() - display proto packet
752  * @record: dptrace record
753  * @index: index
754  * @pdev_id: pdev id for the mgmt pkt
755  * @info: info used to display pkt (live mode, throttling)
756  *
757  * Return: none
758  */
759 void qdf_dp_display_proto_pkt(struct qdf_dp_trace_record_s *record,
760 			      uint16_t index, uint8_t pdev_id,
761 			      uint8_t info);
762 /**
763  * qdf_dp_display_data_pkt_record() - Displays a data packet in DP trace
764  * @record: pointer to a record in DP trace
765  * @rec_index: record index
766  * @pdev_id: pdev id
767  * @info: display info regarding record
768  *
769  * Return: None
770  */
771 void
772 qdf_dp_display_data_pkt_record(struct qdf_dp_trace_record_s *record,
773 			       uint16_t rec_index, uint8_t pdev_id,
774 			       uint8_t info);
775 
776 void qdf_dp_trace_ptr(qdf_nbuf_t nbuf, enum QDF_DP_TRACE_ID code,
777 		      uint8_t pdev_id, uint8_t *data, uint8_t size,
778 		      uint16_t msdu_id, uint16_t status);
779 void qdf_dp_trace_throttle_live_mode(bool high_bw_request);
780 
781 /**
782  * qdf_dp_trace_tput_policy() - Change verbosity based on the TPUT
783  * @is_data_traffic: Is traffic more than low TPUT threashould
784  *
785  * Return: None
786  */
787 void qdf_dp_trace_apply_tput_policy(bool is_data_traffic);
788 
789 /**
790  * qdf_dp_trace_data_pkt() - trace data packet
791  * @nbuf: nbuf which needs to be traced
792  * @pdev_id: pdev_id
793  * @code: QDF_DP_TRACE_ID for the packet (TX or RX)
794  * @msdu_id: tx desc id for the nbuf (Only applies to TX packets)
795  * @dir: TX or RX packet direction
796  *
797  * Return: None
798  */
799 void qdf_dp_trace_data_pkt(qdf_nbuf_t nbuf, uint8_t pdev_id,
800 			   enum QDF_DP_TRACE_ID code, uint16_t msdu_id,
801 			   enum qdf_proto_dir dir);
802 
803 uint32_t qdf_dp_get_proto_bitmap(void);
804 uint8_t qdf_dp_get_verbosity(void);
805 uint8_t qdf_dp_get_no_of_record(void);
806 
807 /**
808  * qdf_dp_trace_proto_pkt() - record proto packet
809  * @code: dptrace code
810  * @vdev_id: vdev id
811  * @sa: source mac address
812  * @da: destination mac address
813  * @type: proto type
814  * @subtype: proto subtype
815  * @dir: direction
816  * @pdev_id: pdev id
817  * @print: to print this proto pkt or not
818  *
819  * Return: none
820  */
821 void
822 qdf_dp_trace_proto_pkt(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
823 	uint8_t *sa, uint8_t *da, enum qdf_proto_type type,
824 	enum qdf_proto_subtype subtype, enum qdf_proto_dir dir,
825 	uint8_t pdev_id, bool print);
826 
827 void qdf_dp_trace_disable_live_mode(void);
828 void qdf_dp_trace_enable_live_mode(void);
829 void qdf_dp_trace_clear_buffer(void);
830 /**
831  * qdf_dp_trace_mgmt_pkt() - record mgmt packet
832  * @code: dptrace code
833  * @vdev_id: vdev id
834  * @pdev_id: pdev_id
835  * @type: proto type
836  * @subtype: proto subtype
837  *
838  * Return: none
839  */
840 void qdf_dp_trace_mgmt_pkt(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
841 			   uint8_t pdev_id, enum qdf_proto_type type,
842 			   enum qdf_proto_subtype subtype);
843 
844 /**
845  * qdf_dp_trace_credit_record() - record credit update
846  * @source: source of record
847  * @operation: credit operation
848  * @delta: credit delta
849  * @total_credits: total credit
850  * @g0_credit: group 0 credit
851  * @g1_credit: group 1 credit
852  */
853 void qdf_dp_trace_credit_record(enum QDF_CREDIT_UPDATE_SOURCE source,
854 				enum QDF_CREDIT_OPERATION operation,
855 				int delta, int total_credits,
856 				int g0_credit, int g1_credit);
857 
858 /**
859  * qdf_dp_display_mgmt_pkt() - display proto packet
860  * @record: dptrace record
861  * @index: index
862  * @pdev_id: pdev id for the mgmt pkt
863  * @info: info used to display pkt (live mode, throttling)
864  *
865  * Return: none
866  */
867 void qdf_dp_display_mgmt_pkt(struct qdf_dp_trace_record_s *record,
868 			     uint16_t index, uint8_t pdev_id, uint8_t info);
869 
870 /**
871  * qdf_dp_display_credit_record() - display credit record
872  * @record: dptrace record
873  * @index: index
874  * @pdev_id: pdev id
875  * @info: metadeta info
876  */
877 void qdf_dp_display_credit_record(struct qdf_dp_trace_record_s *record,
878 				  uint16_t index, uint8_t pdev_id,
879 				  uint8_t info);
880 
881 /**
882  * qdf_dp_display_event_record() - display event records
883  * @record: dptrace record
884  * @index: index
885  * @pdev_id: pdev id for the mgmt pkt
886  * @info: info used to display pkt (live mode, throttling)
887  *
888  * Return: none
889  */
890 void qdf_dp_display_event_record(struct qdf_dp_trace_record_s *record,
891 				 uint16_t index, uint8_t pdev_id, uint8_t info);
892 
893 void qdf_dp_trace_record_event(enum QDF_DP_TRACE_ID code, uint8_t vdev_id,
894 			       uint8_t pdev_id, enum qdf_proto_type type,
895 			       enum qdf_proto_subtype subtype);
896 
897 /**
898  * qdf_dp_set_proto_event_bitmap() - Set the protocol event bitmap
899  * @value: proto event bitmap value.
900  *
901  * QDF_NBUF_PKT_TRAC_TYPE_DNS       0x01
902  * QDF_NBUF_PKT_TRAC_TYPE_EAPOL     0x02
903  * QDF_NBUF_PKT_TRAC_TYPE_DHCP      0x04
904  * QDF_NBUF_PKT_TRAC_TYPE_ARP       0x10
905  *
906  * Return: none
907  */
908 void qdf_dp_set_proto_event_bitmap(uint32_t value);
909 
910 /**
911  * qdf_dp_log_proto_pkt_info() - Send diag log event
912  * @sa: source MAC address
913  * @da: destination MAC address
914  * @type: pkt type
915  * @subtype: pkt subtype
916  * @dir: tx or rx
917  * @msdu_id: msdu id
918  * @status: status
919  *
920  * Return: none
921  */
922 void qdf_dp_log_proto_pkt_info(uint8_t *sa, uint8_t *da, uint8_t type,
923 			       uint8_t subtype, uint8_t dir, uint8_t msdu_id,
924 			       uint8_t status);
925 #else
926 static inline
927 bool qdf_dp_trace_log_pkt(uint8_t vdev_id, struct sk_buff *skb,
928 			  enum qdf_proto_dir dir, uint8_t pdev_id)
929 {
930 	return false;
931 }
932 static inline
933 void qdf_dp_trace_init(bool live_mode_config, uint8_t thresh,
934 				uint16_t time_limit, uint8_t verbosity,
935 				uint32_t proto_bitmap)
936 {
937 }
938 
939 static inline
940 void qdf_dp_trace_deinit(void)
941 {
942 }
943 
944 static inline
945 void qdf_dp_trace_set_track(qdf_nbuf_t nbuf, enum qdf_proto_dir dir)
946 {
947 }
948 static inline
949 void qdf_dp_trace_set_value(uint32_t proto_bitmap, uint8_t no_of_records,
950 			    uint8_t verbosity)
951 {
952 }
953 
954 static inline
955 void qdf_dp_trace_dump_all(uint32_t count, uint8_t pdev_id)
956 {
957 }
958 
959 static inline
960 uint32_t qdf_dpt_get_curr_pos_debugfs(qdf_debugfs_file_t file,
961 				      enum qdf_dpt_debugfs_state state)
962 {
963 	return 0;
964 }
965 
966 static inline
967 QDF_STATUS qdf_dpt_dump_stats_debugfs(qdf_debugfs_file_t file,
968 				      uint32_t curr_pos)
969 {
970 	return QDF_STATUS_SUCCESS;
971 }
972 
973 static inline
974 void qdf_dpt_set_value_debugfs(uint8_t proto_bitmap, uint8_t no_of_record,
975 			    uint8_t verbosity, uint16_t num_records_to_dump)
976 {
977 }
978 
979 static inline void qdf_dp_trace_dump_stats(void)
980 {
981 }
982 
983 static inline
984 void qdf_dp_trace_disable_live_mode(void)
985 {
986 }
987 
988 static inline
989 void qdf_dp_trace_enable_live_mode(void)
990 {
991 }
992 
993 static inline
994 void qdf_dp_trace_throttle_live_mode(bool high_bw_request)
995 {
996 }
997 
998 static inline
999 void qdf_dp_trace_clear_buffer(void)
1000 {
1001 }
1002 
1003 static inline
1004 void qdf_dp_trace_apply_tput_policy(bool is_data_traffic)
1005 {
1006 }
1007 
1008 static inline
1009 void qdf_dp_trace_data_pkt(qdf_nbuf_t nbuf, uint8_t pdev_id,
1010 			   enum QDF_DP_TRACE_ID code, uint16_t msdu_id,
1011 			   enum qdf_proto_dir dir)
1012 {
1013 }
1014 
1015 static inline
1016 void qdf_dp_log_proto_pkt_info(uint8_t *sa, uint8_t *da, uint8_t type,
1017 			       uint8_t subtype, uint8_t dir, uint8_t msdu_id,
1018 			       uint8_t status)
1019 {
1020 }
1021 #endif
1022 
1023 void qdf_trace_display(void);
1024 
1025 void __printf(3, 4) qdf_snprintf(char *str_buffer, unsigned int size,
1026 		  char *str_format, ...);
1027 
1028 #define QDF_SNPRINTF qdf_snprintf
1029 
1030 #ifdef TSOSEG_DEBUG
1031 
1032 static inline void qdf_tso_seg_dbg_bug(char *msg)
1033 {
1034 	qdf_print("%s", msg);
1035 	QDF_BUG(0);
1036 };
1037 
1038 /**
1039  * qdf_tso_seg_dbg_init - initialize TSO segment debug structure
1040  * @tsoseg : structure to initialize
1041  *
1042  * TSO segment dbg structures are attached to qdf_tso_seg_elem_t
1043  * structures and are allocated only of TSOSEG_DEBUG is defined.
1044  * When allocated, at the time of the tso_seg_pool initialization,
1045  * which goes with tx_desc initialization (1:1), each structure holds
1046  * a number of (currently 16) history entries, basically describing
1047  * what operation has been performed on this particular tso_seg_elem.
1048  * This history buffer is a circular buffer and the current index is
1049  * held in an atomic variable called cur. It is incremented every
1050  * operation. Each of these operations are added with the function
1051  * qdf_tso_seg_dbg_record.
1052  * For each segment, this initialization function MUST be called PRIOR
1053  * TO any _dbg_record() function calls.
1054  * On free, qdf_tso_seg_elem structure is cleared (using qdf_tso_seg_dbg_zero)
1055  * which clears the tso_desc, BUT DOES NOT CLEAR THE HISTORY element.
1056  *
1057  * Return:
1058  *   None
1059  */
1060 static inline
1061 void qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t *tsoseg)
1062 {
1063 	tsoseg->dbg.txdesc = NULL;
1064 	qdf_atomic_init(&tsoseg->dbg.cur); /* history empty */
1065 }
1066 
1067 /**
1068  * qdf_tso_seg_dbg_record - add a history entry to TSO debug structure
1069  * @tsoseg : structure to initialize
1070  * @id     : operation ID (identifies the caller)
1071  *
1072  * Adds a history entry to the history circular buffer. Each entry
1073  * contains an operation id (caller, as currently each ID is used only
1074  * once in the source, so it directly identifies the src line that invoked
1075  * the recording.
1076  *
1077  * qdf_tso_seg_dbg_record CAN ONLY BE CALLED AFTER the entry is initialized
1078  * by qdf_tso_seg_dbg_init.
1079  *
1080  * The entry to be added is written at the location pointed by the atomic
1081  * variable called cur. Cur is an ever increasing atomic variable. It is
1082  * masked so that only the lower 4 bits are used (16 history entries).
1083  *
1084  * Return:
1085  *   int: the entry this record was recorded at
1086  */
1087 static inline
1088 int qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t *tsoseg, short id)
1089 {
1090 	int rc = -1;
1091 	unsigned int c;
1092 
1093 	qdf_assert(tsoseg);
1094 
1095 	if (id == TSOSEG_LOC_ALLOC) {
1096 		c = qdf_atomic_read(&tsoseg->dbg.cur);
1097 		/* dont crash on the very first alloc on the segment */
1098 		c &= 0x0f;
1099 		/* allow only INIT and FREE ops before ALLOC */
1100 		if (tsoseg->dbg.h[c].id >= id)
1101 			qdf_tso_seg_dbg_bug("Rogue TSO seg alloc");
1102 	}
1103 	c = qdf_atomic_inc_return(&tsoseg->dbg.cur);
1104 
1105 	c &= 0x0f;
1106 	tsoseg->dbg.h[c].ts = qdf_get_log_timestamp();
1107 	tsoseg->dbg.h[c].id = id;
1108 	rc = c;
1109 
1110 	return rc;
1111 };
1112 
1113 static inline void
1114 qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t *tsoseg, void *owner)
1115 {
1116 	if (tsoseg)
1117 		tsoseg->dbg.txdesc = owner;
1118 };
1119 
1120 static inline void
1121 qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t *tsoseg)
1122 {
1123 	memset(tsoseg, 0, offsetof(struct qdf_tso_seg_elem_t, dbg));
1124 	return;
1125 };
1126 
1127 #else
1128 static inline
1129 void qdf_tso_seg_dbg_init(struct qdf_tso_seg_elem_t *tsoseg)
1130 {
1131 };
1132 static inline
1133 int qdf_tso_seg_dbg_record(struct qdf_tso_seg_elem_t *tsoseg, short id)
1134 {
1135 	return 0;
1136 };
1137 static inline void qdf_tso_seg_dbg_bug(char *msg)
1138 {
1139 };
1140 static inline void
1141 qdf_tso_seg_dbg_setowner(struct qdf_tso_seg_elem_t *tsoseg, void *owner)
1142 {
1143 };
1144 static inline int
1145 qdf_tso_seg_dbg_zero(struct qdf_tso_seg_elem_t *tsoseg)
1146 {
1147 	memset(tsoseg, 0, sizeof(struct qdf_tso_seg_elem_t));
1148 	return 0;
1149 };
1150 
1151 #endif /* TSOSEG_DEBUG */
1152 
1153 /**
1154  * qdf_trace_hex_dump() - externally called hex dump function
1155  * @module: Module identifier a member of the QDF_MODULE_ID enumeration that
1156  * identifies the module issuing the trace message.
1157  * @level: Trace level a member of the QDF_TRACE_LEVEL enumeration indicating
1158  * the severity of the condition causing the trace message to be
1159  * issued. More severe conditions are more likely to be logged.
1160  * @data: The base address of the buffer to be logged.
1161  * @buf_len: The size of the buffer to be logged.
1162  *
1163  * Checks the level of severity and accordingly prints the trace messages
1164  *
1165  * Return:  None
1166  */
1167 void qdf_trace_hex_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
1168 			void *data, int buf_len);
1169 
1170 /**
1171  * qdf_trace_hex_ascii_dump() - externally called hex and ascii dump function
1172  * @module: Module identifier a member of the QDF_MODULE_ID enumeration that
1173  * identifies the module issuing the trace message.
1174  * @level: Trace level a member of the QDF_TRACE_LEVEL enumeration indicating
1175  * the severity of the condition causing the trace message to be
1176  * issued. More severe conditions are more likely to be logged.
1177  * @data: The base address of the buffer to be logged.
1178  * @buf_len: The size of the buffer to be logged.
1179  *
1180  * Checks the level of severity and accordingly prints the trace messages
1181  *
1182  * Return:  None
1183  */
1184 void qdf_trace_hex_ascii_dump(QDF_MODULE_ID module, QDF_TRACE_LEVEL level,
1185 			      void *data, int buf_len);
1186 
1187 #define ERROR_CODE                      -1
1188 #define QDF_MAX_NAME_SIZE               32
1189 #define MAX_PRINT_CONFIG_SUPPORTED      32
1190 
1191 #define MAX_SUPPORTED_CATEGORY QDF_MODULE_ID_MAX
1192 
1193 /**
1194  * qdf_set_pidx() - Sets the global qdf_pidx.
1195  * @pidx : Index of print control object assigned to the module
1196  *
1197  */
1198 void qdf_set_pidx(int pidx);
1199 
1200 /**
1201  * qdf_get_pidx() - Returns the global qdf_pidx.
1202  *
1203  * Return : Current qdf print index.
1204  */
1205 int qdf_get_pidx(void);
1206 /*
1207  * Shared print control index
1208  * for converged debug framework
1209  */
1210 
1211 #define QDF_PRINT_IDX_SHARED -1
1212 
1213 /**
1214  * QDF_PRINT_INFO() - Generic wrapper API for logging
1215  * @idx : Index of print control object
1216  * @module : Module identifier. A member of QDF_MODULE_ID enumeration that
1217  *           identifies the module issuing the trace message
1218  * @level : Trace level. A member of QDF_TRACE_LEVEL enumeration indicating
1219  *          the severity of the condition causing the trace message to be
1220  *          issued.
1221  * @str_format : Format string that contains the message to be logged.
1222  *
1223  *
1224  * This wrapper will be used for any generic logging messages. Wrapper will
1225  * compile a call to converged QDF trace message API.
1226  *
1227  * Return : Nothing
1228  *
1229  */
1230 void QDF_PRINT_INFO(unsigned int idx, QDF_MODULE_ID module,
1231 		    QDF_TRACE_LEVEL level,
1232 		    char *str_format, ...);
1233 
1234 /**
1235  * struct category_info  : Category information structure
1236  * @category_verbose_mask: Embeds information about category's verbose level
1237  */
1238 struct category_info {
1239 	uint16_t category_verbose_mask;
1240 };
1241 
1242 /**
1243  * struct category_name_info  : Category name information structure
1244  * @category_name_str: Embeds information about category name
1245  */
1246 struct category_name_info {
1247 	unsigned char category_name_str[QDF_MAX_NAME_SIZE];
1248 };
1249 
1250 /**
1251  * qdf_trace_msg_cmn()- Converged logging API
1252  * @idx: Index of print control object assigned to the module
1253  * @category: Category identifier. A member of the QDF_MODULE_ID enumeration
1254  *            that identifies the category issuing the trace message.
1255  * @verbose: Verbose level. A member of the QDF_TRACE_LEVEL enumeration
1256  *           indicating the severity of the condition causing the trace
1257  *           message to be issued. More severe conditions are more likely
1258  *           to be logged.
1259  * @str_format: Format string. The message to be logged. This format string
1260  *              contains printf-like replacement parameters, which follow this
1261  *              parameter in the variable argument list.
1262  * @val: Variable argument list part of the log message
1263  *
1264  * Return: nothing
1265  *
1266  */
1267 void qdf_trace_msg_cmn(unsigned int idx,
1268 			QDF_MODULE_ID category,
1269 			QDF_TRACE_LEVEL verbose,
1270 			const char *str_format,
1271 			va_list val);
1272 
1273 /**
1274  * struct qdf_print_ctrl: QDF Print Control structure
1275  *                        Statically allocated objects of print control
1276  *                        structure are declared that will support maximum of
1277  *                        32 print control objects. Any module that needs to
1278  *                        register to the print control framework needs to
1279  *                        obtain a print control object using
1280  *                        qdf_print_ctrl_register API. It will have to pass
1281  *                        pointer to category info structure, name and
1282  *                        custom print function to be used if required.
1283  * @name                : Optional name for the control object
1284  * @cat_info            : Array of category_info struct
1285  * @custom_print        : Custom print handler
1286  * @custom_ctxt         : Custom print context
1287  * @dbglvlmac_on        : Flag to enable/disable MAC level filtering
1288  * @in_use              : Boolean to indicate if control object is in use
1289  */
1290 struct qdf_print_ctrl {
1291 	char name[QDF_MAX_NAME_SIZE];
1292 	struct category_info cat_info[MAX_SUPPORTED_CATEGORY];
1293 	void (*custom_print)(void *ctxt, const char *fmt, va_list args);
1294 	void *custom_ctxt;
1295 #ifdef DBG_LVL_MAC_FILTERING
1296 	unsigned char dbglvlmac_on;
1297 #endif
1298 	bool in_use;
1299 };
1300 
1301 /**
1302  * qdf_print_ctrl_register() - Allocate QDF print control object, assign
1303  *                             pointer to category info or print control
1304  *                             structure and return the index to the callee
1305  * @cinfo                 : Pointer to array of category info structure
1306  * @custom_print_handler  : Pointer to custom print handler
1307  * @custom_ctx            : Pointer to custom context
1308  * @pctrl_name            : Pointer to print control object name
1309  *
1310  * Return                 : Index of qdf_print_ctrl structure
1311  *
1312  */
1313 int qdf_print_ctrl_register(const struct category_info *cinfo,
1314 			    void *custom_print_handler,
1315 			    void *custom_ctx,
1316 			    const char *pctrl_name);
1317 
1318 /**
1319  * qdf_shared_print_ctrl_init() - Initialize the shared print ctrl obj with
1320  *                                all categories set to the default level
1321  *
1322  * Return                 : void
1323  *
1324  */
1325 void qdf_shared_print_ctrl_init(void);
1326 
1327 /**
1328  * qdf_print_setup() - Setup default values to all the print control objects
1329  *
1330  * Register new print control object for the callee
1331  *
1332  * Return :             QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE
1333  *                      on failure
1334  */
1335 QDF_STATUS qdf_print_setup(void);
1336 
1337 /**
1338  * qdf_print_ctrl_cleanup() - Clean up a print control object
1339  *
1340  * Cleanup the print control object for the callee
1341  *
1342  * @pctrl : Index of print control object
1343  *
1344  * Return : QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE on failure
1345  */
1346 QDF_STATUS qdf_print_ctrl_cleanup(unsigned int idx);
1347 
1348 /**
1349  * qdf_print_ctrl_shared_cleanup() - Clean up of the shared object
1350  *
1351  * Cleanup the shared print-ctrl-object
1352  *
1353  * Return : void
1354  */
1355 void qdf_shared_print_ctrl_cleanup(void);
1356 
1357 /**
1358  * qdf_print_set_category_verbose() - Enable/Disable category for a
1359  *                                    print control object with
1360  *                                    user provided verbose level
1361  *
1362  * @idx : Index of the print control object assigned to callee
1363  * @category : Category information
1364  * @verbose: Verbose information
1365  * @is_set: Flag indicating if verbose level needs to be enabled or disabled
1366  *
1367  * Return : QDF_STATUS_SUCCESS for success and QDF_STATUS_E_FAILURE for failure
1368  */
1369 QDF_STATUS qdf_print_set_category_verbose(unsigned int idx,
1370 					  QDF_MODULE_ID category,
1371 					  QDF_TRACE_LEVEL verbose,
1372 					  bool is_set);
1373 
1374 /**
1375  * qdf_log_dump_at_kernel_level() - Enable/Disable printk call
1376  * @enable: Indicates whether printk is enabled in QDF_TRACE
1377  *
1378  * Return: void
1379  */
1380 void qdf_log_dump_at_kernel_level(bool enable);
1381 
1382 /**
1383  * qdf_logging_set_flush_timer() - Set the time period in which host logs
1384  *                                 should be flushed out to user-space
1385  * @milliseconds: milliseconds after which the logs should be flushed out to
1386  *                 user-space
1387  *
1388  * Return: QDF_STATUS_SUCCESS for success and QDF_STATUS_E_FAILURE for failure
1389  */
1390 int qdf_logging_set_flush_timer(uint32_t milliseconds);
1391 
1392 /**
1393  * qdf_logging_flush_logs() - Flush out the logs to user-space one time
1394  *
1395  * Return: void
1396  */
1397 void qdf_logging_flush_logs(void);
1398 
1399 /**
1400  * qdf_print_is_category_enabled() - Get category information for the
1401  *                                   print control object
1402  *
1403  * @idx : Index of print control object
1404  * @category : Category information
1405  *
1406  * Return : Verbose enabled(true) or disabled(false) or invalid input (false)
1407  */
1408 bool qdf_print_is_category_enabled(unsigned int idx,
1409 				   QDF_MODULE_ID category);
1410 
1411 /**
1412  * qdf_print_is_verbose_enabled() - Get verbose information of a category for
1413  *                                  the print control object
1414  *
1415  * @idx : Index of print control object
1416  * @category : Category information
1417  * @verbose : Verbose information
1418  *
1419  * Return : Verbose enabled(true) or disabled(false) or invalid input (false)
1420  */
1421 bool qdf_print_is_verbose_enabled(unsigned int idx,
1422 				  QDF_MODULE_ID category,
1423 				  QDF_TRACE_LEVEL verbose);
1424 
1425 /**
1426  * qdf_print_clean_node_flag() - Clean up node flag for print control object
1427  *
1428  * @idx : Index of print control object
1429  *
1430  * Return : None
1431  */
1432 void qdf_print_clean_node_flag(unsigned int idx);
1433 
1434 #ifdef DBG_LVL_MAC_FILTERING
1435 
1436 /**
1437  * qdf_print_set_node_flag() - Set flag to enable MAC level filtering
1438  *
1439  * @idx : Index of print control object
1440  * @enable : Enable/Disable bit sent by callee
1441  *
1442  * Return : QDF_STATUS_SUCCESS on Success and QDF_STATUS_E_FAILURE on Failure
1443  */
1444 QDF_STATUS qdf_print_set_node_flag(unsigned int idx,
1445 				   uint8_t enable);
1446 
1447 /**
1448  * qdf_print_get_node_flag() - Get flag that controls MAC level filtering
1449  *
1450  * @idx : Index of print control object
1451  *
1452  * Return : Flag that indicates enable(1) or disable(0) or invalid(-1)
1453  */
1454 bool qdf_print_get_node_flag(unsigned int idx);
1455 
1456 #endif
1457 
1458 /**
1459  * qdf_logging_init() - Initialize msg logging functionality
1460  *
1461  *
1462  * Return : void
1463  */
1464 void qdf_logging_init(void);
1465 
1466 /**
1467  * qdf_logging_exit() - Cleanup msg logging functionality
1468  *
1469  *
1470  * Return : void
1471  */
1472 void qdf_logging_exit(void);
1473 
1474 #define QDF_SYMBOL_LEN __QDF_SYMBOL_LEN
1475 
1476 /**
1477  * qdf_sprint_symbol() - prints the name of a symbol into a string buffer
1478  * @buffer: the string buffer to print into
1479  * @addr: address of the symbol to lookup and print
1480  *
1481  * Return: number of characters printed
1482  */
1483 int qdf_sprint_symbol(char *buffer, void *addr);
1484 
1485 /**
1486  * qdf_minidump_log() - Log memory address to be included in minidump
1487  * @start_addr: Start address of the memory to be dumped
1488  * @size: Size in bytes
1489  * @name: String to identify this entry
1490  */
1491 static inline
1492 void qdf_minidump_log(void *start_addr, size_t size, const char *name)
1493 {
1494 	__qdf_minidump_log(start_addr, size, name);
1495 }
1496 
1497 /**
1498  * qdf_minidump_remove() - Remove memory address from minidump
1499  * @addr: Start address of the memory previously added
1500  */
1501 static inline
1502 void qdf_minidump_remove(void *addr)
1503 {
1504 	__qdf_minidump_remove(addr);
1505 }
1506 
1507 #endif /* __QDF_TRACE_H */
1508