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

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