/* SPDX-License-Identifier: GPL-2.0 */1#ifndef _SCSI_SCSI_HOST_H2#define _SCSI_SCSI_HOST_H34#include <linux/device.h>5#include <linux/list.h>6#include <linux/types.h>7#include <linux/workqueue.h>8#include <linux/mutex.h>9#include <linux/seq_file.h>10#include <linux/blk-mq.h>11#include <scsi/scsi.h>1213struct block_device;14struct completion;15struct module;16struct scsi_cmnd;17struct scsi_device;18struct scsi_target;19struct Scsi_Host;20struct scsi_transport_template;212223#define SG_ALL SG_CHUNK_SIZE2425#define MODE_UNKNOWN 0x0026#define MODE_INITIATOR 0x0127#define MODE_TARGET 0x022829/**30* enum scsi_timeout_action - How to handle a command that timed out.31* @SCSI_EH_DONE: The command has already been completed.32* @SCSI_EH_RESET_TIMER: Reset the timer and continue waiting for completion.33* @SCSI_EH_NOT_HANDLED: The command has not yet finished. Abort the command.34*/35enum scsi_timeout_action {36SCSI_EH_DONE,37SCSI_EH_RESET_TIMER,38SCSI_EH_NOT_HANDLED,39};4041struct scsi_host_template {42/*43* Put fields referenced in IO submission path together in44* same cacheline45*/4647/*48* Additional per-command data allocated for the driver.49*/50unsigned int cmd_size;5152/*53* The queuecommand function is used to queue up a scsi54* command block to the LLDD. When the driver finished55* processing the command the done callback is invoked.56*57* If queuecommand returns 0, then the driver has accepted the58* command. It must also push it to the HBA if the scsi_cmnd59* flag SCMD_LAST is set, or if the driver does not implement60* commit_rqs. The done() function must be called on the command61* when the driver has finished with it. (you may call done on the62* command before queuecommand returns, but in this case you63* *must* return 0 from queuecommand).64*65* Queuecommand may also reject the command, in which case it may66* not touch the command and must not call done() for it.67*68* There are two possible rejection returns:69*70* SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but71* allow commands to other devices serviced by this host.72*73* SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this74* host temporarily.75*76* For compatibility, any other non-zero return is treated the77* same as SCSI_MLQUEUE_HOST_BUSY.78*79* NOTE: "temporarily" means either until the next command for#80* this device/host completes, or a period of time determined by81* I/O pressure in the system if there are no other outstanding82* commands.83*84* STATUS: REQUIRED85*/86int (* queuecommand)(struct Scsi_Host *, struct scsi_cmnd *);8788/*89* Queue a reserved command (BLK_MQ_REQ_RESERVED). The .queuecommand()90* documentation also applies to the .queue_reserved_command() callback.91*/92int (*queue_reserved_command)(struct Scsi_Host *, struct scsi_cmnd *);9394/*95* The commit_rqs function is used to trigger a hardware96* doorbell after some requests have been queued with97* queuecommand, when an error is encountered before sending98* the request with SCMD_LAST set.99*100* STATUS: OPTIONAL101*/102void (*commit_rqs)(struct Scsi_Host *, u16);103104struct module *module;105const char *name;106107/*108* The info function will return whatever useful information the109* developer sees fit. If not provided, then the name field will110* be used instead.111*112* Status: OPTIONAL113*/114const char *(*info)(struct Scsi_Host *);115116/*117* Ioctl interface118*119* Status: OPTIONAL120*/121int (*ioctl)(struct scsi_device *dev, unsigned int cmd,122void __user *arg);123124125#ifdef CONFIG_COMPAT126/*127* Compat handler. Handle 32bit ABI.128* When unknown ioctl is passed return -ENOIOCTLCMD.129*130* Status: OPTIONAL131*/132int (*compat_ioctl)(struct scsi_device *dev, unsigned int cmd,133void __user *arg);134#endif135136int (*init_cmd_priv)(struct Scsi_Host *shost, struct scsi_cmnd *cmd);137int (*exit_cmd_priv)(struct Scsi_Host *shost, struct scsi_cmnd *cmd);138139/*140* This is an error handling strategy routine. You don't need to141* define one of these if you don't want to - there is a default142* routine that is present that should work in most cases. For those143* driver authors that have the inclination and ability to write their144* own strategy routine, this is where it is specified. Note - the145* strategy routine is *ALWAYS* run in the context of the kernel eh146* thread. Thus you are guaranteed to *NOT* be in an interrupt147* handler when you execute this, and you are also guaranteed to148* *NOT* have any other commands being queued while you are in the149* strategy routine. When you return from this function, operations150* return to normal.151*152* See scsi_error.c scsi_unjam_host for additional comments about153* what this function should and should not be attempting to do.154*155* Status: REQUIRED (at least one of them)156*/157int (* eh_abort_handler)(struct scsi_cmnd *);158int (* eh_device_reset_handler)(struct scsi_cmnd *);159int (* eh_target_reset_handler)(struct scsi_cmnd *);160int (* eh_bus_reset_handler)(struct scsi_cmnd *);161int (* eh_host_reset_handler)(struct scsi_cmnd *);162163/*164* Before the mid layer attempts to scan for a new device where none165* currently exists, it will call this entry in your driver. Should166* your driver need to allocate any structs or perform any other init167* items in order to send commands to a currently unused target/lun168* combo, then this is where you can perform those allocations. This169* is specifically so that drivers won't have to perform any kind of170* "is this a new device" checks in their queuecommand routine,171* thereby making the hot path a bit quicker.172*173* Return values: 0 on success, non-0 on failure174*175* Deallocation: If we didn't find any devices at this ID, you will176* get an immediate call to sdev_destroy(). If we find something177* here then you will get a call to sdev_configure(), then the178* device will be used for however long it is kept around, then when179* the device is removed from the system (or * possibly at reboot180* time), you will then get a call to sdev_destroy(). This is181* assuming you implement sdev_configure and sdev_destroy.182* However, if you allocate memory and hang it off the device struct,183* then you must implement the sdev_destroy() routine at a minimum184* in order to avoid leaking memory185* each time a device is tore down.186*187* Status: OPTIONAL188*/189int (* sdev_init)(struct scsi_device *);190191/*192* Once the device has responded to an INQUIRY and we know the193* device is online, we call into the low level driver with the194* struct scsi_device *. If the low level device driver implements195* this function, it *must* perform the task of setting the queue196* depth on the device. All other tasks are optional and depend197* on what the driver supports and various implementation details.198*199* Things currently recommended to be handled at this time include:200*201* 1. Setting the device queue depth. Proper setting of this is202* described in the comments for scsi_change_queue_depth.203* 2. Determining if the device supports the various synchronous204* negotiation protocols. The device struct will already have205* responded to INQUIRY and the results of the standard items206* will have been shoved into the various device flag bits, eg.207* device->sdtr will be true if the device supports SDTR messages.208* 3. Allocating command structs that the device will need.209* 4. Setting the default timeout on this device (if needed).210* 5. Anything else the low level driver might want to do on a device211* specific setup basis...212* 6. Return 0 on success, non-0 on error. The device will be marked213* as offline on error so that no access will occur. If you return214* non-0, your sdev_destroy routine will never get called for this215* device, so don't leave any loose memory hanging around, clean216* up after yourself before returning non-0217*218* Status: OPTIONAL219*/220int (* sdev_configure)(struct scsi_device *, struct queue_limits *lim);221222/*223* Immediately prior to deallocating the device and after all activity224* has ceased the mid layer calls this point so that the low level225* driver may completely detach itself from the scsi device and vice226* versa. The low level driver is responsible for freeing any memory227* it allocated in the sdev_init or sdev_configure calls.228*229* Status: OPTIONAL230*/231void (* sdev_destroy)(struct scsi_device *);232233/*234* Before the mid layer attempts to scan for a new device attached235* to a target where no target currently exists, it will call this236* entry in your driver. Should your driver need to allocate any237* structs or perform any other init items in order to send commands238* to a currently unused target, then this is where you can perform239* those allocations.240*241* Return values: 0 on success, non-0 on failure242*243* Status: OPTIONAL244*/245int (* target_alloc)(struct scsi_target *);246247/*248* Immediately prior to deallocating the target structure, and249* after all activity to attached scsi devices has ceased, the250* midlayer calls this point so that the driver may deallocate251* and terminate any references to the target.252*253* Note: This callback is called with the host lock held and hence254* must not sleep.255*256* Status: OPTIONAL257*/258void (* target_destroy)(struct scsi_target *);259260/*261* If a host has the ability to discover targets on its own instead262* of scanning the entire bus, it can fill in this function and263* call scsi_scan_host(). This function will be called periodically264* until it returns 1 with the scsi_host and the elapsed time of265* the scan in jiffies.266*267* Status: OPTIONAL268*/269int (* scan_finished)(struct Scsi_Host *, unsigned long);270271/*272* If the host wants to be called before the scan starts, but273* after the midlayer has set up ready for the scan, it can fill274* in this function.275*276* Status: OPTIONAL277*/278void (* scan_start)(struct Scsi_Host *);279280/*281* Fill in this function to allow the queue depth of this host282* to be changeable (on a per device basis). Returns either283* the current queue depth setting (may be different from what284* was passed in) or an error. An error should only be285* returned if the requested depth is legal but the driver was286* unable to set it. If the requested depth is illegal, the287* driver should set and return the closest legal queue depth.288*289* Status: OPTIONAL290*/291int (* change_queue_depth)(struct scsi_device *, int);292293/*294* This functions lets the driver expose the queue mapping295* to the block layer.296*297* Status: OPTIONAL298*/299void (* map_queues)(struct Scsi_Host *shost);300301/*302* SCSI interface of blk_poll - poll for IO completions.303* Only applicable if SCSI LLD exposes multiple h/w queues.304*305* Return value: Number of completed entries found.306*307* Status: OPTIONAL308*/309int (* mq_poll)(struct Scsi_Host *shost, unsigned int queue_num);310311/*312* Check if scatterlists need to be padded for DMA draining.313*314* Status: OPTIONAL315*/316bool (* dma_need_drain)(struct request *rq);317318/*319* This function determines the BIOS parameters for a given320* harddisk. These tend to be numbers that are made up by321* the host adapter. Parameters:322* size, device, list (heads, sectors, cylinders)323*324* Status: OPTIONAL325*/326int (* bios_param)(struct scsi_device *, struct gendisk *,327sector_t, int []);328329/*330* This function is called when one or more partitions on the331* device reach beyond the end of the device.332*333* Status: OPTIONAL334*/335void (*unlock_native_capacity)(struct scsi_device *);336337/*338* Can be used to export driver statistics and other infos to the339* world outside the kernel ie. userspace and it also provides an340* interface to feed the driver with information.341*342* Status: OBSOLETE343*/344int (*show_info)(struct seq_file *, struct Scsi_Host *);345int (*write_info)(struct Scsi_Host *, char *, int);346347/*348* This is an optional routine that allows the transport to become349* involved when a scsi io timer fires. The return value tells the350* timer routine how to finish the io timeout handling.351*352* Status: OPTIONAL353*/354enum scsi_timeout_action (*eh_timed_out)(struct scsi_cmnd *);355/*356* Optional routine that allows the transport to decide if a cmd357* is retryable. Return true if the transport is in a state the358* cmd should be retried on.359*/360bool (*eh_should_retry_cmd)(struct scsi_cmnd *scmd);361362/* This is an optional routine that allows transport to initiate363* LLD adapter or firmware reset using sysfs attribute.364*365* Return values: 0 on success, -ve value on failure.366*367* Status: OPTIONAL368*/369370int (*host_reset)(struct Scsi_Host *shost, int reset_type);371#define SCSI_ADAPTER_RESET 1372#define SCSI_FIRMWARE_RESET 2373374375/*376* Name of proc directory377*/378const char *proc_name;379380/*381* This determines if we will use a non-interrupt driven382* or an interrupt driven scheme. It is set to the maximum number383* of simultaneous commands a single hw queue in HBA will accept384* excluding internal commands.385*/386int can_queue;387388/*389* This determines how many commands the HBA will set aside390* for internal commands. This number will be added to391* @can_queue to calculate the maximum number of simultaneous392* commands sent to the host.393*/394int nr_reserved_cmds;395396/*397* In many instances, especially where disconnect / reconnect are398* supported, our host also has an ID on the SCSI bus. If this is399* the case, then it must be reserved. Please set this_id to -1 if400* your setup is in single initiator mode, and the host lacks an401* ID.402*/403int this_id;404405/*406* This determines the degree to which the host adapter is capable407* of scatter-gather.408*/409unsigned short sg_tablesize;410unsigned short sg_prot_tablesize;411412/*413* Set this if the host adapter has limitations beside segment count.414*/415unsigned int max_sectors;416417/*418* Maximum size in bytes of a single segment.419*/420unsigned int max_segment_size;421422unsigned int dma_alignment;423424/*425* DMA scatter gather segment boundary limit. A segment crossing this426* boundary will be split in two.427*/428unsigned long dma_boundary;429430unsigned long virt_boundary_mask;431432/*433* This specifies "machine infinity" for host templates which don't434* limit the transfer size. Note this limit represents an absolute435* maximum, and may be over the transfer limits allowed for436* individual devices (e.g. 256 for SCSI-1).437*/438#define SCSI_DEFAULT_MAX_SECTORS 1024439440/*441* True if this host adapter can make good use of linked commands.442* This will allow more than one command to be queued to a given443* unit on a given host. Set this to the maximum number of command444* blocks to be provided for each device. Set this to 1 for one445* command block per lun, 2 for two, etc. Do not set this to 0.446* You should make sure that the host adapter will do the right thing447* before you try setting this above 1.448*/449short cmd_per_lun;450451/*452* Allocate tags starting from last allocated tag.453*/454bool tag_alloc_policy_rr : 1;455456/*457* Track QUEUE_FULL events and reduce queue depth on demand.458*/459unsigned track_queue_depth:1;460461/*462* This specifies the mode that a LLD supports.463*/464unsigned supported_mode:2;465466/*467* True for emulated SCSI host adapters (e.g. ATAPI).468*/469unsigned emulated:1;470471/*472* True if the low-level driver performs its own reset-settle delays.473*/474unsigned skip_settle_delay:1;475476/* True if the controller does not support WRITE SAME */477unsigned no_write_same:1;478479/* True if the host uses host-wide tagspace */480unsigned host_tagset:1;481482/* The queuecommand callback may block. See also BLK_MQ_F_BLOCKING. */483unsigned queuecommand_may_block:1;484485/*486* Countdown for host blocking with no commands outstanding.487*/488unsigned int max_host_blocked;489490/*491* Default value for the blocking. If the queue is empty,492* host_blocked counts down in the request_fn until it restarts493* host operations as zero is reached.494*495* FIXME: This should probably be a value in the template496*/497#define SCSI_DEFAULT_HOST_BLOCKED 7498499/*500* Pointer to the SCSI host sysfs attribute groups, NULL terminated.501*/502const struct attribute_group **shost_groups;503504/*505* Pointer to the SCSI device attribute groups for this host,506* NULL terminated.507*/508const struct attribute_group **sdev_groups;509510/*511* Vendor Identifier associated with the host512*513* Note: When specifying vendor_id, be sure to read the514* Vendor Type and ID formatting requirements specified in515* scsi_netlink.h516*/517u64 vendor_id;518};519520/*521* Temporary #define for host lock push down. Can be removed when all522* drivers have been updated to take advantage of unlocked523* queuecommand.524*525*/526#define DEF_SCSI_QCMD(func_name) \527int func_name(struct Scsi_Host *shost, struct scsi_cmnd *cmd) \528{ \529unsigned long irq_flags; \530int rc; \531spin_lock_irqsave(shost->host_lock, irq_flags); \532rc = func_name##_lck(cmd); \533spin_unlock_irqrestore(shost->host_lock, irq_flags); \534return rc; \535}536537538/*539* shost state: If you alter this, you also need to alter scsi_sysfs.c540* (for the ascii descriptions) and the state model enforcer:541* scsi_host_set_state()542*/543enum scsi_host_state {544SHOST_CREATED = 1,545SHOST_RUNNING,546SHOST_CANCEL,547SHOST_DEL,548SHOST_RECOVERY,549SHOST_CANCEL_RECOVERY,550SHOST_DEL_RECOVERY,551};552553struct Scsi_Host {554/*555* __devices is protected by the host_lock, but you should556* usually use scsi_device_lookup / shost_for_each_device557* to access it and don't care about locking yourself.558* In the rare case of being in irq context you can use559* their __ prefixed variants with the lock held. NEVER560* access this list directly from a driver.561*/562struct list_head __devices;563struct list_head __targets;564565struct list_head starved_list;566567spinlock_t default_lock;568spinlock_t *host_lock;569570struct mutex scan_mutex;/* serialize scanning activity */571572struct list_head eh_abort_list;573struct list_head eh_cmd_q;574struct task_struct * ehandler; /* Error recovery thread. */575struct completion * eh_action; /* Wait for specific actions on the576host. */577wait_queue_head_t host_wait;578const struct scsi_host_template *hostt;579struct scsi_transport_template *transportt;580581struct kref tagset_refcnt;582struct completion tagset_freed;583/* Area to keep a shared tag map */584struct blk_mq_tag_set tag_set;585586atomic_t host_blocked;587588unsigned int host_failed; /* commands that failed.589protected by host_lock */590unsigned int host_eh_scheduled; /* EH scheduled without command */591592unsigned int host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */593594/* next two fields are used to bound the time spent in error handling */595int eh_deadline;596unsigned long last_reset;597598599/*600* These three parameters can be used to allow for wide scsi,601* and for host adapters that support multiple busses602* The last two should be set to 1 more than the actual max id603* or lun (e.g. 8 for SCSI parallel systems).604*/605unsigned int max_channel;606unsigned int max_id;607u64 max_lun;608609/*610* This is a unique identifier that must be assigned so that we611* have some way of identifying each detected host adapter properly612* and uniquely. For hosts that do not support more than one card613* in the system at one time, this does not need to be set. It is614* initialized to 0 in scsi_host_alloc.615*/616unsigned int unique_id;617618/*619* The maximum length of SCSI commands that this host can accept.620* Probably 12 for most host adapters, but could be 16 for others.621* or 260 if the driver supports variable length cdbs.622* For drivers that don't set this field, a value of 12 is623* assumed.624*/625unsigned short max_cmd_len;626627int this_id;628629/*630* Number of commands this host can handle at the same time.631* This excludes reserved commands as specified by nr_reserved_cmds.632*/633int can_queue;634/*635* Number of reserved commands to allocate, if any.636*/637unsigned int nr_reserved_cmds;638639short cmd_per_lun;640short unsigned int sg_tablesize;641short unsigned int sg_prot_tablesize;642unsigned int max_sectors;643unsigned int opt_sectors;644unsigned int max_segment_size;645unsigned int dma_alignment;646unsigned long dma_boundary;647unsigned long virt_boundary_mask;648/*649* In scsi-mq mode, the number of hardware queues supported by the LLD.650*651* Note: it is assumed that each hardware queue has a queue depth of652* can_queue. In other words, the total queue depth per host653* is nr_hw_queues * can_queue. However, for when host_tagset is set,654* the total queue depth is can_queue.655*/656unsigned nr_hw_queues;657unsigned nr_maps;658unsigned active_mode:2;659660/*661* Host has requested that no further requests come through for the662* time being.663*/664unsigned host_self_blocked:1;665666/*667* Host uses correct SCSI ordering not PC ordering. The bit is668* set for the minority of drivers whose authors actually read669* the spec ;).670*/671unsigned reverse_ordering:1;672673/* Task mgmt function in progress */674unsigned tmf_in_progress:1;675676/* Asynchronous scan in progress */677unsigned async_scan:1;678679/* Don't resume host in EH */680unsigned eh_noresume:1;681682/* The controller does not support WRITE SAME */683unsigned no_write_same:1;684685/* True if the host uses host-wide tagspace */686unsigned host_tagset:1;687688/* The queuecommand callback may block. See also BLK_MQ_F_BLOCKING. */689unsigned queuecommand_may_block:1;690691/* Host responded with short (<36 bytes) INQUIRY result */692unsigned short_inquiry:1;693694/* The transport requires the LUN bits NOT to be stored in CDB[1] */695unsigned no_scsi2_lun_in_cdb:1;696697/*698* Optional work queue to be utilized by the transport699*/700struct workqueue_struct *work_q;701702/*703* Task management function work queue704*/705struct workqueue_struct *tmf_work_q;706707/*708* Value host_blocked counts down from709*/710unsigned int max_host_blocked;711712/* Protection Information */713unsigned int prot_capabilities;714unsigned char prot_guard_type;715716/* legacy crap */717unsigned long base;718unsigned long io_port;719unsigned char n_io_port;720unsigned char dma_channel;721unsigned int irq;722723724enum scsi_host_state shost_state;725726/* ldm bits */727struct device shost_gendev, shost_dev;728729/*730* A SCSI device structure used for sending internal commands to the731* HBA. There is no corresponding logical unit inside the SCSI device.732*/733struct scsi_device *pseudo_sdev;734735/*736* Points to the transport data (if any) which is allocated737* separately738*/739void *shost_data;740741/*742* Points to the physical bus device we'd use to do DMA743* Needed just in case we have virtual hosts.744*/745struct device *dma_dev;746747/* Delay for runtime autosuspend */748int rpm_autosuspend_delay;749750/*751* We should ensure that this is aligned, both for better performance752* and also because some compilers (m68k) don't automatically force753* alignment to a long boundary.754*/755unsigned long hostdata[] /* Used for storage of host specific stuff */756__attribute__ ((aligned (sizeof(unsigned long))));757};758759#define class_to_shost(d) \760container_of(d, struct Scsi_Host, shost_dev)761762#define shost_printk(prefix, shost, fmt, a...) \763dev_printk(prefix, &(shost)->shost_gendev, fmt, ##a)764765static inline void *shost_priv(struct Scsi_Host *shost)766{767return (void *)shost->hostdata;768}769770int scsi_is_host_device(const struct device *);771772static inline struct Scsi_Host *dev_to_shost(struct device *dev)773{774while (!scsi_is_host_device(dev)) {775if (!dev->parent)776return NULL;777dev = dev->parent;778}779return container_of(dev, struct Scsi_Host, shost_gendev);780}781782static inline int scsi_host_in_recovery(struct Scsi_Host *shost)783{784return shost->shost_state == SHOST_RECOVERY ||785shost->shost_state == SHOST_CANCEL_RECOVERY ||786shost->shost_state == SHOST_DEL_RECOVERY ||787shost->tmf_in_progress;788}789790extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);791extern void scsi_flush_work(struct Scsi_Host *);792793extern struct Scsi_Host *scsi_host_alloc(const struct scsi_host_template *, int);794extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *,795struct device *,796struct device *);797#if defined(CONFIG_SCSI_PROC_FS)798struct proc_dir_entry *799scsi_template_proc_dir(const struct scsi_host_template *sht);800#else801#define scsi_template_proc_dir(sht) NULL802#endif803extern void scsi_scan_host(struct Scsi_Host *);804extern int scsi_resume_device(struct scsi_device *sdev);805extern int scsi_rescan_device(struct scsi_device *sdev);806extern void scsi_remove_host(struct Scsi_Host *);807extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);808extern int scsi_host_busy(struct Scsi_Host *shost);809extern void scsi_host_put(struct Scsi_Host *t);810extern struct Scsi_Host *scsi_host_lookup(unsigned int hostnum);811extern const char *scsi_host_state_name(enum scsi_host_state);812extern void scsi_host_complete_all_commands(struct Scsi_Host *shost,813enum scsi_host_status status);814815static inline int __must_check scsi_add_host(struct Scsi_Host *host,816struct device *dev)817{818return scsi_add_host_with_dma(host, dev, dev);819}820821static inline struct device *scsi_get_device(struct Scsi_Host *shost)822{823return shost->shost_gendev.parent;824}825826/**827* scsi_host_scan_allowed - Is scanning of this host allowed828* @shost: Pointer to Scsi_Host.829**/830static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)831{832return shost->shost_state == SHOST_RUNNING ||833shost->shost_state == SHOST_RECOVERY;834}835836extern void scsi_unblock_requests(struct Scsi_Host *);837extern void scsi_block_requests(struct Scsi_Host *);838extern int scsi_host_block(struct Scsi_Host *shost);839extern int scsi_host_unblock(struct Scsi_Host *shost, int new_state);840841void scsi_host_busy_iter(struct Scsi_Host *,842bool (*fn)(struct scsi_cmnd *, void *), void *priv);843844struct class_container;845846/*847* DIF defines the exchange of protection information between848* initiator and SBC block device.849*850* DIX defines the exchange of protection information between OS and851* initiator.852*/853enum scsi_host_prot_capabilities {854SHOST_DIF_TYPE1_PROTECTION = 1 << 0, /* T10 DIF Type 1 */855SHOST_DIF_TYPE2_PROTECTION = 1 << 1, /* T10 DIF Type 2 */856SHOST_DIF_TYPE3_PROTECTION = 1 << 2, /* T10 DIF Type 3 */857858SHOST_DIX_TYPE0_PROTECTION = 1 << 3, /* DIX between OS and HBA only */859SHOST_DIX_TYPE1_PROTECTION = 1 << 4, /* DIX with DIF Type 1 */860SHOST_DIX_TYPE2_PROTECTION = 1 << 5, /* DIX with DIF Type 2 */861SHOST_DIX_TYPE3_PROTECTION = 1 << 6, /* DIX with DIF Type 3 */862};863864/*865* SCSI hosts which support the Data Integrity Extensions must866* indicate their capabilities by setting the prot_capabilities using867* this call.868*/869static inline void scsi_host_set_prot(struct Scsi_Host *shost, unsigned int mask)870{871shost->prot_capabilities = mask;872}873874static inline unsigned int scsi_host_get_prot(struct Scsi_Host *shost)875{876return shost->prot_capabilities;877}878879static inline int scsi_host_prot_dma(struct Scsi_Host *shost)880{881return shost->prot_capabilities >= SHOST_DIX_TYPE0_PROTECTION;882}883884static inline unsigned int scsi_host_dif_capable(struct Scsi_Host *shost, unsigned int target_type)885{886static unsigned char cap[] = { 0,887SHOST_DIF_TYPE1_PROTECTION,888SHOST_DIF_TYPE2_PROTECTION,889SHOST_DIF_TYPE3_PROTECTION };890891if (target_type >= ARRAY_SIZE(cap))892return 0;893894return shost->prot_capabilities & cap[target_type] ? target_type : 0;895}896897static inline unsigned int scsi_host_dix_capable(struct Scsi_Host *shost, unsigned int target_type)898{899#if defined(CONFIG_BLK_DEV_INTEGRITY)900static unsigned char cap[] = { SHOST_DIX_TYPE0_PROTECTION,901SHOST_DIX_TYPE1_PROTECTION,902SHOST_DIX_TYPE2_PROTECTION,903SHOST_DIX_TYPE3_PROTECTION };904905if (target_type >= ARRAY_SIZE(cap))906return 0;907908return shost->prot_capabilities & cap[target_type];909#endif910return 0;911}912913/*914* All DIX-capable initiators must support the T10-mandated CRC915* checksum. Controllers can optionally implement the IP checksum916* scheme which has much lower impact on system performance. Note917* that the main rationale for the checksum is to match integrity918* metadata with data. Detecting bit errors are a job for ECC memory919* and buses.920*/921922enum scsi_host_guard_type {923SHOST_DIX_GUARD_CRC = 1 << 0,924SHOST_DIX_GUARD_IP = 1 << 1,925};926927static inline void scsi_host_set_guard(struct Scsi_Host *shost, unsigned char type)928{929shost->prot_guard_type = type;930}931932static inline unsigned char scsi_host_get_guard(struct Scsi_Host *shost)933{934return shost->prot_guard_type;935}936937extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);938939#endif /* _SCSI_SCSI_HOST_H */940941942