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. board_inquiry
  3. port_detect
  4. u14_34f_detect
  5. build_sg_list
  6. u14_34f_queuecommand
  7. u14_34f_abort
  8. u14_34f_reset
  9. u14_34f_biosparam
  10. u14_34f_interrupt_handler

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

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