mass_storage: speed up MSD by increasing SCSI read/write buffer

This commit is contained in:
Andrey Gusakov 2025-02-13 17:35:54 +03:00 committed by rusefillc
parent d89c07635b
commit 86fb107d70
3 changed files with 9 additions and 7 deletions

View File

@ -161,7 +161,7 @@ static const scsi_unit_serial_number_inquiry_response_t default_scsi_unit_serial
};
void MassStorageController::attachLun(uint8_t lunIndex,
BaseBlockDevice *blkdev, uint8_t *blkbuf,
BaseBlockDevice *blkdev, uint8_t *blkbuf, size_t blkbufsize,
const scsi_inquiry_response_t *inquiry,
const scsi_unit_serial_number_inquiry_response_t *serialInquiry) {
chibios_rt::MutexLocker lock(m_lunMutex);
@ -182,6 +182,7 @@ void MassStorageController::attachLun(uint8_t lunIndex,
lun.config.unit_serial_number_inquiry_response = serialInquiry;
}
lun.config.blkbuf = blkbuf;
lun.config.blkbufsize = blkbufsize;
lun.config.blkdev = blkdev;
lun.config.transport = &m_scsiTransport;

View File

@ -16,7 +16,7 @@ class MassStorageController : public ThreadController<USB_MSD_THREAD_WA_SIZE> {
public:
MassStorageController(USBDriver* usb);
void attachLun(uint8_t lunIndex, BaseBlockDevice *blkdev, uint8_t *blkbuf,
void attachLun(uint8_t lunIndex, BaseBlockDevice *blkdev, uint8_t *blkbuf, size_t blkbufsize,
const scsi_inquiry_response_t *inquiry,
const scsi_unit_serial_number_inquiry_response_t *serialInquiry);
protected:

View File

@ -43,7 +43,8 @@
// One block buffer per LUN
static NO_CACHE uint8_t blkbuf0[MMCSD_BLOCK_SIZE];
static NO_CACHE uint8_t blkbuf1[MMCSD_BLOCK_SIZE];
// Speed-up SD card
static NO_CACHE uint8_t blkbuf1[4 * MMCSD_BLOCK_SIZE];
static MassStorageController msd(usb_driver);
@ -76,7 +77,7 @@ static const scsi_inquiry_response_t sdCardInquiry = {
};
void attachMsdSdCard(BaseBlockDevice* blkdev) {
msd.attachLun(1, blkdev, blkbuf1, &sdCardInquiry, nullptr);
msd.attachLun(1, blkdev, blkbuf1, sizeof(blkbuf1), &sdCardInquiry, nullptr);
#if EFI_TUNER_STUDIO
// SD MSD attached, enable indicator in TS
@ -85,7 +86,7 @@ void attachMsdSdCard(BaseBlockDevice* blkdev) {
}
void deattachMsdSdCard(void) {
msd.attachLun(1, (BaseBlockDevice*)&ND1, blkbuf1, &sdCardInquiry, nullptr);
msd.attachLun(1, (BaseBlockDevice*)&ND1, blkbuf1, sizeof(blkbuf1), &sdCardInquiry, nullptr);
#if EFI_TUNER_STUDIO
// SD MSD attached, enable indicator in TS
@ -123,10 +124,10 @@ static BaseBlockDevice* getRamdiskDevice() {
void initUsbMsd() {
// Attach the ini ramdisk
msd.attachLun(0, getRamdiskDevice(), blkbuf0, &iniDriveInquiry, nullptr);
msd.attachLun(0, getRamdiskDevice(), blkbuf0, sizeof(blkbuf0), &iniDriveInquiry, nullptr);
// attach a null device in place of the SD card for now - the SD thread may replace it later
msd.attachLun(1, (BaseBlockDevice*)&ND1, blkbuf1, &sdCardInquiry, nullptr);
msd.attachLun(1, (BaseBlockDevice*)&ND1, blkbuf1, sizeof(blkbuf1), &sdCardInquiry, nullptr);
// start the mass storage thread
msd.start();