aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/generic/patches-3.10/770-bgmac-backport.patch
diff options
context:
space:
mode:
Diffstat (limited to 'target/linux/generic/patches-3.10/770-bgmac-backport.patch')
-rw-r--r--target/linux/generic/patches-3.10/770-bgmac-backport.patch395
1 files changed, 393 insertions, 2 deletions
diff --git a/target/linux/generic/patches-3.10/770-bgmac-backport.patch b/target/linux/generic/patches-3.10/770-bgmac-backport.patch
index 38a34a930f..c6c8736866 100644
--- a/target/linux/generic/patches-3.10/770-bgmac-backport.patch
+++ b/target/linux/generic/patches-3.10/770-bgmac-backport.patch
@@ -338,7 +338,156 @@ patches for bgmac backported from net-next/master
ring->num_slots * sizeof(struct bgmac_dma_desc));
ring->start = 0;
-@@ -909,9 +958,9 @@ static void bgmac_chip_reset(struct bgma
+@@ -633,70 +682,6 @@ static int bgmac_phy_write(struct bgmac
+ return 0;
+ }
+
+-/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyforce */
+-static void bgmac_phy_force(struct bgmac *bgmac)
+-{
+- u16 ctl;
+- u16 mask = ~(BGMAC_PHY_CTL_SPEED | BGMAC_PHY_CTL_SPEED_MSB |
+- BGMAC_PHY_CTL_ANENAB | BGMAC_PHY_CTL_DUPLEX);
+-
+- if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
+- return;
+-
+- if (bgmac->autoneg)
+- return;
+-
+- ctl = bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL);
+- ctl &= mask;
+- if (bgmac->full_duplex)
+- ctl |= BGMAC_PHY_CTL_DUPLEX;
+- if (bgmac->speed == BGMAC_SPEED_100)
+- ctl |= BGMAC_PHY_CTL_SPEED_100;
+- else if (bgmac->speed == BGMAC_SPEED_1000)
+- ctl |= BGMAC_PHY_CTL_SPEED_1000;
+- bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL, ctl);
+-}
+-
+-/* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyadvertise */
+-static void bgmac_phy_advertise(struct bgmac *bgmac)
+-{
+- u16 adv;
+-
+- if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
+- return;
+-
+- if (!bgmac->autoneg)
+- return;
+-
+- /* Adv selected 10/100 speeds */
+- adv = bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV);
+- adv &= ~(BGMAC_PHY_ADV_10HALF | BGMAC_PHY_ADV_10FULL |
+- BGMAC_PHY_ADV_100HALF | BGMAC_PHY_ADV_100FULL);
+- if (!bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_10)
+- adv |= BGMAC_PHY_ADV_10HALF;
+- if (!bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_100)
+- adv |= BGMAC_PHY_ADV_100HALF;
+- if (bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_10)
+- adv |= BGMAC_PHY_ADV_10FULL;
+- if (bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_100)
+- adv |= BGMAC_PHY_ADV_100FULL;
+- bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV, adv);
+-
+- /* Adv selected 1000 speeds */
+- adv = bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV2);
+- adv &= ~(BGMAC_PHY_ADV2_1000HALF | BGMAC_PHY_ADV2_1000FULL);
+- if (!bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_1000)
+- adv |= BGMAC_PHY_ADV2_1000HALF;
+- if (bgmac->full_duplex && bgmac->speed & BGMAC_SPEED_1000)
+- adv |= BGMAC_PHY_ADV2_1000FULL;
+- bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_ADV2, adv);
+-
+- /* Restart */
+- bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
+- bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) |
+- BGMAC_PHY_CTL_RESTART);
+-}
+-
+ /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/chipphyinit */
+ static void bgmac_phy_init(struct bgmac *bgmac)
+ {
+@@ -827,19 +812,28 @@ static void bgmac_clear_mib(struct bgmac
+ }
+
+ /* http://bcm-v4.sipsolutions.net/mac-gbit/gmac/gmac_speed */
+-static void bgmac_speed(struct bgmac *bgmac, int speed)
++static void bgmac_mac_speed(struct bgmac *bgmac)
+ {
+ u32 mask = ~(BGMAC_CMDCFG_ES_MASK | BGMAC_CMDCFG_HD);
+ u32 set = 0;
+
+- if (speed & BGMAC_SPEED_10)
++ switch (bgmac->mac_speed) {
++ case SPEED_10:
+ set |= BGMAC_CMDCFG_ES_10;
+- if (speed & BGMAC_SPEED_100)
++ break;
++ case SPEED_100:
+ set |= BGMAC_CMDCFG_ES_100;
+- if (speed & BGMAC_SPEED_1000)
++ break;
++ case SPEED_1000:
+ set |= BGMAC_CMDCFG_ES_1000;
+- if (!bgmac->full_duplex)
++ break;
++ default:
++ bgmac_err(bgmac, "Unsupported speed: %d\n", bgmac->mac_speed);
++ }
++
++ if (bgmac->mac_duplex == DUPLEX_HALF)
+ set |= BGMAC_CMDCFG_HD;
++
+ bgmac_cmdcfg_maskset(bgmac, mask, set, true);
+ }
+
+@@ -848,10 +842,9 @@ static void bgmac_miiconfig(struct bgmac
+ u8 imode = (bgmac_read(bgmac, BGMAC_DEV_STATUS) & BGMAC_DS_MM_MASK) >>
+ BGMAC_DS_MM_SHIFT;
+ if (imode == 0 || imode == 1) {
+- if (bgmac->autoneg)
+- bgmac_speed(bgmac, BGMAC_SPEED_100);
+- else
+- bgmac_speed(bgmac, bgmac->speed);
++ bgmac->mac_speed = SPEED_100;
++ bgmac->mac_duplex = DUPLEX_FULL;
++ bgmac_mac_speed(bgmac);
+ }
+ }
+
+@@ -884,9 +877,9 @@ static void bgmac_chip_reset(struct bgma
+ }
+
+ iost = bcma_aread32(core, BCMA_IOST);
+- if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 10) ||
++ if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == BCMA_PKG_ID_BCM47186) ||
+ (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg == 10) ||
+- (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg == 9))
++ (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg == BCMA_PKG_ID_BCM47188))
+ iost &= ~BGMAC_BCMA_IOST_ATTACHED;
+
+ if (iost & BGMAC_BCMA_IOST_ATTACHED) {
+@@ -898,30 +891,35 @@ static void bgmac_chip_reset(struct bgma
+ bcma_core_enable(core, flags);
+
+ if (core->id.rev > 2) {
+- bgmac_set(bgmac, BCMA_CLKCTLST, 1 << 8);
+- bgmac_wait_value(bgmac->core, BCMA_CLKCTLST, 1 << 24, 1 << 24,
++ bgmac_set(bgmac, BCMA_CLKCTLST,
++ BGMAC_BCMA_CLKCTLST_MISC_PLL_REQ);
++ bgmac_wait_value(bgmac->core, BCMA_CLKCTLST,
++ BGMAC_BCMA_CLKCTLST_MISC_PLL_ST,
++ BGMAC_BCMA_CLKCTLST_MISC_PLL_ST,
+ 1000);
+ }
+
+- if (ci->id == BCMA_CHIP_ID_BCM5357 || ci->id == BCMA_CHIP_ID_BCM4749 ||
++ if (ci->id == BCMA_CHIP_ID_BCM5357 ||
++ ci->id == BCMA_CHIP_ID_BCM4749 ||
+ ci->id == BCMA_CHIP_ID_BCM53572) {
+ struct bcma_drv_cc *cc = &bgmac->core->bus->drv_cc;
u8 et_swtype = 0;
u8 sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHY |
BGMAC_CHIPCTL_1_IF_TYPE_MII;
@@ -350,7 +499,30 @@ patches for bgmac backported from net-next/master
if (kstrtou8(buf, 0, &et_swtype))
bgmac_err(bgmac, "Failed to parse et_swtype (%s)\n",
buf);
-@@ -970,6 +1019,8 @@ static void bgmac_chip_reset(struct bgma
+ et_swtype &= 0x0f;
+ et_swtype <<= 4;
+ sw_type = et_swtype;
+- } else if (ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == 9) {
++ } else if (ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == BCMA_PKG_ID_BCM5358) {
+ sw_type = BGMAC_CHIPCTL_1_SW_TYPE_EPHYRMII;
+- } else if ((ci->id != BCMA_CHIP_ID_BCM53572 && ci->pkg == 10) ||
+- (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg == 9)) {
++ } else if ((ci->id == BCMA_CHIP_ID_BCM5357 && ci->pkg == BCMA_PKG_ID_BCM47186) ||
++ (ci->id == BCMA_CHIP_ID_BCM4749 && ci->pkg == 10) ||
++ (ci->id == BCMA_CHIP_ID_BCM53572 && ci->pkg == BCMA_PKG_ID_BCM47188)) {
+ sw_type = BGMAC_CHIPCTL_1_IF_TYPE_RGMII |
+ BGMAC_CHIPCTL_1_SW_TYPE_RGMII;
+ }
+@@ -960,6 +958,8 @@ static void bgmac_chip_reset(struct bgma
+ BGMAC_CMDCFG_CFE |
+ BGMAC_CMDCFG_SR,
+ false);
++ bgmac->mac_speed = SPEED_UNKNOWN;
++ bgmac->mac_duplex = DUPLEX_UNKNOWN;
+
+ bgmac_clear_mib(bgmac);
+ if (core->id.id == BCMA_CORE_4706_MAC_GBIT)
+@@ -970,6 +970,8 @@ static void bgmac_chip_reset(struct bgma
bgmac_miiconfig(bgmac);
bgmac_phy_init(bgmac);
@@ -359,8 +531,205 @@ patches for bgmac backported from net-next/master
bgmac->int_status = 0;
}
+@@ -1057,13 +1059,6 @@ static void bgmac_chip_init(struct bgmac
+
+ bgmac_write(bgmac, BGMAC_RXMAX_LENGTH, 32 + ETHER_MAX_LEN);
+
+- if (!bgmac->autoneg) {
+- bgmac_speed(bgmac, bgmac->speed);
+- bgmac_phy_force(bgmac);
+- } else if (bgmac->speed) { /* if there is anything to adv */
+- bgmac_phy_advertise(bgmac);
+- }
+-
+ if (full_init) {
+ bgmac_dma_init(bgmac);
+ if (1) /* FIXME: is there any case we don't want IRQs? */
+@@ -1153,6 +1148,8 @@ static int bgmac_open(struct net_device
+ }
+ napi_enable(&bgmac->napi);
+
++ phy_start(bgmac->phy_dev);
++
+ netif_carrier_on(net_dev);
+
+ err_out:
+@@ -1165,6 +1162,8 @@ static int bgmac_stop(struct net_device
+
+ netif_carrier_off(net_dev);
+
++ phy_stop(bgmac->phy_dev);
++
+ napi_disable(&bgmac->napi);
+ bgmac_chip_intrs_off(bgmac);
+ free_irq(bgmac->core->irq, net_dev);
+@@ -1243,61 +1242,16 @@ static int bgmac_get_settings(struct net
+ {
+ struct bgmac *bgmac = netdev_priv(net_dev);
+
+- cmd->supported = SUPPORTED_10baseT_Half |
+- SUPPORTED_10baseT_Full |
+- SUPPORTED_100baseT_Half |
+- SUPPORTED_100baseT_Full |
+- SUPPORTED_1000baseT_Half |
+- SUPPORTED_1000baseT_Full |
+- SUPPORTED_Autoneg;
+-
+- if (bgmac->autoneg) {
+- WARN_ON(cmd->advertising);
+- if (bgmac->full_duplex) {
+- if (bgmac->speed & BGMAC_SPEED_10)
+- cmd->advertising |= ADVERTISED_10baseT_Full;
+- if (bgmac->speed & BGMAC_SPEED_100)
+- cmd->advertising |= ADVERTISED_100baseT_Full;
+- if (bgmac->speed & BGMAC_SPEED_1000)
+- cmd->advertising |= ADVERTISED_1000baseT_Full;
+- } else {
+- if (bgmac->speed & BGMAC_SPEED_10)
+- cmd->advertising |= ADVERTISED_10baseT_Half;
+- if (bgmac->speed & BGMAC_SPEED_100)
+- cmd->advertising |= ADVERTISED_100baseT_Half;
+- if (bgmac->speed & BGMAC_SPEED_1000)
+- cmd->advertising |= ADVERTISED_1000baseT_Half;
+- }
+- } else {
+- switch (bgmac->speed) {
+- case BGMAC_SPEED_10:
+- ethtool_cmd_speed_set(cmd, SPEED_10);
+- break;
+- case BGMAC_SPEED_100:
+- ethtool_cmd_speed_set(cmd, SPEED_100);
+- break;
+- case BGMAC_SPEED_1000:
+- ethtool_cmd_speed_set(cmd, SPEED_1000);
+- break;
+- }
+- }
+-
+- cmd->duplex = bgmac->full_duplex ? DUPLEX_FULL : DUPLEX_HALF;
+-
+- cmd->autoneg = bgmac->autoneg;
+-
+- return 0;
++ return phy_ethtool_gset(bgmac->phy_dev, cmd);
+ }
+
+-#if 0
+ static int bgmac_set_settings(struct net_device *net_dev,
+ struct ethtool_cmd *cmd)
+ {
+ struct bgmac *bgmac = netdev_priv(net_dev);
+
+- return -1;
++ return phy_ethtool_sset(bgmac->phy_dev, cmd);
+ }
+-#endif
+
+ static void bgmac_get_drvinfo(struct net_device *net_dev,
+ struct ethtool_drvinfo *info)
+@@ -1308,6 +1262,7 @@ static void bgmac_get_drvinfo(struct net
+
+ static const struct ethtool_ops bgmac_ethtool_ops = {
+ .get_settings = bgmac_get_settings,
++ .set_settings = bgmac_set_settings,
+ .get_drvinfo = bgmac_get_drvinfo,
+ };
+
+@@ -1326,9 +1281,35 @@ static int bgmac_mii_write(struct mii_bu
+ return bgmac_phy_write(bus->priv, mii_id, regnum, value);
+ }
+
++static void bgmac_adjust_link(struct net_device *net_dev)
++{
++ struct bgmac *bgmac = netdev_priv(net_dev);
++ struct phy_device *phy_dev = bgmac->phy_dev;
++ bool update = false;
++
++ if (phy_dev->link) {
++ if (phy_dev->speed != bgmac->mac_speed) {
++ bgmac->mac_speed = phy_dev->speed;
++ update = true;
++ }
++
++ if (phy_dev->duplex != bgmac->mac_duplex) {
++ bgmac->mac_duplex = phy_dev->duplex;
++ update = true;
++ }
++ }
++
++ if (update) {
++ bgmac_mac_speed(bgmac);
++ phy_print_status(phy_dev);
++ }
++}
++
+ static int bgmac_mii_register(struct bgmac *bgmac)
+ {
+ struct mii_bus *mii_bus;
++ struct phy_device *phy_dev;
++ char bus_id[MII_BUS_ID_SIZE + 3];
+ int i, err = 0;
+
+ mii_bus = mdiobus_alloc();
+@@ -1360,8 +1341,22 @@ static int bgmac_mii_register(struct bgm
+
+ bgmac->mii_bus = mii_bus;
+
++ /* Connect to the PHY */
++ snprintf(bus_id, sizeof(bus_id), PHY_ID_FMT, mii_bus->id,
++ bgmac->phyaddr);
++ phy_dev = phy_connect(bgmac->net_dev, bus_id, &bgmac_adjust_link,
++ PHY_INTERFACE_MODE_MII);
++ if (IS_ERR(phy_dev)) {
++ bgmac_err(bgmac, "PHY connecton failed\n");
++ err = PTR_ERR(phy_dev);
++ goto err_unregister_bus;
++ }
++ bgmac->phy_dev = phy_dev;
++
+ return err;
+
++err_unregister_bus:
++ mdiobus_unregister(mii_bus);
+ err_free_irq:
+ kfree(mii_bus->irq);
+ err_free_bus:
+@@ -1416,9 +1411,6 @@ static int bgmac_probe(struct bcma_devic
+ bcma_set_drvdata(core, bgmac);
+
+ /* Defaults */
+- bgmac->autoneg = true;
+- bgmac->full_duplex = true;
+- bgmac->speed = BGMAC_SPEED_10 | BGMAC_SPEED_100 | BGMAC_SPEED_1000;
+ memcpy(bgmac->net_dev->dev_addr, mac, ETH_ALEN);
+
+ /* On BCM4706 we need common core to access PHY */
--- a/drivers/net/ethernet/broadcom/bgmac.h
+++ b/drivers/net/ethernet/broadcom/bgmac.h
+@@ -95,7 +95,11 @@
+ #define BGMAC_RXQ_CTL_MDP_SHIFT 24
+ #define BGMAC_GPIO_SELECT 0x194
+ #define BGMAC_GPIO_OUTPUT_EN 0x198
+-/* For 0x1e0 see BCMA_CLKCTLST */
++
++/* For 0x1e0 see BCMA_CLKCTLST. Below are BGMAC specific bits */
++#define BGMAC_BCMA_CLKCTLST_MISC_PLL_REQ 0x00000100
++#define BGMAC_BCMA_CLKCTLST_MISC_PLL_ST 0x01000000
++
+ #define BGMAC_HW_WAR 0x1e4
+ #define BGMAC_PWR_CTL 0x1e8
+ #define BGMAC_DMA_BASE0 0x200 /* Tx and Rx controller */
+@@ -342,10 +346,6 @@
+ #define BGMAC_CHIPCTL_1_SW_TYPE_RGMII 0x000000C0
+ #define BGMAC_CHIPCTL_1_RXC_DLL_BYPASS 0x00010000
+
+-#define BGMAC_SPEED_10 0x0001
+-#define BGMAC_SPEED_100 0x0002
+-#define BGMAC_SPEED_1000 0x0004
+-
+ #define BGMAC_WEIGHT 64
+
+ #define ETHER_MAX_LEN 1518
@@ -384,6 +384,8 @@ struct bgmac_dma_ring {
u16 mmio_base;
struct bgmac_dma_desc *cpu_base;
@@ -370,3 +739,25 @@ patches for bgmac backported from net-next/master
struct bgmac_slot_info slots[BGMAC_RX_RING_SLOTS];
};
+@@ -400,6 +402,7 @@ struct bgmac {
+ struct net_device *net_dev;
+ struct napi_struct napi;
+ struct mii_bus *mii_bus;
++ struct phy_device *phy_dev;
+
+ /* DMA */
+ struct bgmac_dma_ring tx_ring[BGMAC_MAX_TX_RINGS];
+@@ -414,10 +417,9 @@ struct bgmac {
+ u32 int_mask;
+ u32 int_status;
+
+- /* Speed-related */
+- int speed;
+- bool autoneg;
+- bool full_duplex;
++ /* Current MAC state */
++ int mac_speed;
++ int mac_duplex;
+
+ u8 phyaddr;
+ bool has_robosw;