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 static struct sigaction pas16_sigaction =  { pas16_intr, 0, SA_INTERRUPT , NULL };
 307 
 308 /* 
 309  * Function : int pas16_detect(Scsi_Host_Template * tpnt)
 310  *
 311  * Purpose : detects and initializes PAS16 controllers
 312  *      that were autoprobed, overriden on the LILO command line, 
 313  *      or specified at compile time.
 314  *
 315  * Inputs : tpnt - template for this SCSI adapter.
 316  * 
 317  * Returns : 1 if a host adapter was found, 0 if not.
 318  *
 319  */
 320 
 321 int pas16_detect(Scsi_Host_Template * tpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 322     static int current_override = 0;
 323     static unsigned short current_base = 0;
 324     struct Scsi_Host *instance;
 325     unsigned short io_port;
 326     int  count;
 327 
 328     for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
 329         io_port = 0;
 330 
 331         if (overrides[current_override].io_port)
 332         {
 333             io_port = overrides[current_override].io_port;
 334             enable_board( current_override, io_port );
 335             init_board( io_port, overrides[current_override].irq, 1 );
 336         }
 337         else
 338             for (; !io_port && (current_base < NO_BASES); ++current_base) {
 339 #if (PDEBUG & PDEBUG_INIT)
 340     printk("scsi-pas16 : probing io_port %04x\n", (unsigned int) bases[current_base].io_port);
 341 #endif
 342                 if ( !bases[current_base].noauto &&
 343                      pas16_hw_detect( current_base ) ){
 344                         io_port = bases[current_base].io_port;
 345                         init_board( io_port, default_irqs[ current_base ], 0 ); 
 346 #if (PDEBUG & PDEBUG_INIT)
 347                         printk("scsi-pas16 : detected board.\n");
 348 #endif
 349                 }
 350     }
 351 
 352 
 353 #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
 354         printk("scsi-pas16 : io_port = %04x\n", (unsigned int) io_port);
 355 #endif
 356 
 357         if (!io_port)
 358             break;
 359 
 360         instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
 361         instance->io_port = io_port;
 362 
 363         NCR5380_init(instance);
 364 
 365         if (overrides[current_override].irq != IRQ_AUTO)
 366             instance->irq = overrides[current_override].irq;
 367         else 
 368             instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
 369 
 370         if (instance->irq != IRQ_NONE) 
 371             if (irqaction (instance->irq, &pas16_sigaction)) {
 372                 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 
 373                     instance->host_no, instance->irq);
 374                 instance->irq = IRQ_NONE;
 375             } 
 376 
 377         if (instance->irq == IRQ_NONE) {
 378             printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
 379             printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
 380             /* Disable 5380 interrupts, leave drive params the same */
 381             outb( 0x4d, io_port + SYS_CONFIG_4 );
 382         }
 383 
 384 #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT)
 385         printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
 386 #endif
 387 
 388         printk("scsi%d : at 0x%04x", instance->host_no, (int) 
 389             instance->io_port);
 390         if (instance->irq == IRQ_NONE)
 391             printk (" interrupts disabled");
 392         else 
 393             printk (" irq %d", instance->irq);
 394         printk(" options CAN_QUEUE=%d  CMD_PER_LUN=%d release=%d",
 395             CAN_QUEUE, CMD_PER_LUN, PAS16_PUBLIC_RELEASE);
 396         NCR5380_print_options(instance);
 397         printk("\n");
 398 
 399         ++current_override;
 400         ++count;
 401     }
 402     return count;
 403 }
 404 
 405 /*
 406  * Function : int pas16_biosparam(Disk *disk, int dev, int *ip)
 407  *
 408  * Purpose : Generates a BIOS / DOS compatable H-C-S mapping for 
 409  *      the specified device / size.
 410  * 
 411  * Inputs : size = size of device in sectors (512 bytes), dev = block device
 412  *      major / minor, ip[] = {heads, sectors, cylinders}  
 413  *
 414  * Returns : allways 0 (success), initializes ip
 415  *      
 416  */
 417 
 418 /* 
 419  * XXX Most SCSI boards use this mapping, I could be incorrect.  Some one
 420  * using hard disks on a trantor should verify that this mapping corresponds
 421  * to that used by the BIOS / ASPI driver by running the linux fdisk program
 422  * and matching the H_C_S coordinates to what DOS uses.
 423  */
 424 
 425 int pas16_biosparam(Disk * disk, int dev, int * ip)
     /* [previous][next][first][last][top][bottom][index][help] */
 426 {
 427   int size = disk->capacity;
 428   ip[0] = 64;
 429   ip[1] = 32;
 430   ip[2] = size >> 11;
 431   return 0;
 432 }
 433 
 434 /*
 435  * Function : int NCR5380_pread (struct Scsi_Host *instance, 
 436  *      unsigned char *dst, int len)
 437  *
 438  * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to 
 439  *      dst
 440  * 
 441  * Inputs : dst = destination, len = length in bytes
 442  *
 443  * Returns : 0 on success, non zero on a failure such as a watchdog 
 444  *      timeout.
 445  */
 446 
 447 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
     /* [previous][next][first][last][top][bottom][index][help] */
 448     int len) {
 449     register unsigned char  *d = dst;
 450     register unsigned short reg = (unsigned short) (instance->io_port + 
 451         P_DATA_REG_OFFSET);
 452     register i = len;
 453 
 454     while ( inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY );
 455 
 456     for (; i; --i) 
 457         *d++ = (unsigned char) inb(reg);
 458 
 459     if ( inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
 460         outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
 461         printk("scsi%d : watchdog timer fired in NCR5480_pread()\n",
 462             instance->host_no);
 463         return -1;
 464     } else
 465         return 0;
 466 }
 467 
 468 /*
 469  * Function : int NCR5380_pwrite (struct Scsi_Host *instance, 
 470  *      unsigned char *src, int len)
 471  *
 472  * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
 473  *      src
 474  * 
 475  * Inputs : src = source, len = length in bytes
 476  *
 477  * Returns : 0 on success, non zero on a failure such as a watchdog 
 478  *      timeout.
 479  */
 480 
 481 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
     /* [previous][next][first][last][top][bottom][index][help] */
 482     int len) {
 483     register unsigned char *s = src;
 484     register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET);
 485     register i = len;
 486 
 487     while ( ( inb( instance->io_port + P_STATUS_REG_OFFSET ) ) & P_ST_RDY );
 488     for (; i; --i)
 489         outb( *s++, reg );
 490 
 491     if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
 492         outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
 493         printk("scsi%d : watchdog timer fired in NCR5480_pwrite()\n",
 494             instance->host_no);
 495         return -1;
 496     } else 
 497         return 0;
 498 }
 499 
 500 /*
 501  * Function : const char *pas16_info(void)
 502  *
 503  * Purpose : provide furthur information about this driver.
 504  *
 505  * Returns : an empty string.
 506  */
 507 
 508 const char *pas16_info (void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 509     static const char string[]="";
 510     return string;
 511 }
 512 
 513 #include "NCR5380.c"

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