Chapter 2 56 Bulk and interrupt endpoints increment the Sequence Number for every trans- action, resetting to zero on rollover or after completing a Set Configuration, Set Interface, or Clear Feature(ENDPOINT_HALT) request. In isochronous transfers, the Sequence Number resets to zero at the start of a service interval and increments on each additional Data Packet within the service interval. The endpoint descriptor specifies the length of a service interval and the maximum number of Data Packets per service interval. On detecting an error in a received Data Packet, the host or device sends an ACK Transaction Packet with the Retry bit set and the Sequence Number of the packet that contained the error. The sender of the Data Packet must then resend all sent Data Packets beginning with that Sequence Number. Table 2-8: The Data Packet Header provides the Data Packet’s length and other information. (Reserved fields not shown.) (KGNF $KVU (WPEVKQP Type 5 Data Packet Header (01000 b ) Route String or reserved 20 In downstream communications, used by hubs to route a packet to the correct port. Otherwise reserved. Device Address 7 The device that is the source or receiver of the Data Packet. Sequence Number 5 Identifies the Data Packet. End of Burst (EOB) (non-isochronous) or Last Packet Flag (LPF) (isochronous) 1 For non-isochronous IN endpoints, identifies the last packet in a burst. For non-isochronous OUT endpoints, zero. For isochronous endpoints, identifies the last packet in a service interval. Direction 1 0 = host to device; 1 = device to host. Endpoint Number 4 The endpoint that is the source or receiver of the Data Packet. Setup 1 Set by the host when the Data Packet is a Setup packet. Data Length 16 The number of data bytes in the Data Packet Payload. Stream ID or reserved 16 For bulk endpoints, can identify a stream. Packets Pending 1 Set by the host when it has another packet scheduled for the target endpoint. CRC-16 16 For error checking. Link Control Word 16 For link management. Inside USB Transfers 57 $WTUV6TCPUCEVKQPU SuperSpeed bulk and interrupt endpoints can support burst transactions, where the host or device sends multiple Data Packets without waiting for ACK Trans- action Packets to acknowledge previous received data. Every data payload in a burst except the last must equal the endpoint’s maximum packet size. The NumP field in an ACK Transaction Packet sets the number of Data Pack- ets a device or host can receive in a burst. Valid values are zero or any value from one less than the value in the previous ACK packet to bMaxBurst + 1 in the endpoint companion descriptor. Note that bMaxBurst is zero-based, with zero Table 2-9: Hosts and devices use Transaction Packets to send status and control information. 5WDV[RG 5QWTEG &GUETKRVKQP ACK Host Requests data from an IN endpoint and acknowledges a previously received data packet. Device Acknowledges data received on an OUT endpoint and specifies how many data packet buffers are available after receiving this packet. NRDY Device On receiving a Data Packet on an OUT endpoint, informs the host that the device has no buffer space to accept the data. On receiving an ACK Transaction Packet on an IN endpoint, informs the host that the device can’t return a data packet. Valid for non-isochronous endpoints. ERDY Device An endpoint is ready to send or receive Data Packets. Valid for non-isochronous endpoints. STATUS Host The host has initiated the Status stage of a control transfer. Valid for control endpoints. STALL Device The endpoint is halted or a requested control transfer is invalid or unsupported. DEV_NOTIFICATION Device A change in a device or interface state has occurred. The high nibble is the type of change: 0h reserved 1h function wake 2h latency tolerance message 3h bus interval adjustment message 4h–Fh reserved PING Host Before initiating an isochronous transfer when a link is in a low-power state, requests all paths between the host and the isochronous endpoint to transition to the active state. PING_RESPONSE Device Response to PING. Chapter 2 58 indicating a maximum burst of 1 packet, while NumP indicates the actual number of packets a receiver can accept (which may be zero). A Set Configuration, Set Interface, or Clear Feature(ENDPOINT_HALT) request resets the burst size of the associated endpoint(s). Isochronous endpoints can support isochronous burst transactions, which con- sist of multiple Data Packets transferred in a service interval with each packet except the last required to be the endpoint’s maximum packet size. Isochronous transactions never use ACK. 6KOKPI%QPUVTCKPVU Devices and hosts must respond quickly to received Data Packets and ACK Transaction Packets that request data. On receiving an ACK Transaction Packet with NumP > 0, a device must begin to return a Data Packet or NRDY Trans- action Packet within 250 ns. On receiving a Data Packet, a device must begin Table 2-10: An ACK Transaction Packet can acknowledge received data and request new data. (Reserved fields not shown.) 0WODGTQH $KVU (KGNF0COG &GUETKRVKQP 20 Route String Used by hubs in routing packets downstream. 7 Device Address The address assigned during enumeration. 4SubType ACK 1 Retry Data Packet If set, the host or device requests a resend due to not receiving a packet or receiving a corrupted packet. 1 Direction The direction of the endpoint sending or receiving the data: 0 = host to device; 1 = device to host. 4 Endpoint Number The endpoint sending or receiving the data. 1 Host Error For host-to-device ACK Transaction Packets, indicates that host was unable to accept a valid data packet. 5 Number of Packets (NumP) The number of Data Packets the receiver can accept in a burst. 5 Sequence Number (Seq Num) The sequence number of the next expected Data Packet. 16 Stream ID For bulk endpoints, can identify a stream. 1 Packets Pending Indicates whether the host has another packet for the endpoint. Inside USB Transfers 59 to return an ACK or NRDY Transaction Packet within 250 ns. On receiving a Data Packet, a host must begin to return an ACK or NRDY Transaction Packet within 3 µs. The maximum interval between Data Packets in a burst is 100 ns. The device hardware thus handles responding to received packets. 0QVKH[KPIVJG*QUV To conserve bandwidth and to enable inactive links to transition to low-power states, USB 3.0 hosts stop requesting to send or receive data from SuperSpeed endpoints that are in the flow control condition. This condition indicates that the endpoint temporarily can’t send or receive data. To request to resume com- munications, the endpoint sends an ERDY Transaction Packet. A device can send the ERDY at any time without waiting for the host to request a packet. On receiving the ERDY, the host resumes communications with the endpoint. An IN endpoint is in the flow control condition after responding to an ACK Transaction Packet with either of the following: A NRDY Transaction Packet. A Data Packet with the End of Burst (EOB) field set to 1, indicating that the packet is the last in a burst. The device sets EOB if the data payload is equal to the endpoint’s maximum packet size and the endpoint is returning fewer than the number of packets requested in the previous ACK Transac- tion Packet. An OUT endpoint is in the flow control condition on responding to a Data Packet with either of the following: A NRDY Transaction Packet. An ACK Transaction Packet with the NumP field set to zero, indicating that the endpoint can’t accept any Data Packets. Hosts retain the option to attempt communications with bulk endpoints in the flow-control condition before receiving ERDY. .KPM/CPCIGOGPV2CEMGVU Link Management Packets have these subtypes: • Set Link Function defines a bit for use in testing. • U2 Inactivity Timeout specifies the timeout for transitioning between low-power states. • Vendor Device Test provides a mechanism for vendor-specific tests. • Port Capabilities indicates if the port can be configured as an upstream-fac- Chapter 2 60 ing port, a downstream-facing port, or both. The ports in a link exchange this packet after initializing the link. For situations where both ports in a link support both port types, a tiebreaker field and protocol determines which port is upstream-facing and which is downstream-facing. • Port Configuration contains a bit to specify a speed of 5 Gbps. A down- stream-facing port sends this packet to its link partner. • Port Configuration Response accepts or rejects a received Port Configura- tion LMP. 61 #6TCPUHGT6[RG HQT'XGT[2WTRQUG This chapter takes a closer look at USB’s four transfer types: control, bulk, interrupt, and isochronous. Each type has features that make it suitable for spe- cific purposes. %QPVTQN6TCPUHGTU Control transfers have two uses. For all devices, control transfers carry the stan- dard requests that the host uses to learn about and configure devices. Control transfers can also carry requests defined by a class or vendor for any purpose. #XCKNCDKNKV[ Every device must support control transfers over the default pipe at endpoint zero. A device may also have additional pipes for control transfers, but in reality there’s no need for more than one. Even if a device needs to send a lot of control requests, hosts allocate bandwidth for control transfers according to the number and size of requests, not by the number of control endpoints, so additional con- trol endpoints offer no advantage. Chapter 3 62 5VTWEVWTG Chapter 2 introduced control transfers and their Setup, Data, and Status stages. Each stage consists of one or more transactions. Every control transfer must have a Setup stage and a Status stage. Not all trans- fers have Data stages, though specific requests can require them. Because every control transfer requires transferring information in both directions, the control transfer’s message pipe uses both the IN and OUT endpoint addresses. In a control write transfer, the data in the Data stage travels from the host to the device. Control transfers that have no Data stage are also considered to be con- trol write transfers. In a control read transfer, the data in the Data stage travels from the device to the host. Figure 3-1 and Figure 3-2 show the stages of con- trol read and control write transfers at low and full speeds on a low/full-speed bus. There are differences, described later in this chapter, for some high-speed transfers, low- and full-speed transfers with USB 2.0 hubs on high-speed buses, and SuperSpeed transfers. In the Setup stage, the host begins a Setup transaction by sending information about the request. The token packet’s SETUP PID identifies the transaction as a Setup transaction that begins a control transfer. The data packet contains eight bytes of information about the request, including the request number, whether or not the transfer has a Data stage, and if so, in which direction the data will travel. The USB 2.0 and USB 3.0 specifications define standard requests. Successful enumeration requires specific responses to some requests, such as the request that sets a device’s address. For other requests, a device can return STALL to indicate that the request isn’t supported. A STALL ends the transfer. A class may require a device to support class-specific requests, and devices can support requests defined by a vendor-specific driver. When present, the Data stage consists of one or more transactions. Depending on the request, the host or peripheral may be the source of the data in these transactions, but all data packets in this stage are in the same direction. The Status stage consists of one IN or OUT transaction where the device reports the success or failure of the transfer. The source of the Status stage’s data packet is the receiver of the data in the Data stage. When there is no Data stage, the device sends the Status stage’s data packet. On completing or abandoning the current transfer, the host can begin a new control transfer. A Transfer Type for Every Purpose 63 Figure 3-1. A USB 2.0 control write transfer contains a Setup transaction, zero or more Data transactions, and a Status transaction. Not shown are the PING protocol used in some high-speed transfers with multiple data packets and the split transactions used with low- and full-speed devices on a high-speed bus. Chapter 3 64 Figure 3-2. A USB 2.0 control read transfer contains a Setup transaction, one or more data transactions, and a status transaction. Not shown are the split transactions used with low- and full-speed devices on a high-speed bus. A Transfer Type for Every Purpose 65 *KIJ5RGGF&KHHGTGPEGU As described in Chapter 2, if a high-speed control write transfer has more than one data packet in the Data stage and the device returns NYET after receiving a data packet, the host may use the PING protocol before sending the next data packet. If a host is performing a control transfer with a low- or full-speed device on a high-speed bus, the host uses split transactions for all of the transfer’s transac- tions. To the device, the transaction is no different than a transaction with a USB 1.x host. The USB 2.0 or USB 3.0 hub nearest the device initiates transac- tions with the device and returns data and status information to the host. 5WRGT5RGGF&KHHGTGPEGU On a SuperSpeed bus, the Setup stage’s Setup Data Packet contains the eight bytes of Setup data. The Data Packet Header uses the following values: Sequence Number = 0 Data Length = 8 Setup = 1 Figure 3-3 shows the structure of a SuperSpeed control write transfer. The host begins the transfer with a Setup Data Packet, and on receiving the packet with- out error, the device responds with an ACK Transaction Packet. If the transfer has a Data stage, the host sends one or more Data Packets, and the device responds to each with an ACK Transaction Packet. If the transfer has multiple Data packets, the Sequence Numbers in the Data and ACK packets increment for each Data packet. In the Status stage, the host sends a STATUS Transaction Packet, and the device returns ACK. Figure 3-4 shows the structure of a SuperSpeed control read transfer., which is identical to a control write transfer except for the Data stage. In the Data stage, the host sends one or more ACK Transaction Packets, and the device responds to each with a Data Packet. A device can control the flow of a control transfer by responding to the Setup Data Packet with an ACK Transaction Packet with NumP = 0 and Sequence Number = 0. The device then requests to start the Data and Status stages by sending an ERDY Transaction Packet. In the Data or Status stage, an endpoint can return a STALL or NRDY Trans- action Packet instead of ACK. A STALL ends the transfer. NRDY halts the transfer until the device returns ERDY. . transac- tions. To the device, the transaction is no different than a transaction with a USB 1.x host. The USB 2.0 or USB 3.0 hub nearest the device initiates transac- tions with the device and returns. not the transfer has a Data stage, and if so, in which direction the data will travel. The USB 2.0 and USB 3.0 specifications define standard requests. Successful enumeration requires specific. packets. 0QVKH[KPIVJG*QUV To conserve bandwidth and to enable inactive links to transition to low-power states, USB 3.0 hosts stop requesting to send or receive data from SuperSpeed endpoints that are in the