Netdev List
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Woojung.Huh@microchip.com, davem@davemloft.net
Cc: andrew@lunn.ch, netdev@vger.kernel.org, UNGLinuxDriver@microchip.com
Subject: Re: [PATCH] lan78xx: relocate mdix setting to phy driver
Date: Tue, 15 Nov 2016 15:47:25 -0800	[thread overview]
Message-ID: <c894a7bd-4062-cb63-6b70-02bb86c874c1@gmail.com> (raw)
In-Reply-To: <9235D6609DB808459E95D78E17F2E43D40965635@CHN-SV-EXMX02.mchp-main.com>

On 11/15/2016 01:57 PM, Woojung.Huh@microchip.com wrote:
> From: Woojung Huh <woojung.huh@microchip.com>
> 
> Relocate mdix code to phy driver to be called at config_init().
> 
> Signed-off-by: Woojung Huh <woojung.huh@microchip.com>
> ---
>  drivers/net/phy/microchip.c | 43 +++++++++++++++++++++++++-
>  drivers/net/usb/lan78xx.c   | 73 ++-------------------------------------------
>  2 files changed, 45 insertions(+), 71 deletions(-)
> 
> diff --git a/drivers/net/phy/microchip.c b/drivers/net/phy/microchip.c
> index 7c00e50..13553df 100644
> --- a/drivers/net/phy/microchip.c
> +++ b/drivers/net/phy/microchip.c
> @@ -106,6 +106,47 @@ static int lan88xx_set_wol(struct phy_device *phydev,
>  	return 0;
>  }
>  
> +static void lan88xx_set_mdix(struct phy_device *phydev)
> +{
> +	int buf;
> +
> +	if (phydev->mdix == ETH_TP_MDI) {
> +		phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
> +			  LAN88XX_EXT_PAGE_SPACE_1);

Should you take this write out of the if/else

> +		buf = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);

And this one too

> +		buf &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
> +		phy_write(phydev, LAN88XX_EXT_MODE_CTRL,
> +			  buf | LAN88XX_EXT_MODE_CTRL_MDI_);
> +		phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
> +			  LAN88XX_EXT_PAGE_SPACE_0);

And this one too as well

> +	} else if (phydev->mdix == ETH_TP_MDI_X) {

switch/case statement would be more appropriate and it would be easier
to add support for future possible modes.

And once you take the write/read/write out of the switch case, it's just
a matter of translating phydev->mdix into the appropriate mask value to
write.

So essentially, this comes down to:

static void lan88xx_set_mdix(struct phy_device *phydev)
{
	int buf;
	int mask_val;

	switch (phydev->mdix) {
	case ETH_TP_MDI:
		mask_val = LAN88XX_EXT_MODE_CTRL_MDI_;
		break;
	case ETH_TP_MDI_X:
		mask_val = LAN88XX_EXT_MODE_CTRL_MDI_X_;
		break;
	case ETH_TP_MDI_AUTO:
		mask_val = LAN88XX_EXT_MODE_CTRL_AUTO_MDIX_:
		break:
	default:
		return;
	}

	phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
		  LAN88XX_EXT_PAGE_SPACE_1);
	buf = phy_read(phydev, LAN88XX_EXT_MODE_CTRL);
	buf &= ~LAN88XX_EXT_MODE_CTRL_MDIX_MASK_;
	buf |= mask_val;
	phy_write(phydev, LAN88XX_EXT_MODE_CTRL, buf);
	phy_write(phydev, LAN88XX_EXT_PAGE_ACCESS,
		  LAN88XX_EXT_PAGE_SPACE_0);
}

I leave it up to you whether you need to do this now, or as a subsequent
clean up patch.
-- 
Florian

  reply	other threads:[~2016-11-15 23:47 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-15 21:57 [PATCH] lan78xx: relocate mdix setting to phy driver Woojung.Huh
2016-11-15 23:47 ` Florian Fainelli [this message]
2016-11-16 15:31   ` Woojung.Huh

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=c894a7bd-4062-cb63-6b70-02bb86c874c1@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=Woojung.Huh@microchip.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox