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>
26 #include "targaddrs.h"
35 static unsigned int ath10k_target_ps;
36 module_param(ath10k_target_ps, uint, 0644);
37 MODULE_PARM_DESC(ath10k_target_ps, "Enable ath10k Target (SoC) PS option");
39 #define QCA988X_2_0_DEVICE_ID (0x003c)
41 static DEFINE_PCI_DEVICE_TABLE(ath10k_pci_id_table) = {
42 { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */
46 static int ath10k_pci_diag_read_access(struct ath10k *ar, u32 address,
49 static void ath10k_pci_process_ce(struct ath10k *ar);
50 static int ath10k_pci_post_rx(struct ath10k *ar);
51 static int ath10k_pci_post_rx_pipe(struct hif_ce_pipe_info *pipe_info,
53 static void ath10k_pci_rx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info);
54 static void ath10k_pci_stop_ce(struct ath10k *ar);
55 static void ath10k_pci_device_reset(struct ath10k *ar);
56 static int ath10k_pci_reset_target(struct ath10k *ar);
57 static int ath10k_pci_start_intr(struct ath10k *ar);
58 static void ath10k_pci_stop_intr(struct ath10k *ar);
60 static const struct ce_attr host_ce_config_wlan[] = {
61 /* host->target HTC control and raw streams */
62 { /* CE0 */ CE_ATTR_FLAGS, 16, 256, 0 },
63 /* could be moved to share CE3 */
64 /* target->host HTT + HTC control */
65 { /* CE1 */ CE_ATTR_FLAGS, 0, 512, 512 },
66 /* target->host WMI */
67 { /* CE2 */ CE_ATTR_FLAGS, 0, 2048, 32 },
68 /* host->target WMI */
69 { /* CE3 */ CE_ATTR_FLAGS, 32, 2048, 0 },
70 /* host->target HTT */
71 { /* CE4 */ CE_ATTR_FLAGS | CE_ATTR_DIS_INTR,
72 CE_HTT_H2T_MSG_SRC_NENTRIES, 256, 0 },
74 { /* CE5 */ CE_ATTR_FLAGS, 0, 0, 0 },
75 /* Target autonomous hif_memcpy */
76 { /* CE6 */ CE_ATTR_FLAGS, 0, 0, 0 },
77 /* ce_diag, the Diagnostic Window */
78 { /* CE7 */ CE_ATTR_FLAGS, 2, DIAG_TRANSFER_LIMIT, 2 },
81 /* Target firmware's Copy Engine configuration. */
82 static const struct ce_pipe_config target_ce_config_wlan[] = {
83 /* host->target HTC control and raw streams */
84 { /* CE0 */ 0, PIPEDIR_OUT, 32, 256, CE_ATTR_FLAGS, 0,},
85 /* target->host HTT + HTC control */
86 { /* CE1 */ 1, PIPEDIR_IN, 32, 512, CE_ATTR_FLAGS, 0,},
87 /* target->host WMI */
88 { /* CE2 */ 2, PIPEDIR_IN, 32, 2048, CE_ATTR_FLAGS, 0,},
89 /* host->target WMI */
90 { /* CE3 */ 3, PIPEDIR_OUT, 32, 2048, CE_ATTR_FLAGS, 0,},
91 /* host->target HTT */
92 { /* CE4 */ 4, PIPEDIR_OUT, 256, 256, CE_ATTR_FLAGS, 0,},
93 /* NB: 50% of src nentries, since tx has 2 frags */
95 { /* CE5 */ 5, PIPEDIR_OUT, 32, 2048, CE_ATTR_FLAGS, 0,},
96 /* Reserved for target autonomous hif_memcpy */
97 { /* CE6 */ 6, PIPEDIR_INOUT, 32, 4096, CE_ATTR_FLAGS, 0,},
98 /* CE7 used only by Host */
102 * Diagnostic read/write access is provided for startup/config/debug usage.
103 * Caller must guarantee proper alignment, when applicable, and single user
106 static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data,
109 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
112 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
115 struct ce_state *ce_diag;
116 /* Host buffer address in CE space */
118 dma_addr_t ce_data_base = 0;
119 void *data_buf = NULL;
123 * This code cannot handle reads to non-memory space. Redirect to the
124 * register read fn but preserve the multi word read capability of
127 if (address < DRAM_BASE_ADDRESS) {
128 if (!IS_ALIGNED(address, 4) ||
129 !IS_ALIGNED((unsigned long)data, 4))
132 while ((nbytes >= 4) && ((ret = ath10k_pci_diag_read_access(
133 ar, address, (u32 *)data)) == 0)) {
134 nbytes -= sizeof(u32);
135 address += sizeof(u32);
141 ce_diag = ar_pci->ce_diag;
144 * Allocate a temporary bounce buffer to hold caller's data
145 * to be DMA'ed from Target. This guarantees
146 * 1) 4-byte alignment
147 * 2) Buffer in DMA-able space
149 orig_nbytes = nbytes;
150 data_buf = (unsigned char *)pci_alloc_consistent(ar_pci->pdev,
158 memset(data_buf, 0, orig_nbytes);
160 remaining_bytes = orig_nbytes;
161 ce_data = ce_data_base;
162 while (remaining_bytes) {
163 nbytes = min_t(unsigned int, remaining_bytes,
164 DIAG_TRANSFER_LIMIT);
166 ret = ath10k_ce_recv_buf_enqueue(ce_diag, NULL, ce_data);
170 /* Request CE to send from Target(!) address to Host buffer */
172 * The address supplied by the caller is in the
173 * Target CPU virtual address space.
175 * In order to use this address with the diagnostic CE,
176 * convert it from Target CPU virtual address space
177 * to CE address space
180 address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem,
182 ath10k_pci_sleep(ar);
184 ret = ath10k_ce_send(ce_diag, NULL, (u32)address, nbytes, 0,
190 while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf,
194 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
200 if (nbytes != completed_nbytes) {
205 if (buf != (u32) address) {
211 while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf,
216 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
222 if (nbytes != completed_nbytes) {
227 if (buf != ce_data) {
232 remaining_bytes -= nbytes;
239 /* Copy data from allocated DMA buf to caller's buf */
240 WARN_ON_ONCE(orig_nbytes & 3);
241 for (i = 0; i < orig_nbytes / sizeof(__le32); i++) {
243 __le32_to_cpu(((__le32 *)data_buf)[i]);
246 ath10k_dbg(ATH10K_DBG_PCI, "%s failure (0x%x)\n",
250 pci_free_consistent(ar_pci->pdev, orig_nbytes,
251 data_buf, ce_data_base);
256 /* Read 4-byte aligned data from Target memory or register */
257 static int ath10k_pci_diag_read_access(struct ath10k *ar, u32 address,
260 /* Assume range doesn't cross this boundary */
261 if (address >= DRAM_BASE_ADDRESS)
262 return ath10k_pci_diag_read_mem(ar, address, data, sizeof(u32));
265 *data = ath10k_pci_read32(ar, address);
266 ath10k_pci_sleep(ar);
270 static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address,
271 const void *data, int nbytes)
273 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
276 unsigned int completed_nbytes, orig_nbytes, remaining_bytes;
279 struct ce_state *ce_diag;
280 void *data_buf = NULL;
281 u32 ce_data; /* Host buffer address in CE space */
282 dma_addr_t ce_data_base = 0;
285 ce_diag = ar_pci->ce_diag;
288 * Allocate a temporary bounce buffer to hold caller's data
289 * to be DMA'ed to Target. This guarantees
290 * 1) 4-byte alignment
291 * 2) Buffer in DMA-able space
293 orig_nbytes = nbytes;
294 data_buf = (unsigned char *)pci_alloc_consistent(ar_pci->pdev,
302 /* Copy caller's data to allocated DMA buf */
303 WARN_ON_ONCE(orig_nbytes & 3);
304 for (i = 0; i < orig_nbytes / sizeof(__le32); i++)
305 ((__le32 *)data_buf)[i] = __cpu_to_le32(((u32 *)data)[i]);
308 * The address supplied by the caller is in the
309 * Target CPU virtual address space.
311 * In order to use this address with the diagnostic CE,
313 * Target CPU virtual address space
318 address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem, address);
319 ath10k_pci_sleep(ar);
321 remaining_bytes = orig_nbytes;
322 ce_data = ce_data_base;
323 while (remaining_bytes) {
324 /* FIXME: check cast */
325 nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT);
327 /* Set up to receive directly into Target(!) address */
328 ret = ath10k_ce_recv_buf_enqueue(ce_diag, NULL, address);
333 * Request CE to send caller-supplied data that
334 * was copied to bounce buffer to Target(!) address.
336 ret = ath10k_ce_send(ce_diag, NULL, (u32) ce_data,
342 while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf,
347 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
353 if (nbytes != completed_nbytes) {
358 if (buf != ce_data) {
364 while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf,
369 if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) {
375 if (nbytes != completed_nbytes) {
380 if (buf != address) {
385 remaining_bytes -= nbytes;
392 pci_free_consistent(ar_pci->pdev, orig_nbytes, data_buf,
397 ath10k_dbg(ATH10K_DBG_PCI, "%s failure (0x%x)\n", __func__,
403 /* Write 4B data to Target memory or register */
404 static int ath10k_pci_diag_write_access(struct ath10k *ar, u32 address,
407 /* Assume range doesn't cross this boundary */
408 if (address >= DRAM_BASE_ADDRESS)
409 return ath10k_pci_diag_write_mem(ar, address, &data,
413 ath10k_pci_write32(ar, address, data);
414 ath10k_pci_sleep(ar);
418 static bool ath10k_pci_target_is_awake(struct ath10k *ar)
420 void __iomem *mem = ath10k_pci_priv(ar)->mem;
422 val = ioread32(mem + PCIE_LOCAL_BASE_ADDRESS +
424 return (RTC_STATE_V_GET(val) == RTC_STATE_V_ON);
427 static void ath10k_pci_wait(struct ath10k *ar)
431 while (n-- && !ath10k_pci_target_is_awake(ar))
435 ath10k_warn("Unable to wakeup target\n");
438 void ath10k_do_pci_wake(struct ath10k *ar)
440 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
441 void __iomem *pci_addr = ar_pci->mem;
445 if (atomic_read(&ar_pci->keep_awake_count) == 0) {
447 iowrite32(PCIE_SOC_WAKE_V_MASK,
448 pci_addr + PCIE_LOCAL_BASE_ADDRESS +
449 PCIE_SOC_WAKE_ADDRESS);
451 atomic_inc(&ar_pci->keep_awake_count);
453 if (ar_pci->verified_awake)
457 if (ath10k_pci_target_is_awake(ar)) {
458 ar_pci->verified_awake = true;
462 if (tot_delay > PCIE_WAKE_TIMEOUT) {
463 ath10k_warn("target takes too long to wake up (awake count %d)\n",
464 atomic_read(&ar_pci->keep_awake_count));
469 tot_delay += curr_delay;
476 void ath10k_do_pci_sleep(struct ath10k *ar)
478 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
479 void __iomem *pci_addr = ar_pci->mem;
481 if (atomic_dec_and_test(&ar_pci->keep_awake_count)) {
483 ar_pci->verified_awake = false;
484 iowrite32(PCIE_SOC_WAKE_RESET,
485 pci_addr + PCIE_LOCAL_BASE_ADDRESS +
486 PCIE_SOC_WAKE_ADDRESS);
491 * FIXME: Handle OOM properly.
494 struct ath10k_pci_compl *get_free_compl(struct hif_ce_pipe_info *pipe_info)
496 struct ath10k_pci_compl *compl = NULL;
498 spin_lock_bh(&pipe_info->pipe_lock);
499 if (list_empty(&pipe_info->compl_free)) {
500 ath10k_warn("Completion buffers are full\n");
503 compl = list_first_entry(&pipe_info->compl_free,
504 struct ath10k_pci_compl, list);
505 list_del(&compl->list);
507 spin_unlock_bh(&pipe_info->pipe_lock);
511 /* Called by lower (CE) layer when a send to Target completes. */
512 static void ath10k_pci_ce_send_done(struct ce_state *ce_state,
513 void *transfer_context,
516 unsigned int transfer_id)
518 struct ath10k *ar = ce_state->ar;
519 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
520 struct hif_ce_pipe_info *pipe_info = &ar_pci->pipe_info[ce_state->id];
521 struct ath10k_pci_compl *compl;
522 bool process = false;
526 * For the send completion of an item in sendlist, just
527 * increment num_sends_allowed. The upper layer callback will
528 * be triggered when last fragment is done with send.
530 if (transfer_context == CE_SENDLIST_ITEM_CTXT) {
531 spin_lock_bh(&pipe_info->pipe_lock);
532 pipe_info->num_sends_allowed++;
533 spin_unlock_bh(&pipe_info->pipe_lock);
537 compl = get_free_compl(pipe_info);
541 compl->state = ATH10K_PCI_COMPL_SEND;
542 compl->ce_state = ce_state;
543 compl->pipe_info = pipe_info;
544 compl->transfer_context = transfer_context;
545 compl->nbytes = nbytes;
546 compl->transfer_id = transfer_id;
550 * Add the completion to the processing queue.
552 spin_lock_bh(&ar_pci->compl_lock);
553 list_add_tail(&compl->list, &ar_pci->compl_process);
554 spin_unlock_bh(&ar_pci->compl_lock);
557 } while (ath10k_ce_completed_send_next(ce_state,
563 * If only some of the items within a sendlist have completed,
564 * don't invoke completion processing until the entire sendlist
570 ath10k_pci_process_ce(ar);
573 /* Called by lower (CE) layer when data is received from the Target. */
574 static void ath10k_pci_ce_recv_data(struct ce_state *ce_state,
575 void *transfer_context, u32 ce_data,
577 unsigned int transfer_id,
580 struct ath10k *ar = ce_state->ar;
581 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
582 struct hif_ce_pipe_info *pipe_info = &ar_pci->pipe_info[ce_state->id];
583 struct ath10k_pci_compl *compl;
587 compl = get_free_compl(pipe_info);
591 compl->state = ATH10K_PCI_COMPL_RECV;
592 compl->ce_state = ce_state;
593 compl->pipe_info = pipe_info;
594 compl->transfer_context = transfer_context;
595 compl->nbytes = nbytes;
596 compl->transfer_id = transfer_id;
597 compl->flags = flags;
599 skb = transfer_context;
600 dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr,
601 skb->len + skb_tailroom(skb),
604 * Add the completion to the processing queue.
606 spin_lock_bh(&ar_pci->compl_lock);
607 list_add_tail(&compl->list, &ar_pci->compl_process);
608 spin_unlock_bh(&ar_pci->compl_lock);
610 } while (ath10k_ce_completed_recv_next(ce_state,
616 ath10k_pci_process_ce(ar);
619 /* Send the first nbytes bytes of the buffer */
620 static int ath10k_pci_hif_send_head(struct ath10k *ar, u8 pipe_id,
621 unsigned int transfer_id,
622 unsigned int bytes, struct sk_buff *nbuf)
624 struct ath10k_skb_cb *skb_cb = ATH10K_SKB_CB(nbuf);
625 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
626 struct hif_ce_pipe_info *pipe_info = &(ar_pci->pipe_info[pipe_id]);
627 struct ce_state *ce_hdl = pipe_info->ce_hdl;
628 struct ce_sendlist sendlist;
633 memset(&sendlist, 0, sizeof(struct ce_sendlist));
635 len = min(bytes, nbuf->len);
639 ath10k_warn("skb not aligned to 4-byte boundary (%d)\n", len);
641 ath10k_dbg(ATH10K_DBG_PCI,
642 "pci send data vaddr %p paddr 0x%llx len %d as %d bytes\n",
643 nbuf->data, (unsigned long long) skb_cb->paddr,
645 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP, NULL,
647 nbuf->data, nbuf->len);
649 ath10k_ce_sendlist_buf_add(&sendlist, skb_cb->paddr, len, flags);
651 /* Make sure we have resources to handle this request */
652 spin_lock_bh(&pipe_info->pipe_lock);
653 if (!pipe_info->num_sends_allowed) {
654 ath10k_warn("Pipe: %d is full\n", pipe_id);
655 spin_unlock_bh(&pipe_info->pipe_lock);
658 pipe_info->num_sends_allowed--;
659 spin_unlock_bh(&pipe_info->pipe_lock);
661 ret = ath10k_ce_sendlist_send(ce_hdl, nbuf, &sendlist, transfer_id);
663 ath10k_warn("CE send failed: %p\n", nbuf);
668 static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe)
670 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
671 struct hif_ce_pipe_info *pipe_info = &(ar_pci->pipe_info[pipe]);
674 spin_lock_bh(&pipe_info->pipe_lock);
675 ret = pipe_info->num_sends_allowed;
676 spin_unlock_bh(&pipe_info->pipe_lock);
681 static void ath10k_pci_hif_dump_area(struct ath10k *ar)
683 u32 reg_dump_area = 0;
684 u32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {};
689 ath10k_err("firmware crashed!\n");
690 ath10k_err("hardware name %s version 0x%x\n",
691 ar->hw_params.name, ar->target_version);
692 ath10k_err("firmware version: %u.%u.%u.%u\n", ar->fw_version_major,
693 ar->fw_version_minor, ar->fw_version_release,
694 ar->fw_version_build);
696 host_addr = host_interest_item_address(HI_ITEM(hi_failure_state));
697 if (ath10k_pci_diag_read_mem(ar, host_addr,
698 ®_dump_area, sizeof(u32)) != 0) {
699 ath10k_warn("could not read hi_failure_state\n");
703 ath10k_err("target register Dump Location: 0x%08X\n", reg_dump_area);
705 ret = ath10k_pci_diag_read_mem(ar, reg_dump_area,
707 REG_DUMP_COUNT_QCA988X * sizeof(u32));
709 ath10k_err("could not dump FW Dump Area\n");
713 BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4);
715 ath10k_err("target Register Dump\n");
716 for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4)
717 ath10k_err("[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n",
720 reg_dump_values[i + 1],
721 reg_dump_values[i + 2],
722 reg_dump_values[i + 3]);
724 ieee80211_queue_work(ar->hw, &ar->restart_work);
727 static void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe,
733 * Decide whether to actually poll for completions, or just
734 * wait for a later chance.
735 * If there seem to be plenty of resources left, then just wait
736 * since checking involves reading a CE register, which is a
737 * relatively expensive operation.
739 resources = ath10k_pci_hif_get_free_queue_number(ar, pipe);
742 * If at least 50% of the total resources are still available,
743 * don't bother checking again yet.
745 if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1))
748 ath10k_ce_per_engine_service(ar, pipe);
751 static void ath10k_pci_hif_set_callbacks(struct ath10k *ar,
752 struct ath10k_hif_cb *callbacks)
754 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
756 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
758 memcpy(&ar_pci->msg_callbacks_current, callbacks,
759 sizeof(ar_pci->msg_callbacks_current));
762 static int ath10k_pci_start_ce(struct ath10k *ar)
764 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
765 struct ce_state *ce_diag = ar_pci->ce_diag;
766 const struct ce_attr *attr;
767 struct hif_ce_pipe_info *pipe_info;
768 struct ath10k_pci_compl *compl;
769 int i, pipe_num, completions, disable_interrupts;
771 spin_lock_init(&ar_pci->compl_lock);
772 INIT_LIST_HEAD(&ar_pci->compl_process);
774 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
775 pipe_info = &ar_pci->pipe_info[pipe_num];
777 spin_lock_init(&pipe_info->pipe_lock);
778 INIT_LIST_HEAD(&pipe_info->compl_free);
780 /* Handle Diagnostic CE specially */
781 if (pipe_info->ce_hdl == ce_diag)
784 attr = &host_ce_config_wlan[pipe_num];
787 if (attr->src_nentries) {
788 disable_interrupts = attr->flags & CE_ATTR_DIS_INTR;
789 ath10k_ce_send_cb_register(pipe_info->ce_hdl,
790 ath10k_pci_ce_send_done,
792 completions += attr->src_nentries;
793 pipe_info->num_sends_allowed = attr->src_nentries - 1;
796 if (attr->dest_nentries) {
797 ath10k_ce_recv_cb_register(pipe_info->ce_hdl,
798 ath10k_pci_ce_recv_data);
799 completions += attr->dest_nentries;
802 if (completions == 0)
805 for (i = 0; i < completions; i++) {
806 compl = kmalloc(sizeof(*compl), GFP_KERNEL);
808 ath10k_warn("No memory for completion state\n");
809 ath10k_pci_stop_ce(ar);
813 compl->state = ATH10K_PCI_COMPL_FREE;
814 list_add_tail(&compl->list, &pipe_info->compl_free);
821 static void ath10k_pci_stop_ce(struct ath10k *ar)
823 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
824 struct ath10k_pci_compl *compl;
828 ath10k_ce_disable_interrupts(ar);
830 /* Cancel the pending tasklet */
831 tasklet_kill(&ar_pci->intr_tq);
833 for (i = 0; i < CE_COUNT; i++)
834 tasklet_kill(&ar_pci->pipe_info[i].intr);
836 /* Mark pending completions as aborted, so that upper layers free up
837 * their associated resources */
838 spin_lock_bh(&ar_pci->compl_lock);
839 list_for_each_entry(compl, &ar_pci->compl_process, list) {
840 skb = (struct sk_buff *)compl->transfer_context;
841 ATH10K_SKB_CB(skb)->is_aborted = true;
843 spin_unlock_bh(&ar_pci->compl_lock);
846 static void ath10k_pci_cleanup_ce(struct ath10k *ar)
848 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
849 struct ath10k_pci_compl *compl, *tmp;
850 struct hif_ce_pipe_info *pipe_info;
851 struct sk_buff *netbuf;
854 /* Free pending completions. */
855 spin_lock_bh(&ar_pci->compl_lock);
856 if (!list_empty(&ar_pci->compl_process))
857 ath10k_warn("pending completions still present! possible memory leaks.\n");
859 list_for_each_entry_safe(compl, tmp, &ar_pci->compl_process, list) {
860 list_del(&compl->list);
861 netbuf = (struct sk_buff *)compl->transfer_context;
862 dev_kfree_skb_any(netbuf);
865 spin_unlock_bh(&ar_pci->compl_lock);
867 /* Free unused completions for each pipe. */
868 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
869 pipe_info = &ar_pci->pipe_info[pipe_num];
871 spin_lock_bh(&pipe_info->pipe_lock);
872 list_for_each_entry_safe(compl, tmp,
873 &pipe_info->compl_free, list) {
874 list_del(&compl->list);
877 spin_unlock_bh(&pipe_info->pipe_lock);
881 static void ath10k_pci_process_ce(struct ath10k *ar)
883 struct ath10k_pci *ar_pci = ar->hif.priv;
884 struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current;
885 struct ath10k_pci_compl *compl;
888 int ret, send_done = 0;
890 /* Upper layers aren't ready to handle tx/rx completions in parallel so
891 * we must serialize all completion processing. */
893 spin_lock_bh(&ar_pci->compl_lock);
894 if (ar_pci->compl_processing) {
895 spin_unlock_bh(&ar_pci->compl_lock);
898 ar_pci->compl_processing = true;
899 spin_unlock_bh(&ar_pci->compl_lock);
902 spin_lock_bh(&ar_pci->compl_lock);
903 if (list_empty(&ar_pci->compl_process)) {
904 spin_unlock_bh(&ar_pci->compl_lock);
907 compl = list_first_entry(&ar_pci->compl_process,
908 struct ath10k_pci_compl, list);
909 list_del(&compl->list);
910 spin_unlock_bh(&ar_pci->compl_lock);
912 switch (compl->state) {
913 case ATH10K_PCI_COMPL_SEND:
914 cb->tx_completion(ar,
915 compl->transfer_context,
919 case ATH10K_PCI_COMPL_RECV:
920 ret = ath10k_pci_post_rx_pipe(compl->pipe_info, 1);
922 ath10k_warn("Unable to post recv buffer for pipe: %d\n",
923 compl->pipe_info->pipe_num);
927 skb = (struct sk_buff *)compl->transfer_context;
928 nbytes = compl->nbytes;
930 ath10k_dbg(ATH10K_DBG_PCI,
931 "ath10k_pci_ce_recv_data netbuf=%p nbytes=%d\n",
933 ath10k_dbg_dump(ATH10K_DBG_PCI_DUMP, NULL,
934 "ath10k rx: ", skb->data, nbytes);
936 if (skb->len + skb_tailroom(skb) >= nbytes) {
938 skb_put(skb, nbytes);
939 cb->rx_completion(ar, skb,
940 compl->pipe_info->pipe_num);
942 ath10k_warn("rxed more than expected (nbytes %d, max %d)",
944 skb->len + skb_tailroom(skb));
947 case ATH10K_PCI_COMPL_FREE:
948 ath10k_warn("free completion cannot be processed\n");
951 ath10k_warn("invalid completion state (%d)\n",
956 compl->state = ATH10K_PCI_COMPL_FREE;
959 * Add completion back to the pipe's free list.
961 spin_lock_bh(&compl->pipe_info->pipe_lock);
962 list_add_tail(&compl->list, &compl->pipe_info->compl_free);
963 compl->pipe_info->num_sends_allowed += send_done;
964 spin_unlock_bh(&compl->pipe_info->pipe_lock);
967 spin_lock_bh(&ar_pci->compl_lock);
968 ar_pci->compl_processing = false;
969 spin_unlock_bh(&ar_pci->compl_lock);
972 /* TODO - temporary mapping while we have too few CE's */
973 static int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar,
974 u16 service_id, u8 *ul_pipe,
975 u8 *dl_pipe, int *ul_is_polled,
980 /* polling for received messages not supported */
983 switch (service_id) {
984 case ATH10K_HTC_SVC_ID_HTT_DATA_MSG:
986 * Host->target HTT gets its own pipe, so it can be polled
987 * while other pipes are interrupt driven.
991 * Use the same target->host pipe for HTC ctrl, HTC raw
997 case ATH10K_HTC_SVC_ID_RSVD_CTRL:
998 case ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS:
1000 * Note: HTC_RAW_STREAMS_SVC is currently unused, and
1001 * HTC_CTRL_RSVD_SVC could share the same pipe as the
1002 * WMI services. So, if another CE is needed, change
1003 * this to *ul_pipe = 3, which frees up CE 0.
1010 case ATH10K_HTC_SVC_ID_WMI_DATA_BK:
1011 case ATH10K_HTC_SVC_ID_WMI_DATA_BE:
1012 case ATH10K_HTC_SVC_ID_WMI_DATA_VI:
1013 case ATH10K_HTC_SVC_ID_WMI_DATA_VO:
1015 case ATH10K_HTC_SVC_ID_WMI_CONTROL:
1021 /* pipe 6 reserved */
1022 /* pipe 7 reserved */
1029 (host_ce_config_wlan[*ul_pipe].flags & CE_ATTR_DIS_INTR) != 0;
1034 static void ath10k_pci_hif_get_default_pipe(struct ath10k *ar,
1035 u8 *ul_pipe, u8 *dl_pipe)
1037 int ul_is_polled, dl_is_polled;
1039 (void)ath10k_pci_hif_map_service_to_pipe(ar,
1040 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1047 static int ath10k_pci_post_rx_pipe(struct hif_ce_pipe_info *pipe_info,
1050 struct ath10k *ar = pipe_info->hif_ce_state;
1051 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1052 struct ce_state *ce_state = pipe_info->ce_hdl;
1053 struct sk_buff *skb;
1057 if (pipe_info->buf_sz == 0)
1060 for (i = 0; i < num; i++) {
1061 skb = dev_alloc_skb(pipe_info->buf_sz);
1063 ath10k_warn("could not allocate skbuff for pipe %d\n",
1069 WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb");
1071 ce_data = dma_map_single(ar->dev, skb->data,
1072 skb->len + skb_tailroom(skb),
1075 if (unlikely(dma_mapping_error(ar->dev, ce_data))) {
1076 ath10k_warn("could not dma map skbuff\n");
1077 dev_kfree_skb_any(skb);
1082 ATH10K_SKB_CB(skb)->paddr = ce_data;
1084 pci_dma_sync_single_for_device(ar_pci->pdev, ce_data,
1086 PCI_DMA_FROMDEVICE);
1088 ret = ath10k_ce_recv_buf_enqueue(ce_state, (void *)skb,
1091 ath10k_warn("could not enqueue to pipe %d (%d)\n",
1100 ath10k_pci_rx_pipe_cleanup(pipe_info);
1104 static int ath10k_pci_post_rx(struct ath10k *ar)
1106 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1107 struct hif_ce_pipe_info *pipe_info;
1108 const struct ce_attr *attr;
1109 int pipe_num, ret = 0;
1111 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
1112 pipe_info = &ar_pci->pipe_info[pipe_num];
1113 attr = &host_ce_config_wlan[pipe_num];
1115 if (attr->dest_nentries == 0)
1118 ret = ath10k_pci_post_rx_pipe(pipe_info,
1119 attr->dest_nentries - 1);
1121 ath10k_warn("Unable to replenish recv buffers for pipe: %d\n",
1124 for (; pipe_num >= 0; pipe_num--) {
1125 pipe_info = &ar_pci->pipe_info[pipe_num];
1126 ath10k_pci_rx_pipe_cleanup(pipe_info);
1135 static int ath10k_pci_hif_start(struct ath10k *ar)
1137 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1140 ret = ath10k_pci_start_ce(ar);
1142 ath10k_warn("could not start CE (%d)\n", ret);
1146 /* Post buffers once to start things off. */
1147 ret = ath10k_pci_post_rx(ar);
1149 ath10k_warn("could not post rx pipes (%d)\n", ret);
1153 ar_pci->started = 1;
1157 static void ath10k_pci_rx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info)
1160 struct ath10k_pci *ar_pci;
1161 struct ce_state *ce_hdl;
1163 struct sk_buff *netbuf;
1166 buf_sz = pipe_info->buf_sz;
1168 /* Unused Copy Engine */
1172 ar = pipe_info->hif_ce_state;
1173 ar_pci = ath10k_pci_priv(ar);
1175 if (!ar_pci->started)
1178 ce_hdl = pipe_info->ce_hdl;
1180 while (ath10k_ce_revoke_recv_next(ce_hdl, (void **)&netbuf,
1182 dma_unmap_single(ar->dev, ATH10K_SKB_CB(netbuf)->paddr,
1183 netbuf->len + skb_tailroom(netbuf),
1185 dev_kfree_skb_any(netbuf);
1189 static void ath10k_pci_tx_pipe_cleanup(struct hif_ce_pipe_info *pipe_info)
1192 struct ath10k_pci *ar_pci;
1193 struct ce_state *ce_hdl;
1194 struct sk_buff *netbuf;
1196 unsigned int nbytes;
1200 buf_sz = pipe_info->buf_sz;
1202 /* Unused Copy Engine */
1206 ar = pipe_info->hif_ce_state;
1207 ar_pci = ath10k_pci_priv(ar);
1209 if (!ar_pci->started)
1212 ce_hdl = pipe_info->ce_hdl;
1214 while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf,
1215 &ce_data, &nbytes, &id) == 0) {
1216 if (netbuf != CE_SENDLIST_ITEM_CTXT)
1218 * Indicate the completion to higer layer to free
1221 ATH10K_SKB_CB(netbuf)->is_aborted = true;
1222 ar_pci->msg_callbacks_current.tx_completion(ar,
1229 * Cleanup residual buffers for device shutdown:
1230 * buffers that were enqueued for receive
1231 * buffers that were to be sent
1232 * Note: Buffers that had completed but which were
1233 * not yet processed are on a completion queue. They
1234 * are handled when the completion thread shuts down.
1236 static void ath10k_pci_buffer_cleanup(struct ath10k *ar)
1238 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1241 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
1242 struct hif_ce_pipe_info *pipe_info;
1244 pipe_info = &ar_pci->pipe_info[pipe_num];
1245 ath10k_pci_rx_pipe_cleanup(pipe_info);
1246 ath10k_pci_tx_pipe_cleanup(pipe_info);
1250 static void ath10k_pci_ce_deinit(struct ath10k *ar)
1252 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1253 struct hif_ce_pipe_info *pipe_info;
1256 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
1257 pipe_info = &ar_pci->pipe_info[pipe_num];
1258 if (pipe_info->ce_hdl) {
1259 ath10k_ce_deinit(pipe_info->ce_hdl);
1260 pipe_info->ce_hdl = NULL;
1261 pipe_info->buf_sz = 0;
1266 static void ath10k_pci_disable_irqs(struct ath10k *ar)
1268 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1271 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
1272 disable_irq(ar_pci->pdev->irq + i);
1275 static void ath10k_pci_hif_stop(struct ath10k *ar)
1277 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1279 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
1281 /* Irqs are never explicitly re-enabled. They are implicitly re-enabled
1282 * by ath10k_pci_start_intr(). */
1283 ath10k_pci_disable_irqs(ar);
1285 ath10k_pci_stop_ce(ar);
1287 /* At this point, asynchronous threads are stopped, the target should
1288 * not DMA nor interrupt. We process the leftovers and then free
1289 * everything else up. */
1291 ath10k_pci_process_ce(ar);
1292 ath10k_pci_cleanup_ce(ar);
1293 ath10k_pci_buffer_cleanup(ar);
1295 ar_pci->started = 0;
1298 static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar,
1299 void *req, u32 req_len,
1300 void *resp, u32 *resp_len)
1302 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1303 struct ce_state *ce_tx = ar_pci->pipe_info[BMI_CE_NUM_TO_TARG].ce_hdl;
1304 struct ce_state *ce_rx = ar_pci->pipe_info[BMI_CE_NUM_TO_HOST].ce_hdl;
1305 dma_addr_t req_paddr = 0;
1306 dma_addr_t resp_paddr = 0;
1307 struct bmi_xfer xfer = {};
1308 void *treq, *tresp = NULL;
1311 if (resp && !resp_len)
1314 if (resp && resp_len && *resp_len == 0)
1317 treq = kmemdup(req, req_len, GFP_KERNEL);
1321 req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE);
1322 ret = dma_mapping_error(ar->dev, req_paddr);
1326 if (resp && resp_len) {
1327 tresp = kzalloc(*resp_len, GFP_KERNEL);
1333 resp_paddr = dma_map_single(ar->dev, tresp, *resp_len,
1335 ret = dma_mapping_error(ar->dev, resp_paddr);
1339 xfer.wait_for_resp = true;
1342 ath10k_ce_recv_buf_enqueue(ce_rx, &xfer, resp_paddr);
1345 init_completion(&xfer.done);
1347 ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0);
1351 ret = wait_for_completion_timeout(&xfer.done,
1352 BMI_COMMUNICATION_TIMEOUT_HZ);
1355 unsigned int unused_nbytes;
1356 unsigned int unused_id;
1359 ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer,
1360 &unused_nbytes, &unused_id);
1362 /* non-zero means we did not time out */
1370 ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer);
1371 dma_unmap_single(ar->dev, resp_paddr,
1372 *resp_len, DMA_FROM_DEVICE);
1375 dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE);
1377 if (ret == 0 && resp_len) {
1378 *resp_len = min(*resp_len, xfer.resp_len);
1379 memcpy(resp, tresp, xfer.resp_len);
1388 static void ath10k_pci_bmi_send_done(struct ce_state *ce_state,
1389 void *transfer_context,
1391 unsigned int nbytes,
1392 unsigned int transfer_id)
1394 struct bmi_xfer *xfer = transfer_context;
1396 if (xfer->wait_for_resp)
1399 complete(&xfer->done);
1402 static void ath10k_pci_bmi_recv_data(struct ce_state *ce_state,
1403 void *transfer_context,
1405 unsigned int nbytes,
1406 unsigned int transfer_id,
1409 struct bmi_xfer *xfer = transfer_context;
1411 if (!xfer->wait_for_resp) {
1412 ath10k_warn("unexpected: BMI data received; ignoring\n");
1416 xfer->resp_len = nbytes;
1417 complete(&xfer->done);
1421 * Map from service/endpoint to Copy Engine.
1422 * This table is derived from the CE_PCI TABLE, above.
1423 * It is passed to the Target at startup for use by firmware.
1425 static const struct service_to_pipe target_service_to_ce_map_wlan[] = {
1427 ATH10K_HTC_SVC_ID_WMI_DATA_VO,
1428 PIPEDIR_OUT, /* out = UL = host -> target */
1432 ATH10K_HTC_SVC_ID_WMI_DATA_VO,
1433 PIPEDIR_IN, /* in = DL = target -> host */
1437 ATH10K_HTC_SVC_ID_WMI_DATA_BK,
1438 PIPEDIR_OUT, /* out = UL = host -> target */
1442 ATH10K_HTC_SVC_ID_WMI_DATA_BK,
1443 PIPEDIR_IN, /* in = DL = target -> host */
1447 ATH10K_HTC_SVC_ID_WMI_DATA_BE,
1448 PIPEDIR_OUT, /* out = UL = host -> target */
1452 ATH10K_HTC_SVC_ID_WMI_DATA_BE,
1453 PIPEDIR_IN, /* in = DL = target -> host */
1457 ATH10K_HTC_SVC_ID_WMI_DATA_VI,
1458 PIPEDIR_OUT, /* out = UL = host -> target */
1462 ATH10K_HTC_SVC_ID_WMI_DATA_VI,
1463 PIPEDIR_IN, /* in = DL = target -> host */
1467 ATH10K_HTC_SVC_ID_WMI_CONTROL,
1468 PIPEDIR_OUT, /* out = UL = host -> target */
1472 ATH10K_HTC_SVC_ID_WMI_CONTROL,
1473 PIPEDIR_IN, /* in = DL = target -> host */
1477 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1478 PIPEDIR_OUT, /* out = UL = host -> target */
1479 0, /* could be moved to 3 (share with WMI) */
1482 ATH10K_HTC_SVC_ID_RSVD_CTRL,
1483 PIPEDIR_IN, /* in = DL = target -> host */
1487 ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS, /* not currently used */
1488 PIPEDIR_OUT, /* out = UL = host -> target */
1492 ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS, /* not currently used */
1493 PIPEDIR_IN, /* in = DL = target -> host */
1497 ATH10K_HTC_SVC_ID_HTT_DATA_MSG,
1498 PIPEDIR_OUT, /* out = UL = host -> target */
1502 ATH10K_HTC_SVC_ID_HTT_DATA_MSG,
1503 PIPEDIR_IN, /* in = DL = target -> host */
1507 /* (Additions here) */
1509 { /* Must be last */
1517 * Send an interrupt to the device to wake up the Target CPU
1518 * so it has an opportunity to notice any changed state.
1520 static int ath10k_pci_wake_target_cpu(struct ath10k *ar)
1525 ret = ath10k_pci_diag_read_access(ar, SOC_CORE_BASE_ADDRESS |
1529 ath10k_warn("Unable to read core ctrl\n");
1533 /* A_INUM_FIRMWARE interrupt to Target CPU */
1534 core_ctrl |= CORE_CTRL_CPU_INTR_MASK;
1536 ret = ath10k_pci_diag_write_access(ar, SOC_CORE_BASE_ADDRESS |
1540 ath10k_warn("Unable to set interrupt mask\n");
1545 static int ath10k_pci_init_config(struct ath10k *ar)
1547 u32 interconnect_targ_addr;
1548 u32 pcie_state_targ_addr = 0;
1549 u32 pipe_cfg_targ_addr = 0;
1550 u32 svc_to_pipe_map = 0;
1551 u32 pcie_config_flags = 0;
1553 u32 ealloc_targ_addr;
1555 u32 flag2_targ_addr;
1558 /* Download to Target the CE Config and the service-to-CE map */
1559 interconnect_targ_addr =
1560 host_interest_item_address(HI_ITEM(hi_interconnect_state));
1562 /* Supply Target-side CE configuration */
1563 ret = ath10k_pci_diag_read_access(ar, interconnect_targ_addr,
1564 &pcie_state_targ_addr);
1566 ath10k_err("Failed to get pcie state addr: %d\n", ret);
1570 if (pcie_state_targ_addr == 0) {
1572 ath10k_err("Invalid pcie state addr\n");
1576 ret = ath10k_pci_diag_read_access(ar, pcie_state_targ_addr +
1577 offsetof(struct pcie_state,
1579 &pipe_cfg_targ_addr);
1581 ath10k_err("Failed to get pipe cfg addr: %d\n", ret);
1585 if (pipe_cfg_targ_addr == 0) {
1587 ath10k_err("Invalid pipe cfg addr\n");
1591 ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr,
1592 target_ce_config_wlan,
1593 sizeof(target_ce_config_wlan));
1596 ath10k_err("Failed to write pipe cfg: %d\n", ret);
1600 ret = ath10k_pci_diag_read_access(ar, pcie_state_targ_addr +
1601 offsetof(struct pcie_state,
1605 ath10k_err("Failed to get svc/pipe map: %d\n", ret);
1609 if (svc_to_pipe_map == 0) {
1611 ath10k_err("Invalid svc_to_pipe map\n");
1615 ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map,
1616 target_service_to_ce_map_wlan,
1617 sizeof(target_service_to_ce_map_wlan));
1619 ath10k_err("Failed to write svc/pipe map: %d\n", ret);
1623 ret = ath10k_pci_diag_read_access(ar, pcie_state_targ_addr +
1624 offsetof(struct pcie_state,
1626 &pcie_config_flags);
1628 ath10k_err("Failed to get pcie config_flags: %d\n", ret);
1632 pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1;
1634 ret = ath10k_pci_diag_write_mem(ar, pcie_state_targ_addr +
1635 offsetof(struct pcie_state, config_flags),
1637 sizeof(pcie_config_flags));
1639 ath10k_err("Failed to write pcie config_flags: %d\n", ret);
1643 /* configure early allocation */
1644 ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc));
1646 ret = ath10k_pci_diag_read_access(ar, ealloc_targ_addr, &ealloc_value);
1648 ath10k_err("Faile to get early alloc val: %d\n", ret);
1652 /* first bank is switched to IRAM */
1653 ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) &
1654 HI_EARLY_ALLOC_MAGIC_MASK);
1655 ealloc_value |= ((1 << HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) &
1656 HI_EARLY_ALLOC_IRAM_BANKS_MASK);
1658 ret = ath10k_pci_diag_write_access(ar, ealloc_targ_addr, ealloc_value);
1660 ath10k_err("Failed to set early alloc val: %d\n", ret);
1664 /* Tell Target to proceed with initialization */
1665 flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2));
1667 ret = ath10k_pci_diag_read_access(ar, flag2_targ_addr, &flag2_value);
1669 ath10k_err("Failed to get option val: %d\n", ret);
1673 flag2_value |= HI_OPTION_EARLY_CFG_DONE;
1675 ret = ath10k_pci_diag_write_access(ar, flag2_targ_addr, flag2_value);
1677 ath10k_err("Failed to set option val: %d\n", ret);
1686 static int ath10k_pci_ce_init(struct ath10k *ar)
1688 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1689 struct hif_ce_pipe_info *pipe_info;
1690 const struct ce_attr *attr;
1693 for (pipe_num = 0; pipe_num < ar_pci->ce_count; pipe_num++) {
1694 pipe_info = &ar_pci->pipe_info[pipe_num];
1695 pipe_info->pipe_num = pipe_num;
1696 pipe_info->hif_ce_state = ar;
1697 attr = &host_ce_config_wlan[pipe_num];
1699 pipe_info->ce_hdl = ath10k_ce_init(ar, pipe_num, attr);
1700 if (pipe_info->ce_hdl == NULL) {
1701 ath10k_err("Unable to initialize CE for pipe: %d\n",
1704 /* It is safe to call it here. It checks if ce_hdl is
1705 * valid for each pipe */
1706 ath10k_pci_ce_deinit(ar);
1710 if (pipe_num == ar_pci->ce_count - 1) {
1712 * Reserve the ultimate CE for
1713 * diagnostic Window support
1716 ar_pci->pipe_info[ar_pci->ce_count - 1].ce_hdl;
1720 pipe_info->buf_sz = (size_t) (attr->src_sz_max);
1724 * Initially, establish CE completion handlers for use with BMI.
1725 * These are overwritten with generic handlers after we exit BMI phase.
1727 pipe_info = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG];
1728 ath10k_ce_send_cb_register(pipe_info->ce_hdl,
1729 ath10k_pci_bmi_send_done, 0);
1731 pipe_info = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST];
1732 ath10k_ce_recv_cb_register(pipe_info->ce_hdl,
1733 ath10k_pci_bmi_recv_data);
1738 static void ath10k_pci_fw_interrupt_handler(struct ath10k *ar)
1740 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1741 u32 fw_indicator_address, fw_indicator;
1743 ath10k_pci_wake(ar);
1745 fw_indicator_address = ar_pci->fw_indicator_address;
1746 fw_indicator = ath10k_pci_read32(ar, fw_indicator_address);
1748 if (fw_indicator & FW_IND_EVENT_PENDING) {
1749 /* ACK: clear Target-side pending event */
1750 ath10k_pci_write32(ar, fw_indicator_address,
1751 fw_indicator & ~FW_IND_EVENT_PENDING);
1753 if (ar_pci->started) {
1754 ath10k_pci_hif_dump_area(ar);
1757 * Probable Target failure before we're prepared
1758 * to handle it. Generally unexpected.
1760 ath10k_warn("early firmware event indicated\n");
1764 ath10k_pci_sleep(ar);
1767 static int ath10k_pci_hif_power_up(struct ath10k *ar)
1769 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1772 ret = ath10k_pci_start_intr(ar);
1774 ath10k_err("could not start interrupt handling (%d)\n", ret);
1779 * Bring the target up cleanly.
1781 * The target may be in an undefined state with an AUX-powered Target
1782 * and a Host in WoW mode. If the Host crashes, loses power, or is
1783 * restarted (without unloading the driver) then the Target is left
1784 * (aux) powered and running. On a subsequent driver load, the Target
1785 * is in an unexpected state. We try to catch that here in order to
1786 * reset the Target and retry the probe.
1788 ath10k_pci_device_reset(ar);
1790 ret = ath10k_pci_reset_target(ar);
1794 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
1795 /* Force AWAKE forever */
1796 ath10k_do_pci_wake(ar);
1798 ret = ath10k_pci_ce_init(ar);
1802 ret = ath10k_pci_init_config(ar);
1806 ret = ath10k_pci_wake_target_cpu(ar);
1808 ath10k_err("could not wake up target CPU (%d)\n", ret);
1815 ath10k_pci_ce_deinit(ar);
1817 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
1818 ath10k_do_pci_sleep(ar);
1820 ath10k_pci_stop_intr(ar);
1825 static void ath10k_pci_hif_power_down(struct ath10k *ar)
1827 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1829 ath10k_pci_stop_intr(ar);
1831 ath10k_pci_ce_deinit(ar);
1832 if (!test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
1833 ath10k_do_pci_sleep(ar);
1838 #define ATH10K_PCI_PM_CONTROL 0x44
1840 static int ath10k_pci_hif_suspend(struct ath10k *ar)
1842 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1843 struct pci_dev *pdev = ar_pci->pdev;
1846 pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val);
1848 if ((val & 0x000000ff) != 0x3) {
1849 pci_save_state(pdev);
1850 pci_disable_device(pdev);
1851 pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
1852 (val & 0xffffff00) | 0x03);
1858 static int ath10k_pci_hif_resume(struct ath10k *ar)
1860 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1861 struct pci_dev *pdev = ar_pci->pdev;
1864 pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val);
1866 if ((val & 0x000000ff) != 0) {
1867 pci_restore_state(pdev);
1868 pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL,
1871 * Suspend/Resume resets the PCI configuration space,
1872 * so we have to re-disable the RETRY_TIMEOUT register (0x41)
1873 * to keep PCI Tx retries from interfering with C3 CPU state
1875 pci_read_config_dword(pdev, 0x40, &val);
1877 if ((val & 0x0000ff00) != 0)
1878 pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
1885 static const struct ath10k_hif_ops ath10k_pci_hif_ops = {
1886 .send_head = ath10k_pci_hif_send_head,
1887 .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg,
1888 .start = ath10k_pci_hif_start,
1889 .stop = ath10k_pci_hif_stop,
1890 .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe,
1891 .get_default_pipe = ath10k_pci_hif_get_default_pipe,
1892 .send_complete_check = ath10k_pci_hif_send_complete_check,
1893 .set_callbacks = ath10k_pci_hif_set_callbacks,
1894 .get_free_queue_number = ath10k_pci_hif_get_free_queue_number,
1895 .power_up = ath10k_pci_hif_power_up,
1896 .power_down = ath10k_pci_hif_power_down,
1898 .suspend = ath10k_pci_hif_suspend,
1899 .resume = ath10k_pci_hif_resume,
1903 static void ath10k_pci_ce_tasklet(unsigned long ptr)
1905 struct hif_ce_pipe_info *pipe = (struct hif_ce_pipe_info *)ptr;
1906 struct ath10k_pci *ar_pci = pipe->ar_pci;
1908 ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num);
1911 static void ath10k_msi_err_tasklet(unsigned long data)
1913 struct ath10k *ar = (struct ath10k *)data;
1915 ath10k_pci_fw_interrupt_handler(ar);
1919 * Handler for a per-engine interrupt on a PARTICULAR CE.
1920 * This is used in cases where each CE has a private MSI interrupt.
1922 static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg)
1924 struct ath10k *ar = arg;
1925 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1926 int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL;
1928 if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) {
1929 ath10k_warn("unexpected/invalid irq %d ce_id %d\n", irq, ce_id);
1934 * NOTE: We are able to derive ce_id from irq because we
1935 * use a one-to-one mapping for CE's 0..5.
1936 * CE's 6 & 7 do not use interrupts at all.
1938 * This mapping must be kept in sync with the mapping
1941 tasklet_schedule(&ar_pci->pipe_info[ce_id].intr);
1945 static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg)
1947 struct ath10k *ar = arg;
1948 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1950 tasklet_schedule(&ar_pci->msi_fw_err);
1955 * Top-level interrupt handler for all PCI interrupts from a Target.
1956 * When a block of MSI interrupts is allocated, this top-level handler
1957 * is not used; instead, we directly call the correct sub-handler.
1959 static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg)
1961 struct ath10k *ar = arg;
1962 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1964 if (ar_pci->num_msi_intrs == 0) {
1966 * IMPORTANT: INTR_CLR regiser has to be set after
1967 * INTR_ENABLE is set to 0, otherwise interrupt can not be
1970 iowrite32(0, ar_pci->mem +
1971 (SOC_CORE_BASE_ADDRESS |
1972 PCIE_INTR_ENABLE_ADDRESS));
1973 iowrite32(PCIE_INTR_FIRMWARE_MASK |
1974 PCIE_INTR_CE_MASK_ALL,
1975 ar_pci->mem + (SOC_CORE_BASE_ADDRESS |
1976 PCIE_INTR_CLR_ADDRESS));
1978 * IMPORTANT: this extra read transaction is required to
1979 * flush the posted write buffer.
1981 (void) ioread32(ar_pci->mem +
1982 (SOC_CORE_BASE_ADDRESS |
1983 PCIE_INTR_ENABLE_ADDRESS));
1986 tasklet_schedule(&ar_pci->intr_tq);
1991 static void ath10k_pci_tasklet(unsigned long data)
1993 struct ath10k *ar = (struct ath10k *)data;
1994 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
1996 ath10k_pci_fw_interrupt_handler(ar); /* FIXME: Handle FW error */
1997 ath10k_ce_per_engine_service_any(ar);
1999 if (ar_pci->num_msi_intrs == 0) {
2000 /* Enable Legacy PCI line interrupts */
2001 iowrite32(PCIE_INTR_FIRMWARE_MASK |
2002 PCIE_INTR_CE_MASK_ALL,
2003 ar_pci->mem + (SOC_CORE_BASE_ADDRESS |
2004 PCIE_INTR_ENABLE_ADDRESS));
2006 * IMPORTANT: this extra read transaction is required to
2007 * flush the posted write buffer
2009 (void) ioread32(ar_pci->mem +
2010 (SOC_CORE_BASE_ADDRESS |
2011 PCIE_INTR_ENABLE_ADDRESS));
2015 static int ath10k_pci_start_intr_msix(struct ath10k *ar, int num)
2017 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2021 ret = pci_enable_msi_block(ar_pci->pdev, num);
2025 ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW,
2026 ath10k_pci_msi_fw_handler,
2027 IRQF_SHARED, "ath10k_pci", ar);
2029 ath10k_warn("request_irq(%d) failed %d\n",
2030 ar_pci->pdev->irq + MSI_ASSIGN_FW, ret);
2032 pci_disable_msi(ar_pci->pdev);
2036 for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) {
2037 ret = request_irq(ar_pci->pdev->irq + i,
2038 ath10k_pci_per_engine_handler,
2039 IRQF_SHARED, "ath10k_pci", ar);
2041 ath10k_warn("request_irq(%d) failed %d\n",
2042 ar_pci->pdev->irq + i, ret);
2044 for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--)
2045 free_irq(ar_pci->pdev->irq + i, ar);
2047 free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar);
2048 pci_disable_msi(ar_pci->pdev);
2053 ath10k_info("MSI-X interrupt handling (%d intrs)\n", num);
2057 static int ath10k_pci_start_intr_msi(struct ath10k *ar)
2059 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2062 ret = pci_enable_msi(ar_pci->pdev);
2066 ret = request_irq(ar_pci->pdev->irq,
2067 ath10k_pci_interrupt_handler,
2068 IRQF_SHARED, "ath10k_pci", ar);
2070 pci_disable_msi(ar_pci->pdev);
2074 ath10k_info("MSI interrupt handling\n");
2078 static int ath10k_pci_start_intr_legacy(struct ath10k *ar)
2080 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2083 ret = request_irq(ar_pci->pdev->irq,
2084 ath10k_pci_interrupt_handler,
2085 IRQF_SHARED, "ath10k_pci", ar);
2090 * Make sure to wake the Target before enabling Legacy
2093 iowrite32(PCIE_SOC_WAKE_V_MASK,
2094 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
2095 PCIE_SOC_WAKE_ADDRESS);
2097 ath10k_pci_wait(ar);
2100 * A potential race occurs here: The CORE_BASE write
2101 * depends on target correctly decoding AXI address but
2102 * host won't know when target writes BAR to CORE_CTRL.
2103 * This write might get lost if target has NOT written BAR.
2104 * For now, fix the race by repeating the write in below
2105 * synchronization checking.
2107 iowrite32(PCIE_INTR_FIRMWARE_MASK |
2108 PCIE_INTR_CE_MASK_ALL,
2109 ar_pci->mem + (SOC_CORE_BASE_ADDRESS |
2110 PCIE_INTR_ENABLE_ADDRESS));
2111 iowrite32(PCIE_SOC_WAKE_RESET,
2112 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
2113 PCIE_SOC_WAKE_ADDRESS);
2115 ath10k_info("legacy interrupt handling\n");
2119 static int ath10k_pci_start_intr(struct ath10k *ar)
2121 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2122 int num = MSI_NUM_REQUEST;
2126 tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long) ar);
2127 tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet,
2128 (unsigned long) ar);
2130 for (i = 0; i < CE_COUNT; i++) {
2131 ar_pci->pipe_info[i].ar_pci = ar_pci;
2132 tasklet_init(&ar_pci->pipe_info[i].intr,
2133 ath10k_pci_ce_tasklet,
2134 (unsigned long)&ar_pci->pipe_info[i]);
2137 if (!test_bit(ATH10K_PCI_FEATURE_MSI_X, ar_pci->features))
2141 ret = ath10k_pci_start_intr_msix(ar, num);
2145 ath10k_warn("MSI-X didn't succeed (%d), trying MSI\n", ret);
2150 ret = ath10k_pci_start_intr_msi(ar);
2154 ath10k_warn("MSI didn't succeed (%d), trying legacy INTR\n",
2159 ret = ath10k_pci_start_intr_legacy(ar);
2162 ar_pci->num_msi_intrs = num;
2163 ar_pci->ce_count = CE_COUNT;
2167 static void ath10k_pci_stop_intr(struct ath10k *ar)
2169 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2172 /* There's at least one interrupt irregardless whether its legacy INTR
2173 * or MSI or MSI-X */
2174 for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++)
2175 free_irq(ar_pci->pdev->irq + i, ar);
2177 if (ar_pci->num_msi_intrs > 0)
2178 pci_disable_msi(ar_pci->pdev);
2181 static int ath10k_pci_reset_target(struct ath10k *ar)
2183 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2184 int wait_limit = 300; /* 3 sec */
2186 /* Wait for Target to finish initialization before we proceed. */
2187 iowrite32(PCIE_SOC_WAKE_V_MASK,
2188 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
2189 PCIE_SOC_WAKE_ADDRESS);
2191 ath10k_pci_wait(ar);
2193 while (wait_limit-- &&
2194 !(ioread32(ar_pci->mem + FW_INDICATOR_ADDRESS) &
2195 FW_IND_INITIALIZED)) {
2196 if (ar_pci->num_msi_intrs == 0)
2197 /* Fix potential race by repeating CORE_BASE writes */
2198 iowrite32(PCIE_INTR_FIRMWARE_MASK |
2199 PCIE_INTR_CE_MASK_ALL,
2200 ar_pci->mem + (SOC_CORE_BASE_ADDRESS |
2201 PCIE_INTR_ENABLE_ADDRESS));
2205 if (wait_limit < 0) {
2206 ath10k_err("Target stalled\n");
2207 iowrite32(PCIE_SOC_WAKE_RESET,
2208 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
2209 PCIE_SOC_WAKE_ADDRESS);
2213 iowrite32(PCIE_SOC_WAKE_RESET,
2214 ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS +
2215 PCIE_SOC_WAKE_ADDRESS);
2220 static void ath10k_pci_device_reset(struct ath10k *ar)
2222 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
2223 void __iomem *mem = ar_pci->mem;
2227 if (!SOC_GLOBAL_RESET_ADDRESS)
2233 ath10k_pci_reg_write32(mem, PCIE_SOC_WAKE_ADDRESS,
2234 PCIE_SOC_WAKE_V_MASK);
2235 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2236 if (ath10k_pci_target_is_awake(ar))
2241 /* Put Target, including PCIe, into RESET. */
2242 val = ath10k_pci_reg_read32(mem, SOC_GLOBAL_RESET_ADDRESS);
2244 ath10k_pci_reg_write32(mem, SOC_GLOBAL_RESET_ADDRESS, val);
2246 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2247 if (ath10k_pci_reg_read32(mem, RTC_STATE_ADDRESS) &
2248 RTC_STATE_COLD_RESET_MASK)
2253 /* Pull Target, including PCIe, out of RESET. */
2255 ath10k_pci_reg_write32(mem, SOC_GLOBAL_RESET_ADDRESS, val);
2257 for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) {
2258 if (!(ath10k_pci_reg_read32(mem, RTC_STATE_ADDRESS) &
2259 RTC_STATE_COLD_RESET_MASK))
2264 ath10k_pci_reg_write32(mem, PCIE_SOC_WAKE_ADDRESS, PCIE_SOC_WAKE_RESET);
2267 static void ath10k_pci_dump_features(struct ath10k_pci *ar_pci)
2271 for (i = 0; i < ATH10K_PCI_FEATURE_COUNT; i++) {
2272 if (!test_bit(i, ar_pci->features))
2276 case ATH10K_PCI_FEATURE_MSI_X:
2277 ath10k_dbg(ATH10K_DBG_PCI, "device supports MSI-X\n");
2279 case ATH10K_PCI_FEATURE_SOC_POWER_SAVE:
2280 ath10k_dbg(ATH10K_DBG_PCI, "QCA98XX SoC power save enabled\n");
2286 static int ath10k_pci_probe(struct pci_dev *pdev,
2287 const struct pci_device_id *pci_dev)
2292 struct ath10k_pci *ar_pci;
2295 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
2297 ar_pci = kzalloc(sizeof(*ar_pci), GFP_KERNEL);
2301 ar_pci->pdev = pdev;
2302 ar_pci->dev = &pdev->dev;
2304 switch (pci_dev->device) {
2305 case QCA988X_2_0_DEVICE_ID:
2306 set_bit(ATH10K_PCI_FEATURE_MSI_X, ar_pci->features);
2310 ath10k_err("Unkown device ID: %d\n", pci_dev->device);
2314 if (ath10k_target_ps)
2315 set_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features);
2317 ath10k_pci_dump_features(ar_pci);
2319 ar = ath10k_core_create(ar_pci, ar_pci->dev, &ath10k_pci_hif_ops);
2321 ath10k_err("ath10k_core_create failed!\n");
2327 ar_pci->fw_indicator_address = FW_INDICATOR_ADDRESS;
2328 atomic_set(&ar_pci->keep_awake_count, 0);
2330 pci_set_drvdata(pdev, ar);
2333 * Without any knowledge of the Host, the Target may have been reset or
2334 * power cycled and its Config Space may no longer reflect the PCI
2335 * address space that was assigned earlier by the PCI infrastructure.
2338 ret = pci_assign_resource(pdev, BAR_NUM);
2340 ath10k_err("cannot assign PCI space: %d\n", ret);
2344 ret = pci_enable_device(pdev);
2346 ath10k_err("cannot enable PCI device: %d\n", ret);
2350 /* Request MMIO resources */
2351 ret = pci_request_region(pdev, BAR_NUM, "ath");
2353 ath10k_err("PCI MMIO reservation error: %d\n", ret);
2358 * Target structures have a limit of 32 bit DMA pointers.
2359 * DMA pointers can be wider than 32 bits by default on some systems.
2361 ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
2363 ath10k_err("32-bit DMA not available: %d\n", ret);
2367 ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
2369 ath10k_err("cannot enable 32-bit consistent DMA\n");
2373 /* Set bus master bit in PCI_COMMAND to enable DMA */
2374 pci_set_master(pdev);
2377 * Temporary FIX: disable ASPM
2378 * Will be removed after the OTP is programmed
2380 pci_read_config_dword(pdev, 0x80, &lcr_val);
2381 pci_write_config_dword(pdev, 0x80, (lcr_val & 0xffffff00));
2383 /* Arrange for access to Target SoC registers. */
2384 mem = pci_iomap(pdev, BAR_NUM, 0);
2386 ath10k_err("PCI iomap error\n");
2393 spin_lock_init(&ar_pci->ce_lock);
2395 ar_pci->cacheline_sz = dma_get_cache_alignment();
2397 ret = ath10k_core_register(ar);
2399 ath10k_err("could not register driver core (%d)\n", ret);
2406 pci_iounmap(pdev, mem);
2408 pci_clear_master(pdev);
2410 pci_release_region(pdev, BAR_NUM);
2412 pci_disable_device(pdev);
2414 pci_set_drvdata(pdev, NULL);
2415 ath10k_core_destroy(ar);
2417 /* call HIF PCI free here */
2423 static void ath10k_pci_remove(struct pci_dev *pdev)
2425 struct ath10k *ar = pci_get_drvdata(pdev);
2426 struct ath10k_pci *ar_pci;
2428 ath10k_dbg(ATH10K_DBG_PCI, "%s\n", __func__);
2433 ar_pci = ath10k_pci_priv(ar);
2438 tasklet_kill(&ar_pci->msi_fw_err);
2440 ath10k_core_unregister(ar);
2442 pci_set_drvdata(pdev, NULL);
2443 pci_iounmap(pdev, ar_pci->mem);
2444 pci_release_region(pdev, BAR_NUM);
2445 pci_clear_master(pdev);
2446 pci_disable_device(pdev);
2448 ath10k_core_destroy(ar);
2452 MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table);
2454 static struct pci_driver ath10k_pci_driver = {
2455 .name = "ath10k_pci",
2456 .id_table = ath10k_pci_id_table,
2457 .probe = ath10k_pci_probe,
2458 .remove = ath10k_pci_remove,
2461 static int __init ath10k_pci_init(void)
2465 ret = pci_register_driver(&ath10k_pci_driver);
2467 ath10k_err("pci_register_driver failed [%d]\n", ret);
2471 module_init(ath10k_pci_init);
2473 static void __exit ath10k_pci_exit(void)
2475 pci_unregister_driver(&ath10k_pci_driver);
2478 module_exit(ath10k_pci_exit);
2480 MODULE_AUTHOR("Qualcomm Atheros");
2481 MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices");
2482 MODULE_LICENSE("Dual BSD/GPL");
2483 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_FILE);
2484 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_OTP_FILE);
2485 MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE);