36 #include <linux/module.h>
37 #include <linux/kernel.h>
38 #include <linux/string.h>
39 #include <linux/netdevice.h>
43 #include <linux/ethtool.h>
45 #include <linux/bitops.h>
47 #include <asm/uaccess.h>
57 #define DRIVER_VERSION "v2.8"
59 #define DRIVER_DESC "CATC EL1210A NetMate USB Ethernet driver"
60 #define SHORT_DRIVER_DESC "EL1210A NetMate USB Ethernet"
72 #define STATS_UPDATE (HZ)
73 #define TX_TIMEOUT (5*HZ)
75 #define RX_MAX_BURST 15
76 #define TX_MAX_BURST 15
78 #define RX_PKT_SZ 1600
158 #define CTRL_RUNNING 0
206 #define catc_get_mac(catc, mac) catc_ctrl_msg(catc, USB_DIR_IN, GetMac, 0, 0, mac, 6)
207 #define catc_reset(catc) catc_ctrl_msg(catc, USB_DIR_OUT, Reset, 0, 0, NULL, 0)
208 #define catc_set_reg(catc, reg, val) catc_ctrl_msg(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0)
209 #define catc_get_reg(catc, reg, buf) catc_ctrl_msg(catc, USB_DIR_IN, GetReg, 0, reg, buf, 1)
210 #define catc_write_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size)
211 #define catc_read_mem(catc, addr, buf, size) catc_ctrl_msg(catc, USB_DIR_IN, ReadMem, 0, addr, buf, size)
213 #define f5u011_rxmode(catc, rxmode) catc_ctrl_msg(catc, USB_DIR_OUT, SetRxMode, 0, 1, rxmode, 2)
214 #define f5u011_rxmode_async(catc, rxmode) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 1, &rxmode, 2, NULL)
215 #define f5u011_mchash_async(catc, hash) catc_ctrl_async(catc, USB_DIR_OUT, SetRxMode, 0, 2, &hash, 8, NULL)
217 #define catc_set_reg_async(catc, reg, val) catc_ctrl_async(catc, USB_DIR_OUT, SetReg, val, reg, NULL, 0, NULL)
218 #define catc_get_reg_async(catc, reg, cb) catc_ctrl_async(catc, USB_DIR_IN, GetReg, 0, reg, NULL, 1, cb)
219 #define catc_write_mem_async(catc, addr, buf, size) catc_ctrl_async(catc, USB_DIR_OUT, WriteMem, 0, addr, buf, size, NULL)
225 static void catc_rx_done(
struct urb *
urb)
228 u8 *pkt_start = urb->transfer_buffer;
239 dev_dbg(&urb->dev->dev,
"rx_done, status %d, length %d\n",
240 status, urb->actual_length);
247 if (pkt_len > urb->actual_length) {
248 catc->
netdev->stats.rx_length_errors++;
249 catc->
netdev->stats.rx_errors++;
253 pkt_len = urb->actual_length;
256 if (!(skb = dev_alloc_skb(pkt_len)))
259 skb_copy_to_linear_data(skb, pkt_start + pkt_offset, pkt_len);
265 catc->
netdev->stats.rx_packets++;
271 pkt_start += (((pkt_len + 1) >> 6) + 1) << 6;
273 }
while (pkt_start - (
u8 *) urb->transfer_buffer < urb->actual_length);
283 "submit(rx_urb) status %d\n", state);
291 static void catc_irq_done(
struct urb *
urb)
294 u8 *
data = urb->transfer_buffer;
300 hasdata = data[1] & 0x80;
303 else if (data[1] & 0x20)
309 else if (data[0] == 0xA0)
323 "irq_done, status %d, data %02x %02x.\n",
324 status, data[0], data[1]);
346 "submit(rx_urb) status %d\n", res);
354 "can't resubmit intr, %s-%s, status %d\n",
355 catc->
usbdev->bus->bus_name,
356 catc->
usbdev->devpath, res);
363 static int catc_tx_run(
struct catc *catc)
385 static void catc_tx_done(
struct urb *urb)
387 struct catc *catc = urb->context;
389 int r, status = urb->status;
392 dev_dbg(&urb->dev->dev,
"Tx Reset.\n");
395 catc->
netdev->stats.tx_errors++;
397 netif_wake_queue(catc->
netdev);
402 dev_dbg(&urb->dev->dev,
"tx_done, status %d, length %d\n",
403 status, urb->actual_length);
410 r = catc_tx_run(catc);
417 netif_wake_queue(catc->
netdev);
419 spin_unlock_irqrestore(&catc->
tx_lock, flags);
425 struct catc *catc = netdev_priv(netdev);
438 skb_copy_from_linear_data(skb, tx_buf + 2, skb->
len);
442 r = catc_tx_run(catc);
449 netif_stop_queue(netdev);
451 spin_unlock_irqrestore(&catc->
tx_lock, flags);
454 catc->
netdev->stats.tx_bytes += skb->
len;
455 catc->
netdev->stats.tx_packets++;
463 static void catc_tx_timeout(
struct net_device *netdev)
465 struct catc *catc = netdev_priv(netdev);
478 dir ? usb_rcvctrlpipe(catc->
usbdev, 0) : usb_sndctrlpipe(catc->
usbdev, 0),
479 request, 0x40 | dir, value, index, buf, len, 1000);
480 return retval < 0 ? retval : 0;
483 static void catc_ctrl_run(
struct catc *catc)
486 struct usb_device *usbdev = catc->
usbdev;
497 urb->pipe = q->dir ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0);
498 urb->transfer_buffer_length = q->len;
499 urb->transfer_buffer = catc->
ctrl_buf;
500 urb->setup_packet = (
void *) dr;
503 if (!q->dir && q->buf && q->len)
511 static void catc_ctrl_done(
struct urb *urb)
513 struct catc *catc = urb->context;
514 struct ctrl_queue *
q;
516 int status = urb->status;
519 dev_dbg(&urb->dev->dev,
"ctrl_done, status %d, len %d.\n",
520 status, urb->actual_length);
527 if (q->buf && q->len)
534 q->callback(catc, q);
543 spin_unlock_irqrestore(&catc->
ctrl_lock, flags);
546 static int catc_ctrl_async(
struct catc *catc,
u8 dir,
u8 request,
u16 value,
547 u16 index,
void *buf,
int len,
void (*
callback)(
struct catc *catc,
struct ctrl_queue *q))
549 struct ctrl_queue *
q;
576 spin_unlock_irqrestore(&catc->
ctrl_lock, flags);
585 static void catc_stats_done(
struct catc *catc,
struct ctrl_queue *q)
601 catc->
netdev->stats.collisions += data - last;
604 catc->
netdev->stats.tx_aborted_errors += data - last;
605 catc->
netdev->stats.tx_errors += data - last;
608 catc->
netdev->stats.rx_frame_errors += data - last;
609 catc->
netdev->stats.rx_errors += data - last;
616 static void catc_stats_timer(
unsigned long data)
618 struct catc *catc = (
void *) data;
621 for (i = 0; i < 8; i++)
636 multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
639 static void catc_set_multicast_list(
struct net_device *netdev)
641 struct catc *catc = netdev_priv(netdev);
646 memset(broadcast, 0xff, 6);
649 catc_multicast(broadcast, catc->
multicast);
663 catc->
multicast[(crc >> 3) & 0x3f] |= 1 << (crc & 7);
665 catc->
multicast[7-(crc >> 29)] |= 1 << ((crc >> 26) & 7);
674 if (catc->
rxmode[0] != rx) {
677 "Setting RX mode to %2.2X %2.2X\n",
687 struct catc *catc = netdev_priv(dev);
695 struct catc *catc = netdev_priv(dev);
701 ethtool_cmd_speed_set(cmd,
SPEED_10);
713 .get_drvinfo = catc_get_drvinfo,
714 .get_settings = catc_get_settings,
722 static int catc_open(
struct net_device *netdev)
724 struct catc *catc = netdev_priv(netdev);
734 netif_start_queue(netdev);
742 static int catc_stop(
struct net_device *netdev)
744 struct catc *catc = netdev_priv(netdev);
746 netif_stop_queue(netdev);
760 .ndo_open = catc_open,
761 .ndo_stop = catc_stop,
762 .ndo_start_xmit = catc_start_xmit,
764 .ndo_tx_timeout = catc_tx_timeout,
765 .ndo_set_rx_mode = catc_set_multicast_list,
777 struct device *dev = &intf->dev;
778 struct usb_device *usbdev = interface_to_usbdev(intf);
785 intf->altsetting->desc.bInterfaceNumber, 1)) {
786 dev_err(dev,
"Can't set altsetting 1.\n");
790 netdev = alloc_etherdev(
sizeof(
struct catc));
794 catc = netdev_priv(netdev);
808 catc->
timer.function = catc_stats_timer;
816 dev_err(&intf->dev,
"No free urbs available.\n");
826 if (
le16_to_cpu(usbdev->descriptor.idVendor) == 0x0423 &&
827 le16_to_cpu(usbdev->descriptor.idProduct) == 0xa &&
829 dev_dbg(dev,
"Testing for f5u011\n");
837 usb_fill_control_urb(catc->
ctrl_urb, usbdev, usb_sndctrlpipe(usbdev, 0),
838 NULL,
NULL, 0, catc_ctrl_done, catc);
840 usb_fill_bulk_urb(catc->
tx_urb, usbdev, usb_sndbulkpipe(usbdev, 1),
841 NULL, 0, catc_tx_done, catc);
843 usb_fill_bulk_urb(catc->
rx_urb, usbdev, usb_rcvbulkpipe(usbdev, 1),
844 catc->
rx_buf, pktsz, catc_rx_done, catc);
846 usb_fill_int_urb(catc->
irq_urb, usbdev, usb_rcvintpipe(usbdev, 2),
847 catc->
irq_buf, 2, catc_irq_done, catc, 1);
850 dev_dbg(dev,
"Checking memory size\n");
866 "Couldn't detect memory size, assuming 32k\n");
874 dev_dbg(dev,
"Getting MAC from SEEROM.\n");
878 dev_dbg(dev,
"Setting MAC into registers.\n");
880 for (i = 0; i < 6; i++)
883 dev_dbg(dev,
"Filling the multicast list.\n");
885 memset(broadcast, 0xff, 6);
886 catc_multicast(broadcast, catc->
multicast);
890 dev_dbg(dev,
"Clearing error counters.\n");
892 for (i = 0; i < 8; i++)
903 dev_dbg(dev,
"Performing reset\n");
907 dev_dbg(dev,
"Setting RX Mode\n");
914 netdev->
name, (catc->
is_f5u011) ?
"Belkin F5U011" :
"CATC EL1210A NetMate",
915 usbdev->bus->bus_name, usbdev->devpath, netdev->
dev_addr);
916 usb_set_intfdata(intf, catc);
920 usb_set_intfdata(intf,
NULL);
933 struct catc *catc = usb_get_intfdata(intf);
935 usb_set_intfdata(intf,
NULL);
951 { USB_DEVICE(0x0423, 0xa) },
952 { USB_DEVICE(0x0423, 0
xc) },
953 { USB_DEVICE(0x08d1, 0x1) },
959 static struct usb_driver catc_driver = {
962 .disconnect = catc_disconnect,
963 .id_table = catc_id_table,
964 .disable_hub_initiated_lpm = 1,