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