xref: /openbmc/linux/drivers/net/wireless/ath/ath11k/ahb.c (revision 1ff8ed78)
1d5c65159SKalle Valo // SPDX-License-Identifier: BSD-3-Clause-Clear
2d5c65159SKalle Valo /*
3d5c65159SKalle Valo  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4d5c65159SKalle Valo  */
5d5c65159SKalle Valo 
6d5c65159SKalle Valo #include <linux/module.h>
7d5c65159SKalle Valo #include <linux/platform_device.h>
8d5c65159SKalle Valo #include <linux/of_device.h>
9d5c65159SKalle Valo #include <linux/of.h>
10d5c65159SKalle Valo #include <linux/dma-mapping.h>
11d5c65159SKalle Valo #include "ahb.h"
12d5c65159SKalle Valo #include "debug.h"
1331858805SGovind Singh #include "hif.h"
14d5c65159SKalle Valo #include <linux/remoteproc.h>
15d5c65159SKalle Valo 
16d5c65159SKalle Valo static const struct of_device_id ath11k_ahb_of_match[] = {
17d5c65159SKalle Valo 	/* TODO: Should we change the compatible string to something similar
18d5c65159SKalle Valo 	 * to one that ath10k uses?
19d5c65159SKalle Valo 	 */
20d5c65159SKalle Valo 	{ .compatible = "qcom,ipq8074-wifi",
21d5c65159SKalle Valo 	  .data = (void *)ATH11K_HW_IPQ8074,
22d5c65159SKalle Valo 	},
23d5c65159SKalle Valo 	{ }
24d5c65159SKalle Valo };
25d5c65159SKalle Valo 
26d5c65159SKalle Valo MODULE_DEVICE_TABLE(of, ath11k_ahb_of_match);
27d5c65159SKalle Valo 
281ff8ed78SGovind Singh static const struct ath11k_bus_params ath11k_ahb_bus_params = {
291ff8ed78SGovind Singh 	.mhi_support = false,
301ff8ed78SGovind Singh };
311ff8ed78SGovind Singh 
32d5c65159SKalle Valo /* Target firmware's Copy Engine configuration. */
33d5c65159SKalle Valo static const struct ce_pipe_config target_ce_config_wlan[] = {
34d5c65159SKalle Valo 	/* CE0: host->target HTC control and raw streams */
35d5c65159SKalle Valo 	{
36d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(0),
37d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),
38d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
39d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(2048),
40d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
41d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
42d5c65159SKalle Valo 	},
43d5c65159SKalle Valo 
44d5c65159SKalle Valo 	/* CE1: target->host HTT + HTC control */
45d5c65159SKalle Valo 	{
46d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(1),
47d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),
48d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
49d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(2048),
50d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
51d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
52d5c65159SKalle Valo 	},
53d5c65159SKalle Valo 
54d5c65159SKalle Valo 	/* CE2: target->host WMI */
55d5c65159SKalle Valo 	{
56d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
57d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),
58d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
59d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(2048),
60d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
61d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
62d5c65159SKalle Valo 	},
63d5c65159SKalle Valo 
64d5c65159SKalle Valo 	/* CE3: host->target WMI */
65d5c65159SKalle Valo 	{
66d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(3),
67d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),
68d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
69d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(2048),
70d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
71d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
72d5c65159SKalle Valo 	},
73d5c65159SKalle Valo 
74d5c65159SKalle Valo 	/* CE4: host->target HTT */
75d5c65159SKalle Valo 	{
76d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(4),
77d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),
78d5c65159SKalle Valo 		.nentries = __cpu_to_le32(256),
79d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(256),
80d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
81d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
82d5c65159SKalle Valo 	},
83d5c65159SKalle Valo 
84d5c65159SKalle Valo 	/* CE5: target->host Pktlog */
85d5c65159SKalle Valo 	{
86d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(5),
87d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),
88d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
89d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(2048),
90d5c65159SKalle Valo 		.flags = __cpu_to_le32(0),
91d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
92d5c65159SKalle Valo 	},
93d5c65159SKalle Valo 
94d5c65159SKalle Valo 	/* CE6: Reserved for target autonomous hif_memcpy */
95d5c65159SKalle Valo 	{
96d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(6),
97d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_INOUT),
98d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
99d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(65535),
100d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
101d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
102d5c65159SKalle Valo 	},
103d5c65159SKalle Valo 
104d5c65159SKalle Valo 	/* CE7 used only by Host */
105d5c65159SKalle Valo 	{
106d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(7),
107d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),
108d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
109d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(2048),
110d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
111d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
112d5c65159SKalle Valo 	},
113d5c65159SKalle Valo 
114d5c65159SKalle Valo 	/* CE8 target->host used only by IPA */
115d5c65159SKalle Valo 	{
116d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(8),
117d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_INOUT),
118d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
119d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(65535),
120d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
121d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
122d5c65159SKalle Valo 	},
123d5c65159SKalle Valo 
124d5c65159SKalle Valo 	/* CE9 host->target HTT */
125d5c65159SKalle Valo 	{
126d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(9),
127d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),
128d5c65159SKalle Valo 		.nentries = __cpu_to_le32(32),
129d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(2048),
130d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
131d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
132d5c65159SKalle Valo 	},
133d5c65159SKalle Valo 
134d5c65159SKalle Valo 	/* CE10 target->host HTT */
135d5c65159SKalle Valo 	{
136d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(10),
137d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_INOUT_H2H),
138d5c65159SKalle Valo 		.nentries = __cpu_to_le32(0),
139d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(0),
140d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
141d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
142d5c65159SKalle Valo 	},
143d5c65159SKalle Valo 
144d5c65159SKalle Valo 	/* CE11 Not used */
145d5c65159SKalle Valo 	{
146d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(0),
147d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(0),
148d5c65159SKalle Valo 		.nentries = __cpu_to_le32(0),
149d5c65159SKalle Valo 		.nbytes_max = __cpu_to_le32(0),
150d5c65159SKalle Valo 		.flags = __cpu_to_le32(CE_ATTR_FLAGS),
151d5c65159SKalle Valo 		.reserved = __cpu_to_le32(0),
152d5c65159SKalle Valo 	},
153d5c65159SKalle Valo };
154d5c65159SKalle Valo 
155d5c65159SKalle Valo /* Map from service/endpoint to Copy Engine.
156d5c65159SKalle Valo  * This table is derived from the CE_PCI TABLE, above.
157d5c65159SKalle Valo  * It is passed to the Target at startup for use by firmware.
158d5c65159SKalle Valo  */
159d5c65159SKalle Valo static const struct service_to_pipe target_service_to_ce_map_wlan[] = {
160d5c65159SKalle Valo 	{
161d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_VO),
162d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
163d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(3),
164d5c65159SKalle Valo 	},
165d5c65159SKalle Valo 	{
166d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_VO),
167d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
168d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
169d5c65159SKalle Valo 	},
170d5c65159SKalle Valo 	{
171d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_BK),
172d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
173d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(3),
174d5c65159SKalle Valo 	},
175d5c65159SKalle Valo 	{
176d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_BK),
177d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
178d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
179d5c65159SKalle Valo 	},
180d5c65159SKalle Valo 	{
181d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_BE),
182d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
183d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(3),
184d5c65159SKalle Valo 	},
185d5c65159SKalle Valo 	{
186d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_BE),
187d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
188d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
189d5c65159SKalle Valo 	},
190d5c65159SKalle Valo 	{
191d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_VI),
192d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
193d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(3),
194d5c65159SKalle Valo 	},
195d5c65159SKalle Valo 	{
196d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_DATA_VI),
197d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
198d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
199d5c65159SKalle Valo 	},
200d5c65159SKalle Valo 	{
201d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_CONTROL),
202d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
203d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(3),
204d5c65159SKalle Valo 	},
205d5c65159SKalle Valo 	{
206d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_CONTROL),
207d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
208d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
209d5c65159SKalle Valo 	},
210d5c65159SKalle Valo 	{
211d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1),
212d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
213d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(7),
214d5c65159SKalle Valo 	},
215d5c65159SKalle Valo 	{
216d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC1),
217d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
218d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
219d5c65159SKalle Valo 	},
220d5c65159SKalle Valo 	{
221d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2),
222d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
223d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(9),
224d5c65159SKalle Valo 	},
225d5c65159SKalle Valo 	{
226d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_WMI_CONTROL_MAC2),
227d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
228d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(2),
229d5c65159SKalle Valo 	},
230d5c65159SKalle Valo 	{
231d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_RSVD_CTRL),
232d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
233d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(0),
234d5c65159SKalle Valo 	},
235d5c65159SKalle Valo 	{
236d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_RSVD_CTRL),
237d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
238d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(1),
239d5c65159SKalle Valo 	},
240d5c65159SKalle Valo 	{ /* not used */
241d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS),
242d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
243d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(0),
244d5c65159SKalle Valo 	},
245d5c65159SKalle Valo 	{ /* not used */
246d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_TEST_RAW_STREAMS),
247d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
248d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(1),
249d5c65159SKalle Valo 	},
250d5c65159SKalle Valo 	{
251d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_HTT_DATA_MSG),
252d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_OUT),	/* out = UL = host -> target */
253d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(4),
254d5c65159SKalle Valo 	},
255d5c65159SKalle Valo 	{
256d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_HTT_DATA_MSG),
257d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
258d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(1),
259d5c65159SKalle Valo 	},
260d5c65159SKalle Valo 	{
261d5c65159SKalle Valo 		.service_id = __cpu_to_le32(ATH11K_HTC_SVC_ID_PKT_LOG),
262d5c65159SKalle Valo 		.pipedir = __cpu_to_le32(PIPEDIR_IN),	/* in = DL = target -> host */
263d5c65159SKalle Valo 		.pipenum = __cpu_to_le32(5),
264d5c65159SKalle Valo 	},
265d5c65159SKalle Valo 
266d5c65159SKalle Valo 	/* (Additions here) */
267d5c65159SKalle Valo 
268d5c65159SKalle Valo 	{ /* terminator entry */ }
269d5c65159SKalle Valo };
270d5c65159SKalle Valo 
271d5c65159SKalle Valo #define ATH11K_IRQ_CE0_OFFSET 4
272d5c65159SKalle Valo 
273d5c65159SKalle Valo static const char *irq_name[ATH11K_IRQ_NUM_MAX] = {
274d5c65159SKalle Valo 	"misc-pulse1",
275d5c65159SKalle Valo 	"misc-latch",
276d5c65159SKalle Valo 	"sw-exception",
277d5c65159SKalle Valo 	"watchdog",
278d5c65159SKalle Valo 	"ce0",
279d5c65159SKalle Valo 	"ce1",
280d5c65159SKalle Valo 	"ce2",
281d5c65159SKalle Valo 	"ce3",
282d5c65159SKalle Valo 	"ce4",
283d5c65159SKalle Valo 	"ce5",
284d5c65159SKalle Valo 	"ce6",
285d5c65159SKalle Valo 	"ce7",
286d5c65159SKalle Valo 	"ce8",
287d5c65159SKalle Valo 	"ce9",
288d5c65159SKalle Valo 	"ce10",
289d5c65159SKalle Valo 	"ce11",
290d5c65159SKalle Valo 	"host2wbm-desc-feed",
291d5c65159SKalle Valo 	"host2reo-re-injection",
292d5c65159SKalle Valo 	"host2reo-command",
293d5c65159SKalle Valo 	"host2rxdma-monitor-ring3",
294d5c65159SKalle Valo 	"host2rxdma-monitor-ring2",
295d5c65159SKalle Valo 	"host2rxdma-monitor-ring1",
296d5c65159SKalle Valo 	"reo2ost-exception",
297d5c65159SKalle Valo 	"wbm2host-rx-release",
298d5c65159SKalle Valo 	"reo2host-status",
299d5c65159SKalle Valo 	"reo2host-destination-ring4",
300d5c65159SKalle Valo 	"reo2host-destination-ring3",
301d5c65159SKalle Valo 	"reo2host-destination-ring2",
302d5c65159SKalle Valo 	"reo2host-destination-ring1",
303d5c65159SKalle Valo 	"rxdma2host-monitor-destination-mac3",
304d5c65159SKalle Valo 	"rxdma2host-monitor-destination-mac2",
305d5c65159SKalle Valo 	"rxdma2host-monitor-destination-mac1",
306d5c65159SKalle Valo 	"ppdu-end-interrupts-mac3",
307d5c65159SKalle Valo 	"ppdu-end-interrupts-mac2",
308d5c65159SKalle Valo 	"ppdu-end-interrupts-mac1",
309d5c65159SKalle Valo 	"rxdma2host-monitor-status-ring-mac3",
310d5c65159SKalle Valo 	"rxdma2host-monitor-status-ring-mac2",
311d5c65159SKalle Valo 	"rxdma2host-monitor-status-ring-mac1",
312d5c65159SKalle Valo 	"host2rxdma-host-buf-ring-mac3",
313d5c65159SKalle Valo 	"host2rxdma-host-buf-ring-mac2",
314d5c65159SKalle Valo 	"host2rxdma-host-buf-ring-mac1",
315d5c65159SKalle Valo 	"rxdma2host-destination-ring-mac3",
316d5c65159SKalle Valo 	"rxdma2host-destination-ring-mac2",
317d5c65159SKalle Valo 	"rxdma2host-destination-ring-mac1",
318d5c65159SKalle Valo 	"host2tcl-input-ring4",
319d5c65159SKalle Valo 	"host2tcl-input-ring3",
320d5c65159SKalle Valo 	"host2tcl-input-ring2",
321d5c65159SKalle Valo 	"host2tcl-input-ring1",
322d5c65159SKalle Valo 	"wbm2host-tx-completions-ring3",
323d5c65159SKalle Valo 	"wbm2host-tx-completions-ring2",
324d5c65159SKalle Valo 	"wbm2host-tx-completions-ring1",
325d5c65159SKalle Valo 	"tcl2host-status-ring",
326d5c65159SKalle Valo };
327d5c65159SKalle Valo 
328d5c65159SKalle Valo /* enum ext_irq_num - irq numbers that can be used by external modules
329d5c65159SKalle Valo  * like datapath
330d5c65159SKalle Valo  */
331d5c65159SKalle Valo enum ext_irq_num {
332d5c65159SKalle Valo 	host2wbm_desc_feed = 16,
333d5c65159SKalle Valo 	host2reo_re_injection,
334d5c65159SKalle Valo 	host2reo_command,
335d5c65159SKalle Valo 	host2rxdma_monitor_ring3,
336d5c65159SKalle Valo 	host2rxdma_monitor_ring2,
337d5c65159SKalle Valo 	host2rxdma_monitor_ring1,
338d5c65159SKalle Valo 	reo2host_exception,
339d5c65159SKalle Valo 	wbm2host_rx_release,
340d5c65159SKalle Valo 	reo2host_status,
341d5c65159SKalle Valo 	reo2host_destination_ring4,
342d5c65159SKalle Valo 	reo2host_destination_ring3,
343d5c65159SKalle Valo 	reo2host_destination_ring2,
344d5c65159SKalle Valo 	reo2host_destination_ring1,
345d5c65159SKalle Valo 	rxdma2host_monitor_destination_mac3,
346d5c65159SKalle Valo 	rxdma2host_monitor_destination_mac2,
347d5c65159SKalle Valo 	rxdma2host_monitor_destination_mac1,
348d5c65159SKalle Valo 	ppdu_end_interrupts_mac3,
349d5c65159SKalle Valo 	ppdu_end_interrupts_mac2,
350d5c65159SKalle Valo 	ppdu_end_interrupts_mac1,
351d5c65159SKalle Valo 	rxdma2host_monitor_status_ring_mac3,
352d5c65159SKalle Valo 	rxdma2host_monitor_status_ring_mac2,
353d5c65159SKalle Valo 	rxdma2host_monitor_status_ring_mac1,
354d5c65159SKalle Valo 	host2rxdma_host_buf_ring_mac3,
355d5c65159SKalle Valo 	host2rxdma_host_buf_ring_mac2,
356d5c65159SKalle Valo 	host2rxdma_host_buf_ring_mac1,
357d5c65159SKalle Valo 	rxdma2host_destination_ring_mac3,
358d5c65159SKalle Valo 	rxdma2host_destination_ring_mac2,
359d5c65159SKalle Valo 	rxdma2host_destination_ring_mac1,
360d5c65159SKalle Valo 	host2tcl_input_ring4,
361d5c65159SKalle Valo 	host2tcl_input_ring3,
362d5c65159SKalle Valo 	host2tcl_input_ring2,
363d5c65159SKalle Valo 	host2tcl_input_ring1,
364d5c65159SKalle Valo 	wbm2host_tx_completions_ring3,
365d5c65159SKalle Valo 	wbm2host_tx_completions_ring2,
366d5c65159SKalle Valo 	wbm2host_tx_completions_ring1,
367d5c65159SKalle Valo 	tcl2host_status_ring,
368d5c65159SKalle Valo };
369d5c65159SKalle Valo 
37031858805SGovind Singh static inline u32 ath11k_ahb_read32(struct ath11k_base *ab, u32 offset)
37131858805SGovind Singh {
37231858805SGovind Singh 	return ioread32(ab->mem + offset);
37331858805SGovind Singh }
37431858805SGovind Singh 
37531858805SGovind Singh static inline void ath11k_ahb_write32(struct ath11k_base *ab, u32 offset, u32 value)
37631858805SGovind Singh {
37731858805SGovind Singh 	iowrite32(value, ab->mem + offset);
37831858805SGovind Singh }
37931858805SGovind Singh 
380d5c65159SKalle Valo static void ath11k_ahb_kill_tasklets(struct ath11k_base *ab)
381d5c65159SKalle Valo {
382d5c65159SKalle Valo 	int i;
383d5c65159SKalle Valo 
384d5c65159SKalle Valo 	for (i = 0; i < CE_COUNT; i++) {
385d5c65159SKalle Valo 		struct ath11k_ce_pipe *ce_pipe = &ab->ce.ce_pipe[i];
386d5c65159SKalle Valo 
387d5c65159SKalle Valo 		if (ath11k_ce_get_attr_flags(i) & CE_ATTR_DIS_INTR)
388d5c65159SKalle Valo 			continue;
389d5c65159SKalle Valo 
390d5c65159SKalle Valo 		tasklet_kill(&ce_pipe->intr_tq);
391d5c65159SKalle Valo 	}
392d5c65159SKalle Valo }
393d5c65159SKalle Valo 
394d5c65159SKalle Valo static void ath11k_ahb_ext_grp_disable(struct ath11k_ext_irq_grp *irq_grp)
395d5c65159SKalle Valo {
396d5c65159SKalle Valo 	int i;
397d5c65159SKalle Valo 
398d5c65159SKalle Valo 	for (i = 0; i < irq_grp->num_irq; i++)
399d5c65159SKalle Valo 		disable_irq_nosync(irq_grp->ab->irq_num[irq_grp->irqs[i]]);
400d5c65159SKalle Valo }
401d5c65159SKalle Valo 
402d5c65159SKalle Valo static void __ath11k_ahb_ext_irq_disable(struct ath11k_base *ab)
403d5c65159SKalle Valo {
404d5c65159SKalle Valo 	int i;
405d5c65159SKalle Valo 
406d5c65159SKalle Valo 	for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
407d5c65159SKalle Valo 		struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
408d5c65159SKalle Valo 
409d5c65159SKalle Valo 		ath11k_ahb_ext_grp_disable(irq_grp);
410d5c65159SKalle Valo 
411d5c65159SKalle Valo 		napi_synchronize(&irq_grp->napi);
412d5c65159SKalle Valo 		napi_disable(&irq_grp->napi);
413d5c65159SKalle Valo 	}
414d5c65159SKalle Valo }
415d5c65159SKalle Valo 
416d5c65159SKalle Valo static void ath11k_ahb_ext_grp_enable(struct ath11k_ext_irq_grp *irq_grp)
417d5c65159SKalle Valo {
418d5c65159SKalle Valo 	int i;
419d5c65159SKalle Valo 
420d5c65159SKalle Valo 	for (i = 0; i < irq_grp->num_irq; i++)
421d5c65159SKalle Valo 		enable_irq(irq_grp->ab->irq_num[irq_grp->irqs[i]]);
422d5c65159SKalle Valo }
423d5c65159SKalle Valo 
424d5c65159SKalle Valo static void ath11k_ahb_setbit32(struct ath11k_base *ab, u8 bit, u32 offset)
425d5c65159SKalle Valo {
426d5c65159SKalle Valo 	u32 val;
427d5c65159SKalle Valo 
428d5c65159SKalle Valo 	val = ath11k_ahb_read32(ab, offset);
429d5c65159SKalle Valo 	ath11k_ahb_write32(ab, offset, val | BIT(bit));
430d5c65159SKalle Valo }
431d5c65159SKalle Valo 
432d5c65159SKalle Valo static void ath11k_ahb_clearbit32(struct ath11k_base *ab, u8 bit, u32 offset)
433d5c65159SKalle Valo {
434d5c65159SKalle Valo 	u32 val;
435d5c65159SKalle Valo 
436d5c65159SKalle Valo 	val = ath11k_ahb_read32(ab, offset);
437d5c65159SKalle Valo 	ath11k_ahb_write32(ab, offset, val & ~BIT(bit));
438d5c65159SKalle Valo }
439d5c65159SKalle Valo 
440d5c65159SKalle Valo static void ath11k_ahb_ce_irq_enable(struct ath11k_base *ab, u16 ce_id)
441d5c65159SKalle Valo {
442d5c65159SKalle Valo 	const struct ce_pipe_config *ce_config;
443d5c65159SKalle Valo 
444d5c65159SKalle Valo 	ce_config = &target_ce_config_wlan[ce_id];
445d5c65159SKalle Valo 	if (__le32_to_cpu(ce_config->pipedir) & PIPEDIR_OUT)
446d5c65159SKalle Valo 		ath11k_ahb_setbit32(ab, ce_id, CE_HOST_IE_ADDRESS);
447d5c65159SKalle Valo 
448d5c65159SKalle Valo 	if (__le32_to_cpu(ce_config->pipedir) & PIPEDIR_IN) {
449d5c65159SKalle Valo 		ath11k_ahb_setbit32(ab, ce_id, CE_HOST_IE_2_ADDRESS);
450d5c65159SKalle Valo 		ath11k_ahb_setbit32(ab, ce_id + CE_HOST_IE_3_SHIFT,
451d5c65159SKalle Valo 				    CE_HOST_IE_3_ADDRESS);
452d5c65159SKalle Valo 	}
453d5c65159SKalle Valo }
454d5c65159SKalle Valo 
455d5c65159SKalle Valo static void ath11k_ahb_ce_irq_disable(struct ath11k_base *ab, u16 ce_id)
456d5c65159SKalle Valo {
457d5c65159SKalle Valo 	const struct ce_pipe_config *ce_config;
458d5c65159SKalle Valo 
459d5c65159SKalle Valo 	ce_config = &target_ce_config_wlan[ce_id];
460d5c65159SKalle Valo 	if (__le32_to_cpu(ce_config->pipedir) & PIPEDIR_OUT)
461d5c65159SKalle Valo 		ath11k_ahb_clearbit32(ab, ce_id, CE_HOST_IE_ADDRESS);
462d5c65159SKalle Valo 
463d5c65159SKalle Valo 	if (__le32_to_cpu(ce_config->pipedir) & PIPEDIR_IN) {
464d5c65159SKalle Valo 		ath11k_ahb_clearbit32(ab, ce_id, CE_HOST_IE_2_ADDRESS);
465d5c65159SKalle Valo 		ath11k_ahb_clearbit32(ab, ce_id + CE_HOST_IE_3_SHIFT,
466d5c65159SKalle Valo 				      CE_HOST_IE_3_ADDRESS);
467d5c65159SKalle Valo 	}
468d5c65159SKalle Valo }
469d5c65159SKalle Valo 
470d5c65159SKalle Valo static void ath11k_ahb_sync_ce_irqs(struct ath11k_base *ab)
471d5c65159SKalle Valo {
472d5c65159SKalle Valo 	int i;
473d5c65159SKalle Valo 	int irq_idx;
474d5c65159SKalle Valo 
475d5c65159SKalle Valo 	for (i = 0; i < CE_COUNT; i++) {
476d5c65159SKalle Valo 		if (ath11k_ce_get_attr_flags(i) & CE_ATTR_DIS_INTR)
477d5c65159SKalle Valo 			continue;
478d5c65159SKalle Valo 
479d5c65159SKalle Valo 		irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
480d5c65159SKalle Valo 		synchronize_irq(ab->irq_num[irq_idx]);
481d5c65159SKalle Valo 	}
482d5c65159SKalle Valo }
483d5c65159SKalle Valo 
484d5c65159SKalle Valo static void ath11k_ahb_sync_ext_irqs(struct ath11k_base *ab)
485d5c65159SKalle Valo {
486d5c65159SKalle Valo 	int i, j;
487d5c65159SKalle Valo 	int irq_idx;
488d5c65159SKalle Valo 
489d5c65159SKalle Valo 	for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
490d5c65159SKalle Valo 		struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
491d5c65159SKalle Valo 
492d5c65159SKalle Valo 		for (j = 0; j < irq_grp->num_irq; j++) {
493d5c65159SKalle Valo 			irq_idx = irq_grp->irqs[j];
494d5c65159SKalle Valo 			synchronize_irq(ab->irq_num[irq_idx]);
495d5c65159SKalle Valo 		}
496d5c65159SKalle Valo 	}
497d5c65159SKalle Valo }
498d5c65159SKalle Valo 
499d5c65159SKalle Valo static void ath11k_ahb_ce_irqs_enable(struct ath11k_base *ab)
500d5c65159SKalle Valo {
501d5c65159SKalle Valo 	int i;
502d5c65159SKalle Valo 
503d5c65159SKalle Valo 	for (i = 0; i < CE_COUNT; i++) {
504d5c65159SKalle Valo 		if (ath11k_ce_get_attr_flags(i) & CE_ATTR_DIS_INTR)
505d5c65159SKalle Valo 			continue;
506d5c65159SKalle Valo 		ath11k_ahb_ce_irq_enable(ab, i);
507d5c65159SKalle Valo 	}
508d5c65159SKalle Valo }
509d5c65159SKalle Valo 
510d5c65159SKalle Valo static void ath11k_ahb_ce_irqs_disable(struct ath11k_base *ab)
511d5c65159SKalle Valo {
512d5c65159SKalle Valo 	int i;
513d5c65159SKalle Valo 
514d5c65159SKalle Valo 	for (i = 0; i < CE_COUNT; i++) {
515d5c65159SKalle Valo 		if (ath11k_ce_get_attr_flags(i) & CE_ATTR_DIS_INTR)
516d5c65159SKalle Valo 			continue;
517d5c65159SKalle Valo 		ath11k_ahb_ce_irq_disable(ab, i);
518d5c65159SKalle Valo 	}
519d5c65159SKalle Valo }
520d5c65159SKalle Valo 
52131858805SGovind Singh static int ath11k_ahb_start(struct ath11k_base *ab)
522d5c65159SKalle Valo {
523d5c65159SKalle Valo 	ath11k_ahb_ce_irqs_enable(ab);
524d5c65159SKalle Valo 	ath11k_ce_rx_post_buf(ab);
525d5c65159SKalle Valo 
526d5c65159SKalle Valo 	return 0;
527d5c65159SKalle Valo }
528d5c65159SKalle Valo 
52931858805SGovind Singh static void ath11k_ahb_ext_irq_enable(struct ath11k_base *ab)
530d5c65159SKalle Valo {
531d5c65159SKalle Valo 	int i;
532d5c65159SKalle Valo 
533d5c65159SKalle Valo 	for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
534d5c65159SKalle Valo 		struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
535d5c65159SKalle Valo 
536d5c65159SKalle Valo 		napi_enable(&irq_grp->napi);
537d5c65159SKalle Valo 		ath11k_ahb_ext_grp_enable(irq_grp);
538d5c65159SKalle Valo 	}
539d5c65159SKalle Valo }
540d5c65159SKalle Valo 
54131858805SGovind Singh static void ath11k_ahb_ext_irq_disable(struct ath11k_base *ab)
542d5c65159SKalle Valo {
543d5c65159SKalle Valo 	__ath11k_ahb_ext_irq_disable(ab);
544d5c65159SKalle Valo 	ath11k_ahb_sync_ext_irqs(ab);
545d5c65159SKalle Valo }
546d5c65159SKalle Valo 
54731858805SGovind Singh static void ath11k_ahb_stop(struct ath11k_base *ab)
548d5c65159SKalle Valo {
549d5c65159SKalle Valo 	if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))
550d5c65159SKalle Valo 		ath11k_ahb_ce_irqs_disable(ab);
551d5c65159SKalle Valo 	ath11k_ahb_sync_ce_irqs(ab);
552d5c65159SKalle Valo 	ath11k_ahb_kill_tasklets(ab);
553d5c65159SKalle Valo 	del_timer_sync(&ab->rx_replenish_retry);
554d5c65159SKalle Valo 	ath11k_ce_cleanup_pipes(ab);
555d5c65159SKalle Valo }
556d5c65159SKalle Valo 
55731858805SGovind Singh static int ath11k_ahb_power_up(struct ath11k_base *ab)
558d5c65159SKalle Valo {
559d5c65159SKalle Valo 	int ret;
560d5c65159SKalle Valo 
561d5c65159SKalle Valo 	ret = rproc_boot(ab->tgt_rproc);
562d5c65159SKalle Valo 	if (ret)
563d5c65159SKalle Valo 		ath11k_err(ab, "failed to boot the remote processor Q6\n");
564d5c65159SKalle Valo 
565d5c65159SKalle Valo 	return ret;
566d5c65159SKalle Valo }
567d5c65159SKalle Valo 
56831858805SGovind Singh static void ath11k_ahb_power_down(struct ath11k_base *ab)
569d5c65159SKalle Valo {
570d5c65159SKalle Valo 	rproc_shutdown(ab->tgt_rproc);
571d5c65159SKalle Valo }
572d5c65159SKalle Valo 
573d5c65159SKalle Valo static void ath11k_ahb_init_qmi_ce_config(struct ath11k_base *ab)
574d5c65159SKalle Valo {
575d5c65159SKalle Valo 	struct ath11k_qmi_ce_cfg *cfg = &ab->qmi.ce_cfg;
576d5c65159SKalle Valo 
577d6af906dSAnilkumar Kolli 	cfg->tgt_ce_len = ARRAY_SIZE(target_ce_config_wlan) - 1;
578d6af906dSAnilkumar Kolli 	cfg->tgt_ce = target_ce_config_wlan;
579d6af906dSAnilkumar Kolli 	cfg->svc_to_ce_map_len = ARRAY_SIZE(target_service_to_ce_map_wlan);
580d6af906dSAnilkumar Kolli 	cfg->svc_to_ce_map = target_service_to_ce_map_wlan;
581d5c65159SKalle Valo }
582d5c65159SKalle Valo 
583d5c65159SKalle Valo static void ath11k_ahb_free_ext_irq(struct ath11k_base *ab)
584d5c65159SKalle Valo {
585d5c65159SKalle Valo 	int i, j;
586d5c65159SKalle Valo 
587d5c65159SKalle Valo 	for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
588d5c65159SKalle Valo 		struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
589d5c65159SKalle Valo 
590d5c65159SKalle Valo 		for (j = 0; j < irq_grp->num_irq; j++)
591d5c65159SKalle Valo 			free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp);
592d5c65159SKalle Valo 	}
593d5c65159SKalle Valo }
594d5c65159SKalle Valo 
595d5c65159SKalle Valo static void ath11k_ahb_free_irq(struct ath11k_base *ab)
596d5c65159SKalle Valo {
597d5c65159SKalle Valo 	int irq_idx;
598d5c65159SKalle Valo 	int i;
599d5c65159SKalle Valo 
600d5c65159SKalle Valo 	for (i = 0; i < CE_COUNT; i++) {
601d5c65159SKalle Valo 		if (ath11k_ce_get_attr_flags(i) & CE_ATTR_DIS_INTR)
602d5c65159SKalle Valo 			continue;
603d5c65159SKalle Valo 		irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
604d5c65159SKalle Valo 		free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]);
605d5c65159SKalle Valo 	}
606d5c65159SKalle Valo 
607d5c65159SKalle Valo 	ath11k_ahb_free_ext_irq(ab);
608d5c65159SKalle Valo }
609d5c65159SKalle Valo 
610d5c65159SKalle Valo static void ath11k_ahb_ce_tasklet(unsigned long data)
611d5c65159SKalle Valo {
612d5c65159SKalle Valo 	struct ath11k_ce_pipe *ce_pipe = (struct ath11k_ce_pipe *)data;
613d5c65159SKalle Valo 
614d5c65159SKalle Valo 	ath11k_ce_per_engine_service(ce_pipe->ab, ce_pipe->pipe_num);
615d5c65159SKalle Valo 
616d5c65159SKalle Valo 	ath11k_ahb_ce_irq_enable(ce_pipe->ab, ce_pipe->pipe_num);
617d5c65159SKalle Valo }
618d5c65159SKalle Valo 
619d5c65159SKalle Valo static irqreturn_t ath11k_ahb_ce_interrupt_handler(int irq, void *arg)
620d5c65159SKalle Valo {
621d5c65159SKalle Valo 	struct ath11k_ce_pipe *ce_pipe = arg;
622d5c65159SKalle Valo 
6235118935bSManikanta Pubbisetty 	/* last interrupt received for this CE */
6245118935bSManikanta Pubbisetty 	ce_pipe->timestamp = jiffies;
6255118935bSManikanta Pubbisetty 
626d5c65159SKalle Valo 	ath11k_ahb_ce_irq_disable(ce_pipe->ab, ce_pipe->pipe_num);
627d5c65159SKalle Valo 
628d5c65159SKalle Valo 	tasklet_schedule(&ce_pipe->intr_tq);
629d5c65159SKalle Valo 
630d5c65159SKalle Valo 	return IRQ_HANDLED;
631d5c65159SKalle Valo }
632d5c65159SKalle Valo 
633d5c65159SKalle Valo static int ath11k_ahb_ext_grp_napi_poll(struct napi_struct *napi, int budget)
634d5c65159SKalle Valo {
635d5c65159SKalle Valo 	struct ath11k_ext_irq_grp *irq_grp = container_of(napi,
636d5c65159SKalle Valo 						struct ath11k_ext_irq_grp,
637d5c65159SKalle Valo 						napi);
638d5c65159SKalle Valo 	struct ath11k_base *ab = irq_grp->ab;
639d5c65159SKalle Valo 	int work_done;
640d5c65159SKalle Valo 
641d5c65159SKalle Valo 	work_done = ath11k_dp_service_srng(ab, irq_grp, budget);
642d5c65159SKalle Valo 	if (work_done < budget) {
643d5c65159SKalle Valo 		napi_complete_done(napi, work_done);
644d5c65159SKalle Valo 		ath11k_ahb_ext_grp_enable(irq_grp);
645d5c65159SKalle Valo 	}
646d5c65159SKalle Valo 
647d5c65159SKalle Valo 	if (work_done > budget)
648d5c65159SKalle Valo 		work_done = budget;
649d5c65159SKalle Valo 
650d5c65159SKalle Valo 	return work_done;
651d5c65159SKalle Valo }
652d5c65159SKalle Valo 
653d5c65159SKalle Valo static irqreturn_t ath11k_ahb_ext_interrupt_handler(int irq, void *arg)
654d5c65159SKalle Valo {
655d5c65159SKalle Valo 	struct ath11k_ext_irq_grp *irq_grp = arg;
656d5c65159SKalle Valo 
6575118935bSManikanta Pubbisetty 	/* last interrupt received for this group */
6585118935bSManikanta Pubbisetty 	irq_grp->timestamp = jiffies;
6595118935bSManikanta Pubbisetty 
660d5c65159SKalle Valo 	ath11k_ahb_ext_grp_disable(irq_grp);
661d5c65159SKalle Valo 
662d5c65159SKalle Valo 	napi_schedule(&irq_grp->napi);
663d5c65159SKalle Valo 
664d5c65159SKalle Valo 	return IRQ_HANDLED;
665d5c65159SKalle Valo }
666d5c65159SKalle Valo 
667d5c65159SKalle Valo static int ath11k_ahb_ext_irq_config(struct ath11k_base *ab)
668d5c65159SKalle Valo {
669d547ca4cSAnilkumar Kolli 	struct ath11k_hw_params *hw = &ab->hw_params;
670d5c65159SKalle Valo 	int i, j;
671d5c65159SKalle Valo 	int irq;
672d5c65159SKalle Valo 	int ret;
673d5c65159SKalle Valo 
674d5c65159SKalle Valo 	for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
675d5c65159SKalle Valo 		struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
676d5c65159SKalle Valo 		u32 num_irq = 0;
677d5c65159SKalle Valo 
678d5c65159SKalle Valo 		irq_grp->ab = ab;
679d5c65159SKalle Valo 		irq_grp->grp_id = i;
680d5c65159SKalle Valo 		init_dummy_netdev(&irq_grp->napi_ndev);
681d5c65159SKalle Valo 		netif_napi_add(&irq_grp->napi_ndev, &irq_grp->napi,
682d5c65159SKalle Valo 			       ath11k_ahb_ext_grp_napi_poll, NAPI_POLL_WEIGHT);
683d5c65159SKalle Valo 
684d5c65159SKalle Valo 		for (j = 0; j < ATH11K_EXT_IRQ_NUM_MAX; j++) {
68534d5a3a8SKalle Valo 			if (ab->hw_params.ring_mask->tx[i] & BIT(j)) {
686d5c65159SKalle Valo 				irq_grp->irqs[num_irq++] =
687d5c65159SKalle Valo 					wbm2host_tx_completions_ring1 - j;
688d5c65159SKalle Valo 			}
689d5c65159SKalle Valo 
69034d5a3a8SKalle Valo 			if (ab->hw_params.ring_mask->rx[i] & BIT(j)) {
691d5c65159SKalle Valo 				irq_grp->irqs[num_irq++] =
692d5c65159SKalle Valo 					reo2host_destination_ring1 - j;
693d5c65159SKalle Valo 			}
694d5c65159SKalle Valo 
69534d5a3a8SKalle Valo 			if (ab->hw_params.ring_mask->rx_err[i] & BIT(j))
696d5c65159SKalle Valo 				irq_grp->irqs[num_irq++] = reo2host_exception;
697d5c65159SKalle Valo 
69834d5a3a8SKalle Valo 			if (ab->hw_params.ring_mask->rx_wbm_rel[i] & BIT(j))
699d5c65159SKalle Valo 				irq_grp->irqs[num_irq++] = wbm2host_rx_release;
700d5c65159SKalle Valo 
70134d5a3a8SKalle Valo 			if (ab->hw_params.ring_mask->reo_status[i] & BIT(j))
702d5c65159SKalle Valo 				irq_grp->irqs[num_irq++] = reo2host_status;
703d5c65159SKalle Valo 
704d547ca4cSAnilkumar Kolli 			if (j < ab->hw_params.max_radios) {
70534d5a3a8SKalle Valo 				if (ab->hw_params.ring_mask->rxdma2host[i] & BIT(j)) {
706d5c65159SKalle Valo 					irq_grp->irqs[num_irq++] =
707d547ca4cSAnilkumar Kolli 						rxdma2host_destination_ring_mac1 -
708d547ca4cSAnilkumar Kolli 						ath11k_hw_get_mac_from_pdev_id(hw, j);
709d5c65159SKalle Valo 				}
710d5c65159SKalle Valo 
71134d5a3a8SKalle Valo 				if (ab->hw_params.ring_mask->host2rxdma[i] & BIT(j)) {
712d5c65159SKalle Valo 					irq_grp->irqs[num_irq++] =
713d547ca4cSAnilkumar Kolli 						host2rxdma_host_buf_ring_mac1 -
714d547ca4cSAnilkumar Kolli 						ath11k_hw_get_mac_from_pdev_id(hw, j);
715d5c65159SKalle Valo 				}
716d5c65159SKalle Valo 
71734d5a3a8SKalle Valo 				if (ab->hw_params.ring_mask->rx_mon_status[i] & BIT(j)) {
718d5c65159SKalle Valo 					irq_grp->irqs[num_irq++] =
719d5c65159SKalle Valo 						ppdu_end_interrupts_mac1 -
720d547ca4cSAnilkumar Kolli 						ath11k_hw_get_mac_from_pdev_id(hw, j);
721d5c65159SKalle Valo 					irq_grp->irqs[num_irq++] =
722d5c65159SKalle Valo 						rxdma2host_monitor_status_ring_mac1 -
723d547ca4cSAnilkumar Kolli 						ath11k_hw_get_mac_from_pdev_id(hw, j);
724d5c65159SKalle Valo 				}
725d5c65159SKalle Valo 			}
726d5c65159SKalle Valo 		}
727d5c65159SKalle Valo 		irq_grp->num_irq = num_irq;
728d5c65159SKalle Valo 
729d5c65159SKalle Valo 		for (j = 0; j < irq_grp->num_irq; j++) {
730d5c65159SKalle Valo 			int irq_idx = irq_grp->irqs[j];
731d5c65159SKalle Valo 
732d5c65159SKalle Valo 			irq = platform_get_irq_byname(ab->pdev,
733d5c65159SKalle Valo 						      irq_name[irq_idx]);
734d5c65159SKalle Valo 			ab->irq_num[irq_idx] = irq;
73505090864SManikanta Pubbisetty 			irq_set_status_flags(irq, IRQ_NOAUTOEN | IRQ_DISABLE_UNLAZY);
736d5c65159SKalle Valo 			ret = request_irq(irq, ath11k_ahb_ext_interrupt_handler,
737d5c65159SKalle Valo 					  IRQF_TRIGGER_RISING,
738d5c65159SKalle Valo 					  irq_name[irq_idx], irq_grp);
739d5c65159SKalle Valo 			if (ret) {
740d5c65159SKalle Valo 				ath11k_err(ab, "failed request_irq for %d\n",
741d5c65159SKalle Valo 					   irq);
742d5c65159SKalle Valo 			}
743d5c65159SKalle Valo 		}
744d5c65159SKalle Valo 	}
745d5c65159SKalle Valo 
746d5c65159SKalle Valo 	return 0;
747d5c65159SKalle Valo }
748d5c65159SKalle Valo 
749d5c65159SKalle Valo static int ath11k_ahb_config_irq(struct ath11k_base *ab)
750d5c65159SKalle Valo {
751d5c65159SKalle Valo 	int irq, irq_idx, i;
752d5c65159SKalle Valo 	int ret;
753d5c65159SKalle Valo 
754d5c65159SKalle Valo 	/* Configure CE irqs */
755d5c65159SKalle Valo 	for (i = 0; i < CE_COUNT; i++) {
756d5c65159SKalle Valo 		struct ath11k_ce_pipe *ce_pipe = &ab->ce.ce_pipe[i];
757d5c65159SKalle Valo 
758d5c65159SKalle Valo 		if (ath11k_ce_get_attr_flags(i) & CE_ATTR_DIS_INTR)
759d5c65159SKalle Valo 			continue;
760d5c65159SKalle Valo 
761d5c65159SKalle Valo 		irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
762d5c65159SKalle Valo 
763d5c65159SKalle Valo 		tasklet_init(&ce_pipe->intr_tq, ath11k_ahb_ce_tasklet,
764d5c65159SKalle Valo 			     (unsigned long)ce_pipe);
765d5c65159SKalle Valo 		irq = platform_get_irq_byname(ab->pdev, irq_name[irq_idx]);
766d5c65159SKalle Valo 		ret = request_irq(irq, ath11k_ahb_ce_interrupt_handler,
767d5c65159SKalle Valo 				  IRQF_TRIGGER_RISING, irq_name[irq_idx],
768d5c65159SKalle Valo 				  ce_pipe);
769d5c65159SKalle Valo 		if (ret)
770d5c65159SKalle Valo 			return ret;
771d5c65159SKalle Valo 
772d5c65159SKalle Valo 		ab->irq_num[irq_idx] = irq;
773d5c65159SKalle Valo 	}
774d5c65159SKalle Valo 
775d5c65159SKalle Valo 	/* Configure external interrupts */
776d5c65159SKalle Valo 	ret = ath11k_ahb_ext_irq_config(ab);
777d5c65159SKalle Valo 
778d5c65159SKalle Valo 	return ret;
779d5c65159SKalle Valo }
780d5c65159SKalle Valo 
78131858805SGovind Singh static int ath11k_ahb_map_service_to_pipe(struct ath11k_base *ab, u16 service_id,
782d5c65159SKalle Valo 					  u8 *ul_pipe, u8 *dl_pipe)
783d5c65159SKalle Valo {
784d5c65159SKalle Valo 	const struct service_to_pipe *entry;
785d5c65159SKalle Valo 	bool ul_set = false, dl_set = false;
786d5c65159SKalle Valo 	int i;
787d5c65159SKalle Valo 
788d5c65159SKalle Valo 	for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
789d5c65159SKalle Valo 		entry = &target_service_to_ce_map_wlan[i];
790d5c65159SKalle Valo 
791d5c65159SKalle Valo 		if (__le32_to_cpu(entry->service_id) != service_id)
792d5c65159SKalle Valo 			continue;
793d5c65159SKalle Valo 
794d5c65159SKalle Valo 		switch (__le32_to_cpu(entry->pipedir)) {
795d5c65159SKalle Valo 		case PIPEDIR_NONE:
796d5c65159SKalle Valo 			break;
797d5c65159SKalle Valo 		case PIPEDIR_IN:
798d5c65159SKalle Valo 			WARN_ON(dl_set);
799d5c65159SKalle Valo 			*dl_pipe = __le32_to_cpu(entry->pipenum);
800d5c65159SKalle Valo 			dl_set = true;
801d5c65159SKalle Valo 			break;
802d5c65159SKalle Valo 		case PIPEDIR_OUT:
803d5c65159SKalle Valo 			WARN_ON(ul_set);
804d5c65159SKalle Valo 			*ul_pipe = __le32_to_cpu(entry->pipenum);
805d5c65159SKalle Valo 			ul_set = true;
806d5c65159SKalle Valo 			break;
807d5c65159SKalle Valo 		case PIPEDIR_INOUT:
808d5c65159SKalle Valo 			WARN_ON(dl_set);
809d5c65159SKalle Valo 			WARN_ON(ul_set);
810d5c65159SKalle Valo 			*dl_pipe = __le32_to_cpu(entry->pipenum);
811d5c65159SKalle Valo 			*ul_pipe = __le32_to_cpu(entry->pipenum);
812d5c65159SKalle Valo 			dl_set = true;
813d5c65159SKalle Valo 			ul_set = true;
814d5c65159SKalle Valo 			break;
815d5c65159SKalle Valo 		}
816d5c65159SKalle Valo 	}
817d5c65159SKalle Valo 
818d5c65159SKalle Valo 	if (WARN_ON(!ul_set || !dl_set))
819d5c65159SKalle Valo 		return -ENOENT;
820d5c65159SKalle Valo 
821d5c65159SKalle Valo 	return 0;
822d5c65159SKalle Valo }
823d5c65159SKalle Valo 
82431858805SGovind Singh static const struct ath11k_hif_ops ath11k_ahb_hif_ops = {
82531858805SGovind Singh 	.start = ath11k_ahb_start,
82631858805SGovind Singh 	.stop = ath11k_ahb_stop,
82731858805SGovind Singh 	.read32 = ath11k_ahb_read32,
82831858805SGovind Singh 	.write32 = ath11k_ahb_write32,
82931858805SGovind Singh 	.irq_enable = ath11k_ahb_ext_irq_enable,
83031858805SGovind Singh 	.irq_disable = ath11k_ahb_ext_irq_disable,
83131858805SGovind Singh 	.map_service_to_pipe = ath11k_ahb_map_service_to_pipe,
83231858805SGovind Singh 	.power_down = ath11k_ahb_power_down,
83331858805SGovind Singh 	.power_up = ath11k_ahb_power_up,
83431858805SGovind Singh };
83531858805SGovind Singh 
836d5c65159SKalle Valo static int ath11k_ahb_probe(struct platform_device *pdev)
837d5c65159SKalle Valo {
838d5c65159SKalle Valo 	struct ath11k_base *ab;
839d5c65159SKalle Valo 	const struct of_device_id *of_id;
840d5c65159SKalle Valo 	struct resource *mem_res;
841d5c65159SKalle Valo 	void __iomem *mem;
842d5c65159SKalle Valo 	int ret;
843d5c65159SKalle Valo 
844d5c65159SKalle Valo 	of_id = of_match_device(ath11k_ahb_of_match, &pdev->dev);
845d5c65159SKalle Valo 	if (!of_id) {
846d5c65159SKalle Valo 		dev_err(&pdev->dev, "failed to find matching device tree id\n");
847d5c65159SKalle Valo 		return -EINVAL;
848d5c65159SKalle Valo 	}
849d5c65159SKalle Valo 
850c8ffcd12SWei Yongjun 	mem = devm_platform_get_and_ioremap_resource(pdev, 0, &mem_res);
851d5c65159SKalle Valo 	if (IS_ERR(mem)) {
852d5c65159SKalle Valo 		dev_err(&pdev->dev, "ioremap error\n");
853d5c65159SKalle Valo 		return PTR_ERR(mem);
854d5c65159SKalle Valo 	}
855d5c65159SKalle Valo 
856d5c65159SKalle Valo 	ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
857d5c65159SKalle Valo 	if (ret) {
858d5c65159SKalle Valo 		dev_err(&pdev->dev, "failed to set 32-bit consistent dma\n");
859d5c65159SKalle Valo 		return ret;
860d5c65159SKalle Valo 	}
861d5c65159SKalle Valo 
8621ff8ed78SGovind Singh 	ab = ath11k_core_alloc(&pdev->dev, 0, ATH11K_BUS_AHB, &ath11k_ahb_bus_params);
863d5c65159SKalle Valo 	if (!ab) {
864d5c65159SKalle Valo 		dev_err(&pdev->dev, "failed to allocate ath11k base\n");
865d5c65159SKalle Valo 		return -ENOMEM;
866d5c65159SKalle Valo 	}
867d5c65159SKalle Valo 
86831858805SGovind Singh 	ab->hif.ops = &ath11k_ahb_hif_ops;
869d5c65159SKalle Valo 	ab->pdev = pdev;
870d5c65159SKalle Valo 	ab->hw_rev = (enum ath11k_hw_rev)of_id->data;
871d5c65159SKalle Valo 	ab->mem = mem;
872d5c65159SKalle Valo 	ab->mem_len = resource_size(mem_res);
873d5c65159SKalle Valo 	platform_set_drvdata(pdev, ab);
874d5c65159SKalle Valo 
875b8246f88SKalle Valo 	ret = ath11k_core_pre_init(ab);
876b8246f88SKalle Valo 	if (ret)
877b8246f88SKalle Valo 		goto err_core_free;
878b8246f88SKalle Valo 
879d5c65159SKalle Valo 	ret = ath11k_hal_srng_init(ab);
880d5c65159SKalle Valo 	if (ret)
881d5c65159SKalle Valo 		goto err_core_free;
882d5c65159SKalle Valo 
883d5c65159SKalle Valo 	ret = ath11k_ce_alloc_pipes(ab);
884d5c65159SKalle Valo 	if (ret) {
885d5c65159SKalle Valo 		ath11k_err(ab, "failed to allocate ce pipes: %d\n", ret);
886d5c65159SKalle Valo 		goto err_hal_srng_deinit;
887d5c65159SKalle Valo 	}
888d5c65159SKalle Valo 
889d5c65159SKalle Valo 	ath11k_ahb_init_qmi_ce_config(ab);
890d5c65159SKalle Valo 
891d5c65159SKalle Valo 	ret = ath11k_core_init(ab);
892d5c65159SKalle Valo 	if (ret) {
893d5c65159SKalle Valo 		ath11k_err(ab, "failed to init core: %d\n", ret);
894d5c65159SKalle Valo 		goto err_ce_free;
895d5c65159SKalle Valo 	}
896d5c65159SKalle Valo 
897166e22b3SAnilkumar Kolli 	ret = ath11k_ahb_config_irq(ab);
898166e22b3SAnilkumar Kolli 	if (ret) {
899166e22b3SAnilkumar Kolli 		ath11k_err(ab, "failed to configure irq: %d\n", ret);
900166e22b3SAnilkumar Kolli 		goto err_ce_free;
901166e22b3SAnilkumar Kolli 	}
902166e22b3SAnilkumar Kolli 
903d5c65159SKalle Valo 	return 0;
904d5c65159SKalle Valo 
905d5c65159SKalle Valo err_ce_free:
906d5c65159SKalle Valo 	ath11k_ce_free_pipes(ab);
907d5c65159SKalle Valo 
908d5c65159SKalle Valo err_hal_srng_deinit:
909d5c65159SKalle Valo 	ath11k_hal_srng_deinit(ab);
910d5c65159SKalle Valo 
911d5c65159SKalle Valo err_core_free:
912d5c65159SKalle Valo 	ath11k_core_free(ab);
913d5c65159SKalle Valo 	platform_set_drvdata(pdev, NULL);
914d5c65159SKalle Valo 
915d5c65159SKalle Valo 	return ret;
916d5c65159SKalle Valo }
917d5c65159SKalle Valo 
918d5c65159SKalle Valo static int ath11k_ahb_remove(struct platform_device *pdev)
919d5c65159SKalle Valo {
920d5c65159SKalle Valo 	struct ath11k_base *ab = platform_get_drvdata(pdev);
921d5c65159SKalle Valo 
922d5c65159SKalle Valo 	reinit_completion(&ab->driver_recovery);
923d5c65159SKalle Valo 
924d5c65159SKalle Valo 	if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags))
925d5c65159SKalle Valo 		wait_for_completion_timeout(&ab->driver_recovery,
926d5c65159SKalle Valo 					    ATH11K_AHB_RECOVERY_TIMEOUT);
927d5c65159SKalle Valo 
928d5c65159SKalle Valo 	set_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags);
929d5c65159SKalle Valo 	cancel_work_sync(&ab->restart_work);
930d5c65159SKalle Valo 
931d5c65159SKalle Valo 	ath11k_core_deinit(ab);
932d5c65159SKalle Valo 	ath11k_ahb_free_irq(ab);
933d5c65159SKalle Valo 
934d5c65159SKalle Valo 	ath11k_hal_srng_deinit(ab);
935d5c65159SKalle Valo 	ath11k_ce_free_pipes(ab);
936d5c65159SKalle Valo 	ath11k_core_free(ab);
937d5c65159SKalle Valo 	platform_set_drvdata(pdev, NULL);
938d5c65159SKalle Valo 
939d5c65159SKalle Valo 	return 0;
940d5c65159SKalle Valo }
941d5c65159SKalle Valo 
942d5c65159SKalle Valo static struct platform_driver ath11k_ahb_driver = {
943d5c65159SKalle Valo 	.driver         = {
944d5c65159SKalle Valo 		.name   = "ath11k",
945d5c65159SKalle Valo 		.of_match_table = ath11k_ahb_of_match,
946d5c65159SKalle Valo 	},
947d5c65159SKalle Valo 	.probe  = ath11k_ahb_probe,
948d5c65159SKalle Valo 	.remove = ath11k_ahb_remove,
949d5c65159SKalle Valo };
950d5c65159SKalle Valo 
95131858805SGovind Singh static int ath11k_ahb_init(void)
952d5c65159SKalle Valo {
953d5c65159SKalle Valo 	return platform_driver_register(&ath11k_ahb_driver);
954d5c65159SKalle Valo }
95531858805SGovind Singh module_init(ath11k_ahb_init);
956d5c65159SKalle Valo 
95731858805SGovind Singh static void ath11k_ahb_exit(void)
958d5c65159SKalle Valo {
959d5c65159SKalle Valo 	platform_driver_unregister(&ath11k_ahb_driver);
960d5c65159SKalle Valo }
96131858805SGovind Singh module_exit(ath11k_ahb_exit);
96231858805SGovind Singh 
9636e0355afSGovind Singh MODULE_DESCRIPTION("Driver support for Qualcomm Technologies 802.11ax WLAN AHB devices");
96431858805SGovind Singh MODULE_LICENSE("Dual BSD/GPL");
965