All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: Re: [PATCH v2] net: phy: Add driver for Motorcomm yt8521 gigabit
@ 2022-06-29 12:48 Frank
  2022-06-29 12:56 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Frank @ 2022-06-29 12:48 UTC (permalink / raw)
  To: Peter Geis, Andrew Lunn, Heiner Kallweit, Russell King,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: yinghong.zhang, fei.zhang, hua.sun, netdev, linux-kernel, Frank

Hi Andrew,
	Thanks for your comments.
	This driver is for an utp-fiber combo phy and sometimes, it has to
switch register spaces between utp and fiber for same operation. That is why it
looks that there are duplicated operations. 

> > + * yt8521_soft_reset() - called to issue a PHY software reset
> > + * @phydev: a pointer to a &struct phy_device
> > + *
> > + * returns 0 or negative errno code
> > + */
> > +int yt8521_soft_reset(struct phy_device *phydev)
> > +{
> > + int old_page;
> > + int ret = 0;
> > +
> > + old_page = phy_save_page(phydev);
> > + if (old_page < 0)
> > +  goto err_restore_page;
> > +
> > + ret = yt8521_modify_UTP_FIBER_BMCR(phydev, 0, BMCR_RESET);
> > + if (ret < 0)
> > +  goto err_restore_page;
> 
> You should wait for the reset to completed. Can you actually use the
> core helper? Is the BMCR in the usual place? So long as you hold the
> lock, nothing is going to change the page, so you should be able to
> use the helper.
> 

yes, you said it. we will add codes to check if the reset is completed at all.

> 
> > +int yt8521_config_aneg(struct phy_device *phydev)
> > +{
> > + struct yt8521_priv *priv = phydev->priv;
> > + u8 polling_mode = priv->polling_mode;
> > + int old_page;
> > + int ret;
> > +
> > + old_page = yt8521_read_page_with_lock(phydev);
> > + if (old_page)
> > +  return old_page;
> > +
> > + if (polling_mode == YT8521_MODE_FIBER ||
> > +     polling_mode == YT8521_MODE_POLL) {
> > +  ret = yt8521_write_page_with_lock(phydev,
> > +        YT8521_RSSR_FIBER_SPACE);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > +
> > +  ret = genphy_config_aneg(phydev);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > + }
> > +
> > + if (polling_mode == YT8521_MODE_UTP ||
> > +     polling_mode == YT8521_MODE_POLL) {
> > +  ret = yt8521_write_page_with_lock(phydev,
> > +        YT8521_RSSR_UTP_SPACE);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > +
> > +  ret = genphy_config_aneg(phydev);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > + }
> 
> Looks like this could be refactored to reduce duplication.
> 

sure, as the reason said above, the same operation is required in both utp and
fiber spaces.

> 
> > +int yt8521_aneg_done(struct phy_device *phydev)
> > +{
> > + struct yt8521_priv *priv = phydev->priv;
> > + u8 polling_mode = priv->polling_mode;
> > + int link_fiber = 0;
> > + int link_utp = 0;
> > + int old_page;
> > + int ret = 0;
> > +
> > + old_page = phy_save_page(phydev);
> > + if (old_page < 0)
> > +  goto err_restore_page;
> > +
> > + if (polling_mode == YT8521_MODE_FIBER ||
> > +     polling_mode == YT8521_MODE_POLL) {
> > +  /* switch to FIBER reg space*/
> > +  ret = yt8521_write_page(phydev, YT8521_RSSR_FIBER_SPACE);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > +
> > +  ret = __phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > +
> > +  link_fiber = !!(ret & YTPHY_SSR_LINK);
> > + }
> > +
> > + if (polling_mode == YT8521_MODE_UTP ||
> > +     polling_mode == YT8521_MODE_POLL) {
> > +  /* switch to UTP reg space */
> > +  ret = yt8521_write_page(phydev, YT8521_RSSR_UTP_SPACE);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > +
> > +  ret = __phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG);
> > +  if (ret < 0)
> > +   goto err_restore_page;
> > +
> > +  link_utp = !!(ret & YTPHY_SSR_LINK);
> > + }
> > +
> > + ret = !!(link_fiber | link_utp);
> 
> Does this mean it can do both copper and fibre at the same time. And
> whichever gives up first wins?

Sure, the phy supports utp, fiber, and both. In the case of both, this driver
supposes that fiber is of priority.

Thaks again and we will chnaged codes based on your comments.

Cheers and BR,
Frank

-- 
2.31.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [PATCH v2] net: phy: Add driver for Motorcomm yt8521 gigabit
  2022-06-29 12:48 Re: [PATCH v2] net: phy: Add driver for Motorcomm yt8521 gigabit Frank
@ 2022-06-29 12:56 ` Andrew Lunn
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Lunn @ 2022-06-29 12:56 UTC (permalink / raw)
  To: Frank
  Cc: Peter Geis, Heiner Kallweit, Russell King, David S . Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, yinghong.zhang,
	fei.zhang, hua.sun, netdev, linux-kernel

> > > +int yt8521_config_aneg(struct phy_device *phydev)
> > > +{
> > > + struct yt8521_priv *priv = phydev->priv;
> > > + u8 polling_mode = priv->polling_mode;
> > > + int old_page;
> > > + int ret;
> > > +
> > > + old_page = yt8521_read_page_with_lock(phydev);
> > > + if (old_page)
> > > +  return old_page;
> > > +
> > > + if (polling_mode == YT8521_MODE_FIBER ||
> > > +     polling_mode == YT8521_MODE_POLL) {
> > > +  ret = yt8521_write_page_with_lock(phydev,
> > > +        YT8521_RSSR_FIBER_SPACE);
> > > +  if (ret < 0)
> > > +   goto err_restore_page;
> > > +
> > > +  ret = genphy_config_aneg(phydev);
> > > +  if (ret < 0)
> > > +   goto err_restore_page;
> > > + }
> > > +
> > > + if (polling_mode == YT8521_MODE_UTP ||
> > > +     polling_mode == YT8521_MODE_POLL) {
> > > +  ret = yt8521_write_page_with_lock(phydev,
> > > +        YT8521_RSSR_UTP_SPACE);
> > > +  if (ret < 0)
> > > +   goto err_restore_page;
> > > +
> > > +  ret = genphy_config_aneg(phydev);
> > > +  if (ret < 0)
> > > +   goto err_restore_page;
> > > + }
> > 
> > Looks like this could be refactored to reduce duplication.
> > 
> 
> sure, as the reason said above, the same operation is required in both utp and
> fiber spaces.

So you can probably pull the 'core' of this function out into a
helper, and then call it either with YT8521_RSSR_UTP_SPACE or
YT8521_RSSR_FIBER_SPACE.

> > > + ret = !!(link_fiber | link_utp);
> > 
> > Does this mean it can do both copper and fibre at the same time. And
> > whichever gives up first wins?
> 
> Sure, the phy supports utp, fiber, and both. In the case of both, this driver
> supposes that fiber is of priority.

It is generally not that simple. Fibre, you probably want 1000BaseX,
unless the fibre module is actually copper, and then you want
SGMII. So you need something to talk to the fibre module and ask it
what it is. That something is phylink. Phylink does not support both
copper and fibre at the same time for one MAC.

       Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Re: [PATCH v2] net: phy: Add driver for Motorcomm yt8521 gigabit
@ 2022-06-29 13:30 Frank
  0 siblings, 0 replies; 3+ messages in thread
From: Frank @ 2022-06-29 13:30 UTC (permalink / raw)
  To: Peter Geis, Andrew Lunn, Heiner Kallweit, Russell King,
	David S . Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: yinghong.zhang, fei.zhang, hua.sun, netdev, linux-kernel, Frank

The poll mode of yt8521 phy is not support utp and fiber at same time, In other
words, only utp or fiber can be connected at one time, and you can change to
fiber or utp at next time. so in poll mode need to do both ( utp and fiber )
operation

> > > > +int yt8521_config_aneg(struct phy_device *phydev)
> > > > +{
> > > > + struct yt8521_priv *priv = phydev->priv;
> > > > + u8 polling_mode = priv->polling_mode;
> > > > + int old_page;
> > > > + int ret;
> > > > +
> > > > + old_page = yt8521_read_page_with_lock(phydev);
> > > > + if (old_page)
> > > > +  return old_page;
> > > > +
> > > > + if (polling_mode == YT8521_MODE_FIBER ||
> > > > +     polling_mode == YT8521_MODE_POLL) {
> > > > +  ret = yt8521_write_page_with_lock(phydev,
> > > > +        YT8521_RSSR_FIBER_SPACE);
> > > > +  if (ret < 0)
> > > > +   goto err_restore_page;
> > > > +
> > > > +  ret = genphy_config_aneg(phydev);
> > > > +  if (ret < 0)
> > > > +   goto err_restore_page;
> > > > + }
> > > > +
> > > > + if (polling_mode == YT8521_MODE_UTP ||
> > > > +     polling_mode == YT8521_MODE_POLL) {
> > > > +  ret = yt8521_write_page_with_lock(phydev,
> > > > +        YT8521_RSSR_UTP_SPACE);
> > > > +  if (ret < 0)
> > > > +   goto err_restore_page;
> > > > +
> > > > +  ret = genphy_config_aneg(phydev);
> > > > +  if (ret < 0)
> > > > +   goto err_restore_page;
> > > > + }
> > >
> > > Looks like this could be refactored to reduce duplication.
> > >
> >
> > sure, as the reason said above, the same operation is required in both utp and
> > fiber spaces.
> 
> So you can probably pull the 'core' of this function out into a
> helper, and then call it either with YT8521_RSSR_UTP_SPACE or
> YT8521_RSSR_FIBER_SPACE.
> 
> > > > + ret = !!(link_fiber | link_utp);
> > >
> > > Does this mean it can do both copper and fibre at the same time. And
> > > whichever gives up first wins?
> >
> > Sure, the phy supports utp, fiber, and both. In the case of both, this driver
> > supposes that fiber is of priority.
> 
> It is generally not that simple. Fibre, you probably want 1000BaseX,
> unless the fibre module is actually copper, and then you want
> SGMII. So you need something to talk to the fibre module and ask it
> what it is. That something is phylink. Phylink does not support both
> copper and fibre at the same time for one MAC.

Cheers and BR,
Frank

-- 
2.31.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-06-29 13:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 12:48 Re: [PATCH v2] net: phy: Add driver for Motorcomm yt8521 gigabit Frank
2022-06-29 12:56 ` Andrew Lunn
2022-06-29 13:30 Frank

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.