#ifndef _SCSI_SCSI_HOST_H1#define _SCSI_SCSI_HOST_H23#include <linux/device.h>4#include <linux/list.h>5#include <linux/types.h>6#include <linux/workqueue.h>7#include <linux/mutex.h>8#include <scsi/scsi.h>910struct request_queue;11struct block_device;12struct completion;13struct module;14struct scsi_cmnd;15struct scsi_device;16struct scsi_target;17struct Scsi_Host;18struct scsi_host_cmd_pool;19struct scsi_transport_template;20struct blk_queue_tags;212223/*24* The various choices mean:25* NONE: Self evident. Host adapter is not capable of scatter-gather.26* ALL: Means that the host adapter module can do scatter-gather,27* and that there is no limit to the size of the table to which28* we scatter/gather data. The value we set here is the maximum29* single element sglist. To use chained sglists, the adapter30* has to set a value beyond ALL (and correctly use the chain31* handling API.32* Anything else: Indicates the maximum number of chains that can be33* used in one scatter-gather request.34*/35#define SG_NONE 036#define SG_ALL SCSI_MAX_SG_SEGMENTS3738#define MODE_UNKNOWN 0x0039#define MODE_INITIATOR 0x0140#define MODE_TARGET 0x024142#define DISABLE_CLUSTERING 043#define ENABLE_CLUSTERING 14445enum {46SCSI_QDEPTH_DEFAULT, /* default requested change, e.g. from sysfs */47SCSI_QDEPTH_QFULL, /* scsi-ml requested due to queue full */48SCSI_QDEPTH_RAMP_UP, /* scsi-ml requested due to threshold event */49};5051struct scsi_host_template {52struct module *module;53const char *name;5455/*56* Used to initialize old-style drivers. For new-style drivers57* just perform all work in your module initialization function.58*59* Status: OBSOLETE60*/61int (* detect)(struct scsi_host_template *);6263/*64* Used as unload callback for hosts with old-style drivers.65*66* Status: OBSOLETE67*/68int (* release)(struct Scsi_Host *);6970/*71* The info function will return whatever useful information the72* developer sees fit. If not provided, then the name field will73* be used instead.74*75* Status: OPTIONAL76*/77const char *(* info)(struct Scsi_Host *);7879/*80* Ioctl interface81*82* Status: OPTIONAL83*/84int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg);858687#ifdef CONFIG_COMPAT88/*89* Compat handler. Handle 32bit ABI.90* When unknown ioctl is passed return -ENOIOCTLCMD.91*92* Status: OPTIONAL93*/94int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg);95#endif9697/*98* The queuecommand function is used to queue up a scsi99* command block to the LLDD. When the driver finished100* processing the command the done callback is invoked.101*102* If queuecommand returns 0, then the HBA has accepted the103* command. The done() function must be called on the command104* when the driver has finished with it. (you may call done on the105* command before queuecommand returns, but in this case you106* *must* return 0 from queuecommand).107*108* Queuecommand may also reject the command, in which case it may109* not touch the command and must not call done() for it.110*111* There are two possible rejection returns:112*113* SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but114* allow commands to other devices serviced by this host.115*116* SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this117* host temporarily.118*119* For compatibility, any other non-zero return is treated the120* same as SCSI_MLQUEUE_HOST_BUSY.121*122* NOTE: "temporarily" means either until the next command for#123* this device/host completes, or a period of time determined by124* I/O pressure in the system if there are no other outstanding125* commands.126*127* STATUS: REQUIRED128*/129int (* queuecommand)(struct Scsi_Host *, struct scsi_cmnd *);130131/*132* The transfer functions are used to queue a scsi command to133* the LLD. When the driver is finished processing the command134* the done callback is invoked.135*136* This is called to inform the LLD to transfer137* scsi_bufflen(cmd) bytes. scsi_sg_count(cmd) speciefies the138* number of scatterlist entried in the command and139* scsi_sglist(cmd) returns the scatterlist.140*141* return values: see queuecommand142*143* If the LLD accepts the cmd, it should set the result to an144* appropriate value when completed before calling the done function.145*146* STATUS: REQUIRED FOR TARGET DRIVERS147*/148/* TODO: rename */149int (* transfer_response)(struct scsi_cmnd *,150void (*done)(struct scsi_cmnd *));151152/*153* This is an error handling strategy routine. You don't need to154* define one of these if you don't want to - there is a default155* routine that is present that should work in most cases. For those156* driver authors that have the inclination and ability to write their157* own strategy routine, this is where it is specified. Note - the158* strategy routine is *ALWAYS* run in the context of the kernel eh159* thread. Thus you are guaranteed to *NOT* be in an interrupt160* handler when you execute this, and you are also guaranteed to161* *NOT* have any other commands being queued while you are in the162* strategy routine. When you return from this function, operations163* return to normal.164*165* See scsi_error.c scsi_unjam_host for additional comments about166* what this function should and should not be attempting to do.167*168* Status: REQUIRED (at least one of them)169*/170int (* eh_abort_handler)(struct scsi_cmnd *);171int (* eh_device_reset_handler)(struct scsi_cmnd *);172int (* eh_target_reset_handler)(struct scsi_cmnd *);173int (* eh_bus_reset_handler)(struct scsi_cmnd *);174int (* eh_host_reset_handler)(struct scsi_cmnd *);175176/*177* Before the mid layer attempts to scan for a new device where none178* currently exists, it will call this entry in your driver. Should179* your driver need to allocate any structs or perform any other init180* items in order to send commands to a currently unused target/lun181* combo, then this is where you can perform those allocations. This182* is specifically so that drivers won't have to perform any kind of183* "is this a new device" checks in their queuecommand routine,184* thereby making the hot path a bit quicker.185*186* Return values: 0 on success, non-0 on failure187*188* Deallocation: If we didn't find any devices at this ID, you will189* get an immediate call to slave_destroy(). If we find something190* here then you will get a call to slave_configure(), then the191* device will be used for however long it is kept around, then when192* the device is removed from the system (or * possibly at reboot193* time), you will then get a call to slave_destroy(). This is194* assuming you implement slave_configure and slave_destroy.195* However, if you allocate memory and hang it off the device struct,196* then you must implement the slave_destroy() routine at a minimum197* in order to avoid leaking memory198* each time a device is tore down.199*200* Status: OPTIONAL201*/202int (* slave_alloc)(struct scsi_device *);203204/*205* Once the device has responded to an INQUIRY and we know the206* device is online, we call into the low level driver with the207* struct scsi_device *. If the low level device driver implements208* this function, it *must* perform the task of setting the queue209* depth on the device. All other tasks are optional and depend210* on what the driver supports and various implementation details.211*212* Things currently recommended to be handled at this time include:213*214* 1. Setting the device queue depth. Proper setting of this is215* described in the comments for scsi_adjust_queue_depth.216* 2. Determining if the device supports the various synchronous217* negotiation protocols. The device struct will already have218* responded to INQUIRY and the results of the standard items219* will have been shoved into the various device flag bits, eg.220* device->sdtr will be true if the device supports SDTR messages.221* 3. Allocating command structs that the device will need.222* 4. Setting the default timeout on this device (if needed).223* 5. Anything else the low level driver might want to do on a device224* specific setup basis...225* 6. Return 0 on success, non-0 on error. The device will be marked226* as offline on error so that no access will occur. If you return227* non-0, your slave_destroy routine will never get called for this228* device, so don't leave any loose memory hanging around, clean229* up after yourself before returning non-0230*231* Status: OPTIONAL232*/233int (* slave_configure)(struct scsi_device *);234235/*236* Immediately prior to deallocating the device and after all activity237* has ceased the mid layer calls this point so that the low level238* driver may completely detach itself from the scsi device and vice239* versa. The low level driver is responsible for freeing any memory240* it allocated in the slave_alloc or slave_configure calls.241*242* Status: OPTIONAL243*/244void (* slave_destroy)(struct scsi_device *);245246/*247* Before the mid layer attempts to scan for a new device attached248* to a target where no target currently exists, it will call this249* entry in your driver. Should your driver need to allocate any250* structs or perform any other init items in order to send commands251* to a currently unused target, then this is where you can perform252* those allocations.253*254* Return values: 0 on success, non-0 on failure255*256* Status: OPTIONAL257*/258int (* target_alloc)(struct scsi_target *);259260/*261* Immediately prior to deallocating the target structure, and262* after all activity to attached scsi devices has ceased, the263* midlayer calls this point so that the driver may deallocate264* and terminate any references to the target.265*266* Status: OPTIONAL267*/268void (* target_destroy)(struct scsi_target *);269270/*271* If a host has the ability to discover targets on its own instead272* of scanning the entire bus, it can fill in this function and273* call scsi_scan_host(). This function will be called periodically274* until it returns 1 with the scsi_host and the elapsed time of275* the scan in jiffies.276*277* Status: OPTIONAL278*/279int (* scan_finished)(struct Scsi_Host *, unsigned long);280281/*282* If the host wants to be called before the scan starts, but283* after the midlayer has set up ready for the scan, it can fill284* in this function.285*286* Status: OPTIONAL287*/288void (* scan_start)(struct Scsi_Host *);289290/*291* Fill in this function to allow the queue depth of this host292* to be changeable (on a per device basis). Returns either293* the current queue depth setting (may be different from what294* was passed in) or an error. An error should only be295* returned if the requested depth is legal but the driver was296* unable to set it. If the requested depth is illegal, the297* driver should set and return the closest legal queue depth.298*299* Status: OPTIONAL300*/301int (* change_queue_depth)(struct scsi_device *, int, int);302303/*304* Fill in this function to allow the changing of tag types305* (this also allows the enabling/disabling of tag command306* queueing). An error should only be returned if something307* went wrong in the driver while trying to set the tag type.308* If the driver doesn't support the requested tag type, then309* it should set the closest type it does support without310* returning an error. Returns the actual tag type set.311*312* Status: OPTIONAL313*/314int (* change_queue_type)(struct scsi_device *, int);315316/*317* This function determines the BIOS parameters for a given318* harddisk. These tend to be numbers that are made up by319* the host adapter. Parameters:320* size, device, list (heads, sectors, cylinders)321*322* Status: OPTIONAL323*/324int (* bios_param)(struct scsi_device *, struct block_device *,325sector_t, int []);326327/*328* This function is called when one or more partitions on the329* device reach beyond the end of the device.330*331* Status: OPTIONAL332*/333void (*unlock_native_capacity)(struct scsi_device *);334335/*336* Can be used to export driver statistics and other infos to the337* world outside the kernel ie. userspace and it also provides an338* interface to feed the driver with information.339*340* Status: OBSOLETE341*/342int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);343344/*345* This is an optional routine that allows the transport to become346* involved when a scsi io timer fires. The return value tells the347* timer routine how to finish the io timeout handling:348* EH_HANDLED: I fixed the error, please complete the command349* EH_RESET_TIMER: I need more time, reset the timer and350* begin counting again351* EH_NOT_HANDLED Begin normal error recovery352*353* Status: OPTIONAL354*/355enum blk_eh_timer_return (*eh_timed_out)(struct scsi_cmnd *);356357/*358* Name of proc directory359*/360const char *proc_name;361362/*363* Used to store the procfs directory if a driver implements the364* proc_info method.365*/366struct proc_dir_entry *proc_dir;367368/*369* This determines if we will use a non-interrupt driven370* or an interrupt driven scheme. It is set to the maximum number371* of simultaneous commands a given host adapter will accept.372*/373int can_queue;374375/*376* In many instances, especially where disconnect / reconnect are377* supported, our host also has an ID on the SCSI bus. If this is378* the case, then it must be reserved. Please set this_id to -1 if379* your setup is in single initiator mode, and the host lacks an380* ID.381*/382int this_id;383384/*385* This determines the degree to which the host adapter is capable386* of scatter-gather.387*/388unsigned short sg_tablesize;389unsigned short sg_prot_tablesize;390391/*392* Set this if the host adapter has limitations beside segment count.393*/394unsigned short max_sectors;395396/*397* DMA scatter gather segment boundary limit. A segment crossing this398* boundary will be split in two.399*/400unsigned long dma_boundary;401402/*403* This specifies "machine infinity" for host templates which don't404* limit the transfer size. Note this limit represents an absolute405* maximum, and may be over the transfer limits allowed for406* individual devices (e.g. 256 for SCSI-1).407*/408#define SCSI_DEFAULT_MAX_SECTORS 1024409410/*411* True if this host adapter can make good use of linked commands.412* This will allow more than one command to be queued to a given413* unit on a given host. Set this to the maximum number of command414* blocks to be provided for each device. Set this to 1 for one415* command block per lun, 2 for two, etc. Do not set this to 0.416* You should make sure that the host adapter will do the right thing417* before you try setting this above 1.418*/419short cmd_per_lun;420421/*422* present contains counter indicating how many boards of this423* type were found when we did the scan.424*/425unsigned char present;426427/*428* This specifies the mode that a LLD supports.429*/430unsigned supported_mode:2;431432/*433* True if this host adapter uses unchecked DMA onto an ISA bus.434*/435unsigned unchecked_isa_dma:1;436437/*438* True if this host adapter can make good use of clustering.439* I originally thought that if the tablesize was large that it440* was a waste of CPU cycles to prepare a cluster list, but441* it works out that the Buslogic is faster if you use a smaller442* number of segments (i.e. use clustering). I guess it is443* inefficient.444*/445unsigned use_clustering:1;446447/*448* True for emulated SCSI host adapters (e.g. ATAPI).449*/450unsigned emulated:1;451452/*453* True if the low-level driver performs its own reset-settle delays.454*/455unsigned skip_settle_delay:1;456457/*458* True if we are using ordered write support.459*/460unsigned ordered_tag:1;461462/*463* Countdown for host blocking with no commands outstanding.464*/465unsigned int max_host_blocked;466467/*468* Default value for the blocking. If the queue is empty,469* host_blocked counts down in the request_fn until it restarts470* host operations as zero is reached.471*472* FIXME: This should probably be a value in the template473*/474#define SCSI_DEFAULT_HOST_BLOCKED 7475476/*477* Pointer to the sysfs class properties for this host, NULL terminated.478*/479struct device_attribute **shost_attrs;480481/*482* Pointer to the SCSI device properties for this host, NULL terminated.483*/484struct device_attribute **sdev_attrs;485486/*487* List of hosts per template.488*489* This is only for use by scsi_module.c for legacy templates.490* For these access to it is synchronized implicitly by491* module_init/module_exit.492*/493struct list_head legacy_hosts;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); \517scsi_cmd_get_serial(shost, cmd); \518rc = func_name##_lck (cmd, cmd->scsi_done); \519spin_unlock_irqrestore(shost->host_lock, irq_flags); \520return rc; \521}522523524/*525* shost state: If you alter this, you also need to alter scsi_sysfs.c526* (for the ascii descriptions) and the state model enforcer:527* scsi_host_set_state()528*/529enum scsi_host_state {530SHOST_CREATED = 1,531SHOST_RUNNING,532SHOST_CANCEL,533SHOST_DEL,534SHOST_RECOVERY,535SHOST_CANCEL_RECOVERY,536SHOST_DEL_RECOVERY,537};538539struct Scsi_Host {540/*541* __devices is protected by the host_lock, but you should542* usually use scsi_device_lookup / shost_for_each_device543* to access it and don't care about locking yourself.544* In the rare case of beeing in irq context you can use545* their __ prefixed variants with the lock held. NEVER546* access this list directly from a driver.547*/548struct list_head __devices;549struct list_head __targets;550551struct scsi_host_cmd_pool *cmd_pool;552spinlock_t free_list_lock;553struct list_head free_list; /* backup store of cmd structs */554struct list_head starved_list;555556spinlock_t default_lock;557spinlock_t *host_lock;558559struct mutex scan_mutex;/* serialize scanning activity */560561struct list_head eh_cmd_q;562struct task_struct * ehandler; /* Error recovery thread. */563struct completion * eh_action; /* Wait for specific actions on the564host. */565wait_queue_head_t host_wait;566struct scsi_host_template *hostt;567struct scsi_transport_template *transportt;568569/*570* Area to keep a shared tag map (if needed, will be571* NULL if not).572*/573struct blk_queue_tag *bqt;574575/*576* The following two fields are protected with host_lock;577* however, eh routines can safely access during eh processing578* without acquiring the lock.579*/580unsigned int host_busy; /* commands actually active on low-level */581unsigned int host_failed; /* commands that failed. */582unsigned int host_eh_scheduled; /* EH scheduled without command */583584unsigned int host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */585int resetting; /* if set, it means that last_reset is a valid value */586unsigned long last_reset;587588/*589* These three parameters can be used to allow for wide scsi,590* and for host adapters that support multiple busses591* The first two should be set to 1 more than the actual max id592* or lun (i.e. 8 for normal systems).593*/594unsigned int max_id;595unsigned int max_lun;596unsigned int max_channel;597598/*599* This is a unique identifier that must be assigned so that we600* have some way of identifying each detected host adapter properly601* and uniquely. For hosts that do not support more than one card602* in the system at one time, this does not need to be set. It is603* initialized to 0 in scsi_register.604*/605unsigned int unique_id;606607/*608* The maximum length of SCSI commands that this host can accept.609* Probably 12 for most host adapters, but could be 16 for others.610* or 260 if the driver supports variable length cdbs.611* For drivers that don't set this field, a value of 12 is612* assumed.613*/614unsigned short max_cmd_len;615616int this_id;617int can_queue;618short cmd_per_lun;619short unsigned int sg_tablesize;620short unsigned int sg_prot_tablesize;621short unsigned int max_sectors;622unsigned long dma_boundary;623/*624* Used to assign serial numbers to the cmds.625* Protected by the host lock.626*/627unsigned long cmd_serial_number;628629unsigned active_mode:2;630unsigned unchecked_isa_dma:1;631unsigned use_clustering:1;632unsigned use_blk_tcq:1;633634/*635* Host has requested that no further requests come through for the636* time being.637*/638unsigned host_self_blocked:1;639640/*641* Host uses correct SCSI ordering not PC ordering. The bit is642* set for the minority of drivers whose authors actually read643* the spec ;).644*/645unsigned reverse_ordering:1;646647/*648* Ordered write support649*/650unsigned ordered_tag:1;651652/* Task mgmt function in progress */653unsigned tmf_in_progress:1;654655/* Asynchronous scan in progress */656unsigned async_scan:1;657658/*659* Optional work queue to be utilized by the transport660*/661char work_q_name[20];662struct workqueue_struct *work_q;663664/*665* Host has rejected a command because it was busy.666*/667unsigned int host_blocked;668669/*670* Value host_blocked counts down from671*/672unsigned int max_host_blocked;673674/* Protection Information */675unsigned int prot_capabilities;676unsigned char prot_guard_type;677678/*679* q used for scsi_tgt msgs, async events or any other requests that680* need to be processed in userspace681*/682struct request_queue *uspace_req_q;683684/* legacy crap */685unsigned long base;686unsigned long io_port;687unsigned char n_io_port;688unsigned char dma_channel;689unsigned int irq;690691692enum scsi_host_state shost_state;693694/* ldm bits */695struct device shost_gendev, shost_dev;696697/*698* List of hosts per template.699*700* This is only for use by scsi_module.c for legacy templates.701* For these access to it is synchronized implicitly by702* module_init/module_exit.703*/704struct list_head sht_legacy_list;705706/*707* Points to the transport data (if any) which is allocated708* separately709*/710void *shost_data;711712/*713* Points to the physical bus device we'd use to do DMA714* Needed just in case we have virtual hosts.715*/716struct device *dma_dev;717718/*719* We should ensure that this is aligned, both for better performance720* and also because some compilers (m68k) don't automatically force721* alignment to a long boundary.722*/723unsigned long hostdata[0] /* Used for storage of host specific stuff */724__attribute__ ((aligned (sizeof(unsigned long))));725};726727#define class_to_shost(d) \728container_of(d, struct Scsi_Host, shost_dev)729730#define shost_printk(prefix, shost, fmt, a...) \731dev_printk(prefix, &(shost)->shost_gendev, fmt, ##a)732733static inline void *shost_priv(struct Scsi_Host *shost)734{735return (void *)shost->hostdata;736}737738int scsi_is_host_device(const struct device *);739740static inline struct Scsi_Host *dev_to_shost(struct device *dev)741{742while (!scsi_is_host_device(dev)) {743if (!dev->parent)744return NULL;745dev = dev->parent;746}747return container_of(dev, struct Scsi_Host, shost_gendev);748}749750static inline int scsi_host_in_recovery(struct Scsi_Host *shost)751{752return shost->shost_state == SHOST_RECOVERY ||753shost->shost_state == SHOST_CANCEL_RECOVERY ||754shost->shost_state == SHOST_DEL_RECOVERY ||755shost->tmf_in_progress;756}757758extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);759extern void scsi_flush_work(struct Scsi_Host *);760761extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);762extern int __must_check scsi_add_host_with_dma(struct Scsi_Host *,763struct device *,764struct device *);765extern void scsi_scan_host(struct Scsi_Host *);766extern void scsi_rescan_device(struct device *);767extern void scsi_remove_host(struct Scsi_Host *);768extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);769extern void scsi_host_put(struct Scsi_Host *t);770extern struct Scsi_Host *scsi_host_lookup(unsigned short);771extern const char *scsi_host_state_name(enum scsi_host_state);772extern void scsi_cmd_get_serial(struct Scsi_Host *, struct scsi_cmnd *);773774extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);775776static inline int __must_check scsi_add_host(struct Scsi_Host *host,777struct device *dev)778{779return scsi_add_host_with_dma(host, dev, dev);780}781782static inline struct device *scsi_get_device(struct Scsi_Host *shost)783{784return shost->shost_gendev.parent;785}786787/**788* scsi_host_scan_allowed - Is scanning of this host allowed789* @shost: Pointer to Scsi_Host.790**/791static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)792{793return shost->shost_state == SHOST_RUNNING;794}795796extern void scsi_unblock_requests(struct Scsi_Host *);797extern void scsi_block_requests(struct Scsi_Host *);798799struct class_container;800801extern struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,802void (*) (struct request_queue *));803/*804* These two functions are used to allocate and free a pseudo device805* which will connect to the host adapter itself rather than any806* physical device. You must deallocate when you are done with the807* thing. This physical pseudo-device isn't real and won't be available808* from any high-level drivers.809*/810extern void scsi_free_host_dev(struct scsi_device *);811extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);812813/*814* DIF defines the exchange of protection information between815* initiator and SBC block device.816*817* DIX defines the exchange of protection information between OS and818* initiator.819*/820enum scsi_host_prot_capabilities {821SHOST_DIF_TYPE1_PROTECTION = 1 << 0, /* T10 DIF Type 1 */822SHOST_DIF_TYPE2_PROTECTION = 1 << 1, /* T10 DIF Type 2 */823SHOST_DIF_TYPE3_PROTECTION = 1 << 2, /* T10 DIF Type 3 */824825SHOST_DIX_TYPE0_PROTECTION = 1 << 3, /* DIX between OS and HBA only */826SHOST_DIX_TYPE1_PROTECTION = 1 << 4, /* DIX with DIF Type 1 */827SHOST_DIX_TYPE2_PROTECTION = 1 << 5, /* DIX with DIF Type 2 */828SHOST_DIX_TYPE3_PROTECTION = 1 << 6, /* DIX with DIF Type 3 */829};830831/*832* SCSI hosts which support the Data Integrity Extensions must833* indicate their capabilities by setting the prot_capabilities using834* this call.835*/836static inline void scsi_host_set_prot(struct Scsi_Host *shost, unsigned int mask)837{838shost->prot_capabilities = mask;839}840841static inline unsigned int scsi_host_get_prot(struct Scsi_Host *shost)842{843return shost->prot_capabilities;844}845846static inline int scsi_host_prot_dma(struct Scsi_Host *shost)847{848return shost->prot_capabilities >= SHOST_DIX_TYPE0_PROTECTION;849}850851static inline unsigned int scsi_host_dif_capable(struct Scsi_Host *shost, unsigned int target_type)852{853static unsigned char cap[] = { 0,854SHOST_DIF_TYPE1_PROTECTION,855SHOST_DIF_TYPE2_PROTECTION,856SHOST_DIF_TYPE3_PROTECTION };857858return shost->prot_capabilities & cap[target_type] ? target_type : 0;859}860861static inline unsigned int scsi_host_dix_capable(struct Scsi_Host *shost, unsigned int target_type)862{863#if defined(CONFIG_BLK_DEV_INTEGRITY)864static unsigned char cap[] = { SHOST_DIX_TYPE0_PROTECTION,865SHOST_DIX_TYPE1_PROTECTION,866SHOST_DIX_TYPE2_PROTECTION,867SHOST_DIX_TYPE3_PROTECTION };868869return shost->prot_capabilities & cap[target_type];870#endif871return 0;872}873874/*875* All DIX-capable initiators must support the T10-mandated CRC876* checksum. Controllers can optionally implement the IP checksum877* scheme which has much lower impact on system performance. Note878* that the main rationale for the checksum is to match integrity879* metadata with data. Detecting bit errors are a job for ECC memory880* and buses.881*/882883enum scsi_host_guard_type {884SHOST_DIX_GUARD_CRC = 1 << 0,885SHOST_DIX_GUARD_IP = 1 << 1,886};887888static inline void scsi_host_set_guard(struct Scsi_Host *shost, unsigned char type)889{890shost->prot_guard_type = type;891}892893static inline unsigned char scsi_host_get_guard(struct Scsi_Host *shost)894{895return shost->prot_guard_type;896}897898/* legacy interfaces */899extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);900extern void scsi_unregister(struct Scsi_Host *);901extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);902903#endif /* _SCSI_SCSI_HOST_H */904905906