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

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