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

net: ethernet: bgmac: Add platform device support

The bcma portion of the driver has been split off into a bcma specific
driver. This has been mirrored for the platform driver. The last
references to the bcma core struct have been changed into a generic
function call. These function calls are wrappers to either the original
bcma code or new platform functions that access the same areas via MMIO.
This necessitated adding function pointers for both platform and bcma to
hide which backend is being used from the generic bgmac code.

Signed-off-by: Jon Mason <jon.mason@broadcom.com>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Tested-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Jon Mason and committed by
David S. Miller
f6a95a24 db791eb2

+652 -287
+22 -1
drivers/net/ethernet/broadcom/Kconfig
··· 140 140 allows for virtual function acceleration in virtual environments. 141 141 142 142 config BGMAC 143 - tristate "BCMA bus GBit core support" 143 + tristate 144 + help 145 + This enables the integrated ethernet controller support for many 146 + Broadcom (mostly iProc) SoCs. An appropriate bus interface driver 147 + needs to be enabled to select this. 148 + 149 + config BGMAC_BCMA 150 + tristate "Broadcom iProc GBit BCMA support" 144 151 depends on BCMA && BCMA_HOST_SOC 145 152 depends on HAS_DMA 146 153 depends on BCM47XX || ARCH_BCM_5301X || COMPILE_TEST 154 + select BGMAC 147 155 select PHYLIB 148 156 select FIXED_PHY 149 157 ---help--- ··· 159 151 They can be found on BCM47xx SoCs and provide gigabit ethernet. 160 152 In case of using this driver on BCM4706 it's also requires to enable 161 153 BCMA_DRIVER_GMAC_CMN to make it work. 154 + 155 + config BGMAC_PLATFORM 156 + tristate "Broadcom iProc GBit platform support" 157 + depends on HAS_DMA 158 + depends on ARCH_BCM_IPROC || COMPILE_TEST 159 + depends on OF 160 + select BGMAC 161 + select PHYLIB 162 + select FIXED_PHY 163 + default ARCH_BCM_IPROC 164 + ---help--- 165 + Say Y here if you want to use the Broadcom iProc Gigabit Ethernet 166 + controller through the generic platform interface 162 167 163 168 config SYSTEMPORT 164 169 tristate "Broadcom SYSTEMPORT internal MAC support"
+3 -1
drivers/net/ethernet/broadcom/Makefile
··· 10 10 obj-$(CONFIG_BNX2X) += bnx2x/ 11 11 obj-$(CONFIG_SB1250_MAC) += sb1250-mac.o 12 12 obj-$(CONFIG_TIGON3) += tg3.o 13 - obj-$(CONFIG_BGMAC) += bgmac.o bgmac-bcma-mdio.o 13 + obj-$(CONFIG_BGMAC) += bgmac.o 14 + obj-$(CONFIG_BGMAC_BCMA) += bgmac-bcma.o bgmac-bcma-mdio.o 15 + obj-$(CONFIG_BGMAC_PLATFORM) += bgmac-platform.o 14 16 obj-$(CONFIG_SYSTEMPORT) += bcmsysport.o 15 17 obj-$(CONFIG_BNXT) += bnxt/
+2
drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c
··· 245 245 kfree(bcma_mdio); 246 246 return ERR_PTR(err); 247 247 } 248 + EXPORT_SYMBOL_GPL(bcma_mdio_mii_register); 248 249 249 250 void bcma_mdio_mii_unregister(struct mii_bus *mii_bus) 250 251 { ··· 260 259 mdiobus_free(mii_bus); 261 260 kfree(bcma_mdio); 262 261 } 262 + EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister); 263 263 264 264 MODULE_AUTHOR("Rafał Miłecki"); 265 265 MODULE_LICENSE("GPL");
+315
drivers/net/ethernet/broadcom/bgmac-bcma.c
··· 1 + /* 2 + * Driver for (BCM4706)? GBit MAC core on BCMA bus. 3 + * 4 + * Copyright (C) 2012 Rafał Miłecki <zajec5@gmail.com> 5 + * 6 + * Licensed under the GNU/GPL. See COPYING for details. 7 + */ 8 + 9 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 10 + 11 + #include <linux/bcma/bcma.h> 12 + #include <linux/brcmphy.h> 13 + #include <linux/etherdevice.h> 14 + #include "bgmac.h" 15 + 16 + static inline bool bgmac_is_bcm4707_family(struct bcma_device *core) 17 + { 18 + switch (core->bus->chipinfo.id) { 19 + case BCMA_CHIP_ID_BCM4707: 20 + case BCMA_CHIP_ID_BCM47094: 21 + case BCMA_CHIP_ID_BCM53018: 22 + return true; 23 + default: 24 + return false; 25 + } 26 + } 27 + 28 + /************************************************** 29 + * BCMA bus ops 30 + **************************************************/ 31 + 32 + static u32 bcma_bgmac_read(struct bgmac *bgmac, u16 offset) 33 + { 34 + return bcma_read32(bgmac->bcma.core, offset); 35 + } 36 + 37 + static void bcma_bgmac_write(struct bgmac *bgmac, u16 offset, u32 value) 38 + { 39 + bcma_write32(bgmac->bcma.core, offset, value); 40 + } 41 + 42 + static u32 bcma_bgmac_idm_read(struct bgmac *bgmac, u16 offset) 43 + { 44 + return bcma_aread32(bgmac->bcma.core, offset); 45 + } 46 + 47 + static void bcma_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value) 48 + { 49 + return bcma_awrite32(bgmac->bcma.core, offset, value); 50 + } 51 + 52 + static bool bcma_bgmac_clk_enabled(struct bgmac *bgmac) 53 + { 54 + return bcma_core_is_enabled(bgmac->bcma.core); 55 + } 56 + 57 + static void bcma_bgmac_clk_enable(struct bgmac *bgmac, u32 flags) 58 + { 59 + bcma_core_enable(bgmac->bcma.core, flags); 60 + } 61 + 62 + static void bcma_bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset, 63 + u32 mask, u32 set) 64 + { 65 + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc; 66 + 67 + bcma_chipco_chipctl_maskset(cc, offset, mask, set); 68 + } 69 + 70 + static u32 bcma_bgmac_get_bus_clock(struct bgmac *bgmac) 71 + { 72 + struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc; 73 + 74 + return bcma_pmu_get_bus_clock(cc); 75 + } 76 + 77 + static void bcma_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, u32 mask, 78 + u32 set) 79 + { 80 + bcma_maskset32(bgmac->bcma.cmn, offset, mask, set); 81 + } 82 + 83 + static const struct bcma_device_id bgmac_bcma_tbl[] = { 84 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, 85 + BCMA_ANY_REV, BCMA_ANY_CLASS), 86 + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_MAC_GBIT, BCMA_ANY_REV, 87 + BCMA_ANY_CLASS), 88 + {}, 89 + }; 90 + MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl); 91 + 92 + /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipattach */ 93 + static int bgmac_probe(struct bcma_device *core) 94 + { 95 + struct ssb_sprom *sprom = &core->bus->sprom; 96 + struct mii_bus *mii_bus; 97 + struct bgmac *bgmac; 98 + u8 *mac; 99 + int err; 100 + 101 + bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL); 102 + if (!bgmac) 103 + return -ENOMEM; 104 + 105 + bgmac->bcma.core = core; 106 + bgmac->dev = &core->dev; 107 + bgmac->dma_dev = core->dma_dev; 108 + bgmac->irq = core->irq; 109 + 110 + bcma_set_drvdata(core, bgmac); 111 + 112 + switch (core->core_unit) { 113 + case 0: 114 + mac = sprom->et0mac; 115 + break; 116 + case 1: 117 + mac = sprom->et1mac; 118 + break; 119 + case 2: 120 + mac = sprom->et2mac; 121 + break; 122 + default: 123 + dev_err(bgmac->dev, "Unsupported core_unit %d\n", 124 + core->core_unit); 125 + err = -ENOTSUPP; 126 + goto err; 127 + } 128 + 129 + ether_addr_copy(bgmac->mac_addr, mac); 130 + 131 + /* On BCM4706 we need common core to access PHY */ 132 + if (core->id.id == BCMA_CORE_4706_MAC_GBIT && 133 + !core->bus->drv_gmac_cmn.core) { 134 + dev_err(bgmac->dev, "GMAC CMN core not found (required for BCM4706)\n"); 135 + err = -ENODEV; 136 + goto err; 137 + } 138 + bgmac->bcma.cmn = core->bus->drv_gmac_cmn.core; 139 + 140 + switch (core->core_unit) { 141 + case 0: 142 + bgmac->phyaddr = sprom->et0phyaddr; 143 + break; 144 + case 1: 145 + bgmac->phyaddr = sprom->et1phyaddr; 146 + break; 147 + case 2: 148 + bgmac->phyaddr = sprom->et2phyaddr; 149 + break; 150 + } 151 + bgmac->phyaddr &= BGMAC_PHY_MASK; 152 + if (bgmac->phyaddr == BGMAC_PHY_MASK) { 153 + dev_err(bgmac->dev, "No PHY found\n"); 154 + err = -ENODEV; 155 + goto err; 156 + } 157 + dev_info(bgmac->dev, "Found PHY addr: %d%s\n", bgmac->phyaddr, 158 + bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : ""); 159 + 160 + if (!bgmac_is_bcm4707_family(core)) { 161 + mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr); 162 + if (!IS_ERR(mii_bus)) { 163 + err = PTR_ERR(mii_bus); 164 + goto err; 165 + } 166 + 167 + bgmac->mii_bus = mii_bus; 168 + } 169 + 170 + if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) { 171 + dev_err(bgmac->dev, "PCI setup not implemented\n"); 172 + err = -ENOTSUPP; 173 + goto err1; 174 + } 175 + 176 + bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo & 177 + BGMAC_BFL_ENETROBO); 178 + if (bgmac->has_robosw) 179 + dev_warn(bgmac->dev, "Support for Roboswitch not implemented\n"); 180 + 181 + if (core->bus->sprom.boardflags_lo & BGMAC_BFL_ENETADM) 182 + dev_warn(bgmac->dev, "Support for ADMtek ethernet switch not implemented\n"); 183 + 184 + /* Feature Flags */ 185 + switch (core->bus->chipinfo.id) { 186 + case BCMA_CHIP_ID_BCM5357: 187 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 188 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 189 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1; 190 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY; 191 + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47186) { 192 + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED; 193 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII; 194 + } 195 + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM5358) 196 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_EPHYRMII; 197 + break; 198 + case BCMA_CHIP_ID_BCM53572: 199 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 200 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 201 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1; 202 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY; 203 + if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47188) { 204 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII; 205 + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED; 206 + } 207 + break; 208 + case BCMA_CHIP_ID_BCM4749: 209 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 210 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 211 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1; 212 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY; 213 + if (core->bus->chipinfo.pkg == 10) { 214 + bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII; 215 + bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED; 216 + } 217 + break; 218 + case BCMA_CHIP_ID_BCM4716: 219 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 220 + /* fallthrough */ 221 + case BCMA_CHIP_ID_BCM47162: 222 + bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL2; 223 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 224 + break; 225 + /* bcm4707_family */ 226 + case BCMA_CHIP_ID_BCM4707: 227 + case BCMA_CHIP_ID_BCM47094: 228 + case BCMA_CHIP_ID_BCM53018: 229 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 230 + bgmac->feature_flags |= BGMAC_FEAT_NO_RESET; 231 + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500; 232 + break; 233 + default: 234 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 235 + bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 236 + } 237 + 238 + if (!bgmac_is_bcm4707_family(core) && core->id.rev > 2) 239 + bgmac->feature_flags |= BGMAC_FEAT_MISC_PLL_REQ; 240 + 241 + if (core->id.id == BCMA_CORE_4706_MAC_GBIT) { 242 + bgmac->feature_flags |= BGMAC_FEAT_CMN_PHY_CTL; 243 + bgmac->feature_flags |= BGMAC_FEAT_NO_CLR_MIB; 244 + } 245 + 246 + if (core->id.rev >= 4) { 247 + bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4; 248 + bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP; 249 + bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP; 250 + } 251 + 252 + bgmac->read = bcma_bgmac_read; 253 + bgmac->write = bcma_bgmac_write; 254 + bgmac->idm_read = bcma_bgmac_idm_read; 255 + bgmac->idm_write = bcma_bgmac_idm_write; 256 + bgmac->clk_enabled = bcma_bgmac_clk_enabled; 257 + bgmac->clk_enable = bcma_bgmac_clk_enable; 258 + bgmac->cco_ctl_maskset = bcma_bgmac_cco_ctl_maskset; 259 + bgmac->get_bus_clock = bcma_bgmac_get_bus_clock; 260 + bgmac->cmn_maskset32 = bcma_bgmac_cmn_maskset32; 261 + 262 + err = bgmac_enet_probe(bgmac); 263 + if (err) 264 + goto err1; 265 + 266 + return 0; 267 + 268 + err1: 269 + bcma_mdio_mii_unregister(bgmac->mii_bus); 270 + err: 271 + kfree(bgmac); 272 + bcma_set_drvdata(core, NULL); 273 + 274 + return err; 275 + } 276 + 277 + static void bgmac_remove(struct bcma_device *core) 278 + { 279 + struct bgmac *bgmac = bcma_get_drvdata(core); 280 + 281 + bcma_mdio_mii_unregister(bgmac->mii_bus); 282 + bgmac_enet_remove(bgmac); 283 + bcma_set_drvdata(core, NULL); 284 + kfree(bgmac); 285 + } 286 + 287 + static struct bcma_driver bgmac_bcma_driver = { 288 + .name = KBUILD_MODNAME, 289 + .id_table = bgmac_bcma_tbl, 290 + .probe = bgmac_probe, 291 + .remove = bgmac_remove, 292 + }; 293 + 294 + static int __init bgmac_init(void) 295 + { 296 + int err; 297 + 298 + err = bcma_driver_register(&bgmac_bcma_driver); 299 + if (err) 300 + return err; 301 + pr_info("Broadcom 47xx GBit MAC driver loaded\n"); 302 + 303 + return 0; 304 + } 305 + 306 + static void __exit bgmac_exit(void) 307 + { 308 + bcma_driver_unregister(&bgmac_bcma_driver); 309 + } 310 + 311 + module_init(bgmac_init) 312 + module_exit(bgmac_exit) 313 + 314 + MODULE_AUTHOR("Rafał Miłecki"); 315 + MODULE_LICENSE("GPL");
+189
drivers/net/ethernet/broadcom/bgmac-platform.c
··· 1 + /* 2 + * Copyright (C) 2016 Broadcom 3 + * 4 + * This program is free software; you can redistribute it and/or 5 + * modify it under the terms of the GNU General Public License as 6 + * published by the Free Software Foundation version 2. 7 + * 8 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any 9 + * kind, whether express or implied; without even the implied warranty 10 + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 + * GNU General Public License for more details. 12 + */ 13 + 14 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 15 + 16 + #include <linux/bcma/bcma.h> 17 + #include <linux/etherdevice.h> 18 + #include <linux/of_address.h> 19 + #include <linux/of_net.h> 20 + #include "bgmac.h" 21 + 22 + static u32 platform_bgmac_read(struct bgmac *bgmac, u16 offset) 23 + { 24 + return readl(bgmac->plat.base + offset); 25 + } 26 + 27 + static void platform_bgmac_write(struct bgmac *bgmac, u16 offset, u32 value) 28 + { 29 + writel(value, bgmac->plat.base + offset); 30 + } 31 + 32 + static u32 platform_bgmac_idm_read(struct bgmac *bgmac, u16 offset) 33 + { 34 + return readl(bgmac->plat.idm_base + offset); 35 + } 36 + 37 + static void platform_bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value) 38 + { 39 + return writel(value, bgmac->plat.idm_base + offset); 40 + } 41 + 42 + static bool platform_bgmac_clk_enabled(struct bgmac *bgmac) 43 + { 44 + if ((bgmac_idm_read(bgmac, BCMA_IOCTL) & 45 + (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC)) != BCMA_IOCTL_CLK) 46 + return false; 47 + if (bgmac_idm_read(bgmac, BCMA_RESET_CTL) & BCMA_RESET_CTL_RESET) 48 + return false; 49 + return true; 50 + } 51 + 52 + static void platform_bgmac_clk_enable(struct bgmac *bgmac, u32 flags) 53 + { 54 + bgmac_idm_write(bgmac, BCMA_IOCTL, 55 + (BCMA_IOCTL_CLK | BCMA_IOCTL_FGC | flags)); 56 + bgmac_idm_read(bgmac, BCMA_IOCTL); 57 + 58 + bgmac_idm_write(bgmac, BCMA_RESET_CTL, 0); 59 + bgmac_idm_read(bgmac, BCMA_RESET_CTL); 60 + udelay(1); 61 + 62 + bgmac_idm_write(bgmac, BCMA_IOCTL, (BCMA_IOCTL_CLK | flags)); 63 + bgmac_idm_read(bgmac, BCMA_IOCTL); 64 + udelay(1); 65 + } 66 + 67 + static void platform_bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset, 68 + u32 mask, u32 set) 69 + { 70 + /* This shouldn't be encountered */ 71 + WARN_ON(1); 72 + } 73 + 74 + static u32 platform_bgmac_get_bus_clock(struct bgmac *bgmac) 75 + { 76 + /* This shouldn't be encountered */ 77 + WARN_ON(1); 78 + 79 + return 0; 80 + } 81 + 82 + static void platform_bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, 83 + u32 mask, u32 set) 84 + { 85 + /* This shouldn't be encountered */ 86 + WARN_ON(1); 87 + } 88 + 89 + static int bgmac_probe(struct platform_device *pdev) 90 + { 91 + struct device_node *np = pdev->dev.of_node; 92 + struct bgmac *bgmac; 93 + struct resource *regs; 94 + const u8 *mac_addr; 95 + 96 + bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL); 97 + if (!bgmac) 98 + return -ENOMEM; 99 + 100 + platform_set_drvdata(pdev, bgmac); 101 + 102 + /* Set the features of the 4707 family */ 103 + bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 104 + bgmac->feature_flags |= BGMAC_FEAT_NO_RESET; 105 + bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500; 106 + bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4; 107 + bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP; 108 + bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP; 109 + 110 + bgmac->dev = &pdev->dev; 111 + bgmac->dma_dev = &pdev->dev; 112 + 113 + mac_addr = of_get_mac_address(np); 114 + if (mac_addr) 115 + ether_addr_copy(bgmac->mac_addr, mac_addr); 116 + else 117 + dev_warn(&pdev->dev, "MAC address not present in device tree\n"); 118 + 119 + bgmac->irq = platform_get_irq(pdev, 0); 120 + if (bgmac->irq < 0) { 121 + dev_err(&pdev->dev, "Unable to obtain IRQ\n"); 122 + return bgmac->irq; 123 + } 124 + 125 + regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "amac_base"); 126 + if (!regs) { 127 + dev_err(&pdev->dev, "Unable to obtain base resource\n"); 128 + return -EINVAL; 129 + } 130 + 131 + bgmac->plat.base = devm_ioremap_resource(&pdev->dev, regs); 132 + if (IS_ERR(bgmac->plat.base)) { 133 + dev_err(&pdev->dev, "Unable to map base resource\n"); 134 + return PTR_ERR(bgmac->plat.base); 135 + } 136 + 137 + regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "idm_base"); 138 + if (!regs) { 139 + dev_err(&pdev->dev, "Unable to obtain idm resource\n"); 140 + return -EINVAL; 141 + } 142 + 143 + bgmac->plat.idm_base = devm_ioremap_resource(&pdev->dev, regs); 144 + if (!bgmac->plat.idm_base) { 145 + dev_err(&pdev->dev, "Unable to map idm resource\n"); 146 + return PTR_ERR(bgmac->plat.idm_base); 147 + } 148 + 149 + bgmac->read = platform_bgmac_read; 150 + bgmac->write = platform_bgmac_write; 151 + bgmac->idm_read = platform_bgmac_idm_read; 152 + bgmac->idm_write = platform_bgmac_idm_write; 153 + bgmac->clk_enabled = platform_bgmac_clk_enabled; 154 + bgmac->clk_enable = platform_bgmac_clk_enable; 155 + bgmac->cco_ctl_maskset = platform_bgmac_cco_ctl_maskset; 156 + bgmac->get_bus_clock = platform_bgmac_get_bus_clock; 157 + bgmac->cmn_maskset32 = platform_bgmac_cmn_maskset32; 158 + 159 + return bgmac_enet_probe(bgmac); 160 + } 161 + 162 + static int bgmac_remove(struct platform_device *pdev) 163 + { 164 + struct bgmac *bgmac = platform_get_drvdata(pdev); 165 + 166 + bgmac_enet_remove(bgmac); 167 + 168 + return 0; 169 + } 170 + 171 + static const struct of_device_id bgmac_of_enet_match[] = { 172 + {.compatible = "brcm,amac",}, 173 + {.compatible = "brcm,nsp-amac",}, 174 + {}, 175 + }; 176 + 177 + MODULE_DEVICE_TABLE(of, bgmac_of_enet_match); 178 + 179 + static struct platform_driver bgmac_enet_driver = { 180 + .driver = { 181 + .name = "bgmac-enet", 182 + .of_match_table = bgmac_of_enet_match, 183 + }, 184 + .probe = bgmac_probe, 185 + .remove = bgmac_remove, 186 + }; 187 + 188 + module_platform_driver(bgmac_enet_driver); 189 + MODULE_LICENSE("GPL");
+54 -279
drivers/net/ethernet/broadcom/bgmac.c
··· 6 6 * Licensed under the GNU/GPL. See COPYING for details. 7 7 */ 8 8 9 + 10 + #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 11 + 12 + #include <linux/bcma/bcma.h> 13 + #include <linux/etherdevice.h> 14 + #include <linux/bcm47xx_nvram.h> 9 15 #include "bgmac.h" 10 16 11 - #include <linux/kernel.h> 12 - #include <linux/module.h> 13 - #include <linux/delay.h> 14 - #include <linux/etherdevice.h> 15 - #include <linux/mii.h> 16 - #include <linux/phy.h> 17 - #include <linux/phy_fixed.h> 18 - #include <linux/interrupt.h> 19 - #include <linux/dma-mapping.h> 20 - #include <linux/bcm47xx_nvram.h> 21 - 22 - static const struct bcma_device_id bgmac_bcma_tbl[] = { 23 - BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS), 24 - BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS), 25 - {}, 26 - }; 27 - MODULE_DEVICE_TABLE(bcma, bgmac_bcma_tbl); 28 - 29 - static inline bool bgmac_is_bcm4707_family(struct bgmac *bgmac) 30 - { 31 - switch (bgmac->core->bus->chipinfo.id) { 32 - case BCMA_CHIP_ID_BCM4707: 33 - case BCMA_CHIP_ID_BCM47094: 34 - case BCMA_CHIP_ID_BCM53018: 35 - return true; 36 - default: 37 - return false; 38 - } 39 - } 40 - 41 - static bool bgmac_wait_value(struct bcma_device *core, u16 reg, u32 mask, 17 + static bool bgmac_wait_value(struct bgmac *bgmac, u16 reg, u32 mask, 42 18 u32 value, int timeout) 43 19 { 44 20 u32 val; 45 21 int i; 46 22 47 23 for (i = 0; i < timeout / 10; i++) { 48 - val = bcma_read32(core, reg); 24 + val = bgmac_read(bgmac, reg); 49 25 if ((val & mask) == value) 50 26 return true; 51 27 udelay(10); 52 28 } 53 - dev_err(&core->dev, "Timeout waiting for reg 0x%X\n", reg); 29 + dev_err(bgmac->dev, "Timeout waiting for reg 0x%X\n", reg); 54 30 return false; 55 31 } 56 32 ··· 65 89 66 90 /* Remove SUSPEND bit */ 67 91 bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_TX_CTL, 0); 68 - if (!bgmac_wait_value(bgmac->core, 92 + if (!bgmac_wait_value(bgmac, 69 93 ring->mmio_base + BGMAC_DMA_TX_STATUS, 70 94 BGMAC_DMA_TX_STAT, BGMAC_DMA_TX_STAT_DISABLED, 71 95 10000)) { ··· 293 317 return; 294 318 295 319 bgmac_write(bgmac, ring->mmio_base + BGMAC_DMA_RX_CTL, 0); 296 - if (!bgmac_wait_value(bgmac->core, 320 + if (!bgmac_wait_value(bgmac, 297 321 ring->mmio_base + BGMAC_DMA_RX_STATUS, 298 322 BGMAC_DMA_RX_STAT, BGMAC_DMA_RX_STAT_DISABLED, 299 323 10000)) ··· 616 640 BUILD_BUG_ON(BGMAC_MAX_TX_RINGS > ARRAY_SIZE(ring_base)); 617 641 BUILD_BUG_ON(BGMAC_MAX_RX_RINGS > ARRAY_SIZE(ring_base)); 618 642 619 - if (!(bcma_aread32(bgmac->core, BCMA_IOST) & BCMA_IOST_DMA64)) { 643 + if (!(bgmac_idm_read(bgmac, BCMA_IOST) & BCMA_IOST_DMA64)) { 620 644 dev_err(bgmac->dev, "Core does not report 64-bit DMA\n"); 621 645 return -ENOTSUPP; 622 646 } ··· 848 872 849 873 static void bgmac_miiconfig(struct bgmac *bgmac) 850 874 { 851 - struct bcma_device *core = bgmac->core; 852 - 853 875 if (bgmac->feature_flags & BGMAC_FEAT_FORCE_SPEED_2500) { 854 - bcma_awrite32(core, BCMA_IOCTL, 855 - bcma_aread32(core, BCMA_IOCTL) | 0x40 | 856 - BGMAC_BCMA_IOCTL_SW_CLKEN); 876 + bgmac_idm_write(bgmac, BCMA_IOCTL, 877 + bgmac_idm_read(bgmac, BCMA_IOCTL) | 0x40 | 878 + BGMAC_BCMA_IOCTL_SW_CLKEN); 857 879 bgmac->mac_speed = SPEED_2500; 858 880 bgmac->mac_duplex = DUPLEX_FULL; 859 881 bgmac_mac_speed(bgmac); ··· 871 897 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipreset */ 872 898 static void bgmac_chip_reset(struct bgmac *bgmac) 873 899 { 874 - struct bcma_device *core = bgmac->core; 875 900 u32 cmdcfg_sr; 876 901 u32 iost; 877 902 int i; 878 903 879 - if (bcma_core_is_enabled(core)) { 904 + if (bgmac_clk_enabled(bgmac)) { 880 905 if (!bgmac->stats_grabbed) { 881 906 /* bgmac_chip_stats_update(bgmac); */ 882 907 bgmac->stats_grabbed = true; ··· 893 920 /* TODO: Clear software multicast filter list */ 894 921 } 895 922 896 - iost = bcma_aread32(core, BCMA_IOST); 923 + iost = bgmac_idm_read(bgmac, BCMA_IOST); 897 924 if (bgmac->feature_flags & BGMAC_FEAT_IOST_ATTACHED) 898 925 iost &= ~BGMAC_BCMA_IOST_ATTACHED; 899 926 ··· 905 932 if (!bgmac->has_robosw) 906 933 flags |= BGMAC_BCMA_IOCTL_SW_RESET; 907 934 } 908 - bcma_core_enable(core, flags); 935 + bgmac_clk_enable(bgmac, flags); 909 936 } 910 937 911 938 /* Request Misc PLL for corerev > 2 */ 912 939 if (bgmac->feature_flags & BGMAC_FEAT_MISC_PLL_REQ) { 913 940 bgmac_set(bgmac, BCMA_CLKCTLST, 914 941 BGMAC_BCMA_CLKCTLST_MISC_PLL_REQ); 915 - bgmac_wait_value(bgmac->core, BCMA_CLKCTLST, 942 + bgmac_wait_value(bgmac, BCMA_CLKCTLST, 916 943 BGMAC_BCMA_CLKCTLST_MISC_PLL_ST, 917 944 BGMAC_BCMA_CLKCTLST_MISC_PLL_ST, 918 945 1000); 919 946 } 920 947 921 948 if (bgmac->feature_flags & BGMAC_FEAT_SW_TYPE_PHY) { 922 - struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc; 923 949 u8 et_swtype = 0; 924 950 u8 sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHY | 925 951 BGMAC_CHIPCTL_1_IF_TYPE_MII; ··· 937 965 sw_type = BGMAC_CHIPCTL_1_IF_TYPE_RGMII | 938 966 BGMAC_CHIPCTL_1_SW_TYPE_RGMII; 939 967 } 940 - bcma_chipco_chipctl_maskset(cc, 1, 941 - ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK | 942 - BGMAC_CHIPCTL_1_SW_TYPE_MASK), 943 - sw_type); 968 + bgmac_cco_ctl_maskset(bgmac, 1, ~(BGMAC_CHIPCTL_1_IF_TYPE_MASK | 969 + BGMAC_CHIPCTL_1_SW_TYPE_MASK), 970 + sw_type); 944 971 } 945 972 946 973 if (iost & BGMAC_BCMA_IOST_ATTACHED && !bgmac->has_robosw) 947 - bcma_awrite32(core, BCMA_IOCTL, 948 - bcma_aread32(core, BCMA_IOCTL) & 949 - ~BGMAC_BCMA_IOCTL_SW_RESET); 974 + bgmac_idm_write(bgmac, BCMA_IOCTL, 975 + bgmac_idm_read(bgmac, BCMA_IOCTL) & 976 + ~BGMAC_BCMA_IOCTL_SW_RESET); 950 977 951 978 /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_reset 952 979 * Specs don't say about using BGMAC_CMDCFG_SR, but in this routine ··· 981 1010 982 1011 bgmac_clear_mib(bgmac); 983 1012 if (bgmac->feature_flags & BGMAC_FEAT_CMN_PHY_CTL) 984 - bcma_maskset32(bgmac->cmn, BCMA_GMAC_CMN_PHY_CTL, ~0, 985 - BCMA_GMAC_CMN_PC_MTE); 1013 + bgmac_cmn_maskset32(bgmac, BCMA_GMAC_CMN_PHY_CTL, ~0, 1014 + BCMA_GMAC_CMN_PC_MTE); 986 1015 else 987 1016 bgmac_set(bgmac, BGMAC_PHY_CNTL, BGMAC_PC_MTE); 988 1017 bgmac_miiconfig(bgmac); ··· 1027 1056 if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST || mode != 0) 1028 1057 bgmac_set(bgmac, BCMA_CLKCTLST, BCMA_CLKCTLST_FORCEHT); 1029 1058 if (bgmac->feature_flags & BGMAC_FEAT_CLKCTLST && mode == 2) 1030 - bcma_chipco_chipctl_maskset(&bgmac->core->bus->drv_cc, 1, ~0, 1031 - BGMAC_CHIPCTL_1_RXC_DLL_BYPASS); 1059 + bgmac_cco_ctl_maskset(bgmac, 1, ~0, 1060 + BGMAC_CHIPCTL_1_RXC_DLL_BYPASS); 1032 1061 1033 1062 if (bgmac->feature_flags & (BGMAC_FEAT_FLW_CTRL1 | 1034 1063 BGMAC_FEAT_FLW_CTRL2)) { ··· 1050 1079 1051 1080 rxq_ctl = bgmac_read(bgmac, BGMAC_RXQ_CTL); 1052 1081 rxq_ctl &= ~BGMAC_RXQ_CTL_MDP_MASK; 1053 - bp_clk = bcma_pmu_get_bus_clock(&bgmac->core->bus->drv_cc) / 1054 - 1000000; 1082 + bp_clk = bgmac_get_bus_clock(bgmac) / 1000000; 1055 1083 mdp = (bp_clk * 128 / 1000) - 3; 1056 1084 rxq_ctl |= (mdp << BGMAC_RXQ_CTL_MDP_SHIFT); 1057 1085 bgmac_write(bgmac, BGMAC_RXQ_CTL, rxq_ctl); ··· 1145 1175 /* Specs say about reclaiming rings here, but we do that in DMA init */ 1146 1176 bgmac_chip_init(bgmac); 1147 1177 1148 - err = request_irq(bgmac->core->irq, bgmac_interrupt, IRQF_SHARED, 1178 + err = request_irq(bgmac->irq, bgmac_interrupt, IRQF_SHARED, 1149 1179 KBUILD_MODNAME, net_dev); 1150 1180 if (err < 0) { 1151 1181 dev_err(bgmac->dev, "IRQ request error: %d!\n", err); ··· 1171 1201 1172 1202 napi_disable(&bgmac->napi); 1173 1203 bgmac_chip_intrs_off(bgmac); 1174 - free_irq(bgmac->core->irq, net_dev); 1204 + free_irq(bgmac->irq, net_dev); 1175 1205 1176 1206 bgmac_chip_reset(bgmac); 1177 1207 bgmac_dma_cleanup(bgmac); ··· 1350 1380 struct ethtool_drvinfo *info) 1351 1381 { 1352 1382 strlcpy(info->driver, KBUILD_MODNAME, sizeof(info->driver)); 1353 - strlcpy(info->bus_info, "BCMA", sizeof(info->bus_info)); 1383 + strlcpy(info->bus_info, "AXI", sizeof(info->bus_info)); 1354 1384 } 1355 1385 1356 1386 static const struct ethtool_ops bgmac_ethtool_ops = { ··· 1434 1464 return 0; 1435 1465 } 1436 1466 1437 - static int bgmac_probe(struct bcma_device *core) 1467 + int bgmac_enet_probe(struct bgmac *info) 1438 1468 { 1439 1469 struct net_device *net_dev; 1440 1470 struct bgmac *bgmac; 1441 - struct ssb_sprom *sprom = &core->bus->sprom; 1442 - u8 *mac; 1443 1471 int err; 1444 - 1445 - switch (core->core_unit) { 1446 - case 0: 1447 - mac = sprom->et0mac; 1448 - break; 1449 - case 1: 1450 - mac = sprom->et1mac; 1451 - break; 1452 - case 2: 1453 - mac = sprom->et2mac; 1454 - break; 1455 - default: 1456 - dev_err(&core->dev, "Unsupported core_unit %d\n", 1457 - core->core_unit); 1458 - return -ENOTSUPP; 1459 - } 1460 - 1461 - if (!is_valid_ether_addr(mac)) { 1462 - dev_err(&core->dev, "Invalid MAC addr: %pM\n", mac); 1463 - eth_random_addr(mac); 1464 - dev_warn(&core->dev, "Using random MAC: %pM\n", mac); 1465 - } 1466 - 1467 - /* This (reset &) enable is not preset in specs or reference driver but 1468 - * Broadcom does it in arch PCI code when enabling fake PCI device. 1469 - */ 1470 - bcma_core_enable(core, 0); 1471 1472 1472 1473 /* Allocation and references */ 1473 1474 net_dev = alloc_etherdev(sizeof(*bgmac)); 1474 1475 if (!net_dev) 1475 1476 return -ENOMEM; 1477 + 1476 1478 net_dev->netdev_ops = &bgmac_netdev_ops; 1477 - net_dev->irq = core->irq; 1478 1479 net_dev->ethtool_ops = &bgmac_ethtool_ops; 1479 1480 bgmac = netdev_priv(net_dev); 1480 - bgmac->dev = &core->dev; 1481 - bgmac->dma_dev = core->dma_dev; 1481 + memcpy(bgmac, info, sizeof(*bgmac)); 1482 1482 bgmac->net_dev = net_dev; 1483 - bgmac->core = core; 1484 - bcma_set_drvdata(core, bgmac); 1485 - SET_NETDEV_DEV(net_dev, &core->dev); 1483 + net_dev->irq = bgmac->irq; 1484 + SET_NETDEV_DEV(net_dev, bgmac->dev); 1486 1485 1487 - /* Defaults */ 1488 - memcpy(bgmac->net_dev->dev_addr, mac, ETH_ALEN); 1486 + if (!is_valid_ether_addr(bgmac->mac_addr)) { 1487 + dev_err(bgmac->dev, "Invalid MAC addr: %pM\n", 1488 + bgmac->mac_addr); 1489 + eth_random_addr(bgmac->mac_addr); 1490 + dev_warn(bgmac->dev, "Using random MAC: %pM\n", 1491 + bgmac->mac_addr); 1492 + } 1493 + ether_addr_copy(net_dev->dev_addr, bgmac->mac_addr); 1489 1494 1490 - /* On BCM4706 we need common core to access PHY */ 1491 - if (core->id.id == BCMA_CORE_4706_MAC_GBIT && 1492 - !core->bus->drv_gmac_cmn.core) { 1493 - dev_err(bgmac->dev, "GMAC CMN core not found (required for BCM4706)\n"); 1494 - err = -ENODEV; 1495 - goto err_netdev_free; 1496 - } 1497 - bgmac->cmn = core->bus->drv_gmac_cmn.core; 1498 - 1499 - switch (core->core_unit) { 1500 - case 0: 1501 - bgmac->phyaddr = sprom->et0phyaddr; 1502 - break; 1503 - case 1: 1504 - bgmac->phyaddr = sprom->et1phyaddr; 1505 - break; 1506 - case 2: 1507 - bgmac->phyaddr = sprom->et2phyaddr; 1508 - break; 1509 - } 1510 - bgmac->phyaddr &= BGMAC_PHY_MASK; 1511 - if (bgmac->phyaddr == BGMAC_PHY_MASK) { 1512 - dev_err(bgmac->dev, "No PHY found\n"); 1513 - err = -ENODEV; 1514 - goto err_netdev_free; 1515 - } 1516 - dev_info(bgmac->dev, "Found PHY addr: %d%s\n", bgmac->phyaddr, 1517 - bgmac->phyaddr == BGMAC_PHY_NOREGS ? " (NOREGS)" : ""); 1518 - 1519 - if (core->bus->hosttype == BCMA_HOSTTYPE_PCI) { 1520 - dev_err(bgmac->dev, "PCI setup not implemented\n"); 1521 - err = -ENOTSUPP; 1522 - goto err_netdev_free; 1523 - } 1495 + /* This (reset &) enable is not preset in specs or reference driver but 1496 + * Broadcom does it in arch PCI code when enabling fake PCI device. 1497 + */ 1498 + bgmac_clk_enable(bgmac, 0); 1524 1499 1525 1500 bgmac_chip_reset(bgmac); 1526 - 1527 - /* For Northstar, we have to take all GMAC core out of reset */ 1528 - if (bgmac_is_bcm4707_family(bgmac)) { 1529 - struct bcma_device *ns_core; 1530 - int ns_gmac; 1531 - 1532 - /* Northstar has 4 GMAC cores */ 1533 - for (ns_gmac = 0; ns_gmac < 4; ns_gmac++) { 1534 - /* As Northstar requirement, we have to reset all GMACs 1535 - * before accessing one. bgmac_chip_reset() call 1536 - * bcma_core_enable() for this core. Then the other 1537 - * three GMACs didn't reset. We do it here. 1538 - */ 1539 - ns_core = bcma_find_core_unit(core->bus, 1540 - BCMA_CORE_MAC_GBIT, 1541 - ns_gmac); 1542 - if (ns_core && !bcma_core_is_enabled(ns_core)) 1543 - bcma_core_enable(ns_core, 0); 1544 - } 1545 - } 1546 1501 1547 1502 err = bgmac_dma_alloc(bgmac); 1548 1503 if (err) { ··· 1479 1584 if (bcm47xx_nvram_getenv("et0_no_txint", NULL, 0) == 0) 1480 1585 bgmac->int_mask &= ~BGMAC_IS_TX_MASK; 1481 1586 1482 - bgmac->has_robosw = !!(core->bus->sprom.boardflags_lo & 1483 - BGMAC_BFL_ENETROBO); 1484 - if (bgmac->has_robosw) 1485 - dev_warn(bgmac->dev, "Support for Roboswitch not implemented\n"); 1486 - 1487 - if (core->bus->sprom.boardflags_lo & BGMAC_BFL_ENETADM) 1488 - dev_warn(bgmac->dev, "Support for ADMtek ethernet switch not implemented\n"); 1489 - 1490 - /* Feature Flags */ 1491 - switch (core->bus->chipinfo.id) { 1492 - case BCMA_CHIP_ID_BCM5357: 1493 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 1494 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 1495 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1; 1496 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY; 1497 - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47186) { 1498 - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED; 1499 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII; 1500 - } 1501 - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM5358) 1502 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_EPHYRMII; 1503 - break; 1504 - case BCMA_CHIP_ID_BCM53572: 1505 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 1506 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 1507 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1; 1508 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY; 1509 - if (core->bus->chipinfo.pkg == BCMA_PKG_ID_BCM47188) { 1510 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII; 1511 - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED; 1512 - } 1513 - break; 1514 - case BCMA_CHIP_ID_BCM4749: 1515 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 1516 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 1517 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL1; 1518 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_PHY; 1519 - if (core->bus->chipinfo.pkg == 10) { 1520 - bgmac->feature_flags |= BGMAC_FEAT_SW_TYPE_RGMII; 1521 - bgmac->feature_flags |= BGMAC_FEAT_IOST_ATTACHED; 1522 - } 1523 - break; 1524 - case BCMA_CHIP_ID_BCM4716: 1525 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 1526 - /* fallthrough */ 1527 - case BCMA_CHIP_ID_BCM47162: 1528 - bgmac->feature_flags |= BGMAC_FEAT_FLW_CTRL2; 1529 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 1530 - break; 1531 - /* bcm4707_family */ 1532 - case BCMA_CHIP_ID_BCM4707: 1533 - case BCMA_CHIP_ID_BCM47094: 1534 - case BCMA_CHIP_ID_BCM53018: 1535 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 1536 - bgmac->feature_flags |= BGMAC_FEAT_NO_RESET; 1537 - bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500; 1538 - break; 1539 - default: 1540 - bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; 1541 - bgmac->feature_flags |= BGMAC_FEAT_SET_RXQ_CLK; 1542 - } 1543 - 1544 - if (!bgmac_is_bcm4707_family(bgmac) && core->id.rev > 2) 1545 - bgmac->feature_flags |= BGMAC_FEAT_MISC_PLL_REQ; 1546 - 1547 - if (core->id.id == BCMA_CORE_4706_MAC_GBIT) { 1548 - bgmac->feature_flags |= BGMAC_FEAT_CMN_PHY_CTL; 1549 - bgmac->feature_flags |= BGMAC_FEAT_NO_CLR_MIB; 1550 - } 1551 - 1552 - if (core->id.rev >= 4) { 1553 - bgmac->feature_flags |= BGMAC_FEAT_CMDCFG_SR_REV4; 1554 - bgmac->feature_flags |= BGMAC_FEAT_TX_MASK_SETUP; 1555 - bgmac->feature_flags |= BGMAC_FEAT_RX_MASK_SETUP; 1556 - } 1557 - 1558 1587 netif_napi_add(net_dev, &bgmac->napi, bgmac_poll, BGMAC_WEIGHT); 1559 - 1560 - if (!bgmac_is_bcm4707_family(bgmac)) { 1561 - struct mii_bus *mii_bus; 1562 - 1563 - mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr); 1564 - if (!IS_ERR(mii_bus)) { 1565 - err = PTR_ERR(mii_bus); 1566 - goto err_dma_free; 1567 - } 1568 - 1569 - bgmac->mii_bus = mii_bus; 1570 - } 1571 1588 1572 1589 if (!bgmac->mii_bus) 1573 1590 err = bgmac_phy_connect_direct(bgmac); ··· 1487 1680 err = bgmac_phy_connect(bgmac); 1488 1681 if (err) { 1489 1682 dev_err(bgmac->dev, "Cannot connect to phy\n"); 1490 - goto err_mii_unregister; 1683 + goto err_dma_free; 1491 1684 } 1492 1685 1493 1686 net_dev->features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM; ··· 1506 1699 1507 1700 err_phy_disconnect: 1508 1701 phy_disconnect(net_dev->phydev); 1509 - err_mii_unregister: 1510 - bcma_mdio_mii_unregister(bgmac->mii_bus); 1511 1702 err_dma_free: 1512 1703 bgmac_dma_free(bgmac); 1513 1704 err_netdev_free: 1514 - bcma_set_drvdata(core, NULL); 1515 1705 free_netdev(net_dev); 1516 1706 1517 1707 return err; 1518 1708 } 1709 + EXPORT_SYMBOL_GPL(bgmac_enet_probe); 1519 1710 1520 - static void bgmac_remove(struct bcma_device *core) 1711 + void bgmac_enet_remove(struct bgmac *bgmac) 1521 1712 { 1522 - struct bgmac *bgmac = bcma_get_drvdata(core); 1523 - 1524 1713 unregister_netdev(bgmac->net_dev); 1525 1714 phy_disconnect(bgmac->net_dev->phydev); 1526 - bcma_mdio_mii_unregister(bgmac->mii_bus); 1527 1715 netif_napi_del(&bgmac->napi); 1528 1716 bgmac_dma_free(bgmac); 1529 - bcma_set_drvdata(core, NULL); 1530 1717 free_netdev(bgmac->net_dev); 1531 1718 } 1532 - 1533 - static struct bcma_driver bgmac_bcma_driver = { 1534 - .name = KBUILD_MODNAME, 1535 - .id_table = bgmac_bcma_tbl, 1536 - .probe = bgmac_probe, 1537 - .remove = bgmac_remove, 1538 - }; 1539 - 1540 - static int __init bgmac_init(void) 1541 - { 1542 - int err; 1543 - 1544 - err = bcma_driver_register(&bgmac_bcma_driver); 1545 - if (err) 1546 - return err; 1547 - pr_info("Broadcom 47xx GBit MAC driver loaded\n"); 1548 - 1549 - return 0; 1550 - } 1551 - 1552 - static void __exit bgmac_exit(void) 1553 - { 1554 - bcma_driver_unregister(&bgmac_bcma_driver); 1555 - } 1556 - 1557 - module_init(bgmac_init) 1558 - module_exit(bgmac_exit) 1719 + EXPORT_SYMBOL_GPL(bgmac_enet_remove); 1559 1720 1560 1721 MODULE_AUTHOR("Rafał Miłecki"); 1561 1722 MODULE_LICENSE("GPL");
+67 -6
drivers/net/ethernet/broadcom/bgmac.h
··· 1 1 #ifndef _BGMAC_H 2 2 #define _BGMAC_H 3 3 4 - #include <linux/bcma/bcma.h> 5 - #include <linux/brcmphy.h> 6 4 #include <linux/netdevice.h> 7 5 8 6 #define BGMAC_DEV_CTL 0x000 ··· 440 442 }; 441 443 442 444 struct bgmac { 443 - struct bcma_device *core; 444 - struct bcma_device *cmn; /* Reference to CMN core for BCM4706 */ 445 + union { 446 + struct { 447 + void *base; 448 + void *idm_base; 449 + } plat; 450 + struct { 451 + struct bcma_device *core; 452 + /* Reference to CMN core for BCM4706 */ 453 + struct bcma_device *cmn; 454 + } bcma; 455 + }; 445 456 446 457 struct device *dev; 447 458 struct device *dma_dev; 459 + unsigned char mac_addr[ETH_ALEN]; 448 460 u32 feature_flags; 449 461 450 462 struct net_device *net_dev; ··· 471 463 u32 mib_rx_regs[BGMAC_NUM_MIB_RX_REGS]; 472 464 473 465 /* Int */ 466 + int irq; 474 467 u32 int_mask; 475 468 476 469 /* Current MAC state */ ··· 482 473 bool has_robosw; 483 474 484 475 bool loopback; 476 + 477 + u32 (*read)(struct bgmac *bgmac, u16 offset); 478 + void (*write)(struct bgmac *bgmac, u16 offset, u32 value); 479 + u32 (*idm_read)(struct bgmac *bgmac, u16 offset); 480 + void (*idm_write)(struct bgmac *bgmac, u16 offset, u32 value); 481 + bool (*clk_enabled)(struct bgmac *bgmac); 482 + void (*clk_enable)(struct bgmac *bgmac, u32 flags); 483 + void (*cco_ctl_maskset)(struct bgmac *bgmac, u32 offset, u32 mask, 484 + u32 set); 485 + u32 (*get_bus_clock)(struct bgmac *bgmac); 486 + void (*cmn_maskset32)(struct bgmac *bgmac, u16 offset, u32 mask, 487 + u32 set); 485 488 }; 489 + 490 + int bgmac_enet_probe(struct bgmac *info); 491 + void bgmac_enet_remove(struct bgmac *bgmac); 486 492 487 493 struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr); 488 494 void bcma_mdio_mii_unregister(struct mii_bus *mii_bus); 489 495 490 496 static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset) 491 497 { 492 - return bcma_read32(bgmac->core, offset); 498 + return bgmac->read(bgmac, offset); 493 499 } 494 500 495 501 static inline void bgmac_write(struct bgmac *bgmac, u16 offset, u32 value) 496 502 { 497 - bcma_write32(bgmac->core, offset, value); 503 + bgmac->write(bgmac, offset, value); 504 + } 505 + 506 + static inline u32 bgmac_idm_read(struct bgmac *bgmac, u16 offset) 507 + { 508 + return bgmac->idm_read(bgmac, offset); 509 + } 510 + 511 + static inline void bgmac_idm_write(struct bgmac *bgmac, u16 offset, u32 value) 512 + { 513 + bgmac->idm_write(bgmac, offset, value); 514 + } 515 + 516 + static inline bool bgmac_clk_enabled(struct bgmac *bgmac) 517 + { 518 + return bgmac->clk_enabled(bgmac); 519 + } 520 + 521 + static inline void bgmac_clk_enable(struct bgmac *bgmac, u32 flags) 522 + { 523 + bgmac->clk_enable(bgmac, flags); 524 + } 525 + 526 + static inline void bgmac_cco_ctl_maskset(struct bgmac *bgmac, u32 offset, 527 + u32 mask, u32 set) 528 + { 529 + bgmac->cco_ctl_maskset(bgmac, offset, mask, set); 530 + } 531 + 532 + static inline u32 bgmac_get_bus_clock(struct bgmac *bgmac) 533 + { 534 + return bgmac->get_bus_clock(bgmac); 535 + } 536 + 537 + static inline void bgmac_cmn_maskset32(struct bgmac *bgmac, u16 offset, 538 + u32 mask, u32 set) 539 + { 540 + bgmac->cmn_maskset32(bgmac, offset, mask, set); 498 541 } 499 542 500 543 static inline void bgmac_maskset(struct bgmac *bgmac, u16 offset, u32 mask,