xref: /linux/drivers/net/wireless/ath/ath12k/hif.h (revision ed7171ff9fabc49ae6ed42fbd082a576473836fc)
1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3  * Copyright (c) 2019-2021 The Linux Foundation. All rights reserved.
4  * Copyright (c) 2021-2024 Qualcomm Innovation Center, Inc. All rights reserved.
5  */
6 
7 #ifndef ATH12K_HIF_H
8 #define ATH12K_HIF_H
9 
10 #include "core.h"
11 
12 struct ath12k_hif_ops {
13 	u32 (*read32)(struct ath12k_base *ab, u32 address);
14 	void (*write32)(struct ath12k_base *ab, u32 address, u32 data);
15 	void (*irq_enable)(struct ath12k_base *ab);
16 	void (*irq_disable)(struct ath12k_base *ab);
17 	int (*start)(struct ath12k_base *ab);
18 	void (*stop)(struct ath12k_base *ab);
19 	int (*power_up)(struct ath12k_base *ab);
20 	void (*power_down)(struct ath12k_base *ab, bool is_suspend);
21 	int (*suspend)(struct ath12k_base *ab);
22 	int (*resume)(struct ath12k_base *ab);
23 	int (*map_service_to_pipe)(struct ath12k_base *ab, u16 service_id,
24 				   u8 *ul_pipe, u8 *dl_pipe);
25 	int (*get_user_msi_vector)(struct ath12k_base *ab, char *user_name,
26 				   int *num_vectors, u32 *user_base_data,
27 				   u32 *base_vector);
28 	void (*get_msi_address)(struct ath12k_base *ab, u32 *msi_addr_lo,
29 				u32 *msi_addr_hi);
30 	void (*ce_irq_enable)(struct ath12k_base *ab);
31 	void (*ce_irq_disable)(struct ath12k_base *ab);
32 	void (*get_ce_msi_idx)(struct ath12k_base *ab, u32 ce_id, u32 *msi_idx);
33 	int (*panic_handler)(struct ath12k_base *ab);
34 };
35 
36 static inline int ath12k_hif_map_service_to_pipe(struct ath12k_base *ab, u16 service_id,
37 						 u8 *ul_pipe, u8 *dl_pipe)
38 {
39 	return ab->hif.ops->map_service_to_pipe(ab, service_id,
40 						ul_pipe, dl_pipe);
41 }
42 
43 static inline int ath12k_hif_get_user_msi_vector(struct ath12k_base *ab,
44 						 char *user_name,
45 						 int *num_vectors,
46 						 u32 *user_base_data,
47 						 u32 *base_vector)
48 {
49 	if (!ab->hif.ops->get_user_msi_vector)
50 		return -EOPNOTSUPP;
51 
52 	return ab->hif.ops->get_user_msi_vector(ab, user_name, num_vectors,
53 						user_base_data,
54 						base_vector);
55 }
56 
57 static inline void ath12k_hif_get_msi_address(struct ath12k_base *ab,
58 					      u32 *msi_addr_lo,
59 					      u32 *msi_addr_hi)
60 {
61 	if (!ab->hif.ops->get_msi_address)
62 		return;
63 
64 	ab->hif.ops->get_msi_address(ab, msi_addr_lo, msi_addr_hi);
65 }
66 
67 static inline void ath12k_hif_get_ce_msi_idx(struct ath12k_base *ab, u32 ce_id,
68 					     u32 *msi_data_idx)
69 {
70 	if (ab->hif.ops->get_ce_msi_idx)
71 		ab->hif.ops->get_ce_msi_idx(ab, ce_id, msi_data_idx);
72 	else
73 		*msi_data_idx = ce_id;
74 }
75 
76 static inline void ath12k_hif_ce_irq_enable(struct ath12k_base *ab)
77 {
78 	if (ab->hif.ops->ce_irq_enable)
79 		ab->hif.ops->ce_irq_enable(ab);
80 }
81 
82 static inline void ath12k_hif_ce_irq_disable(struct ath12k_base *ab)
83 {
84 	if (ab->hif.ops->ce_irq_disable)
85 		ab->hif.ops->ce_irq_disable(ab);
86 }
87 
88 static inline void ath12k_hif_irq_enable(struct ath12k_base *ab)
89 {
90 	ab->hif.ops->irq_enable(ab);
91 }
92 
93 static inline void ath12k_hif_irq_disable(struct ath12k_base *ab)
94 {
95 	ab->hif.ops->irq_disable(ab);
96 }
97 
98 static inline int ath12k_hif_suspend(struct ath12k_base *ab)
99 {
100 	if (ab->hif.ops->suspend)
101 		return ab->hif.ops->suspend(ab);
102 
103 	return 0;
104 }
105 
106 static inline int ath12k_hif_resume(struct ath12k_base *ab)
107 {
108 	if (ab->hif.ops->resume)
109 		return ab->hif.ops->resume(ab);
110 
111 	return 0;
112 }
113 
114 static inline int ath12k_hif_start(struct ath12k_base *ab)
115 {
116 	return ab->hif.ops->start(ab);
117 }
118 
119 static inline void ath12k_hif_stop(struct ath12k_base *ab)
120 {
121 	ab->hif.ops->stop(ab);
122 }
123 
124 static inline u32 ath12k_hif_read32(struct ath12k_base *ab, u32 address)
125 {
126 	return ab->hif.ops->read32(ab, address);
127 }
128 
129 static inline void ath12k_hif_write32(struct ath12k_base *ab, u32 address,
130 				      u32 data)
131 {
132 	ab->hif.ops->write32(ab, address, data);
133 }
134 
135 static inline int ath12k_hif_power_up(struct ath12k_base *ab)
136 {
137 	if (!ab->hif.ops->power_up)
138 		return -EOPNOTSUPP;
139 
140 	return ab->hif.ops->power_up(ab);
141 }
142 
143 static inline void ath12k_hif_power_down(struct ath12k_base *ab, bool is_suspend)
144 {
145 	if (!ab->hif.ops->power_down)
146 		return;
147 
148 	ab->hif.ops->power_down(ab, is_suspend);
149 }
150 
151 static inline int ath12k_hif_panic_handler(struct ath12k_base *ab)
152 {
153 	if (!ab->hif.ops->panic_handler)
154 		return NOTIFY_DONE;
155 
156 	return ab->hif.ops->panic_handler(ab);
157 }
158 
159 #endif /* ATH12K_HIF_H */
160