xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_umac_reset.h (revision d0c05845839e5f2ba5a8dcebe0cd3e4cd4e8dfcf)
1 /*
2  * Copyright (c) 2022 Qualcomm Innovation Center, Inc. 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 #ifndef _DP_UMAC_RESET_H_
18 #define _DP_UMAC_RESET_H_
19 
20 #include <qdf_types.h>
21 struct dp_soc;
22 
23 /**
24  * enum umac_reset_action - Actions supported by the UMAC reset
25  * @UMAC_RESET_ACTION_DO_PRE_RESET: DO_PRE_RESET
26  * @UMAC_RESET_ACTION_DO_POST_RESET_START: DO_POST_RESET_START
27  * @UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE: DO_POST_RESET_COMPLETE
28  * @UMAC_RESET_ACTION_MAX: Maximum actions
29  */
30 enum umac_reset_action {
31 	UMAC_RESET_ACTION_DO_PRE_RESET = 0,
32 	UMAC_RESET_ACTION_DO_POST_RESET_START = 1,
33 	UMAC_RESET_ACTION_DO_POST_RESET_COMPLETE = 2,
34 	UMAC_RESET_ACTION_MAX
35 };
36 
37 #ifdef DP_UMAC_HW_RESET_SUPPORT
38 
39 #define dp_umac_reset_alert(params...) \
40 	QDF_TRACE_FATAL(QDF_MODULE_ID_DP_UMAC_RESET, params)
41 #define dp_umac_reset_err(params...) \
42 	QDF_TRACE_ERROR(QDF_MODULE_ID_DP_UMAC_RESET, params)
43 #define dp_umac_reset_warn(params...) \
44 	QDF_TRACE_WARN(QDF_MODULE_ID_DP_UMAC_RESET, params)
45 #define dp_umac_reset_notice(params...) \
46 	QDF_TRACE_INFO(QDF_MODULE_ID_DP_UMAC_RESET, params)
47 #define dp_umac_reset_info(params...) \
48 	QDF_TRACE_INFO(QDF_MODULE_ID_DP_UMAC_RESET, params)
49 #define dp_umac_reset_debug(params...) \
50 	QDF_TRACE_DEBUG(QDF_MODULE_ID_DP_UMAC_RESET, params)
51 
52 #define DP_UMAC_RESET_SHMEM_ALIGN 8
53 #define DP_UMAC_RESET_SHMEM_MAGIC_NUM (0xDEADBEEF)
54 
55 /**
56  * enum umac_reset_state - States required by the UMAC reset state machine
57  * @UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET: Waiting for the DO_PRE_RESET event
58  * @UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED: Received the DO_PRE_RESET event
59  * @UMAC_RESET_STATE_HOST_PRE_RESET_DONE: Host has completed handling the
60  * PRE_RESET event
61  * @UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START: Waiting for the
62  * DO_POST_RESET_START event
63  * @UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED: Received the
64  * DO_POST_RESET_START event
65  * @UMAC_RESET_STATE_HOST_POST_RESET_START_DONE: Host has completed handling the
66  * POST_RESET_START event
67  * @UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE: Waiting for the
68  * DO_POST_RESET_COMPLETE event
69  * @UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED: Received the
70  * DO_POST_RESET_COMPLETE event
71  * @UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE: Host has completed handling
72  * the DO_POST_RESET_COMPLETE event
73  */
74 enum umac_reset_state {
75 	UMAC_RESET_STATE_WAIT_FOR_DO_PRE_RESET = 0,
76 	UMAC_RESET_STATE_DO_PRE_RESET_RECEIVED,
77 	UMAC_RESET_STATE_HOST_PRE_RESET_DONE,
78 
79 	UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_START,
80 	UMAC_RESET_STATE_DO_POST_RESET_START_RECEIVED,
81 	UMAC_RESET_STATE_HOST_POST_RESET_START_DONE,
82 
83 	UMAC_RESET_STATE_WAIT_FOR_DO_POST_RESET_COMPLETE,
84 	UMAC_RESET_STATE_DO_POST_RESET_COMPLETE_RECEIVED,
85 	UMAC_RESET_STATE_HOST_POST_RESET_COMPLETE_DONE,
86 };
87 
88 /**
89  * enum umac_reset_rx_event - Rx events deduced by the UMAC reset
90  * @UMAC_RESET_RX_EVENT_NONE: No event
91  * @UMAC_RESET_RX_EVENT_DO_PRE_RESET: DO_PRE_RESET event
92  * @UMAC_RESET_RX_EVENT_DO_POST_RESET_START: DO_POST_RESET_START event
93  * @UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE: DO_POST_RESET_COMPELTE event
94  * @UMAC_RESET_RX_EVENT_ERROR: Error while processing the Rx event
95  */
96 enum umac_reset_rx_event {
97 	UMAC_RESET_RX_EVENT_NONE = 0x0,
98 	UMAC_RESET_RX_EVENT_DO_PRE_RESET = 0x1,
99 	UMAC_RESET_RX_EVENT_DO_POST_RESET_START = 0x2,
100 	UMAC_RESET_RX_EVENT_DO_POST_RESET_COMPELTE = 0x4,
101 
102 	UMAC_RESET_RX_EVENT_ERROR = 0xFFFFFFFF,
103 };
104 
105 /**
106  * enum umac_reset_tx_cmd: UMAC reset Tx command
107  * @UMAC_RESET_TX_CMD_PRE_RESET_DONE: PRE_RESET_DONE
108  * @UMAC_RESET_TX_CMD_POST_RESET_START_DONE: POST_RESET_START_DONE
109  * @UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE: POST_RESET_COMPLETE_DONE
110  */
111 enum umac_reset_tx_cmd {
112 	UMAC_RESET_TX_CMD_PRE_RESET_DONE,
113 	UMAC_RESET_TX_CMD_POST_RESET_START_DONE,
114 	UMAC_RESET_TX_CMD_POST_RESET_COMPLETE_DONE,
115 };
116 
117 /**
118  * struct umac_reset_rx_actions - callbacks for handling UMAC reset actions
119  * @cb: Array of pointers where each pointer contains callback for each UMAC
120  * reset action for that index
121  */
122 struct umac_reset_rx_actions {
123 	QDF_STATUS (*cb[UMAC_RESET_ACTION_MAX])(struct dp_soc *soc);
124 };
125 
126 /**
127  * struct dp_soc_umac_reset_ctx - UMAC reset context at soc level
128  * @shmem_paddr_unaligned: Physical address of the shared memory (unaligned)
129  * @shmem_vaddr_unaligned: Virtual address of the shared memory (unaligned)
130  * @shmem_paddr_aligned: Physical address of the shared memory (aligned)
131  * @shmem_vaddr_aligned: Virtual address of the shared memory (aligned)
132  * @shmem_size: Size of the shared memory
133  * @intr_offset: Offset of the UMAC reset interrupt w.r.t DP base interrupt
134  * @current_state: current state of the UMAC reset state machine
135  * @shmem_exp_magic_num: Expected magic number in the shared memory
136  * @rx_actions: callbacks for handling UMAC reset actions
137  */
138 struct dp_soc_umac_reset_ctx {
139 	qdf_dma_addr_t shmem_paddr_unaligned;
140 	void *shmem_vaddr_unaligned;
141 	qdf_dma_addr_t shmem_paddr_aligned;
142 	htt_umac_hang_recovery_msg_shmem_t *shmem_vaddr_aligned;
143 	size_t shmem_size;
144 	int intr_offset;
145 	enum umac_reset_state current_state;
146 	uint32_t shmem_exp_magic_num;
147 	struct umac_reset_rx_actions rx_actions;
148 };
149 
150 /**
151  * dp_soc_umac_reset_init() - Initialize UMAC reset context
152  * @soc: DP soc object
153  *
154  * Return: QDF status of operation
155  */
156 QDF_STATUS dp_soc_umac_reset_init(struct dp_soc *soc);
157 
158 /**
159  * dp_soc_umac_reset_deinit() - De-initialize UMAC reset context
160  * @txrx_soc: DP soc object
161  *
162  * Return: QDF status of operation
163  */
164 QDF_STATUS dp_soc_umac_reset_deinit(struct cdp_soc_t *txrx_soc);
165 
166 /**
167  * dp_umac_reset_interrupt_attach() - Register handlers for UMAC reset interrupt
168  * @soc: DP soc object
169  *
170  * Return: QDF status of operation
171  */
172 QDF_STATUS dp_umac_reset_interrupt_attach(struct dp_soc *soc);
173 
174 /**
175  * dp_umac_reset_interrupt_detach() - Unregister UMAC reset interrupt handlers
176  * @soc: DP soc object
177  *
178  * Return: QDF status of operation
179  */
180 QDF_STATUS dp_umac_reset_interrupt_detach(struct dp_soc *soc);
181 
182 /**
183  * dp_umac_reset_register_rx_action_callback() - Register a callback for a given
184  * UMAC reset action
185  * @soc: DP soc object
186  * @handler: callback handler to be registered
187  * @action: UMAC reset action for which @handler needs to be registered
188  *
189  * Return: QDF status of operation
190  */
191 QDF_STATUS dp_umac_reset_register_rx_action_callback(
192 			struct dp_soc *soc,
193 			QDF_STATUS (*handler)(struct dp_soc *soc),
194 			enum umac_reset_action action);
195 
196 /**
197  * dp_umac_reset_notify_action_completion() - Notify that a given action has
198  * been completed
199  * @soc: DP soc object
200  * @action: UMAC reset action that got completed
201  *
202  * Return: QDF status of operation
203  */
204 QDF_STATUS dp_umac_reset_notify_action_completion(
205 			struct dp_soc *soc,
206 			enum umac_reset_action action);
207 #else
208 static inline
209 QDF_STATUS dp_soc_umac_reset_init(struct dp_soc *soc)
210 {
211 	return QDF_STATUS_SUCCESS;
212 }
213 
214 static inline
215 QDF_STATUS dp_soc_umac_reset_deinit(struct cdp_soc_t *txrx_soc)
216 {
217 	return QDF_STATUS_SUCCESS;
218 }
219 
220 static inline
221 QDF_STATUS dp_umac_reset_register_rx_action_callback(
222 			struct dp_soc *soc,
223 			QDF_STATUS (*handler)(struct dp_soc *soc),
224 			enum umac_reset_action action)
225 {
226 	return QDF_STATUS_SUCCESS;
227 }
228 
229 static inline
230 QDF_STATUS dp_umac_reset_notify_action_completion(
231 		struct dp_soc *soc,
232 		enum umac_reset_action action)
233 {
234 	return QDF_STATUS_SUCCESS;
235 }
236 #endif /* DP_UMAC_HW_RESET_SUPPORT */
237 #endif /* _DP_UMAC_RESET_H_ */
238