-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmVyyWIACgkQONu9yGCS aT6Y8A//QJPg7pguCawsJGrem3a5dvhi9scNMmfuhKZOKS73JEmt4yudB9IOUjIX 1c1aBcJo5yYMZq5L9mhXnlgkgqENxE9fI45FtMdwoKiriEQ0w9OBLlfZuKN9lwzC tyIigaGE5DD3SqL8e/04LNmMPPdolM38lJ368fYaD3T4d7LfwK0qHJFL8dSg4OFQ VaePViMFgbodjtSXoERNjVLaNtSlQDQytiWHMiQX2uf6CIIRbm+zFHn2Se1mUgh3 WGT9JfXZ+achPw6OLhSIjwL+7vowhn3eRETq4zGkkNSK+rmB6W7zjPhou4SYsmc+ FAYXvalmhQWWjlmIyZzO7GIVtgx19VuEYB8h5KLvp6DXQ0h0wCBOGgsfIT4icbgW wO0R+toWYY3Y79OLRGiMjiL9b60njJYnrm7JrheRD+BIm2jva+Tb7UxhC6QDMfH6 a8fya8iJDNZWggwpx67JUANdMO8e+2rS4ttNxW0gTZSHhyEjo1HXctKBEmmtXk4s HGNV5xUniPnzrP8rduNqePG5B6c3wqOHUwj45L4scGmeC0DzW7E8EBgkHfRcU6CG ik9z5nQeDikREfK7cp8OSFtLaEBWSIX57XwHWDTMVPDGTN8EQ6eI7vTnQH3xOhA8 VWFfwcU6avROM/ih7eJ+X4JvuDKcAGTPeD6oF3II0MLPK2m7ZmE= =p/ty -----END PGP SIGNATURE----- Merge 5.4.263 into android11-5.4-lts Changes in 5.4.263 driver core: Release all resources during unbind before updating device links RDMA/irdma: Prevent zero-length STAG registration PCI: keystone: Drop __init from ks_pcie_add_pcie_{ep,port}() afs: Make error on cell lookup failure consistent with OpenAFS drm/panel: simple: Fix Innolux G101ICE-L01 bus flags drm/panel: simple: Fix Innolux G101ICE-L01 timings ata: pata_isapnp: Add missing error check for devm_ioport_map() drm/rockchip: vop: Fix color for RGB888/BGR888 format on VOP full HID: core: store the unique system identifier in hid_device HID: fix HID device resource race between HID core and debugging support ipv4: Correct/silence an endian warning in __ip_do_redirect net: usb: ax88179_178a: fix failed operations during ax88179_reset arm/xen: fix xen_vcpu_info allocation alignment amd-xgbe: handle corner-case during sfp hotplug amd-xgbe: handle the corner-case during tx completion amd-xgbe: propagate the correct speed and duplex status net: axienet: Fix check for partial TX checksum afs: Return ENOENT if no cell DNS record can be found afs: Fix file locking on R/O volumes to operate in local mode nvmet: remove unnecessary ctrl parameter nvmet: nul-terminate the NQNs passed in the connect command MIPS: KVM: Fix a build warning about variable set but not used ext4: add a new helper to check if es must be kept ext4: factor out __es_alloc_extent() and __es_free_extent() ext4: use pre-allocated es in __es_insert_extent() ext4: use pre-allocated es in __es_remove_extent() ext4: using nofail preallocation in ext4_es_remove_extent() ext4: using nofail preallocation in ext4_es_insert_delayed_block() ext4: using nofail preallocation in ext4_es_insert_extent() ext4: fix slab-use-after-free in ext4_es_insert_extent() ext4: make sure allocate pending entry not fail arm64: cpufeature: Extract capped perfmon fields KVM: arm64: limit PMU version to PMUv3 for ARMv8.1 ACPI: resource: Skip IRQ override on ASUS ExpertBook B1402CVA bcache: replace a mistaken IS_ERR() by IS_ERR_OR_NULL() in btree_gc_coalesce() s390/dasd: protect device queue against concurrent access USB: serial: option: add Luat Air72*U series products hv_netvsc: Fix race of register_netdevice_notifier and VF register hv_netvsc: Mark VF as slave before exposing it to user-mode dm-delay: fix a race between delay_presuspend and delay_bio bcache: check return value from btree_node_alloc_replacement() bcache: prevent potential division by zero error USB: serial: option: add Fibocom L7xx modules USB: serial: option: fix FM101R-GL defines USB: serial: option: don't claim interface 4 for ZTE MF290 USB: dwc2: write HCINT with INTMASK applied usb: dwc3: set the dma max_seg_size USB: dwc3: qcom: fix resource leaks on probe deferral USB: dwc3: qcom: fix wakeup after probe deferral io_uring: fix off-by one bvec index pinctrl: avoid reload of p state in list iteration firewire: core: fix possible memory leak in create_units() mmc: block: Do not lose cache flush during CQE error recovery ALSA: hda: Disable power-save on KONTRON SinglePC ALSA: hda/realtek: Headset Mic VREF to 100% ALSA: hda/realtek: Add supported ALC257 for ChromeOS dm-verity: align struct dm_verity_fec_io properly dm verity: don't perform FEC for failed readahead IO bcache: revert replacing IS_ERR_OR_NULL with IS_ERR powerpc: Don't clobber f0/vs0 during fp|altivec register save btrfs: add dmesg output for first mount and last unmount of a filesystem btrfs: fix off-by-one when checking chunk map includes logical address btrfs: send: ensure send_fd is writable btrfs: make error messages more clear when getting a chunk map Input: xpad - add HyperX Clutch Gladiate Support ipv4: igmp: fix refcnt uaf issue when receiving igmp query packet net: stmmac: xgmac: Disable FPE MMC interrupts ravb: Fix races between ravb_tx_timeout_work() and net related ops net: ravb: Use pm_runtime_resume_and_get() net: ravb: Start TX queues after HW initialization succeeded smb3: fix touch -h of symlink s390/mm: fix phys vs virt confusion in mark_kernel_pXd() functions family s390/cmma: fix detection of DAT pages mtd: cfi_cmdset_0001: Support the absence of protection registers mtd: cfi_cmdset_0001: Byte swap OTP info fbdev: stifb: Make the STI next font pointer a 32-bit signed offset ima: annotate iint mutex to avoid lockdep false positive warnings ovl: skip overlayfs superblocks at global sync ima: detect changes to the backing overlay file scsi: qla2xxx: Simplify the code for aborting SCSI commands scsi: core: Introduce the scsi_cmd_to_rq() function scsi: qla2xxx: Use scsi_cmd_to_rq() instead of scsi_cmnd.request scsi: qla2xxx: Fix system crash due to bad pointer access cpufreq: imx6q: don't warn for disabling a non-existing frequency cpufreq: imx6q: Don't disable 792 Mhz OPP unnecessarily mmc: cqhci: Increase recovery halt timeout mmc: cqhci: Warn of halt or task clear failure mmc: cqhci: Fix task clearing in CQE error recovery mmc: core: convert comma to semicolon mmc: block: Retry commands in CQE error recovery Linux 5.4.263 Change-Id: I5187b50207d7ed37d7448664448409ed75106ea1 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
349 lines
9.3 KiB
C
349 lines
9.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _SCSI_SCSI_CMND_H
|
|
#define _SCSI_SCSI_CMND_H
|
|
|
|
#include <linux/dma-mapping.h>
|
|
#include <linux/blkdev.h>
|
|
#include <linux/t10-pi.h>
|
|
#include <linux/list.h>
|
|
#include <linux/types.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/scatterlist.h>
|
|
#include <scsi/scsi_device.h>
|
|
#include <scsi/scsi_request.h>
|
|
#include <linux/android_kabi.h>
|
|
|
|
struct Scsi_Host;
|
|
struct scsi_driver;
|
|
|
|
/*
|
|
* MAX_COMMAND_SIZE is:
|
|
* The longest fixed-length SCSI CDB as per the SCSI standard.
|
|
* fixed-length means: commands that their size can be determined
|
|
* by their opcode and the CDB does not carry a length specifier, (unlike
|
|
* the VARIABLE_LENGTH_CMD(0x7f) command). This is actually not exactly
|
|
* true and the SCSI standard also defines extended commands and
|
|
* vendor specific commands that can be bigger than 16 bytes. The kernel
|
|
* will support these using the same infrastructure used for VARLEN CDB's.
|
|
* So in effect MAX_COMMAND_SIZE means the maximum size command scsi-ml
|
|
* supports without specifying a cmd_len by ULD's
|
|
*/
|
|
#define MAX_COMMAND_SIZE 16
|
|
#if (MAX_COMMAND_SIZE > BLK_MAX_CDB)
|
|
# error MAX_COMMAND_SIZE can not be bigger than BLK_MAX_CDB
|
|
#endif
|
|
|
|
struct scsi_data_buffer {
|
|
struct sg_table table;
|
|
unsigned length;
|
|
};
|
|
|
|
/* embedded in scsi_cmnd */
|
|
struct scsi_pointer {
|
|
char *ptr; /* data pointer */
|
|
int this_residual; /* left in this buffer */
|
|
struct scatterlist *buffer; /* which buffer */
|
|
int buffers_residual; /* how many buffers left */
|
|
|
|
dma_addr_t dma_handle;
|
|
|
|
volatile int Status;
|
|
volatile int Message;
|
|
volatile int have_data_in;
|
|
volatile int sent_command;
|
|
volatile int phase;
|
|
};
|
|
|
|
/* for scmd->flags */
|
|
#define SCMD_TAGGED (1 << 0)
|
|
#define SCMD_UNCHECKED_ISA_DMA (1 << 1)
|
|
#define SCMD_INITIALIZED (1 << 2)
|
|
#define SCMD_LAST (1 << 3)
|
|
/* flags preserved across unprep / reprep */
|
|
#define SCMD_PRESERVED_FLAGS (SCMD_UNCHECKED_ISA_DMA | SCMD_INITIALIZED)
|
|
|
|
/* for scmd->state */
|
|
#define SCMD_STATE_COMPLETE 0
|
|
|
|
struct scsi_cmnd {
|
|
struct scsi_request req;
|
|
struct scsi_device *device;
|
|
struct list_head list; /* scsi_cmnd participates in queue lists */
|
|
struct list_head eh_entry; /* entry for the host eh_cmd_q */
|
|
struct delayed_work abort_work;
|
|
|
|
struct rcu_head rcu;
|
|
|
|
int eh_eflags; /* Used by error handlr */
|
|
|
|
/*
|
|
* This is set to jiffies as it was when the command was first
|
|
* allocated. It is used to time how long the command has
|
|
* been outstanding
|
|
*/
|
|
unsigned long jiffies_at_alloc;
|
|
|
|
int retries;
|
|
int allowed;
|
|
|
|
unsigned char prot_op;
|
|
unsigned char prot_type;
|
|
unsigned char prot_flags;
|
|
|
|
unsigned short cmd_len;
|
|
enum dma_data_direction sc_data_direction;
|
|
|
|
/* These elements define the operation we are about to perform */
|
|
unsigned char *cmnd;
|
|
|
|
|
|
/* These elements define the operation we ultimately want to perform */
|
|
struct scsi_data_buffer sdb;
|
|
struct scsi_data_buffer *prot_sdb;
|
|
|
|
unsigned underflow; /* Return error if less than
|
|
this amount is transferred */
|
|
|
|
unsigned transfersize; /* How much we are guaranteed to
|
|
transfer with each SCSI transfer
|
|
(ie, between disconnect /
|
|
reconnects. Probably == sector
|
|
size */
|
|
|
|
struct request *request; /* The command we are
|
|
working on */
|
|
|
|
unsigned char *sense_buffer;
|
|
/* obtained by REQUEST SENSE when
|
|
* CHECK CONDITION is received on original
|
|
* command (auto-sense). Length must be
|
|
* SCSI_SENSE_BUFFERSIZE bytes. */
|
|
|
|
/* Low-level done function - can be used by low-level driver to point
|
|
* to completion function. Not used by mid/upper level code. */
|
|
void (*scsi_done) (struct scsi_cmnd *);
|
|
|
|
/*
|
|
* The following fields can be written to by the host specific code.
|
|
* Everything else should be left alone.
|
|
*/
|
|
struct scsi_pointer SCp; /* Scratchpad used by some host adapters */
|
|
|
|
unsigned char *host_scribble; /* The host adapter is allowed to
|
|
* call scsi_malloc and get some memory
|
|
* and hang it here. The host adapter
|
|
* is also expected to call scsi_free
|
|
* to release this memory. (The memory
|
|
* obtained by scsi_malloc is guaranteed
|
|
* to be at an address < 16Mb). */
|
|
|
|
int result; /* Status code from lower level driver */
|
|
int flags; /* Command flags */
|
|
unsigned long state; /* Command completion state */
|
|
|
|
unsigned char tag; /* SCSI-II queued command tag */
|
|
|
|
ANDROID_KABI_RESERVE(1);
|
|
ANDROID_KABI_RESERVE(2);
|
|
ANDROID_KABI_RESERVE(3);
|
|
ANDROID_KABI_RESERVE(4);
|
|
};
|
|
|
|
/* Variant of blk_mq_rq_from_pdu() that verifies the type of its argument. */
|
|
static inline struct request *scsi_cmd_to_rq(struct scsi_cmnd *scmd)
|
|
{
|
|
return blk_mq_rq_from_pdu(scmd);
|
|
}
|
|
|
|
/*
|
|
* Return the driver private allocation behind the command.
|
|
* Only works if cmd_size is set in the host template.
|
|
*/
|
|
static inline void *scsi_cmd_priv(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd + 1;
|
|
}
|
|
|
|
/* make sure not to use it with passthrough commands */
|
|
static inline struct scsi_driver *scsi_cmd_to_driver(struct scsi_cmnd *cmd)
|
|
{
|
|
return *(struct scsi_driver **)cmd->request->rq_disk->private_data;
|
|
}
|
|
|
|
extern void scsi_put_command(struct scsi_cmnd *);
|
|
extern void scsi_finish_command(struct scsi_cmnd *cmd);
|
|
|
|
extern void *scsi_kmap_atomic_sg(struct scatterlist *sg, int sg_count,
|
|
size_t *offset, size_t *len);
|
|
extern void scsi_kunmap_atomic_sg(void *virt);
|
|
|
|
extern blk_status_t scsi_init_io(struct scsi_cmnd *cmd);
|
|
|
|
#ifdef CONFIG_SCSI_DMA
|
|
extern int scsi_dma_map(struct scsi_cmnd *cmd);
|
|
extern void scsi_dma_unmap(struct scsi_cmnd *cmd);
|
|
#else /* !CONFIG_SCSI_DMA */
|
|
static inline int scsi_dma_map(struct scsi_cmnd *cmd) { return -ENOSYS; }
|
|
static inline void scsi_dma_unmap(struct scsi_cmnd *cmd) { }
|
|
#endif /* !CONFIG_SCSI_DMA */
|
|
|
|
static inline unsigned scsi_sg_count(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd->sdb.table.nents;
|
|
}
|
|
|
|
static inline struct scatterlist *scsi_sglist(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd->sdb.table.sgl;
|
|
}
|
|
|
|
static inline unsigned scsi_bufflen(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd->sdb.length;
|
|
}
|
|
|
|
static inline void scsi_set_resid(struct scsi_cmnd *cmd, int resid)
|
|
{
|
|
cmd->req.resid_len = resid;
|
|
}
|
|
|
|
static inline int scsi_get_resid(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd->req.resid_len;
|
|
}
|
|
|
|
#define scsi_for_each_sg(cmd, sg, nseg, __i) \
|
|
for_each_sg(scsi_sglist(cmd), sg, nseg, __i)
|
|
|
|
static inline int scsi_sg_copy_from_buffer(struct scsi_cmnd *cmd,
|
|
const void *buf, int buflen)
|
|
{
|
|
return sg_copy_from_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
|
|
buf, buflen);
|
|
}
|
|
|
|
static inline int scsi_sg_copy_to_buffer(struct scsi_cmnd *cmd,
|
|
void *buf, int buflen)
|
|
{
|
|
return sg_copy_to_buffer(scsi_sglist(cmd), scsi_sg_count(cmd),
|
|
buf, buflen);
|
|
}
|
|
|
|
/*
|
|
* The operations below are hints that tell the controller driver how
|
|
* to handle I/Os with DIF or similar types of protection information.
|
|
*/
|
|
enum scsi_prot_operations {
|
|
/* Normal I/O */
|
|
SCSI_PROT_NORMAL = 0,
|
|
|
|
/* OS-HBA: Protected, HBA-Target: Unprotected */
|
|
SCSI_PROT_READ_INSERT,
|
|
SCSI_PROT_WRITE_STRIP,
|
|
|
|
/* OS-HBA: Unprotected, HBA-Target: Protected */
|
|
SCSI_PROT_READ_STRIP,
|
|
SCSI_PROT_WRITE_INSERT,
|
|
|
|
/* OS-HBA: Protected, HBA-Target: Protected */
|
|
SCSI_PROT_READ_PASS,
|
|
SCSI_PROT_WRITE_PASS,
|
|
};
|
|
|
|
static inline void scsi_set_prot_op(struct scsi_cmnd *scmd, unsigned char op)
|
|
{
|
|
scmd->prot_op = op;
|
|
}
|
|
|
|
static inline unsigned char scsi_get_prot_op(struct scsi_cmnd *scmd)
|
|
{
|
|
return scmd->prot_op;
|
|
}
|
|
|
|
enum scsi_prot_flags {
|
|
SCSI_PROT_TRANSFER_PI = 1 << 0,
|
|
SCSI_PROT_GUARD_CHECK = 1 << 1,
|
|
SCSI_PROT_REF_CHECK = 1 << 2,
|
|
SCSI_PROT_REF_INCREMENT = 1 << 3,
|
|
SCSI_PROT_IP_CHECKSUM = 1 << 4,
|
|
};
|
|
|
|
/*
|
|
* The controller usually does not know anything about the target it
|
|
* is communicating with. However, when DIX is enabled the controller
|
|
* must be know target type so it can verify the protection
|
|
* information passed along with the I/O.
|
|
*/
|
|
enum scsi_prot_target_type {
|
|
SCSI_PROT_DIF_TYPE0 = 0,
|
|
SCSI_PROT_DIF_TYPE1,
|
|
SCSI_PROT_DIF_TYPE2,
|
|
SCSI_PROT_DIF_TYPE3,
|
|
};
|
|
|
|
static inline void scsi_set_prot_type(struct scsi_cmnd *scmd, unsigned char type)
|
|
{
|
|
scmd->prot_type = type;
|
|
}
|
|
|
|
static inline unsigned char scsi_get_prot_type(struct scsi_cmnd *scmd)
|
|
{
|
|
return scmd->prot_type;
|
|
}
|
|
|
|
static inline sector_t scsi_get_lba(struct scsi_cmnd *scmd)
|
|
{
|
|
return blk_rq_pos(scmd->request);
|
|
}
|
|
|
|
static inline unsigned int scsi_prot_interval(struct scsi_cmnd *scmd)
|
|
{
|
|
return scmd->device->sector_size;
|
|
}
|
|
|
|
static inline unsigned scsi_prot_sg_count(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd->prot_sdb ? cmd->prot_sdb->table.nents : 0;
|
|
}
|
|
|
|
static inline struct scatterlist *scsi_prot_sglist(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd->prot_sdb ? cmd->prot_sdb->table.sgl : NULL;
|
|
}
|
|
|
|
static inline struct scsi_data_buffer *scsi_prot(struct scsi_cmnd *cmd)
|
|
{
|
|
return cmd->prot_sdb;
|
|
}
|
|
|
|
#define scsi_for_each_prot_sg(cmd, sg, nseg, __i) \
|
|
for_each_sg(scsi_prot_sglist(cmd), sg, nseg, __i)
|
|
|
|
static inline void set_msg_byte(struct scsi_cmnd *cmd, char status)
|
|
{
|
|
cmd->result = (cmd->result & 0xffff00ff) | (status << 8);
|
|
}
|
|
|
|
static inline void set_host_byte(struct scsi_cmnd *cmd, char status)
|
|
{
|
|
cmd->result = (cmd->result & 0xff00ffff) | (status << 16);
|
|
}
|
|
|
|
static inline void set_driver_byte(struct scsi_cmnd *cmd, char status)
|
|
{
|
|
cmd->result = (cmd->result & 0x00ffffff) | (status << 24);
|
|
}
|
|
|
|
static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
|
|
{
|
|
unsigned int xfer_len = scmd->sdb.length;
|
|
unsigned int prot_interval = scsi_prot_interval(scmd);
|
|
|
|
if (scmd->prot_flags & SCSI_PROT_TRANSFER_PI)
|
|
xfer_len += (xfer_len >> ilog2(prot_interval)) * 8;
|
|
|
|
return xfer_len;
|
|
}
|
|
|
|
#endif /* _SCSI_SCSI_CMND_H */
|