ia64/xen-unstable

changeset 3485:4e64b8deb0d4

bitkeeper revision 1.1159.212.25 (41f276d3ugY9cEgwC334t8sIzg3kiA)

USB virtualisation updated to 2.4.29.
author mwilli2@equilibrium.research
date Sat Jan 22 15:52:51 2005 +0000 (2005-01-22)
parents 610068179f96
children c60c0cc29ae0
files .rootkeys linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/Makefile linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/Makefile linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/common.h linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/control.c linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/interface.c linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/main.c linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/main.c linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/xhci.h linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/usbif.h linux-2.4.28-xen-sparse/drivers/usb/hcd.c linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/Makefile linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/Makefile linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/common.h linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/control.c linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/interface.c linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/main.c linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/main.c linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/xhci.h linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/usbif.h
line diff
     1.1 --- a/.rootkeys	Sat Jan 22 15:16:02 2005 +0000
     1.2 +++ b/.rootkeys	Sat Jan 22 15:52:51 2005 +0000
     1.3 @@ -45,17 +45,6 @@ 3f815145CB8XdPUqsmhAjSDFuwOoqA extras/mi
     1.4  3f815145vGYx1WY79voKkZB9yKwJKQ extras/mini-os/time.c
     1.5  3f815145xlKBAQmal9oces3G_Mvxqw extras/mini-os/traps.c
     1.6  4187ca95_eQN62ugV1zliQcfzXrHnw install.sh
     1.7 -41ee5e8b_2rt-qHzbDXtIoBzOli0EA linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/Makefile
     1.8 -41ee5e8bUhF4tH7OoJaVbUxdXqneVw linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/Makefile
     1.9 -41ee5e8bYDQkjRVKnFn5uFyy0KreCw linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/common.h
    1.10 -41ee5e8bt7xeBUJqG5XJS-ofukdsgA linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/control.c
    1.11 -41ee5e8bSs3BGC7yegM_ek2Tn0Ahvw linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/interface.c
    1.12 -41ee5e8bglvqKvZSY5uJ5JGQejEwyQ linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/main.c
    1.13 -41ee5e8bSPpxzhGO6TrY20TegW3cZg linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile
    1.14 -41ee5e8ckZ9xVNvu9NHIZDK7JqApmQ linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/main.c
    1.15 -41ee5e8ck9scpGirfqEZRARbGDyTXA linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/xhci.h
    1.16 -41ee5e8c6mLxIx82KPsbpt_uts_vSA linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/usbif.h
    1.17 -41ee5e8c__abdO50ZtQjPeSa5VN2dg linux-2.4.28-xen-sparse/drivers/usb/hcd.c
    1.18  3e5a4e6589G-U42lFKs43plskXoFxQ linux-2.4.29-xen-sparse/Makefile
    1.19  3e5a4e65IEPjnWPZ5w3TxS5scV8Ewg linux-2.4.29-xen-sparse/arch/xen/Makefile
    1.20  3e5a4e65n-KhsEAs-A4ULiStBp-r6w linux-2.4.29-xen-sparse/arch/xen/boot/Makefile
    1.21 @@ -74,6 +63,16 @@ 40420a6ebRqDjufoN1WSJvolEW2Wjw linux-2.4
    1.22  4083dc16-Kd5y9psK_yk161sme5j5Q linux-2.4.29-xen-sparse/arch/xen/drivers/netif/Makefile
    1.23  4083dc16UmHXxS9g_UFVnkUpN-oP2Q linux-2.4.29-xen-sparse/arch/xen/drivers/netif/backend/Makefile
    1.24  405853f2wg7JXZJNltspMwOZJklxgw linux-2.4.29-xen-sparse/arch/xen/drivers/netif/frontend/Makefile
    1.25 +41ee5e8b_2rt-qHzbDXtIoBzOli0EA linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/Makefile
    1.26 +41ee5e8bUhF4tH7OoJaVbUxdXqneVw linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/Makefile
    1.27 +41ee5e8bYDQkjRVKnFn5uFyy0KreCw linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/common.h
    1.28 +41ee5e8bt7xeBUJqG5XJS-ofukdsgA linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/control.c
    1.29 +41ee5e8bSs3BGC7yegM_ek2Tn0Ahvw linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/interface.c
    1.30 +41ee5e8bglvqKvZSY5uJ5JGQejEwyQ linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/main.c
    1.31 +41ee5e8bSPpxzhGO6TrY20TegW3cZg linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile
    1.32 +41ee5e8ckZ9xVNvu9NHIZDK7JqApmQ linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/main.c
    1.33 +41ee5e8ck9scpGirfqEZRARbGDyTXA linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/xhci.h
    1.34 +41ee5e8c6mLxIx82KPsbpt_uts_vSA linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/usbif.h
    1.35  3e5a4e65lWzkiPXsZdzPt2RNnJGG1g linux-2.4.29-xen-sparse/arch/xen/kernel/Makefile
    1.36  3e5a4e65_hqfuxtGG8IUy6wRM86Ecg linux-2.4.29-xen-sparse/arch/xen/kernel/entry.S
    1.37  3e5a4e65Hy_1iUvMTPsNqGNXd9uFpg linux-2.4.29-xen-sparse/arch/xen/kernel/head.S
     2.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/Makefile	Sat Jan 22 15:16:02 2005 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,10 +0,0 @@
     2.4 -
     2.5 -O_TARGET := drv.o
     2.6 -
     2.7 -subdir-$(CONFIG_XEN_USB_FRONTEND) += frontend
     2.8 -obj-$(CONFIG_XEN_USB_FRONTEND) += frontend/drv.o
     2.9 -
    2.10 -subdir-$(CONFIG_XEN_USB_BACKEND) += backend
    2.11 -obj-$(CONFIG_XEN_USB_BACKEND)    += backend/drv.o
    2.12 -
    2.13 -include $(TOPDIR)/Rules.make
     3.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/Makefile	Sat Jan 22 15:16:02 2005 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,3 +0,0 @@
     3.4 -O_TARGET := drv.o
     3.5 -obj-y := main.o interface.o control.o # vrh.o don't think I need this!
     3.6 -include $(TOPDIR)/Rules.make
     4.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/common.h	Sat Jan 22 15:16:02 2005 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,87 +0,0 @@
     4.4 -
     4.5 -#ifndef __USBIF__BACKEND__COMMON_H__
     4.6 -#define __USBIF__BACKEND__COMMON_H__
     4.7 -
     4.8 -#include <linux/config.h>
     4.9 -#include <linux/version.h>
    4.10 -#include <linux/module.h>
    4.11 -#include <linux/rbtree.h>
    4.12 -#include <linux/interrupt.h>
    4.13 -#include <linux/slab.h>
    4.14 -#include <linux/blkdev.h>
    4.15 -#include <asm/io.h>
    4.16 -#include <asm/setup.h>
    4.17 -#include <asm/pgalloc.h>
    4.18 -#include <asm-xen/ctrl_if.h>
    4.19 -#include <asm-xen/hypervisor.h>
    4.20 -
    4.21 -#include "../usbif.h"
    4.22 -
    4.23 -#if 0
    4.24 -#define ASSERT(_p) \
    4.25 -    if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
    4.26 -    __LINE__, __FILE__); *(int*)0=0; }
    4.27 -#define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
    4.28 -                           __FILE__ , __LINE__ , ## _a )
    4.29 -#else
    4.30 -#define ASSERT(_p) ((void)0)
    4.31 -#define DPRINTK(_f, _a...) ((void)0)
    4.32 -#endif
    4.33 -
    4.34 -typedef struct usbif_priv_st usbif_priv_t;
    4.35 -
    4.36 -struct usbif_priv_st {
    4.37 -    /* Unique identifier for this interface. */
    4.38 -    domid_t          domid;
    4.39 -    unsigned int     handle;
    4.40 -    /* Physical parameters of the comms window. */
    4.41 -    unsigned long    shmem_frame;
    4.42 -    unsigned int     evtchn;
    4.43 -    int              irq;
    4.44 -    /* Comms information. */
    4.45 -    usbif_t      *usb_ring_base; /* ioremap()'ed ptr to shmem_frame. */
    4.46 -    USBIF_RING_IDX     usb_req_cons;  /* Request consumer. */
    4.47 -    USBIF_RING_IDX     usb_resp_prod; /* Private version of resp. producer. */
    4.48 -    /* Private fields. */
    4.49 -    enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
    4.50 -    /*
    4.51 -     * DISCONNECT response is deferred until pending requests are ack'ed.
    4.52 -     * We therefore need to store the id from the original request.
    4.53 -     */
    4.54 -    u8                   disconnect_rspid;
    4.55 -    usbif_priv_t *hash_next;
    4.56 -    struct list_head     usbif_list;
    4.57 -    spinlock_t           usb_ring_lock;
    4.58 -    atomic_t             refcnt;
    4.59 -    atomic_t             work_scheduled;
    4.60 -
    4.61 -    struct work_struct work;
    4.62 -};
    4.63 -
    4.64 -void usbif_create(usbif_be_create_t *create);
    4.65 -void usbif_destroy(usbif_be_destroy_t *destroy);
    4.66 -void usbif_connect(usbif_be_connect_t *connect);
    4.67 -int  usbif_disconnect(usbif_be_disconnect_t *disconnect, u8 rsp_id);
    4.68 -void usbif_disconnect_complete(usbif_priv_t *up);
    4.69 -
    4.70 -void usbif_release_port(usbif_be_release_port_t *msg);
    4.71 -int usbif_claim_port(usbif_be_claim_port_t *msg);
    4.72 -void usbif_release_ports(usbif_priv_t *up);
    4.73 -
    4.74 -usbif_priv_t *usbif_find(domid_t domid);
    4.75 -#define usbif_get(_b) (atomic_inc(&(_b)->refcnt))
    4.76 -#define usbif_put(_b)                             \
    4.77 -    do {                                          \
    4.78 -        if ( atomic_dec_and_test(&(_b)->refcnt) ) \
    4.79 -            usbif_disconnect_complete(_b);        \
    4.80 -    } while (0)
    4.81 -
    4.82 -
    4.83 -void usbif_interface_init(void);
    4.84 -void usbif_ctrlif_init(void);
    4.85 -
    4.86 -void usbif_deschedule(usbif_priv_t *usbif);
    4.87 -
    4.88 -irqreturn_t usbif_be_int(int irq, void *dev_id, struct pt_regs *regs);
    4.89 -
    4.90 -#endif /* __USBIF__BACKEND__COMMON_H__ */
     5.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/control.c	Sat Jan 22 15:16:02 2005 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,77 +0,0 @@
     5.4 -/******************************************************************************
     5.5 - * arch/xen/drivers/usbif/backend/control.c
     5.6 - * 
     5.7 - * Routines for interfacing with the control plane.
     5.8 - * 
     5.9 - * Copyright (c) 2004, Keir Fraser
    5.10 - */
    5.11 -
    5.12 -#include "common.h"
    5.13 -
    5.14 -static void usbif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
    5.15 -{
    5.16 -    DPRINTK("Received usbif backend message, subtype=%d\n", msg->subtype);
    5.17 -    
    5.18 -    switch ( msg->subtype )
    5.19 -    {
    5.20 -    case CMSG_USBIF_BE_CREATE:
    5.21 -        if ( msg->length != sizeof(usbif_be_create_t) )
    5.22 -            goto parse_error;
    5.23 -        usbif_create((usbif_be_create_t *)&msg->msg[0]);
    5.24 -        break;        
    5.25 -    case CMSG_USBIF_BE_DESTROY:
    5.26 -        if ( msg->length != sizeof(usbif_be_destroy_t) )
    5.27 -            goto parse_error;
    5.28 -        usbif_destroy((usbif_be_destroy_t *)&msg->msg[0]);
    5.29 -        break;        
    5.30 -    case CMSG_USBIF_BE_CONNECT:
    5.31 -        if ( msg->length != sizeof(usbif_be_connect_t) )
    5.32 -            goto parse_error;
    5.33 -        usbif_connect((usbif_be_connect_t *)&msg->msg[0]);
    5.34 -        break;        
    5.35 -    case CMSG_USBIF_BE_DISCONNECT:
    5.36 -        if ( msg->length != sizeof(usbif_be_disconnect_t) )
    5.37 -            goto parse_error;
    5.38 -        if ( !usbif_disconnect((usbif_be_disconnect_t *)&msg->msg[0],msg->id) )
    5.39 -            return; /* Sending the response is deferred until later. */
    5.40 -        break;        
    5.41 -    case CMSG_USBIF_BE_CLAIM_PORT:
    5.42 -        if ( msg->length != sizeof(usbif_be_claim_port_t) )
    5.43 -            goto parse_error;
    5.44 -	usbif_claim_port((usbif_be_claim_port_t *)&msg->msg[0]);
    5.45 -        break;
    5.46 -    case CMSG_USBIF_BE_RELEASE_PORT:
    5.47 -        if ( msg->length != sizeof(usbif_be_release_port_t) )
    5.48 -            goto parse_error;
    5.49 -        usbif_release_port((usbif_be_release_port_t *)&msg->msg[0]);
    5.50 -        break;
    5.51 -    default:
    5.52 -        goto parse_error;
    5.53 -    }
    5.54 -
    5.55 -    ctrl_if_send_response(msg);
    5.56 -    return;
    5.57 -
    5.58 - parse_error:
    5.59 -    DPRINTK("Parse error while reading message subtype %d, len %d\n",
    5.60 -            msg->subtype, msg->length);
    5.61 -    msg->length = 0;
    5.62 -    ctrl_if_send_response(msg);
    5.63 -}
    5.64 -
    5.65 -void usbif_ctrlif_init(void)
    5.66 -{
    5.67 -    ctrl_msg_t                       cmsg;
    5.68 -    usbif_be_driver_status_changed_t st;
    5.69 -
    5.70 -    (void)ctrl_if_register_receiver(CMSG_USBIF_BE, usbif_ctrlif_rx, 
    5.71 -                                    CALLBACK_IN_BLOCKING_CONTEXT);
    5.72 -
    5.73 -    /* Send a driver-UP notification to the domain controller. */
    5.74 -    cmsg.type      = CMSG_USBIF_BE;
    5.75 -    cmsg.subtype   = CMSG_USBIF_BE_DRIVER_STATUS_CHANGED;
    5.76 -    cmsg.length    = sizeof(usbif_be_driver_status_changed_t);
    5.77 -    st.status      = USBIF_DRIVER_STATUS_UP;
    5.78 -    memcpy(cmsg.msg, &st, sizeof(st));
    5.79 -    ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
    5.80 -}
     6.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/interface.c	Sat Jan 22 15:16:02 2005 +0000
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,248 +0,0 @@
     6.4 -/******************************************************************************
     6.5 - * arch/xen/drivers/usbif/backend/interface.c
     6.6 - * 
     6.7 - * USB device interface management.
     6.8 - * 
     6.9 - * by Mark Williamson, Copyright (c) 2004
    6.10 - */
    6.11 -
    6.12 -
    6.13 -/******************************************************************************
    6.14 - * arch/xen/drivers/blkif/backend/interface.c
    6.15 - * 
    6.16 - * Block-device interface management.
    6.17 - * 
    6.18 - * Copyright (c) 2004, Keir Fraser
    6.19 - */
    6.20 -
    6.21 -#include "common.h"
    6.22 -
    6.23 -#define USBIF_HASHSZ 1024
    6.24 -#define USBIF_HASH(_d) (((int)(_d))&(USBIF_HASHSZ-1))
    6.25 -
    6.26 -static kmem_cache_t      *usbif_priv_cachep;
    6.27 -static usbif_priv_t      *usbif_priv_hash[USBIF_HASHSZ];
    6.28 -
    6.29 -usbif_priv_t *usbif_find(domid_t domid)
    6.30 -{
    6.31 -    usbif_priv_t *up = usbif_priv_hash[USBIF_HASH(domid)];
    6.32 -    while ( (up != NULL ) && ( up->domid != domid ) )
    6.33 -        up = up->hash_next;
    6.34 -    return up;
    6.35 -}
    6.36 -
    6.37 -static void __usbif_disconnect_complete(void *arg)
    6.38 -{
    6.39 -    usbif_priv_t         *usbif = (usbif_priv_t *)arg;
    6.40 -    ctrl_msg_t            cmsg;
    6.41 -    usbif_be_disconnect_t disc;
    6.42 -
    6.43 -    /*
    6.44 -     * These can't be done in usbif_disconnect() because at that point there
    6.45 -     * may be outstanding requests at the device whose asynchronous responses
    6.46 -     * must still be notified to the remote driver.
    6.47 -     */
    6.48 -    unbind_evtchn_from_irq(usbif->evtchn);
    6.49 -    vfree(usbif->usb_ring_base);
    6.50 -
    6.51 -    /* Construct the deferred response message. */
    6.52 -    cmsg.type         = CMSG_USBIF_BE;
    6.53 -    cmsg.subtype      = CMSG_USBIF_BE_DISCONNECT;
    6.54 -    cmsg.id           = usbif->disconnect_rspid;
    6.55 -    cmsg.length       = sizeof(usbif_be_disconnect_t);
    6.56 -    disc.domid        = usbif->domid;
    6.57 -    disc.status       = USBIF_BE_STATUS_OKAY;
    6.58 -    memcpy(cmsg.msg, &disc, sizeof(disc));
    6.59 -
    6.60 -    /*
    6.61 -     * Make sure message is constructed /before/ status change, because
    6.62 -     * after the status change the 'usbif' structure could be deallocated at
    6.63 -     * any time. Also make sure we send the response /after/ status change,
    6.64 -     * as otherwise a subsequent CONNECT request could spuriously fail if
    6.65 -     * another CPU doesn't see the status change yet.
    6.66 -     */
    6.67 -    mb();
    6.68 -    if ( usbif->status != DISCONNECTING )
    6.69 -        BUG();
    6.70 -    usbif->status = DISCONNECTED;
    6.71 -    mb();
    6.72 -
    6.73 -    /* Send the successful response. */
    6.74 -    ctrl_if_send_response(&cmsg);
    6.75 -}
    6.76 -
    6.77 -void usbif_disconnect_complete(usbif_priv_t *up)
    6.78 -{
    6.79 -    INIT_WORK(&up->work, __usbif_disconnect_complete, (void *)up);
    6.80 -    schedule_work(&up->work);
    6.81 -}
    6.82 -
    6.83 -void usbif_create(usbif_be_create_t *create)
    6.84 -{
    6.85 -    domid_t       domid  = create->domid;
    6.86 -    usbif_priv_t **pup, *up;
    6.87 -
    6.88 -    if ( (up = kmem_cache_alloc(usbif_priv_cachep, GFP_KERNEL)) == NULL )
    6.89 -    {
    6.90 -        DPRINTK("Could not create usbif: out of memory\n");
    6.91 -        create->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
    6.92 -        return;
    6.93 -    }
    6.94 -
    6.95 -    memset(up, 0, sizeof(*up));
    6.96 -    up->domid  = domid;
    6.97 -    up->status = DISCONNECTED;
    6.98 -    spin_lock_init(&up->usb_ring_lock);
    6.99 -    atomic_set(&up->refcnt, 0);
   6.100 -
   6.101 -    pup = &usbif_priv_hash[USBIF_HASH(domid)];
   6.102 -    while ( *pup != NULL )
   6.103 -    {
   6.104 -        if ( (*pup)->domid == domid )
   6.105 -        {
   6.106 -            create->status = USBIF_BE_STATUS_INTERFACE_EXISTS;
   6.107 -            kmem_cache_free(usbif_priv_cachep, up);
   6.108 -            return;
   6.109 -        }
   6.110 -        pup = &(*pup)->hash_next;
   6.111 -    }
   6.112 -
   6.113 -    up->hash_next = *pup;
   6.114 -    *pup = up;
   6.115 -
   6.116 -    create->status = USBIF_BE_STATUS_OKAY;
   6.117 -}
   6.118 -
   6.119 -void usbif_destroy(usbif_be_destroy_t *destroy)
   6.120 -{
   6.121 -    domid_t       domid  = destroy->domid;
   6.122 -    usbif_priv_t  **pup, *up;
   6.123 -
   6.124 -    pup = &usbif_priv_hash[USBIF_HASH(domid)];
   6.125 -    while ( (up = *pup) != NULL )
   6.126 -    {
   6.127 -        if ( up->domid == domid )
   6.128 -        {
   6.129 -            if ( up->status != DISCONNECTED )
   6.130 -                goto still_connected;
   6.131 -            goto destroy;
   6.132 -        }
   6.133 -        pup = &up->hash_next;
   6.134 -    }
   6.135 -
   6.136 -    destroy->status = USBIF_BE_STATUS_INTERFACE_NOT_FOUND;
   6.137 -    return;
   6.138 -
   6.139 - still_connected:
   6.140 -    destroy->status = USBIF_BE_STATUS_INTERFACE_CONNECTED;
   6.141 -    return;
   6.142 -
   6.143 - destroy:
   6.144 -    *pup = up->hash_next;
   6.145 -    usbif_release_ports(up);
   6.146 -    kmem_cache_free(usbif_priv_cachep, up);
   6.147 -    destroy->status = USBIF_BE_STATUS_OKAY;
   6.148 -}
   6.149 -
   6.150 -void usbif_connect(usbif_be_connect_t *connect)
   6.151 -{
   6.152 -    domid_t       domid  = connect->domid;
   6.153 -    unsigned int  evtchn = connect->evtchn;
   6.154 -    unsigned long shmem_frame = connect->shmem_frame;
   6.155 -    struct vm_struct *vma;
   6.156 -    pgprot_t      prot;
   6.157 -    int           error;
   6.158 -    usbif_priv_t *up;
   6.159 -
   6.160 -    up = usbif_find(domid);
   6.161 -    if ( unlikely(up == NULL) )
   6.162 -    {
   6.163 -        DPRINTK("usbif_connect attempted for non-existent usbif (%u)\n", 
   6.164 -                connect->domid); 
   6.165 -        connect->status = USBIF_BE_STATUS_INTERFACE_NOT_FOUND;
   6.166 -        return;
   6.167 -    }
   6.168 -
   6.169 -    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
   6.170 -    {
   6.171 -        connect->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
   6.172 -        return;
   6.173 -    }
   6.174 -
   6.175 -    prot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED);
   6.176 -    error = direct_remap_area_pages(&init_mm, VMALLOC_VMADDR(vma->addr),
   6.177 -                                    shmem_frame<<PAGE_SHIFT, PAGE_SIZE,
   6.178 -                                    prot, domid);
   6.179 -    if ( error != 0 )
   6.180 -    {
   6.181 -        if ( error == -ENOMEM )
   6.182 -            connect->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
   6.183 -        else if ( error == -EFAULT )
   6.184 -            connect->status = USBIF_BE_STATUS_MAPPING_ERROR;
   6.185 -        else
   6.186 -            connect->status = USBIF_BE_STATUS_ERROR;
   6.187 -        vfree(vma->addr);
   6.188 -        return;
   6.189 -    }
   6.190 -
   6.191 -    if ( up->status != DISCONNECTED )
   6.192 -    {
   6.193 -        connect->status = USBIF_BE_STATUS_INTERFACE_CONNECTED;
   6.194 -        vfree(vma->addr);
   6.195 -        return;
   6.196 -    }
   6.197 -
   6.198 -    up->evtchn        = evtchn;
   6.199 -    up->irq           = bind_evtchn_to_irq(evtchn);
   6.200 -    up->shmem_frame   = shmem_frame;
   6.201 -    up->usb_ring_base = (usbif_t *)vma->addr;
   6.202 -    up->status        = CONNECTED;
   6.203 -    usbif_get(up);
   6.204 -
   6.205 -    request_irq(up->irq, usbif_be_int, 0, "usbif-backend", up);
   6.206 -
   6.207 -    connect->status = USBIF_BE_STATUS_OKAY;
   6.208 -}
   6.209 -
   6.210 -/* Remove URBs for this interface before destroying it. */
   6.211 -void usbif_deschedule(usbif_priv_t *up)
   6.212 -{
   6.213 -    remove_from_usbif_list(up);
   6.214 -}
   6.215 -
   6.216 -int usbif_disconnect(usbif_be_disconnect_t *disconnect, u8 rsp_id)
   6.217 -{
   6.218 -    domid_t       domid  = disconnect->domid;
   6.219 -    usbif_priv_t *up;
   6.220 -
   6.221 -    up = usbif_find(domid);
   6.222 -    if ( unlikely(up == NULL) )
   6.223 -    {
   6.224 -        DPRINTK("usbif_disconnect attempted for non-existent usbif"
   6.225 -                " (%u)\n", disconnect->domid); 
   6.226 -        disconnect->status = USBIF_BE_STATUS_INTERFACE_NOT_FOUND;
   6.227 -        return 1; /* Caller will send response error message. */
   6.228 -    }
   6.229 -
   6.230 -    if ( up->status == CONNECTED )
   6.231 -    {
   6.232 -        up->status = DISCONNECTING;
   6.233 -        up->disconnect_rspid = rsp_id;
   6.234 -        wmb(); /* Let other CPUs see the status change. */
   6.235 -        free_irq(up->irq, up);
   6.236 -	usbif_deschedule(up);
   6.237 -        usbif_put(up);
   6.238 -        return 0; /* Caller should not send response message. */
   6.239 -    }
   6.240 -
   6.241 -    disconnect->status = USBIF_BE_STATUS_OKAY;
   6.242 -    return 1;
   6.243 -}
   6.244 -
   6.245 -void __init usbif_interface_init(void)
   6.246 -{
   6.247 -    usbif_priv_cachep = kmem_cache_create("usbif_priv_cache",
   6.248 -					  sizeof(usbif_priv_t), 
   6.249 -					  0, 0, NULL, NULL);
   6.250 -    memset(usbif_priv_hash, 0, sizeof(usbif_priv_hash));
   6.251 -}
     7.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/backend/main.c	Sat Jan 22 15:16:02 2005 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,1011 +0,0 @@
     7.4 -/******************************************************************************
     7.5 - * arch/xen/drivers/usbif/backend/main.c
     7.6 - * 
     7.7 - * Backend for the Xen virtual USB driver - provides an abstraction of a
     7.8 - * USB host controller to the corresponding frontend driver.
     7.9 - *
    7.10 - * by Mark Williamson, Copyright (c) 2004 Intel Research Cambridge
    7.11 - *
    7.12 - * Based on arch/xen/drivers/blkif/backend/main.c
    7.13 - * Copyright (c) 2003-2004, Keir Fraser & Steve Hand
    7.14 - */
    7.15 -
    7.16 -#include "common.h"
    7.17 -
    7.18 -
    7.19 -#include <linux/list.h>
    7.20 -#include <linux/usb.h>
    7.21 -#include <linux/spinlock.h>
    7.22 -#include <linux/module.h>
    7.23 -#include <linux/tqueue.h>
    7.24 -
    7.25 -/*
    7.26 - * This is rather arbitrary.
    7.27 - */
    7.28 -#define MAX_PENDING_REQS 4
    7.29 -#define BATCH_PER_DOMAIN 1
    7.30 -
    7.31 -static unsigned long mmap_vstart;
    7.32 -
    7.33 -/* Needs to be sufficiently large that we can map the (large) buffers
    7.34 - * the USB mass storage driver wants. */
    7.35 -#define MMAP_PAGES_PER_REQUEST \
    7.36 -    (128)
    7.37 -#define MMAP_PAGES             \
    7.38 -    (MAX_PENDING_REQS * MMAP_PAGES_PER_REQUEST)
    7.39 -
    7.40 -#define MMAP_VADDR(_req,_seg)                        \
    7.41 -    (mmap_vstart +                                   \
    7.42 -     ((_req) * MMAP_PAGES_PER_REQUEST * PAGE_SIZE) + \
    7.43 -     ((_seg) * PAGE_SIZE))
    7.44 -
    7.45 -#define MIN(x,y) ( ( x < y ) ? x : y )
    7.46 -
    7.47 -static spinlock_t owned_ports_lock;
    7.48 -LIST_HEAD(owned_ports);
    7.49 -
    7.50 -/* A list of these structures is used to track ownership of physical USB
    7.51 - * ports. */
    7.52 -typedef struct 
    7.53 -{
    7.54 -    usbif_priv_t     *usbif_priv;
    7.55 -    char             path[16];
    7.56 -    int               guest_port;
    7.57 -    int enabled;
    7.58 -    struct list_head  list;
    7.59 -    unsigned long guest_address; /* The USB device address that has been
    7.60 -                                  * assigned by the guest. */
    7.61 -    int               dev_present; /* Is there a device present? */
    7.62 -    struct usb_device * dev;
    7.63 -    unsigned long ifaces;  /* What interfaces are present on this device? */
    7.64 -} owned_port_t;
    7.65 -
    7.66 -
    7.67 -/*
    7.68 - * Each outstanding request that we've passed to the lower device layers has a
    7.69 - * 'pending_req' allocated to it.  The request is complete, the specified
    7.70 - * domain has a response queued for it, with the saved 'id' passed back.
    7.71 - */
    7.72 -typedef struct {
    7.73 -    usbif_priv_t       *usbif_priv;
    7.74 -    usbif_iso_t        *iso_sched;
    7.75 -    unsigned long      id;
    7.76 -    int                nr_pages;
    7.77 -    unsigned short     operation;
    7.78 -    int                status;
    7.79 -} pending_req_t;
    7.80 -
    7.81 -/*
    7.82 - * We can't allocate pending_req's in order, since they may complete out of 
    7.83 - * order. We therefore maintain an allocation ring. This ring also indicates 
    7.84 - * when enough work has been passed down -- at that point the allocation ring 
    7.85 - * will be empty.
    7.86 - */
    7.87 -static pending_req_t pending_reqs[MAX_PENDING_REQS];
    7.88 -static unsigned char pending_ring[MAX_PENDING_REQS];
    7.89 -static spinlock_t pend_prod_lock = SPIN_LOCK_UNLOCKED;
    7.90 -
    7.91 -/* NB. We use a different index type to differentiate from shared blk rings. */
    7.92 -typedef unsigned int PEND_RING_IDX;
    7.93 -#define MASK_PEND_IDX(_i) ((_i)&(MAX_PENDING_REQS-1))
    7.94 -static PEND_RING_IDX pending_prod, pending_cons;
    7.95 -#define NR_PENDING_REQS (MAX_PENDING_REQS - pending_prod + pending_cons)
    7.96 -
    7.97 -static int do_usb_io_op(usbif_priv_t *usbif, int max_to_do);
    7.98 -static void make_response(usbif_priv_t *usbif, unsigned long id, 
    7.99 -                          unsigned short op, int st, int inband,
   7.100 -			  unsigned long actual_length);
   7.101 -static void dispatch_usb_probe(usbif_priv_t *up, unsigned long id, unsigned long port);
   7.102 -static void dispatch_usb_io(usbif_priv_t *up, usbif_request_t *req);    
   7.103 -static void dispatch_usb_reset(usbif_priv_t *up, unsigned long portid);
   7.104 -static owned_port_t *usbif_find_port(char *);
   7.105 -
   7.106 -
   7.107 -void dump_port(owned_port_t *p)
   7.108 -{
   7.109 -    printk("owned_port_t @ %p\n", p);
   7.110 -    printk("  usbif_priv @ %p\n", p->usbif_priv);
   7.111 -    printk("  path: %s\n", p->path);
   7.112 -    printk("  guest_port: %d\n", p->guest_port);
   7.113 -    printk("  guest_address: %ld\n", p->guest_address);
   7.114 -    printk("  dev_present: %d\n", p->dev_present);
   7.115 -    printk("  dev @ %p\n", p->dev);
   7.116 -    printk("  ifaces: 0x%lx\n", p->ifaces);
   7.117 -}
   7.118 -
   7.119 -
   7.120 -
   7.121 -static void fast_flush_area(int idx, int nr_pages)
   7.122 -{
   7.123 -    multicall_entry_t mcl[MMAP_PAGES_PER_REQUEST];
   7.124 -    int               i;
   7.125 -
   7.126 -    for ( i = 0; i < nr_pages; i++ )
   7.127 -    {
   7.128 -        mcl[i].op = __HYPERVISOR_update_va_mapping;
   7.129 -        mcl[i].args[0] = MMAP_VADDR(idx, i) >> PAGE_SHIFT;
   7.130 -        mcl[i].args[1] = 0;
   7.131 -        mcl[i].args[2] = 0;
   7.132 -    }
   7.133 -
   7.134 -    mcl[nr_pages-1].args[2] = UVMF_FLUSH_TLB;
   7.135 -    if ( unlikely(HYPERVISOR_multicall(mcl, nr_pages) != 0) )
   7.136 -        BUG();
   7.137 -}
   7.138 -
   7.139 -
   7.140 -/******************************************************************
   7.141 - * USB INTERFACE SCHEDULER LIST MAINTENANCE
   7.142 - */
   7.143 -
   7.144 -static struct list_head usbio_schedule_list;
   7.145 -static spinlock_t usbio_schedule_list_lock;
   7.146 -
   7.147 -static int __on_usbif_list(usbif_priv_t *up)
   7.148 -{
   7.149 -    return up->usbif_list.next != NULL;
   7.150 -}
   7.151 -
   7.152 -void remove_from_usbif_list(usbif_priv_t *up)
   7.153 -{
   7.154 -    unsigned long flags;
   7.155 -    if ( !__on_usbif_list(up) ) return;
   7.156 -    spin_lock_irqsave(&usbio_schedule_list_lock, flags);
   7.157 -    if ( __on_usbif_list(up) )
   7.158 -    {
   7.159 -        list_del(&up->usbif_list);
   7.160 -        up->usbif_list.next = NULL;
   7.161 -        usbif_put(up);
   7.162 -    }
   7.163 -    spin_unlock_irqrestore(&usbio_schedule_list_lock, flags);
   7.164 -}
   7.165 -
   7.166 -static void add_to_usbif_list_tail(usbif_priv_t *up)
   7.167 -{
   7.168 -    unsigned long flags;
   7.169 -    if ( __on_usbif_list(up) ) return;
   7.170 -    spin_lock_irqsave(&usbio_schedule_list_lock, flags);
   7.171 -    if ( !__on_usbif_list(up) && (up->status == CONNECTED) )
   7.172 -    {
   7.173 -        list_add_tail(&up->usbif_list, &usbio_schedule_list);
   7.174 -        usbif_get(up);
   7.175 -    }
   7.176 -    spin_unlock_irqrestore(&usbio_schedule_list_lock, flags);
   7.177 -}
   7.178 -
   7.179 -
   7.180 -/******************************************************************
   7.181 - * COMPLETION CALLBACK -- Called as urb->complete()
   7.182 - */
   7.183 -
   7.184 -static void maybe_trigger_usbio_schedule(void);
   7.185 -
   7.186 -static void __end_usb_io_op(struct urb *purb)
   7.187 -{
   7.188 -    unsigned long flags;
   7.189 -    pending_req_t *pending_req;
   7.190 -    int pending_idx;
   7.191 -
   7.192 -    pending_req = purb->context;
   7.193 -
   7.194 -/*     printk("Completed for id = %p to 0x%lx - 0x%lx\n", pending_req->id, */
   7.195 -/*            virt_to_machine(purb->transfer_buffer), */
   7.196 -/*            virt_to_machine(purb->transfer_buffer) */
   7.197 -/*            + pending_req->nr_pages * PAGE_SIZE); */
   7.198 -
   7.199 -    pending_idx = pending_req - pending_reqs;
   7.200 -
   7.201 -    ASSERT(purb->actual_length <= purb->transfer_buffer_length);
   7.202 -    ASSERT(purb->actual_length <= pending_req->nr_pages * PAGE_SIZE);
   7.203 -    
   7.204 -    /* An error fails the entire request. */
   7.205 -    if ( purb->status )
   7.206 -    {
   7.207 -        printk("URB @ %p failed. Status %d\n", purb, purb->status);
   7.208 -    }
   7.209 -
   7.210 -    if ( usb_pipetype(purb->pipe) == 0 )
   7.211 -    {
   7.212 -        int i;
   7.213 -        usbif_iso_t *sched = (usbif_iso_t *)MMAP_VADDR(pending_idx, pending_req->nr_pages - 1);
   7.214 -
   7.215 -        ASSERT(sched == pending_req->sched);
   7.216 -
   7.217 -	//	printk("writing back schedule at %p\n", sched);
   7.218 -
   7.219 -        /* If we're dealing with an iso pipe, we need to copy back the schedule. */
   7.220 -        for ( i = 0; i < purb->number_of_packets; i++ )
   7.221 -        {
   7.222 -            sched[i].length = purb->iso_frame_desc[i].actual_length;
   7.223 -            ASSERT(sched[i].buffer_offset ==
   7.224 -                   purb->iso_frame_desc[i].offset);
   7.225 -            sched[i].status = purb->iso_frame_desc[i].status;
   7.226 -        }
   7.227 -    }
   7.228 -    
   7.229 -    //    printk("Flushing %d pages\n", pending_req->nr_pages);
   7.230 -    fast_flush_area(pending_req - pending_reqs, pending_req->nr_pages);
   7.231 -
   7.232 -    kfree(purb->setup_packet);
   7.233 -
   7.234 -    spin_lock_irqsave(&pending_req->usbif_priv->usb_ring_lock, flags);
   7.235 -    make_response(pending_req->usbif_priv, pending_req->id,
   7.236 -		  pending_req->operation, pending_req->status, 0, purb->actual_length);
   7.237 -    spin_unlock_irqrestore(&pending_req->usbif_priv->usb_ring_lock, flags);
   7.238 -    usbif_put(pending_req->usbif_priv);
   7.239 -
   7.240 -    usb_free_urb(purb);
   7.241 -
   7.242 -    /* Free the pending request. */
   7.243 -    spin_lock_irqsave(&pend_prod_lock, flags);
   7.244 -    pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
   7.245 -    spin_unlock_irqrestore(&pend_prod_lock, flags);
   7.246 -
   7.247 -    rmb();
   7.248 -
   7.249 -    /* Check for anything still waiting in the rings, having freed a request... */
   7.250 -    maybe_trigger_usbio_schedule();
   7.251 -}
   7.252 -
   7.253 -/******************************************************************
   7.254 - * SCHEDULER FUNCTIONS
   7.255 - */
   7.256 -
   7.257 -static DECLARE_WAIT_QUEUE_HEAD(usbio_schedule_wait);
   7.258 -
   7.259 -static int usbio_schedule(void *arg)
   7.260 -{
   7.261 -    DECLARE_WAITQUEUE(wq, current);
   7.262 -
   7.263 -    usbif_priv_t          *up;
   7.264 -    struct list_head *ent;
   7.265 -
   7.266 -    daemonize();
   7.267 -
   7.268 -    for ( ; ; )
   7.269 -    {
   7.270 -        /* Wait for work to do. */
   7.271 -        add_wait_queue(&usbio_schedule_wait, &wq);
   7.272 -        set_current_state(TASK_INTERRUPTIBLE);
   7.273 -        if ( (NR_PENDING_REQS == MAX_PENDING_REQS) || 
   7.274 -             list_empty(&usbio_schedule_list) )
   7.275 -            schedule();
   7.276 -        __set_current_state(TASK_RUNNING);
   7.277 -        remove_wait_queue(&usbio_schedule_wait, &wq);
   7.278 -
   7.279 -        /* Queue up a batch of requests. */
   7.280 -        while ( (NR_PENDING_REQS < MAX_PENDING_REQS) &&
   7.281 -                !list_empty(&usbio_schedule_list) )
   7.282 -        {
   7.283 -            ent = usbio_schedule_list.next;
   7.284 -            up = list_entry(ent, usbif_priv_t, usbif_list);
   7.285 -            usbif_get(up);
   7.286 -            remove_from_usbif_list(up);
   7.287 -            if ( do_usb_io_op(up, BATCH_PER_DOMAIN) )
   7.288 -                add_to_usbif_list_tail(up);
   7.289 -            usbif_put(up);
   7.290 -        }
   7.291 -    }
   7.292 -}
   7.293 -
   7.294 -static void maybe_trigger_usbio_schedule(void)
   7.295 -{
   7.296 -    /*
   7.297 -     * Needed so that two processes, who together make the following predicate
   7.298 -     * true, don't both read stale values and evaluate the predicate
   7.299 -     * incorrectly. Incredibly unlikely to stall the scheduler on x86, but...
   7.300 -     */
   7.301 -    smp_mb();
   7.302 -
   7.303 -    if ( !list_empty(&usbio_schedule_list) )
   7.304 -        wake_up(&usbio_schedule_wait);
   7.305 -}
   7.306 -
   7.307 -
   7.308 -/******************************************************************************
   7.309 - * NOTIFICATION FROM GUEST OS.
   7.310 - */
   7.311 -
   7.312 -irqreturn_t usbif_be_int(int irq, void *dev_id, struct pt_regs *regs)
   7.313 -{
   7.314 -    usbif_priv_t *up = dev_id;
   7.315 -
   7.316 -    smp_mb();
   7.317 -
   7.318 -    add_to_usbif_list_tail(up); 
   7.319 -
   7.320 -    /* Will in fact /always/ trigger an io schedule in this case. */
   7.321 -    maybe_trigger_usbio_schedule();
   7.322 -
   7.323 -    return IRQ_HANDLED;
   7.324 -}
   7.325 -
   7.326 -
   7.327 -
   7.328 -/******************************************************************
   7.329 - * DOWNWARD CALLS -- These interface with the usb-device layer proper.
   7.330 - */
   7.331 -
   7.332 -static int do_usb_io_op(usbif_priv_t *up, int max_to_do)
   7.333 -{
   7.334 -    usbif_t *usb_ring = up->usb_ring_base;
   7.335 -    usbif_request_t *req;
   7.336 -    USBIF_RING_IDX i, rp;
   7.337 -    int more_to_do = 0;
   7.338 -    unsigned long flags;
   7.339 -
   7.340 -    spin_lock_irqsave(&up->usb_ring_lock, flags);
   7.341 -
   7.342 -    rp = usb_ring->req_prod;
   7.343 -    rmb(); /* Ensure we see queued requests up to 'rp'. */
   7.344 -    
   7.345 -    /* Take items off the comms ring, taking care not to overflow. */
   7.346 -    for ( i = up->usb_req_cons; 
   7.347 -          (i != rp) && ((i-up->usb_resp_prod) != USBIF_RING_SIZE);
   7.348 -          i++ )
   7.349 -    {
   7.350 -        if ( (max_to_do-- == 0) || (NR_PENDING_REQS == MAX_PENDING_REQS) )
   7.351 -        {
   7.352 -            more_to_do = 1;
   7.353 -            break;
   7.354 -        }
   7.355 -
   7.356 -        req = &usb_ring->ring[MASK_USBIF_IDX(i)].req;
   7.357 -        
   7.358 -        switch ( req->operation )
   7.359 -        {
   7.360 -        case USBIF_OP_PROBE:
   7.361 -            dispatch_usb_probe(up, req->id, req->port);
   7.362 -            break;
   7.363 -
   7.364 -        case USBIF_OP_IO:
   7.365 -	  /* Assemble an appropriate URB. */
   7.366 -	  dispatch_usb_io(up, req);
   7.367 -          break;
   7.368 -
   7.369 -	case USBIF_OP_RESET:
   7.370 -	  dispatch_usb_reset(up, req->port);
   7.371 -          break;
   7.372 -
   7.373 -        default:
   7.374 -            DPRINTK("error: unknown USB io operation [%d]\n",
   7.375 -                    req->operation);
   7.376 -            make_response(up, req->id, req->operation, -EINVAL, 0, 0);
   7.377 -            break;
   7.378 -        }
   7.379 -    }
   7.380 -
   7.381 -    up->usb_req_cons = i;
   7.382 -
   7.383 -    spin_unlock_irqrestore(&up->usb_ring_lock, flags);
   7.384 -
   7.385 -    return more_to_do;
   7.386 -}
   7.387 -
   7.388 -static owned_port_t *find_guest_port(usbif_priv_t *up, int port)
   7.389 -{
   7.390 -    unsigned long flags;
   7.391 -    struct list_head *l;
   7.392 -
   7.393 -    spin_lock_irqsave(&owned_ports_lock, flags);
   7.394 -    list_for_each(l, &owned_ports)
   7.395 -    {
   7.396 -        owned_port_t *p = list_entry(l, owned_port_t, list);
   7.397 -        if(p->usbif_priv == up && p->guest_port == port)
   7.398 -        {
   7.399 -            spin_unlock_irqrestore(&owned_ports_lock, flags);
   7.400 -            return p;
   7.401 -        }
   7.402 -    }
   7.403 -    spin_unlock_irqrestore(&owned_ports_lock, flags);
   7.404 -
   7.405 -    return NULL;
   7.406 -}
   7.407 -
   7.408 -static void dispatch_usb_reset(usbif_priv_t *up, unsigned long portid)
   7.409 -{
   7.410 -    owned_port_t *port = find_guest_port(up, portid);
   7.411 -    int ret = 0;
   7.412 -
   7.413 -
   7.414 -    /* Allowing the guest to actually reset the device causes more problems
   7.415 -     * than it's worth.  We just fake it out in software but we will do a real
   7.416 -     * reset when the interface is destroyed. */
   7.417 -
   7.418 -#if 0
   7.419 -    printk("Reset port %d\n", portid);
   7.420 -
   7.421 -    dump_port(port);
   7.422 -#endif
   7.423 -
   7.424 -    port->guest_address = 0;
   7.425 -    /* If there's an attached device then the port is now enabled. */
   7.426 -    if ( port->dev_present )
   7.427 -        port->enabled = 1;
   7.428 -    else
   7.429 -        port->enabled = 0;
   7.430 -
   7.431 -    make_response(up, 0, USBIF_OP_RESET, ret, 0, 0);
   7.432 -}
   7.433 -
   7.434 -static void dispatch_usb_probe(usbif_priv_t *up, unsigned long id, unsigned long portid)
   7.435 -{
   7.436 -    owned_port_t *port = find_guest_port(up, portid);
   7.437 -    int ret;
   7.438 - 
   7.439 -    if ( port != NULL )
   7.440 -        ret = port->dev_present;
   7.441 -    else
   7.442 -    {
   7.443 -        ret = -EINVAL;
   7.444 -        printk("dispatch_usb_probe(): invalid port probe request (port %ld)\n",
   7.445 -	       portid);
   7.446 -    }
   7.447 -
   7.448 -    /* Probe result is sent back in-band.  Probes don't have an associated id
   7.449 -     * right now... */
   7.450 -    make_response(up, id, USBIF_OP_PROBE, ret, portid, 0);
   7.451 -}
   7.452 -
   7.453 -owned_port_t *find_port_for_request(usbif_priv_t *up, usbif_request_t *req);
   7.454 -
   7.455 -static void dump_request(usbif_request_t *req)
   7.456 -{    
   7.457 -    printk("id = 0x%lx\n", req->id);
   7.458 -    
   7.459 -	printk("devnum %d\n", req->devnum);
   7.460 -	printk("endpoint 0x%x\n", req->endpoint);
   7.461 -	printk("direction %d\n", req->direction);
   7.462 -	printk("speed %d\n", req->speed);
   7.463 -        printk("pipe_type 0x%x\n", req->pipe_type);
   7.464 -        printk("transfer_buffer 0x%lx\n", req->transfer_buffer);
   7.465 -        printk("length 0x%lx\n", req->length);
   7.466 -        printk("transfer_flags 0x%lx\n", req->transfer_flags);
   7.467 -        printk("setup = { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
   7.468 -               req->setup[0], req->setup[1], req->setup[2], req->setup[3],
   7.469 -               req->setup[4], req->setup[5], req->setup[6], req->setup[7]);
   7.470 -        printk("iso_schedule = 0x%lx\n", req->iso_schedule);
   7.471 -        printk("num_iso %ld\n", req->num_iso);
   7.472 -}
   7.473 -
   7.474 -void dump_urb(struct urb *urb)
   7.475 -{
   7.476 -    printk("dumping urb @ %p\n", urb);
   7.477 -
   7.478 -#define DUMP_URB_FIELD(name, format) printk("  " # name " " format "\n", urb-> name)
   7.479 -    
   7.480 -    DUMP_URB_FIELD(pipe, "0x%x");
   7.481 -    DUMP_URB_FIELD(status, "%d");
   7.482 -    DUMP_URB_FIELD(transfer_flags, "0x%x");    
   7.483 -    DUMP_URB_FIELD(transfer_buffer, "%p");
   7.484 -    DUMP_URB_FIELD(transfer_buffer_length, "%d");
   7.485 -    DUMP_URB_FIELD(actual_length, "%d");
   7.486 -}
   7.487 -
   7.488 -
   7.489 -static void dispatch_usb_io(usbif_priv_t *up, usbif_request_t *req)
   7.490 -{
   7.491 -    unsigned long buffer_mach;
   7.492 -    int i = 0, offset = 0,
   7.493 -        pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
   7.494 -    pending_req_t *pending_req;
   7.495 -    unsigned long  remap_prot;
   7.496 -    multicall_entry_t mcl[MMAP_PAGES_PER_REQUEST];
   7.497 -    struct urb *purb = NULL;
   7.498 -    owned_port_t *port;
   7.499 -    unsigned char *setup;    
   7.500 -
   7.501 -//    dump_request(req);
   7.502 -
   7.503 -    if ( NR_PENDING_REQS == MAX_PENDING_REQS )
   7.504 -    {
   7.505 -        printk("usbback: Max requests already queued.  Now giving up!\n");
   7.506 -        
   7.507 -        return;
   7.508 -    }
   7.509 -
   7.510 -    port = find_port_for_request(up, req);
   7.511 -
   7.512 -    if(port == NULL)
   7.513 -    {
   7.514 -	printk("No such device! (%d)\n", req->devnum);
   7.515 -	dump_request(req);
   7.516 -
   7.517 -        make_response(up, req->id, req->operation, -ENODEV, 0, 0);
   7.518 -	return;
   7.519 -    }
   7.520 -
   7.521 -    setup = kmalloc(8, GFP_ATOMIC | GFP_NOIO);
   7.522 -
   7.523 -    if ( setup == NULL )
   7.524 -        goto no_mem;
   7.525 -   
   7.526 -    /* Copy request out for safety. */
   7.527 -    memcpy(setup, req->setup, 8);
   7.528 -
   7.529 -    if( setup[0] == 0x0 && setup[1] == 0x5)
   7.530 -    {
   7.531 -        /* To virtualise the USB address space, we need to intercept
   7.532 -         * set_address messages and emulate.  From the USB specification:
   7.533 -         * bmRequestType = 0x0;
   7.534 -         * Brequest = SET_ADDRESS (i.e. 0x5)
   7.535 -         * wValue = device address
   7.536 -         * wIndex = 0
   7.537 -         * wLength = 0
   7.538 -         * data = None
   7.539 -         */
   7.540 -        /* Store into the guest transfer buffer using cpu_to_le16 */
   7.541 -        port->guest_address = le16_to_cpu(*(u16 *)(setup + 2));
   7.542 -        /* Make a successful response.  That was easy! */
   7.543 -
   7.544 -        make_response(up, req->id, req->operation, 0, 0, 0);
   7.545 -
   7.546 -	kfree(setup);
   7.547 -        return;
   7.548 -    }
   7.549 -    else if ( setup[0] == 0x0 && setup[1] == 0x9 )
   7.550 -    {
   7.551 -        /* The host kernel needs to know what device configuration is in use
   7.552 -         * because various error checks get confused otherwise.  We just do
   7.553 -         * configuration settings here, under controlled conditions.
   7.554 -         */
   7.555 -        usb_set_configuration(port->dev, setup[2]);
   7.556 -
   7.557 -        make_response(up, req->id, req->operation, 0, 0, 0);
   7.558 -
   7.559 -        kfree(setup);
   7.560 -        return;
   7.561 -    }
   7.562 -
   7.563 -    else if ( setup[0] == 0x1 && setup[1] == 0xB )
   7.564 -    {
   7.565 -        /* The host kernel needs to know what device interface is in use
   7.566 -         * because various error checks get confused otherwise.  We just do
   7.567 -         * configuration settings here, under controlled conditions.
   7.568 -         */
   7.569 -        usb_set_interface(port->dev, (setup[4] | setup[5] << 8),
   7.570 -                          (setup[2] | setup[3] << 8) );
   7.571 -
   7.572 -        make_response(up, req->id, req->operation, 0, 0, 0);
   7.573 -
   7.574 -        kfree(setup);
   7.575 -        return;
   7.576 -    }
   7.577 -
   7.578 -    if ( ( req->transfer_buffer - (req->transfer_buffer & PAGE_MASK)
   7.579 -	   + req->length )
   7.580 -	 > MMAP_PAGES_PER_REQUEST * PAGE_SIZE )
   7.581 -    {
   7.582 -        printk("usbback: request of %d bytes too large, failing it\n", req->length);
   7.583 -        make_response(up, req->id, req->operation, -EINVAL, 0, 0);
   7.584 -        kfree(setup);
   7.585 -        return;
   7.586 -    }
   7.587 -    
   7.588 -    buffer_mach = req->transfer_buffer;
   7.589 -
   7.590 -    if( buffer_mach == 0 )
   7.591 -	goto no_remap;
   7.592 -
   7.593 -    ASSERT((req->length >> PAGE_SHIFT) <= MMAP_PAGES_PER_REQUEST);
   7.594 -    ASSERT(buffer_mach);
   7.595 -
   7.596 -    /* Always map writeable for now. */
   7.597 -    remap_prot = _PAGE_PRESENT|_PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_RW;
   7.598 -
   7.599 -    for ( i = 0, offset = 0; offset < req->length;
   7.600 -          i++, offset += PAGE_SIZE )
   7.601 -    {
   7.602 -      //        printk("length = %d, offset = %d, looping!\n", req->length, offset);
   7.603 -        
   7.604 -	mcl[i].op = __HYPERVISOR_update_va_mapping_otherdomain;
   7.605 -	mcl[i].args[0] = MMAP_VADDR(pending_idx, i) >> PAGE_SHIFT;
   7.606 -        mcl[i].args[1] = ((buffer_mach & PAGE_MASK) + offset) | remap_prot;
   7.607 -        mcl[i].args[2] = 0;
   7.608 -        mcl[i].args[3] = up->domid;
   7.609 -        
   7.610 -        phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] =
   7.611 -            FOREIGN_FRAME((buffer_mach + offset) >> PAGE_SHIFT);
   7.612 -	//	printk("i = %d\n", i);
   7.613 -
   7.614 -        ASSERT(virt_to_machine(MMAP_VADDR(pending_idx, i))
   7.615 -               == buffer_mach + i << PAGE_SHIFT);
   7.616 -    }
   7.617 -
   7.618 -    if ( req->pipe_type == 0 && req->num_iso > 0 ) /* Maybe schedule ISO... */
   7.619 -    {
   7.620 -      //      printk("for iso, i = %d\n", i);
   7.621 -        /* Map in ISO schedule, if necessary. */
   7.622 -        mcl[i].op = __HYPERVISOR_update_va_mapping_otherdomain;
   7.623 -        mcl[i].args[0] = MMAP_VADDR(pending_idx, i) >> PAGE_SHIFT;
   7.624 -        mcl[i].args[1] = (req->iso_schedule & PAGE_MASK) | remap_prot;
   7.625 -        mcl[i].args[2] = 0;
   7.626 -        mcl[i].args[3] = up->domid;
   7.627 -
   7.628 -        phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] =
   7.629 -            FOREIGN_FRAME(req->iso_schedule >> PAGE_SHIFT);
   7.630 -    
   7.631 -        //    printk("Mapped iso at %p\n", MMAP_VADDR(pending_idx, i));
   7.632 -        i++;
   7.633 -    }
   7.634 -
   7.635 -    //    printk("Well we got this far!\n");
   7.636 -
   7.637 -    if ( unlikely(HYPERVISOR_multicall(mcl, i) != 0) )
   7.638 -        BUG();
   7.639 -    
   7.640 -    {
   7.641 -        int j;
   7.642 -        for ( j = 0; j < i; j++ )
   7.643 -        {
   7.644 -            if ( unlikely(mcl[j].args[5] != 0) )
   7.645 -            {
   7.646 -                printk("invalid buffer %d -- could not remap it\n", j);
   7.647 -                fast_flush_area(pending_idx, i);
   7.648 -		printk("sending invalid descriptor\n");
   7.649 -                goto bad_descriptor;
   7.650 -            }
   7.651 -	}
   7.652 -    }
   7.653 -    
   7.654 - no_remap:
   7.655 -
   7.656 -    ASSERT(i <= MMAP_PAGES_PER_REQUEST);
   7.657 -    ASSERT(i * PAGE_SIZE >= req->length);
   7.658 -
   7.659 -    /* We have to do this because some things might complete out of order. */
   7.660 -    pending_req = &pending_reqs[pending_idx];
   7.661 -    pending_req->usbif_priv= up;
   7.662 -    pending_req->id        = req->id;
   7.663 -    pending_req->operation = req->operation;
   7.664 -    pending_req->nr_pages  = i;
   7.665 -
   7.666 -
   7.667 -
   7.668 -    pending_cons++;
   7.669 -
   7.670 -    usbif_get(up);
   7.671 -    
   7.672 -    /* Fill out an actual request for the USB layer. */
   7.673 -    purb = usb_alloc_urb(req->num_iso);
   7.674 -
   7.675 -    if ( purb == NULL )
   7.676 -        goto no_mem;
   7.677 -
   7.678 -    purb->dev = port->dev;
   7.679 -    purb->context = pending_req;
   7.680 -    purb->transfer_buffer = (void *)MMAP_VADDR(pending_idx, 0) + (buffer_mach & ~PAGE_MASK);
   7.681 -    if(buffer_mach == 0)
   7.682 -      purb->transfer_buffer = NULL;
   7.683 -    purb->complete = __end_usb_io_op;
   7.684 -    purb->transfer_buffer_length = req->length;
   7.685 -    purb->transfer_flags = req->transfer_flags;
   7.686 -
   7.687 -/*     if ( req->transfer_flags != 0 ) */
   7.688 -/*       dump_request(req); */
   7.689 -
   7.690 -    purb->pipe = 0;
   7.691 -    purb->pipe |= req->direction << 7;
   7.692 -    purb->pipe |= port->dev->devnum << 8;
   7.693 -    purb->pipe |= req->speed << 26;
   7.694 -    purb->pipe |= req->pipe_type << 30;
   7.695 -    purb->pipe |= req->endpoint << 15;
   7.696 -
   7.697 -    purb->number_of_packets = req->num_iso;
   7.698 -
   7.699 -    /* Make sure there's always some kind of timeout. */
   7.700 -    purb->timeout = ( req->timeout > 0 ) ?  (req->timeout * HZ) / 1000
   7.701 -                    :  1000;
   7.702 -
   7.703 -    purb->setup_packet = setup;
   7.704 -
   7.705 -    if ( req->pipe_type == 0 ) /* ISO */
   7.706 -    {
   7.707 -        int j;
   7.708 -        usbif_iso_t *iso_sched = (usbif_iso_t *)MMAP_VADDR(pending_idx, i - 1);
   7.709 -
   7.710 -	//	printk("Reading iso sched at %p\n", iso_sched);
   7.711 -
   7.712 -        /* If we're dealing with an iso pipe, we need to copy in a schedule. */
   7.713 -        for ( j = 0; j < req->num_iso; j++ )
   7.714 -        {
   7.715 -            purb->iso_frame_desc[j].length = iso_sched[j].length;
   7.716 -            purb->iso_frame_desc[j].offset = iso_sched[j].buffer_offset;
   7.717 -            iso_sched[j].status = 0;
   7.718 -        }
   7.719 -        pending_req->iso_sched = iso_sched;
   7.720 -    }
   7.721 -
   7.722 -    {
   7.723 -      int ret;
   7.724 -      ret = usb_submit_urb(purb);
   7.725 -
   7.726 -      //      dump_urb(purb);
   7.727 -
   7.728 -      if ( ret != 0 )
   7.729 -          goto bad_descriptor; /* XXX free pending here! */
   7.730 -    }
   7.731 -    
   7.732 -    return;
   7.733 -
   7.734 - bad_descriptor:
   7.735 -    kfree ( setup );
   7.736 -    if ( purb != NULL )
   7.737 -        usb_free_urb(purb);
   7.738 -    make_response(up, req->id, req->operation, -EINVAL, 0, 0);
   7.739 -    return;
   7.740 -    
   7.741 - no_mem:
   7.742 -    if ( setup != NULL )
   7.743 -        kfree(setup);
   7.744 -    make_response(up, req->id, req->operation, -ENOMEM, 0, 0);
   7.745 -    return;
   7.746 -} 
   7.747 -
   7.748 -
   7.749 -
   7.750 -/******************************************************************
   7.751 - * MISCELLANEOUS SETUP / TEARDOWN / DEBUGGING
   7.752 - */
   7.753 -
   7.754 -
   7.755 -static void make_response(usbif_priv_t *up, unsigned long id,
   7.756 -                          unsigned short op, int st, int inband,
   7.757 -			  unsigned long length)
   7.758 -{
   7.759 -    usbif_response_t *resp;
   7.760 -    unsigned long     flags;
   7.761 -
   7.762 -#if 0
   7.763 -    printk("usbback: Sending response:\n");
   7.764 -    printk("         id = 0x%x\n", id);
   7.765 -    printk("         op = %d\n", op);
   7.766 -    printk("         status = %d\n", st);
   7.767 -    printk("         data = %d\n", inband);
   7.768 -    printk("         length = %d\n", length);
   7.769 -#endif
   7.770 -
   7.771 -    /* Place on the response ring for the relevant domain. */ 
   7.772 -    spin_lock_irqsave(&up->usb_ring_lock, flags);
   7.773 -    resp = &up->usb_ring_base->
   7.774 -        ring[MASK_USBIF_IDX(up->usb_resp_prod)].resp;
   7.775 -    resp->id        = id;
   7.776 -    resp->operation = op;
   7.777 -    resp->status    = st;
   7.778 -    resp->data      = inband;
   7.779 -    resp->length = length;
   7.780 -    wmb(); /* Ensure other side can see the response fields. */
   7.781 -    up->usb_ring_base->resp_prod = ++up->usb_resp_prod;
   7.782 -    spin_unlock_irqrestore(&up->usb_ring_lock, flags);
   7.783 -
   7.784 -    /* Kick the relevant domain. */
   7.785 -    notify_via_evtchn(up->evtchn);
   7.786 -}
   7.787 -
   7.788 -/**
   7.789 - * usbif_claim_port - claim devices on a port on behalf of guest
   7.790 - *
   7.791 - * Once completed, this will ensure that any device attached to that
   7.792 - * port is claimed by this driver for use by the guest.
   7.793 - */
   7.794 -int usbif_claim_port(usbif_be_claim_port_t *msg)
   7.795 -{
   7.796 -    owned_port_t *o_p;
   7.797 -    
   7.798 -    /* Sanity... */
   7.799 -    if ( usbif_find_port(msg->path) != NULL )
   7.800 -    {
   7.801 -        printk("usbback: Attempted to claim USB port "
   7.802 -               "we already own!\n");
   7.803 -        return -EINVAL;
   7.804 -    }
   7.805 -
   7.806 -    spin_lock_irq(&owned_ports_lock);
   7.807 -    
   7.808 -    /* No need for a slab cache - this should be infrequent. */
   7.809 -    o_p = kmalloc(sizeof(owned_port_t), GFP_KERNEL);
   7.810 -
   7.811 -    o_p->enabled = 0;
   7.812 -    o_p->usbif_priv = usbif_find(msg->domid);
   7.813 -    o_p->guest_port = msg->usbif_port;
   7.814 -    o_p->dev_present = 0;
   7.815 -    o_p->guest_address = 0; /* Default address. */
   7.816 -
   7.817 -    strcpy(o_p->path, msg->path);
   7.818 -
   7.819 -    list_add(&o_p->list, &owned_ports);
   7.820 -
   7.821 -    printk("usbback: Claimed USB port (%s) for %d.%d\n", o_p->path,
   7.822 -	   msg->domid, msg->usbif_port);
   7.823 -
   7.824 -    spin_unlock_irq(&owned_ports_lock);
   7.825 -
   7.826 -    /* Force a reprobe for unclaimed devices. */
   7.827 -    usb_scan_devices();
   7.828 -
   7.829 -    return 0;
   7.830 -}
   7.831 -
   7.832 -owned_port_t *find_port_for_request(usbif_priv_t *up, usbif_request_t *req)
   7.833 -{
   7.834 -    unsigned long flags;
   7.835 -    struct list_head *port;
   7.836 -
   7.837 -    /* I'm assuming this is not called from IRQ context - correct?  I think
   7.838 -     * it's probably only called in response to control messages or plug events
   7.839 -     * in the USB hub kernel thread, so should be OK. */
   7.840 -    spin_lock_irqsave(&owned_ports_lock, flags);
   7.841 -    list_for_each(port, &owned_ports)
   7.842 -    {
   7.843 -        owned_port_t *p = list_entry(port, owned_port_t, list);
   7.844 -        if(p->usbif_priv == up && p->guest_address == req->devnum && p->enabled )
   7.845 -	  {
   7.846 -#if 0
   7.847 -              printk("Found port for devnum %d\n", req->devnum);
   7.848 -
   7.849 -              dump_port(p);
   7.850 -#endif
   7.851 -              return p;
   7.852 -	  }
   7.853 -    }
   7.854 -    spin_unlock_irqrestore(&owned_ports_lock, flags);
   7.855 -
   7.856 -    return NULL;    
   7.857 -}
   7.858 -
   7.859 -owned_port_t *usbif_find_port(char *path)
   7.860 -{
   7.861 -    struct list_head *port;
   7.862 -    unsigned long flags;
   7.863 -
   7.864 -    spin_lock_irqsave(&owned_ports_lock, flags);
   7.865 -    list_for_each(port, &owned_ports)
   7.866 -    {
   7.867 -        owned_port_t *p = list_entry(port, owned_port_t, list);
   7.868 -        if(!strcmp(path, p->path))
   7.869 -        {
   7.870 -            spin_unlock_irqrestore(&owned_ports_lock, flags);
   7.871 -            return p;
   7.872 -        }
   7.873 -    }
   7.874 -    spin_unlock_irqrestore(&owned_ports_lock, flags);
   7.875 -
   7.876 -    return NULL;
   7.877 -}
   7.878 -
   7.879 -
   7.880 -static void *probe(struct usb_device *dev, unsigned iface,
   7.881 -	    const struct usb_device_id *id)
   7.882 -{
   7.883 -    owned_port_t *p;
   7.884 -
   7.885 -    /* We don't care what the device is - if we own the port, we want it.  We
   7.886 -     * don't deal with device-specifics in this driver, so we don't care what
   7.887 -     * the device actually is ;-) */
   7.888 -    if ( ( p = usbif_find_port(dev->devpath) ) != NULL )
   7.889 -    {
   7.890 -        printk("usbback: claimed device attached to owned port\n");
   7.891 -
   7.892 -        p->dev_present = 1;
   7.893 -        p->dev = dev;
   7.894 -        set_bit(iface, &p->ifaces);
   7.895 -        
   7.896 -        return p->usbif_priv;
   7.897 -    }
   7.898 -    else
   7.899 -        printk("usbback: hotplug for non-owned port (%s), ignoring\n", dev->devpath);
   7.900 -   
   7.901 -
   7.902 -    return NULL;
   7.903 -}
   7.904 -
   7.905 -static void disconnect(struct usb_device *dev, void *usbif)
   7.906 -{
   7.907 -    /* Note the device is removed so we can tell the guest when it probes. */
   7.908 -    owned_port_t *port = usbif_find_port(dev->devpath);
   7.909 -    port->dev_present = 0;
   7.910 -    port->dev = NULL;
   7.911 -    port->ifaces = 0;
   7.912 -}
   7.913 -
   7.914 -
   7.915 -struct usb_driver driver =
   7.916 -{
   7.917 -    .owner      = THIS_MODULE,
   7.918 -    .name       = "Xen USB Backend",
   7.919 -    .probe      = probe,
   7.920 -    .disconnect = disconnect,
   7.921 -    .id_table   = NULL,
   7.922 -};
   7.923 -
   7.924 -/* __usbif_release_port - internal mechanics for releasing a port */
   7.925 -void __usbif_release_port(owned_port_t *p)
   7.926 -{
   7.927 -    int i;
   7.928 -
   7.929 -    for ( i = 0; p->ifaces != 0; i++)
   7.930 -        if ( p->ifaces & 1 << i )
   7.931 -        {
   7.932 -            usb_driver_release_interface(&driver, usb_ifnum_to_if(p->dev, i));
   7.933 -            clear_bit(i, &p->ifaces);
   7.934 -        }
   7.935 -    list_del(&p->list);
   7.936 -
   7.937 -    /* Reset the real device.  We don't simulate disconnect / probe for other
   7.938 -     * drivers in this kernel because we assume the device is completely under
   7.939 -     * the control of ourselves (i.e. the guest!).  This should ensure that the
   7.940 -     * device is in a sane state for the next customer ;-) */
   7.941 -/*     if ( p->dev != NULL) */
   7.942 -/*         usb_reset_device(p->dev); */
   7.943 -
   7.944 -    kfree(p);
   7.945 -}
   7.946 -
   7.947 -
   7.948 -/**
   7.949 - * usbif_release_port - stop claiming devices on a port on behalf of guest
   7.950 - */
   7.951 -void usbif_release_port(usbif_be_release_port_t *msg)
   7.952 -{
   7.953 -    owned_port_t *p;
   7.954 -
   7.955 -    spin_lock_irq(&owned_ports_lock);
   7.956 -    p = usbif_find_port(msg->path);
   7.957 -    __usbif_release_port(p);
   7.958 -    spin_unlock_irq(&owned_ports_lock);
   7.959 -}
   7.960 -
   7.961 -void usbif_release_ports(usbif_priv_t *up)
   7.962 -{
   7.963 -    struct list_head *port, *tmp;
   7.964 -    unsigned long flags;
   7.965 -    
   7.966 -    spin_lock_irqsave(&owned_ports_lock, flags);
   7.967 -    list_for_each_safe(port, tmp, &owned_ports)
   7.968 -    {
   7.969 -        owned_port_t *p = list_entry(port, owned_port_t, list);
   7.970 -        if ( p->usbif_priv == up )
   7.971 -            __usbif_release_port(p);
   7.972 -    }
   7.973 -    spin_unlock_irqrestore(&owned_ports_lock, flags);
   7.974 -}
   7.975 -
   7.976 -static int __init usbif_init(void)
   7.977 -{
   7.978 -    int i;
   7.979 -
   7.980 -    if ( !(xen_start_info.flags & SIF_INITDOMAIN) &&
   7.981 -         !(xen_start_info.flags & SIF_USB_BE_DOMAIN) )
   7.982 -        return 0;
   7.983 -    
   7.984 -    INIT_LIST_HEAD(&owned_ports);
   7.985 -
   7.986 -    usb_register(&driver);
   7.987 -
   7.988 -    usbif_interface_init();
   7.989 -
   7.990 -    if ( (mmap_vstart = allocate_empty_lowmem_region(MMAP_PAGES)) == 0 )
   7.991 -        BUG();
   7.992 -
   7.993 -    pending_cons = 0;
   7.994 -    pending_prod = MAX_PENDING_REQS;
   7.995 -    memset(pending_reqs, 0, sizeof(pending_reqs));
   7.996 -    for ( i = 0; i < MAX_PENDING_REQS; i++ )
   7.997 -        pending_ring[i] = i;
   7.998 -
   7.999 -    spin_lock_init(&usbio_schedule_list_lock);
  7.1000 -    INIT_LIST_HEAD(&usbio_schedule_list);
  7.1001 -
  7.1002 -    if ( kernel_thread(usbio_schedule, 0, CLONE_FS | CLONE_FILES) < 0 )
  7.1003 -        BUG();
  7.1004 -    
  7.1005 -    usbif_ctrlif_init();
  7.1006 -
  7.1007 -    spin_lock_init(&owned_ports_lock);
  7.1008 -
  7.1009 -    printk("Xen USB Backend Initialised");
  7.1010 -
  7.1011 -    return 0;
  7.1012 -}
  7.1013 -
  7.1014 -__initcall(usbif_init);
     8.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile	Sat Jan 22 15:16:02 2005 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,3 +0,0 @@
     8.4 -O_TARGET := drv.o
     8.5 -obj-y := main.o
     8.6 -include $(TOPDIR)/Rules.make
     9.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/main.c	Sat Jan 22 15:16:02 2005 +0000
     9.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.3 @@ -1,1720 +0,0 @@
     9.4 -/*
     9.5 - * Xen Virtual USB Frontend Driver 
     9.6 - *
     9.7 - * This file contains the first version of the Xen virtual USB hub
     9.8 - * that I've managed not to delete by mistake (3rd time lucky!).
     9.9 - *
    9.10 - * Based on Linux's uhci.c, original copyright notices are displayed
    9.11 - * below.  Portions also (c) 2004 Intel Research Cambridge
    9.12 - * and (c) 2004 Mark Williamson
    9.13 - *
    9.14 - * Contact <mark.williamson@cl.cam.ac.uk> or
    9.15 - * <xen-devel@lists.sourceforge.net> regarding this code.
    9.16 - *
    9.17 - * Still to be (maybe) implemented:
    9.18 - * - multiple port
    9.19 - * - multiple interfaces
    9.20 - * - migration / backend restart support?
    9.21 - * - unloading support
    9.22 - *
    9.23 - * Differences to a normal host controller:
    9.24 - * - the backend does most of the mucky stuff so we don't have to do various
    9.25 - *   things that are necessary for a normal host controller (e.g. FSBR).
    9.26 - * - we don't have any hardware, so status registers are simulated in software.
    9.27 - */
    9.28 -
    9.29 -/*
    9.30 - * Universal Host Controller Interface driver for USB.
    9.31 - *
    9.32 - * Maintainer: Johannes Erdfelt <johannes@erdfelt.com>
    9.33 - *
    9.34 - * (C) Copyright 1999 Linus Torvalds
    9.35 - * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
    9.36 - * (C) Copyright 1999 Randy Dunlap
    9.37 - * (C) Copyright 1999 Georg Acher, acher@in.tum.de
    9.38 - * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
    9.39 - * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
    9.40 - * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
    9.41 - * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
    9.42 - *               support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
    9.43 - * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
    9.44 - *
    9.45 - * Intel documents this fairly well, and as far as I know there
    9.46 - * are no royalties or anything like that, but even so there are
    9.47 - * people who decided that they want to do the same thing in a
    9.48 - * completely different way.
    9.49 - *
    9.50 - * WARNING! The USB documentation is downright evil. Most of it
    9.51 - * is just crap, written by a committee. You're better off ignoring
    9.52 - * most of it, the important stuff is:
    9.53 - *  - the low-level protocol (fairly simple but lots of small details)
    9.54 - *  - working around the horridness of the rest
    9.55 - */
    9.56 -
    9.57 -#include <linux/config.h>
    9.58 -#include <linux/module.h>
    9.59 -#include <linux/kernel.h>
    9.60 -#include <linux/init.h>
    9.61 -#include <linux/delay.h>
    9.62 -#include <linux/ioport.h>
    9.63 -#include <linux/sched.h>
    9.64 -#include <linux/slab.h>
    9.65 -#include <linux/smp_lock.h>
    9.66 -#include <linux/errno.h>
    9.67 -#include <linux/unistd.h>
    9.68 -#include <linux/interrupt.h>
    9.69 -#include <linux/spinlock.h>
    9.70 -#ifdef CONFIG_USB_DEBUG
    9.71 -#define DEBUG
    9.72 -#else
    9.73 -#undef DEBUG
    9.74 -#endif
    9.75 -#include <linux/usb.h>
    9.76 -
    9.77 -#include <asm/uaccess.h>
    9.78 -#include <asm/irq.h>
    9.79 -#include <asm/system.h>
    9.80 -
    9.81 -#include "xhci.h"
    9.82 -
    9.83 -#include <linux/pm.h>
    9.84 -
    9.85 -#include "../../../../../drivers/usb/hcd.h"
    9.86 -
    9.87 -#include "../usbif.h"
    9.88 -#include <asm/ctrl_if.h>
    9.89 -#include <asm/xen-public/io/domain_controller.h>
    9.90 -
    9.91 -/*
    9.92 - * Version Information
    9.93 - */
    9.94 -#define DRIVER_VERSION "v1.0"
    9.95 -#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, Mark Williamson"
    9.96 -#define DRIVER_DESC "Xen Virtual USB Host Controller Interface driver"
    9.97 -
    9.98 -/*
    9.99 - * debug = 0, no debugging messages
   9.100 - * debug = 1, dump failed URB's except for stalls
   9.101 - * debug = 2, dump all failed URB's (including stalls)
   9.102 - */
   9.103 -#ifdef DEBUG
   9.104 -static int debug = 1;
   9.105 -#else
   9.106 -static int debug = 0;
   9.107 -#endif
   9.108 -MODULE_PARM(debug, "i");
   9.109 -MODULE_PARM_DESC(debug, "Debug level");
   9.110 -static char *errbuf;
   9.111 -#define ERRBUF_LEN    (PAGE_SIZE * 8)
   9.112 -
   9.113 -static kmem_cache_t *xhci_up_cachep;	/* urb_priv */
   9.114 -
   9.115 -static int rh_submit_urb(struct urb *urb);
   9.116 -static int rh_unlink_urb(struct urb *urb);
   9.117 -//static int xhci_get_current_frame_number(struct usb_device *dev);
   9.118 -static int xhci_unlink_urb(struct urb *urb);
   9.119 -static void xhci_unlink_generic(struct urb *urb);
   9.120 -static void xhci_call_completion(struct urb *urb);
   9.121 -static void xhci_drain_ring(void);
   9.122 -
   9.123 -#define MAX_URB_LOOP	2048		/* Maximum number of linked URB's */
   9.124 -
   9.125 -struct xhci *xhci;
   9.126 -
   9.127 -enum { USBIF_STATE_CONNECTED = 2,
   9.128 -       USBIF_STATE_DISCONNECTED = 1,
   9.129 -       USBIF_STATE_CLOSED =0
   9.130 -};
   9.131 -
   9.132 -static int awaiting_reset = 0;
   9.133 -
   9.134 -/**
   9.135 - * xhci_construct_isoc - add isochronous information to a request
   9.136 - */
   9.137 -int xhci_construct_isoc(usbif_request_t *req, struct urb *urb)
   9.138 -{
   9.139 -        usbif_iso_t *schedule;
   9.140 -        int i;
   9.141 -        struct urb_priv *urb_priv = urb->hcpriv;
   9.142 -        
   9.143 -        req->num_iso = urb->number_of_packets;
   9.144 -        schedule = (usbif_iso_t *)__get_free_page(GFP_KERNEL);
   9.145 -
   9.146 -        if ( schedule == NULL )
   9.147 -            return -ENOMEM;
   9.148 -
   9.149 -        for ( i = 0; i < req->num_iso; i++ )
   9.150 -        {
   9.151 -                schedule[i].buffer_offset = urb->iso_frame_desc[i].offset;
   9.152 -                schedule[i].length = urb->iso_frame_desc[i].length;
   9.153 -        }
   9.154 -
   9.155 -        urb_priv->schedule = schedule;
   9.156 -	req->iso_schedule = virt_to_machine(schedule);
   9.157 -
   9.158 -        return 0;
   9.159 -}
   9.160 -
   9.161 -#define USBIF_RING_FULL ((xhci->usbif->req_prod - xhci->usb_resp_cons) == USBIF_RING_SIZE)
   9.162 -
   9.163 -static void dump_urb(struct urb *urb)
   9.164 -{
   9.165 -        printk("dumping urb @ %p\n", urb);
   9.166 -        
   9.167 -        printk("hcpriv = %p\n", urb->hcpriv);
   9.168 -        printk("next = %p\n", urb->next);
   9.169 -        printk("dev = %p\n", urb->dev);
   9.170 -        printk("pipe = 0x%lx\n", urb->pipe);
   9.171 -        printk("status = %d\n", urb->status);
   9.172 -        printk("transfer_flags = 0x%lx\n", urb->transfer_flags);
   9.173 -        printk("transfer_buffer = %p\n", urb->transfer_buffer);
   9.174 -        printk("transfer_buffer_length = %d\n", urb->transfer_buffer_length);
   9.175 -        printk("actual_length = %d\n", urb->actual_length);
   9.176 -        printk("bandwidth = %d\n", urb->bandwidth);
   9.177 -        printk("setup_packet = %p\n", urb->setup_packet);
   9.178 -	if ( urb->setup_packet != NULL )
   9.179 -	          printk("setup = { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
   9.180 -               urb->setup_packet[0], urb->setup_packet[1], urb->setup_packet[2], urb->setup_packet[3],
   9.181 -               urb->setup_packet[4], urb->setup_packet[5], urb->setup_packet[6], urb->setup_packet[7]);
   9.182 -        printk("complete = %p\n", urb->complete);
   9.183 -        printk("interval = %d\n", urb->interval);
   9.184 -        
   9.185 -}
   9.186 -
   9.187 -
   9.188 -static int
   9.189 -xhci_queue_req(struct urb *urb)
   9.190 -{
   9.191 -        usbif_request_t *req;
   9.192 -        usbif_t *usbif = xhci->usbif;
   9.193 -
   9.194 -#if 0
   9.195 -        printk("usbif = %p, req_prod = %d (@ 0x%lx), resp_prod = %d, resp_cons = %d\n",
   9.196 -               usbif, usbif->req_prod, virt_to_machine(&usbif->req_prod),
   9.197 -               usbif->resp_prod, xhci->usb_resp_cons);
   9.198 -#endif
   9.199 -        
   9.200 -
   9.201 -/* 	printk("Usbif_priv %p, want IO at 0x%lx\n", urb->hcpriv, virt_to_machine(urb->transfer_buffer)); */
   9.202 -
   9.203 -        if ( USBIF_RING_FULL )
   9.204 -        {
   9.205 -                printk("xhci_queue_req(): USB ring full, not queuing request\n");
   9.206 -                return -ENOBUFS;
   9.207 -        }
   9.208 -
   9.209 -        /* Stick something in the shared communications ring. */
   9.210 -        req = &usbif->ring[MASK_USBIF_IDX(usbif->req_prod)].req;
   9.211 -
   9.212 -        req->operation       = USBIF_OP_IO;
   9.213 -        req->port            = 0; /* We don't care what the port is. */
   9.214 -        req->id              = (unsigned long) urb->hcpriv;
   9.215 -        req->transfer_buffer = virt_to_machine(urb->transfer_buffer);
   9.216 -	req->devnum          = usb_pipedevice(urb->pipe);
   9.217 -        req->direction       = usb_pipein(urb->pipe);
   9.218 -	req->speed           = usb_pipeslow(urb->pipe);
   9.219 -        req->pipe_type       = usb_pipetype(urb->pipe);
   9.220 -        req->length          = urb->transfer_buffer_length;
   9.221 -        req->transfer_flags  = urb->transfer_flags;
   9.222 -	req->endpoint        = usb_pipeendpoint(urb->pipe);
   9.223 -	req->speed           = usb_pipeslow(urb->pipe);
   9.224 -	req->timeout         = urb->timeout * (1000 / HZ);
   9.225 -
   9.226 -        if ( usb_pipetype(urb->pipe) == 0 ) /* ISO */
   9.227 -        {
   9.228 -            int ret = xhci_construct_isoc(req, urb);
   9.229 -            if ( ret != 0 )
   9.230 -                return ret;
   9.231 -        }
   9.232 -
   9.233 -	if(urb->setup_packet != NULL)
   9.234 -                memcpy(req->setup, urb->setup_packet, 8);
   9.235 -        else
   9.236 -                memset(req->setup, 0, 8);
   9.237 -        
   9.238 -        wmb();
   9.239 -
   9.240 -        usbif->req_prod++;
   9.241 -
   9.242 -	notify_via_evtchn(xhci->evtchn);
   9.243 -
   9.244 -	//	dump_urb(urb);
   9.245 -
   9.246 -        return -EINPROGRESS;
   9.247 -}
   9.248 -
   9.249 -static inline usbif_request_t *
   9.250 -xhci_queue_probe(usbif_vdev_t port)
   9.251 -{
   9.252 -        usbif_request_t *req;
   9.253 -        usbif_t *usbif = xhci->usbif;
   9.254 -
   9.255 -#if 0
   9.256 -	printk("queuing probe: req_prod = %d (@ 0x%lx), resp_prod = %d, resp_cons = %d\n",
   9.257 -	       usbif->req_prod, virt_to_machine(&usbif->req_prod),
   9.258 -	       usbif->resp_prod, xhci->usb_resp_cons);
   9.259 -#endif
   9.260 -        
   9.261 -        if ( USBIF_RING_FULL )
   9.262 -        {
   9.263 -                printk("xhci_queue_probe(): USB ring full, not queuing request\n");
   9.264 -                return NULL;
   9.265 -        }
   9.266 -
   9.267 -        /* Stick something in the shared communications ring. */
   9.268 -        req = &usbif->ring[MASK_USBIF_IDX(usbif->req_prod)].req;
   9.269 -
   9.270 -        req->operation       = USBIF_OP_PROBE;
   9.271 -        req->port            = port;
   9.272 -        req->id              = 0;
   9.273 -        req->transfer_buffer = 0;
   9.274 -	req->devnum          = 0;
   9.275 -        req->direction       = 0;
   9.276 -	req->speed           = 0;
   9.277 -        req->pipe_type       = 0;
   9.278 -        req->length          = 0;
   9.279 -        req->transfer_flags  = 0;
   9.280 -	req->endpoint        = 0;
   9.281 -	req->speed           = 0;
   9.282 -
   9.283 -        wmb();
   9.284 -
   9.285 -        usbif->req_prod++;
   9.286 -
   9.287 -	notify_via_evtchn(xhci->evtchn);
   9.288 -
   9.289 -        return req;
   9.290 -}
   9.291 -
   9.292 -static int
   9.293 -xhci_port_reset(usbif_vdev_t port)
   9.294 -{
   9.295 -        usbif_request_t *req;
   9.296 -        usbif_t *usbif = xhci->usbif;
   9.297 -
   9.298 -        /* We only reset one port at a time, so we only need one variable per
   9.299 -         * hub. */
   9.300 -        awaiting_reset = 1;
   9.301 -        
   9.302 -        /* Stick something in the shared communications ring. */
   9.303 -        req = &usbif->ring[MASK_USBIF_IDX(usbif->req_prod)].req;
   9.304 -
   9.305 -        req->operation       = USBIF_OP_RESET;
   9.306 -        req->port            = port;
   9.307 -        
   9.308 -        wmb();
   9.309 -
   9.310 -        usbif->req_prod++;
   9.311 -
   9.312 -	notify_via_evtchn(xhci->evtchn);
   9.313 -
   9.314 -        while ( awaiting_reset > 0 )
   9.315 -        {
   9.316 -                mdelay(1);
   9.317 -                xhci_drain_ring();
   9.318 -        }
   9.319 -
   9.320 -        return awaiting_reset;
   9.321 -}
   9.322 -
   9.323 -static void xhci_show_resp(usbif_response_t *r)
   9.324 -{
   9.325 -        printk("id=0x%lx, op=0x%x, data=0x%x, status=0x%x, length=0x%lx\n",
   9.326 -               r->id, r->operation, r->data, r->status, r->length);
   9.327 -}
   9.328 -
   9.329 -
   9.330 -/*
   9.331 - * Only the USB core should call xhci_alloc_dev and xhci_free_dev
   9.332 - */
   9.333 -static int xhci_alloc_dev(struct usb_device *dev)
   9.334 -{
   9.335 -	return 0;
   9.336 -}
   9.337 -
   9.338 -static int xhci_free_dev(struct usb_device *dev)
   9.339 -{
   9.340 -	return 0;
   9.341 -}
   9.342 -
   9.343 -static inline void xhci_add_complete(struct urb *urb)
   9.344 -{
   9.345 -	struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
   9.346 -	unsigned long flags;
   9.347 -
   9.348 -	spin_lock_irqsave(&xhci->complete_list_lock, flags);
   9.349 -	list_add_tail(&urbp->complete_list, &xhci->complete_list);
   9.350 -	spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
   9.351 -}
   9.352 -
   9.353 -/* When this returns, the owner of the URB may free its
   9.354 - * storage.
   9.355 - *
   9.356 - * We spin and wait for the URB to complete before returning.
   9.357 - */
   9.358 -static void xhci_delete_urb(struct urb *urb)
   9.359 -{
   9.360 -        struct urb_priv *urbp;
   9.361 -
   9.362 -	urbp = urb->hcpriv;
   9.363 -
   9.364 -        /* If there's no urb_priv structure for this URB then it can't have
   9.365 -         * been submitted at all. */
   9.366 -	if ( urbp == NULL )
   9.367 -		return;
   9.368 -
   9.369 -	/* For now we just spin until the URB completes.  It shouldn't take too
   9.370 -         * long and we don't expect to have to do this very often. */
   9.371 -	while ( urb->status == -EINPROGRESS )
   9.372 -        {
   9.373 -            xhci_drain_ring();
   9.374 -            mdelay(1);
   9.375 -        }
   9.376 -
   9.377 -	/* Now we know that further transfers to the buffer won't
   9.378 -	 * occur, so we can safely return. */
   9.379 -}
   9.380 -
   9.381 -static struct urb_priv *xhci_alloc_urb_priv(struct urb *urb)
   9.382 -{
   9.383 -	struct urb_priv *urbp;
   9.384 -
   9.385 -	urbp = kmem_cache_alloc(xhci_up_cachep, SLAB_ATOMIC);
   9.386 -	if (!urbp) {
   9.387 -		err("xhci_alloc_urb_priv: couldn't allocate memory for urb_priv\n");
   9.388 -		return NULL;
   9.389 -	}
   9.390 -
   9.391 -	memset((void *)urbp, 0, sizeof(*urbp));
   9.392 -
   9.393 -	urbp->inserttime = jiffies;
   9.394 -	urbp->urb = urb;
   9.395 -	urbp->dev = urb->dev;
   9.396 -	
   9.397 -	INIT_LIST_HEAD(&urbp->complete_list);
   9.398 -
   9.399 -	urb->hcpriv = urbp;
   9.400 -
   9.401 -	return urbp;
   9.402 -}
   9.403 -
   9.404 -/*
   9.405 - * MUST be called with urb->lock acquired
   9.406 - */
   9.407 -/* When is this called?  Do we need to stop the transfer (as we
   9.408 - * currently do)? */
   9.409 -static void xhci_destroy_urb_priv(struct urb *urb)
   9.410 -{
   9.411 -    struct urb_priv *urbp;
   9.412 -    
   9.413 -    urbp = (struct urb_priv *)urb->hcpriv;
   9.414 -    if (!urbp)
   9.415 -        return;
   9.416 -
   9.417 -    if (!list_empty(&urb->urb_list))
   9.418 -        warn("xhci_destroy_urb_priv: urb %p still on xhci->urb_list or xhci->remove_list", urb);
   9.419 -    
   9.420 -    if (!list_empty(&urbp->complete_list))
   9.421 -        warn("xhci_destroy_urb_priv: urb %p still on xhci->complete_list", urb);
   9.422 -    
   9.423 -    kmem_cache_free(xhci_up_cachep, urb->hcpriv);
   9.424 -
   9.425 -    urb->hcpriv = NULL;
   9.426 -}
   9.427 -
   9.428 -/**
   9.429 - * Try to find URBs in progress on the same pipe to the same device.
   9.430 - *
   9.431 - * MUST be called with xhci->urb_list_lock acquired
   9.432 - */
   9.433 -static struct urb *xhci_find_urb_ep(struct xhci *xhci, struct urb *urb)
   9.434 -{
   9.435 -	struct list_head *tmp, *head;
   9.436 -
   9.437 -	/* We don't match Isoc transfers since they are special */
   9.438 -	if (usb_pipeisoc(urb->pipe))
   9.439 -		return NULL;
   9.440 -
   9.441 -	head = &xhci->urb_list;
   9.442 -	tmp = head->next;
   9.443 -	while (tmp != head) {
   9.444 -		struct urb *u = list_entry(tmp, struct urb, urb_list);
   9.445 -
   9.446 -		tmp = tmp->next;
   9.447 -
   9.448 -		if (u->dev == urb->dev && u->pipe == urb->pipe &&
   9.449 -		    u->status == -EINPROGRESS)
   9.450 -			return u;
   9.451 -	}
   9.452 -
   9.453 -	return NULL;
   9.454 -}
   9.455 -
   9.456 -static int xhci_submit_urb(struct urb *urb)
   9.457 -{
   9.458 -	int ret = -EINVAL;
   9.459 -	unsigned long flags;
   9.460 -	struct urb *eurb;
   9.461 -	int bustime;
   9.462 -
   9.463 -#if 0
   9.464 -        printk("submitting urb @ %p for dev @ %p, devnum = %d path %s\n",
   9.465 -               urb, urb->dev, urb->dev->devnum, urb->dev->devpath);
   9.466 -#endif
   9.467 -
   9.468 -	if (!urb)
   9.469 -		return -EINVAL;
   9.470 -
   9.471 -	if (!urb->dev || !urb->dev->bus || !urb->dev->bus->hcpriv) {
   9.472 -		warn("xhci_submit_urb: urb %p belongs to disconnected device or bus?", urb);
   9.473 -		return -ENODEV;
   9.474 -	}
   9.475 -
   9.476 -        if ( urb->dev->devpath == NULL )
   9.477 -        {
   9.478 -                printk("BARF!\n");
   9.479 -                BUG();
   9.480 -        }
   9.481 -        
   9.482 -        
   9.483 -
   9.484 -	usb_inc_dev_use(urb->dev);
   9.485 -
   9.486 -	spin_lock_irqsave(&xhci->urb_list_lock, flags);
   9.487 -	spin_lock(&urb->lock);
   9.488 -
   9.489 -	if (urb->status == -EINPROGRESS || urb->status == -ECONNRESET ||
   9.490 -	    urb->status == -ECONNABORTED) {
   9.491 -		dbg("xhci_submit_urb: urb not available to submit (status = %d)", urb->status);
   9.492 -		/* Since we can have problems on the out path */
   9.493 -		spin_unlock(&urb->lock);
   9.494 -		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.495 -		usb_dec_dev_use(urb->dev);
   9.496 -
   9.497 -		return ret;
   9.498 -	}
   9.499 -
   9.500 -	INIT_LIST_HEAD(&urb->urb_list);
   9.501 -	if (!xhci_alloc_urb_priv(urb)) {
   9.502 -		ret = -ENOMEM;
   9.503 -
   9.504 -		goto out;
   9.505 -	}
   9.506 -
   9.507 -        ( (struct urb_priv *)urb->hcpriv )->in_progress = 1;
   9.508 -
   9.509 -	eurb = xhci_find_urb_ep(xhci, urb);
   9.510 -	if (eurb && !(urb->transfer_flags & USB_QUEUE_BULK)) {
   9.511 -		ret = -ENXIO;
   9.512 -
   9.513 -		goto out;
   9.514 -	}
   9.515 -
   9.516 -	/* Short circuit the virtual root hub */
   9.517 -	if (urb->dev == xhci->rh.dev) {
   9.518 -		ret = rh_submit_urb(urb);
   9.519 -
   9.520 -		goto out;
   9.521 -	}
   9.522 -
   9.523 -	if ( usb_pipedevice(urb->pipe) == 1 )
   9.524 -	  printk("dev = %p, dev->path = %s, rh.dev = %p, rh.dev.devnum = %d rh.dev->path = %s!\n",
   9.525 -		 urb->dev, urb->dev->devpath, xhci->rh.dev, xhci->rh.dev->devnum, xhci->rh.dev->devpath);
   9.526 -
   9.527 -	switch (usb_pipetype(urb->pipe)) {
   9.528 -	case PIPE_CONTROL:
   9.529 -		ret = xhci_queue_req(urb);
   9.530 -		break;
   9.531 -	case PIPE_INTERRUPT:
   9.532 -		if (urb->bandwidth == 0) {	/* not yet checked/allocated */
   9.533 -			bustime = usb_check_bandwidth(urb->dev, urb);
   9.534 -			if (bustime < 0)
   9.535 -				ret = bustime;
   9.536 -			else {
   9.537 -				ret = xhci_queue_req(urb);
   9.538 -				if (ret == -EINPROGRESS)
   9.539 -					usb_claim_bandwidth(urb->dev, urb, bustime, 0);
   9.540 -			}
   9.541 -		} else		/* bandwidth is already set */
   9.542 -			ret = xhci_queue_req(urb);
   9.543 -		break;
   9.544 -	case PIPE_BULK:
   9.545 -		ret = xhci_queue_req(urb);
   9.546 -		break;
   9.547 -	case PIPE_ISOCHRONOUS:
   9.548 -		if (urb->bandwidth == 0) {	/* not yet checked/allocated */
   9.549 -			if (urb->number_of_packets <= 0) {
   9.550 -				ret = -EINVAL;
   9.551 -				break;
   9.552 -			}
   9.553 -			bustime = usb_check_bandwidth(urb->dev, urb);
   9.554 -			if (bustime < 0) {
   9.555 -				ret = bustime;
   9.556 -				break;
   9.557 -			}
   9.558 -
   9.559 -			ret = xhci_queue_req(urb);
   9.560 -			if (ret == -EINPROGRESS)
   9.561 -				usb_claim_bandwidth(urb->dev, urb, bustime, 1);
   9.562 -		} else		/* bandwidth is already set */
   9.563 -			ret = xhci_queue_req(urb);
   9.564 -		break;
   9.565 -	}
   9.566 -
   9.567 -out:
   9.568 -	urb->status = ret;
   9.569 -
   9.570 -	if (ret == -EINPROGRESS) {
   9.571 -		/* We use _tail to make find_urb_ep more efficient */
   9.572 -		list_add_tail(&urb->urb_list, &xhci->urb_list);
   9.573 -
   9.574 -		spin_unlock(&urb->lock);
   9.575 -		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.576 -
   9.577 -		return 0;
   9.578 -	}
   9.579 -
   9.580 -	xhci_unlink_generic(urb);
   9.581 -
   9.582 -	spin_unlock(&urb->lock);
   9.583 -	spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.584 -
   9.585 -	/* Only call completion if it was successful */
   9.586 -	if (!ret)
   9.587 -		xhci_call_completion(urb);
   9.588 -
   9.589 -	return ret;
   9.590 -}
   9.591 -
   9.592 -/*
   9.593 - * Return the result of a transfer
   9.594 - *
   9.595 - * MUST be called with urb_list_lock acquired
   9.596 - */
   9.597 -static void xhci_transfer_result(struct xhci *xhci, struct urb *urb)
   9.598 -{
   9.599 -	int ret = 0;
   9.600 -	unsigned long flags;
   9.601 -	struct urb_priv *urbp;
   9.602 -
   9.603 -	/* The root hub is special */
   9.604 -	if (urb->dev == xhci->rh.dev)
   9.605 -		return;
   9.606 -
   9.607 -	spin_lock_irqsave(&urb->lock, flags);
   9.608 -
   9.609 -	urbp = (struct urb_priv *)urb->hcpriv;
   9.610 -
   9.611 -        if ( ( (struct urb_priv *)urb->hcpriv )->in_progress )
   9.612 -                ret = -EINPROGRESS;
   9.613 -
   9.614 -        if (urb->actual_length < urb->transfer_buffer_length) {
   9.615 -                if (urb->transfer_flags & USB_DISABLE_SPD) {
   9.616 -                        ret = -EREMOTEIO;
   9.617 -                }
   9.618 -        }
   9.619 -
   9.620 -	if (urb->status == -EPIPE)
   9.621 -        {
   9.622 -                ret = urb->status;
   9.623 -		/* endpoint has stalled - mark it halted */
   9.624 -		usb_endpoint_halt(urb->dev, usb_pipeendpoint(urb->pipe),
   9.625 -                                  usb_pipeout(urb->pipe));
   9.626 -        }
   9.627 -
   9.628 -	if ((debug == 1 && ret != 0 && ret != -EPIPE) ||
   9.629 -            (ret != 0 && debug > 1)) {
   9.630 -		/* Some debugging code */
   9.631 -		dbg("xhci_result_interrupt/bulk() failed with status %x",
   9.632 -			status);
   9.633 -	}
   9.634 -
   9.635 -	if (ret == -EINPROGRESS)
   9.636 -		goto out;
   9.637 -
   9.638 -	switch (usb_pipetype(urb->pipe)) {
   9.639 -	case PIPE_CONTROL:
   9.640 -	case PIPE_BULK:
   9.641 -	case PIPE_ISOCHRONOUS:
   9.642 -		/* Release bandwidth for Interrupt or Isoc. transfers */
   9.643 -		/* Spinlock needed ? */
   9.644 -		if (urb->bandwidth)
   9.645 -			usb_release_bandwidth(urb->dev, urb, 1);
   9.646 -		xhci_unlink_generic(urb);
   9.647 -		break;
   9.648 -	case PIPE_INTERRUPT:
   9.649 -		/* Interrupts are an exception */
   9.650 -		if (urb->interval)
   9.651 -			goto out_complete;
   9.652 -
   9.653 -		/* Release bandwidth for Interrupt or Isoc. transfers */
   9.654 -		/* Spinlock needed ? */
   9.655 -		if (urb->bandwidth)
   9.656 -			usb_release_bandwidth(urb->dev, urb, 0);
   9.657 -		xhci_unlink_generic(urb);
   9.658 -		break;
   9.659 -	default:
   9.660 -		info("xhci_transfer_result: unknown pipe type %d for urb %p\n",
   9.661 -			usb_pipetype(urb->pipe), urb);
   9.662 -	}
   9.663 -
   9.664 -	/* Remove it from xhci->urb_list */
   9.665 -	list_del_init(&urb->urb_list);
   9.666 -
   9.667 -out_complete:
   9.668 -	xhci_add_complete(urb);
   9.669 -
   9.670 -out:
   9.671 -	spin_unlock_irqrestore(&urb->lock, flags);
   9.672 -}
   9.673 -
   9.674 -/*
   9.675 - * MUST be called with urb->lock acquired
   9.676 - */
   9.677 -static void xhci_unlink_generic(struct urb *urb)
   9.678 -{
   9.679 -	struct urb_priv *urbp = urb->hcpriv;
   9.680 -
   9.681 -	/* We can get called when urbp allocation fails, so check */
   9.682 -	if (!urbp)
   9.683 -		return;
   9.684 -
   9.685 -        /* ??? This function is now so minimal it doesn't do much.  Do we really
   9.686 -         * need it? */
   9.687 -
   9.688 -	xhci_delete_urb(urb);
   9.689 -}
   9.690 -
   9.691 -static int xhci_unlink_urb(struct urb *urb)
   9.692 -{
   9.693 -	unsigned long flags;
   9.694 -	struct urb_priv *urbp = urb->hcpriv;
   9.695 -
   9.696 -	if (!urb)
   9.697 -		return -EINVAL;
   9.698 -
   9.699 -	if (!urb->dev || !urb->dev->bus || !urb->dev->bus->hcpriv)
   9.700 -		return -ENODEV;
   9.701 -
   9.702 -	spin_lock_irqsave(&xhci->urb_list_lock, flags);
   9.703 -	spin_lock(&urb->lock);
   9.704 -
   9.705 -	/* Release bandwidth for Interrupt or Isoc. transfers */
   9.706 -	/* Spinlock needed ? */
   9.707 -	if (urb->bandwidth) {
   9.708 -		switch (usb_pipetype(urb->pipe)) {
   9.709 -		case PIPE_INTERRUPT:
   9.710 -			usb_release_bandwidth(urb->dev, urb, 0);
   9.711 -			break;
   9.712 -		case PIPE_ISOCHRONOUS:
   9.713 -			usb_release_bandwidth(urb->dev, urb, 1);
   9.714 -			break;
   9.715 -		default:
   9.716 -			break;
   9.717 -		}
   9.718 -	}
   9.719 -
   9.720 -	if (urb->status != -EINPROGRESS) {
   9.721 -		spin_unlock(&urb->lock);
   9.722 -		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.723 -		return 0;
   9.724 -	}
   9.725 -
   9.726 -	list_del_init(&urb->urb_list);
   9.727 -
   9.728 -	xhci_unlink_generic(urb);
   9.729 -
   9.730 -	/* Short circuit the virtual root hub */
   9.731 -	if (urb->dev == xhci->rh.dev) {
   9.732 -		rh_unlink_urb(urb);
   9.733 -
   9.734 -		spin_unlock(&urb->lock);
   9.735 -		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.736 -
   9.737 -		xhci_call_completion(urb);
   9.738 -	} else {
   9.739 -		if (urb->transfer_flags & USB_ASYNC_UNLINK) {
   9.740 -			urbp->status = urb->status = -ECONNABORTED;
   9.741 -
   9.742 -			spin_lock(&xhci->urb_remove_list_lock);
   9.743 -
   9.744 -			list_add(&urb->urb_list, &xhci->urb_remove_list);
   9.745 -
   9.746 -			spin_unlock(&xhci->urb_remove_list_lock);
   9.747 -
   9.748 -			spin_unlock(&urb->lock);
   9.749 -			spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.750 -
   9.751 -		} else {
   9.752 -			urb->status = -ENOENT;
   9.753 -
   9.754 -			spin_unlock(&urb->lock);
   9.755 -			spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.756 -
   9.757 -			if (in_interrupt()) {	/* wait at least 1 frame */
   9.758 -				static int errorcount = 10;
   9.759 -
   9.760 -				if (errorcount--)
   9.761 -					dbg("xhci_unlink_urb called from interrupt for urb %p", urb);
   9.762 -				udelay(1000);
   9.763 -			} else
   9.764 -				schedule_timeout(1+1*HZ/1000); 
   9.765 -
   9.766 -			xhci_call_completion(urb);
   9.767 -		}
   9.768 -	}
   9.769 -
   9.770 -	return 0;
   9.771 -}
   9.772 -
   9.773 -
   9.774 -struct usb_operations xhci_device_operations = {
   9.775 -	.allocate = xhci_alloc_dev,
   9.776 -	.deallocate = xhci_free_dev,
   9.777 -        /* It doesn't look like any drivers actually care what the frame number
   9.778 -	 * is at the moment!  If necessary, we could approximate the current
   9.779 -	 * frame nubmer by passing it from the backend in response messages. */
   9.780 -	.get_frame_number = NULL,
   9.781 -	.submit_urb = xhci_submit_urb,
   9.782 -	.unlink_urb = xhci_unlink_urb
   9.783 -};
   9.784 -
   9.785 -/* Virtual Root Hub */
   9.786 -
   9.787 -static __u8 root_hub_dev_des[] =
   9.788 -{
   9.789 - 	0x12,			/*  __u8  bLength; */
   9.790 -	0x01,			/*  __u8  bDescriptorType; Device */
   9.791 -	0x00,			/*  __u16 bcdUSB; v1.0 */
   9.792 -	0x01,
   9.793 -	0x09,			/*  __u8  bDeviceClass; HUB_CLASSCODE */
   9.794 -	0x00,			/*  __u8  bDeviceSubClass; */
   9.795 -	0x00,			/*  __u8  bDeviceProtocol; */
   9.796 -	0x08,			/*  __u8  bMaxPacketSize0; 8 Bytes */
   9.797 -	0x00,			/*  __u16 idVendor; */
   9.798 -	0x00,
   9.799 -	0x00,			/*  __u16 idProduct; */
   9.800 -	0x00,
   9.801 -	0x00,			/*  __u16 bcdDevice; */
   9.802 -	0x00,
   9.803 -	0x00,			/*  __u8  iManufacturer; */
   9.804 -	0x02,			/*  __u8  iProduct; */
   9.805 -	0x01,			/*  __u8  iSerialNumber; */
   9.806 -	0x01			/*  __u8  bNumConfigurations; */
   9.807 -};
   9.808 -
   9.809 -
   9.810 -/* Configuration descriptor */
   9.811 -static __u8 root_hub_config_des[] =
   9.812 -{
   9.813 -	0x09,			/*  __u8  bLength; */
   9.814 -	0x02,			/*  __u8  bDescriptorType; Configuration */
   9.815 -	0x19,			/*  __u16 wTotalLength; */
   9.816 -	0x00,
   9.817 -	0x01,			/*  __u8  bNumInterfaces; */
   9.818 -	0x01,			/*  __u8  bConfigurationValue; */
   9.819 -	0x00,			/*  __u8  iConfiguration; */
   9.820 -	0x40,			/*  __u8  bmAttributes;
   9.821 -					Bit 7: Bus-powered, 6: Self-powered,
   9.822 -					Bit 5 Remote-wakeup, 4..0: resvd */
   9.823 -	0x00,			/*  __u8  MaxPower; */
   9.824 -
   9.825 -	/* interface */
   9.826 -	0x09,			/*  __u8  if_bLength; */
   9.827 -	0x04,			/*  __u8  if_bDescriptorType; Interface */
   9.828 -	0x00,			/*  __u8  if_bInterfaceNumber; */
   9.829 -	0x00,			/*  __u8  if_bAlternateSetting; */
   9.830 -	0x01,			/*  __u8  if_bNumEndpoints; */
   9.831 -	0x09,			/*  __u8  if_bInterfaceClass; HUB_CLASSCODE */
   9.832 -	0x00,			/*  __u8  if_bInterfaceSubClass; */
   9.833 -	0x00,			/*  __u8  if_bInterfaceProtocol; */
   9.834 -	0x00,			/*  __u8  if_iInterface; */
   9.835 -
   9.836 -	/* endpoint */
   9.837 -	0x07,			/*  __u8  ep_bLength; */
   9.838 -	0x05,			/*  __u8  ep_bDescriptorType; Endpoint */
   9.839 -	0x81,			/*  __u8  ep_bEndpointAddress; IN Endpoint 1 */
   9.840 -	0x03,			/*  __u8  ep_bmAttributes; Interrupt */
   9.841 -	0x08,			/*  __u16 ep_wMaxPacketSize; 8 Bytes */
   9.842 -	0x00,
   9.843 -	0xff			/*  __u8  ep_bInterval; 255 ms */
   9.844 -};
   9.845 -
   9.846 -static __u8 root_hub_hub_des[] =
   9.847 -{
   9.848 -	0x09,			/*  __u8  bLength; */
   9.849 -	0x29,			/*  __u8  bDescriptorType; Hub-descriptor */
   9.850 -	0x02,			/*  __u8  bNbrPorts; */
   9.851 -	0x00,			/* __u16  wHubCharacteristics; */
   9.852 -	0x00,
   9.853 -	0x01,			/*  __u8  bPwrOn2pwrGood; 2ms */
   9.854 -	0x00,			/*  __u8  bHubContrCurrent; 0 mA */
   9.855 -	0x00,			/*  __u8  DeviceRemovable; *** 7 Ports max *** */
   9.856 -	0xff			/*  __u8  PortPwrCtrlMask; *** 7 ports max *** */
   9.857 -};
   9.858 -
   9.859 -/* prepare Interrupt pipe transaction data; HUB INTERRUPT ENDPOINT */
   9.860 -static int rh_send_irq(struct urb *urb)
   9.861 -{
   9.862 -	struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
   9.863 -        xhci_port_t *ports = xhci->rh.ports;
   9.864 -	unsigned long flags;
   9.865 -	int i, len = 1;
   9.866 -	__u16 data = 0;
   9.867 -
   9.868 -	spin_lock_irqsave(&urb->lock, flags);
   9.869 -	for (i = 0; i < xhci->rh.numports; i++) {
   9.870 -                /* MAW: No idea what the old code was doing here or why it worked.
   9.871 -		 * This implementation sets a bit if anything at all has changed on the 
   9.872 -		 * port, as per USB spec 11.12 */
   9.873 -		data |= (ports[i].cs_chg || ports[i].pe_chg )
   9.874 -                        ? (1 << (i + 1))
   9.875 -                        : 0;
   9.876 -
   9.877 -		len = (i + 1) / 8 + 1;
   9.878 -	}
   9.879 -
   9.880 -	*(__u16 *) urb->transfer_buffer = cpu_to_le16(data);
   9.881 -	urb->actual_length = len;
   9.882 -	urbp->status = 0;
   9.883 -
   9.884 -	spin_unlock_irqrestore(&urb->lock, flags);
   9.885 -
   9.886 -	if ((data > 0) && (xhci->rh.send != 0)) {
   9.887 -		dbg("root-hub INT complete: data: %x", data);
   9.888 -		xhci_call_completion(urb);
   9.889 -	}
   9.890 -
   9.891 -	return 0;
   9.892 -}
   9.893 -
   9.894 -/* Virtual Root Hub INTs are polled by this timer every "interval" ms */
   9.895 -static int rh_init_int_timer(struct urb *urb);
   9.896 -
   9.897 -static void rh_int_timer_do(unsigned long ptr)
   9.898 -{
   9.899 -	struct urb *urb = (struct urb *)ptr;
   9.900 -	struct list_head list, *tmp, *head;
   9.901 -	unsigned long flags;
   9.902 -	int i;
   9.903 -
   9.904 -	for ( i = 0; i < xhci->rh.numports; i++)
   9.905 -                xhci_queue_probe(i);
   9.906 -
   9.907 -	if (xhci->rh.send)
   9.908 -		rh_send_irq(urb);
   9.909 -
   9.910 -	INIT_LIST_HEAD(&list);
   9.911 -
   9.912 -	spin_lock_irqsave(&xhci->urb_list_lock, flags);
   9.913 -	head = &xhci->urb_list;
   9.914 -	tmp = head->next;
   9.915 -	while (tmp != head) {
   9.916 -		struct urb *u = list_entry(tmp, struct urb, urb_list);
   9.917 -		struct urb_priv *up = (struct urb_priv *)u->hcpriv;
   9.918 -
   9.919 -		tmp = tmp->next;
   9.920 -
   9.921 -		spin_lock(&u->lock);
   9.922 -
   9.923 -		/* Check if the URB timed out */
   9.924 -		if (u->timeout && time_after_eq(jiffies, up->inserttime + u->timeout)) {
   9.925 -			list_del(&u->urb_list);
   9.926 -			list_add_tail(&u->urb_list, &list);
   9.927 -		}
   9.928 -
   9.929 -		spin_unlock(&u->lock);
   9.930 -	}
   9.931 -	spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
   9.932 -
   9.933 -	head = &list;
   9.934 -	tmp = head->next;
   9.935 -	while (tmp != head) {
   9.936 -		struct urb *u = list_entry(tmp, struct urb, urb_list);
   9.937 -
   9.938 -		tmp = tmp->next;
   9.939 -
   9.940 -		u->transfer_flags |= USB_ASYNC_UNLINK | USB_TIMEOUT_KILLED;
   9.941 -		xhci_unlink_urb(u);
   9.942 -	}
   9.943 -
   9.944 -	rh_init_int_timer(urb);
   9.945 -}
   9.946 -
   9.947 -/* Root Hub INTs are polled by this timer */
   9.948 -static int rh_init_int_timer(struct urb *urb)
   9.949 -{
   9.950 -	xhci->rh.interval = urb->interval;
   9.951 -	init_timer(&xhci->rh.rh_int_timer);
   9.952 -	xhci->rh.rh_int_timer.function = rh_int_timer_do;
   9.953 -	xhci->rh.rh_int_timer.data = (unsigned long)urb;
   9.954 -	xhci->rh.rh_int_timer.expires = jiffies + (HZ * (urb->interval < 30 ? 30 : urb->interval)) / 1000;
   9.955 -	add_timer(&xhci->rh.rh_int_timer);
   9.956 -
   9.957 -	return 0;
   9.958 -}
   9.959 -
   9.960 -#define OK(x)			len = (x); break
   9.961 -
   9.962 -/* Root Hub Control Pipe */
   9.963 -static int rh_submit_urb(struct urb *urb)
   9.964 -{
   9.965 -	unsigned int pipe = urb->pipe;
   9.966 -	struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *)urb->setup_packet;
   9.967 -	void *data = urb->transfer_buffer;
   9.968 -	int leni = urb->transfer_buffer_length;
   9.969 -	int len = 0;
   9.970 -	xhci_port_t *status;
   9.971 -	int stat = 0;
   9.972 -	int i;
   9.973 -	int retstatus;
   9.974 -        unsigned long flags;
   9.975 -        
   9.976 -	__u16 cstatus;
   9.977 -	__u16 bmRType_bReq;
   9.978 -	__u16 wValue;
   9.979 -	__u16 wIndex;
   9.980 -	__u16 wLength;
   9.981 -
   9.982 -	if (usb_pipetype(pipe) == PIPE_INTERRUPT) {
   9.983 -		xhci->rh.urb = urb;
   9.984 -		xhci->rh.send = 1;
   9.985 -		xhci->rh.interval = urb->interval;
   9.986 -		rh_init_int_timer(urb);
   9.987 -
   9.988 -		return -EINPROGRESS;
   9.989 -	}
   9.990 -
   9.991 -	bmRType_bReq = cmd->bRequestType | cmd->bRequest << 8;
   9.992 -	wValue = le16_to_cpu(cmd->wValue);
   9.993 -	wIndex = le16_to_cpu(cmd->wIndex);
   9.994 -	wLength = le16_to_cpu(cmd->wLength);
   9.995 -
   9.996 -	for (i = 0; i < 8; i++)
   9.997 -		xhci->rh.c_p_r[i] = 0;
   9.998 -
   9.999 -        status = &xhci->rh.ports[wIndex - 1];
  9.1000 -
  9.1001 -        spin_lock_irqsave(&xhci->rh.port_state_lock, flags);
  9.1002 -
  9.1003 -	switch (bmRType_bReq) {
  9.1004 -		/* Request Destination:
  9.1005 -		   without flags: Device,
  9.1006 -		   RH_INTERFACE: interface,
  9.1007 -		   RH_ENDPOINT: endpoint,
  9.1008 -		   RH_CLASS means HUB here,
  9.1009 -		   RH_OTHER | RH_CLASS  almost ever means HUB_PORT here
  9.1010 -		*/
  9.1011 -
  9.1012 -	case RH_GET_STATUS:
  9.1013 -		*(__u16 *)data = cpu_to_le16(1);
  9.1014 -		OK(2);
  9.1015 -	case RH_GET_STATUS | RH_INTERFACE:
  9.1016 -		*(__u16 *)data = cpu_to_le16(0);
  9.1017 -		OK(2);
  9.1018 -	case RH_GET_STATUS | RH_ENDPOINT:
  9.1019 -		*(__u16 *)data = cpu_to_le16(0);
  9.1020 -		OK(2);
  9.1021 -	case RH_GET_STATUS | RH_CLASS:
  9.1022 -		*(__u32 *)data = cpu_to_le32(0);
  9.1023 -		OK(4);		/* hub power */
  9.1024 -	case RH_GET_STATUS | RH_OTHER | RH_CLASS:
  9.1025 -		cstatus = (status->cs_chg) |
  9.1026 -			(status->pe_chg << 1) |
  9.1027 -			(xhci->rh.c_p_r[wIndex - 1] << 4);
  9.1028 -		retstatus = (status->ccs) |
  9.1029 -			(status->pe << 1) |
  9.1030 -			(status->susp << 2) |
  9.1031 -			(status->pr << 8) |
  9.1032 -			(1 << 8) |      /* power on */
  9.1033 -			(status->lsda << 9);
  9.1034 -		*(__u16 *)data = cpu_to_le16(retstatus);
  9.1035 -		*(__u16 *)(data + 2) = cpu_to_le16(cstatus);
  9.1036 -		OK(4);
  9.1037 -	case RH_CLEAR_FEATURE | RH_ENDPOINT:
  9.1038 -		switch (wValue) {
  9.1039 -		case RH_ENDPOINT_STALL:
  9.1040 -			OK(0);
  9.1041 -		}
  9.1042 -		break;
  9.1043 -	case RH_CLEAR_FEATURE | RH_CLASS:
  9.1044 -		switch (wValue) {
  9.1045 -		case RH_C_HUB_OVER_CURRENT:
  9.1046 -			OK(0);	/* hub power over current */
  9.1047 -		}
  9.1048 -		break;
  9.1049 -	case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
  9.1050 -		switch (wValue) {
  9.1051 -		case RH_PORT_ENABLE:
  9.1052 -                        status->pe     = 0;
  9.1053 -			OK(0);
  9.1054 -		case RH_PORT_SUSPEND:
  9.1055 -                        status->susp   = 0;
  9.1056 -			OK(0);
  9.1057 -		case RH_PORT_POWER:
  9.1058 -			OK(0);	/* port power */
  9.1059 -		case RH_C_PORT_CONNECTION:
  9.1060 -                        status->cs_chg = 0;
  9.1061 -			OK(0);
  9.1062 -		case RH_C_PORT_ENABLE:
  9.1063 -                        status->pe_chg = 0;
  9.1064 -			OK(0);
  9.1065 -		case RH_C_PORT_SUSPEND:
  9.1066 -			/*** WR_RH_PORTSTAT(RH_PS_PSSC); */
  9.1067 -			OK(0);
  9.1068 -		case RH_C_PORT_OVER_CURRENT:
  9.1069 -			OK(0);	/* port power over current */
  9.1070 -		case RH_C_PORT_RESET:
  9.1071 -			xhci->rh.c_p_r[wIndex - 1] = 0;
  9.1072 -			OK(0);
  9.1073 -		}
  9.1074 -		break;
  9.1075 -	case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
  9.1076 -		switch (wValue) {
  9.1077 -		case RH_PORT_SUSPEND:
  9.1078 -                        status->susp = 1;	
  9.1079 -			OK(0);
  9.1080 -		case RH_PORT_RESET:
  9.1081 -                {
  9.1082 -                        int ret;
  9.1083 -                        xhci->rh.c_p_r[wIndex - 1] = 1;
  9.1084 -                        status->pr = 0;
  9.1085 -                        status->pe = 1;
  9.1086 -                        ret = xhci_port_reset(wIndex - 1);
  9.1087 -                        /* XXX MAW: should probably cancel queued transfers during reset... *\/ */
  9.1088 -                        if ( ret == 0 ) { OK(0); }
  9.1089 -                        else { return ret; }
  9.1090 -                }
  9.1091 -                break;
  9.1092 -		case RH_PORT_POWER:
  9.1093 -			OK(0); /* port power ** */
  9.1094 -		case RH_PORT_ENABLE:
  9.1095 -                        status->pe = 1;
  9.1096 -			OK(0);
  9.1097 -		}
  9.1098 -		break;
  9.1099 -	case RH_SET_ADDRESS:
  9.1100 -	  printk("setting root hub device to %d\n", wValue);
  9.1101 -		xhci->rh.devnum = wValue;
  9.1102 -		OK(0);
  9.1103 -	case RH_GET_DESCRIPTOR:
  9.1104 -		switch ((wValue & 0xff00) >> 8) {
  9.1105 -		case 0x01:	/* device descriptor */
  9.1106 -			len = min_t(unsigned int, leni,
  9.1107 -				  min_t(unsigned int,
  9.1108 -				      sizeof(root_hub_dev_des), wLength));
  9.1109 -			memcpy(data, root_hub_dev_des, len);
  9.1110 -			OK(len);
  9.1111 -		case 0x02:	/* configuration descriptor */
  9.1112 -			len = min_t(unsigned int, leni,
  9.1113 -				  min_t(unsigned int,
  9.1114 -				      sizeof(root_hub_config_des), wLength));
  9.1115 -			memcpy (data, root_hub_config_des, len);
  9.1116 -			OK(len);
  9.1117 -		case 0x03:	/* string descriptors */
  9.1118 -			len = usb_root_hub_string (wValue & 0xff,
  9.1119 -				0, "XHCI-alt",
  9.1120 -				data, wLength);
  9.1121 -			if (len > 0) {
  9.1122 -				OK(min_t(int, leni, len));
  9.1123 -			} else 
  9.1124 -				stat = -EPIPE;
  9.1125 -		}
  9.1126 -		break;
  9.1127 -	case RH_GET_DESCRIPTOR | RH_CLASS:
  9.1128 -		root_hub_hub_des[2] = xhci->rh.numports;
  9.1129 -		len = min_t(unsigned int, leni,
  9.1130 -			  min_t(unsigned int, sizeof(root_hub_hub_des), wLength));
  9.1131 -		memcpy(data, root_hub_hub_des, len);
  9.1132 -		OK(len);
  9.1133 -	case RH_GET_CONFIGURATION:
  9.1134 -		*(__u8 *)data = 0x01;
  9.1135 -		OK(1);
  9.1136 -	case RH_SET_CONFIGURATION:
  9.1137 -		OK(0);
  9.1138 -	case RH_GET_INTERFACE | RH_INTERFACE:
  9.1139 -		*(__u8 *)data = 0x00;
  9.1140 -		OK(1);
  9.1141 -	case RH_SET_INTERFACE | RH_INTERFACE:
  9.1142 -		OK(0);
  9.1143 -	default:
  9.1144 -		stat = -EPIPE;
  9.1145 -	}
  9.1146 -
  9.1147 -        spin_unlock_irqrestore(&xhci->rh.port_state_lock, flags);
  9.1148 -
  9.1149 -	urb->actual_length = len;
  9.1150 -
  9.1151 -	return stat;
  9.1152 -}
  9.1153 -
  9.1154 -/*
  9.1155 - * MUST be called with urb->lock acquired
  9.1156 - */
  9.1157 -static int rh_unlink_urb(struct urb *urb)
  9.1158 -{
  9.1159 -	if (xhci->rh.urb == urb) {
  9.1160 -		urb->status = -ENOENT;
  9.1161 -		xhci->rh.send = 0;
  9.1162 -		xhci->rh.urb = NULL;
  9.1163 -		del_timer(&xhci->rh.rh_int_timer);
  9.1164 -	}
  9.1165 -	return 0;
  9.1166 -}
  9.1167 -
  9.1168 -static void xhci_call_completion(struct urb *urb)
  9.1169 -{
  9.1170 -	struct urb_priv *urbp;
  9.1171 -	struct usb_device *dev = urb->dev;
  9.1172 -	int is_ring = 0, killed, resubmit_interrupt, status;
  9.1173 -	struct urb *nurb;
  9.1174 -	unsigned long flags;
  9.1175 -
  9.1176 -	spin_lock_irqsave(&urb->lock, flags);
  9.1177 -
  9.1178 -	urbp = (struct urb_priv *)urb->hcpriv;
  9.1179 -	if (!urbp || !urb->dev) {
  9.1180 -		spin_unlock_irqrestore(&urb->lock, flags);
  9.1181 -		return;
  9.1182 -	}
  9.1183 -
  9.1184 -	killed = (urb->status == -ENOENT || urb->status == -ECONNABORTED ||
  9.1185 -			urb->status == -ECONNRESET);
  9.1186 -	resubmit_interrupt = (usb_pipetype(urb->pipe) == PIPE_INTERRUPT &&
  9.1187 -			urb->interval);
  9.1188 -
  9.1189 -	nurb = urb->next;
  9.1190 -	if (nurb && !killed) {
  9.1191 -		int count = 0;
  9.1192 -
  9.1193 -		while (nurb && nurb != urb && count < MAX_URB_LOOP) {
  9.1194 -			if (nurb->status == -ENOENT ||
  9.1195 -			    nurb->status == -ECONNABORTED ||
  9.1196 -			    nurb->status == -ECONNRESET) {
  9.1197 -				killed = 1;
  9.1198 -				break;
  9.1199 -			}
  9.1200 -
  9.1201 -			nurb = nurb->next;
  9.1202 -			count++;
  9.1203 -		}
  9.1204 -
  9.1205 -		if (count == MAX_URB_LOOP)
  9.1206 -			err("xhci_call_completion: too many linked URB's, loop? (first loop)");
  9.1207 -
  9.1208 -		/* Check to see if chain is a ring */
  9.1209 -		is_ring = (nurb == urb);
  9.1210 -	}
  9.1211 -
  9.1212 -	status = urbp->status;
  9.1213 -	if (!resubmit_interrupt || killed)
  9.1214 -		/* We don't need urb_priv anymore */
  9.1215 -		xhci_destroy_urb_priv(urb);
  9.1216 -
  9.1217 -	if (!killed)
  9.1218 -		urb->status = status;
  9.1219 -
  9.1220 -	spin_unlock_irqrestore(&urb->lock, flags);
  9.1221 -
  9.1222 -	if (urb->complete)
  9.1223 -		urb->complete(urb);
  9.1224 -
  9.1225 -	if (resubmit_interrupt)
  9.1226 -		/* Recheck the status. The completion handler may have */
  9.1227 -		/*  unlinked the resubmitting interrupt URB */
  9.1228 -		killed = (urb->status == -ENOENT ||
  9.1229 -			  urb->status == -ECONNABORTED ||
  9.1230 -			  urb->status == -ECONNRESET);
  9.1231 -
  9.1232 -	if (resubmit_interrupt && !killed) {
  9.1233 -                if ( urb->dev != xhci->rh.dev )
  9.1234 -                        xhci_queue_req(urb); /* XXX What if this fails? */
  9.1235 -                /* Don't need to resubmit URBs for the virtual root dev. */
  9.1236 -	} else {
  9.1237 -		if (is_ring && !killed) {
  9.1238 -			urb->dev = dev;
  9.1239 -			xhci_submit_urb(urb);
  9.1240 -		} else {
  9.1241 -			/* We decrement the usage count after we're done */
  9.1242 -			/*  with everything */
  9.1243 -			usb_dec_dev_use(dev);
  9.1244 -		}
  9.1245 -	}
  9.1246 -}
  9.1247 -
  9.1248 -static void xhci_finish_completion(void)
  9.1249 -{
  9.1250 -	struct list_head *tmp, *head;
  9.1251 -	unsigned long flags;
  9.1252 -
  9.1253 -	spin_lock_irqsave(&xhci->complete_list_lock, flags);
  9.1254 -	head = &xhci->complete_list;
  9.1255 -	tmp = head->next;
  9.1256 -	while (tmp != head) {
  9.1257 -		struct urb_priv *urbp = list_entry(tmp, struct urb_priv, complete_list);
  9.1258 -		struct urb *urb = urbp->urb;
  9.1259 -
  9.1260 -		list_del_init(&urbp->complete_list);
  9.1261 -		spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
  9.1262 -
  9.1263 -		xhci_call_completion(urb);
  9.1264 -
  9.1265 -		spin_lock_irqsave(&xhci->complete_list_lock, flags);
  9.1266 -		head = &xhci->complete_list;
  9.1267 -		tmp = head->next;
  9.1268 -	}
  9.1269 -	spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
  9.1270 -}
  9.1271 -
  9.1272 -void receive_usb_reset(usbif_response_t *resp)
  9.1273 -{
  9.1274 -    awaiting_reset = resp->status;
  9.1275 -    rmb();
  9.1276 -    
  9.1277 -}
  9.1278 -
  9.1279 -void receive_usb_probe(usbif_response_t *resp)
  9.1280 -{
  9.1281 -    spin_lock(&xhci->rh.port_state_lock);
  9.1282 -
  9.1283 -    if ( resp->status > 0 )
  9.1284 -    {
  9.1285 -        if ( resp->status == 1 )
  9.1286 -        {
  9.1287 -/* 	  printk("hey hey, there's a device on port %d\n", resp->data); */
  9.1288 -
  9.1289 -            /* If theres a device there and there wasn't one before there must
  9.1290 -             * have been a connection status change. */
  9.1291 -            if( xhci->rh.ports[resp->data].cs == 0 )
  9.1292 -	    {
  9.1293 -                xhci->rh.ports[resp->data].cs = 1;
  9.1294 -                xhci->rh.ports[resp->data].ccs = 1;
  9.1295 -                xhci->rh.ports[resp->data].cs_chg = 1;
  9.1296 -/* 		printk("Look at device on port %d that wasn't there before\n", resp->data); */
  9.1297 -	    }
  9.1298 -        }
  9.1299 -        else
  9.1300 -            printk("receive_usb_probe(): unexpected status %d for port %d\n",
  9.1301 -                   resp->status, resp->data);
  9.1302 -    }
  9.1303 -    else if ( resp->status < 0)
  9.1304 -        printk("receive_usb_probe(): got error status %d\n", resp->status);
  9.1305 -
  9.1306 -    spin_unlock(&xhci->rh.port_state_lock);
  9.1307 -}
  9.1308 -
  9.1309 -void receive_usb_io(usbif_response_t *resp)
  9.1310 -{
  9.1311 -        struct urb_priv *urbp = (struct urb_priv *)resp->id;
  9.1312 -        struct urb *urb = urbp->urb;
  9.1313 -
  9.1314 -        urb->actual_length = resp->length;
  9.1315 -	urb->status = resp->status;
  9.1316 -	urbp->status = resp->status;
  9.1317 -        urbp->in_progress = 0;
  9.1318 -
  9.1319 -        if( usb_pipetype(urb->pipe) == 0 ) /* ISO */
  9.1320 -        {
  9.1321 -                int i;
  9.1322 -              
  9.1323 -                /* Copy ISO schedule results back in. */
  9.1324 -
  9.1325 -                for ( i = 0; i < urb->number_of_packets; i++ )
  9.1326 -                {
  9.1327 -                        urb->iso_frame_desc[i].status
  9.1328 -			  = urbp->schedule[i].status;
  9.1329 -                        urb->iso_frame_desc[i].actual_length
  9.1330 -                                = urbp->schedule[i].length;
  9.1331 -                }
  9.1332 -                free_page((unsigned long)urbp->schedule);
  9.1333 -        }
  9.1334 -}
  9.1335 -
  9.1336 -static void xhci_drain_ring(void)
  9.1337 -{
  9.1338 -	struct list_head *tmp, *head;
  9.1339 -	usbif_t *usb_ring = xhci->usbif;
  9.1340 -	usbif_response_t *resp;
  9.1341 -        USBIF_RING_IDX i, rp;
  9.1342 -
  9.1343 -        /* Walk the ring here to get responses, updating URBs to show what
  9.1344 -         * completed. */
  9.1345 -        
  9.1346 -        rp = usb_ring->resp_prod;
  9.1347 -        rmb(); /* Ensure we see queued requests up to 'rp'. */
  9.1348 -
  9.1349 -        /* Take items off the comms ring, taking care not to overflow. */
  9.1350 -        for ( i = xhci->usb_resp_cons; 
  9.1351 -              (i != rp) && ((i-usb_ring->req_prod) != USBIF_RING_SIZE);
  9.1352 -              i++ )
  9.1353 -        {
  9.1354 -            resp = &usb_ring->ring[MASK_USBIF_IDX(i)].resp;
  9.1355 -            
  9.1356 -            /* May need to deal with batching and with putting a ceiling on
  9.1357 -               the number dispatched for performance and anti-dos reasons */
  9.1358 -
  9.1359 -#if 0
  9.1360 -            printk("usbfront: Processing response:\n");
  9.1361 -            printk("          id = 0x%x\n", resp->id);
  9.1362 -            printk("          op = %d\n", resp->operation);
  9.1363 -            printk("          status = %d\n", resp->status);
  9.1364 -            printk("          length = %d\n", resp->length);
  9.1365 -#endif            
  9.1366 -
  9.1367 -            switch ( resp->operation )
  9.1368 -            {
  9.1369 -            case USBIF_OP_PROBE:
  9.1370 -                receive_usb_probe(resp);
  9.1371 -                break;
  9.1372 -                
  9.1373 -            case USBIF_OP_IO:
  9.1374 -                receive_usb_io(resp);
  9.1375 -                break;
  9.1376 -
  9.1377 -            case USBIF_OP_RESET:
  9.1378 -                receive_usb_reset(resp);
  9.1379 -                break;
  9.1380 -
  9.1381 -            default:
  9.1382 -                printk("error: unknown USB io operation response [%d]\n",
  9.1383 -                       usb_ring->ring[i].req.operation);
  9.1384 -                break;
  9.1385 -            }
  9.1386 -        }
  9.1387 -
  9.1388 -        xhci->usb_resp_cons = i;
  9.1389 -
  9.1390 -	/* Walk the list of pending URB's to see which ones completed and do
  9.1391 -         * callbacks, etc. */
  9.1392 -	spin_lock(&xhci->urb_list_lock);
  9.1393 -	head = &xhci->urb_list;
  9.1394 -	tmp = head->next;
  9.1395 -	while (tmp != head) {
  9.1396 -                
  9.1397 -		struct urb *urb = list_entry(tmp, struct urb, urb_list);
  9.1398 -
  9.1399 -		tmp = tmp->next;
  9.1400 -
  9.1401 -		/* Checks the status and does all of the magic necessary */
  9.1402 -		xhci_transfer_result(xhci, urb);
  9.1403 -	}
  9.1404 -	spin_unlock(&xhci->urb_list_lock);
  9.1405 -
  9.1406 -	xhci_finish_completion();
  9.1407 -}
  9.1408 -
  9.1409 -
  9.1410 -static void xhci_interrupt(int irq, void *__xhci, struct pt_regs *regs)
  9.1411 -{
  9.1412 -        xhci_drain_ring();
  9.1413 -}
  9.1414 -
  9.1415 -static void free_xhci(struct xhci *xhci)
  9.1416 -{
  9.1417 -	kfree(xhci);
  9.1418 -}
  9.1419 -
  9.1420 -/* /\* */
  9.1421 -/*  * De-allocate all resources.. */
  9.1422 -/*  *\/ */
  9.1423 -/* static void release_xhci(struct xhci *xhci) */
  9.1424 -/* { */
  9.1425 -/* 	if (xhci->irq >= 0) { */
  9.1426 -/* 		free_irq(xhci->irq, xhci); */
  9.1427 -/* 		xhci->irq = -1; */
  9.1428 -/* 	} */
  9.1429 -
  9.1430 -/*         /\* Get the ring back from the backend domain.  Then free it.  Hmmmm. */
  9.1431 -/*          * Lets ignore this for now - not particularly useful. *\/ */
  9.1432 -
  9.1433 -/* 	free_xhci(xhci); */
  9.1434 -/* } */
  9.1435 -
  9.1436 -/**
  9.1437 - * Initialise a new virtual root hub for a new USB device channel.
  9.1438 - */
  9.1439 -static int alloc_xhci(void)
  9.1440 -{
  9.1441 -	int retval;
  9.1442 -	struct usb_bus *bus;
  9.1443 -
  9.1444 -	retval = -EBUSY;
  9.1445 -
  9.1446 -	xhci = kmalloc(sizeof(*xhci), GFP_KERNEL);
  9.1447 -	if (!xhci) {
  9.1448 -		err("couldn't allocate xhci structure");
  9.1449 -		retval = -ENOMEM;
  9.1450 -		goto err_alloc_xhci;
  9.1451 -	}
  9.1452 -
  9.1453 -	/* Reset here so we don't get any interrupts from an old setup */
  9.1454 -	/*  or broken setup */
  9.1455 -	//	reset_hc(xhci);
  9.1456 -
  9.1457 -
  9.1458 -	xhci->state = USBIF_STATE_CLOSED;
  9.1459 -	xhci->is_suspended = 0;
  9.1460 -
  9.1461 -	spin_lock_init(&xhci->urb_remove_list_lock);
  9.1462 -	INIT_LIST_HEAD(&xhci->urb_remove_list);
  9.1463 -
  9.1464 -	spin_lock_init(&xhci->urb_list_lock);
  9.1465 -	INIT_LIST_HEAD(&xhci->urb_list);
  9.1466 -
  9.1467 -	spin_lock_init(&xhci->complete_list_lock);
  9.1468 -	INIT_LIST_HEAD(&xhci->complete_list);
  9.1469 -
  9.1470 -	spin_lock_init(&xhci->frame_list_lock);
  9.1471 -
  9.1472 -	/* We need exactly one page (per XHCI specs), how convenient */
  9.1473 -	/* We assume that one page is atleast 4k (1024 frames * 4 bytes) */
  9.1474 -#if PAGE_SIZE < (4 * 1024)
  9.1475 -#error PAGE_SIZE is not atleast 4k
  9.1476 -#endif
  9.1477 -	bus = usb_alloc_bus(&xhci_device_operations);
  9.1478 -	if (!bus) {
  9.1479 -		err("unable to allocate bus");
  9.1480 -		goto err_alloc_bus;
  9.1481 -	}
  9.1482 -
  9.1483 -	xhci->bus = bus;
  9.1484 -	bus->bus_name = "XHCI";
  9.1485 -	bus->hcpriv = xhci;
  9.1486 -
  9.1487 -	usb_register_bus(xhci->bus);
  9.1488 -
  9.1489 -	/* Initialize the root hub */
  9.1490 -
  9.1491 -	xhci->rh.numports = 0;
  9.1492 -
  9.1493 -	xhci->bus->root_hub = xhci->rh.dev = usb_alloc_dev(NULL, xhci->bus);
  9.1494 -	if (!xhci->rh.dev) {
  9.1495 -		err("unable to allocate root hub");
  9.1496 -		goto err_alloc_root_hub;
  9.1497 -	}
  9.1498 -
  9.1499 -	xhci->state = 0;
  9.1500 -
  9.1501 -	return 0;
  9.1502 -
  9.1503 -/*
  9.1504 - * error exits:
  9.1505 - */
  9.1506 -err_start_root_hub:
  9.1507 -	free_irq(xhci->irq, xhci);
  9.1508 -	xhci->irq = -1;
  9.1509 -
  9.1510 -err_alloc_root_hub:
  9.1511 -	usb_free_bus(xhci->bus);
  9.1512 -	xhci->bus = NULL;
  9.1513 -
  9.1514 -err_alloc_bus:
  9.1515 -	free_xhci(xhci);
  9.1516 -
  9.1517 -err_alloc_xhci:
  9.1518 -	return retval;
  9.1519 -}
  9.1520 -
  9.1521 -static void usbif_status_change(usbif_fe_interface_status_changed_t *status)
  9.1522 -{
  9.1523 -    ctrl_msg_t                   cmsg;
  9.1524 -    usbif_fe_interface_connect_t up;
  9.1525 -    long rc;
  9.1526 -    usbif_t *usbif;
  9.1527 -
  9.1528 -    switch ( status->status )
  9.1529 -    {
  9.1530 -    case USBIF_INTERFACE_STATUS_DESTROYED:
  9.1531 -        printk(KERN_WARNING "Unexpected usbif-DESTROYED message in state %d\n",
  9.1532 -               xhci->state);
  9.1533 -        break;
  9.1534 -
  9.1535 -    case USBIF_INTERFACE_STATUS_DISCONNECTED:
  9.1536 -        if ( xhci->state != USBIF_STATE_CLOSED )
  9.1537 -        {
  9.1538 -            printk(KERN_WARNING "Unexpected usbif-DISCONNECTED message"
  9.1539 -                   " in state %d\n", xhci->state);
  9.1540 -            break;
  9.1541 -            /* Not bothering to do recovery here for now.  Keep things
  9.1542 -             * simple. */
  9.1543 -        }
  9.1544 -
  9.1545 -        /* Move from CLOSED to DISCONNECTED state. */
  9.1546 -        xhci->usbif = usbif = (usbif_t *)__get_free_page(GFP_KERNEL);
  9.1547 -        usbif->req_prod = usbif->resp_prod = 0;
  9.1548 -        xhci->state  = USBIF_STATE_DISCONNECTED;
  9.1549 -
  9.1550 -        /* Construct an interface-CONNECT message for the domain controller. */
  9.1551 -        cmsg.type      = CMSG_USBIF_FE;
  9.1552 -        cmsg.subtype   = CMSG_USBIF_FE_INTERFACE_CONNECT;
  9.1553 -        cmsg.length    = sizeof(usbif_fe_interface_connect_t);
  9.1554 -        up.shmem_frame = virt_to_machine(usbif) >> PAGE_SHIFT;
  9.1555 -        memcpy(cmsg.msg, &up, sizeof(up));
  9.1556 -        
  9.1557 -        /* Tell the controller to bring up the interface. */
  9.1558 -        ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
  9.1559 -        break;
  9.1560 -
  9.1561 -    case USBIF_INTERFACE_STATUS_CONNECTED:
  9.1562 -        if ( xhci->state == USBIF_STATE_CLOSED )
  9.1563 -        {
  9.1564 -            printk(KERN_WARNING "Unexpected usbif-CONNECTED message"
  9.1565 -                   " in state %d\n", xhci->state);
  9.1566 -            break;
  9.1567 -        }
  9.1568 -
  9.1569 -        xhci->evtchn = status->evtchn;
  9.1570 -        xhci->irq = bind_evtchn_to_irq(xhci->evtchn);
  9.1571 -	xhci->bandwidth = status->bandwidth;
  9.1572 -	xhci->rh.numports = status->num_ports;
  9.1573 -
  9.1574 -        xhci->rh.ports = kmalloc (sizeof(xhci_port_t) * xhci->rh.numports, GFP_KERNEL);
  9.1575 -        memset(xhci->rh.ports, 0, sizeof(xhci_port_t) * xhci->rh.numports);
  9.1576 -
  9.1577 -        printk("rh.dev @ %p\n", xhci->rh.dev);
  9.1578 -
  9.1579 -	usb_connect(xhci->rh.dev);
  9.1580 -
  9.1581 -	if (usb_new_device(xhci->rh.dev) != 0) {
  9.1582 -		err("unable to start root hub");
  9.1583 -	}
  9.1584 -
  9.1585 -	/* Allocate the appropriate USB bandwidth here...  Need to
  9.1586 -	* somehow know what the total available is thought to be so we
  9.1587 -	* can calculate the reservation correctly. */
  9.1588 - 	usb_claim_bandwidth(xhci->rh.dev, xhci->rh.urb,
  9.1589 - 			    1000 - xhci->bandwidth, 0);
  9.1590 -
  9.1591 -        if ( (rc = request_irq(xhci->irq, xhci_interrupt, 
  9.1592 -                               SA_SAMPLE_RANDOM, "usbif", xhci)) )
  9.1593 -                printk(KERN_ALERT"usbfront request_irq failed (%ld)\n",rc);
  9.1594 -
  9.1595 -	printk(KERN_INFO __FILE__ ": USB XHCI: SHM at %p (0x%lx), EVTCHN %d IRQ %d\n",
  9.1596 -               xhci->usbif, virt_to_machine(xhci->usbif), xhci->evtchn, xhci->irq);
  9.1597 -
  9.1598 -        xhci->state = USBIF_STATE_CONNECTED;
  9.1599 -        
  9.1600 -        break;
  9.1601 -
  9.1602 -    default:
  9.1603 -        printk(KERN_WARNING "Status change to unknown value %d\n", 
  9.1604 -               status->status);
  9.1605 -        break;
  9.1606 -    }
  9.1607 -}
  9.1608 -
  9.1609 -
  9.1610 -static void usbif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
  9.1611 -{
  9.1612 -    switch ( msg->subtype )
  9.1613 -    {
  9.1614 -    case CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED:
  9.1615 -        if ( msg->length != sizeof(usbif_fe_interface_status_changed_t) )
  9.1616 -            goto parse_error;
  9.1617 -        usbif_status_change((usbif_fe_interface_status_changed_t *)
  9.1618 -                            &msg->msg[0]);
  9.1619 -        break;        
  9.1620 -
  9.1621 -        /* New interface...? */
  9.1622 -    default:
  9.1623 -        goto parse_error;
  9.1624 -    }
  9.1625 -
  9.1626 -    ctrl_if_send_response(msg);
  9.1627 -    return;
  9.1628 -
  9.1629 - parse_error:
  9.1630 -    msg->length = 0;
  9.1631 -    ctrl_if_send_response(msg);
  9.1632 -}
  9.1633 -
  9.1634 -
  9.1635 -static int __init xhci_hcd_init(void)
  9.1636 -{
  9.1637 -	int retval = -ENOMEM, i;
  9.1638 -        usbif_fe_interface_status_changed_t st;
  9.1639 -        control_msg_t cmsg;
  9.1640 -
  9.1641 -	if ( (xen_start_info.flags & SIF_INITDOMAIN)
  9.1642 -	     || (xen_start_info.flags & SIF_USB_BE_DOMAIN) )
  9.1643 -                return 0;
  9.1644 -
  9.1645 -	info(DRIVER_DESC " " DRIVER_VERSION);
  9.1646 -
  9.1647 -	if (debug) {
  9.1648 -		errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL);
  9.1649 -		if (!errbuf)
  9.1650 -			goto errbuf_failed;
  9.1651 -	}
  9.1652 -
  9.1653 -	xhci_up_cachep = kmem_cache_create("xhci_urb_priv",
  9.1654 -		sizeof(struct urb_priv), 0, 0, NULL, NULL);
  9.1655 -	if (!xhci_up_cachep)
  9.1656 -		goto up_failed;
  9.1657 -
  9.1658 -        /* Lazily avoid unloading issues for now. ;-)*/
  9.1659 -	MOD_INC_USE_COUNT;
  9.1660 -
  9.1661 -        /* Let the domain controller know we're here.  For now we wait until
  9.1662 -         * connection, as for the block and net drivers.  This is only strictly
  9.1663 -         * necessary if we're going to boot off a USB device. */
  9.1664 -        printk(KERN_INFO "Initialising Xen virtual USB hub\n");
  9.1665 -    
  9.1666 -        (void)ctrl_if_register_receiver(CMSG_USBIF_FE, usbif_ctrlif_rx,
  9.1667 -                                        CALLBACK_IN_BLOCKING_CONTEXT);
  9.1668 -        
  9.1669 -	alloc_xhci();
  9.1670 -
  9.1671 -        /* Send a driver-UP notification to the domain controller. */
  9.1672 -        cmsg.type      = CMSG_USBIF_FE;
  9.1673 -        cmsg.subtype   = CMSG_USBIF_FE_DRIVER_STATUS_CHANGED;
  9.1674 -        cmsg.length    = sizeof(usbif_fe_driver_status_changed_t);
  9.1675 -        st.status      = USBIF_DRIVER_STATUS_UP;
  9.1676 -        memcpy(cmsg.msg, &st, sizeof(st));
  9.1677 -        ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
  9.1678 -        
  9.1679 -        /*
  9.1680 -         * We should read 'nr_interfaces' from response message and wait
  9.1681 -         * for notifications before proceeding. For now we assume that we
  9.1682 -         * will be notified of exactly one interface.
  9.1683 -         */
  9.1684 -        for ( i=0; (xhci->state != USBIF_STATE_CONNECTED) && (i < 10*HZ); i++ )
  9.1685 -        {
  9.1686 -            set_current_state(TASK_INTERRUPTIBLE);
  9.1687 -            schedule_timeout(1);
  9.1688 -        }
  9.1689 -        
  9.1690 -        if (xhci->state != USBIF_STATE_CONNECTED)
  9.1691 -            printk(KERN_INFO "Timeout connecting USB frontend driver!\n");
  9.1692 -	
  9.1693 -	return 0;
  9.1694 -
  9.1695 -up_failed:
  9.1696 -
  9.1697 -	if (errbuf)
  9.1698 -		kfree(errbuf);
  9.1699 -
  9.1700 -errbuf_failed:
  9.1701 -
  9.1702 -	return retval;
  9.1703 -}
  9.1704 -
  9.1705 -static void __exit xhci_hcd_cleanup(void) 
  9.1706 -{
  9.1707 -	if (kmem_cache_destroy(xhci_up_cachep))
  9.1708 -		printk(KERN_INFO "xhci: not all urb_priv's were freed\n");
  9.1709 -
  9.1710 -//        release_xhci(); do some calls here
  9.1711 -
  9.1712 -
  9.1713 -	if (errbuf)
  9.1714 -		kfree(errbuf);
  9.1715 -}
  9.1716 -
  9.1717 -module_init(xhci_hcd_init);
  9.1718 -module_exit(xhci_hcd_cleanup);
  9.1719 -
  9.1720 -MODULE_AUTHOR(DRIVER_AUTHOR);
  9.1721 -MODULE_DESCRIPTION(DRIVER_DESC);
  9.1722 -MODULE_LICENSE("GPL");
  9.1723 -
    10.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/frontend/xhci.h	Sat Jan 22 15:16:02 2005 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,210 +0,0 @@
    10.4 -#ifndef __LINUX_XHCI_H
    10.5 -#define __LINUX_XHCI_H
    10.6 -
    10.7 -#include <linux/list.h>
    10.8 -#include <linux/usb.h>
    10.9 -#include "../usbif.h"
   10.10 -#include <linux/spinlock.h>
   10.11 -
   10.12 -#define XHCI_NUMFRAMES		1024	/* in the frame list [array] */
   10.13 -#define XHCI_MAX_SOF_NUMBER	2047	/* in an SOF packet */
   10.14 -#define CAN_SCHEDULE_FRAMES	1000	/* how far future frames can be scheduled */
   10.15 -
   10.16 -/* In the absence of actual hardware state, we maintain the current known state
   10.17 - * of the virtual hub ports in this data structure.
   10.18 - */
   10.19 -typedef struct
   10.20 -{
   10.21 -        unsigned int cs     :1;     /* Connection status.  do we really need this /and/ ccs? */
   10.22 -        unsigned int cs_chg :1; /* Connection status change.  */
   10.23 -        unsigned int pe     :1;     /* Port enable.               */
   10.24 -        unsigned int pe_chg :1; /* Port enable change.        */
   10.25 -        unsigned int ccs    :1;    /* Current connect status.    */
   10.26 -        unsigned int susp   :1;   /* Suspended.                 */
   10.27 -        unsigned int lsda   :1;   /* Low speed device attached. */
   10.28 -        unsigned int pr     :1;     /* Port reset.                */
   10.29 -        
   10.30 -    /* Device info? */
   10.31 -} xhci_port_t;
   10.32 -
   10.33 -struct xhci_frame_list {
   10.34 -	__u32 frame[XHCI_NUMFRAMES];
   10.35 -
   10.36 -	void *frame_cpu[XHCI_NUMFRAMES];
   10.37 -};
   10.38 -
   10.39 -struct urb_priv;
   10.40 -
   10.41 -#define xhci_status_bits(ctrl_sts)	(ctrl_sts & 0xFE0000)
   10.42 -#define xhci_actual_length(ctrl_sts)	((ctrl_sts + 1) & TD_CTRL_ACTLEN_MASK) /* 1-based */
   10.43 -
   10.44 -#define xhci_maxlen(token)	((token) >> 21)
   10.45 -#define xhci_expected_length(info) (((info >> 21) + 1) & TD_TOKEN_EXPLEN_MASK) /* 1-based */
   10.46 -#define xhci_toggle(token)	(((token) >> TD_TOKEN_TOGGLE_SHIFT) & 1)
   10.47 -#define xhci_endpoint(token)	(((token) >> 15) & 0xf)
   10.48 -#define xhci_devaddr(token)	(((token) >> 8) & 0x7f)
   10.49 -#define xhci_devep(token)	(((token) >> 8) & 0x7ff)
   10.50 -#define xhci_packetid(token)	((token) & TD_TOKEN_PID_MASK)
   10.51 -#define xhci_packetout(token)	(xhci_packetid(token) != USB_PID_IN)
   10.52 -#define xhci_packetin(token)	(xhci_packetid(token) == USB_PID_IN)
   10.53 -
   10.54 -struct virt_root_hub {
   10.55 -	struct usb_device *dev;
   10.56 -	int devnum;		/* Address of Root Hub endpoint */
   10.57 -	struct urb *urb;
   10.58 -	void *int_addr;
   10.59 -	int send;
   10.60 -	int interval;
   10.61 -	int numports;
   10.62 -	int c_p_r[8];
   10.63 -	struct timer_list rh_int_timer;
   10.64 -        spinlock_t port_state_lock;
   10.65 -        xhci_port_t *ports;       /*  */
   10.66 -};
   10.67 -
   10.68 -/*
   10.69 - * This describes the full xhci information.
   10.70 - *
   10.71 - * Note how the "proper" USB information is just
   10.72 - * a subset of what the full implementation needs.
   10.73 - */
   10.74 -struct xhci {
   10.75 -
   10.76 -#ifdef CONFIG_PROC_FS
   10.77 -	/* procfs */
   10.78 -	int num;
   10.79 -	struct proc_dir_entry *proc_entry;
   10.80 -#endif
   10.81 -
   10.82 -        int evtchn;                        /* Interdom channel to backend */
   10.83 -        int irq;                           /* Bound to evtchn */
   10.84 -        int state;                         /* State of this USB interface */
   10.85 -        unsigned long bandwidth;
   10.86 -        int handle;
   10.87 -
   10.88 -	struct usb_bus *bus;
   10.89 -
   10.90 -	spinlock_t frame_list_lock;
   10.91 -	struct xhci_frame_list *fl;		/* P: xhci->frame_list_lock */
   10.92 -	int is_suspended;
   10.93 -
   10.94 -	/* Main list of URB's currently controlled by this HC */
   10.95 -	spinlock_t urb_list_lock;
   10.96 -	struct list_head urb_list;		/* P: xhci->urb_list_lock */
   10.97 -
   10.98 -	/* List of asynchronously unlinked URB's */
   10.99 -	spinlock_t urb_remove_list_lock;
  10.100 -	struct list_head urb_remove_list;	/* P: xhci->urb_remove_list_lock */
  10.101 -
  10.102 -	/* List of URB's awaiting completion callback */
  10.103 -	spinlock_t complete_list_lock;
  10.104 -	struct list_head complete_list;		/* P: xhci->complete_list_lock */
  10.105 -
  10.106 -	struct virt_root_hub rh;	/* private data of the virtual root hub */
  10.107 -
  10.108 -        spinlock_t response_lock;
  10.109 -
  10.110 -        usbif_t *usbif;
  10.111 -        int usb_resp_cons;
  10.112 -};
  10.113 -
  10.114 -struct urb_priv {
  10.115 -	struct urb *urb;
  10.116 -        usbif_iso_t *schedule;
  10.117 -	struct usb_device *dev;
  10.118 -
  10.119 -        int in_progress : 1;	        /* QH was queued (not linked in) */
  10.120 -	int short_control_packet : 1;	/* If we get a short packet during */
  10.121 -					/*  a control transfer, retrigger */
  10.122 -					/*  the status phase */
  10.123 -
  10.124 -	int status;			/* Final status */
  10.125 -
  10.126 -	unsigned long inserttime;	/* In jiffies */
  10.127 -
  10.128 -	struct list_head queue_list;	/* P: xhci->frame_list_lock */
  10.129 -	struct list_head complete_list;	/* P: xhci->complete_list_lock */
  10.130 -};
  10.131 -
  10.132 -/*
  10.133 - * Locking in xhci.c
  10.134 - *
  10.135 - * spinlocks are used extensively to protect the many lists and data
  10.136 - * structures we have. It's not that pretty, but it's necessary. We
  10.137 - * need to be done with all of the locks (except complete_list_lock) when
  10.138 - * we call urb->complete. I've tried to make it simple enough so I don't
  10.139 - * have to spend hours racking my brain trying to figure out if the
  10.140 - * locking is safe.
  10.141 - *
  10.142 - * Here's the safe locking order to prevent deadlocks:
  10.143 - *
  10.144 - * #1 xhci->urb_list_lock
  10.145 - * #2 urb->lock
  10.146 - * #3 xhci->urb_remove_list_lock, xhci->frame_list_lock, 
  10.147 - *   xhci->qh_remove_list_lock
  10.148 - * #4 xhci->complete_list_lock
  10.149 - *
  10.150 - * If you're going to grab 2 or more locks at once, ALWAYS grab the lock
  10.151 - * at the lowest level FIRST and NEVER grab locks at the same level at the
  10.152 - * same time.
  10.153 - * 
  10.154 - * So, if you need xhci->urb_list_lock, grab it before you grab urb->lock
  10.155 - */
  10.156 -
  10.157 -/* -------------------------------------------------------------------------
  10.158 -   Virtual Root HUB
  10.159 -   ------------------------------------------------------------------------- */
  10.160 -/* destination of request */
  10.161 -#define RH_DEVICE		0x00
  10.162 -#define RH_INTERFACE		0x01
  10.163 -#define RH_ENDPOINT		0x02
  10.164 -#define RH_OTHER		0x03
  10.165 -
  10.166 -#define RH_CLASS		0x20
  10.167 -#define RH_VENDOR		0x40
  10.168 -
  10.169 -/* Requests: bRequest << 8 | bmRequestType */
  10.170 -#define RH_GET_STATUS		0x0080
  10.171 -#define RH_CLEAR_FEATURE	0x0100
  10.172 -#define RH_SET_FEATURE		0x0300
  10.173 -#define RH_SET_ADDRESS		0x0500
  10.174 -#define RH_GET_DESCRIPTOR	0x0680
  10.175 -#define RH_SET_DESCRIPTOR	0x0700
  10.176 -#define RH_GET_CONFIGURATION	0x0880
  10.177 -#define RH_SET_CONFIGURATION	0x0900
  10.178 -#define RH_GET_STATE		0x0280
  10.179 -#define RH_GET_INTERFACE	0x0A80
  10.180 -#define RH_SET_INTERFACE	0x0B00
  10.181 -#define RH_SYNC_FRAME		0x0C80
  10.182 -/* Our Vendor Specific Request */
  10.183 -#define RH_SET_EP		0x2000
  10.184 -
  10.185 -/* Hub port features */
  10.186 -#define RH_PORT_CONNECTION	0x00
  10.187 -#define RH_PORT_ENABLE		0x01
  10.188 -#define RH_PORT_SUSPEND		0x02
  10.189 -#define RH_PORT_OVER_CURRENT	0x03
  10.190 -#define RH_PORT_RESET		0x04
  10.191 -#define RH_PORT_POWER		0x08
  10.192 -#define RH_PORT_LOW_SPEED	0x09
  10.193 -#define RH_C_PORT_CONNECTION	0x10
  10.194 -#define RH_C_PORT_ENABLE	0x11
  10.195 -#define RH_C_PORT_SUSPEND	0x12
  10.196 -#define RH_C_PORT_OVER_CURRENT	0x13
  10.197 -#define RH_C_PORT_RESET		0x14
  10.198 -
  10.199 -/* Hub features */
  10.200 -#define RH_C_HUB_LOCAL_POWER	0x00
  10.201 -#define RH_C_HUB_OVER_CURRENT	0x01
  10.202 -#define RH_DEVICE_REMOTE_WAKEUP	0x00
  10.203 -#define RH_ENDPOINT_STALL	0x01
  10.204 -
  10.205 -/* Our Vendor Specific feature */
  10.206 -#define RH_REMOVE_EP		0x00
  10.207 -
  10.208 -#define RH_ACK			0x01
  10.209 -#define RH_REQ_ERR		-1
  10.210 -#define RH_NACK			0x00
  10.211 -
  10.212 -#endif
  10.213 -
    11.1 --- a/linux-2.4.28-xen-sparse/arch/xen/drivers/usbif/usbif.h	Sat Jan 22 15:16:02 2005 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,111 +0,0 @@
    11.4 -/******************************************************************************
    11.5 - * usbif.h
    11.6 - * 
    11.7 - * Unified block-device I/O interface for Xen guest OSes.
    11.8 - * 
    11.9 - * Copyright (c) 2003-2004, Keir Fraser
   11.10 - */
   11.11 -
   11.12 -#ifndef __SHARED_USBIF_H__
   11.13 -#define __SHARED_USBIF_H__
   11.14 -
   11.15 -#define usbif_vdev_t   u16
   11.16 -#define usbif_sector_t u64
   11.17 -
   11.18 -#define USBIF_OP_IO      0
   11.19 -#define USBIF_OP_PROBE   1 /* Is there a device on this port? */
   11.20 -#define USBIF_OP_RESET   2 /* Reset a virtual USB port.       */
   11.21 -
   11.22 -/* NB. Ring size must be small enough for sizeof(usbif_ring_t) <= PAGE_SIZE. */
   11.23 -#define USBIF_RING_SIZE        64
   11.24 -
   11.25 -/* XXX this does not want to be here!  it really ought to be dynamic but it can
   11.26 - * live here for now */
   11.27 -#define NUM_PORTS 1
   11.28 -
   11.29 -typedef struct {
   11.30 -    unsigned long  id;           /*  0: private guest value, echoed in resp  */
   11.31 -    u8             operation;    /*  4: USBIF_OP_???                         */
   11.32 -    u8  __pad1;
   11.33 -    usbif_vdev_t   port;         /* 6 : guest virtual USB port               */
   11.34 -    unsigned long  devnum :7;    /* 8 : Device address, as seen by the guest.*/
   11.35 -    unsigned long  endpoint :4;  /* Device endpoint.                         */
   11.36 -    unsigned long  direction :1; /* Pipe direction.                          */
   11.37 -    unsigned long  speed :1;     /* Pipe speed.                              */
   11.38 -    unsigned long  pipe_type :2; /* Pipe type (iso, bulk, int, ctrl)         */
   11.39 -    unsigned long  __pad2 :18;
   11.40 -    unsigned long  transfer_buffer; /* 12: Machine address */
   11.41 -    unsigned long  length;          /* 16: Buffer length */
   11.42 -    unsigned long  transfer_flags;  /* 20: For now just pass Linux transfer
   11.43 -                                     * flags - this may change. */
   11.44 -    unsigned char setup[8];         /* 22 Embed setup packets directly. */
   11.45 -    unsigned long  iso_schedule;    /* 30 Machine address of transfer sched (iso
   11.46 -                                     * only) */
   11.47 -    unsigned long num_iso;        /* 34 : length of iso schedule */
   11.48 -    unsigned long timeout;        /* 38: timeout in ms */
   11.49 -} PACKED usbif_request_t; /* 42 */
   11.50 -/* Data we need to pass:
   11.51 - * - Transparently handle short packets or complain at us?
   11.52 - */
   11.53 -
   11.54 -typedef struct {
   11.55 -    unsigned long   id;              /* 0: copied from request         */
   11.56 -    u8              operation;       /* 4: copied from request         */
   11.57 -    u8              data;            /* 5: Small chunk of in-band data */
   11.58 -    s16             status;          /* 6: USBIF_RSP_???               */
   11.59 -    unsigned long   transfer_mutex;  /* Used for cancelling requests atomically. */
   11.60 -    unsigned long    length;          /* 8: How much data we really got */
   11.61 -} PACKED usbif_response_t;
   11.62 -
   11.63 -#define USBIF_RSP_ERROR  -1 /* non-specific 'error' */
   11.64 -#define USBIF_RSP_OKAY    0 /* non-specific 'okay'  */
   11.65 -
   11.66 -/*
   11.67 - * We use a special capitalised type name because it is _essential_ that all 
   11.68 - * arithmetic on indexes is done on an integer type of the correct size.
   11.69 - */
   11.70 -typedef u32 USBIF_RING_IDX;
   11.71 -
   11.72 -/*
   11.73 - * Ring indexes are 'free running'. That is, they are not stored modulo the
   11.74 - * size of the ring buffer. The following macro converts a free-running counter
   11.75 - * into a value that can directly index a ring-buffer array.
   11.76 - */
   11.77 -#define MASK_USBIF_IDX(_i) ((_i)&(USBIF_RING_SIZE-1))
   11.78 -
   11.79 -typedef struct {
   11.80 -    USBIF_RING_IDX req_prod;  /*  0: Request producer. Updated by front-end. */
   11.81 -    USBIF_RING_IDX resp_prod; /*  4: Response producer. Updated by back-end. */
   11.82 -
   11.83 -    union {                   /*  8 */
   11.84 -        usbif_request_t  req;
   11.85 -        usbif_response_t resp;
   11.86 -    } PACKED ring[USBIF_RING_SIZE];
   11.87 -} PACKED usbif_t;
   11.88 -
   11.89 -
   11.90 -
   11.91 -/*
   11.92 - * USBIF_OP_PROBE:
   11.93 - * The request format for a probe request is constrained as follows:
   11.94 - *  @operation   == USBIF_OP_PROBE
   11.95 - *  @nr_segments == size of probe buffer in pages
   11.96 - *  @device      == unused (zero)
   11.97 - *  @id          == any value (echoed in response message)
   11.98 - *  @sector_num  == unused (zero)
   11.99 - *  @frame_and_sects == list of page-sized buffers.
  11.100 - *                       (i.e., @first_sect == 0, @last_sect == 7).
  11.101 - * 
  11.102 - * The response is a list of vdisk_t elements copied into the out-of-band
  11.103 - * probe buffer. On success the response status field contains the number
  11.104 - * of vdisk_t elements.
  11.105 - */
  11.106 -
  11.107 -typedef struct {
  11.108 -    unsigned long length; /* IN = expected, OUT = actual */
  11.109 -    unsigned long buffer_offset;  /* IN offset in buffer specified in main
  11.110 -                                     packet */
  11.111 -    unsigned long status; /* OUT Status for this packet. */
  11.112 -} usbif_iso_t;
  11.113 -
  11.114 -#endif /* __SHARED_USBIF_H__ */
    12.1 --- a/linux-2.4.28-xen-sparse/drivers/usb/hcd.c	Sat Jan 22 15:16:02 2005 +0000
    12.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.3 @@ -1,1511 +0,0 @@
    12.4 -/*
    12.5 - * Copyright (c) 2001-2002 by David Brownell
    12.6 - * 
    12.7 - * This program is free software; you can redistribute it and/or modify it
    12.8 - * under the terms of the GNU General Public License as published by the
    12.9 - * Free Software Foundation; either version 2 of the License, or (at your
   12.10 - * option) any later version.
   12.11 - *
   12.12 - * This program is distributed in the hope that it will be useful, but
   12.13 - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
   12.14 - * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.15 - * for more details.
   12.16 - *
   12.17 - * You should have received a copy of the GNU General Public License
   12.18 - * along with this program; if not, write to the Free Software Foundation,
   12.19 - * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   12.20 - */
   12.21 -
   12.22 -#include <linux/config.h>
   12.23 -#include <linux/module.h>
   12.24 -#include <linux/pci.h>
   12.25 -#include <linux/kernel.h>
   12.26 -#include <linux/delay.h>
   12.27 -#include <linux/ioport.h>
   12.28 -#include <linux/sched.h>
   12.29 -#include <linux/slab.h>
   12.30 -#include <linux/smp_lock.h>
   12.31 -#include <linux/errno.h>
   12.32 -#include <linux/kmod.h>
   12.33 -#include <linux/init.h>
   12.34 -#include <linux/timer.h>
   12.35 -#include <linux/list.h>
   12.36 -#include <linux/interrupt.h>
   12.37 -#include <linux/completion.h>
   12.38 -#include <linux/uts.h>			/* for UTS_SYSNAME */
   12.39 -
   12.40 -
   12.41 -#ifdef CONFIG_USB_DEBUG
   12.42 -	#define DEBUG
   12.43 -#else
   12.44 -	#undef DEBUG
   12.45 -#endif
   12.46 -
   12.47 -#include <linux/usb.h>
   12.48 -#include "hcd.h"
   12.49 -
   12.50 -#include <asm/io.h>
   12.51 -#include <asm/irq.h>
   12.52 -#include <asm/system.h>
   12.53 -#include <asm/unaligned.h>
   12.54 -
   12.55 -
   12.56 -/*-------------------------------------------------------------------------*/
   12.57 -
   12.58 -/*
   12.59 - * USB Host Controller Driver framework
   12.60 - *
   12.61 - * Plugs into usbcore (usb_bus) and lets HCDs share code, minimizing
   12.62 - * HCD-specific behaviors/bugs.  Think of it as the "upper level" of
   12.63 - * some drivers, where the "lower level" is hardware-specific.
   12.64 - *
   12.65 - * This does error checks, tracks devices and urbs, and delegates to a
   12.66 - * "hc_driver" only for code (and data) that really needs to know about
   12.67 - * hardware differences.  That includes root hub registers, i/o queues,
   12.68 - * and so on ... but as little else as possible.
   12.69 - *
   12.70 - * Shared code includes most of the "root hub" code (these are emulated,
   12.71 - * though each HC's hardware works differently) and PCI glue, plus request
   12.72 - * tracking overhead.  The HCD code should only block on spinlocks or on
   12.73 - * hardware handshaking; blocking on software events (such as other kernel
   12.74 - * threads releasing resources, or completing actions) is all generic.
   12.75 - *
   12.76 - * Happens the USB 2.0 spec says this would be invisible inside the "USBD",
   12.77 - * and includes mostly a "HCDI" (HCD Interface) along with some APIs used
   12.78 - * only by the hub driver ... and that neither should be seen or used by
   12.79 - * usb client device drivers.
   12.80 - *
   12.81 - * Contributors of ideas or unattributed patches include: David Brownell,
   12.82 - * Roman Weissgaerber, Rory Bolt, ...
   12.83 - *
   12.84 - * HISTORY:
   12.85 - * 2002-sept	Merge some 2.5 updates so we can share hardware level HCD
   12.86 - * 	code between the 2.4.20+ and 2.5 trees.
   12.87 - * 2002-feb	merge to 2.4.19
   12.88 - * 2001-12-12	Initial patch version for Linux 2.5.1 kernel.
   12.89 - */
   12.90 -
   12.91 -/*-------------------------------------------------------------------------*/
   12.92 -
   12.93 -/* host controllers we manage */
   12.94 -static LIST_HEAD (hcd_list);
   12.95 -
   12.96 -/* used when updating list of hcds */
   12.97 -static DECLARE_MUTEX (hcd_list_lock);
   12.98 -
   12.99 -/* used when updating hcd data */
  12.100 -static spinlock_t hcd_data_lock = SPIN_LOCK_UNLOCKED;
  12.101 -
  12.102 -static struct usb_operations hcd_operations;
  12.103 -
  12.104 -/*-------------------------------------------------------------------------*/
  12.105 -
  12.106 -/*
  12.107 - * Sharable chunks of root hub code.
  12.108 - */
  12.109 -
  12.110 -/*-------------------------------------------------------------------------*/
  12.111 -
  12.112 -#define KERNEL_REL	((LINUX_VERSION_CODE >> 16) & 0x0ff)
  12.113 -#define KERNEL_VER	((LINUX_VERSION_CODE >> 8) & 0x0ff)
  12.114 -
  12.115 -/* usb 2.0 root hub device descriptor */
  12.116 -static const u8 usb2_rh_dev_descriptor [18] = {
  12.117 -	0x12,       /*  __u8  bLength; */
  12.118 -	0x01,       /*  __u8  bDescriptorType; Device */
  12.119 -	0x00, 0x02, /*  __u16 bcdUSB; v2.0 */
  12.120 -
  12.121 -	0x09,	    /*  __u8  bDeviceClass; HUB_CLASSCODE */
  12.122 -	0x00,	    /*  __u8  bDeviceSubClass; */
  12.123 -	0x01,       /*  __u8  bDeviceProtocol; [ usb 2.0 single TT ]*/
  12.124 -	0x08,       /*  __u8  bMaxPacketSize0; 8 Bytes */
  12.125 -
  12.126 -	0x00, 0x00, /*  __u16 idVendor; */
  12.127 - 	0x00, 0x00, /*  __u16 idProduct; */
  12.128 -	KERNEL_VER, KERNEL_REL, /*  __u16 bcdDevice */
  12.129 -
  12.130 -	0x03,       /*  __u8  iManufacturer; */
  12.131 -	0x02,       /*  __u8  iProduct; */
  12.132 -	0x01,       /*  __u8  iSerialNumber; */
  12.133 -	0x01        /*  __u8  bNumConfigurations; */
  12.134 -};
  12.135 -
  12.136 -/* no usb 2.0 root hub "device qualifier" descriptor: one speed only */
  12.137 -
  12.138 -/* usb 1.1 root hub device descriptor */
  12.139 -static const u8 usb11_rh_dev_descriptor [18] = {
  12.140 -	0x12,       /*  __u8  bLength; */
  12.141 -	0x01,       /*  __u8  bDescriptorType; Device */
  12.142 -	0x10, 0x01, /*  __u16 bcdUSB; v1.1 */
  12.143 -
  12.144 -	0x09,	    /*  __u8  bDeviceClass; HUB_CLASSCODE */
  12.145 -	0x00,	    /*  __u8  bDeviceSubClass; */
  12.146 -	0x00,       /*  __u8  bDeviceProtocol; [ low/full speeds only ] */
  12.147 -	0x08,       /*  __u8  bMaxPacketSize0; 8 Bytes */
  12.148 -
  12.149 -	0x00, 0x00, /*  __u16 idVendor; */
  12.150 - 	0x00, 0x00, /*  __u16 idProduct; */
  12.151 -	KERNEL_VER, KERNEL_REL, /*  __u16 bcdDevice */
  12.152 -
  12.153 -	0x03,       /*  __u8  iManufacturer; */
  12.154 -	0x02,       /*  __u8  iProduct; */
  12.155 -	0x01,       /*  __u8  iSerialNumber; */
  12.156 -	0x01        /*  __u8  bNumConfigurations; */
  12.157 -};
  12.158 -
  12.159 -
  12.160 -/*-------------------------------------------------------------------------*/
  12.161 -
  12.162 -/* Configuration descriptors for our root hubs */
  12.163 -
  12.164 -static const u8 fs_rh_config_descriptor [] = {
  12.165 -
  12.166 -	/* one configuration */
  12.167 -	0x09,       /*  __u8  bLength; */
  12.168 -	0x02,       /*  __u8  bDescriptorType; Configuration */
  12.169 -	0x19, 0x00, /*  __u16 wTotalLength; */
  12.170 -	0x01,       /*  __u8  bNumInterfaces; (1) */
  12.171 -	0x01,       /*  __u8  bConfigurationValue; */
  12.172 -	0x00,       /*  __u8  iConfiguration; */
  12.173 -	0x40,       /*  __u8  bmAttributes; 
  12.174 -				 Bit 7: Bus-powered,
  12.175 -				     6: Self-powered,
  12.176 -				     5 Remote-wakwup,
  12.177 -				     4..0: resvd */
  12.178 -	0x00,       /*  __u8  MaxPower; */
  12.179 -      
  12.180 -	/* USB 1.1:
  12.181 -	 * USB 2.0, single TT organization (mandatory):
  12.182 -	 *	one interface, protocol 0
  12.183 -	 *
  12.184 -	 * USB 2.0, multiple TT organization (optional):
  12.185 -	 *	two interfaces, protocols 1 (like single TT)
  12.186 -	 *	and 2 (multiple TT mode) ... config is
  12.187 -	 *	sometimes settable
  12.188 -	 *	NOT IMPLEMENTED
  12.189 -	 */
  12.190 -
  12.191 -	/* one interface */
  12.192 -	0x09,       /*  __u8  if_bLength; */
  12.193 -	0x04,       /*  __u8  if_bDescriptorType; Interface */
  12.194 -	0x00,       /*  __u8  if_bInterfaceNumber; */
  12.195 -	0x00,       /*  __u8  if_bAlternateSetting; */
  12.196 -	0x01,       /*  __u8  if_bNumEndpoints; */
  12.197 -	0x09,       /*  __u8  if_bInterfaceClass; HUB_CLASSCODE */
  12.198 -	0x00,       /*  __u8  if_bInterfaceSubClass; */
  12.199 -	0x00,       /*  __u8  if_bInterfaceProtocol; [usb1.1 or single tt] */
  12.200 -	0x00,       /*  __u8  if_iInterface; */
  12.201 -     
  12.202 -	/* one endpoint (status change endpoint) */
  12.203 -	0x07,       /*  __u8  ep_bLength; */
  12.204 -	0x05,       /*  __u8  ep_bDescriptorType; Endpoint */
  12.205 -	0x81,       /*  __u8  ep_bEndpointAddress; IN Endpoint 1 */
  12.206 - 	0x03,       /*  __u8  ep_bmAttributes; Interrupt */
  12.207 - 	0x02, 0x00, /*  __u16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
  12.208 -	0xff        /*  __u8  ep_bInterval; (255ms -- usb 2.0 spec) */
  12.209 -};
  12.210 -
  12.211 -static const u8 hs_rh_config_descriptor [] = {
  12.212 -
  12.213 -	/* one configuration */
  12.214 -	0x09,       /*  __u8  bLength; */
  12.215 -	0x02,       /*  __u8  bDescriptorType; Configuration */
  12.216 -	0x19, 0x00, /*  __u16 wTotalLength; */
  12.217 -	0x01,       /*  __u8  bNumInterfaces; (1) */
  12.218 -	0x01,       /*  __u8  bConfigurationValue; */
  12.219 -	0x00,       /*  __u8  iConfiguration; */
  12.220 -	0x40,       /*  __u8  bmAttributes; 
  12.221 -				 Bit 7: Bus-powered,
  12.222 -				     6: Self-powered,
  12.223 -				     5 Remote-wakwup,
  12.224 -				     4..0: resvd */
  12.225 -	0x00,       /*  __u8  MaxPower; */
  12.226 -      
  12.227 -	/* USB 1.1:
  12.228 -	 * USB 2.0, single TT organization (mandatory):
  12.229 -	 *	one interface, protocol 0
  12.230 -	 *
  12.231 -	 * USB 2.0, multiple TT organization (optional):
  12.232 -	 *	two interfaces, protocols 1 (like single TT)
  12.233 -	 *	and 2 (multiple TT mode) ... config is
  12.234 -	 *	sometimes settable
  12.235 -	 *	NOT IMPLEMENTED
  12.236 -	 */
  12.237 -
  12.238 -	/* one interface */
  12.239 -	0x09,       /*  __u8  if_bLength; */
  12.240 -	0x04,       /*  __u8  if_bDescriptorType; Interface */
  12.241 -	0x00,       /*  __u8  if_bInterfaceNumber; */
  12.242 -	0x00,       /*  __u8  if_bAlternateSetting; */
  12.243 -	0x01,       /*  __u8  if_bNumEndpoints; */
  12.244 -	0x09,       /*  __u8  if_bInterfaceClass; HUB_CLASSCODE */
  12.245 -	0x00,       /*  __u8  if_bInterfaceSubClass; */
  12.246 -	0x00,       /*  __u8  if_bInterfaceProtocol; [usb1.1 or single tt] */
  12.247 -	0x00,       /*  __u8  if_iInterface; */
  12.248 -     
  12.249 -	/* one endpoint (status change endpoint) */
  12.250 -	0x07,       /*  __u8  ep_bLength; */
  12.251 -	0x05,       /*  __u8  ep_bDescriptorType; Endpoint */
  12.252 -	0x81,       /*  __u8  ep_bEndpointAddress; IN Endpoint 1 */
  12.253 - 	0x03,       /*  __u8  ep_bmAttributes; Interrupt */
  12.254 - 	0x02, 0x00, /*  __u16 ep_wMaxPacketSize; 1 + (MAX_ROOT_PORTS / 8) */
  12.255 -	0x0c        /*  __u8  ep_bInterval; (256ms -- usb 2.0 spec) */
  12.256 -};
  12.257 -
  12.258 -/*-------------------------------------------------------------------------*/
  12.259 -
  12.260 -/*
  12.261 - * helper routine for returning string descriptors in UTF-16LE
  12.262 - * input can actually be ISO-8859-1; ASCII is its 7-bit subset
  12.263 - */
  12.264 -static int ascii2utf (char *s, u8 *utf, int utfmax)
  12.265 -{
  12.266 -	int retval;
  12.267 -
  12.268 -	for (retval = 0; *s && utfmax > 1; utfmax -= 2, retval += 2) {
  12.269 -		*utf++ = *s++;
  12.270 -		*utf++ = 0;
  12.271 -	}
  12.272 -	return retval;
  12.273 -}
  12.274 -
  12.275 -/*
  12.276 - * rh_string - provides manufacturer, product and serial strings for root hub
  12.277 - * @id: the string ID number (1: serial number, 2: product, 3: vendor)
  12.278 - * @pci_desc: PCI device descriptor for the relevant HC
  12.279 - * @type: string describing our driver 
  12.280 - * @data: return packet in UTF-16 LE
  12.281 - * @len: length of the return packet
  12.282 - *
  12.283 - * Produces either a manufacturer, product or serial number string for the
  12.284 - * virtual root hub device.
  12.285 - */
  12.286 -static int rh_string (
  12.287 -	int		id,
  12.288 -	struct usb_hcd	*hcd,
  12.289 -	u8		*data,
  12.290 -	int		len
  12.291 -) {
  12.292 -	char buf [100];
  12.293 -
  12.294 -	// language ids
  12.295 -	if (id == 0) {
  12.296 -		*data++ = 4; *data++ = 3;	/* 4 bytes string data */
  12.297 -		*data++ = 0; *data++ = 0;	/* some language id */
  12.298 -		return 4;
  12.299 -
  12.300 -	// serial number
  12.301 -	} else if (id == 1) {
  12.302 -		strcpy (buf, hcd->bus->bus_name);
  12.303 -
  12.304 -	// product description
  12.305 -	} else if (id == 2) {
  12.306 -                strcpy (buf, hcd->product_desc);
  12.307 -
  12.308 - 	// id 3 == vendor description
  12.309 -	} else if (id == 3) {
  12.310 -                sprintf (buf, "%s %s %s", UTS_SYSNAME, UTS_RELEASE,
  12.311 -			hcd->description);
  12.312 -
  12.313 -	// unsupported IDs --> "protocol stall"
  12.314 -	} else
  12.315 -	    return 0;
  12.316 -
  12.317 -	data [0] = 2 * (strlen (buf) + 1);
  12.318 -	data [1] = 3;	/* type == string */
  12.319 -	return 2 + ascii2utf (buf, data + 2, len - 2);
  12.320 -}
  12.321 -
  12.322 -
  12.323 -/* Root hub control transfers execute synchronously */
  12.324 -static int rh_call_control (struct usb_hcd *hcd, struct urb *urb)
  12.325 -{
  12.326 -	struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *) urb->setup_packet;
  12.327 - 	u16		typeReq, wValue, wIndex, wLength;
  12.328 -	const u8	*bufp = 0;
  12.329 -	u8		*ubuf = urb->transfer_buffer;
  12.330 -	int		len = 0;
  12.331 -
  12.332 -	typeReq  = (cmd->bRequestType << 8) | cmd->bRequest;
  12.333 -	wValue   = le16_to_cpu (cmd->wValue);
  12.334 -	wIndex   = le16_to_cpu (cmd->wIndex);
  12.335 -	wLength  = le16_to_cpu (cmd->wLength);
  12.336 -
  12.337 -	if (wLength > urb->transfer_buffer_length)
  12.338 -		goto error;
  12.339 -
  12.340 -	/* set up for success */
  12.341 -	urb->status = 0;
  12.342 -	urb->actual_length = wLength;
  12.343 -	switch (typeReq) {
  12.344 -
  12.345 -	/* DEVICE REQUESTS */
  12.346 -
  12.347 -	case DeviceRequest | USB_REQ_GET_STATUS:
  12.348 -		// DEVICE_REMOTE_WAKEUP
  12.349 -		ubuf [0] = 1; // selfpowered
  12.350 -		ubuf [1] = 0;
  12.351 -			/* FALLTHROUGH */
  12.352 -	case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
  12.353 -	case DeviceOutRequest | USB_REQ_SET_FEATURE:
  12.354 -		dbg ("no device features yet yet");
  12.355 -		break;
  12.356 -	case DeviceRequest | USB_REQ_GET_CONFIGURATION:
  12.357 -		ubuf [0] = 1;
  12.358 -			/* FALLTHROUGH */
  12.359 -	case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
  12.360 -		break;
  12.361 -	case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
  12.362 -		switch (wValue & 0xff00) {
  12.363 -		case USB_DT_DEVICE << 8:
  12.364 -			if (hcd->driver->flags & HCD_USB2)
  12.365 -				bufp = usb2_rh_dev_descriptor;
  12.366 -			else if (hcd->driver->flags & HCD_USB11)
  12.367 -				bufp = usb11_rh_dev_descriptor;
  12.368 -			else
  12.369 -				goto error;
  12.370 -			len = 18;
  12.371 -			break;
  12.372 -		case USB_DT_CONFIG << 8:
  12.373 -			if (hcd->driver->flags & HCD_USB2) {
  12.374 -				bufp = hs_rh_config_descriptor;
  12.375 -				len = sizeof hs_rh_config_descriptor;
  12.376 -			} else {
  12.377 -				bufp = fs_rh_config_descriptor;
  12.378 -				len = sizeof fs_rh_config_descriptor;
  12.379 -			}
  12.380 -			break;
  12.381 -		case USB_DT_STRING << 8:
  12.382 -			urb->actual_length = rh_string (
  12.383 -				wValue & 0xff, hcd,
  12.384 -				ubuf, wLength);
  12.385 -			break;
  12.386 -		default:
  12.387 -			goto error;
  12.388 -		}
  12.389 -		break;
  12.390 -	case DeviceRequest | USB_REQ_GET_INTERFACE:
  12.391 -		ubuf [0] = 0;
  12.392 -			/* FALLTHROUGH */
  12.393 -	case DeviceOutRequest | USB_REQ_SET_INTERFACE:
  12.394 -		break;
  12.395 -	case DeviceOutRequest | USB_REQ_SET_ADDRESS:
  12.396 -		// wValue == urb->dev->devaddr
  12.397 -		dbg ("%s root hub device address %d",
  12.398 -			hcd->bus->bus_name, wValue);
  12.399 -		break;
  12.400 -
  12.401 -	/* INTERFACE REQUESTS (no defined feature/status flags) */
  12.402 -
  12.403 -	/* ENDPOINT REQUESTS */
  12.404 -
  12.405 -	case EndpointRequest | USB_REQ_GET_STATUS:
  12.406 -		// ENDPOINT_HALT flag
  12.407 -		ubuf [0] = 0;
  12.408 -		ubuf [1] = 0;
  12.409 -			/* FALLTHROUGH */
  12.410 -	case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
  12.411 -	case EndpointOutRequest | USB_REQ_SET_FEATURE:
  12.412 -		dbg ("no endpoint features yet");
  12.413 -		break;
  12.414 -
  12.415 -	/* CLASS REQUESTS (and errors) */
  12.416 -
  12.417 -	default:
  12.418 -		/* non-generic request */
  12.419 -		urb->status = hcd->driver->hub_control (hcd,
  12.420 -			typeReq, wValue, wIndex,
  12.421 -			ubuf, wLength);
  12.422 -		break;
  12.423 -error:
  12.424 -		/* "protocol stall" on error */
  12.425 -		urb->status = -EPIPE;
  12.426 -		dbg ("unsupported hub control message (maxchild %d)",
  12.427 -				urb->dev->maxchild);
  12.428 -	}
  12.429 -	if (urb->status) {
  12.430 -		urb->actual_length = 0;
  12.431 -		dbg ("CTRL: TypeReq=0x%x val=0x%x idx=0x%x len=%d ==> %d",
  12.432 -			typeReq, wValue, wIndex, wLength, urb->status);
  12.433 -	}
  12.434 -	if (bufp) {
  12.435 -		if (urb->transfer_buffer_length < len)
  12.436 -			len = urb->transfer_buffer_length;
  12.437 -		urb->actual_length = len;
  12.438 -		// always USB_DIR_IN, toward host
  12.439 -		memcpy (ubuf, bufp, len);
  12.440 -	}
  12.441 -
  12.442 -	/* any errors get returned through the urb completion */
  12.443 -	usb_hcd_giveback_urb (hcd, urb, 0);
  12.444 -	return 0;
  12.445 -}
  12.446 -
  12.447 -/*-------------------------------------------------------------------------*/
  12.448 -
  12.449 -/*
  12.450 - * Root Hub interrupt transfers are synthesized with a timer.
  12.451 - * Completions are called in_interrupt() but not in_irq().
  12.452 - */
  12.453 -
  12.454 -static void rh_report_status (unsigned long ptr);
  12.455 -
  12.456 -static int rh_status_urb (struct usb_hcd *hcd, struct urb *urb) 
  12.457 -{
  12.458 -	int	len = 1 + (urb->dev->maxchild / 8);
  12.459 -
  12.460 -	/* rh_timer protected by hcd_data_lock */
  12.461 -	if (timer_pending (&hcd->rh_timer)
  12.462 -			|| urb->status != -EINPROGRESS
  12.463 -			|| !HCD_IS_RUNNING (hcd->state)
  12.464 -			|| urb->transfer_buffer_length < len) {
  12.465 -		dbg ("not queuing status urb, stat %d", urb->status);
  12.466 -		return -EINVAL;
  12.467 -	}
  12.468 -
  12.469 -	urb->hcpriv = hcd;	/* nonzero to indicate it's queued */
  12.470 -	init_timer (&hcd->rh_timer);
  12.471 -	hcd->rh_timer.function = rh_report_status;
  12.472 -	hcd->rh_timer.data = (unsigned long) urb;
  12.473 -	/* USB 2.0 spec says 256msec; this is close enough */
  12.474 -	hcd->rh_timer.expires = jiffies + HZ/4;
  12.475 -	add_timer (&hcd->rh_timer);
  12.476 -	return 0;
  12.477 -}
  12.478 -
  12.479 -/* timer callback */
  12.480 -
  12.481 -static void rh_report_status (unsigned long ptr)
  12.482 -{
  12.483 -	struct urb	*urb;
  12.484 -	struct usb_hcd	*hcd;
  12.485 -	int		length;
  12.486 -	unsigned long	flags;
  12.487 -
  12.488 -	urb = (struct urb *) ptr;
  12.489 -	spin_lock_irqsave (&urb->lock, flags);
  12.490 -	if (!urb->dev) {
  12.491 -		spin_unlock_irqrestore (&urb->lock, flags);
  12.492 -		return;
  12.493 -	}
  12.494 -
  12.495 -	hcd = urb->dev->bus->hcpriv;
  12.496 -	if (urb->status == -EINPROGRESS) {
  12.497 -		if (HCD_IS_RUNNING (hcd->state)) {
  12.498 -			length = hcd->driver->hub_status_data (hcd,
  12.499 -					urb->transfer_buffer);
  12.500 -			spin_unlock_irqrestore (&urb->lock, flags);
  12.501 -			if (length > 0) {
  12.502 -				urb->actual_length = length;
  12.503 -				urb->status = 0;
  12.504 -				urb->complete (urb);
  12.505 -			}
  12.506 -			spin_lock_irqsave (&hcd_data_lock, flags);
  12.507 -			urb->status = -EINPROGRESS;
  12.508 -			if (HCD_IS_RUNNING (hcd->state)
  12.509 -					&& rh_status_urb (hcd, urb) != 0) {
  12.510 -				/* another driver snuck in? */
  12.511 -				dbg ("%s, can't resubmit roothub status urb?",
  12.512 -					hcd->bus->bus_name);
  12.513 -				spin_unlock_irqrestore (&hcd_data_lock, flags);
  12.514 -				BUG ();
  12.515 -			}
  12.516 -			spin_unlock_irqrestore (&hcd_data_lock, flags);
  12.517 -		} else
  12.518 -			spin_unlock_irqrestore (&urb->lock, flags);
  12.519 -	} else {
  12.520 -		/* this urb's been unlinked */
  12.521 -		urb->hcpriv = 0;
  12.522 -		spin_unlock_irqrestore (&urb->lock, flags);
  12.523 -
  12.524 -		usb_hcd_giveback_urb (hcd, urb, 0);
  12.525 -	}
  12.526 -}
  12.527 -
  12.528 -/*-------------------------------------------------------------------------*/
  12.529 -
  12.530 -static int rh_urb_enqueue (struct usb_hcd *hcd, struct urb *urb)
  12.531 -{
  12.532 -	if (usb_pipeint (urb->pipe)) {
  12.533 -		int		retval;
  12.534 -		unsigned long	flags;
  12.535 -
  12.536 -		spin_lock_irqsave (&hcd_data_lock, flags);
  12.537 -		retval = rh_status_urb (hcd, urb);
  12.538 -		spin_unlock_irqrestore (&hcd_data_lock, flags);
  12.539 -		return retval;
  12.540 -	}
  12.541 -	if (usb_pipecontrol (urb->pipe))
  12.542 -		return rh_call_control (hcd, urb);
  12.543 -	else
  12.544 -		return -EINVAL;
  12.545 -}
  12.546 -
  12.547 -/*-------------------------------------------------------------------------*/
  12.548 -
  12.549 -static void rh_status_dequeue (struct usb_hcd *hcd, struct urb *urb)
  12.550 -{
  12.551 -	unsigned long	flags;
  12.552 -
  12.553 -	spin_lock_irqsave (&hcd_data_lock, flags);
  12.554 -	del_timer_sync (&hcd->rh_timer);
  12.555 -	hcd->rh_timer.data = 0;
  12.556 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
  12.557 -
  12.558 -	/* we rely on RH callback code not unlinking its URB! */
  12.559 -	usb_hcd_giveback_urb (hcd, urb, 0);
  12.560 -}
  12.561 -
  12.562 -/*-------------------------------------------------------------------------*/
  12.563 -
  12.564 -#ifdef CONFIG_PCI
  12.565 -
  12.566 -/* PCI-based HCs are normal, but custom bus glue should be ok */
  12.567 -
  12.568 -static void hcd_irq (int irq, void *__hcd, struct pt_regs *r);
  12.569 -static void hc_died (struct usb_hcd *hcd);
  12.570 -
  12.571 -/*-------------------------------------------------------------------------*/
  12.572 -
  12.573 -/* configure so an HC device and id are always provided */
  12.574 -/* always called with process context; sleeping is OK */
  12.575 -
  12.576 -/**
  12.577 - * usb_hcd_pci_probe - initialize PCI-based HCDs
  12.578 - * @dev: USB Host Controller being probed
  12.579 - * @id: pci hotplug id connecting controller to HCD framework
  12.580 - * Context: !in_interrupt()
  12.581 - *
  12.582 - * Allocates basic PCI resources for this USB host controller, and
  12.583 - * then invokes the start() method for the HCD associated with it
  12.584 - * through the hotplug entry's driver_data.
  12.585 - *
  12.586 - * Store this function in the HCD's struct pci_driver as probe().
  12.587 - */
  12.588 -int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
  12.589 -{
  12.590 -	struct hc_driver	*driver;
  12.591 -	unsigned long		resource, len;
  12.592 -	void			*base;
  12.593 -	struct usb_bus		*bus;
  12.594 -	struct usb_hcd		*hcd;
  12.595 -	int			retval, region;
  12.596 -	char			buf [8], *bufp = buf;
  12.597 -
  12.598 -	if (!id || !(driver = (struct hc_driver *) id->driver_data))
  12.599 -		return -EINVAL;
  12.600 -
  12.601 -	if (pci_enable_device (dev) < 0)
  12.602 -		return -ENODEV;
  12.603 -	
  12.604 -        if (!dev->irq) {
  12.605 -        	err ("Found HC with no IRQ.  Check BIOS/PCI %s setup!",
  12.606 -			dev->slot_name);
  12.607 -   	        return -ENODEV;
  12.608 -        }
  12.609 -	
  12.610 -	if (driver->flags & HCD_MEMORY) {	// EHCI, OHCI
  12.611 -		region = 0;
  12.612 -		resource = pci_resource_start (dev, 0);
  12.613 -		len = pci_resource_len (dev, 0);
  12.614 -		if (!request_mem_region (resource, len, driver->description)) {
  12.615 -			dbg ("controller already in use");
  12.616 -			return -EBUSY;
  12.617 -		}
  12.618 -		base = ioremap_nocache (resource, len);
  12.619 -		if (base == NULL) {
  12.620 -			dbg ("error mapping memory");
  12.621 -			retval = -EFAULT;
  12.622 -clean_1:
  12.623 -			release_mem_region (resource, len);
  12.624 -			err ("init %s fail, %d", dev->slot_name, retval);
  12.625 -			return retval;
  12.626 -		}
  12.627 -
  12.628 -	} else { 				// UHCI
  12.629 -		resource = len = 0;
  12.630 -		for (region = 0; region < PCI_ROM_RESOURCE; region++) {
  12.631 -			if (!(pci_resource_flags (dev, region) & IORESOURCE_IO))
  12.632 -				continue;
  12.633 -
  12.634 -			resource = pci_resource_start (dev, region);
  12.635 -			len = pci_resource_len (dev, region);
  12.636 -			if (request_region (resource, len,
  12.637 -					driver->description))
  12.638 -				break;
  12.639 -		}
  12.640 -		if (region == PCI_ROM_RESOURCE) {
  12.641 -			dbg ("no i/o regions available");
  12.642 -			return -EBUSY;
  12.643 -		}
  12.644 -		base = (void *) resource;
  12.645 -	}
  12.646 -
  12.647 -	// driver->start(), later on, will transfer device from
  12.648 -	// control by SMM/BIOS to control by Linux (if needed)
  12.649 -
  12.650 -	pci_set_master (dev);
  12.651 -	hcd = driver->hcd_alloc ();
  12.652 -	if (hcd == NULL){
  12.653 -		dbg ("hcd alloc fail");
  12.654 -		retval = -ENOMEM;
  12.655 -clean_2:
  12.656 -		if (driver->flags & HCD_MEMORY) {
  12.657 -			iounmap (base);
  12.658 -			goto clean_1;
  12.659 -		} else {
  12.660 -			release_region (resource, len);
  12.661 -			err ("init %s fail, %d", dev->slot_name, retval);
  12.662 -			return retval;
  12.663 -		}
  12.664 -	}
  12.665 -	pci_set_drvdata(dev, hcd);
  12.666 -	hcd->driver = driver;
  12.667 -	hcd->description = driver->description;
  12.668 -	hcd->pdev = dev;
  12.669 -	printk (KERN_INFO "%s %s: %s\n",
  12.670 -			hcd->description,  dev->slot_name, dev->name);
  12.671 -
  12.672 -#ifndef __sparc__
  12.673 -	sprintf (buf, "%d", dev->irq);
  12.674 -#else
  12.675 -	bufp = __irq_itoa(dev->irq);
  12.676 -#endif
  12.677 -	if (request_irq (dev->irq, hcd_irq, SA_SHIRQ, hcd->description, hcd)
  12.678 -			!= 0) {
  12.679 -		err ("request interrupt %s failed", bufp);
  12.680 -		retval = -EBUSY;
  12.681 -clean_3:
  12.682 -		driver->hcd_free (hcd);
  12.683 -		goto clean_2;
  12.684 -	}
  12.685 -	hcd->irq = dev->irq;
  12.686 -
  12.687 -	hcd->regs = base;
  12.688 -	hcd->region = region;
  12.689 -	printk (KERN_INFO "%s %s: irq %s, %s %p\n",
  12.690 -		hcd->description,  dev->slot_name, bufp,
  12.691 -		(driver->flags & HCD_MEMORY) ? "pci mem" : "io base",
  12.692 -		base);
  12.693 -
  12.694 -// FIXME simpler: make "bus" be that data, not pointer to it.
  12.695 -// (fixed in 2.5)
  12.696 -	bus = usb_alloc_bus (&hcd_operations);
  12.697 -	if (bus == NULL) {
  12.698 -		dbg ("usb_alloc_bus fail");
  12.699 -		retval = -ENOMEM;
  12.700 -		free_irq (dev->irq, hcd);
  12.701 -		goto clean_3;
  12.702 -	}
  12.703 -	hcd->bus = bus;
  12.704 -	bus->bus_name = dev->slot_name;
  12.705 -	hcd->product_desc = dev->name;
  12.706 -	bus->hcpriv = (void *) hcd;
  12.707 -
  12.708 -	INIT_LIST_HEAD (&hcd->dev_list);
  12.709 -	INIT_LIST_HEAD (&hcd->hcd_list);
  12.710 -
  12.711 -	down (&hcd_list_lock);
  12.712 -	list_add (&hcd->hcd_list, &hcd_list);
  12.713 -	up (&hcd_list_lock);
  12.714 -
  12.715 -	usb_register_bus (bus);
  12.716 -
  12.717 -	if ((retval = driver->start (hcd)) < 0)
  12.718 -		usb_hcd_pci_remove (dev);
  12.719 -
  12.720 -	return retval;
  12.721 -} 
  12.722 -EXPORT_SYMBOL (usb_hcd_pci_probe);
  12.723 -
  12.724 -
  12.725 -/* may be called without controller electrically present */
  12.726 -/* may be called with controller, bus, and devices active */
  12.727 -
  12.728 -/**
  12.729 - * usb_hcd_pci_remove - shutdown processing for PCI-based HCDs
  12.730 - * @dev: USB Host Controller being removed
  12.731 - * Context: !in_interrupt()
  12.732 - *
  12.733 - * Reverses the effect of usb_hcd_pci_probe(), first invoking
  12.734 - * the HCD's stop() method.  It is always called from a thread
  12.735 - * context, normally "rmmod", "apmd", or something similar.
  12.736 - *
  12.737 - * Store this function in the HCD's struct pci_driver as remove().
  12.738 - */
  12.739 -void usb_hcd_pci_remove (struct pci_dev *dev)
  12.740 -{
  12.741 -	struct usb_hcd		*hcd;
  12.742 -	struct usb_device	*hub;
  12.743 -
  12.744 -	hcd = pci_get_drvdata(dev);
  12.745 -	if (!hcd)
  12.746 -		return;
  12.747 -	printk (KERN_INFO "%s %s: remove state %x\n",
  12.748 -		hcd->description,  dev->slot_name, hcd->state);
  12.749 -
  12.750 -	if (in_interrupt ()) BUG ();
  12.751 -
  12.752 -	hub = hcd->bus->root_hub;
  12.753 -	hcd->state = USB_STATE_QUIESCING;
  12.754 -
  12.755 -	dbg ("%s: roothub graceful disconnect", hcd->bus->bus_name);
  12.756 -	usb_disconnect (&hub);
  12.757 -	// usb_disconnect (&hcd->bus->root_hub);
  12.758 -
  12.759 -	hcd->driver->stop (hcd);
  12.760 -	hcd->state = USB_STATE_HALT;
  12.761 -
  12.762 -	free_irq (hcd->irq, hcd);
  12.763 -	if (hcd->driver->flags & HCD_MEMORY) {
  12.764 -		iounmap (hcd->regs);
  12.765 -		release_mem_region (pci_resource_start (dev, 0),
  12.766 -			pci_resource_len (dev, 0));
  12.767 -	} else {
  12.768 -		release_region (pci_resource_start (dev, hcd->region),
  12.769 -			pci_resource_len (dev, hcd->region));
  12.770 -	}
  12.771 -
  12.772 -	down (&hcd_list_lock);
  12.773 -	list_del (&hcd->hcd_list);
  12.774 -	up (&hcd_list_lock);
  12.775 -
  12.776 -	usb_deregister_bus (hcd->bus);
  12.777 -	usb_free_bus (hcd->bus);
  12.778 -	hcd->bus = NULL;
  12.779 -
  12.780 -	hcd->driver->hcd_free (hcd);
  12.781 -}
  12.782 -EXPORT_SYMBOL (usb_hcd_pci_remove);
  12.783 -
  12.784 -
  12.785 -#ifdef	CONFIG_PM
  12.786 -
  12.787 -/*
  12.788 - * Some "sleep" power levels imply updating struct usb_driver
  12.789 - * to include a callback asking hcds to do their bit by checking
  12.790 - * if all the drivers can suspend.  Gets involved with remote wakeup.
  12.791 - *
  12.792 - * If there are pending urbs, then HCs will need to access memory,
  12.793 - * causing extra power drain.  New sleep()/wakeup() PM calls might
  12.794 - * be needed, beyond PCI suspend()/resume().  The root hub timer
  12.795 - * still be accessing memory though ...
  12.796 - *
  12.797 - * FIXME:  USB should have some power budgeting support working with
  12.798 - * all kinds of hubs.
  12.799 - *
  12.800 - * FIXME:  This assumes only D0->D3 suspend and D3->D0 resume.
  12.801 - * D1 and D2 states should do something, yes?
  12.802 - *
  12.803 - * FIXME:  Should provide generic enable_wake(), calling pci_enable_wake()
  12.804 - * for all supported states, so that USB remote wakeup can work for any
  12.805 - * devices that support it (and are connected via powered hubs).
  12.806 - *
  12.807 - * FIXME:  resume doesn't seem to work right any more...
  12.808 - */
  12.809 -
  12.810 -
  12.811 -// 2.4 kernels have issued concurrent resumes (w/APM)
  12.812 -// we defend against that error; PCI doesn't yet.
  12.813 -
  12.814 -/**
  12.815 - * usb_hcd_pci_suspend - power management suspend of a PCI-based HCD
  12.816 - * @dev: USB Host Controller being suspended
  12.817 - *
  12.818 - * Store this function in the HCD's struct pci_driver as suspend().
  12.819 - */
  12.820 -int usb_hcd_pci_suspend (struct pci_dev *dev, u32 state)
  12.821 -{
  12.822 -	struct usb_hcd		*hcd;
  12.823 -	int			retval;
  12.824 -
  12.825 -	hcd = pci_get_drvdata(dev);
  12.826 -	printk (KERN_INFO "%s %s: suspend to state %d\n",
  12.827 -		hcd->description,  dev->slot_name, state);
  12.828 -
  12.829 -	pci_save_state (dev, hcd->pci_state);
  12.830 -
  12.831 -	// FIXME for all connected devices, leaf-to-root:
  12.832 -	// driver->suspend()
  12.833 -	// proposed "new 2.5 driver model" will automate that
  12.834 -
  12.835 -	/* driver may want to disable DMA etc */
  12.836 -	retval = hcd->driver->suspend (hcd, state);
  12.837 -	hcd->state = USB_STATE_SUSPENDED;
  12.838 -
  12.839 - 	pci_set_power_state (dev, state);
  12.840 -	return retval;
  12.841 -}
  12.842 -EXPORT_SYMBOL (usb_hcd_pci_suspend);
  12.843 -
  12.844 -/**
  12.845 - * usb_hcd_pci_resume - power management resume of a PCI-based HCD
  12.846 - * @dev: USB Host Controller being resumed
  12.847 - *
  12.848 - * Store this function in the HCD's struct pci_driver as resume().
  12.849 - */
  12.850 -int usb_hcd_pci_resume (struct pci_dev *dev)
  12.851 -{
  12.852 -	struct usb_hcd		*hcd;
  12.853 -	int			retval;
  12.854 -
  12.855 -	hcd = pci_get_drvdata(dev);
  12.856 -	printk (KERN_INFO "%s %s: resume\n",
  12.857 -		hcd->description,  dev->slot_name);
  12.858 -
  12.859 -	/* guard against multiple resumes (APM bug?) */
  12.860 -	atomic_inc (&hcd->resume_count);
  12.861 -	if (atomic_read (&hcd->resume_count) != 1) {
  12.862 -		err ("concurrent PCI resumes for %s", hcd->bus->bus_name);
  12.863 -		retval = 0;
  12.864 -		goto done;
  12.865 -	}
  12.866 -
  12.867 -	retval = -EBUSY;
  12.868 -	if (hcd->state != USB_STATE_SUSPENDED) {
  12.869 -		dbg ("can't resume, not suspended!");
  12.870 -		goto done;
  12.871 -	}
  12.872 -	hcd->state = USB_STATE_RESUMING;
  12.873 -
  12.874 -	pci_set_power_state (dev, 0);
  12.875 -	pci_restore_state (dev, hcd->pci_state);
  12.876 -
  12.877 -	retval = hcd->driver->resume (hcd);
  12.878 -	if (!HCD_IS_RUNNING (hcd->state)) {
  12.879 -		dbg ("resume %s failure, retval %d",
  12.880 -			hcd->bus->bus_name, retval);
  12.881 -		hc_died (hcd);
  12.882 -// FIXME:  recover, reset etc.
  12.883 -	} else {
  12.884 -		// FIXME for all connected devices, root-to-leaf:
  12.885 -		// driver->resume ();
  12.886 -		// proposed "new 2.5 driver model" will automate that
  12.887 -	}
  12.888 -
  12.889 -done:
  12.890 -	atomic_dec (&hcd->resume_count);
  12.891 -	return retval;
  12.892 -}
  12.893 -EXPORT_SYMBOL (usb_hcd_pci_resume);
  12.894 -
  12.895 -#endif	/* CONFIG_PM */
  12.896 -
  12.897 -#endif
  12.898 -
  12.899 -/*-------------------------------------------------------------------------*/
  12.900 -
  12.901 -/*
  12.902 - * Generic HC operations.
  12.903 - */
  12.904 -
  12.905 -/*-------------------------------------------------------------------------*/
  12.906 -
  12.907 -/* called from khubd, or root hub init threads for hcd-private init */
  12.908 -static int hcd_alloc_dev (struct usb_device *udev)
  12.909 -{
  12.910 -	struct hcd_dev		*dev;
  12.911 -	struct usb_hcd		*hcd;
  12.912 -	unsigned long		flags;
  12.913 -
  12.914 -	if (!udev || udev->hcpriv)
  12.915 -		return -EINVAL;
  12.916 -	if (!udev->bus || !udev->bus->hcpriv)
  12.917 -		return -ENODEV;
  12.918 -	hcd = udev->bus->hcpriv;
  12.919 -	if (hcd->state == USB_STATE_QUIESCING)
  12.920 -		return -ENOLINK;
  12.921 -
  12.922 -	dev = (struct hcd_dev *) kmalloc (sizeof *dev, GFP_KERNEL);
  12.923 -	if (dev == NULL)
  12.924 -		return -ENOMEM;
  12.925 -	memset (dev, 0, sizeof *dev);
  12.926 -
  12.927 -	INIT_LIST_HEAD (&dev->dev_list);
  12.928 -	INIT_LIST_HEAD (&dev->urb_list);
  12.929 -
  12.930 -	spin_lock_irqsave (&hcd_data_lock, flags);
  12.931 -	list_add (&dev->dev_list, &hcd->dev_list);
  12.932 -	// refcount is implicit
  12.933 -	udev->hcpriv = dev;
  12.934 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
  12.935 -
  12.936 -	return 0;
  12.937 -}
  12.938 -
  12.939 -/*-------------------------------------------------------------------------*/
  12.940 -
  12.941 -static void hcd_panic (void *_hcd)
  12.942 -{
  12.943 -	struct usb_hcd *hcd = _hcd;
  12.944 -	hcd->driver->stop (hcd);
  12.945 -}
  12.946 -
  12.947 -static void hc_died (struct usb_hcd *hcd)
  12.948 -{
  12.949 -	struct list_head	*devlist, *urblist;
  12.950 -	struct hcd_dev		*dev;
  12.951 -	struct urb		*urb;
  12.952 -	unsigned long		flags;
  12.953 -	
  12.954 -	/* flag every pending urb as done */
  12.955 -	spin_lock_irqsave (&hcd_data_lock, flags);
  12.956 -	list_for_each (devlist, &hcd->dev_list) {
  12.957 -		dev = list_entry (devlist, struct hcd_dev, dev_list);
  12.958 -		list_for_each (urblist, &dev->urb_list) {
  12.959 -			urb = list_entry (urblist, struct urb, urb_list);
  12.960 -			dbg ("shutdown %s urb %p pipe %x, current status %d",
  12.961 -				hcd->bus->bus_name,
  12.962 -				urb, urb->pipe, urb->status);
  12.963 -			if (urb->status == -EINPROGRESS)
  12.964 -				urb->status = -ESHUTDOWN;
  12.965 -		}
  12.966 -	}
  12.967 -	urb = (struct urb *) hcd->rh_timer.data;
  12.968 -	if (urb)
  12.969 -		urb->status = -ESHUTDOWN;
  12.970 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
  12.971 -
  12.972 -	if (urb)
  12.973 -		rh_status_dequeue (hcd, urb);
  12.974 -
  12.975 -	/* hcd->stop() needs a task context */
  12.976 -	INIT_TQUEUE (&hcd->work, hcd_panic, hcd);
  12.977 -	(void) schedule_task (&hcd->work);
  12.978 -}
  12.979 -
  12.980 -/*-------------------------------------------------------------------------*/
  12.981 -
  12.982 -static void urb_unlink (struct urb *urb)
  12.983 -{
  12.984 -	unsigned long		flags;
  12.985 -	struct usb_device	*dev;
  12.986 -
  12.987 -	/* Release any periodic transfer bandwidth */
  12.988 -	if (urb->bandwidth)
  12.989 -		usb_release_bandwidth (urb->dev, urb,
  12.990 -			usb_pipeisoc (urb->pipe));
  12.991 -
  12.992 -	/* clear all state linking urb to this dev (and hcd) */
  12.993 -
  12.994 -	spin_lock_irqsave (&hcd_data_lock, flags);
  12.995 -	list_del_init (&urb->urb_list);
  12.996 -	dev = urb->dev;
  12.997 -	urb->dev = NULL;
  12.998 -	usb_dec_dev_use (dev);
  12.999 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
 12.1000 -}
 12.1001 -
 12.1002 -
 12.1003 -/* may be called in any context with a valid urb->dev usecount */
 12.1004 -/* caller surrenders "ownership" of urb */
 12.1005 -
 12.1006 -static int hcd_submit_urb (struct urb *urb)
 12.1007 -{
 12.1008 -	int			status;
 12.1009 -	struct usb_hcd		*hcd;
 12.1010 -	struct hcd_dev		*dev;
 12.1011 -	unsigned long		flags;
 12.1012 -	int			pipe, temp, max;
 12.1013 -	int			mem_flags;
 12.1014 -
 12.1015 -	if (!urb || urb->hcpriv || !urb->complete)
 12.1016 -		return -EINVAL;
 12.1017 -
 12.1018 -	urb->status = -EINPROGRESS;
 12.1019 -	urb->actual_length = 0;
 12.1020 -	urb->bandwidth = 0;
 12.1021 -	INIT_LIST_HEAD (&urb->urb_list);
 12.1022 -
 12.1023 -	if (!urb->dev || !urb->dev->bus || urb->dev->devnum <= 0)
 12.1024 -		return -ENODEV;
 12.1025 -	hcd = urb->dev->bus->hcpriv;
 12.1026 -	dev = urb->dev->hcpriv;
 12.1027 -	if (!hcd || !dev)
 12.1028 -		return -ENODEV;
 12.1029 -
 12.1030 -	/* can't submit new urbs when quiescing, halted, ... */
 12.1031 -	if (hcd->state == USB_STATE_QUIESCING || !HCD_IS_RUNNING (hcd->state))
 12.1032 -		return -ESHUTDOWN;
 12.1033 -	pipe = urb->pipe;
 12.1034 -	temp = usb_pipetype (urb->pipe);
 12.1035 -	if (usb_endpoint_halted (urb->dev, usb_pipeendpoint (pipe),
 12.1036 -			usb_pipeout (pipe)))
 12.1037 -		return -EPIPE;
 12.1038 -
 12.1039 -	/* NOTE: 2.5 passes this value explicitly in submit() */
 12.1040 -	mem_flags = GFP_ATOMIC;
 12.1041 -
 12.1042 -	/* FIXME there should be a sharable lock protecting us against
 12.1043 -	 * config/altsetting changes and disconnects, kicking in here.
 12.1044 -	 */
 12.1045 -
 12.1046 -	/* Sanity check, so HCDs can rely on clean data */
 12.1047 -	max = usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe));
 12.1048 -	if (max <= 0) {
 12.1049 -		err ("bogus endpoint (bad maxpacket)");
 12.1050 -		return -EINVAL;
 12.1051 -	}
 12.1052 -
 12.1053 -	/* "high bandwidth" mode, 1-3 packets/uframe? */
 12.1054 -	if (urb->dev->speed == USB_SPEED_HIGH) {
 12.1055 -		int	mult;
 12.1056 -		switch (temp) {
 12.1057 -		case PIPE_ISOCHRONOUS:
 12.1058 -		case PIPE_INTERRUPT:
 12.1059 -			mult = 1 + ((max >> 11) & 0x03);
 12.1060 -			max &= 0x03ff;
 12.1061 -			max *= mult;
 12.1062 -		}
 12.1063 -	}
 12.1064 -
 12.1065 -	/* periodic transfers limit size per frame/uframe */
 12.1066 -	switch (temp) {
 12.1067 -	case PIPE_ISOCHRONOUS: {
 12.1068 -		int	n, len;
 12.1069 -
 12.1070 -		if (urb->number_of_packets <= 0)		    
 12.1071 -			return -EINVAL;
 12.1072 -		for (n = 0; n < urb->number_of_packets; n++) {
 12.1073 -			len = urb->iso_frame_desc [n].length;
 12.1074 -			if (len < 0 || len > max) 
 12.1075 -				return -EINVAL;
 12.1076 -		}
 12.1077 -
 12.1078 -		}
 12.1079 -		break;
 12.1080 -	case PIPE_INTERRUPT:
 12.1081 -		if (urb->transfer_buffer_length > max)
 12.1082 -			return -EINVAL;
 12.1083 -	}
 12.1084 -
 12.1085 -	/* the I/O buffer must usually be mapped/unmapped */
 12.1086 -	if (urb->transfer_buffer_length < 0)
 12.1087 -		return -EINVAL;
 12.1088 -
 12.1089 -	if (urb->next) {
 12.1090 -		warn ("use explicit queuing not urb->next");
 12.1091 -		return -EINVAL;
 12.1092 -	}
 12.1093 -
 12.1094 -#ifdef DEBUG
 12.1095 -	/* stuff that drivers shouldn't do, but which shouldn't
 12.1096 -	 * cause problems in HCDs if they get it wrong.
 12.1097 -	 */
 12.1098 -	{
 12.1099 -	unsigned int	orig_flags = urb->transfer_flags;
 12.1100 -	unsigned int	allowed;
 12.1101 -
 12.1102 -	/* enforce simple/standard policy */
 12.1103 -	allowed = USB_ASYNC_UNLINK;	// affects later unlinks
 12.1104 -	allowed |= USB_NO_FSBR;		// only affects UHCI
 12.1105 -	switch (temp) {
 12.1106 -	case PIPE_CONTROL:
 12.1107 -		allowed |= USB_DISABLE_SPD;
 12.1108 -		break;
 12.1109 -	case PIPE_BULK:
 12.1110 -		allowed |= USB_DISABLE_SPD | USB_QUEUE_BULK
 12.1111 -				| USB_ZERO_PACKET | URB_NO_INTERRUPT;
 12.1112 -		break;
 12.1113 -	case PIPE_INTERRUPT:
 12.1114 -		allowed |= USB_DISABLE_SPD;
 12.1115 -		break;
 12.1116 -	case PIPE_ISOCHRONOUS:
 12.1117 -		allowed |= USB_ISO_ASAP;
 12.1118 -		break;
 12.1119 -	}
 12.1120 -	urb->transfer_flags &= allowed;
 12.1121 -
 12.1122 -	/* fail if submitter gave bogus flags */
 12.1123 -	if (urb->transfer_flags != orig_flags) {
 12.1124 -		err ("BOGUS urb flags, %x --> %x",
 12.1125 -			orig_flags, urb->transfer_flags);
 12.1126 -		return -EINVAL;
 12.1127 -	}
 12.1128 -	}
 12.1129 -#endif
 12.1130 -	/*
 12.1131 -	 * Force periodic transfer intervals to be legal values that are
 12.1132 -	 * a power of two (so HCDs don't need to).
 12.1133 -	 *
 12.1134 -	 * FIXME want bus->{intr,iso}_sched_horizon values here.  Each HC
 12.1135 -	 * supports different values... this uses EHCI/UHCI defaults (and
 12.1136 -	 * EHCI can use smaller non-default values).
 12.1137 -	 */
 12.1138 -	switch (temp) {
 12.1139 -	case PIPE_ISOCHRONOUS:
 12.1140 -	case PIPE_INTERRUPT:
 12.1141 -		/* too small? */
 12.1142 -		if (urb->interval <= 0)
 12.1143 -			return -EINVAL;
 12.1144 -		/* too big? */
 12.1145 -		switch (urb->dev->speed) {
 12.1146 -		case USB_SPEED_HIGH:	/* units are microframes */
 12.1147 -			// NOTE usb handles 2^15
 12.1148 -			if (urb->interval > (1024 * 8))
 12.1149 -				urb->interval = 1024 * 8;
 12.1150 -			temp = 1024 * 8;
 12.1151 -			break;
 12.1152 -		case USB_SPEED_FULL:	/* units are frames/msec */
 12.1153 -		case USB_SPEED_LOW:
 12.1154 -			if (temp == PIPE_INTERRUPT) {
 12.1155 -				if (urb->interval > 255)
 12.1156 -					return -EINVAL;
 12.1157 -				// NOTE ohci only handles up to 32
 12.1158 -				temp = 128;
 12.1159 -			} else {
 12.1160 -				if (urb->interval > 1024)
 12.1161 -					urb->interval = 1024;
 12.1162 -				// NOTE usb and ohci handle up to 2^15
 12.1163 -				temp = 1024;
 12.1164 -			}
 12.1165 -			break;
 12.1166 -		default:
 12.1167 -			return -EINVAL;
 12.1168 -		}
 12.1169 -		/* power of two? */
 12.1170 -		while (temp > urb->interval)
 12.1171 -			temp >>= 1;
 12.1172 -		urb->interval = temp;
 12.1173 -	}
 12.1174 -
 12.1175 -
 12.1176 -	/*
 12.1177 -	 * FIXME:  make urb timeouts be generic, keeping the HCD cores
 12.1178 -	 * as simple as possible.
 12.1179 -	 */
 12.1180 -
 12.1181 -	// NOTE:  a generic device/urb monitoring hook would go here.
 12.1182 -	// hcd_monitor_hook(MONITOR_URB_SUBMIT, urb)
 12.1183 -	// It would catch submission paths for all urbs.
 12.1184 -
 12.1185 -	/*
 12.1186 -	 * Atomically queue the urb,  first to our records, then to the HCD.
 12.1187 -	 * Access to urb->status is controlled by urb->lock ... changes on
 12.1188 -	 * i/o completion (normal or fault) or unlinking.
 12.1189 -	 */
 12.1190 -
 12.1191 -	// FIXME:  verify that quiescing hc works right (RH cleans up)
 12.1192 -
 12.1193 -	spin_lock_irqsave (&hcd_data_lock, flags);
 12.1194 -	if (HCD_IS_RUNNING (hcd->state) && hcd->state != USB_STATE_QUIESCING) {
 12.1195 -		usb_inc_dev_use (urb->dev);
 12.1196 -		list_add (&urb->urb_list, &dev->urb_list);
 12.1197 -		status = 0;
 12.1198 -	} else {
 12.1199 -		INIT_LIST_HEAD (&urb->urb_list);
 12.1200 -		status = -ESHUTDOWN;
 12.1201 -	}
 12.1202 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
 12.1203 -	if (status)
 12.1204 -		return status;
 12.1205 -
 12.1206 -	// NOTE:  2.5 does this if !URB_NO_DMA_MAP transfer flag
 12.1207 -	
 12.1208 -	/* For 2.4, don't map bounce buffer if it's a root hub operation. */
 12.1209 -	if (urb->dev == hcd->bus->root_hub) {
 12.1210 -		status = rh_urb_enqueue (hcd, urb);
 12.1211 -	} else {
 12.1212 -#ifdef CONFIG_PCI
 12.1213 -		if (usb_pipecontrol (urb->pipe))
 12.1214 -			urb->setup_dma = pci_map_single (
 12.1215 -					hcd->pdev,
 12.1216 -					urb->setup_packet,
 12.1217 -					sizeof (struct usb_ctrlrequest),
 12.1218 -					PCI_DMA_TODEVICE);
 12.1219 -		if (urb->transfer_buffer_length != 0)
 12.1220 -			urb->transfer_dma = pci_map_single (
 12.1221 -					hcd->pdev,
 12.1222 -					urb->transfer_buffer,
 12.1223 -					urb->transfer_buffer_length,
 12.1224 -					usb_pipein (urb->pipe)
 12.1225 -					    ? PCI_DMA_FROMDEVICE
 12.1226 -					    : PCI_DMA_TODEVICE);
 12.1227 -#endif /* CONFIG_PCI */
 12.1228 -		status = hcd->driver->urb_enqueue (hcd, urb, mem_flags);
 12.1229 -	}
 12.1230 -	return status;
 12.1231 -}
 12.1232 -
 12.1233 -/*-------------------------------------------------------------------------*/
 12.1234 -
 12.1235 -/* called in any context */
 12.1236 -static int hcd_get_frame_number (struct usb_device *udev)
 12.1237 -{
 12.1238 -	struct usb_hcd	*hcd = (struct usb_hcd *)udev->bus->hcpriv;
 12.1239 -	return hcd->driver->get_frame_number (hcd);
 12.1240 -}
 12.1241 -
 12.1242 -/*-------------------------------------------------------------------------*/
 12.1243 -
 12.1244 -struct completion_splice {		// modified urb context:
 12.1245 -	/* did we complete? */
 12.1246 -	struct completion	done;
 12.1247 -
 12.1248 -	/* original urb data */
 12.1249 -	void			(*complete)(struct urb *);
 12.1250 -	void			*context;
 12.1251 -};
 12.1252 -
 12.1253 -static void unlink_complete (struct urb *urb)
 12.1254 -{
 12.1255 -	struct completion_splice	*splice;
 12.1256 -
 12.1257 -	splice = (struct completion_splice *) urb->context;
 12.1258 -
 12.1259 -	/* issue original completion call */
 12.1260 -	urb->complete = splice->complete;
 12.1261 -	urb->context = splice->context;
 12.1262 -	urb->complete (urb);
 12.1263 -
 12.1264 -	/* then let the synchronous unlink call complete */
 12.1265 -	complete (&splice->done);
 12.1266 -}
 12.1267 -
 12.1268 -/*
 12.1269 - * called in any context; note ASYNC_UNLINK restrictions
 12.1270 - *
 12.1271 - * caller guarantees urb won't be recycled till both unlink()
 12.1272 - * and the urb's completion function return
 12.1273 - */
 12.1274 -static int hcd_unlink_urb (struct urb *urb)
 12.1275 -{
 12.1276 -	struct hcd_dev			*dev;
 12.1277 -	struct usb_hcd			*hcd = 0;
 12.1278 -	unsigned long			flags;
 12.1279 -	struct completion_splice	splice;
 12.1280 -	int				retval;
 12.1281 -
 12.1282 -	if (!urb)
 12.1283 -		return -EINVAL;
 12.1284 -
 12.1285 -	/*
 12.1286 -	 * we contend for urb->status with the hcd core,
 12.1287 -	 * which changes it while returning the urb.
 12.1288 -	 *
 12.1289 -	 * Caller guaranteed that the urb pointer hasn't been freed, and
 12.1290 -	 * that it was submitted.  But as a rule it can't know whether or
 12.1291 -	 * not it's already been unlinked ... so we respect the reversed
 12.1292 -	 * lock sequence needed for the usb_hcd_giveback_urb() code paths
 12.1293 -	 * (urb lock, then hcd_data_lock) in case some other CPU is now
 12.1294 -	 * unlinking it.
 12.1295 -	 */
 12.1296 -	spin_lock_irqsave (&urb->lock, flags);
 12.1297 -	spin_lock (&hcd_data_lock);
 12.1298 -	if (!urb->hcpriv || urb->transfer_flags & USB_TIMEOUT_KILLED) {
 12.1299 -		retval = -EINVAL;
 12.1300 -		goto done;
 12.1301 -	}
 12.1302 -
 12.1303 -	if (!urb->dev || !urb->dev->bus) {
 12.1304 -		retval = -ENODEV;
 12.1305 -		goto done;
 12.1306 -	}
 12.1307 -
 12.1308 -	/* giveback clears dev; non-null means it's linked at this level */
 12.1309 -	dev = urb->dev->hcpriv;
 12.1310 -	hcd = urb->dev->bus->hcpriv;
 12.1311 -	if (!dev || !hcd) {
 12.1312 -		retval = -ENODEV;
 12.1313 -		goto done;
 12.1314 -	}
 12.1315 -
 12.1316 -	/* Any status except -EINPROGRESS means the HCD has already started
 12.1317 -	 * to return this URB to the driver.  In that case, there's no
 12.1318 -	 * more work for us to do.
 12.1319 -	 *
 12.1320 -	 * There's much magic because of "automagic resubmit" of interrupt
 12.1321 -	 * transfers, stopped only by explicit unlinking.  We won't issue
 12.1322 -	 * an "it's unlinked" callback more than once, but device drivers
 12.1323 -	 * can need to retry (SMP, -EAGAIN) an unlink request as well as
 12.1324 -	 * fake out the "not yet completed" state (set -EINPROGRESS) if
 12.1325 -	 * unlinking from complete().  Automagic eventually vanishes.
 12.1326 -	 *
 12.1327 -	 * FIXME use an URB_UNLINKED flag to match URB_TIMEOUT_KILLED
 12.1328 -	 */
 12.1329 -	if (urb->status != -EINPROGRESS) {
 12.1330 -		if (usb_pipetype (urb->pipe) == PIPE_INTERRUPT)
 12.1331 -			retval = -EAGAIN;
 12.1332 -		else
 12.1333 -			retval = -EBUSY;
 12.1334 -		goto done;
 12.1335 -	}
 12.1336 -
 12.1337 -	/* maybe set up to block on completion notification */
 12.1338 -	if ((urb->transfer_flags & USB_TIMEOUT_KILLED))
 12.1339 -		urb->status = -ETIMEDOUT;
 12.1340 -	else if (!(urb->transfer_flags & USB_ASYNC_UNLINK)) {
 12.1341 -		if (in_interrupt ()) {
 12.1342 -			dbg ("non-async unlink in_interrupt");
 12.1343 -			retval = -EWOULDBLOCK;
 12.1344 -			goto done;
 12.1345 -		}
 12.1346 -		/* synchronous unlink: block till we see the completion */
 12.1347 -		init_completion (&splice.done);
 12.1348 -		splice.complete = urb->complete;
 12.1349 -		splice.context = urb->context;
 12.1350 -		urb->complete = unlink_complete;
 12.1351 -		urb->context = &splice;
 12.1352 -		urb->status = -ENOENT;
 12.1353 -	} else {
 12.1354 -		/* asynchronous unlink */
 12.1355 -		urb->status = -ECONNRESET;
 12.1356 -	}
 12.1357 -	spin_unlock (&hcd_data_lock);
 12.1358 -	spin_unlock_irqrestore (&urb->lock, flags);
 12.1359 -
 12.1360 -	if (urb == (struct urb *) hcd->rh_timer.data) {
 12.1361 -		rh_status_dequeue (hcd, urb);
 12.1362 -		retval = 0;
 12.1363 -	} else {
 12.1364 -		retval = hcd->driver->urb_dequeue (hcd, urb);
 12.1365 -// FIXME:  if retval and we tried to splice, whoa!!
 12.1366 -if (retval && urb->status == -ENOENT) err ("whoa! retval %d", retval);
 12.1367 -	}
 12.1368 -
 12.1369 -    	/* block till giveback, if needed */
 12.1370 -	if (!(urb->transfer_flags & (USB_ASYNC_UNLINK|USB_TIMEOUT_KILLED))
 12.1371 -			&& HCD_IS_RUNNING (hcd->state)
 12.1372 -			&& !retval) {
 12.1373 -		wait_for_completion (&splice.done);
 12.1374 -	} else if ((urb->transfer_flags & USB_ASYNC_UNLINK) && retval == 0) {
 12.1375 -		return -EINPROGRESS;
 12.1376 -	}
 12.1377 -	goto bye;
 12.1378 -done:
 12.1379 -	spin_unlock (&hcd_data_lock);
 12.1380 -	spin_unlock_irqrestore (&urb->lock, flags);
 12.1381 -bye:
 12.1382 -	if (retval)
 12.1383 -		dbg ("%s: hcd_unlink_urb fail %d",
 12.1384 -		    hcd ? hcd->bus->bus_name : "(no bus?)",
 12.1385 -		    retval);
 12.1386 -	return retval;
 12.1387 -}
 12.1388 -
 12.1389 -/*-------------------------------------------------------------------------*/
 12.1390 -
 12.1391 -/* called by khubd, rmmod, apmd, or other thread for hcd-private cleanup */
 12.1392 -
 12.1393 -// FIXME:  likely best to have explicit per-setting (config+alt)
 12.1394 -// setup primitives in the usbcore-to-hcd driver API, so nothing
 12.1395 -// is implicit.  kernel 2.5 needs a bunch of config cleanup...
 12.1396 -
 12.1397 -static int hcd_free_dev (struct usb_device *udev)
 12.1398 -{
 12.1399 -	struct hcd_dev		*dev;
 12.1400 -	struct usb_hcd		*hcd;
 12.1401 -	unsigned long		flags;
 12.1402 -
 12.1403 -	if (!udev || !udev->hcpriv)
 12.1404 -		return -EINVAL;
 12.1405 -
 12.1406 -	if (!udev->bus || !udev->bus->hcpriv)
 12.1407 -		return -ENODEV;
 12.1408 -
 12.1409 -	// should udev->devnum == -1 ??
 12.1410 -
 12.1411 -	dev = udev->hcpriv;
 12.1412 -	hcd = udev->bus->hcpriv;
 12.1413 -
 12.1414 -	/* device driver problem with refcounts? */
 12.1415 -	if (!list_empty (&dev->urb_list)) {
 12.1416 -		dbg ("free busy dev, %s devnum %d (bug!)",
 12.1417 -			hcd->bus->bus_name, udev->devnum);
 12.1418 -		return -EINVAL;
 12.1419 -	}
 12.1420 -
 12.1421 -	hcd->driver->free_config (hcd, udev);
 12.1422 -
 12.1423 -	spin_lock_irqsave (&hcd_data_lock, flags);
 12.1424 -	list_del (&dev->dev_list);
 12.1425 -	udev->hcpriv = NULL;
 12.1426 -	spin_unlock_irqrestore (&hcd_data_lock, flags);
 12.1427 -
 12.1428 -	kfree (dev);
 12.1429 -	return 0;
 12.1430 -}
 12.1431 -
 12.1432 -static struct usb_operations hcd_operations = {
 12.1433 -	allocate:		hcd_alloc_dev,
 12.1434 -	get_frame_number:	hcd_get_frame_number,
 12.1435 -	submit_urb:		hcd_submit_urb,
 12.1436 -	unlink_urb:		hcd_unlink_urb,
 12.1437 -	deallocate:		hcd_free_dev,
 12.1438 -};
 12.1439 -
 12.1440 -/*-------------------------------------------------------------------------*/
 12.1441 -
 12.1442 -static void hcd_irq (int irq, void *__hcd, struct pt_regs * r)
 12.1443 -{
 12.1444 -	struct usb_hcd		*hcd = __hcd;
 12.1445 -	int			start = hcd->state;
 12.1446 -
 12.1447 -	if (unlikely (hcd->state == USB_STATE_HALT))	/* irq sharing? */
 12.1448 -		return;
 12.1449 -
 12.1450 -	hcd->driver->irq (hcd, r);
 12.1451 -	if (hcd->state != start && hcd->state == USB_STATE_HALT)
 12.1452 -		hc_died (hcd);
 12.1453 -}
 12.1454 -
 12.1455 -/*-------------------------------------------------------------------------*/
 12.1456 -
 12.1457 -/**
 12.1458 - * usb_hcd_giveback_urb - return URB from HCD to device driver
 12.1459 - * @hcd: host controller returning the URB
 12.1460 - * @urb: urb being returned to the USB device driver.
 12.1461 - * @regs: saved hardware registers (ignored on 2.4 kernels)
 12.1462 - * Context: in_interrupt()
 12.1463 - *
 12.1464 - * This hands the URB from HCD to its USB device driver, using its
 12.1465 - * completion function.  The HCD has freed all per-urb resources
 12.1466 - * (and is done using urb->hcpriv).  It also released all HCD locks;
 12.1467 - * the device driver won't cause deadlocks if it resubmits this URB,
 12.1468 - * and won't confuse things by modifying and resubmitting this one.
 12.1469 - * Bandwidth and other resources will be deallocated.
 12.1470 - *
 12.1471 - * HCDs must not use this for periodic URBs that are still scheduled
 12.1472 - * and will be reissued.  They should just call their completion handlers
 12.1473 - * until the urb is returned to the device driver by unlinking.
 12.1474 - *
 12.1475 - * NOTE that no urb->next processing is done, even for isochronous URBs.
 12.1476 - * ISO streaming functionality can be achieved by having completion handlers
 12.1477 - * re-queue URBs.  Such explicit queuing doesn't discard error reports.
 12.1478 - */
 12.1479 -void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs)
 12.1480 -{
 12.1481 -	int is_root_hub_operation;
 12.1482 -
 12.1483 -	/* Work this out here as urb_unlink clears urb->dev */
 12.1484 -	is_root_hub_operation = (urb->dev == hcd->bus->root_hub);
 12.1485 -
 12.1486 -	urb_unlink (urb);
 12.1487 -
 12.1488 -	// NOTE:  a generic device/urb monitoring hook would go here.
 12.1489 -	// hcd_monitor_hook(MONITOR_URB_FINISH, urb, dev)
 12.1490 -	// It would catch exit/unlink paths for all urbs, but non-exit
 12.1491 -	// completions for periodic urbs need hooks inside the HCD.
 12.1492 -	// hcd_monitor_hook(MONITOR_URB_UPDATE, urb, dev)
 12.1493 -
 12.1494 -	// NOTE:  2.5 does this if !URB_NO_DMA_MAP transfer flag
 12.1495 -
 12.1496 -#ifdef CONFIG_PCI	
 12.1497 -	/* For 2.4, don't unmap bounce buffer if it's a root hub operation. */
 12.1498 -	if (usb_pipecontrol (urb->pipe) && !is_root_hub_operation)
 12.1499 -		pci_unmap_single (hcd->pdev, urb->setup_dma,
 12.1500 -				sizeof (struct usb_ctrlrequest),
 12.1501 -				PCI_DMA_TODEVICE);
 12.1502 -
 12.1503 -	if ((urb->transfer_buffer_length != 0) && !is_root_hub_operation)
 12.1504 -		pci_unmap_single (hcd->pdev, urb->transfer_dma,
 12.1505 -				urb->transfer_buffer_length,
 12.1506 -				usb_pipein (urb->pipe)
 12.1507 -				    ? PCI_DMA_FROMDEVICE
 12.1508 -				    : PCI_DMA_TODEVICE);
 12.1509 -#endif /* CONFIG_PCI */
 12.1510 -
 12.1511 -	/* pass ownership to the completion handler */
 12.1512 -	urb->complete (urb);
 12.1513 -}
 12.1514 -EXPORT_SYMBOL (usb_hcd_giveback_urb);
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/Makefile	Sat Jan 22 15:52:51 2005 +0000
    13.3 @@ -0,0 +1,10 @@
    13.4 +
    13.5 +O_TARGET := drv.o
    13.6 +
    13.7 +subdir-$(CONFIG_XEN_USB_FRONTEND) += frontend
    13.8 +obj-$(CONFIG_XEN_USB_FRONTEND) += frontend/drv.o
    13.9 +
   13.10 +subdir-$(CONFIG_XEN_USB_BACKEND) += backend
   13.11 +obj-$(CONFIG_XEN_USB_BACKEND)    += backend/drv.o
   13.12 +
   13.13 +include $(TOPDIR)/Rules.make
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/Makefile	Sat Jan 22 15:52:51 2005 +0000
    14.3 @@ -0,0 +1,3 @@
    14.4 +O_TARGET := drv.o
    14.5 +obj-y := main.o interface.o control.o # vrh.o don't think I need this!
    14.6 +include $(TOPDIR)/Rules.make
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/common.h	Sat Jan 22 15:52:51 2005 +0000
    15.3 @@ -0,0 +1,87 @@
    15.4 +
    15.5 +#ifndef __USBIF__BACKEND__COMMON_H__
    15.6 +#define __USBIF__BACKEND__COMMON_H__
    15.7 +
    15.8 +#include <linux/config.h>
    15.9 +#include <linux/version.h>
   15.10 +#include <linux/module.h>
   15.11 +#include <linux/rbtree.h>
   15.12 +#include <linux/interrupt.h>
   15.13 +#include <linux/slab.h>
   15.14 +#include <linux/blkdev.h>
   15.15 +#include <asm/io.h>
   15.16 +#include <asm/setup.h>
   15.17 +#include <asm/pgalloc.h>
   15.18 +#include <asm-xen/ctrl_if.h>
   15.19 +#include <asm-xen/hypervisor.h>
   15.20 +
   15.21 +#include "../usbif.h"
   15.22 +
   15.23 +#if 0
   15.24 +#define ASSERT(_p) \
   15.25 +    if ( !(_p) ) { printk("Assertion '%s' failed, line %d, file %s", #_p , \
   15.26 +    __LINE__, __FILE__); *(int*)0=0; }
   15.27 +#define DPRINTK(_f, _a...) printk(KERN_ALERT "(file=%s, line=%d) " _f, \
   15.28 +                           __FILE__ , __LINE__ , ## _a )
   15.29 +#else
   15.30 +#define ASSERT(_p) ((void)0)
   15.31 +#define DPRINTK(_f, _a...) ((void)0)
   15.32 +#endif
   15.33 +
   15.34 +typedef struct usbif_priv_st usbif_priv_t;
   15.35 +
   15.36 +struct usbif_priv_st {
   15.37 +    /* Unique identifier for this interface. */
   15.38 +    domid_t          domid;
   15.39 +    unsigned int     handle;
   15.40 +    /* Physical parameters of the comms window. */
   15.41 +    unsigned long    shmem_frame;
   15.42 +    unsigned int     evtchn;
   15.43 +    int              irq;
   15.44 +    /* Comms information. */
   15.45 +    usbif_t      *usb_ring_base; /* ioremap()'ed ptr to shmem_frame. */
   15.46 +    USBIF_RING_IDX     usb_req_cons;  /* Request consumer. */
   15.47 +    USBIF_RING_IDX     usb_resp_prod; /* Private version of resp. producer. */
   15.48 +    /* Private fields. */
   15.49 +    enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
   15.50 +    /*
   15.51 +     * DISCONNECT response is deferred until pending requests are ack'ed.
   15.52 +     * We therefore need to store the id from the original request.
   15.53 +     */
   15.54 +    u8                   disconnect_rspid;
   15.55 +    usbif_priv_t *hash_next;
   15.56 +    struct list_head     usbif_list;
   15.57 +    spinlock_t           usb_ring_lock;
   15.58 +    atomic_t             refcnt;
   15.59 +    atomic_t             work_scheduled;
   15.60 +
   15.61 +    struct work_struct work;
   15.62 +};
   15.63 +
   15.64 +void usbif_create(usbif_be_create_t *create);
   15.65 +void usbif_destroy(usbif_be_destroy_t *destroy);
   15.66 +void usbif_connect(usbif_be_connect_t *connect);
   15.67 +int  usbif_disconnect(usbif_be_disconnect_t *disconnect, u8 rsp_id);
   15.68 +void usbif_disconnect_complete(usbif_priv_t *up);
   15.69 +
   15.70 +void usbif_release_port(usbif_be_release_port_t *msg);
   15.71 +int usbif_claim_port(usbif_be_claim_port_t *msg);
   15.72 +void usbif_release_ports(usbif_priv_t *up);
   15.73 +
   15.74 +usbif_priv_t *usbif_find(domid_t domid);
   15.75 +#define usbif_get(_b) (atomic_inc(&(_b)->refcnt))
   15.76 +#define usbif_put(_b)                             \
   15.77 +    do {                                          \
   15.78 +        if ( atomic_dec_and_test(&(_b)->refcnt) ) \
   15.79 +            usbif_disconnect_complete(_b);        \
   15.80 +    } while (0)
   15.81 +
   15.82 +
   15.83 +void usbif_interface_init(void);
   15.84 +void usbif_ctrlif_init(void);
   15.85 +
   15.86 +void usbif_deschedule(usbif_priv_t *usbif);
   15.87 +
   15.88 +irqreturn_t usbif_be_int(int irq, void *dev_id, struct pt_regs *regs);
   15.89 +
   15.90 +#endif /* __USBIF__BACKEND__COMMON_H__ */
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/control.c	Sat Jan 22 15:52:51 2005 +0000
    16.3 @@ -0,0 +1,77 @@
    16.4 +/******************************************************************************
    16.5 + * arch/xen/drivers/usbif/backend/control.c
    16.6 + * 
    16.7 + * Routines for interfacing with the control plane.
    16.8 + * 
    16.9 + * Copyright (c) 2004, Keir Fraser
   16.10 + */
   16.11 +
   16.12 +#include "common.h"
   16.13 +
   16.14 +static void usbif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
   16.15 +{
   16.16 +    DPRINTK("Received usbif backend message, subtype=%d\n", msg->subtype);
   16.17 +    
   16.18 +    switch ( msg->subtype )
   16.19 +    {
   16.20 +    case CMSG_USBIF_BE_CREATE:
   16.21 +        if ( msg->length != sizeof(usbif_be_create_t) )
   16.22 +            goto parse_error;
   16.23 +        usbif_create((usbif_be_create_t *)&msg->msg[0]);
   16.24 +        break;        
   16.25 +    case CMSG_USBIF_BE_DESTROY:
   16.26 +        if ( msg->length != sizeof(usbif_be_destroy_t) )
   16.27 +            goto parse_error;
   16.28 +        usbif_destroy((usbif_be_destroy_t *)&msg->msg[0]);
   16.29 +        break;        
   16.30 +    case CMSG_USBIF_BE_CONNECT:
   16.31 +        if ( msg->length != sizeof(usbif_be_connect_t) )
   16.32 +            goto parse_error;
   16.33 +        usbif_connect((usbif_be_connect_t *)&msg->msg[0]);
   16.34 +        break;        
   16.35 +    case CMSG_USBIF_BE_DISCONNECT:
   16.36 +        if ( msg->length != sizeof(usbif_be_disconnect_t) )
   16.37 +            goto parse_error;
   16.38 +        if ( !usbif_disconnect((usbif_be_disconnect_t *)&msg->msg[0],msg->id) )
   16.39 +            return; /* Sending the response is deferred until later. */
   16.40 +        break;        
   16.41 +    case CMSG_USBIF_BE_CLAIM_PORT:
   16.42 +        if ( msg->length != sizeof(usbif_be_claim_port_t) )
   16.43 +            goto parse_error;
   16.44 +	usbif_claim_port((usbif_be_claim_port_t *)&msg->msg[0]);
   16.45 +        break;
   16.46 +    case CMSG_USBIF_BE_RELEASE_PORT:
   16.47 +        if ( msg->length != sizeof(usbif_be_release_port_t) )
   16.48 +            goto parse_error;
   16.49 +        usbif_release_port((usbif_be_release_port_t *)&msg->msg[0]);
   16.50 +        break;
   16.51 +    default:
   16.52 +        goto parse_error;
   16.53 +    }
   16.54 +
   16.55 +    ctrl_if_send_response(msg);
   16.56 +    return;
   16.57 +
   16.58 + parse_error:
   16.59 +    DPRINTK("Parse error while reading message subtype %d, len %d\n",
   16.60 +            msg->subtype, msg->length);
   16.61 +    msg->length = 0;
   16.62 +    ctrl_if_send_response(msg);
   16.63 +}
   16.64 +
   16.65 +void usbif_ctrlif_init(void)
   16.66 +{
   16.67 +    ctrl_msg_t                       cmsg;
   16.68 +    usbif_be_driver_status_changed_t st;
   16.69 +
   16.70 +    (void)ctrl_if_register_receiver(CMSG_USBIF_BE, usbif_ctrlif_rx, 
   16.71 +                                    CALLBACK_IN_BLOCKING_CONTEXT);
   16.72 +
   16.73 +    /* Send a driver-UP notification to the domain controller. */
   16.74 +    cmsg.type      = CMSG_USBIF_BE;
   16.75 +    cmsg.subtype   = CMSG_USBIF_BE_DRIVER_STATUS_CHANGED;
   16.76 +    cmsg.length    = sizeof(usbif_be_driver_status_changed_t);
   16.77 +    st.status      = USBIF_DRIVER_STATUS_UP;
   16.78 +    memcpy(cmsg.msg, &st, sizeof(st));
   16.79 +    ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
   16.80 +}
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/interface.c	Sat Jan 22 15:52:51 2005 +0000
    17.3 @@ -0,0 +1,248 @@
    17.4 +/******************************************************************************
    17.5 + * arch/xen/drivers/usbif/backend/interface.c
    17.6 + * 
    17.7 + * USB device interface management.
    17.8 + * 
    17.9 + * by Mark Williamson, Copyright (c) 2004
   17.10 + */
   17.11 +
   17.12 +
   17.13 +/******************************************************************************
   17.14 + * arch/xen/drivers/blkif/backend/interface.c
   17.15 + * 
   17.16 + * Block-device interface management.
   17.17 + * 
   17.18 + * Copyright (c) 2004, Keir Fraser
   17.19 + */
   17.20 +
   17.21 +#include "common.h"
   17.22 +
   17.23 +#define USBIF_HASHSZ 1024
   17.24 +#define USBIF_HASH(_d) (((int)(_d))&(USBIF_HASHSZ-1))
   17.25 +
   17.26 +static kmem_cache_t      *usbif_priv_cachep;
   17.27 +static usbif_priv_t      *usbif_priv_hash[USBIF_HASHSZ];
   17.28 +
   17.29 +usbif_priv_t *usbif_find(domid_t domid)
   17.30 +{
   17.31 +    usbif_priv_t *up = usbif_priv_hash[USBIF_HASH(domid)];
   17.32 +    while ( (up != NULL ) && ( up->domid != domid ) )
   17.33 +        up = up->hash_next;
   17.34 +    return up;
   17.35 +}
   17.36 +
   17.37 +static void __usbif_disconnect_complete(void *arg)
   17.38 +{
   17.39 +    usbif_priv_t         *usbif = (usbif_priv_t *)arg;
   17.40 +    ctrl_msg_t            cmsg;
   17.41 +    usbif_be_disconnect_t disc;
   17.42 +
   17.43 +    /*
   17.44 +     * These can't be done in usbif_disconnect() because at that point there
   17.45 +     * may be outstanding requests at the device whose asynchronous responses
   17.46 +     * must still be notified to the remote driver.
   17.47 +     */
   17.48 +    unbind_evtchn_from_irq(usbif->evtchn);
   17.49 +    vfree(usbif->usb_ring_base);
   17.50 +
   17.51 +    /* Construct the deferred response message. */
   17.52 +    cmsg.type         = CMSG_USBIF_BE;
   17.53 +    cmsg.subtype      = CMSG_USBIF_BE_DISCONNECT;
   17.54 +    cmsg.id           = usbif->disconnect_rspid;
   17.55 +    cmsg.length       = sizeof(usbif_be_disconnect_t);
   17.56 +    disc.domid        = usbif->domid;
   17.57 +    disc.status       = USBIF_BE_STATUS_OKAY;
   17.58 +    memcpy(cmsg.msg, &disc, sizeof(disc));
   17.59 +
   17.60 +    /*
   17.61 +     * Make sure message is constructed /before/ status change, because
   17.62 +     * after the status change the 'usbif' structure could be deallocated at
   17.63 +     * any time. Also make sure we send the response /after/ status change,
   17.64 +     * as otherwise a subsequent CONNECT request could spuriously fail if
   17.65 +     * another CPU doesn't see the status change yet.
   17.66 +     */
   17.67 +    mb();
   17.68 +    if ( usbif->status != DISCONNECTING )
   17.69 +        BUG();
   17.70 +    usbif->status = DISCONNECTED;
   17.71 +    mb();
   17.72 +
   17.73 +    /* Send the successful response. */
   17.74 +    ctrl_if_send_response(&cmsg);
   17.75 +}
   17.76 +
   17.77 +void usbif_disconnect_complete(usbif_priv_t *up)
   17.78 +{
   17.79 +    INIT_WORK(&up->work, __usbif_disconnect_complete, (void *)up);
   17.80 +    schedule_work(&up->work);
   17.81 +}
   17.82 +
   17.83 +void usbif_create(usbif_be_create_t *create)
   17.84 +{
   17.85 +    domid_t       domid  = create->domid;
   17.86 +    usbif_priv_t **pup, *up;
   17.87 +
   17.88 +    if ( (up = kmem_cache_alloc(usbif_priv_cachep, GFP_KERNEL)) == NULL )
   17.89 +    {
   17.90 +        DPRINTK("Could not create usbif: out of memory\n");
   17.91 +        create->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
   17.92 +        return;
   17.93 +    }
   17.94 +
   17.95 +    memset(up, 0, sizeof(*up));
   17.96 +    up->domid  = domid;
   17.97 +    up->status = DISCONNECTED;
   17.98 +    spin_lock_init(&up->usb_ring_lock);
   17.99 +    atomic_set(&up->refcnt, 0);
  17.100 +
  17.101 +    pup = &usbif_priv_hash[USBIF_HASH(domid)];
  17.102 +    while ( *pup != NULL )
  17.103 +    {
  17.104 +        if ( (*pup)->domid == domid )
  17.105 +        {
  17.106 +            create->status = USBIF_BE_STATUS_INTERFACE_EXISTS;
  17.107 +            kmem_cache_free(usbif_priv_cachep, up);
  17.108 +            return;
  17.109 +        }
  17.110 +        pup = &(*pup)->hash_next;
  17.111 +    }
  17.112 +
  17.113 +    up->hash_next = *pup;
  17.114 +    *pup = up;
  17.115 +
  17.116 +    create->status = USBIF_BE_STATUS_OKAY;
  17.117 +}
  17.118 +
  17.119 +void usbif_destroy(usbif_be_destroy_t *destroy)
  17.120 +{
  17.121 +    domid_t       domid  = destroy->domid;
  17.122 +    usbif_priv_t  **pup, *up;
  17.123 +
  17.124 +    pup = &usbif_priv_hash[USBIF_HASH(domid)];
  17.125 +    while ( (up = *pup) != NULL )
  17.126 +    {
  17.127 +        if ( up->domid == domid )
  17.128 +        {
  17.129 +            if ( up->status != DISCONNECTED )
  17.130 +                goto still_connected;
  17.131 +            goto destroy;
  17.132 +        }
  17.133 +        pup = &up->hash_next;
  17.134 +    }
  17.135 +
  17.136 +    destroy->status = USBIF_BE_STATUS_INTERFACE_NOT_FOUND;
  17.137 +    return;
  17.138 +
  17.139 + still_connected:
  17.140 +    destroy->status = USBIF_BE_STATUS_INTERFACE_CONNECTED;
  17.141 +    return;
  17.142 +
  17.143 + destroy:
  17.144 +    *pup = up->hash_next;
  17.145 +    usbif_release_ports(up);
  17.146 +    kmem_cache_free(usbif_priv_cachep, up);
  17.147 +    destroy->status = USBIF_BE_STATUS_OKAY;
  17.148 +}
  17.149 +
  17.150 +void usbif_connect(usbif_be_connect_t *connect)
  17.151 +{
  17.152 +    domid_t       domid  = connect->domid;
  17.153 +    unsigned int  evtchn = connect->evtchn;
  17.154 +    unsigned long shmem_frame = connect->shmem_frame;
  17.155 +    struct vm_struct *vma;
  17.156 +    pgprot_t      prot;
  17.157 +    int           error;
  17.158 +    usbif_priv_t *up;
  17.159 +
  17.160 +    up = usbif_find(domid);
  17.161 +    if ( unlikely(up == NULL) )
  17.162 +    {
  17.163 +        DPRINTK("usbif_connect attempted for non-existent usbif (%u)\n", 
  17.164 +                connect->domid); 
  17.165 +        connect->status = USBIF_BE_STATUS_INTERFACE_NOT_FOUND;
  17.166 +        return;
  17.167 +    }
  17.168 +
  17.169 +    if ( (vma = get_vm_area(PAGE_SIZE, VM_IOREMAP)) == NULL )
  17.170 +    {
  17.171 +        connect->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
  17.172 +        return;
  17.173 +    }
  17.174 +
  17.175 +    prot = __pgprot(_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED);
  17.176 +    error = direct_remap_area_pages(&init_mm, VMALLOC_VMADDR(vma->addr),
  17.177 +                                    shmem_frame<<PAGE_SHIFT, PAGE_SIZE,
  17.178 +                                    prot, domid);
  17.179 +    if ( error != 0 )
  17.180 +    {
  17.181 +        if ( error == -ENOMEM )
  17.182 +            connect->status = USBIF_BE_STATUS_OUT_OF_MEMORY;
  17.183 +        else if ( error == -EFAULT )
  17.184 +            connect->status = USBIF_BE_STATUS_MAPPING_ERROR;
  17.185 +        else
  17.186 +            connect->status = USBIF_BE_STATUS_ERROR;
  17.187 +        vfree(vma->addr);
  17.188 +        return;
  17.189 +    }
  17.190 +
  17.191 +    if ( up->status != DISCONNECTED )
  17.192 +    {
  17.193 +        connect->status = USBIF_BE_STATUS_INTERFACE_CONNECTED;
  17.194 +        vfree(vma->addr);
  17.195 +        return;
  17.196 +    }
  17.197 +
  17.198 +    up->evtchn        = evtchn;
  17.199 +    up->irq           = bind_evtchn_to_irq(evtchn);
  17.200 +    up->shmem_frame   = shmem_frame;
  17.201 +    up->usb_ring_base = (usbif_t *)vma->addr;
  17.202 +    up->status        = CONNECTED;
  17.203 +    usbif_get(up);
  17.204 +
  17.205 +    request_irq(up->irq, usbif_be_int, 0, "usbif-backend", up);
  17.206 +
  17.207 +    connect->status = USBIF_BE_STATUS_OKAY;
  17.208 +}
  17.209 +
  17.210 +/* Remove URBs for this interface before destroying it. */
  17.211 +void usbif_deschedule(usbif_priv_t *up)
  17.212 +{
  17.213 +    remove_from_usbif_list(up);
  17.214 +}
  17.215 +
  17.216 +int usbif_disconnect(usbif_be_disconnect_t *disconnect, u8 rsp_id)
  17.217 +{
  17.218 +    domid_t       domid  = disconnect->domid;
  17.219 +    usbif_priv_t *up;
  17.220 +
  17.221 +    up = usbif_find(domid);
  17.222 +    if ( unlikely(up == NULL) )
  17.223 +    {
  17.224 +        DPRINTK("usbif_disconnect attempted for non-existent usbif"
  17.225 +                " (%u)\n", disconnect->domid); 
  17.226 +        disconnect->status = USBIF_BE_STATUS_INTERFACE_NOT_FOUND;
  17.227 +        return 1; /* Caller will send response error message. */
  17.228 +    }
  17.229 +
  17.230 +    if ( up->status == CONNECTED )
  17.231 +    {
  17.232 +        up->status = DISCONNECTING;
  17.233 +        up->disconnect_rspid = rsp_id;
  17.234 +        wmb(); /* Let other CPUs see the status change. */
  17.235 +        free_irq(up->irq, up);
  17.236 +	usbif_deschedule(up);
  17.237 +        usbif_put(up);
  17.238 +        return 0; /* Caller should not send response message. */
  17.239 +    }
  17.240 +
  17.241 +    disconnect->status = USBIF_BE_STATUS_OKAY;
  17.242 +    return 1;
  17.243 +}
  17.244 +
  17.245 +void __init usbif_interface_init(void)
  17.246 +{
  17.247 +    usbif_priv_cachep = kmem_cache_create("usbif_priv_cache",
  17.248 +					  sizeof(usbif_priv_t), 
  17.249 +					  0, 0, NULL, NULL);
  17.250 +    memset(usbif_priv_hash, 0, sizeof(usbif_priv_hash));
  17.251 +}
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/backend/main.c	Sat Jan 22 15:52:51 2005 +0000
    18.3 @@ -0,0 +1,1011 @@
    18.4 +/******************************************************************************
    18.5 + * arch/xen/drivers/usbif/backend/main.c
    18.6 + * 
    18.7 + * Backend for the Xen virtual USB driver - provides an abstraction of a
    18.8 + * USB host controller to the corresponding frontend driver.
    18.9 + *
   18.10 + * by Mark Williamson, Copyright (c) 2004 Intel Research Cambridge
   18.11 + *
   18.12 + * Based on arch/xen/drivers/blkif/backend/main.c
   18.13 + * Copyright (c) 2003-2004, Keir Fraser & Steve Hand
   18.14 + */
   18.15 +
   18.16 +#include "common.h"
   18.17 +
   18.18 +
   18.19 +#include <linux/list.h>
   18.20 +#include <linux/usb.h>
   18.21 +#include <linux/spinlock.h>
   18.22 +#include <linux/module.h>
   18.23 +#include <linux/tqueue.h>
   18.24 +
   18.25 +/*
   18.26 + * This is rather arbitrary.
   18.27 + */
   18.28 +#define MAX_PENDING_REQS 4
   18.29 +#define BATCH_PER_DOMAIN 1
   18.30 +
   18.31 +static unsigned long mmap_vstart;
   18.32 +
   18.33 +/* Needs to be sufficiently large that we can map the (large) buffers
   18.34 + * the USB mass storage driver wants. */
   18.35 +#define MMAP_PAGES_PER_REQUEST \
   18.36 +    (128)
   18.37 +#define MMAP_PAGES             \
   18.38 +    (MAX_PENDING_REQS * MMAP_PAGES_PER_REQUEST)
   18.39 +
   18.40 +#define MMAP_VADDR(_req,_seg)                        \
   18.41 +    (mmap_vstart +                                   \
   18.42 +     ((_req) * MMAP_PAGES_PER_REQUEST * PAGE_SIZE) + \
   18.43 +     ((_seg) * PAGE_SIZE))
   18.44 +
   18.45 +#define MIN(x,y) ( ( x < y ) ? x : y )
   18.46 +
   18.47 +static spinlock_t owned_ports_lock;
   18.48 +LIST_HEAD(owned_ports);
   18.49 +
   18.50 +/* A list of these structures is used to track ownership of physical USB
   18.51 + * ports. */
   18.52 +typedef struct 
   18.53 +{
   18.54 +    usbif_priv_t     *usbif_priv;
   18.55 +    char             path[16];
   18.56 +    int               guest_port;
   18.57 +    int enabled;
   18.58 +    struct list_head  list;
   18.59 +    unsigned long guest_address; /* The USB device address that has been
   18.60 +                                  * assigned by the guest. */
   18.61 +    int               dev_present; /* Is there a device present? */
   18.62 +    struct usb_device * dev;
   18.63 +    unsigned long ifaces;  /* What interfaces are present on this device? */
   18.64 +} owned_port_t;
   18.65 +
   18.66 +
   18.67 +/*
   18.68 + * Each outstanding request that we've passed to the lower device layers has a
   18.69 + * 'pending_req' allocated to it.  The request is complete, the specified
   18.70 + * domain has a response queued for it, with the saved 'id' passed back.
   18.71 + */
   18.72 +typedef struct {
   18.73 +    usbif_priv_t       *usbif_priv;
   18.74 +    usbif_iso_t        *iso_sched;
   18.75 +    unsigned long      id;
   18.76 +    int                nr_pages;
   18.77 +    unsigned short     operation;
   18.78 +    int                status;
   18.79 +} pending_req_t;
   18.80 +
   18.81 +/*
   18.82 + * We can't allocate pending_req's in order, since they may complete out of 
   18.83 + * order. We therefore maintain an allocation ring. This ring also indicates 
   18.84 + * when enough work has been passed down -- at that point the allocation ring 
   18.85 + * will be empty.
   18.86 + */
   18.87 +static pending_req_t pending_reqs[MAX_PENDING_REQS];
   18.88 +static unsigned char pending_ring[MAX_PENDING_REQS];
   18.89 +static spinlock_t pend_prod_lock = SPIN_LOCK_UNLOCKED;
   18.90 +
   18.91 +/* NB. We use a different index type to differentiate from shared blk rings. */
   18.92 +typedef unsigned int PEND_RING_IDX;
   18.93 +#define MASK_PEND_IDX(_i) ((_i)&(MAX_PENDING_REQS-1))
   18.94 +static PEND_RING_IDX pending_prod, pending_cons;
   18.95 +#define NR_PENDING_REQS (MAX_PENDING_REQS - pending_prod + pending_cons)
   18.96 +
   18.97 +static int do_usb_io_op(usbif_priv_t *usbif, int max_to_do);
   18.98 +static void make_response(usbif_priv_t *usbif, unsigned long id, 
   18.99 +                          unsigned short op, int st, int inband,
  18.100 +			  unsigned long actual_length);
  18.101 +static void dispatch_usb_probe(usbif_priv_t *up, unsigned long id, unsigned long port);
  18.102 +static void dispatch_usb_io(usbif_priv_t *up, usbif_request_t *req);    
  18.103 +static void dispatch_usb_reset(usbif_priv_t *up, unsigned long portid);
  18.104 +static owned_port_t *usbif_find_port(char *);
  18.105 +
  18.106 +
  18.107 +void dump_port(owned_port_t *p)
  18.108 +{
  18.109 +    printk("owned_port_t @ %p\n", p);
  18.110 +    printk("  usbif_priv @ %p\n", p->usbif_priv);
  18.111 +    printk("  path: %s\n", p->path);
  18.112 +    printk("  guest_port: %d\n", p->guest_port);
  18.113 +    printk("  guest_address: %ld\n", p->guest_address);
  18.114 +    printk("  dev_present: %d\n", p->dev_present);
  18.115 +    printk("  dev @ %p\n", p->dev);
  18.116 +    printk("  ifaces: 0x%lx\n", p->ifaces);
  18.117 +}
  18.118 +
  18.119 +
  18.120 +
  18.121 +static void fast_flush_area(int idx, int nr_pages)
  18.122 +{
  18.123 +    multicall_entry_t mcl[MMAP_PAGES_PER_REQUEST];
  18.124 +    int               i;
  18.125 +
  18.126 +    for ( i = 0; i < nr_pages; i++ )
  18.127 +    {
  18.128 +        mcl[i].op = __HYPERVISOR_update_va_mapping;
  18.129 +        mcl[i].args[0] = MMAP_VADDR(idx, i) >> PAGE_SHIFT;
  18.130 +        mcl[i].args[1] = 0;
  18.131 +        mcl[i].args[2] = 0;
  18.132 +    }
  18.133 +
  18.134 +    mcl[nr_pages-1].args[2] = UVMF_FLUSH_TLB;
  18.135 +    if ( unlikely(HYPERVISOR_multicall(mcl, nr_pages) != 0) )
  18.136 +        BUG();
  18.137 +}
  18.138 +
  18.139 +
  18.140 +/******************************************************************
  18.141 + * USB INTERFACE SCHEDULER LIST MAINTENANCE
  18.142 + */
  18.143 +
  18.144 +static struct list_head usbio_schedule_list;
  18.145 +static spinlock_t usbio_schedule_list_lock;
  18.146 +
  18.147 +static int __on_usbif_list(usbif_priv_t *up)
  18.148 +{
  18.149 +    return up->usbif_list.next != NULL;
  18.150 +}
  18.151 +
  18.152 +void remove_from_usbif_list(usbif_priv_t *up)
  18.153 +{
  18.154 +    unsigned long flags;
  18.155 +    if ( !__on_usbif_list(up) ) return;
  18.156 +    spin_lock_irqsave(&usbio_schedule_list_lock, flags);
  18.157 +    if ( __on_usbif_list(up) )
  18.158 +    {
  18.159 +        list_del(&up->usbif_list);
  18.160 +        up->usbif_list.next = NULL;
  18.161 +        usbif_put(up);
  18.162 +    }
  18.163 +    spin_unlock_irqrestore(&usbio_schedule_list_lock, flags);
  18.164 +}
  18.165 +
  18.166 +static void add_to_usbif_list_tail(usbif_priv_t *up)
  18.167 +{
  18.168 +    unsigned long flags;
  18.169 +    if ( __on_usbif_list(up) ) return;
  18.170 +    spin_lock_irqsave(&usbio_schedule_list_lock, flags);
  18.171 +    if ( !__on_usbif_list(up) && (up->status == CONNECTED) )
  18.172 +    {
  18.173 +        list_add_tail(&up->usbif_list, &usbio_schedule_list);
  18.174 +        usbif_get(up);
  18.175 +    }
  18.176 +    spin_unlock_irqrestore(&usbio_schedule_list_lock, flags);
  18.177 +}
  18.178 +
  18.179 +
  18.180 +/******************************************************************
  18.181 + * COMPLETION CALLBACK -- Called as urb->complete()
  18.182 + */
  18.183 +
  18.184 +static void maybe_trigger_usbio_schedule(void);
  18.185 +
  18.186 +static void __end_usb_io_op(struct urb *purb)
  18.187 +{
  18.188 +    unsigned long flags;
  18.189 +    pending_req_t *pending_req;
  18.190 +    int pending_idx;
  18.191 +
  18.192 +    pending_req = purb->context;
  18.193 +
  18.194 +/*     printk("Completed for id = %p to 0x%lx - 0x%lx\n", pending_req->id, */
  18.195 +/*            virt_to_machine(purb->transfer_buffer), */
  18.196 +/*            virt_to_machine(purb->transfer_buffer) */
  18.197 +/*            + pending_req->nr_pages * PAGE_SIZE); */
  18.198 +
  18.199 +    pending_idx = pending_req - pending_reqs;
  18.200 +
  18.201 +    ASSERT(purb->actual_length <= purb->transfer_buffer_length);
  18.202 +    ASSERT(purb->actual_length <= pending_req->nr_pages * PAGE_SIZE);
  18.203 +    
  18.204 +    /* An error fails the entire request. */
  18.205 +    if ( purb->status )
  18.206 +    {
  18.207 +        printk("URB @ %p failed. Status %d\n", purb, purb->status);
  18.208 +    }
  18.209 +
  18.210 +    if ( usb_pipetype(purb->pipe) == 0 )
  18.211 +    {
  18.212 +        int i;
  18.213 +        usbif_iso_t *sched = (usbif_iso_t *)MMAP_VADDR(pending_idx, pending_req->nr_pages - 1);
  18.214 +
  18.215 +        ASSERT(sched == pending_req->sched);
  18.216 +
  18.217 +	//	printk("writing back schedule at %p\n", sched);
  18.218 +
  18.219 +        /* If we're dealing with an iso pipe, we need to copy back the schedule. */
  18.220 +        for ( i = 0; i < purb->number_of_packets; i++ )
  18.221 +        {
  18.222 +            sched[i].length = purb->iso_frame_desc[i].actual_length;
  18.223 +            ASSERT(sched[i].buffer_offset ==
  18.224 +                   purb->iso_frame_desc[i].offset);
  18.225 +            sched[i].status = purb->iso_frame_desc[i].status;
  18.226 +        }
  18.227 +    }
  18.228 +    
  18.229 +    //    printk("Flushing %d pages\n", pending_req->nr_pages);
  18.230 +    fast_flush_area(pending_req - pending_reqs, pending_req->nr_pages);
  18.231 +
  18.232 +    kfree(purb->setup_packet);
  18.233 +
  18.234 +    spin_lock_irqsave(&pending_req->usbif_priv->usb_ring_lock, flags);
  18.235 +    make_response(pending_req->usbif_priv, pending_req->id,
  18.236 +		  pending_req->operation, pending_req->status, 0, purb->actual_length);
  18.237 +    spin_unlock_irqrestore(&pending_req->usbif_priv->usb_ring_lock, flags);
  18.238 +    usbif_put(pending_req->usbif_priv);
  18.239 +
  18.240 +    usb_free_urb(purb);
  18.241 +
  18.242 +    /* Free the pending request. */
  18.243 +    spin_lock_irqsave(&pend_prod_lock, flags);
  18.244 +    pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
  18.245 +    spin_unlock_irqrestore(&pend_prod_lock, flags);
  18.246 +
  18.247 +    rmb();
  18.248 +
  18.249 +    /* Check for anything still waiting in the rings, having freed a request... */
  18.250 +    maybe_trigger_usbio_schedule();
  18.251 +}
  18.252 +
  18.253 +/******************************************************************
  18.254 + * SCHEDULER FUNCTIONS
  18.255 + */
  18.256 +
  18.257 +static DECLARE_WAIT_QUEUE_HEAD(usbio_schedule_wait);
  18.258 +
  18.259 +static int usbio_schedule(void *arg)
  18.260 +{
  18.261 +    DECLARE_WAITQUEUE(wq, current);
  18.262 +
  18.263 +    usbif_priv_t          *up;
  18.264 +    struct list_head *ent;
  18.265 +
  18.266 +    daemonize();
  18.267 +
  18.268 +    for ( ; ; )
  18.269 +    {
  18.270 +        /* Wait for work to do. */
  18.271 +        add_wait_queue(&usbio_schedule_wait, &wq);
  18.272 +        set_current_state(TASK_INTERRUPTIBLE);
  18.273 +        if ( (NR_PENDING_REQS == MAX_PENDING_REQS) || 
  18.274 +             list_empty(&usbio_schedule_list) )
  18.275 +            schedule();
  18.276 +        __set_current_state(TASK_RUNNING);
  18.277 +        remove_wait_queue(&usbio_schedule_wait, &wq);
  18.278 +
  18.279 +        /* Queue up a batch of requests. */
  18.280 +        while ( (NR_PENDING_REQS < MAX_PENDING_REQS) &&
  18.281 +                !list_empty(&usbio_schedule_list) )
  18.282 +        {
  18.283 +            ent = usbio_schedule_list.next;
  18.284 +            up = list_entry(ent, usbif_priv_t, usbif_list);
  18.285 +            usbif_get(up);
  18.286 +            remove_from_usbif_list(up);
  18.287 +            if ( do_usb_io_op(up, BATCH_PER_DOMAIN) )
  18.288 +                add_to_usbif_list_tail(up);
  18.289 +            usbif_put(up);
  18.290 +        }
  18.291 +    }
  18.292 +}
  18.293 +
  18.294 +static void maybe_trigger_usbio_schedule(void)
  18.295 +{
  18.296 +    /*
  18.297 +     * Needed so that two processes, who together make the following predicate
  18.298 +     * true, don't both read stale values and evaluate the predicate
  18.299 +     * incorrectly. Incredibly unlikely to stall the scheduler on x86, but...
  18.300 +     */
  18.301 +    smp_mb();
  18.302 +
  18.303 +    if ( !list_empty(&usbio_schedule_list) )
  18.304 +        wake_up(&usbio_schedule_wait);
  18.305 +}
  18.306 +
  18.307 +
  18.308 +/******************************************************************************
  18.309 + * NOTIFICATION FROM GUEST OS.
  18.310 + */
  18.311 +
  18.312 +irqreturn_t usbif_be_int(int irq, void *dev_id, struct pt_regs *regs)
  18.313 +{
  18.314 +    usbif_priv_t *up = dev_id;
  18.315 +
  18.316 +    smp_mb();
  18.317 +
  18.318 +    add_to_usbif_list_tail(up); 
  18.319 +
  18.320 +    /* Will in fact /always/ trigger an io schedule in this case. */
  18.321 +    maybe_trigger_usbio_schedule();
  18.322 +
  18.323 +    return IRQ_HANDLED;
  18.324 +}
  18.325 +
  18.326 +
  18.327 +
  18.328 +/******************************************************************
  18.329 + * DOWNWARD CALLS -- These interface with the usb-device layer proper.
  18.330 + */
  18.331 +
  18.332 +static int do_usb_io_op(usbif_priv_t *up, int max_to_do)
  18.333 +{
  18.334 +    usbif_t *usb_ring = up->usb_ring_base;
  18.335 +    usbif_request_t *req;
  18.336 +    USBIF_RING_IDX i, rp;
  18.337 +    int more_to_do = 0;
  18.338 +    unsigned long flags;
  18.339 +
  18.340 +    spin_lock_irqsave(&up->usb_ring_lock, flags);
  18.341 +
  18.342 +    rp = usb_ring->req_prod;
  18.343 +    rmb(); /* Ensure we see queued requests up to 'rp'. */
  18.344 +    
  18.345 +    /* Take items off the comms ring, taking care not to overflow. */
  18.346 +    for ( i = up->usb_req_cons; 
  18.347 +          (i != rp) && ((i-up->usb_resp_prod) != USBIF_RING_SIZE);
  18.348 +          i++ )
  18.349 +    {
  18.350 +        if ( (max_to_do-- == 0) || (NR_PENDING_REQS == MAX_PENDING_REQS) )
  18.351 +        {
  18.352 +            more_to_do = 1;
  18.353 +            break;
  18.354 +        }
  18.355 +
  18.356 +        req = &usb_ring->ring[MASK_USBIF_IDX(i)].req;
  18.357 +        
  18.358 +        switch ( req->operation )
  18.359 +        {
  18.360 +        case USBIF_OP_PROBE:
  18.361 +            dispatch_usb_probe(up, req->id, req->port);
  18.362 +            break;
  18.363 +
  18.364 +        case USBIF_OP_IO:
  18.365 +	  /* Assemble an appropriate URB. */
  18.366 +	  dispatch_usb_io(up, req);
  18.367 +          break;
  18.368 +
  18.369 +	case USBIF_OP_RESET:
  18.370 +	  dispatch_usb_reset(up, req->port);
  18.371 +          break;
  18.372 +
  18.373 +        default:
  18.374 +            DPRINTK("error: unknown USB io operation [%d]\n",
  18.375 +                    req->operation);
  18.376 +            make_response(up, req->id, req->operation, -EINVAL, 0, 0);
  18.377 +            break;
  18.378 +        }
  18.379 +    }
  18.380 +
  18.381 +    up->usb_req_cons = i;
  18.382 +
  18.383 +    spin_unlock_irqrestore(&up->usb_ring_lock, flags);
  18.384 +
  18.385 +    return more_to_do;
  18.386 +}
  18.387 +
  18.388 +static owned_port_t *find_guest_port(usbif_priv_t *up, int port)
  18.389 +{
  18.390 +    unsigned long flags;
  18.391 +    struct list_head *l;
  18.392 +
  18.393 +    spin_lock_irqsave(&owned_ports_lock, flags);
  18.394 +    list_for_each(l, &owned_ports)
  18.395 +    {
  18.396 +        owned_port_t *p = list_entry(l, owned_port_t, list);
  18.397 +        if(p->usbif_priv == up && p->guest_port == port)
  18.398 +        {
  18.399 +            spin_unlock_irqrestore(&owned_ports_lock, flags);
  18.400 +            return p;
  18.401 +        }
  18.402 +    }
  18.403 +    spin_unlock_irqrestore(&owned_ports_lock, flags);
  18.404 +
  18.405 +    return NULL;
  18.406 +}
  18.407 +
  18.408 +static void dispatch_usb_reset(usbif_priv_t *up, unsigned long portid)
  18.409 +{
  18.410 +    owned_port_t *port = find_guest_port(up, portid);
  18.411 +    int ret = 0;
  18.412 +
  18.413 +
  18.414 +    /* Allowing the guest to actually reset the device causes more problems
  18.415 +     * than it's worth.  We just fake it out in software but we will do a real
  18.416 +     * reset when the interface is destroyed. */
  18.417 +
  18.418 +#if 0
  18.419 +    printk("Reset port %d\n", portid);
  18.420 +
  18.421 +    dump_port(port);
  18.422 +#endif
  18.423 +
  18.424 +    port->guest_address = 0;
  18.425 +    /* If there's an attached device then the port is now enabled. */
  18.426 +    if ( port->dev_present )
  18.427 +        port->enabled = 1;
  18.428 +    else
  18.429 +        port->enabled = 0;
  18.430 +
  18.431 +    make_response(up, 0, USBIF_OP_RESET, ret, 0, 0);
  18.432 +}
  18.433 +
  18.434 +static void dispatch_usb_probe(usbif_priv_t *up, unsigned long id, unsigned long portid)
  18.435 +{
  18.436 +    owned_port_t *port = find_guest_port(up, portid);
  18.437 +    int ret;
  18.438 + 
  18.439 +    if ( port != NULL )
  18.440 +        ret = port->dev_present;
  18.441 +    else
  18.442 +    {
  18.443 +        ret = -EINVAL;
  18.444 +        printk("dispatch_usb_probe(): invalid port probe request (port %ld)\n",
  18.445 +	       portid);
  18.446 +    }
  18.447 +
  18.448 +    /* Probe result is sent back in-band.  Probes don't have an associated id
  18.449 +     * right now... */
  18.450 +    make_response(up, id, USBIF_OP_PROBE, ret, portid, 0);
  18.451 +}
  18.452 +
  18.453 +owned_port_t *find_port_for_request(usbif_priv_t *up, usbif_request_t *req);
  18.454 +
  18.455 +static void dump_request(usbif_request_t *req)
  18.456 +{    
  18.457 +    printk("id = 0x%lx\n", req->id);
  18.458 +    
  18.459 +	printk("devnum %d\n", req->devnum);
  18.460 +	printk("endpoint 0x%x\n", req->endpoint);
  18.461 +	printk("direction %d\n", req->direction);
  18.462 +	printk("speed %d\n", req->speed);
  18.463 +        printk("pipe_type 0x%x\n", req->pipe_type);
  18.464 +        printk("transfer_buffer 0x%lx\n", req->transfer_buffer);
  18.465 +        printk("length 0x%lx\n", req->length);
  18.466 +        printk("transfer_flags 0x%lx\n", req->transfer_flags);
  18.467 +        printk("setup = { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  18.468 +               req->setup[0], req->setup[1], req->setup[2], req->setup[3],
  18.469 +               req->setup[4], req->setup[5], req->setup[6], req->setup[7]);
  18.470 +        printk("iso_schedule = 0x%lx\n", req->iso_schedule);
  18.471 +        printk("num_iso %ld\n", req->num_iso);
  18.472 +}
  18.473 +
  18.474 +void dump_urb(struct urb *urb)
  18.475 +{
  18.476 +    printk("dumping urb @ %p\n", urb);
  18.477 +
  18.478 +#define DUMP_URB_FIELD(name, format) printk("  " # name " " format "\n", urb-> name)
  18.479 +    
  18.480 +    DUMP_URB_FIELD(pipe, "0x%x");
  18.481 +    DUMP_URB_FIELD(status, "%d");
  18.482 +    DUMP_URB_FIELD(transfer_flags, "0x%x");    
  18.483 +    DUMP_URB_FIELD(transfer_buffer, "%p");
  18.484 +    DUMP_URB_FIELD(transfer_buffer_length, "%d");
  18.485 +    DUMP_URB_FIELD(actual_length, "%d");
  18.486 +}
  18.487 +
  18.488 +
  18.489 +static void dispatch_usb_io(usbif_priv_t *up, usbif_request_t *req)
  18.490 +{
  18.491 +    unsigned long buffer_mach;
  18.492 +    int i = 0, offset = 0,
  18.493 +        pending_idx = pending_ring[MASK_PEND_IDX(pending_cons)];
  18.494 +    pending_req_t *pending_req;
  18.495 +    unsigned long  remap_prot;
  18.496 +    multicall_entry_t mcl[MMAP_PAGES_PER_REQUEST];
  18.497 +    struct urb *purb = NULL;
  18.498 +    owned_port_t *port;
  18.499 +    unsigned char *setup;    
  18.500 +
  18.501 +//    dump_request(req);
  18.502 +
  18.503 +    if ( NR_PENDING_REQS == MAX_PENDING_REQS )
  18.504 +    {
  18.505 +        printk("usbback: Max requests already queued.  Now giving up!\n");
  18.506 +        
  18.507 +        return;
  18.508 +    }
  18.509 +
  18.510 +    port = find_port_for_request(up, req);
  18.511 +
  18.512 +    if(port == NULL)
  18.513 +    {
  18.514 +	printk("No such device! (%d)\n", req->devnum);
  18.515 +	dump_request(req);
  18.516 +
  18.517 +        make_response(up, req->id, req->operation, -ENODEV, 0, 0);
  18.518 +	return;
  18.519 +    }
  18.520 +
  18.521 +    setup = kmalloc(8, GFP_ATOMIC | GFP_NOIO);
  18.522 +
  18.523 +    if ( setup == NULL )
  18.524 +        goto no_mem;
  18.525 +   
  18.526 +    /* Copy request out for safety. */
  18.527 +    memcpy(setup, req->setup, 8);
  18.528 +
  18.529 +    if( setup[0] == 0x0 && setup[1] == 0x5)
  18.530 +    {
  18.531 +        /* To virtualise the USB address space, we need to intercept
  18.532 +         * set_address messages and emulate.  From the USB specification:
  18.533 +         * bmRequestType = 0x0;
  18.534 +         * Brequest = SET_ADDRESS (i.e. 0x5)
  18.535 +         * wValue = device address
  18.536 +         * wIndex = 0
  18.537 +         * wLength = 0
  18.538 +         * data = None
  18.539 +         */
  18.540 +        /* Store into the guest transfer buffer using cpu_to_le16 */
  18.541 +        port->guest_address = le16_to_cpu(*(u16 *)(setup + 2));
  18.542 +        /* Make a successful response.  That was easy! */
  18.543 +
  18.544 +        make_response(up, req->id, req->operation, 0, 0, 0);
  18.545 +
  18.546 +	kfree(setup);
  18.547 +        return;
  18.548 +    }
  18.549 +    else if ( setup[0] == 0x0 && setup[1] == 0x9 )
  18.550 +    {
  18.551 +        /* The host kernel needs to know what device configuration is in use
  18.552 +         * because various error checks get confused otherwise.  We just do
  18.553 +         * configuration settings here, under controlled conditions.
  18.554 +         */
  18.555 +        usb_set_configuration(port->dev, setup[2]);
  18.556 +
  18.557 +        make_response(up, req->id, req->operation, 0, 0, 0);
  18.558 +
  18.559 +        kfree(setup);
  18.560 +        return;
  18.561 +    }
  18.562 +
  18.563 +    else if ( setup[0] == 0x1 && setup[1] == 0xB )
  18.564 +    {
  18.565 +        /* The host kernel needs to know what device interface is in use
  18.566 +         * because various error checks get confused otherwise.  We just do
  18.567 +         * configuration settings here, under controlled conditions.
  18.568 +         */
  18.569 +        usb_set_interface(port->dev, (setup[4] | setup[5] << 8),
  18.570 +                          (setup[2] | setup[3] << 8) );
  18.571 +
  18.572 +        make_response(up, req->id, req->operation, 0, 0, 0);
  18.573 +
  18.574 +        kfree(setup);
  18.575 +        return;
  18.576 +    }
  18.577 +
  18.578 +    if ( ( req->transfer_buffer - (req->transfer_buffer & PAGE_MASK)
  18.579 +	   + req->length )
  18.580 +	 > MMAP_PAGES_PER_REQUEST * PAGE_SIZE )
  18.581 +    {
  18.582 +        printk("usbback: request of %d bytes too large, failing it\n", req->length);
  18.583 +        make_response(up, req->id, req->operation, -EINVAL, 0, 0);
  18.584 +        kfree(setup);
  18.585 +        return;
  18.586 +    }
  18.587 +    
  18.588 +    buffer_mach = req->transfer_buffer;
  18.589 +
  18.590 +    if( buffer_mach == 0 )
  18.591 +	goto no_remap;
  18.592 +
  18.593 +    ASSERT((req->length >> PAGE_SHIFT) <= MMAP_PAGES_PER_REQUEST);
  18.594 +    ASSERT(buffer_mach);
  18.595 +
  18.596 +    /* Always map writeable for now. */
  18.597 +    remap_prot = _PAGE_PRESENT|_PAGE_DIRTY|_PAGE_ACCESSED|_PAGE_RW;
  18.598 +
  18.599 +    for ( i = 0, offset = 0; offset < req->length;
  18.600 +          i++, offset += PAGE_SIZE )
  18.601 +    {
  18.602 +      //        printk("length = %d, offset = %d, looping!\n", req->length, offset);
  18.603 +        
  18.604 +	mcl[i].op = __HYPERVISOR_update_va_mapping_otherdomain;
  18.605 +	mcl[i].args[0] = MMAP_VADDR(pending_idx, i) >> PAGE_SHIFT;
  18.606 +        mcl[i].args[1] = ((buffer_mach & PAGE_MASK) + offset) | remap_prot;
  18.607 +        mcl[i].args[2] = 0;
  18.608 +        mcl[i].args[3] = up->domid;
  18.609 +        
  18.610 +        phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] =
  18.611 +            FOREIGN_FRAME((buffer_mach + offset) >> PAGE_SHIFT);
  18.612 +	//	printk("i = %d\n", i);
  18.613 +
  18.614 +        ASSERT(virt_to_machine(MMAP_VADDR(pending_idx, i))
  18.615 +               == buffer_mach + i << PAGE_SHIFT);
  18.616 +    }
  18.617 +
  18.618 +    if ( req->pipe_type == 0 && req->num_iso > 0 ) /* Maybe schedule ISO... */
  18.619 +    {
  18.620 +      //      printk("for iso, i = %d\n", i);
  18.621 +        /* Map in ISO schedule, if necessary. */
  18.622 +        mcl[i].op = __HYPERVISOR_update_va_mapping_otherdomain;
  18.623 +        mcl[i].args[0] = MMAP_VADDR(pending_idx, i) >> PAGE_SHIFT;
  18.624 +        mcl[i].args[1] = (req->iso_schedule & PAGE_MASK) | remap_prot;
  18.625 +        mcl[i].args[2] = 0;
  18.626 +        mcl[i].args[3] = up->domid;
  18.627 +
  18.628 +        phys_to_machine_mapping[__pa(MMAP_VADDR(pending_idx, i))>>PAGE_SHIFT] =
  18.629 +            FOREIGN_FRAME(req->iso_schedule >> PAGE_SHIFT);
  18.630 +    
  18.631 +        //    printk("Mapped iso at %p\n", MMAP_VADDR(pending_idx, i));
  18.632 +        i++;
  18.633 +    }
  18.634 +
  18.635 +    //    printk("Well we got this far!\n");
  18.636 +
  18.637 +    if ( unlikely(HYPERVISOR_multicall(mcl, i) != 0) )
  18.638 +        BUG();
  18.639 +    
  18.640 +    {
  18.641 +        int j;
  18.642 +        for ( j = 0; j < i; j++ )
  18.643 +        {
  18.644 +            if ( unlikely(mcl[j].args[5] != 0) )
  18.645 +            {
  18.646 +                printk("invalid buffer %d -- could not remap it\n", j);
  18.647 +                fast_flush_area(pending_idx, i);
  18.648 +		printk("sending invalid descriptor\n");
  18.649 +                goto bad_descriptor;
  18.650 +            }
  18.651 +	}
  18.652 +    }
  18.653 +    
  18.654 + no_remap:
  18.655 +
  18.656 +    ASSERT(i <= MMAP_PAGES_PER_REQUEST);
  18.657 +    ASSERT(i * PAGE_SIZE >= req->length);
  18.658 +
  18.659 +    /* We have to do this because some things might complete out of order. */
  18.660 +    pending_req = &pending_reqs[pending_idx];
  18.661 +    pending_req->usbif_priv= up;
  18.662 +    pending_req->id        = req->id;
  18.663 +    pending_req->operation = req->operation;
  18.664 +    pending_req->nr_pages  = i;
  18.665 +
  18.666 +
  18.667 +
  18.668 +    pending_cons++;
  18.669 +
  18.670 +    usbif_get(up);
  18.671 +    
  18.672 +    /* Fill out an actual request for the USB layer. */
  18.673 +    purb = usb_alloc_urb(req->num_iso);
  18.674 +
  18.675 +    if ( purb == NULL )
  18.676 +        goto no_mem;
  18.677 +
  18.678 +    purb->dev = port->dev;
  18.679 +    purb->context = pending_req;
  18.680 +    purb->transfer_buffer = (void *)MMAP_VADDR(pending_idx, 0) + (buffer_mach & ~PAGE_MASK);
  18.681 +    if(buffer_mach == 0)
  18.682 +      purb->transfer_buffer = NULL;
  18.683 +    purb->complete = __end_usb_io_op;
  18.684 +    purb->transfer_buffer_length = req->length;
  18.685 +    purb->transfer_flags = req->transfer_flags;
  18.686 +
  18.687 +/*     if ( req->transfer_flags != 0 ) */
  18.688 +/*       dump_request(req); */
  18.689 +
  18.690 +    purb->pipe = 0;
  18.691 +    purb->pipe |= req->direction << 7;
  18.692 +    purb->pipe |= port->dev->devnum << 8;
  18.693 +    purb->pipe |= req->speed << 26;
  18.694 +    purb->pipe |= req->pipe_type << 30;
  18.695 +    purb->pipe |= req->endpoint << 15;
  18.696 +
  18.697 +    purb->number_of_packets = req->num_iso;
  18.698 +
  18.699 +    /* Make sure there's always some kind of timeout. */
  18.700 +    purb->timeout = ( req->timeout > 0 ) ?  (req->timeout * HZ) / 1000
  18.701 +                    :  1000;
  18.702 +
  18.703 +    purb->setup_packet = setup;
  18.704 +
  18.705 +    if ( req->pipe_type == 0 ) /* ISO */
  18.706 +    {
  18.707 +        int j;
  18.708 +        usbif_iso_t *iso_sched = (usbif_iso_t *)MMAP_VADDR(pending_idx, i - 1);
  18.709 +
  18.710 +	//	printk("Reading iso sched at %p\n", iso_sched);
  18.711 +
  18.712 +        /* If we're dealing with an iso pipe, we need to copy in a schedule. */
  18.713 +        for ( j = 0; j < req->num_iso; j++ )
  18.714 +        {
  18.715 +            purb->iso_frame_desc[j].length = iso_sched[j].length;
  18.716 +            purb->iso_frame_desc[j].offset = iso_sched[j].buffer_offset;
  18.717 +            iso_sched[j].status = 0;
  18.718 +        }
  18.719 +        pending_req->iso_sched = iso_sched;
  18.720 +    }
  18.721 +
  18.722 +    {
  18.723 +      int ret;
  18.724 +      ret = usb_submit_urb(purb);
  18.725 +
  18.726 +      //      dump_urb(purb);
  18.727 +
  18.728 +      if ( ret != 0 )
  18.729 +          goto bad_descriptor; /* XXX free pending here! */
  18.730 +    }
  18.731 +    
  18.732 +    return;
  18.733 +
  18.734 + bad_descriptor:
  18.735 +    kfree ( setup );
  18.736 +    if ( purb != NULL )
  18.737 +        usb_free_urb(purb);
  18.738 +    make_response(up, req->id, req->operation, -EINVAL, 0, 0);
  18.739 +    return;
  18.740 +    
  18.741 + no_mem:
  18.742 +    if ( setup != NULL )
  18.743 +        kfree(setup);
  18.744 +    make_response(up, req->id, req->operation, -ENOMEM, 0, 0);
  18.745 +    return;
  18.746 +} 
  18.747 +
  18.748 +
  18.749 +
  18.750 +/******************************************************************
  18.751 + * MISCELLANEOUS SETUP / TEARDOWN / DEBUGGING
  18.752 + */
  18.753 +
  18.754 +
  18.755 +static void make_response(usbif_priv_t *up, unsigned long id,
  18.756 +                          unsigned short op, int st, int inband,
  18.757 +			  unsigned long length)
  18.758 +{
  18.759 +    usbif_response_t *resp;
  18.760 +    unsigned long     flags;
  18.761 +
  18.762 +#if 0
  18.763 +    printk("usbback: Sending response:\n");
  18.764 +    printk("         id = 0x%x\n", id);
  18.765 +    printk("         op = %d\n", op);
  18.766 +    printk("         status = %d\n", st);
  18.767 +    printk("         data = %d\n", inband);
  18.768 +    printk("         length = %d\n", length);
  18.769 +#endif
  18.770 +
  18.771 +    /* Place on the response ring for the relevant domain. */ 
  18.772 +    spin_lock_irqsave(&up->usb_ring_lock, flags);
  18.773 +    resp = &up->usb_ring_base->
  18.774 +        ring[MASK_USBIF_IDX(up->usb_resp_prod)].resp;
  18.775 +    resp->id        = id;
  18.776 +    resp->operation = op;
  18.777 +    resp->status    = st;
  18.778 +    resp->data      = inband;
  18.779 +    resp->length = length;
  18.780 +    wmb(); /* Ensure other side can see the response fields. */
  18.781 +    up->usb_ring_base->resp_prod = ++up->usb_resp_prod;
  18.782 +    spin_unlock_irqrestore(&up->usb_ring_lock, flags);
  18.783 +
  18.784 +    /* Kick the relevant domain. */
  18.785 +    notify_via_evtchn(up->evtchn);
  18.786 +}
  18.787 +
  18.788 +/**
  18.789 + * usbif_claim_port - claim devices on a port on behalf of guest
  18.790 + *
  18.791 + * Once completed, this will ensure that any device attached to that
  18.792 + * port is claimed by this driver for use by the guest.
  18.793 + */
  18.794 +int usbif_claim_port(usbif_be_claim_port_t *msg)
  18.795 +{
  18.796 +    owned_port_t *o_p;
  18.797 +    
  18.798 +    /* Sanity... */
  18.799 +    if ( usbif_find_port(msg->path) != NULL )
  18.800 +    {
  18.801 +        printk("usbback: Attempted to claim USB port "
  18.802 +               "we already own!\n");
  18.803 +        return -EINVAL;
  18.804 +    }
  18.805 +
  18.806 +    spin_lock_irq(&owned_ports_lock);
  18.807 +    
  18.808 +    /* No need for a slab cache - this should be infrequent. */
  18.809 +    o_p = kmalloc(sizeof(owned_port_t), GFP_KERNEL);
  18.810 +
  18.811 +    o_p->enabled = 0;
  18.812 +    o_p->usbif_priv = usbif_find(msg->domid);
  18.813 +    o_p->guest_port = msg->usbif_port;
  18.814 +    o_p->dev_present = 0;
  18.815 +    o_p->guest_address = 0; /* Default address. */
  18.816 +
  18.817 +    strcpy(o_p->path, msg->path);
  18.818 +
  18.819 +    list_add(&o_p->list, &owned_ports);
  18.820 +
  18.821 +    printk("usbback: Claimed USB port (%s) for %d.%d\n", o_p->path,
  18.822 +	   msg->domid, msg->usbif_port);
  18.823 +
  18.824 +    spin_unlock_irq(&owned_ports_lock);
  18.825 +
  18.826 +    /* Force a reprobe for unclaimed devices. */
  18.827 +    usb_scan_devices();
  18.828 +
  18.829 +    return 0;
  18.830 +}
  18.831 +
  18.832 +owned_port_t *find_port_for_request(usbif_priv_t *up, usbif_request_t *req)
  18.833 +{
  18.834 +    unsigned long flags;
  18.835 +    struct list_head *port;
  18.836 +
  18.837 +    /* I'm assuming this is not called from IRQ context - correct?  I think
  18.838 +     * it's probably only called in response to control messages or plug events
  18.839 +     * in the USB hub kernel thread, so should be OK. */
  18.840 +    spin_lock_irqsave(&owned_ports_lock, flags);
  18.841 +    list_for_each(port, &owned_ports)
  18.842 +    {
  18.843 +        owned_port_t *p = list_entry(port, owned_port_t, list);
  18.844 +        if(p->usbif_priv == up && p->guest_address == req->devnum && p->enabled )
  18.845 +	  {
  18.846 +#if 0
  18.847 +              printk("Found port for devnum %d\n", req->devnum);
  18.848 +
  18.849 +              dump_port(p);
  18.850 +#endif
  18.851 +              return p;
  18.852 +	  }
  18.853 +    }
  18.854 +    spin_unlock_irqrestore(&owned_ports_lock, flags);
  18.855 +
  18.856 +    return NULL;    
  18.857 +}
  18.858 +
  18.859 +owned_port_t *usbif_find_port(char *path)
  18.860 +{
  18.861 +    struct list_head *port;
  18.862 +    unsigned long flags;
  18.863 +
  18.864 +    spin_lock_irqsave(&owned_ports_lock, flags);
  18.865 +    list_for_each(port, &owned_ports)
  18.866 +    {
  18.867 +        owned_port_t *p = list_entry(port, owned_port_t, list);
  18.868 +        if(!strcmp(path, p->path))
  18.869 +        {
  18.870 +            spin_unlock_irqrestore(&owned_ports_lock, flags);
  18.871 +            return p;
  18.872 +        }
  18.873 +    }
  18.874 +    spin_unlock_irqrestore(&owned_ports_lock, flags);
  18.875 +
  18.876 +    return NULL;
  18.877 +}
  18.878 +
  18.879 +
  18.880 +static void *probe(struct usb_device *dev, unsigned iface,
  18.881 +	    const struct usb_device_id *id)
  18.882 +{
  18.883 +    owned_port_t *p;
  18.884 +
  18.885 +    /* We don't care what the device is - if we own the port, we want it.  We
  18.886 +     * don't deal with device-specifics in this driver, so we don't care what
  18.887 +     * the device actually is ;-) */
  18.888 +    if ( ( p = usbif_find_port(dev->devpath) ) != NULL )
  18.889 +    {
  18.890 +        printk("usbback: claimed device attached to owned port\n");
  18.891 +
  18.892 +        p->dev_present = 1;
  18.893 +        p->dev = dev;
  18.894 +        set_bit(iface, &p->ifaces);
  18.895 +        
  18.896 +        return p->usbif_priv;
  18.897 +    }
  18.898 +    else
  18.899 +        printk("usbback: hotplug for non-owned port (%s), ignoring\n", dev->devpath);
  18.900 +   
  18.901 +
  18.902 +    return NULL;
  18.903 +}
  18.904 +
  18.905 +static void disconnect(struct usb_device *dev, void *usbif)
  18.906 +{
  18.907 +    /* Note the device is removed so we can tell the guest when it probes. */
  18.908 +    owned_port_t *port = usbif_find_port(dev->devpath);
  18.909 +    port->dev_present = 0;
  18.910 +    port->dev = NULL;
  18.911 +    port->ifaces = 0;
  18.912 +}
  18.913 +
  18.914 +
  18.915 +struct usb_driver driver =
  18.916 +{
  18.917 +    .owner      = THIS_MODULE,
  18.918 +    .name       = "Xen USB Backend",
  18.919 +    .probe      = probe,
  18.920 +    .disconnect = disconnect,
  18.921 +    .id_table   = NULL,
  18.922 +};
  18.923 +
  18.924 +/* __usbif_release_port - internal mechanics for releasing a port */
  18.925 +void __usbif_release_port(owned_port_t *p)
  18.926 +{
  18.927 +    int i;
  18.928 +
  18.929 +    for ( i = 0; p->ifaces != 0; i++)
  18.930 +        if ( p->ifaces & 1 << i )
  18.931 +        {
  18.932 +            usb_driver_release_interface(&driver, usb_ifnum_to_if(p->dev, i));
  18.933 +            clear_bit(i, &p->ifaces);
  18.934 +        }
  18.935 +    list_del(&p->list);
  18.936 +
  18.937 +    /* Reset the real device.  We don't simulate disconnect / probe for other
  18.938 +     * drivers in this kernel because we assume the device is completely under
  18.939 +     * the control of ourselves (i.e. the guest!).  This should ensure that the
  18.940 +     * device is in a sane state for the next customer ;-) */
  18.941 +/*     if ( p->dev != NULL) */
  18.942 +/*         usb_reset_device(p->dev); */
  18.943 +
  18.944 +    kfree(p);
  18.945 +}
  18.946 +
  18.947 +
  18.948 +/**
  18.949 + * usbif_release_port - stop claiming devices on a port on behalf of guest
  18.950 + */
  18.951 +void usbif_release_port(usbif_be_release_port_t *msg)
  18.952 +{
  18.953 +    owned_port_t *p;
  18.954 +
  18.955 +    spin_lock_irq(&owned_ports_lock);
  18.956 +    p = usbif_find_port(msg->path);
  18.957 +    __usbif_release_port(p);
  18.958 +    spin_unlock_irq(&owned_ports_lock);
  18.959 +}
  18.960 +
  18.961 +void usbif_release_ports(usbif_priv_t *up)
  18.962 +{
  18.963 +    struct list_head *port, *tmp;
  18.964 +    unsigned long flags;
  18.965 +    
  18.966 +    spin_lock_irqsave(&owned_ports_lock, flags);
  18.967 +    list_for_each_safe(port, tmp, &owned_ports)
  18.968 +    {
  18.969 +        owned_port_t *p = list_entry(port, owned_port_t, list);
  18.970 +        if ( p->usbif_priv == up )
  18.971 +            __usbif_release_port(p);
  18.972 +    }
  18.973 +    spin_unlock_irqrestore(&owned_ports_lock, flags);
  18.974 +}
  18.975 +
  18.976 +static int __init usbif_init(void)
  18.977 +{
  18.978 +    int i;
  18.979 +
  18.980 +    if ( !(xen_start_info.flags & SIF_INITDOMAIN) &&
  18.981 +         !(xen_start_info.flags & SIF_USB_BE_DOMAIN) )
  18.982 +        return 0;
  18.983 +    
  18.984 +    INIT_LIST_HEAD(&owned_ports);
  18.985 +
  18.986 +    usb_register(&driver);
  18.987 +
  18.988 +    usbif_interface_init();
  18.989 +
  18.990 +    if ( (mmap_vstart = allocate_empty_lowmem_region(MMAP_PAGES)) == 0 )
  18.991 +        BUG();
  18.992 +
  18.993 +    pending_cons = 0;
  18.994 +    pending_prod = MAX_PENDING_REQS;
  18.995 +    memset(pending_reqs, 0, sizeof(pending_reqs));
  18.996 +    for ( i = 0; i < MAX_PENDING_REQS; i++ )
  18.997 +        pending_ring[i] = i;
  18.998 +
  18.999 +    spin_lock_init(&usbio_schedule_list_lock);
 18.1000 +    INIT_LIST_HEAD(&usbio_schedule_list);
 18.1001 +
 18.1002 +    if ( kernel_thread(usbio_schedule, 0, CLONE_FS | CLONE_FILES) < 0 )
 18.1003 +        BUG();
 18.1004 +    
 18.1005 +    usbif_ctrlif_init();
 18.1006 +
 18.1007 +    spin_lock_init(&owned_ports_lock);
 18.1008 +
 18.1009 +    printk("Xen USB Backend Initialised");
 18.1010 +
 18.1011 +    return 0;
 18.1012 +}
 18.1013 +
 18.1014 +__initcall(usbif_init);
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/Makefile	Sat Jan 22 15:52:51 2005 +0000
    19.3 @@ -0,0 +1,3 @@
    19.4 +O_TARGET := drv.o
    19.5 +obj-y := main.o
    19.6 +include $(TOPDIR)/Rules.make
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/main.c	Sat Jan 22 15:52:51 2005 +0000
    20.3 @@ -0,0 +1,1720 @@
    20.4 +/*
    20.5 + * Xen Virtual USB Frontend Driver 
    20.6 + *
    20.7 + * This file contains the first version of the Xen virtual USB hub
    20.8 + * that I've managed not to delete by mistake (3rd time lucky!).
    20.9 + *
   20.10 + * Based on Linux's uhci.c, original copyright notices are displayed
   20.11 + * below.  Portions also (c) 2004 Intel Research Cambridge
   20.12 + * and (c) 2004 Mark Williamson
   20.13 + *
   20.14 + * Contact <mark.williamson@cl.cam.ac.uk> or
   20.15 + * <xen-devel@lists.sourceforge.net> regarding this code.
   20.16 + *
   20.17 + * Still to be (maybe) implemented:
   20.18 + * - multiple port
   20.19 + * - multiple interfaces
   20.20 + * - migration / backend restart support?
   20.21 + * - unloading support
   20.22 + *
   20.23 + * Differences to a normal host controller:
   20.24 + * - the backend does most of the mucky stuff so we don't have to do various
   20.25 + *   things that are necessary for a normal host controller (e.g. FSBR).
   20.26 + * - we don't have any hardware, so status registers are simulated in software.
   20.27 + */
   20.28 +
   20.29 +/*
   20.30 + * Universal Host Controller Interface driver for USB.
   20.31 + *
   20.32 + * Maintainer: Johannes Erdfelt <johannes@erdfelt.com>
   20.33 + *
   20.34 + * (C) Copyright 1999 Linus Torvalds
   20.35 + * (C) Copyright 1999-2002 Johannes Erdfelt, johannes@erdfelt.com
   20.36 + * (C) Copyright 1999 Randy Dunlap
   20.37 + * (C) Copyright 1999 Georg Acher, acher@in.tum.de
   20.38 + * (C) Copyright 1999 Deti Fliegl, deti@fliegl.de
   20.39 + * (C) Copyright 1999 Thomas Sailer, sailer@ife.ee.ethz.ch
   20.40 + * (C) Copyright 1999 Roman Weissgaerber, weissg@vienna.at
   20.41 + * (C) Copyright 2000 Yggdrasil Computing, Inc. (port of new PCI interface
   20.42 + *               support from usb-ohci.c by Adam Richter, adam@yggdrasil.com).
   20.43 + * (C) Copyright 1999 Gregory P. Smith (from usb-ohci.c)
   20.44 + *
   20.45 + * Intel documents this fairly well, and as far as I know there
   20.46 + * are no royalties or anything like that, but even so there are
   20.47 + * people who decided that they want to do the same thing in a
   20.48 + * completely different way.
   20.49 + *
   20.50 + * WARNING! The USB documentation is downright evil. Most of it
   20.51 + * is just crap, written by a committee. You're better off ignoring
   20.52 + * most of it, the important stuff is:
   20.53 + *  - the low-level protocol (fairly simple but lots of small details)
   20.54 + *  - working around the horridness of the rest
   20.55 + */
   20.56 +
   20.57 +#include <linux/config.h>
   20.58 +#include <linux/module.h>
   20.59 +#include <linux/kernel.h>
   20.60 +#include <linux/init.h>
   20.61 +#include <linux/delay.h>
   20.62 +#include <linux/ioport.h>
   20.63 +#include <linux/sched.h>
   20.64 +#include <linux/slab.h>
   20.65 +#include <linux/smp_lock.h>
   20.66 +#include <linux/errno.h>
   20.67 +#include <linux/unistd.h>
   20.68 +#include <linux/interrupt.h>
   20.69 +#include <linux/spinlock.h>
   20.70 +#ifdef CONFIG_USB_DEBUG
   20.71 +#define DEBUG
   20.72 +#else
   20.73 +#undef DEBUG
   20.74 +#endif
   20.75 +#include <linux/usb.h>
   20.76 +
   20.77 +#include <asm/uaccess.h>
   20.78 +#include <asm/irq.h>
   20.79 +#include <asm/system.h>
   20.80 +
   20.81 +#include "xhci.h"
   20.82 +
   20.83 +#include <linux/pm.h>
   20.84 +
   20.85 +#include "../../../../../drivers/usb/hcd.h"
   20.86 +
   20.87 +#include "../usbif.h"
   20.88 +#include <asm/ctrl_if.h>
   20.89 +#include <asm/xen-public/io/domain_controller.h>
   20.90 +
   20.91 +/*
   20.92 + * Version Information
   20.93 + */
   20.94 +#define DRIVER_VERSION "v1.0"
   20.95 +#define DRIVER_AUTHOR "Linus 'Frodo Rabbit' Torvalds, Johannes Erdfelt, Randy Dunlap, Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber, Mark Williamson"
   20.96 +#define DRIVER_DESC "Xen Virtual USB Host Controller Interface driver"
   20.97 +
   20.98 +/*
   20.99 + * debug = 0, no debugging messages
  20.100 + * debug = 1, dump failed URB's except for stalls
  20.101 + * debug = 2, dump all failed URB's (including stalls)
  20.102 + */
  20.103 +#ifdef DEBUG
  20.104 +static int debug = 1;
  20.105 +#else
  20.106 +static int debug = 0;
  20.107 +#endif
  20.108 +MODULE_PARM(debug, "i");
  20.109 +MODULE_PARM_DESC(debug, "Debug level");
  20.110 +static char *errbuf;
  20.111 +#define ERRBUF_LEN    (PAGE_SIZE * 8)
  20.112 +
  20.113 +static kmem_cache_t *xhci_up_cachep;	/* urb_priv */
  20.114 +
  20.115 +static int rh_submit_urb(struct urb *urb);
  20.116 +static int rh_unlink_urb(struct urb *urb);
  20.117 +//static int xhci_get_current_frame_number(struct usb_device *dev);
  20.118 +static int xhci_unlink_urb(struct urb *urb);
  20.119 +static void xhci_unlink_generic(struct urb *urb);
  20.120 +static void xhci_call_completion(struct urb *urb);
  20.121 +static void xhci_drain_ring(void);
  20.122 +
  20.123 +#define MAX_URB_LOOP	2048		/* Maximum number of linked URB's */
  20.124 +
  20.125 +struct xhci *xhci;
  20.126 +
  20.127 +enum { USBIF_STATE_CONNECTED = 2,
  20.128 +       USBIF_STATE_DISCONNECTED = 1,
  20.129 +       USBIF_STATE_CLOSED =0
  20.130 +};
  20.131 +
  20.132 +static int awaiting_reset = 0;
  20.133 +
  20.134 +/**
  20.135 + * xhci_construct_isoc - add isochronous information to a request
  20.136 + */
  20.137 +int xhci_construct_isoc(usbif_request_t *req, struct urb *urb)
  20.138 +{
  20.139 +        usbif_iso_t *schedule;
  20.140 +        int i;
  20.141 +        struct urb_priv *urb_priv = urb->hcpriv;
  20.142 +        
  20.143 +        req->num_iso = urb->number_of_packets;
  20.144 +        schedule = (usbif_iso_t *)__get_free_page(GFP_KERNEL);
  20.145 +
  20.146 +        if ( schedule == NULL )
  20.147 +            return -ENOMEM;
  20.148 +
  20.149 +        for ( i = 0; i < req->num_iso; i++ )
  20.150 +        {
  20.151 +                schedule[i].buffer_offset = urb->iso_frame_desc[i].offset;
  20.152 +                schedule[i].length = urb->iso_frame_desc[i].length;
  20.153 +        }
  20.154 +
  20.155 +        urb_priv->schedule = schedule;
  20.156 +	req->iso_schedule = virt_to_machine(schedule);
  20.157 +
  20.158 +        return 0;
  20.159 +}
  20.160 +
  20.161 +#define USBIF_RING_FULL ((xhci->usbif->req_prod - xhci->usb_resp_cons) == USBIF_RING_SIZE)
  20.162 +
  20.163 +static void dump_urb(struct urb *urb)
  20.164 +{
  20.165 +        printk("dumping urb @ %p\n", urb);
  20.166 +        
  20.167 +        printk("hcpriv = %p\n", urb->hcpriv);
  20.168 +        printk("next = %p\n", urb->next);
  20.169 +        printk("dev = %p\n", urb->dev);
  20.170 +        printk("pipe = 0x%lx\n", urb->pipe);
  20.171 +        printk("status = %d\n", urb->status);
  20.172 +        printk("transfer_flags = 0x%lx\n", urb->transfer_flags);
  20.173 +        printk("transfer_buffer = %p\n", urb->transfer_buffer);
  20.174 +        printk("transfer_buffer_length = %d\n", urb->transfer_buffer_length);
  20.175 +        printk("actual_length = %d\n", urb->actual_length);
  20.176 +        printk("bandwidth = %d\n", urb->bandwidth);
  20.177 +        printk("setup_packet = %p\n", urb->setup_packet);
  20.178 +	if ( urb->setup_packet != NULL )
  20.179 +	          printk("setup = { 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n",
  20.180 +               urb->setup_packet[0], urb->setup_packet[1], urb->setup_packet[2], urb->setup_packet[3],
  20.181 +               urb->setup_packet[4], urb->setup_packet[5], urb->setup_packet[6], urb->setup_packet[7]);
  20.182 +        printk("complete = %p\n", urb->complete);
  20.183 +        printk("interval = %d\n", urb->interval);
  20.184 +        
  20.185 +}
  20.186 +
  20.187 +
  20.188 +static int
  20.189 +xhci_queue_req(struct urb *urb)
  20.190 +{
  20.191 +        usbif_request_t *req;
  20.192 +        usbif_t *usbif = xhci->usbif;
  20.193 +
  20.194 +#if 0
  20.195 +        printk("usbif = %p, req_prod = %d (@ 0x%lx), resp_prod = %d, resp_cons = %d\n",
  20.196 +               usbif, usbif->req_prod, virt_to_machine(&usbif->req_prod),
  20.197 +               usbif->resp_prod, xhci->usb_resp_cons);
  20.198 +#endif
  20.199 +        
  20.200 +
  20.201 +/* 	printk("Usbif_priv %p, want IO at 0x%lx\n", urb->hcpriv, virt_to_machine(urb->transfer_buffer)); */
  20.202 +
  20.203 +        if ( USBIF_RING_FULL )
  20.204 +        {
  20.205 +                printk("xhci_queue_req(): USB ring full, not queuing request\n");
  20.206 +                return -ENOBUFS;
  20.207 +        }
  20.208 +
  20.209 +        /* Stick something in the shared communications ring. */
  20.210 +        req = &usbif->ring[MASK_USBIF_IDX(usbif->req_prod)].req;
  20.211 +
  20.212 +        req->operation       = USBIF_OP_IO;
  20.213 +        req->port            = 0; /* We don't care what the port is. */
  20.214 +        req->id              = (unsigned long) urb->hcpriv;
  20.215 +        req->transfer_buffer = virt_to_machine(urb->transfer_buffer);
  20.216 +	req->devnum          = usb_pipedevice(urb->pipe);
  20.217 +        req->direction       = usb_pipein(urb->pipe);
  20.218 +	req->speed           = usb_pipeslow(urb->pipe);
  20.219 +        req->pipe_type       = usb_pipetype(urb->pipe);
  20.220 +        req->length          = urb->transfer_buffer_length;
  20.221 +        req->transfer_flags  = urb->transfer_flags;
  20.222 +	req->endpoint        = usb_pipeendpoint(urb->pipe);
  20.223 +	req->speed           = usb_pipeslow(urb->pipe);
  20.224 +	req->timeout         = urb->timeout * (1000 / HZ);
  20.225 +
  20.226 +        if ( usb_pipetype(urb->pipe) == 0 ) /* ISO */
  20.227 +        {
  20.228 +            int ret = xhci_construct_isoc(req, urb);
  20.229 +            if ( ret != 0 )
  20.230 +                return ret;
  20.231 +        }
  20.232 +
  20.233 +	if(urb->setup_packet != NULL)
  20.234 +                memcpy(req->setup, urb->setup_packet, 8);
  20.235 +        else
  20.236 +                memset(req->setup, 0, 8);
  20.237 +        
  20.238 +        wmb();
  20.239 +
  20.240 +        usbif->req_prod++;
  20.241 +
  20.242 +	notify_via_evtchn(xhci->evtchn);
  20.243 +
  20.244 +	//	dump_urb(urb);
  20.245 +
  20.246 +        return -EINPROGRESS;
  20.247 +}
  20.248 +
  20.249 +static inline usbif_request_t *
  20.250 +xhci_queue_probe(usbif_vdev_t port)
  20.251 +{
  20.252 +        usbif_request_t *req;
  20.253 +        usbif_t *usbif = xhci->usbif;
  20.254 +
  20.255 +#if 0
  20.256 +	printk("queuing probe: req_prod = %d (@ 0x%lx), resp_prod = %d, resp_cons = %d\n",
  20.257 +	       usbif->req_prod, virt_to_machine(&usbif->req_prod),
  20.258 +	       usbif->resp_prod, xhci->usb_resp_cons);
  20.259 +#endif
  20.260 +        
  20.261 +        if ( USBIF_RING_FULL )
  20.262 +        {
  20.263 +                printk("xhci_queue_probe(): USB ring full, not queuing request\n");
  20.264 +                return NULL;
  20.265 +        }
  20.266 +
  20.267 +        /* Stick something in the shared communications ring. */
  20.268 +        req = &usbif->ring[MASK_USBIF_IDX(usbif->req_prod)].req;
  20.269 +
  20.270 +        req->operation       = USBIF_OP_PROBE;
  20.271 +        req->port            = port;
  20.272 +        req->id              = 0;
  20.273 +        req->transfer_buffer = 0;
  20.274 +	req->devnum          = 0;
  20.275 +        req->direction       = 0;
  20.276 +	req->speed           = 0;
  20.277 +        req->pipe_type       = 0;
  20.278 +        req->length          = 0;
  20.279 +        req->transfer_flags  = 0;
  20.280 +	req->endpoint        = 0;
  20.281 +	req->speed           = 0;
  20.282 +
  20.283 +        wmb();
  20.284 +
  20.285 +        usbif->req_prod++;
  20.286 +
  20.287 +	notify_via_evtchn(xhci->evtchn);
  20.288 +
  20.289 +        return req;
  20.290 +}
  20.291 +
  20.292 +static int
  20.293 +xhci_port_reset(usbif_vdev_t port)
  20.294 +{
  20.295 +        usbif_request_t *req;
  20.296 +        usbif_t *usbif = xhci->usbif;
  20.297 +
  20.298 +        /* We only reset one port at a time, so we only need one variable per
  20.299 +         * hub. */
  20.300 +        awaiting_reset = 1;
  20.301 +        
  20.302 +        /* Stick something in the shared communications ring. */
  20.303 +        req = &usbif->ring[MASK_USBIF_IDX(usbif->req_prod)].req;
  20.304 +
  20.305 +        req->operation       = USBIF_OP_RESET;
  20.306 +        req->port            = port;
  20.307 +        
  20.308 +        wmb();
  20.309 +
  20.310 +        usbif->req_prod++;
  20.311 +
  20.312 +	notify_via_evtchn(xhci->evtchn);
  20.313 +
  20.314 +        while ( awaiting_reset > 0 )
  20.315 +        {
  20.316 +                mdelay(1);
  20.317 +                xhci_drain_ring();
  20.318 +        }
  20.319 +
  20.320 +        return awaiting_reset;
  20.321 +}
  20.322 +
  20.323 +static void xhci_show_resp(usbif_response_t *r)
  20.324 +{
  20.325 +        printk("id=0x%lx, op=0x%x, data=0x%x, status=0x%x, length=0x%lx\n",
  20.326 +               r->id, r->operation, r->data, r->status, r->length);
  20.327 +}
  20.328 +
  20.329 +
  20.330 +/*
  20.331 + * Only the USB core should call xhci_alloc_dev and xhci_free_dev
  20.332 + */
  20.333 +static int xhci_alloc_dev(struct usb_device *dev)
  20.334 +{
  20.335 +	return 0;
  20.336 +}
  20.337 +
  20.338 +static int xhci_free_dev(struct usb_device *dev)
  20.339 +{
  20.340 +	return 0;
  20.341 +}
  20.342 +
  20.343 +static inline void xhci_add_complete(struct urb *urb)
  20.344 +{
  20.345 +	struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
  20.346 +	unsigned long flags;
  20.347 +
  20.348 +	spin_lock_irqsave(&xhci->complete_list_lock, flags);
  20.349 +	list_add_tail(&urbp->complete_list, &xhci->complete_list);
  20.350 +	spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
  20.351 +}
  20.352 +
  20.353 +/* When this returns, the owner of the URB may free its
  20.354 + * storage.
  20.355 + *
  20.356 + * We spin and wait for the URB to complete before returning.
  20.357 + */
  20.358 +static void xhci_delete_urb(struct urb *urb)
  20.359 +{
  20.360 +        struct urb_priv *urbp;
  20.361 +
  20.362 +	urbp = urb->hcpriv;
  20.363 +
  20.364 +        /* If there's no urb_priv structure for this URB then it can't have
  20.365 +         * been submitted at all. */
  20.366 +	if ( urbp == NULL )
  20.367 +		return;
  20.368 +
  20.369 +	/* For now we just spin until the URB completes.  It shouldn't take too
  20.370 +         * long and we don't expect to have to do this very often. */
  20.371 +	while ( urb->status == -EINPROGRESS )
  20.372 +        {
  20.373 +            xhci_drain_ring();
  20.374 +            mdelay(1);
  20.375 +        }
  20.376 +
  20.377 +	/* Now we know that further transfers to the buffer won't
  20.378 +	 * occur, so we can safely return. */
  20.379 +}
  20.380 +
  20.381 +static struct urb_priv *xhci_alloc_urb_priv(struct urb *urb)
  20.382 +{
  20.383 +	struct urb_priv *urbp;
  20.384 +
  20.385 +	urbp = kmem_cache_alloc(xhci_up_cachep, SLAB_ATOMIC);
  20.386 +	if (!urbp) {
  20.387 +		err("xhci_alloc_urb_priv: couldn't allocate memory for urb_priv\n");
  20.388 +		return NULL;
  20.389 +	}
  20.390 +
  20.391 +	memset((void *)urbp, 0, sizeof(*urbp));
  20.392 +
  20.393 +	urbp->inserttime = jiffies;
  20.394 +	urbp->urb = urb;
  20.395 +	urbp->dev = urb->dev;
  20.396 +	
  20.397 +	INIT_LIST_HEAD(&urbp->complete_list);
  20.398 +
  20.399 +	urb->hcpriv = urbp;
  20.400 +
  20.401 +	return urbp;
  20.402 +}
  20.403 +
  20.404 +/*
  20.405 + * MUST be called with urb->lock acquired
  20.406 + */
  20.407 +/* When is this called?  Do we need to stop the transfer (as we
  20.408 + * currently do)? */
  20.409 +static void xhci_destroy_urb_priv(struct urb *urb)
  20.410 +{
  20.411 +    struct urb_priv *urbp;
  20.412 +    
  20.413 +    urbp = (struct urb_priv *)urb->hcpriv;
  20.414 +    if (!urbp)
  20.415 +        return;
  20.416 +
  20.417 +    if (!list_empty(&urb->urb_list))
  20.418 +        warn("xhci_destroy_urb_priv: urb %p still on xhci->urb_list or xhci->remove_list", urb);
  20.419 +    
  20.420 +    if (!list_empty(&urbp->complete_list))
  20.421 +        warn("xhci_destroy_urb_priv: urb %p still on xhci->complete_list", urb);
  20.422 +    
  20.423 +    kmem_cache_free(xhci_up_cachep, urb->hcpriv);
  20.424 +
  20.425 +    urb->hcpriv = NULL;
  20.426 +}
  20.427 +
  20.428 +/**
  20.429 + * Try to find URBs in progress on the same pipe to the same device.
  20.430 + *
  20.431 + * MUST be called with xhci->urb_list_lock acquired
  20.432 + */
  20.433 +static struct urb *xhci_find_urb_ep(struct xhci *xhci, struct urb *urb)
  20.434 +{
  20.435 +	struct list_head *tmp, *head;
  20.436 +
  20.437 +	/* We don't match Isoc transfers since they are special */
  20.438 +	if (usb_pipeisoc(urb->pipe))
  20.439 +		return NULL;
  20.440 +
  20.441 +	head = &xhci->urb_list;
  20.442 +	tmp = head->next;
  20.443 +	while (tmp != head) {
  20.444 +		struct urb *u = list_entry(tmp, struct urb, urb_list);
  20.445 +
  20.446 +		tmp = tmp->next;
  20.447 +
  20.448 +		if (u->dev == urb->dev && u->pipe == urb->pipe &&
  20.449 +		    u->status == -EINPROGRESS)
  20.450 +			return u;
  20.451 +	}
  20.452 +
  20.453 +	return NULL;
  20.454 +}
  20.455 +
  20.456 +static int xhci_submit_urb(struct urb *urb)
  20.457 +{
  20.458 +	int ret = -EINVAL;
  20.459 +	unsigned long flags;
  20.460 +	struct urb *eurb;
  20.461 +	int bustime;
  20.462 +
  20.463 +#if 0
  20.464 +        printk("submitting urb @ %p for dev @ %p, devnum = %d path %s\n",
  20.465 +               urb, urb->dev, urb->dev->devnum, urb->dev->devpath);
  20.466 +#endif
  20.467 +
  20.468 +	if (!urb)
  20.469 +		return -EINVAL;
  20.470 +
  20.471 +	if (!urb->dev || !urb->dev->bus || !urb->dev->bus->hcpriv) {
  20.472 +		warn("xhci_submit_urb: urb %p belongs to disconnected device or bus?", urb);
  20.473 +		return -ENODEV;
  20.474 +	}
  20.475 +
  20.476 +        if ( urb->dev->devpath == NULL )
  20.477 +        {
  20.478 +                printk("BARF!\n");
  20.479 +                BUG();
  20.480 +        }
  20.481 +        
  20.482 +        
  20.483 +
  20.484 +	usb_inc_dev_use(urb->dev);
  20.485 +
  20.486 +	spin_lock_irqsave(&xhci->urb_list_lock, flags);
  20.487 +	spin_lock(&urb->lock);
  20.488 +
  20.489 +	if (urb->status == -EINPROGRESS || urb->status == -ECONNRESET ||
  20.490 +	    urb->status == -ECONNABORTED) {
  20.491 +		dbg("xhci_submit_urb: urb not available to submit (status = %d)", urb->status);
  20.492 +		/* Since we can have problems on the out path */
  20.493 +		spin_unlock(&urb->lock);
  20.494 +		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.495 +		usb_dec_dev_use(urb->dev);
  20.496 +
  20.497 +		return ret;
  20.498 +	}
  20.499 +
  20.500 +	INIT_LIST_HEAD(&urb->urb_list);
  20.501 +	if (!xhci_alloc_urb_priv(urb)) {
  20.502 +		ret = -ENOMEM;
  20.503 +
  20.504 +		goto out;
  20.505 +	}
  20.506 +
  20.507 +        ( (struct urb_priv *)urb->hcpriv )->in_progress = 1;
  20.508 +
  20.509 +	eurb = xhci_find_urb_ep(xhci, urb);
  20.510 +	if (eurb && !(urb->transfer_flags & USB_QUEUE_BULK)) {
  20.511 +		ret = -ENXIO;
  20.512 +
  20.513 +		goto out;
  20.514 +	}
  20.515 +
  20.516 +	/* Short circuit the virtual root hub */
  20.517 +	if (urb->dev == xhci->rh.dev) {
  20.518 +		ret = rh_submit_urb(urb);
  20.519 +
  20.520 +		goto out;
  20.521 +	}
  20.522 +
  20.523 +	if ( usb_pipedevice(urb->pipe) == 1 )
  20.524 +	  printk("dev = %p, dev->path = %s, rh.dev = %p, rh.dev.devnum = %d rh.dev->path = %s!\n",
  20.525 +		 urb->dev, urb->dev->devpath, xhci->rh.dev, xhci->rh.dev->devnum, xhci->rh.dev->devpath);
  20.526 +
  20.527 +	switch (usb_pipetype(urb->pipe)) {
  20.528 +	case PIPE_CONTROL:
  20.529 +		ret = xhci_queue_req(urb);
  20.530 +		break;
  20.531 +	case PIPE_INTERRUPT:
  20.532 +		if (urb->bandwidth == 0) {	/* not yet checked/allocated */
  20.533 +			bustime = usb_check_bandwidth(urb->dev, urb);
  20.534 +			if (bustime < 0)
  20.535 +				ret = bustime;
  20.536 +			else {
  20.537 +				ret = xhci_queue_req(urb);
  20.538 +				if (ret == -EINPROGRESS)
  20.539 +					usb_claim_bandwidth(urb->dev, urb, bustime, 0);
  20.540 +			}
  20.541 +		} else		/* bandwidth is already set */
  20.542 +			ret = xhci_queue_req(urb);
  20.543 +		break;
  20.544 +	case PIPE_BULK:
  20.545 +		ret = xhci_queue_req(urb);
  20.546 +		break;
  20.547 +	case PIPE_ISOCHRONOUS:
  20.548 +		if (urb->bandwidth == 0) {	/* not yet checked/allocated */
  20.549 +			if (urb->number_of_packets <= 0) {
  20.550 +				ret = -EINVAL;
  20.551 +				break;
  20.552 +			}
  20.553 +			bustime = usb_check_bandwidth(urb->dev, urb);
  20.554 +			if (bustime < 0) {
  20.555 +				ret = bustime;
  20.556 +				break;
  20.557 +			}
  20.558 +
  20.559 +			ret = xhci_queue_req(urb);
  20.560 +			if (ret == -EINPROGRESS)
  20.561 +				usb_claim_bandwidth(urb->dev, urb, bustime, 1);
  20.562 +		} else		/* bandwidth is already set */
  20.563 +			ret = xhci_queue_req(urb);
  20.564 +		break;
  20.565 +	}
  20.566 +
  20.567 +out:
  20.568 +	urb->status = ret;
  20.569 +
  20.570 +	if (ret == -EINPROGRESS) {
  20.571 +		/* We use _tail to make find_urb_ep more efficient */
  20.572 +		list_add_tail(&urb->urb_list, &xhci->urb_list);
  20.573 +
  20.574 +		spin_unlock(&urb->lock);
  20.575 +		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.576 +
  20.577 +		return 0;
  20.578 +	}
  20.579 +
  20.580 +	xhci_unlink_generic(urb);
  20.581 +
  20.582 +	spin_unlock(&urb->lock);
  20.583 +	spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.584 +
  20.585 +	/* Only call completion if it was successful */
  20.586 +	if (!ret)
  20.587 +		xhci_call_completion(urb);
  20.588 +
  20.589 +	return ret;
  20.590 +}
  20.591 +
  20.592 +/*
  20.593 + * Return the result of a transfer
  20.594 + *
  20.595 + * MUST be called with urb_list_lock acquired
  20.596 + */
  20.597 +static void xhci_transfer_result(struct xhci *xhci, struct urb *urb)
  20.598 +{
  20.599 +	int ret = 0;
  20.600 +	unsigned long flags;
  20.601 +	struct urb_priv *urbp;
  20.602 +
  20.603 +	/* The root hub is special */
  20.604 +	if (urb->dev == xhci->rh.dev)
  20.605 +		return;
  20.606 +
  20.607 +	spin_lock_irqsave(&urb->lock, flags);
  20.608 +
  20.609 +	urbp = (struct urb_priv *)urb->hcpriv;
  20.610 +
  20.611 +        if ( ( (struct urb_priv *)urb->hcpriv )->in_progress )
  20.612 +                ret = -EINPROGRESS;
  20.613 +
  20.614 +        if (urb->actual_length < urb->transfer_buffer_length) {
  20.615 +                if (urb->transfer_flags & USB_DISABLE_SPD) {
  20.616 +                        ret = -EREMOTEIO;
  20.617 +                }
  20.618 +        }
  20.619 +
  20.620 +	if (urb->status == -EPIPE)
  20.621 +        {
  20.622 +                ret = urb->status;
  20.623 +		/* endpoint has stalled - mark it halted */
  20.624 +		usb_endpoint_halt(urb->dev, usb_pipeendpoint(urb->pipe),
  20.625 +                                  usb_pipeout(urb->pipe));
  20.626 +        }
  20.627 +
  20.628 +	if ((debug == 1 && ret != 0 && ret != -EPIPE) ||
  20.629 +            (ret != 0 && debug > 1)) {
  20.630 +		/* Some debugging code */
  20.631 +		dbg("xhci_result_interrupt/bulk() failed with status %x",
  20.632 +			status);
  20.633 +	}
  20.634 +
  20.635 +	if (ret == -EINPROGRESS)
  20.636 +		goto out;
  20.637 +
  20.638 +	switch (usb_pipetype(urb->pipe)) {
  20.639 +	case PIPE_CONTROL:
  20.640 +	case PIPE_BULK:
  20.641 +	case PIPE_ISOCHRONOUS:
  20.642 +		/* Release bandwidth for Interrupt or Isoc. transfers */
  20.643 +		/* Spinlock needed ? */
  20.644 +		if (urb->bandwidth)
  20.645 +			usb_release_bandwidth(urb->dev, urb, 1);
  20.646 +		xhci_unlink_generic(urb);
  20.647 +		break;
  20.648 +	case PIPE_INTERRUPT:
  20.649 +		/* Interrupts are an exception */
  20.650 +		if (urb->interval)
  20.651 +			goto out_complete;
  20.652 +
  20.653 +		/* Release bandwidth for Interrupt or Isoc. transfers */
  20.654 +		/* Spinlock needed ? */
  20.655 +		if (urb->bandwidth)
  20.656 +			usb_release_bandwidth(urb->dev, urb, 0);
  20.657 +		xhci_unlink_generic(urb);
  20.658 +		break;
  20.659 +	default:
  20.660 +		info("xhci_transfer_result: unknown pipe type %d for urb %p\n",
  20.661 +			usb_pipetype(urb->pipe), urb);
  20.662 +	}
  20.663 +
  20.664 +	/* Remove it from xhci->urb_list */
  20.665 +	list_del_init(&urb->urb_list);
  20.666 +
  20.667 +out_complete:
  20.668 +	xhci_add_complete(urb);
  20.669 +
  20.670 +out:
  20.671 +	spin_unlock_irqrestore(&urb->lock, flags);
  20.672 +}
  20.673 +
  20.674 +/*
  20.675 + * MUST be called with urb->lock acquired
  20.676 + */
  20.677 +static void xhci_unlink_generic(struct urb *urb)
  20.678 +{
  20.679 +	struct urb_priv *urbp = urb->hcpriv;
  20.680 +
  20.681 +	/* We can get called when urbp allocation fails, so check */
  20.682 +	if (!urbp)
  20.683 +		return;
  20.684 +
  20.685 +        /* ??? This function is now so minimal it doesn't do much.  Do we really
  20.686 +         * need it? */
  20.687 +
  20.688 +	xhci_delete_urb(urb);
  20.689 +}
  20.690 +
  20.691 +static int xhci_unlink_urb(struct urb *urb)
  20.692 +{
  20.693 +	unsigned long flags;
  20.694 +	struct urb_priv *urbp = urb->hcpriv;
  20.695 +
  20.696 +	if (!urb)
  20.697 +		return -EINVAL;
  20.698 +
  20.699 +	if (!urb->dev || !urb->dev->bus || !urb->dev->bus->hcpriv)
  20.700 +		return -ENODEV;
  20.701 +
  20.702 +	spin_lock_irqsave(&xhci->urb_list_lock, flags);
  20.703 +	spin_lock(&urb->lock);
  20.704 +
  20.705 +	/* Release bandwidth for Interrupt or Isoc. transfers */
  20.706 +	/* Spinlock needed ? */
  20.707 +	if (urb->bandwidth) {
  20.708 +		switch (usb_pipetype(urb->pipe)) {
  20.709 +		case PIPE_INTERRUPT:
  20.710 +			usb_release_bandwidth(urb->dev, urb, 0);
  20.711 +			break;
  20.712 +		case PIPE_ISOCHRONOUS:
  20.713 +			usb_release_bandwidth(urb->dev, urb, 1);
  20.714 +			break;
  20.715 +		default:
  20.716 +			break;
  20.717 +		}
  20.718 +	}
  20.719 +
  20.720 +	if (urb->status != -EINPROGRESS) {
  20.721 +		spin_unlock(&urb->lock);
  20.722 +		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.723 +		return 0;
  20.724 +	}
  20.725 +
  20.726 +	list_del_init(&urb->urb_list);
  20.727 +
  20.728 +	xhci_unlink_generic(urb);
  20.729 +
  20.730 +	/* Short circuit the virtual root hub */
  20.731 +	if (urb->dev == xhci->rh.dev) {
  20.732 +		rh_unlink_urb(urb);
  20.733 +
  20.734 +		spin_unlock(&urb->lock);
  20.735 +		spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.736 +
  20.737 +		xhci_call_completion(urb);
  20.738 +	} else {
  20.739 +		if (urb->transfer_flags & USB_ASYNC_UNLINK) {
  20.740 +			urbp->status = urb->status = -ECONNABORTED;
  20.741 +
  20.742 +			spin_lock(&xhci->urb_remove_list_lock);
  20.743 +
  20.744 +			list_add(&urb->urb_list, &xhci->urb_remove_list);
  20.745 +
  20.746 +			spin_unlock(&xhci->urb_remove_list_lock);
  20.747 +
  20.748 +			spin_unlock(&urb->lock);
  20.749 +			spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.750 +
  20.751 +		} else {
  20.752 +			urb->status = -ENOENT;
  20.753 +
  20.754 +			spin_unlock(&urb->lock);
  20.755 +			spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.756 +
  20.757 +			if (in_interrupt()) {	/* wait at least 1 frame */
  20.758 +				static int errorcount = 10;
  20.759 +
  20.760 +				if (errorcount--)
  20.761 +					dbg("xhci_unlink_urb called from interrupt for urb %p", urb);
  20.762 +				udelay(1000);
  20.763 +			} else
  20.764 +				schedule_timeout(1+1*HZ/1000); 
  20.765 +
  20.766 +			xhci_call_completion(urb);
  20.767 +		}
  20.768 +	}
  20.769 +
  20.770 +	return 0;
  20.771 +}
  20.772 +
  20.773 +
  20.774 +struct usb_operations xhci_device_operations = {
  20.775 +	.allocate = xhci_alloc_dev,
  20.776 +	.deallocate = xhci_free_dev,
  20.777 +        /* It doesn't look like any drivers actually care what the frame number
  20.778 +	 * is at the moment!  If necessary, we could approximate the current
  20.779 +	 * frame nubmer by passing it from the backend in response messages. */
  20.780 +	.get_frame_number = NULL,
  20.781 +	.submit_urb = xhci_submit_urb,
  20.782 +	.unlink_urb = xhci_unlink_urb
  20.783 +};
  20.784 +
  20.785 +/* Virtual Root Hub */
  20.786 +
  20.787 +static __u8 root_hub_dev_des[] =
  20.788 +{
  20.789 + 	0x12,			/*  __u8  bLength; */
  20.790 +	0x01,			/*  __u8  bDescriptorType; Device */
  20.791 +	0x00,			/*  __u16 bcdUSB; v1.0 */
  20.792 +	0x01,
  20.793 +	0x09,			/*  __u8  bDeviceClass; HUB_CLASSCODE */
  20.794 +	0x00,			/*  __u8  bDeviceSubClass; */
  20.795 +	0x00,			/*  __u8  bDeviceProtocol; */
  20.796 +	0x08,			/*  __u8  bMaxPacketSize0; 8 Bytes */
  20.797 +	0x00,			/*  __u16 idVendor; */
  20.798 +	0x00,
  20.799 +	0x00,			/*  __u16 idProduct; */
  20.800 +	0x00,
  20.801 +	0x00,			/*  __u16 bcdDevice; */
  20.802 +	0x00,
  20.803 +	0x00,			/*  __u8  iManufacturer; */
  20.804 +	0x02,			/*  __u8  iProduct; */
  20.805 +	0x01,			/*  __u8  iSerialNumber; */
  20.806 +	0x01			/*  __u8  bNumConfigurations; */
  20.807 +};
  20.808 +
  20.809 +
  20.810 +/* Configuration descriptor */
  20.811 +static __u8 root_hub_config_des[] =
  20.812 +{
  20.813 +	0x09,			/*  __u8  bLength; */
  20.814 +	0x02,			/*  __u8  bDescriptorType; Configuration */
  20.815 +	0x19,			/*  __u16 wTotalLength; */
  20.816 +	0x00,
  20.817 +	0x01,			/*  __u8  bNumInterfaces; */
  20.818 +	0x01,			/*  __u8  bConfigurationValue; */
  20.819 +	0x00,			/*  __u8  iConfiguration; */
  20.820 +	0x40,			/*  __u8  bmAttributes;
  20.821 +					Bit 7: Bus-powered, 6: Self-powered,
  20.822 +					Bit 5 Remote-wakeup, 4..0: resvd */
  20.823 +	0x00,			/*  __u8  MaxPower; */
  20.824 +
  20.825 +	/* interface */
  20.826 +	0x09,			/*  __u8  if_bLength; */
  20.827 +	0x04,			/*  __u8  if_bDescriptorType; Interface */
  20.828 +	0x00,			/*  __u8  if_bInterfaceNumber; */
  20.829 +	0x00,			/*  __u8  if_bAlternateSetting; */
  20.830 +	0x01,			/*  __u8  if_bNumEndpoints; */
  20.831 +	0x09,			/*  __u8  if_bInterfaceClass; HUB_CLASSCODE */
  20.832 +	0x00,			/*  __u8  if_bInterfaceSubClass; */
  20.833 +	0x00,			/*  __u8  if_bInterfaceProtocol; */
  20.834 +	0x00,			/*  __u8  if_iInterface; */
  20.835 +
  20.836 +	/* endpoint */
  20.837 +	0x07,			/*  __u8  ep_bLength; */
  20.838 +	0x05,			/*  __u8  ep_bDescriptorType; Endpoint */
  20.839 +	0x81,			/*  __u8  ep_bEndpointAddress; IN Endpoint 1 */
  20.840 +	0x03,			/*  __u8  ep_bmAttributes; Interrupt */
  20.841 +	0x08,			/*  __u16 ep_wMaxPacketSize; 8 Bytes */
  20.842 +	0x00,
  20.843 +	0xff			/*  __u8  ep_bInterval; 255 ms */
  20.844 +};
  20.845 +
  20.846 +static __u8 root_hub_hub_des[] =
  20.847 +{
  20.848 +	0x09,			/*  __u8  bLength; */
  20.849 +	0x29,			/*  __u8  bDescriptorType; Hub-descriptor */
  20.850 +	0x02,			/*  __u8  bNbrPorts; */
  20.851 +	0x00,			/* __u16  wHubCharacteristics; */
  20.852 +	0x00,
  20.853 +	0x01,			/*  __u8  bPwrOn2pwrGood; 2ms */
  20.854 +	0x00,			/*  __u8  bHubContrCurrent; 0 mA */
  20.855 +	0x00,			/*  __u8  DeviceRemovable; *** 7 Ports max *** */
  20.856 +	0xff			/*  __u8  PortPwrCtrlMask; *** 7 ports max *** */
  20.857 +};
  20.858 +
  20.859 +/* prepare Interrupt pipe transaction data; HUB INTERRUPT ENDPOINT */
  20.860 +static int rh_send_irq(struct urb *urb)
  20.861 +{
  20.862 +	struct urb_priv *urbp = (struct urb_priv *)urb->hcpriv;
  20.863 +        xhci_port_t *ports = xhci->rh.ports;
  20.864 +	unsigned long flags;
  20.865 +	int i, len = 1;
  20.866 +	__u16 data = 0;
  20.867 +
  20.868 +	spin_lock_irqsave(&urb->lock, flags);
  20.869 +	for (i = 0; i < xhci->rh.numports; i++) {
  20.870 +                /* MAW: No idea what the old code was doing here or why it worked.
  20.871 +		 * This implementation sets a bit if anything at all has changed on the 
  20.872 +		 * port, as per USB spec 11.12 */
  20.873 +		data |= (ports[i].cs_chg || ports[i].pe_chg )
  20.874 +                        ? (1 << (i + 1))
  20.875 +                        : 0;
  20.876 +
  20.877 +		len = (i + 1) / 8 + 1;
  20.878 +	}
  20.879 +
  20.880 +	*(__u16 *) urb->transfer_buffer = cpu_to_le16(data);
  20.881 +	urb->actual_length = len;
  20.882 +	urbp->status = 0;
  20.883 +
  20.884 +	spin_unlock_irqrestore(&urb->lock, flags);
  20.885 +
  20.886 +	if ((data > 0) && (xhci->rh.send != 0)) {
  20.887 +		dbg("root-hub INT complete: data: %x", data);
  20.888 +		xhci_call_completion(urb);
  20.889 +	}
  20.890 +
  20.891 +	return 0;
  20.892 +}
  20.893 +
  20.894 +/* Virtual Root Hub INTs are polled by this timer every "interval" ms */
  20.895 +static int rh_init_int_timer(struct urb *urb);
  20.896 +
  20.897 +static void rh_int_timer_do(unsigned long ptr)
  20.898 +{
  20.899 +	struct urb *urb = (struct urb *)ptr;
  20.900 +	struct list_head list, *tmp, *head;
  20.901 +	unsigned long flags;
  20.902 +	int i;
  20.903 +
  20.904 +	for ( i = 0; i < xhci->rh.numports; i++)
  20.905 +                xhci_queue_probe(i);
  20.906 +
  20.907 +	if (xhci->rh.send)
  20.908 +		rh_send_irq(urb);
  20.909 +
  20.910 +	INIT_LIST_HEAD(&list);
  20.911 +
  20.912 +	spin_lock_irqsave(&xhci->urb_list_lock, flags);
  20.913 +	head = &xhci->urb_list;
  20.914 +	tmp = head->next;
  20.915 +	while (tmp != head) {
  20.916 +		struct urb *u = list_entry(tmp, struct urb, urb_list);
  20.917 +		struct urb_priv *up = (struct urb_priv *)u->hcpriv;
  20.918 +
  20.919 +		tmp = tmp->next;
  20.920 +
  20.921 +		spin_lock(&u->lock);
  20.922 +
  20.923 +		/* Check if the URB timed out */
  20.924 +		if (u->timeout && time_after_eq(jiffies, up->inserttime + u->timeout)) {
  20.925 +			list_del(&u->urb_list);
  20.926 +			list_add_tail(&u->urb_list, &list);
  20.927 +		}
  20.928 +
  20.929 +		spin_unlock(&u->lock);
  20.930 +	}
  20.931 +	spin_unlock_irqrestore(&xhci->urb_list_lock, flags);
  20.932 +
  20.933 +	head = &list;
  20.934 +	tmp = head->next;
  20.935 +	while (tmp != head) {
  20.936 +		struct urb *u = list_entry(tmp, struct urb, urb_list);
  20.937 +
  20.938 +		tmp = tmp->next;
  20.939 +
  20.940 +		u->transfer_flags |= USB_ASYNC_UNLINK | USB_TIMEOUT_KILLED;
  20.941 +		xhci_unlink_urb(u);
  20.942 +	}
  20.943 +
  20.944 +	rh_init_int_timer(urb);
  20.945 +}
  20.946 +
  20.947 +/* Root Hub INTs are polled by this timer */
  20.948 +static int rh_init_int_timer(struct urb *urb)
  20.949 +{
  20.950 +	xhci->rh.interval = urb->interval;
  20.951 +	init_timer(&xhci->rh.rh_int_timer);
  20.952 +	xhci->rh.rh_int_timer.function = rh_int_timer_do;
  20.953 +	xhci->rh.rh_int_timer.data = (unsigned long)urb;
  20.954 +	xhci->rh.rh_int_timer.expires = jiffies + (HZ * (urb->interval < 30 ? 30 : urb->interval)) / 1000;
  20.955 +	add_timer(&xhci->rh.rh_int_timer);
  20.956 +
  20.957 +	return 0;
  20.958 +}
  20.959 +
  20.960 +#define OK(x)			len = (x); break
  20.961 +
  20.962 +/* Root Hub Control Pipe */
  20.963 +static int rh_submit_urb(struct urb *urb)
  20.964 +{
  20.965 +	unsigned int pipe = urb->pipe;
  20.966 +	struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *)urb->setup_packet;
  20.967 +	void *data = urb->transfer_buffer;
  20.968 +	int leni = urb->transfer_buffer_length;
  20.969 +	int len = 0;
  20.970 +	xhci_port_t *status;
  20.971 +	int stat = 0;
  20.972 +	int i;
  20.973 +	int retstatus;
  20.974 +        unsigned long flags;
  20.975 +        
  20.976 +	__u16 cstatus;
  20.977 +	__u16 bmRType_bReq;
  20.978 +	__u16 wValue;
  20.979 +	__u16 wIndex;
  20.980 +	__u16 wLength;
  20.981 +
  20.982 +	if (usb_pipetype(pipe) == PIPE_INTERRUPT) {
  20.983 +		xhci->rh.urb = urb;
  20.984 +		xhci->rh.send = 1;
  20.985 +		xhci->rh.interval = urb->interval;
  20.986 +		rh_init_int_timer(urb);
  20.987 +
  20.988 +		return -EINPROGRESS;
  20.989 +	}
  20.990 +
  20.991 +	bmRType_bReq = cmd->bRequestType | cmd->bRequest << 8;
  20.992 +	wValue = le16_to_cpu(cmd->wValue);
  20.993 +	wIndex = le16_to_cpu(cmd->wIndex);
  20.994 +	wLength = le16_to_cpu(cmd->wLength);
  20.995 +
  20.996 +	for (i = 0; i < 8; i++)
  20.997 +		xhci->rh.c_p_r[i] = 0;
  20.998 +
  20.999 +        status = &xhci->rh.ports[wIndex - 1];
 20.1000 +
 20.1001 +        spin_lock_irqsave(&xhci->rh.port_state_lock, flags);
 20.1002 +
 20.1003 +	switch (bmRType_bReq) {
 20.1004 +		/* Request Destination:
 20.1005 +		   without flags: Device,
 20.1006 +		   RH_INTERFACE: interface,
 20.1007 +		   RH_ENDPOINT: endpoint,
 20.1008 +		   RH_CLASS means HUB here,
 20.1009 +		   RH_OTHER | RH_CLASS  almost ever means HUB_PORT here
 20.1010 +		*/
 20.1011 +
 20.1012 +	case RH_GET_STATUS:
 20.1013 +		*(__u16 *)data = cpu_to_le16(1);
 20.1014 +		OK(2);
 20.1015 +	case RH_GET_STATUS | RH_INTERFACE:
 20.1016 +		*(__u16 *)data = cpu_to_le16(0);
 20.1017 +		OK(2);
 20.1018 +	case RH_GET_STATUS | RH_ENDPOINT:
 20.1019 +		*(__u16 *)data = cpu_to_le16(0);
 20.1020 +		OK(2);
 20.1021 +	case RH_GET_STATUS | RH_CLASS:
 20.1022 +		*(__u32 *)data = cpu_to_le32(0);
 20.1023 +		OK(4);		/* hub power */
 20.1024 +	case RH_GET_STATUS | RH_OTHER | RH_CLASS:
 20.1025 +		cstatus = (status->cs_chg) |
 20.1026 +			(status->pe_chg << 1) |
 20.1027 +			(xhci->rh.c_p_r[wIndex - 1] << 4);
 20.1028 +		retstatus = (status->ccs) |
 20.1029 +			(status->pe << 1) |
 20.1030 +			(status->susp << 2) |
 20.1031 +			(status->pr << 8) |
 20.1032 +			(1 << 8) |      /* power on */
 20.1033 +			(status->lsda << 9);
 20.1034 +		*(__u16 *)data = cpu_to_le16(retstatus);
 20.1035 +		*(__u16 *)(data + 2) = cpu_to_le16(cstatus);
 20.1036 +		OK(4);
 20.1037 +	case RH_CLEAR_FEATURE | RH_ENDPOINT:
 20.1038 +		switch (wValue) {
 20.1039 +		case RH_ENDPOINT_STALL:
 20.1040 +			OK(0);
 20.1041 +		}
 20.1042 +		break;
 20.1043 +	case RH_CLEAR_FEATURE | RH_CLASS:
 20.1044 +		switch (wValue) {
 20.1045 +		case RH_C_HUB_OVER_CURRENT:
 20.1046 +			OK(0);	/* hub power over current */
 20.1047 +		}
 20.1048 +		break;
 20.1049 +	case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
 20.1050 +		switch (wValue) {
 20.1051 +		case RH_PORT_ENABLE:
 20.1052 +                        status->pe     = 0;
 20.1053 +			OK(0);
 20.1054 +		case RH_PORT_SUSPEND:
 20.1055 +                        status->susp   = 0;
 20.1056 +			OK(0);
 20.1057 +		case RH_PORT_POWER:
 20.1058 +			OK(0);	/* port power */
 20.1059 +		case RH_C_PORT_CONNECTION:
 20.1060 +                        status->cs_chg = 0;
 20.1061 +			OK(0);
 20.1062 +		case RH_C_PORT_ENABLE:
 20.1063 +                        status->pe_chg = 0;
 20.1064 +			OK(0);
 20.1065 +		case RH_C_PORT_SUSPEND:
 20.1066 +			/*** WR_RH_PORTSTAT(RH_PS_PSSC); */
 20.1067 +			OK(0);
 20.1068 +		case RH_C_PORT_OVER_CURRENT:
 20.1069 +			OK(0);	/* port power over current */
 20.1070 +		case RH_C_PORT_RESET:
 20.1071 +			xhci->rh.c_p_r[wIndex - 1] = 0;
 20.1072 +			OK(0);
 20.1073 +		}
 20.1074 +		break;
 20.1075 +	case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
 20.1076 +		switch (wValue) {
 20.1077 +		case RH_PORT_SUSPEND:
 20.1078 +                        status->susp = 1;	
 20.1079 +			OK(0);
 20.1080 +		case RH_PORT_RESET:
 20.1081 +                {
 20.1082 +                        int ret;
 20.1083 +                        xhci->rh.c_p_r[wIndex - 1] = 1;
 20.1084 +                        status->pr = 0;
 20.1085 +                        status->pe = 1;
 20.1086 +                        ret = xhci_port_reset(wIndex - 1);
 20.1087 +                        /* XXX MAW: should probably cancel queued transfers during reset... *\/ */
 20.1088 +                        if ( ret == 0 ) { OK(0); }
 20.1089 +                        else { return ret; }
 20.1090 +                }
 20.1091 +                break;
 20.1092 +		case RH_PORT_POWER:
 20.1093 +			OK(0); /* port power ** */
 20.1094 +		case RH_PORT_ENABLE:
 20.1095 +                        status->pe = 1;
 20.1096 +			OK(0);
 20.1097 +		}
 20.1098 +		break;
 20.1099 +	case RH_SET_ADDRESS:
 20.1100 +	  printk("setting root hub device to %d\n", wValue);
 20.1101 +		xhci->rh.devnum = wValue;
 20.1102 +		OK(0);
 20.1103 +	case RH_GET_DESCRIPTOR:
 20.1104 +		switch ((wValue & 0xff00) >> 8) {
 20.1105 +		case 0x01:	/* device descriptor */
 20.1106 +			len = min_t(unsigned int, leni,
 20.1107 +				  min_t(unsigned int,
 20.1108 +				      sizeof(root_hub_dev_des), wLength));
 20.1109 +			memcpy(data, root_hub_dev_des, len);
 20.1110 +			OK(len);
 20.1111 +		case 0x02:	/* configuration descriptor */
 20.1112 +			len = min_t(unsigned int, leni,
 20.1113 +				  min_t(unsigned int,
 20.1114 +				      sizeof(root_hub_config_des), wLength));
 20.1115 +			memcpy (data, root_hub_config_des, len);
 20.1116 +			OK(len);
 20.1117 +		case 0x03:	/* string descriptors */
 20.1118 +			len = usb_root_hub_string (wValue & 0xff,
 20.1119 +				0, "XHCI-alt",
 20.1120 +				data, wLength);
 20.1121 +			if (len > 0) {
 20.1122 +				OK(min_t(int, leni, len));
 20.1123 +			} else 
 20.1124 +				stat = -EPIPE;
 20.1125 +		}
 20.1126 +		break;
 20.1127 +	case RH_GET_DESCRIPTOR | RH_CLASS:
 20.1128 +		root_hub_hub_des[2] = xhci->rh.numports;
 20.1129 +		len = min_t(unsigned int, leni,
 20.1130 +			  min_t(unsigned int, sizeof(root_hub_hub_des), wLength));
 20.1131 +		memcpy(data, root_hub_hub_des, len);
 20.1132 +		OK(len);
 20.1133 +	case RH_GET_CONFIGURATION:
 20.1134 +		*(__u8 *)data = 0x01;
 20.1135 +		OK(1);
 20.1136 +	case RH_SET_CONFIGURATION:
 20.1137 +		OK(0);
 20.1138 +	case RH_GET_INTERFACE | RH_INTERFACE:
 20.1139 +		*(__u8 *)data = 0x00;
 20.1140 +		OK(1);
 20.1141 +	case RH_SET_INTERFACE | RH_INTERFACE:
 20.1142 +		OK(0);
 20.1143 +	default:
 20.1144 +		stat = -EPIPE;
 20.1145 +	}
 20.1146 +
 20.1147 +        spin_unlock_irqrestore(&xhci->rh.port_state_lock, flags);
 20.1148 +
 20.1149 +	urb->actual_length = len;
 20.1150 +
 20.1151 +	return stat;
 20.1152 +}
 20.1153 +
 20.1154 +/*
 20.1155 + * MUST be called with urb->lock acquired
 20.1156 + */
 20.1157 +static int rh_unlink_urb(struct urb *urb)
 20.1158 +{
 20.1159 +	if (xhci->rh.urb == urb) {
 20.1160 +		urb->status = -ENOENT;
 20.1161 +		xhci->rh.send = 0;
 20.1162 +		xhci->rh.urb = NULL;
 20.1163 +		del_timer(&xhci->rh.rh_int_timer);
 20.1164 +	}
 20.1165 +	return 0;
 20.1166 +}
 20.1167 +
 20.1168 +static void xhci_call_completion(struct urb *urb)
 20.1169 +{
 20.1170 +	struct urb_priv *urbp;
 20.1171 +	struct usb_device *dev = urb->dev;
 20.1172 +	int is_ring = 0, killed, resubmit_interrupt, status;
 20.1173 +	struct urb *nurb;
 20.1174 +	unsigned long flags;
 20.1175 +
 20.1176 +	spin_lock_irqsave(&urb->lock, flags);
 20.1177 +
 20.1178 +	urbp = (struct urb_priv *)urb->hcpriv;
 20.1179 +	if (!urbp || !urb->dev) {
 20.1180 +		spin_unlock_irqrestore(&urb->lock, flags);
 20.1181 +		return;
 20.1182 +	}
 20.1183 +
 20.1184 +	killed = (urb->status == -ENOENT || urb->status == -ECONNABORTED ||
 20.1185 +			urb->status == -ECONNRESET);
 20.1186 +	resubmit_interrupt = (usb_pipetype(urb->pipe) == PIPE_INTERRUPT &&
 20.1187 +			urb->interval);
 20.1188 +
 20.1189 +	nurb = urb->next;
 20.1190 +	if (nurb && !killed) {
 20.1191 +		int count = 0;
 20.1192 +
 20.1193 +		while (nurb && nurb != urb && count < MAX_URB_LOOP) {
 20.1194 +			if (nurb->status == -ENOENT ||
 20.1195 +			    nurb->status == -ECONNABORTED ||
 20.1196 +			    nurb->status == -ECONNRESET) {
 20.1197 +				killed = 1;
 20.1198 +				break;
 20.1199 +			}
 20.1200 +
 20.1201 +			nurb = nurb->next;
 20.1202 +			count++;
 20.1203 +		}
 20.1204 +
 20.1205 +		if (count == MAX_URB_LOOP)
 20.1206 +			err("xhci_call_completion: too many linked URB's, loop? (first loop)");
 20.1207 +
 20.1208 +		/* Check to see if chain is a ring */
 20.1209 +		is_ring = (nurb == urb);
 20.1210 +	}
 20.1211 +
 20.1212 +	status = urbp->status;
 20.1213 +	if (!resubmit_interrupt || killed)
 20.1214 +		/* We don't need urb_priv anymore */
 20.1215 +		xhci_destroy_urb_priv(urb);
 20.1216 +
 20.1217 +	if (!killed)
 20.1218 +		urb->status = status;
 20.1219 +
 20.1220 +	spin_unlock_irqrestore(&urb->lock, flags);
 20.1221 +
 20.1222 +	if (urb->complete)
 20.1223 +		urb->complete(urb);
 20.1224 +
 20.1225 +	if (resubmit_interrupt)
 20.1226 +		/* Recheck the status. The completion handler may have */
 20.1227 +		/*  unlinked the resubmitting interrupt URB */
 20.1228 +		killed = (urb->status == -ENOENT ||
 20.1229 +			  urb->status == -ECONNABORTED ||
 20.1230 +			  urb->status == -ECONNRESET);
 20.1231 +
 20.1232 +	if (resubmit_interrupt && !killed) {
 20.1233 +                if ( urb->dev != xhci->rh.dev )
 20.1234 +                        xhci_queue_req(urb); /* XXX What if this fails? */
 20.1235 +                /* Don't need to resubmit URBs for the virtual root dev. */
 20.1236 +	} else {
 20.1237 +		if (is_ring && !killed) {
 20.1238 +			urb->dev = dev;
 20.1239 +			xhci_submit_urb(urb);
 20.1240 +		} else {
 20.1241 +			/* We decrement the usage count after we're done */
 20.1242 +			/*  with everything */
 20.1243 +			usb_dec_dev_use(dev);
 20.1244 +		}
 20.1245 +	}
 20.1246 +}
 20.1247 +
 20.1248 +static void xhci_finish_completion(void)
 20.1249 +{
 20.1250 +	struct list_head *tmp, *head;
 20.1251 +	unsigned long flags;
 20.1252 +
 20.1253 +	spin_lock_irqsave(&xhci->complete_list_lock, flags);
 20.1254 +	head = &xhci->complete_list;
 20.1255 +	tmp = head->next;
 20.1256 +	while (tmp != head) {
 20.1257 +		struct urb_priv *urbp = list_entry(tmp, struct urb_priv, complete_list);
 20.1258 +		struct urb *urb = urbp->urb;
 20.1259 +
 20.1260 +		list_del_init(&urbp->complete_list);
 20.1261 +		spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
 20.1262 +
 20.1263 +		xhci_call_completion(urb);
 20.1264 +
 20.1265 +		spin_lock_irqsave(&xhci->complete_list_lock, flags);
 20.1266 +		head = &xhci->complete_list;
 20.1267 +		tmp = head->next;
 20.1268 +	}
 20.1269 +	spin_unlock_irqrestore(&xhci->complete_list_lock, flags);
 20.1270 +}
 20.1271 +
 20.1272 +void receive_usb_reset(usbif_response_t *resp)
 20.1273 +{
 20.1274 +    awaiting_reset = resp->status;
 20.1275 +    rmb();
 20.1276 +    
 20.1277 +}
 20.1278 +
 20.1279 +void receive_usb_probe(usbif_response_t *resp)
 20.1280 +{
 20.1281 +    spin_lock(&xhci->rh.port_state_lock);
 20.1282 +
 20.1283 +    if ( resp->status > 0 )
 20.1284 +    {
 20.1285 +        if ( resp->status == 1 )
 20.1286 +        {
 20.1287 +/* 	  printk("hey hey, there's a device on port %d\n", resp->data); */
 20.1288 +
 20.1289 +            /* If theres a device there and there wasn't one before there must
 20.1290 +             * have been a connection status change. */
 20.1291 +            if( xhci->rh.ports[resp->data].cs == 0 )
 20.1292 +	    {
 20.1293 +                xhci->rh.ports[resp->data].cs = 1;
 20.1294 +                xhci->rh.ports[resp->data].ccs = 1;
 20.1295 +                xhci->rh.ports[resp->data].cs_chg = 1;
 20.1296 +/* 		printk("Look at device on port %d that wasn't there before\n", resp->data); */
 20.1297 +	    }
 20.1298 +        }
 20.1299 +        else
 20.1300 +            printk("receive_usb_probe(): unexpected status %d for port %d\n",
 20.1301 +                   resp->status, resp->data);
 20.1302 +    }
 20.1303 +    else if ( resp->status < 0)
 20.1304 +        printk("receive_usb_probe(): got error status %d\n", resp->status);
 20.1305 +
 20.1306 +    spin_unlock(&xhci->rh.port_state_lock);
 20.1307 +}
 20.1308 +
 20.1309 +void receive_usb_io(usbif_response_t *resp)
 20.1310 +{
 20.1311 +        struct urb_priv *urbp = (struct urb_priv *)resp->id;
 20.1312 +        struct urb *urb = urbp->urb;
 20.1313 +
 20.1314 +        urb->actual_length = resp->length;
 20.1315 +	urb->status = resp->status;
 20.1316 +	urbp->status = resp->status;
 20.1317 +        urbp->in_progress = 0;
 20.1318 +
 20.1319 +        if( usb_pipetype(urb->pipe) == 0 ) /* ISO */
 20.1320 +        {
 20.1321 +                int i;
 20.1322 +              
 20.1323 +                /* Copy ISO schedule results back in. */
 20.1324 +
 20.1325 +                for ( i = 0; i < urb->number_of_packets; i++ )
 20.1326 +                {
 20.1327 +                        urb->iso_frame_desc[i].status
 20.1328 +			  = urbp->schedule[i].status;
 20.1329 +                        urb->iso_frame_desc[i].actual_length
 20.1330 +                                = urbp->schedule[i].length;
 20.1331 +                }
 20.1332 +                free_page((unsigned long)urbp->schedule);
 20.1333 +        }
 20.1334 +}
 20.1335 +
 20.1336 +static void xhci_drain_ring(void)
 20.1337 +{
 20.1338 +	struct list_head *tmp, *head;
 20.1339 +	usbif_t *usb_ring = xhci->usbif;
 20.1340 +	usbif_response_t *resp;
 20.1341 +        USBIF_RING_IDX i, rp;
 20.1342 +
 20.1343 +        /* Walk the ring here to get responses, updating URBs to show what
 20.1344 +         * completed. */
 20.1345 +        
 20.1346 +        rp = usb_ring->resp_prod;
 20.1347 +        rmb(); /* Ensure we see queued requests up to 'rp'. */
 20.1348 +
 20.1349 +        /* Take items off the comms ring, taking care not to overflow. */
 20.1350 +        for ( i = xhci->usb_resp_cons; 
 20.1351 +              (i != rp) && ((i-usb_ring->req_prod) != USBIF_RING_SIZE);
 20.1352 +              i++ )
 20.1353 +        {
 20.1354 +            resp = &usb_ring->ring[MASK_USBIF_IDX(i)].resp;
 20.1355 +            
 20.1356 +            /* May need to deal with batching and with putting a ceiling on
 20.1357 +               the number dispatched for performance and anti-dos reasons */
 20.1358 +
 20.1359 +#if 0
 20.1360 +            printk("usbfront: Processing response:\n");
 20.1361 +            printk("          id = 0x%x\n", resp->id);
 20.1362 +            printk("          op = %d\n", resp->operation);
 20.1363 +            printk("          status = %d\n", resp->status);
 20.1364 +            printk("          length = %d\n", resp->length);
 20.1365 +#endif            
 20.1366 +
 20.1367 +            switch ( resp->operation )
 20.1368 +            {
 20.1369 +            case USBIF_OP_PROBE:
 20.1370 +                receive_usb_probe(resp);
 20.1371 +                break;
 20.1372 +                
 20.1373 +            case USBIF_OP_IO:
 20.1374 +                receive_usb_io(resp);
 20.1375 +                break;
 20.1376 +
 20.1377 +            case USBIF_OP_RESET:
 20.1378 +                receive_usb_reset(resp);
 20.1379 +                break;
 20.1380 +
 20.1381 +            default:
 20.1382 +                printk("error: unknown USB io operation response [%d]\n",
 20.1383 +                       usb_ring->ring[i].req.operation);
 20.1384 +                break;
 20.1385 +            }
 20.1386 +        }
 20.1387 +
 20.1388 +        xhci->usb_resp_cons = i;
 20.1389 +
 20.1390 +	/* Walk the list of pending URB's to see which ones completed and do
 20.1391 +         * callbacks, etc. */
 20.1392 +	spin_lock(&xhci->urb_list_lock);
 20.1393 +	head = &xhci->urb_list;
 20.1394 +	tmp = head->next;
 20.1395 +	while (tmp != head) {
 20.1396 +                
 20.1397 +		struct urb *urb = list_entry(tmp, struct urb, urb_list);
 20.1398 +
 20.1399 +		tmp = tmp->next;
 20.1400 +
 20.1401 +		/* Checks the status and does all of the magic necessary */
 20.1402 +		xhci_transfer_result(xhci, urb);
 20.1403 +	}
 20.1404 +	spin_unlock(&xhci->urb_list_lock);
 20.1405 +
 20.1406 +	xhci_finish_completion();
 20.1407 +}
 20.1408 +
 20.1409 +
 20.1410 +static void xhci_interrupt(int irq, void *__xhci, struct pt_regs *regs)
 20.1411 +{
 20.1412 +        xhci_drain_ring();
 20.1413 +}
 20.1414 +
 20.1415 +static void free_xhci(struct xhci *xhci)
 20.1416 +{
 20.1417 +	kfree(xhci);
 20.1418 +}
 20.1419 +
 20.1420 +/* /\* */
 20.1421 +/*  * De-allocate all resources.. */
 20.1422 +/*  *\/ */
 20.1423 +/* static void release_xhci(struct xhci *xhci) */
 20.1424 +/* { */
 20.1425 +/* 	if (xhci->irq >= 0) { */
 20.1426 +/* 		free_irq(xhci->irq, xhci); */
 20.1427 +/* 		xhci->irq = -1; */
 20.1428 +/* 	} */
 20.1429 +
 20.1430 +/*         /\* Get the ring back from the backend domain.  Then free it.  Hmmmm. */
 20.1431 +/*          * Lets ignore this for now - not particularly useful. *\/ */
 20.1432 +
 20.1433 +/* 	free_xhci(xhci); */
 20.1434 +/* } */
 20.1435 +
 20.1436 +/**
 20.1437 + * Initialise a new virtual root hub for a new USB device channel.
 20.1438 + */
 20.1439 +static int alloc_xhci(void)
 20.1440 +{
 20.1441 +	int retval;
 20.1442 +	struct usb_bus *bus;
 20.1443 +
 20.1444 +	retval = -EBUSY;
 20.1445 +
 20.1446 +	xhci = kmalloc(sizeof(*xhci), GFP_KERNEL);
 20.1447 +	if (!xhci) {
 20.1448 +		err("couldn't allocate xhci structure");
 20.1449 +		retval = -ENOMEM;
 20.1450 +		goto err_alloc_xhci;
 20.1451 +	}
 20.1452 +
 20.1453 +	/* Reset here so we don't get any interrupts from an old setup */
 20.1454 +	/*  or broken setup */
 20.1455 +	//	reset_hc(xhci);
 20.1456 +
 20.1457 +
 20.1458 +	xhci->state = USBIF_STATE_CLOSED;
 20.1459 +	xhci->is_suspended = 0;
 20.1460 +
 20.1461 +	spin_lock_init(&xhci->urb_remove_list_lock);
 20.1462 +	INIT_LIST_HEAD(&xhci->urb_remove_list);
 20.1463 +
 20.1464 +	spin_lock_init(&xhci->urb_list_lock);
 20.1465 +	INIT_LIST_HEAD(&xhci->urb_list);
 20.1466 +
 20.1467 +	spin_lock_init(&xhci->complete_list_lock);
 20.1468 +	INIT_LIST_HEAD(&xhci->complete_list);
 20.1469 +
 20.1470 +	spin_lock_init(&xhci->frame_list_lock);
 20.1471 +
 20.1472 +	/* We need exactly one page (per XHCI specs), how convenient */
 20.1473 +	/* We assume that one page is atleast 4k (1024 frames * 4 bytes) */
 20.1474 +#if PAGE_SIZE < (4 * 1024)
 20.1475 +#error PAGE_SIZE is not atleast 4k
 20.1476 +#endif
 20.1477 +	bus = usb_alloc_bus(&xhci_device_operations);
 20.1478 +	if (!bus) {
 20.1479 +		err("unable to allocate bus");
 20.1480 +		goto err_alloc_bus;
 20.1481 +	}
 20.1482 +
 20.1483 +	xhci->bus = bus;
 20.1484 +	bus->bus_name = "XHCI";
 20.1485 +	bus->hcpriv = xhci;
 20.1486 +
 20.1487 +	usb_register_bus(xhci->bus);
 20.1488 +
 20.1489 +	/* Initialize the root hub */
 20.1490 +
 20.1491 +	xhci->rh.numports = 0;
 20.1492 +
 20.1493 +	xhci->bus->root_hub = xhci->rh.dev = usb_alloc_dev(NULL, xhci->bus);
 20.1494 +	if (!xhci->rh.dev) {
 20.1495 +		err("unable to allocate root hub");
 20.1496 +		goto err_alloc_root_hub;
 20.1497 +	}
 20.1498 +
 20.1499 +	xhci->state = 0;
 20.1500 +
 20.1501 +	return 0;
 20.1502 +
 20.1503 +/*
 20.1504 + * error exits:
 20.1505 + */
 20.1506 +err_start_root_hub:
 20.1507 +	free_irq(xhci->irq, xhci);
 20.1508 +	xhci->irq = -1;
 20.1509 +
 20.1510 +err_alloc_root_hub:
 20.1511 +	usb_free_bus(xhci->bus);
 20.1512 +	xhci->bus = NULL;
 20.1513 +
 20.1514 +err_alloc_bus:
 20.1515 +	free_xhci(xhci);
 20.1516 +
 20.1517 +err_alloc_xhci:
 20.1518 +	return retval;
 20.1519 +}
 20.1520 +
 20.1521 +static void usbif_status_change(usbif_fe_interface_status_changed_t *status)
 20.1522 +{
 20.1523 +    ctrl_msg_t                   cmsg;
 20.1524 +    usbif_fe_interface_connect_t up;
 20.1525 +    long rc;
 20.1526 +    usbif_t *usbif;
 20.1527 +
 20.1528 +    switch ( status->status )
 20.1529 +    {
 20.1530 +    case USBIF_INTERFACE_STATUS_DESTROYED:
 20.1531 +        printk(KERN_WARNING "Unexpected usbif-DESTROYED message in state %d\n",
 20.1532 +               xhci->state);
 20.1533 +        break;
 20.1534 +
 20.1535 +    case USBIF_INTERFACE_STATUS_DISCONNECTED:
 20.1536 +        if ( xhci->state != USBIF_STATE_CLOSED )
 20.1537 +        {
 20.1538 +            printk(KERN_WARNING "Unexpected usbif-DISCONNECTED message"
 20.1539 +                   " in state %d\n", xhci->state);
 20.1540 +            break;
 20.1541 +            /* Not bothering to do recovery here for now.  Keep things
 20.1542 +             * simple. */
 20.1543 +        }
 20.1544 +
 20.1545 +        /* Move from CLOSED to DISCONNECTED state. */
 20.1546 +        xhci->usbif = usbif = (usbif_t *)__get_free_page(GFP_KERNEL);
 20.1547 +        usbif->req_prod = usbif->resp_prod = 0;
 20.1548 +        xhci->state  = USBIF_STATE_DISCONNECTED;
 20.1549 +
 20.1550 +        /* Construct an interface-CONNECT message for the domain controller. */
 20.1551 +        cmsg.type      = CMSG_USBIF_FE;
 20.1552 +        cmsg.subtype   = CMSG_USBIF_FE_INTERFACE_CONNECT;
 20.1553 +        cmsg.length    = sizeof(usbif_fe_interface_connect_t);
 20.1554 +        up.shmem_frame = virt_to_machine(usbif) >> PAGE_SHIFT;
 20.1555 +        memcpy(cmsg.msg, &up, sizeof(up));
 20.1556 +        
 20.1557 +        /* Tell the controller to bring up the interface. */
 20.1558 +        ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
 20.1559 +        break;
 20.1560 +
 20.1561 +    case USBIF_INTERFACE_STATUS_CONNECTED:
 20.1562 +        if ( xhci->state == USBIF_STATE_CLOSED )
 20.1563 +        {
 20.1564 +            printk(KERN_WARNING "Unexpected usbif-CONNECTED message"
 20.1565 +                   " in state %d\n", xhci->state);
 20.1566 +            break;
 20.1567 +        }
 20.1568 +
 20.1569 +        xhci->evtchn = status->evtchn;
 20.1570 +        xhci->irq = bind_evtchn_to_irq(xhci->evtchn);
 20.1571 +	xhci->bandwidth = status->bandwidth;
 20.1572 +	xhci->rh.numports = status->num_ports;
 20.1573 +
 20.1574 +        xhci->rh.ports = kmalloc (sizeof(xhci_port_t) * xhci->rh.numports, GFP_KERNEL);
 20.1575 +        memset(xhci->rh.ports, 0, sizeof(xhci_port_t) * xhci->rh.numports);
 20.1576 +
 20.1577 +        printk("rh.dev @ %p\n", xhci->rh.dev);
 20.1578 +
 20.1579 +	usb_connect(xhci->rh.dev);
 20.1580 +
 20.1581 +	if (usb_new_device(xhci->rh.dev) != 0) {
 20.1582 +		err("unable to start root hub");
 20.1583 +	}
 20.1584 +
 20.1585 +	/* Allocate the appropriate USB bandwidth here...  Need to
 20.1586 +	* somehow know what the total available is thought to be so we
 20.1587 +	* can calculate the reservation correctly. */
 20.1588 + 	usb_claim_bandwidth(xhci->rh.dev, xhci->rh.urb,
 20.1589 + 			    1000 - xhci->bandwidth, 0);
 20.1590 +
 20.1591 +        if ( (rc = request_irq(xhci->irq, xhci_interrupt, 
 20.1592 +                               SA_SAMPLE_RANDOM, "usbif", xhci)) )
 20.1593 +                printk(KERN_ALERT"usbfront request_irq failed (%ld)\n",rc);
 20.1594 +
 20.1595 +	printk(KERN_INFO __FILE__ ": USB XHCI: SHM at %p (0x%lx), EVTCHN %d IRQ %d\n",
 20.1596 +               xhci->usbif, virt_to_machine(xhci->usbif), xhci->evtchn, xhci->irq);
 20.1597 +
 20.1598 +        xhci->state = USBIF_STATE_CONNECTED;
 20.1599 +        
 20.1600 +        break;
 20.1601 +
 20.1602 +    default:
 20.1603 +        printk(KERN_WARNING "Status change to unknown value %d\n", 
 20.1604 +               status->status);
 20.1605 +        break;
 20.1606 +    }
 20.1607 +}
 20.1608 +
 20.1609 +
 20.1610 +static void usbif_ctrlif_rx(ctrl_msg_t *msg, unsigned long id)
 20.1611 +{
 20.1612 +    switch ( msg->subtype )
 20.1613 +    {
 20.1614 +    case CMSG_USBIF_FE_INTERFACE_STATUS_CHANGED:
 20.1615 +        if ( msg->length != sizeof(usbif_fe_interface_status_changed_t) )
 20.1616 +            goto parse_error;
 20.1617 +        usbif_status_change((usbif_fe_interface_status_changed_t *)
 20.1618 +                            &msg->msg[0]);
 20.1619 +        break;        
 20.1620 +
 20.1621 +        /* New interface...? */
 20.1622 +    default:
 20.1623 +        goto parse_error;
 20.1624 +    }
 20.1625 +
 20.1626 +    ctrl_if_send_response(msg);
 20.1627 +    return;
 20.1628 +
 20.1629 + parse_error:
 20.1630 +    msg->length = 0;
 20.1631 +    ctrl_if_send_response(msg);
 20.1632 +}
 20.1633 +
 20.1634 +
 20.1635 +static int __init xhci_hcd_init(void)
 20.1636 +{
 20.1637 +	int retval = -ENOMEM, i;
 20.1638 +        usbif_fe_interface_status_changed_t st;
 20.1639 +        control_msg_t cmsg;
 20.1640 +
 20.1641 +	if ( (xen_start_info.flags & SIF_INITDOMAIN)
 20.1642 +	     || (xen_start_info.flags & SIF_USB_BE_DOMAIN) )
 20.1643 +                return 0;
 20.1644 +
 20.1645 +	info(DRIVER_DESC " " DRIVER_VERSION);
 20.1646 +
 20.1647 +	if (debug) {
 20.1648 +		errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL);
 20.1649 +		if (!errbuf)
 20.1650 +			goto errbuf_failed;
 20.1651 +	}
 20.1652 +
 20.1653 +	xhci_up_cachep = kmem_cache_create("xhci_urb_priv",
 20.1654 +		sizeof(struct urb_priv), 0, 0, NULL, NULL);
 20.1655 +	if (!xhci_up_cachep)
 20.1656 +		goto up_failed;
 20.1657 +
 20.1658 +        /* Lazily avoid unloading issues for now. ;-)*/
 20.1659 +	MOD_INC_USE_COUNT;
 20.1660 +
 20.1661 +        /* Let the domain controller know we're here.  For now we wait until
 20.1662 +         * connection, as for the block and net drivers.  This is only strictly
 20.1663 +         * necessary if we're going to boot off a USB device. */
 20.1664 +        printk(KERN_INFO "Initialising Xen virtual USB hub\n");
 20.1665 +    
 20.1666 +        (void)ctrl_if_register_receiver(CMSG_USBIF_FE, usbif_ctrlif_rx,
 20.1667 +                                        CALLBACK_IN_BLOCKING_CONTEXT);
 20.1668 +        
 20.1669 +	alloc_xhci();
 20.1670 +
 20.1671 +        /* Send a driver-UP notification to the domain controller. */
 20.1672 +        cmsg.type      = CMSG_USBIF_FE;
 20.1673 +        cmsg.subtype   = CMSG_USBIF_FE_DRIVER_STATUS_CHANGED;
 20.1674 +        cmsg.length    = sizeof(usbif_fe_driver_status_changed_t);
 20.1675 +        st.status      = USBIF_DRIVER_STATUS_UP;
 20.1676 +        memcpy(cmsg.msg, &st, sizeof(st));
 20.1677 +        ctrl_if_send_message_block(&cmsg, NULL, 0, TASK_UNINTERRUPTIBLE);
 20.1678 +        
 20.1679 +        /*
 20.1680 +         * We should read 'nr_interfaces' from response message and wait
 20.1681 +         * for notifications before proceeding. For now we assume that we
 20.1682 +         * will be notified of exactly one interface.
 20.1683 +         */
 20.1684 +        for ( i=0; (xhci->state != USBIF_STATE_CONNECTED) && (i < 10*HZ); i++ )
 20.1685 +        {
 20.1686 +            set_current_state(TASK_INTERRUPTIBLE);
 20.1687 +            schedule_timeout(1);
 20.1688 +        }
 20.1689 +        
 20.1690 +        if (xhci->state != USBIF_STATE_CONNECTED)
 20.1691 +            printk(KERN_INFO "Timeout connecting USB frontend driver!\n");
 20.1692 +	
 20.1693 +	return 0;
 20.1694 +
 20.1695 +up_failed:
 20.1696 +
 20.1697 +	if (errbuf)
 20.1698 +		kfree(errbuf);
 20.1699 +
 20.1700 +errbuf_failed:
 20.1701 +
 20.1702 +	return retval;
 20.1703 +}
 20.1704 +
 20.1705 +static void __exit xhci_hcd_cleanup(void) 
 20.1706 +{
 20.1707 +	if (kmem_cache_destroy(xhci_up_cachep))
 20.1708 +		printk(KERN_INFO "xhci: not all urb_priv's were freed\n");
 20.1709 +
 20.1710 +//        release_xhci(); do some calls here
 20.1711 +
 20.1712 +
 20.1713 +	if (errbuf)
 20.1714 +		kfree(errbuf);
 20.1715 +}
 20.1716 +
 20.1717 +module_init(xhci_hcd_init);
 20.1718 +module_exit(xhci_hcd_cleanup);
 20.1719 +
 20.1720 +MODULE_AUTHOR(DRIVER_AUTHOR);
 20.1721 +MODULE_DESCRIPTION(DRIVER_DESC);
 20.1722 +MODULE_LICENSE("GPL");
 20.1723 +
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/frontend/xhci.h	Sat Jan 22 15:52:51 2005 +0000
    21.3 @@ -0,0 +1,210 @@
    21.4 +#ifndef __LINUX_XHCI_H
    21.5 +#define __LINUX_XHCI_H
    21.6 +
    21.7 +#include <linux/list.h>
    21.8 +#include <linux/usb.h>
    21.9 +#include "../usbif.h"
   21.10 +#include <linux/spinlock.h>
   21.11 +
   21.12 +#define XHCI_NUMFRAMES		1024	/* in the frame list [array] */
   21.13 +#define XHCI_MAX_SOF_NUMBER	2047	/* in an SOF packet */
   21.14 +#define CAN_SCHEDULE_FRAMES	1000	/* how far future frames can be scheduled */
   21.15 +
   21.16 +/* In the absence of actual hardware state, we maintain the current known state
   21.17 + * of the virtual hub ports in this data structure.
   21.18 + */
   21.19 +typedef struct
   21.20 +{
   21.21 +        unsigned int cs     :1;     /* Connection status.  do we really need this /and/ ccs? */
   21.22 +        unsigned int cs_chg :1; /* Connection status change.  */
   21.23 +        unsigned int pe     :1;     /* Port enable.               */
   21.24 +        unsigned int pe_chg :1; /* Port enable change.        */
   21.25 +        unsigned int ccs    :1;    /* Current connect status.    */
   21.26 +        unsigned int susp   :1;   /* Suspended.                 */
   21.27 +        unsigned int lsda   :1;   /* Low speed device attached. */
   21.28 +        unsigned int pr     :1;     /* Port reset.                */
   21.29 +        
   21.30 +    /* Device info? */
   21.31 +} xhci_port_t;
   21.32 +
   21.33 +struct xhci_frame_list {
   21.34 +	__u32 frame[XHCI_NUMFRAMES];
   21.35 +
   21.36 +	void *frame_cpu[XHCI_NUMFRAMES];
   21.37 +};
   21.38 +
   21.39 +struct urb_priv;
   21.40 +
   21.41 +#define xhci_status_bits(ctrl_sts)	(ctrl_sts & 0xFE0000)
   21.42 +#define xhci_actual_length(ctrl_sts)	((ctrl_sts + 1) & TD_CTRL_ACTLEN_MASK) /* 1-based */
   21.43 +
   21.44 +#define xhci_maxlen(token)	((token) >> 21)
   21.45 +#define xhci_expected_length(info) (((info >> 21) + 1) & TD_TOKEN_EXPLEN_MASK) /* 1-based */
   21.46 +#define xhci_toggle(token)	(((token) >> TD_TOKEN_TOGGLE_SHIFT) & 1)
   21.47 +#define xhci_endpoint(token)	(((token) >> 15) & 0xf)
   21.48 +#define xhci_devaddr(token)	(((token) >> 8) & 0x7f)
   21.49 +#define xhci_devep(token)	(((token) >> 8) & 0x7ff)
   21.50 +#define xhci_packetid(token)	((token) & TD_TOKEN_PID_MASK)
   21.51 +#define xhci_packetout(token)	(xhci_packetid(token) != USB_PID_IN)
   21.52 +#define xhci_packetin(token)	(xhci_packetid(token) == USB_PID_IN)
   21.53 +
   21.54 +struct virt_root_hub {
   21.55 +	struct usb_device *dev;
   21.56 +	int devnum;		/* Address of Root Hub endpoint */
   21.57 +	struct urb *urb;
   21.58 +	void *int_addr;
   21.59 +	int send;
   21.60 +	int interval;
   21.61 +	int numports;
   21.62 +	int c_p_r[8];
   21.63 +	struct timer_list rh_int_timer;
   21.64 +        spinlock_t port_state_lock;
   21.65 +        xhci_port_t *ports;       /*  */
   21.66 +};
   21.67 +
   21.68 +/*
   21.69 + * This describes the full xhci information.
   21.70 + *
   21.71 + * Note how the "proper" USB information is just
   21.72 + * a subset of what the full implementation needs.
   21.73 + */
   21.74 +struct xhci {
   21.75 +
   21.76 +#ifdef CONFIG_PROC_FS
   21.77 +	/* procfs */
   21.78 +	int num;
   21.79 +	struct proc_dir_entry *proc_entry;
   21.80 +#endif
   21.81 +
   21.82 +        int evtchn;                        /* Interdom channel to backend */
   21.83 +        int irq;                           /* Bound to evtchn */
   21.84 +        int state;                         /* State of this USB interface */
   21.85 +        unsigned long bandwidth;
   21.86 +        int handle;
   21.87 +
   21.88 +	struct usb_bus *bus;
   21.89 +
   21.90 +	spinlock_t frame_list_lock;
   21.91 +	struct xhci_frame_list *fl;		/* P: xhci->frame_list_lock */
   21.92 +	int is_suspended;
   21.93 +
   21.94 +	/* Main list of URB's currently controlled by this HC */
   21.95 +	spinlock_t urb_list_lock;
   21.96 +	struct list_head urb_list;		/* P: xhci->urb_list_lock */
   21.97 +
   21.98 +	/* List of asynchronously unlinked URB's */
   21.99 +	spinlock_t urb_remove_list_lock;
  21.100 +	struct list_head urb_remove_list;	/* P: xhci->urb_remove_list_lock */
  21.101 +
  21.102 +	/* List of URB's awaiting completion callback */
  21.103 +	spinlock_t complete_list_lock;
  21.104 +	struct list_head complete_list;		/* P: xhci->complete_list_lock */
  21.105 +
  21.106 +	struct virt_root_hub rh;	/* private data of the virtual root hub */
  21.107 +
  21.108 +        spinlock_t response_lock;
  21.109 +
  21.110 +        usbif_t *usbif;
  21.111 +        int usb_resp_cons;
  21.112 +};
  21.113 +
  21.114 +struct urb_priv {
  21.115 +	struct urb *urb;
  21.116 +        usbif_iso_t *schedule;
  21.117 +	struct usb_device *dev;
  21.118 +
  21.119 +        int in_progress : 1;	        /* QH was queued (not linked in) */
  21.120 +	int short_control_packet : 1;	/* If we get a short packet during */
  21.121 +					/*  a control transfer, retrigger */
  21.122 +					/*  the status phase */
  21.123 +
  21.124 +	int status;			/* Final status */
  21.125 +
  21.126 +	unsigned long inserttime;	/* In jiffies */
  21.127 +
  21.128 +	struct list_head queue_list;	/* P: xhci->frame_list_lock */
  21.129 +	struct list_head complete_list;	/* P: xhci->complete_list_lock */
  21.130 +};
  21.131 +
  21.132 +/*
  21.133 + * Locking in xhci.c
  21.134 + *
  21.135 + * spinlocks are used extensively to protect the many lists and data
  21.136 + * structures we have. It's not that pretty, but it's necessary. We
  21.137 + * need to be done with all of the locks (except complete_list_lock) when
  21.138 + * we call urb->complete. I've tried to make it simple enough so I don't
  21.139 + * have to spend hours racking my brain trying to figure out if the
  21.140 + * locking is safe.
  21.141 + *
  21.142 + * Here's the safe locking order to prevent deadlocks:
  21.143 + *
  21.144 + * #1 xhci->urb_list_lock
  21.145 + * #2 urb->lock
  21.146 + * #3 xhci->urb_remove_list_lock, xhci->frame_list_lock, 
  21.147 + *   xhci->qh_remove_list_lock
  21.148 + * #4 xhci->complete_list_lock
  21.149 + *
  21.150 + * If you're going to grab 2 or more locks at once, ALWAYS grab the lock
  21.151 + * at the lowest level FIRST and NEVER grab locks at the same level at the
  21.152 + * same time.
  21.153 + * 
  21.154 + * So, if you need xhci->urb_list_lock, grab it before you grab urb->lock
  21.155 + */
  21.156 +
  21.157 +/* -------------------------------------------------------------------------
  21.158 +   Virtual Root HUB
  21.159 +   ------------------------------------------------------------------------- */
  21.160 +/* destination of request */
  21.161 +#define RH_DEVICE		0x00
  21.162 +#define RH_INTERFACE		0x01
  21.163 +#define RH_ENDPOINT		0x02
  21.164 +#define RH_OTHER		0x03
  21.165 +
  21.166 +#define RH_CLASS		0x20
  21.167 +#define RH_VENDOR		0x40
  21.168 +
  21.169 +/* Requests: bRequest << 8 | bmRequestType */
  21.170 +#define RH_GET_STATUS		0x0080
  21.171 +#define RH_CLEAR_FEATURE	0x0100
  21.172 +#define RH_SET_FEATURE		0x0300
  21.173 +#define RH_SET_ADDRESS		0x0500
  21.174 +#define RH_GET_DESCRIPTOR	0x0680
  21.175 +#define RH_SET_DESCRIPTOR	0x0700
  21.176 +#define RH_GET_CONFIGURATION	0x0880
  21.177 +#define RH_SET_CONFIGURATION	0x0900
  21.178 +#define RH_GET_STATE		0x0280
  21.179 +#define RH_GET_INTERFACE	0x0A80
  21.180 +#define RH_SET_INTERFACE	0x0B00
  21.181 +#define RH_SYNC_FRAME		0x0C80
  21.182 +/* Our Vendor Specific Request */
  21.183 +#define RH_SET_EP		0x2000
  21.184 +
  21.185 +/* Hub port features */
  21.186 +#define RH_PORT_CONNECTION	0x00
  21.187 +#define RH_PORT_ENABLE		0x01
  21.188 +#define RH_PORT_SUSPEND		0x02
  21.189 +#define RH_PORT_OVER_CURRENT	0x03
  21.190 +#define RH_PORT_RESET		0x04
  21.191 +#define RH_PORT_POWER		0x08
  21.192 +#define RH_PORT_LOW_SPEED	0x09
  21.193 +#define RH_C_PORT_CONNECTION	0x10
  21.194 +#define RH_C_PORT_ENABLE	0x11
  21.195 +#define RH_C_PORT_SUSPEND	0x12
  21.196 +#define RH_C_PORT_OVER_CURRENT	0x13
  21.197 +#define RH_C_PORT_RESET		0x14
  21.198 +
  21.199 +/* Hub features */
  21.200 +#define RH_C_HUB_LOCAL_POWER	0x00
  21.201 +#define RH_C_HUB_OVER_CURRENT	0x01
  21.202 +#define RH_DEVICE_REMOTE_WAKEUP	0x00
  21.203 +#define RH_ENDPOINT_STALL	0x01
  21.204 +
  21.205 +/* Our Vendor Specific feature */
  21.206 +#define RH_REMOVE_EP		0x00
  21.207 +
  21.208 +#define RH_ACK			0x01
  21.209 +#define RH_REQ_ERR		-1
  21.210 +#define RH_NACK			0x00
  21.211 +
  21.212 +#endif
  21.213 +
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/linux-2.4.29-xen-sparse/arch/xen/drivers/usbif/usbif.h	Sat Jan 22 15:52:51 2005 +0000
    22.3 @@ -0,0 +1,111 @@
    22.4 +/******************************************************************************
    22.5 + * usbif.h
    22.6 + * 
    22.7 + * Unified block-device I/O interface for Xen guest OSes.
    22.8 + * 
    22.9 + * Copyright (c) 2003-2004, Keir Fraser
   22.10 + */
   22.11 +
   22.12 +#ifndef __SHARED_USBIF_H__
   22.13 +#define __SHARED_USBIF_H__
   22.14 +
   22.15 +#define usbif_vdev_t   u16
   22.16 +#define usbif_sector_t u64
   22.17 +
   22.18 +#define USBIF_OP_IO      0
   22.19 +#define USBIF_OP_PROBE   1 /* Is there a device on this port? */
   22.20 +#define USBIF_OP_RESET   2 /* Reset a virtual USB port.       */
   22.21 +
   22.22 +/* NB. Ring size must be small enough for sizeof(usbif_ring_t) <= PAGE_SIZE. */
   22.23 +#define USBIF_RING_SIZE        64
   22.24 +
   22.25 +/* XXX this does not want to be here!  it really ought to be dynamic but it can
   22.26 + * live here for now */
   22.27 +#define NUM_PORTS 1
   22.28 +
   22.29 +typedef struct {
   22.30 +    unsigned long  id;           /*  0: private guest value, echoed in resp  */
   22.31 +    u8             operation;    /*  4: USBIF_OP_???                         */
   22.32 +    u8  __pad1;
   22.33 +    usbif_vdev_t   port;         /* 6 : guest virtual USB port               */
   22.34 +    unsigned long  devnum :7;    /* 8 : Device address, as seen by the guest.*/
   22.35 +    unsigned long  endpoint :4;  /* Device endpoint.                         */
   22.36 +    unsigned long  direction :1; /* Pipe direction.                          */
   22.37 +    unsigned long  speed :1;     /* Pipe speed.                              */
   22.38 +    unsigned long  pipe_type :2; /* Pipe type (iso, bulk, int, ctrl)         */
   22.39 +    unsigned long  __pad2 :18;
   22.40 +    unsigned long  transfer_buffer; /* 12: Machine address */
   22.41 +    unsigned long  length;          /* 16: Buffer length */
   22.42 +    unsigned long  transfer_flags;  /* 20: For now just pass Linux transfer
   22.43 +                                     * flags - this may change. */
   22.44 +    unsigned char setup[8];         /* 22 Embed setup packets directly. */
   22.45 +    unsigned long  iso_schedule;    /* 30 Machine address of transfer sched (iso
   22.46 +                                     * only) */
   22.47 +    unsigned long num_iso;        /* 34 : length of iso schedule */
   22.48 +    unsigned long timeout;        /* 38: timeout in ms */
   22.49 +} PACKED usbif_request_t; /* 42 */
   22.50 +/* Data we need to pass:
   22.51 + * - Transparently handle short packets or complain at us?
   22.52 + */
   22.53 +
   22.54 +typedef struct {
   22.55 +    unsigned long   id;              /* 0: copied from request         */
   22.56 +    u8              operation;       /* 4: copied from request         */
   22.57 +    u8              data;            /* 5: Small chunk of in-band data */
   22.58 +    s16             status;          /* 6: USBIF_RSP_???               */
   22.59 +    unsigned long   transfer_mutex;  /* Used for cancelling requests atomically. */
   22.60 +    unsigned long    length;          /* 8: How much data we really got */
   22.61 +} PACKED usbif_response_t;
   22.62 +
   22.63 +#define USBIF_RSP_ERROR  -1 /* non-specific 'error' */
   22.64 +#define USBIF_RSP_OKAY    0 /* non-specific 'okay'  */
   22.65 +
   22.66 +/*
   22.67 + * We use a special capitalised type name because it is _essential_ that all 
   22.68 + * arithmetic on indexes is done on an integer type of the correct size.
   22.69 + */
   22.70 +typedef u32 USBIF_RING_IDX;
   22.71 +
   22.72 +/*
   22.73 + * Ring indexes are 'free running'. That is, they are not stored modulo the
   22.74 + * size of the ring buffer. The following macro converts a free-running counter
   22.75 + * into a value that can directly index a ring-buffer array.
   22.76 + */
   22.77 +#define MASK_USBIF_IDX(_i) ((_i)&(USBIF_RING_SIZE-1))
   22.78 +
   22.79 +typedef struct {
   22.80 +    USBIF_RING_IDX req_prod;  /*  0: Request producer. Updated by front-end. */
   22.81 +    USBIF_RING_IDX resp_prod; /*  4: Response producer. Updated by back-end. */
   22.82 +
   22.83 +    union {                   /*  8 */
   22.84 +        usbif_request_t  req;
   22.85 +        usbif_response_t resp;
   22.86 +    } PACKED ring[USBIF_RING_SIZE];
   22.87 +} PACKED usbif_t;
   22.88 +
   22.89 +
   22.90 +
   22.91 +/*
   22.92 + * USBIF_OP_PROBE:
   22.93 + * The request format for a probe request is constrained as follows:
   22.94 + *  @operation   == USBIF_OP_PROBE
   22.95 + *  @nr_segments == size of probe buffer in pages
   22.96 + *  @device      == unused (zero)
   22.97 + *  @id          == any value (echoed in response message)
   22.98 + *  @sector_num  == unused (zero)
   22.99 + *  @frame_and_sects == list of page-sized buffers.
  22.100 + *                       (i.e., @first_sect == 0, @last_sect == 7).
  22.101 + * 
  22.102 + * The response is a list of vdisk_t elements copied into the out-of-band
  22.103 + * probe buffer. On success the response status field contains the number
  22.104 + * of vdisk_t elements.
  22.105 + */
  22.106 +
  22.107 +typedef struct {
  22.108 +    unsigned long length; /* IN = expected, OUT = actual */
  22.109 +    unsigned long buffer_offset;  /* IN offset in buffer specified in main
  22.110 +                                     packet */
  22.111 +    unsigned long status; /* OUT Status for this packet. */
  22.112 +} usbif_iso_t;
  22.113 +
  22.114 +#endif /* __SHARED_USBIF_H__ */