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 /* 56 The name pointer is a pointer to the name of the SCSI 57 device detected. 58 */ 59 60 char *name; 61 62 /* 63 The detect function shall return non zero on detection, 64 indicating the number of host adapters of this particular 65 type were found. It should also 66 initialize all data necessary for this particular 67 SCSI driver. It is passed the host number, so this host 68 knows where the first entry is in the scsi_hosts[] array. 69 70 Note that the detect routine MUST not call any of the mid level 71 functions to queue commands because things are not guaranteed 72 to be set up yet. The detect routine can send commands to 73 the host adapter as long as the program control will not be 74 passed to scsi.c in the processing of the command. Note 75 especially that scsi_malloc/scsi_free must not be called. 76 */ 77 78 int (* detect)(struct SHT *); 79 80 /* Used with loadable modules to unload the host structures */ 81 int (*release)(struct Scsi_Host *); 82 /* 83 The info function will return whatever useful 84 information the developer sees fit. 85 */ 86 87 const char *(* info)(void); 88 89 /* 90 The command function takes a target, a command (this is a SCSI 91 command formatted as per the SCSI spec, nothing strange), a 92 data buffer pointer, and data buffer length pointer. The return 93 is a status int, bit fielded as follows : 94 Byte What 95 0 SCSI status code 96 1 SCSI 1 byte message 97 2 host error return. 98 3 mid level error return 99 */ 100 101 int (* command)(Scsi_Cmnd *); 102 103 /* 104 The QueueCommand function works in a similar manner 105 to the command function. It takes an additional parameter, 106 void (* done)(int host, int code) which is passed the host 107 # and exit result when the command is complete. 108 Host number is the POSITION IN THE hosts array of THIS 109 host adapter. 110 */ 111 112 int (* queuecommand)(Scsi_Cmnd *, void (*done)(Scsi_Cmnd *)); 113 114 /* 115 Since the mid level driver handles time outs, etc, we want to 116 be able to abort the current command. Abort returns 0 if the 117 abortion was successful. The field SCpnt->abort reason 118 can be filled in with the appropriate reason why we wanted 119 the abort in the first place, and this will be used 120 in the mid-level code instead of the host_byte(). 121 If non-zero, the code passed to it 122 will be used as the return code, otherwise 123 DID_ABORT should be returned. 124 125 Note that the scsi driver should "clean up" after itself, 126 resetting the bus, etc. if necessary. 127 */ 128 129 int (* abort)(Scsi_Cmnd *); 130 131 /* 132 The reset function will reset the SCSI bus. Any executing 133 commands should fail with a DID_RESET in the host byte. 134 The Scsi_Cmnd is passed so that the reset routine can figure 135 out which host adapter should be reset, and also which command 136 within the command block was responsible for the reset in 137 the first place. Some hosts do not implement a reset function, 138 and these hosts must call scsi_request_sense(SCpnt) to keep 139 the command alive. 140 */ 141 142 int (* reset)(Scsi_Cmnd *); 143 /* 144 This function is used to select synchronous communications, 145 which will result in a higher data throughput. Not implemented 146 yet. 147 */ 148 149 int (* slave_attach)(int, int); 150 /* 151 This function determines the bios parameters for a given 152 harddisk. These tend to be numbers that are made up by 153 the host adapter. Parameters: 154 size, device number, list (heads, sectors, cylinders) 155 */ 156 157 int (* bios_param)(Disk *, int, int []); 158 159 /* 160 This determines if we will use a non-interrupt driven 161 or an interrupt driven scheme, It is set to the maximum number 162 of simultaneous commands a given host adapter will accept. 163 */ 164 int can_queue; 165 166 /* 167 In many instances, especially where disconnect / reconnect are 168 supported, our host also has an ID on the SCSI bus. If this is 169 the case, then it must be reserved. Please set this_id to -1 if 170 your setup is in single initiator mode, and the host lacks an 171 ID. 172 */ 173 174 int this_id; 175 176 /* 177 This determines the degree to which the host adapter is capable 178 of scatter-gather. 179 */ 180 181 short unsigned int sg_tablesize; 182 183 /* 184 True if this host adapter can make good use of linked commands. 185 This will allow more than one command to be queued to a given 186 unit on a given host. Set this to the maximum number of command 187 blocks to be provided for each device. Set this to 1 for one 188 command block per lun, 2 for two, etc. Do not set this to 0. 189 You should make sure that the host adapter will do the right thing 190 before you try setting this above 1. 191 */ 192 193 short cmd_per_lun; 194 /* 195 present contains counter indicating how many boards of this 196 type were found when we did the scan. 197 */ 198 199 unsigned char present; 200 /* 201 true if this host adapter uses unchecked DMA onto an ISA bus. 202 */ 203 unsigned unchecked_isa_dma:1; 204 /* 205 true if this host adapter can make good use of clustering. 206 I originally thought that if the tablesize was large that it 207 was a waste of CPU cycles to prepare a cluster list, but 208 it works out that the Buslogic is faster if you use a smaller 209 number of segments (i.e. use clustering). I guess it is 210 inefficient. 211 */ 212 unsigned use_clustering:1; 213 } Scsi_Host_Template; 214 215 /* 216 The scsi_hosts array is the array containing the data for all 217 possible <supported> scsi hosts. This is similar to the 218 Scsi_Host_Template, except that we have one entry for each 219 actual physical host adapter on the system, stored as a linked 220 list. Note that if there are 2 aha1542 boards, then there will 221 be two Scsi_Host entries, but only 1 Scsi_Host_Template entries. 222 */ 223 224 struct Scsi_Host 225 { 226 struct Scsi_Host * next; 227 unsigned short extra_bytes; 228 volatile unsigned char host_busy; 229 char host_no; /* Used for IOCTL_GET_IDLUN */ 230 int last_reset; 231 struct wait_queue *host_wait; 232 Scsi_Cmnd *host_queue; 233 Scsi_Host_Template * hostt; 234 235 /* These parameters should be set by the detect routine */ 236 unsigned char *base; 237 short unsigned int io_port; 238 unsigned char irq; 239 unsigned char dma_channel; 240 /* 241 The rest can be copied from the template, or specifically 242 initialized, as required. 243 */ 244 245 int this_id; 246 short unsigned int sg_tablesize; 247 unsigned unchecked_isa_dma:1; 248 /* 249 True if this host was loaded as a loadable module 250 */ 251 unsigned loaded_as_module:1; 252 253 int hostdata[0]; /* Used for storage of host specific stuff */ 254 }; 255 256 extern struct Scsi_Host * scsi_hostlist; 257 extern struct Scsi_Device_Template * scsi_devicelist; 258 259 extern Scsi_Host_Template * scsi_hosts; 260 261 /* 262 scsi_init initializes the scsi hosts. 263 */ 264 265 266 /* We use these goofy things because the MM is not set up when we init 267 the scsi subsystem. By using these functions we can write code that 268 looks normal. Also, it makes it possible to use the same code for a 269 loadable module. */ 270 271 extern void * scsi_init_malloc(unsigned int size); 272 extern void scsi_init_free(char * ptr, unsigned int size); 273 274 275 extern int scsi_loadable_module_flag; 276 unsigned int scsi_init(void); 277 extern struct Scsi_Host * scsi_register(Scsi_Host_Template *, int j); 278 extern void scsi_unregister(struct Scsi_Host * i); 279 280 #define BLANK_HOST {"", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} 281 282 struct Scsi_Device_Template 283 { 284 struct Scsi_Device_Template * next; 285 char * name; 286 char * tag; 287 unsigned char scsi_type; 288 unsigned char major; 289 unsigned char nr_dev; /* Number currently attached */ 290 unsigned char dev_noticed; /* Number of devices detected. */ 291 unsigned char dev_max; /* Current size of arrays */ 292 unsigned blk:1; /* 0 if character device */ 293 int (*detect)(Scsi_Device *); /* Returns 1 if we can attach this device */ 294 void (*init)(void); /* Sizes arrays based upon number of devices detected */ 295 void (*finish)(void); /* Perform initialization after attachment */ 296 void (*attach)(Scsi_Device *); /* Attach devices to arrays */ 297 void (*detach)(Scsi_Device *); 298 }; 299 300 extern struct Scsi_Device_Template sd_template; 301 extern struct Scsi_Device_Template st_template; 302 extern struct Scsi_Device_Template sr_template; 303 extern struct Scsi_Device_Template sg_template; 304 305 int scsi_register_device(struct Scsi_Device_Template * sdpnt); 306 307 #endif