1 /* 2 * Copyright (c) 2013-2019 The Linux Foundation. All rights reserved. 3 * 4 * Permission to use, copy, modify, and/or distribute this software for 5 * any purpose with or without fee is hereby granted, provided that the 6 * above copyright notice and this permission notice appear in all 7 * copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 * PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 /** 20 * DOC: if_ahb.c 21 * 22 * c file for ahb specific implementations. 23 */ 24 25 #include "hif.h" 26 #include "target_type.h" 27 #include "hif_main.h" 28 #include "hif_debug.h" 29 #include "hif_io32.h" 30 #include "ce_main.h" 31 #include "ce_api.h" 32 #include "ce_tasklet.h" 33 #include "if_ahb.h" 34 #include "if_pci.h" 35 #include "ahb_api.h" 36 #include "pci_api.h" 37 #include "hif_napi.h" 38 #include "qal_vbus_dev.h" 39 40 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 1, 0) 41 #define IRQF_DISABLED 0x00000020 42 #endif 43 44 #define HIF_IC_CE0_IRQ_OFFSET 4 45 #define HIF_IC_MAX_IRQ 52 46 47 static uint8_t ic_irqnum[HIF_IC_MAX_IRQ]; 48 /* integrated chip irq names */ 49 const char *ic_irqname[HIF_IC_MAX_IRQ] = { 50 "misc-pulse1", 51 "misc-latch", 52 "sw-exception", 53 "watchdog", 54 "ce0", 55 "ce1", 56 "ce2", 57 "ce3", 58 "ce4", 59 "ce5", 60 "ce6", 61 "ce7", 62 "ce8", 63 "ce9", 64 "ce10", 65 "ce11", 66 "host2wbm-desc-feed", 67 "host2reo-re-injection", 68 "host2reo-command", 69 "host2rxdma-monitor-ring3", 70 "host2rxdma-monitor-ring2", 71 "host2rxdma-monitor-ring1", 72 "reo2ost-exception", 73 "wbm2host-rx-release", 74 "reo2host-status", 75 "reo2host-destination-ring4", 76 "reo2host-destination-ring3", 77 "reo2host-destination-ring2", 78 "reo2host-destination-ring1", 79 "rxdma2host-monitor-destination-mac3", 80 "rxdma2host-monitor-destination-mac2", 81 "rxdma2host-monitor-destination-mac1", 82 "ppdu-end-interrupts-mac3", 83 "ppdu-end-interrupts-mac2", 84 "ppdu-end-interrupts-mac1", 85 "rxdma2host-monitor-status-ring-mac3", 86 "rxdma2host-monitor-status-ring-mac2", 87 "rxdma2host-monitor-status-ring-mac1", 88 "host2rxdma-host-buf-ring-mac3", 89 "host2rxdma-host-buf-ring-mac2", 90 "host2rxdma-host-buf-ring-mac1", 91 "rxdma2host-destination-ring-mac3", 92 "rxdma2host-destination-ring-mac2", 93 "rxdma2host-destination-ring-mac1", 94 "host2tcl-input-ring4", 95 "host2tcl-input-ring3", 96 "host2tcl-input-ring2", 97 "host2tcl-input-ring1", 98 "wbm2host-tx-completions-ring3", 99 "wbm2host-tx-completions-ring2", 100 "wbm2host-tx-completions-ring1", 101 "tcl2host-status-ring", 102 }; 103 104 /** hif_ahb_get_irq_name() - get irqname 105 * This function gives irqnumber to irqname 106 * mapping. 107 * 108 * @irq_no: irq number 109 * 110 * Return: irq name 111 */ 112 const char *hif_ahb_get_irq_name(int irq_no) 113 { 114 return ic_irqname[irq_no]; 115 } 116 117 /** 118 * hif_disable_isr() - disable isr 119 * 120 * This function disables isr and kills tasklets 121 * 122 * @hif_ctx: struct hif_softc 123 * 124 * Return: void 125 */ 126 void hif_ahb_disable_isr(struct hif_softc *scn) 127 { 128 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn); 129 130 hif_exec_kill(&scn->osc); 131 hif_nointrs(scn); 132 ce_tasklet_kill(scn); 133 tasklet_kill(&sc->intr_tq); 134 qdf_atomic_set(&scn->active_tasklet_cnt, 0); 135 qdf_atomic_set(&scn->active_grp_tasklet_cnt, 0); 136 } 137 138 /** 139 * hif_dump_registers() - dump bus debug registers 140 * @scn: struct hif_opaque_softc 141 * 142 * This function dumps hif bus debug registers 143 * 144 * Return: 0 for success or error code 145 */ 146 int hif_ahb_dump_registers(struct hif_softc *hif_ctx) 147 { 148 int status; 149 struct hif_softc *scn = HIF_GET_SOFTC(hif_ctx); 150 151 status = hif_dump_ce_registers(scn); 152 if (status) 153 HIF_ERROR("%s: Dump CE Registers Failed status %d", __func__, 154 status); 155 156 return 0; 157 } 158 159 /** 160 * hif_ahb_close() - hif_bus_close 161 * @scn: pointer to the hif context. 162 * 163 * This is a callback function for hif_bus_close. 164 * 165 * 166 * Return: n/a 167 */ 168 void hif_ahb_close(struct hif_softc *scn) 169 { 170 hif_ce_close(scn); 171 } 172 173 /** 174 * hif_bus_open() - hif_ahb open 175 * @hif_ctx: hif context 176 * @bus_type: bus type 177 * 178 * This is a callback function for hif_bus_open. 179 * 180 * Return: n/a 181 */ 182 QDF_STATUS hif_ahb_open(struct hif_softc *hif_ctx, enum qdf_bus_type bus_type) 183 { 184 185 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(hif_ctx); 186 187 qdf_spinlock_create(&sc->irq_lock); 188 return hif_ce_open(hif_ctx); 189 } 190 191 /** 192 * hif_bus_configure() - Configure the bus 193 * @scn: pointer to the hif context. 194 * 195 * This function configure the ahb bus 196 * 197 * return: 0 for success. nonzero for failure. 198 */ 199 int hif_ahb_bus_configure(struct hif_softc *scn) 200 { 201 return hif_pci_bus_configure(scn); 202 } 203 204 /** 205 * hif_configure_msi_ahb - Configure MSI interrupts 206 * @sc : pointer to the hif context 207 * 208 * return: 0 for success. nonzero for failure. 209 */ 210 211 int hif_configure_msi_ahb(struct hif_pci_softc *sc) 212 { 213 return 0; 214 } 215 216 /** 217 * hif_ahb_configure_legacy_irq() - Configure Legacy IRQ 218 * @sc: pointer to the hif context. 219 * 220 * This function registers the irq handler and enables legacy interrupts 221 * 222 * return: 0 for success. nonzero for failure. 223 */ 224 int hif_ahb_configure_legacy_irq(struct hif_pci_softc *sc) 225 { 226 int ret = 0; 227 struct hif_softc *scn = HIF_GET_SOFTC(sc); 228 struct platform_device *pdev = (struct platform_device *)sc->pdev; 229 int irq = 0; 230 231 /* do not support MSI or MSI IRQ failed */ 232 tasklet_init(&sc->intr_tq, wlan_tasklet, (unsigned long)sc); 233 qal_vbus_get_irq((struct qdf_pfm_hndl *)pdev, "legacy", &irq); 234 if (irq < 0) { 235 dev_err(&pdev->dev, "Unable to get irq\n"); 236 ret = -1; 237 goto end; 238 } 239 ret = request_irq(irq, hif_pci_legacy_ce_interrupt_handler, 240 IRQF_DISABLED, "wlan_ahb", sc); 241 if (ret) { 242 dev_err(&pdev->dev, "ath_request_irq failed\n"); 243 ret = -1; 244 goto end; 245 } 246 sc->irq = irq; 247 248 /* Use Legacy PCI Interrupts */ 249 hif_write32_mb(sc, sc->mem + (SOC_CORE_BASE_ADDRESS | 250 PCIE_INTR_ENABLE_ADDRESS), 251 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL); 252 /* read once to flush */ 253 hif_read32_mb(sc, sc->mem + (SOC_CORE_BASE_ADDRESS | 254 PCIE_INTR_ENABLE_ADDRESS)); 255 256 end: 257 return ret; 258 } 259 260 int hif_ahb_configure_irq(struct hif_pci_softc *sc) 261 { 262 int ret = 0; 263 struct hif_softc *scn = HIF_GET_SOFTC(sc); 264 struct platform_device *pdev = (struct platform_device *)sc->pdev; 265 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); 266 struct CE_attr *host_ce_conf = hif_state->host_ce_config; 267 int irq = 0; 268 int i; 269 270 /* configure per CE interrupts */ 271 for (i = 0; i < scn->ce_count; i++) { 272 if (host_ce_conf[i].flags & CE_ATTR_DISABLE_INTR) 273 continue; 274 qal_vbus_get_irq((struct qdf_pfm_hndl *)pdev, 275 ic_irqname[HIF_IC_CE0_IRQ_OFFSET + i], &irq); 276 ic_irqnum[HIF_IC_CE0_IRQ_OFFSET + i] = irq; 277 ret = request_irq(irq , 278 hif_ahb_interrupt_handler, 279 IRQF_TRIGGER_RISING, ic_irqname[HIF_IC_CE0_IRQ_OFFSET + i], 280 &hif_state->tasklets[i]); 281 if (ret) { 282 dev_err(&pdev->dev, "ath_request_irq failed\n"); 283 ret = -1; 284 goto end; 285 } 286 hif_ahb_irq_enable(scn, i); 287 } 288 289 end: 290 return ret; 291 } 292 293 int hif_ahb_configure_grp_irq(struct hif_softc *scn, 294 struct hif_exec_context *hif_ext_group) 295 { 296 int ret = 0; 297 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn); 298 struct platform_device *pdev = (struct platform_device *)sc->pdev; 299 int irq = 0; 300 int j; 301 302 /* configure external interrupts */ 303 hif_ext_group->irq_enable = &hif_ahb_exec_grp_irq_enable; 304 hif_ext_group->irq_disable = &hif_ahb_exec_grp_irq_disable; 305 hif_ext_group->irq_name = &hif_ahb_get_irq_name; 306 hif_ext_group->work_complete = &hif_dummy_grp_done; 307 308 qdf_spin_lock_irqsave(&hif_ext_group->irq_lock); 309 310 for (j = 0; j < hif_ext_group->numirq; j++) { 311 qal_vbus_get_irq((struct qdf_pfm_hndl *)pdev, 312 ic_irqname[hif_ext_group->irq[j]], &irq); 313 314 ic_irqnum[hif_ext_group->irq[j]] = irq; 315 irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY); 316 ret = request_irq(irq, hif_ext_group_interrupt_handler, 317 IRQF_TRIGGER_RISING, 318 ic_irqname[hif_ext_group->irq[j]], 319 hif_ext_group); 320 if (ret) { 321 dev_err(&pdev->dev, 322 "ath_request_irq failed\n"); 323 ret = -1; 324 goto end; 325 } 326 hif_ext_group->os_irq[j] = irq; 327 } 328 qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock); 329 330 qdf_spin_lock_irqsave(&hif_ext_group->irq_lock); 331 hif_ext_group->irq_requested = true; 332 333 end: 334 qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock); 335 return ret; 336 } 337 338 void hif_ahb_deconfigure_grp_irq(struct hif_softc *scn) 339 { 340 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); 341 struct hif_exec_context *hif_ext_group; 342 int i, j; 343 int irq = 0; 344 345 /* configure external interrupts */ 346 for (i = 0; i < hif_state->hif_num_extgroup; i++) { 347 hif_ext_group = hif_state->hif_ext_group[i]; 348 if (hif_ext_group->irq_requested == true) { 349 qdf_spin_lock_irqsave(&hif_ext_group->irq_lock); 350 hif_ext_group->irq_requested = false; 351 for (j = 0; j < hif_ext_group->numirq; j++) { 352 irq = hif_ext_group->os_irq[j]; 353 hif_ext_group->irq_enabled = false; 354 irq_clear_status_flags(irq, 355 IRQ_DISABLE_UNLAZY); 356 } 357 qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock); 358 359 /* Avoid holding the irq_lock while freeing the irq 360 * as the same lock is being held by the irq handler 361 * while disabling the irq. This causes a deadlock 362 * between free_irq and irq_handler. 363 */ 364 for (j = 0; j < hif_ext_group->numirq; j++) { 365 irq = hif_ext_group->os_irq[j]; 366 free_irq(irq, hif_ext_group); 367 } 368 } 369 } 370 } 371 372 irqreturn_t hif_ahb_interrupt_handler(int irq, void *context) 373 { 374 struct ce_tasklet_entry *tasklet_entry = context; 375 return ce_dispatch_interrupt(tasklet_entry->ce_id, tasklet_entry); 376 } 377 378 /** 379 * hif_target_sync() : ensure the target is ready 380 * @scn: hif control structure 381 * 382 * Informs fw that we plan to use legacy interupts so that 383 * it can begin booting. Ensures that the fw finishes booting 384 * before continuing. Should be called before trying to write 385 * to the targets other registers for the first time. 386 * 387 * Return: none 388 */ 389 int hif_target_sync_ahb(struct hif_softc *scn) 390 { 391 int val = 0; 392 int limit = 0; 393 394 while (limit < 50) { 395 hif_write32_mb(scn, scn->mem + 396 (SOC_CORE_BASE_ADDRESS | PCIE_INTR_ENABLE_ADDRESS), 397 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL); 398 qdf_mdelay(10); 399 val = hif_read32_mb(scn, scn->mem + 400 (SOC_CORE_BASE_ADDRESS | PCIE_INTR_ENABLE_ADDRESS)); 401 if (val == 0) 402 break; 403 limit++; 404 } 405 hif_write32_mb(scn, scn->mem + 406 (SOC_CORE_BASE_ADDRESS | PCIE_INTR_ENABLE_ADDRESS), 407 PCIE_INTR_FIRMWARE_MASK | PCIE_INTR_CE_MASK_ALL); 408 hif_write32_mb(scn, scn->mem + FW_INDICATOR_ADDRESS, FW_IND_HOST_READY); 409 if (HAS_FW_INDICATOR) { 410 int wait_limit = 500; 411 int fw_ind = 0; 412 413 while (1) { 414 fw_ind = hif_read32_mb(scn, scn->mem + 415 FW_INDICATOR_ADDRESS); 416 if (fw_ind & FW_IND_INITIALIZED) 417 break; 418 if (wait_limit-- < 0) 419 break; 420 hif_write32_mb(scn, scn->mem + (SOC_CORE_BASE_ADDRESS | 421 PCIE_INTR_ENABLE_ADDRESS), 422 PCIE_INTR_FIRMWARE_MASK); 423 qdf_mdelay(10); 424 } 425 if (wait_limit < 0) { 426 HIF_TRACE("%s: FW signal timed out", __func__); 427 return -EIO; 428 } 429 HIF_TRACE("%s: Got FW signal, retries = %x", __func__, 430 500-wait_limit); 431 } 432 433 return 0; 434 } 435 436 /** 437 * hif_disable_bus() - Disable the bus 438 * @scn : pointer to the hif context 439 * 440 * This function disables the bus and helds the target in reset state 441 * 442 * Return: none 443 */ 444 void hif_ahb_disable_bus(struct hif_softc *scn) 445 { 446 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn); 447 void __iomem *mem; 448 struct platform_device *pdev = (struct platform_device *)sc->pdev; 449 struct resource *memres = NULL; 450 int mem_pa_size = 0; 451 struct hif_target_info *tgt_info = NULL; 452 struct qdf_vbus_resource *vmres = NULL; 453 454 tgt_info = &scn->target_info; 455 /*Disable WIFI clock input*/ 456 if (sc->mem) { 457 qal_vbus_get_resource((struct qdf_pfm_hndl *)pdev, &vmres, 458 IORESOURCE_MEM, 0); 459 memres = (struct resource *)vmres; 460 if (!memres) { 461 HIF_INFO("%s: Failed to get IORESOURCE_MEM\n", 462 __func__); 463 return; 464 } 465 mem_pa_size = memres->end - memres->start + 1; 466 467 /* Should not be executed on 8074 platform */ 468 if ((tgt_info->target_type != TARGET_TYPE_QCA8074) && 469 (tgt_info->target_type != TARGET_TYPE_QCA8074V2) && 470 (tgt_info->target_type != TARGET_TYPE_QCA6018)) { 471 hif_ahb_clk_enable_disable(&pdev->dev, 0); 472 473 hif_ahb_device_reset(scn); 474 } 475 mem = (void __iomem *)sc->mem; 476 if (mem) { 477 devm_iounmap(&pdev->dev, mem); 478 devm_release_mem_region(&pdev->dev, scn->mem_pa, 479 mem_pa_size); 480 sc->mem = NULL; 481 } 482 } 483 scn->mem = NULL; 484 } 485 486 /** 487 * hif_enable_bus() - Enable the bus 488 * @dev: dev 489 * @bdev: bus dev 490 * @bid: bus id 491 * @type: bus type 492 * 493 * This function enables the radio bus by enabling necessary 494 * clocks and waits for the target to get ready to proceed futher 495 * 496 * Return: QDF_STATUS 497 */ 498 QDF_STATUS hif_ahb_enable_bus(struct hif_softc *ol_sc, 499 struct device *dev, void *bdev, 500 const struct hif_bus_id *bid, 501 enum hif_enable_type type) 502 { 503 int ret = 0; 504 int hif_type; 505 int target_type; 506 const struct platform_device_id *id = (struct platform_device_id *)bid; 507 struct platform_device *pdev = bdev; 508 struct hif_target_info *tgt_info = NULL; 509 struct resource *memres = NULL; 510 void __iomem *mem = NULL; 511 uint32_t revision_id = 0; 512 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(ol_sc); 513 514 sc->pdev = (struct pci_dev *)pdev; 515 sc->dev = &pdev->dev; 516 sc->devid = id->driver_data; 517 518 ret = hif_get_device_type(id->driver_data, revision_id, 519 &hif_type, &target_type); 520 if (ret < 0) { 521 HIF_ERROR("%s: invalid device ret %d id %d revision_id %d", 522 __func__, ret, (int)id->driver_data, revision_id); 523 return QDF_STATUS_E_FAILURE; 524 } 525 526 memres = platform_get_resource(pdev, IORESOURCE_MEM, 0); 527 if (!memres) { 528 HIF_INFO("%s: Failed to get IORESOURCE_MEM\n", __func__); 529 return -EIO; 530 } 531 532 ret = dma_set_mask(dev, DMA_BIT_MASK(32)); 533 if (ret) { 534 HIF_INFO("ath: 32-bit DMA not available\n"); 535 goto err_cleanup1; 536 } 537 538 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) 539 ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); 540 #else 541 ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32)); 542 #endif 543 if (ret) { 544 HIF_ERROR("%s: failed to set dma mask error = %d", 545 __func__, ret); 546 return ret; 547 } 548 549 /* Arrange for access to Target SoC registers. */ 550 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) 551 mem = devm_ioremap_resource(&pdev->dev, memres); 552 #else 553 mem = devm_request_and_ioremap(&pdev->dev, memres); 554 #endif 555 if (IS_ERR(mem)) { 556 HIF_INFO("ath: ioremap error\n"); 557 ret = PTR_ERR(mem); 558 goto err_cleanup1; 559 } 560 561 sc->mem = mem; 562 ol_sc->mem = mem; 563 ol_sc->mem_pa = memres->start; 564 565 tgt_info = hif_get_target_info_handle((struct hif_opaque_softc *)ol_sc); 566 567 tgt_info->target_type = target_type; 568 hif_register_tbl_attach(ol_sc, hif_type); 569 hif_target_register_tbl_attach(ol_sc, target_type); 570 571 /* QCA_WIFI_QCA8074_VP:Should not be executed on 8074 VP platform */ 572 if ((tgt_info->target_type != TARGET_TYPE_QCA8074) && 573 (tgt_info->target_type != TARGET_TYPE_QCA8074V2) && 574 (tgt_info->target_type != TARGET_TYPE_QCA6018)) { 575 if (hif_ahb_enable_radio(sc, pdev, id) != 0) { 576 HIF_INFO("error in enabling soc\n"); 577 return -EIO; 578 } 579 580 if (hif_target_sync_ahb(ol_sc) < 0) { 581 ret = -EIO; 582 goto err_target_sync; 583 } 584 } 585 HIF_TRACE("%s: X - hif_type = 0x%x, target_type = 0x%x", 586 __func__, hif_type, target_type); 587 588 return QDF_STATUS_SUCCESS; 589 err_target_sync: 590 /* QCA_WIFI_QCA8074_VP:Should not be executed on 8074 VP platform */ 591 if ((tgt_info->target_type != TARGET_TYPE_QCA8074) && 592 (tgt_info->target_type != TARGET_TYPE_QCA8074V2) && 593 (tgt_info->target_type != TARGET_TYPE_QCA6018)) { 594 HIF_INFO("Error: Disabling target\n"); 595 hif_ahb_disable_bus(ol_sc); 596 } 597 err_cleanup1: 598 return ret; 599 } 600 601 602 /** 603 * hif_reset_soc() - reset soc 604 * 605 * @hif_ctx: HIF context 606 * 607 * This function resets soc and helds the 608 * target in reset state 609 * 610 * Return: void 611 */ 612 /* Function to reset SoC */ 613 void hif_ahb_reset_soc(struct hif_softc *hif_ctx) 614 { 615 hif_ahb_device_reset(hif_ctx); 616 } 617 618 619 /** 620 * hif_nointrs() - disable IRQ 621 * 622 * @scn: struct hif_softc 623 * 624 * This function stops interrupt(s) 625 * 626 * Return: none 627 */ 628 void hif_ahb_nointrs(struct hif_softc *scn) 629 { 630 int i; 631 struct hif_pci_softc *sc = HIF_GET_PCI_SOFTC(scn); 632 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); 633 struct CE_attr *host_ce_conf = hif_state->host_ce_config; 634 635 ce_unregister_irq(hif_state, CE_ALL_BITMAP); 636 637 if (scn->request_irq_done == false) 638 return; 639 640 if (sc->num_msi_intrs > 0) { 641 /* MSI interrupt(s) */ 642 for (i = 0; i < sc->num_msi_intrs; i++) { 643 free_irq(sc->irq + i, sc); 644 } 645 sc->num_msi_intrs = 0; 646 } else { 647 if (!scn->per_ce_irq) { 648 free_irq(sc->irq, sc); 649 } else { 650 for (i = 0; i < scn->ce_count; i++) { 651 if (host_ce_conf[i].flags 652 & CE_ATTR_DISABLE_INTR) 653 continue; 654 655 free_irq(ic_irqnum[HIF_IC_CE0_IRQ_OFFSET + i], 656 &hif_state->tasklets[i]); 657 } 658 hif_ahb_deconfigure_grp_irq(scn); 659 } 660 } 661 scn->request_irq_done = false; 662 663 } 664 665 /** 666 * ce_irq_enable() - enable copy engine IRQ 667 * @scn: struct hif_softc 668 * @ce_id: ce_id 669 * 670 * This function enables the interrupt for the radio. 671 * 672 * Return: N/A 673 */ 674 void hif_ahb_irq_enable(struct hif_softc *scn, int ce_id) 675 { 676 uint32_t regval; 677 uint32_t reg_offset = 0; 678 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); 679 struct CE_pipe_config *target_ce_conf = &hif_state->target_ce_config[ce_id]; 680 struct hif_target_info *tgt_info = &scn->target_info; 681 682 if (scn->per_ce_irq) { 683 if (target_ce_conf->pipedir & PIPEDIR_OUT) { 684 reg_offset = HOST_IE_ADDRESS; 685 qdf_spin_lock_irqsave(&hif_state->irq_reg_lock); 686 regval = hif_read32_mb(scn, scn->mem + reg_offset); 687 regval |= HOST_IE_REG1_CE_BIT(ce_id); 688 hif_write32_mb(scn, scn->mem + reg_offset, regval); 689 qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock); 690 } 691 if (target_ce_conf->pipedir & PIPEDIR_IN) { 692 reg_offset = HOST_IE_ADDRESS_2; 693 qdf_spin_lock_irqsave(&hif_state->irq_reg_lock); 694 regval = hif_read32_mb(scn, scn->mem + reg_offset); 695 regval |= HOST_IE_REG2_CE_BIT(ce_id); 696 hif_write32_mb(scn, scn->mem + reg_offset, regval); 697 if (tgt_info->target_type == TARGET_TYPE_QCA8074 || 698 tgt_info->target_type == TARGET_TYPE_QCA8074V2 || 699 tgt_info->target_type == TARGET_TYPE_QCA6018) { 700 /* Enable destination ring interrupts for 701 * 8074, 8074V2 and 6018 702 */ 703 regval = hif_read32_mb(scn, scn->mem + 704 HOST_IE_ADDRESS_3); 705 regval |= HOST_IE_REG3_CE_BIT(ce_id); 706 707 hif_write32_mb(scn, scn->mem + 708 HOST_IE_ADDRESS_3, regval); 709 } 710 qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock); 711 } 712 } else { 713 hif_pci_irq_enable(scn, ce_id); 714 } 715 } 716 717 /** 718 * ce_irq_disable() - disable copy engine IRQ 719 * @scn: struct hif_softc 720 * @ce_id: ce_id 721 * 722 * Return: N/A 723 */ 724 void hif_ahb_irq_disable(struct hif_softc *scn, int ce_id) 725 { 726 uint32_t regval; 727 uint32_t reg_offset = 0; 728 struct HIF_CE_state *hif_state = HIF_GET_CE_STATE(scn); 729 struct CE_pipe_config *target_ce_conf = &hif_state->target_ce_config[ce_id]; 730 struct hif_target_info *tgt_info = &scn->target_info; 731 732 if (scn->per_ce_irq) { 733 if (target_ce_conf->pipedir & PIPEDIR_OUT) { 734 reg_offset = HOST_IE_ADDRESS; 735 qdf_spin_lock_irqsave(&hif_state->irq_reg_lock); 736 regval = hif_read32_mb(scn, scn->mem + reg_offset); 737 regval &= ~HOST_IE_REG1_CE_BIT(ce_id); 738 hif_write32_mb(scn, scn->mem + reg_offset, regval); 739 qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock); 740 } 741 if (target_ce_conf->pipedir & PIPEDIR_IN) { 742 reg_offset = HOST_IE_ADDRESS_2; 743 qdf_spin_lock_irqsave(&hif_state->irq_reg_lock); 744 regval = hif_read32_mb(scn, scn->mem + reg_offset); 745 regval &= ~HOST_IE_REG2_CE_BIT(ce_id); 746 hif_write32_mb(scn, scn->mem + reg_offset, regval); 747 if (tgt_info->target_type == TARGET_TYPE_QCA8074 || 748 tgt_info->target_type == TARGET_TYPE_QCA8074V2 || 749 tgt_info->target_type == TARGET_TYPE_QCA6018) { 750 /* Disable destination ring interrupts for 751 * 8074, 8074V2 and 6018 752 */ 753 regval = hif_read32_mb(scn, scn->mem + 754 HOST_IE_ADDRESS_3); 755 regval &= ~HOST_IE_REG3_CE_BIT(ce_id); 756 757 hif_write32_mb(scn, scn->mem + 758 HOST_IE_ADDRESS_3, regval); 759 } 760 qdf_spin_unlock_irqrestore(&hif_state->irq_reg_lock); 761 } 762 } 763 } 764 765 void hif_ahb_exec_grp_irq_disable(struct hif_exec_context *hif_ext_group) 766 { 767 int i; 768 769 qdf_spin_lock_irqsave(&hif_ext_group->irq_lock); 770 if (hif_ext_group->irq_enabled) { 771 for (i = 0; i < hif_ext_group->numirq; i++) { 772 disable_irq_nosync(hif_ext_group->os_irq[i]); 773 } 774 hif_ext_group->irq_enabled = false; 775 } 776 qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock); 777 } 778 779 void hif_ahb_exec_grp_irq_enable(struct hif_exec_context *hif_ext_group) 780 { 781 int i; 782 783 qdf_spin_lock_irqsave(&hif_ext_group->irq_lock); 784 if (hif_ext_group->irq_requested && !hif_ext_group->irq_enabled) { 785 for (i = 0; i < hif_ext_group->numirq; i++) { 786 enable_irq(hif_ext_group->os_irq[i]); 787 } 788 hif_ext_group->irq_enabled = true; 789 } 790 qdf_spin_unlock_irqrestore(&hif_ext_group->irq_lock); 791 } 792 793 /** 794 * hif_ahb_needs_bmi() - return true if the soc needs bmi through the driver 795 * @scn: hif context 796 * 797 * Return: true if soc needs driver bmi otherwise false 798 */ 799 bool hif_ahb_needs_bmi(struct hif_softc *scn) 800 { 801 return !ce_srng_based(scn); 802 } 803