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