mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFC] bmac:change to use bitrev8() generic function
@ 2015-08-10  9:53 yalin wang
  2015-08-10 11:49 ` Tobias Klauser
  0 siblings, 1 reply; 5+ messages in thread
From: yalin wang @ 2015-08-10  9:53 UTC (permalink / raw)
  To: fabf, david, yalin.wang2010, davem, benh, netdev, open list

This change to use generic bitrev8() for bmac driver.

Signed-off-by: yalin wang <yalin.wang2010@gmail.com>
---
 drivers/net/ethernet/apple/bmac.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/apple/bmac.c b/drivers/net/ethernet/apple/bmac.c
index a65d7a6..e749747 100644
--- a/drivers/net/ethernet/apple/bmac.c
+++ b/drivers/net/ethernet/apple/bmac.c
@@ -22,6 +22,7 @@
 #include <linux/bitrev.h>
 #include <linux/ethtool.h>
 #include <linux/slab.h>
+#include <linux/bitrev.h>
 #include <asm/prom.h>
 #include <asm/dbdma.h>
 #include <asm/io.h>
@@ -805,18 +806,6 @@ static irqreturn_t bmac_txdma_intr(int irq, void *dev_id)
 }
 
 #ifndef SUNHME_MULTICAST
-/* Real fast bit-reversal algorithm, 6-bit values */
-static int reverse6[64] = {
-	0x0,0x20,0x10,0x30,0x8,0x28,0x18,0x38,
-	0x4,0x24,0x14,0x34,0xc,0x2c,0x1c,0x3c,
-	0x2,0x22,0x12,0x32,0xa,0x2a,0x1a,0x3a,
-	0x6,0x26,0x16,0x36,0xe,0x2e,0x1e,0x3e,
-	0x1,0x21,0x11,0x31,0x9,0x29,0x19,0x39,
-	0x5,0x25,0x15,0x35,0xd,0x2d,0x1d,0x3d,
-	0x3,0x23,0x13,0x33,0xb,0x2b,0x1b,0x3b,
-	0x7,0x27,0x17,0x37,0xf,0x2f,0x1f,0x3f
-};
-
 static unsigned int
 crc416(unsigned int curval, unsigned short nxtval)
 {
@@ -871,7 +860,7 @@ bmac_addhash(struct bmac_data *bp, unsigned char *addr)
 
 	if (!(*addr)) return;
 	crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */
-	crc = reverse6[crc];	/* Hyperfast bit-reversing algorithm */
+	crc = bitrev8((u8)crc);
 	if (bp->hash_use_count[crc]++) return; /* This bit is already set */
 	mask = crc % 16;
 	mask = (unsigned char)1 << mask;
@@ -886,7 +875,7 @@ bmac_removehash(struct bmac_data *bp, unsigned char *addr)
 
 	/* Now, delete the address from the filter copy, as indicated */
 	crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */
-	crc = reverse6[crc];	/* Hyperfast bit-reversing algorithm */
+	crc = bitrev8((u8)crc);
 	if (bp->hash_use_count[crc] == 0) return; /* That bit wasn't in use! */
 	if (--bp->hash_use_count[crc]) return; /* That bit is still in use */
 	mask = crc % 16;
-- 
1.9.1

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

* Re: [RFC] bmac:change to use bitrev8() generic function
  2015-08-10  9:53 [RFC] bmac:change to use bitrev8() generic function yalin wang
@ 2015-08-10 11:49 ` Tobias Klauser
  2015-08-10 12:02   ` David Laight
  0 siblings, 1 reply; 5+ messages in thread
From: Tobias Klauser @ 2015-08-10 11:49 UTC (permalink / raw)
  To: yalin wang; +Cc: fabf, david, davem, benh, netdev, open list

On 2015-08-10 at 11:53:41 +0200, yalin wang <yalin.wang2010@gmail.com> wrote:
> This change to use generic bitrev8() for bmac driver.
> 
> Signed-off-by: yalin wang <yalin.wang2010@gmail.com>
> ---
>  drivers/net/ethernet/apple/bmac.c | 17 +++--------------
>  1 file changed, 3 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/net/ethernet/apple/bmac.c b/drivers/net/ethernet/apple/bmac.c
> index a65d7a6..e749747 100644
> --- a/drivers/net/ethernet/apple/bmac.c
> +++ b/drivers/net/ethernet/apple/bmac.c
> @@ -22,6 +22,7 @@
>  #include <linux/bitrev.h>
>  #include <linux/ethtool.h>
>  #include <linux/slab.h>
> +#include <linux/bitrev.h>
>  #include <asm/prom.h>
>  #include <asm/dbdma.h>
>  #include <asm/io.h>
> @@ -805,18 +806,6 @@ static irqreturn_t bmac_txdma_intr(int irq, void *dev_id)
>  }
>  
>  #ifndef SUNHME_MULTICAST
> -/* Real fast bit-reversal algorithm, 6-bit values */
> -static int reverse6[64] = {
> -	0x0,0x20,0x10,0x30,0x8,0x28,0x18,0x38,
> -	0x4,0x24,0x14,0x34,0xc,0x2c,0x1c,0x3c,
> -	0x2,0x22,0x12,0x32,0xa,0x2a,0x1a,0x3a,
> -	0x6,0x26,0x16,0x36,0xe,0x2e,0x1e,0x3e,
> -	0x1,0x21,0x11,0x31,0x9,0x29,0x19,0x39,
> -	0x5,0x25,0x15,0x35,0xd,0x2d,0x1d,0x3d,
> -	0x3,0x23,0x13,0x33,0xb,0x2b,0x1b,0x3b,
> -	0x7,0x27,0x17,0x37,0xf,0x2f,0x1f,0x3f
> -};
> -
>  static unsigned int
>  crc416(unsigned int curval, unsigned short nxtval)
>  {
> @@ -871,7 +860,7 @@ bmac_addhash(struct bmac_data *bp, unsigned char *addr)
>  
>  	if (!(*addr)) return;
>  	crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */
> -	crc = reverse6[crc];	/* Hyperfast bit-reversing algorithm */
> +	crc = bitrev8((u8)crc);

No, this won't work. reverse6 works on 6 bit values, while bitrev8 works
on 8bit values, e.g. reverse6[1] = 0x20, while bitrev8(1) = 0x80

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

* RE: [RFC] bmac:change to use bitrev8() generic function
  2015-08-10 11:49 ` Tobias Klauser
@ 2015-08-10 12:02   ` David Laight
  2015-08-11  2:06     ` yalin wang
  0 siblings, 1 reply; 5+ messages in thread
From: David Laight @ 2015-08-10 12:02 UTC (permalink / raw)
  To: 'Tobias Klauser', yalin wang
  Cc: fabf, david, davem, benh, netdev, open list

> From: Tobias Klauser
> Sent: 10 August 2015 12:49
> On 2015-08-10 at 11:53:41 +0200, yalin wang <yalin.wang2010@gmail.com> wrote:
> > This change to use generic bitrev8() for bmac driver.
...
> > @@ -871,7 +860,7 @@ bmac_addhash(struct bmac_data *bp, unsigned char *addr)
> >
> >  	if (!(*addr)) return;
> >  	crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */

Why not *((u8 *)addr + 1) & 0x3f

> > -	crc = reverse6[crc];	/* Hyperfast bit-reversing algorithm */
> > +	crc = bitrev8((u8)crc);
> 
> No, this won't work. reverse6 works on 6 bit values, while bitrev8 works
> on 8bit values, e.g. reverse6[1] = 0x20, while bitrev8(1) = 0x80

You could use bitrev8(n) >> 2.

But that is a 'strange' map of a 7-bit value to a 6-bit one.

I thought it was more common for ethernet hardware to use the
value of the crc register after all 6 bytes of the mac address
had been processed.

	David


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

* Re: [RFC] bmac:change to use bitrev8() generic function
  2015-08-10 12:02   ` David Laight
@ 2015-08-11  2:06     ` yalin wang
  2015-08-11  2:28       ` [RFC V2] " yalin wang
  0 siblings, 1 reply; 5+ messages in thread
From: yalin wang @ 2015-08-11  2:06 UTC (permalink / raw)
  To: David Laight; +Cc: Tobias Klauser, fabf, david, davem, benh, netdev, open list


> On Aug 10, 2015, at 20:02, David Laight <David.Laight@ACULAB.COM> wrote:
> 
>> From: Tobias Klauser
>> Sent: 10 August 2015 12:49
>> On 2015-08-10 at 11:53:41 +0200, yalin wang <yalin.wang2010@gmail.com> wrote:
>>> This change to use generic bitrev8() for bmac driver.
> ...
>>> @@ -871,7 +860,7 @@ bmac_addhash(struct bmac_data *bp, unsigned char *addr)
>>> 
>>> 	if (!(*addr)) return;
>>> 	crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */
> 
> Why not *((u8 *)addr + 1) & 0x3f
> 
>>> -	crc = reverse6[crc];	/* Hyperfast bit-reversing algorithm */
>>> +	crc = bitrev8((u8)crc);
>> 
>> No, this won't work. reverse6 works on 6 bit values, while bitrev8 works
>> on 8bit values, e.g. reverse6[1] = 0x20, while bitrev8(1) = 0x80
> 
> You could use bitrev8(n) >> 2.
> 
> But that is a 'strange' map of a 7-bit value to a 6-bit one.
> 
> I thought it was more common for ethernet hardware to use the
> value of the crc register after all 6 bytes of the mac address
> had been processed.
oh, my mistake, i will change it in V2 for review.

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

* [RFC V2] bmac:change to use bitrev8() generic function
  2015-08-11  2:06     ` yalin wang
@ 2015-08-11  2:28       ` yalin wang
  0 siblings, 0 replies; 5+ messages in thread
From: yalin wang @ 2015-08-11  2:28 UTC (permalink / raw)
  To: David Laight; +Cc: Tobias Klauser, fabf, david, davem, benh, netdev, open list

This change to use generic bitrev8() for bmac driver.

Signed-off-by: yalin wang <yalin.wang2010@gmail.com>
---
 drivers/net/ethernet/apple/bmac.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/net/ethernet/apple/bmac.c b/drivers/net/ethernet/apple/bmac.c
index a65d7a6..7f7a398 100644
--- a/drivers/net/ethernet/apple/bmac.c
+++ b/drivers/net/ethernet/apple/bmac.c
@@ -22,6 +22,7 @@
 #include <linux/bitrev.h>
 #include <linux/ethtool.h>
 #include <linux/slab.h>
+#include <linux/bitrev.h>
 #include <asm/prom.h>
 #include <asm/dbdma.h>
 #include <asm/io.h>
@@ -805,18 +806,6 @@ static irqreturn_t bmac_txdma_intr(int irq, void *dev_id)
 }
 
 #ifndef SUNHME_MULTICAST
-/* Real fast bit-reversal algorithm, 6-bit values */
-static int reverse6[64] = {
-	0x0,0x20,0x10,0x30,0x8,0x28,0x18,0x38,
-	0x4,0x24,0x14,0x34,0xc,0x2c,0x1c,0x3c,
-	0x2,0x22,0x12,0x32,0xa,0x2a,0x1a,0x3a,
-	0x6,0x26,0x16,0x36,0xe,0x2e,0x1e,0x3e,
-	0x1,0x21,0x11,0x31,0x9,0x29,0x19,0x39,
-	0x5,0x25,0x15,0x35,0xd,0x2d,0x1d,0x3d,
-	0x3,0x23,0x13,0x33,0xb,0x2b,0x1b,0x3b,
-	0x7,0x27,0x17,0x37,0xf,0x2f,0x1f,0x3f
-};
-
 static unsigned int
 crc416(unsigned int curval, unsigned short nxtval)
 {
@@ -871,7 +860,7 @@ bmac_addhash(struct bmac_data *bp, unsigned char *addr)
 
 	if (!(*addr)) return;
 	crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */
-	crc = reverse6[crc];	/* Hyperfast bit-reversing algorithm */
+	crc = bitrev8((u8)crc) >> 2;
 	if (bp->hash_use_count[crc]++) return; /* This bit is already set */
 	mask = crc % 16;
 	mask = (unsigned char)1 << mask;
@@ -886,7 +875,7 @@ bmac_removehash(struct bmac_data *bp, unsigned char *addr)
 
 	/* Now, delete the address from the filter copy, as indicated */
 	crc = bmac_crc((unsigned short *)addr) & 0x3f; /* Big-endian alert! */
-	crc = reverse6[crc];	/* Hyperfast bit-reversing algorithm */
+	crc = bitrev8((u8)crc) >> 2;
 	if (bp->hash_use_count[crc] == 0) return; /* That bit wasn't in use! */
 	if (--bp->hash_use_count[crc]) return; /* That bit is still in use */
 	mask = crc % 16;
-- 
1.9.1

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

end of thread, other threads:[~2015-08-11  2:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-10  9:53 [RFC] bmac:change to use bitrev8() generic function yalin wang
2015-08-10 11:49 ` Tobias Klauser
2015-08-10 12:02   ` David Laight
2015-08-11  2:06     ` yalin wang
2015-08-11  2:28       ` [RFC V2] " yalin wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®