Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

brcm80211: smac: use bcma core access functions in nicpci.c

Code in nicpci.c now uses the PCI(E) core as provided by the BCMA
bus driver to configure that core.

Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: Alwin Beukers <alwin@broadcom.com>
Signed-off-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Franky Lin <frankyl@broadcom.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>

authored by

Arend van Spriel and committed by
John W. Linville
b0327ffa a8779e4a

+89 -110
+3 -8
drivers/net/wireless/brcm80211/brcmsmac/aiutils.c
··· 633 633 634 634 /* fixup necessary chip/core configurations */ 635 635 if (!sii->pch) { 636 - sii->pch = pcicore_init(&sii->pub, sii->pcibus, 637 - sii->curmap + PCI_16KB0_PCIREGS_OFFSET); 636 + sii->pch = pcicore_init(&sii->pub, sii->icbus->drv_pci.core); 638 637 if (sii->pch == NULL) 639 638 return false; 640 639 } ··· 1384 1385 } 1385 1386 1386 1387 if (PCI(sih)) { 1387 - pcicore_pci_setup(sii->pch, regs); 1388 + pcicore_pci_setup(sii->pch); 1388 1389 1389 1390 /* switch back to previous core */ 1390 1391 ai_setcoreidx(sih, idx); ··· 1407 1408 1408 1409 /* check 'pi' is correct and fix it if not */ 1409 1410 regs = ai_setcore(&sii->pub, ai_get_buscoretype(sih), 0); 1410 - if (ai_get_buscoretype(sih) == PCIE_CORE_ID) 1411 - pcicore_fixcfg_pcie(sii->pch, 1412 - (struct sbpcieregs __iomem *)regs); 1413 - else if (ai_get_buscoretype(sih) == PCI_CORE_ID) 1414 - pcicore_fixcfg_pci(sii->pch, (struct sbpciregs __iomem *)regs); 1411 + pcicore_fixcfg(sii->pch); 1415 1412 1416 1413 /* restore the original index */ 1417 1414 ai_setcoreidx(&sii->pub, origidx);
+83 -94
drivers/net/wireless/brcm80211/brcmsmac/nicpci.c
··· 139 139 #define SRSH_PI_MASK 0xf000 /* bit 15:12 */ 140 140 #define SRSH_PI_SHIFT 12 /* bit 15:12 */ 141 141 142 + #define PCIREGOFFS(field) offsetof(struct sbpciregs, field) 143 + #define PCIEREGOFFS(field) offsetof(struct sbpcieregs, field) 144 + 142 145 /* Sonics side: PCI core and host control registers */ 143 146 struct sbpciregs { 144 147 u32 control; /* PCI control */ ··· 208 205 }; 209 206 210 207 struct pcicore_info { 211 - union { 212 - struct sbpcieregs __iomem *pcieregs; 213 - struct sbpciregs __iomem *pciregs; 214 - } regs; /* Memory mapped register to the core */ 215 - 208 + struct bcma_device *core; 216 209 struct si_pub *sih; /* System interconnect handle */ 217 210 struct pci_dev *dev; 218 211 u8 pciecap_lcreg_offset;/* PCIE capability LCreg offset ··· 237 238 /* Initialize the PCI core. 238 239 * It's caller's responsibility to make sure that this is done only once 239 240 */ 240 - struct pcicore_info *pcicore_init(struct si_pub *sih, struct pci_dev *pdev, 241 - void __iomem *regs) 241 + struct pcicore_info *pcicore_init(struct si_pub *sih, struct bcma_device *core) 242 242 { 243 243 struct pcicore_info *pi; 244 244 ··· 247 249 return NULL; 248 250 249 251 pi->sih = sih; 250 - pi->dev = pdev; 252 + pi->dev = core->bus->host_pci; 253 + pi->core = core; 251 254 252 - if (ai_get_buscoretype(sih) == PCIE_CORE_ID) { 255 + if (core->id.id == PCIE_CORE_ID) { 253 256 u8 cap_ptr; 254 - pi->regs.pcieregs = regs; 255 257 cap_ptr = pcicore_find_pci_capability(pi->dev, PCI_CAP_ID_EXP, 256 258 NULL, NULL); 257 259 pi->pciecap_lcreg_offset = cap_ptr + PCIE_CAP_LINKCTRL_OFFSET; 258 - } else 259 - pi->regs.pciregs = regs; 260 - 260 + } 261 261 return pi; 262 262 } 263 263 ··· 330 334 331 335 /* ***** Register Access API */ 332 336 static uint 333 - pcie_readreg(struct sbpcieregs __iomem *pcieregs, uint addrtype, uint offset) 337 + pcie_readreg(struct bcma_device *core, uint addrtype, uint offset) 334 338 { 335 339 uint retval = 0xFFFFFFFF; 336 340 337 341 switch (addrtype) { 338 342 case PCIE_CONFIGREGS: 339 - W_REG(&pcieregs->configaddr, offset); 340 - (void)R_REG((&pcieregs->configaddr)); 341 - retval = R_REG(&pcieregs->configdata); 343 + bcma_write32(core, PCIEREGOFFS(configaddr), offset); 344 + (void)bcma_read32(core, PCIEREGOFFS(configaddr)); 345 + retval = bcma_read32(core, PCIEREGOFFS(configdata)); 342 346 break; 343 347 case PCIE_PCIEREGS: 344 - W_REG(&pcieregs->pcieindaddr, offset); 345 - (void)R_REG(&pcieregs->pcieindaddr); 346 - retval = R_REG(&pcieregs->pcieinddata); 348 + bcma_write32(core, PCIEREGOFFS(pcieindaddr), offset); 349 + (void)bcma_read32(core, PCIEREGOFFS(pcieindaddr)); 350 + retval = bcma_read32(core, PCIEREGOFFS(pcieinddata)); 347 351 break; 348 352 } 349 353 350 354 return retval; 351 355 } 352 356 353 - static uint pcie_writereg(struct sbpcieregs __iomem *pcieregs, uint addrtype, 357 + static uint pcie_writereg(struct bcma_device *core, uint addrtype, 354 358 uint offset, uint val) 355 359 { 356 360 switch (addrtype) { 357 361 case PCIE_CONFIGREGS: 358 - W_REG((&pcieregs->configaddr), offset); 359 - W_REG((&pcieregs->configdata), val); 362 + bcma_write32(core, PCIEREGOFFS(configaddr), offset); 363 + bcma_write32(core, PCIEREGOFFS(configdata), val); 360 364 break; 361 365 case PCIE_PCIEREGS: 362 - W_REG((&pcieregs->pcieindaddr), offset); 363 - W_REG((&pcieregs->pcieinddata), val); 366 + bcma_write32(core, PCIEREGOFFS(pcieindaddr), offset); 367 + bcma_write32(core, PCIEREGOFFS(pcieinddata), val); 364 368 break; 365 369 default: 366 370 break; ··· 370 374 371 375 static bool pcie_mdiosetblock(struct pcicore_info *pi, uint blk) 372 376 { 373 - struct sbpcieregs __iomem *pcieregs = pi->regs.pcieregs; 374 377 uint mdiodata, i = 0; 375 378 uint pcie_serdes_spinwait = 200; 376 379 ··· 377 382 (MDIODATA_DEV_ADDR << MDIODATA_DEVADDR_SHF) | 378 383 (MDIODATA_BLK_ADDR << MDIODATA_REGADDR_SHF) | 379 384 (blk << 4)); 380 - W_REG(&pcieregs->mdiodata, mdiodata); 385 + bcma_write32(pi->core, PCIEREGOFFS(mdiodata), mdiodata); 381 386 382 387 pr28829_delay(); 383 388 /* retry till the transaction is complete */ 384 389 while (i < pcie_serdes_spinwait) { 385 - if (R_REG(&pcieregs->mdiocontrol) & MDIOCTL_ACCESS_DONE) 390 + if (bcma_read32(pi->core, PCIEREGOFFS(mdiocontrol)) & 391 + MDIOCTL_ACCESS_DONE) 386 392 break; 387 393 388 394 udelay(1000); ··· 400 404 pcie_mdioop(struct pcicore_info *pi, uint physmedia, uint regaddr, bool write, 401 405 uint *val) 402 406 { 403 - struct sbpcieregs __iomem *pcieregs = pi->regs.pcieregs; 404 407 uint mdiodata; 405 408 uint i = 0; 406 409 uint pcie_serdes_spinwait = 10; 407 410 408 411 /* enable mdio access to SERDES */ 409 - W_REG(&pcieregs->mdiocontrol, MDIOCTL_PREAM_EN | MDIOCTL_DIVISOR_VAL); 412 + bcma_write32(pi->core, PCIEREGOFFS(mdiocontrol), 413 + MDIOCTL_PREAM_EN | MDIOCTL_DIVISOR_VAL); 410 414 411 415 if (pi->sih->buscorerev >= 10) { 412 416 /* new serdes is slower in rw, ··· 428 432 mdiodata |= (MDIODATA_START | MDIODATA_WRITE | MDIODATA_TA | 429 433 *val); 430 434 431 - W_REG(&pcieregs->mdiodata, mdiodata); 435 + bcma_write32(pi->core, PCIEREGOFFS(mdiodata), mdiodata); 432 436 433 437 pr28829_delay(); 434 438 435 439 /* retry till the transaction is complete */ 436 440 while (i < pcie_serdes_spinwait) { 437 - if (R_REG(&pcieregs->mdiocontrol) & MDIOCTL_ACCESS_DONE) { 441 + if (bcma_read32(pi->core, PCIEREGOFFS(mdiocontrol)) & 442 + MDIOCTL_ACCESS_DONE) { 438 443 if (!write) { 439 444 pr28829_delay(); 440 - *val = (R_REG(&pcieregs->mdiodata) & 445 + *val = (bcma_read32(pi->core, 446 + PCIEREGOFFS(mdiodata)) & 441 447 MDIODATA_MASK); 442 448 } 443 449 /* Disable mdio access to SERDES */ 444 - W_REG(&pcieregs->mdiocontrol, 0); 450 + bcma_write32(pi->core, PCIEREGOFFS(mdiocontrol), 0); 445 451 return 0; 446 452 } 447 453 udelay(1000); ··· 451 453 } 452 454 453 455 /* Timed out. Disable mdio access to SERDES. */ 454 - W_REG(&pcieregs->mdiocontrol, 0); 456 + bcma_write32(pi->core, PCIEREGOFFS(mdiocontrol), 0); 455 457 return 1; 456 458 } 457 459 ··· 500 502 { 501 503 u32 w; 502 504 struct si_pub *sih = pi->sih; 503 - struct sbpcieregs __iomem *pcieregs = pi->regs.pcieregs; 504 505 505 506 if (ai_get_buscoretype(sih) != PCIE_CORE_ID || 506 507 ai_get_buscorerev(sih) < 7) 507 508 return; 508 509 509 - w = pcie_readreg(pcieregs, PCIE_PCIEREGS, PCIE_DLLP_PMTHRESHREG); 510 + w = pcie_readreg(pi->core, PCIE_PCIEREGS, PCIE_DLLP_PMTHRESHREG); 510 511 if (extend) 511 512 w |= PCIE_ASPMTIMER_EXTEND; 512 513 else 513 514 w &= ~PCIE_ASPMTIMER_EXTEND; 514 - pcie_writereg(pcieregs, PCIE_PCIEREGS, PCIE_DLLP_PMTHRESHREG, w); 515 - w = pcie_readreg(pcieregs, PCIE_PCIEREGS, PCIE_DLLP_PMTHRESHREG); 515 + pcie_writereg(pi->core, PCIE_PCIEREGS, PCIE_DLLP_PMTHRESHREG, w); 516 + w = pcie_readreg(pi->core, PCIE_PCIEREGS, PCIE_DLLP_PMTHRESHREG); 516 517 } 517 518 518 519 /* centralized clkreq control policy */ ··· 562 565 if (pi->pcie_polarity != 0) 563 566 return; 564 567 565 - w = pcie_readreg(pi->regs.pcieregs, PCIE_PCIEREGS, PCIE_PLP_STATUSREG); 568 + w = pcie_readreg(pi->core, PCIE_PCIEREGS, PCIE_PLP_STATUSREG); 566 569 567 570 /* Detect the current polarity at attach and force that polarity and 568 571 * disable changing the polarity ··· 581 584 */ 582 585 static void pcie_war_aspm_clkreq(struct pcicore_info *pi) 583 586 { 584 - struct sbpcieregs __iomem *pcieregs = pi->regs.pcieregs; 585 587 struct si_pub *sih = pi->sih; 586 588 u16 val16; 587 - u16 __iomem *reg16; 588 589 u32 w; 589 590 590 591 if (!PCIE_ASPM(sih)) 591 592 return; 592 593 593 594 /* bypass this on QT or VSIM */ 594 - reg16 = &pcieregs->sprom[SRSH_ASPM_OFFSET]; 595 - val16 = R_REG(reg16); 595 + val16 = bcma_read16(pi->core, PCIEREGOFFS(sprom[SRSH_ASPM_OFFSET])); 596 596 597 597 val16 &= ~SRSH_ASPM_ENB; 598 598 if (pi->pcie_war_aspm_ovr == PCIE_ASPM_ENAB) ··· 599 605 else if (pi->pcie_war_aspm_ovr == PCIE_ASPM_L0s_ENAB) 600 606 val16 |= SRSH_ASPM_L0s_ENB; 601 607 602 - W_REG(reg16, val16); 608 + bcma_write16(pi->core, PCIEREGOFFS(sprom[SRSH_ASPM_OFFSET]), val16); 603 609 604 610 pci_read_config_dword(pi->dev, pi->pciecap_lcreg_offset, &w); 605 611 w &= ~PCIE_ASPM_ENAB; 606 612 w |= pi->pcie_war_aspm_ovr; 607 613 pci_write_config_dword(pi->dev, pi->pciecap_lcreg_offset, w); 608 614 609 - reg16 = &pcieregs->sprom[SRSH_CLKREQ_OFFSET_REV5]; 610 - val16 = R_REG(reg16); 615 + val16 = bcma_read16(pi->core, 616 + PCIEREGOFFS(sprom[SRSH_CLKREQ_OFFSET_REV5])); 611 617 612 618 if (pi->pcie_war_aspm_ovr != PCIE_ASPM_DISAB) { 613 619 val16 |= SRSH_CLKREQ_ENB; ··· 615 621 } else 616 622 val16 &= ~SRSH_CLKREQ_ENB; 617 623 618 - W_REG(reg16, val16); 624 + bcma_write16(pi->core, PCIEREGOFFS(sprom[SRSH_CLKREQ_OFFSET_REV5]), 625 + val16); 619 626 } 620 627 621 628 /* Apply the polarity determined at the start */ ··· 640 645 /* Needs to happen when coming out of 'standby'/'hibernate' */ 641 646 static void pcie_misc_config_fixup(struct pcicore_info *pi) 642 647 { 643 - struct sbpcieregs __iomem *pcieregs = pi->regs.pcieregs; 644 648 u16 val16; 645 - u16 __iomem *reg16; 646 649 647 - reg16 = &pcieregs->sprom[SRSH_PCIE_MISC_CONFIG]; 648 - val16 = R_REG(reg16); 650 + val16 = bcma_read16(pi->core, 651 + PCIEREGOFFS(sprom[SRSH_PCIE_MISC_CONFIG])); 649 652 650 653 if ((val16 & SRSH_L23READY_EXIT_NOPERST) == 0) { 651 654 val16 |= SRSH_L23READY_EXIT_NOPERST; 652 - W_REG(reg16, val16); 655 + bcma_write16(pi->core, 656 + PCIEREGOFFS(sprom[SRSH_PCIE_MISC_CONFIG]), val16); 653 657 } 654 658 } 655 659 ··· 656 662 /* Needs to happen when coming out of 'standby'/'hibernate' */ 657 663 static void pcie_war_noplldown(struct pcicore_info *pi) 658 664 { 659 - struct sbpcieregs __iomem *pcieregs = pi->regs.pcieregs; 660 - u16 __iomem *reg16; 661 - 662 665 /* turn off serdes PLL down */ 663 666 ai_cc_reg(pi->sih, offsetof(struct chipcregs, chipcontrol), 664 667 CHIPCTRL_4321_PLL_DOWN, CHIPCTRL_4321_PLL_DOWN); 665 668 666 669 /* clear srom shadow backdoor */ 667 - reg16 = &pcieregs->sprom[SRSH_BD_OFFSET]; 668 - W_REG(reg16, 0); 670 + bcma_write16(pi->core, PCIEREGOFFS(sprom[SRSH_BD_OFFSET]), 0); 669 671 } 670 672 671 673 /* Needs to happen when coming out of 'standby'/'hibernate' */ 672 674 static void pcie_war_pci_setup(struct pcicore_info *pi) 673 675 { 674 676 struct si_pub *sih = pi->sih; 675 - struct sbpcieregs __iomem *pcieregs = pi->regs.pcieregs; 676 677 u32 w; 677 678 678 679 if (ai_get_buscorerev(sih) == 0 || ai_get_buscorerev(sih) == 1) { 679 - w = pcie_readreg(pcieregs, PCIE_PCIEREGS, 680 + w = pcie_readreg(pi->core, PCIE_PCIEREGS, 680 681 PCIE_TLP_WORKAROUNDSREG); 681 682 w |= 0x8; 682 - pcie_writereg(pcieregs, PCIE_PCIEREGS, 683 + pcie_writereg(pi->core, PCIE_PCIEREGS, 683 684 PCIE_TLP_WORKAROUNDSREG, w); 684 685 } 685 686 686 687 if (ai_get_buscorerev(sih) == 1) { 687 - w = pcie_readreg(pcieregs, PCIE_PCIEREGS, PCIE_DLLP_LCREG); 688 + w = pcie_readreg(pi->core, PCIE_PCIEREGS, PCIE_DLLP_LCREG); 688 689 w |= 0x40; 689 - pcie_writereg(pcieregs, PCIE_PCIEREGS, PCIE_DLLP_LCREG, w); 690 + pcie_writereg(pi->core, PCIE_PCIEREGS, PCIE_DLLP_LCREG, w); 690 691 } 691 692 692 693 if (ai_get_buscorerev(sih) == 0) { ··· 690 701 pcie_mdiowrite(pi, MDIODATA_DEV_RX, SERDES_RX_CDRBW, 0x1466); 691 702 } else if (PCIE_ASPM(sih)) { 692 703 /* Change the L1 threshold for better performance */ 693 - w = pcie_readreg(pcieregs, PCIE_PCIEREGS, 704 + w = pcie_readreg(pi->core, PCIE_PCIEREGS, 694 705 PCIE_DLLP_PMTHRESHREG); 695 706 w &= ~PCIE_L1THRESHOLDTIME_MASK; 696 707 w |= PCIE_L1THRESHOLD_WARVAL << PCIE_L1THRESHOLDTIME_SHIFT; 697 - pcie_writereg(pcieregs, PCIE_PCIEREGS, 708 + pcie_writereg(pi->core, PCIE_PCIEREGS, 698 709 PCIE_DLLP_PMTHRESHREG, w); 699 710 700 711 pcie_war_serdes(pi); ··· 783 794 } 784 795 785 796 /* precondition: current core is sii->buscoretype */ 786 - static void pcicore_fixcfg(struct pcicore_info *pi, u16 __iomem *reg16) 797 + void pcicore_fixcfg(struct pcicore_info *pi) 787 798 { 788 - struct si_info *sii = (struct si_info *)(pi->sih); 799 + struct bcma_device *core = pi->core; 789 800 u16 val16; 790 - uint pciidx; 801 + uint regoff; 791 802 792 - pciidx = ai_coreidx(&sii->pub); 793 - val16 = R_REG(reg16); 794 - if (((val16 & SRSH_PI_MASK) >> SRSH_PI_SHIFT) != (u16)pciidx) { 795 - val16 = (u16)(pciidx << SRSH_PI_SHIFT) | 796 - (val16 & ~SRSH_PI_MASK); 797 - W_REG(reg16, val16); 803 + switch (pi->core->id.id) { 804 + case BCMA_CORE_PCI: 805 + regoff = PCIREGOFFS(sprom[SRSH_PI_OFFSET]); 806 + break; 807 + 808 + case BCMA_CORE_PCIE: 809 + regoff = PCIEREGOFFS(sprom[SRSH_PI_OFFSET]); 810 + break; 811 + 812 + default: 813 + return; 798 814 } 799 - } 800 815 801 - void 802 - pcicore_fixcfg_pci(struct pcicore_info *pi, struct sbpciregs __iomem *pciregs) 803 - { 804 - pcicore_fixcfg(pi, &pciregs->sprom[SRSH_PI_OFFSET]); 805 - } 806 - 807 - void pcicore_fixcfg_pcie(struct pcicore_info *pi, 808 - struct sbpcieregs __iomem *pcieregs) 809 - { 810 - pcicore_fixcfg(pi, &pcieregs->sprom[SRSH_PI_OFFSET]); 816 + val16 = bcma_read16(pi->core, regoff); 817 + if (((val16 & SRSH_PI_MASK) >> SRSH_PI_SHIFT) != 818 + (u16)core->core_index) { 819 + val16 = ((u16)core->core_index << SRSH_PI_SHIFT) | 820 + (val16 & ~SRSH_PI_MASK); 821 + bcma_write16(pi->core, regoff, val16); 822 + } 811 823 } 812 824 813 825 /* precondition: current core is pci core */ 814 826 void 815 - pcicore_pci_setup(struct pcicore_info *pi, struct sbpciregs __iomem *pciregs) 827 + pcicore_pci_setup(struct pcicore_info *pi) 816 828 { 817 - u32 w; 829 + bcma_set32(pi->core, PCIREGOFFS(sbtopci2), 830 + SBTOPCI_PREF | SBTOPCI_BURST); 818 831 819 - OR_REG(&pciregs->sbtopci2, SBTOPCI_PREF | SBTOPCI_BURST); 820 - 821 - if (ai_get_buscorerev(pi->sih) >= 11) { 822 - OR_REG(&pciregs->sbtopci2, SBTOPCI_RC_READMULTI); 823 - w = R_REG(&pciregs->clkrun); 824 - W_REG(&pciregs->clkrun, w | PCI_CLKRUN_DSBL); 825 - w = R_REG(&pciregs->clkrun); 832 + if (pi->core->id.rev >= 11) { 833 + bcma_set32(pi->core, PCIREGOFFS(sbtopci2), 834 + SBTOPCI_RC_READMULTI); 835 + bcma_set32(pi->core, PCIREGOFFS(clkrun), PCI_CLKRUN_DSBL); 836 + (void)bcma_read32(pi->core, PCIREGOFFS(clkrun)); 826 837 } 827 838 }
+3 -8
drivers/net/wireless/brcm80211/brcmsmac/nicpci.h
··· 62 62 struct sbpcieregs; 63 63 64 64 extern struct pcicore_info *pcicore_init(struct si_pub *sih, 65 - struct pci_dev *pdev, 66 - void __iomem *regs); 65 + struct bcma_device *core); 67 66 extern void pcicore_deinit(struct pcicore_info *pch); 68 67 extern void pcicore_attach(struct pcicore_info *pch, int state); 69 68 extern void pcicore_hwup(struct pcicore_info *pch); ··· 71 72 extern void pcicore_down(struct pcicore_info *pch, int state); 72 73 extern u8 pcicore_find_pci_capability(struct pci_dev *dev, u8 req_cap_id, 73 74 unsigned char *buf, u32 *buflen); 74 - extern void pcicore_fixcfg_pci(struct pcicore_info *pch, 75 - struct sbpciregs __iomem *pciregs); 76 - extern void pcicore_fixcfg_pcie(struct pcicore_info *pch, 77 - struct sbpcieregs __iomem *pciregs); 78 - extern void pcicore_pci_setup(struct pcicore_info *pch, 79 - struct sbpciregs __iomem *pciregs); 75 + extern void pcicore_fixcfg(struct pcicore_info *pch); 76 + extern void pcicore_pci_setup(struct pcicore_info *pch); 80 77 81 78 #endif /* _BRCM_NICPCI_H_ */