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.
21 #include <linux/interrupt.h>
27 #define REG_DUMP_COUNT_QCA988X 60
30 * maximum number of bytes that can be handled atomically by DiagRead/DiagWrite
32 #define DIAG_TRANSFER_LIMIT 2048
35 * maximum number of bytes that can be
36 * handled atomically by DiagRead/DiagWrite
38 #define DIAG_TRANSFER_LIMIT 2048
41 struct completion done;
47 * PCI-specific Target state
49 * NOTE: Structure is shared between Host software and Target firmware!
51 * Much of this may be of interest to the Host so
52 * HOST_INTEREST->hi_interconnect_state points here
53 * (and all members are 32-bit quantities in order to
54 * facilitate Host access). In particular, Host software is
55 * required to initialize pipe_cfg_addr and svc_to_pipe_map.
58 /* Pipe configuration Target address */
59 /* NB: ce_pipe_config[CE_COUNT] */
62 /* Service to pipe map Target address */
63 /* NB: service_to_pipe[PIPE_TO_CE_MAP_CN] */
66 /* number of MSI interrupts requested */
69 /* number of MSI interrupts granted */
72 /* Message Signalled Interrupt address */
79 * Data for firmware interrupt;
80 * MSI data for other interrupts are
81 * in various SoC registers
85 /* PCIE_PWR_METHOD_* */
86 u32 power_mgmt_method;
88 /* PCIE_CONFIG_FLAG_* */
92 /* PCIE_CONFIG_FLAG definitions */
93 #define PCIE_CONFIG_FLAG_ENABLE_L1 0x0000001
95 /* Host software's Copy Engine configuration. */
96 #define CE_ATTR_FLAGS 0
99 * Configuration information for a Copy Engine pipe.
100 * Passed from Host to Target during startup (one per CE).
102 * NOTE: Structure is shared between Host software and Target firmware!
104 struct ce_pipe_config {
114 * Directions for interconnect pipe configuration.
115 * These definitions may be used during configuration and are shared
116 * between Host and Target.
118 * Pipe Directions are relative to the Host, so PIPEDIR_IN means
119 * "coming IN over air through Target to Host" as with a WiFi Rx operation.
120 * Conversely, PIPEDIR_OUT means "going OUT from Host through Target over air"
121 * as with a WiFi Tx operation. This is somewhat awkward for the "middle-man"
122 * Target since things that are "PIPEDIR_OUT" are coming IN to the Target
123 * over the interconnect.
125 #define PIPEDIR_NONE 0
126 #define PIPEDIR_IN 1 /* Target-->Host, WiFi Rx direction */
127 #define PIPEDIR_OUT 2 /* Host->Target, WiFi Tx direction */
128 #define PIPEDIR_INOUT 3 /* bidirectional */
130 /* Establish a mapping between a service/direction and a pipe. */
131 struct service_to_pipe {
137 enum ath10k_pci_features {
138 ATH10K_PCI_FEATURE_MSI_X = 0,
139 ATH10K_PCI_FEATURE_SOC_POWER_SAVE = 1,
142 ATH10K_PCI_FEATURE_COUNT
145 /* Per-pipe state. */
146 struct ath10k_pci_pipe {
147 /* Handle of underlying Copy Engine */
148 struct ath10k_ce_pipe *ce_hdl;
150 /* Our pipe number; facilitiates use of pipe_info ptrs. */
153 /* Convenience back pointer to hif_ce_state. */
154 struct ath10k *hif_ce_state;
158 /* protects compl_free and num_send_allowed */
159 spinlock_t pipe_lock;
161 struct ath10k_pci *ar_pci;
162 struct tasklet_struct intr;
166 struct pci_dev *pdev;
171 DECLARE_BITMAP(features, ATH10K_PCI_FEATURE_COUNT);
174 * Number of MSI interrupts granted, 0 --> using legacy PCI line
179 struct tasklet_struct intr_tq;
180 struct tasklet_struct msi_fw_err;
181 struct tasklet_struct early_irq_tasklet;
185 atomic_t keep_awake_count;
188 struct ath10k_pci_pipe pipe_info[CE_COUNT_MAX];
190 struct ath10k_hif_cb msg_callbacks_current;
192 /* Target address used to signal a pending firmware event */
193 u32 fw_indicator_address;
195 /* Copy Engine used for Diagnostic Accesses */
196 struct ath10k_ce_pipe *ce_diag;
198 /* FIXME: document what this really protects */
201 /* Map CE id to ce_state */
202 struct ath10k_ce_pipe ce_states[CE_COUNT_MAX];
205 static inline struct ath10k_pci *ath10k_pci_priv(struct ath10k *ar)
210 static inline u32 ath10k_pci_reg_read32(struct ath10k *ar, u32 addr)
212 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
214 return ioread32(ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS + addr);
217 static inline void ath10k_pci_reg_write32(struct ath10k *ar, u32 addr, u32 val)
219 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
221 iowrite32(val, ar_pci->mem + PCIE_LOCAL_BASE_ADDRESS + addr);
224 #define ATH_PCI_RESET_WAIT_MAX 10 /* ms */
225 #define PCIE_WAKE_TIMEOUT 5000 /* 5ms */
229 #define CDC_WAR_MAGIC_STR 0xceef0000
230 #define CDC_WAR_DATA_CE 4
233 * TODO: Should be a function call specific to each Target-type.
234 * This convoluted macro converts from Target CPU Virtual Address Space to CE
235 * Address Space. As part of this process, we conservatively fetch the current
236 * PCIE_BAR. MOST of the time, this should match the upper bits of PCI space
237 * for this device; but that's not guaranteed.
239 #define TARG_CPU_SPACE_TO_CE_SPACE(ar, pci_addr, addr) \
240 (((ioread32((pci_addr)+(SOC_CORE_BASE_ADDRESS| \
241 CORE_CTRL_ADDRESS)) & 0x7ff) << 21) | \
242 0x100000 | ((addr) & 0xfffff))
244 /* Wait up to this many Ms for a Diagnostic Access CE operation to complete */
245 #define DIAG_ACCESS_CE_TIMEOUT_MS 10
248 * This API allows the Host to access Target registers directly
249 * and relatively efficiently over PCIe.
250 * This allows the Host to avoid extra overhead associated with
251 * sending a message to firmware and waiting for a response message
252 * from firmware, as is done on other interconnects.
254 * Yet there is some complexity with direct accesses because the
255 * Target's power state is not known a priori. The Host must issue
256 * special PCIe reads/writes in order to explicitly wake the Target
257 * and to verify that it is awake and will remain awake.
261 * Use ath10k_pci_read32 and ath10k_pci_write32 to access Target space.
262 * These calls must be bracketed by ath10k_pci_wake and
263 * ath10k_pci_sleep. A single BEGIN/END pair is adequate for
264 * multiple READ/WRITE operations.
266 * Use ath10k_pci_wake to put the Target in a state in
267 * which it is legal for the Host to directly access it. This
268 * may involve waking the Target from a low power state, which
269 * may take up to 2Ms!
271 * Use ath10k_pci_sleep to tell the Target that as far as
272 * this code path is concerned, it no longer needs to remain
273 * directly accessible. BEGIN/END is under a reference counter;
274 * multiple code paths may issue BEGIN/END on a single targid.
276 static inline void ath10k_pci_write32(struct ath10k *ar, u32 offset,
279 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
281 iowrite32(value, ar_pci->mem + offset);
284 static inline u32 ath10k_pci_read32(struct ath10k *ar, u32 offset)
286 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
288 return ioread32(ar_pci->mem + offset);
291 static inline u32 ath10k_pci_soc_read32(struct ath10k *ar, u32 addr)
293 return ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + addr);
296 static inline void ath10k_pci_soc_write32(struct ath10k *ar, u32 addr, u32 val)
298 ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + addr, val);
301 int ath10k_do_pci_wake(struct ath10k *ar);
302 void ath10k_do_pci_sleep(struct ath10k *ar);
304 static inline int ath10k_pci_wake(struct ath10k *ar)
306 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
308 if (test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
309 return ath10k_do_pci_wake(ar);
314 static inline void ath10k_pci_sleep(struct ath10k *ar)
316 struct ath10k_pci *ar_pci = ath10k_pci_priv(ar);
318 if (test_bit(ATH10K_PCI_FEATURE_SOC_POWER_SAVE, ar_pci->features))
319 ath10k_do_pci_sleep(ar);