root/drivers/scsi/u14-34f.c

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

DEFINITIONS

This source file includes following definitions.
  1. wait_on_busy
  2. port_detect
  3. u14_34f_detect
  4. build_sg_list
  5. u14_34f_queuecommand
  6. u14_34f_abort
  7. u14_34f_reset
  8. u14_34f_biosparam
  9. u14_34f_interrupt_handler

   1 /*
   2  *      u14-34f.c - Low-level driver for UltraStor 14F/34F SCSI host adapters.
   3  *
   4  *      16 Jan 1995 rev. 1.13 for linux 1.1.81
   5  *          Display a message if check_region detects a port address
   6  *          already in use.
   7  *
   8  *      15 Dec 1994 rev. 1.12 for linux 1.1.74
   9  *          The host->block flag is set for all the detected ISA boards.
  10  *
  11  *      30 Nov 1994 rev. 1.11 for linux 1.1.68
  12  *          Redo i/o on target status CONDITION_GOOD for TYPE_DISK only.
  13  *          Added optional support for using a single board at a time.
  14  *
  15  *      14 Nov 1994 rev. 1.10 for linux 1.1.63
  16  *
  17  *      28 Oct 1994 rev. 1.09 for linux 1.1.58  Final BETA release.
  18  *      16 Jul 1994 rev. 1.00 for linux 1.1.29  Initial ALPHA release.
  19  *
  20  *          This driver is a total replacement of the original UltraStor 
  21  *          scsi driver, but it supports ONLY the 14F and 34F boards.
  22  *          It can be configured in the same kernel in which the original
  23  *          ultrastor driver is configured to allow the original U24F
  24  *          support.
  25  * 
  26  *          Multiple U14F and/or U34F host adapters are supported.
  27  *
  28  *      Released by Dario Ballabio (Dario_Ballabio@milano.europe.dg.com)
  29  *
  30  *      WARNING: if your 14F board has an old firmware revision (see below)
  31  *               you must change "#undef" into "#define" in the following
  32  *               statement.
  33  */
  34 #undef HAVE_OLD_U14F_FIRMWARE
  35 /*
  36  *  The UltraStor 14F, 24F, and 34F are a family of intelligent, high
  37  *  performance SCSI-2 host adapters.
  38  *  Here is the scoop on the various models:
  39  *
  40  *  14F - ISA first-party DMA HA with floppy support and WD1003 emulation.
  41  *  24F - EISA Bus Master HA with floppy support and WD1003 emulation.
  42  *  34F - VESA Local-Bus Bus Master HA (no WD1003 emulation).
  43  *
  44  *  This code has been tested with up to two U14F boards, using both 
  45  *  firmware 28004-005/38004-004 (BIOS rev. 2.00) and the latest firmware
  46  *  28004-006/38004-005 (BIOS rev. 2.01). 
  47  *
  48  *  The latest firmware is required in order to get reliable operations when 
  49  *  clustering is enabled. ENABLE_CLUSTERING provides a performance increase
  50  *  up to 50% on sequential access.
  51  *
  52  *  Since the Scsi_Host_Template structure is shared among all 14F and 34F,
  53  *  the last setting of use_clustering is in effect for all of these boards.
  54  *
  55  *  Here a sample configuration using two U14F boards:
  56  *
  57  U14F0: PORT 0x330, BIOS 0xc8000, IRQ 11, DMA 5, SG 33, Mbox 16, CmdLun 2, C1.
  58  U14F1: PORT 0x340, BIOS 0x00000, IRQ 10, DMA 6, SG 33, Mbox 16, CmdLun 2, C1.
  59  *
  60  *  The boot controller must have its BIOS enabled, while other boards can
  61  *  have their BIOS disabled, or enabled to an higher address.
  62  *  Boards are named Ux4F0, Ux4F1..., according to the port address order in
  63  *  the io_port[] array.
  64  *  
  65  *  The following facts are based on real testing results (not on
  66  *  documentation) on the above U14F board.
  67  *  
  68  *  - The U14F board should be jumpered for bus on time less or equal to 7 
  69  *    microseconds, while the default is 11 microseconds. This is order to 
  70  *    get acceptable performance while using floppy drive and hard disk 
  71  *    together. The jumpering for 7 microseconds is: JP13 pin 15-16, 
  72  *    JP14 pin 7-8 and pin 9-10.
  73  *    The reduction has a little impact on scsi performance.
  74  *  
  75  *  - If scsi bus length exceeds 3m., the scsi bus speed needs to be reduced
  76  *    from 10Mhz to 5Mhz (do this by inserting a jumper on JP13 pin 7-8).
  77  *
  78  *  - If U14F on board firmware is older than 28004-006/38004-005,
  79  *    the U14F board is unable to provide reliable operations if the scsi 
  80  *    request length exceeds 16Kbyte. When this length is exceeded the
  81  *    behavior is: 
  82  *    - adapter_status equal 0x96 or 0xa3 or 0x93 or 0x94;
  83  *    - adapter_status equal 0 and target_status equal 2 on for all targets
  84  *      in the next operation following the reset.
  85  *    This sequence takes a long time (>3 seconds), so in the meantime
  86  *    the SD_TIMEOUT in sd.c could expire giving rise to scsi aborts
  87  *    (SD_TIMEOUT has been increased from 3 to 6 seconds in 1.1.31).
  88  *    Because of this I had to DISABLE_CLUSTERING and to work around the
  89  *    bus reset in the interrupt service routine, returning DID_BUS_BUSY
  90  *    so that the operations are retried without complains from the scsi.c
  91  *    code.
  92  *    Any reset of the scsi bus is going to kill tape operations, since
  93  *    no retry is allowed for tapes. Bus resets are more likely when the
  94  *    scsi bus is under heavy load.
  95  *    Requests using scatter/gather have a maximum length of 16 x 1024 bytes 
  96  *    when DISABLE_CLUSTERING is in effect, but unscattered requests could be
  97  *    larger than 16Kbyte.
  98  *
  99  *    The new firmware has fixed all the above problems and has been tested 
 100  *    with up to 33 scatter/gather lists.
 101  *
 102  *  In order to support multiple ISA boards in a reliable way,
 103  *  the driver sets host->block = TRUE for all ISA boards.
 104  */
 105 
 106 #include <linux/string.h>
 107 #include <linux/sched.h>
 108 #include <linux/kernel.h>
 109 #include <linux/ioport.h>
 110 #include <asm/io.h>
 111 #include <asm/system.h>
 112 #include "../block/blk.h"
 113 #include "scsi.h"
 114 #include "hosts.h"
 115 #include "sd.h"
 116 #include <asm/dma.h>
 117 #include <asm/irq.h>
 118 #include "u14-34f.h"
 119 
 120 /* Values for the PRODUCT_ID ports for the 14/34F */
 121 #define PRODUCT_ID1  0x56
 122 #define PRODUCT_ID2  0x40        /* NOTE: Only upper nibble is used */
 123 
 124 /* Subversion values */
 125 #define ISA  0
 126 #define ESA 1
 127 
 128 #define OP_HOST_ADAPTER   0x1
 129 #define OP_SCSI           0x2
 130 #define OP_RESET          0x4
 131 #define DTD_SCSI          0x0
 132 #define DTD_IN            0x1
 133 #define DTD_OUT           0x2
 134 #define DTD_NONE          0x3
 135 #define HA_CMD_INQUIRY    0x1
 136 #define HA_CMD_SELF_DIAG  0x2
 137 #define HA_CMD_READ_BUFF  0x3
 138 #define HA_CMD_WRITE_BUFF 0x4
 139 
 140 #if defined (HAVE_OLD_U14F_FIRMWARE)
 141 #define U14F_MAX_SGLIST 16
 142 #define U14F_CLUSTERING DISABLE_CLUSTERING
 143 #else
 144 #define U14F_MAX_SGLIST 33
 145 #define U14F_CLUSTERING ENABLE_CLUSTERING
 146 #endif
 147 
 148 #define U34F_MAX_SGLIST 33
 149 #define U34F_CLUSTERING ENABLE_CLUSTERING
 150 
 151 #undef  DEBUG_DETECT
 152 #undef  DEBUG_INTERRUPT
 153 #undef  DEBUG_STATISTICS
 154 
 155 #define MAX_TARGET 8
 156 #define MAX_IRQ 16
 157 #define MAX_BOARDS 4
 158 #define MAX_MAILBOXES 16
 159 #define MAX_SGLIST 33
 160 #define MAX_CMD_PER_LUN 2
 161 
 162 #define FALSE 0
 163 #define TRUE 1
 164 #define FREE 0
 165 #define IN_USE   1
 166 #define LOCKED   2
 167 #define IN_RESET 3
 168 #define NO_IRQ  0xff
 169 #define MAXLOOP 20000
 170 
 171 #define REG_LCL_MASK      0
 172 #define REG_LCL_INTR      1
 173 #define REG_SYS_MASK      2
 174 #define REG_SYS_INTR      3
 175 #define REG_PRODUCT_ID1   4
 176 #define REG_PRODUCT_ID2   5
 177 #define REG_CONFIG1       6
 178 #define REG_CONFIG2       7
 179 #define REG_OGM           8
 180 #define REG_ICM           12
 181 #define REG_REGION        0x0c
 182 #define BSY_ASSERTED      0x01
 183 #define INTR_ASSERTED     0x01
 184 #define CMD_RESET         0xc0
 185 #define CMD_OGM_INTR      0x01
 186 #define CMD_CLR_INTR      0x01
 187 #define CMD_ENA_INTR      0x81
 188 #define ASOK              0x00
 189 #define ASST              0x91
 190 
 191 #define PACKED          __attribute__((packed))
 192 
 193 /* MailBox SCSI Command Packet */
 194 struct mscp {
 195    unsigned char opcode: 3;             /* type of command */
 196    unsigned char xdir: 2;               /* data transfer direction */
 197    unsigned char dcn: 1;                /* disable disconnect */
 198    unsigned char ca: 1;                 /* use cache (if available) */
 199    unsigned char sg: 1;                 /* scatter/gather operation */
 200    unsigned char target: 3;             /* target SCSI id */
 201    unsigned char ch_no: 2;              /* SCSI channel (always 0 for 14f) */
 202    unsigned char lun: 3;                /* logical unit number */
 203    unsigned int data_address PACKED;    /* transfer data pointer */
 204    unsigned int data_len PACKED;        /* length in bytes */
 205    unsigned int command_link PACKED;    /* for linking command chains */
 206    unsigned char scsi_command_link_id;  /* identifies command in chain */
 207    unsigned char use_sg;                /* (if sg is set) 8 bytes per list */
 208    unsigned char sense_len;
 209    unsigned char scsi_cdbs_len;         /* 6, 10, or 12 */
 210    unsigned char scsi_cdbs[12];         /* SCSI commands */
 211    unsigned char adapter_status;        /* non-zero indicates HA error */
 212    unsigned char target_status;         /* non-zero indicates target error */
 213    unsigned int sense_addr PACKED;
 214 
 215    Scsi_Cmnd *SCpnt;
 216 
 217    struct sg_list {
 218       unsigned int address;     /* Segment Address */
 219       unsigned int num_bytes;   /* Segment Length */
 220       } sglist[MAX_SGLIST];
 221 
 222    unsigned int index;   /* cp index */
 223    };
 224 
 225 struct hostdata {
 226    struct mscp cp[MAX_MAILBOXES];       /* Mailboxes for this board */
 227    unsigned int cp_stat[MAX_MAILBOXES]; /* FREE, IN_USE, LOCKED, IN_RESET */
 228    unsigned int last_cp_used;           /* Index of last mailbox used */
 229    unsigned int iocount;                /* Total i/o done for this board */
 230    unsigned int multicount;             /* Total ... in second ihdlr loop */
 231    int board_number;                    /* Number of this board */
 232    char board_name[16];                 /* Name of this board */
 233    int in_reset;                        /* True if board is doing a reset */
 234    int target_time_out[MAX_TARGET];     /* N. of timeout errors on target */
 235    int target_reset[MAX_TARGET];        /* If TRUE redo operation on target */
 236    unsigned char bios_drive_number: 1;
 237    unsigned char heads;
 238    unsigned char sectors;
 239    unsigned char subversion: 4;         /* Bus type, either ISA or ESA */
 240 
 241    /* slot != 0 for the U24F, slot == 0 for both the U14F and U34F */
 242    unsigned char slot;
 243    };
 244 
 245 static struct Scsi_Host * sh[MAX_BOARDS + 1];
 246 static char* driver_name = "Ux4F";
 247 static unsigned int irqlist[MAX_IRQ], calls[MAX_IRQ];
 248 
 249 #define HD(board) ((struct hostdata *) &sh[board]->hostdata)
 250 #define BN(board) (HD(board)->board_name)
 251 
 252 static void u14_34f_interrupt_handler(int, struct pt_regs *);
 253 static int do_trace = FALSE;
 254 
 255 static inline unchar wait_on_busy(ushort iobase) {
     /* [previous][next][first][last][top][bottom][index][help] */
 256    unsigned int loop = MAXLOOP;
 257 
 258    while (inb(iobase + REG_LCL_INTR) & BSY_ASSERTED)
 259       if (--loop == 0) return TRUE;
 260 
 261    return FALSE;
 262 }
 263 
 264 static inline int port_detect(ushort *port_base, unsigned int j, 
     /* [previous][next][first][last][top][bottom][index][help] */
 265                               Scsi_Host_Template * tpnt) {
 266    unsigned char irq, dma_channel, subversion;
 267    unsigned char in_byte;
 268 
 269    /* Allowed BIOS base addresses (NULL indicates reserved) */
 270    void *bios_segment_table[8] = { 
 271       NULL, 
 272       (void *) 0xc4000, (void *) 0xc8000, (void *) 0xcc000, (void *) 0xd0000,
 273       (void *) 0xd4000, (void *) 0xd8000, (void *) 0xdc000
 274       };
 275    
 276    /* Allowed IRQs */
 277    unsigned char interrupt_table[4] = { 15, 14, 11, 10 };
 278    
 279    /* Allowed DMA channels for ISA (0 indicates reserved) */
 280    unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
 281    
 282    /* Head/sector mappings */
 283    struct {
 284       unsigned char heads;
 285       unsigned char sectors;
 286       } mapping_table[4] = { 
 287            { 16, 63 }, { 64, 32 }, { 64, 63 }, { 64, 32 }
 288            };
 289 
 290    struct config_1 {
 291       unsigned char bios_segment: 3;
 292       unsigned char removable_disks_as_fixed: 1;
 293       unsigned char interrupt: 2;
 294       unsigned char dma_channel: 2;
 295       } config_1;
 296 
 297    struct config_2 {
 298       unsigned char ha_scsi_id: 3;
 299       unsigned char mapping_mode: 2;
 300       unsigned char bios_drive_number: 1;
 301       unsigned char tfr_port: 2;
 302       } config_2;
 303 
 304    char name[16];
 305 
 306    sprintf(name, "%s%d", driver_name, j);
 307 
 308    if(check_region(*port_base, REG_REGION)) {
 309       printk("%s: address 0x%03x already in use, detaching.\n", 
 310              name, *port_base);
 311       return FALSE;
 312       }
 313 
 314    if (inb(*port_base + REG_PRODUCT_ID1) != PRODUCT_ID1) return FALSE;
 315 
 316    in_byte = inb(*port_base + REG_PRODUCT_ID2);
 317 
 318    if ((in_byte & 0xf0) != PRODUCT_ID2) return FALSE;
 319 
 320    *(char *)&config_1 = inb(*port_base + REG_CONFIG1);
 321    *(char *)&config_2 = inb(*port_base + REG_CONFIG2);
 322 
 323    irq = interrupt_table[config_1.interrupt];
 324    dma_channel = dma_channel_table[config_1.dma_channel];
 325    subversion = (in_byte & 0x0f);
 326 
 327    /* Board detected, allocate its IRQ if not already done */
 328    if ((irq >= MAX_IRQ) || ((irqlist[irq] == NO_IRQ) && request_irq
 329        (irq, u14_34f_interrupt_handler, SA_INTERRUPT, driver_name))) {
 330       printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq);
 331       return FALSE;
 332       }
 333 
 334    if (subversion == ISA && request_dma(dma_channel, driver_name)) {
 335       printk("%s: unable to allocate DMA channel %u, detaching.\n",
 336              name, dma_channel);
 337       free_irq(irq);
 338       return FALSE;
 339       }
 340 
 341    sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
 342    sh[j]->io_port = *port_base;
 343    sh[j]->base = bios_segment_table[config_1.bios_segment];
 344    sh[j]->irq = irq;
 345    sh[j]->this_id = config_2.ha_scsi_id;
 346    sh[j]->can_queue = MAX_MAILBOXES;
 347    sh[j]->cmd_per_lun = MAX_CMD_PER_LUN;
 348 
 349 #if defined(DEBUG_DETECT)
 350    {
 351    unsigned char sys_mask, lcl_mask;
 352 
 353    sys_mask = inb(sh[j]->io_port + REG_SYS_MASK);
 354    lcl_mask = inb(sh[j]->io_port + REG_LCL_MASK);
 355    printk("SYS_MASK 0x%x, LCL_MASK 0x%x.\n", sys_mask, lcl_mask);
 356    }
 357 #endif
 358 
 359    /* If BIOS is disabled, force enable interrupts */
 360    if (sh[j]->base == 0) outb(CMD_ENA_INTR, sh[j]->io_port + REG_SYS_MASK);
 361 
 362    /* Register the I/O space that we use */
 363    request_region(sh[j]->io_port, REG_REGION, driver_name);
 364 
 365    memset(HD(j), 0, sizeof(struct hostdata));
 366    HD(j)->heads = mapping_table[config_2.mapping_mode].heads;
 367    HD(j)->sectors = mapping_table[config_2.mapping_mode].sectors;
 368    HD(j)->bios_drive_number = config_2.bios_drive_number;
 369    HD(j)->subversion = subversion;
 370    HD(j)->board_number = j;
 371    irqlist[irq] = j;
 372 
 373    if (HD(j)->subversion == ESA) {
 374       sh[j]->dma_channel = 0;
 375       sh[j]->unchecked_isa_dma = FALSE;
 376       sh[j]->sg_tablesize = U34F_MAX_SGLIST;
 377       sh[j]->hostt->use_clustering = U34F_CLUSTERING;
 378       sprintf(BN(j), "U34F%d", j);
 379       }
 380    else {
 381       sh[j]->dma_channel = dma_channel;
 382       sh[j]->block = sh[j];
 383       sh[j]->unchecked_isa_dma = TRUE;
 384       sh[j]->sg_tablesize = U14F_MAX_SGLIST;
 385       sh[j]->hostt->use_clustering = U14F_CLUSTERING;
 386       sprintf(BN(j), "U14F%d", j);
 387       disable_dma(dma_channel);
 388       clear_dma_ff(dma_channel);
 389       set_dma_mode(dma_channel, DMA_MODE_CASCADE);
 390       enable_dma(dma_channel);
 391       }
 392 
 393    printk("%s: PORT 0x%03x, BIOS 0x%05x, IRQ %u, DMA %u, SG %d, "\
 394           "Mbox %d, CmdLun %d, C%d.\n", BN(j), sh[j]->io_port, 
 395           (int)sh[j]->base, sh[j]->irq, 
 396           sh[j]->dma_channel, sh[j]->sg_tablesize, 
 397           sh[j]->can_queue, sh[j]->cmd_per_lun,
 398           sh[j]->hostt->use_clustering);
 399    return TRUE;
 400 }
 401 
 402 int u14_34f_detect (Scsi_Host_Template * tpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 403    unsigned int j = 0, k, flags;
 404 
 405    ushort io_port[] = {
 406       0x330, 0x340, 0x230, 0x240, 0x210, 0x130, 0x140, 0x0
 407       };
 408 
 409    ushort *port_base = io_port;
 410 
 411    save_flags(flags);
 412    cli();
 413 
 414    for (k = 0; k < MAX_IRQ; k++) {
 415       irqlist[k] = NO_IRQ;
 416       calls[k] = 0;
 417       }
 418 
 419    for (k = 0; k < MAX_BOARDS + 1; k++) sh[k] = NULL;
 420 
 421    while (*port_base) {
 422 
 423       if (j < MAX_BOARDS && port_detect(port_base, j, tpnt)) j++;
 424 
 425       port_base++;
 426       }
 427 
 428    restore_flags(flags);
 429    return j;
 430 }
 431 
 432 static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 433    unsigned int k, data_len = 0;
 434    struct scatterlist * sgpnt;
 435 
 436    sgpnt = (struct scatterlist *) SCpnt->request_buffer;
 437 
 438    for (k = 0; k < SCpnt->use_sg; k++) {
 439       cpp->sglist[k].address = (unsigned int) sgpnt[k].address;
 440       cpp->sglist[k].num_bytes = sgpnt[k].length;
 441       data_len += sgpnt[k].length;
 442       }
 443 
 444    cpp->use_sg = SCpnt->use_sg;
 445    cpp->data_address = (unsigned int) cpp->sglist;
 446    cpp->data_len = data_len;
 447 }
 448 
 449 int u14_34f_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
     /* [previous][next][first][last][top][bottom][index][help] */
 450    unsigned int i, j, k, flags;
 451    struct mscp *cpp;
 452 
 453    save_flags(flags);
 454    cli();
 455    /* j is the board number */
 456    j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
 457 
 458    if (!done) panic("%s: qcomm, pid %ld, null done.\n", BN(j), SCpnt->pid);
 459 
 460    /* i is the mailbox number, look for the first free mailbox 
 461       starting from last_cp_used */
 462    i = HD(j)->last_cp_used + 1;
 463 
 464    for (k = 0; k < sh[j]->can_queue; k++, i++) {
 465 
 466       if (i >= sh[j]->can_queue) i = 0;
 467 
 468       if (HD(j)->cp_stat[i] == FREE) {
 469          HD(j)->last_cp_used = i;
 470          break;
 471          }
 472       }
 473 
 474    if (k == sh[j]->can_queue) {
 475       printk("%s: qcomm, no free mailbox, resetting.\n", BN(j));
 476 
 477       if (HD(j)->in_reset) 
 478          printk("%s: qcomm, already in reset.\n", BN(j));
 479       else if (u14_34f_reset(SCpnt) == SCSI_RESET_SUCCESS) 
 480          panic("%s: qcomm, SCSI_RESET_SUCCESS.\n", BN(j));
 481 
 482       SCpnt->result = DID_BUS_BUSY << 16; 
 483       SCpnt->host_scribble = NULL;
 484       printk("%s: qcomm, pid %ld, DID_BUS_BUSY, done.\n", BN(j), SCpnt->pid);
 485       restore_flags(flags);
 486       done(SCpnt);    
 487       return 0;
 488       }
 489 
 490    /* Set pointer to control packet structure */
 491    cpp = &HD(j)->cp[i];
 492 
 493    memset(cpp, 0, sizeof(struct mscp));
 494    SCpnt->scsi_done = done;
 495    cpp->index = i;
 496    SCpnt->host_scribble = (unsigned char *) &cpp->index;
 497 
 498    if (do_trace) printk("%s: qcomm, mbox %d, target %d, pid %ld.\n",
 499                         BN(j), i, SCpnt->target, SCpnt->pid);
 500 
 501    cpp->opcode = OP_SCSI;
 502    cpp->xdir = DTD_SCSI;
 503    cpp->target = SCpnt->target;
 504    cpp->lun = SCpnt->lun;
 505    cpp->SCpnt = SCpnt;
 506    cpp->sense_addr = (unsigned int) SCpnt->sense_buffer;
 507    cpp->sense_len = sizeof SCpnt->sense_buffer;
 508 
 509    if (SCpnt->use_sg) {
 510       cpp->sg = TRUE;
 511       build_sg_list(cpp, SCpnt);
 512       }
 513    else {
 514       cpp->data_address = (unsigned int)SCpnt->request_buffer;
 515       cpp->data_len = SCpnt->request_bufflen;
 516       }
 517 
 518    cpp->scsi_cdbs_len = SCpnt->cmd_len;
 519    memcpy(cpp->scsi_cdbs, SCpnt->cmnd, cpp->scsi_cdbs_len);
 520 
 521    if (wait_on_busy(sh[j]->io_port)) {
 522       SCpnt->result = DID_ERROR << 16;
 523       SCpnt->host_scribble = NULL;
 524       printk("%s: qcomm, target %d, pid %ld, adapter busy, DID_ERROR, done.\n", 
 525              BN(j), SCpnt->target, SCpnt->pid);
 526       restore_flags(flags);
 527       done(SCpnt);
 528       return 0;
 529       }
 530 
 531    /* Store pointer in OGM address bytes */
 532    outl((unsigned int)cpp, sh[j]->io_port + REG_OGM);
 533 
 534    /* Issue OGM interrupt */
 535    outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
 536 
 537    HD(j)->cp_stat[i] = IN_USE;
 538    restore_flags(flags);
 539    return 0;
 540 }
 541 
 542 int u14_34f_abort(Scsi_Cmnd *SCarg) {
     /* [previous][next][first][last][top][bottom][index][help] */
 543    unsigned int i, j, flags;
 544 
 545    save_flags(flags);
 546    cli();
 547    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
 548 
 549    if (SCarg->host_scribble == NULL) {
 550       printk("%s: abort, target %d, pid %ld inactive.\n",
 551              BN(j), SCarg->target, SCarg->pid);
 552       return SCSI_ABORT_NOT_RUNNING;
 553       }
 554 
 555    i = *(unsigned int *)SCarg->host_scribble;
 556    printk("%s: abort, mbox %d, target %d, pid %ld.\n",
 557           BN(j), i, SCarg->target, SCarg->pid);
 558 
 559    if (i >= sh[j]->can_queue)
 560       panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
 561 
 562    if (wait_on_busy(sh[j]->io_port)) {
 563       printk("%s: abort, timeout error.\n", BN(j));
 564       restore_flags(flags);
 565       return SCSI_ABORT_ERROR;
 566       }
 567 
 568    if (HD(j)->cp_stat[i] == FREE) {
 569       printk("%s: abort, mbox %d is free.\n", BN(j), i);
 570       restore_flags(flags);
 571       return SCSI_ABORT_NOT_RUNNING;
 572       }
 573 
 574    if (HD(j)->cp_stat[i] == IN_USE) {
 575       printk("%s: abort, mbox %d is in use.\n", BN(j), i);
 576 
 577       if (SCarg != HD(j)->cp[i].SCpnt)
 578          panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
 579                BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
 580 
 581       restore_flags(flags);
 582       return SCSI_ABORT_SNOOZE;
 583       }
 584 
 585    if (HD(j)->cp_stat[i] == IN_RESET) {
 586       printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
 587       restore_flags(flags);
 588       return SCSI_ABORT_ERROR;
 589       }
 590 
 591    if (HD(j)->cp_stat[i] == LOCKED) {
 592       printk("%s: abort, mbox %d is locked.\n", BN(j), i);
 593       restore_flags(flags);
 594       return SCSI_ABORT_NOT_RUNNING;
 595       }
 596    else
 597       panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
 598 }
 599 
 600 int u14_34f_reset(Scsi_Cmnd * SCarg) {
     /* [previous][next][first][last][top][bottom][index][help] */
 601    unsigned int i, j, flags, time, k, limit = 0;
 602    int arg_done = FALSE;
 603    Scsi_Cmnd *SCpnt;
 604 
 605    save_flags(flags);
 606    cli();
 607    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
 608    printk("%s: reset, enter, target %d, pid %ld.\n", 
 609           BN(j), SCarg->target, SCarg->pid);
 610 
 611    if (SCarg->host_scribble == NULL)
 612       printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
 613 
 614    if (HD(j)->in_reset) {
 615       printk("%s: reset, exit, already in reset.\n", BN(j));
 616       restore_flags(flags);
 617       return SCSI_RESET_ERROR;
 618       }
 619 
 620    if (wait_on_busy(sh[j]->io_port)) {
 621       printk("%s: reset, exit, timeout error.\n", BN(j));
 622       restore_flags(flags);
 623       return SCSI_RESET_ERROR;
 624       }
 625 
 626    for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
 627 
 628    for (i = 0; i < sh[j]->can_queue; i++) {
 629 
 630       if (HD(j)->cp_stat[i] == FREE) continue;
 631 
 632       if (HD(j)->cp_stat[i] == LOCKED) {
 633          HD(j)->cp_stat[i] = FREE;
 634          printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
 635          continue;
 636          }
 637 
 638       SCpnt = HD(j)->cp[i].SCpnt;
 639       HD(j)->cp_stat[i] = IN_RESET;
 640       printk("%s: reset, mbox %d in reset, pid %ld.\n",
 641              BN(j), i, SCpnt->pid);
 642 
 643       if (SCpnt == NULL)
 644          panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
 645 
 646       if (SCpnt->host_scribble == NULL)
 647          panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
 648 
 649       if (*(unsigned int *)SCpnt->host_scribble != i) 
 650          panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
 651 
 652       if (SCpnt->scsi_done == NULL) 
 653          panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
 654 
 655       if (SCpnt == SCarg) arg_done = TRUE;
 656       }
 657 
 658    if (wait_on_busy(sh[j]->io_port)) {
 659       printk("%s: reset, cannot reset, timeout error.\n", BN(j));
 660       restore_flags(flags);
 661       return SCSI_RESET_ERROR;
 662       }
 663 
 664    outb(CMD_RESET, sh[j]->io_port + REG_LCL_INTR);
 665    printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
 666    do_trace = TRUE;
 667    HD(j)->in_reset = TRUE;
 668    sti();
 669    time = jiffies;
 670    while (jiffies < (time + 200) && limit++ < 100000000) sti();
 671    cli();
 672    printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
 673 
 674    for (i = 0; i < sh[j]->can_queue; i++) {
 675 
 676       /* Skip mailboxes already set free by interrupt */
 677       if (HD(j)->cp_stat[i] != IN_RESET) continue;
 678 
 679       SCpnt = HD(j)->cp[i].SCpnt;
 680       SCpnt->result = DID_RESET << 16;
 681       SCpnt->host_scribble = NULL;
 682 
 683       /* This mailbox is still waiting for its interrupt */
 684       HD(j)->cp_stat[i] = LOCKED;
 685 
 686       printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
 687              BN(j), i, SCpnt->pid);
 688       restore_flags(flags);
 689       SCpnt->scsi_done(SCpnt);
 690       cli();
 691       }
 692 
 693    HD(j)->in_reset = FALSE;
 694    do_trace = FALSE;
 695    restore_flags(flags);
 696 
 697    if (arg_done) {
 698       printk("%s: reset, exit, success.\n", BN(j));
 699       return SCSI_RESET_SUCCESS;
 700       }
 701    else {
 702       printk("%s: reset, exit, wakeup.\n", BN(j));
 703       return SCSI_RESET_PUNT;
 704       }
 705 }
 706 
 707 int u14_34f_biosparam(Disk * disk, int dev, int * dkinfo) {
     /* [previous][next][first][last][top][bottom][index][help] */
 708    unsigned int j = 0;
 709    int size = disk->capacity;
 710 
 711    dkinfo[0] = HD(j)->heads;
 712    dkinfo[1] = HD(j)->sectors;
 713    dkinfo[2] = size / (HD(j)->heads * HD(j)->sectors);
 714    return 0;
 715 }
 716 
 717 static void u14_34f_interrupt_handler(int irq, struct pt_regs * regs) {
     /* [previous][next][first][last][top][bottom][index][help] */
 718    Scsi_Cmnd *SCpnt;
 719    unsigned int i, j, k, flags, status, loops, total_loops = 0;
 720    struct mscp *spp;
 721 
 722    save_flags(flags);
 723    cli();
 724 
 725    if (irqlist[irq] == NO_IRQ) {
 726       printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
 727       restore_flags(flags);
 728       return;
 729       }
 730 
 731    if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n", 
 732                         driver_name, irq, calls[irq]);
 733 
 734    /* Service all the boards configured on this irq */
 735    for (j = 0; sh[j] != NULL; j++) {
 736 
 737       if (sh[j]->irq != irq) continue;
 738 
 739       loops = 0;
 740 
 741       /* Loop until all interrupts for a board are serviced */
 742       while (inb(sh[j]->io_port + REG_SYS_INTR) & INTR_ASSERTED) {
 743          total_loops++;
 744          loops++;
 745 
 746          if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
 747                               BN(j), HD(j)->iocount);
 748 
 749          spp = (struct mscp *)inl(sh[j]->io_port + REG_ICM);
 750 
 751          /* Clear interrupt pending flag */
 752          outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
 753 
 754          i = spp - HD(j)->cp;
 755 
 756          if (i >= sh[j]->can_queue)
 757             panic("%s: ihdlr, invalid mscp address.\n", BN(j));
 758 
 759          if (HD(j)->cp_stat[i] == LOCKED) {
 760             HD(j)->cp_stat[i] = FREE;
 761             printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
 762                    BN(j), i, HD(j)->iocount);
 763             continue;
 764             }
 765          else if (HD(j)->cp_stat[i] == FREE) {
 766             printk("%s: ihdlr, mbox %d is free, count %d.\n", 
 767                    BN(j), i, HD(j)->iocount);
 768             continue;
 769             }
 770          else if (HD(j)->cp_stat[i] == IN_RESET)
 771             printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
 772          else if (HD(j)->cp_stat[i] != IN_USE) 
 773             panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
 774 
 775          HD(j)->cp_stat[i] = FREE;
 776          SCpnt = spp->SCpnt;
 777 
 778          if (SCpnt == NULL) 
 779             panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
 780 
 781          if (SCpnt->host_scribble == NULL) 
 782             panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
 783                   BN(j), i, SCpnt->pid, SCpnt);
 784 
 785          if (*(unsigned int *)SCpnt->host_scribble != i) 
 786             panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
 787                   " irq %d.\n", BN(j), i, SCpnt->pid, 
 788                   *(unsigned int *)SCpnt->host_scribble, irq);
 789 
 790          switch (spp->adapter_status) {
 791             case ASOK:     /* status OK */
 792 
 793                /* Fix a "READ CAPACITY failed" error on some disk drives */
 794                if (spp->target_status == INTERMEDIATE_GOOD
 795                                      && SCpnt->device->type != TYPE_TAPE) 
 796                   status = DID_ERROR << 16;
 797 
 798                /* If there was a bus reset, redo operation on each target */
 799                else if (spp->target_status == CONDITION_GOOD
 800                                      && SCpnt->device->type == TYPE_DISK
 801                                      && HD(j)->target_reset[SCpnt->target])
 802                   status = DID_BUS_BUSY << 16;
 803                else
 804                   status = DID_OK << 16;
 805 
 806                if (spp->target_status == 0)
 807                   HD(j)->target_reset[SCpnt->target] = FALSE;
 808 
 809                HD(j)->target_time_out[SCpnt->target] = 0;
 810 
 811                break;
 812             case ASST:     /* SCSI bus selection time out */
 813 
 814                if (HD(j)->target_time_out[SCpnt->target] > 1)
 815                   status = DID_ERROR << 16;
 816                else {
 817                   status = DID_TIME_OUT << 16;
 818                   HD(j)->target_time_out[SCpnt->target]++;
 819                   }
 820 
 821                break;
 822             case 0x92:     /* Data over/under-run */
 823             case 0x93:     /* Unexpected bus free */
 824             case 0x94:     /* Target bus phase sequence failure */
 825             case 0x96:     /* Illegal SCSI command */
 826             case 0xa3:     /* SCSI bus reset error */
 827 
 828                if (SCpnt->device->type != TYPE_TAPE)
 829                   status = DID_BUS_BUSY << 16;
 830                else
 831                   status = DID_ERROR << 16;
 832 
 833                for (k = 0; k < MAX_TARGET; k++) 
 834                   HD(j)->target_reset[k] = TRUE;
 835 
 836                break;
 837             case 0x01:     /* Invalid command */
 838             case 0x02:     /* Invalid parameters */
 839             case 0x03:     /* Invalid data list */
 840             case 0x84:     /* SCSI bus abort error */
 841             case 0x9b:     /* Auto request sense error */
 842             case 0x9f:     /* Unexpected command complete message error */
 843             case 0xff:     /* Invalid parameter in the S/G list */
 844             default:
 845                status = DID_ERROR << 16;
 846                break;
 847             }
 848 
 849          SCpnt->result = status | spp->target_status;
 850          HD(j)->iocount++;
 851 
 852          if (loops > 1) HD(j)->multicount++;
 853 
 854 #if defined (DEBUG_INTERRUPT)
 855          if (SCpnt->result || do_trace) 
 856 #else
 857          if ((spp->adapter_status != ASOK && HD(j)->iocount >  1000) ||
 858              (spp->adapter_status != ASOK && 
 859               spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
 860              do_trace)
 861 #endif
 862             printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
 863                    " target %d:%d, pid %ld, count %d.\n",
 864                    BN(j), i, spp->adapter_status, spp->target_status,
 865                    SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
 866 
 867          /* Set the command state to inactive */
 868          SCpnt->host_scribble = NULL;
 869 
 870          restore_flags(flags);
 871          SCpnt->scsi_done(SCpnt);
 872          cli();
 873 
 874          }   /* Multiple command loop */
 875 
 876       }   /* Boards loop */
 877 
 878    calls[irq]++;
 879 
 880    if (total_loops == 0) 
 881      printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
 882             driver_name, irq, calls[irq]);
 883 
 884    if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n",
 885                         driver_name, irq, calls[irq]);
 886 
 887 #if defined (DEBUG_STATISTICS)
 888    if ((calls[irq] % 100000) == 10000)
 889       for (j = 0; sh[j] != NULL; j++)
 890          printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
 891                 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
 892 #endif
 893 
 894    restore_flags(flags);
 895    return;
 896 }

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