📄 lan91c111end.c
字号:
NETWORK_ADDRESS HardwareAddress; /* ROM Station address */
NETWORK_ADDRESS CurrentAddress; /* Current Station address */
UCHAR HashTable[8]; /* Multicast hash bits */
/*
* Add feature function variable here.
* By Shawn X.D. Meng March 24, 1997.
*/
BOOLEAN EarlyTransmit;
BOOLEAN EarlyTxStart;
BOOLEAN ETEN;
USHORT EarlyTxThreshold;
USHORT ETxThrshInc;
USHORT ETxThrshBase;
BOOLEAN EarlyReceive;
USHORT EarlyRxThreshold;
UCHAR Duplex;
BOOLEAN Auto_Negotiation;
BOOLEAN TxUnderRunFixed;
MULTICAST_TABLE MulticastTable;
USHORT LinkChange;
/*
* Added the Chip Rev Field, RevB of LAN91C111 ... ODD BYTE ISSUE
*
*/
USHORT ChipRev; /* Stores the Chip Revision number*/
USHORT ChipID; /* Stores the Chip ID */
} LAN91C111END_DEVICE;
UINT CurrentPhyAddr;
/*
* This will only work if there is only a single unit, for multiple
* unit device drivers these should be integrated into the END_DEVICE
* structure.
*/
M_CL_CONFIG lan91c111MclBlkConfig = /* network mbuf configuration table */
{
/*
no. mBlks no. clBlks memArea memSize
----------- ---------- ------- -------
*/
256, 128, NULL, 0
};
CL_DESC lan91c111ClDescTbl [] = /* network cluster pool configuration table */
{
/*
clusterSize num memArea memSize
----------- ---- ------- -------
*/
{LAN91C111_BUFSIZE, 0, NULL, 0}
};
int lan91c111ClDescTblNumEnt = (NELEMENTS(lan91c111ClDescTbl));
NET_POOL lan91c111CmpNetPool;
#define DUMP_BANKS 1
#if DUMP_BANKS
UINT myIOBase;
#endif
#define LAN91C111_MIN_FBUF (1536) /* min first buffer size */
/* DEBUG MACROS */
#undef DEBUG
#ifdef DEBUG
BOOL lan91c111Debug = FALSE;
#define LOGMSG(x,a,b,c,d,e,f) \
if (lan91c111Debug) \
{ \
logMsg (x,a,b,c,d,e,f); \
}
#else
#define LOGMSG(x,a,b,c,d,e,f)
#endif /* ENDDEBUG */
#ifndef DRV_DEBUG
#define DRV_DEBUG
#endif
#ifdef DRV_DEBUG
#define DRV_DEBUG_OFF 0x0000
#define DRV_DEBUG_RX 0x0001
#define DRV_DEBUG_TX 0x0002
#define DRV_DEBUG_INT 0x0004
#define DRV_DEBUG_POLL (DRV_DEBUG_POLL_RX | DRV_DEBUG_POLL_TX)
#define DRV_DEBUG_POLL_RX 0x0008
#define DRV_DEBUG_POLL_TX 0x0010
#define DRV_DEBUG_LOAD 0x0020
#define DRV_DEBUG_IOCTL 0x0040
#define DRV_DEBUG_DEV 0x0080
#define DRV_DEBUG_ERR 0x0100
#define DRV_DEBUG_POLL_REDIR 0x10000
#define DRV_DEBUG_LOG_NVRAM 0x20000
#define DRV_DEBUG_STOP 0x40000
/*modify by zj 2005-5-23 15:13*/
int lan91c111Debug = DRV_DEBUG_LOAD;
int lan91c111TxInts = 0;
#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6) \
if (lan91c111Debug & FLG) \
logMsg(X0, X1, X2, X3, X4, X5, X6);
#define DRV_PRINT(FLG,X) \
if (lan91c111Debug & FLG) printf X;
#else /*DRV_DEBUG*/
#define DRV_LOG(DBG_SW, X0, X1, X2, X3, X4, X5, X6)
#define DRV_PRINT(DBG_SW,X)
#endif /*DRV_DEBUG*/
/* User defined Duplex Values - Used to manipulate init string */
#define CONFIG_DUP_DEFAULT 0
#define CONFIG_DUP_AUTO_NEG 1
#define CONFIG_DUP_FULL 2
#define CONFIG_DUP_HALF 3
/* User defined Speed Values - Used to manipulate init string */
#define CONFIG_SPEED_DEFAULT 0
#define CONFIG_SPEED_100 1
#define CONFIG_SPEED_10 2
#define CONFIG_SPEED_AUTO_NEG 3
/* User defined Transceiver Values - Used to manipulate init string */
#define CONFIG_TRANS_AUTO 0
#define CONFIG_TRANS_100 1
#define CONFIG_TRANS_10 2
#define CONFIG_TRANS_AUI 3
#define CONFIG_TRANS_BNC 4
void myDummyISR();
/* Function Prototypes */
/* Initialization, Send, Recv and Interrupt related */
END_OBJ* lan91c111Load( char* initString );
STATUS lan91c111InitParse ( LAN91C111END_DEVICE * pDrvCtrl, char * initString );
STATUS lan91c111MemInit ( LAN91C111END_DEVICE * pDrvCtrl );
STATUS lan91c111Start ( END_OBJ * pEnd );
LOCAL STATUS lan91c111Recv ( LAN91C111END_DEVICE *pDrvCtrl/*, char *, UINT */);
STATUS lan91c111Send(END_OBJ *pEnd,M_BLK_ID pMblk);
LOCAL void lan91c111HandleRcvInt ( LAN91C111END_DEVICE *pDrvCtrl );
#undef LOCAL
#define LOCAL
void lan91c111Int ( LAN91C111END_DEVICE * pDrvCtrl );
/* IOCTL, Multicast and Poll related */
LOCAL void lan91c111HandleError(LAN91C111END_DEVICE *pDrvCtrl, USHORT EphStatus);
LOCAL int lan91c111Ioctl ( END_OBJ * pEnd, int cmd, caddr_t data );
LOCAL STATUS lan91c111MCastAddrAdd ( END_OBJ *pEnd, char* pAddress );
LOCAL STATUS lan91c111MCastAddrDel ( END_OBJ *pEnd, char* pAddress );
LOCAL STATUS lan91c111MCastAddrGet ( END_OBJ *pEnd, MULTI_TABLE* pTable );
LOCAL void lan91c111Config ( LAN91C111END_DEVICE *pDrvCtrl );
LOCAL STATUS lan91c111PollStop ( LAN91C111END_DEVICE * pDrvCtrl );
LOCAL STATUS lan91c111PollStart ( LAN91C111END_DEVICE * pDrvCtrl );
/*LOCAL STATUS lan91c111PollRcv ( END_OBJ * pEnd, M_BLK_ID pMblk );
LOCAL STATUS lan91c111PollSend ( END_OBJ* pEnd, M_BLK_ID pMblk );
*/
/* Stop, Interrupt related */
LOCAL STATUS lan91c111Stop ( END_OBJ *pEnd );
LOCAL STATUS lan91c111Unload ( END_OBJ* pEnd );
LOCAL void lan91c111DisableInterrupt(LAN91C111END_DEVICE *pDrvCtrl);
/*LOCAL void lan91c111EnableInterrupt(LAN91C111END_DEVICE *pDrvCtrl);*/
/* Device Specific reset and programming APIs */
LOCAL STATUS ConfigureAdapter(LAN91C111END_DEVICE *Adapter);
LOCAL STATUS ConfigureIsa(LAN91C111END_DEVICE *Adapter);
LOCAL void MiniPortAutoNegotiation(LAN91C111END_DEVICE *Adapter);
LOCAL BOOLEAN AdapterVerify(LAN91C111END_DEVICE *Adapter);
LOCAL UINT DetectPHY(LAN91C111END_DEVICE *Adapter ,USHORT IOBase);
LOCAL BOOLEAN DoRAMTest(LAN91C111END_DEVICE *Adapter);
LOCAL BOOLEAN AdapterReset(LAN91C111END_DEVICE *Adapter);
/*LOCAL void InitializeData(LAN91C111END_DEVICE *Adapter);*/
LOCAL BOOLEAN DoAllocate(LAN91C111END_DEVICE *pDrvCtrl);
LOCAL void lan91c111WriteToChip(LAN91C111END_DEVICE *pDrvCtrl);
LOCAL void EarlyTransmit(LAN91C111END_DEVICE *pDrvCtrl);
/* Device Specific - PHY programming */
LOCAL BOOLEAN ProgramPHY( LAN91C111END_DEVICE *Adapter );
LOCAL BOOLEAN ProgramNationalPHY( LAN91C111END_DEVICE *Adapter );
UINT ReadPhyRegister( USHORT IOBase, UCHAR phyaddr, UCHAR phyreg);
VOID WritePhyRegister( USHORT IOBase, UCHAR phyaddr, UCHAR phyreg, ULONG phyregdat );
LOCAL USHORT InputMDO( USHORT IOAddress );
LOCAL VOID OutputMDO( USHORT IOAddress, UCHAR lev );
int endMultiLstCnt(END_OBJ* pEnd);
USHORT MakeHash(unsigned char *Address);
LOCAL void lan91c111AddrFilterSet(LAN91C111END_DEVICE *pDrvCtrl);
/*
* Declare our function table. This is static across all driver
* instances.
*/
LOCAL NET_FUNCS lan91c111FuncTable =
{
(FUNCPTR) lan91c111Start, /* Function to start the device. */
(FUNCPTR) lan91c111Stop, /* Function to stop the device. */
(FUNCPTR) lan91c111Unload, /* Unloading function for the driver. */
(FUNCPTR) lan91c111Ioctl, /* Ioctl function for the driver. */
(FUNCPTR) lan91c111Send, /* Send function for the driver. */
(FUNCPTR) lan91c111MCastAddrAdd, /* Multicast add function for the */
/* driver. */
(FUNCPTR) lan91c111MCastAddrDel, /* Multicast delete function for */
/* the driver. */
(FUNCPTR) lan91c111MCastAddrGet, /* Multicast retrieve function for */
/* the driver. */
(FUNCPTR) lan91c111PollStart, /* Polling send function */
(FUNCPTR) lan91c111PollStop, /* Polling receive function */
endEtherAddressForm, /* put address info into a NET_BUFFER */
endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */
endEtherPacketAddrGet /* Get packet addresses. */
};
LAN91C111END_DEVICE *pGDrvCtrl;
char mCastAddr[6];
/******************************************************************************
*
* lan91C111Load - initialize the driver and device
*
* This routine initializes the driver and the device to the operational state.
* All of the device-specific parameters are passed in <initString>, which
* expects a string of the following format:
*
* This routine can be called in two modes. If it is called with an empty but
* allocated string, it places the name of this device (that is, "ln") into
* the <initString> and returns 0.
*
* If the string is allocated and not empty, the routine attempts to load
* the driver using the values specified in the string.
*
* RETURNS: An END object pointer, or NULL on error, or 0 and the name of the
* device if the <initString> was NULL.
*/
END_OBJ* lan91c111Load(
char* initString /* string to be parse by the driver */
)
{
LAN91C111END_DEVICE* Adapter;
LAN91C111END_DEVICE* pDrvCtrl;
int Temp;
STATUS result;
DRV_LOG (DRV_DEBUG_LOAD, "Loading lan...\n", 1, 2, 3, 4, 5, 6);
if (initString == NULL)
return (NULL);
if (initString[0] == NULL)
{
bcopy((char *)LAN91C111_DEV_NAME, initString, LAN91C111_DEV_NAME_LEN);
return (0);
}
/* allocate the device structure */
pDrvCtrl = Adapter = (LAN91C111END_DEVICE *)calloc (sizeof (LAN91C111END_DEVICE), 1);
if (pDrvCtrl == NULL)
goto errorExit;
pGDrvCtrl = pDrvCtrl;
/* parse the init string, filling in the device structure */
/*********************************************************************************
* "0x300:0x2B:0xB:0x2:0x3100"原来提供的,此时没有设置mac地址,应该设置mac地址。
* 赵君 2005-5-19 17:11
*********************************************************************************/
if (lan91c111InitParse (pDrvCtrl, initString) == ERROR)
goto errorExit;
/* Callout to perform adapter init */
SYS_INT_CONNECT (pDrvCtrl,(VOIDFUNCPTR) lan91c111Int, (int)pDrvCtrl, &result);
if (result == ERROR)
return NULL;
DRV_LOG (DRV_DEBUG_LOAD, "lan91c111Start: Interrupt connected.\n",1, 2, 3, 4, 5, 6);
/* If there is any problem, code exits immediately; so no need to check for return values */
if (ConfigureAdapter(Adapter) == ERROR)
{
printf("ConfigureAdapter Problem\n");
goto errorExit;;
}
/*
* Initialize the device
*
*/
if(!AdapterReset(Adapter))
{
DRV_LOG(DRV_DEBUG_LOAD, "Memory Allocation Problem for Adapter\n",1,2,3,4,5,6);
goto errorExit;
}
/* Have the BSP hand us our address. */
SYS_ENET_ADDR_GET(pDrvCtrl);
/* initialize the END and MIB2 parts of the structure */
if (END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ *)pDrvCtrl, LAN91C111_DEV_NAME,
pDrvCtrl->unit, &lan91c111FuncTable,
"SMSC LAN91C111 Network Driver") == ERROR
|| END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd,
&pDrvCtrl->enetAddr[0], 6, ETHERMTU,
LAN91C111_SPEED) == ERROR)
goto errorExit;
/* Perform memory allocation */
if (lan91c111MemInit (pDrvCtrl) == ERROR)
goto errorExit;
/* Read TCR to see if device is working */
SYS_OUT_SHORT( Adapter->IOBase + BANK_SELECT, (USHORT) 0 );
SYS_IN_SHORT((Adapter->IOBase + BANK0_TCR),(USHORT*)&Temp);
DRV_LOG(DRV_DEBUG_LOAD,"VALUE OF TCR=%hx",(USHORT)Temp,2,3,4,5,6);
/* set the flags to indicate readiness */
END_OBJ_READY (&pDrvCtrl->endObj,
IFF_UP | IFF_RUNNING | IFF_NOTRAILERS | IFF_BROADCAST
| IFF_MULTICAST | IFF_SIMPLEX);
DRV_LOG (DRV_DEBUG_LOAD, "Done loading lan91c111...\n", 1, 2, 3, 4, 5, 6);
DRV_LOG(DRV_DEBUG_LOAD, "IOBase 0x%x Ivec 0x%x ILevel 0x%x Offset %d InitConfig 0x%x\n",
pDrvCtrl->IOBase,pDrvCtrl->ivec, pDrvCtrl->ilevel,
pDrvCtrl->offset, pDrvCtrl->InitConfigVal, 6);
printf("\nINIT NET OK");
taskDelay(60);
return (&pDrvCtrl->endObj);
errorExit:
if (pDrvCtrl != NULL)
free ((char *)pDrvCtrl);
printf("\nINIT NET error");
taskDelay(60);
return NULL;
}
/*******************************************************************************
* lan91c111InitParse - parse the initialization string
*
* Parse the input string. Fill in values in the driver control structure.
* The initialization string format is:
* "<unit>:<IOBase>:<interruptVector>:<interruptLevel>:<offset>:<configValue>
*
* RETURNS: OK, or ERROR if any arguments are invalid.
*/
STATUS lan91c111InitParse(
LAN91C111END_DEVICE * pDrvCtrl,
char * initString
)
{
char* tok;
char* pHolder = NULL;
long address;
/* Unit number. */
tok = strtok_r (initString, ":", &pHolder);
if (tok == NULL)
return ERROR;
pDrvCtrl->unit = atoi (tok);
/* IO Base */
tok = strtok_r (NULL, ":", &pHolder);
if (tok == NULL)
return ERROR;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -