xref: /wlan-dirver/qca-wifi-host-cmn/target_if/direct_buf_rx/src/target_if_direct_buf_rx_api.c (revision 503663c6daafffe652fa360bde17243568cd6d2a)
1 /*
2  * Copyright (c) 2017-2019 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 #include <qdf_status.h>
20 #include <target_if_direct_buf_rx_api.h>
21 #include <wlan_objmgr_cmn.h>
22 #include <wlan_objmgr_global_obj.h>
23 #include <wlan_objmgr_psoc_obj.h>
24 #include <wlan_objmgr_cmn.h>
25 #include "target_if_direct_buf_rx_main.h"
26 #include <qdf_module.h>
27 
28 #if defined(WLAN_DEBUGFS) && defined(DIRECT_BUF_RX_DEBUG)
29 /* Base debugfs entry for DBR module */
30 qdf_dentry_t dbr_debugfs_entry;
31 
32 static inline void
33 target_if_direct_buf_rx_debugfs_init(void)
34 {
35 	dbr_debugfs_entry = qdf_debugfs_create_dir("dbr_ring_debug", NULL);
36 
37 	if (!dbr_debugfs_entry)
38 		direct_buf_rx_err("error while creating direct_buf rx debugfs dir");
39 }
40 
41 static inline void
42 target_if_direct_buf_rx_debugfs_deinit(void)
43 {
44 	if (dbr_debugfs_entry) {
45 		qdf_debugfs_remove_dir_recursive(dbr_debugfs_entry);
46 		dbr_debugfs_entry = NULL;
47 	}
48 }
49 #else
50 static inline void
51 target_if_direct_buf_rx_debugfs_init(void)
52 {
53 }
54 
55 static inline void
56 target_if_direct_buf_rx_debugfs_deinit(void)
57 {
58 }
59 #endif /* WLAN_DEBUGFS && DIRECT_BUF_RX_DEBUG */
60 
61 QDF_STATUS direct_buf_rx_init(void)
62 {
63 	QDF_STATUS status;
64 
65 	status = wlan_objmgr_register_psoc_create_handler(
66 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
67 			target_if_direct_buf_rx_psoc_create_handler,
68 			NULL);
69 
70 	if (QDF_IS_STATUS_ERROR(status)) {
71 		direct_buf_rx_err("Failed to register psoc create handler");
72 		return status;
73 	}
74 
75 	status = wlan_objmgr_register_psoc_destroy_handler(
76 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
77 			target_if_direct_buf_rx_psoc_destroy_handler,
78 			NULL);
79 
80 	if (QDF_IS_STATUS_ERROR(status)) {
81 		direct_buf_rx_err("Failed to register psoc destroy handler");
82 		goto dbr_unreg_psoc_create;
83 	}
84 
85 	status = wlan_objmgr_register_pdev_create_handler(
86 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
87 			target_if_direct_buf_rx_pdev_create_handler,
88 			NULL);
89 
90 	if (QDF_IS_STATUS_ERROR(status)) {
91 		direct_buf_rx_err("Failed to register pdev create handler");
92 		goto dbr_unreg_psoc_destroy;
93 	}
94 
95 	status = wlan_objmgr_register_pdev_destroy_handler(
96 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
97 			target_if_direct_buf_rx_pdev_destroy_handler,
98 			NULL);
99 
100 	if (QDF_IS_STATUS_ERROR(status)) {
101 		direct_buf_rx_err("Failed to register pdev destroy handler");
102 		goto dbr_unreg_pdev_create;
103 	}
104 
105 	target_if_direct_buf_rx_debugfs_init();
106 
107 	direct_buf_rx_info("Direct Buffer RX pdev,psoc create and destroy handlers registered");
108 
109 	return QDF_STATUS_SUCCESS;
110 
111 dbr_unreg_pdev_create:
112 	status = wlan_objmgr_unregister_pdev_create_handler(
113 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
114 			target_if_direct_buf_rx_pdev_create_handler,
115 			NULL);
116 
117 dbr_unreg_psoc_destroy:
118 	status = wlan_objmgr_unregister_psoc_destroy_handler(
119 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
120 			target_if_direct_buf_rx_psoc_destroy_handler,
121 			NULL);
122 
123 dbr_unreg_psoc_create:
124 	status = wlan_objmgr_unregister_psoc_create_handler(
125 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
126 			target_if_direct_buf_rx_psoc_create_handler,
127 			NULL);
128 
129 	return QDF_STATUS_E_FAILURE;
130 }
131 qdf_export_symbol(direct_buf_rx_init);
132 
133 QDF_STATUS direct_buf_rx_deinit(void)
134 {
135 	QDF_STATUS status;
136 
137 	target_if_direct_buf_rx_debugfs_deinit();
138 
139 	status = wlan_objmgr_unregister_pdev_destroy_handler(
140 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
141 			target_if_direct_buf_rx_pdev_destroy_handler,
142 			NULL);
143 
144 	if (QDF_IS_STATUS_ERROR(status))
145 		direct_buf_rx_err("Failed to unregister pdev destroy handler");
146 
147 	status = wlan_objmgr_unregister_pdev_create_handler(
148 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
149 			target_if_direct_buf_rx_pdev_create_handler,
150 			NULL);
151 
152 	if (QDF_IS_STATUS_ERROR(status))
153 		direct_buf_rx_err("Failed to unregister pdev create handler");
154 
155 	status = wlan_objmgr_unregister_psoc_destroy_handler(
156 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
157 			target_if_direct_buf_rx_psoc_destroy_handler,
158 			NULL);
159 
160 	if (QDF_IS_STATUS_ERROR(status))
161 		direct_buf_rx_err("Failed to unregister psoc destroy handler");
162 
163 	status = wlan_objmgr_unregister_psoc_create_handler(
164 			WLAN_TARGET_IF_COMP_DIRECT_BUF_RX,
165 			target_if_direct_buf_rx_psoc_create_handler,
166 			NULL);
167 
168 	if (QDF_IS_STATUS_ERROR(status))
169 		direct_buf_rx_err("Failed to unregister psoc create handler");
170 
171 	direct_buf_rx_info("Direct Buffer RX pdev,psoc create and destroy handlers unregistered");
172 
173 	return status;
174 }
175 qdf_export_symbol(direct_buf_rx_deinit);
176 
177 QDF_STATUS direct_buf_rx_target_attach(struct wlan_objmgr_psoc *psoc,
178 				void *hal_soc, qdf_device_t osdev)
179 {
180 	struct direct_buf_rx_psoc_obj *dbr_psoc_obj;
181 
182 	if (!hal_soc || !osdev) {
183 		direct_buf_rx_err("hal soc or osdev is null");
184 		return QDF_STATUS_E_INVAL;
185 	}
186 
187 	dbr_psoc_obj = wlan_objmgr_psoc_get_comp_private_obj(psoc,
188 				WLAN_TARGET_IF_COMP_DIRECT_BUF_RX);
189 
190 	direct_buf_rx_info("Dbr psoc obj %pK", dbr_psoc_obj);
191 
192 	if (!dbr_psoc_obj) {
193 		direct_buf_rx_err("dir buf rx psoc obj is null");
194 		return QDF_STATUS_E_FAILURE;
195 	}
196 
197 	dbr_psoc_obj->hal_soc = hal_soc;
198 	dbr_psoc_obj->osdev = osdev;
199 
200 	return QDF_STATUS_SUCCESS;
201 }
202 
203 #ifdef DIRECT_BUF_RX_DEBUG
204 static inline void
205 target_if_direct_buf_rx_debug_register_tx_ops(
206 	struct wlan_lmac_if_tx_ops *tx_ops)
207 {
208 	tx_ops->dbr_tx_ops.direct_buf_rx_start_ring_debug =
209 				target_if_dbr_start_ring_debug;
210 	tx_ops->dbr_tx_ops.direct_buf_rx_stop_ring_debug =
211 				target_if_dbr_stop_ring_debug;
212 	tx_ops->dbr_tx_ops.direct_buf_rx_start_buffer_poisoning =
213 				target_if_dbr_start_buffer_poisoning;
214 	tx_ops->dbr_tx_ops.direct_buf_rx_stop_buffer_poisoning =
215 				target_if_dbr_stop_buffer_poisoning;
216 }
217 #else
218 static inline void
219 target_if_direct_buf_rx_debug_register_tx_ops(
220 	struct wlan_lmac_if_tx_ops *tx_ops)
221 {
222 }
223 #endif /* DIRECT_BUF_RX_DEBUG */
224 
225 void target_if_direct_buf_rx_register_tx_ops(struct wlan_lmac_if_tx_ops *tx_ops)
226 {
227 	tx_ops->dbr_tx_ops.direct_buf_rx_module_register =
228 				target_if_direct_buf_rx_module_register;
229 	tx_ops->dbr_tx_ops.direct_buf_rx_module_unregister =
230 				target_if_direct_buf_rx_module_unregister;
231 	tx_ops->dbr_tx_ops.direct_buf_rx_register_events =
232 				target_if_direct_buf_rx_register_events;
233 	tx_ops->dbr_tx_ops.direct_buf_rx_unregister_events =
234 				target_if_direct_buf_rx_unregister_events;
235 	tx_ops->dbr_tx_ops.direct_buf_rx_print_ring_stat =
236 				target_if_direct_buf_rx_print_ring_stat;
237 	tx_ops->dbr_tx_ops.direct_buf_rx_get_ring_params =
238 				target_if_direct_buf_rx_get_ring_params;
239 	target_if_direct_buf_rx_debug_register_tx_ops(tx_ops);
240 }
241 qdf_export_symbol(target_if_direct_buf_rx_register_tx_ops);
242