root/drivers/scsi/aha1542.c

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

DEFINITIONS

This source file includes following definitions.
  1. aha1542_stat
  2. aha1542_out
  3. aha1542_in
  4. aha1542_in1
  5. makecode
  6. aha1542_test_port
  7. aha1542_intr_handle
  8. aha1542_queuecommand
  9. internal_done
  10. aha1542_command
  11. setup_mailboxes
  12. aha1542_getconfig
  13. aha1542_mbenable
  14. aha1542_query
  15. aha1542_setup
  16. aha1542_detect
  17. aha1542_restart
  18. aha1542_abort
  19. aha1542_reset
  20. aha1542_biosparam

   1 /* $Id: aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $
   2  *  linux/kernel/aha1542.c
   3  *
   4  *  Copyright (C) 1992  Tommy Thorn
   5  *  Copyright (C) 1993, 1994 Eric Youngdale
   6  *
   7  *  Modified by Eric Youngdale
   8  *        Use request_irq and request_dma to help prevent unexpected conflicts
   9  *        Set up on-board DMA controller, such that we do not have to
  10  *        have the bios enabled to use the aha1542.
  11  *  Modified by David Gentzel
  12  *        Don't call request_dma if dma mask is 0 (for BusLogic BT-445S VL-Bus controller).
  13  *  Modified by Matti Aarnio
  14  *        Accept parameters from LILO cmd-line. -- 1-Oct-94
  15  */
  16 
  17 #include <linux/kernel.h>
  18 #include <linux/head.h>
  19 #include <linux/types.h>
  20 #include <linux/string.h>
  21 #include <linux/ioport.h>
  22 
  23 #include <linux/delay.h>
  24 
  25 #include <linux/sched.h>
  26 #include <asm/dma.h>
  27 
  28 #include <asm/system.h>
  29 #include <asm/io.h>
  30 #include "../block/blk.h"
  31 #include "scsi.h"
  32 #include "hosts.h"
  33 
  34 #include "aha1542.h"
  35 
  36 #ifdef DEBUG
  37 #define DEB(x) x
  38 #else
  39 #define DEB(x)
  40 #endif
  41 /*
  42 static const char RCSid[] = "$Header: /usr/src/linux/kernel/blk_drv/scsi/RCS/aha1542.c,v 1.1 1992/07/24 06:27:38 root Exp root $";
  43 */
  44 
  45 /* The adaptec can be configured for quite a number of addresses, but
  46 I generally do not want the card poking around at random.  We allow
  47 two addresses - this allows people to use the Adaptec with a Midi
  48 card, which also used 0x330 -- can be overriden with LILO! */
  49 
  50 #define MAXBOARDS 2     /* Increase this and the sizes of the
  51                            arrays below, if you need more.. */
  52 
  53 static unsigned int bases[MAXBOARDS]={0x330, 0x334};
  54 
  55 /* set by aha1542_setup according to the command line */
  56 static int setup_called[MAXBOARDS]   = {0,0};
  57 static int setup_buson[MAXBOARDS]    = {0,0};
  58 static int setup_busoff[MAXBOARDS]   = {0,0};
  59 static int setup_dmaspeed[MAXBOARDS] = {-1,-1};
  60 
  61 static char *setup_str[MAXBOARDS] = {(char *)NULL,(char *)NULL};
  62 
  63 /*
  64  * LILO params:  aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]
  65  *
  66  * Where:  <PORTBASE> is any of the valid AHA addresses:
  67  *                      0x130, 0x134, 0x230, 0x234, 0x330, 0x334
  68  *         <BUSON>  is the time (in microsecs) that AHA spends on the AT-bus
  69  *                  when transferring data.  1542A power-on default is 11us,
  70  *                  valid values are in range: 2..15 (decimal)
  71  *         <BUSOFF> is the time that AHA spends OFF THE BUS after while
  72  *                  it is transferring data (not to monopolize the bus).
  73  *                  Power-on default is 4us, valid range: 1..64 microseconds.
  74  *         <DMASPEED> Default is jumper selected (1542A: on the J1),
  75  *                  but experimenter can alter it with this.
  76  *                  Valid values: 5, 6, 7, 8, 10 (MB/s)
  77  *                  Factory default is 5 MB/s.
  78  */
  79 
  80 
  81 /* The DMA-Controller.  We need to fool with this because we want to 
  82    be able to use the aha1542 without having to have the bios enabled */
  83 #define DMA_MODE_REG    0xd6
  84 #define DMA_MASK_REG    0xd4
  85 #define CASCADE         0xc0
  86 
  87 #define BIOS_TRANSLATION_1632 0  /* Used by some old 1542A boards */
  88 #define BIOS_TRANSLATION_6432 1 /* Default case these days */
  89 #define BIOS_TRANSLATION_25563 2 /* Big disk case */
  90 
  91 struct aha1542_hostdata{
  92         /* This will effectively start both of them at the first mailbox */
  93         int bios_translation;   /* Mapping bios uses - for compatibility */
  94         int aha1542_last_mbi_used;
  95         int aha1542_last_mbo_used;
  96         Scsi_Cmnd * SCint[AHA1542_MAILBOXES];
  97         struct mailbox mb[2*AHA1542_MAILBOXES];
  98         struct ccb ccb[AHA1542_MAILBOXES];
  99 };
 100 
 101 #define HOSTDATA(host) ((struct aha1542_hostdata *) &host->hostdata)
 102 
 103 static struct Scsi_Host * aha_host[7] = {NULL,};  /* One for each IRQ level (9-15) */
 104 
 105 
 106 
 107 
 108 #define WAITnexttimeout 3000000
 109 
 110 static void setup_mailboxes(int base_io, struct Scsi_Host * shpnt);
 111 static int aha1542_restart(struct Scsi_Host * shost);
 112 
 113 #define aha1542_intr_reset(base)  outb(IRST, CONTROL(base))
 114 
 115 #define WAIT(port, mask, allof, noneof)                                 \
 116  { register WAITbits;                                                   \
 117    register WAITtimeout = WAITnexttimeout;                              \
 118    while (1) {                                                          \
 119      WAITbits = inb(port) & (mask);                                     \
 120      if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
 121        break;                                                           \
 122      if (--WAITtimeout == 0) goto fail;                                 \
 123    }                                                                    \
 124  }
 125 
 126 /* Similar to WAIT, except we use the udelay call to regulate the
 127    amount of time we wait.  */
 128 #define WAITd(port, mask, allof, noneof, timeout)                       \
 129  { register WAITbits;                                                   \
 130    register WAITtimeout = timeout;                                      \
 131    while (1) {                                                          \
 132      WAITbits = inb(port) & (mask);                                     \
 133      if ((WAITbits & (allof)) == (allof) && ((WAITbits & (noneof)) == 0)) \
 134        break;                                                           \
 135      udelay(1000);                                                      \
 136      if (--WAITtimeout == 0) goto fail;                                 \
 137    }                                                                    \
 138  }
 139 
 140 static void aha1542_stat(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 141 {
 142 /*    int s = inb(STATUS), i = inb(INTRFLAGS);
 143   printk("status=%x intrflags=%x\n", s, i, WAITnexttimeout-WAITtimeout); */
 144 }
 145 
 146 /* This is a bit complicated, but we need to make sure that an interrupt
 147    routine does not send something out while we are in the middle of this.
 148    Fortunately, it is only at boot time that multi-byte messages
 149    are ever sent. */
 150 static int aha1542_out(unsigned int base, unchar *cmdp, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 151 {
 152   if(len == 1) {
 153     while(1==1){
 154         WAIT(STATUS(base), CDF, 0, CDF);
 155         cli();
 156         if(inb(STATUS(base)) & CDF) {sti(); continue;}
 157         outb(*cmdp, DATA(base));
 158         sti();
 159         return 0;
 160       }
 161   } else {
 162     cli();
 163     while (len--)
 164       {
 165         WAIT(STATUS(base), CDF, 0, CDF);
 166         outb(*cmdp++, DATA(base));
 167       }
 168     sti();
 169   }
 170     return 0;
 171   fail:
 172   sti();
 173     printk("aha1542_out failed(%d): ", len+1); aha1542_stat();
 174     return 1;
 175 }
 176 
 177 /* Only used at boot time, so we do not need to worry about latency as much
 178    here */
 179 static int aha1542_in(unsigned int base, unchar *cmdp, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 180 {
 181     cli();
 182     while (len--)
 183       {
 184           WAIT(STATUS(base), DF, DF, 0);
 185           *cmdp++ = inb(DATA(base));
 186       }
 187     sti();
 188     return 0;
 189   fail:
 190     sti();
 191     printk("aha1542_in failed(%d): ", len+1); aha1542_stat();
 192     return 1;
 193 }
 194 
 195 /* Similar to aha1542_in, except that we wait a very short period of time.
 196    We use this if we know the board is alive and awake, but we are not sure
 197    if the board will respond the the command we are about to send or not */
 198 static int aha1542_in1(unsigned int base, unchar *cmdp, int len)
     /* [previous][next][first][last][top][bottom][index][help] */
 199 {
 200     cli();
 201     while (len--)
 202       {
 203           WAITd(STATUS(base), DF, DF, 0, 100);
 204           *cmdp++ = inb(DATA(base));
 205       }
 206     sti();
 207     return 0;
 208   fail:
 209     sti();
 210     return 1;
 211 }
 212 
 213 static int makecode(unsigned hosterr, unsigned scsierr)
     /* [previous][next][first][last][top][bottom][index][help] */
 214 {
 215     switch (hosterr) {
 216       case 0x0:
 217       case 0xa: /* Linked command complete without error and linked normally */
 218       case 0xb: /* Linked command complete without error, interrupt generated */
 219         hosterr = 0;
 220         break;
 221 
 222       case 0x11: /* Selection time out-The initiator selection or target
 223                     reselection was not complete within the SCSI Time out period */
 224         hosterr = DID_TIME_OUT;
 225         break;
 226 
 227       case 0x12: /* Data overrun/underrun-The target attempted to transfer more data
 228                     than was allocated by the Data Length field or the sum of the
 229                     Scatter / Gather Data Length fields. */
 230 
 231       case 0x13: /* Unexpected bus free-The target dropped the SCSI BSY at an unexpected time. */
 232 
 233       case 0x15: /* MBO command was not 00, 01 or 02-The first byte of the CB was
 234                     invalid. This usually indicates a software failure. */
 235 
 236       case 0x16: /* Invalid CCB Operation Code-The first byte of the CCB was invalid.
 237                     This usually indicates a software failure. */
 238 
 239       case 0x17: /* Linked CCB does not have the same LUN-A subsequent CCB of a set
 240                     of linked CCB's does not specify the same logical unit number as
 241                     the first. */
 242       case 0x18: /* Invalid Target Direction received from Host-The direction of a
 243                     Target Mode CCB was invalid. */
 244 
 245       case 0x19: /* Duplicate CCB Received in Target Mode-More than once CCB was
 246                     received to service data transfer between the same target LUN
 247                     and initiator SCSI ID in the same direction. */
 248 
 249       case 0x1a: /* Invalid CCB or Segment List Parameter-A segment list with a zero
 250                     length segment or invalid segment list boundaries was received.
 251                     A CCB parameter was invalid. */
 252         DEB(printk("Aha1542: %x %x\n", hosterr, scsierr));
 253         hosterr = DID_ERROR; /* Couldn't find any better */
 254         break;
 255 
 256       case 0x14: /* Target bus phase sequence failure-An invalid bus phase or bus
 257                     phase sequence was requested by the target. The host adapter
 258                     will generate a SCSI Reset Condition, notifying the host with
 259                     a SCRD interrupt */
 260         hosterr = DID_RESET;
 261         break;
 262       default:
 263         printk("makecode: unknown hoststatus %x\n", hosterr);
 264         break;
 265     }
 266     return scsierr|(hosterr << 16);
 267 }
 268 
 269 static int aha1542_test_port(int bse, struct Scsi_Host * shpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 270 {
 271     int i;
 272     unchar inquiry_cmd[] = {CMD_INQUIRY };
 273     unchar inquiry_result[4];
 274     unchar *cmdp;
 275     int len;
 276     volatile int debug = 0;
 277     
 278     /* Quick and dirty test for presence of the card. */
 279     if(inb(STATUS(bse)) == 0xff) return 0;
 280 
 281     /* Reset the adapter. I ought to make a hard reset, but it's not really necessary */
 282     
 283     /*  DEB(printk("aha1542_test_port called \n")); */
 284 
 285     /* In case some other card was probing here, reset interrupts */
 286     aha1542_intr_reset(bse);     /* reset interrupts, so they don't block */    
 287 
 288     outb(SRST|IRST/*|SCRST*/, CONTROL(bse));
 289 
 290     i = jiffies + 2;
 291     while (i>jiffies); /* Wait a little bit for things to settle down. */
 292     
 293     debug = 1;
 294     /* Expect INIT and IDLE, any of the others are bad */
 295     WAIT(STATUS(bse), STATMASK, INIT|IDLE, STST|DIAGF|INVDCMD|DF|CDF);
 296     
 297     debug = 2;
 298     /* Shouldn't have generated any interrupts during reset */
 299     if (inb(INTRFLAGS(bse))&INTRMASK) goto fail;
 300 
 301 
 302     /* Perform a host adapter inquiry instead so we do not need to set
 303        up the mailboxes ahead of time */
 304 
 305     aha1542_out(bse, inquiry_cmd, 1);
 306 
 307     debug = 3;
 308     len = 4;
 309     cmdp = &inquiry_result[0];
 310 
 311     while (len--)
 312       {
 313           WAIT(STATUS(bse), DF, DF, 0);
 314           *cmdp++ = inb(DATA(bse));
 315       }
 316     
 317     debug = 8;
 318     /* Reading port should reset DF */
 319     if (inb(STATUS(bse)) & DF) goto fail;
 320     
 321     debug = 9;
 322     /* When HACC, command is completed, and we're though testing */
 323     WAIT(INTRFLAGS(bse), HACC, HACC, 0);
 324     /* now initialize adapter */
 325     
 326     debug = 10;
 327     /* Clear interrupts */
 328     outb(IRST, CONTROL(bse));
 329     
 330     debug = 11;
 331 
 332     return debug;                               /* 1 = ok */
 333   fail:
 334     return 0;                                   /* 0 = not ok */
 335 }
 336 
 337 /* A "high" level interrupt handler */
 338 static void aha1542_intr_handle(int foo)
     /* [previous][next][first][last][top][bottom][index][help] */
 339 {
 340     void (*my_done)(Scsi_Cmnd *) = NULL;
 341     int errstatus, mbi, mbo, mbistatus;
 342     int number_serviced;
 343     struct Scsi_Host * shost;
 344     Scsi_Cmnd * SCtmp;
 345     int irqno, * irqp, flag;
 346     int needs_restart;
 347     struct mailbox * mb;
 348     struct ccb  *ccb;
 349 
 350     irqp = (int *) foo;
 351     irqp -= 2;  /* Magic - this is only required for slow interrupt handlers */
 352     irqno = *irqp;
 353 
 354     shost = aha_host[irqno - 9];
 355     if(!shost) panic("Splunge!");
 356 
 357     mb = HOSTDATA(shost)->mb;
 358     ccb = HOSTDATA(shost)->ccb;
 359 
 360 #ifdef DEBUG
 361     {
 362     flag = inb(INTRFLAGS(shost->io_port));
 363     printk("aha1542_intr_handle: ");
 364     if (!(flag&ANYINTR)) printk("no interrupt?");
 365     if (flag&MBIF) printk("MBIF ");
 366     if (flag&MBOA) printk("MBOF ");
 367     if (flag&HACC) printk("HACC ");
 368     if (flag&SCRD) printk("SCRD ");
 369     printk("status %02x\n", inb(STATUS(shost->io_port)));
 370   };
 371 #endif
 372     number_serviced = 0;
 373     needs_restart = 0;
 374 
 375     while(1==1){
 376       flag = inb(INTRFLAGS(shost->io_port));
 377 
 378       /* Check for unusual interrupts.  If any of these happen, we should
 379          probably do something special, but for now just printing a message
 380          is sufficient.  A SCSI reset detected is something that we really
 381          need to deal with in some way. */
 382       if (flag & ~MBIF) {
 383         if (flag&MBOA) printk("MBOF ");
 384         if (flag&HACC) printk("HACC ");
 385         if (flag&SCRD) {
 386           needs_restart = 1;
 387           printk("SCRD ");
 388         }
 389       }
 390 
 391       aha1542_intr_reset(shost->io_port);
 392 
 393       cli();
 394       mbi = HOSTDATA(shost)->aha1542_last_mbi_used + 1;
 395       if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
 396       
 397       do{
 398         if(mb[mbi].status != 0) break;
 399         mbi++;
 400         if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
 401       } while (mbi != HOSTDATA(shost)->aha1542_last_mbi_used);
 402       
 403       if(mb[mbi].status == 0){
 404         sti();
 405         /* Hmm, no mail.  Must have read it the last time around */
 406         if (!number_serviced && !needs_restart)
 407           printk("aha1542.c: interrupt received, but no mail.\n");
 408         /* We detected a reset.  Restart all pending commands for
 409            devices that use the hard reset option */
 410         if(needs_restart) aha1542_restart(shost);
 411         return;
 412       };
 413 
 414       mbo = (scsi2int(mb[mbi].ccbptr) - ((unsigned int) &ccb[0])) / sizeof(struct ccb);
 415       mbistatus = mb[mbi].status;
 416       mb[mbi].status = 0;
 417       HOSTDATA(shost)->aha1542_last_mbi_used = mbi;
 418       sti();
 419       
 420 #ifdef DEBUG
 421       {
 422         if (ccb[mbo].tarstat|ccb[mbo].hastat)
 423           printk("aha1542_command: returning %x (status %d)\n", 
 424                  ccb[mbo].tarstat + ((int) ccb[mbo].hastat << 16), mb[mbi].status);
 425       };
 426 #endif
 427 
 428       if(mbistatus == 3) continue; /* Aborted command not found */
 429 
 430 #ifdef DEBUG
 431       printk("...done %d %d\n",mbo, mbi);
 432 #endif
 433       
 434       SCtmp = HOSTDATA(shost)->SCint[mbo];
 435 
 436       if (!SCtmp || !SCtmp->scsi_done) {
 437         printk("aha1542_intr_handle: Unexpected interrupt\n");
 438         printk("tarstat=%x, hastat=%x idlun=%x ccb#=%d \n", ccb[mbo].tarstat, 
 439                ccb[mbo].hastat, ccb[mbo].idlun, mbo);
 440         return;
 441       }
 442       
 443       my_done = SCtmp->scsi_done;
 444       if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);
 445       
 446       /* Fetch the sense data, and tuck it away, in the required slot.  The
 447          Adaptec automatically fetches it, and there is no guarantee that
 448          we will still have it in the cdb when we come back */
 449       if (ccb[mbo].tarstat == 2)
 450         memcpy(SCtmp->sense_buffer, &ccb[mbo].cdb[ccb[mbo].cdblen], 
 451                sizeof(SCtmp->sense_buffer));
 452       
 453       
 454       /* is there mail :-) */
 455       
 456       /* more error checking left out here */
 457       if (mbistatus != 1)
 458         /* This is surely wrong, but I don't know what's right */
 459         errstatus = makecode(ccb[mbo].hastat, ccb[mbo].tarstat);
 460       else
 461         errstatus = 0;
 462       
 463 #ifdef DEBUG
 464       if(errstatus) printk("(aha1542 error:%x %x %x) ",errstatus, 
 465                            ccb[mbo].hastat, ccb[mbo].tarstat);
 466 #endif
 467 
 468       if (ccb[mbo].tarstat == 2) {
 469 #ifdef DEBUG
 470         int i;
 471 #endif
 472         DEB(printk("aha1542_intr_handle: sense:"));
 473 #ifdef DEBUG
 474         for (i = 0; i < 12; i++)
 475           printk("%02x ", ccb[mbo].cdb[ccb[mbo].cdblen+i]);
 476         printk("\n");
 477 #endif
 478         /*
 479           DEB(printk("aha1542_intr_handle: buf:"));
 480           for (i = 0; i < bufflen; i++)
 481           printk("%02x ", ((unchar *)buff)[i]);
 482           printk("\n");
 483           */
 484       }
 485       DEB(if (errstatus) printk("aha1542_intr_handle: returning %6x\n", errstatus));
 486       SCtmp->result = errstatus;
 487       HOSTDATA(shost)->SCint[mbo] = NULL;  /* This effectively frees up the mailbox slot, as
 488                              far as queuecommand is concerned */
 489       my_done(SCtmp);
 490       number_serviced++;
 491     };
 492 }
 493 
 494 int aha1542_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
     /* [previous][next][first][last][top][bottom][index][help] */
 495 {
 496     unchar ahacmd = CMD_START_SCSI;
 497     unchar direction;
 498     unchar *cmd = (unchar *) SCpnt->cmnd;
 499     unchar target = SCpnt->target;
 500     unchar lun = SCpnt->lun;
 501     void *buff = SCpnt->request_buffer;
 502     int bufflen = SCpnt->request_bufflen;
 503     int mbo;
 504     struct mailbox * mb;
 505     struct ccb  *ccb;
 506 
 507     DEB(int i);
 508 
 509     mb = HOSTDATA(SCpnt->host)->mb;
 510     ccb = HOSTDATA(SCpnt->host)->ccb;
 511 
 512     DEB(if (target > 1) {
 513       SCpnt->result = DID_TIME_OUT << 16;
 514       done(SCpnt); return 0;});
 515     
 516     if(*cmd == REQUEST_SENSE){
 517 #ifndef DEBUG
 518       if (bufflen != sizeof(SCpnt->sense_buffer)) {
 519         printk("Wrong buffer length supplied for request sense (%d)\n",bufflen);
 520       };
 521 #endif
 522       SCpnt->result = 0;
 523       done(SCpnt); 
 524       return 0;
 525     };
 526 
 527 #ifdef DEBUG
 528     if (*cmd == READ_10 || *cmd == WRITE_10)
 529       i = xscsi2int(cmd+2);
 530     else if (*cmd == READ_6 || *cmd == WRITE_6)
 531       i = scsi2int(cmd+2);
 532     else
 533       i = -1;
 534     if (done)
 535       printk("aha1542_queuecommand: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
 536     else
 537       printk("aha1542_command: dev %d cmd %02x pos %d len %d ", target, *cmd, i, bufflen);
 538     aha1542_stat();
 539     printk("aha1542_queuecommand: dumping scsi cmd:");
 540     for (i = 0; i < SCpnt->cmd_len; i++) printk("%02x ", cmd[i]);
 541     printk("\n");
 542     if (*cmd == WRITE_10 || *cmd == WRITE_6)
 543       return 0; /* we are still testing, so *don't* write */
 544 #endif
 545 /* Use the outgoing mailboxes in a round-robin fashion, because this
 546    is how the host adapter will scan for them */
 547 
 548     cli();
 549     mbo = HOSTDATA(SCpnt->host)->aha1542_last_mbo_used + 1;
 550     if (mbo >= AHA1542_MAILBOXES) mbo = 0;
 551 
 552     do{
 553       if(mb[mbo].status == 0 && HOSTDATA(SCpnt->host)->SCint[mbo] == NULL)
 554         break;
 555       mbo++;
 556       if (mbo >= AHA1542_MAILBOXES) mbo = 0;
 557     } while (mbo != HOSTDATA(SCpnt->host)->aha1542_last_mbo_used);
 558 
 559     if(mb[mbo].status || HOSTDATA(SCpnt->host)->SCint[mbo])
 560       panic("Unable to find empty mailbox for aha1542.\n");
 561 
 562     HOSTDATA(SCpnt->host)->SCint[mbo] = SCpnt;  /* This will effectively prevent someone else from
 563                             screwing with this cdb. */
 564 
 565     HOSTDATA(SCpnt->host)->aha1542_last_mbo_used = mbo;    
 566     sti();
 567 
 568 #ifdef DEBUG
 569     printk("Sending command (%d %x)...",mbo, done);
 570 #endif
 571 
 572     any2scsi(mb[mbo].ccbptr, &ccb[mbo]); /* This gets trashed for some reason*/
 573 
 574     memset(&ccb[mbo], 0, sizeof(struct ccb));
 575 
 576     ccb[mbo].cdblen = SCpnt->cmd_len;
 577 
 578     direction = 0;
 579     if (*cmd == READ_10 || *cmd == READ_6)
 580         direction = 8;
 581     else if (*cmd == WRITE_10 || *cmd == WRITE_6)
 582         direction = 16;
 583 
 584     memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);
 585 
 586     if (SCpnt->use_sg) {
 587       struct scatterlist * sgpnt;
 588       struct chain * cptr;
 589 #ifdef DEBUG
 590       unsigned char * ptr;
 591 #endif
 592       int i;
 593       ccb[mbo].op = 2;        /* SCSI Initiator Command  w/scatter-gather*/
 594       SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
 595       sgpnt = (struct scatterlist *) SCpnt->request_buffer;
 596       cptr = (struct chain *) SCpnt->host_scribble; 
 597       if (cptr == NULL) panic("aha1542.c: unable to allocate DMA memory\n");
 598       for(i=0; i<SCpnt->use_sg; i++) {
 599         if(sgpnt[i].length == 0 || SCpnt->use_sg > 16 || 
 600            (((int)sgpnt[i].address) & 1) || (sgpnt[i].length & 1)){
 601           unsigned char * ptr;
 602           printk("Bad segment list supplied to aha1542.c (%d, %d)\n",SCpnt->use_sg,i);
 603           for(i=0;i<SCpnt->use_sg;i++){
 604             printk("%d: %x %x %d\n",i,(unsigned int) sgpnt[i].address, (unsigned int) sgpnt[i].alt_address,
 605                    sgpnt[i].length);
 606           };
 607           printk("cptr %x: ",(unsigned int) cptr);
 608           ptr = (unsigned char *) &cptr[i];
 609           for(i=0;i<18;i++) printk("%02x ", ptr[i]);
 610           panic("Foooooooood fight!");
 611         };
 612         any2scsi(cptr[i].dataptr, sgpnt[i].address);
 613         if(((unsigned  int) sgpnt[i].address) & 0xff000000) goto baddma;
 614         any2scsi(cptr[i].datalen, sgpnt[i].length);
 615       };
 616       any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
 617       any2scsi(ccb[mbo].dataptr, cptr);
 618 #ifdef DEBUG
 619       printk("cptr %x: ",cptr);
 620       ptr = (unsigned char *) cptr;
 621       for(i=0;i<18;i++) printk("%02x ", ptr[i]);
 622 #endif
 623     } else {
 624       ccb[mbo].op = 0;        /* SCSI Initiator Command */
 625       SCpnt->host_scribble = NULL;
 626       any2scsi(ccb[mbo].datalen, bufflen);
 627       if(((unsigned int) buff & 0xff000000)) goto baddma;
 628       any2scsi(ccb[mbo].dataptr, buff);
 629     };
 630     ccb[mbo].idlun = (target&7)<<5 | direction | (lun & 7); /*SCSI Target Id*/
 631     ccb[mbo].rsalen = 12;
 632     ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
 633     ccb[mbo].commlinkid = 0;
 634 
 635 #ifdef DEBUG
 636     { int i;
 637     printk("aha1542_command: sending.. ");
 638     for (i = 0; i < sizeof(ccb[mbo])-10; i++)
 639       printk("%02x ", ((unchar *)&ccb[mbo])[i]);
 640     };
 641 #endif
 642     
 643     if (done) {
 644         DEB(printk("aha1542_queuecommand: now waiting for interrupt "); aha1542_stat());
 645         SCpnt->scsi_done = done;
 646         mb[mbo].status = 1;
 647         aha1542_out(SCpnt->host->io_port, &ahacmd, 1);          /* start scsi command */
 648         DEB(aha1542_stat());
 649     }
 650     else
 651       printk("aha1542_queuecommand: done can't be NULL\n");
 652     
 653     return 0;
 654  baddma:
 655     panic("Buffer at address  > 16Mb used for 1542B");
 656 }
 657 
 658 static void internal_done(Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 659 {
 660         SCpnt->SCp.Status++;
 661 }
 662 
 663 int aha1542_command(Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 664 {
 665     DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));
 666 
 667     aha1542_queuecommand(SCpnt, internal_done);
 668 
 669     SCpnt->SCp.Status = 0;
 670     while (!SCpnt->SCp.Status);
 671     return SCpnt->result;
 672 }
 673 
 674 /* Initialize mailboxes */
 675 static void setup_mailboxes(int bse, struct Scsi_Host * shpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 676 {
 677     int i;
 678     struct mailbox * mb;
 679     struct ccb  *ccb;
 680 
 681     unchar cmd[5] = {CMD_MBINIT, AHA1542_MAILBOXES, 0, 0, 0};
 682 
 683     mb = HOSTDATA(shpnt)->mb;
 684     ccb = HOSTDATA(shpnt)->ccb;
 685 
 686     for(i=0; i<AHA1542_MAILBOXES; i++){
 687       mb[i].status = mb[AHA1542_MAILBOXES+i].status = 0;
 688       any2scsi(mb[i].ccbptr, &ccb[i]);
 689     };
 690     aha1542_intr_reset(bse);     /* reset interrupts, so they don't block */    
 691     any2scsi((cmd+2), mb);
 692     aha1542_out(bse, cmd, 5);
 693     WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
 694     while (0) {
 695       fail:
 696         printk("aha1542_detect: failed setting up mailboxes\n");
 697     }
 698     aha1542_intr_reset(bse);
 699 }
 700 
 701 static int aha1542_getconfig(int base_io, unsigned char * irq_level, unsigned char * dma_chan)
     /* [previous][next][first][last][top][bottom][index][help] */
 702 {
 703   unchar inquiry_cmd[] = {CMD_RETCONF };
 704   unchar inquiry_result[3];
 705   int i;
 706   i = inb(STATUS(base_io));
 707   if (i & DF) {
 708     i = inb(DATA(base_io));
 709   };
 710   aha1542_out(base_io, inquiry_cmd, 1);
 711   aha1542_in(base_io, inquiry_result, 3);
 712   WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
 713   while (0) {
 714   fail:
 715     printk("aha1542_detect: query board settings\n");
 716   }
 717   aha1542_intr_reset(base_io);
 718   switch(inquiry_result[0]){
 719   case 0x80:
 720     *dma_chan = 7;
 721     break;
 722   case 0x40:
 723     *dma_chan = 6;
 724     break;
 725   case 0x20:
 726     *dma_chan = 5;
 727     break;
 728   case 0x01:
 729     printk("DMA priority 0 not available for Adaptec driver\n");
 730     return -1;
 731   case 0:
 732     /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
 733        Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
 734     *dma_chan = 0xFF;
 735     break;
 736   default:
 737     printk("Unable to determine Adaptec DMA priority.  Disabling board\n");
 738     return -1;
 739   };
 740   switch(inquiry_result[1]){
 741   case 0x40:
 742     *irq_level = 15;
 743     break;
 744   case 0x20:
 745     *irq_level = 14;
 746     break;
 747   case 0x8:
 748     *irq_level = 12;
 749     break;
 750   case 0x4:
 751     *irq_level = 11;
 752     break;
 753   case 0x2:
 754     *irq_level = 10;
 755     break;
 756   case 0x1:
 757     *irq_level = 9;
 758     break;
 759   default:
 760     printk("Unable to determine Adaptec IRQ level.  Disabling board\n");
 761     return -1;
 762   };
 763   return 0;
 764 }
 765 
 766 /* This function should only be called for 1542C boards - we can detect
 767    the special firmware settings and unlock the board */
 768 
 769 static int aha1542_mbenable(int base)
     /* [previous][next][first][last][top][bottom][index][help] */
 770 {
 771   static unchar mbenable_cmd[3];
 772   static unchar mbenable_result[2];
 773   int retval;
 774   
 775   retval = BIOS_TRANSLATION_6432;
 776 
 777   mbenable_cmd[0]=CMD_EXTBIOS;
 778   aha1542_out(base,mbenable_cmd,1);
 779   if(aha1542_in1(base,mbenable_result,2))
 780     return retval;
 781   WAITd(INTRFLAGS(base),INTRMASK,HACC,0,100);
 782   aha1542_intr_reset(base);
 783   
 784   if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
 785      mbenable_cmd[0]=CMD_MBENABLE;
 786      mbenable_cmd[1]=0;
 787      mbenable_cmd[2]=mbenable_result[1];
 788      if(mbenable_result[1] & 1) retval = BIOS_TRANSLATION_25563;
 789      aha1542_out(base,mbenable_cmd,3);
 790      WAIT(INTRFLAGS(base),INTRMASK,HACC,0);
 791   };
 792   while(0) {
 793 fail:
 794     printk("aha1542_mbenable: Mailbox init failed\n");
 795   }
 796 aha1542_intr_reset(base);
 797 return retval;
 798 }
 799 
 800 /* Query the board to find out if it is a 1542 or a 1740, or whatever. */
 801 static int aha1542_query(int base_io, int * transl)
     /* [previous][next][first][last][top][bottom][index][help] */
 802 {
 803   unchar inquiry_cmd[] = {CMD_INQUIRY };
 804   unchar inquiry_result[4];
 805   int i;
 806   i = inb(STATUS(base_io));
 807   if (i & DF) {
 808     i = inb(DATA(base_io));
 809   };
 810   aha1542_out(base_io, inquiry_cmd, 1);
 811   aha1542_in(base_io, inquiry_result, 4);
 812   WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
 813   while (0) {
 814   fail:
 815     printk("aha1542_detect: query card type\n");
 816   }
 817   aha1542_intr_reset(base_io);
 818 
 819   *transl = BIOS_TRANSLATION_6432; /* Default case */
 820 
 821 /* For an AHA1740 series board, we ignore the board since there is a
 822    hardware bug which can lead to wrong blocks being returned if the board
 823    is operating in the 1542 emulation mode.  Since there is an extended mode
 824    driver, we simply ignore the board and let the 1740 driver pick it up.
 825 */
 826 
 827   if (inquiry_result[0] == 0x43) {
 828     printk("aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
 829     return 1;
 830   };
 831 
 832   /* Always call this - boards that do not support extended bios translation
 833      will ignore the command, and we will set the proper default */
 834 
 835   *transl = aha1542_mbenable(base_io);
 836 
 837   return 0;
 838 }
 839 
 840 /* called from init/main.c */
 841 void aha1542_setup( char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 842 {
 843     char *ahausage = "aha1542: usage: aha1542=<PORTBASE>[,<BUSON>,<BUSOFF>[,<DMASPEED>]]\n";
 844     static int setup_idx = 0;
 845     int setup_portbase;
 846 
 847     if(setup_idx >= MAXBOARDS)
 848       {
 849         printk("aha1542: aha1542_setup called too many times! Bad LILO params ?\n");
 850         printk("   Entryline 1: %s\n",setup_str[0]);
 851         printk("   Entryline 2: %s\n",setup_str[1]);
 852         printk("   This line:   %s\n",str);
 853         return;
 854       }
 855     if (ints[0] < 1 || ints[0] > 4)
 856       {
 857         printk("aha1542: %s\n", str );
 858         printk(ahausage);
 859         printk("aha1542: Wrong parameters may cause system malfunction.. We try anyway..\n");
 860       }
 861 
 862     setup_called[setup_idx]=ints[0];
 863     setup_str[setup_idx]=str;
 864 
 865     setup_portbase             = ints[0] >= 1 ? ints[1] : 0; /* Preserve the default value.. */
 866     setup_buson   [setup_idx]  = ints[0] >= 2 ? ints[2] : 7;
 867     setup_busoff  [setup_idx]  = ints[0] >= 3 ? ints[3] : 5;
 868     if (ints[0] >= 4) {
 869       int atbt = -1;
 870       switch (ints[4]) {
 871         case 5:
 872             atbt = 0x00;
 873             break;
 874         case 6:
 875             atbt = 0x04;
 876             break;
 877         case 7:
 878             atbt = 0x01;
 879             break;
 880         case 8:
 881             atbt = 0x02;
 882             break;
 883         case 10:
 884             atbt = 0x03;
 885             break;
 886         default:
 887             printk("aha1542: %s\n", str );
 888             printk(ahausage);
 889             printk("aha1542: Valid values for DMASPEED are 5-8, 10 MB/s.  Using jumper defaults.\n");
 890             break;
 891       }
 892       setup_dmaspeed[setup_idx]  = atbt;
 893     }
 894 
 895     if (setup_portbase != 0)
 896       bases[setup_idx] = setup_portbase;
 897 
 898     ++setup_idx;
 899 }
 900 
 901 /* return non-zero on detection */
 902 int aha1542_detect(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 903 {
 904     unsigned char dma_chan;
 905     unsigned char irq_level;
 906     unsigned int base_io;
 907     int trans;
 908     struct Scsi_Host * shpnt = NULL;
 909     int count = 0;
 910     int indx;
 911 
 912     DEB(printk("aha1542_detect: \n"));
 913 
 914     for(indx = 0; indx < sizeof(bases)/sizeof(bases[0]); indx++)
 915             if(bases[indx] != 0 && !check_region(bases[indx], 4)) { 
 916                     shpnt = scsi_register(tpnt,
 917                                           sizeof(struct aha1542_hostdata));
 918 
 919                     /* For now we do this - until kmalloc is more intelligent
 920                        we are resigned to stupid hacks like this */
 921                     if ((unsigned int) shpnt > 0xffffff) {
 922                       printk("Invalid address for shpnt with 1542.\n");
 923                       goto unregister;
 924                     }
 925 
 926                     if(!aha1542_test_port(bases[indx], shpnt)) goto unregister;
 927 
 928 
 929                     base_io = bases[indx];
 930                     
 931                     /* Set the Bus on/off-times as not to ruin floppy performance */
 932             {
 933                     unchar oncmd[] = {CMD_BUSON_TIME, 7};
 934                     unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
 935 
 936                     if(setup_called[indx])
 937                       {
 938                         oncmd[1]  = setup_buson[indx];
 939                         offcmd[1] = setup_busoff[indx];
 940                       }
 941                     
 942                     aha1542_intr_reset(base_io);
 943                     aha1542_out(base_io, oncmd, 2);
 944                     WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
 945                     aha1542_intr_reset(base_io);
 946                     aha1542_out(base_io, offcmd, 2);
 947                     WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
 948                     if (setup_dmaspeed[indx] >= 0)
 949                       {
 950                         unchar dmacmd[] = {CMD_DMASPEED, 0};
 951                         dmacmd[1] = setup_dmaspeed[indx];
 952                         aha1542_intr_reset(base_io);
 953                         aha1542_out(base_io, dmacmd, 2);
 954                         WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
 955                       }
 956                     while (0) {
 957                     fail:
 958                             printk("aha1542_detect: setting bus on/off-time failed\n");
 959                     }
 960                     aha1542_intr_reset(base_io);
 961             }
 962                     if(aha1542_query(base_io, &trans))  goto unregister;
 963                     
 964                     if (aha1542_getconfig(base_io, &irq_level, &dma_chan) == -1)  goto unregister;
 965                     
 966                     printk("Configuring Adaptec at IO:%x, IRQ %d",base_io, irq_level);
 967                     if (dma_chan != 0xFF)
 968                             printk(", DMA priority %d", dma_chan);
 969                     printk("\n");
 970                     
 971                     DEB(aha1542_stat());
 972                     setup_mailboxes(base_io, shpnt);
 973                     
 974                     DEB(aha1542_stat());
 975                     
 976                     DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
 977                     cli();
 978                     if (request_irq(irq_level,aha1542_intr_handle, 0, "aha1542")) {
 979                             printk("Unable to allocate IRQ for adaptec controller.\n");
 980                             goto unregister;
 981                     }
 982                     
 983                     if (dma_chan != 0xFF) {
 984                             if (request_dma(dma_chan,"aha1542")) {
 985                                     printk("Unable to allocate DMA channel for Adaptec.\n");
 986                                     free_irq(irq_level);
 987                                     goto unregister;
 988                             }
 989                             
 990                             if (dma_chan >= 5) {
 991                                     outb((dma_chan - 4) | CASCADE, DMA_MODE_REG);
 992                                     outb(dma_chan - 4, DMA_MASK_REG);
 993                             }
 994                     }
 995                     aha_host[irq_level - 9] = shpnt;
 996                     shpnt->io_port = base_io;
 997                     shpnt->n_io_port = 4;  /* Number of bytes of I/O space used */
 998                     shpnt->dma_channel = dma_chan;
 999                     shpnt->irq = irq_level;
1000                     HOSTDATA(shpnt)->bios_translation  = trans;
1001                     if(trans == 2) 
1002                       printk("aha1542.c: Using extended bios translation\n");
1003                     HOSTDATA(shpnt)->aha1542_last_mbi_used  = (2*AHA1542_MAILBOXES - 1);
1004                     HOSTDATA(shpnt)->aha1542_last_mbo_used  = (AHA1542_MAILBOXES - 1);
1005                     memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
1006                     sti();
1007 #if 0
1008                     DEB(printk(" *** READ CAPACITY ***\n"));
1009                     
1010             {
1011                     unchar buf[8];
1012                     static unchar cmd[] = {     READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1013                     int i;
1014                     
1015                     for (i = 0; i < sizeof(buf); ++i) buf[i] = 0x87;
1016                     for (i = 0; i < 2; ++i)
1017                             if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
1018                                     printk("aha_detect: LU %d sector_size %d device_size %d\n",
1019                                            i, xscsi2int(buf+4), xscsi2int(buf));
1020                             }
1021             }
1022                     
1023                     DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
1024                     
1025                     for (i = 0; i < 4; ++i)
1026                     {
1027                             unsigned char cmd[10];
1028                             static buffer[512];
1029                             
1030                             cmd[0] = READ_10;
1031                             cmd[1] = 0;
1032                             xany2scsi(cmd+2, i);
1033                             cmd[6] = 0;
1034                             cmd[7] = 0;
1035                             cmd[8] = 1;
1036                             cmd[9] = 0;
1037                             aha1542_command(0, cmd, buffer, 512);
1038                     }
1039 #endif    
1040                     snarf_region(bases[indx], 4);  /* Register the IO ports that we use */
1041                     count++;
1042                     continue;
1043             unregister:
1044                     scsi_unregister(shpnt);
1045                     continue;
1046                     
1047             };
1048     return count;
1049 }
1050 
1051 static int aha1542_restart(struct Scsi_Host * shost)
     /* [previous][next][first][last][top][bottom][index][help] */
1052 {
1053   int i;
1054   int count = 0;
1055 #if 0
1056   unchar ahacmd = CMD_START_SCSI;
1057 #endif
1058 
1059   for(i=0; i< AHA1542_MAILBOXES; i++)
1060    if(HOSTDATA(shost)->SCint[i] && 
1061       !(HOSTDATA(shost)->SCint[i]->device->soft_reset))
1062      {
1063 #if 0
1064         HOSTDATA(shost)->mb[i].status = 1; /* Indicate ready to restart... */
1065 #endif
1066         count++;
1067      }     
1068 
1069   printk("Potential to restart %d stalled commands...\n", count);
1070 #if 0
1071   /* start scsi command */
1072   if (count) aha1542_out(shost->io_port, &ahacmd, 1);
1073 #endif
1074   return 0;
1075 }
1076 
1077 /* The abort command does not leave the device in a clean state where
1078    it is available to be used again.  Until this gets worked out, we will
1079    leave it commented out.  */
1080 
1081 int aha1542_abort(Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1082 {
1083 #if 0
1084   int intval[3];
1085   unchar ahacmd = CMD_START_SCSI;
1086   struct mailbox * mb;
1087   int mbi, mbo, i;
1088 
1089   printk("In aha1542_abort: %x %x\n",
1090          inb(STATUS(SCpnt->host->io_port)),
1091          inb(INTRFLAGS(SCpnt->host->io_port)));
1092 
1093   cli();
1094   mb = HOSTDATA(SCpnt->host)->mb;
1095   mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;
1096   if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
1097   
1098   do{
1099     if(mb[mbi].status != 0) break;
1100     mbi++;
1101     if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;
1102   } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);
1103   sti();
1104 
1105   if(mb[mbi].status) {
1106     printk("Lost interrupt discovered on irq %d - attempting to recover\n", 
1107            SCpnt->host->irq);
1108     intval[0] = SCpnt->host->irq;
1109     aha1542_intr_handle((int) &intval[2]);
1110     return 0;
1111   }
1112 
1113   /* OK, no lost interrupt.  Try looking to see how many pending commands
1114      we think we have. */
1115 
1116   for(i=0; i< AHA1542_MAILBOXES; i++)
1117    if(HOSTDATA(SCpnt->host)->SCint[i])
1118      {
1119        if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {
1120          printk("Timed out command pending for %4.4x\n", SCpnt->request.dev);
1121          if (HOSTDATA(SCpnt->host)->mb[i].status) {
1122            printk("OGMB still full - restarting\n");
1123            aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1124          };
1125        } else
1126          printk("Other pending command %4.4x\n", SCpnt->request.dev);
1127      }
1128 
1129 #endif
1130 
1131     DEB(printk("aha1542_abort\n"));
1132 #if 0
1133     cli();
1134     for(mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
1135       if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]){
1136         mb[mbo].status = 2;  /* Abort command */
1137         aha1542_out(SCpnt->host->io_port, &ahacmd, 1); /* start scsi command */
1138         sti();
1139         break;
1140       };
1141 #endif
1142     return SCSI_ABORT_SNOOZE;
1143 }
1144 
1145 /* We do not implement a reset function here, but the upper level code
1146    assumes that it will get some kind of response for the command in
1147    SCpnt.  We must oblige, or the command will hang the scsi system.
1148    For a first go, we assume that the 1542 notifies us with all of the
1149    pending commands (it does implement soft reset, after all). */
1150 
1151 int aha1542_reset(Scsi_Cmnd * SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
1152 {
1153     unchar ahacmd = CMD_START_SCSI;
1154     int i;
1155 
1156     DEB(printk("aha1542_reset called\n"));
1157 #if 0
1158     /* This does a scsi reset for all devices on the bus */
1159     outb(SCRST, CONTROL(SCpnt->host->io_port));
1160 #else
1161     /* This does a selective reset of just the one device */
1162     /* First locate the ccb for this command */
1163     for(i=0; i< AHA1542_MAILBOXES; i++)
1164       if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt)
1165         {
1166           HOSTDATA(SCpnt->host)->ccb[i].op = 0x81;  /* BUS DEVICE RESET */
1167           /* Now tell the 1542 to flush all pending commands for this target */
1168           aha1542_out(SCpnt->host->io_port, &ahacmd, 1);
1169 
1170           /* Here is the tricky part.  What to do next.  Do we get an interrupt
1171              for the commands that we aborted with the specified target, or
1172              do we generate this on our own?  Try it without first and see
1173              what happens */
1174           printk("Sent BUS DEVICE RESET to target %d\n", SCpnt->target);
1175 
1176           /* If the first does not work, then try the second.  I think the
1177              first option is more likely to be correct. Free the command
1178              block for all commands running on this target... */
1179 #if 1
1180           for(i=0; i< AHA1542_MAILBOXES; i++)
1181             if(HOSTDATA(SCpnt->host)->SCint[i] &&
1182                HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target)
1183             {
1184               Scsi_Cmnd * SCtmp;
1185               SCtmp = HOSTDATA(SCpnt->host)->SCint[i];
1186               SCtmp->result = DID_RESET << 16;
1187               if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);
1188               printk("Sending DID_RESET for target %d\n", SCpnt->target);
1189               SCtmp->scsi_done(SCpnt);
1190               
1191               HOSTDATA(SCpnt->host)->SCint[i] = NULL;
1192               HOSTDATA(SCpnt->host)->mb[i].status = 0;
1193             }
1194           return SCSI_RESET_SUCCESS;
1195 #else
1196           return SCSI_RESET_PENDING;
1197 #endif
1198         }
1199 
1200 #endif
1201     /* No active command at this time, so this means that each time we got
1202        some kind of response the last time through.  Tell the mid-level code
1203        to request sense information in order to decide what to do next. */
1204     return SCSI_RESET_PUNT;
1205 }
1206 
1207 #include "sd.h"
1208 
1209 int aha1542_biosparam(Scsi_Disk * disk, int dev, int * ip)
     /* [previous][next][first][last][top][bottom][index][help] */
1210 {
1211   int translation_algorithm;
1212   int size = disk->capacity;
1213 
1214   translation_algorithm = HOSTDATA(disk->device->host)->bios_translation;
1215   /* Should this be > 1024, or >= 1024?  Enquiring minds want to know. */
1216   if((size>>11) > 1024 && translation_algorithm == 2) {
1217     /* Please verify that this is the same as what DOS returns */
1218     ip[0] = 255;
1219     ip[1] = 63;
1220     ip[2] = size /255/63;
1221   } else {
1222     ip[0] = 64;
1223     ip[1] = 32;
1224     ip[2] = size >> 11;
1225   };
1226 /*  if (ip[2] >= 1024) ip[2] = 1024; */
1227   return 0;
1228 }
1229 
1230 
1231 #ifdef MODULE
1232 /* Eventually this will go into an include file, but this will be later */
1233 Scsi_Host_Template driver_template = AHA1542;
1234 
1235 #include "scsi_module.c"
1236 #endif
1237 

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