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