26 #ifndef __LINUX_LIBATA_H__
27 #define __LINUX_LIBATA_H__
39 #include <linux/cdrom.h>
40 #include <linux/sched.h>
46 #ifdef CONFIG_ATA_NONSTANDARD
47 #include <asm/libata-portmap.h>
57 #undef ATA_VERBOSE_DEBUG
64 #define DPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
65 #ifdef ATA_VERBOSE_DEBUG
66 #define VPRINTK(fmt, args...) printk(KERN_ERR "%s: " fmt, __func__, ## args)
68 #define VPRINTK(fmt, args...)
71 #define DPRINTK(fmt, args...)
72 #define VPRINTK(fmt, args...)
75 #define BPRINTK(fmt, args...) if (ap->flags & ATA_FLAG_DEBUGMSG) printk(KERN_ERR "%s: " fmt, __func__, ## args)
77 #define ata_print_version_once(dev, version) \
79 static bool __print_once; \
81 if (!__print_once) { \
82 __print_once = true; \
83 ata_print_version(dev, version); \
88 #define HAVE_LIBATA_MSG 1
101 #define ata_msg_drv(p) ((p)->msg_enable & ATA_MSG_DRV)
102 #define ata_msg_info(p) ((p)->msg_enable & ATA_MSG_INFO)
103 #define ata_msg_probe(p) ((p)->msg_enable & ATA_MSG_PROBE)
104 #define ata_msg_warn(p) ((p)->msg_enable & ATA_MSG_WARN)
105 #define ata_msg_malloc(p) ((p)->msg_enable & ATA_MSG_MALLOC)
106 #define ata_msg_ctl(p) ((p)->msg_enable & ATA_MSG_CTL)
107 #define ata_msg_intr(p) ((p)->msg_enable & ATA_MSG_INTR)
108 #define ata_msg_err(p) ((p)->msg_enable & ATA_MSG_ERR)
110 static inline u32 ata_msg_init(
int dval,
int default_msg_enable_bits)
112 if (dval < 0 || dval >= (
sizeof(
u32) * 8))
113 return default_msg_enable_bits;
116 return (1 << dval) - 1;
120 #define ATA_TAG_POISON 0xfafbfcfdU
503 unsigned long deadline);
518 #ifdef CONFIG_ATA_SFF
533 #ifdef CONFIG_ATA_BMDMA
618 #ifdef CONFIG_ATA_ACPI
620 unsigned int gtf_filter;
666 #define ATA_DEVICE_CLEAR_BEGIN offsetof(struct ata_device, n_sectors)
667 #define ATA_DEVICE_CLEAR_END offsetof(struct ata_device, ering)
731 #define ATA_LINK_CLEAR_BEGIN offsetof(struct ata_link, active_tag)
732 #define ATA_LINK_CLEAR_END offsetof(struct ata_link, device[0])
746 #ifdef CONFIG_ATA_SFF
747 struct ata_ioports ioaddr;
752 #ifdef CONFIG_ATA_BMDMA
802 #ifdef CONFIG_ATA_ACPI
814 #define ATA_OP_NULL (void *)(unsigned long)(-ENOENT)
873 #ifdef CONFIG_ATA_SFF
880 u8 (*sff_check_altstatus)(
struct ata_port *ap);
892 #ifdef CONFIG_ATA_BMDMA
952 static inline const unsigned long *
961 static inline int ata_port_is_dummy(
struct ata_port *ap)
969 int (*check_ready)(
struct ata_link *link));
971 const unsigned long *
params,
unsigned long deadline);
973 unsigned long deadline);
977 const unsigned long *
timing,
unsigned long deadline,
980 unsigned long deadline);
999 int cmd,
void __user *
arg);
1019 extern int ata_sas_port_async_suspend(
struct ata_port *ap,
int *
async);
1020 extern int ata_sas_port_async_resume(
struct ata_port *ap,
int *
async);
1022 static inline int ata_sas_port_async_suspend(
struct ata_port *ap,
int *
async)
1026 static inline int ata_sas_port_async_resume(
struct ata_port *ap,
int *
async)
1052 unsigned int n_elem);
1056 unsigned int ofs,
unsigned int len);
1058 unsigned int ofs,
unsigned int len);
1106 extern int pci_test_config_bits(
struct pci_dev *pdev,
const struct pci_bits *
bits);
1107 extern void ata_pci_remove_one(
struct pci_dev *pdev);
1113 extern int ata_pci_device_resume(
struct pci_dev *pdev);
1120 #ifdef CONFIG_ATA_ACPI
1124 return &ap->__acpi_init_gtm;
1215 #define ATA_BASE_SHT(drv_name) \
1216 .module = THIS_MODULE, \
1218 .ioctl = ata_scsi_ioctl, \
1219 .queuecommand = ata_scsi_queuecmd, \
1220 .can_queue = ATA_DEF_QUEUE, \
1221 .this_id = ATA_SHT_THIS_ID, \
1222 .cmd_per_lun = ATA_SHT_CMD_PER_LUN, \
1223 .emulated = ATA_SHT_EMULATED, \
1224 .use_clustering = ATA_SHT_USE_CLUSTERING, \
1225 .proc_name = drv_name, \
1226 .slave_configure = ata_scsi_slave_config, \
1227 .slave_destroy = ata_scsi_slave_destroy, \
1228 .bios_param = ata_std_bios_param, \
1229 .unlock_native_capacity = ata_scsi_unlock_native_capacity, \
1230 .sdev_attrs = ata_common_sdev_attrs
1232 #define ATA_NCQ_SHT(drv_name) \
1233 ATA_BASE_SHT(drv_name), \
1234 .change_queue_depth = ata_scsi_change_queue_depth
1239 #ifdef CONFIG_SATA_PMP
1240 static inline bool sata_pmp_supported(
struct ata_port *ap)
1245 static inline bool sata_pmp_attached(
struct ata_port *ap)
1250 static inline int ata_is_host_link(
const struct ata_link *link)
1252 return link == &link->
ap->link || link == link->
ap->slave_link;
1255 static inline bool sata_pmp_supported(
struct ata_port *ap)
1260 static inline bool sata_pmp_attached(
struct ata_port *ap)
1265 static inline int ata_is_host_link(
const struct ata_link *link)
1271 static inline int sata_srst_pmp(
struct ata_link *link)
1273 if (sata_pmp_supported(link->
ap) && ata_is_host_link(link))
1286 const char *fmt, ...);
1289 const char *fmt, ...);
1291 #define ata_port_err(ap, fmt, ...) \
1292 ata_port_printk(ap, KERN_ERR, fmt, ##__VA_ARGS__)
1293 #define ata_port_warn(ap, fmt, ...) \
1294 ata_port_printk(ap, KERN_WARNING, fmt, ##__VA_ARGS__)
1295 #define ata_port_notice(ap, fmt, ...) \
1296 ata_port_printk(ap, KERN_NOTICE, fmt, ##__VA_ARGS__)
1297 #define ata_port_info(ap, fmt, ...) \
1298 ata_port_printk(ap, KERN_INFO, fmt, ##__VA_ARGS__)
1299 #define ata_port_dbg(ap, fmt, ...) \
1300 ata_port_printk(ap, KERN_DEBUG, fmt, ##__VA_ARGS__)
1302 #define ata_link_err(link, fmt, ...) \
1303 ata_link_printk(link, KERN_ERR, fmt, ##__VA_ARGS__)
1304 #define ata_link_warn(link, fmt, ...) \
1305 ata_link_printk(link, KERN_WARNING, fmt, ##__VA_ARGS__)
1306 #define ata_link_notice(link, fmt, ...) \
1307 ata_link_printk(link, KERN_NOTICE, fmt, ##__VA_ARGS__)
1308 #define ata_link_info(link, fmt, ...) \
1309 ata_link_printk(link, KERN_INFO, fmt, ##__VA_ARGS__)
1310 #define ata_link_dbg(link, fmt, ...) \
1311 ata_link_printk(link, KERN_DEBUG, fmt, ##__VA_ARGS__)
1313 #define ata_dev_err(dev, fmt, ...) \
1314 ata_dev_printk(dev, KERN_ERR, fmt, ##__VA_ARGS__)
1315 #define ata_dev_warn(dev, fmt, ...) \
1316 ata_dev_printk(dev, KERN_WARNING, fmt, ##__VA_ARGS__)
1317 #define ata_dev_notice(dev, fmt, ...) \
1318 ata_dev_printk(dev, KERN_NOTICE, fmt, ##__VA_ARGS__)
1319 #define ata_dev_info(dev, fmt, ...) \
1320 ata_dev_printk(dev, KERN_INFO, fmt, ##__VA_ARGS__)
1321 #define ata_dev_dbg(dev, fmt, ...) \
1322 ata_dev_printk(dev, KERN_DEBUG, fmt, ##__VA_ARGS__)
1353 static inline unsigned int ata_tag_valid(
unsigned int tag)
1358 static inline unsigned int ata_tag_internal(
unsigned int tag)
1366 static inline unsigned int ata_class_enabled(
unsigned int class)
1372 static inline unsigned int ata_class_disabled(
unsigned int class)
1378 static inline unsigned int ata_class_absent(
unsigned int class)
1380 return !ata_class_enabled(
class) && !ata_class_disabled(
class);
1383 static inline unsigned int ata_dev_enabled(
const struct ata_device *dev)
1385 return ata_class_enabled(dev->
class);
1388 static inline unsigned int ata_dev_disabled(
const struct ata_device *dev)
1390 return ata_class_disabled(dev->
class);
1393 static inline unsigned int ata_dev_absent(
const struct ata_device *dev)
1395 return ata_class_absent(dev->
class);
1401 static inline int ata_link_max_devices(
const struct ata_link *link)
1408 static inline int ata_link_active(
struct ata_link *link)
1462 #define ata_for_each_link(link, ap, mode) \
1463 for ((link) = ata_link_next(NULL, (ap), ATA_LITER_##mode); (link); \
1464 (link) = ata_link_next((link), (ap), ATA_LITER_##mode))
1466 #define ata_for_each_dev(dev, link, mode) \
1467 for ((dev) = ata_dev_next(NULL, (link), ATA_DITER_##mode); (dev); \
1468 (dev) = ata_dev_next((dev), (link), ATA_DITER_##mode))
1480 static inline int ata_ncq_enabled(
struct ata_device *dev)
1494 if (
likely(ata_tag_valid(tag)))
1514 static inline unsigned int ata_qc_raw_nbytes(
struct ata_queued_cmd *qc)
1521 memset(tf, 0,
sizeof(*tf));
1523 #ifdef CONFIG_ATA_SFF
1528 if (dev->
devno == 0)
1546 ata_tf_init(qc->
dev, &qc->
tf);
1553 static inline int ata_try_flush_cache(
const struct ata_device *dev)
1555 return ata_id_wcache_enabled(dev->
id) ||
1556 ata_id_has_flush(dev->
id) ||
1557 ata_id_has_flush_ext(dev->
id);
1560 static inline unsigned int ac_err_mask(
u8 status)
1569 static inline unsigned int __ac_err_mask(
u8 status)
1571 unsigned int mask = ac_err_mask(status);
1579 return *(
struct ata_port **)&host->hostdata[0];
1582 static inline int ata_check_ready(
u8 status)
1594 static inline unsigned long ata_deadline(
unsigned long from_jiffies,
1595 unsigned long timeout_msecs)
1604 static inline int ata_using_mwdma(
struct ata_device *adev)
1611 static inline int ata_using_udma(
struct ata_device *adev)
1618 static inline int ata_dma_enabled(
struct ata_device *adev)
1620 return (adev->
dma_mode == 0xFF ? 0 : 1);
1626 #ifdef CONFIG_SATA_PMP
1635 #define sata_pmp_port_ops sata_port_ops
1636 #define sata_pmp_qc_defer_cmd_switch ata_std_qc_defer
1637 #define sata_pmp_error_handler ata_std_error_handler
1645 #ifdef CONFIG_ATA_SFF
1651 #define ATA_PIO_SHT(drv_name) \
1652 ATA_BASE_SHT(drv_name), \
1653 .sg_tablesize = LIBATA_MAX_PRD, \
1654 .dma_boundary = ATA_DMA_BOUNDARY
1661 unsigned long timeout_pat,
unsigned long timeout);
1674 extern void ata_sff_irq_clear(
struct ata_port *ap);
1676 u8 status,
int in_wq);
1679 unsigned long delay);
1693 unsigned long deadline);
1695 unsigned long deadline);
1697 unsigned long deadline);
1703 extern int ata_pci_sff_init_host(
struct ata_host *
host);
1704 extern int ata_pci_sff_prepare_host(
struct pci_dev *pdev,
1707 extern int ata_pci_sff_activate_host(
struct ata_host *
host,
1710 extern int ata_pci_sff_init_one(
struct pci_dev *pdev,
1715 #ifdef CONFIG_ATA_BMDMA
1719 #define ATA_BMDMA_SHT(drv_name) \
1720 ATA_BASE_SHT(drv_name), \
1721 .sg_tablesize = LIBATA_MAX_PRD, \
1722 .dma_boundary = ATA_DMA_BOUNDARY
1725 extern unsigned int ata_bmdma_qc_issue(
struct ata_queued_cmd *qc);
1727 extern unsigned int ata_bmdma_port_intr(
struct ata_port *ap,
1729 extern irqreturn_t ata_bmdma_interrupt(
int irq,
void *dev_instance);
1730 extern void ata_bmdma_error_handler(
struct ata_port *ap);
1731 extern void ata_bmdma_post_internal_cmd(
struct ata_queued_cmd *qc);
1732 extern void ata_bmdma_irq_clear(
struct ata_port *ap);
1736 extern u8 ata_bmdma_status(
struct ata_port *ap);
1737 extern int ata_bmdma_port_start(
struct ata_port *ap);
1738 extern int ata_bmdma_port_start32(
struct ata_port *ap);
1741 extern int ata_pci_bmdma_clear_simplex(
struct pci_dev *pdev);
1743 extern int ata_pci_bmdma_prepare_host(
struct pci_dev *pdev,
1746 extern int ata_pci_bmdma_init_one(
struct pci_dev *pdev,
1749 void *host_priv,
int hflags);
1766 static inline u8 ata_sff_busy_wait(
struct ata_port *ap,
unsigned int bits,
1773 status = ap->
ops->sff_check_status(ap);
1775 }
while (status != 0xff && (status & bits) && (max > 0));
1790 static inline u8 ata_wait_idle(
struct ata_port *ap)
1792 u8 status = ata_sff_busy_wait(ap, ATA_BUSY |
ATA_DRQ, 1000);
1795 if (status != 0xff && (status & (ATA_BUSY |
ATA_DRQ)))