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
11 * Modified by Eric Youngdale eric@andante.org to
12 * add scatter-gather, multiple outstanding request, and other
15 * Further modified by Eric Youngdale to support multiple host adapters
18 * Jiffies wrap fixes (host->resetting), 3 Dec 1998 Andrea Arcangeli
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>
30 #include <linux/pci.h>
32 /* It is senseless to set SG_ALL any higher than this - the performance
33 * does not get any better, and it wastes memory
38 #define DISABLE_CLUSTERING 0
39 #define ENABLE_CLUSTERING 1
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.
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.
56 typedef struct scsi_disk Disk;
61 /* Used with loadable modules so we can construct a linked list. */
64 /* Used with loadable modules so that we know when it is safe to unload */
65 struct module * module;
67 /* The pointer to the /proc/scsi directory entry */
68 struct proc_dir_entry *proc_dir;
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
75 int (*proc_info)(char *, char **, off_t, int, int, int);
78 * The name pointer is a pointer to the name of the SCSI
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.
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.
98 int (* detect)(struct SHT *);
100 int (*revoke)(Scsi_Device *);
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
107 int (*release)(struct Scsi_Host *);
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.
114 const char *(* info)(struct Scsi_Host *);
119 int (*ioctl)(Scsi_Device *dev, int cmd, void *arg);
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 :
128 * 1 SCSI 1 byte message
129 * 2 host error return.
130 * 3 mid level error return
132 int (* command)(Scsi_Cmnd *);
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
142 * The done() function must only be called after QueueCommand()
145 int (* queuecommand)(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
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.
159 * See scsi_error.c scsi_unjam_host for additional comments about what
160 * this function should and should not be attempting to do.
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 *);
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.
179 * Note that the scsi driver should "clean up" after itself,
180 * resetting the bus, etc. if necessary.
182 * NOTE - this interface is depreciated, and will go away. Use
183 * the eh_ routines instead.
185 int (* abort)(Scsi_Cmnd *);
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
197 * NOTE - this interface is depreciated, and will go away. Use
198 * the eh_ routines instead.
200 int (* reset)(Scsi_Cmnd *, unsigned int);
203 * This function is used to select synchronous communications,
204 * which will result in a higher data throughput. Not implemented
207 int (* slave_attach)(int, int);
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)
215 int (* bios_param)(Disk *, kdev_t, int []);
219 * Used to set the queue depth for a specific device.
221 void (*select_queue_depths)(struct Scsi_Host *, Scsi_Device *);
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.
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
240 * This determines the degree to which the host adapter is capable
243 short unsigned int sg_tablesize;
246 * if the host adapter has limitations beside segment count
248 short unsigned int max_sectors;
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.
262 * present contains counter indicating how many boards of this
263 * type were found when we did the scan.
265 unsigned char present;
268 * true if this host adapter uses unchecked DMA onto an ISA bus.
270 unsigned unchecked_isa_dma:1;
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
280 unsigned use_clustering:1;
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.
287 unsigned use_new_eh_code:1;
290 * True for emulated SCSI host adapters (e.g. ATAPI)
295 * True for drivers that can do I/O from highmem
297 unsigned highmem_io:1;
300 * Name of proc directory
304 } Scsi_Host_Template;
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.
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.
322 struct Scsi_Host * next;
323 Scsi_Device * host_queue;
326 struct task_struct * ehandler; /* Error recovery thread. */
327 struct semaphore * eh_wait; /* The error recovery thread waits on
329 struct semaphore * eh_notify; /* wait for eh to begin */
330 struct semaphore * eh_action; /* Wait for specific actions on the
332 unsigned int eh_active:1; /* Indicates the eh thread is awake and active if
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. */
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;
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).
354 unsigned int max_lun;
355 unsigned int max_channel;
357 /* These parameters should be set by the detect routine */
359 unsigned long io_port;
360 unsigned char n_io_port;
361 unsigned char dma_channel;
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.
371 unsigned int unique_id;
374 * The rest can be copied from the template, or specifically
375 * initialized, as required.
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
387 unsigned char max_cmd_len;
392 short unsigned int sg_tablesize;
393 short unsigned int max_sectors;
395 unsigned in_recovery:1;
396 unsigned unchecked_isa_dma:1;
397 unsigned use_clustering:1;
398 unsigned highmem_io:1;
401 * True if this host was loaded as a loadable module
403 unsigned loaded_as_module:1;
406 * Host has rejected a command because it was busy.
408 unsigned host_blocked:1;
411 * Host has requested that no further requests come through for the
414 unsigned host_self_blocked:1;
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 ;)
420 unsigned reverse_ordering:1;
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.
426 unsigned some_device_starved:1;
428 void (*select_queue_depths)(struct Scsi_Host *, Scsi_Device *);
431 * For SCSI hosts which are PCI devices, set pci_dev so that
432 * we can do BIOS EDD 3.0 mappings
434 struct pci_dev *pci_dev;
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.
441 unsigned long hostdata[0] /* Used for storage of host specific stuff */
442 __attribute__ ((aligned (sizeof(unsigned long))));
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.
452 extern void scsi_free_host_dev(Scsi_Device * SDpnt);
453 extern Scsi_Device * scsi_get_host_dev(struct Scsi_Host * SHpnt);
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);
463 unsigned short host_no;
464 unsigned short host_registered;
465 unsigned loaded_as_module;
468 extern Scsi_Host_Name * scsi_host_no_list;
469 extern struct Scsi_Host * scsi_hostlist;
470 extern struct Scsi_Device_Template * scsi_devicelist;
472 extern Scsi_Host_Template * scsi_hosts;
474 extern void build_proc_dir_entries(Scsi_Host_Template *);
477 * scsi_init initializes the scsi hosts.
480 extern int next_scsi_host;
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);
486 extern void scsi_register_blocked_host(struct Scsi_Host * SHpnt);
487 extern void scsi_deregister_blocked_host(struct Scsi_Host * SHpnt);
489 static inline void scsi_set_pci_device(struct Scsi_Host *SHpnt,
490 struct pci_dev *pdev)
492 SHpnt->pci_dev = pdev;
497 * Prototypes for functions/data in scsi_scan.c
499 extern void scan_scsis(struct Scsi_Host *shpnt,
505 extern void scsi_mark_host_reset(struct Scsi_Host *Host);
507 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
509 struct Scsi_Device_Template
511 struct Scsi_Device_Template * next;
514 struct module * module; /* Used for loadable modules */
515 unsigned char scsi_type;
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
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 */
533 void scsi_initialize_queue(Scsi_Device * SDpnt, struct Scsi_Host * SHpnt);
535 int scsi_register_device(struct Scsi_Device_Template * sdpnt);
536 void scsi_deregister_device(struct Scsi_Device_Template * tpnt);
538 /* These are used by loadable modules */
539 extern int scsi_register_module(int, void *);
540 extern int scsi_unregister_module(int, void *);
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
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
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
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.
562 * The generics driver has been updated to resize as required. So as the tape
563 * driver. Two down, two more to go.
565 #ifndef CONFIG_SD_EXTRA_DEVS
566 #define CONFIG_SD_EXTRA_DEVS 2
568 #ifndef CONFIG_SR_EXTRA_DEVS
569 #define CONFIG_SR_EXTRA_DEVS 2
571 #define SD_EXTRA_DEVS CONFIG_SD_EXTRA_DEVS
572 #define SR_EXTRA_DEVS CONFIG_SR_EXTRA_DEVS
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
580 * ---------------------------------------------------------------------------
583 * c-brace-imaginary-offset: 0
585 * c-argdecl-indent: 4
587 * c-continued-statement-offset: 4
588 * c-continued-brace-offset: 0
589 * indent-tabs-mode: nil