File: /usr/src/linux/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 * Name of proc directory
296 */
297 char *proc_name;
298
299 } Scsi_Host_Template;
300
301 /*
302 * The scsi_hosts array is the array containing the data for all
303 * possible <supported> scsi hosts. This is similar to the
304 * Scsi_Host_Template, except that we have one entry for each
305 * actual physical host adapter on the system, stored as a linked
306 * list. Note that if there are 2 aha1542 boards, then there will
307 * be two Scsi_Host entries, but only 1 Scsi_Host_Template entry.
308 */
309
310 struct Scsi_Host
311 {
312 /* private: */
313 /*
314 * This information is private to the scsi mid-layer. Wrapping it in a
315 * struct private is a way of marking it in a sort of C++ type of way.
316 */
317 struct Scsi_Host * next;
318 Scsi_Device * host_queue;
319
320
321 struct task_struct * ehandler; /* Error recovery thread. */
322 struct semaphore * eh_wait; /* The error recovery thread waits on
323 this. */
324 struct semaphore * eh_notify; /* wait for eh to begin */
325 struct semaphore * eh_action; /* Wait for specific actions on the
326 host. */
327 unsigned int eh_active:1; /* Indicates the eh thread is awake and active if
328 this is true. */
329 wait_queue_head_t host_wait;
330 Scsi_Host_Template * hostt;
331 atomic_t host_active; /* commands checked out */
332 volatile unsigned short host_busy; /* commands actually active on low-level */
333 volatile unsigned short host_failed; /* commands that failed. */
334
335 /* public: */
336 unsigned short extra_bytes;
337 unsigned short host_no; /* Used for IOCTL_GET_IDLUN, /proc/scsi et al. */
338 int resetting; /* if set, it means that last_reset is a valid value */
339 unsigned long last_reset;
340
341
342 /*
343 * These three parameters can be used to allow for wide scsi,
344 * and for host adapters that support multiple busses
345 * The first two should be set to 1 more than the actual max id
346 * or lun (i.e. 8 for normal systems).
347 */
348 unsigned int max_id;
349 unsigned int max_lun;
350 unsigned int max_channel;
351
352 /* These parameters should be set by the detect routine */
353 unsigned long base;
354 unsigned long io_port;
355 unsigned char n_io_port;
356 unsigned char dma_channel;
357 unsigned int irq;
358
359 /*
360 * This is a unique identifier that must be assigned so that we
361 * have some way of identifying each detected host adapter properly
362 * and uniquely. For hosts that do not support more than one card
363 * in the system at one time, this does not need to be set. It is
364 * initialized to 0 in scsi_register.
365 */
366 unsigned int unique_id;
367
368 /*
369 * The rest can be copied from the template, or specifically
370 * initialized, as required.
371 */
372
373 /*
374 * The maximum length of SCSI commands that this host can accept.
375 * Probably 12 for most host adapters, but could be 16 for others.
376 * For drivers that don't set this field, a value of 12 is
377 * assumed. I am leaving this as a number rather than a bit
378 * because you never know what subsequent SCSI standards might do
379 * (i.e. could there be a 20 byte or a 24-byte command a few years
380 * down the road?).
381 */
382 unsigned char max_cmd_len;
383
384 int this_id;
385 int can_queue;
386 short cmd_per_lun;
387 short unsigned int sg_tablesize;
388 short unsigned int max_sectors;
389
390 unsigned in_recovery:1;
391 unsigned unchecked_isa_dma:1;
392 unsigned use_clustering:1;
393 /*
394 * True if this host was loaded as a loadable module
395 */
396 unsigned loaded_as_module:1;
397
398 /*
399 * Host has rejected a command because it was busy.
400 */
401 unsigned host_blocked:1;
402
403 /*
404 * Host has requested that no further requests come through for the
405 * time being.
406 */
407 unsigned host_self_blocked:1;
408
409 /*
410 * Host uses correct SCSI ordering not PC ordering. The bit is
411 * set for the minority of drivers whose authors actually read the spec ;)
412 */
413 unsigned reverse_ordering:1;
414
415 /*
416 * Indicates that one or more devices on this host were starved, and
417 * when the device becomes less busy that we need to feed them.
418 */
419 unsigned some_device_starved:1;
420
421 void (*select_queue_depths)(struct Scsi_Host *, Scsi_Device *);
422
423 /*
424 * For SCSI hosts which are PCI devices, set pci_dev so that
425 * we can do BIOS EDD 3.0 mappings
426 */
427 struct pci_dev *pci_dev;
428
429 /*
430 * We should ensure that this is aligned, both for better performance
431 * and also because some compilers (m68k) don't automatically force
432 * alignment to a long boundary.
433 */
434 unsigned long hostdata[0] /* Used for storage of host specific stuff */
435 __attribute__ ((aligned (sizeof(unsigned long))));
436 };
437
438 /*
439 * These two functions are used to allocate and free a pseudo device
440 * which will connect to the host adapter itself rather than any
441 * physical device. You must deallocate when you are done with the
442 * thing. This physical pseudo-device isn't real and won't be available
443 * from any high-level drivers.
444 */
445 extern void scsi_free_host_dev(Scsi_Device * SDpnt);
446 extern Scsi_Device * scsi_get_host_dev(struct Scsi_Host * SHpnt);
447
448 extern void scsi_unblock_requests(struct Scsi_Host * SHpnt);
449 extern void scsi_block_requests(struct Scsi_Host * SHpnt);
450 extern void scsi_report_bus_reset(struct Scsi_Host * SHpnt, int channel);
451
452 typedef struct SHN
453 {
454 struct SHN * next;
455 char * name;
456 unsigned short host_no;
457 unsigned short host_registered;
458 unsigned loaded_as_module;
459 } Scsi_Host_Name;
460
461 extern Scsi_Host_Name * scsi_host_no_list;
462 extern struct Scsi_Host * scsi_hostlist;
463 extern struct Scsi_Device_Template * scsi_devicelist;
464
465 extern Scsi_Host_Template * scsi_hosts;
466
467 extern void build_proc_dir_entries(Scsi_Host_Template *);
468
469 /*
470 * scsi_init initializes the scsi hosts.
471 */
472
473 extern int next_scsi_host;
474
475 unsigned int scsi_init(void);
476 extern struct Scsi_Host * scsi_register(Scsi_Host_Template *, int j);
477 extern void scsi_unregister(struct Scsi_Host * i);
478
479 extern void scsi_register_blocked_host(struct Scsi_Host * SHpnt);
480 extern void scsi_deregister_blocked_host(struct Scsi_Host * SHpnt);
481
482 static inline void scsi_set_pci_device(struct Scsi_Host *SHpnt,
483 struct pci_dev *pdev)
484 {
485 SHpnt->pci_dev = pdev;
486 }
487
488
489 /*
490 * Prototypes for functions/data in scsi_scan.c
491 */
492 extern void scan_scsis(struct Scsi_Host *shpnt,
493 uint hardcoded,
494 uint hchannel,
495 uint hid,
496 uint hlun);
497
498 extern void scsi_mark_host_reset(struct Scsi_Host *Host);
499
500 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
501
502 struct Scsi_Device_Template
503 {
504 struct Scsi_Device_Template * next;
505 const char * name;
506 const char * tag;
507 struct module * module; /* Used for loadable modules */
508 unsigned char scsi_type;
509 unsigned int major;
510 unsigned int min_major; /* Minimum major in range. */
511 unsigned int max_major; /* Maximum major in range. */
512 unsigned int nr_dev; /* Number currently attached */
513 unsigned int dev_noticed; /* Number of devices detected. */
514 unsigned int dev_max; /* Current size of arrays */
515 unsigned blk:1; /* 0 if character device */
516 int (*detect)(Scsi_Device *); /* Returns 1 if we can attach this device */
517 int (*init)(void); /* Sizes arrays based upon number of devices
518 * detected */
519 void (*finish)(void); /* Perform initialization after attachment */
520 int (*attach)(Scsi_Device *); /* Attach devices to arrays */
521 void (*detach)(Scsi_Device *);
522 int (*init_command)(Scsi_Cmnd *); /* Used by new queueing code.
523 Selects command for blkdevs */
524 };
525
526 void scsi_initialize_queue(Scsi_Device * SDpnt, struct Scsi_Host * SHpnt);
527
528 int scsi_register_device(struct Scsi_Device_Template * sdpnt);
529
530 /* These are used by loadable modules */
531 extern int scsi_register_module(int, void *);
532 extern int scsi_unregister_module(int, void *);
533
534 /* The different types of modules that we can load and unload */
535 #define MODULE_SCSI_HA 1
536 #define MODULE_SCSI_CONST 2
537 #define MODULE_SCSI_IOCTL 3
538 #define MODULE_SCSI_DEV 4
539
540
541 /*
542 * This is an ugly hack. If we expect to be able to load devices at run time,
543 * we need to leave extra room in some of the data structures. Doing a
544 * realloc to enlarge the structures would be riddled with race conditions,
545 * so until a better solution is discovered, we use this crude approach
546 *
547 * Even bigger hack for SparcSTORAGE arrays. Those are at least 6 disks, but
548 * usually up to 30 disks, so everyone would need to change this. -jj
549 *
550 * Note: These things are all evil and all need to go away. My plan is to
551 * tackle the character devices first, as there aren't any locking implications
552 * in the block device layer. The block devices will require more work.
553 *
554 * The generics driver has been updated to resize as required. So as the tape
555 * driver. Two down, two more to go.
556 */
557 #ifndef CONFIG_SD_EXTRA_DEVS
558 #define CONFIG_SD_EXTRA_DEVS 2
559 #endif
560 #ifndef CONFIG_SR_EXTRA_DEVS
561 #define CONFIG_SR_EXTRA_DEVS 2
562 #endif
563 #define SD_EXTRA_DEVS CONFIG_SD_EXTRA_DEVS
564 #define SR_EXTRA_DEVS CONFIG_SR_EXTRA_DEVS
565
566 #endif
567 /*
568 * Overrides for Emacs so that we follow Linus's tabbing style.
569 * Emacs will notice this stuff at the end of the file and automatically
570 * adjust the settings for this buffer only. This must remain at the end
571 * of the file.
572 * ---------------------------------------------------------------------------
573 * Local variables:
574 * c-indent-level: 4
575 * c-brace-imaginary-offset: 0
576 * c-brace-offset: -4
577 * c-argdecl-indent: 4
578 * c-label-offset: -4
579 * c-continued-statement-offset: 4
580 * c-continued-brace-offset: 0
581 * indent-tabs-mode: nil
582 * tab-width: 8
583 * End:
584 */
585