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.h273
-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, 228 insertions, 82 deletions
diff --git a/include/linux/ata.h b/include/linux/ata.h
index 312a2c0c64e6..c494e1c0531e 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 d35b1e3bb7e0..fcdd798bb086 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -108,7 +108,9 @@ 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 */
113 ATA_MAX_BUS = 2, 115 ATA_MAX_BUS = 2,
114 ATA_DEF_BUSY_WAIT = 10000, 116 ATA_DEF_BUSY_WAIT = 10000,
@@ -122,6 +124,8 @@ enum {
122 /* struct ata_device stuff */ 124 /* struct ata_device stuff */
123 ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */ 125 ATA_DFLAG_LBA = (1 << 0), /* device supports LBA */
124 ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */ 126 ATA_DFLAG_LBA48 = (1 << 1), /* device supports LBA48 */
127 ATA_DFLAG_CDB_INTR = (1 << 2), /* device asserts INTRQ when ready for CDB */
128 ATA_DFLAG_NCQ = (1 << 3), /* device supports NCQ */
125 ATA_DFLAG_CFG_MASK = (1 << 8) - 1, 129 ATA_DFLAG_CFG_MASK = (1 << 8) - 1,
126 130
127 ATA_DFLAG_PIO = (1 << 8), /* device currently in PIO mode */ 131 ATA_DFLAG_PIO = (1 << 8), /* device currently in PIO mode */
@@ -145,14 +149,19 @@ enum {
145 ATA_FLAG_PIO_DMA = (1 << 7), /* PIO cmds via DMA */ 149 ATA_FLAG_PIO_DMA = (1 << 7), /* PIO cmds via DMA */
146 ATA_FLAG_PIO_LBA48 = (1 << 8), /* Host DMA engine is LBA28 only */ 150 ATA_FLAG_PIO_LBA48 = (1 << 8), /* Host DMA engine is LBA28 only */
147 ATA_FLAG_IRQ_MASK = (1 << 9), /* Mask IRQ in PIO xfers */ 151 ATA_FLAG_IRQ_MASK = (1 << 9), /* Mask IRQ in PIO xfers */
152 ATA_FLAG_PIO_POLLING = (1 << 10), /* use polling PIO if LLD
153 * doesn't handle PIO interrupts */
154 ATA_FLAG_NCQ = (1 << 11), /* host supports NCQ */
148 155
149 ATA_FLAG_NOINTR = (1 << 16), /* FIXME: Remove this once 156 ATA_FLAG_DEBUGMSG = (1 << 14),
150 * proper HSM is in place. */ 157 ATA_FLAG_FLUSH_PORT_TASK = (1 << 15), /* flush port task */
151 ATA_FLAG_DEBUGMSG = (1 << 17),
152 ATA_FLAG_FLUSH_PORT_TASK = (1 << 18), /* flush port task */
153 158
154 ATA_FLAG_DISABLED = (1 << 19), /* port is disabled, ignore it */ 159 ATA_FLAG_EH_PENDING = (1 << 16), /* EH pending */
155 ATA_FLAG_SUSPENDED = (1 << 20), /* port is suspended */ 160 ATA_FLAG_FROZEN = (1 << 17), /* port is frozen */
161 ATA_FLAG_RECOVERED = (1 << 18), /* recovery action performed */
162
163 ATA_FLAG_DISABLED = (1 << 22), /* port is disabled, ignore it */
164 ATA_FLAG_SUSPENDED = (1 << 23), /* port is suspended (power) */
156 165
157 /* bits 24:31 of ap->flags are reserved for LLDD specific flags */ 166 /* bits 24:31 of ap->flags are reserved for LLDD specific flags */
158 167
@@ -162,17 +171,18 @@ enum {
162 ATA_QCFLAG_SINGLE = (1 << 2), /* no s/g, just a single buffer */ 171 ATA_QCFLAG_SINGLE = (1 << 2), /* no s/g, just a single buffer */
163 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE, 172 ATA_QCFLAG_DMAMAP = ATA_QCFLAG_SG | ATA_QCFLAG_SINGLE,
164 ATA_QCFLAG_IO = (1 << 3), /* standard IO command */ 173 ATA_QCFLAG_IO = (1 << 3), /* standard IO command */
165 ATA_QCFLAG_EH_SCHEDULED = (1 << 4), /* EH scheduled */ 174 ATA_QCFLAG_RESULT_TF = (1 << 4), /* result TF requested */
175
176 ATA_QCFLAG_FAILED = (1 << 16), /* cmd failed and is owned by EH */
177 ATA_QCFLAG_SENSE_VALID = (1 << 17), /* sense data valid */
178 ATA_QCFLAG_EH_SCHEDULED = (1 << 18), /* EH scheduled (obsolete) */
166 179
167 /* host set flags */ 180 /* host set flags */
168 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host_set only */ 181 ATA_HOST_SIMPLEX = (1 << 0), /* Host is simplex, one DMA channel per host_set only */
169 182
170 /* various lengths of time */ 183 /* various lengths of time */
171 ATA_TMOUT_PIO = 30 * HZ,
172 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */ 184 ATA_TMOUT_BOOT = 30 * HZ, /* heuristic */
173 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* heuristic */ 185 ATA_TMOUT_BOOT_QUICK = 7 * HZ, /* heuristic */
174 ATA_TMOUT_CDB = 30 * HZ,
175 ATA_TMOUT_CDB_QUICK = 5 * HZ,
176 ATA_TMOUT_INTERNAL = 30 * HZ, 186 ATA_TMOUT_INTERNAL = 30 * HZ,
177 ATA_TMOUT_INTERNAL_QUICK = 5 * HZ, 187 ATA_TMOUT_INTERNAL_QUICK = 5 * HZ,
178 188
@@ -216,19 +226,39 @@ enum {
216 ATA_PORT_PRIMARY = (1 << 0), 226 ATA_PORT_PRIMARY = (1 << 0),
217 ATA_PORT_SECONDARY = (1 << 1), 227 ATA_PORT_SECONDARY = (1 << 1),
218 228
229 /* ering size */
230 ATA_ERING_SIZE = 32,
231
232 /* desc_len for ata_eh_info and context */
233 ATA_EH_DESC_LEN = 80,
234
235 /* reset / recovery action types */
236 ATA_EH_REVALIDATE = (1 << 0),
237 ATA_EH_SOFTRESET = (1 << 1),
238 ATA_EH_HARDRESET = (1 << 2),
239
240 ATA_EH_RESET_MASK = ATA_EH_SOFTRESET | ATA_EH_HARDRESET,
241
242 /* ata_eh_info->flags */
243 ATA_EHI_DID_RESET = (1 << 0), /* already reset this port */
244
245 /* max repeat if error condition is still set after ->error_handler */
246 ATA_EH_MAX_REPEAT = 5,
247
219 /* how hard are we gonna try to probe/recover devices */ 248 /* how hard are we gonna try to probe/recover devices */
220 ATA_PROBE_MAX_TRIES = 3, 249 ATA_PROBE_MAX_TRIES = 3,
250 ATA_EH_RESET_TRIES = 3,
251 ATA_EH_DEV_TRIES = 3,
221}; 252};
222 253
223enum hsm_task_states { 254enum hsm_task_states {
224 HSM_ST_UNKNOWN, 255 HSM_ST_UNKNOWN, /* state unknown */
225 HSM_ST_IDLE, 256 HSM_ST_IDLE, /* no command on going */
226 HSM_ST_POLL, 257 HSM_ST, /* (waiting the device to) transfer data */
227 HSM_ST_TMOUT, 258 HSM_ST_LAST, /* (waiting the device to) complete command */
228 HSM_ST, 259 HSM_ST_ERR, /* error */
229 HSM_ST_LAST, 260 HSM_ST_FIRST, /* (waiting the device to)
230 HSM_ST_LAST_POLL, 261 write CDB or first data block */
231 HSM_ST_ERR,
232}; 262};
233 263
234enum ata_completion_errors { 264enum ata_completion_errors {
@@ -343,7 +373,7 @@ struct ata_queued_cmd {
343 struct scatterlist *__sg; 373 struct scatterlist *__sg;
344 374
345 unsigned int err_mask; 375 unsigned int err_mask;
346 376 struct ata_taskfile result_tf;
347 ata_qc_cb_t complete_fn; 377 ata_qc_cb_t complete_fn;
348 378
349 void *private_data; 379 void *private_data;
@@ -355,12 +385,24 @@ struct ata_host_stats {
355 unsigned long rw_reqbuf; 385 unsigned long rw_reqbuf;
356}; 386};
357 387
388struct ata_ering_entry {
389 int is_io;
390 unsigned int err_mask;
391 u64 timestamp;
392};
393
394struct ata_ering {
395 int cursor;
396 struct ata_ering_entry ring[ATA_ERING_SIZE];
397};
398
358struct ata_device { 399struct ata_device {
400 struct ata_port *ap;
359 u64 n_sectors; /* size of device, if ATA */ 401 u64 n_sectors; /* size of device, if ATA */
360 unsigned long flags; /* ATA_DFLAG_xxx */ 402 unsigned long flags; /* ATA_DFLAG_xxx */
361 unsigned int class; /* ATA_DEV_xxx */ 403 unsigned int class; /* ATA_DEV_xxx */
362 unsigned int devno; /* 0 or 1 */ 404 unsigned int devno; /* 0 or 1 */
363 u16 *id; /* IDENTIFY xxx DEVICE data */ 405 u16 id[ATA_ID_WORDS]; /* IDENTIFY xxx DEVICE data */
364 u8 pio_mode; 406 u8 pio_mode;
365 u8 dma_mode; 407 u8 dma_mode;
366 u8 xfer_mode; 408 u8 xfer_mode;
@@ -380,6 +422,24 @@ struct ata_device {
380 u16 cylinders; /* Number of cylinders */ 422 u16 cylinders; /* Number of cylinders */
381 u16 heads; /* Number of heads */ 423 u16 heads; /* Number of heads */
382 u16 sectors; /* Number of sectors per track */ 424 u16 sectors; /* Number of sectors per track */
425
426 /* error history */
427 struct ata_ering ering;
428};
429
430struct ata_eh_info {
431 struct ata_device *dev; /* offending device */
432 u32 serror; /* SError from LLDD */
433 unsigned int err_mask; /* port-wide err_mask */
434 unsigned int action; /* ATA_EH_* action mask */
435 unsigned int flags; /* ATA_EHI_* flags */
436 char desc[ATA_EH_DESC_LEN];
437 int desc_len;
438};
439
440struct ata_eh_context {
441 struct ata_eh_info i;
442 int tries[ATA_MAX_DEVICES];
383}; 443};
384 444
385struct ata_port { 445struct ata_port {
@@ -406,11 +466,19 @@ struct ata_port {
406 unsigned int cbl; /* cable type; ATA_CBL_xxx */ 466 unsigned int cbl; /* cable type; ATA_CBL_xxx */
407 unsigned int sata_spd_limit; /* SATA PHY speed limit */ 467 unsigned int sata_spd_limit; /* SATA PHY speed limit */
408 468
469 /* record runtime error info, protected by host_set lock */
470 struct ata_eh_info eh_info;
471 /* EH context owned by EH */
472 struct ata_eh_context eh_context;
473
409 struct ata_device device[ATA_MAX_DEVICES]; 474 struct ata_device device[ATA_MAX_DEVICES];
410 475
411 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE]; 476 struct ata_queued_cmd qcmd[ATA_MAX_QUEUE];
412 unsigned long qactive; 477 unsigned long qc_allocated;
478 unsigned int qc_active;
479
413 unsigned int active_tag; 480 unsigned int active_tag;
481 u32 sactive;
414 482
415 struct ata_host_stats stats; 483 struct ata_host_stats stats;
416 struct ata_host_set *host_set; 484 struct ata_host_set *host_set;
@@ -419,12 +487,13 @@ struct ata_port {
419 struct work_struct port_task; 487 struct work_struct port_task;
420 488
421 unsigned int hsm_task_state; 489 unsigned int hsm_task_state;
422 unsigned long pio_task_timeout;
423 490
424 u32 msg_enable; 491 u32 msg_enable;
425 struct list_head eh_done_q; 492 struct list_head eh_done_q;
426 493
427 void *private_data; 494 void *private_data;
495
496 u8 sector_buf[ATA_SECT_SIZE]; /* owned by EH */
428}; 497};
429 498
430struct ata_port_operations { 499struct ata_port_operations {
@@ -458,7 +527,15 @@ struct ata_port_operations {
458 void (*qc_prep) (struct ata_queued_cmd *qc); 527 void (*qc_prep) (struct ata_queued_cmd *qc);
459 unsigned int (*qc_issue) (struct ata_queued_cmd *qc); 528 unsigned int (*qc_issue) (struct ata_queued_cmd *qc);
460 529
461 void (*eng_timeout) (struct ata_port *ap); 530 /* Error handlers. ->error_handler overrides ->eng_timeout and
531 * indicates that new-style EH is in place.
532 */
533 void (*eng_timeout) (struct ata_port *ap); /* obsolete */
534
535 void (*freeze) (struct ata_port *ap);
536 void (*thaw) (struct ata_port *ap);
537 void (*error_handler) (struct ata_port *ap);
538 void (*post_internal_cmd) (struct ata_queued_cmd *qc);
462 539
463 irqreturn_t (*irq_handler)(int, void *, struct pt_regs *); 540 irqreturn_t (*irq_handler)(int, void *, struct pt_regs *);
464 void (*irq_clear) (struct ata_port *); 541 void (*irq_clear) (struct ata_port *);
@@ -504,7 +581,7 @@ extern void ata_port_probe(struct ata_port *);
504extern void __sata_phy_reset(struct ata_port *ap); 581extern void __sata_phy_reset(struct ata_port *ap);
505extern void sata_phy_reset(struct ata_port *ap); 582extern void sata_phy_reset(struct ata_port *ap);
506extern void ata_bus_reset(struct ata_port *ap); 583extern void ata_bus_reset(struct ata_port *ap);
507extern int ata_set_sata_spd(struct ata_port *ap); 584extern int sata_set_spd(struct ata_port *ap);
508extern int ata_drive_probe_reset(struct ata_port *ap, 585extern int ata_drive_probe_reset(struct ata_port *ap,
509 ata_probeinit_fn_t probeinit, 586 ata_probeinit_fn_t probeinit,
510 ata_reset_fn_t softreset, ata_reset_fn_t hardreset, 587 ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
@@ -513,8 +590,7 @@ extern void ata_std_probeinit(struct ata_port *ap);
513extern int ata_std_softreset(struct ata_port *ap, unsigned int *classes); 590extern int ata_std_softreset(struct ata_port *ap, unsigned int *classes);
514extern int sata_std_hardreset(struct ata_port *ap, unsigned int *class); 591extern int sata_std_hardreset(struct ata_port *ap, unsigned int *class);
515extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes); 592extern void ata_std_postreset(struct ata_port *ap, unsigned int *classes);
516extern int ata_dev_revalidate(struct ata_port *ap, struct ata_device *dev, 593extern int ata_dev_revalidate(struct ata_device *dev, int post_reset);
517 int post_reset);
518extern void ata_port_disable(struct ata_port *); 594extern void ata_port_disable(struct ata_port *);
519extern void ata_std_ports(struct ata_ioports *ioaddr); 595extern void ata_std_ports(struct ata_ioports *ioaddr);
520#ifdef CONFIG_PCI 596#ifdef CONFIG_PCI
@@ -530,14 +606,18 @@ extern void ata_host_set_remove(struct ata_host_set *host_set);
530extern int ata_scsi_detect(struct scsi_host_template *sht); 606extern int ata_scsi_detect(struct scsi_host_template *sht);
531extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 607extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
532extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); 608extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
533extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
534extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
535extern int ata_scsi_release(struct Scsi_Host *host); 609extern int ata_scsi_release(struct Scsi_Host *host);
536extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); 610extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc);
611extern int sata_scr_valid(struct ata_port *ap);
612extern int sata_scr_read(struct ata_port *ap, int reg, u32 *val);
613extern int sata_scr_write(struct ata_port *ap, int reg, u32 val);
614extern int sata_scr_write_flush(struct ata_port *ap, int reg, u32 val);
615extern int ata_port_online(struct ata_port *ap);
616extern int ata_port_offline(struct ata_port *ap);
537extern int ata_scsi_device_resume(struct scsi_device *); 617extern int ata_scsi_device_resume(struct scsi_device *);
538extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state); 618extern int ata_scsi_device_suspend(struct scsi_device *, pm_message_t state);
539extern int ata_device_resume(struct ata_port *, struct ata_device *); 619extern int ata_device_resume(struct ata_device *);
540extern int ata_device_suspend(struct ata_port *, struct ata_device *, pm_message_t state); 620extern int ata_device_suspend(struct ata_device *, pm_message_t state);
541extern int ata_ratelimit(void); 621extern int ata_ratelimit(void);
542extern unsigned int ata_busy_sleep(struct ata_port *ap, 622extern unsigned int ata_busy_sleep(struct ata_port *ap,
543 unsigned long timeout_pat, 623 unsigned long timeout_pat,
@@ -582,16 +662,26 @@ extern void ata_bmdma_start (struct ata_queued_cmd *qc);
582extern void ata_bmdma_stop(struct ata_queued_cmd *qc); 662extern void ata_bmdma_stop(struct ata_queued_cmd *qc);
583extern u8 ata_bmdma_status(struct ata_port *ap); 663extern u8 ata_bmdma_status(struct ata_port *ap);
584extern void ata_bmdma_irq_clear(struct ata_port *ap); 664extern void ata_bmdma_irq_clear(struct ata_port *ap);
585extern void __ata_qc_complete(struct ata_queued_cmd *qc); 665extern void ata_bmdma_freeze(struct ata_port *ap);
586extern void ata_scsi_simulate(struct ata_port *ap, struct ata_device *dev, 666extern void ata_bmdma_thaw(struct ata_port *ap);
587 struct scsi_cmnd *cmd, 667extern void ata_bmdma_drive_eh(struct ata_port *ap,
668 ata_reset_fn_t softreset,
669 ata_reset_fn_t hardreset,
670 ata_postreset_fn_t postreset);
671extern void ata_bmdma_error_handler(struct ata_port *ap);
672extern void ata_bmdma_post_internal_cmd(struct ata_queued_cmd *qc);
673extern void ata_qc_complete(struct ata_queued_cmd *qc);
674extern int ata_qc_complete_multiple(struct ata_port *ap, u32 qc_active,
675 void (*finish_qc)(struct ata_queued_cmd *));
676extern void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd,
588 void (*done)(struct scsi_cmnd *)); 677 void (*done)(struct scsi_cmnd *));
589extern int ata_std_bios_param(struct scsi_device *sdev, 678extern int ata_std_bios_param(struct scsi_device *sdev,
590 struct block_device *bdev, 679 struct block_device *bdev,
591 sector_t capacity, int geom[]); 680 sector_t capacity, int geom[]);
592extern int ata_scsi_slave_config(struct scsi_device *sdev); 681extern int ata_scsi_slave_config(struct scsi_device *sdev);
593extern struct ata_device *ata_dev_pair(struct ata_port *ap, 682extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
594 struct ata_device *adev); 683 int queue_depth);
684extern struct ata_device *ata_dev_pair(struct ata_device *adev);
595 685
596/* 686/*
597 * Timing helpers 687 * Timing helpers
@@ -641,10 +731,46 @@ extern unsigned long ata_pci_default_filter(const struct ata_port *, struct ata_
641 * EH 731 * EH
642 */ 732 */
643extern void ata_eng_timeout(struct ata_port *ap); 733extern void ata_eng_timeout(struct ata_port *ap);
734
735extern void ata_port_schedule_eh(struct ata_port *ap);
736extern int ata_port_abort(struct ata_port *ap);
737extern int ata_port_freeze(struct ata_port *ap);
738
739extern void ata_eh_freeze_port(struct ata_port *ap);
740extern void ata_eh_thaw_port(struct ata_port *ap);
741
644extern void ata_eh_qc_complete(struct ata_queued_cmd *qc); 742extern void ata_eh_qc_complete(struct ata_queued_cmd *qc);
645extern void ata_eh_qc_retry(struct ata_queued_cmd *qc); 743extern void ata_eh_qc_retry(struct ata_queued_cmd *qc);
646 744
745extern void ata_do_eh(struct ata_port *ap, ata_reset_fn_t softreset,
746 ata_reset_fn_t hardreset, ata_postreset_fn_t postreset);
747
748/*
749 * printk helpers
750 */
751#define ata_port_printk(ap, lv, fmt, args...) \
752 printk(lv"ata%u: "fmt, (ap)->id , ##args)
753
754#define ata_dev_printk(dev, lv, fmt, args...) \
755 printk(lv"ata%u.%02u: "fmt, (dev)->ap->id, (dev)->devno , ##args)
756
757/*
758 * ata_eh_info helpers
759 */
760#define ata_ehi_push_desc(ehi, fmt, args...) do { \
761 (ehi)->desc_len += scnprintf((ehi)->desc + (ehi)->desc_len, \
762 ATA_EH_DESC_LEN - (ehi)->desc_len, \
763 fmt , ##args); \
764} while (0)
765
766#define ata_ehi_clear_desc(ehi) do { \
767 (ehi)->desc[0] = '\0'; \
768 (ehi)->desc_len = 0; \
769} while (0)
647 770
771/*
772 * qc helpers
773 */
648static inline int 774static inline int
649ata_sg_is_last(struct scatterlist *sg, struct ata_queued_cmd *qc) 775ata_sg_is_last(struct scatterlist *sg, struct ata_queued_cmd *qc)
650{ 776{
@@ -687,6 +813,11 @@ static inline unsigned int ata_tag_valid(unsigned int tag)
687 return (tag < ATA_MAX_QUEUE) ? 1 : 0; 813 return (tag < ATA_MAX_QUEUE) ? 1 : 0;
688} 814}
689 815
816static inline unsigned int ata_tag_internal(unsigned int tag)
817{
818 return tag == ATA_MAX_QUEUE - 1;
819}
820
690static inline unsigned int ata_class_enabled(unsigned int class) 821static inline unsigned int ata_class_enabled(unsigned int class)
691{ 822{
692 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI; 823 return class == ATA_DEV_ATA || class == ATA_DEV_ATAPI;
@@ -795,20 +926,35 @@ static inline void ata_qc_set_polling(struct ata_queued_cmd *qc)
795 qc->tf.ctl |= ATA_NIEN; 926 qc->tf.ctl |= ATA_NIEN;
796} 927}
797 928
798static inline struct ata_queued_cmd *ata_qc_from_tag (struct ata_port *ap, 929static inline struct ata_queued_cmd *__ata_qc_from_tag(struct ata_port *ap,
799 unsigned int tag) 930 unsigned int tag)
800{ 931{
801 if (likely(ata_tag_valid(tag))) 932 if (likely(ata_tag_valid(tag)))
802 return &ap->qcmd[tag]; 933 return &ap->qcmd[tag];
803 return NULL; 934 return NULL;
804} 935}
805 936
806static inline void ata_tf_init(struct ata_port *ap, struct ata_taskfile *tf, unsigned int device) 937static inline struct ata_queued_cmd *ata_qc_from_tag(struct ata_port *ap,
938 unsigned int tag)
939{
940 struct ata_queued_cmd *qc = __ata_qc_from_tag(ap, tag);
941
942 if (unlikely(!qc) || !ap->ops->error_handler)
943 return qc;
944
945 if ((qc->flags & (ATA_QCFLAG_ACTIVE |
946 ATA_QCFLAG_FAILED)) == ATA_QCFLAG_ACTIVE)
947 return qc;
948
949 return NULL;
950}
951
952static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
807{ 953{
808 memset(tf, 0, sizeof(*tf)); 954 memset(tf, 0, sizeof(*tf));
809 955
810 tf->ctl = ap->ctl; 956 tf->ctl = dev->ap->ctl;
811 if (device == 0) 957 if (dev->devno == 0)
812 tf->device = ATA_DEVICE_OBS; 958 tf->device = ATA_DEVICE_OBS;
813 else 959 else
814 tf->device = ATA_DEVICE_OBS | ATA_DEV1; 960 tf->device = ATA_DEVICE_OBS | ATA_DEV1;
@@ -823,26 +969,11 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
823 qc->nbytes = qc->curbytes = 0; 969 qc->nbytes = qc->curbytes = 0;
824 qc->err_mask = 0; 970 qc->err_mask = 0;
825 971
826 ata_tf_init(qc->ap, &qc->tf, qc->dev->devno); 972 ata_tf_init(qc->dev, &qc->tf);
827}
828 973
829/** 974 /* init result_tf such that it indicates normal completion */
830 * ata_qc_complete - Complete an active ATA command 975 qc->result_tf.command = ATA_DRDY;
831 * @qc: Command to complete 976 qc->result_tf.feature = 0;
832 * @err_mask: ATA Status register contents
833 *
834 * Indicate to the mid and upper layers that an ATA
835 * command has completed, with either an ok or not-ok status.
836 *
837 * LOCKING:
838 * spin_lock_irqsave(host_set lock)
839 */
840static inline void ata_qc_complete(struct ata_queued_cmd *qc)
841{
842 if (unlikely(qc->flags & ATA_QCFLAG_EH_SCHEDULED))
843 return;
844
845 __ata_qc_complete(qc);
846} 977}
847 978
848/** 979/**
@@ -921,28 +1052,6 @@ static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)
921 return status; 1052 return status;
922} 1053}
923 1054
924static inline u32 scr_read(struct ata_port *ap, unsigned int reg)
925{
926 return ap->ops->scr_read(ap, reg);
927}
928
929static inline void scr_write(struct ata_port *ap, unsigned int reg, u32 val)
930{
931 ap->ops->scr_write(ap, reg, val);
932}
933
934static inline void scr_write_flush(struct ata_port *ap, unsigned int reg,
935 u32 val)
936{
937 ap->ops->scr_write(ap, reg, val);
938 (void) ap->ops->scr_read(ap, reg);
939}
940
941static inline unsigned int sata_dev_present(struct ata_port *ap)
942{
943 return ((scr_read(ap, SCR_STATUS) & 0xf) == 0x3) ? 1 : 0;
944}
945
946static inline int ata_try_flush_cache(const struct ata_device *dev) 1055static inline int ata_try_flush_cache(const struct ata_device *dev)
947{ 1056{
948 return ata_id_wcache_enabled(dev->id) || 1057 return ata_id_wcache_enabled(dev->id) ||
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h
index 1ace1b9fe537..88c6c4da6c05 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 d160880b2a87..212c983a6a18 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 de6ce541a046..a42efd6e4be8 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 */