📄 sysfei82557end.c
字号:
/* sysFei82557End.c - system configuration module for fei82557End *//* Copyright 1984 - 2005 Wind River Systems, Inc. *//*modification history--------------------01b,09feb05,m_h fei configuration01a,17dec04,m_h Created*//*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.INCLUDE FILES:end.h drv/end/fei82557End.h*/#if (defined(INCLUDE_END) && defined (INCLUDE_FEI82557END))/* includes */#include "vxWorks.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "end.h"#include "netinet/if_ether.h"#include "config.h"#include "drv/end/fei82557End.h"/* imports */IMPORT END_TBL_ENTRY endDevTbl[];END_TBL_ENTRY *pendDevTbl = endDevTbl;IMPORT FUNCPTR feiEndIntConnect;IMPORT FUNCPTR feiEndIntDisconnect;IMPORT END_OBJ * fei82557EndLoad (char *);IMPORT void sysMicroDelay (int microseconds);/* defines */#undef PCI_END_DEBUG/* * Some delay is required after most config commands * A delay of 1uS should be OK but should be tested. * 3uS is more than enough. */#define PCI_CONFIG_DELAY 3 #undef FEI_MAX_UNITS#define FEI_MAX_UNITS IXP425_MAX_FEI_DEVS#define END_LD_STR_SIZE 80/* Intel EtherExpress PRO100B LAN Adapter type */#define TYPE_ALLOC 1000/* * FEI cards in range 1001 -> 2000 */#define FEI_START TYPE_ALLOC + 1#define TYPE_PRO100B_PCI FEI_START /* Intel EtherExpress PRO-100B PCI */#define TYPE_INBUSINESS_PCI FEI_START + 1 /* Intel InBusiness 10/100 PCI */#define TYPE_XX82559ER_PCI FEI_START + 100 /* Arbitrary card with 82559ER *//* the following two are tuneable parameters which specify the number of transmit and receive buffers to be allocated for use by an fei (82559) driver. These must never be set below 2, otherwise the driver will assume a default of 32, and our calculations of how much memory to allocate for the driver will be in error*/#define FEI_N_RFDS 32#define FEI_N_TFDS 32/* * FEI_RFD_MULTIPLIER is the multiplier that is applied to the number of RFDs requested * to determine the number of "spares" available for loaning to the network * stack. This value (4) was taken from the fei driver source code (its not * available in the header, so if this changes in future versions of the driver * this will break - if it is increased the driver will complain that we have not * given it enough memory, if it is decreased everything will work but we will be * wasting SDRAM. */#define FEI_RFD_MULTIPLIER 4#define FEI_N_RFD_LOAN (FEI_N_RFDS * FEI_RFD_MULTIPLIER)/* * Again FEI_CL_OVERHEAD has been taken from the fei source code (not specified in header), * so the caveats for the FEI_RFD_MULTIPLIER apply here too */#define FEI_CL_OVERHEAD 4 /* prepended cluster header */#define FEI_CL_RFD_SIZE (RFD_SIZE + FEI_CL_OVERHEAD)#define FEI_CFD_SIZE CFD_SIZE/*This calculation is taken from the fei driver source, again, if this changes, the driver will either complain that it has not been allocated enough memory, or will work fine but we will be wasting SDRAM*/#define FEI_TOTAL_SIZE ((FEI_N_RFDS * FEI_CL_RFD_SIZE) + \ (FEI_N_RFD_LOAN * FEI_CL_RFD_SIZE) + \ (FEI_N_TFDS * (FEI_CFD_SIZE +sizeof(long))) + 4)/* 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 */#define EEPROM_WORD_SIZE 0x40 /* 0-0x3f *//* unknown values */#ifndef UNKNOWN#define UNKNOWN 0xFFFFFFFF#endif /*UNKNOWN*//* FEI driver access routines *//* typedefs */typedef struct feiResource /* FEI_RESOURCE */ { UINT32 membaseCsr; /* Base Address Register 0 */ UINT32 iobaseCsr; /* Base Address Register 1 */ UINT32 membaseFlash; /* Base Address Register 2 */ char irq; /* Interrupt Request Level */ UINT32 configType; /* type of configuration - unused */ UINT32 boardType; /* type of LAN board this unit is */ UINT32 pciBus; /* PCI Bus number */ UINT32 pciDevice; /* PCI Device number */ UINT32 pciFunc; /* PCI Function number */ UINT32 eeprom[EEPROM_WORD_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 */ UINT memLength; /* required memory size */ UINT initialStateMask; /* mask parameter to vmStateSet */ UINT initialState; /* state parameter to vmStateSet */ } FEI_RESOURCE;/* locals *//* END load strings */LOCAL UINT32 feiUnits = 0; /* number of FEIs we found */LOCAL FEI_RESOURCE feiResources [FEI_MAX_UNITS] = { {UNKNOWN, UNKNOWN, UNKNOWN, (char)NONE, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, ERROR, {ERROR}, NULL, UNKNOWN, UNKNOWN, UNKNOWN}, {UNKNOWN, UNKNOWN, UNKNOWN, (char)NONE, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, ERROR, {ERROR}, NULL, UNKNOWN, UNKNOWN, UNKNOWN}, {UNKNOWN, UNKNOWN, UNKNOWN, (char)NONE, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, ERROR, {ERROR}, NULL, UNKNOWN, UNKNOWN, UNKNOWN}, {UNKNOWN, UNKNOWN, UNKNOWN, (char)NONE, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, ERROR, {ERROR}, NULL, UNKNOWN, UNKNOWN, UNKNOWN}, };LOCAL const char *phys[] = { "None", "i82553-A/B", "i82553-C", "i82503", "DP83840", "80c240", "80c24", "unknown" };enum phy_chips { NonSuchPhy=0, I82553AB, I82553C, I82503, DP83840, S80C240, S80C24, UndefinedPhy };LOCAL const char *connectors[] = {" RJ45", " BNC", " AUI", " MII"};/* forward declarations */UINT16 sys557eepromRead (int unit, int location);void sys557eepromDump (int unit);LOCAL UINT16 sys557mdioRead (int unit, int phyId, int location);LOCAL UINT16 sys557mdioWrite (int unit, int phyId, int location, int value);LOCAL int sys557IntAck (int unit);LOCAL UINT32 sys557EndPhysToPci ( int unit, UINT32 PhysAddr);LOCAL UINT32 sys557EndPciToPhys ( int unit, UINT32 PhysAddr);LOCAL STATUS sys557IntDisable (int unit);LOCAL STATUS sys557IntEnable (int unit);LOCAL STATUS sys557IntConnect ( void *pDrvCtrl, VOIDFUNCPTR *intHandler, int drvCtrl );LOCAL STATUS sys557IntDisconnect ( void *pDrvCtrl, VOIDFUNCPTR *intHandler );/******************************************************************************** sysFei82557EndLoad - load fei82557 (fei) device.** This routine loads the fei device with initial parameters.** RETURNS: pointer to END object or NULL.** ERRNO: N/A** 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; void *feiMemBase=NULL; if(!feiUnits) { /* Possible problem with sys557PciInit */ return NULL; } if (strlen (pParamStr) == 0) { /* * muxDevLoad() calls us twice. If the string is * zero length, then this is the first time through * this routine, so we just 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 */ /*allocate memory for FEI END device*/ feiMemBase = cacheDmaMalloc(FEI_TOTAL_SIZE); if (feiMemBase == NULL) { return NULL; } sprintf (cp, "0x%x:0x%x:0x%x:0x%x:0x00:2", (UINT32)feiMemBase, (UINT32)FEI_TOTAL_SIZE, (UINT32)FEI_N_TFDS, (UINT32)FEI_N_RFDS); /* set up BAR in PCI controller so that the PCI device can access the memory that has just been set up for it*/ if(sysPciMappingAdd((UINT32)feiMemBase, FEI_TOTAL_SIZE)!=OK) { printf("sysPciMappingAdd failed in sysLanPciInit\n"); cacheDmaFree (feiMemBase); return NULL; } if ((pEnd = fei82557EndLoad (paramStr)) == (END_OBJ *)NULL) { printf ("Error: device failed fei82557EndLoad routine.\n"); } } return (pEnd); }/********************************************************************************* sys557PciInit - prepare LAN adapter for 82557 initialization** This routine discovers the PCI device, and maps its memory and IO address.* It must be done prior to initializing the 82557, sys557Init(). Also* must be done prior to MMU initialization, usrMmuInit().** ERRNO: N/A** RETURNS: N/A*/void sys557PciInit (void) { FEI_RESOURCE *pReso; int pciBus; int pciDevice; int pciFunc; int unit; BOOL duplicate; UINT32 membaseCsr; UINT32 iobaseCsr; UINT32 membaseFlash; char irq; int ix; for (unit = 0; unit < FEI_MAX_UNITS; unit++) { if (pciFindDevice ((PCI_ID_I82557 & 0xffff), (PCI_ID_I82557 >> 16), unit, &pciBus, &pciDevice, &pciFunc) != OK) if (pciFindDevice ((PCI_ID_I82559 & 0xffff), (PCI_ID_I82559 >> 16), unit, &pciBus, &pciDevice, &pciFunc) != OK) if (pciFindDevice ((PCI_ID_I82559ER & 0xffff), (PCI_ID_I82559ER >> 16), unit, &pciBus, &pciDevice, &pciFunc) != OK) break; /* check the duplicate */ pReso = &feiResources [0]; duplicate = FALSE; for (ix = 0; ix < FEI_MAX_UNITS; ix++, pReso++) { if ((ix != unit) && (pReso->pciBus == pciBus) && (pReso->pciDevice == pciDevice) && (pReso->pciFunc == pciFunc)) duplicate = TRUE; } if (duplicate) continue; /* we found the right one */ pReso = &feiResources [unit]; pReso->pciBus = pciBus; pReso->pciDevice = pciDevice; pReso->pciFunc = pciFunc; /* get memory base address and IO base address */ pciConfigInLong (pReso->pciBus, pReso->pciDevice, pReso->pciFunc, PCI_CFG_BASE_ADDRESS_0, &membaseCsr); pciConfigInLong (pReso->pciBus, pReso->pciDevice, pReso->pciFunc, PCI_CFG_BASE_ADDRESS_1, &iobaseCsr); pciConfigInLong (pReso->pciBus, pReso->pciDevice, pReso->pciFunc, PCI_CFG_BASE_ADDRESS_2, &membaseFlash);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -