Skip to contentSkip to conversation

New inventions in rounding up in catc.c?

PATCH Denis Vlasenko 3 participants 4 messages Sep 24, 2005 – Sep 25, 2005 USB

lore
Share & tools
lore
#0 lore raw
# 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

drivers/usb/net/catc.c renamed from drivers/usb/net/catc.c.org +2 -2
@@ -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);
drivers/usb/net/catc.c renamed from drivers/usb/net/catc.c.org +2 -2
@@ -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);
#1 lore raw

Review

Quoted 5 lines · Denis Vlasenko
		/* F5U011 only does one packet per RX */
		if (catc->is_f5u011)
			break;
(quoted diff) +1 -1
-		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.

#2 lore raw
Quoted 10 lines · Grant Coady

Review

Quoted 5 lines · Denis Vlasenko
		/* F5U011 only does one packet per RX */
		if (catc->is_f5u011)
			break;
(quoted diff) +1 -1
-		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

#3 lore raw
Quoted 12 lines · Denis Vlasenko
Quoted 10 lines · Grant Coady

Review

Quoted 5 lines · Denis Vlasenko
		/* F5U011 only does one packet per RX */
		if (catc->is_f5u011)
			break;
(quoted diff) +1 -1
-		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.

Quoted 7 lines

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.

Signature · 2 lines
Vojtech Pavlik
SuSE Labs, SuSE CR