forked from len0rd/rockbox
Make usb storage wait for new commands in parallel with sending out the CSW again, for a nice speed improvement.
This is basically the same as was done before r24333, only this time it should be correct. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25542 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
f7b0224a9c
commit
1d94c3fa69
1 changed files with 40 additions and 19 deletions
|
@ -63,6 +63,8 @@
|
||||||
#define READ_BUFFER_SIZE (1024*64)
|
#define READ_BUFFER_SIZE (1024*64)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define MAX_CBW_SIZE 1024
|
||||||
|
|
||||||
#ifdef USB_WRITE_BUFFER_SIZE
|
#ifdef USB_WRITE_BUFFER_SIZE
|
||||||
#define WRITE_BUFFER_SIZE USB_WRITE_BUFFER_SIZE
|
#define WRITE_BUFFER_SIZE USB_WRITE_BUFFER_SIZE
|
||||||
#else
|
#else
|
||||||
|
@ -302,7 +304,8 @@ static enum {
|
||||||
SENDING_FAILED_RESULT,
|
SENDING_FAILED_RESULT,
|
||||||
RECEIVING_BLOCKS,
|
RECEIVING_BLOCKS,
|
||||||
RECEIVING_TIME,
|
RECEIVING_TIME,
|
||||||
SENDING_CSW
|
WAITING_FOR_CSW_COMPLETION_OR_COMMAND,
|
||||||
|
WAITING_FOR_CSW_COMPLETION
|
||||||
} state = WAITING_FOR_COMMAND;
|
} state = WAITING_FOR_COMMAND;
|
||||||
|
|
||||||
static void yearday_to_daymonth(int yd, int y, int *d, int *m)
|
static void yearday_to_daymonth(int yd, int y, int *d, int *m)
|
||||||
|
@ -447,7 +450,7 @@ void usb_storage_init_connection(void)
|
||||||
|
|
||||||
#if CONFIG_CPU == IMX31L || defined(CPU_TCC77X) || defined(CPU_TCC780X) || \
|
#if CONFIG_CPU == IMX31L || defined(CPU_TCC77X) || defined(CPU_TCC780X) || \
|
||||||
defined(BOOTLOADER) || CONFIG_CPU == DM320
|
defined(BOOTLOADER) || CONFIG_CPU == DM320
|
||||||
static unsigned char _cbw_buffer[ALLOCATE_BUFFER_SIZE]
|
static unsigned char _cbw_buffer[MAX_CBW_SIZE]
|
||||||
USB_DEVBSS_ATTR __attribute__((aligned(32)));
|
USB_DEVBSS_ATTR __attribute__((aligned(32)));
|
||||||
cbw_buffer = (void *)_cbw_buffer;
|
cbw_buffer = (void *)_cbw_buffer;
|
||||||
|
|
||||||
|
@ -469,13 +472,13 @@ void usb_storage_init_connection(void)
|
||||||
#else
|
#else
|
||||||
cbw_buffer = (void *)((unsigned int)(audio_buffer+31) & 0xffffffe0);
|
cbw_buffer = (void *)((unsigned int)(audio_buffer+31) & 0xffffffe0);
|
||||||
#endif
|
#endif
|
||||||
tb.transfer_buffer = cbw_buffer + 1024;
|
tb.transfer_buffer = cbw_buffer + MAX_CBW_SIZE;
|
||||||
cpucache_invalidate();
|
cpucache_invalidate();
|
||||||
#ifdef USB_USE_RAMDISK
|
#ifdef USB_USE_RAMDISK
|
||||||
ramdisk_buffer = tb.transfer_buffer + ALLOCATE_BUFFER_SIZE;
|
ramdisk_buffer = tb.transfer_buffer + ALLOCATE_BUFFER_SIZE;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
usb_drv_recv(ep_out, cbw_buffer, 1024);
|
usb_drv_recv(ep_out, cbw_buffer, MAX_CBW_SIZE);
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
for(i=0;i<storage_num_drives();i++) {
|
for(i=0;i<storage_num_drives();i++) {
|
||||||
|
@ -569,27 +572,30 @@ void usb_storage_transfer_complete(int ep,int dir,int status,int length)
|
||||||
cur_sense_data.ascq=0;
|
cur_sense_data.ascq=0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case WAITING_FOR_CSW_COMPLETION_OR_COMMAND:
|
||||||
|
if(dir==USB_DIR_IN) {
|
||||||
|
/* This was the CSW */
|
||||||
|
state = WAITING_FOR_COMMAND;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
/* This was the command */
|
||||||
|
state = WAITING_FOR_CSW_COMPLETION;
|
||||||
|
/* We now have the CBW, but we won't execute it yet to avoid
|
||||||
|
* issues with the still-pending CSW */
|
||||||
|
}
|
||||||
|
break;
|
||||||
case WAITING_FOR_COMMAND:
|
case WAITING_FOR_COMMAND:
|
||||||
if(dir==USB_DIR_IN) {
|
if(dir==USB_DIR_IN) {
|
||||||
logf("IN received in WAITING_FOR_COMMAND");
|
logf("IN received in WAITING_FOR_COMMAND");
|
||||||
}
|
}
|
||||||
//logf("command received");
|
handle_scsi(cbw);
|
||||||
if(letoh32(cbw->signature) == CBW_SIGNATURE) {
|
|
||||||
handle_scsi(cbw);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
usb_drv_stall(ep_in, true,true);
|
|
||||||
usb_drv_stall(ep_out, true,false);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SENDING_CSW:
|
case WAITING_FOR_CSW_COMPLETION:
|
||||||
if(dir==USB_DIR_OUT) {
|
if(dir==USB_DIR_OUT) {
|
||||||
logf("OUT received in SENDING_CSW");
|
logf("OUT received in WAITING_FOR_CSW_COMPLETION");
|
||||||
}
|
}
|
||||||
//logf("csw sent, now go back to idle");
|
handle_scsi(cbw);
|
||||||
state = WAITING_FOR_COMMAND;
|
break;
|
||||||
/* Already start waiting for the next command */
|
|
||||||
usb_drv_recv(ep_out, cbw_buffer, 1024);
|
|
||||||
#if 0
|
#if 0
|
||||||
if(cur_cmd.cur_cmd == SCSI_WRITE_10)
|
if(cur_cmd.cur_cmd == SCSI_WRITE_10)
|
||||||
{
|
{
|
||||||
|
@ -747,6 +753,17 @@ static void handle_scsi(struct command_block_wrapper* cbw)
|
||||||
bool lun_present=true;
|
bool lun_present=true;
|
||||||
unsigned char lun = cbw->lun;
|
unsigned char lun = cbw->lun;
|
||||||
unsigned int block_size_mult = 1;
|
unsigned int block_size_mult = 1;
|
||||||
|
|
||||||
|
if(letoh32(cbw->signature) != CBW_SIGNATURE) {
|
||||||
|
usb_drv_stall(ep_in, true,true);
|
||||||
|
usb_drv_stall(ep_out, true,false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
/* Clear the signature to prevent possible bugs elsewhere
|
||||||
|
* to trigger a second execution of the same command with
|
||||||
|
* bogus data */
|
||||||
|
cbw->signature=0;
|
||||||
|
|
||||||
#ifdef HIDE_FIRST_DRIVE
|
#ifdef HIDE_FIRST_DRIVE
|
||||||
lun++;
|
lun++;
|
||||||
#endif
|
#endif
|
||||||
|
@ -1186,8 +1203,12 @@ static void send_csw(int status)
|
||||||
|
|
||||||
usb_drv_send_nonblocking(ep_in, tb.csw,
|
usb_drv_send_nonblocking(ep_in, tb.csw,
|
||||||
sizeof(struct command_status_wrapper));
|
sizeof(struct command_status_wrapper));
|
||||||
state = SENDING_CSW;
|
state = WAITING_FOR_CSW_COMPLETION_OR_COMMAND;
|
||||||
//logf("CSW: %X",status);
|
//logf("CSW: %X",status);
|
||||||
|
/* Already start waiting for the next command */
|
||||||
|
usb_drv_recv(ep_out, cbw_buffer, MAX_CBW_SIZE);
|
||||||
|
/* The next completed transfer will be either the CSW one
|
||||||
|
* or the new command */
|
||||||
|
|
||||||
if(status == UMS_STATUS_GOOD) {
|
if(status == UMS_STATUS_GOOD) {
|
||||||
cur_sense_data.sense_key=0;
|
cur_sense_data.sense_key=0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue