📄 sysfei82557end.c
字号:
/* sysFei82557End.c - template for system configuration module for fei82557End *//* Copyright 2002 Wind River Systems, Inc. *//*TODO - Remove the template modification history and begin a new history starting with version 01a and growing the history upward with each revision.modification history--------------------01a,21may02,scm written.*//*DESCRIPTIONThis is the WRS-supplied configuration module for the VxWorksfei82557End (fei) END driver. It performs the dynamic parameterizationof the fei82557End driver. This technique of 'just-in-time'parameterization allows driver parameter values to be declaredas something other than static strings.*/#ifdef INCLUDE_FEI_END/* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "end.h"#include "config.h"#include "drv/end/fei82557End.h" /* TODO - Fill in this file with I/O addresses and related constants for the template BSP. Anything with "template" as a prefix needs to examined and re-named to id the BSP (i.e. iq80321, iq80310, etc.) *//* defines */#define END_LD_STR_SIZE 80IMPORT void sysUsDelay (int);#define sys557Delay() sysUsDelay(10)/* EEPROM control bits */#define EE_SK 0x01 /* shift clock */#define EE_CS 0x02 /* chip select */#define EE_DI 0x04 /* chip data in */#define EE_DO 0x08 /* chip data out *//* EEPROM opcode */#define EE_CMD_WRITE 0x05 /* WRITE opcode, 101 */#define EE_CMD_READ 0x06 /* READ opcode, 110 */#define EE_CMD_ERASE 0x07 /* ERASE opcode, 111 *//* EEPROM misc. defines */#define EE_CMD_BITS 3 /* number of opcode bits */#define EE_ADDR_BITS 6 /* number of address bits */#define EE_DATA_BITS 16 /* number of data bits */#define EE_SIZE 0x40 /* 0x40 words */#define EE_CHECKSUM 0xbaba /* checksum *//* PC compatibility macros */#define sysOutWord(addr,data) (*((UINT16 *) (addr)) = ((UINT16) (data)))#define sysInWord(addr) (*((UINT16 *) (addr)))#define sysOutLong(addr,data) (*((UINT32 *) (addr)) = ((UINT32) (data)))#define sysInLong(addr) (*((UINT32 *) (addr)))/* get rid of the value from fei82557end.h */#undef PRO100B_PCI_DEVICE_ID#define INTEL_PCI_VENDOR_ID 0x8086 /* PCI vendor ID */#define PRO100B_PCI_DEVICE_ID 0x1030 /* PCI device ID */#define PRO100S_PCI_DEVICE_ID 0x1229 /* PCI device ID */#define I82559ER_PCI_DEVICE_ID 0x1209/* * This array lists supported PCI vendor and device IDs. * The list must contain a terminating NULL entry.*/LOCAL SYS_PCI_IDENT feiDevices [] ={ {INTEL_PCI_VENDOR_ID, PRO100B_PCI_DEVICE_ID}, {INTEL_PCI_VENDOR_ID, PRO100S_PCI_DEVICE_ID}, {0, 0},};#define BOARD_TYPE_NB (NELEMENTS(feiDevices))/* typedefs */typedef struct { UINT32 membaseCsr; /* Base Address Register 0 */ UINT32 iobaseCsr; /* Base Address Register 1 */ UINT32 membaseFlash; /* Base Address Register 2 */ char irq; /* Interrupt Request Level */ UINT32 busNum; /* Which PCI Bus */ UINT32 devNum; /* Which PCI devnum */ UINT32 irqvec; /* Interrupt Request vector */ UINT16 pciVendID; UINT16 pciDevID; UINT16 eeprom[EE_SIZE]; /* Ethernet Address of this unit */ INT32 timeout; /* timeout for the self-test */ INT32 str[6]; /* storage for the self-test result */ volatile INT32 *pResults; /* pointer to the self-test result */} SYS_FEI_RESOURCE;/* The number of entries in this array should be >= to SYS_FEI_UNITS + 1 */LOCAL SYS_FEI_RESOURCE feiResources[SYS_FEI_UNITS + 1];LOCAL const char *fei_phys[] = { "None", "i82553-A/B", "i82553-C", "i82503", "DP83840", "80c240", "80c24", "unknown"};enum phy_chips { NonSuchPhy=0, I82553AB, I82553C, I82503, DP83840, S80C240, S80C24, I82555, DP83840A=10, UndefinedPhy };LOCAL const char *fei_connectors[] = {" RJ45", " BNC", " AUI", " MII"};unsigned char i82559erMacAddr[] = I82559ERMAC;LOCAL int feiUnits = 0; /* unit numbers *//* FEI specific imports */IMPORT FUNCPTR feiEndIntConnect;IMPORT FUNCPTR feiEndIntDisconnect;IMPORT END_OBJ *fei82557EndLoad(char *);IMPORT void sysFlashBoardDelay (void);/* forward declarations */LOCAL UINT16 sys557eepromRead (int unit, int location);LOCAL UINT32 sys557mdioRead (int unit, int phyId, int location);LOCAL UINT32 sys557mdioWrite (int unit, int phyId, int location, int value);LOCAL int sys557IntEnable (int unit);LOCAL int sys557IntDisable (int unit);LOCAL int sys557IntAck (int unit);/***************************************************************************** sysFei82557EndLoad - load fei82557 (fei) device.** This routine loads the fei device with initial parameters.** RETURNS: pointer to END object or ERROR.** SEE ALSO: fei82557EndLoad()*/END_OBJ * sysFei82557EndLoad ( char * pParamStr, /* ptr to initialization parameter string */ void * unused /* unused optional argument */ ){ char *cp; char paramStr [END_INIT_STR_MAX]; /* from end.h */ END_OBJ *pEnd; if(!feiUnits) { return NULL; } if(strlen(pParamStr) == 0) { /* * muxDevLoad() calls us twice. If the string is zero * length, then this is the first call by MUX. * Just call driver load function and return. */ pEnd = fei82557EndLoad (pParamStr); } else { /* * On the second pass though here, we actually create * the initialization parameter string on the fly. * Note that we will be handed our unit number on the * second pass through and we need to preserve that information. * So we use the unit number handed from the input string. */ cp = strcpy (paramStr, pParamStr); /* cp points to paramStr */ /* Now, we advance cp, by finding the end the string */ cp += strlen (paramStr); /* finish off the initialization parameter string */ /* * The fei82557End driver END_LOAD_STRING should be: * "<memBase>:<memSize>:<nTfds>:<nRfds>:<flags>:<offset>" */ sprintf (cp, "-1:0x00:0x20:0x20:0x00:2"); if ((pEnd = fei82557EndLoad (paramStr)) == NULL) printf ("Error: device failed fei82557EndLoad routine.\n"); } return pEnd;}/***************************************************************************** sys557PciInit - prepare LAN adapter for 82557 initialization** This routine find out the PCI device, and map its memory and IO address.* It must be done prior to initializing the 82557, sys557Init(). Also* must be done prior to MMU initialization, usrMmuInit().** RETURNS: N/A*/void sys557PciInit (void){ int i,unitNum; SYS_FEI_RESOURCE *pRes; /* FEI specific info */ for(i = 0; i < MAX_END_DEVS; ++i) { if(pendDevTbl[i].endLoadFunc == sysFei82557EndLoad) { pendDevTbl[i].processed = TRUE; } } /* * The following code tries to automatically detect * all instances of fei driver supported Ethernet cards. */ for(i = 0; i < SYS_FEI_UNITS; ++i) { pRes = &feiResources[feiUnits]; if(sysPciFindDevices(feiDevices,i, &pRes->busNum,&pRes->devNum, &pRes->pciVendID,&pRes->pciDevID) != OK) { break; /* found all instances */ } /* * * 32-bit BARs * * Memory: BAR0: [31:17]: memory base, read/write * [16:4] : read as "0" * [3] : 0 - device is not prefetchable * [2:1] : 00b - 32-bit address space * [0] : 0 - memory map decoded * * FLASH : BAR1: if BAR0[31:xx]: flash memory base * [xx:4] : read as "0" * * where 64K 31:16 15:4 * 128K 31:17 16:4 * 256K 31:18 17:4 * 512K 31:19 18:4 * * [3] : 0 - device is not prefetchable * [2:1] : 00b - 32-bit address space * [0] : 0 - memory map decoded * * IO : BAR2: if BAR0[31:3]: memory base, read/write * [2:1] : 00b * [0] : 1 - io map decoded * */ ++feiUnits; /* get memory and I/O base addresses and irq num */ pciConfigInLong(pRes->busNum,pRes->devNum,0,PCI_CFG_BASE_ADDRESS_0,&pRes->membaseCsr); pciConfigInLong(pRes->busNum,pRes->devNum,0,PCI_CFG_BASE_ADDRESS_1,&pRes->iobaseCsr); pciConfigInByte(pRes->busNum,pRes->devNum,0,PCI_CFG_DEV_INT_LINE,&pRes->irq); /* Convert to CPU address */ pRes->membaseCsr &= PCI_MEMBASE_MASK; pRes->iobaseCsr &= PCI_IOBASE_MASK; pRes->membaseCsr += template_CPU_PCI_MEM0_BASE; pRes->iobaseCsr += template_CPU_PCI_IO_BASE; } if(feiUnits) { /* one or more devices were found */ for(unitNum = 0, i = 0; unitNum < feiUnits && i < MAX_END_DEVS; ++i) { if(pendDevTbl[i].endLoadFunc == sysFei82557EndLoad || pendDevTbl[i].endLoadFunc == END_TBL_END) { pendDevTbl[i].unit = unitNum; pendDevTbl[i].endLoadFunc = sysFei82557EndLoad; pendDevTbl[i].endLoadString = ""; pendDevTbl[i].endLoan = TRUE /* FEI_BUFF_LOAN */ ; pendDevTbl[i].pBSP = NULL; pendDevTbl[i].processed = FALSE; ++unitNum; } } } /* specify the interrupt connect/disconnect routines to be used */ feiEndIntConnect = (FUNCPTR)intConnect; feiEndIntDisconnect = NULL; return;}/***************************************************************************** sys557Init - prepare LAN adapter for 82557 initialization** This routine is expected to perform any adapter-specific or target-specific* initialization that must be done prior to initializing the 82557.** The 82557 driver calls this routine from the driver attach routine before* any other routines in this library.** This routine returns the interrupt level the <pIntLvl> parameter.** RETURNS: OK or ERROR if the adapter could not be prepared for initialization.*/STATUS sys557Init(int unit,FEI_BOARD_INFO *pBoard){ volatile SYS_FEI_RESOURCE *pRes = &feiResources [unit]; UINT16 sum = 0; int ix; int iy; UINT16 value; void * testbuf = 0; /* keep compiler quite */ if (unit >= feiUnits) return ERROR; if(!pRes->pResults) { /* only do this setup once */ /* read the configuration in EEPROM */ for(ix = 0; ix < EE_SIZE; ++ix) { value = sys557eepromRead (unit, ix); pRes->eeprom[ix] = value; sum += value; } if(pRes->pciDevID != I82559ER_PCI_DEVICE_ID) { if(sum != EE_CHECKSUM)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -