Commit graph

54 commits

Author SHA1 Message Date
Gerd Hoffmann f1ae32a1ec usb: the big rename
Reorganize usb source files.  Create a new hw/usb/ directory and move
all usb source code to that place.  Also make filenames a bit more
descriptive.  Host adapters are prefixed with "hch-" now, usb device
emulations are prefixed with "dev-".  Fixup paths Makefile and include
paths to make it compile.  No code changes.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-13 10:15:32 +01:00
Gerd Hoffmann 1b4b29a114 usb: add shortcut for control transfers
Add a more direct code path to submit control transfers.  Instead of
feeding three usb packets (setup, data, ack) to usb_handle_packet and
have the do_token_* functions in usb.c poke the control transfer
parameters out of it just submit a single packet carrying the actual
data with the control xfer parameters filled into USBPacket->parameters.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-07 12:28:05 +01:00
Gerd Hoffmann 7936e0f0d2 usb: add pipelining option to usb endpoints
With this patch applied USB drivers can enable pipelining per endpoint.
With pipelining enabled the usb core will continue submitting packets
even when there are still async transfers in flight instead of passing
them on one by one.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-07 12:28:05 +01:00
Gerd Hoffmann eb9d4673e3 usb: queue can have async packets
This can happen today in case the ->complete() callback queues up the
next packet.  Also we'll support pipelining soon, which allows to have
multiple packets per queue in flight (aka ASYNC) state.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-07 12:28:05 +01:00
Gerd Hoffmann 808aeb98ff usb: add tracepoint for usb packet state changes.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-27 13:37:36 +01:00
Gerd Hoffmann 37f32f0fdd usb: add USBBusOps->wakeup_endpoint
Add usb bus op which is called whenever a usb endpoint becomes ready,
so the host adapter emulation can react on that event.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 12:16:30 +01:00
Gerd Hoffmann 7567b51fbe usb: pass USBEndpoint to usb_wakeup
Devices must specify which endpoint has data to transfer now.
The plan is to use the usb_wakeup() not only for remove wakeup support,
but for "data ready" signaling in general, so we can move away from
constant polling to event driven usb device emulation.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 12:16:30 +01:00
Gerd Hoffmann db4be873d3 usb: maintain async packet list per endpoint
Maintain a list of async packets per endpoint.  With the current code
the list will never receive more than a single item.  I think you can
guess what the future plan is though ;)

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 12:16:18 +01:00
Gerd Hoffmann 079d0b7f1e usb: Set USBEndpoint in usb_packet_setup().
With the separation of the device lookup (via usb_find_device) and
packet processing we can lookup device and endpoint before setting up
the usb packet.  So we can initialize USBPacket->ep early and keep it
valid for the whole lifecycle of the USBPacket.  Also the devaddr and
devep fields are not needed any more.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:31:57 +01:00
Gerd Hoffmann 63095ab54c usb: add USBEndpoint->{nr,pid}
Add a "nr" and "pid" fields to USBEndpoint so you can easily figure the
endpoint number and direction of any given endpoint.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:31:57 +01:00
Gerd Hoffmann f53c398aa6 usb: USBPacket: add status, rename owner -> ep
Add enum to track the status of USBPackets, use that instead of the
owner pointer to figure whenever a usb packet is currently in flight
or not.  Add some more packet status sanity checks.  Also rename the
USBEndpoint pointer from "owner" to "ep".

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:31:57 +01:00
Gerd Hoffmann 1977f93dac usb: fold usb_generic_handle_packet into usb_handle_packet
There is no reason to have a separate usb_generic_handle_packet function
any more, fold it into usb_handle_packet().  Also call the do_token_*
functions which handle control transfer emulation for control pipe
packets only.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:31:57 +01:00
Gerd Hoffmann 7f74a56b14 usb: kill handle_packet callback
All drivers except usb-hub use usb_generic_handle_packet.  The only
reason the usb hub has its own function is that it used to be called
with packets which are intended for downstream devices.  With the new,
separate device lookup step this doesn't happen any more, so the need
for a different handle_packet callback is gone.

So we can kill the handle_packet callback and just call
usb_generic_handle_packet directly.  The special hub handling in
usb_handle_packet() can go away for the same reason.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:31:57 +01:00
Gerd Hoffmann 98861f512b usb: handle dev == NULL in usb_handle_packet()
Allow passing in a NULL pointer, return USB_RET_NODEV in that case.
Removes the burden to to a NULL pointer check from the callers.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:31:57 +01:00
Gerd Hoffmann 73796fe622 usb: add usb_find_device()
Add usb_find_device().  This function will check whenever a device with
a specific address is connected to the specified port.  Usually this
will just check state and address of the device hooked up to the port,
but in case of a hub it will ask the hub to check all hub ports for a
matching device.

This patch doesn't put the code into use yet, see the following patches
for details.

The master plan is to separate device lookup and packet processing.
Right now the usb code simply walks all devices, calls
usb_handle_packet() on each until one accepts the packet (by returning
something different that USB_RET_NODEV).  I want to have a device lookup
first, then call usb_handle_packet() once, for the device which actually
processes the packet.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:31:48 +01:00
Gerd Hoffmann 70fc20d4dc usb: kill usb_send_msg
No users left.  Zap it.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:12:04 +01:00
Gerd Hoffmann d28f4e2d86 usb: kill USB_MSG_RESET
The USB subsystem pipes internal reset notifications through
usb_handle_packet() with a special magic PID.  This indirection
is a pretty pointless excercise as it ends up being handled by
usb_generic_handle_packet anyway.

Replace the USB_MSG_RESET with a usb_device_reset() function
which can be called directly.  Also rename the existing usb_reset()
function to usb_port_reset() to avoid confusion.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:12:04 +01:00
Gerd Hoffmann d1f8b53618 usb: kill USB_MSG_{ATTACH,DETACH}
The USB subsystem pipes internal attach/detach notifications through
usb_handle_packet() with a special magic PID.  This indirection is a
pretty pointless excercise as it ends up being handled by
usb_generic_handle_packet anyway.  Remove it.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:12:04 +01:00
Anthony Liguori 62aed76583 usb: convert to QEMU Object Model
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:47 -06:00
Gerd Hoffmann 25d5de7d81 usb: link packets to endpoints not devices
Add USBEndpoint for the control endpoint to USBDevices.  Link async
packets to the USBEndpoint instead of the USBDevice.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann f003397ce9 usb: add max_packet_size to USBEndpoint
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann 5b6780d045 usb/debug: add usb_ep_dump
Add function to dump endpoint data, for debugging purposes.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann 82f02fe965 usb: add ifnum to USBEndpoint
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann d8e17efdec usb: add USBEndpoint
Start maintaining endpoint state at USBDevice level.  Add USBEndpoint
struct and some helper functions to deal with it.  For now it contains
the endpoint type only.  Moved over some bits from usb-linux.c

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann e0b8e72dd9 usb: fix port reset
commit 891fb2cd45 removed the implicit
detach before (re-)attaching in usb_attach().  Some usb host controllers
used that behavior though to do a port reset by a detach+attach
sequence.

This patch establishes old behavior by adding a new usb_reset() function
for port resets and putting it into use, thereby also unifying port
reset behavior of all host controllers.  The patch also adds asserts to
usb_attach() and usb_detach() to make sure the calls are symmetrical.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-10-13 12:58:51 +02:00
Gerd Hoffmann 891fb2cd45 usb: claim port at device initialization time.
This patch makes qemu assign a port when creating the device, not when
attaching it.  For most usb devices this isn't a noticable difference
because they are in attached state all the time.

The change affects usb-host devices which live in detached state while
the real device is unplugged from the host.  They have a fixed port
assigned all the time now instead of getting grabbing one on attach and
releasing it at detach, i.e. they stop floating around at the usb bus.

The change also allows to simplify usb-hub.  It doesn't need the
handle_attach() callback any more to configure the downstream ports.
This can be done at device initialitation time now.  The changed
initialization order (first grab upstream port, then register downstream
ports) also fixes some icky corner cases.  For example it is not possible
any more to plug the hub into one of its own downstream ports.

The usb host adapters must care too.  USBPort->dev being non-NULL
doesn't imply any more the device is in attached state.  The host
adapters must additionally check the USBPort->dev->attached flag.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07 09:58:26 +02:00
Gerd Hoffmann 4d8debba76 usb: fix use after free
The ->complete() callback might have released the USBPacket (uhci
actually does), so we must not touch it after the callback returns.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07 09:58:26 +02:00
Gerd Hoffmann 4f4321c11f usb: use iovecs in USBPacket
Zap data pointer from USBPacket, add a QEMUIOVector instead.
Add a bunch of helper functions to manage USBPacket data.
Switch over users to the new interface.

Note that USBPacket->len was used for two purposes:  First to
pass in the buffer size and second to return the number of
transfered bytes or the status code on async transfers.  There
is a new result variable for the latter.  A new status code
was added to catch uninitialized result.

Nobody creates iovecs with more than one element (yet).
Some users are (temporarely) limited to iovecs with a single
element to keep the patch size as small as possible.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-08-04 15:51:22 +02:00
Hans de Goede 45b9fd3480 usb: assert on calling usb_attach(port, NULL) on a port without a dev
with the "usb-ehci: cleanup port reset handling" patch in place no callers
are calling usb_attach(port, NULL) for a port where port->dev is NULL.

Doing that makes no sense as that causes the port detach op to get called
for a port with nothing attached. Add an assert that port->dev != NULL when
dev == NULL, and remove the check for not having a port->dev in the dev == NULL
case.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-07-05 15:09:02 +02:00
Hans de Goede d47e59b8b8 usb: Make port wakeup and complete ops take a USBPort instead of a Device
This makes them consistent with the attach and detach ops, and in general
it makes sense to make portops take a port as argument. This also makes
adding support for a companion controller easier / cleaner.

[ kraxel: fix usb-musb.c build ]

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-07-05 15:09:02 +02:00
Gerd Hoffmann eb5e680ae5 usb: move cancel callback to USBDeviceInfo
Remove the cancel callback from the USBPacket struct, move it over
to USBDeviceInfo.  Zap usb_defer_packet() which is obsolete now.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:03 +02:00
Gerd Hoffmann 4ff658fb6c usb: keep track of packet owner.
Keep track of the device which owns the usb packet for async processing.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:03 +02:00
Gerd Hoffmann 53aa8c0e2a usb: add usb_handle_packet
Add a usb_handle_packet function, put it into use everywhere.
Right now it just calls dev->info->handle_packet(), that will
change in future patches though.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:03 +02:00
Hans de Goede 50b7963e72 usb-linux: use usb_generic_handle_packet()
Make the linux usb host passthrough code use the usb_generic_handle_packet()
function, rather then the curent DYI code. This removes 200 lines of almost
identical code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-26 11:55:02 +02:00
Hans de Goede 007fd62f4d usb: Pass the packet to the device's handle_control callback
This allows using the generic usb_generic_handle_packet function from
device code which does ASYNC control requests (such as the linux host
pass through code).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-26 11:55:02 +02:00
Hans de Goede 19f3322379 usb: control buffer fixes
Windows allows control transfers to pass up to 4k of data, so raise our
control buffer size to 4k. For control out transfers the usb core code copies
the control request data to a buffer before calling the device's handle_control
callback. Add a check for overflowing the buffer before copying the data.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:52 +02:00
Gerd Hoffmann b6f77fbe23 usb: add attach callback
Add handle_attach() callback to USBDeviceInfo which is called by the
generic package handler when the device is attached to the usb bus
(i.e. plugged into a port).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:15:24 +01:00
Gerd Hoffmann 01eacab6e9 usb: add usb_wakeup() + wakeup callback to port ops
Add wakeup callback to port ops for remote wakeup handling.
Also add a usb_wakeup() function for devices which want
trigger a remote wakeup.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:01:02 +01:00
Gerd Hoffmann 618c169b57 usb: rework attach/detach workflow
Add separate detach callback to USBPortOps, split
uhci/ohci/musb/usbhub attach functions into two.

Move common code to the usb_attach() function, only
the hardware-specific bits remain in the attach/detach
callbacks.

Keep track of the port it is attached to for each usb device.

[ v3: fix tyops in usb-musb.c ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:01:02 +01:00
Gerd Hoffmann 0d86d2bebb usb: create USBPortOps, move attach there.
Create USBPortOps struct, move the attach function to that struct.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:01:02 +01:00
Gerd Hoffmann 806b602482 qdev/usb: add usb bus support to qdev, convert drivers.
* Add USBBus.
 * Add USBDeviceInfo, move device callbacks here.
 * Add usb-qdev helper functions.
 * Switch drivers to qdev.

TODO:
 * make the rest of qemu aware of usb busses and kill the FIXMEs
   added by this patch.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-09-09 14:55:17 -05:00
aliguori 89b9b79f34 usb: generic packet handler cleanup and documentation (Max Krasnyansky)
A bit better documentation of the USB device API, namely
return codes.
Rewrite of usb_generic_handle_packet() to make it more
reable and easier to follow.

Signed-off-by: Max Krasnyansky <maxk@kernel.org>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5049 c046a42c-6fe2-441c-8c8c-71466251a162
2008-08-21 19:29:38 +00:00
pbrook 87ecb68bdf Break up vl.h.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3674 c046a42c-6fe2-441c-8c8c-71466251a162
2007-11-17 17:14:51 +00:00
ths 5fafdf24ef find -type f | xargs sed -i 's/[\t ]$//g' # on most files
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3173 c046a42c-6fe2-441c-8c8c-71466251a162
2007-09-16 21:08:06 +00:00
ths aa1f17c18d Spelling fixes, by Stefan Weil.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@3066 c046a42c-6fe2-441c-8c8c-71466251a162
2007-07-11 22:48:58 +00:00
pbrook 4d611c9a2f SCSI and USB async IO support.
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2107 c046a42c-6fe2-441c-8c8c-71466251a162
2006-08-12 01:04:27 +00:00
bellard 059809e451 usb destroy API change (Lonnie Mendez)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2066 c046a42c-6fe2-441c-8c8c-71466251a162
2006-07-19 18:06:15 +00:00
pbrook 2e5d83bbef Rearrange SCSI disk emulation code.
Add USB mass storage device emulation.


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1940 c046a42c-6fe2-441c-8c8c-71466251a162
2006-05-25 23:58:51 +00:00
bellard 72899afc5d separate file for usb hub device
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1848 c046a42c-6fe2-441c-8c8c-71466251a162
2006-04-24 21:18:20 +00:00
bellard 56bebe70bd usb setup state machine fix when driver reads or writes too many bytes
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@1847 c046a42c-6fe2-441c-8c8c-71466251a162
2006-04-24 21:10:52 +00:00