root/drivers/scsi/eata.c

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

DEFINITIONS

This source file includes following definitions.
  1. wait_on_busy
  2. do_dma
  3. read_pio
  4. port_detect
  5. eata_detect
  6. build_sg_list
  7. eata_queuecommand
  8. eata_abort
  9. eata_reset
  10. eata_interrupt_handler

   1 /*
   2  *      eata.c - Low-level driver for EATA/DMA SCSI host adapters.
   3  *
   4  *      17 Dec 1994 rev. 1.11 for linux 1.1.74
   5  *          Use the scsicam_bios_param routine. This allows an easy
   6  *          migration path from disk partition tables created using 
   7  *          different SCSI drivers and non optimal disk geometry.
   8  *
   9  *      15 Dec 1994 rev. 1.10 for linux 1.1.74
  10  *          Added support for ISA EATA boards (DPT PM2011, DPT PM2021).
  11  *          The host->block flag is set for all the detected ISA boards.
  12  *          The detect routine no longer enforces LEVEL triggering
  13  *          for EISA boards, it just prints a warning message.
  14  *
  15  *      30 Nov 1994 rev. 1.09 for linux 1.1.68
  16  *          Redo i/o on target status CONDITION_GOOD for TYPE_DISK only.
  17  *          Added optional support for using a single board at a time.
  18  *
  19  *      18 Nov 1994 rev. 1.08 for linux 1.1.64
  20  *          Forces sg_tablesize = 64 and can_queue = 64 if these
  21  *          values are not correctly detected (DPT PM2012).
  22  *
  23  *      14 Nov 1994 rev. 1.07 for linux 1.1.63  Final BETA release.
  24  *      04 Aug 1994 rev. 1.00 for linux 1.1.39  First BETA release.
  25  *
  26  *
  27  *          This driver is based on the CAM (Common Access Method Committee)
  28  *          EATA (Enhanced AT Bus Attachment) rev. 2.0A, using DMA protocol.
  29  *
  30  *      Released by Dario Ballabio (Dario_Ballabio@milano.europe.dg.com)
  31  *
  32  */
  33 
  34 /*
  35  *
  36  *  Here is a brief description of the DPT SCSI host adapters.
  37  *  All these boards provide an EATA/DMA compatible programming interface
  38  *  and are fully supported by this driver:
  39  *
  40  *  PM2011B/9X -  Entry Level ISA
  41  *  PM2021A/9X -  High Performance ISA
  42  *  PM2012A       Old EISA
  43  *  PM2012B       Old EISA
  44  *  PM2022A/9X -  Entry Level EISA
  45  *  PM2122A/9X -  High Performance EISA
  46  *  PM2322A/9X -  Extra High Performance EISA
  47  *
  48  *  The DPT PM2001 provides only the EATA/PIO interface and hence is not
  49  *  supported by this driver.
  50  *
  51  *  This code has been tested with up to 3 Distributed Processing Technology 
  52  *  PM2122A/9X (DPT SCSI BIOS v002.D1, firmware v05E.0) eisa controllers,
  53  *  no on board cache and no RAID option. 
  54  *  BIOS must be enabled on the first board and must be disabled for all other 
  55  *  boards. 
  56  *  Support is provided for any number of DPT PM2122 eisa boards.
  57  *  All boards should be configured at the same IRQ level.
  58  *  Multiple IRQ configurations are supported too.
  59  *  Boards can be located in any eisa slot (1-15) and are named EATA0, 
  60  *  EATA1,... in increasing eisa slot number. ISA boards are detected
  61  *  after the eisa slot probes.
  62  *
  63  *  The IRQ for EISA boards should be _level_ triggered (not _edge_ triggered).
  64  *  This is a requirement in order to support multiple boards on the same IRQ.
  65  *
  66  *  Other eisa configuration parameters are:
  67  *
  68  *  COMMAND QUEUING   : ENABLED
  69  *  COMMAND TIMEOUT   : ENABLED
  70  *  CACHE             : DISABLED
  71  *
  72  *  In order to support multiple ISA boards in a reliable way,
  73  *  the driver sets host->block = TRUE for all ISA boards.
  74  */
  75 
  76 #include <linux/string.h>
  77 #include <linux/sched.h>
  78 #include <linux/kernel.h>
  79 #include <linux/ioport.h>
  80 #include <asm/io.h>
  81 #include <asm/system.h>
  82 #include "../block/blk.h"
  83 #include "scsi.h"
  84 #include "hosts.h"
  85 #include "sd.h"
  86 #include <asm/dma.h>
  87 #include <asm/irq.h>
  88 #include "linux/in.h"
  89 #include "eata.h"
  90 
  91 /* Subversion values */
  92 #define ISA  0
  93 #define ESA 1
  94 
  95 #undef  DEBUG_DETECT
  96 #undef  DEBUG_INTERRUPT
  97 #undef  DEBUG_STATISTICS
  98 
  99 #define MAX_TARGET 8
 100 #define MAX_IRQ 16
 101 #define MAX_BOARDS 18
 102 #define MAX_MAILBOXES 64
 103 #define MAX_SGLIST 64
 104 #define MAX_CMD_PER_LUN 2
 105 
 106 #define FALSE 0
 107 #define TRUE 1
 108 #define FREE 0
 109 #define IN_USE   1
 110 #define LOCKED   2
 111 #define IN_RESET 3
 112 #define NO_IRQ  0xff
 113 #define MAXLOOP 20000
 114 
 115 #define REG_CMD         7
 116 #define REG_STATUS      7
 117 #define REG_AUX_STATUS  8
 118 #define REG_DATA        0
 119 #define REG_DATA2       1
 120 #define REG_SEE         6
 121 #define REG_LOW         2
 122 #define REG_LM          3
 123 #define REG_MID         4
 124 #define REG_MSB         5
 125 #define REG_REGION      9
 126 #define EISA_RANGE      0xf000
 127 #define BSY_ASSERTED      0x80
 128 #define DRQ_ASSERTED      0x08
 129 #define ABSY_ASSERTED     0x01
 130 #define IRQ_ASSERTED      0x02
 131 #define READ_CONFIG_PIO   0xF0
 132 #define SET_CONFIG_PIO    0xF1
 133 #define SEND_CP_PIO       0xF2
 134 #define RECEIVE_SP_PIO    0xF3
 135 #define TRUNCATE_XFR_PIO  0xF4
 136 #define RESET_PIO         0xF9
 137 #define READ_CONFIG_DMA   0xFD
 138 #define SET_CONFIG_DMA    0xFE
 139 #define SEND_CP_DMA       0xFF
 140 #define ASOK              0x00
 141 #define ASST              0x01
 142 
 143 /* "EATA", in Big Endian format */
 144 #define EATA_SIGNATURE 0x41544145
 145 
 146 /* Board info structure */
 147 struct eata_info {
 148    ulong  data_len;     /* Number of valid bytes after this field (30) */
 149    ulong  sign;         /* ASCII "EATA" signature */
 150    unchar        :4,    /* unused low nibble */
 151           version:4;    /* EATA version */
 152    unchar  ocsena:1,    /* Overlap Command Support Enabled */
 153            tarsup:1,    /* Target Mode Supported */
 154                  :2,
 155            dmasup:1,    /* DMA Supported */
 156            drqvld:1,    /* DRQ Index (DRQX) is valid */
 157               ata:1,    /* This is an ATA device */
 158            haaval:1;    /* Host Adapter Address Valid */
 159    ushort cp_pad_len;   /* Number of pad bytes after cp_len */
 160    ulong  host_addr;    /* Host Adapter SCSI ID */
 161    ulong  cp_len;       /* Number of valid bytes in cp */
 162    ulong  sp_len;       /* Number of valid bytes in sp */
 163    ushort queue_size;   /* Max number of cp that can be queued */
 164    ushort unused;
 165    ushort scatt_size;   /* Max number of entries in scatter/gather table */
 166    unchar     irq:4,    /* Interrupt Request assigned to this controller */
 167            irq_tr:1,    /* 0 for edge triggered, 1 for level triggered */
 168            second:1,    /* 1 if this is a secondary (not primary) controller */
 169              drqx:2;    /* DRQ Index (0=DMA0, 1=DMA7, 2=DMA6, 3=DMA5) */
 170    unchar  sync;        /* 1 if scsi target id 7...0 is running sync scsi */
 171    ushort ipad[250];
 172    };
 173 
 174 /* Board config structure */
 175 struct eata_config {
 176    ushort len;          /* Number of bytes following this field */
 177    unchar edis:1,       /* Disable EATA interface after config command */
 178          ocena:1,       /* Overlapped Commands Enabled */
 179         mdpena:1,       /* Transfer all Modified Data Pointer Messages */
 180         tarena:1,       /* Target Mode Enabled for this controller */
 181               :4;
 182    unchar cpad[511];
 183    };
 184 
 185 /* Returned status packet structure */
 186 struct mssp {
 187    unchar adapter_status:7,    /* State related to current command */
 188                      eoc:1;    /* End Of Command (1 = command completed) */
 189    unchar target_status;       /* SCSI status received after data transfer */
 190    unchar unused[2];
 191    ulong inv_res_len;          /* Number of bytes not transferred */
 192    Scsi_Cmnd *SCpnt;           /* Address set in cp */
 193    char mess[12];
 194    };
 195 
 196 /* MailBox SCSI Command Packet */
 197 struct mscp {
 198    unchar  sreset:1,     /* SCSI Bus Reset Signal should be asserted */
 199            interp:1,     /* The controller interprets cp, not the target */ 
 200            reqsen:1,     /* Transfer Request Sense Data to addr using DMA */
 201                sg:1,     /* Use Scatter/Gather */
 202                  :1,
 203              init:1,     /* Re-initialize controller and self test */
 204              dout:1,     /* Direction of Transfer is Out (Host to Target) */
 205               din:1;     /* Direction of Transfer is In (Target to Host) */
 206    unchar sense_len;     /* Request Sense Length */
 207    unchar unused[4];
 208    unchar phsunit:1,     /* Send to Target Physical Unit (bypass RAID) */
 209           notused:7;
 210    unchar target;        /* SCSI Target ID */
 211    unchar     lun:3,     /* LUN */
 212                  :2,
 213            luntar:1,     /* This cp is for Target (not LUN) */
 214            dispri:1,     /* Disconnect Privilege granted */
 215               one:1;     /* 1 */
 216    unchar mess[3];       /* Massage to/from Target */
 217    unchar cdb[12];       /* Command Descriptor Block */
 218    ulong  data_len;      /* If sg=0 Data Length, if sg=1 sglist length */
 219    Scsi_Cmnd *SCpnt;     /* Address to be returned is sp */
 220    ulong  data_address;  /* If sg=0 Data Address, if sg=1 sglist address */
 221    ulong  sp_addr;       /* Address where sp is DMA'ed when cp completes */
 222    ulong  sense_addr;    /* Address where Sense Data is DMA'ed on error */
 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    int in_reset;                        /* True if board is doing a reset */
 241    int target_time_out[MAX_TARGET];     /* N. of timeout errors on target */
 242    int target_reset[MAX_TARGET];        /* If TRUE redo operation on target */
 243    unsigned char subversion;            /* Bus type, either ISA or ESA */
 244    struct mssp sp[MAX_MAILBOXES];       /* Returned status for this board */
 245    };
 246 
 247 static struct Scsi_Host * sh[MAX_BOARDS + 1];
 248 static char* driver_name = "EATA";
 249 static unsigned int irqlist[MAX_IRQ], calls[MAX_IRQ];
 250 
 251 #define HD(board) ((struct hostdata *) &sh[board]->hostdata)
 252 #define BN(board) (HD(board)->board_name)
 253 
 254 static void eata_interrupt_handler(int);
 255 static int do_trace = FALSE;
 256 
 257 static inline unchar wait_on_busy(ushort iobase) {
     /* [previous][next][first][last][top][bottom][index][help] */
 258    unsigned int loop = MAXLOOP;
 259 
 260    while (inb(iobase + REG_AUX_STATUS) & ABSY_ASSERTED)
 261       if (--loop == 0) return TRUE;
 262 
 263    return FALSE;
 264 }
 265 
 266 static inline unchar do_dma (ushort iobase, unsigned int addr, unchar cmd) {
     /* [previous][next][first][last][top][bottom][index][help] */
 267 
 268    if (wait_on_busy(iobase)) return TRUE;
 269 
 270    if (addr) {
 271       outb((char)  addr,        iobase + REG_LOW);
 272       outb((char) (addr >> 8),  iobase + REG_LM);
 273       outb((char) (addr >> 16), iobase + REG_MID);
 274       outb((char) (addr >> 24), iobase + REG_MSB);
 275       }
 276 
 277    outb(cmd, iobase + REG_CMD);
 278    return FALSE;
 279 }
 280 
 281 static inline unchar read_pio (ushort iobase, ushort *start, ushort *end) {
     /* [previous][next][first][last][top][bottom][index][help] */
 282    unsigned int loop = MAXLOOP;
 283    ushort *p;
 284 
 285    for (p = start; p <= end; p++) {
 286 
 287       while (!(inb(iobase + REG_STATUS) & DRQ_ASSERTED)) 
 288          if (--loop == 0) return TRUE;
 289 
 290       loop = MAXLOOP;
 291       *p = inw(iobase);
 292       }
 293 
 294    return FALSE;
 295 }
 296 
 297 static inline int port_detect(ushort *port_base, unsigned int j, 
     /* [previous][next][first][last][top][bottom][index][help] */
 298                               Scsi_Host_Template * tpnt) {
 299    unsigned char irq, dma_channel, subversion;
 300    struct eata_info info;
 301    struct eata_config config;
 302    char *board_status;
 303 
 304    /* Allowed DMA channels for ISA (0 indicates reserved) */
 305    unsigned char dma_channel_table[4] = { 5, 6, 7, 0 };
 306 
 307    char name[16];
 308 
 309    sprintf(name, "%s%d", driver_name, j);
 310 
 311    if(check_region(*port_base, REG_REGION)) return FALSE;
 312 
 313    if (do_dma(*port_base, 0, READ_CONFIG_PIO)) return FALSE;
 314 
 315    /* Read the info structure */
 316    if (read_pio(*port_base, (ushort *)&info, (ushort *)&info.ipad[0])) 
 317       return FALSE;
 318 
 319    /* check the controller "EATA" signature */
 320    if (info.sign != EATA_SIGNATURE) return FALSE;
 321 
 322    irq = info.irq;
 323 
 324    if (*port_base & EISA_RANGE) {
 325 
 326       if (!info.haaval || info.ata || info.drqvld || !info.dmasup) {
 327          printk("%s: unusable EISA board found, detaching.\n", name);
 328          return FALSE;
 329          }
 330 
 331       subversion = ESA;
 332       dma_channel = 0;
 333       }
 334    else {
 335 
 336       if (!info.haaval || info.ata || !info.drqvld || !info.dmasup) {
 337          printk("%s: unusable ISA board found, detaching.\n", name);
 338          return FALSE;
 339          }
 340 
 341       subversion = ISA;
 342       dma_channel = dma_channel_table[3 - info.drqx];
 343       }
 344 
 345    if (subversion == ESA && !info.irq_tr)
 346       printk("%s: warning, LEVEL triggering is suggested for IRQ %u.\n",
 347              name, irq);
 348 
 349    if (info.second)
 350       board_status = "Sec.";
 351    else
 352       board_status = "Prim.";
 353 
 354    /* Board detected, allocate its IRQ if not already done */
 355    if ((irq >= MAX_IRQ) || ((irqlist[irq] == NO_IRQ) && request_irq
 356        (irq, eata_interrupt_handler, SA_INTERRUPT, driver_name))) {
 357       printk("%s: unable to allocate IRQ %u, detaching.\n", name, irq);
 358       return FALSE;
 359       }
 360 
 361    if (subversion == ISA && request_dma(dma_channel, driver_name)) {
 362       printk("%s: unable to allocate DMA channel %u, detaching.\n",
 363              name, dma_channel);
 364       free_irq(irq);
 365       return FALSE;
 366       }
 367 
 368    /* Set board configuration */
 369    memset((char *)&config, 0, sizeof(struct eata_config));
 370    config.len = (ushort) htons((ushort)510);
 371    config.ocena = TRUE;
 372 
 373    if (do_dma(*port_base, (unsigned int)&config, SET_CONFIG_DMA)) {
 374       printk("%s: busy timeout sending configuration, detaching.\n", name);
 375       return FALSE;
 376       }
 377 
 378    sh[j] = scsi_register(tpnt, sizeof(struct hostdata));
 379    sh[j]->io_port = *port_base;
 380    sh[j]->dma_channel = dma_channel;
 381    sh[j]->irq = irq;
 382    sh[j]->sg_tablesize = (ushort) ntohs(info.scatt_size);
 383    sh[j]->this_id = (ushort) ntohl(info.host_addr);
 384    sh[j]->can_queue = (ushort) ntohs(info.queue_size);
 385    sh[j]->cmd_per_lun = MAX_CMD_PER_LUN;
 386 
 387    /* Register the I/O space that we use */
 388    snarf_region(sh[j]->io_port, REG_REGION);
 389 
 390    memset(HD(j), 0, sizeof(struct hostdata));
 391    HD(j)->subversion = subversion;
 392    HD(j)->board_number = j;
 393    irqlist[irq] = j;
 394 
 395    if (HD(j)->subversion == ESA)
 396       sh[j]->unchecked_isa_dma = FALSE;
 397    else {
 398       sh[j]->block = sh[j];
 399       sh[j]->unchecked_isa_dma = TRUE;
 400       disable_dma(dma_channel);
 401       clear_dma_ff(dma_channel);
 402       set_dma_mode(dma_channel, DMA_MODE_CASCADE);
 403       enable_dma(dma_channel);
 404       }
 405 
 406    strcpy(BN(j), name);
 407 
 408    printk("%s: %s, ID %d, PORT 0x%03x, IRQ %u, DMA %u, SG %d, "\
 409           "Mbox %d, CmdLun %d.\n", BN(j), board_status, sh[j]->this_id, 
 410            sh[j]->io_port, sh[j]->irq, 
 411            sh[j]->dma_channel, sh[j]->sg_tablesize, 
 412            sh[j]->can_queue, sh[j]->cmd_per_lun);
 413 
 414    /* DPT PM2012 does not allow to detect sg_tablesize correctly */
 415    if (sh[j]->sg_tablesize > MAX_SGLIST || sh[j]->sg_tablesize < 2) {
 416       printk("%s: detect, forcing to use %d SG lists.\n", BN(j), MAX_SGLIST);
 417       sh[j]->sg_tablesize = MAX_SGLIST;
 418       }
 419 
 420    /* DPT PM2012 does not allow to detect can_queue correctly */
 421    if (sh[j]->can_queue > MAX_MAILBOXES || sh[j]->can_queue  < 2) {
 422       printk("%s: detect, forcing to use %d Mbox.\n", BN(j), MAX_MAILBOXES);
 423       sh[j]->can_queue = MAX_MAILBOXES;
 424       }
 425 
 426 #if defined (DEBUG_DETECT)
 427    printk("%s: Version 0x%x, SYNC 0x%x, infol %ld, cpl %ld spl %ld.\n", 
 428           name, info.version, info.sync, ntohl(info.data_len), 
 429           ntohl(info.cp_len), ntohl(info.sp_len));
 430 #endif
 431 
 432    return TRUE;
 433 }
 434 
 435 int eata_detect (Scsi_Host_Template * tpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 436    unsigned int j = 0, k, flags;
 437 
 438    ushort io_port[] = { 
 439       0x1c88, 0x2c88, 0x3c88, 0x4c88, 0x5c88, 0x6c88, 0x7c88, 0x8c88,
 440       0x9c88, 0xac88, 0xbc88, 0xcc88, 0xdc88, 0xec88, 0xfc88, 
 441       0x330,  0x230,  0x1f0,  0x170,  0x0
 442       };
 443 
 444    ushort *port_base = io_port;
 445 
 446    save_flags(flags);
 447    cli();
 448 
 449    for (k = 0; k < MAX_IRQ; k++) {
 450       irqlist[k] = NO_IRQ;
 451       calls[k] = 0;
 452       }
 453 
 454    for (k = 0; k < MAX_BOARDS + 1; k++) sh[k] = NULL;
 455 
 456    while (*port_base) {
 457 
 458       if (j < MAX_BOARDS && port_detect(port_base, j, tpnt)) j++;
 459 
 460       port_base++;
 461       }
 462 
 463    restore_flags(flags);
 464    return j;
 465 }
 466 
 467 static inline void build_sg_list(struct mscp *cpp, Scsi_Cmnd *SCpnt) {
     /* [previous][next][first][last][top][bottom][index][help] */
 468    unsigned int k;
 469    struct scatterlist * sgpnt;
 470 
 471    sgpnt = (struct scatterlist *) SCpnt->request_buffer;
 472 
 473    for (k = 0; k < SCpnt->use_sg; k++) {
 474       cpp->sglist[k].address = htonl((unsigned int) sgpnt[k].address);
 475       cpp->sglist[k].num_bytes = htonl((unsigned int) sgpnt[k].length);
 476       }
 477 
 478    cpp->data_address = htonl((unsigned int) cpp->sglist);
 479    cpp->data_len = htonl((SCpnt->use_sg * sizeof(struct sg_list)));
 480 }
 481 
 482 int eata_queuecommand (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *)) {
     /* [previous][next][first][last][top][bottom][index][help] */
 483    unsigned int i, j, k, flags;
 484    struct mscp *cpp;
 485    struct mssp *spp;
 486 
 487    save_flags(flags);
 488    cli();
 489    /* j is the board number */
 490    j = ((struct hostdata *) SCpnt->host->hostdata)->board_number;
 491 
 492    if (!done) panic("%s: qcomm, pid %ld, null done.\n", BN(j), SCpnt->pid);
 493 
 494    /* i is the mailbox number, look for the first free mailbox 
 495       starting from last_cp_used */
 496    i = HD(j)->last_cp_used + 1;
 497 
 498    for (k = 0; k < sh[j]->can_queue; k++, i++) {
 499 
 500       if (i >= sh[j]->can_queue) i = 0;
 501 
 502       if (HD(j)->cp_stat[i] == FREE) {
 503          HD(j)->last_cp_used = i;
 504          break;
 505          }
 506       }
 507 
 508    if (k == sh[j]->can_queue) {
 509       printk("%s: qcomm, no free mailbox, resetting.\n", BN(j));
 510 
 511       if (HD(j)->in_reset) 
 512          printk("%s: qcomm, already in reset.\n", BN(j));
 513       else if (eata_reset(SCpnt) == SCSI_RESET_SUCCESS) 
 514          panic("%s: qcomm, SCSI_RESET_SUCCESS.\n", BN(j));
 515 
 516       SCpnt->result = DID_BUS_BUSY << 16; 
 517       SCpnt->host_scribble = NULL;
 518       printk("%s: qcomm, pid %ld, DID_BUS_BUSY, done.\n", BN(j), SCpnt->pid);
 519       restore_flags(flags);
 520       done(SCpnt);    
 521       return 0;
 522       }
 523 
 524    /* Set pointer to control packet structure */
 525    cpp = &HD(j)->cp[i];
 526 
 527    memset(cpp, 0, sizeof(struct mscp));
 528 
 529    /* Set pointer to status packet structure */
 530    spp = &HD(j)->sp[i];
 531 
 532    memset(spp, 0, sizeof(struct mssp));
 533 
 534    /* The EATA protocol uses Big Endian format, while Intel is Little Endian */
 535    cpp->sp_addr = htonl((unsigned int) spp);
 536 
 537    SCpnt->scsi_done = done;
 538    cpp->index = i;
 539    SCpnt->host_scribble = (unsigned char *) &cpp->index;
 540 
 541    if (do_trace) printk("%s: qcomm, mbox %d, target %d, pid %ld.\n",
 542                         BN(j), i, SCpnt->target, SCpnt->pid);
 543 
 544    if (SCpnt->cmnd[0] == WRITE_10 || SCpnt->cmnd[0] == WRITE_6)
 545       cpp->dout = TRUE;
 546    else
 547       cpp->din = TRUE;
 548 
 549    cpp->reqsen = TRUE;
 550    cpp->dispri = TRUE;
 551    cpp->one = TRUE;
 552    cpp->target = SCpnt->target;
 553    cpp->lun = SCpnt->lun;  
 554    cpp->SCpnt = SCpnt;
 555    cpp->sense_addr = htonl((unsigned int) SCpnt->sense_buffer); 
 556    cpp->sense_len = sizeof SCpnt->sense_buffer;
 557 
 558    if (SCpnt->use_sg) {
 559       cpp->sg = TRUE;
 560       build_sg_list(cpp, SCpnt);
 561       }
 562    else {
 563       cpp->data_address = htonl((unsigned int) SCpnt->request_buffer);
 564       cpp->data_len = htonl(SCpnt->request_bufflen);
 565       }
 566 
 567    memcpy(cpp->cdb, SCpnt->cmnd, SCpnt->cmd_len);
 568 
 569    /* Send control packet to the board */
 570    if (do_dma(sh[j]->io_port, (unsigned int) cpp, SEND_CP_DMA)) {
 571       SCpnt->result = DID_ERROR << 16; 
 572       SCpnt->host_scribble = NULL;
 573       printk("%s: qcomm, target %d, pid %ld, adapter busy, DID_ERROR, done.\n", 
 574              BN(j), SCpnt->target, SCpnt->pid);
 575       restore_flags(flags);
 576       done(SCpnt);    
 577       return 0;
 578       }
 579 
 580    HD(j)->cp_stat[i] = IN_USE;
 581    restore_flags(flags);
 582    return 0;
 583 }
 584 
 585 int eata_abort (Scsi_Cmnd *SCarg) {
     /* [previous][next][first][last][top][bottom][index][help] */
 586    unsigned int i, j, flags;
 587 
 588    save_flags(flags);
 589    cli();
 590    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
 591 
 592    if (SCarg->host_scribble == NULL) {
 593       printk("%s: abort, target %d, pid %ld inactive.\n",
 594              BN(j), SCarg->target, SCarg->pid);
 595       return SCSI_ABORT_NOT_RUNNING;
 596       }
 597 
 598    i = *(unsigned int *)SCarg->host_scribble;
 599    printk("%s: abort, mbox %d, target %d, pid %ld.\n", 
 600           BN(j), i, SCarg->target, SCarg->pid);
 601 
 602    if (i >= sh[j]->can_queue)
 603       panic("%s: abort, invalid SCarg->host_scribble.\n", BN(j));
 604 
 605    if (wait_on_busy(sh[j]->io_port)) {
 606       printk("%s: abort, timeout error.\n", BN(j));
 607       restore_flags(flags);
 608       return SCSI_ABORT_ERROR;
 609       }
 610 
 611    if (HD(j)->cp_stat[i] == FREE) {
 612       printk("%s: abort, mbox %d is free.\n", BN(j), i);
 613       restore_flags(flags);
 614       return SCSI_ABORT_NOT_RUNNING;
 615       }
 616 
 617    if (HD(j)->cp_stat[i] == IN_USE) {
 618       printk("%s: abort, mbox %d is in use.\n", BN(j), i);
 619 
 620       if (SCarg != HD(j)->cp[i].SCpnt)
 621          panic("%s: abort, mbox %d, SCarg %p, cp SCpnt %p.\n",
 622                BN(j), i, SCarg, HD(j)->cp[i].SCpnt);
 623 
 624       restore_flags(flags);
 625       return SCSI_ABORT_SNOOZE;
 626       }
 627 
 628    if (HD(j)->cp_stat[i] == IN_RESET) {
 629       printk("%s: abort, mbox %d is in reset.\n", BN(j), i);
 630       restore_flags(flags);
 631       return SCSI_ABORT_ERROR;
 632       }
 633 
 634    if (HD(j)->cp_stat[i] == LOCKED) {
 635       printk("%s: abort, mbox %d is locked.\n", BN(j), i);
 636       restore_flags(flags);
 637       return SCSI_ABORT_NOT_RUNNING;
 638       }
 639    else
 640       panic("%s: abort, mbox %d, invalid cp_stat.\n", BN(j), i);
 641 }
 642 
 643 int eata_reset (Scsi_Cmnd *SCarg) {
     /* [previous][next][first][last][top][bottom][index][help] */
 644    unsigned int i, j, flags, time, k, limit = 0;
 645    int arg_done = FALSE;
 646    Scsi_Cmnd *SCpnt;
 647 
 648    save_flags(flags);
 649    cli();
 650    j = ((struct hostdata *) SCarg->host->hostdata)->board_number;
 651    printk("%s: reset, enter, target %d, pid %ld.\n", 
 652           BN(j), SCarg->target, SCarg->pid);
 653 
 654    if (SCarg->host_scribble == NULL)
 655       printk("%s: reset, pid %ld inactive.\n", BN(j), SCarg->pid);
 656 
 657    if (HD(j)->in_reset) {
 658       printk("%s: reset, exit, already in reset.\n", BN(j));
 659       restore_flags(flags);
 660       return SCSI_RESET_ERROR;
 661       }
 662 
 663    if (wait_on_busy(sh[j]->io_port)) {
 664       printk("%s: reset, exit, timeout error.\n", BN(j));
 665       restore_flags(flags);
 666       return SCSI_RESET_ERROR;
 667       }
 668 
 669    for (k = 0; k < MAX_TARGET; k++) HD(j)->target_reset[k] = TRUE;
 670 
 671    for (i = 0; i < sh[j]->can_queue; i++) {
 672 
 673       if (HD(j)->cp_stat[i] == FREE) continue;
 674 
 675       if (HD(j)->cp_stat[i] == LOCKED) {
 676          HD(j)->cp_stat[i] = FREE;
 677          printk("%s: reset, locked mbox %d forced free.\n", BN(j), i);
 678          continue;
 679          }
 680 
 681       SCpnt = HD(j)->cp[i].SCpnt;
 682       HD(j)->cp_stat[i] = IN_RESET;
 683       printk("%s: reset, mbox %d in reset, pid %ld.\n",
 684              BN(j), i, SCpnt->pid);
 685 
 686       if (SCpnt == NULL)
 687          panic("%s: reset, mbox %d, SCpnt == NULL.\n", BN(j), i);
 688 
 689       if (SCpnt->host_scribble == NULL)
 690          panic("%s: reset, mbox %d, garbled SCpnt.\n", BN(j), i);
 691 
 692       if (*(unsigned int *)SCpnt->host_scribble != i) 
 693          panic("%s: reset, mbox %d, index mismatch.\n", BN(j), i);
 694 
 695       if (SCpnt->scsi_done == NULL) 
 696          panic("%s: reset, mbox %d, SCpnt->scsi_done == NULL.\n", BN(j), i);
 697 
 698       if (SCpnt == SCarg) arg_done = TRUE;
 699       }
 700 
 701    if (do_dma(sh[j]->io_port, 0, RESET_PIO)) {
 702       printk("%s: reset, cannot reset, timeout error.\n", BN(j));
 703       restore_flags(flags);
 704       return SCSI_RESET_ERROR;
 705       }
 706 
 707    printk("%s: reset, board reset done, enabling interrupts.\n", BN(j));
 708    do_trace = TRUE;
 709    HD(j)->in_reset = TRUE;
 710    sti();
 711    time = jiffies;
 712    while (jiffies < (time + 200) && limit++ < 100000000) sti();
 713    cli();
 714    printk("%s: reset, interrupts disabled, loops %d.\n", BN(j), limit);
 715 
 716    for (i = 0; i < sh[j]->can_queue; i++) {
 717 
 718       /* Skip mailboxes already set free by interrupt */
 719       if (HD(j)->cp_stat[i] != IN_RESET) continue;
 720 
 721       SCpnt = HD(j)->cp[i].SCpnt;
 722       SCpnt->result = DID_RESET << 16;
 723       SCpnt->host_scribble = NULL;
 724 
 725       /* This mailbox is still waiting for its interrupt */
 726       HD(j)->cp_stat[i] = LOCKED;
 727 
 728       printk("%s, reset, mbox %d locked, DID_RESET, pid %ld done.\n",
 729              BN(j), i, SCpnt->pid);
 730       restore_flags(flags);
 731       SCpnt->scsi_done(SCpnt);
 732       cli();
 733       }
 734 
 735    HD(j)->in_reset = FALSE;
 736    do_trace = FALSE;
 737    restore_flags(flags);
 738 
 739    if (arg_done) {
 740       printk("%s: reset, exit, success.\n", BN(j));
 741       return SCSI_RESET_SUCCESS;
 742       }
 743    else {
 744       printk("%s: reset, exit, wakeup.\n", BN(j));
 745       return SCSI_RESET_PUNT;
 746       }
 747 }
 748 
 749 static void eata_interrupt_handler(int irq) {
     /* [previous][next][first][last][top][bottom][index][help] */
 750    Scsi_Cmnd *SCpnt;
 751    unsigned int i, j, k, flags, status, loops, total_loops = 0;
 752    struct mssp *spp;
 753    struct mscp *cpp;
 754 
 755    save_flags(flags);
 756    cli();
 757 
 758    if (irqlist[irq] == NO_IRQ) {
 759       printk("%s, ihdlr, irq %d, unexpected interrupt.\n", driver_name, irq);
 760       restore_flags(flags);
 761       return;
 762       }
 763 
 764    if (do_trace) printk("%s: ihdlr, enter, irq %d, calls %d.\n", 
 765                         driver_name, irq, calls[irq]);
 766 
 767    /* Service all the boards configured on this irq */
 768    for (j = 0; sh[j] != NULL; j++) {
 769 
 770       if (sh[j]->irq != irq) continue;
 771 
 772       loops = 0;
 773 
 774       /* Loop until all interrupts for a board are serviced */
 775       while (inb(sh[j]->io_port + REG_AUX_STATUS) & IRQ_ASSERTED) {
 776          total_loops++;
 777          loops++;
 778 
 779          if (do_trace) printk("%s: ihdlr, start service, count %d.\n",
 780                               BN(j), HD(j)->iocount);
 781    
 782          /* Read the status register to clear the interrupt indication */
 783          inb(sh[j]->io_port + REG_STATUS);
 784    
 785          /* Service all mailboxes of this board */
 786          for (i = 0; i < sh[j]->can_queue; i++) {
 787             spp = &HD(j)->sp[i];
 788    
 789             /* Check if this mailbox has completed the operation */
 790             if (spp->eoc == FALSE) continue;
 791    
 792             spp->eoc = FALSE;
 793    
 794             if (HD(j)->cp_stat[i] == LOCKED) {
 795                HD(j)->cp_stat[i] = FREE;
 796                printk("%s: ihdlr, mbox %d unlocked, count %d.\n",
 797                       BN(j), i, HD(j)->iocount);
 798                continue;
 799                }
 800             else if (HD(j)->cp_stat[i] == FREE) {
 801                printk("%s: ihdlr, mbox %d is free, count %d.\n", 
 802                       BN(j), i, HD(j)->iocount);
 803                continue;
 804                }
 805             else if (HD(j)->cp_stat[i] == IN_RESET)
 806                printk("%s: ihdlr, mbox %d is in reset.\n", BN(j), i);
 807             else if (HD(j)->cp_stat[i] != IN_USE) 
 808                panic("%s: ihdlr, mbox %d, invalid cp_stat.\n", BN(j), i);
 809    
 810             HD(j)->cp_stat[i] = FREE;
 811             cpp = &HD(j)->cp[i];
 812             SCpnt = spp->SCpnt;
 813    
 814             if (SCpnt == NULL)
 815                panic("%s: ihdlr, mbox %d, SCpnt == NULL.\n", BN(j), i);
 816    
 817             if (SCpnt != cpp->SCpnt)
 818                panic("%s: ihdlr, mbox %d, sp SCpnt %p, cp SCpnt %p.\n",
 819                      BN(j), i, SCpnt, cpp->SCpnt);
 820    
 821             if (SCpnt->host_scribble == NULL)
 822                panic("%s: ihdlr, mbox %d, pid %ld, SCpnt %p garbled.\n",
 823                      BN(j), i, SCpnt->pid, SCpnt);
 824    
 825             if (*(unsigned int *)SCpnt->host_scribble != i) 
 826                panic("%s: ihdlr, mbox %d, pid %ld, index mismatch %d,"\
 827                      " irq %d.\n", BN(j), i, SCpnt->pid, 
 828                      *(unsigned int *)SCpnt->host_scribble, irq);
 829    
 830             switch (spp->adapter_status) {
 831                case ASOK:          /* status OK */
 832    
 833                   /* Fix a "READ CAPACITY failed" error on some disk drives */
 834                   if (spp->target_status == INTERMEDIATE_GOOD
 835                                         && SCpnt->device->type != TYPE_TAPE) 
 836                      status = DID_ERROR << 16;
 837    
 838                   /* If there was a bus reset, redo operation on each target */
 839                   else if (spp->target_status == CONDITION_GOOD
 840                                         && SCpnt->device->type == TYPE_DISK
 841                                         && HD(j)->target_reset[SCpnt->target])
 842                      status = DID_BUS_BUSY << 16;
 843                   else
 844                      status = DID_OK << 16;
 845    
 846                   if (spp->target_status == 0)
 847                      HD(j)->target_reset[SCpnt->target] = FALSE;
 848    
 849                   HD(j)->target_time_out[SCpnt->target] = 0;
 850    
 851                   break;
 852                case ASST:          /* Selection Time Out */
 853                case 0x02:          /* Command Time Out   */
 854    
 855                   if (HD(j)->target_time_out[SCpnt->target] > 1)
 856                      status = DID_ERROR << 16;
 857                   else {
 858                      status = DID_TIME_OUT << 16;
 859                      HD(j)->target_time_out[SCpnt->target]++;
 860                      }
 861    
 862                   break;
 863                case 0x03:          /* SCSI Bus Reset Received */
 864    
 865                   if (SCpnt->device->type != TYPE_TAPE)
 866                      status = DID_BUS_BUSY << 16;
 867                   else
 868                      status = DID_ERROR << 16;
 869    
 870                   for (k = 0; k < MAX_TARGET; k++) 
 871                      HD(j)->target_reset[k] = TRUE;
 872    
 873                   break;
 874                case 0x07:          /* Bus Parity Error */
 875                case 0x0c:          /* Controller Ram Parity */
 876                case 0x04:          /* Initial Controller Power-up */
 877                case 0x05:          /* Unexpected Bus Phase */
 878                case 0x06:          /* Unexpected Bus Free */
 879                case 0x08:          /* SCSI Hung */
 880                case 0x09:          /* Unexpected Message Reject */
 881                case 0x0a:          /* SCSI Bus Reset Stuck */
 882                case 0x0b:          /* Auto Request-Sense Failed */
 883                default:
 884                   status = DID_ERROR << 16;
 885                   break;
 886                }
 887    
 888             SCpnt->result = status | spp->target_status;
 889             HD(j)->iocount++;
 890 
 891             if (loops > 1) HD(j)->multicount++;
 892 
 893 #if defined (DEBUG_INTERRUPT)
 894             if (SCpnt->result || do_trace)
 895 #else
 896             if ((spp->adapter_status != ASOK && HD(j)->iocount >  1000) ||
 897                 (spp->adapter_status != ASOK && 
 898                  spp->adapter_status != ASST && HD(j)->iocount <= 1000) ||
 899                 do_trace)
 900 #endif
 901                printk("%s: ihdlr, mbox %d, err 0x%x:%x,"\
 902                       " target %d:%d, pid %ld, count %d.\n",
 903                       BN(j), i, spp->adapter_status, spp->target_status,
 904                       SCpnt->target, SCpnt->lun, SCpnt->pid, HD(j)->iocount);
 905    
 906             /* Set the command state to inactive */
 907             SCpnt->host_scribble = NULL;
 908    
 909             restore_flags(flags);
 910             SCpnt->scsi_done(SCpnt);
 911             cli();
 912 
 913             }   /* Mailbox loop */
 914 
 915          }   /* Multiple command loop */
 916 
 917       }   /* Boards loop */
 918 
 919    calls[irq]++;
 920 
 921    if (total_loops == 0) 
 922      printk("%s: ihdlr, irq %d, no command completed, calls %d.\n",
 923             driver_name, irq, calls[irq]);
 924 
 925    if (do_trace) printk("%s: ihdlr, exit, irq %d, calls %d.\n", 
 926                         driver_name, irq, calls[irq]);
 927 
 928 #if defined (DEBUG_STATISTICS)
 929    if ((calls[irq] % 100000) == 10000)
 930       for (j = 0; sh[j] != NULL; j++)
 931          printk("%s: ihdlr, calls %d, count %d, multi %d.\n", BN(j),
 932                 calls[(sh[j]->irq)], HD(j)->iocount, HD(j)->multicount);
 933 #endif
 934 
 935    restore_flags(flags);
 936    return;
 937 }

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