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

📄 sysnetif.c

📁 VxWorks下 Spruce的BSP源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* sysNetif.c - system network interface support library *//* * Copyright 1989-1996 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------01g,14apr98,sbs  added feiIntConnect and it's initialization.01f,17mar98,sbs  moved PRO100B PCI definitions to if_fei.h.                 documentation corrections.01e,03mar98,sbs  removed update of mmu table entries.                 using sysMmuMapAdd() for adding mmu entries.                 added extra members to feiResource structure.                 changed initialization of feiResources arrray. 01d,03dec96,hdn  changed UINT32 to INT32 for timeout, str[6], *pResults.		 added sys557PciInit(). added configType to the resource.01c,20nov96,dat  chg'd name to sysNetif.c, incorporated #defines		 and struct typedefs from header file. Combines old		 if_eex32.c and if_i82557.c files.01b,07nov96,hdn  re-written.01a,31aug96,dzb  written, based on v01a of src/drv/netif/if_iep.c.*//*Currently, this module only supports the Intel EtherExpress PRO100B LANAdapter.  If support for more 82557-based adapters is desired, this modulemust be modified.SEE ALSO: ifLib,.I "Intel 82557 User's Manual,".I "Intel PRO100B PCI Adapter Driver Technical Reference,"*/#include "vxWorks.h"#include "taskLib.h"#if 0 /* ZZZZZZZZZ */#include "sysLib.h"#endif#include "config.h"#include "stdio.h"#define INCLUDE_FEI#ifdef INCLUDE_FEI	/* Intel 82557 (Fast EI) Support */#include "./if_fei.h"/* ZZZZZZZZZ */#include "drv/pci/pciConfigLib.h"#include "intLib.h"#include "cpc700.h"/* imports */IMPORT FUNCPTR feiIntConnect;#if 0 /* ZZZZZZZZZZ */IMPORT STATUS sysCPC700IntConnect(VOIDFUNCPTR *, VOIDFUNCPTR, int) ;IMPORT STATUS sysCPC700IntDisable(int) ;IMPORT STATUS sysCPC700IntEnable(int) ;#endif/* ZZZZZZZZZZZZZZZ */IMPORT int pciFindFirstDevice(					unsigned short VendorID,			unsigned short DeviceID) ;IMPORT int sysLanIntEnable (int intlvl) ;IMPORT int sysLanIntDisable (int intlvl) ;IMPORT int pciConfigIn (int, int, int) ;IMPORT void pciConfigOut (int, int, UINT, int) ;IMPORT void sysDelay(void) ;IMPORT ULONG sysPciInLong(ULONG) ;IMPORT void sysPciOutLong(ULONG, ULONG) ;IMPORT void sysPciOutWord(ULONG, USHORT) ;IMPORT USHORT sysPciInWord(ULONG) ;IMPORT USHORT sysInWord(ULONG) ;IMPORT void sysOutWord(ULONG, USHORT) ;/* ZZZZZZZZZZZZZZZ *//* defines */#ifdef I82557_DEBUG#   undef	LOCAL#   define	LOCAL#endif	/* I82557_DEBUG *//* Intel EtherExpress PRO100B LAN Adapter type */#define	TYPE_PRO100B_PCI	1	/* Intel EtherExpress PRO-100B PCI *//* EEPROM control bits */#define EE_SK		0x01		/* shift clock, bit 16 */#define EE_CS		0x02		/* chip select, bit 17 */#define EE_DI		0x04		/* chip data in, bit 18 */#define EE_DO		0x08		/* chip data out, bit 19, 20-23 rsvd *//* EEPROM opcode *//* Apparently includes start bit */#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 */#if 1#define EE_ADDR_BITS	6		/* number of address bits */#define EE_SIZE		0x40		/* 0x40 words, 0x80 bytes  */#endif#if 0#define EE_ADDR_BITS    7#define EE_SIZE         0x80#endif#define EE_DATA_BITS	16		/* number of data bits */#define EE_CHECKSUM	0xbaba		/* checksum *//* unknown values */#define UNKNOWN 	-1/* 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 */    UINT16	eeprom[0x40];		/* Ethernet Address of this unit */    INT32	timeout;		/* timeout for the self-test */    INT32	str[6];			/* storage for the self-test result */    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 */LOCAL UINT32 feiUnits;			/* number of FEIs we found */LOCAL FEI_RESOURCE feiResources [FEI_MAX_UNITS] =    {    {UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,     UNKNOWN, UNKNOWN, UNKNOWN},    {UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,     UNKNOWN, UNKNOWN, UNKNOWN},    {UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,     UNKNOWN, UNKNOWN, UNKNOWN},    {UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,     UNKNOWN, UNKNOWN, UNKNOWN},     };#if 0 /* original, hardcoded. pc.h defined these fixed constants */LOCAL FEI_RESOURCE feiResources [FEI_MAX_UNITS] =    {    {FEI0_MEMBASE0, FEI0_IOBASE0, FEI0_MEMBASE1, FEI0_INT_LVL, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,      FEI0_MEMSIZE0, FEI0_INIT_STATE_MASK, FEI0_INIT_STATE},    {FEI1_MEMBASE0, FEI1_IOBASE0, FEI1_MEMBASE1, FEI1_INT_LVL, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,      FEI1_MEMSIZE0, FEI1_INIT_STATE_MASK, FEI1_INIT_STATE},    {FEI2_MEMBASE0, FEI2_IOBASE0, FEI2_MEMBASE1, FEI2_INT_LVL, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,     FEI2_MEMSIZE0, FEI2_INIT_STATE_MASK, FEI2_INIT_STATE},    {FEI3_MEMBASE0, FEI3_IOBASE0, FEI3_MEMBASE1, FEI3_INT_LVL, UNKNOWN,     UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, {UNKNOWN}, UNKNOWN, {UNKNOWN}, NULL,     FEI3_MEMSIZE0, FEI3_INIT_STATE_MASK, FEI3_INIT_STATE},     };#endifLOCAL 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 */LOCAL UINT16	sys557eepromRead (int unit, int location);#if 0LOCAL 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);#endifLOCAL int       sys557IntAck     (int unit);/********************************************************************************* 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)    {    FEI_RESOURCE *pReso;    int pciBus;    int pciDevice;    int pciFunc;    int unit;    BOOL duplicate;    UINT32 membaseCsr;    UINT32 iobaseCsr;    UINT32 membaseFlash;    char irq;    int ix;    int busDevFunc ;    int intvec, intlvl ;#ifdef DEBUGprintf("(sys557PciInit)\n") ;#endif    for (unit = 0; unit < FEI_MAX_UNITS; unit++)    {#ifdef INCLUDE_SPRUCE_NETWORK        if ((busDevFunc = pciFindFirstDevice (PRO100B_PCI_VENDOR_ID, 					      PRO100B_PCI_DEVICE_ID)) == -1)#else        if (pciFindDevice (PRO100B_PCI_VENDOR_ID, PRO100B_PCI_DEVICE_ID, unit,                           &pciBus, &pciDevice, &pciFunc) != OK)#endif	{	    printf("Device not found.\n") ;	}	else	{		/* ZZZZZZZZZZZZZ */		/* max pciBus = 255, 8 bits,                    max pciDevice = 32, 		   max pciFunc = 8 */		pciBus =  (int)((busDevFunc >> 16) & 0xff) ;		pciDevice = (int)((busDevFunc >> 11) & 0x1f) ;		pciFunc = 0 ;#ifdef DEBUG		printf("pciBus: 0x%x\n", pciBus) ;		printf("pciDevice: 0x%x\n", pciDevice) ;#endif	}	/* 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;#if 0 	/* Does a static configuration */        if (PCI_CFG_TYPE == PCI_CFG_FORCE)             {            pciConfigOutLong (pReso->pciBus, pReso->pciDevice, pReso->pciFunc,                              PCI_CFG_BASE_ADDRESS_0, pReso->membaseCsr);            pciConfigOutLong (pReso->pciBus, pReso->pciDevice, pReso->pciFunc,                              PCI_CFG_BASE_ADDRESS_1, pReso->iobaseCsr |                              PCI_BASE_IO);            pciConfigOutLong (pReso->pciBus, pReso->pciDevice, pReso->pciFunc,                              PCI_CFG_BASE_ADDRESS_2, pReso->membaseFlash);            pciConfigOutByte (pReso->pciBus, pReso->pciDevice, pReso->pciFunc,                              PCI_CFG_DEV_INT_LINE, pReso->irq);            }	pciConfigOut (			busDevFunc,			PCI_CFG_BASE_ADDRESS_0,			pReso->membaseCsr,			4 ) ;	pciConfigOut (			busDevFunc,			PCI_CFG_BASE_ADDRESS_1,			pReso->iobaseCsr | PCI_BASE_IO,			4 ) ;	pciConfigOut (			busDevFunc,			PCI_CFG_BASE_ADDRESS_2,			pReso->membaseFlash,			4 ) ;	pciConfigOut (			busDevFunc,			PCI_CFG_DEV_INT_LINE,			pReso->irq,			1 ) ;#endif        /* get memory base address and IO base address */#ifdef INCLUDE_SPRUCE_NETWORK        membaseCsr = pciConfigIn(				busDevFunc, 				PCI_CFG_BASE_ADDRESS_0, 				4);        iobaseCsr = pciConfigIn(				busDevFunc, 						PCI_CFG_BASE_ADDRESS_1, 				4);        membaseFlash = pciConfigIn(				busDevFunc, 				PCI_CFG_BASE_ADDRESS_2, 				4) ;	/* Hard coded to INTA line on the 82559... */        irq = pciConfigIn(			busDevFunc, 			PCI_CFG_DEV_INT_LINE, 			1) ;#else	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);        pciConfigInByte (pReso->pciBus, pReso->pciDevice, pReso->pciFunc,	                 PCI_CFG_DEV_INT_LINE, &irq);#endif	membaseCsr   &= PCI_MEMBASE_MASK; /* (~0xf) */	iobaseCsr    &= PCI_IOBASE_MASK;  /* (~0x3) */	membaseFlash &= PCI_MEMBASE_MASK; /* (~0xf) */	{	#ifdef DEBUG	UINT32 subsystem_info, exp_rom  ;	subsystem_info = pciConfigIn(busDevFunc, 0x2c, 4) ;	printf("pci subsystem info: 0x%x\n", subsystem_info) ;	exp_rom = pciConfigIn(busDevFunc, 0x30, 4) ;	printf("expansion rom base addr reg: 0x%x\n", exp_rom) ;#endif	}#if 0 /* ?????????? */	/* add the entry to sysPhysMemDesc[] */        if (sysMmuMapAdd((void *)membaseCsr, pReso->memLength,                          pReso->initialStateMask,                           pReso->initialState) == ERROR)            break; #endif#ifdef INCLUDE_SPRUCE_NETWORK    /*     * Each PCI slot on the Spruce board is connected to a different pin on     * the CPC700's integrated Universal Interrupt Controller.  Determine the     * interrupt level based on the PCI slot the Ethernet card is plugged in.     */    switch ((busDevFunc & 0x0000F800) >> 11)     /* Strip off just the device */        {        case 1 :  intvec = INT_VEC_PCI_SLOT3;         /* Spruce connector J25 */                  intlvl = INT_LVL_PCI_SLOT3;                  break;        case 2 :  intvec = INT_VEC_PCI_SLOT2;         /* Spruce connector J26 */                  intlvl = INT_LVL_PCI_SLOT2;                  break;        case 3 :  intvec = INT_VEC_PCI_SLOT1;         /* Spruce connector J29 */                  intlvl = INT_LVL_PCI_SLOT1;                  break;        case 4 :  intvec = INT_VEC_PCI_SLOT0;         /* Spruce connector J31 */                  intlvl = INT_LVL_PCI_SLOT0;                  break;        }	pReso->irq          = intlvl ;#else	pReso->irq          = irq ;#endif	/* over write the resource table with read value */	pReso->membaseCsr   = membaseCsr;	pReso->iobaseCsr    = iobaseCsr;	pReso->membaseFlash = membaseFlash;#ifdef DEBUG	printf("membaseCsr: 0x%x\n", membaseCsr) ;	printf("iobaseCsr: 0x%x\n", iobaseCsr) ;	printf("membaseFlash: 0x%x\n", membaseFlash) ;	printf("irq: 0x%x\n", irq) ;#endif	/* enable mapped memory and IO addresses */#ifdef INCLUDE_SPRUCE_NETWORK	pciConfigOut ( busDevFunc,                       PCI_CFG_COMMAND, 		      (/*PCI_CMD_IO_ENABLE |  */		       PCI_CMD_MEM_ENABLE | 		       PCI_CMD_MASTER_ENABLE),	 	       2 );#else	pciConfigOutWord (pReso->pciBus, pReso->pciDevice, pReso->pciFunc,			  PCI_CFG_COMMAND, PCI_CMD_IO_ENABLE |			  PCI_CMD_MEM_ENABLE | PCI_CMD_MASTER_ENABLE);#endif	feiUnits++;	}#if 0 /* ???????? */    /* specify the interrupt connect routine to be used */     feiIntConnect = (FUNCPTR) pciIntConnect;#endif    feiIntConnect = (FUNCPTR) intConnect ;          pReso->boardType = ~TYPE_PRO100B_PCI ;    }/********************************************************************************* 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,			/* unit number */    BOARD_INFO *pBoard		/* board information */    )    {    FEI_RESOURCE *pReso = &feiResources [unit];    UINT16 sum          = 0;    int	ix;    int	iy;    UINT16 value;#ifdef DEBUGprintf("(sys557Init)\n") ;#endif

⌨️ 快捷键说明

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