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

📄 aha1542.c

📁 基于组件方式开发操作系统的OSKIT源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
    printk("aha1542.c: Trying device reset for target %d\n", SCpnt->target);    return SUCCESS;	    #ifdef ERIC_neverdef    /*      * With the 1542 we apparently never get an interrupt to     * acknowledge a device reset being sent.  Then again, Leonard     * says we are doing this wrong in the first place...     *     * Take a wait and see attitude.  If we get spurious interrupts,     * then the device reset is doing something sane and useful, and     * we will wait for the interrupt to post completion.     */    printk("Sent BUS DEVICE RESET to target %d\n", SCpnt->target);        /*     * 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];	    if (SCtmp->host_scribble) 	    {		scsi_free(SCtmp->host_scribble, 512);	    }	    	    HOSTDATA(SCpnt->host)->SCint[i] = NULL;	    HOSTDATA(SCpnt->host)->mb[i].status = 0;	}    }    return SUCCESS;    return FAILED;#endif /* ERIC_neverdef */}int aha1542_bus_reset(Scsi_Cmnd * SCpnt){    int i;    /*      * 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(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.     */    scsi_sleep(4*HZ);    WAIT(STATUS(SCpnt->host->io_port), 	 STATMASK, INIT|IDLE, STST|DIAGF|INVDCMD|DF|CDF);        /*     * Now try to pick up the pieces.  For all pending commands,     * free any internal data structures, and basically clear things     * out.  We do not try and restart any commands or anything -      * the strategy handler takes care of that crap.     */    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];    	    if( SCtmp->device->soft_reset )	    {		/*		 * If this device implements the soft reset option,		 * then it is still holding onto the command, and		 * may yet complete it.  In this case, we don't		 * flush the data.		 */		continue;	    }	    if (SCtmp->host_scribble) 	    {		scsi_free(SCtmp->host_scribble, 512);	    }	    	    HOSTDATA(SCpnt->host)->SCint[i] = NULL;	    HOSTDATA(SCpnt->host)->mb[i].status = 0;	}    }    return SUCCESS;fail:    return FAILED;}int aha1542_host_reset(Scsi_Cmnd * SCpnt){    int i;    /*      * 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.     */    scsi_sleep(4*HZ);    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.  For all pending commands,     * free any internal data structures, and basically clear things     * out.  We do not try and restart any commands or anything -      * the strategy handler takes care of that crap.     */    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];	    if( SCtmp->device->soft_reset )	    {		/*		 * If this device implements the soft reset option,		 * then it is still holding onto the command, and		 * may yet complete it.  In this case, we don't		 * flush the data.		 */		continue;	    }	    if (SCtmp->host_scribble) 	    {		scsi_free(SCtmp->host_scribble, 512);	    }	    	    HOSTDATA(SCpnt->host)->SCint[i] = NULL;	    HOSTDATA(SCpnt->host)->mb[i].status = 0;	}    }    return SUCCESS;fail:    return FAILED;}/* * These are the old error handling routines.  They are only temporarily * here while we play with the new error handling code. */int aha1542_old_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_old_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 + -