Commit Graph

61 Commits

Author SHA1 Message Date
Attilio Rao
7fbfba7bf8 - Handle buffer lock waiters count directly in the buffer cache instead
than rely on the lockmgr support [1]:
  * bump the waiters only if the interlock is held
  * let brelvp() return the waiters count
  * rely on brelvp() instead than BUF_LOCKWAITERS() in order to check
    for the waiters number
- Remove a namespace pollution introduced recently with lockmgr.h
  including lock.h by including lock.h directly in the consumers and
  making it mandatory for using lockmgr.
- Modify flags accepted by lockinit():
  * introduce LK_NOPROFILE which disables lock profiling for the
    specified lockmgr
  * introduce LK_QUIET which disables ktr tracing for the specified
    lockmgr [2]
  * disallow LK_SLEEPFAIL and LK_NOWAIT to be passed there so that it
    can only be used on a per-instance basis
- Remove BUF_LOCKWAITERS() and lockwaiters() as they are no longer
  used

This patch breaks KPI so __FreBSD_version will be bumped and manpages
updated by further commits. Additively, 'struct buf' changes results in
a disturbed ABI also.

[2] Really, currently there is no ktr tracing in the lockmgr, but it
will be added soon.

[1] Submitted by:	kib
Tested by:	pho, Andrea Barberio <insomniac at slackware dot it>
2008-03-01 19:47:50 +00:00
Attilio Rao
5b56116548 - Revert last ehci.c change
- Include lock.h in lockmgr.h as nested header in order to safely use
  LOCK_FILE and LOCK_LINE.  As long as this code will be replaced soon
  we can tollerate for a while this namespace pollution even if the real
  fix would be to let lockmgr() depend by lock.h as a separate header.
2008-02-10 15:50:21 +00:00
Konstantin Belousov
2db08dbb82 After rev. 1.60 of sys/lockmgr.h, the header requires inclusion of the
sys/lock.h.
2008-02-10 07:34:16 +00:00
Attilio Rao
0e9eb108f0 Cleanup lockmgr interface and exported KPI:
- Remove the "thread" argument from the lockmgr() function as it is
  always curthread now
- Axe lockcount() function as it is no longer used
- Axe LOCKMGR_ASSERT() as it is bogus really and no currently used.
  Hopefully this will be soonly replaced by something suitable for it.
- Remove the prototype for dumplockinfo() as the function is no longer
  present

Addictionally:
- Introduce a KASSERT() in lockstatus() in order to let it accept only
  curthread or NULL as they should only be passed
- Do a little bit of style(9) cleanup on lockmgr.h

KPI results heavilly broken by this change, so manpages and
FreeBSD_version will be modified accordingly by further commits.

Tested by: matteo
2008-01-24 12:34:30 +00:00
Attilio Rao
d7a7e17968 Remove explicit calling of lockmgr() with the NULL argument.
Now, lockmgr() function can only be called passing curthread and the
KASSERT() is upgraded according with this.

In order to support on-the-fly owner switching, the new function
lockmgr_disown() has been introduced and gets used in BUF_KERNPROC().
KPI, so, results changed and FreeBSD version will be bumped soon.
Differently from previous code, we assume idle thread cannot try to
acquire the lockmgr as it cannot sleep, so loose the relative check[1]
in BUF_KERNPROC().

Tested by: kris

[1] kib asked for a KASSERT in the lockmgr_disown() about this
condition, but after thinking at it, as this is a well known general
rule, I found it not really necessary.
2008-01-08 23:48:31 +00:00
Don Lewis
4d54b88811 Replace three copies of the host controller reset sequence that
differ in their details with calls to a new function, ehci_hcreset(),
that performs the reset.

The original sequences either had no delay or a 1ms delay between
telling the controller to stop and asserting the controller reset
bit.  One instance of the original reset sequence waited for the
controller to indicate that its reset was complete before continuing,
but the other two immediately let the subsequent code execute.  The
latter is a problem on some hardware, because a read of the HCCPARAMS
register returns an incorrect value while the reset is in progress,
which triggers an infinite loop in ehci_pci_givecontroller(), which
hangs the system on shutdown.

The reset sequence in ehci_hcreset() starts with the most complete
instance from the original code, which contains a loop to wait for
the controller to indicate that its reset is complete.   This appears
to be the correct thing to do according to "Enhanced Host Controller
Interface Specification for Universal Serial Bus" revision 1.0,
section 2.3.1.  Add another loop to wait for the controller to
indicate that it has stopped before setting the HCRESET bit.  This
is required by the section 2.3.1 in the specification, which says
that setting HCRESET before the controller has halted "will result
in undefined behaviour".

Reviewed by:	imp (previous patch version without the extra wait loop)
Tested by:	se  (previous patch version without the extra wait loop)
Approved by:	re (bmah)
MFC after:	1 week
2007-08-12 18:45:24 +00:00
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
Ian Dowse
093daa268f Attempt to follow the procedure described in section 4.10 of the
EHCI spec for linking in new qTDs into an asynchronous QH. This
requires that there is a qTD marked as not active and not halted
at the start of the QH's list, and the hardware will know to re-fetch
the qTD on each pass rather than just looking at the overlay qTD:

  "The host controller must be able to advance the queue from the
  Fetch QH state in order to avoid all hardware/software race
  conditions. This simple mechanism allows software to simply link
  qTDs to the queue head and activate them, then the host controller
  will always find them if/when they are reachable."

This is achieved by keeping an "inactivesqtd" entry on the QH list,
and re-using it each time as the start of the next transfer, and
allocating a new qTD to become the next inactivesqtd. Then a new
transfer can be activated by just setting its "active" flag, which
avoids all the previous messing with overlay qTD state in
ehci_set_qh_qtd().
2006-05-24 03:04:11 +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
1ecfb7ed3d Oops - fix the build in the !USB_DEBUG case. 2006-03-18 17:57:34 +00:00
Ian Dowse
a6725353dd Let the EHCI hardware track the toggle state for bulk and interrupt
transfers. This fixes some cases where the software toggle tracking
was not doing the right thing. For example, a short transfer that
transferred 0 bytes of the requested qTD transfer size does cause
a toggle change, but the existing code was assuming it didn't.

Reported and tested by: pav
MFC after:	2 weeks
2006-03-18 13:55:16 +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
Ariff Abdullah
ed3b31fc67 ehci_pci.c:
ATI EHCI controllers exhibit simmilar stall issues and require
	this dropped interrupts workaround. Be verbose about it.
ehci.c:
ehcivar.h:
	Slight change in comments to note about issues surrounding both
	VIA and ATI EHCI controllers.

Approved by:	iedowse
2006-01-16 19:23:59 +00:00
Ian Dowse
afcb6f8261 Work around a problem seen on VIA EHCI controllers where occasionally
an interrupt appears to occur before the transfer has been marked
as completed. This caused umass transfers to get stuck, especially
when writing large files. The workaround sets up a timer that
rechecks for missed completed transfers if some operations are still
pending. Other suggested workarounds, such as performing a PCI read
immediately after acknowledging the interrupts, do not appear to
help.

Obtained from:	OpenBSD
2006-01-15 21:03:19 +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
c15e3d30c7 The ehci driver doesn't use the transfer `hcpriv' field, so don't
bother setting it to NULL in ehci_root_ctrl_done().
2006-01-15 20:32:52 +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
a3a574f503 Remove trailing whitespace as per NetBSD's revision 1.91. Also
update the TODO comments to more closely match current reality.
2005-03-20 22:22:18 +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
Ian Dowse
bc7744545d Set the split transaction interrupt C-mask correctly. This is the
final piece needed to make split transaction interrupt pipes work,
which I thought I had already committed.
2005-03-14 01:03:50 +00:00
Ian Dowse
f4b4a6b096 The EHCI qTD token has a number of error status bits that are not
cleared if the host controller retries the transfer and is successful,
but we were interpreting these bits as indicating a fatal error.
Ignore these error bits, and instead use the HALTED bit to determine
if the transfer failed. Also update the USBD_STALLED detection to
ignore these bits.

Obtained from: OpenBSD
2005-03-13 23:48:17 +00:00
Ian Dowse
76d8aa3efe Fix the arrangement of periodic QH tree to give the correct interval
between passes over a QH. Previously the accesses to a QH were
bunched together in time, so the interval was often much longer
than intended. This now appears to match the diagrams in the EHCI
spec, so remove the XXX comment.
2005-03-13 04:07:40 +00:00
Ian Dowse
2f9b6e1f34 Fix the silly bug that prevented most EHCI interrupt transfers from
ever working correctly: the code was linking the QHs together but
then immediately overwriting the "next" pointers. Oops. Also
initialise qh_endphub, since the EHCI spec says that we should
always set the pipe multiplier field to something sensible.

This appears to make basic split transactions work, so enable split
transactions for control, bulk and interrupt pipes (split isochronous
transfers are not yet implemented). It should now be possible to
use USB1 devices even when they are connected through a USB2 hub.
2005-03-08 02:47:18 +00:00
Julian Elischer
4f93332f16 fix a "little-endian-big-endian confusion that luckily:
1/ doesn't matter on most of our architectures
2/ will never happen unless we start queueing multiple trasactions
to a single endpoint at one time (which we do not allow yet).
If anyone has a big_endian machine with EHCI they might check this
if they are having problems with EHCI but it's unlikely even there..

Submitted by:	Hans Petter Selasky <hselasky@c2i.net>
MFC after:	3 days
2005-01-09 23:49:45 +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
Julian Elischer
4eefd67bb0 Fix comment. One of the two "Step 4" shuold be a "step 5" 2005-01-05 01:04:35 +00:00
Julian Elischer
2f37e02978 Rewrite ehci_abort_xfer() to use the method hinted at in the EHCI spec.
to remove a transaction from the async schedule. The previous method didn't
work well and led to the hardware writing to free'd buffers etc, as
it didn't always know that the transaction had been aborted.

Written after consultation with David Brownell who wrote the Linux
EHCI driver.

As part of this give the sqh structure a "previous" pointer.

MFC after:	1 week
2004-12-29 01:21:18 +00:00
Julian Elischer
53d4f8518a Slight change to formatting so that 'ctags' doesn't
give up on teh file half way through.. Might have been my
mistake earlier anyhow. No actual code change

MFC after:	5 days
2004-12-18 01:20:18 +00:00
Poul-Henning Kamp
a884a1b0f2 Make LINT compile.
When leaving functions for ddb use don't make them static: it makes
gcc think they are unused.

Shouldn't this be in #ifdef DDB anyway ?
2004-12-14 07:46:28 +00:00
Julian Elischer
b96aca53dc A bunch more whitespace and formatting diff reductions for NetBSD.
Obtained from:	NetBSD
MFC after:	1 week
2004-12-14 04:47:24 +00:00
Julian Elischer
47f9e7b6ce Don't abandon ship just because the number of companions doesn't seem correct.
Obtained from:	NetBSD
MFC after:	1 week
2004-12-14 04:05:10 +00:00
Julian Elischer
6e6281a3dc Small formatting change..
Move a declaration to the same place as in NetBSD.

Obtained from:	NetBSD
MFC after:	1 week
2004-12-14 03:54:08 +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
b483f84d55 The ehci_dump() function shouldn't be declared static, as it is
just a convenience function to be called from debuggers that gets
compiled in when EHCI_DEBUG is defined. Move its declaration to
make this more obvious.
2004-11-03 15:12:18 +00:00
Ian Dowse
f79bef6097 Merge recent USB2/EHCI related changes from NetBSD:
o Reduce the interrupt delay to 2 microframes.
 o Follow the spec more closely when updating the overlay qTD in the QH.
 o No need to generate an interrupt at the data part of a control
   transfer, it's generated by the status transfer.
 o Make sure to update the data toggle on short transfers.
 o Turn the printf about needing toggle update into a DPRINTF.
 o Keep track of what high speed port (if any) a device belongs to
   so we can set the transaction translator fields for the transfer.
 o Verbosely refuse to open low/full speed pipes that depend on
   unimplemented split transaction support.
 o Fix various typos in comments.

Obtained from:	NetBSD
2004-11-03 01:52:50 +00:00
Ian Dowse
cf181f3b71 Save and restore state across suspend/resume events.
Submitted by:	David Gwynne <dlg@openbsd.org>
Obtained from:	OpenBSD (+ extra patches supplied by David)
2004-10-30 15:13:09 +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
Ian Dowse
da37d6ad41 Attempt to follow the correct procedure for synchronising with the
system BIOS to disable legacy device emulation as per the "EHCI
Extended Capability: Pre-OS to OS Handoff Synchronisation" section
of the EHCI spec. BIOSes that implement legacy emulation using SMIs
are supposed to disable the emulation when this procedure is performed.
2004-08-02 12:56:01 +00:00
Ian Dowse
2dacb7cc04 Implement basic support for EHCI interrupt pipes. This is unlikely
to be particularly correct or optimal, but it seems to be enough
to allow the attachment of USB2 hubs and USB2 devices connected via
USB2 hubs. None of the split transaction support is implemented in
our USB stack, so USB1 peripherals will definitely not work when
connected via USB2 hubs.
2004-08-01 18:47:42 +00:00