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. eata_info
  7. build_sg_list
  8. eata_queuecommand
  9. eata_abort
  10. eata_reset
  11. eata_bios_param
  12. eata_interrupt_handler

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

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