root/drivers/scsi/eata_pio.c

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

DEFINITIONS

This source file includes following definitions.
  1. hprint
  2. eata_pio_release
  3. IncStat
  4. eata_pio_int_handler
  5. eata_pio_send_command
  6. eata_pio_queue
  7. eata_pio_abort
  8. eata_pio_reset
  9. get_pio_board_data
  10. get_pio_conf_PIO
  11. print_pio_config
  12. print_selftest
  13. register_pio_HBA
  14. find_pio_ISA
  15. find_pio_EISA
  16. find_pio_PCI
  17. eata_pio_detect

   1 /************************************************************
   2  *                                                          *
   3  *               Linux EATA SCSI PIO 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 EATA-PIO boards                       *
  11  *      -only supports DASD devices                         *
  12  *                                                          *
  13  *  (c)1993,94,95 Michael Neuffer, Alfred Arnold            *
  14  *                neuffer@goofy.zdv.uni-mainz.de            *
  15  *                a.arnold@kfa-juelich.de                   * 
  16  *                                                          *
  17  *  This program is free software; you can redistribute it  *
  18  *  and/or modify it under the terms of the GNU General     *
  19  *  Public License as published by the Free Software        *
  20  *  Foundation; either version 2 of the License, or         *
  21  *  (at your option) any later version.                     *
  22  *                                                          *
  23  *  This program is distributed in the hope that it will be *
  24  *  useful, but WITHOUT ANY WARRANTY; without even the      *
  25  *  implied warranty of MERCHANTABILITY or FITNESS FOR A    *
  26  *  PARTICULAR PURPOSE.  See the GNU General Public License *
  27  *  for more details.                                       *
  28  *                                                          *
  29  *  You should have received a copy of the GNU General      *
  30  *  Public License along with this kernel; if not, write to *
  31  *  the Free Software Foundation, Inc., 675 Mass Ave,       *
  32  *  Cambridge, MA 02139, USA.                               *
  33  *                                                          *
  34  ************************************************************
  35  *  last change: 95/08/04                 OS: Linux 1.3.15  *
  36  ************************************************************/
  37 
  38 /* Look in eata_pio.h for configuration information */
  39 
  40 #ifdef MODULE
  41 #include <linux/module.h>
  42 #include <linux/version.h>
  43 #endif
  44  
  45 #include <linux/kernel.h>
  46 #include <linux/sched.h>
  47 #include <linux/string.h>
  48 #include <linux/ioport.h>
  49 #include <linux/malloc.h>
  50 #include <linux/in.h>
  51 #include <linux/bios32.h>
  52 #include <linux/pci.h>
  53 #include <linux/proc_fs.h>
  54 #include <asm/io.h>
  55 #include "eata_pio.h"
  56 #include "eata_dma_proc.h"
  57 #include "scsi.h"
  58 #include "sd.h"
  59 
  60 static uint ISAbases[MAXISA] =
  61 {0x1F0, 0x170, 0x330, 0x230};
  62 static uint ISAirqs[MAXISA] =
  63 {14,12,15,11};
  64 static unchar EISAbases[] =
  65 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  66 static uint registered_HBAs = 0;
  67 static struct Scsi_Host *last_HBA = NULL;
  68 static struct Scsi_Host *first_HBA = NULL;
  69 static unchar reg_IRQ[] =
  70 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  71 static unchar reg_IRQL[] =
  72 {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  73 
  74 static ulong int_counter = 0;
  75 static ulong queue_counter = 0;
  76 
  77 void hprint(const char *str)
     /* [previous][next][first][last][top][bottom][index][help] */
  78 {
  79     char *hptr =(char *) 0x000b0000;
  80     char *hptr2=(char *) 0x000b00a0; 
  81     char *hptr3=(char *) 0x000b0f00;
  82     int z;
  83     
  84     memmove(hptr,hptr2,24*80*2);
  85     for (z=0; z<strlen(str); z++)
  86         hptr3[z*2]=str[z];
  87     for (; z<80; z++)
  88         hptr3[z*2]=' ';
  89 }
  90 
  91 
  92 #include "eata_pio_proc.c"
  93  
  94 #ifdef MODULE
  95 int eata_pio_release(struct Scsi_Host *sh)
     /* [previous][next][first][last][top][bottom][index][help] */
  96 {
  97     if (sh->irq && reg_IRQ[sh->irq] == 1) free_irq(sh->irq);
  98     else reg_IRQ[sh->irq]--;
  99     if (SD(sh)->channel == 0) {
 100         if (sh->io_port && sh->n_io_port)
 101             release_region(sh->io_port, sh->n_io_port);
 102     }
 103     return(TRUE);
 104 }
 105 #endif
 106 
 107 void IncStat(Scsi_Pointer *SCp, uint Increment)
     /* [previous][next][first][last][top][bottom][index][help] */
 108 {
 109     SCp->ptr+=Increment; 
 110     if ((SCp->this_residual-=Increment)==0)
 111     {
 112         if ((--SCp->buffers_residual)==0) SCp->Status=FALSE;
 113         else
 114         {
 115             SCp->buffer++;
 116             SCp->ptr=SCp->buffer->address;
 117             SCp->this_residual=SCp->buffer->length;
 118         }
 119     }
 120 }
 121 
 122 void eata_pio_int_handler(int irq, struct pt_regs * regs)
     /* [previous][next][first][last][top][bottom][index][help] */
 123 {
 124     uint eata_stat = 0xfffff;
 125     Scsi_Cmnd *cmd;
 126     hostdata *hd;
 127     struct eata_ccb *cp;
 128     uint base;
 129     ulong flags;
 130     uint x,z;
 131     struct Scsi_Host *sh;
 132     ushort zwickel=0;
 133     unchar stat,odd;
 134     
 135     save_flags(flags);
 136     cli();
 137     
 138     for (x = 1, sh = first_HBA; x <= registered_HBAs; x++, sh = SD(sh)->prev) {
 139         if (sh->irq != irq)
 140             continue;
 141         if (inb((uint)sh->base + HA_RSTATUS) & HA_SBUSY)
 142             continue;
 143         
 144         int_counter++;
 145         
 146         hd=SD(sh);
 147         
 148         cp = &hd->ccb[0];
 149         cmd = cp->cmd;
 150         base = (uint) cmd->host->base;
 151         
 152         do
 153         {
 154             stat=inb(base+HA_RSTATUS);
 155             if (stat&HA_SDRQ)
 156                 if (cp->DataIn)
 157                 {
 158                     z=256; odd=FALSE;
 159                     while ((cmd->SCp.Status)&&((z>0)||(odd)))
 160                     {
 161                         if (odd) 
 162                         { 
 163                             *(cmd->SCp.ptr)=zwickel>>8; 
 164                             IncStat(&cmd->SCp,1);
 165                             odd=FALSE;
 166                         }
 167                         x=min(z,cmd->SCp.this_residual/2);
 168                         insw(base+HA_RDATA,cmd->SCp.ptr,x);
 169                         z-=x; 
 170                         IncStat(&cmd->SCp,2*x);
 171                         if ((z>0)&&(cmd->SCp.this_residual==1))
 172                         {
 173                             zwickel=inw(base+HA_RDATA); 
 174                             *(cmd->SCp.ptr)=zwickel&0xff;
 175                             IncStat(&cmd->SCp,1); z--; 
 176                             odd=TRUE;
 177                         }
 178                     }
 179                     while (z>0) {
 180                         zwickel=inw(base+HA_RDATA); 
 181                         z--;
 182                     } 
 183                 }
 184                 else /* cp->DataOut */
 185                 {
 186                     odd=FALSE; z=256;
 187                     while ((cmd->SCp.Status)&&((z>0)||(odd)))
 188                     {
 189                         if (odd)
 190                         {
 191                             zwickel+=*(cmd->SCp.ptr)<<8; 
 192                             IncStat(&cmd->SCp,1);
 193                             outw(zwickel,base+HA_RDATA); 
 194                             z--; 
 195                             odd=FALSE; 
 196                         }
 197                         x=min(z,cmd->SCp.this_residual/2);
 198                         outsw(base+HA_RDATA,cmd->SCp.ptr,x);
 199                         z-=x; 
 200                         IncStat(&cmd->SCp,2*x);
 201                         if ((z>0)&&(cmd->SCp.this_residual==1))
 202                         {
 203                             zwickel=*(cmd->SCp.ptr); 
 204                             zwickel&=0xff;
 205                             IncStat(&cmd->SCp,1); 
 206                             odd=TRUE;
 207                         }  
 208                     }
 209                     while (z>0||odd) {
 210                         outw(zwickel,base+HA_RDATA); 
 211                         z--; 
 212                         odd=FALSE;
 213                     }
 214                 }
 215         }
 216         while ((stat&HA_SDRQ)||((stat&HA_SMORE)&&hd->moresupport));
 217         
 218         /* terminate handler if HBA goes busy again, i.e. transfers
 219          * more data */
 220         
 221         if (stat&HA_SBUSY) break;
 222         
 223         /* OK, this is quite stupid, but I haven't found any correct
 224          * way to get HBA&SCSI status so far */
 225         
 226         if (!(inb(base+HA_RSTATUS)&HA_SERROR))
 227         {
 228             cmd->result=(DID_OK<<16); 
 229             hd->devflags|=(1<<cp->cp_id);
 230         }
 231         else if (hd->devflags&1<<cp->cp_id) 
 232             cmd->result=(DID_OK<<16)+0x02;
 233         else cmd->result=(DID_NO_CONNECT<<16);
 234         
 235         if (cp->status == LOCKED) {
 236             cp->status = FREE;
 237             eata_stat = inb(base + HA_RSTATUS);
 238             printk("eata_pio: int_handler, freeing locked queueslot\n");
 239             DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
 240             restore_flags(flags);
 241             return;
 242         }
 243         
 244 #if DBG_INTR2
 245         if (stat != 0x50) 
 246             printk("stat: %#.2x, result: %#.8x\n", stat, cmd->result); 
 247         DBG(DBG_INTR&&DBG_DELAY,DEL2(800));
 248 #endif
 249         
 250         cp->status = FREE;   /* now we can release the slot  */
 251         
 252         restore_flags(flags);
 253         cmd->scsi_done(cmd);
 254         save_flags(flags);
 255         cli();
 256     }
 257     restore_flags(flags);
 258     
 259     return;
 260 }
 261 
 262 inline uint eata_pio_send_command(uint base, unchar command)
     /* [previous][next][first][last][top][bottom][index][help] */
 263 {
 264     uint loop = R_LIMIT;
 265     
 266     while (inb(base + HA_RSTATUS) & HA_SBUSY)
 267         if (--loop == 0)
 268             return(TRUE);
 269     
 270     outb(command, base + HA_WCOMMAND);
 271     return(FALSE);
 272 }
 273 
 274 int eata_pio_queue(Scsi_Cmnd * cmd, void (*done) (Scsi_Cmnd *))
     /* [previous][next][first][last][top][bottom][index][help] */
 275 {
 276     uint x, y;
 277     long flags;
 278     uint base;
 279     
 280     hostdata *hd;
 281     struct Scsi_Host *sh;
 282     struct eata_ccb *cp;
 283     
 284     save_flags(flags);
 285     cli();
 286     
 287     queue_counter++;
 288     
 289     hd = HD(cmd);
 290     sh = cmd->host;
 291     base = (uint) sh->base;
 292     
 293     /* use only slot 0, as 2001 can handle only one cmd at a time */
 294     
 295     y = x = 0;
 296     
 297     if (hd->ccb[y].status!=FREE) { 
 298         
 299         DBG(DBG_QUEUE, printk("can_queue %d, x %d, y %d\n",sh->can_queue,x,y));
 300 #if DEBUG_EATA
 301         panic("eata_pio: run out of queue slots cmdno:%ld intrno: %ld\n", 
 302               queue_counter, int_counter);
 303 #else
 304         panic("eata_pio: run out of queue slots....\n");
 305 #endif
 306     }
 307     
 308     cp = &hd->ccb[y];
 309     
 310     memset(cp, 0, sizeof(struct eata_ccb));
 311     memset(cmd->sense_buffer, 0, sizeof(cmd->sense_buffer));
 312         
 313     cp->status = USED;      /* claim free slot */
 314 
 315     DBG(DBG_QUEUE, printk("eata_pio_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 UPDATE_BLOCK:      case WRITE_LONG:      case WRITE_SAME:      
 329     case SEARCH_HIGH_12:    case SEARCH_EQUAL_12: case SEARCH_LOW_12:
 330     case WRITE_12:          case WRITE_VERIFY_12: case SET_WINDOW: 
 331     case MEDIUM_SCAN:       case SEND_VOLUME_TAG:            
 332     case 0xea:      /* alternate number for WRITE LONG */
 333         cp->DataOut = TRUE; /* Output mode */
 334         break;
 335     case TEST_UNIT_READY:
 336     default:
 337         cp->DataIn = TRUE;  /* Input mode  */
 338     }
 339     
 340     cp->Interpret = (cmd->target == hd->hostid);
 341     cp->cp_datalen = htonl((ulong)cmd->request_bufflen);
 342     cp->Auto_Req_Sen = FALSE;
 343     cp->cp_reqDMA = htonl(0);
 344     cp->reqlen = 0;
 345     
 346     cp->cp_id = cmd->target;
 347     cp->cp_lun = cmd->lun;
 348     cp->cp_dispri = FALSE;
 349     cp->cp_identify = TRUE;
 350     memcpy(cp->cp_cdb, cmd->cmnd, COMMAND_SIZE(*cmd->cmnd));
 351     
 352     cp->cp_statDMA = htonl(0);
 353     
 354     cp->cp_viraddr = cp;
 355     cp->cmd = cmd;
 356     cmd->host_scribble = (char *)&hd->ccb[y];   
 357     
 358     if (cmd->use_sg == 0)
 359     { 
 360         cmd->SCp.buffers_residual=1;
 361         cmd->SCp.ptr = cmd->request_buffer;
 362         cmd->SCp.this_residual = cmd->request_bufflen;
 363         cmd->SCp.buffer = NULL;
 364     } else {
 365         cmd->SCp.buffer = cmd->request_buffer;
 366         cmd->SCp.buffers_residual = cmd->use_sg;
 367         cmd->SCp.ptr = cmd->SCp.buffer->address;
 368         cmd->SCp.this_residual = cmd->SCp.buffer->length;
 369     }
 370     cmd->SCp.Status = (cmd->SCp.this_residual != 0);  /* TRUE as long as bytes 
 371                                                        * are to transfer */ 
 372     
 373     if (eata_pio_send_command(base, EATA_CMD_PIO_SEND_CP)) 
 374     {
 375         cmd->result = DID_ERROR << 16;
 376         printk("eata_pio_queue target %d, pid %ld, HBA busy, returning "
 377                "DID_ERROR, done.\n", cmd->target, cmd->pid);
 378         restore_flags(flags);
 379         done(cmd);
 380         return (0);
 381     }
 382     while (!(inb(base + HA_RSTATUS) & HA_SDRQ));
 383     outsw(base + HA_RDATA, cp, hd->cplen);
 384     outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
 385     for (x = 0; x < hd->cppadlen; x++) outw(0, base + HA_RDATA);
 386     
 387     DBG(DBG_QUEUE,printk("Queued base %#.4lx pid: %ld target: %x lun: %x "
 388                          "slot %d irq %d\n", (long)sh->base, cmd->pid, 
 389                          cmd->target, cmd->lun, y, sh->irq));
 390     DBG(DBG_QUEUE && DBG_DELAY, DEL2(200));
 391     
 392     restore_flags(flags);
 393     return (0);
 394 }
 395 
 396 int eata_pio_abort(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 397 {
 398     ulong flags;
 399     uint loop = R_LIMIT;
 400     
 401     save_flags(flags);
 402     cli();
 403     
 404     DBG(DBG_ABNORM, printk("eata_pio_abort called pid: %ld target: %x lun: %x"
 405                            " reason %x\n", cmd->pid, cmd->target, cmd->lun, 
 406                            cmd->abort_reason));
 407     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 408     
 409     
 410     while (inb((uint)(cmd->host->base) + HA_RAUXSTAT) & HA_ABUSY)
 411         if (--loop == 0) {
 412             printk("eata_pio: abort, timeout error.\n");
 413             restore_flags(flags);
 414             DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 415             return (SCSI_ABORT_ERROR);
 416         }
 417     if (CD(cmd)->status == FREE) {
 418         DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_NOT_RUNNING\n")); 
 419         restore_flags(flags);
 420         return (SCSI_ABORT_NOT_RUNNING);
 421     }
 422     if (CD(cmd)->status == USED) {
 423         DBG(DBG_ABNORM, printk("Returning: SCSI_ABORT_BUSY\n"));
 424         restore_flags(flags);
 425         return (SCSI_ABORT_BUSY);  /* SNOOZE */ 
 426     }
 427     if (CD(cmd)->status == RESET) {
 428         restore_flags(flags);
 429         printk("eata_pio: abort, command reset error.\n");
 430         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 431         return (SCSI_ABORT_ERROR);
 432     }
 433     if (CD(cmd)->status == LOCKED) {
 434         restore_flags(flags);
 435         DBG(DBG_ABNORM, printk("eata_pio: abort, queue slot locked.\n"));
 436         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 437         return (SCSI_ABORT_NOT_RUNNING);
 438     } else
 439         panic("eata_pio: abort: invalid slot status\n");
 440 }
 441 
 442 int eata_pio_reset(Scsi_Cmnd * cmd)
     /* [previous][next][first][last][top][bottom][index][help] */
 443 {
 444     uint x, z, time, limit = 0;
 445     ulong flags;
 446     unchar success = FALSE;
 447     Scsi_Cmnd *sp; 
 448     
 449     save_flags(flags);
 450     cli();
 451     hprint("reset");
 452     DBG(DBG_ABNORM, printk("eata_pio_reset called pid:%ld target: %x lun: %x "
 453                            "reason %x\n", cmd->pid, cmd->target, cmd->lun, 
 454                            cmd->abort_reason));
 455 
 456     if (HD(cmd)->state == RESET) {
 457         printk("eata_pio_reset: exit, already in reset.\n");
 458         restore_flags(flags);
 459         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 460         return (SCSI_RESET_ERROR);
 461     }
 462     
 463     for (z = 0; z < MAXTARGET; z++) {
 464         HD(cmd)->t_state[0][z] = RESET;
 465         HD(cmd)->t_timeout[0][z] = NO_TIMEOUT;
 466     }
 467     
 468     /* force all slots to be free */
 469     
 470     for (x = 0; x < cmd->host->can_queue; x++) {
 471         
 472         if (HD(cmd)->ccb[x].status == FREE) 
 473             continue;
 474         
 475         sp = HD(cmd)->ccb[x].cmd;
 476         HD(cmd)->ccb[x].status = RESET;
 477         printk("eata_pio_reset: slot %d in reset, pid %ld.\n", x, sp->pid);
 478         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 479         
 480         if (sp == NULL)
 481             panic("eata_pio_reset: slot %d, sp==NULL.\n", x);
 482         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 483     }
 484     
 485     /* hard reset the HBA  */
 486     outb((uint) cmd->host->base+HA_WCOMMAND, EATA_CMD_RESET);
 487     
 488     DBG(DBG_ABNORM, printk("eata_pio_reset: board reset done.\n"));
 489     HD(cmd)->state = RESET;
 490     
 491     time = jiffies;
 492     while (jiffies < (time + (3 * HZ)) && limit++ < 10000000);
 493     
 494     DBG(DBG_ABNORM, printk("eata_pio_reset: interrupts disabled, loops %d.\n", limit));
 495     DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 496     
 497     for (x = 0; x < cmd->host->can_queue; x++) {
 498         
 499         /* Skip slots already set free by interrupt */
 500         if (HD(cmd)->ccb[x].status != RESET)
 501             continue;
 502         
 503         sp = HD(cmd)->ccb[x].cmd;
 504         sp->result = DID_RESET << 16;
 505         
 506         /* This mailbox is terminated */
 507         printk("eata_pio_reset: resetted ccb %d.\n",x);
 508         HD(cmd)->ccb[x].status = FREE;
 509         
 510         restore_flags(flags);
 511         sp->scsi_done(sp);
 512         cli();
 513     }
 514     
 515     HD(cmd)->state = FALSE;
 516     restore_flags(flags);
 517     
 518     if (success) { /* hmmm... */
 519         DBG(DBG_ABNORM, printk("eata_pio_reset: exit, success.\n"));
 520         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 521         return (SCSI_RESET_SUCCESS);
 522     } else {
 523         DBG(DBG_ABNORM, printk("eata_pio_reset: exit, wakeup.\n"));
 524         DBG(DBG_ABNORM && DBG_DELAY, DEL2(500));
 525         return (SCSI_RESET_PUNT);
 526     }
 527 }
 528 
 529 char * get_pio_board_data(ulong base, uint irq, uint id, ulong cplen, ushort cppadlen)
     /* [previous][next][first][last][top][bottom][index][help] */
 530 {
 531     struct eata_ccb cp;
 532     static char buff[256];
 533     int z;
 534     
 535     memset(&cp, 0, sizeof(struct eata_ccb));
 536     memset(buff, 0, sizeof(buff));
 537     
 538     cp.DataIn = TRUE;     
 539     cp.Interpret = TRUE;   /* Interpret command */
 540     
 541     cp.cp_datalen = htonl(254);  
 542     cp.cp_dataDMA = htonl(0);
 543     
 544     cp.cp_id = id;
 545     cp.cp_lun = 0;
 546     
 547     cp.cp_cdb[0] = INQUIRY;
 548     cp.cp_cdb[1] = 0;
 549     cp.cp_cdb[2] = 0;
 550     cp.cp_cdb[3] = 0;
 551     cp.cp_cdb[4] = 254;
 552     cp.cp_cdb[5] = 0;
 553     
 554     if (eata_pio_send_command((uint) base, EATA_CMD_PIO_SEND_CP)) 
 555         return (NULL);
 556     while (!(inb(base + HA_RSTATUS) & HA_SDRQ));
 557     outsw(base + HA_RDATA, &cp, cplen);
 558     outb(EATA_CMD_PIO_TRUNC, base + HA_WCOMMAND);
 559     for (z = 0; z < cppadlen; z++) outw(0, base + HA_RDATA);
 560     
 561     while (inb(base + HA_RSTATUS) & HA_SBUSY);
 562     if (inb(base + HA_RSTATUS) & HA_SERROR)
 563         return (NULL);
 564     else if (!(inb(base + HA_RSTATUS) & HA_SDRQ))
 565         return (NULL);
 566     else
 567     {
 568         insw(base+HA_RDATA, &buff, 127);
 569         while (inb(base + HA_RSTATUS)&HA_SDRQ) inw(base + HA_RDATA);
 570         return (buff);
 571     }
 572 }
 573 
 574 int get_pio_conf_PIO(u32 base, struct get_conf *buf)
     /* [previous][next][first][last][top][bottom][index][help] */
 575 {
 576     ulong loop = R_LIMIT;
 577     int z;
 578     ushort *p;
 579     
 580     if(check_region(base, 9))  
 581         return (FALSE);
 582     
 583     memset(buf, 0, sizeof(struct get_conf));
 584     
 585     while (inb(base + HA_RSTATUS) & HA_SBUSY)
 586         if (--loop == 0) 
 587             return (FALSE);
 588     
 589     DBG(DBG_PIO && DBG_PROBE,
 590         printk("Issuing PIO READ CONFIG to HBA at %#x\n", base));
 591     eata_pio_send_command(base, EATA_CMD_PIO_READ_CONFIG);
 592 
 593     loop = R_LIMIT;
 594     for (p = (ushort *) buf; 
 595          (long)p <= ((long)buf + (sizeof(struct get_conf) / 2)); p++) {
 596         while (!(inb(base + HA_RSTATUS) & HA_SDRQ))
 597             if (--loop == 0)
 598                 return (FALSE);
 599 
 600         loop = R_LIMIT;
 601         *p = inw(base + HA_RDATA);
 602     }
 603     if (!(inb(base + HA_RSTATUS) & HA_SERROR)) {            /* Error ? */
 604         if (htonl(EATA_SIGNATURE) == buf->signature) {
 605             DBG(DBG_PIO&&DBG_PROBE, printk("EATA Controller found at %#4x "
 606                                            "EATA Level: %x\n", base, 
 607                                            (uint) (buf->version)));
 608             
 609             while (inb(base + HA_RSTATUS) & HA_SDRQ) 
 610                 inw(base + HA_RDATA);
 611             if(ALLOW_DMA_BOARDS == FALSE) {
 612                 for (z = 0; z < MAXISA; z++)
 613                     if (base == ISAbases[z]) {
 614                         buf->IRQ = ISAirqs[z]; 
 615                         break;
 616                     }
 617             }
 618             return (TRUE);
 619         } 
 620     } else {
 621         DBG(DBG_PROBE, printk("eata_dma: get_conf_PIO, error during transfer "
 622                               "for HBA at %x\n", base));
 623     }
 624     return (FALSE);
 625 }
 626 
 627 void print_pio_config(struct get_conf *gc)
     /* [previous][next][first][last][top][bottom][index][help] */
 628 {
 629     printk("Please check values: (read config data)\n");
 630     printk("LEN: %d ver:%d OCS:%d TAR:%d TRNXFR:%d MORES:%d\n",
 631            (uint) ntohl(gc->len), gc->version,
 632            gc->OCS_enabled, gc->TAR_support, gc->TRNXFR, gc->MORE_support);
 633     printk("HAAV:%d SCSIID0:%d ID1:%d ID2:%d QUEUE:%d SG:%d SEC:%d\n",
 634            gc->HAA_valid, gc->scsi_id[3], gc->scsi_id[2],
 635            gc->scsi_id[1], ntohs(gc->queuesiz), ntohs(gc->SGsiz), gc->SECOND);
 636     printk("IRQ:%d IRQT:%d FORCADR:%d MCH:%d RIDQ:%d\n",
 637            gc->IRQ, gc->IRQ_TR, gc->FORCADR, 
 638            gc->MAX_CHAN, gc->ID_qest);
 639     DBG(DPT_DEBUG, DELAY(14));
 640 }
 641 
 642 static uint print_selftest(uint base)
     /* [previous][next][first][last][top][bottom][index][help] */
 643 {
 644     unchar buffer[512];
 645 #ifdef VERBOSE_SETUP
 646     int z;
 647 #endif
 648     
 649     printk("eata_pio: executing controller self test & setup...\n");
 650     while (inb(base + HA_RSTATUS) & HA_SBUSY);
 651     outb(EATA_CMD_PIO_SETUPTEST, base + HA_WCOMMAND);
 652     do {
 653         while (inb(base + HA_RSTATUS) & HA_SBUSY)
 654             /* nothing */ ;
 655         if (inb(base + HA_RSTATUS) & HA_SDRQ)
 656         {
 657             insw(base + HA_RDATA, &buffer, 256);
 658 #ifdef VERBOSE_SETUP
 659             /* no beeps please... */
 660             for (z = 0; z < 511 && buffer[z]; z++)
 661                 if (buffer[z] != 7) printk("%c", buffer[z]);
 662 #endif
 663         }
 664     } while (inb(base+HA_RSTATUS) & (HA_SBUSY|HA_SDRQ));
 665     
 666     return (!(inb(base+HA_RSTATUS) & HA_SERROR)); 
 667 }
 668 
 669 int register_pio_HBA(long base, struct get_conf *gc, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 670 {
 671     ulong size = 0;
 672     char *buff;
 673     ulong cplen;
 674     ushort cppadlen;
 675     struct Scsi_Host *sh;
 676     hostdata *hd;
 677     
 678     DBG(DBG_REGISTER, print_pio_config(gc));
 679     
 680     if (gc->DMA_support == TRUE) {
 681         printk("HBA at %#.4lx supports DMA. Please use EATA-DMA driver.\n",base);
 682         if(ALLOW_DMA_BOARDS == FALSE)
 683             return (FALSE);
 684     }
 685     
 686     if ((buff = get_pio_board_data((uint)base, gc->IRQ, gc->scsi_id[3], 
 687                                cplen   =(htonl(gc->cplen   )+1)/2, 
 688                                cppadlen=(htons(gc->cppadlen)+1)/2)) == NULL)
 689     {
 690         printk("HBA at %#lx didn't react on INQUIRY. Sorry.\n", (ulong) base);
 691         return (FALSE);
 692     }
 693     
 694     if (print_selftest(base) == FALSE && ALLOW_DMA_BOARDS == FALSE)
 695     {
 696         printk("HBA at %#lx failed while performing self test & setup.\n", 
 697                (ulong) base);
 698         return (FALSE);
 699     }
 700     
 701     if (!reg_IRQ[gc->IRQ]) {    /* Interrupt already registered ? */
 702         if (!request_irq(gc->IRQ, eata_pio_int_handler, SA_INTERRUPT, 
 703                          "EATA-PIO")){
 704             reg_IRQ[gc->IRQ]++;
 705             if (!gc->IRQ_TR)
 706                 reg_IRQL[gc->IRQ] = TRUE;   /* IRQ is edge triggered */
 707         } else {
 708             printk("Couldn't allocate IRQ %d, Sorry.", gc->IRQ);
 709             return (FALSE);
 710         }
 711     } else {            /* More than one HBA on this IRQ */
 712         if (reg_IRQL[gc->IRQ] == TRUE) {
 713             printk("Can't support more than one HBA on this IRQ,\n"
 714                    "  if the IRQ is edge triggered. Sorry.\n");
 715             return (FALSE);
 716         } else
 717             reg_IRQ[gc->IRQ]++;
 718     }
 719     
 720     request_region(base, 8, "eata_pio");
 721     
 722     size = sizeof(hostdata) + (sizeof(struct eata_ccb) * ntohs(gc->queuesiz));
 723     
 724     sh = scsi_register(tpnt, size);
 725     hd = SD(sh);                   
 726     
 727     memset(hd->ccb, 0, (sizeof(struct eata_ccb) * ntohs(gc->queuesiz)));
 728     memset(hd->reads, 0, sizeof(ulong) * 26); 
 729     
 730     strncpy(SD(sh)->vendor, &buff[8], 8);
 731     SD(sh)->vendor[8] = 0;
 732     strncpy(SD(sh)->name, &buff[16], 17);
 733     SD(sh)->name[17] = 0;
 734     SD(sh)->revision[0] = buff[32];
 735     SD(sh)->revision[1] = buff[33];
 736     SD(sh)->revision[2] = buff[34];
 737     SD(sh)->revision[3] = '.';
 738     SD(sh)->revision[4] = buff[35];
 739     SD(sh)->revision[5] = 0;
 740 
 741     switch (ntohl(gc->len)) {
 742     case 0x1c:
 743         SD(sh)->EATA_revision = 'a';
 744         break;
 745     case 0x1e:
 746         SD(sh)->EATA_revision = 'b';
 747         break;
 748     case 0x22:
 749         SD(sh)->EATA_revision = 'c';
 750         break;
 751     case 0x24:
 752         SD(sh)->EATA_revision = 'z';            
 753     default:
 754         SD(sh)->EATA_revision = '?';
 755     }
 756 
 757     if(ntohl(gc->len) >= 0x22) {
 758         if (gc->is_PCI == TRUE)
 759             hd->bustype = IS_PCI;
 760         else if (gc->is_EISA == TRUE)
 761             hd->bustype = IS_EISA;
 762         else
 763             hd->bustype = IS_ISA;
 764     } else {
 765         if (buff[21] == '4')
 766             hd->bustype = IS_PCI;
 767         else if (buff[21] == '2')
 768             hd->bustype = IS_EISA;
 769         else
 770             hd->bustype = IS_ISA;
 771     }
 772   
 773     SD(sh)->cplen=cplen;
 774     SD(sh)->cppadlen=cppadlen;
 775     SD(sh)->hostid=gc->scsi_id[3];
 776     SD(sh)->devflags=1<<gc->scsi_id[3];
 777     SD(sh)->moresupport=gc->MORE_support;
 778     sh->base = (char *) base;
 779     sh->io_port = (ushort) base;
 780     sh->n_io_port = 8;
 781     sh->irq = gc->IRQ;
 782     sh->dma_channel = 0xfe;  /* PIO */
 783     sh->this_id = gc->scsi_id[3];
 784     sh->can_queue = 1;
 785     sh->cmd_per_lun = 1;
 786     sh->sg_tablesize = SG_ALL;
 787     
 788     hd->channel = 0;
 789     
 790     sh->max_id = 8;
 791     sh->max_lun = 8;
 792 
 793     if (gc->SECOND)
 794         hd->primary = FALSE;
 795     else
 796         hd->primary = TRUE;
 797     
 798     sh->unchecked_isa_dma = FALSE; /* We can only do PIO */
 799     
 800     hd->next = NULL;    /* build a linked list of all HBAs */
 801     hd->prev = last_HBA;
 802     if(hd->prev != NULL)
 803         SD(hd->prev)->next = sh;
 804     last_HBA = sh;
 805     if (first_HBA == NULL)
 806         first_HBA = sh;
 807     registered_HBAs++;
 808     return (1);
 809 }
 810 
 811 void find_pio_ISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 812 {
 813     int i;
 814     
 815     for (i = 0; i < MAXISA; i++) {  
 816         if (ISAbases[i]) {  
 817             if (get_pio_conf_PIO(ISAbases[i], buf) == TRUE){
 818                 register_pio_HBA(ISAbases[i], buf, tpnt);
 819             }
 820             ISAbases[i] = 0;
 821         }
 822     }
 823     return;
 824 }
 825 
 826 void find_pio_EISA(struct get_conf *buf, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 827 {
 828     u32 base;
 829     int i;
 830 
 831 #if CHECKPAL
 832     u8 pal1, pal2, pal3;
 833 #endif
 834 
 835     for (i = 0; i < MAXEISA; i++) {
 836         if (EISAbases[i] == TRUE) { /* Still a possibility ?          */
 837 
 838             base = 0x1c88 + (i * 0x1000);
 839 #if CHECKPAL
 840             pal1 = inb((u16)base - 8);
 841             pal2 = inb((u16)base - 7);
 842             pal3 = inb((u16)base - 6);
 843 
 844             if (((pal1 == 0x12) && (pal2 == 0x14)) ||
 845                 ((pal1 == 0x38) && (pal2 == 0xa3) && (pal3 == 0x82)) ||
 846                 ((pal1 == 0x06) && (pal2 == 0x94) && (pal3 == 0x24))) {
 847                 DBG(DBG_PROBE, printk("EISA EATA id tags found: %x %x %x \n",
 848                                       (int)pal1, (int)pal2, (int)pal3));
 849 #endif
 850                 if (get_pio_conf_PIO(base, buf) == TRUE) {
 851                     DBG(DBG_PROBE && DBG_EISA, print_pio_config(buf));
 852                     if (buf->IRQ) {
 853                         register_pio_HBA(base, buf, tpnt);
 854                     } else
 855                         printk("eata_dma: No valid IRQ. HBA removed from list\n");
 856                 }
 857                 /* Nothing found here so we take it from the list */
 858                 EISAbases[i] = 0;
 859 #if CHECKPAL
 860             }
 861 #endif
 862         }
 863     }
 864     return;
 865 }
 866 
 867 void find_pio_PCI(struct get_conf *buf, Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 868 {
 869 
 870 #ifndef CONFIG_PCI
 871     printk("eata_pio: kernel PCI support not enabled. Skipping scan for PCI HBAs.\n");
 872 #else
 873     
 874     u8 pci_bus, pci_device_fn;
 875     static s16 pci_index = 0;   /* Device index to PCI BIOS calls */
 876     u32 base = 0;
 877     u16 com_adr;
 878     u16 rev_device;
 879     u32 error, i, x;
 880 
 881     if (pcibios_present()) {
 882         for (i = 0; i <= MAXPCI; ++i, ++pci_index) {
 883             if (pcibios_find_device(PCI_VENDOR_ID_DPT, PCI_DEVICE_ID_DPT, 
 884                                     pci_index, &pci_bus, &pci_device_fn))
 885                 break;
 886             DBG(DBG_PROBE && DBG_PCI, 
 887                 printk("eata_pio: HBA at bus %d, device %d,"
 888                        " function %d, index %d\n", (s32)pci_bus, 
 889                        (s32)((pci_device_fn & 0xf8) >> 3),
 890                        (s32)(pci_device_fn & 7), pci_index));
 891             
 892             if (!(error = pcibios_read_config_word(pci_bus, pci_device_fn, 
 893                                        PCI_CLASS_DEVICE, &rev_device))) {
 894                 if (rev_device == PCI_CLASS_STORAGE_SCSI) {
 895                     if (!(error = pcibios_read_config_word(pci_bus, 
 896                                                pci_device_fn, PCI_COMMAND, 
 897                                                (u16 *) & com_adr))) {
 898                         if (!((com_adr & PCI_COMMAND_IO) && 
 899                               (com_adr & PCI_COMMAND_MASTER))) {
 900                             printk("HBA has IO or BUSMASTER mode disabled\n");
 901                             continue;
 902                         }
 903                     } else
 904                         printk("eata_pio: error %x while reading "
 905                                "PCI_COMMAND\n", error);
 906                 } else
 907                     printk("DEVICECLASSID %x didn't match\n", rev_device);
 908             } else {
 909                 printk("eata_pio: error %x while reading PCI_CLASS_BASE\n", 
 910                        error);
 911                 continue;
 912             }
 913             
 914             if (!(error = pcibios_read_config_dword(pci_bus, pci_device_fn,
 915                                        PCI_BASE_ADDRESS_0, (int *) &base))){
 916                 
 917                 /* Check if the address is valid */
 918                 if (base & 0x01) {
 919                     base &= 0xfffffffe;
 920                     /* EISA tag there ? */
 921                     if ((inb(base) == 0x12) && (inb(base + 1) == 0x14))
 922                         continue;   /* Jep, it's forced, so move on  */
 923                     base += 0x10;   /* Now, THIS is the real address */
 924                     if (base != 0x1f8) {
 925                         /* We didn't find it in the primary search */
 926                         if (get_pio_conf_PIO(base, buf) == TRUE) {
 927                             if (buf->FORCADR)   /* If the address is forced */
 928                                 continue;       /* we'll find it later      */
 929                             
 930                             /* OK. We made it till here, so we can go now  
 931                              * and register it. We  only have to check and 
 932                              * eventually remove it from the EISA and ISA list 
 933                              */
 934                             
 935                             register_pio_HBA(base, buf, tpnt);
 936                             
 937                             if (base < 0x1000) {
 938                                 for (x = 0; x < MAXISA; ++x) {
 939                                     if (ISAbases[x] == base) {
 940                                         ISAbases[x] = 0;
 941                                         break;
 942                                     }
 943                                 }
 944                             } else if ((base & 0x0fff) == 0x0c88) {
 945                                 x = (base >> 12) & 0x0f;
 946                                 EISAbases[x] = 0;
 947                             }
 948                             continue;  /* break; */
 949                         }
 950                     }
 951                 }
 952             } else
 953                 printk("eata_pio: error %x while reading "
 954                        "PCI_BASE_ADDRESS_0\n", error);
 955         }
 956     } else
 957         printk("eata_pio: No BIOS32 extensions present. This driver release "
 958                "still depends on it.\n"
 959                "          Skipping scan for PCI HBAs.\n");
 960 #endif /* #ifndef CONFIG_PCI */
 961     return;
 962 }
 963 
 964 
 965 int eata_pio_detect(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 966 {
 967     struct Scsi_Host *HBA_ptr;
 968     struct get_conf gc;
 969     int i;
 970     
 971     DBG((DBG_PROBE && DBG_DELAY) || DPT_DEBUG,
 972         printk("Using lots of delays to let you read the debugging output\n"));
 973     
 974 
 975     find_pio_PCI(&gc, tpnt);
 976 
 977     find_pio_EISA(&gc, tpnt);
 978 
 979     find_pio_ISA(&gc, tpnt);
 980     
 981     for (i = 0; i <= MAXIRQ; i++)
 982         if (reg_IRQ[i])
 983             request_irq(i, eata_pio_int_handler, SA_INTERRUPT, "EATA-PIO");
 984     
 985     HBA_ptr = first_HBA;
 986   
 987     if (registered_HBAs != 0) {
 988         printk("EATA (Extended Attachment) PIO driver version: %d.%d%s\n"
 989                "(c) 1993-95 Michael Neuffer, neuffer@goofy.zdv.uni-mainz.de\n"
 990                "            Alfred Arnold,   a.arnold@kfa-juelich.de\n"
 991                "This release only supports DASD devices (harddisks)\n",
 992                VER_MAJOR, VER_MINOR, VER_SUB);
 993         
 994         printk("Registered HBAs:\n");
 995         printk("HBA no. Boardtype: Revis: EATA: Bus: BaseIO: IRQ: Ch: ID: Pr:"
 996                " QS: SG: CPL:\n");
 997         for (i = 1; i <= registered_HBAs; i++) {
 998             printk("scsi%-2d: %.10s v%s 2.0%c  %s %#.4x   %2d   %d   %d   %c"
 999                    "  %2d  %2d  %2d\n", 
1000                    HBA_ptr->host_no, SD(HBA_ptr)->name, SD(HBA_ptr)->revision,
1001                    SD(HBA_ptr)->EATA_revision, (SD(HBA_ptr)->bustype == 'P')?
1002                    "PCI ":(SD(HBA_ptr)->bustype == 'E')?"EISA":"ISA ",
1003                    (uint) HBA_ptr->base, HBA_ptr->irq, SD(HBA_ptr)->channel, 
1004                    HBA_ptr->this_id, (SD(HBA_ptr)->primary == TRUE)?'Y':'N', 
1005                    HBA_ptr->can_queue, HBA_ptr->sg_tablesize, 
1006                    HBA_ptr->cmd_per_lun);
1007             HBA_ptr = SD(HBA_ptr)->next;
1008         }
1009     }
1010     DBG(DPT_DEBUG,DELAY(12));
1011     
1012     return (registered_HBAs);
1013 }
1014 
1015 #ifdef MODULE
1016 /* Eventually this will go into an include file, but this will be later */
1017 Scsi_Host_Template driver_template = EATA_PIO;
1018 
1019 #include "scsi_module.c"
1020 #endif
1021 
1022 /*
1023  * Overrides for Emacs so that we almost follow Linus's tabbing style.
1024  * Emacs will notice this stuff at the end of the file and automatically
1025  * adjust the settings for this buffer only.  This must remain at the end
1026  * of the file.
1027  * ---------------------------------------------------------------------------
1028  * Local variables:
1029  * c-indent-level: 4
1030  * c-brace-imaginary-offset: 0
1031  * c-brace-offset: -4
1032  * c-argdecl-indent: 4
1033  * c-label-offset: -4
1034  * c-continued-statement-offset: 4
1035  * c-continued-brace-offset: 0
1036  * indent-tabs-mode: nil
1037  * tab-width: 8
1038  * End:
1039  */

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