[PATCH] libata-ncq: implement ap->qc_active, ap->sactive and complete helper
[deliverable/linux.git] / include / linux / libata.h
index 6a9316cbb70b170aeb529e11a39a516ddb9f4ee5..dd0db2d21bc59aa7e3e51928eaffe9ee110994d2 100644 (file)
@@ -33,6 +33,7 @@
 #include <asm/io.h>
 #include <linux/ata.h>
 #include <linux/workqueue.h>
+#include <scsi/scsi_host.h>
 
 /*
  * compile-time options: to be removed as soon as all the drivers are
@@ -44,7 +45,6 @@
 #undef ATA_NDEBUG              /* define to disable quick runtime checks */
 #undef ATA_ENABLE_PATA         /* define to enable PATA support in some
                                 * low-level drivers */
-#undef ATAPI_ENABLE_DMADIR     /* enables ATAPI DMADIR bridge support */
 
 
 /* note: prints function name for you */
@@ -108,7 +108,9 @@ enum {
        LIBATA_MAX_PRD          = ATA_MAX_PRD / 2,
        ATA_MAX_PORTS           = 8,
        ATA_DEF_QUEUE           = 1,
-       ATA_MAX_QUEUE           = 1,
+       /* tag ATA_MAX_QUEUE - 1 is reserved for internal commands */
+       ATA_MAX_QUEUE           = 2,
+       ATA_TAG_INTERNAL        = ATA_MAX_QUEUE - 1,
        ATA_MAX_SECTORS         = 200,  /* FIXME */
        ATA_MAX_BUS             = 2,
        ATA_DEF_BUSY_WAIT       = 10000,
@@ -120,9 +122,13 @@ enum {
        ATA_SHT_USE_CLUSTERING  = 1,
 
        /* struct ata_device stuff */
-       ATA_DFLAG_LBA48         = (1 << 0), /* device supports LBA48 */
-       ATA_DFLAG_PIO           = (1 << 1), /* device currently in PIO mode */
-       ATA_DFLAG_LBA           = (1 << 2), /* device supports LBA */
+       ATA_DFLAG_LBA           = (1 << 0), /* device supports LBA */
+       ATA_DFLAG_LBA48         = (1 << 1), /* device supports LBA48 */
+       ATA_DFLAG_CDB_INTR      = (1 << 2), /* device asserts INTRQ when ready for CDB */
+       ATA_DFLAG_NCQ           = (1 << 3), /* device supports NCQ */
+       ATA_DFLAG_CFG_MASK      = (1 << 8) - 1,
+
+       ATA_DFLAG_PIO           = (1 << 8), /* device currently in PIO mode */
 
        ATA_DEV_UNKNOWN         = 0,    /* unknown device */
        ATA_DEV_ATA             = 1,    /* ATA device */
@@ -132,43 +138,51 @@ enum {
        ATA_DEV_NONE            = 5,    /* no device */
 
        /* struct ata_port flags */
-       ATA_FLAG_SLAVE_POSS     = (1 << 1), /* host supports slave dev */
+       ATA_FLAG_SLAVE_POSS     = (1 << 0), /* host supports slave dev */
                                            /* (doesn't imply presence) */
-       ATA_FLAG_PORT_DISABLED  = (1 << 2), /* port is disabled, ignore it */
-       ATA_FLAG_SATA           = (1 << 3),
-       ATA_FLAG_NO_LEGACY      = (1 << 4), /* no legacy mode check */
-       ATA_FLAG_SRST           = (1 << 5), /* (obsolete) use ATA SRST, not E.D.D. */
-       ATA_FLAG_MMIO           = (1 << 6), /* use MMIO, not PIO */
-       ATA_FLAG_SATA_RESET     = (1 << 7), /* (obsolete) use COMRESET */
-       ATA_FLAG_PIO_DMA        = (1 << 8), /* PIO cmds via DMA */
-       ATA_FLAG_NOINTR         = (1 << 9), /* FIXME: Remove this once
-                                            * proper HSM is in place. */
-       ATA_FLAG_DEBUGMSG       = (1 << 10),
-       ATA_FLAG_NO_ATAPI       = (1 << 11), /* No ATAPI support */
-
-       ATA_FLAG_SUSPENDED      = (1 << 12), /* port is suspended */
-
-       ATA_FLAG_PIO_LBA48      = (1 << 13), /* Host DMA engine is LBA28 only */
-       ATA_FLAG_IRQ_MASK       = (1 << 14), /* Mask IRQ in PIO xfers */
-
-       ATA_FLAG_FLUSH_PORT_TASK = (1 << 15), /* Flush port task */
-       ATA_FLAG_IN_EH          = (1 << 16), /* EH in progress */
-
-       ATA_QCFLAG_ACTIVE       = (1 << 1), /* cmd not yet ack'd to scsi lyer */
-       ATA_QCFLAG_SG           = (1 << 3), /* have s/g table? */
-       ATA_QCFLAG_SINGLE       = (1 << 4), /* no s/g, just a single buffer */
+       ATA_FLAG_SATA           = (1 << 1),
+       ATA_FLAG_NO_LEGACY      = (1 << 2), /* no legacy mode check */
+       ATA_FLAG_MMIO           = (1 << 3), /* use MMIO, not PIO */
+       ATA_FLAG_SRST           = (1 << 4), /* (obsolete) use ATA SRST, not E.D.D. */
+       ATA_FLAG_SATA_RESET     = (1 << 5), /* (obsolete) use COMRESET */
+       ATA_FLAG_NO_ATAPI       = (1 << 6), /* No ATAPI support */
+       ATA_FLAG_PIO_DMA        = (1 << 7), /* PIO cmds via DMA */
+       ATA_FLAG_PIO_LBA48      = (1 << 8), /* Host DMA engine is LBA28 only */
+       ATA_FLAG_IRQ_MASK       = (1 << 9), /* Mask IRQ in PIO xfers */
+       ATA_FLAG_PIO_POLLING    = (1 << 10), /* use polling PIO if LLD
+                                             * doesn't handle PIO interrupts */
+       ATA_FLAG_NCQ            = (1 << 11), /* host supports NCQ */
+
+       ATA_FLAG_DEBUGMSG       = (1 << 14),
+       ATA_FLAG_FLUSH_PORT_TASK = (1 << 15), /* flush port task */
+
+       ATA_FLAG_EH_PENDING     = (1 << 16), /* EH pending */
+       ATA_FLAG_FROZEN         = (1 << 17), /* port is frozen */
+       ATA_FLAG_RECOVERED      = (1 << 18), /* recovery action performed */
+
+       ATA_FLAG_DISABLED       = (1 << 22), /* port is disabled, ignore it */
+       ATA_FLAG_SUSPENDED      = (1 << 23), /* port is suspended (power) */
+
+       /* bits 24:31 of ap->flags are reserved for LLDD specific flags */
+
+       /* struct ata_queued_cmd flags */
+       ATA_QCFLAG_ACTIVE       = (1 << 0), /* cmd not yet ack'd to scsi lyer */
+       ATA_QCFLAG_SG           = (1 << 1), /* have s/g table? */
+       ATA_QCFLAG_SINGLE       = (1 << 2), /* no s/g, just a single buffer */
        ATA_QCFLAG_DMAMAP       = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE,
-       ATA_QCFLAG_EH_SCHEDULED = (1 << 5), /* EH scheduled */
+       ATA_QCFLAG_IO           = (1 << 3), /* standard IO command */
+       ATA_QCFLAG_RESULT_TF    = (1 << 4), /* result TF requested */
+
+       ATA_QCFLAG_FAILED       = (1 << 16), /* cmd failed and is owned by EH */
+       ATA_QCFLAG_SENSE_VALID  = (1 << 17), /* sense data valid */
+       ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */
 
        /* host set flags */
        ATA_HOST_SIMPLEX        = (1 << 0),     /* Host is simplex, one DMA channel per host_set only */
        
        /* various lengths of time */
-       ATA_TMOUT_PIO           = 30 * HZ,
        ATA_TMOUT_BOOT          = 30 * HZ,      /* heuristic */
        ATA_TMOUT_BOOT_QUICK    = 7 * HZ,       /* heuristic */
-       ATA_TMOUT_CDB           = 30 * HZ,
-       ATA_TMOUT_CDB_QUICK     = 5 * HZ,
        ATA_TMOUT_INTERNAL      = 30 * HZ,
        ATA_TMOUT_INTERNAL_QUICK = 5 * HZ,
 
@@ -207,21 +221,44 @@ enum {
        /* size of buffer to pad xfers ending on unaligned boundaries */
        ATA_DMA_PAD_SZ          = 4,
        ATA_DMA_PAD_BUF_SZ      = ATA_DMA_PAD_SZ * ATA_MAX_QUEUE,
-       
-       /* Masks for port functions */
+
+       /* masks for port functions */
        ATA_PORT_PRIMARY        = (1 << 0),
        ATA_PORT_SECONDARY      = (1 << 1),
+
+       /* ering size */
+       ATA_ERING_SIZE          = 32,
+
+       /* desc_len for ata_eh_info and context */
+       ATA_EH_DESC_LEN         = 80,
+
+       /* reset / recovery action types */
+       ATA_EH_REVALIDATE       = (1 << 0),
+       ATA_EH_SOFTRESET        = (1 << 1),
+       ATA_EH_HARDRESET        = (1 << 2),
+
+       ATA_EH_RESET_MASK       = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
+
+       /* ata_eh_info->flags */
+       ATA_EHI_DID_RESET       = (1 << 0), /* already reset this port */
+
+       /* max repeat if error condition is still set after ->error_handler */
+       ATA_EH_MAX_REPEAT       = 5,
+
+       /* how hard are we gonna try to probe/recover devices */
+       ATA_PROBE_MAX_TRIES     = 3,
+       ATA_EH_RESET_TRIES      = 3,
+       ATA_EH_DEV_TRIES        = 3,
 };
 
 enum hsm_task_states {
-       HSM_ST_UNKNOWN,
-       HSM_ST_IDLE,
-       HSM_ST_POLL,
-       HSM_ST_TMOUT,
-       HSM_ST,
-       HSM_ST_LAST,
-       HSM_ST_LAST_POLL,
-       HSM_ST_ERR,
+       HSM_ST_UNKNOWN,         /* state unknown */
+       HSM_ST_IDLE,            /* no command on going */
+       HSM_ST,                 /* (waiting the device to) transfer data */
+       HSM_ST_LAST,            /* (waiting the device to) complete command */
+       HSM_ST_ERR,             /* error */
+       HSM_ST_FIRST,           /* (waiting the device to)
+                                  write CDB or first data block */
 };
 
 enum ata_completion_errors {
@@ -245,7 +282,7 @@ struct ata_queued_cmd;
 /* typedefs */
 typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
 typedef void (*ata_probeinit_fn_t)(struct ata_port *);
-typedef int (*ata_reset_fn_t)(struct ata_port *, int, unsigned int *);
+typedef int (*ata_reset_fn_t)(struct ata_port *, unsigned int *);
 typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *);
 
 struct ata_ioports {
@@ -294,6 +331,9 @@ struct ata_host_set {
        unsigned int            n_ports;
        void                    *private_data;
        const struct ata_port_operations *ops;
+       unsigned long           flags;
+       int                     simplex_claimed;        /* Keep seperate in case we
+                                                          ever need to do this locked */
        struct ata_port *       ports[0];
 };
 
@@ -333,7 +373,7 @@ struct ata_queued_cmd {
        struct scatterlist      *__sg;
 
        unsigned int            err_mask;
-
+       struct ata_taskfile     result_tf;
        ata_qc_cb_t             complete_fn;
 
        void                    *private_data;
@@ -345,12 +385,24 @@ struct ata_host_stats {
        unsigned long           rw_reqbuf;
 };
 
+struct ata_ering_entry {
+       int                     is_io;
+       unsigned int            err_mask;
+       u64                     timestamp;
+};
+
+struct ata_ering {
+       int                     cursor;
+       struct ata_ering_entry  ring[ATA_ERING_SIZE];
+};
+
 struct ata_device {
+       struct ata_port         *ap;
        u64                     n_sectors;      /* size of device, if ATA */
        unsigned long           flags;          /* ATA_DFLAG_xxx */
        unsigned int            class;          /* ATA_DEV_xxx */
        unsigned int            devno;          /* 0 or 1 */
-       u16                     *id;            /* IDENTIFY xxx DEVICE data */
+       u16                     id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
        u8                      pio_mode;
        u8                      dma_mode;
        u8                      xfer_mode;
@@ -370,6 +422,24 @@ struct ata_device {
        u16                     cylinders;      /* Number of cylinders */
        u16                     heads;          /* Number of heads */
        u16                     sectors;        /* Number of sectors per track */
+
+       /* error history */
+       struct ata_ering        ering;
+};
+
+struct ata_eh_info {
+       struct ata_device       *dev;           /* offending device */
+       u32                     serror;         /* SError from LLDD */
+       unsigned int            err_mask;       /* port-wide err_mask */
+       unsigned int            action;         /* ATA_EH_* action mask */
+       unsigned int            flags;          /* ATA_EHI_* flags */
+       char                    desc[ATA_EH_DESC_LEN];
+       int                     desc_len;
+};
+
+struct ata_eh_context {
+       struct ata_eh_info      i;
+       int                     tries[ATA_MAX_DEVICES];
 };
 
 struct ata_port {
@@ -394,12 +464,21 @@ struct ata_port {
        unsigned int            mwdma_mask;
        unsigned int            udma_mask;
        unsigned int            cbl;    /* cable type; ATA_CBL_xxx */
+       unsigned int            sata_spd_limit; /* SATA PHY speed limit */
+
+       /* record runtime error info, protected by host_set lock */
+       struct ata_eh_info      eh_info;
+       /* EH context owned by EH */
+       struct ata_eh_context   eh_context;
 
        struct ata_device       device[ATA_MAX_DEVICES];
 
        struct ata_queued_cmd   qcmd[ATA_MAX_QUEUE];
-       unsigned long           qactive;
+       unsigned long           qc_allocated;
+       unsigned int            qc_active;
+
        unsigned int            active_tag;
+       u32                     sactive;
 
        struct ata_host_stats   stats;
        struct ata_host_set     *host_set;
@@ -408,12 +487,13 @@ struct ata_port {
        struct work_struct      port_task;
 
        unsigned int            hsm_task_state;
-       unsigned long           pio_task_timeout;
 
        u32                     msg_enable;
        struct list_head        eh_done_q;
 
        void                    *private_data;
+
+       u8                      sector_buf[ATA_SECT_SIZE]; /* owned by EH */
 };
 
 struct ata_port_operations {
@@ -423,6 +503,7 @@ struct ata_port_operations {
 
        void (*set_piomode) (struct ata_port *, struct ata_device *);
        void (*set_dmamode) (struct ata_port *, struct ata_device *);
+       unsigned long (*mode_filter) (const struct ata_port *, struct ata_device *, unsigned long);
 
        void (*tf_load) (struct ata_port *ap, const struct ata_taskfile *tf);
        void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf);
@@ -446,7 +527,15 @@ struct ata_port_operations {
        void (*qc_prep) (struct ata_queued_cmd *qc);
        unsigned int (*qc_issue) (struct ata_queued_cmd *qc);
 
-       void (*eng_timeout) (struct ata_port *ap);
+       /* Error handlers.  ->error_handler overrides ->eng_timeout and
+        * indicates that new-style EH is in place.
+        */
+       void (*eng_timeout) (struct ata_port *ap); /* obsolete */
+
+       void (*freeze) (struct ata_port *ap);
+       void (*thaw) (struct ata_port *ap);
+       void (*error_handler) (struct ata_port *ap);
+       void (*post_internal_cmd) (struct ata_queued_cmd *qc);
 
        irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);
        void (*irq_clear) (struct ata_port *);
@@ -492,18 +581,16 @@ extern void ata_port_probe(struct ata_port *);
 extern void __sata_phy_reset(struct ata_port *ap);
 extern void sata_phy_reset(struct ata_port *ap);
 extern void ata_bus_reset(struct ata_port *ap);
+extern int sata_set_spd(struct ata_port *ap);
 extern int ata_drive_probe_reset(struct ata_port *ap,
                        ata_probeinit_fn_t probeinit,
                        ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
                        ata_postreset_fn_t postreset, unsigned int *classes);
 extern void ata_std_probeinit(struct ata_port *ap);
-extern int ata_std_softreset(struct ata_port *ap, int verbose,
-                            unsigned int *classes);
-extern int sata_std_hardreset(struct ata_port *ap, int verbose,
-                             unsigned int *class);
+extern int ata_std_softreset(struct ata_port *ap, unsigned int *classes);
+extern int sata_std_hardreset(struct ata_port *ap, unsigned int *class);
 extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes);
-extern int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev,
-                             int post_reset);
+extern int ata_dev_revalidate(struct ata_device *dev, int post_reset);
 extern void ata_port_disable(struct ata_port *);
 extern void ata_std_ports(struct ata_ioports *ioaddr);
 #ifdef CONFIG_PCI
@@ -519,21 +606,27 @@ extern void ata_host_set_remove(struct ata_host_set *host_set);
 extern int ata_scsi_detect(struct scsi_host_template *sht);
 extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
 extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
-extern int ata_scsi_error(struct Scsi_Host *host);
-extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
-extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
 extern int ata_scsi_release(struct Scsi_Host *host);
 extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
+extern int sata_scr_valid(struct ata_port *ap);
+extern int sata_scr_read(struct ata_port *ap, int reg, u32 *val);
+extern int sata_scr_write(struct ata_port *ap, int reg, u32 val);
+extern int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val);
+extern int ata_port_online(struct ata_port *ap);
+extern int ata_port_offline(struct ata_port *ap);
 extern int ata_scsi_device_resume(struct scsi_device *);
 extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state);
-extern int ata_device_resume(struct ata_port *, struct ata_device *);
-extern int ata_device_suspend(struct ata_port *, struct ata_device *, pm_message_t state);
+extern int ata_device_resume(struct ata_device *);
+extern int ata_device_suspend(struct ata_device *, pm_message_t state);
 extern int ata_ratelimit(void);
 extern unsigned int ata_busy_sleep(struct ata_port *ap,
                                   unsigned long timeout_pat,
                                   unsigned long timeout);
 extern void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *),
                                void *data, unsigned long delay);
+extern u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
+                            unsigned long interval_msec,
+                            unsigned long timeout_msec);
 
 /*
  * Default driver ops implementations
@@ -569,17 +662,24 @@ extern void ata_bmdma_start (struct ata_queued_cmd *qc);
 extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
 extern u8   ata_bmdma_status(struct ata_port *ap);
 extern void ata_bmdma_irq_clear(struct ata_port *ap);
-extern void __ata_qc_complete(struct ata_queued_cmd *qc);
-extern void ata_eng_timeout(struct ata_port *ap);
-extern void ata_scsi_simulate(struct ata_port *ap, struct ata_device *dev,
-                             struct scsi_cmnd *cmd,
+extern void ata_bmdma_freeze(struct ata_port *ap);
+extern void ata_bmdma_thaw(struct ata_port *ap);
+extern void ata_bmdma_drive_eh(struct ata_port *ap,
+                              ata_reset_fn_t softreset,
+                              ata_reset_fn_t hardreset,
+                              ata_postreset_fn_t postreset);
+extern void ata_bmdma_error_handler(struct ata_port *ap);
+extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
+extern void ata_qc_complete(struct ata_queued_cmd *qc);
+extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active,
+                                   void (*finish_qc)(struct ata_queued_cmd *));
+extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
                              void (*done)(struct scsi_cmnd *));
 extern int ata_std_bios_param(struct scsi_device *sdev,
                              struct block_device *bdev,
                              sector_t capacity, int geom[]);
 extern int ata_scsi_slave_config(struct scsi_device *sdev);
-extern struct ata_device *ata_dev_pair(struct ata_port *ap, 
-                                      struct ata_device *adev);
+extern struct ata_device *ata_dev_pair(struct ata_device *adev);
 
 /*
  * Timing helpers
@@ -625,7 +725,50 @@ extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bit
 extern unsigned long ata_pci_default_filter(const struct ata_port *, struct ata_device *, unsigned long);
 #endif /* CONFIG_PCI */
 
+/*
+ * EH
+ */
+extern void ata_eng_timeout(struct ata_port *ap);
+
+extern void ata_port_schedule_eh(struct ata_port *ap);
+extern int ata_port_abort(struct ata_port *ap);
+extern int ata_port_freeze(struct ata_port *ap);
+
+extern void ata_eh_freeze_port(struct ata_port *ap);
+extern void ata_eh_thaw_port(struct ata_port *ap);
+
+extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
+extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
+
+extern void ata_do_eh(struct ata_port *ap, ata_reset_fn_t softreset,
+                     ata_reset_fn_t hardreset, ata_postreset_fn_t postreset);
+
+/*
+ * printk helpers
+ */
+#define ata_port_printk(ap, lv, fmt, args...) \
+       printk(lv"ata%u: "fmt, (ap)->id , ##args)
+
+#define ata_dev_printk(dev, lv, fmt, args...) \
+       printk(lv"ata%u.%02u: "fmt, (dev)->ap->id, (dev)->devno , ##args)
+
+/*
+ * ata_eh_info helpers
+ */
+#define ata_ehi_push_desc(ehi, fmt, args...) do { \
+       (ehi)->desc_len += scnprintf((ehi)->desc + (ehi)->desc_len, \
+                                    ATA_EH_DESC_LEN - (ehi)->desc_len, \
+                                    fmt , ##args); \
+} while (0)
+
+#define ata_ehi_clear_desc(ehi) do { \
+       (ehi)->desc[0] = '\0'; \
+       (ehi)->desc_len = 0; \
+} while (0)
 
+/*
+ * qc helpers
+ */
 static inline int
 ata_sg_is_last(struct scatterlist *sg, struct ata_queued_cmd *qc)
 {
@@ -668,14 +811,39 @@ static inline unsigned int ata_tag_valid(unsigned int tag)
        return (tag < ATA_MAX_QUEUE) ? 1 : 0;
 }
 
-static inline unsigned int ata_class_present(unsigned int class)
+static inline unsigned int ata_tag_internal(unsigned int tag)
+{
+       return tag == ATA_MAX_QUEUE - 1;
+}
+
+static inline unsigned int ata_class_enabled(unsigned int class)
 {
        return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI;
 }
 
-static inline unsigned int ata_dev_present(const struct ata_device *dev)
+static inline unsigned int ata_class_disabled(unsigned int class)
+{
+       return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP;
+}
+
+static inline unsigned int ata_class_absent(unsigned int class)
+{
+       return !ata_class_enabled(class) && !ata_class_disabled(class);
+}
+
+static inline unsigned int ata_dev_enabled(const struct ata_device *dev)
+{
+       return ata_class_enabled(dev->class);
+}
+
+static inline unsigned int ata_dev_disabled(const struct ata_device *dev)
+{
+       return ata_class_disabled(dev->class);
+}
+
+static inline unsigned int ata_dev_absent(const struct ata_device *dev)
 {
-       return ata_class_present(dev->class);
+       return ata_class_absent(dev->class);
 }
 
 static inline u8 ata_chk_status(struct ata_port *ap)
@@ -756,20 +924,35 @@ static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
        qc->tf.ctl |= ATA_NIEN;
 }
 
-static inline struct ata_queued_cmd *ata_qc_from_tag (struct ata_port *ap,
-                                                     unsigned int tag)
+static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
+                                                      unsigned int tag)
 {
        if (likely(ata_tag_valid(tag)))
                return &ap->qcmd[tag];
        return NULL;
 }
 
-static inline void ata_tf_init(struct ata_port *ap, struct ata_taskfile *tf, unsigned int device)
+static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
+                                                    unsigned int tag)
+{
+       struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
+
+       if (unlikely(!qc) || !ap->ops->error_handler)
+               return qc;
+
+       if ((qc->flags & (ATA_QCFLAG_ACTIVE |
+                         ATA_QCFLAG_FAILED)) == ATA_QCFLAG_ACTIVE)
+               return qc;
+
+       return NULL;
+}
+
+static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
 {
        memset(tf, 0, sizeof(*tf));
 
-       tf->ctl = ap->ctl;
-       if (device == 0)
+       tf->ctl = dev->ap->ctl;
+       if (dev->devno == 0)
                tf->device = ATA_DEVICE_OBS;
        else
                tf->device = ATA_DEVICE_OBS | ATA_DEV1;
@@ -784,26 +967,11 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
        qc->nbytes = qc->curbytes = 0;
        qc->err_mask = 0;
 
-       ata_tf_init(qc->ap, &qc->tf, qc->dev->devno);
-}
-
-/**
- *     ata_qc_complete - Complete an active ATA command
- *     @qc: Command to complete
- *     @err_mask: ATA Status register contents
- *
- *     Indicate to the mid and upper layers that an ATA
- *     command has completed, with either an ok or not-ok status.
- *
- *     LOCKING:
- *     spin_lock_irqsave(host_set lock)
- */
-static inline void ata_qc_complete(struct ata_queued_cmd *qc)
-{
-       if (unlikely(qc->flags & ATA_QCFLAG_EH_SCHEDULED))
-               return;
+       ata_tf_init(qc->dev, &qc->tf);
 
-       __ata_qc_complete(qc);
+       /* init result_tf such that it indicates normal completion */
+       qc->result_tf.command = ATA_DRDY;
+       qc->result_tf.feature = 0;
 }
 
 /**
@@ -882,28 +1050,6 @@ static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)
        return status;
 }
 
-static inline u32 scr_read(struct ata_port *ap, unsigned int reg)
-{
-       return ap->ops->scr_read(ap, reg);
-}
-
-static inline void scr_write(struct ata_port *ap, unsigned int reg, u32 val)
-{
-       ap->ops->scr_write(ap, reg, val);
-}
-
-static inline void scr_write_flush(struct ata_port *ap, unsigned int reg,
-                                  u32 val)
-{
-       ap->ops->scr_write(ap, reg, val);
-       (void) ap->ops->scr_read(ap, reg);
-}
-
-static inline unsigned int sata_dev_present(struct ata_port *ap)
-{
-       return ((scr_read(ap, SCR_STATUS) & 0xf) == 0x3) ? 1 : 0;
-}
-
 static inline int ata_try_flush_cache(const struct ata_device *dev)
 {
        return ata_id_wcache_enabled(dev->id) ||
@@ -941,4 +1087,9 @@ static inline void ata_pad_free(struct ata_port *ap, struct device *dev)
        dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma);
 }
 
+static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
+{
+       return (struct ata_port *) &host->hostdata[0];
+}
+
 #endif /* __LINUX_LIBATA_H__ */
This page took 0.040592 seconds and 5 git commands to generate.