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