xref: /wlan-dirver/qca-wifi-host-cmn/umac/cmn_services/sm_engine/src/wlan_sm_engine_dbg.c (revision ad85c389289a03e320cd08dea21861f9857892fc)
1 /*
2  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /**
18  * DOC: Implements general SM debug framework
19  */
20 #include <wlan_sm_engine.h>
21 #include <wlan_sm_engine_dbg.h>
22 
23 void wlan_sm_save_history(struct wlan_sm *sm,
24 			  enum wlan_sm_trace_type trace_type,
25 			  uint8_t initial_state, uint8_t final_state,
26 			  uint16_t event_type)
27 {
28 	struct wlan_sm_history *p_sm_history = &sm->history;
29 	struct wlan_sm_history_info *p_memento;
30 
31 	/*
32 	 * History saved in circular buffer.
33 	 * Save a pointer to next write location and increment pointer.
34 	 */
35 	qdf_spin_lock_bh(&p_sm_history->sm_history_lock);
36 	p_memento = &p_sm_history->data[p_sm_history->index];
37 	p_sm_history->index++;
38 
39 	if (p_sm_history->index >= WLAN_SM_ENGINE_HISTORY_SIZE)
40 		p_sm_history->index = 0;
41 
42 	qdf_spin_unlock_bh(&p_sm_history->sm_history_lock);
43 
44 	qdf_mem_zero(p_memento, sizeof(*p_memento));
45 	p_memento->trace_type = trace_type;
46 	p_memento->initial_state = initial_state;
47 	p_memento->final_state = final_state;
48 	p_memento->event_type = event_type;
49 }
50 
51 void wlan_sm_history_init(struct wlan_sm *sm)
52 {
53 	qdf_spinlock_create(&sm->history.sm_history_lock);
54 }
55 
56 void wlan_sm_history_delete(struct wlan_sm *sm)
57 {
58 	qdf_spinlock_destroy(&sm->history.sm_history_lock);
59 }
60 
61 static void wlan_sm_print_history_entry(struct wlan_sm *sm,
62 					struct wlan_sm_history_info *ent,
63 					uint16_t i)
64 {
65 	const char *event_name = NULL;
66 
67 	if (sm->event_names) {
68 		if (ent->event_type < sm->num_event_names)
69 			event_name = sm->event_names[ent->event_type];
70 
71 		sm_engine_nofl_info(" (%d) trace_type: %d, event:%s[%d]", i,
72 				    ent->trace_type,
73 				    event_name ? event_name : "UNKNOWN_EVENT",
74 				    ent->event_type);
75 	} else {
76 		sm_engine_nofl_info(" (%d) trace_type: %d, event: %d", i,
77 				    ent->trace_type, ent->event_type);
78 	}
79 
80 	sm_engine_nofl_info(" (%d) initial state :%s[%d], final state: %s[%d]",
81 			    i, sm->state_info[ent->initial_state].name,
82 			    ent->initial_state,
83 			    sm->state_info[ent->final_state].name,
84 			    ent->final_state);
85 }
86 
87 void wlan_sm_print_history(struct wlan_sm *sm)
88 {
89 	struct wlan_sm_history *p_sm_history = &sm->history;
90 	uint16_t i;
91 
92 	/*
93 	 * History saved in circular buffer.
94 	 * Save a pointer to next write location and increment pointer.
95 	 */
96 	qdf_spin_lock_bh(&p_sm_history->sm_history_lock);
97 	sm_engine_nofl_info("%s: SM History index is %d",
98 			    sm->name, p_sm_history->index);
99 	for (i = 0; i < WLAN_SM_ENGINE_HISTORY_SIZE; i++)
100 		wlan_sm_print_history_entry(sm, &p_sm_history->data[i], i);
101 
102 	qdf_spin_unlock_bh(&p_sm_history->sm_history_lock);
103 }
104