// SPDX-License-Identifier: GPL-2.0-or-later /* * libata-scsi.c - helper library for ATA * * Copyright 2003-2004 Red Hat, Inc. All rights reserved. * Copyright 2003-2004 Jeff Garzik * * libata documentation is available via 'make {ps|pdf}docs', * as Documentation/driver-api/libata.rst * * Hardware documentation available from * - http://www.t10.org/ * - http://www.t13.org/ */ #include <linux/compat.h> #include <linux/slab.h> #include <linux/kernel.h> #include <linux/blkdev.h> #include <linux/spinlock.h> #include <linux/export.h> #include <scsi/scsi.h> #include <scsi/scsi_host.h> #include <scsi/scsi_cmnd.h> #include <scsi/scsi_eh.h> #include <scsi/scsi_device.h> #include <scsi/scsi_tcq.h> #include <scsi/scsi_transport.h> #include <linux/libata.h> #include <linux/hdreg.h> #include <linux/uaccess.h> #include <linux/suspend.h> #include <asm/unaligned.h> #include <linux/ioprio.h> #include <linux/of.h> #include "libata.h" #include "libata-transport.h" #define ATA_SCSI_RBUF_SIZE … static DEFINE_SPINLOCK(ata_scsi_rbuf_lock); static u8 ata_scsi_rbuf[ATA_SCSI_RBUF_SIZE]; ata_xlat_func_t; static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev); #define RW_RECOVERY_MPAGE … #define RW_RECOVERY_MPAGE_LEN … #define CACHE_MPAGE … #define CACHE_MPAGE_LEN … #define CONTROL_MPAGE … #define CONTROL_MPAGE_LEN … #define ALL_MPAGES … #define ALL_SUB_MPAGES … #define CDL_T2A_SUB_MPAGE … #define CDL_T2B_SUB_MPAGE … #define CDL_T2_SUB_MPAGE_LEN … #define ATA_FEATURE_SUB_MPAGE … #define ATA_FEATURE_SUB_MPAGE_LEN … static const u8 def_rw_recovery_mpage[RW_RECOVERY_MPAGE_LEN] = …; static const u8 def_cache_mpage[CACHE_MPAGE_LEN] = …; static const u8 def_control_mpage[CONTROL_MPAGE_LEN] = …; static ssize_t ata_scsi_park_show(struct device *device, struct device_attribute *attr, char *buf) { … } static ssize_t ata_scsi_park_store(struct device *device, struct device_attribute *attr, const char *buf, size_t len) { … } DEVICE_ATTR(…); EXPORT_SYMBOL_GPL(…); bool ata_scsi_sense_is_valid(u8 sk, u8 asc, u8 ascq) { … } void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd, u8 sk, u8 asc, u8 ascq) { … } void ata_scsi_set_sense_information(struct ata_device *dev, struct scsi_cmnd *cmd, const struct ata_taskfile *tf) { … } /** * ata_scsi_set_passthru_sense_fields - Set ATA fields in sense buffer * @qc: ATA PASS-THROUGH command. * * Populates "ATA Status Return sense data descriptor" / "Fixed format * sense data" with ATA taskfile fields. * * LOCKING: * None. */ static void ata_scsi_set_passthru_sense_fields(struct ata_queued_cmd *qc) { … } static void ata_scsi_set_invalid_field(struct ata_device *dev, struct scsi_cmnd *cmd, u16 field, u8 bit) { … } static void ata_scsi_set_invalid_parameter(struct ata_device *dev, struct scsi_cmnd *cmd, u16 field) { … } static struct attribute *ata_common_sdev_attrs[] = …; static const struct attribute_group ata_common_sdev_attr_group = …; const struct attribute_group *ata_common_sdev_groups[] = …; EXPORT_SYMBOL_GPL(…); /** * ata_std_bios_param - generic bios head/sector/cylinder calculator used by sd. * @sdev: SCSI device for which BIOS geometry is to be determined * @bdev: block device associated with @sdev * @capacity: capacity of SCSI device * @geom: location to which geometry will be output * * Generic bios head/sector/cylinder calculator * used by sd. Most BIOSes nowadays expect a XXX/255/16 (CHS) * mapping. Some situations may arise where the disk is not * bootable if this is not used. * * LOCKING: * Defined by the SCSI layer. We don't really care. * * RETURNS: * Zero. */ int ata_std_bios_param(struct scsi_device *sdev, struct block_device *bdev, sector_t capacity, int geom[]) { … } EXPORT_SYMBOL_GPL(…); /** * ata_scsi_unlock_native_capacity - unlock native capacity * @sdev: SCSI device to adjust device capacity for * * This function is called if a partition on @sdev extends beyond * the end of the device. It requests EH to unlock HPA. * * LOCKING: * Defined by the SCSI layer. Might sleep. */ void ata_scsi_unlock_native_capacity(struct scsi_device *sdev) { … } EXPORT_SYMBOL_GPL(…); /** * ata_get_identity - Handler for HDIO_GET_IDENTITY ioctl * @ap: target port * @sdev: SCSI device to get identify data for * @arg: User buffer area for identify data * * LOCKING: * Defined by the SCSI layer. We don't really care. * * RETURNS: * Zero on success, negative errno on error. */ static int ata_get_identity(struct ata_port *ap, struct scsi_device *sdev, void __user *arg) { … } /** * ata_cmd_ioctl - Handler for HDIO_DRIVE_CMD ioctl * @scsidev: Device to which we are issuing command * @arg: User provided data for issuing command * * LOCKING: * Defined by the SCSI layer. We don't really care. * * RETURNS: * Zero on success, negative errno on error. */ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) { … } /** * ata_task_ioctl - Handler for HDIO_DRIVE_TASK ioctl * @scsidev: Device to which we are issuing command * @arg: User provided data for issuing command * * LOCKING: * Defined by the SCSI layer. We don't really care. * * RETURNS: * Zero on success, negative errno on error. */ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) { … } static bool ata_ioc32(struct ata_port *ap) { … } /* * This handles both native and compat commands, so anything added * here must have a compatible argument, or check in_compat_syscall() */ int ata_sas_scsi_ioctl(struct ata_port *ap, struct scsi_device *scsidev, unsigned int cmd, void __user *arg) { … } EXPORT_SYMBOL_GPL(…); int ata_scsi_ioctl(struct scsi_device *scsidev, unsigned int cmd, void __user *arg) { … } EXPORT_SYMBOL_GPL(…); /** * ata_scsi_qc_new - acquire new ata_queued_cmd reference * @dev: ATA device to which the new command is attached * @cmd: SCSI command that originated this ATA command * * Obtain a reference to an unused ata_queued_cmd structure, * which is the basic libata structure representing a single * ATA command sent to the hardware. * * If a command was available, fill in the SCSI-specific * portions of the structure with information on the * current command. * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * Command allocated, or %NULL if none available. */ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, struct scsi_cmnd *cmd) { … } static void ata_qc_set_pc_nbytes(struct ata_queued_cmd *qc) { … } /** * ata_to_sense_error - convert ATA error to SCSI error * @drv_stat: value contained in ATA status register * @drv_err: value contained in ATA error register * @sk: the sense key we'll fill out * @asc: the additional sense code we'll fill out * @ascq: the additional sense code qualifier we'll fill out * * Converts an ATA error into a SCSI error. Fill out pointers to * SK, ASC, and ASCQ bytes for later use in fixed or descriptor * format sense blocks. * * LOCKING: * spin_lock_irqsave(host lock) */ static void ata_to_sense_error(u8 drv_stat, u8 drv_err, u8 *sk, u8 *asc, u8 *ascq) { … } /* * ata_gen_passthru_sense - Generate check condition sense block. * @qc: Command that completed. * * This function is specific to the ATA pass through commands. * Regardless of whether the command errored or not, return a sense * block. If there was no error, we get the request from an ATA * passthrough command, so we use the following sense data: * sk = RECOVERED ERROR * asc,ascq = ATA PASS-THROUGH INFORMATION AVAILABLE * * * LOCKING: * None. */ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) { … } /** * ata_gen_ata_sense - generate a SCSI fixed sense block * @qc: Command that we are erroring out * * Generate sense block for a failed ATA command @qc. Descriptor * format is used to accommodate LBA48 block address. * * LOCKING: * None. */ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) { … } void ata_scsi_sdev_config(struct scsi_device *sdev) { … } /** * ata_scsi_dma_need_drain - Check whether data transfer may overflow * @rq: request to be checked * * ATAPI commands which transfer variable length data to host * might overflow due to application error or hardware bug. This * function checks whether overflow should be drained and ignored * for @request. * * LOCKING: * None. * * RETURNS: * 1 if ; otherwise, 0. */ bool ata_scsi_dma_need_drain(struct request *rq) { … } EXPORT_SYMBOL_GPL(…); int ata_scsi_dev_config(struct scsi_device *sdev, struct queue_limits *lim, struct ata_device *dev) { … } /** * ata_scsi_slave_alloc - Early setup of SCSI device * @sdev: SCSI device to examine * * This is called from scsi_alloc_sdev() when the scsi device * associated with an ATA device is scanned on a port. * * LOCKING: * Defined by SCSI layer. We don't really care. */ int ata_scsi_slave_alloc(struct scsi_device *sdev) { … } EXPORT_SYMBOL_GPL(…); /** * ata_scsi_device_configure - Set SCSI device attributes * @sdev: SCSI device to examine * @lim: queue limits * * This is called before we actually start reading * and writing to the device, to configure certain * SCSI mid-layer behaviors. * * LOCKING: * Defined by SCSI layer. We don't really care. */ int ata_scsi_device_configure(struct scsi_device *sdev, struct queue_limits *lim) { … } EXPORT_SYMBOL_GPL(…); /** * ata_scsi_slave_destroy - SCSI device is about to be destroyed * @sdev: SCSI device to be destroyed * * @sdev is about to be destroyed for hot/warm unplugging. If * this unplugging was initiated by libata as indicated by NULL * dev->sdev, this function doesn't have to do anything. * Otherwise, SCSI layer initiated warm-unplug is in progress. * Clear dev->sdev, schedule the device for ATA detach and invoke * EH. * * LOCKING: * Defined by SCSI layer. We don't really care. */ void ata_scsi_slave_destroy(struct scsi_device *sdev) { … } EXPORT_SYMBOL_GPL(…); /** * ata_scsi_start_stop_xlat - Translate SCSI START STOP UNIT command * @qc: Storage for translated ATA taskfile * * Sets up an ATA taskfile to issue STANDBY (to stop) or READ VERIFY * (to start). Perhaps these commands should be preceded by * CHECK POWER MODE to see what power mode the device is already in. * [See SAT revision 5 at www.t10.org] * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * Zero on success, non-zero on error. */ static unsigned int ata_scsi_start_stop_xlat(struct ata_queued_cmd *qc) { … } /** * ata_scsi_flush_xlat - Translate SCSI SYNCHRONIZE CACHE command * @qc: Storage for translated ATA taskfile * * Sets up an ATA taskfile to issue FLUSH CACHE or * FLUSH CACHE EXT. * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * Zero on success, non-zero on error. */ static unsigned int ata_scsi_flush_xlat(struct ata_queued_cmd *qc) { … } /** * scsi_6_lba_len - Get LBA and transfer length * @cdb: SCSI command to translate * * Calculate LBA and transfer length for 6-byte commands. * * RETURNS: * @plba: the LBA * @plen: the transfer length */ static void scsi_6_lba_len(const u8 *cdb, u64 *plba, u32 *plen) { … } /** * scsi_10_lba_len - Get LBA and transfer length * @cdb: SCSI command to translate * * Calculate LBA and transfer length for 10-byte commands. * * RETURNS: * @plba: the LBA * @plen: the transfer length */ static inline void scsi_10_lba_len(const u8 *cdb, u64 *plba, u32 *plen) { … } /** * scsi_16_lba_len - Get LBA and transfer length * @cdb: SCSI command to translate * * Calculate LBA and transfer length for 16-byte commands. * * RETURNS: * @plba: the LBA * @plen: the transfer length */ static inline void scsi_16_lba_len(const u8 *cdb, u64 *plba, u32 *plen) { … } /** * scsi_dld - Get duration limit descriptor index * @cdb: SCSI command to translate * * Returns the dld bits indicating the index of a command duration limit * descriptor. */ static inline int scsi_dld(const u8 *cdb) { … } /** * ata_scsi_verify_xlat - Translate SCSI VERIFY command into an ATA one * @qc: Storage for translated ATA taskfile * * Converts SCSI VERIFY command to an ATA READ VERIFY command. * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * Zero on success, non-zero on error. */ static unsigned int ata_scsi_verify_xlat(struct ata_queued_cmd *qc) { … } static bool ata_check_nblocks(struct scsi_cmnd *scmd, u32 n_blocks) { … } /** * ata_scsi_rw_xlat - Translate SCSI r/w command into an ATA one * @qc: Storage for translated ATA taskfile * * Converts any of six SCSI read/write commands into the * ATA counterpart, including starting sector (LBA), * sector count, and taking into account the device's LBA48 * support. * * Commands %READ_6, %READ_10, %READ_16, %WRITE_6, %WRITE_10, and * %WRITE_16 are currently supported. * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * Zero on success, non-zero on error. */ static unsigned int ata_scsi_rw_xlat(struct ata_queued_cmd *qc) { … } static void ata_qc_done(struct ata_queued_cmd *qc) { … } static void ata_scsi_qc_complete(struct ata_queued_cmd *qc) { … } /** * ata_scsi_translate - Translate then issue SCSI command to ATA device * @dev: ATA device to which the command is addressed * @cmd: SCSI command to execute * @xlat_func: Actor which translates @cmd to an ATA taskfile * * Our ->queuecommand() function has decided that the SCSI * command issued can be directly translated into an ATA * command, rather than handled internally. * * This function sets up an ata_queued_cmd structure for the * SCSI command, and sends that ata_queued_cmd to the hardware. * * The xlat_func argument (actor) returns 0 if ready to execute * ATA command, else 1 to finish translation. If 1 is returned * then cmd->result (and possibly cmd->sense_buffer) are assumed * to be set reflecting an error condition or clean (early) * termination. * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * 0 on success, SCSI_ML_QUEUE_DEVICE_BUSY if the command * needs to be deferred. */ static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd, ata_xlat_func_t xlat_func) { … } struct ata_scsi_args { … }; /** * ata_scsi_rbuf_fill - wrapper for SCSI command simulators * @args: device IDENTIFY data / SCSI command of interest. * @actor: Callback hook for desired SCSI command simulator * * Takes care of the hard work of simulating a SCSI command... * Mapping the response buffer, calling the command's handler, * and handling the handler's return value. This return value * indicates whether the handler wishes the SCSI command to be * completed successfully (0), or not (in which case cmd->result * and sense buffer are assumed to be set). * * LOCKING: * spin_lock_irqsave(host lock) */ static void ata_scsi_rbuf_fill(struct ata_scsi_args *args, unsigned int (*actor)(struct ata_scsi_args *args, u8 *rbuf)) { … } /** * ata_scsiop_inq_std - Simulate INQUIRY command * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Returns standard device identification data associated * with non-VPD INQUIRY command output. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_inq_std(struct ata_scsi_args *args, u8 *rbuf) { … } /** * ata_scsiop_inq_00 - Simulate INQUIRY VPD page 0, list of pages * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Returns list of inquiry VPD pages available. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_inq_00(struct ata_scsi_args *args, u8 *rbuf) { … } /** * ata_scsiop_inq_80 - Simulate INQUIRY VPD page 80, device serial number * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Returns ATA device serial number. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_inq_80(struct ata_scsi_args *args, u8 *rbuf) { … } /** * ata_scsiop_inq_83 - Simulate INQUIRY VPD page 83, device identity * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Yields two logical unit device identification designators: * - vendor specific ASCII containing the ATA serial number * - SAT defined "t10 vendor id based" containing ASCII vendor * name ("ATA "), model and serial numbers. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_inq_83(struct ata_scsi_args *args, u8 *rbuf) { … } /** * ata_scsiop_inq_89 - Simulate INQUIRY VPD page 89, ATA info * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Yields SAT-specified ATA VPD page. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf) { … } static unsigned int ata_scsiop_inq_b0(struct ata_scsi_args *args, u8 *rbuf) { … } static unsigned int ata_scsiop_inq_b1(struct ata_scsi_args *args, u8 *rbuf) { … } static unsigned int ata_scsiop_inq_b2(struct ata_scsi_args *args, u8 *rbuf) { … } static unsigned int ata_scsiop_inq_b6(struct ata_scsi_args *args, u8 *rbuf) { … } static unsigned int ata_scsiop_inq_b9(struct ata_scsi_args *args, u8 *rbuf) { … } /** * modecpy - Prepare response for MODE SENSE * @dest: output buffer * @src: data being copied * @n: length of mode page * @changeable: whether changeable parameters are requested * * Generate a generic MODE SENSE page for either current or changeable * parameters. * * LOCKING: * None. */ static void modecpy(u8 *dest, const u8 *src, int n, bool changeable) { … } /** * ata_msense_caching - Simulate MODE SENSE caching info page * @id: device IDENTIFY data * @buf: output buffer * @changeable: whether changeable parameters are requested * * Generate a caching info page, which conditionally indicates * write caching to the SCSI layer, depending on device * capabilities. * * LOCKING: * None. */ static unsigned int ata_msense_caching(u16 *id, u8 *buf, bool changeable) { … } /* * Simulate MODE SENSE control mode page, sub-page 0. */ static unsigned int ata_msense_control_spg0(struct ata_device *dev, u8 *buf, bool changeable) { … } /* * Translate an ATA duration limit in microseconds to a SCSI duration limit * using the t2cdlunits 0xa (10ms). Since the SCSI duration limits are 2-bytes * only, take care of overflows. */ static inline u16 ata_xlat_cdl_limit(u8 *buf) { … } /* * Simulate MODE SENSE control mode page, sub-pages 07h and 08h * (command duration limits T2A and T2B mode pages). */ static unsigned int ata_msense_control_spgt2(struct ata_device *dev, u8 *buf, u8 spg) { … } /* * Simulate MODE SENSE control mode page, sub-page f2h * (ATA feature control mode page). */ static unsigned int ata_msense_control_ata_feature(struct ata_device *dev, u8 *buf) { … } /** * ata_msense_control - Simulate MODE SENSE control mode page * @dev: ATA device of interest * @buf: output buffer * @spg: sub-page code * @changeable: whether changeable parameters are requested * * Generate a generic MODE SENSE control mode page. * * LOCKING: * None. */ static unsigned int ata_msense_control(struct ata_device *dev, u8 *buf, u8 spg, bool changeable) { … } /** * ata_msense_rw_recovery - Simulate MODE SENSE r/w error recovery page * @buf: output buffer * @changeable: whether changeable parameters are requested * * Generate a generic MODE SENSE r/w error recovery page. * * LOCKING: * None. */ static unsigned int ata_msense_rw_recovery(u8 *buf, bool changeable) { … } /** * ata_scsiop_mode_sense - Simulate MODE SENSE 6, 10 commands * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Simulate MODE SENSE commands. Assume this is invoked for direct * access devices (e.g. disks) only. There should be no block * descriptor for other device types. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_mode_sense(struct ata_scsi_args *args, u8 *rbuf) { … } /** * ata_scsiop_read_cap - Simulate READ CAPACITY[ 16] commands * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Simulate READ CAPACITY commands. * * LOCKING: * None. */ static unsigned int ata_scsiop_read_cap(struct ata_scsi_args *args, u8 *rbuf) { … } /** * ata_scsiop_report_luns - Simulate REPORT LUNS command * @args: device IDENTIFY data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Simulate REPORT LUNS command. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_report_luns(struct ata_scsi_args *args, u8 *rbuf) { … } /* * ATAPI devices typically report zero for their SCSI version, and sometimes * deviate from the spec WRT response data format. If SCSI version is * reported as zero like normal, then we make the following fixups: * 1) Fake MMC-5 version, to indicate to the Linux scsi midlayer this is a * modern device. * 2) Ensure response data format / ATAPI information are always correct. */ static void atapi_fixup_inquiry(struct scsi_cmnd *cmd) { … } static void atapi_qc_complete(struct ata_queued_cmd *qc) { … } /** * atapi_xlat - Initialize PACKET taskfile * @qc: command structure to be initialized * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * Zero on success, non-zero on failure. */ static unsigned int atapi_xlat(struct ata_queued_cmd *qc) { … } static struct ata_device *ata_find_dev(struct ata_port *ap, unsigned int devno) { … } static struct ata_device *__ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev) { … } /** * ata_scsi_find_dev - lookup ata_device from scsi_cmnd * @ap: ATA port to which the device is attached * @scsidev: SCSI device from which we derive the ATA device * * Given various information provided in struct scsi_cmnd, * map that onto an ATA bus, and using that mapping * determine which ata_device is associated with the * SCSI command to be sent. * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * Associated ATA device, or %NULL if not found. */ struct ata_device * ata_scsi_find_dev(struct ata_port *ap, const struct scsi_device *scsidev) { … } /* * ata_scsi_map_proto - Map pass-thru protocol value to taskfile value. * @byte1: Byte 1 from pass-thru CDB. * * RETURNS: * ATA_PROT_UNKNOWN if mapping failed/unimplemented, protocol otherwise. */ static u8 ata_scsi_map_proto(u8 byte1) { … } /** * ata_scsi_pass_thru - convert ATA pass-thru CDB to taskfile * @qc: command structure to be initialized * * Handles either 12, 16, or 32-byte versions of the CDB. * * RETURNS: * Zero on success, non-zero on failure. */ static unsigned int ata_scsi_pass_thru(struct ata_queued_cmd *qc) { … } /** * ata_format_dsm_trim_descr() - SATL Write Same to DSM Trim * @cmd: SCSI command being translated * @trmax: Maximum number of entries that will fit in sector_size bytes. * @sector: Starting sector * @count: Total Range of request in logical sectors * * Rewrite the WRITE SAME descriptor to be a DSM TRIM little-endian formatted * descriptor. * * Upto 64 entries of the format: * 63:48 Range Length * 47:0 LBA * * Range Length of 0 is ignored. * LBA's should be sorted order and not overlap. * * NOTE: this is the same format as ADD LBA(S) TO NV CACHE PINNED SET * * Return: Number of bytes copied into sglist. */ static size_t ata_format_dsm_trim_descr(struct scsi_cmnd *cmd, u32 trmax, u64 sector, u32 count) { … } /** * ata_scsi_write_same_xlat() - SATL Write Same to ATA SCT Write Same * @qc: Command to be translated * * Translate a SCSI WRITE SAME command to be either a DSM TRIM command or * an SCT Write Same command. * Based on WRITE SAME has the UNMAP flag: * * - When set translate to DSM TRIM * - When clear translate to SCT Write Same */ static unsigned int ata_scsi_write_same_xlat(struct ata_queued_cmd *qc) { … } /** * ata_scsiop_maint_in - Simulate a subset of MAINTENANCE_IN * @args: device MAINTENANCE_IN data / SCSI command of interest. * @rbuf: Response buffer, to which simulated SCSI cmd output is sent. * * Yields a subset to satisfy scsi_report_opcode() * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsiop_maint_in(struct ata_scsi_args *args, u8 *rbuf) { … } /** * ata_scsi_report_zones_complete - convert ATA output * @qc: command structure returning the data * * Convert T-13 little-endian field representation into * T-10 big-endian field representation. * What a mess. */ static void ata_scsi_report_zones_complete(struct ata_queued_cmd *qc) { … } static unsigned int ata_scsi_zbc_in_xlat(struct ata_queued_cmd *qc) { … } static unsigned int ata_scsi_zbc_out_xlat(struct ata_queued_cmd *qc) { … } /** * ata_mselect_caching - Simulate MODE SELECT for caching info page * @qc: Storage for translated ATA taskfile * @buf: input buffer * @len: number of valid bytes in the input buffer * @fp: out parameter for the failed field on error * * Prepare a taskfile to modify caching information for the device. * * LOCKING: * None. */ static int ata_mselect_caching(struct ata_queued_cmd *qc, const u8 *buf, int len, u16 *fp) { … } /* * Simulate MODE SELECT control mode page, sub-page 0. */ static int ata_mselect_control_spg0(struct ata_queued_cmd *qc, const u8 *buf, int len, u16 *fp) { … } /* * Translate MODE SELECT control mode page, sub-pages f2h (ATA feature mode * page) into a SET FEATURES command. */ static unsigned int ata_mselect_control_ata_feature(struct ata_queued_cmd *qc, const u8 *buf, int len, u16 *fp) { … } /** * ata_mselect_control - Simulate MODE SELECT for control page * @qc: Storage for translated ATA taskfile * @spg: target sub-page of the control page * @buf: input buffer * @len: number of valid bytes in the input buffer * @fp: out parameter for the failed field on error * * Prepare a taskfile to modify caching information for the device. * * LOCKING: * None. */ static int ata_mselect_control(struct ata_queued_cmd *qc, u8 spg, const u8 *buf, int len, u16 *fp) { … } /** * ata_scsi_mode_select_xlat - Simulate MODE SELECT 6, 10 commands * @qc: Storage for translated ATA taskfile * * Converts a MODE SELECT command to an ATA SET FEATURES taskfile. * Assume this is invoked for direct access devices (e.g. disks) only. * There should be no block descriptor for other device types. * * LOCKING: * spin_lock_irqsave(host lock) */ static unsigned int ata_scsi_mode_select_xlat(struct ata_queued_cmd *qc) { … } static u8 ata_scsi_trusted_op(u32 len, bool send, bool dma) { … } static unsigned int ata_scsi_security_inout_xlat(struct ata_queued_cmd *qc) { … } /** * ata_scsi_var_len_cdb_xlat - SATL variable length CDB to Handler * @qc: Command to be translated * * Translate a SCSI variable length CDB to specified commands. * It checks a service action value in CDB to call corresponding handler. * * RETURNS: * Zero on success, non-zero on failure * */ static unsigned int ata_scsi_var_len_cdb_xlat(struct ata_queued_cmd *qc) { … } /** * ata_get_xlat_func - check if SCSI to ATA translation is possible * @dev: ATA device * @cmd: SCSI command opcode to consider * * Look up the SCSI command given, and determine whether the * SCSI command is to be translated or simulated. * * RETURNS: * Pointer to translation function if possible, %NULL if not. */ static inline ata_xlat_func_t ata_get_xlat_func(struct ata_device *dev, u8 cmd) { … } int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev) { … } /** * ata_scsi_queuecmd - Issue SCSI cdb to libata-managed device * @shost: SCSI host of command to be sent * @cmd: SCSI command to be sent * * In some cases, this function translates SCSI commands into * ATA taskfiles, and queues the taskfiles to be sent to * hardware. In other cases, this function simulates a * SCSI device by evaluating and responding to certain * SCSI commands. This creates the overall effect of * ATA and ATAPI devices appearing as SCSI devices. * * LOCKING: * ATA host lock * * RETURNS: * Return value from __ata_scsi_queuecmd() if @cmd can be queued, * 0 otherwise. */ int ata_scsi_queuecmd(struct Scsi_Host *shost, struct scsi_cmnd *cmd) { … } EXPORT_SYMBOL_GPL(…); /** * ata_scsi_simulate - simulate SCSI command on ATA device * @dev: the target device * @cmd: SCSI command being sent to device. * * Interprets and directly executes a select list of SCSI commands * that can be handled internally. * * LOCKING: * spin_lock_irqsave(host lock) */ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd) { … } int ata_scsi_add_hosts(struct ata_host *host, const struct scsi_host_template *sht) { … } #ifdef CONFIG_OF static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap) { … } #else static void ata_scsi_assign_ofnode(struct ata_device *dev, struct ata_port *ap) { } #endif void ata_scsi_scan_host(struct ata_port *ap, int sync) { … } /** * ata_scsi_offline_dev - offline attached SCSI device * @dev: ATA device to offline attached SCSI device for * * This function is called from ata_eh_hotplug() and responsible * for taking the SCSI device attached to @dev offline. This * function is called with host lock which protects dev->sdev * against clearing. * * LOCKING: * spin_lock_irqsave(host lock) * * RETURNS: * 1 if attached SCSI device exists, 0 otherwise. */ int ata_scsi_offline_dev(struct ata_device *dev) { … } /** * ata_scsi_remove_dev - remove attached SCSI device * @dev: ATA device to remove attached SCSI device for * * This function is called from ata_eh_scsi_hotplug() and * responsible for removing the SCSI device attached to @dev. * * LOCKING: * Kernel thread context (may sleep). */ static void ata_scsi_remove_dev(struct ata_device *dev) { … } static void ata_scsi_handle_link_detach(struct ata_link *link) { … } /** * ata_scsi_media_change_notify - send media change event * @dev: Pointer to the disk device with media change event * * Tell the block layer to send a media change notification * event. * * LOCKING: * spin_lock_irqsave(host lock) */ void ata_scsi_media_change_notify(struct ata_device *dev) { … } /** * ata_scsi_hotplug - SCSI part of hotplug * @work: Pointer to ATA port to perform SCSI hotplug on * * Perform SCSI part of hotplug. It's executed from a separate * workqueue after EH completes. This is necessary because SCSI * hot plugging requires working EH and hot unplugging is * synchronized with hot plugging with a mutex. * * LOCKING: * Kernel thread context (may sleep). */ void ata_scsi_hotplug(struct work_struct *work) { … } /** * ata_scsi_user_scan - indication for user-initiated bus scan * @shost: SCSI host to scan * @channel: Channel to scan * @id: ID to scan * @lun: LUN to scan * * This function is called when user explicitly requests bus * scan. Set probe pending flag and invoke EH. * * LOCKING: * SCSI layer (we don't care) * * RETURNS: * Zero. */ int ata_scsi_user_scan(struct Scsi_Host *shost, unsigned int channel, unsigned int id, u64 lun) { … } /** * ata_scsi_dev_rescan - initiate scsi_rescan_device() * @work: Pointer to ATA port to perform scsi_rescan_device() * * After ATA pass thru (SAT) commands are executed successfully, * libata need to propagate the changes to SCSI layer. * * LOCKING: * Kernel thread context (may sleep). */ void ata_scsi_dev_rescan(struct work_struct *work) { … }