root/drivers/scsi/eata_dma.c

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

DEFINITIONS

This source file includes following definitions.
  1. eata_scsi_done
  2. eata_fake_int_handler
  3. eata_release
  4. eata_info
  5. eata_int_handler
  6. eata_send_command
  7. eata_send_immediate
  8. eata_queue
  9. eata_abort
  10. eata_reset
  11. get_board_data
  12. check_blink_state
  13. get_conf_PIO
  14. print_config
  15. register_HBA
  16. find_EISA
  17. find_ISA
  18. find_PCI
  19. eata_detect

   1 /************************************************************
   2  *                                                          *
   3  *                  Linux EATA SCSI driver                  *
   4  *                                                          *
   5  *  based on the CAM document CAM/89-004 rev. 2.0c,         *
   6  *  DPT's driver kit, some internal documents and source,   *
   7  *  and several other Linux scsi drivers and kernel docs.   *
   8  *                                                          *
   9  *  The driver currently:                                   *
  10  *      -supports all ISA based EATA-DMA boards             *
  11  *      -supports all EISA based EATA-DMA boards            *
  12  *      -supports all PCI based EATA-DMA boards             *
  13  *      -supports multiple HBAs with & without IRQ sharing  *
  14  *      -supports all SCSI channels on multi channel boards *
  15  *      -can be loaded as module                            *
  16  *      -displays statistical and hardware information      *
  17  *       in /proc/scsi/eata_dma                             *
  18  *      -needs identical HBA ids on all channels            * 
  19  *                                                          *
  20  *  (c)1993,94,95 Michael Neuffer                           *
  21  *                neuffer@goofy.zdv.uni-mainz.de            *
  22  *                                                          *
  23  *  This program is free software; you can redistribute it  *
  24  *  and/or modify it under the terms of the GNU General     *
  25  *  Public License as published by the Free Software        *
  26  *  Foundation; either version 2 of the License, or         *
  27  *  (at your option) any later version.                     *
  28  *                                                          *
  29  *  This program is distributed in the hope that it will be *
  30  *  useful, but WITHOUT ANY WARRANTY; without even the      *
  31  *  implied warranty of MERCHANTABILITY or FITNESS FOR A    *
  32  *  PARTICULAR PURPOSE.  See the GNU General Public License *
  33  *  for more details.                                       *
  34  *                                                          *
  35  *  You should have received a copy of the GNU General      *
  36  *  Public License along with this kernel; if not, write to *
  37  *  the Free Software Foundation, Inc., 675 Mass Ave,       *
  38  *  Cambridge, MA 02139, USA.                               *
  39  *                                                          *
  40  * I have to thank DPT for their excellent support. I took  *
  41  * me almost a year and a stopover at their HQ, on my first *
  42  * trip to the USA, to get it, but since then they've been  *
  43  * very helpful and tried to give me all the infos and      *
  44  * support I need.                                          *
  45  *                                                          *
  46  * Thanks also to Greg Hosler who did a lot of testing and  *
  47  * found quite a number of bugs during the development.     *
  48  ************************************************************
  49  *  last change: 95/06/28 OS: Linux 1.3.4 + pre1.3 SCSI pat.*
  50  ************************************************************/
  51 
  52 /* Look in eata_dma.h for configuration and revision information */
  53 
  54 #ifdef MODULE
  55 #include <linux/module.h>
  56 #include <linux/version.h>
  57 #endif
  58  
  59 #include <linux/kernel.h>
  60 #include <linux/sched.h>
  61 #include <linux/string.h>
  62 #include <linux/ioport.h>
  63 #include <linux/malloc.h>
  64 #include <linux/in.h>
  65 #include <linux/bios32.h>
  66 #include <linux/pci.h>
  67 #include <linux/proc_fs.h>
  68 #include <asm/byteorder.h>
  69 #include <asm/types.h>
  70 #include <asm/io.h>
  71 #include <asm/dma.h>
  72 #include "../block/blk.h"
  73 #include "scsi.h"
  74 #include "sd.h"
  75 #include "hosts.h"
  76 #include <linux/scsicam.h>
  77 #include "eata_dma.h"
  78 #include "eata_dma_proc.h" 
  79 
  80 
  81 static u32 ISAbases[] =
  82 {0x1F0, 0x170, 0x330, 0x230};
  83 static unchar EISAbases[] =
  84 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  85 static uint registered_HBAs = 0;
  86 static struct Scsi_Host *last_HBA = NULL;
  87 static struct Scsi_Host *first_HBA = NULL;
  88 static unchar reg_IRQ[] =
  89 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  90 static unchar reg_IRQL[] =
  91 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  92 static struct eata_sp *status = 0;   /* Statuspacket array   */
  93 static void *dma_scratch = 0;
  94 
  95 static uint internal_command_finished = TRUE;
  96 static unchar HBA_interpret = FALSE;
  97 static u32 fake_int_base;
  98 static u32 fake_int_result;
  99 
 100 static ulong int_counter = 0;
 101 static ulong queue_counter = 0;
 102 
 103 void eata_scsi_done (Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 104 {
 105     return;
 106 }   
 107 
 108 void eata_fake_int_handler(s32 irq, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 109 {
 110     fake_int_result = inb(fake_int_base + HA_RSTATUS);
 111     DBG(DBG_INTR3, printk("eata_fake_int_handler called irq%d base %#x"
 112                           " res %#x\n", irq, fake_int_base, fake_int_result));
 113     return;
 114 }
 115 
 116 #include "eata_dma_proc.c"
 117 
 118 #ifdef MODULE
 119 int eata_release(struct Scsi_Host *sh)
     /* [previous][next][first][last][top][bottom][index][help] */
 120 {
 121     uint i;
 122     if (sh->irq && reg_IRQ[sh->irq] == 1) free_irq(sh->irq);
 123     else reg_IRQ[sh->irq]--;
 124     
 125     scsi_init_free((void *)status, 512);
 126     scsi_init_free((void *)dma_scratch, 512);
 127     for (i = 0; i < sh->can_queue; i++){ /* Free all SG arrays */
 128         if(SD(sh)->ccb[i].sg_list != NULL)
 129             scsi_init_free((void *) SD(sh)->ccb[i].sg_list, 
 130                            sh->sg_tablesize * sizeof(struct eata_sg_list));
 131     }
 132     
 133     if (SD(sh)->channel == 0) {
 134         if (sh->dma_channel != 0xff) free_dma(sh->dma_channel);
 135         if (sh->io_port && sh->n_io_port)
 136             release_region(sh->io_port, sh->n_io_port);
 137     }
 138     return(TRUE);
 139 }
 140 #endif
 141 
 142 const char *eata_info(struct Scsi_Host *host)
     /* [previous][next][first][last][top][bottom][index][help] */
 143 {
 144     static char *information = "EATA SCSI HBA Driver";
 145     return information;
 146 }
 147 
 148 void eata_int_handler(int irq, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 149 {
 150     uint i, result = 0;
 151     uint hba_stat, scsi_stat, eata_stat;
 152     Scsi_Cmnd *cmd;
 153     struct eata_ccb *cp;
 154     struct eata_sp *sp;
 155     uint base;
 156     ulong flags;
 157     uint x;
 158     struct Scsi_Host *sh;
 159 
 160     save_flags(flags);
 161     cli();
 162 
 163     for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) {
 164         if (sh->irq != irq)
 165             continue;
 166         if (!(inb((uint)sh->base + HA_RAUXSTAT) & HA_AIRQ))
 167             continue;
 168         
 169         int_counter++;
 170         
 171         sp=&SD(sh)->sp;
 172         
 173         cp = sp->ccb;
 174         cmd = cp->cmd;
 175         base = (uint) cmd->host->base;
 176         
 177         hba_stat = sp->hba_stat;
 178         
 179         scsi_stat = (sp->scsi_stat >> 1) & 0x1f; 
 180        
 181         if (sp->EOC == FALSE) {
 182             eata_stat = inb(base + HA_RSTATUS);
 183             printk("eata_dma: int_handler, board: %x cmd %lx returned "
 184                    "unfinished.\nEATA: %x HBA: %x SCSI: %x spadr %lx spadrirq "
 185                    "%lx, irq%d\n", base, (long)cp, eata_stat, hba_stat, 
 186                    scsi_stat,(long)&status, (long)&status[irq], irq);
 187             DBG(DBG_DELAY, DEL2(800));
 188             restore_flags(flags);
 189             return;
 190         } 
 191         
 192         if (cp->status == LOCKED) {
 193             cp->status = FREE;
 194             eata_stat = inb(base + HA_RSTATUS);
 195             printk("eata_dma: int_handler, freeing locked queueslot\n");
 196             DBG(DBG_INTR && DBG_DELAY, DEL2(800));
 197             restore_flags(flags);
 198             return;
 199         }
 200         
 201         eata_stat = inb(base + HA_RSTATUS); 
 202         DBG(DBG_INTR, printk("IRQ %d received, base %#.4x, pid %ld, target: "
 203                              "%x, lun: %x, ea_s: %#.2x, hba_s: %#.2x \n", 
 204                              irq, base, cmd->pid, cmd->target, cmd->lun, 
 205                              eata_stat, hba_stat));
 206 
 207         switch (hba_stat) {
 208         case HA_NO_ERROR:       /* NO Error */
 209             if (scsi_stat == CONDITION_GOOD
 210                 && cmd->device->type == TYPE_DISK
 211                 && (HD(cmd)->t_state[cp->cp_channel][cp->cp_id] == RESET))
 212                 result = DID_BUS_BUSY << 16;        
 213             else if (scsi_stat == GOOD)
 214                 HD(cmd)->t_state[cp->cp_channel][cp->cp_id] = OK;
 215             else if (scsi_stat == CHECK_CONDITION
 216                      && cmd->device->type == TYPE_DISK
 217                      && (cmd->sense_buffer[2] & 0xf) == RECOVERED_ERROR)
 218                 result = DID_BUS_BUSY << 16;
 219             else
 220                 result = DID_OK << 16;
 221             HD(cmd)->t_timeout[cp->cp_channel][cp->cp_id] = OK;
 222             break;
 223         case HA_ERR_SEL_TO:     /* Selection Timeout */
 224             result = DID_BAD_TARGET << 16;  
 225             break;
 226         case HA_ERR_CMD_TO:     /* Command Timeout   */
 227             if (HD(cmd)->t_timeout[cp->cp_channel][cp->cp_id] > 1)
 228                 result = DID_ERROR << 16;
 229             else {
 230                 result = DID_TIME_OUT << 16;
 231                 HD(cmd)->t_timeout[cp->cp_channel][cp->cp_id]++;
 232             }
 233             break;
 234         case HA_ERR_RESET:              /* SCSI Bus Reset Received */
 235         case HA_INIT_POWERUP:           /* Initial Controller Power-up */
 236             if (cmd->device->type != TYPE_TAPE)
 237                 result = DID_BUS_BUSY << 16;
 238             else
 239                 result = DID_ERROR << 16;
 240             
 241             for (i = 0; i < MAXTARGET; i++)
 242                 HD(cmd)->t_state[cp->cp_channel][i] = RESET;
 243             break;
 244         case HA_UNX_BUSPHASE:       /* Unexpected Bus Phase */
 245         case HA_UNX_BUS_FREE:       /* Unexpected Bus Free */
 246         case HA_BUS_PARITY:         /* Bus Parity Error */
 247         case HA_SCSI_HUNG:          /* SCSI Hung */
 248         case HA_UNX_MSGRJCT:        /* Unexpected Message Reject */
 249         case HA_RESET_STUCK:        /* SCSI Bus Reset Stuck */
 250         case HA_RSENSE_FAIL:        /* Auto Request-Sense Failed */
 251         case HA_PARITY_ERR:         /* Controller Ram Parity */
 252         default:
 253             result = DID_ERROR << 16;
 254             break;
 255         }
 256         cmd->result = result | (scsi_stat << 1); 
 257         
 258 #if DBG_INTR2
 259         if (scsi_stat || result || hba_stat || eata_stat != 0x50 
 260             || cmd->scsi_done == NULL || cmd->device->id == 7) 
 261             printk("HBA: %d, channel %d, id: %d, lun %d, pid %ld:\n" 
 262                    "eata_stat %#x, hba_stat %#.2x, scsi_stat %#.2x, "
 263                    "sense_key: %#x, result: %#.8x\n", 
 264                    x, cmd->device->channel, cmd->device->id, cmd->device->lun,
 265                    cmd->pid, eata_stat, hba_stat, scsi_stat, 
 266                    cmd->sense_buffer[2] & 0xf, cmd->result); 
 267         DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
 268 #endif
 269         
 270         cp->status = FREE;          /* now we can release the slot  */
 271         
 272         restore_flags(flags);
 273         if(cmd->scsi_done != eata_scsi_done) cmd->scsi_done(cmd);
 274         else {
 275             internal_command_finished = TRUE;
 276             HBA_interpret = FALSE;
 277         }
 278         save_flags(flags);
 279         cli();
 280     }
 281     restore_flags(flags);
 282     
 283     return;
 284 }
 285 
 286 inline int eata_send_command(u32 addr, u32 base, u8 command)
     /* [previous][next][first][last][top][bottom][index][help] */
 287 {
 288     long loop = R_LIMIT;
 289     
 290     while (inb(base + HA_RAUXSTAT) & HA_ABUSY)
 291         if (--loop == 0)
 292             return(FALSE);
 293     
 294     outb( addr & 0x000000ff,        base + HA_WDMAADDR);
 295     outb((addr & 0x0000ff00) >> 8,  base + HA_WDMAADDR + 1);
 296     outb((addr & 0x00ff0000) >> 16, base + HA_WDMAADDR + 2);
 297     outb((addr & 0xff000000) >> 24, base + HA_WDMAADDR + 3);
 298     outb(command, base + HA_WCOMMAND);
 299     return(TRUE);
 300 }
 301 
 302 #if 0
 303 inline int eata_send_immediate(u32 addr, u32 base, u8 cmnd, u8 cmnd2, u8 id, 
     /* [previous][next][first][last][top][bottom][index][help] */
 304                                u8 lun)
 305 {
 306     if(addr){
 307         outb( addr & 0x000000ff,        base + HA_WDMAADDR);
 308         outb((addr & 0x0000ff00) >> 8,  base + HA_WDMAADDR + 1);
 309         outb((addr & 0x00ff0000) >> 16, base + HA_WDMAADDR + 2);
 310         outb((addr & 0xff000000) >> 24, base + HA_WDMAADDR + 3);
 311     } else {
 312         outb(id,  base + HA_WSUBCODE);
 313         outb(lun, base + HA_WSUBLUN);
 314     }
 315     
 316     outb(cmnd2, base + HA_WCOMMAND2);
 317     outb(cmnd,  base + HA_WCOMMAND);
 318     return(TRUE);
 319 }
 320 #endif
 321 
 322 int eata_queue(Scsi_Cmnd * cmd, void (* done) (Scsi_Cmnd *))
     /* [previous][next][first][last][top][bottom][index][help] */
 323 {
 324     unsigned int i, x, y;
 325     u32 flags;
 326     hostdata *hd;
 327     struct Scsi_Host *sh;
 328     struct eata_ccb *cp;
 329     struct scatterlist *sl;
 330 
 331     save_flags(flags);
 332     cli();
 333 
 334     queue_counter++;
 335     
 336     if (done == (void *)eata_scsi_done) { 
 337         if (internal_command_finished == TRUE)
 338             internal_command_finished = FALSE;
 339         else 
 340             cmd->result = (DID_ERROR << 16) + QUEUE_FULL;
 341     }
 342     
 343     hd = HD(cmd);
 344     sh = cmd->host;
 345     
 346     /* check for free slot */
 347     for (y = hd->last_ccb + 1, x = 0; x < sh->can_queue; x++, y++) { 
 348         if (y >= sh->can_queue)
 349             y = 0;
 350         if (hd->ccb[y].status == FREE)
 351             break;
 352     }
 353     
 354     hd->last_ccb = y;
 355     
 356     if (x == sh->can_queue) { 
 357         
 358         DBG(DBG_QUEUE, printk("can_queue %d, x %d, y %d\n", 
 359                               sh->can_queue, x, y));
 360 #if DEBUG_EATA
 361         panic("eata_dma: run out of queue slots cmdno:%ld intrno: %ld\n", 
 362               queue_counter, int_counter);
 363 #else
 364         panic("eata_dma: run out of queue slots....\n");
 365 #endif
 366     }
 367     
 368     cp = &hd->ccb[y];
 369     
 370     memset(cp, 0, sizeof(struct eata_ccb) - sizeof(struct eata_sg_list *));
 371     
 372     cp->status = USED;      /* claim free slot */
 373     
 374     DBG(DBG_QUEUE, printk("eata_queue pid %ld, target: %x, lun: %x, y %d\n",
 375                           cmd->pid, cmd->target, cmd->lun, y));
 376     DBG(DBG_QUEUE && DBG_DELAY, DEL2(250));
 377     cmd->scsi_done = (void *)done;
 378     
 379     switch (cmd->cmnd[0]) {
 380     case CHANGE_DEFINITION: case COMPARE:         case COPY:
 381     case COPY_VERIFY:       case LOG_SELECT:      case MODE_SELECT:
 382     case MODE_SELECT_10:    case SEND_DIAGNOSTIC: case WRITE_BUFFER:
 383     case FORMAT_UNIT:       case REASSIGN_BLOCKS: case RESERVE:
 384     case SEARCH_EQUAL:      case SEARCH_HIGH:     case SEARCH_LOW:
 385     case WRITE_6:           case WRITE_10:        case WRITE_VERIFY:
 386     case UPDATE_BLOCK:      case WRITE_LONG:      case WRITE_SAME:      
 387     case SEARCH_HIGH_12:    case SEARCH_EQUAL_12: case SEARCH_LOW_12:
 388     case WRITE_12:          case WRITE_VERIFY_12: case SET_WINDOW: 
 389     case MEDIUM_SCAN:       case SEND_VOLUME_TAG:            
 390     case 0xea:      /* alternate number for WRITE LONG */
 391         cp->DataOut = TRUE;     /* Output mode */
 392         break;
 393     case TEST_UNIT_READY:
 394     default:
 395         cp->DataIn = TRUE;      /* Input mode  */
 396     }
 397     
 398     if ((done == (void *) eata_scsi_done && HBA_interpret == TRUE) 
 399         || cmd->target == sh->this_id) 
 400         cp->Interpret = TRUE;   /* Interpret command */
 401     
 402     if (cmd->use_sg) {
 403         cp->scatter = TRUE;     /* SG mode     */
 404         if (cp->sg_list == NULL) {
 405             cp->sg_list = kmalloc(SG_SIZE_BIG*sizeof(struct eata_sg_list),
 406                                      GFP_ATOMIC | GFP_DMA);
 407         }
 408         cp->cp_dataDMA = htonl((ulong)cp->sg_list); 
 409         if (cp->cp_dataDMA == 0)
 410             panic("eata_dma: Run out of DMA memory for SG lists !\n");
 411 
 412         cp->cp_datalen = htonl(cmd->use_sg * sizeof(struct eata_sg_list));
 413         sl=(struct scatterlist *)cmd->request_buffer;
 414         for(i = 0; i < cmd->use_sg; i++, sl++){
 415             cp->sg_list[i].data = htonl((u32) sl->address);
 416             cp->sg_list[i].len = htonl((u32) sl->length);
 417         }
 418     } else {
 419         cp->scatter = FALSE;
 420         cp->cp_datalen = htonl(cmd->request_bufflen);
 421         cp->cp_dataDMA = htonl((u32)cmd->request_buffer);
 422     }
 423     
 424     cp->Auto_Req_Sen = TRUE;
 425     cp->cp_reqDMA = htonl((u32) cmd->sense_buffer);
 426     cp->reqlen = sizeof(cmd->sense_buffer);
 427     
 428     cp->cp_id = cmd->target;
 429     cp->cp_channel = cmd->channel;
 430     cp->cp_lun = cmd->lun;
 431     cp->cp_dispri = TRUE;
 432     cp->cp_identify = TRUE;
 433     memcpy(cp->cp_cdb, cmd->cmnd, cmd->cmd_len);
 434     
 435     cp->cp_statDMA = htonl((u32) &(hd->sp));
 436     
 437     cp->cp_viraddr = cp;
 438     cp->cmd = cmd;
 439     cmd->host_scribble = (char *)&hd->ccb[y];   
 440     
 441     if(eata_send_command((u32) cp, (u32) sh->base, EATA_CMD_DMA_SEND_CP) == FALSE) {
 442         cmd->result = DID_ERROR << 16;
 443         printk("eata_queue target %d, pid %ld, HBA busy, returning DID_ERROR,"
 444                " done.\n", cmd->target, cmd->pid);
 445         restore_flags(flags);
 446         if(done != (void *)eata_scsi_done) done(cmd);
 447         return (0);
 448     }
 449     DBG(DBG_QUEUE,printk("Queued base %#.4x pid: %ld target: %x lun: %x "
 450                          "slot %d irq %d\n", (s32)sh->base, cmd->pid, 
 451                          cmd->target, cmd->lun, y, sh->irq));
 452     DBG(DBG_QUEUE && DBG_DELAY, DEL2(200));
 453     restore_flags(flags);
 454     return (0);
 455 }
 456 
 457 
 458 int eata_abort(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 459 {
 460     ulong flags;
 461     ulong loop = R_LIMIT;
 462 
 463     save_flags(flags);
 464     cli();
 465 
 466     DBG(DBG_ABNORM, printk("eata_abort called pid: %ld target: %x lun: %x"
 467                            " reason %x\n", cmd->pid, cmd->target, cmd->lun, 
 468                            cmd->abort_reason));
 469     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 470     
 471     
 472     while (inb((u32)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
 473         if (--loop == 0) {
 474             printk("eata_dma: abort, timeout error.\n");
 475             restore_flags(flags);
 476             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 477             return (SCSI_ABORT_ERROR);
 478         }
 479     if (CD(cmd)->status == USED) {
 480         DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_BUSY\n"));
 481         restore_flags(flags);
 482         return (SCSI_ABORT_BUSY);  /* SNOOZE */ 
 483     }
 484     if (CD(cmd)->status == FREE) {
 485         DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_NOT_RUNNING\n")); 
 486         restore_flags(flags);
 487         return (SCSI_ABORT_NOT_RUNNING);
 488     }
 489     if (CD(cmd)->status == RESET) {
 490         restore_flags(flags);
 491         printk("eata_dma: abort, command reset error.\n");
 492         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 493         return (SCSI_ABORT_ERROR);
 494     }
 495     if (CD(cmd)->status == LOCKED) {
 496         restore_flags(flags);
 497         DBG(DBG_ABNORM, printk("eata_dma: abort, queue slot locked.\n"));
 498         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 499         return (SCSI_ABORT_NOT_RUNNING);
 500     } else
 501         panic("eata_dma: abort: invalid slot status\n");
 502 }
 503 
 504 int eata_reset(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 505 {
 506     ushort x, z; 
 507     ulong time, limit = 0;
 508     ulong loop = R_LIMIT;
 509     ulong flags;
 510     unchar success = FALSE;
 511     Scsi_Cmnd *sp; 
 512     
 513     save_flags(flags);
 514     cli();
 515     
 516     DBG(DBG_ABNORM, printk("eata_reset called pid:%ld target: %x lun: %x"
 517                            " reason %x\n", cmd->pid, cmd->target, cmd->lun, 
 518                            cmd->abort_reason));
 519         
 520     if (HD(cmd)->state == RESET) {
 521         printk("eata_reset: exit, already in reset.\n");
 522         restore_flags(flags);
 523         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 524         return (SCSI_RESET_ERROR);
 525     }
 526     
 527     while (inb((u32)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
 528         if (--loop == 0) {
 529             printk("eata_reset: exit, timeout error.\n");
 530             restore_flags(flags);
 531             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 532             return (SCSI_RESET_ERROR);
 533         }
 534  
 535     for (x = 0; x < MAXCHANNEL; x++) {
 536         for (z = 0; z < MAXTARGET; z++) {
 537             HD(cmd)->t_state[x][z] = RESET;
 538             HD(cmd)->t_timeout[x][z] = NO_TIMEOUT;
 539         }
 540     }
 541 
 542     for (x = 0; x < cmd->host->can_queue; x++) {
 543         if (HD(cmd)->ccb[x].status == FREE)
 544             continue;
 545         
 546         if (HD(cmd)->ccb[x].status == LOCKED) {
 547             HD(cmd)->ccb[x].status = FREE;
 548             printk("eata_reset: locked slot %d forced free.\n", x);
 549             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 550             continue;
 551         }
 552         sp = HD(cmd)->ccb[x].cmd;
 553         HD(cmd)->ccb[x].status = RESET;
 554         printk("eata_reset: slot %d in reset, pid %ld.\n", x, sp->pid);
 555         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 556         
 557         if (sp == NULL)
 558             panic("eata_reset: slot %d, sp==NULL.\n", x);
 559         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 560         
 561         if (sp == cmd)
 562             success = TRUE;
 563     }
 564     
 565     /* hard reset the HBA  */
 566     inb((u32) (cmd->host->base) + HA_RSTATUS);  /* This might cause trouble */
 567     eata_send_command(0, (u32) cmd->host->base, EATA_CMD_RESET);
 568     
 569     DBG(DBG_ABNORM, printk("eata_reset: board reset done, enabling interrupts.\n"));
 570     HD(cmd)->state = RESET;
 571     
 572     restore_flags(flags);
 573     
 574     time = jiffies;
 575     while (jiffies < (time + 300) && limit++ < 10000000)
 576         /* nothing */;
 577     
 578     save_flags(flags);
 579     cli();
 580     
 581     DBG(DBG_ABNORM, printk("eata_reset: interrupts disabled, loops %ld.\n", 
 582                            limit));
 583     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 584     
 585     for (x = 0; x < cmd->host->can_queue; x++) {
 586         
 587         /* Skip slots already set free by interrupt */
 588         if (HD(cmd)->ccb[x].status != RESET)
 589             continue;
 590         
 591         sp = HD(cmd)->ccb[x].cmd;
 592         sp->result = DID_RESET << 16;
 593         
 594         /* This mailbox is still waiting for its interrupt */
 595         HD(cmd)->ccb[x].status = LOCKED;
 596         
 597         printk("eata_reset: slot %d locked, DID_RESET, pid %ld done.\n",
 598                x, sp->pid);
 599         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 600         restore_flags(flags);
 601         sp->scsi_done(sp);
 602         cli();
 603     }
 604     
 605     HD(cmd)->state = FALSE;
 606     restore_flags(flags);
 607     
 608     if (success) {
 609         DBG(DBG_ABNORM, printk("eata_reset: exit, success.\n"));
 610         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 611         return (SCSI_RESET_SUCCESS);
 612     } else {
 613         DBG(DBG_ABNORM, printk("eata_reset: exit, wakeup.\n"));
 614         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 615         return (SCSI_RESET_PUNT);
 616     }
 617 }
 618 
 619 char * get_board_data(u32 base, u32 irq, u32 id)
     /* [previous][next][first][last][top][bottom][index][help] */
 620 {
 621     struct eata_ccb *cp;
 622     struct eata_sp  *sp;
 623     static char *buff;
 624     ulong i;
 625     ulong limit = 0;
 626 
 627     cp = (struct eata_ccb *) scsi_init_malloc(sizeof(struct eata_ccb),
 628                                               GFP_ATOMIC | GFP_DMA);
 629     sp = (struct eata_sp *) scsi_init_malloc(sizeof(struct eata_sp), 
 630                                              GFP_ATOMIC | GFP_DMA);
 631 
 632     buff = dma_scratch;
 633  
 634     memset(cp, 0, sizeof(struct eata_ccb));
 635     memset(sp, 0, sizeof(struct eata_sp));
 636     memset(buff, 0, 256);
 637 
 638     cp->DataIn = TRUE;     
 639     cp->Interpret = TRUE;   /* Interpret command */
 640  
 641     cp->cp_datalen = htonl(255);  
 642     cp->cp_dataDMA = htonl((s32)buff);
 643     cp->cp_viraddr = cp;
 644     
 645     cp->cp_id = id;
 646     cp->cp_lun = 0;
 647 
 648     cp->cp_cdb[0] = INQUIRY;
 649     cp->cp_cdb[1] = 0;
 650     cp->cp_cdb[2] = 0;
 651     cp->cp_cdb[3] = 0;
 652     cp->cp_cdb[4] = 255;
 653     cp->cp_cdb[5] = 0;
 654 
 655     cp->cp_statDMA = htonl((ulong) sp);
 656 
 657     fake_int_base = base;
 658     fake_int_result = 0;
 659 
 660     eata_send_command((u32) cp, (u32) base, EATA_CMD_DMA_SEND_CP);
 661     
 662     i = jiffies + 300;
 663     while (fake_int_result == FALSE && jiffies <= i) 
 664         barrier();
 665     
 666     DBG(DBG_INTR3, printk("fake_int_result: %#x hbastat %#x scsistat %#x,"
 667                           " buff %p sp %p\n",
 668                           fake_int_result, (u32) (sp->hba_stat & 0x7f), 
 669                           (u32) sp->scsi_stat, buff, sp));
 670 
 671     scsi_init_free((void *)cp, sizeof(struct eata_ccb));
 672     scsi_init_free((void *)sp, sizeof(struct eata_sp));
 673     
 674     if ((fake_int_result & HA_SERROR) || jiffies > i){
 675         /* hard reset the HBA  */
 676         inb((u32) (base) + HA_RSTATUS);
 677         eata_send_command(0, base, EATA_CMD_RESET);
 678         i = jiffies;
 679         while (jiffies < (i + 300) && limit++ < 10000000)
 680             barrier();
 681         return (NULL);
 682     } else
 683         return (buff);
 684 }
 685     
 686 int check_blink_state(long base)
     /* [previous][next][first][last][top][bottom][index][help] */
 687 {
 688     ushort loops = 10;
 689     u32 blinkindicator;
 690     u32 state = 0x12345678;
 691     u32 oldstate = 0;
 692 
 693     blinkindicator = htonl(0x54504442);
 694     while ((loops--) && (state != oldstate)) {
 695         oldstate = state;
 696         state = inl((uint) base + 1);
 697     }
 698 
 699     DBG(DBG_BLINK, printk("Did Blink check. Status: %d\n",
 700               (state == oldstate) && (state == blinkindicator)));
 701 
 702     if ((state == oldstate) && (state == blinkindicator))
 703         return(TRUE);
 704     else
 705         return (FALSE);
 706 }
 707 
 708 int get_conf_PIO(u32 base, struct get_conf *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 709 {
 710     ulong loop = R_LIMIT;
 711     u16 *p;
 712 
 713     if(check_region(base, 9)) 
 714         return (FALSE);
 715      
 716     memset(buf, 0, sizeof(struct get_conf));
 717 
 718     while (inb(base + HA_RSTATUS) & HA_SBUSY)
 719         if (--loop == 0) 
 720             return (FALSE);
 721        
 722     DBG(DBG_PIO && DBG_PROBE,
 723         printk("Issuing PIO READ CONFIG to HBA at %#x\n", base));
 724     eata_send_command(0, base, EATA_CMD_PIO_READ_CONFIG);
 725 
 726     loop = R_LIMIT;
 727     for (p = (u16 *) buf; 
 728          (long)p <= ((long)buf + (sizeof(struct get_conf) / 2)); p++) {
 729         while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
 730             if (--loop == 0)
 731                 return (FALSE);
 732 
 733         loop = R_LIMIT;
 734         *p = inw(base + HA_RDATA);
 735     }
 736 
 737     if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {            /* Error ? */
 738         if (htonl(EATA_SIGNATURE) == buf->signature) {
 739             DBG(DBG_PIO&&DBG_PROBE, printk("EATA Controller found at %x "
 740                                            "EATA Level: %x\n", (uint) base, 
 741                                            (uint) (buf->version)));
 742             
 743             while (inb(base + HA_RSTATUS) & HA_SDRQ) 
 744                 inw(base + HA_RDATA);
 745             return (TRUE);
 746         } 
 747     } else {
 748         DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during transfer "
 749                   "for HBA at %lx\n", (long)base));
 750     }
 751     return (FALSE);
 752 }
 753 
 754 void print_config(struct get_conf *gc)
     /* [previous][next][first][last][top][bottom][index][help] */
 755 {
 756     printk("Please check values: (read config data)\n");
 757     printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d DMAS:%d\n",
 758            (u32) ntohl(gc->len), gc->version,
 759            gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support,
 760            gc->DMA_support);
 761     printk("DMAV:%d HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
 762            gc->DMA_valid, gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2],
 763            gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
 764     printk("IRQ:%d IRQT:%d DMAC:%d FORCADR:%d SG_64K:%d SG_UAE:%d MID:%d "
 765            "MCH:%d MLUN:%d\n",
 766            gc->IRQ, gc->IRQ_TR, (8 - gc->DMA_channel) & 7, gc->FORCADR, 
 767            gc->SG_64K, gc->SG_UAE, gc->MAX_ID, gc->MAX_CHAN, gc->MAX_LUN); 
 768     printk("RIDQ:%d PCI:%d EISA:%d\n",
 769            gc->ID_qest, gc->is_PCI, gc->is_EISA);
 770     DBG(DPT_DEBUG, DELAY(1400));
 771 }
 772 
 773 short register_HBA(u32 base, struct get_conf *gc, Scsi_Host_Template * tpnt, 
     /* [previous][next][first][last][top][bottom][index][help] */
 774                    u8 bustype)
 775 {
 776     ulong size = 0;
 777     unchar dma_channel = 0;
 778     char *buff = 0;
 779     unchar bugs = 0;
 780     struct Scsi_Host *sh;
 781     hostdata *hd;
 782     
 783     
 784     DBG(DBG_REGISTER, print_config(gc));
 785 
 786     if (gc->DMA_support == FALSE) {
 787         printk("The EATA HBA at %#.4x does not support DMA.\n" 
 788                "Please use the EATA-PIO driver.\n", base);
 789         return (FALSE);
 790     }
 791 
 792     if(gc->HAA_valid == FALSE || ntohl(gc->len) < 0x22) 
 793         gc->MAX_CHAN = 0;
 794     
 795     if (reg_IRQ[gc->IRQ] == FALSE) {    /* Interrupt already registered ? */
 796         if (!request_irq(gc->IRQ, (void *) eata_fake_int_handler, SA_INTERRUPT,
 797                          "eata_dma")){
 798             reg_IRQ[gc->IRQ]++;
 799             if (!gc->IRQ_TR)
 800                 reg_IRQL[gc->IRQ] = TRUE;   /* IRQ is edge triggered */
 801         } else {
 802             printk("Couldn't allocate IRQ %d, Sorry.", gc->IRQ);
 803             return (FALSE);
 804         }
 805     } else {            /* More than one HBA on this IRQ */
 806         if (reg_IRQL[gc->IRQ] == TRUE) {
 807             printk("Can't support more than one HBA on this IRQ,\n"
 808                    "  if the IRQ is edge triggered. Sorry.\n");
 809             return (FALSE);
 810         } else
 811             reg_IRQ[gc->IRQ]++;
 812     }
 813     
 814     /* if gc->DMA_valid it must be an ISA HBA and we have to register it */
 815     dma_channel = 0xff;
 816     if (gc->DMA_valid) {
 817         if (request_dma(dma_channel = (8 - gc->DMA_channel) & 7, "eata_dma")) {
 818             printk("Unable to allocate DMA channel %d for ISA HBA at %#.4x.\n",
 819                    dma_channel, base);
 820             reg_IRQ[gc->IRQ]--;
 821             if (reg_IRQ[gc->IRQ] == 0)
 822                 free_irq(gc->IRQ);
 823             if (gc->IRQ_TR == FALSE)
 824                 reg_IRQL[gc->IRQ] = FALSE; 
 825             return (FALSE);
 826         }
 827     }
 828  
 829     if (bustype != IS_EISA)
 830         buff = get_board_data(base, gc->IRQ, gc->scsi_id[3]);
 831 
 832     if (buff == NULL) {
 833         if (bustype == IS_EISA) {
 834             bugs = bugs || BROKEN_INQUIRY;
 835         } else {
 836             if (gc->DMA_support == FALSE)
 837                 printk("HBA at %#.4x doesn't support DMA. Sorry\n", base);
 838             else
 839                 printk("HBA at %#.4x does not react on INQUIRY. Sorry.\n", 
 840                        base);
 841             if (gc->DMA_valid) 
 842                 free_dma(dma_channel);
 843             reg_IRQ[gc->IRQ]--;
 844             if (reg_IRQ[gc->IRQ] == 0)
 845                 free_irq(gc->IRQ);
 846             if (gc->IRQ_TR == FALSE)
 847                 reg_IRQL[gc->IRQ] = FALSE; 
 848             return (FALSE);
 849         }
 850     }
 851     
 852     if (gc->DMA_support == FALSE && buff != NULL)  
 853         printk("HBA %.12sat %#.4x doesn't set the DMA_support flag correctly.\n",
 854                &buff[16], base);
 855     
 856     request_region(base, 9, "eata_dma"); /* We already checked the 
 857                                           * availability, so this
 858                                           * should not fail.
 859                                           */
 860     
 861     if(ntohs(gc->queuesiz) == 0) {
 862         gc->queuesiz = ntohs(64);
 863         printk("Warning: Queue size has to be corrected. Assuming 64 queueslots\n"
 864                "         This might be a PM2012B with a defective Firmware\n");
 865     }
 866 
 867     size = sizeof(hostdata) + ((sizeof(struct eata_ccb) + sizeof(long)) 
 868                                * ntohs(gc->queuesiz));
 869 
 870     DBG(DBG_REGISTER, printk("scsi_register size: %ld\n", size));
 871     
 872     sh = scsi_register(tpnt, size);
 873     
 874     if(sh == NULL) {
 875         if (gc->DMA_valid) 
 876             free_dma(dma_channel);
 877         
 878         reg_IRQ[gc->IRQ]--;
 879         if (reg_IRQ[gc->IRQ] == 0)
 880             free_irq(gc->IRQ);
 881         if (gc->IRQ_TR == FALSE)
 882             reg_IRQL[gc->IRQ] = FALSE; 
 883         return (FALSE);
 884     }
 885     
 886     hd = SD(sh);                   
 887     
 888     memset(hd->ccb, 0, sizeof(struct eata_ccb) * ntohs(gc->queuesiz));
 889     memset(hd->reads, 0, sizeof(u32) * 26); 
 890 
 891     hd->broken_INQUIRY = (bugs & BROKEN_INQUIRY);
 892 
 893     if(hd->broken_INQUIRY == TRUE) {
 894         strcpy(SD(sh)->vendor, "DPT");
 895         strcpy(SD(sh)->name, "??????????");
 896         strcpy(SD(sh)->revision, "???.?");
 897     } else {    
 898         strncpy(SD(sh)->vendor, &buff[8], 8);
 899         SD(sh)->vendor[8] = 0;
 900         strncpy(SD(sh)->name, &buff[16], 17);
 901         SD(sh)->name[17] = 0;
 902         SD(sh)->revision[0] = buff[32];
 903         SD(sh)->revision[1] = buff[33];
 904         SD(sh)->revision[2] = buff[34];
 905         SD(sh)->revision[3] = '.';
 906         SD(sh)->revision[4] = buff[35];
 907         SD(sh)->revision[5] = 0;
 908     }
 909 
 910     switch (ntohl(gc->len)) {
 911     case 0x1c:
 912         SD(sh)->EATA_revision = 'a';
 913         break;
 914     case 0x1e:
 915         SD(sh)->EATA_revision = 'b';
 916         break;
 917     case 0x22:
 918         SD(sh)->EATA_revision = 'c';
 919         break;
 920     case 0x24:
 921         SD(sh)->EATA_revision = 'z';            
 922     default:
 923         SD(sh)->EATA_revision = '?';
 924     }
 925 
 926     if(ntohl(gc->len) >= 0x22) {
 927         if (gc->is_PCI == TRUE)
 928             hd->bustype = IS_PCI;
 929         else if (gc->is_EISA == TRUE)
 930             hd->bustype = IS_EISA;
 931         else
 932             hd->bustype = IS_ISA;
 933     } else if(hd->broken_INQUIRY == FALSE) {
 934         if (buff[21] == '4')
 935             hd->bustype = IS_PCI;
 936         else if (buff[21] == '2')
 937             hd->bustype = IS_EISA;
 938         else
 939             hd->bustype = IS_ISA;
 940     } else 
 941         hd->bustype = bustype;
 942     
 943     if(ntohl(gc->len) >= 0x22) {
 944         sh->max_id = gc->MAX_ID;
 945         sh->max_lun = gc->MAX_LUN;
 946     } else {
 947         sh->max_id = 8;
 948         sh->max_lun = 8;
 949     }
 950 
 951     hd->channel = gc->MAX_CHAN;     
 952     sh->max_channel = gc->MAX_CHAN; 
 953     sh->base = (char *) base;
 954     sh->io_port = (u16) base;
 955     sh->n_io_port = 9;
 956     sh->irq = gc->IRQ;
 957     sh->dma_channel = dma_channel;
 958     
 959     /* FIXME:
 960      * SCSI midlevel code should support different HBA ids on every channel
 961      */
 962     sh->this_id = gc->scsi_id[3];
 963     sh->can_queue = ntohs(gc->queuesiz);
 964     
 965     if (gc->OCS_enabled == TRUE) 
 966         if(hd->bustype != IS_ISA)
 967             sh->cmd_per_lun = sh->can_queue/C_P_L_DIV; 
 968         else
 969             sh->cmd_per_lun = 8;
 970     else 
 971         sh->cmd_per_lun = 1;
 972     
 973     /* FIXME:
 974      * SG should be allocated more dynamically 
 975      */
 976     /*
 977      * If we are using a ISA board, we can't use extended SG,
 978      * because we would need exessive amounts of memory for
 979      * bounce buffers.
 980      */
 981     if (gc->SG_64K == TRUE && ntohs(gc->SGsiz) == 64 && hd->bustype != IS_ISA){
 982         sh->sg_tablesize = SG_SIZE_BIG;
 983         sh->use_clustering = FALSE;
 984     } else {
 985         sh->sg_tablesize = ntohs(gc->SGsiz);
 986         sh->use_clustering = TRUE;
 987         if (sh->sg_tablesize > SG_SIZE || sh->sg_tablesize == 0) {
 988             sh->sg_tablesize = SG_SIZE;
 989             if (ntohs(gc->SGsiz) == 0)
 990                 printk("Warning: SG size had to be corrected.\n"
 991                        "This might be a PM2012 with a defective Firmware\n");
 992         }
 993     }
 994     
 995     if (gc->SECOND)
 996         hd->primary = FALSE;
 997     else
 998         hd->primary = TRUE;
 999     
1000     sh->wish_block = FALSE;        
1001     
1002     if (hd->bustype != IS_ISA) {
1003         sh->unchecked_isa_dma = FALSE;
1004     } else {
1005         sh->unchecked_isa_dma = TRUE;   /* We're doing ISA DMA */
1006     }
1007     
1008     hd->next = NULL;    /* build a linked list of all HBAs */
1009     hd->prev = last_HBA;
1010     if(hd->prev != NULL)
1011         SD(hd->prev)->next = sh;
1012     last_HBA = sh;
1013     if (first_HBA == NULL)
1014         first_HBA = sh;
1015     registered_HBAs++;
1016     
1017     return (TRUE);
1018 }
1019 
1020 
1021 void find_EISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1022 {
1023     u32 base;
1024     int i;
1025     
1026 #if CHECKPAL
1027     u8 pal1, pal2, pal3;
1028 #endif
1029     
1030     for (i = 0; i < MAXEISA; i++) {
1031         if (EISAbases[i] == TRUE) { /* Still a possibility ?          */
1032             
1033             base = 0x1c88 + (i * 0x1000);
1034 #if CHECKPAL
1035             pal1 = inb((u16)base - 8);
1036             pal2 = inb((u16)base - 7);
1037             pal3 = inb((u16)base - 6);
1038             
1039             if (((pal1 == 0x12) && (pal2 == 0x14)) ||
1040                 ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) ||
1041                 ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
1042                 DBG(DBG_PROBE, printk("EISA EATA id tags found: %x %x %x \n",
1043                                       (int)pal1, (int)pal2, (int)pal3));
1044 #endif
1045                 if (get_conf_PIO(base, buf) == TRUE) {
1046                     DBG(DBG_PROBE && DBG_EISA, print_config(buf));
1047                     if (buf->IRQ) {  
1048                         register_HBA(base, buf, tpnt, IS_EISA);
1049                     } else
1050                         printk("eata_dma: No valid IRQ. HBA removed from list\n");
1051                 } else {
1052                     if (check_blink_state(base)) 
1053                         printk("HBA is in BLINK state. Consult your HBAs "
1054                                " Manual to correct this.\n");
1055                 } 
1056                 /* Nothing found here so we take it from the list */
1057                 EISAbases[i] = 0;  
1058 #if CHECKPAL
1059             } 
1060 #endif
1061         }
1062     }
1063     return; 
1064 }
1065 
1066 void find_ISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1067 {
1068     int i;
1069     
1070     for (i = 0; i < MAXISA; i++) {  
1071         if (ISAbases[i]) {  
1072             if (get_conf_PIO(ISAbases[i],buf) == TRUE){
1073                 register_HBA(ISAbases[i], buf, tpnt, IS_ISA);
1074             } else {
1075                 if (check_blink_state(ISAbases[i])) 
1076                     printk("HBA is in BLINK state. Consult your HBAs "
1077                            "Manual to correct this.\n");
1078             }
1079             ISAbases[i] = 0;
1080         }
1081     }
1082     return;
1083 }
1084 
1085 void find_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1086 {
1087 
1088 #ifndef CONFIG_PCI
1089     printk("eata_dma: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
1090 #else
1091     
1092     u8 pci_bus, pci_device_fn;
1093     static s16 pci_index = 0;   /* Device index to PCI BIOS calls */
1094     u32 base = 0;
1095     u16 com_adr;
1096     u16 rev_device;
1097     u32 error, i, x;
1098 
1099     if (pcibios_present()) {
1100         for (i = 0; i <= MAXPCI; ++i, ++pci_index) {
1101             if (pcibios_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, 
1102                                     pci_index, &pci_bus, &pci_device_fn))
1103                 break;
1104             DBG(DBG_PROBE && DBG_PCI, 
1105                 printk("eata_dma: HBA at bus %d, device %d,"
1106                        " function %d, index %d\n", (s32)pci_bus, 
1107                        (s32)((pci_device_fn & 0xf8) >> 3),
1108                        (s32)(pci_device_fn & 7), pci_index));
1109             
1110             if (!(error = pcibios_read_config_word(pci_bus, pci_device_fn, 
1111                                        PCI_CLASS_DEVICE, &rev_device))) {
1112                 if (rev_device == PCI_CLASS_STORAGE_SCSI) {
1113                     if (!(error = pcibios_read_config_word(pci_bus, 
1114                                                pci_device_fn, PCI_COMMAND, 
1115                                                (u16 *) & com_adr))) {
1116                         if (!((com_adr & PCI_COMMAND_IO) && 
1117                               (com_adr & PCI_COMMAND_MASTER))) {
1118                             printk("HBA has IO or BUSMASTER mode disabled\n");
1119                             continue;
1120                         }
1121                     } else
1122                         printk("eata_dma: error %x while reading "
1123                                "PCI_COMMAND\n", error);
1124                 } else
1125                     printk("DEVICECLASSID %x didn't match\n", rev_device);
1126             } else {
1127                 printk("eata_dma: error %x while reading PCI_CLASS_BASE\n", 
1128                        error);
1129                 continue;
1130             }
1131             
1132             if (!(error = pcibios_read_config_dword(pci_bus, pci_device_fn,
1133                                        PCI_BASE_ADDRESS_0, (int *) &base))){
1134                 
1135                 /* Check if the address is valid */
1136                 if (base & 0x01) {
1137                     base &= 0xfffffffe;
1138                     /* EISA tag there ? */
1139                     if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
1140                         continue;   /* Jep, it's forced, so move on  */
1141                     base += 0x10;   /* Now, THIS is the real address */
1142                     if (base != 0x1f8) {
1143                         /* We didn't find it in the primary search */
1144                         if (get_conf_PIO(base, buf) == TRUE) {
1145                             if (buf->FORCADR)   /* If the address is forced */
1146                                 continue;       /* we'll find it later      */
1147                             
1148                             /* OK. We made it till here, so we can go now  
1149                              * and register it. We  only have to check and 
1150                              * eventually remove it from the EISA and ISA list 
1151                              */
1152                             
1153                             register_HBA(base, buf, tpnt, IS_PCI);
1154                             
1155                             if (base < 0x1000) {
1156                                 for (x = 0; x < MAXISA; ++x) {
1157                                     if (ISAbases[x] == base) {
1158                                         ISAbases[x] = 0;
1159                                         break;
1160                                     }
1161                                 }
1162                             } else if ((base & 0x0fff) == 0x0c88) {
1163                                 x = (base >> 12) & 0x0f;
1164                                 EISAbases[x] = 0;
1165                             }
1166                             continue;  /* break; */
1167                         } else if (check_blink_state(base) == TRUE) {
1168                             printk("eata_dma: HBA is in BLINK state.\n"
1169                                    "Consult your HBAs Manual to correct this.\n");
1170                         }
1171                     }
1172                 }
1173             } else
1174                 printk("eata_dma: error %x while reading "
1175                        "PCI_BASE_ADDRESS_0\n", error);
1176         }
1177     } else
1178         printk("eata_dma: No BIOS32 extensions present. This driver release "
1179                "still depends on it.\n"
1180                "          Skipping scan for PCI HBAs. \n");
1181 #endif /* #ifndef CONFIG_PCI */
1182     return;
1183 }
1184 
1185 int eata_detect(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1186 {
1187     struct Scsi_Host *HBA_ptr;
1188     struct get_conf gc;
1189     int i;
1190     
1191     DBG((DBG_PROBE && DBG_DELAY) || DPT_DEBUG,
1192         printk("Using lots of delays to let you read the debugging output\n"));
1193 
1194     status = scsi_init_malloc(512, GFP_ATOMIC | GFP_DMA);
1195     dma_scratch = scsi_init_malloc(512, GFP_ATOMIC | GFP_DMA);
1196 
1197     find_PCI(&gc, tpnt);
1198     
1199     find_EISA(&gc, tpnt);
1200     
1201     find_ISA(&gc, tpnt);
1202     
1203     for (i = 0; i <= MAXIRQ; i++)
1204         if (reg_IRQ[i]){
1205             free_irq(i);
1206             request_irq(i, (void *)(eata_int_handler), SA_INTERRUPT, "eata_dma");
1207         }
1208     
1209     HBA_ptr = first_HBA;
1210     
1211     if (registered_HBAs != 0) {
1212         printk("EATA (Extended Attachment) driver version: %d.%d%s\n"
1213                "developed in co-operation with DPT\n"             
1214                "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n",
1215                VER_MAJOR, VER_MINOR, VER_SUB);
1216         printk("Registered HBAs:");
1217         printk("\nHBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: DMA: Ch: "
1218                "ID: Pr: QS: SG: CPL:\n");
1219         for (i = 1; i <= registered_HBAs; i++) {
1220             printk("scsi%-2d: %.10s v%s 2.0%c  %s %#.4x   %2d",
1221                    HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
1222                    SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P')? 
1223                    "PCI ":(SD(HBA_ptr)->bustype == 'E')?"EISA":"ISA ",
1224                    (u32) HBA_ptr->base, HBA_ptr->irq);
1225             if(HBA_ptr->dma_channel != 0xff)
1226                 printk("   %2x ", HBA_ptr->dma_channel);
1227             else
1228                 printk("  %s", "BMST");
1229             printk("  %d   %d   %c  %2d  %2d   %2d\n", SD(HBA_ptr)->channel, 
1230                    HBA_ptr->this_id, (SD(HBA_ptr)->primary == TRUE)?'Y':'N', 
1231                    HBA_ptr->can_queue, HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
1232             HBA_ptr = SD(HBA_ptr)->next;
1233         }
1234     } else {
1235         scsi_init_free((void *)status, 512);
1236     }
1237 
1238     scsi_init_free((void *)dma_scratch, 512);
1239 
1240     DBG(DPT_DEBUG, DELAY(1200));
1241 
1242     return(registered_HBAs);
1243 }
1244 
1245 #ifdef MODULE
1246 /* Eventually this will go into an include file, but this will be later */
1247 Scsi_Host_Template driver_template = EATA_DMA;
1248 #include "scsi_module.c"
1249 #endif
1250 
1251 /*
1252  * Overrides for Emacs so that we almost follow Linus's tabbing style.
1253  * Emacs will notice this stuff at the end of the file and automatically
1254  * adjust the settings for this buffer only.  This must remain at the end
1255  * of the file.
1256  * ---------------------------------------------------------------------------
1257  * Local variables:
1258  * c-indent-level: 4
1259  * c-brace-imaginary-offset: 0
1260  * c-brace-offset: -4
1261  * c-argdecl-indent: 4
1262  * c-label-offset: -4
1263  * c-continued-statement-offset: 4
1264  * c-continued-brace-offset: 0
1265  * indent-tabs-mode: nil
1266  * tab-width: 8
1267  * End:
1268  */

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