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