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

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