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