Huge merge from NetBSD:

usbdi.c (1.61):
	===================================================================
	revision 1.61
	date: 2000/01/31 20:13:07;  author: augustss;  lines: +20 -4
	Change the way the HC done method is invoked a little.
	===================================================================

usbdi.c (1.65):
	===================================================================
	revision 1.65
	date: 2000/03/08 15:34:10;  author: augustss;  lines: +4 -2
	Get the status right when a polled transfer times out.
	===================================================================

ohci.c (1.79), uhci.c (1.89), uhcivar.h (1.24), usb_port.h (1.22),
usbdivar.h (1.48):
	===================================================================
	date: 2000/03/23 07:01:46;  author: thorpej;
	New callout mechanism with two major improvements over the old
	timeout()/untimeout() API:
	- Clients supply callout handle storage, thus eliminating problems of
	  resource allocation.
	- Insertion and removal of callouts is constant time, important as
	  this facility is used quite a lot in the kernel.

	The old timeout()/untimeout() API has been removed from the kernel.
	===================================================================

uhci.c (1.80), usbdi.c (1.66):
	===================================================================
	date: 2000/03/23 18:59:10;  author: thorpej;
	Shake out some bugs from the callout changes.
	===================================================================

ohci.c (1.80), uhci.c (1.91), uhcivar.h (1.25), usb_port.h (1.23),
usbdi.c (1.67), usbdivar.h (1.49):
	===================================================================
	date: 2000/03/24 22:03:30;  author: augustss;
	Some cleanup and renaming of the callouts used in USB drivers.
	===================================================================

uhci.c (1.92), uhcivar.h (1.26):
	===================================================================
	date: 2000/03/24 22:57:58;  author: augustss;
	Two major changes:

	  Make each xfer have its own intr_info.  This is necessary if we want
	  to queue multiple xfers on an endpoint.  This should get rid of the
	  (mostly harmless) DIAGNOSTICs about intr_infos (not) being done.

	  Change (again!) how xfers are aborted.  Aborting a TD is a nightmare
	  on the braindead UHCI controller.  (Unless you stop the HC, thereby
	  losing isoc traffic.)  Hopefully I got it right this time.
	===================================================================

usbdivar.h (1.50):
	===================================================================
	revision 1.50
	date: 2000/03/25 00:10:19;  author: augustss;  lines: +4 -2
	GC an unsued field and add some DIAGNOSTIC in xfer.
	===================================================================

ums.c: Use the callout functions instead of the timeout ones.

uhci.c (1.93):
	===================================================================
	revision 1.93
	date: 2000/03/25 00:11:21;  author: augustss;
	lines: +26 -1
	Add more DIAGNOSTIC when aborting isoc.
	===================================================================

uhci.c (1.94), usbdivar.h (1.51):
	===================================================================
	date: 2000/03/25 07:13:05;  author: augustss;
	More DIAGNOSTIC.
	Initialize a callout handle I forgot.
	===================================================================

uhci.c (1.95):
	===================================================================
	revision 1.95
	date: 2000/03/25 07:23:12;  author: augustss;
	Exp;  lines: +24 -7
	Improve uhci_dump_ii().
	===================================================================

ohci.c (1.81), uhci.c (1.96), uhcivar.h (1.27), usb_subr.c (1.68),
usbdi.c (1.68), usbdivar.h (1.52):
	===================================================================
	date: 2000/03/25 18:02:33;  author: augustss;
	Rename and move around callout handles to make it more sane.
	Add some DIAGNOSTIC.
	Fix buglet in isoc abort on UHCI.
	===================================================================

uhci.c (1.98):
	===================================================================
	revision 1.98
	date: 2000/03/27 07:39:48;  author: augustss;  lines: +12 -4
	Make it compile without DIAGNOSTIC.
	===================================================================

uhci.c (1.99):
	===================================================================
	revision 1.99
	date: 2000/03/27 08:01:09;  author: augustss;  lines: +1 -5
	Remove some debug nonsense.
	===================================================================

uhci.c (1.100):
	===================================================================
	revision 1.100
	date: 2000/03/27 09:41:36;  author: augustss;  lines: +13 -3
	Don't mess with QH in bulk abort for the moment.
	===================================================================

uhci.c (1.102):
	===================================================================
	revision 1.102
	date: 2000/03/27 22:42:57;  author: augustss;  lines: +66 -26
	Be a little more careful when aborting.
	Preallocate some TDs for large buffers.
	===================================================================

uhci.c (1.103):
	===================================================================
	date: 2000/03/28 09:47:10;  author: augustss;  lines: +11 -1
	Another patch for xfer abort...
	XXX The current xfer queueing and aborting semantics should really
	XXX be changed.  It cannot be implemented in a sane way on UHCI.
	XXX One day when I have lots of time I'll redesign it...
	===================================================================

uhci.c (1.104): Correct a debug message.
uhci.c (1.105): Be more defensive in a DIAGNOSTIC test.

uhci.c (1.106):
	===================================================================
	revision 1.106
	date: 2000/03/29 01:49:13;  author: augustss;  lines: +14 -309
	*SIGH*  Revert back to the old method of aborting xfers.
	I had tested the new stuff for two months now, but as soon as I commited
	it the problems started to appear.  Murphy, no doubt...
	===================================================================

usb_subr.c (1.70), usbdi.c (1.71), usbdivar.h (1.53):
	===================================================================
	revision 1.70
	date: 2000/03/29 01:45:20;  author: augustss;  lines: +2 -1
	Do not accept new xfers for queuing while a pipe is aborting.
	===================================================================
This commit is contained in:
Josef Karthauser 2002-03-16 12:06:01 +00:00
parent a5b2e75d32
commit 5a11d73afa
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=92404
8 changed files with 368 additions and 293 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: ohci.c,v 1.74 2000/02/29 21:37:00 augustss Exp $ */
/* $NetBSD: ohci.c,v 1.81 2000/03/25 18:02:32 augustss Exp $ */
/* $FreeBSD$ */
/*
@ -1175,7 +1175,7 @@ ohci_softintr(struct usbd_bus *bus)
continue;
}
cc = OHCI_TD_GET_CC(le32toh(std->td.td_flags));
usb_untimeout(ohci_timeout, xfer, xfer->timo_handle);
usb_uncallout(xfer->timeout_handle, ohci_timeout, xfer);
if (xfer->status == USBD_CANCELLED ||
xfer->status == USBD_TIMEOUT) {
DPRINTF(("ohci_process_done: cancel/timeout, xfer=%p\n",
@ -1510,8 +1510,8 @@ ohci_device_request(usbd_xfer_handle xfer)
opipe->tail.td = tail;
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_CLF);
if (xfer->timeout && !sc->sc_bus.use_polling) {
usb_timeout(ohci_timeout, xfer,
MS_TO_TICKS(xfer->timeout), xfer->timo_handle);
usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
ohci_timeout, xfer);
}
splx(s);
@ -1700,6 +1700,7 @@ ohci_open(usbd_pipe_handle pipe)
DPRINTFN(1, ("ohci_open: pipe=%p, addr=%d, endpt=%d (%d)\n",
pipe, addr, ed->bEndpointAddress, sc->sc_addr));
if (addr == sc->sc_addr) {
switch (ed->bEndpointAddress) {
case USB_CONTROL_ENDPOINT:
@ -1844,7 +1845,7 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
xfer->status = status;
usb_untimeout(ohci_timeout, xfer, xfer->timo_handle);
usb_uncallout(xfer->timeout_handle, ohci_timeout, xfer);
sed = opipe->sed;
sed->ed.ed_flags |= htole32(OHCI_ED_SKIP); /* force hardware skip */
@ -1856,7 +1857,9 @@ ohci_abort_xfer(usbd_xfer_handle xfer, usbd_status status)
#if 1
if (xfer->device->bus->intr_context) {
/* We have no process context, so we can't use tsleep(). */
timeout(ohci_abort_xfer_end, xfer, hz / USB_FRAMES_PER_SECOND);
usb_callout(xfer->pipe->abort_handle,
hz / USB_FRAMES_PER_SECOND, ohci_abort_xfer_end, xfer);
} else {
#if defined(DIAGNOSTIC) && defined(__i386__) && defined(__FreeBSD__)
KASSERT(curthread->td_intr_nesting_level == 0,
@ -2527,8 +2530,8 @@ ohci_device_bulk_start(usbd_xfer_handle xfer)
sed->ed.ed_flags &= htole32(~OHCI_ED_SKIP);
OWRITE4(sc, OHCI_COMMAND_STATUS, OHCI_BLF);
if (xfer->timeout && !sc->sc_bus.use_polling) {
usb_timeout(ohci_timeout, xfer,
MS_TO_TICKS(xfer->timeout), xfer->timo_handle);
usb_callout(xfer->timeout_handle, MS_TO_TICKS(xfer->timeout),
ohci_timeout, xfer);
}
#if 0

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/* $NetBSD: uhcivar.h,v 1.22 2000/01/26 10:04:39 augustss Exp $ */
/* $NetBSD: uhcivar.h,v 1.27 2000/03/25 18:02:33 augustss Exp $ */
/* $FreeBSD$ */
/*
@ -75,14 +75,19 @@ typedef struct uhci_intr_info {
uhci_soft_td_t *stdstart;
uhci_soft_td_t *stdend;
LIST_ENTRY(uhci_intr_info) list;
#if defined(__FreeBSD__)
struct callout_handle timeout_handle;
#endif /* defined(__FreeBSD__) */
#ifdef DIAGNOSTIC
int isdone;
#endif
} uhci_intr_info_t;
struct uhci_xfer {
struct usbd_xfer xfer;
uhci_intr_info_t iinfo;
int curframe;
};
#define UXFER(xfer) ((struct uhci_xfer *)(xfer))
/*
* Extra information that we need for a TD.
*/
@ -109,8 +114,6 @@ struct uhci_soft_qh {
uhci_soft_td_t *elink; /* soft version of qh_elink */
uhci_physaddr_t physaddr; /* QH's physical address. */
int pos; /* Timeslot position */
uhci_intr_info_t *intr_info; /* Who to call on completion. */
/* XXX should try to shrink with 4 bytes to fit into 32 bytes */
};
/* See comment about UHCI_STD_SIZE. */
#define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
@ -170,11 +173,8 @@ typedef struct uhci_softc {
/* Info for the root hub interrupt channel. */
int sc_ival; /* time between root hub intrs */
usbd_xfer_handle sc_has_timo; /* root hub interrupt transfer */
char sc_vflock; /* for lock virtual frame list */
#define UHCI_HAS_LOCK 1
#define UHCI_WANT_LOCK 2
usbd_xfer_handle sc_intr_xfer; /* root hub interrupt transfer */
usb_callout_t sc_poll_handle;
char sc_vendor[16]; /* vendor string for root hub */
int sc_id_vendor; /* vendor ID for root hub */

View File

@ -97,7 +97,7 @@ struct ums_softc {
struct hid_location sc_loc_x, sc_loc_y, sc_loc_z;
struct hid_location *sc_loc_btn;
struct callout_handle timeout_handle; /* for spurious button ups */
usb_callout_t callout_handle; /* for spurious button ups */
int sc_enabled;
int sc_disconnected; /* device is gone */
@ -470,12 +470,11 @@ ums_intr(xfer, addr, status)
*/
if (sc->flags & UMS_SPUR_BUT_UP &&
dx == 0 && dy == 0 && dz == 0 && buttons == 0) {
usb_timeout(ums_add_to_queue_timeout, (void *) sc,
MS_TO_TICKS(50 /*msecs*/), sc->timeout_handle);
usb_callout(sc->callout_handle, MS_TO_TICKS(50 /*msecs*/),
ums_add_to_queue_timeout, (void *) sc);
} else {
usb_untimeout(ums_add_to_queue_timeout, (void *) sc,
sc->timeout_handle);
usb_uncallout(sc->callout_handle,
ums_add_to_queue_timeout, (void *) sc);
ums_add_to_queue(sc, dx, dy, dz, buttons);
}
}
@ -556,7 +555,7 @@ ums_enable(v)
sc->status.button = sc->status.obutton = 0;
sc->status.dx = sc->status.dy = sc->status.dz = 0;
callout_handle_init(&sc->timeout_handle);
callout_handle_init((struct callout_handle *)&sc->callout_handle);
/* Set up interrupt pipe. */
err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr,
@ -578,7 +577,7 @@ ums_disable(priv)
{
struct ums_softc *sc = priv;
usb_untimeout(ums_add_to_queue_timeout, sc, sc->timeout_handle);
usb_uncallout(sc->callout_handle, ums_add_to_queue_timeout, sc);
/* Disable interrupts. */
usbd_abort_pipe(sc->sc_intrpipe);

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb_port.h,v 1.15 1999/11/16 12:04:28 augustss Exp $ */
/* $NetBSD: usb_port.h,v 1.23 2000/03/24 22:03:32 augustss Exp $ */
/* $FreeBSD$ */
/*
@ -81,8 +81,10 @@ typedef struct device *device_ptr_t;
u_int offs; \
} usb_dma_t
#define usb_timeout(f, d, t, h) timeout((f), (d), (t))
#define usb_untimeout(f, d, h) untimeout((f), (d))
typedef struct callout usb_callout_t;
#define usb_callout_init(h) callout_handle_init(&(h))
#define usb_callout(h, t, f, d) ((h) = timeout((f), (d), (t)))
#define usb_uncallout(h, f, d) untimeout((f), (d))
#define logprintf printf
@ -203,8 +205,10 @@ typedef struct device device_ptr_t;
u_int offs; \
} usb_dma_t
#define usb_timeout(f, d, t, h) timeout((f), (d), (t))
#define usb_untimeout(f, d, h) untimeout((f), (d))
typedef char usb_callout_t;
#define usb_callout_init(h)
#define usb_callout(h, t, f, d) timeout((f), (d), (t))
#define usb_uncallout(h, f, d) untimeout((f), (d))
#define USB_DECLARE_DRIVER(dname) \
int __CONCAT(dname,_match)(struct device *, void *, void *); \
@ -320,8 +324,10 @@ typedef struct thread *usb_proc_ptr;
#define config_pending_incr()
#define config_pending_decr()
#define usb_timeout(f, d, t, h) ((h) = timeout((f), (d), (t)))
#define usb_untimeout(f, d, h) untimeout((f), (d), (h))
typedef struct callout usb_callout_t;
#define usb_callout_init(h) callout_init(&(h), 0)
#define usb_callout(h, t, f, d) callout_reset(&(h), (t), (f), (d))
#define usb_uncallout(h, f, d) callout_stop(&(h))
#define clalloc(p, s, x) (clist_alloc_cblocks((p), (s), (s)), 0)
#define clfree(p) clist_free_cblocks((p))

View File

@ -1,4 +1,4 @@
/* $NetBSD: usb_subr.c,v 1.76 2000/04/27 15:26:50 augustss Exp $ */
/* $NetBSD: usb_subr.c,v 1.70 2000/03/29 01:45:20 augustss Exp $ */
/* $FreeBSD$ */
/*
@ -696,9 +696,11 @@ usbd_setup_pipe(usbd_device_handle dev, usbd_interface_handle iface,
p->refcnt = 1;
p->intrxfer = 0;
p->running = 0;
p->aborting = 0;
p->repeat = 0;
p->interval = ival;
SIMPLEQ_INIT(&p->queue);
usb_callout_init(p->abort_handle);
err = dev->bus->methods->open_pipe(p);
if (err) {
DPRINTFN(-1,("usbd_setup_pipe: endpoint=0x%x failed, error="

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbdi.c,v 1.60 2000/01/19 00:23:58 augustss Exp $ */
/* $NetBSD: usbdi.c,v 1.71 2000/03/29 01:45:21 augustss Exp $ */
/* $FreeBSD$ */
/*
@ -237,6 +237,12 @@ usbd_close_pipe(pipe)
LIST_REMOVE(pipe, next);
pipe->endpoint->refcnt--;
pipe->methods->close(pipe);
#if defined(__NetBSD__) && defined(DIAGNOSTIC)
if (callout_pending(&pipe->abort_handle)) {
callout_stop(&pipe->abort_handle);
printf("usbd_close_pipe: abort_handle pending");
}
#endif
if (pipe->intrxfer != NULL)
usbd_free_xfer(pipe->intrxfer);
free(pipe, M_USB);
@ -261,6 +267,9 @@ usbd_transfer(xfer)
#endif
xfer->done = 0;
if (pipe->aborting)
return (USBD_CANCELLED);
size = xfer->length;
/* If there is no buffer, allocate one. */
if (!(xfer->rqflags & URQ_DEV_DMABUF) && size != 0) {
@ -314,8 +323,10 @@ usbd_transfer(xfer)
if (xfer->done)
break;
}
if (!xfer->done)
if (!xfer->done) {
pipe->methods->abort(xfer);
xfer->status = USBD_TIMEOUT;
}
} else
/* XXX End hack XXX */
tsleep(xfer, PRIBIO, "usbsyn", 0);
@ -381,6 +392,7 @@ usbd_alloc_xfer(dev)
if (xfer == NULL)
return (NULL);
xfer->device = dev;
usb_callout_init(xfer->timeout_handle);
DPRINTFN(5,("usbd_alloc_xfer() = %p\n", xfer));
return (xfer);
}
@ -392,6 +404,12 @@ usbd_free_xfer(xfer)
DPRINTFN(5,("usbd_free_xfer: %p\n", xfer));
if (xfer->rqflags & (URQ_DEV_DMABUF | URQ_AUTO_DMABUF))
usbd_free_buffer(xfer);
#if defined(__NetBSD__) && defined(DIAGNOSTIC)
if (callout_pending(&xfer->timeout_handle)) {
callout_stop(&xfer->timeout_handle);
printf("usbd_free_xfer: timout_handle pending");
}
#endif
xfer->device->bus->methods->freex(xfer->device->bus, xfer);
return (USBD_NORMAL_COMPLETION);
}
@ -607,13 +625,11 @@ usbd_clear_endpoint_stall_async(pipe)
}
void
usbd_clear_endpoint_toggle(pipe)
usbd_pipe_handle pipe;
usbd_clear_endpoint_toggle(usbd_pipe_handle pipe)
{
pipe->methods->cleartoggle(pipe);
}
usbd_status
usbd_endpoint_count(iface, count)
usbd_interface_handle iface;
@ -752,6 +768,7 @@ usbd_ar_pipe(pipe)
usbd_dump_queue(pipe);
#endif
pipe->repeat = 0;
pipe->aborting = 1;
while ((xfer = SIMPLEQ_FIRST(&pipe->queue)) != NULL) {
DPRINTFN(2,("usbd_ar_pipe: pipe=%p xfer=%p (methods=%p)\n",
pipe, xfer, pipe->methods));
@ -759,6 +776,7 @@ usbd_ar_pipe(pipe)
pipe->methods->abort(xfer);
/* XXX only for non-0 usbd_clear_endpoint_stall(pipe); */
}
pipe->aborting = 0;
return (USBD_NORMAL_COMPLETION);
}
@ -809,9 +827,6 @@ usb_transfer_complete(xfer)
}
}
if (pipe->methods->done != NULL)
pipe->methods->done(xfer);
if (!repeat) {
/* Remove request from queue. */
#ifdef DIAGNOSTIC
@ -821,6 +836,8 @@ usb_transfer_complete(xfer)
#endif
SIMPLEQ_REMOVE_HEAD(&pipe->queue, xfer, next);
}
DPRINTFN(5,("usb_transfer_complete: repeat=%d new head=%p\n",
repeat, SIMPLEQ_FIRST(&pipe->queue)));
/* Count completed transfers. */
++pipe->device->bus->stats.uds_requests
@ -837,6 +854,15 @@ usb_transfer_complete(xfer)
if (xfer->callback)
xfer->callback(xfer, xfer->priv, xfer->status);
#ifdef DIAGNOSTIC
if (pipe->methods->done != NULL)
pipe->methods->done(xfer);
else
printf("usb_transfer_complete: pipe->methods->done == NULL\n");
#else
pipe->methods->done(xfer);
#endif
if ((xfer->flags & USBD_SYNCHRONOUS) && !polling)
wakeup(xfer);

View File

@ -1,4 +1,4 @@
/* $NetBSD: usbdivar.h,v 1.47 2000/02/22 11:30:56 augustss Exp $ */
/* $NetBSD: usbdivar.h,v 1.53 2000/03/29 01:45:21 augustss Exp $ */
/* $FreeBSD$ */
/*
@ -38,6 +38,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/callout.h>
/* From usb_mem.h */
DECLARE_USB_DMA_T;
@ -156,6 +158,7 @@ struct usbd_pipe {
struct usbd_endpoint *endpoint;
int refcnt;
char running;
char aborting;
SIMPLEQ_HEAD(, usbd_xfer) queue;
LIST_ENTRY(usbd_pipe) next;
@ -163,6 +166,8 @@ struct usbd_pipe {
char repeat;
int interval;
usb_callout_t abort_handle;
/* Filled by HC driver. */
struct usbd_pipe_methods *methods;
};
@ -178,6 +183,11 @@ struct usbd_xfer {
usbd_status status;
usbd_callback callback;
__volatile char done;
#ifdef DIAGNOSTIC
u_int32_t busy_free;
#define XFER_FREE 0x46524545
#define XFER_BUSY 0x42555357
#endif
/* For control pipe */
usb_device_request_t request;
@ -198,11 +208,8 @@ struct usbd_xfer {
SIMPLEQ_ENTRY(usbd_xfer) next;
void *hcpriv; /* private use by the HC driver */
int hcprivint;
#if defined(__FreeBSD__)
struct callout_handle timo_handle;
#endif
usb_callout_t timeout_handle;
};
void usbd_init(void);