root/drivers/scsi/eata_dma.c

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

DEFINITIONS

This source file includes following definitions.
  1. eata_info
  2. eata_int_handler
  3. eata_send_command
  4. eata_queue
  5. internal_done
  6. eata_command
  7. eata_abort
  8. eata_reset
  9. get_board_data
  10. check_blink_state
  11. get_conf_PIO
  12. print_config
  13. register_HBA
  14. find_EISA
  15. find_ISA
  16. find_PCI
  17. 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  *                                                          *
  16  *  (c)1993,94,95 Michael Neuffer                           *
  17  *                neuffer@goofy.zdv.uni-mainz.de            *
  18  *                                                          *
  19  *  This program is free software; you can redistribute it  *
  20  *  and/or modify it under the terms of the GNU General     *
  21  *  Public License as published by the Free Software        *
  22  *  Foundation; either version 2 of the License, or         *
  23  *  (at your option) any later version.                     *
  24  *                                                          *
  25  *  This program is distributed in the hope that it will be *
  26  *  useful, but WITHOUT ANY WARRANTY; without even the      *
  27  *  implied warranty of MERCHANTABILITY or FITNESS FOR A    *
  28  *  PARTICULAR PURPOSE.  See the GNU General Public License *
  29  *  for more details.                                       *
  30  *                                                          *
  31  *  You should have received a copy of the GNU General      *
  32  *  Public License along with this kernel; if not, write to *
  33  *  the Free Software Foundation, Inc., 675 Mass Ave,       *
  34  *  Cambridge, MA 02139, USA.                               *
  35  *                                                          *
  36  * I have to thank DPT for their excellent support. I took  *
  37  * me almost a year and a stopover at their HQ, on my first *
  38  * trip to the USA, to get it, but since then they've been  *
  39  * very helpful and tried to give me all the infos and      *
  40  * support I need.                                          *
  41  *                                                          *
  42  *  Thanks also to Greg Hosler who did a lot of testing and *
  43  *  found quite a number of bugs during the development.   *
  44  ************************************************************
  45  *  last change: 95/01/15                                   *
  46  ************************************************************/
  47 
  48 /* Look in eata_dma.h for configuration information */
  49 
  50 #include <linux/kernel.h>
  51 #include <linux/sched.h>
  52 #include <linux/string.h>
  53 #include <linux/ioport.h>
  54 #include <linux/malloc.h>
  55 #include <linux/in.h>
  56 #include <linux/bios32.h>
  57 #include <linux/pci.h>
  58 #include <asm/io.h>
  59 #include <asm/dma.h>
  60 #include "eata_dma.h"
  61 #include "scsi.h"
  62 #include "sd.h"
  63 
  64 static uint ISAbases[] =
  65 {0x1F0, 0x170, 0x330, 0x230};
  66 static unchar EISAbases[] =
  67 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  68 static uint registered_HBAs = 0;
  69 static struct Scsi_Host *last_HBA = NULL;
  70 static unchar reg_IRQ[] =
  71 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  72 static unchar reg_IRQL[] =
  73 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  74 
  75 static struct eata_sp status[MAXIRQ];   /* Statuspacket array   */
  76 
  77 static struct geom_emul geometry;       /* Drive 1 & 2 geometry */
  78 
  79 #if DEBUG
  80 static ulong int_counter = 0;
  81 static ulong queue_counter = 0;
  82 #endif
  83 
  84 const char *eata_info(struct Scsi_Host *host)
     /* [previous][next][first][last][top][bottom][index][help] */
  85 {
  86     static char *information = "EATA SCSI HBA Driver\n";
  87     return information;
  88 }
  89 
  90 void eata_int_handler(int irq, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
  91 {
  92     uint i, result;
  93     uint hba_stat, scsi_stat, eata_stat;
  94     Scsi_Cmnd *cmd;
  95     struct eata_ccb *cp;
  96     struct eata_sp *sp;
  97     uint base;
  98     ulong flags;
  99     uint x;
 100     struct Scsi_Host *sh;
 101 
 102     save_flags(flags);
 103     cli();
 104 
 105     for (x = 1, sh = last_HBA; x <= registered_HBAs; x++, sh = SD(sh)->next) {
 106         if (sh->irq != irq)
 107             continue;
 108         if (!(inb((uint)sh->base + HA_RAUXSTAT) & HA_AIRQ))
 109             continue;
 110 
 111         DBG(DEBUG, int_counter++);
 112 
 113         sp=&SD(sh)->sp;
 114 
 115         cp = sp->ccb;
 116         cmd = cp->cmd;
 117         base = (uint) cmd->host->base;
 118 
 119         hba_stat = sp->hba_stat;
 120 
 121         scsi_stat = (sp->scsi_stat >> 1) && 0x1f; 
 122 
 123         if (sp->EOC == FALSE) {
 124             eata_stat = inb(base + HA_RSTATUS);
 125             printk("eata_dma: int_handler, board: %x cmd %lx returned "
 126                    "unfinished.\nEATA: %x HBA: %x SCSI: %x spadr %lx spadrirq "
 127                    "%lx, irq%d\n", base, (long)cp, eata_stat, hba_stat, 
 128                    scsi_stat,(long)&status, (long)&status[irq], irq);
 129             DBG(DBG_DELAY,DEL2(800));
 130             restore_flags(flags);
 131             return;
 132         } 
 133 
 134         if (cp->status == LOCKED) {
 135             cp->status = FREE;
 136             eata_stat = inb(base + HA_RSTATUS);
 137             printk("eata_dma: int_handler, freeing locked queueslot\n");
 138             DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
 139             restore_flags(flags);
 140             return;
 141         }
 142 
 143         eata_stat = inb(base + HA_RSTATUS);     
 144         DBG(DBG_INTR, printk("IRQ %d received, base 0x%04x, pid %lx, target: %x, "
 145                              "lun: %x, ea_s: 0x%02x, hba_s: 0x%02x \n", 
 146                              irq, base, cmd->pid, cmd->target, cmd->lun, 
 147                              eata_stat, hba_stat));
 148 
 149         switch (hba_stat) {
 150         case 0x00:              /* status OK */
 151             if (scsi_stat == INTERMEDIATE_GOOD && cmd->device->type != TYPE_TAPE)
 152                 result = DID_ERROR << 16;
 153 
 154             /* If there was a bus reset, redo operation on each target */
 155             else if (scsi_stat == CONDITION_GOOD
 156                      && cmd->device->type == TYPE_DISK
 157                      && (HD(cmd)->t_state[cmd->target] == RESET))
 158                 result = DID_BUS_BUSY << 16;        
 159             else
 160                 result = DID_OK << 16;
 161             if (scsi_stat == 0)
 162                 HD(cmd)->t_state[cmd->target] = FALSE;
 163             HD(cmd)->t_timeout[cmd->target] = 0;
 164             break;
 165         case 0x01:              /* Selection Timeout */
 166             result = DID_BAD_TARGET << 16;  
 167             break;
 168         case 0x02:              /* Command Timeout   */
 169             if (HD(cmd)->t_timeout[cmd->target] > 1)
 170                 result = DID_ERROR << 16;
 171             else {
 172                 result = DID_TIME_OUT << 16;
 173                 HD(cmd)->t_timeout[cmd->target]++;
 174             }
 175             break;
 176         case 0x03:              /* SCSI Bus Reset Received */
 177             if (cmd->device->type != TYPE_TAPE)
 178                 result = DID_BUS_BUSY << 16;
 179             else
 180                 result = DID_ERROR << 16;
 181 
 182             for (i = 0; i < MAXTARGET; i++)
 183                 HD(cmd)->t_state[i] = RESET;
 184 
 185             break;
 186         case 0x07:              /* Bus Parity Error */
 187         case 0x0c:              /* Controller Ram Parity */
 188         case 0x04:              /* Initial Controller Power-up */
 189         case 0x05:              /* Unexpected Bus Phase */
 190         case 0x06:              /* Unexpected Bus Free */
 191         case 0x08:              /* SCSI Hung */
 192         case 0x09:              /* Unexpected Message Reject */
 193         case 0x0a:              /* SCSI Bus Reset Stuck */
 194         case 0x0b:              /* Auto Request-Sense Failed */
 195         default:
 196             result = DID_ERROR << 16;
 197             break;
 198         }
 199         cmd->result = result | scsi_stat;
 200 
 201         if (scsi_stat == CHECK_CONDITION) { 
 202             cmd->result |= (DRIVER_SENSE << 24);
 203         }
 204 
 205         DBG(DBG_INTR,printk("scsi_stat: 0x%02x, result: 0x%08x\n",  
 206                             scsi_stat, result)); 
 207         DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
 208 
 209         cp->status = FREE;   /* now we can release the slot  */
 210  
 211         restore_flags(flags);
 212    
 213         DBG(DBG_INTR,printk("Calling scsi_done(%lx)\n",(long)cmd));
 214         cmd->scsi_done(cmd);
 215         DBG(DBG_INTR,printk("returned from scsi_done(%lx)\n",(long)cmd));
 216  
 217         save_flags(flags);
 218         cli();
 219     }
 220     restore_flags(flags);
 221 
 222     return;
 223 }
 224 
 225 inline uint eata_send_command(ulong addr, uint base, unchar command)
     /* [previous][next][first][last][top][bottom][index][help] */
 226 {
 227     uint loop = R_LIMIT;
 228 
 229     while (inb(base + HA_RAUXSTAT) & HA_ABUSY)
 230         if (--loop == 0)
 231             return(TRUE);
 232 
 233     outb(addr & 0x000000ff, base + HA_WDMAADDR);
 234     outb((addr & 0x0000ff00) >> 8, base + HA_WDMAADDR + 1);
 235     outb((addr & 0x00ff0000) >> 16, base + HA_WDMAADDR + 2);
 236     outb((addr & 0xff000000) >> 24, base + HA_WDMAADDR + 3);
 237     outb(command, base + HA_WCOMMAND);
 238     return(FALSE);
 239 }
 240 
 241 int eata_queue(Scsi_Cmnd * cmd, void *(done) (Scsi_Cmnd *))
     /* [previous][next][first][last][top][bottom][index][help] */
 242 {
 243     uint i, x, y;
 244     long flags;
 245 
 246     hostdata *hd;
 247     struct Scsi_Host *sh;
 248     struct eata_ccb *cp;
 249     struct scatterlist *sl;
 250 
 251     save_flags(flags);
 252     cli();
 253 
 254     DBG(DEBUG,queue_counter++);
 255 
 256     hd = HD(cmd);
 257     sh = cmd->host;
 258  
 259     /* check for free slot */
 260      for (y = hd->last_ccb + 1, x = 0; x < sh->can_queue; x++, y++) { 
 261         if (y >= sh->can_queue)
 262             y = 0;
 263         if (hd->ccb[y].status == FREE)
 264             break;
 265     }
 266 
 267     hd->last_ccb = y;
 268 
 269     if (x == sh->can_queue) { 
 270 
 271         DBG(DBG_QUEUE, printk("can_queue %d, x %d, y %d\n",sh->can_queue,x,y));
 272 #if DEBUG
 273         panic("eata_dma: run out of queue slots cmdno:%ld intrno: %ld\n", 
 274               queue_counter, int_counter);
 275 #else
 276         panic("eata_dma: run out of queue slots....\n");
 277 #endif
 278     }
 279 
 280     cp = &hd->ccb[y];
 281 
 282     memset(cp, 0, sizeof(struct eata_ccb));
 283 
 284     cp->status = USED;          /* claim free slot */
 285     
 286     DBG(DBG_QUEUE, printk("eata_queue pid %lx, target: %x, lun: %x, y %d\n",
 287                           cmd->pid, cmd->target, cmd->lun, y));
 288     DBG(DBG_QUEUE && DBG_DELAY, DEL2(250));
 289  
 290     cmd->scsi_done = (void *)done;
 291 
 292     if (cmd->cmnd[0] == WRITE_6 || cmd->cmnd[0] == WRITE_10)
 293         cp->DataOut = TRUE;     /* Output mode */
 294     else
 295         cp->DataIn = TRUE;      /* Input mode  */
 296 
 297     if (cmd->use_sg) {
 298         cp->scatter = TRUE;     /* SG mode     */
 299         cp->cp_dataDMA = htonl((long)&cp->sg_list);
 300         cp->cp_datalen = htonl(cmd->use_sg*8);
 301         sl=(struct scatterlist *)cmd->request_buffer;
 302  
 303         for(i = 0; i < cmd->use_sg; i++, sl++){
 304             cp->sg_list[i].data = htonl((ulong) sl->address);
 305             cp->sg_list[i].len = htonl((ulong) sl->length);
 306         }
 307     } else {
 308         cp->scatter = FALSE;
 309         cp->cp_datalen = htonl(cmd->request_bufflen);
 310         cp->cp_dataDMA = htonl((int)cmd->request_buffer);
 311     }
 312 
 313     cp->Auto_Req_Sen = TRUE;
 314     cp->cp_reqDMA = htonl((ulong) cmd->sense_buffer);
 315     cp->reqlen = sizeof(cmd->sense_buffer);
 316 
 317     cp->cp_id = cmd->target;
 318     cp->cp_lun = cmd->lun;
 319     cp->cp_dispri = TRUE;
 320     cp->cp_identify = TRUE;
 321     memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
 322 
 323     cp->cp_statDMA = htonl((ulong) &(hd->sp));
 324 
 325     cp->cp_viraddr = cp;
 326     cp->cmd = cmd;
 327     cmd->host_scribble = (char *)&hd->ccb[y];   
 328 
 329     if(eata_send_command((ulong) cp, (uint) sh->base, EATA_CMD_DMA_SEND_CP)) {
 330       cmd->result = DID_ERROR << 16;
 331       printk("eata_queue target %d, pid %ld, HBA busy, returning DID_ERROR, done.\n",
 332               cmd->target, cmd->pid);
 333       restore_flags(flags);
 334       done(cmd);
 335       return (0);
 336     }
 337     DBG(DBG_QUEUE,printk("Queued base 0x%04lx pid: %lx target: %x lun: %x slot %d irq %d\n",
 338                           (long)sh->base, cmd->pid, cmd->target, cmd->lun, y, sh->irq));
 339     DBG(DBG_QUEUE && DBG_DELAY, DEL2(200));
 340     restore_flags(flags);
 341     return (0);
 342 }
 343 
 344 static volatile int internal_done_flag = 0;
 345 static volatile int internal_done_errcode = 0;
 346 
 347 static void internal_done(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 348 {
 349     internal_done_errcode = cmd->result;
 350     ++internal_done_flag;
 351 }
 352 
 353 int eata_command(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 354 {
 355 
 356     DBG(DBG_COM, printk("eata_command: calling eata_queue\n"));
 357 
 358     eata_queue(cmd, (void *)internal_done);
 359 
 360     while (!internal_done_flag);
 361     internal_done_flag = 0;
 362     return (internal_done_errcode);
 363 }
 364 
 365 int eata_abort(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 366 {
 367     ulong flags;
 368     uint loop = R_LIMIT;
 369 
 370     save_flags(flags);
 371     cli();
 372 
 373     DBG(DBG_ABNORM, printk("eata_abort called pid: %lx target: %x lun: %x reason %x\n",
 374                            cmd->pid, cmd->target, cmd->lun, cmd->abort_reason));
 375     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 376  
 377 
 378     while (inb((uint)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
 379         if (--loop == 0) {
 380             printk("eata_dma: abort, timeout error.\n");
 381             restore_flags(flags);
 382             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 383             return (SCSI_ABORT_ERROR);
 384         }
 385     if (CD(cmd)->status == FREE) {
 386         DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_NOT_RUNNING\n")); 
 387         restore_flags(flags);
 388         return (SCSI_ABORT_NOT_RUNNING);
 389     }
 390     if (CD(cmd)->status == USED) {
 391         DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_BUSY\n"));
 392         restore_flags(flags);
 393         return (SCSI_ABORT_BUSY);  /* SNOOZE */ 
 394     }
 395     if (CD(cmd)->status == RESET) {
 396         restore_flags(flags);
 397         printk("eata_dma: abort, command reset error.\n");
 398         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 399         return (SCSI_ABORT_ERROR);
 400     }
 401     if (CD(cmd)->status == LOCKED) {
 402         restore_flags(flags);
 403         DBG(DBG_ABNORM, printk("eata_dma: abort, queue slot locked.\n"));
 404         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 405         return (SCSI_ABORT_NOT_RUNNING);
 406     } else
 407         panic("eata_dma: abort: invalid slot status\n");
 408 }
 409 
 410 int eata_reset(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 411 {
 412     uint x, z, time, limit = 0;
 413     uint loop = R_LIMIT;
 414     ulong flags;
 415     unchar success = FALSE;
 416     Scsi_Cmnd *sp; 
 417 
 418     save_flags(flags);
 419     cli();
 420 
 421     DBG(DBG_ABNORM, printk("eata_reset called pid:%lx target: %x lun: %x reason %x\n",
 422                            cmd->pid, cmd->target, cmd->lun, cmd->abort_reason));
 423 
 424 
 425     if (HD(cmd)->state == RESET) {
 426         printk("eata_dma: reset, exit, already in reset.\n");
 427         restore_flags(flags);
 428         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 429         return (SCSI_RESET_ERROR);
 430     }
 431 
 432     while (inb((uint)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
 433         if (--loop == 0) {
 434             printk("eata_dma: reset, exit, timeout error.\n");
 435             restore_flags(flags);
 436             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 437             return (SCSI_RESET_ERROR);
 438         }
 439     for (z = 0; z < MAXTARGET; z++)
 440         HD(cmd)->t_state[z] = RESET;
 441 
 442     for (x = 0; x < cmd->host->can_queue; x++) {
 443 
 444         if (HD(cmd)->ccb[x].status == FREE)
 445             continue;
 446 
 447         if (HD(cmd)->ccb[x].status == LOCKED) {
 448             HD(cmd)->ccb[x].status = FREE;
 449             printk("eata_dma: reset, locked slot %d forced free.\n", x);
 450             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 451             continue;
 452         }
 453         sp = HD(cmd)->ccb[x].cmd;
 454         HD(cmd)->ccb[x].status = RESET;
 455         printk("eata_dma: reset, slot %d in reset, pid %ld.\n", x, sp->pid);
 456         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 457  
 458         if (sp == NULL)
 459             panic("eata_dma: reset, slot %d, sp==NULL.\n", x);
 460             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 461  
 462         if (sp == cmd)
 463             success = TRUE;
 464     }
 465 
 466     /* hard reset the HBA  */
 467     inb((uint) (cmd->host->base) + HA_RSTATUS);   /* This might cause trouble */
 468     eata_send_command(0, (uint) cmd->host->base, EATA_CMD_RESET);
 469 
 470     DBG(DBG_ABNORM, printk("eata_dma: reset, board reset done, enabling interrupts.\n"));
 471     HD(cmd)->state = RESET;
 472 
 473     restore_flags(flags);
 474 
 475     time = jiffies;
 476     while (jiffies < (time + 300) && limit++ < 10000000);
 477 
 478     save_flags(flags);
 479     cli();
 480 
 481     DBG(DBG_ABNORM, printk("eata_dma: reset, interrupts disabled, loops %d.\n",
 482                            limit));
 483     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 484  
 485     for (x = 0; x < cmd->host->can_queue; x++) {
 486 
 487         /* Skip slots already set free by interrupt */
 488         if (HD(cmd)->ccb[x].status != RESET)
 489             continue;
 490 
 491         sp = HD(cmd)->ccb[x].cmd;
 492         sp->result = DID_RESET << 16;
 493 
 494         /* This mailbox is still waiting for its interrupt */
 495         HD(cmd)->ccb[x].status = LOCKED;
 496 
 497         printk("eata_dma, reset, slot %d locked, DID_RESET, pid %ld done.\n",
 498             x, sp->pid);
 499         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 500         restore_flags(flags);
 501         sp->scsi_done(sp);
 502         cli();
 503     }
 504 
 505     HD(cmd)->state = FALSE;
 506     restore_flags(flags);
 507 
 508     if (success) {
 509         DBG(DBG_ABNORM, printk("eata_dma: reset, exit, success.\n"));
 510         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 511         return (SCSI_RESET_SUCCESS);
 512     } else {
 513         DBG(DBG_ABNORM, printk("eata_dma: reset, exit, wakeup.\n"));
 514         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 515         return (SCSI_RESET_PUNT);
 516     }
 517 }
 518 
 519 
 520 char * get_board_data(ulong base, uint irq, uint id)
     /* [previous][next][first][last][top][bottom][index][help] */
 521 {
 522     struct eata_ccb cp;
 523     struct eata_sp  sp;
 524     static char buff[256];
 525 
 526     memset(&cp, 0, sizeof(struct eata_ccb));
 527     memset(buff, 0, sizeof(buff));
 528 
 529     cp.DataIn = TRUE;     
 530     cp.Interpret = TRUE;   /* Interpret command */
 531  
 532     cp.cp_datalen = htonl(255);  
 533     cp.cp_dataDMA = htonl((long)buff);
 534 
 535     cp.cp_id = id;
 536     cp.cp_lun = 0;
 537 
 538     cp.cp_cdb[0] = INQUIRY;
 539     cp.cp_cdb[1] = 0;
 540     cp.cp_cdb[2] = 0;
 541     cp.cp_cdb[3] = 0;
 542     cp.cp_cdb[4] = 255;
 543     cp.cp_cdb[5] = 0;
 544 
 545     cp.cp_statDMA = htonl((ulong) &sp);
 546 
 547     eata_send_command((ulong) &cp, (uint) base, EATA_CMD_DMA_SEND_CP);
 548     while (!(inb(base + HA_RAUXSTAT) & HA_AIRQ));
 549     inb((uint) base + HA_RSTATUS);
 550 
 551     return (buff);
 552 }
 553     
 554 int check_blink_state(long base)
     /* [previous][next][first][last][top][bottom][index][help] */
 555 {
 556     uint ret = 0;
 557     uint loops = 10;
 558     ulong blinkindicator = 0x42445054;
 559     ulong state = 0x12345678;
 560     ulong oldstate = 0;
 561 
 562     while ((loops--) && (state != oldstate)) {
 563         oldstate = state;
 564         state = inl((uint) base + 1);
 565     }
 566 
 567     if ((state == oldstate) && (state == blinkindicator))
 568         ret = 1;
 569     DBG(DBG_BLINK, printk("Did Blink check. Status: %d\n", ret));
 570     return (ret);
 571 }
 572 
 573 int get_conf_PIO(struct eata_register *base, struct get_conf *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 574 {
 575     ulong loop = R_LIMIT;
 576     ushort *p;
 577 
 578     if(check_region((uint)base, 9)) 
 579         return (FALSE);
 580  
 581     memset(buf, 0, sizeof(struct get_conf));
 582 
 583     while (inb((uint) base + HA_RSTATUS) & HA_SBUSY)
 584         if (--loop == 0) 
 585             return (FALSE);
 586        
 587     DBG(DBG_PIO && DBG_PROBE, printk("Issuing PIO READ CONFIG to HBA at %lx\n", 
 588                                    (long)base));
 589     eata_send_command(0, (uint) base, EATA_CMD_PIO_READ_CONFIG);
 590     loop = R_LIMIT;
 591     for (p = (ushort *) buf; 
 592          (long)p <= ((long)buf + (sizeof(struct get_conf)/ 2)); p++) {
 593         while (!(inb((uint) base + HA_RSTATUS) & HA_SDRQ))
 594             if (--loop == 0)
 595                 return (FALSE);
 596         loop = R_LIMIT;
 597         *p = inw((uint) base + HA_RDATA);
 598     }
 599     if (!(inb((uint) base + HA_RSTATUS) & HA_SERROR)) {         /* Error ? */
 600         DBG(DBG_PIO&&DBG_PROBE, printk("\nSignature: %c%c%c%c\n", 
 601                               (char)buf->sig[0], (char)buf->sig[1], 
 602                               (char)buf->sig[2], (char)buf->sig[3]));
 603 
 604         if ((buf->sig[0] == 'E') && (buf->sig[1] == 'A')
 605             && (buf->sig[2] == 'T') && (buf->sig[3] == 'A')) {
 606             DBG(DBG_PIO&&DBG_PROBE, printk("EATA Controller found at %x "
 607                       "EATA Level: %x\n", (uint) base, (uint) (buf->version)));
 608         
 609             while (inb((uint) base + HA_RSTATUS) & HA_SDRQ) 
 610                 inw((uint) base + HA_RDATA);
 611             return (TRUE);
 612         } 
 613     } else {
 614         printk("eata_dma: get_conf_PIO, error during transfer for HBA at %lx",
 615                (long)base);
 616     }
 617     return (FALSE);
 618 }
 619 
 620 void print_config(struct get_conf *gc)
     /* [previous][next][first][last][top][bottom][index][help] */
 621 {
 622     printk("Please check values: (read config data)\n");
 623     printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d DMAS:%d\n",
 624         (uint) ntohl(gc->len), gc->version,
 625         gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support,
 626         gc->DMA_support);
 627     printk("DMAV:%d HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
 628         gc->DMA_valid, gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2],
 629         gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
 630     printk("IRQ:%d IRQT:%d DMAC:%d FORCADR:%d MCH:%d RIDQ:%d PCI:%d EISA:%d\n",
 631         gc->IRQ, gc->IRQ_TR, (8 - gc->DMA_channel) & 7, gc->FORCADR, 
 632         gc->MAX_CHAN, gc->ID_qest, gc->is_PCI, gc->is_EISA);
 633     DBG(DPT_DEBUG, DELAY(1400));
 634 }
 635 
 636 int register_HBA(long base, struct get_conf *gc, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 637 {
 638     ulong size = 0;
 639     unchar dma_channel = 0;
 640     char *buff;
 641     uint i;
 642     struct Scsi_Host *sh;
 643     hostdata *hd;
 644     
 645     DBG(DBG_REGISTER, print_config(gc));
 646 
 647     if (!gc->DMA_support) {
 648         printk("HBA at 0x%08lx doesn't support DMA. Sorry\n",base);
 649         return (FALSE);
 650     }
 651 
 652     /* if gc->DMA_valid it must be a PM2011 and we have to register it */
 653     dma_channel = (8 - gc->DMA_channel) & 7;
 654     if (gc->DMA_valid) {
 655         if (request_dma(dma_channel, "DPT_PM2011")) {
 656             printk("Unable to allocate DMA channel %d for HBA PM2011.\n",
 657                 dma_channel);
 658             return (FALSE);
 659         }
 660     }
 661 
 662     if (!reg_IRQ[gc->IRQ]) {    /* Interrupt already registered ? */
 663         if (!request_irq(gc->IRQ, eata_int_handler, SA_INTERRUPT, "EATA-DMA")){
 664             reg_IRQ[gc->IRQ]++;
 665             if (!gc->IRQ_TR)
 666                 reg_IRQL[gc->IRQ] = 1;  /* IRQ is edge triggered */
 667 
 668             /* We free it again so we can do a get_conf_dma and 
 669              * allocate the interrupt again later */
 670             free_irq(gc->IRQ);  
 671         } else {
 672             printk("Couldn't allocate IRQ %d, Sorry.", gc->IRQ);
 673             return (0);
 674         }
 675     } else {                    /* More than one HBA on this IRQ */
 676         if (reg_IRQL[gc->IRQ]) {
 677             printk("Can't support more than one HBA on this IRQ,\n"
 678                    "  if the IRQ is edge triggered. Sorry.\n");
 679             return (0);
 680         } else
 681             reg_IRQ[gc->IRQ]++;
 682     }
 683 
 684     request_region(base, 9, "eata_dma");
 685 
 686     if(gc->HAA_valid == FALSE) gc->MAX_CHAN = 0;
 687 
 688     size = sizeof(hostdata) + ((sizeof(struct eata_ccb) * ntohs(gc->queuesiz))/
 689                                (gc->MAX_CHAN + 1));
 690     if(ntohs(gc->queuesiz) == 0) {
 691         gc->queuesiz = ntohs(64);
 692             printk("Warning: Queue size had to be corrected.\n"
 693                    "This might be a PM2012 with a defective Firmware\n");
 694     }
 695 
 696     buff = get_board_data((uint)base, gc->IRQ, gc->scsi_id[3]);
 697 
 698     if(!(strncmp("PM2322", &buff[16], 6) || strncmp("PM3021", &buff[16], 6)
 699        || strncmp("PM3222", &buff[16], 6) || strncmp("PM3224", &buff[16], 6)))
 700       gc->MAX_CHAN = 0;
 701     
 702     if (gc->MAX_CHAN) {
 703         printk("This is a multichannel HBA. Linux doesn't support them,\n");
 704         printk("so we'll try to register every channel as a virtual HBA.\n");
 705     }
 706     
 707     for (i = 0; i <= gc->MAX_CHAN; i++) {
 708 
 709         sh = scsi_register(tpnt, size);
 710         hd = SD(sh);                   
 711 
 712         memset(hd->ccb, 0, (sizeof(struct eata_ccb) * ntohs(gc->queuesiz)) / 
 713                (gc->MAX_CHAN + 1));
 714 
 715         strncpy(SD(sh)->vendor, &buff[8], 8);
 716         SD(sh)->vendor[8] = 0;
 717         strncpy(SD(sh)->name, &buff[16], 17);
 718         SD(sh)->name[17] = 0;
 719         SD(sh)->revision[0] = buff[32];
 720         SD(sh)->revision[1] = buff[33];
 721         SD(sh)->revision[2] = buff[34];
 722         SD(sh)->revision[3] = '.';
 723         SD(sh)->revision[4] = buff[35];
 724         SD(sh)->revision[5] = 0;
 725 
 726         sh->base = (char *) base;
 727         sh->irq = gc->IRQ;
 728         sh->dma_channel = dma_channel;
 729 
 730         sh->this_id = gc->scsi_id[3 - i];
 731 
 732         sh->can_queue = ntohs(gc->queuesiz) / (gc->MAX_CHAN + 1);
 733 
 734         if (gc->OCS_enabled == TRUE) {
 735             sh->cmd_per_lun = sh->can_queue/C_P_L_DIV; 
 736         } else {
 737             sh->cmd_per_lun = 1;
 738         }
 739         sh->sg_tablesize = ntohs(gc->SGsiz);
 740         if (sh->sg_tablesize > SG_SIZE || sh->sg_tablesize == 0) {
 741             sh->sg_tablesize = SG_SIZE;
 742             if (ntohs(gc->SGsiz) == 0)
 743                 printk("Warning: SG size had to be corrected.\n"
 744                        "This might be a PM2012 with a defective Firmware\n");
 745         }
 746         sh->loaded_as_module = 0;       /* Not yet supported */
 747 
 748         hd->channel = i;
 749 
 750         if (buff[21] == '4')
 751             hd->bustype = 'P';
 752         else if (buff[21] == '2')
 753             hd->bustype = 'E';
 754         else
 755             hd->bustype = 'I';
 756 
 757         if (gc->SECOND)
 758             hd->primary = FALSE;
 759         else
 760             hd->primary = TRUE;
 761 
 762         if (hd->bustype != 'I')
 763             sh->unchecked_isa_dma = FALSE;
 764         else
 765             sh->unchecked_isa_dma = TRUE;   /* We're doing ISA DMA */
 766 
 767         if((hd->primary == TRUE) && (i == 0) && HARDCODED){                  
 768           geometry.drv[0].heads = HEADS0;          
 769           geometry.drv[0].sectors = SECTORS0;      
 770           geometry.drv[0].cylinder = CYLINDER0;
 771           geometry.drv[0].id = ID0;
 772           geometry.drv[0].trans = TRUE;
 773           geometry.drv[1].heads = HEADS1;
 774           geometry.drv[1].sectors = SECTORS1;
 775           geometry.drv[1].cylinder = CYLINDER1;
 776           geometry.drv[1].id = ID1;
 777           geometry.drv[1].trans = TRUE;
 778         } else {
 779           geometry.drv[0].id=-1;
 780           geometry.drv[1].id=-1;
 781         }
 782 
 783         hd->next = NULL;        /* build a linked list of all HBAs */
 784         hd->prev = last_HBA;
 785         hd->prev->next = sh;
 786         last_HBA = sh;
 787 
 788         registered_HBAs++;
 789     }
 790     return (1);
 791 }
 792 
 793 /* flag: -1 scan for primary   HBA
 794  *        0 scan for secondary HBA
 795  * buf :  pointer to data structure for read config command
 796  */
 797 
 798 long find_EISA(struct get_conf *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 799 {
 800     struct eata_register *base;
 801     int i;
 802 
 803 #if CHECKPAL
 804     unsigned char pal1, pal2, pal3, *p;
 805 #endif
 806 
 807     for (i = 0; i < MAXEISA; i++) {
 808         if (EISAbases[i] == TRUE) {     /* Still a possibility ?          */
 809 
 810             base = (void *)0x1c88 + (i * 0x1000);
 811 #if CHECKPAL
 812             p = (char *)base;
 813             pal1 = *(p - 8);
 814             pal2 = *(p - 7);
 815             pal3 = *(p - 6);
 816 
 817             if (((pal1 == 0x12) && (pal2 == 0x14)) ||
 818                 ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) ||
 819                 ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
 820                 DBG(DBG_PROBE, printk("EISA EATA id tags found: %x %x %x \n",
 821                         (int)pal1, (int)pal2, (int)pal3));
 822 #endif
 823                 if (get_conf_PIO(base, buf)) {
 824                     DBG(DBG_PROBE&&DBG_EISA,print_config(buf));
 825                     if ((buf->SECOND == FALSE) && (buf->IRQ)) {
 826                         /* We just found a primary EISA, so there is no primary
 827                          * ISA HBA and we can take it from the EISA list. 
 828                          */
 829                         ISAbases[0] = 0;
 830                         EISAbases[i] = 0;
 831                         return ((long)base);
 832                     } else if ((buf->SECOND == TRUE) && (buf->IRQ)) {
 833                         /* We've found a secondary EISA, so there is no 
 834                          * secondary ISA HBA  */
 835                         ISAbases[1] = 0;
 836                         /* and we can take it from the list and return it */
 837                         EISAbases[i] = 0;
 838                         return ((long)base);
 839                     } else {
 840                         EISAbases[i] = 0;
 841                         printk("No valid IRQ. HBA removed from list\n");
 842                     }
 843                 } else
 844                     /* Nothing found here so we take it from the list */
 845                     EISAbases[i] = 0;  
 846 #if CHECKPAL
 847             }
 848 #endif
 849         }
 850     }
 851     return (0l);                /* Nothing found  :-(             */
 852 }
 853 
 854 long find_ISA(struct get_conf *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 855 {
 856     int i, l;
 857     long ret;
 858 
 859     ret = (long)NULL;
 860 
 861     for (l = 0; l < MAXISA; l++) {      
 862         if (ISAbases[l]) {      
 863             i = get_conf_PIO((struct eata_register *)ISAbases[l], buf);
 864             if (i == TRUE) {
 865                 ret = ISAbases[l];
 866                 ISAbases[l] = 0;
 867                 return (ret);
 868             } else
 869                 ISAbases[l] = 0;
 870         }
 871     }
 872     return ((long)NULL);
 873 }
 874 
 875 void find_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 876 {
 877 
 878 #ifndef CONFIG_PCI
 879     printk("Kernel PCI support not enabled. Skipping.\n");
 880 #else
 881 
 882     unchar pci_bus, pci_device_fn;
 883     static short pci_index = 0; /* Device index to PCI BIOS calls */
 884     ulong base = 0;
 885     ushort com_adr;
 886     ushort rev_device;
 887     uint error, i, x;
 888 
 889     if (pcibios_present()) {
 890         for (i = 0; i <= MAXPCI; ++i, ++pci_index) {
 891 
 892             if (pcibios_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, 
 893                                     pci_index, &pci_bus, &pci_device_fn))
 894                 break;
 895             DBG(DBG_PROBE && DBG_PCI, printk("eata_dma: HBA at bus %d, device %d,"
 896                                 " function %d, index %d\n", (int)pci_bus, 
 897                                 (int)((pci_device_fn & 0xf8) >> 3),
 898                                 (int)(pci_device_fn & 7), pci_index));
 899 
 900             if (!(error = pcibios_read_config_word(pci_bus, pci_device_fn, 
 901                                                  PCI_CLASS_DEVICE, &rev_device))) {
 902                 if (rev_device == PCI_CLASS_STORAGE_SCSI) {
 903                     if (!(error = pcibios_read_config_word(pci_bus, 
 904                                                            pci_device_fn, PCI_COMMAND, 
 905                                                            (ushort *) & com_adr))) {
 906                         if (!((com_adr & PCI_COMMAND_IO) && 
 907                               (com_adr & PCI_COMMAND_MASTER))) {
 908                             printk("HBA has IO or BUSMASTER mode disabled\n");
 909                             continue;
 910                         }
 911                     } else
 912                         printk("error %x while reading PCI_COMMAND\n", error);
 913                 } else
 914                   printk("DEVICECLASSID %x didn't match\n", rev_device);
 915             } else {
 916               printk("error %x while reading PCI_CLASS_BASE\n", error);
 917               continue;
 918             }
 919 
 920             if (!(error = pcibios_read_config_dword(pci_bus, pci_device_fn,
 921                                                   PCI_BASE_ADDRESS_0, &base))) {
 922 
 923                 /* Check if the address is valid */
 924                 if (base & 0x01) {
 925                     base &= 0xfffffffe;
 926                                         /* EISA tag there ? */
 927                     if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
 928                         continue;       /* Jep, it's forced, so move on  */
 929                     base += 0x10;       /* Now, THIS is the real address */
 930                     if (base != 0x1f8) {
 931                         /* We didn't find it in the primary search */
 932                         if (get_conf_PIO((struct eata_register *)base, buf)) {
 933                             if (buf->FORCADR)   /* If the address is forced */
 934                                 continue;       /* we'll find it later      */
 935 
 936                             /* OK. We made it till here, so we can go now  
 937                              * and register it. We  only have to check and 
 938                              * eventually remove it from the EISA and ISA list 
 939                              */
 940 
 941                             register_HBA(base, buf, tpnt);
 942 
 943                             if (base < 0x1000) {
 944                                 for (x = 0; x < MAXISA; ++x) {
 945                                     if (ISAbases[x] == base) {
 946                                         ISAbases[x] = 0;
 947                                         break;
 948                                     }
 949                                 }
 950                             } else if ((base & 0x0fff) == 0x0c88) {
 951                                 x = (base >> 12) & 0x0f;
 952                                 EISAbases[x] = 0;
 953                             }
 954                             continue;  /*break;*/
 955                         } else if (check_blink_state(base)) {
 956                             printk("HBA is in BLINK state. Consult your HBAs "
 957                                    " Manual to correct this.\n");
 958                         }
 959                     }
 960                 }
 961             } else
 962               printk("error %x while reading PCI_BASE_ADDRESS_0\n", error);
 963         }
 964     } else
 965     printk("No BIOS32 extensions present. This release still depends on it."
 966              " Sorry.\n");
 967 #endif /* #ifndef CONFIG_PCI */
 968     return;
 969 }
 970 
 971 int eata_detect(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 972 {
 973     struct Scsi_Host *HBA_ptr;
 974     struct get_conf gc;
 975     ulong base = 0;
 976     int i;
 977  
 978     geometry.drv[0].trans = geometry.drv[1].trans = 0;
 979 
 980     printk("EATA (Extended Attachment) driver version: %d.%d%s\n"
 981            "developed in co-operation with DPT\n"             
 982            "(c) 1993-95 Michael Neuffer  neuffer@goofy.zdv.uni-mainz.de\n",
 983            VER_MAJOR, VER_MINOR, VER_SUB);
 984  
 985     DBG((DBG_PROBE && DBG_DELAY)|| DPT_DEBUG,
 986         printk("Using lots of delays to let you read the debugging output\n"));
 987 
 988     printk("Now scanning for PCI HBAs\n");
 989 
 990     find_PCI(&gc, tpnt);
 991 
 992     printk("Now scanning for EISA HBAs\n");
 993 
 994     for (i = 0; i <= MAXEISA; i++) {
 995         base = find_EISA(&gc);
 996         if (base)
 997             register_HBA(base, &gc, tpnt);
 998     }
 999 
1000     printk("Now scanning for ISA HBAs\n");
1001 
1002     for (i = 0; i <= MAXISA; i++) {
1003         base = find_ISA(&gc);
1004         if (base)
1005             register_HBA(base, &gc, tpnt);
1006     }
1007 
1008     for (i = 0; i <= MAXIRQ; i++)
1009         if (reg_IRQ[i])
1010             request_irq(i, eata_int_handler, SA_INTERRUPT, "EATA-DMA");
1011 
1012     HBA_ptr = last_HBA;
1013     for (i = 1; i < registered_HBAs; i++)
1014         HBA_ptr = SD(HBA_ptr)->prev;
1015 
1016     printk("Registered HBAs:\n");
1017     printk("HBA no. VID: Boardtype:  Revis: Bus: BaseIO: IRQ: Chan: ID: Prim: QS: SG: CPL:\n");
1018     for (i = 1; i <= registered_HBAs; i++) {
1019         printk("scsi%-2d: %.4s %.11s v%s ", HBA_ptr->host_no, 
1020                SD(HBA_ptr)->vendor, SD(HBA_ptr)->name, SD(HBA_ptr)->revision);
1021         if(SD(HBA_ptr)->bustype == 'P') printk("PCI "); 
1022         else if(SD(HBA_ptr)->bustype == 'E') printk("EISA"); 
1023         else printk(" ISA");
1024         printk(" 0x%04x   %2d     %d   %d     %d  %2d  %2d   %2d\n", 
1025                (uint) HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, 
1026                HBA_ptr->this_id, SD(HBA_ptr)->primary, HBA_ptr->can_queue, 
1027                HBA_ptr->sg_tablesize, HBA_ptr->cmd_per_lun);
1028         HBA_ptr = SD(HBA_ptr)->next;
1029       }
1030     DBG(DPT_DEBUG,DELAY(1200));
1031 
1032     return (registered_HBAs);
1033 }
1034 
1035 
1036 

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