All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Marek Vasut <marex@denx.de>
Cc: linux-usb@vger.kernel.org,
	"David S . Miller" <davem@davemloft.net>,
	Nisar Sayed <Nisar.Sayed@microchip.com>,
	Woojung Huh <Woojung.Huh@microchip.com>,
	netdev <netdev@vger.kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: smsc95xx: Add support for automated PHY address detection
Date: Sun, 23 Dec 2018 11:56:43 +0100	[thread overview]
Message-ID: <20181223105643.GF32178@lunn.ch> (raw)

On Sun, Dec 23, 2018 at 11:43:05AM +0100, Marek Vasut wrote:
> On 12/23/18 11:23 AM, Andrew Lunn wrote:
> >>> +static int smsc95xx_phy_address(struct usbnet *dev)
> >>> +{
> >>> +	u32 read_buf;
> >>> +	int ret, id1, id2, phyad;
> >>> +
> >>> +	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
> >>> +	if (ret < 0)
> >>> +		return ret;
> >>> +
> >>> +	/* Check if using external PHY, if not, use internal PHY address */
> >>> +	if (!(read_buf & HW_CFG_PSEL_))
> >>> +		return SMSC95XX_INTERNAL_PHY_ID;
> >>> +
> >>> +	/*
> >>> +	 * Detect external PHY address. Here we probe the MDIO bus from
> >>> +	 * the highest address, since some PHYs respond also on address
> >>> +	 * zero, which they consider MDIO broadcast address. We really
> >>> +	 * want to get their proper address instead though, so we scan
> >>> +	 * address zero last.
> >>> +	 */
> >>> +	for (phyad = 0x1f; phyad >= 0; phyad--) {
> >>> +		id1 = smsc95xx_mdio_read(dev->net, phyad, MII_PHYSID1);
> >>> +		id2 = smsc95xx_mdio_read(dev->net, phyad, MII_PHYSID2);
> >>> +		/* Check for valid response from the PHY */
> >>> +		if (id1 > 0 && id2 > 0 && id1 != 0x7fff && id2 != 0xffff)
> >>> +			return phyad;
> >>> +	}
> > 
> > This would be so much easier if the driver used the core mdio/phy
> > code. Just set mdio->phy_mask to ~BIT(0) and then use
> > phy_find_first().
> 
> That's in the pipeline, along with PM cleanups, but low prio.

Great. Does using the broadcast address actually cause a problem?  If
not, i would say lets drop this part of the patch until you do the
cleanup.

     Andrew

WARNING: multiple messages have this Message-ID (diff)
From: Andrew Lunn <andrew@lunn.ch>
To: Marek Vasut <marex@denx.de>
Cc: linux-usb@vger.kernel.org,
	"David S . Miller" <davem@davemloft.net>,
	Nisar Sayed <Nisar.Sayed@microchip.com>,
	Woojung Huh <Woojung.Huh@microchip.com>,
	netdev <netdev@vger.kernel.org>,
	Florian Fainelli <f.fainelli@gmail.com>
Subject: Re: [PATCH] smsc95xx: Add support for automated PHY address detection
Date: Sun, 23 Dec 2018 11:56:43 +0100	[thread overview]
Message-ID: <20181223105643.GF32178@lunn.ch> (raw)
In-Reply-To: <184170a4-3827-5609-ce77-66a49fd56aa1@denx.de>

On Sun, Dec 23, 2018 at 11:43:05AM +0100, Marek Vasut wrote:
> On 12/23/18 11:23 AM, Andrew Lunn wrote:
> >>> +static int smsc95xx_phy_address(struct usbnet *dev)
> >>> +{
> >>> +	u32 read_buf;
> >>> +	int ret, id1, id2, phyad;
> >>> +
> >>> +	ret = smsc95xx_read_reg(dev, HW_CFG, &read_buf);
> >>> +	if (ret < 0)
> >>> +		return ret;
> >>> +
> >>> +	/* Check if using external PHY, if not, use internal PHY address */
> >>> +	if (!(read_buf & HW_CFG_PSEL_))
> >>> +		return SMSC95XX_INTERNAL_PHY_ID;
> >>> +
> >>> +	/*
> >>> +	 * Detect external PHY address. Here we probe the MDIO bus from
> >>> +	 * the highest address, since some PHYs respond also on address
> >>> +	 * zero, which they consider MDIO broadcast address. We really
> >>> +	 * want to get their proper address instead though, so we scan
> >>> +	 * address zero last.
> >>> +	 */
> >>> +	for (phyad = 0x1f; phyad >= 0; phyad--) {
> >>> +		id1 = smsc95xx_mdio_read(dev->net, phyad, MII_PHYSID1);
> >>> +		id2 = smsc95xx_mdio_read(dev->net, phyad, MII_PHYSID2);
> >>> +		/* Check for valid response from the PHY */
> >>> +		if (id1 > 0 && id2 > 0 && id1 != 0x7fff && id2 != 0xffff)
> >>> +			return phyad;
> >>> +	}
> > 
> > This would be so much easier if the driver used the core mdio/phy
> > code. Just set mdio->phy_mask to ~BIT(0) and then use
> > phy_find_first().
> 
> That's in the pipeline, along with PM cleanups, but low prio.

Great. Does using the broadcast address actually cause a problem?  If
not, i would say lets drop this part of the patch until you do the
cleanup.

     Andrew

             reply	other threads:[~2018-12-23 10:56 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-23 10:56 Andrew Lunn [this message]
2018-12-23 10:56 ` [PATCH] smsc95xx: Add support for automated PHY address detection Andrew Lunn
  -- strict thread matches above, loose matches on Subject: below --
2018-12-23 10:59 Marek Vasut
2018-12-23 10:59 ` [PATCH] " Marek Vasut
2018-12-23 10:43 Marek Vasut
2018-12-23 10:43 ` [PATCH] " Marek Vasut
2018-12-23 10:23 Andrew Lunn
2018-12-23 10:23 ` [PATCH] " Andrew Lunn
2018-12-23  9:30 Marek Vasut
2018-12-23  9:30 ` [PATCH] " Marek Vasut
2018-09-11 10:12 Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181223105643.GF32178@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=Nisar.Sayed@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=davem@davemloft.net \
    --cc=f.fainelli@gmail.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.