From f1a9c3c21468099abed6e55837d8bf0559f3e789 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Fri, 4 Apr 2008 23:46:14 +0000 Subject: [PATCH] Implement a downcounter for the synchronize cache command. There are devices that do not support it (probably because they do not have a cache at all like in flash media) and this should at least avoid spamming the syslog when this is the case. It will try 5 times and then disable syncing for that device. Untested as of yet though. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24803 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/disk/usb/usb_disk/usb_disk.cpp | 12 ++++++++++++ .../kernel/drivers/disk/usb/usb_disk/usb_disk.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp index 84bd530139..c955045bcd 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.cpp @@ -436,10 +436,21 @@ usb_disk_update_capacity(device_lun *lun) status_t usb_disk_synchronize(device_lun *lun, bool force) { + if (lun->device->sync_support == 0) { + // this device repeatedly reported an illegal request when syncing + // it obviously does really not support this command... + return B_UNSUPPORTED; + } + if (lun->should_sync || force) { status_t result = usb_disk_operation(lun, SCSI_SYNCHRONIZE_CACHE_10, 10, 0, 0, NULL, NULL, false); lun->should_sync = false; + + if (result == B_OK) + lun->device->sync_support = SYNC_SUPPORT_RELOAD; + else if (result == B_DEV_INVALID_IOCTL) + lun->device->sync_support--; return result; } @@ -474,6 +485,7 @@ usb_disk_device_added(usb_device newDevice, void **cookie) device->open_count = 0; device->interface = 0xff; device->current_tag = 0; + device->sync_support = SYNC_SUPPORT_RELOAD; device->luns = NULL; // scan through the interfaces to find our bulk-only data interface diff --git a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h index c57909cf74..34a693255d 100644 --- a/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h +++ b/src/add-ons/kernel/drivers/disk/usb/usb_disk/usb_disk.h @@ -25,6 +25,8 @@ #define CSW_STATUS_COMMAND_FAILED 0x01 #define CSW_STATUS_PHASE_ERROR 0x02 +#define SYNC_SUPPORT_RELOAD 5 + typedef struct device_lun_s device_lun; // holds common information about an attached device (pointed to by luns) @@ -40,6 +42,7 @@ typedef struct disk_device_s { usb_pipe bulk_out; uint8 interface; uint32 current_tag; + uint8 sync_support; // used to store callback information sem_id notify;