Merge 4.5-rc6 into usb-next
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Mar 2016 00:13:54 +0000 (16:13 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 2 Mar 2016 00:13:54 +0000 (16:13 -0800)
We want the USB fixes in here as well.

Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
81 files changed:
MAINTAINERS
drivers/usb/atm/cxacru.c
drivers/usb/chipidea/debug.c
drivers/usb/class/cdc-acm.c
drivers/usb/class/cdc-acm.h
drivers/usb/class/usbtmc.c
drivers/usb/common/common.c
drivers/usb/core/buffer.c
drivers/usb/core/config.c
drivers/usb/core/devices.c
drivers/usb/core/devio.c
drivers/usb/core/file.c
drivers/usb/core/hcd-pci.c
drivers/usb/core/hcd.c
drivers/usb/core/hub.c
drivers/usb/core/hub.h
drivers/usb/core/sysfs.c
drivers/usb/core/urb.c
drivers/usb/core/usb.c
drivers/usb/core/usb.h
drivers/usb/dwc2/Kconfig
drivers/usb/gadget/function/rndis.c
drivers/usb/gadget/udc/Kconfig
drivers/usb/host/Kconfig
drivers/usb/host/bcma-hcd.c
drivers/usb/host/ehci-dbg.c
drivers/usb/host/ehci-fsl.c
drivers/usb/host/ehci-hcd.c
drivers/usb/host/ehci-hub.c
drivers/usb/host/ehci-msm.c
drivers/usb/host/ehci-pci.c
drivers/usb/host/ehci-platform.c
drivers/usb/host/ehci-q.c
drivers/usb/host/ehci-sched.c
drivers/usb/host/ehci-st.c
drivers/usb/host/ehci-timer.c
drivers/usb/host/ehci.h
drivers/usb/host/fotg210-hcd.c
drivers/usb/host/fsl-mph-dr-of.c
drivers/usb/host/max3421-hcd.c
drivers/usb/host/ohci-nxp.c
drivers/usb/host/ohci-platform.c
drivers/usb/host/ohci-pxa27x.c
drivers/usb/host/ohci-st.c
drivers/usb/host/oxu210hp-hcd.c
drivers/usb/host/pci-quirks.c
drivers/usb/host/r8a66597-hcd.c
drivers/usb/host/u132-hcd.c
drivers/usb/host/xhci-hub.c
drivers/usb/host/xhci-mem.c
drivers/usb/host/xhci-ring.c
drivers/usb/host/xhci.c
drivers/usb/host/xhci.h
drivers/usb/misc/chaoskey.c
drivers/usb/misc/sisusbvga/sisusb.c
drivers/usb/mon/mon_main.c
drivers/usb/musb/Kconfig
drivers/usb/renesas_usbhs/Kconfig
drivers/usb/renesas_usbhs/fifo.c
drivers/usb/renesas_usbhs/fifo.h
drivers/usb/renesas_usbhs/pipe.h
drivers/usb/storage/debug.c
drivers/usb/storage/debug.h
drivers/usb/storage/ene_ub6250.c
drivers/usb/storage/sddr09.c
drivers/usb/storage/uas.c
drivers/usb/usbip/usbip_event.c
drivers/usb/usbip/vhci_hcd.c
drivers/usb/usbip/vhci_rx.c
drivers/usb/usbip/vhci_sysfs.c
drivers/usb/usbip/vhci_tx.c
drivers/usb/wusbcore/wusbhc.h
include/linux/device.h
include/linux/usb.h
include/linux/usb/hcd.h
include/linux/usb/msm_hsusb_hw.h
include/linux/usb/storage.h
include/uapi/linux/usb/ch11.h
include/uapi/linux/usb/ch9.h
include/uapi/linux/usb/tmc.h
include/uapi/linux/usbdevice_fs.h

index da3e4d8..a1477a7 100644 (file)
@@ -11256,7 +11256,7 @@ F:      include/linux/mtd/ubi.h
 F:     include/uapi/mtd/ubi-user.h
 
 USB ACM DRIVER
-M:     Oliver Neukum <oliver@neukum.org>
+M:     Oliver Neukum <oneukum@suse.com>
 L:     linux-usb@vger.kernel.org
 S:     Maintained
 F:     Documentation/usb/acm.txt
index 1173f9c..0a866e9 100644 (file)
@@ -476,6 +476,8 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
                        return -EINVAL;
                if (index < 0 || index > 0x7f)
                        return -EINVAL;
+               if (tmp < 0 || tmp > len - pos)
+                       return -EINVAL;
                pos += tmp;
 
                /* skip trailing newline */
index df47110..6d23eed 100644 (file)
@@ -175,7 +175,6 @@ static int ci_requests_show(struct seq_file *s, void *data)
 {
        struct ci_hdrc *ci = s->private;
        unsigned long flags;
-       struct list_head   *ptr = NULL;
        struct ci_hw_req *req = NULL;
        struct td_node *node, *tmpnode;
        unsigned i, j, qsize = sizeof(struct ci_hw_td)/sizeof(u32);
@@ -187,9 +186,7 @@ static int ci_requests_show(struct seq_file *s, void *data)
 
        spin_lock_irqsave(&ci->lock, flags);
        for (i = 0; i < ci->hw_ep_max; i++)
-               list_for_each(ptr, &ci->ci_hw_ep[i].qh.queue) {
-                       req = list_entry(ptr, struct ci_hw_req, queue);
-
+               list_for_each_entry(req, &ci->ci_hw_ep[i].qh.queue, queue) {
                        list_for_each_entry_safe(node, tmpnode, &req->tds, td) {
                                seq_printf(s, "EP=%02i: TD=%08X %s\n",
                                           i % (ci->hw_ep_max / 2),
index fa4e239..1d2c99a 100644 (file)
@@ -713,9 +713,20 @@ static int acm_tty_write(struct tty_struct *tty,
        }
 
        if (acm->susp_count) {
+               if (acm->putbuffer) {
+                       /* now to preserve order */
+                       usb_anchor_urb(acm->putbuffer->urb, &acm->delayed);
+                       acm->putbuffer = NULL;
+               }
                usb_anchor_urb(wb->urb, &acm->delayed);
                spin_unlock_irqrestore(&acm->write_lock, flags);
                return count;
+       } else {
+               if (acm->putbuffer) {
+                       /* at this point there is no good way to handle errors */
+                       acm_start_wb(acm, acm->putbuffer);
+                       acm->putbuffer = NULL;
+               }
        }
 
        stat = acm_start_wb(acm, wb);
@@ -726,6 +737,60 @@ static int acm_tty_write(struct tty_struct *tty,
        return count;
 }
 
+static void acm_tty_flush_chars(struct tty_struct *tty)
+{
+       struct acm *acm = tty->driver_data;
+       struct acm_wb *cur = acm->putbuffer;
+       int err;
+       unsigned long flags;
+
+       acm->putbuffer = NULL;
+       err = usb_autopm_get_interface_async(acm->control);
+       spin_lock_irqsave(&acm->write_lock, flags);
+       if (err < 0) {
+               cur->use = 0;
+               goto out;
+       }
+
+       if (acm->susp_count)
+               usb_anchor_urb(cur->urb, &acm->delayed);
+       else
+               acm_start_wb(acm, cur);
+out:
+       spin_unlock_irqrestore(&acm->write_lock, flags);
+       return;
+}
+
+static int acm_tty_put_char(struct tty_struct *tty, unsigned char ch)
+{
+       struct acm *acm = tty->driver_data;
+       struct acm_wb *cur;
+       int wbn;
+       unsigned long flags;
+
+overflow:
+       cur = acm->putbuffer;
+       if (!cur) {
+               spin_lock_irqsave(&acm->write_lock, flags);
+               wbn = acm_wb_alloc(acm);
+               if (wbn >= 0) {
+                       cur = &acm->wb[wbn];
+                       acm->putbuffer = cur;
+               }
+               spin_unlock_irqrestore(&acm->write_lock, flags);
+               if (!cur)
+                       return 0;
+       }
+
+       if (cur->len == acm->writesize) {
+               acm_tty_flush_chars(tty);
+               goto overflow;
+       }
+
+       cur->buf[cur->len++] = ch;
+       return 1;
+}
+
 static int acm_tty_write_room(struct tty_struct *tty)
 {
        struct acm *acm = tty->driver_data;
@@ -1905,6 +1970,8 @@ static const struct tty_operations acm_ops = {
        .cleanup =              acm_tty_cleanup,
        .hangup =               acm_tty_hangup,
        .write =                acm_tty_write,
+       .put_char =             acm_tty_put_char,
+       .flush_chars =          acm_tty_flush_chars,
        .write_room =           acm_tty_write_room,
        .ioctl =                acm_tty_ioctl,
        .throttle =             acm_tty_throttle,
index ccfaba9..05ce308 100644 (file)
@@ -94,6 +94,7 @@ struct acm {
        unsigned long read_urbs_free;
        struct urb *read_urbs[ACM_NR];
        struct acm_rb read_buffers[ACM_NR];
+       struct acm_wb *putbuffer;                       /* for acm_tty_put_char() */
        int rx_buflimit;
        int rx_endpoint;
        spinlock_t read_lock;
index 7a11a82..917a55c 100644 (file)
@@ -27,6 +27,7 @@
 #include <linux/uaccess.h>
 #include <linux/kref.h>
 #include <linux/slab.h>
+#include <linux/poll.h>
 #include <linux/mutex.h>
 #include <linux/usb.h>
 #include <linux/usb/tmc.h>
@@ -87,6 +88,23 @@ struct usbtmc_device_data {
        u8 bTag_last_write;     /* needed for abort */
        u8 bTag_last_read;      /* needed for abort */
 
+       /* data for interrupt in endpoint handling */
+       u8             bNotify1;
+       u8             bNotify2;
+       u16            ifnum;
+       u8             iin_bTag;
+       u8            *iin_buffer;
+       atomic_t       iin_data_valid;
+       unsigned int   iin_ep;
+       int            iin_ep_present;
+       int            iin_interval;
+       struct urb    *iin_urb;
+       u16            iin_wMaxPacketSize;
+       atomic_t       srq_asserted;
+
+       /* coalesced usb488_caps from usbtmc_dev_capabilities */
+       __u8 usb488_caps;
+
        u8 rigol_quirk;
 
        /* attributes from the USB TMC spec for this device */
@@ -99,6 +117,8 @@ struct usbtmc_device_data {
        struct usbtmc_dev_capabilities  capabilities;
        struct kref kref;
        struct mutex io_mutex;  /* only one i/o function running at a time */
+       wait_queue_head_t waitq;
+       struct fasync_struct *fasync;
 };
 #define to_usbtmc_data(d) container_of(d, struct usbtmc_device_data, kref)
 
@@ -373,6 +393,142 @@ exit:
        return rv;
 }
 
+static int usbtmc488_ioctl_read_stb(struct usbtmc_device_data *data,
+                               void __user *arg)
+{
+       struct device *dev = &data->intf->dev;
+       u8 *buffer;
+       u8 tag;
+       __u8 stb;
+       int rv;
+
+       dev_dbg(dev, "Enter ioctl_read_stb iin_ep_present: %d\n",
+               data->iin_ep_present);
+
+       buffer = kmalloc(8, GFP_KERNEL);
+       if (!buffer)
+               return -ENOMEM;
+
+       atomic_set(&data->iin_data_valid, 0);
+
+       /* must issue read_stb before using poll or select */
+       atomic_set(&data->srq_asserted, 0);
+
+       rv = usb_control_msg(data->usb_dev,
+                       usb_rcvctrlpipe(data->usb_dev, 0),
+                       USBTMC488_REQUEST_READ_STATUS_BYTE,
+                       USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+                       data->iin_bTag,
+                       data->ifnum,
+                       buffer, 0x03, USBTMC_TIMEOUT);
+       if (rv < 0) {
+               dev_err(dev, "stb usb_control_msg returned %d\n", rv);
+               goto exit;
+       }
+
+       if (buffer[0] != USBTMC_STATUS_SUCCESS) {
+               dev_err(dev, "control status returned %x\n", buffer[0]);
+               rv = -EIO;
+               goto exit;
+       }
+
+       if (data->iin_ep_present) {
+               rv = wait_event_interruptible_timeout(
+                       data->waitq,
+                       atomic_read(&data->iin_data_valid) != 0,
+                       USBTMC_TIMEOUT);
+               if (rv < 0) {
+                       dev_dbg(dev, "wait interrupted %d\n", rv);
+                       goto exit;
+               }
+
+               if (rv == 0) {
+                       dev_dbg(dev, "wait timed out\n");
+                       rv = -ETIME;
+                       goto exit;
+               }
+
+               tag = data->bNotify1 & 0x7f;
+               if (tag != data->iin_bTag) {
+                       dev_err(dev, "expected bTag %x got %x\n",
+                               data->iin_bTag, tag);
+               }
+
+               stb = data->bNotify2;
+       } else {
+               stb = buffer[2];
+       }
+
+       rv = copy_to_user(arg, &stb, sizeof(stb));
+       if (rv)
+               rv = -EFAULT;
+
+ exit:
+       /* bump interrupt bTag */
+       data->iin_bTag += 1;
+       if (data->iin_bTag > 127)
+               /* 1 is for SRQ see USBTMC-USB488 subclass spec section 4.3.1 */
+               data->iin_bTag = 2;
+
+       kfree(buffer);
+       return rv;
+}
+
+static int usbtmc488_ioctl_simple(struct usbtmc_device_data *data,
+                               void __user *arg, unsigned int cmd)
+{
+       struct device *dev = &data->intf->dev;
+       __u8 val;
+       u8 *buffer;
+       u16 wValue;
+       int rv;
+
+       if (!(data->usb488_caps & USBTMC488_CAPABILITY_SIMPLE))
+               return -EINVAL;
+
+       buffer = kmalloc(8, GFP_KERNEL);
+       if (!buffer)
+               return -ENOMEM;
+
+       if (cmd == USBTMC488_REQUEST_REN_CONTROL) {
+               rv = copy_from_user(&val, arg, sizeof(val));
+               if (rv) {
+                       rv = -EFAULT;
+                       goto exit;
+               }
+               wValue = val ? 1 : 0;
+       } else {
+               wValue = 0;
+       }
+
+       rv = usb_control_msg(data->usb_dev,
+                       usb_rcvctrlpipe(data->usb_dev, 0),
+                       cmd,
+                       USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
+                       wValue,
+                       data->ifnum,
+                       buffer, 0x01, USBTMC_TIMEOUT);
+       if (rv < 0) {
+               dev_err(dev, "simple usb_control_msg failed %d\n", rv);
+               goto exit;
+       } else if (rv != 1) {
+               dev_warn(dev, "simple usb_control_msg returned %d\n", rv);
+               rv = -EIO;
+               goto exit;
+       }
+
+       if (buffer[0] != USBTMC_STATUS_SUCCESS) {
+               dev_err(dev, "simple control status returned %x\n", buffer[0]);
+               rv = -EIO;
+               goto exit;
+       }
+       rv = 0;
+
+ exit:
+       kfree(buffer);
+       return rv;
+}
+
 /*
  * Sends a REQUEST_DEV_DEP_MSG_IN message on the Bulk-IN endpoint.
  * @transfer_size: number of bytes to request from the device.
@@ -895,6 +1051,7 @@ static int get_capabilities(struct usbtmc_device_data *data)
        data->capabilities.device_capabilities = buffer[5];
        data->capabilities.usb488_interface_capabilities = buffer[14];
        data->capabilities.usb488_device_capabilities = buffer[15];
+       data->usb488_caps = (buffer[14] & 0x07) | ((buffer[15] & 0x0f) << 4);
        rv = 0;
 
 err_out:
@@ -1069,6 +1226,33 @@ static long usbtmc_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        case USBTMC_IOCTL_ABORT_BULK_IN:
                retval = usbtmc_ioctl_abort_bulk_in(data);
                break;
+
+       case USBTMC488_IOCTL_GET_CAPS:
+               retval = copy_to_user((void __user *)arg,
+                               &data->usb488_caps,
+                               sizeof(data->usb488_caps));
+               if (retval)
+                       retval = -EFAULT;
+               break;
+
+       case USBTMC488_IOCTL_READ_STB:
+               retval = usbtmc488_ioctl_read_stb(data, (void __user *)arg);
+               break;
+
+       case USBTMC488_IOCTL_REN_CONTROL:
+               retval = usbtmc488_ioctl_simple(data, (void __user *)arg,
+                                               USBTMC488_REQUEST_REN_CONTROL);
+               break;
+
+       case USBTMC488_IOCTL_GOTO_LOCAL:
+               retval = usbtmc488_ioctl_simple(data, (void __user *)arg,
+                                               USBTMC488_REQUEST_GOTO_LOCAL);
+               break;
+
+       case USBTMC488_IOCTL_LOCAL_LOCKOUT:
+               retval = usbtmc488_ioctl_simple(data, (void __user *)arg,
+                                               USBTMC488_REQUEST_LOCAL_LOCKOUT);
+               break;
        }
 
 skip_io_on_zombie:
@@ -1076,6 +1260,34 @@ skip_io_on_zombie:
        return retval;
 }
 
+static int usbtmc_fasync(int fd, struct file *file, int on)
+{
+       struct usbtmc_device_data *data = file->private_data;
+
+       return fasync_helper(fd, file, on, &data->fasync);
+}
+
+static unsigned int usbtmc_poll(struct file *file, poll_table *wait)
+{
+       struct usbtmc_device_data *data = file->private_data;
+       unsigned int mask;
+
+       mutex_lock(&data->io_mutex);
+
+       if (data->zombie) {
+               mask = POLLHUP | POLLERR;
+               goto no_poll;
+       }
+
+       poll_wait(file, &data->waitq, wait);
+
+       mask = (atomic_read(&data->srq_asserted)) ? POLLIN | POLLRDNORM : 0;
+
+no_poll:
+       mutex_unlock(&data->io_mutex);
+       return mask;
+}
+
 static const struct file_operations fops = {
        .owner          = THIS_MODULE,
        .read           = usbtmc_read,
@@ -1083,6 +1295,8 @@ static const struct file_operations fops = {
        .open           = usbtmc_open,
        .release        = usbtmc_release,
        .unlocked_ioctl = usbtmc_ioctl,
+       .fasync         = usbtmc_fasync,
+       .poll           = usbtmc_poll,
        .llseek         = default_llseek,
 };
 
@@ -1092,6 +1306,67 @@ static struct usb_class_driver usbtmc_class = {
        .minor_base =   USBTMC_MINOR_BASE,
 };
 
+static void usbtmc_interrupt(struct urb *urb)
+{
+       struct usbtmc_device_data *data = urb->context;
+       struct device *dev = &data->intf->dev;
+       int status = urb->status;
+       int rv;
+
+       dev_dbg(&data->intf->dev, "int status: %d len %d\n",
+               status, urb->actual_length);
+
+       switch (status) {
+       case 0: /* SUCCESS */
+               /* check for valid STB notification */
+               if (data->iin_buffer[0] > 0x81) {
+                       data->bNotify1 = data->iin_buffer[0];
+                       data->bNotify2 = data->iin_buffer[1];
+                       atomic_set(&data->iin_data_valid, 1);
+                       wake_up_interruptible(&data->waitq);
+                       goto exit;
+               }
+               /* check for SRQ notification */
+               if (data->iin_buffer[0] == 0x81) {
+                       if (data->fasync)
+                               kill_fasync(&data->fasync,
+                                       SIGIO, POLL_IN);
+
+                       atomic_set(&data->srq_asserted, 1);
+                       wake_up_interruptible(&data->waitq);
+                       goto exit;
+               }
+               dev_warn(dev, "invalid notification: %x\n", data->iin_buffer[0]);
+               break;
+       case -EOVERFLOW:
+               dev_err(dev, "overflow with length %d, actual length is %d\n",
+                       data->iin_wMaxPacketSize, urb->actual_length);
+       case -ECONNRESET:
+       case -ENOENT:
+       case -ESHUTDOWN:
+       case -EILSEQ:
+       case -ETIME:
+               /* urb terminated, clean up */
+               dev_dbg(dev, "urb terminated, status: %d\n", status);
+               return;
+       default:
+               dev_err(dev, "unknown status received: %d\n", status);
+       }
+exit:
+       rv = usb_submit_urb(urb, GFP_ATOMIC);
+       if (rv)
+               dev_err(dev, "usb_submit_urb failed: %d\n", rv);
+}
+
+static void usbtmc_free_int(struct usbtmc_device_data *data)
+{
+       if (!data->iin_ep_present || !data->iin_urb)
+               return;
+       usb_kill_urb(data->iin_urb);
+       kfree(data->iin_buffer);
+       usb_free_urb(data->iin_urb);
+       kref_put(&data->kref, usbtmc_delete);
+}
 
 static int usbtmc_probe(struct usb_interface *intf,
                        const struct usb_device_id *id)
@@ -1114,6 +1389,9 @@ static int usbtmc_probe(struct usb_interface *intf,
        usb_set_intfdata(intf, data);
        kref_init(&data->kref);
        mutex_init(&data->io_mutex);
+       init_waitqueue_head(&data->waitq);
+       atomic_set(&data->iin_data_valid, 0);
+       atomic_set(&data->srq_asserted, 0);
        data->zombie = 0;
 
        /* Determine if it is a Rigol or not */
@@ -1134,9 +1412,12 @@ static int usbtmc_probe(struct usb_interface *intf,
        data->bTag      = 1;
        data->TermCharEnabled = 0;
        data->TermChar = '\n';
+       /*  2 <= bTag <= 127   USBTMC-USB488 subclass specification 4.3.1 */
+       data->iin_bTag = 2;
 
        /* USBTMC devices have only one setting, so use that */
        iface_desc = data->intf->cur_altsetting;
+       data->ifnum = iface_desc->desc.bInterfaceNumber;
 
        /* Find bulk in endpoint */
        for (n = 0; n < iface_desc->desc.bNumEndpoints; n++) {
@@ -1161,6 +1442,20 @@ static int usbtmc_probe(struct usb_interface *intf,
                        break;
                }
        }
+       /* Find int endpoint */
+       for (n = 0; n < iface_desc->desc.bNumEndpoints; n++) {
+               endpoint = &iface_desc->endpoint[n].desc;
+
+               if (usb_endpoint_is_int_in(endpoint)) {
+                       data->iin_ep_present = 1;
+                       data->iin_ep = endpoint->bEndpointAddress;
+                       data->iin_wMaxPacketSize = usb_endpoint_maxp(endpoint);
+                       data->iin_interval = endpoint->bInterval;
+                       dev_dbg(&intf->dev, "Found Int in endpoint at %u\n",
+                               data->iin_ep);
+                       break;
+               }
+       }
 
        retcode = get_capabilities(data);
        if (retcode)
@@ -1169,6 +1464,39 @@ static int usbtmc_probe(struct usb_interface *intf,
                retcode = sysfs_create_group(&intf->dev.kobj,
                                             &capability_attr_grp);
 
+       if (data->iin_ep_present) {
+               /* allocate int urb */
+               data->iin_urb = usb_alloc_urb(0, GFP_KERNEL);
+               if (!data->iin_urb) {
+                       dev_err(&intf->dev, "Failed to allocate int urb\n");
+                       goto error_register;
+               }
+
+               /* will reference data in int urb */
+               kref_get(&data->kref);
+
+               /* allocate buffer for interrupt in */
+               data->iin_buffer = kmalloc(data->iin_wMaxPacketSize,
+                                       GFP_KERNEL);
+               if (!data->iin_buffer) {
+                       dev_err(&intf->dev, "Failed to allocate int buf\n");
+                       goto error_register;
+               }
+
+               /* fill interrupt urb */
+               usb_fill_int_urb(data->iin_urb, data->usb_dev,
+                               usb_rcvintpipe(data->usb_dev, data->iin_ep),
+                               data->iin_buffer, data->iin_wMaxPacketSize,
+                               usbtmc_interrupt,
+                               data, data->iin_interval);
+
+               retcode = usb_submit_urb(data->iin_urb, GFP_KERNEL);
+               if (retcode) {
+                       dev_err(&intf->dev, "Failed to submit iin_urb\n");
+                       goto error_register;
+               }
+       }
+
        retcode = sysfs_create_group(&intf->dev.kobj, &data_attr_grp);
 
        retcode = usb_register_dev(intf, &usbtmc_class);
@@ -1185,6 +1513,7 @@ static int usbtmc_probe(struct usb_interface *intf,
 error_register:
        sysfs_remove_group(&intf->dev.kobj, &capability_attr_grp);
        sysfs_remove_group(&intf->dev.kobj, &data_attr_grp);
+       usbtmc_free_int(data);
        kref_put(&data->kref, usbtmc_delete);
        return retcode;
 }
@@ -1201,7 +1530,9 @@ static void usbtmc_disconnect(struct usb_interface *intf)
        sysfs_remove_group(&intf->dev.kobj, &data_attr_grp);
        mutex_lock(&data->io_mutex);
        data->zombie = 1;
+       wake_up_all(&data->waitq);
        mutex_unlock(&data->io_mutex);
+       usbtmc_free_int(data);
        kref_put(&data->kref, usbtmc_delete);
 }
 
index e6ec125..49fbfe8 100644 (file)
@@ -51,6 +51,7 @@ static const char *const speed_names[] = {
        [USB_SPEED_HIGH] = "high-speed",
        [USB_SPEED_WIRELESS] = "wireless",
        [USB_SPEED_SUPER] = "super-speed",
+       [USB_SPEED_SUPER_PLUS] = "super-speed-plus",
 };
 
 const char *usb_speed_string(enum usb_device_speed speed)
index 89f2e77..2741566 100644 (file)
@@ -62,8 +62,9 @@ int hcd_buffer_create(struct usb_hcd *hcd)
        char            name[16];
        int             i, size;
 
-       if (!hcd->self.controller->dma_mask &&
-           !(hcd->driver->flags & HCD_LOCAL_MEM))
+       if (!IS_ENABLED(CONFIG_HAS_DMA) ||
+           (!hcd->self.controller->dma_mask &&
+            !(hcd->driver->flags & HCD_LOCAL_MEM)))
                return 0;
 
        for (i = 0; i < HCD_BUFFER_POOLS; i++) {
@@ -93,6 +94,9 @@ void hcd_buffer_destroy(struct usb_hcd *hcd)
 {
        int i;
 
+       if (!IS_ENABLED(CONFIG_HAS_DMA))
+               return;
+
        for (i = 0; i < HCD_BUFFER_POOLS; i++) {
                struct dma_pool *pool = hcd->pool[i];
 
@@ -119,8 +123,9 @@ void *hcd_buffer_alloc(
        int                     i;
 
        /* some USB hosts just use PIO */
-       if (!bus->controller->dma_mask &&
-           !(hcd->driver->flags & HCD_LOCAL_MEM)) {
+       if (!IS_ENABLED(CONFIG_HAS_DMA) ||
+           (!bus->controller->dma_mask &&
+            !(hcd->driver->flags & HCD_LOCAL_MEM))) {
                *dma = ~(dma_addr_t) 0;
                return kmalloc(size, mem_flags);
        }
@@ -145,8 +150,9 @@ void hcd_buffer_free(
        if (!addr)
                return;
 
-       if (!bus->controller->dma_mask &&
-           !(hcd->driver->flags & HCD_LOCAL_MEM)) {
+       if (!IS_ENABLED(CONFIG_HAS_DMA) ||
+           (!bus->controller->dma_mask &&
+            !(hcd->driver->flags & HCD_LOCAL_MEM))) {
                kfree(addr);
                return;
        }
index 5050760..5eb1a87 100644 (file)
@@ -43,6 +43,27 @@ static int find_next_descriptor(unsigned char *buffer, int size,
        return buffer - buffer0;
 }
 
+static void usb_parse_ssp_isoc_endpoint_companion(struct device *ddev,
+               int cfgno, int inum, int asnum, struct usb_host_endpoint *ep,
+               unsigned char *buffer, int size)
+{
+       struct usb_ssp_isoc_ep_comp_descriptor *desc;
+
+       /*
+        * The SuperSpeedPlus Isoc endpoint companion descriptor immediately
+        * follows the SuperSpeed Endpoint Companion descriptor
+        */
+       desc = (struct usb_ssp_isoc_ep_comp_descriptor *) buffer;
+       if (desc->bDescriptorType != USB_DT_SSP_ISOC_ENDPOINT_COMP ||
+           size < USB_DT_SSP_ISOC_EP_COMP_SIZE) {
+               dev_warn(ddev, "Invalid SuperSpeedPlus isoc endpoint companion"
+                        "for config %d interface %d altsetting %d ep %d.\n",
+                        cfgno, inum, asnum, ep->desc.bEndpointAddress);
+               return;
+       }
+       memcpy(&ep->ssp_isoc_ep_comp, desc, USB_DT_SSP_ISOC_EP_COMP_SIZE);
+}
+
 static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
                int inum, int asnum, struct usb_host_endpoint *ep,
                unsigned char *buffer, int size)
@@ -54,6 +75,9 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
         * be the first thing immediately following the endpoint descriptor.
         */
        desc = (struct usb_ss_ep_comp_descriptor *) buffer;
+       buffer += desc->bLength;
+       size -= desc->bLength;
+
        if (desc->bDescriptorType != USB_DT_SS_ENDPOINT_COMP ||
                        size < USB_DT_SS_EP_COMP_SIZE) {
                dev_warn(ddev, "No SuperSpeed endpoint companion for config %d "
@@ -112,6 +136,7 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
                                cfgno, inum, asnum, ep->desc.bEndpointAddress);
                ep->ss_ep_comp.bmAttributes = 16;
        } else if (usb_endpoint_xfer_isoc(&ep->desc) &&
+                  !USB_SS_SSP_ISOC_COMP(desc->bmAttributes) &&
                   USB_SS_MULT(desc->bmAttributes) > 3) {
                dev_warn(ddev, "Isoc endpoint has Mult of %d in "
                                "config %d interface %d altsetting %d ep %d: "
@@ -121,6 +146,12 @@ static void usb_parse_ss_endpoint_companion(struct device *ddev, int cfgno,
                ep->ss_ep_comp.bmAttributes = 2;
        }
 
+       /* Parse a possible SuperSpeedPlus isoc ep companion descriptor */
+       if (usb_endpoint_xfer_isoc(&ep->desc) &&
+           USB_SS_SSP_ISOC_COMP(desc->bmAttributes))
+               usb_parse_ssp_isoc_endpoint_companion(ddev, cfgno, inum, asnum,
+                                                       ep, buffer, size);
+
        if (usb_endpoint_xfer_isoc(&ep->desc))
                max_tx = (desc->bMaxBurst + 1) *
                        (USB_SS_MULT(desc->bmAttributes)) *
@@ -191,6 +222,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
        if (usb_endpoint_xfer_int(d)) {
                i = 1;
                switch (to_usb_device(ddev)->speed) {
+               case USB_SPEED_SUPER_PLUS:
                case USB_SPEED_SUPER:
                case USB_SPEED_HIGH:
                        /* Many device manufacturers are using full-speed
@@ -274,7 +306,7 @@ static int usb_parse_endpoint(struct device *ddev, int cfgno, int inum,
        }
 
        /* Parse a possible SuperSpeed endpoint companion descriptor */
-       if (to_usb_device(ddev)->speed == USB_SPEED_SUPER)
+       if (to_usb_device(ddev)->speed >= USB_SPEED_SUPER)
                usb_parse_ss_endpoint_companion(ddev, cfgno,
                                inum, asnum, endpoint, buffer, size);
 
@@ -862,6 +894,9 @@ int usb_get_bos_descriptor(struct usb_device *dev)
                        dev->bos->ss_id =
                                (struct usb_ss_container_id_descriptor *)buffer;
                        break;
+               case USB_PTM_CAP_TYPE:
+                       dev->bos->ptm_cap =
+                               (struct usb_ptm_cap_descriptor *)buffer;
                default:
                        break;
                }
index cffa0a0..ef04b50 100644 (file)
@@ -110,13 +110,6 @@ static const char format_endpt[] =
 /* E:  Ad=xx(s) Atr=xx(ssss) MxPS=dddd Ivl=D?s */
   "E:  Ad=%02x(%c) Atr=%02x(%-4s) MxPS=%4d Ivl=%d%cs\n";
 
-
-/*
- * Need access to the driver and USB bus lists.
- * extern struct list_head usb_bus_list;
- * However, these will come from functions that return ptrs to each of them.
- */
-
 /*
  * Wait for an connect/disconnect event to happen. We initialize
  * the event counter with an odd number, and each event will increment
@@ -221,7 +214,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
                break;
        case USB_ENDPOINT_XFER_INT:
                type = "Int.";
-               if (speed == USB_SPEED_HIGH || speed == USB_SPEED_SUPER)
+               if (speed == USB_SPEED_HIGH || speed >= USB_SPEED_SUPER)
                        interval = 1 << (desc->bInterval - 1);
                else
                        interval = desc->bInterval;
@@ -230,7 +223,7 @@ static char *usb_dump_endpoint_descriptor(int speed, char *start, char *end,
                return start;
        }
        interval *= (speed == USB_SPEED_HIGH ||
-                    speed == USB_SPEED_SUPER) ? 125 : 1000;
+                    speed >= USB_SPEED_SUPER) ? 125 : 1000;
        if (interval % 1000)
                unit = 'u';
        else {
@@ -322,7 +315,7 @@ static char *usb_dump_config_descriptor(char *start, char *end,
 
        if (start > end)
                return start;
-       if (speed == USB_SPEED_SUPER)
+       if (speed >= USB_SPEED_SUPER)
                mul = 8;
        else
                mul = 2;
@@ -534,6 +527,8 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
                speed = "480"; break;
        case USB_SPEED_SUPER:
                speed = "5000"; break;
+       case USB_SPEED_SUPER_PLUS:
+               speed = "10000"; break;
        default:
                speed = "??";
        }
@@ -553,7 +548,7 @@ static ssize_t usb_device_dump(char __user **buffer, size_t *nbytes,
 
                /* super/high speed reserves 80%, full/low reserves 90% */
                if (usbdev->speed == USB_SPEED_HIGH ||
-                   usbdev->speed == USB_SPEED_SUPER)
+                   usbdev->speed >= USB_SPEED_SUPER)
                        max = 800;
                else
                        max = FRAME_TIME_MAX_USECS_ALLOC;
@@ -616,6 +611,7 @@ static ssize_t usb_device_read(struct file *file, char __user *buf,
        struct usb_bus *bus;
        ssize_t ret, total_written = 0;
        loff_t skip_bytes = *ppos;
+       int id;
 
        if (*ppos < 0)
                return -EINVAL;
@@ -624,9 +620,9 @@ static ssize_t usb_device_read(struct file *file, char __user *buf,
        if (!access_ok(VERIFY_WRITE, buf, nbytes))
                return -EFAULT;
 
-       mutex_lock(&usb_bus_list_lock);
+       mutex_lock(&usb_bus_idr_lock);
        /* print devices for all busses */
-       list_for_each_entry(bus, &usb_bus_list, bus_list) {
+       idr_for_each_entry(&usb_bus_idr, bus, id) {
                /* recurse through all children of the root hub */
                if (!bus_to_hcd(bus)->rh_registered)
                        continue;
@@ -635,12 +631,12 @@ static ssize_t usb_device_read(struct file *file, char __user *buf,
                                      bus->root_hub, bus, 0, 0, 0);
                usb_unlock_device(bus->root_hub);
                if (ret < 0) {
-                       mutex_unlock(&usb_bus_list_lock);
+                       mutex_unlock(&usb_bus_idr_lock);
                        return ret;
                }
                total_written += ret;
        }
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_unlock(&usb_bus_idr_lock);
        return total_written;
 }
 
index 59e7a33..39da166 100644 (file)
@@ -50,6 +50,7 @@
 #include <linux/user_namespace.h>
 #include <linux/scatterlist.h>
 #include <linux/uaccess.h>
+#include <linux/dma-mapping.h>
 #include <asm/byteorder.h>
 #include <linux/moduleparam.h>
 
@@ -69,6 +70,7 @@ struct usb_dev_state {
        spinlock_t lock;            /* protects the async urb lists */
        struct list_head async_pending;
        struct list_head async_completed;
+       struct list_head memory_list;
        wait_queue_head_t wait;     /* wake up if a request completed */
        unsigned int discsignr;
        struct pid *disc_pid;
@@ -79,6 +81,17 @@ struct usb_dev_state {
        u32 disabled_bulk_eps;
 };
 
+struct usb_memory {
+       struct list_head memlist;
+       int vma_use_count;
+       int urb_use_count;
+       u32 size;
+       void *mem;
+       dma_addr_t dma_handle;
+       unsigned long vm_start;
+       struct usb_dev_state *ps;
+};
+
 struct async {
        struct list_head asynclist;
        struct usb_dev_state *ps;
@@ -89,6 +102,7 @@ struct async {
        void __user *userbuffer;
        void __user *userurb;
        struct urb *urb;
+       struct usb_memory *usbm;
        unsigned int mem_usage;
        int status;
        u32 secid;
@@ -162,6 +176,111 @@ static int connected(struct usb_dev_state *ps)
                        ps->dev->state != USB_STATE_NOTATTACHED);
 }
 
+static void dec_usb_memory_use_count(struct usb_memory *usbm, int *count)
+{
+       struct usb_dev_state *ps = usbm->ps;
+       unsigned long flags;
+
+       spin_lock_irqsave(&ps->lock, flags);
+       --*count;
+       if (usbm->urb_use_count == 0 && usbm->vma_use_count == 0) {
+               list_del(&usbm->memlist);
+               spin_unlock_irqrestore(&ps->lock, flags);
+
+               usb_free_coherent(ps->dev, usbm->size, usbm->mem,
+                               usbm->dma_handle);
+               usbfs_decrease_memory_usage(
+                       usbm->size + sizeof(struct usb_memory));
+               kfree(usbm);
+       } else {
+               spin_unlock_irqrestore(&ps->lock, flags);
+       }
+}
+
+static void usbdev_vm_open(struct vm_area_struct *vma)
+{
+       struct usb_memory *usbm = vma->vm_private_data;
+       unsigned long flags;
+
+       spin_lock_irqsave(&usbm->ps->lock, flags);
+       ++usbm->vma_use_count;
+       spin_unlock_irqrestore(&usbm->ps->lock, flags);
+}
+
+static void usbdev_vm_close(struct vm_area_struct *vma)
+{
+       struct usb_memory *usbm = vma->vm_private_data;
+
+       dec_usb_memory_use_count(usbm, &usbm->vma_use_count);
+}
+
+struct vm_operations_struct usbdev_vm_ops = {
+       .open = usbdev_vm_open,
+       .close = usbdev_vm_close
+};
+
+static int usbdev_mmap(struct file *file, struct vm_area_struct *vma)
+{
+       struct usb_memory *usbm = NULL;
+       struct usb_dev_state *ps = file->private_data;
+       size_t size = vma->vm_end - vma->vm_start;
+       void *mem;
+       unsigned long flags;
+       dma_addr_t dma_handle;
+       int ret;
+
+       ret = usbfs_increase_memory_usage(size + sizeof(struct usb_memory));
+       if (ret)
+               goto error;
+
+       usbm = kzalloc(sizeof(struct usb_memory), GFP_KERNEL);
+       if (!usbm) {
+               ret = -ENOMEM;
+               goto error_decrease_mem;
+       }
+
+       mem = usb_alloc_coherent(ps->dev, size, GFP_USER, &dma_handle);
+       if (!mem) {
+               ret = -ENOMEM;
+               goto error_free_usbm;
+       }
+
+       memset(mem, 0, size);
+
+       usbm->mem = mem;
+       usbm->dma_handle = dma_handle;
+       usbm->size = size;
+       usbm->ps = ps;
+       usbm->vm_start = vma->vm_start;
+       usbm->vma_use_count = 1;
+       INIT_LIST_HEAD(&usbm->memlist);
+
+       if (remap_pfn_range(vma, vma->vm_start,
+                       virt_to_phys(usbm->mem) >> PAGE_SHIFT,
+                       size, vma->vm_page_prot) < 0) {
+               dec_usb_memory_use_count(usbm, &usbm->vma_use_count);
+               return -EAGAIN;
+       }
+
+       vma->vm_flags |= VM_IO;
+       vma->vm_flags |= (VM_DONTEXPAND | VM_DONTDUMP);
+       vma->vm_ops = &usbdev_vm_ops;
+       vma->vm_private_data = usbm;
+
+       spin_lock_irqsave(&ps->lock, flags);
+       list_add_tail(&usbm->memlist, &ps->memory_list);
+       spin_unlock_irqrestore(&ps->lock, flags);
+
+       return 0;
+
+error_free_usbm:
+       kfree(usbm);
+error_decrease_mem:
+       usbfs_decrease_memory_usage(size + sizeof(struct usb_memory));
+error:
+       return ret;
+}
+
 static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
                           loff_t *ppos)
 {
@@ -278,8 +397,13 @@ static void free_async(struct async *as)
                if (sg_page(&as->urb->sg[i]))
                        kfree(sg_virt(&as->urb->sg[i]));
        }
+
        kfree(as->urb->sg);
-       kfree(as->urb->transfer_buffer);
+       if (as->usbm == NULL)
+               kfree(as->urb->transfer_buffer);
+       else
+               dec_usb_memory_use_count(as->usbm, &as->usbm->urb_use_count);
+
        kfree(as->urb->setup_packet);
        usb_free_urb(as->urb);
        usbfs_decrease_memory_usage(as->mem_usage);
@@ -848,7 +972,7 @@ static struct usb_device *usbdev_lookup_by_devt(dev_t devt)
                              (void *) (unsigned long) devt, match_devt);
        if (!dev)
                return NULL;
-       return container_of(dev, struct usb_device, dev);
+       return to_usb_device(dev);
 }
 
 /*
@@ -893,6 +1017,7 @@ static int usbdev_open(struct inode *inode, struct file *file)
        INIT_LIST_HEAD(&ps->list);
        INIT_LIST_HEAD(&ps->async_pending);
        INIT_LIST_HEAD(&ps->async_completed);
+       INIT_LIST_HEAD(&ps->memory_list);
        init_waitqueue_head(&ps->wait);
        ps->discsignr = 0;
        ps->disc_pid = get_pid(task_pid(current));
@@ -945,6 +1070,7 @@ static int usbdev_release(struct inode *inode, struct file *file)
                free_async(as);
                as = async_getcompleted(ps);
        }
+
        kfree(ps);
        return 0;
 }
@@ -1266,6 +1392,31 @@ static int proc_setconfig(struct usb_dev_state *ps, void __user *arg)
        return status;
 }
 
+static struct usb_memory *
+find_memory_area(struct usb_dev_state *ps, const struct usbdevfs_urb *uurb)
+{
+       struct usb_memory *usbm = NULL, *iter;
+       unsigned long flags;
+       unsigned long uurb_start = (unsigned long)uurb->buffer;
+
+       spin_lock_irqsave(&ps->lock, flags);
+       list_for_each_entry(iter, &ps->memory_list, memlist) {
+               if (uurb_start >= iter->vm_start &&
+                               uurb_start < iter->vm_start + iter->size) {
+                       if (uurb->buffer_length > iter->vm_start + iter->size -
+                                       uurb_start) {
+                               usbm = ERR_PTR(-EINVAL);
+                       } else {
+                               usbm = iter;
+                               usbm->urb_use_count++;
+                       }
+                       break;
+               }
+       }
+       spin_unlock_irqrestore(&ps->lock, flags);
+       return usbm;
+}
+
 static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb,
                        struct usbdevfs_iso_packet_desc __user *iso_frame_desc,
                        void __user *arg)
@@ -1378,11 +1529,10 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
                number_of_packets = uurb->number_of_packets;
                isofrmlen = sizeof(struct usbdevfs_iso_packet_desc) *
                                   number_of_packets;
-               isopkt = kmalloc(isofrmlen, GFP_KERNEL);
-               if (!isopkt)
-                       return -ENOMEM;
-               if (copy_from_user(isopkt, iso_frame_desc, isofrmlen)) {
-                       ret = -EFAULT;
+               isopkt = memdup_user(iso_frame_desc, isofrmlen);
+               if (IS_ERR(isopkt)) {
+                       ret = PTR_ERR(isopkt);
+                       isopkt = NULL;
                        goto error;
                }
                for (totlen = u = 0; u < number_of_packets; u++) {
@@ -1422,6 +1572,19 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
                goto error;
        }
 
+       as->usbm = find_memory_area(ps, uurb);
+       if (IS_ERR(as->usbm)) {
+               ret = PTR_ERR(as->usbm);
+               as->usbm = NULL;
+               goto error;
+       }
+
+       /* do not use SG buffers when memory mapped segments
+        * are in use
+        */
+       if (as->usbm)
+               num_sgs = 0;
+
        u += sizeof(struct async) + sizeof(struct urb) + uurb->buffer_length +
             num_sgs * sizeof(struct scatterlist);
        ret = usbfs_increase_memory_usage(u);
@@ -1459,29 +1622,35 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
                        totlen -= u;
                }
        } else if (uurb->buffer_length > 0) {
-               as->urb->transfer_buffer = kmalloc(uurb->buffer_length,
-                               GFP_KERNEL);
-               if (!as->urb->transfer_buffer) {
-                       ret = -ENOMEM;
-                       goto error;
-               }
+               if (as->usbm) {
+                       unsigned long uurb_start = (unsigned long)uurb->buffer;
 
-               if (!is_in) {
-                       if (copy_from_user(as->urb->transfer_buffer,
-                                          uurb->buffer,
-                                          uurb->buffer_length)) {
-                               ret = -EFAULT;
+                       as->urb->transfer_buffer = as->usbm->mem +
+                                       (uurb_start - as->usbm->vm_start);
+               } else {
+                       as->urb->transfer_buffer = kmalloc(uurb->buffer_length,
+                                       GFP_KERNEL);
+                       if (!as->urb->transfer_buffer) {
+                               ret = -ENOMEM;
                                goto error;
                        }
-               } else if (uurb->type == USBDEVFS_URB_TYPE_ISO) {
-                       /*
-                        * Isochronous input data may end up being
-                        * discontiguous if some of the packets are short.
-                        * Clear the buffer so that the gaps don't leak
-                        * kernel data to userspace.
-                        */
-                       memset(as->urb->transfer_buffer, 0,
-                                       uurb->buffer_length);
+                       if (!is_in) {
+                               if (copy_from_user(as->urb->transfer_buffer,
+                                                  uurb->buffer,
+                                                  uurb->buffer_length)) {
+                                       ret = -EFAULT;
+                                       goto error;
+                               }
+                       } else if (uurb->type == USBDEVFS_URB_TYPE_ISO) {
+                               /*
+                                * Isochronous input data may end up being
+                                * discontiguous if some of the packets are
+                                * short. Clear the buffer so that the gaps
+                                * don't leak kernel data to userspace.
+                                */
+                               memset(as->urb->transfer_buffer, 0,
+                                               uurb->buffer_length);
+                       }
                }
        }
        as->urb->dev = ps->dev;
@@ -1528,10 +1697,14 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
        isopkt = NULL;
        as->ps = ps;
        as->userurb = arg;
-       if (is_in && uurb->buffer_length > 0)
+       if (as->usbm) {
+               unsigned long uurb_start = (unsigned long)uurb->buffer;
+
+               as->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+               as->urb->transfer_dma = as->usbm->dma_handle +
+                               (uurb_start - as->usbm->vm_start);
+       } else if (is_in && uurb->buffer_length > 0)
                as->userbuffer = uurb->buffer;
-       else
-               as->userbuffer = NULL;
        as->signr = uurb->signr;
        as->ifnum = ifnum;
        as->pid = get_pid(task_pid(current));
@@ -1587,6 +1760,8 @@ static int proc_do_submiturb(struct usb_dev_state *ps, struct usbdevfs_urb *uurb
        return 0;
 
  error:
+       if (as && as->usbm)
+               dec_usb_memory_use_count(as->usbm, &as->usbm->urb_use_count);
        kfree(isopkt);
        kfree(dr);
        if (as)
@@ -1903,7 +2078,7 @@ static int proc_releaseinterface(struct usb_dev_state *ps, void __user *arg)
        ret = releaseintf(ps, ifnum);
        if (ret < 0)
                return ret;
-       destroy_async_on_interface (ps, ifnum);
+       destroy_async_on_interface(ps, ifnum);
        return 0;
 }
 
@@ -2040,7 +2215,7 @@ static int proc_get_capabilities(struct usb_dev_state *ps, void __user *arg)
        __u32 caps;
 
        caps = USBDEVFS_CAP_ZERO_PACKET | USBDEVFS_CAP_NO_PACKET_SIZE_LIM |
-                       USBDEVFS_CAP_REAP_AFTER_DISCONNECT;
+                       USBDEVFS_CAP_REAP_AFTER_DISCONNECT | USBDEVFS_CAP_MMAP;
        if (!ps->dev->bus->no_stop_on_short)
                caps |= USBDEVFS_CAP_BULK_CONTINUATION;
        if (ps->dev->bus->sg_tablesize)
@@ -2366,6 +2541,7 @@ const struct file_operations usbdev_file_operations = {
 #ifdef CONFIG_COMPAT
        .compat_ioctl =   usbdev_compat_ioctl,
 #endif
+       .mmap =           usbdev_mmap,
        .open =           usbdev_open,
        .release =        usbdev_release,
 };
index ea337a7..822ced9 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/errno.h>
 #include <linux/rwsem.h>
 #include <linux/slab.h>
+#include <linux/string.h>
 #include <linux/usb.h>
 
 #include "usb.h"
@@ -155,7 +156,6 @@ int usb_register_dev(struct usb_interface *intf,
        int minor_base = class_driver->minor_base;
        int minor;
        char name[20];
-       char *temp;
 
 #ifdef CONFIG_USB_DYNAMIC_MINORS
        /*
@@ -192,14 +192,9 @@ int usb_register_dev(struct usb_interface *intf,
 
        /* create a usb class device for this usb interface */
        snprintf(name, sizeof(name), class_driver->name, minor - minor_base);
-       temp = strrchr(name, '/');
-       if (temp && (temp[1] != '\0'))
-               ++temp;
-       else
-               temp = name;
        intf->usb_dev = device_create(usb_class->class, &intf->dev,
                                      MKDEV(USB_MAJOR, minor), class_driver,
-                                     "%s", temp);
+                                     "%s", kbasename(name));
        if (IS_ERR(intf->usb_dev)) {
                down_write(&minor_rwsem);
                usb_minors[minor] = NULL;
index 9eb1cff..22a9ac2 100644 (file)
@@ -197,7 +197,7 @@ int usb_hcd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
         * The xHCI driver has its own irq management
         * make sure irq setup is not touched for xhci in generic hcd code
         */
-       if ((driver->flags & HCD_MASK) != HCD_USB3) {
+       if ((driver->flags & HCD_MASK) < HCD_USB3) {
                if (!dev->irq) {
                        dev_err(&dev->dev,
                        "Found HC with no IRQ. Check BIOS/PCI %s setup!\n",
index df0e3b9..2ca2cef 100644 (file)
@@ -90,16 +90,15 @@ unsigned long usb_hcds_loaded;
 EXPORT_SYMBOL_GPL(usb_hcds_loaded);
 
 /* host controllers we manage */
-LIST_HEAD (usb_bus_list);
-EXPORT_SYMBOL_GPL (usb_bus_list);
+DEFINE_IDR (usb_bus_idr);
+EXPORT_SYMBOL_GPL (usb_bus_idr);
 
 /* used when allocating bus numbers */
 #define USB_MAXBUS             64
-static DECLARE_BITMAP(busmap, USB_MAXBUS);
 
 /* used when updating list of hcds */
-DEFINE_MUTEX(usb_bus_list_lock);       /* exported only for usbfs */
-EXPORT_SYMBOL_GPL (usb_bus_list_lock);
+DEFINE_MUTEX(usb_bus_idr_lock);        /* exported only for usbfs */
+EXPORT_SYMBOL_GPL (usb_bus_idr_lock);
 
 /* used for controlling access to virtual root hubs */
 static DEFINE_SPINLOCK(hcd_root_hub_lock);
@@ -128,6 +127,27 @@ static inline int is_root_hub(struct usb_device *udev)
 #define KERNEL_REL     bin2bcd(((LINUX_VERSION_CODE >> 16) & 0x0ff))
 #define KERNEL_VER     bin2bcd(((LINUX_VERSION_CODE >> 8) & 0x0ff))
 
+/* usb 3.1 root hub device descriptor */
+static const u8 usb31_rh_dev_descriptor[18] = {
+       0x12,       /*  __u8  bLength; */
+       USB_DT_DEVICE, /* __u8 bDescriptorType; Device */
+       0x10, 0x03, /*  __le16 bcdUSB; v3.1 */
+
+       0x09,       /*  __u8  bDeviceClass; HUB_CLASSCODE */
+       0x00,       /*  __u8  bDeviceSubClass; */
+       0x03,       /*  __u8  bDeviceProtocol; USB 3 hub */
+       0x09,       /*  __u8  bMaxPacketSize0; 2^9 = 512 Bytes */
+
+       0x6b, 0x1d, /*  __le16 idVendor; Linux Foundation 0x1d6b */
+       0x03, 0x00, /*  __le16 idProduct; device 0x0003 */
+       KERNEL_VER, KERNEL_REL, /*  __le16 bcdDevice */
+
+       0x03,       /*  __u8  iManufacturer; */
+       0x02,       /*  __u8  iProduct; */
+       0x01,       /*  __u8  iSerialNumber; */
+       0x01        /*  __u8  bNumConfigurations; */
+};
+
 /* usb 3.0 root hub device descriptor */
 static const u8 usb3_rh_dev_descriptor[18] = {
        0x12,       /*  __u8  bLength; */
@@ -557,6 +577,8 @@ static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
                case USB_DT_DEVICE << 8:
                        switch (hcd->speed) {
                        case HCD_USB31:
+                               bufp = usb31_rh_dev_descriptor;
+                               break;
                        case HCD_USB3:
                                bufp = usb3_rh_dev_descriptor;
                                break;
@@ -645,9 +667,15 @@ nongeneric:
                /* non-generic request */
                switch (typeReq) {
                case GetHubStatus:
-               case GetPortStatus:
                        len = 4;
                        break;
+               case GetPortStatus:
+                       if (wValue == HUB_PORT_STATUS)
+                               len = 4;
+                       else
+                               /* other port status types return 8 bytes */
+                               len = 8;
+                       break;
                case GetHubDescriptor:
                        len = sizeof (struct usb_hub_descriptor);
                        break;
@@ -967,8 +995,6 @@ static void usb_bus_init (struct usb_bus *bus)
        bus->bandwidth_int_reqs  = 0;
        bus->bandwidth_isoc_reqs = 0;
        mutex_init(&bus->usb_address0_mutex);
-
-       INIT_LIST_HEAD (&bus->bus_list);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -988,18 +1014,14 @@ static int usb_register_bus(struct usb_bus *bus)
        int result = -E2BIG;
        int busnum;
 
-       mutex_lock(&usb_bus_list_lock);
-       busnum = find_next_zero_bit(busmap, USB_MAXBUS, 1);
-       if (busnum >= USB_MAXBUS) {
-               printk (KERN_ERR "%s: too many buses\n", usbcore_name);
+       mutex_lock(&usb_bus_idr_lock);
+       busnum = idr_alloc(&usb_bus_idr, bus, 1, USB_MAXBUS, GFP_KERNEL);
+       if (busnum < 0) {
+               pr_err("%s: failed to get bus number\n", usbcore_name);
                goto error_find_busnum;
        }
-       set_bit(busnum, busmap);
        bus->busnum = busnum;
-
-       /* Add it to the local list of buses */
-       list_add (&bus->bus_list, &usb_bus_list);
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_unlock(&usb_bus_idr_lock);
 
        usb_notify_add_bus(bus);
 
@@ -1008,7 +1030,7 @@ static int usb_register_bus(struct usb_bus *bus)
        return 0;
 
 error_find_busnum:
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_unlock(&usb_bus_idr_lock);
        return result;
 }
 
@@ -1029,13 +1051,11 @@ static void usb_deregister_bus (struct usb_bus *bus)
         * controller code, as well as having it call this when cleaning
         * itself up
         */
-       mutex_lock(&usb_bus_list_lock);
-       list_del (&bus->bus_list);
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_lock(&usb_bus_idr_lock);
+       idr_remove(&usb_bus_idr, bus->busnum);
+       mutex_unlock(&usb_bus_idr_lock);
 
        usb_notify_remove_bus(bus);
-
-       clear_bit(bus->busnum, busmap);
 }
 
 /**
@@ -1063,12 +1083,12 @@ static int register_root_hub(struct usb_hcd *hcd)
        set_bit (devnum, usb_dev->bus->devmap.devicemap);
        usb_set_device_state(usb_dev, USB_STATE_ADDRESS);
 
-       mutex_lock(&usb_bus_list_lock);
+       mutex_lock(&usb_bus_idr_lock);
 
        usb_dev->ep0.desc.wMaxPacketSize = cpu_to_le16(64);
        retval = usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE);
        if (retval != sizeof usb_dev->descriptor) {
-               mutex_unlock(&usb_bus_list_lock);
+               mutex_unlock(&usb_bus_idr_lock);
                dev_dbg (parent_dev, "can't read %s device descriptor %d\n",
                                dev_name(&usb_dev->dev), retval);
                return (retval < 0) ? retval : -EMSGSIZE;
@@ -1078,8 +1098,8 @@ static int register_root_hub(struct usb_hcd *hcd)
                retval = usb_get_bos_descriptor(usb_dev);
                if (!retval) {
                        usb_dev->lpm_capable = usb_device_supports_lpm(usb_dev);
-               } else if (usb_dev->speed == USB_SPEED_SUPER) {
-                       mutex_unlock(&usb_bus_list_lock);
+               } else if (usb_dev->speed >= USB_SPEED_SUPER) {
+                       mutex_unlock(&usb_bus_idr_lock);
                        dev_dbg(parent_dev, "can't read %s bos descriptor %d\n",
                                        dev_name(&usb_dev->dev), retval);
                        return retval;
@@ -1099,7 +1119,7 @@ static int register_root_hub(struct usb_hcd *hcd)
                if (HCD_DEAD(hcd))
                        usb_hc_died (hcd);      /* This time clean up */
        }
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_unlock(&usb_bus_idr_lock);
 
        return retval;
 }
@@ -1408,7 +1428,8 @@ static void hcd_free_coherent(struct usb_bus *bus, dma_addr_t *dma_handle,
 
 void usb_hcd_unmap_urb_setup_for_dma(struct usb_hcd *hcd, struct urb *urb)
 {
-       if (urb->transfer_flags & URB_SETUP_MAP_SINGLE)
+       if (IS_ENABLED(CONFIG_HAS_DMA) &&
+           (urb->transfer_flags & URB_SETUP_MAP_SINGLE))
                dma_unmap_single(hcd->self.controller,
                                urb->setup_dma,
                                sizeof(struct usb_ctrlrequest),
@@ -1440,17 +1461,20 @@ void usb_hcd_unmap_urb_for_dma(struct usb_hcd *hcd, struct urb *urb)
        usb_hcd_unmap_urb_setup_for_dma(hcd, urb);
 
        dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
-       if (urb->transfer_flags & URB_DMA_MAP_SG)
+       if (IS_ENABLED(CONFIG_HAS_DMA) &&
+           (urb->transfer_flags & URB_DMA_MAP_SG))
                dma_unmap_sg(hcd->self.controller,
                                urb->sg,
                                urb->num_sgs,
                                dir);
-       else if (urb->transfer_flags & URB_DMA_MAP_PAGE)
+       else if (IS_ENABLED(CONFIG_HAS_DMA) &&
+                (urb->transfer_flags & URB_DMA_MAP_PAGE))
                dma_unmap_page(hcd->self.controller,
                                urb->transfer_dma,
                                urb->transfer_buffer_length,
                                dir);
-       else if (urb->transfer_flags & URB_DMA_MAP_SINGLE)
+       else if (IS_ENABLED(CONFIG_HAS_DMA) &&
+                (urb->transfer_flags & URB_DMA_MAP_SINGLE))
                dma_unmap_single(hcd->self.controller,
                                urb->transfer_dma,
                                urb->transfer_buffer_length,
@@ -1492,7 +1516,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
        if (usb_endpoint_xfer_control(&urb->ep->desc)) {
                if (hcd->self.uses_pio_for_control)
                        return ret;
-               if (hcd->self.uses_dma) {
+               if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
                        urb->setup_dma = dma_map_single(
                                        hcd->self.controller,
                                        urb->setup_packet,
@@ -1518,7 +1542,7 @@ int usb_hcd_map_urb_for_dma(struct usb_hcd *hcd, struct urb *urb,
        dir = usb_urb_dir_in(urb) ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
        if (urb->transfer_buffer_length != 0
            && !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)) {
-               if (hcd->self.uses_dma) {
+               if (IS_ENABLED(CONFIG_HAS_DMA) && hcd->self.uses_dma) {
                        if (urb->num_sgs) {
                                int n;
 
@@ -2112,7 +2136,7 @@ int usb_alloc_streams(struct usb_interface *interface,
        hcd = bus_to_hcd(dev->bus);
        if (!hcd->driver->alloc_streams || !hcd->driver->free_streams)
                return -EINVAL;
-       if (dev->speed != USB_SPEED_SUPER)
+       if (dev->speed < USB_SPEED_SUPER)
                return -EINVAL;
        if (dev->state < USB_STATE_CONFIGURED)
                return -ENODEV;
@@ -2160,7 +2184,7 @@ int usb_free_streams(struct usb_interface *interface,
 
        dev = interface_to_usbdev(interface);
        hcd = bus_to_hcd(dev->bus);
-       if (dev->speed != USB_SPEED_SUPER)
+       if (dev->speed < USB_SPEED_SUPER)
                return -EINVAL;
 
        /* Double-free is not allowed */
@@ -2208,7 +2232,7 @@ int usb_hcd_get_frame_number (struct usb_device *udev)
 
 int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
 {
-       struct usb_hcd  *hcd = container_of(rhdev->bus, struct usb_hcd, self);
+       struct usb_hcd  *hcd = bus_to_hcd(rhdev->bus);
        int             status;
        int             old_state = hcd->state;
 
@@ -2257,7 +2281,7 @@ int hcd_bus_suspend(struct usb_device *rhdev, pm_message_t msg)
 
 int hcd_bus_resume(struct usb_device *rhdev, pm_message_t msg)
 {
-       struct usb_hcd  *hcd = container_of(rhdev->bus, struct usb_hcd, self);
+       struct usb_hcd  *hcd = bus_to_hcd(rhdev->bus);
        int             status;
        int             old_state = hcd->state;
 
@@ -2371,7 +2395,7 @@ int usb_bus_start_enum(struct usb_bus *bus, unsigned port_num)
         * boards with root hubs hooked up to internal devices (instead of
         * just the OTG port) may need more attention to resetting...
         */
-       hcd = container_of (bus, struct usb_hcd, self);
+       hcd = bus_to_hcd(bus);
        if (port_num && hcd->driver->start_port_reset)
                status = hcd->driver->start_port_reset(hcd, port_num);
 
@@ -2778,9 +2802,11 @@ int usb_add_hcd(struct usb_hcd *hcd,
                rhdev->speed = USB_SPEED_WIRELESS;
                break;
        case HCD_USB3:
-       case HCD_USB31:
                rhdev->speed = USB_SPEED_SUPER;
                break;
+       case HCD_USB31:
+               rhdev->speed = USB_SPEED_SUPER_PLUS;
+               break;
        default:
                retval = -EINVAL;
                goto err_set_rh_speed;
@@ -2863,9 +2889,9 @@ error_create_attr_group:
 #ifdef CONFIG_PM
        cancel_work_sync(&hcd->wakeup_work);
 #endif
-       mutex_lock(&usb_bus_list_lock);
+       mutex_lock(&usb_bus_idr_lock);
        usb_disconnect(&rhdev);         /* Sets rhdev to NULL */
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_unlock(&usb_bus_idr_lock);
 err_register_root_hub:
        hcd->rh_pollable = 0;
        clear_bit(HCD_FLAG_POLL_RH, &hcd->flags);
@@ -2932,9 +2958,9 @@ void usb_remove_hcd(struct usb_hcd *hcd)
        cancel_work_sync(&hcd->wakeup_work);
 #endif
 
-       mutex_lock(&usb_bus_list_lock);
+       mutex_lock(&usb_bus_idr_lock);
        usb_disconnect(&rhdev);         /* Sets rhdev to NULL */
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_unlock(&usb_bus_idr_lock);
 
        /*
         * tasklet_kill() isn't needed here because:
index 51b4369..fa23967 100644 (file)
@@ -49,7 +49,7 @@ static void hub_event(struct work_struct *work);
 DEFINE_MUTEX(usb_port_peer_mutex);
 
 /* cycle leds on hubs that aren't blinking for attention */
-static bool blinkenlights = 0;
+static bool blinkenlights;
 module_param(blinkenlights, bool, S_IRUGO);
 MODULE_PARM_DESC(blinkenlights, "true to cycle leds on hubs");
 
@@ -78,7 +78,7 @@ MODULE_PARM_DESC(initial_descriptor_timeout,
  * otherwise the new scheme is used.  If that fails and "use_both_schemes"
  * is set, then the driver will make another attempt, using the other scheme.
  */
-static bool old_scheme_first = 0;
+static bool old_scheme_first;
 module_param(old_scheme_first, bool, S_IRUGO | S_IWUSR);
 MODULE_PARM_DESC(old_scheme_first,
                 "start with the old device initialization scheme");
@@ -298,7 +298,7 @@ static void usb_set_lpm_parameters(struct usb_device *udev)
        unsigned int hub_u1_del;
        unsigned int hub_u2_del;
 
-       if (!udev->lpm_capable || udev->speed != USB_SPEED_SUPER)
+       if (!udev->lpm_capable || udev->speed < USB_SPEED_SUPER)
                return;
 
        hub = usb_hub_to_struct_hub(udev->parent);
@@ -537,29 +537,34 @@ static int get_hub_status(struct usb_device *hdev,
 
 /*
  * USB 2.0 spec Section 11.24.2.7
+ * USB 3.1 takes into use the wValue and wLength fields, spec Section 10.16.2.6
  */
 static int get_port_status(struct usb_device *hdev, int port1,
-               struct usb_port_status *data)
+                          void *data, u16 value, u16 length)
 {
        int i, status = -ETIMEDOUT;
 
        for (i = 0; i < USB_STS_RETRIES &&
                        (status == -ETIMEDOUT || status == -EPIPE); i++) {
                status = usb_control_msg(hdev, usb_rcvctrlpipe(hdev, 0),
-                       USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port1,
-                       data, sizeof(*data), USB_STS_TIMEOUT);
+                       USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, value,
+                       port1, data, length, USB_STS_TIMEOUT);
        }
        return status;
 }
 
-static int hub_port_status(struct usb_hub *hub, int port1,
-               u16 *status, u16 *change)
+static int hub_ext_port_status(struct usb_hub *hub, int port1, int type,
+                              u16 *status, u16 *change, u32 *ext_status)
 {
        int ret;
+       int len = 4;
+
+       if (type != HUB_PORT_STATUS)
+               len = 8;
 
        mutex_lock(&hub->status_mutex);
-       ret = get_port_status(hub->hdev, port1, &hub->status->port);
-       if (ret < 4) {
+       ret = get_port_status(hub->hdev, port1, &hub->status->port, type, len);
+       if (ret < len) {
                if (ret != -ENODEV)
                        dev_err(hub->intfdev,
                                "%s failed (err = %d)\n", __func__, ret);
@@ -568,13 +573,22 @@ static int hub_port_status(struct usb_hub *hub, int port1,
        } else {
                *status = le16_to_cpu(hub->status->port.wPortStatus);
                *change = le16_to_cpu(hub->status->port.wPortChange);
-
+               if (type != HUB_PORT_STATUS && ext_status)
+                       *ext_status = le32_to_cpu(
+                               hub->status->port.dwExtPortStatus);
                ret = 0;
        }
        mutex_unlock(&hub->status_mutex);
        return ret;
 }
 
+static int hub_port_status(struct usb_hub *hub, int port1,
+               u16 *status, u16 *change)
+{
+       return hub_ext_port_status(hub, port1, HUB_PORT_STATUS,
+                                  status, change, NULL);
+}
+
 static void kick_hub_wq(struct usb_hub *hub)
 {
        struct usb_interface *intf;
@@ -2131,7 +2145,7 @@ static void hub_disconnect_children(struct usb_device *udev)
  * Something got disconnected. Get rid of it and all of its children.
  *
  * If *pdev is a normal device then the parent hub must already be locked.
- * If *pdev is a root hub then the caller must hold the usb_bus_list_lock,
+ * If *pdev is a root hub then the caller must hold the usb_bus_idr_lock,
  * which protects the set of root hubs as well as the list of buses.
  *
  * Only hub drivers (including virtual root hub drivers for host
@@ -2429,7 +2443,7 @@ static void set_usb_port_removable(struct usb_device *udev)
  * enumerated.  The device descriptor is available, but not descriptors
  * for any device configuration.  The caller must have locked either
  * the parent hub (if udev is a normal device) or else the
- * usb_bus_list_lock (if udev is a root hub).  The parent's pointer to
+ * usb_bus_idr_lock (if udev is a root hub).  The parent's pointer to
  * udev has already been installed, but udev is not yet visible through
  * sysfs or other filesystem code.
  *
@@ -2612,6 +2626,32 @@ out_authorized:
        return result;
 }
 
+/*
+ * Return 1 if port speed is SuperSpeedPlus, 0 otherwise
+ * check it from the link protocol field of the current speed ID attribute.
+ * current speed ID is got from ext port status request. Sublink speed attribute
+ * table is returned with the hub BOS SSP device capability descriptor
+ */
+static int port_speed_is_ssp(struct usb_device *hdev, int speed_id)
+{
+       int ssa_count;
+       u32 ss_attr;
+       int i;
+       struct usb_ssp_cap_descriptor *ssp_cap = hdev->bos->ssp_cap;
+
+       if (!ssp_cap)
+               return 0;
+
+       ssa_count = le32_to_cpu(ssp_cap->bmAttributes) &
+               USB_SSP_SUBLINK_SPEED_ATTRIBS;
+
+       for (i = 0; i <= ssa_count; i++) {
+               ss_attr = le32_to_cpu(ssp_cap->bmSublinkSpeedAttr[i]);
+               if (speed_id == (ss_attr & USB_SSP_SUBLINK_SPEED_SSID))
+                       return !!(ss_attr & USB_SSP_SUBLINK_SPEED_LP);
+       }
+       return 0;
+}
 
 /* Returns 1 if @hub is a WUSB root hub, 0 otherwise */
 static unsigned hub_is_wusb(struct usb_hub *hub)
@@ -2619,7 +2659,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
        struct usb_hcd *hcd;
        if (hub->hdev->parent != NULL)  /* not a root hub? */
                return 0;
-       hcd = container_of(hub->hdev->bus, struct usb_hcd, self);
+       hcd = bus_to_hcd(hub->hdev->bus);
        return hcd->wireless;
 }
 
@@ -2645,7 +2685,7 @@ static unsigned hub_is_wusb(struct usb_hub *hub)
  */
 static bool use_new_scheme(struct usb_device *udev, int retry)
 {
-       if (udev->speed == USB_SPEED_SUPER)
+       if (udev->speed >= USB_SPEED_SUPER)
                return false;
 
        return USE_NEW_SCHEME(retry);
@@ -2676,6 +2716,7 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
        int delay_time, ret;
        u16 portstatus;
        u16 portchange;
+       u32 ext_portstatus = 0;
 
        for (delay_time = 0;
                        delay_time < HUB_RESET_TIMEOUT;
@@ -2684,7 +2725,14 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
                msleep(delay);
 
                /* read and decode port status */
-               ret = hub_port_status(hub, port1, &portstatus, &portchange);
+               if (hub_is_superspeedplus(hub->hdev))
+                       ret = hub_ext_port_status(hub, port1,
+                                                 HUB_EXT_PORT_STATUS,
+                                                 &portstatus, &portchange,
+                                                 &ext_portstatus);
+               else
+                       ret = hub_port_status(hub, port1, &portstatus,
+                                             &portchange);
                if (ret < 0)
                        return ret;
 
@@ -2727,6 +2775,10 @@ static int hub_port_wait_reset(struct usb_hub *hub, int port1,
 
        if (hub_is_wusb(hub))
                udev->speed = USB_SPEED_WIRELESS;
+       else if (hub_is_superspeedplus(hub->hdev) &&
+                port_speed_is_ssp(hub->hdev, ext_portstatus &
+                                  USB_EXT_PORT_STAT_RX_SPEED_ID))
+               udev->speed = USB_SPEED_SUPER_PLUS;
        else if (hub_is_superspeed(hub->hdev))
                udev->speed = USB_SPEED_SUPER;
        else if (portstatus & USB_PORT_STAT_HIGH_SPEED)
@@ -3989,7 +4041,7 @@ int usb_disable_lpm(struct usb_device *udev)
        struct usb_hcd *hcd;
 
        if (!udev || !udev->parent ||
-                       udev->speed != USB_SPEED_SUPER ||
+                       udev->speed < USB_SPEED_SUPER ||
                        !udev->lpm_capable ||
                        udev->state < USB_STATE_DEFAULT)
                return 0;
@@ -4048,7 +4100,7 @@ void usb_enable_lpm(struct usb_device *udev)
        struct usb_port *port_dev;
 
        if (!udev || !udev->parent ||
-                       udev->speed != USB_SPEED_SUPER ||
+                       udev->speed < USB_SPEED_SUPER ||
                        !udev->lpm_capable ||
                        udev->state < USB_STATE_DEFAULT)
                return;
@@ -4323,7 +4375,9 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
 
        retval = -ENODEV;
 
-       if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed) {
+       /* Don't allow speed changes at reset, except usb 3.0 to faster */
+       if (oldspeed != USB_SPEED_UNKNOWN && oldspeed != udev->speed &&
+           !(oldspeed == USB_SPEED_SUPER && udev->speed > oldspeed)) {
                dev_dbg(&udev->dev, "device reset changed speed!\n");
                goto fail;
        }
@@ -4335,6 +4389,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
         * reported as 0xff in the device descriptor). WUSB1.0[4.8.1].
         */
        switch (udev->speed) {
+       case USB_SPEED_SUPER_PLUS:
        case USB_SPEED_SUPER:
        case USB_SPEED_WIRELESS:        /* fixed at 512 */
                udev->ep0.desc.wMaxPacketSize = cpu_to_le16(512);
@@ -4361,7 +4416,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
        else
                speed = usb_speed_string(udev->speed);
 
-       if (udev->speed != USB_SPEED_SUPER)
+       if (udev->speed < USB_SPEED_SUPER)
                dev_info(&udev->dev,
                                "%s %s USB device number %d using %s\n",
                                (udev->config) ? "reset" : "new", speed,
@@ -4441,7 +4496,13 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
                                                r = -EPROTO;
                                        break;
                                }
-                               if (r == 0)
+                               /*
+                                * Some devices time out if they are powered on
+                                * when already connected. They need a second
+                                * reset. But only on the first attempt,
+                                * lest we get into a time out/reset loop
+                                */
+                               if (r == 0  || (r == -ETIMEDOUT && j == 0))
                                        break;
                        }
                        udev->descriptor.bMaxPacketSize0 =
@@ -4485,11 +4546,12 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
                                                        devnum, retval);
                                goto fail;
                        }
-                       if (udev->speed == USB_SPEED_SUPER) {
+                       if (udev->speed >= USB_SPEED_SUPER) {
                                devnum = udev->devnum;
                                dev_info(&udev->dev,
-                                               "%s SuperSpeed USB device number %d using %s\n",
+                                               "%s SuperSpeed%s USB device number %d using %s\n",
                                                (udev->config) ? "reset" : "new",
+                                        (udev->speed == USB_SPEED_SUPER_PLUS) ? "Plus" : "",
                                                devnum, udev->bus->controller->driver->name);
                        }
 
@@ -4528,7 +4590,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
         * got from those devices show they aren't superspeed devices. Warm
         * reset the port attached by the devices can fix them.
         */
-       if ((udev->speed == USB_SPEED_SUPER) &&
+       if ((udev->speed >= USB_SPEED_SUPER) &&
                        (le16_to_cpu(udev->descriptor.bcdUSB) < 0x0300)) {
                dev_err(&udev->dev, "got a wrong device descriptor, "
                                "warm reset device\n");
@@ -4539,7 +4601,7 @@ hub_port_init(struct usb_hub *hub, struct usb_device *udev, int port1,
        }
 
        if (udev->descriptor.bMaxPacketSize0 == 0xff ||
-                       udev->speed == USB_SPEED_SUPER)
+                       udev->speed >= USB_SPEED_SUPER)
                i = 512;
        else
                i = udev->descriptor.bMaxPacketSize0;
@@ -4749,7 +4811,7 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
                udev->level = hdev->level + 1;
                udev->wusb = hub_is_wusb(hub);
 
-               /* Only USB 3.0 devices are connected to SuperSpeed hubs. */
+               /* Devices connected to SuperSpeed hubs are USB 3.0 or later */
                if (hub_is_superspeed(hub->hdev))
                        udev->speed = USB_SPEED_SUPER;
                else
index 45d070d..34c1a7e 100644 (file)
@@ -140,6 +140,13 @@ static inline int hub_is_superspeed(struct usb_device *hdev)
        return hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS;
 }
 
+static inline int hub_is_superspeedplus(struct usb_device *hdev)
+{
+       return (hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS &&
+               le16_to_cpu(hdev->descriptor.bcdUSB) >= 0x0310 &&
+               hdev->bos->ssp_cap);
+}
+
 static inline unsigned hub_power_on_good_delay(struct usb_hub *hub)
 {
        unsigned delay = hub->descriptor->bPwrOn2PwrGood * 2;
index 65b6e6b..c953a0f 100644 (file)
@@ -23,10 +23,12 @@ static ssize_t field##_show(struct device *dev,                             \
 {                                                                      \
        struct usb_device *udev;                                        \
        struct usb_host_config *actconfig;                              \
-       ssize_t rc = 0;                                                 \
+       ssize_t rc;                                                     \
                                                                        \
        udev = to_usb_device(dev);                                      \
-       usb_lock_device(udev);                                          \
+       rc = usb_lock_device_interruptible(udev);                       \
+       if (rc < 0)                                                     \
+               return -EINTR;                                          \
        actconfig = udev->actconfig;                                    \
        if (actconfig)                                                  \
                rc = sprintf(buf, format_string,                        \
@@ -47,10 +49,12 @@ static ssize_t bMaxPower_show(struct device *dev,
 {
        struct usb_device *udev;
        struct usb_host_config *actconfig;
-       ssize_t rc = 0;
+       ssize_t rc;
 
        udev = to_usb_device(dev);
-       usb_lock_device(udev);
+       rc = usb_lock_device_interruptible(udev);
+       if (rc < 0)
+               return -EINTR;
        actconfig = udev->actconfig;
        if (actconfig)
                rc = sprintf(buf, "%dmA\n", usb_get_max_power(udev, actconfig));
@@ -64,10 +68,12 @@ static ssize_t configuration_show(struct device *dev,
 {
        struct usb_device *udev;
        struct usb_host_config *actconfig;
-       ssize_t rc = 0;
+       ssize_t rc;
 
        udev = to_usb_device(dev);
-       usb_lock_device(udev);
+       rc = usb_lock_device_interruptible(udev);
+       if (rc < 0)
+               return -EINTR;
        actconfig = udev->actconfig;
        if (actconfig && actconfig->string)
                rc = sprintf(buf, "%s\n", actconfig->string);
@@ -84,11 +90,13 @@ static ssize_t bConfigurationValue_store(struct device *dev,
                                         const char *buf, size_t count)
 {
        struct usb_device       *udev = to_usb_device(dev);
-       int                     config, value;
+       int                     config, value, rc;
 
        if (sscanf(buf, "%d", &config) != 1 || config < -1 || config > 255)
                return -EINVAL;
-       usb_lock_device(udev);
+       rc = usb_lock_device_interruptible(udev);
+       if (rc < 0)
+               return -EINTR;
        value = usb_set_configuration(udev, config);
        usb_unlock_device(udev);
        return (value < 0) ? value : count;
@@ -105,7 +113,9 @@ static ssize_t  name##_show(struct device *dev,                             \
        int retval;                                                     \
                                                                        \
        udev = to_usb_device(dev);                                      \
-       usb_lock_device(udev);                                          \
+       retval = usb_lock_device_interruptible(udev);                   \
+       if (retval < 0)                                                 \
+               return -EINTR;                                          \
        retval = sprintf(buf, "%s\n", udev->name);                      \
        usb_unlock_device(udev);                                        \
        return retval;                                                  \
@@ -141,6 +151,9 @@ static ssize_t speed_show(struct device *dev, struct device_attribute *attr,
        case USB_SPEED_SUPER:
                speed = "5000";
                break;
+       case USB_SPEED_SUPER_PLUS:
+               speed = "10000";
+               break;
        default:
                speed = "unknown";
        }
@@ -224,11 +237,13 @@ static ssize_t avoid_reset_quirk_store(struct device *dev,
                                      const char *buf, size_t count)
 {
        struct usb_device       *udev = to_usb_device(dev);
-       int                     val;
+       int                     val, rc;
 
        if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1)
                return -EINVAL;
-       usb_lock_device(udev);
+       rc = usb_lock_device_interruptible(udev);
+       if (rc < 0)
+               return -EINTR;
        if (val)
                udev->quirks |= USB_QUIRK_RESET;
        else
@@ -294,7 +309,7 @@ static ssize_t persist_store(struct device *dev, struct device_attribute *attr,
                             const char *buf, size_t count)
 {
        struct usb_device *udev = to_usb_device(dev);
-       int value;
+       int value, rc;
 
        /* Hubs are always enabled for USB_PERSIST */
        if (udev->descriptor.bDeviceClass == USB_CLASS_HUB)
@@ -303,7 +318,9 @@ static ssize_t persist_store(struct device *dev, struct device_attribute *attr,
        if (sscanf(buf, "%d", &value) != 1)
                return -EINVAL;
 
-       usb_lock_device(udev);
+       rc = usb_lock_device_interruptible(udev);
+       if (rc < 0)
+               return -EINTR;
        udev->persist_enabled = !!value;
        usb_unlock_device(udev);
        return count;
@@ -420,13 +437,16 @@ static ssize_t level_store(struct device *dev, struct device_attribute *attr,
        int len = count;
        char *cp;
        int rc = count;
+       int rv;
 
        warn_level();
        cp = memchr(buf, '\n', count);
        if (cp)
                len = cp - buf;
 
-       usb_lock_device(udev);
+       rv = usb_lock_device_interruptible(udev);
+       if (rv < 0)
+               return -EINTR;
 
        if (len == sizeof on_string - 1 &&
                        strncmp(buf, on_string, len) == 0)
@@ -466,7 +486,9 @@ static ssize_t usb2_hardware_lpm_store(struct device *dev,
        bool value;
        int ret;
 
-       usb_lock_device(udev);
+       ret = usb_lock_device_interruptible(udev);
+       if (ret < 0)
+               return -EINTR;
 
        ret = strtobool(buf, &value);
 
@@ -536,8 +558,11 @@ static ssize_t usb3_hardware_lpm_u1_show(struct device *dev,
 {
        struct usb_device *udev = to_usb_device(dev);
        const char *p;
+       int rc;
 
-       usb_lock_device(udev);
+       rc = usb_lock_device_interruptible(udev);
+       if (rc < 0)
+               return -EINTR;
 
        if (udev->usb3_lpm_u1_enabled)
                p = "enabled";
@@ -555,8 +580,11 @@ static ssize_t usb3_hardware_lpm_u2_show(struct device *dev,
 {
        struct usb_device *udev = to_usb_device(dev);
        const char *p;
+       int rc;
 
-       usb_lock_device(udev);
+       rc = usb_lock_device_interruptible(udev);
+       if (rc < 0)
+               return -EINTR;
 
        if (udev->usb3_lpm_u2_enabled)
                p = "enabled";
@@ -822,7 +850,6 @@ read_descriptors(struct file *filp, struct kobject *kobj,
         * Following that are the raw descriptor entries for all the
         * configurations (config plus subsidiary descriptors).
         */
-       usb_lock_device(udev);
        for (cfgno = -1; cfgno < udev->descriptor.bNumConfigurations &&
                        nleft > 0; ++cfgno) {
                if (cfgno < 0) {
@@ -843,7 +870,6 @@ read_descriptors(struct file *filp, struct kobject *kobj,
                        off -= srclen;
                }
        }
-       usb_unlock_device(udev);
        return count - nleft;
 }
 
@@ -969,7 +995,9 @@ static ssize_t supports_autosuspend_show(struct device *dev,
 {
        int s;
 
-       device_lock(dev);
+       s = device_lock_interruptible(dev);
+       if (s < 0)
+               return -EINTR;
        /* Devices will be autosuspended even when an interface isn't claimed */
        s = (!dev->driver || to_usb_driver(dev->driver)->supports_autosuspend);
        device_unlock(dev);
index 3d27477..c601e25 100644 (file)
@@ -401,7 +401,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
                /* SuperSpeed isoc endpoints have up to 16 bursts of up to
                 * 3 packets each
                 */
-               if (dev->speed == USB_SPEED_SUPER) {
+               if (dev->speed >= USB_SPEED_SUPER) {
                        int     burst = 1 + ep->ss_ep_comp.bMaxBurst;
                        int     mult = USB_SS_MULT(ep->ss_ep_comp.bmAttributes);
                        max *= burst;
@@ -499,6 +499,7 @@ int usb_submit_urb(struct urb *urb, gfp_t mem_flags)
                }
                /* too big? */
                switch (dev->speed) {
+               case USB_SPEED_SUPER_PLUS:
                case USB_SPEED_SUPER:   /* units are 125us */
                        /* Handle up to 2^(16-1) microframes */
                        if (urb->interval > (1 << 15))
index ebb29ca..524c982 100644 (file)
@@ -241,7 +241,7 @@ static int __each_dev(struct device *dev, void *data)
        if (!is_usb_device(dev))
                return 0;
 
-       return arg->fn(container_of(dev, struct usb_device, dev), arg->data);
+       return arg->fn(to_usb_device(dev), arg->data);
 }
 
 /**
@@ -397,7 +397,7 @@ struct device_type usb_device_type = {
 /* Returns 1 if @usb_bus is WUSB, 0 otherwise */
 static unsigned usb_bus_is_wusb(struct usb_bus *bus)
 {
-       struct usb_hcd *hcd = container_of(bus, struct usb_hcd, self);
+       struct usb_hcd *hcd = bus_to_hcd(bus);
        return hcd->wireless;
 }
 
@@ -1115,6 +1115,7 @@ static void __exit usb_exit(void)
        bus_unregister(&usb_bus_type);
        usb_acpi_unregister();
        usb_debugfs_cleanup();
+       idr_destroy(&usb_bus_idr);
 }
 
 subsys_initcall(usb_init);
index 05b5e17..5331812 100644 (file)
@@ -45,7 +45,7 @@ static inline unsigned usb_get_max_power(struct usb_device *udev,
                struct usb_host_config *c)
 {
        /* SuperSpeed power is in 8 mA units; others are in 2 mA units */
-       unsigned mul = (udev->speed == USB_SPEED_SUPER ? 8 : 2);
+       unsigned mul = (udev->speed >= USB_SPEED_SUPER ? 8 : 2);
 
        return c->desc.bMaxPower * mul;
 }
index f0decc0..c1f29ca 100644 (file)
@@ -2,6 +2,7 @@ config USB_DWC2
        tristate "DesignWare USB2 DRD Core Support"
        depends on HAS_DMA
        depends on USB || USB_GADGET
+       depends on HAS_IOMEM
        help
          Say Y here if your system has a Dual Role Hi-Speed USB
          controller based on the DesignWare HSOTG IP Core.
index 70d3917..943c21a 100644 (file)
@@ -914,7 +914,7 @@ struct rndis_params *rndis_register(void (*resp_avail)(void *v), void *v)
        params->media_state = RNDIS_MEDIA_STATE_DISCONNECTED;
        params->resp_avail = resp_avail;
        params->v = v;
-       INIT_LIST_HEAD(&(params->resp_queue));
+       INIT_LIST_HEAD(&params->resp_queue);
        pr_debug("%s: configNr = %d\n", __func__, i);
 
        return params;
@@ -1006,13 +1006,10 @@ EXPORT_SYMBOL_GPL(rndis_add_hdr);
 
 void rndis_free_response(struct rndis_params *params, u8 *buf)
 {
-       rndis_resp_t *r;
-       struct list_head *act, *tmp;
+       rndis_resp_t *r, *n;
 
-       list_for_each_safe(act, tmp, &(params->resp_queue))
-       {
-               r = list_entry(act, rndis_resp_t, list);
-               if (r && r->buf == buf) {
+       list_for_each_entry_safe(r, n, &params->resp_queue, list) {
+               if (r->buf == buf) {
                        list_del(&r->list);
                        kfree(r);
                }
@@ -1022,14 +1019,11 @@ EXPORT_SYMBOL_GPL(rndis_free_response);
 
 u8 *rndis_get_next_response(struct rndis_params *params, u32 *length)
 {
-       rndis_resp_t *r;
-       struct list_head *act, *tmp;
+       rndis_resp_t *r, *n;
 
        if (!length) return NULL;
 
-       list_for_each_safe(act, tmp, &(params->resp_queue))
-       {
-               r = list_entry(act, rndis_resp_t, list);
+       list_for_each_entry_safe(r, n, &params->resp_queue, list) {
                if (!r->send) {
                        r->send = 1;
                        *length = r->length;
@@ -1053,7 +1047,7 @@ static rndis_resp_t *rndis_add_response(struct rndis_params *params, u32 length)
        r->length = length;
        r->send = 0;
 
-       list_add_tail(&r->list, &(params->resp_queue));
+       list_add_tail(&r->list, &params->resp_queue);
        return r;
 }
 
index 753c29b..d6ad7e6 100644 (file)
@@ -128,6 +128,7 @@ config USB_OMAP
 config USB_PXA25X
        tristate "PXA 25x or IXP 4xx"
        depends on (ARCH_PXA && PXA25x) || ARCH_IXP4XX
+       depends on HAS_IOMEM
        help
           Intel's PXA 25x series XScale ARM-5TE processors include
           an integrated full speed USB 1.1 device controller.  The
@@ -187,6 +188,7 @@ config USB_RENESAS_USB3
 
 config USB_PXA27X
        tristate "PXA 27x"
+       depends on HAS_IOMEM
        help
           Intel's PXA 27x series XScale ARM v5TE processors include
           an integrated full speed USB 1.1 device controller.
@@ -244,6 +246,7 @@ config USB_MV_U3D
 
 config USB_M66592
        tristate "Renesas M66592 USB Peripheral Controller"
+       depends on HAS_IOMEM
        help
           M66592 is a discrete USB peripheral controller chip that
           supports both full and high speed USB 2.0 data transfers.
@@ -287,6 +290,7 @@ config USB_FSL_QE
           dynamically linked module called "fsl_qe_udc".
 
 config USB_NET2272
+       depends on HAS_IOMEM
        tristate "PLX NET2272"
        help
          PLX NET2272 is a USB peripheral controller which supports
index 1f117c3..ed9a90f 100644 (file)
@@ -5,6 +5,7 @@ comment "USB Host Controller Drivers"
 
 config USB_C67X00_HCD
        tristate "Cypress C67x00 HCD support"
+       depends on HAS_IOMEM
        help
          The Cypress C67x00 (EZ-Host/EZ-OTG) chips are dual-role
          host/peripheral/OTG USB controllers.
@@ -17,6 +18,7 @@ config USB_C67X00_HCD
 
 config USB_XHCI_HCD
        tristate "xHCI HCD (USB 3.0) support"
+       depends on HAS_IOMEM
        ---help---
          The eXtensible Host Controller Interface (xHCI) is standard for USB 3.0
          "SuperSpeed" host controller hardware.
@@ -53,6 +55,7 @@ config USB_XHCI_MTK
 config USB_XHCI_MVEBU
        tristate "xHCI support for Marvell Armada 375/38x"
        select USB_XHCI_PLATFORM
+       depends on HAS_IOMEM
        depends on ARCH_MVEBU || COMPILE_TEST
        ---help---
          Say 'Y' to enable the support for the xHCI host controller
@@ -61,7 +64,7 @@ config USB_XHCI_MVEBU
 config USB_XHCI_RCAR
        tristate "xHCI support for Renesas R-Car SoCs"
        select USB_XHCI_PLATFORM
-       depends on ARCH_SHMOBILE || COMPILE_TEST
+       depends on ARCH_RENESAS || COMPILE_TEST
        ---help---
          Say 'Y' to enable the support for the xHCI host controller
          found in Renesas R-Car ARM SoCs.
@@ -70,6 +73,7 @@ endif # USB_XHCI_HCD
 
 config USB_EHCI_HCD
        tristate "EHCI HCD (USB 2.0) support"
+       depends on HAS_IOMEM
        ---help---
          The Enhanced Host Controller Interface (EHCI) is standard for USB 2.0
          "high speed" (480 Mbit/sec, 60 Mbyte/sec) host controller hardware.
@@ -328,6 +332,7 @@ endif # USB_EHCI_HCD
 
 config USB_OXU210HP_HCD
        tristate "OXU210HP HCD support"
+       depends on HAS_IOMEM
        ---help---
          The OXU210HP is an USB host/OTG/device controller. Enable this
          option if your board has this chip. If unsure, say N.
@@ -340,6 +345,7 @@ config USB_OXU210HP_HCD
 
 config USB_ISP116X_HCD
        tristate "ISP116X HCD support"
+       depends on HAS_IOMEM
        ---help---
          The ISP1160 and ISP1161 chips are USB host controllers. Enable this
          option if your board has this chip. If unsure, say N.
@@ -351,6 +357,7 @@ config USB_ISP116X_HCD
 
 config USB_ISP1362_HCD
        tristate "ISP1362 HCD support"
+       depends on HAS_IOMEM
        ---help---
          Supports the Philips ISP1362 chip as a host controller
 
@@ -362,6 +369,7 @@ config USB_ISP1362_HCD
 config USB_FOTG210_HCD
        tristate "FOTG210 HCD support"
        depends on USB
+       depends on HAS_IOMEM
        ---help---
          Faraday FOTG210 is an OTG controller which can be configured as
          an USB2.0 host. It is designed to meet USB2.0 EHCI specification
@@ -383,6 +391,7 @@ config USB_MAX3421_HCD
 
 config USB_OHCI_HCD
        tristate "OHCI HCD (USB 1.1) support"
+       depends on HAS_IOMEM
        ---help---
          The Open Host Controller Interface (OHCI) is a standard for accessing
          USB 1.1 host controller hardware.  It does more in hardware than Intel's
@@ -668,6 +677,7 @@ config USB_U132_HCD
 
 config USB_SL811_HCD
        tristate "SL811HS HCD support"
+       depends on HAS_IOMEM
        help
          The SL811HS is a single-port USB controller that supports either
          host side or peripheral side roles.  Enable this option if your
@@ -699,6 +709,7 @@ config USB_SL811_CS
 
 config USB_R8A66597_HCD
        tristate "R8A66597 HCD support"
+       depends on HAS_IOMEM
        help
          The R8A66597 is a USB 2.0 host and peripheral controller.
 
index 291aaa2..963e2d0 100644 (file)
@@ -35,6 +35,7 @@ MODULE_DESCRIPTION("Common USB driver for BCMA Bus");
 MODULE_LICENSE("GPL");
 
 struct bcma_hcd_device {
+       struct bcma_device *core;
        struct platform_device *ehci_dev;
        struct platform_device *ohci_dev;
        struct gpio_desc *gpio_desc;
@@ -244,7 +245,10 @@ static const struct usb_ehci_pdata ehci_pdata = {
 static const struct usb_ohci_pdata ohci_pdata = {
 };
 
-static struct platform_device *bcma_hcd_create_pdev(struct bcma_device *dev, bool ohci, u32 addr)
+static struct platform_device *bcma_hcd_create_pdev(struct bcma_device *dev,
+                                                   const char *name, u32 addr,
+                                                   const void *data,
+                                                   size_t size)
 {
        struct platform_device *hci_dev;
        struct resource hci_res[2];
@@ -259,8 +263,7 @@ static struct platform_device *bcma_hcd_create_pdev(struct bcma_device *dev, boo
        hci_res[1].start = dev->irq;
        hci_res[1].flags = IORESOURCE_IRQ;
 
-       hci_dev = platform_device_alloc(ohci ? "ohci-platform" :
-                                       "ehci-platform" , 0);
+       hci_dev = platform_device_alloc(name, 0);
        if (!hci_dev)
                return ERR_PTR(-ENOMEM);
 
@@ -271,12 +274,8 @@ static struct platform_device *bcma_hcd_create_pdev(struct bcma_device *dev, boo
                                            ARRAY_SIZE(hci_res));
        if (ret)
                goto err_alloc;
-       if (ohci)
-               ret = platform_device_add_data(hci_dev, &ohci_pdata,
-                                              sizeof(ohci_pdata));
-       else
-               ret = platform_device_add_data(hci_dev, &ehci_pdata,
-                                              sizeof(ehci_pdata));
+       if (data)
+               ret = platform_device_add_data(hci_dev, data, size);
        if (ret)
                goto err_alloc;
        ret = platform_device_add(hci_dev);
@@ -290,31 +289,16 @@ err_alloc:
        return ERR_PTR(ret);
 }
 
-static int bcma_hcd_probe(struct bcma_device *dev)
+static int bcma_hcd_usb20_init(struct bcma_hcd_device *usb_dev)
 {
-       int err;
+       struct bcma_device *dev = usb_dev->core;
+       struct bcma_chipinfo *chipinfo = &dev->bus->chipinfo;
        u32 ohci_addr;
-       struct bcma_hcd_device *usb_dev;
-       struct bcma_chipinfo *chipinfo;
-
-       chipinfo = &dev->bus->chipinfo;
-
-       /* TODO: Probably need checks here; is the core connected? */
+       int err;
 
        if (dma_set_mask_and_coherent(dev->dma_dev, DMA_BIT_MASK(32)))
                return -EOPNOTSUPP;
 
-       usb_dev = devm_kzalloc(&dev->dev, sizeof(struct bcma_hcd_device),
-                              GFP_KERNEL);
-       if (!usb_dev)
-               return -ENOMEM;
-
-       if (dev->dev.of_node)
-               usb_dev->gpio_desc = devm_get_gpiod_from_child(&dev->dev, "vcc",
-                                                              &dev->dev.of_node->fwnode);
-       if (!IS_ERR_OR_NULL(usb_dev->gpio_desc))
-               gpiod_direction_output(usb_dev->gpio_desc, 1);
-
        switch (dev->id.id) {
        case BCMA_CORE_NS_USB20:
                bcma_hcd_init_chip_arm(dev);
@@ -333,17 +317,20 @@ static int bcma_hcd_probe(struct bcma_device *dev)
            && chipinfo->rev == 0)
                ohci_addr = 0x18009000;
 
-       usb_dev->ohci_dev = bcma_hcd_create_pdev(dev, true, ohci_addr);
+       usb_dev->ohci_dev = bcma_hcd_create_pdev(dev, "ohci-platform",
+                                                ohci_addr, &ohci_pdata,
+                                                sizeof(ohci_pdata));
        if (IS_ERR(usb_dev->ohci_dev))
                return PTR_ERR(usb_dev->ohci_dev);
 
-       usb_dev->ehci_dev = bcma_hcd_create_pdev(dev, false, dev->addr);
+       usb_dev->ehci_dev = bcma_hcd_create_pdev(dev, "ehci-platform",
+                                                dev->addr, &ehci_pdata,
+                                                sizeof(ehci_pdata));
        if (IS_ERR(usb_dev->ehci_dev)) {
                err = PTR_ERR(usb_dev->ehci_dev);
                goto err_unregister_ohci_dev;
        }
 
-       bcma_set_drvdata(dev, usb_dev);
        return 0;
 
 err_unregister_ohci_dev:
@@ -351,6 +338,40 @@ err_unregister_ohci_dev:
        return err;
 }
 
+static int bcma_hcd_probe(struct bcma_device *core)
+{
+       int err;
+       struct bcma_hcd_device *usb_dev;
+
+       /* TODO: Probably need checks here; is the core connected? */
+
+       usb_dev = devm_kzalloc(&core->dev, sizeof(struct bcma_hcd_device),
+                              GFP_KERNEL);
+       if (!usb_dev)
+               return -ENOMEM;
+       usb_dev->core = core;
+
+       if (core->dev.of_node)
+               usb_dev->gpio_desc = devm_get_gpiod_from_child(&core->dev, "vcc",
+                                                              &core->dev.of_node->fwnode);
+       if (!IS_ERR_OR_NULL(usb_dev->gpio_desc))
+               gpiod_direction_output(usb_dev->gpio_desc, 1);
+
+       switch (core->id.id) {
+       case BCMA_CORE_USB20_HOST:
+       case BCMA_CORE_NS_USB20:
+               err = bcma_hcd_usb20_init(usb_dev);
+               if (err)
+                       return err;
+               break;
+       default:
+               return -ENODEV;
+       }
+
+       bcma_set_drvdata(core, usb_dev);
+       return 0;
+}
+
 static void bcma_hcd_remove(struct bcma_device *dev)
 {
        struct bcma_hcd_device *usb_dev = bcma_get_drvdata(dev);
index b7d623f..79d12b2 100644 (file)
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 /* this file is part of ehci-hcd.c */
 
 #ifdef CONFIG_DYNAMIC_DEBUG
 
-/* check the values in the HCSPARAMS register
+/*
+ * check the values in the HCSPARAMS register
  * (host controller _Structural_ parameters)
  * see EHCI spec, Table 2-4 for each value
  */
-static void dbg_hcs_params (struct ehci_hcd *ehci, char *label)
+static void dbg_hcs_params(struct ehci_hcd *ehci, char *label)
 {
        u32     params = ehci_readl(ehci, &ehci->caps->hcs_params);
 
-       ehci_dbg (ehci,
+       ehci_dbg(ehci,
                "%s hcs_params 0x%x dbg=%d%s cc=%d pcc=%d%s%s ports=%d\n",
                label, params,
-               HCS_DEBUG_PORT (params),
-               HCS_INDICATOR (params) ? " ind" : "",
-               HCS_N_CC (params),
-               HCS_N_PCC (params),
-               HCS_PORTROUTED (params) ? "" : " ordered",
-               HCS_PPC (params) ? "" : " !ppc",
-               HCS_N_PORTS (params)
-               );
+               HCS_DEBUG_PORT(params),
+               HCS_INDICATOR(params) ? " ind" : "",
+               HCS_N_CC(params),
+               HCS_N_PCC(params),
+               HCS_PORTROUTED(params) ? "" : " ordered",
+               HCS_PPC(params) ? "" : " !ppc",
+               HCS_N_PORTS(params));
        /* Port routing, per EHCI 0.95 Spec, Section 2.2.5 */
-       if (HCS_PORTROUTED (params)) {
+       if (HCS_PORTROUTED(params)) {
                int i;
-               char buf [46], tmp [7], byte;
+               char buf[46], tmp[7], byte;
 
                buf[0] = 0;
-               for (i = 0; i < HCS_N_PORTS (params); i++) {
-                       // FIXME MIPS won't readb() ...
-                       byte = readb (&ehci->caps->portroute[(i>>1)]);
+               for (i = 0; i < HCS_N_PORTS(params); i++) {
+                       /* FIXME MIPS won't readb() ... */
+                       byte = readb(&ehci->caps->portroute[(i >> 1)]);
                        sprintf(tmp, "%d ",
-                               ((i & 0x1) ? ((byte)&0xf) : ((byte>>4)&0xf)));
+                               (i & 0x1) ? byte & 0xf : (byte >> 4) & 0xf);
                        strcat(buf, tmp);
                }
-               ehci_dbg (ehci, "%s portroute %s\n",
-                               label, buf);
+               ehci_dbg(ehci, "%s portroute %s\n", label, buf);
        }
 }
 #else
 
-static inline void dbg_hcs_params (struct ehci_hcd *ehci, char *label) {}
+static inline void dbg_hcs_params(struct ehci_hcd *ehci, char *label) {}
 
 #endif
 
 #ifdef CONFIG_DYNAMIC_DEBUG
 
-/* check the values in the HCCPARAMS register
+/*
+ * check the values in the HCCPARAMS register
  * (host controller _Capability_ parameters)
  * see EHCI Spec, Table 2-5 for each value
- * */
-static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
+ */
+static void dbg_hcc_params(struct ehci_hcd *ehci, char *label)
 {
        u32     params = ehci_readl(ehci, &ehci->caps->hcc_params);
 
-       if (HCC_ISOC_CACHE (params)) {
-               ehci_dbg (ehci,
+       if (HCC_ISOC_CACHE(params)) {
+               ehci_dbg(ehci,
                        "%s hcc_params %04x caching frame %s%s%s\n",
                        label, params,
                        HCC_PGM_FRAMELISTLEN(params) ? "256/512/1024" : "1024",
                        HCC_CANPARK(params) ? " park" : "",
                        HCC_64BIT_ADDR(params) ? " 64 bit addr" : "");
        } else {
-               ehci_dbg (ehci,
+               ehci_dbg(ehci,
                        "%s hcc_params %04x thresh %d uframes %s%s%s%s%s%s%s\n",
                        label,
                        params,
@@ -97,21 +94,21 @@ static void dbg_hcc_params (struct ehci_hcd *ehci, char *label)
 }
 #else
 
-static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
+static inline void dbg_hcc_params(struct ehci_hcd *ehci, char *label) {}
 
 #endif
 
 #ifdef CONFIG_DYNAMIC_DEBUG
 
 static void __maybe_unused
-dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
+dbg_qtd(const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
 {
        ehci_dbg(ehci, "%s td %p n%08x %08x t%08x p0=%08x\n", label, qtd,
                hc32_to_cpup(ehci, &qtd->hw_next),
                hc32_to_cpup(ehci, &qtd->hw_alt_next),
                hc32_to_cpup(ehci, &qtd->hw_token),
-               hc32_to_cpup(ehci, &qtd->hw_buf [0]));
-       if (qtd->hw_buf [1])
+               hc32_to_cpup(ehci, &qtd->hw_buf[0]));
+       if (qtd->hw_buf[1])
                ehci_dbg(ehci, "  p1=%08x p2=%08x p3=%08x p4=%08x\n",
                        hc32_to_cpup(ehci, &qtd->hw_buf[1]),
                        hc32_to_cpup(ehci, &qtd->hw_buf[2]),
@@ -120,22 +117,22 @@ dbg_qtd (const char *label, struct ehci_hcd *ehci, struct ehci_qtd *qtd)
 }
 
 static void __maybe_unused
-dbg_qh (const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
+dbg_qh(const char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
 {
        struct ehci_qh_hw *hw = qh->hw;
 
-       ehci_dbg (ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
+       ehci_dbg(ehci, "%s qh %p n%08x info %x %x qtd %x\n", label,
                qh, hw->hw_next, hw->hw_info1, hw->hw_info2, hw->hw_current);
        dbg_qtd("overlay", ehci, (struct ehci_qtd *) &hw->hw_qtd_next);
 }
 
 static void __maybe_unused
-dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
+dbg_itd(const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
 {
-       ehci_dbg (ehci, "%s [%d] itd %p, next %08x, urb %p\n",
+       ehci_dbg(ehci, "%s [%d] itd %p, next %08x, urb %p\n",
                label, itd->frame, itd, hc32_to_cpu(ehci, itd->hw_next),
                itd->urb);
-       ehci_dbg (ehci,
+       ehci_dbg(ehci,
                "  trans: %08x %08x %08x %08x %08x %08x %08x %08x\n",
                hc32_to_cpu(ehci, itd->hw_transaction[0]),
                hc32_to_cpu(ehci, itd->hw_transaction[1]),
@@ -145,7 +142,7 @@ dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
                hc32_to_cpu(ehci, itd->hw_transaction[5]),
                hc32_to_cpu(ehci, itd->hw_transaction[6]),
                hc32_to_cpu(ehci, itd->hw_transaction[7]));
-       ehci_dbg (ehci,
+       ehci_dbg(ehci,
                "  buf:   %08x %08x %08x %08x %08x %08x %08x\n",
                hc32_to_cpu(ehci, itd->hw_bufp[0]),
                hc32_to_cpu(ehci, itd->hw_bufp[1]),
@@ -154,19 +151,19 @@ dbg_itd (const char *label, struct ehci_hcd *ehci, struct ehci_itd *itd)
                hc32_to_cpu(ehci, itd->hw_bufp[4]),
                hc32_to_cpu(ehci, itd->hw_bufp[5]),
                hc32_to_cpu(ehci, itd->hw_bufp[6]));
-       ehci_dbg (ehci, "  index: %d %d %d %d %d %d %d %d\n",
+       ehci_dbg(ehci, "  index: %d %d %d %d %d %d %d %d\n",
                itd->index[0], itd->index[1], itd->index[2],
                itd->index[3], itd->index[4], itd->index[5],
                itd->index[6], itd->index[7]);
 }
 
 static void __maybe_unused
-dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
+dbg_sitd(const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
 {
-       ehci_dbg (ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
+       ehci_dbg(ehci, "%s [%d] sitd %p, next %08x, urb %p\n",
                label, sitd->frame, sitd, hc32_to_cpu(ehci, sitd->hw_next),
                sitd->urb);
-       ehci_dbg (ehci,
+       ehci_dbg(ehci,
                "  addr %08x sched %04x result %08x buf %08x %08x\n",
                hc32_to_cpu(ehci, sitd->hw_fullspeed_ep),
                hc32_to_cpu(ehci, sitd->hw_uframe),
@@ -176,11 +173,11 @@ dbg_sitd (const char *label, struct ehci_hcd *ehci, struct ehci_sitd *sitd)
 }
 
 static int __maybe_unused
-dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
+dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
 {
-       return scnprintf (buf, len,
+       return scnprintf(buf, len,
                "%s%sstatus %04x%s%s%s%s%s%s%s%s%s%s%s",
-               label, label [0] ? " " : "", status,
+               label, label[0] ? " " : "", status,
                (status & STS_PPCE_MASK) ? " PPCE" : "",
                (status & STS_ASS) ? " Async" : "",
                (status & STS_PSS) ? " Periodic" : "",
@@ -191,79 +188,83 @@ dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
                (status & STS_FLR) ? " FLR" : "",
                (status & STS_PCD) ? " PCD" : "",
                (status & STS_ERR) ? " ERR" : "",
-               (status & STS_INT) ? " INT" : ""
-               );
+               (status & STS_INT) ? " INT" : "");
 }
 
 static int __maybe_unused
-dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
+dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
 {
-       return scnprintf (buf, len,
+       return scnprintf(buf, len,
                "%s%sintrenable %02x%s%s%s%s%s%s%s",
-               label, label [0] ? " " : "", enable,
+               label, label[0] ? " " : "", enable,
                (enable & STS_PPCE_MASK) ? " PPCE" : "",
                (enable & STS_IAA) ? " IAA" : "",
                (enable & STS_FATAL) ? " FATAL" : "",
                (enable & STS_FLR) ? " FLR" : "",
                (enable & STS_PCD) ? " PCD" : "",
                (enable & STS_ERR) ? " ERR" : "",
-               (enable & STS_INT) ? " INT" : ""
-               );
+               (enable & STS_INT) ? " INT" : "");
 }
 
-static const char *const fls_strings [] =
-    { "1024", "512", "256", "??" };
+static const char *const fls_strings[] = { "1024", "512", "256", "??" };
 
 static int
-dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
+dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
 {
-       return scnprintf (buf, len,
+       return scnprintf(buf, len,
                "%s%scommand %07x %s%s%s%s%s%s=%d ithresh=%d%s%s%s%s "
                "period=%s%s %s",
-               label, label [0] ? " " : "", command,
+               label, label[0] ? " " : "", command,
                (command & CMD_HIRD) ? " HIRD" : "",
                (command & CMD_PPCEE) ? " PPCEE" : "",
                (command & CMD_FSP) ? " FSP" : "",
                (command & CMD_ASPE) ? " ASPE" : "",
                (command & CMD_PSPE) ? " PSPE" : "",
                (command & CMD_PARK) ? " park" : "(park)",
-               CMD_PARK_CNT (command),
+               CMD_PARK_CNT(command),
                (command >> 16) & 0x3f,
                (command & CMD_LRESET) ? " LReset" : "",
                (command & CMD_IAAD) ? " IAAD" : "",
                (command & CMD_ASE) ? " Async" : "",
                (command & CMD_PSE) ? " Periodic" : "",
-               fls_strings [(command >> 2) & 0x3],
+               fls_strings[(command >> 2) & 0x3],
                (command & CMD_RESET) ? " Reset" : "",
-               (command & CMD_RUN) ? "RUN" : "HALT"
-               );
+               (command & CMD_RUN) ? "RUN" : "HALT");
 }
 
 static int
-dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
+dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
 {
        char    *sig;
 
        /* signaling state */
        switch (status & (3 << 10)) {
-       case 0 << 10: sig = "se0"; break;
-       case 1 << 10: sig = "k"; break;         /* low speed */
-       case 2 << 10: sig = "j"; break;
-       default: sig = "?"; break;
+       case 0 << 10:
+               sig = "se0";
+               break;
+       case 1 << 10: /* low speed */
+               sig = "k";
+               break;
+       case 2 << 10:
+               sig = "j";
+               break;
+       default:
+               sig = "?";
+               break;
        }
 
-       return scnprintf (buf, len,
+       return scnprintf(buf, len,
                "%s%sport:%d status %06x %d %s%s%s%s%s%s "
                "sig=%s%s%s%s%s%s%s%s%s%s%s",
-               label, label [0] ? " " : "", port, status,
-               status>>25,/*device address */
-               (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ACK ?
+               label, label[0] ? " " : "", port, status,
+               status >> 25, /*device address */
+               (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ACK ?
                                                " ACK" : "",
-               (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_NYET ?
+               (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_NYET ?
                                                " NYET" : "",
-               (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_STALL ?
+               (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_STALL ?
                                                " STALL" : "",
-               (status & PORT_SSTS)>>23 == PORTSC_SUSPEND_STS_ERR ?
+               (status & PORT_SSTS) >> 23 == PORTSC_SUSPEND_STS_ERR ?
                                                " ERR" : "",
                (status & PORT_POWER) ? " POWER" : "",
                (status & PORT_OWNER) ? " OWNER" : "",
@@ -282,52 +283,68 @@ dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
 
 #else
 static inline void __maybe_unused
-dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
+dbg_qh(char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
 {}
 
 static inline int __maybe_unused
-dbg_status_buf (char *buf, unsigned len, const char *label, u32 status)
-{ return 0; }
+dbg_status_buf(char *buf, unsigned len, const char *label, u32 status)
+{
+       return 0;
+}
 
 static inline int __maybe_unused
-dbg_command_buf (char *buf, unsigned len, const char *label, u32 command)
-{ return 0; }
+dbg_command_buf(char *buf, unsigned len, const char *label, u32 command)
+{
+       return 0;
+}
 
 static inline int __maybe_unused
-dbg_intr_buf (char *buf, unsigned len, const char *label, u32 enable)
-{ return 0; }
+dbg_intr_buf(char *buf, unsigned len, const char *label, u32 enable)
+{
+       return 0;
+}
 
 static inline int __maybe_unused
-dbg_port_buf (char *buf, unsigned len, const char *label, int port, u32 status)
-{ return 0; }
+dbg_port_buf(char *buf, unsigned len, const char *label, int port, u32 status)
+{
+       return 0;
+}
 
 #endif /* CONFIG_DYNAMIC_DEBUG */
 
-/* functions have the "wrong" filename when they're output... */
-#define dbg_status(ehci, label, status) { \
-       char _buf [80]; \
-       dbg_status_buf (_buf, sizeof _buf, label, status); \
-       ehci_dbg (ehci, "%s\n", _buf); \
+static inline void
+dbg_status(struct ehci_hcd *ehci, const char *label, u32 status)
+{
+       char buf[80];
+
+       dbg_status_buf(buf, sizeof(buf), label, status);
+       ehci_dbg(ehci, "%s\n", buf);
 }
 
-#define dbg_cmd(ehci, label, command) { \
-       char _buf [80]; \
-       dbg_command_buf (_buf, sizeof _buf, label, command); \
-       ehci_dbg (ehci, "%s\n", _buf); \
+static inline void
+dbg_cmd(struct ehci_hcd *ehci, const char *label, u32 command)
+{
+       char buf[80];
+
+       dbg_command_buf(buf, sizeof(buf), label, command);
+       ehci_dbg(ehci, "%s\n", buf);
 }
 
-#define dbg_port(ehci, label, port, status) { \
-       char _buf [80]; \
-       dbg_port_buf (_buf, sizeof _buf, label, port, status); \
-       ehci_dbg (ehci, "%s\n", _buf); \
+static inline void
+dbg_port(struct ehci_hcd *ehci, const char *label, int port, u32 status)
+{
+       char buf[80];
+
+       dbg_port_buf(buf, sizeof(buf), label, port, status);
+       ehci_dbg(ehci, "%s\n", buf);
 }
 
 /*-------------------------------------------------------------------------*/
 
-#ifdef STUB_DEBUG_FILES
+#ifndef CONFIG_DYNAMIC_DEBUG
 
-static inline void create_debug_files (struct ehci_hcd *bus) { }
-static inline void remove_debug_files (struct ehci_hcd *bus) { }
+static inline void create_debug_files(struct ehci_hcd *bus) { }
+static inline void remove_debug_files(struct ehci_hcd *bus) { }
 
 #else
 
@@ -348,6 +365,7 @@ static const struct file_operations debug_async_fops = {
        .release        = debug_close,
        .llseek         = default_llseek,
 };
+
 static const struct file_operations debug_bandwidth_fops = {
        .owner          = THIS_MODULE,
        .open           = debug_bandwidth_open,
@@ -355,6 +373,7 @@ static const struct file_operations debug_bandwidth_fops = {
        .release        = debug_close,
        .llseek         = default_llseek,
 };
+
 static const struct file_operations debug_periodic_fops = {
        .owner          = THIS_MODULE,
        .open           = debug_periodic_open,
@@ -362,6 +381,7 @@ static const struct file_operations debug_periodic_fops = {
        .release        = debug_close,
        .llseek         = default_llseek,
 };
+
 static const struct file_operations debug_registers_fops = {
        .owner          = THIS_MODULE,
        .open           = debug_registers_open,
@@ -381,13 +401,19 @@ struct debug_buffer {
        size_t alloc_size;
 };
 
-#define speed_char(info1) ({ char tmp; \
-               switch (info1 & (3 << 12)) { \
-               case QH_FULL_SPEED: tmp = 'f'; break; \
-               case QH_LOW_SPEED:  tmp = 'l'; break; \
-               case QH_HIGH_SPEED: tmp = 'h'; break; \
-               default: tmp = '?'; break; \
-               } tmp; })
+static inline char speed_char(u32 info1)
+{
+       switch (info1 & (3 << 12)) {
+       case QH_FULL_SPEED:
+               return 'f';
+       case QH_LOW_SPEED:
+               return 'l';
+       case QH_HIGH_SPEED:
+               return 'h';
+       default:
+               return '?';
+       }
+}
 
 static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
 {
@@ -397,18 +423,14 @@ static inline char token_mark(struct ehci_hcd *ehci, __hc32 token)
                return '*';
        if (v & QTD_STS_HALT)
                return '-';
-       if (!IS_SHORT_READ (v))
+       if (!IS_SHORT_READ(v))
                return ' ';
        /* tries to advance through hw_alt_next */
        return '/';
 }
 
-static void qh_lines (
-       struct ehci_hcd *ehci,
-       struct ehci_qh *qh,
-       char **nextp,
-       unsigned *sizep
-)
+static void qh_lines(struct ehci_hcd *ehci, struct ehci_qh *qh,
+               char **nextp, unsigned *sizep)
 {
        u32                     scratch;
        u32                     hw_curr;
@@ -435,7 +457,7 @@ static void qh_lines (
        }
        scratch = hc32_to_cpup(ehci, &hw->hw_info1);
        hw_curr = (mark == '*') ? hc32_to_cpup(ehci, &hw->hw_current) : 0;
-       temp = scnprintf (next, size,
+       temp = scnprintf(next, size,
                        "qh/%p dev%d %cs ep%d %08x %08x (%08x%c %s nak%d)"
                        " [cur %08x next %08x buf[0] %08x]",
                        qh, scratch & 0x007f,
@@ -453,46 +475,52 @@ static void qh_lines (
        next += temp;
 
        /* hc may be modifying the list as we read it ... */
-       list_for_each (entry, &qh->qtd_list) {
-               td = list_entry (entry, struct ehci_qtd, qtd_list);
+       list_for_each(entry, &qh->qtd_list) {
+               char *type;
+
+               td = list_entry(entry, struct ehci_qtd, qtd_list);
                scratch = hc32_to_cpup(ehci, &td->hw_token);
                mark = ' ';
-               if (hw_curr == td->qtd_dma)
+               if (hw_curr == td->qtd_dma) {
                        mark = '*';
-               else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma))
+               } else if (hw->hw_qtd_next == cpu_to_hc32(ehci, td->qtd_dma)) {
                        mark = '+';
-               else if (QTD_LENGTH (scratch)) {
+               } else if (QTD_LENGTH(scratch)) {
                        if (td->hw_alt_next == ehci->async->hw->hw_alt_next)
                                mark = '#';
                        else if (td->hw_alt_next != list_end)
                                mark = '/';
                }
-               temp = snprintf (next, size,
+               switch ((scratch >> 8) & 0x03) {
+               case 0:
+                       type = "out";
+                       break;
+               case 1:
+                       type = "in";
+                       break;
+               case 2:
+                       type = "setup";
+                       break;
+               default:
+                       type = "?";
+                       break;
+               }
+               temp = scnprintf(next, size,
                                "\n\t%p%c%s len=%d %08x urb %p"
                                " [td %08x buf[0] %08x]",
-                               td, mark, ({ char *tmp;
-                                switch ((scratch>>8)&0x03) {
-                                case 0: tmp = "out"; break;
-                                case 1: tmp = "in"; break;
-                                case 2: tmp = "setup"; break;
-                                default: tmp = "?"; break;
-                                } tmp;}),
+                               td, mark, type,
                                (scratch >> 16) & 0x7fff,
                                scratch,
                                td->urb,
                                (u32) td->qtd_dma,
                                hc32_to_cpup(ehci, &td->hw_buf[0]));
-               if (size < temp)
-                       temp = size;
                size -= temp;
                next += temp;
                if (temp == size)
                        goto done;
        }
 
-       temp = snprintf (next, size, "\n");
-       if (size < temp)
-               temp = size;
+       temp = scnprintf(next, size, "\n");
        size -= temp;
        next += temp;
 
@@ -511,19 +539,20 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
        struct ehci_qh          *qh;
 
        hcd = bus_to_hcd(buf->bus);
-       ehci = hcd_to_ehci (hcd);
+       ehci = hcd_to_ehci(hcd);
        next = buf->output_buf;
        size = buf->alloc_size;
 
        *next = 0;
 
-       /* dumps a snapshot of the async schedule.
+       /*
+        * dumps a snapshot of the async schedule.
         * usually empty except for long-term bulk reads, or head.
         * one QH per line, and TDs we know about
         */
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
        for (qh = ehci->async->qh_next.qh; size > 0 && qh; qh = qh->qh_next.qh)
-               qh_lines (ehci, qh, &next, &size);
+               qh_lines(ehci, qh, &next, &size);
        if (!list_empty(&ehci->async_unlink) && size > 0) {
                temp = scnprintf(next, size, "\nunlink =\n");
                size -= temp;
@@ -535,7 +564,7 @@ static ssize_t fill_async_buffer(struct debug_buffer *buf)
                        qh_lines(ehci, qh, &next, &size);
                }
        }
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
 
        return strlen(buf->output_buf);
 }
@@ -623,6 +652,33 @@ static ssize_t fill_bandwidth_buffer(struct debug_buffer *buf)
        return next - buf->output_buf;
 }
 
+static unsigned output_buf_tds_dir(char *buf, struct ehci_hcd *ehci,
+               struct ehci_qh_hw *hw, struct ehci_qh *qh, unsigned size)
+{
+       u32                     scratch = hc32_to_cpup(ehci, &hw->hw_info1);
+       struct ehci_qtd         *qtd;
+       char                    *type = "";
+       unsigned                temp = 0;
+
+       /* count tds, get ep direction */
+       list_for_each_entry(qtd, &qh->qtd_list, qtd_list) {
+               temp++;
+               switch ((hc32_to_cpu(ehci, qtd->hw_token) >> 8) & 0x03) {
+               case 0:
+                       type = "out";
+                       continue;
+               case 1:
+                       type = "in";
+                       continue;
+               }
+       }
+
+       return scnprintf(buf, size, " (%c%d ep%d%s [%d/%d] q%d p%d)",
+                       speed_char(scratch), scratch & 0x007f,
+                       (scratch >> 8) & 0x000f, type, qh->ps.usecs,
+                       qh->ps.c_usecs, temp, 0x7ff & (scratch >> 16));
+}
+
 #define DBG_SCHED_LIMIT 64
 static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
 {
@@ -635,31 +691,32 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
        unsigned                i;
        __hc32                  tag;
 
-       seen = kmalloc(DBG_SCHED_LIMIT * sizeof *seen, GFP_ATOMIC);
+       seen = kmalloc_array(DBG_SCHED_LIMIT, sizeof(*seen), GFP_ATOMIC);
        if (!seen)
                return 0;
        seen_count = 0;
 
        hcd = bus_to_hcd(buf->bus);
-       ehci = hcd_to_ehci (hcd);
+       ehci = hcd_to_ehci(hcd);
        next = buf->output_buf;
        size = buf->alloc_size;
 
-       temp = scnprintf (next, size, "size = %d\n", ehci->periodic_size);
+       temp = scnprintf(next, size, "size = %d\n", ehci->periodic_size);
        size -= temp;
        next += temp;
 
-       /* dump a snapshot of the periodic schedule.
+       /*
+        * dump a snapshot of the periodic schedule.
         * iso changes, interrupt usually doesn't.
         */
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
        for (i = 0; i < ehci->periodic_size; i++) {
-               p = ehci->pshadow [i];
-               if (likely (!p.ptr))
+               p = ehci->pshadow[i];
+               if (likely(!p.ptr))
                        continue;
-               tag = Q_NEXT_TYPE(ehci, ehci->periodic [i]);
+               tag = Q_NEXT_TYPE(ehci, ehci->periodic[i]);
 
-               temp = scnprintf (next, size, "%4d: ", i);
+               temp = scnprintf(next, size, "%4d: ", i);
                size -= temp;
                next += temp;
 
@@ -669,7 +726,7 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
                        switch (hc32_to_cpu(ehci, tag)) {
                        case Q_TYPE_QH:
                                hw = p.qh->hw;
-                               temp = scnprintf (next, size, " qh%d-%04x/%p",
+                               temp = scnprintf(next, size, " qh%d-%04x/%p",
                                                p.qh->ps.period,
                                                hc32_to_cpup(ehci,
                                                        &hw->hw_info2)
@@ -680,10 +737,10 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
                                next += temp;
                                /* don't repeat what follows this qh */
                                for (temp = 0; temp < seen_count; temp++) {
-                                       if (seen [temp].ptr != p.ptr)
+                                       if (seen[temp].ptr != p.ptr)
                                                continue;
                                        if (p.qh->qh_next.ptr) {
-                                               temp = scnprintf (next, size,
+                                               temp = scnprintf(next, size,
                                                        " ...");
                                                size -= temp;
                                                next += temp;
@@ -692,58 +749,32 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
                                }
                                /* show more info the first time around */
                                if (temp == seen_count) {
-                                       u32     scratch = hc32_to_cpup(ehci,
-                                                       &hw->hw_info1);
-                                       struct ehci_qtd *qtd;
-                                       char            *type = "";
-
-                                       /* count tds, get ep direction */
-                                       temp = 0;
-                                       list_for_each_entry (qtd,
-                                                       &p.qh->qtd_list,
-                                                       qtd_list) {
-                                               temp++;
-                                               switch (0x03 & (hc32_to_cpu(
-                                                       ehci,
-                                                       qtd->hw_token) >> 8)) {
-                                               case 0: type = "out"; continue;
-                                               case 1: type = "in"; continue;
-                                               }
-                                       }
-
-                                       temp = scnprintf (next, size,
-                                               " (%c%d ep%d%s "
-                                               "[%d/%d] q%d p%d)",
-                                               speed_char (scratch),
-                                               scratch & 0x007f,
-                                               (scratch >> 8) & 0x000f, type,
-                                               p.qh->ps.usecs,
-                                               p.qh->ps.c_usecs,
-                                               temp,
-                                               0x7ff & (scratch >> 16));
+                                       temp = output_buf_tds_dir(next, ehci,
+                                               hw, p.qh, size);
 
                                        if (seen_count < DBG_SCHED_LIMIT)
-                                               seen [seen_count++].qh = p.qh;
-                               } else
+                                               seen[seen_count++].qh = p.qh;
+                               } else {
                                        temp = 0;
+                               }
                                tag = Q_NEXT_TYPE(ehci, hw->hw_next);
                                p = p.qh->qh_next;
                                break;
                        case Q_TYPE_FSTN:
-                               temp = scnprintf (next, size,
+                               temp = scnprintf(next, size,
                                        " fstn-%8x/%p", p.fstn->hw_prev,
                                        p.fstn);
                                tag = Q_NEXT_TYPE(ehci, p.fstn->hw_next);
                                p = p.fstn->fstn_next;
                                break;
                        case Q_TYPE_ITD:
-                               temp = scnprintf (next, size,
+                               temp = scnprintf(next, size,
                                        " itd/%p", p.itd);
                                tag = Q_NEXT_TYPE(ehci, p.itd->hw_next);
                                p = p.itd->itd_next;
                                break;
                        case Q_TYPE_SITD:
-                               temp = scnprintf (next, size,
+                               temp = scnprintf(next, size,
                                        " sitd%d-%04x/%p",
                                        p.sitd->stream->ps.period,
                                        hc32_to_cpup(ehci, &p.sitd->hw_uframe)
@@ -757,12 +788,12 @@ static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
                        next += temp;
                } while (p.ptr);
 
-               temp = scnprintf (next, size, "\n");
+               temp = scnprintf(next, size, "\n");
                size -= temp;
                next += temp;
        }
-       spin_unlock_irqrestore (&ehci->lock, flags);
-       kfree (seen);
+       spin_unlock_irqrestore(&ehci->lock, flags);
+       kfree(seen);
 
        return buf->alloc_size - size;
 }
@@ -789,19 +820,19 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
        struct ehci_hcd         *ehci;
        unsigned long           flags;
        unsigned                temp, size, i;
-       char                    *next, scratch [80];
-       static char             fmt [] = "%*s\n";
-       static char             label [] = "";
+       char                    *next, scratch[80];
+       static char             fmt[] = "%*s\n";
+       static char             label[] = "";
 
        hcd = bus_to_hcd(buf->bus);
-       ehci = hcd_to_ehci (hcd);
+       ehci = hcd_to_ehci(hcd);
        next = buf->output_buf;
        size = buf->alloc_size;
 
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
 
        if (!HCD_HW_ACCESSIBLE(hcd)) {
-               size = scnprintf (next, size,
+               size = scnprintf(next, size,
                        "bus %s, device %s\n"
                        "%s\n"
                        "SUSPENDED (no register access)\n",
@@ -813,7 +844,7 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
 
        /* Capability Registers */
        i = HC_VERSION(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
-       temp = scnprintf (next, size,
+       temp = scnprintf(next, size,
                "bus %s, device %s\n"
                "%s\n"
                "EHCI %x.%02x, rh state %s\n",
@@ -829,16 +860,16 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
        if (dev_is_pci(hcd->self.controller)) {
                struct pci_dev  *pdev;
                u32             offset, cap, cap2;
-               unsigned        count = 256/4;
+               unsigned        count = 256 / 4;
 
                pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller);
                offset = HCC_EXT_CAPS(ehci_readl(ehci,
                                &ehci->caps->hcc_params));
                while (offset && count--) {
-                       pci_read_config_dword (pdev, offset, &cap);
+                       pci_read_config_dword(pdev, offset, &cap);
                        switch (cap & 0xff) {
                        case 1:
-                               temp = scnprintf (next, size,
+                               temp = scnprintf(next, size,
                                        "ownership %08x%s%s\n", cap,
                                        (cap & (1 << 24)) ? " linux" : "",
                                        (cap & (1 << 16)) ? " firmware" : "");
@@ -846,8 +877,8 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
                                next += temp;
 
                                offset += 4;
-                               pci_read_config_dword (pdev, offset, &cap2);
-                               temp = scnprintf (next, size,
+                               pci_read_config_dword(pdev, offset, &cap2);
+                               temp = scnprintf(next, size,
                                        "SMI sts/enable 0x%08x\n", cap2);
                                size -= temp;
                                next += temp;
@@ -863,50 +894,50 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
        }
 #endif
 
-       // FIXME interpret both types of params
+       /* FIXME interpret both types of params */
        i = ehci_readl(ehci, &ehci->caps->hcs_params);
-       temp = scnprintf (next, size, "structural params 0x%08x\n", i);
+       temp = scnprintf(next, size, "structural params 0x%08x\n", i);
        size -= temp;
        next += temp;
 
        i = ehci_readl(ehci, &ehci->caps->hcc_params);
-       temp = scnprintf (next, size, "capability params 0x%08x\n", i);
+       temp = scnprintf(next, size, "capability params 0x%08x\n", i);
        size -= temp;
        next += temp;
 
        /* Operational Registers */
-       temp = dbg_status_buf (scratch, sizeof scratch, label,
+       temp = dbg_status_buf(scratch, sizeof(scratch), label,
                        ehci_readl(ehci, &ehci->regs->status));
-       temp = scnprintf (next, size, fmt, temp, scratch);
+       temp = scnprintf(next, size, fmt, temp, scratch);
        size -= temp;
        next += temp;
 
-       temp = dbg_command_buf (scratch, sizeof scratch, label,
+       temp = dbg_command_buf(scratch, sizeof(scratch), label,
                        ehci_readl(ehci, &ehci->regs->command));
-       temp = scnprintf (next, size, fmt, temp, scratch);
+       temp = scnprintf(next, size, fmt, temp, scratch);
        size -= temp;
        next += temp;
 
-       temp = dbg_intr_buf (scratch, sizeof scratch, label,
+       temp = dbg_intr_buf(scratch, sizeof(scratch), label,
                        ehci_readl(ehci, &ehci->regs->intr_enable));
-       temp = scnprintf (next, size, fmt, temp, scratch);
+       temp = scnprintf(next, size, fmt, temp, scratch);
        size -= temp;
        next += temp;
 
-       temp = scnprintf (next, size, "uframe %04x\n",
+       temp = scnprintf(next, size, "uframe %04x\n",
                        ehci_read_frame_index(ehci));
        size -= temp;
        next += temp;
 
-       for (i = 1; i <= HCS_N_PORTS (ehci->hcs_params); i++) {
-               temp = dbg_port_buf (scratch, sizeof scratch, label, i,
+       for (i = 1; i <= HCS_N_PORTS(ehci->hcs_params); i++) {
+               temp = dbg_port_buf(scratch, sizeof(scratch), label, i,
                                ehci_readl(ehci,
                                        &ehci->regs->port_status[i - 1]));
-               temp = scnprintf (next, size, fmt, temp, scratch);
+               temp = scnprintf(next, size, fmt, temp, scratch);
                size -= temp;
                next += temp;
                if (i == HCS_DEBUG_PORT(ehci->hcs_params) && ehci->debug) {
-                       temp = scnprintf (next, size,
+                       temp = scnprintf(next, size,
                                        "    debug control %08x\n",
                                        ehci_readl(ehci,
                                                &ehci->debug->control));
@@ -924,31 +955,31 @@ static ssize_t fill_registers_buffer(struct debug_buffer *buf)
        }
 
 #ifdef EHCI_STATS
-       temp = scnprintf (next, size,
+       temp = scnprintf(next, size,
                "irq normal %ld err %ld iaa %ld (lost %ld)\n",
                ehci->stats.normal, ehci->stats.error, ehci->stats.iaa,
                ehci->stats.lost_iaa);
        size -= temp;
        next += temp;
 
-       temp = scnprintf (next, size, "complete %ld unlink %ld\n",
+       temp = scnprintf(next, size, "complete %ld unlink %ld\n",
                ehci->stats.complete, ehci->stats.unlink);
        size -= temp;
        next += temp;
 #endif
 
 done:
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
 
        return buf->alloc_size - size;
 }
 
 static struct debug_buffer *alloc_buffer(struct usb_bus *bus,
-                               ssize_t (*fill_func)(struct debug_buffer *))
+               ssize_t (*fill_func)(struct debug_buffer *))
 {
        struct debug_buffer *buf;
 
-       buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
+       buf = kzalloc(sizeof(*buf), GFP_KERNEL);
 
        if (buf) {
                buf->bus = bus;
@@ -984,7 +1015,7 @@ out:
 }
 
 static ssize_t debug_output(struct file *file, char __user *user_buf,
-                           size_t len, loff_t *offset)
+               size_t len, loff_t *offset)
 {
        struct debug_buffer *buf = file->private_data;
        int ret = 0;
@@ -1004,7 +1035,6 @@ static ssize_t debug_output(struct file *file, char __user *user_buf,
 
 out:
        return ret;
-
 }
 
 static int debug_close(struct inode *inode, struct file *file)
@@ -1037,11 +1067,12 @@ static int debug_bandwidth_open(struct inode *inode, struct file *file)
 static int debug_periodic_open(struct inode *inode, struct file *file)
 {
        struct debug_buffer *buf;
+
        buf = alloc_buffer(inode->i_private, fill_periodic_buffer);
        if (!buf)
                return -ENOMEM;
 
-       buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8)*PAGE_SIZE;
+       buf->alloc_size = (sizeof(void *) == 4 ? 6 : 8) * PAGE_SIZE;
        file->private_data = buf;
        return 0;
 }
@@ -1054,7 +1085,7 @@ static int debug_registers_open(struct inode *inode, struct file *file)
        return file->private_data ? 0 : -ENOMEM;
 }
 
-static inline void create_debug_files (struct ehci_hcd *ehci)
+static inline void create_debug_files(struct ehci_hcd *ehci)
 {
        struct usb_bus *bus = &ehci_to_hcd(ehci)->self;
 
@@ -1084,9 +1115,9 @@ file_error:
        debugfs_remove_recursive(ehci->debug_dir);
 }
 
-static inline void remove_debug_files (struct ehci_hcd *ehci)
+static inline void remove_debug_files(struct ehci_hcd *ehci)
 {
        debugfs_remove_recursive(ehci->debug_dir);
 }
 
-#endif /* STUB_DEBUG_FILES */
+#endif /* CONFIG_DYNAMIC_DEBUG */
index 3b6eb21..9f5ffb6 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/usb/otg.h>
 #include <linux/platform_device.h>
 #include <linux/fsl_devices.h>
+#include <linux/of_platform.h>
 
 #include "ehci.h"
 #include "ehci-fsl.h"
@@ -241,7 +242,8 @@ static int ehci_fsl_setup_phy(struct usb_hcd *hcd,
         * to portsc
         */
        if (pdata->check_phy_clk_valid) {
-               if (!(in_be32(non_ehci + FSL_SOC_USB_CTRL) & PHY_CLK_VALID)) {
+               if (!(ioread32be(non_ehci + FSL_SOC_USB_CTRL) &
+                   PHY_CLK_VALID)) {
                        dev_warn(hcd->self.controller,
                                 "USB PHY clock invalid\n");
                        return -EINVAL;
@@ -273,9 +275,11 @@ static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 
                /* Setup Snooping for all the 4GB space */
                /* SNOOP1 starts from 0x0, size 2G */
-               out_be32(non_ehci + FSL_SOC_USB_SNOOP1, 0x0 | SNOOP_SIZE_2GB);
+               iowrite32be(0x0 | SNOOP_SIZE_2GB,
+                           non_ehci + FSL_SOC_USB_SNOOP1);
                /* SNOOP2 starts from 0x80000000, size 2G */
-               out_be32(non_ehci + FSL_SOC_USB_SNOOP2, 0x80000000 | SNOOP_SIZE_2GB);
+               iowrite32be(0x80000000 | SNOOP_SIZE_2GB,
+                           non_ehci + FSL_SOC_USB_SNOOP2);
        }
 
        /* Deal with USB erratum A-005275 */
@@ -309,13 +313,13 @@ static int ehci_fsl_usb_setup(struct ehci_hcd *ehci)
 
        if (pdata->have_sysif_regs) {
 #ifdef CONFIG_FSL_SOC_BOOKE
-               out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x00000008);
-               out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000080);
+               iowrite32be(0x00000008, non_ehci + FSL_SOC_USB_PRICTRL);
+               iowrite32be(0x00000080, non_ehci + FSL_SOC_USB_AGECNTTHRSH);
 #else
-               out_be32(non_ehci + FSL_SOC_USB_PRICTRL, 0x0000000c);
-               out_be32(non_ehci + FSL_SOC_USB_AGECNTTHRSH, 0x00000040);
+               iowrite32be(0x0000000c, non_ehci + FSL_SOC_USB_PRICTRL);
+               iowrite32be(0x00000040, non_ehci + FSL_SOC_USB_AGECNTTHRSH);
 #endif
-               out_be32(non_ehci + FSL_SOC_USB_SICTRL, 0x00000001);
+               iowrite32be(0x00000001, non_ehci + FSL_SOC_USB_SICTRL);
        }
 
        return 0;
@@ -554,7 +558,7 @@ static int ehci_fsl_drv_suspend(struct device *dev)
        if (!fsl_deep_sleep())
                return 0;
 
-       ehci_fsl->usb_ctrl = in_be32(non_ehci + FSL_SOC_USB_CTRL);
+       ehci_fsl->usb_ctrl = ioread32be(non_ehci + FSL_SOC_USB_CTRL);
        return 0;
 }
 
@@ -577,7 +581,7 @@ static int ehci_fsl_drv_resume(struct device *dev)
        usb_root_hub_lost_power(hcd->self.root_hub);
 
        /* Restore USB PHY settings and enable the controller. */
-       out_be32(non_ehci + FSL_SOC_USB_CTRL, ehci_fsl->usb_ctrl);
+       iowrite32be(ehci_fsl->usb_ctrl, non_ehci + FSL_SOC_USB_CTRL);
 
        ehci_reset(ehci);
        ehci_fsl_reinit(ehci);
index 14178bb..ae1b6e6 100644 (file)
@@ -306,9 +306,9 @@ static void ehci_quiesce (struct ehci_hcd *ehci)
 
 /*-------------------------------------------------------------------------*/
 
+static void end_iaa_cycle(struct ehci_hcd *ehci);
 static void end_unlink_async(struct ehci_hcd *ehci);
 static void unlink_empty_async(struct ehci_hcd *ehci);
-static void unlink_empty_async_suspended(struct ehci_hcd *ehci);
 static void ehci_work(struct ehci_hcd *ehci);
 static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
 static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh);
@@ -565,6 +565,9 @@ static int ehci_init(struct usb_hcd *hcd)
        /* Accept arbitrarily long scatter-gather lists */
        if (!(hcd->driver->flags & HCD_LOCAL_MEM))
                hcd->self.sg_tablesize = ~0;
+
+       /* Prepare for unlinking active QHs */
+       ehci->old_current = ~0;
        return 0;
 }
 
@@ -675,8 +678,10 @@ int ehci_setup(struct usb_hcd *hcd)
                return retval;
 
        retval = ehci_halt(ehci);
-       if (retval)
+       if (retval) {
+               ehci_mem_cleanup(ehci);
                return retval;
+       }
 
        ehci_reset(ehci);
 
@@ -756,7 +761,7 @@ static irqreturn_t ehci_irq (struct usb_hcd *hcd)
                        ehci_dbg(ehci, "IAA with IAAD still set?\n");
                if (ehci->iaa_in_progress)
                        COUNT(ehci->stats.iaa);
-               end_unlink_async(ehci);
+               end_iaa_cycle(ehci);
        }
 
        /* remote wakeup [4.3.1] */
@@ -909,7 +914,7 @@ static int ehci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
                 */
        } else {
                qh = (struct ehci_qh *) urb->hcpriv;
-               qh->exception = 1;
+               qh->unlink_reason |= QH_UNLINK_REQUESTED;
                switch (qh->qh_state) {
                case QH_STATE_LINKED:
                        if (usb_pipetype(urb->pipe) == PIPE_INTERRUPT)
@@ -970,10 +975,13 @@ rescan:
                goto done;
        }
 
-       qh->exception = 1;
+       qh->unlink_reason |= QH_UNLINK_REQUESTED;
        switch (qh->qh_state) {
        case QH_STATE_LINKED:
-               WARN_ON(!list_empty(&qh->qtd_list));
+               if (list_empty(&qh->qtd_list))
+                       qh->unlink_reason |= QH_UNLINK_QUEUE_EMPTY;
+               else
+                       WARN_ON(1);
                if (usb_endpoint_type(&ep->desc) != USB_ENDPOINT_XFER_INT)
                        start_unlink_async(ehci, qh);
                else
@@ -1040,7 +1048,7 @@ ehci_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
                         * re-linking will call qh_refresh().
                         */
                        usb_settoggle(qh->ps.udev, epnum, is_out, 0);
-                       qh->exception = 1;
+                       qh->unlink_reason |= QH_UNLINK_REQUESTED;
                        if (eptype == USB_ENDPOINT_XFER_BULK)
                                start_unlink_async(ehci, qh);
                        else
index 086a711..ffc9029 100644 (file)
@@ -33,6 +33,8 @@
 
 #ifdef CONFIG_PM
 
+static void unlink_empty_async_suspended(struct ehci_hcd *ehci);
+
 static int persist_enabled_on_companion(struct usb_device *udev, void *unused)
 {
        return !udev->maxchild && udev->persist_enabled &&
@@ -347,8 +349,10 @@ static int ehci_bus_suspend (struct usb_hcd *hcd)
                goto done;
        ehci->rh_state = EHCI_RH_SUSPENDED;
 
-       end_unlink_async(ehci);
        unlink_empty_async_suspended(ehci);
+
+       /* Any IAA cycle that started before the suspend is now invalid */
+       end_iaa_cycle(ehci);
        ehci_handle_start_intr_unlinks(ehci);
        ehci_handle_intr_unlinks(ehci);
        end_free_itds(ehci);
index c23e285..3e226ef 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/usb/msm_hsusb_hw.h>
 #include <linux/usb.h>
 #include <linux/usb/hcd.h>
+#include <linux/acpi.h>
 
 #include "ehci.h"
 
@@ -55,12 +56,16 @@ static int ehci_msm_reset(struct usb_hcd *hcd)
        if (retval)
                return retval;
 
+       /* select ULPI phy and clear other status/control bits in PORTSC */
+       writel(PORTSC_PTS_ULPI, USB_PORTSC);
        /* bursts of unspecified length. */
        writel(0, USB_AHBBURST);
        /* Use the AHB transactor, allow posted data writes */
        writel(0x8, USB_AHBMODE);
        /* Disable streaming mode and select host mode */
        writel(0x13, USB_USBMODE);
+       /* Disable ULPI_TX_PKT_EN_CLR_FIX which is valid only for HSIC */
+       writel(readl(USB_GENCONFIG_2) & ~ULPI_TX_PKT_EN_CLR_FIX, USB_GENCONFIG_2);
 
        return 0;
 }
@@ -104,9 +109,9 @@ static int ehci_msm_probe(struct platform_device *pdev)
        }
 
        /*
-        * OTG driver takes care of PHY initialization, clock management,
-        * powering up VBUS, mapping of registers address space and power
-        * management.
+        * If there is an OTG driver, let it take care of PHY initialization,
+        * clock management, powering up VBUS, mapping of registers address
+        * space and power management.
         */
        if (pdev->dev.of_node)
                phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0);
@@ -114,27 +119,35 @@ static int ehci_msm_probe(struct platform_device *pdev)
                phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
 
        if (IS_ERR(phy)) {
-               dev_err(&pdev->dev, "unable to find transceiver\n");
-               ret = -EPROBE_DEFER;
-               goto put_hcd;
-       }
-
-       ret = otg_set_host(phy->otg, &hcd->self);
-       if (ret < 0) {
-               dev_err(&pdev->dev, "unable to register with transceiver\n");
-               goto put_hcd;
+               if (PTR_ERR(phy) == -EPROBE_DEFER) {
+                       dev_err(&pdev->dev, "unable to find transceiver\n");
+                       ret = -EPROBE_DEFER;
+                       goto put_hcd;
+               }
+               phy = NULL;
        }
 
        hcd->usb_phy = phy;
        device_init_wakeup(&pdev->dev, 1);
-       /*
-        * OTG device parent of HCD takes care of putting
-        * hardware into low power mode.
-        */
-       pm_runtime_no_callbacks(&pdev->dev);
-       pm_runtime_enable(&pdev->dev);
 
-       /* FIXME: need to call usb_add_hcd() here? */
+       if (phy && phy->otg) {
+               /*
+                * MSM OTG driver takes care of adding the HCD and
+                * placing hardware into low power mode via runtime PM.
+                */
+               ret = otg_set_host(phy->otg, &hcd->self);
+               if (ret < 0) {
+                       dev_err(&pdev->dev, "unable to register with transceiver\n");
+                       goto put_hcd;
+               }
+
+               pm_runtime_no_callbacks(&pdev->dev);
+               pm_runtime_enable(&pdev->dev);
+       } else {
+               ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
+               if (ret)
+                       goto put_hcd;
+       }
 
        return 0;
 
@@ -152,9 +165,10 @@ static int ehci_msm_remove(struct platform_device *pdev)
        pm_runtime_disable(&pdev->dev);
        pm_runtime_set_suspended(&pdev->dev);
 
-       otg_set_host(hcd->usb_phy->otg, NULL);
-
-       /* FIXME: need to call usb_remove_hcd() here? */
+       if (hcd->usb_phy && hcd->usb_phy->otg)
+               otg_set_host(hcd->usb_phy->otg, NULL);
+       else
+               usb_remove_hcd(hcd);
 
        usb_put_hcd(hcd);
 
@@ -191,6 +205,12 @@ static const struct dev_pm_ops ehci_msm_dev_pm_ops = {
        .resume          = ehci_msm_pm_resume,
 };
 
+static const struct acpi_device_id msm_ehci_acpi_ids[] = {
+       { "QCOM8040", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(acpi, msm_ehci_acpi_ids);
+
 static const struct of_device_id msm_ehci_dt_match[] = {
        { .compatible = "qcom,ehci-host", },
        {}
@@ -200,10 +220,12 @@ MODULE_DEVICE_TABLE(of, msm_ehci_dt_match);
 static struct platform_driver ehci_msm_driver = {
        .probe  = ehci_msm_probe,
        .remove = ehci_msm_remove,
+       .shutdown = usb_hcd_platform_shutdown,
        .driver = {
                   .name = "msm_hsusb_host",
                   .pm = &ehci_msm_dev_pm_ops,
                   .of_match_table = msm_ehci_dt_match,
+                  .acpi_match_table = ACPI_PTR(msm_ehci_acpi_ids),
        },
 };
 
index 2a5d2fd..3b3649d 100644 (file)
@@ -377,6 +377,12 @@ static int ehci_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
        return usb_hcd_pci_probe(pdev, id);
 }
 
+static void ehci_pci_remove(struct pci_dev *pdev)
+{
+       pci_clear_mwi(pdev);
+       usb_hcd_pci_remove(pdev);       
+}
+
 /* PCI driver selection metadata; PCI hotplugging uses this */
 static const struct pci_device_id pci_ids [] = { {
        /* handle any USB 2.0 EHCI controller */
@@ -396,7 +402,7 @@ static struct pci_driver ehci_pci_driver = {
        .id_table =     pci_ids,
 
        .probe =        ehci_pci_probe,
-       .remove =       usb_hcd_pci_remove,
+       .remove =       ehci_pci_remove,
        .shutdown =     usb_hcd_pci_shutdown,
 
 #ifdef CONFIG_PM
index bd7082f..1757ebb 100644 (file)
@@ -345,8 +345,7 @@ static int ehci_platform_suspend(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
        bool do_wakeup = device_may_wakeup(dev);
        int ret;
 
@@ -364,8 +363,7 @@ static int ehci_platform_resume(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
        struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
 
        if (pdata->power_on) {
index aad0777..eca3710 100644 (file)
@@ -394,6 +394,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
                                        goto retry_xacterr;
                                }
                                stopped = 1;
+                               qh->unlink_reason |= QH_UNLINK_HALTED;
 
                        /* magic dummy for some short reads; qh won't advance.
                         * that silicon quirk can kick in with this dummy too.
@@ -408,6 +409,7 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
                                        && !(qtd->hw_alt_next
                                                & EHCI_LIST_END(ehci))) {
                                stopped = 1;
+                               qh->unlink_reason |= QH_UNLINK_SHORT_READ;
                        }
 
                /* stop scanning when we reach qtds the hc is using */
@@ -420,8 +422,10 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
                        stopped = 1;
 
                        /* cancel everything if we halt, suspend, etc */
-                       if (ehci->rh_state < EHCI_RH_RUNNING)
+                       if (ehci->rh_state < EHCI_RH_RUNNING) {
                                last_status = -ESHUTDOWN;
+                               qh->unlink_reason |= QH_UNLINK_SHUTDOWN;
+                       }
 
                        /* this qtd is active; skip it unless a previous qtd
                         * for its urb faulted, or its urb was canceled.
@@ -538,10 +542,10 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
         * except maybe high bandwidth ...
         */
        if (stopped != 0 || hw->hw_qtd_next == EHCI_LIST_END(ehci))
-               qh->exception = 1;
+               qh->unlink_reason |= QH_UNLINK_DUMMY_OVERLAY;
 
        /* Let the caller know if the QH needs to be unlinked. */
-       return qh->exception;
+       return qh->unlink_reason;
 }
 
 /*-------------------------------------------------------------------------*/
@@ -1003,7 +1007,7 @@ static void qh_link_async (struct ehci_hcd *ehci, struct ehci_qh *qh)
 
        qh->qh_state = QH_STATE_LINKED;
        qh->xacterrs = 0;
-       qh->exception = 0;
+       qh->unlink_reason = 0;
        /* qtd completions reported later by interrupt */
 
        enable_async(ehci);
@@ -1279,17 +1283,13 @@ static void single_unlink_async(struct ehci_hcd *ehci, struct ehci_qh *qh)
 
 static void start_iaa_cycle(struct ehci_hcd *ehci)
 {
-       /* Do nothing if an IAA cycle is already running */
-       if (ehci->iaa_in_progress)
-               return;
-       ehci->iaa_in_progress = true;
-
        /* If the controller isn't running, we don't have to wait for it */
        if (unlikely(ehci->rh_state < EHCI_RH_RUNNING)) {
                end_unlink_async(ehci);
 
-       /* Otherwise start a new IAA cycle */
-       } else if (likely(ehci->rh_state == EHCI_RH_RUNNING)) {
+       /* Otherwise start a new IAA cycle if one isn't already running */
+       } else if (ehci->rh_state == EHCI_RH_RUNNING &&
+                       !ehci->iaa_in_progress) {
 
                /* Make sure the unlinks are all visible to the hardware */
                wmb();
@@ -1297,17 +1297,13 @@ static void start_iaa_cycle(struct ehci_hcd *ehci)
                ehci_writel(ehci, ehci->command | CMD_IAAD,
                                &ehci->regs->command);
                ehci_readl(ehci, &ehci->regs->command);
+               ehci->iaa_in_progress = true;
                ehci_enable_event(ehci, EHCI_HRTIMER_IAA_WATCHDOG, true);
        }
 }
 
-/* the async qh for the qtds being unlinked are now gone from the HC */
-
-static void end_unlink_async(struct ehci_hcd *ehci)
+static void end_iaa_cycle(struct ehci_hcd *ehci)
 {
-       struct ehci_qh          *qh;
-       bool                    early_exit;
-
        if (ehci->has_synopsys_hc_bug)
                ehci_writel(ehci, (u32) ehci->async->qh_dma,
                            &ehci->regs->async_next);
@@ -1315,6 +1311,16 @@ static void end_unlink_async(struct ehci_hcd *ehci)
        /* The current IAA cycle has ended */
        ehci->iaa_in_progress = false;
 
+       end_unlink_async(ehci);
+}
+
+/* See if the async qh for the qtds being unlinked are now gone from the HC */
+
+static void end_unlink_async(struct ehci_hcd *ehci)
+{
+       struct ehci_qh          *qh;
+       bool                    early_exit;
+
        if (list_empty(&ehci->async_unlink))
                return;
        qh = list_first_entry(&ehci->async_unlink, struct ehci_qh,
@@ -1335,14 +1341,60 @@ static void end_unlink_async(struct ehci_hcd *ehci)
         * after the IAA interrupt occurs.  In self-defense, always go
         * through two IAA cycles for each QH.
         */
-       else if (qh->qh_state == QH_STATE_UNLINK_WAIT) {
+       else if (qh->qh_state == QH_STATE_UNLINK) {
+               /*
+                * Second IAA cycle has finished.  Process only the first
+                * waiting QH (NVIDIA (?) bug).
+                */
+               list_move_tail(&qh->unlink_node, &ehci->async_idle);
+       }
+
+       /*
+        * AMD/ATI (?) bug: The HC can continue to use an active QH long
+        * after the IAA interrupt occurs.  To prevent problems, QHs that
+        * may still be active will wait until 2 ms have passed with no
+        * change to the hw_current and hw_token fields (this delay occurs
+        * between the two IAA cycles).
+        *
+        * The EHCI spec (4.8.2) says that active QHs must not be removed
+        * from the async schedule and recommends waiting until the QH
+        * goes inactive.  This is ridiculous because the QH will _never_
+        * become inactive if the endpoint NAKs indefinitely.
+        */
+
+       /* Some reasons for unlinking guarantee the QH can't be active */
+       else if (qh->unlink_reason & (QH_UNLINK_HALTED |
+                       QH_UNLINK_SHORT_READ | QH_UNLINK_DUMMY_OVERLAY))
+               goto DelayDone;
+
+       /* The QH can't be active if the queue was and still is empty... */
+       else if ((qh->unlink_reason & QH_UNLINK_QUEUE_EMPTY) &&
+                       list_empty(&qh->qtd_list))
+               goto DelayDone;
+
+       /* ... or if the QH has halted */
+       else if (qh->hw->hw_token & cpu_to_hc32(ehci, QTD_STS_HALT))
+               goto DelayDone;
+
+       /* Otherwise we have to wait until the QH stops changing */
+       else {
+               __hc32          qh_current, qh_token;
+
+               qh_current = qh->hw->hw_current;
+               qh_token = qh->hw->hw_token;
+               if (qh_current != ehci->old_current ||
+                               qh_token != ehci->old_token) {
+                       ehci->old_current = qh_current;
+                       ehci->old_token = qh_token;
+                       ehci_enable_event(ehci,
+                                       EHCI_HRTIMER_ACTIVE_UNLINK, true);
+                       return;
+               }
+ DelayDone:
                qh->qh_state = QH_STATE_UNLINK;
                early_exit = true;
        }
-
-       /* Otherwise process only the first waiting QH (NVIDIA bug?) */
-       else
-               list_move_tail(&qh->unlink_node, &ehci->async_idle);
+       ehci->old_current = ~0;         /* Prepare for next QH */
 
        /* Start a new IAA cycle if any QHs are waiting for it */
        if (!list_empty(&ehci->async_unlink))
@@ -1395,6 +1447,7 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
 
        /* If nothing else is being unlinked, unlink the last empty QH */
        if (list_empty(&ehci->async_unlink) && qh_to_unlink) {
+               qh_to_unlink->unlink_reason |= QH_UNLINK_QUEUE_EMPTY;
                start_unlink_async(ehci, qh_to_unlink);
                --count;
        }
@@ -1406,8 +1459,10 @@ static void unlink_empty_async(struct ehci_hcd *ehci)
        }
 }
 
+#ifdef CONFIG_PM
+
 /* The root hub is suspended; unlink all the async QHs */
-static void __maybe_unused unlink_empty_async_suspended(struct ehci_hcd *ehci)
+static void unlink_empty_async_suspended(struct ehci_hcd *ehci)
 {
        struct ehci_qh          *qh;
 
@@ -1416,9 +1471,10 @@ static void __maybe_unused unlink_empty_async_suspended(struct ehci_hcd *ehci)
                WARN_ON(!list_empty(&qh->qtd_list));
                single_unlink_async(ehci, qh);
        }
-       start_iaa_cycle(ehci);
 }
 
+#endif
+
 /* makes sure the async qh will become idle */
 /* caller must own ehci->lock */
 
index f9a3327..1dfe54f 100644 (file)
@@ -34,7 +34,7 @@
  * pre-calculated schedule data to make appending to the queue be quick.
  */
 
-static int ehci_get_frame (struct usb_hcd *hcd);
+static int ehci_get_frame(struct usb_hcd *hcd);
 
 /*
  * periodic_next_shadow - return "next" pointer on shadow list
@@ -52,7 +52,7 @@ periodic_next_shadow(struct ehci_hcd *ehci, union ehci_shadow *periodic,
                return &periodic->fstn->fstn_next;
        case Q_TYPE_ITD:
                return &periodic->itd->itd_next;
-       // case Q_TYPE_SITD:
+       /* case Q_TYPE_SITD: */
        default:
                return &periodic->sitd->sitd_next;
        }
@@ -73,7 +73,7 @@ shadow_next_periodic(struct ehci_hcd *ehci, union ehci_shadow *periodic,
 }
 
 /* caller must hold ehci->lock */
-static void periodic_unlink (struct ehci_hcd *ehci, unsigned frame, void *ptr)
+static void periodic_unlink(struct ehci_hcd *ehci, unsigned frame, void *ptr)
 {
        union ehci_shadow       *prev_p = &ehci->pshadow[frame];
        __hc32                  *hw_p = &ehci->periodic[frame];
@@ -296,10 +296,9 @@ static void compute_tt_budget(u8 budget_table[EHCI_BANDWIDTH_SIZE],
                                if (x <= 125) {
                                        budget_line[uf] = x;
                                        break;
-                               } else {
-                                       budget_line[uf] = 125;
-                                       x -= 125;
                                }
+                               budget_line[uf] = 125;
+                               x -= 125;
                        }
                }
        }
@@ -330,7 +329,8 @@ static int __maybe_unused same_tt(struct usb_device *dev1,
  */
 static inline unsigned char tt_start_uframe(struct ehci_hcd *ehci, __hc32 mask)
 {
-       unsigned char smask = QH_SMASK & hc32_to_cpu(ehci, mask);
+       unsigned char smask = hc32_to_cpu(ehci, mask) & QH_SMASK;
+
        if (!smask) {
                ehci_err(ehci, "invalid empty smask!\n");
                /* uframe 7 can't have bw so this will indicate failure */
@@ -346,7 +346,8 @@ max_tt_usecs[] = { 125, 125, 125, 125, 125, 125, 30, 0 };
 static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
 {
        int i;
-       for (i=0; i<7; i++) {
+
+       for (i = 0; i < 7; i++) {
                if (max_tt_usecs[i] < tt_usecs[i]) {
                        tt_usecs[i+1] += tt_usecs[i] - max_tt_usecs[i];
                        tt_usecs[i] = max_tt_usecs[i];
@@ -375,7 +376,7 @@ static inline void carryover_tt_bandwidth(unsigned short tt_usecs[8])
  * limit of 16, specified in USB 2.0 spec section 11.18.4 requirement #4,
  * since proper scheduling limits ssplits to less than 16 per uframe.
  */
-static int tt_available (
+static int tt_available(
        struct ehci_hcd         *ehci,
        struct ehci_per_sched   *ps,
        struct ehci_tt          *tt,
@@ -409,11 +410,11 @@ static int tt_available (
                 * must be empty, so as to not illegally delay
                 * already scheduled transactions
                 */
-               if (125 < usecs) {
+               if (usecs > 125) {
                        int ufs = (usecs / 125);
 
                        for (i = uframe; i < (uframe + ufs) && i < 8; i++)
-                               if (0 < tt_usecs[i])
+                               if (tt_usecs[i] > 0)
                                        return 0;
                }
 
@@ -435,7 +436,7 @@ static int tt_available (
  * for a periodic transfer starting at the specified frame, using
  * all the uframes in the mask.
  */
-static int tt_no_collision (
+static int tt_no_collision(
        struct ehci_hcd         *ehci,
        unsigned                period,
        struct usb_device       *dev,
@@ -455,8 +456,8 @@ static int tt_no_collision (
                __hc32                  type;
                struct ehci_qh_hw       *hw;
 
-               here = ehci->pshadow [frame];
-               type = Q_NEXT_TYPE(ehci, ehci->periodic [frame]);
+               here = ehci->pshadow[frame];
+               type = Q_NEXT_TYPE(ehci, ehci->periodic[frame]);
                while (here.ptr) {
                        switch (hc32_to_cpu(ehci, type)) {
                        case Q_TYPE_ITD:
@@ -479,7 +480,7 @@ static int tt_no_collision (
                                here = here.qh->qh_next;
                                continue;
                        case Q_TYPE_SITD:
-                               if (same_tt (dev, here.sitd->urb->dev)) {
+                               if (same_tt(dev, here.sitd->urb->dev)) {
                                        u16             mask;
 
                                        mask = hc32_to_cpu(ehci, here.sitd
@@ -492,9 +493,9 @@ static int tt_no_collision (
                                type = Q_NEXT_TYPE(ehci, here.sitd->hw_next);
                                here = here.sitd->sitd_next;
                                continue;
-                       // case Q_TYPE_FSTN:
+                       /* case Q_TYPE_FSTN: */
                        default:
-                               ehci_dbg (ehci,
+                               ehci_dbg(ehci,
                                        "periodic frame %d bogus type %d\n",
                                        frame, type);
                        }
@@ -588,14 +589,14 @@ static void qh_link_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
                        qh->qh_next = here;
                        if (here.qh)
                                qh->hw->hw_next = *hw_p;
-                       wmb ();
+                       wmb();
                        prev->qh = qh;
-                       *hw_p = QH_NEXT (ehci, qh->qh_dma);
+                       *hw_p = QH_NEXT(ehci, qh->qh_dma);
                }
        }
        qh->qh_state = QH_STATE_LINKED;
        qh->xacterrs = 0;
-       qh->exception = 0;
+       qh->unlink_reason = 0;
 
        /* update per-qh bandwidth for debugfs */
        ehci_to_hcd(ehci)->self.bandwidth_allocated += qh->ps.bw_period
@@ -633,7 +634,7 @@ static void qh_unlink_periodic(struct ehci_hcd *ehci, struct ehci_qh *qh)
        period = qh->ps.period ? : 1;
 
        for (i = qh->ps.phase; i < ehci->periodic_size; i += period)
-               periodic_unlink (ehci, i, qh);
+               periodic_unlink(ehci, i, qh);
 
        /* update per-qh bandwidth for debugfs */
        ehci_to_hcd(ehci)->self.bandwidth_allocated -= qh->ps.bw_period
@@ -679,7 +680,7 @@ static void start_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
        /* if the qh is waiting for unlink, cancel it now */
        cancel_unlink_wait_intr(ehci, qh);
 
-       qh_unlink_periodic (ehci, qh);
+       qh_unlink_periodic(ehci, qh);
 
        /* Make sure the unlinks are visible before starting the timer */
        wmb();
@@ -763,7 +764,7 @@ static void end_unlink_intr(struct ehci_hcd *ehci, struct ehci_qh *qh)
 
 /*-------------------------------------------------------------------------*/
 
-static int check_period (
+static int check_period(
        struct ehci_hcd *ehci,
        unsigned        frame,
        unsigned        uframe,
@@ -785,11 +786,11 @@ static int check_period (
                        return 0;
        }
 
-       // success!
+       /* success! */
        return 1;
 }
 
-static int check_intr_schedule (
+static int check_intr_schedule(
        struct ehci_hcd         *ehci,
        unsigned                frame,
        unsigned                uframe,
@@ -925,7 +926,7 @@ done:
        return status;
 }
 
-static int intr_submit (
+static int intr_submit(
        struct ehci_hcd         *ehci,
        struct urb              *urb,
        struct list_head        *qtd_list,
@@ -940,7 +941,7 @@ static int intr_submit (
        /* get endpoint and transfer/schedule data */
        epnum = urb->ep->desc.bEndpointAddress;
 
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
 
        if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
                status = -ESHUTDOWN;
@@ -951,20 +952,21 @@ static int intr_submit (
                goto done_not_linked;
 
        /* get qh and force any scheduling errors */
-       INIT_LIST_HEAD (&empty);
+       INIT_LIST_HEAD(&empty);
        qh = qh_append_tds(ehci, urb, &empty, epnum, &urb->ep->hcpriv);
        if (qh == NULL) {
                status = -ENOMEM;
                goto done;
        }
        if (qh->qh_state == QH_STATE_IDLE) {
-               if ((status = qh_schedule (ehci, qh)) != 0)
+               status = qh_schedule(ehci, qh);
+               if (status)
                        goto done;
        }
 
        /* then queue the urb's tds to the qh */
        qh = qh_append_tds(ehci, urb, qtd_list, epnum, &urb->ep->hcpriv);
-       BUG_ON (qh == NULL);
+       BUG_ON(qh == NULL);
 
        /* stuff into the periodic schedule */
        if (qh->qh_state == QH_STATE_IDLE) {
@@ -982,9 +984,9 @@ done:
        if (unlikely(status))
                usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
 done_not_linked:
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
        if (status)
-               qtd_list_free (ehci, urb, qtd_list);
+               qtd_list_free(ehci, urb, qtd_list);
 
        return status;
 }
@@ -1022,12 +1024,12 @@ static void scan_intr(struct ehci_hcd *ehci)
 /* ehci_iso_stream ops work with both ITD and SITD */
 
 static struct ehci_iso_stream *
-iso_stream_alloc (gfp_t mem_flags)
+iso_stream_alloc(gfp_t mem_flags)
 {
        struct ehci_iso_stream *stream;
 
-       stream = kzalloc(sizeof *stream, mem_flags);
-       if (likely (stream != NULL)) {
+       stream = kzalloc(sizeof(*stream), mem_flags);
+       if (likely(stream != NULL)) {
                INIT_LIST_HEAD(&stream->td_list);
                INIT_LIST_HEAD(&stream->free_list);
                stream->next_uframe = NO_FRAME;
@@ -1037,13 +1039,13 @@ iso_stream_alloc (gfp_t mem_flags)
 }
 
 static void
-iso_stream_init (
+iso_stream_init(
        struct ehci_hcd         *ehci,
        struct ehci_iso_stream  *stream,
        struct urb              *urb
 )
 {
-       static const u8 smask_out [] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f };
+       static const u8 smask_out[] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f };
 
        struct usb_device       *dev = urb->dev;
        u32                     buf1;
@@ -1058,11 +1060,7 @@ iso_stream_init (
        epnum = usb_pipeendpoint(urb->pipe);
        is_input = usb_pipein(urb->pipe) ? USB_DIR_IN : 0;
        maxp = usb_endpoint_maxp(&urb->ep->desc);
-       if (is_input) {
-               buf1 = (1 << 11);
-       } else {
-               buf1 = 0;
-       }
+       buf1 = is_input ? 1 << 11 : 0;
 
        /* knows about ITD vs SITD */
        if (dev->speed == USB_SPEED_HIGH) {
@@ -1111,7 +1109,7 @@ iso_stream_init (
                think_time = dev->tt ? dev->tt->think_time : 0;
                stream->ps.tt_usecs = NS_TO_US(think_time + usb_calc_bus_time(
                                dev->speed, is_input, 1, maxp));
-               hs_transfers = max (1u, (maxp + 187) / 188);
+               hs_transfers = max(1u, (maxp + 187) / 188);
                if (is_input) {
                        u32     tmp;
 
@@ -1151,7 +1149,7 @@ iso_stream_init (
 }
 
 static struct ehci_iso_stream *
-iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
+iso_stream_find(struct ehci_hcd *ehci, struct urb *urb)
 {
        unsigned                epnum;
        struct ehci_iso_stream  *stream;
@@ -1164,25 +1162,25 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
        else
                ep = urb->dev->ep_out[epnum];
 
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
        stream = ep->hcpriv;
 
-       if (unlikely (stream == NULL)) {
+       if (unlikely(stream == NULL)) {
                stream = iso_stream_alloc(GFP_ATOMIC);
-               if (likely (stream != NULL)) {
+               if (likely(stream != NULL)) {
                        ep->hcpriv = stream;
                        iso_stream_init(ehci, stream, urb);
                }
 
        /* if dev->ep [epnum] is a QH, hw is set */
-       } else if (unlikely (stream->hw != NULL)) {
-               ehci_dbg (ehci, "dev %s ep%d%s, not iso??\n",
+       } else if (unlikely(stream->hw != NULL)) {
+               ehci_dbg(ehci, "dev %s ep%d%s, not iso??\n",
                        urb->dev->devpath, epnum,
                        usb_pipein(urb->pipe) ? "in" : "out");
                stream = NULL;
        }
 
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
        return stream;
 }
 
@@ -1191,16 +1189,16 @@ iso_stream_find (struct ehci_hcd *ehci, struct urb *urb)
 /* ehci_iso_sched ops can be ITD-only or SITD-only */
 
 static struct ehci_iso_sched *
-iso_sched_alloc (unsigned packets, gfp_t mem_flags)
+iso_sched_alloc(unsigned packets, gfp_t mem_flags)
 {
        struct ehci_iso_sched   *iso_sched;
-       int                     size = sizeof *iso_sched;
+       int                     size = sizeof(*iso_sched);
 
-       size += packets * sizeof (struct ehci_iso_packet);
+       size += packets * sizeof(struct ehci_iso_packet);
        iso_sched = kzalloc(size, mem_flags);
-       if (likely (iso_sched != NULL)) {
-               INIT_LIST_HEAD (&iso_sched->td_list);
-       }
+       if (likely(iso_sched != NULL))
+               INIT_LIST_HEAD(&iso_sched->td_list);
+
        return iso_sched;
 }
 
@@ -1222,17 +1220,17 @@ itd_sched_init(
         * when we fit new itds into the schedule.
         */
        for (i = 0; i < urb->number_of_packets; i++) {
-               struct ehci_iso_packet  *uframe = &iso_sched->packet [i];
+               struct ehci_iso_packet  *uframe = &iso_sched->packet[i];
                unsigned                length;
                dma_addr_t              buf;
                u32                     trans;
 
-               length = urb->iso_frame_desc [i].length;
-               buf = dma + urb->iso_frame_desc [i].offset;
+               length = urb->iso_frame_desc[i].length;
+               buf = dma + urb->iso_frame_desc[i].offset;
 
                trans = EHCI_ISOC_ACTIVE;
                trans |= buf & 0x0fff;
-               if (unlikely (((i + 1) == urb->number_of_packets))
+               if (unlikely(((i + 1) == urb->number_of_packets))
                                && !(urb->transfer_flags & URB_NO_INTERRUPT))
                        trans |= EHCI_ITD_IOC;
                trans |= length << 16;
@@ -1241,26 +1239,26 @@ itd_sched_init(
                /* might need to cross a buffer page within a uframe */
                uframe->bufp = (buf & ~(u64)0x0fff);
                buf += length;
-               if (unlikely ((uframe->bufp != (buf & ~(u64)0x0fff))))
+               if (unlikely((uframe->bufp != (buf & ~(u64)0x0fff))))
                        uframe->cross = 1;
        }
 }
 
 static void
-iso_sched_free (
+iso_sched_free(
        struct ehci_iso_stream  *stream,
        struct ehci_iso_sched   *iso_sched
 )
 {
        if (!iso_sched)
                return;
-       // caller must hold ehci->lock!
-       list_splice (&iso_sched->td_list, &stream->free_list);
-       kfree (iso_sched);
+       /* caller must hold ehci->lock! */
+       list_splice(&iso_sched->td_list, &stream->free_list);
+       kfree(iso_sched);
 }
 
 static int
-itd_urb_transaction (
+itd_urb_transaction(
        struct ehci_iso_stream  *stream,
        struct ehci_hcd         *ehci,
        struct urb              *urb,
@@ -1274,8 +1272,8 @@ itd_urb_transaction (
        struct ehci_iso_sched   *sched;
        unsigned long           flags;
 
-       sched = iso_sched_alloc (urb->number_of_packets, mem_flags);
-       if (unlikely (sched == NULL))
+       sched = iso_sched_alloc(urb->number_of_packets, mem_flags);
+       if (unlikely(sched == NULL))
                return -ENOMEM;
 
        itd_sched_init(ehci, sched, stream, urb);
@@ -1286,7 +1284,7 @@ itd_urb_transaction (
                num_itds = urb->number_of_packets;
 
        /* allocate/init ITDs */
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
        for (i = 0; i < num_itds; i++) {
 
                /*
@@ -1298,14 +1296,14 @@ itd_urb_transaction (
                                        struct ehci_itd, itd_list);
                        if (itd->frame == ehci->now_frame)
                                goto alloc_itd;
-                       list_del (&itd->itd_list);
+                       list_del(&itd->itd_list);
                        itd_dma = itd->itd_dma;
                } else {
  alloc_itd:
-                       spin_unlock_irqrestore (&ehci->lock, flags);
-                       itd = dma_pool_alloc (ehci->itd_pool, mem_flags,
+                       spin_unlock_irqrestore(&ehci->lock, flags);
+                       itd = dma_pool_alloc(ehci->itd_pool, mem_flags,
                                        &itd_dma);
-                       spin_lock_irqsave (&ehci->lock, flags);
+                       spin_lock_irqsave(&ehci->lock, flags);
                        if (!itd) {
                                iso_sched_free(stream, sched);
                                spin_unlock_irqrestore(&ehci->lock, flags);
@@ -1313,12 +1311,12 @@ itd_urb_transaction (
                        }
                }
 
-               memset (itd, 0, sizeof *itd);
+               memset(itd, 0, sizeof(*itd));
                itd->itd_dma = itd_dma;
                itd->frame = NO_FRAME;
-               list_add (&itd->itd_list, &sched->td_list);
+               list_add(&itd->itd_list, &sched->td_list);
        }
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
 
        /* temporarily store schedule info in hcpriv */
        urb->hcpriv = sched;
@@ -1385,7 +1383,7 @@ static void reserve_release_iso_bandwidth(struct ehci_hcd *ehci,
 }
 
 static inline int
-itd_slot_ok (
+itd_slot_ok(
        struct ehci_hcd         *ehci,
        struct ehci_iso_stream  *stream,
        unsigned                uframe
@@ -1405,7 +1403,7 @@ itd_slot_ok (
 }
 
 static inline int
-sitd_slot_ok (
+sitd_slot_ok(
        struct ehci_hcd         *ehci,
        struct ehci_iso_stream  *stream,
        unsigned                uframe,
@@ -1492,7 +1490,7 @@ sitd_slot_ok (
  */
 
 static int
-iso_stream_schedule (
+iso_stream_schedule(
        struct ehci_hcd         *ehci,
        struct urb              *urb,
        struct ehci_iso_stream  *stream
@@ -1693,9 +1691,9 @@ itd_init(struct ehci_hcd *ehci, struct ehci_iso_stream *stream,
 
        /* it's been recently zeroed */
        itd->hw_next = EHCI_LIST_END(ehci);
-       itd->hw_bufp [0] = stream->buf0;
-       itd->hw_bufp [1] = stream->buf1;
-       itd->hw_bufp [2] = stream->buf2;
+       itd->hw_bufp[0] = stream->buf0;
+       itd->hw_bufp[1] = stream->buf1;
+       itd->hw_bufp[2] = stream->buf2;
 
        for (i = 0; i < 8; i++)
                itd->index[i] = -1;
@@ -1712,13 +1710,13 @@ itd_patch(
        u16                     uframe
 )
 {
-       struct ehci_iso_packet  *uf = &iso_sched->packet [index];
+       struct ehci_iso_packet  *uf = &iso_sched->packet[index];
        unsigned                pg = itd->pg;
 
-       // BUG_ON (pg == 6 && uf->cross);
+       /* BUG_ON(pg == 6 && uf->cross); */
 
        uframe &= 0x07;
-       itd->index [uframe] = index;
+       itd->index[uframe] = index;
 
        itd->hw_transaction[uframe] = uf->transaction;
        itd->hw_transaction[uframe] |= cpu_to_hc32(ehci, pg << 12);
@@ -1726,7 +1724,7 @@ itd_patch(
        itd->hw_bufp_hi[pg] |= cpu_to_hc32(ehci, (u32)(uf->bufp >> 32));
 
        /* iso_frame_desc[].offset must be strictly increasing */
-       if (unlikely (uf->cross)) {
+       if (unlikely(uf->cross)) {
                u64     bufp = uf->bufp + 4096;
 
                itd->pg = ++pg;
@@ -1736,7 +1734,7 @@ itd_patch(
 }
 
 static inline void
-itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
+itd_link(struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
 {
        union ehci_shadow       *prev = &ehci->pshadow[frame];
        __hc32                  *hw_p = &ehci->periodic[frame];
@@ -1757,7 +1755,7 @@ itd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_itd *itd)
        itd->hw_next = *hw_p;
        prev->itd = itd;
        itd->frame = frame;
-       wmb ();
+       wmb();
        *hw_p = cpu_to_hc32(ehci, itd->itd_dma | Q_TYPE_ITD);
 }
 
@@ -1776,7 +1774,7 @@ static void itd_link_urb(
 
        next_uframe = stream->next_uframe & (mod - 1);
 
-       if (unlikely (list_empty(&stream->td_list)))
+       if (unlikely(list_empty(&stream->td_list)))
                ehci_to_hcd(ehci)->self.bandwidth_allocated
                                += stream->bandwidth;
 
@@ -1792,16 +1790,16 @@ static void itd_link_urb(
                        packet < urb->number_of_packets;) {
                if (itd == NULL) {
                        /* ASSERT:  we have all necessary itds */
-                       // BUG_ON (list_empty (&iso_sched->td_list));
+                       /* BUG_ON(list_empty(&iso_sched->td_list)); */
 
                        /* ASSERT:  no itds for this endpoint in this uframe */
 
-                       itd = list_entry (iso_sched->td_list.next,
+                       itd = list_entry(iso_sched->td_list.next,
                                        struct ehci_itd, itd_list);
-                       list_move_tail (&itd->itd_list, &stream->td_list);
+                       list_move_tail(&itd->itd_list, &stream->td_list);
                        itd->stream = stream;
                        itd->urb = urb;
-                       itd_init (ehci, stream, itd);
+                       itd_init(ehci, stream, itd);
                }
 
                uframe = next_uframe & 0x07;
@@ -1823,7 +1821,7 @@ static void itd_link_urb(
        stream->next_uframe = next_uframe;
 
        /* don't need that schedule data any more */
-       iso_sched_free (stream, iso_sched);
+       iso_sched_free(stream, iso_sched);
        urb->hcpriv = stream;
 
        ++ehci->isoc_count;
@@ -1855,19 +1853,19 @@ static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)
 
        /* for each uframe with a packet */
        for (uframe = 0; uframe < 8; uframe++) {
-               if (likely (itd->index[uframe] == -1))
+               if (likely(itd->index[uframe] == -1))
                        continue;
                urb_index = itd->index[uframe];
-               desc = &urb->iso_frame_desc [urb_index];
+               desc = &urb->iso_frame_desc[urb_index];
 
-               t = hc32_to_cpup(ehci, &itd->hw_transaction [uframe]);
-               itd->hw_transaction [uframe] = 0;
+               t = hc32_to_cpup(ehci, &itd->hw_transaction[uframe]);
+               itd->hw_transaction[uframe] = 0;
 
                /* report transfer status */
-               if (unlikely (t & ISO_ERRS)) {
+               if (unlikely(t & ISO_ERRS)) {
                        urb->error_count++;
                        if (t & EHCI_ISOC_BUF_ERR)
-                               desc->status = usb_pipein (urb->pipe)
+                               desc->status = usb_pipein(urb->pipe)
                                        ? -ENOSR  /* hc couldn't read */
                                        : -ECOMM; /* hc couldn't write */
                        else if (t & EHCI_ISOC_BABBLE)
@@ -1880,7 +1878,7 @@ static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)
                                desc->actual_length = EHCI_ITD_LENGTH(t);
                                urb->actual_length += desc->actual_length;
                        }
-               } else if (likely ((t & EHCI_ISOC_ACTIVE) == 0)) {
+               } else if (likely((t & EHCI_ISOC_ACTIVE) == 0)) {
                        desc->status = 0;
                        desc->actual_length = EHCI_ITD_LENGTH(t);
                        urb->actual_length += desc->actual_length;
@@ -1891,12 +1889,13 @@ static bool itd_complete(struct ehci_hcd *ehci, struct ehci_itd *itd)
        }
 
        /* handle completion now? */
-       if (likely ((urb_index + 1) != urb->number_of_packets))
+       if (likely((urb_index + 1) != urb->number_of_packets))
                goto done;
 
-       /* ASSERT: it's really the last itd for this urb
-       list_for_each_entry (itd, &stream->td_list, itd_list)
-               BUG_ON (itd->urb == urb);
+       /*
+        * ASSERT: it's really the last itd for this urb
+        * list_for_each_entry (itd, &stream->td_list, itd_list)
+        *       BUG_ON(itd->urb == urb);
         */
 
        /* give urb back to the driver; completion often (re)submits */
@@ -1936,7 +1935,7 @@ done:
 
 /*-------------------------------------------------------------------------*/
 
-static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
+static int itd_submit(struct ehci_hcd *ehci, struct urb *urb,
        gfp_t mem_flags)
 {
        int                     status = -EINVAL;
@@ -1944,37 +1943,37 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
        struct ehci_iso_stream  *stream;
 
        /* Get iso_stream head */
-       stream = iso_stream_find (ehci, urb);
-       if (unlikely (stream == NULL)) {
-               ehci_dbg (ehci, "can't get iso stream\n");
+       stream = iso_stream_find(ehci, urb);
+       if (unlikely(stream == NULL)) {
+               ehci_dbg(ehci, "can't get iso stream\n");
                return -ENOMEM;
        }
        if (unlikely(urb->interval != stream->uperiod)) {
-               ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
+               ehci_dbg(ehci, "can't change iso interval %d --> %d\n",
                        stream->uperiod, urb->interval);
                goto done;
        }
 
 #ifdef EHCI_URB_TRACE
-       ehci_dbg (ehci,
+       ehci_dbg(ehci,
                "%s %s urb %p ep%d%s len %d, %d pkts %d uframes [%p]\n",
                __func__, urb->dev->devpath, urb,
-               usb_pipeendpoint (urb->pipe),
-               usb_pipein (urb->pipe) ? "in" : "out",
+               usb_pipeendpoint(urb->pipe),
+               usb_pipein(urb->pipe) ? "in" : "out",
                urb->transfer_buffer_length,
                urb->number_of_packets, urb->interval,
                stream);
 #endif
 
        /* allocate ITDs w/o locking anything */
-       status = itd_urb_transaction (stream, ehci, urb, mem_flags);
-       if (unlikely (status < 0)) {
-               ehci_dbg (ehci, "can't init itds\n");
+       status = itd_urb_transaction(stream, ehci, urb, mem_flags);
+       if (unlikely(status < 0)) {
+               ehci_dbg(ehci, "can't init itds\n");
                goto done;
        }
 
        /* schedule ... need to lock */
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
        if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
                status = -ESHUTDOWN;
                goto done_not_linked;
@@ -1984,7 +1983,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
                goto done_not_linked;
        status = iso_stream_schedule(ehci, urb, stream);
        if (likely(status == 0)) {
-               itd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
+               itd_link_urb(ehci, urb, ehci->periodic_size << 3, stream);
        } else if (status > 0) {
                status = 0;
                ehci_urb_done(ehci, urb, 0);
@@ -1992,7 +1991,7 @@ static int itd_submit (struct ehci_hcd *ehci, struct urb *urb,
                usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
        }
  done_not_linked:
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
  done:
        return status;
 }
@@ -2022,13 +2021,13 @@ sitd_sched_init(
         * when we fit new sitds into the schedule.
         */
        for (i = 0; i < urb->number_of_packets; i++) {
-               struct ehci_iso_packet  *packet = &iso_sched->packet [i];
+               struct ehci_iso_packet  *packet = &iso_sched->packet[i];
                unsigned                length;
                dma_addr_t              buf;
                u32                     trans;
 
-               length = urb->iso_frame_desc [i].length & 0x03ff;
-               buf = dma + urb->iso_frame_desc [i].offset;
+               length = urb->iso_frame_desc[i].length & 0x03ff;
+               buf = dma + urb->iso_frame_desc[i].offset;
 
                trans = SITD_STS_ACTIVE;
                if (((i + 1) == urb->number_of_packets)
@@ -2054,7 +2053,7 @@ sitd_sched_init(
 }
 
 static int
-sitd_urb_transaction (
+sitd_urb_transaction(
        struct ehci_iso_stream  *stream,
        struct ehci_hcd         *ehci,
        struct urb              *urb,
@@ -2067,14 +2066,14 @@ sitd_urb_transaction (
        struct ehci_iso_sched   *iso_sched;
        unsigned long           flags;
 
-       iso_sched = iso_sched_alloc (urb->number_of_packets, mem_flags);
+       iso_sched = iso_sched_alloc(urb->number_of_packets, mem_flags);
        if (iso_sched == NULL)
                return -ENOMEM;
 
        sitd_sched_init(ehci, iso_sched, stream, urb);
 
        /* allocate/init sITDs */
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
        for (i = 0; i < urb->number_of_packets; i++) {
 
                /* NOTE:  for now, we don't try to handle wraparound cases
@@ -2091,14 +2090,14 @@ sitd_urb_transaction (
                                         struct ehci_sitd, sitd_list);
                        if (sitd->frame == ehci->now_frame)
                                goto alloc_sitd;
-                       list_del (&sitd->sitd_list);
+                       list_del(&sitd->sitd_list);
                        sitd_dma = sitd->sitd_dma;
                } else {
  alloc_sitd:
-                       spin_unlock_irqrestore (&ehci->lock, flags);
-                       sitd = dma_pool_alloc (ehci->sitd_pool, mem_flags,
+                       spin_unlock_irqrestore(&ehci->lock, flags);
+                       sitd = dma_pool_alloc(ehci->sitd_pool, mem_flags,
                                        &sitd_dma);
-                       spin_lock_irqsave (&ehci->lock, flags);
+                       spin_lock_irqsave(&ehci->lock, flags);
                        if (!sitd) {
                                iso_sched_free(stream, iso_sched);
                                spin_unlock_irqrestore(&ehci->lock, flags);
@@ -2106,17 +2105,17 @@ sitd_urb_transaction (
                        }
                }
 
-               memset (sitd, 0, sizeof *sitd);
+               memset(sitd, 0, sizeof(*sitd));
                sitd->sitd_dma = sitd_dma;
                sitd->frame = NO_FRAME;
-               list_add (&sitd->sitd_list, &iso_sched->td_list);
+               list_add(&sitd->sitd_list, &iso_sched->td_list);
        }
 
        /* temporarily store schedule info in hcpriv */
        urb->hcpriv = iso_sched;
        urb->error_count = 0;
 
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
        return 0;
 }
 
@@ -2131,8 +2130,8 @@ sitd_patch(
        unsigned                index
 )
 {
-       struct ehci_iso_packet  *uf = &iso_sched->packet [index];
-       u64                     bufp = uf->bufp;
+       struct ehci_iso_packet  *uf = &iso_sched->packet[index];
+       u64                     bufp;
 
        sitd->hw_next = EHCI_LIST_END(ehci);
        sitd->hw_fullspeed_ep = stream->address;
@@ -2152,14 +2151,14 @@ sitd_patch(
 }
 
 static inline void
-sitd_link (struct ehci_hcd *ehci, unsigned frame, struct ehci_sitd *sitd)
+sitd_link(struct ehci_hcd *ehci, unsigned frame, struct ehci_sitd *sitd)
 {
        /* note: sitd ordering could matter (CSPLIT then SSPLIT) */
-       sitd->sitd_next = ehci->pshadow [frame];
-       sitd->hw_next = ehci->periodic [frame];
-       ehci->pshadow [frame].sitd = sitd;
+       sitd->sitd_next = ehci->pshadow[frame];
+       sitd->hw_next = ehci->periodic[frame];
+       ehci->pshadow[frame].sitd = sitd;
        sitd->frame = frame;
-       wmb ();
+       wmb();
        ehci->periodic[frame] = cpu_to_hc32(ehci, sitd->sitd_dma | Q_TYPE_SITD);
 }
 
@@ -2196,13 +2195,13 @@ static void sitd_link_urb(
                        packet++) {
 
                /* ASSERT:  we have all necessary sitds */
-               BUG_ON (list_empty (&sched->td_list));
+               BUG_ON(list_empty(&sched->td_list));
 
                /* ASSERT:  no itds for this endpoint in this frame */
 
-               sitd = list_entry (sched->td_list.next,
+               sitd = list_entry(sched->td_list.next,
                                struct ehci_sitd, sitd_list);
-               list_move_tail (&sitd->sitd_list, &stream->td_list);
+               list_move_tail(&sitd->sitd_list, &stream->td_list);
                sitd->stream = stream;
                sitd->urb = urb;
 
@@ -2215,7 +2214,7 @@ static void sitd_link_urb(
        stream->next_uframe = next_uframe & (mod - 1);
 
        /* don't need that schedule data any more */
-       iso_sched_free (stream, sched);
+       iso_sched_free(stream, sched);
        urb->hcpriv = stream;
 
        ++ehci->isoc_count;
@@ -2242,20 +2241,20 @@ static bool sitd_complete(struct ehci_hcd *ehci, struct ehci_sitd *sitd)
        struct urb                              *urb = sitd->urb;
        struct usb_iso_packet_descriptor        *desc;
        u32                                     t;
-       int                                     urb_index = -1;
+       int                                     urb_index;
        struct ehci_iso_stream                  *stream = sitd->stream;
        struct usb_device                       *dev;
        bool                                    retval = false;
 
        urb_index = sitd->index;
-       desc = &urb->iso_frame_desc [urb_index];
+       desc = &urb->iso_frame_desc[urb_index];
        t = hc32_to_cpup(ehci, &sitd->hw_results);
 
        /* report transfer status */
        if (unlikely(t & SITD_ERRS)) {
                urb->error_count++;
                if (t & SITD_STS_DBE)
-                       desc->status = usb_pipein (urb->pipe)
+                       desc->status = usb_pipein(urb->pipe)
                                ? -ENOSR  /* hc couldn't read */
                                : -ECOMM; /* hc couldn't write */
                else if (t & SITD_STS_BABBLE)
@@ -2275,9 +2274,10 @@ static bool sitd_complete(struct ehci_hcd *ehci, struct ehci_sitd *sitd)
        if ((urb_index + 1) != urb->number_of_packets)
                goto done;
 
-       /* ASSERT: it's really the last sitd for this urb
-       list_for_each_entry (sitd, &stream->td_list, sitd_list)
-               BUG_ON (sitd->urb == urb);
+       /*
+        * ASSERT: it's really the last sitd for this urb
+        * list_for_each_entry (sitd, &stream->td_list, sitd_list)
+        *       BUG_ON(sitd->urb == urb);
         */
 
        /* give urb back to the driver; completion often (re)submits */
@@ -2316,7 +2316,7 @@ done:
 }
 
 
-static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
+static int sitd_submit(struct ehci_hcd *ehci, struct urb *urb,
        gfp_t mem_flags)
 {
        int                     status = -EINVAL;
@@ -2324,35 +2324,35 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
        struct ehci_iso_stream  *stream;
 
        /* Get iso_stream head */
-       stream = iso_stream_find (ehci, urb);
+       stream = iso_stream_find(ehci, urb);
        if (stream == NULL) {
-               ehci_dbg (ehci, "can't get iso stream\n");
+               ehci_dbg(ehci, "can't get iso stream\n");
                return -ENOMEM;
        }
        if (urb->interval != stream->ps.period) {
-               ehci_dbg (ehci, "can't change iso interval %d --> %d\n",
+               ehci_dbg(ehci, "can't change iso interval %d --> %d\n",
                        stream->ps.period, urb->interval);
                goto done;
        }
 
 #ifdef EHCI_URB_TRACE
-       ehci_dbg (ehci,
+       ehci_dbg(ehci,
                "submit %p dev%s ep%d%s-iso len %d\n",
                urb, urb->dev->devpath,
-               usb_pipeendpoint (urb->pipe),
-               usb_pipein (urb->pipe) ? "in" : "out",
+               usb_pipeendpoint(urb->pipe),
+               usb_pipein(urb->pipe) ? "in" : "out",
                urb->transfer_buffer_length);
 #endif
 
        /* allocate SITDs */
-       status = sitd_urb_transaction (stream, ehci, urb, mem_flags);
+       status = sitd_urb_transaction(stream, ehci, urb, mem_flags);
        if (status < 0) {
-               ehci_dbg (ehci, "can't init sitds\n");
+               ehci_dbg(ehci, "can't init sitds\n");
                goto done;
        }
 
        /* schedule ... need to lock */
-       spin_lock_irqsave (&ehci->lock, flags);
+       spin_lock_irqsave(&ehci->lock, flags);
        if (unlikely(!HCD_HW_ACCESSIBLE(ehci_to_hcd(ehci)))) {
                status = -ESHUTDOWN;
                goto done_not_linked;
@@ -2362,7 +2362,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
                goto done_not_linked;
        status = iso_stream_schedule(ehci, urb, stream);
        if (likely(status == 0)) {
-               sitd_link_urb (ehci, urb, ehci->periodic_size << 3, stream);
+               sitd_link_urb(ehci, urb, ehci->periodic_size << 3, stream);
        } else if (status > 0) {
                status = 0;
                ehci_urb_done(ehci, urb, 0);
@@ -2370,7 +2370,7 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
                usb_hcd_unlink_urb_from_ep(ehci_to_hcd(ehci), urb);
        }
  done_not_linked:
-       spin_unlock_irqrestore (&ehci->lock, flags);
+       spin_unlock_irqrestore(&ehci->lock, flags);
  done:
        return status;
 }
@@ -2379,9 +2379,11 @@ static int sitd_submit (struct ehci_hcd *ehci, struct urb *urb,
 
 static void scan_isoc(struct ehci_hcd *ehci)
 {
-       unsigned        uf, now_frame, frame;
-       unsigned        fmask = ehci->periodic_size - 1;
-       bool            modified, live;
+       unsigned                uf, now_frame, frame;
+       unsigned                fmask = ehci->periodic_size - 1;
+       bool                    modified, live;
+       union ehci_shadow       q, *q_p;
+       __hc32                  type, *hw_p;
 
        /*
         * When running, scan from last scan point up to "now"
@@ -2399,119 +2401,117 @@ static void scan_isoc(struct ehci_hcd *ehci)
        ehci->now_frame = now_frame;
 
        frame = ehci->last_iso_frame;
-       for (;;) {
-               union ehci_shadow       q, *q_p;
-               __hc32                  type, *hw_p;
 
 restart:
-               /* scan each element in frame's queue for completions */
-               q_p = &ehci->pshadow [frame];
-               hw_p = &ehci->periodic [frame];
-               q.ptr = q_p->ptr;
-               type = Q_NEXT_TYPE(ehci, *hw_p);
-               modified = false;
-
-               while (q.ptr != NULL) {
-                       switch (hc32_to_cpu(ehci, type)) {
-                       case Q_TYPE_ITD:
-                               /* If this ITD is still active, leave it for
-                                * later processing ... check the next entry.
-                                * No need to check for activity unless the
-                                * frame is current.
-                                */
-                               if (frame == now_frame && live) {
-                                       rmb();
-                                       for (uf = 0; uf < 8; uf++) {
-                                               if (q.itd->hw_transaction[uf] &
-                                                           ITD_ACTIVE(ehci))
-                                                       break;
-                                       }
-                                       if (uf < 8) {
-                                               q_p = &q.itd->itd_next;
-                                               hw_p = &q.itd->hw_next;
-                                               type = Q_NEXT_TYPE(ehci,
-                                                       q.itd->hw_next);
-                                               q = *q_p;
+       /* Scan each element in frame's queue for completions */
+       q_p = &ehci->pshadow[frame];
+       hw_p = &ehci->periodic[frame];
+       q.ptr = q_p->ptr;
+       type = Q_NEXT_TYPE(ehci, *hw_p);
+       modified = false;
+
+       while (q.ptr != NULL) {
+               switch (hc32_to_cpu(ehci, type)) {
+               case Q_TYPE_ITD:
+                       /*
+                        * If this ITD is still active, leave it for
+                        * later processing ... check the next entry.
+                        * No need to check for activity unless the
+                        * frame is current.
+                        */
+                       if (frame == now_frame && live) {
+                               rmb();
+                               for (uf = 0; uf < 8; uf++) {
+                                       if (q.itd->hw_transaction[uf] &
+                                                       ITD_ACTIVE(ehci))
                                                break;
-                                       }
                                }
-
-                               /* Take finished ITDs out of the schedule
-                                * and process them:  recycle, maybe report
-                                * URB completion.  HC won't cache the
-                                * pointer for much longer, if at all.
-                                */
-                               *q_p = q.itd->itd_next;
-                               if (!ehci->use_dummy_qh ||
-                                   q.itd->hw_next != EHCI_LIST_END(ehci))
-                                       *hw_p = q.itd->hw_next;
-                               else
-                                       *hw_p = cpu_to_hc32(ehci,
-                                                       ehci->dummy->qh_dma);
-                               type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
-                               wmb();
-                               modified = itd_complete (ehci, q.itd);
-                               q = *q_p;
-                               break;
-                       case Q_TYPE_SITD:
-                               /* If this SITD is still active, leave it for
-                                * later processing ... check the next entry.
-                                * No need to check for activity unless the
-                                * frame is current.
-                                */
-                               if (((frame == now_frame) ||
-                                    (((frame + 1) & fmask) == now_frame))
-                                   && live
-                                   && (q.sitd->hw_results &
-                                       SITD_ACTIVE(ehci))) {
-
-                                       q_p = &q.sitd->sitd_next;
-                                       hw_p = &q.sitd->hw_next;
+                               if (uf < 8) {
+                                       q_p = &q.itd->itd_next;
+                                       hw_p = &q.itd->hw_next;
                                        type = Q_NEXT_TYPE(ehci,
-                                                       q.sitd->hw_next);
+                                                       q.itd->hw_next);
                                        q = *q_p;
                                        break;
                                }
+                       }
+
+                       /*
+                        * Take finished ITDs out of the schedule
+                        * and process them:  recycle, maybe report
+                        * URB completion.  HC won't cache the
+                        * pointer for much longer, if at all.
+                        */
+                       *q_p = q.itd->itd_next;
+                       if (!ehci->use_dummy_qh ||
+                                       q.itd->hw_next != EHCI_LIST_END(ehci))
+                               *hw_p = q.itd->hw_next;
+                       else
+                               *hw_p = cpu_to_hc32(ehci, ehci->dummy->qh_dma);
+                       type = Q_NEXT_TYPE(ehci, q.itd->hw_next);
+                       wmb();
+                       modified = itd_complete(ehci, q.itd);
+                       q = *q_p;
+                       break;
+               case Q_TYPE_SITD:
+                       /*
+                        * If this SITD is still active, leave it for
+                        * later processing ... check the next entry.
+                        * No need to check for activity unless the
+                        * frame is current.
+                        */
+                       if (((frame == now_frame) ||
+                                       (((frame + 1) & fmask) == now_frame))
+                               && live
+                               && (q.sitd->hw_results & SITD_ACTIVE(ehci))) {
 
-                               /* Take finished SITDs out of the schedule
-                                * and process them:  recycle, maybe report
-                                * URB completion.
-                                */
-                               *q_p = q.sitd->sitd_next;
-                               if (!ehci->use_dummy_qh ||
-                                   q.sitd->hw_next != EHCI_LIST_END(ehci))
-                                       *hw_p = q.sitd->hw_next;
-                               else
-                                       *hw_p = cpu_to_hc32(ehci,
-                                                       ehci->dummy->qh_dma);
+                               q_p = &q.sitd->sitd_next;
+                               hw_p = &q.sitd->hw_next;
                                type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
-                               wmb();
-                               modified = sitd_complete (ehci, q.sitd);
                                q = *q_p;
                                break;
-                       default:
-                               ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
-                                       type, frame, q.ptr);
-                               // BUG ();
-                               /* FALL THROUGH */
-                       case Q_TYPE_QH:
-                       case Q_TYPE_FSTN:
-                               /* End of the iTDs and siTDs */
-                               q.ptr = NULL;
-                               break;
                        }
 
-                       /* assume completion callbacks modify the queue */
-                       if (unlikely(modified && ehci->isoc_count > 0))
-                               goto restart;
-               }
-
-               /* Stop when we have reached the current frame */
-               if (frame == now_frame)
+                       /*
+                        * Take finished SITDs out of the schedule
+                        * and process them:  recycle, maybe report
+                        * URB completion.
+                        */
+                       *q_p = q.sitd->sitd_next;
+                       if (!ehci->use_dummy_qh ||
+                                       q.sitd->hw_next != EHCI_LIST_END(ehci))
+                               *hw_p = q.sitd->hw_next;
+                       else
+                               *hw_p = cpu_to_hc32(ehci, ehci->dummy->qh_dma);
+                       type = Q_NEXT_TYPE(ehci, q.sitd->hw_next);
+                       wmb();
+                       modified = sitd_complete(ehci, q.sitd);
+                       q = *q_p;
+                       break;
+               default:
+                       ehci_dbg(ehci, "corrupt type %d frame %d shadow %p\n",
+                                       type, frame, q.ptr);
+                       /* BUG(); */
+                       /* FALL THROUGH */
+               case Q_TYPE_QH:
+               case Q_TYPE_FSTN:
+                       /* End of the iTDs and siTDs */
+                       q.ptr = NULL;
                        break;
+               }
 
-               /* The last frame may still have active siTDs */
-               ehci->last_iso_frame = frame;
-               frame = (frame + 1) & fmask;
+               /* Assume completion callbacks modify the queue */
+               if (unlikely(modified && ehci->isoc_count > 0))
+                       goto restart;
        }
+
+       /* Stop when we have reached the current frame */
+       if (frame == now_frame)
+               return;
+
+       /* The last frame may still have active siTDs */
+       ehci->last_iso_frame = frame;
+       frame = (frame + 1) & fmask;
+
+       goto restart;
 }
index b7c5cfa..a94ed67 100644 (file)
@@ -287,8 +287,7 @@ static int st_ehci_suspend(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
        bool do_wakeup = device_may_wakeup(dev);
        int ret;
 
@@ -308,8 +307,7 @@ static int st_ehci_resume(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
        int err;
 
        pinctrl_pm_select_default_state(dev);
index 424ac5d..69f50e6 100644 (file)
@@ -72,6 +72,7 @@ static unsigned event_delays_ns[] = {
        1 * NSEC_PER_MSEC,      /* EHCI_HRTIMER_POLL_DEAD */
        1125 * NSEC_PER_USEC,   /* EHCI_HRTIMER_UNLINK_INTR */
        2 * NSEC_PER_MSEC,      /* EHCI_HRTIMER_FREE_ITDS */
+       2 * NSEC_PER_MSEC,      /* EHCI_HRTIMER_ACTIVE_UNLINK */
        5 * NSEC_PER_MSEC,      /* EHCI_HRTIMER_START_UNLINK_INTR */
        6 * NSEC_PER_MSEC,      /* EHCI_HRTIMER_ASYNC_UNLINKS */
        10 * NSEC_PER_MSEC,     /* EHCI_HRTIMER_IAA_WATCHDOG */
@@ -237,6 +238,7 @@ static void ehci_handle_start_intr_unlinks(struct ehci_hcd *ehci)
                                ehci->intr_unlink_wait_cycle))
                        break;
                list_del_init(&qh->unlink_node);
+               qh->unlink_reason |= QH_UNLINK_QUEUE_EMPTY;
                start_unlink_intr(ehci, qh);
        }
 
@@ -360,7 +362,7 @@ static void ehci_iaa_watchdog(struct ehci_hcd *ehci)
        }
 
        ehci_dbg(ehci, "IAA watchdog: status %x cmd %x\n", status, cmd);
-       end_unlink_async(ehci);
+       end_iaa_cycle(ehci);
 }
 
 
@@ -394,6 +396,7 @@ static void (*event_handlers[])(struct ehci_hcd *) = {
        ehci_handle_controller_death,   /* EHCI_HRTIMER_POLL_DEAD */
        ehci_handle_intr_unlinks,       /* EHCI_HRTIMER_UNLINK_INTR */
        end_free_itds,                  /* EHCI_HRTIMER_FREE_ITDS */
+       end_unlink_async,               /* EHCI_HRTIMER_ACTIVE_UNLINK */
        ehci_handle_start_intr_unlinks, /* EHCI_HRTIMER_START_UNLINK_INTR */
        unlink_empty_async,             /* EHCI_HRTIMER_ASYNC_UNLINKS */
        ehci_iaa_watchdog,              /* EHCI_HRTIMER_IAA_WATCHDOG */
index ec61aed..2ddf352 100644 (file)
@@ -110,6 +110,7 @@ enum ehci_hrtimer_event {
        EHCI_HRTIMER_POLL_DEAD,         /* Wait for dead controller to stop */
        EHCI_HRTIMER_UNLINK_INTR,       /* Wait for interrupt QH unlink */
        EHCI_HRTIMER_FREE_ITDS,         /* Wait for unused iTDs and siTDs */
+       EHCI_HRTIMER_ACTIVE_UNLINK,     /* Wait while unlinking an active QH */
        EHCI_HRTIMER_START_UNLINK_INTR, /* Unlink empty interrupt QHs */
        EHCI_HRTIMER_ASYNC_UNLINKS,     /* Unlink empty async QHs */
        EHCI_HRTIMER_IAA_WATCHDOG,      /* Handle lost IAA interrupts */
@@ -156,6 +157,8 @@ struct ehci_hcd {                   /* one per controller */
        struct list_head        async_idle;
        unsigned                async_unlink_cycle;
        unsigned                async_count;    /* async activity count */
+       __hc32                  old_current;    /* Test for QH becoming */
+       __hc32                  old_token;      /*  inactive during unlink */
 
        /* periodic schedule support */
 #define        DEFAULT_I_TDPS          1024            /* some HCs can do less */
@@ -185,7 +188,7 @@ struct ehci_hcd {                   /* one per controller */
        struct ehci_sitd        *last_sitd_to_free;
 
        /* per root hub port */
-       unsigned long           reset_done [EHCI_MAX_ROOT_PORTS];
+       unsigned long           reset_done[EHCI_MAX_ROOT_PORTS];
 
        /* bit vectors (one bit per port) */
        unsigned long           bus_suspended;          /* which ports were
@@ -244,9 +247,9 @@ struct ehci_hcd {                   /* one per controller */
        /* irq statistics */
 #ifdef EHCI_STATS
        struct ehci_stats       stats;
-#      define COUNT(x) do { (x)++; } while (0)
+#      define COUNT(x) ((x)++)
 #else
-#      define COUNT(x) do {} while (0)
+#      define COUNT(x)
 #endif
 
        /* debug files */
@@ -268,13 +271,13 @@ struct ehci_hcd {                 /* one per controller */
 };
 
 /* convert between an HCD pointer and the corresponding EHCI_HCD */
-static inline struct ehci_hcd *hcd_to_ehci (struct usb_hcd *hcd)
+static inline struct ehci_hcd *hcd_to_ehci(struct usb_hcd *hcd)
 {
        return (struct ehci_hcd *) (hcd->hcd_priv);
 }
-static inline struct usb_hcd *ehci_to_hcd (struct ehci_hcd *ehci)
+static inline struct usb_hcd *ehci_to_hcd(struct ehci_hcd *ehci)
 {
-       return container_of ((void *) ehci, struct usb_hcd, hcd_priv);
+       return container_of((void *) ehci, struct usb_hcd, hcd_priv);
 }
 
 /*-------------------------------------------------------------------------*/
@@ -316,25 +319,25 @@ struct ehci_qtd {
 #define HALT_BIT(ehci)         cpu_to_hc32(ehci, QTD_STS_HALT)
 #define STATUS_BIT(ehci)       cpu_to_hc32(ehci, QTD_STS_STS)
 
-       __hc32                  hw_buf [5];        /* see EHCI 3.5.4 */
-       __hc32                  hw_buf_hi [5];        /* Appendix B */
+       __hc32                  hw_buf[5];        /* see EHCI 3.5.4 */
+       __hc32                  hw_buf_hi[5];        /* Appendix B */
 
        /* the rest is HCD-private */
        dma_addr_t              qtd_dma;                /* qtd address */
        struct list_head        qtd_list;               /* sw qtd list */
        struct urb              *urb;                   /* qtd's urb */
        size_t                  length;                 /* length of buffer */
-} __attribute__ ((aligned (32)));
+} __aligned(32);
 
 /* mask NakCnt+T in qh->hw_alt_next */
-#define QTD_MASK(ehci) cpu_to_hc32 (ehci, ~0x1f)
+#define QTD_MASK(ehci) cpu_to_hc32(ehci, ~0x1f)
 
-#define IS_SHORT_READ(token) (QTD_LENGTH (token) != 0 && QTD_PID (token) == 1)
+#define IS_SHORT_READ(token) (QTD_LENGTH(token) != 0 && QTD_PID(token) == 1)
 
 /*-------------------------------------------------------------------------*/
 
 /* type tag from {qh,itd,sitd,fstn}->hw_next */
-#define Q_NEXT_TYPE(ehci,dma)  ((dma) & cpu_to_hc32(ehci, 3 << 1))
+#define Q_NEXT_TYPE(ehci, dma) ((dma) & cpu_to_hc32(ehci, 3 << 1))
 
 /*
  * Now the following defines are not converted using the
@@ -350,7 +353,8 @@ struct ehci_qtd {
 #define Q_TYPE_FSTN    (3 << 1)
 
 /* next async queue entry, or pointer to interrupt/periodic QH */
-#define QH_NEXT(ehci,dma)      (cpu_to_hc32(ehci, (((u32)dma)&~0x01f)|Q_TYPE_QH))
+#define QH_NEXT(ehci, dma) \
+               (cpu_to_hc32(ehci, (((u32) dma) & ~0x01f) | Q_TYPE_QH))
 
 /* for periodic/async schedules and qtd lists, mark end of list */
 #define EHCI_LIST_END(ehci)    cpu_to_hc32(ehci, 1) /* "null pointer" to hw */
@@ -405,9 +409,9 @@ struct ehci_qh_hw {
        __hc32                  hw_qtd_next;
        __hc32                  hw_alt_next;
        __hc32                  hw_token;
-       __hc32                  hw_buf [5];
-       __hc32                  hw_buf_hi [5];
-} __attribute__ ((aligned(32)));
+       __hc32                  hw_buf[5];
+       __hc32                  hw_buf_hi[5];
+} __aligned(32);
 
 struct ehci_qh {
        struct ehci_qh_hw       *hw;            /* Must come first */
@@ -432,13 +436,19 @@ struct ehci_qh {
        u8                      xacterrs;       /* XactErr retry counter */
 #define        QH_XACTERR_MAX          32              /* XactErr retry limit */
 
+       u8                      unlink_reason;
+#define QH_UNLINK_HALTED       0x01            /* Halt flag is set */
+#define QH_UNLINK_SHORT_READ   0x02            /* Recover from a short read */
+#define QH_UNLINK_DUMMY_OVERLAY        0x04            /* QH overlayed the dummy TD */
+#define QH_UNLINK_SHUTDOWN     0x08            /* The HC isn't running */
+#define QH_UNLINK_QUEUE_EMPTY  0x10            /* Reached end of the queue */
+#define QH_UNLINK_REQUESTED    0x20            /* Disable, reset, or dequeue */
+
        u8                      gap_uf;         /* uframes split/csplit gap */
 
        unsigned                is_out:1;       /* bulk or intr OUT */
        unsigned                clearing_tt:1;  /* Clear-TT-Buf in progress */
        unsigned                dequeue_during_giveback:1;
-       unsigned                exception:1;    /* got a fault, or an unlink
-                                                  was requested */
        unsigned                should_be_inactive:1;
 };
 
@@ -462,7 +472,7 @@ struct ehci_iso_sched {
        struct list_head        td_list;
        unsigned                span;
        unsigned                first_packet;
-       struct ehci_iso_packet  packet [0];
+       struct ehci_iso_packet  packet[0];
 };
 
 /*
@@ -510,7 +520,7 @@ struct ehci_iso_stream {
 struct ehci_itd {
        /* first part defined by EHCI spec */
        __hc32                  hw_next;           /* see EHCI 3.3.1 */
-       __hc32                  hw_transaction [8]; /* see EHCI 3.3.2 */
+       __hc32                  hw_transaction[8]; /* see EHCI 3.3.2 */
 #define EHCI_ISOC_ACTIVE        (1<<31)        /* activate transfer this slot */
 #define EHCI_ISOC_BUF_ERR       (1<<30)        /* Data buffer error */
 #define EHCI_ISOC_BABBLE        (1<<29)        /* babble detected */
@@ -520,8 +530,8 @@ struct ehci_itd {
 
 #define ITD_ACTIVE(ehci)       cpu_to_hc32(ehci, EHCI_ISOC_ACTIVE)
 
-       __hc32                  hw_bufp [7];    /* see EHCI 3.3.3 */
-       __hc32                  hw_bufp_hi [7]; /* Appendix B */
+       __hc32                  hw_bufp[7];     /* see EHCI 3.3.3 */
+       __hc32                  hw_bufp_hi[7];  /* Appendix B */
 
        /* the rest is HCD-private */
        dma_addr_t              itd_dma;        /* for this itd */
@@ -535,7 +545,7 @@ struct ehci_itd {
        unsigned                frame;          /* where scheduled */
        unsigned                pg;
        unsigned                index[8];       /* in urb->iso_frame_desc */
-} __attribute__ ((aligned (32)));
+} __aligned(32);
 
 /*-------------------------------------------------------------------------*/
 
@@ -554,7 +564,7 @@ struct ehci_sitd {
        __hc32                  hw_results;             /* EHCI table 3-11 */
 #define        SITD_IOC        (1 << 31)       /* interrupt on completion */
 #define        SITD_PAGE       (1 << 30)       /* buffer 0/1 */
-#define        SITD_LENGTH(x)  (0x3ff & ((x)>>16))
+#define        SITD_LENGTH(x)  (((x) >> 16) & 0x3ff)
 #define        SITD_STS_ACTIVE (1 << 7)        /* HC may execute this */
 #define        SITD_STS_ERR    (1 << 6)        /* error from TT */
 #define        SITD_STS_DBE    (1 << 5)        /* data buffer error (in HC) */
@@ -565,9 +575,9 @@ struct ehci_sitd {
 
 #define SITD_ACTIVE(ehci)      cpu_to_hc32(ehci, SITD_STS_ACTIVE)
 
-       __hc32                  hw_buf [2];             /* EHCI table 3-12 */
+       __hc32                  hw_buf[2];              /* EHCI table 3-12 */
        __hc32                  hw_backpointer;         /* EHCI table 3-13 */
-       __hc32                  hw_buf_hi [2];          /* Appendix B */
+       __hc32                  hw_buf_hi[2];           /* Appendix B */
 
        /* the rest is HCD-private */
        dma_addr_t              sitd_dma;
@@ -578,7 +588,7 @@ struct ehci_sitd {
        struct list_head        sitd_list;      /* list of stream's sitds */
        unsigned                frame;
        unsigned                index;
-} __attribute__ ((aligned (32)));
+} __aligned(32);
 
 /*-------------------------------------------------------------------------*/
 
@@ -598,7 +608,7 @@ struct ehci_fstn {
        /* the rest is HCD-private */
        dma_addr_t              fstn_dma;
        union ehci_shadow       fstn_next;      /* ptr to periodic q entry */
-} __attribute__ ((aligned (32)));
+} __aligned(32);
 
 /*-------------------------------------------------------------------------*/
 
@@ -634,10 +644,10 @@ struct ehci_tt {
 /* Prepare the PORTSC wakeup flags during controller suspend/resume */
 
 #define ehci_prepare_ports_for_controller_suspend(ehci, do_wakeup)     \
-               ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup);
+               ehci_adjust_port_wakeup_flags(ehci, true, do_wakeup)
 
 #define ehci_prepare_ports_for_controller_resume(ehci)                 \
-               ehci_adjust_port_wakeup_flags(ehci, false, false);
+               ehci_adjust_port_wakeup_flags(ehci, false, false)
 
 /*-------------------------------------------------------------------------*/
 
@@ -731,7 +741,7 @@ ehci_port_speed(struct ehci_hcd *ehci, unsigned int portsc)
 #endif
 
 static inline unsigned int ehci_readl(const struct ehci_hcd *ehci,
-               __u32 __iomem * regs)
+               __u32 __iomem *regs)
 {
 #ifdef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO
        return ehci_big_endian_mmio(ehci) ?
@@ -806,7 +816,7 @@ static inline void set_ohci_hcfs(struct ehci_hcd *ehci, int operational)
 #define ehci_big_endian_desc(e)                ((e)->big_endian_desc)
 
 /* cpu to ehci */
-static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
+static inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x)
 {
        return ehci_big_endian_desc(ehci)
                ? (__force __hc32)cpu_to_be32(x)
@@ -814,14 +824,14 @@ static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
 }
 
 /* ehci to cpu */
-static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
+static inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x)
 {
        return ehci_big_endian_desc(ehci)
                ? be32_to_cpu((__force __be32)x)
                : le32_to_cpu((__force __le32)x);
 }
 
-static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
+static inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x)
 {
        return ehci_big_endian_desc(ehci)
                ? be32_to_cpup((__force __be32 *)x)
@@ -831,18 +841,18 @@ static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
 #else
 
 /* cpu to ehci */
-static inline __hc32 cpu_to_hc32 (const struct ehci_hcd *ehci, const u32 x)
+static inline __hc32 cpu_to_hc32(const struct ehci_hcd *ehci, const u32 x)
 {
        return cpu_to_le32(x);
 }
 
 /* ehci to cpu */
-static inline u32 hc32_to_cpu (const struct ehci_hcd *ehci, const __hc32 x)
+static inline u32 hc32_to_cpu(const struct ehci_hcd *ehci, const __hc32 x)
 {
        return le32_to_cpu(x);
 }
 
-static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
+static inline u32 hc32_to_cpup(const struct ehci_hcd *ehci, const __hc32 *x)
 {
        return le32_to_cpup(x);
 }
@@ -852,18 +862,13 @@ static inline u32 hc32_to_cpup (const struct ehci_hcd *ehci, const __hc32 *x)
 /*-------------------------------------------------------------------------*/
 
 #define ehci_dbg(ehci, fmt, args...) \
-       dev_dbg(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
+       dev_dbg(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
 #define ehci_err(ehci, fmt, args...) \
-       dev_err(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
+       dev_err(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
 #define ehci_info(ehci, fmt, args...) \
-       dev_info(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
+       dev_info(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
 #define ehci_warn(ehci, fmt, args...) \
-       dev_warn(ehci_to_hcd(ehci)->self.controller , fmt , ## args)
-
-
-#ifndef CONFIG_DYNAMIC_DEBUG
-#define STUB_DEBUG_FILES
-#endif
+       dev_warn(ehci_to_hcd(ehci)->self.controller, fmt, ## args)
 
 /*-------------------------------------------------------------------------*/
 
index 2341af4..360a5e9 100644 (file)
@@ -2267,7 +2267,7 @@ static unsigned qh_completions(struct fotg210_hcd *fotg210,
                struct fotg210_qh *qh)
 {
        struct fotg210_qtd *last, *end = qh->dummy;
-       struct list_head *entry, *tmp;
+       struct fotg210_qtd *qtd, *tmp;
        int last_status;
        int stopped;
        unsigned count = 0;
@@ -2301,12 +2301,10 @@ rescan:
         * then let the queue advance.
         * if queue is stopped, handles unlinks.
         */
-       list_for_each_safe(entry, tmp, &qh->qtd_list) {
-               struct fotg210_qtd *qtd;
+       list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) {
                struct urb *urb;
                u32 token = 0;
 
-               qtd = list_entry(entry, struct fotg210_qtd, qtd_list);
                urb = qtd->urb;
 
                /* clean up any state from previous QTD ...*/
@@ -2544,14 +2542,11 @@ retry_xacterr:
  * used for cleanup after errors, before HC sees an URB's TDs.
  */
 static void qtd_list_free(struct fotg210_hcd *fotg210, struct urb *urb,
-               struct list_head *qtd_list)
+               struct list_head *head)
 {
-       struct list_head *entry, *temp;
-
-       list_for_each_safe(entry, temp, qtd_list) {
-               struct fotg210_qtd *qtd;
+       struct fotg210_qtd *qtd, *temp;
 
-               qtd = list_entry(entry, struct fotg210_qtd, qtd_list);
+       list_for_each_entry_safe(qtd, temp, head, qtd_list) {
                list_del(&qtd->qtd_list);
                fotg210_qtd_free(fotg210, qtd);
        }
index 0c38265..1044b0f 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/of_platform.h>
 #include <linux/clk.h>
 #include <linux/module.h>
+#include <linux/dma-mapping.h>
 
 struct fsl_usb2_dev_data {
        char *dr_mode;          /* controller mode */
@@ -96,7 +97,11 @@ static struct platform_device *fsl_usb2_device_register(
        pdev->dev.parent = &ofdev->dev;
 
        pdev->dev.coherent_dma_mask = ofdev->dev.coherent_dma_mask;
-       *pdev->dev.dma_mask = *ofdev->dev.dma_mask;
+
+       if (!pdev->dev.dma_mask)
+               pdev->dev.dma_mask = &ofdev->dev.coherent_dma_mask;
+       else
+               dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
 
        retval = platform_device_add_data(pdev, pdata, sizeof(*pdata));
        if (retval)
index bd98706..c369c29 100644 (file)
@@ -797,19 +797,16 @@ max3421_check_unlink(struct usb_hcd *hcd)
 {
        struct spi_device *spi = to_spi_device(hcd->self.controller);
        struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd);
-       struct list_head *pos, *upos, *next_upos;
        struct max3421_ep *max3421_ep;
        struct usb_host_endpoint *ep;
-       struct urb *urb;
+       struct urb *urb, *next;
        unsigned long flags;
        int retval = 0;
 
        spin_lock_irqsave(&max3421_hcd->lock, flags);
-       list_for_each(pos, &max3421_hcd->ep_list) {
-               max3421_ep = container_of(pos, struct max3421_ep, ep_list);
+       list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) {
                ep = max3421_ep->ep;
-               list_for_each_safe(upos, next_upos, &ep->urb_list) {
-                       urb = container_of(upos, struct urb, urb_list);
+               list_for_each_entry_safe(urb, next, &ep->urb_list, urb_list) {
                        if (urb->unlinked) {
                                retval = 1;
                                dev_dbg(&spi->dev, "%s: URB %p unlinked=%d",
@@ -1184,22 +1181,19 @@ dump_eps(struct usb_hcd *hcd)
        struct max3421_hcd *max3421_hcd = hcd_to_max3421(hcd);
        struct max3421_ep *max3421_ep;
        struct usb_host_endpoint *ep;
-       struct list_head *pos, *upos;
        char ubuf[512], *dp, *end;
        unsigned long flags;
        struct urb *urb;
        int epnum, ret;
 
        spin_lock_irqsave(&max3421_hcd->lock, flags);
-       list_for_each(pos, &max3421_hcd->ep_list) {
-               max3421_ep = container_of(pos, struct max3421_ep, ep_list);
+       list_for_each_entry(max3421_ep, &max3421_hcd->ep_list, ep_list) {
                ep = max3421_ep->ep;
 
                dp = ubuf;
                end = dp + sizeof(ubuf);
                *dp = '\0';
-               list_for_each(upos, &ep->urb_list) {
-                       urb = container_of(upos, struct urb, urb_list);
+               list_for_each_entry(urb, &ep->urb_list, urb_list) {
                        ret = snprintf(dp, end - dp, " %p(%d.%s %d/%d)", urb,
                                       usb_pipetype(urb->pipe),
                                       usb_urb_dir_in(urb) ? "IN" : "OUT",
index cfa9427..ebacf97 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/dma-mapping.h>
 #include <linux/io.h>
 #include <linux/i2c.h>
-#include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/platform_device.h>
 
 #include "ohci.h"
 
-
 #include <mach/hardware.h>
-#include <asm/mach-types.h>
-#include <asm/io.h>
-
-#include <mach/platform.h>
-#include <mach/irqs.h>
 
 #define USB_CONFIG_BASE                0x31020000
 #define PWRMAN_BASE            0x40004000
index c2669f1..ae1c988 100644 (file)
@@ -310,8 +310,7 @@ static int ohci_platform_suspend(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ohci_pdata *pdata = dev->platform_data;
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
        bool do_wakeup = device_may_wakeup(dev);
        int ret;
 
@@ -329,8 +328,7 @@ static int ohci_platform_resume(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
 
        if (pdata->power_on) {
                int err = pdata->power_on(pdev);
index e8c006e..a667cf2 100644 (file)
@@ -435,7 +435,7 @@ int usb_hcd_pxa27x_probe (const struct hc_driver *driver, struct platform_device
        irq = platform_get_irq(pdev, 0);
        if (irq < 0) {
                pr_err("no resource of IORESOURCE_IRQ");
-               return -ENXIO;
+               return irq;
        }
 
        usb_clk = devm_clk_get(&pdev->dev, NULL);
index df9028e..acf2eb2 100644 (file)
@@ -270,8 +270,7 @@ static int st_ohci_suspend(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ohci_pdata *pdata = dev->platform_data;
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
        bool do_wakeup = device_may_wakeup(dev);
        int ret;
 
@@ -289,8 +288,7 @@ static int st_ohci_resume(struct device *dev)
 {
        struct usb_hcd *hcd = dev_get_drvdata(dev);
        struct usb_ohci_pdata *pdata = dev_get_platdata(dev);
-       struct platform_device *pdev =
-               container_of(dev, struct platform_device, dev);
+       struct platform_device *pdev = to_platform_device(dev);
        int err;
 
        if (pdata->power_on) {
index bc74aca..4e4d601 100644 (file)
@@ -981,7 +981,7 @@ static int qh_schedule(struct oxu_hcd *oxu, struct ehci_qh *qh);
 static unsigned qh_completions(struct oxu_hcd *oxu, struct ehci_qh *qh)
 {
        struct ehci_qtd *last = NULL, *end = qh->dummy;
-       struct list_head *entry, *tmp;
+       struct ehci_qtd *qtd, *tmp;
        int stopped;
        unsigned count = 0;
        int do_status = 0;
@@ -1006,12 +1006,10 @@ static unsigned qh_completions(struct oxu_hcd *oxu, struct ehci_qh *qh)
         * then let the queue advance.
         * if queue is stopped, handles unlinks.
         */
-       list_for_each_safe(entry, tmp, &qh->qtd_list) {
-               struct ehci_qtd *qtd;
+       list_for_each_entry_safe(qtd, tmp, &qh->qtd_list, qtd_list) {
                struct urb *urb;
                u32 token = 0;
 
-               qtd = list_entry(entry, struct ehci_qtd, qtd_list);
                urb = qtd->urb;
 
                /* Clean up any state from previous QTD ...*/
@@ -1174,14 +1172,11 @@ halt:
  * used for cleanup after errors, before HC sees an URB's TDs.
  */
 static void qtd_list_free(struct oxu_hcd *oxu,
-                               struct urb *urb, struct list_head *qtd_list)
+                               struct urb *urb, struct list_head *head)
 {
-       struct list_head *entry, *temp;
-
-       list_for_each_safe(entry, temp, qtd_list) {
-               struct ehci_qtd *qtd;
+       struct ehci_qtd *qtd, *temp;
 
-               qtd = list_entry(entry, struct ehci_qtd, qtd_list);
+       list_for_each_entry_safe(qtd, temp, head, qtd_list) {
                list_del(&qtd->qtd_list);
                oxu_qtd_free(oxu, qtd);
        }
index 26cb8c8..35af362 100644 (file)
@@ -992,7 +992,7 @@ static void quirk_usb_handoff_xhci(struct pci_dev *pdev)
        if ((ext_cap_offset + sizeof(val)) > len) {
                /* We're reading garbage from the controller */
                dev_warn(&pdev->dev, "xHCI controller failing to respond");
-               return;
+               goto iounmap;
        }
        val = readl(base + ext_cap_offset);
 
@@ -1055,6 +1055,7 @@ hc_init:
                         XHCI_MAX_HALT_USEC, val);
        }
 
+iounmap:
        iounmap(base);
 }
 
index 4cbd063..bfa7fa3 100644 (file)
@@ -2099,16 +2099,13 @@ static void r8a66597_check_detect_child(struct r8a66597 *r8a66597,
 
        memset(now_map, 0, sizeof(now_map));
 
-       list_for_each_entry(bus, &usb_bus_list, bus_list) {
-               if (!bus->root_hub)
-                       continue;
-
-               if (bus->busnum != hcd->self.busnum)
-                       continue;
-
+       mutex_lock(&usb_bus_idr_lock);
+       bus = idr_find(&usb_bus_idr, hcd->self.busnum);
+       if (bus && bus->root_hub) {
                collect_usb_address_map(bus->root_hub, now_map);
                update_usb_address_map(r8a66597, bus->root_hub, now_map);
        }
+       mutex_unlock(&usb_bus_idr_lock);
 }
 
 static int r8a66597_hub_status_data(struct usb_hcd *hcd, char *buf)
index 05c85c7..43d5293 100644 (file)
@@ -1309,13 +1309,9 @@ static void u132_hcd_ring_work_scheduler(struct work_struct *work)
                u132_ring_put_kref(u132, ring);
                return;
        } else if (ring->curr_endp) {
-               struct u132_endp *last_endp = ring->curr_endp;
-               struct list_head *scan;
-               struct list_head *head = &last_endp->endp_ring;
+               struct u132_endp *endp, *last_endp = ring->curr_endp;
                unsigned long wakeup = 0;
-               list_for_each(scan, head) {
-                       struct u132_endp *endp = list_entry(scan,
-                               struct u132_endp, endp_ring);
+               list_for_each_entry(endp, &last_endp->endp_ring, endp_ring) {
                        if (endp->queue_next == endp->queue_last) {
                        } else if ((endp->delayed == 0)
                                || time_after_eq(jiffies, endp->jiffies)) {
@@ -2393,14 +2389,12 @@ static int u132_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
 static int dequeue_from_overflow_chain(struct u132 *u132,
        struct u132_endp *endp, struct urb *urb)
 {
-       struct list_head *scan;
-       struct list_head *head = &endp->urb_more;
-       list_for_each(scan, head) {
-               struct u132_urbq *urbq = list_entry(scan, struct u132_urbq,
-                       urb_more);
+       struct u132_urbq *urbq;
+
+       list_for_each_entry(urbq, &endp->urb_more, urb_more) {
                if (urbq->urb == urb) {
                        struct usb_hcd *hcd = u132_to_hcd(u132);
-                       list_del(scan);
+                       list_del(&urbq->urb_more);
                        endp->queue_size -= 1;
                        urb->error_count = 0;
                        usb_hcd_giveback_urb(hcd, urb, 0);
index b30b4ce..d61fcc4 100644 (file)
@@ -50,14 +50,18 @@ static u8 usb_bos_descriptor [] = {
        0x00,                           /* bU1DevExitLat, set later. */
        0x00, 0x00,                     /* __le16 bU2DevExitLat, set later. */
        /* Second device capability, SuperSpeedPlus */
-       0x0c,                           /* bLength 12, will be adjusted later */
+       0x1c,                           /* bLength 28, will be adjusted later */
        USB_DT_DEVICE_CAPABILITY,       /* Device Capability */
        USB_SSP_CAP_TYPE,               /* bDevCapabilityType SUPERSPEED_PLUS */
        0x00,                           /* bReserved 0 */
-       0x00, 0x00, 0x00, 0x00,         /* bmAttributes, get from xhci psic */
-       0x00, 0x00,                     /* wFunctionalitySupport */
+       0x23, 0x00, 0x00, 0x00,         /* bmAttributes, SSAC=3 SSIC=1 */
+       0x01, 0x00,                     /* wFunctionalitySupport */
        0x00, 0x00,                     /* wReserved 0 */
-       /* Sublink Speed Attributes are added in xhci_create_usb3_bos_desc() */
+       /* Default Sublink Speed Attributes, overwrite if custom PSI exists */
+       0x34, 0x00, 0x05, 0x00,         /* 5Gbps, symmetric, rx, ID = 4 */
+       0xb4, 0x00, 0x05, 0x00,         /* 5Gbps, symmetric, tx, ID = 4 */
+       0x35, 0x40, 0x0a, 0x00,         /* 10Gbps, SSP, symmetric, rx, ID = 5 */
+       0xb5, 0x40, 0x0a, 0x00,         /* 10Gbps, SSP, symmetric, tx, ID = 5 */
 };
 
 static int xhci_create_usb3_bos_desc(struct xhci_hcd *xhci, char *buf,
@@ -72,10 +76,14 @@ static int xhci_create_usb3_bos_desc(struct xhci_hcd *xhci, char *buf,
        ssp_cap_size = sizeof(usb_bos_descriptor) - desc_size;
 
        /* does xhci support USB 3.1 Enhanced SuperSpeed */
-       if (xhci->usb3_rhub.min_rev >= 0x01 && xhci->usb3_rhub.psi_uid_count) {
-               /* two SSA entries for each unique PSI ID, one RX and one TX */
-               ssa_count = xhci->usb3_rhub.psi_uid_count * 2;
-               ssa_size = ssa_count * sizeof(u32);
+       if (xhci->usb3_rhub.min_rev >= 0x01) {
+               /* does xhci provide a PSI table for SSA speed attributes? */
+               if (xhci->usb3_rhub.psi_count) {
+                       /* two SSA entries for each unique PSI ID, RX and TX */
+                       ssa_count = xhci->usb3_rhub.psi_uid_count * 2;
+                       ssa_size = ssa_count * sizeof(u32);
+                       ssp_cap_size -= 16; /* skip copying the default SSA */
+               }
                desc_size += ssp_cap_size;
                usb3_1 = true;
        }
@@ -102,7 +110,8 @@ static int xhci_create_usb3_bos_desc(struct xhci_hcd *xhci, char *buf,
                put_unaligned_le16(HCS_U2_LATENCY(temp), &buf[13]);
        }
 
-       if (usb3_1) {
+       /* If PSI table exists, add the custom speed attributes from it */
+       if (usb3_1 && xhci->usb3_rhub.psi_count) {
                u32 ssp_cap_base, bm_attrib, psi;
                int offset;
 
index 5cd080e..80c1de2 100644 (file)
@@ -1070,7 +1070,7 @@ static u32 xhci_find_real_port_number(struct xhci_hcd *xhci,
        struct usb_device *top_dev;
        struct usb_hcd *hcd;
 
-       if (udev->speed == USB_SPEED_SUPER)
+       if (udev->speed >= USB_SPEED_SUPER)
                hcd = xhci->shared_hcd;
        else
                hcd = xhci->main_hcd;
@@ -1105,6 +1105,10 @@ int xhci_setup_addressable_virt_dev(struct xhci_hcd *xhci, struct usb_device *ud
        /* 3) Only the control endpoint is valid - one endpoint context */
        slot_ctx->dev_info |= cpu_to_le32(LAST_CTX(1) | udev->route);
        switch (udev->speed) {
+       case USB_SPEED_SUPER_PLUS:
+               slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SSP);
+               max_packets = MAX_PACKET(512);
+               break;
        case USB_SPEED_SUPER:
                slot_ctx->dev_info |= cpu_to_le32(SLOT_SPEED_SS);
                max_packets = MAX_PACKET(512);
@@ -1292,6 +1296,7 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
                }
                /* Fall through - SS and HS isoc/int have same decoding */
 
+       case USB_SPEED_SUPER_PLUS:
        case USB_SPEED_SUPER:
                if (usb_endpoint_xfer_int(&ep->desc) ||
                    usb_endpoint_xfer_isoc(&ep->desc)) {
@@ -1321,7 +1326,7 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
        default:
                BUG();
        }
-       return EP_INTERVAL(interval);
+       return interval;
 }
 
 /* The "Mult" field in the endpoint context is only set for SuperSpeed isoc eps.
@@ -1332,39 +1337,42 @@ static unsigned int xhci_get_endpoint_interval(struct usb_device *udev,
 static u32 xhci_get_endpoint_mult(struct usb_device *udev,
                struct usb_host_endpoint *ep)
 {
-       if (udev->speed != USB_SPEED_SUPER ||
+       if (udev->speed < USB_SPEED_SUPER ||
                        !usb_endpoint_xfer_isoc(&ep->desc))
                return 0;
        return ep->ss_ep_comp.bmAttributes;
 }
 
+static u32 xhci_get_endpoint_max_burst(struct usb_device *udev,
+                                      struct usb_host_endpoint *ep)
+{
+       /* Super speed and Plus have max burst in ep companion desc */
+       if (udev->speed >= USB_SPEED_SUPER)
+               return ep->ss_ep_comp.bMaxBurst;
+
+       if (udev->speed == USB_SPEED_HIGH &&
+           (usb_endpoint_xfer_isoc(&ep->desc) ||
+            usb_endpoint_xfer_int(&ep->desc)))
+               return (usb_endpoint_maxp(&ep->desc) & 0x1800) >> 11;
+
+       return 0;
+}
+
 static u32 xhci_get_endpoint_type(struct usb_host_endpoint *ep)
 {
        int in;
-       u32 type;
 
        in = usb_endpoint_dir_in(&ep->desc);
-       if (usb_endpoint_xfer_control(&ep->desc)) {
-               type = EP_TYPE(CTRL_EP);
-       } else if (usb_endpoint_xfer_bulk(&ep->desc)) {
-               if (in)
-                       type = EP_TYPE(BULK_IN_EP);
-               else
-                       type = EP_TYPE(BULK_OUT_EP);
-       } else if (usb_endpoint_xfer_isoc(&ep->desc)) {
-               if (in)
-                       type = EP_TYPE(ISOC_IN_EP);
-               else
-                       type = EP_TYPE(ISOC_OUT_EP);
-       } else if (usb_endpoint_xfer_int(&ep->desc)) {
-               if (in)
-                       type = EP_TYPE(INT_IN_EP);
-               else
-                       type = EP_TYPE(INT_OUT_EP);
-       } else {
-               type = 0;
-       }
-       return type;
+
+       if (usb_endpoint_xfer_control(&ep->desc))
+               return CTRL_EP;
+       if (usb_endpoint_xfer_bulk(&ep->desc))
+               return in ? BULK_IN_EP : BULK_OUT_EP;
+       if (usb_endpoint_xfer_isoc(&ep->desc))
+               return in ? ISOC_IN_EP : ISOC_OUT_EP;
+       if (usb_endpoint_xfer_int(&ep->desc))
+               return in ? INT_IN_EP : INT_OUT_EP;
+       return 0;
 }
 
 /* Return the maximum endpoint service interval time (ESIT) payload.
@@ -1382,7 +1390,12 @@ static u32 xhci_get_max_esit_payload(struct usb_device *udev,
                        usb_endpoint_xfer_bulk(&ep->desc))
                return 0;
 
-       if (udev->speed == USB_SPEED_SUPER)
+       /* SuperSpeedPlus Isoc ep sending over 48k per esit */
+       if ((udev->speed >= USB_SPEED_SUPER_PLUS) &&
+           USB_SS_SSP_ISOC_COMP(ep->ss_ep_comp.bmAttributes))
+               return le32_to_cpu(ep->ssp_isoc_ep_comp.dwBytesPerInterval);
+       /* SuperSpeed or SuperSpeedPlus Isoc ep with less than 48k per esit */
+       else if (udev->speed >= USB_SPEED_SUPER)
                return le16_to_cpu(ep->ss_ep_comp.wBytesPerInterval);
 
        max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc));
@@ -1404,10 +1417,14 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
        struct xhci_ep_ctx *ep_ctx;
        struct xhci_ring *ep_ring;
        unsigned int max_packet;
-       unsigned int max_burst;
-       enum xhci_ring_type type;
+       enum xhci_ring_type ring_type;
        u32 max_esit_payload;
        u32 endpoint_type;
+       unsigned int max_burst;
+       unsigned int interval;
+       unsigned int mult;
+       unsigned int avg_trb_len;
+       unsigned int err_count = 0;
 
        ep_index = xhci_get_endpoint_index(&ep->desc);
        ep_ctx = xhci_get_ep_ctx(xhci, virt_dev->in_ctx, ep_index);
@@ -1415,12 +1432,11 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
        endpoint_type = xhci_get_endpoint_type(ep);
        if (!endpoint_type)
                return -EINVAL;
-       ep_ctx->ep_info2 = cpu_to_le32(endpoint_type);
 
-       type = usb_endpoint_type(&ep->desc);
+       ring_type = usb_endpoint_type(&ep->desc);
        /* Set up the endpoint ring */
        virt_dev->eps[ep_index].new_ring =
-               xhci_ring_alloc(xhci, 2, 1, type, mem_flags);
+               xhci_ring_alloc(xhci, 2, 1, ring_type, mem_flags);
        if (!virt_dev->eps[ep_index].new_ring) {
                /* Attempt to use the ring cache */
                if (virt_dev->num_rings_cached == 0)
@@ -1430,80 +1446,52 @@ int xhci_endpoint_init(struct xhci_hcd *xhci,
                        virt_dev->ring_cache[virt_dev->num_rings_cached];
                virt_dev->ring_cache[virt_dev->num_rings_cached] = NULL;
                xhci_reinit_cached_ring(xhci, virt_dev->eps[ep_index].new_ring,
-                                       1, type);
+                                       1, ring_type);
        }
        virt_dev->eps[ep_index].skip = false;
        ep_ring = virt_dev->eps[ep_index].new_ring;
-       ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma | ep_ring->cycle_state);
 
-       ep_ctx->ep_info = cpu_to_le32(xhci_get_endpoint_interval(udev, ep)
-                                     | EP_MULT(xhci_get_endpoint_mult(udev, ep)));
+       /*
+        * Get values to fill the endpoint context, mostly from ep descriptor.
+        * The average TRB buffer lengt for bulk endpoints is unclear as we
+        * have no clue on scatter gather list entry size. For Isoc and Int,
+        * set it to max available. See xHCI 1.1 spec 4.14.1.1 for details.
+        */
+       max_esit_payload = xhci_get_max_esit_payload(udev, ep);
+       interval = xhci_get_endpoint_interval(udev, ep);
+       mult = xhci_get_endpoint_mult(udev, ep);
+       max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc));
+       max_burst = xhci_get_endpoint_max_burst(udev, ep);
+       avg_trb_len = max_esit_payload;
 
        /* FIXME dig Mult and streams info out of ep companion desc */
 
-       /* Allow 3 retries for everything but isoc;
-        * CErr shall be set to 0 for Isoch endpoints.
-        */
+       /* Allow 3 retries for everything but isoc, set CErr = 3 */
        if (!usb_endpoint_xfer_isoc(&ep->desc))
-               ep_ctx->ep_info2 |= cpu_to_le32(ERROR_COUNT(3));
-       else
-               ep_ctx->ep_info2 |= cpu_to_le32(ERROR_COUNT(0));
-
-       /* Set the max packet size and max burst */
-       max_packet = GET_MAX_PACKET(usb_endpoint_maxp(&ep->desc));
-       max_burst = 0;
-       switch (udev->speed) {
-       case USB_SPEED_SUPER:
-               /* dig out max burst from ep companion desc */
-               max_burst = ep->ss_ep_comp.bMaxBurst;
-               break;
-       case USB_SPEED_HIGH:
-               /* Some devices get this wrong */
-               if (usb_endpoint_xfer_bulk(&ep->desc))
-                       max_packet = 512;
-               /* bits 11:12 specify the number of additional transaction
-                * opportunities per microframe (USB 2.0, section 9.6.6)
-                */
-               if (usb_endpoint_xfer_isoc(&ep->desc) ||
-                               usb_endpoint_xfer_int(&ep->desc)) {
-                       max_burst = (usb_endpoint_maxp(&ep->desc)
-                                    & 0x1800) >> 11;
-               }
-               break;
-       case USB_SPEED_FULL:
-       case USB_SPEED_LOW:
-               break;
-       default:
-               BUG();
-       }
-       ep_ctx->ep_info2 |= cpu_to_le32(MAX_PACKET(max_packet) |
-                       MAX_BURST(max_burst));
-       max_esit_payload = xhci_get_max_esit_payload(udev, ep);
-       ep_ctx->tx_info = cpu_to_le32(MAX_ESIT_PAYLOAD_FOR_EP(max_esit_payload));
-
-       /*
-        * XXX no idea how to calculate the average TRB buffer length for bulk
-        * endpoints, as the driver gives us no clue how big each scatter gather
-        * list entry (or buffer) is going to be.
-        *
-        * For isochronous and interrupt endpoints, we set it to the max
-        * available, until we have new API in the USB core to allow drivers to
-        * declare how much bandwidth they actually need.
-        *
-        * Normally, it would be calculated by taking the total of the buffer
-        * lengths in the TD and then dividing by the number of TRBs in a TD,
-        * including link TRBs, No-op TRBs, and Event data TRBs.  Since we don't
-        * use Event Data TRBs, and we don't chain in a link TRB on short
-        * transfers, we're basically dividing by 1.
-        *
-        * xHCI 1.0 and 1.1 specification indicates that the Average TRB Length
-        * should be set to 8 for control endpoints.
-        */
+               err_count = 3;
+       /* Some devices get this wrong */
+       if (usb_endpoint_xfer_bulk(&ep->desc) && udev->speed == USB_SPEED_HIGH)
+               max_packet = 512;
+       /* xHCI 1.0 and 1.1 indicates that ctrl ep avg TRB Length should be 8 */
        if (usb_endpoint_xfer_control(&ep->desc) && xhci->hci_version >= 0x100)
-               ep_ctx->tx_info |= cpu_to_le32(AVG_TRB_LENGTH_FOR_EP(8));
-       else
-               ep_ctx->tx_info |=
-                        cpu_to_le32(AVG_TRB_LENGTH_FOR_EP(max_esit_payload));
+               avg_trb_len = 8;
+       /* xhci 1.1 with LEC support doesn't use mult field, use RsvdZ */
+       if ((xhci->hci_version > 0x100) && HCC2_LEC(xhci->hcc_params2))
+               mult = 0;
+
+       /* Fill the endpoint context */
+       ep_ctx->ep_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_HI(max_esit_payload) |
+                                     EP_INTERVAL(interval) |
+                                     EP_MULT(mult));
+       ep_ctx->ep_info2 = cpu_to_le32(EP_TYPE(endpoint_type) |
+                                      MAX_PACKET(max_packet) |
+                                      MAX_BURST(max_burst) |
+                                      ERROR_COUNT(err_count));
+       ep_ctx->deq = cpu_to_le64(ep_ring->first_seg->dma |
+                                 ep_ring->cycle_state);
+
+       ep_ctx->tx_info = cpu_to_le32(EP_MAX_ESIT_PAYLOAD_LO(max_esit_payload) |
+                                     EP_AVG_TRB_LENGTH(avg_trb_len));
 
        /* FIXME Debug endpoint context */
        return 0;
index 3915657..7cf6621 100644 (file)
@@ -3558,12 +3558,11 @@ static int count_isoc_trbs_needed(struct xhci_hcd *xhci,
  * zero.  Only xHCI 1.0 host controllers support this field.
  */
 static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci,
-               struct usb_device *udev,
                struct urb *urb, unsigned int total_packet_count)
 {
        unsigned int max_burst;
 
-       if (xhci->hci_version < 0x100 || udev->speed != USB_SPEED_SUPER)
+       if (xhci->hci_version < 0x100 || urb->dev->speed < USB_SPEED_SUPER)
                return 0;
 
        max_burst = urb->ep->ss_ep_comp.bMaxBurst;
@@ -3579,7 +3578,6 @@ static unsigned int xhci_get_burst_count(struct xhci_hcd *xhci,
  * contain 1 to (bMaxBurst + 1) packets.
  */
 static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci,
-               struct usb_device *udev,
                struct urb *urb, unsigned int total_packet_count)
 {
        unsigned int max_burst;
@@ -3588,8 +3586,7 @@ static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci,
        if (xhci->hci_version < 0x100)
                return 0;
 
-       switch (udev->speed) {
-       case USB_SPEED_SUPER:
+       if (urb->dev->speed >= USB_SPEED_SUPER) {
                /* bMaxBurst is zero based: 0 means 1 packet per burst */
                max_burst = urb->ep->ss_ep_comp.bMaxBurst;
                residue = total_packet_count % (max_burst + 1);
@@ -3599,11 +3596,10 @@ static unsigned int xhci_get_last_burst_packet_count(struct xhci_hcd *xhci,
                if (residue == 0)
                        return max_burst;
                return residue - 1;
-       default:
-               if (total_packet_count == 0)
-                       return 0;
-               return total_packet_count - 1;
        }
+       if (total_packet_count == 0)
+               return 0;
+       return total_packet_count - 1;
 }
 
 /*
@@ -3714,6 +3710,7 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
        int i, j;
        bool more_trbs_coming;
        struct xhci_virt_ep *xep;
+       int frame_id;
 
        xep = &xhci->devs[slot_id]->eps[ep_index];
        ep_ring = xhci->devs[slot_id]->eps[ep_index].ring;
@@ -3723,33 +3720,31 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                xhci_dbg(xhci, "Isoc URB with zero packets?\n");
                return -EINVAL;
        }
-
        start_addr = (u64) urb->transfer_dma;
        start_trb = &ep_ring->enqueue->generic;
        start_cycle = ep_ring->cycle_state;
 
        urb_priv = urb->hcpriv;
-       /* Queue the first TRB, even if it's zero-length */
+       /* Queue the TRBs for each TD, even if they are zero-length */
        for (i = 0; i < num_tds; i++) {
-               unsigned int total_packet_count;
-               unsigned int burst_count;
-               unsigned int residue;
+               unsigned int total_pkt_count, max_pkt;
+               unsigned int burst_count, last_burst_pkt_count;
+               u32 sia_frame_id;
 
                first_trb = true;
                running_total = 0;
                addr = start_addr + urb->iso_frame_desc[i].offset;
                td_len = urb->iso_frame_desc[i].length;
                td_remain_len = td_len;
-               total_packet_count = DIV_ROUND_UP(td_len,
-                               GET_MAX_PACKET(
-                                       usb_endpoint_maxp(&urb->ep->desc)));
+               max_pkt = GET_MAX_PACKET(usb_endpoint_maxp(&urb->ep->desc));
+               total_pkt_count = DIV_ROUND_UP(td_len, max_pkt);
+
                /* A zero-length transfer still involves at least one packet. */
-               if (total_packet_count == 0)
-                       total_packet_count++;
-               burst_count = xhci_get_burst_count(xhci, urb->dev, urb,
-                               total_packet_count);
-               residue = xhci_get_last_burst_packet_count(xhci,
-                               urb->dev, urb, total_packet_count);
+               if (total_pkt_count == 0)
+                       total_pkt_count++;
+               burst_count = xhci_get_burst_count(xhci, urb, total_pkt_count);
+               last_burst_pkt_count = xhci_get_last_burst_packet_count(xhci,
+                                                       urb, total_pkt_count);
 
                trbs_per_td = count_isoc_trbs_needed(xhci, urb, i);
 
@@ -3760,68 +3755,57 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                                return ret;
                        goto cleanup;
                }
-
                td = urb_priv->td[i];
+
+               /* use SIA as default, if frame id is used overwrite it */
+               sia_frame_id = TRB_SIA;
+               if (!(urb->transfer_flags & URB_ISO_ASAP) &&
+                   HCC_CFC(xhci->hcc_params)) {
+                       frame_id = xhci_get_isoc_frame_id(xhci, urb, i);
+                       if (frame_id >= 0)
+                               sia_frame_id = TRB_FRAME_ID(frame_id);
+               }
+               /*
+                * Set isoc specific data for the first TRB in a TD.
+                * Prevent HW from getting the TRBs by keeping the cycle state
+                * inverted in the first TDs isoc TRB.
+                */
+               field = TRB_TYPE(TRB_ISOC) |
+                       TRB_TLBPC(last_burst_pkt_count) |
+                       sia_frame_id |
+                       (i ? ep_ring->cycle_state : !start_cycle);
+
+               /* xhci 1.1 with ETE uses TD_Size field for TBC, old is Rsvdz */
+               if (!xep->use_extended_tbc)
+                       field |= TRB_TBC(burst_count);
+
+               /* fill the rest of the TRB fields, and remaining normal TRBs */
                for (j = 0; j < trbs_per_td; j++) {
-                       int frame_id = 0;
                        u32 remainder = 0;
-                       field = 0;
-
-                       if (first_trb) {
-                               field = TRB_TBC(burst_count) |
-                                       TRB_TLBPC(residue);
-                               /* Queue the isoc TRB */
-                               field |= TRB_TYPE(TRB_ISOC);
-
-                               /* Calculate Frame ID and SIA fields */
-                               if (!(urb->transfer_flags & URB_ISO_ASAP) &&
-                                               HCC_CFC(xhci->hcc_params)) {
-                                       frame_id = xhci_get_isoc_frame_id(xhci,
-                                                                         urb,
-                                                                         i);
-                                       if (frame_id >= 0)
-                                               field |= TRB_FRAME_ID(frame_id);
-                                       else
-                                               field |= TRB_SIA;
-                               } else
-                                       field |= TRB_SIA;
-
-                               if (i == 0) {
-                                       if (start_cycle == 0)
-                                               field |= 0x1;
-                               } else
-                                       field |= ep_ring->cycle_state;
-                               first_trb = false;
-                       } else {
-                               /* Queue other normal TRBs */
-                               field |= TRB_TYPE(TRB_NORMAL);
-                               field |= ep_ring->cycle_state;
-                       }
+
+                       /* only first TRB is isoc, overwrite otherwise */
+                       if (!first_trb)
+                               field = TRB_TYPE(TRB_NORMAL) |
+                                       ep_ring->cycle_state;
 
                        /* Only set interrupt on short packet for IN EPs */
                        if (usb_urb_dir_in(urb))
                                field |= TRB_ISP;
 
-                       /* Chain all the TRBs together; clear the chain bit in
-                        * the last TRB to indicate it's the last TRB in the
-                        * chain.
-                        */
+                       /* Set the chain bit for all except the last TRB  */
                        if (j < trbs_per_td - 1) {
-                               field |= TRB_CHAIN;
                                more_trbs_coming = true;
+                               field |= TRB_CHAIN;
                        } else {
+                               more_trbs_coming = false;
                                td->last_trb = ep_ring->enqueue;
                                field |= TRB_IOC;
-                               if (xhci->hci_version == 0x100 &&
-                                               !(xhci->quirks &
-                                                       XHCI_AVOID_BEI)) {
-                                       /* Set BEI bit except for the last td */
-                                       if (i < num_tds - 1)
-                                               field |= TRB_BEI;
-                               }
-                               more_trbs_coming = false;
+                               /* set BEI, except for the last TD */
+                               if (xhci->hci_version >= 0x100 &&
+                                   !(xhci->quirks & XHCI_AVOID_BEI) &&
+                                   i < num_tds - 1)
+                                       field |= TRB_BEI;
                        }
-
                        /* Calculate TRB length */
                        trb_buff_len = TRB_MAX_BUFF_SIZE -
                                (addr & ((1 << TRB_MAX_BUFF_SHIFT) - 1));
@@ -3834,9 +3818,15 @@ static int xhci_queue_isoc_tx(struct xhci_hcd *xhci, gfp_t mem_flags,
                                                   urb, trbs_per_td - j - 1);
 
                        length_field = TRB_LEN(trb_buff_len) |
-                               TRB_TD_SIZE(remainder) |
                                TRB_INTR_TARGET(0);
 
+                       /* xhci 1.1 with ETE uses TD Size field for TBC */
+                       if (first_trb && xep->use_extended_tbc)
+                               length_field |= TRB_TD_SIZE_TBC(burst_count);
+                       else
+                               length_field |= TRB_TD_SIZE(remainder);
+                       first_trb = false;
+
                        queue_trb(xhci, ep_ring, more_trbs_coming,
                                lower_32_bits(addr),
                                upper_32_bits(addr),
index 0c8087d..d51ee0c 100644 (file)
@@ -2086,6 +2086,7 @@ static unsigned int xhci_get_block_size(struct usb_device *udev)
        case USB_SPEED_HIGH:
                return HS_BLOCK;
        case USB_SPEED_SUPER:
+       case USB_SPEED_SUPER_PLUS:
                return SS_BLOCK;
        case USB_SPEED_UNKNOWN:
        case USB_SPEED_WIRELESS:
@@ -2211,7 +2212,7 @@ static int xhci_check_bw_table(struct xhci_hcd *xhci,
        unsigned int packets_remaining = 0;
        unsigned int i;
 
-       if (virt_dev->udev->speed == USB_SPEED_SUPER)
+       if (virt_dev->udev->speed >= USB_SPEED_SUPER)
                return xhci_check_ss_bw(xhci, virt_dev);
 
        if (virt_dev->udev->speed == USB_SPEED_HIGH) {
@@ -2412,7 +2413,7 @@ void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci,
        if (xhci_is_async_ep(ep_bw->type))
                return;
 
-       if (udev->speed == USB_SPEED_SUPER) {
+       if (udev->speed >= USB_SPEED_SUPER) {
                if (xhci_is_sync_in_ep(ep_bw->type))
                        xhci->devs[udev->slot_id]->bw_table->ss_bw_in -=
                                xhci_get_ss_bw_consumed(ep_bw);
@@ -2450,6 +2451,7 @@ void xhci_drop_ep_from_interval_table(struct xhci_hcd *xhci,
                interval_bw->overhead[HS_OVERHEAD_TYPE] -= 1;
                break;
        case USB_SPEED_SUPER:
+       case USB_SPEED_SUPER_PLUS:
        case USB_SPEED_UNKNOWN:
        case USB_SPEED_WIRELESS:
                /* Should never happen because only LS/FS/HS endpoints will get
@@ -2509,6 +2511,7 @@ static void xhci_add_ep_to_interval_table(struct xhci_hcd *xhci,
                interval_bw->overhead[HS_OVERHEAD_TYPE] += 1;
                break;
        case USB_SPEED_SUPER:
+       case USB_SPEED_SUPER_PLUS:
        case USB_SPEED_UNKNOWN:
        case USB_SPEED_WIRELESS:
                /* Should never happen because only LS/FS/HS endpoints will get
@@ -4897,6 +4900,7 @@ int xhci_gen_setup(struct usb_hcd *hcd, xhci_get_quirks_t get_quirks)
                if (xhci->sbrn == 0x31) {
                        xhci_info(xhci, "Host supports USB 3.1 Enhanced SuperSpeed\n");
                        hcd->speed = HCD_USB31;
+                       hcd->self.root_hub->speed = USB_SPEED_SUPER_PLUS;
                }
                /* xHCI private pointer was set in xhci_pci_probe for the second
                 * registered roothub.
index cc65138..e293e09 100644 (file)
@@ -232,7 +232,9 @@ struct xhci_op_regs {
  * disabled, or powered-off state.
  */
 #define CMD_PM_INDEX   (1 << 11)
-/* bits 12:31 are reserved (and should be preserved on writes). */
+/* bit 14 Extended TBC Enable, changes Isoc TRB fields to support larger TBC */
+#define CMD_ETE                (1 << 14)
+/* bits 15:31 are reserved (and should be preserved on writes). */
 
 /* IMAN - Interrupt Management Register */
 #define IMAN_IE                (1 << 1)
@@ -343,6 +345,7 @@ struct xhci_op_regs {
 #define        SLOT_SPEED_LS           (XDEV_LS << 10)
 #define        SLOT_SPEED_HS           (XDEV_HS << 10)
 #define        SLOT_SPEED_SS           (XDEV_SS << 10)
+#define        SLOT_SPEED_SSP          (XDEV_SSP << 10)
 /* Port Indicator Control */
 #define PORT_LED_OFF   (0 << 14)
 #define PORT_LED_AMBER (1 << 14)
@@ -748,8 +751,9 @@ struct xhci_ep_ctx {
 #define GET_MAX_PACKET(p)      ((p) & 0x7ff)
 
 /* tx_info bitmasks */
-#define AVG_TRB_LENGTH_FOR_EP(p)       ((p) & 0xffff)
-#define MAX_ESIT_PAYLOAD_FOR_EP(p)     (((p) & 0xffff) << 16)
+#define EP_AVG_TRB_LENGTH(p)           ((p) & 0xffff)
+#define EP_MAX_ESIT_PAYLOAD_LO(p)      (((p) & 0xffff) << 16)
+#define EP_MAX_ESIT_PAYLOAD_HI(p)      ((((p) >> 16) & 0xff) << 24)
 #define CTX_TO_MAX_ESIT_PAYLOAD(p)     (((p) >> 16) & 0xffff)
 
 /* deq bitmasks */
@@ -941,6 +945,8 @@ struct xhci_virt_ep {
        struct list_head        bw_endpoint_list;
        /* Isoch Frame ID checking storage */
        int                     next_frame_id;
+       /* Use new Isoch TRB layout needed for extended TBC support */
+       bool                    use_extended_tbc;
 };
 
 enum xhci_overhead_type {
@@ -1182,9 +1188,12 @@ enum xhci_setup_dev {
 #define        TRB_LEN(p)              ((p) & 0x1ffff)
 /* TD Size, packets remaining in this TD, bits 21:17 (5 bits, so max 31) */
 #define TRB_TD_SIZE(p)          (min((p), (u32)31) << 17)
+/* xhci 1.1 uses the TD_SIZE field for TBC if Extended TBC is enabled (ETE) */
+#define TRB_TD_SIZE_TBC(p)      (min((p), (u32)31) << 17)
 /* Interrupter Target - which MSI-X vector to target the completion event at */
 #define TRB_INTR_TARGET(p)     (((p) & 0x3ff) << 22)
 #define GET_INTR_TARGET(p)     (((p) >> 22) & 0x3ff)
+/* Total burst count field, Rsvdz on xhci 1.1 with Extended TBC enabled (ETE) */
 #define TRB_TBC(p)             (((p) & 0x3) << 7)
 #define TRB_TLBPC(p)           (((p) & 0xf) << 16)
 
index 23c7948..76350e4 100644 (file)
@@ -73,6 +73,8 @@ static const struct usb_device_id chaoskey_table[] = {
 };
 MODULE_DEVICE_TABLE(usb, chaoskey_table);
 
+static void chaos_read_callback(struct urb *urb);
+
 /* Driver-local specific stuff */
 struct chaoskey {
        struct usb_interface *interface;
@@ -80,7 +82,8 @@ struct chaoskey {
        struct mutex lock;
        struct mutex rng_lock;
        int open;                       /* open count */
-       int present;                    /* device not disconnected */
+       bool present;                   /* device not disconnected */
+       bool reading;                   /* ongoing IO */
        int size;                       /* size of buf */
        int valid;                      /* bytes of buf read */
        int used;                       /* bytes of buf consumed */
@@ -88,15 +91,19 @@ struct chaoskey {
        struct hwrng hwrng;             /* Embedded struct for hwrng */
        int hwrng_registered;           /* registered with hwrng API */
        wait_queue_head_t wait_q;       /* for timeouts */
+       struct urb *urb;                /* for performing IO */
        char *buf;
 };
 
 static void chaoskey_free(struct chaoskey *dev)
 {
-       usb_dbg(dev->interface, "free");
-       kfree(dev->name);
-       kfree(dev->buf);
-       kfree(dev);
+       if (dev) {
+               usb_dbg(dev->interface, "free");
+               usb_free_urb(dev->urb);
+               kfree(dev->name);
+               kfree(dev->buf);
+               kfree(dev);
+       }
 }
 
 static int chaoskey_probe(struct usb_interface *interface,
@@ -107,7 +114,7 @@ static int chaoskey_probe(struct usb_interface *interface,
        int i;
        int in_ep = -1;
        struct chaoskey *dev;
-       int result;
+       int result = -ENOMEM;
        int size;
 
        usb_dbg(interface, "probe %s-%s", udev->product, udev->serial);
@@ -142,14 +149,25 @@ static int chaoskey_probe(struct usb_interface *interface,
        dev = kzalloc(sizeof(struct chaoskey), GFP_KERNEL);
 
        if (dev == NULL)
-               return -ENOMEM;
+               goto out;
 
        dev->buf = kmalloc(size, GFP_KERNEL);
 
-       if (dev->buf == NULL) {
-               kfree(dev);
-               return -ENOMEM;
-       }
+       if (dev->buf == NULL)
+               goto out;
+
+       dev->urb = usb_alloc_urb(0, GFP_KERNEL);
+
+       if (!dev->urb)
+               goto out;
+
+       usb_fill_bulk_urb(dev->urb,
+               udev,
+               usb_rcvbulkpipe(udev, in_ep),
+               dev->buf,
+               size,
+               chaos_read_callback,
+               dev);
 
        /* Construct a name using the product and serial values. Each
         * device needs a unique name for the hwrng code
@@ -158,11 +176,8 @@ static int chaoskey_probe(struct usb_interface *interface,
        if (udev->product && udev->serial) {
                dev->name = kmalloc(strlen(udev->product) + 1 +
                                    strlen(udev->serial) + 1, GFP_KERNEL);
-               if (dev->name == NULL) {
-                       kfree(dev->buf);
-                       kfree(dev);
-                       return -ENOMEM;
-               }
+               if (dev->name == NULL)
+                       goto out;
 
                strcpy(dev->name, udev->product);
                strcat(dev->name, "-");
@@ -186,9 +201,7 @@ static int chaoskey_probe(struct usb_interface *interface,
        result = usb_register_dev(interface, &chaoskey_class);
        if (result) {
                usb_err(interface, "Unable to allocate minor number.");
-               usb_set_intfdata(interface, NULL);
-               chaoskey_free(dev);
-               return result;
+               goto out;
        }
 
        dev->hwrng.name = dev->name ? dev->name : chaoskey_driver.name;
@@ -215,6 +228,11 @@ static int chaoskey_probe(struct usb_interface *interface,
 
        usb_dbg(interface, "chaoskey probe success, size %d", dev->size);
        return 0;
+
+out:
+       usb_set_intfdata(interface, NULL);
+       chaoskey_free(dev);
+       return result;
 }
 
 static void chaoskey_disconnect(struct usb_interface *interface)
@@ -237,6 +255,7 @@ static void chaoskey_disconnect(struct usb_interface *interface)
        mutex_lock(&dev->lock);
 
        dev->present = 0;
+       usb_poison_urb(dev->urb);
 
        if (!dev->open) {
                mutex_unlock(&dev->lock);
@@ -311,14 +330,33 @@ static int chaoskey_release(struct inode *inode, struct file *file)
        return 0;
 }
 
+static void chaos_read_callback(struct urb *urb)
+{
+       struct chaoskey *dev = urb->context;
+       int status = urb->status;
+
+       usb_dbg(dev->interface, "callback status (%d)", status);
+
+       if (status == 0)
+               dev->valid = urb->actual_length;
+       else
+               dev->valid = 0;
+
+       dev->used = 0;
+
+       /* must be seen first before validity is announced */
+       smp_wmb();
+
+       dev->reading = false;
+       wake_up(&dev->wait_q);
+}
+
 /* Fill the buffer. Called with dev->lock held
  */
 static int _chaoskey_fill(struct chaoskey *dev)
 {
        DEFINE_WAIT(wait);
        int result;
-       int this_read;
-       struct usb_device *udev = interface_to_usbdev(dev->interface);
 
        usb_dbg(dev->interface, "fill");
 
@@ -343,21 +381,31 @@ static int _chaoskey_fill(struct chaoskey *dev)
                return result;
        }
 
-       result = usb_bulk_msg(udev,
-                             usb_rcvbulkpipe(udev, dev->in_ep),
-                             dev->buf, dev->size, &this_read,
-                             NAK_TIMEOUT);
+       dev->reading = true;
+       result = usb_submit_urb(dev->urb, GFP_KERNEL);
+       if (result < 0) {
+               result = usb_translate_errors(result);
+               dev->reading = false;
+               goto out;
+       }
+
+       result = wait_event_interruptible_timeout(
+               dev->wait_q,
+               !dev->reading,
+               NAK_TIMEOUT);
+
+       if (result < 0)
+               goto out;
 
+       if (result == 0)
+               result = -ETIMEDOUT;
+       else
+               result = dev->valid;
+out:
        /* Let the device go back to sleep eventually */
        usb_autopm_put_interface(dev->interface);
 
-       if (result == 0) {
-               dev->valid = this_read;
-               dev->used = 0;
-       }
-
-       usb_dbg(dev->interface, "bulk_msg result %d this_read %d",
-               result, this_read);
+       usb_dbg(dev->interface, "read %d bytes", dev->valid);
 
        return result;
 }
@@ -395,13 +443,7 @@ static ssize_t chaoskey_read(struct file *file,
                        goto bail;
                if (dev->valid == dev->used) {
                        result = _chaoskey_fill(dev);
-                       if (result) {
-                               mutex_unlock(&dev->lock);
-                               goto bail;
-                       }
-
-                       /* Read returned zero bytes */
-                       if (dev->used == dev->valid) {
+                       if (result < 0) {
                                mutex_unlock(&dev->lock);
                                goto bail;
                        }
@@ -435,6 +477,8 @@ bail:
                return read_count;
        }
        usb_dbg(dev->interface, "empty read, result %d", result);
+       if (result == -ETIMEDOUT)
+               result = -EAGAIN;
        return result;
 }
 
index 8efbaba..a22de52 100644 (file)
@@ -61,8 +61,8 @@
 /* Forward declarations / clean-up routines */
 
 #ifdef INCL_SISUSB_CON
-static int sisusb_first_vc = 0;
-static int sisusb_last_vc = 0;
+static int sisusb_first_vc;
+static int sisusb_last_vc;
 module_param_named(first, sisusb_first_vc, int, 0);
 module_param_named(last, sisusb_last_vc, int, 0);
 MODULE_PARM_DESC(first, "Number of first console to take over (1 - MAX_NR_CONSOLES)");
@@ -71,25 +71,19 @@ MODULE_PARM_DESC(last, "Number of last console to take over (1 - MAX_NR_CONSOLES
 
 static struct usb_driver sisusb_driver;
 
-static void
-sisusb_free_buffers(struct sisusb_usb_data *sisusb)
+static void sisusb_free_buffers(struct sisusb_usb_data *sisusb)
 {
        int i;
 
        for (i = 0; i < NUMOBUFS; i++) {
-               if (sisusb->obuf[i]) {
-                       kfree(sisusb->obuf[i]);
-                       sisusb->obuf[i] = NULL;
-               }
-       }
-       if (sisusb->ibuf) {
-               kfree(sisusb->ibuf);
-               sisusb->ibuf = NULL;
+               kfree(sisusb->obuf[i]);
+               sisusb->obuf[i] = NULL;
        }
+       kfree(sisusb->ibuf);
+       sisusb->ibuf = NULL;
 }
 
-static void
-sisusb_free_urbs(struct sisusb_usb_data *sisusb)
+static void sisusb_free_urbs(struct sisusb_usb_data *sisusb)
 {
        int i;
 
@@ -108,8 +102,7 @@ sisusb_free_urbs(struct sisusb_usb_data *sisusb)
 /* out-urb management */
 
 /* Return 1 if all free, 0 otherwise */
-static int
-sisusb_all_free(struct sisusb_usb_data *sisusb)
+static int sisusb_all_free(struct sisusb_usb_data *sisusb)
 {
        int i;
 
@@ -124,8 +117,7 @@ sisusb_all_free(struct sisusb_usb_data *sisusb)
 }
 
 /* Kill all busy URBs */
-static void
-sisusb_kill_all_busy(struct sisusb_usb_data *sisusb)
+static void sisusb_kill_all_busy(struct sisusb_usb_data *sisusb)
 {
        int i;
 
@@ -141,20 +133,17 @@ sisusb_kill_all_busy(struct sisusb_usb_data *sisusb)
 }
 
 /* Return 1 if ok, 0 if error (not all complete within timeout) */
-static int
-sisusb_wait_all_out_complete(struct sisusb_usb_data *sisusb)
+static int sisusb_wait_all_out_complete(struct sisusb_usb_data *sisusb)
 {
        int timeout = 5 * HZ, i = 1;
 
-       wait_event_timeout(sisusb->wait_q,
-                               (i = sisusb_all_free(sisusb)),
-                                timeout);
+       wait_event_timeout(sisusb->wait_q, (i = sisusb_all_free(sisusb)),
+                       timeout);
 
        return i;
 }
 
-static int
-sisusb_outurb_available(struct sisusb_usb_data *sisusb)
+static int sisusb_outurb_available(struct sisusb_usb_data *sisusb)
 {
        int i;
 
@@ -168,20 +157,17 @@ sisusb_outurb_available(struct sisusb_usb_data *sisusb)
        return -1;
 }
 
-static int
-sisusb_get_free_outbuf(struct sisusb_usb_data *sisusb)
+static int sisusb_get_free_outbuf(struct sisusb_usb_data *sisusb)
 {
        int i, timeout = 5 * HZ;
 
        wait_event_timeout(sisusb->wait_q,
-                               ((i = sisusb_outurb_available(sisusb)) >= 0),
-                               timeout);
+                       ((i = sisusb_outurb_available(sisusb)) >= 0), timeout);
 
        return i;
 }
 
-static int
-sisusb_alloc_outbuf(struct sisusb_usb_data *sisusb)
+static int sisusb_alloc_outbuf(struct sisusb_usb_data *sisusb)
 {
        int i;
 
@@ -193,8 +179,7 @@ sisusb_alloc_outbuf(struct sisusb_usb_data *sisusb)
        return i;
 }
 
-static void
-sisusb_free_outbuf(struct sisusb_usb_data *sisusb, int index)
+static void sisusb_free_outbuf(struct sisusb_usb_data *sisusb, int index)
 {
        if ((index >= 0) && (index < sisusb->numobufs))
                sisusb->urbstatus[index] &= ~SU_URB_ALLOC;
@@ -202,8 +187,7 @@ sisusb_free_outbuf(struct sisusb_usb_data *sisusb, int index)
 
 /* completion callback */
 
-static void
-sisusb_bulk_completeout(struct urb *urb)
+static void sisusb_bulk_completeout(struct urb *urb)
 {
        struct sisusb_urb_context *context = urb->context;
        struct sisusb_usb_data *sisusb;
@@ -225,9 +209,9 @@ sisusb_bulk_completeout(struct urb *urb)
        wake_up(&sisusb->wait_q);
 }
 
-static int
-sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe, void *data,
-               int len, int *actual_length, int timeout, unsigned int tflags)
+static int sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index,
+               unsigned int pipe, void *data, int len, int *actual_length,
+               int timeout, unsigned int tflags)
 {
        struct urb *urb = sisusb->sisurbout[index];
        int retval, byteswritten = 0;
@@ -236,14 +220,15 @@ sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe,
        urb->transfer_flags = 0;
 
        usb_fill_bulk_urb(urb, sisusb->sisusb_dev, pipe, data, len,
-               sisusb_bulk_completeout, &sisusb->urbout_context[index]);
+                       sisusb_bulk_completeout,
+                       &sisusb->urbout_context[index]);
 
        urb->transfer_flags |= tflags;
        urb->actual_length = 0;
 
        /* Set up context */
        sisusb->urbout_context[index].actual_length = (timeout) ?
-                                               NULL : actual_length;
+                       NULL : actual_length;
 
        /* Declare this urb/buffer in use */
        sisusb->urbstatus[index] |= SU_URB_BUSY;
@@ -254,8 +239,8 @@ sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe,
        /* If OK, and if timeout > 0, wait for completion */
        if ((retval == 0) && timeout) {
                wait_event_timeout(sisusb->wait_q,
-                                  (!(sisusb->urbstatus[index] & SU_URB_BUSY)),
-                                  timeout);
+                               (!(sisusb->urbstatus[index] & SU_URB_BUSY)),
+                               timeout);
                if (sisusb->urbstatus[index] & SU_URB_BUSY) {
                        /* URB timed out... kill it and report error */
                        usb_kill_urb(urb);
@@ -277,8 +262,7 @@ sisusb_bulkout_msg(struct sisusb_usb_data *sisusb, int index, unsigned int pipe,
 
 /* completion callback */
 
-static void
-sisusb_bulk_completein(struct urb *urb)
+static void sisusb_bulk_completein(struct urb *urb)
 {
        struct sisusb_usb_data *sisusb = urb->context;
 
@@ -289,9 +273,9 @@ sisusb_bulk_completein(struct urb *urb)
        wake_up(&sisusb->wait_q);
 }
 
-static int
-sisusb_bulkin_msg(struct sisusb_usb_data *sisusb, unsigned int pipe, void *data,
-       int len, int *actual_length, int timeout, unsigned int tflags)
+static int sisusb_bulkin_msg(struct sisusb_usb_data *sisusb,
+               unsigned int pipe, void *data, int len,
+               int *actual_length, int timeout, unsigned int tflags)
 {
        struct urb *urb = sisusb->sisurbin;
        int retval, readbytes = 0;
@@ -375,7 +359,7 @@ static int sisusb_send_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len,
 
        do {
                passsize = thispass = (sisusb->obufsize < count) ?
-                                               sisusb->obufsize : count;
+                               sisusb->obufsize : count;
 
                if (index < 0)
                        index = sisusb_get_free_outbuf(sisusb);
@@ -405,14 +389,9 @@ static int sisusb_send_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len,
                        if (!sisusb->sisusb_dev)
                                return -ENODEV;
 
-                       result = sisusb_bulkout_msg(sisusb,
-                                               index,
-                                               pipe,
-                                               buffer,
-                                               thispass,
-                                               &transferred_len,
-                                               async ? 0 : 5 * HZ,
-                                               tflags);
+                       result = sisusb_bulkout_msg(sisusb, index, pipe,
+                                       buffer, thispass, &transferred_len,
+                                       async ? 0 : 5 * HZ, tflags);
 
                        if (result == -ETIMEDOUT) {
 
@@ -500,13 +479,8 @@ static int sisusb_recv_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len,
 
                thispass = (bufsize < count) ? bufsize : count;
 
-               result = sisusb_bulkin_msg(sisusb,
-                                          pipe,
-                                          buffer,
-                                          thispass,
-                                          &transferred_len,
-                                          5 * HZ,
-                                          tflags);
+               result = sisusb_bulkin_msg(sisusb, pipe, buffer, thispass,
+                               &transferred_len, 5 * HZ, tflags);
 
                if (transferred_len)
                        thispass = transferred_len;
@@ -549,7 +523,7 @@ static int sisusb_recv_bulk_msg(struct sisusb_usb_data *sisusb, int ep, int len,
 }
 
 static int sisusb_send_packet(struct sisusb_usb_data *sisusb, int len,
-                                               struct sisusb_packet *packet)
+               struct sisusb_packet *packet)
 {
        int ret;
        ssize_t bytes_transferred = 0;
@@ -585,8 +559,7 @@ static int sisusb_send_packet(struct sisusb_usb_data *sisusb, int len,
 }
 
 static int sisusb_send_bridge_packet(struct sisusb_usb_data *sisusb, int len,
-                                       struct sisusb_packet *packet,
-                                       unsigned int tflags)
+               struct sisusb_packet *packet, unsigned int tflags)
 {
        int ret;
        ssize_t bytes_transferred = 0;
@@ -634,7 +607,7 @@ static int sisusb_send_bridge_packet(struct sisusb_usb_data *sisusb, int len,
  */
 
 static int sisusb_write_memio_byte(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u8 data)
+               u32 addr, u8 data)
 {
        struct sisusb_packet packet;
        int ret;
@@ -647,7 +620,7 @@ static int sisusb_write_memio_byte(struct sisusb_usb_data *sisusb, int type,
 }
 
 static int sisusb_write_memio_word(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u16 data)
+               u32 addr, u16 data)
 {
        struct sisusb_packet packet;
        int ret = 0;
@@ -655,36 +628,36 @@ static int sisusb_write_memio_word(struct sisusb_usb_data *sisusb, int type,
        packet.address = addr & ~3;
 
        switch (addr & 3) {
-               case 0:
-                       packet.header = (type << 6) | 0x0003;
-                       packet.data   = (u32)data;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 1:
-                       packet.header = (type << 6) | 0x0006;
-                       packet.data   = (u32)data << 8;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 2:
-                       packet.header = (type << 6) | 0x000c;
-                       packet.data   = (u32)data << 16;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 3:
-                       packet.header = (type << 6) | 0x0008;
-                       packet.data   = (u32)data << 24;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       packet.header = (type << 6) | 0x0001;
-                       packet.address = (addr & ~3) + 4;
-                       packet.data   = (u32)data >> 8;
-                       ret |= sisusb_send_packet(sisusb, 10, &packet);
+       case 0:
+               packet.header = (type << 6) | 0x0003;
+               packet.data   = (u32)data;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 1:
+               packet.header = (type << 6) | 0x0006;
+               packet.data   = (u32)data << 8;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 2:
+               packet.header = (type << 6) | 0x000c;
+               packet.data   = (u32)data << 16;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 3:
+               packet.header = (type << 6) | 0x0008;
+               packet.data   = (u32)data << 24;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               packet.header = (type << 6) | 0x0001;
+               packet.address = (addr & ~3) + 4;
+               packet.data   = (u32)data >> 8;
+               ret |= sisusb_send_packet(sisusb, 10, &packet);
        }
 
        return ret;
 }
 
 static int sisusb_write_memio_24bit(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u32 data)
+               u32 addr, u32 data)
 {
        struct sisusb_packet packet;
        int ret = 0;
@@ -692,40 +665,40 @@ static int sisusb_write_memio_24bit(struct sisusb_usb_data *sisusb, int type,
        packet.address = addr & ~3;
 
        switch (addr & 3) {
-               case 0:
-                       packet.header  = (type << 6) | 0x0007;
-                       packet.data    = data & 0x00ffffff;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 1:
-                       packet.header  = (type << 6) | 0x000e;
-                       packet.data    = data << 8;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 2:
-                       packet.header  = (type << 6) | 0x000c;
-                       packet.data    = data << 16;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       packet.header  = (type << 6) | 0x0001;
-                       packet.address = (addr & ~3) + 4;
-                       packet.data    = (data >> 16) & 0x00ff;
-                       ret |= sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 3:
-                       packet.header  = (type << 6) | 0x0008;
-                       packet.data    = data << 24;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       packet.header  = (type << 6) | 0x0003;
-                       packet.address = (addr & ~3) + 4;
-                       packet.data    = (data >> 8) & 0xffff;
-                       ret |= sisusb_send_packet(sisusb, 10, &packet);
+       case 0:
+               packet.header  = (type << 6) | 0x0007;
+               packet.data    = data & 0x00ffffff;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 1:
+               packet.header  = (type << 6) | 0x000e;
+               packet.data    = data << 8;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 2:
+               packet.header  = (type << 6) | 0x000c;
+               packet.data    = data << 16;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               packet.header  = (type << 6) | 0x0001;
+               packet.address = (addr & ~3) + 4;
+               packet.data    = (data >> 16) & 0x00ff;
+               ret |= sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 3:
+               packet.header  = (type << 6) | 0x0008;
+               packet.data    = data << 24;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               packet.header  = (type << 6) | 0x0003;
+               packet.address = (addr & ~3) + 4;
+               packet.data    = (data >> 8) & 0xffff;
+               ret |= sisusb_send_packet(sisusb, 10, &packet);
        }
 
        return ret;
 }
 
 static int sisusb_write_memio_long(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u32 data)
+               u32 addr, u32 data)
 {
        struct sisusb_packet packet;
        int ret = 0;
@@ -733,37 +706,37 @@ static int sisusb_write_memio_long(struct sisusb_usb_data *sisusb, int type,
        packet.address = addr & ~3;
 
        switch (addr & 3) {
-               case 0:
-                       packet.header  = (type << 6) | 0x000f;
-                       packet.data    = data;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 1:
-                       packet.header  = (type << 6) | 0x000e;
-                       packet.data    = data << 8;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       packet.header  = (type << 6) | 0x0001;
-                       packet.address = (addr & ~3) + 4;
-                       packet.data    = data >> 24;
-                       ret |= sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 2:
-                       packet.header  = (type << 6) | 0x000c;
-                       packet.data    = data << 16;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       packet.header  = (type << 6) | 0x0003;
-                       packet.address = (addr & ~3) + 4;
-                       packet.data    = data >> 16;
-                       ret |= sisusb_send_packet(sisusb, 10, &packet);
-                       break;
-               case 3:
-                       packet.header  = (type << 6) | 0x0008;
-                       packet.data    = data << 24;
-                       ret = sisusb_send_packet(sisusb, 10, &packet);
-                       packet.header  = (type << 6) | 0x0007;
-                       packet.address = (addr & ~3) + 4;
-                       packet.data    = data >> 8;
-                       ret |= sisusb_send_packet(sisusb, 10, &packet);
+       case 0:
+               packet.header  = (type << 6) | 0x000f;
+               packet.data    = data;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 1:
+               packet.header  = (type << 6) | 0x000e;
+               packet.data    = data << 8;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               packet.header  = (type << 6) | 0x0001;
+               packet.address = (addr & ~3) + 4;
+               packet.data    = data >> 24;
+               ret |= sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 2:
+               packet.header  = (type << 6) | 0x000c;
+               packet.data    = data << 16;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               packet.header  = (type << 6) | 0x0003;
+               packet.address = (addr & ~3) + 4;
+               packet.data    = data >> 16;
+               ret |= sisusb_send_packet(sisusb, 10, &packet);
+               break;
+       case 3:
+               packet.header  = (type << 6) | 0x0008;
+               packet.data    = data << 24;
+               ret = sisusb_send_packet(sisusb, 10, &packet);
+               packet.header  = (type << 6) | 0x0007;
+               packet.address = (addr & ~3) + 4;
+               packet.data    = data >> 8;
+               ret |= sisusb_send_packet(sisusb, 10, &packet);
        }
 
        return ret;
@@ -780,13 +753,12 @@ static int sisusb_write_memio_long(struct sisusb_usb_data *sisusb, int type,
  */
 
 static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
-                               char *kernbuffer, int length,
-                               const char __user *userbuffer, int index,
-                               ssize_t *bytes_written)
+               char *kernbuffer, int length, const char __user *userbuffer,
+               int index, ssize_t *bytes_written)
 {
        struct sisusb_packet packet;
        int  ret = 0;
-       static int msgcount = 0;
+       static int msgcount;
        u8   swap8, fromkern = kernbuffer ? 1 : 0;
        u16  swap16;
        u32  swap32, flag = (length >> 28) & 1;
@@ -803,9 +775,7 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
        length &= 0x00ffffff;
 
        while (length) {
-
-           switch (length) {
-
+               switch (length) {
                case 1:
                        if (userbuffer) {
                                if (get_user(swap8, (u8 __user *)userbuffer))
@@ -813,9 +783,8 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
                        } else
                                swap8 = kernbuffer[0];
 
-                       ret = sisusb_write_memio_byte(sisusb,
-                                                       SISUSB_TYPE_MEM,
-                                                       addr, swap8);
+                       ret = sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM,
+                                       addr, swap8);
 
                        if (!ret)
                                (*bytes_written)++;
@@ -829,10 +798,8 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
                        } else
                                swap16 = *((u16 *)kernbuffer);
 
-                       ret = sisusb_write_memio_word(sisusb,
-                                                       SISUSB_TYPE_MEM,
-                                                       addr,
-                                                       swap16);
+                       ret = sisusb_write_memio_word(sisusb, SISUSB_TYPE_MEM,
+                                       addr, swap16);
 
                        if (!ret)
                                (*bytes_written) += 2;
@@ -863,10 +830,8 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
                                         kernbuffer[0];
 #endif
 
-                       ret = sisusb_write_memio_24bit(sisusb,
-                                                       SISUSB_TYPE_MEM,
-                                                       addr,
-                                                       swap32);
+                       ret = sisusb_write_memio_24bit(sisusb, SISUSB_TYPE_MEM,
+                                       addr, swap32);
 
                        if (!ret)
                                (*bytes_written) += 3;
@@ -880,10 +845,8 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
                        } else
                                swap32 = *((u32 *)kernbuffer);
 
-                       ret = sisusb_write_memio_long(sisusb,
-                                                       SISUSB_TYPE_MEM,
-                                                       addr,
-                                                       swap32);
+                       ret = sisusb_write_memio_long(sisusb, SISUSB_TYPE_MEM,
+                                       addr, swap32);
                        if (!ret)
                                (*bytes_written) += 4;
 
@@ -892,103 +855,106 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
                default:
                        if ((length & ~3) > 0x10000) {
 
-                          packet.header  = 0x001f;
-                          packet.address = 0x000001d4;
-                          packet.data    = addr;
-                          ret = sisusb_send_bridge_packet(sisusb, 10,
-                                                               &packet, 0);
-                          packet.header  = 0x001f;
-                          packet.address = 0x000001d0;
-                          packet.data    = (length & ~3);
-                          ret |= sisusb_send_bridge_packet(sisusb, 10,
-                                                               &packet, 0);
-                          packet.header  = 0x001f;
-                          packet.address = 0x000001c0;
-                          packet.data    = flag | 0x16;
-                          ret |= sisusb_send_bridge_packet(sisusb, 10,
-                                                               &packet, 0);
-                          if (userbuffer) {
-                               ret |= sisusb_send_bulk_msg(sisusb,
+                               packet.header  = 0x001f;
+                               packet.address = 0x000001d4;
+                               packet.data    = addr;
+                               ret = sisusb_send_bridge_packet(sisusb, 10,
+                                               &packet, 0);
+                               packet.header  = 0x001f;
+                               packet.address = 0x000001d0;
+                               packet.data    = (length & ~3);
+                               ret |= sisusb_send_bridge_packet(sisusb, 10,
+                                               &packet, 0);
+                               packet.header  = 0x001f;
+                               packet.address = 0x000001c0;
+                               packet.data    = flag | 0x16;
+                               ret |= sisusb_send_bridge_packet(sisusb, 10,
+                                               &packet, 0);
+                               if (userbuffer) {
+                                       ret |= sisusb_send_bulk_msg(sisusb,
                                                        SISUSB_EP_GFX_LBULK_OUT,
                                                        (length & ~3),
                                                        NULL, userbuffer, 0,
                                                        bytes_written, 0, 1);
-                               userbuffer += (*bytes_written);
-                          } else if (fromkern) {
-                               ret |= sisusb_send_bulk_msg(sisusb,
+                                       userbuffer += (*bytes_written);
+                               } else if (fromkern) {
+                                       ret |= sisusb_send_bulk_msg(sisusb,
                                                        SISUSB_EP_GFX_LBULK_OUT,
                                                        (length & ~3),
                                                        kernbuffer, NULL, 0,
                                                        bytes_written, 0, 1);
-                               kernbuffer += (*bytes_written);
-                          } else {
-                       ret |= sisusb_send_bulk_msg(sisusb,
+                                       kernbuffer += (*bytes_written);
+                               } else {
+                                       ret |= sisusb_send_bulk_msg(sisusb,
                                                        SISUSB_EP_GFX_LBULK_OUT,
                                                        (length & ~3),
                                                        NULL, NULL, index,
                                                        bytes_written, 0, 1);
-                               kernbuffer += ((*bytes_written) &
-                                               (sisusb->obufsize-1));
-                          }
+                                       kernbuffer += ((*bytes_written) &
+                                                       (sisusb->obufsize-1));
+                               }
 
                        } else {
 
-                          packet.header  = 0x001f;
-                          packet.address = 0x00000194;
-                          packet.data    = addr;
-                          ret = sisusb_send_bridge_packet(sisusb, 10,
-                                                               &packet, 0);
-                          packet.header  = 0x001f;
-                          packet.address = 0x00000190;
-                          packet.data    = (length & ~3);
-                          ret |= sisusb_send_bridge_packet(sisusb, 10,
-                                                               &packet, 0);
-                          if (sisusb->flagb0 != 0x16) {
                                packet.header  = 0x001f;
-                               packet.address = 0x00000180;
-                               packet.data    = flag | 0x16;
+                               packet.address = 0x00000194;
+                               packet.data    = addr;
+                               ret = sisusb_send_bridge_packet(sisusb, 10,
+                                               &packet, 0);
+                               packet.header  = 0x001f;
+                               packet.address = 0x00000190;
+                               packet.data    = (length & ~3);
                                ret |= sisusb_send_bridge_packet(sisusb, 10,
-                                                               &packet, 0);
-                               sisusb->flagb0 = 0x16;
-                          }
-                          if (userbuffer) {
-                               ret |= sisusb_send_bulk_msg(sisusb,
+                                               &packet, 0);
+                               if (sisusb->flagb0 != 0x16) {
+                                       packet.header  = 0x001f;
+                                       packet.address = 0x00000180;
+                                       packet.data    = flag | 0x16;
+                                       ret |= sisusb_send_bridge_packet(sisusb,
+                                                       10, &packet, 0);
+                                       sisusb->flagb0 = 0x16;
+                               }
+                               if (userbuffer) {
+                                       ret |= sisusb_send_bulk_msg(sisusb,
                                                        SISUSB_EP_GFX_BULK_OUT,
                                                        (length & ~3),
                                                        NULL, userbuffer, 0,
                                                        bytes_written, 0, 1);
-                               userbuffer += (*bytes_written);
-                          } else if (fromkern) {
-                               ret |= sisusb_send_bulk_msg(sisusb,
+                                       userbuffer += (*bytes_written);
+                               } else if (fromkern) {
+                                       ret |= sisusb_send_bulk_msg(sisusb,
                                                        SISUSB_EP_GFX_BULK_OUT,
                                                        (length & ~3),
                                                        kernbuffer, NULL, 0,
                                                        bytes_written, 0, 1);
-                               kernbuffer += (*bytes_written);
-                          } else {
-                               ret |= sisusb_send_bulk_msg(sisusb,
+                                       kernbuffer += (*bytes_written);
+                               } else {
+                                       ret |= sisusb_send_bulk_msg(sisusb,
                                                        SISUSB_EP_GFX_BULK_OUT,
                                                        (length & ~3),
                                                        NULL, NULL, index,
                                                        bytes_written, 0, 1);
-                               kernbuffer += ((*bytes_written) &
-                                               (sisusb->obufsize-1));
-                          }
+                                       kernbuffer += ((*bytes_written) &
+                                                       (sisusb->obufsize-1));
+                               }
                        }
                        if (ret) {
                                msgcount++;
                                if (msgcount < 500)
-                                       dev_err(&sisusb->sisusb_dev->dev, "Wrote %zd of %d bytes, error %d\n",
-                                               *bytes_written, length, ret);
+                                       dev_err(&sisusb->sisusb_dev->dev,
+                                                       "Wrote %zd of %d bytes, error %d\n",
+                                                       *bytes_written, length,
+                                                       ret);
                                else if (msgcount == 500)
-                                       dev_err(&sisusb->sisusb_dev->dev, "Too many errors, logging stopped\n");
+                                       dev_err(&sisusb->sisusb_dev->dev,
+                                                       "Too many errors, logging stopped\n");
                        }
                        addr += (*bytes_written);
                        length -= (*bytes_written);
-           }
+               }
 
-           if (ret)
-               break;
+               if (ret)
+                       break;
 
        }
 
@@ -1000,7 +966,7 @@ static int sisusb_write_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
  */
 
 static int sisusb_read_memio_byte(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u8 *data)
+               u32 addr, u8 *data)
 {
        struct sisusb_packet packet;
        int ret;
@@ -1014,7 +980,7 @@ static int sisusb_read_memio_byte(struct sisusb_usb_data *sisusb, int type,
 }
 
 static int sisusb_read_memio_word(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u16 *data)
+               u32 addr, u16 *data)
 {
        struct sisusb_packet packet;
        int ret = 0;
@@ -1024,36 +990,36 @@ static int sisusb_read_memio_word(struct sisusb_usb_data *sisusb, int type,
        packet.address = addr & ~3;
 
        switch (addr & 3) {
-               case 0:
-                       packet.header = (type << 6) | 0x0003;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = (u16)(packet.data);
-                       break;
-               case 1:
-                       packet.header = (type << 6) | 0x0006;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = (u16)(packet.data >> 8);
-                       break;
-               case 2:
-                       packet.header = (type << 6) | 0x000c;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = (u16)(packet.data >> 16);
-                       break;
-               case 3:
-                       packet.header = (type << 6) | 0x0008;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = (u16)(packet.data >> 24);
-                       packet.header = (type << 6) | 0x0001;
-                       packet.address = (addr & ~3) + 4;
-                       ret |= sisusb_send_packet(sisusb, 6, &packet);
-                       *data |= (u16)(packet.data << 8);
+       case 0:
+               packet.header = (type << 6) | 0x0003;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = (u16)(packet.data);
+               break;
+       case 1:
+               packet.header = (type << 6) | 0x0006;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = (u16)(packet.data >> 8);
+               break;
+       case 2:
+               packet.header = (type << 6) | 0x000c;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = (u16)(packet.data >> 16);
+               break;
+       case 3:
+               packet.header = (type << 6) | 0x0008;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = (u16)(packet.data >> 24);
+               packet.header = (type << 6) | 0x0001;
+               packet.address = (addr & ~3) + 4;
+               ret |= sisusb_send_packet(sisusb, 6, &packet);
+               *data |= (u16)(packet.data << 8);
        }
 
        return ret;
 }
 
 static int sisusb_read_memio_24bit(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u32 *data)
+               u32 addr, u32 *data)
 {
        struct sisusb_packet packet;
        int ret = 0;
@@ -1061,40 +1027,40 @@ static int sisusb_read_memio_24bit(struct sisusb_usb_data *sisusb, int type,
        packet.address = addr & ~3;
 
        switch (addr & 3) {
-               case 0:
-                       packet.header  = (type << 6) | 0x0007;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data & 0x00ffffff;
-                       break;
-               case 1:
-                       packet.header  = (type << 6) | 0x000e;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data >> 8;
-                       break;
-               case 2:
-                       packet.header  = (type << 6) | 0x000c;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data >> 16;
-                       packet.header  = (type << 6) | 0x0001;
-                       packet.address = (addr & ~3) + 4;
-                       ret |= sisusb_send_packet(sisusb, 6, &packet);
-                       *data |= ((packet.data & 0xff) << 16);
-                       break;
-               case 3:
-                       packet.header  = (type << 6) | 0x0008;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data >> 24;
-                       packet.header  = (type << 6) | 0x0003;
-                       packet.address = (addr & ~3) + 4;
-                       ret |= sisusb_send_packet(sisusb, 6, &packet);
-                       *data |= ((packet.data & 0xffff) << 8);
+       case 0:
+               packet.header  = (type << 6) | 0x0007;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data & 0x00ffffff;
+               break;
+       case 1:
+               packet.header  = (type << 6) | 0x000e;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data >> 8;
+               break;
+       case 2:
+               packet.header  = (type << 6) | 0x000c;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data >> 16;
+               packet.header  = (type << 6) | 0x0001;
+               packet.address = (addr & ~3) + 4;
+               ret |= sisusb_send_packet(sisusb, 6, &packet);
+               *data |= ((packet.data & 0xff) << 16);
+               break;
+       case 3:
+               packet.header  = (type << 6) | 0x0008;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data >> 24;
+               packet.header  = (type << 6) | 0x0003;
+               packet.address = (addr & ~3) + 4;
+               ret |= sisusb_send_packet(sisusb, 6, &packet);
+               *data |= ((packet.data & 0xffff) << 8);
        }
 
        return ret;
 }
 
 static int sisusb_read_memio_long(struct sisusb_usb_data *sisusb, int type,
-                                                       u32 addr, u32 *data)
+               u32 addr, u32 *data)
 {
        struct sisusb_packet packet;
        int ret = 0;
@@ -1102,45 +1068,45 @@ static int sisusb_read_memio_long(struct sisusb_usb_data *sisusb, int type,
        packet.address = addr & ~3;
 
        switch (addr & 3) {
-               case 0:
-                       packet.header  = (type << 6) | 0x000f;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data;
-                       break;
-               case 1:
-                       packet.header  = (type << 6) | 0x000e;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data >> 8;
-                       packet.header  = (type << 6) | 0x0001;
-                       packet.address = (addr & ~3) + 4;
-                       ret |= sisusb_send_packet(sisusb, 6, &packet);
-                       *data |= (packet.data << 24);
-                       break;
-               case 2:
-                       packet.header  = (type << 6) | 0x000c;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data >> 16;
-                       packet.header  = (type << 6) | 0x0003;
-                       packet.address = (addr & ~3) + 4;
-                       ret |= sisusb_send_packet(sisusb, 6, &packet);
-                       *data |= (packet.data << 16);
-                       break;
-               case 3:
-                       packet.header  = (type << 6) | 0x0008;
-                       ret = sisusb_send_packet(sisusb, 6, &packet);
-                       *data = packet.data >> 24;
-                       packet.header  = (type << 6) | 0x0007;
-                       packet.address = (addr & ~3) + 4;
-                       ret |= sisusb_send_packet(sisusb, 6, &packet);
-                       *data |= (packet.data << 8);
+       case 0:
+               packet.header  = (type << 6) | 0x000f;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data;
+               break;
+       case 1:
+               packet.header  = (type << 6) | 0x000e;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data >> 8;
+               packet.header  = (type << 6) | 0x0001;
+               packet.address = (addr & ~3) + 4;
+               ret |= sisusb_send_packet(sisusb, 6, &packet);
+               *data |= (packet.data << 24);
+               break;
+       case 2:
+               packet.header  = (type << 6) | 0x000c;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data >> 16;
+               packet.header  = (type << 6) | 0x0003;
+               packet.address = (addr & ~3) + 4;
+               ret |= sisusb_send_packet(sisusb, 6, &packet);
+               *data |= (packet.data << 16);
+               break;
+       case 3:
+               packet.header  = (type << 6) | 0x0008;
+               ret = sisusb_send_packet(sisusb, 6, &packet);
+               *data = packet.data >> 24;
+               packet.header  = (type << 6) | 0x0007;
+               packet.address = (addr & ~3) + 4;
+               ret |= sisusb_send_packet(sisusb, 6, &packet);
+               *data |= (packet.data << 8);
        }
 
        return ret;
 }
 
 static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
-                               char *kernbuffer, int length,
-                               char __user *userbuffer, ssize_t *bytes_read)
+               char *kernbuffer, int length, char __user *userbuffer,
+               ssize_t *bytes_read)
 {
        int ret = 0;
        char buf[4];
@@ -1152,34 +1118,27 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
        length &= 0x00ffffff;
 
        while (length) {
-
-           switch (length) {
-
+               switch (length) {
                case 1:
-
                        ret |= sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM,
-                                                               addr, &buf[0]);
+                                       addr, &buf[0]);
                        if (!ret) {
                                (*bytes_read)++;
                                if (userbuffer) {
-                                       if (put_user(buf[0],
-                                               (u8 __user *)userbuffer)) {
+                                       if (put_user(buf[0], (u8 __user *)userbuffer))
                                                return -EFAULT;
-                                       }
-                               } else {
+                               } else
                                        kernbuffer[0] = buf[0];
-                               }
                        }
                        return ret;
 
                case 2:
                        ret |= sisusb_read_memio_word(sisusb, SISUSB_TYPE_MEM,
-                                                               addr, &swap16);
+                                       addr, &swap16);
                        if (!ret) {
                                (*bytes_read) += 2;
                                if (userbuffer) {
-                                       if (put_user(swap16,
-                                               (u16 __user *)userbuffer))
+                                       if (put_user(swap16, (u16 __user *)userbuffer))
                                                return -EFAULT;
                                } else {
                                        *((u16 *)kernbuffer) = swap16;
@@ -1189,7 +1148,7 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
 
                case 3:
                        ret |= sisusb_read_memio_24bit(sisusb, SISUSB_TYPE_MEM,
-                                                               addr, &swap32);
+                                       addr, &swap32);
                        if (!ret) {
                                (*bytes_read) += 3;
 #ifdef __BIG_ENDIAN
@@ -1202,7 +1161,8 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
                                buf[0] = swap32 & 0xff;
 #endif
                                if (userbuffer) {
-                                       if (copy_to_user(userbuffer, &buf[0], 3))
+                                       if (copy_to_user(userbuffer,
+                                                       &buf[0], 3))
                                                return -EFAULT;
                                } else {
                                        kernbuffer[0] = buf[0];
@@ -1214,12 +1174,11 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
 
                default:
                        ret |= sisusb_read_memio_long(sisusb, SISUSB_TYPE_MEM,
-                                                               addr, &swap32);
+                                       addr, &swap32);
                        if (!ret) {
                                (*bytes_read) += 4;
                                if (userbuffer) {
-                                       if (put_user(swap32,
-                                               (u32 __user *)userbuffer))
+                                       if (put_user(swap32, (u32 __user *)userbuffer))
                                                return -EFAULT;
 
                                        userbuffer += 4;
@@ -1230,10 +1189,9 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
                                addr += 4;
                                length -= 4;
                        }
-           }
-
-           if (ret)
-               break;
+               }
+               if (ret)
+                       break;
        }
 
        return ret;
@@ -1242,40 +1200,39 @@ static int sisusb_read_mem_bulk(struct sisusb_usb_data *sisusb, u32 addr,
 /* High level: Gfx (indexed) register access */
 
 #ifdef INCL_SISUSB_CON
-int
-sisusb_setreg(struct sisusb_usb_data *sisusb, int port, u8 data)
+int sisusb_setreg(struct sisusb_usb_data *sisusb, int port, u8 data)
 {
        return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
 }
 
-int
-sisusb_getreg(struct sisusb_usb_data *sisusb, int port, u8 *data)
+int sisusb_getreg(struct sisusb_usb_data *sisusb, int port, u8 *data)
 {
        return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, port, data);
 }
 #endif
 
-int
-sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 data)
+int sisusb_setidxreg(struct sisusb_usb_data *sisusb, int port,
+               u8 index, u8 data)
 {
        int ret;
+
        ret = sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, index);
        ret |= sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port + 1, data);
        return ret;
 }
 
-int
-sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port, u8 index, u8 *data)
+int sisusb_getidxreg(struct sisusb_usb_data *sisusb, int port,
+               u8 index, u8 *data)
 {
        int ret;
+
        ret = sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, index);
        ret |= sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, port + 1, data);
        return ret;
 }
 
-int
-sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx,
-                                                       u8 myand, u8 myor)
+int sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx,
+               u8 myand, u8 myor)
 {
        int ret;
        u8 tmp;
@@ -1288,12 +1245,12 @@ sisusb_setidxregandor(struct sisusb_usb_data *sisusb, int port, u8 idx,
        return ret;
 }
 
-static int
-sisusb_setidxregmask(struct sisusb_usb_data *sisusb, int port, u8 idx,
-                                                       u8 data, u8 mask)
+static int sisusb_setidxregmask(struct sisusb_usb_data *sisusb,
+               int port, u8 idx, u8 data, u8 mask)
 {
        int ret;
        u8 tmp;
+
        ret = sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, port, idx);
        ret |= sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, port + 1, &tmp);
        tmp &= ~(mask);
@@ -1302,75 +1259,76 @@ sisusb_setidxregmask(struct sisusb_usb_data *sisusb, int port, u8 idx,
        return ret;
 }
 
-int
-sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port, u8 index, u8 myor)
+int sisusb_setidxregor(struct sisusb_usb_data *sisusb, int port,
+               u8 index, u8 myor)
 {
-       return(sisusb_setidxregandor(sisusb, port, index, 0xff, myor));
+       return sisusb_setidxregandor(sisusb, port, index, 0xff, myor);
 }
 
-int
-sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port, u8 idx, u8 myand)
+int sisusb_setidxregand(struct sisusb_usb_data *sisusb, int port,
+               u8 idx, u8 myand)
 {
-       return(sisusb_setidxregandor(sisusb, port, idx, myand, 0x00));
+       return sisusb_setidxregandor(sisusb, port, idx, myand, 0x00);
 }
 
 /* Write/read video ram */
 
 #ifdef INCL_SISUSB_CON
-int
-sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data)
+int sisusb_writeb(struct sisusb_usb_data *sisusb, u32 adr, u8 data)
 {
-       return(sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data));
+       return sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data);
 }
 
-int
-sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data)
+int sisusb_readb(struct sisusb_usb_data *sisusb, u32 adr, u8 *data)
 {
-       return(sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data));
+       return sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM, adr, data);
 }
 
-int
-sisusb_copy_memory(struct sisusb_usb_data *sisusb, char *src,
-                       u32 dest, int length, size_t *bytes_written)
+int sisusb_copy_memory(struct sisusb_usb_data *sisusb, char *src,
+               u32 dest, int length, size_t *bytes_written)
 {
-       return(sisusb_write_mem_bulk(sisusb, dest, src, length, NULL, 0, bytes_written));
+       return sisusb_write_mem_bulk(sisusb, dest, src, length,
+                       NULL, 0, bytes_written);
 }
 
 #ifdef SISUSBENDIANTEST
-int
-sisusb_read_memory(struct sisusb_usb_data *sisusb, char *dest,
-                       u32 src, int length, size_t *bytes_written)
+int sisusb_read_memory(struct sisusb_usb_data *sisusb, char *dest,
+               u32 src, int length, size_t *bytes_written)
 {
-       return(sisusb_read_mem_bulk(sisusb, src, dest, length, NULL, bytes_written));
+       return sisusb_read_mem_bulk(sisusb, src, dest, length,
+                       NULL, bytes_written);
 }
 #endif
 #endif
 
 #ifdef SISUSBENDIANTEST
-static void
-sisusb_testreadwrite(struct sisusb_usb_data *sisusb)
-{
-    static char srcbuffer[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
-    char destbuffer[10];
-    size_t dummy;
-    int i,j;
-
-    sisusb_copy_memory(sisusb, srcbuffer, sisusb->vrambase, 7, &dummy);
-
-    for(i = 1; i <= 7; i++) {
-        dev_dbg(&sisusb->sisusb_dev->dev, "sisusb: rwtest %d bytes\n", i);
-       sisusb_read_memory(sisusb, destbuffer, sisusb->vrambase, i, &dummy);
-       for(j = 0; j < i; j++) {
-            dev_dbg(&sisusb->sisusb_dev->dev, "rwtest read[%d] = %x\n", j, destbuffer[j]);
+static void sisusb_testreadwrite(struct sisusb_usb_data *sisusb)
+{
+       static char srcbuffer[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77 };
+       char destbuffer[10];
+       size_t dummy;
+       int i, j;
+
+       sisusb_copy_memory(sisusb, srcbuffer, sisusb->vrambase, 7, &dummy);
+
+       for (i = 1; i <= 7; i++) {
+               dev_dbg(&sisusb->sisusb_dev->dev,
+                               "sisusb: rwtest %d bytes\n", i);
+               sisusb_read_memory(sisusb, destbuffer, sisusb->vrambase,
+                               i, &dummy);
+               for (j = 0; j < i; j++) {
+                       dev_dbg(&sisusb->sisusb_dev->dev,
+                                       "rwtest read[%d] = %x\n",
+                                       j, destbuffer[j]);
+               }
        }
-    }
 }
 #endif
 
 /* access pci config registers (reg numbers 0, 4, 8, etc) */
 
-static int
-sisusb_write_pci_config(struct sisusb_usb_data *sisusb, int regnum, u32 data)
+static int sisusb_write_pci_config(struct sisusb_usb_data *sisusb,
+               int regnum, u32 data)
 {
        struct sisusb_packet packet;
        int ret;
@@ -1382,8 +1340,8 @@ sisusb_write_pci_config(struct sisusb_usb_data *sisusb, int regnum, u32 data)
        return ret;
 }
 
-static int
-sisusb_read_pci_config(struct sisusb_usb_data *sisusb, int regnum, u32 *data)
+static int sisusb_read_pci_config(struct sisusb_usb_data *sisusb,
+               int regnum, u32 *data)
 {
        struct sisusb_packet packet;
        int ret;
@@ -1397,8 +1355,8 @@ sisusb_read_pci_config(struct sisusb_usb_data *sisusb, int regnum, u32 *data)
 
 /* Clear video RAM */
 
-static int
-sisusb_clear_vram(struct sisusb_usb_data *sisusb, u32 address, int length)
+static int sisusb_clear_vram(struct sisusb_usb_data *sisusb,
+               u32 address, int length)
 {
        int ret, i;
        ssize_t j;
@@ -1416,7 +1374,8 @@ sisusb_clear_vram(struct sisusb_usb_data *sisusb, u32 address, int length)
                return 0;
 
        /* allocate free buffer/urb and clear the buffer */
-       if ((i = sisusb_alloc_outbuf(sisusb)) < 0)
+       i = sisusb_alloc_outbuf(sisusb);
+       if (i < 0)
                return -EBUSY;
 
        memset(sisusb->obuf[i], 0, sisusb->obufsize);
@@ -1437,20 +1396,19 @@ sisusb_clear_vram(struct sisusb_usb_data *sisusb, u32 address, int length)
  * a defined mode (640x480@60Hz)
  */
 
-#define GETREG(r,d)     sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, r, d)
-#define SETREG(r,d)    sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, r, d)
-#define SETIREG(r,i,d) sisusb_setidxreg(sisusb, r, i, d)
-#define GETIREG(r,i,d)  sisusb_getidxreg(sisusb, r, i, d)
-#define SETIREGOR(r,i,o)       sisusb_setidxregor(sisusb, r, i, o)
-#define SETIREGAND(r,i,a)      sisusb_setidxregand(sisusb, r, i, a)
-#define SETIREGANDOR(r,i,a,o)  sisusb_setidxregandor(sisusb, r, i, a, o)
-#define READL(a,d)     sisusb_read_memio_long(sisusb, SISUSB_TYPE_MEM, a, d)
-#define WRITEL(a,d)    sisusb_write_memio_long(sisusb, SISUSB_TYPE_MEM, a, d)
-#define READB(a,d)     sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM, a, d)
-#define WRITEB(a,d)    sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM, a, d)
-
-static int
-sisusb_triggersr16(struct sisusb_usb_data *sisusb, u8 ramtype)
+#define GETREG(r, d) sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO, r, d)
+#define SETREG(r, d) sisusb_write_memio_byte(sisusb, SISUSB_TYPE_IO, r, d)
+#define SETIREG(r, i, d) sisusb_setidxreg(sisusb, r, i, d)
+#define GETIREG(r, i, d) sisusb_getidxreg(sisusb, r, i, d)
+#define SETIREGOR(r, i, o) sisusb_setidxregor(sisusb, r, i, o)
+#define SETIREGAND(r, i, a) sisusb_setidxregand(sisusb, r, i, a)
+#define SETIREGANDOR(r, i, a, o) sisusb_setidxregandor(sisusb, r, i, a, o)
+#define READL(a, d) sisusb_read_memio_long(sisusb, SISUSB_TYPE_MEM, a, d)
+#define WRITEL(a, d) sisusb_write_memio_long(sisusb, SISUSB_TYPE_MEM, a, d)
+#define READB(a, d) sisusb_read_memio_byte(sisusb, SISUSB_TYPE_MEM, a, d)
+#define WRITEB(a, d) sisusb_write_memio_byte(sisusb, SISUSB_TYPE_MEM, a, d)
+
+static int sisusb_triggersr16(struct sisusb_usb_data *sisusb, u8 ramtype)
 {
        int ret;
        u8 tmp8;
@@ -1480,8 +1438,8 @@ sisusb_triggersr16(struct sisusb_usb_data *sisusb, u8 ramtype)
        return ret;
 }
 
-static int
-sisusb_getbuswidth(struct sisusb_usb_data *sisusb, int *bw, int *chab)
+static int sisusb_getbuswidth(struct sisusb_usb_data *sisusb,
+               int *bw, int *chab)
 {
        int ret;
        u8  ramtype, done = 0;
@@ -1526,7 +1484,7 @@ sisusb_getbuswidth(struct sisusb_usb_data *sisusb, int *bw, int *chab)
                }
                if ((t1 != 0x456789ab) || (t0 != 0x01234567)) {
                        *chab = 1; *bw = 64;
-                       ret |= SETIREGANDOR(SISSR, 0x14, 0xfc,0x01);
+                       ret |= SETIREGANDOR(SISSR, 0x14, 0xfc, 0x01);
 
                        ret |= sisusb_triggersr16(sisusb, ramtype);
                        ret |= WRITEL(ramptr +  0, 0x89abcdef);
@@ -1593,8 +1551,7 @@ sisusb_getbuswidth(struct sisusb_usb_data *sisusb, int *bw, int *chab)
        return ret;
 }
 
-static int
-sisusb_verify_mclk(struct sisusb_usb_data *sisusb)
+static int sisusb_verify_mclk(struct sisusb_usb_data *sisusb)
 {
        int ret = 0;
        u32 ramptr = SISUSB_PCI_MEMBASE;
@@ -1622,10 +1579,8 @@ sisusb_verify_mclk(struct sisusb_usb_data *sisusb)
        return ret;
 }
 
-static int
-sisusb_set_rank(struct sisusb_usb_data *sisusb, int *iret, int index,
-                       u8 rankno, u8 chab, const u8 dramtype[][5],
-                       int bw)
+static int sisusb_set_rank(struct sisusb_usb_data *sisusb, int *iret,
+               int index, u8 rankno, u8 chab, const u8 dramtype[][5], int bw)
 {
        int ret = 0, ranksize;
        u8 tmp;
@@ -1641,7 +1596,9 @@ sisusb_set_rank(struct sisusb_usb_data *sisusb, int *iret, int index,
                return ret;
 
        tmp = 0;
-       while ((ranksize >>= 1) > 0) tmp += 0x10;
+       while ((ranksize >>= 1) > 0)
+               tmp += 0x10;
+
        tmp |= ((rankno - 1) << 2);
        tmp |= ((bw / 64) & 0x02);
        tmp |= (chab & 0x01);
@@ -1654,8 +1611,8 @@ sisusb_set_rank(struct sisusb_usb_data *sisusb, int *iret, int index,
        return ret;
 }
 
-static int
-sisusb_check_rbc(struct sisusb_usb_data *sisusb, int *iret, u32 inc, int testn)
+static int sisusb_check_rbc(struct sisusb_usb_data *sisusb, int *iret,
+               u32 inc, int testn)
 {
        int ret = 0, i;
        u32 j, tmp;
@@ -1669,7 +1626,9 @@ sisusb_check_rbc(struct sisusb_usb_data *sisusb, int *iret, u32 inc, int testn)
 
        for (i = 0, j = 0; i < testn; i++) {
                ret |= READL(sisusb->vrambase + j, &tmp);
-               if (tmp != j) return ret;
+               if (tmp != j)
+                       return ret;
+
                j += inc;
        }
 
@@ -1677,9 +1636,8 @@ sisusb_check_rbc(struct sisusb_usb_data *sisusb, int *iret, u32 inc, int testn)
        return ret;
 }
 
-static int
-sisusb_check_ranks(struct sisusb_usb_data *sisusb, int *iret, int rankno,
-                                       int idx, int bw, const u8 rtype[][5])
+static int sisusb_check_ranks(struct sisusb_usb_data *sisusb,
+               int *iret, int rankno, int idx, int bw, const u8 rtype[][5])
 {
        int ret = 0, i, i2ret;
        u32 inc;
@@ -1687,10 +1645,8 @@ sisusb_check_ranks(struct sisusb_usb_data *sisusb, int *iret, int rankno,
        *iret = 0;
 
        for (i = rankno; i >= 1; i--) {
-               inc = 1 << (rtype[idx][2] +
-                           rtype[idx][1] +
-                           rtype[idx][0] +
-                           bw / 64 + i);
+               inc = 1 << (rtype[idx][2] + rtype[idx][1] + rtype[idx][0] +
+                               bw / 64 + i);
                ret |= sisusb_check_rbc(sisusb, &i2ret, inc, 2);
                if (!i2ret)
                        return ret;
@@ -1710,9 +1666,8 @@ sisusb_check_ranks(struct sisusb_usb_data *sisusb, int *iret, int rankno,
        return ret;
 }
 
-static int
-sisusb_get_sdram_size(struct sisusb_usb_data *sisusb, int *iret, int bw,
-                                                               int chab)
+static int sisusb_get_sdram_size(struct sisusb_usb_data *sisusb, int *iret,
+               int bw, int chab)
 {
        int ret = 0, i2ret = 0, i, j;
        static const u8 sdramtype[13][5] = {
@@ -1736,13 +1691,13 @@ sisusb_get_sdram_size(struct sisusb_usb_data *sisusb, int *iret, int bw,
        for (i = 0; i < 13; i++) {
                ret |= SETIREGANDOR(SISSR, 0x13, 0x80, sdramtype[i][4]);
                for (j = 2; j > 0; j--) {
-                       ret |= sisusb_set_rank(sisusb, &i2ret, i, j,
-                                               chab, sdramtype, bw);
+                       ret |= sisusb_set_rank(sisusb, &i2ret, i, j, chab,
+                                       sdramtype, bw);
                        if (!i2ret)
                                continue;
 
-                       ret |= sisusb_check_ranks(sisusb, &i2ret, j, i,
-                                               bw, sdramtype);
+                       ret |= sisusb_check_ranks(sisusb, &i2ret, j, i, bw,
+                                       sdramtype);
                        if (i2ret) {
                                *iret = 0;      /* ram size found */
                                return ret;
@@ -1753,8 +1708,8 @@ sisusb_get_sdram_size(struct sisusb_usb_data *sisusb, int *iret, int bw,
        return ret;
 }
 
-static int
-sisusb_setup_screen(struct sisusb_usb_data *sisusb, int clrall, int drwfr)
+static int sisusb_setup_screen(struct sisusb_usb_data *sisusb,
+               int clrall, int drwfr)
 {
        int ret = 0;
        u32 address;
@@ -1775,47 +1730,47 @@ sisusb_setup_screen(struct sisusb_usb_data *sisusb, int clrall, int drwfr)
                for (i = 0; i < modex; i++) {
                        address = sisusb->vrambase + (i * bpp);
                        ret |= sisusb_write_memio_word(sisusb, SISUSB_TYPE_MEM,
-                                                       address, 0xf100);
+                                       address, 0xf100);
                        address += (modex * (modey-1) * bpp);
                        ret |= sisusb_write_memio_word(sisusb, SISUSB_TYPE_MEM,
-                                                       address, 0xf100);
+                                       address, 0xf100);
                }
                for (i = 0; i < modey; i++) {
                        address = sisusb->vrambase + ((i * modex) * bpp);
                        ret |= sisusb_write_memio_word(sisusb, SISUSB_TYPE_MEM,
-                                                       address, 0xf100);
+                                       address, 0xf100);
                        address += ((modex - 1) * bpp);
                        ret |= sisusb_write_memio_word(sisusb, SISUSB_TYPE_MEM,
-                                                       address, 0xf100);
+                                       address, 0xf100);
                }
        }
 
        return ret;
 }
 
-static int
-sisusb_set_default_mode(struct sisusb_usb_data *sisusb, int touchengines)
+static int sisusb_set_default_mode(struct sisusb_usb_data *sisusb,
+               int touchengines)
 {
        int ret = 0, i, j, modex, modey, bpp, du;
        u8 sr31, cr63, tmp8;
        static const char attrdata[] = {
-               0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
-               0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
-               0x01,0x00,0x00,0x00
+               0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+               0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+               0x01, 0x00, 0x00, 0x00
        };
        static const char crtcrdata[] = {
-               0x5f,0x4f,0x50,0x82,0x54,0x80,0x0b,0x3e,
-               0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,
-               0xea,0x8c,0xdf,0x28,0x40,0xe7,0x04,0xa3,
+               0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e,
+               0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+               0xea, 0x8c, 0xdf, 0x28, 0x40, 0xe7, 0x04, 0xa3,
                0xff
        };
        static const char grcdata[] = {
-               0x00,0x00,0x00,0x00,0x00,0x40,0x05,0x0f,
+               0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f,
                0xff
        };
        static const char crtcdata[] = {
-               0x5f,0x4f,0x4f,0x83,0x55,0x81,0x0b,0x3e,
-               0xe9,0x8b,0xdf,0xe8,0x0c,0x00,0x00,0x05,
+               0x5f, 0x4f, 0x4f, 0x83, 0x55, 0x81, 0x0b, 0x3e,
+               0xe9, 0x8b, 0xdf, 0xe8, 0x0c, 0x00, 0x00, 0x05,
                0x00
        };
 
@@ -1858,28 +1813,32 @@ sisusb_set_default_mode(struct sisusb_usb_data *sisusb, int touchengines)
        SETIREGAND(SISSR, 0x37, 0xfe);
        SETREG(SISMISCW, 0xef);         /* sync */
        SETIREG(SISCR, 0x11, 0x00);     /* crtc */
-       for (j = 0x00, i = 0; i <= 7; i++, j++) {
+       for (j = 0x00, i = 0; i <= 7; i++, j++)
                SETIREG(SISCR, j, crtcdata[i]);
-       }
-       for (j = 0x10; i <= 10; i++, j++) {
+
+       for (j = 0x10; i <= 10; i++, j++)
                SETIREG(SISCR, j, crtcdata[i]);
-       }
-       for (j = 0x15; i <= 12; i++, j++) {
+
+       for (j = 0x15; i <= 12; i++, j++)
                SETIREG(SISCR, j, crtcdata[i]);
-       }
-       for (j = 0x0A; i <= 15; i++, j++) {
+
+       for (j = 0x0A; i <= 15; i++, j++)
                SETIREG(SISSR, j, crtcdata[i]);
-       }
+
        SETIREG(SISSR, 0x0E, (crtcdata[16] & 0xE0));
        SETIREGANDOR(SISCR, 0x09, 0x5f, ((crtcdata[16] & 0x01) << 5));
        SETIREG(SISCR, 0x14, 0x4f);
        du = (modex / 16) * (bpp * 2);  /* offset/pitch */
-       if (modex % 16) du += bpp;
+       if (modex % 16)
+               du += bpp;
+
        SETIREGANDOR(SISSR, 0x0e, 0xf0, ((du >> 8) & 0x0f));
        SETIREG(SISCR, 0x13, (du & 0xff));
        du <<= 5;
        tmp8 = du >> 8;
-       if (du & 0xff) tmp8++;
+       if (du & 0xff)
+               tmp8++;
+
        SETIREG(SISSR, 0x10, tmp8);
        SETIREG(SISSR, 0x31, 0x00);     /* VCLK */
        SETIREG(SISSR, 0x2b, 0x1b);
@@ -1925,8 +1884,7 @@ sisusb_set_default_mode(struct sisusb_usb_data *sisusb, int touchengines)
        return ret;
 }
 
-static int
-sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
+static int sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
 {
        int ret = 0, i, j, bw, chab, iret, retry = 3;
        u8 tmp8, ramtype;
@@ -1970,7 +1928,8 @@ sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
                ret |= GETREG(SISMISCR, &tmp8);
                ret |= SETREG(SISMISCW, (tmp8 | 0x01));
 
-               if (ret) continue;
+               if (ret)
+                       continue;
 
                /* Reset registers */
                ret |= SETIREGAND(SISCR, 0x5b, 0xdf);
@@ -1979,23 +1938,23 @@ sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
 
                ret |= SETREG(SISMISCW, 0x67);
 
-               for (i = 0x06; i <= 0x1f; i++) {
+               for (i = 0x06; i <= 0x1f; i++)
                        ret |= SETIREG(SISSR, i, 0x00);
-               }
-               for (i = 0x21; i <= 0x27; i++) {
+
+               for (i = 0x21; i <= 0x27; i++)
                        ret |= SETIREG(SISSR, i, 0x00);
-               }
-               for (i = 0x31; i <= 0x3d; i++) {
+
+               for (i = 0x31; i <= 0x3d; i++)
                        ret |= SETIREG(SISSR, i, 0x00);
-               }
-               for (i = 0x12; i <= 0x1b; i++) {
+
+               for (i = 0x12; i <= 0x1b; i++)
                        ret |= SETIREG(SISSR, i, 0x00);
-               }
-               for (i = 0x79; i <= 0x7c; i++) {
+
+               for (i = 0x79; i <= 0x7c; i++)
                        ret |= SETIREG(SISCR, i, 0x00);
-               }
 
-               if (ret) continue;
+               if (ret)
+                       continue;
 
                ret |= SETIREG(SISCR, 0x63, 0x80);
 
@@ -2013,13 +1972,16 @@ sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
                ret |= SETIREG(SISSR, 0x07, 0x18);
                ret |= SETIREG(SISSR, 0x11, 0x0f);
 
-               if (ret) continue;
+               if (ret)
+                       continue;
 
                for (i = 0x15, j = 0; i <= 0x1b; i++, j++) {
-                       ret |= SETIREG(SISSR, i, ramtypetable1[(j*4) + ramtype]);
+                       ret |= SETIREG(SISSR, i,
+                                       ramtypetable1[(j*4) + ramtype]);
                }
                for (i = 0x40, j = 0; i <= 0x44; i++, j++) {
-                       ret |= SETIREG(SISCR, i, ramtypetable2[(j*4) + ramtype]);
+                       ret |= SETIREG(SISCR, i,
+                                       ramtypetable2[(j*4) + ramtype]);
                }
 
                ret |= SETIREG(SISCR, 0x49, 0xaa);
@@ -2036,7 +1998,8 @@ sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
 
                ret |= SETIREGAND(SISCAP, 0x3f, 0xef);
 
-               if (ret) continue;
+               if (ret)
+                       continue;
 
                ret |= SETIREG(SISPART1, 0x00, 0x00);
 
@@ -2058,7 +2021,8 @@ sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
                ret |= SETIREG(SISSR, 0x32, 0x11);
                ret |= SETIREG(SISSR, 0x33, 0x00);
 
-               if (ret) continue;
+               if (ret)
+                       continue;
 
                ret |= SETIREG(SISCR, 0x83, 0x00);
 
@@ -2080,13 +2044,15 @@ sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
                if (ramtype <= 1) {
                        ret |= sisusb_get_sdram_size(sisusb, &iret, bw, chab);
                        if (iret) {
-                               dev_err(&sisusb->sisusb_dev->dev,"RAM size detection failed, assuming 8MB video RAM\n");
-                               ret |= SETIREG(SISSR,0x14,0x31);
+                               dev_err(&sisusb->sisusb_dev->dev,
+                                               "RAM size detection failed, assuming 8MB video RAM\n");
+                               ret |= SETIREG(SISSR, 0x14, 0x31);
                                /* TODO */
                        }
                } else {
-                       dev_err(&sisusb->sisusb_dev->dev, "DDR RAM device found, assuming 8MB video RAM\n");
-                       ret |= SETIREG(SISSR,0x14,0x31);
+                       dev_err(&sisusb->sisusb_dev->dev,
+                                       "DDR RAM device found, assuming 8MB video RAM\n");
+                       ret |= SETIREG(SISSR, 0x14, 0x31);
                        /* *** TODO *** */
                }
 
@@ -2117,8 +2083,7 @@ sisusb_init_gfxcore(struct sisusb_usb_data *sisusb)
 #undef READL
 #undef WRITEL
 
-static void
-sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
+static void sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
 {
        u8 tmp8, tmp82, ramtype;
        int bw = 0;
@@ -2127,7 +2092,7 @@ sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
        static const char ram_dynamictype[4] = {'D', 'G', 'D', 'G'};
        static const int busSDR[4]  = {64, 64, 128, 128};
        static const int busDDR[4]  = {32, 32,  64,  64};
-       static const int busDDRA[4] = {64+32, 64+32 , (64+32)*2, (64+32)*2};
+       static const int busDDRA[4] = {64+32, 64+32, (64+32)*2, (64+32)*2};
 
        sisusb_getidxreg(sisusb, SISSR, 0x14, &tmp8);
        sisusb_getidxreg(sisusb, SISSR, 0x15, &tmp82);
@@ -2135,35 +2100,38 @@ sisusb_get_ramconfig(struct sisusb_usb_data *sisusb)
        sisusb->vramsize = (1 << ((tmp8 & 0xf0) >> 4)) * 1024 * 1024;
        ramtype &= 0x03;
        switch ((tmp8 >> 2) & 0x03) {
-       case 0: ramtypetext1 = "1 ch/1 r";
-               if (tmp82 & 0x10) {
+       case 0:
+               ramtypetext1 = "1 ch/1 r";
+               if (tmp82 & 0x10)
                        bw = 32;
-               } else {
+               else
                        bw = busSDR[(tmp8 & 0x03)];
-               }
+
                break;
-       case 1: ramtypetext1 = "1 ch/2 r";
+       case 1:
+               ramtypetext1 = "1 ch/2 r";
                sisusb->vramsize <<= 1;
                bw = busSDR[(tmp8 & 0x03)];
                break;
-       case 2: ramtypetext1 = "asymmeric";
+       case 2:
+               ramtypetext1 = "asymmeric";
                sisusb->vramsize += sisusb->vramsize/2;
                bw = busDDRA[(tmp8 & 0x03)];
                break;
-       case 3: ramtypetext1 = "2 channel";
+       case 3:
+               ramtypetext1 = "2 channel";
                sisusb->vramsize <<= 1;
                bw = busDDR[(tmp8 & 0x03)];
                break;
        }
 
-
-       dev_info(&sisusb->sisusb_dev->dev, "%dMB %s %cDR S%cRAM, bus width %d\n",
-                sisusb->vramsize >> 20, ramtypetext1,
-                ram_datarate[ramtype], ram_dynamictype[ramtype], bw);
+       dev_info(&sisusb->sisusb_dev->dev,
+                       "%dMB %s %cDR S%cRAM, bus width %d\n",
+                       sisusb->vramsize >> 20, ramtypetext1,
+                       ram_datarate[ramtype], ram_dynamictype[ramtype], bw);
 }
 
-static int
-sisusb_do_init_gfxdevice(struct sisusb_usb_data *sisusb)
+static int sisusb_do_init_gfxdevice(struct sisusb_usb_data *sisusb)
 {
        struct sisusb_packet packet;
        int ret;
@@ -2241,8 +2209,7 @@ sisusb_do_init_gfxdevice(struct sisusb_usb_data *sisusb)
  * of the graphics board.
  */
 
-static int
-sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen)
+static int sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen)
 {
        int ret = 0, test = 0;
        u32 tmp32;
@@ -2250,16 +2217,25 @@ sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen)
        if (sisusb->devinit == 1) {
                /* Read PCI BARs and see if they have been set up */
                ret |= sisusb_read_pci_config(sisusb, 0x10, &tmp32);
-               if (ret) return ret;
-               if ((tmp32 & 0xfffffff0) == SISUSB_PCI_MEMBASE) test++;
+               if (ret)
+                       return ret;
+
+               if ((tmp32 & 0xfffffff0) == SISUSB_PCI_MEMBASE)
+                       test++;
 
                ret |= sisusb_read_pci_config(sisusb, 0x14, &tmp32);
-               if (ret) return ret;
-               if ((tmp32 & 0xfffffff0) == SISUSB_PCI_MMIOBASE) test++;
+               if (ret)
+                       return ret;
+
+               if ((tmp32 & 0xfffffff0) == SISUSB_PCI_MMIOBASE)
+                       test++;
 
                ret |= sisusb_read_pci_config(sisusb, 0x18, &tmp32);
-               if (ret) return ret;
-               if ((tmp32 & 0xfffffff0) == SISUSB_PCI_IOPORTBASE) test++;
+               if (ret)
+                       return ret;
+
+               if ((tmp32 & 0xfffffff0) == SISUSB_PCI_IOPORTBASE)
+                       test++;
        }
 
        /* No? So reset the device */
@@ -2289,20 +2265,20 @@ sisusb_init_gfxdevice(struct sisusb_usb_data *sisusb, int initscreen)
 #ifdef INCL_SISUSB_CON
 
 /* Set up default text mode:
  - Set text mode (0x03)
  - Upload default font
  - Upload user font (if available)
-*/
* - Set text mode (0x03)
* - Upload default font
* - Upload user font (if available)
+ */
 
-int
-sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
+int sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
 {
        int ret = 0, slot = sisusb->font_slot, i;
        const struct font_desc *myfont;
        u8 *tempbuf;
        u16 *tempbufb;
        size_t written;
-       static const char bootstring[] = "SiSUSB VGA text console, (C) 2005 Thomas Winischhofer.";
+       static const char bootstring[] =
+               "SiSUSB VGA text console, (C) 2005 Thomas Winischhofer.";
        static const char bootlogo[] = "(o_ //\\ V_/_";
 
        /* sisusb->lock is down */
@@ -2328,7 +2304,8 @@ sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
                memcpy(tempbuf + (i * 32), myfont->data + (i * 16), 16);
 
        /* Upload default font */
-       ret = sisusbcon_do_font_op(sisusb, 1, 0, tempbuf, 8192, 0, 1, NULL, 16, 0);
+       ret = sisusbcon_do_font_op(sisusb, 1, 0, tempbuf, 8192,
+                       0, 1, NULL, 16, 0);
 
        vfree(tempbuf);
 
@@ -2366,7 +2343,7 @@ sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
                                *(tempbufb++) = 0x0700 | bootstring[i++];
 
                        ret |= sisusb_copy_memory(sisusb, tempbuf,
-                               sisusb->vrambase, 8192, &written);
+                                       sisusb->vrambase, 8192, &written);
 
                        vfree(tempbuf);
 
@@ -2375,12 +2352,13 @@ sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
        } else if (sisusb->scrbuf) {
 
                ret |= sisusb_copy_memory(sisusb, (char *)sisusb->scrbuf,
-                               sisusb->vrambase, sisusb->scrbuf_size, &written);
+                               sisusb->vrambase, sisusb->scrbuf_size,
+                               &written);
 
        }
 
        if (sisusb->sisusb_cursor_size_from >= 0 &&
-           sisusb->sisusb_cursor_size_to >= 0) {
+                       sisusb->sisusb_cursor_size_to >= 0) {
                sisusb_setidxreg(sisusb, SISCR, 0x0a,
                                sisusb->sisusb_cursor_size_from);
                sisusb_setidxregandor(sisusb, SISCR, 0x0b, 0xe0,
@@ -2392,7 +2370,8 @@ sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
        }
 
        slot = sisusb->sisusb_cursor_loc;
-       if(slot < 0) slot = 0;
+       if (slot < 0)
+               slot = 0;
 
        sisusb->sisusb_cursor_loc = -1;
        sisusb->bad_cursor_pos = 1;
@@ -2413,22 +2392,19 @@ sisusb_reset_text_mode(struct sisusb_usb_data *sisusb, int init)
 
 /* fops */
 
-static int
-sisusb_open(struct inode *inode, struct file *file)
+static int sisusb_open(struct inode *inode, struct file *file)
 {
        struct sisusb_usb_data *sisusb;
        struct usb_interface *interface;
        int subminor = iminor(inode);
 
        interface = usb_find_interface(&sisusb_driver, subminor);
-       if (!interface) {
+       if (!interface)
                return -ENODEV;
-       }
 
        sisusb = usb_get_intfdata(interface);
-       if (!sisusb) {
+       if (!sisusb)
                return -ENODEV;
-       }
 
        mutex_lock(&sisusb->lock);
 
@@ -2444,15 +2420,17 @@ sisusb_open(struct inode *inode, struct file *file)
 
        if (!sisusb->devinit) {
                if (sisusb->sisusb_dev->speed == USB_SPEED_HIGH ||
-                   sisusb->sisusb_dev->speed == USB_SPEED_SUPER) {
+                               sisusb->sisusb_dev->speed == USB_SPEED_SUPER) {
                        if (sisusb_init_gfxdevice(sisusb, 0)) {
                                mutex_unlock(&sisusb->lock);
-                               dev_err(&sisusb->sisusb_dev->dev, "Failed to initialize device\n");
+                               dev_err(&sisusb->sisusb_dev->dev,
+                                               "Failed to initialize device\n");
                                return -EIO;
                        }
                } else {
                        mutex_unlock(&sisusb->lock);
-                       dev_err(&sisusb->sisusb_dev->dev, "Device not attached to USB 2.0 hub\n");
+                       dev_err(&sisusb->sisusb_dev->dev,
+                                       "Device not attached to USB 2.0 hub\n");
                        return -EIO;
                }
        }
@@ -2469,8 +2447,7 @@ sisusb_open(struct inode *inode, struct file *file)
        return 0;
 }
 
-void
-sisusb_delete(struct kref *kref)
+void sisusb_delete(struct kref *kref)
 {
        struct sisusb_usb_data *sisusb = to_sisusb_dev(kref);
 
@@ -2488,8 +2465,7 @@ sisusb_delete(struct kref *kref)
        kfree(sisusb);
 }
 
-static int
-sisusb_release(struct inode *inode, struct file *file)
+static int sisusb_release(struct inode *inode, struct file *file)
 {
        struct sisusb_usb_data *sisusb;
 
@@ -2516,8 +2492,8 @@ sisusb_release(struct inode *inode, struct file *file)
        return 0;
 }
 
-static ssize_t
-sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
+static ssize_t sisusb_read(struct file *file, char __user *buffer,
+               size_t count, loff_t *ppos)
 {
        struct sisusb_usb_data *sisusb;
        ssize_t bytes_read = 0;
@@ -2539,11 +2515,10 @@ sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
        }
 
        if ((*ppos) >= SISUSB_PCI_PSEUDO_IOPORTBASE &&
-           (*ppos) <  SISUSB_PCI_PSEUDO_IOPORTBASE + 128) {
+                       (*ppos) <  SISUSB_PCI_PSEUDO_IOPORTBASE + 128) {
 
-               address = (*ppos) -
-                       SISUSB_PCI_PSEUDO_IOPORTBASE +
-                       SISUSB_PCI_IOPORTBASE;
+               address = (*ppos) - SISUSB_PCI_PSEUDO_IOPORTBASE +
+                               SISUSB_PCI_IOPORTBASE;
 
                /* Read i/o ports
                 * Byte, word and long(32) can be read. As this
@@ -2551,82 +2526,77 @@ sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
                 * in machine-endianness.
                 */
                switch (count) {
+               case 1:
+                       if (sisusb_read_memio_byte(sisusb, SISUSB_TYPE_IO,
+                                       address, &buf8))
+                               errno = -EIO;
+                       else if (put_user(buf8, (u8 __user *)buffer))
+                               errno = -EFAULT;
+                       else
+                               bytes_read = 1;
 
-                       case 1:
-                               if (sisusb_read_memio_byte(sisusb,
-                                                       SISUSB_TYPE_IO,
-                                                       address, &buf8))
-                                       errno = -EIO;
-                               else if (put_user(buf8, (u8 __user *)buffer))
-                                       errno = -EFAULT;
-                               else
-                                       bytes_read = 1;
-
-                               break;
+                       break;
 
-                       case 2:
-                               if (sisusb_read_memio_word(sisusb,
-                                                       SISUSB_TYPE_IO,
-                                                       address, &buf16))
-                                       errno = -EIO;
-                               else if (put_user(buf16, (u16 __user *)buffer))
-                                       errno = -EFAULT;
-                               else
-                                       bytes_read = 2;
+               case 2:
+                       if (sisusb_read_memio_word(sisusb, SISUSB_TYPE_IO,
+                                       address, &buf16))
+                               errno = -EIO;
+                       else if (put_user(buf16, (u16 __user *)buffer))
+                               errno = -EFAULT;
+                       else
+                               bytes_read = 2;
 
-                               break;
+                       break;
 
-                       case 4:
-                               if (sisusb_read_memio_long(sisusb,
-                                                       SISUSB_TYPE_IO,
-                                                       address, &buf32))
-                                       errno = -EIO;
-                               else if (put_user(buf32, (u32 __user *)buffer))
-                                       errno = -EFAULT;
-                               else
-                                       bytes_read = 4;
+               case 4:
+                       if (sisusb_read_memio_long(sisusb, SISUSB_TYPE_IO,
+                                       address, &buf32))
+                               errno = -EIO;
+                       else if (put_user(buf32, (u32 __user *)buffer))
+                               errno = -EFAULT;
+                       else
+                               bytes_read = 4;
 
-                               break;
+                       break;
 
-                       default:
-                               errno = -EIO;
+               default:
+                       errno = -EIO;
 
                }
 
-       } else if ((*ppos) >= SISUSB_PCI_PSEUDO_MEMBASE &&
-                  (*ppos) <  SISUSB_PCI_PSEUDO_MEMBASE + sisusb->vramsize) {
+       } else if ((*ppos) >= SISUSB_PCI_PSEUDO_MEMBASE && (*ppos) <
+                       SISUSB_PCI_PSEUDO_MEMBASE + sisusb->vramsize) {
 
-               address = (*ppos) -
-                       SISUSB_PCI_PSEUDO_MEMBASE +
-                       SISUSB_PCI_MEMBASE;
+               address = (*ppos) - SISUSB_PCI_PSEUDO_MEMBASE +
+                               SISUSB_PCI_MEMBASE;
 
                /* Read video ram
                 * Remember: Data delivered is never endian-corrected
                 */
                errno = sisusb_read_mem_bulk(sisusb, address,
-                                       NULL, count, buffer, &bytes_read);
+                               NULL, count, buffer, &bytes_read);
 
                if (bytes_read)
                        errno = bytes_read;
 
        } else  if ((*ppos) >= SISUSB_PCI_PSEUDO_MMIOBASE &&
-                   (*ppos) <  SISUSB_PCI_PSEUDO_MMIOBASE + SISUSB_PCI_MMIOSIZE) {
+                               (*ppos) <  SISUSB_PCI_PSEUDO_MMIOBASE +
+                               SISUSB_PCI_MMIOSIZE) {
 
-               address = (*ppos) -
-                       SISUSB_PCI_PSEUDO_MMIOBASE +
-                       SISUSB_PCI_MMIOBASE;
+               address = (*ppos) - SISUSB_PCI_PSEUDO_MMIOBASE +
+                               SISUSB_PCI_MMIOBASE;
 
                /* Read MMIO
                 * Remember: Data delivered is never endian-corrected
                 */
                errno = sisusb_read_mem_bulk(sisusb, address,
-                                       NULL, count, buffer, &bytes_read);
+                               NULL, count, buffer, &bytes_read);
 
                if (bytes_read)
                        errno = bytes_read;
 
        } else  if ((*ppos) >= SISUSB_PCI_PSEUDO_PCIBASE &&
-                   (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE + 0x5c) {
+                       (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE + 0x5c) {
 
                if (count != 4) {
                        mutex_unlock(&sisusb->lock);
@@ -2658,9 +2628,8 @@ sisusb_read(struct file *file, char __user *buffer, size_t count, loff_t *ppos)
        return errno ? errno : bytes_read;
 }
 
-static ssize_t
-sisusb_write(struct file *file, const char __user *buffer, size_t count,
-                                                               loff_t *ppos)
+static ssize_t sisusb_write(struct file *file, const char __user *buffer,
+               size_t count, loff_t *ppos)
 {
        struct sisusb_usb_data *sisusb;
        int errno = 0;
@@ -2682,11 +2651,10 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
        }
 
        if ((*ppos) >= SISUSB_PCI_PSEUDO_IOPORTBASE &&
-           (*ppos) <  SISUSB_PCI_PSEUDO_IOPORTBASE + 128) {
+                       (*ppos) <  SISUSB_PCI_PSEUDO_IOPORTBASE + 128) {
 
-               address = (*ppos) -
-                       SISUSB_PCI_PSEUDO_IOPORTBASE +
-                       SISUSB_PCI_IOPORTBASE;
+               address = (*ppos) - SISUSB_PCI_PSEUDO_IOPORTBASE +
+                               SISUSB_PCI_IOPORTBASE;
 
                /* Write i/o ports
                 * Byte, word and long(32) can be written. As this
@@ -2694,53 +2662,49 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
                 * in machine-endianness.
                 */
                switch (count) {
+               case 1:
+                       if (get_user(buf8, (u8 __user *)buffer))
+                               errno = -EFAULT;
+                       else if (sisusb_write_memio_byte(sisusb,
+                                       SISUSB_TYPE_IO, address, buf8))
+                               errno = -EIO;
+                       else
+                               bytes_written = 1;
 
-                       case 1:
-                               if (get_user(buf8, (u8 __user *)buffer))
-                                       errno = -EFAULT;
-                               else if (sisusb_write_memio_byte(sisusb,
-                                                       SISUSB_TYPE_IO,
-                                                       address, buf8))
-                                       errno = -EIO;
-                               else
-                                       bytes_written = 1;
-
-                               break;
+                       break;
 
-                       case 2:
-                               if (get_user(buf16, (u16 __user *)buffer))
-                                       errno = -EFAULT;
-                               else if (sisusb_write_memio_word(sisusb,
-                                                       SISUSB_TYPE_IO,
-                                                       address, buf16))
-                                       errno = -EIO;
-                               else
-                                       bytes_written = 2;
+               case 2:
+                       if (get_user(buf16, (u16 __user *)buffer))
+                               errno = -EFAULT;
+                       else if (sisusb_write_memio_word(sisusb,
+                                       SISUSB_TYPE_IO, address, buf16))
+                               errno = -EIO;
+                       else
+                               bytes_written = 2;
 
-                               break;
+                       break;
 
-                       case 4:
-                               if (get_user(buf32, (u32 __user *)buffer))
-                                       errno = -EFAULT;
-                               else if (sisusb_write_memio_long(sisusb,
-                                                       SISUSB_TYPE_IO,
-                                                       address, buf32))
-                                       errno = -EIO;
-                               else
-                                       bytes_written = 4;
+               case 4:
+                       if (get_user(buf32, (u32 __user *)buffer))
+                               errno = -EFAULT;
+                       else if (sisusb_write_memio_long(sisusb,
+                                       SISUSB_TYPE_IO, address, buf32))
+                               errno = -EIO;
+                       else
+                               bytes_written = 4;
 
-                               break;
+                       break;
 
-                       default:
-                               errno = -EIO;
+               default:
+                       errno = -EIO;
                }
 
        } else if ((*ppos) >= SISUSB_PCI_PSEUDO_MEMBASE &&
-                  (*ppos) <  SISUSB_PCI_PSEUDO_MEMBASE + sisusb->vramsize) {
+                       (*ppos) <  SISUSB_PCI_PSEUDO_MEMBASE +
+                       sisusb->vramsize) {
 
-               address = (*ppos) -
-                       SISUSB_PCI_PSEUDO_MEMBASE +
-                       SISUSB_PCI_MEMBASE;
+               address = (*ppos) - SISUSB_PCI_PSEUDO_MEMBASE +
+                               SISUSB_PCI_MEMBASE;
 
                /* Write video ram.
                 * Buffer is copied 1:1, therefore, on big-endian
@@ -2749,17 +2713,17 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
                 * mode or if YUV data is being transferred).
                 */
                errno = sisusb_write_mem_bulk(sisusb, address, NULL,
-                                       count, buffer, 0, &bytes_written);
+                               count, buffer, 0, &bytes_written);
 
                if (bytes_written)
                        errno = bytes_written;
 
        } else  if ((*ppos) >= SISUSB_PCI_PSEUDO_MMIOBASE &&
-                   (*ppos) <  SISUSB_PCI_PSEUDO_MMIOBASE + SISUSB_PCI_MMIOSIZE) {
+                       (*ppos) <  SISUSB_PCI_PSEUDO_MMIOBASE +
+                       SISUSB_PCI_MMIOSIZE) {
 
-               address = (*ppos) -
-                       SISUSB_PCI_PSEUDO_MMIOBASE +
-                       SISUSB_PCI_MMIOBASE;
+               address = (*ppos) - SISUSB_PCI_PSEUDO_MMIOBASE +
+                               SISUSB_PCI_MMIOBASE;
 
                /* Write MMIO.
                 * Buffer is copied 1:1, therefore, on big-endian
@@ -2767,13 +2731,14 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
                 * in advance.
                 */
                errno = sisusb_write_mem_bulk(sisusb, address, NULL,
-                                       count, buffer, 0, &bytes_written);
+                               count, buffer, 0, &bytes_written);
 
                if (bytes_written)
                        errno = bytes_written;
 
        } else  if ((*ppos) >= SISUSB_PCI_PSEUDO_PCIBASE &&
-                   (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE + SISUSB_PCI_PCONFSIZE) {
+                               (*ppos) <= SISUSB_PCI_PSEUDO_PCIBASE +
+                               SISUSB_PCI_PCONFSIZE) {
 
                if (count != 4) {
                        mutex_unlock(&sisusb->lock);
@@ -2807,8 +2772,7 @@ sisusb_write(struct file *file, const char __user *buffer, size_t count,
        return errno ? errno : bytes_written;
 }
 
-static loff_t
-sisusb_lseek(struct file *file, loff_t offset, int orig)
+static loff_t sisusb_lseek(struct file *file, loff_t offset, int orig)
 {
        struct sisusb_usb_data *sisusb;
        loff_t ret;
@@ -2831,9 +2795,8 @@ sisusb_lseek(struct file *file, loff_t offset, int orig)
        return ret;
 }
 
-static int
-sisusb_handle_command(struct sisusb_usb_data *sisusb, struct sisusb_command *y,
-                                                       unsigned long arg)
+static int sisusb_handle_command(struct sisusb_usb_data *sisusb,
+               struct sisusb_command *y, unsigned long arg)
 {
        int     retval, port, length;
        u32     address;
@@ -2849,105 +2812,99 @@ sisusb_handle_command(struct sisusb_usb_data *sisusb, struct sisusb_command *y,
                SISUSB_PCI_IOPORTBASE;
 
        switch (y->operation) {
-               case SUCMD_GET:
-                       retval = sisusb_getidxreg(sisusb, port,
-                                                        y->data0, &y->data1);
-                       if (!retval) {
-                               if (copy_to_user((void __user *)arg, y,
-                                                       sizeof(*y)))
-                                       retval = -EFAULT;
-                       }
-                       break;
+       case SUCMD_GET:
+               retval = sisusb_getidxreg(sisusb, port, y->data0, &y->data1);
+               if (!retval) {
+                       if (copy_to_user((void __user *)arg, y, sizeof(*y)))
+                               retval = -EFAULT;
+               }
+               break;
 
-               case SUCMD_SET:
-                       retval = sisusb_setidxreg(sisusb, port,
-                                               y->data0, y->data1);
-                       break;
+       case SUCMD_SET:
+               retval = sisusb_setidxreg(sisusb, port, y->data0, y->data1);
+               break;
 
-               case SUCMD_SETOR:
-                       retval = sisusb_setidxregor(sisusb, port,
-                                               y->data0, y->data1);
-                       break;
+       case SUCMD_SETOR:
+               retval = sisusb_setidxregor(sisusb, port, y->data0, y->data1);
+               break;
 
-               case SUCMD_SETAND:
-                       retval = sisusb_setidxregand(sisusb, port,
-                                               y->data0, y->data1);
-                       break;
+       case SUCMD_SETAND:
+               retval = sisusb_setidxregand(sisusb, port, y->data0, y->data1);
+               break;
 
-               case SUCMD_SETANDOR:
-                       retval = sisusb_setidxregandor(sisusb, port,
-                                               y->data0, y->data1, y->data2);
-                       break;
+       case SUCMD_SETANDOR:
+               retval = sisusb_setidxregandor(sisusb, port, y->data0,
+                               y->data1, y->data2);
+               break;
 
-               case SUCMD_SETMASK:
-                       retval = sisusb_setidxregmask(sisusb, port,
-                                               y->data0, y->data1, y->data2);
-                       break;
+       case SUCMD_SETMASK:
+               retval = sisusb_setidxregmask(sisusb, port, y->data0,
+                               y->data1, y->data2);
+               break;
 
-               case SUCMD_CLRSCR:
-                       /* Gfx core must be initialized */
-                       if (!sisusb->gfxinit)
-                               return -ENODEV;
+       case SUCMD_CLRSCR:
+               /* Gfx core must be initialized */
+               if (!sisusb->gfxinit)
+                       return -ENODEV;
 
-                       length = (y->data0 << 16) | (y->data1 << 8) | y->data2;
-                       address = y->data3 -
-                               SISUSB_PCI_PSEUDO_MEMBASE +
+               length = (y->data0 << 16) | (y->data1 << 8) | y->data2;
+               address = y->data3 - SISUSB_PCI_PSEUDO_MEMBASE +
                                SISUSB_PCI_MEMBASE;
-                       retval = sisusb_clear_vram(sisusb, address, length);
-                       break;
+               retval = sisusb_clear_vram(sisusb, address, length);
+               break;
 
-               case SUCMD_HANDLETEXTMODE:
-                       retval = 0;
+       case SUCMD_HANDLETEXTMODE:
+               retval = 0;
 #ifdef INCL_SISUSB_CON
-                       /* Gfx core must be initialized, SiS_Pr must exist */
-                       if (!sisusb->gfxinit || !sisusb->SiS_Pr)
-                               return -ENODEV;
+               /* Gfx core must be initialized, SiS_Pr must exist */
+               if (!sisusb->gfxinit || !sisusb->SiS_Pr)
+                       return -ENODEV;
 
-                       switch (y->data0) {
-                       case 0:
-                               retval = sisusb_reset_text_mode(sisusb, 0);
-                               break;
-                       case 1:
-                               sisusb->textmodedestroyed = 1;
-                               break;
-                       }
-#endif
+               switch (y->data0) {
+               case 0:
+                       retval = sisusb_reset_text_mode(sisusb, 0);
+                       break;
+               case 1:
+                       sisusb->textmodedestroyed = 1;
                        break;
+               }
+#endif
+               break;
 
 #ifdef INCL_SISUSB_CON
-               case SUCMD_SETMODE:
-                       /* Gfx core must be initialized, SiS_Pr must exist */
-                       if (!sisusb->gfxinit || !sisusb->SiS_Pr)
-                               return -ENODEV;
+       case SUCMD_SETMODE:
+               /* Gfx core must be initialized, SiS_Pr must exist */
+               if (!sisusb->gfxinit || !sisusb->SiS_Pr)
+                       return -ENODEV;
 
-                       retval = 0;
+               retval = 0;
 
-                       sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
-                       sisusb->SiS_Pr->sisusb = (void *)sisusb;
+               sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
+               sisusb->SiS_Pr->sisusb = (void *)sisusb;
 
-                       if (SiSUSBSetMode(sisusb->SiS_Pr, y->data3))
-                               retval = -EINVAL;
+               if (SiSUSBSetMode(sisusb->SiS_Pr, y->data3))
+                       retval = -EINVAL;
 
-                       break;
+               break;
 
-               case SUCMD_SETVESAMODE:
-                       /* Gfx core must be initialized, SiS_Pr must exist */
-                       if (!sisusb->gfxinit || !sisusb->SiS_Pr)
-                               return -ENODEV;
+       case SUCMD_SETVESAMODE:
+               /* Gfx core must be initialized, SiS_Pr must exist */
+               if (!sisusb->gfxinit || !sisusb->SiS_Pr)
+                       return -ENODEV;
 
-                       retval = 0;
+               retval = 0;
 
-                       sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
-                       sisusb->SiS_Pr->sisusb = (void *)sisusb;
+               sisusb->SiS_Pr->IOAddress = SISUSB_PCI_IOPORTBASE + 0x30;
+               sisusb->SiS_Pr->sisusb = (void *)sisusb;
 
-                       if (SiSUSBSetVESAMode(sisusb->SiS_Pr, y->data3))
-                               retval = -EINVAL;
+               if (SiSUSBSetVESAMode(sisusb->SiS_Pr, y->data3))
+                       retval = -EINVAL;
 
-                       break;
+               break;
 #endif
 
-               default:
-                       retval = -EINVAL;
+       default:
+               retval = -EINVAL;
        }
 
        if (retval > 0)
@@ -2956,8 +2913,7 @@ sisusb_handle_command(struct sisusb_usb_data *sisusb, struct sisusb_command *y,
        return retval;
 }
 
-static long
-sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
+static long sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
        struct sisusb_usb_data *sisusb;
        struct sisusb_info x;
@@ -2978,52 +2934,51 @@ sisusb_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 
        switch (cmd) {
+       case SISUSB_GET_CONFIG_SIZE:
 
-               case SISUSB_GET_CONFIG_SIZE:
-
-                       if (put_user(sizeof(x), argp))
-                               retval = -EFAULT;
+               if (put_user(sizeof(x), argp))
+                       retval = -EFAULT;
 
-                       break;
+               break;
 
-               case SISUSB_GET_CONFIG:
-
-                       x.sisusb_id         = SISUSB_ID;
-                       x.sisusb_version    = SISUSB_VERSION;
-                       x.sisusb_revision   = SISUSB_REVISION;
-                       x.sisusb_patchlevel = SISUSB_PATCHLEVEL;
-                       x.sisusb_gfxinit    = sisusb->gfxinit;
-                       x.sisusb_vrambase   = SISUSB_PCI_PSEUDO_MEMBASE;
-                       x.sisusb_mmiobase   = SISUSB_PCI_PSEUDO_MMIOBASE;
-                       x.sisusb_iobase     = SISUSB_PCI_PSEUDO_IOPORTBASE;
-                       x.sisusb_pcibase    = SISUSB_PCI_PSEUDO_PCIBASE;
-                       x.sisusb_vramsize   = sisusb->vramsize;
-                       x.sisusb_minor      = sisusb->minor;
-                       x.sisusb_fbdevactive= 0;
+       case SISUSB_GET_CONFIG:
+
+               x.sisusb_id = SISUSB_ID;
+               x.sisusb_version = SISUSB_VERSION;
+               x.sisusb_revision = SISUSB_REVISION;
+               x.sisusb_patchlevel = SISUSB_PATCHLEVEL;
+               x.sisusb_gfxinit = sisusb->gfxinit;
+               x.sisusb_vrambase = SISUSB_PCI_PSEUDO_MEMBASE;
+               x.sisusb_mmiobase = SISUSB_PCI_PSEUDO_MMIOBASE;
+               x.sisusb_iobase = SISUSB_PCI_PSEUDO_IOPORTBASE;
+               x.sisusb_pcibase = SISUSB_PCI_PSEUDO_PCIBASE;
+               x.sisusb_vramsize = sisusb->vramsize;
+               x.sisusb_minor = sisusb->minor;
+               x.sisusb_fbdevactive = 0;
 #ifdef INCL_SISUSB_CON
-                       x.sisusb_conactive  = sisusb->haveconsole ? 1 : 0;
+               x.sisusb_conactive  = sisusb->haveconsole ? 1 : 0;
 #else
-                       x.sisusb_conactive  = 0;
+               x.sisusb_conactive  = 0;
 #endif
-                       memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved));
+               memset(x.sisusb_reserved, 0, sizeof(x.sisusb_reserved));
 
-                       if (copy_to_user((void __user *)arg, &x, sizeof(x)))
-                               retval = -EFAULT;
+               if (copy_to_user((void __user *)arg, &x, sizeof(x)))
+                       retval = -EFAULT;
 
-                       break;
+               break;
 
-               case SISUSB_COMMAND:
+       case SISUSB_COMMAND:
 
-                       if (copy_from_user(&y, (void __user *)arg, sizeof(y)))
-                               retval = -EFAULT;
-                       else
-                               retval = sisusb_handle_command(sisusb, &y, arg);
+               if (copy_from_user(&y, (void __user *)arg, sizeof(y)))
+                       retval = -EFAULT;
+               else
+                       retval = sisusb_handle_command(sisusb, &y, arg);
 
-                       break;
+               break;
 
-               default:
-                       retval = -ENOTTY;
-                       break;
+       default:
+               retval = -ENOTTY;
+               break;
        }
 
 err_out:
@@ -3032,20 +2987,20 @@ err_out:
 }
 
 #ifdef SISUSB_NEW_CONFIG_COMPAT
-static long
-sisusb_compat_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
+static long sisusb_compat_ioctl(struct file *f, unsigned int cmd,
+               unsigned long arg)
 {
        long retval;
 
        switch (cmd) {
-               case SISUSB_GET_CONFIG_SIZE:
-               case SISUSB_GET_CONFIG:
-               case SISUSB_COMMAND:
-                       retval = sisusb_ioctl(f, cmd, arg);
-                       return retval;
+       case SISUSB_GET_CONFIG_SIZE:
+       case SISUSB_GET_CONFIG:
+       case SISUSB_COMMAND:
+               retval = sisusb_ioctl(f, cmd, arg);
+               return retval;
 
-               default:
-                       return -ENOIOCTLCMD;
+       default:
+               return -ENOIOCTLCMD;
        }
 }
 #endif
@@ -3070,21 +3025,20 @@ static struct usb_class_driver usb_sisusb_class = {
 };
 
 static int sisusb_probe(struct usb_interface *intf,
-                       const struct usb_device_id *id)
+               const struct usb_device_id *id)
 {
        struct usb_device *dev = interface_to_usbdev(intf);
        struct sisusb_usb_data *sisusb;
        int retval = 0, i;
 
        dev_info(&dev->dev, "USB2VGA dongle found at address %d\n",
-               dev->devnum);
+                       dev->devnum);
 
        /* Allocate memory for our private */
        sisusb = kzalloc(sizeof(*sisusb), GFP_KERNEL);
-       if (!sisusb) {
-               dev_err(&dev->dev, "Failed to allocate memory for private data\n");
+       if (!sisusb)
                return -ENOMEM;
-       }
+
        kref_init(&sisusb->kref);
 
        mutex_init(&(sisusb->lock));
@@ -3092,8 +3046,9 @@ static int sisusb_probe(struct usb_interface *intf,
        /* Register device */
        retval = usb_register_dev(intf, &usb_sisusb_class);
        if (retval) {
-               dev_err(&sisusb->sisusb_dev->dev, "Failed to get a minor for device %d\n",
-                       dev->devnum);
+               dev_err(&sisusb->sisusb_dev->dev,
+                               "Failed to get a minor for device %d\n",
+                               dev->devnum);
                retval = -ENODEV;
                goto error_1;
        }
@@ -3108,8 +3063,8 @@ static int sisusb_probe(struct usb_interface *intf,
 
        /* Allocate buffers */
        sisusb->ibufsize = SISUSB_IBUF_SIZE;
-       if (!(sisusb->ibuf = kmalloc(SISUSB_IBUF_SIZE, GFP_KERNEL))) {
-               dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for input buffer");
+       sisusb->ibuf = kmalloc(SISUSB_IBUF_SIZE, GFP_KERNEL);
+       if (!sisusb->ibuf) {
                retval = -ENOMEM;
                goto error_2;
        }
@@ -3117,20 +3072,20 @@ static int sisusb_probe(struct usb_interface *intf,
        sisusb->numobufs = 0;
        sisusb->obufsize = SISUSB_OBUF_SIZE;
        for (i = 0; i < NUMOBUFS; i++) {
-               if (!(sisusb->obuf[i] = kmalloc(SISUSB_OBUF_SIZE, GFP_KERNEL))) {
+               sisusb->obuf[i] = kmalloc(SISUSB_OBUF_SIZE, GFP_KERNEL);
+               if (!sisusb->obuf[i]) {
                        if (i == 0) {
-                               dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate memory for output buffer\n");
                                retval = -ENOMEM;
                                goto error_3;
                        }
                        break;
-               } else
-                       sisusb->numobufs++;
-
+               }
+               sisusb->numobufs++;
        }
 
        /* Allocate URBs */
-       if (!(sisusb->sisurbin = usb_alloc_urb(0, GFP_KERNEL))) {
+       sisusb->sisurbin = usb_alloc_urb(0, GFP_KERNEL);
+       if (!sisusb->sisurbin) {
                dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate URBs\n");
                retval = -ENOMEM;
                goto error_3;
@@ -3138,8 +3093,10 @@ static int sisusb_probe(struct usb_interface *intf,
        sisusb->completein = 1;
 
        for (i = 0; i < sisusb->numobufs; i++) {
-               if (!(sisusb->sisurbout[i] = usb_alloc_urb(0, GFP_KERNEL))) {
-                       dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate URBs\n");
+               sisusb->sisurbout[i] = usb_alloc_urb(0, GFP_KERNEL);
+               if (!sisusb->sisurbout[i]) {
+                       dev_err(&sisusb->sisusb_dev->dev,
+                                       "Failed to allocate URBs\n");
                        retval = -ENOMEM;
                        goto error_4;
                }
@@ -3148,12 +3105,15 @@ static int sisusb_probe(struct usb_interface *intf,
                sisusb->urbstatus[i] = 0;
        }
 
-       dev_info(&sisusb->sisusb_dev->dev, "Allocated %d output buffers\n", sisusb->numobufs);
+       dev_info(&sisusb->sisusb_dev->dev, "Allocated %d output buffers\n",
+                       sisusb->numobufs);
 
 #ifdef INCL_SISUSB_CON
        /* Allocate our SiS_Pr */
-       if (!(sisusb->SiS_Pr = kmalloc(sizeof(struct SiS_Private), GFP_KERNEL))) {
-               dev_err(&sisusb->sisusb_dev->dev, "Failed to allocate SiS_Pr\n");
+       sisusb->SiS_Pr = kmalloc(sizeof(struct SiS_Private), GFP_KERNEL);
+       if (!sisusb->SiS_Pr) {
+               retval = -ENOMEM;
+               goto error_4;
        }
 #endif
 
@@ -3170,17 +3130,18 @@ static int sisusb_probe(struct usb_interface *intf,
        if (dev->speed == USB_SPEED_HIGH || dev->speed == USB_SPEED_SUPER) {
                int initscreen = 1;
 #ifdef INCL_SISUSB_CON
-               if (sisusb_first_vc > 0 &&
-                   sisusb_last_vc > 0 &&
-                   sisusb_first_vc <= sisusb_last_vc &&
-                   sisusb_last_vc <= MAX_NR_CONSOLES)
+               if (sisusb_first_vc > 0 && sisusb_last_vc > 0 &&
+                               sisusb_first_vc <= sisusb_last_vc &&
+                               sisusb_last_vc <= MAX_NR_CONSOLES)
                        initscreen = 0;
 #endif
                if (sisusb_init_gfxdevice(sisusb, initscreen))
-                       dev_err(&sisusb->sisusb_dev->dev, "Failed to early initialize device\n");
+                       dev_err(&sisusb->sisusb_dev->dev,
+                                       "Failed to early initialize device\n");
 
        } else
-               dev_info(&sisusb->sisusb_dev->dev, "Not attached to USB 2.0 hub, deferring init\n");
+               dev_info(&sisusb->sisusb_dev->dev,
+                               "Not attached to USB 2.0 hub, deferring init\n");
 
        sisusb->ready = 1;
 
@@ -3254,7 +3215,7 @@ static const struct usb_device_id sisusb_table[] = {
        { }
 };
 
-MODULE_DEVICE_TABLE (usb, sisusb_table);
+MODULE_DEVICE_TABLE(usb, sisusb_table);
 
 static struct usb_driver sisusb_driver = {
        .name =         "sisusb",
index fec3f11..33ff49c 100644 (file)
@@ -349,7 +349,7 @@ struct mon_bus *mon_bus_lookup(unsigned int num)
 static int __init mon_init(void)
 {
        struct usb_bus *ubus;
-       int rc;
+       int rc, id;
 
        if ((rc = mon_text_init()) != 0)
                goto err_text;
@@ -365,12 +365,11 @@ static int __init mon_init(void)
        }
        // MOD_INC_USE_COUNT(which_module?);
 
-       mutex_lock(&usb_bus_list_lock);
-       list_for_each_entry (ubus, &usb_bus_list, bus_list) {
+       mutex_lock(&usb_bus_idr_lock);
+       idr_for_each_entry(&usb_bus_idr, ubus, id)
                mon_bus_init(ubus);
-       }
        usb_register_notify(&mon_nb);
-       mutex_unlock(&usb_bus_list_lock);
+       mutex_unlock(&usb_bus_idr_lock);
        return 0;
 
 err_reg:
index 45c83ba..886526b 100644 (file)
@@ -7,6 +7,7 @@
 config USB_MUSB_HDRC
        tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
        depends on (USB || USB_GADGET)
+       depends on HAS_IOMEM
        help
          Say Y here if your system has a dual role high speed USB
          controller based on the Mentor Graphics silicon IP.  Then
@@ -85,6 +86,7 @@ config USB_MUSB_DA8XX
 
 config USB_MUSB_TUSB6010
        tristate "TUSB6010"
+       depends on HAS_IOMEM
        depends on ARCH_OMAP2PLUS || COMPILE_TEST
        depends on NOP_USB_XCEIV = USB_MUSB_HDRC # both built-in or both modules
 
index ebc99ee..b26d7c3 100644 (file)
@@ -5,7 +5,7 @@
 config USB_RENESAS_USBHS
        tristate 'Renesas USBHS controller'
        depends on USB_GADGET
-       depends on ARCH_SHMOBILE || SUPERH || COMPILE_TEST
+       depends on ARCH_RENESAS || SUPERH || COMPILE_TEST
        depends on EXTCON || !EXTCON # if EXTCON=m, USBHS cannot be built-in
        default n
        help
index c0f5c65..b4de70e 100644 (file)
@@ -46,7 +46,7 @@ static int usbhsf_null_handle(struct usbhs_pkt *pkt, int *is_done)
        return -EINVAL;
 }
 
-static struct usbhs_pkt_handle usbhsf_null_handler = {
+static const struct usbhs_pkt_handle usbhsf_null_handler = {
        .prepare = usbhsf_null_handle,
        .try_run = usbhsf_null_handle,
 };
@@ -422,12 +422,12 @@ static int usbhs_dcp_dir_switch_done(struct usbhs_pkt *pkt, int *is_done)
        return 0;
 }
 
-struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler = {
+const struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler = {
        .prepare = usbhs_dcp_dir_switch_to_write,
        .try_run = usbhs_dcp_dir_switch_done,
 };
 
-struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler = {
+const struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler = {
        .prepare = usbhs_dcp_dir_switch_to_read,
        .try_run = usbhs_dcp_dir_switch_done,
 };
@@ -449,7 +449,7 @@ static int usbhsf_dcp_data_stage_try_push(struct usbhs_pkt *pkt, int *is_done)
        return pkt->handler->prepare(pkt, is_done);
 }
 
-struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler = {
+const struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler = {
        .prepare = usbhsf_dcp_data_stage_try_push,
 };
 
@@ -488,7 +488,7 @@ static int usbhsf_dcp_data_stage_prepare_pop(struct usbhs_pkt *pkt,
        return pkt->handler->prepare(pkt, is_done);
 }
 
-struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler = {
+const struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler = {
        .prepare = usbhsf_dcp_data_stage_prepare_pop,
 };
 
@@ -600,7 +600,7 @@ static int usbhsf_pio_prepare_push(struct usbhs_pkt *pkt, int *is_done)
        return usbhsf_pio_try_push(pkt, is_done);
 }
 
-struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
+const struct usbhs_pkt_handle usbhs_fifo_pio_push_handler = {
        .prepare = usbhsf_pio_prepare_push,
        .try_run = usbhsf_pio_try_push,
 };
@@ -730,7 +730,7 @@ usbhs_fifo_read_busy:
        return ret;
 }
 
-struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
+const struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler = {
        .prepare = usbhsf_prepare_pop,
        .try_run = usbhsf_pio_try_pop,
 };
@@ -747,7 +747,7 @@ static int usbhsf_ctrl_stage_end(struct usbhs_pkt *pkt, int *is_done)
        return 0;
 }
 
-struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
+const struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler = {
        .prepare = usbhsf_ctrl_stage_end,
        .try_run = usbhsf_ctrl_stage_end,
 };
@@ -934,7 +934,7 @@ static int usbhsf_dma_push_done(struct usbhs_pkt *pkt, int *is_done)
        return 0;
 }
 
-struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
+const struct usbhs_pkt_handle usbhs_fifo_dma_push_handler = {
        .prepare        = usbhsf_dma_prepare_push,
        .dma_done       = usbhsf_dma_push_done,
 };
@@ -1182,7 +1182,7 @@ static int usbhsf_dma_pop_done(struct usbhs_pkt *pkt, int *is_done)
                return usbhsf_dma_pop_done_with_rx_irq(pkt, is_done);
 }
 
-struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
+const struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler = {
        .prepare        = usbhsf_dma_prepare_pop,
        .try_run        = usbhsf_dma_try_pop,
        .dma_done       = usbhsf_dma_pop_done
index c7d9b86..8b98507 100644 (file)
@@ -54,7 +54,7 @@ struct usbhs_pkt_handle;
 struct usbhs_pkt {
        struct list_head node;
        struct usbhs_pipe *pipe;
-       struct usbhs_pkt_handle *handler;
+       const struct usbhs_pkt_handle *handler;
        void (*done)(struct usbhs_priv *priv,
                     struct usbhs_pkt *pkt);
        struct work_struct work;
@@ -86,18 +86,18 @@ void usbhs_fifo_clear_dcp(struct usbhs_pipe *pipe);
 /*
  * packet info
  */
-extern struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
-extern struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
-extern struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
+extern const struct usbhs_pkt_handle usbhs_fifo_pio_push_handler;
+extern const struct usbhs_pkt_handle usbhs_fifo_pio_pop_handler;
+extern const struct usbhs_pkt_handle usbhs_ctrl_stage_end_handler;
 
-extern struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
-extern struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
+extern const struct usbhs_pkt_handle usbhs_fifo_dma_push_handler;
+extern const struct usbhs_pkt_handle usbhs_fifo_dma_pop_handler;
 
-extern struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler;
-extern struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler;
+extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_in_handler;
+extern const struct usbhs_pkt_handle usbhs_dcp_status_stage_out_handler;
 
-extern struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler;
-extern struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler;
+extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_in_handler;
+extern const struct usbhs_pkt_handle usbhs_dcp_data_stage_out_handler;
 
 void usbhs_pkt_init(struct usbhs_pkt *pkt);
 void usbhs_pkt_push(struct usbhs_pipe *pipe, struct usbhs_pkt *pkt,
index 3212ab5..7835747 100644 (file)
@@ -38,7 +38,7 @@ struct usbhs_pipe {
 #define USBHS_PIPE_FLAGS_IS_DIR_HOST           (1 << 2)
 #define USBHS_PIPE_FLAGS_IS_RUNNING            (1 << 3)
 
-       struct usbhs_pkt_handle *handler;
+       const struct usbhs_pkt_handle *handler;
 
        void *mod_private;
 };
index 57bf3ad..5a12c03 100644 (file)
@@ -57,7 +57,6 @@
 void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
 {
        char *what = NULL;
-       int i;
 
        switch (srb->cmnd[0]) {
        case TEST_UNIT_READY: what = "TEST_UNIT_READY"; break;
@@ -153,10 +152,8 @@ void usb_stor_show_command(const struct us_data *us, struct scsi_cmnd *srb)
        default: what = "(unknown command)"; break;
        }
        usb_stor_dbg(us, "Command %s (%d bytes)\n", what, srb->cmd_len);
-       usb_stor_dbg(us, "bytes: ");
-       for (i = 0; i < srb->cmd_len && i < 16; i++)
-               US_DEBUGPX(" %02x", srb->cmnd[i]);
-       US_DEBUGPX("\n");
+       usb_stor_dbg(us, "bytes: %*ph\n", min_t(int, srb->cmd_len, 16),
+                    (const unsigned char *)srb->cmnd);
 }
 
 void usb_stor_show_sense(const struct us_data *us,
@@ -174,11 +171,10 @@ void usb_stor_show_sense(const struct us_data *us,
        if (what == NULL)
                what = "(unknown ASC/ASCQ)";
 
-       usb_stor_dbg(us, "%s: ", keystr);
        if (fmt)
-               US_DEBUGPX("%s (%s%x)\n", what, fmt, ascq);
+               usb_stor_dbg(us, "%s: %s (%s%x)\n", keystr, what, fmt, ascq);
        else
-               US_DEBUGPX("%s\n", what);
+               usb_stor_dbg(us, "%s: %s\n", keystr, what);
 }
 
 void usb_stor_dbg(const struct us_data *us, const char *fmt, ...)
index f525203..6b365ce 100644 (file)
@@ -53,7 +53,6 @@ void usb_stor_show_sense(const struct us_data *us, unsigned char key,
 __printf(2, 3) void usb_stor_dbg(const struct us_data *us,
                                 const char *fmt, ...);
 
-#define US_DEBUGPX(fmt, ...)   printk(fmt, ##__VA_ARGS__)
 #define US_DEBUG(x)            x
 #else
 __printf(2, 3)
@@ -63,8 +62,6 @@ static inline void _usb_stor_dbg(const struct us_data *us,
 }
 #define usb_stor_dbg(us, fmt, ...)                             \
        do { if (0) _usb_stor_dbg(us, fmt, ##__VA_ARGS__); } while (0)
-#define US_DEBUGPX(fmt, ...)                                   \
-       do { if (0) printk(fmt, ##__VA_ARGS__); } while (0)
 #define US_DEBUG(x)
 #endif
 
index f3cf4ce..d3a17c6 100644 (file)
@@ -1067,12 +1067,12 @@ static void ms_lib_free_writebuf(struct us_data *us)
        ms_lib_clear_pagemap(info); /* (pdx)->MS_Lib.pagemap memset 0 in ms.h */
 
        if (info->MS_Lib.blkpag) {
-               kfree((u8 *)(info->MS_Lib.blkpag));  /* Arnold test ... */
+               kfree(info->MS_Lib.blkpag);  /* Arnold test ... */
                info->MS_Lib.blkpag = NULL;
        }
 
        if (info->MS_Lib.blkext) {
-               kfree((u8 *)(info->MS_Lib.blkext));  /* Arnold test ... */
+               kfree(info->MS_Lib.blkext);  /* Arnold test ... */
                info->MS_Lib.blkext = NULL;
        }
 }
index b746036..79224fc 100644 (file)
@@ -1102,24 +1102,24 @@ static int
 sddr09_get_wp(struct us_data *us, struct sddr09_card_info *info) {
        int result;
        unsigned char status;
+       const char *wp_fmt;
 
        result = sddr09_read_status(us, &status);
        if (result) {
                usb_stor_dbg(us, "read_status fails\n");
                return result;
        }
-       usb_stor_dbg(us, "status 0x%02X", status);
        if ((status & 0x80) == 0) {
                info->flags |= SDDR09_WP;       /* write protected */
-               US_DEBUGPX(" WP");
+               wp_fmt = " WP";
+       } else {
+               wp_fmt = "";
        }
-       if (status & 0x40)
-               US_DEBUGPX(" Ready");
-       if (status & LUNBITS)
-               US_DEBUGPX(" Suspended");
-       if (status & 0x1)
-               US_DEBUGPX(" Error");
-       US_DEBUGPX("\n");
+       usb_stor_dbg(us, "status 0x%02X%s%s%s%s\n", status, wp_fmt,
+                    status & 0x40 ? " Ready" : "",
+                    status & LUNBITS ? " Suspended" : "",
+                    status & 0x01 ? " Error" : "");
+
        return 0;
 }
 
index 9ff9404..44b096c 100644 (file)
@@ -246,6 +246,29 @@ static void uas_xfer_data(struct urb *urb, struct scsi_cmnd *cmnd,
        }
 }
 
+static bool uas_evaluate_response_iu(struct response_iu *riu, struct scsi_cmnd *cmnd)
+{
+       u8 response_code = riu->response_code;
+
+       switch (response_code) {
+       case RC_INCORRECT_LUN:
+               cmnd->result = DID_BAD_TARGET << 16;
+               break;
+       case RC_TMF_SUCCEEDED:
+               cmnd->result = DID_OK << 16;
+               break;
+       case RC_TMF_NOT_SUPPORTED:
+               cmnd->result = DID_TARGET_FAILURE << 16;
+               break;
+       default:
+               uas_log_cmd_state(cmnd, "response iu", response_code);
+               cmnd->result = DID_ERROR << 16;
+               break;
+       }
+
+       return response_code == RC_TMF_SUCCEEDED;
+}
+
 static void uas_stat_cmplt(struct urb *urb)
 {
        struct iu *iu = urb->transfer_buffer;
@@ -258,6 +281,7 @@ static void uas_stat_cmplt(struct urb *urb)
        unsigned long flags;
        unsigned int idx;
        int status = urb->status;
+       bool success;
 
        spin_lock_irqsave(&devinfo->lock, flags);
 
@@ -313,13 +337,13 @@ static void uas_stat_cmplt(struct urb *urb)
                uas_xfer_data(urb, cmnd, SUBMIT_DATA_OUT_URB);
                break;
        case IU_ID_RESPONSE:
-               uas_log_cmd_state(cmnd, "unexpected response iu",
-                                 ((struct response_iu *)iu)->response_code);
-               /* Error, cancel data transfers */
-               data_in_urb = usb_get_urb(cmdinfo->data_in_urb);
-               data_out_urb = usb_get_urb(cmdinfo->data_out_urb);
                cmdinfo->state &= ~COMMAND_INFLIGHT;
-               cmnd->result = DID_ERROR << 16;
+               success = uas_evaluate_response_iu((struct response_iu *)iu, cmnd);
+               if (!success) {
+                       /* Error, cancel data transfers */
+                       data_in_urb = usb_get_urb(cmdinfo->data_in_urb);
+                       data_out_urb = usb_get_urb(cmdinfo->data_out_urb);
+               }
                uas_try_complete(cmnd, __func__);
                break;
        default:
index 64933b9..2580a32 100644 (file)
@@ -117,11 +117,12 @@ EXPORT_SYMBOL_GPL(usbip_event_add);
 int usbip_event_happened(struct usbip_device *ud)
 {
        int happened = 0;
+       unsigned long flags;
 
-       spin_lock(&ud->lock);
+       spin_lock_irqsave(&ud->lock, flags);
        if (ud->event != 0)
                happened = 1;
-       spin_unlock(&ud->lock);
+       spin_unlock_irqrestore(&ud->lock, flags);
 
        return happened;
 }
index 7fbe19d..fca5110 100644 (file)
@@ -121,9 +121,11 @@ static void dump_port_status_diff(u32 prev_status, u32 new_status)
 
 void rh_port_connect(int rhport, enum usb_device_speed speed)
 {
+       unsigned long   flags;
+
        usbip_dbg_vhci_rh("rh_port_connect %d\n", rhport);
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
 
        the_controller->port_status[rhport] |= USB_PORT_STAT_CONNECTION
                | (1 << USB_PORT_FEAT_C_CONNECTION);
@@ -139,22 +141,24 @@ void rh_port_connect(int rhport, enum usb_device_speed speed)
                break;
        }
 
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 
        usb_hcd_poll_rh_status(vhci_to_hcd(the_controller));
 }
 
 static void rh_port_disconnect(int rhport)
 {
+       unsigned long   flags;
+
        usbip_dbg_vhci_rh("rh_port_disconnect %d\n", rhport);
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
 
        the_controller->port_status[rhport] &= ~USB_PORT_STAT_CONNECTION;
        the_controller->port_status[rhport] |=
                                        (1 << USB_PORT_FEAT_C_CONNECTION);
 
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
        usb_hcd_poll_rh_status(vhci_to_hcd(the_controller));
 }
 
@@ -182,13 +186,14 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
        int             retval;
        int             rhport;
        int             changed = 0;
+       unsigned long   flags;
 
        retval = DIV_ROUND_UP(VHCI_NPORTS + 1, 8);
        memset(buf, 0, retval);
 
        vhci = hcd_to_vhci(hcd);
 
-       spin_lock(&vhci->lock);
+       spin_lock_irqsave(&vhci->lock, flags);
        if (!HCD_HW_ACCESSIBLE(hcd)) {
                usbip_dbg_vhci_rh("hw accessible flag not on?\n");
                goto done;
@@ -209,7 +214,7 @@ static int vhci_hub_status(struct usb_hcd *hcd, char *buf)
                usb_hcd_resume_root_hub(hcd);
 
 done:
-       spin_unlock(&vhci->lock);
+       spin_unlock_irqrestore(&vhci->lock, flags);
        return changed ? retval : 0;
 }
 
@@ -231,6 +236,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
        struct vhci_hcd *dum;
        int             retval = 0;
        int             rhport;
+       unsigned long   flags;
 
        u32 prev_port_status[VHCI_NPORTS];
 
@@ -249,7 +255,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
 
        dum = hcd_to_vhci(hcd);
 
-       spin_lock(&dum->lock);
+       spin_lock_irqsave(&dum->lock, flags);
 
        /* store old status and compare now and old later */
        if (usbip_dbg_flag_vhci_rh) {
@@ -403,7 +409,7 @@ static int vhci_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
        }
        usbip_dbg_vhci_rh(" bye\n");
 
-       spin_unlock(&dum->lock);
+       spin_unlock_irqrestore(&dum->lock, flags);
 
        return retval;
 }
@@ -426,6 +432,7 @@ static void vhci_tx_urb(struct urb *urb)
 {
        struct vhci_device *vdev = get_vdev(urb->dev);
        struct vhci_priv *priv;
+       unsigned long flags;
 
        if (!vdev) {
                pr_err("could not get virtual device");
@@ -438,7 +445,7 @@ static void vhci_tx_urb(struct urb *urb)
                return;
        }
 
-       spin_lock(&vdev->priv_lock);
+       spin_lock_irqsave(&vdev->priv_lock, flags);
 
        priv->seqnum = atomic_inc_return(&the_controller->seqnum);
        if (priv->seqnum == 0xffff)
@@ -452,7 +459,7 @@ static void vhci_tx_urb(struct urb *urb)
        list_add_tail(&priv->list, &vdev->priv_tx);
 
        wake_up(&vdev->waitq_tx);
-       spin_unlock(&vdev->priv_lock);
+       spin_unlock_irqrestore(&vdev->priv_lock, flags);
 }
 
 static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
@@ -461,6 +468,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
        struct device *dev = &urb->dev->dev;
        int ret = 0;
        struct vhci_device *vdev;
+       unsigned long flags;
 
        usbip_dbg_vhci_hc("enter, usb_hcd %p urb %p mem_flags %d\n",
                          hcd, urb, mem_flags);
@@ -468,11 +476,11 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
        /* patch to usb_sg_init() is in 2.5.60 */
        BUG_ON(!urb->transfer_buffer && urb->transfer_buffer_length);
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
 
        if (urb->status != -EINPROGRESS) {
                dev_err(dev, "URB already unlinked!, status %d\n", urb->status);
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
                return urb->status;
        }
 
@@ -484,7 +492,7 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
            vdev->ud.status == VDEV_ST_ERROR) {
                dev_err(dev, "enqueue for inactive port %d\n", vdev->rhport);
                spin_unlock(&vdev->ud.lock);
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
                return -ENODEV;
        }
        spin_unlock(&vdev->ud.lock);
@@ -557,14 +565,14 @@ static int vhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
 
 out:
        vhci_tx_urb(urb);
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 
        return 0;
 
 no_need_xmit:
        usb_hcd_unlink_urb_from_ep(hcd, urb);
 no_need_unlink:
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
        if (!ret)
                usb_hcd_giveback_urb(vhci_to_hcd(the_controller),
                                     urb, urb->status);
@@ -621,16 +629,17 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 {
        struct vhci_priv *priv;
        struct vhci_device *vdev;
+       unsigned long flags;
 
        pr_info("dequeue a urb %p\n", urb);
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
 
        priv = urb->hcpriv;
        if (!priv) {
                /* URB was never linked! or will be soon given back by
                 * vhci_rx. */
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
                return -EIDRM;
        }
 
@@ -639,7 +648,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 
                ret = usb_hcd_check_unlink_urb(hcd, urb, status);
                if (ret) {
-                       spin_unlock(&the_controller->lock);
+                       spin_unlock_irqrestore(&the_controller->lock, flags);
                        return ret;
                }
        }
@@ -667,10 +676,10 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 
                usb_hcd_unlink_urb_from_ep(hcd, urb);
 
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
                usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
                                     urb->status);
-               spin_lock(&the_controller->lock);
+               spin_lock_irqsave(&the_controller->lock, flags);
 
        } else {
                /* tcp connection is alive */
@@ -682,7 +691,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
                unlink = kzalloc(sizeof(struct vhci_unlink), GFP_ATOMIC);
                if (!unlink) {
                        spin_unlock(&vdev->priv_lock);
-                       spin_unlock(&the_controller->lock);
+                       spin_unlock_irqrestore(&the_controller->lock, flags);
                        usbip_event_add(&vdev->ud, VDEV_EVENT_ERROR_MALLOC);
                        return -ENOMEM;
                }
@@ -703,7 +712,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
                spin_unlock(&vdev->priv_lock);
        }
 
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 
        usbip_dbg_vhci_hc("leave\n");
        return 0;
@@ -712,8 +721,9 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
 static void vhci_device_unlink_cleanup(struct vhci_device *vdev)
 {
        struct vhci_unlink *unlink, *tmp;
+       unsigned long flags;
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
        spin_lock(&vdev->priv_lock);
 
        list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) {
@@ -747,19 +757,19 @@ static void vhci_device_unlink_cleanup(struct vhci_device *vdev)
                list_del(&unlink->list);
 
                spin_unlock(&vdev->priv_lock);
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
 
                usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
                                     urb->status);
 
-               spin_lock(&the_controller->lock);
+               spin_lock_irqsave(&the_controller->lock, flags);
                spin_lock(&vdev->priv_lock);
 
                kfree(unlink);
        }
 
        spin_unlock(&vdev->priv_lock);
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 }
 
 /*
@@ -826,8 +836,9 @@ static void vhci_shutdown_connection(struct usbip_device *ud)
 static void vhci_device_reset(struct usbip_device *ud)
 {
        struct vhci_device *vdev = container_of(ud, struct vhci_device, ud);
+       unsigned long flags;
 
-       spin_lock(&ud->lock);
+       spin_lock_irqsave(&ud->lock, flags);
 
        vdev->speed  = 0;
        vdev->devid  = 0;
@@ -841,14 +852,16 @@ static void vhci_device_reset(struct usbip_device *ud)
        }
        ud->status = VDEV_ST_NULL;
 
-       spin_unlock(&ud->lock);
+       spin_unlock_irqrestore(&ud->lock, flags);
 }
 
 static void vhci_device_unusable(struct usbip_device *ud)
 {
-       spin_lock(&ud->lock);
+       unsigned long flags;
+
+       spin_lock_irqsave(&ud->lock, flags);
        ud->status = VDEV_ST_ERROR;
-       spin_unlock(&ud->lock);
+       spin_unlock_irqrestore(&ud->lock, flags);
 }
 
 static void vhci_device_init(struct vhci_device *vdev)
@@ -938,12 +951,13 @@ static int vhci_get_frame_number(struct usb_hcd *hcd)
 static int vhci_bus_suspend(struct usb_hcd *hcd)
 {
        struct vhci_hcd *vhci = hcd_to_vhci(hcd);
+       unsigned long flags;
 
        dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
 
-       spin_lock(&vhci->lock);
+       spin_lock_irqsave(&vhci->lock, flags);
        hcd->state = HC_STATE_SUSPENDED;
-       spin_unlock(&vhci->lock);
+       spin_unlock_irqrestore(&vhci->lock, flags);
 
        return 0;
 }
@@ -952,15 +966,16 @@ static int vhci_bus_resume(struct usb_hcd *hcd)
 {
        struct vhci_hcd *vhci = hcd_to_vhci(hcd);
        int rc = 0;
+       unsigned long flags;
 
        dev_dbg(&hcd->self.root_hub->dev, "%s\n", __func__);
 
-       spin_lock(&vhci->lock);
+       spin_lock_irqsave(&vhci->lock, flags);
        if (!HCD_HW_ACCESSIBLE(hcd))
                rc = -ESHUTDOWN;
        else
                hcd->state = HC_STATE_RUNNING;
-       spin_unlock(&vhci->lock);
+       spin_unlock_irqrestore(&vhci->lock, flags);
 
        return rc;
 }
@@ -1058,17 +1073,18 @@ static int vhci_hcd_suspend(struct platform_device *pdev, pm_message_t state)
        int rhport = 0;
        int connected = 0;
        int ret = 0;
+       unsigned long flags;
 
        hcd = platform_get_drvdata(pdev);
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
 
        for (rhport = 0; rhport < VHCI_NPORTS; rhport++)
                if (the_controller->port_status[rhport] &
                    USB_PORT_STAT_CONNECTION)
                        connected += 1;
 
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 
        if (connected > 0) {
                dev_info(&pdev->dev,
index 00e4a54..d656e0e 100644 (file)
@@ -72,10 +72,11 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
 {
        struct usbip_device *ud = &vdev->ud;
        struct urb *urb;
+       unsigned long flags;
 
-       spin_lock(&vdev->priv_lock);
+       spin_lock_irqsave(&vdev->priv_lock, flags);
        urb = pickup_urb_and_free_priv(vdev, pdu->base.seqnum);
-       spin_unlock(&vdev->priv_lock);
+       spin_unlock_irqrestore(&vdev->priv_lock, flags);
 
        if (!urb) {
                pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
@@ -104,9 +105,9 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
 
        usbip_dbg_vhci_rx("now giveback urb %p\n", urb);
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
        usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 
        usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb, urb->status);
 
@@ -117,8 +118,9 @@ static struct vhci_unlink *dequeue_pending_unlink(struct vhci_device *vdev,
                                                  struct usbip_header *pdu)
 {
        struct vhci_unlink *unlink, *tmp;
+       unsigned long flags;
 
-       spin_lock(&vdev->priv_lock);
+       spin_lock_irqsave(&vdev->priv_lock, flags);
 
        list_for_each_entry_safe(unlink, tmp, &vdev->unlink_rx, list) {
                pr_info("unlink->seqnum %lu\n", unlink->seqnum);
@@ -127,12 +129,12 @@ static struct vhci_unlink *dequeue_pending_unlink(struct vhci_device *vdev,
                                          unlink->seqnum);
                        list_del(&unlink->list);
 
-                       spin_unlock(&vdev->priv_lock);
+                       spin_unlock_irqrestore(&vdev->priv_lock, flags);
                        return unlink;
                }
        }
 
-       spin_unlock(&vdev->priv_lock);
+       spin_unlock_irqrestore(&vdev->priv_lock, flags);
 
        return NULL;
 }
@@ -142,6 +144,7 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
 {
        struct vhci_unlink *unlink;
        struct urb *urb;
+       unsigned long flags;
 
        usbip_dump_header(pdu);
 
@@ -152,9 +155,9 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
                return;
        }
 
-       spin_lock(&vdev->priv_lock);
+       spin_lock_irqsave(&vdev->priv_lock, flags);
        urb = pickup_urb_and_free_priv(vdev, unlink->unlink_seqnum);
-       spin_unlock(&vdev->priv_lock);
+       spin_unlock_irqrestore(&vdev->priv_lock, flags);
 
        if (!urb) {
                /*
@@ -171,9 +174,9 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
                urb->status = pdu->u.ret_unlink.status;
                pr_info("urb->status %d\n", urb->status);
 
-               spin_lock(&the_controller->lock);
+               spin_lock_irqsave(&the_controller->lock, flags);
                usb_hcd_unlink_urb_from_ep(vhci_to_hcd(the_controller), urb);
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
 
                usb_hcd_giveback_urb(vhci_to_hcd(the_controller), urb,
                                     urb->status);
@@ -185,10 +188,11 @@ static void vhci_recv_ret_unlink(struct vhci_device *vdev,
 static int vhci_priv_tx_empty(struct vhci_device *vdev)
 {
        int empty = 0;
+       unsigned long flags;
 
-       spin_lock(&vdev->priv_lock);
+       spin_lock_irqsave(&vdev->priv_lock, flags);
        empty = list_empty(&vdev->priv_rx);
-       spin_unlock(&vdev->priv_lock);
+       spin_unlock_irqrestore(&vdev->priv_lock, flags);
 
        return empty;
 }
index 211f43f..5b5462e 100644 (file)
@@ -32,10 +32,11 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
 {
        char *s = out;
        int i = 0;
+       unsigned long flags;
 
        BUG_ON(!the_controller || !out);
 
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
 
        /*
         * output example:
@@ -70,7 +71,7 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
                spin_unlock(&vdev->ud.lock);
        }
 
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 
        return out - s;
 }
@@ -80,11 +81,12 @@ static DEVICE_ATTR_RO(status);
 static int vhci_port_disconnect(__u32 rhport)
 {
        struct vhci_device *vdev;
+       unsigned long flags;
 
        usbip_dbg_vhci_sysfs("enter\n");
 
        /* lock */
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
 
        vdev = port_to_vdev(rhport);
 
@@ -94,14 +96,14 @@ static int vhci_port_disconnect(__u32 rhport)
 
                /* unlock */
                spin_unlock(&vdev->ud.lock);
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
 
                return -EINVAL;
        }
 
        /* unlock */
        spin_unlock(&vdev->ud.lock);
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
 
        usbip_event_add(&vdev->ud, VDEV_EVENT_DOWN);
 
@@ -177,6 +179,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
        int sockfd = 0;
        __u32 rhport = 0, devid = 0, speed = 0;
        int err;
+       unsigned long flags;
 
        /*
         * @rhport: port number of vhci_hcd
@@ -202,14 +205,14 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
        /* now need lock until setting vdev status as used */
 
        /* begin a lock */
-       spin_lock(&the_controller->lock);
+       spin_lock_irqsave(&the_controller->lock, flags);
        vdev = port_to_vdev(rhport);
        spin_lock(&vdev->ud.lock);
 
        if (vdev->ud.status != VDEV_ST_NULL) {
                /* end of the lock */
                spin_unlock(&vdev->ud.lock);
-               spin_unlock(&the_controller->lock);
+               spin_unlock_irqrestore(&the_controller->lock, flags);
 
                sockfd_put(socket);
 
@@ -227,7 +230,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
        vdev->ud.status     = VDEV_ST_NOTASSIGNED;
 
        spin_unlock(&vdev->ud.lock);
-       spin_unlock(&the_controller->lock);
+       spin_unlock_irqrestore(&the_controller->lock, flags);
        /* end the lock */
 
        vdev->ud.tcp_rx = kthread_get_run(vhci_rx_loop, &vdev->ud, "vhci_rx");
index 409fd99..3e7878f 100644 (file)
@@ -47,16 +47,17 @@ static void setup_cmd_submit_pdu(struct usbip_header *pdup,  struct urb *urb)
 static struct vhci_priv *dequeue_from_priv_tx(struct vhci_device *vdev)
 {
        struct vhci_priv *priv, *tmp;
+       unsigned long flags;
 
-       spin_lock(&vdev->priv_lock);
+       spin_lock_irqsave(&vdev->priv_lock, flags);
 
        list_for_each_entry_safe(priv, tmp, &vdev->priv_tx, list) {
                list_move_tail(&priv->list, &vdev->priv_rx);
-               spin_unlock(&vdev->priv_lock);
+               spin_unlock_irqrestore(&vdev->priv_lock, flags);
                return priv;
        }
 
-       spin_unlock(&vdev->priv_lock);
+       spin_unlock_irqrestore(&vdev->priv_lock, flags);
 
        return NULL;
 }
@@ -136,16 +137,17 @@ static int vhci_send_cmd_submit(struct vhci_device *vdev)
 static struct vhci_unlink *dequeue_from_unlink_tx(struct vhci_device *vdev)
 {
        struct vhci_unlink *unlink, *tmp;
+       unsigned long flags;
 
-       spin_lock(&vdev->priv_lock);
+       spin_lock_irqsave(&vdev->priv_lock, flags);
 
        list_for_each_entry_safe(unlink, tmp, &vdev->unlink_tx, list) {
                list_move_tail(&unlink->list, &vdev->unlink_rx);
-               spin_unlock(&vdev->priv_lock);
+               spin_unlock_irqrestore(&vdev->priv_lock, flags);
                return unlink;
        }
 
-       spin_unlock(&vdev->priv_lock);
+       spin_unlock_irqrestore(&vdev->priv_lock, flags);
 
        return NULL;
 }
index 41838db..8c5bd00 100644 (file)
@@ -336,7 +336,7 @@ static inline
 struct usb_hcd *usb_hcd_get_by_usb_dev(struct usb_device *usb_dev)
 {
        struct usb_hcd *usb_hcd;
-       usb_hcd = container_of(usb_dev->bus, struct usb_hcd, self);
+       usb_hcd = bus_to_hcd(usb_dev->bus);
        return usb_get_hcd(usb_hcd);
 }
 
index 6d6f1fe..2d0e6e5 100644 (file)
@@ -958,6 +958,11 @@ static inline void device_lock(struct device *dev)
        mutex_lock(&dev->mutex);
 }
 
+static inline int device_lock_interruptible(struct device *dev)
+{
+       return mutex_lock_interruptible(&dev->mutex);
+}
+
 static inline int device_trylock(struct device *dev)
 {
        return mutex_trylock(&dev->mutex);
index 89533ba..6a9a0c2 100644 (file)
@@ -50,6 +50,7 @@ struct ep_device;
  * struct usb_host_endpoint - host-side endpoint descriptor and queue
  * @desc: descriptor for this endpoint, wMaxPacketSize in native byteorder
  * @ss_ep_comp: SuperSpeed companion descriptor for this endpoint
+ * @ssp_isoc_ep_comp: SuperSpeedPlus isoc companion descriptor for this endpoint
  * @urb_list: urbs queued to this endpoint; maintained by usbcore
  * @hcpriv: for use by HCD; typically holds hardware dma queue head (QH)
  *     with one or more transfer descriptors (TDs) per urb
@@ -65,6 +66,7 @@ struct ep_device;
 struct usb_host_endpoint {
        struct usb_endpoint_descriptor          desc;
        struct usb_ss_ep_comp_descriptor        ss_ep_comp;
+       struct usb_ssp_isoc_ep_comp_descriptor  ssp_isoc_ep_comp;
        struct list_head                urb_list;
        void                            *hcpriv;
        struct ep_device                *ep_dev;        /* For sysfs info */
@@ -330,6 +332,7 @@ struct usb_host_bos {
        struct usb_ss_cap_descriptor    *ss_cap;
        struct usb_ssp_cap_descriptor   *ssp_cap;
        struct usb_ss_container_id_descriptor   *ss_id;
+       struct usb_ptm_cap_descriptor   *ptm_cap;
 };
 
 int __usb_get_extra_descriptor(char *buffer, unsigned size,
@@ -375,7 +378,6 @@ struct usb_bus {
        struct usb_devmap devmap;       /* device address allocation map */
        struct usb_device *root_hub;    /* Root hub */
        struct usb_bus *hs_companion;   /* Companion EHCI bus, if any */
-       struct list_head bus_list;      /* list of busses */
 
        struct mutex usb_address0_mutex; /* unaddressed device mutex */
 
@@ -642,9 +644,10 @@ extern struct usb_device *usb_hub_find_child(struct usb_device *hdev,
                if (!child) continue; else
 
 /* USB device locking */
-#define usb_lock_device(udev)          device_lock(&(udev)->dev)
-#define usb_unlock_device(udev)                device_unlock(&(udev)->dev)
-#define usb_trylock_device(udev)       device_trylock(&(udev)->dev)
+#define usb_lock_device(udev)                  device_lock(&(udev)->dev)
+#define usb_unlock_device(udev)                        device_unlock(&(udev)->dev)
+#define usb_lock_device_interruptible(udev)    device_lock_interruptible(&(udev)->dev)
+#define usb_trylock_device(udev)               device_trylock(&(udev)->dev)
 extern int usb_lock_device_for_reset(struct usb_device *udev,
                                     const struct usb_interface *iface);
 
index 4dcf844..b98f831 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <linux/rwsem.h>
 #include <linux/interrupt.h>
+#include <linux/idr.h>
 
 #define MAX_TOPO_LEVEL         6
 
@@ -630,8 +631,8 @@ extern void usb_set_device_state(struct usb_device *udev,
 
 /* exported only within usbcore */
 
-extern struct list_head usb_bus_list;
-extern struct mutex usb_bus_list_lock;
+extern struct idr usb_bus_idr;
+extern struct mutex usb_bus_idr_lock;
 extern wait_queue_head_t usb_kill_urb_queue;
 
 
index e159b39..974c379 100644 (file)
@@ -22,6 +22,7 @@
 #define USB_AHBBURST         (MSM_USB_BASE + 0x0090)
 #define USB_AHBMODE          (MSM_USB_BASE + 0x0098)
 #define USB_GENCONFIG_2      (MSM_USB_BASE + 0x00a0)
+#define ULPI_TX_PKT_EN_CLR_FIX BIT(19)
 
 #define USB_CAPLENGTH        (MSM_USB_BASE + 0x0100) /* 8 bit */
 
index cb33fff..305ee8d 100644 (file)
@@ -45,9 +45,9 @@
 
 #define USB_PR_DEVICE  0xff            /* Use device's value */
 
- /*
 * Bulk only data structures
 */
+/*
+ * Bulk only data structures
+ */
 
 /* command block wrapper */
 struct bulk_cb_wrap {
@@ -56,18 +56,18 @@ struct bulk_cb_wrap {
        __le32  DataTransferLength;     /* size of data */
        __u8    Flags;                  /* direction in bit 0 */
        __u8    Lun;                    /* LUN normally 0 */
-       __u8    Length;                 /* of of the CDB */
+       __u8    Length;                 /* length of the CDB */
        __u8    CDB[16];                /* max command */
 };
 
 #define US_BULK_CB_WRAP_LEN    31
-#define US_BULK_CB_SIGN                0x43425355      /*spells out USBC */
+#define US_BULK_CB_SIGN                0x43425355      /* spells out 'USBC' */
 #define US_BULK_FLAG_IN                (1 << 7)
 #define US_BULK_FLAG_OUT       0
 
 /* command status wrapper */
 struct bulk_cs_wrap {
-       __le32  Signature;      /* should = 'USBS' */
+       __le32  Signature;      /* contains 'USBS' */
        __u32   Tag;            /* same as original command */
        __le32  Residue;        /* amount not transferred */
        __u8    Status;         /* see below */
index 331499d..361297e 100644 (file)
 #define USB_RT_HUB     (USB_TYPE_CLASS | USB_RECIP_DEVICE)
 #define USB_RT_PORT    (USB_TYPE_CLASS | USB_RECIP_OTHER)
 
+/*
+ * Port status type for GetPortStatus requests added in USB 3.1
+ * See USB 3.1 spec Table 10-12
+ */
+#define HUB_PORT_STATUS                0
+#define HUB_PORT_PD_STATUS     1
+#define HUB_EXT_PORT_STATUS    2
+
 /*
  * Hub class requests
  * See USB 2.0 spec Table 11-16
 /*
  * Hub Status and Hub Change results
  * See USB 2.0 spec Table 11-19 and Table 11-20
+ * USB 3.1 extends the port status request and may return 4 additional bytes.
+ * See USB 3.1 spec section 10.16.2.6 Table 10-12 and 10-15
  */
 struct usb_port_status {
        __le16 wPortStatus;
        __le16 wPortChange;
+       __le32 dwExtPortStatus;
 } __attribute__ ((packed));
 
 /*
@@ -172,6 +183,16 @@ struct usb_port_status {
 #define USB_PORT_STAT_C_LINK_STATE     0x0040
 #define USB_PORT_STAT_C_CONFIG_ERROR   0x0080
 
+/*
+ * USB 3.1 dwExtPortStatus field masks
+ * See USB 3.1 spec 10.16.2.6.3 Table 10-15
+ */
+
+#define USB_EXT_PORT_STAT_RX_SPEED_ID  0x0000000f
+#define USB_EXT_PORT_STAT_TX_SPEED_ID  0x000000f0
+#define USB_EXT_PORT_STAT_RX_LANES     0x00000f00
+#define USB_EXT_PORT_STAT_TX_LANES     0x0000f000
+
 /*
  * wHubCharacteristics (masks)
  * See USB 2.0 spec Table 11-13, offset 3
index 4338eb7..252ac16 100644 (file)
@@ -234,6 +234,8 @@ struct usb_ctrlrequest {
 #define USB_DT_PIPE_USAGE              0x24
 /* From the USB 3.0 spec */
 #define        USB_DT_SS_ENDPOINT_COMP         0x30
+/* From the USB 3.1 spec */
+#define        USB_DT_SSP_ISOC_ENDPOINT_COMP   0x31
 
 /* Conventional codes for class-specific descriptors.  The convention is
  * defined in the USB "Common Class" Spec (3.11).  Individual class specs
@@ -613,6 +615,20 @@ static inline int usb_endpoint_interrupt_type(
 
 /*-------------------------------------------------------------------------*/
 
+/* USB_DT_SSP_ISOC_ENDPOINT_COMP: SuperSpeedPlus Isochronous Endpoint Companion
+ * descriptor
+ */
+struct usb_ssp_isoc_ep_comp_descriptor {
+       __u8  bLength;
+       __u8  bDescriptorType;
+       __le16 wReseved;
+       __le32 dwBytesPerInterval;
+} __attribute__ ((packed));
+
+#define USB_DT_SSP_ISOC_EP_COMP_SIZE           8
+
+/*-------------------------------------------------------------------------*/
+
 /* USB_DT_SS_ENDPOINT_COMP: SuperSpeed Endpoint Companion descriptor */
 struct usb_ss_ep_comp_descriptor {
        __u8  bLength;
@@ -646,6 +662,8 @@ usb_ss_max_streams(const struct usb_ss_ep_comp_descriptor *comp)
 
 /* Bits 1:0 of bmAttributes if this is an isoc endpoint */
 #define USB_SS_MULT(p)                 (1 + ((p) & 0x3))
+/* Bit 7 of bmAttributes if a SSP isoc endpoint companion descriptor exists */
+#define USB_SS_SSP_ISOC_COMP(p)                ((p) & (1 << 7))
 
 /*-------------------------------------------------------------------------*/
 
@@ -894,6 +912,16 @@ struct usb_ssp_cap_descriptor {
 #define USB_SSP_SUBLINK_SPEED_LSM      (0xff << 16)    /* Lanespeed mantissa */
 } __attribute__((packed));
 
+/*
+ * Precision time measurement capability descriptor: advertised by devices and
+ * hubs that support PTM
+ */
+#define        USB_PTM_CAP_TYPE        0xb
+struct usb_ptm_cap_descriptor {
+       __u8  bLength;
+       __u8  bDescriptorType;
+       __u8  bDevCapabilityType;
+} __attribute__((packed));
 
 /*-------------------------------------------------------------------------*/
 
@@ -954,6 +982,7 @@ enum usb_device_speed {
        USB_SPEED_HIGH,                         /* usb 2.0 */
        USB_SPEED_WIRELESS,                     /* wireless (usb 2.5) */
        USB_SPEED_SUPER,                        /* usb 3.0 */
+       USB_SPEED_SUPER_PLUS,                   /* usb 3.1 */
 };
 
 
index c045ae1..2e59d9c 100644 (file)
@@ -2,12 +2,14 @@
  * Copyright (C) 2007 Stefan Kopp, Gechingen, Germany
  * Copyright (C) 2008 Novell, Inc.
  * Copyright (C) 2008 Greg Kroah-Hartman <gregkh@suse.de>
+ * Copyright (C) 2015 Dave Penkler <dpenkler@gmail.com>
  *
  * This file holds USB constants defined by the USB Device Class
- * Definition for Test and Measurement devices published by the USB-IF.
+ * and USB488 Subclass Definitions for Test and Measurement devices
+ * published by the USB-IF.
  *
- * It also has the ioctl definitions for the usbtmc kernel driver that
- * userspace needs to know about.
+ * It also has the ioctl and capability definitions for the
+ * usbtmc kernel driver that userspace needs to know about.
  */
 
 #ifndef __LINUX_USB_TMC_H
 #define USBTMC_REQUEST_CHECK_CLEAR_STATUS              6
 #define USBTMC_REQUEST_GET_CAPABILITIES                        7
 #define USBTMC_REQUEST_INDICATOR_PULSE                 64
+#define USBTMC488_REQUEST_READ_STATUS_BYTE             128
+#define USBTMC488_REQUEST_REN_CONTROL                  160
+#define USBTMC488_REQUEST_GOTO_LOCAL                   161
+#define USBTMC488_REQUEST_LOCAL_LOCKOUT                        162
 
 /* Request values for USBTMC driver's ioctl entry point */
 #define USBTMC_IOC_NR                  91
 #define USBTMC_IOCTL_ABORT_BULK_IN     _IO(USBTMC_IOC_NR, 4)
 #define USBTMC_IOCTL_CLEAR_OUT_HALT    _IO(USBTMC_IOC_NR, 6)
 #define USBTMC_IOCTL_CLEAR_IN_HALT     _IO(USBTMC_IOC_NR, 7)
+#define USBTMC488_IOCTL_GET_CAPS       _IOR(USBTMC_IOC_NR, 17, unsigned char)
+#define USBTMC488_IOCTL_READ_STB       _IOR(USBTMC_IOC_NR, 18, unsigned char)
+#define USBTMC488_IOCTL_REN_CONTROL    _IOW(USBTMC_IOC_NR, 19, unsigned char)
+#define USBTMC488_IOCTL_GOTO_LOCAL     _IO(USBTMC_IOC_NR, 20)
+#define USBTMC488_IOCTL_LOCAL_LOCKOUT  _IO(USBTMC_IOC_NR, 21)
+
+/* Driver encoded usb488 capabilities */
+#define USBTMC488_CAPABILITY_TRIGGER         1
+#define USBTMC488_CAPABILITY_SIMPLE          2
+#define USBTMC488_CAPABILITY_REN_CONTROL     2
+#define USBTMC488_CAPABILITY_GOTO_LOCAL      2
+#define USBTMC488_CAPABILITY_LOCAL_LOCKOUT   2
+#define USBTMC488_CAPABILITY_488_DOT_2       4
+#define USBTMC488_CAPABILITY_DT1             16
+#define USBTMC488_CAPABILITY_RL1             32
+#define USBTMC488_CAPABILITY_SR1             64
+#define USBTMC488_CAPABILITY_FULL_SCPI       128
 
 #endif
index 019ba1e..ecbd176 100644 (file)
@@ -134,6 +134,7 @@ struct usbdevfs_hub_portinfo {
 #define USBDEVFS_CAP_NO_PACKET_SIZE_LIM                0x04
 #define USBDEVFS_CAP_BULK_SCATTER_GATHER       0x08
 #define USBDEVFS_CAP_REAP_AFTER_DISCONNECT     0x10
+#define USBDEVFS_CAP_MMAP                      0x20
 
 /* USBDEVFS_DISCONNECT_CLAIM flags & struct */