From: Andrew Lunn <andrew@lunn•ch>
To: Lukas Wunner <lukas@wunner•de>
Cc: Marek Vasut <marex@denx•de>,
netdev@vger•kernel.org, "David S . Miller" <davem@davemloft•net>,
Petr Stetiar <ynezz@true•cz>, YueHaibing <yuehaibing@huawei•com>
Subject: Re: [PATCH 07/14] net: ks8851: Use 16-bit writes to program MAC address
Date: Tue, 24 Mar 2020 13:25:53 +0100 [thread overview]
Message-ID: <20200324122553.GS3819@lunn.ch> (raw)
In-Reply-To: <20200324081311.ww6p7dmijbddi5jm@wunner.de>
On Tue, Mar 24, 2020 at 09:13:11AM +0100, Lukas Wunner wrote:
> On Tue, Mar 24, 2020 at 12:42:56AM +0100, Marek Vasut wrote:
> > On the SPI variant of KS8851, the MAC address can be programmed with
> > either 8/16/32-bit writes. To make it easier to support the 16-bit
> > parallel option of KS8851 too, switch both the MAC address programming
> > and readout to 16-bit operations.
> [...]
> > static int ks8851_write_mac_addr(struct net_device *dev)
> > {
> > struct ks8851_net *ks = netdev_priv(dev);
> > + u16 val;
> > int i;
> >
> > mutex_lock(&ks->lock);
> > @@ -358,8 +329,12 @@ static int ks8851_write_mac_addr(struct net_device *dev)
> > * the first write to the MAC address does not take effect.
> > */
> > ks8851_set_powermode(ks, PMECR_PM_NORMAL);
> > - for (i = 0; i < ETH_ALEN; i++)
> > - ks8851_wrreg8(ks, KS_MAR(i), dev->dev_addr[i]);
> > +
> > + for (i = 0; i < ETH_ALEN; i += 2) {
> > + val = (dev->dev_addr[i] << 8) | dev->dev_addr[i + 1];
> > + ks8851_wrreg16(ks, KS_MAR(i + 1), val);
> > + }
> > +
>
> This looks like it won't work on little-endian machines: The MAC bytes
> are stored in dev->dev_addr as 012345, but in the EEPROM they're stored
> as 543210. The first 16-bit value that you write is 10 on big-endian
> and 01 on little-endian if I'm not mistaken.
>
> By only writing 8-bit values, the original author elegantly sidestepped
> this issue.
>
> Maybe the simplest and most readable solution is something like:
>
> u8 val[2];
> ...
> val[0] = dev->dev_addr[i+1];
> val[1] = dev->dev_addr;
>
> Then cast val to a u16 when passing it to ks8851_wrreg16().
>
> Alternatively, use cpu_to_be16().
Hi Lukas
There is a cpu_to_be16() inside ks8851_wrreg16(). Something i already
checked, because i wondered about endianess issues as well.
Andrew
next prev parent reply other threads:[~2020-03-24 12:25 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-23 23:42 [PATCH 00/14] net: ks8851: Unify KS8851 SPI and MLL drivers Marek Vasut
2020-03-23 23:42 ` [PATCH 01/14] net: ks8851: Factor out spi->dev in probe()/remove() Marek Vasut
2020-03-24 1:15 ` Andrew Lunn
2020-03-24 6:46 ` Lukas Wunner
2020-03-23 23:42 ` [PATCH 02/14] net: ks8851: Replace dev_err() with netdev_err() in IRQ handler Marek Vasut
2020-03-24 1:16 ` Andrew Lunn
2020-03-23 23:42 ` [PATCH 03/14] net: ks8851: Pass device pointer into ks8851_init_mac() Marek Vasut
2020-03-24 1:06 ` Andrew Lunn
2020-03-24 7:08 ` Lukas Wunner
2020-03-23 23:42 ` [PATCH 04/14] net: ks8851: Use devm_alloc_etherdev() Marek Vasut
2020-03-24 1:19 ` Andrew Lunn
2020-03-23 23:42 ` [PATCH 05/14] net: ks8851: Use dev_{get,set}_drvdata() Marek Vasut
2020-03-24 1:22 ` Andrew Lunn
2020-03-23 23:42 ` [PATCH 06/14] net: ks8851: Remove ks8851_rdreg32() Marek Vasut
2020-03-24 1:30 ` Andrew Lunn
2020-03-24 12:34 ` Marek Vasut
2020-03-24 7:22 ` Lukas Wunner
2020-03-24 12:37 ` Marek Vasut
2020-03-23 23:42 ` [PATCH 07/14] net: ks8851: Use 16-bit writes to program MAC address Marek Vasut
2020-03-24 1:40 ` Andrew Lunn
2020-03-24 7:17 ` Michal Kubecek
2020-03-24 8:13 ` Lukas Wunner
2020-03-24 12:25 ` Andrew Lunn [this message]
2020-03-24 12:36 ` Lukas Wunner
2020-03-24 13:09 ` Marek Vasut
2020-03-24 13:31 ` Marek Vasut
2020-03-24 14:47 ` Lukas Wunner
2020-03-24 14:53 ` Marek Vasut
2020-03-23 23:42 ` [PATCH 08/14] net: ks8851: Use 16-bit read of RXFC register Marek Vasut
2020-03-24 1:50 ` Andrew Lunn
2020-03-24 12:50 ` Marek Vasut
2020-03-24 13:32 ` Andrew Lunn
2020-03-24 10:41 ` Lukas Wunner
2020-03-24 12:42 ` Marek Vasut
2020-03-23 23:42 ` [PATCH 09/14] net: ks8851: Split out SPI specific entries in struct ks8851_net Marek Vasut
2020-03-24 1:55 ` Andrew Lunn
2020-03-24 10:49 ` Lukas Wunner
2020-03-24 12:27 ` Andrew Lunn
2020-03-23 23:42 ` [PATCH 10/14] net: ks8851: Split out SPI specific code from probe() and remove() Marek Vasut
2020-03-24 1:58 ` Andrew Lunn
2020-03-23 23:43 ` [PATCH 11/14] net: ks8851: Implement register and FIFO accessor callbacks Marek Vasut
2020-03-24 13:45 ` Lukas Wunner
2020-03-24 14:10 ` Marek Vasut
2020-03-24 14:29 ` Lukas Wunner
2020-03-24 14:44 ` Marek Vasut
2020-03-29 14:22 ` Marek Vasut
2020-03-23 23:43 ` [PATCH 12/14] net: ks8851: Separate SPI operations into separate file Marek Vasut
2020-03-23 23:43 ` [PATCH 13/14] net: ks8851: Implement Parallel bus operations Marek Vasut
2020-03-24 8:16 ` kbuild test robot
2020-03-23 23:43 ` [PATCH 14/14] net: ks8851: Remove ks8851_mll.c Marek Vasut
2020-03-24 14:08 ` Lukas Wunner
2020-03-24 14:12 ` Marek Vasut
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=20200324122553.GS3819@lunn.ch \
--to=andrew@lunn$(echo .)ch \
--cc=davem@davemloft$(echo .)net \
--cc=lukas@wunner$(echo .)de \
--cc=marex@denx$(echo .)de \
--cc=netdev@vger$(echo .)kernel.org \
--cc=ynezz@true$(echo .)cz \
--cc=yuehaibing@huawei$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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