Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 1 | /* |
Houston Hoffman | 62aa58d | 2015-11-02 21:14:55 -0800 | [diff] [blame] | 2 | * Copyright (c) 2013-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 3 | * |
| 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 Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 36 | #include <ol_if_athvar.h> |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 37 | #include "hif.h" |
| 38 | #include "cepci.h" |
Komal Seelam | 43301de | 2016-02-02 18:20:48 +0530 | [diff] [blame] | 39 | #include "ce_main.h" |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 40 | |
| 41 | /* An address (e.g. of a buffer) in Copy Engine space. */ |
| 42 | |
| 43 | #define HIF_MAX_TASKLET_NUM 11 |
| 44 | struct hif_tasklet_entry { |
| 45 | uint8_t id; /* 0 - 9: maps to CE, 10: fw */ |
| 46 | void *hif_handler; /* struct hif_pci_softc */ |
| 47 | }; |
Houston Hoffman | 62aa58d | 2015-11-02 21:14:55 -0800 | [diff] [blame] | 48 | |
| 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 | */ |
| 56 | enum 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 | */ |
| 71 | struct 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 */ |
| 79 | struct 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 Seelam | aa72bb7 | 2016-02-01 17:22:50 +0530 | [diff] [blame] | 96 | /** |
| 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 | */ |
| 104 | struct hif_msi_info { |
| 105 | void *magic; |
| 106 | dma_addr_t magic_da; |
| 107 | OS_DMA_MEM_CONTEXT(dmacontext) |
| 108 | }; |
| 109 | |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 110 | struct hif_pci_softc { |
Komal Seelam | 43301de | 2016-02-02 18:20:48 +0530 | [diff] [blame] | 111 | struct HIF_CE_state ce_sc; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 112 | void __iomem *mem; /* PCI address. */ |
| 113 | /* For efficiency, should be first in struct */ |
| 114 | |
| 115 | struct device *dev; |
| 116 | struct pci_dev *pdev; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 117 | 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 Seelam | aa72bb7 | 2016-02-01 17:22:50 +0530 | [diff] [blame] | 121 | struct hif_msi_info msi_info; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 122 | int irq; |
| 123 | int irq_event; |
| 124 | int cacheline_sz; |
| 125 | u16 devid; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 126 | qdf_dma_addr_t soc_pcie_bar0; |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 127 | struct hif_tasklet_entry tasklet_entries[HIF_MAX_TASKLET_NUM]; |
| 128 | bool pci_enabled; |
Chouhan, Anurag | fc06aa9 | 2016-03-03 19:05:05 +0530 | [diff] [blame] | 129 | qdf_spinlock_t irq_lock; |
| 130 | qdf_work_t reschedule_tasklet_work; |
Komal Seelam | aa72bb7 | 2016-02-01 17:22:50 +0530 | [diff] [blame] | 131 | uint32_t lcr_val; |
Houston Hoffman | 62aa58d | 2015-11-02 21:14:55 -0800 | [diff] [blame] | 132 | #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 Hoffman | cceec34 | 2015-11-11 11:37:20 -0800 | [diff] [blame] | 141 | struct hif_pm_runtime_lock *prevent_linkdown_lock; |
Houston Hoffman | 62aa58d | 2015-11-02 21:14:55 -0800 | [diff] [blame] | 142 | #ifdef WLAN_OPEN_SOURCE |
| 143 | struct dentry *pm_dentry; |
| 144 | #endif |
| 145 | #endif |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 146 | }; |
| 147 | |
Komal Seelam | 644263d | 2016-02-22 20:45:49 +0530 | [diff] [blame] | 148 | bool hif_pci_targ_is_present(struct hif_softc *scn, void *__iomem *mem); |
| 149 | void icnss_dispatch_ce_irq(struct hif_softc *scn); |
| 150 | int hif_configure_irq(struct hif_softc *sc); |
| 151 | void hif_pci_cancel_deferred_target_sleep(struct hif_softc *scn); |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 152 | |
| 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 Hoffman | 9078a15 | 2015-11-02 16:15:02 -0800 | [diff] [blame] | 189 | |
| 190 | |
| 191 | #ifdef FEATURE_RUNTIME_PM |
| 192 | #include <linux/pm_runtime.h> |
| 193 | |
| 194 | #ifdef WLAN_OPEN_SOURCE |
| 195 | static inline int hif_pm_request_resume(struct device *dev) |
| 196 | { |
| 197 | return pm_request_resume(dev); |
| 198 | } |
| 199 | static inline int __hif_pm_runtime_get(struct device *dev) |
| 200 | { |
| 201 | return pm_runtime_get(dev); |
| 202 | } |
| 203 | |
| 204 | static inline int hif_pm_runtime_put_auto(struct device *dev) |
| 205 | { |
| 206 | return pm_runtime_put_autosuspend(dev); |
| 207 | } |
| 208 | |
| 209 | static inline void hif_pm_runtime_mark_last_busy(struct device *dev) |
| 210 | { |
| 211 | pm_runtime_mark_last_busy(dev); |
| 212 | } |
| 213 | |
| 214 | static inline int hif_pm_runtime_resume(struct device *dev) |
| 215 | { |
| 216 | return pm_runtime_resume(dev); |
| 217 | } |
| 218 | #else |
| 219 | static inline int hif_pm_request_resume(struct device *dev) |
| 220 | { |
| 221 | return cnss_pm_runtime_request(dev, CNSS_PM_REQUEST_RESUME); |
| 222 | } |
| 223 | |
| 224 | static inline int __hif_pm_runtime_get(struct device *dev) |
| 225 | { |
| 226 | return cnss_pm_runtime_request(dev, CNSS_PM_RUNTIME_GET); |
| 227 | } |
| 228 | |
| 229 | static 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 | |
| 234 | static 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 | } |
| 238 | static 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 Hoffman | 226a3b1 | 2015-11-12 18:00:21 -0800 | [diff] [blame] | 243 | #else |
| 244 | static inline void hif_pm_runtime_mark_last_busy(struct device *dev) { } |
Houston Hoffman | 9078a15 | 2015-11-02 16:15:02 -0800 | [diff] [blame] | 245 | #endif /* FEATURE_RUNTIME_PM */ |
Prakash Dhavali | d5c9f1c | 2015-11-08 19:04:44 -0800 | [diff] [blame] | 246 | #endif /* __ATH_PCI_H__ */ |