From: Vladimir Oltean <olteanv@gmail.com>
To: Arun.Ramadoss@microchip.com
Cc: songliubraving@fb.com, linux-kernel@vger.kernel.org,
bpf@vger.kernel.org, daniel@iogearbox.net, ast@kernel.org,
robh+dt@kernel.org, andrew@lunn.ch, devicetree@vger.kernel.org,
linux@armlinux.org.uk, andrii@kernel.org,
UNGLinuxDriver@microchip.com, john.fastabend@gmail.com,
vivien.didelot@gmail.com, f.fainelli@gmail.com, kuba@kernel.org,
kpsingh@kernel.org, edumazet@google.com, pabeni@redhat.com,
netdev@vger.kernel.org, kafai@fb.com, yhs@fb.com,
krzysztof.kozlowski+dt@linaro.org, davem@davemloft.net,
Woojung.Huh@microchip.com
Subject: Re: [Patch net-next v13 07/13] net: dsa: microchip: add LAN937x SPI driver
Date: Thu, 5 May 2022 18:15:07 +0300 [thread overview]
Message-ID: <20220505151507.5fp3lur74gs4faee@skbuf> (raw)
In-Reply-To: <52e682a1bcd2aac1097f2b4f1948066fe5bb6924.camel@microchip.com>
On Thu, May 05, 2022 at 10:32:17AM +0000, Arun.Ramadoss@microchip.com wrote:
> > > static int lan937x_switch_init(struct ksz_device *dev)
> > > {
> > > + int ret;
> > > +
> > > dev->ds->ops = &lan937x_switch_ops;
> > >
> > > + /* Check device tree */
> > > + ret = lan937x_check_device_id(dev);
> > > + if (ret < 0)
> > > + return ret;
> > > +
> >
> > Can't this be called from lan937x_spi_probe() directly, why do you
> > need
> > to go through lan937x_switch_register() first?
>
> lan937x_check_device_id function compares the dev->chip_id with the
> lan937x_switch_chip array and populate the some of the parameters of
> struct ksz_dev. The dev->chip_id is populated using the dev->dev_ops-
> >detect in the ksz_switch_register function. If lan937x_check_device_id
> needs to be called in spi_probe, then chip_id has to be identified as
> part of spi_probe function. Since ksz_switch_register handles the
> identifying the chip_id, checking the device_id is part of switch_init.
>
> if (dev->dev_ops->detect(dev))
> return -EINVAL;
>
> ret = dev->dev_ops->init(dev);
> if (ret)
> return ret;
Whatever you do, please use a common pattern for all of ksz9477, ksz8,
and your lan937x. This includes validation of chip id, placement of the
chip_data and dev_ops structures, and reuse as much logic as possible.
The key is to limit the chip-specific information to structured data
(tables) wherever possible and let common code deal with them.
For example there is no reason why struct ksz_chip_data is redefined for
every switch, why copying from "chip" to "dev" is duplicated for every
switch, and yet, why every other switch copies from "chip" to "dev" in
the "switch_init" function yet lan937x does it from "check_device_id".
So much boilerplate, yet different in subtle ways, makes the code very
unpleasant to review.
I'm sure you'll find a straightforward way to code up a probing function.
> As per the comment, enable_spi_indirect_access function called twice
> https://lore.kernel.org/netdev/20220408232557.b62l3lksotq5vuvm@skbuf/
> I have removed the enable_spi_indirect_access in the lan937x_setup
> function in v13 patch 6. But it actually failed our regression.
> The SPI indirect is required for accessing the Internal phy registers.
> We have enabled it in lan937x_init before registering the
> mdio_register. We need it for reading the phy id.
> And another place enabled in lan937x_setup after lan937x_switch_reset
> function. When I removed enabling in setup function, switch_reset
> disables the spi indirecting addressing. Because of that further phy
> register r/w fails. In Summary, we need to enable spi indirect access
> in both the places, one for mdio_register and another after
> switch_reset.
>
> Can I enable it both the places? Kindly suggest.
So you call lan937x_reset_switch() as the first thing in ds->ops->setup(),
and this momentarily breaks the earlier MDIO bus setup done from probe
-> ksz_switch_register() -> dev_ops->init().
So why don't you move the lan937x_enable_spi_indirect_access() and
lan937x_mdio_register() calls to ds->ops->setup(), _after_ the switch
soft reset, then?
next prev parent reply other threads:[~2022-05-05 15:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-04 15:17 [Patch net-next v13 00/13] net: dsa: microchip: DSA driver support for LAN937x Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 01/13] dt-bindings: net: make internal-delay-ps based on phy-mode Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 02/13] dt-bindings: net: dsa: dt bindings for microchip lan937x Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 03/13] net: dsa: move mib->cnt_ptr reset code to ksz_common.c Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 04/13] net: dsa: tag_ksz: add tag handling for Microchip LAN937x Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 05/13] net: dsa: microchip: add DSA support for microchip LAN937x Arun Ramadoss
2022-05-04 19:26 ` Vladimir Oltean
2022-05-04 15:17 ` [Patch net-next v13 06/13] net: dsa: microchip: add support for phy read and write Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 07/13] net: dsa: microchip: add LAN937x SPI driver Arun Ramadoss
2022-05-04 20:07 ` Vladimir Oltean
2022-05-05 10:32 ` Arun.Ramadoss
2022-05-05 15:15 ` Vladimir Oltean [this message]
2022-05-04 15:17 ` [Patch net-next v13 08/13] net: dsa: microchip: add support for MTU configuration and fast_age Arun Ramadoss
2022-05-04 20:10 ` Vladimir Oltean
2022-05-04 15:17 ` [Patch net-next v13 09/13] net: dsa: microchip: add support for phylink management Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 10/13] net: dsa: microchip: add support for ethtool port counters Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 11/13] net: dsa: microchip: add support for port mirror operations Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 12/13] net: dsa: microchip: add support for fdb and mdb management Arun Ramadoss
2022-05-04 15:17 ` [Patch net-next v13 13/13] net: dsa: microchip: add support for vlan operations Arun Ramadoss
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=20220505151507.5fp3lur74gs4faee@skbuf \
--to=olteanv@gmail.com \
--cc=Arun.Ramadoss@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=Woojung.Huh@microchip.com \
--cc=andrew@lunn.ch \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robh+dt@kernel.org \
--cc=songliubraving@fb.com \
--cc=vivien.didelot@gmail.com \
--cc=yhs@fb.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;
as well as URLs for NNTP newsgroup(s).