root/drivers/scsi/hosts.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


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

/* [previous][next][first][last][top][bottom][index][help] */