From 655b9736c5e8e23ede082c2c62860bf4f5e52704 Mon Sep 17 00:00:00 2001 From: ValdikSS Date: Wed, 27 Sep 2023 17:02:34 +0300 Subject: [PATCH] xerox_mfp: skip ENDPOINT CLEAR HALT command by default Some xerox_mfp scanners, such as Samsung SCX-4521F, hangs when their OUT ENDPOINT receives CLEAR HALT command, which is performed in usb open and close functions of the backend. The issue seem to be dependant on USB controller and assumingly happens due to some sort of incompatibility of USB implementation in the scanner. Skip sending this command by default and add SANE_XEROX_USB_HALT_WORKAROUND env variable to execute CLEAR HALT commands. --- backend/xerox_mfp-usb.c | 23 +++++++++++++++++++++-- doc/sane-usb.man | 9 +++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/backend/xerox_mfp-usb.c b/backend/xerox_mfp-usb.c index 6ef1eeae8..519aba611 100644 --- a/backend/xerox_mfp-usb.c +++ b/backend/xerox_mfp-usb.c @@ -21,6 +21,21 @@ extern int sanei_debug_xerox_mfp; +static int +xerox_need_clear_halt() +{ + char *env; + int workaround = 0; + + env = getenv("SANE_XEROX_USB_HALT_WORKAROUND"); + if (env) { + workaround = atoi(env); + DBG(5, "xerox_need_clear_halt: workaround: %d\n", workaround); + return workaround; + } + return 0; +} + int usb_dev_request(struct device *dev, SANE_Byte *cmd, size_t cmdlen, @@ -70,7 +85,9 @@ usb_dev_open(struct device *dev) dev->dn = -1; return status; } - sanei_usb_clear_halt(dev->dn); + if (xerox_need_clear_halt()) { + sanei_usb_clear_halt(dev->dn); + } return SANE_STATUS_GOOD; } @@ -92,7 +109,9 @@ usb_dev_close(struct device *dev) ret_cancel(dev, 0); } - sanei_usb_clear_halt(dev->dn); /* unstall for next users */ + if (xerox_need_clear_halt()) { + sanei_usb_clear_halt(dev->dn); /* unstall for next users */ + } sanei_usb_close(dev->dn); dev->dn = -1; } diff --git a/doc/sane-usb.man b/doc/sane-usb.man index 3fd90e44b..a885ee88e 100644 --- a/doc/sane-usb.man +++ b/doc/sane-usb.man @@ -178,6 +178,15 @@ setting the environment variable to 1. This may work around issues which happen with particular kernel versions. Example: .I export SANE_USB_WORKAROUND=1. +.TP +.B SANE_XEROX_USB_HALT_WORKAROUND +If your old (pre-2010) Xerox / Samsung / HP scanner is detected +only once and subsequent usage requires replugging the cable, try +setting the environment variable +.B SANE_XEROX_USB_HALT_WORKAROUND +to 1. This may work around issues which happen with particular USB +controllers. Example: +.I export SANE_XEROX_USB_HALT_WORKAROUND=1. .SH "SEE ALSO" .BR sane (7),