Commit Graph

169 Commits

Author SHA1 Message Date
Warner Losh
7bd250d818 s/logprintf/printf/g
Approved by: re@
2007-06-20 05:11:37 +00:00
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
Ian Dowse
9145721957 Use a different task queue for host controller and peripheral driver
tasks. Since the host controllers rely on tasks to process transfer
timeouts, if a synchronous transfer from a driver was invoked from
a task and timed out, it would never complete because the single
task thread was stuck performing the synchronous transfer so couldn't
process the timeout.

This affected the axe, udav and ural drivers.

Problem hardware provided by:	guido
2006-10-19 01:15:58 +00:00
Ian Dowse
dff926577b Fix compile in non-debug case. 2006-10-03 08:38:08 +00:00
Ian Dowse
9c63c3f400 When changing the device address and max packet size in usbd_new_device(),
close and re-open the default pipe instead of relying on the host
controller driver to notice the changes. Remove the unreliable code
that attempted to update these fields while the pipe was active.
This fixes a case where the hardware could cache and continue to
use the old address, resulting in a "getting first desc failed"
error.

PR:		usb/103167
2006-10-03 01:13:26 +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
46f1e0d36c If a zero-length bulk or interrupt transfer is requested then assume
USBD_FORCE_SHORT_XFER to ensure that we actually build and execute
a transfer. This means that the various alloc_sqtd_chain functions
will always construct a transfer, so it is safe to modify the
allocated descriptors on return. Previously there were cases where
a zero length transfer would cause a NULL dereference.

Reported by:	bp
2006-05-28 23:37:04 +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
Poul-Henning Kamp
c40da00ca3 Since DELAY() was moved, most <machine/clock.h> #includes have been
unnecessary.
2006-05-16 14:37:58 +00:00
Ian Dowse
78e3c96cc9 Save and restore the data toggle value when a pipe to an endpoint
is closed and then reopened. This appears to be necessary now that
we no longer clear endpoint stalls every time a pipe is opened.
Previously we could assume an initial toggle value of zero because
the clear-stall operation resets the device's toggle state.

Reported by:	Holger Kipp
MFC after:	3 days
2006-02-26 02:57:57 +00:00
Ian Dowse
b184cddcc2 Add a missing ohci_waitintr() call that allows polled operation of
bulk transfers to have a chance of working.

PR:		usb/93720
Submitted by:	Nate Nielsen
MFC after:	1 week
2006-02-25 17:44:29 +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
df3e5efa87 Set sc_dying to 1 when detaching. In NetBSD and OpenBSD this was
done by the DVACT_DEACTIVATE case in *hci_activate(), but we don't
use that code in FreeBSD so it was never set.
2006-01-15 20:41:04 +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
Yoshihiro Takahashi
d4fcf3cba5 Remove bus_{mem,p}io.h and related code for a micro-optimization on i386
and amd64.  The optimization is a trivial on recent machines.

Reviewed by:	-arch (imp, marcel, dfr)
2005-05-29 04:42:30 +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
098ca2bda9 Start each of the license/copyright comments with /*-, minor shuffle of lines 2005-01-06 01:43:34 +00:00
Giorgos Keramidas
285d9e0fa7 Fix KASSERT inversion that was introduced in 1.150, resulting in instant
panic curlen != 0, which is perfectly normal.

Approved by:	mux
2005-01-05 20:10:05 +00:00
Julian Elischer
a8ef988f65 Remove comment that doesn't seem to be true and add comments describing
what is going on, to replace it. Slight formatting changes
Code here is alredy different to NetBSD.
MFC after:	1 week
2005-01-03 08:52:26 +00:00
Julian Elischer
2410443379 A much simpler way to work out if the required transfer can be done in 2
scatter gather segments.

MFC after:	1 week
2005-01-03 08:09:05 +00:00
Julian Elischer
80ee93cb22 Slightly reorganise part of the ohci_softintr() function
to better keep track of the total amoutn transferred during a
transfer. Seems similar to some code in the NetBSD version.
I notice they have incorporated matches from him so I don't know which
direction it went.

Submitted by:	damien.bergamini@free.fr
Obtained from:	patches to make the ueagle driver work
MFC after:	1 week
2004-12-14 03:59:24 +00:00
Ian Dowse
f6b587096b Fix just the worst of the timeout race conditions that the previous
backed out commits were trying to address: when cancelling the timeout
callout, also cancel the abort_task event, since it is possible that
the timeout has already fired and set up an abort_task.
2004-11-16 00:48:27 +00:00
Ian Dowse
85b8134e51 Back out my recent changes for timeout races, as there have been
reports of problems. The bug is probably that there are cases where
`xfer->timeout && !sc->sc_bus.use_polling' is not a suitable test
for an active timeout callout, so an explicit flag will be necessary.
Apologies for the breakage.
2004-11-12 02:57:35 +00:00
Ian Dowse
0ce606de7c Attempt to fix a number of race conditions in the handling of
transfer timeouts that typically cause a transfer to be completed
twice, resulting in panics and page faults:

 o A transfer completion interrupt could arrive while an abort_task
   event was set up, so the transfer would be aborted after it had
   completed. This is very easy to reproduce. Fix this by setting
   the transfer status to USBD_TIMEOUT before scheduling the
   abort_task so that the transfer completion code will ignore it.

 o The transfer completion code could execute concurrently with the
   timeout callout, leaving the callout blocked (e.g. waiting for
   Giant) while the transfer completion code runs. In this case,
   callout_stop() does not prevent the callout from running, so
   again the timeout code would run after the transfer was complete.
   Handle this case by checking the return value from callout_stop(),
   and ignoring the transfer if the callout could not be removed.

 o Finally, protect against a timeout callout occurring while a
   transfer is being aborted by another process. Here we arrange
   for the timeout processing to ignore the transfer, and use
   callout_drain() to ensure that the callout has really gone before
   completing the transfer.

This was tested by repeatedly performing USB transfers with a timeout
set to approximately the same as the normal transfer completion
time. In the PR below, apparently this occurred by accident with a
particular printer and the default timeout.

PR:		kern/71491
2004-11-09 20:51:32 +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
Lukas Ertl
57ceda5d84 MFNetBSD.
ohci.c (1.147), author: mycroft
   Failure to properly mask off UE_DIR_IN from the endpoint address
   was causing OHCI_ED_FORMAT_ISO and EHCI_QH_HRECL to get set
   spuriously, causing rather interesting lossage.

   Suddenly I get MUCH better performance with ehci...

ohci.c (1.148), author: mycroft
   Adjust a couple of comments to make it clear WTF is going on.

Obtained from:   NetBSD
2004-06-26 09:19:31 +00:00
Julian Elischer
c8e8e129a5 MFNetBSD Version 1.146
various probing and attaching tweeks.

Submitted by:	Rudolf Cejka <cejkar@fit.vutbr.cz>

Obtained from:	NetBSD
MFC after: 3 days
2004-03-26 18:56:58 +00:00
Takeshi Shibagaki
8eabf88dd3 Fixed incomplete initialization in some ohci controllers with
broken BIOS. Separate ohci_controller_init() from ohci_init(),
and call ohci_controller_init() at resume process once more.

Discussed on [bsd-nomads:16737] - [bsd-nomads:16746].

Submitted by Hiroyuki Aizu <eyes@navi.org> [bsd-nomads:16741]
2003-12-22 15:40:10 +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
Ian Dowse
5bc9164667 Write the correct value to `td_be' for the second and further
transfer descriptors when a large request needs to be split into
more than one 8k chunk. The bug was that the calculation did not
take into account the offset of the chunk within the overall request.
This is reported to fix crashes and data corruption on ohci
controllers.

Submitted by:	green
Approved by:	re
2003-11-25 02:23:29 +00:00
Josef Karthauser
447f52c8b4 Remove a gremlin so that this code compiles under -stable without
a "syntax error before `struct'" error.
2003-11-12 01:40:11 +00:00
Josef Karthauser
7a4a3d9f69 MFNetBSD:
date: 2003/10/18 04:50:35;  author: simonb
    Remove assigned-to but otherwise unused variables.
    Remove unreachable break after return statements.
2003-11-10 00:20:52 +00:00
Josef Karthauser
f395d6798d MFNetBSD:
revision 1.142
    date: 2003/10/11 03:04:26;  author: toshii
    Fix a done list handling bug which exhibits under high shared
    interrupt rate and bus traffic.  As the interrupt register is
    read after checking hcca_done_head, there was a small chance
    of dropping a done list.  Ignore OHCI_WDH interrupt bit if
    hcca_done_head is zero so that OHCI_WDH is processed later.
2003-11-10 00:16:36 +00:00
Josef Karthauser
9c96cea538 MFNetBSD:
revision 1.141
    date: 2003/09/10 20:08:29;  author: mycroft;
    Update actlen even in the case where a TD returns an error --
    this is critical for the umass bulk-only STALL case.
2003-11-10 00:12:39 +00:00
Josef Karthauser
fe5e683b90 Revise the NetBSD revision control strings. 2003-11-09 23:56:19 +00:00
Josef Karthauser
35b64e1272 MFNetBSD:
- remove the unnecessary elm arg from SIMPLEQ_REMOVE_HEAD().
  this mirrors the functionality of SLIST_REMOVE_HEAD() (the other
  singly-linked list type) and FreeBSD's STAILQ_REMOVE_HEAD()
2003-11-09 23:54:21 +00:00
David E. O'Brien
aad970f1fe Use __FBSDID().
Also some minor style cleanups.
2003-08-24 17:55:58 +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
John-Mark Gurney
45dd937507 make usb bus_dma aware.
Reviewed by:	joe among others
2003-07-15 22:42:37 +00:00
John-Mark Gurney
e65f8c784d minor white space fix up
initalize itds
remove extra htole32.  Things don't work to well when you do
htole32(htole32(var))
2003-07-15 22:14:22 +00:00
Josef Karthauser
b214af6eba Backout the last commit!
MFNetBSD: revision 1.137
    date: 2003/01/20 07:12:13;  author: simonb;
    Grrr.  So much for my ability to use grep(1) effectively.  Pointed out
    by Stephen Degler in private mail.
2003-07-14 19:56:32 +00:00
Josef Karthauser
563a940856 MFNetBSD: revision 1.136
date: 2003/01/20 05:30:09;  author: simonb;
    The Double-Semi-Colon Police.
2003-07-14 19:54:21 +00:00
Josef Karthauser
a237c6ec2e MFNetBSD: revision 1.135
date: 2002/12/10 14:07:37;  author: toshii;  state: Exp;  lines: +6 -6
    Add a couple of le32toh which were missing in the previous.
    Pointed out by SOMEYA Yoshihiko.
2003-07-14 19:51:53 +00:00
Josef Karthauser
e35285ad59 MFNetBSD: revision 1.134
date: 2002/12/07 07:33:20;  author: toshii;  state: Exp;  lines: +50 -29
    Update xfer->frlengths for input isoc transfer.  Based on patches from
    SOMEYA Yoshihiko.
    Also fix error handling for isoc transfer somewhat; usb_transfer_complete
    shouldn't be called for more than once.
2003-07-14 19:50:06 +00:00
Josef Karthauser
0ab3fe8a80 MFNetBSD: revision 1.133
date: 2002/12/07 07:14:28;  author: toshii;
    Fix several nits.  Mostly from SOMEYA Yoshihiko.
    - Call usbd_transfer_complete at splusb.
    - Fix a botched for loop in ohci_rem_ed.
    - In ohci_close_pipe, wait 1ms after removing an ED to avoid possible race
     condition.

The splusb change is non-functional on FreeBSD.
The botched loop and race condition changes came from us.

This patch is non-functional.
2003-07-14 19:47:59 +00:00
Josef Karthauser
4999f44917 MFNetBSD: revision 1.132
date: 2002/12/07 06:52:11;  author: toshii;
    Remove junk at the end of a DPRINTF.  From SOMEYA Yoshihiko.
2003-07-14 19:42:05 +00:00
Josef Karthauser
99112dddf2 MFNetBSD: revision 1.129
date: 2002/09/29 20:58:25;  author: augustss;
    Add some spl calls to protect critical regions. From kern/18440,
    Takeshi Nakayama.

(No functional change on FreeBSD).
2003-07-14 19:39:16 +00:00
Josef Karthauser
771b291ad0 MFNetBSD:
date: 2003/05/13 04:41:59;  author: gson;
    Function names printed in debug messages did not always match the
    actual name of the function.
2003-07-14 18:56:33 +00:00