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;
923 /* Mark pending completions as aborted, so that upper layers free up
924 * their associated resources */
925 spin_lock_bh(&ar_pci->compl_lock);
926 list_for_each_entry(compl, &ar_pci->compl_process, list) {
928 ATH10K_SKB_CB(skb)->is_aborted = true;
930 spin_unlock_bh(&ar_pci->compl_lock);
933 static void ath10k_pci_cleanup_ce(struct ath10k *ar)
935 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
936 struct ath10k_pci_compl *compl, *tmp;
937 struct ath10k_pci_pipe *pipe_info;
938 struct sk_buff *netbuf;
941 /* Free pending completions. */
942 spin_lock_bh(&ar_pci->compl_lock);
943 if (!list_empty(&ar_pci->compl_process))
944 ath10k_warn("pending completions still present! possible memory leaks.\n");
946 list_for_each_entry_safe(compl, tmp, &ar_pci->compl_process, list) {
947 list_del(&compl->list);
949 dev_kfree_skb_any(netbuf);
952 spin_unlock_bh(&ar_pci->compl_lock);
954 /* Free unused completions for each pipe. */
955 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
956 pipe_info = &ar_pci->pipe_info[pipe_num];
958 spin_lock_bh(&pipe_info->pipe_lock);
959 list_for_each_entry_safe(compl, tmp,
960 &pipe_info->compl_free, list) {
961 list_del(&compl->list);
964 spin_unlock_bh(&pipe_info->pipe_lock);
968 static void ath10k_pci_process_ce(struct ath10k *ar)
970 struct ath10k_pci *ar_pci = ar->hif.priv;
971 struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current;
972 struct ath10k_pci_compl *compl;
975 int ret, send_done = 0;
977 /* Upper layers aren't ready to handle tx/rx completions in parallel so
978 * we must serialize all completion processing. */
980 spin_lock_bh(&ar_pci->compl_lock);
981 if (ar_pci->compl_processing) {
982 spin_unlock_bh(&ar_pci->compl_lock);
985 ar_pci->compl_processing = true;
986 spin_unlock_bh(&ar_pci->compl_lock);
989 spin_lock_bh(&ar_pci->compl_lock);
990 if (list_empty(&ar_pci->compl_process)) {
991 spin_unlock_bh(&ar_pci->compl_lock);
994 compl = list_first_entry(&ar_pci->compl_process,
995 struct ath10k_pci_compl, list);
996 list_del(&compl->list);
997 spin_unlock_bh(&ar_pci->compl_lock);
999 switch (compl->state) {
1000 case ATH10K_PCI_COMPL_SEND:
1001 cb->tx_completion(ar,
1003 compl->transfer_id);
1006 case ATH10K_PCI_COMPL_RECV:
1007 ret = ath10k_pci_post_rx_pipe(compl->pipe_info, 1);
1009 ath10k_warn("failed to post RX buffer for pipe %d: %d\n",
1010 compl->pipe_info->pipe_num, ret);
1015 nbytes = compl->nbytes;
1017 ath10k_dbg(ATH10K_DBG_PCI,
1018 "ath10k_pci_ce_recv_data netbuf=%p nbytes=%d\n",
1020 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP, NULL,
1021 "ath10k rx: ", skb->data, nbytes);
1023 if (skb->len + skb_tailroom(skb) >= nbytes) {
1025 skb_put(skb, nbytes);
1026 cb->rx_completion(ar, skb,
1027 compl->pipe_info->pipe_num);
1029 ath10k_warn("rxed more than expected (nbytes %d, max %d)",
1031 skb->len + skb_tailroom(skb));
1034 case ATH10K_PCI_COMPL_FREE:
1035 ath10k_warn("free completion cannot be processed\n");
1038 ath10k_warn("invalid completion state (%d)\n",
1043 compl->state = ATH10K_PCI_COMPL_FREE;
1046 * Add completion back to the pipe's free list.
1048 spin_lock_bh(&compl->pipe_info->pipe_lock);
1049 list_add_tail(&compl->list, &compl->pipe_info->compl_free);
1050 spin_unlock_bh(&compl->pipe_info->pipe_lock);
1053 spin_lock_bh(&ar_pci->compl_lock);
1054 ar_pci->compl_processing = false;
1055 spin_unlock_bh(&ar_pci->compl_lock);
1058 /* TODO - temporary mapping while we have too few CE's */
1059 static int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar,
1060 u16 service_id, u8 *ul_pipe,
1061 u8 *dl_pipe, int *ul_is_polled,
1066 /* polling for received messages not supported */
1069 switch (service_id) {
1070 case ATH10K_HTC_SVC_ID_HTT_DATA_MSG:
1072 * Host->target HTT gets its own pipe, so it can be polled
1073 * while other pipes are interrupt driven.
1077 * Use the same target->host pipe for HTC ctrl, HTC raw
1083 case ATH10K_HTC_SVC_ID_RSVD_CTRL:
1084 case ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS:
1086 * Note: HTC_RAW_STREAMS_SVC is currently unused, and
1087 * HTC_CTRL_RSVD_SVC could share the same pipe as the
1088 * WMI services. So, if another CE is needed, change
1089 * this to *ul_pipe = 3, which frees up CE 0.
1096 case ATH10K_HTC_SVC_ID_WMI_DATA_BK:
1097 case ATH10K_HTC_SVC_ID_WMI_DATA_BE:
1098 case ATH10K_HTC_SVC_ID_WMI_DATA_VI:
1099 case ATH10K_HTC_SVC_ID_WMI_DATA_VO:
1101 case ATH10K_HTC_SVC_ID_WMI_CONTROL:
1107 /* pipe 6 reserved */
1108 /* pipe 7 reserved */
1115 (host_ce_config_wlan[*ul_pipe].flags & CE_ATTR_DIS_INTR) != 0;
1120 static void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1121 u8 *ul_pipe, u8 *dl_pipe)
1123 int ul_is_polled, dl_is_polled;
1125 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1126 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1133 static int ath10k_pci_post_rx_pipe(struct ath10k_pci_pipe *pipe_info,
1136 struct ath10k *ar = pipe_info->hif_ce_state;
1137 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1138 struct ath10k_ce_pipe *ce_state = pipe_info->ce_hdl;
1139 struct sk_buff *skb;
1143 if (pipe_info->buf_sz == 0)
1146 for (i = 0; i < num; i++) {
1147 skb = dev_alloc_skb(pipe_info->buf_sz);
1149 ath10k_warn("failed to allocate skbuff for pipe %d\n",
1155 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
1157 ce_data = dma_map_single(ar->dev, skb->data,
1158 skb->len + skb_tailroom(skb),
1161 if (unlikely(dma_mapping_error(ar->dev, ce_data))) {
1162 ath10k_warn("failed to DMA map sk_buff\n");
1163 dev_kfree_skb_any(skb);
1168 ATH10K_SKB_CB(skb)->paddr = ce_data;
1170 pci_dma_sync_single_for_device(ar_pci->pdev, ce_data,
1172 PCI_DMA_FROMDEVICE);
1174 ret = ath10k_ce_recv_buf_enqueue(ce_state, (void *)skb,
1177 ath10k_warn("failed to enqueue to pipe %d: %d\n",
1186 ath10k_pci_rx_pipe_cleanup(pipe_info);
1190 static int ath10k_pci_post_rx(struct ath10k *ar)
1192 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1193 struct ath10k_pci_pipe *pipe_info;
1194 const struct ce_attr *attr;
1195 int pipe_num, ret = 0;
1197 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1198 pipe_info = &ar_pci->pipe_info[pipe_num];
1199 attr = &host_ce_config_wlan[pipe_num];
1201 if (attr->dest_nentries == 0)
1204 ret = ath10k_pci_post_rx_pipe(pipe_info,
1205 attr->dest_nentries - 1);
1207 ath10k_warn("failed to post RX buffer for pipe %d: %d\n",
1210 for (; pipe_num >= 0; pipe_num--) {
1211 pipe_info = &ar_pci->pipe_info[pipe_num];
1212 ath10k_pci_rx_pipe_cleanup(pipe_info);
1221 static int ath10k_pci_hif_start(struct ath10k *ar)
1223 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1226 ret = ath10k_pci_alloc_compl(ar);
1228 ath10k_warn("failed to allocate CE completions: %d\n", ret);
1232 ret = ath10k_pci_request_irq(ar);
1234 ath10k_warn("failed to post RX buffers for all pipes: %d\n",
1236 goto err_free_compl;
1239 ret = ath10k_pci_setup_ce_irq(ar);
1241 ath10k_warn("failed to setup CE interrupts: %d\n", ret);
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_ce_disable_interrupts(ar);
1258 ath10k_pci_free_irq(ar);
1259 ath10k_pci_kill_tasklet(ar);
1260 ath10k_pci_stop_ce(ar);
1261 ath10k_pci_process_ce(ar);
1263 ath10k_pci_cleanup_ce(ar);
1267 static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info)
1270 struct ath10k_pci *ar_pci;
1271 struct ath10k_ce_pipe *ce_hdl;
1273 struct sk_buff *netbuf;
1276 buf_sz = pipe_info->buf_sz;
1278 /* Unused Copy Engine */
1282 ar = pipe_info->hif_ce_state;
1283 ar_pci = ath10k_pci_priv(ar);
1285 if (!ar_pci->started)
1288 ce_hdl = pipe_info->ce_hdl;
1290 while (ath10k_ce_revoke_recv_next(ce_hdl, (void **)&netbuf,
1292 dma_unmap_single(ar->dev, ATH10K_SKB_CB(netbuf)->paddr,
1293 netbuf->len + skb_tailroom(netbuf),
1295 dev_kfree_skb_any(netbuf);
1299 static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info)
1302 struct ath10k_pci *ar_pci;
1303 struct ath10k_ce_pipe *ce_hdl;
1304 struct sk_buff *netbuf;
1306 unsigned int nbytes;
1310 buf_sz = pipe_info->buf_sz;
1312 /* Unused Copy Engine */
1316 ar = pipe_info->hif_ce_state;
1317 ar_pci = ath10k_pci_priv(ar);
1319 if (!ar_pci->started)
1322 ce_hdl = pipe_info->ce_hdl;
1324 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf,
1325 &ce_data, &nbytes, &id) == 0) {
1327 * Indicate the completion to higer layer to free
1332 ath10k_warn("invalid sk_buff on CE %d - NULL pointer. firmware crashed?\n",
1337 ATH10K_SKB_CB(netbuf)->is_aborted = true;
1338 ar_pci->msg_callbacks_current.tx_completion(ar,
1345 * Cleanup residual buffers for device shutdown:
1346 * buffers that were enqueued for receive
1347 * buffers that were to be sent
1348 * Note: Buffers that had completed but which were
1349 * not yet processed are on a completion queue. They
1350 * are handled when the completion thread shuts down.
1352 static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1354 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1357 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1358 struct ath10k_pci_pipe *pipe_info;
1360 pipe_info = &ar_pci->pipe_info[pipe_num];
1361 ath10k_pci_rx_pipe_cleanup(pipe_info);
1362 ath10k_pci_tx_pipe_cleanup(pipe_info);
1366 static void ath10k_pci_ce_deinit(struct ath10k *ar)
1368 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1369 struct ath10k_pci_pipe *pipe_info;
1372 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1373 pipe_info = &ar_pci->pipe_info[pipe_num];
1374 if (pipe_info->ce_hdl) {
1375 ath10k_ce_deinit(pipe_info->ce_hdl);
1376 pipe_info->ce_hdl = NULL;
1377 pipe_info->buf_sz = 0;
1382 static void ath10k_pci_hif_stop(struct ath10k *ar)
1384 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1387 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
1389 ret = ath10k_ce_disable_interrupts(ar);
1391 ath10k_warn("failed to disable CE interrupts: %d\n", ret);
1393 ath10k_pci_free_irq(ar);
1394 ath10k_pci_kill_tasklet(ar);
1395 ath10k_pci_stop_ce(ar);
1397 /* At this point, asynchronous threads are stopped, the target should
1398 * not DMA nor interrupt. We process the leftovers and then free
1399 * everything else up. */
1401 ath10k_pci_process_ce(ar);
1402 ath10k_pci_cleanup_ce(ar);
1403 ath10k_pci_buffer_cleanup(ar);
1405 /* Make the sure the device won't access any structures on the host by
1406 * resetting it. The device was fed with PCI CE ringbuffer
1407 * configuration during init. If ringbuffers are freed and the device
1408 * were to access them this could lead to memory corruption on the
1410 ath10k_pci_device_reset(ar);
1412 ar_pci->started = 0;
1415 static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1416 void *req, u32 req_len,
1417 void *resp, u32 *resp_len)
1419 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1420 struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1421 struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1422 struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl;
1423 struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl;
1424 dma_addr_t req_paddr = 0;
1425 dma_addr_t resp_paddr = 0;
1426 struct bmi_xfer xfer = {};
1427 void *treq, *tresp = NULL;
1432 if (resp && !resp_len)
1435 if (resp && resp_len && *resp_len == 0)
1438 treq = kmemdup(req, req_len, GFP_KERNEL);
1442 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1443 ret = dma_mapping_error(ar->dev, req_paddr);
1447 if (resp && resp_len) {
1448 tresp = kzalloc(*resp_len, GFP_KERNEL);
1454 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1456 ret = dma_mapping_error(ar->dev, resp_paddr);
1460 xfer.wait_for_resp = true;
1463 ath10k_ce_recv_buf_enqueue(ce_rx, &xfer, resp_paddr);
1466 init_completion(&xfer.done);
1468 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1472 ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer);
1475 unsigned int unused_nbytes;
1476 unsigned int unused_id;
1478 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1479 &unused_nbytes, &unused_id);
1481 /* non-zero means we did not time out */
1489 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1490 dma_unmap_single(ar->dev, resp_paddr,
1491 *resp_len, DMA_FROM_DEVICE);
1494 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1496 if (ret == 0 && resp_len) {
1497 *resp_len = min(*resp_len, xfer.resp_len);
1498 memcpy(resp, tresp, xfer.resp_len);
1507 static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state)
1509 struct bmi_xfer *xfer;
1511 unsigned int nbytes;
1512 unsigned int transfer_id;
1514 if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer, &ce_data,
1515 &nbytes, &transfer_id))
1518 if (xfer->wait_for_resp)
1521 complete(&xfer->done);
1524 static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state)
1526 struct bmi_xfer *xfer;
1528 unsigned int nbytes;
1529 unsigned int transfer_id;
1532 if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer, &ce_data,
1533 &nbytes, &transfer_id, &flags))
1536 if (!xfer->wait_for_resp) {
1537 ath10k_warn("unexpected: BMI data received; ignoring\n");
1541 xfer->resp_len = nbytes;
1542 complete(&xfer->done);
1545 static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe,
1546 struct ath10k_ce_pipe *rx_pipe,
1547 struct bmi_xfer *xfer)
1549 unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ;
1551 while (time_before_eq(jiffies, timeout)) {
1552 ath10k_pci_bmi_send_done(tx_pipe);
1553 ath10k_pci_bmi_recv_data(rx_pipe);
1555 if (completion_done(&xfer->done))
1565 * Map from service/endpoint to Copy Engine.
1566 * This table is derived from the CE_PCI TABLE, above.
1567 * It is passed to the Target at startup for use by firmware.
1569 static const struct service_to_pipe target_service_to_ce_map_wlan[] = {
1571 ATH10K_HTC_SVC_ID_WMI_DATA_VO,
1572 PIPEDIR_OUT, /* out = UL = host -> target */
1576 ATH10K_HTC_SVC_ID_WMI_DATA_VO,
1577 PIPEDIR_IN, /* in = DL = target -> host */
1581 ATH10K_HTC_SVC_ID_WMI_DATA_BK,
1582 PIPEDIR_OUT, /* out = UL = host -> target */
1586 ATH10K_HTC_SVC_ID_WMI_DATA_BK,
1587 PIPEDIR_IN, /* in = DL = target -> host */
1591 ATH10K_HTC_SVC_ID_WMI_DATA_BE,
1592 PIPEDIR_OUT, /* out = UL = host -> target */
1596 ATH10K_HTC_SVC_ID_WMI_DATA_BE,
1597 PIPEDIR_IN, /* in = DL = target -> host */
1601 ATH10K_HTC_SVC_ID_WMI_DATA_VI,
1602 PIPEDIR_OUT, /* out = UL = host -> target */
1606 ATH10K_HTC_SVC_ID_WMI_DATA_VI,
1607 PIPEDIR_IN, /* in = DL = target -> host */
1611 ATH10K_HTC_SVC_ID_WMI_CONTROL,
1612 PIPEDIR_OUT, /* out = UL = host -> target */
1616 ATH10K_HTC_SVC_ID_WMI_CONTROL,
1617 PIPEDIR_IN, /* in = DL = target -> host */
1621 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1622 PIPEDIR_OUT, /* out = UL = host -> target */
1623 0, /* could be moved to 3 (share with WMI) */
1626 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1627 PIPEDIR_IN, /* in = DL = target -> host */
1631 ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS, /* not currently used */
1632 PIPEDIR_OUT, /* out = UL = host -> target */
1636 ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS, /* not currently used */
1637 PIPEDIR_IN, /* in = DL = target -> host */
1641 ATH10K_HTC_SVC_ID_HTT_DATA_MSG,
1642 PIPEDIR_OUT, /* out = UL = host -> target */
1646 ATH10K_HTC_SVC_ID_HTT_DATA_MSG,
1647 PIPEDIR_IN, /* in = DL = target -> host */
1651 /* (Additions here) */
1653 { /* Must be last */
1661 * Send an interrupt to the device to wake up the Target CPU
1662 * so it has an opportunity to notice any changed state.
1664 static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1669 ret = ath10k_pci_diag_read_access(ar, SOC_CORE_BASE_ADDRESS |
1673 ath10k_warn("failed to read core_ctrl: %d\n", ret);
1677 /* A_INUM_FIRMWARE interrupt to Target CPU */
1678 core_ctrl |= CORE_CTRL_CPU_INTR_MASK;
1680 ret = ath10k_pci_diag_write_access(ar, SOC_CORE_BASE_ADDRESS |
1684 ath10k_warn("failed to set target CPU interrupt mask: %d\n",
1692 static int ath10k_pci_init_config(struct ath10k *ar)
1694 u32 interconnect_targ_addr;
1695 u32 pcie_state_targ_addr = 0;
1696 u32 pipe_cfg_targ_addr = 0;
1697 u32 svc_to_pipe_map = 0;
1698 u32 pcie_config_flags = 0;
1700 u32 ealloc_targ_addr;
1702 u32 flag2_targ_addr;
1705 /* Download to Target the CE Config and the service-to-CE map */
1706 interconnect_targ_addr =
1707 host_interest_item_address(HI_ITEM(hi_interconnect_state));
1709 /* Supply Target-side CE configuration */
1710 ret = ath10k_pci_diag_read_access(ar, interconnect_targ_addr,
1711 &pcie_state_targ_addr);
1713 ath10k_err("Failed to get pcie state addr: %d\n", ret);
1717 if (pcie_state_targ_addr == 0) {
1719 ath10k_err("Invalid pcie state addr\n");
1723 ret = ath10k_pci_diag_read_access(ar, pcie_state_targ_addr +
1724 offsetof(struct pcie_state,
1726 &pipe_cfg_targ_addr);
1728 ath10k_err("Failed to get pipe cfg addr: %d\n", ret);
1732 if (pipe_cfg_targ_addr == 0) {
1734 ath10k_err("Invalid pipe cfg addr\n");
1738 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
1739 target_ce_config_wlan,
1740 sizeof(target_ce_config_wlan));
1743 ath10k_err("Failed to write pipe cfg: %d\n", ret);
1747 ret = ath10k_pci_diag_read_access(ar, pcie_state_targ_addr +
1748 offsetof(struct pcie_state,
1752 ath10k_err("Failed to get svc/pipe map: %d\n", ret);
1756 if (svc_to_pipe_map == 0) {
1758 ath10k_err("Invalid svc_to_pipe map\n");
1762 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
1763 target_service_to_ce_map_wlan,
1764 sizeof(target_service_to_ce_map_wlan));
1766 ath10k_err("Failed to write svc/pipe map: %d\n", ret);
1770 ret = ath10k_pci_diag_read_access(ar, pcie_state_targ_addr +
1771 offsetof(struct pcie_state,
1773 &pcie_config_flags);
1775 ath10k_err("Failed to get pcie config_flags: %d\n", ret);
1779 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
1781 ret = ath10k_pci_diag_write_mem(ar, pcie_state_targ_addr +
1782 offsetof(struct pcie_state, config_flags),
1784 sizeof(pcie_config_flags));
1786 ath10k_err("Failed to write pcie config_flags: %d\n", ret);
1790 /* configure early allocation */
1791 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
1793 ret = ath10k_pci_diag_read_access(ar, ealloc_targ_addr, &ealloc_value);
1795 ath10k_err("Faile to get early alloc val: %d\n", ret);
1799 /* first bank is switched to IRAM */
1800 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
1801 HI_EARLY_ALLOC_MAGIC_MASK);
1802 ealloc_value |= ((1 << HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
1803 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
1805 ret = ath10k_pci_diag_write_access(ar, ealloc_targ_addr, ealloc_value);
1807 ath10k_err("Failed to set early alloc val: %d\n", ret);
1811 /* Tell Target to proceed with initialization */
1812 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
1814 ret = ath10k_pci_diag_read_access(ar, flag2_targ_addr, &flag2_value);
1816 ath10k_err("Failed to get option val: %d\n", ret);
1820 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
1822 ret = ath10k_pci_diag_write_access(ar, flag2_targ_addr, flag2_value);
1824 ath10k_err("Failed to set option val: %d\n", ret);
1833 static int ath10k_pci_ce_init(struct ath10k *ar)
1835 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1836 struct ath10k_pci_pipe *pipe_info;
1837 const struct ce_attr *attr;
1840 for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) {
1841 pipe_info = &ar_pci->pipe_info[pipe_num];
1842 pipe_info->pipe_num = pipe_num;
1843 pipe_info->hif_ce_state = ar;
1844 attr = &host_ce_config_wlan[pipe_num];
1846 pipe_info->ce_hdl = ath10k_ce_init(ar, pipe_num, attr);
1847 if (pipe_info->ce_hdl == NULL) {
1848 ath10k_err("failed to initialize CE for pipe: %d\n",
1851 /* It is safe to call it here. It checks if ce_hdl is
1852 * valid for each pipe */
1853 ath10k_pci_ce_deinit(ar);
1857 if (pipe_num == CE_COUNT - 1) {
1859 * Reserve the ultimate CE for
1860 * diagnostic Window support
1862 ar_pci->ce_diag = pipe_info->ce_hdl;
1866 pipe_info->buf_sz = (size_t) (attr->src_sz_max);
1872 static void ath10k_pci_fw_interrupt_handler(struct ath10k *ar)
1874 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1875 u32 fw_indicator_address, fw_indicator;
1877 ath10k_pci_wake(ar);
1879 fw_indicator_address = ar_pci->fw_indicator_address;
1880 fw_indicator = ath10k_pci_read32(ar, fw_indicator_address);
1882 if (fw_indicator & FW_IND_EVENT_PENDING) {
1883 /* ACK: clear Target-side pending event */
1884 ath10k_pci_write32(ar, fw_indicator_address,
1885 fw_indicator & ~FW_IND_EVENT_PENDING);
1887 if (ar_pci->started) {
1888 ath10k_pci_hif_dump_area(ar);
1891 * Probable Target failure before we're prepared
1892 * to handle it. Generally unexpected.
1894 ath10k_warn("early firmware event indicated\n");
1898 ath10k_pci_sleep(ar);
1901 static int ath10k_pci_hif_power_up(struct ath10k *ar)
1903 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1904 const char *irq_mode;
1908 * Bring the target up cleanly.
1910 * The target may be in an undefined state with an AUX-powered Target
1911 * and a Host in WoW mode. If the Host crashes, loses power, or is
1912 * restarted (without unloading the driver) then the Target is left
1913 * (aux) powered and running. On a subsequent driver load, the Target
1914 * is in an unexpected state. We try to catch that here in order to
1915 * reset the Target and retry the probe.
1917 ret = ath10k_pci_device_reset(ar);
1919 ath10k_err("failed to reset target: %d\n", ret);
1923 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
1924 /* Force AWAKE forever */
1925 ath10k_do_pci_wake(ar);
1927 ret = ath10k_pci_ce_init(ar);
1929 ath10k_err("failed to initialize CE: %d\n", ret);
1933 ret = ath10k_ce_disable_interrupts(ar);
1935 ath10k_err("failed to disable CE interrupts: %d\n", ret);
1939 ret = ath10k_pci_init_irq(ar);
1941 ath10k_err("failed to init irqs: %d\n", ret);
1945 ret = ath10k_pci_wait_for_target_init(ar);
1947 ath10k_err("failed to wait for target to init: %d\n", ret);
1948 goto err_deinit_irq;
1951 ret = ath10k_pci_init_config(ar);
1953 ath10k_err("failed to setup init config: %d\n", ret);
1954 goto err_deinit_irq;
1957 ret = ath10k_pci_wake_target_cpu(ar);
1959 ath10k_err("could not wake up target CPU: %d\n", ret);
1960 goto err_deinit_irq;
1963 if (ar_pci->num_msi_intrs > 1)
1965 else if (ar_pci->num_msi_intrs == 1)
1968 irq_mode = "legacy";
1970 if (!test_bit(ATH10K_FLAG_FIRST_BOOT_DONE, &ar->dev_flags))
1971 ath10k_info("pci irq %s\n", irq_mode);
1976 ath10k_pci_deinit_irq(ar);
1978 ath10k_pci_ce_deinit(ar);
1979 ath10k_pci_device_reset(ar);
1981 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
1982 ath10k_do_pci_sleep(ar);
1987 static void ath10k_pci_hif_power_down(struct ath10k *ar)
1989 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1991 ath10k_pci_deinit_irq(ar);
1992 ath10k_pci_device_reset(ar);
1994 ath10k_pci_ce_deinit(ar);
1995 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
1996 ath10k_do_pci_sleep(ar);
2001 #define ATH10K_PCI_PM_CONTROL 0x44
2003 static int ath10k_pci_hif_suspend(struct ath10k *ar)
2005 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2006 struct pci_dev *pdev = ar_pci->pdev;
2009 pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val);
2011 if ((val & 0x000000ff) != 0x3) {
2012 pci_save_state(pdev);
2013 pci_disable_device(pdev);
2014 pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
2015 (val & 0xffffff00) | 0x03);
2021 static int ath10k_pci_hif_resume(struct ath10k *ar)
2023 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2024 struct pci_dev *pdev = ar_pci->pdev;
2027 pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val);
2029 if ((val & 0x000000ff) != 0) {
2030 pci_restore_state(pdev);
2031 pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
2034 * Suspend/Resume resets the PCI configuration space,
2035 * so we have to re-disable the RETRY_TIMEOUT register (0x41)
2036 * to keep PCI Tx retries from interfering with C3 CPU state
2038 pci_read_config_dword(pdev, 0x40, &val);
2040 if ((val & 0x0000ff00) != 0)
2041 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
2048 static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
2049 .send_head = ath10k_pci_hif_send_head,
2050 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
2051 .start = ath10k_pci_hif_start,
2052 .stop = ath10k_pci_hif_stop,
2053 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
2054 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
2055 .send_complete_check = ath10k_pci_hif_send_complete_check,
2056 .set_callbacks = ath10k_pci_hif_set_callbacks,
2057 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
2058 .power_up = ath10k_pci_hif_power_up,
2059 .power_down = ath10k_pci_hif_power_down,
2061 .suspend = ath10k_pci_hif_suspend,
2062 .resume = ath10k_pci_hif_resume,
2066 static void ath10k_pci_ce_tasklet(unsigned long ptr)
2068 struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr;
2069 struct ath10k_pci *ar_pci = pipe->ar_pci;
2071 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
2074 static void ath10k_msi_err_tasklet(unsigned long data)
2076 struct ath10k *ar = (struct ath10k *)data;
2078 ath10k_pci_fw_interrupt_handler(ar);
2082 * Handler for a per-engine interrupt on a PARTICULAR CE.
2083 * This is used in cases where each CE has a private MSI interrupt.
2085 static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg)
2087 struct ath10k *ar = arg;
2088 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2089 int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL;
2091 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) {
2092 ath10k_warn("unexpected/invalid irq %d ce_id %d\n", irq, ce_id);
2097 * NOTE: We are able to derive ce_id from irq because we
2098 * use a one-to-one mapping for CE's 0..5.
2099 * CE's 6 & 7 do not use interrupts at all.
2101 * This mapping must be kept in sync with the mapping
2104 tasklet_schedule(&ar_pci->pipe_info[ce_id].intr);
2108 static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg)
2110 struct ath10k *ar = arg;
2111 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2113 tasklet_schedule(&ar_pci->msi_fw_err);
2118 * Top-level interrupt handler for all PCI interrupts from a Target.
2119 * When a block of MSI interrupts is allocated, this top-level handler
2120 * is not used; instead, we directly call the correct sub-handler.
2122 static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
2124 struct ath10k *ar = arg;
2125 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2127 if (ar_pci->num_msi_intrs == 0) {
2128 if (!ath10k_pci_irq_pending(ar))
2132 * IMPORTANT: INTR_CLR regiser has to be set after
2133 * INTR_ENABLE is set to 0, otherwise interrupt can not be
2136 iowrite32(0, ar_pci->mem +
2137 (SOC_CORE_BASE_ADDRESS |
2138 PCIE_INTR_ENABLE_ADDRESS));
2139 iowrite32(PCIE_INTR_FIRMWARE_MASK |
2140 PCIE_INTR_CE_MASK_ALL,
2141 ar_pci->mem + (SOC_CORE_BASE_ADDRESS |
2142 PCIE_INTR_CLR_ADDRESS));
2144 * IMPORTANT: this extra read transaction is required to
2145 * flush the posted write buffer.
2147 (void) ioread32(ar_pci->mem +
2148 (SOC_CORE_BASE_ADDRESS |
2149 PCIE_INTR_ENABLE_ADDRESS));
2152 tasklet_schedule(&ar_pci->intr_tq);
2157 static void ath10k_pci_tasklet(unsigned long data)
2159 struct ath10k *ar = (struct ath10k *)data;
2160 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2162 ath10k_pci_fw_interrupt_handler(ar); /* FIXME: Handle FW error */
2163 ath10k_ce_per_engine_service_any(ar);
2165 if (ar_pci->num_msi_intrs == 0) {
2166 /* Enable Legacy PCI line interrupts */
2167 iowrite32(PCIE_INTR_FIRMWARE_MASK |
2168 PCIE_INTR_CE_MASK_ALL,
2169 ar_pci->mem + (SOC_CORE_BASE_ADDRESS |
2170 PCIE_INTR_ENABLE_ADDRESS));
2172 * IMPORTANT: this extra read transaction is required to
2173 * flush the posted write buffer
2175 (void) ioread32(ar_pci->mem +
2176 (SOC_CORE_BASE_ADDRESS |
2177 PCIE_INTR_ENABLE_ADDRESS));
2181 static int ath10k_pci_request_irq_msix(struct ath10k *ar)
2183 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2186 ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW,
2187 ath10k_pci_msi_fw_handler,
2188 IRQF_SHARED, "ath10k_pci", ar);
2190 ath10k_warn("failed to request MSI-X fw irq %d: %d\n",
2191 ar_pci->pdev->irq + MSI_ASSIGN_FW, ret);
2195 for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) {
2196 ret = request_irq(ar_pci->pdev->irq + i,
2197 ath10k_pci_per_engine_handler,
2198 IRQF_SHARED, "ath10k_pci", ar);
2200 ath10k_warn("failed to request MSI-X ce irq %d: %d\n",
2201 ar_pci->pdev->irq + i, ret);
2203 for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--)
2204 free_irq(ar_pci->pdev->irq + i, ar);
2206 free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar);
2214 static int ath10k_pci_request_irq_msi(struct ath10k *ar)
2216 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2219 ret = request_irq(ar_pci->pdev->irq,
2220 ath10k_pci_interrupt_handler,
2221 IRQF_SHARED, "ath10k_pci", ar);
2223 ath10k_warn("failed to request MSI irq %d: %d\n",
2224 ar_pci->pdev->irq, ret);
2231 static int ath10k_pci_request_irq_legacy(struct ath10k *ar)
2233 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2236 ret = request_irq(ar_pci->pdev->irq,
2237 ath10k_pci_interrupt_handler,
2238 IRQF_SHARED, "ath10k_pci", ar);
2240 ath10k_warn("failed to request legacy irq %d: %d\n",
2241 ar_pci->pdev->irq, ret);
2248 static int ath10k_pci_request_irq(struct ath10k *ar)
2250 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2252 switch (ar_pci->num_msi_intrs) {
2254 return ath10k_pci_request_irq_legacy(ar);
2256 return ath10k_pci_request_irq_msi(ar);
2257 case MSI_NUM_REQUEST:
2258 return ath10k_pci_request_irq_msix(ar);
2261 ath10k_warn("unknown irq configuration upon request\n");
2265 static void ath10k_pci_free_irq(struct ath10k *ar)
2267 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2270 /* There's at least one interrupt irregardless whether its legacy INTR
2271 * or MSI or MSI-X */
2272 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
2273 free_irq(ar_pci->pdev->irq + i, ar);
2276 static void ath10k_pci_init_irq_tasklets(struct ath10k *ar)
2278 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2281 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar);
2282 tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet,
2285 for (i = 0; i < CE_COUNT; i++) {
2286 ar_pci->pipe_info[i].ar_pci = ar_pci;
2287 tasklet_init(&ar_pci->pipe_info[i].intr, ath10k_pci_ce_tasklet,
2288 (unsigned long)&ar_pci->pipe_info[i]);
2292 static int ath10k_pci_init_irq(struct ath10k *ar)
2294 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2297 ath10k_pci_init_irq_tasklets(ar);
2299 if (!test_bit(ATH10K_PCI_FEATURE_MSI_X, ar_pci->features))
2303 ar_pci->num_msi_intrs = MSI_NUM_REQUEST;
2304 ret = pci_enable_msi_block(ar_pci->pdev, ar_pci->num_msi_intrs);
2308 pci_disable_msi(ar_pci->pdev);
2312 ar_pci->num_msi_intrs = 1;
2313 ret = pci_enable_msi(ar_pci->pdev);
2319 * A potential race occurs here: The CORE_BASE write
2320 * depends on target correctly decoding AXI address but
2321 * host won't know when target writes BAR to CORE_CTRL.
2322 * This write might get lost if target has NOT written BAR.
2323 * For now, fix the race by repeating the write in below
2324 * synchronization checking. */
2325 ar_pci->num_msi_intrs = 0;
2327 ret = ath10k_pci_wake(ar);
2329 ath10k_warn("failed to wake target: %d\n", ret);
2333 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2334 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL);
2335 ath10k_pci_sleep(ar);
2340 static int ath10k_pci_deinit_irq_legacy(struct ath10k *ar)
2344 ret = ath10k_pci_wake(ar);
2346 ath10k_warn("failed to wake target: %d\n", ret);
2350 ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS,
2352 ath10k_pci_sleep(ar);
2357 static int ath10k_pci_deinit_irq(struct ath10k *ar)
2359 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2361 switch (ar_pci->num_msi_intrs) {
2363 return ath10k_pci_deinit_irq_legacy(ar);
2366 case MSI_NUM_REQUEST:
2367 pci_disable_msi(ar_pci->pdev);
2371 ath10k_warn("unknown irq configuration upon deinit\n");
2375 static int ath10k_pci_wait_for_target_init(struct ath10k *ar)
2377 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2378 int wait_limit = 300; /* 3 sec */
2381 ret = ath10k_pci_wake(ar);
2383 ath10k_err("failed to wake up target: %d\n", ret);
2387 while (wait_limit-- &&
2388 !(ioread32(ar_pci->mem + FW_INDICATOR_ADDRESS) &
2389 FW_IND_INITIALIZED)) {
2390 if (ar_pci->num_msi_intrs == 0)
2391 /* Fix potential race by repeating CORE_BASE writes */
2392 iowrite32(PCIE_INTR_FIRMWARE_MASK |
2393 PCIE_INTR_CE_MASK_ALL,
2394 ar_pci->mem + (SOC_CORE_BASE_ADDRESS |
2395 PCIE_INTR_ENABLE_ADDRESS));
2399 if (wait_limit < 0) {
2400 ath10k_err("target stalled\n");
2406 ath10k_pci_sleep(ar);
2410 static int ath10k_pci_device_reset(struct ath10k *ar)
2415 ret = ath10k_do_pci_wake(ar);
2417 ath10k_err("failed to wake up target: %d\n",
2422 /* Put Target, including PCIe, into RESET. */
2423 val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS);
2425 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2427 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2428 if (ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) &
2429 RTC_STATE_COLD_RESET_MASK)
2434 /* Pull Target, including PCIe, out of RESET. */
2436 ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val);
2438 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2439 if (!(ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) &
2440 RTC_STATE_COLD_RESET_MASK))
2445 ath10k_do_pci_sleep(ar);
2449 static void ath10k_pci_dump_features(struct ath10k_pci *ar_pci)
2453 for (i = 0; i < ATH10K_PCI_FEATURE_COUNT; i++) {
2454 if (!test_bit(i, ar_pci->features))
2458 case ATH10K_PCI_FEATURE_MSI_X:
2459 ath10k_dbg(ATH10K_DBG_BOOT, "device supports MSI-X\n");
2461 case ATH10K_PCI_FEATURE_SOC_POWER_SAVE:
2462 ath10k_dbg(ATH10K_DBG_BOOT, "QCA98XX SoC power save enabled\n");
2468 static int ath10k_pci_probe(struct pci_dev *pdev,
2469 const struct pci_device_id *pci_dev)
2474 struct ath10k_pci *ar_pci;
2475 u32 lcr_val, chip_id;
2477 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
2479 ar_pci = kzalloc(sizeof(*ar_pci), GFP_KERNEL);
2483 ar_pci->pdev = pdev;
2484 ar_pci->dev = &pdev->dev;
2486 switch (pci_dev->device) {
2487 case QCA988X_2_0_DEVICE_ID:
2488 set_bit(ATH10K_PCI_FEATURE_MSI_X, ar_pci->features);
2492 ath10k_err("Unkown device ID: %d\n", pci_dev->device);
2496 if (ath10k_target_ps)
2497 set_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features);
2499 ath10k_pci_dump_features(ar_pci);
2501 ar = ath10k_core_create(ar_pci, ar_pci->dev, &ath10k_pci_hif_ops);
2503 ath10k_err("failed to create driver core\n");
2509 ar_pci->fw_indicator_address = FW_INDICATOR_ADDRESS;
2510 atomic_set(&ar_pci->keep_awake_count, 0);
2512 pci_set_drvdata(pdev, ar);
2515 * Without any knowledge of the Host, the Target may have been reset or
2516 * power cycled and its Config Space may no longer reflect the PCI
2517 * address space that was assigned earlier by the PCI infrastructure.
2520 ret = pci_assign_resource(pdev, BAR_NUM);
2522 ath10k_err("failed to assign PCI space: %d\n", ret);
2526 ret = pci_enable_device(pdev);
2528 ath10k_err("failed to enable PCI device: %d\n", ret);
2532 /* Request MMIO resources */
2533 ret = pci_request_region(pdev, BAR_NUM, "ath");
2535 ath10k_err("failed to request MMIO region: %d\n", ret);
2540 * Target structures have a limit of 32 bit DMA pointers.
2541 * DMA pointers can be wider than 32 bits by default on some systems.
2543 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2545 ath10k_err("failed to set DMA mask to 32-bit: %d\n", ret);
2549 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2551 ath10k_err("failed to set consistent DMA mask to 32-bit\n");
2555 /* Set bus master bit in PCI_COMMAND to enable DMA */
2556 pci_set_master(pdev);
2559 * Temporary FIX: disable ASPM
2560 * Will be removed after the OTP is programmed
2562 pci_read_config_dword(pdev, 0x80, &lcr_val);
2563 pci_write_config_dword(pdev, 0x80, (lcr_val & 0xffffff00));
2565 /* Arrange for access to Target SoC registers. */
2566 mem = pci_iomap(pdev, BAR_NUM, 0);
2568 ath10k_err("failed to perform IOMAP for BAR%d\n", BAR_NUM);
2575 spin_lock_init(&ar_pci->ce_lock);
2577 ret = ath10k_do_pci_wake(ar);
2579 ath10k_err("Failed to get chip id: %d\n", ret);
2583 chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS);
2585 ath10k_do_pci_sleep(ar);
2587 ath10k_dbg(ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem);
2589 ret = ath10k_core_register(ar, chip_id);
2591 ath10k_err("failed to register driver core: %d\n", ret);
2598 pci_iounmap(pdev, mem);
2600 pci_clear_master(pdev);
2602 pci_release_region(pdev, BAR_NUM);
2604 pci_disable_device(pdev);
2606 ath10k_core_destroy(ar);
2608 /* call HIF PCI free here */
2614 static void ath10k_pci_remove(struct pci_dev *pdev)
2616 struct ath10k *ar = pci_get_drvdata(pdev);
2617 struct ath10k_pci *ar_pci;
2619 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
2624 ar_pci = ath10k_pci_priv(ar);
2629 tasklet_kill(&ar_pci->msi_fw_err);
2631 ath10k_core_unregister(ar);
2633 pci_iounmap(pdev, ar_pci->mem);
2634 pci_release_region(pdev, BAR_NUM);
2635 pci_clear_master(pdev);
2636 pci_disable_device(pdev);
2638 ath10k_core_destroy(ar);
2642 MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
2644 static struct pci_driver ath10k_pci_driver = {
2645 .name = "ath10k_pci",
2646 .id_table = ath10k_pci_id_table,
2647 .probe = ath10k_pci_probe,
2648 .remove = ath10k_pci_remove,
2651 static int __init ath10k_pci_init(void)
2655 ret = pci_register_driver(&ath10k_pci_driver);
2657 ath10k_err("failed to register PCI driver: %d\n", ret);
2661 module_init(ath10k_pci_init);
2663 static void __exit ath10k_pci_exit(void)
2665 pci_unregister_driver(&ath10k_pci_driver);
2668 module_exit(ath10k_pci_exit);
2670 MODULE_AUTHOR("Qualcomm Atheros");
2671 MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
2672 MODULE_LICENSE("Dual BSD/GPL");
2673 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
2674 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_OTP_FILE);
2675 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);