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