root/drivers/scsi/pas16.c

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

DEFINITIONS

This source file includes following definitions.
  1. enable_board
  2. init_board
  3. pas16_hw_detect
  4. pas16_setup
  5. pas16_detect
  6. pas16_biosparam
  7. NCR5380_pread
  8. NCR5380_pwrite

   1 #define AUTOSENSE
   2 #define PSEUDO_DMA
   3 #define FOO
   4 #define UNSAFE  /* Not unsafe for PAS16 -- use it */
   5 
   6 /*
   7  * This driver adapted from Drew Eckhardt's Trantor T128 driver
   8  *
   9  * Copyright 1993, Drew Eckhardt
  10  *      Visionary Computing
  11  *      (Unix and Linux consulting and custom programming)
  12  *      drew@colorado.edu
  13  *      +1 (303) 666-5836
  14  *
  15  *  ( Based on T128 - DISTRIBUTION RELEASE 3. ) 
  16  *
  17  * Modified to work with the Pro Audio Spectrum/Studio 16
  18  * by John Weidman.
  19  *
  20  *
  21  * For more information, please consult 
  22  *
  23  * Media Vision
  24  * (510) 770-8600
  25  * (800) 348-7116
  26  * 
  27  * and 
  28  *
  29  * NCR 5380 Family
  30  * SCSI Protocol Controller
  31  * Databook
  32  *
  33  * NCR Microelectronics
  34  * 1635 Aeroplaza Drive
  35  * Colorado Springs, CO 80916
  36  * 1+ (719) 578-3400
  37  * 1+ (800) 334-5454
  38  */
  39 
  40 /*
  41  * Options : 
  42  * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
  43  *      for commands that return with a CHECK CONDITION status. 
  44  *
  45  * LIMIT_TRANSFERSIZE - if defined, limit the pseudo-dma transfers to 512
  46  *      bytes at a time.  Since interrupts are disabled by default during
  47  *      these transfers, we might need this to give reasonable interrupt
  48  *      service time if the transfer size gets too large.
  49  *
  50  * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
  51  * increase compared to polled I/O.
  52  *
  53  * PARITY - enable parity checking.  Not supported.
  54  * 
  55  * SCSI2 - enable support for SCSI-II tagged queueing.  Untested.
  56  *
  57  * UNSAFE - leave interrupts enabled during pseudo-DMA transfers.  This
  58  *          parameter comes from the NCR5380 code.  It is NOT unsafe with
  59  *          the PAS16 and you should use it.  If you don't you will have
  60  *          a problem with dropped characters during high speed
  61  *          communications during SCSI transfers.  If you really don't
  62  *          want to use UNSAFE you can try defining LIMIT_TRANSFERSIZE or
  63  *          twiddle with the transfer size in the high level code.
  64  *
  65  * USLEEP - enable support for devices that don't disconnect.  Untested.
  66  *
  67  * The card is detected and initialized in one of several ways : 
  68  * 1.  Autoprobe (default) - There are many different models of
  69  *     the Pro Audio Spectrum/Studio 16, and I only have one of
  70  *     them, so this may require a little tweaking.  An interrupt
  71  *     is triggered to autoprobe for the interrupt line.  Note:
  72  *     with the newer model boards, the interrupt is set via
  73  *     software after reset using the default_irq for the
  74  *     current board number.
  75  *
  76  *
  77  * 2.  With command line overrides - pas16=port,irq may be 
  78  *     used on the LILO command line to override the defaults.
  79  *
  80  * 3.  With the PAS16_OVERRIDE compile time define.  This is 
  81  *     specified as an array of address, irq tuples.  Ie, for
  82  *     one board at the default 0x388 address, IRQ10, I could say 
  83  *     -DPAS16_OVERRIDE={{0x388, 10}}
  84  *     NOTE:  Untested.
  85  *      
  86  *     Note that if the override methods are used, place holders must
  87  *     be specified for other boards in the system.
  88  *
  89  *
  90  * Configuration notes :
  91  *   The current driver does not support interrupt sharing with the
  92  *   sound portion of the card.  If you use the same irq for the
  93  *   scsi port and sound you will have problems.  Either use
  94  *   a different irq for the scsi port or don't use interrupts
  95  *   for the scsi port.
  96  *
  97  *   If you have problems with your card not being recognized, use
  98  *   the LILO command line override.  Try to get it recognized without
  99  *   interrupts.  Ie, for a board at the default 0x388 base port,
 100  *   boot: linux pas16=0x388,255
 101  *
 102  *     (255 is the IRQ_NONE constant in NCR5380.h)
 103  */
 104  
 105 #include <asm/system.h>
 106 #include <linux/signal.h>
 107 #include <linux/sched.h>
 108 #include <asm/io.h>
 109 #include "../block/blk.h"
 110 #include "scsi.h"
 111 #include "hosts.h"
 112 #include "pas16.h"
 113 #define AUTOPROBE_IRQ
 114 #include "NCR5380.h"
 115 #include "constants.h"
 116 #include "sd.h"
 117 
 118 
 119 int scsi_irq_translate[] =
 120         { 0,  0,  1,  2,  3,  4,  5,  6, 0,  0,  7,  8,  9,  0, 10, 11 };
 121 
 122 /* The default_irqs array contains values used to set the irq into the
 123  * board via software (as must be done on newer model boards without
 124  * irq jumpers on the board).  The first value in the array will be
 125  * assigned to logical board 0, the next to board 1, etc.
 126  */
 127 int default_irqs[] = {  PAS16_DEFAULT_BOARD_1_IRQ,
 128                         PAS16_DEFAULT_BOARD_2_IRQ,
 129                         PAS16_DEFAULT_BOARD_3_IRQ,
 130                         PAS16_DEFAULT_BOARD_4_IRQ
 131                      };
 132 
 133 static struct override {
 134     unsigned short io_port;
 135     int  irq;
 136 } overrides 
 137 #ifdef PAS16_OVERRIDE
 138     [] = PAS16_OVERRIDE;
 139 #else
 140     [4] = {{0,IRQ_AUTO}, {0,IRQ_AUTO}, {0,IRQ_AUTO},
 141         {0,IRQ_AUTO}};
 142 #endif
 143 
 144 #define NO_OVERRIDES (sizeof(overrides) / sizeof(struct override))
 145 
 146 static struct base {
 147     unsigned short io_port;
 148     int noauto;
 149 } bases[] = { {PAS16_DEFAULT_BASE_1, 0},
 150               {PAS16_DEFAULT_BASE_2, 0},
 151               {PAS16_DEFAULT_BASE_3, 0},
 152               {PAS16_DEFAULT_BASE_4, 0}
 153             };
 154 
 155 #define NO_BASES (sizeof (bases) / sizeof (struct base))
 156 
 157 unsigned short  pas16_offset[ 8 ] =
 158     {
 159         0x1c00,    /* OUTPUT_DATA_REG */
 160         0x1c01,    /* INITIATOR_COMMAND_REG */
 161         0x1c02,    /* MODE_REG */
 162         0x1c03,    /* TARGET_COMMAND_REG */
 163         0x3c00,    /* STATUS_REG ro, SELECT_ENABLE_REG wo */
 164         0x3c01,    /* BUS_AND_STATUS_REG ro, START_DMA_SEND_REG wo */
 165         0x3c02,    /* INPUT_DATA_REGISTER ro, (N/A on PAS16 ?)
 166                     * START_DMA_TARGET_RECEIVE_REG wo
 167                     */
 168         0x3c03,    /* RESET_PARITY_INTERRUPT_REG ro,
 169                     * START_DMA_INITIATOR_RECEIVE_REG wo
 170                     */
 171     };
 172 
 173 
 174 
 175 /*
 176  * Function : enable_board( int  board_num, unsigned short port )
 177  *
 178  * Purpose :  set address in new model board
 179  *
 180  * Inputs : board_num - logical board number 0-3, port - base address
 181  *
 182  */
 183 
 184 void    enable_board( int  board_num,  unsigned short port )
     /* [previous][next][first][last][top][bottom][index][help] */
 185 {
 186     outb( 0xbc + board_num, MASTER_ADDRESS_PTR );
 187     outb( port >> 2, MASTER_ADDRESS_PTR );
 188 }
 189 
 190 
 191 
 192 /*
 193  * Function : init_board( unsigned short port, int irq )
 194  *
 195  * Purpose :  Set the board up to handle the SCSI interface
 196  *
 197  * Inputs : port - base address of the board,
 198  *          irq - irq to assign to the SCSI port
 199  *          force_irq - set it even if it conflicts with sound driver
 200  *
 201  */
 202 
 203 void    init_board( unsigned short io_port, int irq, int force_irq )
     /* [previous][next][first][last][top][bottom][index][help] */
 204 {
 205         unsigned int    tmp;
 206         unsigned int    pas_irq_code;
 207 
 208         /* Initialize the SCSI part of the board */
 209 
 210         outb( 0x30, io_port + P_TIMEOUT_COUNTER_REG );  /* Timeout counter */
 211         outb( 0x01, io_port + P_TIMEOUT_STATUS_REG_OFFSET );   /* Reset TC */
 212         outb( 0x01, io_port + WAIT_STATE );   /* 1 Wait state */
 213 
 214         NCR5380_read( RESET_PARITY_INTERRUPT_REG );
 215 
 216         /* Set the SCSI interrupt pointer without mucking up the sound
 217          * interrupt pointer in the same byte.
 218          */
 219         pas_irq_code = ( irq < 16 ) ? scsi_irq_translate[irq] : 0;
 220         tmp = inb( io_port + IO_CONFIG_3 );
 221 
 222         if( (( tmp & 0x0f ) == pas_irq_code) && pas_irq_code > 0 
 223             && !force_irq )
 224         {
 225             printk( "pas16: WARNING: Can't use same irq as sound "
 226                     "driver -- interrupts disabled\n" );
 227             /* Set up the drive parameters, disable 5380 interrupts */
 228             outb( 0x4d, io_port + SYS_CONFIG_4 );
 229         }
 230         else
 231         {
 232             tmp = (  tmp & 0x0f ) | ( pas_irq_code << 4 );
 233             outb( tmp, io_port + IO_CONFIG_3 );
 234 
 235             /* Set up the drive parameters and enable 5380 interrupts */
 236             outb( 0x6d, io_port + SYS_CONFIG_4 );
 237         }
 238 }
 239 
 240 
 241 /*
 242  * Function : pas16_hw_detect( unsigned short board_num )
 243  *
 244  * Purpose : determine if a pas16 board is present
 245  * 
 246  * Inputs : board_num - logical board number ( 0 - 3 )
 247  *
 248  * Returns : 0 if board not found, 1 if found.
 249  */
 250 
 251 int     pas16_hw_detect( unsigned short  board_num )
     /* [previous][next][first][last][top][bottom][index][help] */
 252 {
 253     unsigned char       board_rev, tmp;
 254     unsigned short      io_port = bases[ board_num ].io_port;
 255 
 256     /* See if we can find a PAS16 board at the address associated
 257      * with this logical board number.
 258      */
 259 
 260     /* First, attempt to take a newer model board out of reset and
 261      * give it a base address.  This shouldn't affect older boards.
 262      */
 263     enable_board( board_num, io_port );
 264 
 265     /* Now see if it looks like a PAS16 board */
 266     board_rev = inb( io_port + PCB_CONFIG );
 267 
 268     if( board_rev == 0xff )
 269         return 0;
 270 
 271     tmp = board_rev ^ 0xe0;
 272 
 273     outb( tmp, io_port + PCB_CONFIG );
 274     tmp = inb( io_port + PCB_CONFIG );
 275     outb( board_rev, io_port + PCB_CONFIG );
 276 
 277     if( board_rev != tmp )      /* Not a PAS-16 */
 278         return 0;
 279 
 280     if( ( inb( io_port + OPERATION_MODE_1 ) & 0x03 ) != 0x03 ) 
 281         return 0;       /* return if no SCSI interface found */
 282 
 283     /* Mediavision has some new model boards that return ID bits
 284      * that indicate a SCSI interface, but they're not (LMS).  We'll
 285      * put in an additional test to try and weed them out.
 286      */
 287 
 288     outb( 0x01, io_port + WAIT_STATE );         /* 1 Wait state */
 289     NCR5380_write( MODE_REG, 0x20 );            /* Is it really SCSI? */
 290     if( NCR5380_read( MODE_REG ) != 0x20 )      /* Write to a reg.    */
 291         return 0;                               /* and try to read    */
 292     NCR5380_write( MODE_REG, 0x00 );            /* it back.           */
 293     if( NCR5380_read( MODE_REG ) != 0x00 )
 294         return 0;
 295 
 296     return 1;
 297 }
 298 
 299 
 300 /*
 301  * Function : pas16_setup(char *str, int *ints)
 302  *
 303  * Purpose : LILO command line initialization of the overrides array,
 304  * 
 305  * Inputs : str - unused, ints - array of integer parameters with ints[0]
 306  *      equal to the number of ints.
 307  *
 308  */
 309 
 310 void pas16_setup(char *str, int *ints) {
     /* [previous][next][first][last][top][bottom][index][help] */
 311     static int commandline_current = 0;
 312     int i;
 313     if (ints[0] != 2) 
 314         printk("pas16_setup : usage pas16=io_port,irq\n");
 315     else 
 316         if (commandline_current < NO_OVERRIDES) {
 317             overrides[commandline_current].io_port = (unsigned short) ints[1];
 318             overrides[commandline_current].irq = ints[2];
 319             for (i = 0; i < NO_BASES; ++i)
 320                 if (bases[i].io_port == (unsigned short) ints[1]) {
 321                     bases[i].noauto = 1;
 322                     break;
 323                 }
 324             ++commandline_current;
 325         }
 326 }
 327 
 328 /* 
 329  * Function : int pas16_detect(Scsi_Host_Template * tpnt)
 330  *
 331  * Purpose : detects and initializes PAS16 controllers
 332  *      that were autoprobed, overridden on the LILO command line, 
 333  *      or specified at compile time.
 334  *
 335  * Inputs : tpnt - template for this SCSI adapter.
 336  * 
 337  * Returns : 1 if a host adapter was found, 0 if not.
 338  *
 339  */
 340 
 341 int pas16_detect(Scsi_Host_Template * tpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 342     static int current_override = 0;
 343     static unsigned short current_base = 0;
 344     struct Scsi_Host *instance;
 345     unsigned short io_port;
 346     int  count;
 347 
 348     for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
 349         io_port = 0;
 350 
 351         if (overrides[current_override].io_port)
 352         {
 353             io_port = overrides[current_override].io_port;
 354             enable_board( current_override, io_port );
 355             init_board( io_port, overrides[current_override].irq, 1 );
 356         }
 357         else
 358             for (; !io_port && (current_base < NO_BASES); ++current_base) {
 359 #if (PDEBUG & PDEBUG_INIT)
 360     printk("scsi-pas16 : probing io_port %04x\n", (unsigned int) bases[current_base].io_port);
 361 #endif
 362                 if ( !bases[current_base].noauto &&
 363                      pas16_hw_detect( current_base ) ){
 364                         io_port = bases[current_base].io_port;
 365                         init_board( io_port, default_irqs[ current_base ], 0 ); 
 366 #if (PDEBUG & PDEBUG_INIT)
 367                         printk("scsi-pas16 : detected board.\n");
 368 #endif
 369                 }
 370     }
 371 
 372 
 373 #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
 374         printk("scsi-pas16 : io_port = %04x\n", (unsigned int) io_port);
 375 #endif
 376 
 377         if (!io_port)
 378             break;
 379 
 380         instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
 381         instance->io_port = io_port;
 382 
 383         NCR5380_init(instance, 0);
 384 
 385         if (overrides[current_override].irq != IRQ_AUTO)
 386             instance->irq = overrides[current_override].irq;
 387         else 
 388             instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
 389 
 390         if (instance->irq != IRQ_NONE) 
 391             if (request_irq(instance->irq, pas16_intr, SA_INTERRUPT, "pas16")) {
 392                 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 
 393                     instance->host_no, instance->irq);
 394                 instance->irq = IRQ_NONE;
 395             } 
 396 
 397         if (instance->irq == IRQ_NONE) {
 398             printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
 399             printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
 400             /* Disable 5380 interrupts, leave drive params the same */
 401             outb( 0x4d, io_port + SYS_CONFIG_4 );
 402             outb( (inb(io_port + IO_CONFIG_3) & 0x0f), io_port + IO_CONFIG_3 );
 403         }
 404 
 405 #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
 406         printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
 407 #endif
 408 
 409         printk("scsi%d : at 0x%04x", instance->host_no, (int) 
 410             instance->io_port);
 411         if (instance->irq == IRQ_NONE)
 412             printk (" interrupts disabled");
 413         else 
 414             printk (" irq %d", instance->irq);
 415         printk(" options CAN_QUEUE=%d  CMD_PER_LUN=%d release=%d",
 416             CAN_QUEUE, CMD_PER_LUN, PAS16_PUBLIC_RELEASE);
 417         NCR5380_print_options(instance);
 418         printk("\n");
 419 
 420         ++current_override;
 421         ++count;
 422     }
 423     return count;
 424 }
 425 
 426 /*
 427  * Function : int pas16_biosparam(Disk *disk, int dev, int *ip)
 428  *
 429  * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for 
 430  *      the specified device / size.
 431  * 
 432  * Inputs : size = size of device in sectors (512 bytes), dev = block device
 433  *      major / minor, ip[] = {heads, sectors, cylinders}  
 434  *
 435  * Returns : always 0 (success), initializes ip
 436  *      
 437  */
 438 
 439 /* 
 440  * XXX Most SCSI boards use this mapping, I could be incorrect.  Some one
 441  * using hard disks on a trantor should verify that this mapping corresponds
 442  * to that used by the BIOS / ASPI driver by running the linux fdisk program
 443  * and matching the H_C_S coordinates to what DOS uses.
 444  */
 445 
 446 int pas16_biosparam(Disk * disk, int dev, int * ip)
     /* [previous][next][first][last][top][bottom][index][help] */
 447 {
 448   int size = disk->capacity;
 449   ip[0] = 64;
 450   ip[1] = 32;
 451   ip[2] = size >> 11;           /* I think I have it as /(32*64) */
 452   if( ip[2] > 1024 ) {          /* yes, >, not >= */
 453         ip[0]=255;
 454         ip[1]=63;
 455         ip[2]=size/(63*255);
 456         if( ip[2] > 1023 )      /* yes >1023... */
 457                 ip[2] = 1023;
 458   }
 459 
 460   return 0;
 461 }
 462 
 463 /*
 464  * Function : int NCR5380_pread (struct Scsi_Host *instance, 
 465  *      unsigned char *dst, int len)
 466  *
 467  * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to 
 468  *      dst
 469  * 
 470  * Inputs : dst = destination, len = length in bytes
 471  *
 472  * Returns : 0 on success, non zero on a failure such as a watchdog 
 473  *      timeout.
 474  */
 475 
 476 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
     /* [previous][next][first][last][top][bottom][index][help] */
 477     int len) {
 478     register unsigned char  *d = dst;
 479     register unsigned short reg = (unsigned short) (instance->io_port + 
 480         P_DATA_REG_OFFSET);
 481     register i = len;
 482 
 483     while ( !(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY) );
 484 
 485     insb( reg, d, i );
 486 
 487     if ( inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
 488         outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
 489         printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
 490             instance->host_no);
 491         return -1;
 492     } else
 493         return 0;
 494 }
 495 
 496 /*
 497  * Function : int NCR5380_pwrite (struct Scsi_Host *instance, 
 498  *      unsigned char *src, int len)
 499  *
 500  * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
 501  *      src
 502  * 
 503  * Inputs : src = source, len = length in bytes
 504  *
 505  * Returns : 0 on success, non zero on a failure such as a watchdog 
 506  *      timeout.
 507  */
 508 
 509 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
     /* [previous][next][first][last][top][bottom][index][help] */
 510     int len) {
 511     register unsigned char *s = src;
 512     register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET);
 513     register i = len;
 514 
 515     while ( !((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY) );
 516  
 517     outsb( reg, s, i );
 518 
 519     if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
 520         outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
 521         printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
 522             instance->host_no);
 523         return -1;
 524     } else 
 525         return 0;
 526 }
 527 
 528 #include "NCR5380.c"

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