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

📄 sym53c8xx.c

📁 F:worksip2440a board可启动u-boot-like.tar.gz F:worksip2440a board可启动u-boot-like.tar.gz
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * (C) Copyright 2001 * Denis Peter, MPL AG Switzerland, d.peter@mpl.ch. * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA * partly derived from * linux/drivers/scsi/sym53c8xx.c * *//* * SCSI support based on the chip sym53C810. * * 09-19-2001 Andreas Heppel, Sysgo RTS GmbH <aheppel@sysgo.de> *		The local version of this driver for the BAB750 board does not *		use interrupts but polls the chip instead (see the call of *		'handle_scsi_int()' in 'scsi_issue()'. */#include <common.h>#ifdef CONFIG_SCSI_SYM53C8XX#include <command.h>#include <pci.h>#include <asm/processor.h>#include <sym53c8xx.h>#include <scsi.h>#undef	SYM53C8XX_DEBUG#ifdef	SYM53C8XX_DEBUG#define	PRINTF(fmt,args...)	printf (fmt ,##args)#else#define PRINTF(fmt,args...)#endif#if (CONFIG_COMMANDS & CFG_CMD_SCSI) && defined(CONFIG_SCSI_SYM53C8XX)#undef SCSI_SINGLE_STEP/* * Single Step is only used for debug purposes */#ifdef SCSI_SINGLE_STEPstatic unsigned long start_script_select;static unsigned long start_script_msgout;static unsigned long start_script_msgin;static unsigned long start_script_msg_ext;static unsigned long start_script_cmd;static unsigned long start_script_data_in;static unsigned long start_script_data_out;static unsigned long start_script_status;static unsigned long start_script_complete;static unsigned long start_script_error;static unsigned long start_script_reselection;static unsigned int len_script_select;static unsigned int len_script_msgout;static unsigned int len_script_msgin;static unsigned int len_script_msg_ext;static unsigned int len_script_cmd;static unsigned int len_script_data_in;static unsigned int len_script_data_out;static unsigned int len_script_status;static unsigned int len_script_complete;static unsigned int len_script_error;static unsigned int len_script_reselection;#endifstatic unsigned short scsi_int_mask;		/* shadow register for SCSI related interrupts */static unsigned char  script_int_mask;	/* shadow register for SCRIPT related interrupts */static unsigned long script_select[8]; /* script for selection */static unsigned long script_msgout[8]; /* script for message out phase (NOT USED) */static unsigned long script_msgin[14]; /* script for message in phase */static unsigned long script_msg_ext[32]; /* script for message in phase when more than 1 byte message */static unsigned long script_cmd[18];    /* script for command phase */static unsigned long script_data_in[8]; /* script for data in phase */static unsigned long script_data_out[8]; /* script for data out phase */static unsigned long script_status[6]; /* script for status phase */static unsigned long script_complete[10]; /* script for complete */static unsigned long script_reselection[4]; /* script for reselection (NOT USED) */static unsigned long script_error[2]; /* script for error handling */static unsigned long int_stat[3]; /* interrupt status */static unsigned long scsi_mem_addr; /* base memory address =SCSI_MEM_ADDRESS; */#define bus_to_phys(a)	pci_mem_to_phys(busdevfunc, (unsigned long) (a))#define phys_to_bus(a)	pci_phys_to_mem(busdevfunc, (unsigned long) (a))#define SCSI_MAX_RETRY 3 /* number of retries in scsi_issue() */#define SCSI_MAX_RETRY_NOT_READY 10 /* number of retries when device is not ready */#define SCSI_NOT_READY_TIME_OUT 500 /* timeout per retry when not ready *//********************************************************************************* * forward declerations */void scsi_chip_init(void);void handle_scsi_int(void);/******************************************************************************** * reports SCSI errors to the user */void scsi_print_error(ccb *pccb){	int i;	printf("SCSI Error: Target %d LUN %d Command %02X\n",pccb->target, pccb->lun, pccb->cmd[0]);	printf("       CCB: ");	for(i=0;i<pccb->cmdlen;i++)		printf("%02X ",pccb->cmd[i]);	printf("(len=%d)\n",pccb->cmdlen);	printf("     Cntrl: ");	switch(pccb->contr_stat) {		case SIR_COMPLETE: 						printf("Complete (no Error)\n"); break;		case SIR_SEL_ATN_NO_MSG_OUT: 	printf("Selected with ATN no MSG out phase\n"); break;		case SIR_CMD_OUT_ILL_PH: 			printf("Command out illegal phase\n"); break;		case SIR_MSG_RECEIVED: 				printf("MSG received Error\n"); break;		case SIR_DATA_IN_ERR: 				printf("Data in Error\n"); break;		case SIR_DATA_OUT_ERR: 				printf("Data out Error\n"); break;		case SIR_SCRIPT_ERROR: 				printf("Script Error\n"); break;		case SIR_MSG_OUT_NO_CMD: 			printf("MSG out no Command phase\n"); break;		case SIR_MSG_OVER7: 					printf("MSG in over 7 bytes\n"); break;		case INT_ON_FY: 							printf("Interrupt on fly\n"); break;		case SCSI_SEL_TIME_OUT:				printf("SCSI Selection Timeout\n"); break;		case SCSI_HNS_TIME_OUT:				printf("SCSI Handshake Timeout\n"); break;		case SCSI_MA_TIME_OUT:				printf("SCSI Phase Error\n"); break;		case SCSI_UNEXP_DIS:					printf("SCSI unexpected disconnect\n"); break;		default:											printf("unknown status %lx\n",pccb->contr_stat); break;	}	printf("     Sense: SK %x (",pccb->sense_buf[2]&0x0f);	switch(pccb->sense_buf[2]&0xf) {		case SENSE_NO_SENSE: printf("No Sense)"); break;		case SENSE_RECOVERED_ERROR: printf("Recovered Error)"); break;		case SENSE_NOT_READY:	printf("Not Ready)"); break;		case SENSE_MEDIUM_ERROR: printf("Medium Error)"); break;		case SENSE_HARDWARE_ERROR: printf("Hardware Error)"); break;		case SENSE_ILLEGAL_REQUEST: printf("Illegal request)"); break;		case SENSE_UNIT_ATTENTION: printf("Unit Attention)"); break;		case SENSE_DATA_PROTECT: printf("Data Protect)"); break;		case SENSE_BLANK_CHECK:	printf("Blank check)"); break;		case SENSE_VENDOR_SPECIFIC: printf("Vendor specific)"); break;		case SENSE_COPY_ABORTED: printf("Copy aborted)"); break;		case SENSE_ABORTED_COMMAND:	printf("Aborted Command)"); break;		case SENSE_VOLUME_OVERFLOW:	printf("Volume overflow)"); break;		case SENSE_MISCOMPARE: printf("Misscompare\n"); break;		default: printf("Illegal Sensecode\n"); break;	}	printf(" ASC %x ASCQ %x\n",pccb->sense_buf[12],pccb->sense_buf[13]);	printf("    Status: ");	switch(pccb->status) {		case S_GOOD :	printf("Good\n"); break;		case S_CHECK_COND: printf("Check condition\n"); break;		case S_COND_MET: printf("Condition Met\n"); break;		case S_BUSY: printf("Busy\n"); break;		case S_INT: printf("Intermediate\n"); break;		case S_INT_COND_MET: printf("Intermediate condition met\n"); break;		case S_CONFLICT: printf("Reservation conflict\n"); break;		case S_TERMINATED: printf("Command terminated\n"); break;		case S_QUEUE_FULL: printf("Task set full\n"); break;		default: printf("unknown: %02X\n",pccb->status); break;	}}/****************************************************************************** * sets-up the SCSI controller * the base memory address is retrived via the pci_read_config_dword */void scsi_low_level_init(int busdevfunc){	unsigned int cmd;	unsigned int addr;	unsigned char vec;	pci_read_config_byte(busdevfunc, PCI_INTERRUPT_LINE, &vec);	pci_read_config_dword(busdevfunc, PCI_BASE_ADDRESS_1, &addr);	addr = bus_to_phys(addr & ~0xf);	/*	 * Enable bus mastering in case this has not been done, yet.	 */	pci_read_config_dword(busdevfunc, PCI_COMMAND, &cmd);	cmd |= PCI_COMMAND_MASTER;	pci_write_config_dword(busdevfunc, PCI_COMMAND, cmd);	scsi_mem_addr = addr;	scsi_chip_init();	scsi_bus_reset();}/************************************************************************************ * Low level Part of SCSI Driver *//* * big-endian -> little endian conversion for the script */unsigned long swap_script(unsigned long val){	unsigned long tmp;	tmp = ((val>>24)&0xff) | ((val>>8)&0xff00) | ((val<<8)&0xff0000) | ((val<<24)&0xff000000);	return tmp;}void scsi_write_byte(ulong offset,unsigned char val){	out8(scsi_mem_addr+offset,val);}unsigned char scsi_read_byte(ulong offset){	return(in8(scsi_mem_addr+offset));}/******************************************************************************** * interrupt handler */void handle_scsi_int(void){	unsigned char stat,stat1,stat2;	unsigned short sstat;	int i;#ifdef SCSI_SINGLE_STEP	unsigned long tt;#endif	stat=scsi_read_byte(ISTAT);	if((stat & DIP)==DIP) { /* DMA Interrupt pending */		stat1=scsi_read_byte(DSTAT);#ifdef SCSI_SINGLE_STEP		if((stat1 & SSI)==SSI)		{			tt=in32r(scsi_mem_addr+DSP);			if(((tt)>=start_script_select) && ((tt)<start_script_select+len_script_select)) {				printf("select %d\n",(tt-start_script_select)>>2);				goto end_single;			}			if(((tt)>=start_script_msgout) && ((tt)<start_script_msgout+len_script_msgout)) {				printf("msgout %d\n",(tt-start_script_msgout)>>2);				goto end_single;			}			if(((tt)>=start_script_msgin) && ((tt)<start_script_msgin+len_script_msgin)) {				printf("msgin %d\n",(tt-start_script_msgin)>>2);				goto end_single;			}			if(((tt)>=start_script_msg_ext) && ((tt)<start_script_msg_ext+len_script_msg_ext)) {				printf("msgin_ext %d\n",(tt-start_script_msg_ext)>>2);				goto end_single;			}			if(((tt)>=start_script_cmd) && ((tt)<start_script_cmd+len_script_cmd)) {				printf("cmd %d\n",(tt-start_script_cmd)>>2);				goto end_single;			}			if(((tt)>=start_script_data_in) && ((tt)<start_script_data_in+len_script_data_in)) {				printf("data_in %d\n",(tt-start_script_data_in)>>2);				goto end_single;			}			if(((tt)>=start_script_data_out) && ((tt)<start_script_data_out+len_script_data_out)) {				printf("data_out %d\n",(tt-start_script_data_out)>>2);				goto end_single;			}			if(((tt)>=start_script_status) && ((tt)<start_script_status+len_script_status)) {				printf("status %d\n",(tt-start_script_status)>>2);				goto end_single;			}			if(((tt)>=start_script_complete) && ((tt)<start_script_complete+len_script_complete)) {				printf("complete %d\n",(tt-start_script_complete)>>2);				goto end_single;			}			if(((tt)>=start_script_error) && ((tt)<start_script_error+len_script_error)) {				printf("error %d\n",(tt-start_script_error)>>2);				goto end_single;			}			if(((tt)>=start_script_reselection) && ((tt)<start_script_reselection+len_script_reselection)) {				printf("reselection %d\n",(tt-start_script_reselection)>>2);				goto end_single;			}			printf("sc: %lx\n",tt);end_single:			stat2=scsi_read_byte(DCNTL);			stat2|=STD;			scsi_write_byte(DCNTL,stat2);		}#endif		if((stat1 & SIR)==SIR) /* script interrupt */		{			int_stat[0]=in32(scsi_mem_addr+DSPS);		}		if((stat1 & DFE)==0) { /* fifo not epmty */			scsi_write_byte(CTEST3,CLF); /* Clear DMA FIFO */			stat2=scsi_read_byte(STEST3);			scsi_write_byte(STEST3,(stat2 | CSF)); /* Clear SCSI FIFO */		}	}	if((stat & SIP)==SIP) {  /* scsi interrupt */		sstat = (unsigned short)scsi_read_byte(SIST+1);		sstat <<=8;		sstat |= (unsigned short)scsi_read_byte(SIST);		for(i=0;i<3;i++) {			if(int_stat[i]==0)				break; /* found an empty int status */		}		int_stat[i]=SCSI_INT_STATE | sstat;		stat1=scsi_read_byte(DSTAT);		if((stat1 & DFE)==0) { /* fifo not epmty */			scsi_write_byte(CTEST3,CLF); /* Clear DMA FIFO */			stat2=scsi_read_byte(STEST3);			scsi_write_byte(STEST3,(stat2 | CSF)); /* Clear SCSI FIFO */		}	}	if((stat & INTF)==INTF) { /* interrupt on Fly */		scsi_write_byte(ISTAT,stat); /* clear it */		for(i=0;i<3;i++) {			if(int_stat[i]==0)				break; /* found an empty int status */		}		int_stat[i]=INT_ON_FY;	}}void scsi_bus_reset(void){	unsigned char t;	int i;	int end = CFG_SCSI_SPIN_UP_TIME*1000;	t=scsi_read_byte(SCNTL1);	scsi_write_byte(SCNTL1,(t | CRST));	udelay(50);	scsi_write_byte(SCNTL1,t);	puts("waiting for devices to spin up");	for(i=0;i<end;i++) {		udelay(1000); /* give the devices time to spin up */		if (i % 1000 == 0)			putc('.');	}	putc('\n');	scsi_chip_init(); /* reinit the chip ...*/}void scsi_int_enable(void){	scsi_write_byte(SIEN,(unsigned char)scsi_int_mask);	scsi_write_byte(SIEN+1,(unsigned char)(scsi_int_mask>>8));	scsi_write_byte(DIEN,script_int_mask);}void scsi_write_dsp(unsigned long start){	unsigned long val;#ifdef SCSI_SINGLE_STEP	unsigned char t;#endif	val = start;	out32r(scsi_mem_addr + DSP,start);#ifdef SCSI_SINGLE_STEP	t=scsi_read_byte(DCNTL);  t|=STD;	scsi_write_byte(DCNTL,t);#endif}/* only used for debug purposes */void scsi_print_script(void){	printf("script_select @         0x%08lX\n",(unsigned long)&script_select[0]);	printf("script_msgout @         0x%08lX\n",(unsigned long)&script_msgout[0]);	printf("script_msgin @          0x%08lX\n",(unsigned long)&script_msgin[0]);	printf("script_msgext @         0x%08lX\n",(unsigned long)&script_msg_ext[0]);	printf("script_cmd @            0x%08lX\n",(unsigned long)&script_cmd[0]);	printf("script_data_in @        0x%08lX\n",(unsigned long)&script_data_in[0]);

⌨️ 快捷键说明

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