summaryrefslogtreecommitdiff
path: root/usb-linux.c
AgeCommit message (Collapse)AuthorFilesLines
2012-03-13usb: the big renameGerd Hoffmann1-1913/+0
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-07usb-host: enable pipelineing for bulk endpoints.Gerd Hoffmann1-0/+3
We really don't want to wait for packets finish before submitting the next, we want keep the data flow running. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-07usb: add USB_RET_IOERRORHans de Goede1-2/+2
We already have USB_RET_NAK, but that means that a device does not want to send/receive right now. But with host / network redirection we can actually have a transaction fail due to some io error, rather then ie the device just not having any data atm. This patch adds a new error code named USB_RET_IOERROR for this, and uses it were appropriate. Notes: -Currently all usb-controllers handle this the same as NODEV, but that may change in the future, OHCI could indicate a CRC error instead for example. -This patch does not touch hw/usb-musb.c, that is because the code in there handles STALL and NAK specially and has a if status < 0 generic catch all for all other errors Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-03-07usb: return BABBLE rather then NAK when we receive too much dataHans de Goede1-1/+7
Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-27usb: Resolve warnings about unassigned bus on usb device creationJan Kiszka1-2/+2
When creating an USB device the old way, there is no way to specify the target bus. Thus the warning issued by usb_create makes no sense and rather confuses our users. Resolve this by passing a bus reference to the usbdevice_init handler and letting those handlers forward it to usb_create. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-15Merge remote-tracking branch 'kraxel/usb.38' into stagingAnthony Liguori1-23/+22
* kraxel/usb.38: (28 commits) xhci: handle USB_RET_NAK xhci: remote wakeup support xhci: kill port arg from xhci_setup_packet xhci: stop on errors xhci: add trb type name lookup support. xhci: signal low- and fullspeed support usb: add USBBusOps->wakeup_endpoint usb: pass USBEndpoint to usb_wakeup usb: maintain async packet list per endpoint usb: Set USBEndpoint in usb_packet_setup(). usb: add USBEndpoint->{nr,pid} usb: USBPacket: add status, rename owner -> ep usb: fold usb_generic_handle_packet into usb_handle_packet usb: kill handle_packet callback usb-xhci: switch to usb_find_device() usb-musb: switch to usb_find_device() usb-ohci: switch to usb_find_device() usb-ehci: switch to usb_find_device() usb-uhci: switch to usb_find_device() usb: handle dev == NULL in usb_handle_packet() ...
2012-02-15qom: Unify type registrationAndreas Färber1-2/+3
Replace device_init() with generalized type_init(). While at it, unify naming convention: type_init([$prefix_]register_types) Also, type_init() is a function, so add preceding blank line where necessary and don't put a semicolon after the closing brace. Signed-off-by: Andreas Färber <afaerber@suse.de> Cc: Anthony Liguori <anthony@codemonkey.ws> Cc: malc <av1474@comtv.ru> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-10usb: Set USBEndpoint in usb_packet_setup().Gerd Hoffmann1-22/+22
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-10usb: kill handle_packet callbackGerd Hoffmann1-1/+0
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-03qdev: register all types natively through QEMU Object ModelAnthony Liguori1-15/+19
This was done in a mostly automated fashion. I did it in three steps and then rebased it into a single step which avoids repeatedly touching every file in the tree. The first step was a sed-based addition of the parent type to the subclass registration functions. The second step was another sed-based removal of subclass registration functions while also adding virtual functions from the base class into a class_init function as appropriate. Finally, a python script was used to convert the DeviceInfo structures and qdev_register_subclass functions to TypeInfo structures, class_init functions, and type_register_static calls. We are almost fully converted to QOM after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03usb: separate out legacy usb registration from type registrationAnthony Liguori1-1/+2
Type registeration is going to get turned into a QOM call so decouple the legacy support. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27usb: convert to QEMU Object ModelAnthony Liguori1-16/+21
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-17usb: add max_packet_size to USBEndpointGerd Hoffmann1-26/+5
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17usb/debug: add usb_ep_dumpGerd Hoffmann1-0/+3
Add function to dump endpoint data, for debugging purposes. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17usb: add ifnum to USBEndpointGerd Hoffmann1-0/+1
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17usb: add USBEndpointGerd Hoffmann1-34/+29
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-13usb: track altsetting in USBDeviceGerd Hoffmann1-0/+10
Also handle {GET,SET}_INTERFACE in common code (usb-desc.c). Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-13usb: track configuration and interface count in USBDevice.Gerd Hoffmann1-12/+9
Move fields from USBHostDevice to USBDevice. Add bits to usb-desc.c to fill them for emulated devices too. Also allow to set configuration 0 (== None) for emulated devices. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-13usb-host: rip out legacy procfs supportGerd Hoffmann1-285/+42
This patch removes support for parsing /proc/bus/usb/devices for device discovery. The code lacks a few features compared to the sysfs code and is also bitrotting as everybody has sysfs these days. This implies having sysfs mounted is mandatory now to use the usb-host driver. udev isn't required though. qemu will prefer the udev-managed device nodes below /dev/bus/usb, but in case this directory isn't preset qemu will use the device nodes below /proc/bus/usb (default usbfs mount point). Bottom line: make sure you have both sysfs and usbfs mounted properly, and everything should continue to work as it did before. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-06usb-host: properly release port on unplug & exitGerd Hoffmann1-8/+20
Factor out port release into a separate function. Call release function in exit notifier too. Add explicit call the USBDEVFS_RELEASE_PORT ioctl, just closing the hub file handle seems not to be enougth. Make sure we release the port before resetting the device, otherwise host drivers will not re-attach. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-04Fix parse of usb device description with multiple configurationsCao,Bing Bu1-8/+11
Changed From V1: Use DPRINTF instead of fprintf,because it is not an error. When testing ipod on QEMU by He Jie Xu<xuhj@linux.vnet.ibm.com>,qemu made a assertion. We found that the ipod with 2 configurations,and the usb-linux did not parse the descriptor correctly. The descr_len returned is the total length of the all configurations,not one configuration. The older version will through the other configurations instead of skip,continue parsing the descriptor of interfaces/endpoints in other configurations,then went wrong. This patch will put the configuration descriptor parse in loop outside and dispel the other configurations not requested. Signed-off-by: Cao,Bing Bu <mars@linux.vnet.ibm.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-23usb-host: add usb_host_do_reset function.Gerd Hoffmann1-3/+22
Add a special function to reset the host usb device. It tracks the time needed by the USBDEVFS_RESET ioctl and prints a warning in case it needs too long. Usually it should be finished in 200 - 300 miliseconds. Warning threshold is one second. Intention is to help troubleshooting by indicating that the usb device stopped responding even to a reset request and is possibly broken. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-21usb-linux: fix /proc/bus/usb/devices scanGerd Hoffmann1-1/+6
Commit 0c402e5abb8c2755390eee864b43a98280fc2453 is incomplete and misses one of the two function pointer calls in usb_host_scan_dev(). Add the additional port handling logic to the other call too. Spotted by Coverity. Cc: Markus Armbruster <armbru@redhat.com> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-11-01usb-host: fix host closeGerd Hoffmann1-2/+4
The whole usb_host_close() function is skipped in case the device is not in attached state. This is wrong though, only then usb_device_detach() must be skipped, all other cleanup (especially device reset and closing the file handle) still needs to be done. There are code paths where usb_host_close() is called with the device in detached state already. This fixes usb-host devices not being released and returned to the host after removing them with device_del. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-10-13usb-host: handle USBDEVFS_SETCONFIGURATION returning EBUSYGerd Hoffmann1-1/+35
In case the host uses the usb device usbfs will refuse to set the configuration due to the device being busy. Handle this case by disconnection the interfaces, then trying again. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-10-13usb-host: factor out codeGerd Hoffmann1-63/+77
Move code to claim usb ports and to disconnect usb interfaces into usb_host_claim_port and usb_host_disconnect_ifaces functions. No functional change. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: tag as unmigratableGerd Hoffmann1-0/+6
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: parse port in /proc/bus/usb/devices scanGerd Hoffmann1-3/+13
Unfortunaly this is limited to root ports. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: constify portGerd Hoffmann1-5/+8
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: endpoint table fixupGerd Hoffmann1-78/+101
USB Devices can have up to 15 IN and 15 OUT endpoints, not 15 endpoints total. Move from one array to two arrays (one IN, one OUT) to maintain the endpoint state.
2011-09-07usb-host: claim portGerd Hoffmann1-0/+57
When configured to pass through a specific host port (using hostbus and hostport properties), try to claim the port if supported by the kernel. That will avoid any kernel drivers binding to devices plugged into that port. It will not stop any userspace apps (such as usb_modeswitch) access the device via usbfs though. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: fix configuration tracking.Gerd Hoffmann1-63/+19
It is perfectly fine to leave the usb device in unconfigured state (USBHostDevice->configuration == 0). Just do that and wait for the guest to explicitly set a configuration. This is closer to what real hardware does and it also simplifies the device initialization. There is no need to figure how the device is configured on the host. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: limit open retriesGerd Hoffmann1-1/+12
Limit the number of times qemu tries to open host devices to three. Reset error counter when the device goes away, after un-plugging and re-plugging the device qemu will try again three times. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: fix halted endpointsGerd Hoffmann1-3/+4
Two fixes for the price of one ;) First, reinitialize the endpoint table after device reset. This is needed anyway as the reset might have switched interfaces. It also clears the endpoint halted state. Second the CLEAR_HALT ioctl wants a unsigned int passed in as argument, not uint8_t. This gets my usb sd card reader (sandisk micromate) going. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07usb-host: reapurb error report fixGerd Hoffmann1-3/+5
Don't report errors on devices which are in disconnected and closing state.
2011-09-07usb-host: start tracing supportGerd Hoffmann1-25/+48
Add a bunch of trace points to usb-linux.c Drop a bunch of DPRINTK's in favor of the trace points. Also cleanup error reporting a bit while being at it. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-7/+7
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-08-04usb-host: iovec supportGerd Hoffmann1-9/+18
Add full support for iovecs to usb-host. The code can split large transfers into smaller ones already, we are using this to also split requests at iovec borders. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-08-04usb: use iovecs in USBPacketGerd Hoffmann1-13/+14
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-07-23notifier: Pass data argument to callbackJan Kiszka1-1/+1
This allows to pass additional information to the notifier callback which is useful if sender and receiver do not share any other distinct data structure. Will be used first for the clock reset notifier. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-06-23usb-linux: allow "compatible" high speed devices to connect at fullspeedHans de Goede1-0/+39
Some usb2 highspeed devices, like usb-msd devices, work fine when redirected to a usb1 virtual controller. Allow this to avoid the new speedhecks causing regressions for users who do not enable the new experimental ehci code. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23usb: Add a speedmask to devicesHans de Goede1-0/+1
This is used to indicate at which speed[s] the device can operate, so that this can be checked to match the ports capabilities when it gets attached to a bus. Note that currently all usb1 emulated device claim to be fullspeed, this seems to not cause any problems, but still seems wrong, because with real hardware keyboards, mice and tablets usually are lo-speed, so reporting these as fullspeed devices seems wrong. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23usb: Proper error propagation for usb_device_attach errorsHans de Goede1-1/+5
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23usb-linux: track inflight iso urb countGerd Hoffmann1-1/+25
Track the number of iso urbs which are currently in flight. Log a message in case the count goes down to zero. Also warn in case many urbs are returned at the same time. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23usb-linux: make iso urb count contigurableGerd Hoffmann1-7/+8
Add a qdev property for the number of iso urbs which usb-linux keeps in flight, so it can be configured at runtime. Make it default to four (old hardcoded value used to be three). Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23usb-linux: add get_endp()Gerd Hoffmann1-18/+21
Add a helper function to get the endpoint data structure and put it into use. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14usb-linux: Enlarge buffer for descriptors to 8192 bytesHans de Goede1-1/+1
1024 bytes is way to small, one hd UVC webcam I have over here has so many resolutions its descriptors take op close to 4k. Hopefully 8k will be enough for all devices. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14usb-linux: only cleanup in host_close when host_open was successful.Gerd Hoffmann1-4/+4
2011-06-14usb-linux: Don't try to open the same device twiceHans de Goede1-0/+1
If a user wants to redirect 2 identical usb sticks, in theory this is possible by doing: usb_add host:1234:5678 usb_add host:1234:5678 But this will lead to us trying to open the first stick twice, since we don't break the loop after having found a match in our filter list, so the next' filter list entry will result in us trying to open the same device again. Fix this by adding the missing break. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14usb-linux: Ensure devep != 0Hans de Goede1-0/+5
So that we don't index endp_table with a negative index. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>