SA-1110 Bulk Transfer Encapsulation                             Stuart Lynne
Lineo                                           Thu Mar 15 13:38:16 PST 2001 


1. Bulk Transfer Encapsulation

There are two problems with the SA-1110 UDC USB Device that affect the link
level:

        - the UDC cannot send empty, zero byte, packets 

        - the UDC can silently corrupt outbound packets


The design of the UDC transmit uses packetsize-1 in an 8-bit register to
define the size of the outgoing packet. This allows packetsizes from 1 to
256 but does not allow for zero. 

A documented problem with the DMA engine supplying data to the UDC for
transfer is that it can sometimes provide the same byte of data twice (i.e.
        the address increment fails between two successive data requests).

USB Bulk data transfers allow for large amounts of data to be sent across
the USB bus in multiple data packets and still identified as a single set of
data when received.  The end of the bulk transfer is identified by a packet
of data that is less than the full packet size. 

If the size of the data transfer is a multiple of the packet size then an
empty (zero byte) packet is sent.

This leads to two requirements for the SA-1110 link level design:

    - need to be able to detect data corruption 
   
    - need to be able to terminate bulk transfers that are a multiple of the
    packetsize

The simplest method to detect data corruption is to use a 16bit CRC. This is
sufficent to protect bulk data transfers up to 4096 bytes in length. The
algorithm used is the same as that used by PPP as defined in RFC 1662.

The sender calculates a 16 bit CRC along the data and appends it to the data
before sending. The receiver calculates the same CRC along the received data
and if the results are correct it removes the last two bytes and passes the
correct amount of data up.

This algorithm is additionaly complicated by the other problem. The SA-1110
cannot send an empty packet to signal the end of the size of a  bulk
transfer (the data plus CRC) is an exact multiple of the packet size. This
is solved by sending a data packet containing a single byte of data.

The receiver must now handle three different scenarios:

        0                               packetsize 
        |                               |
    A.  |................|FCS|FCS| 
    B.  |.......................|FCS|FCS|XXX|
    C.  |...........................|FCS|FCS|
                                        

    A. The default case, the data plus FCS bytes is not a multiple of the
    packet size, process normally, test FCS and if successful discard the
    two FCS bytes.

    B. The received data is one more than the packet size. The receiver must
    check if the CRC is correct one byte early. If the test is successful
    then it discards three bytes (two FCS and the additional padding byte).

    C. The received data is one more than the packet size and the CRC test
    at the packet boundary failed, test again with the last byte and if
    successful discard the two FCS bytes.


The Bulk Transfer mechanism described above provides for a mechanism for
transferring data that has the following characteristics:

    - arbitrary data sizes supported

    - data received correctly or not at all

This means that there is no additional requirement for a size within the
data being transferred. The size received is what was sent.

It also means that while the data that is received is correct; it is possible
for data to be silently lost.


2. Function Specific Encapsulation

There are two function applictions:

    - serial

    - network

Both of these just use the bulk transfer mechanism without additional
encapsulation. The serial function just passes all data through without
any additional processing. 

The network function transfers the 802.3 data frames.



