aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/linux/ata.h34
-rw-r--r--include/linux/libata.h379
-rw-r--r--include/scsi/scsi_cmnd.h1
-rw-r--r--include/scsi/scsi_eh.h1
-rw-r--r--include/scsi/scsi_host.h1
5 files changed, 302 insertions, 114 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 312a2c0c64..c494e1c053 100644
--- a/include/linux/ata.h
+++ b/include/linux/ata.h
@@ -97,6 +97,9 @@ enum {
97 ATA_DRQ = (1 << 3), /* data request i/o */ 97 ATA_DRQ = (1 << 3), /* data request i/o */
98 ATA_ERR = (1 << 0), /* have an error */ 98 ATA_ERR = (1 << 0), /* have an error */
99 ATA_SRST = (1 << 2), /* software reset */ 99 ATA_SRST = (1 << 2), /* software reset */
100 ATA_ICRC = (1 << 7), /* interface CRC error */
101 ATA_UNC = (1 << 6), /* uncorrectable media error */
102 ATA_IDNF = (1 << 4), /* ID not found */
100 ATA_ABORTED = (1 << 2), /* command aborted */ 103 ATA_ABORTED = (1 << 2), /* command aborted */
101 104
102 /* ATA command block registers */ 105 /* ATA command block registers */
@@ -130,6 +133,8 @@ enum {
130 ATA_CMD_WRITE = 0xCA, 133 ATA_CMD_WRITE = 0xCA,
131 ATA_CMD_WRITE_EXT = 0x35, 134 ATA_CMD_WRITE_EXT = 0x35,
132 ATA_CMD_WRITE_FUA_EXT = 0x3D, 135 ATA_CMD_WRITE_FUA_EXT = 0x3D,
136 ATA_CMD_FPDMA_READ = 0x60,
137 ATA_CMD_FPDMA_WRITE = 0x61,
133 ATA_CMD_PIO_READ = 0x20, 138 ATA_CMD_PIO_READ = 0x20,
134 ATA_CMD_PIO_READ_EXT = 0x24, 139 ATA_CMD_PIO_READ_EXT = 0x24,
135 ATA_CMD_PIO_WRITE = 0x30, 140 ATA_CMD_PIO_WRITE = 0x30,
@@ -148,6 +153,10 @@ enum {
148 ATA_CMD_INIT_DEV_PARAMS = 0x91, 153 ATA_CMD_INIT_DEV_PARAMS = 0x91,
149 ATA_CMD_READ_NATIVE_MAX = 0xF8, 154 ATA_CMD_READ_NATIVE_MAX = 0xF8,
150 ATA_CMD_READ_NATIVE_MAX_EXT = 0x27, 155 ATA_CMD_READ_NATIVE_MAX_EXT = 0x27,
156 ATA_CMD_READ_LOG_EXT = 0x2f,
157
158 /* READ_LOG_EXT pages */
159 ATA_LOG_SATA_NCQ = 0x10,
151 160
152 /* SETFEATURES stuff */ 161 /* SETFEATURES stuff */
153 SETFEATURES_XFER = 0x03, 162 SETFEATURES_XFER = 0x03,
@@ -192,6 +201,16 @@ enum {
192 SCR_ACTIVE = 3, 201 SCR_ACTIVE = 3,
193 SCR_NOTIFICATION = 4, 202 SCR_NOTIFICATION = 4,
194 203
204 /* SError bits */
205 SERR_DATA_RECOVERED = (1 << 0), /* recovered data error */
206 SERR_COMM_RECOVERED = (1 << 1), /* recovered comm failure */
207 SERR_DATA = (1 << 8), /* unrecovered data error */
208 SERR_PERSISTENT = (1 << 9), /* persistent data/comm error */
209 SERR_PROTOCOL = (1 << 10), /* protocol violation */
210 SERR_INTERNAL = (1 << 11), /* host internal error */
211 SERR_PHYRDY_CHG = (1 << 16), /* PHY RDY changed */
212 SERR_DEV_XCHG = (1 << 26), /* device exchanged */
213
195 /* struct ata_taskfile flags */ 214 /* struct ata_taskfile flags */
196 ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */ 215 ATA_TFLAG_LBA48 = (1 << 0), /* enable 48-bit LBA and "HOB" */
197 ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */ 216 ATA_TFLAG_ISADDR = (1 << 1), /* enable r/w to nsect/lba regs */
@@ -199,6 +218,7 @@ enum {
199 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */ 218 ATA_TFLAG_WRITE = (1 << 3), /* data dir: host->dev==1 (write) */
200 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */ 219 ATA_TFLAG_LBA = (1 << 4), /* enable LBA */
201 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */ 220 ATA_TFLAG_FUA = (1 << 5), /* enable FUA */
221 ATA_TFLAG_POLLING = (1 << 6), /* set nIEN to 1 and use polling */
202}; 222};
203 223
204enum ata_tf_protocols { 224enum ata_tf_protocols {
@@ -207,6 +227,7 @@ enum ata_tf_protocols {
207 ATA_PROT_NODATA, /* no data */ 227 ATA_PROT_NODATA, /* no data */
208 ATA_PROT_PIO, /* PIO single sector */ 228 ATA_PROT_PIO, /* PIO single sector */
209 ATA_PROT_DMA, /* DMA */ 229 ATA_PROT_DMA, /* DMA */
230 ATA_PROT_NCQ, /* NCQ */
210 ATA_PROT_ATAPI, /* packet command, PIO data xfer*/ 231 ATA_PROT_ATAPI, /* packet command, PIO data xfer*/
211 ATA_PROT_ATAPI_NODATA, /* packet command, no data */ 232 ATA_PROT_ATAPI_NODATA, /* packet command, no data */
212 ATA_PROT_ATAPI_DMA, /* packet command with special DMA sauce */ 233 ATA_PROT_ATAPI_DMA, /* packet command with special DMA sauce */
@@ -262,6 +283,8 @@ struct ata_taskfile {
262#define ata_id_has_pm(id) ((id)[82] & (1 << 3)) 283#define ata_id_has_pm(id) ((id)[82] & (1 << 3))
263#define ata_id_has_lba(id) ((id)[49] & (1 << 9)) 284#define ata_id_has_lba(id) ((id)[49] & (1 << 9))
264#define ata_id_has_dma(id) ((id)[49] & (1 << 8)) 285#define ata_id_has_dma(id) ((id)[49] & (1 << 8))
286#define ata_id_has_ncq(id) ((id)[76] & (1 << 8))
287#define ata_id_queue_depth(id) (((id)[75] & 0x1f) + 1)
265#define ata_id_removeable(id) ((id)[0] & (1 << 7)) 288#define ata_id_removeable(id) ((id)[0] & (1 << 7))
266#define ata_id_has_dword_io(id) ((id)[50] & (1 << 0)) 289#define ata_id_has_dword_io(id) ((id)[50] & (1 << 0))
267#define ata_id_u32(id,n) \ 290#define ata_id_u32(id,n) \
@@ -272,6 +295,8 @@ struct ata_taskfile {
272 ((u64) (id)[(n) + 1] << 16) | \ 295 ((u64) (id)[(n) + 1] << 16) | \
273 ((u64) (id)[(n) + 0]) ) 296 ((u64) (id)[(n) + 0]) )
274 297
298#define ata_id_cdb_intr(id) (((id)[0] & 0x60) == 0x20)
299
275static inline unsigned int ata_id_major_version(const u16 *id) 300static inline unsigned int ata_id_major_version(const u16 *id)
276{ 301{
277 unsigned int mver; 302 unsigned int mver;
@@ -311,6 +336,15 @@ static inline int is_atapi_taskfile(const struct ata_taskfile *tf)
311 (tf->protocol == ATA_PROT_ATAPI_DMA); 336 (tf->protocol == ATA_PROT_ATAPI_DMA);
312} 337}
313 338
339static inline int is_multi_taskfile(struct ata_taskfile *tf)
340{
341 return (tf->command == ATA_CMD_READ_MULTI) ||
342 (tf->command == ATA_CMD_WRITE_MULTI) ||
343 (tf->command == ATA_CMD_READ_MULTI_EXT) ||
344 (tf->command == ATA_CMD_WRITE_MULTI_EXT) ||
345 (tf->command == ATA_CMD_WRITE_MULTI_FUA_EXT);
346}
347
314static inline int ata_ok(u8 status) 348static inline int ata_ok(u8 status)
315{ 349{
316 return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR)) 350 return ((status & (ATA_BUSY | ATA_DRDY | ATA_DF | ATA_DRQ | ATA_ERR))
diff --git a/include/linux/libata.h b/include/linux/libata.h
index b80d2e7fa6..2803ab8e92 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -33,6 +33,7 @@
33#include <asm/io.h> 33#include <asm/io.h>
34#include <linux/ata.h> 34#include <linux/ata.h>
35#include <linux/workqueue.h> 35#include <linux/workqueue.h>
36#include <scsi/scsi_host.h>
36 37
37/* 38/*
38 * compile-time options: to be removed as soon as all the drivers are 39 * compile-time options: to be removed as soon as all the drivers are
@@ -44,7 +45,6 @@
44#undef ATA_NDEBUG /* define to disable quick runtime checks */ 45#undef ATA_NDEBUG /* define to disable quick runtime checks */
45#undef ATA_ENABLE_PATA /* define to enable PATA support in some 46#undef ATA_ENABLE_PATA /* define to enable PATA support in some
46 * low-level drivers */ 47 * low-level drivers */
47#undef ATAPI_ENABLE_DMADIR /* enables ATAPI DMADIR bridge support */
48 48
49 49
50/* note: prints function name for you */ 50/* note: prints function name for you */
@@ -108,8 +108,11 @@ enum {
108 LIBATA_MAX_PRD = ATA_MAX_PRD / 2, 108 LIBATA_MAX_PRD = ATA_MAX_PRD / 2,
109 ATA_MAX_PORTS = 8, 109 ATA_MAX_PORTS = 8,
110 ATA_DEF_QUEUE = 1, 110 ATA_DEF_QUEUE = 1,
111 ATA_MAX_QUEUE = 1, 111 /* tag ATA_MAX_QUEUE - 1 is reserved for internal commands */
112 ATA_MAX_QUEUE = 32,
113 ATA_TAG_INTERNAL = ATA_MAX_QUEUE - 1,
112 ATA_MAX_SECTORS = 200, /* FIXME */ 114 ATA_MAX_SECTORS = 200, /* FIXME */
115 ATA_MAX_SECTORS_LBA48 = 65535,
113 ATA_MAX_BUS = 2, 116 ATA_MAX_BUS = 2,
114 ATA_DEF_BUSY_WAIT = 10000, 117 ATA_DEF_BUSY_WAIT = 10000,
115 ATA_SHORT_PAUSE = (HZ >> 6) + 1, 118 ATA_SHORT_PAUSE = (HZ >> 6) + 1,
@@ -120,9 +123,13 @@ enum {
120 ATA_SHT_USE_CLUSTERING = 1, 123 ATA_SHT_USE_CLUSTERING = 1,
121 124
122 /* struct ata_device stuff */ 125 /* struct ata_device stuff */
123 ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */ 126 ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */
124 ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */ 127 ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */
125 ATA_DFLAG_LBA = (1 << 2), /* device supports LBA */ 128 ATA_DFLAG_CDB_INTR = (1 << 2), /* device asserts INTRQ when ready for CDB */
129 ATA_DFLAG_NCQ = (1 << 3), /* device supports NCQ */
130 ATA_DFLAG_CFG_MASK = (1 << 8) - 1,
131
132 ATA_DFLAG_PIO = (1 << 8), /* device currently in PIO mode */
126 133
127 ATA_DEV_UNKNOWN = 0, /* unknown device */ 134 ATA_DEV_UNKNOWN = 0, /* unknown device */
128 ATA_DEV_ATA = 1, /* ATA device */ 135 ATA_DEV_ATA = 1, /* ATA device */
@@ -132,43 +139,51 @@ enum {
132 ATA_DEV_NONE = 5, /* no device */ 139 ATA_DEV_NONE = 5, /* no device */
133 140
134 /* struct ata_port flags */ 141 /* struct ata_port flags */
135 ATA_FLAG_SLAVE_POSS = (1 << 1), /* host supports slave dev */ 142 ATA_FLAG_SLAVE_POSS = (1 << 0), /* host supports slave dev */
136 /* (doesn't imply presence) */ 143 /* (doesn't imply presence) */
137 ATA_FLAG_PORT_DISABLED = (1 << 2), /* port is disabled, ignore it */ 144 ATA_FLAG_SATA = (1 << 1),
138 ATA_FLAG_SATA = (1 << 3), 145 ATA_FLAG_NO_LEGACY = (1 << 2), /* no legacy mode check */
139 ATA_FLAG_NO_LEGACY = (1 << 4), /* no legacy mode check */ 146 ATA_FLAG_MMIO = (1 << 3), /* use MMIO, not PIO */
140 ATA_FLAG_SRST = (1 << 5), /* (obsolete) use ATA SRST, not E.D.D. */ 147 ATA_FLAG_SRST = (1 << 4), /* (obsolete) use ATA SRST, not E.D.D. */
141 ATA_FLAG_MMIO = (1 << 6), /* use MMIO, not PIO */ 148 ATA_FLAG_SATA_RESET = (1 << 5), /* (obsolete) use COMRESET */
142 ATA_FLAG_SATA_RESET = (1 << 7), /* (obsolete) use COMRESET */ 149 ATA_FLAG_NO_ATAPI = (1 << 6), /* No ATAPI support */
143 ATA_FLAG_PIO_DMA = (1 << 8), /* PIO cmds via DMA */ 150 ATA_FLAG_PIO_DMA = (1 << 7), /* PIO cmds via DMA */
144 ATA_FLAG_NOINTR = (1 << 9), /* FIXME: Remove this once 151 ATA_FLAG_PIO_LBA48 = (1 << 8), /* Host DMA engine is LBA28 only */
145 * proper HSM is in place. */ 152 ATA_FLAG_IRQ_MASK = (1 << 9), /* Mask IRQ in PIO xfers */
146 ATA_FLAG_DEBUGMSG = (1 << 10), 153 ATA_FLAG_PIO_POLLING = (1 << 10), /* use polling PIO if LLD
147 ATA_FLAG_NO_ATAPI = (1 << 11), /* No ATAPI support */ 154 * doesn't handle PIO interrupts */
148 155 ATA_FLAG_NCQ = (1 << 11), /* host supports NCQ */
149 ATA_FLAG_SUSPENDED = (1 << 12), /* port is suspended */ 156
150 157 ATA_FLAG_DEBUGMSG = (1 << 14),
151 ATA_FLAG_PIO_LBA48 = (1 << 13), /* Host DMA engine is LBA28 only */ 158 ATA_FLAG_FLUSH_PORT_TASK = (1 << 15), /* flush port task */
152 ATA_FLAG_IRQ_MASK = (1 << 14), /* Mask IRQ in PIO xfers */ 159
153 160 ATA_FLAG_EH_PENDING = (1 << 16), /* EH pending */
154 ATA_FLAG_FLUSH_PORT_TASK = (1 << 15), /* Flush port task */ 161 ATA_FLAG_FROZEN = (1 << 17), /* port is frozen */
155 ATA_FLAG_IN_EH = (1 << 16), /* EH in progress */ 162 ATA_FLAG_RECOVERED = (1 << 18), /* recovery action performed */
156 163
157 ATA_QCFLAG_ACTIVE = (1 << 1), /* cmd not yet ack'd to scsi lyer */ 164 ATA_FLAG_DISABLED = (1 << 22), /* port is disabled, ignore it */
158 ATA_QCFLAG_SG = (1 << 3), /* have s/g table? */ 165 ATA_FLAG_SUSPENDED = (1 << 23), /* port is suspended (power) */
159 ATA_QCFLAG_SINGLE = (1 << 4), /* no s/g, just a single buffer */ 166
167 /* bits 24:31 of ap->flags are reserved for LLDD specific flags */
168
169 /* struct ata_queued_cmd flags */
170 ATA_QCFLAG_ACTIVE = (1 << 0), /* cmd not yet ack'd to scsi lyer */
171 ATA_QCFLAG_SG = (1 << 1), /* have s/g table? */
172 ATA_QCFLAG_SINGLE = (1 << 2), /* no s/g, just a single buffer */
160 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE, 173 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE,
161 ATA_QCFLAG_EH_SCHEDULED = (1 << 5), /* EH scheduled */ 174 ATA_QCFLAG_IO = (1 << 3), /* standard IO command */
175 ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
176
177 ATA_QCFLAG_FAILED = (1 << 16), /* cmd failed and is owned by EH */
178 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
179 ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */
162 180
163 /* host set flags */ 181 /* host set flags */
164 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host_set only */ 182 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host_set only */
165 183
166 /* various lengths of time */ 184 /* various lengths of time */
167 ATA_TMOUT_PIO = 30 * HZ,
168 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */ 185 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */
169 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* heuristic */ 186 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* heuristic */
170 ATA_TMOUT_CDB = 30 * HZ,
171 ATA_TMOUT_CDB_QUICK = 5 * HZ,
172 ATA_TMOUT_INTERNAL = 30 * HZ, 187 ATA_TMOUT_INTERNAL = 30 * HZ,
173 ATA_TMOUT_INTERNAL_QUICK = 5 * HZ, 188 ATA_TMOUT_INTERNAL_QUICK = 5 * HZ,
174 189
@@ -207,21 +222,44 @@ enum {
207 /* size of buffer to pad xfers ending on unaligned boundaries */ 222 /* size of buffer to pad xfers ending on unaligned boundaries */
208 ATA_DMA_PAD_SZ = 4, 223 ATA_DMA_PAD_SZ = 4,
209 ATA_DMA_PAD_BUF_SZ = ATA_DMA_PAD_SZ * ATA_MAX_QUEUE, 224 ATA_DMA_PAD_BUF_SZ = ATA_DMA_PAD_SZ * ATA_MAX_QUEUE,
210 225
211 /* Masks for port functions */ 226 /* masks for port functions */
212 ATA_PORT_PRIMARY = (1 << 0), 227 ATA_PORT_PRIMARY = (1 << 0),
213 ATA_PORT_SECONDARY = (1 << 1), 228 ATA_PORT_SECONDARY = (1 << 1),
229
230 /* ering size */
231 ATA_ERING_SIZE = 32,
232
233 /* desc_len for ata_eh_info and context */
234 ATA_EH_DESC_LEN = 80,
235
236 /* reset / recovery action types */
237 ATA_EH_REVALIDATE = (1 << 0),
238 ATA_EH_SOFTRESET = (1 << 1),
239 ATA_EH_HARDRESET = (1 << 2),
240
241 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
242
243 /* ata_eh_info->flags */
244 ATA_EHI_DID_RESET = (1 << 0), /* already reset this port */
245
246 /* max repeat if error condition is still set after ->error_handler */
247 ATA_EH_MAX_REPEAT = 5,
248
249 /* how hard are we gonna try to probe/recover devices */
250 ATA_PROBE_MAX_TRIES = 3,
251 ATA_EH_RESET_TRIES = 3,
252 ATA_EH_DEV_TRIES = 3,
214}; 253};
215 254
216enum hsm_task_states { 255enum hsm_task_states {
217 HSM_ST_UNKNOWN, 256 HSM_ST_UNKNOWN, /* state unknown */
218 HSM_ST_IDLE, 257 HSM_ST_IDLE, /* no command on going */
219 HSM_ST_POLL, 258 HSM_ST, /* (waiting the device to) transfer data */
220 HSM_ST_TMOUT, 259 HSM_ST_LAST, /* (waiting the device to) complete command */
221 HSM_ST, 260 HSM_ST_ERR, /* error */
222 HSM_ST_LAST, 261 HSM_ST_FIRST, /* (waiting the device to)
223 HSM_ST_LAST_POLL, 262 write CDB or first data block */
224 HSM_ST_ERR,
225}; 263};
226 264
227enum ata_completion_errors { 265enum ata_completion_errors {
@@ -245,7 +283,7 @@ struct ata_queued_cmd;
245/* typedefs */ 283/* typedefs */
246typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc); 284typedef void (*ata_qc_cb_t) (struct ata_queued_cmd *qc);
247typedef void (*ata_probeinit_fn_t)(struct ata_port *); 285typedef void (*ata_probeinit_fn_t)(struct ata_port *);
248typedef int (*ata_reset_fn_t)(struct ata_port *, int, unsigned int *); 286typedef int (*ata_reset_fn_t)(struct ata_port *, unsigned int *);
249typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *); 287typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *);
250 288
251struct ata_ioports { 289struct ata_ioports {
@@ -336,7 +374,7 @@ struct ata_queued_cmd {
336 struct scatterlist *__sg; 374 struct scatterlist *__sg;
337 375
338 unsigned int err_mask; 376 unsigned int err_mask;
339 377 struct ata_taskfile result_tf;
340 ata_qc_cb_t complete_fn; 378 ata_qc_cb_t complete_fn;
341 379
342 void *private_data; 380 void *private_data;
@@ -348,12 +386,24 @@ struct ata_host_stats {
348 unsigned long rw_reqbuf; 386 unsigned long rw_reqbuf;
349}; 387};
350 388
389struct ata_ering_entry {
390 int is_io;
391 unsigned int err_mask;
392 u64 timestamp;
393};
394
395struct ata_ering {
396 int cursor;
397 struct ata_ering_entry ring[ATA_ERING_SIZE];
398};
399
351struct ata_device { 400struct ata_device {
401 struct ata_port *ap;
352 u64 n_sectors; /* size of device, if ATA */ 402 u64 n_sectors; /* size of device, if ATA */
353 unsigned long flags; /* ATA_DFLAG_xxx */ 403 unsigned long flags; /* ATA_DFLAG_xxx */
354 unsigned int class; /* ATA_DEV_xxx */ 404 unsigned int class; /* ATA_DEV_xxx */
355 unsigned int devno; /* 0 or 1 */ 405 unsigned int devno; /* 0 or 1 */
356 u16 *id; /* IDENTIFY xxx DEVICE data */ 406 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
357 u8 pio_mode; 407 u8 pio_mode;
358 u8 dma_mode; 408 u8 dma_mode;
359 u8 xfer_mode; 409 u8 xfer_mode;
@@ -373,6 +423,24 @@ struct ata_device {
373 u16 cylinders; /* Number of cylinders */ 423 u16 cylinders; /* Number of cylinders */
374 u16 heads; /* Number of heads */ 424 u16 heads; /* Number of heads */
375 u16 sectors; /* Number of sectors per track */ 425 u16 sectors; /* Number of sectors per track */
426
427 /* error history */
428 struct ata_ering ering;
429};
430
431struct ata_eh_info {
432 struct ata_device *dev; /* offending device */
433 u32 serror; /* SError from LLDD */
434 unsigned int err_mask; /* port-wide err_mask */
435 unsigned int action; /* ATA_EH_* action mask */
436 unsigned int flags; /* ATA_EHI_* flags */
437 char desc[ATA_EH_DESC_LEN];
438 int desc_len;
439};
440
441struct ata_eh_context {
442 struct ata_eh_info i;
443 int tries[ATA_MAX_DEVICES];
376}; 444};
377 445
378struct ata_port { 446struct ata_port {
@@ -397,12 +465,21 @@ struct ata_port {
397 unsigned int mwdma_mask; 465 unsigned int mwdma_mask;
398 unsigned int udma_mask; 466 unsigned int udma_mask;
399 unsigned int cbl; /* cable type; ATA_CBL_xxx */ 467 unsigned int cbl; /* cable type; ATA_CBL_xxx */
468 unsigned int sata_spd_limit; /* SATA PHY speed limit */
469
470 /* record runtime error info, protected by host_set lock */
471 struct ata_eh_info eh_info;
472 /* EH context owned by EH */
473 struct ata_eh_context eh_context;
400 474
401 struct ata_device device[ATA_MAX_DEVICES]; 475 struct ata_device device[ATA_MAX_DEVICES];
402 476
403 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE]; 477 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE];
404 unsigned long qactive; 478 unsigned long qc_allocated;
479 unsigned int qc_active;
480
405 unsigned int active_tag; 481 unsigned int active_tag;
482 u32 sactive;
406 483
407 struct ata_host_stats stats; 484 struct ata_host_stats stats;
408 struct ata_host_set *host_set; 485 struct ata_host_set *host_set;
@@ -411,12 +488,13 @@ struct ata_port {
411 struct work_struct port_task; 488 struct work_struct port_task;
412 489
413 unsigned int hsm_task_state; 490 unsigned int hsm_task_state;
414 unsigned long pio_task_timeout;
415 491
416 u32 msg_enable; 492 u32 msg_enable;
417 struct list_head eh_done_q; 493 struct list_head eh_done_q;
418 494
419 void *private_data; 495 void *private_data;
496
497 u8 sector_buf[ATA_SECT_SIZE]; /* owned by EH */
420}; 498};
421 499
422struct ata_port_operations { 500struct ata_port_operations {
@@ -450,7 +528,15 @@ struct ata_port_operations {
450 void (*qc_prep) (struct ata_queued_cmd *qc); 528 void (*qc_prep) (struct ata_queued_cmd *qc);
451 unsigned int (*qc_issue) (struct ata_queued_cmd *qc); 529 unsigned int (*qc_issue) (struct ata_queued_cmd *qc);
452 530
453 void (*eng_timeout) (struct ata_port *ap); 531 /* Error handlers. ->error_handler overrides ->eng_timeout and
532 * indicates that new-style EH is in place.
533 */
534 void (*eng_timeout) (struct ata_port *ap); /* obsolete */
535
536 void (*freeze) (struct ata_port *ap);
537 void (*thaw) (struct ata_port *ap);
538 void (*error_handler) (struct ata_port *ap);
539 void (*post_internal_cmd) (struct ata_queued_cmd *qc);
454 540
455 irqreturn_t (*irq_handler)(int, void *, struct pt_regs *); 541 irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);
456 void (*irq_clear) (struct ata_port *); 542 void (*irq_clear) (struct ata_port *);
@@ -496,18 +582,16 @@ extern void ata_port_probe(struct ata_port *);
496extern void __sata_phy_reset(struct ata_port *ap); 582extern void __sata_phy_reset(struct ata_port *ap);
497extern void sata_phy_reset(struct ata_port *ap); 583extern void sata_phy_reset(struct ata_port *ap);
498extern void ata_bus_reset(struct ata_port *ap); 584extern void ata_bus_reset(struct ata_port *ap);
585extern int sata_set_spd(struct ata_port *ap);
499extern int ata_drive_probe_reset(struct ata_port *ap, 586extern int ata_drive_probe_reset(struct ata_port *ap,
500 ata_probeinit_fn_t probeinit, 587 ata_probeinit_fn_t probeinit,
501 ata_reset_fn_t softreset, ata_reset_fn_t hardreset, 588 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
502 ata_postreset_fn_t postreset, unsigned int *classes); 589 ata_postreset_fn_t postreset, unsigned int *classes);
503extern void ata_std_probeinit(struct ata_port *ap); 590extern void ata_std_probeinit(struct ata_port *ap);
504extern int ata_std_softreset(struct ata_port *ap, int verbose, 591extern int ata_std_softreset(struct ata_port *ap, unsigned int *classes);
505 unsigned int *classes); 592extern int sata_std_hardreset(struct ata_port *ap, unsigned int *class);
506extern int sata_std_hardreset(struct ata_port *ap, int verbose,
507 unsigned int *class);
508extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes); 593extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes);
509extern int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, 594extern int ata_dev_revalidate(struct ata_device *dev, int post_reset);
510 int post_reset);
511extern void ata_port_disable(struct ata_port *); 595extern void ata_port_disable(struct ata_port *);
512extern void ata_std_ports(struct ata_ioports *ioaddr); 596extern void ata_std_ports(struct ata_ioports *ioaddr);
513#ifdef CONFIG_PCI 597#ifdef CONFIG_PCI
@@ -523,20 +607,27 @@ extern void ata_host_set_remove(struct ata_host_set *host_set);
523extern int ata_scsi_detect(struct scsi_host_template *sht); 607extern int ata_scsi_detect(struct scsi_host_template *sht);
524extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 608extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
525extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); 609extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
526extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
527extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
528extern int ata_scsi_release(struct Scsi_Host *host); 610extern int ata_scsi_release(struct Scsi_Host *host);
529extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 611extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
612extern int sata_scr_valid(struct ata_port *ap);
613extern int sata_scr_read(struct ata_port *ap, int reg, u32 *val);
614extern int sata_scr_write(struct ata_port *ap, int reg, u32 val);
615extern int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val);
616extern int ata_port_online(struct ata_port *ap);
617extern int ata_port_offline(struct ata_port *ap);
530extern int ata_scsi_device_resume(struct scsi_device *); 618extern int ata_scsi_device_resume(struct scsi_device *);
531extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state); 619extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state);
532extern int ata_device_resume(struct ata_port *, struct ata_device *); 620extern int ata_device_resume(struct ata_device *);
533extern int ata_device_suspend(struct ata_port *, struct ata_device *, pm_message_t state); 621extern int ata_device_suspend(struct ata_device *, pm_message_t state);
534extern int ata_ratelimit(void); 622extern int ata_ratelimit(void);
535extern unsigned int ata_busy_sleep(struct ata_port *ap, 623extern unsigned int ata_busy_sleep(struct ata_port *ap,
536 unsigned long timeout_pat, 624 unsigned long timeout_pat,
537 unsigned long timeout); 625 unsigned long timeout);
538extern void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *), 626extern void ata_port_queue_task(struct ata_port *ap, void (*fn)(void *),
539 void *data, unsigned long delay); 627 void *data, unsigned long delay);
628extern u32 ata_wait_register(void __iomem *reg, u32 mask, u32 val,
629 unsigned long interval_msec,
630 unsigned long timeout_msec);
540 631
541/* 632/*
542 * Default driver ops implementations 633 * Default driver ops implementations
@@ -572,17 +663,26 @@ extern void ata_bmdma_start (struct ata_queued_cmd *qc);
572extern void ata_bmdma_stop(struct ata_queued_cmd *qc); 663extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
573extern u8 ata_bmdma_status(struct ata_port *ap); 664extern u8 ata_bmdma_status(struct ata_port *ap);
574extern void ata_bmdma_irq_clear(struct ata_port *ap); 665extern void ata_bmdma_irq_clear(struct ata_port *ap);
575extern void __ata_qc_complete(struct ata_queued_cmd *qc); 666extern void ata_bmdma_freeze(struct ata_port *ap);
576extern void ata_eng_timeout(struct ata_port *ap); 667extern void ata_bmdma_thaw(struct ata_port *ap);
577extern void ata_scsi_simulate(struct ata_port *ap, struct ata_device *dev, 668extern void ata_bmdma_drive_eh(struct ata_port *ap,
578 struct scsi_cmnd *cmd, 669 ata_reset_fn_t softreset,
670 ata_reset_fn_t hardreset,
671 ata_postreset_fn_t postreset);
672extern void ata_bmdma_error_handler(struct ata_port *ap);
673extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
674extern void ata_qc_complete(struct ata_queued_cmd *qc);
675extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active,
676 void (*finish_qc)(struct ata_queued_cmd *));
677extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
579 void (*done)(struct scsi_cmnd *)); 678 void (*done)(struct scsi_cmnd *));
580extern int ata_std_bios_param(struct scsi_device *sdev, 679extern int ata_std_bios_param(struct scsi_device *sdev,
581 struct block_device *bdev, 680 struct block_device *bdev,
582 sector_t capacity, int geom[]); 681 sector_t capacity, int geom[]);
583extern int ata_scsi_slave_config(struct scsi_device *sdev); 682extern int ata_scsi_slave_config(struct scsi_device *sdev);
584extern struct ata_device *ata_dev_pair(struct ata_port *ap, 683extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
585 struct ata_device *adev); 684 int queue_depth);
685extern struct ata_device *ata_dev_pair(struct ata_device *adev);
586 686
587/* 687/*
588 * Timing helpers 688 * Timing helpers
@@ -628,7 +728,50 @@ extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bit
628extern unsigned long ata_pci_default_filter(const struct ata_port *, struct ata_device *, unsigned long); 728extern unsigned long ata_pci_default_filter(const struct ata_port *, struct ata_device *, unsigned long);
629#endif /* CONFIG_PCI */ 729#endif /* CONFIG_PCI */
630 730
731/*
732 * EH
733 */
734extern void ata_eng_timeout(struct ata_port *ap);
735
736extern void ata_port_schedule_eh(struct ata_port *ap);
737extern int ata_port_abort(struct ata_port *ap);
738extern int ata_port_freeze(struct ata_port *ap);
739
740extern void ata_eh_freeze_port(struct ata_port *ap);
741extern void ata_eh_thaw_port(struct ata_port *ap);
742
743extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
744extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
745
746extern void ata_do_eh(struct ata_port *ap, ata_reset_fn_t softreset,
747 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset);
748
749/*
750 * printk helpers
751 */
752#define ata_port_printk(ap, lv, fmt, args...) \
753 printk(lv"ata%u: "fmt, (ap)->id , ##args)
754
755#define ata_dev_printk(dev, lv, fmt, args...) \
756 printk(lv"ata%u.%02u: "fmt, (dev)->ap->id, (dev)->devno , ##args)
757
758/*
759 * ata_eh_info helpers
760 */
761#define ata_ehi_push_desc(ehi, fmt, args...) do { \
762 (ehi)->desc_len += scnprintf((ehi)->desc + (ehi)->desc_len, \
763 ATA_EH_DESC_LEN - (ehi)->desc_len, \
764 fmt , ##args); \
765} while (0)
766
767#define ata_ehi_clear_desc(ehi) do { \
768 (ehi)->desc[0] = '\0'; \
769 (ehi)->desc_len = 0; \
770} while (0)
631 771
772/*
773 * qc helpers
774 */
632static inline int 775static inline int
633ata_sg_is_last(struct scatterlist *sg, struct ata_queued_cmd *qc) 776ata_sg_is_last(struct scatterlist *sg, struct ata_queued_cmd *qc)
634{ 777{
@@ -671,14 +814,39 @@ static inline unsigned int ata_tag_valid(unsigned int tag)
671 return (tag < ATA_MAX_QUEUE) ? 1 : 0; 814 return (tag < ATA_MAX_QUEUE) ? 1 : 0;
672} 815}
673 816
674static inline unsigned int ata_class_present(unsigned int class) 817static inline unsigned int ata_tag_internal(unsigned int tag)
818{
819 return tag == ATA_MAX_QUEUE - 1;
820}
821
822static inline unsigned int ata_class_enabled(unsigned int class)
675{ 823{
676 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI; 824 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI;
677} 825}
678 826
679static inline unsigned int ata_dev_present(const struct ata_device *dev) 827static inline unsigned int ata_class_disabled(unsigned int class)
828{
829 return class == ATA_DEV_ATA_UNSUP || class == ATA_DEV_ATAPI_UNSUP;
830}
831
832static inline unsigned int ata_class_absent(unsigned int class)
833{
834 return !ata_class_enabled(class) && !ata_class_disabled(class);
835}
836
837static inline unsigned int ata_dev_enabled(const struct ata_device *dev)
838{
839 return ata_class_enabled(dev->class);
840}
841
842static inline unsigned int ata_dev_disabled(const struct ata_device *dev)
843{
844 return ata_class_disabled(dev->class);
845}
846
847static inline unsigned int ata_dev_absent(const struct ata_device *dev)
680{ 848{
681 return ata_class_present(dev->class); 849 return ata_class_absent(dev->class);
682} 850}
683 851
684static inline u8 ata_chk_status(struct ata_port *ap) 852static inline u8 ata_chk_status(struct ata_port *ap)
@@ -759,20 +927,35 @@ static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
759 qc->tf.ctl |= ATA_NIEN; 927 qc->tf.ctl |= ATA_NIEN;
760} 928}
761 929
762static inline struct ata_queued_cmd *ata_qc_from_tag (struct ata_port *ap, 930static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
763 unsigned int tag) 931 unsigned int tag)
764{ 932{
765 if (likely(ata_tag_valid(tag))) 933 if (likely(ata_tag_valid(tag)))
766 return &ap->qcmd[tag]; 934 return &ap->qcmd[tag];
767 return NULL; 935 return NULL;
768} 936}
769 937
770static inline void ata_tf_init(struct ata_port *ap, struct ata_taskfile *tf, unsigned int device) 938static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
939 unsigned int tag)
940{
941 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
942
943 if (unlikely(!qc) || !ap->ops->error_handler)
944 return qc;
945
946 if ((qc->flags & (ATA_QCFLAG_ACTIVE |
947 ATA_QCFLAG_FAILED)) == ATA_QCFLAG_ACTIVE)
948 return qc;
949
950 return NULL;
951}
952
953static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
771{ 954{
772 memset(tf, 0, sizeof(*tf)); 955 memset(tf, 0, sizeof(*tf));
773 956
774 tf->ctl = ap->ctl; 957 tf->ctl = dev->ap->ctl;
775 if (device == 0) 958 if (dev->devno == 0)
776 tf->device = ATA_DEVICE_OBS; 959 tf->device = ATA_DEVICE_OBS;
777 else 960 else
778 tf->device = ATA_DEVICE_OBS | ATA_DEV1; 961 tf->device = ATA_DEVICE_OBS | ATA_DEV1;
@@ -787,26 +970,11 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
787 qc->nbytes = qc->curbytes = 0; 970 qc->nbytes = qc->curbytes = 0;
788 qc->err_mask = 0; 971 qc->err_mask = 0;
789 972
790 ata_tf_init(qc->ap, &qc->tf, qc->dev->devno); 973 ata_tf_init(qc->dev, &qc->tf);
791}
792
793/**
794 * ata_qc_complete - Complete an active ATA command
795 * @qc: Command to complete
796 * @err_mask: ATA Status register contents
797 *
798 * Indicate to the mid and upper layers that an ATA
799 * command has completed, with either an ok or not-ok status.
800 *
801 * LOCKING:
802 * spin_lock_irqsave(host_set lock)
803 */
804static inline void ata_qc_complete(struct ata_queued_cmd *qc)
805{
806 if (unlikely(qc->flags & ATA_QCFLAG_EH_SCHEDULED))
807 return;
808 974
809 __ata_qc_complete(qc); 975 /* init result_tf such that it indicates normal completion */
976 qc->result_tf.command = ATA_DRDY;
977 qc->result_tf.feature = 0;
810} 978}
811 979
812/** 980/**
@@ -885,28 +1053,6 @@ static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)
885 return status; 1053 return status;
886} 1054}
887 1055
888static inline u32 scr_read(struct ata_port *ap, unsigned int reg)
889{
890 return ap->ops->scr_read(ap, reg);
891}
892
893static inline void scr_write(struct ata_port *ap, unsigned int reg, u32 val)
894{
895 ap->ops->scr_write(ap, reg, val);
896}
897
898static inline void scr_write_flush(struct ata_port *ap, unsigned int reg,
899 u32 val)
900{
901 ap->ops->scr_write(ap, reg, val);
902 (void) ap->ops->scr_read(ap, reg);
903}
904
905static inline unsigned int sata_dev_present(struct ata_port *ap)
906{
907 return ((scr_read(ap, SCR_STATUS) & 0xf) == 0x3) ? 1 : 0;
908}
909
910static inline int ata_try_flush_cache(const struct ata_device *dev) 1056static inline int ata_try_flush_cache(const struct ata_device *dev)
911{ 1057{
912 return ata_id_wcache_enabled(dev->id) || 1058 return ata_id_wcache_enabled(dev->id) ||
@@ -944,4 +1090,9 @@ static inline void ata_pad_free(struct ata_port *ap, struct device *dev)
944 dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma); 1090 dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma);
945} 1091}
946 1092
1093static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)
1094{
1095 return (struct ata_port *) &host->hostdata[0];
1096}
1097
947#endif /* __LINUX_LIBATA_H__ */ 1098#endif /* __LINUX_LIBATA_H__ */
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 1ace1b9fe5..88c6c4da6c 100644
--- a/include/scsi/scsi_cmnd.h
+++ b/include/scsi/scsi_cmnd.h
@@ -151,5 +151,6 @@ extern struct scsi_cmnd *scsi_get_command(struct scsi_device *, gfp_t);
151extern void scsi_put_command(struct scsi_cmnd *); 151extern void scsi_put_command(struct scsi_cmnd *);
152extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int); 152extern void scsi_io_completion(struct scsi_cmnd *, unsigned int, unsigned int);
153extern void scsi_finish_command(struct scsi_cmnd *cmd); 153extern void scsi_finish_command(struct scsi_cmnd *cmd);
154extern void scsi_req_abort_cmd(struct scsi_cmnd *cmd);
154 155
155#endif /* _SCSI_SCSI_CMND_H */ 156#endif /* _SCSI_SCSI_CMND_H */
diff --git a/include/scsi/scsi_eh.h b/include/scsi/scsi_eh.h
index d160880b2a..212c983a6a 100644
--- a/include/scsi/scsi_eh.h
+++ b/include/scsi/scsi_eh.h
@@ -35,6 +35,7 @@ static inline int scsi_sense_valid(struct scsi_sense_hdr *sshdr)
35} 35}
36 36
37 37
38extern void scsi_eh_wakeup(struct Scsi_Host *shost);
38extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd, 39extern void scsi_eh_finish_cmd(struct scsi_cmnd *scmd,
39 struct list_head *done_q); 40 struct list_head *done_q);
40extern void scsi_eh_flush_done_q(struct list_head *done_q); 41extern void scsi_eh_flush_done_q(struct list_head *done_q);
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index de6ce541a0..a42efd6e4b 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -472,6 +472,7 @@ struct Scsi_Host {
472 */ 472 */
473 unsigned int host_busy; /* commands actually active on low-level */ 473 unsigned int host_busy; /* commands actually active on low-level */
474 unsigned int host_failed; /* commands that failed. */ 474 unsigned int host_failed; /* commands that failed. */
475 unsigned int host_eh_scheduled; /* EH scheduled without command */
475 476
476 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */ 477 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
477 int resetting; /* if set, it means that last_reset is a valid value */ 478 int resetting; /* if set, it means that last_reset is a valid value */