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

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