Received: from list by lists.gnu.org with archive (Exim 4.71) id 1Tevpu-000311-HO for mharc-grub-devel@gnu.org; Sat, 01 Dec 2012 17:47:02 -0500 Received: from eggs.gnu.org ([208.118.235.92]:43040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tevps-00030m-Q9 for grub-devel@gnu.org; Sat, 01 Dec 2012 17:47:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tevpr-0008Da-J3 for grub-devel@gnu.org; Sat, 01 Dec 2012 17:47:00 -0500 Received: from smtp.volny.cz ([62.44.29.27]:57249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tevpr-0008Bj-7t for grub-devel@gnu.org; Sat, 01 Dec 2012 17:46:59 -0500 Received: from [192.168.6.160] (unknown [193.86.90.90]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: starous) by smtp.volny.cz (Postfix) with ESMTPSA id 8E696260A57 for ; Sat, 1 Dec 2012 23:46:56 +0100 (CET) Subject: [PATCH] Long USB transfers problem From: =?UTF-8?Q?Ale=C5=A1?= Nesrsta To: grub-devel@gnu.org Content-Type: multipart/mixed; boundary="=-3Fbj4nXy8m12XLWxcwf6" Date: Sat, 01 Dec 2012 23:46:49 +0100 Message-ID: <1354402009.2479.108.camel@pracovna> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 62.44.29.27 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Dec 2012 22:47:01 -0000 --=-3Fbj4nXy8m12XLWxcwf6 Content-Type: text/plain; charset="ISO-8859-2" Content-Transfer-Encoding: 7bit Hi, I found some USB problem: Some part of GRUB wants read "long" data block from USB mass storage device when GRUB opens USB disk, e.g. when "ls" command is entered first time after EHCI/UHCI/OHCI module is loaded. "Long" means data block of 0x8000 bytes length - it is not too much nowadays :-) But: Some USB devices have too low limit of bulk data packet size, e.g. 32 bytes or less - so, in such case the USB driver needs to use lot of Transfer Descriptors (TDs) to transfer 32Kbytes of data. Unfortunately, number of TDs is limited in GRUB driver(s) - and there is not enough TDs in this situation. The result is internal error, no data transfer is initiated by driver and error code is returned to calling function from usbms.c. It is vary bad situation: USB device receives CBW command to transfer 0x8000 bytes - but transfer of data is never started because driver run out of TDs... Some devices could be automatically recovered from such situation and works normally later when GRUB tries read disk by smaller parts. But some devices remains confused even if they are reset by USBMS specific reset command. So, I wrote simple experimental patch which splits "long" transfer into smaller parts - it looks to solve this issue. Patch solves only read transfer - AFAIK GRUB loader is not designed to write some data into disk, so there probably never be transfer of "long" data block in direction into USB mass storage device. Maximal size 2Kbyte of USB data transfer data block (defined in usbtrans.h) looks to be more or less optimal value. It is probably not critical patch because this situation happens mainly if USB device is full speed device - i.e. this problem is related mainly to very old USB flash disks or some (older) special mass storage devices like GPS devices, cameras, card readers etc. - which will be probably never used as boot devices... (but - who knows...) :-) BR, Ales --=-3Fbj4nXy8m12XLWxcwf6 Content-Disposition: attachment; filename="usb_patch_121201_0" Content-Type: text/x-patch; name="usb_patch_121201_0"; charset="ISO-8859-2" Content-Transfer-Encoding: 7bit --- ./grub/include/grub/usbtrans.h 2012-11-11 21:01:57.000000000 +0100 +++ ./grub_patched/include/grub/usbtrans.h 2012-11-30 21:35:11.000000000 +0100 @@ -19,6 +19,8 @@ #ifndef GRUB_USBTRANS_H #define GRUB_USBTRANS_H 1 +#define MAX_USB_TRANSFER_LEN 0x0800 + typedef enum { GRUB_USB_TRANSFER_TYPE_IN, --- ./grub/grub-core/bus/usb/usbtrans.c 2012-11-11 21:01:57.000000000 +0100 +++ ./grub_patched/grub-core/bus/usb/usbtrans.c 2012-11-30 22:42:04.000000000 +0100 @@ -351,11 +351,23 @@ grub_usb_err_t grub_usb_bulk_read (grub_usb_device_t dev, int endpoint, grub_size_t size, char *data) { - grub_size_t actual; + grub_size_t actual, transferred; grub_usb_err_t err; - err = grub_usb_bulk_readwrite (dev, endpoint, size, data, - GRUB_USB_TRANSFER_TYPE_IN, 1000, &actual); - if (!err && actual != size) + grub_size_t current_size, position; + + for (position = 0, transferred = 0; + position < size; position += MAX_USB_TRANSFER_LEN) + { + current_size = size - position; + if (current_size >= MAX_USB_TRANSFER_LEN) + current_size = MAX_USB_TRANSFER_LEN; + err = grub_usb_bulk_readwrite (dev, endpoint, current_size, + &data[position], GRUB_USB_TRANSFER_TYPE_IN, 1000, &actual); + transferred += actual; + if (err || (current_size != actual) ) break; + } + + if (!err && transferred != size) err = GRUB_USB_ERR_DATA; return err; } --=-3Fbj4nXy8m12XLWxcwf6--