2 * Copyright (c) 2005-2011 Atheros Communications Inc.
3 * Copyright (c) 2011-2013 Qualcomm Atheros, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 #include <linux/pci.h>
19 #include <linux/module.h>
20 #include <linux/interrupt.h>
21 #include <linux/spinlock.h>
22 #include <linux/bitops.h>
27 #include "targaddrs.h"
36 enum ath10k_pci_irq_mode {
37 ATH10K_PCI_IRQ_AUTO = 0,
38 ATH10K_PCI_IRQ_LEGACY = 1,
39 ATH10K_PCI_IRQ_MSI = 2,
42 enum ath10k_pci_reset_mode {
43 ATH10K_PCI_RESET_AUTO = 0,
44 ATH10K_PCI_RESET_WARM_ONLY = 1,
47 static unsigned int ath10k_pci_irq_mode = ATH10K_PCI_IRQ_AUTO;
48 static unsigned int ath10k_pci_reset_mode = ATH10K_PCI_RESET_AUTO;
50 module_param_named(irq_mode, ath10k_pci_irq_mode, uint, 0644);
51 MODULE_PARM_DESC(irq_mode, "0: auto, 1: legacy, 2: msi (default: 0)");
53 module_param_named(reset_mode, ath10k_pci_reset_mode, uint, 0644);
54 MODULE_PARM_DESC(reset_mode, "0: auto, 1: warm only (default: 0)");
56 /* how long wait to wait for target to initialise, in ms */
57 #define ATH10K_PCI_TARGET_WAIT 3000
58 #define ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS 3
60 static const struct pci_device_id ath10k_pci_id_table[] = {
61 { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */
62 { PCI_VDEVICE(ATHEROS, QCA6164_2_1_DEVICE_ID) }, /* PCI-E QCA6164 V2.1 */
63 { PCI_VDEVICE(ATHEROS, QCA6174_2_1_DEVICE_ID) }, /* PCI-E QCA6174 V2.1 */
64 { PCI_VDEVICE(ATHEROS, QCA99X0_2_0_DEVICE_ID) }, /* PCI-E QCA99X0 V2 */
65 { PCI_VDEVICE(ATHEROS, QCA9377_1_0_DEVICE_ID) }, /* PCI-E QCA9377 V1 */
69 static const struct ath10k_pci_supp_chip ath10k_pci_supp_chips[] = {
70 /* QCA988X pre 2.0 chips are not supported because they need some nasty
71 * hacks. ath10k doesn't have them and these devices crash horribly
74 { QCA988X_2_0_DEVICE_ID, QCA988X_HW_2_0_CHIP_ID_REV },
76 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
77 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
78 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
79 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
80 { QCA6164_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
82 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_1_CHIP_ID_REV },
83 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_2_2_CHIP_ID_REV },
84 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_0_CHIP_ID_REV },
85 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_1_CHIP_ID_REV },
86 { QCA6174_2_1_DEVICE_ID, QCA6174_HW_3_2_CHIP_ID_REV },
88 { QCA99X0_2_0_DEVICE_ID, QCA99X0_HW_2_0_CHIP_ID_REV },
90 { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_0_CHIP_ID_REV },
91 { QCA9377_1_0_DEVICE_ID, QCA9377_HW_1_1_CHIP_ID_REV },
94 static void ath10k_pci_buffer_cleanup(struct ath10k *ar);
95 static int ath10k_pci_cold_reset(struct ath10k *ar);
96 static int ath10k_pci_safe_chip_reset(struct ath10k *ar);
97 static int ath10k_pci_init_irq(struct ath10k *ar);
98 static int ath10k_pci_deinit_irq(struct ath10k *ar);
99 static int ath10k_pci_request_irq(struct ath10k *ar);
100 static void ath10k_pci_free_irq(struct ath10k *ar);
101 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
102 struct ath10k_ce_pipe *rx_pipe,
103 struct bmi_xfer *xfer);
104 static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar);
105 static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state);
106 static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
107 static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state);
108 static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state);
109 static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state);
110 static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state);
112 static struct ce_attr host_ce_config_wlan[] = {
113 /* CE0: host->target HTC control and raw streams */
115 .flags = CE_ATTR_FLAGS,
119 .send_cb = ath10k_pci_htc_tx_cb,
122 /* CE1: target->host HTT + HTC control */
124 .flags = CE_ATTR_FLAGS,
127 .dest_nentries = 512,
128 .recv_cb = ath10k_pci_htt_htc_rx_cb,
131 /* CE2: target->host WMI */
133 .flags = CE_ATTR_FLAGS,
136 .dest_nentries = 128,
137 .recv_cb = ath10k_pci_htc_rx_cb,
140 /* CE3: host->target WMI */
142 .flags = CE_ATTR_FLAGS,
146 .send_cb = ath10k_pci_htc_tx_cb,
149 /* CE4: host->target HTT */
151 .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
152 .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES,
155 .send_cb = ath10k_pci_htt_tx_cb,
158 /* CE5: target->host HTT (HIF->HTT) */
160 .flags = CE_ATTR_FLAGS,
163 .dest_nentries = 512,
164 .recv_cb = ath10k_pci_htt_rx_cb,
167 /* CE6: target autonomous hif_memcpy */
169 .flags = CE_ATTR_FLAGS,
175 /* CE7: ce_diag, the Diagnostic Window */
177 .flags = CE_ATTR_FLAGS,
179 .src_sz_max = DIAG_TRANSFER_LIMIT,
183 /* CE8: target->host pktlog */
185 .flags = CE_ATTR_FLAGS,
188 .dest_nentries = 128,
189 .recv_cb = ath10k_pci_pktlog_rx_cb,
192 /* CE9 target autonomous qcache memcpy */
194 .flags = CE_ATTR_FLAGS,
200 /* CE10: target autonomous hif memcpy */
202 .flags = CE_ATTR_FLAGS,
208 /* CE11: target autonomous hif memcpy */
210 .flags = CE_ATTR_FLAGS,
217 /* Target firmware's Copy Engine configuration. */
218 static struct ce_pipe_config target_ce_config_wlan[] = {
219 /* CE0: host->target HTC control and raw streams */
221 .pipenum = __cpu_to_le32(0),
222 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
223 .nentries = __cpu_to_le32(32),
224 .nbytes_max = __cpu_to_le32(256),
225 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
226 .reserved = __cpu_to_le32(0),
229 /* CE1: target->host HTT + HTC control */
231 .pipenum = __cpu_to_le32(1),
232 .pipedir = __cpu_to_le32(PIPEDIR_IN),
233 .nentries = __cpu_to_le32(32),
234 .nbytes_max = __cpu_to_le32(2048),
235 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
236 .reserved = __cpu_to_le32(0),
239 /* CE2: target->host WMI */
241 .pipenum = __cpu_to_le32(2),
242 .pipedir = __cpu_to_le32(PIPEDIR_IN),
243 .nentries = __cpu_to_le32(64),
244 .nbytes_max = __cpu_to_le32(2048),
245 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
246 .reserved = __cpu_to_le32(0),
249 /* CE3: host->target WMI */
251 .pipenum = __cpu_to_le32(3),
252 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
253 .nentries = __cpu_to_le32(32),
254 .nbytes_max = __cpu_to_le32(2048),
255 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
256 .reserved = __cpu_to_le32(0),
259 /* CE4: host->target HTT */
261 .pipenum = __cpu_to_le32(4),
262 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
263 .nentries = __cpu_to_le32(256),
264 .nbytes_max = __cpu_to_le32(256),
265 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
266 .reserved = __cpu_to_le32(0),
269 /* NB: 50% of src nentries, since tx has 2 frags */
271 /* CE5: target->host HTT (HIF->HTT) */
273 .pipenum = __cpu_to_le32(5),
274 .pipedir = __cpu_to_le32(PIPEDIR_IN),
275 .nentries = __cpu_to_le32(32),
276 .nbytes_max = __cpu_to_le32(512),
277 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
278 .reserved = __cpu_to_le32(0),
281 /* CE6: Reserved for target autonomous hif_memcpy */
283 .pipenum = __cpu_to_le32(6),
284 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
285 .nentries = __cpu_to_le32(32),
286 .nbytes_max = __cpu_to_le32(4096),
287 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
288 .reserved = __cpu_to_le32(0),
291 /* CE7 used only by Host */
293 .pipenum = __cpu_to_le32(7),
294 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
295 .nentries = __cpu_to_le32(0),
296 .nbytes_max = __cpu_to_le32(0),
297 .flags = __cpu_to_le32(0),
298 .reserved = __cpu_to_le32(0),
301 /* CE8 target->host packtlog */
303 .pipenum = __cpu_to_le32(8),
304 .pipedir = __cpu_to_le32(PIPEDIR_IN),
305 .nentries = __cpu_to_le32(64),
306 .nbytes_max = __cpu_to_le32(2048),
307 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
308 .reserved = __cpu_to_le32(0),
311 /* CE9 target autonomous qcache memcpy */
313 .pipenum = __cpu_to_le32(9),
314 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
315 .nentries = __cpu_to_le32(32),
316 .nbytes_max = __cpu_to_le32(2048),
317 .flags = __cpu_to_le32(CE_ATTR_FLAGS | CE_ATTR_DIS_INTR),
318 .reserved = __cpu_to_le32(0),
321 /* It not necessary to send target wlan configuration for CE10 & CE11
322 * as these CEs are not actively used in target.
327 * Map from service/endpoint to Copy Engine.
328 * This table is derived from the CE_PCI TABLE, above.
329 * It is passed to the Target at startup for use by firmware.
331 static struct service_to_pipe target_service_to_ce_map_wlan[] = {
333 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
334 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
338 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
339 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
343 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
344 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
348 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
349 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
353 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
354 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
358 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
359 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
363 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
364 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
368 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
369 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
373 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
374 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
378 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
379 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
383 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
384 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
388 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
389 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
393 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
394 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
398 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
399 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
403 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
404 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
408 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
409 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
413 /* (Additions here) */
422 static bool ath10k_pci_is_awake(struct ath10k *ar)
424 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
425 u32 val = ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
428 return RTC_STATE_V_GET(val) == RTC_STATE_V_ON;
431 static void __ath10k_pci_wake(struct ath10k *ar)
433 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
435 lockdep_assert_held(&ar_pci->ps_lock);
437 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake reg refcount %lu awake %d\n",
438 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
440 iowrite32(PCIE_SOC_WAKE_V_MASK,
441 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
442 PCIE_SOC_WAKE_ADDRESS);
445 static void __ath10k_pci_sleep(struct ath10k *ar)
447 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
449 lockdep_assert_held(&ar_pci->ps_lock);
451 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep reg refcount %lu awake %d\n",
452 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
454 iowrite32(PCIE_SOC_WAKE_RESET,
455 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
456 PCIE_SOC_WAKE_ADDRESS);
457 ar_pci->ps_awake = false;
460 static int ath10k_pci_wake_wait(struct ath10k *ar)
465 while (tot_delay < PCIE_WAKE_TIMEOUT) {
466 if (ath10k_pci_is_awake(ar)) {
467 if (tot_delay > PCIE_WAKE_LATE_US)
468 ath10k_warn(ar, "device wakeup took %d ms which is unusally long, otherwise it works normally.\n",
474 tot_delay += curr_delay;
483 static int ath10k_pci_force_wake(struct ath10k *ar)
485 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
492 spin_lock_irqsave(&ar_pci->ps_lock, flags);
494 if (!ar_pci->ps_awake) {
495 iowrite32(PCIE_SOC_WAKE_V_MASK,
496 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
497 PCIE_SOC_WAKE_ADDRESS);
499 ret = ath10k_pci_wake_wait(ar);
501 ar_pci->ps_awake = true;
504 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
509 static void ath10k_pci_force_sleep(struct ath10k *ar)
511 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
514 spin_lock_irqsave(&ar_pci->ps_lock, flags);
516 iowrite32(PCIE_SOC_WAKE_RESET,
517 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
518 PCIE_SOC_WAKE_ADDRESS);
519 ar_pci->ps_awake = false;
521 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
524 static int ath10k_pci_wake(struct ath10k *ar)
526 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
530 if (ar_pci->pci_ps == 0)
533 spin_lock_irqsave(&ar_pci->ps_lock, flags);
535 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps wake refcount %lu awake %d\n",
536 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
538 /* This function can be called very frequently. To avoid excessive
539 * CPU stalls for MMIO reads use a cache var to hold the device state.
541 if (!ar_pci->ps_awake) {
542 __ath10k_pci_wake(ar);
544 ret = ath10k_pci_wake_wait(ar);
546 ar_pci->ps_awake = true;
550 ar_pci->ps_wake_refcount++;
551 WARN_ON(ar_pci->ps_wake_refcount == 0);
554 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
559 static void ath10k_pci_sleep(struct ath10k *ar)
561 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
564 if (ar_pci->pci_ps == 0)
567 spin_lock_irqsave(&ar_pci->ps_lock, flags);
569 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps sleep refcount %lu awake %d\n",
570 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
572 if (WARN_ON(ar_pci->ps_wake_refcount == 0))
575 ar_pci->ps_wake_refcount--;
577 mod_timer(&ar_pci->ps_timer, jiffies +
578 msecs_to_jiffies(ATH10K_PCI_SLEEP_GRACE_PERIOD_MSEC));
581 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
584 static void ath10k_pci_ps_timer(unsigned long ptr)
586 struct ath10k *ar = (void *)ptr;
587 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
590 spin_lock_irqsave(&ar_pci->ps_lock, flags);
592 ath10k_dbg(ar, ATH10K_DBG_PCI_PS, "pci ps timer refcount %lu awake %d\n",
593 ar_pci->ps_wake_refcount, ar_pci->ps_awake);
595 if (ar_pci->ps_wake_refcount > 0)
598 __ath10k_pci_sleep(ar);
601 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
604 static void ath10k_pci_sleep_sync(struct ath10k *ar)
606 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
609 if (ar_pci->pci_ps == 0) {
610 ath10k_pci_force_sleep(ar);
614 del_timer_sync(&ar_pci->ps_timer);
616 spin_lock_irqsave(&ar_pci->ps_lock, flags);
617 WARN_ON(ar_pci->ps_wake_refcount > 0);
618 __ath10k_pci_sleep(ar);
619 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
622 static void ath10k_bus_pci_write32(struct ath10k *ar, u32 offset, u32 value)
624 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
627 if (unlikely(offset + sizeof(value) > ar_pci->mem_len)) {
628 ath10k_warn(ar, "refusing to write mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
629 offset, offset + sizeof(value), ar_pci->mem_len);
633 ret = ath10k_pci_wake(ar);
635 ath10k_warn(ar, "failed to wake target for write32 of 0x%08x at 0x%08x: %d\n",
640 iowrite32(value, ar_pci->mem + offset);
641 ath10k_pci_sleep(ar);
644 static u32 ath10k_bus_pci_read32(struct ath10k *ar, u32 offset)
646 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
650 if (unlikely(offset + sizeof(val) > ar_pci->mem_len)) {
651 ath10k_warn(ar, "refusing to read mmio out of bounds at 0x%08x - 0x%08zx (max 0x%08zx)\n",
652 offset, offset + sizeof(val), ar_pci->mem_len);
656 ret = ath10k_pci_wake(ar);
658 ath10k_warn(ar, "failed to wake target for read32 at 0x%08x: %d\n",
663 val = ioread32(ar_pci->mem + offset);
664 ath10k_pci_sleep(ar);
669 inline void ath10k_pci_write32(struct ath10k *ar, u32 offset, u32 value)
671 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
673 ar_pci->bus_ops->write32(ar, offset, value);
676 inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
678 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
680 return ar_pci->bus_ops->read32(ar, offset);
683 u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr)
685 return ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + addr);
688 void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val)
690 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + addr, val);
693 u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
695 return ath10k_pci_read32(ar, PCIE_LOCAL_BASE_ADDRESS + addr);
698 void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
700 ath10k_pci_write32(ar, PCIE_LOCAL_BASE_ADDRESS + addr, val);
703 bool ath10k_pci_irq_pending(struct ath10k *ar)
707 /* Check if the shared legacy irq is for us */
708 cause = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
709 PCIE_INTR_CAUSE_ADDRESS);
710 if (cause & (PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL))
716 void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar)
718 /* IMPORTANT: INTR_CLR register has to be set after
719 * INTR_ENABLE is set to 0, otherwise interrupt can not be
721 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
723 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS,
724 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
726 /* IMPORTANT: this extra read transaction is required to
727 * flush the posted write buffer. */
728 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
729 PCIE_INTR_ENABLE_ADDRESS);
732 void ath10k_pci_enable_legacy_irq(struct ath10k *ar)
734 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
735 PCIE_INTR_ENABLE_ADDRESS,
736 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
738 /* IMPORTANT: this extra read transaction is required to
739 * flush the posted write buffer. */
740 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
741 PCIE_INTR_ENABLE_ADDRESS);
744 static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar)
746 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
748 if (ar_pci->num_msi_intrs > 1)
751 if (ar_pci->num_msi_intrs == 1)
757 static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe)
759 struct ath10k *ar = pipe->hif_ce_state;
760 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
761 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
766 skb = dev_alloc_skb(pipe->buf_sz);
770 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
772 paddr = dma_map_single(ar->dev, skb->data,
773 skb->len + skb_tailroom(skb),
775 if (unlikely(dma_mapping_error(ar->dev, paddr))) {
776 ath10k_warn(ar, "failed to dma map pci rx buf\n");
777 dev_kfree_skb_any(skb);
781 ATH10K_SKB_RXCB(skb)->paddr = paddr;
783 spin_lock_bh(&ar_pci->ce_lock);
784 ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr);
785 spin_unlock_bh(&ar_pci->ce_lock);
787 dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
789 dev_kfree_skb_any(skb);
796 static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
798 struct ath10k *ar = pipe->hif_ce_state;
799 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
800 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
803 if (pipe->buf_sz == 0)
806 if (!ce_pipe->dest_ring)
809 spin_lock_bh(&ar_pci->ce_lock);
810 num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
811 spin_unlock_bh(&ar_pci->ce_lock);
814 ret = __ath10k_pci_rx_post_buf(pipe);
818 ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
819 mod_timer(&ar_pci->rx_post_retry, jiffies +
820 ATH10K_PCI_RX_POST_RETRY_MS);
827 void ath10k_pci_rx_post(struct ath10k *ar)
829 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
832 for (i = 0; i < CE_COUNT; i++)
833 ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
836 void ath10k_pci_rx_replenish_retry(unsigned long ptr)
838 struct ath10k *ar = (void *)ptr;
840 ath10k_pci_rx_post(ar);
843 static u32 ath10k_pci_targ_cpu_to_ce_addr(struct ath10k *ar, u32 addr)
847 switch (ar->hw_rev) {
848 case ATH10K_HW_QCA988X:
849 case ATH10K_HW_QCA6174:
850 case ATH10K_HW_QCA9377:
851 val = (ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
855 case ATH10K_HW_QCA99X0:
856 case ATH10K_HW_QCA4019:
857 val = ath10k_pci_read32(ar, PCIE_BAR_REG_ADDRESS);
861 val |= 0x100000 | (addr & 0xfffff);
866 * Diagnostic read/write access is provided for startup/config/debug usage.
867 * Caller must guarantee proper alignment, when applicable, and single user
870 static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
873 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
876 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
877 struct ath10k_ce_pipe *ce_diag;
878 /* Host buffer address in CE space */
880 dma_addr_t ce_data_base = 0;
881 void *data_buf = NULL;
884 spin_lock_bh(&ar_pci->ce_lock);
886 ce_diag = ar_pci->ce_diag;
889 * Allocate a temporary bounce buffer to hold caller's data
890 * to be DMA'ed from Target. This guarantees
891 * 1) 4-byte alignment
892 * 2) Buffer in DMA-able space
894 orig_nbytes = nbytes;
895 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
904 memset(data_buf, 0, orig_nbytes);
906 remaining_bytes = orig_nbytes;
907 ce_data = ce_data_base;
908 while (remaining_bytes) {
909 nbytes = min_t(unsigned int, remaining_bytes,
910 DIAG_TRANSFER_LIMIT);
912 ret = __ath10k_ce_rx_post_buf(ce_diag, &ce_data, ce_data);
916 /* Request CE to send from Target(!) address to Host buffer */
918 * The address supplied by the caller is in the
919 * Target CPU virtual address space.
921 * In order to use this address with the diagnostic CE,
922 * convert it from Target CPU virtual address space
923 * to CE address space
925 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
927 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)address, nbytes, 0,
933 while (ath10k_ce_completed_send_next_nolock(ce_diag,
936 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
943 while (ath10k_ce_completed_recv_next_nolock(ce_diag,
949 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
955 if (nbytes != completed_nbytes) {
960 if (*buf != ce_data) {
965 remaining_bytes -= nbytes;
972 memcpy(data, data_buf, orig_nbytes);
974 ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
978 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
981 spin_unlock_bh(&ar_pci->ce_lock);
986 static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
991 ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
992 *value = __le32_to_cpu(val);
997 static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
1000 u32 host_addr, addr;
1003 host_addr = host_interest_item_address(src);
1005 ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
1007 ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
1012 ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
1014 ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
1022 #define ath10k_pci_diag_read_hi(ar, dest, src, len) \
1023 __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
1025 int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
1026 const void *data, int nbytes)
1028 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1031 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
1032 struct ath10k_ce_pipe *ce_diag;
1033 void *data_buf = NULL;
1034 u32 ce_data; /* Host buffer address in CE space */
1035 dma_addr_t ce_data_base = 0;
1038 spin_lock_bh(&ar_pci->ce_lock);
1040 ce_diag = ar_pci->ce_diag;
1043 * Allocate a temporary bounce buffer to hold caller's data
1044 * to be DMA'ed to Target. This guarantees
1045 * 1) 4-byte alignment
1046 * 2) Buffer in DMA-able space
1048 orig_nbytes = nbytes;
1049 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
1058 /* Copy caller's data to allocated DMA buf */
1059 memcpy(data_buf, data, orig_nbytes);
1062 * The address supplied by the caller is in the
1063 * Target CPU virtual address space.
1065 * In order to use this address with the diagnostic CE,
1067 * Target CPU virtual address space
1071 address = ath10k_pci_targ_cpu_to_ce_addr(ar, address);
1073 remaining_bytes = orig_nbytes;
1074 ce_data = ce_data_base;
1075 while (remaining_bytes) {
1076 /* FIXME: check cast */
1077 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
1079 /* Set up to receive directly into Target(!) address */
1080 ret = __ath10k_ce_rx_post_buf(ce_diag, &address, address);
1085 * Request CE to send caller-supplied data that
1086 * was copied to bounce buffer to Target(!) address.
1088 ret = ath10k_ce_send_nolock(ce_diag, NULL, (u32)ce_data,
1094 while (ath10k_ce_completed_send_next_nolock(ce_diag,
1098 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1105 while (ath10k_ce_completed_recv_next_nolock(ce_diag,
1111 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
1117 if (nbytes != completed_nbytes) {
1122 if (*buf != address) {
1127 remaining_bytes -= nbytes;
1134 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
1139 ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
1142 spin_unlock_bh(&ar_pci->ce_lock);
1147 static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
1149 __le32 val = __cpu_to_le32(value);
1151 return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
1154 /* Called by lower (CE) layer when a send to Target completes. */
1155 static void ath10k_pci_htc_tx_cb(struct ath10k_ce_pipe *ce_state)
1157 struct ath10k *ar = ce_state->ar;
1158 struct sk_buff_head list;
1159 struct sk_buff *skb;
1161 __skb_queue_head_init(&list);
1162 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
1163 /* no need to call tx completion for NULL pointers */
1167 __skb_queue_tail(&list, skb);
1170 while ((skb = __skb_dequeue(&list)))
1171 ath10k_htc_tx_completion_handler(ar, skb);
1174 static void ath10k_pci_process_rx_cb(struct ath10k_ce_pipe *ce_state,
1175 void (*callback)(struct ath10k *ar,
1176 struct sk_buff *skb))
1178 struct ath10k *ar = ce_state->ar;
1179 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1180 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
1181 struct sk_buff *skb;
1182 struct sk_buff_head list;
1183 void *transfer_context;
1184 unsigned int nbytes, max_nbytes;
1186 __skb_queue_head_init(&list);
1187 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
1189 skb = transfer_context;
1190 max_nbytes = skb->len + skb_tailroom(skb);
1191 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1192 max_nbytes, DMA_FROM_DEVICE);
1194 if (unlikely(max_nbytes < nbytes)) {
1195 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
1196 nbytes, max_nbytes);
1197 dev_kfree_skb_any(skb);
1201 skb_put(skb, nbytes);
1202 __skb_queue_tail(&list, skb);
1205 while ((skb = __skb_dequeue(&list))) {
1206 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1207 ce_state->id, skb->len);
1208 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1209 skb->data, skb->len);
1214 ath10k_pci_rx_post_pipe(pipe_info);
1217 static void ath10k_pci_process_htt_rx_cb(struct ath10k_ce_pipe *ce_state,
1218 void (*callback)(struct ath10k *ar,
1219 struct sk_buff *skb))
1221 struct ath10k *ar = ce_state->ar;
1222 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1223 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
1224 struct ath10k_ce_pipe *ce_pipe = pipe_info->ce_hdl;
1225 struct sk_buff *skb;
1226 struct sk_buff_head list;
1227 void *transfer_context;
1228 unsigned int nbytes, max_nbytes, nentries;
1231 /* No need to aquire ce_lock for CE5, since this is the only place CE5
1232 * is processed other than init and deinit. Before releasing CE5
1233 * buffers, interrupts are disabled. Thus CE5 access is serialized.
1235 __skb_queue_head_init(&list);
1236 while (ath10k_ce_completed_recv_next_nolock(ce_state, &transfer_context,
1238 skb = transfer_context;
1239 max_nbytes = skb->len + skb_tailroom(skb);
1241 if (unlikely(max_nbytes < nbytes)) {
1242 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
1243 nbytes, max_nbytes);
1247 dma_sync_single_for_cpu(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1248 max_nbytes, DMA_FROM_DEVICE);
1249 skb_put(skb, nbytes);
1250 __skb_queue_tail(&list, skb);
1253 nentries = skb_queue_len(&list);
1254 while ((skb = __skb_dequeue(&list))) {
1255 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci rx ce pipe %d len %d\n",
1256 ce_state->id, skb->len);
1257 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci rx: ",
1258 skb->data, skb->len);
1260 orig_len = skb->len;
1262 skb_push(skb, orig_len - skb->len);
1263 skb_reset_tail_pointer(skb);
1266 /*let device gain the buffer again*/
1267 dma_sync_single_for_device(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1268 skb->len + skb_tailroom(skb),
1271 ath10k_ce_rx_update_write_idx(ce_pipe, nentries);
1274 /* Called by lower (CE) layer when data is received from the Target. */
1275 static void ath10k_pci_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1277 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1280 static void ath10k_pci_htt_htc_rx_cb(struct ath10k_ce_pipe *ce_state)
1282 /* CE4 polling needs to be done whenever CE pipe which transports
1283 * HTT Rx (target->host) is processed.
1285 ath10k_ce_per_engine_service(ce_state->ar, 4);
1287 ath10k_pci_process_rx_cb(ce_state, ath10k_htc_rx_completion_handler);
1290 /* Called by lower (CE) layer when data is received from the Target.
1291 * Only 10.4 firmware uses separate CE to transfer pktlog data.
1293 static void ath10k_pci_pktlog_rx_cb(struct ath10k_ce_pipe *ce_state)
1295 ath10k_pci_process_rx_cb(ce_state,
1296 ath10k_htt_rx_pktlog_completion_handler);
1299 /* Called by lower (CE) layer when a send to HTT Target completes. */
1300 static void ath10k_pci_htt_tx_cb(struct ath10k_ce_pipe *ce_state)
1302 struct ath10k *ar = ce_state->ar;
1303 struct sk_buff *skb;
1305 while (ath10k_ce_completed_send_next(ce_state, (void **)&skb) == 0) {
1306 /* no need to call tx completion for NULL pointers */
1310 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
1311 skb->len, DMA_TO_DEVICE);
1312 ath10k_htt_hif_tx_complete(ar, skb);
1316 static void ath10k_pci_htt_rx_deliver(struct ath10k *ar, struct sk_buff *skb)
1318 skb_pull(skb, sizeof(struct ath10k_htc_hdr));
1319 ath10k_htt_t2h_msg_handler(ar, skb);
1322 /* Called by lower (CE) layer when HTT data is received from the Target. */
1323 static void ath10k_pci_htt_rx_cb(struct ath10k_ce_pipe *ce_state)
1325 /* CE4 polling needs to be done whenever CE pipe which transports
1326 * HTT Rx (target->host) is processed.
1328 ath10k_ce_per_engine_service(ce_state->ar, 4);
1330 ath10k_pci_process_htt_rx_cb(ce_state, ath10k_pci_htt_rx_deliver);
1333 int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
1334 struct ath10k_hif_sg_item *items, int n_items)
1336 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1337 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
1338 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
1339 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
1340 unsigned int nentries_mask;
1341 unsigned int sw_index;
1342 unsigned int write_index;
1345 spin_lock_bh(&ar_pci->ce_lock);
1347 nentries_mask = src_ring->nentries_mask;
1348 sw_index = src_ring->sw_index;
1349 write_index = src_ring->write_index;
1351 if (unlikely(CE_RING_DELTA(nentries_mask,
1352 write_index, sw_index - 1) < n_items)) {
1357 for (i = 0; i < n_items - 1; i++) {
1358 ath10k_dbg(ar, ATH10K_DBG_PCI,
1359 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1360 i, items[i].paddr, items[i].len, n_items);
1361 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
1362 items[i].vaddr, items[i].len);
1364 err = ath10k_ce_send_nolock(ce_pipe,
1365 items[i].transfer_context,
1368 items[i].transfer_id,
1369 CE_SEND_FLAG_GATHER);
1374 /* `i` is equal to `n_items -1` after for() */
1376 ath10k_dbg(ar, ATH10K_DBG_PCI,
1377 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
1378 i, items[i].paddr, items[i].len, n_items);
1379 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
1380 items[i].vaddr, items[i].len);
1382 err = ath10k_ce_send_nolock(ce_pipe,
1383 items[i].transfer_context,
1386 items[i].transfer_id,
1391 spin_unlock_bh(&ar_pci->ce_lock);
1396 __ath10k_ce_send_revert(ce_pipe);
1398 spin_unlock_bh(&ar_pci->ce_lock);
1402 int ath10k_pci_hif_diag_read(struct ath10k *ar, u32 address, void *buf,
1405 return ath10k_pci_diag_read_mem(ar, address, buf, buf_len);
1408 u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
1410 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1412 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
1414 return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
1417 static void ath10k_pci_dump_registers(struct ath10k *ar,
1418 struct ath10k_fw_crash_data *crash_data)
1420 __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
1423 lockdep_assert_held(&ar->data_lock);
1425 ret = ath10k_pci_diag_read_hi(ar, ®_dump_values[0],
1427 REG_DUMP_COUNT_QCA988X * sizeof(__le32));
1429 ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
1433 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
1435 ath10k_err(ar, "firmware register dump:\n");
1436 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
1437 ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
1439 __le32_to_cpu(reg_dump_values[i]),
1440 __le32_to_cpu(reg_dump_values[i + 1]),
1441 __le32_to_cpu(reg_dump_values[i + 2]),
1442 __le32_to_cpu(reg_dump_values[i + 3]));
1447 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
1448 crash_data->registers[i] = reg_dump_values[i];
1451 static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
1453 struct ath10k_fw_crash_data *crash_data;
1456 spin_lock_bh(&ar->data_lock);
1458 ar->stats.fw_crash_counter++;
1460 crash_data = ath10k_debug_get_new_fw_crash_data(ar);
1463 scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
1465 scnprintf(uuid, sizeof(uuid), "n/a");
1467 ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
1468 ath10k_print_driver_info(ar);
1469 ath10k_pci_dump_registers(ar, crash_data);
1471 spin_unlock_bh(&ar->data_lock);
1473 queue_work(ar->workqueue, &ar->restart_work);
1476 void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
1479 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
1484 * Decide whether to actually poll for completions, or just
1485 * wait for a later chance.
1486 * If there seem to be plenty of resources left, then just wait
1487 * since checking involves reading a CE register, which is a
1488 * relatively expensive operation.
1490 resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
1493 * If at least 50% of the total resources are still available,
1494 * don't bother checking again yet.
1496 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
1499 ath10k_ce_per_engine_service(ar, pipe);
1502 void ath10k_pci_kill_tasklet(struct ath10k *ar)
1504 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1507 tasklet_kill(&ar_pci->intr_tq);
1508 tasklet_kill(&ar_pci->msi_fw_err);
1510 for (i = 0; i < CE_COUNT; i++)
1511 tasklet_kill(&ar_pci->pipe_info[i].intr);
1513 del_timer_sync(&ar_pci->rx_post_retry);
1516 int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, u16 service_id,
1517 u8 *ul_pipe, u8 *dl_pipe)
1519 const struct service_to_pipe *entry;
1520 bool ul_set = false, dl_set = false;
1523 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
1525 for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
1526 entry = &target_service_to_ce_map_wlan[i];
1528 if (__le32_to_cpu(entry->service_id) != service_id)
1531 switch (__le32_to_cpu(entry->pipedir)) {
1536 *dl_pipe = __le32_to_cpu(entry->pipenum);
1541 *ul_pipe = __le32_to_cpu(entry->pipenum);
1547 *dl_pipe = __le32_to_cpu(entry->pipenum);
1548 *ul_pipe = __le32_to_cpu(entry->pipenum);
1555 if (WARN_ON(!ul_set || !dl_set))
1561 void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1562 u8 *ul_pipe, u8 *dl_pipe)
1564 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
1566 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1567 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1571 static void ath10k_pci_irq_msi_fw_mask(struct ath10k *ar)
1575 switch (ar->hw_rev) {
1576 case ATH10K_HW_QCA988X:
1577 case ATH10K_HW_QCA6174:
1578 case ATH10K_HW_QCA9377:
1579 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1581 val &= ~CORE_CTRL_PCIE_REG_31_MASK;
1582 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1583 CORE_CTRL_ADDRESS, val);
1585 case ATH10K_HW_QCA99X0:
1586 case ATH10K_HW_QCA4019:
1587 /* TODO: Find appropriate register configuration for QCA99X0
1594 static void ath10k_pci_irq_msi_fw_unmask(struct ath10k *ar)
1598 switch (ar->hw_rev) {
1599 case ATH10K_HW_QCA988X:
1600 case ATH10K_HW_QCA6174:
1601 case ATH10K_HW_QCA9377:
1602 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1604 val |= CORE_CTRL_PCIE_REG_31_MASK;
1605 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1606 CORE_CTRL_ADDRESS, val);
1608 case ATH10K_HW_QCA99X0:
1609 case ATH10K_HW_QCA4019:
1610 /* TODO: Find appropriate register configuration for QCA99X0
1611 * to unmask irq/MSI.
1617 static void ath10k_pci_irq_disable(struct ath10k *ar)
1619 ath10k_ce_disable_interrupts(ar);
1620 ath10k_pci_disable_and_clear_legacy_irq(ar);
1621 ath10k_pci_irq_msi_fw_mask(ar);
1624 static void ath10k_pci_irq_sync(struct ath10k *ar)
1626 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1629 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
1630 synchronize_irq(ar_pci->pdev->irq + i);
1633 static void ath10k_pci_irq_enable(struct ath10k *ar)
1635 ath10k_ce_enable_interrupts(ar);
1636 ath10k_pci_enable_legacy_irq(ar);
1637 ath10k_pci_irq_msi_fw_unmask(ar);
1640 static int ath10k_pci_hif_start(struct ath10k *ar)
1642 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1644 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
1646 ath10k_pci_irq_enable(ar);
1647 ath10k_pci_rx_post(ar);
1649 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
1655 static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
1658 struct ath10k_ce_pipe *ce_pipe;
1659 struct ath10k_ce_ring *ce_ring;
1660 struct sk_buff *skb;
1663 ar = pci_pipe->hif_ce_state;
1664 ce_pipe = pci_pipe->ce_hdl;
1665 ce_ring = ce_pipe->dest_ring;
1670 if (!pci_pipe->buf_sz)
1673 for (i = 0; i < ce_ring->nentries; i++) {
1674 skb = ce_ring->per_transfer_context[i];
1678 ce_ring->per_transfer_context[i] = NULL;
1680 dma_unmap_single(ar->dev, ATH10K_SKB_RXCB(skb)->paddr,
1681 skb->len + skb_tailroom(skb),
1683 dev_kfree_skb_any(skb);
1687 static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pci_pipe)
1690 struct ath10k_pci *ar_pci;
1691 struct ath10k_ce_pipe *ce_pipe;
1692 struct ath10k_ce_ring *ce_ring;
1693 struct sk_buff *skb;
1696 ar = pci_pipe->hif_ce_state;
1697 ar_pci = ath10k_pci_priv(ar);
1698 ce_pipe = pci_pipe->ce_hdl;
1699 ce_ring = ce_pipe->src_ring;
1704 if (!pci_pipe->buf_sz)
1707 for (i = 0; i < ce_ring->nentries; i++) {
1708 skb = ce_ring->per_transfer_context[i];
1712 ce_ring->per_transfer_context[i] = NULL;
1714 ath10k_htc_tx_completion_handler(ar, skb);
1719 * Cleanup residual buffers for device shutdown:
1720 * buffers that were enqueued for receive
1721 * buffers that were to be sent
1722 * Note: Buffers that had completed but which were
1723 * not yet processed are on a completion queue. They
1724 * are handled when the completion thread shuts down.
1726 static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1728 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1731 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1732 struct ath10k_pci_pipe *pipe_info;
1734 pipe_info = &ar_pci->pipe_info[pipe_num];
1735 ath10k_pci_rx_pipe_cleanup(pipe_info);
1736 ath10k_pci_tx_pipe_cleanup(pipe_info);
1740 void ath10k_pci_ce_deinit(struct ath10k *ar)
1744 for (i = 0; i < CE_COUNT; i++)
1745 ath10k_ce_deinit_pipe(ar, i);
1748 void ath10k_pci_flush(struct ath10k *ar)
1750 ath10k_pci_kill_tasklet(ar);
1751 ath10k_pci_buffer_cleanup(ar);
1754 static void ath10k_pci_hif_stop(struct ath10k *ar)
1756 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1757 unsigned long flags;
1759 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
1761 /* Most likely the device has HTT Rx ring configured. The only way to
1762 * prevent the device from accessing (and possible corrupting) host
1763 * memory is to reset the chip now.
1765 * There's also no known way of masking MSI interrupts on the device.
1766 * For ranged MSI the CE-related interrupts can be masked. However
1767 * regardless how many MSI interrupts are assigned the first one
1768 * is always used for firmware indications (crashes) and cannot be
1769 * masked. To prevent the device from asserting the interrupt reset it
1770 * before proceeding with cleanup.
1772 ath10k_pci_safe_chip_reset(ar);
1774 ath10k_pci_irq_disable(ar);
1775 ath10k_pci_irq_sync(ar);
1776 ath10k_pci_flush(ar);
1778 spin_lock_irqsave(&ar_pci->ps_lock, flags);
1779 WARN_ON(ar_pci->ps_wake_refcount > 0);
1780 spin_unlock_irqrestore(&ar_pci->ps_lock, flags);
1783 int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1784 void *req, u32 req_len,
1785 void *resp, u32 *resp_len)
1787 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1788 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1789 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1790 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1791 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
1792 dma_addr_t req_paddr = 0;
1793 dma_addr_t resp_paddr = 0;
1794 struct bmi_xfer xfer = {};
1795 void *treq, *tresp = NULL;
1800 if (resp && !resp_len)
1803 if (resp && resp_len && *resp_len == 0)
1806 treq = kmemdup(req, req_len, GFP_KERNEL);
1810 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1811 ret = dma_mapping_error(ar->dev, req_paddr);
1817 if (resp && resp_len) {
1818 tresp = kzalloc(*resp_len, GFP_KERNEL);
1824 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1826 ret = dma_mapping_error(ar->dev, resp_paddr);
1832 xfer.wait_for_resp = true;
1835 ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
1838 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1842 ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
1845 unsigned int unused_nbytes;
1846 unsigned int unused_id;
1848 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1849 &unused_nbytes, &unused_id);
1851 /* non-zero means we did not time out */
1859 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1860 dma_unmap_single(ar->dev, resp_paddr,
1861 *resp_len, DMA_FROM_DEVICE);
1864 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1866 if (ret == 0 && resp_len) {
1867 *resp_len = min(*resp_len, xfer.resp_len);
1868 memcpy(resp, tresp, xfer.resp_len);
1877 static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
1879 struct bmi_xfer *xfer;
1881 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer))
1884 xfer->tx_done = true;
1887 static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
1889 struct ath10k *ar = ce_state->ar;
1890 struct bmi_xfer *xfer;
1891 unsigned int nbytes;
1893 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer,
1897 if (WARN_ON_ONCE(!xfer))
1900 if (!xfer->wait_for_resp) {
1901 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
1905 xfer->resp_len = nbytes;
1906 xfer->rx_done = true;
1909 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
1910 struct ath10k_ce_pipe *rx_pipe,
1911 struct bmi_xfer *xfer)
1913 unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
1915 while (time_before_eq(jiffies, timeout)) {
1916 ath10k_pci_bmi_send_done(tx_pipe);
1917 ath10k_pci_bmi_recv_data(rx_pipe);
1919 if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
1929 * Send an interrupt to the device to wake up the Target CPU
1930 * so it has an opportunity to notice any changed state.
1932 static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1936 addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS;
1937 val = ath10k_pci_read32(ar, addr);
1938 val |= CORE_CTRL_CPU_INTR_MASK;
1939 ath10k_pci_write32(ar, addr, val);
1944 static int ath10k_pci_get_num_banks(struct ath10k *ar)
1946 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1948 switch (ar_pci->pdev->device) {
1949 case QCA988X_2_0_DEVICE_ID:
1950 case QCA99X0_2_0_DEVICE_ID:
1952 case QCA6164_2_1_DEVICE_ID:
1953 case QCA6174_2_1_DEVICE_ID:
1954 switch (MS(ar->chip_id, SOC_CHIP_ID_REV)) {
1955 case QCA6174_HW_1_0_CHIP_ID_REV:
1956 case QCA6174_HW_1_1_CHIP_ID_REV:
1957 case QCA6174_HW_2_1_CHIP_ID_REV:
1958 case QCA6174_HW_2_2_CHIP_ID_REV:
1960 case QCA6174_HW_1_3_CHIP_ID_REV:
1962 case QCA6174_HW_3_0_CHIP_ID_REV:
1963 case QCA6174_HW_3_1_CHIP_ID_REV:
1964 case QCA6174_HW_3_2_CHIP_ID_REV:
1968 case QCA9377_1_0_DEVICE_ID:
1972 ath10k_warn(ar, "unknown number of banks, assuming 1\n");
1976 static int ath10k_bus_get_num_banks(struct ath10k *ar)
1978 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1980 return ar_pci->bus_ops->get_num_banks(ar);
1983 int ath10k_pci_init_config(struct ath10k *ar)
1985 u32 interconnect_targ_addr;
1986 u32 pcie_state_targ_addr = 0;
1987 u32 pipe_cfg_targ_addr = 0;
1988 u32 svc_to_pipe_map = 0;
1989 u32 pcie_config_flags = 0;
1991 u32 ealloc_targ_addr;
1993 u32 flag2_targ_addr;
1996 /* Download to Target the CE Config and the service-to-CE map */
1997 interconnect_targ_addr =
1998 host_interest_item_address(HI_ITEM(hi_interconnect_state));
2000 /* Supply Target-side CE configuration */
2001 ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
2002 &pcie_state_targ_addr);
2004 ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
2008 if (pcie_state_targ_addr == 0) {
2010 ath10k_err(ar, "Invalid pcie state addr\n");
2014 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
2015 offsetof(struct pcie_state,
2017 &pipe_cfg_targ_addr);
2019 ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
2023 if (pipe_cfg_targ_addr == 0) {
2025 ath10k_err(ar, "Invalid pipe cfg addr\n");
2029 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
2030 target_ce_config_wlan,
2031 sizeof(struct ce_pipe_config) *
2032 NUM_TARGET_CE_CONFIG_WLAN);
2035 ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
2039 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
2040 offsetof(struct pcie_state,
2044 ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
2048 if (svc_to_pipe_map == 0) {
2050 ath10k_err(ar, "Invalid svc_to_pipe map\n");
2054 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
2055 target_service_to_ce_map_wlan,
2056 sizeof(target_service_to_ce_map_wlan));
2058 ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
2062 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
2063 offsetof(struct pcie_state,
2065 &pcie_config_flags);
2067 ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
2071 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
2073 ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
2074 offsetof(struct pcie_state,
2078 ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
2082 /* configure early allocation */
2083 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
2085 ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
2087 ath10k_err(ar, "Faile to get early alloc val: %d\n", ret);
2091 /* first bank is switched to IRAM */
2092 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
2093 HI_EARLY_ALLOC_MAGIC_MASK);
2094 ealloc_value |= ((ath10k_bus_get_num_banks(ar) <<
2095 HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
2096 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
2098 ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
2100 ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
2104 /* Tell Target to proceed with initialization */
2105 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
2107 ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
2109 ath10k_err(ar, "Failed to get option val: %d\n", ret);
2113 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
2115 ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
2117 ath10k_err(ar, "Failed to set option val: %d\n", ret);
2124 static void ath10k_pci_override_ce_config(struct ath10k *ar)
2126 struct ce_attr *attr;
2127 struct ce_pipe_config *config;
2129 /* For QCA6174 we're overriding the Copy Engine 5 configuration,
2130 * since it is currently used for other feature.
2133 /* Override Host's Copy Engine 5 configuration */
2134 attr = &host_ce_config_wlan[5];
2135 attr->src_sz_max = 0;
2136 attr->dest_nentries = 0;
2138 /* Override Target firmware's Copy Engine configuration */
2139 config = &target_ce_config_wlan[5];
2140 config->pipedir = __cpu_to_le32(PIPEDIR_OUT);
2141 config->nbytes_max = __cpu_to_le32(2048);
2143 /* Map from service/endpoint to Copy Engine */
2144 target_service_to_ce_map_wlan[15].pipenum = __cpu_to_le32(1);
2147 int ath10k_pci_alloc_pipes(struct ath10k *ar)
2149 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2150 struct ath10k_pci_pipe *pipe;
2153 for (i = 0; i < CE_COUNT; i++) {
2154 pipe = &ar_pci->pipe_info[i];
2155 pipe->ce_hdl = &ar_pci->ce_states[i];
2157 pipe->hif_ce_state = ar;
2159 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
2161 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
2166 /* Last CE is Diagnostic Window */
2167 if (i == CE_DIAG_PIPE) {
2168 ar_pci->ce_diag = pipe->ce_hdl;
2172 pipe->buf_sz = (size_t)(host_ce_config_wlan[i].src_sz_max);
2178 void ath10k_pci_free_pipes(struct ath10k *ar)
2182 for (i = 0; i < CE_COUNT; i++)
2183 ath10k_ce_free_pipe(ar, i);
2186 int ath10k_pci_init_pipes(struct ath10k *ar)
2190 for (i = 0; i < CE_COUNT; i++) {
2191 ret = ath10k_ce_init_pipe(ar, i, &host_ce_config_wlan[i]);
2193 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
2202 static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
2204 return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
2205 FW_IND_EVENT_PENDING;
2208 static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
2212 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2213 val &= ~FW_IND_EVENT_PENDING;
2214 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
2217 /* this function effectively clears target memory controller assert line */
2218 static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
2222 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2223 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2224 val | SOC_RESET_CONTROL_SI0_RST_MASK);
2225 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2229 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2230 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
2231 val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
2232 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
2237 static void ath10k_pci_warm_reset_cpu(struct ath10k *ar)
2241 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
2243 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2244 SOC_RESET_CONTROL_ADDRESS);
2245 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2246 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
2249 static void ath10k_pci_warm_reset_ce(struct ath10k *ar)
2253 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2254 SOC_RESET_CONTROL_ADDRESS);
2256 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2257 val | SOC_RESET_CONTROL_CE_RST_MASK);
2259 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
2260 val & ~SOC_RESET_CONTROL_CE_RST_MASK);
2263 static void ath10k_pci_warm_reset_clear_lf(struct ath10k *ar)
2267 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
2268 SOC_LF_TIMER_CONTROL0_ADDRESS);
2269 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
2270 SOC_LF_TIMER_CONTROL0_ADDRESS,
2271 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
2274 static int ath10k_pci_warm_reset(struct ath10k *ar)
2278 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
2280 spin_lock_bh(&ar->data_lock);
2281 ar->stats.fw_warm_reset_counter++;
2282 spin_unlock_bh(&ar->data_lock);
2284 ath10k_pci_irq_disable(ar);
2286 /* Make sure the target CPU is not doing anything dangerous, e.g. if it
2287 * were to access copy engine while host performs copy engine reset
2288 * then it is possible for the device to confuse pci-e controller to
2289 * the point of bringing host system to a complete stop (i.e. hang).
2291 ath10k_pci_warm_reset_si0(ar);
2292 ath10k_pci_warm_reset_cpu(ar);
2293 ath10k_pci_init_pipes(ar);
2294 ath10k_pci_wait_for_target_init(ar);
2296 ath10k_pci_warm_reset_clear_lf(ar);
2297 ath10k_pci_warm_reset_ce(ar);
2298 ath10k_pci_warm_reset_cpu(ar);
2299 ath10k_pci_init_pipes(ar);
2301 ret = ath10k_pci_wait_for_target_init(ar);
2303 ath10k_warn(ar, "failed to wait for target init: %d\n", ret);
2307 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
2312 static int ath10k_pci_safe_chip_reset(struct ath10k *ar)
2314 if (QCA_REV_988X(ar) || QCA_REV_6174(ar)) {
2315 return ath10k_pci_warm_reset(ar);
2316 } else if (QCA_REV_99X0(ar)) {
2317 ath10k_pci_irq_disable(ar);
2318 return ath10k_pci_qca99x0_chip_reset(ar);
2324 static int ath10k_pci_qca988x_chip_reset(struct ath10k *ar)
2329 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot 988x chip reset\n");
2331 /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
2332 * It is thus preferred to use warm reset which is safer but may not be
2333 * able to recover the device from all possible fail scenarios.
2335 * Warm reset doesn't always work on first try so attempt it a few
2336 * times before giving up.
2338 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
2339 ret = ath10k_pci_warm_reset(ar);
2341 ath10k_warn(ar, "failed to warm reset attempt %d of %d: %d\n",
2342 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS,
2347 /* FIXME: Sometimes copy engine doesn't recover after warm
2348 * reset. In most cases this needs cold reset. In some of these
2349 * cases the device is in such a state that a cold reset may
2352 * Reading any host interest register via copy engine is
2353 * sufficient to verify if device is capable of booting
2356 ret = ath10k_pci_init_pipes(ar);
2358 ath10k_warn(ar, "failed to init copy engine: %d\n",
2363 ret = ath10k_pci_diag_read32(ar, QCA988X_HOST_INTEREST_ADDRESS,
2366 ath10k_warn(ar, "failed to poke copy engine: %d\n",
2371 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot chip reset complete (warm)\n");
2375 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) {
2376 ath10k_warn(ar, "refusing cold reset as requested\n");
2380 ret = ath10k_pci_cold_reset(ar);
2382 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2386 ret = ath10k_pci_wait_for_target_init(ar);
2388 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2393 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca988x chip reset complete (cold)\n");
2398 static int ath10k_pci_qca6174_chip_reset(struct ath10k *ar)
2402 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset\n");
2404 /* FIXME: QCA6174 requires cold + warm reset to work. */
2406 ret = ath10k_pci_cold_reset(ar);
2408 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2412 ret = ath10k_pci_wait_for_target_init(ar);
2414 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2419 ret = ath10k_pci_warm_reset(ar);
2421 ath10k_warn(ar, "failed to warm reset: %d\n", ret);
2425 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca6174 chip reset complete (cold)\n");
2430 static int ath10k_pci_qca99x0_chip_reset(struct ath10k *ar)
2434 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset\n");
2436 ret = ath10k_pci_cold_reset(ar);
2438 ath10k_warn(ar, "failed to cold reset: %d\n", ret);
2442 ret = ath10k_pci_wait_for_target_init(ar);
2444 ath10k_warn(ar, "failed to wait for target after cold reset: %d\n",
2449 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot qca99x0 chip reset complete (cold)\n");
2454 static int ath10k_pci_chip_reset(struct ath10k *ar)
2456 if (QCA_REV_988X(ar))
2457 return ath10k_pci_qca988x_chip_reset(ar);
2458 else if (QCA_REV_6174(ar))
2459 return ath10k_pci_qca6174_chip_reset(ar);
2460 else if (QCA_REV_9377(ar))
2461 return ath10k_pci_qca6174_chip_reset(ar);
2462 else if (QCA_REV_99X0(ar))
2463 return ath10k_pci_qca99x0_chip_reset(ar);
2468 static int ath10k_pci_hif_power_up(struct ath10k *ar)
2470 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2473 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
2475 pcie_capability_read_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2477 pcie_capability_write_word(ar_pci->pdev, PCI_EXP_LNKCTL,
2478 ar_pci->link_ctl & ~PCI_EXP_LNKCTL_ASPMC);
2481 * Bring the target up cleanly.
2483 * The target may be in an undefined state with an AUX-powered Target
2484 * and a Host in WoW mode. If the Host crashes, loses power, or is
2485 * restarted (without unloading the driver) then the Target is left
2486 * (aux) powered and running. On a subsequent driver load, the Target
2487 * is in an unexpected state. We try to catch that here in order to
2488 * reset the Target and retry the probe.
2490 ret = ath10k_pci_chip_reset(ar);
2492 if (ath10k_pci_has_fw_crashed(ar)) {
2493 ath10k_warn(ar, "firmware crashed during chip reset\n");
2494 ath10k_pci_fw_crashed_clear(ar);
2495 ath10k_pci_fw_crashed_dump(ar);
2498 ath10k_err(ar, "failed to reset chip: %d\n", ret);
2502 ret = ath10k_pci_init_pipes(ar);
2504 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
2508 ret = ath10k_pci_init_config(ar);
2510 ath10k_err(ar, "failed to setup init config: %d\n", ret);
2514 ret = ath10k_pci_wake_target_cpu(ar);
2516 ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
2523 ath10k_pci_ce_deinit(ar);
2529 void ath10k_pci_hif_power_down(struct ath10k *ar)
2531 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
2533 /* Currently hif_power_up performs effectively a reset and hif_stop
2534 * resets the chip as well so there's no point in resetting here.
2540 static int ath10k_pci_hif_suspend(struct ath10k *ar)
2542 /* The grace timer can still be counting down and ar->ps_awake be true.
2543 * It is known that the device may be asleep after resuming regardless
2544 * of the SoC powersave state before suspending. Hence make sure the
2545 * device is asleep before proceeding.
2547 ath10k_pci_sleep_sync(ar);
2552 static int ath10k_pci_hif_resume(struct ath10k *ar)
2554 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2555 struct pci_dev *pdev = ar_pci->pdev;
2559 ret = ath10k_pci_force_wake(ar);
2561 ath10k_err(ar, "failed to wake up target: %d\n", ret);
2565 /* Suspend/Resume resets the PCI configuration space, so we have to
2566 * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
2567 * from interfering with C3 CPU state. pci_restore_state won't help
2568 * here since it only restores the first 64 bytes pci config header.
2570 pci_read_config_dword(pdev, 0x40, &val);
2571 if ((val & 0x0000ff00) != 0)
2572 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
2578 static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
2579 .tx_sg = ath10k_pci_hif_tx_sg,
2580 .diag_read = ath10k_pci_hif_diag_read,
2581 .diag_write = ath10k_pci_diag_write_mem,
2582 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
2583 .start = ath10k_pci_hif_start,
2584 .stop = ath10k_pci_hif_stop,
2585 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
2586 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
2587 .send_complete_check = ath10k_pci_hif_send_complete_check,
2588 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
2589 .power_up = ath10k_pci_hif_power_up,
2590 .power_down = ath10k_pci_hif_power_down,
2591 .read32 = ath10k_pci_read32,
2592 .write32 = ath10k_pci_write32,
2594 .suspend = ath10k_pci_hif_suspend,
2595 .resume = ath10k_pci_hif_resume,
2599 static void ath10k_pci_ce_tasklet(unsigned long ptr)
2601 struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr;
2602 struct ath10k_pci *ar_pci = pipe->ar_pci;
2604 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
2607 static void ath10k_msi_err_tasklet(unsigned long data)
2609 struct ath10k *ar = (struct ath10k *)data;
2611 if (!ath10k_pci_has_fw_crashed(ar)) {
2612 ath10k_warn(ar, "received unsolicited fw crash interrupt\n");
2616 ath10k_pci_irq_disable(ar);
2617 ath10k_pci_fw_crashed_clear(ar);
2618 ath10k_pci_fw_crashed_dump(ar);
2622 * Handler for a per-engine interrupt on a PARTICULAR CE.
2623 * This is used in cases where each CE has a private MSI interrupt.
2625 static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg)
2627 struct ath10k *ar = arg;
2628 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2629 int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL;
2631 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) {
2632 ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
2638 * NOTE: We are able to derive ce_id from irq because we
2639 * use a one-to-one mapping for CE's 0..5.
2640 * CE's 6 & 7 do not use interrupts at all.
2642 * This mapping must be kept in sync with the mapping
2645 tasklet_schedule(&ar_pci->pipe_info[ce_id].intr);
2649 static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg)
2651 struct ath10k *ar = arg;
2652 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2654 tasklet_schedule(&ar_pci->msi_fw_err);
2659 * Top-level interrupt handler for all PCI interrupts from a Target.
2660 * When a block of MSI interrupts is allocated, this top-level handler
2661 * is not used; instead, we directly call the correct sub-handler.
2663 static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
2665 struct ath10k *ar = arg;
2666 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2669 ret = ath10k_pci_force_wake(ar);
2671 ath10k_warn(ar, "failed to wake device up on irq: %d\n", ret);
2675 if (ar_pci->num_msi_intrs == 0) {
2676 if (!ath10k_pci_irq_pending(ar))
2679 ath10k_pci_disable_and_clear_legacy_irq(ar);
2682 tasklet_schedule(&ar_pci->intr_tq);
2687 static void ath10k_pci_tasklet(unsigned long data)
2689 struct ath10k *ar = (struct ath10k *)data;
2690 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2692 if (ath10k_pci_has_fw_crashed(ar)) {
2693 ath10k_pci_irq_disable(ar);
2694 ath10k_pci_fw_crashed_clear(ar);
2695 ath10k_pci_fw_crashed_dump(ar);
2699 ath10k_ce_per_engine_service_any(ar);
2701 /* Re-enable legacy irq that was disabled in the irq handler */
2702 if (ar_pci->num_msi_intrs == 0)
2703 ath10k_pci_enable_legacy_irq(ar);
2706 static int ath10k_pci_request_irq_msix(struct ath10k *ar)
2708 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2711 ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW,
2712 ath10k_pci_msi_fw_handler,
2713 IRQF_SHARED, "ath10k_pci", ar);
2715 ath10k_warn(ar, "failed to request MSI-X fw irq %d: %d\n",
2716 ar_pci->pdev->irq + MSI_ASSIGN_FW, ret);
2720 for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) {
2721 ret = request_irq(ar_pci->pdev->irq + i,
2722 ath10k_pci_per_engine_handler,
2723 IRQF_SHARED, "ath10k_pci", ar);
2725 ath10k_warn(ar, "failed to request MSI-X ce irq %d: %d\n",
2726 ar_pci->pdev->irq + i, ret);
2728 for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--)
2729 free_irq(ar_pci->pdev->irq + i, ar);
2731 free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar);
2739 static int ath10k_pci_request_irq_msi(struct ath10k *ar)
2741 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2744 ret = request_irq(ar_pci->pdev->irq,
2745 ath10k_pci_interrupt_handler,
2746 IRQF_SHARED, "ath10k_pci", ar);
2748 ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
2749 ar_pci->pdev->irq, ret);
2756 static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
2758 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2761 ret = request_irq(ar_pci->pdev->irq,
2762 ath10k_pci_interrupt_handler,
2763 IRQF_SHARED, "ath10k_pci", ar);
2765 ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
2766 ar_pci->pdev->irq, ret);
2773 static int ath10k_pci_request_irq(struct ath10k *ar)
2775 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2777 switch (ar_pci->num_msi_intrs) {
2779 return ath10k_pci_request_irq_legacy(ar);
2781 return ath10k_pci_request_irq_msi(ar);
2783 return ath10k_pci_request_irq_msix(ar);
2787 static void ath10k_pci_free_irq(struct ath10k *ar)
2789 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2792 /* There's at least one interrupt irregardless whether its legacy INTR
2793 * or MSI or MSI-X */
2794 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
2795 free_irq(ar_pci->pdev->irq + i, ar);
2798 void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
2800 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2803 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
2804 tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet,
2807 for (i = 0; i < CE_COUNT; i++) {
2808 ar_pci->pipe_info[i].ar_pci = ar_pci;
2809 tasklet_init(&ar_pci->pipe_info[i].intr, ath10k_pci_ce_tasklet,
2810 (unsigned long)&ar_pci->pipe_info[i]);
2814 static int ath10k_pci_init_irq(struct ath10k *ar)
2816 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2819 ath10k_pci_init_irq_tasklets(ar);
2821 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
2822 ath10k_info(ar, "limiting irq mode to: %d\n",
2823 ath10k_pci_irq_mode);
2826 if (ath10k_pci_irq_mode == ATH10K_PCI_IRQ_AUTO) {
2827 ar_pci->num_msi_intrs = MSI_ASSIGN_CE_MAX + 1;
2828 ret = pci_enable_msi_range(ar_pci->pdev, ar_pci->num_msi_intrs,
2829 ar_pci->num_msi_intrs);
2837 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
2838 ar_pci->num_msi_intrs = 1;
2839 ret = pci_enable_msi(ar_pci->pdev);
2848 * A potential race occurs here: The CORE_BASE write
2849 * depends on target correctly decoding AXI address but
2850 * host won't know when target writes BAR to CORE_CTRL.
2851 * This write might get lost if target has NOT written BAR.
2852 * For now, fix the race by repeating the write in below
2853 * synchronization checking. */
2854 ar_pci->num_msi_intrs = 0;
2856 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2857 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
2862 static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
2864 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2868 static int ath10k_pci_deinit_irq(struct ath10k *ar)
2870 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2872 switch (ar_pci->num_msi_intrs) {
2874 ath10k_pci_deinit_irq_legacy(ar);
2877 pci_disable_msi(ar_pci->pdev);
2884 int ath10k_pci_wait_for_target_init(struct ath10k *ar)
2886 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2887 unsigned long timeout;
2890 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
2892 timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
2895 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2897 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
2900 /* target should never return this */
2901 if (val == 0xffffffff)
2904 /* the device has crashed so don't bother trying anymore */
2905 if (val & FW_IND_EVENT_PENDING)
2908 if (val & FW_IND_INITIALIZED)
2911 if (ar_pci->num_msi_intrs == 0)
2912 /* Fix potential race by repeating CORE_BASE writes */
2913 ath10k_pci_enable_legacy_irq(ar);
2916 } while (time_before(jiffies, timeout));
2918 ath10k_pci_disable_and_clear_legacy_irq(ar);
2919 ath10k_pci_irq_msi_fw_mask(ar);
2921 if (val == 0xffffffff) {
2922 ath10k_err(ar, "failed to read device register, device is gone\n");
2926 if (val & FW_IND_EVENT_PENDING) {
2927 ath10k_warn(ar, "device has crashed during init\n");
2931 if (!(val & FW_IND_INITIALIZED)) {
2932 ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
2937 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
2941 static int ath10k_pci_cold_reset(struct ath10k *ar)
2945 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
2947 spin_lock_bh(&ar->data_lock);
2949 ar->stats.fw_cold_reset_counter++;
2951 spin_unlock_bh(&ar->data_lock);
2953 /* Put Target, including PCIe, into RESET. */
2954 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
2956 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2958 /* After writing into SOC_GLOBAL_RESET to put device into
2959 * reset and pulling out of reset pcie may not be stable
2960 * for any immediate pcie register access and cause bus error,
2961 * add delay before any pcie access request to fix this issue.
2965 /* Pull Target, including PCIe, out of RESET. */
2967 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2971 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
2976 static int ath10k_pci_claim(struct ath10k *ar)
2978 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2979 struct pci_dev *pdev = ar_pci->pdev;
2982 pci_set_drvdata(pdev, ar);
2984 ret = pci_enable_device(pdev);
2986 ath10k_err(ar, "failed to enable pci device: %d\n", ret);
2990 ret = pci_request_region(pdev, BAR_NUM, "ath");
2992 ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
2997 /* Target expects 32 bit DMA. Enforce it. */
2998 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
3000 ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
3004 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
3006 ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
3011 pci_set_master(pdev);
3013 /* Arrange for access to Target SoC registers. */
3014 ar_pci->mem_len = pci_resource_len(pdev, BAR_NUM);
3015 ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
3017 ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
3022 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
3026 pci_clear_master(pdev);
3029 pci_release_region(pdev, BAR_NUM);
3032 pci_disable_device(pdev);
3037 static void ath10k_pci_release(struct ath10k *ar)
3039 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
3040 struct pci_dev *pdev = ar_pci->pdev;
3042 pci_iounmap(pdev, ar_pci->mem);
3043 pci_release_region(pdev, BAR_NUM);
3044 pci_clear_master(pdev);
3045 pci_disable_device(pdev);
3048 static bool ath10k_pci_chip_is_supported(u32 dev_id, u32 chip_id)
3050 const struct ath10k_pci_supp_chip *supp_chip;
3052 u32 rev_id = MS(chip_id, SOC_CHIP_ID_REV);
3054 for (i = 0; i < ARRAY_SIZE(ath10k_pci_supp_chips); i++) {
3055 supp_chip = &ath10k_pci_supp_chips[i];
3057 if (supp_chip->dev_id == dev_id &&
3058 supp_chip->rev_id == rev_id)
3065 int ath10k_pci_setup_resource(struct ath10k *ar)
3067 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
3070 spin_lock_init(&ar_pci->ce_lock);
3071 spin_lock_init(&ar_pci->ps_lock);
3073 setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
3076 if (QCA_REV_6174(ar))
3077 ath10k_pci_override_ce_config(ar);
3079 ret = ath10k_pci_alloc_pipes(ar);
3081 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
3089 void ath10k_pci_release_resource(struct ath10k *ar)
3091 ath10k_pci_kill_tasklet(ar);
3092 ath10k_pci_ce_deinit(ar);
3093 ath10k_pci_free_pipes(ar);
3096 static const struct ath10k_bus_ops ath10k_pci_bus_ops = {
3097 .read32 = ath10k_bus_pci_read32,
3098 .write32 = ath10k_bus_pci_write32,
3099 .get_num_banks = ath10k_pci_get_num_banks,
3102 static int ath10k_pci_probe(struct pci_dev *pdev,
3103 const struct pci_device_id *pci_dev)
3107 struct ath10k_pci *ar_pci;
3108 enum ath10k_hw_rev hw_rev;
3112 switch (pci_dev->device) {
3113 case QCA988X_2_0_DEVICE_ID:
3114 hw_rev = ATH10K_HW_QCA988X;
3117 case QCA6164_2_1_DEVICE_ID:
3118 case QCA6174_2_1_DEVICE_ID:
3119 hw_rev = ATH10K_HW_QCA6174;
3122 case QCA99X0_2_0_DEVICE_ID:
3123 hw_rev = ATH10K_HW_QCA99X0;
3126 case QCA9377_1_0_DEVICE_ID:
3127 hw_rev = ATH10K_HW_QCA9377;
3135 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, ATH10K_BUS_PCI,
3136 hw_rev, &ath10k_pci_hif_ops);
3138 dev_err(&pdev->dev, "failed to allocate core\n");
3142 ath10k_dbg(ar, ATH10K_DBG_BOOT, "pci probe %04x:%04x %04x:%04x\n",
3143 pdev->vendor, pdev->device,
3144 pdev->subsystem_vendor, pdev->subsystem_device);
3146 ar_pci = ath10k_pci_priv(ar);
3147 ar_pci->pdev = pdev;
3148 ar_pci->dev = &pdev->dev;
3150 ar->dev_id = pci_dev->device;
3151 ar_pci->pci_ps = pci_ps;
3152 ar_pci->bus_ops = &ath10k_pci_bus_ops;
3154 ar->id.vendor = pdev->vendor;
3155 ar->id.device = pdev->device;
3156 ar->id.subsystem_vendor = pdev->subsystem_vendor;
3157 ar->id.subsystem_device = pdev->subsystem_device;
3159 setup_timer(&ar_pci->ps_timer, ath10k_pci_ps_timer,
3162 ret = ath10k_pci_setup_resource(ar);
3164 ath10k_err(ar, "failed to setup resource: %d\n", ret);
3165 goto err_core_destroy;
3168 ret = ath10k_pci_claim(ar);
3170 ath10k_err(ar, "failed to claim device: %d\n", ret);
3171 goto err_free_pipes;
3174 ret = ath10k_pci_force_wake(ar);
3176 ath10k_warn(ar, "failed to wake up device : %d\n", ret);
3180 ath10k_pci_ce_deinit(ar);
3181 ath10k_pci_irq_disable(ar);
3183 ret = ath10k_pci_init_irq(ar);
3185 ath10k_err(ar, "failed to init irqs: %d\n", ret);
3189 ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n",
3190 ath10k_pci_get_irq_method(ar), ar_pci->num_msi_intrs,
3191 ath10k_pci_irq_mode, ath10k_pci_reset_mode);
3193 ret = ath10k_pci_request_irq(ar);
3195 ath10k_warn(ar, "failed to request irqs: %d\n", ret);
3196 goto err_deinit_irq;
3199 ret = ath10k_pci_chip_reset(ar);
3201 ath10k_err(ar, "failed to reset chip: %d\n", ret);
3205 chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
3206 if (chip_id == 0xffffffff) {
3207 ath10k_err(ar, "failed to get chip id\n");
3211 if (!ath10k_pci_chip_is_supported(pdev->device, chip_id)) {
3212 ath10k_err(ar, "device %04x with chip_id %08x isn't supported\n",
3213 pdev->device, chip_id);
3217 ret = ath10k_core_register(ar, chip_id);
3219 ath10k_err(ar, "failed to register driver core: %d\n", ret);
3226 ath10k_pci_free_irq(ar);
3227 ath10k_pci_kill_tasklet(ar);
3230 ath10k_pci_deinit_irq(ar);
3233 ath10k_pci_sleep_sync(ar);
3234 ath10k_pci_release(ar);
3237 ath10k_pci_free_pipes(ar);
3240 ath10k_core_destroy(ar);
3245 static void ath10k_pci_remove(struct pci_dev *pdev)
3247 struct ath10k *ar = pci_get_drvdata(pdev);
3248 struct ath10k_pci *ar_pci;
3250 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
3255 ar_pci = ath10k_pci_priv(ar);
3260 ath10k_core_unregister(ar);
3261 ath10k_pci_free_irq(ar);
3262 ath10k_pci_deinit_irq(ar);
3263 ath10k_pci_release_resource(ar);
3264 ath10k_pci_sleep_sync(ar);
3265 ath10k_pci_release(ar);
3266 ath10k_core_destroy(ar);
3269 MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
3271 static struct pci_driver ath10k_pci_driver = {
3272 .name = "ath10k_pci",
3273 .id_table = ath10k_pci_id_table,
3274 .probe = ath10k_pci_probe,
3275 .remove = ath10k_pci_remove,
3278 static int __init ath10k_pci_init(void)
3282 ret = pci_register_driver(&ath10k_pci_driver);
3284 printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
3287 ret = ath10k_ahb_init();
3289 printk(KERN_ERR "ahb init failed: %d\n", ret);
3293 module_init(ath10k_pci_init);
3295 static void __exit ath10k_pci_exit(void)
3297 pci_unregister_driver(&ath10k_pci_driver);
3301 module_exit(ath10k_pci_exit);
3303 MODULE_AUTHOR("Qualcomm Atheros");
3304 MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
3305 MODULE_LICENSE("Dual BSD/GPL");
3307 /* QCA988x 2.0 firmware files */
3308 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
3309 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API2_FILE);
3310 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API3_FILE);
3311 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API4_FILE);
3312 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_FW_API5_FILE);
3313 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);
3314 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
3316 /* QCA6174 2.1 firmware files */
3317 MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API4_FILE);
3318 MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_FW_API5_FILE);
3319 MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" QCA6174_HW_2_1_BOARD_DATA_FILE);
3320 MODULE_FIRMWARE(QCA6174_HW_2_1_FW_DIR "/" ATH10K_BOARD_API2_FILE);
3322 /* QCA6174 3.1 firmware files */
3323 MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API4_FILE);
3324 MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_FW_API5_FILE);
3325 MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" QCA6174_HW_3_0_BOARD_DATA_FILE);
3326 MODULE_FIRMWARE(QCA6174_HW_3_0_FW_DIR "/" ATH10K_BOARD_API2_FILE);
3328 /* QCA9377 1.0 firmware files */
3329 MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" ATH10K_FW_API5_FILE);
3330 MODULE_FIRMWARE(QCA9377_HW_1_0_FW_DIR "/" QCA9377_HW_1_0_BOARD_DATA_FILE);