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

📄 seagate.c

📁 GNU Mach 微内核源代码, 基于美国卡内基美隆大学的 Mach 研究项目
💻 C
📖 第 1 页 / 共 3 页
字号:
/* *	seagate.c Copyright (C) 1992, 1993 Drew Eckhardt  *	low level scsi driver for ST01/ST02, Future Domain TMC-885,  *	TMC-950  by * *		Drew Eckhardt  * *	<drew@colorado.edu> * * 	Note : TMC-880 boards don't work because they have two bits in  *		the status register flipped, I'll fix this "RSN" * *      This card does all the I/O via memory mapped I/O, so there is no need *      to check or allocate a region of the I/O address space. *//* * Configuration :  * To use without BIOS -DOVERRIDE=base_address -DCONTROLLER=FD or SEAGATE * -DIRQ will override the default of 5. * Note: You can now set these options from the kernel's "command line". * The syntax is: * *     st0x=ADDRESS,IRQ                (for a Seagate controller) * or: *     tmc8xx=ADDRESS,IRQ              (for a TMC-8xx or TMC-950 controller) * eg: *     tmc8xx=0xC8000,15 * * will configure the driver for a TMC-8xx style controller using IRQ 15 * with a base address of 0xC8000. *  * -DFAST or -DFAST32 will use blind transfers where possible * * -DARBITRATE will cause the host adapter to arbitrate for the  *	bus for better SCSI-II compatibility, rather than just  *	waiting for BUS FREE and then doing its thing.  Should *	let us do one command per Lun when I integrate my  *	reorganization changes into the distribution sources. * * -DSLOW_HANDSHAKE will allow compatibility with broken devices that don't  *	handshake fast enough (ie, some CD ROM's) for the Seagate * 	code. * * -DSLOW_RATE=x, x some number will let you specify a default  *	transfer rate if handshaking isn't working correctly. */#ifdef MACH#define ARBITRATE#define SLOW_HANDSHAKE#define FAST32#endif#include <linux/module.h>#include <asm/io.h>#include <asm/system.h>#include <linux/signal.h>#include <linux/sched.h>#include <linux/string.h>#include <linux/config.h>#include <linux/proc_fs.h>#include <linux/blk.h>#include "scsi.h"#include "hosts.h"#include "seagate.h"#include "constants.h"#include<linux/stat.h>struct proc_dir_entry proc_scsi_seagate = {    PROC_SCSI_SEAGATE, 7, "seagate",    S_IFDIR | S_IRUGO | S_IXUGO, 2};#ifndef IRQ#define IRQ 5#endif#if (defined(FAST32) && !defined(FAST))#define FAST#endif#if defined(SLOW_RATE) && !defined(SLOW_HANDSHAKE)#define SLOW_HANDSHAKE#endif#if defined(SLOW_HANDSHAKE) && !defined(SLOW_RATE)#define SLOW_RATE 50#endif#if defined(LINKED)#undef LINKED		/* Linked commands are currently broken ! */#endifstatic int internal_command(unsigned char target, unsigned char lun,			    const void *cmnd,			 void *buff, int bufflen, int reselect);static int incommand;			/*						set if arbitration has finished and we are 						in some command phase.					*/static const void *base_address = NULL;	/*						Where the card ROM starts,						used to calculate memory mapped						register location.					*/#ifdef notyetstatic volatile int abort_confirm = 0;#endifstatic volatile void *st0x_cr_sr;       /*						control register write,						status register read.						256 bytes in length.						Read is status of SCSI BUS,						as per STAT masks.					*/static volatile void *st0x_dr;         /*						data register, read write						256 bytes in length.					*/static volatile int st0x_aborted=0;	/* 						set when we are aborted, ie by a time out, etc.					*/static unsigned char controller_type = 0; /* set to SEAGATE for ST0x boards or FD for TMC-8xx boards */static unsigned char irq = IRQ;			#define retcode(result) (((result) << 16) | (message << 8) | status) 			#define STATUS (*(volatile unsigned char *) st0x_cr_sr)#define CONTROL STATUS #define DATA (*(volatile unsigned char *) st0x_dr)#define WRITE_CONTROL(d) { writeb((d), st0x_cr_sr); }#define WRITE_DATA(d) { writeb((d), st0x_dr); }void st0x_setup (char *str, int *ints) {    controller_type = SEAGATE;    base_address = (void *) ints[1];    irq = ints[2];}void tmc8xx_setup (char *str, int *ints) {    controller_type = FD;    base_address = (void *) ints[1];    irq = ints[2];}    #ifndef OVERRIDE		static const char *  seagate_bases[] = {	(char *) 0xc8000, (char *) 0xca000, (char *) 0xcc000,	(char *) 0xce000, (char *) 0xdc000, (char *) 0xde000};typedef struct {	const char *signature ;	unsigned offset;	unsigned length;	unsigned char type;} Signature;	static const Signature signatures[] = {#ifdef CONFIG_SCSI_SEAGATE{"ST01 v1.7  (C) Copyright 1987 Seagate", 15, 37, SEAGATE},{"SCSI BIOS 2.00  (C) Copyright 1987 Seagate", 15, 40, SEAGATE},/* * The following two lines are NOT mistakes.  One detects ROM revision  * 3.0.0, the other 3.2.  Since seagate has only one type of SCSI adapter,  * and this is not going to change, the "SEAGATE" and "SCSI" together * are probably "good enough" */{"SEAGATE SCSI BIOS ",16, 17, SEAGATE},{"SEAGATE SCSI BIOS ",17, 17, SEAGATE},/* * However, future domain makes several incompatible SCSI boards, so specific * signatures must be used. */{"FUTURE DOMAIN CORP. (C) 1986-1989 V5.0C2/14/89", 5, 46, FD},{"FUTURE DOMAIN CORP. (C) 1986-1989 V6.0A7/28/89", 5, 46, FD},{"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0105/31/90",5, 47, FD},{"FUTURE DOMAIN CORP. (C) 1986-1990 V6.0209/18/90",5, 47, FD},{"FUTURE DOMAIN CORP. (C) 1986-1990 V7.009/18/90", 5, 46, FD},{"FUTURE DOMAIN CORP. (C) 1992 V8.00.004/02/92",   5, 44, FD},{"IBM F1 BIOS V1.1004/30/92",			   5, 25, FD},{"FUTURE DOMAIN TMC-950",                        5, 21, FD},#endif /* CONFIG_SCSI_SEAGATE */};#define NUM_SIGNATURES (sizeof(signatures) / sizeof(Signature))#endif /* n OVERRIDE *//* * hostno stores the hostnumber, as told to us by the init routine. */static int hostno = -1;static void seagate_reconnect_intr(int, void *, struct pt_regs *);#ifdef FASTstatic int fast = 1;#endif #ifdef SLOW_HANDSHAKE/*  * Support for broken devices :  * The Seagate board has a handshaking problem.  Namely, a lack  * thereof for slow devices.  You can blast 600K/second through  * it if you are polling for each byte, more if you do a blind  * transfer.  In the first case, with a fast device, REQ will  * transition high-low or high-low-high before your loop restarts  * and you'll have no problems.  In the second case, the board  * will insert wait states for up to 13.2 usecs for REQ to  * transition low->high, and everything will work. * * However, there's nothing in the state machine that says  * you *HAVE* to see a high-low-high set of transitions before * sending the next byte, and slow things like the Trantor CD ROMS * will break because of this. *  * So, we need to slow things down, which isn't as simple as it  * seems.  We can't slow things down period, because then people * who don't recompile their kernels will shoot me for ruining  * their performance.  We need to do it on a case per case basis. * * The best for performance will be to, only for borken devices  * (this is stored on a per-target basis in the scsi_devices array) *  * Wait for a low->high transition before continuing with that  * transfer.  If we timeout, continue anyways.  We don't need  * a long timeout, because REQ should only be asserted until the  * corresponding ACK is received and processed. * * Note that we can't use the system timer for this, because of  * resolution, and we *really* can't use the timer chip since  * gettimeofday() and the beeper routines use that.  So, * the best thing for us to do will be to calibrate a timing * loop in the initialization code using the timer chip before * gettimeofday() can screw with it. */static int borken_calibration = 0;static void borken_init (void) {  register int count = 0, start = jiffies + 1, stop = start + 25;  while (jiffies < start);  for (;jiffies < stop; ++count);/*  * Ok, we now have a count for .25 seconds.  Convert to a  * count per second and divide by transfer rate in K. */  borken_calibration =  (count * 4) / (SLOW_RATE*1024);  if (borken_calibration < 1)  	borken_calibration = 1;#if (DEBUG & DEBUG_BORKEN)  printk("scsi%d : borken calibrated to %dK/sec, %d cycles per transfer\n", 	hostno, BORKEN_RATE, borken_calibration);#endif}static inline void borken_wait(void) {  register int count;  for (count = borken_calibration; count && (STATUS & STAT_REQ);   	--count);#if (DEBUG & DEBUG_BORKEN)   if (count)  	printk("scsi%d : borken timeout\n", hostno);#endif }#endif /* def SLOW_HANDSHAKE */int seagate_st0x_detect (Scsi_Host_Template * tpnt)	{     struct Scsi_Host *instance;#ifndef OVERRIDE	int i,j;#endif      tpnt->proc_dir = &proc_scsi_seagate;/* *	First, we try for the manual override. */#ifdef DEBUG 	printk("Autodetecting ST0x / TMC-8xx\n");#endif		if (hostno != -1)		{		printk ("ERROR : seagate_st0x_detect() called twice.\n");		return 0;		}      /* If the user specified the controller type from the command line,	 controller_type will be non-zero, so don't try to detect one */	if (!controller_type) {#ifdef OVERRIDE	base_address = (void *) OVERRIDE;/* CONTROLLER is used to override controller (SEAGATE or FD). PM: 07/01/93 */#ifdef CONTROLLER	controller_type = CONTROLLER;#else#error Please use -DCONTROLLER=SEAGATE or -DCONTROLLER=FD to override controller type#endif /* CONTROLLER */#ifdef DEBUG	printk("Base address overridden to %x, controller type is %s\n",		base_address,controller_type == SEAGATE ? "SEAGATE" : "FD");#endif #else /* OVERRIDE */	/* *	To detect this card, we simply look for the signature *	from the BIOS version notice in all the possible locations *	of the ROM's.  This has a nice side effect of not trashing * 	any register locations that might be used by something else. * * XXX - note that we probably should be probing the address * space for the on-board RAM instead. */	for (i = 0; i < (sizeof (seagate_bases) / sizeof (char  * )); ++i)		for (j = 0; !base_address && j < NUM_SIGNATURES; ++j)		if (!memcmp ((const void *) (seagate_bases[i] +		    signatures[j].offset), (const void *) signatures[j].signature,		    signatures[j].length)) {			base_address = (const void *) seagate_bases[i];			controller_type = signatures[j].type;		}#endif /* OVERRIDE */	} /* (! controller_type) */ 	tpnt->this_id = (controller_type == SEAGATE) ? 7 : 6;	tpnt->name = (controller_type == SEAGATE) ? ST0X_ID_STR : FD_ID_STR;	if (base_address)		{		st0x_cr_sr =(void *) (((const unsigned char *) base_address) + (controller_type == SEAGATE ? 0x1a00 : 0x1c00)); 		st0x_dr = (void *) (((const unsigned char *) base_address ) + (controller_type == SEAGATE ? 0x1c00 : 0x1e00));#ifdef DEBUG		printk("%s detected. Base address = %x, cr = %x, dr = %x\n", tpnt->name, base_address, st0x_cr_sr, st0x_dr);#endif/* *	At all times, we will use IRQ 5.  Should also check for IRQ3 if we  * 	loose our first interrupt. */		instance = scsi_register(tpnt, 0);		hostno = instance->host_no;		if (request_irq((int) irq, seagate_reconnect_intr, SA_INTERRUPT,		   (controller_type == SEAGATE) ? "seagate" : "tmc-8xx", NULL)) {			printk("scsi%d : unable to allocate IRQ%d\n",				hostno, (int) irq);			return 0;		}		instance->irq = irq;		instance->io_port = (unsigned int) base_address;#ifdef SLOW_HANDSHAKE		borken_init();#endif				printk("%s options:"#ifdef ARBITRATE		" ARBITRATE"#endif#ifdef SLOW_HANDSHAKE		" SLOW_HANDSHAKE"#endif#ifdef FAST#ifdef FAST32		" FAST32"#else		" FAST"#endif#endif#ifdef LINKED		" LINKED"#endif	      "\n", tpnt->name);		return 1;		}	else		{#ifdef DEBUG		printk("ST0x / TMC-8xx not detected.\n");#endif		return 0;		}	}	 const char *seagate_st0x_info(struct Scsi_Host * shpnt) {      static char buffer[64];	sprintf(buffer, "%s at irq %d, address 0x%05X", 		(controller_type == SEAGATE) ? ST0X_ID_STR : FD_ID_STR,		irq, (unsigned int)base_address);	return buffer;}int seagate_st0x_proc_info(char *buffer, char **start, off_t offset,                               int length, int hostno, int inout){       const char *info = seagate_st0x_info(NULL);       int len;       int pos;       int begin;       if (inout) return(-ENOSYS);       begin = 0;       strcpy(buffer,info);       strcat(buffer,"\n");       pos = len = strlen(buffer);       if (pos<offset) {               len = 0;               begin = pos;               }       *start = buffer + (offset - begin);       len -= (offset - begin);       if ( len > length ) len = length;       return(len);}/* * These are our saved pointers for the outstanding command that is  * waiting for a reconnect */static unsigned char current_target, current_lun;static unsigned char *current_cmnd, *current_data;static int current_nobuffs;static struct scatterlist *current_buffer;static int current_bufflen;#ifdef LINKED/*  * linked_connected indicates whether or not we are currently connected to  * linked_target, linked_lun and in an INFORMATION TRANSFER phase, * using linked commands. */static int linked_connected = 0;static unsigned char linked_target, linked_lun;#endifstatic void (*done_fn)(Scsi_Cmnd *) = NULL;static Scsi_Cmnd * SCint = NULL;/* * These control whether or not disconnect / reconnect will be attempted, * or are being attempted. */#define NO_RECONNECT 	0#define RECONNECT_NOW 	1#define CAN_RECONNECT	2#ifdef LINKED/* * LINKED_RIGHT indicates that we are currently connected to the correct target * for this command, LINKED_WRONG indicates that we are connected to the wrong  * target.  Note that these imply CAN_RECONNECT. */#define LINKED_RIGHT 	3#define LINKED_WRONG	4#endif/* * This determines if we are expecting to reconnect or not. */static int should_reconnect = 0;/* * The seagate_reconnect_intr routine is called when a target reselects the  * host adapter.  This occurs on the interrupt triggered by the target  * asserting SEL. */static void seagate_reconnect_intr(int irq, void *dev_id, struct pt_regs *regs)	{	int temp;	Scsi_Cmnd * SCtmp;/* enable all other interrupts. */		sti();#if (DEBUG & PHASE_RESELECT)	printk("scsi%d : seagate_reconnect_intr() called\n", hostno);#endif	if (!should_reconnect)	    printk("scsi%d: unexpected interrupt.\n", hostno);	else {		 should_reconnect = 0;#if (DEBUG & PHASE_RESELECT)		printk("scsi%d : internal_command("		       "%d, %08x, %08x, %d, RECONNECT_NOW\n", hostno, 			current_target, current_data, current_bufflen);#endif			temp =  internal_command (current_target, current_lun,			current_cmnd, current_data, current_bufflen,			RECONNECT_NOW);		if (msg_byte(temp) != DISCONNECT) {			if (done_fn) {#if (DEBUG & PHASE_RESELECT)				printk("scsi%d : done_fn(%d,%08x)", hostno, 				hostno, temp);#endif				if(!SCint) panic("SCint == NULL in seagate");				SCtmp = SCint;				SCint = NULL;				SCtmp->result = temp;				done_fn (SCtmp);			} else				printk("done_fn() not defined.\n");			}		}	} /*  * The seagate_st0x_queue_command() function provides a queued interface * to the seagate SCSI driver.  Basically, it just passes control onto the * seagate_command() function, after fixing it so that the done_fn() * is set to the one passed to the function.  We have to be very careful, * because there are some commands on some devices that do not disconnect, * and if we simply call the done_fn when the command is done then another * command is started and queue_command is called again...  We end up * overflowing the kernel stack, and this tends not to be such a good idea. */static int recursion_depth = 0;int seagate_st0x_queue_command (Scsi_Cmnd * SCpnt,  void (*done)(Scsi_Cmnd *))

⌨️ 快捷键说明

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