aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/libata.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/libata.h')
-rw-r--r--include/linux/libata.h141
1 files changed, 45 insertions, 96 deletions
diff --git a/include/linux/libata.h b/include/linux/libata.h
index ab2754830322..596e0c18887d 100644
--- a/include/linux/libata.h
+++ b/include/linux/libata.h
@@ -31,7 +31,7 @@
31#include <linux/pci.h> 31#include <linux/pci.h>
32#include <linux/dma-mapping.h> 32#include <linux/dma-mapping.h>
33#include <asm/scatterlist.h> 33#include <asm/scatterlist.h>
34#include <asm/io.h> 34#include <linux/io.h>
35#include <linux/ata.h> 35#include <linux/ata.h>
36#include <linux/workqueue.h> 36#include <linux/workqueue.h>
37#include <scsi/scsi_host.h> 37#include <scsi/scsi_host.h>
@@ -54,8 +54,6 @@
54#undef ATA_VERBOSE_DEBUG /* yet more debugging output */ 54#undef ATA_VERBOSE_DEBUG /* yet more debugging output */
55#undef ATA_IRQ_TRAP /* define to ack screaming irqs */ 55#undef ATA_IRQ_TRAP /* define to ack screaming irqs */
56#undef ATA_NDEBUG /* define to disable quick runtime checks */ 56#undef ATA_NDEBUG /* define to disable quick runtime checks */
57#define ATA_ENABLE_PATA /* define to enable PATA support in some
58 * low-level drivers */
59 57
60 58
61/* note: prints function name for you */ 59/* note: prints function name for you */
@@ -109,10 +107,6 @@ static inline u32 ata_msg_init(int dval, int default_msg_enable_bits)
109#define ATA_TAG_POISON 0xfafbfcfdU 107#define ATA_TAG_POISON 0xfafbfcfdU
110 108
111/* move to PCI layer? */ 109/* move to PCI layer? */
112#define PCI_VDEVICE(vendor, device) \
113 PCI_VENDOR_ID_##vendor, (device), \
114 PCI_ANY_ID, PCI_ANY_ID, 0, 0
115
116static inline struct device *pci_dev_to_dev(struct pci_dev *pdev) 110static inline struct device *pci_dev_to_dev(struct pci_dev *pdev)
117{ 111{
118 return &pdev->dev; 112 return &pdev->dev;
@@ -177,6 +171,7 @@ enum {
177 * Register FIS clearing BSY */ 171 * Register FIS clearing BSY */
178 ATA_FLAG_DEBUGMSG = (1 << 13), 172 ATA_FLAG_DEBUGMSG = (1 << 13),
179 ATA_FLAG_SETXFER_POLLING= (1 << 14), /* use polling for SETXFER */ 173 ATA_FLAG_SETXFER_POLLING= (1 << 14), /* use polling for SETXFER */
174 ATA_FLAG_IGN_SIMPLEX = (1 << 15), /* ignore SIMPLEX */
180 175
181 /* The following flag belongs to ap->pflags but is kept in 176 /* The following flag belongs to ap->pflags but is kept in
182 * ap->flags because it's referenced in many LLDs and will be 177 * ap->flags because it's referenced in many LLDs and will be
@@ -307,7 +302,7 @@ enum {
307 * most devices. 302 * most devices.
308 */ 303 */
309 ATA_SPINUP_WAIT = 8000, 304 ATA_SPINUP_WAIT = 8000,
310 305
311 /* Horkage types. May be set by libata or controller on drives 306 /* Horkage types. May be set by libata or controller on drives
312 (some horkage may be drive/controller pair dependant */ 307 (some horkage may be drive/controller pair dependant */
313 308
@@ -351,21 +346,21 @@ typedef int (*ata_reset_fn_t)(struct ata_port *ap, unsigned int *classes);
351typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *classes); 346typedef void (*ata_postreset_fn_t)(struct ata_port *ap, unsigned int *classes);
352 347
353struct ata_ioports { 348struct ata_ioports {
354 unsigned long cmd_addr; 349 void __iomem *cmd_addr;
355 unsigned long data_addr; 350 void __iomem *data_addr;
356 unsigned long error_addr; 351 void __iomem *error_addr;
357 unsigned long feature_addr; 352 void __iomem *feature_addr;
358 unsigned long nsect_addr; 353 void __iomem *nsect_addr;
359 unsigned long lbal_addr; 354 void __iomem *lbal_addr;
360 unsigned long lbam_addr; 355 void __iomem *lbam_addr;
361 unsigned long lbah_addr; 356 void __iomem *lbah_addr;
362 unsigned long device_addr; 357 void __iomem *device_addr;
363 unsigned long status_addr; 358 void __iomem *status_addr;
364 unsigned long command_addr; 359 void __iomem *command_addr;
365 unsigned long altstatus_addr; 360 void __iomem *altstatus_addr;
366 unsigned long ctl_addr; 361 void __iomem *ctl_addr;
367 unsigned long bmdma_addr; 362 void __iomem *bmdma_addr;
368 unsigned long scr_addr; 363 void __iomem *scr_addr;
369}; 364};
370 365
371struct ata_probe_ent { 366struct ata_probe_ent {
@@ -384,7 +379,7 @@ struct ata_probe_ent {
384 unsigned int irq_flags; 379 unsigned int irq_flags;
385 unsigned long port_flags; 380 unsigned long port_flags;
386 unsigned long _host_flags; 381 unsigned long _host_flags;
387 void __iomem *mmio_base; 382 void __iomem * const *iomap;
388 void *private_data; 383 void *private_data;
389 384
390 /* port_info for the secondary port. Together with irq2, it's 385 /* port_info for the secondary port. Together with irq2, it's
@@ -401,7 +396,7 @@ struct ata_host {
401 struct device *dev; 396 struct device *dev;
402 unsigned long irq; 397 unsigned long irq;
403 unsigned long irq2; 398 unsigned long irq2;
404 void __iomem *mmio_base; 399 void __iomem * const *iomap;
405 unsigned int n_ports; 400 unsigned int n_ports;
406 void *private_data; 401 void *private_data;
407 const struct ata_port_operations *ops; 402 const struct ata_port_operations *ops;
@@ -430,9 +425,6 @@ struct ata_queued_cmd {
430 425
431 unsigned int pad_len; 426 unsigned int pad_len;
432 427
433 unsigned int nsect;
434 unsigned int cursect;
435
436 unsigned int nbytes; 428 unsigned int nbytes;
437 unsigned int curbytes; 429 unsigned int curbytes;
438 430
@@ -612,11 +604,11 @@ struct ata_port_operations {
612 void (*dev_select)(struct ata_port *ap, unsigned int device); 604 void (*dev_select)(struct ata_port *ap, unsigned int device);
613 605
614 void (*phy_reset) (struct ata_port *ap); /* obsolete */ 606 void (*phy_reset) (struct ata_port *ap); /* obsolete */
615 void (*set_mode) (struct ata_port *ap); 607 int (*set_mode) (struct ata_port *ap, struct ata_device **r_failed_dev);
616 608
617 void (*post_set_mode) (struct ata_port *ap); 609 void (*post_set_mode) (struct ata_port *ap);
618 610
619 int (*check_atapi_dma) (struct ata_queued_cmd *qc); 611 int (*check_atapi_dma) (struct ata_queued_cmd *qc);
620 612
621 void (*bmdma_setup) (struct ata_queued_cmd *qc); 613 void (*bmdma_setup) (struct ata_queued_cmd *qc);
622 void (*bmdma_start) (struct ata_queued_cmd *qc); 614 void (*bmdma_start) (struct ata_queued_cmd *qc);
@@ -638,6 +630,8 @@ struct ata_port_operations {
638 630
639 irq_handler_t irq_handler; 631 irq_handler_t irq_handler;
640 void (*irq_clear) (struct ata_port *); 632 void (*irq_clear) (struct ata_port *);
633 u8 (*irq_on) (struct ata_port *);
634 u8 (*irq_ack) (struct ata_port *ap, unsigned int chk_drq);
641 635
642 u32 (*scr_read) (struct ata_port *ap, unsigned int sc_reg); 636 u32 (*scr_read) (struct ata_port *ap, unsigned int sc_reg);
643 void (*scr_write) (struct ata_port *ap, unsigned int sc_reg, 637 void (*scr_write) (struct ata_port *ap, unsigned int sc_reg,
@@ -719,20 +713,18 @@ extern int ata_pci_init_one (struct pci_dev *pdev, struct ata_port_info **port_i
719 unsigned int n_ports); 713 unsigned int n_ports);
720extern void ata_pci_remove_one (struct pci_dev *pdev); 714extern void ata_pci_remove_one (struct pci_dev *pdev);
721extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg); 715extern void ata_pci_device_do_suspend(struct pci_dev *pdev, pm_message_t mesg);
722extern void ata_pci_device_do_resume(struct pci_dev *pdev); 716extern int __must_check ata_pci_device_do_resume(struct pci_dev *pdev);
723extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg); 717extern int ata_pci_device_suspend(struct pci_dev *pdev, pm_message_t mesg);
724extern int ata_pci_device_resume(struct pci_dev *pdev); 718extern int ata_pci_device_resume(struct pci_dev *pdev);
725extern int ata_pci_clear_simplex(struct pci_dev *pdev); 719extern int ata_pci_clear_simplex(struct pci_dev *pdev);
726#endif /* CONFIG_PCI */ 720#endif /* CONFIG_PCI */
727extern int ata_device_add(const struct ata_probe_ent *ent); 721extern int ata_device_add(const struct ata_probe_ent *ent);
728extern void ata_port_detach(struct ata_port *ap); 722extern void ata_host_detach(struct ata_host *host);
729extern void ata_host_init(struct ata_host *, struct device *, 723extern void ata_host_init(struct ata_host *, struct device *,
730 unsigned long, const struct ata_port_operations *); 724 unsigned long, const struct ata_port_operations *);
731extern void ata_host_remove(struct ata_host *host);
732extern int ata_scsi_detect(struct scsi_host_template *sht); 725extern int ata_scsi_detect(struct scsi_host_template *sht);
733extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg); 726extern int ata_scsi_ioctl(struct scsi_device *dev, int cmd, void __user *arg);
734extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)); 727extern int ata_scsi_queuecmd(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *));
735extern int ata_scsi_release(struct Scsi_Host *host);
736extern void ata_sas_port_destroy(struct ata_port *); 728extern void ata_sas_port_destroy(struct ata_port *);
737extern struct ata_port *ata_sas_port_alloc(struct ata_host *, 729extern struct ata_port *ata_sas_port_alloc(struct ata_host *,
738 struct ata_port_info *, struct Scsi_Host *); 730 struct ata_port_info *, struct Scsi_Host *);
@@ -775,15 +767,11 @@ extern u8 ata_check_status(struct ata_port *ap);
775extern u8 ata_altstatus(struct ata_port *ap); 767extern u8 ata_altstatus(struct ata_port *ap);
776extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf); 768extern void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf);
777extern int ata_port_start (struct ata_port *ap); 769extern int ata_port_start (struct ata_port *ap);
778extern void ata_port_stop (struct ata_port *ap);
779extern void ata_host_stop (struct ata_host *host);
780extern irqreturn_t ata_interrupt (int irq, void *dev_instance); 770extern irqreturn_t ata_interrupt (int irq, void *dev_instance);
781extern void ata_mmio_data_xfer(struct ata_device *adev, unsigned char *buf, 771extern void ata_data_xfer(struct ata_device *adev, unsigned char *buf,
782 unsigned int buflen, int write_data); 772 unsigned int buflen, int write_data);
783extern void ata_pio_data_xfer(struct ata_device *adev, unsigned char *buf, 773extern void ata_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
784 unsigned int buflen, int write_data); 774 unsigned int buflen, int write_data);
785extern void ata_pio_data_xfer_noirq(struct ata_device *adev, unsigned char *buf,
786 unsigned int buflen, int write_data);
787extern void ata_qc_prep(struct ata_queued_cmd *qc); 775extern void ata_qc_prep(struct ata_queued_cmd *qc);
788extern void ata_noop_qc_prep(struct ata_queued_cmd *qc); 776extern void ata_noop_qc_prep(struct ata_queued_cmd *qc);
789extern unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc); 777extern unsigned int ata_qc_issue_prot(struct ata_queued_cmd *qc);
@@ -825,6 +813,10 @@ extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
825extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, 813extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
826 int queue_depth); 814 int queue_depth);
827extern struct ata_device *ata_dev_pair(struct ata_device *adev); 815extern struct ata_device *ata_dev_pair(struct ata_device *adev);
816extern u8 ata_irq_on(struct ata_port *ap);
817extern u8 ata_dummy_irq_on(struct ata_port *ap);
818extern u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq);
819extern u8 ata_dummy_irq_ack(struct ata_port *ap, unsigned int chk_drq);
828 820
829/* 821/*
830 * Timing helpers 822 * Timing helpers
@@ -863,7 +855,6 @@ struct pci_bits {
863 unsigned long val; 855 unsigned long val;
864}; 856};
865 857
866extern void ata_pci_host_stop (struct ata_host *host);
867extern struct ata_probe_ent * 858extern struct ata_probe_ent *
868ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int portmask); 859ata_pci_init_native_mode(struct pci_dev *pdev, struct ata_port_info **port, int portmask);
869extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits); 860extern int pci_test_config_bits(struct pci_dev *pdev, const struct pci_bits *bits);
@@ -1053,6 +1044,8 @@ static inline void ata_pause(struct ata_port *ap)
1053/** 1044/**
1054 * ata_busy_wait - Wait for a port status register 1045 * ata_busy_wait - Wait for a port status register
1055 * @ap: Port to wait for. 1046 * @ap: Port to wait for.
1047 * @bits: bits that must be clear
1048 * @max: number of 10uS waits to perform
1056 * 1049 *
1057 * Waits up to max*10 microseconds for the selected bits in the port's 1050 * Waits up to max*10 microseconds for the selected bits in the port's
1058 * status register to be cleared. 1051 * status register to be cleared.
@@ -1093,10 +1086,9 @@ static inline u8 ata_wait_idle(struct ata_port *ap)
1093 u8 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000); 1086 u8 status = ata_busy_wait(ap, ATA_BUSY | ATA_DRQ, 1000);
1094 1087
1095 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ))) { 1088 if (status != 0xff && (status & (ATA_BUSY | ATA_DRQ))) {
1096 unsigned long l = ap->ioaddr.status_addr;
1097 if (ata_msg_warn(ap)) 1089 if (ata_msg_warn(ap))
1098 printk(KERN_WARNING "ATA: abnormal status 0x%X on port 0x%lX\n", 1090 printk(KERN_WARNING "ATA: abnormal status 0x%X on port 0x%p\n",
1099 status, l); 1091 status, ap->ioaddr.status_addr);
1100 } 1092 }
1101 1093
1102 return status; 1094 return status;
@@ -1143,12 +1135,14 @@ static inline void ata_tf_init(struct ata_device *dev, struct ata_taskfile *tf)
1143 1135
1144static inline void ata_qc_reinit(struct ata_queued_cmd *qc) 1136static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
1145{ 1137{
1138 qc->dma_dir = DMA_NONE;
1146 qc->__sg = NULL; 1139 qc->__sg = NULL;
1147 qc->flags = 0; 1140 qc->flags = 0;
1148 qc->cursect = qc->cursg = qc->cursg_ofs = 0; 1141 qc->cursg = qc->cursg_ofs = 0;
1149 qc->nsect = 0;
1150 qc->nbytes = qc->curbytes = 0; 1142 qc->nbytes = qc->curbytes = 0;
1143 qc->n_elem = 0;
1151 qc->err_mask = 0; 1144 qc->err_mask = 0;
1145 qc->pad_len = 0;
1152 1146
1153 ata_tf_init(qc->dev, &qc->tf); 1147 ata_tf_init(qc->dev, &qc->tf);
1154 1148
@@ -1157,51 +1151,6 @@ static inline void ata_qc_reinit(struct ata_queued_cmd *qc)
1157 qc->result_tf.feature = 0; 1151 qc->result_tf.feature = 0;
1158} 1152}
1159 1153
1160/**
1161 * ata_irq_ack - Acknowledge a device interrupt.
1162 * @ap: Port on which interrupts are enabled.
1163 *
1164 * Wait up to 10 ms for legacy IDE device to become idle (BUSY
1165 * or BUSY+DRQ clear). Obtain dma status and port status from
1166 * device. Clear the interrupt. Return port status.
1167 *
1168 * LOCKING:
1169 */
1170
1171static inline u8 ata_irq_ack(struct ata_port *ap, unsigned int chk_drq)
1172{
1173 unsigned int bits = chk_drq ? ATA_BUSY | ATA_DRQ : ATA_BUSY;
1174 u8 host_stat, post_stat, status;
1175
1176 status = ata_busy_wait(ap, bits, 1000);
1177 if (status & bits)
1178 if (ata_msg_err(ap))
1179 printk(KERN_ERR "abnormal status 0x%X\n", status);
1180
1181 /* get controller status; clear intr, err bits */
1182 if (ap->flags & ATA_FLAG_MMIO) {
1183 void __iomem *mmio = (void __iomem *) ap->ioaddr.bmdma_addr;
1184 host_stat = readb(mmio + ATA_DMA_STATUS);
1185 writeb(host_stat | ATA_DMA_INTR | ATA_DMA_ERR,
1186 mmio + ATA_DMA_STATUS);
1187
1188 post_stat = readb(mmio + ATA_DMA_STATUS);
1189 } else {
1190 host_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
1191 outb(host_stat | ATA_DMA_INTR | ATA_DMA_ERR,
1192 ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
1193
1194 post_stat = inb(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);
1195 }
1196
1197 if (ata_msg_intr(ap))
1198 printk(KERN_INFO "%s: irq ack: host_stat 0x%X, new host_stat 0x%X, drv_stat 0x%X\n",
1199 __FUNCTION__,
1200 host_stat, post_stat, status);
1201
1202 return status;
1203}
1204
1205static inline int ata_try_flush_cache(const struct ata_device *dev) 1154static inline int ata_try_flush_cache(const struct ata_device *dev)
1206{ 1155{
1207 return ata_id_wcache_enabled(dev->id) || 1156 return ata_id_wcache_enabled(dev->id) ||
@@ -1229,14 +1178,14 @@ static inline unsigned int __ac_err_mask(u8 status)
1229static inline int ata_pad_alloc(struct ata_port *ap, struct device *dev) 1178static inline int ata_pad_alloc(struct ata_port *ap, struct device *dev)
1230{ 1179{
1231 ap->pad_dma = 0; 1180 ap->pad_dma = 0;
1232 ap->pad = dma_alloc_coherent(dev, ATA_DMA_PAD_BUF_SZ, 1181 ap->pad = dmam_alloc_coherent(dev, ATA_DMA_PAD_BUF_SZ,
1233 &ap->pad_dma, GFP_KERNEL); 1182 &ap->pad_dma, GFP_KERNEL);
1234 return (ap->pad == NULL) ? -ENOMEM : 0; 1183 return (ap->pad == NULL) ? -ENOMEM : 0;
1235} 1184}
1236 1185
1237static inline void ata_pad_free(struct ata_port *ap, struct device *dev) 1186static inline void ata_pad_free(struct ata_port *ap, struct device *dev)
1238{ 1187{
1239 dma_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma); 1188 dmam_free_coherent(dev, ATA_DMA_PAD_BUF_SZ, ap->pad, ap->pad_dma);
1240} 1189}
1241 1190
1242static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host) 1191static inline struct ata_port *ata_shost_to_port(struct Scsi_Host *host)