Lines Matching +full:write +full:- +full:host
45 * The protocol for the USB-SPI bridge is implemented in the following files
57 * a response. The initial packet from host contains a 2B header indicating
58 * write and read counts with an optional payload length equal to the write
65 * Command First Packet (Host to Device):
67 * USB SPI command, containing the number of bytes to write and read
68 * and a payload of bytes to write.
70 * +------------------+-----------------+------------------------+
71 * | write count : 1B | read count : 1B | write payload : <= 62B |
72 * +------------------+-----------------+------------------------+
74 * write count: 1 byte, zero based count of bytes to write
79 * write payload: Up to 62 bytes of data to write to SPI, the total
80 * length of all TX packets must match write count.
84 * Response Packet (Device to Host):
89 * +-------------+-----------------------+
91 * +-------------+-----------------------+
99 * 0x0003: Write count invalid (over 62 bytes)
129 * Example: USB SPI request with 128 byte write and 0 byte read.
131 * Packet #1 Host to Device:
133 * write count = 128
135 * payload = First 58 bytes from the write buffer,
139 * Packet #2 Host to Device:
142 * payload = Next 60 bytes from the write buffer,
146 * Packet #3 Host to Device:
149 * payload = Next 10 bytes from the write buffer,
153 * Packet #4 Device to Host:
159 * Example: USB SPI request with 2 byte write and 100 byte read.
161 * Packet #1 Host to Device:
163 * write count = 2
165 * payload = The 2 byte write buffer
168 * Packet #2 Device to Host:
175 * Packet #3 Device to Host:
185 * Command Start Packet (Host to Device):
187 * Start of the USB SPI command, contains the number of bytes to write
188 * and read on SPI and up to the first 58 bytes of write payload.
192 * +----------------+------------------+-----------------+---------------+
193 * | packet id : 2B | write count : 2B | read count : 2B | w.p. : <= 58B |
194 * +----------------+------------------+-----------------+---------------+
199 * write count: 2 byte, zero based count of bytes to write
203 * equal to the write count.
205 * write payload: Up to 58 bytes of data to write to SPI, the total
206 * length of all TX packets must match write count.
211 * Response Start Packet (Device to Host):
218 * +----------------+------------------+-----------------------+
220 * +----------------+------------------+-----------------------+
231 * 0x0003: Write count invalid. The byte limit is platform specific
238 * 0x0007: The RX endpoint has received more data than write count.
260 * +----------------+-----------------+-------------------------------+
261 * | packet id : 2B | data index : 2B | write / read payload : <= 60B |
262 * +----------------+-----------------+-------------------------------+
267 * indicates the packet is being transmitted from the host
268 * to the device and contains SPI write payload.
271 * to the host and contains SPI read payload.
274 * read or write buffers that have already been transmitted.
280 * read and write payload:
282 * the SPI write buffer or from the SPI read buffer.
285 * Command Get Configuration Packet (Host to Device):
288 * the number of bytes it can write and read.
290 * +----------------+
292 * +----------------+
296 * Response Configuration Packet (Device to Host):
298 * Response packet form the device to report the maximum write and
301 * +----------------+----------------+---------------+----------------+
302 * | packet id : 2B | max write : 2B | max read : 2B | feature bitmap |
303 * +----------------+----------------+---------------+----------------+
307 * max write count: 2 byte count of the maximum number of bytes
308 * the device can write to SPI in one transaction.
317 * Command Restart Response Packet (Host to Device):
320 * the host to recover from a lost packet when reading the response
323 * +----------------+
325 * +----------------+
334 * 0x00001-0x0FFFF: Error code returned by the USB SPI device.
335 * 0x10001-0x1FFFF: Error code returned by the USB SPI host.
336 * 0x20001-0x20063 Lower bits store the positive value representation
338 * http://libusb.sourceforge.net/api-1.0/group__misc.html
371 /* The host failed to transfer the data with no libusb error. */
398 /* The RX endpoint has received more data than write count. */
508 * Start a USB SPI transfer specifying number of bytes to write,
509 * read and deliver first packet of data to write.
512 /* Additional packets containing write payload. */
606 * if we attempt to write SPI data to the device or read from it. We know
634 return (struct raiden_debug_spi_data *)flash->mst->spi.data; in get_raiden_data_from_context()
650 size_t max_read_length = dst->receive_size - dst->receive_index; in read_usb_packet()
651 size_t bytes_in_buffer = src->packet_size - src->header_size; in read_usb_packet()
652 const uint8_t *packet_buffer = src->bytes + src->header_size; in read_usb_packet()
665 dst->receive_size, dst->receive_index); in read_usb_packet()
668 memcpy(dst->buffer + dst->receive_index, packet_buffer, in read_usb_packet()
671 dst->receive_index += bytes_in_buffer; in read_usb_packet()
684 size_t transmit_size = src->transmit_size - src->transmit_index; in fill_usb_packet()
685 size_t max_buffer_size = USB_MAX_PACKET_SIZE - dst->header_size; in fill_usb_packet()
686 uint8_t *packet_buffer = dst->bytes + dst->header_size; in fill_usb_packet()
691 memcpy(packet_buffer, src->buffer + src->transmit_index, transmit_size); in fill_usb_packet()
693 dst->packet_size = dst->header_size + transmit_size; in fill_usb_packet()
694 src->transmit_index += transmit_size; in fill_usb_packet()
709 int status = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle, in receive_packet()
710 ctx_data->in_ep, in receive_packet()
711 packet->bytes, in receive_packet()
715 packet->packet_size = received; in receive_packet()
729 * @param packet Source packet we will write to the endpoint data.
737 int status = LIBUSB(libusb_bulk_transfer(ctx_data->dev->handle, in transmit_packet()
738 ctx_data->out_ep, in transmit_packet()
739 packet->bytes, in transmit_packet()
740 packet->packet_size, in transmit_packet()
743 if (status || (size_t)transferred != packet->packet_size) { in transmit_packet()
752 transferred, packet->packet_size, status); in transmit_packet()
759 * Version 1 protocol command to start a USB SPI transfer and write the payload.
762 * @param write Write context of data to transmit and write payload.
768 struct usb_spi_transmit_ctx *write, in write_command_v1() argument
773 .packet_v1.command.write_count = write->transmit_size, in write_command_v1()
774 .packet_v1.command.read_count = read->receive_size in write_command_v1()
777 /* Reset the write context to the start. */ in write_command_v1()
778 write->transmit_index = 0; in write_command_v1()
780 fill_usb_packet(&command, write); in write_command_v1()
790 * @param write Write context of data to transmit and write payload.
796 struct usb_spi_transmit_ctx *write, in read_response_v1() argument
803 read->receive_index = 0; in read_response_v1()
826 * @param write_count Number of bytes to write
828 * @param write_buffer Address of write buffer
839 int status = -1; in send_command_v1()
851 if (write_count > ctx_data->max_spi_write_count) { in send_command_v1()
852 msg_perr("Raiden: Invalid write count\n" in send_command_v1()
853 " write count = %u\n" in send_command_v1()
854 " max write = %d\n", in send_command_v1()
855 write_count, ctx_data->max_spi_write_count); in send_command_v1()
859 if (read_count > ctx_data->max_spi_read_count) { in send_command_v1()
863 read_count, ctx_data->max_spi_read_count); in send_command_v1()
875 /* No errors were reported, but write is incomplete. */ in send_command_v1()
880 /* Write operation failed. */ in send_command_v1()
881 msg_perr("Raiden: Write command failed\n" in send_command_v1()
883 " write count = %u\n" in send_command_v1()
886 " write attempt = %u\n" in send_command_v1()
888 ctx_data->protocol_version, in send_command_v1()
917 " write count = %u\n" in send_command_v1()
920 " write attempt = %u\n" in send_command_v1()
923 ctx_data->protocol_version, in send_command_v1()
938 * Get the USB SPI configuration with the maximum write and read counts, and
989 ctx_data->max_spi_write_count = in get_spi_config_v2()
991 ctx_data->max_spi_read_count = in get_spi_config_v2()
1000 const size_t err_packet_size = sizeof(struct usb_spi_response_v2) - in get_spi_config_v2()
1044 * Version 2 Protocol: command to start a USB SPI transfer and write the payload.
1047 * @param write Write context of data to transmit and write payload.
1053 struct usb_spi_transmit_ctx *write, in write_command_v2() argument
1062 .packet_v2.cmd_start.write_count = write->transmit_size, in write_command_v2()
1063 .packet_v2.cmd_start.read_count = read->receive_size in write_command_v2()
1066 /* Reset the write context to the start. */ in write_command_v2()
1067 write->transmit_index = 0; in write_command_v2()
1069 fill_usb_packet(&start_usb_spi_packet, write); in write_command_v2()
1075 while (write->transmit_index < write->transmit_size) { in write_command_v2()
1081 write->transmit_index; in write_command_v2()
1083 fill_usb_packet(&continue_packet, write); in write_command_v2()
1098 * @param write Write context of data to transmit and write payload.
1104 struct usb_spi_transmit_ctx *write, in read_response_v2() argument
1107 int status = -1; in read_response_v2()
1111 read->receive_index = 0; in read_response_v2()
1122 * The host should only see this packet if an error occurs in read_response_v2()
1128 if (read->receive_index) { in read_response_v2()
1138 if (read->receive_index != in read_response_v2()
1142 read->receive_index); in read_response_v2()
1155 } while (read->receive_index < read->receive_size); in read_response_v2()
1172 * @param write_count Number of bytes to write
1174 * @param write_buffer Address of write buffer
1187 int status = -1; in send_command_v2()
1200 if (write_count > ctx_data->max_spi_write_count) { in send_command_v2()
1201 msg_perr("Raiden: Invalid write count\n" in send_command_v2()
1202 " write count = %u\n" in send_command_v2()
1203 " max write = %u\n", in send_command_v2()
1204 write_count, ctx_data->max_spi_write_count); in send_command_v2()
1208 if (read_count > ctx_data->max_spi_read_count) { in send_command_v2()
1212 read_count, ctx_data->max_spi_read_count); in send_command_v2()
1223 /* No errors were reported, but write is incomplete. */ in send_command_v2()
1228 /* Write operation failed. */ in send_command_v2()
1229 msg_perr("Raiden: Write command failed\n" in send_command_v2()
1231 " write count = %u\n" in send_command_v2()
1234 " write attempt = %u\n" in send_command_v2()
1236 ctx_data->protocol_version, in send_command_v2()
1265 " write count = %u\n" in send_command_v2()
1268 " write attempt = %u\n" in send_command_v2()
1271 ctx_data->protocol_version, in send_command_v2()
1290 struct spi_master *spi_config = ctx_data->spi_config; in raiden_debug_spi_shutdown()
1293 ctx_data->dev->handle, in raiden_debug_spi_shutdown()
1299 ctx_data->dev->interface_descriptor->bInterfaceNumber, in raiden_debug_spi_shutdown()
1310 usb_device_free(ctx_data->dev); in raiden_debug_spi_shutdown()
1331 return (((descriptor->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK) == in match_endpoint()
1333 ((descriptor->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK) == in match_endpoint()
1343 for (i = 0; i < dev->interface_descriptor->bNumEndpoints; i++) { in find_endpoints()
1345 &dev->interface_descriptor->endpoint[i]; in find_endpoints()
1349 *in_ep = endpoint->bEndpointAddress; in find_endpoints()
1352 *out_ep = endpoint->bEndpointAddress; in find_endpoints()
1383 struct spi_master *spi_config = ctx_data->spi_config; in configure_protocol()
1385 ctx_data->protocol_version = in configure_protocol()
1386 ctx_data->dev->interface_descriptor->bInterfaceProtocol; in configure_protocol()
1388 switch (ctx_data->protocol_version) { in configure_protocol()
1392 * read and write sizes which results in no continue packets. in configure_protocol()
1394 spi_config->command = send_command_v1; in configure_protocol()
1395 ctx_data->max_spi_write_count = SPI_TRANSFER_V1_MAX; in configure_protocol()
1396 ctx_data->max_spi_read_count = SPI_TRANSFER_V1_MAX; in configure_protocol()
1400 * Protocol V2 requires the host to query the device for in configure_protocol()
1401 * its maximum read and write sizes in configure_protocol()
1403 spi_config->command = send_command_v2; in configure_protocol()
1411 ctx_data->protocol_version); in configure_protocol()
1417 * of bytes that your SPI device can read/write, these values are the maximum in configure_protocol()
1426 spi_config->max_data_write = ctx_data->max_spi_write_count - in configure_protocol()
1428 spi_config->max_data_read = ctx_data->max_spi_read_count - in configure_protocol()
1446 ap_request = -1; in get_ap_request_type()
1496 dev = dev->next; in free_dev_list()
1563 if (libusb_get_device_descriptor(device->device, &descriptor)) { in raiden_debug_spi_init()
1568 rc = libusb_get_string_descriptor_ascii(device->handle, in raiden_debug_spi_init()
1602 device->handle, in raiden_debug_spi_init()
1608 device->interface_descriptor->bInterfaceNumber, in raiden_debug_spi_init()
1619 * Load switches can have a 1-3 ms turn on time, and SPI flash devices in raiden_debug_spi_init()
1620 * can require up to 10 ms from power on to the first write. in raiden_debug_spi_init()
1640 data->dev = device; in raiden_debug_spi_init()
1641 data->in_ep = in_endpoint; in raiden_debug_spi_init()
1642 data->out_ep = out_endpoint; in raiden_debug_spi_init()
1643 data->spi_config = spi_config; in raiden_debug_spi_init()
1648 * the write and read sizes and switch command functions. in raiden_debug_spi_init()
1655 data->dev->interface_descriptor->bInterfaceProtocol, ret); in raiden_debug_spi_init()