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