public inbox for linux-mediatek@lists.infradead.org
 help / color / mirror / Atom feed
From: "Arınç ÜNAL" <arinc.unal@arinc9.com>
To: David Bauer <mail@david-bauer.net>, Andrew Lunn <andrew@lunn.ch>
Cc: Florian Fainelli <f.fainelli@gmail.com>,
	Vladimir Oltean <olteanv@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Landen Chao <Landen.Chao@mediatek.com>,
	DENG Qingfang <dqfext@gmail.com>,
	Sean Wang <sean.wang@mediatek.com>,
	Daniel Golle <daniel@makrotopia.org>,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-mediatek@lists.infradead.org
Subject: Re: [PATCH 2/2] dt-bindings: net: dsa: mediatek,mt7530: document MDIO-bus
Date: Mon, 1 May 2023 12:28:55 +0300	[thread overview]
Message-ID: <0f501bb6-18a0-1713-b08c-6ad244c022ec@arinc9.com> (raw)
In-Reply-To: <1f759370-af97-e2a4-4b93-183eb854f7cd@david-bauer.net>

On 1.05.2023 12:22, David Bauer wrote:
> Hi Arinc,
> 
> thanks for spotting this issue.
> 
> On 4/30/23 21:54, Arınç ÜNAL wrote:
>> On 30.04.2023 21:48, Andrew Lunn wrote:
>>>>> Try setting ds->slave_mii_bus to the MDIO bus you register via
>>>>> of_mdiobus_register().
>>>>
>>>> That seems to be the case already, under mt7530_setup_mdio():
>>>>
>>>>     bus = devm_mdiobus_alloc(dev);
>>>>     if (!bus)
>>>>         return -ENOMEM;
>>>>
>>>>     ds->slave_mii_bus = bus;
>>>>
>>>> The bus is registered with devm_of_mdiobus_register(), if that matters. (My
>>>> current knowledge about OF or OF helpers for MDIO is next to nothing.)
>>>>
>>>> The same behaviour is there.
>>>
>>> Maybe take a look at what is going on in dsa_slave_phy_setup() and
>>> dsa_slave_phy_connect().
>>>
>>> The way i understand it, is it first looks in DT to see if there is a
>>> phy-handle, and if there is, it uses it. If not, it assumes there is a
>>> 1:1 mapping between port number and PHY address, and looks to see if a
>>> PHY has been found on ds->slave_mii_bus at that address, and uses it.
>>>
>>> So i don't think you need to list the PHY, the fallback should be
>>> used.
>>
>> Thanks for pointing me in the right direction Andrew.
>>
>> I applied this diff:
>>
>> diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
>> index 389f33a12534..19d0c209e7e9 100644
>> --- a/drivers/net/phy/mdio_bus.c
>> +++ b/drivers/net/phy/mdio_bus.c
>> @@ -117,8 +117,12 @@ struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
>>
>>       mdiodev = bus->mdio_map[addr];
>>
>> -    if (!mdiodev)
>> +    if (!mdiodev) {
>> +        dev_info(&bus->dev, "mdio device doesn't exist\n");
>>           return NULL;
>> +    }
>> +
>> +    dev_info(&bus->dev, "mdio device exists\n");
>>
>>       if (!(mdiodev->flags & MDIO_DEVICE_FLAG_PHY))
>>           return NULL;
>> diff --git a/net/dsa/slave.c b/net/dsa/slave.c
>> index 165bb2cb8431..0be408e32a76 100644
>> --- a/net/dsa/slave.c
>> +++ b/net/dsa/slave.c
>> @@ -2487,6 +2487,7 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev)
>>           /* We could not connect to a designated PHY or SFP, so try to
>>            * use the switch internal MDIO bus instead
>>            */
>> +        netdev_err(slave_dev, "using switch's internal MDIO bus\n");
>>           ret = dsa_slave_phy_connect(slave_dev, dp->index, phy_flags);
>>       }
>>       if (ret) {
>>
>> With or without this patch, the switch's internal MDIO bus is used to set
>> up the PHYs.
>>
>> DT that defines ethphy0 only, without this patch applied:
>>
>> [    4.660784] mt7530-mdio mdio-bus:1f wan (uninitialized): using switch's internal MDIO bus
>> [    4.669026] mdio_bus mt7530-0: mdio device exists
>> [    4.677693] mt7530-mdio mdio-bus:1f wan (uninitialized): PHY [mt7530-0:00] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.693238] mt7530-mdio mdio-bus:1f lan0 (uninitialized): using switch's internal MDIO bus
>> [    4.701589] mdio_bus mt7530-0: mdio device exists
>> [    4.707101] mt7530-mdio mdio-bus:1f lan0 (uninitialized): PHY [mt7530-0:01] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.718550] mt7530-mdio mdio-bus:1f lan1 (uninitialized): using switch's internal MDIO bus
>> [    4.726856] mdio_bus mt7530-0: mdio device exists
>> [    4.732384] mt7530-mdio mdio-bus:1f lan1 (uninitialized): PHY [mt7530-0:02] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.743822] mt7530-mdio mdio-bus:1f lan2 (uninitialized): using switch's internal MDIO bus
>> [    4.752154] mdio_bus mt7530-0: mdio device exists
>> [    4.757662] mt7530-mdio mdio-bus:1f lan2 (uninitialized): PHY [mt7530-0:03] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.769099] mt7530-mdio mdio-bus:1f lan3 (uninitialized): using switch's internal MDIO bus
>> [    4.781872] mdio_bus mt7530-0: mdio device exists
>> [    4.787413] mt7530-mdio mdio-bus:1f lan3 (uninitialized): PHY [mt7530-0:04] driver [MediaTek MT7530 PHY] (irq=POLL)
>>
>> Same DT but with this patch applied:
>>
>> [    4.621547] mt7530-mdio mdio-bus:1f: configuring for fixed/trgmii link mode
>> [    4.631524] mt7530-mdio mdio-bus:1f wan (uninitialized): using switch's internal MDIO bus
>> [    4.639764] mdio_bus mt7530-0: mdio device exists
>> [    4.647770] mt7530-mdio mdio-bus:1f wan (uninitialized): PHY [mt7530-0:00] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.663898] mt7530-mdio mdio-bus:1f lan0 (uninitialized): using switch's internal MDIO bus
>> [    4.672253] mdio_bus mt7530-0: mdio device doesn't exist
>> [    4.677597] mt7530-mdio mdio-bus:1f lan0 (uninitialized): no phy at 1
>> [    4.684053] mt7530-mdio mdio-bus:1f lan0 (uninitialized): failed to connect to PHY: -ENODEV
>> [    4.692435] mt7530-mdio mdio-bus:1f lan0 (uninitialized): error -19 setting up PHY for tree 0, switch 0, port 1
>> [    4.703087] mt7530-mdio mdio-bus:1f lan1 (uninitialized): using switch's internal MDIO bus
>> [    4.711408] mdio_bus mt7530-0: mdio device doesn't exist
>> [    4.716731] mt7530-mdio mdio-bus:1f lan1 (uninitialized): no phy at 2
>> [    4.723214] mt7530-mdio mdio-bus:1f lan1 (uninitialized): failed to connect to PHY: -ENODEV
>> [    4.731597] mt7530-mdio mdio-bus:1f lan1 (uninitialized): error -19 setting up PHY for tree 0, switch 0, port 2
>> [    4.742199] mt7530-mdio mdio-bus:1f lan2 (uninitialized): using switch's internal MDIO bus
>> [    4.755431] mdio_bus mt7530-0: mdio device doesn't exist
>> [    4.760793] mt7530-mdio mdio-bus:1f lan2 (uninitialized): no phy at 3
>> [    4.767263] mt7530-mdio mdio-bus:1f lan2 (uninitialized): failed to connect to PHY: -ENODEV
>> [    4.775632] mt7530-mdio mdio-bus:1f lan2 (uninitialized): error -19 setting up PHY for tree 0, switch 0, port 3
>> [    4.786270] mt7530-mdio mdio-bus:1f lan3 (uninitialized): using switch's internal MDIO bus
>> [    4.794591] mdio_bus mt7530-0: mdio device doesn't exist
>> [    4.799944] mt7530-mdio mdio-bus:1f lan3 (uninitialized): no phy at 4
>> [    4.806397] mt7530-mdio mdio-bus:1f lan3 (uninitialized): failed to connect to PHY: -ENODEV
>> [    4.814782] mt7530-mdio mdio-bus:1f lan3 (uninitialized): error -19 setting up PHY for tree 0, switch 0, port 4
>>
>> DT without the mdio node defined, with this patch applied:
>>
>> [    4.650766] mt7530-mdio mdio-bus:1f: configuring for fixed/trgmii link mode
>> [    4.660687] mt7530-mdio mdio-bus:1f wan (uninitialized): using switch's internal MDIO bus
>> [    4.668937] mdio_bus mt7530-0: mdio device exists
>> [    4.677787] mt7530-mdio mdio-bus:1f wan (uninitialized): PHY [mt7530-0:00] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.693165] mt7530-mdio mdio-bus:1f lan0 (uninitialized): using switch's internal MDIO bus
>> [    4.701517] mdio_bus mt7530-0: mdio device exists
>> [    4.707029] mt7530-mdio mdio-bus:1f lan0 (uninitialized): PHY [mt7530-0:01] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.718469] mt7530-mdio mdio-bus:1f lan1 (uninitialized): using switch's internal MDIO bus
>> [    4.726773] mdio_bus mt7530-0: mdio device exists
>> [    4.732322] mt7530-mdio mdio-bus:1f lan1 (uninitialized): PHY [mt7530-0:02] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.743793] mt7530-mdio mdio-bus:1f lan2 (uninitialized): using switch's internal MDIO bus
>> [    4.752143] mdio_bus mt7530-0: mdio device exists
>> [    4.757662] mt7530-mdio mdio-bus:1f lan2 (uninitialized): PHY [mt7530-0:03] driver [MediaTek MT7530 PHY] (irq=POLL)
>> [    4.769105] mt7530-mdio mdio-bus:1f lan3 (uninitialized): using switch's internal MDIO bus
>> [    4.781905] mdio_bus mt7530-0: mdio device exists
>> [    4.787459] mt7530-mdio mdio-bus:1f lan3 (uninitialized): PHY [mt7530-0:04] driver [MediaTek MT7530 PHY] (irq=POLL)
>>
>> This is how I define it, mind you no phandles.
>>
>> switch@1f {
>>      ...
>>      mdio {
>>          #address-cells = <0x01>;
>>          #size-cells = <0x00>;
>>
>>          ethernet-phy@0 {
>>              reg = <0x00>;
>>          };
>>      };
>> };
>>
>> Like you said, if the mdio node is not defined, the driver will assume 1:1
>> mapping. If not, it will need all the PHYs to be defined on the mdio node
>> along with on the ports node. Hence back to my original statement, we can
>> either force defining the PHYs on the mdio node which would break the ABI,
>> or forget about doing PHY muxing this way.
> 
> While i was not aware of this side effect, I don't see how this breaks the ABI.

Your patch doesn't break it, my then-intention of doing PHY muxing by
utilising this would. Your first patch is perfectly fine as is.

> 
> Existing device-trees not defining the MDIO node will still continue to work.

Agreed, I also confirmed this with my test above.

> 
> Wouldn't we just skip the whole issue by documenting the need for defining all PHYs
> used on the switch when defining the MDIO bus?

Good idea, please do that.

Arınç


  reply	other threads:[~2023-05-01  9:29 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-30 11:28 [PATCH 1/2] mt7530: register OF node for internal MDIO bus David Bauer
2023-04-30 11:28 ` [PATCH 2/2] dt-bindings: net: dsa: mediatek,mt7530: document MDIO-bus David Bauer
2023-04-30 12:34   ` Arınç ÜNAL
2023-04-30 12:44     ` Daniel Golle
2023-04-30 12:52       ` Arınç ÜNAL
2023-04-30 16:17     ` Arınç ÜNAL
2023-04-30 17:18       ` Andrew Lunn
2023-04-30 18:28         ` Arınç ÜNAL
2023-04-30 18:48           ` Andrew Lunn
2023-04-30 19:54             ` Arınç ÜNAL
2023-04-30 20:41               ` Andrew Lunn
2023-05-01  9:22               ` David Bauer
2023-05-01  9:28                 ` Arınç ÜNAL [this message]
2023-04-30 12:53   ` Arınç ÜNAL
2023-04-30 11:42 ` [PATCH 1/2] mt7530: register OF node for internal MDIO bus Daniel Golle
2023-04-30 14:14 ` Andrew Lunn

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=0f501bb6-18a0-1713-b08c-6ad244c022ec@arinc9.com \
    --to=arinc.unal@arinc9.com \
    --cc=Landen.Chao@mediatek.com \
    --cc=andrew@lunn.ch \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=daniel@makrotopia.org \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=dqfext@gmail.com \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=kuba@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=mail@david-bauer.net \
    --cc=matthias.bgg@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=olteanv@gmail.com \
    --cc=pabeni@redhat.com \
    --cc=robh+dt@kernel.org \
    --cc=sean.wang@mediatek.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