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

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