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