1 /* 2 * Copyright (c) 2013-2019 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef __ATH_PCI_H__ 20 #define __ATH_PCI_H__ 21 22 #include <linux/version.h> 23 #include <linux/semaphore.h> 24 #include <linux/interrupt.h> 25 26 #define ATH_DBG_DEFAULT 0 27 #define DRAM_SIZE 0x000a8000 28 #include "hif.h" 29 #include "cepci.h" 30 #include "ce_main.h" 31 32 #ifdef QCA_HIF_HIA_EXTND 33 extern int32_t frac, intval, ar900b_20_targ_clk, qca9888_20_targ_clk; 34 #endif 35 36 /* An address (e.g. of a buffer) in Copy Engine space. */ 37 38 #define HIF_MAX_TASKLET_NUM 11 39 struct hif_tasklet_entry { 40 uint8_t id; /* 0 - 9: maps to CE, 10: fw */ 41 void *hif_handler; /* struct hif_pci_softc */ 42 }; 43 44 /** 45 * enum hif_pm_runtime_state - Driver States for Runtime Power Management 46 * HIF_PM_RUNTIME_STATE_NONE: runtime pm is off 47 * HIF_PM_RUNTIME_STATE_ON: runtime pm is active and link is active 48 * HIF_PM_RUNTIME_STATE_INPROGRESS: a runtime suspend or resume is in progress 49 * HIF_PM_RUNTIME_STATE_SUSPENDED: the driver is runtime suspended 50 */ 51 enum hif_pm_runtime_state { 52 HIF_PM_RUNTIME_STATE_NONE, 53 HIF_PM_RUNTIME_STATE_ON, 54 HIF_PM_RUNTIME_STATE_INPROGRESS, 55 HIF_PM_RUNTIME_STATE_SUSPENDED, 56 }; 57 58 #ifdef FEATURE_RUNTIME_PM 59 60 /** 61 * struct hif_pm_runtime_lock - data structure for preventing runtime suspend 62 * @list - global list of runtime locks 63 * @active - true if this lock is preventing suspend 64 * @name - character string for tracking this lock 65 */ 66 struct hif_pm_runtime_lock { 67 struct list_head list; 68 bool active; 69 uint32_t timeout; 70 const char *name; 71 }; 72 73 /* Debugging stats for Runtime PM */ 74 struct hif_pci_pm_stats { 75 u32 suspended; 76 u32 suspend_err; 77 u32 resumed; 78 u32 runtime_get; 79 u32 runtime_put; 80 u32 request_resume; 81 u32 allow_suspend; 82 u32 prevent_suspend; 83 u32 prevent_suspend_timeout; 84 u32 allow_suspend_timeout; 85 u32 runtime_get_err; 86 void *last_resume_caller; 87 unsigned long suspend_jiffies; 88 }; 89 #endif 90 91 /** 92 * struct hif_msi_info - Structure to hold msi info 93 * @magic: cookie 94 * @magic_da: dma address 95 * @dmaContext: dma address 96 * 97 * Structure to hold MSI information for PCIe interrupts 98 */ 99 struct hif_msi_info { 100 void *magic; 101 dma_addr_t magic_da; 102 OS_DMA_MEM_CONTEXT(dmacontext); 103 }; 104 105 struct hif_pci_softc { 106 struct HIF_CE_state ce_sc; 107 void __iomem *mem; /* PCI address. */ 108 size_t mem_len; 109 110 struct device *dev; /* For efficiency, should be first in struct */ 111 struct pci_dev *pdev; 112 int num_msi_intrs; /* number of MSI interrupts granted */ 113 /* 0 --> using legacy PCI line interrupts */ 114 struct tasklet_struct intr_tq; /* tasklet */ 115 struct hif_msi_info msi_info; 116 int ce_msi_irq_num[CE_COUNT_MAX]; 117 int irq; 118 int irq_event; 119 int cacheline_sz; 120 u16 devid; 121 struct hif_tasklet_entry tasklet_entries[HIF_MAX_TASKLET_NUM]; 122 bool pci_enabled; 123 bool use_register_windowing; 124 uint32_t register_window; 125 qdf_spinlock_t register_access_lock; 126 qdf_spinlock_t irq_lock; 127 qdf_work_t reschedule_tasklet_work; 128 uint32_t lcr_val; 129 #ifdef FEATURE_RUNTIME_PM 130 atomic_t pm_state; 131 uint32_t prevent_suspend_cnt; 132 struct hif_pci_pm_stats pm_stats; 133 struct work_struct pm_work; 134 spinlock_t runtime_lock; 135 qdf_timer_t runtime_timer; 136 struct list_head prevent_suspend_list; 137 unsigned long runtime_timer_expires; 138 qdf_runtime_lock_t prevent_linkdown_lock; 139 #ifdef WLAN_OPEN_SOURCE 140 struct dentry *pm_dentry; 141 #endif 142 #endif 143 int (*hif_enable_pci)(struct hif_pci_softc *sc, struct pci_dev *pdev, 144 const struct pci_device_id *id); 145 void (*hif_pci_deinit)(struct hif_pci_softc *sc); 146 void (*hif_pci_get_soc_info)(struct hif_pci_softc *sc, 147 struct device *dev); 148 }; 149 150 bool hif_pci_targ_is_present(struct hif_softc *scn, void *__iomem *mem); 151 int hif_configure_irq(struct hif_softc *sc); 152 void hif_pci_cancel_deferred_target_sleep(struct hif_softc *scn); 153 void wlan_tasklet(unsigned long data); 154 irqreturn_t hif_pci_legacy_ce_interrupt_handler(int irq, void *arg); 155 int hif_pci_addr_in_boundary(struct hif_softc *scn, uint32_t offset); 156 157 /* 158 * A firmware interrupt to the Host is indicated by the 159 * low bit of SCRATCH_3_ADDRESS being set. 160 */ 161 #define FW_EVENT_PENDING_REG_ADDRESS SCRATCH_3_ADDRESS 162 163 /* 164 * Typically, MSI Interrupts are used with PCIe. To force use of legacy 165 * "ABCD" PCI line interrupts rather than MSI, define 166 * FORCE_LEGACY_PCI_INTERRUPTS. 167 * Even when NOT forced, the driver may attempt to use legacy PCI interrupts 168 * MSI allocation fails 169 */ 170 #define LEGACY_INTERRUPTS(sc) ((sc)->num_msi_intrs == 0) 171 172 /* 173 * There may be some pending tx frames during platform suspend. 174 * Suspend operation should be delayed until those tx frames are 175 * transferred from the host to target. This macro specifies how 176 * long suspend thread has to sleep before checking pending tx 177 * frame count. 178 */ 179 #define OL_ATH_TX_DRAIN_WAIT_DELAY 50 /* ms */ 180 181 #define HIF_CE_DRAIN_WAIT_DELAY 10 /* ms */ 182 /* 183 * Wait time (in unit of OL_ATH_TX_DRAIN_WAIT_DELAY) for pending 184 * tx frame completion before suspend. Refer: hif_pci_suspend() 185 */ 186 #ifndef QCA_WIFI_3_0_EMU 187 #define OL_ATH_TX_DRAIN_WAIT_CNT 10 188 #else 189 #define OL_ATH_TX_DRAIN_WAIT_CNT 60 190 #endif 191 192 #ifdef FEATURE_RUNTIME_PM 193 #include <linux/pm_runtime.h> 194 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 void hif_pm_runtime_mark_last_busy(struct device *dev) { } 220 #endif /* FEATURE_RUNTIME_PM */ 221 #endif /* __ATH_PCI_H__ */ 222