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