import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / drivers / scsi / hosts.h
1 /*
2  *  hosts.h Copyright (C) 1992 Drew Eckhardt
3  *          Copyright (C) 1993, 1994, 1995, 1998, 1999 Eric Youngdale
4  *
5  *  mid to low-level SCSI driver interface header
6  *      Initial versions: Drew Eckhardt
7  *      Subsequent revisions: Eric Youngdale
8  *
9  *  <drew@colorado.edu>
10  *
11  *       Modified by Eric Youngdale eric@andante.org to
12  *       add scatter-gather, multiple outstanding request, and other
13  *       enhancements.
14  *
15  *  Further modified by Eric Youngdale to support multiple host adapters
16  *  of the same type.
17  *
18  *  Jiffies wrap fixes (host->resetting), 3 Dec 1998 Andrea Arcangeli
19  */
20
21 #ifndef _HOSTS_H
22 #define _HOSTS_H
23
24 /*
25     $Header: /vger/u4/cvs/linux/drivers/scsi/hosts.h,v 1.6 1997/01/19 23:07:13 davem Exp $
26 */
27
28 #include <linux/config.h>
29 #include <linux/proc_fs.h>
30 #include <linux/pci.h>
31
32 /* It is senseless to set SG_ALL any higher than this - the performance
33  *  does not get any better, and it wastes memory
34  */
35 #define SG_NONE 0
36 #define SG_ALL 0xff
37
38 #define DISABLE_CLUSTERING 0
39 #define ENABLE_CLUSTERING 1
40
41 /* The various choices mean:
42  * NONE: Self evident.  Host adapter is not capable of scatter-gather.
43  * ALL:  Means that the host adapter module can do scatter-gather,
44  *       and that there is no limit to the size of the table to which
45  *       we scatter/gather data.
46  * Anything else:  Indicates the maximum number of chains that can be
47  *       used in one scatter-gather request.
48  */
49
50 /*
51  * The Scsi_Host_Template type has all that is needed to interface with a SCSI
52  * host in a device independent matter.  There is one entry for each different
53  * type of host adapter that is supported on the system.
54  */
55
56 typedef struct scsi_disk Disk;
57
58 typedef struct  SHT
59 {
60
61     /* Used with loadable modules so we can construct a linked list. */
62     struct SHT * next;
63
64     /* Used with loadable modules so that we know when it is safe to unload */
65     struct module * module;
66
67     /* The pointer to the /proc/scsi directory entry */
68     struct proc_dir_entry *proc_dir;
69
70     /* proc-fs info function.
71      * Can be used to export driver statistics and other infos to the world
72      * outside the kernel ie. userspace and it also provides an interface
73      * to feed the driver with information. Check eata_dma_proc.c for reference
74      */
75     int (*proc_info)(char *, char **, off_t, int, int, int);
76
77     /*
78      * The name pointer is a pointer to the name of the SCSI
79      * device detected.
80      */
81     const char *name;
82
83     /*
84      * The detect function shall return non zero on detection,
85      * indicating the number of host adapters of this particular
86      * type were found.  It should also
87      * initialize all data necessary for this particular
88      * SCSI driver.  It is passed the host number, so this host
89      * knows where the first entry is in the scsi_hosts[] array.
90      *
91      * Note that the detect routine MUST not call any of the mid level
92      * functions to queue commands because things are not guaranteed
93      * to be set up yet.  The detect routine can send commands to
94      * the host adapter as long as the program control will not be
95      * passed to scsi.c in the processing of the command.  Note
96      * especially that scsi_malloc/scsi_free must not be called.
97      */
98     int (* detect)(struct SHT *);
99
100     int (*revoke)(Scsi_Device *);
101
102     /* Used with loadable modules to unload the host structures.  Note:
103      * there is a default action built into the modules code which may
104      * be sufficient for most host adapters.  Thus you may not have to supply
105      * this at all.
106      */
107     int (*release)(struct Scsi_Host *);
108
109     /*
110      * The info function will return whatever useful
111      * information the developer sees fit.  If not provided, then
112      * the name field will be used instead.
113      */
114     const char *(* info)(struct Scsi_Host *);
115
116     /*
117      * ioctl interface
118      */
119     int (*ioctl)(Scsi_Device *dev, int cmd, void *arg);
120
121     /*
122      * The command function takes a target, a command (this is a SCSI
123      * command formatted as per the SCSI spec, nothing strange), a
124      * data buffer pointer, and data buffer length pointer.  The return
125      * is a status int, bit fielded as follows :
126      * Byte What
127      * 0    SCSI status code
128      * 1    SCSI 1 byte message
129      * 2    host error return.
130      * 3    mid level error return
131      */
132     int (* command)(Scsi_Cmnd *);
133
134     /*
135      * The QueueCommand function works in a similar manner
136      * to the command function.  It takes an additional parameter,
137      * void (* done)(int host, int code) which is passed the host
138      * # and exit result when the command is complete.
139      * Host number is the POSITION IN THE hosts array of THIS
140      * host adapter.
141      *
142      * The done() function must only be called after QueueCommand() 
143      * has returned.
144      */
145     int (* queuecommand)(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
146
147     /*
148      * This is an error handling strategy routine.  You don't need to
149      * define one of these if you don't want to - there is a default
150      * routine that is present that should work in most cases.  For those
151      * driver authors that have the inclination and ability to write their
152      * own strategy routine, this is where it is specified.  Note - the
153      * strategy routine is *ALWAYS* run in the context of the kernel eh
154      * thread.  Thus you are guaranteed to *NOT* be in an interrupt handler
155      * when you execute this, and you are also guaranteed to *NOT* have any
156      * other commands being queued while you are in the strategy routine.
157      * When you return from this function, operations return to normal.
158      *
159      * See scsi_error.c scsi_unjam_host for additional comments about what
160      * this function should and should not be attempting to do.
161      */
162      int (*eh_strategy_handler)(struct Scsi_Host *);
163      int (*eh_abort_handler)(Scsi_Cmnd *);
164      int (*eh_device_reset_handler)(Scsi_Cmnd *);
165      int (*eh_bus_reset_handler)(Scsi_Cmnd *);
166      int (*eh_host_reset_handler)(Scsi_Cmnd *);
167
168     /*
169      * Since the mid level driver handles time outs, etc, we want to
170      * be able to abort the current command.  Abort returns 0 if the
171      * abortion was successful.  The field SCpnt->abort reason
172      * can be filled in with the appropriate reason why we wanted
173      * the abort in the first place, and this will be used
174      * in the mid-level code instead of the host_byte().
175      * If non-zero, the code passed to it
176      * will be used as the return code, otherwise
177      * DID_ABORT  should be returned.
178      *
179      * Note that the scsi driver should "clean up" after itself,
180      * resetting the bus, etc.  if necessary.
181      *
182      * NOTE - this interface is depreciated, and will go away.  Use
183      * the eh_ routines instead.
184      */
185     int (* abort)(Scsi_Cmnd *);
186
187     /*
188      * The reset function will reset the SCSI bus.  Any executing
189      * commands should fail with a DID_RESET in the host byte.
190      * The Scsi_Cmnd  is passed so that the reset routine can figure
191      * out which host adapter should be reset, and also which command
192      * within the command block was responsible for the reset in
193      * the first place.  Some hosts do not implement a reset function,
194      * and these hosts must call scsi_request_sense(SCpnt) to keep
195      * the command alive.
196      *
197      * NOTE - this interface is depreciated, and will go away.  Use
198      * the eh_ routines instead.
199      */
200     int (* reset)(Scsi_Cmnd *, unsigned int);
201
202     /*
203      * This function is used to select synchronous communications,
204      * which will result in a higher data throughput.  Not implemented
205      * yet.
206      */
207     int (* slave_attach)(int, int);
208
209     /*
210      * This function determines the bios parameters for a given
211      * harddisk.  These tend to be numbers that are made up by
212      * the host adapter.  Parameters:
213      * size, device number, list (heads, sectors, cylinders)
214      */
215     int (* bios_param)(Disk *, kdev_t, int []);
216
217
218     /*
219      * Used to set the queue depth for a specific device.
220      */
221     void (*select_queue_depths)(struct Scsi_Host *, Scsi_Device *);
222
223     /*
224      * This determines if we will use a non-interrupt driven
225      * or an interrupt driven scheme,  It is set to the maximum number
226      * of simultaneous commands a given host adapter will accept.
227      */
228     int can_queue;
229
230     /*
231      * In many instances, especially where disconnect / reconnect are
232      * supported, our host also has an ID on the SCSI bus.  If this is
233      * the case, then it must be reserved.  Please set this_id to -1 if
234      * your setup is in single initiator mode, and the host lacks an
235      * ID.
236      */
237     int this_id;
238
239     /*
240      * This determines the degree to which the host adapter is capable
241      * of scatter-gather.
242      */
243     short unsigned int sg_tablesize;
244
245     /*
246      * if the host adapter has limitations beside segment count
247      */
248     short unsigned int max_sectors;
249
250     /*
251      * True if this host adapter can make good use of linked commands.
252      * This will allow more than one command to be queued to a given
253      * unit on a given host.  Set this to the maximum number of command
254      * blocks to be provided for each device.  Set this to 1 for one
255      * command block per lun, 2 for two, etc.  Do not set this to 0.
256      * You should make sure that the host adapter will do the right thing
257      * before you try setting this above 1.
258      */
259     short cmd_per_lun;
260
261     /*
262      * present contains counter indicating how many boards of this
263      * type were found when we did the scan.
264      */
265     unsigned char present;
266
267     /*
268      * true if this host adapter uses unchecked DMA onto an ISA bus.
269      */
270     unsigned unchecked_isa_dma:1;
271
272     /*
273      * true if this host adapter can make good use of clustering.
274      * I originally thought that if the tablesize was large that it
275      * was a waste of CPU cycles to prepare a cluster list, but
276      * it works out that the Buslogic is faster if you use a smaller
277      * number of segments (i.e. use clustering).  I guess it is
278      * inefficient.
279      */
280     unsigned use_clustering:1;
281
282     /*
283      * True if this driver uses the new error handling code.  This flag is
284      * really only temporary until all of the other drivers get converted
285      * to use the new error handling code.
286      */
287     unsigned use_new_eh_code:1;
288
289     /*
290      * True for emulated SCSI host adapters (e.g. ATAPI)
291      */
292     unsigned emulated:1;
293
294     /*
295      * True for drivers that can do I/O from highmem
296      */
297     unsigned highmem_io:1;
298
299     /*
300      * Name of proc directory
301      */
302     char *proc_name;
303
304 } Scsi_Host_Template;
305
306 /*
307  * The scsi_hosts array is the array containing the data for all
308  * possible <supported> scsi hosts.   This is similar to the
309  * Scsi_Host_Template, except that we have one entry for each
310  * actual physical host adapter on the system, stored as a linked
311  * list.  Note that if there are 2 aha1542 boards, then there will
312  * be two Scsi_Host entries, but only 1 Scsi_Host_Template entry.
313  */
314
315 struct Scsi_Host
316 {
317 /* private: */
318     /*
319      * This information is private to the scsi mid-layer.  Wrapping it in a
320      * struct private is a way of marking it in a sort of C++ type of way.
321      */
322     struct Scsi_Host      * next;
323     Scsi_Device           * host_queue;
324
325
326     struct task_struct    * ehandler;  /* Error recovery thread. */
327     struct semaphore      * eh_wait;   /* The error recovery thread waits on
328                                           this. */
329     struct semaphore      * eh_notify; /* wait for eh to begin */
330     struct semaphore      * eh_action; /* Wait for specific actions on the
331                                           host. */
332     unsigned int            eh_active:1; /* Indicates the eh thread is awake and active if
333                                           this is true. */
334     wait_queue_head_t       host_wait;
335     Scsi_Host_Template    * hostt;
336     atomic_t                host_active; /* commands checked out */
337     volatile unsigned short host_busy;   /* commands actually active on low-level */
338     volatile unsigned short host_failed; /* commands that failed. */
339     
340 /* public: */
341     unsigned short extra_bytes;
342     unsigned short host_no;  /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
343     int resetting; /* if set, it means that last_reset is a valid value */
344     unsigned long last_reset;
345
346
347     /*
348      *  These three parameters can be used to allow for wide scsi,
349      *  and for host adapters that support multiple busses
350      *  The first two should be set to 1 more than the actual max id
351      *  or lun (i.e. 8 for normal systems).
352      */
353     unsigned int max_id;
354     unsigned int max_lun;
355     unsigned int max_channel;
356
357     /* These parameters should be set by the detect routine */
358     unsigned long base;
359     unsigned long io_port;
360     unsigned char n_io_port;
361     unsigned char dma_channel;
362     unsigned int  irq;
363
364     /*
365      * This is a unique identifier that must be assigned so that we
366      * have some way of identifying each detected host adapter properly
367      * and uniquely.  For hosts that do not support more than one card
368      * in the system at one time, this does not need to be set.  It is
369      * initialized to 0 in scsi_register.
370      */
371     unsigned int unique_id;
372
373     /*
374      * The rest can be copied from the template, or specifically
375      * initialized, as required.
376      */
377
378     /*
379      * The maximum length of SCSI commands that this host can accept.
380      * Probably 12 for most host adapters, but could be 16 for others.
381      * For drivers that don't set this field, a value of 12 is
382      * assumed.  I am leaving this as a number rather than a bit
383      * because you never know what subsequent SCSI standards might do
384      * (i.e. could there be a 20 byte or a 24-byte command a few years
385      * down the road?).  
386      */
387     unsigned char max_cmd_len;
388
389     int this_id;
390     int can_queue;
391     short cmd_per_lun;
392     short unsigned int sg_tablesize;
393     short unsigned int max_sectors;
394
395     unsigned in_recovery:1;
396     unsigned unchecked_isa_dma:1;
397     unsigned use_clustering:1;
398     unsigned highmem_io:1;
399
400     /*
401      * True if this host was loaded as a loadable module
402      */
403     unsigned loaded_as_module:1;
404
405     /*
406      * Host has rejected a command because it was busy.
407      */
408     unsigned host_blocked:1;
409
410     /*
411      * Host has requested that no further requests come through for the
412      * time being.
413      */
414     unsigned host_self_blocked:1;
415     
416     /*
417      * Host uses correct SCSI ordering not PC ordering. The bit is
418      * set for the minority of drivers whose authors actually read the spec ;)
419      */
420     unsigned reverse_ordering:1;
421
422     /*
423      * Indicates that one or more devices on this host were starved, and
424      * when the device becomes less busy that we need to feed them.
425      */
426     unsigned some_device_starved:1;
427    
428     void (*select_queue_depths)(struct Scsi_Host *, Scsi_Device *);
429
430     /*
431      * For SCSI hosts which are PCI devices, set pci_dev so that
432      * we can do BIOS EDD 3.0 mappings
433      */
434     struct pci_dev *pci_dev;
435
436     /*
437      * We should ensure that this is aligned, both for better performance
438      * and also because some compilers (m68k) don't automatically force
439      * alignment to a long boundary.
440      */
441     unsigned long hostdata[0]  /* Used for storage of host specific stuff */
442         __attribute__ ((aligned (sizeof(unsigned long))));
443 };
444
445 /*
446  * These two functions are used to allocate and free a pseudo device
447  * which will connect to the host adapter itself rather than any
448  * physical device.  You must deallocate when you are done with the
449  * thing.  This physical pseudo-device isn't real and won't be available
450  * from any high-level drivers.
451  */
452 extern void scsi_free_host_dev(Scsi_Device * SDpnt);
453 extern Scsi_Device * scsi_get_host_dev(struct Scsi_Host * SHpnt);
454
455 extern void scsi_unblock_requests(struct Scsi_Host * SHpnt);
456 extern void scsi_block_requests(struct Scsi_Host * SHpnt);
457 extern void scsi_report_bus_reset(struct Scsi_Host * SHpnt, int channel);
458
459 typedef struct SHN
460     {
461     struct SHN * next;
462     char * name;
463     unsigned short host_no;
464     unsigned short host_registered;
465     unsigned loaded_as_module;
466     } Scsi_Host_Name;
467         
468 extern Scsi_Host_Name * scsi_host_no_list;
469 extern struct Scsi_Host * scsi_hostlist;
470 extern struct Scsi_Device_Template * scsi_devicelist;
471
472 extern Scsi_Host_Template * scsi_hosts;
473
474 extern void build_proc_dir_entries(Scsi_Host_Template  *);
475
476 /*
477  *  scsi_init initializes the scsi hosts.
478  */
479
480 extern int next_scsi_host;
481
482 unsigned int scsi_init(void);
483 extern struct Scsi_Host * scsi_register(Scsi_Host_Template *, int j);
484 extern void scsi_unregister(struct Scsi_Host * i);
485
486 extern void scsi_register_blocked_host(struct Scsi_Host * SHpnt);
487 extern void scsi_deregister_blocked_host(struct Scsi_Host * SHpnt);
488
489 static inline void scsi_set_pci_device(struct Scsi_Host *SHpnt,
490                                        struct pci_dev *pdev)
491 {
492         SHpnt->pci_dev = pdev;
493 }
494
495
496 /*
497  * Prototypes for functions/data in scsi_scan.c
498  */
499 extern void scan_scsis(struct Scsi_Host *shpnt,
500                        uint hardcoded,
501                        uint hchannel,
502                        uint hid,
503                        uint hlun);
504
505 extern void scsi_mark_host_reset(struct Scsi_Host *Host);
506
507 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
508
509 struct Scsi_Device_Template
510 {
511     struct Scsi_Device_Template * next;
512     const char * name;
513     const char * tag;
514     struct module * module;       /* Used for loadable modules */
515     unsigned char scsi_type;
516     unsigned int major;
517     unsigned int min_major;      /* Minimum major in range. */ 
518     unsigned int max_major;      /* Maximum major in range. */
519     unsigned int nr_dev;          /* Number currently attached */
520     unsigned int dev_noticed;     /* Number of devices detected. */
521     unsigned int dev_max;         /* Current size of arrays */
522     unsigned blk:1;               /* 0 if character device */
523     int (*detect)(Scsi_Device *); /* Returns 1 if we can attach this device */
524     int (*init)(void);            /* Sizes arrays based upon number of devices
525                    *  detected */
526     void (*finish)(void);         /* Perform initialization after attachment */
527     int (*attach)(Scsi_Device *); /* Attach devices to arrays */
528     void (*detach)(Scsi_Device *);
529     int (*init_command)(Scsi_Cmnd *);     /* Used by new queueing code. 
530                                            Selects command for blkdevs */
531 };
532
533 void  scsi_initialize_queue(Scsi_Device * SDpnt, struct Scsi_Host * SHpnt);
534
535 int scsi_register_device(struct Scsi_Device_Template * sdpnt);
536 void scsi_deregister_device(struct Scsi_Device_Template * tpnt);
537
538 /* These are used by loadable modules */
539 extern int scsi_register_module(int, void *);
540 extern int scsi_unregister_module(int, void *);
541
542 /* The different types of modules that we can load and unload */
543 #define MODULE_SCSI_HA 1
544 #define MODULE_SCSI_CONST 2
545 #define MODULE_SCSI_IOCTL 3
546 #define MODULE_SCSI_DEV 4
547
548
549 /*
550  * This is an ugly hack.  If we expect to be able to load devices at run time,
551  * we need to leave extra room in some of the data structures.  Doing a
552  * realloc to enlarge the structures would be riddled with race conditions,
553  * so until a better solution is discovered, we use this crude approach
554  *
555  * Even bigger hack for SparcSTORAGE arrays. Those are at least 6 disks, but
556  * usually up to 30 disks, so everyone would need to change this. -jj
557  *
558  * Note: These things are all evil and all need to go away.  My plan is to
559  * tackle the character devices first, as there aren't any locking implications
560  * in the block device layer.   The block devices will require more work.
561  *
562  * The generics driver has been updated to resize as required.  So as the tape
563  * driver. Two down, two more to go.
564  */
565 #ifndef CONFIG_SD_EXTRA_DEVS
566 #define CONFIG_SD_EXTRA_DEVS 2
567 #endif
568 #ifndef CONFIG_SR_EXTRA_DEVS
569 #define CONFIG_SR_EXTRA_DEVS 2
570 #endif
571 #define SD_EXTRA_DEVS CONFIG_SD_EXTRA_DEVS
572 #define SR_EXTRA_DEVS CONFIG_SR_EXTRA_DEVS
573
574 #endif
575 /*
576  * Overrides for Emacs so that we follow Linus's tabbing style.
577  * Emacs will notice this stuff at the end of the file and automatically
578  * adjust the settings for this buffer only.  This must remain at the end
579  * of the file.
580  * ---------------------------------------------------------------------------
581  * Local variables:
582  * c-indent-level: 4
583  * c-brace-imaginary-offset: 0
584  * c-brace-offset: -4
585  * c-argdecl-indent: 4
586  * c-label-offset: -4
587  * c-continued-statement-offset: 4
588  * c-continued-brace-offset: 0
589  * indent-tabs-mode: nil
590  * tab-width: 8
591  * End:
592  */