xref: /wlan-driver/qcacld-3.0/core/pld/src/pld_snoc.h (revision 5113495b16420b49004c444715d2daae2066e7dc) !
1 /*
2  * Copyright (c) 2016-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2021-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_SNOC_H__
21 #define __PLD_SNOC_H__
22 
23 #ifdef CONFIG_CNSS_OUT_OF_TREE
24 #ifdef CONFIG_PLD_SNOC_ICNSS
25 #ifdef CONFIG_PLD_SNOC_ICNSS2
26 #include "icnss2.h"
27 #else
28 #include "icnss.h"
29 #endif
30 #endif
31 #else
32 #ifdef CONFIG_PLD_SNOC_ICNSS
33 #ifdef CONFIG_PLD_SNOC_ICNSS2
34 #include <soc/qcom/icnss2.h>
35 #else
36 #include <soc/qcom/icnss.h>
37 #endif
38 #endif
39 #endif
40 
41 #include "pld_internal.h"
42 
43 #ifndef CONFIG_PLD_SNOC_ICNSS
pld_snoc_register_driver(void)44 static inline int pld_snoc_register_driver(void)
45 {
46 	return 0;
47 }
48 
pld_snoc_unregister_driver(void)49 static inline void pld_snoc_unregister_driver(void)
50 {
51 }
pld_snoc_wlan_enable(struct device * dev,struct pld_wlan_enable_cfg * config,enum pld_driver_mode mode,const char * host_version)52 static inline int pld_snoc_wlan_enable(struct device *dev,
53 			struct pld_wlan_enable_cfg *config,
54 			enum pld_driver_mode mode, const char *host_version)
55 {
56 	return 0;
57 }
pld_snoc_wlan_disable(struct device * dev,enum pld_driver_mode mode)58 static inline int pld_snoc_wlan_disable(struct device *dev,
59 					enum pld_driver_mode mode)
60 {
61 	return 0;
62 }
pld_snoc_ce_request_irq(struct device * dev,unsigned int ce_id,irqreturn_t (* handler)(int,void *),unsigned long flags,const char * name,void * ctx)63 static inline int pld_snoc_ce_request_irq(struct device *dev,
64 					  unsigned int ce_id,
65 					  irqreturn_t (*handler)(int, void *),
66 					  unsigned long flags,
67 					  const char *name, void *ctx)
68 {
69 	return 0;
70 }
pld_snoc_ce_free_irq(struct device * dev,unsigned int ce_id,void * ctx)71 static inline int pld_snoc_ce_free_irq(struct device *dev,
72 				       unsigned int ce_id, void *ctx)
73 {
74 	return 0;
75 }
pld_snoc_enable_irq(struct device * dev,unsigned int ce_id)76 static inline void pld_snoc_enable_irq(struct device *dev, unsigned int ce_id)
77 {
78 }
pld_snoc_disable_irq(struct device * dev,unsigned int ce_id)79 static inline void pld_snoc_disable_irq(struct device *dev, unsigned int ce_id)
80 {
81 }
pld_snoc_get_soc_info(struct device * dev,struct pld_soc_info * info)82 static inline int pld_snoc_get_soc_info(struct device *dev, struct pld_soc_info *info)
83 {
84 	return 0;
85 }
pld_snoc_get_ce_id(struct device * dev,int irq)86 static inline int pld_snoc_get_ce_id(struct device *dev, int irq)
87 {
88 	return 0;
89 }
pld_snoc_power_on(struct device * dev)90 static inline int pld_snoc_power_on(struct device *dev)
91 {
92 	return 0;
93 }
pld_snoc_power_off(struct device * dev)94 static inline int pld_snoc_power_off(struct device *dev)
95 {
96 	return 0;
97 }
pld_snoc_get_irq(struct device * dev,int ce_id)98 static inline int pld_snoc_get_irq(struct device *dev, int ce_id)
99 {
100 	return 0;
101 }
pld_snoc_athdiag_read(struct device * dev,uint32_t offset,uint32_t memtype,uint32_t datalen,uint8_t * output)102 static inline int pld_snoc_athdiag_read(struct device *dev, uint32_t offset,
103 					uint32_t memtype, uint32_t datalen,
104 					uint8_t *output)
105 {
106 	return 0;
107 }
pld_snoc_athdiag_write(struct device * dev,uint32_t offset,uint32_t memtype,uint32_t datalen,uint8_t * input)108 static inline int pld_snoc_athdiag_write(struct device *dev, uint32_t offset,
109 					 uint32_t memtype, uint32_t datalen,
110 					 uint8_t *input)
111 {
112 	return 0;
113 }
114 
115 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
pld_snoc_smmu_get_domain(struct device * dev)116 static inline void *pld_snoc_smmu_get_domain(struct device *dev)
117 {
118 	return NULL;
119 }
120 
121 #else
pld_snoc_smmu_get_mapping(struct device * dev)122 static inline void *pld_snoc_smmu_get_mapping(struct device *dev)
123 {
124 	return NULL;
125 }
126 #endif
127 
pld_snoc_idle_restart(struct device * dev)128 static inline int pld_snoc_idle_restart(struct device *dev)
129 {
130 	return 0;
131 }
132 
pld_snoc_idle_shutdown(struct device * dev)133 static inline int pld_snoc_idle_shutdown(struct device *dev)
134 {
135 	return 0;
136 }
137 
pld_snoc_get_device_config(void)138 static inline unsigned long pld_snoc_get_device_config(void)
139 {
140 	return 0;
141 }
142 
pld_snoc_smmu_map(struct device * dev,phys_addr_t paddr,uint32_t * iova_addr,size_t size)143 static inline int pld_snoc_smmu_map(struct device *dev, phys_addr_t paddr,
144 				    uint32_t *iova_addr, size_t size)
145 {
146 	return 0;
147 }
148 
pld_snoc_smmu_unmap(struct device * dev,uint32_t iova_addr,size_t size)149 static inline int pld_snoc_smmu_unmap(struct device *dev,
150 				      uint32_t iova_addr, size_t size)
151 {
152 	return 0;
153 }
154 
155 static inline
pld_snoc_socinfo_get_serial_number(struct device * dev)156 unsigned int pld_snoc_socinfo_get_serial_number(struct device *dev)
157 {
158 	return 0;
159 }
pld_snoc_is_qmi_disable(struct device * dev)160 static inline int pld_snoc_is_qmi_disable(struct device *dev)
161 {
162 	return 0;
163 }
164 
pld_snoc_is_fw_down(struct device * dev)165 static inline int pld_snoc_is_fw_down(struct device *dev)
166 {
167 	return 0;
168 }
169 
pld_snoc_is_low_power_mode(struct device * dev)170 static inline int pld_snoc_is_low_power_mode(struct device *dev)
171 {
172 	return 0;
173 }
174 
pld_snoc_set_fw_log_mode(struct device * dev,u8 fw_log_mode)175 static inline int pld_snoc_set_fw_log_mode(struct device *dev, u8 fw_log_mode)
176 {
177 	return 0;
178 }
pld_snoc_force_assert_target(struct device * dev)179 static inline int pld_snoc_force_assert_target(struct device *dev)
180 {
181 	return 0;
182 }
183 
pld_snoc_is_pdr(void)184 static inline int pld_snoc_is_pdr(void)
185 {
186 	return 0;
187 }
188 
pld_snoc_is_fw_rejuvenate(void)189 static inline int pld_snoc_is_fw_rejuvenate(void)
190 {
191 	return 0;
192 }
193 
pld_snoc_block_shutdown(bool status)194 static inline void pld_snoc_block_shutdown(bool status)
195 {
196 }
197 
198 #ifdef FEATURE_WLAN_TIME_SYNC_FTM
199 static inline int
pld_snoc_get_audio_wlan_timestamp(struct device * dev,enum pld_wlan_time_sync_trigger_type type,uint64_t * ts)200 pld_snoc_get_audio_wlan_timestamp(struct device *dev,
201 				  enum pld_wlan_time_sync_trigger_type type,
202 				  uint64_t *ts)
203 {
204 	return 0;
205 }
206 #endif /* FEATURE_WLAN_TIME_SYNC_FTM */
207 
208 #else
209 /**
210  * pld_snoc_register_driver() - Register platform device callback functions
211  *
212  * Return: int
213  */
214 int pld_snoc_register_driver(void);
215 
216 /**
217  * pld_snoc_unregister_driver() - Unregister platform device callback functions
218  *
219  * Return: void
220  */
221 void pld_snoc_unregister_driver(void);
222 
223 /**
224  * pld_snoc_wlan_enable() - Enable WLAN
225  * @dev: device
226  * @config: WLAN configuration data
227  * @mode: WLAN mode
228  * @host_version: host software version
229  *
230  * This function enables WLAN FW. It passed WLAN configuration data,
231  * WLAN mode and host software version to FW.
232  *
233  * Return: 0 for success
234  *         Non zero failure code for errors
235  */
236 int pld_snoc_wlan_enable(struct device *dev,
237 			 struct pld_wlan_enable_cfg *config,
238 			 enum pld_driver_mode mode, const char *host_version);
239 
240 /**
241  * pld_snoc_wlan_disable() - Disable WLAN
242  * @dev: device
243  * @mode: WLAN mode
244  *
245  * This function disables WLAN FW. It passes WLAN mode to FW.
246  *
247  * Return: 0 for success
248  *         Non zero failure code for errors
249  */
250 int pld_snoc_wlan_disable(struct device *dev, enum pld_driver_mode mode);
251 
252 /**
253  * pld_snoc_get_soc_info() - Get SOC information
254  * @dev: device
255  * @info: buffer to SOC information
256  *
257  * Return SOC info to the buffer.
258  *
259  * Return: 0 for success
260  *         Non zero failure code for errors
261  */
262 int pld_snoc_get_soc_info(struct device *dev, struct pld_soc_info *info);
263 
264 #ifdef FEATURE_WLAN_TIME_SYNC_FTM
265 /**
266  * pld_snoc_get_audio_wlan_timestamp() - Get audio timestamp
267  * @dev: device
268  * @type: trigger type
269  * @ts: timestamp
270  *
271  * Return audio timestamp to the ts.
272  *
273  * Return: 0 for success
274  *         Non zero failure code for errors
275  */
276 static inline int
pld_snoc_get_audio_wlan_timestamp(struct device * dev,enum pld_wlan_time_sync_trigger_type type,uint64_t * ts)277 pld_snoc_get_audio_wlan_timestamp(struct device *dev,
278 				  enum pld_wlan_time_sync_trigger_type type,
279 				  uint64_t *ts)
280 {
281 	if (!dev)
282 		return -ENODEV;
283 
284 	return 0;
285 }
286 #endif /* FEATURE_WLAN_TIME_SYNC_FTM */
pld_snoc_ce_request_irq(struct device * dev,unsigned int ce_id,irqreturn_t (* handler)(int,void *),unsigned long flags,const char * name,void * ctx)287 static inline int pld_snoc_ce_request_irq(struct device *dev,
288 					  unsigned int ce_id,
289 					  irqreturn_t (*handler)(int, void *),
290 					  unsigned long flags,
291 					  const char *name, void *ctx)
292 {
293 	if (!dev)
294 		return -ENODEV;
295 
296 	return icnss_ce_request_irq(dev, ce_id, handler, flags, name, ctx);
297 }
298 
pld_snoc_ce_free_irq(struct device * dev,unsigned int ce_id,void * ctx)299 static inline int pld_snoc_ce_free_irq(struct device *dev,
300 				       unsigned int ce_id, void *ctx)
301 {
302 	if (!dev)
303 		return -ENODEV;
304 
305 	return icnss_ce_free_irq(dev, ce_id, ctx);
306 }
307 
pld_snoc_enable_irq(struct device * dev,unsigned int ce_id)308 static inline void pld_snoc_enable_irq(struct device *dev, unsigned int ce_id)
309 {
310 	if (dev)
311 		icnss_enable_irq(dev, ce_id);
312 }
313 
pld_snoc_disable_irq(struct device * dev,unsigned int ce_id)314 static inline void pld_snoc_disable_irq(struct device *dev, unsigned int ce_id)
315 {
316 	if (dev)
317 		icnss_disable_irq(dev, ce_id);
318 }
319 
pld_snoc_get_ce_id(struct device * dev,int irq)320 static inline int pld_snoc_get_ce_id(struct device *dev, int irq)
321 {
322 	if (!dev)
323 		return -ENODEV;
324 
325 	return icnss_get_ce_id(dev, irq);
326 }
327 
pld_snoc_get_irq(struct device * dev,int ce_id)328 static inline int pld_snoc_get_irq(struct device *dev, int ce_id)
329 {
330 	if (!dev)
331 		return -ENODEV;
332 
333 	return icnss_get_irq(dev, ce_id);
334 }
335 
pld_snoc_power_on(struct device * dev)336 static inline int pld_snoc_power_on(struct device *dev)
337 {
338 	return icnss_power_on(dev);
339 }
pld_snoc_power_off(struct device * dev)340 static inline int pld_snoc_power_off(struct device *dev)
341 {
342 	return icnss_power_off(dev);
343 }
pld_snoc_athdiag_read(struct device * dev,uint32_t offset,uint32_t memtype,uint32_t datalen,uint8_t * output)344 static inline int pld_snoc_athdiag_read(struct device *dev, uint32_t offset,
345 					uint32_t memtype, uint32_t datalen,
346 					uint8_t *output)
347 {
348 	return icnss_athdiag_read(dev, offset, memtype, datalen, output);
349 }
pld_snoc_athdiag_write(struct device * dev,uint32_t offset,uint32_t memtype,uint32_t datalen,uint8_t * input)350 static inline int pld_snoc_athdiag_write(struct device *dev, uint32_t offset,
351 					 uint32_t memtype, uint32_t datalen,
352 					 uint8_t *input)
353 {
354 	return icnss_athdiag_write(dev, offset, memtype, datalen, input);
355 }
356 
357 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0))
pld_snoc_smmu_get_domain(struct device * dev)358 static inline void *pld_snoc_smmu_get_domain(struct device *dev)
359 {
360 	return icnss_smmu_get_domain(dev);
361 }
362 
363 #else
pld_snoc_smmu_get_mapping(struct device * dev)364 static inline void *pld_snoc_smmu_get_mapping(struct device *dev)
365 {
366 	return icnss_smmu_get_mapping(dev);
367 }
368 #endif
369 
pld_snoc_smmu_map(struct device * dev,phys_addr_t paddr,uint32_t * iova_addr,size_t size)370 static inline int pld_snoc_smmu_map(struct device *dev, phys_addr_t paddr,
371 				    uint32_t *iova_addr, size_t size)
372 {
373 	return icnss_smmu_map(dev, paddr, iova_addr, size);
374 }
375 
376 #ifdef CONFIG_SMMU_S1_UNMAP
pld_snoc_smmu_unmap(struct device * dev,uint32_t iova_addr,size_t size)377 static inline int pld_snoc_smmu_unmap(struct device *dev,
378 				      uint32_t iova_addr, size_t size)
379 {
380 	return icnss_smmu_unmap(dev, iova_addr, size);
381 }
382 
383 #else
pld_snoc_smmu_unmap(struct device * dev,uint32_t iova_addr,size_t size)384 static inline int pld_snoc_smmu_unmap(struct device *dev,
385 				      uint32_t iova_addr, size_t size)
386 {
387 	return 0;
388 }
389 #endif
390 
391 static inline
pld_snoc_socinfo_get_serial_number(struct device * dev)392 unsigned int pld_snoc_socinfo_get_serial_number(struct device *dev)
393 {
394 	return icnss_socinfo_get_serial_number(dev);
395 }
396 
pld_snoc_is_fw_down(struct device * dev)397 static inline int pld_snoc_is_fw_down(struct device *dev)
398 {
399 	return icnss_is_fw_down();
400 }
401 
402 #ifdef CONFIG_ENABLE_LOW_POWER_MODE
pld_snoc_is_low_power_mode(struct device * dev)403 static inline int pld_snoc_is_low_power_mode(struct device *dev)
404 {
405 	return icnss_is_low_power();
406 }
407 #else
pld_snoc_is_low_power_mode(struct device * dev)408 static inline int pld_snoc_is_low_power_mode(struct device *dev)
409 {
410 	return 0;
411 }
412 #endif
413 
pld_snoc_is_qmi_disable(struct device * dev)414 static inline int pld_snoc_is_qmi_disable(struct device *dev)
415 {
416 	if (!dev)
417 		return -ENODEV;
418 
419 	return icnss_is_qmi_disable(dev);
420 }
421 
pld_snoc_set_fw_log_mode(struct device * dev,u8 fw_log_mode)422 static inline int pld_snoc_set_fw_log_mode(struct device *dev, u8 fw_log_mode)
423 {
424 	if (!dev)
425 		return -ENODEV;
426 
427 	return icnss_set_fw_log_mode(dev, fw_log_mode);
428 }
429 
pld_snoc_force_assert_target(struct device * dev)430 static inline int pld_snoc_force_assert_target(struct device *dev)
431 {
432 	return icnss_trigger_recovery(dev);
433 }
434 
pld_snoc_is_pdr(void)435 static inline int pld_snoc_is_pdr(void)
436 {
437 	return icnss_is_pdr();
438 }
439 
pld_snoc_is_fw_rejuvenate(void)440 static inline int pld_snoc_is_fw_rejuvenate(void)
441 {
442 	return icnss_is_rejuvenate();
443 }
444 
pld_snoc_block_shutdown(bool status)445 static inline void pld_snoc_block_shutdown(bool status)
446 {
447 	icnss_block_shutdown(status);
448 }
449 
pld_snoc_idle_restart(struct device * dev)450 static inline int pld_snoc_idle_restart(struct device *dev)
451 {
452 	return icnss_idle_restart(dev);
453 }
454 
pld_snoc_idle_shutdown(struct device * dev)455 static inline int pld_snoc_idle_shutdown(struct device *dev)
456 {
457 	return icnss_idle_shutdown(dev);
458 }
459 
pld_snoc_get_device_config(void)460 static inline unsigned long pld_snoc_get_device_config(void)
461 {
462 	return icnss_get_device_config();
463 }
464 #endif
465 #endif
466