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
  9. pas16_info

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

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