Merge with Linux 2.5.73.
[linux-2.6/linux-mips.git] / include / scsi / scsi_host.h
blobd92dc75d131df3cf42834c1ba91a5062e760da61
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>
8 struct block_device;
9 struct module;
10 struct scsi_cmnd;
11 struct scsi_device;
12 struct Scsi_Host;
13 struct scsi_host_cmd_pool;
17 * The various choices mean:
18 * NONE: Self evident. Host adapter is not capable of scatter-gather.
19 * ALL: Means that the host adapter module can do scatter-gather,
20 * and that there is no limit to the size of the table to which
21 * we scatter/gather data.
22 * Anything else: Indicates the maximum number of chains that can be
23 * used in one scatter-gather request.
25 #define SG_NONE 0
26 #define SG_ALL 0xff
29 #define DISABLE_CLUSTERING 0
30 #define ENABLE_CLUSTERING 1
33 struct scsi_host_template {
34 struct module *module;
35 const char *name;
38 * Used to initialize old-style drivers. For new-style drivers
39 * just perform all work in your module initialization function.
41 * Status: OBSOLETE
43 int (* detect)(struct scsi_host_template *);
46 * Used as unload callback for hosts with old-style drivers.
48 * Status: OBSOLETE
50 int (* release)(struct Scsi_Host *);
53 * The info function will return whatever useful information the
54 * developer sees fit. If not provided, then the name field will
55 * be used instead.
57 * Status: OPTIONAL
59 const char *(* info)(struct Scsi_Host *);
62 * Ioctl interface
64 * Status: OPTIONAL
66 int (* ioctl)(struct scsi_device *dev, int cmd, void *arg);
69 * The queuecommand function is used to queue up a scsi
70 * command block to the LLDD. When the driver finished
71 * processing the command the done callback is invoked.
73 * If queuecommand returns 0, then the HBA has accepted the
74 * command. The done() function must be called on the command
75 * when the driver has finished with it. (you may call done on the
76 * command before queuecommand returns, but in this case you
77 * *must* return 0 from queuecommand).
79 * Queuecommand may also reject the command, in which case it may
80 * not touch the command and must not call done() for it.
82 * There are two possible rejection returns:
84 * SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but
85 * allow commands to other devices serviced by this host.
87 * SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this
88 * host temporarily.
90 * For compatibility, any other non-zero return is treated the
91 * same as SCSI_MLQUEUE_HOST_BUSY.
93 * NOTE: "temporarily" means either until the next command for#
94 * this device/host completes, or a period of time determined by
95 * I/O pressure in the system if there are no other outstanding
96 * commands.
98 * STATUS: REQUIRED
100 int (* queuecommand)(struct scsi_cmnd *,
101 void (*done)(struct scsi_cmnd *));
104 * This is an error handling strategy routine. You don't need to
105 * define one of these if you don't want to - there is a default
106 * routine that is present that should work in most cases. For those
107 * driver authors that have the inclination and ability to write their
108 * own strategy routine, this is where it is specified. Note - the
109 * strategy routine is *ALWAYS* run in the context of the kernel eh
110 * thread. Thus you are guaranteed to *NOT* be in an interrupt
111 * handler when you execute this, and you are also guaranteed to
112 * *NOT* have any other commands being queued while you are in the
113 * strategy routine. When you return from this function, operations
114 * return to normal.
116 * See scsi_error.c scsi_unjam_host for additional comments about
117 * what this function should and should not be attempting to do.
119 * Status: REQUIRED (at least one of them)
121 int (* eh_strategy_handler)(struct Scsi_Host *);
122 int (* eh_abort_handler)(struct scsi_cmnd *);
123 int (* eh_device_reset_handler)(struct scsi_cmnd *);
124 int (* eh_bus_reset_handler)(struct scsi_cmnd *);
125 int (* eh_host_reset_handler)(struct scsi_cmnd *);
128 * Old EH handlers, no longer used. Make them warn the user of old
129 * drivers by using a wrong type
131 * Status: MORE THAN OBSOLETE
133 int (* abort)(int);
134 int (* reset)(int, int);
137 * Before the mid layer attempts to scan for a new device where none
138 * currently exists, it will call this entry in your driver. Should
139 * your driver need to allocate any structs or perform any other init
140 * items in order to send commands to a currently unused target/lun
141 * combo, then this is where you can perform those allocations. This
142 * is specifically so that drivers won't have to perform any kind of
143 * "is this a new device" checks in their queuecommand routine,
144 * thereby making the hot path a bit quicker.
146 * Return values: 0 on success, non-0 on failure
148 * Deallocation: If we didn't find any devices at this ID, you will
149 * get an immediate call to slave_destroy(). If we find something
150 * here then you will get a call to slave_configure(), then the
151 * device will be used for however long it is kept around, then when
152 * the device is removed from the system (or * possibly at reboot
153 * time), you will then get a call to slave_detach(). This is
154 * assuming you implement slave_configure and slave_destroy.
155 * However, if you allocate memory and hang it off the device struct,
156 * then you must implement the slave_destroy() routine at a minimum
157 * in order to avoid leaking memory
158 * each time a device is tore down.
160 * Status: OPTIONAL
162 int (* slave_alloc)(struct scsi_device *);
165 * Once the device has responded to an INQUIRY and we know the
166 * device is online, we call into the low level driver with the
167 * struct scsi_device *. If the low level device driver implements
168 * this function, it *must* perform the task of setting the queue
169 * depth on the device. All other tasks are optional and depend
170 * on what the driver supports and various implementation details.
172 * Things currently recommended to be handled at this time include:
174 * 1. Setting the device queue depth. Proper setting of this is
175 * described in the comments for scsi_adjust_queue_depth.
176 * 2. Determining if the device supports the various synchronous
177 * negotiation protocols. The device struct will already have
178 * responded to INQUIRY and the results of the standard items
179 * will have been shoved into the various device flag bits, eg.
180 * device->sdtr will be true if the device supports SDTR messages.
181 * 3. Allocating command structs that the device will need.
182 * 4. Setting the default timeout on this device (if needed).
183 * 5. Anything else the low level driver might want to do on a device
184 * specific setup basis...
185 * 6. Return 0 on success, non-0 on error. The device will be marked
186 * as offline on error so that no access will occur. If you return
187 * non-0, your slave_detach routine will never get called for this
188 * device, so don't leave any loose memory hanging around, clean
189 * up after yourself before returning non-0
191 * Status: OPTIONAL
193 int (* slave_configure)(struct scsi_device *);
196 * Immediately prior to deallocating the device and after all activity
197 * has ceased the mid layer calls this point so that the low level
198 * driver may completely detach itself from the scsi device and vice
199 * versa. The low level driver is responsible for freeing any memory
200 * it allocated in the slave_alloc or slave_configure calls.
202 * Status: OPTIONAL
204 void (* slave_destroy)(struct scsi_device *);
207 * This function determines the bios parameters for a given
208 * harddisk. These tend to be numbers that are made up by
209 * the host adapter. Parameters:
210 * size, device, list (heads, sectors, cylinders)
212 * Status: OPTIONAL
214 int (* bios_param)(struct scsi_device *, struct block_device *,
215 sector_t, int []);
218 * Can be used to export driver statistics and other infos to the
219 * world outside the kernel ie. userspace and it also provides an
220 * interface to feed the driver with information.
222 * Status: OBSOLETE
224 int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);
227 * Name of proc directory
229 char *proc_name;
232 * Used to store the procfs directory if a driver implements the
233 * proc_info method.
235 struct proc_dir_entry *proc_dir;
238 * This determines if we will use a non-interrupt driven
239 * or an interrupt driven scheme, It is set to the maximum number
240 * of simultaneous commands a given host adapter will accept.
242 int can_queue;
245 * In many instances, especially where disconnect / reconnect are
246 * supported, our host also has an ID on the SCSI bus. If this is
247 * the case, then it must be reserved. Please set this_id to -1 if
248 * your setup is in single initiator mode, and the host lacks an
249 * ID.
251 int this_id;
254 * This determines the degree to which the host adapter is capable
255 * of scatter-gather.
257 unsigned short sg_tablesize;
260 * If the host adapter has limitations beside segment count
262 unsigned short max_sectors;
265 * This specifies "machine infinity" for host templates which don't
266 * limit the transfer size. Note this limit represents an absolute
267 * maximum, and may be over the transfer limits allowed for
268 * individual devices (e.g. 256 for SCSI-1)
270 #define SCSI_DEFAULT_MAX_SECTORS 1024
273 * True if this host adapter can make good use of linked commands.
274 * This will allow more than one command to be queued to a given
275 * unit on a given host. Set this to the maximum number of command
276 * blocks to be provided for each device. Set this to 1 for one
277 * command block per lun, 2 for two, etc. Do not set this to 0.
278 * You should make sure that the host adapter will do the right thing
279 * before you try setting this above 1.
281 short cmd_per_lun;
284 * present contains counter indicating how many boards of this
285 * type were found when we did the scan.
287 unsigned char present;
290 * true if this host adapter uses unchecked DMA onto an ISA bus.
292 unsigned unchecked_isa_dma:1;
295 * true if this host adapter can make good use of clustering.
296 * I originally thought that if the tablesize was large that it
297 * was a waste of CPU cycles to prepare a cluster list, but
298 * it works out that the Buslogic is faster if you use a smaller
299 * number of segments (i.e. use clustering). I guess it is
300 * inefficient.
302 unsigned use_clustering:1;
305 * True for emulated SCSI host adapters (e.g. ATAPI)
307 unsigned emulated:1;
309 unsigned highmem_io:1;
312 * True if the driver wishes to use the generic block layer
313 * tag queueing functions
315 unsigned use_blk_tcq:1;
318 * Countdown for host blocking with no commands outstanding
320 unsigned int max_host_blocked;
323 * Default value for the blocking. If the queue is empty,
324 * host_blocked counts down in the request_fn until it restarts
325 * host operations as zero is reached.
327 * FIXME: This should probably be a value in the template
329 #define SCSI_DEFAULT_HOST_BLOCKED 7
332 * Pointer to the sysfs class properties for this host
334 struct class_device_attribute **shost_attrs;
337 * Pointer to the SCSI device properties for this host
339 struct device_attribute **sdev_attrs;
342 * List of hosts per template.
344 * This is only for use by scsi_module.c for legacy templates.
345 * For these access to it is synchronized implicitly by
346 * module_init/module_exit.
348 struct list_head legacy_hosts;
351 struct Scsi_Host {
352 struct list_head my_devices;
353 struct scsi_host_cmd_pool *cmd_pool;
354 spinlock_t free_list_lock;
355 struct list_head free_list; /* backup store of cmd structs */
356 struct list_head starved_list;
358 spinlock_t default_lock;
359 spinlock_t *host_lock;
361 struct list_head eh_cmd_q;
362 struct task_struct * ehandler; /* Error recovery thread. */
363 struct semaphore * eh_wait; /* The error recovery thread waits on
364 this. */
365 struct completion * eh_notify; /* wait for eh to begin or end */
366 struct semaphore * eh_action; /* Wait for specific actions on the
367 host. */
368 unsigned int eh_active:1; /* Indicates the eh thread is awake and active if
369 this is true. */
370 unsigned int eh_kill:1; /* set when killing the eh thread */
371 wait_queue_head_t host_wait;
372 struct scsi_host_template *hostt;
373 volatile unsigned short host_busy; /* commands actually active on low-level */
374 volatile unsigned short host_failed; /* commands that failed. */
376 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
377 int resetting; /* if set, it means that last_reset is a valid value */
378 unsigned long last_reset;
381 * These three parameters can be used to allow for wide scsi,
382 * and for host adapters that support multiple busses
383 * The first two should be set to 1 more than the actual max id
384 * or lun (i.e. 8 for normal systems).
386 unsigned int max_id;
387 unsigned int max_lun;
388 unsigned int max_channel;
391 * This is a unique identifier that must be assigned so that we
392 * have some way of identifying each detected host adapter properly
393 * and uniquely. For hosts that do not support more than one card
394 * in the system at one time, this does not need to be set. It is
395 * initialized to 0 in scsi_register.
397 unsigned int unique_id;
400 * The maximum length of SCSI commands that this host can accept.
401 * Probably 12 for most host adapters, but could be 16 for others.
402 * For drivers that don't set this field, a value of 12 is
403 * assumed. I am leaving this as a number rather than a bit
404 * because you never know what subsequent SCSI standards might do
405 * (i.e. could there be a 20 byte or a 24-byte command a few years
406 * down the road?).
408 unsigned char max_cmd_len;
410 int this_id;
411 int can_queue;
412 short cmd_per_lun;
413 short unsigned int sg_tablesize;
414 short unsigned int max_sectors;
416 unsigned in_recovery:1;
417 unsigned unchecked_isa_dma:1;
418 unsigned use_clustering:1;
419 unsigned highmem_io:1;
420 unsigned use_blk_tcq:1;
423 * Host has requested that no further requests come through for the
424 * time being.
426 unsigned host_self_blocked:1;
429 * Host uses correct SCSI ordering not PC ordering. The bit is
430 * set for the minority of drivers whose authors actually read
431 * the spec ;)
433 unsigned reverse_ordering:1;
436 * Host has rejected a command because it was busy.
438 unsigned int host_blocked;
441 * Value host_blocked counts down from
443 unsigned int max_host_blocked;
446 * Support for sysfs
448 struct device host_gendev;
449 struct class_device class_dev;
451 /* legacy crap */
452 unsigned long base;
453 unsigned long io_port;
454 unsigned char n_io_port;
455 unsigned char dma_channel;
456 unsigned int irq;
460 * List of hosts per template.
462 * This is only for use by scsi_module.c for legacy templates.
463 * For these access to it is synchronized implicitly by
464 * module_init/module_exit.
466 struct list_head sht_legacy_list;
469 * We should ensure that this is aligned, both for better performance
470 * and also because some compilers (m68k) don't automatically force
471 * alignment to a long boundary.
473 unsigned long hostdata[0] /* Used for storage of host specific stuff */
474 __attribute__ ((aligned (sizeof(unsigned long))));
476 #define dev_to_shost(d) \
477 container_of(d, struct Scsi_Host, host_gendev)
478 #define class_to_shost(d) \
479 container_of(d, struct Scsi_Host, class_dev)
481 extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
482 extern int scsi_add_host(struct Scsi_Host *, struct device *);
483 extern int scsi_remove_host(struct Scsi_Host *);
484 extern void scsi_host_get(struct Scsi_Host *);
485 extern void scsi_host_put(struct Scsi_Host *t);
486 extern struct Scsi_Host *scsi_host_lookup(unsigned short);
488 extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
490 static inline void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock)
492 shost->host_lock = lock;
495 static inline void scsi_set_device(struct Scsi_Host *shost,
496 struct device *dev)
498 shost->host_gendev.parent = dev;
501 static inline struct device *scsi_get_device(struct Scsi_Host *shost)
503 return shost->host_gendev.parent;
506 extern void scsi_sysfs_release_attributes(struct scsi_host_template *);
508 extern void scsi_unblock_requests(struct Scsi_Host *);
509 extern void scsi_block_requests(struct Scsi_Host *);
512 * These two functions are used to allocate and free a pseudo device
513 * which will connect to the host adapter itself rather than any
514 * physical device. You must deallocate when you are done with the
515 * thing. This physical pseudo-device isn't real and won't be available
516 * from any high-level drivers.
518 extern void scsi_free_host_dev(struct scsi_device *);
519 extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
521 /* legacy interfaces */
522 extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
523 extern void scsi_unregister(struct Scsi_Host *);
525 #endif /* _SCSI_SCSI_HOST_H */