xref: /wlan-driver/qcacld-3.0/core/pld/src/pld_sdio.h (revision 5113495b16420b49004c444715d2daae2066e7dc) !
1 /*
2  * Copyright (c) 2016-2019 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef __PLD_SDIO_H__
21 #define __PLD_SDIO_H__
22 
23 #ifdef CONFIG_PLD_SDIO_CNSS
24 #include <net/cnss.h>
25 #endif
26 #include "pld_common.h"
27 
28 #ifdef DYNAMIC_SINGLE_CHIP
29 #define PREFIX DYNAMIC_SINGLE_CHIP "/"
30 #else
31 
32 #ifdef MULTI_IF_NAME
33 #define PREFIX MULTI_IF_NAME "/"
34 #else
35 #define PREFIX ""
36 #endif
37 
38 #endif
39 
40 #define PLD_QCA9377_REV1_1_VERSION          0x5020001
41 #define PLD_QCA9379_REV1_VERSION            0x5040000
42 
43 #ifndef CONFIG_CNSS
44 #define PLD_AR6004_VERSION_REV1_3           0x31c8088a
45 #define PLD_AR9888_REV2_VERSION             0x4100016c
46 #define PLD_AR6320_REV1_VERSION             0x5000000
47 #define PLD_AR6320_REV1_1_VERSION           0x5000001
48 #define PLD_AR6320_REV1_3_VERSION           0x5000003
49 #define PLD_AR6320_REV2_1_VERSION           0x5010000
50 #define PLD_AR6320_REV3_VERSION             0x5020000
51 #define PLD_AR6320_REV3_2_VERSION           0x5030000
52 #define PLD_AR6320_DEV_VERSION              0x1000000
53 
54 
55 #endif
56 
57 #ifndef CONFIG_SDIO
pld_sdio_register_driver(void)58 static inline int pld_sdio_register_driver(void)
59 {
60 	return 0;
61 }
62 
pld_sdio_unregister_driver(void)63 static inline void pld_sdio_unregister_driver(void)
64 {
65 }
66 
67 static inline
pld_sdio_get_fw_files_for_target(struct pld_fw_files * pfw_files,u32 target_type,u32 target_version)68 int pld_sdio_get_fw_files_for_target(struct pld_fw_files *pfw_files,
69 				     u32 target_type, u32 target_version)
70 {
71 	return 0;
72 }
pld_sdio_get_wlan_mac_address(struct device * dev,uint32_t * num)73 static inline uint8_t *pld_sdio_get_wlan_mac_address(struct device *dev,
74 						     uint32_t *num)
75 {
76 	*num = 0;
77 	return NULL;
78 }
79 #else
80 /**
81  * pld_sdio_register_driver() - Register SDIO device callback functions
82  *
83  * Return: int
84  */
85 int pld_sdio_register_driver(void);
86 
87 /**
88  * pld_sdio_unregister_driver() - Unregister SDIO device callback functions
89  *
90  * Return: void
91  */
92 void pld_sdio_unregister_driver(void);
93 
94 /**
95  * pld_sdio_get_fw_files_for_target() - Get FW file names
96  * @pfw_files: buffer for FW file names
97  * @target_type: target type
98  * @target_version: target version
99  *
100  * Return target specific FW file names to the buffer.
101  *
102  * Return: 0 for success
103  *         Non zero failure code for errors
104  */
105 int pld_sdio_get_fw_files_for_target(struct pld_fw_files *pfw_files,
106 				     u32 target_type, u32 target_version);
107 #ifdef CONFIG_CNSS
pld_sdio_get_wlan_mac_address(struct device * dev,uint32_t * num)108 static inline uint8_t *pld_sdio_get_wlan_mac_address(struct device *dev,
109 						     uint32_t *num)
110 {
111 	return cnss_common_get_wlan_mac_address(dev, num);
112 }
113 #else
pld_sdio_get_wlan_mac_address(struct device * dev,uint32_t * num)114 static inline uint8_t *pld_sdio_get_wlan_mac_address(struct device *dev,
115 						     uint32_t *num)
116 {
117 	*num = 0;
118 	return NULL;
119 }
120 #endif
121 #endif
122 
123 #ifdef CONFIG_PLD_SDIO_CNSS
pld_sdio_get_virt_ramdump_mem(struct device * dev,unsigned long * size)124 static inline void *pld_sdio_get_virt_ramdump_mem(struct device *dev,
125 		unsigned long *size)
126 {
127 	return cnss_common_get_virt_ramdump_mem(dev, size);
128 }
129 
pld_sdio_release_virt_ramdump_mem(void * address)130 static inline void pld_sdio_release_virt_ramdump_mem(void *address)
131 {
132 }
133 
pld_sdio_device_crashed(struct device * dev)134 static inline void pld_sdio_device_crashed(struct device *dev)
135 {
136 	cnss_common_device_crashed(dev);
137 }
pld_sdio_is_fw_dump_skipped(void)138 static inline bool pld_sdio_is_fw_dump_skipped(void)
139 {
140 	return cnss_get_restart_level() == CNSS_RESET_SUBSYS_COUPLED;
141 }
142 
pld_sdio_device_self_recovery(struct device * dev)143 static inline void pld_sdio_device_self_recovery(struct device *dev)
144 {
145 	cnss_common_device_self_recovery(dev);
146 }
147 
pld_sdio_platform_driver_support(void)148 static inline bool pld_sdio_platform_driver_support(void)
149 {
150 	return true;
151 }
152 #else
pld_sdio_get_virt_ramdump_mem(struct device * dev,unsigned long * size)153 static inline void *pld_sdio_get_virt_ramdump_mem(struct device *dev,
154 		unsigned long *size)
155 {
156 	size_t length = 0;
157 	int flags = GFP_KERNEL;
158 
159 	length = TOTAL_DUMP_SIZE;
160 
161 	if (!size)
162 		return NULL;
163 
164 	*size = (unsigned long)length;
165 
166 	if (in_interrupt() || irqs_disabled() || in_atomic())
167 		flags = GFP_ATOMIC;
168 
169 	return kzalloc(length, flags);
170 }
171 
pld_sdio_release_virt_ramdump_mem(void * address)172 static inline void pld_sdio_release_virt_ramdump_mem(void *address)
173 {
174 	kfree(address);
175 }
176 
pld_sdio_device_crashed(struct device * dev)177 static inline void pld_sdio_device_crashed(struct device *dev)
178 {
179 }
pld_sdio_is_fw_dump_skipped(void)180 static inline bool pld_sdio_is_fw_dump_skipped(void)
181 {
182 	return false;
183 }
184 
pld_sdio_device_self_recovery(struct device * dev)185 static inline void pld_sdio_device_self_recovery(struct device *dev)
186 {
187 }
188 
pld_sdio_platform_driver_support(void)189 static inline bool pld_sdio_platform_driver_support(void)
190 {
191 	return false;
192 }
193 #endif
194 
195 #ifdef CONFIG_PLD_SDIO_CNSS
196 /**
197  * pld_hif_sdio_get_virt_ramdump_mem() - Get virtual ramdump memory
198  * @dev: device
199  * @size: buffer to virtual memory size
200  *
201  * Return: virtual ramdump memory address
202  */
pld_hif_sdio_get_virt_ramdump_mem(struct device * dev,unsigned long * size)203 static inline void *pld_hif_sdio_get_virt_ramdump_mem(struct device *dev,
204 						unsigned long *size)
205 {
206 	return cnss_common_get_virt_ramdump_mem(dev, size);
207 }
208 
209 /**
210  * pld_hif_sdio_release_ramdump_mem() - Release virtual ramdump memory
211  * @address: virtual ramdump memory address
212  *
213  * Return: void
214  */
pld_hif_sdio_release_ramdump_mem(unsigned long * address)215 static inline void pld_hif_sdio_release_ramdump_mem(unsigned long *address)
216 {
217 }
218 #else
219 #ifdef CONFIG_PLD_SDIO_CNSS2
220 #include <net/cnss2.h>
221 
222 /**
223  * pld_sdio_get_sdio_al_client_handle() - Get the sdio al client handle
224  * @func: SDIO function pointer
225  *
226  * Return: On success return client handle from al via cnss, else NULL
227  */
pld_sdio_get_sdio_al_client_handle(struct sdio_func * func)228 static inline struct sdio_al_client_handle *pld_sdio_get_sdio_al_client_handle
229 (
230 struct sdio_func *func
231 )
232 {
233 	if (!func)
234 		return NULL;
235 
236 	return cnss_sdio_wlan_get_sdio_al_client_handle(func);
237 }
238 
239 /**
240  * pld_sdio_register_sdio_al_channel() - Register channel with sdio al
241  * @al_client: SDIO al client handle
242  * @ch_data: SDIO client channel data
243  *
244  * Return: Channel handle on success, else null
245  */
pld_sdio_register_sdio_al_channel(struct sdio_al_client_handle * al_client,struct sdio_al_channel_data * ch_data)246 static inline struct sdio_al_channel_handle *pld_sdio_register_sdio_al_channel
247 (
248 struct sdio_al_client_handle *al_client,
249 struct sdio_al_channel_data *ch_data
250 )
251 {
252 	if (!al_client || !ch_data)
253 		return NULL;
254 
255 	return cnss_sdio_wlan_register_sdio_al_channel(ch_data);
256 }
257 
258 /**
259  * pld_sdio_unregister_sdio_al_channel() - Unregister the sdio al channel
260  * @ch_handle: SDIO al channel handle
261  *
262  * Return: None
263  */
pld_sdio_unregister_sdio_al_channel(struct sdio_al_channel_handle * ch_handle)264 static inline void pld_sdio_unregister_sdio_al_channel
265 (
266 struct sdio_al_channel_handle *ch_handle
267 )
268 {
269 	cnss_sdio_wlan_unregister_sdio_al_channel(ch_handle);
270 }
271 
272 /**
273  * pld_sdio_wlan_enable() - Enable WLAN
274  * @dev: device
275  * @config: NA
276  * @mode: WLAN mode
277  * @host_version: host software version
278  *
279  * This function enables WLAN FW. It passed
280  * WLAN mode and host software version to FW.
281  *
282  * Return: 0 for success
283  *         Non zero failure code for errors
284  */
285 int pld_sdio_wlan_enable(struct device *dev, struct pld_wlan_enable_cfg *config,
286 			 enum pld_driver_mode mode, const char *host_version);
287 #else
pld_sdio_wlan_enable(struct device * dev,struct pld_wlan_enable_cfg * config,enum pld_driver_mode mode,const char * host_version)288 static inline int pld_sdio_wlan_enable(struct device *dev,
289 				       struct pld_wlan_enable_cfg *config,
290 				       enum pld_driver_mode mode,
291 				       const char *host_version)
292 {
293 	return 0;
294 }
295 #endif /* CONFIG_PLD_SDIO_CNSS2 */
296 
297 /**
298  * pld_hif_sdio_get_virt_ramdump_mem() - Get virtual ramdump memory
299  * @dev: device
300  * @size: buffer to virtual memory size
301  *
302  * Return: virtual ramdump memory address
303  */
pld_hif_sdio_get_virt_ramdump_mem(struct device * dev,unsigned long * size)304 static inline void *pld_hif_sdio_get_virt_ramdump_mem(struct device *dev,
305 						unsigned long *size)
306 {
307 	size_t length = 0;
308 	int flags = GFP_KERNEL;
309 
310 	length = TOTAL_DUMP_SIZE;
311 
312 	if (size)
313 		*size = (unsigned long)length;
314 
315 	if (in_interrupt() || irqs_disabled() || in_atomic())
316 		flags = GFP_ATOMIC;
317 
318 	return kzalloc(length, flags);
319 }
320 
321 /**
322  * pld_hif_sdio_release_ramdump_mem() - Release virtual ramdump memory
323  * @address: virtual ramdump memory address
324  *
325  * Return: void
326  */
pld_hif_sdio_release_ramdump_mem(unsigned long * address)327 static inline void pld_hif_sdio_release_ramdump_mem(unsigned long *address)
328 {
329 	if (address)
330 		kfree(address);
331 }
332 #endif
333 #endif
334