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