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. u14_34f_info
  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 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 const char *u14_34f_info(void) {
     /* [previous][next][first][last][top][bottom][index][help] */
 420    return driver_name;
 421 }
 422 
 423 static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 424    unsigned int k, data_len = 0;
 425    struct scatterlist * sgpnt;
 426 
 427    sgpnt = (struct scatterlist *) SCpnt->request_buffer;
 428 
 429    for(k = 0; k < SCpnt->use_sg; k++) {
 430       cpp->sglist[k].address = (unsigned int) sgpnt[k].address;
 431       cpp->sglist[k].num_bytes = sgpnt[k].length;
 432       data_len += sgpnt[k].length;
 433       }
 434 
 435    cpp->use_sg = SCpnt->use_sg;
 436    cpp->data_address = (unsigned int) cpp->sglist;
 437    cpp->data_len = data_len;
 438 }
 439 
 440 int u14_34f_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
     /* [previous][next][first][last][top][bottom][index][help] */
 441    unsigned int i, j, k, flags;
 442    struct mscp *cpp;
 443 
 444    save_flags(flags);
 445    cli();
 446    /* j is the board number */
 447    j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
 448 
 449    if (!done) panic("%s: qcomm, pid %ld, null done.\n", BN(j), SCpnt->pid);
 450 
 451    /* i is the mailbox number, look for the first free mailbox 
 452       starting from last_cp_used */
 453    i = HD(j)->last_cp_used + 1;
 454 
 455    for(k = 0; k < sh[j]->can_queue; k++, i++) {
 456 
 457       if (i >= sh[j]->can_queue) i = 0;
 458 
 459       if (HD(j)->cp_stat[i] == FREE) {
 460          HD(j)->last_cp_used = i;
 461          break;
 462          }
 463       }
 464 
 465    if (k == sh[j]->can_queue) {
 466       printk("%s: qcomm, no free mailbox, resetting.\n", BN(j));
 467 
 468       if (HD(j)->in_reset) 
 469          printk("%s: qcomm, already in reset.\n", BN(j));
 470       else if (u14_34f_reset(SCpnt) == SCSI_RESET_SUCCESS) 
 471          panic("%s: qcomm, SCSI_RESET_SUCCESS.\n", BN(j));
 472 
 473       SCpnt->result = DID_BUS_BUSY << 16; 
 474       SCpnt->host_scribble = NULL;
 475       printk("%s: qcomm, pid %ld, DID_BUS_BUSY, done.\n", BN(j), SCpnt->pid);
 476       restore_flags(flags);
 477       done(SCpnt);    
 478       return 0;
 479       }
 480 
 481    /* Set pointer to control packet structure */
 482    cpp = &HD(j)->cp[i];
 483 
 484    memset(cpp, 0, sizeof(struct mscp));
 485    SCpnt->scsi_done = done;
 486    cpp->index = i;
 487    SCpnt->host_scribble = (unsigned char *) &cpp->index;
 488 
 489    if (do_trace) printk("%s: qcomm, mbox %d, target %d, pid %ld.\n",
 490                         BN(j), i, SCpnt->target, SCpnt->pid);
 491 
 492    cpp->opcode = OP_SCSI;
 493    cpp->xdir = DTD_SCSI;
 494    cpp->target = SCpnt->target;
 495    cpp->lun = SCpnt->lun;
 496    cpp->SCpnt = SCpnt;
 497    cpp->sense_addr = (unsigned int) SCpnt->sense_buffer;
 498    cpp->sense_len = sizeof SCpnt->sense_buffer;
 499 
 500    if (SCpnt->use_sg) {
 501       cpp->sg = TRUE;
 502       build_sg_list(cpp, SCpnt);
 503       }
 504    else {
 505       cpp->data_address = (unsigned int)SCpnt->request_buffer;
 506       cpp->data_len = SCpnt->request_bufflen;
 507       }
 508 
 509    cpp->scsi_cdbs_len = COMMAND_SIZE(*(unsigned char *)SCpnt->cmnd);
 510    memcpy(cpp->scsi_cdbs, SCpnt->cmnd, cpp->scsi_cdbs_len);
 511 
 512    if (wait_on_busy(sh[j]->io_port)) {
 513       SCpnt->result = DID_ERROR << 16;
 514       SCpnt->host_scribble = NULL;
 515       printk("%s: qcomm, target %d, pid %ld, adapter busy, DID_ERROR, done.\n", 
 516              BN(j), SCpnt->target, SCpnt->pid);
 517       restore_flags(flags);
 518       done(SCpnt);
 519       return 0;
 520       }
 521 
 522    /* Store pointer in OGM address bytes */
 523    outl((unsigned int)cpp, sh[j]->io_port + REG_OGM);
 524 
 525    /* Issue OGM interrupt */
 526    outb(CMD_OGM_INTR, sh[j]->io_port + REG_LCL_INTR);
 527 
 528    HD(j)->cp_stat[i] = IN_USE;
 529    restore_flags(flags);
 530    return 0;
 531 }
 532 
 533 int u14_34f_abort(Scsi_Cmnd *SCarg) {
     /* [previous][next][first][last][top][bottom][index][help] */
 534    unsigned int i, j, flags;
 535 
 536    save_flags(flags);
 537    cli();
 538    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
 539 
 540    if (SCarg->host_scribble == NULL) {
 541       printk("%s: abort, target %d, pid %ld inactive.\n",
 542              BN(j), SCarg->target, SCarg->pid);
 543       return SCSI_ABORT_NOT_RUNNING;
 544       }
 545 
 546    i = *(unsigned int *)SCarg->host_scribble;
 547    printk("%s: abort, mbox %d, target %d, pid %ld.\n",
 548           BN(j), i, SCarg->target, SCarg->pid);
 549 
 550    if (i >= sh[j]->can_queue)
 551       panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
 552 
 553    if (wait_on_busy(sh[j]->io_port)) {
 554       printk("%s: abort, timeout error.\n", BN(j));
 555       restore_flags(flags);
 556       return SCSI_ABORT_ERROR;
 557       }
 558 
 559    if (HD(j)->cp_stat[i] == FREE) {
 560       printk("%s: abort, mbox %d is free.\n", BN(j), i);
 561       restore_flags(flags);
 562       return SCSI_ABORT_NOT_RUNNING;
 563       }
 564 
 565    if (HD(j)->cp_stat[i] == IN_USE) {
 566       printk("%s: abort, mbox %d is in use.\n", BN(j), i);
 567 
 568       if (SCarg != HD(j)->cp[i].SCpnt)
 569          panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
 570                BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
 571 
 572       restore_flags(flags);
 573       return SCSI_ABORT_SNOOZE;
 574       }
 575 
 576    if (HD(j)->cp_stat[i] == IN_RESET) {
 577       printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
 578       restore_flags(flags);
 579       return SCSI_ABORT_ERROR;
 580       }
 581 
 582    if (HD(j)->cp_stat[i] == LOCKED) {
 583       printk("%s: abort, mbox %d is locked.\n", BN(j), i);
 584       restore_flags(flags);
 585       return SCSI_ABORT_NOT_RUNNING;
 586       }
 587    else
 588       panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
 589 }
 590 
 591 int u14_34f_reset(Scsi_Cmnd * SCarg) {
     /* [previous][next][first][last][top][bottom][index][help] */
 592    unsigned int i, j, flags, time, k, limit = 0;
 593    int arg_done = FALSE;
 594    Scsi_Cmnd *SCpnt;
 595 
 596    save_flags(flags);
 597    cli();
 598    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
 599    printk("%s: reset, enter, target %d, pid %ld.\n", 
 600           BN(j), SCarg->target, SCarg->pid);
 601 
 602    if (SCarg->host_scribble == NULL)
 603       printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
 604 
 605    if (HD(j)->in_reset) {
 606       printk("%s: reset, exit, already in reset.\n", BN(j));
 607       restore_flags(flags);
 608       return SCSI_RESET_ERROR;
 609       }
 610 
 611    if (wait_on_busy(sh[j]->io_port)) {
 612       printk("%s: reset, exit, timeout error.\n", BN(j));
 613       restore_flags(flags);
 614       return SCSI_RESET_ERROR;
 615       }
 616 
 617    for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
 618 
 619    for (i = 0; i < sh[j]->can_queue; i++) {
 620 
 621       if (HD(j)->cp_stat[i] == FREE) continue;
 622 
 623       if (HD(j)->cp_stat[i] == LOCKED) {
 624          HD(j)->cp_stat[i] = FREE;
 625          printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
 626          continue;
 627          }
 628 
 629       SCpnt = HD(j)->cp[i].SCpnt;
 630       HD(j)->cp_stat[i] = IN_RESET;
 631       printk("%s: reset, mbox %d in reset, pid %ld.\n",
 632              BN(j), i, SCpnt->pid);
 633 
 634       if (SCpnt == NULL)
 635          panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
 636 
 637       if (SCpnt->host_scribble == NULL)
 638          panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
 639 
 640       if (*(unsigned int *)SCpnt->host_scribble != i) 
 641          panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
 642 
 643       if (SCpnt->scsi_done == NULL) 
 644          panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
 645 
 646       if (SCpnt == SCarg) arg_done = TRUE;
 647       }
 648 
 649    if (wait_on_busy(sh[j]->io_port)) {
 650       printk("%s: reset, cannot reset, timeout error.\n", BN(j));
 651       restore_flags(flags);
 652       return SCSI_RESET_ERROR;
 653       }
 654 
 655    outb(CMD_RESET, sh[j]->io_port + REG_LCL_INTR);
 656    printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
 657    do_trace = TRUE;
 658    HD(j)->in_reset = TRUE;
 659    sti();
 660    time = jiffies;
 661    while (jiffies < (time + 200) && limit++ < 100000000) sti();
 662    cli();
 663    printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
 664 
 665    for (i = 0; i < sh[j]->can_queue; i++) {
 666 
 667       /* Skip mailboxes already set free by interrupt */
 668       if (HD(j)->cp_stat[i] != IN_RESET) continue;
 669 
 670       SCpnt = HD(j)->cp[i].SCpnt;
 671       SCpnt->result = DID_RESET << 16;
 672       SCpnt->host_scribble = NULL;
 673 
 674       /* This mailbox is still waiting for its interrupt */
 675       HD(j)->cp_stat[i] = LOCKED;
 676 
 677       printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
 678              BN(j), i, SCpnt->pid);
 679       restore_flags(flags);
 680       SCpnt->scsi_done(SCpnt);
 681       cli();
 682       }
 683 
 684    HD(j)->in_reset = FALSE;
 685    do_trace = FALSE;
 686    restore_flags(flags);
 687 
 688    if (arg_done) {
 689       printk("%s: reset, exit, success.\n", BN(j));
 690       return SCSI_RESET_SUCCESS;
 691       }
 692    else {
 693       printk("%s: reset, exit, wakeup.\n", BN(j));
 694       return SCSI_RESET_PUNT;
 695       }
 696 }
 697 
 698 int u14_34f_biosparam(Disk * disk, int dev, int * dkinfo) {
     /* [previous][next][first][last][top][bottom][index][help] */
 699    unsigned int j = 0;
 700    int size = disk->capacity;
 701 
 702    dkinfo[0] = HD(j)->heads;
 703    dkinfo[1] = HD(j)->sectors;
 704    dkinfo[2] = size / (HD(j)->heads * HD(j)->sectors);
 705    return 0;
 706 }
 707 
 708 static void u14_34f_interrupt_handler(int irq) {
     /* [previous][next][first][last][top][bottom][index][help] */
 709    Scsi_Cmnd *SCpnt;
 710    unsigned int i, j, k, flags, status, loops, total_loops = 0;
 711    struct mscp *spp;
 712 
 713    save_flags(flags);
 714    cli();
 715 
 716    if (irqlist[irq] == NO_IRQ) {
 717       printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
 718       restore_flags(flags);
 719       return;
 720       }
 721 
 722    if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n", 
 723                         driver_name, irq, calls[irq]);
 724 
 725    /* Service all the boards configured on this irq */
 726    for (j = 0; sh[j] != NULL; j++) {
 727 
 728       if (sh[j]->irq != irq) continue;
 729 
 730       loops = 0;
 731 
 732       /* Loop until all interrupts for a board are serviced */
 733       while (inb(sh[j]->io_port + REG_SYS_INTR) & INTR_ASSERTED) {
 734          total_loops++;
 735          loops++;
 736 
 737          if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
 738                               BN(j), HD(j)->iocount);
 739 
 740          spp = (struct mscp *)inl(sh[j]->io_port + REG_ICM);
 741 
 742          /* Clear interrupt pending flag */
 743          outb(CMD_CLR_INTR, sh[j]->io_port + REG_SYS_INTR);
 744 
 745          i = spp - HD(j)->cp;
 746 
 747          if (i >= sh[j]->can_queue)
 748             panic("%s: ihdlr, invalid mscp address.\n", BN(j));
 749 
 750          if (HD(j)->cp_stat[i] == LOCKED) {
 751             HD(j)->cp_stat[i] = FREE;
 752             printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
 753                    BN(j), i, HD(j)->iocount);
 754             continue;
 755             }
 756          else if (HD(j)->cp_stat[i] == FREE) {
 757             printk("%s: ihdlr, mbox %d is free, count %d.\n", 
 758                    BN(j), i, HD(j)->iocount);
 759             continue;
 760             }
 761          else if (HD(j)->cp_stat[i] == IN_RESET)
 762             printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
 763          else if (HD(j)->cp_stat[i] != IN_USE) 
 764             panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
 765 
 766          HD(j)->cp_stat[i] = FREE;
 767          SCpnt = spp->SCpnt;
 768 
 769          if (SCpnt == NULL) 
 770             panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
 771 
 772          if (SCpnt->host_scribble == NULL) 
 773             panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
 774                   BN(j), i, SCpnt->pid, SCpnt);
 775 
 776          if (*(unsigned int *)SCpnt->host_scribble != i) 
 777             panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
 778                   " irq %d.\n", BN(j), i, SCpnt->pid, 
 779                   *(unsigned int *)SCpnt->host_scribble, irq);
 780 
 781          switch (spp->adapter_status) {
 782             case ASOK:     /* status OK */
 783 
 784                /* Fix a "READ CAPACITY failed" error on some disk drives */
 785                if (spp->target_status == INTERMEDIATE_GOOD
 786                                      && SCpnt->device->type != TYPE_TAPE) 
 787                   status = DID_ERROR << 16;
 788 
 789                /* If there was a bus reset, redo operation on each target */
 790                else if (spp->target_status == CONDITION_GOOD
 791                                      && SCpnt->device->type != TYPE_TAPE
 792                                      && HD(j)->target_reset[SCpnt->target])
 793                   status = DID_BUS_BUSY << 16;
 794                else
 795                   status = DID_OK << 16;
 796 
 797                if (spp->target_status == 0)
 798                   HD(j)->target_reset[SCpnt->target] = FALSE;
 799 
 800                HD(j)->target_time_out[SCpnt->target] = 0;
 801 
 802                break;
 803             case ASST:     /* SCSI bus selection time out */
 804 
 805                if (HD(j)->target_time_out[SCpnt->target] > 1)
 806                   status = DID_ERROR << 16;
 807                else {
 808                   status = DID_TIME_OUT << 16;
 809                   HD(j)->target_time_out[SCpnt->target]++;
 810                   }
 811 
 812                break;
 813             case 0x92:     /* Data over/under-run */
 814             case 0x93:     /* Unexpected bus free */
 815             case 0x94:     /* Target bus phase sequence failure */
 816             case 0x96:     /* Illegal SCSI command */
 817             case 0xa3:     /* SCSI bus reset error */
 818 
 819                if (SCpnt->device->type != TYPE_TAPE)
 820                   status = DID_BUS_BUSY << 16;
 821                else
 822                   status = DID_ERROR << 16;
 823 
 824                for (k = 0; k < MAX_TARGET; k++) 
 825                   HD(j)->target_reset[k] = TRUE;
 826 
 827                break;
 828             case 0x01:     /* Invalid command */
 829             case 0x02:     /* Invalid parameters */
 830             case 0x03:     /* Invalid data list */
 831             case 0x84:     /* SCSI bus abort error */
 832             case 0x9b:     /* Auto request sense error */
 833             case 0x9f:     /* Unexpected command complete message error */
 834             case 0xff:     /* Invalid parameter in the S/G list */
 835             default:
 836                status = DID_ERROR << 16;
 837                break;
 838             }
 839 
 840          SCpnt->result = status | spp->target_status;
 841          HD(j)->iocount++;
 842 
 843          if (loops > 1) HD(j)->multicount++;
 844 
 845 #if defined (DEBUG_INTERRUPT)
 846          if (SCpnt->result || do_trace) 
 847 #else
 848          if ((spp->adapter_status != ASOK && HD(j)->iocount >  1000) ||
 849              (spp->adapter_status != ASOK && 
 850               spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
 851              do_trace)
 852 #endif
 853             printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
 854                    " target %d:%d, pid %ld, count %d.\n",
 855                    BN(j), i, spp->adapter_status, spp->target_status,
 856                    SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
 857 
 858          /* Set the command state to inactive */
 859          SCpnt->host_scribble = NULL;
 860 
 861          restore_flags(flags);
 862          SCpnt->scsi_done(SCpnt);
 863          cli();
 864 
 865          }   /* Multiple command loop */
 866 
 867       }   /* Boards loop */
 868 
 869    calls[irq]++;
 870 
 871    if (total_loops == 0) 
 872      printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
 873             driver_name, irq, calls[irq]);
 874 
 875    if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n",
 876                         driver_name, irq, calls[irq]);
 877 
 878 #if defined (DEBUG_STATISTICS)
 879    if ((calls[irq] % 100000) == 10000)
 880       for (j = 0; sh[j] != NULL; j++)
 881          printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
 882                 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
 883 #endif
 884 
 885    restore_flags(flags);
 886    return;
 887 }

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