linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] b43: use the bitrev helpers rather than rolling a private one
@ 2008-05-13 19:55 Harvey Harrison
  2008-05-13 23:24 ` Michael Buesch
  0 siblings, 1 reply; 7+ messages in thread
From: Harvey Harrison @ 2008-05-13 19:55 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Andrew Morton, linux-wireless

The 4-bit reversal flip_4bit is replaced with the bitrev helper
bitrev8 and a 4-bit shift.  The B43_WARN is moved to the location
where a register is read from for checking there.  The other caller
explicitly passes an array index which is guaranteed to be within range
and so a B43_WARN is not added there.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 drivers/net/wireless/b43/phy.c |   26 +++++---------------------
 1 files changed, 5 insertions(+), 21 deletions(-)

diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
index de024dc..3410674 100644
--- a/drivers/net/wireless/b43/phy.c
+++ b/drivers/net/wireless/b43/phy.c
@@ -28,6 +28,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/types.h>
+#include <linux/bitrev.h>
 
 #include "b43.h"
 #include "phy.h"
@@ -85,23 +86,6 @@ const u8 b43_radio_channel_codes_bg[] = {
 
 static void b43_phy_initg(struct b43_wldev *dev);
 
-/* Reverse the bits of a 4bit value.
- * Example:  1101 is flipped 1011
- */
-static u16 flip_4bit(u16 value)
-{
-	u16 flipped = 0x0000;
-
-	B43_WARN_ON(value & ~0x000F);
-
-	flipped |= (value & 0x0001) << 3;
-	flipped |= (value & 0x0002) << 1;
-	flipped |= (value & 0x0004) >> 1;
-	flipped |= (value & 0x0008) >> 3;
-
-	return flipped;
-}
-
 static void generate_rfatt_list(struct b43_wldev *dev,
 				struct b43_rfatt_list *list)
 {
@@ -3069,13 +3053,13 @@ b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
 		}
 		radio_stacksave(0x0078);
 		tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
-		flipped = flip_4bit(tmp);
+		B43_WARN_ON(tmp > 15);
+		flipped = bitrev8(tmp) >> 4;
 		if (flipped < 10 && flipped >= 8)
 			flipped = 7;
 		else if (flipped >= 10)
 			flipped -= 3;
-		flipped = flip_4bit(flipped);
-		flipped = (flipped << 1) | 0x0020;
+		flipped = (bitrev8(flipped) >> 3) | 0x0020;
 		b43_radio_write16(dev, 0x0078, flipped);
 
 		b43_calc_nrssi_threshold(dev);
@@ -3708,7 +3692,7 @@ u16 b43_radio_init2050(struct b43_wldev *dev)
 	tmp1 >>= 9;
 
 	for (i = 0; i < 16; i++) {
-		radio78 = ((flip_4bit(i) << 1) | 0x20);
+		radio78 = (bitrev8(i) >> 3) | 0x0020;
 		b43_radio_write16(dev, 0x78, radio78);
 		udelay(10);
 		for (j = 0; j < 16; j++) {
-- 
1.5.5.1.482.g0f174




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] b43: use the bitrev helpers rather than rolling a private one
  2008-05-13 19:55 [PATCH] b43: use the bitrev helpers rather than rolling a private one Harvey Harrison
@ 2008-05-13 23:24 ` Michael Buesch
  2008-05-14  0:53   ` Harvey Harrison
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Buesch @ 2008-05-13 23:24 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: Andrew Morton, linux-wireless

On Tuesday 13 May 2008 21:55:18 Harvey Harrison wrote:
> The 4-bit reversal flip_4bit is replaced with the bitrev helper
> bitrev8 and a 4-bit shift.  The B43_WARN is moved to the location
> where a register is read from for checking there.  The other caller
> explicitly passes an array index which is guaranteed to be within range
> and so a B43_WARN is not added there.
> 
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>

ACK

But I'd prefer if we had something like the following
and use that:

#define bitrev4(x)	(bitrev8(x) >> 4)

This way the confusing (confusing to me :) ) shifts in the code would go away.
I have a hard time realizing that
bitrev8(x) >> 3
does actually mean
bitrev4(x) << 1
Maybe I'm just stupid, though. :)

> @@ -3069,13 +3053,13 @@ b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
>  		}
>  		radio_stacksave(0x0078);
>  		tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
> -		flipped = flip_4bit(tmp);
> +		B43_WARN_ON(tmp > 15);
> +		flipped = bitrev8(tmp) >> 4;
>  		if (flipped < 10 && flipped >= 8)


-- 
Greetings Michael.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] b43: use the bitrev helpers rather than rolling a private one
  2008-05-13 23:24 ` Michael Buesch
@ 2008-05-14  0:53   ` Harvey Harrison
  2008-05-14  1:03     ` Michael Buesch
  0 siblings, 1 reply; 7+ messages in thread
From: Harvey Harrison @ 2008-05-14  0:53 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Andrew Morton, linux-wireless

On Wed, 2008-05-14 at 01:24 +0200, Michael Buesch wrote:
> On Tuesday 13 May 2008 21:55:18 Harvey Harrison wrote:
> > The 4-bit reversal flip_4bit is replaced with the bitrev helper
> > bitrev8 and a 4-bit shift.  The B43_WARN is moved to the location
> > where a register is read from for checking there.  The other caller
> > explicitly passes an array index which is guaranteed to be within range
> > and so a B43_WARN is not added there.
> > 
> > Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> 
> ACK
> 
> But I'd prefer if we had something like the following
> and use that:
> 
> #define bitrev4(x)	(bitrev8(x) >> 4)
> 
> This way the confusing (confusing to me :) ) shifts in the code would go away.
> I have a hard time realizing that
> bitrev8(x) >> 3
> does actually mean
> bitrev4(x) << 1
> Maybe I'm just stupid, though. :)
> 

You're not, this was only valid because x < 16....if bit 4 could be set
this doesn't work anymore as bitrev8(x) >> 4 would truncate bit 4
before shifting left.  So there was some subtlety here that makes >> 3
ok.

Do you want an incremental patch adding a bitrev4 to phy.c or are you
going to add it?

Harvey


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] b43: use the bitrev helpers rather than rolling a private one
  2008-05-14  0:53   ` Harvey Harrison
@ 2008-05-14  1:03     ` Michael Buesch
  2008-05-14  1:13       ` [PATCHv2] " Harvey Harrison
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Buesch @ 2008-05-14  1:03 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: Andrew Morton, linux-wireless

On Wednesday 14 May 2008 02:53:56 Harvey Harrison wrote:
> On Wed, 2008-05-14 at 01:24 +0200, Michael Buesch wrote:
> > On Tuesday 13 May 2008 21:55:18 Harvey Harrison wrote:
> > > The 4-bit reversal flip_4bit is replaced with the bitrev helper
> > > bitrev8 and a 4-bit shift.  The B43_WARN is moved to the location
> > > where a register is read from for checking there.  The other caller
> > > explicitly passes an array index which is guaranteed to be within range
> > > and so a B43_WARN is not added there.
> > > 
> > > Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> > 
> > ACK
> > 
> > But I'd prefer if we had something like the following
> > and use that:
> > 
> > #define bitrev4(x)	(bitrev8(x) >> 4)
> > 
> > This way the confusing (confusing to me :) ) shifts in the code would go away.
> > I have a hard time realizing that
> > bitrev8(x) >> 3
> > does actually mean
> > bitrev4(x) << 1
> > Maybe I'm just stupid, though. :)
> > 
> 
> You're not, this was only valid because x < 16....if bit 4 could be set
> this doesn't work anymore as bitrev8(x) >> 4 would truncate bit 4
> before shifting left.  So there was some subtlety here that makes >> 3
> ok.

I don't understand. These are all 4 bit values.
The old flip helper enforced this with a B43_WARN_ON().

The >>3 actually is

((bitrev8(x) >> 4) << 1)
which is the same as
(bitrev4(x) << 1)

The <<1 is there, because the hardware wants is this way in the register.
The <<1 is not related to the actual flip operation.

> Do you want an incremental patch adding a bitrev4 to phy.c or are you
> going to add it?

Can you just respin this one instead of doing an incremental one?

-- 
Greetings Michael.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCHv2] b43: use the bitrev helpers rather than rolling a private one
  2008-05-14  1:03     ` Michael Buesch
@ 2008-05-14  1:13       ` Harvey Harrison
  2008-05-14 10:21         ` Michael Buesch
  0 siblings, 1 reply; 7+ messages in thread
From: Harvey Harrison @ 2008-05-14  1:13 UTC (permalink / raw)
  To: Michael Buesch; +Cc: Andrew Morton, linux-wireless

The 4-bit reversal flip_4bit is replaced with the bitrev helper
bitrev8 and a 4-bit shift.  The B43_WARN is moved to the location
where a register is read from for checking there.  The other caller
explicitly passes an array index which is guaranteed to be within range
and so a B43_WARN is not added there.

Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
 drivers/net/wireless/b43/phy.c |   27 ++++++---------------------
 1 files changed, 6 insertions(+), 21 deletions(-)

diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
index de024dc..feea79f 100644
--- a/drivers/net/wireless/b43/phy.c
+++ b/drivers/net/wireless/b43/phy.c
@@ -28,6 +28,7 @@
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/types.h>
+#include <linux/bitrev.h>
 
 #include "b43.h"
 #include "phy.h"
@@ -83,25 +84,9 @@ const u8 b43_radio_channel_codes_bg[] = {
 	72, 84,
 };
 
+#define bitrev4(tmp) (bitrev8(tmp) >> 4)
 static void b43_phy_initg(struct b43_wldev *dev);
 
-/* Reverse the bits of a 4bit value.
- * Example:  1101 is flipped 1011
- */
-static u16 flip_4bit(u16 value)
-{
-	u16 flipped = 0x0000;
-
-	B43_WARN_ON(value & ~0x000F);
-
-	flipped |= (value & 0x0001) << 3;
-	flipped |= (value & 0x0002) << 1;
-	flipped |= (value & 0x0004) >> 1;
-	flipped |= (value & 0x0008) >> 3;
-
-	return flipped;
-}
-
 static void generate_rfatt_list(struct b43_wldev *dev,
 				struct b43_rfatt_list *list)
 {
@@ -3069,13 +3054,13 @@ b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
 		}
 		radio_stacksave(0x0078);
 		tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
-		flipped = flip_4bit(tmp);
+		B43_WARN_ON(tmp > 15);
+		flipped = bitrev4(tmp);
 		if (flipped < 10 && flipped >= 8)
 			flipped = 7;
 		else if (flipped >= 10)
 			flipped -= 3;
-		flipped = flip_4bit(flipped);
-		flipped = (flipped << 1) | 0x0020;
+		flipped = (bitrev4(flipped) << 1) | 0x0020;
 		b43_radio_write16(dev, 0x0078, flipped);
 
 		b43_calc_nrssi_threshold(dev);
@@ -3708,7 +3693,7 @@ u16 b43_radio_init2050(struct b43_wldev *dev)
 	tmp1 >>= 9;
 
 	for (i = 0; i < 16; i++) {
-		radio78 = ((flip_4bit(i) << 1) | 0x20);
+		radio78 = (bitrev4(i) << 1) | 0x0020;
 		b43_radio_write16(dev, 0x78, radio78);
 		udelay(10);
 		for (j = 0; j < 16; j++) {
-- 
1.5.5.1.482.g0f174




^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCHv2] b43: use the bitrev helpers rather than rolling a private one
  2008-05-14  1:13       ` [PATCHv2] " Harvey Harrison
@ 2008-05-14 10:21         ` Michael Buesch
  2008-05-14 10:26           ` Michael Buesch
  0 siblings, 1 reply; 7+ messages in thread
From: Michael Buesch @ 2008-05-14 10:21 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: Andrew Morton, linux-wireless

On Wednesday 14 May 2008 03:13:35 Harvey Harrison wrote:
> The 4-bit reversal flip_4bit is replaced with the bitrev helper
> bitrev8 and a 4-bit shift.  The B43_WARN is moved to the location
> where a register is read from for checking there.  The other caller
> explicitly passes an array index which is guaranteed to be within range
> and so a B43_WARN is not added there.
> 
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>

Reviewed-off-by: Michael Buesch <mb@bu3sch.de>

> ---
>  drivers/net/wireless/b43/phy.c |   27 ++++++---------------------
>  1 files changed, 6 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
> index de024dc..feea79f 100644
> --- a/drivers/net/wireless/b43/phy.c
> +++ b/drivers/net/wireless/b43/phy.c
> @@ -28,6 +28,7 @@
>  #include <linux/delay.h>
>  #include <linux/io.h>
>  #include <linux/types.h>
> +#include <linux/bitrev.h>
>  
>  #include "b43.h"
>  #include "phy.h"
> @@ -83,25 +84,9 @@ const u8 b43_radio_channel_codes_bg[] = {
>  	72, 84,
>  };
>  
> +#define bitrev4(tmp) (bitrev8(tmp) >> 4)
>  static void b43_phy_initg(struct b43_wldev *dev);
>  
> -/* Reverse the bits of a 4bit value.
> - * Example:  1101 is flipped 1011
> - */
> -static u16 flip_4bit(u16 value)
> -{
> -	u16 flipped = 0x0000;
> -
> -	B43_WARN_ON(value & ~0x000F);
> -
> -	flipped |= (value & 0x0001) << 3;
> -	flipped |= (value & 0x0002) << 1;
> -	flipped |= (value & 0x0004) >> 1;
> -	flipped |= (value & 0x0008) >> 3;
> -
> -	return flipped;
> -}
> -
>  static void generate_rfatt_list(struct b43_wldev *dev,
>  				struct b43_rfatt_list *list)
>  {
> @@ -3069,13 +3054,13 @@ b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
>  		}
>  		radio_stacksave(0x0078);
>  		tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
> -		flipped = flip_4bit(tmp);
> +		B43_WARN_ON(tmp > 15);
> +		flipped = bitrev4(tmp);
>  		if (flipped < 10 && flipped >= 8)
>  			flipped = 7;
>  		else if (flipped >= 10)
>  			flipped -= 3;
> -		flipped = flip_4bit(flipped);
> -		flipped = (flipped << 1) | 0x0020;
> +		flipped = (bitrev4(flipped) << 1) | 0x0020;
>  		b43_radio_write16(dev, 0x0078, flipped);
>  
>  		b43_calc_nrssi_threshold(dev);
> @@ -3708,7 +3693,7 @@ u16 b43_radio_init2050(struct b43_wldev *dev)
>  	tmp1 >>= 9;
>  
>  	for (i = 0; i < 16; i++) {
> -		radio78 = ((flip_4bit(i) << 1) | 0x20);
> +		radio78 = (bitrev4(i) << 1) | 0x0020;
>  		b43_radio_write16(dev, 0x78, radio78);
>  		udelay(10);
>  		for (j = 0; j < 16; j++) {



-- 
Greetings Michael.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCHv2] b43: use the bitrev helpers rather than rolling a private one
  2008-05-14 10:21         ` Michael Buesch
@ 2008-05-14 10:26           ` Michael Buesch
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Buesch @ 2008-05-14 10:26 UTC (permalink / raw)
  To: Harvey Harrison; +Cc: Andrew Morton, linux-wireless

On Wednesday 14 May 2008 12:21:00 Michael Buesch wrote:
> On Wednesday 14 May 2008 03:13:35 Harvey Harrison wrote:
> > The 4-bit reversal flip_4bit is replaced with the bitrev helper
> > bitrev8 and a 4-bit shift.  The B43_WARN is moved to the location
> > where a register is read from for checking there.  The other caller
> > explicitly passes an array index which is guaranteed to be within range
> > and so a B43_WARN is not added there.
> > 
> > Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> 
> Reviewed-off-by: Michael Buesch <mb@bu3sch.de>

Reviewed-off bah :D
That's when want to you change a Signed-off-by to a Reviewed-by. ;)

> 
> > ---
> >  drivers/net/wireless/b43/phy.c |   27 ++++++---------------------
> >  1 files changed, 6 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
> > index de024dc..feea79f 100644
> > --- a/drivers/net/wireless/b43/phy.c
> > +++ b/drivers/net/wireless/b43/phy.c
> > @@ -28,6 +28,7 @@
> >  #include <linux/delay.h>
> >  #include <linux/io.h>
> >  #include <linux/types.h>
> > +#include <linux/bitrev.h>
> >  
> >  #include "b43.h"
> >  #include "phy.h"
> > @@ -83,25 +84,9 @@ const u8 b43_radio_channel_codes_bg[] = {
> >  	72, 84,
> >  };
> >  
> > +#define bitrev4(tmp) (bitrev8(tmp) >> 4)
> >  static void b43_phy_initg(struct b43_wldev *dev);
> >  
> > -/* Reverse the bits of a 4bit value.
> > - * Example:  1101 is flipped 1011
> > - */
> > -static u16 flip_4bit(u16 value)
> > -{
> > -	u16 flipped = 0x0000;
> > -
> > -	B43_WARN_ON(value & ~0x000F);
> > -
> > -	flipped |= (value & 0x0001) << 3;
> > -	flipped |= (value & 0x0002) << 1;
> > -	flipped |= (value & 0x0004) >> 1;
> > -	flipped |= (value & 0x0008) >> 3;
> > -
> > -	return flipped;
> > -}
> > -
> >  static void generate_rfatt_list(struct b43_wldev *dev,
> >  				struct b43_rfatt_list *list)
> >  {
> > @@ -3069,13 +3054,13 @@ b43_radio_interference_mitigation_enable(struct b43_wldev *dev, int mode)
> >  		}
> >  		radio_stacksave(0x0078);
> >  		tmp = (b43_radio_read16(dev, 0x0078) & 0x001E);
> > -		flipped = flip_4bit(tmp);
> > +		B43_WARN_ON(tmp > 15);
> > +		flipped = bitrev4(tmp);
> >  		if (flipped < 10 && flipped >= 8)
> >  			flipped = 7;
> >  		else if (flipped >= 10)
> >  			flipped -= 3;
> > -		flipped = flip_4bit(flipped);
> > -		flipped = (flipped << 1) | 0x0020;
> > +		flipped = (bitrev4(flipped) << 1) | 0x0020;
> >  		b43_radio_write16(dev, 0x0078, flipped);
> >  
> >  		b43_calc_nrssi_threshold(dev);
> > @@ -3708,7 +3693,7 @@ u16 b43_radio_init2050(struct b43_wldev *dev)
> >  	tmp1 >>= 9;
> >  
> >  	for (i = 0; i < 16; i++) {
> > -		radio78 = ((flip_4bit(i) << 1) | 0x20);
> > +		radio78 = (bitrev4(i) << 1) | 0x0020;
> >  		b43_radio_write16(dev, 0x78, radio78);
> >  		udelay(10);
> >  		for (j = 0; j < 16; j++) {
> 
> 
> 



-- 
Greetings Michael.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-05-14 10:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-13 19:55 [PATCH] b43: use the bitrev helpers rather than rolling a private one Harvey Harrison
2008-05-13 23:24 ` Michael Buesch
2008-05-14  0:53   ` Harvey Harrison
2008-05-14  1:03     ` Michael Buesch
2008-05-14  1:13       ` [PATCHv2] " Harvey Harrison
2008-05-14 10:21         ` Michael Buesch
2008-05-14 10:26           ` Michael Buesch

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).