|
From: Akinobu M. <mi...@mi...> - 2005-05-23 06:22:20
|
Hello,
I made updated patch for diskdump usb-storage support.
This patch works on all machines and USB mass storages I have.
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/core/Makefile 2.6.9-diskdump-1.0/drivers/usb/core/Makefile
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/Makefile 2005-05-23 14:10:01.653006280 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/core/Makefile 2005-05-23 14:10:22.325863528 +0900
@@ -3,7 +3,7 @@
#
usbcore-objs := usb.o hub.o hcd.o urb.o message.o \
- config.o file.o buffer.o sysfs.o
+ config.o file.o buffer.o sysfs.o poll.o
ifeq ($(CONFIG_PCI),y)
usbcore-objs += hcd-pci.o
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/core/hcd.h 2.6.9-diskdump-1.0/drivers/usb/core/hcd.h
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/hcd.h 2005-05-23 14:10:01.647007192 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/core/hcd.h 2005-05-23 14:10:22.325863528 +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);
/* -------------------------------------------------------------------------- */
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/core/hub.c 2.6.9-diskdump-1.0/drivers/usb/core/hub.c
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/hub.c 2005-05-23 14:10:01.647007192 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/core/hub.c 2005-05-23 14:10:32.186364504 +0900
@@ -27,6 +27,7 @@
#include <linux/usb.h>
#include <linux/usbdevice_fs.h>
#include <linux/suspend.h>
+#include <linux/diskdump.h>
#include <asm/semaphore.h>
#include <asm/uaccess.h>
@@ -1300,9 +1301,18 @@ static int hub_port_wait_reset(struct us
for (delay_time = 0;
delay_time < HUB_RESET_TIMEOUT;
delay_time += delay) {
+
+ /* XXX: USB Controller: Intel Corp. 82801EB/ER (ICH5/ICH5R)
+ * USB2 EHCI Controller (rev 02) needs this */
+ if (crashdump_mode())
+ usb_hcd_poll(hdev->bus->hcpriv);
+
/* wait to give the device a chance to reset */
msleep(delay);
+ if (crashdump_mode())
+ diskdump_update();
+
/* read and decode port status */
ret = hub_port_status(hdev, port, &portstatus, &portchange);
if (ret < 0)
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/core/message.c 2.6.9-diskdump-1.0/drivers/usb/core/message.c
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/message.c 2005-05-23 14:10:01.647007192 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/core/message.c 2005-05-23 14:10:22.326863376 +0900
@@ -63,7 +63,10 @@ static int usb_start_wait_urb(struct urb
/* grr. timeout _should_ include submit delays. */
add_timer(&timer);
}
- wait_for_completion(&done);
+ if (crashdump_mode())
+ usb_dump_wait_for_completion(&done, urb);
+ else
+ wait_for_completion(&done);
status = urb->status;
/* note: HCDs return ETIMEDOUT for other reasons too */
if (status == -ECONNRESET)
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/core/poll.c 2.6.9-diskdump-1.0/drivers/usb/core/poll.c
--- 2.6.9-diskdump-1.0.orig/drivers/usb/core/poll.c 1970-01-01 09:00:00.000000000 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/core/poll.c 2005-05-23 14:10:32.187364352 +0900
@@ -0,0 +1,55 @@
+#include <linux/config.h>
+
+#ifdef CONFIG_USB_DEBUG
+#define DEBUG
+#endif
+
+#include <linux/module.h>
+#include <linux/version.h>
+#include <linux/kernel.h>
+#include <linux/completion.h>
+#include <linux/usb.h>
+#include <linux/diskdump.h>
+
+#include "usb.h"
+#include "hcd.h"
+
+
+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)
+{
+ unsigned long flags;
+
+ might_sleep();
+ spin_lock_irqsave(&x->wait.lock, flags);
+ if (!x->done) {
+ struct usb_hcd *hcd = urb->dev->bus->hcpriv;
+
+ DECLARE_WAITQUEUE(wait, current);
+
+ wait.flags |= WQ_FLAG_EXCLUSIVE;
+ __add_wait_queue_tail(&x->wait, &wait);
+ do {
+ __set_current_state(TASK_UNINTERRUPTIBLE);
+ spin_unlock_irqrestore(&x->wait.lock, flags);
+ usb_hcd_poll(hcd);
+ udelay(100);
+ diskdump_update();
+ spin_lock_irqsave(&x->wait.lock, flags);
+ } while (!x->done);
+ __remove_wait_queue(&x->wait, &wait);
+ }
+ x->done--;
+ spin_unlock_irqrestore(&x->wait.lock, flags);
+}
+EXPORT_SYMBOL (usb_dump_wait_for_completion);
+
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/storage/scsiglue.c 2.6.9-diskdump-1.0/drivers/usb/storage/scsiglue.c
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/scsiglue.c 2005-05-23 14:10:01.644007648 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/storage/scsiglue.c 2005-05-23 14:10:22.327863224 +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" */
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/storage/transport.c 2.6.9-diskdump-1.0/drivers/usb/storage/transport.c
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/transport.c 2005-05-23 14:10:01.643007800 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/storage/transport.c 2005-05-23 14:10:22.327863224 +0900
@@ -60,6 +60,8 @@
#include "usb.h"
#include "debug.h"
+#include "../core/hcd.h"
+
/***********************************************************************
* Data transfer routines
@@ -196,7 +198,10 @@ static int usb_stor_msg_common(struct us
}
/* wait for the completion of the URB */
- wait_for_completion(&urb_done);
+ if (crashdump_mode())
+ usb_dump_wait_for_completion(&urb_done, us->current_urb);
+ else
+ wait_for_completion(&urb_done);
clear_bit(US_FLIDX_URB_ACTIVE, &us->flags);
/* clean up the timeout timer */
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/storage/usb.c 2.6.9-diskdump-1.0/drivers/usb/storage/usb.c
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/usb.c 2005-05-23 14:10:01.628010080 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/storage/usb.c 2005-05-23 14:10:32.187364352 +0900
@@ -272,6 +272,116 @@ 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;
+ }
+
+ /* XXX: USB Controller: Intel Corp. 82371AB/EB/MB PIIX4 USB (rev 01)
+ * fails doing auto-sence */
+ else if ((us->srb->cmnd[0] == MODE_SELECT) ||
+ (us->srb->cmnd[0] == SYNCHRONIZE_CACHE))
+ 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;
diff -Nurp 2.6.9-diskdump-1.0.orig/drivers/usb/storage/usb.h 2.6.9-diskdump-1.0/drivers/usb/storage/usb.h
--- 2.6.9-diskdump-1.0.orig/drivers/usb/storage/usb.h 2005-05-23 14:10:01.645007496 +0900
+++ 2.6.9-diskdump-1.0/drivers/usb/storage/usb.h 2005-05-23 14:10:22.328863072 +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)
|