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

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