diff options
Diffstat (limited to 'include/linux/libata.h')
-rw-r--r-- | include/linux/libata.h | 143 |
1 files changed, 107 insertions, 36 deletions
diff --git a/include/linux/libata.h b/include/linux/libata.h index ceee1fc42c60..0ba3af7a1236 100644 --- a/include/linux/libata.h +++ b/include/linux/libata.h | |||
@@ -91,12 +91,13 @@ enum { | |||
91 | ATA_SHT_EMULATED = 1, | 91 | ATA_SHT_EMULATED = 1, |
92 | ATA_SHT_CMD_PER_LUN = 1, | 92 | ATA_SHT_CMD_PER_LUN = 1, |
93 | ATA_SHT_THIS_ID = -1, | 93 | ATA_SHT_THIS_ID = -1, |
94 | ATA_SHT_USE_CLUSTERING = 0, | 94 | ATA_SHT_USE_CLUSTERING = 1, |
95 | 95 | ||
96 | /* struct ata_device stuff */ | 96 | /* struct ata_device stuff */ |
97 | ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */ | 97 | ATA_DFLAG_LBA48 = (1 << 0), /* device supports LBA48 */ |
98 | ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */ | 98 | ATA_DFLAG_PIO = (1 << 1), /* device currently in PIO mode */ |
99 | ATA_DFLAG_LOCK_SECTORS = (1 << 2), /* don't adjust max_sectors */ | 99 | ATA_DFLAG_LOCK_SECTORS = (1 << 2), /* don't adjust max_sectors */ |
100 | ATA_DFLAG_LBA = (1 << 3), /* device supports LBA */ | ||
100 | 101 | ||
101 | ATA_DEV_UNKNOWN = 0, /* unknown device */ | 102 | ATA_DEV_UNKNOWN = 0, /* unknown device */ |
102 | ATA_DEV_ATA = 1, /* ATA device */ | 103 | ATA_DEV_ATA = 1, /* ATA device */ |
@@ -154,17 +155,28 @@ enum { | |||
154 | ATA_SHIFT_UDMA = 0, | 155 | ATA_SHIFT_UDMA = 0, |
155 | ATA_SHIFT_MWDMA = 8, | 156 | ATA_SHIFT_MWDMA = 8, |
156 | ATA_SHIFT_PIO = 11, | 157 | ATA_SHIFT_PIO = 11, |
158 | |||
159 | /* Masks for port functions */ | ||
160 | ATA_PORT_PRIMARY = (1 << 0), | ||
161 | ATA_PORT_SECONDARY = (1 << 1), | ||
157 | }; | 162 | }; |
158 | 163 | ||
159 | enum pio_task_states { | 164 | enum hsm_task_states { |
160 | PIO_ST_UNKNOWN, | 165 | HSM_ST_UNKNOWN, |
161 | PIO_ST_IDLE, | 166 | HSM_ST_IDLE, |
162 | PIO_ST_POLL, | 167 | HSM_ST_POLL, |
163 | PIO_ST_TMOUT, | 168 | HSM_ST_TMOUT, |
164 | PIO_ST, | 169 | HSM_ST, |
165 | PIO_ST_LAST, | 170 | HSM_ST_LAST, |
166 | PIO_ST_LAST_POLL, | 171 | HSM_ST_LAST_POLL, |
167 | PIO_ST_ERR, | 172 | HSM_ST_ERR, |
173 | }; | ||
174 | |||
175 | enum ata_completion_errors { | ||
176 | AC_ERR_OTHER = (1 << 0), | ||
177 | AC_ERR_DEV = (1 << 1), | ||
178 | AC_ERR_ATA_BUS = (1 << 2), | ||
179 | AC_ERR_HOST_BUS = (1 << 3), | ||
168 | }; | 180 | }; |
169 | 181 | ||
170 | /* forward declarations */ | 182 | /* forward declarations */ |
@@ -174,7 +186,7 @@ struct ata_port; | |||
174 | struct ata_queued_cmd; | 186 | struct ata_queued_cmd; |
175 | 187 | ||
176 | /* typedefs */ | 188 | /* typedefs */ |
177 | typedef int (*ata_qc_cb_t) (struct ata_queued_cmd *qc, u8 drv_stat); | 189 | typedef int (*ata_qc_cb_t) (struct ata_queued_cmd *qc, unsigned int err_mask); |
178 | 190 | ||
179 | struct ata_ioports { | 191 | struct ata_ioports { |
180 | unsigned long cmd_addr; | 192 | unsigned long cmd_addr; |
@@ -197,7 +209,7 @@ struct ata_ioports { | |||
197 | struct ata_probe_ent { | 209 | struct ata_probe_ent { |
198 | struct list_head node; | 210 | struct list_head node; |
199 | struct device *dev; | 211 | struct device *dev; |
200 | struct ata_port_operations *port_ops; | 212 | const struct ata_port_operations *port_ops; |
201 | Scsi_Host_Template *sht; | 213 | Scsi_Host_Template *sht; |
202 | struct ata_ioports port[ATA_MAX_PORTS]; | 214 | struct ata_ioports port[ATA_MAX_PORTS]; |
203 | unsigned int n_ports; | 215 | unsigned int n_ports; |
@@ -220,7 +232,7 @@ struct ata_host_set { | |||
220 | void __iomem *mmio_base; | 232 | void __iomem *mmio_base; |
221 | unsigned int n_ports; | 233 | unsigned int n_ports; |
222 | void *private_data; | 234 | void *private_data; |
223 | struct ata_port_operations *ops; | 235 | const struct ata_port_operations *ops; |
224 | struct ata_port * ports[0]; | 236 | struct ata_port * ports[0]; |
225 | }; | 237 | }; |
226 | 238 | ||
@@ -278,15 +290,18 @@ struct ata_device { | |||
278 | u8 xfer_mode; | 290 | u8 xfer_mode; |
279 | unsigned int xfer_shift; /* ATA_SHIFT_xxx */ | 291 | unsigned int xfer_shift; /* ATA_SHIFT_xxx */ |
280 | 292 | ||
281 | /* cache info about current transfer mode */ | 293 | unsigned int multi_count; /* sectors count for |
282 | u8 xfer_protocol; /* taskfile xfer protocol */ | 294 | READ/WRITE MULTIPLE */ |
283 | u8 read_cmd; /* opcode to use on read */ | 295 | |
284 | u8 write_cmd; /* opcode to use on write */ | 296 | /* for CHS addressing */ |
297 | u16 cylinders; /* Number of cylinders */ | ||
298 | u16 heads; /* Number of heads */ | ||
299 | u16 sectors; /* Number of sectors per track */ | ||
285 | }; | 300 | }; |
286 | 301 | ||
287 | struct ata_port { | 302 | struct ata_port { |
288 | struct Scsi_Host *host; /* our co-allocated scsi host */ | 303 | struct Scsi_Host *host; /* our co-allocated scsi host */ |
289 | struct ata_port_operations *ops; | 304 | const struct ata_port_operations *ops; |
290 | unsigned long flags; /* ATA_FLAG_xxx */ | 305 | unsigned long flags; /* ATA_FLAG_xxx */ |
291 | unsigned int id; /* unique id req'd by scsi midlyr */ | 306 | unsigned int id; /* unique id req'd by scsi midlyr */ |
292 | unsigned int port_no; /* unique port #; from zero */ | 307 | unsigned int port_no; /* unique port #; from zero */ |
@@ -319,7 +334,7 @@ struct ata_port { | |||
319 | struct work_struct packet_task; | 334 | struct work_struct packet_task; |
320 | 335 | ||
321 | struct work_struct pio_task; | 336 | struct work_struct pio_task; |
322 | unsigned int pio_task_state; | 337 | unsigned int hsm_task_state; |
323 | unsigned long pio_task_timeout; | 338 | unsigned long pio_task_timeout; |
324 | 339 | ||
325 | void *private_data; | 340 | void *private_data; |
@@ -333,13 +348,12 @@ struct ata_port_operations { | |||
333 | void (*set_piomode) (struct ata_port *, struct ata_device *); | 348 | void (*set_piomode) (struct ata_port *, struct ata_device *); |
334 | void (*set_dmamode) (struct ata_port *, struct ata_device *); | 349 | void (*set_dmamode) (struct ata_port *, struct ata_device *); |
335 | 350 | ||
336 | void (*tf_load) (struct ata_port *ap, struct ata_taskfile *tf); | 351 | void (*tf_load) (struct ata_port *ap, const struct ata_taskfile *tf); |
337 | void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf); | 352 | void (*tf_read) (struct ata_port *ap, struct ata_taskfile *tf); |
338 | 353 | ||
339 | void (*exec_command)(struct ata_port *ap, struct ata_taskfile *tf); | 354 | void (*exec_command)(struct ata_port *ap, const struct ata_taskfile *tf); |
340 | u8 (*check_status)(struct ata_port *ap); | 355 | u8 (*check_status)(struct ata_port *ap); |
341 | u8 (*check_altstatus)(struct ata_port *ap); | 356 | u8 (*check_altstatus)(struct ata_port *ap); |
342 | u8 (*check_err)(struct ata_port *ap); | ||
343 | void (*dev_select)(struct ata_port *ap, unsigned int device); | 357 | void (*dev_select)(struct ata_port *ap, unsigned int device); |
344 | 358 | ||
345 | void (*phy_reset) (struct ata_port *ap); | 359 | void (*phy_reset) (struct ata_port *ap); |
@@ -377,9 +391,22 @@ struct ata_port_info { | |||
377 | unsigned long pio_mask; | 391 | unsigned long pio_mask; |
378 | unsigned long mwdma_mask; | 392 | unsigned long mwdma_mask; |
379 | unsigned long udma_mask; | 393 | unsigned long udma_mask; |
380 | struct ata_port_operations *port_ops; | 394 | const struct ata_port_operations *port_ops; |
395 | }; | ||
396 | |||
397 | struct ata_timing { | ||
398 | unsigned short mode; /* ATA mode */ | ||
399 | unsigned short setup; /* t1 */ | ||
400 | unsigned short act8b; /* t2 for 8-bit I/O */ | ||
401 | unsigned short rec8b; /* t2i for 8-bit I/O */ | ||
402 | unsigned short cyc8b; /* t0 for 8-bit I/O */ | ||
403 | unsigned short active; /* t2 or tD */ | ||
404 | unsigned short recover; /* t2i or tK */ | ||
405 | unsigned short cycle; /* t0 */ | ||
406 | unsigned short udma; /* t2CYCTYP/2 */ | ||
381 | }; | 407 | }; |
382 | 408 | ||
409 | #define FIT(v,vmin,vmax) max_t(short,min_t(short,v,vmax),vmin) | ||
383 | 410 | ||
384 | extern void ata_port_probe(struct ata_port *); | 411 | extern void ata_port_probe(struct ata_port *); |
385 | extern void __sata_phy_reset(struct ata_port *ap); | 412 | extern void __sata_phy_reset(struct ata_port *ap); |
@@ -392,7 +419,7 @@ extern int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_i | |||
392 | unsigned int n_ports); | 419 | unsigned int n_ports); |
393 | extern void ata_pci_remove_one (struct pci_dev *pdev); | 420 | extern void ata_pci_remove_one (struct pci_dev *pdev); |
394 | #endif /* CONFIG_PCI */ | 421 | #endif /* CONFIG_PCI */ |
395 | extern int ata_device_add(struct ata_probe_ent *ent); | 422 | extern int ata_device_add(const struct ata_probe_ent *ent); |
396 | extern void ata_host_set_remove(struct ata_host_set *host_set); | 423 | extern void ata_host_set_remove(struct ata_host_set *host_set); |
397 | extern int ata_scsi_detect(Scsi_Host_Template *sht); | 424 | extern int ata_scsi_detect(Scsi_Host_Template *sht); |
398 | extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); | 425 | extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); |
@@ -400,19 +427,20 @@ extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmn | |||
400 | extern int ata_scsi_error(struct Scsi_Host *host); | 427 | extern int ata_scsi_error(struct Scsi_Host *host); |
401 | extern int ata_scsi_release(struct Scsi_Host *host); | 428 | extern int ata_scsi_release(struct Scsi_Host *host); |
402 | extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); | 429 | extern unsigned int ata_host_intr(struct ata_port *ap, struct ata_queued_cmd *qc); |
430 | extern int ata_ratelimit(void); | ||
431 | |||
403 | /* | 432 | /* |
404 | * Default driver ops implementations | 433 | * Default driver ops implementations |
405 | */ | 434 | */ |
406 | extern void ata_tf_load(struct ata_port *ap, struct ata_taskfile *tf); | 435 | extern void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf); |
407 | extern void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf); | 436 | extern void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf); |
408 | extern void ata_tf_to_fis(struct ata_taskfile *tf, u8 *fis, u8 pmp); | 437 | extern void ata_tf_to_fis(const struct ata_taskfile *tf, u8 *fis, u8 pmp); |
409 | extern void ata_tf_from_fis(u8 *fis, struct ata_taskfile *tf); | 438 | extern void ata_tf_from_fis(const u8 *fis, struct ata_taskfile *tf); |
410 | extern void ata_noop_dev_select (struct ata_port *ap, unsigned int device); | 439 | extern void ata_noop_dev_select (struct ata_port *ap, unsigned int device); |
411 | extern void ata_std_dev_select (struct ata_port *ap, unsigned int device); | 440 | extern void ata_std_dev_select (struct ata_port *ap, unsigned int device); |
412 | extern u8 ata_check_status(struct ata_port *ap); | 441 | extern u8 ata_check_status(struct ata_port *ap); |
413 | extern u8 ata_altstatus(struct ata_port *ap); | 442 | extern u8 ata_altstatus(struct ata_port *ap); |
414 | extern u8 ata_chk_err(struct ata_port *ap); | 443 | extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf); |
415 | extern void ata_exec_command(struct ata_port *ap, struct ata_taskfile *tf); | ||
416 | extern int ata_port_start (struct ata_port *ap); | 444 | extern int ata_port_start (struct ata_port *ap); |
417 | extern void ata_port_stop (struct ata_port *ap); | 445 | extern void ata_port_stop (struct ata_port *ap); |
418 | extern void ata_host_stop (struct ata_host_set *host_set); | 446 | extern void ata_host_stop (struct ata_host_set *host_set); |
@@ -423,8 +451,8 @@ extern void ata_sg_init_one(struct ata_queued_cmd *qc, void *buf, | |||
423 | unsigned int buflen); | 451 | unsigned int buflen); |
424 | extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, | 452 | extern void ata_sg_init(struct ata_queued_cmd *qc, struct scatterlist *sg, |
425 | unsigned int n_elem); | 453 | unsigned int n_elem); |
426 | extern unsigned int ata_dev_classify(struct ata_taskfile *tf); | 454 | extern unsigned int ata_dev_classify(const struct ata_taskfile *tf); |
427 | extern void ata_dev_id_string(u16 *id, unsigned char *s, | 455 | extern void ata_dev_id_string(const u16 *id, unsigned char *s, |
428 | unsigned int ofs, unsigned int len); | 456 | unsigned int ofs, unsigned int len); |
429 | extern void ata_dev_config(struct ata_port *ap, unsigned int i); | 457 | extern void ata_dev_config(struct ata_port *ap, unsigned int i); |
430 | extern void ata_bmdma_setup (struct ata_queued_cmd *qc); | 458 | extern void ata_bmdma_setup (struct ata_queued_cmd *qc); |
@@ -432,7 +460,7 @@ extern void ata_bmdma_start (struct ata_queued_cmd *qc); | |||
432 | extern void ata_bmdma_stop(struct ata_queued_cmd *qc); | 460 | extern void ata_bmdma_stop(struct ata_queued_cmd *qc); |
433 | extern u8 ata_bmdma_status(struct ata_port *ap); | 461 | extern u8 ata_bmdma_status(struct ata_port *ap); |
434 | extern void ata_bmdma_irq_clear(struct ata_port *ap); | 462 | extern void ata_bmdma_irq_clear(struct ata_port *ap); |
435 | extern void ata_qc_complete(struct ata_queued_cmd *qc, u8 drv_stat); | 463 | extern void ata_qc_complete(struct ata_queued_cmd *qc, unsigned int err_mask); |
436 | extern void ata_eng_timeout(struct ata_port *ap); | 464 | extern void ata_eng_timeout(struct ata_port *ap); |
437 | extern void ata_scsi_simulate(u16 *id, struct scsi_cmnd *cmd, | 465 | extern void ata_scsi_simulate(u16 *id, struct scsi_cmnd *cmd, |
438 | void (*done)(struct scsi_cmnd *)); | 466 | void (*done)(struct scsi_cmnd *)); |
@@ -441,6 +469,32 @@ extern int ata_std_bios_param(struct scsi_device *sdev, | |||
441 | sector_t capacity, int geom[]); | 469 | sector_t capacity, int geom[]); |
442 | extern int ata_scsi_slave_config(struct scsi_device *sdev); | 470 | extern int ata_scsi_slave_config(struct scsi_device *sdev); |
443 | 471 | ||
472 | /* | ||
473 | * Timing helpers | ||
474 | */ | ||
475 | extern int ata_timing_compute(struct ata_device *, unsigned short, | ||
476 | struct ata_timing *, int, int); | ||
477 | extern void ata_timing_merge(const struct ata_timing *, | ||
478 | const struct ata_timing *, struct ata_timing *, | ||
479 | unsigned int); | ||
480 | |||
481 | enum { | ||
482 | ATA_TIMING_SETUP = (1 << 0), | ||
483 | ATA_TIMING_ACT8B = (1 << 1), | ||
484 | ATA_TIMING_REC8B = (1 << 2), | ||
485 | ATA_TIMING_CYC8B = (1 << 3), | ||
486 | ATA_TIMING_8BIT = ATA_TIMING_ACT8B | ATA_TIMING_REC8B | | ||
487 | ATA_TIMING_CYC8B, | ||
488 | ATA_TIMING_ACTIVE = (1 << 4), | ||
489 | ATA_TIMING_RECOVER = (1 << 5), | ||
490 | ATA_TIMING_CYCLE = (1 << 6), | ||
491 | ATA_TIMING_UDMA = (1 << 7), | ||
492 | ATA_TIMING_ALL = ATA_TIMING_SETUP | ATA_TIMING_ACT8B | | ||
493 | ATA_TIMING_REC8B | ATA_TIMING_CYC8B | | ||
494 | ATA_TIMING_ACTIVE | ATA_TIMING_RECOVER | | ||
495 | ATA_TIMING_CYCLE | ATA_TIMING_UDMA, | ||
496 | }; | ||
497 | |||
444 | 498 | ||
445 | #ifdef CONFIG_PCI | 499 | #ifdef CONFIG_PCI |
446 | struct pci_bits { | 500 | struct pci_bits { |
@@ -452,8 +506,8 @@ struct pci_bits { | |||
452 | 506 | ||
453 | extern void ata_pci_host_stop (struct ata_host_set *host_set); | 507 | extern void ata_pci_host_stop (struct ata_host_set *host_set); |
454 | extern struct ata_probe_ent * | 508 | extern struct ata_probe_ent * |
455 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port); | 509 | ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int portmask); |
456 | extern int pci_test_config_bits(struct pci_dev *pdev, struct pci_bits *bits); | 510 | extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits); |
457 | 511 | ||
458 | #endif /* CONFIG_PCI */ | 512 | #endif /* CONFIG_PCI */ |
459 | 513 | ||
@@ -463,7 +517,7 @@ static inline unsigned int ata_tag_valid(unsigned int tag) | |||
463 | return (tag < ATA_MAX_QUEUE) ? 1 : 0; | 517 | return (tag < ATA_MAX_QUEUE) ? 1 : 0; |
464 | } | 518 | } |
465 | 519 | ||
466 | static inline unsigned int ata_dev_present(struct ata_device *dev) | 520 | static inline unsigned int ata_dev_present(const struct ata_device *dev) |
467 | { | 521 | { |
468 | return ((dev->class == ATA_DEV_ATA) || | 522 | return ((dev->class == ATA_DEV_ATA) || |
469 | (dev->class == ATA_DEV_ATAPI)); | 523 | (dev->class == ATA_DEV_ATAPI)); |
@@ -662,11 +716,28 @@ static inline unsigned int sata_dev_present(struct ata_port *ap) | |||
662 | return ((scr_read(ap, SCR_STATUS) & 0xf) == 0x3) ? 1 : 0; | 716 | return ((scr_read(ap, SCR_STATUS) & 0xf) == 0x3) ? 1 : 0; |
663 | } | 717 | } |
664 | 718 | ||
665 | static inline int ata_try_flush_cache(struct ata_device *dev) | 719 | static inline int ata_try_flush_cache(const struct ata_device *dev) |
666 | { | 720 | { |
667 | return ata_id_wcache_enabled(dev->id) || | 721 | return ata_id_wcache_enabled(dev->id) || |
668 | ata_id_has_flush(dev->id) || | 722 | ata_id_has_flush(dev->id) || |
669 | ata_id_has_flush_ext(dev->id); | 723 | ata_id_has_flush_ext(dev->id); |
670 | } | 724 | } |
671 | 725 | ||
726 | static inline unsigned int ac_err_mask(u8 status) | ||
727 | { | ||
728 | if (status & ATA_BUSY) | ||
729 | return AC_ERR_ATA_BUS; | ||
730 | if (status & (ATA_ERR | ATA_DF)) | ||
731 | return AC_ERR_DEV; | ||
732 | return 0; | ||
733 | } | ||
734 | |||
735 | static inline unsigned int __ac_err_mask(u8 status) | ||
736 | { | ||
737 | unsigned int mask = ac_err_mask(status); | ||
738 | if (mask == 0) | ||
739 | return AC_ERR_OTHER; | ||
740 | return mask; | ||
741 | } | ||
742 | |||
672 | #endif /* __LINUX_LIBATA_H__ */ | 743 | #endif /* __LINUX_LIBATA_H__ */ |