Commit 455980ab authored by Linus Torvalds's avatar Linus Torvalds

Merge USB update

parents 54f1543d b305ae0f
...@@ -690,7 +690,6 @@ static void irda_usb_net_timeout(struct net_device *netdev) ...@@ -690,7 +690,6 @@ static void irda_usb_net_timeout(struct net_device *netdev)
* The way I see it is that if we submit more than one Rx URB at a * The way I see it is that if we submit more than one Rx URB at a
* time, the Rx URB can be automatically re-submitted after the * time, the Rx URB can be automatically re-submitted after the
* completion handler is called. * completion handler is called.
* We make sure to disable this feature by setting urb->next to NULL
* *
* My take is that it's a questionable feature, and quite difficult * My take is that it's a questionable feature, and quite difficult
* to control and to make work effectively. * to control and to make work effectively.
...@@ -754,7 +753,6 @@ static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, struc ...@@ -754,7 +753,6 @@ static void irda_usb_submit(struct irda_usb_cb *self, struct sk_buff *skb, struc
/* Note : unlink *must* be synchronous because of the code in /* Note : unlink *must* be synchronous because of the code in
* irda_usb_net_close() -> free the skb - Jean II */ * irda_usb_net_close() -> free the skb - Jean II */
urb->status = 0; urb->status = 0;
urb->next = NULL; /* Don't auto resubmit URBs */
/* Can be called from irda_usb_receive (irq handler) -> GFP_ATOMIC */ /* Can be called from irda_usb_receive (irq handler) -> GFP_ATOMIC */
ret = usb_submit_urb(urb, GFP_ATOMIC); ret = usb_submit_urb(urb, GFP_ATOMIC);
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
mod-subdirs := serial mod-subdirs := serial
obj-$(CONFIG_USB) += core/ obj-$(CONFIG_USB) += core/
obj-$(CONFIG_USB_EHCI_HCD) += host/ obj-$(CONFIG_USB_EHCI_HCD) += host/
obj-$(CONFIG_USB_OHCI_HCD) += host/ obj-$(CONFIG_USB_OHCI_HCD) += host/
obj-$(CONFIG_USB_OHCI) += host/ obj-$(CONFIG_USB_OHCI) += host/
obj-$(CONFIG_USB_SL811HS) += host/
obj-$(CONFIG_USB_UHCI_ALT) += host/ obj-$(CONFIG_USB_UHCI_ALT) += host/
obj-$(CONFIG_USB_UHCI_HCD_ALT) += host/ obj-$(CONFIG_USB_UHCI_HCD_ALT) += host/
obj-$(CONFIG_USB_UHCI_HCD) += host/ obj-$(CONFIG_USB_UHCI_HCD) += host/
......
...@@ -745,12 +745,18 @@ EXPORT_SYMBOL (usb_register_root_hub); ...@@ -745,12 +745,18 @@ EXPORT_SYMBOL (usb_register_root_hub);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* /**
* usb_calc_bus_time: * usb_calc_bus_time: approximate periodic transaction time in nanoseconds
* @speed: from dev->speed; USB_SPEED_{LOW,FULL,HIGH}
* @is_input: true iff the transaction sends data to the host
* @is_isoc: true for isochronous transactions, false for interrupt ones
* @bytecount: how many bytes in the transaction.
*
* Returns approximate bus time in nanoseconds for a periodic transaction. * Returns approximate bus time in nanoseconds for a periodic transaction.
* See USB 2.0 spec section 5.11.3 * See USB 2.0 spec section 5.11.3; only periodic transfers need to be
* scheduled in software, this function is only used for such scheduling.
*/ */
static long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount) long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
{ {
unsigned long tmp; unsigned long tmp;
...@@ -772,14 +778,18 @@ static long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount) ...@@ -772,14 +778,18 @@ static long usb_calc_bus_time (int speed, int is_input, int isoc, int bytecount)
return (9107L + BW_HOST_DELAY + tmp); return (9107L + BW_HOST_DELAY + tmp);
} }
case USB_SPEED_HIGH: /* ISOC or INTR */ case USB_SPEED_HIGH: /* ISOC or INTR */
// FIXME merge from EHCI code; caller will need to handle // FIXME adjust for input vs output
// each part of a split separately. if (isoc)
return 0; tmp = HS_USECS (bytecount);
else
tmp = HS_USECS_ISO (bytecount);
return tmp;
default: default:
dbg ("bogus device speed!"); dbg ("bogus device speed!");
return -1; return -1;
} }
} }
EXPORT_SYMBOL (usb_calc_bus_time);
/* /*
* usb_check_bandwidth(): * usb_check_bandwidth():
......
...@@ -263,6 +263,22 @@ extern void usb_release_bandwidth (struct usb_device *dev, struct urb *urb, ...@@ -263,6 +263,22 @@ extern void usb_release_bandwidth (struct usb_device *dev, struct urb *urb,
extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb); extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
/*
* Ceiling microseconds (typical) for that many bytes at high speed
* ISO is a bit less, no ACK ... from USB 2.0 spec, 5.11.3 (and needed
* to preallocate bandwidth)
*/
#define USB2_HOST_DELAY 5 /* nsec, guess */
#define HS_USECS(bytes) NS_TO_US ( ((55 * 8 * 2083)/1000) \
+ ((2083UL * (3167 + BitTime (bytes)))/1000) \
+ USB2_HOST_DELAY)
#define HS_USECS_ISO(bytes) NS_TO_US ( ((long)(38 * 8 * 2.083)) \
+ ((2083UL * (3167 + BitTime (bytes)))/1000) \
+ USB2_HOST_DELAY)
extern long usb_calc_bus_time (int speed, int is_input,
int isoc, int bytecount);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
extern struct usb_bus *usb_alloc_bus (struct usb_operations *); extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
......
...@@ -2032,8 +2032,8 @@ int usb_set_address(struct usb_device *dev) ...@@ -2032,8 +2032,8 @@ int usb_set_address(struct usb_device *dev)
* *
* This call is synchronous, and may not be used in an interrupt context. * This call is synchronous, and may not be used in an interrupt context.
* *
* Returns zero on success, or else the status code returned by the * Returns the number of bytes received on success, or else the status code
* underlying usb_control_msg() call. * returned by the underlying usb_control_msg() call.
*/ */
int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size) int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char index, void *buf, int size)
{ {
...@@ -2073,8 +2073,8 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char ...@@ -2073,8 +2073,8 @@ int usb_get_descriptor(struct usb_device *dev, unsigned char type, unsigned char
* *
* This call is synchronous, and may not be used in an interrupt context. * This call is synchronous, and may not be used in an interrupt context.
* *
* Returns zero on success, or else the status code returned by the * Returns the number of bytes received on success, or else the status code
* underlying usb_control_msg() call. * returned by the underlying usb_control_msg() call.
*/ */
int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char index, void *buf, int size) int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char index, void *buf, int size)
{ {
...@@ -2100,8 +2100,8 @@ int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char ...@@ -2100,8 +2100,8 @@ int usb_get_string(struct usb_device *dev, unsigned short langid, unsigned char
* *
* This call is synchronous, and may not be used in an interrupt context. * This call is synchronous, and may not be used in an interrupt context.
* *
* Returns zero on success, or else the status code returned by the * Returns the number of bytes received on success, or else the status code
* underlying usb_control_msg() call. * returned by the underlying usb_control_msg() call.
*/ */
int usb_get_device_descriptor(struct usb_device *dev) int usb_get_device_descriptor(struct usb_device *dev)
{ {
...@@ -2135,8 +2135,8 @@ int usb_get_device_descriptor(struct usb_device *dev) ...@@ -2135,8 +2135,8 @@ int usb_get_device_descriptor(struct usb_device *dev)
* *
* This call is synchronous, and may not be used in an interrupt context. * This call is synchronous, and may not be used in an interrupt context.
* *
* Returns zero on success, or else the status code returned by the * Returns the number of bytes received on success, or else the status code
* underlying usb_control_msg() call. * returned by the underlying usb_control_msg() call.
*/ */
int usb_get_status(struct usb_device *dev, int type, int target, void *data) int usb_get_status(struct usb_device *dev, int type, int target, void *data)
{ {
......
...@@ -89,3 +89,13 @@ CONFIG_USB_OHCI ...@@ -89,3 +89,13 @@ CONFIG_USB_OHCI
inserted in and removed from the running kernel whenever you want). inserted in and removed from the running kernel whenever you want).
The module will be called usb-ohci.o. If you want to compile it The module will be called usb-ohci.o. If you want to compile it
as a module, say M here and read <file:Documentation/modules.txt>. as a module, say M here and read <file:Documentation/modules.txt>.
CONFIG_USB_SL811HS
Say Y here if you have a SL811HS USB host controller in your system.
If you do not know what this is, please say N.
This code is also available as a module ( = code which can be
inserted in and removed from the running kernel whenever you want).
The module will be called hc_sl811.o. If you want to compile it
as a module, say M here and read <file:Documentation/modules.txt>.
...@@ -19,3 +19,6 @@ fi ...@@ -19,3 +19,6 @@ fi
# define_bool CONFIG_USB_UHCI_ALT n # define_bool CONFIG_USB_UHCI_ALT n
#fi #fi
#dep_tristate ' OHCI (Compaq, iMacs, OPTi, SiS, ALi, ...) support' CONFIG_USB_OHCI $CONFIG_USB #dep_tristate ' OHCI (Compaq, iMacs, OPTi, SiS, ALi, ...) support' CONFIG_USB_OHCI $CONFIG_USB
if [ "$CONFIG_ARM" = "y" ]; then
dep_tristate ' SL811HS support' CONFIG_USB_SL811HS $CONFIG_USB
fi
...@@ -11,5 +11,6 @@ obj-$(CONFIG_USB_UHCI_HCD_ALT) += uhci-hcd.o ...@@ -11,5 +11,6 @@ obj-$(CONFIG_USB_UHCI_HCD_ALT) += uhci-hcd.o
obj-$(CONFIG_USB_UHCI) += usb-uhci.o obj-$(CONFIG_USB_UHCI) += usb-uhci.o
obj-$(CONFIG_USB_UHCI_ALT) += uhci.o obj-$(CONFIG_USB_UHCI_ALT) += uhci.o
obj-$(CONFIG_USB_OHCI) += usb-ohci.o obj-$(CONFIG_USB_OHCI) += usb-ohci.o
obj-$(CONFIG_USB_SL811HS) += hc_sl811.o
include $(TOPDIR)/Rules.make include $(TOPDIR)/Rules.make
...@@ -102,8 +102,8 @@ static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {} ...@@ -102,8 +102,8 @@ static inline void dbg_hcc_params (struct ehci_hcd *ehci, char *label) {}
#ifdef DEBUG #ifdef DEBUG
#if 0 static void __attribute__((__unused__))
static void dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
{ {
dbg ("%s %p info1 %x info2 %x hw_curr %x qtd_next %x", label, dbg ("%s %p info1 %x info2 %x hw_curr %x qtd_next %x", label,
qh, qh->hw_info1, qh->hw_info2, qh, qh->hw_info1, qh->hw_info2,
...@@ -117,15 +117,13 @@ static void dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) ...@@ -117,15 +117,13 @@ static void dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh)
qh->hw_buf [4]); qh->hw_buf [4]);
} }
} }
#endif
static const char *const fls_strings [] = static const char *const fls_strings [] =
{ "1024", "512", "256", "??" }; { "1024", "512", "256", "??" };
#else #else
#if 0 static inline void __attribute__((__unused__))
static inline void dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) {} dbg_qh (char *label, struct ehci_hcd *ehci, struct ehci_qh *qh) {}
#endif
#endif /* DEBUG */ #endif /* DEBUG */
/* functions have the "wrong" filename when they're output... */ /* functions have the "wrong" filename when they're output... */
......
...@@ -65,6 +65,7 @@ ...@@ -65,6 +65,7 @@
* *
* HISTORY: * HISTORY:
* *
* 2002-05-24 Preliminary FS/LS interrupts, using scheduling shortcuts
* 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other * 2002-05-11 Clear TT errors for FS/LS ctrl/bulk. Fill in some other
* missing pieces: enabling 64bit dma, handoff from BIOS/SMM. * missing pieces: enabling 64bit dma, handoff from BIOS/SMM.
* 2002-05-07 Some error path cleanups to report better errors; wmb(); * 2002-05-07 Some error path cleanups to report better errors; wmb();
...@@ -82,7 +83,7 @@ ...@@ -82,7 +83,7 @@
* 2001-June Works with usb-storage and NEC EHCI on 2.4 * 2001-June Works with usb-storage and NEC EHCI on 2.4
*/ */
#define DRIVER_VERSION "2002-May-11" #define DRIVER_VERSION "2002-May-24"
#define DRIVER_AUTHOR "David Brownell" #define DRIVER_AUTHOR "David Brownell"
#define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver" #define DRIVER_DESC "USB 2.0 'Enhanced' Host Controller (EHCI) Driver"
...@@ -622,7 +623,10 @@ dbg ("wait for dequeue: state %d, reclaim %p, hcd state %d", ...@@ -622,7 +623,10 @@ dbg ("wait for dequeue: state %d, reclaim %p, hcd state %d",
return 0; return 0;
case PIPE_INTERRUPT: case PIPE_INTERRUPT:
intr_deschedule (ehci, urb->start_frame, qh, urb->interval); intr_deschedule (ehci, urb->start_frame, qh,
(urb->dev->speed == USB_SPEED_HIGH)
? urb->interval
: (urb->interval << 3));
if (ehci->hcd.state == USB_STATE_HALT) if (ehci->hcd.state == USB_STATE_HALT)
urb->status = -ESHUTDOWN; urb->status = -ESHUTDOWN;
qh_completions (ehci, qh, 1); qh_completions (ehci, qh, 1);
......
...@@ -33,19 +33,6 @@ ...@@ -33,19 +33,6 @@
* or with "USB On The Go" additions to USB 2.0 ...) * or with "USB On The Go" additions to USB 2.0 ...)
*/ */
/*
* Ceiling microseconds (typical) for that many bytes at high speed
* ISO is a bit less, no ACK ... from USB 2.0 spec, 5.11.3 (and needed
* to preallocate bandwidth)
*/
#define EHCI_HOST_DELAY 5 /* nsec, guess */
#define HS_USECS(bytes) NS_TO_US ( ((55 * 8 * 2083)/1000) \
+ ((2083UL * (3167 + BitTime (bytes)))/1000) \
+ EHCI_HOST_DELAY)
#define HS_USECS_ISO(bytes) NS_TO_US ( ((long)(38 * 8 * 2.083)) \
+ ((2083UL * (3167 + BitTime (bytes)))/1000) \
+ EHCI_HOST_DELAY)
static int ehci_get_frame (struct usb_hcd *hcd); static int ehci_get_frame (struct usb_hcd *hcd);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -124,6 +111,9 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe) ...@@ -124,6 +111,9 @@ periodic_usecs (struct ehci_hcd *ehci, unsigned frame, unsigned uframe)
/* is it in the S-mask? */ /* is it in the S-mask? */
if (q->qh->hw_info2 & cpu_to_le32 (1 << uframe)) if (q->qh->hw_info2 & cpu_to_le32 (1 << uframe))
usecs += q->qh->usecs; usecs += q->qh->usecs;
/* ... or C-mask? */
if (q->qh->hw_info2 & cpu_to_le32 (1 << (8 + uframe)))
usecs += q->qh->c_usecs;
q = &q->qh->qh_next; q = &q->qh->qh_next;
break; break;
case Q_TYPE_FSTN: case Q_TYPE_FSTN:
...@@ -273,6 +263,12 @@ static int check_period ( ...@@ -273,6 +263,12 @@ static int check_period (
unsigned period, unsigned period,
unsigned usecs unsigned usecs
) { ) {
/* complete split running into next frame?
* given FSTN support, we could sometimes check...
*/
if (uframe >= 8)
return 0;
/* /*
* 80% periodic == 100 usec/uframe available * 80% periodic == 100 usec/uframe available
* convert "usecs we need" to "max already claimed" * convert "usecs we need" to "max already claimed"
...@@ -284,6 +280,8 @@ static int check_period ( ...@@ -284,6 +280,8 @@ static int check_period (
// FIXME delete when intr_submit handles non-empty queues // FIXME delete when intr_submit handles non-empty queues
// this gives us a one intr/frame limit (vs N/uframe) // this gives us a one intr/frame limit (vs N/uframe)
// ... and also lets us avoid tracking split transactions
// that might collide at a given TT/hub.
if (ehci->pshadow [frame].ptr) if (ehci->pshadow [frame].ptr)
return 0; return 0;
...@@ -305,20 +303,54 @@ static int intr_submit ( ...@@ -305,20 +303,54 @@ static int intr_submit (
int mem_flags int mem_flags
) { ) {
unsigned epnum, period; unsigned epnum, period;
unsigned short usecs; unsigned short usecs, c_usecs, gap_uf;
unsigned long flags; unsigned long flags;
struct ehci_qh *qh; struct ehci_qh *qh;
struct hcd_dev *dev; struct hcd_dev *dev;
int is_input;
int status = 0; int status = 0;
/* get endpoint and transfer data */ /* get endpoint and transfer/schedule data */
epnum = usb_pipeendpoint (urb->pipe); epnum = usb_pipeendpoint (urb->pipe);
if (usb_pipein (urb->pipe)) is_input = usb_pipein (urb->pipe);
if (is_input)
epnum |= 0x10; epnum |= 0x10;
if (urb->dev->speed != USB_SPEED_HIGH) {
dbg ("no intr/tt scheduling yet"); /*
status = -ENOSYS; * HS interrupt transfers are simple -- only one microframe. FS/LS
goto done; * interrupt transfers involve a SPLIT in one microframe and CSPLIT
* sometime later. We need to know how much time each will be
* needed in each microframe and, for FS/LS, how many microframes
* separate the two in the best case.
*/
usecs = usb_calc_bus_time (USB_SPEED_HIGH, is_input, 0,
urb->transfer_buffer_length);
if (urb->dev->speed == USB_SPEED_HIGH) {
gap_uf = 0;
c_usecs = 0;
/* FIXME handle HS periods of less than 1 frame. */
period = urb->interval >> 3;
if (period < 1) {
dbg ("intr period %d uframes, NYET!", urb->interval);
status = -EINVAL;
goto done;
}
} else {
/* gap is a function of full/low speed transfer times */
gap_uf = 1 + usb_calc_bus_time (urb->dev->speed, is_input, 0,
urb->transfer_buffer_length) / (125 * 1000);
/* FIXME this just approximates SPLIT/CSPLIT times */
if (is_input) { // SPLIT, gap, CSPLIT+DATA
c_usecs = usecs + HS_USECS (0);
usecs = HS_USECS (1);
} else { // SPLIT+DATA, gap, CSPLIT
usecs = usecs + HS_USECS (1);
c_usecs = HS_USECS (0);
}
period = urb->interval;
} }
/* /*
...@@ -339,16 +371,6 @@ static int intr_submit ( ...@@ -339,16 +371,6 @@ static int intr_submit (
goto done; goto done;
} }
usecs = HS_USECS (urb->transfer_buffer_length);
/* FIXME handle HS periods of less than 1 frame. */
period = urb->interval >> 3;
if (period < 1) {
dbg ("intr period %d uframes, NYET!", urb->interval);
status = -EINVAL;
goto done;
}
spin_lock_irqsave (&ehci->lock, flags); spin_lock_irqsave (&ehci->lock, flags);
/* get the qh (must be empty and idle) */ /* get the qh (must be empty and idle) */
...@@ -392,6 +414,7 @@ static int intr_submit ( ...@@ -392,6 +414,7 @@ static int intr_submit (
qh->hw_next = EHCI_LIST_END; qh->hw_next = EHCI_LIST_END;
qh->usecs = usecs; qh->usecs = usecs;
qh->c_usecs = c_usecs;
urb->hcpriv = qh_get (qh); urb->hcpriv = qh_get (qh);
status = -ENOSPC; status = -ENOSPC;
...@@ -399,18 +422,47 @@ static int intr_submit ( ...@@ -399,18 +422,47 @@ static int intr_submit (
/* pick a set of schedule slots, link the QH into them */ /* pick a set of schedule slots, link the QH into them */
do { do {
int uframe; int uframe;
u32 c_mask = 0;
/* pick a set of slots such that all uframes have /* pick a set of slots such that all uframes have
* enough periodic bandwidth available. * enough periodic bandwidth available.
*
* FIXME for TT splits, need uframes for start and end.
* FSTNs can put end into next frame (uframes 0 or 1).
*/ */
frame--; frame--;
for (uframe = 0; uframe < 8; uframe++) { for (uframe = 0; uframe < 8; uframe++) {
if (check_period (ehci, frame, uframe, if (check_period (ehci, frame, uframe,
period, usecs) != 0) period, usecs) == 0)
break; continue;
/* If this is a split transaction, check the
* bandwidth available for the completion
* too. check both best and worst case gaps:
* worst case is SPLIT near uframe end, and
* CSPLIT near start ... best is vice versa.
* Difference can be almost two uframe times.
*
* FIXME don't even bother unless we know
* this TT is idle in that uframe ... right
* now we know only one interrupt transfer
* will be scheduled per frame, so we don't
* need to update/check TT state when we
* schedule a split (QH, SITD, or FSTN).
*
* FIXME ehci 0.96 and above can use FSTNs
*/
if (!c_usecs)
break;
if (check_period (ehci, frame,
uframe + gap_uf,
period, c_usecs) == 0)
continue;
if (check_period (ehci, frame,
uframe + gap_uf + 1,
period, c_usecs) == 0)
continue;
c_mask = 0x03 << (8 + uframe + gap_uf);
c_mask = cpu_to_le32 (c_mask);
break;
} }
if (uframe == 8) if (uframe == 8)
continue; continue;
...@@ -419,13 +471,14 @@ static int intr_submit ( ...@@ -419,13 +471,14 @@ static int intr_submit (
urb->start_frame = frame; urb->start_frame = frame;
status = 0; status = 0;
/* set S-frame mask */ /* reset S-frame and (maybe) C-frame masks */
qh->hw_info2 |= cpu_to_le32 (1 << uframe); qh->hw_info2 &= ~0xffff;
qh->hw_info2 |= cpu_to_le32 (1 << uframe) | c_mask;
// dbg_qh ("Schedule INTR qh", ehci, qh); // dbg_qh ("Schedule INTR qh", ehci, qh);
/* stuff into the periodic schedule */ /* stuff into the periodic schedule */
qh->qh_state = QH_STATE_LINKED; qh->qh_state = QH_STATE_LINKED;
vdbg ("qh %p usecs %d period %d starting %d.%d", vdbg ("qh %p usecs %d period %d.0 starting %d.%d",
qh, qh->usecs, period, frame, uframe); qh, qh->usecs, period, frame, uframe);
do { do {
if (unlikely (ehci->pshadow [frame].ptr != 0)) { if (unlikely (ehci->pshadow [frame].ptr != 0)) {
...@@ -443,7 +496,8 @@ static int intr_submit ( ...@@ -443,7 +496,8 @@ static int intr_submit (
} while (frame < ehci->periodic_size); } while (frame < ehci->periodic_size);
/* update bandwidth utilization records (for usbfs) */ /* update bandwidth utilization records (for usbfs) */
usb_claim_bandwidth (urb->dev, urb, usecs/period, 0); usb_claim_bandwidth (urb->dev, urb,
(usecs + c_usecs) / period, 0);
/* maybe enable periodic schedule processing */ /* maybe enable periodic schedule processing */
if (!ehci->periodic_urbs++) if (!ehci->periodic_urbs++)
...@@ -557,6 +611,7 @@ itd_fill ( ...@@ -557,6 +611,7 @@ itd_fill (
u32 buf1; u32 buf1;
unsigned i, epnum, maxp, multi; unsigned i, epnum, maxp, multi;
unsigned length; unsigned length;
int is_input;
itd->hw_next = EHCI_LIST_END; itd->hw_next = EHCI_LIST_END;
itd->urb = urb; itd->urb = urb;
...@@ -578,7 +633,8 @@ itd_fill ( ...@@ -578,7 +633,8 @@ itd_fill (
* as encoded in the ep descriptor's maxpacket field * as encoded in the ep descriptor's maxpacket field
*/ */
epnum = usb_pipeendpoint (urb->pipe); epnum = usb_pipeendpoint (urb->pipe);
if (usb_pipein (urb->pipe)) { is_input = usb_pipein (urb->pipe);
if (is_input) {
maxp = urb->dev->epmaxpacketin [epnum]; maxp = urb->dev->epmaxpacketin [epnum];
buf1 = (1 << 11); buf1 = (1 << 11);
} else { } else {
...@@ -598,7 +654,7 @@ itd_fill ( ...@@ -598,7 +654,7 @@ itd_fill (
urb->iso_frame_desc [index].length); urb->iso_frame_desc [index].length);
return -ENOSPC; return -ENOSPC;
} }
itd->usecs = HS_USECS_ISO (length); itd->usecs = usb_calc_bus_time (USB_SPEED_HIGH, is_input, 1, length);
/* "plus" info in low order bits of buffer pointers */ /* "plus" info in low order bits of buffer pointers */
itd->hw_bufp [0] |= cpu_to_le32 ((epnum << 8) | urb->dev->devnum); itd->hw_bufp [0] |= cpu_to_le32 ((epnum << 8) | urb->dev->devnum);
...@@ -919,17 +975,9 @@ itd_complete ( ...@@ -919,17 +975,9 @@ itd_complete (
return flags; return flags;
/* /*
* For now, always give the urb back to the driver ... expect it * Always give the urb back to the driver ... expect it to submit
* to submit a new urb (or resubmit this), and to have another * a new urb (or resubmit this), and to have another already queued
* already queued when un-interrupted transfers are needed. * when un-interrupted transfers are needed.
* No, that's not what OHCI or UHCI are now doing.
*
* FIXME Revisit the ISO URB model. It's cleaner not to have all
* the special case magic, but it'd be faster to reuse existing
* ITD/DMA setup and schedule state. Easy to dma_sync/complete(),
* then either reschedule or, if unlinking, free and giveback().
* But we can't overcommit like the full and low speed HCs do, and
* there's no clean way to report an error when rescheduling...
* *
* NOTE that for now we don't accelerate ISO unlinks; they just * NOTE that for now we don't accelerate ISO unlinks; they just
* happen according to the current schedule. Means a delay of * happen according to the current schedule. Means a delay of
......
...@@ -288,14 +288,11 @@ struct ehci_qh { ...@@ -288,14 +288,11 @@ struct ehci_qh {
atomic_t refcount; atomic_t refcount;
unsigned short usecs; /* intr bandwidth */ unsigned short usecs; /* intr bandwidth */
unsigned short c_usecs; /* ... split completion bw */
short qh_state; short qh_state;
#define QH_STATE_LINKED 1 /* HC sees this */ #define QH_STATE_LINKED 1 /* HC sees this */
#define QH_STATE_UNLINK 2 /* HC may still see this */ #define QH_STATE_UNLINK 2 /* HC may still see this */
#define QH_STATE_IDLE 3 /* HC doesn't see this */ #define QH_STATE_IDLE 3 /* HC doesn't see this */
#ifdef EHCI_SOFT_RETRIES
int retries;
#endif
} __attribute__ ((aligned (32))); } __attribute__ ((aligned (32)));
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
...@@ -360,6 +357,9 @@ struct ehci_sitd { ...@@ -360,6 +357,9 @@ struct ehci_sitd {
union ehci_shadow sitd_next; /* ptr to periodic q entry */ union ehci_shadow sitd_next; /* ptr to periodic q entry */
struct urb *urb; struct urb *urb;
dma_addr_t buf_dma; /* buffer address */ dma_addr_t buf_dma; /* buffer address */
unsigned short usecs; /* start bandwidth */
unsigned short c_usecs; /* completion bandwidth */
} __attribute__ ((aligned (32))); } __attribute__ ((aligned (32)));
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
......
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*
* simple generic USB HCD frontend Version 0.9.5 (10/28/2001)
* for embedded HCs (SL811HS)
*
* USB URB handling, hci_ hcs_
* URB queueing, qu_
* Transfer scheduling, sh_
*
*
*-------------------------------------------------------------------------*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*-------------------------------------------------------------------------*/
/* main lock for urb access */
static spinlock_t usb_urb_lock = SPIN_LOCK_UNLOCKED;
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
/* URB HCD API function layer
* * * */
/***************************************************************************
* Function Name : hcs_urb_queue
*
* This function initializes the urb status and length before queueing the
* urb.
*
* Input: hci = data structure for the host controller
* urb = USB request block data structure
*
* Return: 0
**************************************************************************/
static inline int hcs_urb_queue (hci_t * hci, struct urb * urb)
{
int i;
DBGFUNC ("enter hcs_urb_queue\n");
if (usb_pipeisoc (urb->pipe)) {
DBGVERBOSE ("hcs_urb_queue: isoc pipe\n");
for (i = 0; i < urb->number_of_packets; i++) {
urb->iso_frame_desc[i].actual_length = 0;
urb->iso_frame_desc[i].status = -EXDEV;
}
/* urb->next hack : 1 .. resub, 0 .. single shot */
/* urb->interval = urb->next ? 1 : 0; */
}
urb->status = -EINPROGRESS;
urb->actual_length = 0;
urb->error_count = 0;
if (usb_pipecontrol (urb->pipe))
hc_flush_data_cache (hci, urb->setup_packet, 8);
if (usb_pipeout (urb->pipe))
hc_flush_data_cache (hci, urb->transfer_buffer,
urb->transfer_buffer_length);
qu_queue_urb (hci, urb);
return 0;
}
/***************************************************************************
* Function Name : hcs_return_urb
*
* This function the return path of URB back to the USB core. It calls the
* the urb complete function if exist, and also handles the resubmition of
* interrupt URBs.
*
* Input: hci = data structure for the host controller
* urb = USB request block data structure
* resub_ok = resubmit flag: 1 = submit urb again, 0 = not submit
*
* Return: 0
**************************************************************************/
static int hcs_return_urb (hci_t * hci, struct urb * urb, int resub_ok)
{
struct usb_device *dev = urb->dev;
int resubmit = 0;
DBGFUNC ("enter hcs_return_urb, urb pointer = 0x%x, "
"transferbuffer point = 0x%x, "
" setup packet pointer = 0x%x, context pointer = 0x%x \n",
(__u32 *) urb, (__u32 *) urb->transfer_buffer,
(__u32 *) urb->setup_packet, (__u32 *) urb->context);
if (urb_debug)
urb_print (urb, "RET", usb_pipeout (urb->pipe));
resubmit = urb->interval && resub_ok;
urb->dev = urb->hcpriv = NULL;
if (urb->complete) {
urb->complete (urb); /* call complete */
}
if (resubmit) {
/* requeue the URB */
urb->dev = dev;
hcs_urb_queue (hci, urb);
} else {
usb_put_urb(urb);
}
return 0;
}
/***************************************************************************
* Function Name : hci_submit_urb
*
* This function is called by the USB core API when an URB is available to
* process. This function does the following
*
* 1) Check the validity of the URB
* 2) Parse the device number from the URB
* 3) Pass the URB to the root hub routine if its intended for the hub, else
* queue the urb for the attached device.
*
* Input: urb = USB request block data structure
*
* Return: 0 if success or error code
**************************************************************************/
static int hci_submit_urb (struct urb * urb, int mem_flags)
{
hci_t *hci;
unsigned int pipe = urb->pipe;
unsigned long flags;
int ret;
DBGFUNC ("enter hci_submit_urb, pipe = 0x%x\n", urb->pipe);
if (!urb->dev || !urb->dev->bus || urb->hcpriv)
return -EINVAL;
if (usb_endpoint_halted
(urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe))) {
printk ("hci_submit_urb: endpoint_halted\n");
return -EPIPE;
}
hci = (hci_t *) urb->dev->bus->hcpriv;
/* a request to the virtual root hub */
if (usb_pipedevice (pipe) == hci->rh.devnum) {
if (urb_debug > 1)
urb_print (urb, "SUB-RH", usb_pipein (pipe));
return rh_submit_urb (urb);
}
/* increment urb's reference count, we now control it. */
urb = usb_get_urb (urb);
/* queue the URB to its endpoint-queue */
spin_lock_irqsave (&usb_urb_lock, flags);
ret = hcs_urb_queue (hci, urb);
if (ret != 0) {
/* error on return */
DBGERR ("hci_submit_urb: return err, ret = 0x%x, urb->status = 0x%x\n",
ret, urb->status);
usb_put_urb (urb);
}
spin_unlock_irqrestore (&usb_urb_lock, flags);
return ret;
}
/***************************************************************************
* Function Name : hci_unlink_urb
*
* This function mark the URB to unlink
*
* Input: urb = USB request block data structure
*
* Return: 0 if success or error code
**************************************************************************/
static int hci_unlink_urb (struct urb * urb)
{
unsigned long flags;
hci_t *hci;
DECLARE_WAITQUEUE (wait, current);
void *comp = NULL;
DBGFUNC ("enter hci_unlink_urb\n");
if (!urb) /* just to be sure */
return -EINVAL;
if (!urb->dev || !urb->dev->bus)
return -ENODEV;
hci = (hci_t *) urb->dev->bus->hcpriv;
/* a request to the virtual root hub */
if (usb_pipedevice (urb->pipe) == hci->rh.devnum) {
return rh_unlink_urb (urb);
}
if (urb_debug)
urb_print (urb, "UNLINK", 1);
spin_lock_irqsave (&usb_urb_lock, flags);
if (!list_empty (&urb->urb_list) && urb->status == -EINPROGRESS) {
/* URB active? */
if (urb->transfer_flags & (USB_ASYNC_UNLINK | USB_TIMEOUT_KILLED)) {
/* asynchron with callback */
list_del (&urb->urb_list); /* relink the urb to the del list */
list_add (&urb->urb_list, &hci->del_list);
spin_unlock_irqrestore (&usb_urb_lock, flags);
} else {
/* synchron without callback */
add_wait_queue (&hci->waitq, &wait);
set_current_state (TASK_UNINTERRUPTIBLE);
comp = urb->complete;
urb->complete = NULL;
list_del (&urb->urb_list); /* relink the urb to the del list */
list_add (&urb->urb_list, &hci->del_list);
spin_unlock_irqrestore (&usb_urb_lock, flags);
schedule_timeout (HZ / 50);
if (!list_empty (&urb->urb_list))
list_del (&urb->urb_list);
urb->complete = comp;
urb->hcpriv = NULL;
remove_wait_queue (&hci->waitq, &wait);
}
} else {
/* hcd does not own URB but we keep the driver happy anyway */
spin_unlock_irqrestore (&usb_urb_lock, flags);
if (urb->complete && (urb->transfer_flags & USB_ASYNC_UNLINK)) {
urb->status = -ENOENT;
urb->actual_length = 0;
urb->complete (urb);
urb->status = 0;
} else {
urb->status = -ENOENT;
}
}
return 0;
}
/***************************************************************************
* Function Name : hci_alloc_dev
*
* This function allocates private data space for the usb device and
* initialize the endpoint descriptor heads.
*
* Input: usb_dev = pointer to the usb device
*
* Return: 0 if success or error code
**************************************************************************/
static int hci_alloc_dev (struct usb_device *usb_dev)
{
struct hci_device *dev;
int i;
DBGFUNC ("enter hci_alloc_dev\n");
dev = kmalloc (sizeof (*dev), GFP_KERNEL);
if (!dev)
return -ENOMEM;
memset (dev, 0, sizeof (*dev));
for (i = 0; i < 32; i++) {
INIT_LIST_HEAD (&(dev->ed[i].urb_queue));
dev->ed[i].pipe_head = NULL;
}
usb_dev->hcpriv = dev;
DBGVERBOSE ("USB HC dev alloc %d bytes\n", sizeof (*dev));
return 0;
}
/***************************************************************************
* Function Name : hci_free_dev
*
* This function de-allocates private data space for the usb devic
*
* Input: usb_dev = pointer to the usb device
*
* Return: 0
**************************************************************************/
static int hci_free_dev (struct usb_device *usb_dev)
{
DBGFUNC ("enter hci_free_dev\n");
if (usb_dev->hcpriv)
kfree (usb_dev->hcpriv);
usb_dev->hcpriv = NULL;
return 0;
}
/***************************************************************************
* Function Name : hci_get_current_frame_number
*
* This function get the current USB frame number
*
* Input: usb_dev = pointer to the usb device
*
* Return: frame number
**************************************************************************/
static int hci_get_current_frame_number (struct usb_device *usb_dev)
{
hci_t *hci = usb_dev->bus->hcpriv;
DBGFUNC ("enter hci_get_current_frame_number, frame = 0x%x \r\n",
hci->frame_number);
return (hci->frame_number);
}
/***************************************************************************
* List of all io-functions
**************************************************************************/
static struct usb_operations hci_device_operations = {
allocate: hci_alloc_dev,
deallocate: hci_free_dev,
get_frame_number: hci_get_current_frame_number,
submit_urb: hci_submit_urb,
unlink_urb: hci_unlink_urb,
};
/***************************************************************************
* URB queueing:
*
* For each type of transfer (INTR, BULK, ISO, CTRL) there is a list of
* active URBs.
* (hci->intr_list, hci->bulk_list, hci->iso_list, hci->ctrl_list)
* For every endpoint the head URB of the queued URBs is linked to one of
* those lists.
*
* The rest of the queued URBs of an endpoint are linked into a
* private URB list for each endpoint. (hci_dev->ed [endpoint_io].urb_queue)
* hci_dev->ed [endpoint_io].pipe_head .. points to the head URB which is
* in one of the active URB lists.
*
* The index of an endpoint consists of its number and its direction.
*
* The state of an intr and iso URB is 0.
* For ctrl URBs the states are US_CTRL_SETUP, US_CTRL_DATA, US_CTRL_ACK
* Bulk URBs states are US_BULK and US_BULK0 (with 0-len packet)
*
**************************************************************************/
/***************************************************************************
* Function Name : qu_urb_timeout
*
* This function is called when the URB timeout. The function unlinks the
* URB.
*
* Input: lurb: URB
*
* Return: none
**************************************************************************/
#ifdef HC_URB_TIMEOUT
static void qu_urb_timeout (unsigned long lurb)
{
struct urb *urb = (struct urb *) lurb;
DBGFUNC ("enter qu_urb_timeout\n");
urb->transfer_flags |= USB_TIMEOUT_KILLED;
hci_unlink_urb (urb);
}
#endif
/***************************************************************************
* Function Name : qu_pipeindex
*
* This function gets the index of the pipe.
*
* Input: pipe: the urb pipe
*
* Return: index
**************************************************************************/
static inline int qu_pipeindex (__u32 pipe)
{
DBGFUNC ("enter qu_pipeindex\n");
return (usb_pipeendpoint (pipe) << 1) | (usb_pipecontrol (pipe) ? 0 : usb_pipeout (pipe));
}
/***************************************************************************
* Function Name : qu_seturbstate
*
* This function set the state of the URB.
*
* control pipe: 3 states -- Setup, data, status
* interrupt and bulk pipe: 1 state -- data
*
* Input: urb = USB request block data structure
* state = the urb state
*
* Return: none
**************************************************************************/
static inline void qu_seturbstate (struct urb * urb, int state)
{
DBGFUNC ("enter qu_seturbstate\n");
urb->pipe &= ~0x1f;
urb->pipe |= state & 0x1f;
}
/***************************************************************************
* Function Name : qu_urbstate
*
* This function get the current state of the URB.
*
* Input: urb = USB request block data structure
*
* Return: none
**************************************************************************/
static inline int qu_urbstate (struct urb * urb)
{
DBGFUNC ("enter qu_urbstate\n");
return urb->pipe & 0x1f;
}
/***************************************************************************
* Function Name : qu_queue_active_urb
*
* This function adds the urb to the appropriate active urb list and set
* the urb state.
*
* There are four active lists: isochoronous list, interrupt list,
* control list, and bulk list.
*
* Input: hci = data structure for the host controller
* urb = USB request block data structure
* ed = endpoint descriptor
*
* Return: none
**************************************************************************/
static inline void qu_queue_active_urb (hci_t * hci, struct urb * urb, epd_t * ed)
{
int urb_state = 0;
DBGFUNC ("enter qu_queue_active_urb\n");
switch (usb_pipetype (urb->pipe)) {
case PIPE_CONTROL:
list_add (&urb->urb_list, &hci->ctrl_list);
urb_state = US_CTRL_SETUP;
break;
case PIPE_BULK:
list_add (&urb->urb_list, &hci->bulk_list);
if ((urb->transfer_flags & USB_ZERO_PACKET)
&& urb->transfer_buffer_length > 0
&&
((urb->transfer_buffer_length %
usb_maxpacket (urb->dev, urb->pipe,
usb_pipeout (urb->pipe))) == 0)) {
urb_state = US_BULK0;
}
break;
case PIPE_INTERRUPT:
urb->start_frame = hci->frame_number;
list_add (&urb->urb_list, &hci->intr_list);
break;
case PIPE_ISOCHRONOUS:
list_add (&urb->urb_list, &hci->iso_list);
break;
}
#ifdef HC_URB_TIMEOUT
if (urb->timeout) {
ed->timeout.data = (unsigned long) urb;
ed->timeout.expires = urb->timeout + jiffies;
ed->timeout.function = qu_urb_timeout;
add_timer (&ed->timeout);
}
#endif
qu_seturbstate (urb, urb_state);
}
/***************************************************************************
* Function Name : qu_queue_urb
*
* This function adds the urb to the endpoint descriptor list
*
* Input: hci = data structure for the host controller
* urb = USB request block data structure
*
* Return: none
**************************************************************************/
static int qu_queue_urb (hci_t * hci, struct urb * urb)
{
struct hci_device *hci_dev = usb_to_hci (urb->dev);
epd_t *ed = &hci_dev->ed[qu_pipeindex (urb->pipe)];
DBGFUNC ("Enter qu_queue_urb\n");
/* for ISOC transfers calculate start frame index */
if (usb_pipeisoc (urb->pipe) && urb->transfer_flags & USB_ISO_ASAP) {
urb->start_frame = ((ed->pipe_head) ? (ed->last_iso + 1) : hci_get_current_frame_number (urb-> dev) + 1) & 0xffff;
}
if (ed->pipe_head) {
__list_add (&urb->urb_list, ed->urb_queue.prev,
&(ed->urb_queue));
} else {
ed->pipe_head = urb;
qu_queue_active_urb (hci, urb, ed);
if (++hci->active_urbs == 1)
hc_start_int (hci);
}
return 0;
}
/***************************************************************************
* Function Name : qu_next_urb
*
* This function removes the URB from the queue and add the next URB to
* active list.
*
* Input: hci = data structure for the host controller
* urb = USB request block data structure
* resub_ok = resubmit flag
*
* Return: pointer to the next urb
**************************************************************************/
static struct urb *qu_next_urb (hci_t * hci, struct urb * urb, int resub_ok)
{
struct hci_device *hci_dev = usb_to_hci (urb->dev);
epd_t *ed = &hci_dev->ed[qu_pipeindex (urb->pipe)];
DBGFUNC ("enter qu_next_urb\n");
list_del (&urb->urb_list);
INIT_LIST_HEAD (&urb->urb_list);
if (ed->pipe_head == urb) {
#ifdef HC_URB_TIMEOUT
if (urb->timeout)
del_timer (&ed->timeout);
#endif
if (!--hci->active_urbs)
hc_stop_int (hci);
if (!list_empty (&ed->urb_queue)) {
urb = list_entry (ed->urb_queue.next, struct urb, urb_list);
list_del (&urb->urb_list);
INIT_LIST_HEAD (&urb->urb_list);
ed->pipe_head = urb;
qu_queue_active_urb (hci, urb, ed);
} else {
ed->pipe_head = NULL;
urb = NULL;
}
}
return urb;
}
/***************************************************************************
* Function Name : qu_return_urb
*
* This function is part of the return path.
*
* Input: hci = data structure for the host controller
* urb = USB request block data structure
* resub_ok = resubmit flag
*
* Return: pointer to the next urb
**************************************************************************/
static struct urb *qu_return_urb (hci_t * hci, struct urb * urb, int resub_ok)
{
struct urb *next_urb;
DBGFUNC ("enter qu_return_rub\n");
next_urb = qu_next_urb (hci, urb, resub_ok);
hcs_return_urb (hci, urb, resub_ok);
return next_urb;
}
/***************************************************************************
* Function Name : sh_scan_iso_urb_list
*
* This function goes throught the isochronous urb list and schedule the
* the transfer.
*
* Note: This function has not tested yet
*
* Input: hci = data structure for the host controller
* list_lh = pointer to the isochronous list
* frame_number = the frame number
*
* Return: 0 = unsuccessful; 1 = successful
**************************************************************************/
static int sh_scan_iso_urb_list (hci_t * hci, struct list_head *list_lh,
int frame_number)
{
struct list_head *lh = list_lh->next;
struct urb *urb;
DBGFUNC ("enter sh_scan_iso_urb_list\n");
hci->td_array->len = 0;
while (lh != list_lh) {
urb = list_entry (lh, struct urb, urb_list);
lh = lh->next;
if (((frame_number - urb->start_frame) & 0x7ff) <
urb->number_of_packets) {
if (!sh_add_packet (hci, urb)) {
return 0;
} else {
if (((frame_number -
urb->start_frame) & 0x7ff) > 0x400) {
if (qu_urbstate (urb) > 0)
urb = qu_return_urb (hci, urb, 1);
else
urb = qu_next_urb (hci, urb, 1);
if (lh == list_lh && urb)
lh = &urb->urb_list;
}
}
}
}
return 1;
}
/***************************************************************************
* Function Name : sh_scan_urb_list
*
* This function goes through the urb list and schedule the
* the transaction.
*
* Input: hci = data structure for the host controller
* list_lh = pointer to the isochronous list
*
* Return: 0 = unsuccessful; 1 = successful
**************************************************************************/
static int sh_scan_urb_list (hci_t * hci, struct list_head *list_lh)
{
struct list_head *lh = NULL;
struct urb *urb;
if (list_lh == NULL) {
DBGERR ("sh_scan_urb_list: error, list_lh == NULL\n");
}
DBGFUNC ("enter sh_scan_urb_list: frame# \n");
list_for_each (lh, list_lh) {
urb = list_entry (lh, struct urb, urb_list);
if (urb == NULL)
return 1;
if (!usb_pipeint (urb->pipe)
|| (((hci->frame_number - urb->start_frame)
& 0x7ff) >= urb->interval)) {
DBGVERBOSE ("sh_scan_urb_list !INT: %d fr_no: %d int: %d pint: %d\n",
urb->start_frame, hci->frame_number, urb->interval,
usb_pipeint (urb->pipe));
if (!sh_add_packet (hci, urb)) {
return 0;
} else {
DBGVERBOSE ("INT: start: %d fr_no: %d int: %d pint: %d\n",
urb->start_frame, hci->frame_number,
urb->interval, usb_pipeint (urb->pipe));
urb->start_frame = hci->frame_number;
return 0;
}
}
}
return 1;
}
/***************************************************************************
* Function Name : sh_shedule_trans
*
* This function schedule the USB transaction.
* This function will process the endpoint in the following order:
* interrupt, control, and bulk.
*
* Input: hci = data structure for the host controller
* isSOF = flag indicate if Start Of Frame has occurred
*
* Return: 0
**************************************************************************/
static int sh_schedule_trans (hci_t * hci, int isSOF)
{
int units_left = 1;
struct list_head *lh;
if (hci == NULL) {
DBGERR ("sh_schedule_trans: hci == NULL\n");
return 0;
}
if (hci->td_array == NULL) {
DBGERR ("sh_schedule_trans: hci->td_array == NULL\n");
return 0;
}
if (hci->td_array->len != 0) {
DBGERR ("ERROR: schedule, hci->td_array->len = 0x%x, s/b: 0\n",
hci->td_array->len);
}
/* schedule the next available interrupt transfer or the next
* stage of the interrupt transfer */
if (hci->td_array->len == 0 && !list_empty (&hci->intr_list)) {
units_left = sh_scan_urb_list (hci, &hci->intr_list);
}
/* schedule the next available control transfer or the next
* stage of the control transfer */
if (hci->td_array->len == 0 && !list_empty (&hci->ctrl_list) && units_left > 0) {
units_left = sh_scan_urb_list (hci, &hci->ctrl_list);
}
/* schedule the next available bulk transfer or the next
* stage of the bulk transfer */
if (hci->td_array->len == 0 && !list_empty (&hci->bulk_list) && units_left > 0) {
sh_scan_urb_list (hci, &hci->bulk_list);
/* be fair to each BULK URB (move list head around)
* only when the new SOF happens */
lh = hci->bulk_list.next;
list_del (&hci->bulk_list);
list_add (&hci->bulk_list, lh);
}
return 0;
}
/***************************************************************************
* Function Name : sh_add_packet
*
* This function forms the packet and transmit the packet. This function
* will handle all endpoint type: isochoronus, interrupt, control, and
* bulk.
*
* Input: hci = data structure for the host controller
* urb = USB request block data structure
*
* Return: 0 = unsucessful; 1 = successful
**************************************************************************/
static int sh_add_packet (hci_t * hci, struct urb * urb)
{
__u8 *data = NULL;
int len = 0;
int toggle = 0;
int maxps = usb_maxpacket (urb->dev, urb->pipe, usb_pipeout (urb->pipe));
int endpoint = usb_pipeendpoint (urb->pipe);
int address = usb_pipedevice (urb->pipe);
int slow = (((urb->pipe) >> 26) & 1);
int out = usb_pipeout (urb->pipe);
int pid = 0;
int ret;
int i = 0;
int iso = 0;
DBGFUNC ("enter sh_add_packet\n");
if (maxps == 0)
maxps = 8;
/* calculate len, toggle bit and add the transaction */
switch (usb_pipetype (urb->pipe)) {
case PIPE_ISOCHRONOUS:
pid = out ? PID_OUT : PID_IN;
iso = 1;
i = hci->frame_number - urb->start_frame;
data = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
len = urb->iso_frame_desc[i].length;
break;
case PIPE_BULK: /* BULK and BULK0 */
case PIPE_INTERRUPT:
pid = out ? PID_OUT : PID_IN;
len = urb->transfer_buffer_length - urb->actual_length;
data = urb->transfer_buffer + urb->actual_length;
toggle = usb_gettoggle (urb->dev, endpoint, out);
break;
case PIPE_CONTROL:
switch (qu_urbstate (urb)) {
case US_CTRL_SETUP:
len = 8;
pid = PID_SETUP;
data = urb->setup_packet;
toggle = 0;
break;
case US_CTRL_DATA:
if (!hci->last_packet_nak) {
/* The last packet received is not a nak:
* reset the nak count
*/
hci->nakCnt = 0;
}
if (urb->transfer_buffer_length != 0) {
pid = out ? PID_OUT : PID_IN;
len = urb->transfer_buffer_length - urb->actual_length;
data = urb->transfer_buffer + urb->actual_length;
toggle = (urb->actual_length & maxps) ? 0 : 1;
usb_settoggle (urb->dev,
usb_pipeendpoint (urb->pipe),
usb_pipeout (urb->pipe), toggle);
break;
} else {
/* correct state and fall through */
qu_seturbstate (urb, US_CTRL_ACK);
}
case US_CTRL_ACK:
len = 0;
/* reply in opposite direction */
pid = !out ? PID_OUT : PID_IN;
toggle = 1;
usb_settoggle (urb->dev, usb_pipeendpoint (urb->pipe),
usb_pipeout (urb->pipe), toggle);
break;
}
}
ret =
hc_add_trans (hci, len, data, toggle, maxps, slow, endpoint,
address, pid, iso, qu_urbstate (urb));
DBGVERBOSE ("transfer_pa: addr:%d ep:%d pid:%x tog:%x iso:%x sl:%x "
"max:%d\n len:%d ret:%d data:%p left:%d\n",
address, endpoint, pid, toggle, iso, slow,
maxps, len, ret, data, hci->hp.units_left);
if (ret >= 0) {
hci->td_array->td[hci->td_array->len].urb = urb;
hci->td_array->td[hci->td_array->len].len = ret;
hci->td_array->td[hci->td_array->len].iso_index = i;
hci->td_array->len++;
hci->active_trans = 1;
return 1;
}
return 0;
}
/***************************************************************************
* Function Name : cc_to_error
*
* This function maps the SL811HS hardware error code to the linux USB error
* code.
*
* Input: cc = hardware error code
*
* Return: USB error code
**************************************************************************/
static int cc_to_error (int cc)
{
int errCode = 0;
if (cc & SL11H_STATMASK_ERROR) {
errCode |= -EILSEQ;
} else if (cc & SL11H_STATMASK_OVF) {
errCode |= -EOVERFLOW;
} else if (cc & SL11H_STATMASK_STALL) {
errCode |= -EPIPE;
}
return errCode;
}
/***************************************************************************
* Function Name : sh_done_list
*
* This function process the packet when it has done finish transfer.
*
* 1) It handles hardware error
* 2) It updates the URB state
* 3) If the USB transaction is complete, it start the return stack path.
*
* Input: hci = data structure for the host controller
* isExcessNak = flag tells if there excess NAK condition occurred
*
* Return: urb_state or -1 if the transaction has complete
**************************************************************************/
static int sh_done_list (hci_t * hci, int *isExcessNak)
{
int actbytes = 0;
int active = 0;
void *data = NULL;
int cc;
int maxps;
int toggle;
struct urb *urb;
int urb_state = 0;
int ret = 1; /* -1 parse abbort, 1 parse ok, 0 last element */
int trans = 0;
int len;
int iso_index = 0;
int out;
int pid = 0;
int debugLen = 0;
*isExcessNak = 0;
DBGFUNC ("enter sh_done_list: td_array->len = 0x%x\n",
hci->td_array->len);
debugLen = hci->td_array->len;
if (debugLen > 1)
DBGERR ("sh_done_list: td_array->len = 0x%x > 1\n",
hci->td_array->len);
for (trans = 0; ret && trans < hci->td_array->len && trans < MAX_TRANS;
trans++) {
urb = hci->td_array->td[trans].urb;
len = hci->td_array->td[trans].len;
out = usb_pipeout (urb->pipe);
if (usb_pipeisoc (urb->pipe)) {
iso_index = hci->td_array->td[trans].iso_index;
data = urb->transfer_buffer + urb->iso_frame_desc[iso_index].offset;
toggle = 0;
} else {
data = urb->transfer_buffer + urb->actual_length;
toggle = usb_gettoggle (urb->dev,
usb_pipeendpoint (urb->pipe),
usb_pipeout (urb->pipe));
}
urb_state = qu_urbstate (urb);
pid = out ? PID_OUT : PID_IN;
ret = hc_parse_trans (hci, &actbytes, data, &cc, &toggle, len,
pid, urb_state);
maxps = usb_maxpacket (urb->dev, urb->pipe, usb_pipeout (urb->pipe));
if (maxps == 0)
maxps = 8;
active = (urb_state != US_CTRL_SETUP) && (actbytes && !(actbytes & (maxps - 1)));
/* If the transfer is not bulk in, then it is necessary to get all
* data specify by the urb->transfer_len.
*/
if (!(usb_pipebulk (urb->pipe) && usb_pipein (urb->pipe)))
active = active && (urb->transfer_buffer_length != urb->actual_length + actbytes);
if (urb->transfer_buffer_length == urb->actual_length + actbytes)
active = 0;
if ((cc &
(SL11H_STATMASK_ERROR | SL11H_STATMASK_TMOUT |
SL11H_STATMASK_OVF | SL11H_STATMASK_STALL))
&& !(cc & SL11H_STATMASK_NAK)) {
if (++urb->error_count > 3) {
DBGERR ("done_list: excessive error: errcount = 0x%x, cc = 0x%x\n",
urb->error_count, cc);
urb_state = 0;
active = 0;
} else {
DBGERR ("done_list: packet err, cc = 0x%x, "
" urb->length = 0x%x, actual_len = 0x%x,"
" urb_state =0x%x\n",
cc, urb->transfer_buffer_length,
urb->actual_length, urb_state);
// if (cc & SL11H_STATMASK_STALL) {
/* The USB function is STALLED on a control pipe (0),
* then it needs to send the SETUP command again to
* clear the STALL condition
*/
// if (usb_pipeendpoint (urb->pipe) == 0) {
// urb_state = 2;
// active = 0;
// }
// } else
active = 1;
}
} else {
if (cc & SL11H_STATMASK_NAK) {
if (hci->nakCnt < 0x10000) {
hci->nakCnt++;
hci->last_packet_nak = 1;
active = 1;
*isExcessNak = 0;
} else {
DBGERR ("done_list: nak count exceed limit\n");
active = 0;
*isExcessNak = 1;
hci->nakCnt = 0;
}
} else {
hci->nakCnt = 0;
hci->last_packet_nak = 0;
}
if (urb_state != US_CTRL_SETUP) {
/* no error */
urb->actual_length += actbytes;
usb_settoggle (urb->dev,
usb_pipeendpoint (urb->pipe),
usb_pipeout (urb->pipe), toggle);
}
if (usb_pipeisoc (urb->pipe)) {
urb->iso_frame_desc[iso_index].actual_length = actbytes;
urb->iso_frame_desc[iso_index].status = cc_to_error (cc);
active = (iso_index < urb->number_of_packets);
}
}
if (!active) {
if (!urb_state) {
urb->status = cc_to_error (cc);
if (urb->status) {
DBGERR ("error on received packet: urb->status = 0x%x\n",
urb->status);
}
hci->td_array->len = 0;
qu_return_urb (hci, urb, 1);
return -1;
} else {
/* We do not want to decrement the urb_state if exceeded nak,
* because we need to finish the data stage of the control
* packet
*/
if (!(*isExcessNak))
urb_state--;
qu_seturbstate (urb, urb_state);
}
}
}
if (urb_state < 0)
DBGERR ("ERROR: done_list, urb_state = %d, suppose > 0\n",
urb_state);
if (debugLen != hci->td_array->len) {
DBGERR ("ERROR: done_list, debugLen!= td_array->len,"
"debugLen = 0x%x, hci->td_array->len = 0x%x\n",
debugLen, hci->td_array->len);
}
hci->td_array->len = 0;
return urb_state;
}
/*-------------------------------------------------------------------------*/
/* list of all controllers using this driver
* */
static LIST_HEAD (hci_hcd_list);
/* URB states (urb_state) */
/* isoc, interrupt single state */
/* bulk transfer main state and 0-length packet */
#define US_BULK 0
#define US_BULK0 1
/* three setup states */
#define US_CTRL_SETUP 2
#define US_CTRL_DATA 1
#define US_CTRL_ACK 0
/*-------------------------------------------------------------------------*/
/* HC private part of a device descriptor
* */
#define NUM_EDS 32
typedef struct epd {
struct urb *pipe_head;
struct list_head urb_queue;
// int urb_state;
struct timer_list timeout;
int last_iso; /* timestamp of last queued ISOC transfer */
} epd_t;
struct hci_device {
epd_t ed[NUM_EDS];
};
/*-------------------------------------------------------------------------*/
/* Virtual Root HUB
*/
#define usb_to_hci(usb) ((struct hci_device *)(usb)->hcpriv)
struct virt_root_hub {
int devnum; /* Address of Root Hub endpoint */
void *urb; /* interrupt URB of root hub */
int send; /* active flag */
int interval; /* intervall of roothub interrupt transfers */
struct timer_list rh_int_timer; /* intervall timer for rh interrupt EP */
};
#if 1
/* USB HUB CONSTANTS (not OHCI-specific; see hub.h and USB spec) */
/* destination of request */
#define RH_INTERFACE 0x01
#define RH_ENDPOINT 0x02
#define RH_OTHER 0x03
#define RH_CLASS 0x20
#define RH_VENDOR 0x40
/* Requests: bRequest << 8 | bmRequestType */
#define RH_GET_STATUS 0x0080
#define RH_CLEAR_FEATURE 0x0100
#define RH_SET_FEATURE 0x0300
#define RH_SET_ADDRESS 0x0500
#define RH_GET_DESCRIPTOR 0x0680
#define RH_SET_DESCRIPTOR 0x0700
#define RH_GET_CONFIGURATION 0x0880
#define RH_SET_CONFIGURATION 0x0900
#define RH_GET_STATE 0x0280
#define RH_GET_INTERFACE 0x0A80
#define RH_SET_INTERFACE 0x0B00
#define RH_SYNC_FRAME 0x0C80
/* Our Vendor Specific Request */
#define RH_SET_EP 0x2000
/* Hub port features */
#define RH_PORT_CONNECTION 0x00
#define RH_PORT_ENABLE 0x01
#define RH_PORT_SUSPEND 0x02
#define RH_PORT_OVER_CURRENT 0x03
#define RH_PORT_RESET 0x04
#define RH_PORT_POWER 0x08
#define RH_PORT_LOW_SPEED 0x09
#define RH_C_PORT_CONNECTION 0x10
#define RH_C_PORT_ENABLE 0x11
#define RH_C_PORT_SUSPEND 0x12
#define RH_C_PORT_OVER_CURRENT 0x13
#define RH_C_PORT_RESET 0x14
/* Hub features */
#define RH_C_HUB_LOCAL_POWER 0x00
#define RH_C_HUB_OVER_CURRENT 0x01
#define RH_DEVICE_REMOTE_WAKEUP 0x00
#define RH_ENDPOINT_STALL 0x01
#endif
/*-------------------------------------------------------------------------*/
/* struct for each HC
*/
#define MAX_TRANS 32
typedef struct td {
struct urb *urb;
__u16 len;
__u16 iso_index;
} td_t;
typedef struct td_array {
int len;
td_t td[MAX_TRANS];
} td_array_t;
typedef struct hci {
struct virt_root_hub rh; /* roothub */
wait_queue_head_t waitq; /* deletion of URBs and devices needs a waitqueue */
int active; /* HC is operating */
struct list_head ctrl_list; /* set of ctrl endpoints */
struct list_head bulk_list; /* set of bulk endpoints */
struct list_head iso_list; /* set of isoc endpoints */
struct list_head intr_list; /* ordered (tree) set of int endpoints */
struct list_head del_list; /* set of entpoints to be deleted */
td_array_t *td_array;
td_array_t a_td_array;
td_array_t i_td_array[2];
struct list_head hci_hcd_list; /* list of all hci_hcd */
struct usb_bus *bus; /* our bus */
// int trans; /* number of transactions pending */
int active_urbs;
int active_trans;
int frame_number; /* frame number */
hcipriv_t hp; /* individual part of hc type */
int nakCnt;
int last_packet_nak;
} hci_t;
/*-------------------------------------------------------------------------*/
/* condition (error) CC codes and mapping OHCI like
*/
#define TD_CC_NOERROR 0x00
#define TD_CC_CRC 0x01
#define TD_CC_BITSTUFFING 0x02
#define TD_CC_DATATOGGLEM 0x03
#define TD_CC_STALL 0x04
#define TD_DEVNOTRESP 0x05
#define TD_PIDCHECKFAIL 0x06
#define TD_UNEXPECTEDPID 0x07
#define TD_DATAOVERRUN 0x08
#define TD_DATAUNDERRUN 0x09
#define TD_BUFFEROVERRUN 0x0C
#define TD_BUFFERUNDERRUN 0x0D
#define TD_NOTACCESSED 0x0F
/* urb interface functions */
static int hci_get_current_frame_number (struct usb_device *usb_dev);
static int hci_unlink_urb (struct urb * urb);
static int qu_queue_urb (hci_t * hci, struct urb * urb);
/* root hub */
static int rh_init_int_timer (struct urb * urb);
static int rh_submit_urb (struct urb * urb);
static int rh_unlink_urb (struct urb * urb);
/* schedule functions */
static int sh_add_packet (hci_t * hci, struct urb * urb);
/* hc specific functions */
static inline void hc_flush_data_cache (hci_t * hci, void *data, int len);
static inline int hc_parse_trans (hci_t * hci, int *actbytes, __u8 * data,
int *cc, int *toggle, int length, int pid,
int urb_state);
static inline int hc_add_trans (hci_t * hci, int len, void *data, int toggle,
int maxps, int slow, int endpoint, int address,
int pid, int format, int urb_state);
static void hc_start_int (hci_t * hci);
static void hc_stop_int (hci_t * hci);
static void SL811Write (hci_t * hci, char offset, char data);
/* debug| print the main components of an URB
* small: 0) header + data packets 1) just header */
static void urb_print (struct urb * urb, char *str, int small)
{
unsigned int pipe = urb->pipe;
int i, len;
if (!urb->dev || !urb->dev->bus) {
dbg ("%s URB: no dev", str);
return;
}
printk ("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,flags:%4x,len:%d/%d,stat:%d(%x)\n",
str, hci_get_current_frame_number (urb->dev),
usb_pipedevice (pipe), usb_pipeendpoint (pipe),
usb_pipeout (pipe) ? 'O' : 'I',
usb_pipetype (pipe) < 2 ? (usb_pipeint (pipe) ? "INTR" : "ISOC")
: (usb_pipecontrol (pipe) ? "CTRL" : "BULK"), urb->transfer_flags,
urb->actual_length, urb->transfer_buffer_length, urb->status,
urb->status);
if (!small) {
if (usb_pipecontrol (pipe)) {
printk (__FILE__ ": cmd(8):");
for (i = 0; i < 8; i++)
printk (" %02x", ((__u8 *) urb->setup_packet)[i]);
printk ("\n");
}
if (urb->transfer_buffer_length > 0 && urb->transfer_buffer) {
printk (__FILE__ ": data(%d/%d):", urb->actual_length,
urb->transfer_buffer_length);
len = usb_pipeout (pipe) ? urb-> transfer_buffer_length : urb->actual_length;
for (i = 0; i < 2096 && i < len; i++)
printk (" %02x", ((__u8 *) urb->transfer_buffer)[i]);
printk ("%s stat:%d\n", i < len ? "..." : "",
urb->status);
}
}
}
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*
* SL811HS USB HCD for Linux Version 0.1 (10/28/2001)
*
* requires (includes) hc_simple.[hc] simple generic HCD frontend
*
* COPYRIGHT(C) 2001 by CYPRESS SEMICONDUCTOR INC.
*
*-------------------------------------------------------------------------*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*-------------------------------------------------------------------------*/
#include <linux/config.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/malloc.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/smp_lock.h>
#include <linux/list.h>
#include <linux/ioport.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <linux/usb.h>
#include "../core/hcd.h"
#undef HC_URB_TIMEOUT
#undef HC_SWITCH_INT
#undef HC_ENABLE_ISOC
#define SL811_DEBUG_ERR
#ifdef SL811_DEBUG_ERR
#define DBGERR(fmt, args...) printk(fmt,## args)
#else
#define DBGERR(fmt, args...)
#endif
#ifdef SL811_DEBUG
#define DBG(fmt, args...) printk(fmt,## args)
#else
#define DBG(fmt, args...)
#endif
#ifdef SL811_DEBUG_FUNC
#define DBGFUNC(fmt, args...) printk(fmt,## args)
#else
#define DBGFUNC(fmt, args...)
#endif
#ifdef SL811_DEBUG_DATA
#define DBGDATAR(fmt, args...) printk(fmt,## args)
#define DBGDATAW(fmt, args...) printk(fmt,## args)
#else
#define DBGDATAR(fmt, args...)
#define DBGDATAW(fmt, args...)
#endif
#ifdef SL811_DEBUG_VERBOSE
#define DBGVERBOSE(fmt, args...) printk(fmt,## args)
#else
#define DBGVERBOSE(fmt, args...)
#endif
#define TRUE 1
#define FALSE 0
#define HC_SWITCH_INT
#include "hc_sl811.h"
#include "hc_simple.h"
static int urb_debug = 0;
#include "hc_simple.c"
#include "hc_sl811_rh.c"
/* The base_addr, data_reg_addr, and irq number are board specific.
* The current values are design to run on the Accelent SA1110 IDP
* NOTE: values need to modify for different development boards
*/
static int base_addr = 0xd3800000;
static int data_reg_addr = 0xd3810000;
static int irq = 34;
/* forware declaration */
int SL11StartXaction (hci_t * hci, __u8 addr, __u8 epaddr, int pid, int len,
int toggle, int slow, int urb_state);
static int sofWaitCnt = 0;
MODULE_PARM (urb_debug, "i");
MODULE_PARM_DESC (urb_debug, "debug urb messages, default is 0 (no)");
MODULE_PARM (base_addr, "i");
MODULE_PARM_DESC (base_addr, "sl811 base address 0xd3800000");
MODULE_PARM (data_reg_addr, "i");
MODULE_PARM_DESC (data_reg_addr, "sl811 data register address 0xd3810000");
MODULE_PARM (irq, "i");
MODULE_PARM_DESC (irq, "IRQ 34 (default)");
static int hc_reset (hci_t * hci);
/***************************************************************************
* Function Name : SL811Read
*
* Read a byte of data from the SL811H/SL11H
*
* Input: hci = data structure for the host controller
* offset = address of SL811/SL11H register or memory
*
* Return: data
**************************************************************************/
char SL811Read (hci_t * hci, char offset)
{
hcipriv_t *hp = &hci->hp;
char data;
writeb (offset, hp->hcport);
wmb ();
data = readb (hp->hcport2);
rmb ();
return (data);
}
/***************************************************************************
* Function Name : SL811Write
*
* Write a byte of data to the SL811H/SL11H
*
* Input: hci = data structure for the host controller
* offset = address of SL811/SL11H register or memory
* data = the data going to write to SL811H
*
* Return: none
**************************************************************************/
void SL811Write (hci_t * hci, char offset, char data)
{
hcipriv_t *hp = &hci->hp;
writeb (offset, hp->hcport);
writeb (data, hp->hcport2);
wmb ();
}
/***************************************************************************
* Function Name : SL811BufRead
*
* Read consecutive bytes of data from the SL811H/SL11H buffer
*
* Input: hci = data structure for the host controller
* offset = SL811/SL11H register offset
* buf = the buffer where the data will store
* size = number of bytes to read
*
* Return: none
**************************************************************************/
void SL811BufRead (hci_t * hci, short offset, char *buf, short size)
{
hcipriv_t *hp = &hci->hp;
if (size <= 0)
return;
writeb ((char) offset, hp->hcport);
wmb ();
DBGDATAR ("SL811BufRead: offset = 0x%x, data = ", offset);
while (size--) {
*buf++ = (char) readb (hp->hcport2);
DBGDATAR ("0x%x ", *(buf - 1));
rmb ();
}
DBGDATAR ("\n");
}
/***************************************************************************
* Function Name : SL811BufWrite
*
* Write consecutive bytes of data to the SL811H/SL11H buffer
*
* Input: hci = data structure for the host controller
* offset = SL811/SL11H register offset
* buf = the data buffer
* size = number of bytes to write
*
* Return: none
**************************************************************************/
void SL811BufWrite (hci_t * hci, short offset, char *buf, short size)
{
hcipriv_t *hp = &hci->hp;
if (size <= 0)
return;
writeb ((char) offset, hp->hcport);
wmb ();
DBGDATAW ("SL811BufWrite: offset = 0x%x, data = ", offset);
while (size--) {
DBGDATAW ("0x%x ", *buf);
writeb (*buf, hp->hcport2);
wmb ();
buf++;
}
DBGDATAW ("\n");
}
/***************************************************************************
* Function Name : regTest
*
* This routine test the Read/Write functionality of SL811HS registers
*
* 1) Store original register value into a buffer
* 2) Write to registers with a RAMP pattern. (10, 11, 12, ..., 255)
* 3) Read from register
* 4) Compare the written value with the read value and make sure they are
* equivalent
* 5) Restore the original register value
*
* Input: hci = data structure for the host controller
*
*
* Return: TRUE = passed; FALSE = failed
**************************************************************************/
int regTest (hci_t * hci)
{
int i, data, result = TRUE;
char buf[256];
DBGFUNC ("Enter regTest\n");
for (i = 0x10; i < 256; i++) {
/* save the original buffer */
buf[i] = (char) SL811Read (hci, i);
/* Write the new data to the buffer */
SL811Write (hci, i, i);
}
/* compare the written data */
for (i = 0x10; i < 256; i++) {
data = SL811Read (hci, i);
if (data != i) {
DBGERR ("Pattern test failed!! value = 0x%x, s/b 0x%x\n",
data, i);
result = FALSE;
}
}
/* restore the data */
for (i = 0x10; i < 256; i++) {
SL811Write (hci, i, buf[i]);
}
return (result);
}
/***************************************************************************
* Function Name : regShow
*
* Display all SL811HS register values
*
* Input: hci = data structure for the host controller
*
* Return: none
**************************************************************************/
void regShow (hci_t * hci)
{
int i;
for (i = 0; i < 256; i++) {
printk ("offset %d: 0x%x\n", i, SL811Read (hci, i));
}
}
/************************************************************************
* Function Name : USBReset
*
* This function resets SL811HS controller and detects the speed of
* the connecting device
*
* Input: hci = data structure for the host controller
*
* Return: 0 = no device attached; 1 = USB device attached
*
***********************************************************************/
static int USBReset (hci_t * hci)
{
int status;
hcipriv_t *hp = &hci->hp;
DBGFUNC ("enter USBReset\n");
SL811Write (hci, SL11H_CTLREG2, 0xae);
// setup master and full speed
SL811Write (hci, SL11H_CTLREG1, 0x08); // reset USB
mdelay (20); // 20ms
SL811Write (hci, SL11H_CTLREG1, 0); // remove SE0
for (status = 0; status < 100; status++)
SL811Write (hci, SL11H_INTSTATREG, 0xff); // clear all interrupt bits
status = SL811Read (hci, SL11H_INTSTATREG);
if (status & 0x40) // Check if device is removed
{
DBG ("USBReset: Device removed\n");
SL811Write (hci, SL11H_INTENBLREG,
SL11H_INTMASK_XFERDONE | SL11H_INTMASK_SOFINTR |
SL11H_INTMASK_INSRMV);
hp->RHportStatus->portStatus &=
~(PORT_CONNECT_STAT | PORT_ENABLE_STAT);
return 0;
}
SL811Write (hci, SL11H_BUFLNTHREG_B, 0); //zero lenth
SL811Write (hci, SL11H_PIDEPREG_B, 0x50); //send SOF to EP0
SL811Write (hci, SL11H_DEVADDRREG_B, 0x01); //address0
SL811Write (hci, SL11H_SOFLOWREG, 0xe0);
if (!(status & 0x80)) {
/* slow speed device connect directly to root-hub */
DBG ("USBReset: low speed Device attached\n");
SL811Write (hci, SL11H_CTLREG1, 0x8);
mdelay (20);
SL811Write (hci, SL11H_SOFTMRREG, 0xee);
SL811Write (hci, SL11H_CTLREG1, 0x21);
/* start the SOF or EOP */
SL811Write (hci, SL11H_HOSTCTLREG_B, 0x01);
hp->RHportStatus->portStatus |=
(PORT_CONNECT_STAT | PORT_LOW_SPEED_DEV_ATTACH_STAT);
/* clear all interrupt bits */
for (status = 0; status < 20; status++)
SL811Write (hci, SL11H_INTSTATREG, 0xff);
} else {
/* full speed device connect directly to root hub */
DBG ("USBReset: full speed Device attached\n");
SL811Write (hci, SL11H_CTLREG1, 0x8);
mdelay (20);
SL811Write (hci, SL11H_SOFTMRREG, 0xae);
SL811Write (hci, SL11H_CTLREG1, 0x01);
/* start the SOF or EOP */
SL811Write (hci, SL11H_HOSTCTLREG_B, 0x01);
hp->RHportStatus->portStatus |= (PORT_CONNECT_STAT);
hp->RHportStatus->portStatus &= ~PORT_LOW_SPEED_DEV_ATTACH_STAT;
/* clear all interrupt bits */
SL811Write (hci, SL11H_INTSTATREG, 0xff);
}
/* enable all interrupts */
SL811Write (hci, SL11H_INTENBLREG,
SL11H_INTMASK_XFERDONE | SL11H_INTMASK_SOFINTR |
SL11H_INTMASK_INSRMV);
return 1;
}
/*-------------------------------------------------------------------------*/
/* tl functions */
static inline void hc_mark_last_trans (hci_t * hci)
{
hcipriv_t *hp = &hci->hp;
__u8 *ptd = hp->tl;
dbg ("enter hc_mark_last_trans\n");
if (ptd == NULL) {
printk ("hc_mark_last_trans: ptd = null\n");
return;
}
if (hp->xferPktLen > 0)
*(ptd + hp->tl_last) |= (1 << 3);
}
static inline void hc_flush_data_cache (hci_t * hci, void *data, int len)
{
}
/************************************************************************
* Function Name : hc_add_trans
*
* This function sets up the SL811HS register and transmit the USB packets.
*
* 1) Determine if enough time within the current frame to send the packet
* 2) Load the data into the SL811HS register
* 3) Set the appropriate command to the register and trigger the transmit
*
* Input: hci = data structure for the host controller
* len = data length
* data = transmitting data
* toggle = USB toggle bit, either 0 or 1
* maxps = maximum packet size for this endpoint
* slow = speed of the device
* endpoint = endpoint number
* address = USB address of the device
* pid = packet ID
* format =
* urb_state = the current stage of USB transaction
*
* Return: 0 = no time left to schedule the transfer
* 1 = success
*
***********************************************************************/
static inline int hc_add_trans (hci_t * hci, int len, void *data, int toggle,
int maxps, int slow, int endpoint, int address,
int pid, int format, int urb_state)
{
hcipriv_t *hp = &hci->hp;
__u16 speed;
int ii, jj, kk;
DBGFUNC ("enter hc_addr_trans: len =0x%x, toggle:0x%x, endpoing:0x%x,"
" addr:0x%x, pid:0x%x,format:0x%x\n", len, toggle, endpoint,
i address, pid, format);
if (len > maxps) {
len = maxps;
}
speed = hp->RHportStatus->portStatus;
if (speed & PORT_LOW_SPEED_DEV_ATTACH_STAT) {
// ii = (8*7*8 + 6*3) * len + 800;
ii = 8 * 8 * len + 1024;
} else {
if (slow) {
// ii = (8*7*8 + 6*3) * len + 800;
ii = 8 * 8 * len + 2048;
} else
// ii = (8*7 + 6*3)*len + 110;
ii = 8 * len + 256;
}
ii += 2 * 10 * len;
jj = SL811Read (hci, SL11H_SOFTMRREG);
kk = (jj & 0xFF) * 64 - ii;
if (kk < 0) {
DBGVERBOSE
("hc_add_trans: no bandwidth for schedule, ii = 0x%x,"
"jj = 0x%x, len =0x%x, active_trans = 0x%x\n", ii, jj, len,
hci->active_trans);
return (-1);
}
if (pid != PID_IN) {
/* Load data into hc */
SL811BufWrite (hci, SL11H_DATA_START, (__u8 *) data, len);
}
/* transmit */
SL11StartXaction (hci, (__u8) address, (__u8) endpoint, (__u8) pid, len,
toggle, slow, urb_state);
return len;
}
/************************************************************************
* Function Name : hc_parse_trans
*
* This function checks the status of the transmitted or received packet
* and copy the data from the SL811HS register into a buffer.
*
* 1) Check the status of the packet
* 2) If successful, and IN packet then copy the data from the SL811HS register
* into a buffer
*
* Input: hci = data structure for the host controller
* actbytes = pointer to actual number of bytes
* data = data buffer
* cc = packet status
* length = the urb transmit length
* pid = packet ID
* urb_state = the current stage of USB transaction
*
* Return: 0
***********************************************************************/
static inline int hc_parse_trans (hci_t * hci, int *actbytes, __u8 * data,
int *cc, int *toggle, int length, int pid,
int urb_state)
{
__u8 addr;
__u8 len;
DBGFUNC ("enter hc_parse_trans\n");
/* get packet status; convert ack rcvd to ack-not-rcvd */
*cc = (int) SL811Read (hci, SL11H_PKTSTATREG);
if (*cc &
(SL11H_STATMASK_ERROR | SL11H_STATMASK_TMOUT | SL11H_STATMASK_OVF |
SL11H_STATMASK_NAK | SL11H_STATMASK_STALL)) {
if (*cc & SL11H_STATMASK_OVF)
DBGERR ("parse trans: error recv ack, cc = 0x%x, TX_BASE_Len = "
"0x%x, TX_count=0x%x\n", *cc,
SL811Read (hci, SL11H_BUFLNTHREG),
SL811Read (hci, SL11H_XFERCNTREG));
} else {
DBGVERBOSE ("parse trans: recv ack, cc = 0x%x, len = 0x%x, \n",
*cc, length);
/* Successful data */
if ((pid == PID_IN) && (urb_state != US_CTRL_SETUP)) {
/* Find the base address */
addr = SL811Read (hci, SL11H_BUFADDRREG);
/* Find the Transmit Length */
len = SL811Read (hci, SL11H_BUFLNTHREG);
/* The actual data length = xmit length reg - xfer count reg */
*actbytes = len - SL811Read (hci, SL11H_XFERCNTREG);
if ((data != NULL) && (*actbytes > 0)) {
SL811BufRead (hci, addr, data, *actbytes);
} else if ((data == NULL) && (*actbytes <= 0)) {
DBGERR ("hc_parse_trans: data = NULL or actbyte = 0x%x\n",
*actbytes);
return 0;
}
} else if (pid == PID_OUT) {
*actbytes = length;
} else {
// printk ("ERR:parse_trans, pid != IN or OUT, pid = 0x%x\n", pid);
}
*toggle = !*toggle;
}
return 0;
}
/************************************************************************
* Function Name : hc_start_int
*
* This function enables SL811HS interrupts
*
* Input: hci = data structure for the host controller
*
* Return: none
***********************************************************************/
static void hc_start_int (hci_t * hci)
{
#ifdef HC_SWITCH_INT
int mask =
SL11H_INTMASK_XFERDONE | SL11H_INTMASK_SOFINTR |
SL11H_INTMASK_INSRMV | SL11H_INTMASK_USBRESET;
SL811Write (hci, IntEna, mask);
#endif
}
/************************************************************************
* Function Name : hc_stop_int
*
* This function disables SL811HS interrupts
*
* Input: hci = data structure for the host controller
*
* Return: none
***********************************************************************/
static void hc_stop_int (hci_t * hci)
{
#ifdef HC_SWITCH_INT
SL811Write (hci, SL11H_INTSTATREG, 0xff);
// SL811Write(hci, SL11H_INTENBLREG, SL11H_INTMASK_INSRMV);
#endif
}
/************************************************************************
* Function Name : handleInsRmvIntr
*
* This function handles the insertion or removal of device on SL811HS.
* It resets the controller and updates the port status
*
* Input: hci = data structure for the host controller
*
* Return: none
***********************************************************************/
void handleInsRmvIntr (hci_t * hci)
{
hcipriv_t *hp = &hci->hp;
USBReset (hci);
/* Changes in connection status */
hp->RHportStatus->portChange |= PORT_CONNECT_CHANGE;
/* Port Enable or Disable */
if (hp->RHportStatus->portStatus & PORT_CONNECT_STAT) {
/* device is connected to the port:
* 1) Enable port
* 2) Resume ??
*/
// hp->RHportStatus->portChange |= PORT_ENABLE_CHANGE;
/* Over Current is not supported by the SL811 HW ?? */
/* How about the Port Power ?? */
} else {
/* Device has disconnect:
* 1) Disable port
*/
hp->RHportStatus->portStatus &= ~(PORT_ENABLE_STAT);
hp->RHportStatus->portChange |= PORT_ENABLE_CHANGE;
}
}
/*****************************************************************
*
* Function Name: SL11StartXaction
*
* This functions load the registers with appropriate value and
* transmit the packet.
*
* Input: hci = data structure for the host controller
* addr = USB address of the device
* epaddr = endpoint number
* pid = packet ID
* len = data length
* toggle = USB toggle bit, either 0 or 1
* slow = speed of the device
* urb_state = the current stage of USB transaction
*
* Return: 0 = error; 1 = successful
*
*****************************************************************/
int SL11StartXaction (hci_t * hci, __u8 addr, __u8 epaddr, int pid, int len,
int toggle, int slow, int urb_state)
{
hcipriv_t *hp = &hci->hp;
__u8 cmd = 0;
__u8 setup_data[4];
__u16 speed;
speed = hp->RHportStatus->portStatus;
if (!(speed & PORT_LOW_SPEED_DEV_ATTACH_STAT) && slow) {
cmd |= SL11H_HCTLMASK_PREAMBLE;
}
switch (pid) {
case PID_SETUP:
cmd &= SL11H_HCTLMASK_PREAMBLE;
cmd |=
(SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENBLEP |
SL11H_HCTLMASK_WRITE);
break;
case PID_OUT:
cmd &= (SL11H_HCTLMASK_SEQ | SL11H_HCTLMASK_PREAMBLE);
cmd |=
(SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENBLEP |
SL11H_HCTLMASK_WRITE);
if (toggle) {
cmd |= SL11H_HCTLMASK_SEQ;
}
break;
case PID_IN:
cmd &= (SL11H_HCTLMASK_SEQ | SL11H_HCTLMASK_PREAMBLE);
cmd |= (SL11H_HCTLMASK_ARM | SL11H_HCTLMASK_ENBLEP);
break;
default:
DBGERR ("ERR: SL11StartXaction: unknow pid = 0x%x\n", pid);
return 0;
}
setup_data[0] = SL11H_DATA_START;
setup_data[1] = len;
setup_data[2] = (((pid & 0x0F) << 4) | (epaddr & 0xF));
setup_data[3] = addr & 0x7F;
SL811BufWrite (hci, SL11H_BUFADDRREG, (__u8 *) & setup_data[0], 4);
SL811Write (hci, SL11H_HOSTCTLREG, cmd);
#if 0
/* The SL811 has a hardware flaw when hub devices sends out
* SE0 between packets. It has been found in a TI chipset and
* cypress hub chipset. It causes the SL811 to hang
* The workaround is to re-issue the preample again.
*/
if ((cmd & SL11H_HCTLMASK_PREAMBLE)) {
SL811Write (hci, SL11H_PIDEPREG_B, 0xc0);
SL811Write (hci, SL11H_HOSTCTLREG_B, 0x1); // send the premable
}
#endif
return 1;
}
/*****************************************************************
*
* Function Name: hc_interrupt
*
* Interrupt service routine.
*
* 1) determine the causes of interrupt
* 2) clears all interrupts
* 3) calls appropriate function to service the interrupt
*
* Input: irq = interrupt line associated with the controller
* hci = data structure for the host controller
* r = holds the snapshot of the processor's context before
* the processor entered interrupt code. (not used here)
*
* Return value : None.
*
*****************************************************************/
static void hc_interrupt (int irq, void *__hci, struct pt_regs *r)
{
char ii;
hci_t *hci = __hci;
int isExcessNak = 0;
int urb_state = 0;
char tmpIrq = 0;
/* Get value from interrupt status register */
ii = SL811Read (hci, SL11H_INTSTATREG);
if (ii & SL11H_INTMASK_INSRMV) {
/* Device insertion or removal detected for the USB port */
SL811Write (hci, SL11H_INTENBLREG, 0);
SL811Write (hci, SL11H_CTLREG1, 0);
mdelay (100); // wait for device stable
handleInsRmvIntr (hci);
return;
}
/* Clear all interrupts */
SL811Write (hci, SL11H_INTSTATREG, 0xff);
if (ii & SL11H_INTMASK_XFERDONE) {
/* USB Done interrupt occurred */
urb_state = sh_done_list (hci, &isExcessNak);
#ifdef WARNING
if (hci->td_array->len > 0)
printk ("WARNING: IRQ, td_array->len = 0x%x, s/b:0\n",
hci->td_array->len);
#endif
if (hci->td_array->len == 0 && !isExcessNak
&& !(ii & SL11H_INTMASK_SOFINTR) && (urb_state == 0)) {
if (urb_state == 0) {
/* All urb_state has not been finished yet!
* continue with the current urb transaction
*/
if (hci->last_packet_nak == 0) {
if (!usb_pipecontrol
(hci->td_array->td[0].urb->pipe))
sh_add_packet (hci, hci->td_array-> td[0].urb);
}
} else {
/* The last transaction has completed:
* schedule the next transaction
*/
sh_schedule_trans (hci, 0);
}
}
SL811Write (hci, SL11H_INTSTATREG, 0xff);
return;
}
if (ii & SL11H_INTMASK_SOFINTR) {
hci->frame_number = (hci->frame_number + 1) % 2048;
if (hci->td_array->len == 0)
sh_schedule_trans (hci, 1);
else {
if (sofWaitCnt++ > 100) {
/* The last transaction has not completed.
* Need to retire the current td, and let
* it transmit again later on.
* (THIS NEEDS TO BE WORK ON MORE, IT SHOULD NEVER
* GET TO THIS POINT)
*/
DBGERR ("SOF interrupt: td_array->len = 0x%x, s/b: 0\n",
hci->td_array->len);
urb_print (hci->td_array->td[hci->td_array->len - 1].urb,
"INTERRUPT", 0);
sh_done_list (hci, &isExcessNak);
SL811Write (hci, SL11H_INTSTATREG, 0xff);
hci->td_array->len = 0;
sofWaitCnt = 0;
}
}
tmpIrq = SL811Read (hci, SL11H_INTSTATREG) & SL811Read (hci, SL11H_INTENBLREG);
if (tmpIrq) {
DBG ("IRQ occurred while service SOF: irq = 0x%x\n",
tmpIrq);
/* If we receive a DONE IRQ after schedule, need to
* handle DONE IRQ again
*/
if (tmpIrq & SL11H_INTMASK_XFERDONE) {
DBGERR ("IRQ occurred while service SOF: irq = 0x%x\n",
tmpIrq);
urb_state = sh_done_list (hci, &isExcessNak);
}
SL811Write (hci, SL11H_INTSTATREG, 0xff);
}
} else {
DBG ("SL811 ISR: unknown, int = 0x%x \n", ii);
}
SL811Write (hci, SL11H_INTSTATREG, 0xff);
return;
}
/*****************************************************************
*
* Function Name: hc_reset
*
* This function does register test and resets the SL811HS
* controller.
*
* Input: hci = data structure for the host controller
*
* Return value : 0
*
*****************************************************************/
static int hc_reset (hci_t * hci)
{
int attachFlag = 0;
DBGFUNC ("Enter hc_reset\n");
regTest (hci);
attachFlag = USBReset (hci);
if (attachFlag) {
setPortChange (hci, PORT_CONNECT_CHANGE);
}
return (0);
}
/*****************************************************************
*
* Function Name: hc_alloc_trans_buffer
*
* This function allocates all transfer buffer
*
* Input: hci = data structure for the host controller
*
* Return value : 0
*
*****************************************************************/
static int hc_alloc_trans_buffer (hci_t * hci)
{
hcipriv_t *hp = &hci->hp;
int maxlen;
hp->itl0_len = 0;
hp->itl1_len = 0;
hp->atl_len = 0;
hp->itl_buffer_len = 1024;
hp->atl_buffer_len = 4096 - 2 * hp->itl_buffer_len; /* 2048 */
maxlen = (hp->itl_buffer_len > hp->atl_buffer_len) ? hp->itl_buffer_len : hp->atl_buffer_len;
hp->tl = kmalloc (maxlen, GFP_KERNEL);
if (!hp->tl)
return -ENOMEM;
memset (hp->tl, 0, maxlen);
return 0;
}
/*****************************************************************
*
* Function Name: getPortStatusAndChange
*
* This function gets the ports status from SL811 and format it
* to a USB request format
*
* Input: hci = data structure for the host controller
*
* Return value : port status and change
*
*****************************************************************/
static __u32 getPortStatusAndChange (hci_t * hci)
{
hcipriv_t *hp = &hci->hp;
__u32 portstatus;
DBGFUNC ("enter getPorStatusAndChange\n");
portstatus = hp->RHportStatus->portChange << 16 | hp->RHportStatus->portStatus;
return (portstatus);
}
/*****************************************************************
*
* Function Name: setPortChange
*
* This function set the bit position of portChange.
*
* Input: hci = data structure for the host controller
* bitPos = the bit position
*
* Return value : none
*
*****************************************************************/
static void setPortChange (hci_t * hci, __u16 bitPos)
{
hcipriv_t *hp = &hci->hp;
switch (bitPos) {
case PORT_CONNECT_STAT:
hp->RHportStatus->portChange |= bitPos;
break;
case PORT_ENABLE_STAT:
hp->RHportStatus->portChange |= bitPos;
break;
case PORT_RESET_STAT:
hp->RHportStatus->portChange |= bitPos;
break;
case PORT_POWER_STAT:
hp->RHportStatus->portChange |= bitPos;
break;
case PORT_SUSPEND_STAT:
hp->RHportStatus->portChange |= bitPos;
break;
case PORT_OVER_CURRENT_STAT:
hp->RHportStatus->portChange |= bitPos;
break;
}
}
/*****************************************************************
*
* Function Name: clrPortChange
*
* This function clear the bit position of portChange.
*
* Input: hci = data structure for the host controller
* bitPos = the bit position
*
* Return value : none
*
*****************************************************************/
static void clrPortChange (hci_t * hci, __u16 bitPos)
{
hcipriv_t *hp = &hci->hp;
switch (bitPos) {
case PORT_CONNECT_CHANGE:
hp->RHportStatus->portChange &= ~bitPos;
break;
case PORT_ENABLE_CHANGE:
hp->RHportStatus->portChange &= ~bitPos;
break;
case PORT_RESET_CHANGE:
hp->RHportStatus->portChange &= ~bitPos;
break;
case PORT_SUSPEND_CHANGE:
hp->RHportStatus->portChange &= ~bitPos;
break;
case PORT_OVER_CURRENT_CHANGE:
hp->RHportStatus->portChange &= ~bitPos;
break;
}
}
/*****************************************************************
*
* Function Name: clrPortStatus
*
* This function clear the bit position of portStatus.
*
* Input: hci = data structure for the host controller
* bitPos = the bit position
*
* Return value : none
*
*****************************************************************/
static void clrPortStatus (hci_t * hci, __u16 bitPos)
{
hcipriv_t *hp = &hci->hp;
switch (bitPos) {
case PORT_ENABLE_STAT:
hp->RHportStatus->portStatus &= ~bitPos;
break;
case PORT_RESET_STAT:
hp->RHportStatus->portStatus &= ~bitPos;
break;
case PORT_POWER_STAT:
hp->RHportStatus->portStatus &= ~bitPos;
break;
case PORT_SUSPEND_STAT:
hp->RHportStatus->portStatus &= ~bitPos;
break;
}
}
/*****************************************************************
*
* Function Name: setPortStatus
*
* This function set the bit position of portStatus.
*
* Input: hci = data structure for the host controller
* bitPos = the bit position
*
* Return value : none
*
*****************************************************************/
static void setPortStatus (hci_t * hci, __u16 bitPos)
{
hcipriv_t *hp = &hci->hp;
switch (bitPos) {
case PORT_ENABLE_STAT:
hp->RHportStatus->portStatus |= bitPos;
break;
case PORT_RESET_STAT:
hp->RHportStatus->portStatus |= bitPos;
break;
case PORT_POWER_STAT:
hp->RHportStatus->portStatus |= bitPos;
break;
case PORT_SUSPEND_STAT:
hp->RHportStatus->portStatus |= bitPos;
break;
}
}
/*****************************************************************
*
* Function Name: hc_start
*
* This function starts the root hub functionality.
*
* Input: hci = data structure for the host controller
*
* Return value : 0
*
*****************************************************************/
static int hc_start (hci_t * hci)
{
DBGFUNC ("Enter hc_start\n");
rh_connect_rh (hci);
return 0;
}
/*****************************************************************
*
* Function Name: hc_alloc_hci
*
* This function allocates all data structure and store in the
* private data structure.
*
* Input: hci = data structure for the host controller
*
* Return value : 0
*
*****************************************************************/
static hci_t *__devinit hc_alloc_hci (void)
{
hci_t *hci;
hcipriv_t *hp;
portstat_t *ps;
struct usb_bus *bus;
DBGFUNC ("Enter hc_alloc_hci\n");
hci = (hci_t *) kmalloc (sizeof (hci_t), GFP_KERNEL);
if (!hci)
return NULL;
memset (hci, 0, sizeof (hci_t));
hp = &hci->hp;
hp->irq = -1;
hp->hcport = -1;
/* setup root hub port status */
ps = (portstat_t *) kmalloc (sizeof (portstat_t), GFP_KERNEL);
if (!ps)
return NULL;
ps->portStatus = PORT_STAT_DEFAULT;
ps->portChange = PORT_CHANGE_DEFAULT;
hp->RHportStatus = ps;
hci->nakCnt = 0;
hci->last_packet_nak = 0;
hci->a_td_array.len = 0;
hci->i_td_array[0].len = 0;
hci->i_td_array[1].len = 0;
hci->td_array = &hci->a_td_array;
hci->active_urbs = 0;
hci->active_trans = 0;
INIT_LIST_HEAD (&hci->hci_hcd_list);
list_add (&hci->hci_hcd_list, &hci_hcd_list);
init_waitqueue_head (&hci->waitq);
INIT_LIST_HEAD (&hci->ctrl_list);
INIT_LIST_HEAD (&hci->bulk_list);
INIT_LIST_HEAD (&hci->iso_list);
INIT_LIST_HEAD (&hci->intr_list);
INIT_LIST_HEAD (&hci->del_list);
bus = usb_alloc_bus (&hci_device_operations);
if (!bus) {
kfree (hci);
return NULL;
}
hci->bus = bus;
bus->hcpriv = (void *) hci;
return hci;
}
/*****************************************************************
*
* Function Name: hc_release_hci
*
* This function De-allocate all resources
*
* Input: hci = data structure for the host controller
*
* Return value : 0
*
*****************************************************************/
static void hc_release_hci (hci_t * hci)
{
hcipriv_t *hp = &hci->hp;
DBGFUNC ("Enter hc_release_hci\n");
/* disconnect all devices */
if (hci->bus->root_hub)
usb_disconnect (&hci->bus->root_hub);
hc_reset (hci);
if (hp->tl)
kfree (hp->tl);
if (hp->hcport > 0) {
release_region (hp->hcport, 2);
hp->hcport = 0;
}
if (hp->irq >= 0) {
free_irq (hp->irq, hci);
hp->irq = -1;
}
usb_deregister_bus (hci->bus);
usb_free_bus (hci->bus);
list_del (&hci->hci_hcd_list);
INIT_LIST_HEAD (&hci->hci_hcd_list);
kfree (hci);
}
/*****************************************************************
*
* Function Name: init_irq
*
* This function is board specific. It sets up the interrupt to
* be an edge trigger and trigger on the rising edge
*
* Input: none
*
* Return value : none
*
*****************************************************************/
void init_irq (void)
{
GPDR &= ~(1 << 13);
set_GPIO_IRQ_edge (1 << 13, GPIO_RISING_EDGE);
}
/*****************************************************************
*
* Function Name: hc_found_hci
*
* This function request IO memory regions, request IRQ, and
* allocate all other resources.
*
* Input: addr = first IO address
* addr2 = second IO address
* irq = interrupt number
*
* Return: 0 = success or error condition
*
*****************************************************************/
static int __devinit hc_found_hci (int addr, int addr2, int irq)
{
hci_t *hci;
hcipriv_t *hp;
DBGFUNC ("Enter hc_found_hci\n");
hci = hc_alloc_hci ();
if (!hci) {
return -ENOMEM;
}
init_irq ();
hp = &hci->hp;
if (!request_region (addr, 256, "SL811 USB HOST")) {
DBGERR ("request address %d failed", addr);
hc_release_hci (hci);
return -EBUSY;
}
hp->hcport = addr;
if (!hp->hcport) {
DBGERR ("Error mapping SL811 Memory 0x%x", hp->hcport);
}
if (!request_region (addr2, 256, "SL811 USB HOST")) {
DBGERR ("request address %d failed", addr2);
hc_release_hci (hci);
return -EBUSY;
}
hp->hcport2 = addr2;
if (!hp->hcport2) {
DBGERR ("Error mapping SL811 Memory 0x%x", hp->hcport2);
}
if (hc_alloc_trans_buffer (hci)) {
hc_release_hci (hci);
return -ENOMEM;
}
usb_register_bus (hci->bus);
if (request_irq (irq, hc_interrupt, 0, "SL811", hci) != 0) {
DBGERR ("request interrupt %d failed", irq);
hc_release_hci (hci);
return -EBUSY;
}
hp->irq = irq;
printk (KERN_INFO __FILE__ ": USB SL811 at %x, addr2 = %x, IRQ %d\n",
addr, addr2, irq);
hc_reset (hci);
if (hc_start (hci) < 0) {
DBGERR ("can't start usb-%x", addr);
hc_release_hci (hci);
return -EBUSY;
}
return 0;
}
/*****************************************************************
*
* Function Name: hci_hcd_init
*
* This is an init function, and it is the first function being called
*
* Input: none
*
* Return: 0 = success or error condition
*
*****************************************************************/
static int __init hci_hcd_init (void)
{
int ret;
DBGFUNC ("Enter hci_hcd_init\n");
ret = hc_found_hci (base_addr, data_reg_addr, irq);
return ret;
}
/*****************************************************************
*
* Function Name: hci_hcd_cleanup
*
* This is a cleanup function, and it is called when module is
* unloaded.
*
* Input: none
*
* Return: none
*
*****************************************************************/
static void __exit hci_hcd_cleanup (void)
{
struct list_head *hci_l;
hci_t *hci;
DBGFUNC ("Enter hci_hcd_cleanup\n");
for (hci_l = hci_hcd_list.next; hci_l != &hci_hcd_list;) {
hci = list_entry (hci_l, hci_t, hci_hcd_list);
hci_l = hci_l->next;
hc_release_hci (hci);
}
}
module_init (hci_hcd_init);
module_exit (hci_hcd_cleanup);
MODULE_AUTHOR ("Pei Liu <pbl@cypress.com>");
MODULE_DESCRIPTION ("USB SL811HS Host Controller Driver");
/*
* SL811HS HCD (Host Controller Driver) for USB.
*
* COPYRIGHT (C) by CYPRESS SEMICONDUCTOR INC
*
*
*/
#define GET_FRAME_NUMBER(hci) READ_REG32 (hci, HcFmNumber)
/*
* Maximum number of root hub ports
*/
#define MAX_ROOT_PORTS 15 /* maximum OHCI root hub ports */
/* control and status registers */
#define HcRevision 0x00
#define HcControl 0x01
#define HcCommandStatus 0x02
#define HcInterruptStatus 0x03
#define HcInterruptEnable 0x04
#define HcInterruptDisable 0x05
#define HcFmInterval 0x0D
#define HcFmRemaining 0x0E
#define HcFmNumber 0x0F
#define HcLSThreshold 0x11
#define HcRhDescriptorA 0x12
#define HcRhDescriptorB 0x13
#define HcRhStatus 0x14
#define HcRhPortStatus 0x15
#define HcHardwareConfiguration 0x20
#define HcDMAConfiguration 0x21
#define HcTransferCounter 0x22
#define HcuPInterrupt 0x24
#define HcuPInterruptEnable 0x25
#define HcChipID 0x27
#define HcScratch 0x28
#define HcSoftwareReset 0x29
#define HcITLBufferLength 0x2A
#define HcATLBufferLength 0x2B
#define HcBufferStatus 0x2C
#define HcReadBackITL0Length 0x2D
#define HcReadBackITL1Length 0x2E
#define HcITLBufferPort 0x40
#define HcATLBufferPort 0x41
/* OHCI CONTROL AND STATUS REGISTER MASKS */
/*
* HcControl (control) register masks
*/
#define OHCI_CTRL_HCFS (3 << 6) /* BUS state mask */
#define OHCI_CTRL_RWC (1 << 9) /* remote wakeup connected */
#define OHCI_CTRL_RWE (1 << 10) /* remote wakeup enable */
/* pre-shifted values for HCFS */
#define OHCI_USB_RESET (0 << 6)
#define OHCI_USB_RESUME (1 << 6)
#define OHCI_USB_OPER (2 << 6)
#define OHCI_USB_SUSPEND (3 << 6)
/*
* HcCommandStatus (cmdstatus) register masks
*/
#define OHCI_HCR (1 << 0) /* host controller reset */
#define OHCI_SO (3 << 16) /* scheduling overrun count */
/*
* masks used with interrupt registers:
* HcInterruptStatus (intrstatus)
* HcInterruptEnable (intrenable)
* HcInterruptDisable (intrdisable)
*/
#define OHCI_INTR_SO (1 << 0) /* scheduling overrun */
#define OHCI_INTR_SF (1 << 2) /* start frame */
#define OHCI_INTR_RD (1 << 3) /* resume detect */
#define OHCI_INTR_UE (1 << 4) /* unrecoverable error */
#define OHCI_INTR_FNO (1 << 5) /* frame number overflow */
#define OHCI_INTR_RHSC (1 << 6) /* root hub status change */
#define OHCI_INTR_ATD (1 << 7) /* scheduling overrun */
#define OHCI_INTR_MIE (1 << 31) /* master interrupt enable */
/*
* HcHardwareConfiguration
*/
#define InterruptPinEnable (1 << 0)
#define InterruptPinTrigger (1 << 1)
#define InterruptOutputPolarity (1 << 2)
#define DataBusWidth16 (1 << 3)
#define DREQOutputPolarity (1 << 5)
#define DACKInputPolarity (1 << 6)
#define EOTInputPolarity (1 << 7)
#define DACKMode (1 << 8)
#define AnalogOCEnable (1 << 10)
#define SuspendClkNotStop (1 << 11)
#define DownstreamPort15KRSel (1 << 12)
/*
* HcDMAConfiguration
*/
#define DMAReadWriteSelect (1 << 0)
#define ITL_ATL_DataSelect (1 << 1)
#define DMACounterSelect (1 << 2)
#define DMAEnable (1 << 4)
#define BurstLen_1 0
#define BurstLen_4 (1 << 5)
#define BurstLen_8 (2 << 5)
/*
* HcuPInterrupt
*/
#define SOFITLInt (1 << 0)
#define ATLInt (1 << 1)
#define AllEOTInterrupt (1 << 2)
#define OPR_Reg (1 << 4)
#define HCSuspended (1 << 5)
#define ClkReady (1 << 6)
/*
* HcBufferStatus
*/
#define ITL0BufferFull (1 << 0)
#define ITL1BufferFull (1 << 1)
#define ATLBufferFull (1 << 2)
#define ITL0BufferDone (1 << 3)
#define ITL1BufferDone (1 << 4)
#define ATLBufferDone (1 << 5)
/* OHCI ROOT HUB REGISTER MASKS */
/* roothub.portstatus [i] bits */
#define RH_PS_CCS 0x00000001 /* current connect status */
#define RH_PS_PES 0x00000002 /* port enable status */
#define RH_PS_PSS 0x00000004 /* port suspend status */
#define RH_PS_POCI 0x00000008 /* port over current indicator */
#define RH_PS_PRS 0x00000010 /* port reset status */
#define RH_PS_PPS 0x00000100 /* port power status */
#define RH_PS_LSDA 0x00000200 /* low speed device attached */
#define RH_PS_CSC 0x00010000 /* connect status change */
#define RH_PS_PESC 0x00020000 /* port enable status change */
#define RH_PS_PSSC 0x00040000 /* port suspend status change */
#define RH_PS_OCIC 0x00080000 /* over current indicator change */
#define RH_PS_PRSC 0x00100000 /* port reset status change */
/* roothub.status bits */
#define RH_HS_LPS 0x00000001 /* local power status */
#define RH_HS_OCI 0x00000002 /* over current indicator */
#define RH_HS_DRWE 0x00008000 /* device remote wakeup enable */
#define RH_HS_LPSC 0x00010000 /* local power status change */
#define RH_HS_OCIC 0x00020000 /* over current indicator change */
#define RH_HS_CRWE 0x80000000 /* clear remote wakeup enable */
/* roothub.b masks */
#define RH_B_DR 0x0000ffff /* device removable flags */
#define RH_B_PPCM 0xffff0000 /* port power control mask */
/* roothub.a masks */
#define RH_A_NDP (0xff << 0) /* number of downstream ports */
#define RH_A_PSM (1 << 8) /* power switching mode */
#define RH_A_NPS (1 << 9) /* no power switching */
#define RH_A_DT (1 << 10) /* device type (mbz) */
#define RH_A_OCPM (1 << 11) /* over current protection mode */
#define RH_A_NOCP (1 << 12) /* no over current protection */
#define RH_A_POTPGT (0xff << 24) /* power on to power good time */
#define URB_DEL 1
#define PORT_STAT_DEFAULT 0x0100
#define PORT_CONNECT_STAT 0x1
#define PORT_ENABLE_STAT 0x2
#define PORT_SUSPEND_STAT 0x4
#define PORT_OVER_CURRENT_STAT 0x8
#define PORT_RESET_STAT 0x10
#define PORT_POWER_STAT 0x100
#define PORT_LOW_SPEED_DEV_ATTACH_STAT 0x200
#define PORT_CHANGE_DEFAULT 0x0
#define PORT_CONNECT_CHANGE 0x1
#define PORT_ENABLE_CHANGE 0x2
#define PORT_SUSPEND_CHANGE 0x4
#define PORT_OVER_CURRENT_CHANGE 0x8
#define PORT_RESET_CHANGE 0x10
/* Port Status Request info */
typedef struct portstat {
__u16 portChange;
__u16 portStatus;
} portstat_t;
typedef struct hcipriv {
int irq;
int disabled; /* e.g. got a UE, we're hung */
atomic_t resume_count; /* defending against multiple resumes */
struct ohci_regs *regs; /* OHCI controller's memory */
int hcport; /* I/O base address */
int hcport2; /* I/O data reg addr */
struct portstat *RHportStatus; /* root hub port status */
int intrstatus;
__u32 hc_control; /* copy of the hc control reg */
int frame;
__u8 *tl;
int xferPktLen;
int atl_len;
int atl_buffer_len;
int itl0_len;
int itl1_len;
int itl_buffer_len;
int itl_index;
int tl_last;
int units_left;
} hcipriv_t;
struct hci;
#define cClt 0 // Control
#define cISO 1 // ISO
#define cBULK 2 // BULK
#define cInt 3 // Interrupt
#define ISO_BIT 0x10
/*-------------------------------------------------------------------------
* EP0 use for configuration and Vendor Specific command interface
*------------------------------------------------------------------------*/
#define cMemStart 0x10
#define EP0Buf 0x40 /* SL11H/SL811H memory start at 0x40 */
#define EP0Len 0x40 /* Length of config buffer EP0Buf */
#define EP1Buf 0x60
#define EP1Len 0x40
/*-------------------------------------------------------------------------
* SL11H/SL811H memory from 80h-ffh use as ping-pong buffer.
*------------------------------------------------------------------------*/
#define uBufA 0x80 /* buffer A address for DATA0 */
#define uBufB 0xc0 /* buffer B address for DATA1 */
#define uXferLen 0x40 /* xfer length */
#define sMemSize 0xc0 /* Total SL11 memory size */
#define cMemEnd 256
/*-------------------------------------------------------------------------
* SL811H Register Control memory map
* --Note:
* --SL11H only has one control register set from 0x00-0x04
* --SL811H has two control register set from 0x00-0x04 and 0x08-0x0c
*------------------------------------------------------------------------*/
#define EP0Control 0x00
#define EP0Address 0x01
#define EP0XferLen 0x02
#define EP0Status 0x03
#define EP0Counter 0x04
#define EP1Control 0x08
#define EP1Address 0x09
#define EP1XferLen 0x0a
#define EP1Status 0x0b
#define EP1Counter 0x0c
#define CtrlReg 0x05
#define IntEna 0x06
// 0x07 is reserved
#define IntStatus 0x0d
#define cDATASet 0x0e
#define cSOFcnt 0x0f
#define IntMask 0x57 /* Reset|DMA|EP0|EP2|EP1 for IntEna */
#define HostMask 0x47 /* Host request command for IntStatus */
#define ReadMask 0xd7 /* Read mask interrupt for IntStatus */
/*-------------------------------------------------------------------------
* Standard Chapter 9 definition
*-------------------------------------------------------------------------
*/
#define GET_STATUS 0x00
#define CLEAR_FEATURE 0x01
#define SET_FEATURE 0x03
#define SET_ADDRESS 0x05
#define GET_DESCRIPTOR 0x06
#define SET_DESCRIPTOR 0x07
#define GET_CONFIG 0x08
#define SET_CONFIG 0x09
#define GET_INTERFACE 0x0a
#define SET_INTERFACE 0x0b
#define SYNCH_FRAME 0x0c
#define DEVICE 0x01
#define CONFIGURATION 0x02
#define STRING 0x03
#define INTERFACE 0x04
#define ENDPOINT 0x05
/*-------------------------------------------------------------------------
* SL11H/SL811H definition
*-------------------------------------------------------------------------
*/
#define DATA0_WR 0x07 // (Arm+Enable+tranmist to Host+DATA0)
#define DATA1_WR 0x47 // (Arm+Enable+tranmist to Host on DATA1)
#define ZDATA0_WR 0x05 // (Arm+Transaction Ignored+tranmist to Host+DATA0)
#define ZDATA1_WR 0x45 // (Arm+Transaction Ignored+tranmist to Host+DATA1)
#define DATA0_RD 0x03 // (Arm+Enable+received from Host+DATA0)
#define DATA1_RD 0x43 // (Arm+Enable+received from Host+DATA1)
#define PID_SETUP 0x2d // USB Specification 1.1 Standard Definition
#define PID_SOF 0xA5
#define PID_IN 0x69
#define PID_OUT 0xe1
#define MAX_RETRY 0xffff
#define TIMEOUT 5 /* 2 mseconds */
#define SL11H_HOSTCTLREG 0
#define SL11H_BUFADDRREG 1
#define SL11H_BUFLNTHREG 2
#define SL11H_PKTSTATREG 3 /* read */
#define SL11H_PIDEPREG 3 /* write */
#define SL11H_XFERCNTREG 4 /* read */
#define SL11H_DEVADDRREG 4 /* write */
#define SL11H_CTLREG1 5
#define SL11H_INTENBLREG 6
#define SL11H_HOSTCTLREG_B 8
#define SL11H_BUFADDRREG_B 9
#define SL11H_BUFLNTHREG_B 0x0A
#define SL11H_PKTSTATREG_B 0x0B /* read */
#define SL11H_PIDEPREG_B 0x0B /* write */
#define SL11H_XFERCNTREG_B 0x0C /* read */
#define SL11H_DEVADDRREG_B 0x0C /* write */
#define SL11H_INTSTATREG 0x0D /* write clears bitwise */
#define SL11H_HWREVREG 0x0E /* read */
#define SL11H_SOFLOWREG 0x0E /* write */
#define SL11H_SOFTMRREG 0x0F /* read */
#define SL11H_CTLREG2 0x0F /* write */
#define SL11H_DATA_START 0x10
/* Host control register bits (addr 0) */
#define SL11H_HCTLMASK_ARM 1
#define SL11H_HCTLMASK_ENBLEP 2
#define SL11H_HCTLMASK_WRITE 4
#define SL11H_HCTLMASK_ISOCH 0x10
#define SL11H_HCTLMASK_AFTERSOF 0x20
#define SL11H_HCTLMASK_SEQ 0x40
#define SL11H_HCTLMASK_PREAMBLE 0x80
/* Packet status register bits (addr 3) */
#define SL11H_STATMASK_ACK 1
#define SL11H_STATMASK_ERROR 2
#define SL11H_STATMASK_TMOUT 4
#define SL11H_STATMASK_SEQ 8
#define SL11H_STATMASK_SETUP 0x10
#define SL11H_STATMASK_OVF 0x20
#define SL11H_STATMASK_NAK 0x40
#define SL11H_STATMASK_STALL 0x80
/* Control register 1 bits (addr 5) */
#define SL11H_CTL1MASK_DSBLSOF 1
#define SL11H_CTL1MASK_NOTXEOF2 4
#define SL11H_CTL1MASK_DSTATE 0x18
#define SL11H_CTL1MASK_NSPD 0x20
#define SL11H_CTL1MASK_SUSPEND 0x40
#define SL11H_CTL1MASK_CLK12 0x80
#define SL11H_CTL1VAL_RESET 8
/* Interrut enable (addr 6) and interrupt status register bits (addr 0xD) */
#define SL11H_INTMASK_XFERDONE 1
#define SL11H_INTMASK_SOFINTR 0x10
#define SL11H_INTMASK_INSRMV 0x20
#define SL11H_INTMASK_USBRESET 0x40
#define SL11H_INTMASK_DSTATE 0x80 /* only in status reg */
/* HW rev and SOF lo register bits (addr 0xE) */
#define SL11H_HWRMASK_HWREV 0xF0
/* SOF counter and control reg 2 (addr 0xF) */
#define SL11H_CTL2MASK_SOFHI 0x3F
#define SL11H_CTL2MASK_DSWAP 0x40
#define SL11H_CTL2MASK_HOSTMODE 0xae
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*
* SL811HS virtual root hub
*
* based on usb-ohci.c by R. Weissgaerber et al.
*-------------------------------------------------------------------------*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*-------------------------------------------------------------------------*/
#ifdef DEBUG
#undef DEBUG
#endif
static __u32 getPortStatusAndChange (hci_t * hci);
static void setPortStatus (hci_t * hci, __u16 bitPos);
static void setPortChange (hci_t * hci, __u16 bitPos);
static void clrPortStatus (hci_t * hci, __u16 bitPos);
static void clrPortChange (hci_t * hci, __u16 bitPos);
static int USBReset (hci_t * hci);
static int cc_to_error (int cc);
/*-------------------------------------------------------------------------*
* Virtual Root Hub
*-------------------------------------------------------------------------*/
/* Device descriptor */
static __u8 root_hub_dev_des[] = {
0x12, /* __u8 bLength; */
0x01, /* __u8 bDescriptorType; Device */
0x10, /* __u16 bcdUSB; v1.1 */
0x01,
0x09, /* __u8 bDeviceClass; HUB_CLASSCODE */
0x00, /* __u8 bDeviceSubClass; */
0x00, /* __u8 bDeviceProtocol; */
0x08, /* __u8 bMaxPacketSize0; 8 Bytes */
0x00, /* __u16 idVendor; */
0x00,
0x00, /* __u16 idProduct; */
0x00,
0x00, /* __u16 bcdDevice; */
0x00,
0x00, /* __u8 iManufacturer; */
0x02, /* __u8 iProduct; */
0x01, /* __u8 iSerialNumber; */
0x01 /* __u8 bNumConfigurations; */
};
/* Configuration descriptor */
static __u8 root_hub_config_des[] = {
0x09, /* __u8 bLength; */
0x02, /* __u8 bDescriptorType; Configuration */
0x19, /* __u16 wTotalLength; */
0x00,
0x01, /* __u8 bNumInterfaces; */
0x01, /* __u8 bConfigurationValue; */
0x00, /* __u8 iConfiguration; */
0x40, /* __u8 bmAttributes;
Bit 7: Bus-powered, 6: Self-powered, 5 Remote-wakwup,
4..0: resvd */
0x00, /* __u8 MaxPower; */
/* interface */
0x09, /* __u8 if_bLength; */
0x04, /* __u8 if_bDescriptorType; Interface */
0x00, /* __u8 if_bInterfaceNumber; */
0x00, /* __u8 if_bAlternateSetting; */
0x01, /* __u8 if_bNumEndpoints; */
0x09, /* __u8 if_bInterfaceClass; HUB_CLASSCODE */
0x00, /* __u8 if_bInterfaceSubClass; */
0x00, /* __u8 if_bInterfaceProtocol; */
0x00, /* __u8 if_iInterface; */
/* endpoint */
0x07, /* __u8 ep_bLength; */
0x05, /* __u8 ep_bDescriptorType; Endpoint */
0x81, /* __u8 ep_bEndpointAddress; IN Endpoint 1 */
0x03, /* __u8 ep_bmAttributes; Interrupt */
0x02, /* __u16 ep_wMaxPacketSize; ((MAX_ROOT_PORTS + 1) / 8 */
0x00,
0xff /* __u8 ep_bInterval; 255 ms */
};
/* Hub class-specific descriptor is constructed dynamically */
/***************************************************************************
* Function Name : rh_send_irq
*
* This function examine the port change in the virtual root hub.
*
* Note: This function assumes only one port exist in the root hub.
*
* Input: hci = data structure for the host controller
* rh_data = The pointer to port change data
* rh_len = length of the data in bytes
*
* Return: length of data
**************************************************************************/
static int rh_send_irq (hci_t * hci, void *rh_data, int rh_len)
{
int num_ports;
int i;
int ret;
int len;
__u8 data[8];
DBGFUNC ("enter rh_send_irq: \n");
/* Assuming the root hub has one port. This value need to change if
* there are more than one port for the root hub
*/
num_ports = 1;
/* The root hub status is not implemented, it basically has two fields:
* -- Local Power Status
* -- Over Current Indicator
* -- Local Power Change
* -- Over Current Indicator
*
* Right now, It is assume the power is good and no changes
*/
*(__u8 *) data = 0;
ret = *(__u8 *) data;
/* Has the port status change within the root hub: It checks for
* -- Port Connect Status change
* -- Port Enable Change
*/
for (i = 0; i < num_ports; i++) {
*(__u8 *) (data + (i + 1) / 8) |=
(((getPortStatusAndChange (hci) >> 16) & (PORT_CONNECT_STAT | PORT_ENABLE_STAT)) ? 1 : 0) << ((i + 1) % 8);
ret += *(__u8 *) (data + (i + 1) / 8);
/* After the port change is read, it should be reset so the next time
* is it doesn't trigger a change again */
}
len = i / 8 + 1;
if (ret > 0) {
memcpy (rh_data, data, min (len, min (rh_len, (int)sizeof (data))));
return len;
}
return 0;
}
/***************************************************************************
* Function Name : rh_int_timer_do
*
* This function is called when the timer expires. It gets the the port
* change data and pass along to the upper protocol.
*
* Note: The virtual root hub interrupt pipe are polled by the timer
* every "interval" ms
*
* Input: ptr = ptr to the urb
*
* Return: none
**************************************************************************/
static void rh_int_timer_do (unsigned long ptr)
{
int len;
struct urb *urb = (struct urb *) ptr;
hci_t *hci = urb->dev->bus->hcpriv;
DBGFUNC ("enter rh_int_timer_do\n");
if (hci->rh.send) {
len = rh_send_irq (hci, urb->transfer_buffer,
urb->transfer_buffer_length);
if (len > 0) {
urb->actual_length = len;
if (urb_debug == 2)
urb_print (urb, "RET-t(rh)",
usb_pipeout (urb->pipe));
if (urb->complete) {
urb->complete (urb);
}
}
}
/* re-activate the timer */
rh_init_int_timer (urb);
}
/***************************************************************************
* Function Name : rh_init_int_timer
*
* This function creates a timer that act as interrupt pipe in the
* virtual hub.
*
* Note: The virtual root hub's interrupt pipe are polled by the timer
* every "interval" ms
*
* Input: urb = USB request block
*
* Return: 0
**************************************************************************/
static int rh_init_int_timer (struct urb * urb)
{
hci_t *hci = urb->dev->bus->hcpriv;
hci->rh.interval = urb->interval;
init_timer (&hci->rh.rh_int_timer);
hci->rh.rh_int_timer.function = rh_int_timer_do;
hci->rh.rh_int_timer.data = (unsigned long) urb;
hci->rh.rh_int_timer.expires = jiffies + (HZ * (urb->interval < 30 ? 30 : urb->interval)) / 1000;
add_timer (&hci->rh.rh_int_timer);
return 0;
}
/*-------------------------------------------------------------------------*/
/* helper macro */
#define OK(x) len = (x); break
/***************************************************************************
* Function Name : rh_submit_urb
*
* This function handles all USB request to the the virtual root hub
*
* Input: urb = USB request block
*
* Return: 0
**************************************************************************/
static int rh_submit_urb (struct urb * urb)
{
struct usb_device *usb_dev = urb->dev;
hci_t *hci = usb_dev->bus->hcpriv;
unsigned int pipe = urb->pipe;
struct usb_ctrlrequest *cmd = (struct usb_ctrlrequest *) urb->setup_packet;
void *data = urb->transfer_buffer;
int leni = urb->transfer_buffer_length;
int len = 0;
int status = TD_CC_NOERROR;
__u32 datab[4];
__u8 *data_buf = (__u8 *) datab;
__u16 bmRType_bReq;
__u16 wValue;
__u16 wIndex;
__u16 wLength;
DBGFUNC ("enter rh_submit_urb\n");
if (usb_pipeint (pipe)) {
hci->rh.urb = urb;
hci->rh.send = 1;
hci->rh.interval = urb->interval;
rh_init_int_timer (urb);
urb->status = cc_to_error (TD_CC_NOERROR);
return 0;
}
bmRType_bReq = cmd->bRequestType | (cmd->bRequest << 8);
wValue = le16_to_cpu (cmd->wValue);
wIndex = le16_to_cpu (cmd->wIndex);
wLength = le16_to_cpu (cmd->wLength);
DBG ("rh_submit_urb, req = %d(%x) len=%d",
bmRType_bReq, bmRType_bReq, wLength);
switch (bmRType_bReq) {
/* Request Destination:
without flags: Device,
RH_INTERFACE: interface,
RH_ENDPOINT: endpoint,
RH_CLASS means HUB here,
RH_OTHER | RH_CLASS almost ever means HUB_PORT here
*/
case RH_GET_STATUS:
*(__u16 *) data_buf = cpu_to_le16 (1);
OK (2);
case RH_GET_STATUS | RH_INTERFACE:
*(__u16 *) data_buf = cpu_to_le16 (0);
OK (2);
case RH_GET_STATUS | RH_ENDPOINT:
*(__u16 *) data_buf = cpu_to_le16 (0);
OK (2);
case RH_GET_STATUS | RH_CLASS:
*(__u32 *) data_buf = cpu_to_le32 (0);
OK (4);
case RH_GET_STATUS | RH_OTHER | RH_CLASS:
*(__u32 *) data_buf =
cpu_to_le32 (getPortStatusAndChange (hci));
OK (4);
case RH_CLEAR_FEATURE | RH_ENDPOINT:
switch (wValue) {
case (RH_ENDPOINT_STALL):
OK (0);
}
break;
case RH_CLEAR_FEATURE | RH_CLASS:
switch (wValue) {
case RH_C_HUB_LOCAL_POWER:
OK (0);
case (RH_C_HUB_OVER_CURRENT):
/* Over Current Not Implemented */
OK (0);
}
break;
case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
switch (wValue) {
case (RH_PORT_ENABLE):
clrPortStatus (hci, PORT_ENABLE_STAT);
OK (0);
case (RH_PORT_SUSPEND):
clrPortStatus (hci, PORT_SUSPEND_STAT);
OK (0);
case (RH_PORT_POWER):
clrPortStatus (hci, PORT_POWER_STAT);
OK (0);
case (RH_C_PORT_CONNECTION):
clrPortChange (hci, PORT_CONNECT_STAT);
OK (0);
case (RH_C_PORT_ENABLE):
clrPortChange (hci, PORT_ENABLE_STAT);
OK (0);
case (RH_C_PORT_SUSPEND):
clrPortChange (hci, PORT_SUSPEND_STAT);
OK (0);
case (RH_C_PORT_OVER_CURRENT):
clrPortChange (hci, PORT_OVER_CURRENT_STAT);
OK (0);
case (RH_C_PORT_RESET):
clrPortChange (hci, PORT_RESET_STAT);
OK (0);
}
break;
case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
switch (wValue) {
case (RH_PORT_SUSPEND):
setPortStatus (hci, PORT_SUSPEND_STAT);
OK (0);
case (RH_PORT_RESET):
setPortStatus (hci, PORT_RESET_STAT);
// USBReset(hci);
clrPortChange (hci,
PORT_CONNECT_CHANGE | PORT_ENABLE_CHANGE
| PORT_SUSPEND_CHANGE |
PORT_OVER_CURRENT_CHANGE);
setPortChange (hci, PORT_RESET_CHANGE);
clrPortStatus (hci, PORT_RESET_STAT);
setPortStatus (hci, PORT_ENABLE_STAT);
OK (0);
case (RH_PORT_POWER):
setPortStatus (hci, PORT_POWER_STAT);
OK (0);
case (RH_PORT_ENABLE):
setPortStatus (hci, PORT_ENABLE_STAT);
OK (0);
}
break;
case RH_SET_ADDRESS:
hci->rh.devnum = wValue;
OK (0);
case RH_GET_DESCRIPTOR:
DBGVERBOSE ("rh_submit_urb: RH_GET_DESCRIPTOR, wValue = 0x%x\n", wValue);
switch ((wValue & 0xff00) >> 8) {
case (0x01): /* device descriptor */
len = min (leni, min ((__u16)sizeof (root_hub_dev_des), wLength));
data_buf = root_hub_dev_des;
OK (len);
case (0x02): /* configuration descriptor */
len = min (leni, min ((__u16)sizeof (root_hub_config_des), wLength));
data_buf = root_hub_config_des;
OK (len);
case (0x03): /* string descriptors */
len = usb_root_hub_string (wValue & 0xff, (int) (long) 0,
"SL811HS", data, wLength);
if (len > 0) {
data_buf = data;
OK (min (leni, len));
}
default:
status = SL11H_STATMASK_STALL;
}
break;
case RH_GET_DESCRIPTOR | RH_CLASS:
data_buf[0] = 9; // min length;
data_buf[1] = 0x29;
data_buf[2] = 1; // # of downstream port
data_buf[3] = 0;
datab[1] = 0;
data_buf[5] = 50; // 100 ms for port reset
data_buf[7] = 0xfc; // which port is attachable
if (data_buf[2] < 7) {
data_buf[8] = 0xff;
} else {
}
len = min (leni, min ((__u16)data_buf[0], wLength));
OK (len);
case RH_GET_CONFIGURATION:
*(__u8 *) data_buf = 0x01;
OK (1);
case RH_SET_CONFIGURATION:
OK (0);
default:
DBGERR ("unsupported root hub command");
status = SL11H_STATMASK_STALL;
}
len = min (len, leni);
if (data != data_buf)
memcpy (data, data_buf, len);
urb->actual_length = len;
urb->status = cc_to_error (status);
urb->hcpriv = NULL;
urb->dev = NULL;
if (urb->complete) {
urb->complete (urb);
}
return 0;
}
/***************************************************************************
* Function Name : rh_unlink_urb
*
* This function unlinks the URB
*
* Input: urb = USB request block
*
* Return: 0
**************************************************************************/
static int rh_unlink_urb (struct urb * urb)
{
hci_t *hci = urb->dev->bus->hcpriv;
DBGFUNC ("enter rh_unlink_urb\n");
if (hci->rh.urb == urb) {
hci->rh.send = 0;
del_timer (&hci->rh.rh_int_timer);
hci->rh.urb = NULL;
urb->hcpriv = NULL;
usb_put_dev (urb->dev);
urb->dev = NULL;
if (urb->transfer_flags & USB_ASYNC_UNLINK) {
urb->status = -ECONNRESET;
if (urb->complete) {
urb->complete (urb);
}
} else
urb->status = -ENOENT;
}
return 0;
}
/***************************************************************************
* Function Name : rh_connect_rh
*
* This function connect the virtual root hub to the USB stack
*
* Input: urb = USB request block
*
* Return: 0
**************************************************************************/
static int rh_connect_rh (hci_t * hci)
{
struct usb_device *usb_dev;
hci->rh.devnum = 0;
usb_dev = usb_alloc_dev (NULL, hci->bus);
if (!usb_dev)
return -ENOMEM;
hci->bus->root_hub = usb_dev;
usb_connect (usb_dev);
if (usb_new_device (usb_dev) != 0) {
usb_free_dev (usb_dev);
return -ENODEV;
}
return 0;
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
Georg Acher + Deti Fliegl + Thomas Sailer Georg Acher + Deti Fliegl + Thomas Sailer
georg@acher.org deti@fliegl.de sailer@ife.ee.ethz.ch georg@acher.org deti@fliegl.de sailer@ife.ee.ethz.ch
$Id: usb-uhci-dbg.c,v 1.1 2002/05/14 20:36:57 acher Exp $ $Id: usb-uhci-dbg.c,v 1.2 2002/05/21 21:40:16 acher Exp $
*/ */
#ifdef DEBUG #ifdef DEBUG
...@@ -105,7 +105,7 @@ static void __attribute__((__unused__)) uhci_show_sc (int port, unsigned short s ...@@ -105,7 +105,7 @@ static void __attribute__((__unused__)) uhci_show_sc (int port, unsigned short s
void uhci_show_status (struct uhci_hcd *uhci) void uhci_show_status (struct uhci_hcd *uhci)
{ {
unsigned int io_addr = (int)uhci->hcd.regs; unsigned long io_addr = (unsigned long)uhci->hcd.regs;
unsigned short usbcmd, usbstat, usbint, usbfrnum; unsigned short usbcmd, usbstat, usbint, usbfrnum;
unsigned int flbaseadd; unsigned int flbaseadd;
unsigned char sof; unsigned char sof;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
HW-initalization based on material of HW-initalization based on material of
Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds
$Id: usb-uhci-hcd.c,v 1.1 2002/05/14 20:36:57 acher Exp $ $Id: usb-uhci-hcd.c,v 1.3 2002/05/25 16:42:41 acher Exp $
*/ */
#include <linux/config.h> #include <linux/config.h>
...@@ -37,7 +37,6 @@ ...@@ -37,7 +37,6 @@
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <linux/usb.h> #include <linux/usb.h>
#define CONFIG_USB_DEBUG
#ifdef CONFIG_USB_DEBUG #ifdef CONFIG_USB_DEBUG
#define DEBUG #define DEBUG
#else #else
...@@ -47,34 +46,34 @@ ...@@ -47,34 +46,34 @@
#include "../core/hcd.h" #include "../core/hcd.h"
#include "usb-uhci-hcd.h" #include "usb-uhci-hcd.h"
#define DRIVER_VERSION "$Revision: 1.1 $" #define DRIVER_VERSION "$Revision: 1.3 $"
#define DRIVER_AUTHOR "Georg Acher, Deti Fliegl, Thomas Sailer" #define DRIVER_AUTHOR "Georg Acher, Deti Fliegl, Thomas Sailer"
#define DRIVER_DESC "USB 1.1 Universal Host Controller Interface driver (HCD)" #define DRIVER_DESC "USB 1.1 Universal Host Controller Interface driver (HCD)"
/*--------------------------------------------------------------------------*/
// Values you may tweak
/* CONFIG_USB_UHCI_HIGH_BANDWITH turns on Full Speed Bandwidth /*--------------------------------------------------------------------------*/
* Reclamation: feature that puts loop on descriptor loop when /* Values you may tweak with module parameters
*
* high_bw: 1=on (default), 0=off
* Turns on Full Speed Bandwidth Reclamation:
* Feature that puts a loop on the descriptor chain when
* there's some transfer going on. With FSBR, USB performance * there's some transfer going on. With FSBR, USB performance
* is optimal, but PCI can be slowed down up-to 5 times, slowing down * is optimal, but PCI can be slowed down up-to 5 times, slowing down
* system performance (eg. framebuffer devices). * system performance (eg. framebuffer devices).
*/ *
#define CONFIG_USB_UHCI_HIGH_BANDWIDTH * bulk_depth/ctrl_depth: 0=off (default), 1:on
* Puts descriptors for bulk/control transfers in depth-first mode.
/* *_DEPTH_FIRST puts descriptor in depth-first mode. This has * This has somehow similar effect to FSBR (higher speed), but does not
* somehow similar effect to FSBR (higher speed), but does not
* slow PCI down. OTOH USB performace is slightly slower than * slow PCI down. OTOH USB performace is slightly slower than
* in FSBR case and single device could hog whole USB, starving * in FSBR case and single device could hog whole USB, starving
* other devices. * other devices. Some devices (e.g. STV680-based cameras) NEED this depth
*/ * first search to work properly.
#define USE_CTRL_DEPTH_FIRST 0 // 0: Breadth first, 1: Depth first *
#define USE_BULK_DEPTH_FIRST 0 // 0: Breadth first, 1: Depth first * Turning off both high_bw and bulk_depth/ctrl_depth
/* Turning off both CONFIG_USB_UHCI_HIGH_BANDWITH and *_DEPTH_FIRST
* will lead to <64KB/sec performance over USB for bulk transfers targeting * will lead to <64KB/sec performance over USB for bulk transfers targeting
* one device's endpoint. You probably do not want to do that. * one device's endpoint. You probably do not want to do that.
*/ */
// Other constants, there's usually no need to change them.
// stop bandwidth reclamation after (roughly) 50ms // stop bandwidth reclamation after (roughly) 50ms
#define IDLE_TIMEOUT (HZ/20) #define IDLE_TIMEOUT (HZ/20)
...@@ -100,6 +99,14 @@ ...@@ -100,6 +99,14 @@
// NO serviceable parts below! // NO serviceable parts below!
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
/* Can be set by module parameters */
static int high_bw = 1;
static int ctrl_depth = 0; /* 0: Breadth first, 1: Depth first */
static int bulk_depth = 0; /* 0: Breadth first, 1: Depth first */
// How much URBs with ->next are walked
#define MAX_NEXT_COUNT 2048
static struct uhci *devs = NULL; static struct uhci *devs = NULL;
/* used by userspace UHCI data structure dumper */ /* used by userspace UHCI data structure dumper */
...@@ -155,7 +162,6 @@ static int uhci_urb_enqueue (struct usb_hcd *hcd, struct urb *urb, int mem_flags ...@@ -155,7 +162,6 @@ static int uhci_urb_enqueue (struct usb_hcd *hcd, struct urb *urb, int mem_flags
spin_lock_irqsave (&uhci->urb_list_lock, flags); spin_lock_irqsave (&uhci->urb_list_lock, flags);
queued_urb = search_dev_ep (uhci, urb); // returns already queued urb for that pipe queued_urb = search_dev_ep (uhci, urb); // returns already queued urb for that pipe
if (queued_urb) { if (queued_urb) {
...@@ -165,7 +171,7 @@ static int uhci_urb_enqueue (struct usb_hcd *hcd, struct urb *urb, int mem_flags ...@@ -165,7 +171,7 @@ static int uhci_urb_enqueue (struct usb_hcd *hcd, struct urb *urb, int mem_flags
((type == PIPE_BULK) && ((type == PIPE_BULK) &&
(!(urb->transfer_flags & USB_QUEUE_BULK) || !(queued_urb->transfer_flags & USB_QUEUE_BULK)))) { (!(urb->transfer_flags & USB_QUEUE_BULK) || !(queued_urb->transfer_flags & USB_QUEUE_BULK)))) {
spin_unlock_irqrestore (&uhci->urb_list_lock, flags); spin_unlock_irqrestore (&uhci->urb_list_lock, flags);
err("ENXIO (%s) %08x, flags %x, urb %p, burb %p, propably device driver bug...", err("ENXIO (%s) %08x, flags %x, urb %p, burb %p, probably device driver bug...",
PIPESTRING(type), PIPESTRING(type),
urb->pipe,urb->transfer_flags,urb,queued_urb); urb->pipe,urb->transfer_flags,urb,queued_urb);
return -ENXIO; // urb already queued return -ENXIO; // urb already queued
...@@ -196,7 +202,7 @@ static int uhci_urb_enqueue (struct usb_hcd *hcd, struct urb *urb, int mem_flags ...@@ -196,7 +202,7 @@ static int uhci_urb_enqueue (struct usb_hcd *hcd, struct urb *urb, int mem_flags
PCI_DMA_TODEVICE); PCI_DMA_TODEVICE);
// for bulk queuing it is essential that interrupts are disabled until submission // for bulk queuing it is essential that interrupts are disabled until submission
// all other type enable interrupts again // all other types enable interrupts again
switch (type) { switch (type) {
case PIPE_BULK: case PIPE_BULK:
if (queued_urb) { if (queued_urb) {
...@@ -293,7 +299,7 @@ static int uhci_get_frame (struct usb_hcd *hcd) ...@@ -293,7 +299,7 @@ static int uhci_get_frame (struct usb_hcd *hcd)
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
static int hc_reset (struct uhci_hcd *uhci) static int hc_reset (struct uhci_hcd *uhci)
{ {
unsigned int io_addr = (int)uhci->hcd.regs; unsigned long io_addr = (unsigned long)uhci->hcd.regs;
uhci->apm_state = 0; uhci->apm_state = 0;
uhci->running = 0; uhci->running = 0;
...@@ -306,7 +312,7 @@ static int hc_reset (struct uhci_hcd *uhci) ...@@ -306,7 +312,7 @@ static int hc_reset (struct uhci_hcd *uhci)
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
static int hc_irq_run(struct uhci_hcd *uhci) static int hc_irq_run(struct uhci_hcd *uhci)
{ {
unsigned int io_addr = (int)uhci->hcd.regs; unsigned long io_addr = (unsigned long)uhci->hcd.regs;
/* Turn on all interrupts */ /* Turn on all interrupts */
outw (USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP, io_addr + USBINTR); outw (USBINTR_TIMEOUT | USBINTR_RESUME | USBINTR_IOC | USBINTR_SP, io_addr + USBINTR);
...@@ -324,7 +330,7 @@ static int hc_irq_run(struct uhci_hcd *uhci) ...@@ -324,7 +330,7 @@ static int hc_irq_run(struct uhci_hcd *uhci)
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
static int hc_start (struct uhci_hcd *uhci) static int hc_start (struct uhci_hcd *uhci)
{ {
unsigned int io_addr = (int)uhci->hcd.regs; unsigned long io_addr = (unsigned long)uhci->hcd.regs;
int timeout = 10; int timeout = 10;
struct usb_device *udev; struct usb_device *udev;
init_dbg("hc_start uhci %p",uhci); init_dbg("hc_start uhci %p",uhci);
...@@ -351,7 +357,6 @@ static int hc_start (struct uhci_hcd *uhci) ...@@ -351,7 +357,6 @@ static int hc_start (struct uhci_hcd *uhci)
uhci->hcd.state = USB_STATE_READY; uhci->hcd.state = USB_STATE_READY;
if (!udev) { if (!udev) {
uhci->running = 0; uhci->running = 0;
// FIXME cleanup
return -ENOMEM; return -ENOMEM;
} }
...@@ -360,7 +365,6 @@ static int hc_start (struct uhci_hcd *uhci) ...@@ -360,7 +365,6 @@ static int hc_start (struct uhci_hcd *uhci)
if (usb_register_root_hub (udev, &uhci->hcd.pdev->dev) != 0) { if (usb_register_root_hub (udev, &uhci->hcd.pdev->dev) != 0) {
usb_free_dev (udev); usb_free_dev (udev);
uhci->running = 0; uhci->running = 0;
// FIXME cleanup
return -ENODEV; return -ENODEV;
} }
...@@ -374,7 +378,7 @@ static int __devinit uhci_start (struct usb_hcd *hcd) ...@@ -374,7 +378,7 @@ static int __devinit uhci_start (struct usb_hcd *hcd)
{ {
struct uhci_hcd *uhci = hcd_to_uhci (hcd); struct uhci_hcd *uhci = hcd_to_uhci (hcd);
int ret; int ret;
int io_addr=(int)hcd->regs, io_size=0x20; // FIXME unsigned long io_addr=(unsigned long)hcd->regs, io_size=0x20;
init_dbg("uhci_start hcd %p uhci %p, pdev %p",hcd,uhci,hcd->pdev); init_dbg("uhci_start hcd %p uhci %p, pdev %p",hcd,uhci,hcd->pdev);
/* disable legacy emulation, Linux takes over... */ /* disable legacy emulation, Linux takes over... */
...@@ -448,7 +452,7 @@ static void uhci_stop (struct usb_hcd *hcd) ...@@ -448,7 +452,7 @@ static void uhci_stop (struct usb_hcd *hcd)
static void uhci_irq (struct usb_hcd *hcd) static void uhci_irq (struct usb_hcd *hcd)
{ {
struct uhci_hcd *uhci = hcd_to_uhci (hcd); struct uhci_hcd *uhci = hcd_to_uhci (hcd);
unsigned int io_addr = (int)hcd->regs; unsigned long io_addr = (unsigned long)hcd->regs;
unsigned short status; unsigned short status;
struct list_head *p, *p2; struct list_head *p, *p2;
int restarts, work_done; int restarts, work_done;
...@@ -589,6 +593,12 @@ static const struct hc_driver uhci_driver = { ...@@ -589,6 +593,12 @@ static const struct hc_driver uhci_driver = {
MODULE_AUTHOR (DRIVER_AUTHOR); MODULE_AUTHOR (DRIVER_AUTHOR);
MODULE_DESCRIPTION (DRIVER_INFO); MODULE_DESCRIPTION (DRIVER_INFO);
MODULE_LICENSE ("GPL"); MODULE_LICENSE ("GPL");
MODULE_PARM (high_bw, "i");
MODULE_PARM_DESC (high_bw, "high_hw: Enable high bandwidth mode, 1=on (default), 0=off");
MODULE_PARM (bulk_depth, "i");
MODULE_PARM_DESC (bulk_depth, "bulk_depth: Depth first processing for bulk transfers, 0=off (default), 1=on");
MODULE_PARM (ctrl_depth, "i");
MODULE_PARM_DESC (ctrl_depth, "ctrl_depth: Depth first processing for control transfers, 0=off (default), 1=on");
static const struct pci_device_id __devinitdata pci_ids [] = { { static const struct pci_device_id __devinitdata pci_ids [] = { {
...@@ -627,6 +637,10 @@ static int __init uhci_hcd_init (void) ...@@ -627,6 +637,10 @@ static int __init uhci_hcd_init (void)
init_dbg (DRIVER_INFO); init_dbg (DRIVER_INFO);
init_dbg ("block sizes: hq %d td %d", init_dbg ("block sizes: hq %d td %d",
sizeof (struct qh), sizeof (struct td)); sizeof (struct qh), sizeof (struct td));
info("High bandwidth mode %s.%s%s",
high_bw?"enabled":"disabled",
ctrl_depth?"CTRL depth first enabled":"",
bulk_depth?"BULK depth first enabled":"");
return pci_module_init (&uhci_pci_driver); return pci_module_init (&uhci_pci_driver);
} }
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
HW-initalization based on material of HW-initalization based on material of
Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds
$Id: usb-uhci-hub.c,v 1.1 2002/05/14 20:36:57 acher Exp $ $Id: usb-uhci-hub.c,v 1.2 2002/05/21 21:40:16 acher Exp $
*/ */
#define CLR_RH_PORTSTAT(x) \ #define CLR_RH_PORTSTAT(x) \
...@@ -34,7 +34,7 @@ static int oldval=-1; ...@@ -34,7 +34,7 @@ static int oldval=-1;
static int uhci_hub_status_data (struct usb_hcd *hcd, char *buf) static int uhci_hub_status_data (struct usb_hcd *hcd, char *buf)
{ {
struct uhci_hcd *uhci = hcd_to_uhci (hcd); struct uhci_hcd *uhci = hcd_to_uhci (hcd);
unsigned int io_addr = (int)uhci->hcd.regs; unsigned long io_addr = (unsigned long)uhci->hcd.regs;
int i, len=0, data = 0, portstate; int i, len=0, data = 0, portstate;
int changed=0; int changed=0;
...@@ -99,7 +99,7 @@ static int uhci_hub_control ( ...@@ -99,7 +99,7 @@ static int uhci_hub_control (
int status = 0; int status = 0;
int stat = 0; int stat = 0;
int cstatus; int cstatus;
unsigned int io_addr = (int)uhci->hcd.regs; unsigned long io_addr = (unsigned long)uhci->hcd.regs;
int ports = uhci->maxports; int ports = uhci->maxports;
switch (typeReq) { switch (typeReq) {
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
HW-initalization based on material of HW-initalization based on material of
Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds
$Id: usb-uhci-mem.c,v 1.1 2002/05/14 20:36:57 acher Exp $ $Id: usb-uhci-mem.c,v 1.3 2002/05/25 16:42:41 acher Exp $
*/ */
/*###########################################################################*/ /*###########################################################################*/
...@@ -387,10 +387,9 @@ static void uhci_switch_timer_int(struct uhci_hcd *uhci) ...@@ -387,10 +387,9 @@ static void uhci_switch_timer_int(struct uhci_hcd *uhci)
wmb(); wmb();
} }
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
#ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
static void enable_desc_loop(struct uhci_hcd *uhci, struct urb *urb) static void enable_desc_loop(struct uhci_hcd *uhci, struct urb *urb)
{ {
int flags; unsigned long flags;
if (urb->transfer_flags & USB_NO_FSBR) if (urb->transfer_flags & USB_NO_FSBR)
return; return;
...@@ -405,7 +404,7 @@ static void enable_desc_loop(struct uhci_hcd *uhci, struct urb *urb) ...@@ -405,7 +404,7 @@ static void enable_desc_loop(struct uhci_hcd *uhci, struct urb *urb)
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static void disable_desc_loop(struct uhci_hcd *uhci, struct urb *urb) static void disable_desc_loop(struct uhci_hcd *uhci, struct urb *urb)
{ {
int flags; unsigned long flags;
if (urb->transfer_flags & USB_NO_FSBR) if (urb->transfer_flags & USB_NO_FSBR)
return; return;
...@@ -422,18 +421,16 @@ static void disable_desc_loop(struct uhci_hcd *uhci, struct urb *urb) ...@@ -422,18 +421,16 @@ static void disable_desc_loop(struct uhci_hcd *uhci, struct urb *urb)
} }
spin_unlock_irqrestore (&uhci->qh_lock, flags); spin_unlock_irqrestore (&uhci->qh_lock, flags);
} }
#endif
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static void queue_urb_unlocked (struct uhci_hcd *uhci, struct urb *urb) static void queue_urb_unlocked (struct uhci_hcd *uhci, struct urb *urb)
{ {
urb_priv_t *priv=(urb_priv_t*)urb->hcpriv; urb_priv_t *priv=(urb_priv_t*)urb->hcpriv;
#ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
int type; int type;
type=usb_pipetype (urb->pipe); type=usb_pipetype (urb->pipe);
if ((type == PIPE_BULK) || (type == PIPE_CONTROL)) if (high_bw && ((type == PIPE_BULK) || (type == PIPE_CONTROL)))
enable_desc_loop(uhci, urb); enable_desc_loop(uhci, urb);
#endif
urb->status = -EINPROGRESS; urb->status = -EINPROGRESS;
priv->started=jiffies; priv->started=jiffies;
...@@ -455,14 +452,12 @@ static void queue_urb (struct uhci_hcd *uhci, struct urb *urb) ...@@ -455,14 +452,12 @@ static void queue_urb (struct uhci_hcd *uhci, struct urb *urb)
static void dequeue_urb (struct uhci_hcd *uhci, struct urb *urb) static void dequeue_urb (struct uhci_hcd *uhci, struct urb *urb)
{ {
urb_priv_t *priv=(urb_priv_t*)urb->hcpriv; urb_priv_t *priv=(urb_priv_t*)urb->hcpriv;
#ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
int type; int type;
dbg("dequeue URB %p",urb); dbg("dequeue URB %p",urb);
type=usb_pipetype (urb->pipe); type=usb_pipetype (urb->pipe);
if ((type == PIPE_BULK) || (type == PIPE_CONTROL)) if (high_bw && ((type == PIPE_BULK) || (type == PIPE_CONTROL)))
disable_desc_loop(uhci, urb); disable_desc_loop(uhci, urb);
#endif
list_del (&priv->urb_list); list_del (&priv->urb_list);
if (urb->timeout && uhci->timeout_urbs) if (urb->timeout && uhci->timeout_urbs)
...@@ -624,10 +619,10 @@ static int init_skel (struct uhci_hcd *uhci) ...@@ -624,10 +619,10 @@ static int init_skel (struct uhci_hcd *uhci)
insert_qh (uhci, uhci->bulk_chain, qh, 0); insert_qh (uhci, uhci->bulk_chain, qh, 0);
uhci->control_chain = qh; uhci->control_chain = qh;
#ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH
// disabled reclamation loop // disabled reclamation loop
set_qh_head(uhci->chain_end, uhci->control_chain->dma_addr | UHCI_PTR_QH | UHCI_PTR_TERM); if (high_bw)
#endif set_qh_head(uhci->chain_end, uhci->control_chain->dma_addr | UHCI_PTR_QH | UHCI_PTR_TERM);
init_dbg("allocating qh: ls_control_chain"); init_dbg("allocating qh: ls_control_chain");
if (alloc_qh (uhci, &qh)) if (alloc_qh (uhci, &qh))
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
HW-initalization based on material of HW-initalization based on material of
Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds Randy Dunlap + Johannes Erdfelt + Gregory P. Smith + Linus Torvalds
$Id: usb-uhci-q.c,v 1.1 2002/05/14 20:36:57 acher Exp $ $Id: usb-uhci-q.c,v 1.3 2002/05/25 16:42:41 acher Exp $
*/ */
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
...@@ -59,7 +59,7 @@ static int uhci_submit_control_urb (struct uhci_hcd *uhci, struct urb *urb) ...@@ -59,7 +59,7 @@ static int uhci_submit_control_urb (struct uhci_hcd *uhci, struct urb *urb)
urb_priv_t *urb_priv = urb->hcpriv; urb_priv_t *urb_priv = urb->hcpriv;
unsigned long destination, status; unsigned long destination, status;
int maxsze = usb_maxpacket (urb->dev, urb->pipe, usb_pipeout (urb->pipe)); int maxsze = usb_maxpacket (urb->dev, urb->pipe, usb_pipeout (urb->pipe));
int depth_first=USE_CTRL_DEPTH_FIRST; // UHCI descriptor chasing method int depth_first = ctrl_depth; // UHCI descriptor chasing method
unsigned long len; unsigned long len;
char *data; char *data;
...@@ -175,7 +175,7 @@ static int uhci_submit_bulk_urb (struct uhci_hcd *uhci, struct urb *urb, struct ...@@ -175,7 +175,7 @@ static int uhci_submit_bulk_urb (struct uhci_hcd *uhci, struct urb *urb, struct
unsigned int pipe = urb->pipe; unsigned int pipe = urb->pipe;
int maxsze = usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe)); int maxsze = usb_maxpacket (urb->dev, pipe, usb_pipeout (pipe));
int info, len, last; int info, len, last;
int depth_first=USE_BULK_DEPTH_FIRST; // UHCI descriptor chasing method int depth_first = bulk_depth; // UHCI descriptor chasing method
if (usb_endpoint_halted (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe))) if (usb_endpoint_halted (urb->dev, usb_pipeendpoint (pipe), usb_pipeout (pipe)))
return -EPIPE; return -EPIPE;
...@@ -305,7 +305,7 @@ static int uhci_submit_bulk_urb (struct uhci_hcd *uhci, struct urb *urb, struct ...@@ -305,7 +305,7 @@ static int uhci_submit_bulk_urb (struct uhci_hcd *uhci, struct urb *urb, struct
static int uhci_submit_int_urb (struct uhci_hcd *uhci, struct urb *urb) static int uhci_submit_int_urb (struct uhci_hcd *uhci, struct urb *urb)
{ {
urb_priv_t *urb_priv = urb->hcpriv; urb_priv_t *urb_priv = urb->hcpriv;
int nint, n; int nint;
uhci_desc_t *td; uhci_desc_t *td;
int status, destination; int status, destination;
int info; int info;
...@@ -313,16 +313,14 @@ static int uhci_submit_int_urb (struct uhci_hcd *uhci, struct urb *urb) ...@@ -313,16 +313,14 @@ static int uhci_submit_int_urb (struct uhci_hcd *uhci, struct urb *urb)
if (urb->interval == 0) if (urb->interval == 0)
nint = 0; nint = 0;
else { // round interval down to 2^n else {
for (nint = 0, n = 1; nint <= 8; nint++, n += n) // log2-function (urb->interval already 2^n)
if (urb->interval < n) { nint = ffs(urb->interval);
urb->interval = n / 2; if (nint>7)
break; nint=7;
}
nint--;
} }
dbg("Rounded interval to %i, chain %i", urb->interval, nint); dbg("INT-interval %i, chain %i", urb->interval, nint);
// remember start frame, just in case... // remember start frame, just in case...
urb->start_frame = UHCI_GET_CURRENT_FRAME (uhci) & 1023; urb->start_frame = UHCI_GET_CURRENT_FRAME (uhci) & 1023;
...@@ -381,7 +379,7 @@ static int find_iso_limits (struct uhci_hcd *uhci, struct urb *urb, unsigned int ...@@ -381,7 +379,7 @@ static int find_iso_limits (struct uhci_hcd *uhci, struct urb *urb, unsigned int
} }
if (last_urb) { if (last_urb) {
*end = (last_urb->start_frame + last_urb->number_of_packets) & 1023; *end = (last_urb->start_frame + last_urb->number_of_packets*last_urb->interval) & 1023;
ret=0; ret=0;
} }
...@@ -395,12 +393,14 @@ static int find_iso_limits (struct uhci_hcd *uhci, struct urb *urb, unsigned int ...@@ -395,12 +393,14 @@ static int find_iso_limits (struct uhci_hcd *uhci, struct urb *urb, unsigned int
static int iso_find_start (struct uhci_hcd *uhci, struct urb *urb) static int iso_find_start (struct uhci_hcd *uhci, struct urb *urb)
{ {
unsigned int now; unsigned int now;
unsigned int start_limit = 0, stop_limit = 0, queued_size; unsigned int start_limit = 0, stop_limit = 0, queued_size, number_of_frames;
int limits; int limits;
now = UHCI_GET_CURRENT_FRAME (uhci) & 1023; now = UHCI_GET_CURRENT_FRAME (uhci) & 1023;
if ((unsigned) urb->number_of_packets > 900) number_of_frames = (unsigned) (urb->number_of_packets*urb->interval);
if ( number_of_frames > 900)
return -EFBIG; return -EFBIG;
limits = find_iso_limits (uhci, urb, &start_limit, &stop_limit); limits = find_iso_limits (uhci, urb, &start_limit, &stop_limit);
...@@ -415,17 +415,17 @@ static int iso_find_start (struct uhci_hcd *uhci, struct urb *urb) ...@@ -415,17 +415,17 @@ static int iso_find_start (struct uhci_hcd *uhci, struct urb *urb)
else { else {
urb->start_frame = stop_limit; // seamless linkage urb->start_frame = stop_limit; // seamless linkage
if (((now - urb->start_frame) & 1023) <= (unsigned) urb->number_of_packets) { if (((now - urb->start_frame) & 1023) <= (unsigned) number_of_frames) {
info("iso_find_start: gap in seamless isochronous scheduling"); info("iso_find_start: gap in seamless isochronous scheduling");
dbg("iso_find_start: now %u start_frame %u number_of_packets %u pipe 0x%08x", dbg("iso_find_start: now %u start_frame %u number_of_packets %u interval %u pipe 0x%08x",
now, urb->start_frame, urb->number_of_packets, urb->pipe); now, urb->start_frame, urb->number_of_packets, urb->interval, urb->pipe);
urb->start_frame = (now + 5) & 1023; // 5ms setup should be enough urb->start_frame = (now + 5) & 1023; // 5ms setup should be enough
} }
} }
} }
else { else {
urb->start_frame &= 1023; urb->start_frame &= 1023;
if (((now - urb->start_frame) & 1023) < (unsigned) urb->number_of_packets) { if (((now - urb->start_frame) & 1023) < number_of_frames) {
dbg("iso_find_start: now between start_frame and end"); dbg("iso_find_start: now between start_frame and end");
return -EAGAIN; return -EAGAIN;
} }
...@@ -436,7 +436,7 @@ static int iso_find_start (struct uhci_hcd *uhci, struct urb *urb) ...@@ -436,7 +436,7 @@ static int iso_find_start (struct uhci_hcd *uhci, struct urb *urb)
return 0; return 0;
if (((urb->start_frame - start_limit) & 1023) < queued_size || if (((urb->start_frame - start_limit) & 1023) < queued_size ||
((urb->start_frame + urb->number_of_packets - 1 - start_limit) & 1023) < queued_size) { ((urb->start_frame + number_of_frames - 1 - start_limit) & 1023) < queued_size) {
dbg("iso_find_start: start_frame %u number_of_packets %u start_limit %u stop_limit %u", dbg("iso_find_start: start_frame %u number_of_packets %u start_limit %u stop_limit %u",
urb->start_frame, urb->number_of_packets, start_limit, stop_limit); urb->start_frame, urb->number_of_packets, start_limit, stop_limit);
return -EAGAIN; return -EAGAIN;
...@@ -507,7 +507,7 @@ static int uhci_submit_iso_urb (struct uhci_hcd *uhci, struct urb *urb, int mem_ ...@@ -507,7 +507,7 @@ static int uhci_submit_iso_urb (struct uhci_hcd *uhci, struct urb *urb, int mem_
urb_priv->transfer_buffer_dma + urb->iso_frame_desc[n].offset); urb_priv->transfer_buffer_dma + urb->iso_frame_desc[n].offset);
list_add_tail (&td->desc_list, &urb_priv->desc_list); list_add_tail (&td->desc_list, &urb_priv->desc_list);
insert_td_horizontal (uhci, uhci->iso_td[(urb->start_frame + n) & 1023], td); // store in iso-tds insert_td_horizontal (uhci, uhci->iso_td[(urb->start_frame + n*urb->interval) & 1023], td); // store in iso-tds
} }
kfree (tdm); kfree (tdm);
...@@ -742,6 +742,7 @@ static int uhci_unlink_urb_async (struct uhci_hcd *uhci, struct urb *urb, int mo ...@@ -742,6 +742,7 @@ static int uhci_unlink_urb_async (struct uhci_hcd *uhci, struct urb *urb, int mo
switch (usb_pipetype (urb->pipe)) { switch (usb_pipetype (urb->pipe)) {
case PIPE_INTERRUPT: case PIPE_INTERRUPT:
urb_priv->flags = 0; // mark as deleted (if called from completion)
uhci_do_toggle (urb); uhci_do_toggle (urb);
case PIPE_ISOCHRONOUS: case PIPE_ISOCHRONOUS:
...@@ -853,12 +854,9 @@ static void uhci_check_timeouts(struct uhci_hcd *uhci) ...@@ -853,12 +854,9 @@ static void uhci_check_timeouts(struct uhci_hcd *uhci)
async_dbg("uhci_check_timeout: timeout for %p",urb); async_dbg("uhci_check_timeout: timeout for %p",urb);
uhci_unlink_urb_async(uhci, urb, UNLINK_ASYNC_STORE_URB); uhci_unlink_urb_async(uhci, urb, UNLINK_ASYNC_STORE_URB);
} }
#ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH else if (high_bw && ((type == PIPE_BULK) || (type == PIPE_CONTROL)) &&
else if (((type == PIPE_BULK) || (type == PIPE_CONTROL)) &&
(hcpriv->use_loop) && time_after(jiffies, hcpriv->started + IDLE_TIMEOUT)) (hcpriv->use_loop) && time_after(jiffies, hcpriv->started + IDLE_TIMEOUT))
disable_desc_loop(uhci, urb); disable_desc_loop(uhci, urb);
#endif
} }
uhci->timeout_check=jiffies; uhci->timeout_check=jiffies;
} }
...@@ -1040,9 +1038,8 @@ static int process_transfer (struct uhci_hcd *uhci, struct urb *urb, int mode) ...@@ -1040,9 +1038,8 @@ static int process_transfer (struct uhci_hcd *uhci, struct urb *urb, int mode)
uhci_clean_transfer(uhci, urb, qh, mode); uhci_clean_transfer(uhci, urb, qh, mode);
urb->status = status; urb->status = status;
#ifdef CONFIG_USB_UHCI_HIGH_BANDWIDTH if (high_bw)
disable_desc_loop(uhci,urb); disable_desc_loop(uhci,urb);
#endif
dbg("process_transfer: (end) urb %p, wanted len %d, len %d status %x err %d", dbg("process_transfer: (end) urb %p, wanted len %d, len %d status %x err %d",
urb,urb->transfer_buffer_length,urb->actual_length, urb->status, urb->error_count); urb,urb->transfer_buffer_length,urb->actual_length, urb->status, urb->error_count);
...@@ -1088,21 +1085,19 @@ static int process_interrupt (struct uhci_hcd *uhci, struct urb *urb, int mode) ...@@ -1088,21 +1085,19 @@ static int process_interrupt (struct uhci_hcd *uhci, struct urb *urb, int mode)
urb->actual_length = actual_length; urb->actual_length = actual_length;
recycle: recycle:
((urb_priv_t*)urb->hcpriv)->flags=1; // set to detect unlink during completion
uhci_urb_dma_sync(uhci, urb, urb->hcpriv); uhci_urb_dma_sync(uhci, urb, urb->hcpriv);
if (urb->complete) { if (urb->complete) {
//dbg("process_interrupt: calling completion, status %i",status); //dbg("process_interrupt: calling completion, status %i",status);
urb->status = status; urb->status = status;
((urb_priv_t*)urb->hcpriv)->flags=1; // if unlink_urb is called during completion
spin_unlock(&uhci->urb_list_lock); spin_unlock(&uhci->urb_list_lock);
urb->complete ((struct urb *) urb); urb->complete ((struct urb *) urb);
spin_lock(&uhci->urb_list_lock); spin_lock(&uhci->urb_list_lock);
((urb_priv_t*)urb->hcpriv)->flags=0; // FIXME: unlink in completion not handled...
} }
if ((urb->status != -ECONNABORTED) && (urb->status != ECONNRESET) && if ((urb->status != -ECONNABORTED) && (urb->status != ECONNRESET) &&
(urb->status != -ENOENT)) { (urb->status != -ENOENT) && ((urb_priv_t*)urb->hcpriv)->flags) {
urb->status = -EINPROGRESS; urb->status = -EINPROGRESS;
...@@ -1125,7 +1120,7 @@ static int process_interrupt (struct uhci_hcd *uhci, struct urb *urb, int mode) ...@@ -1125,7 +1120,7 @@ static int process_interrupt (struct uhci_hcd *uhci, struct urb *urb, int mode)
mb(); mb();
} }
else { else {
uhci_unlink_urb_async(uhci, urb, UNLINK_ASYNC_STORE_URB); uhci_unlink_urb_async(uhci, urb, UNLINK_ASYNC_STORE_URB);
uhci_do_toggle (urb); // correct toggle after unlink uhci_do_toggle (urb); // correct toggle after unlink
clr_td_ioc(desc); // inactivate TD clr_td_ioc(desc); // inactivate TD
} }
...@@ -1199,7 +1194,6 @@ static int process_iso (struct uhci_hcd *uhci, struct urb *urb, int mode) ...@@ -1199,7 +1194,6 @@ static int process_iso (struct uhci_hcd *uhci, struct urb *urb, int mode)
p_tmp = p; p_tmp = p;
p = p->next; p = p->next;
list_del (p_tmp); list_del (p_tmp);
// delete_desc (uhci, desc);
// add to cool down pool // add to cool down pool
INIT_LIST_HEAD(&desc->horizontal); INIT_LIST_HEAD(&desc->horizontal);
...@@ -1243,19 +1237,18 @@ static int process_urb (struct uhci_hcd *uhci, struct list_head *p) ...@@ -1243,19 +1237,18 @@ static int process_urb (struct uhci_hcd *uhci, struct list_head *p)
break; break;
} }
if (urb->status != -EINPROGRESS) { if (urb->status != -EINPROGRESS && type != PIPE_INTERRUPT) {
dequeue_urb (uhci, urb); dequeue_urb (uhci, urb);
uhci_free_priv(uhci, urb, urb->hcpriv);
uhci_free_priv(uhci, urb, urb->hcpriv); spin_unlock(&uhci->urb_list_lock);
dbg("giveback urb %p, status %i, length %i\n",
urb, urb->status, urb->transfer_buffer_length);
usb_hcd_giveback_urb(&uhci->hcd, urb);
spin_lock(&uhci->urb_list_lock);
if (type != PIPE_INTERRUPT) { // process_interrupt does completion on its own
spin_unlock(&uhci->urb_list_lock);
dbg("giveback urb %p, status %i, length %i\n",
urb, urb->status, urb->transfer_buffer_length);
usb_hcd_giveback_urb(&uhci->hcd, urb);
spin_lock(&uhci->urb_list_lock);
}
} }
return ret; return ret;
} }
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* $Id: debug.h,v 1.6 2001/01/12 23:51:04 mdharm Exp $ * $Id: debug.h,v 1.6 2001/01/12 23:51:04 mdharm Exp $
* *
* Current development and maintenance by: * Current development and maintenance by:
* (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
* *
* Initial work by: * Initial work by:
* (c) 1999 Michael Gee (michael@linuxspecific.com) * (c) 1999 Michael Gee (michael@linuxspecific.com)
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* $Id: scsiglue.c,v 1.26 2002/04/22 03:39:43 mdharm Exp $ * $Id: scsiglue.c,v 1.26 2002/04/22 03:39:43 mdharm Exp $
* *
* Current development and maintenance by: * Current development and maintenance by:
* (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
* *
* Developed with the assistance of: * Developed with the assistance of:
* (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org) * (c) 2000 David L. Brown, Jr. (usb-storage@davidb.org)
...@@ -56,9 +56,6 @@ ...@@ -56,9 +56,6 @@
*/ */
#define US_ACT_COMMAND 1 #define US_ACT_COMMAND 1
#define US_ACT_DEVICE_RESET 2
#define US_ACT_BUS_RESET 3
#define US_ACT_HOST_RESET 4
#define US_ACT_EXIT 5 #define US_ACT_EXIT 5
/*********************************************************************** /***********************************************************************
......
...@@ -351,6 +351,29 @@ unsigned int usb_stor_transfer_length(Scsi_Cmnd *srb) ...@@ -351,6 +351,29 @@ unsigned int usb_stor_transfer_length(Scsi_Cmnd *srb)
* Data transfer routines * Data transfer routines
***********************************************************************/ ***********************************************************************/
/*
* This is subtle, so pay attention:
* ---------------------------------
* We're very concered about races with a command abort. Hanging this code is
* a sure fire way to hang the kernel.
*
* The abort function first sets the machine state, then tries to acquire the
* lock on the current_urb to abort it.
*
* Once a function grabs the current_urb_sem, then it -MUST- test the state to
* see if we just got aborted before the lock was grabbed. If so, it's
* essential to release the lock and return.
*
* The idea is that, once the current_urb_sem is held, the state can't really
* change anymore without also engaging the usb_unlink_urb() call _after_ the
* URB is actually submitted.
*
* So, we've guaranteed that (after the sm_state test), if we do submit the
* URB it will get aborted when we release the current_urb_sem. And we've
* also guaranteed that if the abort code was called before we held the
* current_urb_sem, we can safely get out before the URB is submitted.
*/
/* This is the completion handler which will wake us up when an URB /* This is the completion handler which will wake us up when an URB
* completes. * completes.
*/ */
...@@ -363,6 +386,9 @@ static void usb_stor_blocking_completion(struct urb *urb) ...@@ -363,6 +386,9 @@ static void usb_stor_blocking_completion(struct urb *urb)
/* This is the common part of the URB message submission code /* This is the common part of the URB message submission code
* This function expects the current_urb_sem to be held upon entry. * This function expects the current_urb_sem to be held upon entry.
*
* All URBs from the usb-storage driver _must_ pass through this function
* (or something like it) for the abort mechanisms to work properly.
*/ */
static int usb_stor_msg_common(struct us_data *us) static int usb_stor_msg_common(struct us_data *us)
{ {
...@@ -385,16 +411,6 @@ static int usb_stor_msg_common(struct us_data *us) ...@@ -385,16 +411,6 @@ static int usb_stor_msg_common(struct us_data *us)
return status; return status;
} }
/* has the current command been aborted? */
if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
/* avoid a race with usb_stor_abort_transport():
* if the abort took place before we submitted
* the URB, we must cancel it ourselves */
if (us->current_urb->status == -EINPROGRESS)
usb_unlink_urb(us->current_urb);
}
/* wait for the completion of the URB */ /* wait for the completion of the URB */
up(&(us->current_urb_sem)); up(&(us->current_urb_sem));
wait_for_completion(&urb_done); wait_for_completion(&urb_done);
...@@ -428,9 +444,15 @@ int usb_stor_control_msg(struct us_data *us, unsigned int pipe, ...@@ -428,9 +444,15 @@ int usb_stor_control_msg(struct us_data *us, unsigned int pipe,
/* lock the URB */ /* lock the URB */
down(&(us->current_urb_sem)); down(&(us->current_urb_sem));
/* has the current command been aborted? */
if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
up(&(us->current_urb_sem));
return 0;
}
/* fill the URB */ /* fill the URB */
FILL_CONTROL_URB(us->current_urb, us->pusb_dev, pipe, FILL_CONTROL_URB(us->current_urb, us->pusb_dev, pipe,
(unsigned char*) &dr, data, size, (unsigned char*) dr, data, size,
usb_stor_blocking_completion, NULL); usb_stor_blocking_completion, NULL);
/* submit the URB */ /* submit the URB */
...@@ -456,6 +478,12 @@ int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe, ...@@ -456,6 +478,12 @@ int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe,
/* lock the URB */ /* lock the URB */
down(&(us->current_urb_sem)); down(&(us->current_urb_sem));
/* has the current command been aborted? */
if (atomic_read(&us->sm_state) == US_STATE_ABORTING) {
up(&(us->current_urb_sem));
return 0;
}
/* fill the URB */ /* fill the URB */
FILL_BULK_URB(us->current_urb, us->pusb_dev, pipe, data, len, FILL_BULK_URB(us->current_urb, us->pusb_dev, pipe, data, len,
usb_stor_blocking_completion, NULL); usb_stor_blocking_completion, NULL);
...@@ -473,7 +501,15 @@ int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe, ...@@ -473,7 +501,15 @@ int usb_stor_bulk_msg(struct us_data *us, void *data, int pipe,
/* This is a version of usb_clear_halt() that doesn't read the status from /* This is a version of usb_clear_halt() that doesn't read the status from
* the device -- this is because some devices crash their internal firmware * the device -- this is because some devices crash their internal firmware
* when the status is requested after a halt * when the status is requested after a halt.
*
* A definitive list of these 'bad' devices is too difficult to maintain or
* make complete enough to be useful. This problem was first observed on the
* Hagiwara FlashGate DUAL unit. However, bus traces reveal that neither
* MacOS nor Windows checks the status after clearing a halt.
*
* Since many vendors in this space limit their testing to interoperability
* with these two OSes, specification violations like this one are common.
*/ */
int usb_stor_clear_halt(struct us_data *us, int pipe) int usb_stor_clear_halt(struct us_data *us, int pipe)
{ {
...@@ -823,24 +859,31 @@ void usb_stor_abort_transport(struct us_data *us) ...@@ -823,24 +859,31 @@ void usb_stor_abort_transport(struct us_data *us)
/* If the current state is wrong or if there's /* If the current state is wrong or if there's
* no srb, then there's nothing to do */ * no srb, then there's nothing to do */
if ( !(state == US_STATE_RUNNING || state == US_STATE_RESETTING) BUG_ON((state != US_STATE_RUNNING && state != US_STATE_RESETTING));
|| !us->srb) { BUG_ON(!(us->srb));
US_DEBUGP("-- invalid current state\n");
return; /* set state to abort */
}
atomic_set(&us->sm_state, US_STATE_ABORTING); atomic_set(&us->sm_state, US_STATE_ABORTING);
/* If the state machine is blocked waiting for an URB or an IRQ, /* If the state machine is blocked waiting for an URB or an IRQ,
* let's wake it up */ * let's wake it up */
/* if we have an URB pending, cancel it */ /* If we have an URB pending, cancel it. Note that we guarantee with
* the current_urb_sem that either (a) an URB has just been submitted,
* or (b) the URB will never get submitted. But, because of the use
* of us->sm_state and current_urb_sem, we can't get an URB sumbitted
* _after_ we set the state to US_STATE_ABORTING and this section of
* code runs. Thus we avoid deadlocks.
*/
down(&(us->current_urb_sem));
if (us->current_urb->status == -EINPROGRESS) { if (us->current_urb->status == -EINPROGRESS) {
US_DEBUGP("-- cancelling URB\n"); US_DEBUGP("-- cancelling URB\n");
usb_unlink_urb(us->current_urb); usb_unlink_urb(us->current_urb);
} }
up(&(us->current_urb_sem));
/* if we are waiting for an IRQ, simulate it */ /* If we are waiting for an IRQ, simulate it */
else if (test_bit(IP_WANTED, &us->bitflags)) { if (test_bit(IP_WANTED, &us->bitflags)) {
US_DEBUGP("-- simulating missing IRQ\n"); US_DEBUGP("-- simulating missing IRQ\n");
usb_stor_CBI_irq(us->irq_urb); usb_stor_CBI_irq(us->irq_urb);
} }
......
...@@ -104,9 +104,6 @@ static int my_host_number; ...@@ -104,9 +104,6 @@ static int my_host_number;
*/ */
#define US_ACT_COMMAND 1 #define US_ACT_COMMAND 1
#define US_ACT_DEVICE_RESET 2
#define US_ACT_BUS_RESET 3
#define US_ACT_HOST_RESET 4
#define US_ACT_EXIT 5 #define US_ACT_EXIT 5
/* The list of structures and the protective lock for them */ /* The list of structures and the protective lock for them */
...@@ -344,10 +341,12 @@ static int usb_stor_control_thread(void * __us) ...@@ -344,10 +341,12 @@ static int usb_stor_control_thread(void * __us)
for(;;) { for(;;) {
struct Scsi_Host *host; struct Scsi_Host *host;
US_DEBUGP("*** thread sleeping.\n"); US_DEBUGP("*** thread sleeping.\n");
atomic_set(&us->sm_state, US_STATE_IDLE);
if(down_interruptible(&us->sema)) if(down_interruptible(&us->sema))
break; break;
US_DEBUGP("*** thread awakened.\n"); US_DEBUGP("*** thread awakened.\n");
atomic_set(&us->sm_state, US_STATE_RUNNING);
/* lock access to the queue element */ /* lock access to the queue element */
spin_lock_irq(&us->queue_exclusion); spin_lock_irq(&us->queue_exclusion);
...@@ -361,145 +360,131 @@ static int usb_stor_control_thread(void * __us) ...@@ -361,145 +360,131 @@ static int usb_stor_control_thread(void * __us)
/* release the queue lock as fast as possible */ /* release the queue lock as fast as possible */
spin_unlock_irq(&us->queue_exclusion); spin_unlock_irq(&us->queue_exclusion);
switch (action) { /* exit if we get a signal to exit */
case US_ACT_COMMAND: if (action == US_ACT_EXIT) {
/* reject the command if the direction indicator US_DEBUGP("-- US_ACT_EXIT command received\n");
* is UNKNOWN break;
*/ }
if (us->srb->sc_data_direction == SCSI_DATA_UNKNOWN) {
US_DEBUGP("UNKNOWN data direction\n");
us->srb->result = DID_ERROR << 16;
scsi_lock(host);
us->srb->scsi_done(us->srb);
us->srb = NULL;
scsi_unlock(host);
break;
}
/* reject if target != 0 or if LUN is higher than BUG_ON(action != US_ACT_COMMAND);
* the maximum known LUN
*/
if (us->srb->target &&
!(us->flags & US_FL_SCM_MULT_TARG)) {
US_DEBUGP("Bad target number (%d/%d)\n",
us->srb->target, us->srb->lun);
us->srb->result = DID_BAD_TARGET << 16;
scsi_lock(host);
us->srb->scsi_done(us->srb);
us->srb = NULL;
scsi_unlock(host);
break;
}
if (us->srb->lun > us->max_lun) { /* reject the command if the direction indicator
US_DEBUGP("Bad LUN (%d/%d)\n", * is UNKNOWN
us->srb->target, us->srb->lun); */
us->srb->result = DID_BAD_TARGET << 16; if (us->srb->sc_data_direction == SCSI_DATA_UNKNOWN) {
US_DEBUGP("UNKNOWN data direction\n");
us->srb->result = DID_ERROR << 16;
scsi_lock(host);
us->srb->scsi_done(us->srb);
us->srb = NULL;
scsi_unlock(host);
continue;
}
scsi_lock(host); /* reject if target != 0 or if LUN is higher than
us->srb->scsi_done(us->srb); * the maximum known LUN
us->srb = NULL; */
scsi_unlock(host); if (us->srb->target &&
break; !(us->flags & US_FL_SCM_MULT_TARG)) {
} US_DEBUGP("Bad target number (%d/%d)\n",
us->srb->target, us->srb->lun);
us->srb->result = DID_BAD_TARGET << 16;
scsi_lock(host);
us->srb->scsi_done(us->srb);
us->srb = NULL;
scsi_unlock(host);
continue;
}
/* handle those devices which can't do a START_STOP */ if (us->srb->lun > us->max_lun) {
if ((us->srb->cmnd[0] == START_STOP) && US_DEBUGP("Bad LUN (%d/%d)\n",
(us->flags & US_FL_START_STOP)) { us->srb->target, us->srb->lun);
US_DEBUGP("Skipping START_STOP command\n"); us->srb->result = DID_BAD_TARGET << 16;
us->srb->result = GOOD << 1;
scsi_lock(host); scsi_lock(host);
us->srb->scsi_done(us->srb); us->srb->scsi_done(us->srb);
us->srb = NULL; us->srb = NULL;
scsi_unlock(host); scsi_unlock(host);
break; continue;
} }
/* lock the device pointers */ /* handle those devices which can't do a START_STOP */
down(&(us->dev_semaphore)); if ((us->srb->cmnd[0] == START_STOP) &&
(us->flags & US_FL_START_STOP)) {
/* our device has gone - pretend not ready */ US_DEBUGP("Skipping START_STOP command\n");
if (atomic_read(&us->sm_state) == US_STATE_DETACHED) { us->srb->result = GOOD << 1;
US_DEBUGP("Request is for removed device\n");
/* For REQUEST_SENSE, it's the data. But scsi_lock(host);
* for anything else, it should look like us->srb->scsi_done(us->srb);
* we auto-sensed for it. us->srb = NULL;
*/ scsi_unlock(host);
if (us->srb->cmnd[0] == REQUEST_SENSE) { continue;
memcpy(us->srb->request_buffer, }
usb_stor_sense_notready,
sizeof(usb_stor_sense_notready));
us->srb->result = GOOD << 1;
} else if(us->srb->cmnd[0] == INQUIRY) {
unsigned char data_ptr[36] = {
0x20, 0x80, 0x02, 0x02,
0x1F, 0x00, 0x00, 0x00};
US_DEBUGP("Faking INQUIRY command for disconnected device\n");
fill_inquiry_response(us, data_ptr, 36);
us->srb->result = GOOD << 1;
} else {
memcpy(us->srb->sense_buffer,
usb_stor_sense_notready,
sizeof(usb_stor_sense_notready));
us->srb->result = CHECK_CONDITION << 1;
}
} else { /* atomic_read(&us->sm_state) == STATE_DETACHED */
/* Handle those devices which need us to fake
* their inquiry data */
if ((us->srb->cmnd[0] == INQUIRY) &&
(us->flags & US_FL_FIX_INQUIRY)) {
unsigned char data_ptr[36] = {
0x00, 0x80, 0x02, 0x02,
0x1F, 0x00, 0x00, 0x00};
US_DEBUGP("Faking INQUIRY command\n");
fill_inquiry_response(us, data_ptr, 36);
us->srb->result = GOOD << 1;
} else {
/* we've got a command, let's do it! */
US_DEBUG(usb_stor_show_command(us->srb));
atomic_set(&us->sm_state, US_STATE_RUNNING);
us->proto_handler(us->srb, us);
atomic_set(&us->sm_state, US_STATE_IDLE);
}
}
/* unlock the device pointers */ /* lock the device pointers */
up(&(us->dev_semaphore)); down(&(us->dev_semaphore));
/* indicate that the command is done */ /* our device has gone - pretend not ready */
if (us->srb->result != DID_ABORT << 16) { if (atomic_read(&us->device_state) == US_STATE_DETACHED) {
US_DEBUGP("scsi cmd done, result=0x%x\n", US_DEBUGP("Request is for removed device\n");
us->srb->result); /* For REQUEST_SENSE, it's the data. But
scsi_lock(host); * for anything else, it should look like
us->srb->scsi_done(us->srb); * we auto-sensed for it.
us->srb = NULL; */
scsi_unlock(host); if (us->srb->cmnd[0] == REQUEST_SENSE) {
memcpy(us->srb->request_buffer,
usb_stor_sense_notready,
sizeof(usb_stor_sense_notready));
us->srb->result = GOOD << 1;
} else if(us->srb->cmnd[0] == INQUIRY) {
unsigned char data_ptr[36] = {
0x20, 0x80, 0x02, 0x02,
0x1F, 0x00, 0x00, 0x00};
US_DEBUGP("Faking INQUIRY command for disconnected device\n");
fill_inquiry_response(us, data_ptr, 36);
us->srb->result = GOOD << 1;
} else { } else {
US_DEBUGP("scsi command aborted\n"); memcpy(us->srb->sense_buffer,
us->srb = NULL; usb_stor_sense_notready,
complete(&(us->notify)); sizeof(usb_stor_sense_notready));
us->srb->result = CHECK_CONDITION << 1;
} }
break; } else { /* atomic_read(&us->device_state) == STATE_DETACHED */
case US_ACT_DEVICE_RESET: /* Handle those devices which need us to fake
break; * their inquiry data */
if ((us->srb->cmnd[0] == INQUIRY) &&
case US_ACT_BUS_RESET: (us->flags & US_FL_FIX_INQUIRY)) {
break; unsigned char data_ptr[36] = {
0x00, 0x80, 0x02, 0x02,
case US_ACT_HOST_RESET: 0x1F, 0x00, 0x00, 0x00};
break;
US_DEBUGP("Faking INQUIRY command\n");
} /* end switch on action */ fill_inquiry_response(us, data_ptr, 36);
us->srb->result = GOOD << 1;
} else {
/* we've got a command, let's do it! */
US_DEBUG(usb_stor_show_command(us->srb));
us->proto_handler(us->srb, us);
}
}
/* exit if we get a signal to exit */ /* unlock the device pointers */
if (action == US_ACT_EXIT) { up(&(us->dev_semaphore));
US_DEBUGP("-- US_ACT_EXIT command received\n");
break; /* indicate that the command is done */
if (us->srb->result != DID_ABORT << 16) {
US_DEBUGP("scsi cmd done, result=0x%x\n",
us->srb->result);
scsi_lock(host);
us->srb->scsi_done(us->srb);
us->srb = NULL;
scsi_unlock(host);
} else {
US_DEBUGP("scsi command aborted\n");
us->srb = NULL;
complete(&(us->notify));
} }
} /* for (;;) */ } /* for (;;) */
...@@ -725,7 +710,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -725,7 +710,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
/* establish the connection to the new device upon reconnect */ /* establish the connection to the new device upon reconnect */
ss->ifnum = ifnum; ss->ifnum = ifnum;
ss->pusb_dev = dev; ss->pusb_dev = dev;
atomic_set(&ss->sm_state, US_STATE_IDLE); atomic_set(&ss->device_state, US_STATE_ATTACHED);
/* copy over the endpoint data */ /* copy over the endpoint data */
if (ep_in) if (ep_in)
...@@ -1016,6 +1001,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum, ...@@ -1016,6 +1001,7 @@ static void * storage_probe(struct usb_device *dev, unsigned int ifnum,
/* start up our control thread */ /* start up our control thread */
atomic_set(&ss->sm_state, US_STATE_IDLE); atomic_set(&ss->sm_state, US_STATE_IDLE);
atomic_set(&ss->device_state, US_STATE_ATTACHED);
ss->pid = kernel_thread(usb_stor_control_thread, ss, ss->pid = kernel_thread(usb_stor_control_thread, ss,
CLONE_VM); CLONE_VM);
if (ss->pid < 0) { if (ss->pid < 0) {
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
* $Id: usb.h,v 1.21 2002/04/21 02:57:59 mdharm Exp $ * $Id: usb.h,v 1.21 2002/04/21 02:57:59 mdharm Exp $
* *
* Current development and maintenance by: * Current development and maintenance by:
* (c) 1999, 2000 Matthew Dharm (mdharm-usb@one-eyed-alien.net) * (c) 1999-2002 Matthew Dharm (mdharm-usb@one-eyed-alien.net)
* *
* Initial work by: * Initial work by:
* (c) 1999 Michael Gee (michael@linuxspecific.com) * (c) 1999 Michael Gee (michael@linuxspecific.com)
...@@ -103,11 +103,15 @@ struct us_unusual_dev { ...@@ -103,11 +103,15 @@ struct us_unusual_dev {
#define US_FL_SCM_MULT_TARG 0x00000020 /* supports multiple targets */ #define US_FL_SCM_MULT_TARG 0x00000020 /* supports multiple targets */
#define US_FL_FIX_INQUIRY 0x00000040 /* INQUIRY response needs fixing */ #define US_FL_FIX_INQUIRY 0x00000040 /* INQUIRY response needs fixing */
#define US_STATE_DETACHED 1 /* State machine states */ /* device attached/detached states */
#define US_STATE_IDLE 2 #define US_STATE_DETACHED 1
#define US_STATE_RUNNING 3 #define US_STATE_ATTACHED 2
#define US_STATE_RESETTING 4
#define US_STATE_ABORTING 5 /* processing state machine states */
#define US_STATE_IDLE 1
#define US_STATE_RUNNING 2
#define US_STATE_RESETTING 3
#define US_STATE_ABORTING 4
#define USB_STOR_STRING_LEN 32 #define USB_STOR_STRING_LEN 32
...@@ -120,8 +124,13 @@ typedef void (*extra_data_destructor)(void *); /* extra data destructor */ ...@@ -120,8 +124,13 @@ typedef void (*extra_data_destructor)(void *); /* extra data destructor */
struct us_data { struct us_data {
struct us_data *next; /* next device */ struct us_data *next; /* next device */
/* the device we're working with */ /* The device we're working with
* It's important to note:
* (o) you must hold dev_semaphore to change pusb_dev
* (o) device_state should change whenever pusb_dev does
*/
struct semaphore dev_semaphore; /* protect pusb_dev */ struct semaphore dev_semaphore; /* protect pusb_dev */
atomic_t device_state; /* attached or detached */
struct usb_device *pusb_dev; /* this usb_device */ struct usb_device *pusb_dev; /* this usb_device */
unsigned int flags; /* from filter initially */ unsigned int flags; /* from filter initially */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment