xref: /wlan-dirver/qca-wifi-host-cmn/hif/src/hif_io32.h (revision fffcebf2e926a46534518e770b63d1ab6574e139)
1 /*
2  * Copyright (c) 2015-2017 The Linux Foundation. All rights reserved.
3  *
4  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5  *
6  *
7  * Permission to use, copy, modify, and/or distribute this software for
8  * any purpose with or without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19  * PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27 
28 #ifndef __HIF_IO32_H__
29 #define __HIF_IO32_H__
30 
31 #include <linux/io.h>
32 #include "hif.h"
33 #include "hif_main.h"
34 
35 #define hif_read32_mb(addr)         ioread32((void __iomem *)addr)
36 #define hif_write32_mb(addr, value) \
37 	iowrite32((u32)(value), (void __iomem *)(addr))
38 
39 #define Q_TARGET_ACCESS_BEGIN(scn) \
40 	hif_target_sleep_state_adjust(scn, false, true)
41 #define Q_TARGET_ACCESS_END(scn) \
42 	hif_target_sleep_state_adjust(scn, true, false)
43 #define TARGET_REGISTER_ACCESS_ALLOWED(scn)\
44 		hif_is_target_register_access_allowed(scn)
45 
46 /*
47  * A_TARGET_ACCESS_LIKELY will not wait for the target to wake up before
48  * continuing execution.  Because A_TARGET_ACCESS_LIKELY does not guarantee
49  * that the target is awake before continuing, Q_TARGET_ACCESS macros must
50  * protect the actual target access.  Since Q_TARGET_ACCESS protect the actual
51  * target access, A_TARGET_ACCESS_LIKELY hints are optional.
52  *
53  * To ignore "LIKELY" hints, set CONFIG_TARGET_ACCESS_LIKELY to 0
54  * (slightly worse performance, less power)
55  *
56  * To use "LIKELY" hints, set CONFIG_TARGET_ACCESS_LIKELY to 1
57  * (slightly better performance, more power)
58  *
59  * note: if a bus doesn't use hif_target_sleep_state_adjust, this will have
60  * no impact.
61  */
62 #define CONFIG_TARGET_ACCESS_LIKELY 0
63 #if CONFIG_TARGET_ACCESS_LIKELY
64 #define A_TARGET_ACCESS_LIKELY(scn) \
65 	hif_target_sleep_state_adjust(scn, false, false)
66 #define A_TARGET_ACCESS_UNLIKELY(scn) \
67 	hif_target_sleep_state_adjust(scn, true, false)
68 #else                           /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
69 #define A_TARGET_ACCESS_LIKELY(scn) \
70 	do { \
71 		unsigned long unused = (unsigned long)(scn); \
72 		unused = unused; \
73 	} while (0)
74 
75 #define A_TARGET_ACCESS_UNLIKELY(scn) \
76 	do { \
77 		unsigned long unused = (unsigned long)(scn); \
78 		unused = unused; \
79 	} while (0)
80 #endif /* CONFIG_ATH_PCIE_ACCESS_LIKELY */
81 
82 
83 #ifdef HIF_PCI
84 #include "hif_io32_pci.h"
85 #endif
86 #ifdef HIF_SNOC
87 #include "hif_io32_snoc.h"
88 #endif /* HIF_PCI */
89 
90 #ifdef CONFIG_IO_MEM_ACCESS_DEBUG
91 uint32_t hif_target_read_checked(struct hif_softc *scn,
92 					uint32_t offset);
93 void hif_target_write_checked(struct hif_softc *scn, uint32_t offset,
94 				     uint32_t value);
95 
96 #define A_TARGET_READ(scn, offset) \
97 	hif_target_read_checked(scn, (offset))
98 #define A_TARGET_WRITE(scn, offset, value) \
99 	hif_target_write_checked(scn, (offset), (value))
100 #else                           /* CONFIG_ATH_PCIE_ACCESS_DEBUG */
101 #define A_TARGET_READ(scn, offset) \
102 	hif_read32_mb(scn->mem + (offset))
103 #define A_TARGET_WRITE(scn, offset, value) \
104 	hif_write32_mb((scn->mem) + (offset), value)
105 #endif
106 
107 void hif_irq_enable(struct hif_softc *scn, int irq_id);
108 void hif_irq_disable(struct hif_softc *scn, int irq_id);
109 
110 #endif /* __HIF_IO32_H__ */
111