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 void ath10k_pci_buffer_cleanup(struct ath10k *ar);
68 static int ath10k_pci_cold_reset(struct ath10k *ar);
69 static int ath10k_pci_warm_reset(struct ath10k *ar);
70 static int ath10k_pci_wait_for_target_init(struct ath10k *ar);
71 static int ath10k_pci_init_irq(struct ath10k *ar);
72 static int ath10k_pci_deinit_irq(struct ath10k *ar);
73 static int ath10k_pci_request_irq(struct ath10k *ar);
74 static void ath10k_pci_free_irq(struct ath10k *ar);
75 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
76 struct ath10k_ce_pipe *rx_pipe,
77 struct bmi_xfer *xfer);
79 static const struct ce_attr host_ce_config_wlan[] = {
80 /* CE0: host->target HTC control and raw streams */
82 .flags = CE_ATTR_FLAGS,
88 /* CE1: target->host HTT + HTC control */
90 .flags = CE_ATTR_FLAGS,
96 /* CE2: target->host WMI */
98 .flags = CE_ATTR_FLAGS,
104 /* CE3: host->target WMI */
106 .flags = CE_ATTR_FLAGS,
112 /* CE4: host->target HTT */
114 .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
115 .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES,
122 .flags = CE_ATTR_FLAGS,
128 /* CE6: target autonomous hif_memcpy */
130 .flags = CE_ATTR_FLAGS,
136 /* CE7: ce_diag, the Diagnostic Window */
138 .flags = CE_ATTR_FLAGS,
140 .src_sz_max = DIAG_TRANSFER_LIMIT,
145 /* Target firmware's Copy Engine configuration. */
146 static const struct ce_pipe_config target_ce_config_wlan[] = {
147 /* CE0: host->target HTC control and raw streams */
149 .pipenum = __cpu_to_le32(0),
150 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
151 .nentries = __cpu_to_le32(32),
152 .nbytes_max = __cpu_to_le32(256),
153 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
154 .reserved = __cpu_to_le32(0),
157 /* CE1: target->host HTT + HTC control */
159 .pipenum = __cpu_to_le32(1),
160 .pipedir = __cpu_to_le32(PIPEDIR_IN),
161 .nentries = __cpu_to_le32(32),
162 .nbytes_max = __cpu_to_le32(512),
163 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
164 .reserved = __cpu_to_le32(0),
167 /* CE2: target->host WMI */
169 .pipenum = __cpu_to_le32(2),
170 .pipedir = __cpu_to_le32(PIPEDIR_IN),
171 .nentries = __cpu_to_le32(32),
172 .nbytes_max = __cpu_to_le32(2048),
173 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
174 .reserved = __cpu_to_le32(0),
177 /* CE3: host->target WMI */
179 .pipenum = __cpu_to_le32(3),
180 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
181 .nentries = __cpu_to_le32(32),
182 .nbytes_max = __cpu_to_le32(2048),
183 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
184 .reserved = __cpu_to_le32(0),
187 /* CE4: host->target HTT */
189 .pipenum = __cpu_to_le32(4),
190 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
191 .nentries = __cpu_to_le32(256),
192 .nbytes_max = __cpu_to_le32(256),
193 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
194 .reserved = __cpu_to_le32(0),
197 /* NB: 50% of src nentries, since tx has 2 frags */
201 .pipenum = __cpu_to_le32(5),
202 .pipedir = __cpu_to_le32(PIPEDIR_OUT),
203 .nentries = __cpu_to_le32(32),
204 .nbytes_max = __cpu_to_le32(2048),
205 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
206 .reserved = __cpu_to_le32(0),
209 /* CE6: Reserved for target autonomous hif_memcpy */
211 .pipenum = __cpu_to_le32(6),
212 .pipedir = __cpu_to_le32(PIPEDIR_INOUT),
213 .nentries = __cpu_to_le32(32),
214 .nbytes_max = __cpu_to_le32(4096),
215 .flags = __cpu_to_le32(CE_ATTR_FLAGS),
216 .reserved = __cpu_to_le32(0),
219 /* CE7 used only by Host */
223 * Map from service/endpoint to Copy Engine.
224 * This table is derived from the CE_PCI TABLE, above.
225 * It is passed to the Target at startup for use by firmware.
227 static const struct service_to_pipe target_service_to_ce_map_wlan[] = {
229 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
230 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
234 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO),
235 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
239 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
240 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
244 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK),
245 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
249 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
250 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
254 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE),
255 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
259 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
260 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
264 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI),
265 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
269 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
270 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
274 __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL),
275 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
279 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
280 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
284 __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL),
285 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
289 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
290 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
294 __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS),
295 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
299 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
300 __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */
304 __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG),
305 __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */
309 /* (Additions here) */
318 static bool ath10k_pci_irq_pending(struct ath10k *ar)
322 /* Check if the shared legacy irq is for us */
323 cause = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
324 PCIE_INTR_CAUSE_ADDRESS);
325 if (cause & (PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL))
331 static void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar)
333 /* IMPORTANT: INTR_CLR register has to be set after
334 * INTR_ENABLE is set to 0, otherwise interrupt can not be
336 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
338 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS,
339 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
341 /* IMPORTANT: this extra read transaction is required to
342 * flush the posted write buffer. */
343 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
344 PCIE_INTR_ENABLE_ADDRESS);
347 static void ath10k_pci_enable_legacy_irq(struct ath10k *ar)
349 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
350 PCIE_INTR_ENABLE_ADDRESS,
351 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
353 /* IMPORTANT: this extra read transaction is required to
354 * flush the posted write buffer. */
355 (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
356 PCIE_INTR_ENABLE_ADDRESS);
359 static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar)
361 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
363 if (ar_pci->num_msi_intrs > 1)
365 else if (ar_pci->num_msi_intrs == 1)
371 static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe)
373 struct ath10k *ar = pipe->hif_ce_state;
374 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
375 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
380 lockdep_assert_held(&ar_pci->ce_lock);
382 skb = dev_alloc_skb(pipe->buf_sz);
386 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
388 paddr = dma_map_single(ar->dev, skb->data,
389 skb->len + skb_tailroom(skb),
391 if (unlikely(dma_mapping_error(ar->dev, paddr))) {
392 ath10k_warn(ar, "failed to dma map pci rx buf\n");
393 dev_kfree_skb_any(skb);
397 ATH10K_SKB_CB(skb)->paddr = paddr;
399 ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr);
401 ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
402 dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb),
404 dev_kfree_skb_any(skb);
411 static void __ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
413 struct ath10k *ar = pipe->hif_ce_state;
414 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
415 struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl;
418 lockdep_assert_held(&ar_pci->ce_lock);
420 if (pipe->buf_sz == 0)
423 if (!ce_pipe->dest_ring)
426 num = __ath10k_ce_rx_num_free_bufs(ce_pipe);
428 ret = __ath10k_pci_rx_post_buf(pipe);
430 ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret);
431 mod_timer(&ar_pci->rx_post_retry, jiffies +
432 ATH10K_PCI_RX_POST_RETRY_MS);
438 static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe)
440 struct ath10k *ar = pipe->hif_ce_state;
441 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
443 spin_lock_bh(&ar_pci->ce_lock);
444 __ath10k_pci_rx_post_pipe(pipe);
445 spin_unlock_bh(&ar_pci->ce_lock);
448 static void ath10k_pci_rx_post(struct ath10k *ar)
450 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
453 spin_lock_bh(&ar_pci->ce_lock);
454 for (i = 0; i < CE_COUNT; i++)
455 __ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]);
456 spin_unlock_bh(&ar_pci->ce_lock);
459 static void ath10k_pci_rx_replenish_retry(unsigned long ptr)
461 struct ath10k *ar = (void *)ptr;
463 ath10k_pci_rx_post(ar);
467 * Diagnostic read/write access is provided for startup/config/debug usage.
468 * Caller must guarantee proper alignment, when applicable, and single user
471 static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
474 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
477 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
480 struct ath10k_ce_pipe *ce_diag;
481 /* Host buffer address in CE space */
483 dma_addr_t ce_data_base = 0;
484 void *data_buf = NULL;
487 ce_diag = ar_pci->ce_diag;
490 * Allocate a temporary bounce buffer to hold caller's data
491 * to be DMA'ed from Target. This guarantees
492 * 1) 4-byte alignment
493 * 2) Buffer in DMA-able space
495 orig_nbytes = nbytes;
496 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
505 memset(data_buf, 0, orig_nbytes);
507 remaining_bytes = orig_nbytes;
508 ce_data = ce_data_base;
509 while (remaining_bytes) {
510 nbytes = min_t(unsigned int, remaining_bytes,
511 DIAG_TRANSFER_LIMIT);
513 ret = ath10k_ce_rx_post_buf(ce_diag, NULL, ce_data);
517 /* Request CE to send from Target(!) address to Host buffer */
519 * The address supplied by the caller is in the
520 * Target CPU virtual address space.
522 * In order to use this address with the diagnostic CE,
523 * convert it from Target CPU virtual address space
524 * to CE address space
526 address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem,
529 ret = ath10k_ce_send(ce_diag, NULL, (u32)address, nbytes, 0,
535 while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf,
539 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
545 if (nbytes != completed_nbytes) {
550 if (buf != (u32)address) {
556 while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf,
561 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
567 if (nbytes != completed_nbytes) {
572 if (buf != ce_data) {
577 remaining_bytes -= nbytes;
584 memcpy(data, data_buf, orig_nbytes);
586 ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n",
590 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
596 static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value)
601 ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val));
602 *value = __le32_to_cpu(val);
607 static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest,
613 host_addr = host_interest_item_address(src);
615 ret = ath10k_pci_diag_read32(ar, host_addr, &addr);
617 ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n",
622 ret = ath10k_pci_diag_read_mem(ar, addr, dest, len);
624 ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n",
632 #define ath10k_pci_diag_read_hi(ar, dest, src, len) \
633 __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len);
635 static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
636 const void *data, int nbytes)
638 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
641 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
644 struct ath10k_ce_pipe *ce_diag;
645 void *data_buf = NULL;
646 u32 ce_data; /* Host buffer address in CE space */
647 dma_addr_t ce_data_base = 0;
650 ce_diag = ar_pci->ce_diag;
653 * Allocate a temporary bounce buffer to hold caller's data
654 * to be DMA'ed to Target. This guarantees
655 * 1) 4-byte alignment
656 * 2) Buffer in DMA-able space
658 orig_nbytes = nbytes;
659 data_buf = (unsigned char *)dma_alloc_coherent(ar->dev,
668 /* Copy caller's data to allocated DMA buf */
669 memcpy(data_buf, data, orig_nbytes);
672 * The address supplied by the caller is in the
673 * Target CPU virtual address space.
675 * In order to use this address with the diagnostic CE,
677 * Target CPU virtual address space
681 address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem, address);
683 remaining_bytes = orig_nbytes;
684 ce_data = ce_data_base;
685 while (remaining_bytes) {
686 /* FIXME: check cast */
687 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
689 /* Set up to receive directly into Target(!) address */
690 ret = ath10k_ce_rx_post_buf(ce_diag, NULL, address);
695 * Request CE to send caller-supplied data that
696 * was copied to bounce buffer to Target(!) address.
698 ret = ath10k_ce_send(ce_diag, NULL, (u32)ce_data,
704 while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf,
709 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
715 if (nbytes != completed_nbytes) {
720 if (buf != ce_data) {
726 while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf,
731 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
737 if (nbytes != completed_nbytes) {
742 if (buf != address) {
747 remaining_bytes -= nbytes;
754 dma_free_coherent(ar->dev, orig_nbytes, data_buf,
759 ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n",
765 static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value)
767 __le32 val = __cpu_to_le32(value);
769 return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val));
772 static bool ath10k_pci_is_awake(struct ath10k *ar)
774 u32 val = ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS);
776 return RTC_STATE_V_GET(val) == RTC_STATE_V_ON;
779 static int ath10k_pci_wake_wait(struct ath10k *ar)
784 while (tot_delay < PCIE_WAKE_TIMEOUT) {
785 if (ath10k_pci_is_awake(ar))
789 tot_delay += curr_delay;
798 static int ath10k_pci_wake(struct ath10k *ar)
800 ath10k_pci_reg_write32(ar, PCIE_SOC_WAKE_ADDRESS,
801 PCIE_SOC_WAKE_V_MASK);
802 return ath10k_pci_wake_wait(ar);
805 static void ath10k_pci_sleep(struct ath10k *ar)
807 ath10k_pci_reg_write32(ar, PCIE_SOC_WAKE_ADDRESS,
808 PCIE_SOC_WAKE_RESET);
811 /* Called by lower (CE) layer when a send to Target completes. */
812 static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe *ce_state)
814 struct ath10k *ar = ce_state->ar;
815 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
816 struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current;
817 void *transfer_context;
820 unsigned int transfer_id;
822 while (ath10k_ce_completed_send_next(ce_state, &transfer_context,
824 &transfer_id) == 0) {
825 /* no need to call tx completion for NULL pointers */
826 if (transfer_context == NULL)
829 cb->tx_completion(ar, transfer_context, transfer_id);
833 /* Called by lower (CE) layer when data is received from the Target. */
834 static void ath10k_pci_ce_recv_data(struct ath10k_ce_pipe *ce_state)
836 struct ath10k *ar = ce_state->ar;
837 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
838 struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id];
839 struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current;
841 void *transfer_context;
843 unsigned int nbytes, max_nbytes;
844 unsigned int transfer_id;
847 while (ath10k_ce_completed_recv_next(ce_state, &transfer_context,
848 &ce_data, &nbytes, &transfer_id,
850 skb = transfer_context;
851 max_nbytes = skb->len + skb_tailroom(skb);
852 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
853 max_nbytes, DMA_FROM_DEVICE);
855 if (unlikely(max_nbytes < nbytes)) {
856 ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)",
858 dev_kfree_skb_any(skb);
862 skb_put(skb, nbytes);
863 cb->rx_completion(ar, skb, pipe_info->pipe_num);
866 ath10k_pci_rx_post_pipe(pipe_info);
869 static int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id,
870 struct ath10k_hif_sg_item *items, int n_items)
872 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
873 struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id];
874 struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl;
875 struct ath10k_ce_ring *src_ring = ce_pipe->src_ring;
876 unsigned int nentries_mask;
877 unsigned int sw_index;
878 unsigned int write_index;
881 spin_lock_bh(&ar_pci->ce_lock);
883 nentries_mask = src_ring->nentries_mask;
884 sw_index = src_ring->sw_index;
885 write_index = src_ring->write_index;
887 if (unlikely(CE_RING_DELTA(nentries_mask,
888 write_index, sw_index - 1) < n_items)) {
893 for (i = 0; i < n_items - 1; i++) {
894 ath10k_dbg(ar, ATH10K_DBG_PCI,
895 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
896 i, items[i].paddr, items[i].len, n_items);
897 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
898 items[i].vaddr, items[i].len);
900 err = ath10k_ce_send_nolock(ce_pipe,
901 items[i].transfer_context,
904 items[i].transfer_id,
905 CE_SEND_FLAG_GATHER);
910 /* `i` is equal to `n_items -1` after for() */
912 ath10k_dbg(ar, ATH10K_DBG_PCI,
913 "pci tx item %d paddr 0x%08x len %d n_items %d\n",
914 i, items[i].paddr, items[i].len, n_items);
915 ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ",
916 items[i].vaddr, items[i].len);
918 err = ath10k_ce_send_nolock(ce_pipe,
919 items[i].transfer_context,
922 items[i].transfer_id,
927 spin_unlock_bh(&ar_pci->ce_lock);
932 __ath10k_ce_send_revert(ce_pipe);
934 spin_unlock_bh(&ar_pci->ce_lock);
938 static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
940 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
942 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n");
944 return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl);
947 static void ath10k_pci_dump_registers(struct ath10k *ar,
948 struct ath10k_fw_crash_data *crash_data)
950 __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
953 lockdep_assert_held(&ar->data_lock);
955 ret = ath10k_pci_diag_read_hi(ar, ®_dump_values[0],
957 REG_DUMP_COUNT_QCA988X * sizeof(__le32));
959 ath10k_err(ar, "failed to read firmware dump area: %d\n", ret);
963 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
965 ath10k_err(ar, "firmware register dump:\n");
966 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
967 ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
969 __le32_to_cpu(reg_dump_values[i]),
970 __le32_to_cpu(reg_dump_values[i + 1]),
971 __le32_to_cpu(reg_dump_values[i + 2]),
972 __le32_to_cpu(reg_dump_values[i + 3]));
977 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++)
978 crash_data->registers[i] = reg_dump_values[i];
981 static void ath10k_pci_fw_crashed_dump(struct ath10k *ar)
983 struct ath10k_fw_crash_data *crash_data;
986 spin_lock_bh(&ar->data_lock);
988 crash_data = ath10k_debug_get_new_fw_crash_data(ar);
991 scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid);
993 scnprintf(uuid, sizeof(uuid), "n/a");
995 ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid);
996 ath10k_print_driver_info(ar);
997 ath10k_pci_dump_registers(ar, crash_data);
999 spin_unlock_bh(&ar->data_lock);
1001 queue_work(ar->workqueue, &ar->restart_work);
1004 static void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
1007 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n");
1012 * Decide whether to actually poll for completions, or just
1013 * wait for a later chance.
1014 * If there seem to be plenty of resources left, then just wait
1015 * since checking involves reading a CE register, which is a
1016 * relatively expensive operation.
1018 resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
1021 * If at least 50% of the total resources are still available,
1022 * don't bother checking again yet.
1024 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
1027 ath10k_ce_per_engine_service(ar, pipe);
1030 static void ath10k_pci_hif_set_callbacks(struct ath10k *ar,
1031 struct ath10k_hif_cb *callbacks)
1033 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1035 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif set callbacks\n");
1037 memcpy(&ar_pci->msg_callbacks_current, callbacks,
1038 sizeof(ar_pci->msg_callbacks_current));
1041 static void ath10k_pci_kill_tasklet(struct ath10k *ar)
1043 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1046 tasklet_kill(&ar_pci->intr_tq);
1047 tasklet_kill(&ar_pci->msi_fw_err);
1049 for (i = 0; i < CE_COUNT; i++)
1050 tasklet_kill(&ar_pci->pipe_info[i].intr);
1052 del_timer_sync(&ar_pci->rx_post_retry);
1055 static int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar,
1056 u16 service_id, u8 *ul_pipe,
1057 u8 *dl_pipe, int *ul_is_polled,
1060 const struct service_to_pipe *entry;
1061 bool ul_set = false, dl_set = false;
1064 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n");
1066 /* polling for received messages not supported */
1069 for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) {
1070 entry = &target_service_to_ce_map_wlan[i];
1072 if (__le32_to_cpu(entry->service_id) != service_id)
1075 switch (__le32_to_cpu(entry->pipedir)) {
1080 *dl_pipe = __le32_to_cpu(entry->pipenum);
1085 *ul_pipe = __le32_to_cpu(entry->pipenum);
1091 *dl_pipe = __le32_to_cpu(entry->pipenum);
1092 *ul_pipe = __le32_to_cpu(entry->pipenum);
1099 if (WARN_ON(!ul_set || !dl_set))
1103 (host_ce_config_wlan[*ul_pipe].flags & CE_ATTR_DIS_INTR) != 0;
1108 static void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1109 u8 *ul_pipe, u8 *dl_pipe)
1111 int ul_is_polled, dl_is_polled;
1113 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n");
1115 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1116 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1123 static void ath10k_pci_irq_disable(struct ath10k *ar)
1125 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1128 ath10k_ce_disable_interrupts(ar);
1129 ath10k_pci_disable_and_clear_legacy_irq(ar);
1130 /* FIXME: How to mask all MSI interrupts? */
1132 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
1133 synchronize_irq(ar_pci->pdev->irq + i);
1136 static void ath10k_pci_irq_enable(struct ath10k *ar)
1138 ath10k_ce_enable_interrupts(ar);
1139 ath10k_pci_enable_legacy_irq(ar);
1140 /* FIXME: How to unmask all MSI interrupts? */
1143 static int ath10k_pci_hif_start(struct ath10k *ar)
1145 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n");
1147 ath10k_pci_irq_enable(ar);
1148 ath10k_pci_rx_post(ar);
1153 static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info)
1156 struct ath10k_pci *ar_pci;
1157 struct ath10k_ce_pipe *ce_hdl;
1159 struct sk_buff *netbuf;
1162 buf_sz = pipe_info->buf_sz;
1164 /* Unused Copy Engine */
1168 ar = pipe_info->hif_ce_state;
1169 ar_pci = ath10k_pci_priv(ar);
1170 ce_hdl = pipe_info->ce_hdl;
1172 while (ath10k_ce_revoke_recv_next(ce_hdl, (void **)&netbuf,
1174 dma_unmap_single(ar->dev, ATH10K_SKB_CB(netbuf)->paddr,
1175 netbuf->len + skb_tailroom(netbuf),
1177 dev_kfree_skb_any(netbuf);
1181 static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info)
1184 struct ath10k_pci *ar_pci;
1185 struct ath10k_ce_pipe *ce_hdl;
1186 struct sk_buff *netbuf;
1188 unsigned int nbytes;
1192 buf_sz = pipe_info->buf_sz;
1194 /* Unused Copy Engine */
1198 ar = pipe_info->hif_ce_state;
1199 ar_pci = ath10k_pci_priv(ar);
1200 ce_hdl = pipe_info->ce_hdl;
1202 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf,
1203 &ce_data, &nbytes, &id) == 0) {
1204 /* no need to call tx completion for NULL pointers */
1208 ar_pci->msg_callbacks_current.tx_completion(ar,
1215 * Cleanup residual buffers for device shutdown:
1216 * buffers that were enqueued for receive
1217 * buffers that were to be sent
1218 * Note: Buffers that had completed but which were
1219 * not yet processed are on a completion queue. They
1220 * are handled when the completion thread shuts down.
1222 static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1224 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1227 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1228 struct ath10k_pci_pipe *pipe_info;
1230 pipe_info = &ar_pci->pipe_info[pipe_num];
1231 ath10k_pci_rx_pipe_cleanup(pipe_info);
1232 ath10k_pci_tx_pipe_cleanup(pipe_info);
1236 static void ath10k_pci_ce_deinit(struct ath10k *ar)
1240 for (i = 0; i < CE_COUNT; i++)
1241 ath10k_ce_deinit_pipe(ar, i);
1244 static void ath10k_pci_flush(struct ath10k *ar)
1246 ath10k_pci_kill_tasklet(ar);
1247 ath10k_pci_buffer_cleanup(ar);
1250 static void ath10k_pci_hif_stop(struct ath10k *ar)
1252 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n");
1254 /* Most likely the device has HTT Rx ring configured. The only way to
1255 * prevent the device from accessing (and possible corrupting) host
1256 * memory is to reset the chip now.
1258 * There's also no known way of masking MSI interrupts on the device.
1259 * For ranged MSI the CE-related interrupts can be masked. However
1260 * regardless how many MSI interrupts are assigned the first one
1261 * is always used for firmware indications (crashes) and cannot be
1262 * masked. To prevent the device from asserting the interrupt reset it
1263 * before proceeding with cleanup.
1265 ath10k_pci_warm_reset(ar);
1267 ath10k_pci_irq_disable(ar);
1268 ath10k_pci_flush(ar);
1271 static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1272 void *req, u32 req_len,
1273 void *resp, u32 *resp_len)
1275 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1276 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1277 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1278 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1279 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
1280 dma_addr_t req_paddr = 0;
1281 dma_addr_t resp_paddr = 0;
1282 struct bmi_xfer xfer = {};
1283 void *treq, *tresp = NULL;
1288 if (resp && !resp_len)
1291 if (resp && resp_len && *resp_len == 0)
1294 treq = kmemdup(req, req_len, GFP_KERNEL);
1298 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1299 ret = dma_mapping_error(ar->dev, req_paddr);
1303 if (resp && resp_len) {
1304 tresp = kzalloc(*resp_len, GFP_KERNEL);
1310 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1312 ret = dma_mapping_error(ar->dev, resp_paddr);
1316 xfer.wait_for_resp = true;
1319 ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr);
1322 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1326 ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
1329 unsigned int unused_nbytes;
1330 unsigned int unused_id;
1332 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1333 &unused_nbytes, &unused_id);
1335 /* non-zero means we did not time out */
1343 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1344 dma_unmap_single(ar->dev, resp_paddr,
1345 *resp_len, DMA_FROM_DEVICE);
1348 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1350 if (ret == 0 && resp_len) {
1351 *resp_len = min(*resp_len, xfer.resp_len);
1352 memcpy(resp, tresp, xfer.resp_len);
1361 static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
1363 struct bmi_xfer *xfer;
1365 unsigned int nbytes;
1366 unsigned int transfer_id;
1368 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer, &ce_data,
1369 &nbytes, &transfer_id))
1372 xfer->tx_done = true;
1375 static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
1377 struct ath10k *ar = ce_state->ar;
1378 struct bmi_xfer *xfer;
1380 unsigned int nbytes;
1381 unsigned int transfer_id;
1384 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer, &ce_data,
1385 &nbytes, &transfer_id, &flags))
1388 if (!xfer->wait_for_resp) {
1389 ath10k_warn(ar, "unexpected: BMI data received; ignoring\n");
1393 xfer->resp_len = nbytes;
1394 xfer->rx_done = true;
1397 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
1398 struct ath10k_ce_pipe *rx_pipe,
1399 struct bmi_xfer *xfer)
1401 unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
1403 while (time_before_eq(jiffies, timeout)) {
1404 ath10k_pci_bmi_send_done(tx_pipe);
1405 ath10k_pci_bmi_recv_data(rx_pipe);
1407 if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp))
1417 * Send an interrupt to the device to wake up the Target CPU
1418 * so it has an opportunity to notice any changed state.
1420 static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1424 addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS;
1425 val = ath10k_pci_read32(ar, addr);
1426 val |= CORE_CTRL_CPU_INTR_MASK;
1427 ath10k_pci_write32(ar, addr, val);
1432 static int ath10k_pci_init_config(struct ath10k *ar)
1434 u32 interconnect_targ_addr;
1435 u32 pcie_state_targ_addr = 0;
1436 u32 pipe_cfg_targ_addr = 0;
1437 u32 svc_to_pipe_map = 0;
1438 u32 pcie_config_flags = 0;
1440 u32 ealloc_targ_addr;
1442 u32 flag2_targ_addr;
1445 /* Download to Target the CE Config and the service-to-CE map */
1446 interconnect_targ_addr =
1447 host_interest_item_address(HI_ITEM(hi_interconnect_state));
1449 /* Supply Target-side CE configuration */
1450 ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr,
1451 &pcie_state_targ_addr);
1453 ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret);
1457 if (pcie_state_targ_addr == 0) {
1459 ath10k_err(ar, "Invalid pcie state addr\n");
1463 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
1464 offsetof(struct pcie_state,
1466 &pipe_cfg_targ_addr);
1468 ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret);
1472 if (pipe_cfg_targ_addr == 0) {
1474 ath10k_err(ar, "Invalid pipe cfg addr\n");
1478 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
1479 target_ce_config_wlan,
1480 sizeof(target_ce_config_wlan));
1483 ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret);
1487 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
1488 offsetof(struct pcie_state,
1492 ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret);
1496 if (svc_to_pipe_map == 0) {
1498 ath10k_err(ar, "Invalid svc_to_pipe map\n");
1502 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
1503 target_service_to_ce_map_wlan,
1504 sizeof(target_service_to_ce_map_wlan));
1506 ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret);
1510 ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr +
1511 offsetof(struct pcie_state,
1513 &pcie_config_flags);
1515 ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret);
1519 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
1521 ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr +
1522 offsetof(struct pcie_state,
1526 ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret);
1530 /* configure early allocation */
1531 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
1533 ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value);
1535 ath10k_err(ar, "Faile to get early alloc val: %d\n", ret);
1539 /* first bank is switched to IRAM */
1540 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
1541 HI_EARLY_ALLOC_MAGIC_MASK);
1542 ealloc_value |= ((1 << HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
1543 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
1545 ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value);
1547 ath10k_err(ar, "Failed to set early alloc val: %d\n", ret);
1551 /* Tell Target to proceed with initialization */
1552 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
1554 ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value);
1556 ath10k_err(ar, "Failed to get option val: %d\n", ret);
1560 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
1562 ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value);
1564 ath10k_err(ar, "Failed to set option val: %d\n", ret);
1571 static int ath10k_pci_alloc_ce(struct ath10k *ar)
1575 for (i = 0; i < CE_COUNT; i++) {
1576 ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]);
1578 ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n",
1587 static void ath10k_pci_free_ce(struct ath10k *ar)
1591 for (i = 0; i < CE_COUNT; i++)
1592 ath10k_ce_free_pipe(ar, i);
1595 static int ath10k_pci_ce_init(struct ath10k *ar)
1597 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1598 struct ath10k_pci_pipe *pipe_info;
1599 const struct ce_attr *attr;
1602 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1603 pipe_info = &ar_pci->pipe_info[pipe_num];
1604 pipe_info->ce_hdl = &ar_pci->ce_states[pipe_num];
1605 pipe_info->pipe_num = pipe_num;
1606 pipe_info->hif_ce_state = ar;
1607 attr = &host_ce_config_wlan[pipe_num];
1609 ret = ath10k_ce_init_pipe(ar, pipe_num, attr,
1610 ath10k_pci_ce_send_done,
1611 ath10k_pci_ce_recv_data);
1613 ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n",
1618 if (pipe_num == CE_COUNT - 1) {
1620 * Reserve the ultimate CE for
1621 * diagnostic Window support
1623 ar_pci->ce_diag = pipe_info->ce_hdl;
1627 pipe_info->buf_sz = (size_t)(attr->src_sz_max);
1633 static bool ath10k_pci_has_fw_crashed(struct ath10k *ar)
1635 return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) &
1636 FW_IND_EVENT_PENDING;
1639 static void ath10k_pci_fw_crashed_clear(struct ath10k *ar)
1643 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
1644 val &= ~FW_IND_EVENT_PENDING;
1645 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val);
1648 /* this function effectively clears target memory controller assert line */
1649 static void ath10k_pci_warm_reset_si0(struct ath10k *ar)
1653 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1654 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
1655 val | SOC_RESET_CONTROL_SI0_RST_MASK);
1656 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1660 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1661 ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS,
1662 val & ~SOC_RESET_CONTROL_SI0_RST_MASK);
1663 val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS);
1668 static int ath10k_pci_warm_reset(struct ath10k *ar)
1672 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n");
1675 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1676 PCIE_INTR_CAUSE_ADDRESS);
1677 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot host cpu intr cause: 0x%08x\n",
1680 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1682 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target cpu intr cause: 0x%08x\n",
1685 /* disable pending irqs */
1686 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1687 PCIE_INTR_ENABLE_ADDRESS, 0);
1689 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
1690 PCIE_INTR_CLR_ADDRESS, ~0);
1694 /* clear fw indicator */
1695 ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0);
1697 /* clear target LF timer interrupts */
1698 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1699 SOC_LF_TIMER_CONTROL0_ADDRESS);
1700 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS +
1701 SOC_LF_TIMER_CONTROL0_ADDRESS,
1702 val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK);
1705 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1706 SOC_RESET_CONTROL_ADDRESS);
1707 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1708 val | SOC_RESET_CONTROL_CE_RST_MASK);
1709 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1710 SOC_RESET_CONTROL_ADDRESS);
1714 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1715 val & ~SOC_RESET_CONTROL_CE_RST_MASK);
1716 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1717 SOC_RESET_CONTROL_ADDRESS);
1720 ath10k_pci_warm_reset_si0(ar);
1723 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1724 PCIE_INTR_CAUSE_ADDRESS);
1725 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot host cpu intr cause: 0x%08x\n",
1728 val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS +
1730 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target cpu intr cause: 0x%08x\n",
1733 /* CPU warm reset */
1734 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1735 SOC_RESET_CONTROL_ADDRESS);
1736 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS,
1737 val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK);
1739 val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS +
1740 SOC_RESET_CONTROL_ADDRESS);
1741 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target reset state: 0x%08x\n",
1746 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n");
1751 static int __ath10k_pci_hif_power_up(struct ath10k *ar, bool cold_reset)
1756 * Bring the target up cleanly.
1758 * The target may be in an undefined state with an AUX-powered Target
1759 * and a Host in WoW mode. If the Host crashes, loses power, or is
1760 * restarted (without unloading the driver) then the Target is left
1761 * (aux) powered and running. On a subsequent driver load, the Target
1762 * is in an unexpected state. We try to catch that here in order to
1763 * reset the Target and retry the probe.
1766 ret = ath10k_pci_cold_reset(ar);
1768 ret = ath10k_pci_warm_reset(ar);
1771 ath10k_err(ar, "failed to reset target: %d\n", ret);
1775 ret = ath10k_pci_ce_init(ar);
1777 ath10k_err(ar, "failed to initialize CE: %d\n", ret);
1781 ret = ath10k_pci_wait_for_target_init(ar);
1783 ath10k_err(ar, "failed to wait for target to init: %d\n", ret);
1787 ret = ath10k_pci_init_config(ar);
1789 ath10k_err(ar, "failed to setup init config: %d\n", ret);
1793 ret = ath10k_pci_wake_target_cpu(ar);
1795 ath10k_err(ar, "could not wake up target CPU: %d\n", ret);
1802 ath10k_pci_ce_deinit(ar);
1803 ath10k_pci_warm_reset(ar);
1808 static int ath10k_pci_hif_power_up_warm(struct ath10k *ar)
1813 * Sometime warm reset succeeds after retries.
1815 * FIXME: It might be possible to tune ath10k_pci_warm_reset() to work
1818 for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) {
1819 ret = __ath10k_pci_hif_power_up(ar, false);
1823 ath10k_warn(ar, "failed to warm reset (attempt %d out of %d): %d\n",
1824 i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS, ret);
1830 static int ath10k_pci_hif_power_up(struct ath10k *ar)
1834 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n");
1837 * Hardware CUS232 version 2 has some issues with cold reset and the
1838 * preferred (and safer) way to perform a device reset is through a
1841 * Warm reset doesn't always work though so fall back to cold reset may
1844 ret = ath10k_pci_hif_power_up_warm(ar);
1846 ath10k_warn(ar, "failed to power up target using warm reset: %d\n",
1849 if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY)
1852 ath10k_warn(ar, "trying cold reset\n");
1854 ret = __ath10k_pci_hif_power_up(ar, true);
1856 ath10k_err(ar, "failed to power up target using cold reset too (%d)\n",
1865 static void ath10k_pci_hif_power_down(struct ath10k *ar)
1867 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n");
1869 ath10k_pci_warm_reset(ar);
1874 #define ATH10K_PCI_PM_CONTROL 0x44
1876 static int ath10k_pci_hif_suspend(struct ath10k *ar)
1878 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1879 struct pci_dev *pdev = ar_pci->pdev;
1882 pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val);
1884 if ((val & 0x000000ff) != 0x3) {
1885 pci_save_state(pdev);
1886 pci_disable_device(pdev);
1887 pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
1888 (val & 0xffffff00) | 0x03);
1894 static int ath10k_pci_hif_resume(struct ath10k *ar)
1896 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1897 struct pci_dev *pdev = ar_pci->pdev;
1900 pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val);
1902 if ((val & 0x000000ff) != 0) {
1903 pci_restore_state(pdev);
1904 pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
1907 * Suspend/Resume resets the PCI configuration space,
1908 * so we have to re-disable the RETRY_TIMEOUT register (0x41)
1909 * to keep PCI Tx retries from interfering with C3 CPU state
1911 pci_read_config_dword(pdev, 0x40, &val);
1913 if ((val & 0x0000ff00) != 0)
1914 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1921 static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
1922 .tx_sg = ath10k_pci_hif_tx_sg,
1923 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
1924 .start = ath10k_pci_hif_start,
1925 .stop = ath10k_pci_hif_stop,
1926 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
1927 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
1928 .send_complete_check = ath10k_pci_hif_send_complete_check,
1929 .set_callbacks = ath10k_pci_hif_set_callbacks,
1930 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
1931 .power_up = ath10k_pci_hif_power_up,
1932 .power_down = ath10k_pci_hif_power_down,
1934 .suspend = ath10k_pci_hif_suspend,
1935 .resume = ath10k_pci_hif_resume,
1939 static void ath10k_pci_ce_tasklet(unsigned long ptr)
1941 struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr;
1942 struct ath10k_pci *ar_pci = pipe->ar_pci;
1944 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
1947 static void ath10k_msi_err_tasklet(unsigned long data)
1949 struct ath10k *ar = (struct ath10k *)data;
1951 if (!ath10k_pci_has_fw_crashed(ar)) {
1952 ath10k_warn(ar, "received unsolicited fw crash interrupt\n");
1956 ath10k_pci_fw_crashed_clear(ar);
1957 ath10k_pci_fw_crashed_dump(ar);
1961 * Handler for a per-engine interrupt on a PARTICULAR CE.
1962 * This is used in cases where each CE has a private MSI interrupt.
1964 static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg)
1966 struct ath10k *ar = arg;
1967 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1968 int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL;
1970 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) {
1971 ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq,
1977 * NOTE: We are able to derive ce_id from irq because we
1978 * use a one-to-one mapping for CE's 0..5.
1979 * CE's 6 & 7 do not use interrupts at all.
1981 * This mapping must be kept in sync with the mapping
1984 tasklet_schedule(&ar_pci->pipe_info[ce_id].intr);
1988 static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg)
1990 struct ath10k *ar = arg;
1991 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1993 tasklet_schedule(&ar_pci->msi_fw_err);
1998 * Top-level interrupt handler for all PCI interrupts from a Target.
1999 * When a block of MSI interrupts is allocated, this top-level handler
2000 * is not used; instead, we directly call the correct sub-handler.
2002 static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
2004 struct ath10k *ar = arg;
2005 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2007 if (ar_pci->num_msi_intrs == 0) {
2008 if (!ath10k_pci_irq_pending(ar))
2011 ath10k_pci_disable_and_clear_legacy_irq(ar);
2014 tasklet_schedule(&ar_pci->intr_tq);
2019 static void ath10k_pci_tasklet(unsigned long data)
2021 struct ath10k *ar = (struct ath10k *)data;
2022 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2024 if (ath10k_pci_has_fw_crashed(ar)) {
2025 ath10k_pci_fw_crashed_clear(ar);
2026 ath10k_pci_fw_crashed_dump(ar);
2030 ath10k_ce_per_engine_service_any(ar);
2032 /* Re-enable legacy irq that was disabled in the irq handler */
2033 if (ar_pci->num_msi_intrs == 0)
2034 ath10k_pci_enable_legacy_irq(ar);
2037 static int ath10k_pci_request_irq_msix(struct ath10k *ar)
2039 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2042 ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW,
2043 ath10k_pci_msi_fw_handler,
2044 IRQF_SHARED, "ath10k_pci", ar);
2046 ath10k_warn(ar, "failed to request MSI-X fw irq %d: %d\n",
2047 ar_pci->pdev->irq + MSI_ASSIGN_FW, ret);
2051 for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) {
2052 ret = request_irq(ar_pci->pdev->irq + i,
2053 ath10k_pci_per_engine_handler,
2054 IRQF_SHARED, "ath10k_pci", ar);
2056 ath10k_warn(ar, "failed to request MSI-X ce irq %d: %d\n",
2057 ar_pci->pdev->irq + i, ret);
2059 for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--)
2060 free_irq(ar_pci->pdev->irq + i, ar);
2062 free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar);
2070 static int ath10k_pci_request_irq_msi(struct ath10k *ar)
2072 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2075 ret = request_irq(ar_pci->pdev->irq,
2076 ath10k_pci_interrupt_handler,
2077 IRQF_SHARED, "ath10k_pci", ar);
2079 ath10k_warn(ar, "failed to request MSI irq %d: %d\n",
2080 ar_pci->pdev->irq, ret);
2087 static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
2089 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2092 ret = request_irq(ar_pci->pdev->irq,
2093 ath10k_pci_interrupt_handler,
2094 IRQF_SHARED, "ath10k_pci", ar);
2096 ath10k_warn(ar, "failed to request legacy irq %d: %d\n",
2097 ar_pci->pdev->irq, ret);
2104 static int ath10k_pci_request_irq(struct ath10k *ar)
2106 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2108 switch (ar_pci->num_msi_intrs) {
2110 return ath10k_pci_request_irq_legacy(ar);
2112 return ath10k_pci_request_irq_msi(ar);
2113 case MSI_NUM_REQUEST:
2114 return ath10k_pci_request_irq_msix(ar);
2117 ath10k_warn(ar, "unknown irq configuration upon request\n");
2121 static void ath10k_pci_free_irq(struct ath10k *ar)
2123 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2126 /* There's at least one interrupt irregardless whether its legacy INTR
2127 * or MSI or MSI-X */
2128 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
2129 free_irq(ar_pci->pdev->irq + i, ar);
2132 static void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
2134 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2137 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
2138 tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet,
2141 for (i = 0; i < CE_COUNT; i++) {
2142 ar_pci->pipe_info[i].ar_pci = ar_pci;
2143 tasklet_init(&ar_pci->pipe_info[i].intr, ath10k_pci_ce_tasklet,
2144 (unsigned long)&ar_pci->pipe_info[i]);
2148 static int ath10k_pci_init_irq(struct ath10k *ar)
2150 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2153 ath10k_pci_init_irq_tasklets(ar);
2155 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO)
2156 ath10k_info(ar, "limiting irq mode to: %d\n",
2157 ath10k_pci_irq_mode);
2160 if (ath10k_pci_irq_mode == ATH10K_PCI_IRQ_AUTO) {
2161 ar_pci->num_msi_intrs = MSI_NUM_REQUEST;
2162 ret = pci_enable_msi_range(ar_pci->pdev, ar_pci->num_msi_intrs,
2163 ar_pci->num_msi_intrs);
2171 if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) {
2172 ar_pci->num_msi_intrs = 1;
2173 ret = pci_enable_msi(ar_pci->pdev);
2182 * A potential race occurs here: The CORE_BASE write
2183 * depends on target correctly decoding AXI address but
2184 * host won't know when target writes BAR to CORE_CTRL.
2185 * This write might get lost if target has NOT written BAR.
2186 * For now, fix the race by repeating the write in below
2187 * synchronization checking. */
2188 ar_pci->num_msi_intrs = 0;
2190 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2191 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
2196 static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
2198 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2202 static int ath10k_pci_deinit_irq(struct ath10k *ar)
2204 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2206 switch (ar_pci->num_msi_intrs) {
2208 ath10k_pci_deinit_irq_legacy(ar);
2212 case MSI_NUM_REQUEST:
2213 pci_disable_msi(ar_pci->pdev);
2216 pci_disable_msi(ar_pci->pdev);
2219 ath10k_warn(ar, "unknown irq configuration upon deinit\n");
2223 static int ath10k_pci_wait_for_target_init(struct ath10k *ar)
2225 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2226 unsigned long timeout;
2229 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n");
2231 timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT);
2234 val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS);
2236 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n",
2239 /* target should never return this */
2240 if (val == 0xffffffff)
2243 /* the device has crashed so don't bother trying anymore */
2244 if (val & FW_IND_EVENT_PENDING)
2247 if (val & FW_IND_INITIALIZED)
2250 if (ar_pci->num_msi_intrs == 0)
2251 /* Fix potential race by repeating CORE_BASE writes */
2252 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS +
2253 PCIE_INTR_ENABLE_ADDRESS,
2254 PCIE_INTR_FIRMWARE_MASK |
2255 PCIE_INTR_CE_MASK_ALL);
2258 } while (time_before(jiffies, timeout));
2260 if (val == 0xffffffff) {
2261 ath10k_err(ar, "failed to read device register, device is gone\n");
2265 if (val & FW_IND_EVENT_PENDING) {
2266 ath10k_warn(ar, "device has crashed during init\n");
2267 ath10k_pci_fw_crashed_clear(ar);
2268 ath10k_pci_fw_crashed_dump(ar);
2272 if (!(val & FW_IND_INITIALIZED)) {
2273 ath10k_err(ar, "failed to receive initialized event from target: %08x\n",
2278 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n");
2282 static int ath10k_pci_cold_reset(struct ath10k *ar)
2287 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n");
2289 /* Put Target, including PCIe, into RESET. */
2290 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
2292 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2294 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2295 if (ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) &
2296 RTC_STATE_COLD_RESET_MASK)
2301 /* Pull Target, including PCIe, out of RESET. */
2303 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2305 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2306 if (!(ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) &
2307 RTC_STATE_COLD_RESET_MASK))
2312 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n");
2317 static int ath10k_pci_claim(struct ath10k *ar)
2319 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2320 struct pci_dev *pdev = ar_pci->pdev;
2324 pci_set_drvdata(pdev, ar);
2326 ret = pci_enable_device(pdev);
2328 ath10k_err(ar, "failed to enable pci device: %d\n", ret);
2332 ret = pci_request_region(pdev, BAR_NUM, "ath");
2334 ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM,
2339 /* Target expects 32 bit DMA. Enforce it. */
2340 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2342 ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret);
2346 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2348 ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n",
2353 pci_set_master(pdev);
2355 /* Workaround: Disable ASPM */
2356 pci_read_config_dword(pdev, 0x80, &lcr_val);
2357 pci_write_config_dword(pdev, 0x80, (lcr_val & 0xffffff00));
2359 /* Arrange for access to Target SoC registers. */
2360 ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0);
2362 ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM);
2367 ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
2371 pci_clear_master(pdev);
2374 pci_release_region(pdev, BAR_NUM);
2377 pci_disable_device(pdev);
2382 static void ath10k_pci_release(struct ath10k *ar)
2384 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2385 struct pci_dev *pdev = ar_pci->pdev;
2387 pci_iounmap(pdev, ar_pci->mem);
2388 pci_release_region(pdev, BAR_NUM);
2389 pci_clear_master(pdev);
2390 pci_disable_device(pdev);
2393 static int ath10k_pci_probe(struct pci_dev *pdev,
2394 const struct pci_device_id *pci_dev)
2398 struct ath10k_pci *ar_pci;
2401 ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev,
2402 &ath10k_pci_hif_ops);
2404 dev_err(&pdev->dev, "failed to allocate core\n");
2408 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci probe\n");
2410 ar_pci = ath10k_pci_priv(ar);
2411 ar_pci->pdev = pdev;
2412 ar_pci->dev = &pdev->dev;
2415 spin_lock_init(&ar_pci->ce_lock);
2416 setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry,
2419 ret = ath10k_pci_claim(ar);
2421 ath10k_err(ar, "failed to claim device: %d\n", ret);
2422 goto err_core_destroy;
2425 ret = ath10k_pci_wake(ar);
2427 ath10k_err(ar, "failed to wake up: %d\n", ret);
2431 chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
2432 if (chip_id == 0xffffffff) {
2433 ath10k_err(ar, "failed to get chip id\n");
2437 ret = ath10k_pci_alloc_ce(ar);
2439 ath10k_err(ar, "failed to allocate copy engine pipes: %d\n",
2444 ath10k_pci_ce_deinit(ar);
2446 ret = ath10k_ce_disable_interrupts(ar);
2448 ath10k_err(ar, "failed to disable copy engine interrupts: %d\n",
2453 /* Workaround: There's no known way to mask all possible interrupts via
2454 * device CSR. The only way to make sure device doesn't assert
2455 * interrupts is to reset it. Interrupts are then disabled on host
2456 * after handlers are registered.
2458 ath10k_pci_warm_reset(ar);
2460 ret = ath10k_pci_init_irq(ar);
2462 ath10k_err(ar, "failed to init irqs: %d\n", ret);
2466 ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n",
2467 ath10k_pci_get_irq_method(ar), ar_pci->num_msi_intrs,
2468 ath10k_pci_irq_mode, ath10k_pci_reset_mode);
2470 ret = ath10k_pci_request_irq(ar);
2472 ath10k_warn(ar, "failed to request irqs: %d\n", ret);
2473 goto err_deinit_irq;
2476 /* This shouldn't race as the device has been reset above. */
2477 ath10k_pci_irq_disable(ar);
2479 ret = ath10k_core_register(ar, chip_id);
2481 ath10k_err(ar, "failed to register driver core: %d\n", ret);
2488 ath10k_pci_free_irq(ar);
2489 ath10k_pci_kill_tasklet(ar);
2492 ath10k_pci_deinit_irq(ar);
2495 ath10k_pci_free_ce(ar);
2498 ath10k_pci_sleep(ar);
2501 ath10k_pci_release(ar);
2504 ath10k_core_destroy(ar);
2509 static void ath10k_pci_remove(struct pci_dev *pdev)
2511 struct ath10k *ar = pci_get_drvdata(pdev);
2512 struct ath10k_pci *ar_pci;
2514 ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n");
2519 ar_pci = ath10k_pci_priv(ar);
2524 ath10k_core_unregister(ar);
2525 ath10k_pci_free_irq(ar);
2526 ath10k_pci_kill_tasklet(ar);
2527 ath10k_pci_deinit_irq(ar);
2528 ath10k_pci_ce_deinit(ar);
2529 ath10k_pci_free_ce(ar);
2530 ath10k_pci_sleep(ar);
2531 ath10k_pci_release(ar);
2532 ath10k_core_destroy(ar);
2535 MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
2537 static struct pci_driver ath10k_pci_driver = {
2538 .name = "ath10k_pci",
2539 .id_table = ath10k_pci_id_table,
2540 .probe = ath10k_pci_probe,
2541 .remove = ath10k_pci_remove,
2544 static int __init ath10k_pci_init(void)
2548 ret = pci_register_driver(&ath10k_pci_driver);
2550 printk(KERN_ERR "failed to register ath10k pci driver: %d\n",
2555 module_init(ath10k_pci_init);
2557 static void __exit ath10k_pci_exit(void)
2559 pci_unregister_driver(&ath10k_pci_driver);
2562 module_exit(ath10k_pci_exit);
2564 MODULE_AUTHOR("Qualcomm Atheros");
2565 MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
2566 MODULE_LICENSE("Dual BSD/GPL");
2567 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_3_FILE);
2568 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);