Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2005-2011 Atheros Communications Inc. |
| 3 | * Copyright (c) 2011-2013 Qualcomm Atheros, Inc. |
| 4 | * |
| 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. |
| 8 | * |
| 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. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/pci.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/spinlock.h> |
Kalle Valo | 650b91f | 2013-11-20 10:00:49 +0200 | [diff] [blame] | 22 | #include <linux/bitops.h> |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 23 | |
| 24 | #include "core.h" |
| 25 | #include "debug.h" |
| 26 | |
| 27 | #include "targaddrs.h" |
| 28 | #include "bmi.h" |
| 29 | |
| 30 | #include "hif.h" |
| 31 | #include "htc.h" |
| 32 | |
| 33 | #include "ce.h" |
| 34 | #include "pci.h" |
| 35 | |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 36 | enum ath10k_pci_irq_mode { |
| 37 | ATH10K_PCI_IRQ_AUTO = 0, |
| 38 | ATH10K_PCI_IRQ_LEGACY = 1, |
| 39 | ATH10K_PCI_IRQ_MSI = 2, |
| 40 | }; |
| 41 | |
Kalle Valo | 3509846 | 2014-03-28 09:32:27 +0200 | [diff] [blame] | 42 | enum ath10k_pci_reset_mode { |
| 43 | ATH10K_PCI_RESET_AUTO = 0, |
| 44 | ATH10K_PCI_RESET_WARM_ONLY = 1, |
| 45 | }; |
| 46 | |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 47 | static unsigned int ath10k_pci_irq_mode = ATH10K_PCI_IRQ_AUTO; |
Kalle Valo | 3509846 | 2014-03-28 09:32:27 +0200 | [diff] [blame] | 48 | static unsigned int ath10k_pci_reset_mode = ATH10K_PCI_RESET_AUTO; |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 49 | |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 50 | module_param_named(irq_mode, ath10k_pci_irq_mode, uint, 0644); |
| 51 | MODULE_PARM_DESC(irq_mode, "0: auto, 1: legacy, 2: msi (default: 0)"); |
| 52 | |
Kalle Valo | 3509846 | 2014-03-28 09:32:27 +0200 | [diff] [blame] | 53 | module_param_named(reset_mode, ath10k_pci_reset_mode, uint, 0644); |
| 54 | MODULE_PARM_DESC(reset_mode, "0: auto, 1: warm only (default: 0)"); |
| 55 | |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 56 | /* how long wait to wait for target to initialise, in ms */ |
| 57 | #define ATH10K_PCI_TARGET_WAIT 3000 |
Michal Kazior | 61c95ce | 2014-05-14 16:56:16 +0300 | [diff] [blame] | 58 | #define ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS 3 |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 59 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 60 | #define QCA988X_2_0_DEVICE_ID (0x003c) |
| 61 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 62 | static const struct pci_device_id ath10k_pci_id_table[] = { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 63 | { PCI_VDEVICE(ATHEROS, QCA988X_2_0_DEVICE_ID) }, /* PCI-E QCA988X V2 */ |
| 64 | {0} |
| 65 | }; |
| 66 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 67 | static void ath10k_pci_buffer_cleanup(struct ath10k *ar); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 68 | static int ath10k_pci_cold_reset(struct ath10k *ar); |
| 69 | static int ath10k_pci_warm_reset(struct ath10k *ar); |
Michal Kazior | d7fb47f | 2013-11-08 08:01:26 +0100 | [diff] [blame] | 70 | static int ath10k_pci_wait_for_target_init(struct ath10k *ar); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 71 | static int ath10k_pci_init_irq(struct ath10k *ar); |
| 72 | static int ath10k_pci_deinit_irq(struct ath10k *ar); |
| 73 | static int ath10k_pci_request_irq(struct ath10k *ar); |
| 74 | static void ath10k_pci_free_irq(struct ath10k *ar); |
Michal Kazior | 85622cd | 2013-11-25 14:06:22 +0100 | [diff] [blame] | 75 | static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe, |
| 76 | struct ath10k_ce_pipe *rx_pipe, |
| 77 | struct bmi_xfer *xfer); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 78 | |
| 79 | static const struct ce_attr host_ce_config_wlan[] = { |
Kalle Valo | 48e9c22 | 2013-09-01 10:01:32 +0300 | [diff] [blame] | 80 | /* CE0: host->target HTC control and raw streams */ |
| 81 | { |
| 82 | .flags = CE_ATTR_FLAGS, |
| 83 | .src_nentries = 16, |
| 84 | .src_sz_max = 256, |
| 85 | .dest_nentries = 0, |
| 86 | }, |
| 87 | |
| 88 | /* CE1: target->host HTT + HTC control */ |
| 89 | { |
| 90 | .flags = CE_ATTR_FLAGS, |
| 91 | .src_nentries = 0, |
| 92 | .src_sz_max = 512, |
| 93 | .dest_nentries = 512, |
| 94 | }, |
| 95 | |
| 96 | /* CE2: target->host WMI */ |
| 97 | { |
| 98 | .flags = CE_ATTR_FLAGS, |
| 99 | .src_nentries = 0, |
| 100 | .src_sz_max = 2048, |
| 101 | .dest_nentries = 32, |
| 102 | }, |
| 103 | |
| 104 | /* CE3: host->target WMI */ |
| 105 | { |
| 106 | .flags = CE_ATTR_FLAGS, |
| 107 | .src_nentries = 32, |
| 108 | .src_sz_max = 2048, |
| 109 | .dest_nentries = 0, |
| 110 | }, |
| 111 | |
| 112 | /* CE4: host->target HTT */ |
| 113 | { |
| 114 | .flags = CE_ATTR_FLAGS | CE_ATTR_DIS_INTR, |
| 115 | .src_nentries = CE_HTT_H2T_MSG_SRC_NENTRIES, |
| 116 | .src_sz_max = 256, |
| 117 | .dest_nentries = 0, |
| 118 | }, |
| 119 | |
| 120 | /* CE5: unused */ |
| 121 | { |
| 122 | .flags = CE_ATTR_FLAGS, |
| 123 | .src_nentries = 0, |
| 124 | .src_sz_max = 0, |
| 125 | .dest_nentries = 0, |
| 126 | }, |
| 127 | |
| 128 | /* CE6: target autonomous hif_memcpy */ |
| 129 | { |
| 130 | .flags = CE_ATTR_FLAGS, |
| 131 | .src_nentries = 0, |
| 132 | .src_sz_max = 0, |
| 133 | .dest_nentries = 0, |
| 134 | }, |
| 135 | |
| 136 | /* CE7: ce_diag, the Diagnostic Window */ |
| 137 | { |
| 138 | .flags = CE_ATTR_FLAGS, |
| 139 | .src_nentries = 2, |
| 140 | .src_sz_max = DIAG_TRANSFER_LIMIT, |
| 141 | .dest_nentries = 2, |
| 142 | }, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 143 | }; |
| 144 | |
| 145 | /* Target firmware's Copy Engine configuration. */ |
| 146 | static const struct ce_pipe_config target_ce_config_wlan[] = { |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 147 | /* CE0: host->target HTC control and raw streams */ |
| 148 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 149 | .pipenum = __cpu_to_le32(0), |
| 150 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 151 | .nentries = __cpu_to_le32(32), |
| 152 | .nbytes_max = __cpu_to_le32(256), |
| 153 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 154 | .reserved = __cpu_to_le32(0), |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 155 | }, |
| 156 | |
| 157 | /* CE1: target->host HTT + HTC control */ |
| 158 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 159 | .pipenum = __cpu_to_le32(1), |
| 160 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 161 | .nentries = __cpu_to_le32(32), |
| 162 | .nbytes_max = __cpu_to_le32(512), |
| 163 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 164 | .reserved = __cpu_to_le32(0), |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 165 | }, |
| 166 | |
| 167 | /* CE2: target->host WMI */ |
| 168 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 169 | .pipenum = __cpu_to_le32(2), |
| 170 | .pipedir = __cpu_to_le32(PIPEDIR_IN), |
| 171 | .nentries = __cpu_to_le32(32), |
| 172 | .nbytes_max = __cpu_to_le32(2048), |
| 173 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 174 | .reserved = __cpu_to_le32(0), |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 175 | }, |
| 176 | |
| 177 | /* CE3: host->target WMI */ |
| 178 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 179 | .pipenum = __cpu_to_le32(3), |
| 180 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 181 | .nentries = __cpu_to_le32(32), |
| 182 | .nbytes_max = __cpu_to_le32(2048), |
| 183 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 184 | .reserved = __cpu_to_le32(0), |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 185 | }, |
| 186 | |
| 187 | /* CE4: host->target HTT */ |
| 188 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 189 | .pipenum = __cpu_to_le32(4), |
| 190 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 191 | .nentries = __cpu_to_le32(256), |
| 192 | .nbytes_max = __cpu_to_le32(256), |
| 193 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 194 | .reserved = __cpu_to_le32(0), |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 195 | }, |
| 196 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 197 | /* NB: 50% of src nentries, since tx has 2 frags */ |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 198 | |
| 199 | /* CE5: unused */ |
| 200 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 201 | .pipenum = __cpu_to_le32(5), |
| 202 | .pipedir = __cpu_to_le32(PIPEDIR_OUT), |
| 203 | .nentries = __cpu_to_le32(32), |
| 204 | .nbytes_max = __cpu_to_le32(2048), |
| 205 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 206 | .reserved = __cpu_to_le32(0), |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 207 | }, |
| 208 | |
| 209 | /* CE6: Reserved for target autonomous hif_memcpy */ |
| 210 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 211 | .pipenum = __cpu_to_le32(6), |
| 212 | .pipedir = __cpu_to_le32(PIPEDIR_INOUT), |
| 213 | .nentries = __cpu_to_le32(32), |
| 214 | .nbytes_max = __cpu_to_le32(4096), |
| 215 | .flags = __cpu_to_le32(CE_ATTR_FLAGS), |
| 216 | .reserved = __cpu_to_le32(0), |
Kalle Valo | d88effb | 2013-09-01 10:01:39 +0300 | [diff] [blame] | 217 | }, |
| 218 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 219 | /* CE7 used only by Host */ |
| 220 | }; |
| 221 | |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 222 | /* |
| 223 | * Map from service/endpoint to Copy Engine. |
| 224 | * This table is derived from the CE_PCI TABLE, above. |
| 225 | * It is passed to the Target at startup for use by firmware. |
| 226 | */ |
| 227 | static const struct service_to_pipe target_service_to_ce_map_wlan[] = { |
| 228 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 229 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO), |
| 230 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 231 | __cpu_to_le32(3), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 232 | }, |
| 233 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 234 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VO), |
| 235 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 236 | __cpu_to_le32(2), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 237 | }, |
| 238 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 239 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK), |
| 240 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 241 | __cpu_to_le32(3), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 242 | }, |
| 243 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 244 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BK), |
| 245 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 246 | __cpu_to_le32(2), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 247 | }, |
| 248 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 249 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE), |
| 250 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 251 | __cpu_to_le32(3), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 252 | }, |
| 253 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 254 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_BE), |
| 255 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 256 | __cpu_to_le32(2), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 257 | }, |
| 258 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 259 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI), |
| 260 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 261 | __cpu_to_le32(3), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 262 | }, |
| 263 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 264 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_DATA_VI), |
| 265 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 266 | __cpu_to_le32(2), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 267 | }, |
| 268 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 269 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL), |
| 270 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 271 | __cpu_to_le32(3), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 272 | }, |
| 273 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 274 | __cpu_to_le32(ATH10K_HTC_SVC_ID_WMI_CONTROL), |
| 275 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 276 | __cpu_to_le32(2), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 277 | }, |
| 278 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 279 | __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL), |
| 280 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 281 | __cpu_to_le32(0), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 282 | }, |
| 283 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 284 | __cpu_to_le32(ATH10K_HTC_SVC_ID_RSVD_CTRL), |
| 285 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 286 | __cpu_to_le32(1), |
| 287 | }, |
| 288 | { /* not used */ |
| 289 | __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS), |
| 290 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 291 | __cpu_to_le32(0), |
| 292 | }, |
| 293 | { /* not used */ |
| 294 | __cpu_to_le32(ATH10K_HTC_SVC_ID_TEST_RAW_STREAMS), |
| 295 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 296 | __cpu_to_le32(1), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 297 | }, |
| 298 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 299 | __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG), |
| 300 | __cpu_to_le32(PIPEDIR_OUT), /* out = UL = host -> target */ |
| 301 | __cpu_to_le32(4), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 302 | }, |
| 303 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 304 | __cpu_to_le32(ATH10K_HTC_SVC_ID_HTT_DATA_MSG), |
| 305 | __cpu_to_le32(PIPEDIR_IN), /* in = DL = target -> host */ |
| 306 | __cpu_to_le32(1), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 307 | }, |
| 308 | |
| 309 | /* (Additions here) */ |
| 310 | |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 311 | { /* must be last */ |
| 312 | __cpu_to_le32(0), |
| 313 | __cpu_to_le32(0), |
| 314 | __cpu_to_le32(0), |
Michal Kazior | d7bfb7a | 2014-08-26 19:14:02 +0300 | [diff] [blame] | 315 | }, |
| 316 | }; |
| 317 | |
Michal Kazior | e539887 | 2013-11-25 14:06:20 +0100 | [diff] [blame] | 318 | static bool ath10k_pci_irq_pending(struct ath10k *ar) |
| 319 | { |
| 320 | u32 cause; |
| 321 | |
| 322 | /* Check if the shared legacy irq is for us */ |
| 323 | cause = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + |
| 324 | PCIE_INTR_CAUSE_ADDRESS); |
| 325 | if (cause & (PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL)) |
| 326 | return true; |
| 327 | |
| 328 | return false; |
| 329 | } |
| 330 | |
Michal Kazior | 2685218 | 2013-11-25 14:06:25 +0100 | [diff] [blame] | 331 | static void ath10k_pci_disable_and_clear_legacy_irq(struct ath10k *ar) |
| 332 | { |
| 333 | /* IMPORTANT: INTR_CLR register has to be set after |
| 334 | * INTR_ENABLE is set to 0, otherwise interrupt can not be |
| 335 | * really cleared. */ |
| 336 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS, |
| 337 | 0); |
| 338 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_CLR_ADDRESS, |
| 339 | PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL); |
| 340 | |
| 341 | /* IMPORTANT: this extra read transaction is required to |
| 342 | * flush the posted write buffer. */ |
Kalle Valo | cfbc06a | 2014-09-14 12:50:23 +0300 | [diff] [blame^] | 343 | (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + |
| 344 | PCIE_INTR_ENABLE_ADDRESS); |
Michal Kazior | 2685218 | 2013-11-25 14:06:25 +0100 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static void ath10k_pci_enable_legacy_irq(struct ath10k *ar) |
| 348 | { |
| 349 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + |
| 350 | PCIE_INTR_ENABLE_ADDRESS, |
| 351 | PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL); |
| 352 | |
| 353 | /* IMPORTANT: this extra read transaction is required to |
| 354 | * flush the posted write buffer. */ |
Kalle Valo | cfbc06a | 2014-09-14 12:50:23 +0300 | [diff] [blame^] | 355 | (void)ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + |
| 356 | PCIE_INTR_ENABLE_ADDRESS); |
Michal Kazior | 2685218 | 2013-11-25 14:06:25 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 359 | static inline const char *ath10k_pci_get_irq_method(struct ath10k *ar) |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 360 | { |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 361 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 362 | |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 363 | if (ar_pci->num_msi_intrs > 1) |
| 364 | return "msi-x"; |
| 365 | else if (ar_pci->num_msi_intrs == 1) |
| 366 | return "msi"; |
| 367 | else |
| 368 | return "legacy"; |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 369 | } |
| 370 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 371 | static int __ath10k_pci_rx_post_buf(struct ath10k_pci_pipe *pipe) |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 372 | { |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 373 | struct ath10k *ar = pipe->hif_ce_state; |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 374 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 375 | struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl; |
| 376 | struct sk_buff *skb; |
| 377 | dma_addr_t paddr; |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 378 | int ret; |
| 379 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 380 | lockdep_assert_held(&ar_pci->ce_lock); |
| 381 | |
| 382 | skb = dev_alloc_skb(pipe->buf_sz); |
| 383 | if (!skb) |
| 384 | return -ENOMEM; |
| 385 | |
| 386 | WARN_ONCE((unsigned long)skb->data & 3, "unaligned skb"); |
| 387 | |
| 388 | paddr = dma_map_single(ar->dev, skb->data, |
| 389 | skb->len + skb_tailroom(skb), |
| 390 | DMA_FROM_DEVICE); |
| 391 | if (unlikely(dma_mapping_error(ar->dev, paddr))) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 392 | ath10k_warn(ar, "failed to dma map pci rx buf\n"); |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 393 | dev_kfree_skb_any(skb); |
| 394 | return -EIO; |
| 395 | } |
| 396 | |
| 397 | ATH10K_SKB_CB(skb)->paddr = paddr; |
| 398 | |
| 399 | ret = __ath10k_ce_rx_post_buf(ce_pipe, skb, paddr); |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 400 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 401 | ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret); |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 402 | dma_unmap_single(ar->dev, paddr, skb->len + skb_tailroom(skb), |
| 403 | DMA_FROM_DEVICE); |
| 404 | dev_kfree_skb_any(skb); |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 405 | return ret; |
| 406 | } |
| 407 | |
| 408 | return 0; |
| 409 | } |
| 410 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 411 | static void __ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe) |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 412 | { |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 413 | struct ath10k *ar = pipe->hif_ce_state; |
| 414 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 415 | struct ath10k_ce_pipe *ce_pipe = pipe->ce_hdl; |
| 416 | int ret, num; |
| 417 | |
| 418 | lockdep_assert_held(&ar_pci->ce_lock); |
| 419 | |
| 420 | if (pipe->buf_sz == 0) |
| 421 | return; |
| 422 | |
| 423 | if (!ce_pipe->dest_ring) |
| 424 | return; |
| 425 | |
| 426 | num = __ath10k_ce_rx_num_free_bufs(ce_pipe); |
| 427 | while (num--) { |
| 428 | ret = __ath10k_pci_rx_post_buf(pipe); |
| 429 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 430 | ath10k_warn(ar, "failed to post pci rx buf: %d\n", ret); |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 431 | mod_timer(&ar_pci->rx_post_retry, jiffies + |
| 432 | ATH10K_PCI_RX_POST_RETRY_MS); |
| 433 | break; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
| 438 | static void ath10k_pci_rx_post_pipe(struct ath10k_pci_pipe *pipe) |
| 439 | { |
| 440 | struct ath10k *ar = pipe->hif_ce_state; |
| 441 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 442 | |
| 443 | spin_lock_bh(&ar_pci->ce_lock); |
| 444 | __ath10k_pci_rx_post_pipe(pipe); |
| 445 | spin_unlock_bh(&ar_pci->ce_lock); |
| 446 | } |
| 447 | |
| 448 | static void ath10k_pci_rx_post(struct ath10k *ar) |
| 449 | { |
| 450 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 451 | int i; |
| 452 | |
| 453 | spin_lock_bh(&ar_pci->ce_lock); |
| 454 | for (i = 0; i < CE_COUNT; i++) |
| 455 | __ath10k_pci_rx_post_pipe(&ar_pci->pipe_info[i]); |
| 456 | spin_unlock_bh(&ar_pci->ce_lock); |
| 457 | } |
| 458 | |
| 459 | static void ath10k_pci_rx_replenish_retry(unsigned long ptr) |
| 460 | { |
| 461 | struct ath10k *ar = (void *)ptr; |
| 462 | |
| 463 | ath10k_pci_rx_post(ar); |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 464 | } |
| 465 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 466 | /* |
| 467 | * Diagnostic read/write access is provided for startup/config/debug usage. |
| 468 | * Caller must guarantee proper alignment, when applicable, and single user |
| 469 | * at any moment. |
| 470 | */ |
| 471 | static int ath10k_pci_diag_read_mem(struct ath10k *ar, u32 address, void *data, |
| 472 | int nbytes) |
| 473 | { |
| 474 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 475 | int ret = 0; |
| 476 | u32 buf; |
| 477 | unsigned int completed_nbytes, orig_nbytes, remaining_bytes; |
| 478 | unsigned int id; |
| 479 | unsigned int flags; |
Michal Kazior | 2aa3911 | 2013-08-27 13:08:02 +0200 | [diff] [blame] | 480 | struct ath10k_ce_pipe *ce_diag; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 481 | /* Host buffer address in CE space */ |
| 482 | u32 ce_data; |
| 483 | dma_addr_t ce_data_base = 0; |
| 484 | void *data_buf = NULL; |
| 485 | int i; |
| 486 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 487 | ce_diag = ar_pci->ce_diag; |
| 488 | |
| 489 | /* |
| 490 | * Allocate a temporary bounce buffer to hold caller's data |
| 491 | * to be DMA'ed from Target. This guarantees |
| 492 | * 1) 4-byte alignment |
| 493 | * 2) Buffer in DMA-able space |
| 494 | */ |
| 495 | orig_nbytes = nbytes; |
Michal Kazior | 68c0324 | 2014-03-28 10:02:35 +0200 | [diff] [blame] | 496 | data_buf = (unsigned char *)dma_alloc_coherent(ar->dev, |
| 497 | orig_nbytes, |
| 498 | &ce_data_base, |
| 499 | GFP_ATOMIC); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 500 | |
| 501 | if (!data_buf) { |
| 502 | ret = -ENOMEM; |
| 503 | goto done; |
| 504 | } |
| 505 | memset(data_buf, 0, orig_nbytes); |
| 506 | |
| 507 | remaining_bytes = orig_nbytes; |
| 508 | ce_data = ce_data_base; |
| 509 | while (remaining_bytes) { |
| 510 | nbytes = min_t(unsigned int, remaining_bytes, |
| 511 | DIAG_TRANSFER_LIMIT); |
| 512 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 513 | ret = ath10k_ce_rx_post_buf(ce_diag, NULL, ce_data); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 514 | if (ret != 0) |
| 515 | goto done; |
| 516 | |
| 517 | /* Request CE to send from Target(!) address to Host buffer */ |
| 518 | /* |
| 519 | * The address supplied by the caller is in the |
| 520 | * Target CPU virtual address space. |
| 521 | * |
| 522 | * In order to use this address with the diagnostic CE, |
| 523 | * convert it from Target CPU virtual address space |
| 524 | * to CE address space |
| 525 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 526 | address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem, |
| 527 | address); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 528 | |
| 529 | ret = ath10k_ce_send(ce_diag, NULL, (u32)address, nbytes, 0, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 530 | 0); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 531 | if (ret) |
| 532 | goto done; |
| 533 | |
| 534 | i = 0; |
| 535 | while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf, |
| 536 | &completed_nbytes, |
| 537 | &id) != 0) { |
| 538 | mdelay(1); |
| 539 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
| 540 | ret = -EBUSY; |
| 541 | goto done; |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | if (nbytes != completed_nbytes) { |
| 546 | ret = -EIO; |
| 547 | goto done; |
| 548 | } |
| 549 | |
Kalle Valo | cfbc06a | 2014-09-14 12:50:23 +0300 | [diff] [blame^] | 550 | if (buf != (u32)address) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 551 | ret = -EIO; |
| 552 | goto done; |
| 553 | } |
| 554 | |
| 555 | i = 0; |
| 556 | while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf, |
| 557 | &completed_nbytes, |
| 558 | &id, &flags) != 0) { |
| 559 | mdelay(1); |
| 560 | |
| 561 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
| 562 | ret = -EBUSY; |
| 563 | goto done; |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | if (nbytes != completed_nbytes) { |
| 568 | ret = -EIO; |
| 569 | goto done; |
| 570 | } |
| 571 | |
| 572 | if (buf != ce_data) { |
| 573 | ret = -EIO; |
| 574 | goto done; |
| 575 | } |
| 576 | |
| 577 | remaining_bytes -= nbytes; |
| 578 | address += nbytes; |
| 579 | ce_data += nbytes; |
| 580 | } |
| 581 | |
| 582 | done: |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 583 | if (ret == 0) |
| 584 | memcpy(data, data_buf, orig_nbytes); |
| 585 | else |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 586 | ath10k_warn(ar, "failed to read diag value at 0x%x: %d\n", |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 587 | address, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 588 | |
| 589 | if (data_buf) |
Michal Kazior | 68c0324 | 2014-03-28 10:02:35 +0200 | [diff] [blame] | 590 | dma_free_coherent(ar->dev, orig_nbytes, data_buf, |
| 591 | ce_data_base); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 592 | |
| 593 | return ret; |
| 594 | } |
| 595 | |
Kalle Valo | 3d29a3e | 2014-08-25 08:37:26 +0300 | [diff] [blame] | 596 | static int ath10k_pci_diag_read32(struct ath10k *ar, u32 address, u32 *value) |
| 597 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 598 | __le32 val = 0; |
| 599 | int ret; |
| 600 | |
| 601 | ret = ath10k_pci_diag_read_mem(ar, address, &val, sizeof(val)); |
| 602 | *value = __le32_to_cpu(val); |
| 603 | |
| 604 | return ret; |
Kalle Valo | 3d29a3e | 2014-08-25 08:37:26 +0300 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | static int __ath10k_pci_diag_read_hi(struct ath10k *ar, void *dest, |
| 608 | u32 src, u32 len) |
| 609 | { |
| 610 | u32 host_addr, addr; |
| 611 | int ret; |
| 612 | |
| 613 | host_addr = host_interest_item_address(src); |
| 614 | |
| 615 | ret = ath10k_pci_diag_read32(ar, host_addr, &addr); |
| 616 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 617 | ath10k_warn(ar, "failed to get memcpy hi address for firmware address %d: %d\n", |
Kalle Valo | 3d29a3e | 2014-08-25 08:37:26 +0300 | [diff] [blame] | 618 | src, ret); |
| 619 | return ret; |
| 620 | } |
| 621 | |
| 622 | ret = ath10k_pci_diag_read_mem(ar, addr, dest, len); |
| 623 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 624 | ath10k_warn(ar, "failed to memcpy firmware memory from %d (%d B): %d\n", |
Kalle Valo | 3d29a3e | 2014-08-25 08:37:26 +0300 | [diff] [blame] | 625 | addr, len, ret); |
| 626 | return ret; |
| 627 | } |
| 628 | |
| 629 | return 0; |
| 630 | } |
| 631 | |
| 632 | #define ath10k_pci_diag_read_hi(ar, dest, src, len) \ |
| 633 | __ath10k_pci_diag_read_hi(ar, dest, HI_ITEM(src), len); |
| 634 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 635 | static int ath10k_pci_diag_write_mem(struct ath10k *ar, u32 address, |
| 636 | const void *data, int nbytes) |
| 637 | { |
| 638 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 639 | int ret = 0; |
| 640 | u32 buf; |
| 641 | unsigned int completed_nbytes, orig_nbytes, remaining_bytes; |
| 642 | unsigned int id; |
| 643 | unsigned int flags; |
Michal Kazior | 2aa3911 | 2013-08-27 13:08:02 +0200 | [diff] [blame] | 644 | struct ath10k_ce_pipe *ce_diag; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 645 | void *data_buf = NULL; |
| 646 | u32 ce_data; /* Host buffer address in CE space */ |
| 647 | dma_addr_t ce_data_base = 0; |
| 648 | int i; |
| 649 | |
| 650 | ce_diag = ar_pci->ce_diag; |
| 651 | |
| 652 | /* |
| 653 | * Allocate a temporary bounce buffer to hold caller's data |
| 654 | * to be DMA'ed to Target. This guarantees |
| 655 | * 1) 4-byte alignment |
| 656 | * 2) Buffer in DMA-able space |
| 657 | */ |
| 658 | orig_nbytes = nbytes; |
Michal Kazior | 68c0324 | 2014-03-28 10:02:35 +0200 | [diff] [blame] | 659 | data_buf = (unsigned char *)dma_alloc_coherent(ar->dev, |
| 660 | orig_nbytes, |
| 661 | &ce_data_base, |
| 662 | GFP_ATOMIC); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 663 | if (!data_buf) { |
| 664 | ret = -ENOMEM; |
| 665 | goto done; |
| 666 | } |
| 667 | |
| 668 | /* Copy caller's data to allocated DMA buf */ |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 669 | memcpy(data_buf, data, orig_nbytes); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 670 | |
| 671 | /* |
| 672 | * The address supplied by the caller is in the |
| 673 | * Target CPU virtual address space. |
| 674 | * |
| 675 | * In order to use this address with the diagnostic CE, |
| 676 | * convert it from |
| 677 | * Target CPU virtual address space |
| 678 | * to |
| 679 | * CE address space |
| 680 | */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 681 | address = TARG_CPU_SPACE_TO_CE_SPACE(ar, ar_pci->mem, address); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 682 | |
| 683 | remaining_bytes = orig_nbytes; |
| 684 | ce_data = ce_data_base; |
| 685 | while (remaining_bytes) { |
| 686 | /* FIXME: check cast */ |
| 687 | nbytes = min_t(int, remaining_bytes, DIAG_TRANSFER_LIMIT); |
| 688 | |
| 689 | /* Set up to receive directly into Target(!) address */ |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 690 | ret = ath10k_ce_rx_post_buf(ce_diag, NULL, address); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 691 | if (ret != 0) |
| 692 | goto done; |
| 693 | |
| 694 | /* |
| 695 | * Request CE to send caller-supplied data that |
| 696 | * was copied to bounce buffer to Target(!) address. |
| 697 | */ |
Kalle Valo | cfbc06a | 2014-09-14 12:50:23 +0300 | [diff] [blame^] | 698 | ret = ath10k_ce_send(ce_diag, NULL, (u32)ce_data, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 699 | nbytes, 0, 0); |
| 700 | if (ret != 0) |
| 701 | goto done; |
| 702 | |
| 703 | i = 0; |
| 704 | while (ath10k_ce_completed_send_next(ce_diag, NULL, &buf, |
| 705 | &completed_nbytes, |
| 706 | &id) != 0) { |
| 707 | mdelay(1); |
| 708 | |
| 709 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
| 710 | ret = -EBUSY; |
| 711 | goto done; |
| 712 | } |
| 713 | } |
| 714 | |
| 715 | if (nbytes != completed_nbytes) { |
| 716 | ret = -EIO; |
| 717 | goto done; |
| 718 | } |
| 719 | |
| 720 | if (buf != ce_data) { |
| 721 | ret = -EIO; |
| 722 | goto done; |
| 723 | } |
| 724 | |
| 725 | i = 0; |
| 726 | while (ath10k_ce_completed_recv_next(ce_diag, NULL, &buf, |
| 727 | &completed_nbytes, |
| 728 | &id, &flags) != 0) { |
| 729 | mdelay(1); |
| 730 | |
| 731 | if (i++ > DIAG_ACCESS_CE_TIMEOUT_MS) { |
| 732 | ret = -EBUSY; |
| 733 | goto done; |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | if (nbytes != completed_nbytes) { |
| 738 | ret = -EIO; |
| 739 | goto done; |
| 740 | } |
| 741 | |
| 742 | if (buf != address) { |
| 743 | ret = -EIO; |
| 744 | goto done; |
| 745 | } |
| 746 | |
| 747 | remaining_bytes -= nbytes; |
| 748 | address += nbytes; |
| 749 | ce_data += nbytes; |
| 750 | } |
| 751 | |
| 752 | done: |
| 753 | if (data_buf) { |
Michal Kazior | 68c0324 | 2014-03-28 10:02:35 +0200 | [diff] [blame] | 754 | dma_free_coherent(ar->dev, orig_nbytes, data_buf, |
| 755 | ce_data_base); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | if (ret != 0) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 759 | ath10k_warn(ar, "failed to write diag value at 0x%x: %d\n", |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 760 | address, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 761 | |
| 762 | return ret; |
| 763 | } |
| 764 | |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 765 | static int ath10k_pci_diag_write32(struct ath10k *ar, u32 address, u32 value) |
| 766 | { |
| 767 | __le32 val = __cpu_to_le32(value); |
| 768 | |
| 769 | return ath10k_pci_diag_write_mem(ar, address, &val, sizeof(val)); |
| 770 | } |
| 771 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 772 | static bool ath10k_pci_is_awake(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 773 | { |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 774 | u32 val = ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS); |
| 775 | |
| 776 | return RTC_STATE_V_GET(val) == RTC_STATE_V_ON; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 777 | } |
| 778 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 779 | static int ath10k_pci_wake_wait(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 780 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 781 | int tot_delay = 0; |
| 782 | int curr_delay = 5; |
| 783 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 784 | while (tot_delay < PCIE_WAKE_TIMEOUT) { |
| 785 | if (ath10k_pci_is_awake(ar)) |
Kalle Valo | 3aebe54 | 2013-09-01 10:02:07 +0300 | [diff] [blame] | 786 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 787 | |
| 788 | udelay(curr_delay); |
| 789 | tot_delay += curr_delay; |
| 790 | |
| 791 | if (curr_delay < 50) |
| 792 | curr_delay += 5; |
| 793 | } |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 794 | |
| 795 | return -ETIMEDOUT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 796 | } |
| 797 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 798 | static int ath10k_pci_wake(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 799 | { |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 800 | ath10k_pci_reg_write32(ar, PCIE_SOC_WAKE_ADDRESS, |
| 801 | PCIE_SOC_WAKE_V_MASK); |
| 802 | return ath10k_pci_wake_wait(ar); |
| 803 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 804 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 805 | static void ath10k_pci_sleep(struct ath10k *ar) |
| 806 | { |
| 807 | ath10k_pci_reg_write32(ar, PCIE_SOC_WAKE_ADDRESS, |
| 808 | PCIE_SOC_WAKE_RESET); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 809 | } |
| 810 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 811 | /* Called by lower (CE) layer when a send to Target completes. */ |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 812 | static void ath10k_pci_ce_send_done(struct ath10k_ce_pipe *ce_state) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 813 | { |
| 814 | struct ath10k *ar = ce_state->ar; |
| 815 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 816 | struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current; |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 817 | void *transfer_context; |
| 818 | u32 ce_data; |
| 819 | unsigned int nbytes; |
| 820 | unsigned int transfer_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 821 | |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 822 | while (ath10k_ce_completed_send_next(ce_state, &transfer_context, |
| 823 | &ce_data, &nbytes, |
| 824 | &transfer_id) == 0) { |
Michal Kazior | a16942e | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 825 | /* no need to call tx completion for NULL pointers */ |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 826 | if (transfer_context == NULL) |
| 827 | continue; |
| 828 | |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 829 | cb->tx_completion(ar, transfer_context, transfer_id); |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 830 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | /* Called by lower (CE) layer when data is received from the Target. */ |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 834 | static void ath10k_pci_ce_recv_data(struct ath10k_ce_pipe *ce_state) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 835 | { |
| 836 | struct ath10k *ar = ce_state->ar; |
| 837 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | 87263e5 | 2013-08-27 13:08:01 +0200 | [diff] [blame] | 838 | struct ath10k_pci_pipe *pipe_info = &ar_pci->pipe_info[ce_state->id]; |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 839 | struct ath10k_hif_cb *cb = &ar_pci->msg_callbacks_current; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 840 | struct sk_buff *skb; |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 841 | void *transfer_context; |
| 842 | u32 ce_data; |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 843 | unsigned int nbytes, max_nbytes; |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 844 | unsigned int transfer_id; |
| 845 | unsigned int flags; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 846 | |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 847 | while (ath10k_ce_completed_recv_next(ce_state, &transfer_context, |
| 848 | &ce_data, &nbytes, &transfer_id, |
| 849 | &flags) == 0) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 850 | skb = transfer_context; |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 851 | max_nbytes = skb->len + skb_tailroom(skb); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 852 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(skb)->paddr, |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 853 | max_nbytes, DMA_FROM_DEVICE); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 854 | |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 855 | if (unlikely(max_nbytes < nbytes)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 856 | ath10k_warn(ar, "rxed more than expected (nbytes %d, max %d)", |
Michal Kazior | 2f5280d | 2014-02-27 18:50:05 +0200 | [diff] [blame] | 857 | nbytes, max_nbytes); |
| 858 | dev_kfree_skb_any(skb); |
| 859 | continue; |
| 860 | } |
| 861 | |
| 862 | skb_put(skb, nbytes); |
| 863 | cb->rx_completion(ar, skb, pipe_info->pipe_num); |
| 864 | } |
Michal Kazior | c29a380 | 2014-07-21 21:03:10 +0300 | [diff] [blame] | 865 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 866 | ath10k_pci_rx_post_pipe(pipe_info); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 867 | } |
| 868 | |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 869 | static int ath10k_pci_hif_tx_sg(struct ath10k *ar, u8 pipe_id, |
| 870 | struct ath10k_hif_sg_item *items, int n_items) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 871 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 872 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 873 | struct ath10k_pci_pipe *pci_pipe = &ar_pci->pipe_info[pipe_id]; |
| 874 | struct ath10k_ce_pipe *ce_pipe = pci_pipe->ce_hdl; |
| 875 | struct ath10k_ce_ring *src_ring = ce_pipe->src_ring; |
Michal Kazior | 7147a13 | 2014-05-26 12:02:58 +0200 | [diff] [blame] | 876 | unsigned int nentries_mask; |
| 877 | unsigned int sw_index; |
| 878 | unsigned int write_index; |
Michal Kazior | 08b8aa0 | 2014-05-26 12:02:59 +0200 | [diff] [blame] | 879 | int err, i = 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 880 | |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 881 | spin_lock_bh(&ar_pci->ce_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 882 | |
Michal Kazior | 7147a13 | 2014-05-26 12:02:58 +0200 | [diff] [blame] | 883 | nentries_mask = src_ring->nentries_mask; |
| 884 | sw_index = src_ring->sw_index; |
| 885 | write_index = src_ring->write_index; |
| 886 | |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 887 | if (unlikely(CE_RING_DELTA(nentries_mask, |
| 888 | write_index, sw_index - 1) < n_items)) { |
| 889 | err = -ENOBUFS; |
Michal Kazior | 08b8aa0 | 2014-05-26 12:02:59 +0200 | [diff] [blame] | 890 | goto err; |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 891 | } |
| 892 | |
| 893 | for (i = 0; i < n_items - 1; i++) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 894 | ath10k_dbg(ar, ATH10K_DBG_PCI, |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 895 | "pci tx item %d paddr 0x%08x len %d n_items %d\n", |
| 896 | i, items[i].paddr, items[i].len, n_items); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 897 | ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ", |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 898 | items[i].vaddr, items[i].len); |
| 899 | |
| 900 | err = ath10k_ce_send_nolock(ce_pipe, |
| 901 | items[i].transfer_context, |
| 902 | items[i].paddr, |
| 903 | items[i].len, |
| 904 | items[i].transfer_id, |
| 905 | CE_SEND_FLAG_GATHER); |
| 906 | if (err) |
Michal Kazior | 08b8aa0 | 2014-05-26 12:02:59 +0200 | [diff] [blame] | 907 | goto err; |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /* `i` is equal to `n_items -1` after for() */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 911 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 912 | ath10k_dbg(ar, ATH10K_DBG_PCI, |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 913 | "pci tx item %d paddr 0x%08x len %d n_items %d\n", |
| 914 | i, items[i].paddr, items[i].len, n_items); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 915 | ath10k_dbg_dump(ar, ATH10K_DBG_PCI_DUMP, NULL, "pci tx data: ", |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 916 | items[i].vaddr, items[i].len); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 917 | |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 918 | err = ath10k_ce_send_nolock(ce_pipe, |
| 919 | items[i].transfer_context, |
| 920 | items[i].paddr, |
| 921 | items[i].len, |
| 922 | items[i].transfer_id, |
| 923 | 0); |
| 924 | if (err) |
Michal Kazior | 08b8aa0 | 2014-05-26 12:02:59 +0200 | [diff] [blame] | 925 | goto err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 926 | |
Michal Kazior | 08b8aa0 | 2014-05-26 12:02:59 +0200 | [diff] [blame] | 927 | spin_unlock_bh(&ar_pci->ce_lock); |
| 928 | return 0; |
| 929 | |
| 930 | err: |
| 931 | for (; i > 0; i--) |
| 932 | __ath10k_ce_send_revert(ce_pipe); |
| 933 | |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 934 | spin_unlock_bh(&ar_pci->ce_lock); |
| 935 | return err; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | static u16 ath10k_pci_hif_get_free_queue_number(struct ath10k *ar, u8 pipe) |
| 939 | { |
| 940 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 941 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 942 | ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get free queue number\n"); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 943 | |
Michal Kazior | 3efcb3b | 2013-10-02 11:03:41 +0200 | [diff] [blame] | 944 | return ath10k_ce_num_free_src_entries(ar_pci->pipe_info[pipe].ce_hdl); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 945 | } |
| 946 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 947 | static void ath10k_pci_dump_registers(struct ath10k *ar, |
| 948 | struct ath10k_fw_crash_data *crash_data) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 949 | { |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 950 | __le32 reg_dump_values[REG_DUMP_COUNT_QCA988X] = {}; |
| 951 | int i, ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 952 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 953 | lockdep_assert_held(&ar->data_lock); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 954 | |
Kalle Valo | 3d29a3e | 2014-08-25 08:37:26 +0300 | [diff] [blame] | 955 | ret = ath10k_pci_diag_read_hi(ar, ®_dump_values[0], |
| 956 | hi_failure_state, |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 957 | REG_DUMP_COUNT_QCA988X * sizeof(__le32)); |
Michal Kazior | 1d2b48d | 2013-11-08 08:01:34 +0100 | [diff] [blame] | 958 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 959 | ath10k_err(ar, "failed to read firmware dump area: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | |
| 963 | BUILD_BUG_ON(REG_DUMP_COUNT_QCA988X % 4); |
| 964 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 965 | ath10k_err(ar, "firmware register dump:\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 966 | for (i = 0; i < REG_DUMP_COUNT_QCA988X; i += 4) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 967 | ath10k_err(ar, "[%02d]: 0x%08X 0x%08X 0x%08X 0x%08X\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 968 | i, |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 969 | __le32_to_cpu(reg_dump_values[i]), |
| 970 | __le32_to_cpu(reg_dump_values[i + 1]), |
| 971 | __le32_to_cpu(reg_dump_values[i + 2]), |
| 972 | __le32_to_cpu(reg_dump_values[i + 3])); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 973 | |
Michal Kazior | 1bbb119 | 2014-08-25 12:13:14 +0200 | [diff] [blame] | 974 | if (!crash_data) |
| 975 | return; |
| 976 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 977 | for (i = 0; i < REG_DUMP_COUNT_QCA988X; i++) |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 978 | crash_data->registers[i] = reg_dump_values[i]; |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 979 | } |
| 980 | |
Kalle Valo | 0e9848c | 2014-08-25 08:37:37 +0300 | [diff] [blame] | 981 | static void ath10k_pci_fw_crashed_dump(struct ath10k *ar) |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 982 | { |
| 983 | struct ath10k_fw_crash_data *crash_data; |
| 984 | char uuid[50]; |
| 985 | |
| 986 | spin_lock_bh(&ar->data_lock); |
| 987 | |
| 988 | crash_data = ath10k_debug_get_new_fw_crash_data(ar); |
| 989 | |
| 990 | if (crash_data) |
| 991 | scnprintf(uuid, sizeof(uuid), "%pUl", &crash_data->uuid); |
| 992 | else |
| 993 | scnprintf(uuid, sizeof(uuid), "n/a"); |
| 994 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 995 | ath10k_err(ar, "firmware crashed! (uuid %s)\n", uuid); |
Kalle Valo | 8a0c797 | 2014-08-25 08:37:45 +0300 | [diff] [blame] | 996 | ath10k_print_driver_info(ar); |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 997 | ath10k_pci_dump_registers(ar, crash_data); |
| 998 | |
Ben Greear | 384914b | 2014-08-25 08:37:32 +0300 | [diff] [blame] | 999 | spin_unlock_bh(&ar->data_lock); |
Michal Kazior | affd321 | 2013-07-16 09:54:35 +0200 | [diff] [blame] | 1000 | |
Michal Kazior | 5e90de8 | 2013-10-16 16:46:05 +0300 | [diff] [blame] | 1001 | queue_work(ar->workqueue, &ar->restart_work); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | static void ath10k_pci_hif_send_complete_check(struct ath10k *ar, u8 pipe, |
| 1005 | int force) |
| 1006 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1007 | ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif send complete check\n"); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 1008 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1009 | if (!force) { |
| 1010 | int resources; |
| 1011 | /* |
| 1012 | * Decide whether to actually poll for completions, or just |
| 1013 | * wait for a later chance. |
| 1014 | * If there seem to be plenty of resources left, then just wait |
| 1015 | * since checking involves reading a CE register, which is a |
| 1016 | * relatively expensive operation. |
| 1017 | */ |
| 1018 | resources = ath10k_pci_hif_get_free_queue_number(ar, pipe); |
| 1019 | |
| 1020 | /* |
| 1021 | * If at least 50% of the total resources are still available, |
| 1022 | * don't bother checking again yet. |
| 1023 | */ |
| 1024 | if (resources > (host_ce_config_wlan[pipe].src_nentries >> 1)) |
| 1025 | return; |
| 1026 | } |
| 1027 | ath10k_ce_per_engine_service(ar, pipe); |
| 1028 | } |
| 1029 | |
Michal Kazior | e799bbf | 2013-07-05 16:15:12 +0300 | [diff] [blame] | 1030 | static void ath10k_pci_hif_set_callbacks(struct ath10k *ar, |
| 1031 | struct ath10k_hif_cb *callbacks) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1032 | { |
| 1033 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 1034 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1035 | ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif set callbacks\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1036 | |
| 1037 | memcpy(&ar_pci->msg_callbacks_current, callbacks, |
| 1038 | sizeof(ar_pci->msg_callbacks_current)); |
| 1039 | } |
| 1040 | |
Michal Kazior | 96a9d0d | 2013-11-08 08:01:25 +0100 | [diff] [blame] | 1041 | static void ath10k_pci_kill_tasklet(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1042 | { |
| 1043 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1044 | int i; |
| 1045 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1046 | tasklet_kill(&ar_pci->intr_tq); |
Michal Kazior | 103d4f5 | 2013-11-08 08:01:24 +0100 | [diff] [blame] | 1047 | tasklet_kill(&ar_pci->msi_fw_err); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1048 | |
| 1049 | for (i = 0; i < CE_COUNT; i++) |
| 1050 | tasklet_kill(&ar_pci->pipe_info[i].intr); |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 1051 | |
| 1052 | del_timer_sync(&ar_pci->rx_post_retry); |
Michal Kazior | 96a9d0d | 2013-11-08 08:01:25 +0100 | [diff] [blame] | 1053 | } |
| 1054 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1055 | static int ath10k_pci_hif_map_service_to_pipe(struct ath10k *ar, |
| 1056 | u16 service_id, u8 *ul_pipe, |
| 1057 | u8 *dl_pipe, int *ul_is_polled, |
| 1058 | int *dl_is_polled) |
| 1059 | { |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1060 | const struct service_to_pipe *entry; |
| 1061 | bool ul_set = false, dl_set = false; |
| 1062 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1063 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1064 | ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif map service\n"); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 1065 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1066 | /* polling for received messages not supported */ |
| 1067 | *dl_is_polled = 0; |
| 1068 | |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1069 | for (i = 0; i < ARRAY_SIZE(target_service_to_ce_map_wlan); i++) { |
| 1070 | entry = &target_service_to_ce_map_wlan[i]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1071 | |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1072 | if (__le32_to_cpu(entry->service_id) != service_id) |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1073 | continue; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1074 | |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1075 | switch (__le32_to_cpu(entry->pipedir)) { |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1076 | case PIPEDIR_NONE: |
| 1077 | break; |
| 1078 | case PIPEDIR_IN: |
| 1079 | WARN_ON(dl_set); |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1080 | *dl_pipe = __le32_to_cpu(entry->pipenum); |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1081 | dl_set = true; |
| 1082 | break; |
| 1083 | case PIPEDIR_OUT: |
| 1084 | WARN_ON(ul_set); |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1085 | *ul_pipe = __le32_to_cpu(entry->pipenum); |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1086 | ul_set = true; |
| 1087 | break; |
| 1088 | case PIPEDIR_INOUT: |
| 1089 | WARN_ON(dl_set); |
| 1090 | WARN_ON(ul_set); |
Michal Kazior | 0fdc14e4 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1091 | *dl_pipe = __le32_to_cpu(entry->pipenum); |
| 1092 | *ul_pipe = __le32_to_cpu(entry->pipenum); |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1093 | dl_set = true; |
| 1094 | ul_set = true; |
| 1095 | break; |
| 1096 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1097 | } |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1098 | |
| 1099 | if (WARN_ON(!ul_set || !dl_set)) |
| 1100 | return -ENOENT; |
| 1101 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1102 | *ul_is_polled = |
| 1103 | (host_ce_config_wlan[*ul_pipe].flags & CE_ATTR_DIS_INTR) != 0; |
| 1104 | |
Michal Kazior | 7c6aa25 | 2014-08-26 19:14:03 +0300 | [diff] [blame] | 1105 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1106 | } |
| 1107 | |
| 1108 | static void ath10k_pci_hif_get_default_pipe(struct ath10k *ar, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1109 | u8 *ul_pipe, u8 *dl_pipe) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1110 | { |
| 1111 | int ul_is_polled, dl_is_polled; |
| 1112 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1113 | ath10k_dbg(ar, ATH10K_DBG_PCI, "pci hif get default pipe\n"); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 1114 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1115 | (void)ath10k_pci_hif_map_service_to_pipe(ar, |
| 1116 | ATH10K_HTC_SVC_ID_RSVD_CTRL, |
| 1117 | ul_pipe, |
| 1118 | dl_pipe, |
| 1119 | &ul_is_polled, |
| 1120 | &dl_is_polled); |
| 1121 | } |
| 1122 | |
Michal Kazior | ec5ba4d | 2014-08-22 14:23:33 +0200 | [diff] [blame] | 1123 | static void ath10k_pci_irq_disable(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1124 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1125 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | ec5ba4d | 2014-08-22 14:23:33 +0200 | [diff] [blame] | 1126 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1127 | |
Michal Kazior | ec5ba4d | 2014-08-22 14:23:33 +0200 | [diff] [blame] | 1128 | ath10k_ce_disable_interrupts(ar); |
Michal Kazior | e75db4e | 2014-08-28 22:14:16 +0300 | [diff] [blame] | 1129 | ath10k_pci_disable_and_clear_legacy_irq(ar); |
| 1130 | /* FIXME: How to mask all MSI interrupts? */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1131 | |
Michal Kazior | ec5ba4d | 2014-08-22 14:23:33 +0200 | [diff] [blame] | 1132 | for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++) |
| 1133 | synchronize_irq(ar_pci->pdev->irq + i); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1134 | } |
| 1135 | |
Michal Kazior | ec5ba4d | 2014-08-22 14:23:33 +0200 | [diff] [blame] | 1136 | static void ath10k_pci_irq_enable(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1137 | { |
Michal Kazior | ec5ba4d | 2014-08-22 14:23:33 +0200 | [diff] [blame] | 1138 | ath10k_ce_enable_interrupts(ar); |
Michal Kazior | e75db4e | 2014-08-28 22:14:16 +0300 | [diff] [blame] | 1139 | ath10k_pci_enable_legacy_irq(ar); |
| 1140 | /* FIXME: How to unmask all MSI interrupts? */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | static int ath10k_pci_hif_start(struct ath10k *ar) |
| 1144 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1145 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif start\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1146 | |
Michal Kazior | ec5ba4d | 2014-08-22 14:23:33 +0200 | [diff] [blame] | 1147 | ath10k_pci_irq_enable(ar); |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 1148 | ath10k_pci_rx_post(ar); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 1149 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1150 | return 0; |
| 1151 | } |
| 1152 | |
Michal Kazior | 87263e5 | 2013-08-27 13:08:01 +0200 | [diff] [blame] | 1153 | static void ath10k_pci_rx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1154 | { |
| 1155 | struct ath10k *ar; |
| 1156 | struct ath10k_pci *ar_pci; |
Michal Kazior | 2aa3911 | 2013-08-27 13:08:02 +0200 | [diff] [blame] | 1157 | struct ath10k_ce_pipe *ce_hdl; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1158 | u32 buf_sz; |
| 1159 | struct sk_buff *netbuf; |
| 1160 | u32 ce_data; |
| 1161 | |
| 1162 | buf_sz = pipe_info->buf_sz; |
| 1163 | |
| 1164 | /* Unused Copy Engine */ |
| 1165 | if (buf_sz == 0) |
| 1166 | return; |
| 1167 | |
| 1168 | ar = pipe_info->hif_ce_state; |
| 1169 | ar_pci = ath10k_pci_priv(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1170 | ce_hdl = pipe_info->ce_hdl; |
| 1171 | |
| 1172 | while (ath10k_ce_revoke_recv_next(ce_hdl, (void **)&netbuf, |
| 1173 | &ce_data) == 0) { |
| 1174 | dma_unmap_single(ar->dev, ATH10K_SKB_CB(netbuf)->paddr, |
| 1175 | netbuf->len + skb_tailroom(netbuf), |
| 1176 | DMA_FROM_DEVICE); |
| 1177 | dev_kfree_skb_any(netbuf); |
| 1178 | } |
| 1179 | } |
| 1180 | |
Michal Kazior | 87263e5 | 2013-08-27 13:08:01 +0200 | [diff] [blame] | 1181 | static void ath10k_pci_tx_pipe_cleanup(struct ath10k_pci_pipe *pipe_info) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1182 | { |
| 1183 | struct ath10k *ar; |
| 1184 | struct ath10k_pci *ar_pci; |
Michal Kazior | 2aa3911 | 2013-08-27 13:08:02 +0200 | [diff] [blame] | 1185 | struct ath10k_ce_pipe *ce_hdl; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1186 | struct sk_buff *netbuf; |
| 1187 | u32 ce_data; |
| 1188 | unsigned int nbytes; |
| 1189 | unsigned int id; |
| 1190 | u32 buf_sz; |
| 1191 | |
| 1192 | buf_sz = pipe_info->buf_sz; |
| 1193 | |
| 1194 | /* Unused Copy Engine */ |
| 1195 | if (buf_sz == 0) |
| 1196 | return; |
| 1197 | |
| 1198 | ar = pipe_info->hif_ce_state; |
| 1199 | ar_pci = ath10k_pci_priv(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1200 | ce_hdl = pipe_info->ce_hdl; |
| 1201 | |
| 1202 | while (ath10k_ce_cancel_send_next(ce_hdl, (void **)&netbuf, |
| 1203 | &ce_data, &nbytes, &id) == 0) { |
Michal Kazior | a16942e | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1204 | /* no need to call tx completion for NULL pointers */ |
| 1205 | if (!netbuf) |
Michal Kazior | 2415fc1 | 2013-11-08 08:01:32 +0100 | [diff] [blame] | 1206 | continue; |
Michal Kazior | 2415fc1 | 2013-11-08 08:01:32 +0100 | [diff] [blame] | 1207 | |
Kalle Valo | e9bb0aa | 2013-09-08 18:36:11 +0300 | [diff] [blame] | 1208 | ar_pci->msg_callbacks_current.tx_completion(ar, |
| 1209 | netbuf, |
| 1210 | id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | /* |
| 1215 | * Cleanup residual buffers for device shutdown: |
| 1216 | * buffers that were enqueued for receive |
| 1217 | * buffers that were to be sent |
| 1218 | * Note: Buffers that had completed but which were |
| 1219 | * not yet processed are on a completion queue. They |
| 1220 | * are handled when the completion thread shuts down. |
| 1221 | */ |
| 1222 | static void ath10k_pci_buffer_cleanup(struct ath10k *ar) |
| 1223 | { |
| 1224 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 1225 | int pipe_num; |
| 1226 | |
Michal Kazior | fad6ed7 | 2013-11-08 08:01:23 +0100 | [diff] [blame] | 1227 | for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) { |
Michal Kazior | 87263e5 | 2013-08-27 13:08:01 +0200 | [diff] [blame] | 1228 | struct ath10k_pci_pipe *pipe_info; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1229 | |
| 1230 | pipe_info = &ar_pci->pipe_info[pipe_num]; |
| 1231 | ath10k_pci_rx_pipe_cleanup(pipe_info); |
| 1232 | ath10k_pci_tx_pipe_cleanup(pipe_info); |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | static void ath10k_pci_ce_deinit(struct ath10k *ar) |
| 1237 | { |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1238 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1239 | |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1240 | for (i = 0; i < CE_COUNT; i++) |
| 1241 | ath10k_ce_deinit_pipe(ar, i); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1242 | } |
| 1243 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 1244 | static void ath10k_pci_flush(struct ath10k *ar) |
| 1245 | { |
| 1246 | ath10k_pci_kill_tasklet(ar); |
| 1247 | ath10k_pci_buffer_cleanup(ar); |
| 1248 | } |
| 1249 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1250 | static void ath10k_pci_hif_stop(struct ath10k *ar) |
| 1251 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1252 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif stop\n"); |
Michal Kazior | 32270b6 | 2013-08-02 09:15:47 +0200 | [diff] [blame] | 1253 | |
Michal Kazior | 10d23db | 2014-08-22 14:33:15 +0200 | [diff] [blame] | 1254 | /* Most likely the device has HTT Rx ring configured. The only way to |
| 1255 | * prevent the device from accessing (and possible corrupting) host |
| 1256 | * memory is to reset the chip now. |
Michal Kazior | e75db4e | 2014-08-28 22:14:16 +0300 | [diff] [blame] | 1257 | * |
| 1258 | * There's also no known way of masking MSI interrupts on the device. |
| 1259 | * For ranged MSI the CE-related interrupts can be masked. However |
| 1260 | * regardless how many MSI interrupts are assigned the first one |
| 1261 | * is always used for firmware indications (crashes) and cannot be |
| 1262 | * masked. To prevent the device from asserting the interrupt reset it |
| 1263 | * before proceeding with cleanup. |
Michal Kazior | 10d23db | 2014-08-22 14:33:15 +0200 | [diff] [blame] | 1264 | */ |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1265 | ath10k_pci_warm_reset(ar); |
Michal Kazior | e75db4e | 2014-08-28 22:14:16 +0300 | [diff] [blame] | 1266 | |
| 1267 | ath10k_pci_irq_disable(ar); |
| 1268 | ath10k_pci_flush(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1269 | } |
| 1270 | |
| 1271 | static int ath10k_pci_hif_exchange_bmi_msg(struct ath10k *ar, |
| 1272 | void *req, u32 req_len, |
| 1273 | void *resp, u32 *resp_len) |
| 1274 | { |
| 1275 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | 2aa3911 | 2013-08-27 13:08:02 +0200 | [diff] [blame] | 1276 | struct ath10k_pci_pipe *pci_tx = &ar_pci->pipe_info[BMI_CE_NUM_TO_TARG]; |
| 1277 | struct ath10k_pci_pipe *pci_rx = &ar_pci->pipe_info[BMI_CE_NUM_TO_HOST]; |
| 1278 | struct ath10k_ce_pipe *ce_tx = pci_tx->ce_hdl; |
| 1279 | struct ath10k_ce_pipe *ce_rx = pci_rx->ce_hdl; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1280 | dma_addr_t req_paddr = 0; |
| 1281 | dma_addr_t resp_paddr = 0; |
| 1282 | struct bmi_xfer xfer = {}; |
| 1283 | void *treq, *tresp = NULL; |
| 1284 | int ret = 0; |
| 1285 | |
Michal Kazior | 85622cd | 2013-11-25 14:06:22 +0100 | [diff] [blame] | 1286 | might_sleep(); |
| 1287 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1288 | if (resp && !resp_len) |
| 1289 | return -EINVAL; |
| 1290 | |
| 1291 | if (resp && resp_len && *resp_len == 0) |
| 1292 | return -EINVAL; |
| 1293 | |
| 1294 | treq = kmemdup(req, req_len, GFP_KERNEL); |
| 1295 | if (!treq) |
| 1296 | return -ENOMEM; |
| 1297 | |
| 1298 | req_paddr = dma_map_single(ar->dev, treq, req_len, DMA_TO_DEVICE); |
| 1299 | ret = dma_mapping_error(ar->dev, req_paddr); |
| 1300 | if (ret) |
| 1301 | goto err_dma; |
| 1302 | |
| 1303 | if (resp && resp_len) { |
| 1304 | tresp = kzalloc(*resp_len, GFP_KERNEL); |
| 1305 | if (!tresp) { |
| 1306 | ret = -ENOMEM; |
| 1307 | goto err_req; |
| 1308 | } |
| 1309 | |
| 1310 | resp_paddr = dma_map_single(ar->dev, tresp, *resp_len, |
| 1311 | DMA_FROM_DEVICE); |
| 1312 | ret = dma_mapping_error(ar->dev, resp_paddr); |
| 1313 | if (ret) |
| 1314 | goto err_req; |
| 1315 | |
| 1316 | xfer.wait_for_resp = true; |
| 1317 | xfer.resp_len = 0; |
| 1318 | |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 1319 | ath10k_ce_rx_post_buf(ce_rx, &xfer, resp_paddr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1320 | } |
| 1321 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1322 | ret = ath10k_ce_send(ce_tx, &xfer, req_paddr, req_len, -1, 0); |
| 1323 | if (ret) |
| 1324 | goto err_resp; |
| 1325 | |
Michal Kazior | 85622cd | 2013-11-25 14:06:22 +0100 | [diff] [blame] | 1326 | ret = ath10k_pci_bmi_wait(ce_tx, ce_rx, &xfer); |
| 1327 | if (ret) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1328 | u32 unused_buffer; |
| 1329 | unsigned int unused_nbytes; |
| 1330 | unsigned int unused_id; |
| 1331 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1332 | ath10k_ce_cancel_send_next(ce_tx, NULL, &unused_buffer, |
| 1333 | &unused_nbytes, &unused_id); |
| 1334 | } else { |
| 1335 | /* non-zero means we did not time out */ |
| 1336 | ret = 0; |
| 1337 | } |
| 1338 | |
| 1339 | err_resp: |
| 1340 | if (resp) { |
| 1341 | u32 unused_buffer; |
| 1342 | |
| 1343 | ath10k_ce_revoke_recv_next(ce_rx, NULL, &unused_buffer); |
| 1344 | dma_unmap_single(ar->dev, resp_paddr, |
| 1345 | *resp_len, DMA_FROM_DEVICE); |
| 1346 | } |
| 1347 | err_req: |
| 1348 | dma_unmap_single(ar->dev, req_paddr, req_len, DMA_TO_DEVICE); |
| 1349 | |
| 1350 | if (ret == 0 && resp_len) { |
| 1351 | *resp_len = min(*resp_len, xfer.resp_len); |
| 1352 | memcpy(resp, tresp, xfer.resp_len); |
| 1353 | } |
| 1354 | err_dma: |
| 1355 | kfree(treq); |
| 1356 | kfree(tresp); |
| 1357 | |
| 1358 | return ret; |
| 1359 | } |
| 1360 | |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 1361 | static void ath10k_pci_bmi_send_done(struct ath10k_ce_pipe *ce_state) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1362 | { |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 1363 | struct bmi_xfer *xfer; |
| 1364 | u32 ce_data; |
| 1365 | unsigned int nbytes; |
| 1366 | unsigned int transfer_id; |
| 1367 | |
| 1368 | if (ath10k_ce_completed_send_next(ce_state, (void **)&xfer, &ce_data, |
| 1369 | &nbytes, &transfer_id)) |
| 1370 | return; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1371 | |
Michal Kazior | 2374b18 | 2014-07-14 16:25:25 +0300 | [diff] [blame] | 1372 | xfer->tx_done = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1373 | } |
| 1374 | |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 1375 | static void ath10k_pci_bmi_recv_data(struct ath10k_ce_pipe *ce_state) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1376 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1377 | struct ath10k *ar = ce_state->ar; |
Michal Kazior | 5440ce2 | 2013-09-03 15:09:58 +0200 | [diff] [blame] | 1378 | struct bmi_xfer *xfer; |
| 1379 | u32 ce_data; |
| 1380 | unsigned int nbytes; |
| 1381 | unsigned int transfer_id; |
| 1382 | unsigned int flags; |
| 1383 | |
| 1384 | if (ath10k_ce_completed_recv_next(ce_state, (void **)&xfer, &ce_data, |
| 1385 | &nbytes, &transfer_id, &flags)) |
| 1386 | return; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1387 | |
| 1388 | if (!xfer->wait_for_resp) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1389 | ath10k_warn(ar, "unexpected: BMI data received; ignoring\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1390 | return; |
| 1391 | } |
| 1392 | |
| 1393 | xfer->resp_len = nbytes; |
Michal Kazior | 2374b18 | 2014-07-14 16:25:25 +0300 | [diff] [blame] | 1394 | xfer->rx_done = true; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1395 | } |
| 1396 | |
Michal Kazior | 85622cd | 2013-11-25 14:06:22 +0100 | [diff] [blame] | 1397 | static int ath10k_pci_bmi_wait(struct ath10k_ce_pipe *tx_pipe, |
| 1398 | struct ath10k_ce_pipe *rx_pipe, |
| 1399 | struct bmi_xfer *xfer) |
| 1400 | { |
| 1401 | unsigned long timeout = jiffies + BMI_COMMUNICATION_TIMEOUT_HZ; |
| 1402 | |
| 1403 | while (time_before_eq(jiffies, timeout)) { |
| 1404 | ath10k_pci_bmi_send_done(tx_pipe); |
| 1405 | ath10k_pci_bmi_recv_data(rx_pipe); |
| 1406 | |
Michal Kazior | 2374b18 | 2014-07-14 16:25:25 +0300 | [diff] [blame] | 1407 | if (xfer->tx_done && (xfer->rx_done == xfer->wait_for_resp)) |
Michal Kazior | 85622cd | 2013-11-25 14:06:22 +0100 | [diff] [blame] | 1408 | return 0; |
| 1409 | |
| 1410 | schedule(); |
| 1411 | } |
| 1412 | |
| 1413 | return -ETIMEDOUT; |
| 1414 | } |
| 1415 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1416 | /* |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1417 | * Send an interrupt to the device to wake up the Target CPU |
| 1418 | * so it has an opportunity to notice any changed state. |
| 1419 | */ |
| 1420 | static int ath10k_pci_wake_target_cpu(struct ath10k *ar) |
| 1421 | { |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1422 | u32 addr, val; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1423 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1424 | addr = SOC_CORE_BASE_ADDRESS | CORE_CTRL_ADDRESS; |
| 1425 | val = ath10k_pci_read32(ar, addr); |
| 1426 | val |= CORE_CTRL_CPU_INTR_MASK; |
| 1427 | ath10k_pci_write32(ar, addr, val); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1428 | |
Michal Kazior | 1d2b48d | 2013-11-08 08:01:34 +0100 | [diff] [blame] | 1429 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | static int ath10k_pci_init_config(struct ath10k *ar) |
| 1433 | { |
| 1434 | u32 interconnect_targ_addr; |
| 1435 | u32 pcie_state_targ_addr = 0; |
| 1436 | u32 pipe_cfg_targ_addr = 0; |
| 1437 | u32 svc_to_pipe_map = 0; |
| 1438 | u32 pcie_config_flags = 0; |
| 1439 | u32 ealloc_value; |
| 1440 | u32 ealloc_targ_addr; |
| 1441 | u32 flag2_value; |
| 1442 | u32 flag2_targ_addr; |
| 1443 | int ret = 0; |
| 1444 | |
| 1445 | /* Download to Target the CE Config and the service-to-CE map */ |
| 1446 | interconnect_targ_addr = |
| 1447 | host_interest_item_address(HI_ITEM(hi_interconnect_state)); |
| 1448 | |
| 1449 | /* Supply Target-side CE configuration */ |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1450 | ret = ath10k_pci_diag_read32(ar, interconnect_targ_addr, |
| 1451 | &pcie_state_targ_addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1452 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1453 | ath10k_err(ar, "Failed to get pcie state addr: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1454 | return ret; |
| 1455 | } |
| 1456 | |
| 1457 | if (pcie_state_targ_addr == 0) { |
| 1458 | ret = -EIO; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1459 | ath10k_err(ar, "Invalid pcie state addr\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1460 | return ret; |
| 1461 | } |
| 1462 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1463 | ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr + |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1464 | offsetof(struct pcie_state, |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1465 | pipe_cfg_addr)), |
| 1466 | &pipe_cfg_targ_addr); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1467 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1468 | ath10k_err(ar, "Failed to get pipe cfg addr: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1469 | return ret; |
| 1470 | } |
| 1471 | |
| 1472 | if (pipe_cfg_targ_addr == 0) { |
| 1473 | ret = -EIO; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1474 | ath10k_err(ar, "Invalid pipe cfg addr\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1475 | return ret; |
| 1476 | } |
| 1477 | |
| 1478 | ret = ath10k_pci_diag_write_mem(ar, pipe_cfg_targ_addr, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1479 | target_ce_config_wlan, |
| 1480 | sizeof(target_ce_config_wlan)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1481 | |
| 1482 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1483 | ath10k_err(ar, "Failed to write pipe cfg: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1484 | return ret; |
| 1485 | } |
| 1486 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1487 | ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr + |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1488 | offsetof(struct pcie_state, |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1489 | svc_to_pipe_map)), |
| 1490 | &svc_to_pipe_map); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1491 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1492 | ath10k_err(ar, "Failed to get svc/pipe map: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1493 | return ret; |
| 1494 | } |
| 1495 | |
| 1496 | if (svc_to_pipe_map == 0) { |
| 1497 | ret = -EIO; |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1498 | ath10k_err(ar, "Invalid svc_to_pipe map\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1499 | return ret; |
| 1500 | } |
| 1501 | |
| 1502 | ret = ath10k_pci_diag_write_mem(ar, svc_to_pipe_map, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 1503 | target_service_to_ce_map_wlan, |
| 1504 | sizeof(target_service_to_ce_map_wlan)); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1505 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1506 | ath10k_err(ar, "Failed to write svc/pipe map: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1507 | return ret; |
| 1508 | } |
| 1509 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1510 | ret = ath10k_pci_diag_read32(ar, (pcie_state_targ_addr + |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1511 | offsetof(struct pcie_state, |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1512 | config_flags)), |
| 1513 | &pcie_config_flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1514 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1515 | ath10k_err(ar, "Failed to get pcie config_flags: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1516 | return ret; |
| 1517 | } |
| 1518 | |
| 1519 | pcie_config_flags &= ~PCIE_CONFIG_FLAG_ENABLE_L1; |
| 1520 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1521 | ret = ath10k_pci_diag_write32(ar, (pcie_state_targ_addr + |
| 1522 | offsetof(struct pcie_state, |
| 1523 | config_flags)), |
| 1524 | pcie_config_flags); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1525 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1526 | ath10k_err(ar, "Failed to write pcie config_flags: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1527 | return ret; |
| 1528 | } |
| 1529 | |
| 1530 | /* configure early allocation */ |
| 1531 | ealloc_targ_addr = host_interest_item_address(HI_ITEM(hi_early_alloc)); |
| 1532 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1533 | ret = ath10k_pci_diag_read32(ar, ealloc_targ_addr, &ealloc_value); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1534 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1535 | ath10k_err(ar, "Faile to get early alloc val: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1536 | return ret; |
| 1537 | } |
| 1538 | |
| 1539 | /* first bank is switched to IRAM */ |
| 1540 | ealloc_value |= ((HI_EARLY_ALLOC_MAGIC << HI_EARLY_ALLOC_MAGIC_SHIFT) & |
| 1541 | HI_EARLY_ALLOC_MAGIC_MASK); |
| 1542 | ealloc_value |= ((1 << HI_EARLY_ALLOC_IRAM_BANKS_SHIFT) & |
| 1543 | HI_EARLY_ALLOC_IRAM_BANKS_MASK); |
| 1544 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1545 | ret = ath10k_pci_diag_write32(ar, ealloc_targ_addr, ealloc_value); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1546 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1547 | ath10k_err(ar, "Failed to set early alloc val: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1548 | return ret; |
| 1549 | } |
| 1550 | |
| 1551 | /* Tell Target to proceed with initialization */ |
| 1552 | flag2_targ_addr = host_interest_item_address(HI_ITEM(hi_option_flag2)); |
| 1553 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1554 | ret = ath10k_pci_diag_read32(ar, flag2_targ_addr, &flag2_value); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1555 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1556 | ath10k_err(ar, "Failed to get option val: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1557 | return ret; |
| 1558 | } |
| 1559 | |
| 1560 | flag2_value |= HI_OPTION_EARLY_CFG_DONE; |
| 1561 | |
Michal Kazior | 9e26494 | 2014-09-02 11:00:21 +0300 | [diff] [blame] | 1562 | ret = ath10k_pci_diag_write32(ar, flag2_targ_addr, flag2_value); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1563 | if (ret != 0) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1564 | ath10k_err(ar, "Failed to set option val: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1565 | return ret; |
| 1566 | } |
| 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1571 | static int ath10k_pci_alloc_ce(struct ath10k *ar) |
| 1572 | { |
| 1573 | int i, ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1574 | |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1575 | for (i = 0; i < CE_COUNT; i++) { |
| 1576 | ret = ath10k_ce_alloc_pipe(ar, i, &host_ce_config_wlan[i]); |
| 1577 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1578 | ath10k_err(ar, "failed to allocate copy engine pipe %d: %d\n", |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1579 | i, ret); |
| 1580 | return ret; |
| 1581 | } |
| 1582 | } |
| 1583 | |
| 1584 | return 0; |
| 1585 | } |
| 1586 | |
| 1587 | static void ath10k_pci_free_ce(struct ath10k *ar) |
| 1588 | { |
| 1589 | int i; |
| 1590 | |
| 1591 | for (i = 0; i < CE_COUNT; i++) |
| 1592 | ath10k_ce_free_pipe(ar, i); |
| 1593 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1594 | |
| 1595 | static int ath10k_pci_ce_init(struct ath10k *ar) |
| 1596 | { |
| 1597 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | 87263e5 | 2013-08-27 13:08:01 +0200 | [diff] [blame] | 1598 | struct ath10k_pci_pipe *pipe_info; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1599 | const struct ce_attr *attr; |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1600 | int pipe_num, ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1601 | |
Michal Kazior | fad6ed7 | 2013-11-08 08:01:23 +0100 | [diff] [blame] | 1602 | for (pipe_num = 0; pipe_num < CE_COUNT; pipe_num++) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1603 | pipe_info = &ar_pci->pipe_info[pipe_num]; |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1604 | pipe_info->ce_hdl = &ar_pci->ce_states[pipe_num]; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1605 | pipe_info->pipe_num = pipe_num; |
| 1606 | pipe_info->hif_ce_state = ar; |
| 1607 | attr = &host_ce_config_wlan[pipe_num]; |
| 1608 | |
Michal Kazior | 145cc12 | 2014-08-22 14:23:32 +0200 | [diff] [blame] | 1609 | ret = ath10k_ce_init_pipe(ar, pipe_num, attr, |
| 1610 | ath10k_pci_ce_send_done, |
| 1611 | ath10k_pci_ce_recv_data); |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1612 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1613 | ath10k_err(ar, "failed to initialize copy engine pipe %d: %d\n", |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 1614 | pipe_num, ret); |
| 1615 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1616 | } |
| 1617 | |
Michal Kazior | fad6ed7 | 2013-11-08 08:01:23 +0100 | [diff] [blame] | 1618 | if (pipe_num == CE_COUNT - 1) { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1619 | /* |
| 1620 | * Reserve the ultimate CE for |
| 1621 | * diagnostic Window support |
| 1622 | */ |
Michal Kazior | fad6ed7 | 2013-11-08 08:01:23 +0100 | [diff] [blame] | 1623 | ar_pci->ce_diag = pipe_info->ce_hdl; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1624 | continue; |
| 1625 | } |
| 1626 | |
Kalle Valo | cfbc06a | 2014-09-14 12:50:23 +0300 | [diff] [blame^] | 1627 | pipe_info->buf_sz = (size_t)(attr->src_sz_max); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1628 | } |
| 1629 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1630 | return 0; |
| 1631 | } |
| 1632 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1633 | static bool ath10k_pci_has_fw_crashed(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1634 | { |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1635 | return ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS) & |
| 1636 | FW_IND_EVENT_PENDING; |
| 1637 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1638 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1639 | static void ath10k_pci_fw_crashed_clear(struct ath10k *ar) |
| 1640 | { |
| 1641 | u32 val; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1642 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1643 | val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS); |
| 1644 | val &= ~FW_IND_EVENT_PENDING; |
| 1645 | ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, val); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1646 | } |
| 1647 | |
Michal Kazior | de01357 | 2014-05-14 16:56:16 +0300 | [diff] [blame] | 1648 | /* this function effectively clears target memory controller assert line */ |
| 1649 | static void ath10k_pci_warm_reset_si0(struct ath10k *ar) |
| 1650 | { |
| 1651 | u32 val; |
| 1652 | |
| 1653 | val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS); |
| 1654 | ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS, |
| 1655 | val | SOC_RESET_CONTROL_SI0_RST_MASK); |
| 1656 | val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS); |
| 1657 | |
| 1658 | msleep(10); |
| 1659 | |
| 1660 | val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS); |
| 1661 | ath10k_pci_soc_write32(ar, SOC_RESET_CONTROL_ADDRESS, |
| 1662 | val & ~SOC_RESET_CONTROL_SI0_RST_MASK); |
| 1663 | val = ath10k_pci_soc_read32(ar, SOC_RESET_CONTROL_ADDRESS); |
| 1664 | |
| 1665 | msleep(10); |
| 1666 | } |
| 1667 | |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1668 | static int ath10k_pci_warm_reset(struct ath10k *ar) |
| 1669 | { |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1670 | u32 val; |
| 1671 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1672 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset\n"); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1673 | |
| 1674 | /* debug */ |
| 1675 | val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + |
| 1676 | PCIE_INTR_CAUSE_ADDRESS); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1677 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot host cpu intr cause: 0x%08x\n", |
| 1678 | val); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1679 | |
| 1680 | val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + |
| 1681 | CPU_INTR_ADDRESS); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1682 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target cpu intr cause: 0x%08x\n", |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1683 | val); |
| 1684 | |
| 1685 | /* disable pending irqs */ |
| 1686 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + |
| 1687 | PCIE_INTR_ENABLE_ADDRESS, 0); |
| 1688 | |
| 1689 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + |
| 1690 | PCIE_INTR_CLR_ADDRESS, ~0); |
| 1691 | |
| 1692 | msleep(100); |
| 1693 | |
| 1694 | /* clear fw indicator */ |
Kalle Valo | b39712c | 2014-03-28 09:32:46 +0200 | [diff] [blame] | 1695 | ath10k_pci_write32(ar, FW_INDICATOR_ADDRESS, 0); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1696 | |
| 1697 | /* clear target LF timer interrupts */ |
| 1698 | val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + |
| 1699 | SOC_LF_TIMER_CONTROL0_ADDRESS); |
| 1700 | ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + |
| 1701 | SOC_LF_TIMER_CONTROL0_ADDRESS, |
| 1702 | val & ~SOC_LF_TIMER_CONTROL0_ENABLE_MASK); |
| 1703 | |
| 1704 | /* reset CE */ |
| 1705 | val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + |
| 1706 | SOC_RESET_CONTROL_ADDRESS); |
| 1707 | ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS, |
| 1708 | val | SOC_RESET_CONTROL_CE_RST_MASK); |
| 1709 | val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + |
| 1710 | SOC_RESET_CONTROL_ADDRESS); |
| 1711 | msleep(10); |
| 1712 | |
| 1713 | /* unreset CE */ |
| 1714 | ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS, |
| 1715 | val & ~SOC_RESET_CONTROL_CE_RST_MASK); |
| 1716 | val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + |
| 1717 | SOC_RESET_CONTROL_ADDRESS); |
| 1718 | msleep(10); |
| 1719 | |
Michal Kazior | de01357 | 2014-05-14 16:56:16 +0300 | [diff] [blame] | 1720 | ath10k_pci_warm_reset_si0(ar); |
| 1721 | |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1722 | /* debug */ |
| 1723 | val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + |
| 1724 | PCIE_INTR_CAUSE_ADDRESS); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1725 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot host cpu intr cause: 0x%08x\n", |
| 1726 | val); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1727 | |
| 1728 | val = ath10k_pci_read32(ar, SOC_CORE_BASE_ADDRESS + |
| 1729 | CPU_INTR_ADDRESS); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1730 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target cpu intr cause: 0x%08x\n", |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1731 | val); |
| 1732 | |
| 1733 | /* CPU warm reset */ |
| 1734 | val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + |
| 1735 | SOC_RESET_CONTROL_ADDRESS); |
| 1736 | ath10k_pci_write32(ar, RTC_SOC_BASE_ADDRESS + SOC_RESET_CONTROL_ADDRESS, |
| 1737 | val | SOC_RESET_CONTROL_CPU_WARM_RST_MASK); |
| 1738 | |
| 1739 | val = ath10k_pci_read32(ar, RTC_SOC_BASE_ADDRESS + |
| 1740 | SOC_RESET_CONTROL_ADDRESS); |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1741 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target reset state: 0x%08x\n", |
| 1742 | val); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1743 | |
| 1744 | msleep(100); |
| 1745 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1746 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot warm reset complete\n"); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1747 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 1748 | return 0; |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | static int __ath10k_pci_hif_power_up(struct ath10k *ar, bool cold_reset) |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1752 | { |
| 1753 | int ret; |
| 1754 | |
| 1755 | /* |
| 1756 | * Bring the target up cleanly. |
| 1757 | * |
| 1758 | * The target may be in an undefined state with an AUX-powered Target |
| 1759 | * and a Host in WoW mode. If the Host crashes, loses power, or is |
| 1760 | * restarted (without unloading the driver) then the Target is left |
| 1761 | * (aux) powered and running. On a subsequent driver load, the Target |
| 1762 | * is in an unexpected state. We try to catch that here in order to |
| 1763 | * reset the Target and retry the probe. |
| 1764 | */ |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1765 | if (cold_reset) |
| 1766 | ret = ath10k_pci_cold_reset(ar); |
| 1767 | else |
| 1768 | ret = ath10k_pci_warm_reset(ar); |
| 1769 | |
Michal Kazior | 5b2589f | 2013-11-08 08:01:30 +0100 | [diff] [blame] | 1770 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1771 | ath10k_err(ar, "failed to reset target: %d\n", ret); |
Michal Kazior | 98563d5 | 2013-11-08 08:01:33 +0100 | [diff] [blame] | 1772 | goto err; |
Michal Kazior | 5b2589f | 2013-11-08 08:01:30 +0100 | [diff] [blame] | 1773 | } |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1774 | |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1775 | ret = ath10k_pci_ce_init(ar); |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1776 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1777 | ath10k_err(ar, "failed to initialize CE: %d\n", ret); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 1778 | goto err; |
Michal Kazior | ab977bd | 2013-11-25 14:06:26 +0100 | [diff] [blame] | 1779 | } |
| 1780 | |
Michal Kazior | 98563d5 | 2013-11-08 08:01:33 +0100 | [diff] [blame] | 1781 | ret = ath10k_pci_wait_for_target_init(ar); |
| 1782 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1783 | ath10k_err(ar, "failed to wait for target to init: %d\n", ret); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1784 | goto err_ce; |
Michal Kazior | 98563d5 | 2013-11-08 08:01:33 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | ret = ath10k_pci_init_config(ar); |
| 1788 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1789 | ath10k_err(ar, "failed to setup init config: %d\n", ret); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1790 | goto err_ce; |
Michal Kazior | 98563d5 | 2013-11-08 08:01:33 +0100 | [diff] [blame] | 1791 | } |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1792 | |
| 1793 | ret = ath10k_pci_wake_target_cpu(ar); |
| 1794 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1795 | ath10k_err(ar, "could not wake up target CPU: %d\n", ret); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1796 | goto err_ce; |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1797 | } |
| 1798 | |
| 1799 | return 0; |
| 1800 | |
| 1801 | err_ce: |
| 1802 | ath10k_pci_ce_deinit(ar); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1803 | ath10k_pci_warm_reset(ar); |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1804 | err: |
| 1805 | return ret; |
| 1806 | } |
| 1807 | |
Michal Kazior | 61c95ce | 2014-05-14 16:56:16 +0300 | [diff] [blame] | 1808 | static int ath10k_pci_hif_power_up_warm(struct ath10k *ar) |
| 1809 | { |
| 1810 | int i, ret; |
| 1811 | |
| 1812 | /* |
| 1813 | * Sometime warm reset succeeds after retries. |
| 1814 | * |
| 1815 | * FIXME: It might be possible to tune ath10k_pci_warm_reset() to work |
| 1816 | * at first try. |
| 1817 | */ |
| 1818 | for (i = 0; i < ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS; i++) { |
| 1819 | ret = __ath10k_pci_hif_power_up(ar, false); |
| 1820 | if (ret == 0) |
| 1821 | break; |
| 1822 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1823 | ath10k_warn(ar, "failed to warm reset (attempt %d out of %d): %d\n", |
Michal Kazior | 61c95ce | 2014-05-14 16:56:16 +0300 | [diff] [blame] | 1824 | i + 1, ATH10K_PCI_NUM_WARM_RESET_ATTEMPTS, ret); |
| 1825 | } |
| 1826 | |
| 1827 | return ret; |
| 1828 | } |
| 1829 | |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1830 | static int ath10k_pci_hif_power_up(struct ath10k *ar) |
| 1831 | { |
| 1832 | int ret; |
| 1833 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1834 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power up\n"); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 1835 | |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1836 | /* |
| 1837 | * Hardware CUS232 version 2 has some issues with cold reset and the |
| 1838 | * preferred (and safer) way to perform a device reset is through a |
| 1839 | * warm reset. |
| 1840 | * |
Michal Kazior | 61c95ce | 2014-05-14 16:56:16 +0300 | [diff] [blame] | 1841 | * Warm reset doesn't always work though so fall back to cold reset may |
| 1842 | * be necessary. |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1843 | */ |
Michal Kazior | 61c95ce | 2014-05-14 16:56:16 +0300 | [diff] [blame] | 1844 | ret = ath10k_pci_hif_power_up_warm(ar); |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1845 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1846 | ath10k_warn(ar, "failed to power up target using warm reset: %d\n", |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1847 | ret); |
| 1848 | |
Kalle Valo | 3509846 | 2014-03-28 09:32:27 +0200 | [diff] [blame] | 1849 | if (ath10k_pci_reset_mode == ATH10K_PCI_RESET_WARM_ONLY) |
| 1850 | return ret; |
| 1851 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1852 | ath10k_warn(ar, "trying cold reset\n"); |
Kalle Valo | 3509846 | 2014-03-28 09:32:27 +0200 | [diff] [blame] | 1853 | |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1854 | ret = __ath10k_pci_hif_power_up(ar, true); |
| 1855 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1856 | ath10k_err(ar, "failed to power up target using cold reset too (%d)\n", |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1857 | ret); |
| 1858 | return ret; |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | return 0; |
| 1863 | } |
| 1864 | |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1865 | static void ath10k_pci_hif_power_down(struct ath10k *ar) |
| 1866 | { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1867 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot hif power down\n"); |
Bartosz Markowski | 8cc8df9 | 2013-08-02 09:58:49 +0200 | [diff] [blame] | 1868 | |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 1869 | ath10k_pci_warm_reset(ar); |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1870 | } |
| 1871 | |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 1872 | #ifdef CONFIG_PM |
| 1873 | |
| 1874 | #define ATH10K_PCI_PM_CONTROL 0x44 |
| 1875 | |
| 1876 | static int ath10k_pci_hif_suspend(struct ath10k *ar) |
| 1877 | { |
| 1878 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 1879 | struct pci_dev *pdev = ar_pci->pdev; |
| 1880 | u32 val; |
| 1881 | |
| 1882 | pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val); |
| 1883 | |
| 1884 | if ((val & 0x000000ff) != 0x3) { |
| 1885 | pci_save_state(pdev); |
| 1886 | pci_disable_device(pdev); |
| 1887 | pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL, |
| 1888 | (val & 0xffffff00) | 0x03); |
| 1889 | } |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | |
| 1894 | static int ath10k_pci_hif_resume(struct ath10k *ar) |
| 1895 | { |
| 1896 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 1897 | struct pci_dev *pdev = ar_pci->pdev; |
| 1898 | u32 val; |
| 1899 | |
| 1900 | pci_read_config_dword(pdev, ATH10K_PCI_PM_CONTROL, &val); |
| 1901 | |
| 1902 | if ((val & 0x000000ff) != 0) { |
| 1903 | pci_restore_state(pdev); |
| 1904 | pci_write_config_dword(pdev, ATH10K_PCI_PM_CONTROL, |
| 1905 | val & 0xffffff00); |
| 1906 | /* |
| 1907 | * Suspend/Resume resets the PCI configuration space, |
| 1908 | * so we have to re-disable the RETRY_TIMEOUT register (0x41) |
| 1909 | * to keep PCI Tx retries from interfering with C3 CPU state |
| 1910 | */ |
| 1911 | pci_read_config_dword(pdev, 0x40, &val); |
| 1912 | |
| 1913 | if ((val & 0x0000ff00) != 0) |
| 1914 | pci_write_config_dword(pdev, 0x40, val & 0xffff00ff); |
| 1915 | } |
| 1916 | |
| 1917 | return 0; |
| 1918 | } |
| 1919 | #endif |
| 1920 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1921 | static const struct ath10k_hif_ops ath10k_pci_hif_ops = { |
Michal Kazior | 726346f | 2014-02-27 18:50:04 +0200 | [diff] [blame] | 1922 | .tx_sg = ath10k_pci_hif_tx_sg, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1923 | .exchange_bmi_msg = ath10k_pci_hif_exchange_bmi_msg, |
| 1924 | .start = ath10k_pci_hif_start, |
| 1925 | .stop = ath10k_pci_hif_stop, |
| 1926 | .map_service_to_pipe = ath10k_pci_hif_map_service_to_pipe, |
| 1927 | .get_default_pipe = ath10k_pci_hif_get_default_pipe, |
| 1928 | .send_complete_check = ath10k_pci_hif_send_complete_check, |
Michal Kazior | e799bbf | 2013-07-05 16:15:12 +0300 | [diff] [blame] | 1929 | .set_callbacks = ath10k_pci_hif_set_callbacks, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1930 | .get_free_queue_number = ath10k_pci_hif_get_free_queue_number, |
Michal Kazior | 8c5c536 | 2013-07-16 09:38:50 +0200 | [diff] [blame] | 1931 | .power_up = ath10k_pci_hif_power_up, |
| 1932 | .power_down = ath10k_pci_hif_power_down, |
Michal Kazior | 8cd13ca | 2013-07-16 09:38:54 +0200 | [diff] [blame] | 1933 | #ifdef CONFIG_PM |
| 1934 | .suspend = ath10k_pci_hif_suspend, |
| 1935 | .resume = ath10k_pci_hif_resume, |
| 1936 | #endif |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1937 | }; |
| 1938 | |
| 1939 | static void ath10k_pci_ce_tasklet(unsigned long ptr) |
| 1940 | { |
Michal Kazior | 87263e5 | 2013-08-27 13:08:01 +0200 | [diff] [blame] | 1941 | struct ath10k_pci_pipe *pipe = (struct ath10k_pci_pipe *)ptr; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1942 | struct ath10k_pci *ar_pci = pipe->ar_pci; |
| 1943 | |
| 1944 | ath10k_ce_per_engine_service(ar_pci->ar, pipe->pipe_num); |
| 1945 | } |
| 1946 | |
| 1947 | static void ath10k_msi_err_tasklet(unsigned long data) |
| 1948 | { |
| 1949 | struct ath10k *ar = (struct ath10k *)data; |
| 1950 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1951 | if (!ath10k_pci_has_fw_crashed(ar)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1952 | ath10k_warn(ar, "received unsolicited fw crash interrupt\n"); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 1953 | return; |
| 1954 | } |
| 1955 | |
| 1956 | ath10k_pci_fw_crashed_clear(ar); |
| 1957 | ath10k_pci_fw_crashed_dump(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | /* |
| 1961 | * Handler for a per-engine interrupt on a PARTICULAR CE. |
| 1962 | * This is used in cases where each CE has a private MSI interrupt. |
| 1963 | */ |
| 1964 | static irqreturn_t ath10k_pci_per_engine_handler(int irq, void *arg) |
| 1965 | { |
| 1966 | struct ath10k *ar = arg; |
| 1967 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 1968 | int ce_id = irq - ar_pci->pdev->irq - MSI_ASSIGN_CE_INITIAL; |
| 1969 | |
Dan Carpenter | e574267 | 2013-06-18 10:28:46 +0300 | [diff] [blame] | 1970 | if (ce_id < 0 || ce_id >= ARRAY_SIZE(ar_pci->pipe_info)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 1971 | ath10k_warn(ar, "unexpected/invalid irq %d ce_id %d\n", irq, |
| 1972 | ce_id); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 1973 | return IRQ_HANDLED; |
| 1974 | } |
| 1975 | |
| 1976 | /* |
| 1977 | * NOTE: We are able to derive ce_id from irq because we |
| 1978 | * use a one-to-one mapping for CE's 0..5. |
| 1979 | * CE's 6 & 7 do not use interrupts at all. |
| 1980 | * |
| 1981 | * This mapping must be kept in sync with the mapping |
| 1982 | * used by firmware. |
| 1983 | */ |
| 1984 | tasklet_schedule(&ar_pci->pipe_info[ce_id].intr); |
| 1985 | return IRQ_HANDLED; |
| 1986 | } |
| 1987 | |
| 1988 | static irqreturn_t ath10k_pci_msi_fw_handler(int irq, void *arg) |
| 1989 | { |
| 1990 | struct ath10k *ar = arg; |
| 1991 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 1992 | |
| 1993 | tasklet_schedule(&ar_pci->msi_fw_err); |
| 1994 | return IRQ_HANDLED; |
| 1995 | } |
| 1996 | |
| 1997 | /* |
| 1998 | * Top-level interrupt handler for all PCI interrupts from a Target. |
| 1999 | * When a block of MSI interrupts is allocated, this top-level handler |
| 2000 | * is not used; instead, we directly call the correct sub-handler. |
| 2001 | */ |
| 2002 | static irqreturn_t ath10k_pci_interrupt_handler(int irq, void *arg) |
| 2003 | { |
| 2004 | struct ath10k *ar = arg; |
| 2005 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2006 | |
| 2007 | if (ar_pci->num_msi_intrs == 0) { |
Michal Kazior | e539887 | 2013-11-25 14:06:20 +0100 | [diff] [blame] | 2008 | if (!ath10k_pci_irq_pending(ar)) |
| 2009 | return IRQ_NONE; |
| 2010 | |
Michal Kazior | 2685218 | 2013-11-25 14:06:25 +0100 | [diff] [blame] | 2011 | ath10k_pci_disable_and_clear_legacy_irq(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | tasklet_schedule(&ar_pci->intr_tq); |
| 2015 | |
| 2016 | return IRQ_HANDLED; |
| 2017 | } |
| 2018 | |
| 2019 | static void ath10k_pci_tasklet(unsigned long data) |
| 2020 | { |
| 2021 | struct ath10k *ar = (struct ath10k *)data; |
| 2022 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2023 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2024 | if (ath10k_pci_has_fw_crashed(ar)) { |
| 2025 | ath10k_pci_fw_crashed_clear(ar); |
| 2026 | ath10k_pci_fw_crashed_dump(ar); |
| 2027 | return; |
| 2028 | } |
| 2029 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2030 | ath10k_ce_per_engine_service_any(ar); |
| 2031 | |
Michal Kazior | 2685218 | 2013-11-25 14:06:25 +0100 | [diff] [blame] | 2032 | /* Re-enable legacy irq that was disabled in the irq handler */ |
| 2033 | if (ar_pci->num_msi_intrs == 0) |
| 2034 | ath10k_pci_enable_legacy_irq(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2035 | } |
| 2036 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2037 | static int ath10k_pci_request_irq_msix(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2038 | { |
| 2039 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2040 | int ret, i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2041 | |
| 2042 | ret = request_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, |
| 2043 | ath10k_pci_msi_fw_handler, |
| 2044 | IRQF_SHARED, "ath10k_pci", ar); |
Michal Kazior | 591ecdb | 2013-07-31 10:55:15 +0200 | [diff] [blame] | 2045 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2046 | ath10k_warn(ar, "failed to request MSI-X fw irq %d: %d\n", |
Michal Kazior | 591ecdb | 2013-07-31 10:55:15 +0200 | [diff] [blame] | 2047 | ar_pci->pdev->irq + MSI_ASSIGN_FW, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2048 | return ret; |
Michal Kazior | 591ecdb | 2013-07-31 10:55:15 +0200 | [diff] [blame] | 2049 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2050 | |
| 2051 | for (i = MSI_ASSIGN_CE_INITIAL; i <= MSI_ASSIGN_CE_MAX; i++) { |
| 2052 | ret = request_irq(ar_pci->pdev->irq + i, |
| 2053 | ath10k_pci_per_engine_handler, |
| 2054 | IRQF_SHARED, "ath10k_pci", ar); |
| 2055 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2056 | ath10k_warn(ar, "failed to request MSI-X ce irq %d: %d\n", |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2057 | ar_pci->pdev->irq + i, ret); |
| 2058 | |
Michal Kazior | 87b1423 | 2013-06-26 08:50:50 +0200 | [diff] [blame] | 2059 | for (i--; i >= MSI_ASSIGN_CE_INITIAL; i--) |
| 2060 | free_irq(ar_pci->pdev->irq + i, ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2061 | |
Michal Kazior | 87b1423 | 2013-06-26 08:50:50 +0200 | [diff] [blame] | 2062 | free_irq(ar_pci->pdev->irq + MSI_ASSIGN_FW, ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2063 | return ret; |
| 2064 | } |
| 2065 | } |
| 2066 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2067 | return 0; |
| 2068 | } |
| 2069 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2070 | static int ath10k_pci_request_irq_msi(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2071 | { |
| 2072 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2073 | int ret; |
| 2074 | |
| 2075 | ret = request_irq(ar_pci->pdev->irq, |
| 2076 | ath10k_pci_interrupt_handler, |
| 2077 | IRQF_SHARED, "ath10k_pci", ar); |
Kalle Valo | f378274 | 2013-10-17 11:36:15 +0300 | [diff] [blame] | 2078 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2079 | ath10k_warn(ar, "failed to request MSI irq %d: %d\n", |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2080 | ar_pci->pdev->irq, ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2081 | return ret; |
Kalle Valo | f378274 | 2013-10-17 11:36:15 +0300 | [diff] [blame] | 2082 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2083 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2084 | return 0; |
| 2085 | } |
| 2086 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2087 | static int ath10k_pci_request_irq_legacy(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2088 | { |
| 2089 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2090 | int ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2091 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2092 | ret = request_irq(ar_pci->pdev->irq, |
| 2093 | ath10k_pci_interrupt_handler, |
| 2094 | IRQF_SHARED, "ath10k_pci", ar); |
Kalle Valo | f378274 | 2013-10-17 11:36:15 +0300 | [diff] [blame] | 2095 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2096 | ath10k_warn(ar, "failed to request legacy irq %d: %d\n", |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2097 | ar_pci->pdev->irq, ret); |
Kalle Valo | f378274 | 2013-10-17 11:36:15 +0300 | [diff] [blame] | 2098 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2099 | } |
| 2100 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2101 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2102 | } |
| 2103 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2104 | static int ath10k_pci_request_irq(struct ath10k *ar) |
| 2105 | { |
| 2106 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2107 | |
| 2108 | switch (ar_pci->num_msi_intrs) { |
| 2109 | case 0: |
| 2110 | return ath10k_pci_request_irq_legacy(ar); |
| 2111 | case 1: |
| 2112 | return ath10k_pci_request_irq_msi(ar); |
| 2113 | case MSI_NUM_REQUEST: |
| 2114 | return ath10k_pci_request_irq_msix(ar); |
| 2115 | } |
| 2116 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2117 | ath10k_warn(ar, "unknown irq configuration upon request\n"); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2118 | return -EINVAL; |
| 2119 | } |
| 2120 | |
| 2121 | static void ath10k_pci_free_irq(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2122 | { |
| 2123 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2124 | int i; |
| 2125 | |
| 2126 | /* There's at least one interrupt irregardless whether its legacy INTR |
| 2127 | * or MSI or MSI-X */ |
| 2128 | for (i = 0; i < max(1, ar_pci->num_msi_intrs); i++) |
| 2129 | free_irq(ar_pci->pdev->irq + i, ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2130 | } |
| 2131 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2132 | static void ath10k_pci_init_irq_tasklets(struct ath10k *ar) |
| 2133 | { |
| 2134 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2135 | int i; |
| 2136 | |
| 2137 | tasklet_init(&ar_pci->intr_tq, ath10k_pci_tasklet, (unsigned long)ar); |
| 2138 | tasklet_init(&ar_pci->msi_fw_err, ath10k_msi_err_tasklet, |
| 2139 | (unsigned long)ar); |
| 2140 | |
| 2141 | for (i = 0; i < CE_COUNT; i++) { |
| 2142 | ar_pci->pipe_info[i].ar_pci = ar_pci; |
| 2143 | tasklet_init(&ar_pci->pipe_info[i].intr, ath10k_pci_ce_tasklet, |
| 2144 | (unsigned long)&ar_pci->pipe_info[i]); |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | static int ath10k_pci_init_irq(struct ath10k *ar) |
| 2149 | { |
| 2150 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2151 | int ret; |
| 2152 | |
| 2153 | ath10k_pci_init_irq_tasklets(ar); |
| 2154 | |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2155 | if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_AUTO) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2156 | ath10k_info(ar, "limiting irq mode to: %d\n", |
| 2157 | ath10k_pci_irq_mode); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2158 | |
| 2159 | /* Try MSI-X */ |
Michal Kazior | 0edf257 | 2014-08-07 11:03:29 +0200 | [diff] [blame] | 2160 | if (ath10k_pci_irq_mode == ATH10K_PCI_IRQ_AUTO) { |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 2161 | ar_pci->num_msi_intrs = MSI_NUM_REQUEST; |
Alexander Gordeev | 5ad6867 | 2014-02-13 17:50:02 +0200 | [diff] [blame] | 2162 | ret = pci_enable_msi_range(ar_pci->pdev, ar_pci->num_msi_intrs, |
Kalle Valo | 5b07e07 | 2014-09-14 12:50:06 +0300 | [diff] [blame] | 2163 | ar_pci->num_msi_intrs); |
Alexander Gordeev | 5ad6867 | 2014-02-13 17:50:02 +0200 | [diff] [blame] | 2164 | if (ret > 0) |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 2165 | return 0; |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2166 | |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 2167 | /* fall-through */ |
| 2168 | } |
| 2169 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2170 | /* Try MSI */ |
Michal Kazior | cfe9c45 | 2013-11-25 14:06:27 +0100 | [diff] [blame] | 2171 | if (ath10k_pci_irq_mode != ATH10K_PCI_IRQ_LEGACY) { |
| 2172 | ar_pci->num_msi_intrs = 1; |
| 2173 | ret = pci_enable_msi(ar_pci->pdev); |
| 2174 | if (ret == 0) |
| 2175 | return 0; |
| 2176 | |
| 2177 | /* fall-through */ |
| 2178 | } |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2179 | |
| 2180 | /* Try legacy irq |
| 2181 | * |
| 2182 | * A potential race occurs here: The CORE_BASE write |
| 2183 | * depends on target correctly decoding AXI address but |
| 2184 | * host won't know when target writes BAR to CORE_CTRL. |
| 2185 | * This write might get lost if target has NOT written BAR. |
| 2186 | * For now, fix the race by repeating the write in below |
| 2187 | * synchronization checking. */ |
| 2188 | ar_pci->num_msi_intrs = 0; |
| 2189 | |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2190 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS, |
| 2191 | PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2192 | |
| 2193 | return 0; |
| 2194 | } |
| 2195 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2196 | static void ath10k_pci_deinit_irq_legacy(struct ath10k *ar) |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2197 | { |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2198 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + PCIE_INTR_ENABLE_ADDRESS, |
| 2199 | 0); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | static int ath10k_pci_deinit_irq(struct ath10k *ar) |
| 2203 | { |
| 2204 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2205 | |
| 2206 | switch (ar_pci->num_msi_intrs) { |
| 2207 | case 0: |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2208 | ath10k_pci_deinit_irq_legacy(ar); |
| 2209 | return 0; |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2210 | case 1: |
| 2211 | /* fall-through */ |
| 2212 | case MSI_NUM_REQUEST: |
| 2213 | pci_disable_msi(ar_pci->pdev); |
| 2214 | return 0; |
Alexander Gordeev | bb8b621 | 2014-02-13 17:50:01 +0200 | [diff] [blame] | 2215 | default: |
| 2216 | pci_disable_msi(ar_pci->pdev); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2217 | } |
| 2218 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2219 | ath10k_warn(ar, "unknown irq configuration upon deinit\n"); |
Michal Kazior | fc15ca1 | 2013-11-25 14:06:21 +0100 | [diff] [blame] | 2220 | return -EINVAL; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2221 | } |
| 2222 | |
Michal Kazior | d7fb47f | 2013-11-08 08:01:26 +0100 | [diff] [blame] | 2223 | static int ath10k_pci_wait_for_target_init(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2224 | { |
| 2225 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 2226 | unsigned long timeout; |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 2227 | u32 val; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2228 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2229 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot waiting target to initialise\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2230 | |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 2231 | timeout = jiffies + msecs_to_jiffies(ATH10K_PCI_TARGET_WAIT); |
| 2232 | |
| 2233 | do { |
| 2234 | val = ath10k_pci_read32(ar, FW_INDICATOR_ADDRESS); |
| 2235 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2236 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target indicator %x\n", |
| 2237 | val); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 2238 | |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 2239 | /* target should never return this */ |
| 2240 | if (val == 0xffffffff) |
| 2241 | continue; |
| 2242 | |
Michal Kazior | 7710cd2 | 2014-04-23 19:30:04 +0300 | [diff] [blame] | 2243 | /* the device has crashed so don't bother trying anymore */ |
| 2244 | if (val & FW_IND_EVENT_PENDING) |
| 2245 | break; |
| 2246 | |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 2247 | if (val & FW_IND_INITIALIZED) |
| 2248 | break; |
| 2249 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2250 | if (ar_pci->num_msi_intrs == 0) |
| 2251 | /* Fix potential race by repeating CORE_BASE writes */ |
Michal Kazior | c947a9e | 2014-08-22 14:23:30 +0200 | [diff] [blame] | 2252 | ath10k_pci_write32(ar, SOC_CORE_BASE_ADDRESS + |
| 2253 | PCIE_INTR_ENABLE_ADDRESS, |
| 2254 | PCIE_INTR_FIRMWARE_MASK | |
| 2255 | PCIE_INTR_CE_MASK_ALL); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2256 | |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 2257 | mdelay(10); |
| 2258 | } while (time_before(jiffies, timeout)); |
| 2259 | |
Michal Kazior | 6a4f6e1 | 2014-04-23 19:30:03 +0300 | [diff] [blame] | 2260 | if (val == 0xffffffff) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2261 | ath10k_err(ar, "failed to read device register, device is gone\n"); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2262 | return -EIO; |
Michal Kazior | 6a4f6e1 | 2014-04-23 19:30:03 +0300 | [diff] [blame] | 2263 | } |
| 2264 | |
Michal Kazior | 7710cd2 | 2014-04-23 19:30:04 +0300 | [diff] [blame] | 2265 | if (val & FW_IND_EVENT_PENDING) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2266 | ath10k_warn(ar, "device has crashed during init\n"); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2267 | ath10k_pci_fw_crashed_clear(ar); |
Kalle Valo | 0e9848c | 2014-08-25 08:37:37 +0300 | [diff] [blame] | 2268 | ath10k_pci_fw_crashed_dump(ar); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2269 | return -ECOMM; |
Michal Kazior | 7710cd2 | 2014-04-23 19:30:04 +0300 | [diff] [blame] | 2270 | } |
| 2271 | |
Michal Kazior | 6a4f6e1 | 2014-04-23 19:30:03 +0300 | [diff] [blame] | 2272 | if (!(val & FW_IND_INITIALIZED)) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2273 | ath10k_err(ar, "failed to receive initialized event from target: %08x\n", |
Kalle Valo | 0399eca | 2014-03-28 09:32:21 +0200 | [diff] [blame] | 2274 | val); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2275 | return -ETIMEDOUT; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2276 | } |
| 2277 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2278 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot target initialised\n"); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2279 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2280 | } |
| 2281 | |
Michal Kazior | fc36e3f | 2014-02-10 17:14:22 +0100 | [diff] [blame] | 2282 | static int ath10k_pci_cold_reset(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2283 | { |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2284 | int i; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2285 | u32 val; |
| 2286 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2287 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2288 | |
| 2289 | /* Put Target, including PCIe, into RESET. */ |
Kalle Valo | e479ed4 | 2013-09-01 10:01:53 +0300 | [diff] [blame] | 2290 | val = ath10k_pci_reg_read32(ar, SOC_GLOBAL_RESET_ADDRESS); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2291 | val |= 1; |
Kalle Valo | e479ed4 | 2013-09-01 10:01:53 +0300 | [diff] [blame] | 2292 | ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2293 | |
| 2294 | for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) { |
Kalle Valo | e479ed4 | 2013-09-01 10:01:53 +0300 | [diff] [blame] | 2295 | if (ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) & |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2296 | RTC_STATE_COLD_RESET_MASK) |
| 2297 | break; |
| 2298 | msleep(1); |
| 2299 | } |
| 2300 | |
| 2301 | /* Pull Target, including PCIe, out of RESET. */ |
| 2302 | val &= ~1; |
Kalle Valo | e479ed4 | 2013-09-01 10:01:53 +0300 | [diff] [blame] | 2303 | ath10k_pci_reg_write32(ar, SOC_GLOBAL_RESET_ADDRESS, val); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2304 | |
| 2305 | for (i = 0; i < ATH_PCI_RESET_WAIT_MAX; i++) { |
Kalle Valo | e479ed4 | 2013-09-01 10:01:53 +0300 | [diff] [blame] | 2306 | if (!(ath10k_pci_reg_read32(ar, RTC_STATE_ADDRESS) & |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2307 | RTC_STATE_COLD_RESET_MASK)) |
| 2308 | break; |
| 2309 | msleep(1); |
| 2310 | } |
| 2311 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2312 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot cold reset complete\n"); |
Kalle Valo | 50f87a6 | 2014-03-28 09:32:52 +0200 | [diff] [blame] | 2313 | |
Michal Kazior | 5b2589f | 2013-11-08 08:01:30 +0100 | [diff] [blame] | 2314 | return 0; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2315 | } |
| 2316 | |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2317 | static int ath10k_pci_claim(struct ath10k *ar) |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2318 | { |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2319 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2320 | struct pci_dev *pdev = ar_pci->pdev; |
| 2321 | u32 lcr_val; |
| 2322 | int ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2323 | |
| 2324 | pci_set_drvdata(pdev, ar); |
| 2325 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2326 | ret = pci_enable_device(pdev); |
| 2327 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2328 | ath10k_err(ar, "failed to enable pci device: %d\n", ret); |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2329 | return ret; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2330 | } |
| 2331 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2332 | ret = pci_request_region(pdev, BAR_NUM, "ath"); |
| 2333 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2334 | ath10k_err(ar, "failed to request region BAR%d: %d\n", BAR_NUM, |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2335 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2336 | goto err_device; |
| 2337 | } |
| 2338 | |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2339 | /* Target expects 32 bit DMA. Enforce it. */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2340 | ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 2341 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2342 | ath10k_err(ar, "failed to set dma mask to 32-bit: %d\n", ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2343 | goto err_region; |
| 2344 | } |
| 2345 | |
| 2346 | ret = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 2347 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2348 | ath10k_err(ar, "failed to set consistent dma mask to 32-bit: %d\n", |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2349 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2350 | goto err_region; |
| 2351 | } |
| 2352 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2353 | pci_set_master(pdev); |
| 2354 | |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2355 | /* Workaround: Disable ASPM */ |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2356 | pci_read_config_dword(pdev, 0x80, &lcr_val); |
| 2357 | pci_write_config_dword(pdev, 0x80, (lcr_val & 0xffffff00)); |
| 2358 | |
| 2359 | /* Arrange for access to Target SoC registers. */ |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2360 | ar_pci->mem = pci_iomap(pdev, BAR_NUM, 0); |
| 2361 | if (!ar_pci->mem) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2362 | ath10k_err(ar, "failed to iomap BAR%d\n", BAR_NUM); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2363 | ret = -EIO; |
| 2364 | goto err_master; |
| 2365 | } |
| 2366 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2367 | ath10k_dbg(ar, ATH10K_DBG_BOOT, "boot pci_mem 0x%p\n", ar_pci->mem); |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2368 | return 0; |
| 2369 | |
| 2370 | err_master: |
| 2371 | pci_clear_master(pdev); |
| 2372 | |
| 2373 | err_region: |
| 2374 | pci_release_region(pdev, BAR_NUM); |
| 2375 | |
| 2376 | err_device: |
| 2377 | pci_disable_device(pdev); |
| 2378 | |
| 2379 | return ret; |
| 2380 | } |
| 2381 | |
| 2382 | static void ath10k_pci_release(struct ath10k *ar) |
| 2383 | { |
| 2384 | struct ath10k_pci *ar_pci = ath10k_pci_priv(ar); |
| 2385 | struct pci_dev *pdev = ar_pci->pdev; |
| 2386 | |
| 2387 | pci_iounmap(pdev, ar_pci->mem); |
| 2388 | pci_release_region(pdev, BAR_NUM); |
| 2389 | pci_clear_master(pdev); |
| 2390 | pci_disable_device(pdev); |
| 2391 | } |
| 2392 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2393 | static int ath10k_pci_probe(struct pci_dev *pdev, |
| 2394 | const struct pci_device_id *pci_dev) |
| 2395 | { |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2396 | int ret = 0; |
| 2397 | struct ath10k *ar; |
| 2398 | struct ath10k_pci *ar_pci; |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2399 | u32 chip_id; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2400 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 2401 | ar = ath10k_core_create(sizeof(*ar_pci), &pdev->dev, |
| 2402 | &ath10k_pci_hif_ops); |
| 2403 | if (!ar) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2404 | dev_err(&pdev->dev, "failed to allocate core\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2405 | return -ENOMEM; |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 2406 | } |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2407 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2408 | ath10k_dbg(ar, ATH10K_DBG_PCI, "pci probe\n"); |
| 2409 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 2410 | ar_pci = ath10k_pci_priv(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2411 | ar_pci->pdev = pdev; |
| 2412 | ar_pci->dev = &pdev->dev; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2413 | ar_pci->ar = ar; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2414 | |
| 2415 | spin_lock_init(&ar_pci->ce_lock); |
Michal Kazior | 728f95e | 2014-08-22 14:33:14 +0200 | [diff] [blame] | 2416 | setup_timer(&ar_pci->rx_post_retry, ath10k_pci_rx_replenish_retry, |
| 2417 | (unsigned long)ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2418 | |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2419 | ret = ath10k_pci_claim(ar); |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 2420 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2421 | ath10k_err(ar, "failed to claim device: %d\n", ret); |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 2422 | goto err_core_destroy; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2423 | } |
| 2424 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2425 | ret = ath10k_pci_wake(ar); |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 2426 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2427 | ath10k_err(ar, "failed to wake up: %d\n", ret); |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2428 | goto err_release; |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 2429 | } |
| 2430 | |
Kalle Valo | 233eb97 | 2013-10-16 16:46:11 +0300 | [diff] [blame] | 2431 | chip_id = ath10k_pci_soc_read32(ar, SOC_CHIP_ID_ADDRESS); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2432 | if (chip_id == 0xffffffff) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2433 | ath10k_err(ar, "failed to get chip id\n"); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2434 | goto err_sleep; |
| 2435 | } |
Kalle Valo | e01ae68 | 2013-09-01 11:22:14 +0300 | [diff] [blame] | 2436 | |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 2437 | ret = ath10k_pci_alloc_ce(ar); |
| 2438 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2439 | ath10k_err(ar, "failed to allocate copy engine pipes: %d\n", |
| 2440 | ret); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2441 | goto err_sleep; |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 2442 | } |
| 2443 | |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2444 | ath10k_pci_ce_deinit(ar); |
| 2445 | |
| 2446 | ret = ath10k_ce_disable_interrupts(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2447 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2448 | ath10k_err(ar, "failed to disable copy engine interrupts: %d\n", |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2449 | ret); |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 2450 | goto err_free_ce; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2451 | } |
| 2452 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2453 | /* Workaround: There's no known way to mask all possible interrupts via |
| 2454 | * device CSR. The only way to make sure device doesn't assert |
| 2455 | * interrupts is to reset it. Interrupts are then disabled on host |
| 2456 | * after handlers are registered. |
| 2457 | */ |
| 2458 | ath10k_pci_warm_reset(ar); |
| 2459 | |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2460 | ret = ath10k_pci_init_irq(ar); |
| 2461 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2462 | ath10k_err(ar, "failed to init irqs: %d\n", ret); |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2463 | goto err_free_ce; |
| 2464 | } |
| 2465 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2466 | ath10k_info(ar, "pci irq %s interrupts %d irq_mode %d reset_mode %d\n", |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2467 | ath10k_pci_get_irq_method(ar), ar_pci->num_msi_intrs, |
| 2468 | ath10k_pci_irq_mode, ath10k_pci_reset_mode); |
| 2469 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2470 | ret = ath10k_pci_request_irq(ar); |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2471 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2472 | ath10k_warn(ar, "failed to request irqs: %d\n", ret); |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2473 | goto err_deinit_irq; |
| 2474 | } |
| 2475 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2476 | /* This shouldn't race as the device has been reset above. */ |
| 2477 | ath10k_pci_irq_disable(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2478 | |
| 2479 | ret = ath10k_core_register(ar, chip_id); |
| 2480 | if (ret) { |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2481 | ath10k_err(ar, "failed to register driver core: %d\n", ret); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2482 | goto err_free_irq; |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2483 | } |
| 2484 | |
| 2485 | return 0; |
| 2486 | |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2487 | err_free_irq: |
| 2488 | ath10k_pci_free_irq(ar); |
Michal Kazior | 2139627 | 2014-08-28 10:24:40 +0200 | [diff] [blame] | 2489 | ath10k_pci_kill_tasklet(ar); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2490 | |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2491 | err_deinit_irq: |
| 2492 | ath10k_pci_deinit_irq(ar); |
| 2493 | |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 2494 | err_free_ce: |
| 2495 | ath10k_pci_free_ce(ar); |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2496 | |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2497 | err_sleep: |
| 2498 | ath10k_pci_sleep(ar); |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2499 | |
| 2500 | err_release: |
| 2501 | ath10k_pci_release(ar); |
| 2502 | |
Michal Kazior | e7b5419 | 2014-08-07 11:03:27 +0200 | [diff] [blame] | 2503 | err_core_destroy: |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2504 | ath10k_core_destroy(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2505 | |
| 2506 | return ret; |
| 2507 | } |
| 2508 | |
| 2509 | static void ath10k_pci_remove(struct pci_dev *pdev) |
| 2510 | { |
| 2511 | struct ath10k *ar = pci_get_drvdata(pdev); |
| 2512 | struct ath10k_pci *ar_pci; |
| 2513 | |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2514 | ath10k_dbg(ar, ATH10K_DBG_PCI, "pci remove\n"); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2515 | |
| 2516 | if (!ar) |
| 2517 | return; |
| 2518 | |
| 2519 | ar_pci = ath10k_pci_priv(ar); |
| 2520 | |
| 2521 | if (!ar_pci) |
| 2522 | return; |
| 2523 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2524 | ath10k_core_unregister(ar); |
Michal Kazior | 5c771e7 | 2014-08-22 14:23:34 +0200 | [diff] [blame] | 2525 | ath10k_pci_free_irq(ar); |
Michal Kazior | 2139627 | 2014-08-28 10:24:40 +0200 | [diff] [blame] | 2526 | ath10k_pci_kill_tasklet(ar); |
Michal Kazior | 403d627 | 2014-08-22 14:23:31 +0200 | [diff] [blame] | 2527 | ath10k_pci_deinit_irq(ar); |
| 2528 | ath10k_pci_ce_deinit(ar); |
Michal Kazior | 25d0dbc | 2014-03-28 10:02:38 +0200 | [diff] [blame] | 2529 | ath10k_pci_free_ce(ar); |
Michal Kazior | c0c378f | 2014-08-07 11:03:28 +0200 | [diff] [blame] | 2530 | ath10k_pci_sleep(ar); |
Michal Kazior | 2986e3e | 2014-08-07 11:03:30 +0200 | [diff] [blame] | 2531 | ath10k_pci_release(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2532 | ath10k_core_destroy(ar); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2533 | } |
| 2534 | |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2535 | MODULE_DEVICE_TABLE(pci, ath10k_pci_id_table); |
| 2536 | |
| 2537 | static struct pci_driver ath10k_pci_driver = { |
| 2538 | .name = "ath10k_pci", |
| 2539 | .id_table = ath10k_pci_id_table, |
| 2540 | .probe = ath10k_pci_probe, |
| 2541 | .remove = ath10k_pci_remove, |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2542 | }; |
| 2543 | |
| 2544 | static int __init ath10k_pci_init(void) |
| 2545 | { |
| 2546 | int ret; |
| 2547 | |
| 2548 | ret = pci_register_driver(&ath10k_pci_driver); |
| 2549 | if (ret) |
Michal Kazior | 7aa7a72 | 2014-08-25 12:09:38 +0200 | [diff] [blame] | 2550 | printk(KERN_ERR "failed to register ath10k pci driver: %d\n", |
| 2551 | ret); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2552 | |
| 2553 | return ret; |
| 2554 | } |
| 2555 | module_init(ath10k_pci_init); |
| 2556 | |
| 2557 | static void __exit ath10k_pci_exit(void) |
| 2558 | { |
| 2559 | pci_unregister_driver(&ath10k_pci_driver); |
| 2560 | } |
| 2561 | |
| 2562 | module_exit(ath10k_pci_exit); |
| 2563 | |
| 2564 | MODULE_AUTHOR("Qualcomm Atheros"); |
| 2565 | MODULE_DESCRIPTION("Driver support for Atheros QCA988X PCIe devices"); |
| 2566 | MODULE_LICENSE("Dual BSD/GPL"); |
Michal Kazior | 24c88f7 | 2014-07-25 13:32:17 +0200 | [diff] [blame] | 2567 | MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_FW_3_FILE); |
Kalle Valo | 5e3dd15 | 2013-06-12 20:52:10 +0300 | [diff] [blame] | 2568 | MODULE_FIRMWARE(QCA988X_HW_2_0_FW_DIR "/" QCA988X_HW_2_0_BOARD_DATA_FILE); |