diff --git a/backend/fujitsu.c b/backend/fujitsu.c index 6f3fc5440..d018f61cf 100644 --- a/backend/fujitsu.c +++ b/backend/fujitsu.c @@ -563,6 +563,9 @@ v122 2014-10-28, MAN - add support for object_position halt - call object_position halt in check_for_cancel when requested + v123 2014-11-06, MAN + - workaround Linux USB3 bugs by adding command counting code and + sending an even number of reads and writes during disconnect_fd SANE FLOW DIAGRAM @@ -612,7 +615,7 @@ #include "fujitsu.h" #define DEBUG 1 -#define BUILD 122 +#define BUILD 123 /* values for SANE_DEBUG_FUJITSU env var: - errors 5 @@ -693,6 +696,9 @@ static int global_buffer_size = 64 * 1024; static const SANE_Device **sane_devArray = NULL; static struct fujitsu *fujitsu_devList = NULL; +static int r_cmd_count = 0; +static int w_cmd_count = 1; + /* * @@ Section 2 - SANE & scanner init code */ @@ -8986,6 +8992,17 @@ disconnect_fd (struct fujitsu *s) if(s->fd > -1){ if (s->connection == CONNECTION_USB) { + + /* if read is odd, make it even */ + if(r_cmd_count % 2){ + wait_scanner(s); + } + + /* if write is odd, make it even */ + if(w_cmd_count % 2){ + get_hardware_status(s,0); + } + DBG (15, "disconnecting usb device\n"); sanei_usb_close (s->fd); } @@ -9471,6 +9488,7 @@ do_usb_cmd(struct fujitsu *s, int runRS, int shortTime, hexdump(30, "cmd: >>", usb_cmdBuff, USB_COMMAND_LEN); ret = sanei_usb_write_bulk(s->fd, usb_cmdBuff, &usb_cmdLen); DBG(25, "cmd: wrote %d bytes, retVal %d\n", (int)usb_cmdLen, ret); + w_cmd_count += (usb_cmdLen+63)/64; if(ret == SANE_STATUS_EOF){ DBG(5,"cmd: got EOF, returning IO_ERROR\n"); @@ -9495,6 +9513,7 @@ do_usb_cmd(struct fujitsu *s, int runRS, int shortTime, hexdump(30, "out: >>", outBuff, outLen); ret = sanei_usb_write_bulk(s->fd, outBuff, &usb_outLen); DBG(25, "out: wrote %d bytes, retVal %d\n", (int)usb_outLen, ret); + w_cmd_count += (usb_outLen+63)/64; if(ret == SANE_STATUS_EOF){ DBG(5,"out: got EOF, returning IO_ERROR\n"); @@ -9524,6 +9543,7 @@ do_usb_cmd(struct fujitsu *s, int runRS, int shortTime, ret = sanei_usb_read_bulk(s->fd, inBuff, inLen); DBG(25, "in: retVal %d\n", ret); + r_cmd_count += (*inLen+63)/64; if(ret == SANE_STATUS_EOF){ DBG(5,"in: got EOF, continuing\n"); @@ -9558,6 +9578,7 @@ do_usb_cmd(struct fujitsu *s, int runRS, int shortTime, ret2 = sanei_usb_read_bulk(s->fd, usb_statBuff, &usb_statLen); hexdump(30, "stat: <<", usb_statBuff, usb_statLen); DBG(25, "stat: read %d bytes, retVal %d\n", (int)usb_statLen, ret2); + r_cmd_count += (usb_statLen+63)/64; if(ret2 == SANE_STATUS_EOF){ DBG(5,"stat: got EOF, returning IO_ERROR\n");