[libata sata_vsc, sata_svw] Convert #define'd constants to enums
[sfrench/cifs-2.6.git] / drivers / scsi / sata_vsc.c
index 2e2c3b7acb0c9a5704b359c2db0719879644e866..fbf0713f9aba74387d14c85d55315111e2b9d6da 100644 (file)
 #include <linux/libata.h>
 
 #define DRV_NAME       "sata_vsc"
-#define DRV_VERSION    "1.1"
-
-/* Interrupt register offsets (from chip base address) */
-#define VSC_SATA_INT_STAT_OFFSET       0x00
-#define VSC_SATA_INT_MASK_OFFSET       0x04
-
-/* Taskfile registers offsets */
-#define VSC_SATA_TF_CMD_OFFSET         0x00
-#define VSC_SATA_TF_DATA_OFFSET                0x00
-#define VSC_SATA_TF_ERROR_OFFSET       0x04
-#define VSC_SATA_TF_FEATURE_OFFSET     0x06
-#define VSC_SATA_TF_NSECT_OFFSET       0x08
-#define VSC_SATA_TF_LBAL_OFFSET                0x0c
-#define VSC_SATA_TF_LBAM_OFFSET                0x10
-#define VSC_SATA_TF_LBAH_OFFSET                0x14
-#define VSC_SATA_TF_DEVICE_OFFSET      0x18
-#define VSC_SATA_TF_STATUS_OFFSET      0x1c
-#define VSC_SATA_TF_COMMAND_OFFSET     0x1d
-#define VSC_SATA_TF_ALTSTATUS_OFFSET   0x28
-#define VSC_SATA_TF_CTL_OFFSET         0x29
-
-/* DMA base */
-#define VSC_SATA_UP_DESCRIPTOR_OFFSET  0x64
-#define VSC_SATA_UP_DATA_BUFFER_OFFSET 0x6C
-#define VSC_SATA_DMA_CMD_OFFSET                0x70
-
-/* SCRs base */
-#define VSC_SATA_SCR_STATUS_OFFSET     0x100
-#define VSC_SATA_SCR_ERROR_OFFSET      0x104
-#define VSC_SATA_SCR_CONTROL_OFFSET    0x108
-
-/* Port stride */
-#define VSC_SATA_PORT_OFFSET           0x200
+#define DRV_VERSION    "1.2"
+
+enum {
+       /* Interrupt register offsets (from chip base address) */
+       VSC_SATA_INT_STAT_OFFSET        = 0x00,
+       VSC_SATA_INT_MASK_OFFSET        = 0x04,
+
+       /* Taskfile registers offsets */
+       VSC_SATA_TF_CMD_OFFSET          = 0x00,
+       VSC_SATA_TF_DATA_OFFSET         = 0x00,
+       VSC_SATA_TF_ERROR_OFFSET        = 0x04,
+       VSC_SATA_TF_FEATURE_OFFSET      = 0x06,
+       VSC_SATA_TF_NSECT_OFFSET        = 0x08,
+       VSC_SATA_TF_LBAL_OFFSET         = 0x0c,
+       VSC_SATA_TF_LBAM_OFFSET         = 0x10,
+       VSC_SATA_TF_LBAH_OFFSET         = 0x14,
+       VSC_SATA_TF_DEVICE_OFFSET       = 0x18,
+       VSC_SATA_TF_STATUS_OFFSET       = 0x1c,
+       VSC_SATA_TF_COMMAND_OFFSET      = 0x1d,
+       VSC_SATA_TF_ALTSTATUS_OFFSET    = 0x28,
+       VSC_SATA_TF_CTL_OFFSET          = 0x29,
+
+       /* DMA base */
+       VSC_SATA_UP_DESCRIPTOR_OFFSET   = 0x64,
+       VSC_SATA_UP_DATA_BUFFER_OFFSET  = 0x6C,
+       VSC_SATA_DMA_CMD_OFFSET         = 0x70,
+
+       /* SCRs base */
+       VSC_SATA_SCR_STATUS_OFFSET      = 0x100,
+       VSC_SATA_SCR_ERROR_OFFSET       = 0x104,
+       VSC_SATA_SCR_CONTROL_OFFSET     = 0x108,
+
+       /* Port stride */
+       VSC_SATA_PORT_OFFSET            = 0x200,
+
+       /* Error interrupt status bit offsets */
+       VSC_SATA_INT_ERROR_CRC          = 0x40,
+       VSC_SATA_INT_ERROR_T            = 0x20,
+       VSC_SATA_INT_ERROR_P            = 0x10,
+       VSC_SATA_INT_ERROR_R            = 0x8,
+       VSC_SATA_INT_ERROR_E            = 0x4,
+       VSC_SATA_INT_ERROR_M            = 0x2,
+       VSC_SATA_INT_PHY_CHANGE         = 0x1,
+       VSC_SATA_INT_ERROR = (VSC_SATA_INT_ERROR_CRC  | VSC_SATA_INT_ERROR_T | \
+                             VSC_SATA_INT_ERROR_P    | VSC_SATA_INT_ERROR_R | \
+                             VSC_SATA_INT_ERROR_E    | VSC_SATA_INT_ERROR_M | \
+                             VSC_SATA_INT_PHY_CHANGE),
+};
+
+
+#define is_vsc_sata_int_err(port_idx, int_status) \
+        (int_status & (VSC_SATA_INT_ERROR << (8 * port_idx)))
 
 
 static u32 vsc_sata_scr_read (struct ata_port *ap, unsigned int sc_reg)
@@ -201,13 +220,34 @@ static irqreturn_t vsc_sata_interrupt (int irq, void *dev_instance,
                        struct ata_port *ap;
 
                        ap = host_set->ports[i];
+
                        if (ap && !(ap->flags &
                                    (ATA_FLAG_PORT_DISABLED|ATA_FLAG_NOINTR))) {
                                struct ata_queued_cmd *qc;
 
                                qc = ata_qc_from_tag(ap, ap->active_tag);
-                               if (qc && (!(qc->tf.ctl & ATA_NIEN)))
+                               if (qc && (!(qc->tf.ctl & ATA_NIEN))) {
                                        handled += ata_host_intr(ap, qc);
+                               } else if (is_vsc_sata_int_err(i, int_status)) {
+                                       /*
+                                        * On some chips (i.e. Intel 31244), an error 
+                                        * interrupt will sneak in at initialization
+                                        * time (phy state changes).  Clearing the SCR
+                                        * error register is not required, but it prevents
+                                        * the phy state change interrupts from recurring 
+                                        * later.
+                                        */
+                                       u32 err_status;
+                                       err_status = vsc_sata_scr_read(ap, SCR_ERROR);
+                                       printk(KERN_DEBUG "%s: clearing interrupt, "
+                                              "status %x; sata err status %x\n",
+                                              __FUNCTION__,
+                                              int_status, err_status);
+                                       vsc_sata_scr_write(ap, SCR_ERROR, err_status);
+                                       /* Clear interrupt status */
+                                       ata_chk_status(ap);
+                                       handled++;
+                               }
                        }
                }
        }
@@ -223,11 +263,11 @@ static struct scsi_host_template vsc_sata_sht = {
        .name                   = DRV_NAME,
        .ioctl                  = ata_scsi_ioctl,
        .queuecommand           = ata_scsi_queuecmd,
+       .eh_timed_out           = ata_scsi_timed_out,
        .eh_strategy_handler    = ata_scsi_error,
        .can_queue              = ATA_DEF_QUEUE,
        .this_id                = ATA_SHT_THIS_ID,
        .sg_tablesize           = LIBATA_MAX_PRD,
-       .max_sectors            = ATA_MAX_SECTORS,
        .cmd_per_lun            = ATA_SHT_CMD_PER_LUN,
        .emulated               = ATA_SHT_EMULATED,
        .use_clustering         = ATA_SHT_USE_CLUSTERING,