R&D/Hypervisor

[USB] Types of data transfers

sunshout 2014. 11. 20. 20:39

OUT : Host computer --> USB device

IN : USB device --> Host computer

 

USB endpoint 종류

  1. CONTROL : (Asynchronous) control endpoint USB device access하기 위해서 사용됨
    1. 예를 들어 configure device, retrieving information from device, sending command to the device, retrieving status reports about the device
    2. 모든 USB device CONTROL 해당하는 "endpoint 0" 가짐
      1. USB device insert 사용됨
      1. guaranteed by the USB protocol
  1. INTERRUPT : (Periodic) transfer small amounts of data at a fixed rate every time
    1. ex) keyboard, mouse
    1. guaranteed by the USB protocol
  1. BULK : (Asynchronous) Bulk endpoints transfer large amounts of data
    1. Interrupt endpoint 보다는 많은 data 가짐
    1. data loss 없이 많은 data 전달하고자 사용됨
    1. data 양이 많을 multiple transfers 나눠질 수도 있음
    2. ex) printer, storage, network devices

  1. ISOCHRONOUS : (Periodic) large amount of data transfer , data 대한 guarantee 없음
    1. device can handle loss of data, real-time 장치에 유리
    1. ex) audio, video 장치


Control Transaction
- This is initiated by the host via an appropriately coded token packet with information regarding the control command being issued.
- The recipient either replies with an ACK handshake, or ignores the token totally.
- This type of transfer also contains an optional unidirectional data transfer between the host and the device.
- Lastly, a status is returned to whatever end of the pipe was last to transmit.


Interrupt Transaction

- This function is queried by the host via a token packet,

- Return data if the has any interrupt related information to transfer, or NAK handshake if it doesn't



Bulk Transfers

- When the host wants to initiate a bulk transfer from a device, it sends a token packet specifying whether input or output is desired.

- (OUT) If the host wants input, the function in turn sends either a packet of data or a non-ACK handshake.

- (IN) If the host is sending a request to transmit, it will immediately send the data packet and wait for an appropriate handshake to be returned by the recipient.




Isochronous Transaction

- begin with an appropriate token packet being sent to the function, 

- and then data is transmitted as required.

- Due to the assumed error-tolerance of isochronous data, no handshake packets are used.





QEMU Implementation

- for CONTROL
void usb_host_handle_control(udev, p, request, value, index, length, *data) @ hw/usb/host-libusb.c
switch(request) {
     case  DeviceOutRequest | USB_REQ_SET_ADDRESS:
...
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
...
case InterfaceOutRequest | USB_REQ_SET_INTERFACE:
...
case EndpointOutRequest | USB_REQ_CLEAR_FEATURE:
...



- for BULK, INTERRUPT, ISOCHRONOUS transaction

void usb_host_handle_data(udev, p) @ hw/usb/host-libusb.c

switch (usb_ep_get_type(udev, p->pid, p->ep->nr)) {

    case USB_ENDPOINT_XFER_BULK:

   …

    case USB_ENDPOINT_XFER_INT:

  …

    case USB_ENDPOINT_XFER_ISOC:

 



reference: 
[1] Linux Device Drivers , Chapter 13. USB Drivers
[2] http://www.geoffknagge.com/uni/elec101/essay.shtml

[3] http://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_116_USB%20Data%20Structure.pdf