Beispiel #1
0
/*
<:copyright-broadcom 
 
 Copyright (c) 2002 Broadcom Corporation 
 All Rights Reserved 
 No portions of this material may be reproduced in any form without the 
 written permission of: 
          Broadcom Corporation 
          16215 Alton Parkway 
          Irvine, California 92619 
 All information contained in this document is Broadcom Corporation 
 company private, proprietary, and trade secret. 
 
:>
*/
//**************************************************************************
// File Name  : Adsl.c
//
// Description: This file contains API for ADSL PHY
//
//**************************************************************************

#ifdef _WIN32_WCE
#include <windows.h>
#include <types.h>
#include <ceddk.h>
#include <memory.h>
#include <linklist.h>
#include <nkintr.h>
#include <hwcomapi.h>
#include <devload.h>
#include <pm.h>
#elif defined(_CFE_)
#include "lib_types.h"
#include "lib_string.h"
#include "lib_printf.h"
#include "boardparms.h"
#elif defined(TARG_OS_RTEMS)
#include <alloc.h>
#include <xapi.h>
#include "types.h"
#include "bspcfg.h"
#define ulong unsigned long
#else
#include <linux/version.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/wait.h>
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/jiffies.h>
#include "boardparms.h"
#endif

#ifndef _WIN32_WCE
#include "bcmtypes.h"
#endif

#include "softdsl/AdslCoreDefs.h"

#include "BcmOs.h"
#include "board.h"
#if defined(CONFIG_BCM96338)
#include "6338_map.h"
#endif
#if defined(CONFIG_BCM96358)
#include "6358_map.h"
#endif
#if defined(CONFIG_BCM96348)
#include "6348_map.h"
#endif
#if !defined(TARG_OS_RTEMS)
#include "bcm_intr.h"
#endif
#include "bcmadsl.h"
#include "BcmAdslCore.h"

#if !defined(__KERNEL__)
#define KERNEL_VERSION(a,b,c) 0x7fffffff
#endif

extern void BcmAdslCoreDiagWriteStatusString(char *fmt, ...);

#if !defined(TARG_OS_RTEMS)
LOCAL void		*g_TimerHandle;

LOCAL void BcmAdsl_Status(void);
LOCAL void BcmAdsl_Timer(void * arg);
#else
#define calloc(L,X)     xmalloc(L)
#define free(P)         xfree(P)
extern void AdslLinkReset(void);
LOCAL OS_SEMID  g_StatusSemId;
LOCAL OS_TASKID g_StatusTid;

LOCAL void StatusTask(void);
#endif


#ifdef VDF_SPAIN
int g_ulAdslCuts = 0;
int g_ulAdslOnLineStart = 0;
#endif



LOCAL void IdleNotifyCallback (ADSL_LINK_STATE AdslLinkState, UINT32 ulParm)
{
}

#define ADSL_RJ11_INNER_PAIR	0
#define ADSL_RJ11_OUTER_PAIR	1

LOCAL void SetRj11Pair( UINT16 usPairToEnable, UINT16 usPairToDisable );

LOCAL ADSL_FN_NOTIFY_CB g_pFnNotifyCallback = IdleNotifyCallback;
LOCAL UINT32 g_ulNotifyCallbackParm;
ADSL_LINK_STATE g_LinkState;
LOCAL unsigned short g_GpioInnerPair = 0xffff;
LOCAL unsigned short g_GpioOuterPair = 0xffff;
LOCAL unsigned short g_BoardType;
LOCAL int			 g_RJ11Pair = ADSL_RJ11_INNER_PAIR;
#ifndef DYING_GASP_API
#if defined(__KERNEL__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
LOCAL irqreturn_t BcmDyingGaspIsr(int irq, void * dev_id, struct pt_regs * regs);
#else
LOCAL unsigned int BcmDyingGaspIsr( void );
#endif
#endif
int g_nAdslExit = 0;
int g_nAdslInitialized = 0;
//LGD_FOR_TR098
unsigned long g_ShowtimeStartTicks = 0;
#ifdef _WIN32_WCE

BCMADSL_STATUS BcmAdsl_Initialize(ADSL_FN_NOTIFY_CB pFnNotifyCb, UINT32 ulParm, adslCfgProfile *pAdslCfg)
{
    DEBUGMSG (DBG_MSG, (TEXT("BcmAdsl_Initialize=0x%08X, &g_nAdslExit=0x%08X\n"), (int)BcmAdsl_Initialize, (int) &g_nAdslExit));

    BcmOsInitialize ();

    g_pFnNotifyCallback = (pFnNotifyCb != NULL) ? pFnNotifyCb : IdleNotifyCallback;
    g_ulNotifyCallbackParm = ulParm;

    //BcmAdslCoreSetSDRAMBaseAddr((void *) (((ulong) kerSysGetSdramSize() - 0x40000) | 0xA0000000));
    BcmAdslCoreSetSDRAMBaseAddr((void *) ((0x800000 - 0x40000) | 0xA0000000));
	BcmAdslCoreConfigure(pAdslCfg);

    BcmAdslCoreInit();
    g_LinkState = BCM_ADSL_LINK_DOWN;
    g_nAdslExit = 0;
	g_nAdslInitialized = 1;
	g_TimerHandle = bcmOsTimerCreate(BcmAdsl_Timer, NULL);
	if (NULL != g_TimerHandle)
		bcmOsTimerStart(g_TimerHandle, 1000);

	return BCMADSL_STATUS_SUCCESS;
}

#elif !defined(TARG_OS_RTEMS)

//**************************************************************************
// Function Name: BcmAdsl_Initialize
// Description  : Initializes ADSL PHY.
// Returns      : STS_SUCCESS if successful or error status.
//**************************************************************************
BCMADSL_STATUS BcmAdsl_Initialize(ADSL_FN_NOTIFY_CB pFnNotifyCb, UINT32 ulParm, adslCfgProfile *pAdslCfg)
{

    printk("BcmAdsl_Initialize=0x%08X, g_pFnNotifyCallback=0x%08X\n", (int)BcmAdsl_Initialize, (int) &g_pFnNotifyCallback);

    if (g_nAdslInitialized != 0) {
		BcmAdslCoreConfigure(pAdslCfg);
		return BCMADSL_STATUS_SUCCESS;
	}

    BcmOsInitialize ();
#ifndef DYING_GASP_API
	{
	unsigned long	ulIntr;
#if defined(CONFIG_BCM963x8)
#if defined(__KERNEL__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
    if( BpGetAdslDyingGaspExtIntr( &ulIntr ) == BP_SUCCESS ) 
#endif
	{
		BcmHalMapInterrupt((void *)BcmDyingGaspIsr, 0, INTERRUPT_ID_DG);
		BcmHalInterruptEnable( INTERRUPT_ID_DG );
    }
#endif
	}
#endif
    if( BpGetRj11InnerOuterPairGpios(&g_GpioInnerPair, &g_GpioOuterPair) == BP_SUCCESS ) {
        g_GpioInnerPair = GPIO_NUM_TO_MASK(g_GpioInnerPair);
        g_GpioOuterPair = GPIO_NUM_TO_MASK(g_GpioOuterPair);
    }
    else {
        g_GpioInnerPair = 0xffff;
        g_GpioOuterPair = 0xffff;
    }
    g_BoardType = 0;
    g_pFnNotifyCallback = (pFnNotifyCb != NULL) ? pFnNotifyCb : IdleNotifyCallback;
    g_ulNotifyCallbackParm = ulParm;

    BcmAdslCoreSetSDRAMBaseAddr((void *) (((unsigned long) kerSysGetSdramSize() - 0x40000) | 0xA0000000));
	BcmAdslCoreConfigure(pAdslCfg);

    BcmAdslCoreInit();
    g_LinkState = BCM_ADSL_LINK_DOWN;
    g_nAdslExit = 0;
	g_nAdslInitialized = 1;
	g_TimerHandle = bcmOsTimerCreate(BcmAdsl_Timer, NULL);
	if (NULL != g_TimerHandle)
		bcmOsTimerStart(g_TimerHandle, 1000);

    
	return BCMADSL_STATUS_SUCCESS;
}
#else /* defined(TARG_OS_RTEMS) */
BCMADSL_STATUS BcmAdsl_Initialize(ADSL_FN_NOTIFY_CB pFnNotifyCb, UINT32 ulParm, adslCfgProfile *pAdslCfg)
{
    typedef void (*FN_HDLR) (unsigned long);
    BcmOsInitialize ();

#if 0
/* The interrupt handling of the Dying gasp is controlled external */
    BcmHalMapInterrupt((FN_HDLR)BcmDyingGaspIsr, 0, INTERRUPT_ID_DYING_GASP);
    BcmHalInterruptEnable( INTERRUPT_ID_DYING_GASP );
#if defined(BOARD_bcm96348) || defined(BOARD_bcm96338)
    BcmHalMapInterrupt((FN_HDLR)BcmDyingGaspIsr, 0, INTERRUPT_ID_DG);
    BcmHalInterruptEnable( INTERRUPT_ID_DG );
#endif
#endif

    g_pFnNotifyCallback = (pFnNotifyCb != NULL) ? pFnNotifyCb : IdleNotifyCallback;
    g_BoardType = 0;
    g_ulNotifyCallbackParm = ulParm;
    bcmOsSemCreate(NULL, &g_StatusSemId);

    /* kerSysGetSdramSize subtracts the size reserved for the ADSL MIPS */
    BcmAdslCoreSetSDRAMBaseAddr((void *)
        ((unsigned long) kerSysGetSdramSize() | 0xA0000000));
    BcmAdslCoreConfigure(pAdslCfg);

    BcmAdslCoreInit();
    g_LinkState = BCM_ADSL_LINK_DOWN;
    g_nAdslExit = 0;
	g_nAdslInitialized = 1;
    bcmOsTaskCreate("ADSL", 20*1024, 50, StatusTask, 0, &g_StatusTid);
    
    return BCMADSL_STATUS_SUCCESS;
}
Beispiel #2
0
//**************************************************************************
// Function Name: BcmAdsl_Initialize
// Description  : Initializes ADSL PHY.
// Returns      : STS_SUCCESS if successful or error status.
//**************************************************************************
BCMADSL_STATUS BcmAdsl_Initialize(ADSL_FN_NOTIFY_CB pFnNotifyCb, UINT32 ulParm, adslCfgProfile *pAdslCfg)
{

    printk("BcmAdsl_Initialize=0x%08X, g_pFnNotifyCallback=0x%08X\n", (int)BcmAdsl_Initialize, (int) &g_pFnNotifyCallback);

    if (g_nAdslInitialized != 0) {
		BcmAdslCoreConfigure(pAdslCfg);
		return BCMADSL_STATUS_SUCCESS;
	}

    BcmOsInitialize ();
#ifndef DYING_GASP_API
	{
	unsigned long	ulIntr;
#if defined(CONFIG_BCM963x8)
#if defined(__KERNEL__) && (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
    if( BpGetAdslDyingGaspExtIntr( &ulIntr ) == BP_SUCCESS ) 
#endif
	{
		BcmHalMapInterrupt((void *)BcmDyingGaspIsr, 0, INTERRUPT_ID_DG);
		BcmHalInterruptEnable( INTERRUPT_ID_DG );
    }
#endif
	}
#endif
    if( BpGetRj11InnerOuterPairGpios(&g_GpioInnerPair, &g_GpioOuterPair) == BP_SUCCESS ) {
        g_GpioInnerPair = GPIO_NUM_TO_MASK(g_GpioInnerPair);
        g_GpioOuterPair = GPIO_NUM_TO_MASK(g_GpioOuterPair);
    }
    else {
        g_GpioInnerPair = 0xffff;
        g_GpioOuterPair = 0xffff;
    }
    g_BoardType = 0;
    g_pFnNotifyCallback = (pFnNotifyCb != NULL) ? pFnNotifyCb : IdleNotifyCallback;
    g_ulNotifyCallbackParm = ulParm;

    BcmAdslCoreSetSDRAMBaseAddr((void *) (((unsigned long) kerSysGetSdramSize() - 0x40000) | 0xA0000000));
	BcmAdslCoreConfigure(pAdslCfg);

    BcmAdslCoreInit();
    g_LinkState = BCM_ADSL_LINK_DOWN;
    g_nAdslExit = 0;
	g_nAdslInitialized = 1;
	g_TimerHandle = bcmOsTimerCreate(BcmAdsl_Timer, NULL);
	if (NULL != g_TimerHandle)
		bcmOsTimerStart(g_TimerHandle, 1000);

    
	return BCMADSL_STATUS_SUCCESS;
}
static int bcmPktDma_calc_txbds( void )
{
    uint32_t chnl;
#if defined(CONFIG_BCM_FAP) || defined(CONFIG_BCM_FAP_MODULE)
    int iudmaIdx;
#else
#if !defined(CONFIG_BCM96368)
    uint32_t tot_mem_size = kerSysGetSdramSize();
#endif
#endif

    chnl = 0;                 /* to avoid compiler warning */

#if defined(CONFIG_BCM_FAP) || defined(CONFIG_BCM_FAP_MODULE)
    /* Host config */
    for (chnl=0; chnl < ENET_TX_CHANNELS_MAX; chnl++)
    {
        if (g_Eth_tx_iudma_ownership[chnl] == HOST_OWNED)
            bcmPktDma_Bds_p->host.eth_txbds[chnl] = HOST_ENET_NR_TXBDS;
        else
            bcmPktDma_Bds_p->host.eth_txbds[chnl] = 0;
    }

    for (chnl=0; chnl < ENET_TX_CHANNELS_MAX; chnl++)
    {
        if (g_Eth_tx_iudma_ownership[chnl] == HOST_OWNED)
            bcmPktDma_Bds_p->host.eth_txdqm[chnl] = 0;
        else
            bcmPktDma_Bds_p->host.eth_txdqm[chnl] = DQM_HOST2FAP_ETH_XMIT_DEPTH_LOW;
    }

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    for (chnl=0; chnl < XTM_TX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_Bds_p->host.xtm_txbds[chnl] = 0;
    }

    for (chnl=0; chnl < XTM_TX_CHANNELS_MAX; chnl++)
    {
        if (g_Xtm_tx_iudma_ownership[chnl] == HOST_OWNED)
            bcmPktDma_Bds_p->host.xtm_txdqm[chnl] = 0;
        else
            bcmPktDma_Bds_p->host.xtm_txdqm[chnl] = DQM_HOST2FAP_XTM_XMIT_DEPTH_LOW;
    }
#endif /* defined(CONFIG_BCM_XTMCFG) */

    /* FAP config */
    for (iudmaIdx = 0; iudmaIdx < CONFIG_BCM_DEF_NR_TX_DMA_CHANNELS; iudmaIdx++)
    {
        if (g_Eth_tx_iudma_ownership[iudmaIdx] == HOST_OWNED)
            bcmPktDma_Bds_p->fap.eth_txbds[iudmaIdx] = 0;
        else
            bcmPktDma_Bds_p->fap.eth_txbds[iudmaIdx] = FAP_ENET_NR_TXBDS;
    }

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    for (chnl=0; chnl < XTM_TX_CHANNELS_MAX; chnl++)
    {
        if (g_Xtm_tx_iudma_ownership[chnl] == HOST_OWNED)
            bcmPktDma_Bds_p->fap.xtm_txbds[chnl] = 0;
        else
            bcmPktDma_Bds_p->fap.xtm_txbds[chnl] = FAP_XTM_NR_TXBDS;
    }
#endif /* defined(CONFIG_BCM_XTMCFG) */
#endif

#if defined(CONFIG_BCM96368)
    bcmPktDma_Bds_p->host.eth_txbds[0] = HOST_ENET_NR_TXBDS;

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    for (chnl=0; chnl < XTM_TX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_Bds_p->host.xtm_txbds[chnl] = HOST_XTM_NR_TXBDS;
    }
#endif

    bcmPktDma_Bds_p->fwd.eth_txbds[0] = FWD_ENET_NR_TXBDS;

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    bcmPktDma_Bds_p->fwd.xtm_txbds[0] = FWD_XTM_NR_TXBDS;
#endif
#endif

#if defined(CONFIG_BCM960333)
    /*
     * For Duna: read the number of network interfaces from Boardparms.
     * Currently we assign the same number of TX buffers to each interface.
     */
    {
        ETHERNET_MAC_INFO EnetInfo;
        int num_channels = 0;

        if (BpGetEthernetMacInfo(&EnetInfo, 1) != BP_SUCCESS)
        {
            return -ENODEV;
        }
        bitcount(num_channels, EnetInfo.sw.port_map);
        for (chnl = 0; chnl < num_channels; chnl++)
        {
            /* Setup the PLC TX ring size to hold up to 60% of BPM buffers */
            if (EnetInfo.sw.phyconn[chnl] == PHY_CONN_TYPE_PLC)
            {
                uint32_t tx_ring_size;
                tx_ring_size = kerSysGetSdramSize() / 100
                        * CONFIG_BCM_BPM_BUF_MEM_PRCNT * 60 / 100
                        / BCM_PKTBUF_SIZE;
                tx_ring_size = tx_ring_size & (uint32_t)(0xFFFFFFFE);
                if (tx_ring_size > 8192)
                {
                    tx_ring_size = 8192;
                }
                bcmPktDma_Bds_p->host.eth_txbds[chnl] = tx_ring_size;
            }
            /* Every other channel has a TX ring of default size */
            else
            {
                if (tot_mem_size <= 0x1600000)    // less than or equal to 16MB
                    bcmPktDma_Bds_p->host.eth_txbds[chnl] = HOST_ENET_NR_TXBDS/4;
                else
                    bcmPktDma_Bds_p->host.eth_txbds[chnl] = HOST_ENET_NR_TXBDS;
            }
        }
    }
#endif

#if !(defined(CONFIG_BCM96368) || defined(CONFIG_BCM960333)\
        || defined(CONFIG_BCM_FAP) || defined(CONFIG_BCM_FAP_MODULE))
    for (chnl=0; chnl < ENET_TX_CHANNELS_MAX; chnl++)
    {
        if (tot_mem_size <= 0x1600000)    // less than or equal to 16MB
            bcmPktDma_Bds_p->host.eth_txbds[chnl] = HOST_ENET_NR_TXBDS/4;
        else
            bcmPktDma_Bds_p->host.eth_txbds[chnl] = HOST_ENET_NR_TXBDS;
    }

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    for (chnl=0; chnl < XTM_TX_CHANNELS_MAX; chnl++)
    {
        if (tot_mem_size <= 0x1600000)    // less than or equal to 16MB
            bcmPktDma_Bds_p->host.xtm_txbds[chnl] = HOST_XTM_NR_TXBDS/4;
        else
            bcmPktDma_Bds_p->host.xtm_txbds[chnl] = HOST_XTM_NR_TXBDS;
    }
#endif
#endif

#if defined(BCM_PKTDMA_DUMP_BDS)
    bcmPktDma_dump_txbds();
#endif /* defined(BCM_PKTDMA_DUMP_BDS) */

    return 0;
}
static int bcmPktDma_calc_rxbds( void )
{
    uint32_t __attribute__((unused)) tot_mem_size = kerSysGetSdramSize();
#if (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE))
    uint32_t buf_mem_size = (tot_mem_size/100) * CONFIG_BCM_BPM_BUF_MEM_PRCNT;
    uint32_t tot_num_bufs=0;
#endif
    uint32_t chnl;
    uint32_t host_eth_rxbds;
#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    uint32_t host_xtm_rxbds;
#endif

    chnl = 0;                 /* to avoid compiler warning */

#if (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE))
    tot_num_bufs = (buf_mem_size/BCM_PKTBUF_SIZE);
#endif

#if defined(CONFIG_BCM_FAP) || defined(CONFIG_BCM_FAP_MODULE)
    /* ----------- FAP RX channel ---------- */
#if (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE))
/* Channel-0 is default */
    host_eth_rxbds = (ENET_DEF_RXBDS_BUF_PRCNT * tot_num_bufs/200);

    if (host_eth_rxbds < HOST_ENET_NR_RXBDS_MIN)
        host_eth_rxbds = HOST_ENET_NR_RXBDS_MIN;
#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    host_xtm_rxbds = (XTM_DEF_RXBDS_BUF_PRCNT * tot_num_bufs/200);

    if (host_xtm_rxbds < HOST_XTM_NR_RXBDS_MIN)
        host_xtm_rxbds = HOST_XTM_NR_RXBDS_MIN;
#endif
#else /* (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */
    host_eth_rxbds = HOST_ENET_NR_RXBDS;
#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    host_xtm_rxbds = HOST_XTM_NR_RXBDS;
#endif
#endif /* (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */

#if defined(CONFIG_BCM_GMAC)
    host_eth_rxbds /= 2;
#endif

    for (chnl=0; chnl < ENET_RX_CHANNELS_MAX; chnl++)
    {
        if (g_Eth_rx_iudma_ownership[chnl] == HOST_OWNED )
            bcmPktDma_Bds_p->host.eth_rxbds[chnl] = host_eth_rxbds;
        else
            bcmPktDma_Bds_p->host.eth_rxbds[chnl] = 0;

        bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->host.eth_rxbds[chnl];
    }

    for (chnl=0; chnl < ENET_RX_CHANNELS_MAX; chnl++)
    {
        if (g_Eth_rx_iudma_ownership[chnl] == HOST_OWNED )
            bcmPktDma_Bds_p->host.eth_rxdqm[chnl] = 0;
        else
        {
            bcmPktDma_Bds_p->host.eth_rxdqm[chnl] = 
                DQM_FAP2HOST_ETH_RX_DEPTH_LOW + DQM_FAP2HOST_ETH_RX_DEPTH_HI;
        }
    }

    /* XTM config */
#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    for (chnl=0; chnl < XTM_RX_CHANNELS_MAX; chnl++)
    {
        if (g_Xtm_rx_iudma_ownership[chnl] == HOST_OWNED)
        {
            bcmPktDma_Bds_p->host.xtm_rxbds[chnl] = host_xtm_rxbds;
        }
        else
            bcmPktDma_Bds_p->host.xtm_rxbds[chnl] =
                FAP_XTM_NON_DEF_CHNL_NR_RXBDS;

        bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->host.xtm_rxbds[chnl];
    }

    for (chnl=0; chnl < XTM_RX_CHANNELS_MAX; chnl++)
    {
        if (g_Xtm_rx_iudma_ownership[chnl] == HOST_OWNED)
            bcmPktDma_Bds_p->host.xtm_rxdqm[chnl] = 0;
        else
        {
            if (chnl == 0)
            {
                bcmPktDma_Bds_p->host.xtm_rxdqm[chnl] =
                    DQM_FAP2HOST_XTM_RX_DEPTH_LOW + DQM_FAP2HOST_XTM_RX_DEPTH_HI;
            }
            else
            {
                /* currently we using only 1 channel even when 2 channels are
                 * intialized, so keep the other channel size very low 
                 */
                bcmPktDma_Bds_p->host.xtm_rxdqm[chnl] = 16;
            }
        }
    }
#endif /* #if defined(CONFIG_BCM_XTMCFG) */

    /* FAP config */
    for (chnl=0; chnl < ENET_RX_CHANNELS_MAX; chnl++)
    {
        if (g_Eth_rx_iudma_ownership[chnl] == HOST_OWNED)
            bcmPktDma_Bds_p->fap.eth_rxbds[chnl] = 0;
        else
            bcmPktDma_Bds_p->fap.eth_rxbds[chnl] = FAP_ENET_NR_RXBDS;

        bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->fap.eth_rxbds[chnl];
    }

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    for (chnl=0; chnl < XTM_RX_CHANNELS_MAX; chnl++)
    {
        if (g_Xtm_rx_iudma_ownership[chnl] == HOST_OWNED)
            bcmPktDma_Bds_p->fap.xtm_rxbds[chnl] = 0;
        else
        {
            if (chnl == 0)
                bcmPktDma_Bds_p->fap.xtm_rxbds[chnl] = FAP_XTM_NR_RXBDS;
            else
                bcmPktDma_Bds_p->fap.xtm_rxbds[chnl] =
                    FAP_XTM_NON_DEF_CHNL_NR_RXBDS;
        }
        bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->fap.xtm_rxbds[chnl];
    }
#endif /* defined(CONFIG_BCM_XTMCFG) */
#endif /* defined(CONFIG_BCM_FAP) || defined(CONFIG_BCM_FAP_MODULE) */


#if defined(CONFIG_BCM96368)
#if (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE))
    /* ----------- CMF FWD RX ---------- */
    /* In case of 6368 because of CMF the number of RXBDs is divided
     * equally between Eth driver and CMF FWD */
    host_eth_rxbds = (ENET_DEF_RXBDS_BUF_PRCNT * tot_num_bufs/200);
    if (host_eth_rxbds < HOST_ENET_NR_RXBDS_MIN)
        host_eth_rxbds = HOST_ENET_NR_RXBDS_MIN;

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    host_xtm_rxbds = (XTM_DEF_RXBDS_BUF_PRCNT * tot_num_bufs/200);

    if (host_xtm_rxbds < HOST_XTM_NR_RXBDS_MIN)
        host_xtm_rxbds = HOST_XTM_NR_RXBDS_MIN;
#endif
#else /* (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */
    host_eth_rxbds = HOST_ENET_NR_RXBDS;
#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    host_xtm_rxbds = HOST_XTM_NR_RXBDS;
#endif
#endif /* (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */

    bcmPktDma_Bds_p->host.eth_rxbds[0] = host_eth_rxbds;
    bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->host.eth_rxbds[0];

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    bcmPktDma_Bds_p->host.xtm_rxbds[0] = host_xtm_rxbds;
    for (chnl=1; chnl < XTM_RX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_Bds_p->host.xtm_rxbds[chnl] = HOST_XTM_NON_DEF_CHNL_NR_RXBDS;
    }

    for (chnl=0; chnl < XTM_RX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->host.xtm_rxbds[chnl];
    }
#endif

    /* Note: The # of FWD RXBDs is equal to host RXBDs */
    bcmPktDma_Bds_p->fwd.eth_rxbds[0] = host_eth_rxbds;
    bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->fwd.eth_rxbds[0];

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    bcmPktDma_Bds_p->fwd.xtm_rxbds[0] = host_xtm_rxbds;
    bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->fwd.xtm_rxbds[0];
#endif
#endif

#if !(defined(CONFIG_BCM96368) || defined(CONFIG_BCM_FAP) || defined(CONFIG_BCM_FAP_MODULE))
    /* ----------- Eth RX channel ---------- */
#if (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE))
    host_eth_rxbds = ENET_DEF_RXBDS_BUF_PRCNT * tot_num_bufs/100;
#else /* (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */
    if (tot_mem_size <= 0x1600000)    // less than or equal to 16MB
        host_eth_rxbds = HOST_ENET_NR_RXBDS/4;
    else
        host_eth_rxbds = HOST_ENET_NR_RXBDS;
#endif /* (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */

    for (chnl=1; chnl < ENET_RX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_Bds_p->host.eth_rxbds[chnl] =
                    HOST_ENET_NON_DEF_CHNL_NR_RXBDS;
    }

#if defined(CONFIG_BCM_GMAC)
    host_eth_rxbds /= 2;
    bcmPktDma_Bds_p->host.eth_rxbds[0] = host_eth_rxbds;
    bcmPktDma_Bds_p->host.eth_rxbds[ENET_RX_CHANNELS_MAX-1] = host_eth_rxbds;
#else

#if defined(CONFIG_BCM960333)
    /*
     * For Duna: read the number of network interfaces from Boardparms.
     * Currently we assign the same number of RX buffers to each interface.
     */
    {
        ETHERNET_MAC_INFO EnetInfo;
        int num_channels = 0;

        if (BpGetEthernetMacInfo(&EnetInfo, 1) != BP_SUCCESS)
        {
            return -ENODEV;
        }
        bitcount(num_channels, EnetInfo.sw.port_map);
        for (chnl = 0; chnl < num_channels; chnl++)
        {
            bcmPktDma_Bds_p->host.eth_rxbds[chnl] =
                              host_eth_rxbds / num_channels;
        }
    }
#else
    bcmPktDma_Bds_p->host.eth_rxbds[0] = host_eth_rxbds;
#endif

#endif

    for (chnl=0; chnl < ENET_RX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->host.eth_rxbds[chnl];
    }

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    /* ----------- XTM RX channel ---------- */
#if (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE))
    host_xtm_rxbds = XTM_DEF_RXBDS_BUF_PRCNT * tot_num_bufs/100;
#else /* (defined(CONFIG_BCM_INGQOS) || defined(CONFIG_BCM_INGQOS_MODULE) || defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */

    /* ----------- XTM RX channel ---------- */
    {
        uint32_t tot_mem_size = kerSysGetSdramSize();

        if (tot_mem_size <= 0x800000)    // less than or equal to 8MB
            host_xtm_rxbds = 60;
        else if (tot_mem_size <= 0x1600000)    // less than or equal to 16MB
            host_xtm_rxbds = HOST_XTM_NR_RXBDS/4;
        else
            host_xtm_rxbds = HOST_XTM_NR_RXBDS;
    }
#endif /* (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE)) */

#if defined(CONFIG_BCM_XTMCFG) || defined(CONFIG_BCM_XTMCFG_MODULE)
    bcmPktDma_Bds_p->host.xtm_rxbds[0] = host_xtm_rxbds;
    for (chnl=1; chnl < XTM_RX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_Bds_p->host.xtm_rxbds[chnl] = HOST_XTM_NON_DEF_CHNL_NR_RXBDS;
    }

    for (chnl=0; chnl < XTM_RX_CHANNELS_MAX; chnl++)
    {
        bcmPktDma_tot_rxbds_g += bcmPktDma_Bds_p->host.xtm_rxbds[chnl];
    }
#endif
#endif
#endif

#if defined(BCM_PKTDMA_DUMP_BDS)
    bcmPktDma_dump_rxbds();
#endif /* defined(BCM_PKTDMA_DUMP_BDS) */

#if (defined(CONFIG_BCM_BPM) || defined(CONFIG_BCM_BPM_MODULE))
    printk( "Total # RxBds=%d\n", bcmPktDma_tot_rxbds_g);
    if (bcmPktDma_tot_rxbds_g > tot_num_bufs)
    {
        printk( "ERROR!!!!: Not enough buffers available\n" );
        printk( "ERROR!!!!: Either increase the %% of buffer memory "
                            "using make menuconfig\n" );
        printk( "ERROR!!!!: Or reduce the # of RxBDs (bcmPktDma_bds.h)\n" );
        return -1;
    }
    else if (bcmPktDma_tot_rxbds_g > (tot_num_bufs*2/3))
    {
        printk( "WARNING: # of RXBDs > (buffers*2/3)\n" );
        printk( "WARNING: less buffers available for BPM\n" );
    }
#endif

    return 0;
}