blob: 86e45bd4ad1376cb2757acb5a108799f23049201 [file] [log] [blame]
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08001/*
Houston Hoffman62aa58d2015-11-02 21:14:55 -08002 * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved.
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -08003 *
4 * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5 *
6 *
7 * Permission to use, copy, modify, and/or distribute this software for
8 * any purpose with or without fee is hereby granted, provided that the
9 * above copyright notice and this permission notice appear in all
10 * copies.
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19 * PERFORMANCE OF THIS SOFTWARE.
20 */
21
22/*
23 * This file was originally distributed by Qualcomm Atheros, Inc.
24 * under proprietary terms before Copyright ownership was assigned
25 * to the Linux Foundation.
26 */
27
28#ifndef __ATH_PCI_H__
29#define __ATH_PCI_H__
30
31#include <linux/version.h>
32#include <linux/semaphore.h>
33#include <linux/interrupt.h>
34
35#define ATH_DBG_DEFAULT 0
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080036#include <ol_if_athvar.h>
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080037#include "hif.h"
38#include "cepci.h"
Komal Seelam43301de2016-02-02 18:20:48 +053039#include "ce_main.h"
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -080040
41/* An address (e.g. of a buffer) in Copy Engine space. */
42
43#define HIF_MAX_TASKLET_NUM 11
44struct hif_tasklet_entry {
45 uint8_t id; /* 0 - 9: maps to CE, 10: fw */
46 void *hif_handler; /* struct hif_pci_softc */
47};
Houston Hoffman62aa58d2015-11-02 21:14:55 -080048
49/**
50 * enum hif_pm_runtime_state - Driver States for Runtime Power Management
51 * HIF_PM_RUNTIME_STATE_NONE: runtime pm is off
52 * HIF_PM_RUNTIME_STATE_ON: runtime pm is active and link is active
53 * HIF_PM_RUNTIME_STATE_INPROGRESS: a runtime suspend or resume is in progress
54 * HIF_PM_RUNTIME_STATE_SUSPENDED: the driver is runtime suspended
55 */
56enum hif_pm_runtime_state {
57 HIF_PM_RUNTIME_STATE_NONE,
58 HIF_PM_RUNTIME_STATE_ON,
59 HIF_PM_RUNTIME_STATE_INPROGRESS,
60 HIF_PM_RUNTIME_STATE_SUSPENDED,
61};
62
63#ifdef FEATURE_RUNTIME_PM
64
65/**
66 * struct hif_pm_runtime_lock - data structure for preventing runtime suspend
67 * @list - global list of runtime locks
68 * @active - true if this lock is preventing suspend
69 * @name - character string for tracking this lock
70 */
71struct hif_pm_runtime_lock {
72 struct list_head list;
73 bool active;
74 uint32_t timeout;
75 const char *name;
76};
77
78/* Debugging stats for Runtime PM */
79struct hif_pci_pm_stats {
80 u32 suspended;
81 u32 suspend_err;
82 u32 resumed;
83 u32 runtime_get;
84 u32 runtime_put;
85 u32 request_resume;
86 u32 allow_suspend;
87 u32 prevent_suspend;
88 u32 prevent_suspend_timeout;
89 u32 allow_suspend_timeout;
90 u32 runtime_get_err;
91 void *last_resume_caller;
92 unsigned long suspend_jiffies;
93};
94#endif
95
Komal Seelamaa72bb72016-02-01 17:22:50 +053096/**
97 * struct hif_msi_info - Structure to hold msi info
98 * @magic: cookie
99 * @magic_da: dma address
100 * @dmaContext: dma address
101 *
102 * Structure to hold MSI information for PCIe interrupts
103 */
104struct hif_msi_info {
105 void *magic;
106 dma_addr_t magic_da;
107 OS_DMA_MEM_CONTEXT(dmacontext)
108};
109
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800110struct hif_pci_softc {
Komal Seelam43301de2016-02-02 18:20:48 +0530111 struct HIF_CE_state ce_sc;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800112 void __iomem *mem; /* PCI address. */
113 /* For efficiency, should be first in struct */
114
115 struct device *dev;
116 struct pci_dev *pdev;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800117 int num_msi_intrs; /* number of MSI interrupts granted */
118 /* 0 --> using legacy PCI line interrupts */
119 struct tasklet_struct intr_tq; /* tasklet */
120
Komal Seelamaa72bb72016-02-01 17:22:50 +0530121 struct hif_msi_info msi_info;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800122 int irq;
123 int irq_event;
124 int cacheline_sz;
125 u16 devid;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530126 qdf_dma_addr_t soc_pcie_bar0;
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800127 struct hif_tasklet_entry tasklet_entries[HIF_MAX_TASKLET_NUM];
128 bool pci_enabled;
Chouhan, Anuragfc06aa92016-03-03 19:05:05 +0530129 qdf_spinlock_t irq_lock;
130 qdf_work_t reschedule_tasklet_work;
Komal Seelamaa72bb72016-02-01 17:22:50 +0530131 uint32_t lcr_val;
Houston Hoffman62aa58d2015-11-02 21:14:55 -0800132#ifdef FEATURE_RUNTIME_PM
133 atomic_t pm_state;
134 uint32_t prevent_suspend_cnt;
135 struct hif_pci_pm_stats pm_stats;
136 struct work_struct pm_work;
137 spinlock_t runtime_lock;
138 struct timer_list runtime_timer;
139 struct list_head prevent_suspend_list;
140 unsigned long runtime_timer_expires;
Houston Hoffmancceec342015-11-11 11:37:20 -0800141 struct hif_pm_runtime_lock *prevent_linkdown_lock;
Houston Hoffman62aa58d2015-11-02 21:14:55 -0800142#ifdef WLAN_OPEN_SOURCE
143 struct dentry *pm_dentry;
144#endif
145#endif
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800146};
147
Komal Seelam644263d2016-02-22 20:45:49 +0530148bool hif_pci_targ_is_present(struct hif_softc *scn, void *__iomem *mem);
149void icnss_dispatch_ce_irq(struct hif_softc *scn);
150int hif_configure_irq(struct hif_softc *sc);
151void hif_pci_cancel_deferred_target_sleep(struct hif_softc *scn);
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800152
153/*
154 * A firmware interrupt to the Host is indicated by the
155 * low bit of SCRATCH_3_ADDRESS being set.
156 */
157#define FW_EVENT_PENDING_REG_ADDRESS SCRATCH_3_ADDRESS
158
159/*
160 * Typically, MSI Interrupts are used with PCIe. To force use of legacy
161 * "ABCD" PCI line interrupts rather than MSI, define
162 * FORCE_LEGACY_PCI_INTERRUPTS.
163 * Even when NOT forced, the driver may attempt to use legacy PCI interrupts
164 * MSI allocation fails
165 */
166#define LEGACY_INTERRUPTS(sc) ((sc)->num_msi_intrs == 0)
167
168/*
169 * There may be some pending tx frames during platform suspend.
170 * Suspend operation should be delayed until those tx frames are
171 * transfered from the host to target. This macro specifies how
172 * long suspend thread has to sleep before checking pending tx
173 * frame count.
174 */
175#define OL_ATH_TX_DRAIN_WAIT_DELAY 50 /* ms */
176
177#define HIF_CE_DRAIN_WAIT_DELAY 10 /* ms */
178/*
179 * Wait time (in unit of OL_ATH_TX_DRAIN_WAIT_DELAY) for pending
180 * tx frame completion before suspend. Refer: hif_pci_suspend()
181 */
182#ifndef QCA_WIFI_3_0_EMU
183#define OL_ATH_TX_DRAIN_WAIT_CNT 10
184#else
185#define OL_ATH_TX_DRAIN_WAIT_CNT 60
186#endif
187
188#define HIF_CE_DRAIN_WAIT_CNT 20
Houston Hoffman9078a152015-11-02 16:15:02 -0800189
190
191#ifdef FEATURE_RUNTIME_PM
192#include <linux/pm_runtime.h>
193
194#ifdef WLAN_OPEN_SOURCE
195static inline int hif_pm_request_resume(struct device *dev)
196{
197 return pm_request_resume(dev);
198}
199static inline int __hif_pm_runtime_get(struct device *dev)
200{
201 return pm_runtime_get(dev);
202}
203
204static inline int hif_pm_runtime_put_auto(struct device *dev)
205{
206 return pm_runtime_put_autosuspend(dev);
207}
208
209static inline void hif_pm_runtime_mark_last_busy(struct device *dev)
210{
211 pm_runtime_mark_last_busy(dev);
212}
213
214static inline int hif_pm_runtime_resume(struct device *dev)
215{
216 return pm_runtime_resume(dev);
217}
218#else
219static inline int hif_pm_request_resume(struct device *dev)
220{
221 return cnss_pm_runtime_request(dev, CNSS_PM_REQUEST_RESUME);
222}
223
224static inline int __hif_pm_runtime_get(struct device *dev)
225{
226 return cnss_pm_runtime_request(dev, CNSS_PM_RUNTIME_GET);
227}
228
229static inline int hif_pm_runtime_put_auto(struct device *dev)
230{
231 return cnss_pm_runtime_request(dev, CNSS_PM_RUNTIME_PUT_AUTO);
232}
233
234static inline void hif_pm_runtime_mark_last_busy(struct device *dev)
235{
236 cnss_pm_runtime_request(dev, CNSS_PM_RUNTIME_MARK_LAST_BUSY);
237}
238static inline int hif_pm_runtime_resume(struct device *dev)
239{
240 return cnss_pm_runtime_request(dev, CNSS_PM_RUNTIME_RESUME);
241}
242#endif /* WLAN_OPEN_SOURCE */
Houston Hoffman226a3b12015-11-12 18:00:21 -0800243#else
244static inline void hif_pm_runtime_mark_last_busy(struct device *dev) { }
Houston Hoffman9078a152015-11-02 16:15:02 -0800245#endif /* FEATURE_RUNTIME_PM */
Prakash Dhavalid5c9f1c2015-11-08 19:04:44 -0800246#endif /* __ATH_PCI_H__ */