]> err.no Git - linux-2.6/blobdiff - drivers/usb/storage/shuttle_usbat.c
usbserial: fix inconsistent lock state
[linux-2.6] / drivers / usb / storage / shuttle_usbat.c
index 92095b858eb7ff4ad532119f624ccf1d6de9e27f..cb22a9ad16943cfbccdef9356651c1fa4f499342 100644 (file)
@@ -43,7 +43,6 @@
  * 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include <linux/sched.h>
 #include <linux/errno.h>
 #include <linux/slab.h>
 #include <linux/cdrom.h>
@@ -191,9 +190,6 @@ static int usbat_check_status(struct us_data *us)
        unsigned char *reply = us->iobuf;
        int rc;
 
-       if (!us)
-               return USB_STOR_TRANSPORT_ERROR;
-
        rc = usbat_get_status(us, reply);
        if (rc != USB_STOR_XFER_GOOD)
                return USB_STOR_TRANSPORT_FAILED;
@@ -893,22 +889,28 @@ static int usbat_identify_device(struct us_data *us,
  * Set the transport function based on the device type
  */
 static int usbat_set_transport(struct us_data *us,
-                              struct usbat_info *info)
+                              struct usbat_info *info,
+                              int devicetype)
 {
-       int rc;
 
-       if (!info->devicetype) {
-               rc = usbat_identify_device(us, info);
-               if (rc != USB_STOR_TRANSPORT_GOOD) {
-                       US_DEBUGP("usbat_set_transport: Could not identify device\n");
-                       return 1;
-               }
-       }
+       if (!info->devicetype)
+               info->devicetype = devicetype;
 
-       if (usbat_get_device_type(us) == USBAT_DEV_HP8200)
+       if (!info->devicetype)
+               usbat_identify_device(us, info);
+
+       switch (info->devicetype) {
+       default:
+               return USB_STOR_TRANSPORT_ERROR;
+
+       case  USBAT_DEV_HP8200:
                us->transport = usbat_hp8200e_transport;
-       else if (usbat_get_device_type(us) == USBAT_DEV_FLASH)
+               break;
+
+       case USBAT_DEV_FLASH:
                us->transport = usbat_flash_transport;
+               break;
+       }
 
        return 0;
 }
@@ -991,7 +993,8 @@ static int usbat_flash_read_data(struct us_data *us,
        unsigned char  thistime;
        unsigned int totallen, alloclen;
        int len, result;
-       unsigned int sg_idx = 0, sg_offset = 0;
+       unsigned int sg_offset = 0;
+       struct scatterlist *sg = NULL;
 
        result = usbat_flash_check_media(us, info);
        if (result != USB_STOR_TRANSPORT_GOOD)
@@ -1045,7 +1048,7 @@ static int usbat_flash_read_data(struct us_data *us,
        
                /* Store the data in the transfer buffer */
                usb_stor_access_xfer_buf(buffer, len, us->srb,
-                                        &sg_idx, &sg_offset, TO_XFER_BUF);
+                                        &sg, &sg_offset, TO_XFER_BUF);
 
                sector += thistime;
                totallen -= len;
@@ -1081,7 +1084,8 @@ static int usbat_flash_write_data(struct us_data *us,
        unsigned char  thistime;
        unsigned int totallen, alloclen;
        int len, result;
-       unsigned int sg_idx = 0, sg_offset = 0;
+       unsigned int sg_offset = 0;
+       struct scatterlist *sg = NULL;
 
        result = usbat_flash_check_media(us, info);
        if (result != USB_STOR_TRANSPORT_GOOD)
@@ -1120,7 +1124,7 @@ static int usbat_flash_write_data(struct us_data *us,
 
                /* Get the data from the transfer buffer */
                usb_stor_access_xfer_buf(buffer, len, us->srb,
-                                        &sg_idx, &sg_offset, FROM_XFER_BUF);
+                                        &sg, &sg_offset, FROM_XFER_BUF);
 
                /* ATA command 0x30 (WRITE SECTORS) */
                usbat_pack_ata_sector_cmd(command, thistime, sector, 0x30);
@@ -1160,8 +1164,8 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
        unsigned char *buffer;
        unsigned int len;
        unsigned int sector;
-       unsigned int sg_segment = 0;
        unsigned int sg_offset = 0;
+       struct scatterlist *sg = NULL;
 
        US_DEBUGP("handle_read10: transfersize %d\n",
                srb->transfersize);
@@ -1218,9 +1222,6 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
        sector |= short_pack(data[7+5], data[7+4]);
        transferred = 0;
 
-       sg_segment = 0; /* for keeping track of where we are in */
-       sg_offset = 0;  /* the scatter/gather list */
-
        while (transferred != srb->request_bufflen) {
 
                if (len > srb->request_bufflen - transferred)
@@ -1253,7 +1254,7 @@ static int usbat_hp8200e_handle_read10(struct us_data *us,
 
                /* Store the data in the transfer buffer */
                usb_stor_access_xfer_buf(buffer, len, srb,
-                                &sg_segment, &sg_offset, TO_XFER_BUF);
+                                &sg, &sg_offset, TO_XFER_BUF);
 
                /* Update the amount transferred and the sector number */
 
@@ -1316,7 +1317,7 @@ static int usbat_select_and_test_registers(struct us_data *us)
 /*
  * Initialize the USBAT processor and the storage device
  */
-int init_usbat(struct us_data *us)
+static int init_usbat(struct us_data *us, int devicetype)
 {
        int rc;
        struct usbat_info *info;
@@ -1398,7 +1399,7 @@ int init_usbat(struct us_data *us)
        US_DEBUGP("INIT 9\n");
 
        /* At this point, we need to detect which device we are using */
-       if (usbat_set_transport(us, info))
+       if (usbat_set_transport(us, info, devicetype))
                return USB_STOR_TRANSPORT_ERROR;
 
        US_DEBUGP("INIT 10\n");
@@ -1701,6 +1702,22 @@ static int usbat_flash_transport(struct scsi_cmnd * srb, struct us_data *us)
        return USB_STOR_TRANSPORT_FAILED;
 }
 
+int init_usbat_cd(struct us_data *us)
+{
+       return init_usbat(us, USBAT_DEV_HP8200);
+}
+
+
+int init_usbat_flash(struct us_data *us)
+{
+       return init_usbat(us, USBAT_DEV_FLASH);
+}
+
+int init_usbat_probe(struct us_data *us)
+{
+       return init_usbat(us, 0);
+}
+
 /*
  * Default transport function. Attempts to detect which transport function
  * should be called, makes it the new default, and calls it.
@@ -1714,9 +1731,8 @@ int usbat_transport(struct scsi_cmnd *srb, struct us_data *us)
 {
        struct usbat_info *info = (struct usbat_info*) (us->extra);
 
-       if (usbat_set_transport(us, info))
+       if (usbat_set_transport(us, info, 0))
                return USB_STOR_TRANSPORT_ERROR;
 
        return us->transport(srb, us);  
 }
-