📄 syspnic169end.c
字号:
/* sysPnic169End.c - system configuration module for PNIC169 END *//* * Copyright 1989-2001 Wind River Systems, Inc. *//*modification history--------------------01a,21mar01,g_h written*//*DESCRIPTIONThis is the WRS-supplied configuration module for the VxWorkspnic169End (fei) END driver. It performs the dynamic parameterizationof the pnic169End driver. This technique of 'just-in-time'parameterization allows driver parameter values to be declaredas something other than static strings.*/#if (defined(INCLUDE_PNIC169END) && defined (INCLUDE_NETWORK) && defined (INCLUDE_END))#include "copyright_wrs.h"#include "vxWorks.h"#include "taskLib.h"#include "sysLib.h"#include "end.h"#include "config.h"#include "pnic169End.h"IMPORT END_OBJ * pnic169EndLoad(char *);#define PCI2DRAM_BASE_ADRS 0x00000000 /* memory seen from PCI bus */#define CSR_BASE_MSK 0x7f /* Mask Base Address Register */#define PNIC_USER_FLAGS 0/* forward declarations *//* typedefs */typedef struct pnicResource /* PCI_RESOURCES */ { UINT32 iobaseCsr; /* Base Address Register 0 */ UINT32 membaseCsr; /* Base Address Register 1 */ char irq; /* Interrupt Request Level */ UINT32 irqvec; /* Interrupt Request vector */ UINT32 pciBus; /* PCI Bus number */ UINT32 pciDevice; /* PCI Device number */ UINT32 pciFunc; /* PCI Function number */ } PNIC_RESOURCES;/* locals *//* * This array defines the board-specific PCI resources, the base address * register configuration mode and the Ethernet adapter type. It's indexed * using the device number returned from pciFindDevice(). */LOCAL PNIC_RESOURCES pnicResources = {(UINT32)-1,(UINT32)-1,};/************************************************************************* sysPnic169EndLoad - load pnic169 (pnic) device.** This routine loads the pnic device with initial parameters.** RETURNS: pointer to END object or ERROR.** SEE ALSO: pnic169EndLoad()*/END_OBJ * sysPnic169EndLoad ( char * pParamStr, /* ptr to initialization parameter string */ void * unused /* unused optional argument */ ) { /* * The pnic169End driver END_LOAD_STRING should be: * "<devAdrs>:<PCIadrs>:<ivec>:<ilevel>:<memBase>:<memSize>:<userFlags>:<offset>" */ char * cp; char paramStr [END_INIT_STR_MAX]; /* from end.h */ END_OBJ * pEnd; 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 = pnic169EndLoad (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 */ sprintf (cp, "0x00:0x00:0x00:0x00:0x%x:0x%x:0x%x:0", 0xffffffff,0,PNIC_USER_FLAGS); if ((pEnd = pnic169EndLoad (paramStr)) == NULL) printf ("Error: device failed pnic169EndLoad routine.\n"); } return pEnd; }/************************************************************************ sysPnic169PciInit - prepare LAN adapter for PNIC169 initialization** This routine finds the PNIC169 device, and maps its memory and IO address.* It must be done prior to initializing the PNIC169, sysPnic169Init(). Also* must be done prior to MMU initialization, usrMmuInit().** RETURNS: N/A**/void sysPnic169PciInit ( void ) { PNIC_RESOURCES * pRsrc; /* pnic resource */ volatile UINT32 pciBus; /* PCI Bus number */ volatile UINT32 pciDevice; /* PCI Device number */ volatile UINT32 pciFunc; /* PCI Function number */ volatile UINT32 membaseCsr; /* Base Address Register 1 */ volatile UINT32 iobaseCsr; /* Base Address Register 0 */ volatile char irq; /* Interrupt Request Level */ volatile UINT32 cmdsts; /* command and status registers */ int indexUnits = 0; if (pciFindDevice (PNIC_PCI_VENDORID,PNIC_PCI_DEVICEID,indexUnits, (int*)&pciBus, (int*)&pciDevice, (int*)&pciFunc) == OK) { /* select the media function */ _func_pnic169MediaSelect = NULL; pRsrc = &pnicResources; pRsrc->pciBus = pciBus; pRsrc->pciDevice = pciDevice; pRsrc->pciFunc = pciFunc; /* get memory base address and IO base address */ pciConfigInLong(pciBus,pciDevice,pciFunc, 4, (UINT32*)&cmdsts); pciConfigInLong(pciBus,pciDevice,pciFunc, PCI_CFG_BASE_ADDRESS_0, (UINT32*)&iobaseCsr); pciConfigInLong(pciBus,pciDevice,pciFunc, PCI_CFG_BASE_ADDRESS_1, (UINT32*)&membaseCsr); pciConfigInByte(pciBus,pciDevice,pciFunc, PCI_CFG_DEV_INT_LINE, (UINT8*)&irq); membaseCsr &= ~CSR_BASE_MSK; iobaseCsr &= ~CSR_BASE_MSK; /* overwrite the resource table with read value */ pRsrc->membaseCsr = membaseCsr; pRsrc->iobaseCsr = iobaseCsr; pRsrc->irqvec = irq+INT_VEC_EXT_IRQ0; pRsrc->irq = irq; } return; }/************************************************************************* sysPnic169Init - prepare LAN adapter for pnic169 initialization** This routine is expected to perform any adapter-specific or target-specific* initialization that must be done prior to initializing the pnic169** The pnic169 driver calls this routine from the driver endLoad routine before* any other routines in this library.** This routine returns the base address, the main memory address over the PCI* bus, the interrupt level and the interrupt vector parameter.** RETURNS: OK or ERROR if the adapter could not be prepared for initialization.*/STATUS sysPnic169Init ( PNIC169_DRV_CTRL *pDrvCtrl ) { PNIC_RESOURCES * pRsrc = &pnicResources; if (pRsrc->iobaseCsr != (UINT32)-1 && pRsrc->membaseCsr != (UINT32)-1) { /* set the device control structure */ /* Using membaseCSR instead of iobaseCsr.*/ pDrvCtrl->devAdrs = pRsrc->membaseCsr; pDrvCtrl->pciMemBase = PCI2DRAM_BASE_ADRS; pDrvCtrl->ivec = pRsrc->irqvec; pDrvCtrl->ilevel = pRsrc->irq; return OK; } return ERROR; }/************************************************************************* sysPnic169IntEnable - enable pnic169 interrupts** This routine enables pnic169 interrupts. This may involve operations on* interrupt control hardware.** RETURNS: OK or ERROR for invalid arguments.*/STATUS sysPnic169IntEnable ( int level /* level number */ ) { return(intEnable (level)); }/************************************************************************* sysPnic169IntDisable - disable pnic169 interrupts** This routine disables pnic169 interrupts. This may involve operations on* interrupt control hardware.** RETURNS: OK or ERROR for invalid arguments.*/STATUS sysPnic169IntDisable ( int level /* level number */ ) { return(intDisable (level)); }/************************************************************************* sysPnic169EnetAddrGet - get Ethernet address** This routine provides a target-specific interface for accessing a* device Ethernet address.** RETURNS: OK or ERROR if could not be obtained.*/STATUS sysPnic169EnetAddrGet ( int unit, char * enetAdrs ) { int i,j; long * csr; PNIC_RESOURCES * pRsrc = &pnicResources; /* base mem Address of Netgear CSR regs */ csr = (long *)pRsrc->membaseCsr; /* * Get the Netgear card's MAC from EEPROM. * The user could actually pass back any MAC address. */ for (i = 0; i < 3;++i) { long mac16, timeout = 0x1000; csr[0x98/4] = PCISWAP(0x0600 | i); do { for (j=0 ; j < 0x100; j++); /* waste time */ mac16 = PCISWAP(csr[9*8/4]); /* CSR9 */ }while(mac16 < 0 && --timeout > 0); /* mac address is byte swapped */ enetAdrs[i*2] = (mac16 & 0x0ff00) >> 8; enetAdrs[i*2+1] = (mac16 & 0x000ff); } return OK; }#endif /* defined (INCLUDE_PNIC169END) && defined (INCLUDE_NETWORK) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -