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 static unsigned int ath10k_target_ps
;
37 module_param(ath10k_target_ps
, uint
, 0644);
38 MODULE_PARM_DESC(ath10k_target_ps
, "Enable ath10k Target (SoC) PS option");
40 #define QCA988X_2_0_DEVICE_ID (0x003c)
42 static DEFINE_PCI_DEVICE_TABLE(ath10k_pci_id_table
) = {
43 { PCI_VDEVICE(ATHEROS
, QCA988X_2_0_DEVICE_ID
) }, /* PCI-E QCA988X V2 */
47 static int ath10k_pci_diag_read_access(struct ath10k
*ar
, u32 address
,
50 static void ath10k_pci_process_ce(struct ath10k
*ar
);
51 static int ath10k_pci_post_rx(struct ath10k
*ar
);
52 static int ath10k_pci_post_rx_pipe(struct ath10k_pci_pipe
*pipe_info
,
54 static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe
*pipe_info
);
55 static void ath10k_pci_stop_ce(struct ath10k
*ar
);
56 static int ath10k_pci_device_reset(struct ath10k
*ar
);
57 static int ath10k_pci_wait_for_target_init(struct ath10k
*ar
);
58 static int ath10k_pci_init_irq(struct ath10k
*ar
);
59 static int ath10k_pci_deinit_irq(struct ath10k
*ar
);
60 static int ath10k_pci_request_irq(struct ath10k
*ar
);
61 static void ath10k_pci_free_irq(struct ath10k
*ar
);
62 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe
*tx_pipe
,
63 struct ath10k_ce_pipe
*rx_pipe
,
64 struct bmi_xfer
*xfer
);
65 static void ath10k_pci_cleanup_ce(struct ath10k
*ar
);
67 static const struct ce_attr host_ce_config_wlan
[] = {
68 /* CE0: host->target HTC control and raw streams */
70 .flags
= CE_ATTR_FLAGS
,
76 /* CE1: target->host HTT + HTC control */
78 .flags
= CE_ATTR_FLAGS
,
84 /* CE2: target->host WMI */
86 .flags
= CE_ATTR_FLAGS
,
92 /* CE3: host->target WMI */
94 .flags
= CE_ATTR_FLAGS
,
100 /* CE4: host->target HTT */
102 .flags
= CE_ATTR_FLAGS
| CE_ATTR_DIS_INTR
,
103 .src_nentries
= CE_HTT_H2T_MSG_SRC_NENTRIES
,
110 .flags
= CE_ATTR_FLAGS
,
116 /* CE6: target autonomous hif_memcpy */
118 .flags
= CE_ATTR_FLAGS
,
124 /* CE7: ce_diag, the Diagnostic Window */
126 .flags
= CE_ATTR_FLAGS
,
128 .src_sz_max
= DIAG_TRANSFER_LIMIT
,
133 /* Target firmware's Copy Engine configuration. */
134 static const struct ce_pipe_config target_ce_config_wlan
[] = {
135 /* CE0: host->target HTC control and raw streams */
138 .pipedir
= PIPEDIR_OUT
,
141 .flags
= CE_ATTR_FLAGS
,
145 /* CE1: target->host HTT + HTC control */
148 .pipedir
= PIPEDIR_IN
,
151 .flags
= CE_ATTR_FLAGS
,
155 /* CE2: target->host WMI */
158 .pipedir
= PIPEDIR_IN
,
161 .flags
= CE_ATTR_FLAGS
,
165 /* CE3: host->target WMI */
168 .pipedir
= PIPEDIR_OUT
,
171 .flags
= CE_ATTR_FLAGS
,
175 /* CE4: host->target HTT */
178 .pipedir
= PIPEDIR_OUT
,
181 .flags
= CE_ATTR_FLAGS
,
185 /* NB: 50% of src nentries, since tx has 2 frags */
190 .pipedir
= PIPEDIR_OUT
,
193 .flags
= CE_ATTR_FLAGS
,
197 /* CE6: Reserved for target autonomous hif_memcpy */
200 .pipedir
= PIPEDIR_INOUT
,
203 .flags
= CE_ATTR_FLAGS
,
207 /* CE7 used only by Host */
210 static bool ath10k_pci_irq_pending(struct ath10k
*ar
)
214 /* Check if the shared legacy irq is for us */
215 cause
= ath10k_pci_read32(ar
, SOC_CORE_BASE_ADDRESS
+
216 PCIE_INTR_CAUSE_ADDRESS
);
217 if (cause
& (PCIE_INTR_FIRMWARE_MASK
| PCIE_INTR_CE_MASK_ALL
))
224 * Diagnostic read/write access is provided for startup/config/debug usage.
225 * Caller must guarantee proper alignment, when applicable, and single user
228 static int ath10k_pci_diag_read_mem(struct ath10k
*ar
, u32 address
, void *data
,
231 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
234 unsigned int completed_nbytes
, orig_nbytes
, remaining_bytes
;
237 struct ath10k_ce_pipe
*ce_diag
;
238 /* Host buffer address in CE space */
240 dma_addr_t ce_data_base
= 0;
241 void *data_buf
= NULL
;
245 * This code cannot handle reads to non-memory space. Redirect to the
246 * register read fn but preserve the multi word read capability of
249 if (address
< DRAM_BASE_ADDRESS
) {
250 if (!IS_ALIGNED(address
, 4) ||
251 !IS_ALIGNED((unsigned long)data
, 4))
254 while ((nbytes
>= 4) && ((ret
= ath10k_pci_diag_read_access(
255 ar
, address
, (u32
*)data
)) == 0)) {
256 nbytes
-= sizeof(u32
);
257 address
+= sizeof(u32
);
263 ce_diag
= ar_pci
->ce_diag
;
266 * Allocate a temporary bounce buffer to hold caller's data
267 * to be DMA'ed from Target. This guarantees
268 * 1) 4-byte alignment
269 * 2) Buffer in DMA-able space
271 orig_nbytes
= nbytes
;
272 data_buf
= (unsigned char *)pci_alloc_consistent(ar_pci
->pdev
,
280 memset(data_buf
, 0, orig_nbytes
);
282 remaining_bytes
= orig_nbytes
;
283 ce_data
= ce_data_base
;
284 while (remaining_bytes
) {
285 nbytes
= min_t(unsigned int, remaining_bytes
,
286 DIAG_TRANSFER_LIMIT
);
288 ret
= ath10k_ce_recv_buf_enqueue(ce_diag
, NULL
, ce_data
);
292 /* Request CE to send from Target(!) address to Host buffer */
294 * The address supplied by the caller is in the
295 * Target CPU virtual address space.
297 * In order to use this address with the diagnostic CE,
298 * convert it from Target CPU virtual address space
299 * to CE address space
302 address
= TARG_CPU_SPACE_TO_CE_SPACE(ar
, ar_pci
->mem
,
304 ath10k_pci_sleep(ar
);
306 ret
= ath10k_ce_send(ce_diag
, NULL
, (u32
)address
, nbytes
, 0,
312 while (ath10k_ce_completed_send_next(ce_diag
, NULL
, &buf
,
316 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
322 if (nbytes
!= completed_nbytes
) {
327 if (buf
!= (u32
) address
) {
333 while (ath10k_ce_completed_recv_next(ce_diag
, NULL
, &buf
,
338 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
344 if (nbytes
!= completed_nbytes
) {
349 if (buf
!= ce_data
) {
354 remaining_bytes
-= nbytes
;
361 /* Copy data from allocated DMA buf to caller's buf */
362 WARN_ON_ONCE(orig_nbytes
& 3);
363 for (i
= 0; i
< orig_nbytes
/ sizeof(__le32
); i
++) {
365 __le32_to_cpu(((__le32
*)data_buf
)[i
]);
368 ath10k_dbg(ATH10K_DBG_PCI
, "%s failure (0x%x)\n",
372 pci_free_consistent(ar_pci
->pdev
, orig_nbytes
,
373 data_buf
, ce_data_base
);
378 /* Read 4-byte aligned data from Target memory or register */
379 static int ath10k_pci_diag_read_access(struct ath10k
*ar
, u32 address
,
382 /* Assume range doesn't cross this boundary */
383 if (address
>= DRAM_BASE_ADDRESS
)
384 return ath10k_pci_diag_read_mem(ar
, address
, data
, sizeof(u32
));
387 *data
= ath10k_pci_read32(ar
, address
);
388 ath10k_pci_sleep(ar
);
392 static int ath10k_pci_diag_write_mem(struct ath10k
*ar
, u32 address
,
393 const void *data
, int nbytes
)
395 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
398 unsigned int completed_nbytes
, orig_nbytes
, remaining_bytes
;
401 struct ath10k_ce_pipe
*ce_diag
;
402 void *data_buf
= NULL
;
403 u32 ce_data
; /* Host buffer address in CE space */
404 dma_addr_t ce_data_base
= 0;
407 ce_diag
= ar_pci
->ce_diag
;
410 * Allocate a temporary bounce buffer to hold caller's data
411 * to be DMA'ed to Target. This guarantees
412 * 1) 4-byte alignment
413 * 2) Buffer in DMA-able space
415 orig_nbytes
= nbytes
;
416 data_buf
= (unsigned char *)pci_alloc_consistent(ar_pci
->pdev
,
424 /* Copy caller's data to allocated DMA buf */
425 WARN_ON_ONCE(orig_nbytes
& 3);
426 for (i
= 0; i
< orig_nbytes
/ sizeof(__le32
); i
++)
427 ((__le32
*)data_buf
)[i
] = __cpu_to_le32(((u32
*)data
)[i
]);
430 * The address supplied by the caller is in the
431 * Target CPU virtual address space.
433 * In order to use this address with the diagnostic CE,
435 * Target CPU virtual address space
440 address
= TARG_CPU_SPACE_TO_CE_SPACE(ar
, ar_pci
->mem
, address
);
441 ath10k_pci_sleep(ar
);
443 remaining_bytes
= orig_nbytes
;
444 ce_data
= ce_data_base
;
445 while (remaining_bytes
) {
446 /* FIXME: check cast */
447 nbytes
= min_t(int, remaining_bytes
, DIAG_TRANSFER_LIMIT
);
449 /* Set up to receive directly into Target(!) address */
450 ret
= ath10k_ce_recv_buf_enqueue(ce_diag
, NULL
, address
);
455 * Request CE to send caller-supplied data that
456 * was copied to bounce buffer to Target(!) address.
458 ret
= ath10k_ce_send(ce_diag
, NULL
, (u32
) ce_data
,
464 while (ath10k_ce_completed_send_next(ce_diag
, NULL
, &buf
,
469 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
475 if (nbytes
!= completed_nbytes
) {
480 if (buf
!= ce_data
) {
486 while (ath10k_ce_completed_recv_next(ce_diag
, NULL
, &buf
,
491 if (i
++ > DIAG_ACCESS_CE_TIMEOUT_MS
) {
497 if (nbytes
!= completed_nbytes
) {
502 if (buf
!= address
) {
507 remaining_bytes
-= nbytes
;
514 pci_free_consistent(ar_pci
->pdev
, orig_nbytes
, data_buf
,
519 ath10k_dbg(ATH10K_DBG_PCI
, "%s failure (0x%x)\n", __func__
,
525 /* Write 4B data to Target memory or register */
526 static int ath10k_pci_diag_write_access(struct ath10k
*ar
, u32 address
,
529 /* Assume range doesn't cross this boundary */
530 if (address
>= DRAM_BASE_ADDRESS
)
531 return ath10k_pci_diag_write_mem(ar
, address
, &data
,
535 ath10k_pci_write32(ar
, address
, data
);
536 ath10k_pci_sleep(ar
);
540 static bool ath10k_pci_target_is_awake(struct ath10k
*ar
)
542 void __iomem
*mem
= ath10k_pci_priv(ar
)->mem
;
544 val
= ioread32(mem
+ PCIE_LOCAL_BASE_ADDRESS
+
546 return (RTC_STATE_V_GET(val
) == RTC_STATE_V_ON
);
549 int ath10k_do_pci_wake(struct ath10k
*ar
)
551 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
552 void __iomem
*pci_addr
= ar_pci
->mem
;
556 if (atomic_read(&ar_pci
->keep_awake_count
) == 0) {
558 iowrite32(PCIE_SOC_WAKE_V_MASK
,
559 pci_addr
+ PCIE_LOCAL_BASE_ADDRESS
+
560 PCIE_SOC_WAKE_ADDRESS
);
562 atomic_inc(&ar_pci
->keep_awake_count
);
564 if (ar_pci
->verified_awake
)
568 if (ath10k_pci_target_is_awake(ar
)) {
569 ar_pci
->verified_awake
= true;
573 if (tot_delay
> PCIE_WAKE_TIMEOUT
) {
574 ath10k_warn("target took longer %d us to wake up (awake count %d)\n",
576 atomic_read(&ar_pci
->keep_awake_count
));
581 tot_delay
+= curr_delay
;
588 void ath10k_do_pci_sleep(struct ath10k
*ar
)
590 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
591 void __iomem
*pci_addr
= ar_pci
->mem
;
593 if (atomic_dec_and_test(&ar_pci
->keep_awake_count
)) {
595 ar_pci
->verified_awake
= false;
596 iowrite32(PCIE_SOC_WAKE_RESET
,
597 pci_addr
+ PCIE_LOCAL_BASE_ADDRESS
+
598 PCIE_SOC_WAKE_ADDRESS
);
603 * FIXME: Handle OOM properly.
606 struct ath10k_pci_compl
*get_free_compl(struct ath10k_pci_pipe
*pipe_info
)
608 struct ath10k_pci_compl
*compl = NULL
;
610 spin_lock_bh(&pipe_info
->pipe_lock
);
611 if (list_empty(&pipe_info
->compl_free
)) {
612 ath10k_warn("Completion buffers are full\n");
615 compl = list_first_entry(&pipe_info
->compl_free
,
616 struct ath10k_pci_compl
, list
);
617 list_del(&compl->list
);
619 spin_unlock_bh(&pipe_info
->pipe_lock
);
623 /* Called by lower (CE) layer when a send to Target completes. */
624 static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe
*ce_state
)
626 struct ath10k
*ar
= ce_state
->ar
;
627 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
628 struct ath10k_pci_pipe
*pipe_info
= &ar_pci
->pipe_info
[ce_state
->id
];
629 struct ath10k_pci_compl
*compl;
630 void *transfer_context
;
633 unsigned int transfer_id
;
635 while (ath10k_ce_completed_send_next(ce_state
, &transfer_context
,
637 &transfer_id
) == 0) {
638 compl = get_free_compl(pipe_info
);
642 compl->state
= ATH10K_PCI_COMPL_SEND
;
643 compl->ce_state
= ce_state
;
644 compl->pipe_info
= pipe_info
;
645 compl->skb
= transfer_context
;
646 compl->nbytes
= nbytes
;
647 compl->transfer_id
= transfer_id
;
651 * Add the completion to the processing queue.
653 spin_lock_bh(&ar_pci
->compl_lock
);
654 list_add_tail(&compl->list
, &ar_pci
->compl_process
);
655 spin_unlock_bh(&ar_pci
->compl_lock
);
658 ath10k_pci_process_ce(ar
);
661 /* Called by lower (CE) layer when data is received from the Target. */
662 static void ath10k_pci_ce_recv_data(struct ath10k_ce_pipe
*ce_state
)
664 struct ath10k
*ar
= ce_state
->ar
;
665 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
666 struct ath10k_pci_pipe
*pipe_info
= &ar_pci
->pipe_info
[ce_state
->id
];
667 struct ath10k_pci_compl
*compl;
669 void *transfer_context
;
672 unsigned int transfer_id
;
675 while (ath10k_ce_completed_recv_next(ce_state
, &transfer_context
,
676 &ce_data
, &nbytes
, &transfer_id
,
678 compl = get_free_compl(pipe_info
);
682 compl->state
= ATH10K_PCI_COMPL_RECV
;
683 compl->ce_state
= ce_state
;
684 compl->pipe_info
= pipe_info
;
685 compl->skb
= transfer_context
;
686 compl->nbytes
= nbytes
;
687 compl->transfer_id
= transfer_id
;
688 compl->flags
= flags
;
690 skb
= transfer_context
;
691 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(skb
)->paddr
,
692 skb
->len
+ skb_tailroom(skb
),
695 * Add the completion to the processing queue.
697 spin_lock_bh(&ar_pci
->compl_lock
);
698 list_add_tail(&compl->list
, &ar_pci
->compl_process
);
699 spin_unlock_bh(&ar_pci
->compl_lock
);
702 ath10k_pci_process_ce(ar
);
705 /* Send the first nbytes bytes of the buffer */
706 static int ath10k_pci_hif_send_head(struct ath10k
*ar
, u8 pipe_id
,
707 unsigned int transfer_id
,
708 unsigned int bytes
, struct sk_buff
*nbuf
)
710 struct ath10k_skb_cb
*skb_cb
= ATH10K_SKB_CB(nbuf
);
711 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
712 struct ath10k_pci_pipe
*pipe_info
= &(ar_pci
->pipe_info
[pipe_id
]);
713 struct ath10k_ce_pipe
*ce_hdl
= pipe_info
->ce_hdl
;
718 len
= min(bytes
, nbuf
->len
);
722 ath10k_warn("skb not aligned to 4-byte boundary (%d)\n", len
);
724 ath10k_dbg(ATH10K_DBG_PCI
,
725 "pci send data vaddr %p paddr 0x%llx len %d as %d bytes\n",
726 nbuf
->data
, (unsigned long long) skb_cb
->paddr
,
728 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP
, NULL
,
730 nbuf
->data
, nbuf
->len
);
732 ret
= ath10k_ce_send(ce_hdl
, nbuf
, skb_cb
->paddr
, len
, transfer_id
,
735 ath10k_warn("failed to send sk_buff to CE: %p\n", nbuf
);
740 static u16
ath10k_pci_hif_get_free_queue_number(struct ath10k
*ar
, u8 pipe
)
742 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
743 return ath10k_ce_num_free_src_entries(ar_pci
->pipe_info
[pipe
].ce_hdl
);
746 static void ath10k_pci_hif_dump_area(struct ath10k
*ar
)
748 u32 reg_dump_area
= 0;
749 u32 reg_dump_values
[REG_DUMP_COUNT_QCA988X
] = {};
754 ath10k_err("firmware crashed!\n");
755 ath10k_err("hardware name %s version 0x%x\n",
756 ar
->hw_params
.name
, ar
->target_version
);
757 ath10k_err("firmware version: %u.%u.%u.%u\n", ar
->fw_version_major
,
758 ar
->fw_version_minor
, ar
->fw_version_release
,
759 ar
->fw_version_build
);
761 host_addr
= host_interest_item_address(HI_ITEM(hi_failure_state
));
762 ret
= ath10k_pci_diag_read_mem(ar
, host_addr
,
763 ®_dump_area
, sizeof(u32
));
765 ath10k_err("failed to read FW dump area address: %d\n", ret
);
769 ath10k_err("target register Dump Location: 0x%08X\n", reg_dump_area
);
771 ret
= ath10k_pci_diag_read_mem(ar
, reg_dump_area
,
773 REG_DUMP_COUNT_QCA988X
* sizeof(u32
));
775 ath10k_err("failed to read FW dump area: %d\n", ret
);
779 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X
% 4);
781 ath10k_err("target Register Dump\n");
782 for (i
= 0; i
< REG_DUMP_COUNT_QCA988X
; i
+= 4)
783 ath10k_err("[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
786 reg_dump_values
[i
+ 1],
787 reg_dump_values
[i
+ 2],
788 reg_dump_values
[i
+ 3]);
790 queue_work(ar
->workqueue
, &ar
->restart_work
);
793 static void ath10k_pci_hif_send_complete_check(struct ath10k
*ar
, u8 pipe
,
799 * Decide whether to actually poll for completions, or just
800 * wait for a later chance.
801 * If there seem to be plenty of resources left, then just wait
802 * since checking involves reading a CE register, which is a
803 * relatively expensive operation.
805 resources
= ath10k_pci_hif_get_free_queue_number(ar
, pipe
);
808 * If at least 50% of the total resources are still available,
809 * don't bother checking again yet.
811 if (resources
> (host_ce_config_wlan
[pipe
].src_nentries
>> 1))
814 ath10k_ce_per_engine_service(ar
, pipe
);
817 static void ath10k_pci_hif_set_callbacks(struct ath10k
*ar
,
818 struct ath10k_hif_cb
*callbacks
)
820 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
822 ath10k_dbg(ATH10K_DBG_PCI
, "%s\n", __func__
);
824 memcpy(&ar_pci
->msg_callbacks_current
, callbacks
,
825 sizeof(ar_pci
->msg_callbacks_current
));
828 static int ath10k_pci_alloc_compl(struct ath10k
*ar
)
830 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
831 const struct ce_attr
*attr
;
832 struct ath10k_pci_pipe
*pipe_info
;
833 struct ath10k_pci_compl
*compl;
834 int i
, pipe_num
, completions
;
836 spin_lock_init(&ar_pci
->compl_lock
);
837 INIT_LIST_HEAD(&ar_pci
->compl_process
);
839 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
840 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
842 spin_lock_init(&pipe_info
->pipe_lock
);
843 INIT_LIST_HEAD(&pipe_info
->compl_free
);
845 /* Handle Diagnostic CE specially */
846 if (pipe_info
->ce_hdl
== ar_pci
->ce_diag
)
849 attr
= &host_ce_config_wlan
[pipe_num
];
852 if (attr
->src_nentries
)
853 completions
+= attr
->src_nentries
;
855 if (attr
->dest_nentries
)
856 completions
+= attr
->dest_nentries
;
858 for (i
= 0; i
< completions
; i
++) {
859 compl = kmalloc(sizeof(*compl), GFP_KERNEL
);
861 ath10k_warn("No memory for completion state\n");
862 ath10k_pci_cleanup_ce(ar
);
866 compl->state
= ATH10K_PCI_COMPL_FREE
;
867 list_add_tail(&compl->list
, &pipe_info
->compl_free
);
874 static int ath10k_pci_setup_ce_irq(struct ath10k
*ar
)
876 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
877 const struct ce_attr
*attr
;
878 struct ath10k_pci_pipe
*pipe_info
;
879 int pipe_num
, disable_interrupts
;
881 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
882 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
884 /* Handle Diagnostic CE specially */
885 if (pipe_info
->ce_hdl
== ar_pci
->ce_diag
)
888 attr
= &host_ce_config_wlan
[pipe_num
];
890 if (attr
->src_nentries
) {
891 disable_interrupts
= attr
->flags
& CE_ATTR_DIS_INTR
;
892 ath10k_ce_send_cb_register(pipe_info
->ce_hdl
,
893 ath10k_pci_ce_send_done
,
897 if (attr
->dest_nentries
)
898 ath10k_ce_recv_cb_register(pipe_info
->ce_hdl
,
899 ath10k_pci_ce_recv_data
);
905 static void ath10k_pci_kill_tasklet(struct ath10k
*ar
)
907 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
910 tasklet_kill(&ar_pci
->intr_tq
);
911 tasklet_kill(&ar_pci
->msi_fw_err
);
913 for (i
= 0; i
< CE_COUNT
; i
++)
914 tasklet_kill(&ar_pci
->pipe_info
[i
].intr
);
917 static void ath10k_pci_stop_ce(struct ath10k
*ar
)
919 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
920 struct ath10k_pci_compl
*compl;
924 ret
= ath10k_ce_disable_interrupts(ar
);
926 ath10k_warn("failed to disable CE interrupts: %d\n", ret
);
928 ath10k_pci_kill_tasklet(ar
);
930 /* Mark pending completions as aborted, so that upper layers free up
931 * their associated resources */
932 spin_lock_bh(&ar_pci
->compl_lock
);
933 list_for_each_entry(compl, &ar_pci
->compl_process
, list
) {
935 ATH10K_SKB_CB(skb
)->is_aborted
= true;
937 spin_unlock_bh(&ar_pci
->compl_lock
);
940 static void ath10k_pci_cleanup_ce(struct ath10k
*ar
)
942 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
943 struct ath10k_pci_compl
*compl, *tmp
;
944 struct ath10k_pci_pipe
*pipe_info
;
945 struct sk_buff
*netbuf
;
948 /* Free pending completions. */
949 spin_lock_bh(&ar_pci
->compl_lock
);
950 if (!list_empty(&ar_pci
->compl_process
))
951 ath10k_warn("pending completions still present! possible memory leaks.\n");
953 list_for_each_entry_safe(compl, tmp
, &ar_pci
->compl_process
, list
) {
954 list_del(&compl->list
);
956 dev_kfree_skb_any(netbuf
);
959 spin_unlock_bh(&ar_pci
->compl_lock
);
961 /* Free unused completions for each pipe. */
962 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
963 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
965 spin_lock_bh(&pipe_info
->pipe_lock
);
966 list_for_each_entry_safe(compl, tmp
,
967 &pipe_info
->compl_free
, list
) {
968 list_del(&compl->list
);
971 spin_unlock_bh(&pipe_info
->pipe_lock
);
975 static void ath10k_pci_process_ce(struct ath10k
*ar
)
977 struct ath10k_pci
*ar_pci
= ar
->hif
.priv
;
978 struct ath10k_hif_cb
*cb
= &ar_pci
->msg_callbacks_current
;
979 struct ath10k_pci_compl
*compl;
982 int ret
, send_done
= 0;
984 /* Upper layers aren't ready to handle tx/rx completions in parallel so
985 * we must serialize all completion processing. */
987 spin_lock_bh(&ar_pci
->compl_lock
);
988 if (ar_pci
->compl_processing
) {
989 spin_unlock_bh(&ar_pci
->compl_lock
);
992 ar_pci
->compl_processing
= true;
993 spin_unlock_bh(&ar_pci
->compl_lock
);
996 spin_lock_bh(&ar_pci
->compl_lock
);
997 if (list_empty(&ar_pci
->compl_process
)) {
998 spin_unlock_bh(&ar_pci
->compl_lock
);
1001 compl = list_first_entry(&ar_pci
->compl_process
,
1002 struct ath10k_pci_compl
, list
);
1003 list_del(&compl->list
);
1004 spin_unlock_bh(&ar_pci
->compl_lock
);
1006 switch (compl->state
) {
1007 case ATH10K_PCI_COMPL_SEND
:
1008 cb
->tx_completion(ar
,
1010 compl->transfer_id
);
1013 case ATH10K_PCI_COMPL_RECV
:
1014 ret
= ath10k_pci_post_rx_pipe(compl->pipe_info
, 1);
1016 ath10k_warn("failed to post RX buffer for pipe %d: %d\n",
1017 compl->pipe_info
->pipe_num
, ret
);
1022 nbytes
= compl->nbytes
;
1024 ath10k_dbg(ATH10K_DBG_PCI
,
1025 "ath10k_pci_ce_recv_data netbuf=%p nbytes=%d\n",
1027 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP
, NULL
,
1028 "ath10k rx: ", skb
->data
, nbytes
);
1030 if (skb
->len
+ skb_tailroom(skb
) >= nbytes
) {
1032 skb_put(skb
, nbytes
);
1033 cb
->rx_completion(ar
, skb
,
1034 compl->pipe_info
->pipe_num
);
1036 ath10k_warn("rxed more than expected (nbytes %d, max %d)",
1038 skb
->len
+ skb_tailroom(skb
));
1041 case ATH10K_PCI_COMPL_FREE
:
1042 ath10k_warn("free completion cannot be processed\n");
1045 ath10k_warn("invalid completion state (%d)\n",
1050 compl->state
= ATH10K_PCI_COMPL_FREE
;
1053 * Add completion back to the pipe's free list.
1055 spin_lock_bh(&compl->pipe_info
->pipe_lock
);
1056 list_add_tail(&compl->list
, &compl->pipe_info
->compl_free
);
1057 spin_unlock_bh(&compl->pipe_info
->pipe_lock
);
1060 spin_lock_bh(&ar_pci
->compl_lock
);
1061 ar_pci
->compl_processing
= false;
1062 spin_unlock_bh(&ar_pci
->compl_lock
);
1065 /* TODO - temporary mapping while we have too few CE's */
1066 static int ath10k_pci_hif_map_service_to_pipe(struct ath10k
*ar
,
1067 u16 service_id
, u8
*ul_pipe
,
1068 u8
*dl_pipe
, int *ul_is_polled
,
1073 /* polling for received messages not supported */
1076 switch (service_id
) {
1077 case ATH10K_HTC_SVC_ID_HTT_DATA_MSG
:
1079 * Host->target HTT gets its own pipe, so it can be polled
1080 * while other pipes are interrupt driven.
1084 * Use the same target->host pipe for HTC ctrl, HTC raw
1090 case ATH10K_HTC_SVC_ID_RSVD_CTRL
:
1091 case ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS
:
1093 * Note: HTC_RAW_STREAMS_SVC is currently unused, and
1094 * HTC_CTRL_RSVD_SVC could share the same pipe as the
1095 * WMI services. So, if another CE is needed, change
1096 * this to *ul_pipe = 3, which frees up CE 0.
1103 case ATH10K_HTC_SVC_ID_WMI_DATA_BK
:
1104 case ATH10K_HTC_SVC_ID_WMI_DATA_BE
:
1105 case ATH10K_HTC_SVC_ID_WMI_DATA_VI
:
1106 case ATH10K_HTC_SVC_ID_WMI_DATA_VO
:
1108 case ATH10K_HTC_SVC_ID_WMI_CONTROL
:
1114 /* pipe 6 reserved */
1115 /* pipe 7 reserved */
1122 (host_ce_config_wlan
[*ul_pipe
].flags
& CE_ATTR_DIS_INTR
) != 0;
1127 static void ath10k_pci_hif_get_default_pipe(struct ath10k
*ar
,
1128 u8
*ul_pipe
, u8
*dl_pipe
)
1130 int ul_is_polled
, dl_is_polled
;
1132 (void)ath10k_pci_hif_map_service_to_pipe(ar
,
1133 ATH10K_HTC_SVC_ID_RSVD_CTRL
,
1140 static int ath10k_pci_post_rx_pipe(struct ath10k_pci_pipe
*pipe_info
,
1143 struct ath10k
*ar
= pipe_info
->hif_ce_state
;
1144 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1145 struct ath10k_ce_pipe
*ce_state
= pipe_info
->ce_hdl
;
1146 struct sk_buff
*skb
;
1150 if (pipe_info
->buf_sz
== 0)
1153 for (i
= 0; i
< num
; i
++) {
1154 skb
= dev_alloc_skb(pipe_info
->buf_sz
);
1156 ath10k_warn("failed to allocate skbuff for pipe %d\n",
1162 WARN_ONCE((unsigned long)skb
->data
& 3, "unaligned skb");
1164 ce_data
= dma_map_single(ar
->dev
, skb
->data
,
1165 skb
->len
+ skb_tailroom(skb
),
1168 if (unlikely(dma_mapping_error(ar
->dev
, ce_data
))) {
1169 ath10k_warn("failed to DMA map sk_buff\n");
1170 dev_kfree_skb_any(skb
);
1175 ATH10K_SKB_CB(skb
)->paddr
= ce_data
;
1177 pci_dma_sync_single_for_device(ar_pci
->pdev
, ce_data
,
1179 PCI_DMA_FROMDEVICE
);
1181 ret
= ath10k_ce_recv_buf_enqueue(ce_state
, (void *)skb
,
1184 ath10k_warn("failed to enqueue to pipe %d: %d\n",
1193 ath10k_pci_rx_pipe_cleanup(pipe_info
);
1197 static int ath10k_pci_post_rx(struct ath10k
*ar
)
1199 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1200 struct ath10k_pci_pipe
*pipe_info
;
1201 const struct ce_attr
*attr
;
1202 int pipe_num
, ret
= 0;
1204 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
1205 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
1206 attr
= &host_ce_config_wlan
[pipe_num
];
1208 if (attr
->dest_nentries
== 0)
1211 ret
= ath10k_pci_post_rx_pipe(pipe_info
,
1212 attr
->dest_nentries
- 1);
1214 ath10k_warn("failed to post RX buffer for pipe %d: %d\n",
1217 for (; pipe_num
>= 0; pipe_num
--) {
1218 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
1219 ath10k_pci_rx_pipe_cleanup(pipe_info
);
1228 static int ath10k_pci_hif_start(struct ath10k
*ar
)
1230 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1233 ret
= ath10k_pci_alloc_compl(ar
);
1235 ath10k_warn("failed to allocate CE completions: %d\n", ret
);
1239 ret
= ath10k_pci_setup_ce_irq(ar
);
1241 ath10k_warn("failed to setup CE interrupts: %d\n", ret
);
1242 goto err_free_compl
;
1245 /* Post buffers once to start things off. */
1246 ret
= ath10k_pci_post_rx(ar
);
1248 ath10k_warn("failed to post RX buffers for all pipes: %d\n",
1253 ar_pci
->started
= 1;
1257 ath10k_pci_stop_ce(ar
);
1258 ath10k_pci_process_ce(ar
);
1260 ath10k_pci_cleanup_ce(ar
);
1264 static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe
*pipe_info
)
1267 struct ath10k_pci
*ar_pci
;
1268 struct ath10k_ce_pipe
*ce_hdl
;
1270 struct sk_buff
*netbuf
;
1273 buf_sz
= pipe_info
->buf_sz
;
1275 /* Unused Copy Engine */
1279 ar
= pipe_info
->hif_ce_state
;
1280 ar_pci
= ath10k_pci_priv(ar
);
1282 if (!ar_pci
->started
)
1285 ce_hdl
= pipe_info
->ce_hdl
;
1287 while (ath10k_ce_revoke_recv_next(ce_hdl
, (void **)&netbuf
,
1289 dma_unmap_single(ar
->dev
, ATH10K_SKB_CB(netbuf
)->paddr
,
1290 netbuf
->len
+ skb_tailroom(netbuf
),
1292 dev_kfree_skb_any(netbuf
);
1296 static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe
*pipe_info
)
1299 struct ath10k_pci
*ar_pci
;
1300 struct ath10k_ce_pipe
*ce_hdl
;
1301 struct sk_buff
*netbuf
;
1303 unsigned int nbytes
;
1307 buf_sz
= pipe_info
->buf_sz
;
1309 /* Unused Copy Engine */
1313 ar
= pipe_info
->hif_ce_state
;
1314 ar_pci
= ath10k_pci_priv(ar
);
1316 if (!ar_pci
->started
)
1319 ce_hdl
= pipe_info
->ce_hdl
;
1321 while (ath10k_ce_cancel_send_next(ce_hdl
, (void **)&netbuf
,
1322 &ce_data
, &nbytes
, &id
) == 0) {
1324 * Indicate the completion to higer layer to free
1329 ath10k_warn("invalid sk_buff on CE %d - NULL pointer. firmware crashed?\n",
1334 ATH10K_SKB_CB(netbuf
)->is_aborted
= true;
1335 ar_pci
->msg_callbacks_current
.tx_completion(ar
,
1342 * Cleanup residual buffers for device shutdown:
1343 * buffers that were enqueued for receive
1344 * buffers that were to be sent
1345 * Note: Buffers that had completed but which were
1346 * not yet processed are on a completion queue. They
1347 * are handled when the completion thread shuts down.
1349 static void ath10k_pci_buffer_cleanup(struct ath10k
*ar
)
1351 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1354 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
1355 struct ath10k_pci_pipe
*pipe_info
;
1357 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
1358 ath10k_pci_rx_pipe_cleanup(pipe_info
);
1359 ath10k_pci_tx_pipe_cleanup(pipe_info
);
1363 static void ath10k_pci_ce_deinit(struct ath10k
*ar
)
1365 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1366 struct ath10k_pci_pipe
*pipe_info
;
1369 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
1370 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
1371 if (pipe_info
->ce_hdl
) {
1372 ath10k_ce_deinit(pipe_info
->ce_hdl
);
1373 pipe_info
->ce_hdl
= NULL
;
1374 pipe_info
->buf_sz
= 0;
1379 static void ath10k_pci_disable_irqs(struct ath10k
*ar
)
1381 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1384 for (i
= 0; i
< max(1, ar_pci
->num_msi_intrs
); i
++)
1385 disable_irq(ar_pci
->pdev
->irq
+ i
);
1388 static void ath10k_pci_hif_stop(struct ath10k
*ar
)
1390 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1392 ath10k_dbg(ATH10K_DBG_PCI
, "%s\n", __func__
);
1394 /* Irqs are never explicitly re-enabled. They are implicitly re-enabled
1395 * by upon power_up. */
1396 ath10k_pci_disable_irqs(ar
);
1398 ath10k_pci_stop_ce(ar
);
1400 /* At this point, asynchronous threads are stopped, the target should
1401 * not DMA nor interrupt. We process the leftovers and then free
1402 * everything else up. */
1404 ath10k_pci_process_ce(ar
);
1405 ath10k_pci_cleanup_ce(ar
);
1406 ath10k_pci_buffer_cleanup(ar
);
1408 /* Make the sure the device won't access any structures on the host by
1409 * resetting it. The device was fed with PCI CE ringbuffer
1410 * configuration during init. If ringbuffers are freed and the device
1411 * were to access them this could lead to memory corruption on the
1413 ath10k_pci_device_reset(ar
);
1415 ar_pci
->started
= 0;
1418 static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k
*ar
,
1419 void *req
, u32 req_len
,
1420 void *resp
, u32
*resp_len
)
1422 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1423 struct ath10k_pci_pipe
*pci_tx
= &ar_pci
->pipe_info
[BMI_CE_NUM_TO_TARG
];
1424 struct ath10k_pci_pipe
*pci_rx
= &ar_pci
->pipe_info
[BMI_CE_NUM_TO_HOST
];
1425 struct ath10k_ce_pipe
*ce_tx
= pci_tx
->ce_hdl
;
1426 struct ath10k_ce_pipe
*ce_rx
= pci_rx
->ce_hdl
;
1427 dma_addr_t req_paddr
= 0;
1428 dma_addr_t resp_paddr
= 0;
1429 struct bmi_xfer xfer
= {};
1430 void *treq
, *tresp
= NULL
;
1435 if (resp
&& !resp_len
)
1438 if (resp
&& resp_len
&& *resp_len
== 0)
1441 treq
= kmemdup(req
, req_len
, GFP_KERNEL
);
1445 req_paddr
= dma_map_single(ar
->dev
, treq
, req_len
, DMA_TO_DEVICE
);
1446 ret
= dma_mapping_error(ar
->dev
, req_paddr
);
1450 if (resp
&& resp_len
) {
1451 tresp
= kzalloc(*resp_len
, GFP_KERNEL
);
1457 resp_paddr
= dma_map_single(ar
->dev
, tresp
, *resp_len
,
1459 ret
= dma_mapping_error(ar
->dev
, resp_paddr
);
1463 xfer
.wait_for_resp
= true;
1466 ath10k_ce_recv_buf_enqueue(ce_rx
, &xfer
, resp_paddr
);
1469 init_completion(&xfer
.done
);
1471 ret
= ath10k_ce_send(ce_tx
, &xfer
, req_paddr
, req_len
, -1, 0);
1475 ret
= ath10k_pci_bmi_wait(ce_tx
, ce_rx
, &xfer
);
1478 unsigned int unused_nbytes
;
1479 unsigned int unused_id
;
1481 ath10k_ce_cancel_send_next(ce_tx
, NULL
, &unused_buffer
,
1482 &unused_nbytes
, &unused_id
);
1484 /* non-zero means we did not time out */
1492 ath10k_ce_revoke_recv_next(ce_rx
, NULL
, &unused_buffer
);
1493 dma_unmap_single(ar
->dev
, resp_paddr
,
1494 *resp_len
, DMA_FROM_DEVICE
);
1497 dma_unmap_single(ar
->dev
, req_paddr
, req_len
, DMA_TO_DEVICE
);
1499 if (ret
== 0 && resp_len
) {
1500 *resp_len
= min(*resp_len
, xfer
.resp_len
);
1501 memcpy(resp
, tresp
, xfer
.resp_len
);
1510 static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe
*ce_state
)
1512 struct bmi_xfer
*xfer
;
1514 unsigned int nbytes
;
1515 unsigned int transfer_id
;
1517 if (ath10k_ce_completed_send_next(ce_state
, (void **)&xfer
, &ce_data
,
1518 &nbytes
, &transfer_id
))
1521 if (xfer
->wait_for_resp
)
1524 complete(&xfer
->done
);
1527 static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe
*ce_state
)
1529 struct bmi_xfer
*xfer
;
1531 unsigned int nbytes
;
1532 unsigned int transfer_id
;
1535 if (ath10k_ce_completed_recv_next(ce_state
, (void **)&xfer
, &ce_data
,
1536 &nbytes
, &transfer_id
, &flags
))
1539 if (!xfer
->wait_for_resp
) {
1540 ath10k_warn("unexpected: BMI data received; ignoring\n");
1544 xfer
->resp_len
= nbytes
;
1545 complete(&xfer
->done
);
1548 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe
*tx_pipe
,
1549 struct ath10k_ce_pipe
*rx_pipe
,
1550 struct bmi_xfer
*xfer
)
1552 unsigned long timeout
= jiffies
+ BMI_COMMUNICATION_TIMEOUT_HZ
;
1554 while (time_before_eq(jiffies
, timeout
)) {
1555 ath10k_pci_bmi_send_done(tx_pipe
);
1556 ath10k_pci_bmi_recv_data(rx_pipe
);
1558 if (completion_done(&xfer
->done
))
1568 * Map from service/endpoint to Copy Engine.
1569 * This table is derived from the CE_PCI TABLE, above.
1570 * It is passed to the Target at startup for use by firmware.
1572 static const struct service_to_pipe target_service_to_ce_map_wlan
[] = {
1574 ATH10K_HTC_SVC_ID_WMI_DATA_VO
,
1575 PIPEDIR_OUT
, /* out = UL = host -> target */
1579 ATH10K_HTC_SVC_ID_WMI_DATA_VO
,
1580 PIPEDIR_IN
, /* in = DL = target -> host */
1584 ATH10K_HTC_SVC_ID_WMI_DATA_BK
,
1585 PIPEDIR_OUT
, /* out = UL = host -> target */
1589 ATH10K_HTC_SVC_ID_WMI_DATA_BK
,
1590 PIPEDIR_IN
, /* in = DL = target -> host */
1594 ATH10K_HTC_SVC_ID_WMI_DATA_BE
,
1595 PIPEDIR_OUT
, /* out = UL = host -> target */
1599 ATH10K_HTC_SVC_ID_WMI_DATA_BE
,
1600 PIPEDIR_IN
, /* in = DL = target -> host */
1604 ATH10K_HTC_SVC_ID_WMI_DATA_VI
,
1605 PIPEDIR_OUT
, /* out = UL = host -> target */
1609 ATH10K_HTC_SVC_ID_WMI_DATA_VI
,
1610 PIPEDIR_IN
, /* in = DL = target -> host */
1614 ATH10K_HTC_SVC_ID_WMI_CONTROL
,
1615 PIPEDIR_OUT
, /* out = UL = host -> target */
1619 ATH10K_HTC_SVC_ID_WMI_CONTROL
,
1620 PIPEDIR_IN
, /* in = DL = target -> host */
1624 ATH10K_HTC_SVC_ID_RSVD_CTRL
,
1625 PIPEDIR_OUT
, /* out = UL = host -> target */
1626 0, /* could be moved to 3 (share with WMI) */
1629 ATH10K_HTC_SVC_ID_RSVD_CTRL
,
1630 PIPEDIR_IN
, /* in = DL = target -> host */
1634 ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS
, /* not currently used */
1635 PIPEDIR_OUT
, /* out = UL = host -> target */
1639 ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS
, /* not currently used */
1640 PIPEDIR_IN
, /* in = DL = target -> host */
1644 ATH10K_HTC_SVC_ID_HTT_DATA_MSG
,
1645 PIPEDIR_OUT
, /* out = UL = host -> target */
1649 ATH10K_HTC_SVC_ID_HTT_DATA_MSG
,
1650 PIPEDIR_IN
, /* in = DL = target -> host */
1654 /* (Additions here) */
1656 { /* Must be last */
1664 * Send an interrupt to the device to wake up the Target CPU
1665 * so it has an opportunity to notice any changed state.
1667 static int ath10k_pci_wake_target_cpu(struct ath10k
*ar
)
1672 ret
= ath10k_pci_diag_read_access(ar
, SOC_CORE_BASE_ADDRESS
|
1676 ath10k_warn("failed to read core_ctrl: %d\n", ret
);
1680 /* A_INUM_FIRMWARE interrupt to Target CPU */
1681 core_ctrl
|= CORE_CTRL_CPU_INTR_MASK
;
1683 ret
= ath10k_pci_diag_write_access(ar
, SOC_CORE_BASE_ADDRESS
|
1687 ath10k_warn("failed to set target CPU interrupt mask: %d\n",
1695 static int ath10k_pci_init_config(struct ath10k
*ar
)
1697 u32 interconnect_targ_addr
;
1698 u32 pcie_state_targ_addr
= 0;
1699 u32 pipe_cfg_targ_addr
= 0;
1700 u32 svc_to_pipe_map
= 0;
1701 u32 pcie_config_flags
= 0;
1703 u32 ealloc_targ_addr
;
1705 u32 flag2_targ_addr
;
1708 /* Download to Target the CE Config and the service-to-CE map */
1709 interconnect_targ_addr
=
1710 host_interest_item_address(HI_ITEM(hi_interconnect_state
));
1712 /* Supply Target-side CE configuration */
1713 ret
= ath10k_pci_diag_read_access(ar
, interconnect_targ_addr
,
1714 &pcie_state_targ_addr
);
1716 ath10k_err("Failed to get pcie state addr: %d\n", ret
);
1720 if (pcie_state_targ_addr
== 0) {
1722 ath10k_err("Invalid pcie state addr\n");
1726 ret
= ath10k_pci_diag_read_access(ar
, pcie_state_targ_addr
+
1727 offsetof(struct pcie_state
,
1729 &pipe_cfg_targ_addr
);
1731 ath10k_err("Failed to get pipe cfg addr: %d\n", ret
);
1735 if (pipe_cfg_targ_addr
== 0) {
1737 ath10k_err("Invalid pipe cfg addr\n");
1741 ret
= ath10k_pci_diag_write_mem(ar
, pipe_cfg_targ_addr
,
1742 target_ce_config_wlan
,
1743 sizeof(target_ce_config_wlan
));
1746 ath10k_err("Failed to write pipe cfg: %d\n", ret
);
1750 ret
= ath10k_pci_diag_read_access(ar
, pcie_state_targ_addr
+
1751 offsetof(struct pcie_state
,
1755 ath10k_err("Failed to get svc/pipe map: %d\n", ret
);
1759 if (svc_to_pipe_map
== 0) {
1761 ath10k_err("Invalid svc_to_pipe map\n");
1765 ret
= ath10k_pci_diag_write_mem(ar
, svc_to_pipe_map
,
1766 target_service_to_ce_map_wlan
,
1767 sizeof(target_service_to_ce_map_wlan
));
1769 ath10k_err("Failed to write svc/pipe map: %d\n", ret
);
1773 ret
= ath10k_pci_diag_read_access(ar
, pcie_state_targ_addr
+
1774 offsetof(struct pcie_state
,
1776 &pcie_config_flags
);
1778 ath10k_err("Failed to get pcie config_flags: %d\n", ret
);
1782 pcie_config_flags
&= ~PCIE_CONFIG_FLAG_ENABLE_L1
;
1784 ret
= ath10k_pci_diag_write_mem(ar
, pcie_state_targ_addr
+
1785 offsetof(struct pcie_state
, config_flags
),
1787 sizeof(pcie_config_flags
));
1789 ath10k_err("Failed to write pcie config_flags: %d\n", ret
);
1793 /* configure early allocation */
1794 ealloc_targ_addr
= host_interest_item_address(HI_ITEM(hi_early_alloc
));
1796 ret
= ath10k_pci_diag_read_access(ar
, ealloc_targ_addr
, &ealloc_value
);
1798 ath10k_err("Faile to get early alloc val: %d\n", ret
);
1802 /* first bank is switched to IRAM */
1803 ealloc_value
|= ((HI_EARLY_ALLOC_MAGIC
<< HI_EARLY_ALLOC_MAGIC_SHIFT
) &
1804 HI_EARLY_ALLOC_MAGIC_MASK
);
1805 ealloc_value
|= ((1 << HI_EARLY_ALLOC_IRAM_BANKS_SHIFT
) &
1806 HI_EARLY_ALLOC_IRAM_BANKS_MASK
);
1808 ret
= ath10k_pci_diag_write_access(ar
, ealloc_targ_addr
, ealloc_value
);
1810 ath10k_err("Failed to set early alloc val: %d\n", ret
);
1814 /* Tell Target to proceed with initialization */
1815 flag2_targ_addr
= host_interest_item_address(HI_ITEM(hi_option_flag2
));
1817 ret
= ath10k_pci_diag_read_access(ar
, flag2_targ_addr
, &flag2_value
);
1819 ath10k_err("Failed to get option val: %d\n", ret
);
1823 flag2_value
|= HI_OPTION_EARLY_CFG_DONE
;
1825 ret
= ath10k_pci_diag_write_access(ar
, flag2_targ_addr
, flag2_value
);
1827 ath10k_err("Failed to set option val: %d\n", ret
);
1836 static int ath10k_pci_ce_init(struct ath10k
*ar
)
1838 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1839 struct ath10k_pci_pipe
*pipe_info
;
1840 const struct ce_attr
*attr
;
1843 for (pipe_num
= 0; pipe_num
< CE_COUNT
; pipe_num
++) {
1844 pipe_info
= &ar_pci
->pipe_info
[pipe_num
];
1845 pipe_info
->pipe_num
= pipe_num
;
1846 pipe_info
->hif_ce_state
= ar
;
1847 attr
= &host_ce_config_wlan
[pipe_num
];
1849 pipe_info
->ce_hdl
= ath10k_ce_init(ar
, pipe_num
, attr
);
1850 if (pipe_info
->ce_hdl
== NULL
) {
1851 ath10k_err("failed to initialize CE for pipe: %d\n",
1854 /* It is safe to call it here. It checks if ce_hdl is
1855 * valid for each pipe */
1856 ath10k_pci_ce_deinit(ar
);
1860 if (pipe_num
== CE_COUNT
- 1) {
1862 * Reserve the ultimate CE for
1863 * diagnostic Window support
1865 ar_pci
->ce_diag
= pipe_info
->ce_hdl
;
1869 pipe_info
->buf_sz
= (size_t) (attr
->src_sz_max
);
1875 static void ath10k_pci_fw_interrupt_handler(struct ath10k
*ar
)
1877 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1878 u32 fw_indicator_address
, fw_indicator
;
1880 ath10k_pci_wake(ar
);
1882 fw_indicator_address
= ar_pci
->fw_indicator_address
;
1883 fw_indicator
= ath10k_pci_read32(ar
, fw_indicator_address
);
1885 if (fw_indicator
& FW_IND_EVENT_PENDING
) {
1886 /* ACK: clear Target-side pending event */
1887 ath10k_pci_write32(ar
, fw_indicator_address
,
1888 fw_indicator
& ~FW_IND_EVENT_PENDING
);
1890 if (ar_pci
->started
) {
1891 ath10k_pci_hif_dump_area(ar
);
1894 * Probable Target failure before we're prepared
1895 * to handle it. Generally unexpected.
1897 ath10k_warn("early firmware event indicated\n");
1901 ath10k_pci_sleep(ar
);
1904 static int ath10k_pci_hif_power_up(struct ath10k
*ar
)
1906 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
1907 const char *irq_mode
;
1911 * Bring the target up cleanly.
1913 * The target may be in an undefined state with an AUX-powered Target
1914 * and a Host in WoW mode. If the Host crashes, loses power, or is
1915 * restarted (without unloading the driver) then the Target is left
1916 * (aux) powered and running. On a subsequent driver load, the Target
1917 * is in an unexpected state. We try to catch that here in order to
1918 * reset the Target and retry the probe.
1920 ret
= ath10k_pci_device_reset(ar
);
1922 ath10k_err("failed to reset target: %d\n", ret
);
1926 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE
, ar_pci
->features
))
1927 /* Force AWAKE forever */
1928 ath10k_do_pci_wake(ar
);
1930 ret
= ath10k_pci_ce_init(ar
);
1932 ath10k_err("failed to initialize CE: %d\n", ret
);
1936 ret
= ath10k_ce_disable_interrupts(ar
);
1938 ath10k_err("failed to disable CE interrupts: %d\n", ret
);
1942 ret
= ath10k_pci_init_irq(ar
);
1944 ath10k_err("failed to init irqs: %d\n", ret
);
1948 ret
= ath10k_pci_request_irq(ar
);
1950 ath10k_err("failed to request irqs: %d\n", ret
);
1951 goto err_deinit_irq
;
1954 ret
= ath10k_pci_wait_for_target_init(ar
);
1956 ath10k_err("failed to wait for target to init: %d\n", ret
);
1960 ret
= ath10k_ce_enable_err_irq(ar
);
1962 ath10k_err("failed to enable CE error irq: %d\n", ret
);
1966 ret
= ath10k_pci_init_config(ar
);
1968 ath10k_err("failed to setup init config: %d\n", ret
);
1972 ret
= ath10k_pci_wake_target_cpu(ar
);
1974 ath10k_err("could not wake up target CPU: %d\n", ret
);
1978 if (ar_pci
->num_msi_intrs
> 1)
1980 else if (ar_pci
->num_msi_intrs
== 1)
1983 irq_mode
= "legacy";
1985 if (!test_bit(ATH10K_FLAG_FIRST_BOOT_DONE
, &ar
->dev_flags
))
1986 ath10k_info("pci irq %s\n", irq_mode
);
1991 ath10k_pci_free_irq(ar
);
1992 ath10k_pci_kill_tasklet(ar
);
1993 ath10k_pci_device_reset(ar
);
1995 ath10k_pci_deinit_irq(ar
);
1997 ath10k_pci_ce_deinit(ar
);
1999 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE
, ar_pci
->features
))
2000 ath10k_do_pci_sleep(ar
);
2005 static void ath10k_pci_hif_power_down(struct ath10k
*ar
)
2007 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2009 ath10k_pci_free_irq(ar
);
2010 ath10k_pci_deinit_irq(ar
);
2011 ath10k_pci_device_reset(ar
);
2013 ath10k_pci_ce_deinit(ar
);
2014 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE
, ar_pci
->features
))
2015 ath10k_do_pci_sleep(ar
);
2020 #define ATH10K_PCI_PM_CONTROL 0x44
2022 static int ath10k_pci_hif_suspend(struct ath10k
*ar
)
2024 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2025 struct pci_dev
*pdev
= ar_pci
->pdev
;
2028 pci_read_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
, &val
);
2030 if ((val
& 0x000000ff) != 0x3) {
2031 pci_save_state(pdev
);
2032 pci_disable_device(pdev
);
2033 pci_write_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
,
2034 (val
& 0xffffff00) | 0x03);
2040 static int ath10k_pci_hif_resume(struct ath10k
*ar
)
2042 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2043 struct pci_dev
*pdev
= ar_pci
->pdev
;
2046 pci_read_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
, &val
);
2048 if ((val
& 0x000000ff) != 0) {
2049 pci_restore_state(pdev
);
2050 pci_write_config_dword(pdev
, ATH10K_PCI_PM_CONTROL
,
2053 * Suspend/Resume resets the PCI configuration space,
2054 * so we have to re-disable the RETRY_TIMEOUT register (0x41)
2055 * to keep PCI Tx retries from interfering with C3 CPU state
2057 pci_read_config_dword(pdev
, 0x40, &val
);
2059 if ((val
& 0x0000ff00) != 0)
2060 pci_write_config_dword(pdev
, 0x40, val
& 0xffff00ff);
2067 static const struct ath10k_hif_ops ath10k_pci_hif_ops
= {
2068 .send_head
= ath10k_pci_hif_send_head
,
2069 .exchange_bmi_msg
= ath10k_pci_hif_exchange_bmi_msg
,
2070 .start
= ath10k_pci_hif_start
,
2071 .stop
= ath10k_pci_hif_stop
,
2072 .map_service_to_pipe
= ath10k_pci_hif_map_service_to_pipe
,
2073 .get_default_pipe
= ath10k_pci_hif_get_default_pipe
,
2074 .send_complete_check
= ath10k_pci_hif_send_complete_check
,
2075 .set_callbacks
= ath10k_pci_hif_set_callbacks
,
2076 .get_free_queue_number
= ath10k_pci_hif_get_free_queue_number
,
2077 .power_up
= ath10k_pci_hif_power_up
,
2078 .power_down
= ath10k_pci_hif_power_down
,
2080 .suspend
= ath10k_pci_hif_suspend
,
2081 .resume
= ath10k_pci_hif_resume
,
2085 static void ath10k_pci_ce_tasklet(unsigned long ptr
)
2087 struct ath10k_pci_pipe
*pipe
= (struct ath10k_pci_pipe
*)ptr
;
2088 struct ath10k_pci
*ar_pci
= pipe
->ar_pci
;
2090 ath10k_ce_per_engine_service(ar_pci
->ar
, pipe
->pipe_num
);
2093 static void ath10k_msi_err_tasklet(unsigned long data
)
2095 struct ath10k
*ar
= (struct ath10k
*)data
;
2097 ath10k_pci_fw_interrupt_handler(ar
);
2101 * Handler for a per-engine interrupt on a PARTICULAR CE.
2102 * This is used in cases where each CE has a private MSI interrupt.
2104 static irqreturn_t
ath10k_pci_per_engine_handler(int irq
, void *arg
)
2106 struct ath10k
*ar
= arg
;
2107 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2108 int ce_id
= irq
- ar_pci
->pdev
->irq
- MSI_ASSIGN_CE_INITIAL
;
2110 if (ce_id
< 0 || ce_id
>= ARRAY_SIZE(ar_pci
->pipe_info
)) {
2111 ath10k_warn("unexpected/invalid irq %d ce_id %d\n", irq
, ce_id
);
2116 * NOTE: We are able to derive ce_id from irq because we
2117 * use a one-to-one mapping for CE's 0..5.
2118 * CE's 6 & 7 do not use interrupts at all.
2120 * This mapping must be kept in sync with the mapping
2123 tasklet_schedule(&ar_pci
->pipe_info
[ce_id
].intr
);
2127 static irqreturn_t
ath10k_pci_msi_fw_handler(int irq
, void *arg
)
2129 struct ath10k
*ar
= arg
;
2130 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2132 tasklet_schedule(&ar_pci
->msi_fw_err
);
2137 * Top-level interrupt handler for all PCI interrupts from a Target.
2138 * When a block of MSI interrupts is allocated, this top-level handler
2139 * is not used; instead, we directly call the correct sub-handler.
2141 static irqreturn_t
ath10k_pci_interrupt_handler(int irq
, void *arg
)
2143 struct ath10k
*ar
= arg
;
2144 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2146 if (ar_pci
->num_msi_intrs
== 0) {
2147 if (!ath10k_pci_irq_pending(ar
))
2151 * IMPORTANT: INTR_CLR regiser has to be set after
2152 * INTR_ENABLE is set to 0, otherwise interrupt can not be
2155 iowrite32(0, ar_pci
->mem
+
2156 (SOC_CORE_BASE_ADDRESS
|
2157 PCIE_INTR_ENABLE_ADDRESS
));
2158 iowrite32(PCIE_INTR_FIRMWARE_MASK
|
2159 PCIE_INTR_CE_MASK_ALL
,
2160 ar_pci
->mem
+ (SOC_CORE_BASE_ADDRESS
|
2161 PCIE_INTR_CLR_ADDRESS
));
2163 * IMPORTANT: this extra read transaction is required to
2164 * flush the posted write buffer.
2166 (void) ioread32(ar_pci
->mem
+
2167 (SOC_CORE_BASE_ADDRESS
|
2168 PCIE_INTR_ENABLE_ADDRESS
));
2171 tasklet_schedule(&ar_pci
->intr_tq
);
2176 static void ath10k_pci_tasklet(unsigned long data
)
2178 struct ath10k
*ar
= (struct ath10k
*)data
;
2179 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2181 ath10k_pci_fw_interrupt_handler(ar
); /* FIXME: Handle FW error */
2182 ath10k_ce_per_engine_service_any(ar
);
2184 if (ar_pci
->num_msi_intrs
== 0) {
2185 /* Enable Legacy PCI line interrupts */
2186 iowrite32(PCIE_INTR_FIRMWARE_MASK
|
2187 PCIE_INTR_CE_MASK_ALL
,
2188 ar_pci
->mem
+ (SOC_CORE_BASE_ADDRESS
|
2189 PCIE_INTR_ENABLE_ADDRESS
));
2191 * IMPORTANT: this extra read transaction is required to
2192 * flush the posted write buffer
2194 (void) ioread32(ar_pci
->mem
+
2195 (SOC_CORE_BASE_ADDRESS
|
2196 PCIE_INTR_ENABLE_ADDRESS
));
2200 static int ath10k_pci_request_irq_msix(struct ath10k
*ar
)
2202 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2205 ret
= request_irq(ar_pci
->pdev
->irq
+ MSI_ASSIGN_FW
,
2206 ath10k_pci_msi_fw_handler
,
2207 IRQF_SHARED
, "ath10k_pci", ar
);
2209 ath10k_warn("failed to request MSI-X fw irq %d: %d\n",
2210 ar_pci
->pdev
->irq
+ MSI_ASSIGN_FW
, ret
);
2214 for (i
= MSI_ASSIGN_CE_INITIAL
; i
<= MSI_ASSIGN_CE_MAX
; i
++) {
2215 ret
= request_irq(ar_pci
->pdev
->irq
+ i
,
2216 ath10k_pci_per_engine_handler
,
2217 IRQF_SHARED
, "ath10k_pci", ar
);
2219 ath10k_warn("failed to request MSI-X ce irq %d: %d\n",
2220 ar_pci
->pdev
->irq
+ i
, ret
);
2222 for (i
--; i
>= MSI_ASSIGN_CE_INITIAL
; i
--)
2223 free_irq(ar_pci
->pdev
->irq
+ i
, ar
);
2225 free_irq(ar_pci
->pdev
->irq
+ MSI_ASSIGN_FW
, ar
);
2233 static int ath10k_pci_request_irq_msi(struct ath10k
*ar
)
2235 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2238 ret
= request_irq(ar_pci
->pdev
->irq
,
2239 ath10k_pci_interrupt_handler
,
2240 IRQF_SHARED
, "ath10k_pci", ar
);
2242 ath10k_warn("failed to request MSI irq %d: %d\n",
2243 ar_pci
->pdev
->irq
, ret
);
2250 static int ath10k_pci_request_irq_legacy(struct ath10k
*ar
)
2252 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2255 ret
= request_irq(ar_pci
->pdev
->irq
,
2256 ath10k_pci_interrupt_handler
,
2257 IRQF_SHARED
, "ath10k_pci", ar
);
2259 ath10k_warn("failed to request legacy irq %d: %d\n",
2260 ar_pci
->pdev
->irq
, ret
);
2267 static int ath10k_pci_request_irq(struct ath10k
*ar
)
2269 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2271 switch (ar_pci
->num_msi_intrs
) {
2273 return ath10k_pci_request_irq_legacy(ar
);
2275 return ath10k_pci_request_irq_msi(ar
);
2276 case MSI_NUM_REQUEST
:
2277 return ath10k_pci_request_irq_msix(ar
);
2280 ath10k_warn("unknown irq configuration upon request\n");
2284 static void ath10k_pci_free_irq(struct ath10k
*ar
)
2286 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2289 /* There's at least one interrupt irregardless whether its legacy INTR
2290 * or MSI or MSI-X */
2291 for (i
= 0; i
< max(1, ar_pci
->num_msi_intrs
); i
++)
2292 free_irq(ar_pci
->pdev
->irq
+ i
, ar
);
2295 static void ath10k_pci_init_irq_tasklets(struct ath10k
*ar
)
2297 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2300 tasklet_init(&ar_pci
->intr_tq
, ath10k_pci_tasklet
, (unsigned long)ar
);
2301 tasklet_init(&ar_pci
->msi_fw_err
, ath10k_msi_err_tasklet
,
2304 for (i
= 0; i
< CE_COUNT
; i
++) {
2305 ar_pci
->pipe_info
[i
].ar_pci
= ar_pci
;
2306 tasklet_init(&ar_pci
->pipe_info
[i
].intr
, ath10k_pci_ce_tasklet
,
2307 (unsigned long)&ar_pci
->pipe_info
[i
]);
2311 static int ath10k_pci_init_irq(struct ath10k
*ar
)
2313 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2316 ath10k_pci_init_irq_tasklets(ar
);
2318 if (!test_bit(ATH10K_PCI_FEATURE_MSI_X
, ar_pci
->features
))
2322 ar_pci
->num_msi_intrs
= MSI_NUM_REQUEST
;
2323 ret
= pci_enable_msi_block(ar_pci
->pdev
, ar_pci
->num_msi_intrs
);
2327 pci_disable_msi(ar_pci
->pdev
);
2331 ar_pci
->num_msi_intrs
= 1;
2332 ret
= pci_enable_msi(ar_pci
->pdev
);
2338 * A potential race occurs here: The CORE_BASE write
2339 * depends on target correctly decoding AXI address but
2340 * host won't know when target writes BAR to CORE_CTRL.
2341 * This write might get lost if target has NOT written BAR.
2342 * For now, fix the race by repeating the write in below
2343 * synchronization checking. */
2344 ar_pci
->num_msi_intrs
= 0;
2346 ret
= ath10k_pci_wake(ar
);
2348 ath10k_warn("failed to wake target: %d\n", ret
);
2352 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ PCIE_INTR_ENABLE_ADDRESS
,
2353 PCIE_INTR_FIRMWARE_MASK
| PCIE_INTR_CE_MASK_ALL
);
2354 ath10k_pci_sleep(ar
);
2359 static int ath10k_pci_deinit_irq_legacy(struct ath10k
*ar
)
2363 ret
= ath10k_pci_wake(ar
);
2365 ath10k_warn("failed to wake target: %d\n", ret
);
2369 ath10k_pci_write32(ar
, SOC_CORE_BASE_ADDRESS
+ PCIE_INTR_ENABLE_ADDRESS
,
2371 ath10k_pci_sleep(ar
);
2376 static int ath10k_pci_deinit_irq(struct ath10k
*ar
)
2378 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2380 switch (ar_pci
->num_msi_intrs
) {
2382 return ath10k_pci_deinit_irq_legacy(ar
);
2385 case MSI_NUM_REQUEST
:
2386 pci_disable_msi(ar_pci
->pdev
);
2390 ath10k_warn("unknown irq configuration upon deinit\n");
2394 static int ath10k_pci_wait_for_target_init(struct ath10k
*ar
)
2396 struct ath10k_pci
*ar_pci
= ath10k_pci_priv(ar
);
2397 int wait_limit
= 300; /* 3 sec */
2400 ret
= ath10k_pci_wake(ar
);
2402 ath10k_err("failed to wake up target: %d\n", ret
);
2406 while (wait_limit
-- &&
2407 !(ioread32(ar_pci
->mem
+ FW_INDICATOR_ADDRESS
) &
2408 FW_IND_INITIALIZED
)) {
2409 if (ar_pci
->num_msi_intrs
== 0)
2410 /* Fix potential race by repeating CORE_BASE writes */
2411 iowrite32(PCIE_INTR_FIRMWARE_MASK
|
2412 PCIE_INTR_CE_MASK_ALL
,
2413 ar_pci
->mem
+ (SOC_CORE_BASE_ADDRESS
|
2414 PCIE_INTR_ENABLE_ADDRESS
));
2418 if (wait_limit
< 0) {
2419 ath10k_err("target stalled\n");
2425 ath10k_pci_sleep(ar
);
2429 static int ath10k_pci_device_reset(struct ath10k
*ar
)
2434 ret
= ath10k_do_pci_wake(ar
);
2436 ath10k_err("failed to wake up target: %d\n",
2441 /* Put Target, including PCIe, into RESET. */
2442 val
= ath10k_pci_reg_read32(ar
, SOC_GLOBAL_RESET_ADDRESS
);
2444 ath10k_pci_reg_write32(ar
, SOC_GLOBAL_RESET_ADDRESS
, val
);
2446 for (i
= 0; i
< ATH_PCI_RESET_WAIT_MAX
; i
++) {
2447 if (ath10k_pci_reg_read32(ar
, RTC_STATE_ADDRESS
) &
2448 RTC_STATE_COLD_RESET_MASK
)
2453 /* Pull Target, including PCIe, out of RESET. */
2455 ath10k_pci_reg_write32(ar
, SOC_GLOBAL_RESET_ADDRESS
, val
);
2457 for (i
= 0; i
< ATH_PCI_RESET_WAIT_MAX
; i
++) {
2458 if (!(ath10k_pci_reg_read32(ar
, RTC_STATE_ADDRESS
) &
2459 RTC_STATE_COLD_RESET_MASK
))
2464 ath10k_do_pci_sleep(ar
);
2468 static void ath10k_pci_dump_features(struct ath10k_pci
*ar_pci
)
2472 for (i
= 0; i
< ATH10K_PCI_FEATURE_COUNT
; i
++) {
2473 if (!test_bit(i
, ar_pci
->features
))
2477 case ATH10K_PCI_FEATURE_MSI_X
:
2478 ath10k_dbg(ATH10K_DBG_BOOT
, "device supports MSI-X\n");
2480 case ATH10K_PCI_FEATURE_SOC_POWER_SAVE
:
2481 ath10k_dbg(ATH10K_DBG_BOOT
, "QCA98XX SoC power save enabled\n");
2487 static int ath10k_pci_probe(struct pci_dev
*pdev
,
2488 const struct pci_device_id
*pci_dev
)
2493 struct ath10k_pci
*ar_pci
;
2494 u32 lcr_val
, chip_id
;
2496 ath10k_dbg(ATH10K_DBG_PCI
, "%s\n", __func__
);
2498 ar_pci
= kzalloc(sizeof(*ar_pci
), GFP_KERNEL
);
2502 ar_pci
->pdev
= pdev
;
2503 ar_pci
->dev
= &pdev
->dev
;
2505 switch (pci_dev
->device
) {
2506 case QCA988X_2_0_DEVICE_ID
:
2507 set_bit(ATH10K_PCI_FEATURE_MSI_X
, ar_pci
->features
);
2511 ath10k_err("Unkown device ID: %d\n", pci_dev
->device
);
2515 if (ath10k_target_ps
)
2516 set_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE
, ar_pci
->features
);
2518 ath10k_pci_dump_features(ar_pci
);
2520 ar
= ath10k_core_create(ar_pci
, ar_pci
->dev
, &ath10k_pci_hif_ops
);
2522 ath10k_err("failed to create driver core\n");
2528 ar_pci
->fw_indicator_address
= FW_INDICATOR_ADDRESS
;
2529 atomic_set(&ar_pci
->keep_awake_count
, 0);
2531 pci_set_drvdata(pdev
, ar
);
2534 * Without any knowledge of the Host, the Target may have been reset or
2535 * power cycled and its Config Space may no longer reflect the PCI
2536 * address space that was assigned earlier by the PCI infrastructure.
2539 ret
= pci_assign_resource(pdev
, BAR_NUM
);
2541 ath10k_err("failed to assign PCI space: %d\n", ret
);
2545 ret
= pci_enable_device(pdev
);
2547 ath10k_err("failed to enable PCI device: %d\n", ret
);
2551 /* Request MMIO resources */
2552 ret
= pci_request_region(pdev
, BAR_NUM
, "ath");
2554 ath10k_err("failed to request MMIO region: %d\n", ret
);
2559 * Target structures have a limit of 32 bit DMA pointers.
2560 * DMA pointers can be wider than 32 bits by default on some systems.
2562 ret
= pci_set_dma_mask(pdev
, DMA_BIT_MASK(32));
2564 ath10k_err("failed to set DMA mask to 32-bit: %d\n", ret
);
2568 ret
= pci_set_consistent_dma_mask(pdev
, DMA_BIT_MASK(32));
2570 ath10k_err("failed to set consistent DMA mask to 32-bit\n");
2574 /* Set bus master bit in PCI_COMMAND to enable DMA */
2575 pci_set_master(pdev
);
2578 * Temporary FIX: disable ASPM
2579 * Will be removed after the OTP is programmed
2581 pci_read_config_dword(pdev
, 0x80, &lcr_val
);
2582 pci_write_config_dword(pdev
, 0x80, (lcr_val
& 0xffffff00));
2584 /* Arrange for access to Target SoC registers. */
2585 mem
= pci_iomap(pdev
, BAR_NUM
, 0);
2587 ath10k_err("failed to perform IOMAP for BAR%d\n", BAR_NUM
);
2594 spin_lock_init(&ar_pci
->ce_lock
);
2596 ret
= ath10k_do_pci_wake(ar
);
2598 ath10k_err("Failed to get chip id: %d\n", ret
);
2602 chip_id
= ath10k_pci_soc_read32(ar
, SOC_CHIP_ID_ADDRESS
);
2604 ath10k_do_pci_sleep(ar
);
2606 ath10k_dbg(ATH10K_DBG_BOOT
, "boot pci_mem 0x%p\n", ar_pci
->mem
);
2608 ret
= ath10k_core_register(ar
, chip_id
);
2610 ath10k_err("failed to register driver core: %d\n", ret
);
2617 pci_iounmap(pdev
, mem
);
2619 pci_clear_master(pdev
);
2621 pci_release_region(pdev
, BAR_NUM
);
2623 pci_disable_device(pdev
);
2625 ath10k_core_destroy(ar
);
2627 /* call HIF PCI free here */
2633 static void ath10k_pci_remove(struct pci_dev
*pdev
)
2635 struct ath10k
*ar
= pci_get_drvdata(pdev
);
2636 struct ath10k_pci
*ar_pci
;
2638 ath10k_dbg(ATH10K_DBG_PCI
, "%s\n", __func__
);
2643 ar_pci
= ath10k_pci_priv(ar
);
2648 tasklet_kill(&ar_pci
->msi_fw_err
);
2650 ath10k_core_unregister(ar
);
2652 pci_iounmap(pdev
, ar_pci
->mem
);
2653 pci_release_region(pdev
, BAR_NUM
);
2654 pci_clear_master(pdev
);
2655 pci_disable_device(pdev
);
2657 ath10k_core_destroy(ar
);
2661 MODULE_DEVICE_TABLE(pci
, ath10k_pci_id_table
);
2663 static struct pci_driver ath10k_pci_driver
= {
2664 .name
= "ath10k_pci",
2665 .id_table
= ath10k_pci_id_table
,
2666 .probe
= ath10k_pci_probe
,
2667 .remove
= ath10k_pci_remove
,
2670 static int __init
ath10k_pci_init(void)
2674 ret
= pci_register_driver(&ath10k_pci_driver
);
2676 ath10k_err("failed to register PCI driver: %d\n", ret
);
2680 module_init(ath10k_pci_init
);
2682 static void __exit
ath10k_pci_exit(void)
2684 pci_unregister_driver(&ath10k_pci_driver
);
2687 module_exit(ath10k_pci_exit
);
2689 MODULE_AUTHOR("Qualcomm Atheros");
2690 MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
2691 MODULE_LICENSE("Dual BSD/GPL");
2692 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR
"/" QCA988X_HW_2_0_FW_FILE
);
2693 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR
"/" QCA988X_HW_2_0_OTP_FILE
);
2694 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR
"/" QCA988X_HW_2_0_BOARD_DATA_FILE
);