⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aha1542.c

📁 LINUX 1.0 内核c源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    printk("Sending command (%d %x)...",mbo, done);
#endif

    any2scsi(mb[mbo].ccbptr, &ccb[mbo]); /* This gets trashed for some reason*/

    memset(&ccb[mbo], 0, sizeof(struct ccb));

    ccb[mbo].cdblen = COMMAND_SIZE(*cmd);     /* SCSI Command Descriptor Block Length */

    direction = 0;
    if (*cmd == READ_10 || *cmd == READ_6)
	direction = 8;
    else if (*cmd == WRITE_10 || *cmd == WRITE_6)
	direction = 16;

    memcpy(ccb[mbo].cdb, cmd, ccb[mbo].cdblen);

    if (SCpnt->use_sg) {
      struct scatterlist * sgpnt;
      struct chain * cptr;
#ifdef DEBUG
      unsigned char * ptr;
#endif
      int i;
      ccb[mbo].op = 2;	      /* SCSI Initiator Command  w/scatter-gather*/
      SCpnt->host_scribble = (unsigned char *) scsi_malloc(512);
      sgpnt = (struct scatterlist *) SCpnt->request_buffer;
      cptr = (struct chain *) SCpnt->host_scribble; 
      if (cptr == NULL) panic("aha1542.c: unable to allocate DMA memory\n");
      for(i=0; i<SCpnt->use_sg; i++) {
	if(sgpnt[i].length == 0 || SCpnt->use_sg > 16 || 
	   (((int)sgpnt[i].address) & 1) || (sgpnt[i].length & 1)){
	  unsigned char * ptr;
	  printk("Bad segment list supplied to aha1542.c (%d, %d)\n",SCpnt->use_sg,i);
	  for(i=0;i<SCpnt->use_sg;i++){
	    printk("%d: %x %x %d\n",i,(unsigned int) sgpnt[i].address, (unsigned int) sgpnt[i].alt_address,
		   sgpnt[i].length);
	  };
	  printk("cptr %x: ",(unsigned int) cptr);
	  ptr = (unsigned char *) &cptr[i];
	  for(i=0;i<18;i++) printk("%02x ", ptr[i]);
	  panic("Foooooooood fight!");
	};
	any2scsi(cptr[i].dataptr, sgpnt[i].address);
	if(((unsigned  int) sgpnt[i].address) & 0xff000000) goto baddma;
	any2scsi(cptr[i].datalen, sgpnt[i].length);
      };
      any2scsi(ccb[mbo].datalen, SCpnt->use_sg * sizeof(struct chain));
      if(((unsigned int) buff & 0xff000000)) goto baddma;
      any2scsi(ccb[mbo].dataptr, cptr);
#ifdef DEBUG
      printk("cptr %x: ",cptr);
      ptr = (unsigned char *) cptr;
      for(i=0;i<18;i++) printk("%02x ", ptr[i]);
#endif
    } else {
      ccb[mbo].op = 0;	      /* SCSI Initiator Command */
      SCpnt->host_scribble = NULL;
      any2scsi(ccb[mbo].datalen, bufflen);
      any2scsi(ccb[mbo].dataptr, buff);
    };
    ccb[mbo].idlun = (target&7)<<5 | direction | (lun & 7); /*SCSI Target Id*/
    ccb[mbo].rsalen = 12;
    ccb[mbo].linkptr[0] = ccb[mbo].linkptr[1] = ccb[mbo].linkptr[2] = 0;
    ccb[mbo].commlinkid = 0;

#ifdef DEBUGd
    { int i;
    printk("aha1542_command: sending.. ");
    for (i = 0; i < sizeof(ccb[mbo])-10; i++)
      printk("%02x ", ((unchar *)&ccb[mbo])[i]);
    };
#endif
    
    if (done) {
	DEB(printk("aha1542_queuecommand: now waiting for interrupt "); aha1542_stat());
	SCpnt->scsi_done = done;
	mb[mbo].status = 1;
	aha1542_out(SCpnt->host->io_port, &ahacmd, 1);		/* start scsi command */
	DEB(aha1542_stat());
    }
    else
      printk("aha1542_queuecommand: done can't be NULL\n");
    
    return 0;
 baddma:
    panic("Buffer at address  > 16Mb used for 1542B");
}

static void internal_done(Scsi_Cmnd * SCpnt)
{
	SCpnt->SCp.Status++;
}

int aha1542_command(Scsi_Cmnd * SCpnt)
{
    DEB(printk("aha1542_command: ..calling aha1542_queuecommand\n"));

    aha1542_queuecommand(SCpnt, internal_done);

    SCpnt->SCp.Status = 0;
    while (!SCpnt->SCp.Status);
    return SCpnt->result;
}

/* Initialize mailboxes */
static void setup_mailboxes(int bse, struct Scsi_Host * shpnt)
{
    int i;
    struct mailbox * mb;
    struct ccb  *ccb;

    unchar cmd[5] = {CMD_MBINIT, AHA1542_MAILBOXES};

    mb = HOSTDATA(shpnt)->mb;
    ccb = HOSTDATA(shpnt)->ccb;

    for(i=0; i<AHA1542_MAILBOXES; i++){
      mb[i].status = mb[AHA1542_MAILBOXES+i].status = 0;
      any2scsi(mb[i].ccbptr, &ccb[i]);
    };
    aha1542_intr_reset(bse);     /* reset interrupts, so they don't block */	
    any2scsi((cmd+2), mb);
    aha1542_out(bse, cmd, 5);
    WAIT(INTRFLAGS(bse), INTRMASK, HACC, 0);
    while (0) {
      fail:
	printk("aha1542_detect: failed setting up mailboxes\n");
    }
    aha1542_intr_reset(bse);
}

static int aha1542_getconfig(int base_io, unsigned char * irq_level, unsigned char * dma_chan)
{
  unchar inquiry_cmd[] = {CMD_RETCONF };
  unchar inquiry_result[3];
  int i;
  i = inb(STATUS(base_io));
  if (i & DF) {
    i = inb(DATA(base_io));
  };
  aha1542_out(base_io, inquiry_cmd, 1);
  aha1542_in(base_io, inquiry_result, 3);
  WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
  while (0) {
  fail:
    printk("aha1542_detect: query board settings\n");
  }
  aha1542_intr_reset(base_io);
  switch(inquiry_result[0]){
  case 0x80:
    *dma_chan = 7;
    break;
  case 0x40:
    *dma_chan = 6;
    break;
  case 0x20:
    *dma_chan = 5;
    break;
  case 0x01:
    printk("DMA priority 0 not available for Adaptec driver\n");
    return -1;
  case 0:
    /* This means that the adapter, although Adaptec 1542 compatible, doesn't use a DMA channel.
       Currently only aware of the BusLogic BT-445S VL-Bus adapter which needs this. */
    *dma_chan = 0xFF;
    break;
  default:
    printk("Unable to determine Adaptec DMA priority.  Disabling board\n");
    return -1;
  };
  switch(inquiry_result[1]){
  case 0x40:
    *irq_level = 15;
    break;
  case 0x20:
    *irq_level = 14;
    break;
  case 0x8:
    *irq_level = 12;
    break;
  case 0x4:
    *irq_level = 11;
    break;
  case 0x2:
    *irq_level = 10;
    break;
  case 0x1:
    *irq_level = 9;
    break;
  default:
    printk("Unable to determine Adaptec IRQ level.  Disabling board\n");
    return -1;
  };
  return 0;
}

/* This function should only be called for 1542C boards - we can detect
   the special firmware settings and unlock the board */

static int aha1542_mbenable(int base)
{
  static unchar mbenable_cmd[3];
  static unchar mbenable_result[2];
  int retval;
  
  retval = BIOS_TRANSLATION_6432;

  mbenable_cmd[0]=CMD_EXTBIOS;
  aha1542_out(base,mbenable_cmd,1);
  aha1542_in(base,mbenable_result,2);
  WAIT(INTRFLAGS(base),INTRMASK,HACC,0);
  aha1542_intr_reset(base);
  
  if ((mbenable_result[0] & 0x08) || mbenable_result[1]) {
     mbenable_cmd[0]=CMD_MBENABLE;
     mbenable_cmd[1]=0;
     mbenable_cmd[2]=mbenable_result[1];
     if(mbenable_result[1] & 1) retval = BIOS_TRANSLATION_25563;
     aha1542_out(base,mbenable_cmd,3);
     WAIT(INTRFLAGS(base),INTRMASK,HACC,0);
  };
  while(0) {
fail:
    printk("aha1542_mbenable: Mailbox init failed\n");
  }
aha1542_intr_reset(base);
return retval;
}

/* Query the board to find out if it is a 1542 or a 1740, or whatever. */
static int aha1542_query(int base_io, int * transl)
{
  unchar inquiry_cmd[] = {CMD_INQUIRY };
  unchar inquiry_result[4];
  int i;
  i = inb(STATUS(base_io));
  if (i & DF) {
    i = inb(DATA(base_io));
  };
  aha1542_out(base_io, inquiry_cmd, 1);
  aha1542_in(base_io, inquiry_result, 4);
  WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
  while (0) {
  fail:
    printk("aha1542_detect: query card type\n");
  }
  aha1542_intr_reset(base_io);

  *transl = BIOS_TRANSLATION_6432; /* Default case */

/* For an AHA1740 series board, we ignore the board since there is a
   hardware bug which can lead to wrong blocks being returned if the board
   is operating in the 1542 emulation mode.  Since there is an extended mode
   driver, we simply ignore the board and let the 1740 driver pick it up.
*/

  if (inquiry_result[0] == 0x43) {
    printk("aha1542.c: Emulation mode not supported for AHA 174N hardware.\n");
    return 1;
  };

  /* 1542C returns 0x44, 1542CF returns 0x45 */
  if (inquiry_result[0] == 0x44 || inquiry_result[0] == 0x45)
    { /* Detect 1542C  */
      *transl = aha1542_mbenable(base_io);
    };
  return 0;
}


/* return non-zero on detection */
int aha1542_detect(int hostnum)
{
    unsigned char dma_chan;
    unsigned char irq_level;
    unsigned int base_io;
    int trans;
    struct Scsi_Host * shpnt = NULL;
    int count = 0;
    int indx;

    DEB(printk("aha1542_detect: \n"));
    
    for(indx = 0; indx < sizeof(bases)/sizeof(bases[0]); indx++)
	    if(!check_region(bases[indx], 4)) { 
		    shpnt = scsi_register(hostnum,
					  sizeof(struct aha1542_hostdata));

		    if(!aha1542_test_port(bases[indx], shpnt)) goto unregister;


		    base_io = bases[indx];
		    
		    /* Set the Bus on/off-times as not to ruin floppy performance */
	    {
		    unchar oncmd[] = {CMD_BUSON_TIME, 7};
		    unchar offcmd[] = {CMD_BUSOFF_TIME, 5};
		    
		    aha1542_intr_reset(base_io);
		    aha1542_out(base_io, oncmd, 2);
		    WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
		    aha1542_intr_reset(base_io);
		    aha1542_out(base_io, offcmd, 2);
		    WAIT(INTRFLAGS(base_io), INTRMASK, HACC, 0);
		    while (0) {
		    fail:
			    printk("aha1542_detect: setting bus on/off-time failed\n");
		    }
		    aha1542_intr_reset(base_io);
	    }
		    if(aha1542_query(base_io, &trans))  goto unregister;
		    
		    if (aha1542_getconfig(base_io, &irq_level, &dma_chan) == -1)  goto unregister;
		    
		    printk("Configuring Adaptec at IO:%x, IRQ %d",base_io, irq_level);
		    if (dma_chan != 0xFF)
			    printk(", DMA priority %d", dma_chan);
		    printk("\n");
		    
		    DEB(aha1542_stat());
		    setup_mailboxes(base_io, shpnt);
		    
		    DEB(aha1542_stat());
		    
		    DEB(printk("aha1542_detect: enable interrupt channel %d\n", irq_level));
		    cli();
		    if (request_irq(irq_level,aha1542_intr_handle)) {
			    printk("Unable to allocate IRQ for adaptec controller.\n");
			    goto unregister;
		    }
		    
		    if (dma_chan != 0xFF) {
			    if (request_dma(dma_chan)) {
				    printk("Unable to allocate DMA channel for Adaptec.\n");
				    free_irq(irq_level);
				    goto unregister;
			    }
			    
			    if (dma_chan >= 5) {
				    outb((dma_chan - 4) | CASCADE, DMA_MODE_REG);
				    outb(dma_chan - 4, DMA_MASK_REG);
			    }
		    }
		    aha_host[irq_level - 9] = shpnt;
		    shpnt->io_port = base_io;
		    shpnt->dma_channel = dma_chan;
		    shpnt->irq = irq_level;
		    HOSTDATA(shpnt)->bios_translation  = trans;
		    if(trans == 2) 
		      printk("aha1542.c: Using extended bios translation\n");
		    HOSTDATA(shpnt)->aha1542_last_mbi_used  = (2*AHA1542_MAILBOXES - 1);
		    HOSTDATA(shpnt)->aha1542_last_mbo_used  = (AHA1542_MAILBOXES - 1);
		    memset(HOSTDATA(shpnt)->SCint, 0, sizeof(HOSTDATA(shpnt)->SCint));
		    sti();
#if 0
		    DEB(printk(" *** READ CAPACITY ***\n"));
		    
	    {
		    unchar buf[8];
		    static unchar cmd[] = {	READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		    int i;
		    
		    for (i = 0; i < sizeof(buf); ++i) buf[i] = 0x87;
		    for (i = 0; i < 2; ++i)
			    if (!aha1542_command(i, cmd, buf, sizeof(buf))) {
				    printk("aha_detect: LU %d sector_size %d device_size %d\n",
					   i, xscsi2int(buf+4), xscsi2int(buf));
			    }
	    }
		    
		    DEB(printk(" *** NOW RUNNING MY OWN TEST *** \n"));
		    
		    for (i = 0; i < 4; ++i)
		    {
			    unsigned char cmd[10];
			    static buffer[512];
			    
			    cmd[0] = READ_10;
			    cmd[1] = 0;
			    xany2scsi(cmd+2, i);
			    cmd[6] = 0;
			    cmd[7] = 0;
			    cmd[8] = 1;
			    cmd[9] = 0;
			    aha1542_command(0, cmd, buffer, 512);
		    }
#endif    
		    snarf_region(bases[indx], 4);  /* Register the IO ports that we use */
		    count++;
		    continue;
	    unregister:
		    scsi_unregister(shpnt, sizeof(struct aha1542_hostdata));
		    continue;
		    
	    };
    return count;
}

/* The abort command does not leave the device in a clean state where
   it is available to be used again.  Until this gets worked out, we will
   leave it commented out.  */

int aha1542_abort(Scsi_Cmnd * SCpnt, int i)
{
#if 0
    unchar ahacmd = CMD_START_SCSI;
    int mbo;
#endif
    DEB(printk("aha1542_abort\n"));
#if 0
    cli();
    for(mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)
      if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]){
	mb[mbo].status = 2;  /* Abort command */
	aha1542_out(&ahacmd, 1);		/* start scsi command */
	sti();
	break;
      };
#endif
    return 0;
}

/* We do not implement a reset function here, but the upper level code assumes
   that it will get some kind of response for the command in SCpnt.  We must
   oblige, or the command will hang the scsi system */

int aha1542_reset(Scsi_Cmnd * SCpnt)
{
    DEB(printk("aha1542_reset called\n"));
    if(SCpnt) SCpnt->flags |= NEEDS_JUMPSTART;
    return 0;
}

#ifdef CONFIG_BLK_DEV_SD
#include "sd.h"
#endif

int aha1542_biosparam(int size, int dev, int * ip)
{
  int translation_algorithm;
#ifdef CONFIG_BLK_DEV_SD
  Scsi_Device *disk;

  disk = rscsi_disks[MINOR(dev) >> 4].device;
  translation_algorithm = HOSTDATA(disk->host)->bios_translation;
  /* Should this be > 1024, or >= 1024?  Enquiring minds want to know. */
  if((size>>11) > 1024 && translation_algorithm == 2) {
    /* Please verify that this is the same as what DOS returns */
    ip[0] = 255;
    ip[1] = 63;
    ip[2] = size /255/63;
  } else {
    ip[0] = 64;
    ip[1] = 32;
    ip[2] = size >> 11;
  };
/*  if (ip[2] >= 1024) ip[2] = 1024; */
#endif
  return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -