All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Sky Huang <SkyLake.Huang@mediatek.com>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Daniel Golle <daniel@makrotopia.org>,
	Qingfang Deng <dqfext@gmail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	Steven Liu <Steven.Liu@mediatek.com>
Subject: Re: [PATCH 3/3] net: phy: mediatek: add support for built-in 2.5G ethernet PHY on MT7988
Date: Thu, 25 Apr 2024 10:01:58 +0100	[thread overview]
Message-ID: <ZiocBmBWiNnbeyGq@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240425023325.15586-4-SkyLake.Huang@mediatek.com>

On Thu, Apr 25, 2024 at 10:33:25AM +0800, Sky Huang wrote:
> +static int mt7988_2p5ge_phy_config_init(struct phy_device *phydev)
> +{
> +	int ret, i;
> +	const struct firmware *fw;
> +	struct device *dev = &phydev->mdio.dev;
> +	struct device_node *np;
> +	void __iomem *pmb_addr;
> +	void __iomem *md32_en_cfg_base;
> +	struct mtk_i2p5ge_phy_priv *priv = phydev->priv;
> +	u16 reg;
> +	struct pinctrl *pinctrl;
> +
> +	if (!priv->fw_loaded) {
> +		np = of_find_compatible_node(NULL, NULL, "mediatek,2p5gphy-fw");
> +		if (!np)
> +			return -ENOENT;
> +		pmb_addr = of_iomap(np, 0);
> +		if (!pmb_addr)
> +			return -ENOMEM;
> +		md32_en_cfg_base = of_iomap(np, 1);
> +		if (!md32_en_cfg_base)
> +			return -ENOMEM;

Wouldn't it be better to do this in the probe function rather than here?

> +
> +		ret = request_firmware(&fw, MT7988_2P5GE_PMB, dev);
> +		if (ret) {
> +			dev_err(dev, "failed to load firmware: %s, ret: %d\n",
> +				MT7988_2P5GE_PMB, ret);
> +			return ret;
> +		}

This will block for userspace while holding phydev->lock and the RTNL.
That blocks much of the networking APIs, which is not a good idea. If
you have a number of these PHYs, then the RTNL will serialise the
loading of firmware.

> +
> +		reg = readw(md32_en_cfg_base);
> +		if (reg & MD32_EN) {
> +			phy_set_bits(phydev, 0, BIT(15));

This is probably the BMCR, so if it is, please use the established
definitions.

> +			usleep_range(10000, 11000);
> +		}
> +		phy_set_bits(phydev, 0, BIT(11));

This also looks like it's probably the BMCR.

> +
> +		/* Write magic number to safely stall MCU */
> +		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x800e, 0x1100);
> +		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x800f, 0x00df);
> +
> +		for (i = 0; i < fw->size - 1; i += 4)
> +			writel(*((uint32_t *)(fw->data + i)), pmb_addr + i);
> +		release_firmware(fw);
> +
> +		writew(reg & ~MD32_EN, md32_en_cfg_base);
> +		writew(reg | MD32_EN, md32_en_cfg_base);
> +		phy_set_bits(phydev, 0, BIT(15));

And also probably the BMCR.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!


WARNING: multiple messages have this Message-ID (diff)
From: "Russell King (Oracle)" <linux@armlinux.org.uk>
To: Sky Huang <SkyLake.Huang@mediatek.com>
Cc: Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Daniel Golle <daniel@makrotopia.org>,
	Qingfang Deng <dqfext@gmail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	Steven Liu <Steven.Liu@mediatek.com>
Subject: Re: [PATCH 3/3] net: phy: mediatek: add support for built-in 2.5G ethernet PHY on MT7988
Date: Thu, 25 Apr 2024 10:01:58 +0100	[thread overview]
Message-ID: <ZiocBmBWiNnbeyGq@shell.armlinux.org.uk> (raw)
In-Reply-To: <20240425023325.15586-4-SkyLake.Huang@mediatek.com>

On Thu, Apr 25, 2024 at 10:33:25AM +0800, Sky Huang wrote:
> +static int mt7988_2p5ge_phy_config_init(struct phy_device *phydev)
> +{
> +	int ret, i;
> +	const struct firmware *fw;
> +	struct device *dev = &phydev->mdio.dev;
> +	struct device_node *np;
> +	void __iomem *pmb_addr;
> +	void __iomem *md32_en_cfg_base;
> +	struct mtk_i2p5ge_phy_priv *priv = phydev->priv;
> +	u16 reg;
> +	struct pinctrl *pinctrl;
> +
> +	if (!priv->fw_loaded) {
> +		np = of_find_compatible_node(NULL, NULL, "mediatek,2p5gphy-fw");
> +		if (!np)
> +			return -ENOENT;
> +		pmb_addr = of_iomap(np, 0);
> +		if (!pmb_addr)
> +			return -ENOMEM;
> +		md32_en_cfg_base = of_iomap(np, 1);
> +		if (!md32_en_cfg_base)
> +			return -ENOMEM;

Wouldn't it be better to do this in the probe function rather than here?

> +
> +		ret = request_firmware(&fw, MT7988_2P5GE_PMB, dev);
> +		if (ret) {
> +			dev_err(dev, "failed to load firmware: %s, ret: %d\n",
> +				MT7988_2P5GE_PMB, ret);
> +			return ret;
> +		}

This will block for userspace while holding phydev->lock and the RTNL.
That blocks much of the networking APIs, which is not a good idea. If
you have a number of these PHYs, then the RTNL will serialise the
loading of firmware.

> +
> +		reg = readw(md32_en_cfg_base);
> +		if (reg & MD32_EN) {
> +			phy_set_bits(phydev, 0, BIT(15));

This is probably the BMCR, so if it is, please use the established
definitions.

> +			usleep_range(10000, 11000);
> +		}
> +		phy_set_bits(phydev, 0, BIT(11));

This also looks like it's probably the BMCR.

> +
> +		/* Write magic number to safely stall MCU */
> +		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x800e, 0x1100);
> +		phy_write_mmd(phydev, MDIO_MMD_VEND1, 0x800f, 0x00df);
> +
> +		for (i = 0; i < fw->size - 1; i += 4)
> +			writel(*((uint32_t *)(fw->data + i)), pmb_addr + i);
> +		release_firmware(fw);
> +
> +		writew(reg & ~MD32_EN, md32_en_cfg_base);
> +		writew(reg | MD32_EN, md32_en_cfg_base);
> +		phy_set_bits(phydev, 0, BIT(15));

And also probably the BMCR.

-- 
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2024-04-25  9:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25  2:33 [PATCH 0/3] net: phy: mediatek: Integrate mtk-phy-lib and add 2.5Gphy support Sky Huang
2024-04-25  2:33 ` Sky Huang
2024-04-25  2:33 ` [PATCH 1/3] net: phy: mediatek: Re-organize MediaTek ethernet phy drivers Sky Huang
2024-04-25  2:33   ` Sky Huang
2024-04-25 15:04   ` Andrew Lunn
2024-04-25 15:04     ` Andrew Lunn
2024-04-26  2:27   ` kernel test robot
2024-04-26  2:27     ` kernel test robot
2024-04-25  2:33 ` [PATCH 2/3] net: phy: mediatek: Add mtk phy lib for token ring access & LED/other manipulations Sky Huang
2024-04-25  2:33   ` Sky Huang
2024-04-25 15:13   ` Andrew Lunn
2024-04-25 15:13     ` Andrew Lunn
2024-04-25 18:05   ` kernel test robot
2024-04-25 18:05     ` kernel test robot
2024-05-07 14:40   ` Daniel Golle
2024-05-07 14:40     ` Daniel Golle
2024-05-08 12:25     ` Andrew Lunn
2024-05-08 12:25       ` Andrew Lunn
2024-05-08 13:09       ` Russell King (Oracle)
2024-05-08 13:09         ` Russell King (Oracle)
2024-05-08 14:02         ` Daniel Golle
2024-05-08 14:02           ` Daniel Golle
2024-04-25  2:33 ` [PATCH 3/3] net: phy: mediatek: add support for built-in 2.5G ethernet PHY on MT7988 Sky Huang
2024-04-25  2:33   ` Sky Huang
2024-04-25  9:01   ` Russell King (Oracle) [this message]
2024-04-25  9:01     ` Russell King (Oracle)
2024-05-08 10:56     ` SkyLake Huang (黃啟澤)
2024-05-08 10:56       ` SkyLake Huang (黃啟澤)
2024-05-08 12:30       ` Andrew Lunn
2024-05-08 12:30         ` Andrew Lunn
2024-05-08 16:21         ` Daniel Golle
2024-05-08 16:21           ` Daniel Golle
2024-04-25 15:37   ` Andrew Lunn
2024-04-25 15:37     ` Andrew Lunn
2024-04-25  3:05 ` [PATCH 0/3] net: phy: mediatek: Integrate mtk-phy-lib and add 2.5Gphy support Daniel Golle
2024-04-25  3:05   ` Daniel Golle

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=ZiocBmBWiNnbeyGq@shell.armlinux.org.uk \
    --to=linux@armlinux.org.uk \
    --cc=SkyLake.Huang@mediatek.com \
    --cc=Steven.Liu@mediatek.com \
    --cc=andrew@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=dqfext@gmail.com \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.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 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.