root/drivers/scsi/eata_dma.c

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

DEFINITIONS

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

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

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