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

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