Commit Graph

46 Commits

Author SHA1 Message Date
Warner Losh
200d9c860d Expand callout compatibility macros in the main usb bridges. 2007-06-14 16:23:31 +00:00
Warner Losh
2283429409 Remove more unnecessary and unwanted __OtherBSD__ ifdefs. 2007-06-13 06:00:10 +00:00
Warner Losh
2deae8fa2f More removing compatibility macros.
md5 still the same.

"Dave, stop.  I feel my mind slipping away." -- hal
2006-09-07 00:06:42 +00:00
Warner Losh
56635f6bd3 s/Static/static/g
s/device_ptr_t/device_t/g

No md5 changes in the .o's

# Note to the md5 tracking club: $FreeBSD$ changes md5 after every commit
# so you need to checkout -kk to get $FreeBSD$ instead of the actual value
# of the keyword.
2006-09-06 23:44:25 +00:00
Ian Dowse
368030a87a Use the limited scatter-gather capabilities of ehci, ohci and uhci
host controllers to avoid the need to allocate any multi-page
physically contiguous memory blocks. This makes it possible to use
USB devices reliably on low-memory systems or when memory is too
fragmented for contiguous allocations to succeed.

The USB subsystem now uses bus_dmamap_load() directly on the buffers
supplied by USB peripheral drivers, so this also avoids having to
copy data back and forth before and after transfers. The ehci and
ohci controllers support scatter/gather as long as the buffer is
contiguous in the virtual address space. For uhci the hardware
cannot handle a physical address discontinuity within a USB packet,
so it is necessary to copy small memory fragments at times.
2006-05-28 05:27:09 +00:00
Warner Losh
5df2beab5b Give ohci_intr a proper return value. In FreeBSD, this is void. Remove
now-redundant cast on establishing the interrupt.
2006-02-11 03:29:02 +00:00
Ian Dowse
d63700b023 The ohci driver's processing of completed transfer descriptors (TDs)
appeared to rely on all kinds of non-guaranteed behaviours: the
transfer abort code assumed that TDs with no interrupt timeout
configured would end up on the done queue within 20ms, the done
queue processing assumed that all TDs from a transfer would appear
at the same time, and there were access-after-free bugs triggered
on failed transfers.

Attempt to fix these problems by the following changes:
 - Use a maximum (6-frame) interrupt delay instead of no interrupt
   delay to ensure that the 20ms wait in ohci_abort_xfer() is enough
   for the TDs to have been taken off the hardware done queue.
 - Defer cancellation of timeouts and freeing of TDs until we either
   hit an error or reach the final TD.
 - Remove TDs from the done queue before freeing them so that it
   is safe to continue traversing the done queue.

This appears to fix a hang that was reproducable with revision 1.67
or 1.68 of ulpt.c (earlier revisions had a different transfer
pattern). With certain HP printers, the command "true > /dev/ulpt0"
would cause ohci_add_done() to spin because the done queue had a
loop. The list corruption was caused by a 3-TD transfer where the
first TD completed but remained on the internal host controller
done queue because it had no interrupt timeout. When the transfer
timed out, the TD got freed and reused, so it caused a loop in the
done queue when it was inserted a second time from a different
transfer.

Reported by:	Alex Pivovarov
MFC after:	1 week
2005-11-27 09:05:37 +00:00
Ian Dowse
a3d327674a It was possible to have two threads concurrently aborting the same
transfer, which lead to panics or page faults. For example if a
transfer timed out, another thread could come along and attempt to
abort the same transfer while the timeout task was sleeping in
the *_abort_xfer() function.

Add an "aborting" flag to the private transfer state in each host
controller driver and use this to ensure that the abort is only
executed once. Also prioritise normal abort requests over timeouts
so that the callback is always given a status of USB_CANCELLED even
if the timeout-initiated abort began first.

The crashes caused by this bug were mainly reported in connection
with lpd printing to a USB printer.

PR:	usb/78208, usb/78986
2005-03-19 19:08:46 +00:00
Warner Losh
ad3142eda4 MFp4:
sc_child isn't used on FreeBSD, so ifdef it out in a way that is
NetBSD mergeable.
2005-01-11 07:34:13 +00:00
Warner Losh
098ca2bda9 Start each of the license/copyright comments with /*-, minor shuffle of lines 2005-01-06 01:43:34 +00:00
Ian Dowse
f50033ff2e Make the USB subsystem unloadable and detachable, though currently
a significant amount of memory may be leaked each time a host
controller is detached.
2004-08-02 15:37:35 +00:00
Takeshi Shibagaki
e394a3e85d Enable support for DEVICE_SUSPEND, DEVICE_RESUME and DEVICE_SHUTDOWN
methods for USB devices in the same way of uhci driver. But this change
is not complete because some ohci controlers are not initialized completely.
So "kernel: usb0: 1 scheduling overruns" interrupt will generate many times.

This change will be same one in PR kern/60099.

Discussed on [bsd-nomads:16737] - [bsd-nomads:16746].
2003-12-22 15:18:46 +00:00
John-Mark Gurney
57499a32b1 make allocation of the necessary data structures most efficent by using
a full page instead of only part of a page.

Reviewed by:	joe
2003-07-15 23:19:49 +00:00
John-Mark Gurney
86231a1846 fix support for umass and related devices on ohci. This is a partial
sync of the NetBSD code.

fix isochornous support for ohci.  This gets webcams like my OV511
working on sparc64.

PR:		kern/52589
Submitted by:	Bruce R. Montague (isochonous support)
Reviewed by:	joe among others
2003-07-15 23:12:54 +00:00
Josef Karthauser
fe74650816 In rev 1.51 of usb_port.h I switched over to using the USB_USE_SOFTINTR
code path to fix a bug in the non USB_USE_SOFTINTR path that caused
the usb bus to hang and generally misbehave when devices were unplugged.
In the process though it also reduced the throughput of usb devices because
of a less than optimal implementation under FreeBSD.

This commit fixes the non USB_USE_SOFTINTR code in uhci and ohci
so that it works again, and switches back to using this code path.

The uhci code has been tested, but the ohci code hasn't.  It's
essentially the same anyway and so I don't envisage any difficulties.

Code for uhci submitted by:	Maksim Yevmenkin <myevmenk@exodus.net>
2002-09-30 17:50:18 +00:00
Josef Karthauser
041ed0fb76 MFNetBSD: ohci.c (1.119), ohcivar.h (1.30)
date: 2001/12/31 12:20:35;  author: augustss;
    Change xfer abort to wait for the softintr to run.
2002-04-07 15:16:31 +00:00
Josef Karthauser
8f3c17c9ba MFNetBSD:
revision 1.27
    date: 2001/02/21 10:19:30;  author: minoura;  state: Exp;  lines: +2 -3
    There is no reason to exclude FreeBSD :).
2002-04-07 15:01:01 +00:00
Josef Karthauser
cc29ac735d MFNetBSD: ohci.c (1.114), ohcivar.h (1.29)
date: 2001/11/21 02:41:18;  author: augustss;
    Use a task to perform the timeout abort so we have a process context when
    sleeping.
2002-04-07 14:57:31 +00:00
Josef Karthauser
dc6d4959c0 MFNetBSD: ohci.c (1.101), ohcivar.h (1.26)
revision 1.101
    date: 2001/02/20 15:20:32;  author: minoura;
    Re-initialize some registers after resuming from suspend.
    Some APM BIOSes do not restore them.
    Reviewd by augustss.
2002-04-07 14:40:15 +00:00
Josef Karthauser
daad38f29f MFNetBSD: ohci.c (1.100), ohcivar.h (1.25)
ohci.c
    revision 1.100
    date: 2001/01/28 16:18:09;  author: augustss;  state: Exp;  lines: +7 -2
    Put a rate limiter on the scheduling overrun message.

ohcivar.h:
    revision 1.25
    date: 2001/01/28 19:01:20;  author: augustss;  state: Exp;  lines: +4 -1
    Commit second half of rate limit change.
2002-04-07 14:25:02 +00:00
Josef Karthauser
9bf191c521 MFNetBSD: ohci.c (1.104), ohcivar.h (1.28)
date: 2001/09/28 23:57:21;  author: augustss;
    Reenable RHSC interrupt after one second so hot plugging works.
    (From OpenBSD.)
2002-04-07 11:33:55 +00:00
Josef Karthauser
174ea84839 Use ANSI prototypes and declarations.
Update $NetBSD$ idents to better reflect reality.
2002-04-01 19:01:09 +00:00
Josef Karthauser
6688a3fdbe Merge from NetBSD:
ohci.c (1.83), ohcireg.h (1.16), ohcivar.h (1.21)

	===================================================================
	date: 2000/03/29 01:46:26;  author: augustss;
	A first stab at support for isochronous transfers.
	===================================================================
2002-04-01 13:18:11 +00:00
Josef Karthauser
3ede2e88ea Merge from NetBSD:
ohcivar.h (1.22), uhcivar.h (1.29):
	============================================================
	date: 2000/04/25 09:20:55;  author: augustss;
	Move the size of the mapped bus_space region into the bus
	independent softc.
	============================================================

ohci.c (1.88), uhci.c (1.112):
	============================================================
	date: 2000/04/25 14:28:13;  author: augustss;
	Insert (very conservative!) bus_space_barrier() calls at
	all register accesses.
	The bus_space(9) man page says you've gotta have them...
	============================================================
2002-03-16 12:44:21 +00:00
Josef Karthauser
b7e4eb198d Merge from NetBSD:
ohci.c:	revision 1.72 and 1.73
    ohcivar.h:	revision 1.19 and 1.20
    uhci.c:	revision 1.85
    usbdi.h:	a small part of revision 1.40
    usbdivar.h:	revision 1.47

Relevant commit messages from NetBSD are:

	date: 2000/02/22 11:30:54;  author: augustss;  state: Exp;
	Prepare a little for having USB interrupt processing done
	outside the hard interrupt level (in a thread or a softintr).
	No real soft processing done yet.
	----------------------------
	date: 2000/02/01 05:42:53;  author: augustss;  state: Exp;
	Put some #ifdefs around power and shutdown hooks.
2002-01-26 12:04:22 +00:00
Nick Hibma
4f04f78215 Remove __P prototypes to reduce diffs between the NetBSD and FreeBSD
versions.
2000-07-17 18:41:20 +00:00
Jake Burkholder
e39756439c Back out the previous change to the queue(3) interface.
It was not discussed and should probably not happen.

Requested by:		msmith and others
2000-05-26 02:09:24 +00:00
Jake Burkholder
740a1973a6 Change the way that the queue(3) structures are declared; don't assume that
the type argument to *_HEAD and *_ENTRY is a struct.

Suggested by:	phk
Reviewed by:	phk
Approved by:	mdodd
2000-05-23 20:41:01 +00:00
Nick Hibma
128aa3af3c Change Lennart's e-mail address. 2000-05-14 16:43:10 +00:00
Nick Hibma
8feb725eb1 Add the fields needed to store the cookies. 2000-05-07 20:17:30 +00:00
Nick Hibma
31bfa89e41 Get rid of the last remnants of powerhook abuse. 2000-03-18 14:54:54 +00:00
Nick Hibma
e557a32190 Add the TD's to the hash when they are created not when they are used.
This makes it possible to handle the done queue even when the end of tail
TD has ended up on the done queue as well (the xfer in this case is NULL
but the next field is valid, so we simply skip that element.

Make sure we mark all the handled transfers as handled.

Stop using powerhooks. They are a NetBSD-ism.
2000-03-15 22:27:24 +00:00
Nick Hibma
8648a2cdb9 Move the defines to the right location.
Add a DIAGNOSTIC when closing interrupt pipes.

Insert splx(s) which were left out with iso pipes (non-functional yet) and
in a DIAGNOSTIC.
2000-01-27 23:25:58 +00:00
Bill Paul
a6d9a40e81 More USB ethernet tweaks:
- Sync ohci, uhci and usbdi modules with NetBSD in order to obtain the
  following improvements:
        o New USBD_NO_TSLEEP flag can be used in place of UQ_NO_TSLEEP
          quirk. This allows drivers to specify busy waiting only for
          certain transfers (namely control transfers for reading/writing
          registers and stuff).
        o New USBD_FORCE_SHORT_XFER flag can be used to deal with
          devices like the ADMtek Pegasus that sense the end of bulk OUT
          transfers in a special way (if a transfer is exactly a multiple
          of 64 bytes in size, you need to send an extra empty packet
          to terminate the transfer).
        o usbd_open_pipe_intr() now accepts an interval argument which
          can be used to change the rate at which the interrupt callback
          routine is invoked. Specifying USBD_DEFAULT_INTERVAL uses the
          value specified in the device's config data, but drivers can
          override it if needed.
- Change if_aue to use USBD_FORCE_SHORT_XFER for packet transmissions.
- Change if_aue, if_kue and if_cue to use USBD_NO_TSLEEP for all
  control transfers. We no longer force the non-tsleep hack for
  bulk transfers since these are done asynchronously anyway.
- Removed quirk entry fiddling from if_aue and if_kue since we don't
  need it anymore now that we have the USBD_NO_TSLEEP flag.
- Tweak ulpt, uhid, ums and ukbd drivers to use the new arg to
  usbd_open_pipe_intr().
- Add a flag to the softc struct in the ethernet drivers to indicate
  when a device has been detached, and use this flag to perform
  tests to prevent the drivers from trying to do control transfers
  if this is the case. This is necessary because calling if_detach()
  with INET6 enabled will eventually result in a call to the driver's
  ioctl() routine to delete the multicast groups on the interface,
  which will result in attempts to perform control transfers. (It's
  possible this also happens even without INET6 support enabled.) This
  is pointless since we know that if the detach method has been called,
  the hardware has been unplugged.
- Changed watchdog timeout routines to just call the driver init routines
  to initialize the device states without trying to close and re-open the
  pipes. This is partly because we don't want to frob things at interrupt
  context, but also because this doesn't seem to work right and I don't
  want to panic the system just because a USB device may have stopped
  responding.
- Fix aue_rxeof() to be a little smarter about detecting when a double
  transfer is needed. Unfortunately, the design of the chip makes it hard
  to get this exactly right. Hopefully, this will go away once either
  Nick or Lennart finds the bug in the uhci driver that makes this ugly
  hack necessary.
- Also sync usbdevs with NetBSD.
2000-01-20 07:38:33 +00:00
Nick Hibma
3241be7550 Synchronisation with NetBSD as of 1999/11/16:
Cleaning up the code:
- Declare many functions static
- Change variable names to make them more self explanatory
- Change usbd_request_handle -> usbd_xfer_handle
- Syntactical changes
- Remove some unused code
- Other KNF changes

Interrupt context handling
- Change delay to usbd_delay_ms were possible (takes polling mode into
  account)
- Change detection mechanism for interrupt context

Add support for pre-allocation DMA-able memory by device driver

Add preliminary support for isochronous to the UHCI driver (not for OHCI
yet).

usb.c, uhci.c, ohci.c
- Initial attempt at detachable USB host controllers
- Handle the use_polling flag with a lttle more care and only set it if
we are cold booting.

usb.c, uhci.c ohci.c, usbdi.c usbdi_util.c usb_subr.c
- Make sure an aborted pipe is marked as not running.
- Start queued request in the right order.
- Insert some more DIAGNOSTIC sanity checks.
- Remove (almost) unused definitions USBD_XFER_OUT and USBD_XFER_IN.

usb.c, usb_subr.c
- Add an event mechanism so that a userland process can watch devices
  come and go.

ohci.c
- Handle the case when a USB transfer is so long that it crosses two
  page (4K) boundaries.  OHCI cannot do that with a single TD so we make
  a chain.

ulpt.c
- Use a bigger buffer when transferring data.
- Pre-allocate the DMA buffer.  This makes the driver slightly more
  efficient.
- Comment out the GET_DEVICE_ID code, because for some unknown reason it
  causes printing to fail sometimes.

usb.h
- Add a macro to extract the isoc type.
- Add a macro to check whether the routine has been entered after splusb
  and if not, complain.

usbdi.c
- Fix a glitch in dequeueing and aborting requests on interrupt pipes.
- Add a flag in the request to determine if the data copying is done by
  the driver or the usbdi layer.
1999-11-17 22:33:51 +00:00
Nick Hibma
8c895d718b Major synchronisation with the NetBSD USB stack:
- Some cleanup and improvements in the uhci and ohci drivers
- Support for plugging and unplugging devices improved
- Now available is bulk transport over OHCI controllers
- Resume and suspend have been temporarily been disabled again.  Proper
  support for it is available in the uhci.c and ohci.c files but I have
  not yet spent the brain cycles to use it.
- OpenBSD now uses the USB stack as well
- Add FreeBSD tags
1999-10-07 19:26:38 +00:00
Nick Hibma
d447ab3427 Thou shall do a make before commit.
[grmbl]
Fix duplicate elements in struct in previous commit.
1999-08-28 11:52:12 +00:00
Nick Hibma
f748f71688 Share more between FreeBSD and NetBSD 1999-08-28 11:31:21 +00:00
Peter Wemm
6182fdbda8 Bring the 'new-bus' to the i386. This extensively changes the way the
i386 platform boots, it is no longer ISA-centric, and is fully dynamic.
Most old drivers compile and run without modification via 'compatability
shims' to enable a smoother transition.  eisa, isapnp and pccard* are
not yet using the new resource manager.  Once fully converted, all drivers
will be loadable, including PCI and ISA.

(Some other changes appear to have snuck in, including a port of Soren's
 ATA driver to the Alpha.  Soren, back this out if you need to.)

This is a checkpoint of work-in-progress, but is quite functional.

The bulk of the work was done over the last few years by Doug Rabson and
Garrett Wollman.

Approved by:	core
1999-04-16 21:22:55 +00:00
Nick Hibma
67aa00a71b 1) Make debugging more selective.
2) create function usbd_errstr which turns a usbd_status into a sensible
   error message
3) Change the printf in DPRINTF to logprintf which is a define for
   log(KERN_DEBUG, x)
1999-04-11 20:50:33 +00:00
Nick Hibma
2115c3404f Remove unit from struct. Not used anymore. 1999-04-11 16:22:57 +00:00
Nick Hibma
235dddd4ea Textual changes 1999-01-22 00:51:12 +00:00
Nick Hibma
a73f7cf01f Major synchronisation with NetBSD USB code 1999-01-07 23:07:57 +00:00
Nick Hibma
6fef2c2c27 Added Id to all files 1998-12-14 09:32:25 +00:00
Nick Hibma
97797dc959 Various bug fixes:
1) Removed 'emulation' of bitmaps in printfs, FreeBSD seems to have caught
  up on that one
2) Fixed a few bugs in the timeout/timo timeout variables
3) First attempt at fixing a bug mentioned by Kazu: uhci_run is not able
  start/stop his USB host on his motherboard.
1998-12-09 23:36:15 +00:00
Nick Hibma
0cec007c5f Initial commit of ported NetBSD USB stack 1998-11-26 23:13:13 +00:00