diff options
Diffstat (limited to 'drivers/staging/ozwpan/ozhcd.c')
-rw-r--r-- | drivers/staging/ozwpan/ozhcd.c | 722 |
1 files changed, 411 insertions, 311 deletions
diff --git a/drivers/staging/ozwpan/ozhcd.c b/drivers/staging/ozwpan/ozhcd.c index d68d63a2e683..d9c43c3282e7 100644 --- a/drivers/staging/ozwpan/ozhcd.c +++ b/drivers/staging/ozwpan/ozhcd.c @@ -26,31 +26,42 @@ */ #include <linux/platform_device.h> #include <linux/usb.h> -#include <linux/jiffies.h> #include <linux/slab.h> #include <linux/export.h> #include "linux/usb/hcd.h" #include <asm/unaligned.h> -#include "ozconfig.h" +#include "ozdbg.h" #include "ozusbif.h" -#include "oztrace.h" #include "ozurbparanoia.h" #include "ozhcd.h" -/*------------------------------------------------------------------------------ + +/* * Number of units of buffering to capture for an isochronous IN endpoint before * allowing data to be indicated up. */ -#define OZ_IN_BUFFERING_UNITS 50 +#define OZ_IN_BUFFERING_UNITS 100 + /* Name of our platform device. */ #define OZ_PLAT_DEV_NAME "ozwpan" + /* Maximum number of free urb links that can be kept in the pool. */ #define OZ_MAX_LINK_POOL_SIZE 16 + /* Get endpoint object from the containing link. */ #define ep_from_link(__e) container_of((__e), struct oz_endpoint, link) -/*------------------------------------------------------------------------------ + +/*EP0 timeout before ep0 request is again added to TX queue. (13*8 = 98mSec) + */ +#define EP0_TIMEOUT_COUNTER 13 + +/* Debounce time HCD driver should wait before unregistering. + */ +#define OZ_HUB_DEBOUNCE_TIMEOUT 1500 + +/* * Used to link urbs together and also store some status information for each * urb. * A cache of these are kept in a pool to reduce number of calls to kmalloc. @@ -61,16 +72,18 @@ struct oz_urb_link { struct oz_port *port; u8 req_id; u8 ep_num; - unsigned long submit_jiffies; + unsigned submit_counter; }; /* Holds state information about a USB endpoint. */ +#define OZ_EP_BUFFER_SIZE_ISOC (1024 * 24) +#define OZ_EP_BUFFER_SIZE_INT 512 struct oz_endpoint { struct list_head urb_list; /* List of oz_urb_link items. */ struct list_head link; /* For isoc ep, links in to isoc lists of oz_port. */ - unsigned long last_jiffies; + struct timespec timestamp; int credit; int credit_ceiling; u8 ep_num; @@ -83,6 +96,7 @@ struct oz_endpoint { unsigned flags; int start_frame; }; + /* Bits in the flags field. */ #define OZ_F_EP_BUFFERING 0x1 #define OZ_F_EP_HAVE_STREAM 0x2 @@ -113,6 +127,7 @@ struct oz_port { struct list_head isoc_out_ep; struct list_head isoc_in_ep; }; + #define OZ_PORT_F_PRESENT 0x1 #define OZ_PORT_F_CHANGED 0x2 #define OZ_PORT_F_DYING 0x4 @@ -130,11 +145,12 @@ struct oz_hcd { uint flags; struct usb_hcd *hcd; }; + /* Bits in flags field. */ #define OZ_HDC_F_SUSPENDED 0x1 -/*------------------------------------------------------------------------------ +/* * Static function prototypes. */ static int oz_hcd_start(struct usb_hcd *hcd); @@ -174,7 +190,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, struct urb *urb); static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status); -/*------------------------------------------------------------------------------ + +/* * Static external variables. */ static struct platform_device *g_plat_dev; @@ -188,6 +205,7 @@ static DEFINE_SPINLOCK(g_tasklet_lock); static struct tasklet_struct g_urb_process_tasklet; static struct tasklet_struct g_urb_cancel_tasklet; static atomic_t g_pending_urbs = ATOMIC_INIT(0); +static atomic_t g_usb_frame_number = ATOMIC_INIT(0); static const struct hc_driver g_oz_hc_drv = { .description = g_hcd_name, .product_desc = "Ozmo Devices WPAN", @@ -218,7 +236,8 @@ static struct platform_driver g_oz_plat_drv = { .owner = THIS_MODULE, }, }; -/*------------------------------------------------------------------------------ + +/* * Gets our private context area (which is of type struct oz_hcd) from the * usb_hcd structure. * Context: any @@ -227,7 +246,8 @@ static inline struct oz_hcd *oz_hcd_private(struct usb_hcd *hcd) { return (struct oz_hcd *)hcd->hcd_priv; } -/*------------------------------------------------------------------------------ + +/* * Searches list of ports to find the index of the one with a specified USB * bus address. If none of the ports has the bus address then the connection * port is returned, if there is one or -1 otherwise. @@ -236,13 +256,15 @@ static inline struct oz_hcd *oz_hcd_private(struct usb_hcd *hcd) static int oz_get_port_from_addr(struct oz_hcd *ozhcd, u8 bus_addr) { int i; + for (i = 0; i < OZ_NB_PORTS; i++) { if (ozhcd->ports[i].bus_addr == bus_addr) return i; } return ozhcd->conn_port; } -/*------------------------------------------------------------------------------ + +/* * Allocates an urb link, first trying the pool but going to heap if empty. * Context: any */ @@ -250,6 +272,7 @@ static struct oz_urb_link *oz_alloc_urb_link(void) { struct oz_urb_link *urbl = NULL; unsigned long irq_state; + spin_lock_irqsave(&g_link_lock, irq_state); if (g_link_pool) { urbl = container_of(g_link_pool, struct oz_urb_link, link); @@ -261,7 +284,8 @@ static struct oz_urb_link *oz_alloc_urb_link(void) urbl = kmalloc(sizeof(struct oz_urb_link), GFP_ATOMIC); return urbl; } -/*------------------------------------------------------------------------------ + +/* * Frees an urb link by putting it in the pool if there is enough space or * deallocating it to heap otherwise. * Context: any @@ -281,7 +305,8 @@ static void oz_free_urb_link(struct oz_urb_link *urbl) kfree(urbl); } } -/*------------------------------------------------------------------------------ + +/* * Deallocates all the urb links in the pool. * Context: unknown */ @@ -289,6 +314,7 @@ static void oz_empty_link_pool(void) { struct list_head *e; unsigned long irq_state; + spin_lock_irqsave(&g_link_lock, irq_state); e = g_link_pool; g_link_pool = NULL; @@ -301,12 +327,13 @@ static void oz_empty_link_pool(void) kfree(urbl); } } -/*------------------------------------------------------------------------------ + +/* * Allocates endpoint structure and optionally a buffer. If a buffer is * allocated it immediately follows the endpoint structure. * Context: softirq */ -static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size) +static struct oz_endpoint *oz_ep_alloc(int buffer_size, gfp_t mem_flags) { struct oz_endpoint *ep = kzalloc(sizeof(struct oz_endpoint)+buffer_size, mem_flags); @@ -321,7 +348,8 @@ static struct oz_endpoint *oz_ep_alloc(gfp_t mem_flags, int buffer_size) } return ep; } -/*------------------------------------------------------------------------------ + +/* * Pre-condition: Must be called with g_tasklet_lock held and interrupts * disabled. * Context: softirq or process @@ -330,6 +358,7 @@ static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb { struct oz_urb_link *urbl; struct list_head *e; + list_for_each(e, &ozhcd->urb_cancel_list) { urbl = container_of(e, struct oz_urb_link, link); if (urb == urbl->urb) { @@ -339,17 +368,19 @@ static struct oz_urb_link *oz_uncancel_urb(struct oz_hcd *ozhcd, struct urb *urb } return NULL; } -/*------------------------------------------------------------------------------ + +/* * This is called when we have finished processing an urb. It unlinks it from * the ep and returns it to the core. * Context: softirq or process */ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, - int status, unsigned long submit_jiffies) + int status) { struct oz_hcd *ozhcd = oz_hcd_private(hcd); unsigned long irq_state; - struct oz_urb_link *cancel_urbl = NULL; + struct oz_urb_link *cancel_urbl; + spin_lock_irqsave(&g_tasklet_lock, irq_state); usb_hcd_unlink_urb_from_ep(hcd, urb); /* Clear hcpriv which will prevent it being put in the cancel list @@ -371,15 +402,9 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, */ spin_unlock(&g_tasklet_lock); if (oz_forget_urb(urb)) { - oz_trace("OZWPAN: ERROR Unknown URB %p\n", urb); + oz_dbg(ON, "ERROR Unknown URB %p\n", urb); } else { - static unsigned long last_time; atomic_dec(&g_pending_urbs); - oz_trace2(OZ_TRACE_URB, - "%lu: giveback_urb(%p,%x) %lu %lu pending:%d\n", - jiffies, urb, status, jiffies-submit_jiffies, - jiffies-last_time, atomic_read(&g_pending_urbs)); - last_time = jiffies; usb_hcd_giveback_urb(hcd, urb, status); } spin_lock(&g_tasklet_lock); @@ -387,14 +412,14 @@ static void oz_complete_urb(struct usb_hcd *hcd, struct urb *urb, if (cancel_urbl) oz_free_urb_link(cancel_urbl); } -/*------------------------------------------------------------------------------ + +/* * Deallocates an endpoint including deallocating any associated stream and * returning any queued urbs to the core. * Context: softirq */ static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep) { - oz_trace("oz_ep_free()\n"); if (port) { struct list_head list; struct oz_hcd *ozhcd = port->ozhcd; @@ -409,19 +434,20 @@ static void oz_ep_free(struct oz_port *port, struct oz_endpoint *ep) list_splice_tail(&list, &ozhcd->orphanage); spin_unlock_bh(&ozhcd->hcd_lock); } - oz_trace("Freeing endpoint memory\n"); + oz_dbg(ON, "Freeing endpoint memory\n"); kfree(ep); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_complete_buffered_urb(struct oz_port *port, struct oz_endpoint *ep, struct urb *urb) { - u8 data_len, available_space, copy_len; + int data_len, available_space, copy_len; - memcpy(&data_len, &ep->buffer[ep->out_ix], sizeof(u8)); + data_len = ep->buffer[ep->out_ix]; if (data_len <= urb->transfer_buffer_length) available_space = data_len; else @@ -446,28 +472,29 @@ static void oz_complete_buffered_urb(struct oz_port *port, ep->out_ix = 0; ep->buffered_units--; - oz_trace("Trying to give back buffered frame of size=%d\n", - available_space); - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_dbg(ON, "Trying to give back buffered frame of size=%d\n", + available_space); + oz_complete_urb(port->ozhcd->hcd, urb, 0); } -/*------------------------------------------------------------------------------ +/* * Context: softirq */ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, struct urb *urb, u8 req_id) { struct oz_urb_link *urbl; - struct oz_endpoint *ep; + struct oz_endpoint *ep = NULL; int err = 0; + if (ep_addr >= OZ_NB_ENDPOINTS) { - oz_trace("Invalid endpoint number in oz_enqueue_ep_urb().\n"); + oz_dbg(ON, "%s: Invalid endpoint number\n", __func__); return -EINVAL; } urbl = oz_alloc_urb_link(); if (!urbl) return -ENOMEM; - urbl->submit_jiffies = jiffies; + urbl->submit_counter = 0; urbl->urb = urb; urbl->req_id = req_id; urbl->ep_num = ep_addr; @@ -480,15 +507,20 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, */ if (urb->unlinked) { spin_unlock_bh(&port->ozhcd->hcd_lock); - oz_trace("urb %p unlinked so complete immediately\n", urb); - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_dbg(ON, "urb %p unlinked so complete immediately\n", urb); + oz_complete_urb(port->ozhcd->hcd, urb, 0); oz_free_urb_link(urbl); return 0; } + if (in_dir) ep = port->in_ep[ep_addr]; else ep = port->out_ep[ep_addr]; + if (!ep) { + err = -ENOMEM; + goto out; + } /*For interrupt endpoint check for buffered data * & complete urb @@ -501,21 +533,23 @@ static int oz_enqueue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, return 0; } - if (ep && port->hpd) { + if (port->hpd) { list_add_tail(&urbl->link, &ep->urb_list); if (!in_dir && ep_addr && (ep->credit < 0)) { - ep->last_jiffies = jiffies; + getrawmonotonic(&ep->timestamp); ep->credit = 0; } } else { err = -EPIPE; } +out: spin_unlock_bh(&port->ozhcd->hcd_lock); if (err) oz_free_urb_link(urbl); return err; } -/*------------------------------------------------------------------------------ + +/* * Removes an urb from the queue in the endpoint. * Returns 0 if it is found and -EIDRM otherwise. * Context: softirq @@ -525,6 +559,7 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, { struct oz_urb_link *urbl = NULL; struct oz_endpoint *ep; + spin_lock_bh(&port->ozhcd->hcd_lock); if (in_dir) ep = port->in_ep[ep_addr]; @@ -546,7 +581,8 @@ static int oz_dequeue_ep_urb(struct oz_port *port, u8 ep_addr, int in_dir, oz_free_urb_link(urbl); return urbl ? 0 : -EIDRM; } -/*------------------------------------------------------------------------------ + +/* * Finds an urb given its request id. * Context: softirq */ @@ -555,7 +591,7 @@ static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix, { struct oz_hcd *ozhcd = port->ozhcd; struct urb *urb = NULL; - struct oz_urb_link *urbl = NULL; + struct oz_urb_link *urbl; struct oz_endpoint *ep; spin_lock_bh(&ozhcd->hcd_lock); @@ -578,7 +614,8 @@ static struct urb *oz_find_urb_by_id(struct oz_port *port, int ep_ix, oz_free_urb_link(urbl); return urb; } -/*------------------------------------------------------------------------------ + +/* * Pre-condition: Port lock must be held. * Context: softirq */ @@ -592,12 +629,14 @@ static void oz_acquire_port(struct oz_port *port, void *hpd) oz_usb_get(hpd); port->hpd = hpd; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static struct oz_hcd *oz_hcd_claim(void) { struct oz_hcd *ozhcd; + spin_lock_bh(&g_hcdlock); ozhcd = g_ozhcd; if (ozhcd) @@ -605,7 +644,8 @@ static struct oz_hcd *oz_hcd_claim(void) spin_unlock_bh(&g_hcdlock); return ozhcd; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static inline void oz_hcd_put(struct oz_hcd *ozhcd) @@ -613,7 +653,8 @@ static inline void oz_hcd_put(struct oz_hcd *ozhcd) if (ozhcd) usb_put_hcd(ozhcd->hcd); } -/*------------------------------------------------------------------------------ + +/* * This is called by the protocol handler to notify that a PD has arrived. * We allocate a port to associate with the PD and create a structure for * endpoint 0. This port is made the connection port. @@ -625,75 +666,74 @@ static inline void oz_hcd_put(struct oz_hcd *ozhcd) * probably very rare indeed. * Context: softirq */ -void *oz_hcd_pd_arrived(void *hpd) +struct oz_port *oz_hcd_pd_arrived(void *hpd) { int i; - void *hport = NULL; - struct oz_hcd *ozhcd = NULL; + struct oz_port *hport; + struct oz_hcd *ozhcd; struct oz_endpoint *ep; - oz_trace("oz_hcd_pd_arrived()\n"); + ozhcd = oz_hcd_claim(); - if (ozhcd == NULL) + if (!ozhcd) return NULL; /* Allocate an endpoint object in advance (before holding hcd lock) to * use for out endpoint 0. */ - ep = oz_ep_alloc(GFP_ATOMIC, 0); + ep = oz_ep_alloc(0, GFP_ATOMIC); + if (!ep) + goto err_put; + spin_lock_bh(&ozhcd->hcd_lock); - if (ozhcd->conn_port >= 0) { - spin_unlock_bh(&ozhcd->hcd_lock); - oz_trace("conn_port >= 0\n"); - goto out; - } + if (ozhcd->conn_port >= 0) + goto err_unlock; + for (i = 0; i < OZ_NB_PORTS; i++) { struct oz_port *port = &ozhcd->ports[i]; + spin_lock(&port->port_lock); - if ((port->flags & OZ_PORT_F_PRESENT) == 0) { + if (!(port->flags & (OZ_PORT_F_PRESENT | OZ_PORT_F_CHANGED))) { oz_acquire_port(port, hpd); spin_unlock(&port->port_lock); break; } spin_unlock(&port->port_lock); } - if (i < OZ_NB_PORTS) { - oz_trace("Setting conn_port = %d\n", i); - ozhcd->conn_port = i; - /* Attach out endpoint 0. - */ - ozhcd->ports[i].out_ep[0] = ep; - ep = NULL; - hport = &ozhcd->ports[i]; - spin_unlock_bh(&ozhcd->hcd_lock); - if (ozhcd->flags & OZ_HDC_F_SUSPENDED) { - oz_trace("Resuming root hub\n"); - usb_hcd_resume_root_hub(ozhcd->hcd); - } - usb_hcd_poll_rh_status(ozhcd->hcd); - } else { - spin_unlock_bh(&ozhcd->hcd_lock); - } -out: - if (ep) /* ep is non-null if not used. */ - oz_ep_free(NULL, ep); + if (i == OZ_NB_PORTS) + goto err_unlock; + + ozhcd->conn_port = i; + hport = &ozhcd->ports[i]; + hport->out_ep[0] = ep; + spin_unlock_bh(&ozhcd->hcd_lock); + if (ozhcd->flags & OZ_HDC_F_SUSPENDED) + usb_hcd_resume_root_hub(ozhcd->hcd); + usb_hcd_poll_rh_status(ozhcd->hcd); oz_hcd_put(ozhcd); + return hport; + +err_unlock: + spin_unlock_bh(&ozhcd->hcd_lock); + oz_ep_free(NULL, ep); +err_put: + oz_hcd_put(ozhcd); + return NULL; } -/*------------------------------------------------------------------------------ + +/* * This is called by the protocol handler to notify that the PD has gone away. * We need to deallocate all resources and then request that the root hub is * polled. We release the reference we hold on the PD. * Context: softirq */ -void oz_hcd_pd_departed(void *hport) +void oz_hcd_pd_departed(struct oz_port *port) { - struct oz_port *port = (struct oz_port *)hport; struct oz_hcd *ozhcd; void *hpd; struct oz_endpoint *ep = NULL; - oz_trace("oz_hcd_pd_departed()\n"); if (port == NULL) { - oz_trace("oz_hcd_pd_departed() port = 0\n"); + oz_dbg(ON, "%s: port = 0\n", __func__); return; } ozhcd = port->ozhcd; @@ -704,7 +744,7 @@ void oz_hcd_pd_departed(void *hport) spin_lock_bh(&ozhcd->hcd_lock); if ((ozhcd->conn_port >= 0) && (port == &ozhcd->ports[ozhcd->conn_port])) { - oz_trace("Clearing conn_port\n"); + oz_dbg(ON, "Clearing conn_port\n"); ozhcd->conn_port = -1; } spin_lock(&port->port_lock); @@ -717,9 +757,10 @@ void oz_hcd_pd_departed(void *hport) hpd = port->hpd; port->hpd = NULL; port->bus_addr = 0xff; + port->config_num = 0; port->flags &= ~(OZ_PORT_F_PRESENT | OZ_PORT_F_DYING); port->flags |= OZ_PORT_F_CHANGED; - port->status &= ~USB_PORT_STAT_CONNECTION; + port->status &= ~(USB_PORT_STAT_CONNECTION | USB_PORT_STAT_ENABLE); port->status |= (USB_PORT_STAT_C_CONNECTION << 16); /* If there is an endpont 0 then clear the pointer while we hold * the spinlock be we deallocate it after releasing the lock. @@ -734,7 +775,8 @@ void oz_hcd_pd_departed(void *hport) usb_hcd_poll_rh_status(ozhcd->hcd); oz_usb_put(hpd); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ void oz_hcd_pd_reset(void *hpd, void *hport) @@ -743,7 +785,8 @@ void oz_hcd_pd_reset(void *hpd, void *hport) */ struct oz_port *port = (struct oz_port *)hport; struct oz_hcd *ozhcd = port->ozhcd; - oz_trace("PD Reset\n"); + + oz_dbg(ON, "PD Reset\n"); spin_lock_bh(&port->port_lock); port->flags |= OZ_PORT_F_CHANGED; port->status |= USB_PORT_STAT_RESET; @@ -752,7 +795,8 @@ void oz_hcd_pd_reset(void *hpd, void *hport) oz_clean_endpoints_for_config(ozhcd->hcd, port); usb_hcd_poll_rh_status(ozhcd->hcd); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc, @@ -762,8 +806,8 @@ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc, struct urb *urb; int err = 0; - oz_trace("oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n", - length, offset, total_size); + oz_dbg(ON, "oz_hcd_get_desc_cnf length = %d offs = %d tot_size = %d\n", + length, offset, total_size); urb = oz_find_urb_by_id(port, 0, req_id); if (!urb) return; @@ -795,54 +839,52 @@ void oz_hcd_get_desc_cnf(void *hport, u8 req_id, int status, const u8 *desc, } } urb->actual_length = total_size; - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_complete_urb(port->ozhcd->hcd, urb, 0); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ -#ifdef WANT_TRACE static void oz_display_conf_type(u8 t) { switch (t) { case USB_REQ_GET_STATUS: - oz_trace("USB_REQ_GET_STATUS - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_STATUS - cnf\n"); break; case USB_REQ_CLEAR_FEATURE: - oz_trace("USB_REQ_CLEAR_FEATURE - cnf\n"); + oz_dbg(ON, "USB_REQ_CLEAR_FEATURE - cnf\n"); break; case USB_REQ_SET_FEATURE: - oz_trace("USB_REQ_SET_FEATURE - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_FEATURE - cnf\n"); break; case USB_REQ_SET_ADDRESS: - oz_trace("USB_REQ_SET_ADDRESS - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_ADDRESS - cnf\n"); break; case USB_REQ_GET_DESCRIPTOR: - oz_trace("USB_REQ_GET_DESCRIPTOR - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - cnf\n"); break; case USB_REQ_SET_DESCRIPTOR: - oz_trace("USB_REQ_SET_DESCRIPTOR - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_DESCRIPTOR - cnf\n"); break; case USB_REQ_GET_CONFIGURATION: - oz_trace("USB_REQ_GET_CONFIGURATION - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - cnf\n"); break; case USB_REQ_SET_CONFIGURATION: - oz_trace("USB_REQ_SET_CONFIGURATION - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - cnf\n"); break; case USB_REQ_GET_INTERFACE: - oz_trace("USB_REQ_GET_INTERFACE - cnf\n"); + oz_dbg(ON, "USB_REQ_GET_INTERFACE - cnf\n"); break; case USB_REQ_SET_INTERFACE: - oz_trace("USB_REQ_SET_INTERFACE - cnf\n"); + oz_dbg(ON, "USB_REQ_SET_INTERFACE - cnf\n"); break; case USB_REQ_SYNCH_FRAME: - oz_trace("USB_REQ_SYNCH_FRAME - cnf\n"); + oz_dbg(ON, "USB_REQ_SYNCH_FRAME - cnf\n"); break; } } -#else -#define oz_display_conf_type(__x) -#endif /* WANT_TRACE */ -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb, @@ -850,6 +892,7 @@ static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb, { int rc = 0; struct usb_hcd *hcd = port->ozhcd->hcd; + if (rcode == 0) { port->config_num = config_num; oz_clean_endpoints_for_config(hcd, port); @@ -860,9 +903,10 @@ static void oz_hcd_complete_set_config(struct oz_port *port, struct urb *urb, } else { rc = -ENOMEM; } - oz_complete_urb(hcd, urb, rc, 0); + oz_complete_urb(hcd, urb, rc); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, @@ -870,10 +914,11 @@ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, { struct usb_hcd *hcd = port->ozhcd->hcd; int rc = 0; - if (rcode == 0) { + + if ((rcode == 0) && (port->config_num > 0)) { struct usb_host_config *config; struct usb_host_interface *intf; - oz_trace("Set interface %d alt %d\n", if_num, alt); + oz_dbg(ON, "Set interface %d alt %d\n", if_num, alt); oz_clean_endpoints_for_interface(hcd, port, if_num); config = &urb->dev->config[port->config_num-1]; intf = &config->intf_cache[if_num]->altsetting[alt]; @@ -885,9 +930,10 @@ static void oz_hcd_complete_set_interface(struct oz_port *port, struct urb *urb, } else { rc = -ENOMEM; } - oz_complete_urb(hcd, urb, rc, 0); + oz_complete_urb(hcd, urb, rc); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, @@ -900,10 +946,10 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, unsigned windex; unsigned wvalue; - oz_trace("oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len); + oz_dbg(ON, "oz_hcd_control_cnf rcode=%u len=%d\n", rcode, data_len); urb = oz_find_urb_by_id(port, 0, req_id); if (!urb) { - oz_trace("URB not found\n"); + oz_dbg(ON, "URB not found\n"); return; } setup = (struct usb_ctrlrequest *)urb->setup_packet; @@ -922,12 +968,12 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, (u8)windex, (u8)wvalue); break; default: - oz_complete_urb(hcd, urb, 0, 0); + oz_complete_urb(hcd, urb, 0); } } else { int copy_len; - oz_trace("VENDOR-CLASS - cnf\n"); + oz_dbg(ON, "VENDOR-CLASS - cnf\n"); if (data_len) { if (data_len <= urb->transfer_buffer_length) copy_len = data_len; @@ -936,10 +982,11 @@ void oz_hcd_control_cnf(void *hport, u8 req_id, u8 rcode, const u8 *data, memcpy(urb->transfer_buffer, data, copy_len); urb->actual_length = copy_len; } - oz_complete_urb(hcd, urb, 0, 0); + oz_complete_urb(hcd, urb, 0); } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data, @@ -947,13 +994,14 @@ static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data, { int space; int copy_len; + if (!ep->buffer) return -1; space = ep->out_ix-ep->in_ix-1; if (space < 0) space += ep->buffer_size; if (space < (data_len+1)) { - oz_trace("Buffer full\n"); + oz_dbg(ON, "Buffer full\n"); return -1; } ep->buffer[ep->in_ix] = (u8)data_len; @@ -975,7 +1023,8 @@ static int oz_hcd_buffer_data(struct oz_endpoint *ep, const u8 *data, ep->buffered_units++; return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq-serialized */ void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len) @@ -983,6 +1032,7 @@ void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len) struct oz_port *port = (struct oz_port *)hport; struct oz_endpoint *ep; struct oz_hcd *ozhcd = port->ozhcd; + spin_lock_bh(&ozhcd->hcd_lock); ep = port->in_ep[endpoint & USB_ENDPOINT_NUMBER_MASK]; if (ep == NULL) @@ -1006,10 +1056,10 @@ void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len) copy_len = urb->transfer_buffer_length; memcpy(urb->transfer_buffer, data, copy_len); urb->actual_length = copy_len; - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_complete_urb(port->ozhcd->hcd, urb, 0); return; } else { - oz_trace("buffering frame as URB is not available\n"); + oz_dbg(ON, "buffering frame as URB is not available\n"); oz_hcd_buffer_data(ep, data, data_len); } break; @@ -1020,14 +1070,16 @@ void oz_hcd_data_ind(void *hport, u8 endpoint, const u8 *data, int data_len) done: spin_unlock_bh(&ozhcd->hcd_lock); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static inline int oz_usb_get_frame_number(void) { - return jiffies_to_msecs(get_jiffies_64()); + return atomic_inc_return(&g_usb_frame_number); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ int oz_hcd_heartbeat(void *hport) @@ -1041,7 +1093,9 @@ int oz_hcd_heartbeat(void *hport) struct list_head *n; struct urb *urb; struct oz_endpoint *ep; - unsigned long now = jiffies; + struct timespec ts, delta; + + getrawmonotonic(&ts); INIT_LIST_HEAD(&xfr_list); /* Check the OUT isoc endpoints to see if any URB data can be sent. */ @@ -1050,10 +1104,11 @@ int oz_hcd_heartbeat(void *hport) ep = ep_from_link(e); if (ep->credit < 0) continue; - ep->credit += jiffies_to_msecs(now - ep->last_jiffies); + delta = timespec_sub(ts, ep->timestamp); + ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC); if (ep->credit > ep->credit_ceiling) ep->credit = ep->credit_ceiling; - ep->last_jiffies = now; + ep->timestamp = ts; while (ep->credit && !list_empty(&ep->urb_list)) { urbl = list_first_entry(&ep->urb_list, struct oz_urb_link, link); @@ -1061,6 +1116,8 @@ int oz_hcd_heartbeat(void *hport) if ((ep->credit + 1) < urb->number_of_packets) break; ep->credit -= urb->number_of_packets; + if (ep->credit < 0) + ep->credit = 0; list_move_tail(&urbl->link, &xfr_list); } } @@ -1068,16 +1125,14 @@ int oz_hcd_heartbeat(void *hport) /* Send to PD and complete URBs. */ list_for_each_safe(e, n, &xfr_list) { - unsigned long t; urbl = container_of(e, struct oz_urb_link, link); urb = urbl->urb; - t = urbl->submit_jiffies; list_del_init(e); urb->error_count = 0; urb->start_frame = oz_usb_get_frame_number(); oz_usb_send_isoc(port->hpd, urbl->ep_num, urb); oz_free_urb_link(urbl); - oz_complete_urb(port->ozhcd->hcd, urb, 0, t); + oz_complete_urb(port->ozhcd->hcd, urb, 0); } /* Check the IN isoc endpoints to see if any URBs can be completed. */ @@ -1088,13 +1143,14 @@ int oz_hcd_heartbeat(void *hport) if (ep->buffered_units >= OZ_IN_BUFFERING_UNITS) { ep->flags &= ~OZ_F_EP_BUFFERING; ep->credit = 0; - ep->last_jiffies = now; + ep->timestamp = ts; ep->start_frame = 0; } continue; } - ep->credit += jiffies_to_msecs(now - ep->last_jiffies); - ep->last_jiffies = now; + delta = timespec_sub(ts, ep->timestamp); + ep->credit += div_u64(timespec_to_ns(&delta), NSEC_PER_MSEC); + ep->timestamp = ts; while (!list_empty(&ep->urb_list)) { struct oz_urb_link *urbl = list_first_entry(&ep->urb_list, @@ -1103,7 +1159,7 @@ int oz_hcd_heartbeat(void *hport) int len = 0; int copy_len; int i; - if ((ep->credit + 1) < urb->number_of_packets) + if (ep->credit < urb->number_of_packets) break; if (ep->buffered_units < urb->number_of_packets) break; @@ -1149,7 +1205,7 @@ int oz_hcd_heartbeat(void *hport) urb = urbl->urb; list_del_init(e); oz_free_urb_link(urbl); - oz_complete_urb(port->ozhcd->hcd, urb, 0, 0); + oz_complete_urb(port->ozhcd->hcd, urb, 0); } /* Check if there are any ep0 requests that have timed out. * If so resent to PD. @@ -1161,11 +1217,12 @@ int oz_hcd_heartbeat(void *hport) spin_lock_bh(&ozhcd->hcd_lock); list_for_each_safe(e, n, &ep->urb_list) { urbl = container_of(e, struct oz_urb_link, link); - if (time_after(now, urbl->submit_jiffies+HZ/2)) { - oz_trace("%ld: Request 0x%p timeout\n", - now, urbl->urb); - urbl->submit_jiffies = now; + if (urbl->submit_counter > EP0_TIMEOUT_COUNTER) { + oz_dbg(ON, "Request 0x%p timeout\n", urbl->urb); list_move_tail(e, &xfr_list); + urbl->submit_counter = 0; + } else { + urbl->submit_counter++; } } if (!list_empty(&ep->urb_list)) @@ -1175,14 +1232,15 @@ int oz_hcd_heartbeat(void *hport) while (e != &xfr_list) { urbl = container_of(e, struct oz_urb_link, link); e = e->next; - oz_trace("Resending request to PD.\n"); + oz_dbg(ON, "Resending request to PD\n"); oz_process_ep0_urb(ozhcd, urbl->urb, GFP_ATOMIC); oz_free_urb_link(urbl); } } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, @@ -1193,7 +1251,10 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, int i; int if_ix = intf->desc.bInterfaceNumber; int request_heartbeat = 0; - oz_trace("interface[%d] = %p\n", if_ix, intf); + + oz_dbg(ON, "interface[%d] = %p\n", if_ix, intf); + if (if_ix >= port->num_iface || port->iface == NULL) + return -ENOMEM; for (i = 0; i < intf->desc.bNumEndpoints; i++) { struct usb_host_endpoint *hep = &intf->endpoint[i]; u8 ep_addr = hep->desc.bEndpointAddress; @@ -1201,20 +1262,20 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, struct oz_endpoint *ep; int buffer_size = 0; - oz_trace("%d bEndpointAddress = %x\n", i, ep_addr); + oz_dbg(ON, "%d bEndpointAddress = %x\n", i, ep_addr); if (ep_addr & USB_ENDPOINT_DIR_MASK) { switch (hep->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) { case USB_ENDPOINT_XFER_ISOC: - buffer_size = 24*1024; + buffer_size = OZ_EP_BUFFER_SIZE_ISOC; break; case USB_ENDPOINT_XFER_INT: - buffer_size = 128; + buffer_size = OZ_EP_BUFFER_SIZE_INT; break; } } - ep = oz_ep_alloc(mem_flags, buffer_size); + ep = oz_ep_alloc(buffer_size, mem_flags); if (!ep) { oz_clean_endpoints_for_interface(hcd, port, if_ix); return -ENOMEM; @@ -1223,8 +1284,8 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, ep->ep_num = ep_num; if ((ep->attrib & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_ISOC) { - oz_trace("wMaxPacketSize = %d\n", - usb_endpoint_maxp(&hep->desc)); + oz_dbg(ON, "wMaxPacketSize = %d\n", + usb_endpoint_maxp(&hep->desc)); ep->credit_ceiling = 200; if (ep_addr & USB_ENDPOINT_DIR_MASK) { ep->flags |= OZ_F_EP_BUFFERING; @@ -1259,7 +1320,8 @@ static int oz_build_endpoints_for_interface(struct usb_hcd *hcd, } return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, @@ -1270,7 +1332,7 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, int i; struct list_head ep_list; - oz_trace("Deleting endpoints for interface %d\n", if_ix); + oz_dbg(ON, "Deleting endpoints for interface %d\n", if_ix); if (if_ix >= port->num_iface) return; INIT_LIST_HEAD(&ep_list); @@ -1304,7 +1366,8 @@ static void oz_clean_endpoints_for_interface(struct usb_hcd *hcd, oz_ep_free(port, ep); } } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static int oz_build_endpoints_for_config(struct usb_hcd *hcd, @@ -1314,6 +1377,7 @@ static int oz_build_endpoints_for_config(struct usb_hcd *hcd, struct oz_hcd *ozhcd = port->ozhcd; int i; int num_iface = config->desc.bNumInterfaces; + if (num_iface) { struct oz_interface *iface; @@ -1338,7 +1402,8 @@ fail: oz_clean_endpoints_for_config(hcd, port); return -1; } -/*------------------------------------------------------------------------------ + +/* * Context: softirq */ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, @@ -1346,25 +1411,28 @@ static void oz_clean_endpoints_for_config(struct usb_hcd *hcd, { struct oz_hcd *ozhcd = port->ozhcd; int i; - oz_trace("Deleting endpoints for configuration.\n"); + + oz_dbg(ON, "Deleting endpoints for configuration\n"); for (i = 0; i < port->num_iface; i++) oz_clean_endpoints_for_interface(hcd, port, i); spin_lock_bh(&ozhcd->hcd_lock); if (port->iface) { - oz_trace("Freeing interfaces object.\n"); + oz_dbg(ON, "Freeing interfaces object\n"); kfree(port->iface); port->iface = NULL; } port->num_iface = 0; spin_unlock_bh(&ozhcd->hcd_lock); } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void *oz_claim_hpd(struct oz_port *port) { - void *hpd = NULL; + void *hpd; struct oz_hcd *ozhcd = port->ozhcd; + spin_lock_bh(&ozhcd->hcd_lock); hpd = port->hpd; if (hpd) @@ -1372,7 +1440,8 @@ static void *oz_claim_hpd(struct oz_port *port) spin_unlock_bh(&ozhcd->hcd_lock); return hpd; } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, @@ -1382,7 +1451,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, unsigned windex; unsigned wvalue; unsigned wlength; - void *hpd = NULL; + void *hpd; u8 req_id; int rc = 0; unsigned complete = 0; @@ -1390,7 +1459,7 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, int port_ix = -1; struct oz_port *port = NULL; - oz_trace2(OZ_TRACE_URB, "%lu: oz_process_ep0_urb(%p)\n", jiffies, urb); + oz_dbg(URB, "[%s]:(%p)\n", __func__, urb); port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); if (port_ix < 0) { rc = -EPIPE; @@ -1399,8 +1468,8 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, port = &ozhcd->ports[port_ix]; if (((port->flags & OZ_PORT_F_PRESENT) == 0) || (port->flags & OZ_PORT_F_DYING)) { - oz_trace("Refusing URB port_ix = %d devnum = %d\n", - port_ix, urb->dev->devnum); + oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n", + port_ix, urb->dev->devnum); rc = -EPIPE; goto out; } @@ -1411,17 +1480,16 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, windex = le16_to_cpu(setup->wIndex); wvalue = le16_to_cpu(setup->wValue); wlength = le16_to_cpu(setup->wLength); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "bRequestType = %x\n", - setup->bRequestType); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "bRequest = %x\n", setup->bRequest); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "wValue = %x\n", wvalue); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "wIndex = %x\n", windex); - oz_trace2(OZ_TRACE_CTRL_DETAIL, "wLength = %x\n", wlength); + oz_dbg(CTRL_DETAIL, "bRequestType = %x\n", setup->bRequestType); + oz_dbg(CTRL_DETAIL, "bRequest = %x\n", setup->bRequest); + oz_dbg(CTRL_DETAIL, "wValue = %x\n", wvalue); + oz_dbg(CTRL_DETAIL, "wIndex = %x\n", windex); + oz_dbg(CTRL_DETAIL, "wLength = %x\n", wlength); req_id = port->next_req_id++; hpd = oz_claim_hpd(port); if (hpd == NULL) { - oz_trace("Cannot claim port\n"); + oz_dbg(ON, "Cannot claim port\n"); rc = -EPIPE; goto out; } @@ -1431,30 +1499,31 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, */ switch (setup->bRequest) { case USB_REQ_GET_DESCRIPTOR: - oz_trace("USB_REQ_GET_DESCRIPTOR - req\n"); + oz_dbg(ON, "USB_REQ_GET_DESCRIPTOR - req\n"); break; case USB_REQ_SET_ADDRESS: - oz_trace("USB_REQ_SET_ADDRESS - req\n"); - oz_trace("Port %d address is 0x%x\n", ozhcd->conn_port, - (u8)le16_to_cpu(setup->wValue)); + oz_dbg(ON, "USB_REQ_SET_ADDRESS - req\n"); + oz_dbg(ON, "Port %d address is 0x%x\n", + ozhcd->conn_port, + (u8)le16_to_cpu(setup->wValue)); spin_lock_bh(&ozhcd->hcd_lock); if (ozhcd->conn_port >= 0) { ozhcd->ports[ozhcd->conn_port].bus_addr = (u8)le16_to_cpu(setup->wValue); - oz_trace("Clearing conn_port\n"); + oz_dbg(ON, "Clearing conn_port\n"); ozhcd->conn_port = -1; } spin_unlock_bh(&ozhcd->hcd_lock); complete = 1; break; case USB_REQ_SET_CONFIGURATION: - oz_trace("USB_REQ_SET_CONFIGURATION - req\n"); + oz_dbg(ON, "USB_REQ_SET_CONFIGURATION - req\n"); break; case USB_REQ_GET_CONFIGURATION: /* We short circuit this case and reply directly since * we have the selected configuration number cached. */ - oz_trace("USB_REQ_GET_CONFIGURATION - reply now\n"); + oz_dbg(ON, "USB_REQ_GET_CONFIGURATION - reply now\n"); if (urb->transfer_buffer_length >= 1) { urb->actual_length = 1; *((u8 *)urb->transfer_buffer) = @@ -1468,20 +1537,20 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, /* We short circuit this case and reply directly since * we have the selected interface alternative cached. */ - oz_trace("USB_REQ_GET_INTERFACE - reply now\n"); + oz_dbg(ON, "USB_REQ_GET_INTERFACE - reply now\n"); if (urb->transfer_buffer_length >= 1) { urb->actual_length = 1; *((u8 *)urb->transfer_buffer) = port->iface[(u8)windex].alt; - oz_trace("interface = %d alt = %d\n", - windex, port->iface[(u8)windex].alt); + oz_dbg(ON, "interface = %d alt = %d\n", + windex, port->iface[(u8)windex].alt); complete = 1; } else { rc = -EPIPE; } break; case USB_REQ_SET_INTERFACE: - oz_trace("USB_REQ_SET_INTERFACE - req\n"); + oz_dbg(ON, "USB_REQ_SET_INTERFACE - req\n"); break; } } @@ -1512,13 +1581,14 @@ static void oz_process_ep0_urb(struct oz_hcd *ozhcd, struct urb *urb, oz_usb_put(hpd); out: if (rc || complete) { - oz_trace("Completing request locally\n"); - oz_complete_urb(ozhcd->hcd, urb, rc, 0); + oz_dbg(ON, "Completing request locally\n"); + oz_complete_urb(ozhcd->hcd, urb, rc); } else { oz_usb_request_heartbeat(port->hpd); } } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb) @@ -1526,6 +1596,7 @@ static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb) int rc = 0; struct oz_port *port = urb->hcpriv; u8 ep_addr; + /* When we are paranoid we keep a list of urbs which we check against * before handing one back. This is just for debugging during * development and should be turned off in the released driver. @@ -1551,7 +1622,8 @@ static int oz_urb_process(struct oz_hcd *ozhcd, struct urb *urb) } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void oz_urb_process_tasklet(unsigned long unused) @@ -1560,6 +1632,7 @@ static void oz_urb_process_tasklet(unsigned long unused) struct urb *urb; struct oz_hcd *ozhcd = oz_hcd_claim(); int rc = 0; + if (ozhcd == NULL) return; /* This is called from a tasklet so is in softirq context but the urb @@ -1577,13 +1650,14 @@ static void oz_urb_process_tasklet(unsigned long unused) oz_free_urb_link(urbl); rc = oz_urb_process(ozhcd, urb); if (rc) - oz_complete_urb(ozhcd->hcd, urb, rc, 0); + oz_complete_urb(ozhcd->hcd, urb, rc); spin_lock_irqsave(&g_tasklet_lock, irq_state); } spin_unlock_irqrestore(&g_tasklet_lock, irq_state); oz_hcd_put(ozhcd); } -/*------------------------------------------------------------------------------ + +/* * This function searches for the urb in any of the lists it could be in. * If it is found it is removed from the list and completed. If the urb is * being processed then it won't be in a list so won't be found. However, the @@ -1599,13 +1673,14 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) struct oz_hcd *ozhcd; unsigned long irq_state; u8 ix; + if (port == NULL) { - oz_trace("ERRORERROR: oz_urb_cancel(%p) port is null\n", urb); + oz_dbg(ON, "%s: ERROR: (%p) port is null\n", __func__, urb); return; } ozhcd = port->ozhcd; if (ozhcd == NULL) { - oz_trace("ERRORERROR: oz_urb_cancel(%p) ozhcd is null\n", urb); + oz_dbg(ON, "%s; ERROR: (%p) ozhcd is null\n", __func__, urb); return; } @@ -1630,7 +1705,7 @@ static void oz_urb_cancel(struct oz_port *port, u8 ep_num, struct urb *urb) urbl = container_of(e, struct oz_urb_link, link); if (urbl->urb == urb) { list_del(e); - oz_trace("Found urb in orphanage\n"); + oz_dbg(ON, "Found urb in orphanage\n"); goto out; } } @@ -1646,10 +1721,11 @@ out2: if (urbl) { urb->actual_length = 0; oz_free_urb_link(urbl); - oz_complete_urb(ozhcd->hcd, urb, -EPIPE, 0); + oz_complete_urb(ozhcd->hcd, urb, -EPIPE); } } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static void oz_urb_cancel_tasklet(unsigned long unused) @@ -1657,6 +1733,7 @@ static void oz_urb_cancel_tasklet(unsigned long unused) unsigned long irq_state; struct urb *urb; struct oz_hcd *ozhcd = oz_hcd_claim(); + if (ozhcd == NULL) return; spin_lock_irqsave(&g_tasklet_lock, irq_state); @@ -1675,7 +1752,8 @@ static void oz_urb_cancel_tasklet(unsigned long unused) spin_unlock_irqrestore(&g_tasklet_lock, irq_state); oz_hcd_put(ozhcd); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status) @@ -1686,37 +1764,38 @@ static void oz_hcd_clear_orphanage(struct oz_hcd *ozhcd, int status) urbl = list_first_entry(&ozhcd->orphanage, struct oz_urb_link, link); list_del(&urbl->link); - oz_complete_urb(ozhcd->hcd, urbl->urb, status, 0); + oz_complete_urb(ozhcd->hcd, urbl->urb, status); oz_free_urb_link(urbl); } } } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_hcd_start(struct usb_hcd *hcd) { - oz_trace("oz_hcd_start()\n"); hcd->power_budget = 200; hcd->state = HC_STATE_RUNNING; hcd->uses_new_polling = 1; return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_stop(struct usb_hcd *hcd) { - oz_trace("oz_hcd_stop()\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_shutdown(struct usb_hcd *hcd) { - oz_trace("oz_hcd_shutdown()\n"); } -/*------------------------------------------------------------------------------ + +/* * Called to queue an urb for the device. * This function should return a non-zero error code if it fails the urb but * should not call usb_hcd_giveback_urb(). @@ -1726,21 +1805,19 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flags) { struct oz_hcd *ozhcd = oz_hcd_private(hcd); - int rc = 0; + int rc; int port_ix; struct oz_port *port; unsigned long irq_state; struct oz_urb_link *urbl; - oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_enqueue(%p)\n", - jiffies, urb); + + oz_dbg(URB, "%s: (%p)\n", __func__, urb); if (unlikely(ozhcd == NULL)) { - oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not ozhcd.\n", - jiffies, urb); + oz_dbg(URB, "Refused urb(%p) not ozhcd\n", urb); return -EPIPE; } if (unlikely(hcd->state != HC_STATE_RUNNING)) { - oz_trace2(OZ_TRACE_URB, "%lu: Refused urb(%p) not running.\n", - jiffies, urb); + oz_dbg(URB, "Refused urb(%p) not running\n", urb); return -EPIPE; } port_ix = oz_get_port_from_addr(ozhcd, urb->dev->devnum); @@ -1749,9 +1826,10 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, port = &ozhcd->ports[port_ix]; if (port == NULL) return -EPIPE; - if ((port->flags & OZ_PORT_F_PRESENT) == 0) { - oz_trace("Refusing URB port_ix = %d devnum = %d\n", - port_ix, urb->dev->devnum); + if (!(port->flags & OZ_PORT_F_PRESENT) || + (port->flags & OZ_PORT_F_CHANGED)) { + oz_dbg(ON, "Refusing URB port_ix = %d devnum = %d\n", + port_ix, urb->dev->devnum); return -EPIPE; } urb->hcpriv = port; @@ -1774,14 +1852,16 @@ static int oz_hcd_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, atomic_inc(&g_pending_urbs); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: tasklet */ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, struct urb *urb) { - struct oz_urb_link *urbl = NULL; + struct oz_urb_link *urbl; struct list_head *e; + if (unlikely(ep == NULL)) return NULL; list_for_each(e, &ep->urb_list) { @@ -1798,17 +1878,19 @@ static struct oz_urb_link *oz_remove_urb(struct oz_endpoint *ep, } return NULL; } -/*------------------------------------------------------------------------------ + +/* * Called to dequeue a previously submitted urb for the device. * Context: any */ static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) { struct oz_hcd *ozhcd = oz_hcd_private(hcd); - struct oz_urb_link *urbl = NULL; + struct oz_urb_link *urbl; int rc; unsigned long irq_state; - oz_trace2(OZ_TRACE_URB, "%lu: oz_hcd_urb_dequeue(%p)\n", jiffies, urb); + + oz_dbg(URB, "%s: (%p)\n", __func__, urb); urbl = oz_alloc_urb_link(); if (unlikely(urbl == NULL)) return -ENOMEM; @@ -1838,31 +1920,33 @@ static int oz_hcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status) } return rc; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep) { - oz_trace("oz_hcd_endpoint_disable\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static void oz_hcd_endpoint_reset(struct usb_hcd *hcd, struct usb_host_endpoint *ep) { - oz_trace("oz_hcd_endpoint_reset\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_hcd_get_frame_number(struct usb_hcd *hcd) { - oz_trace("oz_hcd_get_frame_number\n"); + oz_dbg(ON, "oz_hcd_get_frame_number\n"); return oz_usb_get_frame_number(); } -/*------------------------------------------------------------------------------ + +/* * Context: softirq * This is called as a consquence of us calling usb_hcd_poll_rh_status() and we * always do that in softirq context. @@ -1872,27 +1956,33 @@ static int oz_hcd_hub_status_data(struct usb_hcd *hcd, char *buf) struct oz_hcd *ozhcd = oz_hcd_private(hcd); int i; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_status_data()\n"); buf[0] = 0; + buf[1] = 0; spin_lock_bh(&ozhcd->hcd_lock); for (i = 0; i < OZ_NB_PORTS; i++) { if (ozhcd->ports[i].flags & OZ_PORT_F_CHANGED) { - oz_trace2(OZ_TRACE_HUB, "Port %d changed\n", i); + oz_dbg(HUB, "Port %d changed\n", i); ozhcd->ports[i].flags &= ~OZ_PORT_F_CHANGED; - buf[0] |= 1<<(i+1); + if (i < 7) + buf[0] |= 1 << (i + 1); + else + buf[1] |= 1 << (i - 7); } } spin_unlock_bh(&ozhcd->hcd_lock); - return buf[0] ? 1 : 0; + if (buf[0] != 0 || buf[1] != 0) + return 2; + else + return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static void oz_get_hub_descriptor(struct usb_hcd *hcd, struct usb_hub_descriptor *desc) { - oz_trace2(OZ_TRACE_HUB, "GetHubDescriptor\n"); memset(desc, 0, sizeof(*desc)); desc->bDescriptorType = 0x29; desc->bDescLength = 9; @@ -1900,7 +1990,8 @@ static void oz_get_hub_descriptor(struct usb_hcd *hcd, __constant_cpu_to_le16(0x0001); desc->bNbrPorts = OZ_NB_PORTS; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) @@ -1911,59 +2002,59 @@ static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) struct oz_hcd *ozhcd = oz_hcd_private(hcd); unsigned set_bits = 0; unsigned clear_bits = 0; - oz_trace2(OZ_TRACE_HUB, "SetPortFeature\n"); + if ((port_id < 1) || (port_id > OZ_NB_PORTS)) return -EPIPE; port = &ozhcd->ports[port_id-1]; switch (wvalue) { case USB_PORT_FEAT_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n"); break; case USB_PORT_FEAT_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n"); break; case USB_PORT_FEAT_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n"); break; case USB_PORT_FEAT_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); break; case USB_PORT_FEAT_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_RESET\n"); set_bits = USB_PORT_STAT_ENABLE | (USB_PORT_STAT_C_RESET<<16); clear_bits = USB_PORT_STAT_RESET; ozhcd->ports[port_id-1].bus_addr = 0; break; case USB_PORT_FEAT_POWER: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_POWER\n"); + oz_dbg(HUB, "USB_PORT_FEAT_POWER\n"); set_bits |= USB_PORT_STAT_POWER; break; case USB_PORT_FEAT_LOWSPEED: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_LOWSPEED\n"); + oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n"); break; case USB_PORT_FEAT_C_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n"); break; case USB_PORT_FEAT_C_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n"); break; case USB_PORT_FEAT_C_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n"); break; case USB_PORT_FEAT_C_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); break; case USB_PORT_FEAT_C_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n"); break; case USB_PORT_FEAT_TEST: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_TEST\n"); + oz_dbg(HUB, "USB_PORT_FEAT_TEST\n"); break; case USB_PORT_FEAT_INDICATOR: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_INDICATOR\n"); + oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n"); break; default: - oz_trace2(OZ_TRACE_HUB, "Other %d\n", wvalue); + oz_dbg(HUB, "Other %d\n", wvalue); break; } if (set_bits || clear_bits) { @@ -1972,11 +2063,11 @@ static int oz_set_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) port->status |= set_bits; spin_unlock_bh(&port->port_lock); } - oz_trace2(OZ_TRACE_HUB, "Port[%d] status = 0x%x\n", port_id, - port->status); + oz_dbg(HUB, "Port[%d] status = 0x%x\n", port_id, port->status); return err; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) @@ -1986,60 +2077,60 @@ static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) u8 port_id = (u8)windex; struct oz_hcd *ozhcd = oz_hcd_private(hcd); unsigned clear_bits = 0; - oz_trace2(OZ_TRACE_HUB, "ClearPortFeature\n"); + if ((port_id < 1) || (port_id > OZ_NB_PORTS)) return -EPIPE; port = &ozhcd->ports[port_id-1]; switch (wvalue) { case USB_PORT_FEAT_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_CONNECTION\n"); break; case USB_PORT_FEAT_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_ENABLE\n"); clear_bits = USB_PORT_STAT_ENABLE; break; case USB_PORT_FEAT_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_SUSPEND\n"); break; case USB_PORT_FEAT_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_OVER_CURRENT\n"); break; case USB_PORT_FEAT_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_RESET\n"); break; case USB_PORT_FEAT_POWER: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_POWER\n"); + oz_dbg(HUB, "USB_PORT_FEAT_POWER\n"); clear_bits |= USB_PORT_STAT_POWER; break; case USB_PORT_FEAT_LOWSPEED: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_LOWSPEED\n"); + oz_dbg(HUB, "USB_PORT_FEAT_LOWSPEED\n"); break; case USB_PORT_FEAT_C_CONNECTION: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_CONNECTION\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_CONNECTION\n"); clear_bits = (USB_PORT_STAT_C_CONNECTION << 16); break; case USB_PORT_FEAT_C_ENABLE: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_ENABLE\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_ENABLE\n"); clear_bits = (USB_PORT_STAT_C_ENABLE << 16); break; case USB_PORT_FEAT_C_SUSPEND: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_SUSPEND\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_SUSPEND\n"); break; case USB_PORT_FEAT_C_OVER_CURRENT: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_OVER_CURRENT\n"); break; case USB_PORT_FEAT_C_RESET: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_C_RESET\n"); + oz_dbg(HUB, "USB_PORT_FEAT_C_RESET\n"); clear_bits = (USB_PORT_FEAT_C_RESET << 16); break; case USB_PORT_FEAT_TEST: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_TEST\n"); + oz_dbg(HUB, "USB_PORT_FEAT_TEST\n"); break; case USB_PORT_FEAT_INDICATOR: - oz_trace2(OZ_TRACE_HUB, "USB_PORT_FEAT_INDICATOR\n"); + oz_dbg(HUB, "USB_PORT_FEAT_INDICATOR\n"); break; default: - oz_trace2(OZ_TRACE_HUB, "Other %d\n", wvalue); + oz_dbg(HUB, "Other %d\n", wvalue); break; } if (clear_bits) { @@ -2047,37 +2138,40 @@ static int oz_clear_port_feature(struct usb_hcd *hcd, u16 wvalue, u16 windex) port->status &= ~clear_bits; spin_unlock_bh(&port->port_lock); } - oz_trace2(OZ_TRACE_HUB, "Port[%d] status = 0x%x\n", port_id, - ozhcd->ports[port_id-1].status); + oz_dbg(HUB, "Port[%d] status = 0x%x\n", + port_id, ozhcd->ports[port_id-1].status); return err; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_get_port_status(struct usb_hcd *hcd, u16 windex, char *buf) { struct oz_hcd *ozhcd; - u32 status = 0; + u32 status; + if ((windex < 1) || (windex > OZ_NB_PORTS)) return -EPIPE; ozhcd = oz_hcd_private(hcd); - oz_trace2(OZ_TRACE_HUB, "GetPortStatus windex = %d\n", windex); + oz_dbg(HUB, "GetPortStatus windex = %d\n", windex); status = ozhcd->ports[windex-1].status; put_unaligned(cpu_to_le32(status), (__le32 *)buf); - oz_trace2(OZ_TRACE_HUB, "Port[%d] status = %x\n", windex, status); + oz_dbg(HUB, "Port[%d] status = %x\n", windex, status); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue, u16 windex, char *buf, u16 wlength) { int err = 0; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_control()\n"); + switch (req_type) { case ClearHubFeature: - oz_trace2(OZ_TRACE_HUB, "ClearHubFeature: %d\n", req_type); + oz_dbg(HUB, "ClearHubFeature: %d\n", req_type); break; case ClearPortFeature: err = oz_clear_port_feature(hcd, wvalue, windex); @@ -2086,32 +2180,32 @@ static int oz_hcd_hub_control(struct usb_hcd *hcd, u16 req_type, u16 wvalue, oz_get_hub_descriptor(hcd, (struct usb_hub_descriptor *)buf); break; case GetHubStatus: - oz_trace2(OZ_TRACE_HUB, "GetHubStatus: req_type = 0x%x\n", - req_type); + oz_dbg(HUB, "GetHubStatus: req_type = 0x%x\n", req_type); put_unaligned(__constant_cpu_to_le32(0), (__le32 *)buf); break; case GetPortStatus: err = oz_get_port_status(hcd, windex, buf); break; case SetHubFeature: - oz_trace2(OZ_TRACE_HUB, "SetHubFeature: %d\n", req_type); + oz_dbg(HUB, "SetHubFeature: %d\n", req_type); break; case SetPortFeature: err = oz_set_port_feature(hcd, wvalue, windex); break; default: - oz_trace2(OZ_TRACE_HUB, "Other: %d\n", req_type); + oz_dbg(HUB, "Other: %d\n", req_type); break; } return err; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_hcd_bus_suspend(struct usb_hcd *hcd) { struct oz_hcd *ozhcd; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_suspend()\n"); + ozhcd = oz_hcd_private(hcd); spin_lock_bh(&ozhcd->hcd_lock); hcd->state = HC_STATE_SUSPENDED; @@ -2119,13 +2213,14 @@ static int oz_hcd_bus_suspend(struct usb_hcd *hcd) spin_unlock_bh(&ozhcd->hcd_lock); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_hcd_bus_resume(struct usb_hcd *hcd) { struct oz_hcd *ozhcd; - oz_trace2(OZ_TRACE_HUB, "oz_hcd_hub_resume()\n"); + ozhcd = oz_hcd_private(hcd); spin_lock_bh(&ozhcd->hcd_lock); ozhcd->flags &= ~OZ_HDC_F_SUSPENDED; @@ -2133,13 +2228,12 @@ static int oz_hcd_bus_resume(struct usb_hcd *hcd) spin_unlock_bh(&ozhcd->hcd_lock); return 0; } -/*------------------------------------------------------------------------------ - */ + static void oz_plat_shutdown(struct platform_device *dev) { - oz_trace("oz_plat_shutdown()\n"); } -/*------------------------------------------------------------------------------ + +/* * Context: process */ static int oz_plat_probe(struct platform_device *dev) @@ -2148,10 +2242,10 @@ static int oz_plat_probe(struct platform_device *dev) int err; struct usb_hcd *hcd; struct oz_hcd *ozhcd; - oz_trace("oz_plat_probe()\n"); + hcd = usb_create_hcd(&g_oz_hc_drv, &dev->dev, dev_name(&dev->dev)); if (hcd == NULL) { - oz_trace("Failed to created hcd object OK\n"); + oz_dbg(ON, "Failed to created hcd object OK\n"); return -ENOMEM; } ozhcd = oz_hcd_private(hcd); @@ -2172,7 +2266,7 @@ static int oz_plat_probe(struct platform_device *dev) } err = usb_add_hcd(hcd, 0, 0); if (err) { - oz_trace("Failed to add hcd object OK\n"); + oz_dbg(ON, "Failed to add hcd object OK\n"); usb_put_hcd(hcd); return -1; } @@ -2181,14 +2275,15 @@ static int oz_plat_probe(struct platform_device *dev) spin_unlock_bh(&g_hcdlock); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_plat_remove(struct platform_device *dev) { struct usb_hcd *hcd = platform_get_drvdata(dev); struct oz_hcd *ozhcd; - oz_trace("oz_plat_remove()\n"); + if (hcd == NULL) return -1; ozhcd = oz_hcd_private(hcd); @@ -2196,42 +2291,45 @@ static int oz_plat_remove(struct platform_device *dev) if (ozhcd == g_ozhcd) g_ozhcd = NULL; spin_unlock_bh(&g_hcdlock); - oz_trace("Clearing orphanage\n"); + oz_dbg(ON, "Clearing orphanage\n"); oz_hcd_clear_orphanage(ozhcd, -EPIPE); - oz_trace("Removing hcd\n"); + oz_dbg(ON, "Removing hcd\n"); usb_remove_hcd(hcd); usb_put_hcd(hcd); oz_empty_link_pool(); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: unknown */ static int oz_plat_suspend(struct platform_device *dev, pm_message_t msg) { - oz_trace("oz_plat_suspend()\n"); return 0; } -/*------------------------------------------------------------------------------ + + +/* * Context: unknown */ static int oz_plat_resume(struct platform_device *dev) { - oz_trace("oz_plat_resume()\n"); return 0; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ int oz_hcd_init(void) { int err; + if (usb_disabled()) return -ENODEV; tasklet_init(&g_urb_process_tasklet, oz_urb_process_tasklet, 0); tasklet_init(&g_urb_cancel_tasklet, oz_urb_cancel_tasklet, 0); err = platform_driver_register(&g_oz_plat_drv); - oz_trace("platform_driver_register() returned %d\n", err); + oz_dbg(ON, "platform_driver_register() returned %d\n", err); if (err) goto error; g_plat_dev = platform_device_alloc(OZ_PLAT_DEV_NAME, -1); @@ -2239,11 +2337,11 @@ int oz_hcd_init(void) err = -ENOMEM; goto error1; } - oz_trace("platform_device_alloc() succeeded\n"); + oz_dbg(ON, "platform_device_alloc() succeeded\n"); err = platform_device_add(g_plat_dev); if (err) goto error2; - oz_trace("platform_device_add() succeeded\n"); + oz_dbg(ON, "platform_device_add() succeeded\n"); return 0; error2: platform_device_put(g_plat_dev); @@ -2252,17 +2350,19 @@ error1: error: tasklet_disable(&g_urb_process_tasklet); tasklet_disable(&g_urb_cancel_tasklet); - oz_trace("oz_hcd_init() failed %d\n", err); + oz_dbg(ON, "oz_hcd_init() failed %d\n", err); return err; } -/*------------------------------------------------------------------------------ + +/* * Context: process */ void oz_hcd_term(void) { + msleep(OZ_HUB_DEBOUNCE_TIMEOUT); tasklet_kill(&g_urb_process_tasklet); tasklet_kill(&g_urb_cancel_tasklet); platform_device_unregister(g_plat_dev); platform_driver_unregister(&g_oz_plat_drv); - oz_trace("Pending urbs:%d\n", atomic_read(&g_pending_urbs)); + oz_dbg(ON, "Pending urbs:%d\n", atomic_read(&g_pending_urbs)); } |