vserver 2.0 rc7
[linux-2.6.git] / drivers / usb / storage / isd200.c
index 7bb613f..ecb328a 100644 (file)
 
 /* Include files */
 
+#include <linux/jiffies.h>
+#include <linux/errno.h>
+#include <linux/slab.h>
+#include <linux/hdreg.h>
+#include <linux/ide.h>
+
+#include <scsi/scsi.h>
+#include <scsi/scsi_cmnd.h>
+#include <scsi/scsi_device.h>
+
+#include "usb.h"
 #include "transport.h"
 #include "protocol.h"
-#include "usb.h"
 #include "debug.h"
 #include "scsiglue.h"
 #include "isd200.h"
 
-#include <linux/jiffies.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/hdreg.h>
-#include <linux/ide.h>
 
 /* Timeout defines (in Seconds) */
 
@@ -290,8 +295,8 @@ struct isd200_info {
  */
 
 struct read_capacity_data {
-       unsigned long LogicalBlockAddress;
-       unsigned long BytesPerBlock;
+       __be32 LogicalBlockAddress;
+       __be32 BytesPerBlock;
 };
 
 /*
@@ -349,7 +354,7 @@ struct sense_data {
  * RETURNS:
  *    void
  */
-void isd200_build_sense(struct us_data *us, Scsi_Cmnd *srb)
+static void isd200_build_sense(struct us_data *us, struct scsi_cmnd *srb)
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        struct sense_data *buf = (struct sense_data *) &srb->sense_buffer[0];
@@ -427,7 +432,7 @@ static int isd200_action( struct us_data *us, int action,
                ata.generic.RegisterSelect =
                  REG_CYLINDER_LOW | REG_CYLINDER_HIGH |
                  REG_STATUS | REG_ERROR;
-               srb->sc_data_direction = SCSI_DATA_READ;
+               srb->sc_data_direction = DMA_FROM_DEVICE;
                srb->request_buffer = pointer;
                srb->request_bufflen = value;
                break;
@@ -439,7 +444,7 @@ static int isd200_action( struct us_data *us, int action,
                                           ACTION_SELECT_5;
                ata.generic.RegisterSelect = REG_DEVICE_HEAD;
                ata.write.DeviceHeadByte = value;
-               srb->sc_data_direction = SCSI_DATA_NONE;
+               srb->sc_data_direction = DMA_NONE;
                break;
 
        case ACTION_RESET:
@@ -448,7 +453,7 @@ static int isd200_action( struct us_data *us, int action,
                                           ACTION_SELECT_3|ACTION_SELECT_4;
                ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
                ata.write.DeviceControlByte = ATA_DC_RESET_CONTROLLER;
-               srb->sc_data_direction = SCSI_DATA_NONE;
+               srb->sc_data_direction = DMA_NONE;
                break;
 
        case ACTION_REENABLE:
@@ -457,7 +462,7 @@ static int isd200_action( struct us_data *us, int action,
                                           ACTION_SELECT_3|ACTION_SELECT_4;
                ata.generic.RegisterSelect = REG_DEVICE_CONTROL;
                ata.write.DeviceControlByte = ATA_DC_REENABLE_CONTROLLER;
-               srb->sc_data_direction = SCSI_DATA_NONE;
+               srb->sc_data_direction = DMA_NONE;
                break;
 
        case ACTION_SOFT_RESET:
@@ -466,14 +471,14 @@ static int isd200_action( struct us_data *us, int action,
                ata.generic.RegisterSelect = REG_DEVICE_HEAD | REG_COMMAND;
                ata.write.DeviceHeadByte = info->DeviceHead;
                ata.write.CommandByte = WIN_SRST;
-               srb->sc_data_direction = SCSI_DATA_NONE;
+               srb->sc_data_direction = DMA_NONE;
                break;
 
        case ACTION_IDENTIFY:
                US_DEBUGP("   isd200_action(IDENTIFY)\n");
                ata.generic.RegisterSelect = REG_COMMAND;
                ata.write.CommandByte = WIN_IDENTIFY;
-               srb->sc_data_direction = SCSI_DATA_READ;
+               srb->sc_data_direction = DMA_FROM_DEVICE;
                srb->request_buffer = (void *) info->id;
                srb->request_bufflen = sizeof(struct hd_driveid);
                break;
@@ -505,7 +510,7 @@ static int isd200_action( struct us_data *us, int action,
  * RETURNS:
  *    ISD status code
  */
-int isd200_read_regs( struct us_data *us )
+static int isd200_read_regs( struct us_data *us )
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        int retStatus = ISD200_GOOD;
@@ -534,8 +539,8 @@ int isd200_read_regs( struct us_data *us )
  * This is used by the protocol layers to actually send the message to
  * the device and receive the response.
  */
-void isd200_invoke_transport( struct us_data *us, 
-                             Scsi_Cmnd *srb, 
+static void isd200_invoke_transport( struct us_data *us, 
+                             struct scsi_cmnd *srb, 
                              union ata_cdb *ataCdb )
 {
        int need_auto_sense = 0;
@@ -550,7 +555,7 @@ void isd200_invoke_transport( struct us_data *us,
        /* if the command gets aborted by the higher layers, we need to
         * short-circuit all other processing
         */
-       if (us->sm_state == US_STATE_ABORTING) {
+       if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
                US_DEBUGP("-- command was aborted\n");
                goto Handle_Abort;
        }
@@ -597,7 +602,7 @@ void isd200_invoke_transport( struct us_data *us,
 
        if (need_auto_sense) {
                result = isd200_read_regs(us);
-               if (us->sm_state == US_STATE_ABORTING) {
+               if (test_bit(US_FLIDX_TIMED_OUT, &us->flags)) {
                        US_DEBUGP("-- auto-sense aborted\n");
                        goto Handle_Abort;
                }
@@ -677,7 +682,7 @@ static void isd200_log_config( struct isd200_info* info )
  * RETURNS:
  *    ISD status code
  */
-int isd200_write_config( struct us_data *us ) 
+static int isd200_write_config( struct us_data *us ) 
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        int retStatus = ISD200_GOOD;
@@ -720,7 +725,7 @@ int isd200_write_config( struct us_data *us )
  * RETURNS:
  *    ISD status code
  */
-int isd200_read_config( struct us_data *us ) 
+static int isd200_read_config( struct us_data *us ) 
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        int retStatus = ISD200_GOOD;
@@ -765,7 +770,7 @@ int isd200_read_config( struct us_data *us )
  * RETURNS:
  *    NT status code
  */
-int isd200_atapi_soft_reset( struct us_data *us ) 
+static int isd200_atapi_soft_reset( struct us_data *us ) 
 {
        int retStatus = ISD200_GOOD;
        int transferStatus;
@@ -791,7 +796,7 @@ int isd200_atapi_soft_reset( struct us_data *us )
  * RETURNS:
  *    ISD status code
  */
-int isd200_srst( struct us_data *us ) 
+static int isd200_srst( struct us_data *us ) 
 {
        int retStatus = ISD200_GOOD;
        int transferStatus;
@@ -806,7 +811,7 @@ int isd200_srst( struct us_data *us )
                retStatus = ISD200_ERROR;
        } else {
                /* delay 10ms to give the drive a chance to see it */
-               wait_ms(10);
+               msleep(10);
 
                transferStatus = isd200_action( us, ACTION_REENABLE, NULL, 0 );
                if (transferStatus != ISD200_TRANSPORT_GOOD) {
@@ -814,7 +819,7 @@ int isd200_srst( struct us_data *us )
                        retStatus = ISD200_ERROR;
                } else {
                        /* delay 50ms to give the drive a chance to recover after SRST */
-                       wait_ms(50);
+                       msleep(50);
                }
        }
 
@@ -839,7 +844,7 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
        unsigned long endTime;
        struct isd200_info *info = (struct isd200_info *)us->extra;
        unsigned char *regs = info->RegsBuf;
-       int recheckAsMaster = FALSE;
+       int recheckAsMaster = 0;
 
        if ( detect )
                endTime = jiffies + ISD200_ENUM_DETECT_TIMEOUT * HZ;
@@ -847,7 +852,7 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
                endTime = jiffies + ISD200_ENUM_BSY_TIMEOUT * HZ;
 
        /* loop until we detect !BSY or timeout */
-       while(TRUE) {
+       while(1) {
 #ifdef CONFIG_USB_STORAGE_DEBUG
                char* mstr = master_slave == ATA_ADDRESS_DEVHEAD_STD ?
                        "Master" : "Slave";
@@ -899,9 +904,9 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
                           itself okay as a master also
                        */
                        if ((master_slave & ATA_ADDRESS_DEVHEAD_SLAVE) &&
-                           (recheckAsMaster == FALSE)) {
+                           !recheckAsMaster) {
                                US_DEBUGP("   Identified ATAPI device as slave.  Rechecking again as master\n");
-                               recheckAsMaster = TRUE;
+                               recheckAsMaster = 1;
                                master_slave = ATA_ADDRESS_DEVHEAD_STD;
                        } else {
                                US_DEBUGP("   Identified ATAPI device\n");
@@ -937,7 +942,7 @@ static int isd200_try_enum(struct us_data *us, unsigned char master_slave,
  * RETURNS:
  *    ISD status code
  */
-int isd200_manual_enum(struct us_data *us)
+static int isd200_manual_enum(struct us_data *us)
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        int retStatus = ISD200_GOOD;
@@ -948,15 +953,15 @@ int isd200_manual_enum(struct us_data *us)
        if (retStatus == ISD200_GOOD) {
                int isslave;
                /* master or slave? */
-               retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, FALSE );
+               retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, 0);
                if (retStatus == ISD200_GOOD)
-                       retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_SLAVE, FALSE );
+                       retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_SLAVE, 0);
 
                if (retStatus == ISD200_GOOD) {
                        retStatus = isd200_srst(us);
                        if (retStatus == ISD200_GOOD)
                                /* ata or atapi? */
-                               retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, TRUE );
+                               retStatus = isd200_try_enum( us, ATA_ADDRESS_DEVHEAD_STD, 1);
                }
 
                isslave = (info->DeviceHead & ATA_ADDRESS_DEVHEAD_SLAVE) ? 1 : 0;
@@ -981,7 +986,7 @@ int isd200_manual_enum(struct us_data *us)
  * RETURNS:
  *    ISD status code
  */
-int isd200_get_inquiry_data( struct us_data *us )
+static int isd200_get_inquiry_data( struct us_data *us )
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        int retStatus = ISD200_GOOD;
@@ -1011,7 +1016,8 @@ int isd200_get_inquiry_data( struct us_data *us )
                        } else {
                                /* ATA Command Identify successful */
                                int i;
-                               __u16 *src, *dest;
+                               __be16 *src;
+                               __u16 *dest;
                                ide_fix_driveid(id);
 
                                US_DEBUGP("   Identify Data Structure:\n");
@@ -1047,12 +1053,6 @@ int isd200_get_inquiry_data( struct us_data *us )
                                /* Standard IDE interface only supports disks */
                                info->InquiryData.DeviceType = DIRECT_ACCESS_DEVICE;
 
-                               /* Fix-up the return data from an INQUIRY command to show 
-                                * ANSI SCSI rev 2 so we don't confuse the SCSI layers above us
-                                * in Linux.
-                                */
-                               info->InquiryData.Versions = 0x2;
-
                                /* The length must be at least 36 (5 + 31) */
                                info->InquiryData.AdditionalLength = 0x1F;
 
@@ -1063,17 +1063,17 @@ int isd200_get_inquiry_data( struct us_data *us )
                                }
 
                                /* Fill in vendor identification fields */
-                               src = (__u16*)id->model;
+                               src = (__be16*)id->model;
                                dest = (__u16*)info->InquiryData.VendorId;
                                for (i=0;i<4;i++)
                                        dest[i] = be16_to_cpu(src[i]);
 
-                               src = (__u16*)(id->model+8);
+                               src = (__be16*)(id->model+8);
                                dest = (__u16*)info->InquiryData.ProductId;
                                for (i=0;i<8;i++)
                                        dest[i] = be16_to_cpu(src[i]);
 
-                               src = (__u16*)id->fw_rev;
+                               src = (__be16*)id->fw_rev;
                                dest = (__u16*)info->InquiryData.ProductRevisionLevel;
                                for (i=0;i<2;i++)
                                        dest[i] = be16_to_cpu(src[i]);
@@ -1121,15 +1121,15 @@ int isd200_get_inquiry_data( struct us_data *us )
  * Translate SCSI commands to ATA commands.
  *
  * RETURNS:
- *    TRUE if the command needs to be sent to the transport layer
- *    FALSE otherwise
+ *    1 if the command needs to be sent to the transport layer
+ *    0 otherwise
  */
-int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us, 
-                      union ata_cdb * ataCdb)
+static int isd200_scsi_to_ata(struct scsi_cmnd *srb, struct us_data *us,
+                             union ata_cdb * ataCdb)
 {
        struct isd200_info *info = (struct isd200_info *)us->extra;
        struct hd_driveid *id = info->id;
-       int sendToTransport = TRUE;
+       int sendToTransport = 1;
        unsigned char sectnum, head;
        unsigned short cylinder;
        unsigned long lba;
@@ -1147,7 +1147,7 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
                usb_stor_set_xfer_buf((unsigned char *) &info->InquiryData,
                                sizeof(info->InquiryData), srb);
                srb->result = SAM_STAT_GOOD;
-               sendToTransport = FALSE;
+               sendToTransport = 0;
                break;
 
        case MODE_SENSE:
@@ -1167,7 +1167,7 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
                } else {
                        US_DEBUGP("   Media Status not supported, just report okay\n");
                        srb->result = SAM_STAT_GOOD;
-                       sendToTransport = FALSE;
+                       sendToTransport = 0;
                }
                break;
 
@@ -1185,7 +1185,7 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
                } else {
                        US_DEBUGP("   Media Status not supported, just report okay\n");
                        srb->result = SAM_STAT_GOOD;
-                       sendToTransport = FALSE;
+                       sendToTransport = 0;
                }
                break;
 
@@ -1209,15 +1209,14 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
                usb_stor_set_xfer_buf((unsigned char *) &readCapacityData,
                                sizeof(readCapacityData), srb);
                srb->result = SAM_STAT_GOOD;
-               sendToTransport = FALSE;
+               sendToTransport = 0;
        }
        break;
 
        case READ_10:
                US_DEBUGP("   ATA OUT - SCSIOP_READ\n");
 
-               lba = *(unsigned long *)&srb->cmnd[2]; 
-               lba = cpu_to_be32(lba);
+               lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]);
                blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8];
 
                if (id->capability & CAPABILITY_LBA) {
@@ -1249,8 +1248,7 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
        case WRITE_10:
                US_DEBUGP("   ATA OUT - SCSIOP_WRITE\n");
 
-               lba = *(unsigned long *)&srb->cmnd[2]; 
-               lba = cpu_to_be32(lba);
+               lba = be32_to_cpu(*(__be32 *)&srb->cmnd[2]);
                blockCount = (unsigned long)srb->cmnd[7]<<8 | (unsigned long)srb->cmnd[8];
 
                if (id->capability & CAPABILITY_LBA) {
@@ -1293,7 +1291,7 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
                } else {
                        US_DEBUGP("   Not removeable media, just report okay\n");
                        srb->result = SAM_STAT_GOOD;
-                       sendToTransport = FALSE;
+                       sendToTransport = 0;
                }
                break;
 
@@ -1319,14 +1317,14 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
                } else {
                        US_DEBUGP("   Nothing to do, just report okay\n");
                        srb->result = SAM_STAT_GOOD;
-                       sendToTransport = FALSE;
+                       sendToTransport = 0;
                }
                break;
 
        default:
                US_DEBUGP("Unsupported SCSI command - 0x%X\n", srb->cmnd[0]);
                srb->result = DID_ERROR << 16;
-               sendToTransport = FALSE;
+               sendToTransport = 0;
                break;
        }
 
@@ -1339,7 +1337,7 @@ int isd200_scsi_to_ata(Scsi_Cmnd *srb, struct us_data *us,
  *
  * Frees the driver structure.
  */
-void isd200_free_info_ptrs(void *info_)
+static void isd200_free_info_ptrs(void *info_)
 {
        struct isd200_info *info = (struct isd200_info *) info_;
 
@@ -1357,7 +1355,7 @@ void isd200_free_info_ptrs(void *info_)
  * RETURNS:
  *    ISD status code
  */
-int isd200_init_info(struct us_data *us)
+static int isd200_init_info(struct us_data *us)
 {
        int retStatus = ISD200_GOOD;
        struct isd200_info *info;
@@ -1424,9 +1422,9 @@ int isd200_Initialization(struct us_data *us)
  *
  */
 
-void isd200_ata_command(Scsi_Cmnd *srb, struct us_data *us)
+void isd200_ata_command(struct scsi_cmnd *srb, struct us_data *us)
 {
-       int sendToTransport = TRUE;
+       int sendToTransport = 1;
        union ata_cdb ataCdb;
 
        /* Make sure driver was initialized */