VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / include / scsi / scsi_host.h
1 #ifndef _SCSI_SCSI_HOST_H
2 #define _SCSI_SCSI_HOST_H
3
4 #include <linux/device.h>
5 #include <linux/list.h>
6 #include <linux/types.h>
7
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;
14 struct scsi_transport_template;
15
16
17 /*
18  * The various choices mean:
19  * NONE: Self evident.  Host adapter is not capable of scatter-gather.
20  * ALL:  Means that the host adapter module can do scatter-gather,
21  *       and that there is no limit to the size of the table to which
22  *       we scatter/gather data.
23  * Anything else:  Indicates the maximum number of chains that can be
24  *       used in one scatter-gather request.
25  */
26 #define SG_NONE 0
27 #define SG_ALL 0xff
28
29
30 #define DISABLE_CLUSTERING 0
31 #define ENABLE_CLUSTERING 1
32
33 enum scsi_eh_timer_return {
34         EH_NOT_HANDLED,
35         EH_HANDLED,
36         EH_RESET_TIMER,
37 };
38
39
40 struct scsi_host_template {
41         struct module *module;
42         const char *name;
43
44         /*
45          * Used to initialize old-style drivers.  For new-style drivers
46          * just perform all work in your module initialization function.
47          *
48          * Status:  OBSOLETE
49          */
50         int (* detect)(struct scsi_host_template *);
51
52         /*
53          * Used as unload callback for hosts with old-style drivers.
54          *
55          * Status: OBSOLETE
56          */
57         int (* release)(struct Scsi_Host *);
58
59         /*
60          * The info function will return whatever useful information the
61          * developer sees fit.  If not provided, then the name field will
62          * be used instead.
63          *
64          * Status: OPTIONAL
65          */
66         const char *(* info)(struct Scsi_Host *);
67
68         /*
69          * Ioctl interface
70          *
71          * Status: OPTIONAL
72          */
73         int (* ioctl)(struct scsi_device *dev, int cmd, void __user *arg);
74         
75         /*
76          * The queuecommand function is used to queue up a scsi
77          * command block to the LLDD.  When the driver finished
78          * processing the command the done callback is invoked.
79          *
80          * If queuecommand returns 0, then the HBA has accepted the
81          * command.  The done() function must be called on the command
82          * when the driver has finished with it. (you may call done on the
83          * command before queuecommand returns, but in this case you
84          * *must* return 0 from queuecommand).
85          *
86          * Queuecommand may also reject the command, in which case it may
87          * not touch the command and must not call done() for it.
88          *
89          * There are two possible rejection returns:
90          *
91          *   SCSI_MLQUEUE_DEVICE_BUSY: Block this device temporarily, but
92          *   allow commands to other devices serviced by this host.
93          *
94          *   SCSI_MLQUEUE_HOST_BUSY: Block all devices served by this
95          *   host temporarily.
96          *
97          * For compatibility, any other non-zero return is treated the
98          * same as SCSI_MLQUEUE_HOST_BUSY.
99          *
100          * NOTE: "temporarily" means either until the next command for#
101          * this device/host completes, or a period of time determined by
102          * I/O pressure in the system if there are no other outstanding
103          * commands.
104          *
105          * STATUS: REQUIRED
106          */
107         int (* queuecommand)(struct scsi_cmnd *,
108                              void (*done)(struct scsi_cmnd *));
109
110         /*
111          * This is an error handling strategy routine.  You don't need to
112          * define one of these if you don't want to - there is a default
113          * routine that is present that should work in most cases.  For those
114          * driver authors that have the inclination and ability to write their
115          * own strategy routine, this is where it is specified.  Note - the
116          * strategy routine is *ALWAYS* run in the context of the kernel eh
117          * thread.  Thus you are guaranteed to *NOT* be in an interrupt
118          * handler when you execute this, and you are also guaranteed to
119          * *NOT* have any other commands being queued while you are in the
120          * strategy routine. When you return from this function, operations
121          * return to normal.
122          *
123          * See scsi_error.c scsi_unjam_host for additional comments about
124          * what this function should and should not be attempting to do.
125          *
126          * Status: REQUIRED     (at least one of them)
127          */
128         int (* eh_strategy_handler)(struct Scsi_Host *);
129         int (* eh_abort_handler)(struct scsi_cmnd *);
130         int (* eh_device_reset_handler)(struct scsi_cmnd *);
131         int (* eh_bus_reset_handler)(struct scsi_cmnd *);
132         int (* eh_host_reset_handler)(struct scsi_cmnd *);
133
134         /*
135          * This is an optional routine to notify the host that the scsi
136          * timer just fired.  The returns tell the timer routine what to
137          * do about this:
138          *
139          * EH_HANDLED:          I fixed the error, please complete the command
140          * EH_RESET_TIMER:      I need more time, reset the timer and
141          *                      begin counting again
142          * EH_NOT_HANDLED       Begin normal error recovery
143          *
144          * Status: OPTIONAL
145          */
146         enum scsi_eh_timer_return (* eh_timed_out)(struct scsi_cmnd *);
147
148         /*
149          * Old EH handlers, no longer used. Make them warn the user of old
150          * drivers by using a wrong type
151          *
152          * Status: MORE THAN OBSOLETE
153          */
154         int (* abort)(int);
155         int (* reset)(int, int);
156
157         /*
158          * Before the mid layer attempts to scan for a new device where none
159          * currently exists, it will call this entry in your driver.  Should
160          * your driver need to allocate any structs or perform any other init
161          * items in order to send commands to a currently unused target/lun
162          * combo, then this is where you can perform those allocations.  This
163          * is specifically so that drivers won't have to perform any kind of
164          * "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 failure
168          *
169          * Deallocation:  If we didn't find any devices at this ID, you will
170          * get an immediate call to slave_destroy().  If we find something
171          * here then you will get a call to slave_configure(), then the
172          * device will be used for however long it is kept around, then when
173          * the device is removed from the system (or * possibly at reboot
174          * time), you will then get a call to slave_destroy().  This is
175          * assuming you implement slave_configure and slave_destroy.
176          * However, if you allocate memory and hang it off the device struct,
177          * then you must implement the slave_destroy() routine at a minimum
178          * in order to avoid leaking memory
179          * each time a device is tore down.
180          *
181          * Status: OPTIONAL
182          */
183         int (* slave_alloc)(struct scsi_device *);
184
185         /*
186          * Once the device has responded to an INQUIRY and we know the
187          * device is online, we call into the low level driver with the
188          * struct scsi_device *.  If the low level device driver implements
189          * this function, it *must* perform the task of setting the queue
190          * depth on the device.  All other tasks are optional and depend
191          * 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 is
196          *     described in the comments for scsi_adjust_queue_depth.
197          * 2.  Determining if the device supports the various synchronous
198          *     negotiation protocols.  The device struct will already have
199          *     responded to INQUIRY and the results of the standard items
200          *     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 device
205          *     specific setup basis...
206          * 6.  Return 0 on success, non-0 on error.  The device will be marked
207          *     as offline on error so that no access will occur.  If you return
208          *     non-0, your slave_destroy routine will never get called for this
209          *     device, so don't leave any loose memory hanging around, clean
210          *     up after yourself before returning non-0
211          *
212          * Status: OPTIONAL
213          */
214         int (* slave_configure)(struct scsi_device *);
215
216         /*
217          * Immediately prior to deallocating the device and after all activity
218          * has ceased the mid layer calls this point so that the low level
219          * driver may completely detach itself from the scsi device and vice
220          * versa.  The low level driver is responsible for freeing any memory
221          * it allocated in the slave_alloc or slave_configure calls. 
222          *
223          * Status: OPTIONAL
224          */
225         void (* slave_destroy)(struct scsi_device *);
226
227         /*
228          * This function determines the bios parameters for a given
229          * harddisk.  These tend to be numbers that are made up by
230          * the host adapter.  Parameters:
231          * size, device, list (heads, sectors, cylinders)
232          *
233          * Status: OPTIONAL
234          */
235         int (* bios_param)(struct scsi_device *, struct block_device *,
236                         sector_t, int []);
237
238         /*
239          * Can be used to export driver statistics and other infos to the
240          * world outside the kernel ie. userspace and it also provides an
241          * interface to feed the driver with information.
242          *
243          * Status: OBSOLETE
244          */
245         int (*proc_info)(struct Scsi_Host *, char *, char **, off_t, int, int);
246
247         /*
248          * Name of proc directory
249          */
250         char *proc_name;
251
252         /*
253          * Used to store the procfs directory if a driver implements the
254          * proc_info method.
255          */
256         struct proc_dir_entry *proc_dir;
257
258         /*
259          * This determines if we will use a non-interrupt driven
260          * or an interrupt driven scheme,  It is set to the maximum number
261          * of simultaneous commands a given host adapter will accept.
262          */
263         int can_queue;
264
265         /*
266          * In many instances, especially where disconnect / reconnect are
267          * supported, our host also has an ID on the SCSI bus.  If this is
268          * the case, then it must be reserved.  Please set this_id to -1 if
269          * your setup is in single initiator mode, and the host lacks an
270          * ID.
271          */
272         int this_id;
273
274         /*
275          * This determines the degree to which the host adapter is capable
276          * of scatter-gather.
277          */
278         unsigned short sg_tablesize;
279
280         /*
281          * If the host adapter has limitations beside segment count
282          */
283         unsigned short max_sectors;
284
285         /*
286          * dma scatter gather segment boundary limit. a segment crossing this
287          * boundary will be split in two.
288          */
289         unsigned long dma_boundary;
290
291         /*
292          * This specifies "machine infinity" for host templates which don't
293          * limit the transfer size.  Note this limit represents an absolute
294          * maximum, and may be over the transfer limits allowed for
295          * individual devices (e.g. 256 for SCSI-1)
296          */
297 #define SCSI_DEFAULT_MAX_SECTORS        1024
298
299         /*
300          * True if this host adapter can make good use of linked commands.
301          * This will allow more than one command to be queued to a given
302          * unit on a given host.  Set this to the maximum number of command
303          * blocks to be provided for each device.  Set this to 1 for one
304          * command block per lun, 2 for two, etc.  Do not set this to 0.
305          * You should make sure that the host adapter will do the right thing
306          * before you try setting this above 1.
307          */
308         short cmd_per_lun;
309
310         /*
311          * present contains counter indicating how many boards of this
312          * type were found when we did the scan.
313          */
314         unsigned char present;
315
316         /*
317          * true if this host adapter uses unchecked DMA onto an ISA bus.
318          */
319         unsigned unchecked_isa_dma:1;
320
321         /*
322          * true if this host adapter can make good use of clustering.
323          * I originally thought that if the tablesize was large that it
324          * was a waste of CPU cycles to prepare a cluster list, but
325          * it works out that the Buslogic is faster if you use a smaller
326          * number of segments (i.e. use clustering).  I guess it is
327          * inefficient.
328          */
329         unsigned use_clustering:1;
330
331         /*
332          * True for emulated SCSI host adapters (e.g. ATAPI)
333          */
334         unsigned emulated:1;
335
336         /*
337          * True if the low-level driver performs its own reset-settle delays.
338          */
339         unsigned skip_settle_delay:1;
340
341         /*
342          * Countdown for host blocking with no commands outstanding
343          */
344         unsigned int max_host_blocked;
345
346         /*
347          * Default value for the blocking.  If the queue is empty,
348          * host_blocked counts down in the request_fn until it restarts
349          * host operations as zero is reached.  
350          *
351          * FIXME: This should probably be a value in the template
352          */
353 #define SCSI_DEFAULT_HOST_BLOCKED       7
354
355         /*
356          * Pointer to the sysfs class properties for this host, NULL terminated.
357          */
358         struct class_device_attribute **shost_attrs;
359
360         /*
361          * Pointer to the SCSI device properties for this host, NULL terminated.
362          */
363         struct device_attribute **sdev_attrs;
364
365         /*
366          * List of hosts per template.
367          *
368          * This is only for use by scsi_module.c for legacy templates.
369          * For these access to it is synchronized implicitly by
370          * module_init/module_exit.
371          */
372         struct list_head legacy_hosts;
373 };
374
375 /*
376  * shost states
377  */
378 enum {
379         SHOST_ADD,
380         SHOST_DEL,
381         SHOST_CANCEL,
382         SHOST_RECOVERY,
383 };
384
385 struct Scsi_Host {
386         /*
387          * __devices is protected by the host_lock, but you should
388          * usually use scsi_device_lookup / shost_for_each_device
389          * to access it and don't care about locking yourself.
390          * In the rare case of beeing in irq context you can use
391          * their __ prefixed variants with the lock held. NEVER
392          * access this list directly from a driver.
393          */
394         struct list_head        __devices;
395         
396         struct scsi_host_cmd_pool *cmd_pool;
397         spinlock_t              free_list_lock;
398         struct list_head        free_list; /* backup store of cmd structs */
399         struct list_head        starved_list;
400
401         spinlock_t              default_lock;
402         spinlock_t              *host_lock;
403
404         struct semaphore        scan_mutex;/* serialize scanning activity */
405
406         struct list_head        eh_cmd_q;
407         struct task_struct    * ehandler;  /* Error recovery thread. */
408         struct semaphore      * eh_wait;   /* The error recovery thread waits
409                                               on this. */
410         struct completion     * eh_notify; /* wait for eh to begin or end */
411         struct semaphore      * eh_action; /* Wait for specific actions on the
412                                           host. */
413         unsigned int            eh_active:1; /* Indicates the eh thread is awake and active if
414                                           this is true. */
415         unsigned int            eh_kill:1; /* set when killing the eh thread */
416         wait_queue_head_t       host_wait;
417         struct scsi_host_template *hostt;
418         struct scsi_transport_template *transportt;
419         volatile unsigned short host_busy;   /* commands actually active on low-level */
420         volatile unsigned short host_failed; /* commands that failed. */
421     
422         unsigned short host_no;  /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
423         int resetting; /* if set, it means that last_reset is a valid value */
424         unsigned long last_reset;
425
426         /*
427          * These three parameters can be used to allow for wide scsi,
428          * and for host adapters that support multiple busses
429          * The first two should be set to 1 more than the actual max id
430          * or lun (i.e. 8 for normal systems).
431          */
432         unsigned int max_id;
433         unsigned int max_lun;
434         unsigned int max_channel;
435
436         /*
437          * This is a unique identifier that must be assigned so that we
438          * have some way of identifying each detected host adapter properly
439          * and uniquely.  For hosts that do not support more than one card
440          * in the system at one time, this does not need to be set.  It is
441          * initialized to 0 in scsi_register.
442          */
443         unsigned int unique_id;
444
445         /*
446          * The maximum length of SCSI commands that this host can accept.
447          * Probably 12 for most host adapters, but could be 16 for others.
448          * For drivers that don't set this field, a value of 12 is
449          * assumed.  I am leaving this as a number rather than a bit
450          * because you never know what subsequent SCSI standards might do
451          * (i.e. could there be a 20 byte or a 24-byte command a few years
452          * down the road?).  
453          */
454         unsigned char max_cmd_len;
455
456         int this_id;
457         int can_queue;
458         short cmd_per_lun;
459         short unsigned int sg_tablesize;
460         short unsigned int max_sectors;
461         unsigned long dma_boundary;
462
463         unsigned unchecked_isa_dma:1;
464         unsigned use_clustering:1;
465         unsigned use_blk_tcq:1;
466
467         /*
468          * Host has requested that no further requests come through for the
469          * time being.
470          */
471         unsigned host_self_blocked:1;
472     
473         /*
474          * Host uses correct SCSI ordering not PC ordering. The bit is
475          * set for the minority of drivers whose authors actually read
476          * the spec ;)
477          */
478         unsigned reverse_ordering:1;
479
480         /*
481          * Host has rejected a command because it was busy.
482          */
483         unsigned int host_blocked;
484
485         /*
486          * Value host_blocked counts down from
487          */
488         unsigned int max_host_blocked;
489
490         /* legacy crap */
491         unsigned long base;
492         unsigned long io_port;
493         unsigned char n_io_port;
494         unsigned char dma_channel;
495         unsigned int  irq;
496         
497
498         unsigned long shost_state;
499
500         /* ldm bits */
501         struct device           shost_gendev;
502         struct class_device     shost_classdev;
503
504         /*
505          * List of hosts per template.
506          *
507          * This is only for use by scsi_module.c for legacy templates.
508          * For these access to it is synchronized implicitly by
509          * module_init/module_exit.
510          */
511         struct list_head sht_legacy_list;
512
513         /*
514          * We should ensure that this is aligned, both for better performance
515          * and also because some compilers (m68k) don't automatically force
516          * alignment to a long boundary.
517          */
518         unsigned long hostdata[0]  /* Used for storage of host specific stuff */
519                 __attribute__ ((aligned (sizeof(unsigned long))));
520 };
521 #define         dev_to_shost(d)         \
522         container_of(d, struct Scsi_Host, shost_gendev)
523 #define         class_to_shost(d)       \
524         container_of(d, struct Scsi_Host, shost_classdev)
525
526 extern struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *, int);
527 extern int scsi_add_host(struct Scsi_Host *, struct device *);
528 extern void scsi_scan_host(struct Scsi_Host *);
529 extern void scsi_remove_host(struct Scsi_Host *);
530 extern struct Scsi_Host *scsi_host_get(struct Scsi_Host *);
531 extern void scsi_host_put(struct Scsi_Host *t);
532 extern struct Scsi_Host *scsi_host_lookup(unsigned short);
533
534 extern u64 scsi_calculate_bounce_limit(struct Scsi_Host *);
535
536 static inline void scsi_assign_lock(struct Scsi_Host *shost, spinlock_t *lock)
537 {
538         shost->host_lock = lock;
539 }
540
541 static inline void scsi_set_device(struct Scsi_Host *shost,
542                                    struct device *dev)
543 {
544         shost->shost_gendev.parent = dev;
545 }
546
547 static inline struct device *scsi_get_device(struct Scsi_Host *shost)
548 {
549         return shost->shost_gendev.parent;
550 }
551
552 extern void scsi_unblock_requests(struct Scsi_Host *);
553 extern void scsi_block_requests(struct Scsi_Host *);
554
555 /*
556  * These two functions are used to allocate and free a pseudo device
557  * which will connect to the host adapter itself rather than any
558  * physical device.  You must deallocate when you are done with the
559  * thing.  This physical pseudo-device isn't real and won't be available
560  * from any high-level drivers.
561  */
562 extern void scsi_free_host_dev(struct scsi_device *);
563 extern struct scsi_device *scsi_get_host_dev(struct Scsi_Host *);
564
565 /* legacy interfaces */
566 extern struct Scsi_Host *scsi_register(struct scsi_host_template *, int);
567 extern void scsi_unregister(struct Scsi_Host *);
568
569 #endif /* _SCSI_SCSI_HOST_H */