public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* New inventions in rounding up in catc.c?
@ 2005-09-24 10:43 Denis Vlasenko
  2005-09-24 18:46 ` Grant Coady
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Vlasenko @ 2005-09-24 10:43 UTC (permalink / raw)
  To: Simon Evans, Vojtech Pavlik; +Cc: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1945 bytes --]

# grep '>> 6' -C5 catc.c
                catc->stats.rx_bytes += pkt_len;

                /* F5U011 only does one packet per RX */
                if (catc->is_f5u011)
                        break;
                pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;

        } while (pkt_start - (u8 *) urb->transfer_buffer < urb->actual_length);

        catc->netdev->last_rx = jiffies;

--
        unsigned long flags;
        char *tx_buf;

        spin_lock_irqsave(&catc->tx_lock, flags);

        catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
        tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
        *((u16*)tx_buf) = (catc->is_f5u011) ? cpu_to_be16((u16)skb->len) : cpu_to_le16((u16)skb->len);
        memcpy(tx_buf + 2, skb->data, skb->len);
        catc->tx_ptr += skb->len + 2;

I case I do not miss something, second one rounds tx_ptr up to 64 byte
boundary. It can be done in 2 operations instead of 4.

First one may be the same, but do you really meant pkt_len + 1, not pkt_len - 1?

Patch is below, and also attached (KMail may mangle inline patches).
--
vda

--- linux-2.6.13.org/drivers/usb/net/catc.c.org	Mon Aug 29 02:41:01 2005
+++ linux-2.6.13.org/drivers/usb/net/catc.c	Sat Sep 24 13:35:42 2005
@@ -268,7 +268,7 @@ static void catc_rx_done(struct urb *urb
 		/* F5U011 only does one packet per RX */
 		if (catc->is_f5u011)
 			break;
-		pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
+		pkt_start += ((pkt_len + 2) + 63) & ~63;
 
 	} while (pkt_start - (u8 *) urb->transfer_buffer < urb->actual_length);
 
@@ -417,7 +417,7 @@ static int catc_hard_start_xmit(struct s
 
 	spin_lock_irqsave(&catc->tx_lock, flags);
 
-	catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
+	catc->tx_ptr = (catc->tx_ptr + 63) & ~63;
 	tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
 	*((u16*)tx_buf) = (catc->is_f5u011) ? cpu_to_be16((u16)skb->len) : cpu_to_le16((u16)skb->len);
 	memcpy(tx_buf + 2, skb->data, skb->len);

[-- Attachment #2: catc.patch --]
[-- Type: text/x-diff, Size: 855 bytes --]

--- linux-2.6.13.org/drivers/usb/net/catc.c.org	Mon Aug 29 02:41:01 2005
+++ linux-2.6.13.org/drivers/usb/net/catc.c	Sat Sep 24 13:35:42 2005
@@ -268,7 +268,7 @@ static void catc_rx_done(struct urb *urb
 		/* F5U011 only does one packet per RX */
 		if (catc->is_f5u011)
 			break;
-		pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
+		pkt_start += ((pkt_len + 2) + 63) & ~63;
 
 	} while (pkt_start - (u8 *) urb->transfer_buffer < urb->actual_length);
 
@@ -417,7 +417,7 @@ static int catc_hard_start_xmit(struct s
 
 	spin_lock_irqsave(&catc->tx_lock, flags);
 
-	catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
+	catc->tx_ptr = (catc->tx_ptr + 63) & ~63;
 	tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
 	*((u16*)tx_buf) = (catc->is_f5u011) ? cpu_to_be16((u16)skb->len) : cpu_to_le16((u16)skb->len);
 	memcpy(tx_buf + 2, skb->data, skb->len);

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

* Re: New inventions in rounding up in catc.c?
  2005-09-24 10:43 New inventions in rounding up in catc.c? Denis Vlasenko
@ 2005-09-24 18:46 ` Grant Coady
  2005-09-25 10:43   ` Denis Vlasenko
  0 siblings, 1 reply; 4+ messages in thread
From: Grant Coady @ 2005-09-24 18:46 UTC (permalink / raw)
  To: Denis Vlasenko; +Cc: Simon Evans, Vojtech Pavlik, linux-kernel

On Sat, 24 Sep 2005 13:43:42 +0300, Denis Vlasenko <vda@ilport.com.ua> wrote:
> 		/* F5U011 only does one packet per RX */
> 		if (catc->is_f5u011)
> 			break;
>-		pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
>+		pkt_start += ((pkt_len + 2) + 63) & ~63;

  		pkt_start += ((pkt_len + 1) + 64) & ~63;

Seems more clear to me.

Grant.


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

* Re: New inventions in rounding up in catc.c?
  2005-09-24 18:46 ` Grant Coady
@ 2005-09-25 10:43   ` Denis Vlasenko
  2005-09-25 20:54     ` Vojtech Pavlik
  0 siblings, 1 reply; 4+ messages in thread
From: Denis Vlasenko @ 2005-09-25 10:43 UTC (permalink / raw)
  To: Grant Coady; +Cc: Simon Evans, Vojtech Pavlik, linux-kernel

On Saturday 24 September 2005 21:46, Grant Coady wrote:
> On Sat, 24 Sep 2005 13:43:42 +0300, Denis Vlasenko <vda@ilport.com.ua> wrote:
> > 		/* F5U011 only does one packet per RX */
> > 		if (catc->is_f5u011)
> > 			break;
> >-		pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
> >+		pkt_start += ((pkt_len + 2) + 63) & ~63;
> 
>   		pkt_start += ((pkt_len + 1) + 64) & ~63;
> 
> Seems more clear to me.

Why?

((pkt_len + 2) + 63) & ~63 is "add 2 and round up to next 64".
((pkt_len + 1) + 64) & ~63 is "???!"

It's strange code anyway, I hope maintainer can clarify what's going on.
(I suspect it was intended to be pkt_len - 1, not +, in the first place)
--
vda

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

* Re: New inventions in rounding up in catc.c?
  2005-09-25 10:43   ` Denis Vlasenko
@ 2005-09-25 20:54     ` Vojtech Pavlik
  0 siblings, 0 replies; 4+ messages in thread
From: Vojtech Pavlik @ 2005-09-25 20:54 UTC (permalink / raw)
  To: Denis Vlasenko; +Cc: Grant Coady, Simon Evans, linux-kernel

On Sun, Sep 25, 2005 at 01:43:47PM +0300, Denis Vlasenko wrote:
> On Saturday 24 September 2005 21:46, Grant Coady wrote:
> > On Sat, 24 Sep 2005 13:43:42 +0300, Denis Vlasenko <vda@ilport.com.ua> wrote:
> > > 		/* F5U011 only does one packet per RX */
> > > 		if (catc->is_f5u011)
> > > 			break;
> > >-		pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
> > >+		pkt_start += ((pkt_len + 2) + 63) & ~63;
> > 
> >   		pkt_start += ((pkt_len + 1) + 64) & ~63;
> > 
> > Seems more clear to me.
> 
> Why?
> 
> ((pkt_len + 2) + 63) & ~63 is "add 2 and round up to next 64".
> ((pkt_len + 1) + 64) & ~63 is "???!"
> 
> It's strange code anyway, I hope maintainer can clarify what's going on.
> (I suspect it was intended to be pkt_len - 1, not +, in the first place)
 
Honestly, I don't remember at all. I'll try to find the (very old) docs
I have for the chip.

-- 
Vojtech Pavlik
SuSE Labs, SuSE CR

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

end of thread, other threads:[~2005-09-25 20:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-24 10:43 New inventions in rounding up in catc.c? Denis Vlasenko
2005-09-24 18:46 ` Grant Coady
2005-09-25 10:43   ` Denis Vlasenko
2005-09-25 20:54     ` Vojtech Pavlik

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