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 #define SCSI_HOST_BLOCK 0x80 232 233 struct Scsi_Host 234 { 235 struct Scsi_Host * next; 236 unsigned short extra_bytes; 237 volatile unsigned char host_busy; 238 char host_no; /* Used for IOCTL_GET_IDLUN */ 239 int last_reset; 240 struct wait_queue *host_wait; 241 Scsi_Cmnd *host_queue; 242 Scsi_Host_Template * hostt; 243 244 /* Pointer to a circularly linked list - this indicates the hosts 245 that should be locked out of performing I/O while we have an active 246 command on this host. */ 247 struct Scsi_Host * block; 248 249 /* These parameters should be set by the detect routine */ 250 unsigned char *base; 251 short unsigned int io_port; 252 unsigned char n_io_port; 253 unsigned char irq; 254 unsigned char dma_channel; 255 256 /* 257 Set these if there are conflicts between memory 258 in the < 1mb region and regions at 16mb multiples. 259 The address must be on a page boundary. 260 */ 261 unsigned long forbidden_addr; 262 unsigned long forbidden_size; 263 264 /* 265 The rest can be copied from the template, or specifically 266 initialized, as required. 267 */ 268 269 int this_id; 270 int can_queue; 271 short cmd_per_lun; 272 short unsigned int sg_tablesize; 273 unsigned unchecked_isa_dma:1; 274 /* 275 True if this host was loaded as a loadable module 276 */ 277 unsigned loaded_as_module:1; 278 279 int hostdata[0]; /* Used for storage of host specific stuff */ 280 }; 281 282 extern struct Scsi_Host * scsi_hostlist; 283 extern struct Scsi_Device_Template * scsi_devicelist; 284 285 extern Scsi_Host_Template * scsi_hosts; 286 287 /* 288 scsi_init initializes the scsi hosts. 289 */ 290 291 292 /* We use these goofy things because the MM is not set up when we init 293 the scsi subsystem. By using these functions we can write code that 294 looks normal. Also, it makes it possible to use the same code for a 295 loadable module. */ 296 297 extern void * scsi_init_malloc(unsigned int size); 298 extern void scsi_init_free(char * ptr, unsigned int size); 299 300 301 extern int scsi_loadable_module_flag; 302 unsigned int scsi_init(void); 303 extern struct Scsi_Host * scsi_register(Scsi_Host_Template *, int j); 304 extern void scsi_unregister(struct Scsi_Host * i); 305 306 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 307 308 struct Scsi_Device_Template 309 { 310 struct Scsi_Device_Template * next; 311 char * name; 312 char * tag; 313 unsigned char scsi_type; 314 unsigned char major; 315 unsigned char nr_dev; /* Number currently attached */ 316 unsigned char dev_noticed; /* Number of devices detected. */ 317 unsigned char dev_max; /* Current size of arrays */ 318 unsigned blk:1; /* 0 if character device */ 319 int (*detect)(Scsi_Device *); /* Returns 1 if we can attach this device */ 320 void (*init)(void); /* Sizes arrays based upon number of devices detected */ 321 void (*finish)(void); /* Perform initialization after attachment */ 322 void (*attach)(Scsi_Device *); /* Attach devices to arrays */ 323 void (*detach)(Scsi_Device *); 324 }; 325 326 extern struct Scsi_Device_Template sd_template; 327 extern struct Scsi_Device_Template st_template; 328 extern struct Scsi_Device_Template sr_template; 329 extern struct Scsi_Device_Template sg_template; 330 331 int scsi_register_device(struct Scsi_Device_Template * sdpnt); 332 333 #endif