⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wancomend.c

📁 WINDRIVER SBC7410 BSP
💻 C
📖 第 1 页 / 共 5 页
字号:
    RX_DESC*    dummyRxDescPtr;  /* Pointer to dummy Rx desc queue */    TX_DESC*    usedTxDescPtr;   /* Pointer to head Tx desc queue 	*/    TX_DESC*    currTxDescPtr;   /* Pointer to next available Tx desc */    SEM_ID      rxSemId;    UINT8       flags;      /* driver state */    BOOL        attached;   /* interface has been attached */    volatile BOOL   rxHandle;   /* rx handler scheduled */    BOOL        txHandle;   /* tx handler scheduled */    BOOL        txStall;    /* tx handler stalled - no CFDs */    CACHE_FUNCS cacheFuncs; /* cache descriptor */    WANCOM_PORT_INFO port ;     /* port specific info */    CL_POOL_ID  pClPoolId;      /* cluster pool identifier */    int         addressTableHashMode ;    int         addressTableHashSize ;    UINT32      addressTableBase ;    } WANCOM_DRV_CTRL;IMPORT STATUS    sysWancomInit (int unit, WANCOM_PORT_INFO *pPort);/* forward function declarations */LOCAL STATUS    wancomInitParse (WANCOM_DRV_CTRL *pDrvCtrl, char *initString);LOCAL void      wancomEndConfig(WANCOM_DRV_CTRL *pDrvCtrl);LOCAL STATUS    wancomInitMem (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL STATUS    wancomPhyInit (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL STATUS    wancomReset (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL void      wancomCFDFree (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL void      wancomRFDReturn (WANCOM_DRV_CTRL *pDrvCtrl, RX_DESC *pRxDesc, int allocNewBuffer);LOCAL void      wancomInt (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL void      wancomHandleRecvInt (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL void      wancomReceive (WANCOM_DRV_CTRL *pDrvCtrl, RX_DESC * pRxDesc);/* END Specific interfaces. */END_OBJ *       wancomEndLoad (char *initString);    LOCAL STATUS    wancomStart (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL STATUS    wancomUnload (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL STATUS    wancomStop (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL int       wancomIoctl (WANCOM_DRV_CTRL *pDrvCtrl, UINT32 cmd, caddr_t data);LOCAL STATUS    wancomSend (WANCOM_DRV_CTRL *pDrvCtrl, M_BLK *pMblk);LOCAL STATUS    wancomMCastAddrAdd (WANCOM_DRV_CTRL *pDrvCtrl, char* pAddress);LOCAL STATUS    wancomMCastAddrDel (WANCOM_DRV_CTRL *pDrvCtrl, char* pAddress);LOCAL STATUS    wancomMCastAddrGet (WANCOM_DRV_CTRL *pDrvCtrl, MULTI_TABLE *pTable);LOCAL STATUS    wancomPollSend (WANCOM_DRV_CTRL *pDrvCtrl, M_BLK_ID pMblk);LOCAL STATUS    wancomPollReceive (WANCOM_DRV_CTRL *pDrvCtrl, M_BLK_ID pMblk);LOCAL STATUS    wancomPollStart (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL STATUS    wancomPollStop (WANCOM_DRV_CTRL *pDrvCtrl);LOCAL STATUS addAddressTableEntry(                                 WANCOM_DRV_CTRL *pDrvCtrl,                                 unsigned int macH,                                 unsigned int macL,                                 unsigned int rd,                                 unsigned int skip) ;LOCAL int hashTableFunction(                           unsigned int macH,                           unsigned int macL,                           int HashSize,                           int hash_mode) ;LOCAL STATUS initAddressTable(                             WANCOM_DRV_CTRL *pDrvCtrl,                             int hashMode,                             int hashSize,                             int hashDefaultMode) ;/*  Define the device function table.  Static across all driver instances.   */LOCAL NET_FUNCS wancomNetFuncs = {    (FUNCPTR)wancomStart,       /* start func. */            (FUNCPTR)wancomStop,        /* stop func. */    (FUNCPTR)wancomUnload,      /* unload func. */          (FUNCPTR)wancomIoctl,       /* ioctl func. */            (FUNCPTR)wancomSend,        /* send func. */              (FUNCPTR)wancomMCastAddrAdd,    /* multicast add func. */        (FUNCPTR)wancomMCastAddrDel,    /* multicast delete func. */          (FUNCPTR)wancomMCastAddrGet,    /* multicast get fun. */          (FUNCPTR)wancomPollSend,        /* polling send func. */          (FUNCPTR)wancomPollReceive,     /* polling receive func. */    endEtherAddressForm,    /* put address info into a NET_BUFFER. */    endEtherPacketDataGet,  /* get pointer to data in NET_BUFFER. */    endEtherPacketAddrGet   /* Get packet addresses. */};      /********************************************************************************* wancomEndLoad - initialize the driver and device** This routine initializes both, driver and device to an operational state* using device specific parameters specified by <initString>.** The parameter string, <initString>, is an ordered list of parameters each* separated by a colon. The format of <initString> is,* "<memBase>:<memSize>:<nCFDs>:<nRFDs>:<flags>"** The GT64260A shares a region of memory with the driver.  The caller of this* routine can specify the address of this memory region, or can specify that* the driver must obtain this memory region from the system resources.** A default number of transmit/receive frames of 32 can be selected by* passing zero in the parameters <nTfds> and <nRfds>. In other cases, the* number of frames selected should be greater than two.** The <memBase> parameter is used to inform the driver about the shared* memory region.  If this parameter is set to the constant "NONE," then this* routine will attempt to allocate the shared memory from the system.  Any* other value for this parameter is interpreted by this routine as the address* of the shared memory region to be used. The <memSize> parameter is used* to check that this region is large enough with respect to the provided* values of both transmit/receive frames.** If the caller provides the shared memory region, then the driver assumes* that this region does not require cache coherency operations, nor does it* require conversions between virtual and physical addresses.** If the caller indicates that this routine must allocate the shared memory* region, then this routine will use cacheDmaMalloc() to obtain* some  non-cacheable memory.  The attributes of this memory will be checked,* and if the memory is not write coherent, this routine will abort and* return ERROR.** RETURNS: an END object pointer, or NULL on error.** SEE ALSO: ifLib,* .I "GT64260A Data Sheet"*/END_OBJ* wancomEndLoad    (    char *initString      /* parameter string */    )    {    WANCOM_DRV_CTRL *  pDrvCtrl;        /* pointer to WANCOM_DRV_CTRL structure */    UCHAR       enetAddr[6];    /* ethernet address */    WANCOM_DRV_LOG (DRV_DEBUG_LOAD, ("Loading end...\n"), 1, 2, 3, 4, 5, 6);    if ( initString == NULL )        return(NULL);    if ( initString[0] == (char)NULL )        {        bcopy ((char *)WANCOM_DEV_NAME, (void *)initString, WANCOM_DEV_NAME_LEN);        return(0);        }    /* allocate the device structure */    pDrvCtrl = (WANCOM_DRV_CTRL *) calloc (sizeof (WANCOM_DRV_CTRL), 1);    if ( pDrvCtrl == NULL )        return(NULL);    /* Parse InitString */    if ( wancomInitParse (pDrvCtrl, initString) == ERROR )        goto errorExit;    /* sanity check the unit number */    if ( pDrvCtrl->unit < 0 )        goto errorExit;    /* callout to perform init */    if ( sysWancomInit (pDrvCtrl->unit, &pDrvCtrl->port) == ERROR )        goto errorExit;    /* get CSR address from the WANCOM_PORT_INFO structure */    if ( (int)(pDrvCtrl->pCSR = pDrvCtrl->port.baseAddr) == (UINT32)NULL )        goto errorExit;    /* memory initialization */    if ( wancomInitMem (pDrvCtrl) == ERROR )        goto errorExit;    GT64260_INT_DISABLE;    /* initialize the Physical medium layer. Set MAC address */    wancomPhyInit (pDrvCtrl);    pDrvCtrl->attached = TRUE;    /* get our ethernet hardware address (MAC address)*/    bcopy ( (char *)&pDrvCtrl->port.enetAddr,            (char *)&enetAddr[0],            WANCOM_ADDR_LEN);    WANCOM_DRV_LOG (DRV_DEBUG_LOAD, ("wancomLoad... ADRR: 0x%x 0x%x 0x%x 0x%x 0x%x 0x%x \n "),                     enetAddr[0],                    enetAddr[1],                    enetAddr[2],                    enetAddr[3],                    enetAddr[4],                    enetAddr[5]);    pDrvCtrl->rxSemId = semBCreate(SEM_Q_PRIORITY, SEM_FULL);    /* endObj initializations */    if ( END_OBJ_INIT (&pDrvCtrl->endObj, (DEV_OBJ*) pDrvCtrl,                       WANCOM_DEV_NAME, pDrvCtrl->unit, &wancomNetFuncs,                       "GT-642xx Ethernet Enhanced Network Driver") == ERROR )        goto errorExit;    if ( END_MIB_INIT (&pDrvCtrl->endObj, M2_ifType_ethernet_csmacd,                        (u_char *) &enetAddr[0], WANCOM_ADDR_LEN,                       ETHERMTU, WANCOM_100MBS /*speed (assaf) */) == ERROR )        goto errorExit;    /* Mark the device ready */    END_OBJ_READY (&pDrvCtrl->endObj,                   IFF_NOTRAILERS | IFF_MULTICAST | IFF_BROADCAST);    WANCOM_DRV_LOG (DRV_DEBUG_LOAD, ("wancomLoad for port %d... Done \n"),                    pDrvCtrl->unit, 2, 3, 4, 5, 6);    return(&pDrvCtrl->endObj);    errorExit:    wancomUnload (pDrvCtrl);    free ((char *) pDrvCtrl);    return NULL;    }/********************************************************************************* wancomUnload - unload a driver from the system** RETURNS: N/A*/LOCAL STATUS wancomUnload    (    WANCOM_DRV_CTRL *pDrvCtrl        /* pointer to WANCOM_DRV_CTRL structure */    )    {    WANCOM_DRV_LOG (DRV_DEBUG_LOAD, ("Unloading end..."), 1, 2, 3, 4, 5, 6);    pDrvCtrl->attached = FALSE;    /* free lists */    END_OBJECT_UNLOAD (&pDrvCtrl->endObj);    /* free allocated memory if necessary */    if ( pDrvCtrl->pMemBase != NULL )        cacheDmaFree (pDrvCtrl->pMemBase);    /* free allocated memory if necessary */    if ( pDrvCtrl->pClsBase != NULL )        cacheDmaFree (pDrvCtrl->pClsBase);    cfree (pDrvCtrl->pMemArea);    if ( pDrvCtrl->addressTableBase )        cacheDmaFree((char*)pDrvCtrl->addressTableBase);    WANCOM_DRV_LOG (DRV_DEBUG_LOAD, ("wancomUnload... Done\n"), 1, 2, 3, 4, 5, 6);    return(OK);    }/********************************************************************************* wancomInitParse - parse parameter values from initString** RETURNS: OK or ERROR*/LOCAL STATUS wancomInitParse    (    WANCOM_DRV_CTRL *  pDrvCtrl,            /* pointer to WANCOM_DRV_CTRL structure */    char *  initString      /* parameter string */    )    {    char *  tok;            /* an initString token */    char *  holder = NULL;  /* points to initString fragment beyond tok */    tok = strtok_r (initString, ":", &holder);    if ( tok == NULL )        return ERROR;    pDrvCtrl->unit = atoi (tok);    tok = strtok_r (NULL, ":", &holder);    if ( tok == NULL )        return ERROR;    pDrvCtrl->pMemBase = (char *) strtoul (tok, NULL, 16);    tok = strtok_r (NULL, ":", &holder);    if ( tok == NULL )        return ERROR;    pDrvCtrl->memSize = strtoul (tok, NULL, 16);    tok = strtok_r (NULL, ":", &holder);    if ( tok == NULL )        return ERROR;    pDrvCtrl->nCFDs = strtoul (tok, NULL, 16);    tok = strtok_r (NULL, ":", &holder);    if ( tok == NULL )        return ERROR;    pDrvCtrl->nRFDs = strtoul (tok, NULL, 16);    tok = strtok_r (NULL, ":", &holder);    if ( tok == NULL )        return ERROR;    pDrvCtrl->flags = atoi (tok);    if ( !pDrvCtrl->nCFDs || pDrvCtrl->nCFDs <= 2 )        {        WANCOM_FLAG_SET (WANCOM_INV_NCFD);        pDrvCtrl->nCFDs = DEF_NUM_CFDS;        }    if ( !pDrvCtrl->nRFDs || pDrvCtrl->nRFDs <= 2 )        {        WANCOM_FLAG_SET (WANCOM_INV_NRFD);        pDrvCtrl->nRFDs = DEF_NUM_RFDS;        }    WANCOM_DRV_LOG (DRV_DEBUG_LOAD,                    ("wancomEndLoad: unit=%d pMemBase=0x%x memSize=0x%x nCFDs=%d nRFDs=%d flags=%d\n"),                    pDrvCtrl->unit,                     (int) pDrvCtrl->pMemBase,                    (int) pDrvCtrl->memSize,                    pDrvCtrl->nCFDs,                    pDrvCtrl->nRFDs,                    pDrvCtrl->flags);    return(OK);    }/******************************************************************************** wancomInitMem - initialize memory** RETURNS: OK or ERROR*/LOCAL STATUS wancomInitMem    (    WANCOM_DRV_CTRL *  pDrvCtrl    /* pointer to WANCOM_DRV_CTRL structure */    )    {    RX_DESC* pRxDesc;    RX_DESC* pRxTailDesc;    RX_DESC* pRxDummyDesc;    TX_DESC* pTxDesc;      TX_DESC* pTxPrevDesc;  /* Used for aid in initialize Tx descriptor ring */    TX_DESC* pTxFirstDesc;    UINT32  bufferPtr;     UINT32  descSize;       /* temporary size holder of descriptors */    UINT32  buffSize;       /* temporary size holder of clusters    */    int     ix;             /* a counter */    M_CL_CONFIG  wancomMclBlkConfig =    {        /* mBlkNum  	clBlkNum     	memArea     memSize         *-----------  	--------		-------     -------*/        0,              0,          NULL,       0    };    CL_DESC  wancomClDescTbl [] =    {        /*  clusterSize  		num    	memArea     memSize         *  -----------  		----	-------     -------*/        {ETHERMTU + EH_SIZE + 2,    0,      NULL,       0}        };    int wancomClDescTblNumEnt = (NELEMENTS (wancomClDescTbl));    /* initialize the netPool */    if ( (pDrvCtrl->endObj.pNetPool = malloc (sizeof (NET_POOL))) == NULL )        return(ERROR);    /* descSize holds the memory allocation for Tx and Rx descriptors		*/    descSize = ((pDrvCtrl->nRFDs) * RX_DESC_ALIGNED_SIZE +                 (pDrvCtrl->nCFDs) * TX_DESC_ALIGNED_SIZE );    /* buffSize holds the memory allocation for Rx clusters     			*/    buffSize = ((pDrvCtrl->nRFDs) * RX_BUFFER_DEFAULT_SIZE +                (pDrvCtrl->nRFDs) * RX_BUFFER_DEFAULT_SIZE );     /* 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -