📄 gei82543init.c
字号:
/* sysGei82543End.c - Intel Pro1000 F/T Adapter END driver support routines *//* Copyright 1989-2001 Wind River Systems, Inc. *//* Copyright 2001 Motorola, Inc. All Rights Reserved *//*modification history--------------------01e,10jul02,dtr SPR 79571. Slight API change to an unused function sys543IntEnable/Disable.01d,28nov01,dtr Tidy up.01c,25Nov01,dtr Modified sys543LocalToPciBus etc for new PCI configuration.01b,31jul01,srr Added support for PrPMC-G.01a,08Jan01,jln written based on sysNetif.c.*//*This module is BSP support for Intel PRO1000 F/T adaptors.SEE ALSO: ifLib,.I "RS82543GC GIGABIT ETHERNET CONTROLLER NETWORKING SILICON DEVELOPER'S MANUAL"*/#include "gei82543Lib.h"#ifdef I82543_DEBUG#undef LOCAL#define LOCAL#endif /* I82543_DEBUG *//* include PCI Library */#ifndef INCLUDE_PCI#define INCLUDE_PCI#endif /* INCLUDE_PCI *//* PCI configuration type */#ifndef PCI_CFG_TYPE#define PCI_CFG_TYPE PCI_CFG_NONE#endif/* Default RX descriptor */#ifndef GEI_RXDES_NUM#define GEI_RXDES_NUM GEI_DEFAULT_RXDES_NUM#endif/* Default TX descriptor */#ifndef GEI_TXDES_NUM#define GEI_TXDES_NUM GEI_DEFAULT_TXDES_NUM#endif/* Default User's flags */#ifndef GEI_USR_FLAG#define GEI_USR_FLAG GEI_DEFAULT_USR_FLAG#endif#define GEI82543_LOAD_FUNC gei82543EndLoad#define GEI_X86_OFFSET_VALUE 0x0/* Alaska PHY's information */#define MARVELL_OUI_ID 0x5043#define MARVELL_ALASKA_88E1000 0x5#define MARVELL_ALASKA_88E1000S 0x4#define ALASKA_PHY_SPEC_CTRL_REG 0x10#define ALASKA_PHY_SPEC_STAT_REG 0x11#define ALASKA_INT_ENABLE_REG 0x12#define ALASKA_INT_STATUS_REG 0x13#define ALASKA_EXT_PHY_SPEC_CTRL_REG 0x14#define ALASKA_RX_ERROR_COUNTER 0x15#define ALASKA_LED_CTRL_REG 0x18#define ALASKA_PSCR_ASSERT_CRS_ON_TX 0x0800#define ALASKA_EPSCR_TX_CLK_25 0x0070#define ALASKA_PSCR_AUTO_X_1000T 0x0040#define ALASKA_PSCR_AUTO_X_MODE 0x0060#define ALASKA_PSSR_DPLX 0x2000#define ALASKA_PSSR_SPEED 0xC000#define ALASKA_PSSR_10MBS 0x0000#define ALASKA_PSSR_100MBS 0x4000#define ALASKA_PSSR_1000MBS 0x8000/* assuming 1:1 mapping for virtual:physical address */#if 0/*(_BYTE_ORDER == _BIG_ENDIAN)*/#define GEI_SYS_WRITE_REG(unit, reg, value) \ ((*(volatile UINT32 *)(PCI_MEMIO2LOCAL(geiResources[(unit)].memBaseLow) + (reg))) = \ (UINT32) Drv_Swap32(value))#define GEI_SYS_READ_REG(unit, reg) \ (Drv_Swap32( *(volatile UINT32 *)(PCI_MEMIO2LOCAL(geiResources[(unit)].memBaseLow) + (reg))) )#else /* (_BYTE_ORDER != _BIG_ENDIAN) */#define GEI_SYS_WRITE_REG(unit, reg, value) \ ((*(volatile UINT32 *)(PCI_MEMIO2LOCAL(geiResources[(unit)].memBaseLow) + (reg))) = \ (UINT32)(value))#define GEI_SYS_READ_REG(unit, reg) \ (*(volatile UINT32 *)(PCI_MEMIO2LOCAL(geiResources[(unit)].memBaseLow) + (reg)))#endif /* (_BYTE_ORDER == _BIG_ENDIAN) *//* externs */IMPORT END_TBL_ENTRY endDevTbl[]; /* end device table */#define GEI_LOCAL2PCI_MEMIO(x) (x)#define GEI_PCI_MEMIO2LOCAL(x) (x)#if 0#define IF_SUBTYPE_REG (0x7c04)#define IF_ATT_REG (0x7c20) /* if card attribute reg offset. */#endif#define ETHERNET_IP_MAP_MULTICAST(_mac_, _ip_)\ do {\ (_mac_)[0] = 0x01;\ (_mac_)[1] = 0x00;\ (_mac_)[2] = 0x5e;\ (_mac_)[3] = (_ip_)[1] & 0x7f;\ (_mac_)[4] = (_ip_)[2];\ (_mac_)[5] = (_ip_)[3];\ } while (0)/* locals */LOCAL UINT32 sys543LocalToPciBusAdrs (int slot,UINT32 adrs);LOCAL UINT32 sys543PciBusToLocalAdrs (int slot,UINT32 adrs);GEI_RESOURCE geiResources [MAX_IF_CARD_NUM+1]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};/*lint !e940*//* globals *//* * NOTE: Each GEI device will need it's own lowMemBuf. * Since the PrPMC-G only has one GEI, this is all that is needed for now. */ /* i82543 buffer in low memory *//* forward declarations */LOCAL int sys543IntEnable (int slot);LOCAL int sys543IntDisable (int slot);LOCAL int sys543IntAck (int slot);LOCAL STATUS sys543EtherAdrGet (int unit);#if INSTALL_ON_PPC8241 /*lint !e553*/extern UINT8 devnumConvertIntnum(int,int);extern STATUS b_pciIntEnable(UINT8 );extern STATUS b_pciIntDisable(UINT8);#elseextern INT8 devnumConvertIntnum(int , int );extern STATUS b_pciIntEnable(INT8 );extern STATUS b_pciIntDisable(INT8);#endifSTATUS gei82543DrvIoctl(int,int,UINT8*);/*extern declarations*//******************************************************************************* sys543PciInit - Initialize and get the PCI configuration for 82543 Chips** This routine finds out PCI device, and maps its memory and IO address.* It must be done prior to initializing of 82543 chips. Also* must be done prior to MMU initialization, usrMmuInit().** RETURNS: N/A*/STATUS sys543PciInit (UINT8 slot){ GEI_RESOURCE *pReso; /* chip resources */ int pciBus; /* PCI bus number */ int pciDevice; /* PCI device number */ int pciFunc; /* PCI function number */ UINT32 bar0; /* PCI BAR_0 */ /*UINT32 memBaseLow; mem base low */ UINT16 boardId =0; /* adaptor Id */ if ((slot <1)||(slot>MAX_IF_CARD_NUM)) { return ERROR; } if (ERROR==b_ifPciSlotToID(slot,&pciBus,&pciDevice) ) { return ERROR; } pciFunc = 0; pciConfigInWord(pciBus, pciDevice, pciFunc, PCI_CFG_SUB_SYSTEM_ID, &boardId); pReso = &geiResources [slot]; pReso->boardType = boardId; pReso->pciBus = pciBus; pReso->pciDevice = pciDevice; pReso->pciFunc = pciFunc; pciConfigInLong (pReso->pciBus, pReso->pciDevice, pReso->pciFunc, PCI_CFG_BASE_ADDRESS_0, &bar0); /*2006-11-15 , 为什么 PCI Membase Address 地址不是16字节对齐?*/ bar0 &= PCI_MEMBASE_MASK; pReso->memBaseLow = bar0;#if INSTALL_ON_PPC8241 pReso->irq = devnumConvertIntnum(pciBus,pciDevice);#endif#if INSTALL_ON_PPC8349 /*lint !e553*/ pReso->irq = devnumConvertIntnum(pciBus,pciDevice);#endif#if INSTALL_ON_PPC8347 /*lint !e553*/ pReso->irq = devnumConvertIntnum(pciBus,pciDevice);#endif#if INSTALL_ON_PPC8541 pReso->irq = devnumConvertIntnum(pciBus,pciDevice);#endif /* enable mapped memory and IO addresses */ pciConfigOutWord (pReso->pciBus, pReso->pciDevice, pReso->pciFunc, PCI_CFG_COMMAND, PCI_CMD_IO_ENABLE | PCI_CMD_MEM_ENABLE | PCI_CMD_MASTER_ENABLE); return OK;}/******************************************************************************* sys82543BoardInit - Adaptor initialization for 82543 chip** This routine is expected to perform any adapter-specific or target-specific* initialization that must be done prior to initializing the 82543 chip.** The 82543 driver calls this routine from the driver load routine before* any other routines.** RETURNS: OK or ERROR*/STATUS sys82543BoardInit ( int slot, /* slot number */ ADAPTOR_INFO *pBoard /* board information for the GEI driver */ ){ GEI_RESOURCE *pReso =(GEI_RESOURCE *)NULL; if (slot<1||slot>MAX_IF_CARD_NUM) { return ERROR; } pReso = &geiResources [slot]; if((GEI_RESOURCE *)NULL==pReso) { return ERROR; } if (pReso->boardType != PRO1000F_BOARD && pReso->boardType != PRO1000T_BOARD) { return ERROR; } /* get the Ethernet Address from eeprom */ if (sys543EtherAdrGet (slot) != OK) { printf ("GEI82543:slot=%d, Invalid Ethernet Address!\n", slot); } /* initializes the board information structure */ pBoard->boardType =(UINT32)pReso->boardType; pBoard->vector = (int)pReso->irq; pBoard->regBaseLow = pReso->memBaseLow; pBoard->intEnable =sys543IntEnable; pBoard->intDisable = sys543IntDisable; pBoard->intAck = sys543IntAck; if (pBoard->boardType == PRO1000T_BOARD) { pBoard->phyType = GEI_PHY_GMII_TYPE; } pBoard->delayFunc = (FUNCPTR) NULL; pBoard->delayUnit = 1000; /* sys1000NsDelay() delays 1000ns */ pBoard->sysLocalToBus = sys543LocalToPciBusAdrs; pBoard->sysBusToLocal = sys543PciBusToLocalAdrs; /* specify the interrupt connect/disconnect routines to be used */ pBoard->intConnect = (FUNCPTR) b_pciIntConnect; pBoard->intDisConnect = (FUNCPTR) b_pciIntDisconnect; /* copy Ether address */ memcpy (&pBoard->enetAddr[0], &geiResources[slot].enetAddr[0], ETHER_ADDRESS_SIZE); /* we finished adaptor initialization */ pReso->iniStatus = OK; return (OK);}/*************************************************************************** sys543EtherAdrGet - Get Ethernet address from EEPROM** This routine get an Ethernet address from EEPROM** RETURNS: OK or ERROR*/LOCAL STATUS sys543EtherAdrGet ( int unit ){ UCHAR aprom[ETHER_ADDRESS_SIZE]; Ros_GetMacBase(b_FetchSerial(),aprom); memcpy (&geiResources[unit].enetAddr[0], aprom, ETHER_ADDRESS_SIZE); return OK;}/*configure the multicast address of the device*/ void gei82543IsisSet(int slot){ unsigned char isMac1[6] = {0x01,0x80,0xc2,0x00,0x00,0x14}; unsigned char isMac2[6] = {0x01,0x80,0xc2,0x00,0x00,0x15}; unsigned char isMacStp[6] = {0x01,0x80,0xc2,0x00,0x00,0x00}; unsigned char isMacLacp[6] = {0x01,0x80,0xc2,0x00,0x00,0x02}; unsigned char isMacDot1x[6] = {0x01,0x80,0xc2,0x00,0x00,0x03}; unsigned char isMacGmrp[6] = {0x01,0x80,0xc2,0x00,0x00,0x20}; unsigned char isMacGvrp[6] = {0x01,0x80,0xc2,0x00,0x00,0x21}; UINT8 multiIp[][4] = { { 224, 0, 0, 2 }, { 224, 0, 0, 5 }, { 224, 0, 0, 6 }, { 224, 0, 0, 9 }, { 224, 0, 0, 18}}; unsigned char multiMac[6]; UINT8 *pIpAddr; int i; gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMac1); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMac2); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMac1); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMacStp); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMacLacp); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMacDot1x); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMacGmrp); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, isMacGvrp); for (i = 0; (UINT16)i < sizeof(multiIp)/sizeof(multiIp[0]); i++) { pIpAddr = multiIp[i]; ETHERNET_IP_MAP_MULTICAST(multiMac, pIpAddr); gei82543DrvIoctl(slot, DRV_ETHER_ADD_MAC_MULTI_ADDRESS, multiMac); } return;}STATUS gei82543DrvIoctl ( int slot, int cmd, UINT8 *data ) { END_DEVICE * pDrvCtrl=(END_DEVICE *)NULL; UINT32 gPort; if (slot <1||slot >MAX_IF_CARD_NUM) { return ERROR; } /* find the dev's end_device */ if ((pDrvCtrl = gei82543Unit(slot)) == (END_DEVICE*)NULL) { return ERROR; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -