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

📄 sysmotfccend.c

📁 au1500开发的应用程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* sysMotFccEnd.c - system configuration module for motFccEnd driver */
 
/* Copyright 2002-2005 Founder Communications,Inc. */

/*
modification history
--------------------
01a,28feb05,fhchen  adapted from wrSbc8260Atm/sysMotFccEnd.c
*/
 
/*
DESCRIPTION

This is a modified version of WRS-supplied configuration module for
the VxWorks m8260FccEnd END driver.

It performs the dynamic parameterization of the motFccEnd driver.
This technique of 'just-in-time' parameterization allows driver
parameter values to be declared as any other defined constants rather
than as static strings.

Two FCC are used in SCB: FCC1 and FCC3, they use BRG5 and BRG8 respectively,
PHY address is 00001b and 10001b, MDIO is PC9 and MDC is PC10. PHY chip is
RTL8201BL.

*/

/* includes */

#include "vxWorks.h"
#include "config.h"
 
#include "vmLib.h"
#include "stdio.h"
#include "sysLib.h"
#include "logLib.h"
#include "stdlib.h"
#include "string.h"
#include "end.h"
#include "intLib.h"
#include "lstLib.h"
#include "drv/mem/m82xxDpramLib.h"
#include "miiLib.h"

/* defines */

#ifdef INCLUDE_MOTFCCEND

#define MOT_FCC_TBD_NUM		0x40	/* transmit buffer descriptors (TBD)*/
#define MOT_FCC_RBD_NUM		0x20	/* receive buffer descriptors (RBD)*/
#define MOT_FCC_DEF_PHY_MODE	0x02    /* PHY's default operating mode */
#define MOT_FCC_BDS_SIZE	(2 * 1024)   /* BD size */
#define MOT_FCC_MBLK_RBD_RATIO  0x03    /* Driver allocates (3* MOT_FCC_RBD_NUM) mBlk's */
#define MOT_FCC_CLUS_RBD_RATIO  0x04    /* Driver allocates (4* MOT_FCC_RBD_NUM) Clusters*/

#define MOT_FCC1_NUM		0x01    /* FCC1 */
#define MOT_FCC1_PHY_ADDR	0x01    /* FCC1 PHY address */
#define MOT_FCC1_TBD_NUM	MOT_FCC_TBD_NUM
#define MOT_FCC1_RBD_NUM	MOT_FCC_RBD_NUM
#define MOT_FCC1_DEF_PHY_MODE	MOT_FCC_DEF_PHY_MODE
#define MOT_FCC1_BDS_SIZE	MOT_FCC_BDS_SIZE
#define MOT_FCC1_MBLK_RBD_RATIO  MOT_FCC_MBLK_RBD_RATIO
#define MOT_FCC1_CLUS_RBD_RATIO  MOT_FCC_CLUS_RBD_RATIO

#define MOT_FCC3_NUM		0x03    /* FCC3 */
#define MOT_FCC3_PHY_ADDR	0x11    /* FCC3 PHY address */
#define MOT_FCC3_TBD_NUM	MOT_FCC_TBD_NUM
#define MOT_FCC3_RBD_NUM	MOT_FCC_RBD_NUM
#define MOT_FCC3_DEF_PHY_MODE	MOT_FCC_DEF_PHY_MODE
#define MOT_FCC3_BDS_SIZE	MOT_FCC_BDS_SIZE
#define MOT_FCC3_MBLK_RBD_RATIO  MOT_FCC_MBLK_RBD_RATIO
#define MOT_FCC3_CLUS_RBD_RATIO  MOT_FCC_CLUS_RBD_RATIO

/* imports */
 
IMPORT END_OBJ * motFccEndLoad (char *);
IMPORT UINT32    sysPCGet (void);
IMPORT FUNCPTR	 _func_motFccPhyLSCInt;
IMPORT FUNCPTR   _func_motFccPhyInit;
IMPORT FUNCPTR   _func_motFccPhyDuplex;
IMPORT FUNCPTR   _func_m82xxDpramFree;
IMPORT FUNCPTR	 _func_m82xxDpramFccMalloc;
IMPORT FUNCPTR	 _func_m82xxDpramFccFree;
IMPORT STATUS	 miiPhyInit(PHY_INFO * phyInfo);

/* globals */

UINT32 miiNumLinkChgInts = 0;
UINT32 miiBitRdCount     = 0;
UINT32 miiBitWrCount     = 0;

/* locals */

/*
 * this table may be customized by the user to force a
 * particular order how different technology abilities may be
 * negotiated by the PHY. Entries in this table may be freely combined
 * and even OR'd together.
 */
 
LOCAL INT16 motFccAnOrderTbl [] = {
                                MII_TECH_100BASE_TX,    /* 100Base-T */
                                MII_TECH_100BASE_T4,    /* 100Base-T4 */
                                MII_TECH_10BASE_T,      /* 10Base-T */
                                MII_TECH_10BASE_FD,     /* 10Base-T FD */
                                MII_TECH_100BASE_TX_FD, /* 100Base-T FD */
                                -1                      /* end of table */
                               };

/* forward declarations */

STATUS sysFccEnetAddrGet (int unit,UCHAR *address);
STATUS sysFccEnetEnable (UINT32 immrVal, UINT8 fccNum);
STATUS sysFccEnetCommand(UINT32 immrVal, UINT8	fccNum,	UINT16	command);
STATUS sysFccMiiBitWr (UINT32 immrVal, UINT8 fccNum, INT32 bitVal);
STATUS sysFccMiiBitRd (UINT32 immrVal, UINT8 fccNum, INT8 * bitVal);
STATUS sysFccEnetDisable (UINT32 immrVal, UINT8 fccNum);

/* macro */

#ifndef NSDELAY
#define MOTOROLA_FCC_LOOP_NS 2

#define NSDELAY(nsec)                                                   \
    {                                                                   \
    volatile int nx = 0;                                                \
    volatile int loop = (int)(nsec*MOTOROLA_FCC_LOOP_NS);               \
                                                                        \
    for (nx = 0; nx < loop; nx++);                                      \
    }
#endif /* NSDELAY */

/***********************************************************************
*
* sysMotFcc1EndLoad - load an instance of the motFccEnd driver for FCC1
*
* This routine loads the motFccEnd driver with proper parameters,
* and sets up the load string accordingly.
*
* The END device load string formed by this routine is in the following
* format.
* <immrVal>:<fccNum>:<bdBase>:<bdSize>:<bufBase>:<bufSize>:<fifoTxBase>
* :<fifoRxBase>:<tbdNum>:<rbdNum>:<phyAddr>:<phyDefMode>:<pAnOrderTbl>:
* <userFlags>:<mBlkRatio>:<mBlkRatio>
*
* .IP <immrVal>
* Internal memory address
* .IP <fccNum>
* FCC number being used
* .IP <bdBase>
* buffer descriptors base address
* .IP <bdSize>
* buffer descriptors space size
* .IP <bufBase>
* data buffers base address
* .IP <bufSize>
* data buffers space size
* .IP <fifoTxBase>
* tx buffer in internal memory
* .IP <fifoRxBase>
* rx buffer in internal memory
* .IP <tbdNum>
* number of TBDs or NONE
* .IP <rbdNum>
* number of RBDs or NONE
* .IP <phyAddr>
* address of a MII-compliant PHY device
* .IP <phyDefMode>
* default operating mode of a MII-compliant PHY device
* .IP <pAnOrderTbl>
* auto-negotiation order table for a MII-compliant PHY device or NONE
* .IP <userFlags>
* User flages
* .IP <mBlkRatio>
* Ratio between mBlk's and Rx BD's
* .IP <clusterRatio>
* Ratio between Clusters and Rx BD's
*
* This routine only loads and initializes one instance of the device.
* If the user wishes to use more than one motFccEnd devices, this routine
* should be changed.
*
* RETURNS: pointer to END object or NULL.
*
* SEE ALSO: motFccEndLoad ()
*/
 
END_OBJ * sysMotFcc1EndLoad
    (
    char * pParamStr,   /* ptr to initialization parameter string */
    void * unused       /* unused optional argument */
    )
    {
    /*
     * The motFccEnd driver END_LOAD_STRING should be:
     * <immrVal>:<fccNum>:<bdBase>:<bdSize>:<bufBase>:<bufSize>:<fifoTxBase>
     * :<fifoRxBase>:<tbdNum>:<rbdNum>:<phyAddr>:<phyDefMode>
     * :<pAnOrderTbl>:<userFlags>:<mBlkRatio>:<clusterRatio>
     * 
     * Note that unit string is prepended by the mux, so we
     * don't put it here.
     */
 
    char * pStr = NULL;
    char   paramStr[300];
    UINT32 regPC;
    UINT32 motFccBufsDescAdr;
    UINT32 motFccBufsDescSize;
    UINT32 motFccBufsAdr;
    UINT32 motFccBufsSize;
    UINT32 motFccFlags;

    static char motFccEndParamTemplate [] = 
    "0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x";

    END_OBJ * pEnd;

    _func_m82xxDpramFree = (FUNCPTR)m82xxDpramFree;
    _func_m82xxDpramFccMalloc = (FUNCPTR)m82xxDpramFccMalloc;
    _func_m82xxDpramFccFree = (FUNCPTR)m82xxDpramFccFree;
 
    if (strlen (pParamStr) == 0) 
        {
        /*
         * muxDevLoad() calls us twice. If the string is
         * zero length, then this is the first time through
         * this routine. We just call motFccEndLoad to get
         * the device name.
         */

        pEnd = (END_OBJ *) motFccEndLoad  (pParamStr);
        }
    else
        {

        /* the second time through this routine, do actual init */

	regPC = sysPCGet ();
	
        /* setting buffer address, buffer size and user flags */

	if ((regPC & ROM_BASE_ADRS) == ROM_BASE_ADRS)
	    {
            /* We are running from ROM */

	    /* 
             * ROM resident applications MUST use the option, while RAM resident
             * MAY use the option, which forces all driver buffers (rx and tx)
             * to reside in local bus space. The drawback to having buffers on
             * the local bus is that the driver MUST copy all transmit packets
             * to the local bus -- so zcopy must be inhibited. The driver still
             * passes rx data zcopy.
             *
             */

	    /* for ROM apps, specify local bus space for the buffers */

            motFccBufsAdr  = LOCAL_BUS_SDRAM_ADRS;
            motFccBufsSize = LOCAL_BUS_SDRAM_SIZE >> 2;
            
            /* for ROM apps, MOT_FCC_FLAGS *must* include the following. */

            motFccFlags = 0x0000D000; /*(MOT_FCC_USR_BUF_LBUS|MOT_FCC_USR_NO_ZCOPY|MOT_FCC_USR_DPRAM_ALOC)*/
						
	    /* 
             * NOTE! The FCC driver internally forces MOT_FCC_USR_NO_ZCOPY if
             * MOT_FCC_USR_BUF_LBUS is set in MOT_FCC_FLAGS, making the
	     * inclusion of 'NO_ZCOPY not strictly required. The 'NO_ZCOPY
	     * flag can be used independently of the bus on which buffers
	     * reside -- for those rare apps that might need this option.
             */
	    }
	else
	    {
            /* We are running from RAM */

            /* for RAM apps, let the driver find space for the buffers */

            motFccBufsAdr  = -1UL;
            motFccBufsSize = -1UL;
            motFccFlags    = 0x00008000; /* MOT_FCC_USR_DPRAM_ALOC */
            }

	/* 
         * NOTE! (Regarding bus choices for BDs and buffers)
         * 
         * - If you give a local bus address for BDs and don't include
         *   MOT_FCC_USR_BD_LBUS in MOT_FCC_FLAGS, the CPM will hang.
         *
         * - If you give a local bus address for buffers and don't include
         *   MOT_FCC_USR_BUF_LBUS in MOT_FCC_FLAGS, the CPM will hang.
         * 
         * - If you give a 60x bus address for buffers and/or BDs and
         *   mistakenly include either a 'LBUS flag, the CPM will hang.
         */

        /* setting BD address and BD size */

	/* 
         * - If you want the driver to decide where to put the BDs, set BOTH of
	 *   the following motFccBufsDescAdr & motFccBufsDescSize to -1UL.
	 *
	 * - If you decide to force the driver to use BDs on the local bus, set
	 *   the following motFccBufsDescAdr to a local bus address and size AND
	 *   be sure to add MOT_FCC_USR_BD_LBUS to the definition of
	 *   MOT_FCC_FLAGS below.
	 *
	 * - The defaults use internal DPRAM for BDS. You may optionally specify
	 *   a 60x bus address for BDS.  In these cases do not set the LBUS
	 *   flag.
         */

	motFccBufsDescSize = MOT_FCC1_BDS_SIZE;

	if ((motFccBufsDescAdr = (UINT32)m82xxDpramAlignedMalloc (MOT_FCC1_BDS_SIZE,8)) == 0)
	    {
	    motFccBufsDescAdr = -1UL;
            }

        /*
         * On the second pass through here, we actually create
         * the initialization parameter string on the fly.
         * Note that we will be handed our unit number on the
         * second pass and we need to preserve that information.
         * So we use the unit number handed from the input string.
         */
 
        pStr = strcpy (paramStr, pParamStr);
 
        /* Now, we get to the end of the string */
 
        pStr += strlen (paramStr);
 
	/* finish off the initialization parameter string */

        sprintf (pStr, motFccEndParamTemplate,
			(UINT) vxImmrGet(),
			MOT_FCC1_NUM,
			motFccBufsDescAdr,
			motFccBufsDescSize,
			motFccBufsAdr,
			motFccBufsSize,
			-1UL,-1UL,
			MOT_FCC1_TBD_NUM,  	
			MOT_FCC1_RBD_NUM,  	
			MOT_FCC1_PHY_ADDR,  	
			MOT_FCC1_DEF_PHY_MODE,  	
			&motFccAnOrderTbl,
			motFccFlags,
			MOT_FCC1_MBLK_RBD_RATIO,
			MOT_FCC1_CLUS_RBD_RATIO
		 );

        if ((pEnd = (END_OBJ *) motFccEndLoad(paramStr)) == (END_OBJ *)NULL) 
            {
            logMsg ("sysMotFcc1Endload: Error, motFccEndLoad failed to load driver for FCC1\n",
                    0, 0, 0, 0, 0, 0);
            }
        }

    return pEnd;
    }

/***********************************************************************
*
* sysMotFcc3EndLoad - load an instance of the motFccEnd driver for FCC3
*
* This routine loads the motFccEnd driver with proper parameters,
* and sets up the load string accordingly. It is almost the same as
* sysMotFcc1EndLoad except the following:
* - motFccBufsAdr
* - Those macros defined at head of this file
*   - FCC number
*   - PHY number
*
* RETURNS: pointer to END object or NULL.
*
* SEE ALSO: motFccEndLoad ()
*/

END_OBJ * sysMotFcc3EndLoad
    (
    char * pParamStr,   /* ptr to initialization parameter string */
    void * unused       /* unused optional argument */
    )
    {
    /*
     * The motFccEnd driver END_LOAD_STRING should be:
     * <immrVal>:<fccNum>:<bdBase>:<bdSize>:<bufBase>:<bufSize>:<fifoTxBase>
     * :<fifoRxBase>:<tbdNum>:<rbdNum>:<phyAddr>:<phyDefMode>
     * :<pAnOrderTbl>:<userFlags>:<mBlkRatio>:<clusterRatio>
     * 
     * Note that unit string is prepended by the mux, so we
     * don't put it here.
     */
 
    char * pStr = NULL;
    char   paramStr[300];
    UINT32 regPC;
    UINT32 motFccBufsDescAdr;
    UINT32 motFccBufsDescSize;
    UINT32 motFccBufsAdr;
    UINT32 motFccBufsSize;
    UINT32 motFccFlags;

    static char motFccEndParamTemplate [] = 
    "0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x:0x%x";

    END_OBJ * pEnd;

    _func_m82xxDpramFree = (FUNCPTR)m82xxDpramFree;
    _func_m82xxDpramFccMalloc = (FUNCPTR)m82xxDpramFccMalloc;
    _func_m82xxDpramFccFree = (FUNCPTR)m82xxDpramFccFree;
 
    if (strlen (pParamStr) == 0) 
        {
        /*
         * muxDevLoad() calls us twice. If the string is
         * zero length, then this is the first time through
         * this routine. We just call motFccEndLoad to get
         * the device name.
         */

        pEnd = (END_OBJ *) motFccEndLoad  (pParamStr);
        }
    else
        {

        /* the second time through this routine, do actual init */

	regPC = sysPCGet ();
	
        /* setting buffer address, buffer size and user flags */

	if ((regPC & ROM_BASE_ADRS) == ROM_BASE_ADRS)
	    {
            /* We are running from ROM */

	    /* 
             * ROM resident applications MUST use the option, while RAM resident
             * MAY use the option, which forces all driver buffers (rx and tx)
             * to reside in local bus space. The drawback to having buffers on
             * the local bus is that the driver MUST copy all transmit packets
             * to the local bus -- so zcopy must be inhibited. The driver still
             * passes rx data zcopy.
             *
             */

	    /* for ROM apps, specify local bus space for the buffers */

            motFccBufsAdr  = LOCAL_BUS_SDRAM_ADRS + (LOCAL_BUS_SDRAM_SIZE >> 2);
            motFccBufsSize = LOCAL_BUS_SDRAM_SIZE >> 2;
            
            /* for ROM apps, MOT_FCC_FLAGS *must* include the following. */

            motFccFlags = 0x0000D000; /*(MOT_FCC_USR_BUF_LBUS|MOT_FCC_USR_NO_ZCOPY|MOT_FCC_USR_DPRAM_ALOC)*/
						
	    /* 
             * NOTE! The FCC driver internally forces MOT_FCC_USR_NO_ZCOPY if
             * MOT_FCC_USR_BUF_LBUS is set in MOT_FCC_FLAGS, making the
	     * inclusion of 'NO_ZCOPY not strictly required. The 'NO_ZCOPY
	     * flag can be used independently of the bus on which buffers
	     * reside -- for those rare apps that might need this option.
             */
	    }
	else
	    {
            /* We are running from RAM */

            /* for RAM apps, let the driver find space for the buffers */

            motFccBufsAdr  = -1UL;
            motFccBufsSize = -1UL;
            motFccFlags    = 0x00008000; /* MOT_FCC_USR_DPRAM_ALOC */
            }

	/* 
         * NOTE! (Regarding bus choices for BDs and buffers)
         * 
         * - If you give a local bus address for BDs and don't include
         *   MOT_FCC_USR_BD_LBUS in MOT_FCC_FLAGS, the CPM will hang.
         *
         * - If you give a local bus address for buffers and don't include
         *   MOT_FCC_USR_BUF_LBUS in MOT_FCC_FLAGS, the CPM will hang.
         * 
         * - If you give a 60x bus address for buffers and/or BDs and
         *   mistakenly include either a 'LBUS flag, the CPM will hang.
         */

        /* setting BD address and BD size */

	/* 
         * - If you want the driver to decide where to put the BDs, set BOTH of
	 *   the following motFccBufsDescAdr & motFccBufsDescSize to -1UL.
	 *
	 * - If you decide to force the driver to use BDs on the local bus, set
	 *   the following motFccBufsDescAdr to a local bus address and size AND
	 *   be sure to add MOT_FCC_USR_BD_LBUS to the definition of
	 *   MOT_FCC_FLAGS below.
	 *
	 * - The defaults use internal DPRAM for BDS. You may optionally specify

⌨️ 快捷键说明

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