usb_master: Store maximum packet size for bulk endpoints

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Use endpoint size for bulk transfer size

Do not hardcode the packet size to 64 bytes, but instead use the value from
the endpoint descriptor.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Create buffer for storing leftover data

The device will send data in chunks of the endpoint size until it finishes
sending the entire range given in set_address(). When we are requested to
read less than that, we need to store the excess data until the next read.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Invalidate read buffer on set_address calls

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Empty read buffer before reading new data from chip

For every readn() call, data which exists in the read buffer must be placed
before any new data from the chip.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Keep track of range after a set_address() call

Knowing the address range is needed in order to know how much data to
expect from the USB device.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Return when no async transfers is to be used

The asynchronous transfer loop is only concerned with transfers of endpoint
sized packets. When there is less than a packet worth of data to transfer,
return immediately.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Update address range on successful bulk read

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Return an error on out of range reads

When we are requested to read more data than what was specified in
set_address(), return immediately with an error.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Print the address range which is being read

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Handle leftover transfers on bulk read

Handle readn() requests for which the last transfer is not a multiple of
the endpoint size. The last transfer usually requires buffering, and is
handled separately from the other transfers.

This change allows the qiprog's test_alignment to complete succesfully.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
qiprog: Implement chip program action

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
qiprog: Return the result of read, write, or verify actions

Only the result of run_tests() was returned to the caller. The result og
other actions was not returned, instead returning EXIT_FAILURE. Return the
actual result.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Remove misleading comment in do_async_bulkin()

Leftover transactions are already handled safely, so the FIXME comment
describing the issue no longer applies.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Rename do_async_bulkin to do_async_bulk_transfers

This function handles both IN and OUT transactions, so rename it to reflect
that and to avoid confusion.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>
usb_master: Implement bulk programming of flash chip

This implements replaces the 'writen' stub with a fully functional bulk OUT
implementation.

Signed-off-by: Alexandru Gagniuc <mr.nuke.me@gmail.com>