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