📄 rtlcpp.c
字号:
/*************kongfq2005.8.16********************/
/*logMsg ("ivec : 0x%X ...\n", pDrvCtrl->ivec,
2, 3, 4, 5, 6);*/
/* Interrupt level. */
tok = strtok_r (NULL, ":", &holder);
/*if (tok == NULL)
return ERROR;*/ /************kongfq 2005.8.15************/
pDrvCtrl->ilevel = atoi (tok);
/*************kongfq2005.8.16********************/
/*logMsg("ilevel : 0x%X ...\n", pDrvCtrl->ilevel,
2, 3, 4, 5, 6);*/
/* Caller supplied memory address. */
tok = strtok_r (NULL, ":", &holder);
if (tok == NULL)
return ERROR;
pDrvCtrl->memAdrs = (char *)strtoul (tok, NULL, 16);
/*************kongfq2005.8.16********************/
/*logMsg ("memAdrs : 0x%X ...\n", (int)pDrvCtrl->memAdrs,
2, 3, 4, 5, 6);*/
/* Caller supplied memory size. */
tok = strtok_r (NULL, ":", &holder);
if (tok == NULL)
return ERROR;
pDrvCtrl->memSize = strtoul (tok, NULL, 16);
/*************kongfq2005.8.16********************/
/*logMsg ("memSize : 0x%X ...\n", pDrvCtrl->memSize,
2, 3, 4, 5, 6);*/
/* Caller supplied memory width. */
tok = strtok_r (NULL, ":", &holder);
if (tok == NULL)
return ERROR;
pDrvCtrl->memWidth = atoi (tok);
/*DRV_LOG (DRV_DEBUG_LOAD, "memWidth : 0x%X ...\n", pDrvCtrl->memWidth,
2, 3, 4, 5, 6);*/
/* CSR3B value */
tok = strtok_r (NULL, ":", &holder);
if (tok == NULL)
return ERROR;
pDrvCtrl->csr3B = strtoul (tok, NULL, 16);
/*DRV_LOG (DRV_DEBUG_LOAD, "csr3b value : %d ...\n", pDrvCtrl->csr3B,
2, 3, 4, 5, 6);*/
/* Caller supplied alignment offset. */
tok = strtok_r (NULL, ":", &holder);
if (tok == NULL)
return ERROR;
pDrvCtrl->offset = atoi (tok);
/*DRV_LOG (DRV_DEBUG_LOAD, "offset value : %d ...\n", pDrvCtrl->offset,
2, 3, 4, 5, 6);*/
/* caller supplied flags */
tok = strtok_r (NULL, ":", &holder);
if (tok == NULL)
return ERROR;
pDrvCtrl->flags |= strtoul (tok, NULL, 16);
/*DRV_LOG (DRV_DEBUG_LOAD, "flags : 0x%X ...\n", pDrvCtrl->flags,
2, 3, 4, 5, 6);*/
return OK;
}
/*******************************************************************************
*
* rtl81x9InitMem - initialize memory for the device
*
* Using data in the control structure, setup and initialize the memory
* areas needed. If the memory address is not already specified, then allocate
* cache safe memory.
*
* RETURNS: OK or ERROR.
*
*/
LOCAL STATUS rtl81x9InitMem
(
RTL81X9END_DEVICE * pDrvCtrl /* device to be initialized */
)
{
UINT sz = 0; /* temporary size holder */
descript * pRmd;
int ix;
char * pTempBuf;
void * pTemp;
UINT8 diff;
UINT32 tempcmd_leng;
/***** Establish size of shared memory region we require *****/
DRV_LOG (DRV_DEBUG_ALL, "rtl81x9cpp InitMem\n", 0, 0, 0, 0, 0, 0);
if ((int) pDrvCtrl->memAdrs != NONE) /* specified memory pool */
{
/*
* With a specified memory pool we want to maximize
* rtlRsize and rtlTsize
*/
DRV_LOG (DRV_DEBUG_LOAD, "No memAdrs supplied\n", 0, 0, 0, 0, 0, 0);
sz = (pDrvCtrl->memSize - (RMD_SIZ + sizeof (rtl_ib)))
/ ((2 * RTL_BUFSIZ) + RMD_SIZ);
sz >>= 1; /* adjust for roundoff */
for (rtlRsize = 0; sz != 0; rtlRsize++, sz >>= 1)
;
}
/* limit ring sizes to reasonable values */
rtlRsize = max (rtlRsize, 2); /* 4 Rx buffers is reasonable min */
rtlRsize = min (rtlRsize, 7); /* 128 Rx buffers is max for chip */
/* Add it all up */
sz = (((1 << rtlRsize) + 1) * RMD_SIZ) + IB_SIZ + 24;
/*DRV_LOG (DRV_DEBUG_LOAD, "sx - %d\n",sz, 0, 0, 0, 0, 0); */
/***** Establish a region of shared memory *****/
/* OK. We now know how much shared memory we need. If the caller
* provides a specific memory region, we check to see if the provided
* region is large enough for our needs. If the caller did not
* provide a specific region, then we attempt to allocate the memory
* from the system, using the cache aware allocation system call.
*/
switch ((int) pDrvCtrl->memAdrs)
{
default : /* caller provided memory */
if (pDrvCtrl->memSize < sz) /* not enough space */
{
DRV_LOG (DRV_DEBUG_LOAD, "rtl81x9: not enough memory provided need %ul got %d\n",
pDrvCtrl->memSize, sz, 0, 0, 0, 0);
return (NULL);
}
/* set the beginning of pool */
pDrvCtrl->pShMem = pDrvCtrl->memAdrs;
/* assume pool is cache coherent, copy null structure */
pDrvCtrl->cacheFuncs = cacheNullFuncs;
DRV_LOG (DRV_DEBUG_LOAD, "Memory checks out\n",0, 0, 0, 0, 0, 0);
break;
case NONE : /* get our own memory */
/* Because the structures that are shared between the device
* and the driver may share cache lines, the possibility exists
* that the driver could flush a cache line for a structure and
* wipe out an asynchronous change by the device to a neighboring
* structure. Therefore, this driver cannot operate with memory
* that is not write coherent. We check for the availability of
* such memory here, and abort if the system did not give us what
* we need.
*/
if (!CACHE_DMA_IS_WRITE_COHERENT ())
{
DRV_LOG (DRV_DEBUG_LOAD, "rtl: device requires cache coherent memory\n", 0, 0, 0, 0, 0, 0);
return (ERROR);
}
pDrvCtrl->pShMem = (char *) cacheDmaMalloc (sz);
if ((int)pDrvCtrl->pShMem == NULL)
{
DRV_LOG (DRV_DEBUG_LOAD, "rtl: system memory unavailable\n", 0, 0, 0, 0, 0, 0);
return (ERROR);
}
/* copy the DMA structure */
pDrvCtrl->cacheFuncs = cacheDmaFuncs;
break;
}
/* Turkey Carving
* --------------
*
* LOW MEMORY
*
* |----------------------------------------|
* | The initialization block |
* | (sizeof (rtl_ib)) |
* |----------------------------------------|
* | The Rx descriptors |
* | ((1 << rtlRsize) + 1)*sizeof (RTL_RMD) |
* |----------------------------------------|
*/
/* align */
pDrvCtrl->pShMem = (char *) ( ( (int)pDrvCtrl->pShMem + 3) & ~3);
/* Save some things */
pDrvCtrl->memBase = (char *)((ULONG)pDrvCtrl->pShMem & 0xff000000);
if ((int) pDrvCtrl->memAdrs == NONE)
pDrvCtrl->flags |= RTL_FLG_MEM_ALLOC_FLAG;
/* first let's clear memory */
bzero ((char *) pDrvCtrl->pShMem, (int) sz);
/* setup Rx memory pointers */
pDrvCtrl->pRring = (RTL_RMD *) ((int)pDrvCtrl->pShMem + IB_SIZ);
pDrvCtrl->rringLen = rtlRsize;
pDrvCtrl->rringSize = 1 << rtlRsize;
pDrvCtrl->rmdIndex = 0;
pDrvCtrl->pTring = (RTL_TMD *) (int)(pDrvCtrl->pShMem + IB_SIZ +
((1 << rtlRsize) + 1) * RMD_SIZ + 0xff);
pDrvCtrl->pTring = (RTL_TMD *) (((int)pDrvCtrl->pTring + 0xff) & ~0xff);
pDrvCtrl->tringSize = 1 << rtlTsize;
pDrvCtrl->tringLen = rtlTsize;
pDrvCtrl->tmdIndex = 0;
pDrvCtrl->tmdIndexC = 0;
/* Allocate a chunk of memory for the Chip to place the Rx Buffers in */
pDrvCtrl->ptrRxBufSpace = cacheDmaMalloc (RTL_RXBUFLEN + 64+256);
/* pDrvCtrl->ptrRxBufSpace += 4;*/
diff= (UINT32) pDrvCtrl->ptrRxBufSpace-(((UINT32)pDrvCtrl->ptrRxBufSpace >> 8)<< 8);
diff=256-diff;
pDrvCtrl->ptrRxBufSpace+=diff;
/* pDrvCtrl->ptrRxBufSpace = malloc (RTLCP_MAX_RX_DESC*sizeof(descript) + 256);*/
if (pDrvCtrl->ptrRxBufSpace == NULL)
{
DRV_LOG (DRV_DEBUG_LOAD, "ptrRxBufSpace == NULL\n", 0, 0, 0, 0, 0, 0);
return (ERROR);
}
/*pDrvCtrl->rmdNext = 0;*/
/*c+*/
pDrvCtrl->ptrTxBufSpace = cacheDmaMalloc (RTL_RXBUFLEN + 64+ 256);
memset(pDrvCtrl->ptrTxBufSpace,0,(RTL_RXBUFLEN + 64+ 256));
if (pDrvCtrl->ptrTxBufSpace == NULL)
{
DRV_LOG (DRV_DEBUG_LOAD, "ptrTxBufSpace == NULL\n", 0, 0, 0, 0, 0, 0);
return (ERROR);
}
diff= (UINT32) pDrvCtrl->ptrTxBufSpace-(((UINT32)pDrvCtrl->ptrTxBufSpace >> 8)<< 8);
diff=256-diff;
pDrvCtrl->ptrTxBufSpace+=diff;
/*pDrvCtrl->tmdNext = 0;*/
/*
* Allocate receive buffers from our own private pool.
*/
if ((pDrvCtrl->end.pNetPool = malloc (sizeof(NET_POOL))) == NULL)
return (ERROR);
/*rtlMclConfig.mBlkNum = pDrvCtrl->rringSize * 3*/
g_ul8139ClusterNum = max (g_ul8139ClusterNum, (pDrvCtrl->rringSize) * 2);
g_ul8139ClusterNum = min (g_ul8139ClusterNum, 5000);
rtlMclConfig.mBlkNum = g_ul8139ClusterNum;
/* rtlClDesc[0].clNum = pDrvCtrl->rringSize *3 */
rtlClDesc[0].clNum = g_ul8139ClusterNum;
rtlMclConfig.clBlkNum = rtlClDesc[0].clNum;
DRV_LOG (DRV_DEBUG_ALL, "%d %d %d \n", rtlMclConfig.mBlkNum, rtlMclConfig.clBlkNum, rtlClDesc[0].clNum, 0, 0, 0);
rtlMclConfig.memSize = (rtlMclConfig.mBlkNum * (MSIZE + sizeof (long))) +
(rtlMclConfig.clBlkNum * (CL_BLK_SZ + sizeof(long)));
if ((rtlMclConfig.memArea = (char *) memalign (sizeof(long),
rtlMclConfig.memSize))
== NULL)
return (ERROR);
rtlClDesc[0].memSize = (rtlClDesc[0].clNum * (RTL_BUFSIZ + 8))
+ sizeof(int);
DRV_LOG (DRV_DEBUG_ALL, "memSize=%d \n",rtlClDesc[0].memSize , 0, 0, 0, 0, 0);
if ((int) pDrvCtrl->memAdrs != NONE) /* Do we hand over our own memory? */
{
rtlClDesc[0].memArea =
(char *)(pDrvCtrl->pRring + (((1 << rtlRsize) + 1) * RMD_SIZ));
}
else
{
rtlClDesc[0].memArea =
(char *) cacheDmaMalloc (rtlClDesc[0].memSize);
if ((int)rtlClDesc[0].memArea == NULL)
{
DRV_LOG(DRV_DEBUG_LOAD,
"system memory unavailable\n", 1, 2, 3, 4, 5, 6);
return (ERROR);
}
}
if (netPoolInit(pDrvCtrl->end.pNetPool, &rtlMclConfig,
&rtlClDesc[0], rtlClDescNumEnt, NULL) == ERROR)
{
DRV_LOG (DRV_DEBUG_LOAD, "Could not init buffering\n",0, 0, 0, 0, 0, 0);
return (ERROR);
}
/* Store the cluster pool id as others need it later. */
pDrvCtrl->pClPoolId = clPoolIdGet(pDrvCtrl->end.pNetPool,
RTL_BUFSIZ, FALSE);
/* pDrvCtrl->pRring = (RTL_RMD *) (((int)pDrvCtrl->pRring + 0xff) & ~0xff); */
/* pDrvCtrl->pTring = (RTL_RMD *) (((int)pDrvCtrl->pTring + 0xff) & ~0xff); */
/* pRmd = pDrvCtrl->pRring; */
/*test*/
pRmd = ( descript *)(pDrvCtrl->ptrRxBufSpace); /* modified by zoutl 2003/2/21 */
/* pTmd = pDrvCtrl->ptrTxBufSpace; */
DRV_LOG (DRV_DEBUG_ALL, "Using %d RX buffers from 0x%X rringSize=%d num=%d\n",
pDrvCtrl->rringSize, (int)pRmd, pDrvCtrl->rringSize, rtlMclConfig.clBlkNum, 5, 6);
for (ix = 0; ix < pDrvCtrl->rringSize; ix++, pRmd++)
{
if ((pTempBuf = (char *)netClusterGet (pDrvCtrl->end.pNetPool,
pDrvCtrl->pClPoolId)) == NULL)
{
DRV_LOG (DRV_DEBUG_ALL, "Could not get a buffer\n",
1, 2, 3, 4, 5, 6);
return (ERROR);
}
pTempBuf += pDrvCtrl->offset;
/* pRmd->cmd_leng=0xb00005f0; */
tempcmd_leng=RTLCP_RX_OWN|RTLCP_RX_EMS|RTL81x9_BUFSIZE;/* modified by mashuyu */
pRmd->cmd_leng=PCI_SWAP (tempcmd_leng);/* added by mashuyu */
RTL_RMD_BUF_TO_ADDR (pRmd, pTemp, pTempBuf);
}
pRmd--;
/* pRmd->cmd_leng=0xf00005f0; */
tempcmd_leng=RTLCP_RX_OWN|RTLCP_RX_EOR |RTLCP_RX_EMS|RTL81x9_BUFSIZE;/* modified by mashuyu */
pRmd->cmd_leng=PCI_SWAP (tempcmd_leng);/* added by mashuyu */
/* please see datasheet page 70 */
return OK;
}
/*******************************************************************************
*
* rtl81x9Start - start the device
*
* This function initializes the device and calls BSP functions to connect
* interrupts and start the device running in interrupt mode.
*
* The complement of this routine is rtl81x9Stop. Once a unit is reset by
* rtl81x9Stop, it may be re-initialized to a running state by this routine.
*
* RETURNS: OK if successful, otherwise ERROR
*/
LOCAL STATUS rtl81x9Start
(
RTL81X9END_DEVICE * pDrvCtrl
)
{
STATUS result;
int rxcfg;
/* int testvalue; */
/*UINT8 diff;*/
/* add by zoutl for test 2003-4-6 19:22 */
unsigned short usCommand;
UINT8 ByteIn8139;
ByteIn8139 = rtl81x9CsrReadByte(pDrvCtrl, RTL_REGS_CONFIG3, RTL_WIN_0);
ByteIn8139 = ByteIn8139|0x1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -