📄 dp8381~1.c
字号:
* Macros to get/set the values of descriptor fields with * appropriate address and byte order translations */#define DP_DESC_LNK_XLATE_GET(p) BUS_TO_CPU_ADDR_XLATE(DP_DESC_LNK_GET(p))#define DP_DESC_CMDSTS_XLATE_GET(p) BUS_TO_CPU_SWAP_32(DP_DESC_CMDSTS_GET(p))#define DP_DESC_BUFPTR_XLATE_GET(p) BUS_TO_CPU_ADDR_XLATE(DP_DESC_BUFPTR_GET(p))#define DP_DESC_LNK_XLATE_SET(p, v) \ DP_DESC_LNK_SET(p, CPU_TO_BUS_ADDR_XLATE(v))#define DP_DESC_CMDSTS_XLATE_SET(p, v) \ DP_DESC_CMDSTS_SET(p, CPU_TO_BUS_SWAP_32(v))#define DP_DESC_BUFPTR_XLATE_SET(p,v) \ DP_DESC_BUFPTR_SET(p, CPU_TO_BUS_ADDR_XLATE(v))/* Descriptor queue */typedef struct dp83815_queue { VIRT_ADDR firstDescAddr; /* descriptor array address */ VIRT_ADDR lastDescAddr; /* last descriptor address */ VIRT_ADDR curDescAddr; /* current descriptor address */ UINT16 count; /* number of elements */ } DP83815_QUEUE;/* Queue types -- qtype */#define DP_QUEUE_TYPE_TX 1 /* Transmit queue */#define DP_QUEUE_TYPE_RX 2 /* Receive queue *//* Cluster block and M_BLK sizes with padding */#define CLBLK_SIZE (CL_BLK_SZ + sizeof(long))#define MBLK_SIZE (MSIZE + sizeof(long))/* The definition of the driver control structure */typedef struct end_device { END_OBJ end; /* The class we inherit from. */ int unit; /* unit number */ UINT32 baseAddr; /* Device base address */ int ivec; /* interrupt vector */ int ilevel; /* interrupt level */ UINT32 pciMemBase; /* PCI memory base address */ char* pDmaBuf; /* ptr to device memory */ char* pMclMem; /* ptr to MBLK/CL_BLK memory */ UINT32 dmaBufSize; /* size of user specified memory *//* hanzhf int */ UINT8 txDescCount; /* Transmit descriptor count */ UINT8 rxDescCount; /* Receive descriptor count */ UINT16 mBlkCount; /* MBLK count */ UINT16 clCount; /* Cluster count */ DP83815_QUEUE txQueue; /* Transmit descriptor queue */ DP83815_QUEUE rxQueue; /* Receive descriptor queue */ long flags; /* Our local flags. */ UCHAR enetAddr[6]; /* ethernet address */ CACHE_FUNCS cacheFuncs; /* cache function pointers */ } END_DEVICE;/* Definitions for the flags field */#define DP83815_PROMISCUOUS 0x1#define DP83815_POLLING 0x2#define DP83815_RCV 0x4#define DP83815_BUF_LOCAL 0x8/* Debug Macros */#define DRV_DEBUG /* hanzhf*/#undef DRV_DEBUG#ifdef DRV_DEBUG# define LOGMSG(x,a,b,c,d,e,f) \ if (dp83815Debug & DRV_DEBUG_LOG_ALL) \ { \ logMsg (x,a,b,c,d,e,f); \ }NET_POOL_ID dp83815Pool;#else# define LOGMSG(x,a,b,c,d,e,f)#endif /* DRV_DEBUG */#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_POLL_MODE 0x0080#define DRV_DEBUG_POLL_REDIR 0x10000#define DRV_DEBUG_LOG_NVRAM 0x20000#define DRV_DEBUG_LOG_ALL 0x80000int dp83815Debug = DRV_DEBUG_INT|DRV_DEBUG_LOAD; /* hanzhf*/int dp83815TxInts = 0;LOCAL void pollPrint();LOCAL void dumpPkt();LOCAL int mblkCount();#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6) \ if (dp83815Debug & FLG) \ logMsg(X0, X1, X2, X3, X4, X5, X6);#define DRV_POLL_PRINT(FLG, X0, X1, X2, X3, X4, X5, X6) \ if (dp83815Debug & FLG) \ pollPrint(X0, X1, X2, X3, X4, X5, X6);#define DRV_PRINT(FLG,X) \ if (dp83815Debug & FLG) printf X;#else /*DRV_DEBUG*/#define DRV_LOG(DBG_SW, X0, X1, X2, X3, X4, X5, X6)#define DRV_PRINT(DBG_SW,X)#define DRV_POLL_PRINT(FLG, X0, X1, X2, X3, X4, X5, X6)#endif /*DRV_DEBUG*//* IMPORTS */IMPORT STATUS sysDp83815ParamGet (int unit, DP83815_PARAM *pParam);IMPORT void sysDp83815EnetAddrGet (int unit, char *pEnetAddr);/* LOCALS *//* forward static functions */LOCAL STATUS dp83815Reset (END_DEVICE *pDrvCtrl);LOCAL void dp83815Int (END_DEVICE *pDrvCtrl);LOCAL STATUS dp83815Recv (END_DEVICE *pDrvCtrl);LOCAL STATUS dp83815Config (END_DEVICE *pDrvCtrl);LOCAL void dp83815MacAddressSet (UINT32 iobase, char *macAddr);LOCAL void dp83815MacAddressGet (UINT32 iobase, char *macAddr);LOCAL UINT32 dp83815HashCrc (char *pMcAddr);LOCAL void dp83815RxFilterConfig (END_DEVICE *pDrvCtrl);LOCAL void dp83815memAlign(char *ptr,int len);/* Driver private routines */LOCAL STATUS dp83815QueueCreate (END_DEVICE *pDrvCtrl, DP83815_QUEUE *q, char *pMem, int count, int qtype);LOCAL STATUS dp83815QueueDelete (DP83815_QUEUE *q);LOCAL VIRT_ADDR dp83815TxDescGet (END_DEVICE *pDrvCtrl);LOCAL VIRT_ADDR dp83815RxDescGet (END_DEVICE *pDrvCtrl);LOCAL STATUS dp83815PhySetup (END_DEVICE *pDrvCtrl);#if 0LOCAL void dp83815TxMblkReclaim (END_DEVICE *pDrvCtrl, VIRT_ADDR descAddr);#endif/* Support Functions */LOCAL UINT16 swap16 (UINT16 us);/*LOCAL UINT32 swap32 (UINT32 us);*//* END Specific interfaces. *//* This is the only externally visible interface. */END_OBJ* dp83815Load (char* initString);LOCAL STATUS dp83815Start (VOID* pDrvCtrl);LOCAL STATUS dp83815Stop (VOID* pDrvCtrl);LOCAL STATUS dp83815Unload (VOID* pDrvCtrl);LOCAL int dp83815Ioctl (VOID* pDrvCtrl, int cmd, caddr_t data);LOCAL STATUS dp83815Send (VOID* pDrvCtrl, M_BLK_ID pBuf); LOCAL STATUS dp83815MCastAdd (VOID* pDrvCtrl, char* pAddress);LOCAL STATUS dp83815MCastDel (VOID* pDrvCtrl, char* pAddress);LOCAL STATUS dp83815MCastGet (VOID* pDrvCtrl, MULTI_TABLE* pTable);LOCAL STATUS dp83815PollSend (VOID* pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS dp83815PollRecv (VOID* pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS dp83815PollStart(VOID* pDrvCtrl);LOCAL STATUS dp83815PollStop (VOID* pDrvCtrl);LOCAL STATUS dp83815Parse (END_DEVICE *pDrvCtrl, char *initString);LOCAL STATUS dp83815MemInit (END_DEVICE *pDrvCtrl);/* * Declare our function table. This is static across all driver * instances. */LOCAL NET_FUNCS dp83815FuncTable = { dp83815Start, /* Function to start the device. */ dp83815Stop, /* Function to stop the device. */ dp83815Unload, /* Unloading function for the driver. */ dp83815Ioctl, /* Ioctl function for the driver. */ dp83815Send, /* Send function for the driver. */ dp83815MCastAdd, /* Multicast add function for the driver. */ dp83815MCastDel, /* Multicast delete function for the driver. */ dp83815MCastGet, /* Multicast retrieve function for the driver.*/ dp83815PollSend, /* Polling send function */ dp83815PollRecv, /* Polling receive function */ endEtherAddressForm, /* put address info into a NET_BUFFER */ endEtherPacketDataGet, /* get pointer to data in NET_BUFFER */ endEtherPacketAddrGet /* Get packet addresses. */ };/******************************************************************************* dp83815Load - initialize the driver and device** This routine initializes the driver and the device to the operational state.* All device specific parameters are obtained from sysDp83815ParamGet() and* driver specific parameters are passed in the <initString>.** The <initString> is a colon-separated string of parameters with the following* syntax,** .CS* "unit:dmaBufAdr:dmaBufSize:txDescCount:rxDescCount:clCount"* .CE** .iP <unit>* Device unit number, is prefixed by automatically by the MUX* .iP <dmaBufAdr>* Address of the DMA buffer area * .iP <dmaBufSize>* Size of DMA buffer area* .iP <txDescCount>* Transmit descriptor count* .iP <rxDescCount>* Receive descriptor count* .iP <clCount>* Cluster count* .iE** If <dmaBufAdr> is specified as NULL (0) or NONE (-1), the driver allocates* the required DMA buffer area using cacheDmaMalloc. Otherwise, <dmaBufAdr>* should contain the address of a cache-safe memory location, whose size is* specified by <dmaBufSize>. The parameters <txDescCount> and <rxDescCount>* specify the number of transmit and recive descriptors, while <clCount>* specifies the number of clusters. NULL (0) in these fields are use to* specify default values, DP_TX_DESC_DEFAULT, DP_RX_DESC_DEFAULT, and* .CS* (txDescCount + rxDescCount + DP_CL_EXTRA_DEFAULT)* .CE* for the number of transmit descriptors, receive descriptors, and the* number of clusters. If <clCount> is specified it should be atleast* .CS* (txDescCount + rxDescCount + DP_CL_EXTRA_MIN)* .CE* otherwise the driver will set <clCount> to this value.** The size of the entire DMA buffer can be calculated using,** .CS* ((clCount * (DP_BUF_SIZE + (2 *DP_ALIGN))) + * ((rxDescCount + txDescCount) * (DP_QUEUE_ELE_SIZE)) + (2 * DP_ALIGN))* .CE** RETURNS: An END object pointer or NULL on error.*/END_OBJ* dp83815Load ( char* initString /* String to be parsed by the driver. */ ) { END_DEVICE *pDrvCtrl; DP83815_PARAM dpParam; /* holds device specific parameters */ DRV_LOG (DRV_DEBUG_LOAD, "Loading dp83815...\n", 1, 2, 3, 4, 5, 6); if (initString == NULL) return (NULL); if (initString[0] == NULL) { bcopy ((char *) DP_DEV_NAME, initString, strlen(DP_DEV_NAME)); return (0); } /* allocate the device structure */ pDrvCtrl = (END_DEVICE *) calloc (sizeof (END_DEVICE), 1); if (pDrvCtrl == NULL) goto errorExit; /* parse the init string, filling in the device structure */ if (dp83815Parse (pDrvCtrl, initString) == ERROR) goto errorExit; /* Get parameters from the BSP and fill in the device structure */ if (sysDp83815ParamGet (pDrvCtrl->unit, &dpParam) == ERROR) goto errorExit; pDrvCtrl->baseAddr = dpParam.iobase; pDrvCtrl->ivec = dpParam.ivec; pDrvCtrl->ilevel = dpParam.ilevel; pDrvCtrl->pciMemBase = dpParam.pciMemBase; /* Get the ethernet address from the card. */ dp83815MacAddressGet (pDrvCtrl->baseAddr, pDrvCtrl->enetAddr); if (pDrvCtrl->enetAddr[0] != 0x08) { /* Buggy Ethernet Address; needs swapping */ if (pDrvCtrl->enetAddr[1] == 0x08) { UINT16 *pShort = (UINT16 *)pDrvCtrl->enetAddr; UINT8 i; for (i=0; i<3; i++) { *pShort = swap16(*pShort); pShort++; } } else { /* Bogus ethernet address, ask the BSP for one */ SYS_ENET_ADDR_GET (pDrvCtrl); } } DRV_LOG (DRV_DEBUG_LOAD, "ethernet addr=%02x:%02x:%02x:%02x:%02x:%02x\n", pDrvCtrl->enetAddr[0], pDrvCtrl->enetAddr[1], pDrvCtrl->enetAddr[2], pDrvCtrl->enetAddr[3], pDrvCtrl->enetAddr[4], pDrvCtrl->enetAddr[5]); /* initialize the END and MIB2 parts of the structure */ if ((END_OBJ_INIT (&pDrvCtrl->end, (DEV_OBJ *)pDrvCtrl, DP_DEV_NAME, pDrvCtrl->unit, &dp83815FuncTable, DP_DRV_NAME) == ERROR) || (END_MIB_INIT (&pDrvCtrl->end, M2_ifType_ethernet_csmacd, pDrvCtrl->enetAddr, 6, ETHERMTU, END_SPEED) == ERROR)) goto errorExit; /* Perform memory allocation/distribution */
if (dp83815MemInit (pDrvCtrl) == ERROR) goto errorExit; /* configure the device */ if (dp83815Config (pDrvCtrl) == ERROR) goto errorExit; /* set the flags to indicate readiness */ END_OBJ_READY (&pDrvCtrl->end, IFF_UP | IFF_RUNNING | IFF_NOTRAILERS | IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST); DRV_LOG (DRV_DEBUG_LOAD, "Done loading Dp83815, pDrvCtrl=%p txQ=%p rxQ=%p\n", (int)pDrvCtrl, (int) &pDrvCtrl->txQueue, (int) &pDrvCtrl->rxQueue, 4, 5, 6); return (&pDrvCtrl->end); errorExit: { if (pDrvCtrl != NULL) free ((char *) pDrvCtrl); DRV_LOG (DRV_DEBUG_LOAD, "errorExit from dp83815Load...\n", 1, 2, 3, 4, 5, 6); return NULL; } }/******************************************************************************* dp83815Parse - parse the init string** Parse the input string. Fill in values in the driver control structure.** The initialization string format is:* "unit:pDmaBuf:dmaBufSize:txDescCount:rxDescCount:clCount"** .bS* unit Device unit number, a small integer* pDmaBuf Shared memory address* dmaBufSize Size of memory reserved* txDescCount Transmit descriptor count* rxDescCount Receive descriptor count* clCount Cluster count* .bE** RETURNS: OK or ERROR for invalid arguments.*/LOCAL STATUS dp83815Parse ( END_DEVICE * pDrvCtrl, /* device pointer */ char * initString /* information string */ ) { char* tok; char* pHolder = NULL; /* Parse the initString */ /* Unit number. */ tok = strtok_r (initString, ":", &pHolder); if (tok == NULL) return ERROR; pDrvCtrl->unit = strtoul (tok, NULL, NULL); /* Device DMA buffer address. */ tok = strtok_r (NULL, ":", &pHolder); if (tok == NULL) return ERROR; pDrvCtrl->pDmaBuf = (char*) strtoul (tok, NULL, NULL); /* DMA buffer size. */ tok = strtok_r (NULL, ":", &pHolder);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -