[PATCH] ppc32: Fix errata for some G3 CPUs
[linux-2.6/linux-2.6-openrd.git] / include / scsi / scsi_host.h
blob1cee1e100943dafe00c14d5329b73659062a4d1a
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>
9 struct block_device;
10 struct module;
11 struct scsi_cmnd;
12 struct scsi_device;
13 struct Scsi_Host;
14 struct scsi_host_cmd_pool;
15 struct scsi_transport_template;
19 * The various choices mean:
20 * NONE: Self evident. Host adapter is not capable of scatter-gather.
21 * ALL: Means that the host adapter module can do scatter-gather,
22 * and that there is no limit to the size of the table to which
23 * we scatter/gather data.
24 * Anything else: Indicates the maximum number of chains that can be
25 * used in one scatter-gather request.
27 #define SG_NONE 0
28 #define SG_ALL 0xff
31 #define DISABLE_CLUSTERING 0
32 #define ENABLE_CLUSTERING 1
34 enum scsi_eh_timer_return {
35 EH_NOT_HANDLED,
36 EH_HANDLED,
37 EH_RESET_TIMER,
41 struct scsi_host_template {
42 struct module *module;
43 const char *name;
46 * Used to initialize old-style drivers. For new-style drivers
47 * just perform all work in your module initialization function.
49 * Status: OBSOLETE
51 int (* detect)(struct scsi_host_template *);
54 * Used as unload callback for hosts with old-style drivers.
56 * Status: OBSOLETE
58 int (* release)(struct Scsi_Host *);
61 * The info function will return whatever useful information the
62 * developer sees fit. If not provided, then the name field will
63 * be used instead.
65 * Status: OPTIONAL
67 const char *(* info)(struct Scsi_Host *);
70 * Ioctl interface
72 * Status: OPTIONAL
74 int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
77 #ifdef CONFIG_COMPAT
78 /*
79 * Compat handler. Handle 32bit ABI.
80 * When unknown ioctl is passed return -ENOIOCTLCMD.
82 * Status: OPTIONAL
84 int (* compat_ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
85 #endif
88 * The queuecommand function is used to queue up a scsi
89 * command block to the LLDD. When the driver finished
90 * processing the command the done callback is invoked.
92 * If queuecommand returns 0, then the HBA has accepted the
93 * command. The done() function must be called on the command
94 * when the driver has finished with it. (you may call done on the
95 * command before queuecommand returns, but in this case you
96 * *must* return 0 from queuecommand).
98 * Queuecommand may also reject the command, in which case it may
99 * not touch the command and must not call done() for it.
101 * There are two possible rejection returns:
103 * SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but
104 * allow commands to other devices serviced by this host.
106 * SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this
107 * host temporarily.
109 * For compatibility, any other non-zero return is treated the
110 * same as SCSI_MLQUEUE_HOST_BUSY.
112 * NOTE: "temporarily" means either until the next command for#
113 * this device/host completes, or a period of time determined by
114 * I/O pressure in the system if there are no other outstanding
115 * commands.
117 * STATUS: REQUIRED
119 int (* queuecommand)(struct scsi_cmnd *,
120 void (*done)(struct scsi_cmnd *));
123 * This is an error handling strategy routine. You don't need to
124 * define one of these if you don't want to - there is a default
125 * routine that is present that should work in most cases. For those
126 * driver authors that have the inclination and ability to write their
127 * own strategy routine, this is where it is specified. Note - the
128 * strategy routine is *ALWAYS* run in the context of the kernel eh
129 * thread. Thus you are guaranteed to *NOT* be in an interrupt
130 * handler when you execute this, and you are also guaranteed to
131 * *NOT* have any other commands being queued while you are in the
132 * strategy routine. When you return from this function, operations
133 * return to normal.
135 * See scsi_error.c scsi_unjam_host for additional comments about
136 * what this function should and should not be attempting to do.
138 * Status: REQUIRED (at least one of them)
140 int (* eh_strategy_handler)(struct Scsi_Host *);
141 int (* eh_abort_handler)(struct scsi_cmnd *);
142 int (* eh_device_reset_handler)(struct scsi_cmnd *);
143 int (* eh_bus_reset_handler)(struct scsi_cmnd *);
144 int (* eh_host_reset_handler)(struct scsi_cmnd *);
147 * This is an optional routine to notify the host that the scsi
148 * timer just fired. The returns tell the timer routine what to
149 * do about this:
151 * EH_HANDLED: I fixed the error, please complete the command
152 * EH_RESET_TIMER: I need more time, reset the timer and
153 * begin counting again
154 * EH_NOT_HANDLED Begin normal error recovery
156 * Status: OPTIONAL
158 enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *);
161 * Before the mid layer attempts to scan for a new device where none
162 * currently exists, it will call this entry in your driver. Should
163 * your driver need to allocate any structs or perform any other init
164 * items in order to send commands to a currently unused target/lun
165 * combo, then this is where you can perform those allocations. This
166 * is specifically so that drivers won't have to perform any kind of
167 * "is this a new device" checks in their queuecommand routine,
168 * thereby making the hot path a bit quicker.
170 * Return values: 0 on success, non-0 on failure
172 * Deallocation: If we didn't find any devices at this ID, you will
173 * get an immediate call to slave_destroy(). If we find something
174 * here then you will get a call to slave_configure(), then the
175 * device will be used for however long it is kept around, then when
176 * the device is removed from the system (or * possibly at reboot
177 * time), you will then get a call to slave_destroy(). This is
178 * assuming you implement slave_configure and slave_destroy.
179 * However, if you allocate memory and hang it off the device struct,
180 * then you must implement the slave_destroy() routine at a minimum
181 * in order to avoid leaking memory
182 * each time a device is tore down.
184 * Status: OPTIONAL
186 int (* slave_alloc)(struct scsi_device *);
189 * Once the device has responded to an INQUIRY and we know the
190 * device is online, we call into the low level driver with the
191 * struct scsi_device *. If the low level device driver implements
192 * this function, it *must* perform the task of setting the queue
193 * depth on the device. All other tasks are optional and depend
194 * on what the driver supports and various implementation details.
196 * Things currently recommended to be handled at this time include:
198 * 1. Setting the device queue depth. Proper setting of this is
199 * described in the comments for scsi_adjust_queue_depth.
200 * 2. Determining if the device supports the various synchronous
201 * negotiation protocols. The device struct will already have
202 * responded to INQUIRY and the results of the standard items
203 * will have been shoved into the various device flag bits, eg.
204 * device->sdtr will be true if the device supports SDTR messages.
205 * 3. Allocating command structs that the device will need.
206 * 4. Setting the default timeout on this device (if needed).
207 * 5. Anything else the low level driver might want to do on a device
208 * specific setup basis...
209 * 6. Return 0 on success, non-0 on error. The device will be marked
210 * as offline on error so that no access will occur. If you return
211 * non-0, your slave_destroy routine will never get called for this
212 * device, so don't leave any loose memory hanging around, clean
213 * up after yourself before returning non-0
215 * Status: OPTIONAL
217 int (* slave_configure)(struct scsi_device *);
220 * Immediately prior to deallocating the device and after all activity
221 * has ceased the mid layer calls this point so that the low level
222 * driver may completely detach itself from the scsi device and vice
223 * versa. The low level driver is responsible for freeing any memory
224 * it allocated in the slave_alloc or slave_configure calls.
226 * Status: OPTIONAL
228 void (* slave_destroy)(struct scsi_device *);
231 * fill in this function to allow the queue depth of this host
232 * to be changeable (on a per device basis). returns either
233 * the current queue depth setting (may be different from what
234 * was passed in) or an error. An error should only be
235 * returned if the requested depth is legal but the driver was
236 * unable to set it. If the requested depth is illegal, the
237 * driver should set and return the closest legal queue depth.
240 int (* change_queue_depth)(struct scsi_device *, int);
243 * fill in this function to allow the changing of tag types
244 * (this also allows the enabling/disabling of tag command
245 * queueing). An error should only be returned if something
246 * went wrong in the driver while trying to set the tag type.
247 * If the driver doesn't support the requested tag type, then
248 * it should set the closest type it does support without
249 * returning an error. Returns the actual tag type set.
251 int (* change_queue_type)(struct scsi_device *, int);
254 * This function determines the bios parameters for a given
255 * harddisk. These tend to be numbers that are made up by
256 * the host adapter. Parameters:
257 * size, device, list (heads, sectors, cylinders)
259 * Status: OPTIONAL */
260 int (* bios_param)(struct scsi_device *, struct block_device *,
261 sector_t, int []);
264 * Can be used to export driver statistics and other infos to the
265 * world outside the kernel ie. userspace and it also provides an
266 * interface to feed the driver with information.
268 * Status: OBSOLETE
270 int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);
273 * Name of proc directory
275 char *proc_name;
278 * Used to store the procfs directory if a driver implements the
279 * proc_info method.
281 struct proc_dir_entry *proc_dir;
284 * This determines if we will use a non-interrupt driven
285 * or an interrupt driven scheme, It is set to the maximum number
286 * of simultaneous commands a given host adapter will accept.
288 int can_queue;
291 * In many instances, especially where disconnect / reconnect are
292 * supported, our host also has an ID on the SCSI bus. If this is
293 * the case, then it must be reserved. Please set this_id to -1 if
294 * your setup is in single initiator mode, and the host lacks an
295 * ID.
297 int this_id;
300 * This determines the degree to which the host adapter is capable
301 * of scatter-gather.
303 unsigned short sg_tablesize;
306 * If the host adapter has limitations beside segment count
308 unsigned short max_sectors;
311 * dma scatter gather segment boundary limit. a segment crossing this
312 * boundary will be split in two.
314 unsigned long dma_boundary;
317 * This specifies "machine infinity" for host templates which don't
318 * limit the transfer size. Note this limit represents an absolute
319 * maximum, and may be over the transfer limits allowed for
320 * individual devices (e.g. 256 for SCSI-1)
322 #define SCSI_DEFAULT_MAX_SECTORS 1024
325 * True if this host adapter can make good use of linked commands.
326 * This will allow more than one command to be queued to a given
327 * unit on a given host. Set this to the maximum number of command
328 * blocks to be provided for each device. Set this to 1 for one
329 * command block per lun, 2 for two, etc. Do not set this to 0.
330 * You should make sure that the host adapter will do the right thing
331 * before you try setting this above 1.
333 short cmd_per_lun;
336 * present contains counter indicating how many boards of this
337 * type were found when we did the scan.
339 unsigned char present;
342 * true if this host adapter uses unchecked DMA onto an ISA bus.
344 unsigned unchecked_isa_dma:1;
347 * true if this host adapter can make good use of clustering.
348 * I originally thought that if the tablesize was large that it
349 * was a waste of CPU cycles to prepare a cluster list, but
350 * it works out that the Buslogic is faster if you use a smaller
351 * number of segments (i.e. use clustering). I guess it is
352 * inefficient.
354 unsigned use_clustering:1;
357 * True for emulated SCSI host adapters (e.g. ATAPI)
359 unsigned emulated:1;
362 * True if the low-level driver performs its own reset-settle delays.
364 unsigned skip_settle_delay:1;
367 * ordered write support
369 unsigned ordered_flush:1;
370 unsigned ordered_tag:1;
373 * Countdown for host blocking with no commands outstanding
375 unsigned int max_host_blocked;
378 * Default value for the blocking. If the queue is empty,
379 * host_blocked counts down in the request_fn until it restarts
380 * host operations as zero is reached.
382 * FIXME: This should probably be a value in the template
384 #define SCSI_DEFAULT_HOST_BLOCKED 7
387 * Pointer to the sysfs class properties for this host, NULL terminated.
389 struct class_device_attribute **shost_attrs;
392 * Pointer to the SCSI device properties for this host, NULL terminated.
394 struct device_attribute **sdev_attrs;
397 * List of hosts per template.
399 * This is only for use by scsi_module.c for legacy templates.
400 * For these access to it is synchronized implicitly by
401 * module_init/module_exit.
403 struct list_head legacy_hosts;
407 * shost states
409 enum {
410 SHOST_ADD,
411 SHOST_DEL,
412 SHOST_CANCEL,
413 SHOST_RECOVERY,
416 struct Scsi_Host {
418 * __devices is protected by the host_lock, but you should
419 * usually use scsi_device_lookup / shost_for_each_device
420 * to access it and don't care about locking yourself.
421 * In the rare case of beeing in irq context you can use
422 * their __ prefixed variants with the lock held. NEVER
423 * access this list directly from a driver.
425 struct list_head __devices;
426 struct list_head __targets;
428 struct scsi_host_cmd_pool *cmd_pool;
429 spinlock_t free_list_lock;
430 struct list_head free_list; /* backup store of cmd structs */
431 struct list_head starved_list;
433 spinlock_t default_lock;
434 spinlock_t *host_lock;
436 struct semaphore scan_mutex;/* serialize scanning activity */
438 struct list_head eh_cmd_q;
439 struct task_struct * ehandler; /* Error recovery thread. */
440 struct semaphore * eh_wait; /* The error recovery thread waits
441 on this. */
442 struct completion * eh_notify; /* wait for eh to begin or end */
443 struct semaphore * eh_action; /* Wait for specific actions on the
444 host. */
445 unsigned int eh_active:1; /* Indicates the eh thread is awake and active if
446 this is true. */
447 unsigned int eh_kill:1; /* set when killing the eh thread */
448 wait_queue_head_t host_wait;
449 struct scsi_host_template *hostt;
450 struct scsi_transport_template *transportt;
453 * The following two fields are protected with host_lock;
454 * however, eh routines can safely access during eh processing
455 * without acquiring the lock.
457 unsigned int host_busy; /* commands actually active on low-level */
458 unsigned int host_failed; /* commands that failed. */
460 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
461 int resetting; /* if set, it means that last_reset is a valid value */
462 unsigned long last_reset;
465 * These three parameters can be used to allow for wide scsi,
466 * and for host adapters that support multiple busses
467 * The first two should be set to 1 more than the actual max id
468 * or lun (i.e. 8 for normal systems).
470 unsigned int max_id;
471 unsigned int max_lun;
472 unsigned int max_channel;
475 * This is a unique identifier that must be assigned so that we
476 * have some way of identifying each detected host adapter properly
477 * and uniquely. For hosts that do not support more than one card
478 * in the system at one time, this does not need to be set. It is
479 * initialized to 0 in scsi_register.
481 unsigned int unique_id;
484 * The maximum length of SCSI commands that this host can accept.
485 * Probably 12 for most host adapters, but could be 16 for others.
486 * For drivers that don't set this field, a value of 12 is
487 * assumed. I am leaving this as a number rather than a bit
488 * because you never know what subsequent SCSI standards might do
489 * (i.e. could there be a 20 byte or a 24-byte command a few years
490 * down the road?).
492 unsigned char max_cmd_len;
494 int this_id;
495 int can_queue;
496 short cmd_per_lun;
497 short unsigned int sg_tablesize;
498 short unsigned int max_sectors;
499 unsigned long dma_boundary;
501 * Used to assign serial numbers to the cmds.
502 * Protected by the host lock.
504 unsigned long cmd_serial_number, cmd_pid;
506 unsigned unchecked_isa_dma:1;
507 unsigned use_clustering:1;
508 unsigned use_blk_tcq:1;
511 * Host has requested that no further requests come through for the
512 * time being.
514 unsigned host_self_blocked:1;
517 * Host uses correct SCSI ordering not PC ordering. The bit is
518 * set for the minority of drivers whose authors actually read
519 * the spec ;)
521 unsigned reverse_ordering:1;
524 * ordered write support
526 unsigned ordered_flush:1;
527 unsigned ordered_tag:1;
530 * Optional work queue to be utilized by the transport
532 char work_q_name[KOBJ_NAME_LEN];
533 struct workqueue_struct *work_q;
536 * Host has rejected a command because it was busy.
538 unsigned int host_blocked;
541 * Value host_blocked counts down from
543 unsigned int max_host_blocked;
545 /* legacy crap */
546 unsigned long base;
547 unsigned long io_port;
548 unsigned char n_io_port;
549 unsigned char dma_channel;
550 unsigned int irq;
553 unsigned long shost_state;
555 /* ldm bits */
556 struct device shost_gendev;
557 struct class_device shost_classdev;
560 * List of hosts per template.
562 * This is only for use by scsi_module.c for legacy templates.
563 * For these access to it is synchronized implicitly by
564 * module_init/module_exit.
566 struct list_head sht_legacy_list;
569 * Points to the transport data (if any) which is allocated
570 * separately
572 void *shost_data;
575 * We should ensure that this is aligned, both for better performance
576 * and also because some compilers (m68k) don't automatically force
577 * alignment to a long boundary.
579 unsigned long hostdata[0] /* Used for storage of host specific stuff */
580 __attribute__ ((aligned (sizeof(unsigned long))));
583 #define class_to_shost(d) \
584 container_of(d, struct Scsi_Host, shost_classdev)
586 int scsi_is_host_device(const struct device *);
588 static inline struct Scsi_Host *dev_to_shost(struct device *dev)
590 while (!scsi_is_host_device(dev)) {
591 if (!dev->parent)
592 return NULL;
593 dev = dev->parent;
595 return container_of(dev, struct Scsi_Host, shost_gendev);
598 extern int scsi_queue_work(struct Scsi_Host *, struct work_struct *);
599 extern void scsi_flush_work(struct Scsi_Host *);
601 extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
602 extern int __must_check scsi_add_host(struct Scsi_Host *, struct device *);
603 extern void scsi_scan_host(struct Scsi_Host *);
604 extern void scsi_scan_single_target(struct Scsi_Host *, unsigned int,
605 unsigned int);
606 extern void scsi_rescan_device(struct device *);
607 extern void scsi_remove_host(struct Scsi_Host *);
608 extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
609 extern void scsi_host_put(struct Scsi_Host *t);
610 extern struct Scsi_Host *scsi_host_lookup(unsigned short);
612 extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
614 static inline void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock)
616 shost->host_lock = lock;
619 static inline void scsi_set_device(struct Scsi_Host *shost,
620 struct device *dev)
622 shost->shost_gendev.parent = dev;
625 static inline struct device *scsi_get_device(struct Scsi_Host *shost)
627 return shost->shost_gendev.parent;
630 extern void scsi_unblock_requests(struct Scsi_Host *);
631 extern void scsi_block_requests(struct Scsi_Host *);
633 struct class_container;
635 * These two functions are used to allocate and free a pseudo device
636 * which will connect to the host adapter itself rather than any
637 * physical device. You must deallocate when you are done with the
638 * thing. This physical pseudo-device isn't real and won't be available
639 * from any high-level drivers.
641 extern void scsi_free_host_dev(struct scsi_device *);
642 extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
644 /* legacy interfaces */
645 extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
646 extern void scsi_unregister(struct Scsi_Host *);
648 #endif /* _SCSI_SCSI_HOST_H */