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

📄 sym895lib.c

📁 IXP425的BSP代码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* sym895Lib.c - SCSI-2 driver for Symbios SYM895 SCSI Controller. *//* Copyright 1989-2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01f,31jan02,pmr  SPR 71337: properly setting transfer period in                 sym895XferParamsCvt(), fixed warnings.01e,30jul01,rcs  documented sym895DelayCount. SPR# 69249 01d,18jun01,dtr  sysInWord,sysOutWord,sysInLong,sysOutLong are usually byte                 swapped in the BSP.So the byteswapping is removed for                 _BYTE_ORDER == _BIG_ENDIAN. SPR# 6849701c,19jul00,rcs  corrected include path for sym895Lib.h01b,23jun00,bsp  modified IO access macros, as per sysLib.h01a,03mar00,bsp  written (from templateSCSI2.c, ver 01p).*//*DESCRIPTIONThe SYM53C895 PCI-SCSI I/O Processor (SIOP) brings Ultra2 SCSI performanceto Host adapter, making it easy to add a high performance SCSI Bus to any PCISystem.  It supports Ultra-2 SCSI rates and allows increased SCSI connectivityand cable length Low Voltage Differential (LVD) signaling for SCSI.  This driver runs in conjunction with SCRIPTS Assembly program for the Symbios SCSIcontrollers.  These scripts use DMA transfers for all data, messages, and statustransfers.For each controller device a manager task is created to manage SCSI threadson each bus.  A SCSI thread represents each unit of SCSI work.This driver supports multiple initiators, disconnect/reconnect, taggedcommand queuing and synchronous data transfer protocol.  In general, theSCSI system and this driver will automatically choose the best combinationof these features to suit the target devices used.  However, the defaultchoices may be over-ridden by using the function "scsiTargetOptionsSet()"(see scsiLib).Scatter/ Gather memory support: Scatter-Gather transfers are used when data scattered across memory must be transferred across the SCSI bus together with out CPU intervention.  This is achieved by a chain of block move script instructions together with the support from the driver. The driver is expectedto provide a set of addresses and byte counts for the SCRIPTS code.  However there is no support as such from vxworks SCSI Manager for this kind of data transfers.  So the implementation, as of today, is not completely integrated with vxworks, and assumes support from SCSI manager in the form of array ofpointers. The macro SCATTER_GATHER in sym895.h is thus not defined to avoidcompilation errors.Loopback mode allows 895 chip to control all SCSI signals, regardless of whether it is in initiator or target role.  This mode insures proper SCRIPTS instructions fetches and data paths.  SYM895 executes initiator instructions through the SCRIPTS, and the target role is implemented in sym895Loopback by asserting and polling the appropriate SCSI signals in the SOCL, SODL, SBCL, and SBDL registers.USER-CALLABLE ROUTINESMost of the routines in this driver are accessible only through the I/Osystem.  Three routines, however, must be called directly sym895CtrlCreate() to create a controller structure, and sym895CtrlInit() to initialize it.If the default configuration is not correct, the routine sym895SetHwRegister() must be used to properly configure the registers.Critical events, which are to be logged anyway irrespective of whetherdebugging is being done or not, can be logged by using the SCSI_MSG macro.PCI MEMORY ADDRESSINGThe global variable sym895PciMemOffset was created to provide the BSPwith a means of changing the VIRT_TO_PHYS mapping without changing thefunctions in the cacheFuncs structures.  In generating physical addressesfor DMA on the PCI bus, local addresses are passed through the functionCACHE_DMA_VIRT_TO_PHYS and then the value of sym895PciMemOffset is added.For backward compatibility, the initial value of sym895PciMemOffset comesfrom the macro PCI_TO_MEM_OFFSET.INTERFACEThe BSP must connect the interrupt service routine for the controller deviceto the appropriate interrupt system.  The routine to be called issym895Intr(), and the argument is the pointer to the controller device pSiop.i.e..CS    pSiop = sym895CtrlCreate (...);    intConnect (XXXX, sym895Intr, pSiop);    sym895CtrlInit (pSiop, ...);.CEHARDWARE ACCESSAll hardware access is to be done through macros.  The default definitionof the SYM895_REGx_READ() and SYM895_REGx_WRITE() macros (where x stands for the width of the register being accessed ) assumes an I/O mapped model.  Register access mode can be set to either IO/memory using SYM895_IO_MAPPEDmacro in sym895.h.  The macros can be redefined as necessary to accommodate other models, and situations where timing and write pipe considerations need to be addressed.  In IO mapped mode, BSP routines sysInByte(), sysOutByte()are used for accessing SYM895 registers.  If these standard calls are not supported, the calls supported by respective BSP are to be mapped to these standard calls.  Memory mapped mode makes use of pointers to register offsets.The macro SYM895_REGx_READ(pDev, reg) is used to read aregister of width x bits.  The two arguments are the device structurepointer and the register offset.The macro SYM895_REGx_WRITE(pDev, reg,data) is used to write data to thespecified register address.  These macros presume memory mapped I/O bydefault.  Both macros can be redefined to tailor the driver to some otherI/O model.The global variable sym895Delaycount provides the control count for the sym895 's delay loop. This variable is global in order to allow BSPs to adjust its value if necessary. The default value is 10 but itmay be set to a higher value as system clock speeds dictate.  INCLUDE FILESscsiLib.h, sym895.h, and sym895Script.cSEE ALSO scsiLib, scsi2Lib, cacheLib, .I "SYM53C895 PCI-SCSI I/O Processor Data Manual Version 3.0,".I "Symbios Logic PCI-SCSI I/O Processors Programming Guide Version 2.1,"*/#define INCLUDE_SCSI2	/* This is a SCSI2 driver */#include "vxWorks.h"#include "sysLib.h"#include "memLib.h"#include "ctype.h"#include "stdlib.h"#include "string.h"#include "stdio.h"#include "logLib.h"#include "semLib.h"#include "intLib.h"#include "errnoLib.h"#include "cacheLib.h"#include "taskLib.h"#include "scsiLib.h"#include "drv/scsi/sym895.h"/* Include SCRIPTS Assembly code */#include "sym895Script.c"/* defines *//* * short hand. All through the documentation,  * "SIOP" is used extensively for "SCSI Controller" */typedef SYM895_SCSI_CTRL SIOP;	#define PCI_TO_MEM_OFFSET	0x00#if (_BYTE_ORDER == _BIG_ENDIAN)#define SYM895_SWAP_32(x)  LONGSWAP((UINT)x)#define SYM895_SWAP_16(x)  ((LSB(x) << 8)|MSB(x))#else   /* _BYTE_ORDER == _BIG_ENDIAN   *//*  * Byte order is Little endian  * Don't need to swap because the chip is little endian inherently. */#define SYM895_SWAP_32   #define SYM895_SWAP_16#endif    /* _BYTE_ORDER == _BIG_ENDIAN   */#define SYM895_SCSI_DEBUG_MSG SCSI_DEBUG_MSG#define SYM895_VIRT_TO_PHYS(x) \	((UINT)CACHE_DMA_VIRT_TO_PHYS(x) + (UINT)sym895PciMemOffset)#define SYM895_PHYS_TO_VIRT(x) \	((UINT)CACHE_DMA_PHYS_TO_VIRT(x) + (UINT)sym895PciMemOffset)/* Hardware Abstraction macros hide all actual access to the chip */#ifdef SYM895_IO_MAPPED#if (_BYTE_ORDER==_LITTLE_ENDIAN)#define SYM895_REG8_READ(pSiop, reg) \	sysInByte((UINT32)((pSiop->baseAddress) + (reg)))#define SYM895_REG8_WRITE(pSiop, reg, data) \	sysOutByte((UINT32)((pSiop->baseAddress) + (reg)),(UINT8)data)#define SYM895_REG16_READ(pSiop, reg) \	SYM895_SWAP_16(sysInWord((UINT32)((pSiop->baseAddress) + (reg))))#define SYM895_REG16_WRITE(pSiop, reg, data) \	sysOutWord((UINT32)((pSiop->baseAddress) + (reg)), \                   SYM895_SWAP_16((UINT16)data))#define SYM895_REG32_READ(pSiop, reg) \	SYM895_SWAP_32(sysInLong((UINT32)((pSiop->baseAddress) + (reg))))#define SYM895_REG32_WRITE(pSiop, reg, data) \	sysOutLong((UINT32)((pSiop->baseAddress) + (reg)), \                   SYM895_SWAP_32((UINT32)data))#else#define SYM895_REG8_READ(pSiop, reg) \	sysInByte((ULONG)((pSiop->baseAddress) + (reg)))#define SYM895_REG8_WRITE(pSiop, reg, data) \	sysOutByte((ULONG)((pSiop->baseAddress) + (reg)),(UINT8)data)#define SYM895_REG16_READ(pSiop, reg) \	sysInWord((ULONG)((pSiop->baseAddress) + (reg)))#define SYM895_REG16_WRITE(pSiop, reg, data) \	sysOutWord((ULONG)((pSiop->baseAddress) + (reg)), \                   (UINT16)data)#define SYM895_REG32_READ(pSiop, reg) \	sysInLong((ULONG)((pSiop->baseAddress) + (reg)))#define SYM895_REG32_WRITE(pSiop, reg, data) \	sysOutLong((ULONG)((pSiop->baseAddress) + (reg)), \                   (UINT32)data)#endif #else	/* SYM895_IO_MAPPED */#define SYM895_REG8_READ(pSiop, reg) \	(*(UINT8 *)((pSiop->baseAddress) + (reg)))#define SYM895_REG8_WRITE(pSiop, reg, data) \	(*(UINT8 *)((pSiop->baseAddress) + (reg)) = (UINT8)data)#define SYM895_REG16_READ(pSiop, reg) \	SYM895_SWAP_16(*(UINT16 *)((pSiop->baseAddress) + (reg)))#define SYM895_REG16_WRITE(pSiop, reg, data) \	(*(UINT16 *)((pSiop->baseAddress) + (reg)) = SYM895_SWAP_16((UINT)data))#define SYM895_REG32_READ(pSiop, reg) \	SYM895_SWAP_32(*(UINT32 *)((pSiop->baseAddress) + (reg)))#define SYM895_REG32_WRITE(pSiop, reg, data) \	(*(UINT32 *)((pSiop->baseAddress) + (reg)) = SYM895_SWAP_32((UINT)data))#endif   /* SYM895_IO_MAPPED *//* Other miscellaneous defines */#define SYM895_MAX_XFER_LENGTH 0xffffff	/* 16MB max transfer */IMPORT BOOL scsiDebug;/* Configurable options, scsi manager task */int     sym895SingleStepSemOptions = SEM_Q_PRIORITY;char *  sym895ScsiTaskName         = SCSI_DEF_TASK_NAME;int     sym895ScsiTaskOptions      = SCSI_DEF_TASK_OPTIONS;int     sym895ScsiTaskPriority     = SCSI_DEF_TASK_PRIORITY;int     sym895ScsiTaskStackSize    = SCSI_DEF_TASK_STACK_SIZE;/* Globals */int     sym895PciMemOffset = PCI_TO_MEM_OFFSET;int     sym895DelayCount   = 10;ULONG * sym895ScriptEntry [] =  {				sym895Wait,				sym895InitStart,				sym895InitContinue,				sym895TgtDisconnect,                                sym895Diag				};/*  * The variable "sym895Instructions" needs to be defined for PPC family. As   * the memory is Big-Endian and PCI bus being little endian,the sym895  * scripts need to be byte swapped in memory. However, they should only be  * swapped the first time that sysSym895PciInit() is invoked. This variable is * used in BSP file sysScsi.c to swap the scripts in memory. *  * vxEieio () is needed for PPC family to make sure that SIOP registers * are written in order. */#if (CPU_FAMILY==PPC)ULONG sym895Instructions = SYM895_INSTRUCTIONS;#endif#if ((CPU==PPC603) || (CPU == PPCEC603) || (CPU==PPC604))# undef CACHE_PIPE_FLUSHextern void  vxEieio ();# define CACHE_PIPE_FLUSH() vxEieio()#endif/* forward declarations */LOCAL STATUS sym895HwInit (SIOP * pSiop);LOCAL void   sym895SharedMemInit ( SIOP * pSiop, SYM895_SHARED * pShMem);LOCAL STATUS sym895IdentThreadInit (SYM895_THREAD * pThread);STATUS       sym895SetHwOptions (SIOP * pSiop, SYM895_HW_OPTIONS * pHwOptions);LOCAL void   sym895Delay (void);LOCAL void   sym895ScsiBusReset (FAST SIOP * pSiop);LOCAL UINT   sym895RemainderGet ( SIOP * pSiop, UINT phase);LOCAL void   sym895Event (SIOP * pSiop, SYM895_EVENT * pEvent);LOCAL STATUS sym895ThreadInit (SIOP * pSiop, SYM895_THREAD * pThread);LOCAL STATUS sym895ThreadActivate (SIOP * pSiop, SYM895_THREAD * pThread);LOCAL BOOL   sym895ThreadAbort (SIOP * pSiop, SYM895_THREAD * pThread);LOCAL STATUS sym895ScsiBusControl (SIOP * pSiop, int operation);LOCAL STATUS sym895XferParamsQuery (SCSI_CTRL * pScsiCtrl, UINT8 * pOffset,                                    UINT8 * pPeriod);LOCAL STATUS sym895XferParamsSet (SCSI_CTRL * pScsiCtrl, UINT8 offset,                                  UINT8 period);LOCAL BOOL   sym895XferParamsCvt (SIOP * pSiop, UINT8 * pOffset, UINT8 * pPeriod,                                    UINT8 * pXferParams, UINT8 * pClockDiv);LOCAL void   sym895TargIdentEvent (SYM895_THREAD * pThread,                                    SYM895_EVENT * pEvent);LOCAL STATUS sym895WideXferParamsQuery (SCSI_CTRL * pScsiCtrl,                                        UINT8 * xferWidth);LOCAL STATUS sym895WideXferParamsSet (SCSI_CTRL * pScsiCtrl, UINT8 xferWidth);LOCAL void   sym895ScriptStart (SIOP * pSiop, SYM895_THREAD * pThread,                                SYM895_SCRIPT_ENTRY entryId);LOCAL int    sym895EventTypeGet (SIOP * pSiop);LOCAL STATUS sym895ThreadParamsSet (SYM895_THREAD *, UINT8, UINT8);LOCAL STATUS sym895Activate (SIOP * pSiop, SYM895_THREAD * pThread);LOCAL void   sym895ThreadStateSet (SYM895_THREAD * pThread,                                   SCSI_THREAD_STATE state);LOCAL void   sym895Abort (SIOP * pSiop);LOCAL void   sym895ThreadEvent (SYM895_THREAD * pThread,                                 SYM895_EVENT *  pEvent);LOCAL void   sym895InitEvent (SYM895_THREAD * pThread,                              SYM895_EVENT *  pEvent);LOCAL void   sym895ThreadUpdate (SYM895_THREAD * pThread);LOCAL void   sym895InitIdentEvent (SYM895_THREAD * pThread,                                   SYM895_EVENT * pEvent);LOCAL void   sym895IdentInContinue (SYM895_THREAD * pThread);LOCAL STATUS sym895Resume (SIOP * pSiop, SYM895_THREAD * pThread,                           SYM895_SCRIPT_ENTRY entryId);LOCAL void   sym895ThreadFail (SYM895_THREAD * pThread, int errNum);LOCAL void   sym895ThreadComplete (SYM895_THREAD * pThread);LOCAL void   sym895ThreadDefer (SYM895_THREAD * pThread);LOCAL STATUS sym895PhaseMismatch (SYM895_THREAD * pThread, int phase,				  UINT remCount);LOCAL void   sym895ThreadReconnect (SYM895_THREAD * pThread);/********************************************************************************* sym895CtrlCreate - create a structure for a SYM895 device.** This routine creates a SCSI Controller data structure and must be called * before using a SCSI Controller chip.  It should be called once and only * once for a specified SCSI Controller. Since it allocates memory for a * structure needed by all routines in sym895Lib, it must be called* before any other routines in the library. After calling this routine,* sym895CtrlInit() should be called at least once before any SCSI* transactions are initiated using the SCSI Controller.** A Detailed description of parameters follows.** .IP <siopBaseAdrs>* base address of the SCSI controller.* .IP <clkPeriod>* clock controller period (nsec*100).This is used to determine the clock period* for the SCSI core and affects the timing of both asynchronous and synchronous* transfers. Several Commonly used values are** .CS* SYM895_1667MHZ  6000    16.67Mhz chip * SYM895_20MHZ    5000    20Mhz chip * SYM895_25MHZ    4000    25Mhz chip * SYM895_3750MHZ  2667    37.50Mhz chip * SYM895_40MHZ    2500    40Mhz chip 

⌨️ 快捷键说明

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