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
31 /* It is senseless to set SG_ALL any higher than this - the performance
32 * does not get any better, and it wastes memory
33 */
34 #define SG_NONE 0
35 #define SG_ALL 0xff
36
37 #define DISABLE_CLUSTERING 0
38 #define ENABLE_CLUSTERING 1
39
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.
47 */
48
49 /*
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.
53 */
54
55 typedef struct scsi_disk Disk;
56
57 typedef struct SHT
58 {
59
60 /* Used with loadable modules so we can construct a linked list. */
61 struct SHT * next;
62
63 /* Used with loadable modules so that we know when it is safe to unload */
64 struct module * module;
65
66 /* The pointer to the /proc/scsi directory entry */
67 struct proc_dir_entry *proc_dir;
68
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
73 */
74 int (*proc_info)(char *, char **, off_t, int, int, int);
75
76 /*
77 * The name pointer is a pointer to the name of the SCSI
78 * device detected.
79 */
80 const char *name;
81
82 /*
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.
89 *
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.
96 */
97 int (* detect)(struct SHT *);
98
99 int (*revoke)(Scsi_Device *);
100
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.
105 */
106 int (*release)(struct Scsi_Host *);
107
108 /*
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.
112 */
113 const char *(* info)(struct Scsi_Host *);
114
115 /*
116 * ioctl interface
117 */
118 int (*ioctl)(Scsi_Device *dev, int cmd, void *arg);
119
120 /*
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
130 */
131 int (* command)(Scsi_Cmnd *);
132
133 /*
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.
140 *
141 * The done() function must only be called after QueueCommand()
142 * has returned.
143 */
144 int (* queuecommand)(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
145
146 /*
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.
157 *
158 * See scsi_error.c scsi_unjam_host for additional comments about what
159 * this function should and should not be attempting to do.
160 */
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 *);
166
167 /*
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.
177 *
178 * Note that the scsi driver should "clean up" after itself,
179 * resetting the bus, etc. if necessary.
180 *
181 * NOTE - this interface is depreciated, and will go away. Use
182 * the eh_ routines instead.
183 */
184 int (* abort)(Scsi_Cmnd *);
185
186 /*
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.
195 *
196 * NOTE - this interface is depreciated, and will go away. Use
197 * the eh_ routines instead.
198 */
199 int (* reset)(Scsi_Cmnd *, unsigned int);
200
201 /*
202 * This function is used to select synchronous communications,
203 * which will result in a higher data throughput. Not implemented
204 * yet.
205 */
206 int (* slave_attach)(int, int);
207
208 /*
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)
213 */
214 int (* bios_param)(Disk *, kdev_t, int []);
215
216
217 /*
218 * Used to set the queue depth for a specific device.
219 */
220 void (*select_queue_depths)(struct Scsi_Host *, Scsi_Device *);
221
222 /*
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.
226 */
227 int can_queue;
228
229 /*
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.
235 */
236 int this_id;
237
238 /*
239 * This determines the degree to which the host adapter is capable
240 * of scatter-gather.
241 */
242 short unsigned int sg_tablesize;
243
244 /*
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.
252 */
253 short cmd_per_lun;
254
255 /*
256 * present contains counter indicating how many boards of this
257 * type were found when we did the scan.
258 */
259 unsigned char present;
260
261 /*
262 * true if this host adapter uses unchecked DMA onto an ISA bus.
263 */
264 unsigned unchecked_isa_dma:1;
265
266 /*
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.
273 */
274 unsigned use_clustering:1;
275
276 /*
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.
280 */
281 unsigned use_new_eh_code:1;
282
283 /*
284 * True for emulated SCSI host adapters (e.g. ATAPI)
285 */
286 unsigned emulated:1;
287
288 /*
289 * Name of proc directory
290 */
291 char *proc_name;
292
293 } Scsi_Host_Template;
294
295 /*
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.
302 */
303
304 struct Scsi_Host
305 {
306 /* private: */
307 /*
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.
310 */
311 struct Scsi_Host * next;
312 Scsi_Device * host_queue;
313
314
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. */
328
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;
334
335
336 /*
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).
341 */
342 unsigned int max_id;
343 unsigned int max_lun;
344 unsigned int max_channel;
345
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;
352
353 /*
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.
359 */
360 unsigned int unique_id;
361
362 /*
363 * The rest can be copied from the template, or specifically
364 * initialized, as required.
365 */
366
367 /*
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?).
375 */
376 unsigned char max_cmd_len;
377
378 int this_id;
379 int can_queue;
380 short cmd_per_lun;
381 short unsigned int sg_tablesize;
382
383 unsigned in_recovery:1;
384 unsigned unchecked_isa_dma:1;
385 unsigned use_clustering:1;
386 /*
387 * True if this host was loaded as a loadable module
388 */
389 unsigned loaded_as_module:1;
390
391 /*
392 * Host has rejected a command because it was busy.
393 */
394 unsigned host_blocked:1;
395
396 /*
397 * Host has requested that no further requests come through for the
398 * time being.
399 */
400 unsigned host_self_blocked:1;
401
402 /*
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 ;)
405 */
406 unsigned reverse_ordering:1;
407
408 /*
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.
411 */
412 unsigned some_device_starved:1;
413
414 void (*select_queue_depths)(struct Scsi_Host *, Scsi_Device *);
415
416 /*
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.
420 */
421 unsigned long hostdata[0] /* Used for storage of host specific stuff */
422 __attribute__ ((aligned (sizeof(unsigned long))));
423 };
424
425 /*
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.
431 */
432 extern void scsi_free_host_dev(Scsi_Device * SDpnt);
433 extern Scsi_Device * scsi_get_host_dev(struct Scsi_Host * SHpnt);
434
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);
438
439 typedef struct SHN
440 {
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;
447
448 extern Scsi_Host_Name * scsi_host_no_list;
449 extern struct Scsi_Host * scsi_hostlist;
450 extern struct Scsi_Device_Template * scsi_devicelist;
451
452 extern Scsi_Host_Template * scsi_hosts;
453
454 extern void build_proc_dir_entries(Scsi_Host_Template *);
455
456 /*
457 * scsi_init initializes the scsi hosts.
458 */
459
460 extern int next_scsi_host;
461
462 unsigned int scsi_init(void);
463 extern struct Scsi_Host * scsi_register(Scsi_Host_Template *, int j);
464 extern void scsi_unregister(struct Scsi_Host * i);
465
466 extern void scsi_register_blocked_host(struct Scsi_Host * SHpnt);
467 extern void scsi_deregister_blocked_host(struct Scsi_Host * SHpnt);
468
469 /*
470 * Prototypes for functions/data in scsi_scan.c
471 */
472 extern void scan_scsis(struct Scsi_Host *shpnt,
473 uint hardcoded,
474 uint hchannel,
475 uint hid,
476 uint hlun);
477
478 extern void scsi_mark_host_reset(struct Scsi_Host *Host);
479
480 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
481
482 struct Scsi_Device_Template
483 {
484 struct Scsi_Device_Template * next;
485 const char * name;
486 const char * tag;
487 struct module * module; /* Used for loadable modules */
488 unsigned char scsi_type;
489 unsigned int major;
490 unsigned int min_major; /* Minimum major in range. */
491 unsigned int max_major; /* Maximum major in range. */
492 unsigned int nr_dev; /* Number currently attached */
493 unsigned int dev_noticed; /* Number of devices detected. */
494 unsigned int dev_max; /* Current size of arrays */
495 unsigned blk:1; /* 0 if character device */
496 int (*detect)(Scsi_Device *); /* Returns 1 if we can attach this device */
497 int (*init)(void); /* Sizes arrays based upon number of devices
498 * detected */
499 void (*finish)(void); /* Perform initialization after attachment */
500 int (*attach)(Scsi_Device *); /* Attach devices to arrays */
501 void (*detach)(Scsi_Device *);
502 int (*init_command)(Scsi_Cmnd *); /* Used by new queueing code.
503 Selects command for blkdevs */
504 };
505
506 void scsi_initialize_queue(Scsi_Device * SDpnt, struct Scsi_Host * SHpnt);
507
508 int scsi_register_device(struct Scsi_Device_Template * sdpnt);
509
510 /* These are used by loadable modules */
511 extern int scsi_register_module(int, void *);
512 extern void scsi_unregister_module(int, void *);
513
514 /* The different types of modules that we can load and unload */
515 #define MODULE_SCSI_HA 1
516 #define MODULE_SCSI_CONST 2
517 #define MODULE_SCSI_IOCTL 3
518 #define MODULE_SCSI_DEV 4
519
520
521 /*
522 * This is an ugly hack. If we expect to be able to load devices at run time,
523 * we need to leave extra room in some of the data structures. Doing a
524 * realloc to enlarge the structures would be riddled with race conditions,
525 * so until a better solution is discovered, we use this crude approach
526 *
527 * Even bigger hack for SparcSTORAGE arrays. Those are at least 6 disks, but
528 * usually up to 30 disks, so everyone would need to change this. -jj
529 *
530 * Note: These things are all evil and all need to go away. My plan is to
531 * tackle the character devices first, as there aren't any locking implications
532 * in the block device layer. The block devices will require more work.
533 *
534 * The generics driver has been updated to resize as required. So as the tape
535 * driver. Two down, two more to go.
536 */
537 #ifndef CONFIG_SD_EXTRA_DEVS
538 #define CONFIG_SD_EXTRA_DEVS 2
539 #endif
540 #ifndef CONFIG_SR_EXTRA_DEVS
541 #define CONFIG_SR_EXTRA_DEVS 2
542 #endif
543 #define SD_EXTRA_DEVS CONFIG_SD_EXTRA_DEVS
544 #define SR_EXTRA_DEVS CONFIG_SR_EXTRA_DEVS
545
546 #endif
547 /*
548 * Overrides for Emacs so that we follow Linus's tabbing style.
549 * Emacs will notice this stuff at the end of the file and automatically
550 * adjust the settings for this buffer only. This must remain at the end
551 * of the file.
552 * ---------------------------------------------------------------------------
553 * Local variables:
554 * c-indent-level: 4
555 * c-brace-imaginary-offset: 0
556 * c-brace-offset: -4
557 * c-argdecl-indent: 4
558 * c-label-offset: -4
559 * c-continued-statement-offset: 4
560 * c-continued-brace-offset: 0
561 * indent-tabs-mode: nil
562 * tab-width: 8
563 * End:
564 */
565
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.