2 * hosts.h Copyright (C) 1992 Drew Eckhardt
3 * Copyright (C) 1993, 1994, 1995 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@aib.com to
12 * add scatter-gather, multiple outstanding request, and other
15 * Further modified by Eric Youngdale to support multiple host adapters
23 $Header: /vger/u4/cvs/linux/drivers/scsi/hosts.h,v 1.6 1997/01/19 23:07:13 davem Exp $
26 #include <linux/proc_fs.h>
28 /* It is senseless to set SG_ALL any higher than this - the performance
29 * does not get any better, and it wastes memory
34 #define DISABLE_CLUSTERING 0
35 #define ENABLE_CLUSTERING 1
37 /* The various choices mean:
38 * NONE: Self evident. Host adapter is not capable of scatter-gather.
39 * ALL: Means that the host adapter module can do scatter-gather,
40 * and that there is no limit to the size of the table to which
41 * we scatter/gather data.
42 * Anything else: Indicates the maximum number of chains that can be
43 * used in one scatter-gather request.
47 * The Scsi_Host_Template type has all that is needed to interface with a SCSI
48 * host in a device independent matter. There is one entry for each different
49 * type of host adapter that is supported on the system.
52 typedef struct scsi_disk Disk
;
57 /* Used with loadable modules so we can construct a linked list. */
60 /* Used with loadable modules so that we know when it is safe to unload */
61 struct module
* module
;
63 /* The pointer to the /proc/scsi directory entry */
64 struct proc_dir_entry
*proc_dir
;
66 /* proc-fs info function.
67 * Can be used to export driver statistics and other infos to the world
68 * outside the kernel ie. userspace and it also provides an interface
69 * to feed the driver with information. Check eata_dma_proc.c for reference
71 int (*proc_info
)(char *, char **, off_t
, int, int, int);
74 * The name pointer is a pointer to the name of the SCSI
80 * The detect function shall return non zero on detection,
81 * indicating the number of host adapters of this particular
82 * type were found. It should also
83 * initialize all data necessary for this particular
84 * SCSI driver. It is passed the host number, so this host
85 * knows where the first entry is in the scsi_hosts[] array.
87 * Note that the detect routine MUST not call any of the mid level
88 * functions to queue commands because things are not guaranteed
89 * to be set up yet. The detect routine can send commands to
90 * the host adapter as long as the program control will not be
91 * passed to scsi.c in the processing of the command. Note
92 * especially that scsi_malloc/scsi_free must not be called.
94 int (* detect
)(struct SHT
*);
96 /* Used with loadable modules to unload the host structures. Note:
97 * there is a default action built into the modules code which may
98 * be sufficient for most host adapters. Thus you may not have to supply
101 int (*release
)(struct Scsi_Host
*);
104 * The info function will return whatever useful
105 * information the developer sees fit. If not provided, then
106 * the name field will be used instead.
108 const char *(* info
)(struct Scsi_Host
*);
111 * The command function takes a target, a command (this is a SCSI
112 * command formatted as per the SCSI spec, nothing strange), a
113 * data buffer pointer, and data buffer length pointer. The return
114 * is a status int, bit fielded as follows :
117 * 1 SCSI 1 byte message
118 * 2 host error return.
119 * 3 mid level error return
121 int (* command
)(Scsi_Cmnd
*);
124 * The QueueCommand function works in a similar manner
125 * to the command function. It takes an additional parameter,
126 * void (* done)(int host, int code) which is passed the host
127 * # and exit result when the command is complete.
128 * Host number is the POSITION IN THE hosts array of THIS
131 * The done() function must only be called after QueueCommand()
134 int (* queuecommand
)(Scsi_Cmnd
*, void (*done
)(Scsi_Cmnd
*));
137 * This is an error handling strategy routine. You don't need to
138 * define one of these if you don't want to - there is a default
139 * routine that is present that should work in most cases. For those
140 * driver authors that have the inclination and ability to write their
141 * own strategy routine, this is where it is specified. Note - the
142 * strategy routine is *ALWAYS* run in the context of the kernel eh
143 * thread. Thus you are guaranteed to *NOT* be in an interrupt handler
144 * when you execute this, and you are also guaranteed to *NOT* have any
145 * other commands being queued while you are in the strategy routine.
146 * When you return from this function, operations return to normal.
148 * See scsi_error.c scsi_unjam_host for additional comments about what
149 * this function should and should not be attempting to do.
151 int (*eh_strategy_handler
)(struct Scsi_Host
*);
152 int (*eh_abort_handler
)(Scsi_Cmnd
*);
153 int (*eh_device_reset_handler
)(Scsi_Cmnd
*);
154 int (*eh_bus_reset_handler
)(Scsi_Cmnd
*);
155 int (*eh_host_reset_handler
)(Scsi_Cmnd
*);
158 * Since the mid level driver handles time outs, etc, we want to
159 * be able to abort the current command. Abort returns 0 if the
160 * abortion was successful. The field SCpnt->abort reason
161 * can be filled in with the appropriate reason why we wanted
162 * the abort in the first place, and this will be used
163 * in the mid-level code instead of the host_byte().
164 * If non-zero, the code passed to it
165 * will be used as the return code, otherwise
166 * DID_ABORT should be returned.
168 * Note that the scsi driver should "clean up" after itself,
169 * resetting the bus, etc. if necessary.
171 * NOTE - this interface is depreciated, and will go away. Use
172 * the eh_ routines instead.
174 int (* abort
)(Scsi_Cmnd
*);
177 * The reset function will reset the SCSI bus. Any executing
178 * commands should fail with a DID_RESET in the host byte.
179 * The Scsi_Cmnd is passed so that the reset routine can figure
180 * out which host adapter should be reset, and also which command
181 * within the command block was responsible for the reset in
182 * the first place. Some hosts do not implement a reset function,
183 * and these hosts must call scsi_request_sense(SCpnt) to keep
186 * NOTE - this interface is depreciated, and will go away. Use
187 * the eh_ routines instead.
189 int (* reset
)(Scsi_Cmnd
*, unsigned int);
192 * This function is used to select synchronous communications,
193 * which will result in a higher data throughput. Not implemented
196 int (* slave_attach
)(int, int);
199 * This function determines the bios parameters for a given
200 * harddisk. These tend to be numbers that are made up by
201 * the host adapter. Parameters:
202 * size, device number, list (heads, sectors, cylinders)
204 int (* bios_param
)(Disk
*, kdev_t
, int []);
207 * This determines if we will use a non-interrupt driven
208 * or an interrupt driven scheme, It is set to the maximum number
209 * of simultaneous commands a given host adapter will accept.
214 * In many instances, especially where disconnect / reconnect are
215 * supported, our host also has an ID on the SCSI bus. If this is
216 * the case, then it must be reserved. Please set this_id to -1 if
217 * your setup is in single initiator mode, and the host lacks an
223 * This determines the degree to which the host adapter is capable
226 short unsigned int sg_tablesize
;
229 * True if this host adapter can make good use of linked commands.
230 * This will allow more than one command to be queued to a given
231 * unit on a given host. Set this to the maximum number of command
232 * blocks to be provided for each device. Set this to 1 for one
233 * command block per lun, 2 for two, etc. Do not set this to 0.
234 * You should make sure that the host adapter will do the right thing
235 * before you try setting this above 1.
240 * present contains counter indicating how many boards of this
241 * type were found when we did the scan.
243 unsigned char present
;
246 * true if this host adapter uses unchecked DMA onto an ISA bus.
248 unsigned unchecked_isa_dma
:1;
251 * true if this host adapter can make good use of clustering.
252 * I originally thought that if the tablesize was large that it
253 * was a waste of CPU cycles to prepare a cluster list, but
254 * it works out that the Buslogic is faster if you use a smaller
255 * number of segments (i.e. use clustering). I guess it is
258 unsigned use_clustering
:1;
261 * True if this driver uses the new error handling code. This flag is
262 * really only temporary until all of the other drivers get converted
263 * to use the new error handling code.
265 unsigned use_new_eh_code
:1;
267 } Scsi_Host_Template
;
270 * The scsi_hosts array is the array containing the data for all
271 * possible <supported> scsi hosts. This is similar to the
272 * Scsi_Host_Template, except that we have one entry for each
273 * actual physical host adapter on the system, stored as a linked
274 * list. Note that if there are 2 aha1542 boards, then there will
275 * be two Scsi_Host entries, but only 1 Scsi_Host_Template entry.
282 * This information is private to the scsi mid-layer. Wrapping it in a
283 * struct private is a way of marking it in a sort of C++ type of way.
285 struct Scsi_Host
* next
;
286 Scsi_Device
* host_queue
;
288 * List of commands that have been rejected because either the host
289 * or the device was busy. These need to be retried relatively quickly,
290 * but we need to hold onto it for a short period until the host/device
293 Scsi_Cmnd
* pending_commands
;
295 struct task_struct
* ehandler
; /* Error recovery thread. */
296 struct semaphore
* eh_wait
; /* The error recovery thread waits on
298 struct semaphore
* eh_notify
; /* wait for eh to begin */
299 struct semaphore
* eh_action
; /* Wait for specific actions on the
301 unsigned int eh_active
:1; /* Indicates the eh thread is awake and active if
303 struct wait_queue
* host_wait
;
304 Scsi_Host_Template
* hostt
;
305 atomic_t host_active
; /* commands checked out */
306 volatile unsigned short host_busy
; /* commands actually active on low-level */
307 volatile unsigned short host_failed
; /* commands that failed. */
310 unsigned short extra_bytes
;
311 unsigned short host_no
; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
312 unsigned long last_reset
;
316 * These three parameters can be used to allow for wide scsi,
317 * and for host adapters that support multiple busses
318 * The first two should be set to 1 more than the actual max id
319 * or lun (i.e. 8 for normal systems).
322 unsigned int max_lun
;
323 unsigned int max_channel
;
326 * Pointer to a circularly linked list - this indicates the hosts
327 * that should be locked out of performing I/O while we have an active
328 * command on this host.
330 struct Scsi_Host
* block
;
331 unsigned wish_block
:1;
333 /* These parameters should be set by the detect routine */
335 unsigned int io_port
;
336 unsigned char n_io_port
;
338 unsigned char dma_channel
;
341 * This is a unique identifier that must be assigned so that we
342 * have some way of identifying each detected host adapter properly
343 * and uniquely. For hosts that do not support more than one card
344 * in the system at one time, this does not need to be set. It is
345 * initialized to 0 in scsi_register.
347 unsigned int unique_id
;
350 * The rest can be copied from the template, or specifically
351 * initialized, as required.
357 short unsigned int sg_tablesize
;
359 unsigned in_recovery
:1;
360 unsigned unchecked_isa_dma
:1;
361 unsigned use_clustering
:1;
363 * True if this host was loaded as a loadable module
365 unsigned loaded_as_module
:1;
368 * Host has rejected a command because it was busy.
370 unsigned host_blocked
:1;
372 void (*select_queue_depths
)(struct Scsi_Host
*, Scsi_Device
*);
374 unsigned long hostdata
[0]; /* Used for storage of host specific stuff */
377 extern struct Scsi_Host
* scsi_hostlist
;
378 extern struct Scsi_Device_Template
* scsi_devicelist
;
380 extern Scsi_Host_Template
* scsi_hosts
;
382 extern void build_proc_dir_entries(Scsi_Host_Template
*);
386 * scsi_init initializes the scsi hosts.
390 * We use these goofy things because the MM is not set up when we init
391 * the scsi subsystem. By using these functions we can write code that
392 * looks normal. Also, it makes it possible to use the same code for a
396 extern void * scsi_init_malloc(unsigned int size
, int priority
);
397 extern void scsi_init_free(char * ptr
, unsigned int size
);
399 extern int next_scsi_host
;
401 extern int scsi_loadable_module_flag
;
402 unsigned int scsi_init(void);
403 extern struct Scsi_Host
* scsi_register(Scsi_Host_Template
*, int j
);
404 extern void scsi_unregister(struct Scsi_Host
* i
);
406 extern void scsi_mark_host_reset(struct Scsi_Host
*Host
);
408 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
410 struct Scsi_Device_Template
412 struct Scsi_Device_Template
* next
;
415 struct module
* module
; /* Used for loadable modules */
416 unsigned char scsi_type
;
418 unsigned char nr_dev
; /* Number currently attached */
419 unsigned char dev_noticed
; /* Number of devices detected. */
420 unsigned char dev_max
; /* Current size of arrays */
421 unsigned blk
:1; /* 0 if character device */
422 int (*detect
)(Scsi_Device
*); /* Returns 1 if we can attach this device */
423 int (*init
)(void); /* Sizes arrays based upon number of devices
425 void (*finish
)(void); /* Perform initialization after attachment */
426 int (*attach
)(Scsi_Device
*); /* Attach devices to arrays */
427 void (*detach
)(Scsi_Device
*);
430 extern struct Scsi_Device_Template sd_template
;
431 extern struct Scsi_Device_Template st_template
;
432 extern struct Scsi_Device_Template sr_template
;
433 extern struct Scsi_Device_Template sg_template
;
435 int scsi_register_device(struct Scsi_Device_Template
* sdpnt
);
437 /* These are used by loadable modules */
438 extern int scsi_register_module(int, void *);
439 extern void scsi_unregister_module(int, void *);
441 /* The different types of modules that we can load and unload */
442 #define MODULE_SCSI_HA 1
443 #define MODULE_SCSI_CONST 2
444 #define MODULE_SCSI_IOCTL 3
445 #define MODULE_SCSI_DEV 4
449 * This is an ugly hack. If we expect to be able to load devices at run time,
450 * we need to leave extra room in some of the data structures. Doing a
451 * realloc to enlarge the structures would be riddled with race conditions,
452 * so until a better solution is discovered, we use this crude approach
454 #define SD_EXTRA_DEVS 2
455 #define ST_EXTRA_DEVS 2
456 #define SR_EXTRA_DEVS 2
457 #define SG_EXTRA_DEVS (SD_EXTRA_DEVS + SR_EXTRA_DEVS + ST_EXTRA_DEVS)
461 * Overrides for Emacs so that we follow Linus's tabbing style.
462 * Emacs will notice this stuff at the end of the file and automatically
463 * adjust the settings for this buffer only. This must remain at the end
465 * ---------------------------------------------------------------------------
468 * c-brace-imaginary-offset: 0
470 * c-argdecl-indent: 4
472 * c-continued-statement-offset: 4
473 * c-continued-brace-offset: 0
474 * indent-tabs-mode: nil