📄 sysgei82544end.c
字号:
/* sysGei82543End.c - template for system configuration module for gei82543End *//* Copyright 2002 Wind River Systems, Inc. */#include "copyright_wrs.h"/*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.*//*This module is the WRS-supplied configuration module for Intel PRO1000F/T/XF/XT adapters. It has routines for initializing device resourcesand provides BSP-specific gei82543End (gei) END driver routines forIntel 82543 and 82544 Ethernet PCI bus controllers.The number of supported devices that can be configured for a particularsystem is finite and is specified by the GEI_MAX_DEV configurationconstant. This value, and the internal data structures using it, can bemodified in this file for specific implementations.SEE ALSO: ifLib,.I "RS82543GC GIGABIT ETHERNET CONTROLLER NETWORKING SILICON DEVELOPER'S MANUAL"*/#ifdef INCLUDE_GEI_END#include "vxWorks.h"#include "config.h"#include "stdio.h"#include "sysLib.h"#include "logLib.h"#include "intLib.h"#include "taskLib.h"#include "end.h"#include "drv/pci/pciConfigLib.h"#include "drv/end/gei82543End.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.) */#define SYS_GEI_DEBUG#define SYS_543_EEPROM_UTILS#define PRO1000_543_PCI_DEVICE_ID_1 0x1001#define PRO1000_543_PCI_DEVICE_ID_2 0x1004#define PRO1000_544_PCI_DEVICE_ID_1 0x1008 /* Copper */#define PRO1000_544_PCI_DEVICE_ID_2 0x1009 /* Fiber */#define PRO1000_544_PCI_DEVICE_ID_3 0x100C /* Copper */#define EEPROM_EWEN_OPCODE 0x0130 /* Erase-write enable */#define EEPROM_EWDS_OPCODE 0x0100 /* Erase-write disable */#define EEPROM_ERAL_OPCODE 0x0120 /* Erase all */#ifdef SYS_GEI_DEBUG#undef LOCAL#define LOCAL#define SYS_GEI_LOG(format, arg1, arg2, arg3, arg4, arg5, arg6) \ do { \ if (_func_logMsg != NULL) \ _func_logMsg ((format), (arg1), (arg2), (arg3), \ (arg4), (arg5), (arg6)); \ } while (0);#else#define SYS_GEI_LOG(format, arg1, arg2, arg3, arg4, arg5, arg6)#endif /* SYS_GEI_DEBUG */IMPORT void sysUsDelay (int);#define SYS_DELAY(delay) sysUsDelay(delay)#ifndef SYS_GEI_MAX_UNITS#define SYS_GEI_MAX_UNITS SYS_GEI_UNITS#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/* PCI configuration type */#ifndef PCI_CFG_TYPE#define PCI_CFG_TYPE PCI_CFG_NONE#endif/* INTEL 82544 INTERNAL PHY */#define INTEL_82544PHY_OUI_ID (0x5043)#define INTEL_82544PHY_MODEL (0x3)#define INTEL_82544PHY_PHY_SPEC_CTRL_REG (0x10)#define INTEL_82544PHY_PHY_SPEC_STAT_REG (0x11)#define INTEL_82544PHY_INT_ENABLE_REG (0x12)#define INTEL_82544PHY_INT_STATUS_REG (0x13)#define INTEL_82544PHY_EXT_PHY_SPEC_CTRL_REG (0x14)#define INTEL_82544PHY_RX_ERROR_COUNTER (0x15)#define INTEL_82544PHY_PHY_GLOBAL_STAT (0x17)#define INTEL_82544PHY_LED_CTRL_REG (0x18)#define INTEL_82544PHY_PSCR_ASSERT_CRS_ON_TX (0x0800)#define INTEL_82544PHY_EPSCR_TX_CLK_25 (0x0070)/* 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 Little-Endian Arch */#define GEI_SYS_WRITE_REG(unit, reg, value) \ ((*(volatile UINT32 *)(geiResources[(unit)].memBaseLow + reg)) = \ (UINT32)(value))#define GEI_SYS_READ_REG(unit, reg) \ (*(volatile UINT32 *)(geiResources[(unit)].memBaseLow + reg))/* typedefs */typedef struct geiResource /* GEI_RESOURCE */ { UINT32 memBaseLow; /* Base Address MEM LOW (PCI address) */ UINT32 memBaseHigh; /* Base Address MEM HIGH (PCI address) */ UINT32 flashBaseLow; /* Base Address FLASH LOW (PCI address) */ UINT32 flashBaseHigh; /* Base Address FLASH HIGH (PCI address) */ UINT32 ioBase; /* Base Address IO (PCI address) */ BOOL addr64; /* flag to key 64bit addressing */ UINT16 pciVendID; /* Vendor ID */ UINT16 pciDevID; /* Device ID */ UINT16 subSysVendID; /* Subsystem Vendor ID */ UINT16 subSysDevID; /* Subsystem Device ID */ int boardType; /* type of LAN board this unit is */ int pciBus; /* PCI Bus number */ int pciDevice; /* PCI Device number */ int pciFunc; /* PCI Function number */ UINT8 pciIntPin; /* which PCI INT pin this unit use */ UINT8 irq; /* Interrupt Request Level */ UINT8 revID; /* Revision ID */ UINT8 classCode; /* Class Code */ UINT8 subClassCode; /* Sub-Class Code */ UINT8 progIF; /* Programming Interface */ UINT16 eeprom_icw1; /* EEPROM initialization control word 1 */ UINT16 eeprom_icw2; /* EEPROM initialization control word 2 */ UCHAR enetAddr[6]; /* MAC address for this adaptor */ STATUS iniStatus; /* initialization perform status */ UINT32 localToSysOffset; /* low part sysAddr - localAddr */ } GEI_RESOURCE;typedef struct _if_params { UINT32 rxDesNum; /* number of RX descriptors for this unit */ UINT32 txDesNum; /* number of TX descriptors for this unit */ UINT32 usrFlags; /* user flags for this unit */ UINT32 clSize; /* cluster size */ UINT32 mtu; /* mtu */ char * ipAddr; /* IP address string (dot notation) */ char * hostName; /* host name corresponding to IP address */ u_int subnetMask; /* subnet mask; host native byte order */ } IF_PARAMS;/* locals */LOCAL UINT32 geiUnits = 0 ; /* number of GEIs found so far */UINT32 sysGeiUnits = SYS_GEI_UNITS;LOCAL IF_PARAMS geiConfig [SYS_GEI_MAX_UNITS] = { { GEI_RXDES_NUM, GEI_TXDES_NUM, GEI_USR_FLAG, 0, /* use default cluster size */ 0, /* use default mtu */ GEI_IP_ADDR, GEI_HOST_NAME, GEI_SUBNET_MASK },#ifndef INCLUDE_FEI_END { GEI_RXDES_NUM, GEI_TXDES_NUM, GEI_USR_FLAG, 0, /* use default cluster size */ 0, /* use default mtu */ GEI_IP_ADDR, GEI_HOST_NAME, GEI_SUBNET_MASK },#endif /* Add subsequent units here */ };END_OBJ * sysGei82543EndLoad (char * pParamStr, void * unused);LOCAL GEI_RESOURCE geiResources [SYS_GEI_MAX_UNITS] = { {UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, 0, 0, {UNKNOWN}, ERROR, 0},#ifndef INCLUDE_FEI_END {UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, 0, 0, {UNKNOWN}, ERROR, 0},#endif /* Add subsequent units here */ };LOCAL SYS_PCI_IDENT geiDevices [] ={ {INTEL_PCI_VENDOR_ID, PRO1000_544_PCI_DEVICE_ID_1}, {INTEL_PCI_VENDOR_ID, PRO1000_544_PCI_DEVICE_ID_2}, {INTEL_PCI_VENDOR_ID, PRO1000_544_PCI_DEVICE_ID_3},#ifndef INCLUDE_FEI_END {INTEL_PCI_VENDOR_ID, PRO1000_543_PCI_DEVICE_ID_1}, {INTEL_PCI_VENDOR_ID, PRO1000_543_PCI_DEVICE_ID_2},#endif {0, 0},};LOCAL int sys543IntEnable (int unit);LOCAL int sys543IntDisable (int unit);LOCAL int sys543IntAck (int unit);LOCAL STATUS sys543eepromCheckSum (int unit);LOCAL UINT16 sys543eepromReadWord (int unit,UINT32);LOCAL STATUS sys543EtherAddrGet (int unit);LOCAL void sys543PhySpecRegsInit(PHY_INFO *, UINT8);LOCAL void sys543Delay (void);LOCAL UINT32 sys543BusToLocal (int unit, UINT32 sysAddr);LOCAL UINT32 sys543LocalToBus (int unit, UINT32 localAddr);void sys543Show(int unit);void sys543GeiInit (void);STATUS sys543MacAddrStringConvert (UINT8 mac [], char * macAddrString);#ifdef SYS_543_EEPROM_UTILSSTATUS sys543eepromProgram (int unit, UINT16 * pContents, BOOL checksumFix);STATUS sys543eepromEraseWriteAllow (int unit, BOOL enable);STATUS sys543eepromEraseAll (int unit);STATUS sys543eepromWriteWord (int unit, UINT32 index, UINT16 word);STATUS sys543eepromCopy (int unit, UINT16 * pWords);void sys543eepromDump (int unit);STATUS sys543eepromMacAddrSet (int unit, char * macAddrString);#endif /* SYS_543_EEPROM_UTILS *//*************************************************************************** sys543Delay - delay a while.** This routine delays a bit over a microsecond.** RETURNS: N/A*/void sys543Delay (void) { SYS_DELAY (1); }/******************************************************************************* sys82543BoardInit - prepare LAN adapter for 82543 initialization** This routine is expected to perform any adapter-specific or target-specific* initialization that must be done prior to initializing the 82543.** The 82543 driver calls this routine from the driver attach routine before* any other routines in this library.** RETURNS: OK or ERROR if the adapter could not be prepared for initialization.*/STATUS sys82543BoardInit ( int unit, /* unit number */ ADAPTOR_INFO *pBoard /* board information for the GEI driver */ ) { GEI_RESOURCE *pInfo = &geiResources [unit]; int slot; if (unit >= geiUnits) return (ERROR); if (pInfo->boardType != PRO1000_543_BOARD && pInfo->boardType != PRO1000_544_BOARD) return ERROR; slot = pInfo->pciDevice; /* initializes the board information structure */ pBoard->vector = (UINT32) pInfo->irq; /* perform EEPROM checksum */ if (sys543eepromCheckSum (unit) != OK) { printf ("GEI82543:unit=%d, EEPROM checksum Error!\n", unit); } sys543EtherAddrGet (unit); /* Get ethernet address */ bcopy (pInfo->enetAddr, pBoard->enetAddr, ETHER_ADDRESS_SIZE); /* get the initialization control word 1 (ICW1) in EEPROM */ pInfo->eeprom_icw1 = sys543eepromReadWord (unit, EEPROM_ICW1); /* get the initialization control word 2 (ICW2) in EEPROM */ pInfo->eeprom_icw2 = sys543eepromReadWord (unit, EEPROM_ICW2); /* initializes the board information structure */ pBoard->boardType = pInfo->boardType; pBoard->regBaseLow = pInfo->memBaseLow; pBoard->regBaseHigh = pInfo->memBaseHigh; pBoard->flashBase = pInfo->flashBaseLow; pBoard->adr64 = pInfo->addr64; pBoard->intEnable = sys543IntEnable; pBoard->intDisable = sys543IntDisable; pBoard->intAck = sys543IntAck; /* Intel copper-based adapter is based on GMII interface */ pBoard->phyType = GEI_PHY_GMII_TYPE; pBoard->phySpecInit = sys543PhySpecRegsInit; pBoard->delayFunc = (FUNCPTR) sys543Delay; pBoard->delayUnit = 1000; /* sys543Delay() takes at least 1 uSec */ pBoard->sysLocalToBus = NULL; /* sys543LocalToBus; */ pBoard->sysBusToLocal = NULL; /* sys543BusToLocal; */ /* specify the interrupt connect/disconnect routines to be used */ pBoard->intConnect = (FUNCPTR) intConnect; pBoard->intDisConnect = (FUNCPTR) intDisable; /* get the ICW1 and ICW2 */ pBoard->eeprom_icw1 = pInfo->eeprom_icw1; pBoard->eeprom_icw2 = pInfo->eeprom_icw2; /* copy Ether address */ memcpy (&pBoard->enetAddr[0], &pInfo->enetAddr[0], ETHER_ADDRESS_SIZE); /* we finish adaptor initialization */ pInfo->iniStatus = OK; return (OK); }/************************************************************************* sys543SetClkHi - set the clock HI** This routine set the clock HI** RETURNS: N/A*/LOCAL void sys543SetClkHi ( int unit, volatile UINT32 * pEecdRegValue ) { *pEecdRegValue = *pEecdRegValue | EECD_SK_BIT; GEI_SYS_WRITE_REG(unit, INTEL_82543GC_EECD, *pEecdRegValue); /* wait */ SYS_DELAY(25); }/************************************************************************* sys543SetClkLo - set the clock LO** This routine set the clock LO** RETURNS: N/A*/LOCAL void sys543SetClkLo ( int unit, volatile UINT32 * pEecdRegValue ) { *pEecdRegValue = *pEecdRegValue & ~EECD_SK_BIT; GEI_SYS_WRITE_REG(unit, INTEL_82543GC_EECD, *pEecdRegValue); /* wait */ SYS_DELAY(25); }/*************************************************************************** sys543eepromReadBits - read bits from EEPROM** This routine reads bit data from EEPROM** RETURNS: value in WORD size*/LOCAL UINT16 sys543eepromReadBits ( int unit, int bitsNum ) { int ix; UINT16 val; volatile UINT32 eecdRegValue; eecdRegValue = GEI_SYS_READ_REG(unit, INTEL_82543GC_EECD); eecdRegValue &= ~(EECD_DO_BIT | EECD_DI_BIT); val = 0; for (ix = 0; ix < bitsNum; ix++) { val = val << 1; /* raise the clk */ sys543SetClkHi (unit, &eecdRegValue); eecdRegValue = GEI_SYS_READ_REG(unit, INTEL_82543GC_EECD); eecdRegValue &= ~(EECD_DI_BIT); if (eecdRegValue & EECD_DO_BIT) val |= 1; /* lower the clk */ sys543SetClkLo (unit, &eecdRegValue); } return (val); }/*************************************************************************** sys543eepromWriteBits - write bits out to EEPROM** This routine writes bits out to EEPROM** RETURNS: N/A*/LOCAL void sys543eepromWriteBits ( int unit, UINT16 value, UINT16 bitNum ) { UINT16 mask; volatile UINT32 eecdRegValue; if (bitNum == 0) return; mask = 0x01 << (bitNum - 1); eecdRegValue = GEI_SYS_READ_REG(unit,INTEL_82543GC_EECD); eecdRegValue &= ~(EECD_DO_BIT | EECD_DI_BIT); do { eecdRegValue &= ~EECD_DI_BIT; if (value & mask) eecdRegValue |= EECD_DI_BIT; /* write the data */ GEI_SYS_WRITE_REG(unit, INTEL_82543GC_EECD, eecdRegValue); /* wait */ SYS_DELAY(10); /* raise the clk */ sys543SetClkHi (unit, &eecdRegValue); /* lower the clk */ sys543SetClkLo (unit, &eecdRegValue); mask >>= 1; } while(mask); return; }/*************************************************************************** sys543eepromReadWord - Read a word from EEPROM** RETURNS: value in WORD size*/LOCAL UINT16 sys543eepromReadWord (
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -