From: Rafał Miłecki Date: Tue, 31 Jan 2017 21:01:05 +0000 (+0100) Subject: kernel: backport bgmac support for external PHYs X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=6a853776a5021ad294918eafdeabeec302d45d8d;p=openwrt%2Fstaging%2Fjow.git kernel: backport bgmac support for external PHYs Signed-off-by: Rafał Miłecki --- diff --git a/target/linux/generic/patches-4.4/072-net-add-devm-version-of-alloc_etherdev_mqs-function.patch b/target/linux/generic/patches-4.4/072-net-add-devm-version-of-alloc_etherdev_mqs-function.patch new file mode 100644 index 0000000000..1d44d487c7 --- /dev/null +++ b/target/linux/generic/patches-4.4/072-net-add-devm-version-of-alloc_etherdev_mqs-function.patch @@ -0,0 +1,70 @@ +From 40be0dda0725886b623d67868db3219a2e74683b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Sat, 28 Jan 2017 15:15:42 +0100 +Subject: [PATCH] net: add devm version of alloc_etherdev_mqs function + +This patch adds devm_alloc_etherdev_mqs function and devm_alloc_etherdev +macro. These can be used for simpler netdev allocation without having to +care about calling free_netdev. + +Thanks to this change drivers, their error paths and removal paths may +get simpler by a bit. + +Signed-off-by: Rafał Miłecki +Signed-off-by: David S. Miller +--- + include/linux/etherdevice.h | 5 +++++ + net/ethernet/eth.c | 28 ++++++++++++++++++++++++++++ + 2 files changed, 33 insertions(+) + +--- a/include/linux/etherdevice.h ++++ b/include/linux/etherdevice.h +@@ -51,6 +51,11 @@ struct net_device *alloc_etherdev_mqs(in + #define alloc_etherdev(sizeof_priv) alloc_etherdev_mq(sizeof_priv, 1) + #define alloc_etherdev_mq(sizeof_priv, count) alloc_etherdev_mqs(sizeof_priv, count, count) + ++struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv, ++ unsigned int txqs, ++ unsigned int rxqs); ++#define devm_alloc_etherdev(dev, sizeof_priv) devm_alloc_etherdev_mqs(dev, sizeof_priv, 1, 1) ++ + struct sk_buff **eth_gro_receive(struct sk_buff **head, + struct sk_buff *skb); + int eth_gro_complete(struct sk_buff *skb, int nhoff); +--- a/net/ethernet/eth.c ++++ b/net/ethernet/eth.c +@@ -387,6 +387,34 @@ struct net_device *alloc_etherdev_mqs(in + } + EXPORT_SYMBOL(alloc_etherdev_mqs); + ++static void devm_free_netdev(struct device *dev, void *res) ++{ ++ free_netdev(*(struct net_device **)res); ++} ++ ++struct net_device *devm_alloc_etherdev_mqs(struct device *dev, int sizeof_priv, ++ unsigned int txqs, unsigned int rxqs) ++{ ++ struct net_device **dr; ++ struct net_device *netdev; ++ ++ dr = devres_alloc(devm_free_netdev, sizeof(*dr), GFP_KERNEL); ++ if (!dr) ++ return NULL; ++ ++ netdev = alloc_etherdev_mqs(sizeof_priv, txqs, rxqs); ++ if (!netdev) { ++ devres_free(dr); ++ return NULL; ++ } ++ ++ *dr = netdev; ++ devres_add(dev, dr); ++ ++ return netdev; ++} ++EXPORT_SYMBOL(devm_alloc_etherdev_mqs); ++ + ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len) + { + return scnprintf(buf, PAGE_SIZE, "%*phC\n", len, addr); diff --git a/target/linux/generic/patches-4.4/073-v4.10-0001-net-bgmac-allocate-struct-bgmac-just-once-don-t-copy.patch b/target/linux/generic/patches-4.4/073-v4.10-0001-net-bgmac-allocate-struct-bgmac-just-once-don-t-copy.patch new file mode 100644 index 0000000000..544a074a78 --- /dev/null +++ b/target/linux/generic/patches-4.4/073-v4.10-0001-net-bgmac-allocate-struct-bgmac-just-once-don-t-copy.patch @@ -0,0 +1,139 @@ +From 34a5102c3235c470a6c77fba16cb971964d9c136 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Tue, 31 Jan 2017 19:37:54 +0100 +Subject: [PATCH 1/3] net: bgmac: allocate struct bgmac just once & don't copy + it +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +So far were were allocating struct bgmac in 3 places: platform code, +bcma code and shared bgmac_enet_probe function. The reason for this was +bgmac_enet_probe: +1) Requiring early-filled struct bgmac +2) Calling alloc_etherdev on its own in order to use netdev_priv later + +This solution got few drawbacks: +1) Was duplicating allocating code +2) Required copying early-filled struct +3) Resulted in platform/bcma code having access only to unused struct + +Solve this situation by simply extracting some probe code into the new +bgmac_alloc function. + +Signed-off-by: Rafał Miłecki +Reviewed-by: Florian Fainelli +Signed-off-by: David S. Miller +--- + drivers/net/ethernet/broadcom/bgmac-bcma.c | 4 +--- + drivers/net/ethernet/broadcom/bgmac-platform.c | 2 +- + drivers/net/ethernet/broadcom/bgmac.c | 25 +++++++++++++++++-------- + drivers/net/ethernet/broadcom/bgmac.h | 3 ++- + 4 files changed, 21 insertions(+), 13 deletions(-) + +--- a/drivers/net/ethernet/broadcom/bgmac-bcma.c ++++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c +@@ -99,12 +99,11 @@ static int bgmac_probe(struct bcma_devic + u8 *mac; + int err; + +- bgmac = kzalloc(sizeof(*bgmac), GFP_KERNEL); ++ bgmac = bgmac_alloc(&core->dev); + if (!bgmac) + return -ENOMEM; + + bgmac->bcma.core = core; +- bgmac->dev = &core->dev; + bgmac->dma_dev = core->dma_dev; + bgmac->irq = core->irq; + +@@ -285,7 +284,6 @@ static int bgmac_probe(struct bcma_devic + err1: + bcma_mdio_mii_unregister(bgmac->mii_bus); + err: +- kfree(bgmac); + bcma_set_drvdata(core, NULL); + + return err; +--- a/drivers/net/ethernet/broadcom/bgmac-platform.c ++++ b/drivers/net/ethernet/broadcom/bgmac-platform.c +@@ -93,7 +93,7 @@ static int bgmac_probe(struct platform_d + struct resource *regs; + const u8 *mac_addr; + +- bgmac = devm_kzalloc(&pdev->dev, sizeof(*bgmac), GFP_KERNEL); ++ bgmac = bgmac_alloc(&pdev->dev); + if (!bgmac) + return -ENOMEM; + +--- a/drivers/net/ethernet/broadcom/bgmac.c ++++ b/drivers/net/ethernet/broadcom/bgmac.c +@@ -1475,22 +1475,32 @@ static int bgmac_phy_connect(struct bgma + return 0; + } + +-int bgmac_enet_probe(struct bgmac *info) ++struct bgmac *bgmac_alloc(struct device *dev) + { + struct net_device *net_dev; + struct bgmac *bgmac; +- int err; + + /* Allocation and references */ +- net_dev = alloc_etherdev(sizeof(*bgmac)); ++ net_dev = devm_alloc_etherdev(dev, sizeof(*bgmac)); + if (!net_dev) +- return -ENOMEM; ++ return NULL; + + net_dev->netdev_ops = &bgmac_netdev_ops; + net_dev->ethtool_ops = &bgmac_ethtool_ops; ++ + bgmac = netdev_priv(net_dev); +- memcpy(bgmac, info, sizeof(*bgmac)); ++ bgmac->dev = dev; + bgmac->net_dev = net_dev; ++ ++ return bgmac; ++} ++EXPORT_SYMBOL_GPL(bgmac_alloc); ++ ++int bgmac_enet_probe(struct bgmac *bgmac) ++{ ++ struct net_device *net_dev = bgmac->net_dev; ++ int err; ++ + net_dev->irq = bgmac->irq; + SET_NETDEV_DEV(net_dev, bgmac->dev); + +@@ -1517,7 +1527,7 @@ int bgmac_enet_probe(struct bgmac *info) + err = bgmac_dma_alloc(bgmac); + if (err) { + dev_err(bgmac->dev, "Unable to alloc memory for DMA\n"); +- goto err_netdev_free; ++ goto err_out; + } + + bgmac->int_mask = BGMAC_IS_ERRMASK | BGMAC_IS_RX | BGMAC_IS_TX_MASK; +@@ -1553,8 +1563,7 @@ err_phy_disconnect: + phy_disconnect(net_dev->phydev); + err_dma_free: + bgmac_dma_free(bgmac); +-err_netdev_free: +- free_netdev(net_dev); ++err_out: + + return err; + } +--- a/drivers/net/ethernet/broadcom/bgmac.h ++++ b/drivers/net/ethernet/broadcom/bgmac.h +@@ -515,7 +515,8 @@ struct bgmac { + u32 set); + }; + +-int bgmac_enet_probe(struct bgmac *info); ++struct bgmac *bgmac_alloc(struct device *dev); ++int bgmac_enet_probe(struct bgmac *bgmac); + void bgmac_enet_remove(struct bgmac *bgmac); + + struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr); diff --git a/target/linux/generic/patches-4.4/073-v4.10-0002-net-bgmac-drop-struct-bcma_mdio-we-don-t-need-anymor.patch b/target/linux/generic/patches-4.4/073-v4.10-0002-net-bgmac-drop-struct-bcma_mdio-we-don-t-need-anymor.patch new file mode 100644 index 0000000000..8848f619ea --- /dev/null +++ b/target/linux/generic/patches-4.4/073-v4.10-0002-net-bgmac-drop-struct-bcma_mdio-we-don-t-need-anymor.patch @@ -0,0 +1,274 @@ +From aa8863e5d49417094b9457a0d53e8505e95a1863 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Tue, 31 Jan 2017 19:37:55 +0100 +Subject: [PATCH 2/3] net: bgmac: drop struct bcma_mdio we don't need anymore +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Adding struct bcma_mdio was a workaround for bcma code not having access +to the struct bgmac used in the core code. Now we don't duplicate this +struct we can just use it internally in bcma code. + +This simplifies code & allows access to all bgmac driver details from +all places in bcma code. + +Signed-off-by: Rafał Miłecki +Reviewed-by: Florian Fainelli +Signed-off-by: David S. Miller +--- + drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c | 98 ++++++++++--------------- + drivers/net/ethernet/broadcom/bgmac-bcma.c | 2 +- + drivers/net/ethernet/broadcom/bgmac.h | 2 +- + 3 files changed, 42 insertions(+), 60 deletions(-) + +--- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c ++++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c +@@ -12,11 +12,6 @@ + #include + #include "bgmac.h" + +-struct bcma_mdio { +- struct bcma_device *core; +- u8 phyaddr; +-}; +- + static bool bcma_mdio_wait_value(struct bcma_device *core, u16 reg, u32 mask, + u32 value, int timeout) + { +@@ -37,7 +32,7 @@ static bool bcma_mdio_wait_value(struct + * PHY ops + **************************************************/ + +-static u16 bcma_mdio_phy_read(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg) ++static u16 bcma_mdio_phy_read(struct bgmac *bgmac, u8 phyaddr, u8 reg) + { + struct bcma_device *core; + u16 phy_access_addr; +@@ -56,12 +51,12 @@ static u16 bcma_mdio_phy_read(struct bcm + BUILD_BUG_ON(BGMAC_PC_MCT_SHIFT != BCMA_GMAC_CMN_PC_MCT_SHIFT); + BUILD_BUG_ON(BGMAC_PC_MTE != BCMA_GMAC_CMN_PC_MTE); + +- if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) { +- core = bcma_mdio->core->bus->drv_gmac_cmn.core; ++ if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) { ++ core = bgmac->bcma.core->bus->drv_gmac_cmn.core; + phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS; + phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL; + } else { +- core = bcma_mdio->core; ++ core = bgmac->bcma.core; + phy_access_addr = BGMAC_PHY_ACCESS; + phy_ctl_addr = BGMAC_PHY_CNTL; + } +@@ -87,7 +82,7 @@ static u16 bcma_mdio_phy_read(struct bcm + } + + /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphywr */ +-static int bcma_mdio_phy_write(struct bcma_mdio *bcma_mdio, u8 phyaddr, u8 reg, ++static int bcma_mdio_phy_write(struct bgmac *bgmac, u8 phyaddr, u8 reg, + u16 value) + { + struct bcma_device *core; +@@ -95,12 +90,12 @@ static int bcma_mdio_phy_write(struct bc + u16 phy_ctl_addr; + u32 tmp; + +- if (bcma_mdio->core->id.id == BCMA_CORE_4706_MAC_GBIT) { +- core = bcma_mdio->core->bus->drv_gmac_cmn.core; ++ if (bgmac->bcma.core->id.id == BCMA_CORE_4706_MAC_GBIT) { ++ core = bgmac->bcma.core->bus->drv_gmac_cmn.core; + phy_access_addr = BCMA_GMAC_CMN_PHY_ACCESS; + phy_ctl_addr = BCMA_GMAC_CMN_PHY_CTL; + } else { +- core = bcma_mdio->core; ++ core = bgmac->bcma.core; + phy_access_addr = BGMAC_PHY_ACCESS; + phy_ctl_addr = BGMAC_PHY_CNTL; + } +@@ -110,8 +105,8 @@ static int bcma_mdio_phy_write(struct bc + tmp |= phyaddr; + bcma_write32(core, phy_ctl_addr, tmp); + +- bcma_write32(bcma_mdio->core, BGMAC_INT_STATUS, BGMAC_IS_MDIO); +- if (bcma_read32(bcma_mdio->core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO) ++ bcma_write32(bgmac->bcma.core, BGMAC_INT_STATUS, BGMAC_IS_MDIO); ++ if (bcma_read32(bgmac->bcma.core, BGMAC_INT_STATUS) & BGMAC_IS_MDIO) + dev_warn(&core->dev, "Error setting MDIO int\n"); + + tmp = BGMAC_PA_START; +@@ -132,39 +127,39 @@ static int bcma_mdio_phy_write(struct bc + } + + /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */ +-static void bcma_mdio_phy_init(struct bcma_mdio *bcma_mdio) ++static void bcma_mdio_phy_init(struct bgmac *bgmac) + { +- struct bcma_chipinfo *ci = &bcma_mdio->core->bus->chipinfo; ++ struct bcma_chipinfo *ci = &bgmac->bcma.core->bus->chipinfo; + u8 i; + + if (ci->id == BCMA_CHIP_ID_BCM5356) { + for (i = 0; i < 5; i++) { +- bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x008b); +- bcma_mdio_phy_write(bcma_mdio, i, 0x15, 0x0100); +- bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f); +- bcma_mdio_phy_write(bcma_mdio, i, 0x12, 0x2aaa); +- bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b); ++ bcma_mdio_phy_write(bgmac, i, 0x1f, 0x008b); ++ bcma_mdio_phy_write(bgmac, i, 0x15, 0x0100); ++ bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f); ++ bcma_mdio_phy_write(bgmac, i, 0x12, 0x2aaa); ++ bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b); + } + } + if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) || + (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) || + (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg != 9)) { +- struct bcma_drv_cc *cc = &bcma_mdio->core->bus->drv_cc; ++ struct bcma_drv_cc *cc = &bgmac->bcma.core->bus->drv_cc; + + bcma_chipco_chipctl_maskset(cc, 2, ~0xc0000000, 0); + bcma_chipco_chipctl_maskset(cc, 4, ~0x80000000, 0); + for (i = 0; i < 5; i++) { +- bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f); +- bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5284); +- bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b); +- bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x0010); +- bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000f); +- bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x5296); +- bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x1073); +- bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9073); +- bcma_mdio_phy_write(bcma_mdio, i, 0x16, 0x52b6); +- bcma_mdio_phy_write(bcma_mdio, i, 0x17, 0x9273); +- bcma_mdio_phy_write(bcma_mdio, i, 0x1f, 0x000b); ++ bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f); ++ bcma_mdio_phy_write(bgmac, i, 0x16, 0x5284); ++ bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b); ++ bcma_mdio_phy_write(bgmac, i, 0x17, 0x0010); ++ bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000f); ++ bcma_mdio_phy_write(bgmac, i, 0x16, 0x5296); ++ bcma_mdio_phy_write(bgmac, i, 0x17, 0x1073); ++ bcma_mdio_phy_write(bgmac, i, 0x17, 0x9073); ++ bcma_mdio_phy_write(bgmac, i, 0x16, 0x52b6); ++ bcma_mdio_phy_write(bgmac, i, 0x17, 0x9273); ++ bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b); + } + } + } +@@ -172,17 +167,17 @@ static void bcma_mdio_phy_init(struct bc + /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */ + static int bcma_mdio_phy_reset(struct mii_bus *bus) + { +- struct bcma_mdio *bcma_mdio = bus->priv; +- u8 phyaddr = bcma_mdio->phyaddr; ++ struct bgmac *bgmac = bus->priv; ++ u8 phyaddr = bgmac->phyaddr; + +- if (bcma_mdio->phyaddr == BGMAC_PHY_NOREGS) ++ if (phyaddr == BGMAC_PHY_NOREGS) + return 0; + +- bcma_mdio_phy_write(bcma_mdio, phyaddr, MII_BMCR, BMCR_RESET); ++ bcma_mdio_phy_write(bgmac, phyaddr, MII_BMCR, BMCR_RESET); + udelay(100); +- if (bcma_mdio_phy_read(bcma_mdio, phyaddr, MII_BMCR) & BMCR_RESET) +- dev_err(&bcma_mdio->core->dev, "PHY reset failed\n"); +- bcma_mdio_phy_init(bcma_mdio); ++ if (bcma_mdio_phy_read(bgmac, phyaddr, MII_BMCR) & BMCR_RESET) ++ dev_err(bgmac->dev, "PHY reset failed\n"); ++ bcma_mdio_phy_init(bgmac); + + return 0; + } +@@ -202,16 +197,12 @@ static int bcma_mdio_mii_write(struct mi + return bcma_mdio_phy_write(bus->priv, mii_id, regnum, value); + } + +-struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr) ++struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac) + { +- struct bcma_mdio *bcma_mdio; ++ struct bcma_device *core = bgmac->bcma.core; + struct mii_bus *mii_bus; + int i, err; + +- bcma_mdio = kzalloc(sizeof(*bcma_mdio), GFP_KERNEL); +- if (!bcma_mdio) +- return ERR_PTR(-ENOMEM); +- + mii_bus = mdiobus_alloc(); + if (!mii_bus) { + err = -ENOMEM; +@@ -221,12 +212,12 @@ struct mii_bus *bcma_mdio_mii_register(s + mii_bus->name = "bcma_mdio mii bus"; + sprintf(mii_bus->id, "%s-%d-%d", "bcma_mdio", core->bus->num, + core->core_unit); +- mii_bus->priv = bcma_mdio; ++ mii_bus->priv = bgmac; + mii_bus->read = bcma_mdio_mii_read; + mii_bus->write = bcma_mdio_mii_write; + mii_bus->reset = bcma_mdio_phy_reset; + mii_bus->parent = &core->dev; +- mii_bus->phy_mask = ~(1 << phyaddr); ++ mii_bus->phy_mask = ~(1 << bgmac->phyaddr); + + mii_bus->irq = kmalloc_array(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL); + if (!mii_bus->irq) { +@@ -236,9 +227,6 @@ struct mii_bus *bcma_mdio_mii_register(s + for (i = 0; i < PHY_MAX_ADDR; i++) + mii_bus->irq[i] = PHY_POLL; + +- bcma_mdio->core = core; +- bcma_mdio->phyaddr = phyaddr; +- + err = mdiobus_register(mii_bus); + if (err) { + dev_err(&core->dev, "Registration of mii bus failed\n"); +@@ -252,24 +240,18 @@ err_free_irq: + err_free_bus: + mdiobus_free(mii_bus); + err: +- kfree(bcma_mdio); + return ERR_PTR(err); + } + EXPORT_SYMBOL_GPL(bcma_mdio_mii_register); + + void bcma_mdio_mii_unregister(struct mii_bus *mii_bus) + { +- struct bcma_mdio *bcma_mdio; +- + if (!mii_bus) + return; + +- bcma_mdio = mii_bus->priv; +- + mdiobus_unregister(mii_bus); + kfree(mii_bus->irq); + mdiobus_free(mii_bus); +- kfree(bcma_mdio); + } + EXPORT_SYMBOL_GPL(bcma_mdio_mii_unregister); + +--- a/drivers/net/ethernet/broadcom/bgmac-bcma.c ++++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c +@@ -159,7 +159,7 @@ static int bgmac_probe(struct bcma_devic + + if (!bgmac_is_bcm4707_family(core) && + !(ci->id == BCMA_CHIP_ID_BCM53573 && core->core_unit == 1)) { +- mii_bus = bcma_mdio_mii_register(core, bgmac->phyaddr); ++ mii_bus = bcma_mdio_mii_register(bgmac); + if (IS_ERR(mii_bus)) { + err = PTR_ERR(mii_bus); + goto err; +--- a/drivers/net/ethernet/broadcom/bgmac.h ++++ b/drivers/net/ethernet/broadcom/bgmac.h +@@ -519,7 +519,7 @@ struct bgmac *bgmac_alloc(struct device + int bgmac_enet_probe(struct bgmac *bgmac); + void bgmac_enet_remove(struct bgmac *bgmac); + +-struct mii_bus *bcma_mdio_mii_register(struct bcma_device *core, u8 phyaddr); ++struct mii_bus *bcma_mdio_mii_register(struct bgmac *bgmac); + void bcma_mdio_mii_unregister(struct mii_bus *mii_bus); + + static inline u32 bgmac_read(struct bgmac *bgmac, u16 offset) diff --git a/target/linux/generic/patches-4.4/073-v4.10-0003-net-bgmac-use-PHY-subsystem-for-initializing-PHY.patch b/target/linux/generic/patches-4.4/073-v4.10-0003-net-bgmac-use-PHY-subsystem-for-initializing-PHY.patch new file mode 100644 index 0000000000..d1be3e3f4c --- /dev/null +++ b/target/linux/generic/patches-4.4/073-v4.10-0003-net-bgmac-use-PHY-subsystem-for-initializing-PHY.patch @@ -0,0 +1,53 @@ +From 8e6f31baba7e2c13ab7e954fe6179420a7545a8b Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= +Date: Tue, 31 Jan 2017 19:37:56 +0100 +Subject: [PATCH 3/3] net: bgmac: use PHY subsystem for initializing PHY +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +This adds support for using bgmac with PHYs supported by standalone PHY +drivers. Having any PHY initialization in bgmac is hacky and shouldn't +be extended but rather removed if anyone has hardware to test it. + +Signed-off-by: Rafał Miłecki +Reviewed-by: Florian Fainelli +Signed-off-by: David S. Miller +--- + drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +--- a/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c ++++ b/drivers/net/ethernet/broadcom/bgmac-bcma-mdio.c +@@ -132,6 +132,10 @@ static void bcma_mdio_phy_init(struct bg + struct bcma_chipinfo *ci = &bgmac->bcma.core->bus->chipinfo; + u8 i; + ++ /* For some legacy hardware we do chipset-based PHY initialization here ++ * without even detecting PHY ID. It's hacky and should be cleaned as ++ * soon as someone can test it. ++ */ + if (ci->id == BCMA_CHIP_ID_BCM5356) { + for (i = 0; i < 5; i++) { + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x008b); +@@ -140,6 +144,7 @@ static void bcma_mdio_phy_init(struct bg + bcma_mdio_phy_write(bgmac, i, 0x12, 0x2aaa); + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b); + } ++ return; + } + if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg != 10) || + (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg != 10) || +@@ -161,7 +166,12 @@ static void bcma_mdio_phy_init(struct bg + bcma_mdio_phy_write(bgmac, i, 0x17, 0x9273); + bcma_mdio_phy_write(bgmac, i, 0x1f, 0x000b); + } ++ return; + } ++ ++ /* For all other hw do initialization using PHY subsystem. */ ++ if (bgmac->net_dev && bgmac->net_dev->phydev) ++ phy_init_hw(bgmac->net_dev->phydev); + } + + /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyreset */ diff --git a/target/linux/generic/patches-4.4/773-bgmac-add-srab-switch.patch b/target/linux/generic/patches-4.4/773-bgmac-add-srab-switch.patch index 990d23dc8e..5e358c38c1 100644 --- a/target/linux/generic/patches-4.4/773-bgmac-add-srab-switch.patch +++ b/target/linux/generic/patches-4.4/773-bgmac-add-srab-switch.patch @@ -30,7 +30,7 @@ Signed-off-by: Hauke Mehrtens /************************************************** * MII **************************************************/ -@@ -1539,6 +1551,14 @@ int bgmac_enet_probe(struct bgmac *info) +@@ -1549,6 +1561,14 @@ int bgmac_enet_probe(struct bgmac *bgmac net_dev->hw_features = net_dev->features; net_dev->vlan_features = net_dev->features; @@ -45,7 +45,7 @@ Signed-off-by: Hauke Mehrtens err = register_netdev(bgmac->net_dev); if (err) { dev_err(bgmac->dev, "Cannot register net device\n"); -@@ -1562,6 +1582,10 @@ EXPORT_SYMBOL_GPL(bgmac_enet_probe); +@@ -1571,6 +1591,10 @@ EXPORT_SYMBOL_GPL(bgmac_enet_probe); void bgmac_enet_remove(struct bgmac *bgmac) { @@ -75,10 +75,10 @@ Signed-off-by: Hauke Mehrtens + struct platform_device *b53_device; }; - int bgmac_enet_probe(struct bgmac *info); + struct bgmac *bgmac_alloc(struct device *dev); --- a/drivers/net/ethernet/broadcom/bgmac-bcma.c +++ b/drivers/net/ethernet/broadcom/bgmac-bcma.c -@@ -231,6 +231,7 @@ static int bgmac_probe(struct bcma_devic +@@ -230,6 +230,7 @@ static int bgmac_probe(struct bcma_devic bgmac->feature_flags |= BGMAC_FEAT_CLKCTLST; bgmac->feature_flags |= BGMAC_FEAT_NO_RESET; bgmac->feature_flags |= BGMAC_FEAT_FORCE_SPEED_2500;