1 // SPDX-License-Identifier: BSD-3-Clause-Clear
2 /*
3 * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
4 */
5
6 #include <linux/module.h>
7 #include <linux/platform_device.h>
8 #include <linux/of_device.h>
9 #include <linux/of.h>
10 #include <linux/dma-mapping.h>
11 #include "ahb.h"
12 #include "debug.h"
13 #include "hif.h"
14 #include <linux/remoteproc.h>
15
16 static const struct of_device_id ath11k_ahb_of_match[] = {
17 /* TODO: Should we change the compatible string to something similar
18 * to one that ath10k uses?
19 */
20 { .compatible = "qcom,ipq8074-wifi",
21 .data = (void *)ATH11K_HW_IPQ8074,
22 },
23 { .compatible = "qcom,ipq6018-wifi",
24 .data = (void *)ATH11K_HW_IPQ6018_HW10,
25 },
26 { }
27 };
28
29 MODULE_DEVICE_TABLE(of, ath11k_ahb_of_match);
30
31 static const struct ath11k_bus_params ath11k_ahb_bus_params = {
32 .mhi_support = false,
33 .m3_fw_support = false,
34 .fixed_bdf_addr = true,
35 .fixed_mem_region = true,
36 };
37
38 #define ATH11K_IRQ_CE0_OFFSET 4
39
40 static const char *irq_name[ATH11K_IRQ_NUM_MAX] = {
41 "misc-pulse1",
42 "misc-latch",
43 "sw-exception",
44 "watchdog",
45 "ce0",
46 "ce1",
47 "ce2",
48 "ce3",
49 "ce4",
50 "ce5",
51 "ce6",
52 "ce7",
53 "ce8",
54 "ce9",
55 "ce10",
56 "ce11",
57 "host2wbm-desc-feed",
58 "host2reo-re-injection",
59 "host2reo-command",
60 "host2rxdma-monitor-ring3",
61 "host2rxdma-monitor-ring2",
62 "host2rxdma-monitor-ring1",
63 "reo2ost-exception",
64 "wbm2host-rx-release",
65 "reo2host-status",
66 "reo2host-destination-ring4",
67 "reo2host-destination-ring3",
68 "reo2host-destination-ring2",
69 "reo2host-destination-ring1",
70 "rxdma2host-monitor-destination-mac3",
71 "rxdma2host-monitor-destination-mac2",
72 "rxdma2host-monitor-destination-mac1",
73 "ppdu-end-interrupts-mac3",
74 "ppdu-end-interrupts-mac2",
75 "ppdu-end-interrupts-mac1",
76 "rxdma2host-monitor-status-ring-mac3",
77 "rxdma2host-monitor-status-ring-mac2",
78 "rxdma2host-monitor-status-ring-mac1",
79 "host2rxdma-host-buf-ring-mac3",
80 "host2rxdma-host-buf-ring-mac2",
81 "host2rxdma-host-buf-ring-mac1",
82 "rxdma2host-destination-ring-mac3",
83 "rxdma2host-destination-ring-mac2",
84 "rxdma2host-destination-ring-mac1",
85 "host2tcl-input-ring4",
86 "host2tcl-input-ring3",
87 "host2tcl-input-ring2",
88 "host2tcl-input-ring1",
89 "wbm2host-tx-completions-ring3",
90 "wbm2host-tx-completions-ring2",
91 "wbm2host-tx-completions-ring1",
92 "tcl2host-status-ring",
93 };
94
95 /* enum ext_irq_num - irq numbers that can be used by external modules
96 * like datapath
97 */
98 enum ext_irq_num {
99 host2wbm_desc_feed = 16,
100 host2reo_re_injection,
101 host2reo_command,
102 host2rxdma_monitor_ring3,
103 host2rxdma_monitor_ring2,
104 host2rxdma_monitor_ring1,
105 reo2host_exception,
106 wbm2host_rx_release,
107 reo2host_status,
108 reo2host_destination_ring4,
109 reo2host_destination_ring3,
110 reo2host_destination_ring2,
111 reo2host_destination_ring1,
112 rxdma2host_monitor_destination_mac3,
113 rxdma2host_monitor_destination_mac2,
114 rxdma2host_monitor_destination_mac1,
115 ppdu_end_interrupts_mac3,
116 ppdu_end_interrupts_mac2,
117 ppdu_end_interrupts_mac1,
118 rxdma2host_monitor_status_ring_mac3,
119 rxdma2host_monitor_status_ring_mac2,
120 rxdma2host_monitor_status_ring_mac1,
121 host2rxdma_host_buf_ring_mac3,
122 host2rxdma_host_buf_ring_mac2,
123 host2rxdma_host_buf_ring_mac1,
124 rxdma2host_destination_ring_mac3,
125 rxdma2host_destination_ring_mac2,
126 rxdma2host_destination_ring_mac1,
127 host2tcl_input_ring4,
128 host2tcl_input_ring3,
129 host2tcl_input_ring2,
130 host2tcl_input_ring1,
131 wbm2host_tx_completions_ring3,
132 wbm2host_tx_completions_ring2,
133 wbm2host_tx_completions_ring1,
134 tcl2host_status_ring,
135 };
136
ath11k_ahb_read32(struct ath11k_base * ab,u32 offset)137 static inline u32 ath11k_ahb_read32(struct ath11k_base *ab, u32 offset)
138 {
139 return ioread32(ab->mem + offset);
140 }
141
ath11k_ahb_write32(struct ath11k_base * ab,u32 offset,u32 value)142 static inline void ath11k_ahb_write32(struct ath11k_base *ab, u32 offset, u32 value)
143 {
144 iowrite32(value, ab->mem + offset);
145 }
146
ath11k_ahb_kill_tasklets(struct ath11k_base * ab)147 static void ath11k_ahb_kill_tasklets(struct ath11k_base *ab)
148 {
149 int i;
150
151 for (i = 0; i < ab->hw_params.ce_count; i++) {
152 struct ath11k_ce_pipe *ce_pipe = &ab->ce.ce_pipe[i];
153
154 if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
155 continue;
156
157 tasklet_kill(&ce_pipe->intr_tq);
158 }
159 }
160
ath11k_ahb_ext_grp_disable(struct ath11k_ext_irq_grp * irq_grp)161 static void ath11k_ahb_ext_grp_disable(struct ath11k_ext_irq_grp *irq_grp)
162 {
163 int i;
164
165 for (i = 0; i < irq_grp->num_irq; i++)
166 disable_irq_nosync(irq_grp->ab->irq_num[irq_grp->irqs[i]]);
167 }
168
__ath11k_ahb_ext_irq_disable(struct ath11k_base * ab)169 static void __ath11k_ahb_ext_irq_disable(struct ath11k_base *ab)
170 {
171 int i;
172
173 for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
174 struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
175
176 ath11k_ahb_ext_grp_disable(irq_grp);
177
178 if (irq_grp->napi_enabled) {
179 napi_synchronize(&irq_grp->napi);
180 napi_disable(&irq_grp->napi);
181 irq_grp->napi_enabled = false;
182 }
183 }
184 }
185
ath11k_ahb_ext_grp_enable(struct ath11k_ext_irq_grp * irq_grp)186 static void ath11k_ahb_ext_grp_enable(struct ath11k_ext_irq_grp *irq_grp)
187 {
188 int i;
189
190 for (i = 0; i < irq_grp->num_irq; i++)
191 enable_irq(irq_grp->ab->irq_num[irq_grp->irqs[i]]);
192 }
193
ath11k_ahb_setbit32(struct ath11k_base * ab,u8 bit,u32 offset)194 static void ath11k_ahb_setbit32(struct ath11k_base *ab, u8 bit, u32 offset)
195 {
196 u32 val;
197
198 val = ath11k_ahb_read32(ab, offset);
199 ath11k_ahb_write32(ab, offset, val | BIT(bit));
200 }
201
ath11k_ahb_clearbit32(struct ath11k_base * ab,u8 bit,u32 offset)202 static void ath11k_ahb_clearbit32(struct ath11k_base *ab, u8 bit, u32 offset)
203 {
204 u32 val;
205
206 val = ath11k_ahb_read32(ab, offset);
207 ath11k_ahb_write32(ab, offset, val & ~BIT(bit));
208 }
209
ath11k_ahb_ce_irq_enable(struct ath11k_base * ab,u16 ce_id)210 static void ath11k_ahb_ce_irq_enable(struct ath11k_base *ab, u16 ce_id)
211 {
212 const struct ce_attr *ce_attr;
213
214 ce_attr = &ab->hw_params.host_ce_config[ce_id];
215 if (ce_attr->src_nentries)
216 ath11k_ahb_setbit32(ab, ce_id, CE_HOST_IE_ADDRESS);
217
218 if (ce_attr->dest_nentries) {
219 ath11k_ahb_setbit32(ab, ce_id, CE_HOST_IE_2_ADDRESS);
220 ath11k_ahb_setbit32(ab, ce_id + CE_HOST_IE_3_SHIFT,
221 CE_HOST_IE_3_ADDRESS);
222 }
223 }
224
ath11k_ahb_ce_irq_disable(struct ath11k_base * ab,u16 ce_id)225 static void ath11k_ahb_ce_irq_disable(struct ath11k_base *ab, u16 ce_id)
226 {
227 const struct ce_attr *ce_attr;
228
229 ce_attr = &ab->hw_params.host_ce_config[ce_id];
230 if (ce_attr->src_nentries)
231 ath11k_ahb_clearbit32(ab, ce_id, CE_HOST_IE_ADDRESS);
232
233 if (ce_attr->dest_nentries) {
234 ath11k_ahb_clearbit32(ab, ce_id, CE_HOST_IE_2_ADDRESS);
235 ath11k_ahb_clearbit32(ab, ce_id + CE_HOST_IE_3_SHIFT,
236 CE_HOST_IE_3_ADDRESS);
237 }
238 }
239
ath11k_ahb_sync_ce_irqs(struct ath11k_base * ab)240 static void ath11k_ahb_sync_ce_irqs(struct ath11k_base *ab)
241 {
242 int i;
243 int irq_idx;
244
245 for (i = 0; i < ab->hw_params.ce_count; i++) {
246 if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
247 continue;
248
249 irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
250 synchronize_irq(ab->irq_num[irq_idx]);
251 }
252 }
253
ath11k_ahb_sync_ext_irqs(struct ath11k_base * ab)254 static void ath11k_ahb_sync_ext_irqs(struct ath11k_base *ab)
255 {
256 int i, j;
257 int irq_idx;
258
259 for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
260 struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
261
262 for (j = 0; j < irq_grp->num_irq; j++) {
263 irq_idx = irq_grp->irqs[j];
264 synchronize_irq(ab->irq_num[irq_idx]);
265 }
266 }
267 }
268
ath11k_ahb_ce_irqs_enable(struct ath11k_base * ab)269 static void ath11k_ahb_ce_irqs_enable(struct ath11k_base *ab)
270 {
271 int i;
272
273 for (i = 0; i < ab->hw_params.ce_count; i++) {
274 if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
275 continue;
276 ath11k_ahb_ce_irq_enable(ab, i);
277 }
278 }
279
ath11k_ahb_ce_irqs_disable(struct ath11k_base * ab)280 static void ath11k_ahb_ce_irqs_disable(struct ath11k_base *ab)
281 {
282 int i;
283
284 for (i = 0; i < ab->hw_params.ce_count; i++) {
285 if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
286 continue;
287 ath11k_ahb_ce_irq_disable(ab, i);
288 }
289 }
290
ath11k_ahb_start(struct ath11k_base * ab)291 static int ath11k_ahb_start(struct ath11k_base *ab)
292 {
293 ath11k_ahb_ce_irqs_enable(ab);
294 ath11k_ce_rx_post_buf(ab);
295
296 return 0;
297 }
298
ath11k_ahb_ext_irq_enable(struct ath11k_base * ab)299 static void ath11k_ahb_ext_irq_enable(struct ath11k_base *ab)
300 {
301 int i;
302
303 for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
304 struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
305
306 if (!irq_grp->napi_enabled) {
307 napi_enable(&irq_grp->napi);
308 irq_grp->napi_enabled = true;
309 }
310 ath11k_ahb_ext_grp_enable(irq_grp);
311 }
312 }
313
ath11k_ahb_ext_irq_disable(struct ath11k_base * ab)314 static void ath11k_ahb_ext_irq_disable(struct ath11k_base *ab)
315 {
316 __ath11k_ahb_ext_irq_disable(ab);
317 ath11k_ahb_sync_ext_irqs(ab);
318 }
319
ath11k_ahb_stop(struct ath11k_base * ab)320 static void ath11k_ahb_stop(struct ath11k_base *ab)
321 {
322 if (!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))
323 ath11k_ahb_ce_irqs_disable(ab);
324 ath11k_ahb_sync_ce_irqs(ab);
325 ath11k_ahb_kill_tasklets(ab);
326 del_timer_sync(&ab->rx_replenish_retry);
327 ath11k_ce_cleanup_pipes(ab);
328 }
329
ath11k_ahb_power_up(struct ath11k_base * ab)330 static int ath11k_ahb_power_up(struct ath11k_base *ab)
331 {
332 struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
333 int ret;
334
335 ret = rproc_boot(ab_ahb->tgt_rproc);
336 if (ret)
337 ath11k_err(ab, "failed to boot the remote processor Q6\n");
338
339 return ret;
340 }
341
ath11k_ahb_power_down(struct ath11k_base * ab)342 static void ath11k_ahb_power_down(struct ath11k_base *ab)
343 {
344 struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
345
346 rproc_shutdown(ab_ahb->tgt_rproc);
347 }
348
ath11k_ahb_init_qmi_ce_config(struct ath11k_base * ab)349 static void ath11k_ahb_init_qmi_ce_config(struct ath11k_base *ab)
350 {
351 struct ath11k_qmi_ce_cfg *cfg = &ab->qmi.ce_cfg;
352
353 cfg->tgt_ce_len = ab->hw_params.target_ce_count;
354 cfg->tgt_ce = ab->hw_params.target_ce_config;
355 cfg->svc_to_ce_map_len = ab->hw_params.svc_to_ce_map_len;
356 cfg->svc_to_ce_map = ab->hw_params.svc_to_ce_map;
357 ab->qmi.service_ins_id = ATH11K_QMI_WLFW_SERVICE_INS_ID_V01_IPQ8074;
358 }
359
ath11k_ahb_free_ext_irq(struct ath11k_base * ab)360 static void ath11k_ahb_free_ext_irq(struct ath11k_base *ab)
361 {
362 int i, j;
363
364 for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
365 struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
366
367 for (j = 0; j < irq_grp->num_irq; j++)
368 free_irq(ab->irq_num[irq_grp->irqs[j]], irq_grp);
369 }
370 }
371
ath11k_ahb_free_irq(struct ath11k_base * ab)372 static void ath11k_ahb_free_irq(struct ath11k_base *ab)
373 {
374 int irq_idx;
375 int i;
376
377 for (i = 0; i < ab->hw_params.ce_count; i++) {
378 if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
379 continue;
380 irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
381 free_irq(ab->irq_num[irq_idx], &ab->ce.ce_pipe[i]);
382 }
383
384 ath11k_ahb_free_ext_irq(ab);
385 }
386
ath11k_ahb_ce_tasklet(struct tasklet_struct * t)387 static void ath11k_ahb_ce_tasklet(struct tasklet_struct *t)
388 {
389 struct ath11k_ce_pipe *ce_pipe = from_tasklet(ce_pipe, t, intr_tq);
390
391 ath11k_ce_per_engine_service(ce_pipe->ab, ce_pipe->pipe_num);
392
393 ath11k_ahb_ce_irq_enable(ce_pipe->ab, ce_pipe->pipe_num);
394 }
395
ath11k_ahb_ce_interrupt_handler(int irq,void * arg)396 static irqreturn_t ath11k_ahb_ce_interrupt_handler(int irq, void *arg)
397 {
398 struct ath11k_ce_pipe *ce_pipe = arg;
399
400 /* last interrupt received for this CE */
401 ce_pipe->timestamp = jiffies;
402
403 ath11k_ahb_ce_irq_disable(ce_pipe->ab, ce_pipe->pipe_num);
404
405 tasklet_schedule(&ce_pipe->intr_tq);
406
407 return IRQ_HANDLED;
408 }
409
ath11k_ahb_ext_grp_napi_poll(struct napi_struct * napi,int budget)410 static int ath11k_ahb_ext_grp_napi_poll(struct napi_struct *napi, int budget)
411 {
412 struct ath11k_ext_irq_grp *irq_grp = container_of(napi,
413 struct ath11k_ext_irq_grp,
414 napi);
415 struct ath11k_base *ab = irq_grp->ab;
416 int work_done;
417
418 work_done = ath11k_dp_service_srng(ab, irq_grp, budget);
419 if (work_done < budget) {
420 napi_complete_done(napi, work_done);
421 ath11k_ahb_ext_grp_enable(irq_grp);
422 }
423
424 if (work_done > budget)
425 work_done = budget;
426
427 return work_done;
428 }
429
ath11k_ahb_ext_interrupt_handler(int irq,void * arg)430 static irqreturn_t ath11k_ahb_ext_interrupt_handler(int irq, void *arg)
431 {
432 struct ath11k_ext_irq_grp *irq_grp = arg;
433
434 /* last interrupt received for this group */
435 irq_grp->timestamp = jiffies;
436
437 ath11k_ahb_ext_grp_disable(irq_grp);
438
439 napi_schedule(&irq_grp->napi);
440
441 return IRQ_HANDLED;
442 }
443
ath11k_ahb_ext_irq_config(struct ath11k_base * ab)444 static int ath11k_ahb_ext_irq_config(struct ath11k_base *ab)
445 {
446 struct ath11k_hw_params *hw = &ab->hw_params;
447 int i, j;
448 int irq;
449 int ret;
450
451 for (i = 0; i < ATH11K_EXT_IRQ_GRP_NUM_MAX; i++) {
452 struct ath11k_ext_irq_grp *irq_grp = &ab->ext_irq_grp[i];
453 u32 num_irq = 0;
454
455 irq_grp->ab = ab;
456 irq_grp->grp_id = i;
457 init_dummy_netdev(&irq_grp->napi_ndev);
458 netif_napi_add(&irq_grp->napi_ndev, &irq_grp->napi,
459 ath11k_ahb_ext_grp_napi_poll, NAPI_POLL_WEIGHT);
460
461 for (j = 0; j < ATH11K_EXT_IRQ_NUM_MAX; j++) {
462 if (ab->hw_params.ring_mask->tx[i] & BIT(j)) {
463 irq_grp->irqs[num_irq++] =
464 wbm2host_tx_completions_ring1 - j;
465 }
466
467 if (ab->hw_params.ring_mask->rx[i] & BIT(j)) {
468 irq_grp->irqs[num_irq++] =
469 reo2host_destination_ring1 - j;
470 }
471
472 if (ab->hw_params.ring_mask->rx_err[i] & BIT(j))
473 irq_grp->irqs[num_irq++] = reo2host_exception;
474
475 if (ab->hw_params.ring_mask->rx_wbm_rel[i] & BIT(j))
476 irq_grp->irqs[num_irq++] = wbm2host_rx_release;
477
478 if (ab->hw_params.ring_mask->reo_status[i] & BIT(j))
479 irq_grp->irqs[num_irq++] = reo2host_status;
480
481 if (j < ab->hw_params.max_radios) {
482 if (ab->hw_params.ring_mask->rxdma2host[i] & BIT(j)) {
483 irq_grp->irqs[num_irq++] =
484 rxdma2host_destination_ring_mac1 -
485 ath11k_hw_get_mac_from_pdev_id(hw, j);
486 }
487
488 if (ab->hw_params.ring_mask->host2rxdma[i] & BIT(j)) {
489 irq_grp->irqs[num_irq++] =
490 host2rxdma_host_buf_ring_mac1 -
491 ath11k_hw_get_mac_from_pdev_id(hw, j);
492 }
493
494 if (ab->hw_params.ring_mask->rx_mon_status[i] & BIT(j)) {
495 irq_grp->irqs[num_irq++] =
496 ppdu_end_interrupts_mac1 -
497 ath11k_hw_get_mac_from_pdev_id(hw, j);
498 irq_grp->irqs[num_irq++] =
499 rxdma2host_monitor_status_ring_mac1 -
500 ath11k_hw_get_mac_from_pdev_id(hw, j);
501 }
502 }
503 }
504 irq_grp->num_irq = num_irq;
505
506 for (j = 0; j < irq_grp->num_irq; j++) {
507 int irq_idx = irq_grp->irqs[j];
508
509 irq = platform_get_irq_byname(ab->pdev,
510 irq_name[irq_idx]);
511 ab->irq_num[irq_idx] = irq;
512 irq_set_status_flags(irq, IRQ_NOAUTOEN | IRQ_DISABLE_UNLAZY);
513 ret = request_irq(irq, ath11k_ahb_ext_interrupt_handler,
514 IRQF_TRIGGER_RISING,
515 irq_name[irq_idx], irq_grp);
516 if (ret) {
517 ath11k_err(ab, "failed request_irq for %d\n",
518 irq);
519 }
520 }
521 }
522
523 return 0;
524 }
525
ath11k_ahb_config_irq(struct ath11k_base * ab)526 static int ath11k_ahb_config_irq(struct ath11k_base *ab)
527 {
528 int irq, irq_idx, i;
529 int ret;
530
531 /* Configure CE irqs */
532 for (i = 0; i < ab->hw_params.ce_count; i++) {
533 struct ath11k_ce_pipe *ce_pipe = &ab->ce.ce_pipe[i];
534
535 if (ath11k_ce_get_attr_flags(ab, i) & CE_ATTR_DIS_INTR)
536 continue;
537
538 irq_idx = ATH11K_IRQ_CE0_OFFSET + i;
539
540 tasklet_setup(&ce_pipe->intr_tq, ath11k_ahb_ce_tasklet);
541 irq = platform_get_irq_byname(ab->pdev, irq_name[irq_idx]);
542 ret = request_irq(irq, ath11k_ahb_ce_interrupt_handler,
543 IRQF_TRIGGER_RISING, irq_name[irq_idx],
544 ce_pipe);
545 if (ret)
546 return ret;
547
548 ab->irq_num[irq_idx] = irq;
549 }
550
551 /* Configure external interrupts */
552 ret = ath11k_ahb_ext_irq_config(ab);
553
554 return ret;
555 }
556
ath11k_ahb_map_service_to_pipe(struct ath11k_base * ab,u16 service_id,u8 * ul_pipe,u8 * dl_pipe)557 static int ath11k_ahb_map_service_to_pipe(struct ath11k_base *ab, u16 service_id,
558 u8 *ul_pipe, u8 *dl_pipe)
559 {
560 const struct service_to_pipe *entry;
561 bool ul_set = false, dl_set = false;
562 int i;
563
564 for (i = 0; i < ab->hw_params.svc_to_ce_map_len; i++) {
565 entry = &ab->hw_params.svc_to_ce_map[i];
566
567 if (__le32_to_cpu(entry->service_id) != service_id)
568 continue;
569
570 switch (__le32_to_cpu(entry->pipedir)) {
571 case PIPEDIR_NONE:
572 break;
573 case PIPEDIR_IN:
574 WARN_ON(dl_set);
575 *dl_pipe = __le32_to_cpu(entry->pipenum);
576 dl_set = true;
577 break;
578 case PIPEDIR_OUT:
579 WARN_ON(ul_set);
580 *ul_pipe = __le32_to_cpu(entry->pipenum);
581 ul_set = true;
582 break;
583 case PIPEDIR_INOUT:
584 WARN_ON(dl_set);
585 WARN_ON(ul_set);
586 *dl_pipe = __le32_to_cpu(entry->pipenum);
587 *ul_pipe = __le32_to_cpu(entry->pipenum);
588 dl_set = true;
589 ul_set = true;
590 break;
591 }
592 }
593
594 if (WARN_ON(!ul_set || !dl_set))
595 return -ENOENT;
596
597 return 0;
598 }
599
600 static const struct ath11k_hif_ops ath11k_ahb_hif_ops = {
601 .start = ath11k_ahb_start,
602 .stop = ath11k_ahb_stop,
603 .read32 = ath11k_ahb_read32,
604 .write32 = ath11k_ahb_write32,
605 .irq_enable = ath11k_ahb_ext_irq_enable,
606 .irq_disable = ath11k_ahb_ext_irq_disable,
607 .map_service_to_pipe = ath11k_ahb_map_service_to_pipe,
608 .power_down = ath11k_ahb_power_down,
609 .power_up = ath11k_ahb_power_up,
610 };
611
ath11k_core_get_rproc(struct ath11k_base * ab)612 static int ath11k_core_get_rproc(struct ath11k_base *ab)
613 {
614 struct ath11k_ahb *ab_ahb = ath11k_ahb_priv(ab);
615 struct device *dev = ab->dev;
616 struct rproc *prproc;
617 phandle rproc_phandle;
618
619 if (of_property_read_u32(dev->of_node, "qcom,rproc", &rproc_phandle)) {
620 ath11k_err(ab, "failed to get q6_rproc handle\n");
621 return -ENOENT;
622 }
623
624 prproc = rproc_get_by_phandle(rproc_phandle);
625 if (!prproc) {
626 ath11k_err(ab, "failed to get rproc\n");
627 return -EINVAL;
628 }
629 ab_ahb->tgt_rproc = prproc;
630
631 return 0;
632 }
633
ath11k_ahb_probe(struct platform_device * pdev)634 static int ath11k_ahb_probe(struct platform_device *pdev)
635 {
636 struct ath11k_base *ab;
637 const struct of_device_id *of_id;
638 struct resource *mem_res;
639 void __iomem *mem;
640 int ret;
641
642 of_id = of_match_device(ath11k_ahb_of_match, &pdev->dev);
643 if (!of_id) {
644 dev_err(&pdev->dev, "failed to find matching device tree id\n");
645 return -EINVAL;
646 }
647
648 mem = devm_platform_get_and_ioremap_resource(pdev, 0, &mem_res);
649 if (IS_ERR(mem)) {
650 dev_err(&pdev->dev, "ioremap error\n");
651 return PTR_ERR(mem);
652 }
653
654 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
655 if (ret) {
656 dev_err(&pdev->dev, "failed to set 32-bit consistent dma\n");
657 return ret;
658 }
659
660 ab = ath11k_core_alloc(&pdev->dev, sizeof(struct ath11k_ahb),
661 ATH11K_BUS_AHB,
662 &ath11k_ahb_bus_params);
663 if (!ab) {
664 dev_err(&pdev->dev, "failed to allocate ath11k base\n");
665 return -ENOMEM;
666 }
667
668 ab->hif.ops = &ath11k_ahb_hif_ops;
669 ab->pdev = pdev;
670 ab->hw_rev = (enum ath11k_hw_rev)of_id->data;
671 ab->mem = mem;
672 ab->mem_len = resource_size(mem_res);
673 platform_set_drvdata(pdev, ab);
674
675 ret = ath11k_core_pre_init(ab);
676 if (ret)
677 goto err_core_free;
678
679 ret = ath11k_hal_srng_init(ab);
680 if (ret)
681 goto err_core_free;
682
683 ret = ath11k_ce_alloc_pipes(ab);
684 if (ret) {
685 ath11k_err(ab, "failed to allocate ce pipes: %d\n", ret);
686 goto err_hal_srng_deinit;
687 }
688
689 ath11k_ahb_init_qmi_ce_config(ab);
690
691 ret = ath11k_core_get_rproc(ab);
692 if (ret) {
693 ath11k_err(ab, "failed to get rproc: %d\n", ret);
694 goto err_ce_free;
695 }
696
697 ret = ath11k_core_init(ab);
698 if (ret) {
699 ath11k_err(ab, "failed to init core: %d\n", ret);
700 goto err_ce_free;
701 }
702
703 ret = ath11k_ahb_config_irq(ab);
704 if (ret) {
705 ath11k_err(ab, "failed to configure irq: %d\n", ret);
706 goto err_ce_free;
707 }
708
709 return 0;
710
711 err_ce_free:
712 ath11k_ce_free_pipes(ab);
713
714 err_hal_srng_deinit:
715 ath11k_hal_srng_deinit(ab);
716
717 err_core_free:
718 ath11k_core_free(ab);
719 platform_set_drvdata(pdev, NULL);
720
721 return ret;
722 }
723
ath11k_ahb_remove(struct platform_device * pdev)724 static int ath11k_ahb_remove(struct platform_device *pdev)
725 {
726 struct ath11k_base *ab = platform_get_drvdata(pdev);
727 unsigned long left;
728
729 reinit_completion(&ab->driver_recovery);
730
731 if (test_bit(ATH11K_FLAG_RECOVERY, &ab->dev_flags)) {
732 left = wait_for_completion_timeout(&ab->driver_recovery,
733 ATH11K_AHB_RECOVERY_TIMEOUT);
734 if (!left)
735 ath11k_warn(ab, "failed to receive recovery response completion\n");
736 }
737
738 set_bit(ATH11K_FLAG_UNREGISTERING, &ab->dev_flags);
739 cancel_work_sync(&ab->restart_work);
740
741 ath11k_core_deinit(ab);
742 ath11k_ahb_free_irq(ab);
743
744 ath11k_hal_srng_deinit(ab);
745 ath11k_ce_free_pipes(ab);
746 ath11k_core_free(ab);
747 platform_set_drvdata(pdev, NULL);
748
749 return 0;
750 }
751
752 static struct platform_driver ath11k_ahb_driver = {
753 .driver = {
754 .name = "ath11k",
755 .of_match_table = ath11k_ahb_of_match,
756 },
757 .probe = ath11k_ahb_probe,
758 .remove = ath11k_ahb_remove,
759 };
760
ath11k_ahb_init(void)761 static int ath11k_ahb_init(void)
762 {
763 return platform_driver_register(&ath11k_ahb_driver);
764 }
765 module_init(ath11k_ahb_init);
766
ath11k_ahb_exit(void)767 static void ath11k_ahb_exit(void)
768 {
769 platform_driver_unregister(&ath11k_ahb_driver);
770 }
771 module_exit(ath11k_ahb_exit);
772
773 MODULE_DESCRIPTION("Driver support for Qualcomm Technologies 802.11ax WLAN AHB devices");
774 MODULE_LICENSE("Dual BSD/GPL");
775