Skip to contentSkip to conversation

bgmac: drop duplicated PHY defines

PATCH Superseded Rafał Miłecki 3 participants 12 messages Dec 10, 2013 – Dec 27, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 bgmac: drop duplicated PHY defines

---
 drivers/net/ethernet/broadcom/bgmac.c |    6 ++----
 drivers/net/ethernet/broadcom/bgmac.h |   21 ---------------------
 2 files changed, 2 insertions(+), 25 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +2 -4
index 0452937..ad4b2f1 100644
@@ -725,11 +725,9 @@ static void bgmac_phy_reset(struct bgmac *bgmac)
 	if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
 		return;
 
-	bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
-			BGMAC_PHY_CTL_RESET);
+	bgmac_phy_write(bgmac, bgmac->phyaddr, MII_BMCR, BMCR_RESET);
 	udelay(100);
-	if (bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) &
-	    BGMAC_PHY_CTL_RESET)
+	if (bgmac_phy_read(bgmac, bgmac->phyaddr, MII_BMCR) & BMCR_RESET)
 		bgmac_err(bgmac, "PHY reset failed\n");
 	bgmac_phy_init(bgmac);
 }
drivers/net/ethernet/broadcom/bgmac.h +0 -21
index 550f2a8..1c752ce 100644
@@ -216,27 +216,6 @@
 #define BGMAC_RX_STATUS				0xb38
 #define BGMAC_TX_STATUS				0xb3c
 
-#define BGMAC_PHY_CTL				0x00
-#define  BGMAC_PHY_CTL_SPEED_MSB		0x0040
-#define  BGMAC_PHY_CTL_DUPLEX			0x0100		/* duplex mode */
-#define  BGMAC_PHY_CTL_RESTART			0x0200		/* restart autonegotiation */
-#define  BGMAC_PHY_CTL_ANENAB			0x1000		/* enable autonegotiation */
-#define  BGMAC_PHY_CTL_SPEED			0x2000
-#define  BGMAC_PHY_CTL_LOOP			0x4000		/* loopback */
-#define  BGMAC_PHY_CTL_RESET			0x8000		/* reset */
-/* Helpers */
-#define  BGMAC_PHY_CTL_SPEED_10			0
-#define  BGMAC_PHY_CTL_SPEED_100		BGMAC_PHY_CTL_SPEED
-#define  BGMAC_PHY_CTL_SPEED_1000		BGMAC_PHY_CTL_SPEED_MSB
-#define BGMAC_PHY_ADV				0x04
-#define  BGMAC_PHY_ADV_10HALF			0x0020		/* advertise 10MBits/s half duplex */
-#define  BGMAC_PHY_ADV_10FULL			0x0040		/* advertise 10MBits/s full duplex */
-#define  BGMAC_PHY_ADV_100HALF			0x0080		/* advertise 100MBits/s half duplex */
-#define  BGMAC_PHY_ADV_100FULL			0x0100		/* advertise 100MBits/s full duplex */
-#define BGMAC_PHY_ADV2				0x09
-#define  BGMAC_PHY_ADV2_1000HALF		0x0100		/* advertise 1000MBits/s half duplex */
-#define  BGMAC_PHY_ADV2_1000FULL		0x0200		/* advertise 1000MBits/s full duplex */
-
 /* BCMA GMAC core specific IO Control (BCMA_IOCTL) flags */
 #define BGMAC_BCMA_IOCTL_SW_CLKEN		0x00000004	/* PHY Clock Enable */
 #define BGMAC_BCMA_IOCTL_SW_RESET		0x00000008	/* PHY Reset */
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 2/2 bgmac: use phy_mii_ioctl in ioctl handler

From: Hauke Mehrtens <[email protected]>

This works pretty much the same way, so avoid duplicating the code.

---
 drivers/net/ethernet/broadcom/bgmac.c |   26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +5 -21
index ad4b2f1..db71d75 100644
@@ -1187,27 +1187,11 @@ static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
 static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
 {
 	struct bgmac *bgmac = netdev_priv(net_dev);
-	struct mii_ioctl_data *data = if_mii(ifr);
-
-	switch (cmd) {
-	case SIOCGMIIPHY:
-		data->phy_id = bgmac->phyaddr;
-		/* fallthru */
-	case SIOCGMIIREG:
-		if (!netif_running(net_dev))
-			return -EAGAIN;
-		data->val_out = bgmac_phy_read(bgmac, data->phy_id,
-					       data->reg_num & 0x1f);
-		return 0;
-	case SIOCSMIIREG:
-		if (!netif_running(net_dev))
-			return -EAGAIN;
-		bgmac_phy_write(bgmac, data->phy_id, data->reg_num & 0x1f,
-				data->val_in);
-		return 0;
-	default:
-		return -EOPNOTSUPP;
-	}
+
+	if (!netif_running(net_dev))
+		return -EINVAL;
+
+	return phy_mii_ioctl(bgmac->phy_dev, ifr, cmd);
 }
 
 static const struct net_device_ops bgmac_netdev_ops = {
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [PATCH 2/2] bgmac: use phy_mii_ioctl in ioctl handler

2013/12/10 Rafał Miłecki <[email protected]>:

Quoted 6 lines

From: Hauke Mehrtens <[email protected]>

This works pretty much the same way, so avoid duplicating the code.

I forgot "git am" and "git format-patch" drop my comments. There is goest:

Quoted 6 lines

This ports part of Hauke's patch from OpenWrt.

Hauks: I've just dropped
if (!bgmac->phydev)
return -EINVAL;
as we are guaranteed to have PHY dev.

Acked-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] bgmac: use phy_mii_ioctl in ioctl handler

In reply to Rafał Miłecki

2013/12/10 Rafał Miłecki <[email protected]>:

Quoted 6 lines

From: Hauke Mehrtens <[email protected]>

This works pretty much the same way, so avoid duplicating the code.

Quoted 48 lines
---
 drivers/net/ethernet/broadcom/bgmac.c |   26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +5 -22
index ad4b2f1..db71d75 100644
@@ -1187,27 +1187,11 @@ static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
 static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
 {
        struct bgmac *bgmac = netdev_priv(net_dev);
-       struct mii_ioctl_data *data = if_mii(ifr);
-
-       switch (cmd) {
-       case SIOCGMIIPHY:
-               data->phy_id = bgmac->phyaddr;
-               /* fallthru */
-       case SIOCGMIIREG:
-               if (!netif_running(net_dev))
-                       return -EAGAIN;
-               data->val_out = bgmac_phy_read(bgmac, data->phy_id,
-                                              data->reg_num & 0x1f);
-               return 0;
-       case SIOCSMIIREG:
-               if (!netif_running(net_dev))
-                       return -EAGAIN;
-               bgmac_phy_write(bgmac, data->phy_id, data->reg_num & 0x1f,
-                               data->val_in);
-               return 0;
-       default:
-               return -EOPNOTSUPP;
-       }
+
+       if (!netif_running(net_dev))
+               return -EINVAL;
+
+       return phy_mii_ioctl(bgmac->phy_dev, ifr, cmd);
 }
 
 static const struct net_device_ops bgmac_netdev_ops = {
--

1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Florian
#4 lore raw

PATCH RESEND 2/2 bgmac: use phy_mii_ioctl in ioctl handler

In reply to Rafał Miłecki

From: Hauke Mehrtens <[email protected]>

This works pretty much the same way, so avoid duplicating the code.

---
This ports part of Hauke's patch from OpenWrt.

Hauks: I've just dropped
if (!bgmac->phydev)

	return -EINVAL;
as we are guaranteed to have PHY dev.
---
 drivers/net/ethernet/broadcom/bgmac.c |   26 +++++---------------------
 1 file changed, 5 insertions(+), 21 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +5 -21
index 3cd5d68..39efb86 100644
@@ -1198,27 +1198,11 @@ static int bgmac_set_mac_address(struct net_device *net_dev, void *addr)
 static int bgmac_ioctl(struct net_device *net_dev, struct ifreq *ifr, int cmd)
 {
 	struct bgmac *bgmac = netdev_priv(net_dev);
-	struct mii_ioctl_data *data = if_mii(ifr);
-
-	switch (cmd) {
-	case SIOCGMIIPHY:
-		data->phy_id = bgmac->phyaddr;
-		/* fallthru */
-	case SIOCGMIIREG:
-		if (!netif_running(net_dev))
-			return -EAGAIN;
-		data->val_out = bgmac_phy_read(bgmac, data->phy_id,
-					       data->reg_num & 0x1f);
-		return 0;
-	case SIOCSMIIREG:
-		if (!netif_running(net_dev))
-			return -EAGAIN;
-		bgmac_phy_write(bgmac, data->phy_id, data->reg_num & 0x1f,
-				data->val_in);
-		return 0;
-	default:
-		return -EOPNOTSUPP;
-	}
+
+	if (!netif_running(net_dev))
+		return -EINVAL;
+
+	return phy_mii_ioctl(bgmac->phy_dev, ifr, cmd);
 }
 
 static const struct net_device_ops bgmac_netdev_ops = {
Signature · 1 line
1.7.10.4
#6 lore raw
In reply to Rafał Miłecki

Hello Rafal

2013/12/10 Rafał Miłecki <[email protected]>:

Quoted 13 lines
---
 drivers/net/ethernet/broadcom/bgmac.c |    6 ++----
 drivers/net/ethernet/broadcom/bgmac.h |   21 ---------------------
 2 files changed, 2 insertions(+), 25 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +0 -0
index 0452937..ad4b2f1 100644
@@ -725,11 +725,9 @@ static void bgmac_phy_reset(struct bgmac *bgmac)
        if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
                return;

drivers/net/ethernet/broadcom/bgmac.c static void bgmac_phy_reset(struct bgmac *bgmac) · line 732

Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +2 -4
 
-       bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
-                       BGMAC_PHY_CTL_RESET);
+       bgmac_phy_write(bgmac, bgmac->phyaddr, MII_BMCR, BMCR_RESET);
        udelay(100);
-       if (bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) &
-           BGMAC_PHY_CTL_RESET)
+       if (bgmac_phy_read(bgmac, bgmac->phyaddr, MII_BMCR) & BMCR_RESET)
                bgmac_err(bgmac, "PHY reset failed\n");
        bgmac_phy_init(bgmac);

phy_init_hw() now issues a PHY reset through BMCR_RESET, you might want to use it instead of this here:

- the 100 microseconds delay might not be sufficient for all PHYs out there
- any PHY fixup (although there are none for BCM47xx yet) would be wiped out by this "wild" PHY reset

This is quite new, so I do not expect you knew about this. --
Florian

#7 lore raw

2013/12/10 Florian Fainelli <[email protected]>:

Quoted 30 lines

Hello Rafal

2013/12/10 Rafał Miłecki <[email protected]>:

Quoted 13 lines
---
 drivers/net/ethernet/broadcom/bgmac.c |    6 ++----
 drivers/net/ethernet/broadcom/bgmac.h |   21 ---------------------
 2 files changed, 2 insertions(+), 25 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +0 -0
index 0452937..ad4b2f1 100644
@@ -725,11 +725,9 @@ static void bgmac_phy_reset(struct bgmac *bgmac)
        if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
                return;

drivers/net/ethernet/broadcom/bgmac.c static void bgmac_phy_reset(struct bgmac *bgmac) · line 732

Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +2 -4
 
-       bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
-                       BGMAC_PHY_CTL_RESET);
+       bgmac_phy_write(bgmac, bgmac->phyaddr, MII_BMCR, BMCR_RESET);
        udelay(100);
-       if (bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) &
-           BGMAC_PHY_CTL_RESET)
+       if (bgmac_phy_read(bgmac, bgmac->phyaddr, MII_BMCR) & BMCR_RESET)
                bgmac_err(bgmac, "PHY reset failed\n");
        bgmac_phy_init(bgmac);

phy_init_hw() now issues a PHY reset through BMCR_RESET, you might want to use it instead of this here:

Quoted 5 lines

- the 100 microseconds delay might not be sufficient for all PHYs out there
- any PHY fixup (although there are none for BCM47xx yet) would be wiped out by this "wild" PHY reset

This is quite new, so I do not expect you knew about this.

Thanks for pointing that! I was looking for BMCR_RESET usages with:
http://lxr.free-electrons.com/ident?v=3.12;i=BMCR_RESET
but it didn't find any interesting (because it uses 3.12 kernel sources).

This udelay is from specs based on Broadcom's code. What you have in phy_poll_reset sounds indeed much more sane.

If you take a look at bgmac_phy_init, it actually has kind of fixups. They are just programmed per-Broadcom chip id and not per PHY id as you normally do that with phy_register_fixup_for_uid. But I think we should be able to workaround that.

So I fully agree we should use phy_init_hw, but I think we should implement that in a separated patch and on top of PHY cleanups I recently did. Just to simplify bisecting potential regressions.

Are you OK with applying this patch as-is and working on another one cleaning PHY reset/init in a nicer way?

Signature · 1 line
Rafał
#8 lore raw

2013/12/10 Rafał Miłecki <[email protected]>:

Quoted 44 lines

2013/12/10 Florian Fainelli <[email protected]>:

Quoted 30 lines

Hello Rafal

2013/12/10 Rafał Miłecki <[email protected]>:

Quoted 13 lines
---
 drivers/net/ethernet/broadcom/bgmac.c |    6 ++----
 drivers/net/ethernet/broadcom/bgmac.h |   21 ---------------------
 2 files changed, 2 insertions(+), 25 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +0 -0
index 0452937..ad4b2f1 100644
@@ -725,11 +725,9 @@ static void bgmac_phy_reset(struct bgmac *bgmac)
        if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
                return;

drivers/net/ethernet/broadcom/bgmac.c static void bgmac_phy_reset(struct bgmac *bgmac) · line 732

Quoted 10 lines
drivers/net/ethernet/broadcom/bgmac.c +2 -4
 
-       bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
-                       BGMAC_PHY_CTL_RESET);
+       bgmac_phy_write(bgmac, bgmac->phyaddr, MII_BMCR, BMCR_RESET);
        udelay(100);
-       if (bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) &
-           BGMAC_PHY_CTL_RESET)
+       if (bgmac_phy_read(bgmac, bgmac->phyaddr, MII_BMCR) & BMCR_RESET)
                bgmac_err(bgmac, "PHY reset failed\n");
        bgmac_phy_init(bgmac);

phy_init_hw() now issues a PHY reset through BMCR_RESET, you might want to use it instead of this here:

Quoted 5 lines

- the 100 microseconds delay might not be sufficient for all PHYs out there
- any PHY fixup (although there are none for BCM47xx yet) would be wiped out by this "wild" PHY reset

This is quite new, so I do not expect you knew about this.

Thanks for pointing that! I was looking for BMCR_RESET usages with:
http://lxr.free-electrons.com/ident?v=3.12;i=BMCR_RESET
but it didn't find any interesting (because it uses 3.12 kernel sources).

This udelay is from specs based on Broadcom's code. What you have in phy_poll_reset sounds indeed much more sane.

Quoted 8 lines

If you take a look at bgmac_phy_init, it actually has kind of fixups. They are just programmed per-Broadcom chip id and not per PHY id as you normally do that with phy_register_fixup_for_uid. But I think we should be able to workaround that.

So I fully agree we should use phy_init_hw, but I think we should implement that in a separated patch and on top of PHY cleanups I recently did. Just to simplify bisecting potential regressions.

Sounds good!

Quoted 3 lines

Are you OK with applying this patch as-is and working on another one cleaning PHY reset/init in a nicer way?

Oh yes, this patch just made me look at the code, but your cleanups are good. Thanks!

Signature · 1 line
Florian
#10 lore raw

PATCH RESEND 1/2 bgmac: drop duplicated PHY defines

In reply to Rafał Miłecki

---
In future we should try to remove bgmac_phy_reset and use phy_init_hw. However this requires rewriting our fixups first.

Dave: I suspect you may lost this patchset, thus resending. If they are just waiting in your queue for the right moment, sorry, I didn't mean to rush you!

---
 drivers/net/ethernet/broadcom/bgmac.c |    6 ++----
 drivers/net/ethernet/broadcom/bgmac.h |   21 ---------------------
 2 files changed, 2 insertions(+), 25 deletions(-)
drivers/net/ethernet/broadcom/bgmac.c +2 -4
index b665a6a..3cd5d68 100644
@@ -725,11 +725,9 @@ static void bgmac_phy_reset(struct bgmac *bgmac)
 	if (bgmac->phyaddr == BGMAC_PHY_NOREGS)
 		return;
 
-	bgmac_phy_write(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL,
-			BGMAC_PHY_CTL_RESET);
+	bgmac_phy_write(bgmac, bgmac->phyaddr, MII_BMCR, BMCR_RESET);
 	udelay(100);
-	if (bgmac_phy_read(bgmac, bgmac->phyaddr, BGMAC_PHY_CTL) &
-	    BGMAC_PHY_CTL_RESET)
+	if (bgmac_phy_read(bgmac, bgmac->phyaddr, MII_BMCR) & BMCR_RESET)
 		bgmac_err(bgmac, "PHY reset failed\n");
 	bgmac_phy_init(bgmac);
 }
drivers/net/ethernet/broadcom/bgmac.h +0 -21
index 2d44119..130b16b 100644
@@ -220,27 +220,6 @@
 #define BGMAC_RX_STATUS				0xb38
 #define BGMAC_TX_STATUS				0xb3c
 
-#define BGMAC_PHY_CTL				0x00
-#define  BGMAC_PHY_CTL_SPEED_MSB		0x0040
-#define  BGMAC_PHY_CTL_DUPLEX			0x0100		/* duplex mode */
-#define  BGMAC_PHY_CTL_RESTART			0x0200		/* restart autonegotiation */
-#define  BGMAC_PHY_CTL_ANENAB			0x1000		/* enable autonegotiation */
-#define  BGMAC_PHY_CTL_SPEED			0x2000
-#define  BGMAC_PHY_CTL_LOOP			0x4000		/* loopback */
-#define  BGMAC_PHY_CTL_RESET			0x8000		/* reset */
-/* Helpers */
-#define  BGMAC_PHY_CTL_SPEED_10			0
-#define  BGMAC_PHY_CTL_SPEED_100		BGMAC_PHY_CTL_SPEED
-#define  BGMAC_PHY_CTL_SPEED_1000		BGMAC_PHY_CTL_SPEED_MSB
-#define BGMAC_PHY_ADV				0x04
-#define  BGMAC_PHY_ADV_10HALF			0x0020		/* advertise 10MBits/s half duplex */
-#define  BGMAC_PHY_ADV_10FULL			0x0040		/* advertise 10MBits/s full duplex */
-#define  BGMAC_PHY_ADV_100HALF			0x0080		/* advertise 100MBits/s half duplex */
-#define  BGMAC_PHY_ADV_100FULL			0x0100		/* advertise 100MBits/s full duplex */
-#define BGMAC_PHY_ADV2				0x09
-#define  BGMAC_PHY_ADV2_1000HALF		0x0100		/* advertise 1000MBits/s half duplex */
-#define  BGMAC_PHY_ADV2_1000FULL		0x0200		/* advertise 1000MBits/s full duplex */
-
 /* BCMA GMAC core specific IO Control (BCMA_IOCTL) flags */
 #define BGMAC_BCMA_IOCTL_SW_CLKEN		0x00000004	/* PHY Clock Enable */
 #define BGMAC_BCMA_IOCTL_SW_RESET		0x00000008	/* PHY Reset */
Signature · 1 line
1.7.10.4