/* 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* The commit_rqs function is used to trigger a hardware90* doorbell after some requests have been queued with91* queuecommand, when an error is encountered before sending92* the request with SCMD_LAST set.93*94* STATUS: OPTIONAL95*/96void (*commit_rqs)(struct Scsi_Host *, u16);9798struct module *module;99const char *name;100101/*102* The info function will return whatever useful information the103* developer sees fit. If not provided, then the name field will104* be used instead.105*106* Status: OPTIONAL107*/108const char *(*info)(struct Scsi_Host *);109110/*111* Ioctl interface112*113* Status: OPTIONAL114*/115int (*ioctl)(struct scsi_device *dev, unsigned int cmd,116void __user *arg);117118119#ifdef CONFIG_COMPAT120/*121* Compat handler. Handle 32bit ABI.122* When unknown ioctl is passed return -ENOIOCTLCMD.123*124* Status: OPTIONAL125*/126int (*compat_ioctl)(struct scsi_device *dev, unsigned int cmd,127void __user *arg);128#endif129130int (*init_cmd_priv)(struct Scsi_Host *shost, struct scsi_cmnd *cmd);131int (*exit_cmd_priv)(struct Scsi_Host *shost, struct scsi_cmnd *cmd);132133/*134* This is an error handling strategy routine. You don't need to135* define one of these if you don't want to - there is a default136* routine that is present that should work in most cases. For those137* driver authors that have the inclination and ability to write their138* own strategy routine, this is where it is specified. Note - the139* strategy routine is *ALWAYS* run in the context of the kernel eh140* thread. Thus you are guaranteed to *NOT* be in an interrupt141* handler when you execute this, and you are also guaranteed to142* *NOT* have any other commands being queued while you are in the143* strategy routine. When you return from this function, operations144* return to normal.145*146* See scsi_error.c scsi_unjam_host for additional comments about147* what this function should and should not be attempting to do.148*149* Status: REQUIRED (at least one of them)150*/151int (* eh_abort_handler)(struct scsi_cmnd *);152int (* eh_device_reset_handler)(struct scsi_cmnd *);153int (* eh_target_reset_handler)(struct scsi_cmnd *);154int (* eh_bus_reset_handler)(struct scsi_cmnd *);155int (* eh_host_reset_handler)(struct scsi_cmnd *);156157/*158* Before the mid layer attempts to scan for a new device where none159* currently exists, it will call this entry in your driver. Should160* your driver need to allocate any structs or perform any other init161* items in order to send commands to a currently unused target/lun162* combo, then this is where you can perform those allocations. This163* is specifically so that drivers won't have to perform any kind of164* "is this a new device" checks in their queuecommand routine,165* thereby making the hot path a bit quicker.166*167* Return values: 0 on success, non-0 on failure168*169* Deallocation: If we didn't find any devices at this ID, you will170* get an immediate call to sdev_destroy(). If we find something171* here then you will get a call to sdev_configure(), then the172* device will be used for however long it is kept around, then when173* the device is removed from the system (or * possibly at reboot174* time), you will then get a call to sdev_destroy(). This is175* assuming you implement sdev_configure and sdev_destroy.176* However, if you allocate memory and hang it off the device struct,177* then you must implement the sdev_destroy() routine at a minimum178* in order to avoid leaking memory179* each time a device is tore down.180*181* Status: OPTIONAL182*/183int (* sdev_init)(struct scsi_device *);184185/*186* Once the device has responded to an INQUIRY and we know the187* device is online, we call into the low level driver with the188* struct scsi_device *. If the low level device driver implements189* this function, it *must* perform the task of setting the queue190* depth on the device. All other tasks are optional and depend191* on what the driver supports and various implementation details.192*193* Things currently recommended to be handled at this time include:194*195* 1. Setting the device queue depth. Proper setting of this is196* described in the comments for scsi_change_queue_depth.197* 2. Determining if the device supports the various synchronous198* negotiation protocols. The device struct will already have199* responded to INQUIRY and the results of the standard items200* will have been shoved into the various device flag bits, eg.201* device->sdtr will be true if the device supports SDTR messages.202* 3. Allocating command structs that the device will need.203* 4. Setting the default timeout on this device (if needed).204* 5. Anything else the low level driver might want to do on a device205* specific setup basis...206* 6. Return 0 on success, non-0 on error. The device will be marked207* as offline on error so that no access will occur. If you return208* non-0, your sdev_destroy routine will never get called for this209* device, so don't leave any loose memory hanging around, clean210* up after yourself before returning non-0211*212* Status: OPTIONAL213*/214int (* sdev_configure)(struct scsi_device *, struct queue_limits *lim);215216/*217* Immediately prior to deallocating the device and after all activity218* has ceased the mid layer calls this point so that the low level219* driver may completely detach itself from the scsi device and vice220* versa. The low level driver is responsible for freeing any memory221* it allocated in the sdev_init or sdev_configure calls.222*223* Status: OPTIONAL224*/225void (* sdev_destroy)(struct scsi_device *);226227/*228* Before the mid layer attempts to scan for a new device attached229* to a target where no target currently exists, it will call this230* entry in your driver. Should your driver need to allocate any231* structs or perform any other init items in order to send commands232* to a currently unused target, then this is where you can perform233* those allocations.234*235* Return values: 0 on success, non-0 on failure236*237* Status: OPTIONAL238*/239int (* target_alloc)(struct scsi_target *);240241/*242* Immediately prior to deallocating the target structure, and243* after all activity to attached scsi devices has ceased, the244* midlayer calls this point so that the driver may deallocate245* and terminate any references to the target.246*247* Note: This callback is called with the host lock held and hence248* must not sleep.249*250* Status: OPTIONAL251*/252void (* target_destroy)(struct scsi_target *);253254/*255* If a host has the ability to discover targets on its own instead256* of scanning the entire bus, it can fill in this function and257* call scsi_scan_host(). This function will be called periodically258* until it returns 1 with the scsi_host and the elapsed time of259* the scan in jiffies.260*261* Status: OPTIONAL262*/263int (* scan_finished)(struct Scsi_Host *, unsigned long);264265/*266* If the host wants to be called before the scan starts, but267* after the midlayer has set up ready for the scan, it can fill268* in this function.269*270* Status: OPTIONAL271*/272void (* scan_start)(struct Scsi_Host *);273274/*275* Fill in this function to allow the queue depth of this host276* to be changeable (on a per device basis). Returns either277* the current queue depth setting (may be different from what278* was passed in) or an error. An error should only be279* returned if the requested depth is legal but the driver was280* unable to set it. If the requested depth is illegal, the281* driver should set and return the closest legal queue depth.282*283* Status: OPTIONAL284*/285int (* change_queue_depth)(struct scsi_device *, int);286287/*288* This functions lets the driver expose the queue mapping289* to the block layer.290*291* Status: OPTIONAL292*/293void (* map_queues)(struct Scsi_Host *shost);294295/*296* SCSI interface of blk_poll - poll for IO completions.297* Only applicable if SCSI LLD exposes multiple h/w queues.298*299* Return value: Number of completed entries found.300*301* Status: OPTIONAL302*/303int (* mq_poll)(struct Scsi_Host *shost, unsigned int queue_num);304305/*306* Check if scatterlists need to be padded for DMA draining.307*308* Status: OPTIONAL309*/310bool (* dma_need_drain)(struct request *rq);311312/*313* This function determines the BIOS parameters for a given314* harddisk. These tend to be numbers that are made up by315* the host adapter. Parameters:316* size, device, list (heads, sectors, cylinders)317*318* Status: OPTIONAL319*/320int (* bios_param)(struct scsi_device *, struct block_device *,321sector_t, int []);322323/*324* This function is called when one or more partitions on the325* device reach beyond the end of the device.326*327* Status: OPTIONAL328*/329void (*unlock_native_capacity)(struct scsi_device *);330331/*332* Can be used to export driver statistics and other infos to the333* world outside the kernel ie. userspace and it also provides an334* interface to feed the driver with information.335*336* Status: OBSOLETE337*/338int (*show_info)(struct seq_file *, struct Scsi_Host *);339int (*write_info)(struct Scsi_Host *, char *, int);340341/*342* This is an optional routine that allows the transport to become343* involved when a scsi io timer fires. The return value tells the344* timer routine how to finish the io timeout handling.345*346* Status: OPTIONAL347*/348enum scsi_timeout_action (*eh_timed_out)(struct scsi_cmnd *);349/*350* Optional routine that allows the transport to decide if a cmd351* is retryable. Return true if the transport is in a state the352* cmd should be retried on.353*/354bool (*eh_should_retry_cmd)(struct scsi_cmnd *scmd);355356/* This is an optional routine that allows transport to initiate357* LLD adapter or firmware reset using sysfs attribute.358*359* Return values: 0 on success, -ve value on failure.360*361* Status: OPTIONAL362*/363364int (*host_reset)(struct Scsi_Host *shost, int reset_type);365#define SCSI_ADAPTER_RESET 1366#define SCSI_FIRMWARE_RESET 2367368369/*370* Name of proc directory371*/372const char *proc_name;373374/*375* This determines if we will use a non-interrupt driven376* or an interrupt driven scheme. It is set to the maximum number377* of simultaneous commands a single hw queue in HBA will accept.378*/379int can_queue;380381/*382* In many instances, especially where disconnect / reconnect are383* supported, our host also has an ID on the SCSI bus. If this is384* the case, then it must be reserved. Please set this_id to -1 if385* your setup is in single initiator mode, and the host lacks an386* ID.387*/388int this_id;389390/*391* This determines the degree to which the host adapter is capable392* of scatter-gather.393*/394unsigned short sg_tablesize;395unsigned short sg_prot_tablesize;396397/*398* Set this if the host adapter has limitations beside segment count.399*/400unsigned int max_sectors;401402/*403* Maximum size in bytes of a single segment.404*/405unsigned int max_segment_size;406407unsigned int dma_alignment;408409/*410* DMA scatter gather segment boundary limit. A segment crossing this411* boundary will be split in two.412*/413unsigned long dma_boundary;414415unsigned long virt_boundary_mask;416417/*418* This specifies "machine infinity" for host templates which don't419* limit the transfer size. Note this limit represents an absolute420* maximum, and may be over the transfer limits allowed for421* individual devices (e.g. 256 for SCSI-1).422*/423#define SCSI_DEFAULT_MAX_SECTORS 1024424425/*426* True if this host adapter can make good use of linked commands.427* This will allow more than one command to be queued to a given428* unit on a given host. Set this to the maximum number of command429* blocks to be provided for each device. Set this to 1 for one430* command block per lun, 2 for two, etc. Do not set this to 0.431* You should make sure that the host adapter will do the right thing432* before you try setting this above 1.433*/434short cmd_per_lun;435436/*437* Allocate tags starting from last allocated tag.438*/439bool tag_alloc_policy_rr : 1;440441/*442* Track QUEUE_FULL events and reduce queue depth on demand.443*/444unsigned track_queue_depth:1;445446/*447* This specifies the mode that a LLD supports.448*/449unsigned supported_mode:2;450451/*452* True for emulated SCSI host adapters (e.g. ATAPI).453*/454unsigned emulated:1;455456/*457* True if the low-level driver performs its own reset-settle delays.458*/459unsigned skip_settle_delay:1;460461/* True if the controller does not support WRITE SAME */462unsigned no_write_same:1;463464/* True if the host uses host-wide tagspace */465unsigned host_tagset:1;466467/* The queuecommand callback may block. See also BLK_MQ_F_BLOCKING. */468unsigned queuecommand_may_block:1;469470/*471* Countdown for host blocking with no commands outstanding.472*/473unsigned int max_host_blocked;474475/*476* Default value for the blocking. If the queue is empty,477* host_blocked counts down in the request_fn until it restarts478* host operations as zero is reached.479*480* FIXME: This should probably be a value in the template481*/482#define SCSI_DEFAULT_HOST_BLOCKED 7483484/*485* Pointer to the SCSI host sysfs attribute groups, NULL terminated.486*/487const struct attribute_group **shost_groups;488489/*490* Pointer to the SCSI device attribute groups for this host,491* NULL terminated.492*/493const struct attribute_group **sdev_groups;494495/*496* Vendor Identifier associated with the host497*498* Note: When specifying vendor_id, be sure to read the499* Vendor Type and ID formatting requirements specified in500* scsi_netlink.h501*/502u64 vendor_id;503};504505/*506* Temporary #define for host lock push down. Can be removed when all507* drivers have been updated to take advantage of unlocked508* queuecommand.509*510*/511#define DEF_SCSI_QCMD(func_name) \512int func_name(struct Scsi_Host *shost, struct scsi_cmnd *cmd) \513{ \514unsigned long irq_flags; \515int rc; \516spin_lock_irqsave(shost->host_lock, irq_flags); \517rc = func_name##_lck(cmd); \518spin_unlock_irqrestore(shost->host_lock, irq_flags); \519return rc; \520}521522523/*524* shost state: If you alter this, you also need to alter scsi_sysfs.c525* (for the ascii descriptions) and the state model enforcer:526* scsi_host_set_state()527*/528enum scsi_host_state {529SHOST_CREATED = 1,530SHOST_RUNNING,531SHOST_CANCEL,532SHOST_DEL,533SHOST_RECOVERY,534SHOST_CANCEL_RECOVERY,535SHOST_DEL_RECOVERY,536};537538struct Scsi_Host {539/*540* __devices is protected by the host_lock, but you should541* usually use scsi_device_lookup / shost_for_each_device542* to access it and don't care about locking yourself.543* In the rare case of being in irq context you can use544* their __ prefixed variants with the lock held. NEVER545* access this list directly from a driver.546*/547struct list_head __devices;548struct list_head __targets;549550struct list_head starved_list;551552spinlock_t default_lock;553spinlock_t *host_lock;554555struct mutex scan_mutex;/* serialize scanning activity */556557struct list_head eh_abort_list;558struct list_head eh_cmd_q;559struct task_struct * ehandler; /* Error recovery thread. */560struct completion * eh_action; /* Wait for specific actions on the561host. */562wait_queue_head_t host_wait;563const struct scsi_host_template *hostt;564struct scsi_transport_template *transportt;565566struct kref tagset_refcnt;567struct completion tagset_freed;568/* Area to keep a shared tag map */569struct blk_mq_tag_set tag_set;570571atomic_t host_blocked;572573unsigned int host_failed; /* commands that failed.574protected by host_lock */575unsigned int host_eh_scheduled; /* EH scheduled without command */576577unsigned int host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */578579/* next two fields are used to bound the time spent in error handling */580int eh_deadline;581unsigned long last_reset;582583584/*585* These three parameters can be used to allow for wide scsi,586* and for host adapters that support multiple busses587* The last two should be set to 1 more than the actual max id588* or lun (e.g. 8 for SCSI parallel systems).589*/590unsigned int max_channel;591unsigned int max_id;592u64 max_lun;593594/*595* This is a unique identifier that must be assigned so that we596* have some way of identifying each detected host adapter properly597* and uniquely. For hosts that do not support more than one card598* in the system at one time, this does not need to be set. It is599* initialized to 0 in scsi_host_alloc.600*/601unsigned int unique_id;602603/*604* The maximum length of SCSI commands that this host can accept.605* Probably 12 for most host adapters, but could be 16 for others.606* or 260 if the driver supports variable length cdbs.607* For drivers that don't set this field, a value of 12 is608* assumed.609*/610unsigned short max_cmd_len;611612int this_id;613int can_queue;614short cmd_per_lun;615short unsigned int sg_tablesize;616short unsigned int sg_prot_tablesize;617unsigned int max_sectors;618unsigned int opt_sectors;619unsigned int max_segment_size;620unsigned int dma_alignment;621unsigned long dma_boundary;622unsigned long virt_boundary_mask;623/*624* In scsi-mq mode, the number of hardware queues supported by the LLD.625*626* Note: it is assumed that each hardware queue has a queue depth of627* can_queue. In other words, the total queue depth per host628* is nr_hw_queues * can_queue. However, for when host_tagset is set,629* the total queue depth is can_queue.630*/631unsigned nr_hw_queues;632unsigned nr_maps;633unsigned active_mode:2;634635/*636* Host has requested that no further requests come through for the637* time being.638*/639unsigned host_self_blocked:1;640641/*642* Host uses correct SCSI ordering not PC ordering. The bit is643* set for the minority of drivers whose authors actually read644* the spec ;).645*/646unsigned reverse_ordering:1;647648/* Task mgmt function in progress */649unsigned tmf_in_progress:1;650651/* Asynchronous scan in progress */652unsigned async_scan:1;653654/* Don't resume host in EH */655unsigned eh_noresume:1;656657/* The controller does not support WRITE SAME */658unsigned no_write_same:1;659660/* True if the host uses host-wide tagspace */661unsigned host_tagset:1;662663/* The queuecommand callback may block. See also BLK_MQ_F_BLOCKING. */664unsigned queuecommand_may_block:1;665666/* Host responded with short (<36 bytes) INQUIRY result */667unsigned short_inquiry:1;668669/* The transport requires the LUN bits NOT to be stored in CDB[1] */670unsigned no_scsi2_lun_in_cdb:1;671672/*673* Optional work queue to be utilized by the transport674*/675struct workqueue_struct *work_q;676677/*678* Task management function work queue679*/680struct workqueue_struct *tmf_work_q;681682/*683* Value host_blocked counts down from684*/685unsigned int max_host_blocked;686687/* Protection Information */688unsigned int prot_capabilities;689unsigned char prot_guard_type;690691/* legacy crap */692unsigned long base;693unsigned long io_port;694unsigned char n_io_port;695unsigned char dma_channel;696unsigned int irq;697698699enum scsi_host_state shost_state;700701/* ldm bits */702struct device shost_gendev, shost_dev;703704/*705* Points to the transport data (if any) which is allocated706* separately707*/708void *shost_data;709710/*711* Points to the physical bus device we'd use to do DMA712* Needed just in case we have virtual hosts.713*/714struct device *dma_dev;715716/* Delay for runtime autosuspend */717int rpm_autosuspend_delay;718719/*720* We should ensure that this is aligned, both for better performance721* and also because some compilers (m68k) don't automatically force722* alignment to a long boundary.723*/724unsigned long hostdata[] /* Used for storage of host specific stuff */725__attribute__ ((aligned (sizeof(unsigned long))));726};727728#define class_to_shost(d) \729container_of(d, struct Scsi_Host, shost_dev)730731#define shost_printk(prefix, shost, fmt, a...) \732dev_printk(prefix, &(shost)->shost_gendev, fmt, ##a)733734static inline void *shost_priv(struct Scsi_Host *shost)735{736return (void *)shost->hostdata;737}738739int scsi_is_host_device(const struct device *);740741static inline struct Scsi_Host *dev_to_shost(struct device *dev)742{743while (!scsi_is_host_device(dev)) {744if (!dev->parent)745return NULL;746dev = dev->parent;747}748return container_of(dev, struct Scsi_Host, shost_gendev);749}750751static inline int scsi_host_in_recovery(struct Scsi_Host *shost)752{753return shost->shost_state == SHOST_RECOVERY ||754shost->shost_state == SHOST_CANCEL_RECOVERY ||755shost->shost_state == SHOST_DEL_RECOVERY ||756shost->tmf_in_progress;757}758759extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);760extern void scsi_flush_work(struct Scsi_Host *);761762extern struct Scsi_Host *scsi_host_alloc(const struct scsi_host_template *, int);763extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *,764struct device *,765struct device *);766#if defined(CONFIG_SCSI_PROC_FS)767struct proc_dir_entry *768scsi_template_proc_dir(const struct scsi_host_template *sht);769#else770#define scsi_template_proc_dir(sht) NULL771#endif772extern void scsi_scan_host(struct Scsi_Host *);773extern int scsi_resume_device(struct scsi_device *sdev);774extern int scsi_rescan_device(struct scsi_device *sdev);775extern void scsi_remove_host(struct Scsi_Host *);776extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);777extern int scsi_host_busy(struct Scsi_Host *shost);778extern void scsi_host_put(struct Scsi_Host *t);779extern struct Scsi_Host *scsi_host_lookup(unsigned int hostnum);780extern const char *scsi_host_state_name(enum scsi_host_state);781extern void scsi_host_complete_all_commands(struct Scsi_Host *shost,782enum scsi_host_status status);783784static inline int __must_check scsi_add_host(struct Scsi_Host *host,785struct device *dev)786{787return scsi_add_host_with_dma(host, dev, dev);788}789790static inline struct device *scsi_get_device(struct Scsi_Host *shost)791{792return shost->shost_gendev.parent;793}794795/**796* scsi_host_scan_allowed - Is scanning of this host allowed797* @shost: Pointer to Scsi_Host.798**/799static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)800{801return shost->shost_state == SHOST_RUNNING ||802shost->shost_state == SHOST_RECOVERY;803}804805extern void scsi_unblock_requests(struct Scsi_Host *);806extern void scsi_block_requests(struct Scsi_Host *);807extern int scsi_host_block(struct Scsi_Host *shost);808extern int scsi_host_unblock(struct Scsi_Host *shost, int new_state);809810void scsi_host_busy_iter(struct Scsi_Host *,811bool (*fn)(struct scsi_cmnd *, void *), void *priv);812813struct class_container;814815/*816* DIF defines the exchange of protection information between817* initiator and SBC block device.818*819* DIX defines the exchange of protection information between OS and820* initiator.821*/822enum scsi_host_prot_capabilities {823SHOST_DIF_TYPE1_PROTECTION = 1 << 0, /* T10 DIF Type 1 */824SHOST_DIF_TYPE2_PROTECTION = 1 << 1, /* T10 DIF Type 2 */825SHOST_DIF_TYPE3_PROTECTION = 1 << 2, /* T10 DIF Type 3 */826827SHOST_DIX_TYPE0_PROTECTION = 1 << 3, /* DIX between OS and HBA only */828SHOST_DIX_TYPE1_PROTECTION = 1 << 4, /* DIX with DIF Type 1 */829SHOST_DIX_TYPE2_PROTECTION = 1 << 5, /* DIX with DIF Type 2 */830SHOST_DIX_TYPE3_PROTECTION = 1 << 6, /* DIX with DIF Type 3 */831};832833/*834* SCSI hosts which support the Data Integrity Extensions must835* indicate their capabilities by setting the prot_capabilities using836* this call.837*/838static inline void scsi_host_set_prot(struct Scsi_Host *shost, unsigned int mask)839{840shost->prot_capabilities = mask;841}842843static inline unsigned int scsi_host_get_prot(struct Scsi_Host *shost)844{845return shost->prot_capabilities;846}847848static inline int scsi_host_prot_dma(struct Scsi_Host *shost)849{850return shost->prot_capabilities >= SHOST_DIX_TYPE0_PROTECTION;851}852853static inline unsigned int scsi_host_dif_capable(struct Scsi_Host *shost, unsigned int target_type)854{855static unsigned char cap[] = { 0,856SHOST_DIF_TYPE1_PROTECTION,857SHOST_DIF_TYPE2_PROTECTION,858SHOST_DIF_TYPE3_PROTECTION };859860if (target_type >= ARRAY_SIZE(cap))861return 0;862863return shost->prot_capabilities & cap[target_type] ? target_type : 0;864}865866static inline unsigned int scsi_host_dix_capable(struct Scsi_Host *shost, unsigned int target_type)867{868#if defined(CONFIG_BLK_DEV_INTEGRITY)869static unsigned char cap[] = { SHOST_DIX_TYPE0_PROTECTION,870SHOST_DIX_TYPE1_PROTECTION,871SHOST_DIX_TYPE2_PROTECTION,872SHOST_DIX_TYPE3_PROTECTION };873874if (target_type >= ARRAY_SIZE(cap))875return 0;876877return shost->prot_capabilities & cap[target_type];878#endif879return 0;880}881882/*883* All DIX-capable initiators must support the T10-mandated CRC884* checksum. Controllers can optionally implement the IP checksum885* scheme which has much lower impact on system performance. Note886* that the main rationale for the checksum is to match integrity887* metadata with data. Detecting bit errors are a job for ECC memory888* and buses.889*/890891enum scsi_host_guard_type {892SHOST_DIX_GUARD_CRC = 1 << 0,893SHOST_DIX_GUARD_IP = 1 << 1,894};895896static inline void scsi_host_set_guard(struct Scsi_Host *shost, unsigned char type)897{898shost->prot_guard_type = type;899}900901static inline unsigned char scsi_host_get_guard(struct Scsi_Host *shost)902{903return shost->prot_guard_type;904}905906extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);907908#endif /* _SCSI_SCSI_HOST_H */909910911