xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/hif_io32.h (revision 4865edfd190c086bbe2c69aae12a8226f877b91e) !
1 /*
2  * Copyright (c) 2015-2017 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 #ifndef __HIF_IO32_H__
20 #define __HIF_IO32_H__
21 
22 #include <linux/io.h>
23 #include "hif.h"
24 #include "hif_main.h"
25 
26 #define hif_read32_mb(addr)         ioread32((void __iomem *)addr)
27 #define hif_write32_mb(addr, value) \
28 	iowrite32((u32)(value), (void __iomem *)(addr))
29 
30 #define Q_TARGET_ACCESS_BEGIN(scn) \
31 	hif_target_sleep_state_adjust(scn, false, true)
32 #define Q_TARGET_ACCESS_END(scn) \
33 	hif_target_sleep_state_adjust(scn, true, false)
34 #define TARGET_REGISTER_ACCESS_ALLOWED(scn)\
35 		hif_is_target_register_access_allowed(scn)
36 
37 /*
38  * A_TARGET_ACCESS_LIKELY will not wait for the target to wake up before
39  * continuing execution.  Because A_TARGET_ACCESS_LIKELY does not guarantee
40  * that the target is awake before continuing, Q_TARGET_ACCESS macros must
41  * protect the actual target access.  Since Q_TARGET_ACCESS protect the actual
42  * target access, A_TARGET_ACCESS_LIKELY hints are optional.
43  *
44  * To ignore "LIKELY" hints, set CONFIG_TARGET_ACCESS_LIKELY to 0
45  * (slightly worse performance, less power)
46  *
47  * To use "LIKELY" hints, set CONFIG_TARGET_ACCESS_LIKELY to 1
48  * (slightly better performance, more power)
49  *
50  * note: if a bus doesn't use hif_target_sleep_state_adjust, this will have
51  * no impact.
52  */
53 #define CONFIG_TARGET_ACCESS_LIKELY 0
54 #if CONFIG_TARGET_ACCESS_LIKELY
55 #define A_TARGET_ACCESS_LIKELY(scn) \
56 	hif_target_sleep_state_adjust(scn, false, false)
57 #define A_TARGET_ACCESS_UNLIKELY(scn) \
58 	hif_target_sleep_state_adjust(scn, true, false)
59 #else                           /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
60 #define A_TARGET_ACCESS_LIKELY(scn) \
61 	do { \
62 		unsigned long unused = (unsigned long)(scn); \
63 		unused = unused; \
64 	} while (0)
65 
66 #define A_TARGET_ACCESS_UNLIKELY(scn) \
67 	do { \
68 		unsigned long unused = (unsigned long)(scn); \
69 		unused = unused; \
70 	} while (0)
71 #endif /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
72 
73 
74 #ifdef HIF_PCI
75 #include "hif_io32_pci.h"
76 #endif
77 #ifdef HIF_SNOC
78 #include "hif_io32_snoc.h"
79 #endif /* HIF_PCI */
80 
81 #ifdef CONFIG_IO_MEM_ACCESS_DEBUG
82 uint32_t hif_target_read_checked(struct hif_softc *scn,
83 					uint32_t offset);
84 void hif_target_write_checked(struct hif_softc *scn, uint32_t offset,
85 				     uint32_t value);
86 
87 #define A_TARGET_READ(scn, offset) \
88 	hif_target_read_checked(scn, (offset))
89 #define A_TARGET_WRITE(scn, offset, value) \
90 	hif_target_write_checked(scn, (offset), (value))
91 #else                           /* CONFIG_ATH_PCIE_ACCESS_DEBUG */
92 #define A_TARGET_READ(scn, offset) \
93 	hif_read32_mb(scn->mem + (offset))
94 #define A_TARGET_WRITE(scn, offset, value) \
95 	hif_write32_mb((scn->mem) + (offset), value)
96 #endif
97 
98 void hif_irq_enable(struct hif_softc *scn, int irq_id);
99 void hif_irq_disable(struct hif_softc *scn, int irq_id);
100 
101 #endif /* __HIF_IO32_H__ */
102