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

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