linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Rob Herring <robh+dt@kernel.org>
To: Michael Walle <michael@walle.cc>
Cc: "Benjamin Herrenschmidt" <benh@kernel.crashing.org>,
	"QCA ath9k Development" <ath9k-devel@qca.qualcomm.com>,
	"Microchip Linux Driver Support" <UNGLinuxDriver@microchip.com>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	linuxppc-dev <linuxppc-dev@lists.ozlabs.org>,
	netdev <netdev@vger.kernel.org>,
	"moderated list:ARM/Mediatek SoC support"
	<linux-mediatek@lists.infradead.org>,
	"open list:MEDIA DRIVERS FOR RENESAS - FCP"
	<linux-renesas-soc@vger.kernel.org>,
	"moderated list:ARM/STM32 ARCHITECTURE"
	<linux-stm32@st-md-mailman.stormreply.com>,
	"open list:ARM/Amlogic Meson..."
	<linux-amlogic@lists.infradead.org>,
	linux-oxnas@groups.io, linux-omap <linux-omap@vger.kernel.org>,
	linux-wireless <linux-wireless@vger.kernel.org>,
	devicetree@vger.kernel.org, linux-staging@lists.linux.dev,
	"Andrew Lunn" <andrew@lunn.ch>,
	"Gregory Clement" <gregory.clement@bootlin.com>,
	"Sebastian Hesselbarth" <sebastian.hesselbarth@gmail.com>,
	"Russell King" <linux@armlinux.org.uk>,
	"Michael Ellerman" <mpe@ellerman.id.au>,
	"Paul Mackerras" <paulus@samba.org>,
	"Andreas Larsson" <andreas@gaisler.com>,
	"David S . Miller" <davem@davemloft.net>,
	"Jakub Kicinski" <kuba@kernel.org>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Chen-Yu Tsai" <wens@csie.org>,
	"Jernej Skrabec" <jernej.skrabec@siol.net>,
	"Joyce Ooi" <joyce.ooi@intel.com>,
	"Chris Snook" <chris.snook@gmail.com>,
	"Rafał Miłecki" <rafal@milecki.pl>,
	"maintainer:BROADCOM BCM7XXX ARM ARCHITECTURE"
	<bcm-kernel-feedback-list@broadcom.com>,
	"Florian Fainelli" <f.fainelli@gmail.com>,
	"Nicolas Ferre" <nicolas.ferre@microchip.com>,
	"Claudiu Beznea" <claudiu.beznea@microchip.com>,
	"Sunil Goutham" <sgoutham@marvell.com>,
	"Fugang Duan" <fugang.duan@nxp.com>,
	"Madalin Bucur" <madalin.bucur@nxp.com>,
	"Pantelis Antoniou" <pantelis.antoniou@gmail.com>,
	"Claudiu Manoil" <claudiu.manoil@nxp.com>,
	"Li Yang" <leoyang.li@nxp.com>,
	"Yisen Zhuang" <yisen.zhuang@huawei.com>,
	"Salil Mehta" <salil.mehta@huawei.com>,
	"Hauke Mehrtens" <hauke@hauke-m.de>,
	"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Vadym Kochan" <vkochan@marvell.com>,
	"Taras Chornyi" <tchornyi@marvell.com>,
	"Mirko Lindner" <mlindner@marvell.com>,
	"Stephen Hemminger" <stephen@networkplumber.org>,
	"Felix Fietkau" <nbd@nbd.name>, "John Crispin" <john@phrozen.org>,
	"Sean Wang" <sean.wang@mediatek.com>,
	"Mark Lee" <Mark-MC.Lee@mediatek.com>,
	"Matthias Brugger" <matthias.bgg@gmail.com>,
	"Bryan Whitehead" <bryan.whitehead@microchip.com>,
	"Vladimir Zapolskiy" <vz@mleia.com>,
	"Sergei Shtylyov" <sergei.shtylyov@gmail.com>,
	"Byungho An" <bh74.an@samsung.com>,
	"Kunihiko Hayashi" <hayashi.kunihiko@socionext.com>,
	"Giuseppe Cavallaro" <peppe.cavallaro@st.com>,
	"Alexandre Torgue" <alexandre.torgue@st.com>,
	"Jose Abreu" <joabreu@synopsys.com>,
	"Maxime Coquelin" <mcoquelin.stm32@gmail.com>,
	"Shawn Guo" <shawnguo@kernel.org>,
	"Sascha Hauer" <s.hauer@pengutronix.de>,
	"Pengutronix Kernel Team" <kernel@pengutronix.de>,
	"Fabio Estevam" <festevam@gmail.com>,
	"NXP Linux Team" <linux-imx@nxp.com>,
	"Kevin Hilman" <khilman@baylibre.com>,
	"Neil Armstrong" <narmstrong@baylibre.com>,
	"Jerome Brunet" <jbrunet@baylibre.com>,
	"Martin Blumenstingl" <martin.blumenstingl@googlemail.com>,
	"Vinod Koul" <vkoul@kernel.org>,
	"Nobuhiro Iwamatsu" <nobuhiro1.iwamatsu@toshiba.co.jp>,
	"Grygorii Strashko" <grygorii.strashko@ti.com>,
	"Wingman Kwok" <w-kwok2@ti.com>,
	"Murali Karicheri" <m-karicheri2@ti.com>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Radhey Shyam Pandey" <radhey.shyam.pandey@xilinx.com>,
	"Kalle Valo" <kvalo@codeaurora.org>,
	"Lorenzo Bianconi" <lorenzo.bianconi83@gmail.com>,
	"Ryder Lee" <ryder.lee@mediatek.com>,
	"Stanislaw Gruszka" <stf_xl@wp.pl>,
	"Helmut Schaa" <helmut.schaa@googlemail.com>,
	"Heiner Kallweit" <hkallweit1@gmail.com>,
	"Frank Rowand" <frowand.list@gmail.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Jérôme Pouiller" <jerome.pouiller@silabs.com>,
	"Vivien Didelot" <vivien.didelot@gmail.com>,
	"Vladimir Oltean" <olteanv@gmail.com>
Subject: Re: [PATCH net-next v4 2/2] of: net: fix of_get_mac_addr_nvmem() for non-platform devices
Date: Fri, 16 Apr 2021 10:19:40 -0500	[thread overview]
Message-ID: <CAL_JsqLrx6nFZrKiEtm2a1vDvQGG+FkpGtJCG2osM8hhGo3P=Q@mail.gmail.com> (raw)
In-Reply-To: <8157eba9317609294da80472622deb28@walle.cc>

On Fri, Apr 16, 2021 at 2:30 AM Michael Walle <michael@walle.cc> wrote:
>
> Am 2021-04-16 05:24, schrieb Benjamin Herrenschmidt:
> > On Mon, 2021-04-12 at 19:47 +0200, Michael Walle wrote:
> >>
> >>  /**
> >>   * of_get_phy_mode - Get phy mode for given device_node
> >> @@ -59,15 +60,39 @@ static int of_get_mac_addr(struct device_node *np,
> >> const char *name, u8 *addr)
> >>  static int of_get_mac_addr_nvmem(struct device_node *np, u8 *addr)
> >>  {
> >>         struct platform_device *pdev = of_find_device_by_node(np);
> >> +       struct nvmem_cell *cell;
> >> +       const void *mac;
> >> +       size_t len;
> >>         int ret;
> >>
> >> -       if (!pdev)
> >> -               return -ENODEV;
> >> +       /* Try lookup by device first, there might be a
> >> nvmem_cell_lookup
> >> +        * associated with a given device.
> >> +        */
> >> +       if (pdev) {
> >> +               ret = nvmem_get_mac_address(&pdev->dev, addr);
> >> +               put_device(&pdev->dev);
> >> +               return ret;
> >> +       }
> >> +
> >
> > This smells like the wrong band aid :)
> >
> > Any struct device can contain an OF node pointer these days.
>
> But not all nodes might have an associated device, see DSA for example.

I believe what Ben is saying and what I said earlier is going from dev
-> OF node is right and OF node -> dev is wrong. If you only have an
OF node, then use an of_* function.

> And as the name suggests of_get_mac_address() operates on a node. So
> if a driver calls of_get_mac_address() it should work on the node. What
> is wrong IMHO, is that the ethernet drivers where the corresponding
> board
> has a nvmem_cell_lookup registered is calling of_get_mac_address(node).
> It should rather call eth_get_mac_address(dev) in the first place.
>
> One would need to figure out if there is an actual device (with an
> assiciated of_node), then call eth_get_mac_address(dev) and if there
> isn't a device call of_get_mac_address(node).

Yes, I think we're all in agreement.

> But I don't know if that is easy to figure out. Well, one could start
> with just the device where nvmem_cell_lookup is used. Then we could
> drop the workaround above.

Start with the ones just passing dev.of_node directly:

$ git grep 'of_get_mac_address(.*of_node)'
drivers/net/ethernet/aeroflex/greth.c:          addr =
of_get_mac_address(ofdev->dev.of_node);
drivers/net/ethernet/altera/altera_tse_main.c:  macaddr =
of_get_mac_address(pdev->dev.of_node);
drivers/net/ethernet/arc/emac_main.c:   mac_addr =
of_get_mac_address(dev->of_node);
drivers/net/ethernet/broadcom/bgmac-bcma.c:             mac =
of_get_mac_address(bgmac->dev->of_node);
drivers/net/ethernet/cavium/octeon/octeon_mgmt.c:       mac =
of_get_mac_address(pdev->dev.of_node);
drivers/net/ethernet/ethoc.c:           mac =
of_get_mac_address(pdev->dev.of_node);
drivers/net/ethernet/ezchip/nps_enet.c: mac_addr =
of_get_mac_address(dev->of_node);
drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c:  mac_addr =
of_get_mac_address(ofdev->dev.of_node);
drivers/net/ethernet/marvell/pxa168_eth.c:              mac_addr =
of_get_mac_address(pdev->dev.of_node);
drivers/net/ethernet/marvell/sky2.c:    iap =
of_get_mac_address(hw->pdev->dev.of_node);
drivers/net/ethernet/mediatek/mtk_eth_soc.c:    mac_addr =
of_get_mac_address(mac->of_node);
drivers/net/ethernet/microchip/lan743x_main.c:  mac_addr =
of_get_mac_address(pdev->dev.of_node);
drivers/net/ethernet/qualcomm/qca_spi.c:        mac =
of_get_mac_address(spi->dev.of_node);
drivers/net/ethernet/qualcomm/qca_uart.c:       mac =
of_get_mac_address(serdev->dev.of_node);
drivers/net/ethernet/wiznet/w5100-spi.c:        const void *mac =
of_get_mac_address(spi->dev.of_node);
drivers/net/ethernet/xilinx/xilinx_axienet_main.c:      mac_addr =
of_get_mac_address(pdev->dev.of_node);
drivers/net/ethernet/xilinx/xilinx_emaclite.c:  mac_address =
of_get_mac_address(ofdev->dev.of_node);
drivers/net/wireless/ralink/rt2x00/rt2x00dev.c: mac_addr =
of_get_mac_address(rt2x00dev->dev->of_node);
drivers/staging/octeon/ethernet.c:              mac =
of_get_mac_address(priv->of_node);
drivers/staging/wfx/main.c:             macaddr =
of_get_mac_address(wdev->dev->of_node);
net/ethernet/eth.c:             addr = of_get_mac_address(dev->of_node);

Then this will find most of the rest:
git grep -W 'of_get_mac_address([a-z]*)'| grep -E '(node|np)'

Rob

  reply	other threads:[~2021-04-16 15:19 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12 17:47 [PATCH net-next v4 0/2] of: net: support non-platform devices in of_get_mac_address() Michael Walle
2021-04-12 17:47 ` [PATCH net-next v4 1/2] of: net: pass the dst buffer to of_get_mac_address() Michael Walle
2021-04-13  0:55   ` Andrew Lunn
2021-04-12 17:47 ` [PATCH net-next v4 2/2] of: net: fix of_get_mac_addr_nvmem() for non-platform devices Michael Walle
2021-04-13  0:57   ` Andrew Lunn
2021-04-16  3:24   ` Benjamin Herrenschmidt
2021-04-16  7:29     ` Michael Walle
2021-04-16 15:19       ` Rob Herring [this message]
2021-04-26 10:54         ` Michael Walle
2021-04-26 23:44           ` Benjamin Herrenschmidt
2021-04-28  8:09             ` Michael Walle
2021-04-13 21:40 ` [PATCH net-next v4 0/2] of: net: support non-platform devices in of_get_mac_address() patchwork-bot+netdevbpf

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='CAL_JsqLrx6nFZrKiEtm2a1vDvQGG+FkpGtJCG2osM8hhGo3P=Q@mail.gmail.com' \
    --to=robh+dt@kernel.org \
    --cc=Mark-MC.Lee@mediatek.com \
    --cc=UNGLinuxDriver@microchip.com \
    --cc=alexandre.torgue@st.com \
    --cc=andreas@gaisler.com \
    --cc=andrew@lunn.ch \
    --cc=ath9k-devel@qca.qualcomm.com \
    --cc=bcm-kernel-feedback-list@broadcom.com \
    --cc=benh@kernel.crashing.org \
    --cc=bh74.an@samsung.com \
    --cc=bryan.whitehead@microchip.com \
    --cc=chris.snook@gmail.com \
    --cc=claudiu.beznea@microchip.com \
    --cc=claudiu.manoil@nxp.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=festevam@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=fugang.duan@nxp.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=gregory.clement@bootlin.com \
    --cc=grygorii.strashko@ti.com \
    --cc=hauke@hauke-m.de \
    --cc=hayashi.kunihiko@socionext.com \
    --cc=helmut.schaa@googlemail.com \
    --cc=hkallweit1@gmail.com \
    --cc=jbrunet@baylibre.com \
    --cc=jernej.skrabec@siol.net \
    --cc=jerome.pouiller@silabs.com \
    --cc=joabreu@synopsys.com \
    --cc=john@phrozen.org \
    --cc=joyce.ooi@intel.com \
    --cc=kernel@pengutronix.de \
    --cc=khilman@baylibre.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=leoyang.li@nxp.com \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-oxnas@groups.io \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=lorenzo.bianconi83@gmail.com \
    --cc=m-karicheri2@ti.com \
    --cc=madalin.bucur@nxp.com \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=michael@walle.cc \
    --cc=michal.simek@xilinx.com \
    --cc=mlindner@marvell.com \
    --cc=mpe@ellerman.id.au \
    --cc=mripard@kernel.org \
    --cc=narmstrong@baylibre.com \
    --cc=nbd@nbd.name \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=nobuhiro1.iwamatsu@toshiba.co.jp \
    --cc=olteanv@gmail.com \
    --cc=pantelis.antoniou@gmail.com \
    --cc=paulus@samba.org \
    --cc=peppe.cavallaro@st.com \
    --cc=radhey.shyam.pandey@xilinx.com \
    --cc=rafal@milecki.pl \
    --cc=ryder.lee@mediatek.com \
    --cc=s.hauer@pengutronix.de \
    --cc=salil.mehta@huawei.com \
    --cc=sean.wang@mediatek.com \
    --cc=sebastian.hesselbarth@gmail.com \
    --cc=sergei.shtylyov@gmail.com \
    --cc=sgoutham@marvell.com \
    --cc=shawnguo@kernel.org \
    --cc=stephen@networkplumber.org \
    --cc=stf_xl@wp.pl \
    --cc=tchornyi@marvell.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vivien.didelot@gmail.com \
    --cc=vkochan@marvell.com \
    --cc=vkoul@kernel.org \
    --cc=vz@mleia.com \
    --cc=w-kwok2@ti.com \
    --cc=wens@csie.org \
    --cc=yisen.zhuang@huawei.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).