1 /*
2 * hosts.h Copyright (C) 1992 Drew Eckhardt
3 * mid to low-level SCSI driver interface header by
4 * Drew Eckhardt
5 *
6 * <drew@colorado.edu>
7 *
8 * Modified by Eric Youngdale eric@tantalus.nrl.navy.mil to
9 * add scatter-gather, multiple outstanding request, and other
10 * enhancements.
11 *
12 * Further modified by Eric Youngdale to support multiple host adapters
13 * of the same type.
14 */
15
16 #ifndef _HOSTS_H
17 #define _HOSTS_H
18
19 /*
20 $Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/hosts.h,v 1.3 1993/09/24 12:21:00 drew Exp drew $
21 */
22
23
24 /* It is senseless to set SG_ALL any higher than this - the performance
25 does not get any better, and it wastes memory */
26 #define SG_NONE 0
27 #define SG_ALL 0xff
28
29 #define DISABLE_CLUSTERING 0
30 #define ENABLE_CLUSTERING 1
31
32 /* The various choices mean:
33 NONE: Self evident. Host adapter is not capable of scatter-gather.
34 ALL: Means that the host adapter module can do scatter-gather,
35 and that there is no limit to the size of the table to which
36 we scatter/gather data.
37 Anything else: Indicates the maximum number of chains that can be
38 used in one scatter-gather request.
39 */
40
41 /*
42 The Scsi_Host_Template type has all that is needed to interface with a SCSI
43 host in a device independent matter. There is one entry for each different
44 type of host adapter that is supported on the system.
45 */
46
47 typedef struct scsi_disk Disk;
48
49 typedef struct SHT
50 {
51
52 /* Used with loadable modules so we can construct a linked list. */
53 struct SHT * next;
54
55 /* Used with loadable modules so that we know when it is safe to unload */
56 int * usage_count;
57
58 /*
59 The name pointer is a pointer to the name of the SCSI
60 device detected.
61 */
62
63 char *name;
64
65 /*
66 The detect function shall return non zero on detection,
67 indicating the number of host adapters of this particular
68 type were found. It should also
69 initialize all data necessary for this particular
70 SCSI driver. It is passed the host number, so this host
71 knows where the first entry is in the scsi_hosts[] array.
72
73 Note that the detect routine MUST not call any of the mid level
74 functions to queue commands because things are not guaranteed
75 to be set up yet. The detect routine can send commands to
76 the host adapter as long as the program control will not be
77 passed to scsi.c in the processing of the command. Note
78 especially that scsi_malloc/scsi_free must not be called.
79 */
80
81 int (* detect)(struct SHT *);
82
83 /* Used with loadable modules to unload the host structures. Note:
84 there is a default action built into the modules code which may
85 be sufficient for most host adapters. Thus you may not have to supply
86 this at all. */
87 int (*release)(struct Scsi_Host *);
88 /*
89 The info function will return whatever useful
90 information the developer sees fit. If not provided, then
91 the name field will be used instead.
92 */
93
94 const char *(* info)(struct Scsi_Host *);
95
96 /*
97 The command function takes a target, a command (this is a SCSI
98 command formatted as per the SCSI spec, nothing strange), a
99 data buffer pointer, and data buffer length pointer. The return
100 is a status int, bit fielded as follows :
101 Byte What
102 0 SCSI status code
103 1 SCSI 1 byte message
104 2 host error return.
105 3 mid level error return
106 */
107
108 int (* command)(Scsi_Cmnd *);
109
110 /*
111 The QueueCommand function works in a similar manner
112 to the command function. It takes an additional parameter,
113 void (* done)(int host, int code) which is passed the host
114 # and exit result when the command is complete.
115 Host number is the POSITION IN THE hosts array of THIS
116 host adapter.
117 */
118
119 int (* queuecommand)(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *));
120
121 /*
122 Since the mid level driver handles time outs, etc, we want to
123 be able to abort the current command. Abort returns 0 if the
124 abortion was successful. The field SCpnt->abort reason
125 can be filled in with the appropriate reason why we wanted
126 the abort in the first place, and this will be used
127 in the mid-level code instead of the host_byte().
128 If non-zero, the code passed to it
129 will be used as the return code, otherwise
130 DID_ABORT should be returned.
131
132 Note that the scsi driver should "clean up" after itself,
133 resetting the bus, etc. if necessary.
134 */
135
136 int (* abort)(Scsi_Cmnd *);
137
138 /*
139 The reset function will reset the SCSI bus. Any executing
140 commands should fail with a DID_RESET in the host byte.
141 The Scsi_Cmnd is passed so that the reset routine can figure
142 out which host adapter should be reset, and also which command
143 within the command block was responsible for the reset in
144 the first place. Some hosts do not implement a reset function,
145 and these hosts must call scsi_request_sense(SCpnt) to keep
146 the command alive.
147 */
148
149 int (* reset)(Scsi_Cmnd *);
150 /*
151 This function is used to select synchronous communications,
152 which will result in a higher data throughput. Not implemented
153 yet.
154 */
155
156 int (* slave_attach)(int, int);
157 /*
158 This function determines the bios parameters for a given
159 harddisk. These tend to be numbers that are made up by
160 the host adapter. Parameters:
161 size, device number, list (heads, sectors, cylinders)
162 */
163
164 int (* bios_param)(Disk *, int, int []);
165
166 /*
167 This determines if we will use a non-interrupt driven
168 or an interrupt driven scheme, It is set to the maximum number
169 of simultaneous commands a given host adapter will accept.
170 */
171 int can_queue;
172
173 /*
174 In many instances, especially where disconnect / reconnect are
175 supported, our host also has an ID on the SCSI bus. If this is
176 the case, then it must be reserved. Please set this_id to -1 if
177 your setup is in single initiator mode, and the host lacks an
178 ID.
179 */
180
181 int this_id;
182
183 /*
184 This determines the degree to which the host adapter is capable
185 of scatter-gather.
186 */
187
188 short unsigned int sg_tablesize;
189
190 /*
191 True if this host adapter can make good use of linked commands.
192 This will allow more than one command to be queued to a given
193 unit on a given host. Set this to the maximum number of command
194 blocks to be provided for each device. Set this to 1 for one
195 command block per lun, 2 for two, etc. Do not set this to 0.
196 You should make sure that the host adapter will do the right thing
197 before you try setting this above 1.
198 */
199
200 short cmd_per_lun;
201 /*
202 present contains counter indicating how many boards of this
203 type were found when we did the scan.
204 */
205
206 unsigned char present;
207 /*
208 true if this host adapter uses unchecked DMA onto an ISA bus.
209 */
210 unsigned unchecked_isa_dma:1;
211 /*
212 true if this host adapter can make good use of clustering.
213 I originally thought that if the tablesize was large that it
214 was a waste of CPU cycles to prepare a cluster list, but
215 it works out that the Buslogic is faster if you use a smaller
216 number of segments (i.e. use clustering). I guess it is
217 inefficient.
218 */
219 unsigned use_clustering:1;
220 } Scsi_Host_Template;
221
222 /*
223 The scsi_hosts array is the array containing the data for all
224 possible <supported> scsi hosts. This is similar to the
225 Scsi_Host_Template, except that we have one entry for each
226 actual physical host adapter on the system, stored as a linked
227 list. Note that if there are 2 aha1542 boards, then there will
228 be two Scsi_Host entries, but only 1 Scsi_Host_Template entries.
229 */
230
231 struct Scsi_Host
232 {
233 struct Scsi_Host * next;
234 unsigned short extra_bytes;
235 volatile unsigned char host_busy;
236 char host_no; /* Used for IOCTL_GET_IDLUN */
237 int last_reset;
238 struct wait_queue *host_wait;
239 Scsi_Cmnd *host_queue;
240 Scsi_Host_Template * hostt;
241
242 /* Pointer to a circularly linked list - this indicates the hosts
243 that should be locked out of performing I/O while we have an active
244 command on this host. */
245 struct Scsi_Host * block;
246
247 /* These parameters should be set by the detect routine */
248 unsigned char *base;
249 short unsigned int io_port;
250 unsigned char n_io_port;
251 unsigned char irq;
252 unsigned char dma_channel;
253
254 /*
255 Set these if there are conflicts between memory
256 in the < 1mb region and regions at 16mb multiples.
257 The address must be on a page boundary.
258 */
259 unsigned long forbidden_addr;
260 unsigned long forbidden_size;
261
262 /*
263 The rest can be copied from the template, or specifically
264 initialized, as required.
265 */
266
267 int this_id;
268 int can_queue;
269 short cmd_per_lun;
270 short unsigned int sg_tablesize;
271 unsigned unchecked_isa_dma:1;
272 /*
273 True if this host was loaded as a loadable module
274 */
275 unsigned loaded_as_module:1;
276
277 int hostdata[0]; /* Used for storage of host specific stuff */
278 };
279
280 extern struct Scsi_Host * scsi_hostlist;
281 extern struct Scsi_Device_Template * scsi_devicelist;
282
283 extern Scsi_Host_Template * scsi_hosts;
284
285 /*
286 scsi_init initializes the scsi hosts.
287 */
288
289
290 /* We use these goofy things because the MM is not set up when we init
291 the scsi subsystem. By using these functions we can write code that
292 looks normal. Also, it makes it possible to use the same code for a
293 loadable module. */
294
295 extern void * scsi_init_malloc(unsigned int size, int priority);
296 extern void scsi_init_free(char * ptr, unsigned int size);
297
298 void scan_scsis (struct Scsi_Host * shpnt);
299
300 extern int next_scsi_host;
301
302 extern int scsi_loadable_module_flag;
303 unsigned int scsi_init(void);
304 extern struct Scsi_Host * scsi_register(Scsi_Host_Template *, int j);
305 extern void scsi_unregister(struct Scsi_Host * i);
306 extern int scsicam_bios_param (Disk *, int, int *);
307
308 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
309
310 struct Scsi_Device_Template
311 {
312 struct Scsi_Device_Template * next;
313 char * name;
314 char * tag;
315 unsigned char scsi_type;
316 unsigned char major;
317 unsigned char nr_dev; /* Number currently attached */
318 unsigned char dev_noticed; /* Number of devices detected. */
319 unsigned char dev_max; /* Current size of arrays */
320 unsigned blk:1; /* 0 if character device */
321 int (*detect)(Scsi_Device *); /* Returns 1 if we can attach this device */
322 void (*init)(void); /* Sizes arrays based upon number of devices detected */
323 void (*finish)(void); /* Perform initialization after attachment */
324 int (*attach)(Scsi_Device *); /* Attach devices to arrays */
325 void (*detach)(Scsi_Device *);
326 };
327
328 extern struct Scsi_Device_Template sd_template;
329 extern struct Scsi_Device_Template st_template;
330 extern struct Scsi_Device_Template sr_template;
331 extern struct Scsi_Device_Template sg_template;
332
333 int scsi_register_device(struct Scsi_Device_Template * sdpnt);
334
335 /* These are used by loadable modules */
336 extern int scsi_register_module(int, void *);
337 extern void scsi_unregister_module(int, void *);
338
339 /* The different types of modules that we can load and unload */
340 #define MODULE_SCSI_HA 1
341 #define MODULE_SCSI_CONST 2
342 #define MODULE_SCSI_IOCTL 3
343 #define MODULE_SCSI_DEV 4
344
345
346 /*
347 * This is an ugly hack. If we expect to be able to load devices at run time, we need
348 * to leave extra room in some of the data structures. Doing a realloc to enlarge
349 * the structures would be riddled with race conditions, so until a better solution
350 * is discovered, we use this crude approach
351 */
352 #define SD_EXTRA_DEVS 2
353 #define ST_EXTRA_DEVS 2
354 #define SR_EXTRA_DEVS 2
355 #define SG_EXTRA_DEVS (SD_EXTRA_DEVS + SR_EXTRA_DEVS + ST_EXTRA_DEVS)
356
357 #endif