kbuild: whitelist logo references from .text to .init.data
[pv_ops_mirror.git] / include / scsi / scsi_host.h
blob7f1f411d07af04c47f1faf7ce6400b57c197fef2
1 #ifndef _SCSI_SCSI_HOST_H
2 #define _SCSI_SCSI_HOST_H
4 #include <linux/device.h>
5 #include <linux/list.h>
6 #include <linux/types.h>
7 #include <linux/workqueue.h>
8 #include <linux/mutex.h>
10 struct request_queue;
11 struct block_device;
12 struct completion;
13 struct module;
14 struct scsi_cmnd;
15 struct scsi_device;
16 struct scsi_target;
17 struct Scsi_Host;
18 struct scsi_host_cmd_pool;
19 struct scsi_transport_template;
20 struct blk_queue_tags;
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 which
28 * we scatter/gather data.
29 * Anything else: Indicates the maximum number of chains that can be
30 * used in one scatter-gather request.
32 #define SG_NONE 0
33 #define SG_ALL 0xff
36 #define DISABLE_CLUSTERING 0
37 #define ENABLE_CLUSTERING 1
39 enum scsi_eh_timer_return {
40 EH_NOT_HANDLED,
41 EH_HANDLED,
42 EH_RESET_TIMER,
46 struct scsi_host_template {
47 struct module *module;
48 const char *name;
51 * Used to initialize old-style drivers. For new-style drivers
52 * just perform all work in your module initialization function.
54 * Status: OBSOLETE
56 int (* detect)(struct scsi_host_template *);
59 * Used as unload callback for hosts with old-style drivers.
61 * Status: OBSOLETE
63 int (* release)(struct Scsi_Host *);
66 * The info function will return whatever useful information the
67 * developer sees fit. If not provided, then the name field will
68 * be used instead.
70 * Status: OPTIONAL
72 const char *(* info)(struct Scsi_Host *);
75 * Ioctl interface
77 * Status: OPTIONAL
79 int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
82 #ifdef CONFIG_COMPAT
83 /*
84 * Compat handler. Handle 32bit ABI.
85 * When unknown ioctl is passed return -ENOIOCTLCMD.
87 * Status: OPTIONAL
89 int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
90 #endif
93 * The queuecommand function is used to queue up a scsi
94 * command block to the LLDD. When the driver finished
95 * processing the command the done callback is invoked.
97 * If queuecommand returns 0, then the HBA has accepted the
98 * command. The done() function must be called on the command
99 * when the driver has finished with it. (you may call done on the
100 * command before queuecommand returns, but in this case you
101 * *must* return 0 from queuecommand).
103 * Queuecommand may also reject the command, in which case it may
104 * not touch the command and must not call done() for it.
106 * There are two possible rejection returns:
108 * SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but
109 * allow commands to other devices serviced by this host.
111 * SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this
112 * host temporarily.
114 * For compatibility, any other non-zero return is treated the
115 * same as SCSI_MLQUEUE_HOST_BUSY.
117 * NOTE: "temporarily" means either until the next command for#
118 * this device/host completes, or a period of time determined by
119 * I/O pressure in the system if there are no other outstanding
120 * commands.
122 * STATUS: REQUIRED
124 int (* queuecommand)(struct scsi_cmnd *,
125 void (*done)(struct scsi_cmnd *));
128 * The transfer functions are used to queue a scsi command to
129 * the LLD. When the driver is finished processing the command
130 * the done callback is invoked.
132 * return values: see queuecommand
134 * If the LLD accepts the cmd, it should set the result to an
135 * appropriate value when completed before calling the done function.
137 * STATUS: REQUIRED FOR TARGET DRIVERS
139 /* TODO: rename */
140 int (* transfer_response)(struct scsi_cmnd *,
141 void (*done)(struct scsi_cmnd *));
143 * This is called to inform the LLD to transfer cmd->request_bufflen
144 * bytes of the cmd at cmd->offset in the cmd. The cmd->use_sg
145 * speciefies the number of scatterlist entried in the command
146 * and cmd->request_buffer contains the scatterlist.
148 * If the command cannot be processed in one transfer_data call
149 * becuase a scatterlist within the LLD's limits cannot be
150 * created then transfer_data will be called multiple times.
151 * It is initially called from process context, and later
152 * calls are from the interrup context.
154 int (* transfer_data)(struct scsi_cmnd *,
155 void (*done)(struct scsi_cmnd *));
157 /* Used as callback for the completion of task management request. */
158 int (* tsk_mgmt_response)(u64 mid, int result);
161 * This is an error handling strategy routine. You don't need to
162 * define one of these if you don't want to - there is a default
163 * routine that is present that should work in most cases. For those
164 * driver authors that have the inclination and ability to write their
165 * own strategy routine, this is where it is specified. Note - the
166 * strategy routine is *ALWAYS* run in the context of the kernel eh
167 * thread. Thus you are guaranteed to *NOT* be in an interrupt
168 * handler when you execute this, and you are also guaranteed to
169 * *NOT* have any other commands being queued while you are in the
170 * strategy routine. When you return from this function, operations
171 * return to normal.
173 * See scsi_error.c scsi_unjam_host for additional comments about
174 * what this function should and should not be attempting to do.
176 * Status: REQUIRED (at least one of them)
178 int (* eh_abort_handler)(struct scsi_cmnd *);
179 int (* eh_device_reset_handler)(struct scsi_cmnd *);
180 int (* eh_bus_reset_handler)(struct scsi_cmnd *);
181 int (* eh_host_reset_handler)(struct scsi_cmnd *);
184 * Before the mid layer attempts to scan for a new device where none
185 * currently exists, it will call this entry in your driver. Should
186 * your driver need to allocate any structs or perform any other init
187 * items in order to send commands to a currently unused target/lun
188 * combo, then this is where you can perform those allocations. This
189 * is specifically so that drivers won't have to perform any kind of
190 * "is this a new device" checks in their queuecommand routine,
191 * thereby making the hot path a bit quicker.
193 * Return values: 0 on success, non-0 on failure
195 * Deallocation: If we didn't find any devices at this ID, you will
196 * get an immediate call to slave_destroy(). If we find something
197 * here then you will get a call to slave_configure(), then the
198 * device will be used for however long it is kept around, then when
199 * the device is removed from the system (or * possibly at reboot
200 * time), you will then get a call to slave_destroy(). This is
201 * assuming you implement slave_configure and slave_destroy.
202 * However, if you allocate memory and hang it off the device struct,
203 * then you must implement the slave_destroy() routine at a minimum
204 * in order to avoid leaking memory
205 * each time a device is tore down.
207 * Status: OPTIONAL
209 int (* slave_alloc)(struct scsi_device *);
212 * Once the device has responded to an INQUIRY and we know the
213 * device is online, we call into the low level driver with the
214 * struct scsi_device *. If the low level device driver implements
215 * this function, it *must* perform the task of setting the queue
216 * depth on the device. All other tasks are optional and depend
217 * on what the driver supports and various implementation details.
219 * Things currently recommended to be handled at this time include:
221 * 1. Setting the device queue depth. Proper setting of this is
222 * described in the comments for scsi_adjust_queue_depth.
223 * 2. Determining if the device supports the various synchronous
224 * negotiation protocols. The device struct will already have
225 * responded to INQUIRY and the results of the standard items
226 * will have been shoved into the various device flag bits, eg.
227 * device->sdtr will be true if the device supports SDTR messages.
228 * 3. Allocating command structs that the device will need.
229 * 4. Setting the default timeout on this device (if needed).
230 * 5. Anything else the low level driver might want to do on a device
231 * specific setup basis...
232 * 6. Return 0 on success, non-0 on error. The device will be marked
233 * as offline on error so that no access will occur. If you return
234 * non-0, your slave_destroy routine will never get called for this
235 * device, so don't leave any loose memory hanging around, clean
236 * up after yourself before returning non-0
238 * Status: OPTIONAL
240 int (* slave_configure)(struct scsi_device *);
243 * Immediately prior to deallocating the device and after all activity
244 * has ceased the mid layer calls this point so that the low level
245 * driver may completely detach itself from the scsi device and vice
246 * versa. The low level driver is responsible for freeing any memory
247 * it allocated in the slave_alloc or slave_configure calls.
249 * Status: OPTIONAL
251 void (* slave_destroy)(struct scsi_device *);
254 * Before the mid layer attempts to scan for a new device attached
255 * to a target where no target currently exists, it will call this
256 * entry in your driver. Should your driver need to allocate any
257 * structs or perform any other init items in order to send commands
258 * to a currently unused target, then this is where you can perform
259 * those allocations.
261 * Return values: 0 on success, non-0 on failure
263 * Status: OPTIONAL
265 int (* target_alloc)(struct scsi_target *);
268 * Immediately prior to deallocating the target structure, and
269 * after all activity to attached scsi devices has ceased, the
270 * midlayer calls this point so that the driver may deallocate
271 * and terminate any references to the target.
273 * Status: OPTIONAL
275 void (* target_destroy)(struct scsi_target *);
278 * If a host has the ability to discover targets on its own instead
279 * of scanning the entire bus, it can fill in this function and
280 * call scsi_scan_host(). This function will be called periodically
281 * until it returns 1 with the scsi_host and the elapsed time of
282 * the scan in jiffies.
284 * Status: OPTIONAL
286 int (* scan_finished)(struct Scsi_Host *, unsigned long);
289 * If the host wants to be called before the scan starts, but
290 * after the midlayer has set up ready for the scan, it can fill
291 * in this function.
293 void (* scan_start)(struct Scsi_Host *);
296 * fill in this function to allow the queue depth of this host
297 * to be changeable (on a per device basis). returns either
298 * the current queue depth setting (may be different from what
299 * was passed in) or an error. An error should only be
300 * returned if the requested depth is legal but the driver was
301 * unable to set it. If the requested depth is illegal, the
302 * driver should set and return the closest legal queue depth.
305 int (* change_queue_depth)(struct scsi_device *, int);
308 * fill in this function to allow the changing of tag types
309 * (this also allows the enabling/disabling of tag command
310 * queueing). An error should only be returned if something
311 * went wrong in the driver while trying to set the tag type.
312 * If the driver doesn't support the requested tag type, then
313 * it should set the closest type it does support without
314 * returning an error. Returns the actual tag type set.
316 int (* change_queue_type)(struct scsi_device *, int);
319 * This function determines the bios parameters for a given
320 * harddisk. These tend to be numbers that are made up by
321 * the host adapter. Parameters:
322 * size, device, list (heads, sectors, cylinders)
324 * Status: OPTIONAL */
325 int (* bios_param)(struct scsi_device *, struct block_device *,
326 sector_t, int []);
329 * Can be used to export driver statistics and other infos to the
330 * world outside the kernel ie. userspace and it also provides an
331 * interface to feed the driver with information.
333 * Status: OBSOLETE
335 int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);
338 * suspend support
340 int (*resume)(struct scsi_device *);
341 int (*suspend)(struct scsi_device *, pm_message_t state);
344 * Name of proc directory
346 char *proc_name;
349 * Used to store the procfs directory if a driver implements the
350 * proc_info method.
352 struct proc_dir_entry *proc_dir;
355 * This determines if we will use a non-interrupt driven
356 * or an interrupt driven scheme, It is set to the maximum number
357 * of simultaneous commands a given host adapter will accept.
359 int can_queue;
362 * In many instances, especially where disconnect / reconnect are
363 * supported, our host also has an ID on the SCSI bus. If this is
364 * the case, then it must be reserved. Please set this_id to -1 if
365 * your setup is in single initiator mode, and the host lacks an
366 * ID.
368 int this_id;
371 * This determines the degree to which the host adapter is capable
372 * of scatter-gather.
374 unsigned short sg_tablesize;
377 * If the host adapter has limitations beside segment count
379 unsigned short max_sectors;
382 * dma scatter gather segment boundary limit. a segment crossing this
383 * boundary will be split in two.
385 unsigned long dma_boundary;
388 * This specifies "machine infinity" for host templates which don't
389 * limit the transfer size. Note this limit represents an absolute
390 * maximum, and may be over the transfer limits allowed for
391 * individual devices (e.g. 256 for SCSI-1)
393 #define SCSI_DEFAULT_MAX_SECTORS 1024
396 * True if this host adapter can make good use of linked commands.
397 * This will allow more than one command to be queued to a given
398 * unit on a given host. Set this to the maximum number of command
399 * blocks to be provided for each device. Set this to 1 for one
400 * command block per lun, 2 for two, etc. Do not set this to 0.
401 * You should make sure that the host adapter will do the right thing
402 * before you try setting this above 1.
404 short cmd_per_lun;
407 * present contains counter indicating how many boards of this
408 * type were found when we did the scan.
410 unsigned char present;
413 * true if this host adapter uses unchecked DMA onto an ISA bus.
415 unsigned unchecked_isa_dma:1;
418 * true if this host adapter can make good use of clustering.
419 * I originally thought that if the tablesize was large that it
420 * was a waste of CPU cycles to prepare a cluster list, but
421 * it works out that the Buslogic is faster if you use a smaller
422 * number of segments (i.e. use clustering). I guess it is
423 * inefficient.
425 unsigned use_clustering:1;
428 * True for emulated SCSI host adapters (e.g. ATAPI)
430 unsigned emulated:1;
433 * True if the low-level driver performs its own reset-settle delays.
435 unsigned skip_settle_delay:1;
438 * ordered write support
440 unsigned ordered_tag:1;
443 * Countdown for host blocking with no commands outstanding
445 unsigned int max_host_blocked;
448 * Default value for the blocking. If the queue is empty,
449 * host_blocked counts down in the request_fn until it restarts
450 * host operations as zero is reached.
452 * FIXME: This should probably be a value in the template
454 #define SCSI_DEFAULT_HOST_BLOCKED 7
457 * Pointer to the sysfs class properties for this host, NULL terminated.
459 struct class_device_attribute **shost_attrs;
462 * Pointer to the SCSI device properties for this host, NULL terminated.
464 struct device_attribute **sdev_attrs;
467 * List of hosts per template.
469 * This is only for use by scsi_module.c for legacy templates.
470 * For these access to it is synchronized implicitly by
471 * module_init/module_exit.
473 struct list_head legacy_hosts;
477 * shost state: If you alter this, you also need to alter scsi_sysfs.c
478 * (for the ascii descriptions) and the state model enforcer:
479 * scsi_host_set_state()
481 enum scsi_host_state {
482 SHOST_CREATED = 1,
483 SHOST_RUNNING,
484 SHOST_CANCEL,
485 SHOST_DEL,
486 SHOST_RECOVERY,
487 SHOST_CANCEL_RECOVERY,
488 SHOST_DEL_RECOVERY,
491 struct Scsi_Host {
493 * __devices is protected by the host_lock, but you should
494 * usually use scsi_device_lookup / shost_for_each_device
495 * to access it and don't care about locking yourself.
496 * In the rare case of beeing in irq context you can use
497 * their __ prefixed variants with the lock held. NEVER
498 * access this list directly from a driver.
500 struct list_head __devices;
501 struct list_head __targets;
503 struct scsi_host_cmd_pool *cmd_pool;
504 spinlock_t free_list_lock;
505 struct list_head free_list; /* backup store of cmd structs */
506 struct list_head starved_list;
508 spinlock_t default_lock;
509 spinlock_t *host_lock;
511 struct mutex scan_mutex;/* serialize scanning activity */
513 struct list_head eh_cmd_q;
514 struct task_struct * ehandler; /* Error recovery thread. */
515 struct completion * eh_action; /* Wait for specific actions on the
516 host. */
517 wait_queue_head_t host_wait;
518 struct scsi_host_template *hostt;
519 struct scsi_transport_template *transportt;
522 * area to keep a shared tag map (if needed, will be
523 * NULL if not)
525 struct blk_queue_tag *bqt;
528 * The following two fields are protected with host_lock;
529 * however, eh routines can safely access during eh processing
530 * without acquiring the lock.
532 unsigned int host_busy; /* commands actually active on low-level */
533 unsigned int host_failed; /* commands that failed. */
534 unsigned int host_eh_scheduled; /* EH scheduled without command */
536 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
537 int resetting; /* if set, it means that last_reset is a valid value */
538 unsigned long last_reset;
541 * These three parameters can be used to allow for wide scsi,
542 * and for host adapters that support multiple busses
543 * The first two should be set to 1 more than the actual max id
544 * or lun (i.e. 8 for normal systems).
546 unsigned int max_id;
547 unsigned int max_lun;
548 unsigned int max_channel;
551 * This is a unique identifier that must be assigned so that we
552 * have some way of identifying each detected host adapter properly
553 * and uniquely. For hosts that do not support more than one card
554 * in the system at one time, this does not need to be set. It is
555 * initialized to 0 in scsi_register.
557 unsigned int unique_id;
560 * The maximum length of SCSI commands that this host can accept.
561 * Probably 12 for most host adapters, but could be 16 for others.
562 * For drivers that don't set this field, a value of 12 is
563 * assumed. I am leaving this as a number rather than a bit
564 * because you never know what subsequent SCSI standards might do
565 * (i.e. could there be a 20 byte or a 24-byte command a few years
566 * down the road?).
568 unsigned char max_cmd_len;
570 int this_id;
571 int can_queue;
572 short cmd_per_lun;
573 short unsigned int sg_tablesize;
574 short unsigned int max_sectors;
575 unsigned long dma_boundary;
577 * Used to assign serial numbers to the cmds.
578 * Protected by the host lock.
580 unsigned long cmd_serial_number, cmd_pid;
582 unsigned unchecked_isa_dma:1;
583 unsigned use_clustering:1;
584 unsigned use_blk_tcq:1;
587 * Host has requested that no further requests come through for the
588 * time being.
590 unsigned host_self_blocked:1;
593 * Host uses correct SCSI ordering not PC ordering. The bit is
594 * set for the minority of drivers whose authors actually read
595 * the spec ;)
597 unsigned reverse_ordering:1;
600 * ordered write support
602 unsigned ordered_tag:1;
604 /* task mgmt function in progress */
605 unsigned tmf_in_progress:1;
607 /* Asynchronous scan in progress */
608 unsigned async_scan:1;
611 * Optional work queue to be utilized by the transport
613 char work_q_name[KOBJ_NAME_LEN];
614 struct workqueue_struct *work_q;
617 * Host has rejected a command because it was busy.
619 unsigned int host_blocked;
622 * Value host_blocked counts down from
624 unsigned int max_host_blocked;
627 * q used for scsi_tgt msgs, async events or any other requests that
628 * need to be processed in userspace
630 struct request_queue *uspace_req_q;
632 /* legacy crap */
633 unsigned long base;
634 unsigned long io_port;
635 unsigned char n_io_port;
636 unsigned char dma_channel;
637 unsigned int irq;
640 enum scsi_host_state shost_state;
642 /* ldm bits */
643 struct device shost_gendev;
644 struct class_device shost_classdev;
647 * List of hosts per template.
649 * This is only for use by scsi_module.c for legacy templates.
650 * For these access to it is synchronized implicitly by
651 * module_init/module_exit.
653 struct list_head sht_legacy_list;
656 * Points to the transport data (if any) which is allocated
657 * separately
659 void *shost_data;
662 * We should ensure that this is aligned, both for better performance
663 * and also because some compilers (m68k) don't automatically force
664 * alignment to a long boundary.
666 unsigned long hostdata[0] /* Used for storage of host specific stuff */
667 __attribute__ ((aligned (sizeof(unsigned long))));
670 #define class_to_shost(d) \
671 container_of(d, struct Scsi_Host, shost_classdev)
673 #define shost_printk(prefix, shost, fmt, a...) \
674 dev_printk(prefix, &(shost)->shost_gendev, fmt, ##a)
677 int scsi_is_host_device(const struct device *);
679 static inline struct Scsi_Host *dev_to_shost(struct device *dev)
681 while (!scsi_is_host_device(dev)) {
682 if (!dev->parent)
683 return NULL;
684 dev = dev->parent;
686 return container_of(dev, struct Scsi_Host, shost_gendev);
689 static inline int scsi_host_in_recovery(struct Scsi_Host *shost)
691 return shost->shost_state == SHOST_RECOVERY ||
692 shost->shost_state == SHOST_CANCEL_RECOVERY ||
693 shost->shost_state == SHOST_DEL_RECOVERY ||
694 shost->tmf_in_progress;
697 extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
698 extern void scsi_flush_work(struct Scsi_Host *);
700 extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
701 extern int __must_check scsi_add_host(struct Scsi_Host *, struct device *);
702 extern void scsi_scan_host(struct Scsi_Host *);
703 extern void scsi_rescan_device(struct device *);
704 extern void scsi_remove_host(struct Scsi_Host *);
705 extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
706 extern void scsi_host_put(struct Scsi_Host *t);
707 extern struct Scsi_Host *scsi_host_lookup(unsigned short);
708 extern const char *scsi_host_state_name(enum scsi_host_state);
710 extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
712 static inline struct device *scsi_get_device(struct Scsi_Host *shost)
714 return shost->shost_gendev.parent;
718 * scsi_host_scan_allowed - Is scanning of this host allowed
719 * @shost: Pointer to Scsi_Host.
721 static inline int scsi_host_scan_allowed(struct Scsi_Host *shost)
723 return shost->shost_state == SHOST_RUNNING;
726 extern void scsi_unblock_requests(struct Scsi_Host *);
727 extern void scsi_block_requests(struct Scsi_Host *);
729 struct class_container;
731 extern struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
732 void (*) (struct request_queue *));
734 * These two functions are used to allocate and free a pseudo device
735 * which will connect to the host adapter itself rather than any
736 * physical device. You must deallocate when you are done with the
737 * thing. This physical pseudo-device isn't real and won't be available
738 * from any high-level drivers.
740 extern void scsi_free_host_dev(struct scsi_device *);
741 extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
743 /* legacy interfaces */
744 extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
745 extern void scsi_unregister(struct Scsi_Host *);
746 extern int scsi_host_set_state(struct Scsi_Host *, enum scsi_host_state);
748 #endif /* _SCSI_SCSI_HOST_H */