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

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