VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / usb / net / usbnet.c
index 557edde..2d68cb0 100644 (file)
  *             disconnect; other cleanups. (db)  Flush net1080 fifos
  *             after several sequential framing errors. (Johannes Erdfelt)
  * 22-aug-2003 AX8817X support (Dave Hollis).
+ * 14-jun-2004  Trivial patch for AX8817X based Buffalo LUA-U2-KTX in Japan
+ *             (Neil Bortnak)
  *
  *-------------------------------------------------------------------------*/
 
@@ -314,7 +316,7 @@ get_endpoints (struct usbnet *dev, struct usb_interface *intf)
        for (tmp = 0; tmp < intf->num_altsetting; tmp++) {
                unsigned        ep;
 
-               in = out = 0;
+               in = out = NULL;
                alt = intf->altsetting + tmp;
 
                /* take the first altsetting with in-bulk + out-bulk;
@@ -452,6 +454,15 @@ static const struct driver_info    an2720_info = {
 #define AX_MCAST_FILTER_SIZE           8
 #define AX_MAX_MCAST                   64
 
+#define AX_INTERRUPT_BUFSIZE           8
+
+/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */
+struct ax8817x_data {
+       u8 multi_filter[AX_MCAST_FILTER_SIZE];
+       struct urb *int_urb;
+       u8 *int_buf;
+};
+
 static int ax8817x_read_cmd(struct usbnet *dev, u8 cmd, u16 value, u16 index,
                            u16 size, void *data)
 {
@@ -494,6 +505,30 @@ static void ax8817x_async_cmd_callback(struct urb *urb, struct pt_regs *regs)
        usb_free_urb(urb);
 }
 
+static void ax8817x_interrupt_complete(struct urb *urb, struct pt_regs *regs)
+{
+       struct usbnet *dev = (struct usbnet *)urb->context;
+       struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
+       int link;
+
+       if (urb->status < 0) {
+               printk(KERN_DEBUG "ax8817x_interrupt_complete() failed with %d",
+                       urb->status);
+       } else {
+               if (data->int_buf[5] == 0x90) {
+                       link = data->int_buf[2] & 0x01;
+                       if (netif_carrier_ok(dev->net) != link) {
+                               if (link)
+                                       netif_carrier_on(dev->net);
+                               else
+                                       netif_carrier_off(dev->net);
+                               devdbg(dev, "ax8817x - Link Status is: %d", link);
+                       }
+               }
+               usb_submit_urb(data->int_urb, GFP_KERNEL);
+       }
+}
+
 static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 index,
                                    u16 size, void *data)
 {
@@ -533,6 +568,7 @@ static void ax8817x_write_cmd_async(struct usbnet *dev, u8 cmd, u16 value, u16 i
 static void ax8817x_set_multicast(struct net_device *net)
 {
        struct usbnet *dev = (struct usbnet *) net->priv;
+       struct ax8817x_data *data = (struct ax8817x_data *)&dev->data;
        u8 rx_ctl = 0x8c;
 
        if (net->flags & IFF_PROMISC) {
@@ -547,25 +583,24 @@ static void ax8817x_set_multicast(struct net_device *net)
                 * for our 8 byte filter buffer
                 * to avoid allocating memory that
                 * is tricky to free later */
-               u8 *multi_filter = (u8 *)&dev->data;
                struct dev_mc_list *mc_list = net->mc_list;
                u32 crc_bits;
                int i;
 
-               memset(multi_filter, 0, AX_MCAST_FILTER_SIZE);
+               memset(data->multi_filter, 0, AX_MCAST_FILTER_SIZE);
 
                /* Build the multicast hash filter. */
                for (i = 0; i < net->mc_count; i++) {
                        crc_bits =
                            ether_crc(ETH_ALEN,
                                      mc_list->dmi_addr) >> 26;
-                       multi_filter[crc_bits >> 3] |=
+                       data->multi_filter[crc_bits >> 3] |=
                            1 << (crc_bits & 7);
                        mc_list = mc_list->next;
                }
 
                ax8817x_write_cmd_async(dev, AX_CMD_WRITE_MULTI_FILTER, 0, 0,
-                                  AX_MCAST_FILTER_SIZE, multi_filter);
+                                  AX_MCAST_FILTER_SIZE, data->multi_filter);
 
                rx_ctl |= 0x10;
        }
@@ -667,13 +702,6 @@ static void ax8817x_get_drvinfo (struct net_device *net,
        info->eedump_len = 0x3e;
 }
 
-static u32 ax8817x_get_link (struct net_device *net)
-{
-       struct usbnet *dev = (struct usbnet *)net->priv;
-
-       return (u32)mii_link_ok(&dev->mii);
-}
-
 static int ax8817x_get_settings(struct net_device *net, struct ethtool_cmd *cmd)
 {
        struct usbnet *dev = (struct usbnet *)net->priv;
@@ -693,7 +721,7 @@ static int ax8817x_set_settings(struct net_device *net, struct ethtool_cmd *cmd)
    devices that may be connected at the same time. */
 static struct ethtool_ops ax8817x_ethtool_ops = {
        .get_drvinfo            = ax8817x_get_drvinfo,
-       .get_link               = ax8817x_get_link,
+       .get_link               = ethtool_op_get_link,
        .get_msglevel           = usbnet_get_msglevel,
        .set_msglevel           = usbnet_set_msglevel,
        .get_wol                = ax8817x_get_wol,
@@ -707,13 +735,34 @@ static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
 {
        int ret;
        u8 buf[6];
-       u16 *buf16 = (u16 *) buf;
        int i;
        unsigned long gpio_bits = dev->driver_info->data;
+       struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
 
        dev->in = usb_rcvbulkpipe(dev->udev, 3);
        dev->out = usb_sndbulkpipe(dev->udev, 2);
 
+       // allocate irq urb
+       if ((data->int_urb = usb_alloc_urb (0, GFP_KERNEL)) == 0) {
+               dbg ("%s: cannot allocate interrupt URB",
+                       dev->net->name);
+               return -ENOMEM;
+       }
+       
+       if ((data->int_buf = kmalloc(AX_INTERRUPT_BUFSIZE, GFP_KERNEL)) == NULL) {
+               dbg ("%s: cannot allocate memory for interrupt buffer",
+                       dev->net->name);
+               usb_free_urb(data->int_urb);
+               return -ENOMEM;
+       }
+       memset(data->int_buf, 0, AX_INTERRUPT_BUFSIZE);
+
+       usb_fill_int_urb (data->int_urb, dev->udev,
+               usb_rcvintpipe (dev->udev, 1),
+               data->int_buf, AX_INTERRUPT_BUFSIZE,
+               ax8817x_interrupt_complete, dev,
+               dev->udev->speed == USB_SPEED_HIGH ? 8 : 100);
+
        /* Toggle the GPIOs in a manufacturer/model specific way */
        for (i = 2; i >= 0; i--) {
                if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_GPIOS,
@@ -754,49 +803,37 @@ static int ax8817x_bind(struct usbnet *dev, struct usb_interface *intf)
        dev->mii.reg_num_mask = 0x1f;
        dev->mii.phy_id = buf[1];
 
-       if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_SW_MII, 0, 0, 0, &buf)) < 0) {
-               dbg("Failed to go to software MII mode: %02x", ret);
-               return ret;
-       }
-
-       *buf16 = cpu_to_le16(BMCR_RESET);
-       if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
-                                    dev->mii.phy_id, MII_BMCR, 2, buf16)) < 0) {
-               dbg("Failed to write MII reg - MII_BMCR: %02x", ret);
-               return ret;
-       }
+       dev->net->set_multicast_list = ax8817x_set_multicast;
+       dev->net->ethtool_ops = &ax8817x_ethtool_ops;
 
-       /* Advertise that we can do full-duplex pause */
-       *buf16 = cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400);
-       if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
-                                    dev->mii.phy_id, MII_ADVERTISE, 
-                                    2, buf16)) < 0) {
-               dbg("Failed to write MII_REG advertisement: %02x", ret);
-               return ret;
-       }
+       ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_BMCR,
+                       cpu_to_le16(BMCR_RESET));
+       ax8817x_mdio_write(dev->net, dev->mii.phy_id, MII_ADVERTISE,
+                       cpu_to_le16(ADVERTISE_ALL | ADVERTISE_CSMA | 0x0400));
+       mii_nway_restart(&dev->mii);
 
-       *buf16 = cpu_to_le16(BMCR_ANENABLE | BMCR_ANRESTART);
-       if ((ret = ax8817x_write_cmd(dev, AX_CMD_WRITE_MII_REG,
-                                    dev->mii.phy_id, MII_BMCR, 
-                                    2, buf16)) < 0) {
-               dbg("Failed to write MII reg autonegotiate: %02x", ret);
+       if((ret = usb_submit_urb(data->int_urb, GFP_KERNEL)) < 0) {
+               dbg("Failed to submit interrupt URB: %02x", ret);
+               usb_free_urb(data->int_urb);
                return ret;
        }
 
-       if ((ret = ax8817x_write_cmd(dev, AX_CMD_SET_HW_MII, 0, 0, 0, &buf)) < 0) {
-               dbg("Failed to set hardware MII: %02x", ret);
-               return ret;
-       }
+       return 0;
+}
 
-       dev->net->set_multicast_list = ax8817x_set_multicast;
-       dev->net->ethtool_ops = &ax8817x_ethtool_ops;
+static void ax8817x_unbind(struct usbnet *dev, struct usb_interface *intf)
+{
+       struct ax8817x_data *data = (struct ax8817x_data *)dev->data;
 
-       return 0;
+       usb_unlink_urb(data->int_urb);
+       usb_free_urb(data->int_urb);
+       kfree(data->int_buf);
 }
 
 static const struct driver_info ax8817x_info = {
        .description = "ASIX AX8817x USB 2.0 Ethernet",
        .bind = ax8817x_bind,
+       .unbind = ax8817x_unbind,
        .flags =  FLAG_ETHER,
        .data = 0x00130103,
 };
@@ -804,6 +841,7 @@ static const struct driver_info ax8817x_info = {
 static const struct driver_info dlink_dub_e100_info = {
        .description = "DLink DUB-E100 USB Ethernet",
        .bind = ax8817x_bind,
+       .unbind = ax8817x_unbind,
        .flags =  FLAG_ETHER,
        .data = 0x009f9d9f,
 };
@@ -811,6 +849,7 @@ static const struct driver_info dlink_dub_e100_info = {
 static const struct driver_info netgear_fa120_info = {
        .description = "Netgear FA-120 USB Ethernet",
        .bind = ax8817x_bind,
+       .unbind = ax8817x_unbind,
        .flags =  FLAG_ETHER,
        .data = 0x00130103,
 };
@@ -818,6 +857,7 @@ static const struct driver_info netgear_fa120_info = {
 static const struct driver_info hawking_uf200_info = {
        .description = "Hawking UF200 USB Ethernet",
        .bind = ax8817x_bind,
+       .unbind = ax8817x_unbind,
        .flags =  FLAG_ETHER,
        .data = 0x001f1d1f,
 };
@@ -1084,7 +1124,7 @@ static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
                /* ensure immediate exit from usbnet_disconnect */
                usb_set_intfdata(info->data, NULL);
                usb_driver_release_interface (&usbnet_driver, info->data);
-               info->data = 0;
+               info->data = NULL;
        }
 
        /* and vice versa (just in case) */
@@ -1092,7 +1132,7 @@ static void cdc_unbind (struct usbnet *dev, struct usb_interface *intf)
                /* ensure immediate exit from usbnet_disconnect */
                usb_set_intfdata(info->control, NULL);
                usb_driver_release_interface (&usbnet_driver, info->control);
-               info->control = 0;
+               info->control = NULL;
        }
 }
 
@@ -1157,6 +1197,7 @@ static int cdc_bind (struct usbnet *dev, struct usb_interface *intf)
 
        status = get_ethernet_addr (dev, info->ether);
        if (status < 0) {
+               usb_set_intfdata(info->data, NULL);
                usb_driver_release_interface (&usbnet_driver, info->data);
                return status;
        }
@@ -1638,7 +1679,7 @@ nc_vendor_write (struct usbnet *dev, u8 req, u8 regnum, u16 value)
                req,
                USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                value, regnum,
-               0, 0,                   // data is in setup packet
+               NULL, 0,                        // data is in setup packet
                CONTROL_TIMEOUT_JIFFIES);
 }
 
@@ -2081,7 +2122,7 @@ pl_vendor_req (struct usbnet *dev, u8 req, u8 val, u8 index)
                req,
                USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                val, index,
-               0, 0,
+               NULL, 0,
                CONTROL_TIMEOUT_JIFFIES);
 }
 
@@ -2415,7 +2456,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs)
 
        skb_put (skb, urb->actual_length);
        entry->state = rx_done;
-       entry->urb = 0;
+       entry->urb = NULL;
 
        switch (urb_status) {
            // success
@@ -2459,7 +2500,7 @@ static void rx_complete (struct urb *urb, struct pt_regs *regs)
 block:
                entry->state = rx_cleanup;
                entry->urb = urb;
-               urb = 0;
+               urb = NULL;
                break;
 
            // data overrun ... flush fifo?
@@ -2554,7 +2595,7 @@ static int usbnet_stop (struct net_device *net)
                schedule_timeout (UNLINK_TIMEOUT_JIFFIES);
                devdbg (dev, "waited for %d urb completions", temp);
        }
-       dev->wait = 0;
+       dev->wait = NULL;
        remove_wait_queue (&unlink_wakeup, &wait); 
 
        /* deferred work (task, timer, softirq) must also stop.
@@ -2713,7 +2754,7 @@ kevent (void *data)
 
        /* tasklet could resubmit itself forever if memory is tight */
        if (test_bit (EVENT_RX_MEMORY, &dev->flags)) {
-               struct urb      *urb = 0;
+               struct urb      *urb = NULL;
 
                if (netif_running (dev->net))
                        urb = usb_alloc_urb (0, GFP_KERNEL);
@@ -2768,7 +2809,7 @@ static void tx_complete (struct urb *urb, struct pt_regs *regs)
                }
        }
 
-       urb->dev = 0;
+       urb->dev = NULL;
        entry->state = tx_done;
        defer_bh (dev, skb);
 }
@@ -2792,13 +2833,13 @@ static int usbnet_start_xmit (struct sk_buff *skb, struct net_device *net)
        struct usbnet           *dev = (struct usbnet *) net->priv;
        int                     length;
        int                     retval = NET_XMIT_SUCCESS;
-       struct urb              *urb = 0;
+       struct urb              *urb = NULL;
        struct skb_data         *entry;
        struct driver_info      *info = dev->driver_info;
        unsigned long           flags;
 #ifdef CONFIG_USB_NET1080
-       struct nc_header        *header = 0;
-       struct nc_trailer       *trailer = 0;
+       struct nc_header        *header = NULL;
+       struct nc_trailer       *trailer = NULL;
 #endif /* CONFIG_USB_NET1080 */
 
        // some devices want funky USB-level framing, for
@@ -3204,6 +3245,14 @@ static const struct usb_device_id        products [] = {
        // ATEN UC210T
        USB_DEVICE (0x0557, 0x2009),
        .driver_info =  (unsigned long) &ax8817x_info,
+}, {
+       // Buffalo LUA-U2-KTX
+       USB_DEVICE (0x0411, 0x003d),
+       .driver_info =  (unsigned long) &ax8817x_info,
+}, {
+       // Sitecom LN-029 "USB 2.0 10/100 Ethernet adapter"
+       USB_DEVICE (0x6189, 0x182d),
+       .driver_info =  (unsigned long) &ax8817x_info,
 },
 #endif