1*5113495bSYour Name /*
2*5113495bSYour Name * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
3*5113495bSYour Name * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
4*5113495bSYour Name *
5*5113495bSYour Name * Permission to use, copy, modify, and/or distribute this software for
6*5113495bSYour Name * any purpose with or without fee is hereby granted, provided that the
7*5113495bSYour Name * above copyright notice and this permission notice appear in all
8*5113495bSYour Name * copies.
9*5113495bSYour Name *
10*5113495bSYour Name * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11*5113495bSYour Name * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12*5113495bSYour Name * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13*5113495bSYour Name * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14*5113495bSYour Name * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15*5113495bSYour Name * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16*5113495bSYour Name * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17*5113495bSYour Name * PERFORMANCE OF THIS SOFTWARE.
18*5113495bSYour Name */
19*5113495bSYour Name
20*5113495bSYour Name /******************************************************************************
21*5113495bSYour Name * wlan_logging_sock_svc.c
22*5113495bSYour Name *
23*5113495bSYour Name ******************************************************************************/
24*5113495bSYour Name
25*5113495bSYour Name #ifdef WLAN_LOGGING_SOCK_SVC_ENABLE
26*5113495bSYour Name #include <linux/vmalloc.h>
27*5113495bSYour Name #include <wlan_logging_sock_svc.h>
28*5113495bSYour Name #include <linux/kthread.h>
29*5113495bSYour Name #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0))
30*5113495bSYour Name #include <linux/panic_notifier.h>
31*5113495bSYour Name #endif
32*5113495bSYour Name #include <qdf_time.h>
33*5113495bSYour Name #include <qdf_trace.h>
34*5113495bSYour Name #include <qdf_mc_timer.h>
35*5113495bSYour Name #include <qdf_timer.h>
36*5113495bSYour Name #include <qdf_lock.h>
37*5113495bSYour Name #include <wlan_ptt_sock_svc.h>
38*5113495bSYour Name #include <host_diag_core_event.h>
39*5113495bSYour Name #include "host_diag_core_log.h"
40*5113495bSYour Name #include <qdf_event.h>
41*5113495bSYour Name #include <qdf_module.h>
42*5113495bSYour Name #include <qdf_str.h>
43*5113495bSYour Name #ifdef WLAN_FEATURE_CONNECTIVITY_LOGGING
44*5113495bSYour Name #include <wlan_connectivity_logging.h>
45*5113495bSYour Name #endif
46*5113495bSYour Name
47*5113495bSYour Name #include "qdf_ssr_driver_dump.h"
48*5113495bSYour Name #ifdef CNSS_GENL
49*5113495bSYour Name #ifdef CONFIG_CNSS_OUT_OF_TREE
50*5113495bSYour Name #include "cnss_nl.h"
51*5113495bSYour Name #else
52*5113495bSYour Name #include <net/cnss_nl.h>
53*5113495bSYour Name #endif
54*5113495bSYour Name #endif
55*5113495bSYour Name
56*5113495bSYour Name #if defined(FEATURE_FW_LOG_PARSING) || defined(FEATURE_WLAN_DIAG_SUPPORT) || \
57*5113495bSYour Name defined(CONNECTIVITY_PKTLOG)
58*5113495bSYour Name #include <cds_api.h>
59*5113495bSYour Name #include "ani_global.h"
60*5113495bSYour Name #endif
61*5113495bSYour Name
62*5113495bSYour Name #ifdef CONNECTIVITY_PKTLOG
63*5113495bSYour Name #include "wma.h"
64*5113495bSYour Name #include "pktlog_ac.h"
65*5113495bSYour Name #include <cdp_txrx_misc.h>
66*5113495bSYour Name #endif
67*5113495bSYour Name
68*5113495bSYour Name #ifdef WLAN_CHIPSET_STATS
69*5113495bSYour Name #include <wlan_cp_stats_chipset_stats.h>
70*5113495bSYour Name #include <wlan_cp_stats_ucfg_api.h>
71*5113495bSYour Name #endif
72*5113495bSYour Name
73*5113495bSYour Name /*
74*5113495bSYour Name * The following commit was introduced in v5.17:
75*5113495bSYour Name * cead18552660 ("exit: Rename complete_and_exit to kthread_complete_and_exit")
76*5113495bSYour Name * Use the old name for kernels before 5.17
77*5113495bSYour Name */
78*5113495bSYour Name #if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 17, 0))
79*5113495bSYour Name #define kthread_complete_and_exit(c, s) complete_and_exit(c, s)
80*5113495bSYour Name #endif
81*5113495bSYour Name
82*5113495bSYour Name #define MAX_NUM_PKT_LOG 32
83*5113495bSYour Name
84*5113495bSYour Name #define LOGGING_TRACE(level, args ...) \
85*5113495bSYour Name QDF_TRACE(QDF_MODULE_ID_HDD, level, ## args)
86*5113495bSYour Name
87*5113495bSYour Name /* Global variables */
88*5113495bSYour Name
89*5113495bSYour Name #define ANI_NL_MSG_LOG_TYPE 89
90*5113495bSYour Name #define ANI_NL_MSG_READY_IND_TYPE 90
91*5113495bSYour Name #ifndef MAX_LOGMSG_COUNT
92*5113495bSYour Name #define MAX_LOGMSG_COUNT 256
93*5113495bSYour Name #endif
94*5113495bSYour Name #define MAX_LOGMSG_LENGTH 2048
95*5113495bSYour Name #define MAX_SKBMSG_LENGTH 4096
96*5113495bSYour Name
97*5113495bSYour Name #define WLAN_LOG_BUFFER_SIZE 2048
98*5113495bSYour Name #ifdef CONNECTIVITY_PKTLOG
99*5113495bSYour Name /**
100*5113495bSYour Name * Buffer to accommodate -
101*5113495bSYour Name * pktlog buffer (2048 bytes)
102*5113495bSYour Name * ath_pktlog_hdr (16 bytes)
103*5113495bSYour Name * pkt_dump (8 bytes)
104*5113495bSYour Name * extra padding (40 bytes)
105*5113495bSYour Name *
106*5113495bSYour Name * Note: pktlog buffer size is dependent on RX_BUFFER_SIZE and
107*5113495bSYour Name * HTT_T2H_MAX_MSG_SIZE. Adjust WLAN_LOG_BUFFER_SIZE
108*5113495bSYour Name * based on the above mentioned macros.
109*5113495bSYour Name */
110*5113495bSYour Name #define ATH_PKTLOG_HDR_SIZE (sizeof(struct ath_pktlog_hdr))
111*5113495bSYour Name #define PKT_DUMP_HDR_SIZE (sizeof(struct packet_dump))
112*5113495bSYour Name #define EXTRA_PADDING 40
113*5113495bSYour Name
114*5113495bSYour Name #define MAX_PKTSTATS_LENGTH \
115*5113495bSYour Name ((WLAN_LOG_BUFFER_SIZE) + (ATH_PKTLOG_HDR_SIZE) + \
116*5113495bSYour Name (PKT_DUMP_HDR_SIZE) + (EXTRA_PADDING))
117*5113495bSYour Name #else
118*5113495bSYour Name #define MAX_PKTSTATS_LENGTH WLAN_LOG_BUFFER_SIZE
119*5113495bSYour Name #endif /* CONNECTIVITY_PKTLOG */
120*5113495bSYour Name
121*5113495bSYour Name #define MAX_PKTSTATS_BUFF 16
122*5113495bSYour Name #define HOST_LOG_DRIVER_MSG 0x001
123*5113495bSYour Name #define HOST_LOG_PER_PKT_STATS 0x002
124*5113495bSYour Name #define HOST_LOG_FW_FLUSH_COMPLETE 0x003
125*5113495bSYour Name #define HOST_LOG_DRIVER_CONNECTIVITY_MSG 0x004
126*5113495bSYour Name #define HOST_LOG_CHIPSET_STATS 0x005
127*5113495bSYour Name #define FW_LOG_CHIPSET_STATS 0x006
128*5113495bSYour Name
129*5113495bSYour Name #define DIAG_TYPE_LOGS 1
130*5113495bSYour Name #define PTT_MSG_DIAG_CMDS_TYPE 0x5050
131*5113495bSYour Name #define MAX_LOG_LINE 500
132*5113495bSYour Name
133*5113495bSYour Name /* default rate limit period - 2sec */
134*5113495bSYour Name #define PANIC_WIFILOG_PRINT_RATE_LIMIT_PERIOD (2*HZ)
135*5113495bSYour Name /* default burst for rate limit */
136*5113495bSYour Name #define PANIC_WIFILOG_PRINT_RATE_LIMIT_BURST_DEFAULT 500
137*5113495bSYour Name DEFINE_RATELIMIT_STATE(panic_wifilog_ratelimit,
138*5113495bSYour Name PANIC_WIFILOG_PRINT_RATE_LIMIT_PERIOD,
139*5113495bSYour Name PANIC_WIFILOG_PRINT_RATE_LIMIT_BURST_DEFAULT);
140*5113495bSYour Name
141*5113495bSYour Name #define FLUSH_LOG_COMPLETION_TIMEOUT 3000
142*5113495bSYour Name
143*5113495bSYour Name struct log_msg {
144*5113495bSYour Name struct list_head node;
145*5113495bSYour Name unsigned int radio;
146*5113495bSYour Name unsigned int index;
147*5113495bSYour Name /* indicates the current filled log length in logbuf */
148*5113495bSYour Name unsigned int filled_length;
149*5113495bSYour Name /*
150*5113495bSYour Name * Buf to hold the log msg
151*5113495bSYour Name * tAniHdr + log
152*5113495bSYour Name */
153*5113495bSYour Name char logbuf[MAX_LOGMSG_LENGTH];
154*5113495bSYour Name };
155*5113495bSYour Name
156*5113495bSYour Name /**
157*5113495bSYour Name * struct packet_dump - This data structure contains the
158*5113495bSYour Name * Tx/Rx packet stats
159*5113495bSYour Name * @status: Status
160*5113495bSYour Name * @type: Type
161*5113495bSYour Name * @driver_ts: driver timestamp
162*5113495bSYour Name * @fw_ts: fw timestamp
163*5113495bSYour Name */
164*5113495bSYour Name struct packet_dump {
165*5113495bSYour Name unsigned char status;
166*5113495bSYour Name unsigned char type;
167*5113495bSYour Name uint32_t driver_ts;
168*5113495bSYour Name uint16_t fw_ts;
169*5113495bSYour Name } __attribute__((__packed__));
170*5113495bSYour Name
171*5113495bSYour Name /**
172*5113495bSYour Name * struct pkt_stats_msg - This data structure contains the
173*5113495bSYour Name * pkt stats node for link list
174*5113495bSYour Name * @node: LinkList node
175*5113495bSYour Name * @node: Pointer to skb
176*5113495bSYour Name */
177*5113495bSYour Name struct pkt_stats_msg {
178*5113495bSYour Name struct list_head node;
179*5113495bSYour Name struct sk_buff *skb;
180*5113495bSYour Name };
181*5113495bSYour Name
182*5113495bSYour Name #define MAX_FLUSH_TIMER_PERIOD_VALUE 3600000 /* maximum of 1 hour (in ms) */
183*5113495bSYour Name struct wlan_logging {
184*5113495bSYour Name /* Console log levels */
185*5113495bSYour Name uint32_t console_log_levels;
186*5113495bSYour Name /* Number of buffers to be used for logging */
187*5113495bSYour Name uint32_t num_buf;
188*5113495bSYour Name uint32_t buffer_length;
189*5113495bSYour Name /* Lock to synchronize access to shared logging resource */
190*5113495bSYour Name spinlock_t spin_lock;
191*5113495bSYour Name /* Holds the free node which can be used for filling logs */
192*5113495bSYour Name struct list_head free_list;
193*5113495bSYour Name /* Holds the filled nodes which needs to be indicated to APP */
194*5113495bSYour Name struct list_head filled_list;
195*5113495bSYour Name /* Holds nodes for console printing in case of kernel panic */
196*5113495bSYour Name struct list_head panic_list;
197*5113495bSYour Name /* Wait queue for Logger thread */
198*5113495bSYour Name wait_queue_head_t wait_queue;
199*5113495bSYour Name /* Logger thread */
200*5113495bSYour Name struct task_struct *thread;
201*5113495bSYour Name /* Logging thread sets this variable on exit */
202*5113495bSYour Name struct completion shutdown_comp;
203*5113495bSYour Name /* Indicates to logger thread to exit */
204*5113495bSYour Name bool exit;
205*5113495bSYour Name /* Holds number of dropped logs */
206*5113495bSYour Name unsigned int drop_count;
207*5113495bSYour Name /* current logbuf to which the log will be filled to */
208*5113495bSYour Name struct log_msg *pcur_node;
209*5113495bSYour Name /* Event flag used for wakeup and post indication*/
210*5113495bSYour Name unsigned long eventFlag;
211*5113495bSYour Name /* Indicates logger thread is activated */
212*5113495bSYour Name bool is_active;
213*5113495bSYour Name /* Flush completion check */
214*5113495bSYour Name bool is_flush_complete;
215*5113495bSYour Name /* parameters for pkt stats */
216*5113495bSYour Name struct list_head pkt_stat_free_list;
217*5113495bSYour Name struct list_head pkt_stat_filled_list;
218*5113495bSYour Name struct pkt_stats_msg *pkt_stats_pcur_node;
219*5113495bSYour Name unsigned int pkt_stat_drop_cnt;
220*5113495bSYour Name spinlock_t pkt_stats_lock;
221*5113495bSYour Name unsigned int pkt_stats_msg_idx;
222*5113495bSYour Name qdf_timer_t flush_timer;
223*5113495bSYour Name bool is_flush_timer_initialized;
224*5113495bSYour Name uint32_t flush_timer_period;
225*5113495bSYour Name qdf_spinlock_t flush_timer_lock;
226*5113495bSYour Name qdf_event_t flush_log_completion;
227*5113495bSYour Name uint64_t wakup_ts;
228*5113495bSYour Name uint64_t start_ts;
229*5113495bSYour Name uint64_t reinitcompletion_ts;
230*5113495bSYour Name uint64_t set_exit_ts;
231*5113495bSYour Name uint64_t exit_ts;
232*5113495bSYour Name };
233*5113495bSYour Name
234*5113495bSYour Name /* This global variable is intentionally not marked static because it
235*5113495bSYour Name * is used by offline tools. Please do not use it outside this file.
236*5113495bSYour Name */
237*5113495bSYour Name struct wlan_logging gwlan_logging;
238*5113495bSYour Name static struct pkt_stats_msg *gpkt_stats_buffers;
239*5113495bSYour Name
240*5113495bSYour Name #ifdef WLAN_LOGGING_BUFFERS_DYNAMICALLY
241*5113495bSYour Name
242*5113495bSYour Name static struct log_msg *gplog_msg;
243*5113495bSYour Name
allocate_log_msg_buffer(void)244*5113495bSYour Name static inline QDF_STATUS allocate_log_msg_buffer(void)
245*5113495bSYour Name {
246*5113495bSYour Name gplog_msg = qdf_mem_valloc(MAX_LOGMSG_COUNT * sizeof(*gplog_msg));
247*5113495bSYour Name
248*5113495bSYour Name return gplog_msg ? QDF_STATUS_SUCCESS : QDF_STATUS_E_NOMEM;
249*5113495bSYour Name }
250*5113495bSYour Name
free_log_msg_buffer(void)251*5113495bSYour Name static inline void free_log_msg_buffer(void)
252*5113495bSYour Name {
253*5113495bSYour Name qdf_mem_vfree(gplog_msg);
254*5113495bSYour Name gplog_msg = NULL;
255*5113495bSYour Name }
256*5113495bSYour Name
257*5113495bSYour Name #else
258*5113495bSYour Name static struct log_msg gplog_msg[MAX_LOGMSG_COUNT];
259*5113495bSYour Name
allocate_log_msg_buffer(void)260*5113495bSYour Name static inline QDF_STATUS allocate_log_msg_buffer(void)
261*5113495bSYour Name {
262*5113495bSYour Name qdf_minidump_log(&gwlan_logging, sizeof(gwlan_logging),
263*5113495bSYour Name "gwlan_logging");
264*5113495bSYour Name qdf_minidump_log(gplog_msg, sizeof(gplog_msg), "wlan_logs");
265*5113495bSYour Name qdf_ssr_driver_dump_register_region("gwlan_logging", &gwlan_logging,
266*5113495bSYour Name sizeof(gwlan_logging));
267*5113495bSYour Name qdf_ssr_driver_dump_register_region("wlan_logs", gplog_msg,
268*5113495bSYour Name sizeof(gplog_msg));
269*5113495bSYour Name return QDF_STATUS_SUCCESS;
270*5113495bSYour Name }
271*5113495bSYour Name
free_log_msg_buffer(void)272*5113495bSYour Name static inline void free_log_msg_buffer(void)
273*5113495bSYour Name {
274*5113495bSYour Name qdf_ssr_driver_dump_unregister_region("wlan_logs");
275*5113495bSYour Name qdf_ssr_driver_dump_unregister_region("gwlan_logging");
276*5113495bSYour Name qdf_minidump_remove(gplog_msg, sizeof(gplog_msg), "wlan_logs");
277*5113495bSYour Name qdf_minidump_remove(&gwlan_logging, sizeof(gwlan_logging),
278*5113495bSYour Name "gwlan_logging");
279*5113495bSYour Name }
280*5113495bSYour Name #endif
281*5113495bSYour Name
282*5113495bSYour Name /* Need to call this with spin_lock acquired */
wlan_queue_logmsg_for_app(void)283*5113495bSYour Name static int wlan_queue_logmsg_for_app(void)
284*5113495bSYour Name {
285*5113495bSYour Name char *ptr;
286*5113495bSYour Name int ret = 0;
287*5113495bSYour Name ptr = &gwlan_logging.pcur_node->logbuf[sizeof(tAniHdr)];
288*5113495bSYour Name ptr[gwlan_logging.pcur_node->filled_length] = '\0';
289*5113495bSYour Name
290*5113495bSYour Name *(unsigned short *)(gwlan_logging.pcur_node->logbuf) =
291*5113495bSYour Name ANI_NL_MSG_LOG_TYPE;
292*5113495bSYour Name *(unsigned short *)(gwlan_logging.pcur_node->logbuf + 2) =
293*5113495bSYour Name gwlan_logging.pcur_node->filled_length;
294*5113495bSYour Name list_add_tail(&gwlan_logging.pcur_node->node,
295*5113495bSYour Name &gwlan_logging.filled_list);
296*5113495bSYour Name
297*5113495bSYour Name if (!list_empty(&gwlan_logging.free_list)) {
298*5113495bSYour Name /* Get buffer from free list */
299*5113495bSYour Name gwlan_logging.pcur_node =
300*5113495bSYour Name (struct log_msg *)(gwlan_logging.free_list.next);
301*5113495bSYour Name list_del_init(gwlan_logging.free_list.next);
302*5113495bSYour Name } else if (!list_empty(&gwlan_logging.filled_list)) {
303*5113495bSYour Name /* Get buffer from filled list */
304*5113495bSYour Name /* This condition will drop the packet from being
305*5113495bSYour Name * indicated to app
306*5113495bSYour Name */
307*5113495bSYour Name gwlan_logging.pcur_node =
308*5113495bSYour Name (struct log_msg *)(gwlan_logging.filled_list.next);
309*5113495bSYour Name ++gwlan_logging.drop_count;
310*5113495bSYour Name list_del_init(gwlan_logging.filled_list.next);
311*5113495bSYour Name ret = 1;
312*5113495bSYour Name }
313*5113495bSYour Name
314*5113495bSYour Name /* Reset the current node values */
315*5113495bSYour Name gwlan_logging.pcur_node->filled_length = 0;
316*5113495bSYour Name return ret;
317*5113495bSYour Name }
318*5113495bSYour Name
current_process_name(void)319*5113495bSYour Name static const char *current_process_name(void)
320*5113495bSYour Name {
321*5113495bSYour Name if (in_irq())
322*5113495bSYour Name return "irq";
323*5113495bSYour Name
324*5113495bSYour Name if (in_softirq())
325*5113495bSYour Name return "soft_irq";
326*5113495bSYour Name
327*5113495bSYour Name return current->comm;
328*5113495bSYour Name }
329*5113495bSYour Name
330*5113495bSYour Name /**
331*5113495bSYour Name * wlan_add_user_log_time_stamp() - populate firmware and kernel timestamps
332*5113495bSYour Name * @tbuf: Pointer to time stamp buffer
333*5113495bSYour Name * @tbuf_sz: Time buffer size
334*5113495bSYour Name * @ts: Time stamp value
335*5113495bSYour Name *
336*5113495bSYour Name * For adrastea time stamp is QTIMER raw tick which will be used by cnss_diag
337*5113495bSYour Name * to convert it into user visible time stamp. In adrstea FW also uses QTIMER
338*5113495bSYour Name * raw ticks which is needed to synchronize host and fw log time stamps
339*5113495bSYour Name *
340*5113495bSYour Name * Also add logcat timestamp so that driver logs and
341*5113495bSYour Name * logcat logs can be co-related
342*5113495bSYour Name *
343*5113495bSYour Name * For discrete solution e.g rome use system tick and convert it into
344*5113495bSYour Name * seconds.milli seconds
345*5113495bSYour Name *
346*5113495bSYour Name * Return: number of characters written in target buffer not including
347*5113495bSYour Name * trailing '/0'
348*5113495bSYour Name */
wlan_add_user_log_time_stamp(char * tbuf,size_t tbuf_sz,uint64_t ts)349*5113495bSYour Name static int wlan_add_user_log_time_stamp(char *tbuf, size_t tbuf_sz, uint64_t ts)
350*5113495bSYour Name {
351*5113495bSYour Name char time_buf[20];
352*5113495bSYour Name
353*5113495bSYour Name qdf_get_time_of_the_day_in_hr_min_sec_usec(time_buf, sizeof(time_buf));
354*5113495bSYour Name
355*5113495bSYour Name return scnprintf(tbuf, tbuf_sz, "[%.6s][0x%llx]%s",
356*5113495bSYour Name current_process_name(), (unsigned long long)ts,
357*5113495bSYour Name time_buf);
358*5113495bSYour Name }
359*5113495bSYour Name
360*5113495bSYour Name #ifdef WLAN_MAX_LOGS_PER_SEC
wlan_panic_on_excessive_logging(void)361*5113495bSYour Name static inline void wlan_panic_on_excessive_logging(void)
362*5113495bSYour Name {
363*5113495bSYour Name if (qdf_detected_excessive_logging())
364*5113495bSYour Name QDF_DEBUG_PANIC("Exceeded %d logs per second",
365*5113495bSYour Name WLAN_MAX_LOGS_PER_SEC);
366*5113495bSYour Name }
367*5113495bSYour Name #else
wlan_panic_on_excessive_logging(void)368*5113495bSYour Name static inline void wlan_panic_on_excessive_logging(void) {}
369*5113495bSYour Name #endif /* WLAN_MAX_LOGS_PER_SEC */
370*5113495bSYour Name
371*5113495bSYour Name #ifdef QDF_TRACE_PRINT_ENABLE
372*5113495bSYour Name static inline void
log_to_console(QDF_TRACE_LEVEL level,const char * timestamp,const char * msg)373*5113495bSYour Name log_to_console(QDF_TRACE_LEVEL level, const char *timestamp, const char *msg)
374*5113495bSYour Name {
375*5113495bSYour Name if (qdf_detected_excessive_logging()) {
376*5113495bSYour Name qdf_rl_print_suppressed_inc();
377*5113495bSYour Name return;
378*5113495bSYour Name }
379*5113495bSYour Name
380*5113495bSYour Name qdf_rl_print_suppressed_log();
381*5113495bSYour Name pr_err("%s %s\n", timestamp, msg);
382*5113495bSYour Name }
383*5113495bSYour Name #else
384*5113495bSYour Name static inline void
log_to_console(QDF_TRACE_LEVEL level,const char * timestamp,const char * msg)385*5113495bSYour Name log_to_console(QDF_TRACE_LEVEL level, const char *timestamp, const char *msg)
386*5113495bSYour Name {
387*5113495bSYour Name switch (level) {
388*5113495bSYour Name case QDF_TRACE_LEVEL_FATAL:
389*5113495bSYour Name pr_alert("%s %s\n", timestamp, msg);
390*5113495bSYour Name wlan_panic_on_excessive_logging();
391*5113495bSYour Name break;
392*5113495bSYour Name case QDF_TRACE_LEVEL_ERROR:
393*5113495bSYour Name pr_err("%s %s\n", timestamp, msg);
394*5113495bSYour Name wlan_panic_on_excessive_logging();
395*5113495bSYour Name break;
396*5113495bSYour Name case QDF_TRACE_LEVEL_WARN:
397*5113495bSYour Name pr_warn("%s %s\n", timestamp, msg);
398*5113495bSYour Name wlan_panic_on_excessive_logging();
399*5113495bSYour Name break;
400*5113495bSYour Name case QDF_TRACE_LEVEL_INFO:
401*5113495bSYour Name pr_info("%s %s\n", timestamp, msg);
402*5113495bSYour Name wlan_panic_on_excessive_logging();
403*5113495bSYour Name break;
404*5113495bSYour Name case QDF_TRACE_LEVEL_INFO_HIGH:
405*5113495bSYour Name case QDF_TRACE_LEVEL_INFO_MED:
406*5113495bSYour Name case QDF_TRACE_LEVEL_INFO_LOW:
407*5113495bSYour Name case QDF_TRACE_LEVEL_DEBUG:
408*5113495bSYour Name default:
409*5113495bSYour Name /* these levels should not be logged to console */
410*5113495bSYour Name break;
411*5113495bSYour Name }
412*5113495bSYour Name }
413*5113495bSYour Name #endif
414*5113495bSYour Name
wlan_log_to_user(QDF_TRACE_LEVEL log_level,char * to_be_sent,int length)415*5113495bSYour Name int wlan_log_to_user(QDF_TRACE_LEVEL log_level, char *to_be_sent, int length)
416*5113495bSYour Name {
417*5113495bSYour Name char *ptr;
418*5113495bSYour Name char tbuf[60];
419*5113495bSYour Name int tlen;
420*5113495bSYour Name int total_log_len;
421*5113495bSYour Name unsigned int *pfilled_length;
422*5113495bSYour Name bool wake_up_thread = false;
423*5113495bSYour Name unsigned long flags;
424*5113495bSYour Name uint64_t ts;
425*5113495bSYour Name
426*5113495bSYour Name /* Add the current time stamp */
427*5113495bSYour Name ts = qdf_get_log_timestamp();
428*5113495bSYour Name tlen = wlan_add_user_log_time_stamp(tbuf, sizeof(tbuf), ts);
429*5113495bSYour Name
430*5113495bSYour Name /* if logging isn't up yet, just dump to dmesg */
431*5113495bSYour Name if (!gwlan_logging.is_active) {
432*5113495bSYour Name log_to_console(log_level, tbuf, to_be_sent);
433*5113495bSYour Name return 0;
434*5113495bSYour Name }
435*5113495bSYour Name
436*5113495bSYour Name /* 1+1 indicate '\n'+'\0' */
437*5113495bSYour Name total_log_len = length + tlen + 1 + 1;
438*5113495bSYour Name
439*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
440*5113495bSYour Name /* wlan logging svc resources are not yet initialized */
441*5113495bSYour Name if (!gwlan_logging.pcur_node) {
442*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
443*5113495bSYour Name return -EIO;
444*5113495bSYour Name }
445*5113495bSYour Name
446*5113495bSYour Name pfilled_length = &gwlan_logging.pcur_node->filled_length;
447*5113495bSYour Name
448*5113495bSYour Name /* Check if we can accommodate more log into current node/buffer */
449*5113495bSYour Name if ((MAX_LOGMSG_LENGTH - (*pfilled_length +
450*5113495bSYour Name sizeof(tAniNlHdr))) < total_log_len) {
451*5113495bSYour Name wake_up_thread = true;
452*5113495bSYour Name wlan_queue_logmsg_for_app();
453*5113495bSYour Name pfilled_length = &gwlan_logging.pcur_node->filled_length;
454*5113495bSYour Name }
455*5113495bSYour Name
456*5113495bSYour Name ptr = &gwlan_logging.pcur_node->logbuf[sizeof(tAniHdr)];
457*5113495bSYour Name
458*5113495bSYour Name if (unlikely(MAX_LOGMSG_LENGTH < (sizeof(tAniNlHdr) + total_log_len))) {
459*5113495bSYour Name /*
460*5113495bSYour Name * Assumption here is that we receive logs which is less than
461*5113495bSYour Name * MAX_LOGMSG_LENGTH, where we can accommodate the
462*5113495bSYour Name * tAniNlHdr + [context][timestamp] + log
463*5113495bSYour Name * If log length is over MAX_LOGMSG_LENGTH,
464*5113495bSYour Name * the overflow part will be discarded.
465*5113495bSYour Name */
466*5113495bSYour Name length = MAX_LOGMSG_LENGTH - sizeof(tAniNlHdr) - tlen - 2;
467*5113495bSYour Name /*
468*5113495bSYour Name * QDF_ASSERT if complete log was not accommodated into
469*5113495bSYour Name * the available buffer.
470*5113495bSYour Name */
471*5113495bSYour Name QDF_ASSERT(0);
472*5113495bSYour Name }
473*5113495bSYour Name
474*5113495bSYour Name memcpy(&ptr[*pfilled_length], tbuf, tlen);
475*5113495bSYour Name memcpy(&ptr[*pfilled_length + tlen], to_be_sent, length);
476*5113495bSYour Name *pfilled_length += tlen + length;
477*5113495bSYour Name ptr[*pfilled_length] = '\n';
478*5113495bSYour Name *pfilled_length += 1;
479*5113495bSYour Name
480*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
481*5113495bSYour Name
482*5113495bSYour Name /* Wakeup logger thread */
483*5113495bSYour Name if (wake_up_thread) {
484*5113495bSYour Name set_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
485*5113495bSYour Name wake_up_interruptible(&gwlan_logging.wait_queue);
486*5113495bSYour Name }
487*5113495bSYour Name
488*5113495bSYour Name if (gwlan_logging.console_log_levels & BIT(log_level))
489*5113495bSYour Name log_to_console(log_level, tbuf, to_be_sent);
490*5113495bSYour Name
491*5113495bSYour Name return 0;
492*5113495bSYour Name }
493*5113495bSYour Name
494*5113495bSYour Name /**
495*5113495bSYour Name * nl_srv_bcast_host_logs() - Wrapper to send bcast msgs to host logs mcast grp
496*5113495bSYour Name * @skb: sk buffer pointer
497*5113495bSYour Name *
498*5113495bSYour Name * Sends the bcast message to host logs multicast group with generic nl socket
499*5113495bSYour Name * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
500*5113495bSYour Name *
501*5113495bSYour Name * Return: zero on success, error code otherwise
502*5113495bSYour Name */
503*5113495bSYour Name #ifdef CNSS_GENL
nl_srv_bcast_host_logs(struct sk_buff * skb)504*5113495bSYour Name static int nl_srv_bcast_host_logs(struct sk_buff *skb)
505*5113495bSYour Name {
506*5113495bSYour Name return nl_srv_bcast(skb, CLD80211_MCGRP_HOST_LOGS, ANI_NL_MSG_LOG);
507*5113495bSYour Name }
508*5113495bSYour Name #else
nl_srv_bcast_host_logs(struct sk_buff * skb)509*5113495bSYour Name static int nl_srv_bcast_host_logs(struct sk_buff *skb)
510*5113495bSYour Name {
511*5113495bSYour Name return nl_srv_bcast(skb);
512*5113495bSYour Name }
513*5113495bSYour Name #endif
514*5113495bSYour Name
515*5113495bSYour Name #ifdef CONNECTIVITY_PKTLOG
516*5113495bSYour Name /**
517*5113495bSYour Name * pkt_stats_fill_headers() - This function adds headers to skb
518*5113495bSYour Name * @skb: skb to which headers need to be added
519*5113495bSYour Name *
520*5113495bSYour Name * Return: 0 on success or Errno on failure
521*5113495bSYour Name */
pkt_stats_fill_headers(struct sk_buff * skb)522*5113495bSYour Name static int pkt_stats_fill_headers(struct sk_buff *skb)
523*5113495bSYour Name {
524*5113495bSYour Name struct host_log_pktlog_info cds_pktlog;
525*5113495bSYour Name int cds_pkt_size = sizeof(struct host_log_pktlog_info);
526*5113495bSYour Name tAniNlHdr msg_header;
527*5113495bSYour Name int extra_header_len, nl_payload_len;
528*5113495bSYour Name static int nlmsg_seq;
529*5113495bSYour Name int diag_type;
530*5113495bSYour Name
531*5113495bSYour Name qdf_mem_zero(&cds_pktlog, cds_pkt_size);
532*5113495bSYour Name cds_pktlog.version = VERSION_LOG_WLAN_PKT_LOG_INFO_C;
533*5113495bSYour Name cds_pktlog.buf_len = skb->len;
534*5113495bSYour Name cds_pktlog.seq_no = gwlan_logging.pkt_stats_msg_idx++;
535*5113495bSYour Name host_diag_log_set_code(&cds_pktlog, LOG_WLAN_PKT_LOG_INFO_C);
536*5113495bSYour Name host_diag_log_set_length(&cds_pktlog.log_hdr, skb->len +
537*5113495bSYour Name cds_pkt_size);
538*5113495bSYour Name
539*5113495bSYour Name if (unlikely(skb_headroom(skb) < cds_pkt_size)) {
540*5113495bSYour Name qdf_nofl_err("VPKT [%d]: Insufficient headroom, head[%pK], data[%pK], req[%zu]",
541*5113495bSYour Name __LINE__, skb->head, skb->data,
542*5113495bSYour Name sizeof(msg_header));
543*5113495bSYour Name return -EIO;
544*5113495bSYour Name }
545*5113495bSYour Name
546*5113495bSYour Name qdf_mem_copy(skb_push(skb, cds_pkt_size),
547*5113495bSYour Name &cds_pktlog, cds_pkt_size);
548*5113495bSYour Name
549*5113495bSYour Name if (unlikely(skb_headroom(skb) < sizeof(int))) {
550*5113495bSYour Name qdf_nofl_err("VPKT [%d]: Insufficient headroom, head[%pK], data[%pK], req[%zu]",
551*5113495bSYour Name __LINE__, skb->head, skb->data,
552*5113495bSYour Name sizeof(int));
553*5113495bSYour Name return -EIO;
554*5113495bSYour Name }
555*5113495bSYour Name
556*5113495bSYour Name diag_type = DIAG_TYPE_LOGS;
557*5113495bSYour Name qdf_mem_copy(skb_push(skb, sizeof(int)), &diag_type, sizeof(int));
558*5113495bSYour Name
559*5113495bSYour Name extra_header_len = sizeof(msg_header.radio) + sizeof(tAniHdr) +
560*5113495bSYour Name sizeof(struct nlmsghdr);
561*5113495bSYour Name nl_payload_len = extra_header_len + skb->len;
562*5113495bSYour Name
563*5113495bSYour Name msg_header.nlh.nlmsg_type = ANI_NL_MSG_PUMAC;
564*5113495bSYour Name msg_header.nlh.nlmsg_len = nl_payload_len;
565*5113495bSYour Name msg_header.nlh.nlmsg_flags = NLM_F_REQUEST;
566*5113495bSYour Name msg_header.nlh.nlmsg_pid = 0;
567*5113495bSYour Name msg_header.nlh.nlmsg_seq = nlmsg_seq++;
568*5113495bSYour Name msg_header.radio = 0;
569*5113495bSYour Name msg_header.wmsg.type = PTT_MSG_DIAG_CMDS_TYPE;
570*5113495bSYour Name msg_header.wmsg.length = cpu_to_be16(skb->len);
571*5113495bSYour Name
572*5113495bSYour Name if (unlikely(skb_headroom(skb) < sizeof(msg_header))) {
573*5113495bSYour Name qdf_nofl_err("VPKT [%d]: Insufficient headroom, head[%pK], data[%pK], req[%zu]",
574*5113495bSYour Name __LINE__, skb->head, skb->data,
575*5113495bSYour Name sizeof(msg_header));
576*5113495bSYour Name return -EIO;
577*5113495bSYour Name }
578*5113495bSYour Name
579*5113495bSYour Name qdf_mem_copy(skb_push(skb, sizeof(msg_header)), &msg_header,
580*5113495bSYour Name sizeof(msg_header));
581*5113495bSYour Name
582*5113495bSYour Name return 0;
583*5113495bSYour Name }
584*5113495bSYour Name
585*5113495bSYour Name /**
586*5113495bSYour Name * nl_srv_bcast_diag() - Wrapper to send bcast msgs to diag events mcast grp
587*5113495bSYour Name * @skb: sk buffer pointer
588*5113495bSYour Name *
589*5113495bSYour Name * Sends the bcast message to diag events multicast group with generic nl socket
590*5113495bSYour Name * if CNSS_GENL is enabled. Else, use the legacy netlink socket to send.
591*5113495bSYour Name *
592*5113495bSYour Name * Return: zero on success, error code otherwise
593*5113495bSYour Name */
nl_srv_bcast_diag(struct sk_buff * skb)594*5113495bSYour Name static int nl_srv_bcast_diag(struct sk_buff *skb)
595*5113495bSYour Name {
596*5113495bSYour Name #ifdef CNSS_GENL
597*5113495bSYour Name return nl_srv_bcast(skb, CLD80211_MCGRP_DIAG_EVENTS, ANI_NL_MSG_PUMAC);
598*5113495bSYour Name #else
599*5113495bSYour Name return nl_srv_bcast(skb);
600*5113495bSYour Name #endif
601*5113495bSYour Name }
602*5113495bSYour Name
603*5113495bSYour Name /**
604*5113495bSYour Name * pktlog_send_per_pkt_stats_to_user() - This function is used to send the per
605*5113495bSYour Name * packet statistics to the user
606*5113495bSYour Name *
607*5113495bSYour Name * This function is used to send the per packet statistics to the user
608*5113495bSYour Name *
609*5113495bSYour Name * Return: Success if the message is posted to user
610*5113495bSYour Name */
pktlog_send_per_pkt_stats_to_user(void)611*5113495bSYour Name static int pktlog_send_per_pkt_stats_to_user(void)
612*5113495bSYour Name {
613*5113495bSYour Name int ret = -1;
614*5113495bSYour Name struct pkt_stats_msg *pstats_msg;
615*5113495bSYour Name unsigned long flags;
616*5113495bSYour Name struct sk_buff *skb_new = NULL;
617*5113495bSYour Name static int rate_limit;
618*5113495bSYour Name bool free_old_skb = false;
619*5113495bSYour Name
620*5113495bSYour Name while (!list_empty(&gwlan_logging.pkt_stat_filled_list)
621*5113495bSYour Name && !gwlan_logging.exit) {
622*5113495bSYour Name skb_new = dev_alloc_skb(MAX_SKBMSG_LENGTH);
623*5113495bSYour Name if (!skb_new) {
624*5113495bSYour Name if (!rate_limit) {
625*5113495bSYour Name qdf_err("dev_alloc_skb() failed for msg size[%d] drop count = %u",
626*5113495bSYour Name MAX_SKBMSG_LENGTH,
627*5113495bSYour Name gwlan_logging.drop_count);
628*5113495bSYour Name }
629*5113495bSYour Name rate_limit = 1;
630*5113495bSYour Name ret = -ENOMEM;
631*5113495bSYour Name break;
632*5113495bSYour Name }
633*5113495bSYour Name
634*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, flags);
635*5113495bSYour Name
636*5113495bSYour Name pstats_msg = (struct pkt_stats_msg *)
637*5113495bSYour Name (gwlan_logging.pkt_stat_filled_list.next);
638*5113495bSYour Name list_del_init(gwlan_logging.pkt_stat_filled_list.next);
639*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
640*5113495bSYour Name
641*5113495bSYour Name ret = pkt_stats_fill_headers(pstats_msg->skb);
642*5113495bSYour Name if (ret < 0) {
643*5113495bSYour Name qdf_err("Failed to fill headers %d", ret);
644*5113495bSYour Name free_old_skb = true;
645*5113495bSYour Name goto err;
646*5113495bSYour Name }
647*5113495bSYour Name ret = nl_srv_bcast_diag(pstats_msg->skb);
648*5113495bSYour Name if (ret < 0) {
649*5113495bSYour Name qdf_info("Send Failed %d drop_count = %u", ret,
650*5113495bSYour Name ++gwlan_logging.pkt_stat_drop_cnt);
651*5113495bSYour Name } else {
652*5113495bSYour Name ret = 0;
653*5113495bSYour Name }
654*5113495bSYour Name err:
655*5113495bSYour Name /*
656*5113495bSYour Name * Free old skb in case or error before assigning new skb
657*5113495bSYour Name * to the free list.
658*5113495bSYour Name */
659*5113495bSYour Name if (free_old_skb)
660*5113495bSYour Name dev_kfree_skb(pstats_msg->skb);
661*5113495bSYour Name
662*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, flags);
663*5113495bSYour Name pstats_msg->skb = skb_new;
664*5113495bSYour Name list_add_tail(&pstats_msg->node,
665*5113495bSYour Name &gwlan_logging.pkt_stat_free_list);
666*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
667*5113495bSYour Name ret = 0;
668*5113495bSYour Name }
669*5113495bSYour Name
670*5113495bSYour Name return ret;
671*5113495bSYour Name
672*5113495bSYour Name }
673*5113495bSYour Name #else
674*5113495bSYour Name static inline
pktlog_send_per_pkt_stats_to_user(void)675*5113495bSYour Name int pktlog_send_per_pkt_stats_to_user(void)
676*5113495bSYour Name {
677*5113495bSYour Name return 0;
678*5113495bSYour Name }
679*5113495bSYour Name #endif
680*5113495bSYour Name
send_filled_buffers_to_user(void)681*5113495bSYour Name static int send_filled_buffers_to_user(void)
682*5113495bSYour Name {
683*5113495bSYour Name int ret = -1;
684*5113495bSYour Name struct log_msg *plog_msg;
685*5113495bSYour Name int payload_len;
686*5113495bSYour Name int tot_msg_len;
687*5113495bSYour Name tAniNlHdr *wnl;
688*5113495bSYour Name struct sk_buff *skb = NULL;
689*5113495bSYour Name struct nlmsghdr *nlh;
690*5113495bSYour Name static int nlmsg_seq;
691*5113495bSYour Name unsigned long flags;
692*5113495bSYour Name static int rate_limit;
693*5113495bSYour Name
694*5113495bSYour Name while (!list_empty(&gwlan_logging.filled_list)
695*5113495bSYour Name && !gwlan_logging.exit) {
696*5113495bSYour Name
697*5113495bSYour Name skb = dev_alloc_skb(MAX_LOGMSG_LENGTH);
698*5113495bSYour Name if (!skb) {
699*5113495bSYour Name if (!rate_limit) {
700*5113495bSYour Name qdf_err("dev_alloc_skb() failed for msg size[%d] drop count = %u",
701*5113495bSYour Name MAX_LOGMSG_LENGTH,
702*5113495bSYour Name gwlan_logging.drop_count);
703*5113495bSYour Name }
704*5113495bSYour Name rate_limit = 1;
705*5113495bSYour Name ret = -ENOMEM;
706*5113495bSYour Name break;
707*5113495bSYour Name }
708*5113495bSYour Name rate_limit = 0;
709*5113495bSYour Name
710*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
711*5113495bSYour Name
712*5113495bSYour Name plog_msg = (struct log_msg *)
713*5113495bSYour Name (gwlan_logging.filled_list.next);
714*5113495bSYour Name list_del_init(gwlan_logging.filled_list.next);
715*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
716*5113495bSYour Name /* 4 extra bytes for the radio idx */
717*5113495bSYour Name payload_len = plog_msg->filled_length +
718*5113495bSYour Name sizeof(wnl->radio) + sizeof(tAniHdr);
719*5113495bSYour Name
720*5113495bSYour Name tot_msg_len = NLMSG_SPACE(payload_len);
721*5113495bSYour Name nlh = nlmsg_put(skb, 0, nlmsg_seq++,
722*5113495bSYour Name ANI_NL_MSG_LOG, payload_len, NLM_F_REQUEST);
723*5113495bSYour Name if (!nlh) {
724*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
725*5113495bSYour Name list_add_tail(&plog_msg->node,
726*5113495bSYour Name &gwlan_logging.free_list);
727*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
728*5113495bSYour Name qdf_err("drop_count = %u", ++gwlan_logging.drop_count);
729*5113495bSYour Name qdf_err("nlmsg_put() failed for msg size[%d]",
730*5113495bSYour Name tot_msg_len);
731*5113495bSYour Name dev_kfree_skb(skb);
732*5113495bSYour Name skb = NULL;
733*5113495bSYour Name ret = -EINVAL;
734*5113495bSYour Name continue;
735*5113495bSYour Name }
736*5113495bSYour Name
737*5113495bSYour Name wnl = (tAniNlHdr *) nlh;
738*5113495bSYour Name wnl->radio = plog_msg->radio;
739*5113495bSYour Name
740*5113495bSYour Name /* Offset of data buffer from nlmsg_hdr + sizeof(int) radio */
741*5113495bSYour Name memcpy(nlmsg_data(nlh) + sizeof(wnl->radio), plog_msg->logbuf,
742*5113495bSYour Name plog_msg->filled_length + sizeof(tAniHdr));
743*5113495bSYour Name
744*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
745*5113495bSYour Name list_add_tail(&plog_msg->node, &gwlan_logging.free_list);
746*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
747*5113495bSYour Name
748*5113495bSYour Name ret = nl_srv_bcast_host_logs(skb);
749*5113495bSYour Name /* print every 64th drop count */
750*5113495bSYour Name if (ret < 0 && (!(gwlan_logging.drop_count % 0x40))) {
751*5113495bSYour Name qdf_err("Send Failed %d drop_count = %u",
752*5113495bSYour Name ret, ++gwlan_logging.drop_count);
753*5113495bSYour Name }
754*5113495bSYour Name }
755*5113495bSYour Name
756*5113495bSYour Name return ret;
757*5113495bSYour Name }
758*5113495bSYour Name
759*5113495bSYour Name #ifdef FEATURE_WLAN_DIAG_SUPPORT
760*5113495bSYour Name /**
761*5113495bSYour Name * wlan_report_log_completion() - Report bug report completion to userspace
762*5113495bSYour Name * @is_fatal: Type of event, fatal or not
763*5113495bSYour Name * @indicator: Source of bug report, framework/host/firmware
764*5113495bSYour Name * @reason_code: Reason for triggering bug report
765*5113495bSYour Name * @ring_id: Ring id of logging entities
766*5113495bSYour Name *
767*5113495bSYour Name * This function is used to report the bug report completion to userspace
768*5113495bSYour Name *
769*5113495bSYour Name * Return: None
770*5113495bSYour Name */
wlan_report_log_completion(uint32_t is_fatal,uint32_t indicator,uint32_t reason_code,uint8_t ring_id)771*5113495bSYour Name void wlan_report_log_completion(uint32_t is_fatal,
772*5113495bSYour Name uint32_t indicator,
773*5113495bSYour Name uint32_t reason_code,
774*5113495bSYour Name uint8_t ring_id)
775*5113495bSYour Name {
776*5113495bSYour Name WLAN_HOST_DIAG_EVENT_DEF(wlan_diag_event,
777*5113495bSYour Name struct host_event_wlan_log_complete);
778*5113495bSYour Name
779*5113495bSYour Name wlan_diag_event.is_fatal = is_fatal;
780*5113495bSYour Name wlan_diag_event.indicator = indicator;
781*5113495bSYour Name wlan_diag_event.reason_code = reason_code;
782*5113495bSYour Name wlan_diag_event.reserved = ring_id;
783*5113495bSYour Name
784*5113495bSYour Name WLAN_HOST_DIAG_EVENT_REPORT(&wlan_diag_event, EVENT_WLAN_LOG_COMPLETE);
785*5113495bSYour Name }
786*5113495bSYour Name #endif
787*5113495bSYour Name
788*5113495bSYour Name #ifdef FEATURE_WLAN_DIAG_SUPPORT
789*5113495bSYour Name /**
790*5113495bSYour Name * send_flush_completion_to_user() - Indicate flush completion to the user
791*5113495bSYour Name * @ring_id: Ring id of logging entities
792*5113495bSYour Name *
793*5113495bSYour Name * This function is used to send the flush completion message to user space
794*5113495bSYour Name *
795*5113495bSYour Name * Return: None
796*5113495bSYour Name */
send_flush_completion_to_user(uint8_t ring_id)797*5113495bSYour Name static void send_flush_completion_to_user(uint8_t ring_id)
798*5113495bSYour Name {
799*5113495bSYour Name uint32_t is_fatal, indicator, reason_code;
800*5113495bSYour Name bool recovery_needed;
801*5113495bSYour Name
802*5113495bSYour Name cds_get_and_reset_log_completion(&is_fatal,
803*5113495bSYour Name &indicator, &reason_code, &recovery_needed);
804*5113495bSYour Name
805*5113495bSYour Name /* Error on purpose, so that it will get logged in the kmsg */
806*5113495bSYour Name LOGGING_TRACE(QDF_TRACE_LEVEL_DEBUG,
807*5113495bSYour Name "%s: Sending flush done to userspace reason code %d",
808*5113495bSYour Name __func__, reason_code);
809*5113495bSYour Name
810*5113495bSYour Name wlan_report_log_completion(is_fatal, indicator, reason_code, ring_id);
811*5113495bSYour Name
812*5113495bSYour Name if (recovery_needed)
813*5113495bSYour Name cds_trigger_recovery(QDF_FLUSH_LOGS);
814*5113495bSYour Name }
815*5113495bSYour Name #endif
816*5113495bSYour Name
wlan_logging_set_flush_log_completion(void)817*5113495bSYour Name static void wlan_logging_set_flush_log_completion(void)
818*5113495bSYour Name {
819*5113495bSYour Name qdf_event_set(&gwlan_logging.flush_log_completion);
820*5113495bSYour Name }
821*5113495bSYour Name
wlan_logging_wait_for_flush_log_completion(void)822*5113495bSYour Name QDF_STATUS wlan_logging_wait_for_flush_log_completion(void)
823*5113495bSYour Name {
824*5113495bSYour Name qdf_event_reset(&gwlan_logging.flush_log_completion);
825*5113495bSYour Name
826*5113495bSYour Name return qdf_wait_for_event_completion(
827*5113495bSYour Name &gwlan_logging.flush_log_completion,
828*5113495bSYour Name FLUSH_LOG_COMPLETION_TIMEOUT);
829*5113495bSYour Name }
830*5113495bSYour Name
setup_flush_timer(void)831*5113495bSYour Name static void setup_flush_timer(void)
832*5113495bSYour Name {
833*5113495bSYour Name qdf_spin_lock(&gwlan_logging.flush_timer_lock);
834*5113495bSYour Name if (!gwlan_logging.is_flush_timer_initialized ||
835*5113495bSYour Name (gwlan_logging.flush_timer_period == 0)) {
836*5113495bSYour Name qdf_spin_unlock(&gwlan_logging.flush_timer_lock);
837*5113495bSYour Name return;
838*5113495bSYour Name }
839*5113495bSYour Name qdf_timer_mod(&gwlan_logging.flush_timer,
840*5113495bSYour Name gwlan_logging.flush_timer_period);
841*5113495bSYour Name qdf_spin_unlock(&gwlan_logging.flush_timer_lock);
842*5113495bSYour Name }
843*5113495bSYour Name
844*5113495bSYour Name #ifdef WLAN_FEATURE_CONNECTIVITY_LOGGING
845*5113495bSYour Name static QDF_STATUS
wlan_logging_send_connectivity_event(void)846*5113495bSYour Name wlan_logging_send_connectivity_event(void)
847*5113495bSYour Name {
848*5113495bSYour Name return wlan_connectivity_log_dequeue();
849*5113495bSYour Name }
850*5113495bSYour Name #else
851*5113495bSYour Name static inline QDF_STATUS
wlan_logging_send_connectivity_event(void)852*5113495bSYour Name wlan_logging_send_connectivity_event(void)
853*5113495bSYour Name {
854*5113495bSYour Name return QDF_STATUS_E_NOSUPPORT;
855*5113495bSYour Name }
856*5113495bSYour Name #endif
857*5113495bSYour Name
858*5113495bSYour Name #ifdef WLAN_CHIPSET_STATS
wlan_logging_cstats_send_host_buf_to_usr(void)859*5113495bSYour Name static int wlan_logging_cstats_send_host_buf_to_usr(void)
860*5113495bSYour Name {
861*5113495bSYour Name return ucfg_cp_stats_cstats_send_buffer_to_user(CSTATS_HOST_TYPE);
862*5113495bSYour Name }
863*5113495bSYour Name
wlan_logging_cstats_send_fw_buf_to_usr(void)864*5113495bSYour Name static int wlan_logging_cstats_send_fw_buf_to_usr(void)
865*5113495bSYour Name {
866*5113495bSYour Name return ucfg_cp_stats_cstats_send_buffer_to_user(CSTATS_FW_TYPE);
867*5113495bSYour Name }
868*5113495bSYour Name #else
wlan_logging_cstats_send_host_buf_to_usr(void)869*5113495bSYour Name static int wlan_logging_cstats_send_host_buf_to_usr(void)
870*5113495bSYour Name {
871*5113495bSYour Name return 0;
872*5113495bSYour Name }
873*5113495bSYour Name
wlan_logging_cstats_send_fw_buf_to_usr(void)874*5113495bSYour Name static int wlan_logging_cstats_send_fw_buf_to_usr(void)
875*5113495bSYour Name {
876*5113495bSYour Name return 0;
877*5113495bSYour Name }
878*5113495bSYour Name #endif
879*5113495bSYour Name
880*5113495bSYour Name /**
881*5113495bSYour Name * wlan_logging_thread() - The WLAN Logger thread
882*5113495bSYour Name * @Arg - pointer to the HDD context
883*5113495bSYour Name *
884*5113495bSYour Name * This thread logs log message to App registered for the logs.
885*5113495bSYour Name */
wlan_logging_thread(void * Arg)886*5113495bSYour Name static int wlan_logging_thread(void *Arg)
887*5113495bSYour Name {
888*5113495bSYour Name int ret_wait_status = 0;
889*5113495bSYour Name int ret = 0;
890*5113495bSYour Name unsigned long flags;
891*5113495bSYour Name
892*5113495bSYour Name gwlan_logging.start_ts = qdf_get_log_timestamp();
893*5113495bSYour Name
894*5113495bSYour Name while (!gwlan_logging.exit) {
895*5113495bSYour Name setup_flush_timer();
896*5113495bSYour Name ret_wait_status =
897*5113495bSYour Name wait_event_interruptible(gwlan_logging.wait_queue,
898*5113495bSYour Name (!list_empty
899*5113495bSYour Name (&gwlan_logging.filled_list)
900*5113495bSYour Name || test_bit(
901*5113495bSYour Name HOST_LOG_DRIVER_MSG,
902*5113495bSYour Name &gwlan_logging.eventFlag)
903*5113495bSYour Name || test_bit(
904*5113495bSYour Name HOST_LOG_PER_PKT_STATS,
905*5113495bSYour Name &gwlan_logging.eventFlag)
906*5113495bSYour Name || test_bit(
907*5113495bSYour Name HOST_LOG_FW_FLUSH_COMPLETE,
908*5113495bSYour Name &gwlan_logging.eventFlag)
909*5113495bSYour Name || test_bit(
910*5113495bSYour Name HOST_LOG_DRIVER_CONNECTIVITY_MSG,
911*5113495bSYour Name &gwlan_logging.eventFlag)
912*5113495bSYour Name || gwlan_logging.exit));
913*5113495bSYour Name
914*5113495bSYour Name if (ret_wait_status == -ERESTARTSYS) {
915*5113495bSYour Name qdf_err("wait_event_interruptible returned -ERESTARTSYS");
916*5113495bSYour Name break;
917*5113495bSYour Name }
918*5113495bSYour Name
919*5113495bSYour Name if (gwlan_logging.exit)
920*5113495bSYour Name break;
921*5113495bSYour Name
922*5113495bSYour Name
923*5113495bSYour Name if (test_and_clear_bit(HOST_LOG_DRIVER_MSG,
924*5113495bSYour Name &gwlan_logging.eventFlag)) {
925*5113495bSYour Name ret = send_filled_buffers_to_user();
926*5113495bSYour Name if (-ENOMEM == ret)
927*5113495bSYour Name msleep(200);
928*5113495bSYour Name #ifdef FEATURE_WLAN_DIAG_SUPPORT
929*5113495bSYour Name if (WLAN_LOG_INDICATOR_HOST_ONLY ==
930*5113495bSYour Name cds_get_log_indicator()) {
931*5113495bSYour Name send_flush_completion_to_user(
932*5113495bSYour Name RING_ID_DRIVER_DEBUG);
933*5113495bSYour Name }
934*5113495bSYour Name #endif
935*5113495bSYour Name }
936*5113495bSYour Name
937*5113495bSYour Name if (test_and_clear_bit(HOST_LOG_PER_PKT_STATS,
938*5113495bSYour Name &gwlan_logging.eventFlag)) {
939*5113495bSYour Name ret = pktlog_send_per_pkt_stats_to_user();
940*5113495bSYour Name if (-ENOMEM == ret)
941*5113495bSYour Name msleep(200);
942*5113495bSYour Name }
943*5113495bSYour Name
944*5113495bSYour Name if (test_bit(HOST_LOG_CHIPSET_STATS,
945*5113495bSYour Name &gwlan_logging.eventFlag) &&
946*5113495bSYour Name gwlan_logging.is_flush_complete) {
947*5113495bSYour Name test_and_clear_bit(HOST_LOG_CHIPSET_STATS,
948*5113495bSYour Name &gwlan_logging.eventFlag);
949*5113495bSYour Name ret = wlan_logging_cstats_send_host_buf_to_usr();
950*5113495bSYour Name if (-ENOMEM == ret) {
951*5113495bSYour Name QDF_TRACE_ERROR(QDF_MODULE_ID_QDF,
952*5113495bSYour Name "No memory to flush stats");
953*5113495bSYour Name msleep(200);
954*5113495bSYour Name }
955*5113495bSYour Name }
956*5113495bSYour Name
957*5113495bSYour Name if (test_bit(FW_LOG_CHIPSET_STATS,
958*5113495bSYour Name &gwlan_logging.eventFlag) &&
959*5113495bSYour Name gwlan_logging.is_flush_complete) {
960*5113495bSYour Name test_and_clear_bit(FW_LOG_CHIPSET_STATS,
961*5113495bSYour Name &gwlan_logging.eventFlag);
962*5113495bSYour Name ret = wlan_logging_cstats_send_fw_buf_to_usr();
963*5113495bSYour Name if (-ENOMEM == ret) {
964*5113495bSYour Name QDF_TRACE_ERROR(QDF_MODULE_ID_QDF,
965*5113495bSYour Name "No memory to flush stats");
966*5113495bSYour Name msleep(200);
967*5113495bSYour Name }
968*5113495bSYour Name }
969*5113495bSYour Name
970*5113495bSYour Name if (test_and_clear_bit(HOST_LOG_FW_FLUSH_COMPLETE,
971*5113495bSYour Name &gwlan_logging.eventFlag)) {
972*5113495bSYour Name /* Flush bit could have been set while we were mid
973*5113495bSYour Name * way in the logging thread. So, need to check other
974*5113495bSYour Name * buffers like log messages, per packet stats again
975*5113495bSYour Name * to flush any residual data in them
976*5113495bSYour Name */
977*5113495bSYour Name if (gwlan_logging.is_flush_complete == true) {
978*5113495bSYour Name gwlan_logging.is_flush_complete = false;
979*5113495bSYour Name #ifdef FEATURE_WLAN_DIAG_SUPPORT
980*5113495bSYour Name send_flush_completion_to_user(
981*5113495bSYour Name RING_ID_DRIVER_DEBUG);
982*5113495bSYour Name #endif
983*5113495bSYour Name wlan_logging_set_flush_log_completion();
984*5113495bSYour Name } else {
985*5113495bSYour Name gwlan_logging.is_flush_complete = true;
986*5113495bSYour Name /* Flush all current host logs*/
987*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock,
988*5113495bSYour Name flags);
989*5113495bSYour Name wlan_queue_logmsg_for_app();
990*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock,
991*5113495bSYour Name flags);
992*5113495bSYour Name set_bit(HOST_LOG_DRIVER_MSG,
993*5113495bSYour Name &gwlan_logging.eventFlag);
994*5113495bSYour Name set_bit(HOST_LOG_PER_PKT_STATS,
995*5113495bSYour Name &gwlan_logging.eventFlag);
996*5113495bSYour Name set_bit(HOST_LOG_FW_FLUSH_COMPLETE,
997*5113495bSYour Name &gwlan_logging.eventFlag);
998*5113495bSYour Name wake_up_interruptible(
999*5113495bSYour Name &gwlan_logging.wait_queue);
1000*5113495bSYour Name }
1001*5113495bSYour Name }
1002*5113495bSYour Name
1003*5113495bSYour Name /* Dequeue the connectivity_log */
1004*5113495bSYour Name wlan_logging_send_connectivity_event();
1005*5113495bSYour Name clear_bit(HOST_LOG_DRIVER_CONNECTIVITY_MSG,
1006*5113495bSYour Name &gwlan_logging.eventFlag);
1007*5113495bSYour Name }
1008*5113495bSYour Name
1009*5113495bSYour Name gwlan_logging.exit_ts = qdf_get_log_timestamp();
1010*5113495bSYour Name kthread_complete_and_exit(&gwlan_logging.shutdown_comp, 0);
1011*5113495bSYour Name
1012*5113495bSYour Name return 0;
1013*5113495bSYour Name }
1014*5113495bSYour Name
wlan_logging_set_active(bool active)1015*5113495bSYour Name void wlan_logging_set_active(bool active)
1016*5113495bSYour Name {
1017*5113495bSYour Name gwlan_logging.is_active = active;
1018*5113495bSYour Name }
1019*5113495bSYour Name
wlan_set_console_log_levels(uint32_t console_log_levels)1020*5113495bSYour Name void wlan_set_console_log_levels(uint32_t console_log_levels)
1021*5113495bSYour Name {
1022*5113495bSYour Name gwlan_logging.console_log_levels = console_log_levels;
1023*5113495bSYour Name }
1024*5113495bSYour Name
1025*5113495bSYour Name qdf_export_symbol(wlan_set_console_log_levels);
1026*5113495bSYour Name
flush_log_buffers_timer(void * dummy)1027*5113495bSYour Name static void flush_log_buffers_timer(void *dummy)
1028*5113495bSYour Name {
1029*5113495bSYour Name wlan_flush_host_logs_for_fatal();
1030*5113495bSYour Name }
1031*5113495bSYour Name
wlan_logging_set_flush_timer(uint32_t milliseconds)1032*5113495bSYour Name int wlan_logging_set_flush_timer(uint32_t milliseconds)
1033*5113495bSYour Name {
1034*5113495bSYour Name if (milliseconds > MAX_FLUSH_TIMER_PERIOD_VALUE) {
1035*5113495bSYour Name QDF_TRACE_ERROR(QDF_MODULE_ID_QDF,
1036*5113495bSYour Name "ERROR! value should be (0 - %d)\n",
1037*5113495bSYour Name MAX_FLUSH_TIMER_PERIOD_VALUE);
1038*5113495bSYour Name return -EINVAL;
1039*5113495bSYour Name }
1040*5113495bSYour Name if (!gwlan_logging.is_active) {
1041*5113495bSYour Name QDF_TRACE_ERROR(QDF_MODULE_ID_QDF,
1042*5113495bSYour Name "WLAN-Logging not active");
1043*5113495bSYour Name return -EINVAL;
1044*5113495bSYour Name }
1045*5113495bSYour Name qdf_spin_lock(&gwlan_logging.flush_timer_lock);
1046*5113495bSYour Name if (!gwlan_logging.is_flush_timer_initialized) {
1047*5113495bSYour Name qdf_spin_unlock(&gwlan_logging.flush_timer_lock);
1048*5113495bSYour Name return -EINVAL;
1049*5113495bSYour Name }
1050*5113495bSYour Name gwlan_logging.flush_timer_period = milliseconds;
1051*5113495bSYour Name if (milliseconds) {
1052*5113495bSYour Name qdf_timer_mod(&gwlan_logging.flush_timer,
1053*5113495bSYour Name gwlan_logging.flush_timer_period);
1054*5113495bSYour Name }
1055*5113495bSYour Name qdf_spin_unlock(&gwlan_logging.flush_timer_lock);
1056*5113495bSYour Name return 0;
1057*5113495bSYour Name }
1058*5113495bSYour Name
panic_wifilog_ratelimit_print(void)1059*5113495bSYour Name static int panic_wifilog_ratelimit_print(void)
1060*5113495bSYour Name {
1061*5113495bSYour Name return __ratelimit(&panic_wifilog_ratelimit);
1062*5113495bSYour Name }
1063*5113495bSYour Name
1064*5113495bSYour Name /**
1065*5113495bSYour Name * wlan_logging_dump_last_logs() - Panic notifier callback's helper function
1066*5113495bSYour Name *
1067*5113495bSYour Name * This function prints buffered logs one line at a time.
1068*5113495bSYour Name */
wlan_logging_dump_last_logs(void)1069*5113495bSYour Name static void wlan_logging_dump_last_logs(void)
1070*5113495bSYour Name {
1071*5113495bSYour Name char *log;
1072*5113495bSYour Name struct log_msg *plog_msg;
1073*5113495bSYour Name char textbuf[MAX_LOG_LINE];
1074*5113495bSYour Name unsigned int filled_length;
1075*5113495bSYour Name unsigned int text_len;
1076*5113495bSYour Name unsigned long flags;
1077*5113495bSYour Name
1078*5113495bSYour Name /* Iterate over panic list */
1079*5113495bSYour Name pr_err("\n");
1080*5113495bSYour Name while (!list_empty(&gwlan_logging.panic_list)) {
1081*5113495bSYour Name plog_msg = (struct log_msg *)
1082*5113495bSYour Name (gwlan_logging.panic_list.next);
1083*5113495bSYour Name list_del_init(gwlan_logging.panic_list.next);
1084*5113495bSYour Name log = &plog_msg->logbuf[sizeof(tAniHdr)];
1085*5113495bSYour Name filled_length = plog_msg->filled_length;
1086*5113495bSYour Name while (filled_length) {
1087*5113495bSYour Name text_len = qdf_str_copy_all_before_char(log, filled_length,
1088*5113495bSYour Name textbuf,
1089*5113495bSYour Name sizeof(textbuf) - 1,
1090*5113495bSYour Name '\n');
1091*5113495bSYour Name textbuf[text_len] = '\0';
1092*5113495bSYour Name if (panic_wifilog_ratelimit_print())
1093*5113495bSYour Name pr_err("%s\n", textbuf);
1094*5113495bSYour Name
1095*5113495bSYour Name if (log[text_len] == '\n')
1096*5113495bSYour Name text_len += 1; /* skip newline */
1097*5113495bSYour Name log += text_len;
1098*5113495bSYour Name filled_length -= text_len;
1099*5113495bSYour Name }
1100*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
1101*5113495bSYour Name list_add_tail(&plog_msg->node,
1102*5113495bSYour Name &gwlan_logging.free_list);
1103*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
1104*5113495bSYour Name }
1105*5113495bSYour Name }
1106*5113495bSYour Name
1107*5113495bSYour Name /**
1108*5113495bSYour Name * wlan_logging_panic_handler() - Panic notifier callback
1109*5113495bSYour Name *
1110*5113495bSYour Name * This function extracts log buffers in filled list and
1111*5113495bSYour Name * current node.Sends them to helper function for printing.
1112*5113495bSYour Name */
wlan_logging_panic_handler(struct notifier_block * this,unsigned long event,void * ptr)1113*5113495bSYour Name static int wlan_logging_panic_handler(struct notifier_block *this,
1114*5113495bSYour Name unsigned long event, void *ptr)
1115*5113495bSYour Name {
1116*5113495bSYour Name char *log;
1117*5113495bSYour Name struct log_msg *plog_msg;
1118*5113495bSYour Name unsigned long flags;
1119*5113495bSYour Name
1120*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
1121*5113495bSYour Name /* Iterate over nodes queued for app */
1122*5113495bSYour Name while (!list_empty(&gwlan_logging.filled_list)) {
1123*5113495bSYour Name plog_msg = (struct log_msg *)
1124*5113495bSYour Name (gwlan_logging.filled_list.next);
1125*5113495bSYour Name list_del_init(gwlan_logging.filled_list.next);
1126*5113495bSYour Name list_add_tail(&plog_msg->node,
1127*5113495bSYour Name &gwlan_logging.panic_list);
1128*5113495bSYour Name }
1129*5113495bSYour Name /* Check current node */
1130*5113495bSYour Name if (gwlan_logging.pcur_node &&
1131*5113495bSYour Name gwlan_logging.pcur_node->filled_length) {
1132*5113495bSYour Name plog_msg = gwlan_logging.pcur_node;
1133*5113495bSYour Name log = &plog_msg->logbuf[sizeof(tAniHdr)];
1134*5113495bSYour Name log[plog_msg->filled_length] = '\0';
1135*5113495bSYour Name list_add_tail(&gwlan_logging.pcur_node->node,
1136*5113495bSYour Name &gwlan_logging.panic_list);
1137*5113495bSYour Name if (!list_empty(&gwlan_logging.free_list)) {
1138*5113495bSYour Name gwlan_logging.pcur_node =
1139*5113495bSYour Name (struct log_msg *)(gwlan_logging.free_list.next);
1140*5113495bSYour Name list_del_init(gwlan_logging.free_list.next);
1141*5113495bSYour Name gwlan_logging.pcur_node->filled_length = 0;
1142*5113495bSYour Name } else
1143*5113495bSYour Name gwlan_logging.pcur_node = NULL;
1144*5113495bSYour Name }
1145*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
1146*5113495bSYour Name
1147*5113495bSYour Name wlan_logging_dump_last_logs();
1148*5113495bSYour Name
1149*5113495bSYour Name return NOTIFY_DONE;
1150*5113495bSYour Name }
1151*5113495bSYour Name
1152*5113495bSYour Name static struct notifier_block panic_nb = {
1153*5113495bSYour Name .notifier_call = wlan_logging_panic_handler,
1154*5113495bSYour Name };
1155*5113495bSYour Name
wlan_logging_notifier_init(bool dump_at_kernel_enable)1156*5113495bSYour Name int wlan_logging_notifier_init(bool dump_at_kernel_enable)
1157*5113495bSYour Name {
1158*5113495bSYour Name int ret;
1159*5113495bSYour Name
1160*5113495bSYour Name if (gwlan_logging.is_active &&
1161*5113495bSYour Name !dump_at_kernel_enable) {
1162*5113495bSYour Name ret = atomic_notifier_chain_register(&panic_notifier_list,
1163*5113495bSYour Name &panic_nb);
1164*5113495bSYour Name if (ret) {
1165*5113495bSYour Name QDF_TRACE_ERROR(QDF_MODULE_ID_QDF,
1166*5113495bSYour Name "Failed to register panic notifier");
1167*5113495bSYour Name return -EINVAL;
1168*5113495bSYour Name }
1169*5113495bSYour Name }
1170*5113495bSYour Name
1171*5113495bSYour Name return 0;
1172*5113495bSYour Name }
1173*5113495bSYour Name
wlan_logging_notifier_deinit(bool dump_at_kernel_enable)1174*5113495bSYour Name int wlan_logging_notifier_deinit(bool dump_at_kernel_enable)
1175*5113495bSYour Name {
1176*5113495bSYour Name if (gwlan_logging.is_active &&
1177*5113495bSYour Name !dump_at_kernel_enable) {
1178*5113495bSYour Name atomic_notifier_chain_unregister(&panic_notifier_list,
1179*5113495bSYour Name &panic_nb);
1180*5113495bSYour Name }
1181*5113495bSYour Name
1182*5113495bSYour Name return 0;
1183*5113495bSYour Name }
1184*5113495bSYour Name
flush_timer_init(void)1185*5113495bSYour Name static void flush_timer_init(void)
1186*5113495bSYour Name {
1187*5113495bSYour Name qdf_spinlock_create(&gwlan_logging.flush_timer_lock);
1188*5113495bSYour Name qdf_timer_init(NULL, &gwlan_logging.flush_timer,
1189*5113495bSYour Name flush_log_buffers_timer, NULL,
1190*5113495bSYour Name QDF_TIMER_TYPE_SW);
1191*5113495bSYour Name gwlan_logging.is_flush_timer_initialized = true;
1192*5113495bSYour Name gwlan_logging.flush_timer_period = 0;
1193*5113495bSYour Name }
1194*5113495bSYour Name
flush_timer_deinit(void)1195*5113495bSYour Name static void flush_timer_deinit(void)
1196*5113495bSYour Name {
1197*5113495bSYour Name gwlan_logging.is_flush_timer_initialized = false;
1198*5113495bSYour Name qdf_spin_lock(&gwlan_logging.flush_timer_lock);
1199*5113495bSYour Name qdf_timer_stop(&gwlan_logging.flush_timer);
1200*5113495bSYour Name qdf_timer_free(&gwlan_logging.flush_timer);
1201*5113495bSYour Name qdf_spin_unlock(&gwlan_logging.flush_timer_lock);
1202*5113495bSYour Name qdf_spinlock_destroy(&gwlan_logging.flush_timer_lock);
1203*5113495bSYour Name }
1204*5113495bSYour Name
wlan_logging_sock_init_svc(void)1205*5113495bSYour Name int wlan_logging_sock_init_svc(void)
1206*5113495bSYour Name {
1207*5113495bSYour Name int i = 0, j, pkt_stats_size;
1208*5113495bSYour Name unsigned long irq_flag;
1209*5113495bSYour Name QDF_STATUS status;
1210*5113495bSYour Name
1211*5113495bSYour Name spin_lock_init(&gwlan_logging.spin_lock);
1212*5113495bSYour Name spin_lock_init(&gwlan_logging.pkt_stats_lock);
1213*5113495bSYour Name
1214*5113495bSYour Name gwlan_logging.console_log_levels = 0;
1215*5113495bSYour Name gwlan_logging.num_buf = MAX_LOGMSG_COUNT;
1216*5113495bSYour Name gwlan_logging.buffer_length = MAX_LOGMSG_LENGTH;
1217*5113495bSYour Name
1218*5113495bSYour Name if (allocate_log_msg_buffer() != QDF_STATUS_SUCCESS) {
1219*5113495bSYour Name qdf_err("Could not allocate memory for log_msg");
1220*5113495bSYour Name return -ENOMEM;
1221*5113495bSYour Name }
1222*5113495bSYour Name
1223*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag);
1224*5113495bSYour Name INIT_LIST_HEAD(&gwlan_logging.free_list);
1225*5113495bSYour Name INIT_LIST_HEAD(&gwlan_logging.filled_list);
1226*5113495bSYour Name INIT_LIST_HEAD(&gwlan_logging.panic_list);
1227*5113495bSYour Name
1228*5113495bSYour Name for (i = 0; i < gwlan_logging.num_buf; i++) {
1229*5113495bSYour Name list_add(&gplog_msg[i].node, &gwlan_logging.free_list);
1230*5113495bSYour Name gplog_msg[i].index = i;
1231*5113495bSYour Name }
1232*5113495bSYour Name gwlan_logging.pcur_node = (struct log_msg *)
1233*5113495bSYour Name (gwlan_logging.free_list.next);
1234*5113495bSYour Name list_del_init(gwlan_logging.free_list.next);
1235*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag);
1236*5113495bSYour Name
1237*5113495bSYour Name flush_timer_init();
1238*5113495bSYour Name
1239*5113495bSYour Name /* Initialize the pktStats data structure here */
1240*5113495bSYour Name pkt_stats_size = sizeof(struct pkt_stats_msg);
1241*5113495bSYour Name gpkt_stats_buffers = qdf_mem_valloc(MAX_PKTSTATS_BUFF * pkt_stats_size);
1242*5113495bSYour Name if (!gpkt_stats_buffers) {
1243*5113495bSYour Name qdf_err("Could not allocate memory for Pkt stats");
1244*5113495bSYour Name goto err1;
1245*5113495bSYour Name }
1246*5113495bSYour Name qdf_mem_zero(gpkt_stats_buffers,
1247*5113495bSYour Name MAX_PKTSTATS_BUFF * pkt_stats_size);
1248*5113495bSYour Name
1249*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
1250*5113495bSYour Name gwlan_logging.pkt_stats_msg_idx = 0;
1251*5113495bSYour Name INIT_LIST_HEAD(&gwlan_logging.pkt_stat_free_list);
1252*5113495bSYour Name INIT_LIST_HEAD(&gwlan_logging.pkt_stat_filled_list);
1253*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
1254*5113495bSYour Name
1255*5113495bSYour Name
1256*5113495bSYour Name for (i = 0; i < MAX_PKTSTATS_BUFF; i++) {
1257*5113495bSYour Name gpkt_stats_buffers[i].skb = dev_alloc_skb(MAX_PKTSTATS_LENGTH);
1258*5113495bSYour Name if (!gpkt_stats_buffers[i].skb) {
1259*5113495bSYour Name qdf_err("Memory alloc failed for skb");
1260*5113495bSYour Name /* free previously allocated skb and return */
1261*5113495bSYour Name for (j = 0; j < i ; j++)
1262*5113495bSYour Name dev_kfree_skb(gpkt_stats_buffers[j].skb);
1263*5113495bSYour Name goto err2;
1264*5113495bSYour Name }
1265*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
1266*5113495bSYour Name list_add(&gpkt_stats_buffers[i].node,
1267*5113495bSYour Name &gwlan_logging.pkt_stat_free_list);
1268*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
1269*5113495bSYour Name }
1270*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
1271*5113495bSYour Name gwlan_logging.pkt_stats_pcur_node = (struct pkt_stats_msg *)
1272*5113495bSYour Name (gwlan_logging.pkt_stat_free_list.next);
1273*5113495bSYour Name list_del_init(gwlan_logging.pkt_stat_free_list.next);
1274*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
1275*5113495bSYour Name /* Pkt Stats initialization done */
1276*5113495bSYour Name
1277*5113495bSYour Name init_waitqueue_head(&gwlan_logging.wait_queue);
1278*5113495bSYour Name gwlan_logging.exit = false;
1279*5113495bSYour Name clear_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
1280*5113495bSYour Name clear_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
1281*5113495bSYour Name clear_bit(HOST_LOG_FW_FLUSH_COMPLETE, &gwlan_logging.eventFlag);
1282*5113495bSYour Name clear_bit(HOST_LOG_DRIVER_CONNECTIVITY_MSG, &gwlan_logging.eventFlag);
1283*5113495bSYour Name clear_bit(HOST_LOG_CHIPSET_STATS, &gwlan_logging.eventFlag);
1284*5113495bSYour Name clear_bit(FW_LOG_CHIPSET_STATS, &gwlan_logging.eventFlag);
1285*5113495bSYour Name
1286*5113495bSYour Name init_completion(&gwlan_logging.shutdown_comp);
1287*5113495bSYour Name gwlan_logging.thread = kthread_create(wlan_logging_thread, NULL,
1288*5113495bSYour Name "wlan_logging_thread");
1289*5113495bSYour Name if (IS_ERR(gwlan_logging.thread)) {
1290*5113495bSYour Name qdf_err("Could not Create LogMsg Thread Controller");
1291*5113495bSYour Name goto err3;
1292*5113495bSYour Name }
1293*5113495bSYour Name wake_up_process(gwlan_logging.thread);
1294*5113495bSYour Name gwlan_logging.wakup_ts = qdf_get_log_timestamp();
1295*5113495bSYour Name
1296*5113495bSYour Name gwlan_logging.is_active = true;
1297*5113495bSYour Name gwlan_logging.is_flush_complete = false;
1298*5113495bSYour Name
1299*5113495bSYour Name status = qdf_event_create(&gwlan_logging.flush_log_completion);
1300*5113495bSYour Name if (!QDF_IS_STATUS_SUCCESS(status)) {
1301*5113495bSYour Name qdf_err("Flush log completion event init failed");
1302*5113495bSYour Name goto err3;
1303*5113495bSYour Name }
1304*5113495bSYour Name
1305*5113495bSYour Name return 0;
1306*5113495bSYour Name
1307*5113495bSYour Name err3:
1308*5113495bSYour Name for (i = 0; i < MAX_PKTSTATS_BUFF; i++) {
1309*5113495bSYour Name if (gpkt_stats_buffers[i].skb)
1310*5113495bSYour Name dev_kfree_skb(gpkt_stats_buffers[i].skb);
1311*5113495bSYour Name }
1312*5113495bSYour Name err2:
1313*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
1314*5113495bSYour Name gwlan_logging.pkt_stats_pcur_node = NULL;
1315*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
1316*5113495bSYour Name qdf_mem_vfree(gpkt_stats_buffers);
1317*5113495bSYour Name gpkt_stats_buffers = NULL;
1318*5113495bSYour Name err1:
1319*5113495bSYour Name flush_timer_deinit();
1320*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag);
1321*5113495bSYour Name gwlan_logging.pcur_node = NULL;
1322*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag);
1323*5113495bSYour Name free_log_msg_buffer();
1324*5113495bSYour Name
1325*5113495bSYour Name return -ENOMEM;
1326*5113495bSYour Name }
1327*5113495bSYour Name
wlan_logging_sock_deinit_svc(void)1328*5113495bSYour Name int wlan_logging_sock_deinit_svc(void)
1329*5113495bSYour Name {
1330*5113495bSYour Name unsigned long irq_flag;
1331*5113495bSYour Name int i;
1332*5113495bSYour Name
1333*5113495bSYour Name if (!gwlan_logging.pcur_node)
1334*5113495bSYour Name return 0;
1335*5113495bSYour Name
1336*5113495bSYour Name qdf_event_destroy(&gwlan_logging.flush_log_completion);
1337*5113495bSYour Name
1338*5113495bSYour Name gwlan_logging.reinitcompletion_ts = qdf_get_log_timestamp();
1339*5113495bSYour Name INIT_COMPLETION(gwlan_logging.shutdown_comp);
1340*5113495bSYour Name qdf_wmb();
1341*5113495bSYour Name gwlan_logging.exit = true;
1342*5113495bSYour Name qdf_wmb();
1343*5113495bSYour Name gwlan_logging.set_exit_ts = qdf_get_log_timestamp();
1344*5113495bSYour Name
1345*5113495bSYour Name gwlan_logging.is_active = false;
1346*5113495bSYour Name #if defined(FEATURE_FW_LOG_PARSING) || defined(FEATURE_WLAN_DIAG_SUPPORT)
1347*5113495bSYour Name cds_set_multicast_logging(0);
1348*5113495bSYour Name #endif
1349*5113495bSYour Name gwlan_logging.is_flush_complete = false;
1350*5113495bSYour Name clear_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
1351*5113495bSYour Name clear_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
1352*5113495bSYour Name clear_bit(HOST_LOG_FW_FLUSH_COMPLETE, &gwlan_logging.eventFlag);
1353*5113495bSYour Name clear_bit(HOST_LOG_DRIVER_CONNECTIVITY_MSG, &gwlan_logging.eventFlag);
1354*5113495bSYour Name clear_bit(HOST_LOG_CHIPSET_STATS, &gwlan_logging.eventFlag);
1355*5113495bSYour Name clear_bit(FW_LOG_CHIPSET_STATS, &gwlan_logging.eventFlag);
1356*5113495bSYour Name wake_up_interruptible(&gwlan_logging.wait_queue);
1357*5113495bSYour Name wait_for_completion(&gwlan_logging.shutdown_comp);
1358*5113495bSYour Name
1359*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, irq_flag);
1360*5113495bSYour Name gwlan_logging.pkt_stats_pcur_node = NULL;
1361*5113495bSYour Name gwlan_logging.pkt_stats_msg_idx = 0;
1362*5113495bSYour Name gwlan_logging.pkt_stat_drop_cnt = 0;
1363*5113495bSYour Name for (i = 0; i < MAX_PKTSTATS_BUFF; i++) {
1364*5113495bSYour Name if (gpkt_stats_buffers[i].skb)
1365*5113495bSYour Name dev_kfree_skb(gpkt_stats_buffers[i].skb);
1366*5113495bSYour Name }
1367*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, irq_flag);
1368*5113495bSYour Name qdf_mem_vfree(gpkt_stats_buffers);
1369*5113495bSYour Name gpkt_stats_buffers = NULL;
1370*5113495bSYour Name
1371*5113495bSYour Name /* Delete the Flush timer then mark pcur_node NULL */
1372*5113495bSYour Name flush_timer_deinit();
1373*5113495bSYour Name
1374*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, irq_flag);
1375*5113495bSYour Name gwlan_logging.pcur_node = NULL;
1376*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, irq_flag);
1377*5113495bSYour Name
1378*5113495bSYour Name free_log_msg_buffer();
1379*5113495bSYour Name
1380*5113495bSYour Name return 0;
1381*5113495bSYour Name }
1382*5113495bSYour Name
1383*5113495bSYour Name /**
1384*5113495bSYour Name * wlan_logging_set_per_pkt_stats() - This function triggers per packet logging
1385*5113495bSYour Name *
1386*5113495bSYour Name * This function is used to send signal to the logger thread for logging per
1387*5113495bSYour Name * packet stats
1388*5113495bSYour Name *
1389*5113495bSYour Name * Return: None
1390*5113495bSYour Name *
1391*5113495bSYour Name */
wlan_logging_set_per_pkt_stats(void)1392*5113495bSYour Name void wlan_logging_set_per_pkt_stats(void)
1393*5113495bSYour Name {
1394*5113495bSYour Name if (gwlan_logging.is_active == false)
1395*5113495bSYour Name return;
1396*5113495bSYour Name
1397*5113495bSYour Name set_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
1398*5113495bSYour Name wake_up_interruptible(&gwlan_logging.wait_queue);
1399*5113495bSYour Name }
1400*5113495bSYour Name
wlan_logging_set_connectivity_log(void)1401*5113495bSYour Name void wlan_logging_set_connectivity_log(void)
1402*5113495bSYour Name {
1403*5113495bSYour Name if (gwlan_logging.is_active == false)
1404*5113495bSYour Name return;
1405*5113495bSYour Name
1406*5113495bSYour Name set_bit(HOST_LOG_DRIVER_CONNECTIVITY_MSG, &gwlan_logging.eventFlag);
1407*5113495bSYour Name wake_up_interruptible(&gwlan_logging.wait_queue);
1408*5113495bSYour Name }
1409*5113495bSYour Name
1410*5113495bSYour Name /*
1411*5113495bSYour Name * wlan_logging_set_fw_flush_complete() - FW log flush completion
1412*5113495bSYour Name *
1413*5113495bSYour Name * This function is used to send signal to the logger thread to indicate
1414*5113495bSYour Name * that the flushing of FW logs is complete by the FW
1415*5113495bSYour Name *
1416*5113495bSYour Name * Return: None
1417*5113495bSYour Name *
1418*5113495bSYour Name */
wlan_logging_set_fw_flush_complete(void)1419*5113495bSYour Name void wlan_logging_set_fw_flush_complete(void)
1420*5113495bSYour Name {
1421*5113495bSYour Name if (!gwlan_logging.is_active)
1422*5113495bSYour Name return;
1423*5113495bSYour Name
1424*5113495bSYour Name set_bit(HOST_LOG_FW_FLUSH_COMPLETE, &gwlan_logging.eventFlag);
1425*5113495bSYour Name wake_up_interruptible(&gwlan_logging.wait_queue);
1426*5113495bSYour Name }
1427*5113495bSYour Name
1428*5113495bSYour Name /**
1429*5113495bSYour Name * wlan_flush_host_logs_for_fatal() - Flush host logs
1430*5113495bSYour Name *
1431*5113495bSYour Name * This function is used to send signal to the logger thread to
1432*5113495bSYour Name * Flush the host logs
1433*5113495bSYour Name *
1434*5113495bSYour Name * Return: None
1435*5113495bSYour Name */
wlan_flush_host_logs_for_fatal(void)1436*5113495bSYour Name void wlan_flush_host_logs_for_fatal(void)
1437*5113495bSYour Name {
1438*5113495bSYour Name unsigned long flags;
1439*5113495bSYour Name
1440*5113495bSYour Name if (gwlan_logging.flush_timer_period == 0)
1441*5113495bSYour Name qdf_info("Flush all host logs Setting HOST_LOG_POST_MAS");
1442*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.spin_lock, flags);
1443*5113495bSYour Name wlan_queue_logmsg_for_app();
1444*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.spin_lock, flags);
1445*5113495bSYour Name set_bit(HOST_LOG_DRIVER_MSG, &gwlan_logging.eventFlag);
1446*5113495bSYour Name wake_up_interruptible(&gwlan_logging.wait_queue);
1447*5113495bSYour Name }
1448*5113495bSYour Name
1449*5113495bSYour Name #ifdef CONNECTIVITY_PKTLOG
1450*5113495bSYour Name
1451*5113495bSYour Name static uint8_t gtx_count;
1452*5113495bSYour Name static uint8_t grx_count;
1453*5113495bSYour Name
1454*5113495bSYour Name /**
1455*5113495bSYour Name * wlan_get_pkt_stats_free_node() - Get the free node for pkt stats
1456*5113495bSYour Name *
1457*5113495bSYour Name * This function is used to get the free node for pkt stats from
1458*5113495bSYour Name * free list/filled list
1459*5113495bSYour Name *
1460*5113495bSYour Name * Return: int
1461*5113495bSYour Name *
1462*5113495bSYour Name */
wlan_get_pkt_stats_free_node(void)1463*5113495bSYour Name static int wlan_get_pkt_stats_free_node(void)
1464*5113495bSYour Name {
1465*5113495bSYour Name int ret = 0;
1466*5113495bSYour Name
1467*5113495bSYour Name list_add_tail(&gwlan_logging.pkt_stats_pcur_node->node,
1468*5113495bSYour Name &gwlan_logging.pkt_stat_filled_list);
1469*5113495bSYour Name
1470*5113495bSYour Name if (!list_empty(&gwlan_logging.pkt_stat_free_list)) {
1471*5113495bSYour Name /* Get buffer from free list */
1472*5113495bSYour Name gwlan_logging.pkt_stats_pcur_node =
1473*5113495bSYour Name (struct pkt_stats_msg *)(gwlan_logging.pkt_stat_free_list.next);
1474*5113495bSYour Name list_del_init(gwlan_logging.pkt_stat_free_list.next);
1475*5113495bSYour Name } else if (!list_empty(&gwlan_logging.pkt_stat_filled_list)) {
1476*5113495bSYour Name /* Get buffer from filled list. This condition will drop the
1477*5113495bSYour Name * packet from being indicated to app
1478*5113495bSYour Name */
1479*5113495bSYour Name gwlan_logging.pkt_stats_pcur_node =
1480*5113495bSYour Name (struct pkt_stats_msg *)
1481*5113495bSYour Name (gwlan_logging.pkt_stat_filled_list.next);
1482*5113495bSYour Name ++gwlan_logging.pkt_stat_drop_cnt;
1483*5113495bSYour Name /* print every 64th drop count */
1484*5113495bSYour Name if (
1485*5113495bSYour Name cds_is_multicast_logging() &&
1486*5113495bSYour Name (!(gwlan_logging.pkt_stat_drop_cnt % 0x40))) {
1487*5113495bSYour Name qdf_err("drop_count = %u",
1488*5113495bSYour Name gwlan_logging.pkt_stat_drop_cnt);
1489*5113495bSYour Name }
1490*5113495bSYour Name list_del_init(gwlan_logging.pkt_stat_filled_list.next);
1491*5113495bSYour Name ret = 1;
1492*5113495bSYour Name }
1493*5113495bSYour Name
1494*5113495bSYour Name /* Reset the skb values, essential if dequeued from filled list */
1495*5113495bSYour Name skb_trim(gwlan_logging.pkt_stats_pcur_node->skb, 0);
1496*5113495bSYour Name return ret;
1497*5113495bSYour Name }
1498*5113495bSYour Name
1499*5113495bSYour Name /**
1500*5113495bSYour Name * wlan_pkt_stats_to_logger_thread() - Add the pkt stats to SKB
1501*5113495bSYour Name * @pl_hdr: Pointer to pl_hdr
1502*5113495bSYour Name * @pkt_dump: Pointer to pkt_dump
1503*5113495bSYour Name * @data: Pointer to data
1504*5113495bSYour Name *
1505*5113495bSYour Name * This function adds the pktstats hdr and data to current
1506*5113495bSYour Name * skb node of free list.
1507*5113495bSYour Name *
1508*5113495bSYour Name * Return: None
1509*5113495bSYour Name */
wlan_pkt_stats_to_logger_thread(void * pl_hdr,void * pkt_dump,void * data)1510*5113495bSYour Name void wlan_pkt_stats_to_logger_thread(void *pl_hdr, void *pkt_dump, void *data)
1511*5113495bSYour Name {
1512*5113495bSYour Name struct ath_pktlog_hdr *pktlog_hdr;
1513*5113495bSYour Name struct packet_dump *pkt_stats_dump;
1514*5113495bSYour Name int total_stats_len = 0;
1515*5113495bSYour Name bool wake_up_thread = false;
1516*5113495bSYour Name unsigned long flags;
1517*5113495bSYour Name struct sk_buff *ptr;
1518*5113495bSYour Name int hdr_size;
1519*5113495bSYour Name
1520*5113495bSYour Name pktlog_hdr = (struct ath_pktlog_hdr *)pl_hdr;
1521*5113495bSYour Name
1522*5113495bSYour Name if (!pktlog_hdr) {
1523*5113495bSYour Name qdf_err("Invalid pkt_stats_header");
1524*5113495bSYour Name return;
1525*5113495bSYour Name }
1526*5113495bSYour Name
1527*5113495bSYour Name pkt_stats_dump = (struct packet_dump *)pkt_dump;
1528*5113495bSYour Name total_stats_len = sizeof(struct ath_pktlog_hdr) +
1529*5113495bSYour Name pktlog_hdr->size;
1530*5113495bSYour Name
1531*5113495bSYour Name spin_lock_irqsave(&gwlan_logging.pkt_stats_lock, flags);
1532*5113495bSYour Name
1533*5113495bSYour Name if (!gwlan_logging.pkt_stats_pcur_node) {
1534*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
1535*5113495bSYour Name return;
1536*5113495bSYour Name }
1537*5113495bSYour Name
1538*5113495bSYour Name /* Check if we can accommodate more log into current node/buffer */
1539*5113495bSYour Name hdr_size = sizeof(struct host_log_pktlog_info) +
1540*5113495bSYour Name sizeof(tAniNlHdr);
1541*5113495bSYour Name if ((total_stats_len + hdr_size) >=
1542*5113495bSYour Name skb_tailroom(gwlan_logging.pkt_stats_pcur_node->skb)) {
1543*5113495bSYour Name wake_up_thread = true;
1544*5113495bSYour Name wlan_get_pkt_stats_free_node();
1545*5113495bSYour Name }
1546*5113495bSYour Name
1547*5113495bSYour Name ptr = gwlan_logging.pkt_stats_pcur_node->skb;
1548*5113495bSYour Name qdf_mem_copy(skb_put(ptr,
1549*5113495bSYour Name sizeof(struct ath_pktlog_hdr)),
1550*5113495bSYour Name pktlog_hdr,
1551*5113495bSYour Name sizeof(struct ath_pktlog_hdr));
1552*5113495bSYour Name
1553*5113495bSYour Name if (pkt_stats_dump) {
1554*5113495bSYour Name qdf_mem_copy(skb_put(ptr,
1555*5113495bSYour Name sizeof(struct packet_dump)),
1556*5113495bSYour Name pkt_stats_dump,
1557*5113495bSYour Name sizeof(struct packet_dump));
1558*5113495bSYour Name pktlog_hdr->size -= sizeof(struct packet_dump);
1559*5113495bSYour Name }
1560*5113495bSYour Name
1561*5113495bSYour Name if (data)
1562*5113495bSYour Name qdf_mem_copy(skb_put(ptr,
1563*5113495bSYour Name pktlog_hdr->size),
1564*5113495bSYour Name data, pktlog_hdr->size);
1565*5113495bSYour Name
1566*5113495bSYour Name if (pkt_stats_dump && pkt_stats_dump->type == STOP_MONITOR) {
1567*5113495bSYour Name wake_up_thread = true;
1568*5113495bSYour Name wlan_get_pkt_stats_free_node();
1569*5113495bSYour Name }
1570*5113495bSYour Name
1571*5113495bSYour Name spin_unlock_irqrestore(&gwlan_logging.pkt_stats_lock, flags);
1572*5113495bSYour Name
1573*5113495bSYour Name /* Wakeup logger thread */
1574*5113495bSYour Name if (true == wake_up_thread) {
1575*5113495bSYour Name set_bit(HOST_LOG_PER_PKT_STATS, &gwlan_logging.eventFlag);
1576*5113495bSYour Name wake_up_interruptible(&gwlan_logging.wait_queue);
1577*5113495bSYour Name }
1578*5113495bSYour Name }
1579*5113495bSYour Name
1580*5113495bSYour Name /**
1581*5113495bSYour Name * qdf_hal_tx_status_map() - map Tx completion status with
1582*5113495bSYour Name * packet dump Tx status
1583*5113495bSYour Name * @status: Tx completion status
1584*5113495bSYour Name *
1585*5113495bSYour Name * Return: packet dump tx_status enum
1586*5113495bSYour Name */
1587*5113495bSYour Name static inline enum tx_pkt_fate
qdf_hal_tx_status_map(enum qdf_dp_tx_rx_status status)1588*5113495bSYour Name qdf_hal_tx_status_map(enum qdf_dp_tx_rx_status status)
1589*5113495bSYour Name {
1590*5113495bSYour Name switch (status) {
1591*5113495bSYour Name case QDF_TX_RX_STATUS_OK:
1592*5113495bSYour Name return TX_PKT_FATE_ACKED;
1593*5113495bSYour Name case QDF_TX_RX_STATUS_FW_DISCARD:
1594*5113495bSYour Name return TX_PKT_FATE_FW_DROP_OTHER;
1595*5113495bSYour Name case QDF_TX_RX_STATUS_NO_ACK:
1596*5113495bSYour Name return TX_PKT_FATE_SENT;
1597*5113495bSYour Name case QDF_TX_RX_STATUS_DROP:
1598*5113495bSYour Name return TX_PKT_FATE_DRV_DROP_OTHER;
1599*5113495bSYour Name case QDF_TX_RX_STATUS_DOWNLOAD_SUCC:
1600*5113495bSYour Name return TX_PKT_FATE_DRV_QUEUED;
1601*5113495bSYour Name default:
1602*5113495bSYour Name return TX_PKT_FATE_DRV_DROP_OTHER;
1603*5113495bSYour Name }
1604*5113495bSYour Name }
1605*5113495bSYour Name
1606*5113495bSYour Name /**
1607*5113495bSYour Name * qdf_hal_rx_status_map() - map Rx status with
1608*5113495bSYour Name * packet dump Rx status
1609*5113495bSYour Name * @status: Rx status
1610*5113495bSYour Name *
1611*5113495bSYour Name * Return: packet dump rx_status enum
1612*5113495bSYour Name */
1613*5113495bSYour Name static inline enum rx_pkt_fate
qdf_hal_rx_status_map(enum qdf_dp_tx_rx_status status)1614*5113495bSYour Name qdf_hal_rx_status_map(enum qdf_dp_tx_rx_status status)
1615*5113495bSYour Name {
1616*5113495bSYour Name switch (status) {
1617*5113495bSYour Name case QDF_TX_RX_STATUS_OK:
1618*5113495bSYour Name return RX_PKT_FATE_SUCCESS;
1619*5113495bSYour Name case QDF_TX_RX_STATUS_FW_DISCARD:
1620*5113495bSYour Name return RX_PKT_FATE_FW_DROP_OTHER;
1621*5113495bSYour Name case QDF_TX_RX_STATUS_DROP:
1622*5113495bSYour Name return RX_PKT_FATE_DRV_DROP_OTHER;
1623*5113495bSYour Name case QDF_TX_RX_STATUS_DOWNLOAD_SUCC:
1624*5113495bSYour Name return RX_PKT_FATE_DRV_QUEUED;
1625*5113495bSYour Name default:
1626*5113495bSYour Name return RX_PKT_FATE_DRV_DROP_OTHER;
1627*5113495bSYour Name }
1628*5113495bSYour Name }
1629*5113495bSYour Name
1630*5113495bSYour Name /**
1631*5113495bSYour Name * qdf_hal_pkt_type_map() - map qdf packet type with
1632*5113495bSYour Name * packet dump packet type
1633*5113495bSYour Name * @type: packet type
1634*5113495bSYour Name *
1635*5113495bSYour Name * Return: Packet dump packet type
1636*5113495bSYour Name */
1637*5113495bSYour Name static inline enum pkt_type
qdf_hal_pkt_type_map(enum qdf_pkt_type type)1638*5113495bSYour Name qdf_hal_pkt_type_map(enum qdf_pkt_type type)
1639*5113495bSYour Name {
1640*5113495bSYour Name switch (type) {
1641*5113495bSYour Name case QDF_TX_MGMT_PKT:
1642*5113495bSYour Name return TX_MGMT_PKT;
1643*5113495bSYour Name case QDF_TX_DATA_PKT:
1644*5113495bSYour Name return TX_DATA_PKT;
1645*5113495bSYour Name case QDF_RX_MGMT_PKT:
1646*5113495bSYour Name return RX_MGMT_PKT;
1647*5113495bSYour Name case QDF_RX_DATA_PKT:
1648*5113495bSYour Name return RX_DATA_PKT;
1649*5113495bSYour Name default:
1650*5113495bSYour Name return INVALID_PKT;
1651*5113495bSYour Name }
1652*5113495bSYour Name }
1653*5113495bSYour Name
1654*5113495bSYour Name /*
1655*5113495bSYour Name * send_packetdump() - send packet dump
1656*5113495bSYour Name * @soc: soc handle
1657*5113495bSYour Name * @vdev_id: ID of the virtual device handle
1658*5113495bSYour Name * @netbuf: netbuf
1659*5113495bSYour Name * @status: status of tx packet
1660*5113495bSYour Name * @type: type of packet
1661*5113495bSYour Name *
1662*5113495bSYour Name * This function is used to send packet dump to HAL layer
1663*5113495bSYour Name * using wlan_pkt_stats_to_logger_thread
1664*5113495bSYour Name *
1665*5113495bSYour Name * Return: None
1666*5113495bSYour Name *
1667*5113495bSYour Name */
send_packetdump(ol_txrx_soc_handle soc,uint8_t vdev_id,qdf_nbuf_t netbuf,uint8_t status,uint8_t type)1668*5113495bSYour Name static void send_packetdump(ol_txrx_soc_handle soc,
1669*5113495bSYour Name uint8_t vdev_id, qdf_nbuf_t netbuf,
1670*5113495bSYour Name uint8_t status, uint8_t type)
1671*5113495bSYour Name {
1672*5113495bSYour Name struct ath_pktlog_hdr pktlog_hdr = {0};
1673*5113495bSYour Name struct packet_dump pd_hdr = {0};
1674*5113495bSYour Name
1675*5113495bSYour Name if (!netbuf) {
1676*5113495bSYour Name qdf_err("Invalid netbuf");
1677*5113495bSYour Name return;
1678*5113495bSYour Name }
1679*5113495bSYour Name
1680*5113495bSYour Name /* Send packet dump only for STA interface */
1681*5113495bSYour Name if (wlan_op_mode_sta != cdp_get_opmode(soc, vdev_id))
1682*5113495bSYour Name return;
1683*5113495bSYour Name
1684*5113495bSYour Name pktlog_hdr.flags |= PKTLOG_HDR_SIZE_16;
1685*5113495bSYour Name
1686*5113495bSYour Name pktlog_hdr.log_type = PKTLOG_TYPE_PKT_DUMP;
1687*5113495bSYour Name pktlog_hdr.size = sizeof(pd_hdr) + netbuf->len;
1688*5113495bSYour Name
1689*5113495bSYour Name pd_hdr.status = status;
1690*5113495bSYour Name pd_hdr.type = type;
1691*5113495bSYour Name pd_hdr.driver_ts = qdf_get_monotonic_boottime();
1692*5113495bSYour Name
1693*5113495bSYour Name if ((type == TX_MGMT_PKT) || (type == TX_DATA_PKT))
1694*5113495bSYour Name gtx_count++;
1695*5113495bSYour Name else if ((type == RX_MGMT_PKT) || (type == RX_DATA_PKT))
1696*5113495bSYour Name grx_count++;
1697*5113495bSYour Name
1698*5113495bSYour Name wlan_pkt_stats_to_logger_thread(&pktlog_hdr, &pd_hdr, netbuf->data);
1699*5113495bSYour Name }
1700*5113495bSYour Name
1701*5113495bSYour Name
1702*5113495bSYour Name /*
1703*5113495bSYour Name * send_packetdump_monitor() - sends start/stop packet dump indication
1704*5113495bSYour Name * @type: type of packet
1705*5113495bSYour Name *
1706*5113495bSYour Name * This function is used to indicate HAL layer to start/stop monitoring
1707*5113495bSYour Name * of packets
1708*5113495bSYour Name *
1709*5113495bSYour Name * Return: None
1710*5113495bSYour Name *
1711*5113495bSYour Name */
send_packetdump_monitor(uint8_t type)1712*5113495bSYour Name static void send_packetdump_monitor(uint8_t type)
1713*5113495bSYour Name {
1714*5113495bSYour Name struct ath_pktlog_hdr pktlog_hdr = {0};
1715*5113495bSYour Name struct packet_dump pd_hdr = {0};
1716*5113495bSYour Name
1717*5113495bSYour Name pktlog_hdr.flags |= PKTLOG_HDR_SIZE_16;
1718*5113495bSYour Name
1719*5113495bSYour Name pktlog_hdr.log_type = PKTLOG_TYPE_PKT_DUMP;
1720*5113495bSYour Name pktlog_hdr.size = sizeof(pd_hdr);
1721*5113495bSYour Name
1722*5113495bSYour Name pd_hdr.type = type;
1723*5113495bSYour Name
1724*5113495bSYour Name LOGGING_TRACE(QDF_TRACE_LEVEL_DEBUG,
1725*5113495bSYour Name "fate Tx-Rx %s: type: %d", __func__, type);
1726*5113495bSYour Name
1727*5113495bSYour Name wlan_pkt_stats_to_logger_thread(&pktlog_hdr, &pd_hdr, NULL);
1728*5113495bSYour Name }
1729*5113495bSYour Name
wlan_deregister_txrx_packetdump(uint8_t pdev_id)1730*5113495bSYour Name void wlan_deregister_txrx_packetdump(uint8_t pdev_id)
1731*5113495bSYour Name {
1732*5113495bSYour Name void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1733*5113495bSYour Name
1734*5113495bSYour Name if (!soc)
1735*5113495bSYour Name return;
1736*5113495bSYour Name
1737*5113495bSYour Name if (gtx_count || grx_count) {
1738*5113495bSYour Name cdp_deregister_packetdump_cb(soc, pdev_id);
1739*5113495bSYour Name wma_deregister_packetdump_callback();
1740*5113495bSYour Name send_packetdump_monitor(STOP_MONITOR);
1741*5113495bSYour Name csr_packetdump_timer_stop();
1742*5113495bSYour Name
1743*5113495bSYour Name gtx_count = 0;
1744*5113495bSYour Name grx_count = 0;
1745*5113495bSYour Name } else
1746*5113495bSYour Name LOGGING_TRACE(QDF_TRACE_LEVEL_DEBUG,
1747*5113495bSYour Name "%s: deregistered packetdump already", __func__);
1748*5113495bSYour Name }
1749*5113495bSYour Name
1750*5113495bSYour Name /*
1751*5113495bSYour Name * check_txrx_packetdump_count() - function to check
1752*5113495bSYour Name * tx/rx packet dump global counts
1753*5113495bSYour Name * @pdev_id: datapath pdev identifier
1754*5113495bSYour Name *
1755*5113495bSYour Name * This function is used to check global counts of tx/rx
1756*5113495bSYour Name * packet dump functionality.
1757*5113495bSYour Name *
1758*5113495bSYour Name * Return: 1 if either gtx_count or grx_count reached 32
1759*5113495bSYour Name * 0 otherwise
1760*5113495bSYour Name *
1761*5113495bSYour Name */
check_txrx_packetdump_count(uint8_t pdev_id)1762*5113495bSYour Name static bool check_txrx_packetdump_count(uint8_t pdev_id)
1763*5113495bSYour Name {
1764*5113495bSYour Name if (gtx_count == MAX_NUM_PKT_LOG ||
1765*5113495bSYour Name grx_count == MAX_NUM_PKT_LOG) {
1766*5113495bSYour Name LOGGING_TRACE(QDF_TRACE_LEVEL_DEBUG,
1767*5113495bSYour Name "%s gtx_count: %d grx_count: %d deregister packetdump",
1768*5113495bSYour Name __func__, gtx_count, grx_count);
1769*5113495bSYour Name wlan_deregister_txrx_packetdump(pdev_id);
1770*5113495bSYour Name return 1;
1771*5113495bSYour Name }
1772*5113495bSYour Name return 0;
1773*5113495bSYour Name }
1774*5113495bSYour Name
1775*5113495bSYour Name /*
1776*5113495bSYour Name * tx_packetdump_cb() - tx packet dump callback
1777*5113495bSYour Name * @soc: soc handle
1778*5113495bSYour Name * @pdev_id: datapath pdev id
1779*5113495bSYour Name * @vdev_id: vdev id
1780*5113495bSYour Name * @netbuf: netbuf
1781*5113495bSYour Name * @status: status of tx packet
1782*5113495bSYour Name * @type: packet type
1783*5113495bSYour Name *
1784*5113495bSYour Name * This function is used to send tx packet dump to HAL layer
1785*5113495bSYour Name * and deregister packet dump callbacks
1786*5113495bSYour Name *
1787*5113495bSYour Name * Return: None
1788*5113495bSYour Name *
1789*5113495bSYour Name */
tx_packetdump_cb(ol_txrx_soc_handle soc,uint8_t pdev_id,uint8_t vdev_id,qdf_nbuf_t netbuf,enum qdf_dp_tx_rx_status status,enum qdf_pkt_type type)1790*5113495bSYour Name static void tx_packetdump_cb(ol_txrx_soc_handle soc,
1791*5113495bSYour Name uint8_t pdev_id, uint8_t vdev_id,
1792*5113495bSYour Name qdf_nbuf_t netbuf,
1793*5113495bSYour Name enum qdf_dp_tx_rx_status status,
1794*5113495bSYour Name enum qdf_pkt_type type)
1795*5113495bSYour Name {
1796*5113495bSYour Name bool temp;
1797*5113495bSYour Name enum tx_pkt_fate tx_status = qdf_hal_tx_status_map(status);
1798*5113495bSYour Name enum pkt_type pkt_type = qdf_hal_pkt_type_map(type);
1799*5113495bSYour Name
1800*5113495bSYour Name if (!soc)
1801*5113495bSYour Name return;
1802*5113495bSYour Name
1803*5113495bSYour Name temp = check_txrx_packetdump_count(pdev_id);
1804*5113495bSYour Name if (temp)
1805*5113495bSYour Name return;
1806*5113495bSYour Name
1807*5113495bSYour Name send_packetdump(soc, vdev_id, netbuf, tx_status, pkt_type);
1808*5113495bSYour Name }
1809*5113495bSYour Name
1810*5113495bSYour Name
1811*5113495bSYour Name /*
1812*5113495bSYour Name * rx_packetdump_cb() - rx packet dump callback
1813*5113495bSYour Name * @soc: soc handle
1814*5113495bSYour Name * @pdev_id: datapath pdev id
1815*5113495bSYour Name * @vdev_id: vdev id
1816*5113495bSYour Name * @netbuf: netbuf
1817*5113495bSYour Name * @status: status of rx packet
1818*5113495bSYour Name * @type: packet type
1819*5113495bSYour Name *
1820*5113495bSYour Name * This function is used to send rx packet dump to HAL layer
1821*5113495bSYour Name * and deregister packet dump callbacks
1822*5113495bSYour Name *
1823*5113495bSYour Name * Return: None
1824*5113495bSYour Name *
1825*5113495bSYour Name */
rx_packetdump_cb(ol_txrx_soc_handle soc,uint8_t pdev_id,uint8_t vdev_id,qdf_nbuf_t netbuf,enum qdf_dp_tx_rx_status status,enum qdf_pkt_type type)1826*5113495bSYour Name static void rx_packetdump_cb(ol_txrx_soc_handle soc,
1827*5113495bSYour Name uint8_t pdev_id, uint8_t vdev_id,
1828*5113495bSYour Name qdf_nbuf_t netbuf,
1829*5113495bSYour Name enum qdf_dp_tx_rx_status status,
1830*5113495bSYour Name enum qdf_pkt_type type)
1831*5113495bSYour Name {
1832*5113495bSYour Name bool temp;
1833*5113495bSYour Name enum rx_pkt_fate rx_status = qdf_hal_rx_status_map(status);
1834*5113495bSYour Name enum pkt_type pkt_type = qdf_hal_pkt_type_map(type);
1835*5113495bSYour Name
1836*5113495bSYour Name if (!soc)
1837*5113495bSYour Name return;
1838*5113495bSYour Name
1839*5113495bSYour Name temp = check_txrx_packetdump_count(pdev_id);
1840*5113495bSYour Name if (temp)
1841*5113495bSYour Name return;
1842*5113495bSYour Name
1843*5113495bSYour Name send_packetdump(soc, vdev_id, netbuf, rx_status, pkt_type);
1844*5113495bSYour Name }
1845*5113495bSYour Name
wlan_register_txrx_packetdump(uint8_t pdev_id)1846*5113495bSYour Name void wlan_register_txrx_packetdump(uint8_t pdev_id)
1847*5113495bSYour Name {
1848*5113495bSYour Name void *soc = cds_get_context(QDF_MODULE_ID_SOC);
1849*5113495bSYour Name
1850*5113495bSYour Name if (!soc)
1851*5113495bSYour Name return;
1852*5113495bSYour Name
1853*5113495bSYour Name cdp_register_packetdump_cb(soc, pdev_id,
1854*5113495bSYour Name tx_packetdump_cb, rx_packetdump_cb);
1855*5113495bSYour Name wma_register_packetdump_callback(tx_packetdump_cb,
1856*5113495bSYour Name rx_packetdump_cb);
1857*5113495bSYour Name send_packetdump_monitor(START_MONITOR);
1858*5113495bSYour Name
1859*5113495bSYour Name gtx_count = 0;
1860*5113495bSYour Name grx_count = 0;
1861*5113495bSYour Name
1862*5113495bSYour Name csr_packetdump_timer_start();
1863*5113495bSYour Name }
1864*5113495bSYour Name #endif /* CONNECTIVITY_PKTLOG */
1865*5113495bSYour Name #ifdef WLAN_CHIPSET_STATS
wlan_set_chipset_stats_bit(void)1866*5113495bSYour Name void wlan_set_chipset_stats_bit(void)
1867*5113495bSYour Name {
1868*5113495bSYour Name set_bit(HOST_LOG_CHIPSET_STATS, &gwlan_logging.eventFlag);
1869*5113495bSYour Name set_bit(FW_LOG_CHIPSET_STATS, &gwlan_logging.eventFlag);
1870*5113495bSYour Name }
1871*5113495bSYour Name #endif /* WLAN_CHIPSET_STATS */
1872*5113495bSYour Name #endif /* WLAN_LOGGING_SOCK_SVC_ENABLE */
1873