Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*  $Id$
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  *  1993/03/31
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/kernel/aha1740.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Based loosely on aha1542.c which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *  Copyright (C) 1992  Tommy Thorn and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Modified by Eric Youngdale
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *  This file is aha1740.c, written and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *  Copyright (C) 1992,1993  Brad McLean
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *  brad@saturn.gaylord.com or brad@bradpc.gaylord.com.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *  Modifications to makecode and queuecommand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  *  for proper handling of multiple devices courteously
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  *  provided by Michael Weller, March, 1993
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  *  Multiple adapter support, extended translation detection,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  *  update to current scsi subsystem changes, proc fs support,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  *  working (!) module support based on patches from Andreas Arens,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *  by Andreas Degert <ad@papyrus.hamburg.com>, 2/1997
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * aha1740_makecode may still need even more work
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  * if it doesn't work for your devices, take a look.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * Reworked for new_eh and new locking by Alan Cox <alan@lxorguk.ukuu.org.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * Converted to EISA and generic DMA APIs by Marc Zyngier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * <maz@wild-wind.fr.eu.org>, 4/2003.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * Shared interrupt support added by Rask Ingemann Lambertsen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * <rask@sygehus.dk>, 10/2003
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * For the avoidance of doubt the "preferred form" of this code is one which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  * is in an open non patent encumbered format. Where cryptographic key signing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35)  * forms part of the process of creating an executable the information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36)  * including keys needed to generate an equivalently functional executable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37)  * are deemed to be part of the source code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <linux/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #include <linux/eisa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #include <linux/dma-mapping.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #include <asm/dma.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) #include "scsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) #include <scsi/scsi_host.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #include "aha1740.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /* IF YOU ARE HAVING PROBLEMS WITH THIS DRIVER, AND WANT TO WATCH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63)    IT WORK, THEN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) #define DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) #define DEB(x) x
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) #define DEB(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) struct aha1740_hostdata {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct eisa_device *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	unsigned int translation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	unsigned int last_ecb_used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	dma_addr_t ecb_dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct ecb ecb[AHA1740_ECBS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) struct aha1740_sg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	struct aha1740_chain sg_chain[AHA1740_SCATTER];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	dma_addr_t sg_dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	dma_addr_t buf_dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) #define HOSTDATA(host) ((struct aha1740_hostdata *) &host->hostdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static inline struct ecb *ecb_dma_to_cpu (struct Scsi_Host *host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 					  dma_addr_t dma)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	struct aha1740_hostdata *hdata = HOSTDATA (host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	dma_addr_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	offset = dma - hdata->ecb_dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	return (struct ecb *)(((char *) hdata->ecb) + (unsigned int) offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) static inline dma_addr_t ecb_cpu_to_dma (struct Scsi_Host *host, void *cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	struct aha1740_hostdata *hdata = HOSTDATA (host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	dma_addr_t offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)     
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	offset = (char *) cpu - (char *) hdata->ecb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return hdata->ecb_dma_addr + offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int aha1740_show_info(struct seq_file *m, struct Scsi_Host *shpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct aha1740_hostdata *host = HOSTDATA(shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	seq_printf(m, "aha174x at IO:%lx, IRQ %d, SLOT %d.\n"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		      "Extended translation %sabled.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		      shpnt->io_port, shpnt->irq, host->edev->slot,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		      host->translation ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) static int aha1740_makecode(unchar *sense, unchar *status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	struct statusword
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		ushort	don:1,	/* Command Done - No Error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			du:1,	/* Data underrun */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		    :1,	qf:1,	/* Queue full */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		        sc:1,	/* Specification Check */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		        dor:1,	/* Data overrun */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		        ch:1,	/* Chaining Halted */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		        intr:1,	/* Interrupt issued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		        asa:1,	/* Additional Status Available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		        sns:1,	/* Sense information Stored */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		    :1,	ini:1,	/* Initialization Required */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			me:1,	/* Major error or exception */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		    :1,	eca:1,  /* Extended Contingent alliance */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		    :1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	} status_word;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	int retval = DID_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	status_word = * (struct statusword *) status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	printk("makecode from %x,%x,%x,%x %x,%x,%x,%x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	       status[0], status[1], status[2], status[3],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	       sense[0], sense[1], sense[2], sense[3]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (!status_word.don) { /* Anything abnormal was detected */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		if ( (status[1]&0x18) || status_word.sc ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			/*Additional info available*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 			/* Use the supplied info for further diagnostics */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 			switch ( status[2] ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 			case 0x12:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 				if ( status_word.dor )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 					retval=DID_ERROR; /* It's an Overrun */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				/* If not overrun, assume underrun and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 				 * ignore it! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 			case 0x00: /* No info, assume no error, should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				    * not occur */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			case 0x11:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 			case 0x21:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 				retval=DID_TIME_OUT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			case 0x0a:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 				retval=DID_BAD_TARGET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 			case 0x04:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 			case 0x05:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 				retval=DID_ABORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 				/* Either by this driver or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 				 * AHA1740 itself */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 			default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 				retval=DID_ERROR; /* No further
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 						   * diagnostics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 						   * possible */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			/* Michael suggests, and Brad concurs: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 			if ( status_word.qf ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 				retval = DID_TIME_OUT; /* forces a redo */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 				/* I think this specific one should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 				 * not happen -Brad */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 				printk("aha1740.c: WARNING: AHA1740 queue overflow!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				if ( status[0]&0x60 ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 					 /* Didn't find a better error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 					retval = DID_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 				}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			/* In any other case return DID_OK so for example
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 			   CONDITION_CHECKS make it through to the appropriate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 			   device driver */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	/* Under all circumstances supply the target status -Michael */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return status[3] | retval << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int aha1740_test_port(unsigned int base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if ( inb(PORTADR(base)) & PORTADDR_ENH )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return 1;   /* Okay, we're all set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	printk("aha174x: Board detected, but not in enhanced mode, so disabled it.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* A "high" level interrupt handler */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static irqreturn_t aha1740_intr_handle(int irq, void *dev_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	struct Scsi_Host *host = (struct Scsi_Host *) dev_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)         void (*my_done)(struct scsi_cmnd *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	int errstatus, adapstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	int number_serviced;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct ecb *ecbptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	struct scsi_cmnd *SCtmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	unsigned int base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	int handled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct aha1740_sg *sgptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct eisa_device *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	if (!host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		panic("aha1740.c: Irq from unknown host!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	spin_lock_irqsave(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	base = host->io_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	number_serviced = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	edev = HOSTDATA(host)->edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	while(inb(G2STAT(base)) & G2STAT_INTPEND) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		handled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 		DEB(printk("aha1740_intr top of loop.\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		adapstat = inb(G2INTST(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		ecbptr = ecb_dma_to_cpu (host, inl(MBOXIN0(base)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		outb(G2CNTRL_IRST,G2CNTRL(base)); /* interrupt reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)       
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		switch ( adapstat & G2INTST_MASK ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		case	G2INTST_CCBRETRY:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		case	G2INTST_CCBERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 		case	G2INTST_CCBGOOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 			/* Host Ready -> Mailbox in complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			outb(G2CNTRL_HRDY,G2CNTRL(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			if (!ecbptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 				printk("Aha1740 null ecbptr in interrupt (%x,%x,%x,%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				       inb(G2STAT(base)),adapstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				       inb(G2INTST(base)), number_serviced++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			SCtmp = ecbptr->SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 			if (!SCtmp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 				printk("Aha1740 null SCtmp in interrupt (%x,%x,%x,%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 				       inb(G2STAT(base)),adapstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 				       inb(G2INTST(base)), number_serviced++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 			sgptr = (struct aha1740_sg *) SCtmp->host_scribble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			scsi_dma_unmap(SCtmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			/* Free the sg block */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			dma_free_coherent (&edev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 					   sizeof (struct aha1740_sg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 					   SCtmp->host_scribble,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 					   sgptr->sg_dma_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 			/* Fetch the sense data, and tuck it away, in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 			   the required slot.  The Adaptec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			   automatically fetches it, and there is no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 			   guarantee that we will still have it in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			   cdb when we come back */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			if ( (adapstat & G2INTST_MASK) == G2INTST_CCBERROR ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 				memcpy(SCtmp->sense_buffer, ecbptr->sense, 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 				       SCSI_SENSE_BUFFERSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 				errstatus = aha1740_makecode(ecbptr->sense,ecbptr->status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				errstatus = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			DEB(if (errstatus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 			    printk("aha1740_intr_handle: returning %6x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 				   errstatus));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 			SCtmp->result = errstatus;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 			my_done = ecbptr->done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			memset(ecbptr,0,sizeof(struct ecb)); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 			if ( my_done )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 				my_done(SCtmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		case	G2INTST_HARDFAIL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 			printk(KERN_ALERT "aha1740 hardware failure!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 			panic("aha1740.c");	/* Goodbye */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		case	G2INTST_ASNEVENT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 			printk("aha1740 asynchronous event: %02x %02x %02x %02x %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			       adapstat,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 			       inb(MBOXIN0(base)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 			       inb(MBOXIN1(base)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			       inb(MBOXIN2(base)),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			       inb(MBOXIN3(base))); /* Say What? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			/* Host Ready -> Mailbox in complete */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 			outb(G2CNTRL_HRDY,G2CNTRL(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		case	G2INTST_CMDGOOD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			/* set immediate command success flag here: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 			
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		case	G2INTST_CMDERROR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 			/* Set immediate command failure flag here: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		number_serviced++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	spin_unlock_irqrestore(host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	return IRQ_RETVAL(handled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) static int aha1740_queuecommand_lck(struct scsi_cmnd * SCpnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 				    void (*done)(struct scsi_cmnd *))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 	unchar direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	unchar *cmd = (unchar *) SCpnt->cmnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	unchar target = scmd_id(SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	struct aha1740_hostdata *host = HOSTDATA(SCpnt->device->host);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	dma_addr_t sg_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 	struct aha1740_sg *sgptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	int ecbno, nseg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	DEB(int i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	if(*cmd == REQUEST_SENSE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		SCpnt->result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		done(SCpnt); 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 	if (*cmd == READ_10 || *cmd == WRITE_10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 		i = xscsi2int(cmd+2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	else if (*cmd == READ_6 || *cmd == WRITE_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 		i = scsi2int(cmd+2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 		i = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	printk("aha1740_queuecommand: dev %d cmd %02x pos %d len %d ",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	       target, *cmd, i, bufflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	printk("scsi cmd:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	for (i = 0; i < SCpnt->cmd_len; i++) printk("%02x ", cmd[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	/* locate an available ecb */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	ecbno = host->last_ecb_used + 1; /* An optimization */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	if (ecbno >= AHA1740_ECBS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 		ecbno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 		if (!host->ecb[ecbno].cmdw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 		ecbno++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 		if (ecbno >= AHA1740_ECBS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 			ecbno = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 	} while (ecbno != host->last_ecb_used);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) 	if (host->ecb[ecbno].cmdw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 		panic("Unable to find empty ecb for aha1740.\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 	host->ecb[ecbno].cmdw = AHA1740CMD_INIT; /* SCSI Initiator Command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) 						    doubles as reserved flag */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	host->last_ecb_used = ecbno;    
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	printk("Sending command (%d %x)...", ecbno, done);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	host->ecb[ecbno].cdblen = SCpnt->cmd_len; /* SCSI Command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 						   * Descriptor Block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 						   * Length */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	direction = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	if (*cmd == READ_10 || *cmd == READ_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 		direction = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	else if (*cmd == WRITE_10 || *cmd == WRITE_6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 		direction = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	memcpy(host->ecb[ecbno].cdb, cmd, SCpnt->cmd_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	SCpnt->host_scribble = dma_alloc_coherent (&host->edev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 						   sizeof (struct aha1740_sg),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 						   &sg_dma, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if(SCpnt->host_scribble == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		printk(KERN_WARNING "aha1740: out of memory in queuecommand!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 		return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	sgptr = (struct aha1740_sg *) SCpnt->host_scribble;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	sgptr->sg_dma_addr = sg_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	nseg = scsi_dma_map(SCpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	BUG_ON(nseg < 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) 	if (nseg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 		struct scatterlist *sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) 		struct aha1740_chain * cptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) 		DEB(unsigned char * ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) 		host->ecb[ecbno].sg = 1;  /* SCSI Initiator Command
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) 					   * w/scatter-gather*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 		cptr = sgptr->sg_chain;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 		scsi_for_each_sg(SCpnt, sg, nseg, i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 			cptr[i].datalen = sg_dma_len (sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 			cptr[i].dataptr = sg_dma_address (sg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 		host->ecb[ecbno].datalen = nseg * sizeof(struct aha1740_chain);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 		host->ecb[ecbno].dataptr = sg_dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		printk("cptr %x: ",cptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 		ptr = (unsigned char *) cptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 		for(i=0;i<24;i++) printk("%02x ", ptr[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 		host->ecb[ecbno].datalen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 		host->ecb[ecbno].dataptr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	host->ecb[ecbno].lun = SCpnt->device->lun;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	host->ecb[ecbno].ses = 1; /* Suppress underrun errors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	host->ecb[ecbno].dir = direction;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	host->ecb[ecbno].ars = 1; /* Yes, get the sense on an error */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	host->ecb[ecbno].senselen = 12;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	host->ecb[ecbno].senseptr = ecb_cpu_to_dma (SCpnt->device->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 						    host->ecb[ecbno].sense);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	host->ecb[ecbno].statusptr = ecb_cpu_to_dma (SCpnt->device->host,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 						     host->ecb[ecbno].status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	host->ecb[ecbno].done = done;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	host->ecb[ecbno].SCpnt = SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 		printk("aha1740_command: sending.. ");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 		for (i = 0; i < sizeof(host->ecb[ecbno]) - 10; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 			printk("%02x ", ((unchar *)&host->ecb[ecbno])[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 	printk("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	if (done) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	/* The Adaptec Spec says the card is so fast that the loops
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)            will only be executed once in the code below. Even if this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)            was true with the fastest processors when the spec was
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)            written, it doesn't seem to be true with today's fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)            processors. We print a warning if the code is executed more
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)            often than LOOPCNT_WARN. If this happens, it should be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)            investigated. If the count reaches LOOPCNT_MAX, we assume
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)            something is broken; since there is no way to return an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)            error (the return value is ignored by the mid-level scsi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)            layer) we have to panic (and maybe that's the best thing we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452)            can do then anyhow). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #define LOOPCNT_WARN 10		/* excessive mbxout wait -> syslog-msg */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) #define LOOPCNT_MAX 1000000	/* mbxout deadlock -> panic() after ~ 2 sec. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 		int loopcnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 		unsigned int base = SCpnt->device->host->io_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 		DEB(printk("aha1740[%d] critical section\n",ecbno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		spin_lock_irqsave(SCpnt->device->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		for (loopcnt = 0; ; loopcnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			if (inb(G2STAT(base)) & G2STAT_MBXOUT) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			if (loopcnt == LOOPCNT_WARN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 				printk("aha1740[%d]_mbxout wait!\n",ecbno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 			if (loopcnt == LOOPCNT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 				panic("aha1740.c: mbxout busy!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 		outl (ecb_cpu_to_dma (SCpnt->device->host, host->ecb + ecbno),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 		      MBOXOUT0(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		for (loopcnt = 0; ; loopcnt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 			if (! (inb(G2STAT(base)) & G2STAT_BUSY)) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 			if (loopcnt == LOOPCNT_WARN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 				printk("aha1740[%d]_attn wait!\n",ecbno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 			if (loopcnt == LOOPCNT_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) 				panic("aha1740.c: attn wait failed!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 		outb(ATTN_START | (target & 7), ATTN(base)); /* Start it up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) 		spin_unlock_irqrestore(SCpnt->device->host->host_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 		DEB(printk("aha1740[%d] request queued.\n",ecbno));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 		printk(KERN_ALERT "aha1740_queuecommand: done can't be NULL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static DEF_SCSI_QCMD(aha1740_queuecommand)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /* Query the board for its irq_level and irq_type.  Nothing else matters
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)    in enhanced mode on an EISA bus. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) static void aha1740_getconfig(unsigned int base, unsigned int *irq_level,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) 			      unsigned int *irq_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) 			      unsigned int *translation)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 	static int intab[] = { 9, 10, 11, 12, 0, 14, 15, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 	*irq_level = intab[inb(INTDEF(base)) & 0x7];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) 	*irq_type  = (inb(INTDEF(base)) & 0x8) >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) 	*translation = inb(RESV1(base)) & 0x1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) 	outb(inb(INTDEF(base)) | 0x10, INTDEF(base));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int aha1740_biosparam(struct scsi_device *sdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) 			     struct block_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 			     sector_t capacity, int* ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	int size = capacity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	int extended = HOSTDATA(sdev->host)->translation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 	DEB(printk("aha1740_biosparam\n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	if (extended && (ip[2] > 1024))	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 		ip[0] = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		ip[1] = 63;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 		ip[2] = size / (255 * 63);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 		ip[0] = 64;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 		ip[1] = 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		ip[2] = size >> 11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) static int aha1740_eh_abort_handler (struct scsi_cmnd *dummy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527)  * From Alan Cox :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)  * The AHA1740 has firmware handled abort/reset handling. The "head in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)  * sand" kernel code is correct for once 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)  * So we define a dummy handler just to keep the kernel SCSI code as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)  * quiet as possible...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	return SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) static struct scsi_host_template aha1740_template = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 	.module           = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) 	.proc_name        = "aha1740",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 	.show_info        = aha1740_show_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) 	.name             = "Adaptec 174x (EISA)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) 	.queuecommand     = aha1740_queuecommand,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) 	.bios_param       = aha1740_biosparam,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 	.can_queue        = AHA1740_ECBS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) 	.this_id          = 7,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) 	.sg_tablesize     = AHA1740_SCATTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) 	.eh_abort_handler = aha1740_eh_abort_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) static int aha1740_probe (struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) 	int slotbase, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) 	unsigned int irq_level, irq_type, translation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) 	struct Scsi_Host *shpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) 	struct aha1740_hostdata *host;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) 	struct eisa_device *edev = to_eisa_device (dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) 	DEB(printk("aha1740_probe: \n"));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) 	slotbase = edev->base_addr + EISA_VENDOR_ID_OFFSET;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) 	if (!request_region(slotbase, SLOTSIZE, "aha1740")) /* See if in use */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) 		return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) 	if (!aha1740_test_port(slotbase))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) 		goto err_release_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) 	aha1740_getconfig(slotbase,&irq_level,&irq_type,&translation);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) 	if ((inb(G2STAT(slotbase)) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) 	     (G2STAT_MBXOUT|G2STAT_BUSY)) != G2STAT_MBXOUT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) 		/* If the card isn't ready, hard reset it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) 		outb(G2CNTRL_HRST, G2CNTRL(slotbase));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) 		outb(0, G2CNTRL(slotbase));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) 	printk(KERN_INFO "Configuring slot %d at IO:%x, IRQ %u (%s)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) 	       edev->slot, slotbase, irq_level, irq_type ? "edge" : "level");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) 	printk(KERN_INFO "aha174x: Extended translation %sabled.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) 	       translation ? "en" : "dis");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) 	shpnt = scsi_host_alloc(&aha1740_template,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) 			      sizeof(struct aha1740_hostdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) 	if(shpnt == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) 		goto err_release_region;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) 	shpnt->base = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) 	shpnt->io_port = slotbase;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) 	shpnt->n_io_port = SLOTSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) 	shpnt->irq = irq_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) 	shpnt->dma_channel = 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) 	host = HOSTDATA(shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) 	host->edev = edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) 	host->translation = translation;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) 	host->ecb_dma_addr = dma_map_single (&edev->dev, host->ecb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) 					     sizeof (host->ecb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) 					     DMA_BIDIRECTIONAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) 	if (!host->ecb_dma_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) 		printk (KERN_ERR "aha1740_probe: Couldn't map ECB, giving up\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) 		goto err_host_put;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) 	DEB(printk("aha1740_probe: enable interrupt channel %d\n",irq_level));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) 	if (request_irq(irq_level,aha1740_intr_handle,irq_type ? 0 : IRQF_SHARED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) 			"aha1740",shpnt)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) 		printk(KERN_ERR "aha1740_probe: Unable to allocate IRQ %d.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) 		       irq_level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) 		goto err_unmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) 	eisa_set_drvdata (edev, shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) 	rc = scsi_add_host (shpnt, dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) 		goto err_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) 	scsi_scan_host (shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)  err_irq:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616)  	free_irq(irq_level, shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617)  err_unmap:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) 	dma_unmap_single (&edev->dev, host->ecb_dma_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) 			  sizeof (host->ecb), DMA_BIDIRECTIONAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)  err_host_put:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) 	scsi_host_put (shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)  err_release_region:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) 	release_region(slotbase, SLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) 	return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static int aha1740_remove (struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) 	struct Scsi_Host *shpnt = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) 	struct aha1740_hostdata *host = HOSTDATA (shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) 	scsi_remove_host(shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) 	free_irq (shpnt->irq, shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) 	dma_unmap_single (dev, host->ecb_dma_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) 			  sizeof (host->ecb), DMA_BIDIRECTIONAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) 	release_region (shpnt->io_port, SLOTSIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) 	scsi_host_put (shpnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) static struct eisa_device_id aha1740_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) 	{ "ADP0000" },		/* 1740  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) 	{ "ADP0001" },		/* 1740A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) 	{ "ADP0002" },		/* 1742A */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) 	{ "ADP0400" },		/* 1744  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) 	{ "" }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) MODULE_DEVICE_TABLE(eisa, aha1740_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) static struct eisa_driver aha1740_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) 	.id_table = aha1740_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) 	.driver   = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) 		.name    = "aha1740",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) 		.probe   = aha1740_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) 		.remove  = aha1740_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) static __init int aha1740_init (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) 	return eisa_driver_register (&aha1740_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) static __exit void aha1740_exit (void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) 	eisa_driver_unregister (&aha1740_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) module_init (aha1740_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) module_exit (aha1740_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) MODULE_LICENSE("GPL");