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. u14_34f_info
  5. build_sg_list
  6. u14_34f_queuecommand
  7. u14_34f_abort
  8. u14_34f_reset
  9. u14_34f_biosparam
  10. u14_34f_interrupt_handler

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

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