|
From: Akinobu M. <mi...@mi...> - 2005-05-06 05:39:51
|
Hello,
I made diskdump support for usb-storage.
This is unusual implemantation as scsi-dump device.
Because queuecommand() on crashdump mode is not executed
asynchronously. So dump_poll() routine does not make sense (never called).
This may be rough implemantation. But these devices are working
as diskdump devices.
- I-O DATA HDPX-U
- BUFFALO ClipDrive (Ours Technology, Inc. OTI-6803 Flash Disk)
The core part of this patch is usb_stor_dump_queuecommand() which is taken
from usb_stor_control_thread():drivers/usb/storage/usb.c
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/hcd.c 2005-04-26 12:50:15.000000000 +0900
+++ 2.6.9-diskdump-1.0-usb-storage/drivers/usb/core/hcd.c 2005-05-06 12:53:52.485459208 +0900
@@ -42,6 +42,7 @@
#include <asm/byteorder.h>
#include <linux/usb.h>
+#include <linux/diskdump.h>
#include "usb.h"
#include "hcd.h"
@@ -1622,3 +1623,43 @@ void usb_hc_died (struct usb_hcd *hcd)
}
EXPORT_SYMBOL (usb_hc_died);
+void usb_hcd_poll(struct usb_hcd *hcd)
+{
+ unsigned long flags;
+
+ local_irq_save(flags);
+ usb_hcd_irq(0, hcd, NULL);
+ local_irq_restore(flags);
+}
+EXPORT_SYMBOL (usb_hcd_poll);
+
+void usb_dump_wait_for_completion(struct completion *x, struct urb *urb)
+{
+ might_sleep();
+ spin_lock_irq(&x->wait.lock);
+ if (!x->done) {
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ __set_current_state(TASK_UNINTERRUPTIBLE);
+ spin_unlock_irq(&x->wait.lock);
+ if (crashdump_mode()) {
+ struct usb_hcd *hcd = urb->dev->bus->hcpriv;
+
+ usb_hcd_poll(hcd);
+ udelay(100);
+ diskdump_update();
+ } else
+ schedule();
+ spin_lock_irq(&x->wait.lock);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+ spin_unlock_irq(&x->wait.lock);
+}
+
+EXPORT_SYMBOL (usb_dump_wait_for_completion);
+
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/hcd.h 2005-04-26 12:50:15.000000000 +0900
+++ 2.6.9-diskdump-1.0-usb-storage/drivers/usb/core/hcd.h 2005-05-06 12:53:52.474460880 +0900
@@ -246,6 +246,9 @@ void hcd_buffer_free (struct usb_bus *bu
extern struct usb_operations usb_hcd_operations;
extern irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs *r);
extern void usb_hc_died (struct usb_hcd *hcd);
+extern void usb_hcd_poll (struct usb_hcd *hcd);
+extern void usb_dump_wait_for_completion (struct completion *x,
+ struct urb *urb);
/* -------------------------------------------------------------------------- */
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/message.c 2005-04-26 12:50:15.000000000 +0900
+++ 2.6.9-diskdump-1.0-usb-storage/drivers/usb/core/message.c 2005-05-06 12:53:52.474460880 +0900
@@ -63,7 +63,7 @@ static int usb_start_wait_urb(struct urb
/* grr. timeout _should_ include submit delays. */
add_timer(&timer);
}
- wait_for_completion(&done);
+ usb_dump_wait_for_completion(&done, urb);
status = urb->status;
/* note: HCDs return ETIMEDOUT for other reasons too */
if (status == -ECONNRESET)
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/scsiglue.c 2005-04-26 12:50:15.000000000 +0900
+++ 2.6.9-diskdump-1.0-usb-storage/drivers/usb/storage/scsiglue.c 2005-05-06 12:59:30.414086248 +0900
@@ -61,6 +61,8 @@
#include "transport.h"
#include "protocol.h"
+#include "../core/hcd.h"
+
/***********************************************************************
* Host functions
***********************************************************************/
@@ -171,6 +173,8 @@ static int queuecommand(struct scsi_cmnd
/* wake up the process task */
up(&(us->sema));
+ if (crashdump_mode())
+ usb_stor_dump_queuecommand(us);
return 0;
}
@@ -410,6 +414,19 @@ static struct device_attribute *sysfs_de
NULL,
};
+int usb_stor_sanity_check(struct scsi_device *sdev)
+{
+ return 0;
+}
+
+static void usb_stor_poll(struct scsi_device *sdev)
+{
+ struct us_data *us = (struct us_data *) sdev->host->hostdata[0];
+ struct usb_hcd *hcd = us->current_urb->dev->bus->hcpriv;
+
+ usb_hcd_poll(hcd);
+}
+
/*
* this defines our host template, with which we'll allocate hosts
*/
@@ -461,7 +478,9 @@ struct scsi_host_template usb_stor_host_
.sdev_attrs = sysfs_device_attr_list,
/* module management */
- .module = THIS_MODULE
+ .module = THIS_MODULE,
+ .dump_sanity_check = usb_stor_sanity_check,
+ .dump_poll = usb_stor_poll,
};
/* For a device that is "Not Ready" */
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/transport.c 2005-04-26 12:50:15.000000000 +0900
+++ 2.6.9-diskdump-1.0-usb-storage/drivers/usb/storage/transport.c 2005-05-06 12:53:52.472461184 +0900
@@ -60,6 +60,8 @@
#include "usb.h"
#include "debug.h"
+#include "../core/hcd.h"
+
/***********************************************************************
* Data transfer routines
@@ -196,7 +198,7 @@ static int usb_stor_msg_common(struct us
}
/* wait for the completion of the URB */
- wait_for_completion(&urb_done);
+ usb_dump_wait_for_completion(&urb_done, us->current_urb);
clear_bit(US_FLIDX_URB_ACTIVE, &us->flags);
/* clean up the timeout timer */
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/usb.c 2005-04-26 12:50:15.000000000 +0900
+++ 2.6.9-diskdump-1.0-usb-storage/drivers/usb/storage/usb.c 2005-05-06 13:19:06.545287128 +0900
@@ -272,6 +272,110 @@ void fill_inquiry_response(struct us_dat
usb_stor_set_xfer_buf(data, data_len, us->srb);
}
+void usb_stor_dump_queuecommand(struct us_data *us)
+{
+ US_DEBUGP("*** thread sleeping.\n");
+ if(down_interruptible(&us->sema)) {
+ return;
+ }
+
+ US_DEBUGP("*** thread awakened.\n");
+
+ /* lock the device pointers */
+ down(&(us->dev_semaphore));
+
+ /* if us->srb is NULL, we are being asked to exit */
+ if (us->srb == NULL) {
+ US_DEBUGP("-- exit command received\n");
+ up(&(us->dev_semaphore));
+ return;
+ }
+
+ /* has the command been aborted *already* ? */
+ if (us->sm_state == US_STATE_ABORTING) {
+ us->srb->result = DID_ABORT << 16;
+ goto SkipForAbort;
+ }
+
+ /* don't do anything if we are disconnecting */
+ if (test_bit(US_FLIDX_DISCONNECTING, &us->flags)) {
+ US_DEBUGP("No command during disconnect\n");
+ goto SkipForDisconnect;
+ }
+
+ /* set the state and release the lock */
+ us->sm_state = US_STATE_RUNNING;
+
+ /* reject the command if the direction indicator
+ * is UNKNOWN
+ */
+ if (us->srb->sc_data_direction == DMA_BIDIRECTIONAL) {
+ US_DEBUGP("UNKNOWN data direction\n");
+ us->srb->result = DID_ERROR << 16;
+ }
+
+ /* reject if target != 0 or if LUN is higher than
+ * the maximum known LUN
+ */
+ else if (us->srb->device->id &&
+ !(us->flags & US_FL_SCM_MULT_TARG)) {
+ US_DEBUGP("Bad target number (%d:%d)\n",
+ us->srb->device->id, us->srb->device->lun);
+ us->srb->result = DID_BAD_TARGET << 16;
+ }
+
+ else if (us->srb->device->lun > us->max_lun) {
+ US_DEBUGP("Bad LUN (%d:%d)\n",
+ us->srb->device->id, us->srb->device->lun);
+ us->srb->result = DID_BAD_TARGET << 16;
+ }
+
+ /* Handle those devices which need us to fake
+ * their inquiry data */
+ else if ((us->srb->cmnd[0] == INQUIRY) &&
+ (us->flags & US_FL_FIX_INQUIRY)) {
+ unsigned char data_ptr[36] = {
+ 0x00, 0x80, 0x02, 0x02,
+ 0x1F, 0x00, 0x00, 0x00};
+
+ US_DEBUGP("Faking INQUIRY command\n");
+ fill_inquiry_response(us, data_ptr, 36);
+ us->srb->result = SAM_STAT_GOOD;
+ }
+
+ /* we've got a command, let's do it! */
+ else {
+ US_DEBUG(usb_stor_show_command(us->srb));
+ us->proto_handler(us->srb, us);
+ }
+
+ /* indicate that the command is done */
+ if (us->srb->result != DID_ABORT << 16) {
+ US_DEBUGP("scsi cmd done, result=0x%x\n",
+ us->srb->result);
+ us->srb->scsi_done(us->srb);
+ } else {
+SkipForAbort:
+ US_DEBUGP("scsi command aborted\n");
+ }
+
+ /* If an abort request was received we need to signal that
+ * the abort has finished. The proper test for this is
+ * sm_state == US_STATE_ABORTING, not srb->result == DID_ABORT,
+ * because an abort request might be received after all the
+ * USB processing was complete. */
+ if (us->sm_state == US_STATE_ABORTING)
+ complete(&(us->notify));
+
+ /* empty the queue, reset the state, and release the lock */
+SkipForDisconnect:
+ us->srb = NULL;
+ us->sm_state = US_STATE_IDLE;
+
+ /* unlock the device pointers */
+ up(&(us->dev_semaphore));
+}
+
static int usb_stor_control_thread(void * __us)
{
struct us_data *us = (struct us_data *)__us;
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/usb.h 2005-04-26 12:50:15.000000000 +0900
+++ 2.6.9-diskdump-1.0-usb-storage/drivers/usb/storage/usb.h 2005-05-06 12:58:35.135489872 +0900
@@ -174,6 +174,8 @@ extern struct usb_driver usb_storage_dri
extern void fill_inquiry_response(struct us_data *us,
unsigned char *data, unsigned int data_len);
+extern void usb_stor_dump_queuecommand(struct us_data *us);
+
/* The scsi_lock() and scsi_unlock() macros protect the sm_state and the
* single queue element srb for write access */
#define scsi_unlock(host) spin_unlock_irq(host->host_lock)
|