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

📄 aha1542.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 3 页
字号:
    setup_portbase             = ints[0] >= 1 ? ints[1] : 0; /* Preserve the default value.. */    setup_buson   [setup_idx]  = ints[0] >= 2 ? ints[2] : 7;    setup_busoff  [setup_idx]  = ints[0] >= 3 ? ints[3] : 5;    if (ints[0] >= 4) {      int atbt = -1;      switch (ints[4]) {	case 5:	    atbt = 0x00;	    break;	case 6:	    atbt = 0x04;	    break;	case 7:	    atbt = 0x01;	    break;	case 8:	    atbt = 0x02;	    break;	case 10:	    atbt = 0x03;	    break;	default:	    printk("aha1542: %s\n", str );	    printk(ahausage);	    printk("aha1542: Valid values for DMASPEED are 5-8, 10 MB/s.  Using jumper defaults.\n");	    break;      }      setup_dmaspeed[setup_idx]  = atbt;    }    if (setup_portbase != 0)      bases[setup_idx] = setup_portbase;    ++setup_idx;}/* return non-zero on detection */int aha1542_detect(Scsi_Host_Template * tpnt){    unsigned char dma_chan;    unsigned char irq_level;    unsigned char scsi_id;    unsigned long flags;    unsigned int base_io;    int trans;    struct Scsi_Host * shpnt = NULL;    int count = 0;    int indx;    DEB(printk("aha1542_detect: \n"));    tpnt->proc_dir = &proc_scsi_aha1542;    for(indx = 0; indx < sizeof(bases)/sizeof(bases[0]); indx++)	    if(bases[indx] != 0 && !check_region(bases[indx], 4)) { 		    shpnt = scsi_register(tpnt,					  sizeof(struct aha1542_hostdata));		    /* For now we do this - until kmalloc is more intelligent		       we are resigned to stupid hacks like this */		    if ((unsigned int) shpnt > 0xffffff) {		      printk("Invalid address for shpnt with 1542.\n");		      goto unregister;		    }		    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};		    if(setup_called[indx])		      {			oncmd[1]  = setup_buson[indx];			offcmd[1] = setup_busoff[indx];		      }		    		    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);		    if (setup_dmaspeed[indx] >= 0)		      {			unchar dmacmd[] = {CMD_DMASPEED, 0};			dmacmd[1] = setup_dmaspeed[indx];			aha1542_intr_reset(base_io);			aha1542_out(base_io, dmacmd, 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, &scsi_id) == -1)  goto unregister;		    		    printk("Configuring Adaptec (SCSI-ID %d) at IO:%x, IRQ %d", scsi_id, 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));		    save_flags(flags);		    cli();		    if (request_irq(irq_level,aha1542_intr_handle, 0, "aha1542", NULL)) {			    printk("Unable to allocate IRQ for adaptec controller.\n");			    restore_flags(flags);			    goto unregister;		    }		    		    if (dma_chan != 0xFF) {			    if (request_dma(dma_chan,"aha1542")) {				    printk("Unable to allocate DMA channel for Adaptec.\n");				    free_irq(irq_level, NULL);				    restore_flags(flags);				    goto unregister;			    }			    			    if (dma_chan == 0 || dma_chan >= 5) {				    set_dma_mode(dma_chan, DMA_MODE_CASCADE);				    enable_dma(dma_chan);			    }		    }		    aha_host[irq_level - 9] = shpnt; 		    shpnt->this_id = scsi_id; 		    shpnt->unique_id = base_io;		    shpnt->io_port = base_io;		    shpnt->n_io_port = 4;  /* Number of bytes of I/O space used */		    shpnt->dma_channel = dma_chan;		    shpnt->irq = irq_level;		    HOSTDATA(shpnt)->bios_translation  = trans;		    if(trans == BIOS_TRANSLATION_25563) 		      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));		    restore_flags(flags);#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    		    request_region(bases[indx], 4,"aha1542");  /* Register the IO ports that we use */		    count++;		    continue;	    unregister:		    scsi_unregister(shpnt);		    continue;		    	    };	    return count;}static int aha1542_restart(struct Scsi_Host * shost){  int i;  int count = 0;#if 0  unchar ahacmd = CMD_START_SCSI;#endif  for(i=0; i< AHA1542_MAILBOXES; i++)   if(HOSTDATA(shost)->SCint[i] &&       !(HOSTDATA(shost)->SCint[i]->device->soft_reset))     {#if 0	HOSTDATA(shost)->mb[i].status = 1; /* Indicate ready to restart... */#endif	count++;     }       printk("Potential to restart %d stalled commands...\n", count);#if 0  /* start scsi command */  if (count) aha1542_out(shost->io_port, &ahacmd, 1);#endif  return 0;}/* 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){#if 0  unchar ahacmd = CMD_START_SCSI;  unsigned long flags;  struct mailbox * mb;  int mbi, mbo, i;  printk("In aha1542_abort: %x %x\n",	 inb(STATUS(SCpnt->host->io_port)),	 inb(INTRFLAGS(SCpnt->host->io_port)));  save_flags(flags);  cli();  mb = HOSTDATA(SCpnt->host)->mb;  mbi = HOSTDATA(SCpnt->host)->aha1542_last_mbi_used + 1;  if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;    do{    if(mb[mbi].status != 0) break;    mbi++;    if (mbi >= 2*AHA1542_MAILBOXES) mbi = AHA1542_MAILBOXES;  } while (mbi != HOSTDATA(SCpnt->host)->aha1542_last_mbi_used);  restore_flags(flags);  if(mb[mbi].status) {    printk("Lost interrupt discovered on irq %d - attempting to recover\n", 	   SCpnt->host->irq);    aha1542_intr_handle(SCpnt->host->irq, NULL);    return 0;  }  /* OK, no lost interrupt.  Try looking to see how many pending commands     we think we have. */  for(i=0; i< AHA1542_MAILBOXES; i++)   if(HOSTDATA(SCpnt->host)->SCint[i])     {       if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt) {	 printk("Timed out command pending for %s\n",		kdevname(SCpnt->request.rq_dev));	 if (HOSTDATA(SCpnt->host)->mb[i].status) {	   printk("OGMB still full - restarting\n");	   aha1542_out(SCpnt->host->io_port, &ahacmd, 1);	 };       } else	 printk("Other pending command %s\n",		kdevname(SCpnt->request.rq_dev));     }#endif    DEB(printk("aha1542_abort\n"));#if 0    save_flags(flags);    cli();    for(mbo = 0; mbo < AHA1542_MAILBOXES; mbo++)      if (SCpnt == HOSTDATA(SCpnt->host)->SCint[mbo]){	mb[mbo].status = 2;  /* Abort command */	aha1542_out(SCpnt->host->io_port, &ahacmd, 1); /* start scsi command */	restore_flags(flags);	break;      };#endif    return SCSI_ABORT_SNOOZE;}/* 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.   For a first go, we assume that the 1542 notifies us with all of the   pending commands (it does implement soft reset, after all). */int aha1542_reset(Scsi_Cmnd * SCpnt, unsigned int reset_flags){    unchar ahacmd = CMD_START_SCSI;    int i;    /*     * See if a bus reset was suggested.     */    if( reset_flags & SCSI_RESET_SUGGEST_BUS_RESET )      {	/* 	 * This does a scsi reset for all devices on the bus.	 * In principle, we could also reset the 1542 - should	 * we do this?  Try this first, and we can add that later	 * if it turns out to be useful.	 */	outb(HRST | SCRST, CONTROL(SCpnt->host->io_port));	/*	 * Wait for the thing to settle down a bit.  Unfortunately	 * this is going to basically lock up the machine while we	 * wait for this to complete.  To be 100% correct, we need to	 * check for timeout, and if we are doing something like this	 * we are pretty desperate anyways.	 */	WAIT(STATUS(SCpnt->host->io_port), 	     STATMASK, INIT|IDLE, STST|DIAGF|INVDCMD|DF|CDF);	/*	 * We need to do this too before the 1542 can interact with	 * us again.	 */	setup_mailboxes(SCpnt->host->io_port, SCpnt->host);	/*	 * Now try to pick up the pieces.  Restart all commands	 * that are currently active on the bus, and reset all of	 * the datastructures.  We have some time to kill while	 * things settle down, so print a nice message.	 */	printk("Sent BUS RESET to scsi host %d\n", SCpnt->host->host_no);	for(i=0; i< AHA1542_MAILBOXES; i++)	  if(HOSTDATA(SCpnt->host)->SCint[i] != NULL)	    {	      Scsi_Cmnd * SCtmp;	      SCtmp = HOSTDATA(SCpnt->host)->SCint[i];	      SCtmp->result = DID_RESET << 16;	      if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);	      printk("Sending DID_RESET for target %d\n", SCpnt->target);	      SCtmp->scsi_done(SCpnt);	      	      HOSTDATA(SCpnt->host)->SCint[i] = NULL;	      HOSTDATA(SCpnt->host)->mb[i].status = 0;	    }	/*	 * Now tell the mid-level code what we did here.  Since	 * we have restarted all of the outstanding commands,	 * then report SUCCESS.	 */	return (SCSI_RESET_SUCCESS | SCSI_RESET_BUS_RESET);fail:	printk("aha1542.c: Unable to perform hard reset.\n");	printk("Power cycle machine to reset\n");	return (SCSI_RESET_ERROR | SCSI_RESET_BUS_RESET);      }    else      {	/* This does a selective reset of just the one device */	/* First locate the ccb for this command */	for(i=0; i< AHA1542_MAILBOXES; i++)	  if(HOSTDATA(SCpnt->host)->SCint[i] == SCpnt)	    {	      HOSTDATA(SCpnt->host)->ccb[i].op = 0x81;  /* BUS DEVICE RESET */	      /* Now tell the 1542 to flush all pending commands for this target */	      aha1542_out(SCpnt->host->io_port, &ahacmd, 1);	      	      /* Here is the tricky part.  What to do next.  Do we get an interrupt		 for the commands that we aborted with the specified target, or		 do we generate this on our own?  Try it without first and see		 what happens */	      printk("Sent BUS DEVICE RESET to target %d\n", SCpnt->target);	      	      /* If the first does not work, then try the second.  I think the		 first option is more likely to be correct. Free the command		 block for all commands running on this target... */	      for(i=0; i< AHA1542_MAILBOXES; i++)		if(HOSTDATA(SCpnt->host)->SCint[i] &&		   HOSTDATA(SCpnt->host)->SCint[i]->target == SCpnt->target)		  {		    Scsi_Cmnd * SCtmp;		    SCtmp = HOSTDATA(SCpnt->host)->SCint[i];		    SCtmp->result = DID_RESET << 16;		    if (SCtmp->host_scribble) scsi_free(SCtmp->host_scribble, 512);		    printk("Sending DID_RESET for target %d\n", SCpnt->target);		    SCtmp->scsi_done(SCpnt);		    		    HOSTDATA(SCpnt->host)->SCint[i] = NULL;		    HOSTDATA(SCpnt->host)->mb[i].status = 0;		  }	      return SCSI_RESET_SUCCESS;	    }      }    /* No active command at this time, so this means that each time we got       some kind of response the last time through.  Tell the mid-level code       to request sense information in order to decide what to do next. */    return SCSI_RESET_PUNT;}#include "sd.h"int aha1542_biosparam(Scsi_Disk * disk, kdev_t dev, int * ip){  int translation_algorithm;  int size = disk->capacity;  translation_algorithm = HOSTDATA(disk->device->host)->bios_translation;  if((size>>11) > 1024 && translation_algorithm == BIOS_TRANSLATION_25563) {    /* 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;  }  return 0;}#ifdef MODULE/* Eventually this will go into an include file, but this will be later */Scsi_Host_Template driver_template = AHA1542;#include "scsi_module.c"#endif

⌨️ 快捷键说明

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