From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Buesch Subject: Re: [patch 09/11] b44: fix eeprom endianess issue Date: Tue, 26 Sep 2006 18:04:37 +0200 Message-ID: <200609261804.37422.mb@bu3sch.de> References: <200609252339.k8PNdNE4002654@shell0.pdx.osdl.net> <200609261747.25575.mb@bu3sch.de> <45194E60.4010701@garzik.org> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Cc: netdev@vger.kernel.org, Gary Zambrano , akpm@osdl.org Return-path: Received: from static-ip-62-75-166-246.inaddr.intergenia.de ([62.75.166.246]:19935 "EHLO bu3sch.de") by vger.kernel.org with ESMTP id S932314AbWIZQEm (ORCPT ); Tue, 26 Sep 2006 12:04:42 -0400 To: Jeff Garzik In-Reply-To: <45194E60.4010701@garzik.org> Content-Disposition: inline Sender: netdev-owner@vger.kernel.org List-Id: netdev.vger.kernel.org On Tuesday 26 September 2006 17:59, Jeff Garzik wrote: > Michael Buesch wrote: > > On Tuesday 26 September 2006 01:59, Jeff Garzik wrote: > >> akpm@osdl.org wrote: > >>> From: Michael Buesch > >>> > >>> This fixes eeprom read on big-endian architectures. > >>> > >>> Signed-off-by: Michael Buesch > >>> Cc: Jeff Garzik > >>> Signed-off-by: Andrew Morton > >>> --- > >>> > >>> drivers/net/b44.c | 2 +- > >>> 1 file changed, 1 insertion(+), 1 deletion(-) > >>> > >>> diff -puN drivers/net/b44.c~b44-fix-eeprom-endianess-issue drivers/net/b44.c > >>> --- a/drivers/net/b44.c~b44-fix-eeprom-endianess-issue > >>> +++ a/drivers/net/b44.c > >>> @@ -2055,7 +2055,7 @@ static int b44_read_eeprom(struct b44 *b > >>> u16 *ptr = (u16 *) data; > >>> > >>> for (i = 0; i < 128; i += 2) > >>> - ptr[i / 2] = readw(bp->regs + 4096 + i); > >>> + ptr[i / 2] = cpu_to_le16(readw(bp->regs + 4096 + i)); > >> Seems highly silly to me: readw() already swaps on big endian, so > >> you're just swapping again. And then... read the call of > >> b44_read_eeprom(): bp->dev->dev_addr[] assignment is such that it swaps > >> YET AGAIN. > >> > >> Seems like a better solution would be to remove the manual swap from the > >> caller of b44_read_eeprom(). > > > > I already explained this to you, but I will repeat me. > > readw returns the data in CPU order. > > With cpu_to_le16 we convert it to little endian, because > > "ptr" is a pointer to a _byte_ arrray. See the cast above. > > A byte array is little endian. > > Should I go into deeper detail, or did you get it? ;) > > > > The dev_addr assignment _intentionally_ swaps yet again, because > > the values are stored in bigendian format in the SPROM. > > > > Removing the swap for dev_addr would definately the worse and wrong > > solution. > > AFAICS it's an obviously-correct end result, with far fewer swaps to boot. No it isn't. There are lots of other parameters in the ssb SPROM. And most of them are _not_ in bigendian. I think we also read the PHYport or something in b44. See bcm43xx or the ssb module for the rest of the values. Returning a SPROM bytearray as BABABABA is just plain wrong. It must always be ABABABAB, because we expect this. This patch encures ABABAB order on every platform. The interpret function must not know on which platform we are, as it's just interpreting the _byte_ array (byte array, without any endian semantics). This _fixes_ a bug (In the correct way, so that future bugs will not appear) -- Greetings Michael.