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