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