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 #define QCA988X_2_0_DEVICE_ID (0x003c)
62 static const struct pci_device_id ath10k_pci_id_table
[] = {
63 { PCI_VDEVICE(ATHEROS
, QCA988X_2_0_DEVICE_ID
) }, /* PCI-E QCA988X V2 */
67 static const struct ath10k_pci_supp_chip ath10k_pci_supp_chips
[] = {
68 /* QCA988X pre 2.0 chips are not supported because they need some nasty
69 * hacks. ath10k doesn't have them and these devices crash horribly
72 { QCA988X_2_0_DEVICE_ID
, QCA988X_HW_2_0_CHIP_ID_REV
},
75 static void ath10k_pci_buffer_cleanup(struct ath10k
*ar
);
76 static int ath10k_pci_cold_reset(struct ath10k
*ar
);
77 static int ath10k_pci_warm_reset(struct ath10k
*ar
);
78 static int ath10k_pci_wait_for_target_init(struct ath10k
*ar
);
79 static int ath10k_pci_init_irq(struct ath10k
*ar
);
80 static int ath10k_pci_deinit_irq(struct ath10k
*ar
);
81 static int ath10k_pci_request_irq(struct ath10k
*ar
);
82 static void ath10k_pci_free_irq(struct ath10k
*ar
);
83 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe
*tx_pipe
,
84 struct ath10k_ce_pipe
*rx_pipe
,
85 struct bmi_xfer
*xfer
);
87 static const struct ce_attr host_ce_config_wlan
[] = {
88 /* CE0: host->target HTC control and raw streams */
90 .flags
= CE_ATTR_FLAGS
,
96 /* CE1: target->host HTT + HTC control */
98 .flags
= CE_ATTR_FLAGS
,
101 .dest_nentries
= 512,
104 /* CE2: target->host WMI */
106 .flags
= CE_ATTR_FLAGS
,
112 /* CE3: host->target WMI */
114 .flags
= CE_ATTR_FLAGS
,
120 /* CE4: host->target HTT */
122 .flags
= CE_ATTR_FLAGS
| CE_ATTR_DIS_INTR
,
123 .src_nentries
= CE_HTT_H2T_MSG_SRC_NENTRIES
,
130 .flags
= CE_ATTR_FLAGS
,
136 /* CE6: target autonomous hif_memcpy */
138 .flags
= CE_ATTR_FLAGS
,
144 /* CE7: ce_diag, the Diagnostic Window */
146 .flags
= CE_ATTR_FLAGS
,
148 .src_sz_max
= DIAG_TRANSFER_LIMIT
,
153 /* Target firmware's Copy Engine configuration. */
154 static const struct ce_pipe_config target_ce_config_wlan
[] = {
155 /* CE0: host->target HTC control and raw streams */
157 .pipenum
= __cpu_to_le32(0),
158 .pipedir
= __cpu_to_le32(PIPEDIR_OUT
),
159 .nentries
= __cpu_to_le32(32),
160 .nbytes_max
= __cpu_to_le32(256),
161 .flags
= __cpu_to_le32(CE_ATTR_FLAGS
),
162 .reserved
= __cpu_to_le32(0),
165 /* CE1: target->host HTT + HTC control */
167 .pipenum
= __cpu_to_le32(1),
168 .pipedir
= __cpu_to_le32(PIPEDIR_IN
),
169 .nentries
= __cpu_to_le32(32),
170 .nbytes_max
= __cpu_to_le32(512),
171 .flags
= __cpu_to_le32(CE_ATTR_FLAGS
),
172 .reserved
= __cpu_to_le32(0),
175 /* CE2: target->host WMI */
177 .pipenum
= __cpu_to_le32(2),
178 .pipedir
= __cpu_to_le32(PIPEDIR_IN
),
179 .nentries
= __cpu_to_le32(32),
180 .nbytes_max
= __cpu_to_le32(2048),
181 .flags
= __cpu_to_le32(CE_ATTR_FLAGS
),
182 .reserved
= __cpu_to_le32(0),
185 /* CE3: host->target WMI */
187 .pipenum
= __cpu_to_le32(3),
188 .pipedir
= __cpu_to_le32(PIPEDIR_OUT
),
189 .nentries
= __cpu_to_le32(32),
190 .nbytes_max
= __cpu_to_le32(2048),
191 .flags
= __cpu_to_le32(CE_ATTR_FLAGS
),
192 .reserved
= __cpu_to_le32(0),
195 /* CE4: host->target HTT */
197 .pipenum
= __cpu_to_le32(4),
198 .pipedir
= __cpu_to_le32(PIPEDIR_OUT
),
199 .nentries
= __cpu_to_le32(256),
200 .nbytes_max
= __cpu_to_le32(256),
201 .flags
= __cpu_to_le32(CE_ATTR_FLAGS
),
202 .reserved
= __cpu_to_le32(0),
205 /* NB: 50% of src nentries, since tx has 2 frags */
209 .pipenum
= __cpu_to_le32(5),
210 .pipedir
= __cpu_to_le32(PIPEDIR_OUT
),
211 .nentries
= __cpu_to_le32(32),
212 .nbytes_max
= __cpu_to_le32(2048),
213 .flags
= __cpu_to_le32(CE_ATTR_FLAGS
),
214 .reserved
= __cpu_to_le32(0),
217 /* CE6: Reserved for target autonomous hif_memcpy */
219 .pipenum
= __cpu_to_le32(6),
220 .pipedir
= __cpu_to_le32(PIPEDIR_INOUT
),
221 .nentries
= __cpu_to_le32(32),
222 .nbytes_max
= __cpu_to_le32(4096),
223 .flags
= __cpu_to_le32(CE_ATTR_FLAGS
),
224 .reserved
= __cpu_to_le32(0),
227 /* CE7 used only by Host */
231 * Map from service/endpoint to Copy Engine.
232 * This table is derived from the CE_PCI TABLE, above.
233 * It is passed to the Target at startup for use by firmware.
235 static const struct service_to_pipe target_service_to_ce_map_wlan
[] = {
237 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO
),
238 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
242 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO
),
243 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
247 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK
),
248 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
252 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK
),
253 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
257 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE
),
258 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
262 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE
),
263 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
267 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI
),
268 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
272 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI
),
273 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
277 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL
),
278 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
282 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL
),
283 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
287 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL
),
288 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
292 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL
),
293 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
297 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS
),
298 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
302 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS
),
303 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
307 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG
),
308 __cpu_to_le32(PIPEDIR_OUT
), /* out = UL = host -> target */
312 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG
),
313 __cpu_to_le32(PIPEDIR_IN
), /* in = DL = target -> host */
317 /* (Additions here) */
326 static bool ath10k_pci_irq_pending(struct ath10k
*ar
)
330 /* Check if the shared legacy irq is for us */
331 cause
= ath10k_pci_read32(ar
, SOC_CORE_BASE_ADDRESS
+
332 PCIE_INTR_CAUSE_ADDRESS
);
333 if (cause
& (PCIE_INTR_FIRMWARE_MASK
| PCIE_INTR_CE_MASK_ALL
))
339 static void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k
*ar
)
341 /* IMPORTANT: INTR_CLR register has to be set after
342 * INTR_ENABLE is set to 0, otherwise interrupt can not be
344 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ PCIE_INTR_ENABLE_ADDRESS
,
346 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ PCIE_INTR_CLR_ADDRESS
,
347 PCIE_INTR_FIRMWARE_MASK
| PCIE_INTR_CE_MASK_ALL
);
349 /* IMPORTANT: this extra read transaction is required to
350 * flush the posted write buffer. */
351 (void)ath10k_pci_read32(ar
, SOC_CORE_BASE_ADDRESS
+
352 PCIE_INTR_ENABLE_ADDRESS
);
355 static void ath10k_pci_enable_legacy_irq(struct ath10k
*ar
)
357 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+
358 PCIE_INTR_ENABLE_ADDRESS
,
359 PCIE_INTR_FIRMWARE_MASK
| PCIE_INTR_CE_MASK_ALL
);
361 /* IMPORTANT: this extra read transaction is required to
362 * flush the posted write buffer. */
363 (void)ath10k_pci_read32(ar
, SOC_CORE_BASE_ADDRESS
+
364 PCIE_INTR_ENABLE_ADDRESS
);
367 static inline const char *ath10k_pci_get_irq_method(struct ath10k
*ar
)
369 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
371 if (ar_pci
->num_msi_intrs
> 1)
374 if (ar_pci
->num_msi_intrs
== 1)
380 static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe
*pipe
)
382 struct ath10k
*ar
= pipe
->hif_ce_state
;
383 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
384 struct ath10k_ce_pipe
*ce_pipe
= pipe
->ce_hdl
;
389 lockdep_assert_held(&ar_pci
->ce_lock
);
391 skb
= dev_alloc_skb(pipe
->buf_sz
);
395 WARN_ONCE((unsigned long)skb
->data
& 3, "unaligned skb");
397 paddr
= dma_map_single(ar
->dev
, skb
->data
,
398 skb
->len
+ skb_tailroom(skb
),
400 if (unlikely(dma_mapping_error(ar
->dev
, paddr
))) {
401 ath10k_warn(ar
, "failed to dma map pci rx buf\n");
402 dev_kfree_skb_any(skb
);
406 ATH10K_SKB_CB(skb
)->paddr
= paddr
;
408 ret
= __ath10k_ce_rx_post_buf(ce_pipe
, skb
, paddr
);
410 ath10k_warn(ar
, "failed to post pci rx buf: %d\n", ret
);
411 dma_unmap_single(ar
->dev
, paddr
, skb
->len
+ skb_tailroom(skb
),
413 dev_kfree_skb_any(skb
);
420 static void __ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe
*pipe
)
422 struct ath10k
*ar
= pipe
->hif_ce_state
;
423 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
424 struct ath10k_ce_pipe
*ce_pipe
= pipe
->ce_hdl
;
427 lockdep_assert_held(&ar_pci
->ce_lock
);
429 if (pipe
->buf_sz
== 0)
432 if (!ce_pipe
->dest_ring
)
435 num
= __ath10k_ce_rx_num_free_bufs(ce_pipe
);
437 ret
= __ath10k_pci_rx_post_buf(pipe
);
439 ath10k_warn(ar
, "failed to post pci rx buf: %d\n", ret
);
440 mod_timer(&ar_pci
->rx_post_retry
, jiffies
+
441 ATH10K_PCI_RX_POST_RETRY_MS
);
447 static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe
*pipe
)
449 struct ath10k
*ar
= pipe
->hif_ce_state
;
450 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
452 spin_lock_bh(&ar_pci
->ce_lock
);
453 __ath10k_pci_rx_post_pipe(pipe
);
454 spin_unlock_bh(&ar_pci
->ce_lock
);
457 static void ath10k_pci_rx_post(struct ath10k
*ar
)
459 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
462 spin_lock_bh(&ar_pci
->ce_lock
);
463 for (i
= 0; i
< CE_COUNT
; i
++)
464 __ath10k_pci_rx_post_pipe(&ar_pci
->pipe_info
[i
]);
465 spin_unlock_bh(&ar_pci
->ce_lock
);
468 static void ath10k_pci_rx_replenish_retry(unsigned long ptr
)
470 struct ath10k
*ar
= (void *)ptr
;
472 ath10k_pci_rx_post(ar
);
476 * Diagnostic read/write access is provided for startup/config/debug usage.
477 * Caller must guarantee proper alignment, when applicable, and single user
480 static int ath10k_pci_diag_read_mem(struct ath10k
*ar
, u32 address
, void *data
,
483 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
486 unsigned int completed_nbytes
, orig_nbytes
, remaining_bytes
;
489 struct ath10k_ce_pipe
*ce_diag
;
490 /* Host buffer address in CE space */
492 dma_addr_t ce_data_base
= 0;
493 void *data_buf
= NULL
;
496 spin_lock_bh(&ar_pci
->ce_lock
);
498 ce_diag
= ar_pci
->ce_diag
;
501 * Allocate a temporary bounce buffer to hold caller's data
502 * to be DMA'ed from Target. This guarantees
503 * 1) 4-byte alignment
504 * 2) Buffer in DMA-able space
506 orig_nbytes
= nbytes
;
507 data_buf
= (unsigned char *)dma_alloc_coherent(ar
->dev
,
516 memset(data_buf
, 0, orig_nbytes
);
518 remaining_bytes
= orig_nbytes
;
519 ce_data
= ce_data_base
;
520 while (remaining_bytes
) {
521 nbytes
= min_t(unsigned int, remaining_bytes
,
522 DIAG_TRANSFER_LIMIT
);
524 ret
= __ath10k_ce_rx_post_buf(ce_diag
, NULL
, ce_data
);
528 /* Request CE to send from Target(!) address to Host buffer */
530 * The address supplied by the caller is in the
531 * Target CPU virtual address space.
533 * In order to use this address with the diagnostic CE,
534 * convert it from Target CPU virtual address space
535 * to CE address space
537 address
= TARG_CPU_SPACE_TO_CE_SPACE(ar
, ar_pci
->mem
,
540 ret
= ath10k_ce_send_nolock(ce_diag
, NULL
, (u32
)address
, nbytes
, 0,
546 while (ath10k_ce_completed_send_next_nolock(ce_diag
, NULL
, &buf
,
550 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
556 if (nbytes
!= completed_nbytes
) {
561 if (buf
!= (u32
)address
) {
567 while (ath10k_ce_completed_recv_next_nolock(ce_diag
, NULL
, &buf
,
572 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
578 if (nbytes
!= completed_nbytes
) {
583 if (buf
!= ce_data
) {
588 remaining_bytes
-= nbytes
;
595 memcpy(data
, data_buf
, orig_nbytes
);
597 ath10k_warn(ar
, "failed to read diag value at 0x%x: %d\n",
601 dma_free_coherent(ar
->dev
, orig_nbytes
, data_buf
,
604 spin_unlock_bh(&ar_pci
->ce_lock
);
609 static int ath10k_pci_diag_read32(struct ath10k
*ar
, u32 address
, u32
*value
)
614 ret
= ath10k_pci_diag_read_mem(ar
, address
, &val
, sizeof(val
));
615 *value
= __le32_to_cpu(val
);
620 static int __ath10k_pci_diag_read_hi(struct ath10k
*ar
, void *dest
,
626 host_addr
= host_interest_item_address(src
);
628 ret
= ath10k_pci_diag_read32(ar
, host_addr
, &addr
);
630 ath10k_warn(ar
, "failed to get memcpy hi address for firmware address %d: %d\n",
635 ret
= ath10k_pci_diag_read_mem(ar
, addr
, dest
, len
);
637 ath10k_warn(ar
, "failed to memcpy firmware memory from %d (%d B): %d\n",
645 #define ath10k_pci_diag_read_hi(ar, dest, src, len) \
646 __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len)
648 static int ath10k_pci_diag_write_mem(struct ath10k
*ar
, u32 address
,
649 const void *data
, int nbytes
)
651 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
654 unsigned int completed_nbytes
, orig_nbytes
, remaining_bytes
;
657 struct ath10k_ce_pipe
*ce_diag
;
658 void *data_buf
= NULL
;
659 u32 ce_data
; /* Host buffer address in CE space */
660 dma_addr_t ce_data_base
= 0;
663 spin_lock_bh(&ar_pci
->ce_lock
);
665 ce_diag
= ar_pci
->ce_diag
;
668 * Allocate a temporary bounce buffer to hold caller's data
669 * to be DMA'ed to Target. This guarantees
670 * 1) 4-byte alignment
671 * 2) Buffer in DMA-able space
673 orig_nbytes
= nbytes
;
674 data_buf
= (unsigned char *)dma_alloc_coherent(ar
->dev
,
683 /* Copy caller's data to allocated DMA buf */
684 memcpy(data_buf
, data
, orig_nbytes
);
687 * The address supplied by the caller is in the
688 * Target CPU virtual address space.
690 * In order to use this address with the diagnostic CE,
692 * Target CPU virtual address space
696 address
= TARG_CPU_SPACE_TO_CE_SPACE(ar
, ar_pci
->mem
, address
);
698 remaining_bytes
= orig_nbytes
;
699 ce_data
= ce_data_base
;
700 while (remaining_bytes
) {
701 /* FIXME: check cast */
702 nbytes
= min_t(int, remaining_bytes
, DIAG_TRANSFER_LIMIT
);
704 /* Set up to receive directly into Target(!) address */
705 ret
= __ath10k_ce_rx_post_buf(ce_diag
, NULL
, address
);
710 * Request CE to send caller-supplied data that
711 * was copied to bounce buffer to Target(!) address.
713 ret
= ath10k_ce_send_nolock(ce_diag
, NULL
, (u32
)ce_data
,
719 while (ath10k_ce_completed_send_next_nolock(ce_diag
, NULL
, &buf
,
724 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
730 if (nbytes
!= completed_nbytes
) {
735 if (buf
!= ce_data
) {
741 while (ath10k_ce_completed_recv_next_nolock(ce_diag
, NULL
, &buf
,
746 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
752 if (nbytes
!= completed_nbytes
) {
757 if (buf
!= address
) {
762 remaining_bytes
-= nbytes
;
769 dma_free_coherent(ar
->dev
, orig_nbytes
, data_buf
,
774 ath10k_warn(ar
, "failed to write diag value at 0x%x: %d\n",
777 spin_unlock_bh(&ar_pci
->ce_lock
);
782 static int ath10k_pci_diag_write32(struct ath10k
*ar
, u32 address
, u32 value
)
784 __le32 val
= __cpu_to_le32(value
);
786 return ath10k_pci_diag_write_mem(ar
, address
, &val
, sizeof(val
));
789 static bool ath10k_pci_is_awake(struct ath10k
*ar
)
791 u32 val
= ath10k_pci_reg_read32(ar
, RTC_STATE_ADDRESS
);
793 return RTC_STATE_V_GET(val
) == RTC_STATE_V_ON
;
796 static int ath10k_pci_wake_wait(struct ath10k
*ar
)
801 while (tot_delay
< PCIE_WAKE_TIMEOUT
) {
802 if (ath10k_pci_is_awake(ar
))
806 tot_delay
+= curr_delay
;
815 static int ath10k_pci_wake(struct ath10k
*ar
)
817 ath10k_pci_reg_write32(ar
, PCIE_SOC_WAKE_ADDRESS
,
818 PCIE_SOC_WAKE_V_MASK
);
819 return ath10k_pci_wake_wait(ar
);
822 static void ath10k_pci_sleep(struct ath10k
*ar
)
824 ath10k_pci_reg_write32(ar
, PCIE_SOC_WAKE_ADDRESS
,
825 PCIE_SOC_WAKE_RESET
);
828 /* Called by lower (CE) layer when a send to Target completes. */
829 static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe
*ce_state
)
831 struct ath10k
*ar
= ce_state
->ar
;
832 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
833 struct ath10k_hif_cb
*cb
= &ar_pci
->msg_callbacks_current
;
834 struct sk_buff_head list
;
838 unsigned int transfer_id
;
840 __skb_queue_head_init(&list
);
841 while (ath10k_ce_completed_send_next(ce_state
, (void **)&skb
, &ce_data
,
842 &nbytes
, &transfer_id
) == 0) {
843 /* no need to call tx completion for NULL pointers */
847 __skb_queue_tail(&list
, skb
);
850 while ((skb
= __skb_dequeue(&list
)))
851 cb
->tx_completion(ar
, skb
);
854 /* Called by lower (CE) layer when data is received from the Target. */
855 static void ath10k_pci_ce_recv_data(struct ath10k_ce_pipe
*ce_state
)
857 struct ath10k
*ar
= ce_state
->ar
;
858 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
859 struct ath10k_pci_pipe
*pipe_info
= &ar_pci
->pipe_info
[ce_state
->id
];
860 struct ath10k_hif_cb
*cb
= &ar_pci
->msg_callbacks_current
;
862 struct sk_buff_head list
;
863 void *transfer_context
;
865 unsigned int nbytes
, max_nbytes
;
866 unsigned int transfer_id
;
869 __skb_queue_head_init(&list
);
870 while (ath10k_ce_completed_recv_next(ce_state
, &transfer_context
,
871 &ce_data
, &nbytes
, &transfer_id
,
873 skb
= transfer_context
;
874 max_nbytes
= skb
->len
+ skb_tailroom(skb
);
875 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(skb
)->paddr
,
876 max_nbytes
, DMA_FROM_DEVICE
);
878 if (unlikely(max_nbytes
< nbytes
)) {
879 ath10k_warn(ar
, "rxed more than expected (nbytes %d, max %d)",
881 dev_kfree_skb_any(skb
);
885 skb_put(skb
, nbytes
);
886 __skb_queue_tail(&list
, skb
);
889 while ((skb
= __skb_dequeue(&list
))) {
890 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci rx ce pipe %d len %d\n",
891 ce_state
->id
, skb
->len
);
892 ath10k_dbg_dump(ar
, ATH10K_DBG_PCI_DUMP
, NULL
, "pci rx: ",
893 skb
->data
, skb
->len
);
895 cb
->rx_completion(ar
, skb
);
898 ath10k_pci_rx_post_pipe(pipe_info
);
901 static int ath10k_pci_hif_tx_sg(struct ath10k
*ar
, u8 pipe_id
,
902 struct ath10k_hif_sg_item
*items
, int n_items
)
904 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
905 struct ath10k_pci_pipe
*pci_pipe
= &ar_pci
->pipe_info
[pipe_id
];
906 struct ath10k_ce_pipe
*ce_pipe
= pci_pipe
->ce_hdl
;
907 struct ath10k_ce_ring
*src_ring
= ce_pipe
->src_ring
;
908 unsigned int nentries_mask
;
909 unsigned int sw_index
;
910 unsigned int write_index
;
913 spin_lock_bh(&ar_pci
->ce_lock
);
915 nentries_mask
= src_ring
->nentries_mask
;
916 sw_index
= src_ring
->sw_index
;
917 write_index
= src_ring
->write_index
;
919 if (unlikely(CE_RING_DELTA(nentries_mask
,
920 write_index
, sw_index
- 1) < n_items
)) {
925 for (i
= 0; i
< n_items
- 1; i
++) {
926 ath10k_dbg(ar
, ATH10K_DBG_PCI
,
927 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
928 i
, items
[i
].paddr
, items
[i
].len
, n_items
);
929 ath10k_dbg_dump(ar
, ATH10K_DBG_PCI_DUMP
, NULL
, "pci tx data: ",
930 items
[i
].vaddr
, items
[i
].len
);
932 err
= ath10k_ce_send_nolock(ce_pipe
,
933 items
[i
].transfer_context
,
936 items
[i
].transfer_id
,
937 CE_SEND_FLAG_GATHER
);
942 /* `i` is equal to `n_items -1` after for() */
944 ath10k_dbg(ar
, ATH10K_DBG_PCI
,
945 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
946 i
, items
[i
].paddr
, items
[i
].len
, n_items
);
947 ath10k_dbg_dump(ar
, ATH10K_DBG_PCI_DUMP
, NULL
, "pci tx data: ",
948 items
[i
].vaddr
, items
[i
].len
);
950 err
= ath10k_ce_send_nolock(ce_pipe
,
951 items
[i
].transfer_context
,
954 items
[i
].transfer_id
,
959 spin_unlock_bh(&ar_pci
->ce_lock
);
964 __ath10k_ce_send_revert(ce_pipe
);
966 spin_unlock_bh(&ar_pci
->ce_lock
);
970 static int ath10k_pci_hif_diag_read(struct ath10k
*ar
, u32 address
, void *buf
,
973 return ath10k_pci_diag_read_mem(ar
, address
, buf
, buf_len
);
976 static u16
ath10k_pci_hif_get_free_queue_number(struct ath10k
*ar
, u8 pipe
)
978 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
980 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci hif get free queue number\n");
982 return ath10k_ce_num_free_src_entries(ar_pci
->pipe_info
[pipe
].ce_hdl
);
985 static void ath10k_pci_dump_registers(struct ath10k
*ar
,
986 struct ath10k_fw_crash_data
*crash_data
)
988 __le32 reg_dump_values
[REG_DUMP_COUNT_QCA988X
] = {};
991 lockdep_assert_held(&ar
->data_lock
);
993 ret
= ath10k_pci_diag_read_hi(ar
, ®_dump_values
[0],
995 REG_DUMP_COUNT_QCA988X
* sizeof(__le32
));
997 ath10k_err(ar
, "failed to read firmware dump area: %d\n", ret
);
1001 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X
% 4);
1003 ath10k_err(ar
, "firmware register dump:\n");
1004 for (i
= 0; i
< REG_DUMP_COUNT_QCA988X
; i
+= 4)
1005 ath10k_err(ar
, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
1007 __le32_to_cpu(reg_dump_values
[i
]),
1008 __le32_to_cpu(reg_dump_values
[i
+ 1]),
1009 __le32_to_cpu(reg_dump_values
[i
+ 2]),
1010 __le32_to_cpu(reg_dump_values
[i
+ 3]));
1015 for (i
= 0; i
< REG_DUMP_COUNT_QCA988X
; i
++)
1016 crash_data
->registers
[i
] = reg_dump_values
[i
];
1019 static void ath10k_pci_fw_crashed_dump(struct ath10k
*ar
)
1021 struct ath10k_fw_crash_data
*crash_data
;
1024 spin_lock_bh(&ar
->data_lock
);
1026 ar
->stats
.fw_crash_counter
++;
1028 crash_data
= ath10k_debug_get_new_fw_crash_data(ar
);
1031 scnprintf(uuid
, sizeof(uuid
), "%pUl", &crash_data
->uuid
);
1033 scnprintf(uuid
, sizeof(uuid
), "n/a");
1035 ath10k_err(ar
, "firmware crashed! (uuid %s)\n", uuid
);
1036 ath10k_print_driver_info(ar
);
1037 ath10k_pci_dump_registers(ar
, crash_data
);
1039 spin_unlock_bh(&ar
->data_lock
);
1041 queue_work(ar
->workqueue
, &ar
->restart_work
);
1044 static void ath10k_pci_hif_send_complete_check(struct ath10k
*ar
, u8 pipe
,
1047 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci hif send complete check\n");
1052 * Decide whether to actually poll for completions, or just
1053 * wait for a later chance.
1054 * If there seem to be plenty of resources left, then just wait
1055 * since checking involves reading a CE register, which is a
1056 * relatively expensive operation.
1058 resources
= ath10k_pci_hif_get_free_queue_number(ar
, pipe
);
1061 * If at least 50% of the total resources are still available,
1062 * don't bother checking again yet.
1064 if (resources
> (host_ce_config_wlan
[pipe
].src_nentries
>> 1))
1067 ath10k_ce_per_engine_service(ar
, pipe
);
1070 static void ath10k_pci_hif_set_callbacks(struct ath10k
*ar
,
1071 struct ath10k_hif_cb
*callbacks
)
1073 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1075 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci hif set callbacks\n");
1077 memcpy(&ar_pci
->msg_callbacks_current
, callbacks
,
1078 sizeof(ar_pci
->msg_callbacks_current
));
1081 static void ath10k_pci_kill_tasklet(struct ath10k
*ar
)
1083 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1086 tasklet_kill(&ar_pci
->intr_tq
);
1087 tasklet_kill(&ar_pci
->msi_fw_err
);
1089 for (i
= 0; i
< CE_COUNT
; i
++)
1090 tasklet_kill(&ar_pci
->pipe_info
[i
].intr
);
1092 del_timer_sync(&ar_pci
->rx_post_retry
);
1095 static int ath10k_pci_hif_map_service_to_pipe(struct ath10k
*ar
,
1096 u16 service_id
, u8
*ul_pipe
,
1097 u8
*dl_pipe
, int *ul_is_polled
,
1100 const struct service_to_pipe
*entry
;
1101 bool ul_set
= false, dl_set
= false;
1104 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci hif map service\n");
1106 /* polling for received messages not supported */
1109 for (i
= 0; i
< ARRAY_SIZE(target_service_to_ce_map_wlan
); i
++) {
1110 entry
= &target_service_to_ce_map_wlan
[i
];
1112 if (__le32_to_cpu(entry
->service_id
) != service_id
)
1115 switch (__le32_to_cpu(entry
->pipedir
)) {
1120 *dl_pipe
= __le32_to_cpu(entry
->pipenum
);
1125 *ul_pipe
= __le32_to_cpu(entry
->pipenum
);
1131 *dl_pipe
= __le32_to_cpu(entry
->pipenum
);
1132 *ul_pipe
= __le32_to_cpu(entry
->pipenum
);
1139 if (WARN_ON(!ul_set
|| !dl_set
))
1143 (host_ce_config_wlan
[*ul_pipe
].flags
& CE_ATTR_DIS_INTR
) != 0;
1148 static void ath10k_pci_hif_get_default_pipe(struct ath10k
*ar
,
1149 u8
*ul_pipe
, u8
*dl_pipe
)
1151 int ul_is_polled
, dl_is_polled
;
1153 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci hif get default pipe\n");
1155 (void)ath10k_pci_hif_map_service_to_pipe(ar
,
1156 ATH10K_HTC_SVC_ID_RSVD_CTRL
,
1163 static void ath10k_pci_irq_msi_fw_mask(struct ath10k
*ar
)
1167 val
= ath10k_pci_read32(ar
, SOC_CORE_BASE_ADDRESS
+ CORE_CTRL_ADDRESS
);
1168 val
&= ~CORE_CTRL_PCIE_REG_31_MASK
;
1170 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ CORE_CTRL_ADDRESS
, val
);
1173 static void ath10k_pci_irq_msi_fw_unmask(struct ath10k
*ar
)
1177 val
= ath10k_pci_read32(ar
, SOC_CORE_BASE_ADDRESS
+ CORE_CTRL_ADDRESS
);
1178 val
|= CORE_CTRL_PCIE_REG_31_MASK
;
1180 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ CORE_CTRL_ADDRESS
, val
);
1183 static void ath10k_pci_irq_disable(struct ath10k
*ar
)
1185 ath10k_ce_disable_interrupts(ar
);
1186 ath10k_pci_disable_and_clear_legacy_irq(ar
);
1187 ath10k_pci_irq_msi_fw_mask(ar
);
1190 static void ath10k_pci_irq_sync(struct ath10k
*ar
)
1192 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1195 for (i
= 0; i
< max(1, ar_pci
->num_msi_intrs
); i
++)
1196 synchronize_irq(ar_pci
->pdev
->irq
+ i
);
1199 static void ath10k_pci_irq_enable(struct ath10k
*ar
)
1201 ath10k_ce_enable_interrupts(ar
);
1202 ath10k_pci_enable_legacy_irq(ar
);
1203 ath10k_pci_irq_msi_fw_unmask(ar
);
1206 static int ath10k_pci_hif_start(struct ath10k
*ar
)
1208 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot hif start\n");
1210 ath10k_pci_irq_enable(ar
);
1211 ath10k_pci_rx_post(ar
);
1216 static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe
*pci_pipe
)
1219 struct ath10k_ce_pipe
*ce_pipe
;
1220 struct ath10k_ce_ring
*ce_ring
;
1221 struct sk_buff
*skb
;
1224 ar
= pci_pipe
->hif_ce_state
;
1225 ce_pipe
= pci_pipe
->ce_hdl
;
1226 ce_ring
= ce_pipe
->dest_ring
;
1231 if (!pci_pipe
->buf_sz
)
1234 for (i
= 0; i
< ce_ring
->nentries
; i
++) {
1235 skb
= ce_ring
->per_transfer_context
[i
];
1239 ce_ring
->per_transfer_context
[i
] = NULL
;
1241 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(skb
)->paddr
,
1242 skb
->len
+ skb_tailroom(skb
),
1244 dev_kfree_skb_any(skb
);
1248 static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe
*pci_pipe
)
1251 struct ath10k_pci
*ar_pci
;
1252 struct ath10k_ce_pipe
*ce_pipe
;
1253 struct ath10k_ce_ring
*ce_ring
;
1254 struct ce_desc
*ce_desc
;
1255 struct sk_buff
*skb
;
1259 ar
= pci_pipe
->hif_ce_state
;
1260 ar_pci
= ath10k_pci_priv(ar
);
1261 ce_pipe
= pci_pipe
->ce_hdl
;
1262 ce_ring
= ce_pipe
->src_ring
;
1267 if (!pci_pipe
->buf_sz
)
1270 ce_desc
= ce_ring
->shadow_base
;
1271 if (WARN_ON(!ce_desc
))
1274 for (i
= 0; i
< ce_ring
->nentries
; i
++) {
1275 skb
= ce_ring
->per_transfer_context
[i
];
1279 ce_ring
->per_transfer_context
[i
] = NULL
;
1280 id
= MS(__le16_to_cpu(ce_desc
[i
].flags
),
1281 CE_DESC_FLAGS_META_DATA
);
1283 ar_pci
->msg_callbacks_current
.tx_completion(ar
, skb
);
1288 * Cleanup residual buffers for device shutdown:
1289 * buffers that were enqueued for receive
1290 * buffers that were to be sent
1291 * Note: Buffers that had completed but which were
1292 * not yet processed are on a completion queue. They
1293 * are handled when the completion thread shuts down.
1295 static void ath10k_pci_buffer_cleanup(struct ath10k
*ar
)
1297 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1300 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
1301 struct ath10k_pci_pipe
*pipe_info
;
1303 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
1304 ath10k_pci_rx_pipe_cleanup(pipe_info
);
1305 ath10k_pci_tx_pipe_cleanup(pipe_info
);
1309 static void ath10k_pci_ce_deinit(struct ath10k
*ar
)
1313 for (i
= 0; i
< CE_COUNT
; i
++)
1314 ath10k_ce_deinit_pipe(ar
, i
);
1317 static void ath10k_pci_flush(struct ath10k
*ar
)
1319 ath10k_pci_kill_tasklet(ar
);
1320 ath10k_pci_buffer_cleanup(ar
);
1323 static void ath10k_pci_hif_stop(struct ath10k
*ar
)
1325 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot hif stop\n");
1327 /* Most likely the device has HTT Rx ring configured. The only way to
1328 * prevent the device from accessing (and possible corrupting) host
1329 * memory is to reset the chip now.
1331 * There's also no known way of masking MSI interrupts on the device.
1332 * For ranged MSI the CE-related interrupts can be masked. However
1333 * regardless how many MSI interrupts are assigned the first one
1334 * is always used for firmware indications (crashes) and cannot be
1335 * masked. To prevent the device from asserting the interrupt reset it
1336 * before proceeding with cleanup.
1338 ath10k_pci_warm_reset(ar
);
1340 ath10k_pci_irq_disable(ar
);
1341 ath10k_pci_irq_sync(ar
);
1342 ath10k_pci_flush(ar
);
1345 static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k
*ar
,
1346 void *req
, u32 req_len
,
1347 void *resp
, u32
*resp_len
)
1349 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1350 struct ath10k_pci_pipe
*pci_tx
= &ar_pci
->pipe_info
[BMI_CE_NUM_TO_TARG
];
1351 struct ath10k_pci_pipe
*pci_rx
= &ar_pci
->pipe_info
[BMI_CE_NUM_TO_HOST
];
1352 struct ath10k_ce_pipe
*ce_tx
= pci_tx
->ce_hdl
;
1353 struct ath10k_ce_pipe
*ce_rx
= pci_rx
->ce_hdl
;
1354 dma_addr_t req_paddr
= 0;
1355 dma_addr_t resp_paddr
= 0;
1356 struct bmi_xfer xfer
= {};
1357 void *treq
, *tresp
= NULL
;
1362 if (resp
&& !resp_len
)
1365 if (resp
&& resp_len
&& *resp_len
== 0)
1368 treq
= kmemdup(req
, req_len
, GFP_KERNEL
);
1372 req_paddr
= dma_map_single(ar
->dev
, treq
, req_len
, DMA_TO_DEVICE
);
1373 ret
= dma_mapping_error(ar
->dev
, req_paddr
);
1377 if (resp
&& resp_len
) {
1378 tresp
= kzalloc(*resp_len
, GFP_KERNEL
);
1384 resp_paddr
= dma_map_single(ar
->dev
, tresp
, *resp_len
,
1386 ret
= dma_mapping_error(ar
->dev
, resp_paddr
);
1390 xfer
.wait_for_resp
= true;
1393 ath10k_ce_rx_post_buf(ce_rx
, &xfer
, resp_paddr
);
1396 ret
= ath10k_ce_send(ce_tx
, &xfer
, req_paddr
, req_len
, -1, 0);
1400 ret
= ath10k_pci_bmi_wait(ce_tx
, ce_rx
, &xfer
);
1403 unsigned int unused_nbytes
;
1404 unsigned int unused_id
;
1406 ath10k_ce_cancel_send_next(ce_tx
, NULL
, &unused_buffer
,
1407 &unused_nbytes
, &unused_id
);
1409 /* non-zero means we did not time out */
1417 ath10k_ce_revoke_recv_next(ce_rx
, NULL
, &unused_buffer
);
1418 dma_unmap_single(ar
->dev
, resp_paddr
,
1419 *resp_len
, DMA_FROM_DEVICE
);
1422 dma_unmap_single(ar
->dev
, req_paddr
, req_len
, DMA_TO_DEVICE
);
1424 if (ret
== 0 && resp_len
) {
1425 *resp_len
= min(*resp_len
, xfer
.resp_len
);
1426 memcpy(resp
, tresp
, xfer
.resp_len
);
1435 static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe
*ce_state
)
1437 struct bmi_xfer
*xfer
;
1439 unsigned int nbytes
;
1440 unsigned int transfer_id
;
1442 if (ath10k_ce_completed_send_next(ce_state
, (void **)&xfer
, &ce_data
,
1443 &nbytes
, &transfer_id
))
1446 xfer
->tx_done
= true;
1449 static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe
*ce_state
)
1451 struct ath10k
*ar
= ce_state
->ar
;
1452 struct bmi_xfer
*xfer
;
1454 unsigned int nbytes
;
1455 unsigned int transfer_id
;
1458 if (ath10k_ce_completed_recv_next(ce_state
, (void **)&xfer
, &ce_data
,
1459 &nbytes
, &transfer_id
, &flags
))
1462 if (WARN_ON_ONCE(!xfer
))
1465 if (!xfer
->wait_for_resp
) {
1466 ath10k_warn(ar
, "unexpected: BMI data received; ignoring\n");
1470 xfer
->resp_len
= nbytes
;
1471 xfer
->rx_done
= true;
1474 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe
*tx_pipe
,
1475 struct ath10k_ce_pipe
*rx_pipe
,
1476 struct bmi_xfer
*xfer
)
1478 unsigned long timeout
= jiffies
+ BMI_COMMUNICATION_TIMEOUT_HZ
;
1480 while (time_before_eq(jiffies
, timeout
)) {
1481 ath10k_pci_bmi_send_done(tx_pipe
);
1482 ath10k_pci_bmi_recv_data(rx_pipe
);
1484 if (xfer
->tx_done
&& (xfer
->rx_done
== xfer
->wait_for_resp
))
1494 * Send an interrupt to the device to wake up the Target CPU
1495 * so it has an opportunity to notice any changed state.
1497 static int ath10k_pci_wake_target_cpu(struct ath10k
*ar
)
1501 addr
= SOC_CORE_BASE_ADDRESS
| CORE_CTRL_ADDRESS
;
1502 val
= ath10k_pci_read32(ar
, addr
);
1503 val
|= CORE_CTRL_CPU_INTR_MASK
;
1504 ath10k_pci_write32(ar
, addr
, val
);
1509 static int ath10k_pci_init_config(struct ath10k
*ar
)
1511 u32 interconnect_targ_addr
;
1512 u32 pcie_state_targ_addr
= 0;
1513 u32 pipe_cfg_targ_addr
= 0;
1514 u32 svc_to_pipe_map
= 0;
1515 u32 pcie_config_flags
= 0;
1517 u32 ealloc_targ_addr
;
1519 u32 flag2_targ_addr
;
1522 /* Download to Target the CE Config and the service-to-CE map */
1523 interconnect_targ_addr
=
1524 host_interest_item_address(HI_ITEM(hi_interconnect_state
));
1526 /* Supply Target-side CE configuration */
1527 ret
= ath10k_pci_diag_read32(ar
, interconnect_targ_addr
,
1528 &pcie_state_targ_addr
);
1530 ath10k_err(ar
, "Failed to get pcie state addr: %d\n", ret
);
1534 if (pcie_state_targ_addr
== 0) {
1536 ath10k_err(ar
, "Invalid pcie state addr\n");
1540 ret
= ath10k_pci_diag_read32(ar
, (pcie_state_targ_addr
+
1541 offsetof(struct pcie_state
,
1543 &pipe_cfg_targ_addr
);
1545 ath10k_err(ar
, "Failed to get pipe cfg addr: %d\n", ret
);
1549 if (pipe_cfg_targ_addr
== 0) {
1551 ath10k_err(ar
, "Invalid pipe cfg addr\n");
1555 ret
= ath10k_pci_diag_write_mem(ar
, pipe_cfg_targ_addr
,
1556 target_ce_config_wlan
,
1557 sizeof(target_ce_config_wlan
));
1560 ath10k_err(ar
, "Failed to write pipe cfg: %d\n", ret
);
1564 ret
= ath10k_pci_diag_read32(ar
, (pcie_state_targ_addr
+
1565 offsetof(struct pcie_state
,
1569 ath10k_err(ar
, "Failed to get svc/pipe map: %d\n", ret
);
1573 if (svc_to_pipe_map
== 0) {
1575 ath10k_err(ar
, "Invalid svc_to_pipe map\n");
1579 ret
= ath10k_pci_diag_write_mem(ar
, svc_to_pipe_map
,
1580 target_service_to_ce_map_wlan
,
1581 sizeof(target_service_to_ce_map_wlan
));
1583 ath10k_err(ar
, "Failed to write svc/pipe map: %d\n", ret
);
1587 ret
= ath10k_pci_diag_read32(ar
, (pcie_state_targ_addr
+
1588 offsetof(struct pcie_state
,
1590 &pcie_config_flags
);
1592 ath10k_err(ar
, "Failed to get pcie config_flags: %d\n", ret
);
1596 pcie_config_flags
&= ~PCIE_CONFIG_FLAG_ENABLE_L1
;
1598 ret
= ath10k_pci_diag_write32(ar
, (pcie_state_targ_addr
+
1599 offsetof(struct pcie_state
,
1603 ath10k_err(ar
, "Failed to write pcie config_flags: %d\n", ret
);
1607 /* configure early allocation */
1608 ealloc_targ_addr
= host_interest_item_address(HI_ITEM(hi_early_alloc
));
1610 ret
= ath10k_pci_diag_read32(ar
, ealloc_targ_addr
, &ealloc_value
);
1612 ath10k_err(ar
, "Faile to get early alloc val: %d\n", ret
);
1616 /* first bank is switched to IRAM */
1617 ealloc_value
|= ((HI_EARLY_ALLOC_MAGIC
<< HI_EARLY_ALLOC_MAGIC_SHIFT
) &
1618 HI_EARLY_ALLOC_MAGIC_MASK
);
1619 ealloc_value
|= ((1 << HI_EARLY_ALLOC_IRAM_BANKS_SHIFT
) &
1620 HI_EARLY_ALLOC_IRAM_BANKS_MASK
);
1622 ret
= ath10k_pci_diag_write32(ar
, ealloc_targ_addr
, ealloc_value
);
1624 ath10k_err(ar
, "Failed to set early alloc val: %d\n", ret
);
1628 /* Tell Target to proceed with initialization */
1629 flag2_targ_addr
= host_interest_item_address(HI_ITEM(hi_option_flag2
));
1631 ret
= ath10k_pci_diag_read32(ar
, flag2_targ_addr
, &flag2_value
);
1633 ath10k_err(ar
, "Failed to get option val: %d\n", ret
);
1637 flag2_value
|= HI_OPTION_EARLY_CFG_DONE
;
1639 ret
= ath10k_pci_diag_write32(ar
, flag2_targ_addr
, flag2_value
);
1641 ath10k_err(ar
, "Failed to set option val: %d\n", ret
);
1648 static int ath10k_pci_alloc_pipes(struct ath10k
*ar
)
1650 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1651 struct ath10k_pci_pipe
*pipe
;
1654 for (i
= 0; i
< CE_COUNT
; i
++) {
1655 pipe
= &ar_pci
->pipe_info
[i
];
1656 pipe
->ce_hdl
= &ar_pci
->ce_states
[i
];
1658 pipe
->hif_ce_state
= ar
;
1660 ret
= ath10k_ce_alloc_pipe(ar
, i
, &host_ce_config_wlan
[i
],
1661 ath10k_pci_ce_send_done
,
1662 ath10k_pci_ce_recv_data
);
1664 ath10k_err(ar
, "failed to allocate copy engine pipe %d: %d\n",
1669 /* Last CE is Diagnostic Window */
1670 if (i
== CE_COUNT
- 1) {
1671 ar_pci
->ce_diag
= pipe
->ce_hdl
;
1675 pipe
->buf_sz
= (size_t)(host_ce_config_wlan
[i
].src_sz_max
);
1681 static void ath10k_pci_free_pipes(struct ath10k
*ar
)
1685 for (i
= 0; i
< CE_COUNT
; i
++)
1686 ath10k_ce_free_pipe(ar
, i
);
1689 static int ath10k_pci_init_pipes(struct ath10k
*ar
)
1693 for (i
= 0; i
< CE_COUNT
; i
++) {
1694 ret
= ath10k_ce_init_pipe(ar
, i
, &host_ce_config_wlan
[i
]);
1696 ath10k_err(ar
, "failed to initialize copy engine pipe %d: %d\n",
1705 static bool ath10k_pci_has_fw_crashed(struct ath10k
*ar
)
1707 return ath10k_pci_read32(ar
, FW_INDICATOR_ADDRESS
) &
1708 FW_IND_EVENT_PENDING
;
1711 static void ath10k_pci_fw_crashed_clear(struct ath10k
*ar
)
1715 val
= ath10k_pci_read32(ar
, FW_INDICATOR_ADDRESS
);
1716 val
&= ~FW_IND_EVENT_PENDING
;
1717 ath10k_pci_write32(ar
, FW_INDICATOR_ADDRESS
, val
);
1720 /* this function effectively clears target memory controller assert line */
1721 static void ath10k_pci_warm_reset_si0(struct ath10k
*ar
)
1725 val
= ath10k_pci_soc_read32(ar
, SOC_RESET_CONTROL_ADDRESS
);
1726 ath10k_pci_soc_write32(ar
, SOC_RESET_CONTROL_ADDRESS
,
1727 val
| SOC_RESET_CONTROL_SI0_RST_MASK
);
1728 val
= ath10k_pci_soc_read32(ar
, SOC_RESET_CONTROL_ADDRESS
);
1732 val
= ath10k_pci_soc_read32(ar
, SOC_RESET_CONTROL_ADDRESS
);
1733 ath10k_pci_soc_write32(ar
, SOC_RESET_CONTROL_ADDRESS
,
1734 val
& ~SOC_RESET_CONTROL_SI0_RST_MASK
);
1735 val
= ath10k_pci_soc_read32(ar
, SOC_RESET_CONTROL_ADDRESS
);
1740 static void ath10k_pci_warm_reset_cpu(struct ath10k
*ar
)
1744 ath10k_pci_write32(ar
, FW_INDICATOR_ADDRESS
, 0);
1746 val
= ath10k_pci_read32(ar
, RTC_SOC_BASE_ADDRESS
+
1747 SOC_RESET_CONTROL_ADDRESS
);
1748 ath10k_pci_write32(ar
, RTC_SOC_BASE_ADDRESS
+ SOC_RESET_CONTROL_ADDRESS
,
1749 val
| SOC_RESET_CONTROL_CPU_WARM_RST_MASK
);
1752 static void ath10k_pci_warm_reset_ce(struct ath10k
*ar
)
1756 val
= ath10k_pci_read32(ar
, RTC_SOC_BASE_ADDRESS
+
1757 SOC_RESET_CONTROL_ADDRESS
);
1759 ath10k_pci_write32(ar
, RTC_SOC_BASE_ADDRESS
+ SOC_RESET_CONTROL_ADDRESS
,
1760 val
| SOC_RESET_CONTROL_CE_RST_MASK
);
1762 ath10k_pci_write32(ar
, RTC_SOC_BASE_ADDRESS
+ SOC_RESET_CONTROL_ADDRESS
,
1763 val
& ~SOC_RESET_CONTROL_CE_RST_MASK
);
1766 static void ath10k_pci_warm_reset_clear_lf(struct ath10k
*ar
)
1770 val
= ath10k_pci_read32(ar
, RTC_SOC_BASE_ADDRESS
+
1771 SOC_LF_TIMER_CONTROL0_ADDRESS
);
1772 ath10k_pci_write32(ar
, RTC_SOC_BASE_ADDRESS
+
1773 SOC_LF_TIMER_CONTROL0_ADDRESS
,
1774 val
& ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK
);
1777 static int ath10k_pci_warm_reset(struct ath10k
*ar
)
1781 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot warm reset\n");
1783 spin_lock_bh(&ar
->data_lock
);
1784 ar
->stats
.fw_warm_reset_counter
++;
1785 spin_unlock_bh(&ar
->data_lock
);
1787 ath10k_pci_irq_disable(ar
);
1789 /* Make sure the target CPU is not doing anything dangerous, e.g. if it
1790 * were to access copy engine while host performs copy engine reset
1791 * then it is possible for the device to confuse pci-e controller to
1792 * the point of bringing host system to a complete stop (i.e. hang).
1794 ath10k_pci_warm_reset_si0(ar
);
1795 ath10k_pci_warm_reset_cpu(ar
);
1796 ath10k_pci_init_pipes(ar
);
1797 ath10k_pci_wait_for_target_init(ar
);
1799 ath10k_pci_warm_reset_clear_lf(ar
);
1800 ath10k_pci_warm_reset_ce(ar
);
1801 ath10k_pci_warm_reset_cpu(ar
);
1802 ath10k_pci_init_pipes(ar
);
1804 ret
= ath10k_pci_wait_for_target_init(ar
);
1806 ath10k_warn(ar
, "failed to wait for target init: %d\n", ret
);
1810 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot warm reset complete\n");
1815 static int ath10k_pci_chip_reset(struct ath10k
*ar
)
1820 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot chip reset\n");
1822 /* Some hardware revisions (e.g. CUS223v2) has issues with cold reset.
1823 * It is thus preferred to use warm reset which is safer but may not be
1824 * able to recover the device from all possible fail scenarios.
1826 * Warm reset doesn't always work on first try so attempt it a few
1827 * times before giving up.
1829 for (i
= 0; i
< ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS
; i
++) {
1830 ret
= ath10k_pci_warm_reset(ar
);
1832 ath10k_warn(ar
, "failed to warm reset attempt %d of %d: %d\n",
1833 i
+ 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS
,
1838 /* FIXME: Sometimes copy engine doesn't recover after warm
1839 * reset. In most cases this needs cold reset. In some of these
1840 * cases the device is in such a state that a cold reset may
1843 * Reading any host interest register via copy engine is
1844 * sufficient to verify if device is capable of booting
1847 ret
= ath10k_pci_init_pipes(ar
);
1849 ath10k_warn(ar
, "failed to init copy engine: %d\n",
1854 ret
= ath10k_pci_diag_read32(ar
, QCA988X_HOST_INTEREST_ADDRESS
,
1857 ath10k_warn(ar
, "failed to poke copy engine: %d\n",
1862 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot chip reset complete (warm)\n");
1866 if (ath10k_pci_reset_mode
== ATH10K_PCI_RESET_WARM_ONLY
) {
1867 ath10k_warn(ar
, "refusing cold reset as requested\n");
1871 ret
= ath10k_pci_cold_reset(ar
);
1873 ath10k_warn(ar
, "failed to cold reset: %d\n", ret
);
1877 ret
= ath10k_pci_wait_for_target_init(ar
);
1879 ath10k_warn(ar
, "failed to wait for target after cold reset: %d\n",
1884 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot chip reset complete (cold)\n");
1889 static int ath10k_pci_hif_power_up(struct ath10k
*ar
)
1893 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot hif power up\n");
1895 ret
= ath10k_pci_wake(ar
);
1897 ath10k_err(ar
, "failed to wake up target: %d\n", ret
);
1902 * Bring the target up cleanly.
1904 * The target may be in an undefined state with an AUX-powered Target
1905 * and a Host in WoW mode. If the Host crashes, loses power, or is
1906 * restarted (without unloading the driver) then the Target is left
1907 * (aux) powered and running. On a subsequent driver load, the Target
1908 * is in an unexpected state. We try to catch that here in order to
1909 * reset the Target and retry the probe.
1911 ret
= ath10k_pci_chip_reset(ar
);
1913 ath10k_err(ar
, "failed to reset chip: %d\n", ret
);
1917 ret
= ath10k_pci_init_pipes(ar
);
1919 ath10k_err(ar
, "failed to initialize CE: %d\n", ret
);
1923 ret
= ath10k_pci_init_config(ar
);
1925 ath10k_err(ar
, "failed to setup init config: %d\n", ret
);
1929 ret
= ath10k_pci_wake_target_cpu(ar
);
1931 ath10k_err(ar
, "could not wake up target CPU: %d\n", ret
);
1938 ath10k_pci_ce_deinit(ar
);
1941 ath10k_pci_sleep(ar
);
1945 static void ath10k_pci_hif_power_down(struct ath10k
*ar
)
1947 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot hif power down\n");
1949 /* Currently hif_power_up performs effectively a reset and hif_stop
1950 * resets the chip as well so there's no point in resetting here.
1953 ath10k_pci_sleep(ar
);
1958 #define ATH10K_PCI_PM_CONTROL 0x44
1960 static int ath10k_pci_hif_suspend(struct ath10k
*ar
)
1962 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1963 struct pci_dev
*pdev
= ar_pci
->pdev
;
1966 pci_read_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
, &val
);
1968 if ((val
& 0x000000ff) != 0x3) {
1969 pci_save_state(pdev
);
1970 pci_disable_device(pdev
);
1971 pci_write_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
,
1972 (val
& 0xffffff00) | 0x03);
1978 static int ath10k_pci_hif_resume(struct ath10k
*ar
)
1980 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1981 struct pci_dev
*pdev
= ar_pci
->pdev
;
1984 pci_read_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
, &val
);
1986 if ((val
& 0x000000ff) != 0) {
1987 pci_restore_state(pdev
);
1988 pci_write_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
,
1991 * Suspend/Resume resets the PCI configuration space,
1992 * so we have to re-disable the RETRY_TIMEOUT register (0x41)
1993 * to keep PCI Tx retries from interfering with C3 CPU state
1995 pci_read_config_dword(pdev
, 0x40, &val
);
1997 if ((val
& 0x0000ff00) != 0)
1998 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
2005 static const struct ath10k_hif_ops ath10k_pci_hif_ops
= {
2006 .tx_sg
= ath10k_pci_hif_tx_sg
,
2007 .diag_read
= ath10k_pci_hif_diag_read
,
2008 .diag_write
= ath10k_pci_diag_write_mem
,
2009 .exchange_bmi_msg
= ath10k_pci_hif_exchange_bmi_msg
,
2010 .start
= ath10k_pci_hif_start
,
2011 .stop
= ath10k_pci_hif_stop
,
2012 .map_service_to_pipe
= ath10k_pci_hif_map_service_to_pipe
,
2013 .get_default_pipe
= ath10k_pci_hif_get_default_pipe
,
2014 .send_complete_check
= ath10k_pci_hif_send_complete_check
,
2015 .set_callbacks
= ath10k_pci_hif_set_callbacks
,
2016 .get_free_queue_number
= ath10k_pci_hif_get_free_queue_number
,
2017 .power_up
= ath10k_pci_hif_power_up
,
2018 .power_down
= ath10k_pci_hif_power_down
,
2019 .read32
= ath10k_pci_read32
,
2020 .write32
= ath10k_pci_write32
,
2022 .suspend
= ath10k_pci_hif_suspend
,
2023 .resume
= ath10k_pci_hif_resume
,
2027 static void ath10k_pci_ce_tasklet(unsigned long ptr
)
2029 struct ath10k_pci_pipe
*pipe
= (struct ath10k_pci_pipe
*)ptr
;
2030 struct ath10k_pci
*ar_pci
= pipe
->ar_pci
;
2032 ath10k_ce_per_engine_service(ar_pci
->ar
, pipe
->pipe_num
);
2035 static void ath10k_msi_err_tasklet(unsigned long data
)
2037 struct ath10k
*ar
= (struct ath10k
*)data
;
2039 if (!ath10k_pci_has_fw_crashed(ar
)) {
2040 ath10k_warn(ar
, "received unsolicited fw crash interrupt\n");
2044 ath10k_pci_fw_crashed_clear(ar
);
2045 ath10k_pci_fw_crashed_dump(ar
);
2049 * Handler for a per-engine interrupt on a PARTICULAR CE.
2050 * This is used in cases where each CE has a private MSI interrupt.
2052 static irqreturn_t
ath10k_pci_per_engine_handler(int irq
, void *arg
)
2054 struct ath10k
*ar
= arg
;
2055 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2056 int ce_id
= irq
- ar_pci
->pdev
->irq
- MSI_ASSIGN_CE_INITIAL
;
2058 if (ce_id
< 0 || ce_id
>= ARRAY_SIZE(ar_pci
->pipe_info
)) {
2059 ath10k_warn(ar
, "unexpected/invalid irq %d ce_id %d\n", irq
,
2065 * NOTE: We are able to derive ce_id from irq because we
2066 * use a one-to-one mapping for CE's 0..5.
2067 * CE's 6 & 7 do not use interrupts at all.
2069 * This mapping must be kept in sync with the mapping
2072 tasklet_schedule(&ar_pci
->pipe_info
[ce_id
].intr
);
2076 static irqreturn_t
ath10k_pci_msi_fw_handler(int irq
, void *arg
)
2078 struct ath10k
*ar
= arg
;
2079 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2081 tasklet_schedule(&ar_pci
->msi_fw_err
);
2086 * Top-level interrupt handler for all PCI interrupts from a Target.
2087 * When a block of MSI interrupts is allocated, this top-level handler
2088 * is not used; instead, we directly call the correct sub-handler.
2090 static irqreturn_t
ath10k_pci_interrupt_handler(int irq
, void *arg
)
2092 struct ath10k
*ar
= arg
;
2093 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2095 if (ar_pci
->num_msi_intrs
== 0) {
2096 if (!ath10k_pci_irq_pending(ar
))
2099 ath10k_pci_disable_and_clear_legacy_irq(ar
);
2102 tasklet_schedule(&ar_pci
->intr_tq
);
2107 static void ath10k_pci_tasklet(unsigned long data
)
2109 struct ath10k
*ar
= (struct ath10k
*)data
;
2110 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2112 if (ath10k_pci_has_fw_crashed(ar
)) {
2113 ath10k_pci_fw_crashed_clear(ar
);
2114 ath10k_pci_fw_crashed_dump(ar
);
2118 ath10k_ce_per_engine_service_any(ar
);
2120 /* Re-enable legacy irq that was disabled in the irq handler */
2121 if (ar_pci
->num_msi_intrs
== 0)
2122 ath10k_pci_enable_legacy_irq(ar
);
2125 static int ath10k_pci_request_irq_msix(struct ath10k
*ar
)
2127 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2130 ret
= request_irq(ar_pci
->pdev
->irq
+ MSI_ASSIGN_FW
,
2131 ath10k_pci_msi_fw_handler
,
2132 IRQF_SHARED
, "ath10k_pci", ar
);
2134 ath10k_warn(ar
, "failed to request MSI-X fw irq %d: %d\n",
2135 ar_pci
->pdev
->irq
+ MSI_ASSIGN_FW
, ret
);
2139 for (i
= MSI_ASSIGN_CE_INITIAL
; i
<= MSI_ASSIGN_CE_MAX
; i
++) {
2140 ret
= request_irq(ar_pci
->pdev
->irq
+ i
,
2141 ath10k_pci_per_engine_handler
,
2142 IRQF_SHARED
, "ath10k_pci", ar
);
2144 ath10k_warn(ar
, "failed to request MSI-X ce irq %d: %d\n",
2145 ar_pci
->pdev
->irq
+ i
, ret
);
2147 for (i
--; i
>= MSI_ASSIGN_CE_INITIAL
; i
--)
2148 free_irq(ar_pci
->pdev
->irq
+ i
, ar
);
2150 free_irq(ar_pci
->pdev
->irq
+ MSI_ASSIGN_FW
, ar
);
2158 static int ath10k_pci_request_irq_msi(struct ath10k
*ar
)
2160 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2163 ret
= request_irq(ar_pci
->pdev
->irq
,
2164 ath10k_pci_interrupt_handler
,
2165 IRQF_SHARED
, "ath10k_pci", ar
);
2167 ath10k_warn(ar
, "failed to request MSI irq %d: %d\n",
2168 ar_pci
->pdev
->irq
, ret
);
2175 static int ath10k_pci_request_irq_legacy(struct ath10k
*ar
)
2177 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2180 ret
= request_irq(ar_pci
->pdev
->irq
,
2181 ath10k_pci_interrupt_handler
,
2182 IRQF_SHARED
, "ath10k_pci", ar
);
2184 ath10k_warn(ar
, "failed to request legacy irq %d: %d\n",
2185 ar_pci
->pdev
->irq
, ret
);
2192 static int ath10k_pci_request_irq(struct ath10k
*ar
)
2194 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2196 switch (ar_pci
->num_msi_intrs
) {
2198 return ath10k_pci_request_irq_legacy(ar
);
2200 return ath10k_pci_request_irq_msi(ar
);
2201 case MSI_NUM_REQUEST
:
2202 return ath10k_pci_request_irq_msix(ar
);
2205 ath10k_warn(ar
, "unknown irq configuration upon request\n");
2209 static void ath10k_pci_free_irq(struct ath10k
*ar
)
2211 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2214 /* There's at least one interrupt irregardless whether its legacy INTR
2215 * or MSI or MSI-X */
2216 for (i
= 0; i
< max(1, ar_pci
->num_msi_intrs
); i
++)
2217 free_irq(ar_pci
->pdev
->irq
+ i
, ar
);
2220 static void ath10k_pci_init_irq_tasklets(struct ath10k
*ar
)
2222 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2225 tasklet_init(&ar_pci
->intr_tq
, ath10k_pci_tasklet
, (unsigned long)ar
);
2226 tasklet_init(&ar_pci
->msi_fw_err
, ath10k_msi_err_tasklet
,
2229 for (i
= 0; i
< CE_COUNT
; i
++) {
2230 ar_pci
->pipe_info
[i
].ar_pci
= ar_pci
;
2231 tasklet_init(&ar_pci
->pipe_info
[i
].intr
, ath10k_pci_ce_tasklet
,
2232 (unsigned long)&ar_pci
->pipe_info
[i
]);
2236 static int ath10k_pci_init_irq(struct ath10k
*ar
)
2238 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2241 ath10k_pci_init_irq_tasklets(ar
);
2243 if (ath10k_pci_irq_mode
!= ATH10K_PCI_IRQ_AUTO
)
2244 ath10k_info(ar
, "limiting irq mode to: %d\n",
2245 ath10k_pci_irq_mode
);
2248 if (ath10k_pci_irq_mode
== ATH10K_PCI_IRQ_AUTO
) {
2249 ar_pci
->num_msi_intrs
= MSI_NUM_REQUEST
;
2250 ret
= pci_enable_msi_range(ar_pci
->pdev
, ar_pci
->num_msi_intrs
,
2251 ar_pci
->num_msi_intrs
);
2259 if (ath10k_pci_irq_mode
!= ATH10K_PCI_IRQ_LEGACY
) {
2260 ar_pci
->num_msi_intrs
= 1;
2261 ret
= pci_enable_msi(ar_pci
->pdev
);
2270 * A potential race occurs here: The CORE_BASE write
2271 * depends on target correctly decoding AXI address but
2272 * host won't know when target writes BAR to CORE_CTRL.
2273 * This write might get lost if target has NOT written BAR.
2274 * For now, fix the race by repeating the write in below
2275 * synchronization checking. */
2276 ar_pci
->num_msi_intrs
= 0;
2278 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ PCIE_INTR_ENABLE_ADDRESS
,
2279 PCIE_INTR_FIRMWARE_MASK
| PCIE_INTR_CE_MASK_ALL
);
2284 static void ath10k_pci_deinit_irq_legacy(struct ath10k
*ar
)
2286 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ PCIE_INTR_ENABLE_ADDRESS
,
2290 static int ath10k_pci_deinit_irq(struct ath10k
*ar
)
2292 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2294 switch (ar_pci
->num_msi_intrs
) {
2296 ath10k_pci_deinit_irq_legacy(ar
);
2300 case MSI_NUM_REQUEST
:
2301 pci_disable_msi(ar_pci
->pdev
);
2304 pci_disable_msi(ar_pci
->pdev
);
2307 ath10k_warn(ar
, "unknown irq configuration upon deinit\n");
2311 static int ath10k_pci_wait_for_target_init(struct ath10k
*ar
)
2313 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2314 unsigned long timeout
;
2317 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot waiting target to initialise\n");
2319 timeout
= jiffies
+ msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT
);
2322 val
= ath10k_pci_read32(ar
, FW_INDICATOR_ADDRESS
);
2324 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot target indicator %x\n",
2327 /* target should never return this */
2328 if (val
== 0xffffffff)
2331 /* the device has crashed so don't bother trying anymore */
2332 if (val
& FW_IND_EVENT_PENDING
)
2335 if (val
& FW_IND_INITIALIZED
)
2338 if (ar_pci
->num_msi_intrs
== 0)
2339 /* Fix potential race by repeating CORE_BASE writes */
2340 ath10k_pci_enable_legacy_irq(ar
);
2343 } while (time_before(jiffies
, timeout
));
2345 ath10k_pci_disable_and_clear_legacy_irq(ar
);
2346 ath10k_pci_irq_msi_fw_mask(ar
);
2348 if (val
== 0xffffffff) {
2349 ath10k_err(ar
, "failed to read device register, device is gone\n");
2353 if (val
& FW_IND_EVENT_PENDING
) {
2354 ath10k_warn(ar
, "device has crashed during init\n");
2355 ath10k_pci_fw_crashed_clear(ar
);
2356 ath10k_pci_fw_crashed_dump(ar
);
2360 if (!(val
& FW_IND_INITIALIZED
)) {
2361 ath10k_err(ar
, "failed to receive initialized event from target: %08x\n",
2366 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot target initialised\n");
2370 static int ath10k_pci_cold_reset(struct ath10k
*ar
)
2375 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot cold reset\n");
2377 spin_lock_bh(&ar
->data_lock
);
2379 ar
->stats
.fw_cold_reset_counter
++;
2381 spin_unlock_bh(&ar
->data_lock
);
2383 /* Put Target, including PCIe, into RESET. */
2384 val
= ath10k_pci_reg_read32(ar
, SOC_GLOBAL_RESET_ADDRESS
);
2386 ath10k_pci_reg_write32(ar
, SOC_GLOBAL_RESET_ADDRESS
, val
);
2388 for (i
= 0; i
< ATH_PCI_RESET_WAIT_MAX
; i
++) {
2389 if (ath10k_pci_reg_read32(ar
, RTC_STATE_ADDRESS
) &
2390 RTC_STATE_COLD_RESET_MASK
)
2395 /* Pull Target, including PCIe, out of RESET. */
2397 ath10k_pci_reg_write32(ar
, SOC_GLOBAL_RESET_ADDRESS
, val
);
2399 for (i
= 0; i
< ATH_PCI_RESET_WAIT_MAX
; i
++) {
2400 if (!(ath10k_pci_reg_read32(ar
, RTC_STATE_ADDRESS
) &
2401 RTC_STATE_COLD_RESET_MASK
))
2406 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot cold reset complete\n");
2411 static int ath10k_pci_claim(struct ath10k
*ar
)
2413 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2414 struct pci_dev
*pdev
= ar_pci
->pdev
;
2418 pci_set_drvdata(pdev
, ar
);
2420 ret
= pci_enable_device(pdev
);
2422 ath10k_err(ar
, "failed to enable pci device: %d\n", ret
);
2426 ret
= pci_request_region(pdev
, BAR_NUM
, "ath");
2428 ath10k_err(ar
, "failed to request region BAR%d: %d\n", BAR_NUM
,
2433 /* Target expects 32 bit DMA. Enforce it. */
2434 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
2436 ath10k_err(ar
, "failed to set dma mask to 32-bit: %d\n", ret
);
2440 ret
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
2442 ath10k_err(ar
, "failed to set consistent dma mask to 32-bit: %d\n",
2447 pci_set_master(pdev
);
2449 /* Workaround: Disable ASPM */
2450 pci_read_config_dword(pdev
, 0x80, &lcr_val
);
2451 pci_write_config_dword(pdev
, 0x80, (lcr_val
& 0xffffff00));
2453 /* Arrange for access to Target SoC registers. */
2454 ar_pci
->mem
= pci_iomap(pdev
, BAR_NUM
, 0);
2456 ath10k_err(ar
, "failed to iomap BAR%d\n", BAR_NUM
);
2461 ath10k_dbg(ar
, ATH10K_DBG_BOOT
, "boot pci_mem 0x%p\n", ar_pci
->mem
);
2465 pci_clear_master(pdev
);
2468 pci_release_region(pdev
, BAR_NUM
);
2471 pci_disable_device(pdev
);
2476 static void ath10k_pci_release(struct ath10k
*ar
)
2478 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2479 struct pci_dev
*pdev
= ar_pci
->pdev
;
2481 pci_iounmap(pdev
, ar_pci
->mem
);
2482 pci_release_region(pdev
, BAR_NUM
);
2483 pci_clear_master(pdev
);
2484 pci_disable_device(pdev
);
2487 static bool ath10k_pci_chip_is_supported(u32 dev_id
, u32 chip_id
)
2489 const struct ath10k_pci_supp_chip
*supp_chip
;
2491 u32 rev_id
= MS(chip_id
, SOC_CHIP_ID_REV
);
2493 for (i
= 0; i
< ARRAY_SIZE(ath10k_pci_supp_chips
); i
++) {
2494 supp_chip
= &ath10k_pci_supp_chips
[i
];
2496 if (supp_chip
->dev_id
== dev_id
&&
2497 supp_chip
->rev_id
== rev_id
)
2504 static int ath10k_pci_probe(struct pci_dev
*pdev
,
2505 const struct pci_device_id
*pci_dev
)
2509 struct ath10k_pci
*ar_pci
;
2512 ar
= ath10k_core_create(sizeof(*ar_pci
), &pdev
->dev
,
2514 &ath10k_pci_hif_ops
);
2516 dev_err(&pdev
->dev
, "failed to allocate core\n");
2520 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci probe\n");
2522 ar_pci
= ath10k_pci_priv(ar
);
2523 ar_pci
->pdev
= pdev
;
2524 ar_pci
->dev
= &pdev
->dev
;
2527 spin_lock_init(&ar_pci
->ce_lock
);
2528 setup_timer(&ar_pci
->rx_post_retry
, ath10k_pci_rx_replenish_retry
,
2531 ret
= ath10k_pci_claim(ar
);
2533 ath10k_err(ar
, "failed to claim device: %d\n", ret
);
2534 goto err_core_destroy
;
2537 ret
= ath10k_pci_wake(ar
);
2539 ath10k_err(ar
, "failed to wake up: %d\n", ret
);
2543 chip_id
= ath10k_pci_soc_read32(ar
, SOC_CHIP_ID_ADDRESS
);
2544 if (chip_id
== 0xffffffff) {
2545 ath10k_err(ar
, "failed to get chip id\n");
2549 if (!ath10k_pci_chip_is_supported(pdev
->device
, chip_id
)) {
2550 ath10k_err(ar
, "device %04x with chip_id %08x isn't supported\n",
2551 pdev
->device
, chip_id
);
2555 ret
= ath10k_pci_alloc_pipes(ar
);
2557 ath10k_err(ar
, "failed to allocate copy engine pipes: %d\n",
2562 ath10k_pci_ce_deinit(ar
);
2563 ath10k_pci_irq_disable(ar
);
2565 ret
= ath10k_pci_init_irq(ar
);
2567 ath10k_err(ar
, "failed to init irqs: %d\n", ret
);
2568 goto err_free_pipes
;
2571 ath10k_info(ar
, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n",
2572 ath10k_pci_get_irq_method(ar
), ar_pci
->num_msi_intrs
,
2573 ath10k_pci_irq_mode
, ath10k_pci_reset_mode
);
2575 ret
= ath10k_pci_request_irq(ar
);
2577 ath10k_warn(ar
, "failed to request irqs: %d\n", ret
);
2578 goto err_deinit_irq
;
2581 ath10k_pci_sleep(ar
);
2583 ret
= ath10k_core_register(ar
, chip_id
);
2585 ath10k_err(ar
, "failed to register driver core: %d\n", ret
);
2592 ath10k_pci_free_irq(ar
);
2593 ath10k_pci_kill_tasklet(ar
);
2596 ath10k_pci_deinit_irq(ar
);
2599 ath10k_pci_free_pipes(ar
);
2602 ath10k_pci_sleep(ar
);
2605 ath10k_pci_release(ar
);
2608 ath10k_core_destroy(ar
);
2613 static void ath10k_pci_remove(struct pci_dev
*pdev
)
2615 struct ath10k
*ar
= pci_get_drvdata(pdev
);
2616 struct ath10k_pci
*ar_pci
;
2618 ath10k_dbg(ar
, ATH10K_DBG_PCI
, "pci remove\n");
2623 ar_pci
= ath10k_pci_priv(ar
);
2628 ath10k_core_unregister(ar
);
2629 ath10k_pci_free_irq(ar
);
2630 ath10k_pci_kill_tasklet(ar
);
2631 ath10k_pci_deinit_irq(ar
);
2632 ath10k_pci_ce_deinit(ar
);
2633 ath10k_pci_free_pipes(ar
);
2634 ath10k_pci_release(ar
);
2635 ath10k_core_destroy(ar
);
2638 MODULE_DEVICE_TABLE(pci
, ath10k_pci_id_table
);
2640 static struct pci_driver ath10k_pci_driver
= {
2641 .name
= "ath10k_pci",
2642 .id_table
= ath10k_pci_id_table
,
2643 .probe
= ath10k_pci_probe
,
2644 .remove
= ath10k_pci_remove
,
2647 static int __init
ath10k_pci_init(void)
2651 ret
= pci_register_driver(&ath10k_pci_driver
);
2653 printk(KERN_ERR
"failed to register ath10k pci driver: %d\n",
2658 module_init(ath10k_pci_init
);
2660 static void __exit
ath10k_pci_exit(void)
2662 pci_unregister_driver(&ath10k_pci_driver
);
2665 module_exit(ath10k_pci_exit
);
2667 MODULE_AUTHOR("Qualcomm Atheros");
2668 MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
2669 MODULE_LICENSE("Dual BSD/GPL");
2670 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR
"/" QCA988X_HW_2_0_FW_FILE
);
2671 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR
"/" ATH10K_FW_API2_FILE
);
2672 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR
"/" ATH10K_FW_API3_FILE
);
2673 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR
"/" QCA988X_HW_2_0_BOARD_DATA_FILE
);