18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  libata.h - helper library for ATA
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright 2003-2004 Red Hat, Inc.  All rights reserved.
68c2ecf20Sopenharmony_ci *  Copyright 2003-2004 Jeff Garzik
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci *  libata documentation is available via 'make {ps|pdf}docs',
98c2ecf20Sopenharmony_ci *  as Documentation/driver-api/libata.rst
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#ifndef __LIBATA_H__
138c2ecf20Sopenharmony_ci#define __LIBATA_H__
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define DRV_NAME	"libata"
168c2ecf20Sopenharmony_ci#define DRV_VERSION	"3.00"	/* must be exactly four chars */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* libata-core.c */
198c2ecf20Sopenharmony_cienum {
208c2ecf20Sopenharmony_ci	/* flags for ata_dev_read_id() */
218c2ecf20Sopenharmony_ci	ATA_READID_POSTRESET	= (1 << 0), /* reading ID after reset */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci	/* selector for ata_down_xfermask_limit() */
248c2ecf20Sopenharmony_ci	ATA_DNXFER_PIO		= 0,	/* speed down PIO */
258c2ecf20Sopenharmony_ci	ATA_DNXFER_DMA		= 1,	/* speed down DMA */
268c2ecf20Sopenharmony_ci	ATA_DNXFER_40C		= 2,	/* apply 40c cable limit */
278c2ecf20Sopenharmony_ci	ATA_DNXFER_FORCE_PIO	= 3,	/* force PIO */
288c2ecf20Sopenharmony_ci	ATA_DNXFER_FORCE_PIO0	= 4,	/* force PIO0 */
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci	ATA_DNXFER_QUIET	= (1 << 31),
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#define ATA_PORT_TYPE_NAME	"ata_port"
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ciextern atomic_t ata_print_id;
368c2ecf20Sopenharmony_ciextern int atapi_passthru16;
378c2ecf20Sopenharmony_ciextern int libata_fua;
388c2ecf20Sopenharmony_ciextern int libata_noacpi;
398c2ecf20Sopenharmony_ciextern int libata_allow_tpm;
408c2ecf20Sopenharmony_ciextern const struct device_type ata_port_type;
418c2ecf20Sopenharmony_ciextern struct ata_link *ata_dev_phys_link(struct ata_device *dev);
428c2ecf20Sopenharmony_ci#ifdef CONFIG_ATA_FORCE
438c2ecf20Sopenharmony_ciextern void ata_force_cbl(struct ata_port *ap);
448c2ecf20Sopenharmony_ci#else
458c2ecf20Sopenharmony_cistatic inline void ata_force_cbl(struct ata_port *ap) { }
468c2ecf20Sopenharmony_ci#endif
478c2ecf20Sopenharmony_ciextern u64 ata_tf_to_lba(const struct ata_taskfile *tf);
488c2ecf20Sopenharmony_ciextern u64 ata_tf_to_lba48(const struct ata_taskfile *tf);
498c2ecf20Sopenharmony_ciextern struct ata_queued_cmd *ata_qc_new_init(struct ata_device *dev, int tag);
508c2ecf20Sopenharmony_ciextern int ata_build_rw_tf(struct ata_taskfile *tf, struct ata_device *dev,
518c2ecf20Sopenharmony_ci			   u64 block, u32 n_block, unsigned int tf_flags,
528c2ecf20Sopenharmony_ci			   unsigned int tag, int class);
538c2ecf20Sopenharmony_ciextern u64 ata_tf_read_block(const struct ata_taskfile *tf,
548c2ecf20Sopenharmony_ci			     struct ata_device *dev);
558c2ecf20Sopenharmony_ciextern unsigned ata_exec_internal(struct ata_device *dev,
568c2ecf20Sopenharmony_ci				  struct ata_taskfile *tf, const u8 *cdb,
578c2ecf20Sopenharmony_ci				  int dma_dir, void *buf, unsigned int buflen,
588c2ecf20Sopenharmony_ci				  unsigned long timeout);
598c2ecf20Sopenharmony_ciextern unsigned ata_exec_internal_sg(struct ata_device *dev,
608c2ecf20Sopenharmony_ci				     struct ata_taskfile *tf, const u8 *cdb,
618c2ecf20Sopenharmony_ci				     int dma_dir, struct scatterlist *sg,
628c2ecf20Sopenharmony_ci				     unsigned int n_elem, unsigned long timeout);
638c2ecf20Sopenharmony_ciextern int ata_wait_ready(struct ata_link *link, unsigned long deadline,
648c2ecf20Sopenharmony_ci			  int (*check_ready)(struct ata_link *link));
658c2ecf20Sopenharmony_ciextern int ata_dev_read_id(struct ata_device *dev, unsigned int *p_class,
668c2ecf20Sopenharmony_ci			   unsigned int flags, u16 *id);
678c2ecf20Sopenharmony_ciextern int ata_dev_reread_id(struct ata_device *dev, unsigned int readid_flags);
688c2ecf20Sopenharmony_ciextern int ata_dev_revalidate(struct ata_device *dev, unsigned int new_class,
698c2ecf20Sopenharmony_ci			      unsigned int readid_flags);
708c2ecf20Sopenharmony_ciextern int ata_dev_configure(struct ata_device *dev);
718c2ecf20Sopenharmony_ciextern int sata_down_spd_limit(struct ata_link *link, u32 spd_limit);
728c2ecf20Sopenharmony_ciextern int ata_down_xfermask_limit(struct ata_device *dev, unsigned int sel);
738c2ecf20Sopenharmony_ciextern unsigned int ata_dev_set_feature(struct ata_device *dev,
748c2ecf20Sopenharmony_ci					u8 enable, u8 feature);
758c2ecf20Sopenharmony_ciextern void ata_qc_free(struct ata_queued_cmd *qc);
768c2ecf20Sopenharmony_ciextern void ata_qc_issue(struct ata_queued_cmd *qc);
778c2ecf20Sopenharmony_ciextern void __ata_qc_complete(struct ata_queued_cmd *qc);
788c2ecf20Sopenharmony_ciextern int atapi_check_dma(struct ata_queued_cmd *qc);
798c2ecf20Sopenharmony_ciextern void swap_buf_le16(u16 *buf, unsigned int buf_words);
808c2ecf20Sopenharmony_ciextern bool ata_phys_link_online(struct ata_link *link);
818c2ecf20Sopenharmony_ciextern bool ata_phys_link_offline(struct ata_link *link);
828c2ecf20Sopenharmony_ciextern void ata_dev_init(struct ata_device *dev);
838c2ecf20Sopenharmony_ciextern void ata_link_init(struct ata_port *ap, struct ata_link *link, int pmp);
848c2ecf20Sopenharmony_ciextern int sata_link_init_spd(struct ata_link *link);
858c2ecf20Sopenharmony_ciextern int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg);
868c2ecf20Sopenharmony_ciextern int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg);
878c2ecf20Sopenharmony_ciextern struct ata_port *ata_port_alloc(struct ata_host *host);
888c2ecf20Sopenharmony_ciextern const char *sata_spd_string(unsigned int spd);
898c2ecf20Sopenharmony_ciextern int ata_port_probe(struct ata_port *ap);
908c2ecf20Sopenharmony_ciextern void __ata_port_probe(struct ata_port *ap);
918c2ecf20Sopenharmony_ciextern unsigned int ata_read_log_page(struct ata_device *dev, u8 log,
928c2ecf20Sopenharmony_ci				      u8 page, void *buf, unsigned int sectors);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define to_ata_port(d) container_of(d, struct ata_port, tdev)
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ci/* libata-sata.c */
978c2ecf20Sopenharmony_ci#ifdef CONFIG_SATA_HOST
988c2ecf20Sopenharmony_ciint ata_sas_allocate_tag(struct ata_port *ap);
998c2ecf20Sopenharmony_civoid ata_sas_free_tag(unsigned int tag, struct ata_port *ap);
1008c2ecf20Sopenharmony_ci#else
1018c2ecf20Sopenharmony_cistatic inline int ata_sas_allocate_tag(struct ata_port *ap)
1028c2ecf20Sopenharmony_ci{
1038c2ecf20Sopenharmony_ci	return -EOPNOTSUPP;
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_cistatic inline void ata_sas_free_tag(unsigned int tag, struct ata_port *ap) { }
1068c2ecf20Sopenharmony_ci#endif
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/* libata-acpi.c */
1098c2ecf20Sopenharmony_ci#ifdef CONFIG_ATA_ACPI
1108c2ecf20Sopenharmony_ciextern unsigned int ata_acpi_gtf_filter;
1118c2ecf20Sopenharmony_ciextern void ata_acpi_dissociate(struct ata_host *host);
1128c2ecf20Sopenharmony_ciextern int ata_acpi_on_suspend(struct ata_port *ap);
1138c2ecf20Sopenharmony_ciextern void ata_acpi_on_resume(struct ata_port *ap);
1148c2ecf20Sopenharmony_ciextern int ata_acpi_on_devcfg(struct ata_device *dev);
1158c2ecf20Sopenharmony_ciextern void ata_acpi_on_disable(struct ata_device *dev);
1168c2ecf20Sopenharmony_ciextern void ata_acpi_set_state(struct ata_port *ap, pm_message_t state);
1178c2ecf20Sopenharmony_ciextern void ata_acpi_bind_port(struct ata_port *ap);
1188c2ecf20Sopenharmony_ciextern void ata_acpi_bind_dev(struct ata_device *dev);
1198c2ecf20Sopenharmony_ciextern acpi_handle ata_dev_acpi_handle(struct ata_device *dev);
1208c2ecf20Sopenharmony_ci#else
1218c2ecf20Sopenharmony_cistatic inline void ata_acpi_dissociate(struct ata_host *host) { }
1228c2ecf20Sopenharmony_cistatic inline int ata_acpi_on_suspend(struct ata_port *ap) { return 0; }
1238c2ecf20Sopenharmony_cistatic inline void ata_acpi_on_resume(struct ata_port *ap) { }
1248c2ecf20Sopenharmony_cistatic inline int ata_acpi_on_devcfg(struct ata_device *dev) { return 0; }
1258c2ecf20Sopenharmony_cistatic inline void ata_acpi_on_disable(struct ata_device *dev) { }
1268c2ecf20Sopenharmony_cistatic inline void ata_acpi_set_state(struct ata_port *ap,
1278c2ecf20Sopenharmony_ci				      pm_message_t state) { }
1288c2ecf20Sopenharmony_cistatic inline void ata_acpi_bind_port(struct ata_port *ap) {}
1298c2ecf20Sopenharmony_cistatic inline void ata_acpi_bind_dev(struct ata_device *dev) {}
1308c2ecf20Sopenharmony_ci#endif
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_ci/* libata-scsi.c */
1338c2ecf20Sopenharmony_ciextern struct ata_device *ata_scsi_find_dev(struct ata_port *ap,
1348c2ecf20Sopenharmony_ci					    const struct scsi_device *scsidev);
1358c2ecf20Sopenharmony_ciextern int ata_scsi_add_hosts(struct ata_host *host,
1368c2ecf20Sopenharmony_ci			      struct scsi_host_template *sht);
1378c2ecf20Sopenharmony_ciextern void ata_scsi_scan_host(struct ata_port *ap, int sync);
1388c2ecf20Sopenharmony_ciextern int ata_scsi_offline_dev(struct ata_device *dev);
1398c2ecf20Sopenharmony_ciextern void ata_scsi_set_sense(struct ata_device *dev,
1408c2ecf20Sopenharmony_ci			       struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq);
1418c2ecf20Sopenharmony_ciextern void ata_scsi_set_sense_information(struct ata_device *dev,
1428c2ecf20Sopenharmony_ci					   struct scsi_cmnd *cmd,
1438c2ecf20Sopenharmony_ci					   const struct ata_taskfile *tf);
1448c2ecf20Sopenharmony_ciextern void ata_scsi_media_change_notify(struct ata_device *dev);
1458c2ecf20Sopenharmony_ciextern void ata_scsi_hotplug(struct work_struct *work);
1468c2ecf20Sopenharmony_ciextern void ata_schedule_scsi_eh(struct Scsi_Host *shost);
1478c2ecf20Sopenharmony_ciextern void ata_scsi_dev_rescan(struct work_struct *work);
1488c2ecf20Sopenharmony_ciextern int ata_bus_probe(struct ata_port *ap);
1498c2ecf20Sopenharmony_ciextern int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel,
1508c2ecf20Sopenharmony_ci			      unsigned int id, u64 lun);
1518c2ecf20Sopenharmony_civoid ata_scsi_sdev_config(struct scsi_device *sdev);
1528c2ecf20Sopenharmony_ciint ata_scsi_dev_config(struct scsi_device *sdev, struct ata_device *dev);
1538c2ecf20Sopenharmony_civoid ata_scsi_dump_cdb(struct ata_port *ap, struct scsi_cmnd *cmd);
1548c2ecf20Sopenharmony_ciint __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* libata-eh.c */
1578c2ecf20Sopenharmony_ciextern unsigned long ata_internal_cmd_timeout(struct ata_device *dev, u8 cmd);
1588c2ecf20Sopenharmony_ciextern void ata_internal_cmd_timed_out(struct ata_device *dev, u8 cmd);
1598c2ecf20Sopenharmony_ciextern void ata_eh_acquire(struct ata_port *ap);
1608c2ecf20Sopenharmony_ciextern void ata_eh_release(struct ata_port *ap);
1618c2ecf20Sopenharmony_ciextern void ata_scsi_error(struct Scsi_Host *host);
1628c2ecf20Sopenharmony_ciextern void ata_eh_fastdrain_timerfn(struct timer_list *t);
1638c2ecf20Sopenharmony_ciextern void ata_qc_schedule_eh(struct ata_queued_cmd *qc);
1648c2ecf20Sopenharmony_ciextern void ata_dev_disable(struct ata_device *dev);
1658c2ecf20Sopenharmony_ciextern void ata_eh_detach_dev(struct ata_device *dev);
1668c2ecf20Sopenharmony_ciextern void ata_eh_about_to_do(struct ata_link *link, struct ata_device *dev,
1678c2ecf20Sopenharmony_ci			       unsigned int action);
1688c2ecf20Sopenharmony_ciextern void ata_eh_done(struct ata_link *link, struct ata_device *dev,
1698c2ecf20Sopenharmony_ci			unsigned int action);
1708c2ecf20Sopenharmony_ciextern void ata_eh_autopsy(struct ata_port *ap);
1718c2ecf20Sopenharmony_ciconst char *ata_get_cmd_descript(u8 command);
1728c2ecf20Sopenharmony_ciextern void ata_eh_report(struct ata_port *ap);
1738c2ecf20Sopenharmony_ciextern int ata_eh_reset(struct ata_link *link, int classify,
1748c2ecf20Sopenharmony_ci			ata_prereset_fn_t prereset, ata_reset_fn_t softreset,
1758c2ecf20Sopenharmony_ci			ata_reset_fn_t hardreset, ata_postreset_fn_t postreset);
1768c2ecf20Sopenharmony_ciextern int ata_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
1778c2ecf20Sopenharmony_ciextern int ata_eh_recover(struct ata_port *ap, ata_prereset_fn_t prereset,
1788c2ecf20Sopenharmony_ci			  ata_reset_fn_t softreset, ata_reset_fn_t hardreset,
1798c2ecf20Sopenharmony_ci			  ata_postreset_fn_t postreset,
1808c2ecf20Sopenharmony_ci			  struct ata_link **r_failed_disk);
1818c2ecf20Sopenharmony_ciextern void ata_eh_finish(struct ata_port *ap);
1828c2ecf20Sopenharmony_ciextern int ata_ering_map(struct ata_ering *ering,
1838c2ecf20Sopenharmony_ci			 int (*map_fn)(struct ata_ering_entry *, void *),
1848c2ecf20Sopenharmony_ci		  	 void *arg);
1858c2ecf20Sopenharmony_ciextern unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key);
1868c2ecf20Sopenharmony_ciextern unsigned int atapi_eh_request_sense(struct ata_device *dev,
1878c2ecf20Sopenharmony_ci					   u8 *sense_buf, u8 dfl_sense_key);
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci/* libata-pmp.c */
1908c2ecf20Sopenharmony_ci#ifdef CONFIG_SATA_PMP
1918c2ecf20Sopenharmony_ciextern int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val);
1928c2ecf20Sopenharmony_ciextern int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val);
1938c2ecf20Sopenharmony_ciextern int sata_pmp_set_lpm(struct ata_link *link, enum ata_lpm_policy policy,
1948c2ecf20Sopenharmony_ci			    unsigned hints);
1958c2ecf20Sopenharmony_ciextern int sata_pmp_attach(struct ata_device *dev);
1968c2ecf20Sopenharmony_ci#else /* CONFIG_SATA_PMP */
1978c2ecf20Sopenharmony_cistatic inline int sata_pmp_scr_read(struct ata_link *link, int reg, u32 *val)
1988c2ecf20Sopenharmony_ci{
1998c2ecf20Sopenharmony_ci	return -EINVAL;
2008c2ecf20Sopenharmony_ci}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistatic inline int sata_pmp_scr_write(struct ata_link *link, int reg, u32 val)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	return -EINVAL;
2058c2ecf20Sopenharmony_ci}
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_cistatic inline int sata_pmp_set_lpm(struct ata_link *link,
2088c2ecf20Sopenharmony_ci				   enum ata_lpm_policy policy, unsigned hints)
2098c2ecf20Sopenharmony_ci{
2108c2ecf20Sopenharmony_ci	return -EINVAL;
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cistatic inline int sata_pmp_attach(struct ata_device *dev)
2148c2ecf20Sopenharmony_ci{
2158c2ecf20Sopenharmony_ci	return -EINVAL;
2168c2ecf20Sopenharmony_ci}
2178c2ecf20Sopenharmony_ci#endif /* CONFIG_SATA_PMP */
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci/* libata-sff.c */
2208c2ecf20Sopenharmony_ci#ifdef CONFIG_ATA_SFF
2218c2ecf20Sopenharmony_ciextern void ata_sff_flush_pio_task(struct ata_port *ap);
2228c2ecf20Sopenharmony_ciextern void ata_sff_port_init(struct ata_port *ap);
2238c2ecf20Sopenharmony_ciextern int ata_sff_init(void);
2248c2ecf20Sopenharmony_ciextern void ata_sff_exit(void);
2258c2ecf20Sopenharmony_ci#else /* CONFIG_ATA_SFF */
2268c2ecf20Sopenharmony_cistatic inline void ata_sff_flush_pio_task(struct ata_port *ap)
2278c2ecf20Sopenharmony_ci{ }
2288c2ecf20Sopenharmony_cistatic inline void ata_sff_port_init(struct ata_port *ap)
2298c2ecf20Sopenharmony_ci{ }
2308c2ecf20Sopenharmony_cistatic inline int ata_sff_init(void)
2318c2ecf20Sopenharmony_ci{ return 0; }
2328c2ecf20Sopenharmony_cistatic inline void ata_sff_exit(void)
2338c2ecf20Sopenharmony_ci{ }
2348c2ecf20Sopenharmony_ci#endif /* CONFIG_ATA_SFF */
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci/* libata-zpodd.c */
2378c2ecf20Sopenharmony_ci#ifdef CONFIG_SATA_ZPODD
2388c2ecf20Sopenharmony_civoid zpodd_init(struct ata_device *dev);
2398c2ecf20Sopenharmony_civoid zpodd_exit(struct ata_device *dev);
2408c2ecf20Sopenharmony_cistatic inline bool zpodd_dev_enabled(struct ata_device *dev)
2418c2ecf20Sopenharmony_ci{
2428c2ecf20Sopenharmony_ci	return dev->zpodd != NULL;
2438c2ecf20Sopenharmony_ci}
2448c2ecf20Sopenharmony_civoid zpodd_on_suspend(struct ata_device *dev);
2458c2ecf20Sopenharmony_cibool zpodd_zpready(struct ata_device *dev);
2468c2ecf20Sopenharmony_civoid zpodd_enable_run_wake(struct ata_device *dev);
2478c2ecf20Sopenharmony_civoid zpodd_disable_run_wake(struct ata_device *dev);
2488c2ecf20Sopenharmony_civoid zpodd_post_poweron(struct ata_device *dev);
2498c2ecf20Sopenharmony_ci#else /* CONFIG_SATA_ZPODD */
2508c2ecf20Sopenharmony_cistatic inline void zpodd_init(struct ata_device *dev) {}
2518c2ecf20Sopenharmony_cistatic inline void zpodd_exit(struct ata_device *dev) {}
2528c2ecf20Sopenharmony_cistatic inline bool zpodd_dev_enabled(struct ata_device *dev) { return false; }
2538c2ecf20Sopenharmony_cistatic inline void zpodd_on_suspend(struct ata_device *dev) {}
2548c2ecf20Sopenharmony_cistatic inline bool zpodd_zpready(struct ata_device *dev) { return false; }
2558c2ecf20Sopenharmony_cistatic inline void zpodd_enable_run_wake(struct ata_device *dev) {}
2568c2ecf20Sopenharmony_cistatic inline void zpodd_disable_run_wake(struct ata_device *dev) {}
2578c2ecf20Sopenharmony_cistatic inline void zpodd_post_poweron(struct ata_device *dev) {}
2588c2ecf20Sopenharmony_ci#endif /* CONFIG_SATA_ZPODD */
2598c2ecf20Sopenharmony_ci
2608c2ecf20Sopenharmony_ci#endif /* __LIBATA_H__ */
261