Re: Consultation about max_sectors in Linux SCSI Drivers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jul 11, 2024 at 10:16 PM, 龙重余 wrote:
> Hello!
> 
> 
> I'm sorry to bother you. Here is the problem: My usb storage device
> has a 64kB (limited by hardware) buffer used to cache reads/writes
> which means it can only cache up to 128 blocks(512B) of memory.  The
> SCSI Write-10 and Read-10 command has a total-blocks field that can be
> up to 240 blocks (120kB) for USB2.0.  When originally testing the
> product on Windows 11 it never writes more than 128 blocks at a time
> but when tested on Linux it sometimes writes more than 128 blocks,
> which causes the usb storage device to crash.
> 
> 
> Is there a way to tell the host OS not to request more than 128 blocks?
> I have implemented block limit VPD page, and it works well on Windows
> 10/11.  I even set the block limit to be 64 blocks, it's OK too.
> Because before the data transfer, the windows host issue an SCSI
> inquiry order with the VPD PAGE CODE is 0xB0, so the device could
> transmit the block limits information to the host. And then the
> windows host could adjust the amount of data transferred.
> 
> However, on Linux or MacOS, the host does not appear to be running the
> block limits command.  So the host don't know what is the block
> limits. So the write/read blocks number beyond the buffer size.
> 
> 
> Could you please tell me what can I do to dissolve the problem?

(Note that this is really a SCSI question, not a USB question.)

You tell the Linux host the maximum number of sectors the device's 
hardware can transfer in a single command by writing to the 
max_hw_sectors_kb file in sysfs.  For example, if your device shows up 
as /dev/sdc then you could do:

	echo 64 >/sys/block/sdc/queue/max_hw_sectors_kb

You can even write a udev script to do this for you automatically 
whenever the storage device is detected.

I don't know why this doesn't happen automatically.  Maybe the SCSI 
layer doesn't try to read VPD page 0xb0 on USB mass-storage devices.  
You should be able to find out by asking on the 
linux-scsi@xxxxxxxxxxxxxxx mailing list.

Alan Stern




[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux