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_bios_param
  11. eata_interrupt_handler

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

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