mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Lunn <andrew@lunn.ch>
To: Prabhakar <prabhakar.csengg@gmail.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Horatiu Vultur <horatiu.vultur@microchip.com>,
	Geert Uytterhoeven <geert+renesas@glider.be>,
	Vladimir Oltean <vladimir.oltean@nxp.com>,
	Vadim Fedorenko <vadim.fedorenko@linux.dev>,
	Maxime Chevallier <maxime.chevallier@bootlin.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-renesas-soc@vger.kernel.org,
	Biju Das <biju.das.jz@bp.renesas.com>,
	Fabrizio Castro <fabrizio.castro.jz@renesas.com>,
	Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Subject: Re: [PATCH net-next] net: phy: mscc: Add support for PHY LEDs on VSC8541
Date: Thu, 6 Nov 2025 21:45:26 +0100	[thread overview]
Message-ID: <ee6a79ae-4857-44e4-b8e9-29cdd80d828f@lunn.ch> (raw)
In-Reply-To: <20251106200309.1096131-1-prabhakar.mahadev-lad.rj@bp.renesas.com>

> +static int vsc85xx_led_cntl_set_lock_unlock(struct phy_device *phydev,
> +					    u8 led_num,
> +					    u8 mode, bool lock)
>  {
>  	int rc;
>  	u16 reg_val;
>  
> -	mutex_lock(&phydev->lock);
> +	if (lock)
> +		mutex_lock(&phydev->lock);
>  	reg_val = phy_read(phydev, MSCC_PHY_LED_MODE_SEL);
>  	reg_val &= ~LED_MODE_SEL_MASK(led_num);
>  	reg_val |= LED_MODE_SEL(led_num, (u16)mode);
>  	rc = phy_write(phydev, MSCC_PHY_LED_MODE_SEL, reg_val);
> -	mutex_unlock(&phydev->lock);
> +	if (lock)
> +		mutex_unlock(&phydev->lock);
>  
>  	return rc;
>  }

The normal way to do this is have _vsc85xx_led_cntl_set() manipulate
the hardware, no locking. And have vsc85xx_led_cntl_set() take the
lock, call _vsc85xx_led_cntl_set(), and then release the lock. You can
then call _vsc85xx_led_cntl_set() if needed.

> +static int vsc8541_led_combine_disable_set(struct phy_device *phydev, u8 led_num,
> +					   bool combine_disable)
> +{
> +	u16 reg_val;
> +
> +	reg_val = phy_read(phydev, MSCC_PHY_LED_BEHAVIOR);

phy_read() can return a negative value. You should not assign that to
a u16.

Also, BEHAVIOUR.

> +	reg_val &= ~LED_COMBINE_DIS_MASK(led_num);
> +	reg_val |= LED_COMBINE_DIS(led_num, combine_disable);
> +
> +	return phy_write(phydev, MSCC_PHY_LED_BEHAVIOR, reg_val);

You can probably use phy_modify() here.

> +static int vsc8541_led_hw_is_supported(struct phy_device *phydev, u8 index,
> +				       unsigned long rules)
> +{
> +	struct vsc8531_private *vsc8531 = phydev->priv;
> +	static const unsigned long supported = BIT(TRIGGER_NETDEV_LINK) |
> +					       BIT(TRIGGER_NETDEV_LINK_1000) |
> +					       BIT(TRIGGER_NETDEV_LINK_100) |
> +					       BIT(TRIGGER_NETDEV_LINK_10) |
> +					       BIT(TRIGGER_NETDEV_RX) |
> +					       BIT(TRIGGER_NETDEV_TX);
> +

Reverse Christmas tree. The lines should be sorted, longest first,
shortest last.

> +static int vsc8541_led_hw_control_get(struct phy_device *phydev, u8 index,
> +				      unsigned long *rules)
> +{
> +	struct vsc8531_private *vsc8531 = phydev->priv;
> +	u16 reg;
> +
> +	if (index >= vsc8531->nleds)
> +		return -EINVAL;
> +
> +	reg = phy_read(phydev, MSCC_PHY_LED_MODE_SEL) & LED_MODE_SEL_MASK(index);

Another cause of u16, when int should be used. Please check all
instances of phy_read().

> +	reg >>= LED_MODE_SEL_POS(index);
> +	switch (reg) {
> +	case VSC8531_LINK_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;
> +
> +	case VSC8531_LINK_1000_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_LINK_1000) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;
> +
> +	case VSC8531_LINK_100_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_LINK_100) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;
> +
> +	case VSC8531_LINK_10_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_LINK_10) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;
> +
> +	case VSC8531_LINK_100_1000_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_LINK_100) |
> +			 BIT(TRIGGER_NETDEV_LINK_1000) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;
> +
> +	case VSC8531_LINK_10_1000_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_LINK_10) |
> +			 BIT(TRIGGER_NETDEV_LINK_1000) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;
> +
> +	case VSC8531_LINK_10_100_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_LINK_10) |
> +			 BIT(TRIGGER_NETDEV_LINK_100) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;
> +
> +	case VSC8531_ACTIVITY:
> +		*rules = BIT(TRIGGER_NETDEV_LINK) |
> +			 BIT(TRIGGER_NETDEV_RX) |
> +			 BIT(TRIGGER_NETDEV_TX);
> +		break;

Should the combine bit be taken into account here?

> @@ -2343,6 +2532,26 @@ static int vsc85xx_probe(struct phy_device *phydev)
>  	if (!vsc8531->stats)
>  		return -ENOMEM;
>  
> +	phy_id = phydev->drv->phy_id & phydev->drv->phy_id_mask;
> +	if (phy_id == PHY_ID_VSC8541) {

The VSC8541 has its own probe function, vsc8514_probe(). Why is this
needed?

    Andrew

---
pw-bot: cr

  reply	other threads:[~2025-11-06 20:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06 20:03 Prabhakar
2025-11-06 20:45 ` Andrew Lunn [this message]
2025-11-07 10:34   ` Lad, Prabhakar
2025-11-07 12:28     ` Russell King (Oracle)
2025-11-07 12:53       ` Lad, Prabhakar
2025-11-07 13:14     ` Andrew Lunn
2025-11-07 18:55       ` Lad, Prabhakar
2025-11-07 19:01         ` Andrew Lunn
2025-11-07 19:07           ` Lad, Prabhakar

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=ee6a79ae-4857-44e4-b8e9-29cdd80d828f@lunn.ch \
    --to=andrew@lunn.ch \
    --cc=biju.das.jz@bp.renesas.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fabrizio.castro.jz@renesas.com \
    --cc=geert+renesas@glider.be \
    --cc=hkallweit1@gmail.com \
    --cc=horatiu.vultur@microchip.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=maxime.chevallier@bootlin.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=prabhakar.csengg@gmail.com \
    --cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
    --cc=vadim.fedorenko@linux.dev \
    --cc=vladimir.oltean@nxp.com \
    /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

all inboxes | Powered by JetHome®