ia64/xen-unstable

changeset 3838:a58b3f082755

bitkeeper revision 1.1206 (421298acOZi7dg5p-4vCDkR8RsPqRA)

Merge ssh://maw48@freefall.cl.cam.ac.uk//auto/groups/xeno/BK/xeno.bk
into equilibrium.research:/home/irchomes/mwilli2/src/xen-3.0-devel.bk
author mwilli2@equilibrium.research
date Wed Feb 16 00:49:48 2005 +0000 (2005-02-16)
parents 73f9c9685211 a5092d2c64ea
children d52b92174eee
files linux-2.6.10-xen-sparse/drivers/xen/usbback/usbback.c linux-2.6.10-xen-sparse/drivers/xen/usbfront/usbfront.c
line diff
     1.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/usbback/usbback.c	Mon Feb 14 13:05:43 2005 +0000
     1.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/usbback/usbback.c	Wed Feb 16 00:49:48 2005 +0000
     1.3 @@ -69,7 +69,6 @@ typedef struct
     1.4   */
     1.5  typedef struct {
     1.6      usbif_priv_t       *usbif_priv;
     1.7 -    usbif_iso_t        *iso_sched;
     1.8      unsigned long      id;
     1.9      int                nr_pages;
    1.10      unsigned short     operation;
    1.11 @@ -280,8 +279,6 @@ static void __end_usb_io_op(struct urb *
    1.12          int i;
    1.13          usbif_iso_t *sched = (usbif_iso_t *)MMAP_VADDR(pending_idx, pending_req->nr_pages - 1);
    1.14  
    1.15 -        ASSERT(sched == pending_req->sched);
    1.16 -
    1.17          /* If we're dealing with an iso pipe, we need to copy back the schedule. */
    1.18          for ( i = 0; i < purb->number_of_packets; i++ )
    1.19          {
    1.20 @@ -501,6 +498,32 @@ static void dispatch_usb_probe(usbif_pri
    1.21      make_response(up, id, USBIF_OP_PROBE, ret, portid, 0);
    1.22  }
    1.23  
    1.24 +/**
    1.25 + * check_iso_schedule - safety check the isochronous schedule for an URB
    1.26 + * @purb : the URB in question
    1.27 + */
    1.28 +static int check_iso_schedule(struct urb *purb)
    1.29 +{
    1.30 +    int i;
    1.31 +    unsigned long total_length = 0;
    1.32 +    
    1.33 +    for ( i = 0; i < purb->number_of_packets; i++ )
    1.34 +    {
    1.35 +        struct usb_iso_packet_descriptor *desc = &purb->iso_frame_desc[i];
    1.36 +        
    1.37 +        if ( desc->offset >= purb->transfer_buffer_length
    1.38 +            || ( desc->offset + desc->length) > purb->transfer_buffer_length )
    1.39 +            return -EINVAL;
    1.40 +
    1.41 +        total_length += desc->length;
    1.42 +
    1.43 +        if ( total_length > purb->transfer_buffer_length )
    1.44 +            return -EINVAL;
    1.45 +    }
    1.46 +    
    1.47 +    return 0;
    1.48 +}
    1.49 +
    1.50  owned_port_t *find_port_for_request(usbif_priv_t *up, usbif_request_t *req);
    1.51  
    1.52  static void dispatch_usb_io(usbif_priv_t *up, usbif_request_t *req)
    1.53 @@ -588,7 +611,6 @@ static void dispatch_usb_io(usbif_priv_t
    1.54          kfree(setup);
    1.55          return;
    1.56      }
    1.57 -
    1.58      else if ( setup[0] == 0x1 && setup[1] == 0xB )
    1.59      {
    1.60          /* The host kernel needs to know what device interface is in use
    1.61 @@ -719,8 +741,11 @@ static void dispatch_usb_io(usbif_priv_t
    1.62  
    1.63      purb->number_of_packets = req->num_iso;
    1.64  
    1.65 +    if ( purb->number_of_packets * sizeof(usbif_iso_t) > PAGE_SIZE )
    1.66 +        goto urb_error;
    1.67 +
    1.68      /* Make sure there's always some kind of timeout. */
    1.69 -    purb->timeout = ( req->timeout > 0 ) ?  (req->timeout * HZ) / 1000
    1.70 +    purb->timeout = ( req->timeout > 0 ) ? (req->timeout * HZ) / 1000
    1.71                      :  1000;
    1.72  
    1.73      purb->setup_packet = setup;
    1.74 @@ -731,31 +756,27 @@ static void dispatch_usb_io(usbif_priv_t
    1.75          usbif_iso_t *iso_sched = (usbif_iso_t *)MMAP_VADDR(pending_idx, i - 1);
    1.76  
    1.77          /* If we're dealing with an iso pipe, we need to copy in a schedule. */
    1.78 -        for ( j = 0; j < req->num_iso; j++ )
    1.79 +        for ( j = 0; j < purb->number_of_packets; j++ )
    1.80          {
    1.81              purb->iso_frame_desc[j].length = iso_sched[j].length;
    1.82              purb->iso_frame_desc[j].offset = iso_sched[j].buffer_offset;
    1.83              iso_sched[j].status = 0;
    1.84          }
    1.85 -        pending_req->iso_sched = iso_sched;
    1.86      }
    1.87  
    1.88 -    {
    1.89 -        int ret;
    1.90 -        ret = usb_submit_urb(purb);
    1.91 -        
    1.92 -        dump_urb(purb);
    1.93 -        
    1.94 -        if ( ret != 0 )
    1.95 -        {
    1.96 -            usbif_put(up);
    1.97 -            free_pending(pending_idx);
    1.98 -            goto bad_descriptor;
    1.99 -        }
   1.100 -    }
   1.101 -    
   1.102 +    if ( check_iso_schedule(purb) != 0 )
   1.103 +        goto urb_error;
   1.104 +
   1.105 +    if ( usb_submit_urb(purb) != 0 )
   1.106 +        goto urb_error;
   1.107 +
   1.108      return;
   1.109  
   1.110 + urb_error:
   1.111 +    dump_urb(purb);    
   1.112 +    usbif_put(up);
   1.113 +    free_pending(pending_idx);
   1.114 +
   1.115   bad_descriptor:
   1.116      kfree ( setup );
   1.117      if ( purb != NULL )
     2.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/usbfront/usbfront.c	Mon Feb 14 13:05:43 2005 +0000
     2.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/usbfront/usbfront.c	Wed Feb 16 00:49:48 2005 +0000
     2.3 @@ -6,21 +6,14 @@
     2.4   *
     2.5   * Based on Linux's uhci.c, original copyright notices are displayed
     2.6   * below.  Portions also (c) 2004 Intel Research Cambridge
     2.7 - * and (c) 2004 Mark Williamson
     2.8 + * and (c) 2004, 2005 Mark Williamson
     2.9   *
    2.10   * Contact <mark.williamson@cl.cam.ac.uk> or
    2.11   * <xen-devel@lists.sourceforge.net> regarding this code.
    2.12   *
    2.13   * Still to be (maybe) implemented:
    2.14 - * - multiple port
    2.15 - * - multiple interfaces
    2.16   * - migration / backend restart support?
    2.17 - * - unloading support
    2.18 - *
    2.19 - * Differences to a normal host controller:
    2.20 - * - the backend does most of the mucky stuff so we don't have to do various
    2.21 - *   things that are necessary for a normal host controller (e.g. FSBR).
    2.22 - * - we don't have any hardware, so status registers are simulated in software.
    2.23 + * - support for building / using as a module
    2.24   */
    2.25  
    2.26  /*
    2.27 @@ -55,13 +48,11 @@
    2.28  #include <linux/module.h>
    2.29  #include <linux/kernel.h>
    2.30  #include <linux/init.h>
    2.31 +#include <linux/sched.h>
    2.32  #include <linux/delay.h>
    2.33 -#include <linux/ioport.h>
    2.34 -#include <linux/sched.h>
    2.35  #include <linux/slab.h>
    2.36  #include <linux/smp_lock.h>
    2.37  #include <linux/errno.h>
    2.38 -#include <linux/unistd.h>
    2.39  #include <linux/interrupt.h>
    2.40  #include <linux/spinlock.h>
    2.41  #ifdef CONFIG_USB_DEBUG
    2.42 @@ -71,14 +62,11 @@
    2.43  #endif
    2.44  #include <linux/usb.h>
    2.45  
    2.46 -#include <asm/uaccess.h>
    2.47  #include <asm/irq.h>
    2.48  #include <asm/system.h>
    2.49  
    2.50  #include "xhci.h"
    2.51  
    2.52 -#include <linux/pm.h>
    2.53 -
    2.54  #include "../../../../../drivers/usb/hcd.h"
    2.55  
    2.56  #include <asm-xen/xen-public/io/usbif.h>
    2.57 @@ -89,8 +77,10 @@
    2.58   * Version Information
    2.59   */
    2.60  #define DRIVER_VERSION "v1.0"
    2.61 -#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, Mark Williamson"
    2.62 -#define DRIVER_DESC "Xen Virtual USB Host Controller Interface driver"
    2.63 +#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, " \
    2.64 +                      "Randy Dunlap, Georg Acher, Deti Fliegl, " \
    2.65 +                      "Thomas Sailer, Roman Weissgaerber, Mark Williamson"
    2.66 +#define DRIVER_DESC "Xen Virtual USB Host Controller Interface"
    2.67  
    2.68  /*
    2.69   * debug = 0, no debugging messages
    2.70 @@ -107,26 +97,22 @@ MODULE_PARM_DESC(debug, "Debug level");
    2.71  static char *errbuf;
    2.72  #define ERRBUF_LEN    (PAGE_SIZE * 8)
    2.73  
    2.74 -static kmem_cache_t *xhci_up_cachep;	/* urb_priv */
    2.75 -
    2.76  static int rh_submit_urb(struct urb *urb);
    2.77  static int rh_unlink_urb(struct urb *urb);
    2.78 -//static int xhci_get_current_frame_number(struct usb_device *dev);
    2.79  static int xhci_unlink_urb(struct urb *urb);
    2.80 -static void xhci_unlink_generic(struct urb *urb);
    2.81  static void xhci_call_completion(struct urb *urb);
    2.82  static void xhci_drain_ring(void);
    2.83 +static void xhci_transfer_result(struct xhci *xhci, struct urb *urb);
    2.84 +static void xhci_finish_completion(void);
    2.85  
    2.86  #define MAX_URB_LOOP	2048		/* Maximum number of linked URB's */
    2.87  
    2.88 -static struct xhci *xhci;
    2.89 +static kmem_cache_t *xhci_up_cachep;	/* urb_priv cache */
    2.90 +static struct xhci *xhci;               /* XHCI structure for the interface */
    2.91  
    2.92 -enum { USBIF_STATE_CONNECTED = 2,
    2.93 -       USBIF_STATE_DISCONNECTED = 1,
    2.94 -       USBIF_STATE_CLOSED =0
    2.95 -};
    2.96 -
    2.97 -static int awaiting_reset = 0;
    2.98 +/******************************************************************************
    2.99 + * DEBUGGING
   2.100 + */
   2.101  
   2.102  #ifdef DEBUG
   2.103  
   2.104 @@ -145,13 +131,16 @@ static void dump_urb(struct urb *urb)
   2.105             "  bandwidth = %d\n"
   2.106             "  setup_packet = %p\n",
   2.107             urb, urb->hcpriv, urb->next, urb->dev, urb->pipe, urb->status,
   2.108 -           urb->transfer_flags, urb->transfer_buffer, urb->transfer_buffer_length,
   2.109 -           urb->actual_length, urb->bandwidth, urb->setup_packet);
   2.110 +           urb->transfer_flags, urb->transfer_buffer,
   2.111 +           urb->transfer_buffer_length, urb->actual_length, urb->bandwidth,
   2.112 +           urb->setup_packet);
   2.113      if ( urb->setup_packet != NULL )
   2.114          printk(KERN_DEBUG
   2.115                 "setup = { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x }\n",
   2.116 -               urb->setup_packet[0], urb->setup_packet[1], urb->setup_packet[2], urb->setup_packet[3],
   2.117 -               urb->setup_packet[4], urb->setup_packet[5], urb->setup_packet[6], urb->setup_packet[7]);
   2.118 +               urb->setup_packet[0], urb->setup_packet[1],
   2.119 +               urb->setup_packet[2], urb->setup_packet[3],
   2.120 +               urb->setup_packet[4], urb->setup_packet[5],
   2.121 +               urb->setup_packet[6], urb->setup_packet[7]);
   2.122      printk(KERN_DEBUG "complete = %p\n"
   2.123             "interval = %d\n", urb->complete, urb->interval);
   2.124          
   2.125 @@ -178,6 +167,10 @@ static void xhci_show_resp(usbif_respons
   2.126  
   2.127  #endif /* DEBUG */
   2.128  
   2.129 +/******************************************************************************
   2.130 + * RING REQUEST HANDLING
   2.131 + */
   2.132 +
   2.133  /**
   2.134   * xhci_construct_isoc - add isochronous information to a request
   2.135   */
   2.136 @@ -205,6 +198,9 @@ static int xhci_construct_isoc(usbif_req
   2.137          return 0;
   2.138  }
   2.139  
   2.140 +/**
   2.141 + * xhci_queue_req - construct and queue request for an URB
   2.142 + */
   2.143  static int xhci_queue_req(struct urb *urb)
   2.144  {
   2.145          usbif_request_t *req;
   2.146 @@ -265,6 +261,9 @@ static int xhci_queue_req(struct urb *ur
   2.147          return -EINPROGRESS;
   2.148  }
   2.149  
   2.150 +/**
   2.151 + * xhci_queue_probe - queue a probe request for a particular port
   2.152 + */
   2.153  static inline usbif_request_t *xhci_queue_probe(usbif_vdev_t port)
   2.154  {
   2.155          usbif_request_t *req;
   2.156 @@ -272,33 +271,26 @@ static inline usbif_request_t *xhci_queu
   2.157  
   2.158  #if DEBUG
   2.159  	printk(KERN_DEBUG
   2.160 -               "queuing probe: req_prod = %d (@ 0x%lx), resp_prod = %d, resp_cons = %d\n",
   2.161 -	       usbif->req_prod, virt_to_machine(&usbif->req_prod),
   2.162 +               "queuing probe: req_prod = %d (@ 0x%lx), resp_prod = %d, "
   2.163 +               "resp_cons = %d\n", usbif->req_prod,
   2.164 +               virt_to_machine(&usbif->req_prod),
   2.165  	       usbif->resp_prod, xhci->usb_resp_cons);
   2.166  #endif
   2.167          
   2.168          if ( RING_FULL(USBIF_RING, usb_ring) )
   2.169          {
   2.170                  printk(KERN_WARNING
   2.171 -                       "xhci_queue_probe(): USB ring full, not queuing request\n");
   2.172 +                       "xhci_queue_probe(): ring full, not queuing request\n");
   2.173                  return NULL;
   2.174          }
   2.175  
   2.176          /* Stick something in the shared communications ring. */
   2.177          req = RING_GET_REQUEST(USBIF_RING, usb_ring, usb_ring->req_prod_pvt);
   2.178  
   2.179 +        memset(req, sizeof(*req), 0);
   2.180 +
   2.181          req->operation       = USBIF_OP_PROBE;
   2.182          req->port            = port;
   2.183 -        req->id              = 0;
   2.184 -        req->transfer_buffer = 0;
   2.185 -	req->devnum          = 0;
   2.186 -        req->direction       = 0;
   2.187 -	req->speed           = 0;
   2.188 -        req->pipe_type       = 0;
   2.189 -        req->length          = 0;
   2.190 -        req->transfer_flags  = 0;
   2.191 -	req->endpoint        = 0;
   2.192 -	req->speed           = 0;
   2.193  
   2.194          usb_ring->req_prod_pvt++;
   2.195          RING_PUSH_REQUESTS(USBIF_RING, usb_ring);
   2.196 @@ -308,6 +300,9 @@ static inline usbif_request_t *xhci_queu
   2.197          return req;
   2.198  }
   2.199  
   2.200 +/**
   2.201 + * xhci_port_reset - queue a reset request for a particular port
   2.202 + */
   2.203  static int xhci_port_reset(usbif_vdev_t port)
   2.204  {
   2.205          usbif_request_t *req;
   2.206 @@ -315,11 +310,13 @@ static int xhci_port_reset(usbif_vdev_t 
   2.207  
   2.208          /* We only reset one port at a time, so we only need one variable per
   2.209           * hub. */
   2.210 -        awaiting_reset = 1;
   2.211 +        xhci->awaiting_reset = 1;
   2.212          
   2.213          /* Stick something in the shared communications ring. */
   2.214  	req = RING_GET_REQUEST(USBIF_RING, usb_ring, usb_ring->req_prod_pvt);
   2.215  
   2.216 +        memset(req, sizeof(*req), 0);
   2.217 +
   2.218          req->operation       = USBIF_OP_RESET;
   2.219          req->port            = port;
   2.220          
   2.221 @@ -328,25 +325,167 @@ static int xhci_port_reset(usbif_vdev_t 
   2.222  
   2.223  	notify_via_evtchn(xhci->evtchn);
   2.224  
   2.225 -        while ( awaiting_reset > 0 )
   2.226 +        while ( xhci->awaiting_reset > 0 )
   2.227          {
   2.228                  mdelay(1);
   2.229                  xhci_drain_ring();
   2.230          }
   2.231  
   2.232 -        return awaiting_reset;
   2.233 +        return xhci->awaiting_reset;
   2.234  }
   2.235  
   2.236  
   2.237 -/*
   2.238 - * Only the USB core should call xhci_alloc_dev and xhci_free_dev
   2.239 +/******************************************************************************
   2.240 + * RING RESPONSE HANDLING
   2.241   */
   2.242 -static int xhci_alloc_dev(struct usb_device *dev)
   2.243 +
   2.244 +static void receive_usb_reset(usbif_response_t *resp)
   2.245 +{
   2.246 +    xhci->awaiting_reset = resp->status;
   2.247 +    rmb();
   2.248 +    
   2.249 +}
   2.250 +
   2.251 +static void receive_usb_probe(usbif_response_t *resp)
   2.252  {
   2.253 -	return 0;
   2.254 +    spin_lock(&xhci->rh.port_state_lock);
   2.255 +
   2.256 +    if ( resp->status > 0 )
   2.257 +    {
   2.258 +        if ( resp->status == 1 )
   2.259 +        {
   2.260 +            /* If theres a device there and there wasn't one before there must
   2.261 +             * have been a connection status change. */
   2.262 +            if( xhci->rh.ports[resp->data].cs == 0 )
   2.263 +	    {
   2.264 +                xhci->rh.ports[resp->data].cs = 1;
   2.265 +                xhci->rh.ports[resp->data].ccs = 1;
   2.266 +                xhci->rh.ports[resp->data].cs_chg = 1;
   2.267 +	    }
   2.268 +        }
   2.269 +        else
   2.270 +            printk(KERN_WARNING "receive_usb_probe(): unexpected status %d "
   2.271 +                   "for port %d\n", resp->status, resp->data);
   2.272 +    }
   2.273 +    else if ( resp->status < 0)
   2.274 +        printk(KERN_WARNING "receive_usb_probe(): got error status %d\n",
   2.275 +               resp->status);
   2.276 +
   2.277 +    spin_unlock(&xhci->rh.port_state_lock);
   2.278 +}
   2.279 +
   2.280 +static void receive_usb_io(usbif_response_t *resp)
   2.281 +{
   2.282 +        struct urb_priv *urbp = (struct urb_priv *)resp->id;
   2.283 +        struct urb *urb = urbp->urb;
   2.284 +
   2.285 +        urb->actual_length = resp->length;
   2.286 +	urb->status = resp->status;
   2.287 +	urbp->status = resp->status;
   2.288 +        urbp->in_progress = 0;
   2.289 +
   2.290 +        if( usb_pipetype(urb->pipe) == 0 ) /* ISO */
   2.291 +        {
   2.292 +                int i;
   2.293 +              
   2.294 +                /* Copy ISO schedule results back in. */
   2.295 +                for ( i = 0; i < urb->number_of_packets; i++ )
   2.296 +                {
   2.297 +                        urb->iso_frame_desc[i].status
   2.298 +                                = urbp->schedule[i].status;
   2.299 +                        urb->iso_frame_desc[i].actual_length
   2.300 +                                = urbp->schedule[i].length;
   2.301 +                }
   2.302 +                free_page((unsigned long)urbp->schedule);
   2.303 +        }
   2.304  }
   2.305  
   2.306 -static int xhci_free_dev(struct usb_device *dev)
   2.307 +/**
   2.308 + * xhci_drain_ring - drain responses from the ring, calling handlers
   2.309 + *
   2.310 + * This may be called from interrupt context when an event is received from the
   2.311 + * backend domain, or sometimes in process context whilst waiting for a port
   2.312 + * reset or URB completion.
   2.313 + */
   2.314 +static void xhci_drain_ring(void)
   2.315 +{
   2.316 +	struct list_head *tmp, *head;
   2.317 +	usbif_front_ring_t *usb_ring = &xhci->usb_ring;
   2.318 +	usbif_response_t *resp;
   2.319 +        RING_IDX i, rp;
   2.320 +
   2.321 +        /* Walk the ring here to get responses, updating URBs to show what
   2.322 +         * completed. */
   2.323 +        
   2.324 +        rp = usb_ring->sring->rsp_prod;
   2.325 +        rmb(); /* Ensure we see queued requests up to 'rp'. */
   2.326 +
   2.327 +        /* Take items off the comms ring, taking care not to overflow. */
   2.328 +        for ( i = usb_ring->rsp_cons; i != rp; i++ )
   2.329 +        {
   2.330 +            resp = RING_GET_RESPONSE(USBIF_RING, usb_ring, i);
   2.331 +            
   2.332 +            /* May need to deal with batching and with putting a ceiling on
   2.333 +               the number dispatched for performance and anti-dos reasons */
   2.334 +
   2.335 +            xhci_show_resp(resp);
   2.336 +
   2.337 +            switch ( resp->operation )
   2.338 +            {
   2.339 +            case USBIF_OP_PROBE:
   2.340 +                receive_usb_probe(resp);
   2.341 +                break;
   2.342 +                
   2.343 +            case USBIF_OP_IO:
   2.344 +                receive_usb_io(resp);
   2.345 +                break;
   2.346 +
   2.347 +            case USBIF_OP_RESET:
   2.348 +                receive_usb_reset(resp);
   2.349 +                break;
   2.350 +
   2.351 +            default:
   2.352 +                printk(KERN_WARNING
   2.353 +                       "error: unknown USB io operation response [%d]\n",
   2.354 +                       resp->operation);
   2.355 +                break;
   2.356 +            }
   2.357 +        }
   2.358 +
   2.359 +        usb_ring->rsp_cons = i;
   2.360 +
   2.361 +	/* Walk the list of pending URB's to see which ones completed and do
   2.362 +         * callbacks, etc. */
   2.363 +	spin_lock(&xhci->urb_list_lock);
   2.364 +	head = &xhci->urb_list;
   2.365 +	tmp = head->next;
   2.366 +	while (tmp != head) {
   2.367 +		struct urb *urb = list_entry(tmp, struct urb, urb_list);
   2.368 +
   2.369 +		tmp = tmp->next;
   2.370 +
   2.371 +		/* Checks the status and does all of the magic necessary */
   2.372 +		xhci_transfer_result(xhci, urb);
   2.373 +	}
   2.374 +	spin_unlock(&xhci->urb_list_lock);
   2.375 +
   2.376 +	xhci_finish_completion();
   2.377 +}
   2.378 +
   2.379 +
   2.380 +static void xhci_interrupt(int irq, void *__xhci, struct pt_regs *regs)
   2.381 +{
   2.382 +        xhci_drain_ring();
   2.383 +}
   2.384 +
   2.385 +/******************************************************************************
   2.386 + * HOST CONTROLLER FUNCTIONALITY
   2.387 + */
   2.388 +
   2.389 +/**
   2.390 + * no-op implementation of private device alloc / free routines
   2.391 + */
   2.392 +static int xhci_do_nothing_dev(struct usb_device *dev)
   2.393  {
   2.394  	return 0;
   2.395  }
   2.396 @@ -365,6 +504,8 @@ static inline void xhci_add_complete(str
   2.397   * storage.
   2.398   *
   2.399   * We spin and wait for the URB to complete before returning.
   2.400 + *
   2.401 + * Call with urb->lock acquired.
   2.402   */
   2.403  static void xhci_delete_urb(struct urb *urb)
   2.404  {
   2.405 @@ -526,8 +667,10 @@ static int xhci_submit_urb(struct urb *u
   2.406  
   2.407  	switch (usb_pipetype(urb->pipe)) {
   2.408  	case PIPE_CONTROL:
   2.409 +	case PIPE_BULK:
   2.410  		ret = xhci_queue_req(urb);
   2.411  		break;
   2.412 +
   2.413  	case PIPE_INTERRUPT:
   2.414  		if (urb->bandwidth == 0) {	/* not yet checked/allocated */
   2.415  			bustime = usb_check_bandwidth(urb->dev, urb);
   2.416 @@ -536,14 +679,13 @@ static int xhci_submit_urb(struct urb *u
   2.417  			else {
   2.418  				ret = xhci_queue_req(urb);
   2.419  				if (ret == -EINPROGRESS)
   2.420 -					usb_claim_bandwidth(urb->dev, urb, bustime, 0);
   2.421 +					usb_claim_bandwidth(urb->dev, urb,
   2.422 +                                                            bustime, 0);
   2.423  			}
   2.424  		} else		/* bandwidth is already set */
   2.425  			ret = xhci_queue_req(urb);
   2.426  		break;
   2.427 -	case PIPE_BULK:
   2.428 -		ret = xhci_queue_req(urb);
   2.429 -		break;
   2.430 +
   2.431  	case PIPE_ISOCHRONOUS:
   2.432  		if (urb->bandwidth == 0) {	/* not yet checked/allocated */
   2.433  			if (urb->number_of_packets <= 0) {
   2.434 @@ -563,7 +705,6 @@ static int xhci_submit_urb(struct urb *u
   2.435  			ret = xhci_queue_req(urb);
   2.436  		break;
   2.437  	}
   2.438 -
   2.439  out:
   2.440  	urb->status = ret;
   2.441  
   2.442 @@ -577,7 +718,7 @@ out:
   2.443  		return 0;
   2.444  	}
   2.445  
   2.446 -	xhci_unlink_generic(urb);
   2.447 +	xhci_delete_urb(urb);
   2.448  
   2.449  	spin_unlock(&urb->lock);
   2.450  	spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   2.451 @@ -643,7 +784,7 @@ static void xhci_transfer_result(struct 
   2.452  		/* Spinlock needed ? */
   2.453  		if (urb->bandwidth)
   2.454  			usb_release_bandwidth(urb->dev, urb, 1);
   2.455 -		xhci_unlink_generic(urb);
   2.456 +		xhci_delete_urb(urb);
   2.457  		break;
   2.458  	case PIPE_INTERRUPT:
   2.459  		/* Interrupts are an exception */
   2.460 @@ -654,11 +795,11 @@ static void xhci_transfer_result(struct 
   2.461  		/* Spinlock needed ? */
   2.462  		if (urb->bandwidth)
   2.463  			usb_release_bandwidth(urb->dev, urb, 0);
   2.464 -		xhci_unlink_generic(urb);
   2.465 +		xhci_delete_urb(urb);
   2.466  		break;
   2.467  	default:
   2.468  		info("xhci_transfer_result: unknown pipe type %d for urb %p\n",
   2.469 -			usb_pipetype(urb->pipe), urb);
   2.470 +                     usb_pipetype(urb->pipe), urb);
   2.471  	}
   2.472  
   2.473  	/* Remove it from xhci->urb_list */
   2.474 @@ -671,23 +812,6 @@ out:
   2.475  	spin_unlock_irqrestore(&urb->lock, flags);
   2.476  }
   2.477  
   2.478 -/*
   2.479 - * MUST be called with urb->lock acquired
   2.480 - */
   2.481 -static void xhci_unlink_generic(struct urb *urb)
   2.482 -{
   2.483 -	struct urb_priv *urbp = urb->hcpriv;
   2.484 -
   2.485 -	/* We can get called when urbp allocation fails, so check */
   2.486 -	if (!urbp)
   2.487 -		return;
   2.488 -
   2.489 -        /* ??? This function is now so minimal it doesn't do much.  Do we really
   2.490 -         * need it? */
   2.491 -
   2.492 -	xhci_delete_urb(urb);
   2.493 -}
   2.494 -
   2.495  static int xhci_unlink_urb(struct urb *urb)
   2.496  {
   2.497  	unsigned long flags;
   2.498 @@ -725,7 +849,7 @@ static int xhci_unlink_urb(struct urb *u
   2.499  
   2.500  	list_del_init(&urb->urb_list);
   2.501  
   2.502 -	xhci_unlink_generic(urb);
   2.503 +	xhci_delete_urb(urb);
   2.504  
   2.505  	/* Short circuit the virtual root hub */
   2.506  	if (urb->dev == xhci->rh.dev) {
   2.507 @@ -770,10 +894,114 @@ static int xhci_unlink_urb(struct urb *u
   2.508  	return 0;
   2.509  }
   2.510  
   2.511 +static void xhci_call_completion(struct urb *urb)
   2.512 +{
   2.513 +	struct urb_priv *urbp;
   2.514 +	struct usb_device *dev = urb->dev;
   2.515 +	int is_ring = 0, killed, resubmit_interrupt, status;
   2.516 +	struct urb *nurb;
   2.517 +	unsigned long flags;
   2.518 +
   2.519 +	spin_lock_irqsave(&urb->lock, flags);
   2.520 +
   2.521 +	urbp = (struct urb_priv *)urb->hcpriv;
   2.522 +	if (!urbp || !urb->dev) {
   2.523 +		spin_unlock_irqrestore(&urb->lock, flags);
   2.524 +		return;
   2.525 +	}
   2.526 +
   2.527 +	killed = (urb->status == -ENOENT || urb->status == -ECONNABORTED ||
   2.528 +			urb->status == -ECONNRESET);
   2.529 +	resubmit_interrupt = (usb_pipetype(urb->pipe) == PIPE_INTERRUPT &&
   2.530 +			urb->interval);
   2.531 +
   2.532 +	nurb = urb->next;
   2.533 +	if (nurb && !killed) {
   2.534 +		int count = 0;
   2.535 +
   2.536 +		while (nurb && nurb != urb && count < MAX_URB_LOOP) {
   2.537 +			if (nurb->status == -ENOENT ||
   2.538 +			    nurb->status == -ECONNABORTED ||
   2.539 +			    nurb->status == -ECONNRESET) {
   2.540 +				killed = 1;
   2.541 +				break;
   2.542 +			}
   2.543 +
   2.544 +			nurb = nurb->next;
   2.545 +			count++;
   2.546 +		}
   2.547 +
   2.548 +		if (count == MAX_URB_LOOP)
   2.549 +			err("xhci_call_completion: too many linked URB's, loop? (first loop)");
   2.550 +
   2.551 +		/* Check to see if chain is a ring */
   2.552 +		is_ring = (nurb == urb);
   2.553 +	}
   2.554 +
   2.555 +	status = urbp->status;
   2.556 +	if (!resubmit_interrupt || killed)
   2.557 +		/* We don't need urb_priv anymore */
   2.558 +		xhci_destroy_urb_priv(urb);
   2.559 +
   2.560 +	if (!killed)
   2.561 +		urb->status = status;
   2.562 +
   2.563 +	spin_unlock_irqrestore(&urb->lock, flags);
   2.564 +
   2.565 +	if (urb->complete)
   2.566 +		urb->complete(urb);
   2.567 +
   2.568 +	if (resubmit_interrupt)
   2.569 +		/* Recheck the status. The completion handler may have */
   2.570 +		/*  unlinked the resubmitting interrupt URB */
   2.571 +		killed = (urb->status == -ENOENT ||
   2.572 +			  urb->status == -ECONNABORTED ||
   2.573 +			  urb->status == -ECONNRESET);
   2.574 +
   2.575 +	if (resubmit_interrupt && !killed) {
   2.576 +                if ( urb->dev != xhci->rh.dev )
   2.577 +                        xhci_queue_req(urb); /* XXX What if this fails? */
   2.578 +                /* Don't need to resubmit URBs for the virtual root dev. */
   2.579 +	} else {
   2.580 +		if (is_ring && !killed) {
   2.581 +			urb->dev = dev;
   2.582 +			xhci_submit_urb(urb);
   2.583 +		} else {
   2.584 +			/* We decrement the usage count after we're done */
   2.585 +			/*  with everything */
   2.586 +			usb_dec_dev_use(dev);
   2.587 +		}
   2.588 +	}
   2.589 +}
   2.590 +
   2.591 +static void xhci_finish_completion(void)
   2.592 +{
   2.593 +	struct list_head *tmp, *head;
   2.594 +	unsigned long flags;
   2.595 +
   2.596 +	spin_lock_irqsave(&xhci->complete_list_lock, flags);
   2.597 +	head = &xhci->complete_list;
   2.598 +	tmp = head->next;
   2.599 +	while (tmp != head) {
   2.600 +		struct urb_priv *urbp = list_entry(tmp, struct urb_priv,
   2.601 +                                                   complete_list);
   2.602 +		struct urb *urb = urbp->urb;
   2.603 +
   2.604 +		list_del_init(&urbp->complete_list);
   2.605 +		spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
   2.606 +
   2.607 +		xhci_call_completion(urb);
   2.608 +
   2.609 +		spin_lock_irqsave(&xhci->complete_list_lock, flags);
   2.610 +		head = &xhci->complete_list;
   2.611 +		tmp = head->next;
   2.612 +	}
   2.613 +	spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
   2.614 +}
   2.615  
   2.616  static struct usb_operations xhci_device_operations = {
   2.617 -	.allocate = xhci_alloc_dev,
   2.618 -	.deallocate = xhci_free_dev,
   2.619 +	.allocate = xhci_do_nothing_dev,
   2.620 +	.deallocate = xhci_do_nothing_dev,
   2.621          /* It doesn't look like any drivers actually care what the frame number
   2.622  	 * is at the moment!  If necessary, we could approximate the current
   2.623  	 * frame nubmer by passing it from the backend in response messages. */
   2.624 @@ -782,7 +1010,9 @@ static struct usb_operations xhci_device
   2.625  	.unlink_urb = xhci_unlink_urb
   2.626  };
   2.627  
   2.628 -/* Virtual Root Hub */
   2.629 +/******************************************************************************
   2.630 + * VIRTUAL ROOT HUB EMULATION
   2.631 + */
   2.632  
   2.633  static __u8 root_hub_dev_des[] =
   2.634  {
   2.635 @@ -867,9 +1097,8 @@ static int rh_send_irq(struct urb *urb)
   2.636  
   2.637  	spin_lock_irqsave(&urb->lock, flags);
   2.638  	for (i = 0; i < xhci->rh.numports; i++) {
   2.639 -                /* MAW: No idea what the old code was doing here or why it worked.
   2.640 -		 * This implementation sets a bit if anything at all has changed on the 
   2.641 -		 * port, as per USB spec 11.12 */
   2.642 +                /* Set a bit if anything at all has changed on the port, as per
   2.643 +		 * USB spec 11.12 */
   2.644  		data |= (ports[i].cs_chg || ports[i].pe_chg )
   2.645                          ? (1 << (i + 1))
   2.646                          : 0;
   2.647 @@ -921,7 +1150,8 @@ static void rh_int_timer_do(unsigned lon
   2.648  		spin_lock(&u->lock);
   2.649  
   2.650  		/* Check if the URB timed out */
   2.651 -		if (u->timeout && time_after_eq(jiffies, up->inserttime + u->timeout)) {
   2.652 +		if (u->timeout && time_after_eq(jiffies,
   2.653 +                                                up->inserttime + u->timeout)) {
   2.654  			list_del(&u->urb_list);
   2.655  			list_add_tail(&u->urb_list, &list);
   2.656  		}
   2.657 @@ -951,7 +1181,8 @@ static int rh_init_int_timer(struct urb 
   2.658  	init_timer(&xhci->rh.rh_int_timer);
   2.659  	xhci->rh.rh_int_timer.function = rh_int_timer_do;
   2.660  	xhci->rh.rh_int_timer.data = (unsigned long)urb;
   2.661 -	xhci->rh.rh_int_timer.expires = jiffies + (HZ * (urb->interval < 30 ? 30 : urb->interval)) / 1000;
   2.662 +	xhci->rh.rh_int_timer.expires = jiffies
   2.663 +                + (HZ * (urb->interval < 30 ? 30 : urb->interval)) / 1000;
   2.664  	add_timer(&xhci->rh.rh_int_timer);
   2.665  
   2.666  	return 0;
   2.667 @@ -963,7 +1194,8 @@ static int rh_init_int_timer(struct urb 
   2.668  static int rh_submit_urb(struct urb *urb)
   2.669  {
   2.670  	unsigned int pipe = urb->pipe;
   2.671 -	struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *)urb->setup_packet;
   2.672 +	struct usb_ctrlrequest *cmd =
   2.673 +                (struct usb_ctrlrequest *)urb->setup_packet;
   2.674  	void *data = urb->transfer_buffer;
   2.675  	int leni = urb->transfer_buffer_length;
   2.676  	int len = 0;
   2.677 @@ -1164,250 +1396,12 @@ static int rh_unlink_urb(struct urb *urb
   2.678  	return 0;
   2.679  }
   2.680  
   2.681 -static void xhci_call_completion(struct urb *urb)
   2.682 -{
   2.683 -	struct urb_priv *urbp;
   2.684 -	struct usb_device *dev = urb->dev;
   2.685 -	int is_ring = 0, killed, resubmit_interrupt, status;
   2.686 -	struct urb *nurb;
   2.687 -	unsigned long flags;
   2.688 -
   2.689 -	spin_lock_irqsave(&urb->lock, flags);
   2.690 -
   2.691 -	urbp = (struct urb_priv *)urb->hcpriv;
   2.692 -	if (!urbp || !urb->dev) {
   2.693 -		spin_unlock_irqrestore(&urb->lock, flags);
   2.694 -		return;
   2.695 -	}
   2.696 -
   2.697 -	killed = (urb->status == -ENOENT || urb->status == -ECONNABORTED ||
   2.698 -			urb->status == -ECONNRESET);
   2.699 -	resubmit_interrupt = (usb_pipetype(urb->pipe) == PIPE_INTERRUPT &&
   2.700 -			urb->interval);
   2.701 -
   2.702 -	nurb = urb->next;
   2.703 -	if (nurb && !killed) {
   2.704 -		int count = 0;
   2.705 -
   2.706 -		while (nurb && nurb != urb && count < MAX_URB_LOOP) {
   2.707 -			if (nurb->status == -ENOENT ||
   2.708 -			    nurb->status == -ECONNABORTED ||
   2.709 -			    nurb->status == -ECONNRESET) {
   2.710 -				killed = 1;
   2.711 -				break;
   2.712 -			}
   2.713 -
   2.714 -			nurb = nurb->next;
   2.715 -			count++;
   2.716 -		}
   2.717 -
   2.718 -		if (count == MAX_URB_LOOP)
   2.719 -			err("xhci_call_completion: too many linked URB's, loop? (first loop)");
   2.720 -
   2.721 -		/* Check to see if chain is a ring */
   2.722 -		is_ring = (nurb == urb);
   2.723 -	}
   2.724 -
   2.725 -	status = urbp->status;
   2.726 -	if (!resubmit_interrupt || killed)
   2.727 -		/* We don't need urb_priv anymore */
   2.728 -		xhci_destroy_urb_priv(urb);
   2.729 -
   2.730 -	if (!killed)
   2.731 -		urb->status = status;
   2.732 -
   2.733 -	spin_unlock_irqrestore(&urb->lock, flags);
   2.734 -
   2.735 -	if (urb->complete)
   2.736 -		urb->complete(urb);
   2.737 -
   2.738 -	if (resubmit_interrupt)
   2.739 -		/* Recheck the status. The completion handler may have */
   2.740 -		/*  unlinked the resubmitting interrupt URB */
   2.741 -		killed = (urb->status == -ENOENT ||
   2.742 -			  urb->status == -ECONNABORTED ||
   2.743 -			  urb->status == -ECONNRESET);
   2.744 -
   2.745 -	if (resubmit_interrupt && !killed) {
   2.746 -                if ( urb->dev != xhci->rh.dev )
   2.747 -                        xhci_queue_req(urb); /* XXX What if this fails? */
   2.748 -                /* Don't need to resubmit URBs for the virtual root dev. */
   2.749 -	} else {
   2.750 -		if (is_ring && !killed) {
   2.751 -			urb->dev = dev;
   2.752 -			xhci_submit_urb(urb);
   2.753 -		} else {
   2.754 -			/* We decrement the usage count after we're done */
   2.755 -			/*  with everything */
   2.756 -			usb_dec_dev_use(dev);
   2.757 -		}
   2.758 -	}
   2.759 -}
   2.760 -
   2.761 -static void xhci_finish_completion(void)
   2.762 -{
   2.763 -	struct list_head *tmp, *head;
   2.764 -	unsigned long flags;
   2.765 -
   2.766 -	spin_lock_irqsave(&xhci->complete_list_lock, flags);
   2.767 -	head = &xhci->complete_list;
   2.768 -	tmp = head->next;
   2.769 -	while (tmp != head) {
   2.770 -		struct urb_priv *urbp = list_entry(tmp, struct urb_priv, complete_list);
   2.771 -		struct urb *urb = urbp->urb;
   2.772 -
   2.773 -		list_del_init(&urbp->complete_list);
   2.774 -		spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
   2.775 -
   2.776 -		xhci_call_completion(urb);
   2.777 -
   2.778 -		spin_lock_irqsave(&xhci->complete_list_lock, flags);
   2.779 -		head = &xhci->complete_list;
   2.780 -		tmp = head->next;
   2.781 -	}
   2.782 -	spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
   2.783 -}
   2.784 -
   2.785 -static void receive_usb_reset(usbif_response_t *resp)
   2.786 -{
   2.787 -    awaiting_reset = resp->status;
   2.788 -    rmb();
   2.789 -    
   2.790 -}
   2.791 -
   2.792 -static void receive_usb_probe(usbif_response_t *resp)
   2.793 -{
   2.794 -    spin_lock(&xhci->rh.port_state_lock);
   2.795 -
   2.796 -    if ( resp->status > 0 )
   2.797 -    {
   2.798 -        if ( resp->status == 1 )
   2.799 -        {
   2.800 -            /* If theres a device there and there wasn't one before there must
   2.801 -             * have been a connection status change. */
   2.802 -            if( xhci->rh.ports[resp->data].cs == 0 )
   2.803 -	    {
   2.804 -                xhci->rh.ports[resp->data].cs = 1;
   2.805 -                xhci->rh.ports[resp->data].ccs = 1;
   2.806 -                xhci->rh.ports[resp->data].cs_chg = 1;
   2.807 -	    }
   2.808 -        }
   2.809 -        else
   2.810 -            printk(KERN_WARNING "receive_usb_probe(): unexpected status %d for port %d\n",
   2.811 -                   resp->status, resp->data);
   2.812 -    }
   2.813 -    else if ( resp->status < 0)
   2.814 -        printk(KERN_WARNING "receive_usb_probe(): got error status %d\n", resp->status);
   2.815 -
   2.816 -    spin_unlock(&xhci->rh.port_state_lock);
   2.817 -}
   2.818 -
   2.819 -static void receive_usb_io(usbif_response_t *resp)
   2.820 -{
   2.821 -        struct urb_priv *urbp = (struct urb_priv *)resp->id;
   2.822 -        struct urb *urb = urbp->urb;
   2.823 -
   2.824 -        urb->actual_length = resp->length;
   2.825 -	urb->status = resp->status;
   2.826 -	urbp->status = resp->status;
   2.827 -        urbp->in_progress = 0;
   2.828 -
   2.829 -        if( usb_pipetype(urb->pipe) == 0 ) /* ISO */
   2.830 -        {
   2.831 -                int i;
   2.832 -              
   2.833 -                /* Copy ISO schedule results back in. */
   2.834 -
   2.835 -                for ( i = 0; i < urb->number_of_packets; i++ )
   2.836 -                {
   2.837 -                        urb->iso_frame_desc[i].status
   2.838 -			  = urbp->schedule[i].status;
   2.839 -                        urb->iso_frame_desc[i].actual_length
   2.840 -                                = urbp->schedule[i].length;
   2.841 -                }
   2.842 -                free_page((unsigned long)urbp->schedule);
   2.843 -        }
   2.844 -}
   2.845 -
   2.846 -static void xhci_drain_ring(void)
   2.847 -{
   2.848 -	struct list_head *tmp, *head;
   2.849 -	usbif_front_ring_t *usb_ring = &xhci->usb_ring;
   2.850 -	usbif_response_t *resp;
   2.851 -        RING_IDX i, rp;
   2.852 -
   2.853 -        /* Walk the ring here to get responses, updating URBs to show what
   2.854 -         * completed. */
   2.855 -        
   2.856 -        rp = usb_ring->sring->rsp_prod;
   2.857 -        rmb(); /* Ensure we see queued requests up to 'rp'. */
   2.858 -
   2.859 -        /* Take items off the comms ring, taking care not to overflow. */
   2.860 -        for ( i = usb_ring->rsp_cons; i != rp; i++ )
   2.861 -        {
   2.862 -            resp = RING_GET_RESPONSE(USBIF_RING, usb_ring, i);
   2.863 -            
   2.864 -            /* May need to deal with batching and with putting a ceiling on
   2.865 -               the number dispatched for performance and anti-dos reasons */
   2.866 -
   2.867 -            xhci_show_resp(resp);
   2.868 -
   2.869 -            switch ( resp->operation )
   2.870 -            {
   2.871 -            case USBIF_OP_PROBE:
   2.872 -                receive_usb_probe(resp);
   2.873 -                break;
   2.874 -                
   2.875 -            case USBIF_OP_IO:
   2.876 -                receive_usb_io(resp);
   2.877 -                break;
   2.878 -
   2.879 -            case USBIF_OP_RESET:
   2.880 -                receive_usb_reset(resp);
   2.881 -                break;
   2.882 -
   2.883 -            default:
   2.884 -                printk(KERN_WARNING
   2.885 -                       "error: unknown USB io operation response [%d]\n",
   2.886 -                       resp->operation);
   2.887 -                break;
   2.888 -            }
   2.889 -        }
   2.890 -
   2.891 -        usb_ring->rsp_cons = i;
   2.892 -
   2.893 -	/* Walk the list of pending URB's to see which ones completed and do
   2.894 -         * callbacks, etc. */
   2.895 -	spin_lock(&xhci->urb_list_lock);
   2.896 -	head = &xhci->urb_list;
   2.897 -	tmp = head->next;
   2.898 -	while (tmp != head) {
   2.899 -                
   2.900 -		struct urb *urb = list_entry(tmp, struct urb, urb_list);
   2.901 -
   2.902 -		tmp = tmp->next;
   2.903 -
   2.904 -		/* Checks the status and does all of the magic necessary */
   2.905 -		xhci_transfer_result(xhci, urb);
   2.906 -	}
   2.907 -	spin_unlock(&xhci->urb_list_lock);
   2.908 -
   2.909 -	xhci_finish_completion();
   2.910 -}
   2.911 -
   2.912 -
   2.913 -static void xhci_interrupt(int irq, void *__xhci, struct pt_regs *regs)
   2.914 -{
   2.915 -        xhci_drain_ring();
   2.916 -}
   2.917 -
   2.918 -static void free_xhci(struct xhci *xhci)
   2.919 -{
   2.920 -	kfree(xhci);
   2.921 -}
   2.922 +/******************************************************************************
   2.923 + * CONTROL PLANE FUNCTIONALITY
   2.924 + */
   2.925  
   2.926  /**
   2.927 - * Initialise a new virtual root hub for a new USB device channel.
   2.928 + * alloc_xhci - initialise a new virtual root hub for a new USB device channel
   2.929   */
   2.930  static int alloc_xhci(void)
   2.931  {
   2.932 @@ -1442,12 +1436,8 @@ static int alloc_xhci(void)
   2.933  
   2.934  	spin_lock_init(&xhci->frame_list_lock);
   2.935  
   2.936 -	/* We need exactly one page (per XHCI specs), how convenient */
   2.937 -	/* We assume that one page is atleast 4k (1024 frames * 4 bytes) */
   2.938 -#if PAGE_SIZE < (4 * 1024)
   2.939 -#error PAGE_SIZE is not atleast 4k
   2.940 -#endif
   2.941  	bus = usb_alloc_bus(&xhci_device_operations);
   2.942 +
   2.943  	if (!bus) {
   2.944  		err("unable to allocate bus");
   2.945  		goto err_alloc_bus;
   2.946 @@ -1477,16 +1467,20 @@ static int alloc_xhci(void)
   2.947   * error exits:
   2.948   */
   2.949  err_alloc_root_hub:
   2.950 +        usb_deregister_bus(xhci->bus);
   2.951  	usb_free_bus(xhci->bus);
   2.952  	xhci->bus = NULL;
   2.953  
   2.954  err_alloc_bus:
   2.955 -	free_xhci(xhci);
   2.956 +	kfree(xhci);
   2.957  
   2.958  err_alloc_xhci:
   2.959  	return retval;
   2.960  }
   2.961  
   2.962 +/**
   2.963 + * usbif_status_change - deal with an incoming USB_INTERFACE_STATUS_ message
   2.964 + */
   2.965  static void usbif_status_change(usbif_fe_interface_status_changed_t *status)
   2.966  {
   2.967      ctrl_msg_t                   cmsg;
   2.968 @@ -1551,8 +1545,8 @@ static void usbif_status_change(usbif_fe
   2.969  	}
   2.970  
   2.971  	/* Allocate the appropriate USB bandwidth here...  Need to
   2.972 -	* somehow know what the total available is thought to be so we
   2.973 -	* can calculate the reservation correctly. */
   2.974 +         * somehow know what the total available is thought to be so we
   2.975 +         * can calculate the reservation correctly. */
   2.976   	usb_claim_bandwidth(xhci->rh.dev, xhci->rh.urb,
   2.977   			    1000 - xhci->bandwidth, 0);
   2.978  
   2.979 @@ -1560,8 +1554,10 @@ static void usbif_status_change(usbif_fe
   2.980                                 SA_SAMPLE_RANDOM, "usbif", xhci)) )
   2.981                  printk(KERN_ALERT"usbfront request_irq failed (%ld)\n",rc);
   2.982  
   2.983 -	DPRINTK(KERN_INFO __FILE__ ": USB XHCI: SHM at %p (0x%lx), EVTCHN %d IRQ %d\n",
   2.984 -               xhci->usb_ring.sring, virt_to_machine(xhci->usbif), xhci->evtchn, xhci->irq);
   2.985 +	DPRINTK(KERN_INFO __FILE__
   2.986 +                ": USB XHCI: SHM at %p (0x%lx), EVTCHN %d IRQ %d\n",
   2.987 +                xhci->usb_ring.sring, virt_to_machine(xhci->usbif),
   2.988 +                xhci->evtchn, xhci->irq);
   2.989  
   2.990          xhci->state = USBIF_STATE_CONNECTED;
   2.991          
   2.992 @@ -1574,7 +1570,9 @@ static void usbif_status_change(usbif_fe
   2.993      }
   2.994  }
   2.995  
   2.996 -
   2.997 +/**
   2.998 + * usbif_ctrlif_rx - demux control messages by subtype
   2.999 + */
  2.1000  static void usbif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
  2.1001  {
  2.1002      switch ( msg->subtype )
  2.1003 @@ -1623,9 +1621,6 @@ static int __init xhci_hcd_init(void)
  2.1004  	if (!xhci_up_cachep)
  2.1005  		goto up_failed;
  2.1006  
  2.1007 -        /* Lazily avoid unloading issues for now. ;-)*/
  2.1008 -	MOD_INC_USE_COUNT;
  2.1009 -
  2.1010          /* Let the domain controller know we're here.  For now we wait until
  2.1011           * connection, as for the block and net drivers.  This is only strictly
  2.1012           * necessary if we're going to boot off a USB device. */
  2.1013 @@ -1661,29 +1656,14 @@ static int __init xhci_hcd_init(void)
  2.1014  	return 0;
  2.1015  
  2.1016  up_failed:
  2.1017 -
  2.1018  	if (errbuf)
  2.1019  		kfree(errbuf);
  2.1020  
  2.1021  errbuf_failed:
  2.1022 -
  2.1023  	return retval;
  2.1024  }
  2.1025  
  2.1026 -static void __exit xhci_hcd_cleanup(void) 
  2.1027 -{
  2.1028 -	if (kmem_cache_destroy(xhci_up_cachep))
  2.1029 -		printk(KERN_WARNING "xhci: not all urb_priv's were freed\n");
  2.1030 -
  2.1031 -//        release_xhci(); do some calls here
  2.1032 -
  2.1033 -
  2.1034 -	if (errbuf)
  2.1035 -		kfree(errbuf);
  2.1036 -}
  2.1037 -
  2.1038  module_init(xhci_hcd_init);
  2.1039 -module_exit(xhci_hcd_cleanup);
  2.1040  
  2.1041  MODULE_AUTHOR(DRIVER_AUTHOR);
  2.1042  MODULE_DESCRIPTION(DRIVER_DESC);