bulk-streams.rst 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. USB bulk streams
  2. ~~~~~~~~~~~~~~~~
  3. Background
  4. ==========
  5. Bulk endpoint streams were added in the USB 3.0 specification. Streams allow a
  6. device driver to overload a bulk endpoint so that multiple transfers can be
  7. queued at once.
  8. Streams are defined in sections 4.4.6.4 and 8.12.1.4 of the Universal Serial Bus
  9. 3.0 specification at https://www.usb.org/developers/docs/ The USB Attached SCSI
  10. Protocol, which uses streams to queue multiple SCSI commands, can be found on
  11. the T10 website (https://t10.org/).
  12. Device-side implications
  13. ========================
  14. Once a buffer has been queued to a stream ring, the device is notified (through
  15. an out-of-band mechanism on another endpoint) that data is ready for that stream
  16. ID. The device then tells the host which "stream" it wants to start. The host
  17. can also initiate a transfer on a stream without the device asking, but the
  18. device can refuse that transfer. Devices can switch between streams at any
  19. time.
  20. Driver implications
  21. ===================
  22. ::
  23. int usb_alloc_streams(struct usb_interface *interface,
  24. struct usb_host_endpoint **eps, unsigned int num_eps,
  25. unsigned int num_streams, gfp_t mem_flags);
  26. Device drivers will call this API to request that the host controller driver
  27. allocate memory so the driver can use up to num_streams stream IDs. They must
  28. pass an array of usb_host_endpoints that need to be setup with similar stream
  29. IDs. This is to ensure that a UASP driver will be able to use the same stream
  30. ID for the bulk IN and OUT endpoints used in a Bi-directional command sequence.
  31. The return value is an error condition (if one of the endpoints doesn't support
  32. streams, or the xHCI driver ran out of memory), or the number of streams the
  33. host controller allocated for this endpoint. The xHCI host controller hardware
  34. declares how many stream IDs it can support, and each bulk endpoint on a
  35. SuperSpeed device will say how many stream IDs it can handle. Therefore,
  36. drivers should be able to deal with being allocated less stream IDs than they
  37. requested.
  38. Do NOT call this function if you have URBs enqueued for any of the endpoints
  39. passed in as arguments. Do not call this function to request less than two
  40. streams.
  41. Drivers will only be allowed to call this API once for the same endpoint
  42. without calling usb_free_streams(). This is a simplification for the xHCI host
  43. controller driver, and may change in the future.
  44. Picking new Stream IDs to use
  45. =============================
  46. Stream ID 0 is reserved, and should not be used to communicate with devices. If
  47. usb_alloc_streams() returns with a value of N, you may use streams 1 though N.
  48. To queue an URB for a specific stream, set the urb->stream_id value. If the
  49. endpoint does not support streams, an error will be returned.
  50. Note that new API to choose the next stream ID will have to be added if the xHCI
  51. driver supports secondary stream IDs.
  52. Clean up
  53. ========
  54. If a driver wishes to stop using streams to communicate with the device, it
  55. should call::
  56. void usb_free_streams(struct usb_interface *interface,
  57. struct usb_host_endpoint **eps, unsigned int num_eps,
  58. gfp_t mem_flags);
  59. All stream IDs will be deallocated when the driver releases the interface, to
  60. ensure that drivers that don't support streams will be able to use the endpoint.