root/drivers/scsi/t128.c

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

DEFINITIONS

This source file includes following definitions.
  1. t128_detect
  2. t128_biosparam
  3. NCR5380_pread
  4. NCR5380_pwrite

   1 #define AUTOSENSE
   2 #define PSEUDO_DMA
   3 
   4 /*
   5  * Trantor T128/T128F/T228 driver
   6  *      Note : architecturally, the T100 and T130 are different and won't 
   7  *      work
   8  *
   9  * Copyright 1993, Drew Eckhardt
  10  *      Visionary Computing
  11  *      (Unix and Linux consulting and custom programming)
  12  *      drew@colorado.edu
  13  *      +1 (303) 440-4894
  14  *
  15  * DISTRIBUTION RELEASE 3.
  16  *
  17  * For more information, please consult 
  18  *
  19  * Trantor Systems, Ltd.
  20  * T128/T128F/T228 SCSI Host Adapter
  21  * Hardware Specifications
  22  * 
  23  * Trantor Systems, Ltd. 
  24  * 5415 Randall Place
  25  * Fremont, CA 94538
  26  * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
  27  * 
  28  * and 
  29  *
  30  * NCR 5380 Family
  31  * SCSI Protocol Controller
  32  * Databook
  33  *
  34  * NCR Microelectronics
  35  * 1635 Aeroplaza Drive
  36  * Colorado Springs, CO 80916
  37  * 1+ (719) 578-3400
  38  * 1+ (800) 334-5454
  39  */
  40 
  41 /*
  42  * Options : 
  43  * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
  44  *      for commands that return with a CHECK CONDITION status. 
  45  *
  46  * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
  47  * increase compared to polled I/O.
  48  *
  49  * PARITY - enable parity checking.  Not supported.
  50  * 
  51  * SCSI2 - enable support for SCSI-II tagged queueing.  Untested.
  52  *
  53  *
  54  * UNSAFE - leave interrupts enabled during pseudo-DMA transfers.  You
  55  *          only really want to use this if you're having a problem with
  56  *          dropped characters during high speed communications, and even
  57  *          then, you're going to be better off twiddling with transfersize.
  58  *
  59  * USLEEP - enable support for devices that don't disconnect.  Untested.
  60  *
  61  * The card is detected and initialized in one of several ways : 
  62  * 1.  Autoprobe (default) - since the board is memory mapped, 
  63  *     a BIOS signature is scanned for to locate the registers.
  64  *     An interrupt is triggered to autoprobe for the interrupt
  65  *     line.
  66  *
  67  * 2.  With command line overrides - t128=address,irq may be 
  68  *     used on the LILO command line to override the defaults.
  69  *
  70  * 3.  With the T128_OVERRIDE compile time define.  This is 
  71  *     specified as an array of address, irq tuples.  Ie, for
  72  *     one board at the default 0xcc000 address, IRQ5, I could say 
  73  *     -DT128_OVERRIDE={{0xcc000, 5}}
  74  *      
  75  *     Note that if the override methods are used, place holders must
  76  *     be specified for other boards in the system.
  77  * 
  78  * T128/T128F jumper/dipswitch settings (note : on my sample, the switches 
  79  * were epoxy'd shut, meaning I couldn't change the 0xcc000 base address) :
  80  *
  81  * T128    Sw7 Sw8 Sw6 = 0ws Sw5 = boot 
  82  * T128F   Sw6 Sw7 Sw5 = 0ws Sw4 = boot Sw8 = floppy disable
  83  * cc000   off off      
  84  * c8000   off on
  85  * dc000   on  off
  86  * d8000   on  on
  87  *
  88  * 
  89  * Interrupts 
  90  * There is a 12 pin jumper block, jp1, numbered as follows : 
  91  *   T128 (JP1)          T128F (J5)
  92  * 2 4 6 8 10 12        11 9  7 5 3 1
  93  * 1 3 5 7 9  11        12 10 8 6 4 2
  94  *
  95  * 3   2-4
  96  * 5   1-3
  97  * 7   3-5
  98  * T128F only 
  99  * 10 8-10
 100  * 12 7-9
 101  * 14 10-12
 102  * 15 9-11
 103  */
 104  
 105 /*
 106  * $Log: t128.c,v $
 107  */
 108 
 109 #include <asm/system.h>
 110 #include <linux/signal.h>
 111 #include <linux/sched.h>
 112 #include <asm/io.h>
 113 #include <linux/blk.h>
 114 #include "scsi.h"
 115 #include "hosts.h"
 116 #include "t128.h"
 117 #define AUTOPROBE_IRQ
 118 #include "NCR5380.h"
 119 #include "constants.h"
 120 #include "sd.h"
 121 #include<linux/stat.h>
 122 
 123 struct proc_dir_entry proc_scsi_t128 = {
 124     PROC_SCSI_T128, 4, "t128",
 125     S_IFDIR | S_IRUGO | S_IXUGO, 2
 126 };
 127 
 128 
 129 static struct override {
 130     unsigned char *address;
 131     int irq;
 132 } overrides 
 133 #ifdef T128_OVERRIDE
 134     [] = T128_OVERRIDE;
 135 #else
 136     [4] = {{NULL,IRQ_AUTO}, {NULL,IRQ_AUTO}, {NULL,IRQ_AUTO},
 137         {NULL,IRQ_AUTO}};
 138 #endif
 139 
 140 #define NO_OVERRIDES (sizeof(overrides) / sizeof(struct override))
 141 
 142 static struct base {
 143     unsigned char *address;
 144     int noauto;
 145 } bases[] = {{(unsigned char *) 0xcc000, 0}, {(unsigned char *) 0xc8000, 0},
 146     {(unsigned char *) 0xdc000, 0}, {(unsigned char *) 0xd8000, 0}};
 147 
 148 #define NO_BASES (sizeof (bases) / sizeof (struct base))
 149 
 150 static const struct signature {
 151     const char *string;
 152     int offset;
 153 } signatures[] = {
 154 {"TSROM: SCSI BIOS, Version 1.12", 0x36},
 155 };
 156 
 157 #define NO_SIGNATURES (sizeof (signatures) /  sizeof (struct signature))
 158 
 159 /*
 160  * Function : t128_setup(char *str, int *ints)
 161  *
 162  * Purpose : LILO command line initialization of the overrides array,
 163  * 
 164  * Inputs : str - unused, ints - array of integer parameters with ints[0]
 165  *      equal to the number of ints.
 166  *
 167  */
 168 
 169 void t128_setup(char *str, int *ints) {
 170     static int commandline_current = 0;
 171     int i;
 172     if (ints[0] != 2) 
 173         printk("t128_setup : usage t128=address,irq\n");
 174     else 
 175         if (commandline_current < NO_OVERRIDES) {
 176             overrides[commandline_current].address = (unsigned char *) ints[1];
 177             overrides[commandline_current].irq = ints[2];
 178             for (i = 0; i < NO_BASES; ++i)
 179                 if (bases[i].address == (unsigned char *) ints[1]) {
 180                     bases[i].noauto = 1;
 181                     break;
 182                 }
 183             ++commandline_current;
 184         }
 185 }
 186 
 187 /* 
 188  * Function : int t128_detect(Scsi_Host_Template * tpnt)
 189  *
 190  * Purpose : detects and initializes T128,T128F, or T228 controllers
 191  *      that were autoprobed, overridden on the LILO command line, 
 192  *      or specified at compile time.
 193  *
 194  * Inputs : tpnt - template for this SCSI adapter.
 195  * 
 196  * Returns : 1 if a host adapter was found, 0 if not.
 197  *
 198  */
 199 
 200 int t128_detect(Scsi_Host_Template * tpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 201     static int current_override = 0, current_base = 0;
 202     struct Scsi_Host *instance;
 203     unsigned char *base;
 204     int sig, count;
 205 
 206     tpnt->proc_dir = &proc_scsi_t128;
 207     tpnt->proc_info = &t128_proc_info;
 208 
 209     for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
 210         base = NULL;
 211 
 212         if (overrides[current_override].address)
 213             base = overrides[current_override].address;
 214         else 
 215             for (; !base && (current_base < NO_BASES); ++current_base) {
 216 #if (TDEBUG & TDEBUG_INIT)
 217     printk("scsi : probing address %08x\n", (unsigned int) bases[current_base].address);
 218 #endif
 219                 for (sig = 0; sig < NO_SIGNATURES; ++sig) 
 220                     if (!bases[current_base].noauto && !memcmp 
 221                         (bases[current_base].address + signatures[sig].offset, 
 222                         signatures[sig].string, strlen(signatures[sig].string))) {
 223                         base = bases[current_base].address;
 224 #if (TDEBUG & TDEBUG_INIT)
 225                         printk("scsi-t128 : detected board.\n");
 226 #endif
 227                         break;
 228                     }
 229             }
 230 
 231 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
 232         printk("scsi-t128 : base = %08x\n", (unsigned int) base);
 233 #endif
 234 
 235         if (!base)
 236             break;
 237 
 238         instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
 239         instance->base = base;
 240 
 241         NCR5380_init(instance, 0);
 242 
 243         if (overrides[current_override].irq != IRQ_AUTO)
 244             instance->irq = overrides[current_override].irq;
 245         else 
 246             instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
 247 
 248         if (instance->irq != IRQ_NONE) 
 249             if (request_irq(instance->irq, t128_intr, SA_INTERRUPT, "t128", NULL)) {
 250                 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 
 251                     instance->host_no, instance->irq);
 252                 instance->irq = IRQ_NONE;
 253             } 
 254 
 255         if (instance->irq == IRQ_NONE) {
 256             printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
 257             printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
 258         }
 259 
 260 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
 261         printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
 262 #endif
 263 
 264         printk("scsi%d : at 0x%08x", instance->host_no, (int) 
 265             instance->base);
 266         if (instance->irq == IRQ_NONE)
 267             printk (" interrupts disabled");
 268         else 
 269             printk (" irq %d", instance->irq);
 270         printk(" options CAN_QUEUE=%d  CMD_PER_LUN=%d release=%d",
 271             CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
 272         NCR5380_print_options(instance);
 273         printk("\n");
 274 
 275         ++current_override;
 276         ++count;
 277     }
 278     return count;
 279 }
 280 
 281 /*
 282  * Function : int t128_biosparam(Disk * disk, kdev_t dev, int *ip)
 283  *
 284  * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for 
 285  *      the specified device / size.
 286  * 
 287  * Inputs : size = size of device in sectors (512 bytes), dev = block device
 288  *      major / minor, ip[] = {heads, sectors, cylinders}  
 289  *
 290  * Returns : always 0 (success), initializes ip
 291  *      
 292  */
 293 
 294 /* 
 295  * XXX Most SCSI boards use this mapping, I could be incorrect.  Some one
 296  * using hard disks on a trantor should verify that this mapping corresponds
 297  * to that used by the BIOS / ASPI driver by running the linux fdisk program
 298  * and matching the H_C_S coordinates to what DOS uses.
 299  */
 300 
 301 int t128_biosparam(Disk * disk, kdev_t dev, int * ip)
     /* [previous][next][first][last][top][bottom][index][help] */
 302 {
 303   int size = disk->capacity;
 304   ip[0] = 64;
 305   ip[1] = 32;
 306   ip[2] = size >> 11;
 307   return 0;
 308 }
 309 
 310 /*
 311  * Function : int NCR5380_pread (struct Scsi_Host *instance, 
 312  *      unsigned char *dst, int len)
 313  *
 314  * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to 
 315  *      dst
 316  * 
 317  * Inputs : dst = destination, len = length in bytes
 318  *
 319  * Returns : 0 on success, non zero on a failure such as a watchdog 
 320  *      timeout.
 321  */
 322 
 323 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
     /* [previous][next][first][last][top][bottom][index][help] */
 324     int len) {
 325     register unsigned char *reg = (unsigned char *) (instance->base + 
 326         T_DATA_REG_OFFSET), *d = dst;
 327     register i = len;
 328 
 329 
 330 #if 0
 331     for (; i; --i) {
 332         while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
 333 #else
 334     while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
 335     for (; i; --i) {
 336 #endif
 337         *d++ = *reg;
 338     }
 339 
 340     if (*(instance->base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
 341         unsigned char tmp;
 342         volatile unsigned char *foo;
 343         foo = instance->base + T_CONTROL_REG_OFFSET;
 344         tmp = *foo;
 345         *foo = tmp | T_CR_CT;
 346         *foo = tmp;
 347         printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
 348             instance->host_no);
 349         return -1;
 350     } else
 351         return 0;
 352 }
 353 
 354 /*
 355  * Function : int NCR5380_pwrite (struct Scsi_Host *instance, 
 356  *      unsigned char *src, int len)
 357  *
 358  * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
 359  *      src
 360  * 
 361  * Inputs : src = source, len = length in bytes
 362  *
 363  * Returns : 0 on success, non zero on a failure such as a watchdog 
 364  *      timeout.
 365  */
 366 
 367 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
     /* [previous][next][first][last][top][bottom][index][help] */
 368     int len) {
 369     register unsigned char *reg = (unsigned char *) (instance->base + 
 370         T_DATA_REG_OFFSET), *s = src;
 371     register i = len;
 372 
 373 #if 0
 374     for (; i; --i) {
 375         while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
 376 #else
 377     while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
 378     for (; i; --i) {
 379 #endif
 380         *reg = *s++;
 381     }
 382 
 383     if (*(instance->base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
 384         unsigned char tmp;
 385         volatile unsigned char *foo;
 386         foo = instance->base + T_CONTROL_REG_OFFSET;
 387         tmp = *foo;
 388         *foo = tmp | T_CR_CT;
 389         *foo = tmp;
 390         printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
 391             instance->host_no);
 392         return -1;
 393     } else 
 394         return 0;
 395 }
 396 
 397 #include "NCR5380.c"
 398 
 399 #ifdef MODULE
 400 /* Eventually this will go into an include file, but this will be later */
 401 Scsi_Host_Template driver_template = TRANTOR_T128;
 402 
 403 #include "scsi_module.c"
 404 #endif

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