1 /* SPDX-License-Identifier: BSD-3-Clause-Clear */
2 /*
3 * Copyright (c) 2019-2020 The Linux Foundation. All rights reserved.
4 * Copyright (c) 2022-2024 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 };
35
ath11k_hif_ce_irq_enable(struct ath11k_base * ab)36 static inline void ath11k_hif_ce_irq_enable(struct ath11k_base *ab)
37 {
38 if (ab->hif.ops->ce_irq_enable)
39 ab->hif.ops->ce_irq_enable(ab);
40 }
41
ath11k_hif_ce_irq_disable(struct ath11k_base * ab)42 static inline void ath11k_hif_ce_irq_disable(struct ath11k_base *ab)
43 {
44 if (ab->hif.ops->ce_irq_disable)
45 ab->hif.ops->ce_irq_disable(ab);
46 }
47
ath11k_hif_start(struct ath11k_base * ab)48 static inline int ath11k_hif_start(struct ath11k_base *ab)
49 {
50 return ab->hif.ops->start(ab);
51 }
52
ath11k_hif_stop(struct ath11k_base * ab)53 static inline void ath11k_hif_stop(struct ath11k_base *ab)
54 {
55 ab->hif.ops->stop(ab);
56 }
57
ath11k_hif_irq_enable(struct ath11k_base * ab)58 static inline void ath11k_hif_irq_enable(struct ath11k_base *ab)
59 {
60 ab->hif.ops->irq_enable(ab);
61 }
62
ath11k_hif_irq_disable(struct ath11k_base * ab)63 static inline void ath11k_hif_irq_disable(struct ath11k_base *ab)
64 {
65 ab->hif.ops->irq_disable(ab);
66 }
67
ath11k_hif_power_up(struct ath11k_base * ab)68 static inline int ath11k_hif_power_up(struct ath11k_base *ab)
69 {
70 if (!ab->hif.ops->power_up)
71 return -EOPNOTSUPP;
72
73 return ab->hif.ops->power_up(ab);
74 }
75
ath11k_hif_power_down(struct ath11k_base * ab,bool is_suspend)76 static inline void ath11k_hif_power_down(struct ath11k_base *ab, bool is_suspend)
77 {
78 if (!ab->hif.ops->power_down)
79 return;
80
81 ab->hif.ops->power_down(ab, is_suspend);
82 }
83
ath11k_hif_suspend(struct ath11k_base * ab)84 static inline int ath11k_hif_suspend(struct ath11k_base *ab)
85 {
86 if (ab->hif.ops->suspend)
87 return ab->hif.ops->suspend(ab);
88
89 return 0;
90 }
91
ath11k_hif_resume(struct ath11k_base * ab)92 static inline int ath11k_hif_resume(struct ath11k_base *ab)
93 {
94 if (ab->hif.ops->resume)
95 return ab->hif.ops->resume(ab);
96
97 return 0;
98 }
99
ath11k_hif_read32(struct ath11k_base * ab,u32 address)100 static inline u32 ath11k_hif_read32(struct ath11k_base *ab, u32 address)
101 {
102 return ab->hif.ops->read32(ab, address);
103 }
104
ath11k_hif_write32(struct ath11k_base * ab,u32 address,u32 data)105 static inline void ath11k_hif_write32(struct ath11k_base *ab, u32 address, u32 data)
106 {
107 ab->hif.ops->write32(ab, address, data);
108 }
109
ath11k_hif_read(struct ath11k_base * ab,void * buf,u32 start,u32 end)110 static inline int ath11k_hif_read(struct ath11k_base *ab, void *buf,
111 u32 start, u32 end)
112 {
113 if (!ab->hif.ops->read)
114 return -EOPNOTSUPP;
115
116 return ab->hif.ops->read(ab, buf, start, end);
117 }
118
ath11k_hif_map_service_to_pipe(struct ath11k_base * ab,u16 service_id,u8 * ul_pipe,u8 * dl_pipe)119 static inline int ath11k_hif_map_service_to_pipe(struct ath11k_base *ab, u16 service_id,
120 u8 *ul_pipe, u8 *dl_pipe)
121 {
122 return ab->hif.ops->map_service_to_pipe(ab, service_id, ul_pipe, dl_pipe);
123 }
124
ath11k_get_user_msi_vector(struct ath11k_base * ab,char * user_name,int * num_vectors,u32 * user_base_data,u32 * base_vector)125 static inline int ath11k_get_user_msi_vector(struct ath11k_base *ab, char *user_name,
126 int *num_vectors, u32 *user_base_data,
127 u32 *base_vector)
128 {
129 if (!ab->hif.ops->get_user_msi_vector)
130 return -EOPNOTSUPP;
131
132 return ab->hif.ops->get_user_msi_vector(ab, user_name, num_vectors,
133 user_base_data,
134 base_vector);
135 }
136
ath11k_get_msi_address(struct ath11k_base * ab,u32 * msi_addr_lo,u32 * msi_addr_hi)137 static inline void ath11k_get_msi_address(struct ath11k_base *ab, u32 *msi_addr_lo,
138 u32 *msi_addr_hi)
139 {
140 if (!ab->hif.ops->get_msi_address)
141 return;
142
143 ab->hif.ops->get_msi_address(ab, msi_addr_lo, msi_addr_hi);
144 }
145
ath11k_get_ce_msi_idx(struct ath11k_base * ab,u32 ce_id,u32 * msi_data_idx)146 static inline void ath11k_get_ce_msi_idx(struct ath11k_base *ab, u32 ce_id,
147 u32 *msi_data_idx)
148 {
149 if (ab->hif.ops->get_ce_msi_idx)
150 ab->hif.ops->get_ce_msi_idx(ab, ce_id, msi_data_idx);
151 else
152 *msi_data_idx = ce_id;
153 }
154
155 #endif /* _HIF_H_ */
156