patch-2.4.20 linux-2.4.20/drivers/usb/catc.c

Next file: linux-2.4.20/drivers/usb/dabusb.c
Previous file: linux-2.4.20/drivers/usb/brlvger.c
Back to the patch index
Back to the overall index

diff -urN linux-2.4.19/drivers/usb/catc.c linux-2.4.20/drivers/usb/catc.c
@@ -7,6 +7,9 @@
  *
  *  Based on the work of
  *		Donald Becker
+ * 
+ *  Old chipset support added by Simon Evans <spse@secret.org.uk> 2002
+ *    - adds support for Belkin F5U011
  */
 
 /*
@@ -69,6 +72,7 @@
 #define RX_MAX_BURST		15	/* Max packets per rx buffer (> 0, < 16) */
 #define TX_MAX_BURST		15	/* Max full sized packets per tx buffer (> 0) */
 #define CTRL_QUEUE		16	/* Max control requests in flight (power of two) */
+#define RX_PKT_SZ		1600	/* Max size of receive packet for F5U011 */
 
 /*
  * Control requests.
@@ -79,6 +83,7 @@
 	GetMac =	0xf2,
 	Reset =		0xf4,
 	SetMac =	0xf5,
+	SetRxMode =     0xf5,  /* F5U011 only */
 	WriteROM =	0xf8,
 	SetReg =	0xfa,
 	GetReg =	0xfb,
@@ -126,6 +131,7 @@
 	RxForceOK =	0x04,
 	RxMultiCast =	0x08,
 	RxPromisc =	0x10,
+	AltRxPromisc =  0x20, /* F5U011 uses different bit */
 };
 
 enum led_values {
@@ -136,6 +142,12 @@
 	LEDLink =	0x08,
 };
 
+enum link_status {
+	LinkNoChange = 0,
+	LinkGood     = 1,
+	LinkBad      = 2
+};
+
 /*
  * The catc struct.
  */
@@ -159,7 +171,7 @@
 	u8 rx_buf[RX_MAX_BURST * (PKT_SZ + 2)];
 	u8 irq_buf[2];
 	u8 ctrl_buf[64];
-	devrequest ctrl_dr;
+	struct usb_ctrlrequest ctrl_dr;
 
 	struct timer_list timer;
 	u8 stats_buf[8];
@@ -179,6 +191,10 @@
 	} ctrl_queue[CTRL_QUEUE];
 
 	struct urb tx_urb, rx_urb, irq_urb, ctrl_urb;
+
+	u8 is_f5u011;	/* Set if device is an F5U011 */
+	u8 rxmode[2];	/* Used for F5U011 */
+	atomic_t recq_sz; /* Used for F5U011 - counter of waiting rx packets */
 };
 
 /*
@@ -192,6 +208,10 @@
 #define catc_write_mem(catc, addr, buf, size)		catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
 #define catc_read_mem(catc, addr, buf, size)		catc_ctrl_msg(catc, USB_DIR_IN,  ReadMem, 0, addr, buf, size)
 
+#define f5u011_rxmode(catc, rxmode)			catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
+#define f5u011_rxmode_async(catc, rxmode)		catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
+#define f5u011_mchash_async(catc, hash)			catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
+
 #define catc_set_reg_async(catc, reg, val)		catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
 #define catc_get_reg_async(catc, reg, cb)		catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
 #define catc_write_mem_async(catc, addr, buf, size)	catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
@@ -205,9 +225,12 @@
 	struct catc *catc = urb->context;
 	u8 *pkt_start = urb->transfer_buffer;
 	struct sk_buff *skb;
-	int pkt_len;
+	int pkt_len, pkt_offset = 0;
 
-	clear_bit(RX_RUNNING, &catc->flags);
+	if (!catc->is_f5u011) {
+		clear_bit(RX_RUNNING, &catc->flags);
+		pkt_offset = 2;
+	}
 
 	if (urb->status) {
 		dbg("rx_done, status %d, length %d", urb->status, urb->actual_length);
@@ -215,19 +238,22 @@
 	}
 
 	do {
-		pkt_len = le16_to_cpup((u16*)pkt_start);
-
-		if (pkt_len > urb->actual_length) {
-			catc->stats.rx_length_errors++;
-			catc->stats.rx_errors++;
-			break;
+		if(!catc->is_f5u011) {
+			pkt_len = le16_to_cpup((u16*)pkt_start);
+			if (pkt_len > urb->actual_length) {
+				catc->stats.rx_length_errors++;
+				catc->stats.rx_errors++;
+				break;
+			}
+		} else {
+			pkt_len = urb->actual_length;
 		}
 
 		if (!(skb = dev_alloc_skb(pkt_len)))
 			return;
 
 		skb->dev = catc->netdev;
-		eth_copy_and_sum(skb, pkt_start + 2, pkt_len, 0);
+		eth_copy_and_sum(skb, pkt_start + pkt_offset, pkt_len, 0);
 		skb_put(skb, pkt_len);
 
 		skb->protocol = eth_type_trans(skb, catc->netdev);
@@ -236,11 +262,28 @@
 		catc->stats.rx_packets++;
 		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;
+
+	if (catc->is_f5u011) {
+		if (atomic_read(&catc->recq_sz)) {
+			int status;
+			atomic_dec(&catc->recq_sz);
+			dbg("getting extra packet");
+			urb->dev = catc->usbdev;
+			if ((status = usb_submit_urb(urb)) < 0) {
+				dbg("submit(rx_urb) status %d", status);
+			}
+		} else {
+			clear_bit(RX_RUNNING, &catc->flags);
+		}
+	}
 }
 
 static void catc_irq_done(struct urb *urb)
@@ -248,29 +291,48 @@
 	struct catc *catc = urb->context;
 	u8 *data = urb->transfer_buffer;
 	int status;
+	unsigned int hasdata = 0, linksts = LinkNoChange;
+
+	if (!catc->is_f5u011) {
+		hasdata = data[1] & 0x80;
+		if (data[1] & 0x40)
+			linksts = LinkGood;
+		else if (data[1] & 0x20)
+			linksts = LinkBad;
+	} else {
+		hasdata = (unsigned int)(be16_to_cpup((u16*)data) & 0x0fff);
+		if (data[0] == 0x90)
+			linksts = LinkGood;
+		else if (data[0] == 0xA0)
+			linksts = LinkBad;
+	}
 
 	if (urb->status) {
 		dbg("irq_done, status %d, data %02x %02x.", urb->status, data[0], data[1]);
 		return;
 	}
 
-	if ((data[1] & 0x80) && !test_and_set_bit(RX_RUNNING, &catc->flags)) {
-		catc->rx_urb.dev = catc->usbdev;
-		if ((status = usb_submit_urb(&catc->rx_urb)) < 0) {
-			err("submit(rx_urb) status %d", status);
-			return;
-		} 
-	}
-
-	if (data[1] & 0x40) {
+	if (linksts == LinkGood) {
 		netif_carrier_on(catc->netdev);
 		dbg("link ok");
 	}
 
-	if (data[1] & 0x20) {
+	if (linksts == LinkBad) {
 		netif_carrier_off(catc->netdev);
 		dbg("link bad");
 	}
+
+	if (hasdata) {
+		if (test_and_set_bit(RX_RUNNING, &catc->flags)) {
+			if (catc->is_f5u011)
+				atomic_inc(&catc->recq_sz);
+		} else {
+			catc->rx_urb.dev = catc->usbdev;
+			if ((status = usb_submit_urb(&catc->rx_urb)) < 0) {
+				err("submit(rx_urb) status %d", status);
+			}
+		} 
+	}
 }
 
 /*
@@ -281,6 +343,9 @@
 {
 	int status;
 
+	if (catc->is_f5u011)
+		catc->tx_ptr = (catc->tx_ptr + 63) & ~63;
+
 	catc->tx_urb.transfer_buffer_length = catc->tx_ptr;
 	catc->tx_urb.transfer_buffer = catc->tx_buf[catc->tx_idx];
 	catc->tx_urb.dev = catc->usbdev;
@@ -337,14 +402,16 @@
 
 	catc->tx_ptr = (((catc->tx_ptr - 1) >> 6) + 1) << 6;
 	tx_buf = catc->tx_buf[catc->tx_idx] + catc->tx_ptr;
-	*((u16*)tx_buf) = cpu_to_le16((u16)skb->len);
+	*((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;
 
 	if (!test_and_set_bit(TX_RUNNING, &catc->flags))
 		catc_tx_run(catc);
 
-	if (catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2)))
+	if ((catc->is_f5u011 && catc->tx_ptr)
+	     || (catc->tx_ptr >= ((TX_MAX_BURST - 1) * (PKT_SZ + 2))))
 		netif_stop_queue(netdev);
 
 	spin_unlock_irqrestore(&catc->tx_lock, flags);
@@ -383,14 +450,14 @@
 	struct ctrl_queue *q = catc->ctrl_queue + catc->ctrl_tail;
 	struct usb_device *usbdev = catc->usbdev;
 	struct urb *urb = &catc->ctrl_urb;
-	devrequest *dr = &catc->ctrl_dr;
+	struct usb_ctrlrequest *dr = &catc->ctrl_dr;
 	int status;
 
-	dr->request = q->request;
-	dr->requesttype = 0x40 | q->dir;
-	dr->value = cpu_to_le16(q->value);
-	dr->index = cpu_to_le16(q->index);
-	dr->length = cpu_to_le16(q->len);
+	dr->bRequest = q->request;
+	dr->bRequestType = 0x40 | q->dir;
+	dr->wValue = cpu_to_le16(q->value);
+	dr->wIndex = cpu_to_le16(q->index);
+	dr->wLength = cpu_to_le16(q->len);
 
         urb->pipe = q->dir ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0);
 	urb->transfer_buffer_length = q->len;
@@ -529,15 +596,20 @@
  * Receive modes. Broadcast, Multicast, Promisc.
  */
 
-static void catc_multicast(unsigned char *addr, u8 *multicast)
+static inline u32 ether_crc_le(int cnt, unsigned char *addr)
 {
 	unsigned int crc = 0xffffffff;
 	u8 byte, idx, bit;
-
-        for (idx = 0; idx < 6; idx++)
+	
+        for (idx = 0; idx < cnt; idx++)
                 for (byte = *addr++, bit = 0; bit < 8; bit++, byte >>= 1)
                         crc = (crc >> 1) ^ (((crc ^ byte) & 1) ? 0xedb88320U : 0);
+	return crc;
+}
 
+static void catc_multicast(unsigned char *addr, u8 *multicast)
+{
+	unsigned int crc = ether_crc_le(6, addr);
 	multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
 }
 
@@ -557,17 +629,33 @@
 
 	if (netdev->flags & IFF_PROMISC) {
 		memset(catc->multicast, 0xff, 64);
-		rx |= RxPromisc;
+		rx |= (!catc->is_f5u011) ? RxPromisc : AltRxPromisc;
 	} 
 
-	if (netdev->flags & IFF_ALLMULTI)
+	if (netdev->flags & IFF_ALLMULTI) {
 		memset(catc->multicast, 0xff, 64);
-
-	for (i = 0, mc = netdev->mc_list; mc && i < netdev->mc_count; i++, mc = mc->next)
-		catc_multicast(mc->dmi_addr, catc->multicast);
-
-	catc_set_reg_async(catc, RxUnit, rx);
-	catc_write_mem_async(catc, 0xfa80, catc->multicast, 64);
+	} else {
+		for (i = 0, mc = netdev->mc_list; mc && i < netdev->mc_count; i++, mc = mc->next) {
+			u32 crc = ether_crc_le(6, mc->dmi_addr);
+			if (!catc->is_f5u011) {
+				catc->multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
+			} else {
+				catc->multicast[7-(crc >> 29)] |= 1 << ((crc >> 26) & 7);
+			}
+		}
+	}
+	if (!catc->is_f5u011) {
+		catc_set_reg_async(catc, RxUnit, rx);
+		catc_write_mem_async(catc, 0xfa80, catc->multicast, 64);
+	} else {
+		f5u011_mchash_async(catc, catc->multicast);
+		if (catc->rxmode[0] != rx) {
+			catc->rxmode[0] = rx;
+			dbg("Setting RX mode to %2.2X %2.2X", catc->rxmode[0],
+			    catc->rxmode[1]);
+			f5u011_rxmode_async(catc, catc->rxmode);
+		}
+	}
 }
 
 /*
@@ -594,6 +682,30 @@
                         return -EFAULT;
                 return 0;
         }
+
+	/* get settings */
+	case ETHTOOL_GSET:
+		if (catc->is_f5u011) {
+			struct ethtool_cmd ecmd = { 
+				ETHTOOL_GSET, 
+				SUPPORTED_10baseT_Half | SUPPORTED_TP, 
+				ADVERTISED_10baseT_Half | ADVERTISED_TP, 
+				SPEED_10, 
+				DUPLEX_HALF, 
+				PORT_TP, 
+				0, 
+				XCVR_INTERNAL, 
+				AUTONEG_DISABLE, 
+				1, 
+				1 
+			};
+			if (copy_to_user(useraddr, &ecmd, sizeof(ecmd)))
+				return -EFAULT;
+			return 0;
+		} else {
+			return -EOPNOTSUPP;
+		}
+
         /* get link status */
         case ETHTOOL_GLINK: {
                 struct ethtool_value edata = {ETHTOOL_GLINK};
@@ -635,7 +747,8 @@
 
 	netif_start_queue(netdev);
 
-	mod_timer(&catc->timer, jiffies + STATS_UPDATE);
+	if (!catc->is_f5u011)
+		mod_timer(&catc->timer, jiffies + STATS_UPDATE);
 
 	return 0;
 }
@@ -646,7 +759,8 @@
 
 	netif_stop_queue(netdev);
 
-	del_timer_sync(&catc->timer);
+	if (!catc->is_f5u011)
+		del_timer_sync(&catc->timer);
 
 	usb_unlink_urb(&catc->rx_urb);
 	usb_unlink_urb(&catc->tx_urb);
@@ -665,7 +779,7 @@
 	struct net_device *netdev;
 	struct catc *catc;
 	u8 broadcast[6];
-	int i;
+	int i, pktsz;
 
 	if (usb_set_interface(usbdev, ifnum, 1)) {
                 err("Can't set altsetting 1.");
@@ -704,6 +818,20 @@
 	catc->timer.data = (long) catc;
 	catc->timer.function = catc_stats_timer;
 
+	/* The F5U011 has the same vendor/product as the netmate 
+	 *  but a device version of 0x130
+	 */
+	if (usbdev->descriptor.idVendor == 0x0423 && 
+	    usbdev->descriptor.idProduct == 0xa &&
+	    catc->usbdev->descriptor.bcdDevice == 0x0130) {
+		dbg("Testing for f5u011");
+		catc->is_f5u011 = 1;
+		atomic_set(&catc->recq_sz, 0);
+		pktsz = RX_PKT_SZ;
+	} else {
+		pktsz = RX_MAX_BURST * (PKT_SZ + 2);
+	}
+
 	FILL_CONTROL_URB(&catc->ctrl_urb, usbdev, usb_sndctrlpipe(usbdev, 0),
 		NULL, NULL, 0, catc_ctrl_done, catc);
 
@@ -711,20 +839,21 @@
 		NULL, 0, catc_tx_done, catc);
 
 	FILL_BULK_URB(&catc->rx_urb, usbdev, usb_rcvbulkpipe(usbdev, 1),
-		catc->rx_buf, RX_MAX_BURST * (PKT_SZ + 2), catc_rx_done, catc);
+		catc->rx_buf, pktsz, catc_rx_done, catc);
 
 	FILL_INT_URB(&catc->irq_urb, usbdev, usb_rcvintpipe(usbdev, 2),
                 catc->irq_buf, 2, catc_irq_done, catc, 1);
 
-	dbg("Checking memory size\n");
-
-	i = 0x12345678;
-	catc_write_mem(catc, 0x7a80, &i, 4);
-	i = 0x87654321;	
-	catc_write_mem(catc, 0xfa80, &i, 4);
-	catc_read_mem(catc, 0x7a80, &i, 4);
+	if (!catc->is_f5u011) {
+		dbg("Checking memory size\n");
 
-	switch (i) {
+		i = 0x12345678;
+		catc_write_mem(catc, 0x7a80, &i, 4);
+		i = 0x87654321;	
+		catc_write_mem(catc, 0xfa80, &i, 4);
+		catc_read_mem(catc, 0x7a80, &i, 4);
+	  
+		switch (i) {
 		case 0x12345678:
 			catc_set_reg(catc, TxBufCount, 8);
 			catc_set_reg(catc, RxBufCount, 32);
@@ -737,44 +866,52 @@
 			catc_set_reg(catc, RxBufCount, 16);
 			dbg("32k Memory\n");
 			break;
+		}
+	  
+		dbg("Getting MAC from SEEROM.");
+	  
+		catc_get_mac(catc, netdev->dev_addr);
+		
+		dbg("Setting MAC into registers.");
+	  
+		for (i = 0; i < 6; i++)
+			catc_set_reg(catc, StationAddr0 - i, netdev->dev_addr[i]);
+		
+		dbg("Filling the multicast list.");
+	  
+		memset(broadcast, 0xff, 6);
+		catc_multicast(broadcast, catc->multicast);
+		catc_multicast(netdev->dev_addr, catc->multicast);
+		catc_write_mem(catc, 0xfa80, catc->multicast, 64);
+		
+		dbg("Clearing error counters.");
+		
+		for (i = 0; i < 8; i++)
+			catc_set_reg(catc, EthStats + i, 0);
+		catc->last_stats = jiffies;
+		
+		dbg("Enabling.");
+		
+		catc_set_reg(catc, MaxBurst, RX_MAX_BURST);
+		catc_set_reg(catc, OpModes, OpTxMerge | OpRxMerge | OpLenInclude | Op3MemWaits);
+		catc_set_reg(catc, LEDCtrl, LEDLink);
+		catc_set_reg(catc, RxUnit, RxEnable | RxPolarity | RxMultiCast);
+	} else {
+		dbg("Performing reset\n");
+		catc_reset(catc);
+		catc_get_mac(catc, netdev->dev_addr);
+		
+		dbg("Setting RX Mode");
+		catc->rxmode[0] = RxEnable | RxPolarity | RxMultiCast;
+		catc->rxmode[1] = 0;
+		f5u011_rxmode(catc, catc->rxmode);
 	}
-
-	dbg("Getting MAC from SEEROM.");
-
-	catc_get_mac(catc, netdev->dev_addr);
-
-	dbg("Setting MAC into registers.");
-
-	for (i = 0; i < 6; i++)
-		catc_set_reg(catc, StationAddr0 - i, netdev->dev_addr[i]);
-
-	dbg("Filling the multicast list.");
-
-	memset(broadcast, 0xff, 8);
-	catc_multicast(broadcast, catc->multicast);
-	catc_multicast(netdev->dev_addr, catc->multicast);
-	catc_write_mem(catc, 0xfa80, catc->multicast, 64);
-
-	dbg("Clearing error counters.");
-
-	for (i = 0; i < 8; i++)
-		catc_set_reg(catc, EthStats + i, 0);
-	catc->last_stats = jiffies;
-
-	dbg("Enabling.");
-
-	catc_set_reg(catc, MaxBurst, RX_MAX_BURST);
-	catc_set_reg(catc, OpModes, OpTxMerge | OpRxMerge | OpLenInclude | Op3MemWaits);
-	catc_set_reg(catc, LEDCtrl, LEDLink);
-	catc_set_reg(catc, RxUnit, RxEnable | RxPolarity | RxMultiCast);
-
 	dbg("Init done.");
-
-	printk(KERN_INFO "%s: CATC EL1210A NetMate USB Ethernet at usb%d:%d.%d, ",
-		netdev->name, usbdev->bus->busnum, usbdev->devnum, ifnum);
+	printk(KERN_INFO "%s: %s USB Ethernet at usb%d:%d.%d, ",
+	       netdev->name, (catc->is_f5u011) ? "Belkin F5U011" : "CATC EL1210A NetMate",
+	       usbdev->bus->busnum, usbdev->devnum, ifnum);
 	for (i = 0; i < 5; i++) printk("%2.2x:", netdev->dev_addr[i]);
 	printk("%2.2x.\n", netdev->dev_addr[i]);
-
 	return catc;
 }
 
@@ -791,7 +928,7 @@
  */
 
 static struct usb_device_id catc_id_table [] = {
-	{ USB_DEVICE(0x0423, 0xa) },	/* CATC Netmate */
+	{ USB_DEVICE(0x0423, 0xa) },	/* CATC Netmate, Belkin F5U011 */
 	{ USB_DEVICE(0x0423, 0xc) },	/* CATC Netmate II, Belkin F5U111 */
 	{ USB_DEVICE(0x08d1, 0x1) },	/* smartBridges smartNIC */
 	{ }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)