/******************************************************************************/
/*                                                                            */
/*         Copyright(c) 2000-2002 by Ikanos Communications Inc.               */
/*                                                                            */
/*  All rights are reserved.  Reproduction in whole or in part is prohibited  */
/*  without the written consent of the copyright owner.                       */
/*                                                                            */
/*  The information and contents of this file are the proprietary information */
/*  of Ikanos Communication and may not be disclosed or used without the      */
/*  formal written approval of Ikanos Communication Inc.                      */
/*                                                                            */
/*  This Copyright notice may not be removed or modified without prior        */
/*  written consent of Ikanos Communications, Inc.                            */
/*                                                                            */
/******************************************************************************/
/*
**  Filename:    HostPtmfApi.c
**
**  Project:     Ikanos INI ASIC (AMUR) Software Integration
**
**  Target:      MOTOROLA XPC855T based host board
**
**  Platform specific:
**    None.
**
**  Description:
**
**  **************************************************************************** 
**  Public Functions:
**
**  **************************************************************************** 
**  Private Functions:
**
**  **************************************************************************** 
**  Modification History:
**
**    Date         By     Description
**    -----------  ---    ------------------------------------------------------
**	  Jun-16-2002  SFA    Created
**    Jul-17-2002  SFA    Integration into new host code
*/
/******************************************************************************/
/*------------------------------------------------------------------------------
  INCLUDE FILES
  ----------------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>    

#include "dapi.h"
#include "apiosmacro.h"
#include "HostPtmfApi.h"
#include "HostPtmfHwRegs.h"

/*------------------------------------------------------------------------------
  PRIVATE PREPROCESSOR CONSTANTS
  ----------------------------------------------------------------------------*/
/*------------------------------------------------------------------------------
  PRIVATE PREPROCESSOR MACROS
  ----------------------------------------------------------------------------*/
#define PTMF_DEBUG
#define PTMF_RESUME_FRAME_CRC (3503309577)
#define PTMF_PAUSE_FRAME_CRC  (1310758184)

#define PTMF_STR              "EIU"
#define PTMF_ASIC_PART        22111
#define PTMF_ASIC_VERSION     1

/*------------------------------------------------------------------------------
  PRIVATE ENUMERATION DEFINITIONS
  ----------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
  PRIVATE TYPE DEFINITIONS
  ----------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
  PUBLIC VARIABLES DEFINITIONS
  ----------------------------------------------------------------------------*/
static U8               s_bEnetPort = 0;
//static U8               s_bEnetPhyMdioAddr;

int                      dropFrameEnable = 1;

tsIposPtmfCounters      tsIniCounters[MAX_ENET_PORTS];

tsIposPtmfPortConfig    tsIniPortParams[MAX_ENET_PORTS];

tsIposPtmfConfig        tsIniDefaultConfig = {

  PTMF_MDIO_ADDR,                         // Phy MDIO base address for port 0
  PTMF_MODE,                              // INI default mode = RMII
  PTMF_MAX_PORTS_PER_CHIP,                // Max. Ethernet Ports per PTMF 
  PTMF_ENET_PHY_BASE_ADDR,                // Ethernet PHY MDIO base address

  MAX_UTOPIA_PHYS,                        // Max. Utopia PHYS = 16
  IPOS_MAX_BME,                           // Max. RX ENABLE SIGNAL per BME

  UTOP_CELL_HEC_HDR,                      // ATM MODE
  UTOP_TRAFF_NO_IDLE_CELL,                // Idle cell generation OFF
  
  0x7e,                                   // HDLC Special Bytes 
  0xb7,                                   // HEC Byte (Cell byte 5)
  0xde,                                   // Non-Unity Byte (Cell byte 4)

  0,                                      // Not used for INI ASIC
  0,                                      // Not used for INI ASIC
  PTMF_MII_PORT_MAP,                      // xMII Port MAP

  FLOW_CONTROL_DUPLEX,                    // bFlowControl = ON
  DUPLEX_FULL,                            // bDuplex = FULL
  PORT_SPEED_100                          // bPortSpeed = 100Mbps
};

tsIposPtmfPortConfig      tsIniPortDefault = {

  0,                        // bPortIndex;  
  0,                        // bPtmfBaseAddr
  0,                        // bRxEnable
  0,                        // bPortAddr
  0,                        // bUtopiaPort

  FLOW_CONTROL_NONE,        // bFlowControl
  DUPLEX_FULL,              // bDuplex
  PORT_SPEED_100,           // bPortSpeed

  0x1,                      // bPauseFrameSrcAddr
  PTMF_PAUSE_FRAME_CRC,     // uiPauseFrameCrc
  PTMF_RESUME_FRAME_CRC,    // uiResumeFrameCrc

  FIFO_SIZE_16K,            // bTxFifoSize
  0,                        // bTxFifoAddr
  FIFO_WATERMARK_4K,        // bTxFifoLwm
  FIFO_WATERMARK_12K,       // bTxFifoHwm

  FIFO_SIZE_16K,            // bRxFifoSize
  0,                        // bRxFifoAddr
  FIFO_WATERMARK_12K,       // bRxFifoHwm

  0,                        // bTxHdlcHcf: HDLC TX Control field default
  0,                        // bTxHdlcHaf: HDLC TX Address field default

  FILTER_HDLC_CRC,          // bFilterHdlcCrc: Suppress HDLC CRC Errors = YES
  FILTER_ENET_CRC,          // bFilterEnetCrc: Suppress Ethernet CRC Errors = YES

  ENET_INVALID_LINK,        // bEnetLinkStatus: Ethernet Link = Down ; default
  0,                        // bEnetPhyAddr
  0                         // bMiiMode
};

#ifdef PTMF_DEBUG

#ifndef BME_CPE_20
static U16 auiBmeReg[]={
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0x4000 
};

static U16 auiPhyAddrReg[]={
  1,
  2,
  3,
  4,
  5,
  6,
  7,
  8,
  9,
  0xa,
  0xb,
  0xc, 
  0xd,
  0xe,
  0xf 
};

#endif

static U16 auiUtopiaPollReg[]={
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0, 
  0,
  0,
  0,
  0
};

static U16 auiUtopiaMonitorReg[]={
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0,
  0, 
  0,
  0,
  0,
  0
};

static U16 auiPtmfPortReg[]={
  0x7b02,   //    xMII PORT CONFIG REG

#if defined(BME_CPE_20)
  0,        //    ADDR FILT CONFIG REG
  0,        //    ADR FILT TABLE EN REG
#endif

  0,        //    TX FIFO CONFIG REG 0
  0,        //    TX FIFO CONFIG REG 1
  0,        //    RX FIFO CONFIG REG 0
  0,        //    RX FIFO CONFIG REG 1
  0x3,      //    CLK/RST CONFIG REG  
  0,        //    DEBUG CONFIG REG    

#if defined(BME_CPE_20)
  0,        //    RX PAUSE CTR REG
#endif

  0x3ff,    //    TX HDLC ADR/CNT REG 
  0,        //    RX HDLC ADR/CNT REG 
  0x40,     //    MIN FRAME SIZE  REG 
  0x600,    //    MAX FRAME SIZE  REG 
  0x19a,    //    xMII SLOT COUNT REG 
  0,        //    47-40 BITS OF SA REG
  0x5657,   //    PF CRC LS WORD      
  0x5554,   //    PF CRC MS WORD      
  0xacad,   //    RF CRC LS WORD      
  0xaaab,   //    RF CRC MS WORD      

#if defined(BME_CPE_20)
  0xfff,    //    ADDR FILT AGING CNT
  0x804,    //    JAM SEQUENCE LENGTH
  0x5555,   //    JAM SEQUENCE TYPE
#endif

  0,        //    TX FIFO RD POINTER  
  0,        //    TX FIFO WR POINTER  
  0,        //    RX FIFO RD POINTER  
  0,        //    RX FIFO WR POINTER  
  0,        //    TX START FRAME PTR  
  0,        //    RX START FRAME PTR  
};
      
#endif // PTMF_DEBUG

/*------------------------------------------------------------------------------
  PRIVATE VARIABLES DEFINITIONS
  ----------------------------------------------------------------------------*/

/*------------------------------------------------------------------------------
  PRIVATE FUNCTION PROTOTYPE
  ----------------------------------------------------------------------------*/
eIniRetCode
  PrIniUtopiaPollAdd (U8 bPortNumber);

eIniRetCode
  PrIniUtopiaPollRemove (U8 bPortNumber);

U32 
  PrIniMapDsl2Enet (U8 bPortNumber);

void 
  PrIniResetPort (U8 bPortNumber);

void 
  PrIniSetClock (U8 bPtmfBaseAddr);

U32
  PrIniReadDword (U8 bPortNumber, U16 uiRegAddr);

U32
  PrIniReadWord (U8 bPortNumber, U16 uiRegAddr);

void
  PrIniClrCounter (U8 bPortNumber);

void
  PrIniEnetPhyAutoNegotiate (U8 bEnetPortCount);

/*------------------------------------------------------------------------------
  PUBLIC FUNCTION DEFINITIONS
  ----------------------------------------------------------------------------*/
/******************************************************************************
*                                                                             *
* Function.. : iposPtmfGetVersion                           	                *
*                                                   	                        *
* Purpose... : Reads the part number and version number from the definition   *
*              and copy it to the array as a string.                          *
*									                                                            *
* Parameters : Array Pointer                                                  *
*                                                                             *
* Returns... : None                                                           *
*                                                                             *
******************************************************************************/

void iposPtmfGetVersion(char *psVerString)
{
  char abPtmfVerRet[50];
  
	sprintf(abPtmfVerRet,"%s: Part Number: %i Version: %i", PTMF_STR,
                                                          PTMF_ASIC_PART, 
                                                          PTMF_ASIC_VERSION);
#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\n %s\n",abPtmfVerRet);
#endif //DEBUG_INI

  if (psVerString)
    strcpy(psVerString, abPtmfVerRet);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfSetup                                	                *
*                                                   	                        *
* Purpose... : Initialise the INI ASIC AMUR chip                    	        *
*									                                                            *
* Parameters : Pointer to global parameter structure                          *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
eIniRetCode 
  iposPtmfSetup (
    ptsIposPtmfConfig  ptsPtmfConfig)   /* Pointer to global parameter struct */
{
  U16                 uiMaxEnetPort;
  U16                 uiMiiPortMap;
  U8                  i, bPortIndex;
  U8                  bFifoSize, bLwm, bHwm;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC SETUP ");
#endif //DEBUG_INI

  /* if the config structure pointer passed is NULL, use default              */
  if (ptsPtmfConfig == NULL)
  {
    ptsPtmfConfig = &tsIniDefaultConfig;

#ifdef DEBUG_INI
    if (gbDebugLevel <= 2)
      printf("\nINI ASIC: USE DEFAULT..... ");
#endif //DEBUG_INI

  }
  
  if (s_bEnetPort)
  {
    if (ptsPtmfConfig->bIniMdioAddr == 
      tsIniPortParams[s_bEnetPort-1].bPtmfBaseAddr)
    {
      printf("\n PTMF already initialized!");
      return HOST_INI_UNDEFINED_ERROR;
    }
  }
  // Before any MDIO transaction, create a mutex to protect the MDIO bit 
  // access through multiple tasks.
  iposPtmfSemCreate ();

#ifndef BME_CPE_20
  PrIniSetClock(ptsPtmfConfig->bIniMdioAddr);
#endif

  /* Initialise the INI ASIC Chip for data traffic                            */
  iposPtmfInit(ptsPtmfConfig);

  uiMaxEnetPort = s_bEnetPort + ptsPtmfConfig->bIniMaxEnetPort;
  uiMiiPortMap = ptsPtmfConfig->uiMiiPortMap;
  bPortIndex = 0;

//  printf("\n MAX PTMF PORT = %04x ", MAX_ENET_PORTS);        

  for ( i = 0; 
        i < ptsPtmfConfig->bIniMaxEnetPort;
        i ++ )

  {
    // Check if passed Max Ethernet port number exceeds total system ports
    if (MAX_ENET_PORTS == (s_bEnetPort + i))
      return HOST_INI_MAX_ENET_PORT_ERROR;

    /* Initialise all the counters to ZERO                                    */
    PrIniClrCounter (s_bEnetPort + i);

    while(!(uiMiiPortMap & 0x01))
    {
      uiMiiPortMap = uiMiiPortMap >> 1;
      bPortIndex++;
    }

    /* Default values to the port parameters                                  */
//    tsIniPortParams[s_bEnetPort + i].bPortIndex = 
//      i * (16/ptsPtmfConfig->bIniMaxEnetPort);

    tsIniPortParams[s_bEnetPort + i].bPortIndex = bPortIndex;
      
    // MDIO base address of the PTMF chip of this port
    tsIniPortParams[s_bEnetPort + i].bPtmfBaseAddr = 
      ptsPtmfConfig->bIniMdioAddr;

    // Select RX Enable Mode = 0; i.e. use RX_EN_LINE[0] by default
    tsIniPortParams[s_bEnetPort + i].bRxEnable = 
      i /(ptsPtmfConfig->bIniMaxEnetPort / ptsPtmfConfig->bIniMaxRxEnable);

    // Port Addresses are incremental offset from MDIO base address of the PTMF
    tsIniPortParams[s_bEnetPort + i].bPortAddr = 
      ((ptsPtmfConfig->bIniMdioAddr) & PTMF_MDIO_ADDR_MASK) + i;

    // Default: Utopia PHY address = Global Ethernet Port Number
    //tsIniPortParams[s_bEnetPort + i].bUtopiaPort = s_bEnetPort + i;
    // Utopia PHY starts at zero for each new PTMF Chip.
    tsIniPortParams[s_bEnetPort + i].bUtopiaPort = i;

    tsIniPortParams[s_bEnetPort + i].bFlowControl = 
      ptsPtmfConfig->bFlowControl;
          
    tsIniPortParams[s_bEnetPort + i].bDuplex = 
      ptsPtmfConfig->bDuplex;
    
    tsIniPortParams[s_bEnetPort + i].bPortSpeed = 
      ptsPtmfConfig->bPortSpeed;
    
    tsIniPortParams[s_bEnetPort + i].bPauseFrameSrcAddr = 
      tsIniPortDefault.bPauseFrameSrcAddr;

    tsIniPortParams[s_bEnetPort + i].uiPauseFrameCrc = 
      tsIniPortDefault.uiPauseFrameCrc;

    tsIniPortParams[s_bEnetPort + i].uiResumeFrameCrc = 
      tsIniPortDefault.uiResumeFrameCrc;

    //------------------------------------------------------------------------
    switch (ptsPtmfConfig->bIniMaxEnetPort)
    {
      case 16:
        bFifoSize = FIFO_SIZE_16K;
        bLwm      = FIFO_WATERMARK_4K;
        bHwm      = FIFO_WATERMARK_12K;
        break;

      case 8:
        bFifoSize = FIFO_SIZE_32K;
        bLwm      = FIFO_WATERMARK_8K;
        bHwm      = FIFO_WATERMARK_24K;
        break;

      case 4:
        bFifoSize = FIFO_SIZE_64K;
        bLwm      = FIFO_WATERMARK_16K;
        bHwm      = FIFO_WATERMARK_48K;
        break;

      case 1:       // One port PTMF; BME_CPE_20
        bFifoSize = FIFO_SIZE_16K;
        bLwm      = FIFO_WATERMARK_4K;
        bHwm      = FIFO_WATERMARK_12K;
        break;

      default:
        bFifoSize = FIFO_SIZE_16K;
        bLwm      = FIFO_WATERMARK_4K;
        bHwm      = FIFO_WATERMARK_12K;
        break;
    }
    //------------------------------------------------------------------------
    // FIFO SIZES = 16K * 16/max Enet per PTMF chip
    tsIniPortParams[s_bEnetPort + i].bTxFifoSize = bFifoSize;
    tsIniPortParams[s_bEnetPort + i].bRxFifoSize = bFifoSize;
      
    tsIniPortParams[s_bEnetPort + i].bTxFifoLwm = bLwm;
    tsIniPortParams[s_bEnetPort + i].bTxFifoHwm = bHwm;

    tsIniPortParams[s_bEnetPort + i].bRxFifoHwm = bHwm;
      
    //------------------------------------------------------------------------
    // FIFO size increments on 4K boundary - default
    tsIniPortParams[s_bEnetPort + i].bTxFifoAddr =
      ((i * (16/ptsPtmfConfig->bIniMaxEnetPort)) & 0x03) * 4;

#if !defined(BME_CPE_20)
    // FIFO size increments on 4K boundary - default
    tsIniPortParams[s_bEnetPort + i].bRxFifoAddr =
      (((i * (16/ptsPtmfConfig->bIniMaxEnetPort)) & 0x03) + 4) * 4;
#else
    // FIFO size increments on 4K boundary - default
    tsIniPortParams[s_bEnetPort + i].bRxFifoAddr =
      (((i * (16/ptsPtmfConfig->bIniMaxEnetPort)) & 0x03) + 4) * 1;
#endif
    //------------------------------------------------------------------------
    tsIniPortParams[s_bEnetPort + i].bTxHdlcHcf = 
      tsIniPortDefault.bTxHdlcHcf;

    tsIniPortParams[s_bEnetPort + i].bTxHdlcHaf = 
      tsIniPortDefault.bTxHdlcHaf;

    tsIniPortParams[s_bEnetPort + i].bFilterHdlcCrc = 
      tsIniPortDefault.bFilterHdlcCrc;

    tsIniPortParams[s_bEnetPort + i].bFilterEnetCrc = 
      tsIniPortDefault.bFilterEnetCrc;

    tsIniPortParams[s_bEnetPort + i].bEnetLinkStatus = 
      tsIniPortDefault.bEnetLinkStatus;

    tsIniPortParams[s_bEnetPort + i].bEnetPhyAddr = 
      ptsPtmfConfig->bEnetPhyAddr + i;

    tsIniPortParams[s_bEnetPort + i].bMiiMode = 
      ptsPtmfConfig->bIniMode;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 4)
    printf("\n PTMF PORT = %04x ", s_bEnetPort + i);        

  if (gbDebugLevel <= 3)
    {
//      printf("\n PTMF PORT = %04x ", s_bEnetPort + i);        
      iposPtmfPrintPortStruct(s_bEnetPort + i);
    }
#endif //DEBUG_INI
    bPortIndex++;
    uiMiiPortMap = uiMiiPortMap >> 1;
  }
  // First port index of the next PTMF chip 
  s_bEnetPort = s_bEnetPort + i;

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfInit                               	                  *
*                                                   	                        *
* Purpose... : Initialise the PTM Framer chip, Configure the global modes     *
*									                                                            *
* Parameters : Pointer to global parameter structure                          *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode 
  iposPtmfInit (
    ptsIposPtmfConfig  ptsPtmfConfig)   /* Pointer to global parameter struct */
{
  U16                uiRegValue;

  tsHostIniMdioAddrData tsIniReg;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC INIT ");
#endif //DEBUG_INI

  // Set INI ASIC MDIO base address 
  tsIniReg.bIniBaseAddr = ptsPtmfConfig->bIniMdioAddr;
//  iposPtmfMdioSetBaseAddr ((BYTE)tsIniConfig.uiIniMdioAddr);

  // Global Utopia Enable and Multiple RX Enable mode ON
  uiRegValue = UTOP_ENABLE | RX_ENABLE_MODE;               

  if (ptsPtmfConfig->bUtopiaCellMode == UTOP_CELL_ALL_DATA )
    uiRegValue &= 0xfff9;
  else
    uiRegValue |= 0x0002;

  if (ptsPtmfConfig->bUtopiaTrafficMode == UTOP_TRAFF_NO_IDLE_CELL )
    uiRegValue &= 0xffe7;
  else
    uiRegValue |= 0x0008;

  // Utopia Configuration Regiter0 - Global
  tsIniReg.uiIniRegAddr   = UCR0;
  tsIniReg.uiIniRdWrData  = uiRegValue;
  
  iposPtmfMdioWrite ( &tsIniReg );

  // Utopia HDLC Special Bytes Register 0 - Global
  tsIniReg.uiIniRegAddr   = HSBR0;
  tsIniReg.uiIniRdWrData  = ptsPtmfConfig->bHdlcSpecialBytes;
  
  iposPtmfMdioWrite ( &tsIniReg );

  // Utopia Configuration Regiter 1 - Global
  uiRegValue = ptsPtmfConfig->bAtmCellHecByte;
  uiRegValue <<= 8;
  uiRegValue |= ptsPtmfConfig->bAtmCellNonUnityHeaderByte;

  tsIniReg.uiIniRegAddr   = UCR1;
  tsIniReg.uiIniRdWrData  = uiRegValue;
  
  iposPtmfMdioWrite ( &tsIniReg );

  // Utopia Phys Active Register - Global
  tsIniReg.uiIniRegAddr   = UPAR;
  tsIniReg.uiIniRdWrData  = 0;    // ZERO UTOPIA PHYS ACTIVE ON STARTUP
  iposPtmfMdioWrite ( &tsIniReg);

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStartTx                              	                *
*                                                   	                        *
* Purpose... : Activate an Ethernet ->  UTOPIA Path on the INI ASIC  	        *
*									                                                            *
* Parameters : bEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
eIniRetCode iposPtmfStartTx (U8 bEnetPortNumber, 
                             ptsIposPtmfPortConfig ptsPtmfPortConfig)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiMdioRegValue;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC START TX   #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // SFA 08/08
  // Cause a delay of approx 1 sec before activating the TX path.
 	iposTaskDelay(480);

  if (ptsPtmfPortConfig)
  {
    memcpy (&tsIniPortParams[bEnetPortNumber], 
            ptsPtmfPortConfig,
            sizeof(tsIposPtmfPortConfig));
  }

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // If Base Address is the same as port address than it's the first port of 
  // the chip. OR
  // If port Index = 0;
  if (tsIniPortParams[bEnetPortNumber].bPortIndex ) 
  {
    // Phy Address Set and Enable Phy register
    tsIniReg.uiIniRegAddr   = PHY1_ADD + 
                              tsIniPortParams[bEnetPortNumber].bPortIndex - 1;
    iposPtmfMdioRead ( &tsIniReg);

    if (tsIniReg.uiIniRdWrData & 0x0020)
    {
      //Port is already enabled.....
      tsIniPortParams[bEnetPortNumber].bPortAddr = 
        tsIniReg.uiIniRdWrData & 0x001f;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf ("\n Port Already Enabled!!!");
#endif //DEBUG_INI
    }
    else
    {
      // Enable addressing of the port and give it an address to access the 
      // MDIO registers.
      tsIniReg.uiIniRdWrData  = 
        tsIniPortParams[bEnetPortNumber].bPortAddr | 0x20;

      iposPtmfMdioWrite ( &tsIniReg);
    }
  }
  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  // Tx_Fifo Config register 1
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bTxFifoLwm;
  uiMdioRegValue <<= 7;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bTxFifoHwm;
  uiMdioRegValue <<= 2;
  uiMdioRegValue &= 0xfffc;
  
  tsIniReg.uiIniRegAddr   = TFCR1;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Tx_Fifo Config register 0
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bTxFifoSize;
  uiMdioRegValue <<= 5;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bTxFifoAddr;
  uiMdioRegValue <<= 1;
  uiMdioRegValue |= 0x01;

  tsIniReg.uiIniRegAddr   = TFCR0;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStartRx                               	                *
*                                                   	                        *
* Purpose... : Activate the UTOPIA -> Ethernet Path on the INI ASIC  	        *
*									                                                            *
* Parameters : bEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode iposPtmfStartRx (U8 bEnetPortNumber,
                             ptsIposPtmfPortConfig ptsPtmfPortConfig)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiMdioRegValue;
  U32                     uiPauseCrc;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC START RX #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // SFA 08/08
  PrIniClrCounter (bEnetPortNumber);

  if (ptsPtmfPortConfig)
  {
    memcpy (&tsIniPortParams[bEnetPortNumber], 
            ptsPtmfPortConfig,
            sizeof(tsIposPtmfPortConfig));
  }

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // If Base Address is the same as port address than it's the first port of 
  // the chip. OR
  // If port Index = 0;
  if (tsIniPortParams[bEnetPortNumber].bPortIndex ) 
  {
    // Phy Address Set and Enable Phy register
    tsIniReg.uiIniRegAddr   = PHY1_ADD + 
                              tsIniPortParams[bEnetPortNumber].bPortIndex - 1;
    iposPtmfMdioRead ( &tsIniReg);

    if (tsIniReg.uiIniRdWrData & 0x0020)
    {
      //Port is already enabled.....
      tsIniPortParams[bEnetPortNumber].bPortAddr = 
        tsIniReg.uiIniRdWrData & 0x001f;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf ("\n Port Already Enabled!!!");
#endif //DEBUG_INI
    }
    else
    {
      // Enable addressing of the port and give it an address to access the 
      // MDIO registers.
      tsIniReg.uiIniRdWrData  = 
        tsIniPortParams[bEnetPortNumber].bPortAddr | 0x20;

      iposPtmfMdioWrite ( &tsIniReg);
    }
  }
  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  // Do a software reset to the port. This initialises the port state machine,
  // clears all the port counter and FIFO pointers and sets the port registers
  // to their default values.
  PrIniResetPort (bEnetPortNumber);
  
  // Add the port to the utopia polling sequence
  PrIniUtopiaPollAdd (bEnetPortNumber);

  // PORT ENABLE = 1
  uiMdioRegValue = 0x01;
      
  // PORT SPEED 100/10
  if (tsIniPortParams[bEnetPortNumber].bPortSpeed == PORT_SPEED_100)
    uiMdioRegValue |= 0x02;
  else
    uiMdioRegValue &= 0xfffd;

  // DUPLEX = HALF or FULL
  if (tsIniPortParams[bEnetPortNumber].bDuplex == DUPLEX_HALF)
    uiMdioRegValue |= 0x10;
  else
    uiMdioRegValue &= 0xffef;

  // FLOW CONTROL = NO FLOW  or FULL DUPLEX
  if (tsIniPortParams[bEnetPortNumber].bFlowControl == FLOW_CONTROL_DUPLEX)
    uiMdioRegValue |= 0x04;
  else
    uiMdioRegValue &= 0xfff3;

  if (tsIniPortParams[bEnetPortNumber].bMiiMode & PTMF_XMII_LOOPBACK)
  {
    uiMdioRegValue |= 0x40;   // xMII Loop-back mode : set bit[6] of XPCR reg
  }

  // xMII port configuration reg
  tsIniReg.uiIniRegAddr   = XPCR;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  if (!dropFrameEnable)
  {
/*
    // Suppress HDLC CRC Errors ?
    if (tsIniPortParams[bEnetPortNumber].bFilterHdlcCrc == FILTER_HDLC_CRC )
      uiMdioRegValue = 1;
    else
      uiMdioRegValue = 0;

    // Suppress ENET CRC Errors ?
    if (tsIniPortParams[bEnetPortNumber].bFilterEnetCrc == FILTER_ENET_CRC)
      uiMdioRegValue |= 0x0002;
    else
      uiMdioRegValue &= 0xfffd;
*/
    uiMdioRegValue = 0x0003;
  }
  else
  {
    uiMdioRegValue = 0;
  }

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf ("\n DBGR = %0x",uiMdioRegValue);
#endif //DEBUG_INI

  // Ikanos debug features reg 
  tsIniReg.uiIniRegAddr   = DBGR;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  //47-40 BITS OF SA REG
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bPauseFrameSrcAddr;
  uiMdioRegValue &= 0xff;

  tsIniReg.uiIniRegAddr   = PFSAR;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // PF CRC [15: 0]
  uiPauseCrc = tsIniPortParams[bEnetPortNumber].uiPauseFrameCrc;
  uiPauseCrc &= 0x0000ffff;

  tsIniReg.uiIniRegAddr   = PFCR0;
  tsIniReg.uiIniRdWrData  = uiPauseCrc;
  iposPtmfMdioWrite ( &tsIniReg);

  // PF CRC [31: 16]
  uiPauseCrc = tsIniPortParams[bEnetPortNumber].uiPauseFrameCrc;
  uiPauseCrc >>= 16;
  uiPauseCrc &= 0x0000ffff;

  tsIniReg.uiIniRegAddr   = PFCR1;
  tsIniReg.uiIniRdWrData  = uiPauseCrc;
  iposPtmfMdioWrite ( &tsIniReg);

  // RF CRC [15: 0]
  uiPauseCrc = tsIniPortParams[bEnetPortNumber].uiResumeFrameCrc;
  uiPauseCrc &= 0x0000ffff;
  
  tsIniReg.uiIniRegAddr   = RFCRR0;
  tsIniReg.uiIniRdWrData  = uiPauseCrc;
  iposPtmfMdioWrite ( &tsIniReg);

  // RF CRC [31: 16]
  uiPauseCrc = tsIniPortParams[bEnetPortNumber].uiResumeFrameCrc;
  uiPauseCrc &= 0xffff0000;
  uiPauseCrc >>= 16;

  tsIniReg.uiIniRegAddr   = RFCRR1;
  tsIniReg.uiIniRdWrData  = uiPauseCrc;
  iposPtmfMdioWrite ( &tsIniReg);

  if (tsIniPortParams[bEnetPortNumber].bMiiMode & PTMF_PHY_MAC_MODE )
  {
    // Check for activity on the Enet LINK. Auto-negotiate only in MAC mode
    PrIniEnetPhyAutoNegotiate(bEnetPortNumber);  
  }

  // Rx_Fifo Config register 1
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bRxFifoHwm;
  uiMdioRegValue <<= 2;
  uiMdioRegValue &= 0x1fc;

  tsIniReg.uiIniRegAddr   = RFCR1;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  // Rx_Fifo Config register 0
  uiMdioRegValue = tsIniPortParams[bEnetPortNumber].bRxFifoSize;
  uiMdioRegValue <<= 5;
  uiMdioRegValue |= tsIniPortParams[bEnetPortNumber].bRxFifoAddr;
  uiMdioRegValue <<= 1;
  uiMdioRegValue |= 0x01;

  tsIniReg.uiIniRegAddr   = RFCR0;
  tsIniReg.uiIniRdWrData  = uiMdioRegValue;
  iposPtmfMdioWrite ( &tsIniReg);

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStopTx                               	                *
*                                                   	                        *
* Purpose... : De-activate the Ethernet -> UTOPIA Path on the INI ASIC        *
*									                                                            *
* Parameters : bEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode iposPtmfStopTx (U8 bEnetPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiMdioRegValue;
  U8                      i=4;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC STOP TX   #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  // PORT DISABLE = 0
  // xMII port configuration reg
  tsIniReg.uiIniRegAddr   = XPCR;
  tsIniReg.uiIniRdWrData  = 0;
  iposPtmfMdioWrite ( &tsIniReg);

  // Link is DOWN
  tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_INVALID_LINK;

  while (i)
  {
    // Cause 1/2 seconds delay before stopping Ethernet TX
    iposTaskDelay(240);

    // TX FIFO Write Pointer Reg
    tsIniReg.uiIniRegAddr   = TFRPR;
    iposPtmfMdioRead ( &tsIniReg);
    uiMdioRegValue = tsIniReg.uiIniRdWrData;

    // TX FIFO Read Pointer Reg
    tsIniReg.uiIniRegAddr   = TFWPR;
    iposPtmfMdioRead ( &tsIniReg);

#ifdef DEBUG_INI
    if (gbDebugLevel <= 4)
    {
      printf("\nTX: Read= 0x%x Write= 0x%x ", uiMdioRegValue, 
                                              tsIniReg.uiIniRdWrData);
    }
#endif //DEBUG_INI

    // If TX read and TX write pointers are equal, then FIFO is all drained.
    if (uiMdioRegValue == tsIniReg.uiIniRdWrData)
      break;
    
    i--;
  }

  // Tx_Fifo Config register 0
  tsIniReg.uiIniRegAddr   = TFCR0;
  tsIniReg.uiIniRdWrData  = 0;
  iposPtmfMdioWrite ( &tsIniReg);

  // Cause a delay of 1 sec after disabling the TX FIFO on the INI
 	iposTaskDelay(480);

#ifdef DEBUG_INI
  if (gbDebugLevel <= 4)
  {
    // TX FIFO Write Pointer Reg
    tsIniReg.uiIniRegAddr   = TFRPR;
    iposPtmfMdioRead ( &tsIniReg);
    uiMdioRegValue = tsIniReg.uiIniRdWrData;

    // TX FIFO Read Pointer Reg
    tsIniReg.uiIniRegAddr   = TFWPR;
    iposPtmfMdioRead ( &tsIniReg);

    printf("\nTX: Read= 0x%x Write= 0x%x ", uiMdioRegValue, 
                                            tsIniReg.uiIniRdWrData);
  }
#endif //DEBUG_INI

  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfStopRx                               	                *
*                                                   	                        *
* Purpose... : De-activate the Utopia -> Ethernet Path on the INI ASIC        *
*									                                                            *
* Parameters : uiEnetPortNumber												                        *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode iposPtmfStopRx (U8 bEnetPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiMdioRegValue;

#ifdef TRUE_POLLING
  U8                      i=4;
#endif

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC STOP RX #%d ",bEnetPortNumber );
#endif //DEBUG_INI

  bEnetPortNumber = PrIniMapDsl2Enet(bEnetPortNumber);

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

#ifdef TRUE_POLLING

  while (i)
  {
    // Cause 1/2 seconds delay before stopping Ethernet TX
    iposTaskDelay(240);

    // TX FIFO Write Pointer Reg
    tsIniReg.uiIniRegAddr   = RFRPR;
    iposPtmfMdioRead ( &tsIniReg);
    uiMdioRegValue = tsIniReg.uiIniRdWrData;

    // TX FIFO Read Pointer Reg
    tsIniReg.uiIniRegAddr   = RFWPR;
    iposPtmfMdioRead ( &tsIniReg);

#ifdef DEBUG_INI
    if (gbDebugLevel <= 4)
    {
      printf("\nRX: Read= 0x%x Write= 0x%x ", uiMdioRegValue, 
                                              tsIniReg.uiIniRdWrData);
    }
#endif //DEBUG_INI

    // If TX read and TX write pointers are equal, then FIFO is all drained.
    if (uiMdioRegValue == tsIniReg.uiIniRdWrData)
      break;
    
    i--;
  }
  // Remove the port from the utopia polling sequence
  PrIniUtopiaPollRemove (bEnetPortNumber);

  // Rx_Fifo Config register 0
  tsIniReg.uiIniRegAddr   = RFCR0;
  tsIniReg.uiIniRdWrData  = 0;
  iposPtmfMdioWrite ( &tsIniReg);

#endif //TRUE_POLLING

  // Initialise all the counters to ZERO                                      
  PrIniClrCounter (bEnetPortNumber);


#ifdef DEBUG_INI
  if (gbDebugLevel <= 4)
  {
    // RX FIFO Write Pointer Reg
    tsIniReg.uiIniRegAddr   = RFWPR;
    iposPtmfMdioRead ( &tsIniReg);
    uiMdioRegValue = tsIniReg.uiIniRdWrData;

    // RX FIFO Read Pointer Reg
    tsIniReg.uiIniRegAddr   = RFRPR;
    iposPtmfMdioRead ( &tsIniReg);

    printf("\nRX: Read= 0x%x Write= 0x%x ",uiMdioRegValue, tsIniReg.uiIniRdWrData);
  }
#endif //DEBUG_INI

  return HOST_INI_NO_ERROR;
}



/******************************************************************************
*                                                                             *
* Function.. : iposPtmfReadCounters                          	                *
*                                                   	                        *
* Purpose... : Task                    	                                      *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

void iposPtmfReadCounters(U8 bEnetPortCount)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 1)
    printf("\nRead Counter for port #%d",bEnetPortCount);
#endif //DEBUG_INI

  // Ethernet TX frame counter
  tsIniCounters[bEnetPortCount].uiEnetTxFrameCount += 
    PrIniReadDword (bEnetPortCount, TXFCR0); 

  // Ethernet RX Frame Counter
  tsIniCounters[bEnetPortCount].uiEnetRxFrameCount +=
    PrIniReadDword (bEnetPortCount, RXFCR0); 

  // Ethernet Dropped Frame Counter
  tsIniCounters[bEnetPortCount].uiEnetDropFrameCount +=
    PrIniReadDword (bEnetPortCount, EDFR0); 

  // Octet Transmitted Counter
  tsIniCounters[bEnetPortCount].uiEnetOctXmitCount +=
    PrIniReadDword (bEnetPortCount, OTCR0); 
  
  // Allingment Error Counter
  tsIniCounters[bEnetPortCount].uiAllignErrorCount +=
    PrIniReadDword (bEnetPortCount, AECR0); 

  // Long Frame Counter
  tsIniCounters[bEnetPortCount].uiLongFrameCount +=
    PrIniReadDword (bEnetPortCount, FTLCR0); 
  
  // RX Error Counter
  tsIniCounters[bEnetPortCount].uiRxErrorCount +=
    PrIniReadDword (bEnetPortCount, RECR0); 
  
  // Ethernet CRC Error Counter
  tsIniCounters[bEnetPortCount].uiEnetCrcErrorCount +=
    PrIniReadDword (bEnetPortCount, CECR0); 
  
  // Carrier Sense Errror Counter
  tsIniCounters[bEnetPortCount].uiCarrierSenseErrorCount +=
    PrIniReadDword (bEnetPortCount, CSER0); 
  
  // Broadcast Frame Counter
  tsIniCounters[bEnetPortCount].uiBroadCastFrameCount +=
    PrIniReadDword (bEnetPortCount, BFCR0); 

  // TX pause Frame Counter
  tsIniCounters[bEnetPortCount].uiTxPauseFrameCount += 
    PrIniReadWord (bEnetPortCount, TPFCR); 

  // RX Pause Frame Counter
  tsIniCounters[bEnetPortCount].uiRxPauseFrameCount += 
    PrIniReadWord (bEnetPortCount, PFCTR); 

  // Octet Received Counter
  tsIniCounters[bEnetPortCount].uiEnetOctRcvCount +=
    PrIniReadDword (bEnetPortCount, ORCR0); 

  // RX HDLC Error Frame Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcErrorFrameCount +=
    PrIniReadDword (bEnetPortCount, RHECR0); 
  
  // RX HDLC Invalid Frame Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcInvalidFrameCount +=
    PrIniReadDword (bEnetPortCount, CECR0); 

  // RX HDLC Dropped Frame Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcDropFrameCount +=
    PrIniReadDword (bEnetPortCount, RHDCR0); 

  // HD Late Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdlcCount +=
    PrIniReadDword (bEnetPortCount, HLCCR0); 

  // HD Excess Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdecCount +=
    PrIniReadDword (bEnetPortCount, HECCR0); 

  // HD Single Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdscCount +=
    PrIniReadDword (bEnetPortCount, HSCCR0); 

  // HD Multi-Collision Counter
  tsIniCounters[bEnetPortCount].uiRxHdmcCount +=
    PrIniReadDword (bEnetPortCount, HMCCR0); 

  // HD Def Trans Counter
  tsIniCounters[bEnetPortCount].uiRxHdDefTransCount +=
    PrIniReadDword (bEnetPortCount, HDTCR0); 

  if (tsIniPortParams[bEnetPortCount].bMiiMode & PTMF_PHY_MAC_MODE )
  {
    //---------------------------------------------------------------------
    // Check for activity on the Enet LINK. Auto-negotiate only in MAC mode
    PrIniEnetPhyAutoNegotiate (bEnetPortCount);
    //---------------------------------------------------------------------
  }
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfPrintCounters                        	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
void 
  iposPtmfPrintCounters(U8 bEnetPortNumber)
{
    printf("\n=========== INI Performance Counters for Port #%2d =============",
            bEnetPortNumber + 1);
    
    printf("\n-------------------- ETHERNET RECEIVE -------------------------");

    printf("\n Frames...........: %10lu   Bytes............: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetTxFrameCount,
            tsIniCounters[bEnetPortNumber].uiEnetOctXmitCount );

    printf("\n Pause Frames.....: %10lu   Broadcast Frames.: %10lu", 
            tsIniCounters[bEnetPortNumber].uiTxPauseFrameCount,
            tsIniCounters[bEnetPortNumber].uiBroadCastFrameCount );

    printf("\n Dropped Frames...: %10lu   Alignment Errors.: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetDropFrameCount,
            tsIniCounters[bEnetPortNumber].uiAllignErrorCount );

    printf("\n Oversize.........: %10lu   Undersize........: %10lu", 
            tsIniCounters[bEnetPortNumber].uiLongFrameCount,
            tsIniCounters[bEnetPortNumber].uiRxErrorCount );

    printf("\n CRC Errors.......: %10lu   Carrier Sense Err: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetCrcErrorCount,
            tsIniCounters[bEnetPortNumber].uiCarrierSenseErrorCount );

    printf("\n-------------------- ETHERNET TRANSMIT-------------------------");

    printf("\n Frames...........: %10lu   Bytes............: %10lu", 
            tsIniCounters[bEnetPortNumber].uiEnetRxFrameCount,
            tsIniCounters[bEnetPortNumber].uiEnetOctRcvCount );

    printf("\n Pause Frames.....: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxPauseFrameCount );

    
    printf("\n-------------------- ETHERNET HALF DUPLEX ---------------------");

    printf("\n Late Collisions..: %10lu   Excess Collisions: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcCount,
            tsIniCounters[bEnetPortNumber].uiRxHdecCount );

    printf("\n Single Collisions: %10lu   Multi Collisions.: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdscCount,
            tsIniCounters[bEnetPortNumber].uiRxHdmcCount );

    printf("\n Deferred Trans...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdDefTransCount );
    
    printf("\n------------------------- H.D.L.C.-----------------------------");
    
    printf("\n CRC Errors.......: %10lu   Invalid Frames...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcErrorFrameCount,
            tsIniCounters[bEnetPortNumber].uiRxHdlcInvalidFrameCount );

    printf("\n Dropped Frames...: %10lu",
            tsIniCounters[bEnetPortNumber].uiRxHdlcDropFrameCount );

    printf("\n===============================================================");
   
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfPrintPortStruct                         	              *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : Nothing                                                        *
*                                                                             *
******************************************************************************/
void 
  iposPtmfPrintPortStruct(U8 bEnetPortNumber)
{
  if (bEnetPortNumber >= MAX_ENET_PORTS)
  {
    printf("\nInvalid Port Number \n");  
    return;
  }
  printf("\n tsIniPortParams[%02d] ", bEnetPortNumber);
  printf("\n  |--bPortIndex................0x%02x ",tsIniPortParams[bEnetPortNumber].bPortIndex);
  printf("\n  |--bPtmfBaseAddr.............0x%02x ",tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr);
  printf("\n  |--bRxEnable.................0x%02x ",tsIniPortParams[bEnetPortNumber].bRxEnable);
  printf("\n  |--bPortAddr.................0x%02x ",tsIniPortParams[bEnetPortNumber].bPortAddr);
  printf("\n  |--bUtopiaPort...............0x%02x ",tsIniPortParams[bEnetPortNumber].bUtopiaPort);
  printf("\n  |--bFlowControl..............0x%02x ",tsIniPortParams[bEnetPortNumber].bFlowControl);
  printf("\n  |--bDuplex...................0x%02x ",tsIniPortParams[bEnetPortNumber].bDuplex);
  printf("\n  |--bPortSpeed................0x%02x ",tsIniPortParams[bEnetPortNumber].bPortSpeed);
  printf("\n  |--bPauseFrameSrcAddr........0x%02x ",tsIniPortParams[bEnetPortNumber].bPauseFrameSrcAddr);
  printf("\n  |--uiPauseFrameCrc.....0x%08x ",(unsigned int)tsIniPortParams[bEnetPortNumber].uiPauseFrameCrc);
  printf("\n  |--uiResumeFrameCrc....0x%08x ",(unsigned int)tsIniPortParams[bEnetPortNumber].uiResumeFrameCrc);
  printf("\n  |--bTxFifoSize...............0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoSize);
  printf("\n  |--bTxFifoAddr...............0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoAddr);
  printf("\n  |--bTxFifoLwm................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoLwm);
  printf("\n  |--bTxFifoHwm................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxFifoHwm);
  printf("\n  |--bRxFifoSize...............0x%02x ",tsIniPortParams[bEnetPortNumber].bRxFifoSize);
  printf("\n  |--bRxFifoAddr...............0x%02x ",tsIniPortParams[bEnetPortNumber].bRxFifoAddr);
  printf("\n  |--bRxFifoHwm................0x%02x ",tsIniPortParams[bEnetPortNumber].bRxFifoHwm);
  printf("\n  |--bTxHdlcHcf................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxHdlcHcf);
  printf("\n  |--bTxHdlcHaf................0x%02x ",tsIniPortParams[bEnetPortNumber].bTxHdlcHaf);
  printf("\n  |--bFilterHdlcCrc............0x%02x ",tsIniPortParams[bEnetPortNumber].bFilterHdlcCrc);
  printf("\n  |--bFilterEnetCrc............0x%02x ",tsIniPortParams[bEnetPortNumber].bFilterEnetCrc);
  printf("\n  |--bEnetLinkStatus...........0x%02x ",tsIniPortParams[bEnetPortNumber].bEnetLinkStatus);
  printf("\n  |--bEnetPhyAddr..............0x%02x ",tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);
  printf("\n  `--bMiiMode..................0x%02x \n",tsIniPortParams[bEnetPortNumber].bMiiMode);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxFrames                         	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/

U32 
  iposPtmfEnetRxFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetTxFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxBytes                          	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/

U32 
  iposPtmfEnetRxBytes (U8 bPortNumber) 
{
  return (tsIniCounters[bPortNumber].uiEnetOctXmitCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxPauseFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/

U32 
  iposPtmfEnetRxPauseFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiTxPauseFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxBrdcastFrames                   	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxBrdcastFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiBroadCastFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxDroppedFrames                   	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxDroppedFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetDropFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxAllignErrors                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxAllignErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiAllignErrorCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxOversize                        	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxOversize (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiLongFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxUndersize                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxUndersize (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxErrorCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxCrcErrors                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxCrcErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetCrcErrorCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetRxCarrierSenseErrors              	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetRxCarrierSenseErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiCarrierSenseErrorCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetTxFrames                         	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetTxFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetRxFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetTxBytes                          	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetTxBytes (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiEnetOctRcvCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfEnetTxPauseFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfEnetTxPauseFrames (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxPauseFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDLateCollisions                      	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDLateCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdlcCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDExcessCollisions                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDExcessCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdecCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDSingleCollisions                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDSingleCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdscCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDMultiCollisions                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDMultiCollisions (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdmcCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHDDeferredTrans                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHDDeferredTrans (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdDefTransCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHdlcCrcErrors                        	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHdlcCrcErrors (U8 bPortNumber)
{
  return (tsIniCounters[bPortNumber].uiRxHdlcErrorFrameCount);
}


/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHdlcInvalidFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHdlcInvalidFrames (U8 bPortNumber) 
{
  return (tsIniCounters[bPortNumber].uiRxHdlcInvalidFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposPtmfHdlcDroppedFrames                     	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : 32 bit Count Value                                             *
*                                                                             *
******************************************************************************/
U32 
  iposPtmfHdlcDroppedFrames (U8 bPortNumber) 
{
  return (tsIniCounters[bPortNumber].uiRxHdlcDropFrameCount);
}

/******************************************************************************
*                                                                             *
* Function.. : iposReadEnetPhyStatus                        	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Ethernet PHY MDIO PHY base address of the port                 *
*                                                                             *
* Returns... : 16 bit Ethernet PHY status value                               *
*                                                                             *
******************************************************************************/

U16 iposReadEnetPhyStatus(U8 bEnetPhyMdioAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = bEnetPhyMdioAddr;
  
  // Read the status register from the specified Enet PHY port.
  tsIniReg.uiIniRegAddr = ENET_PHY_STATUS_REG;
  iposMdioRead (&tsIniReg);

  return (tsIniReg.uiIniRdWrData);
}

/******************************************************************************
*                                                                             *
* Function.. : iposReadEnetPhyQuickStatus                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Ethernet PHY MDIO PHY base address of the port                 *
*                                                                             *
* Returns... : 16 bit Ethernet PHY quick status value                         *
*                                                                             *
******************************************************************************/

U16 iposReadEnetPhyQuickStatus(U8 bEnetPhyMdioAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = bEnetPhyMdioAddr;
  
  // Read the status register from the specified Enet PHY port.
  tsIniReg.uiIniRegAddr = ENET_PHY_QUICK_STATUS;
  iposMdioRead (&tsIniReg);

  return (tsIniReg.uiIniRdWrData);
}

/******************************************************************************
*                                                                             *
* Function.. : iposReadEnetPhyLinkAbility                    	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Ethernet PHY MDIO PHY base address of the port                 *
*                                                                             *
* Returns... : 16 bit Ethernet PHY Link Partner ability                       *
*                                                                             *
******************************************************************************/

U16 iposReadEnetPhyLinkAbility(U8 bEnetPhyMdioAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = bEnetPhyMdioAddr;
  
  // Read the status register from the specified Enet PHY port.
  tsIniReg.uiIniRegAddr = ENET_PHY_LINK_ABILITY;
  iposMdioRead (&tsIniReg);

  return (tsIniReg.uiIniRdWrData);

}

/******************************************************************************
*                                                                             *
* Function.. : iposReadEnetPhyLinkPauseCapable               	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Ethernet PHY MDIO PHY base address of the port                 *
*                                                                             *
* Returns... : 16 bit Ethernet PHY Link Partner ability                       *
*                                                                             *
******************************************************************************/

U16 
  iposReadEnetPhyLinkPauseCapable(U8 bEnetPhyMdioAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = bEnetPhyMdioAddr;
  
  // Read the status register from the specified Enet PHY port.
  tsIniReg.uiIniRegAddr = ENET_PHY_PAUSE_STATUS_REG;
  iposMdioRead (&tsIniReg);
 
  if (tsIniReg.uiIniRdWrData & ENET_LINK_PAUSE_CAPABLE)
    return (1);
  else
    return (0);
}

/******************************************************************************
*                                                                             *
* Function.. : iposReadEnetPhyGetSpeed                       	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Ethernet PHY MDIO PHY base address of the port                 *
*                                                                             *
* Returns... : Link Speed (100 or 10)                                         *
*                                                                             *
******************************************************************************/
U16 iposReadEnetPhyGetSpeed(U8 bEnetPhyMdioAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = bEnetPhyMdioAddr;
  
  // Read the status register from the specified Enet PHY port.
  tsIniReg.uiIniRegAddr = ENET_PHY_SPEED_STATUS_REG;
  iposMdioRead (&tsIniReg);

  if (tsIniReg.uiIniRdWrData & ENET_PHY_LINK_SPEED)
    return 100;
  else
    return 10;

}
/******************************************************************************
*                                                                             *
* Function.. : iposReadEnetPhyGetDuplex                      	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : Ethernet PHY MDIO PHY base address of the port                 *
*                                                                             *
* Returns... : Link Speed (100 or 10)                                         *
*                                                                             *
******************************************************************************/
U16 iposReadEnetPhyGetDuplex(U8 bEnetPhyMdioAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = bEnetPhyMdioAddr;
  
  // Read the status register from the specified Enet PHY port.
  tsIniReg.uiIniRegAddr = ENET_PHY_DUPLEX_STATUS_REG;
  iposMdioRead (&tsIniReg);

  if (tsIniReg.uiIniRdWrData & ENET_PHY_LINK_DUPLEX)
    return 1;
  else
    return 0;
}

#ifdef PTMF_DEBUG
/******************************************************************************
*                                                                             *
* Function.. : dbgPtmfGlobalRegs                            	                *
*                                                   	                        *
* Purpose... :                     	                                          *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

U32
  dbgPtmfGlobalRegs (U8 bIniBaseAddr)
{
  U16  uiStartAddr, uiEndAddr, j;
  tsHostIniMdioAddrData tsIniReg;
  U32   uiRetVal = 0;
  
#ifndef BME_CPE_20  
  U16   i;
#endif

  tsIniReg.bIniBaseAddr = bIniBaseAddr;
  tsIniReg.uiIniPhyAddr = bIniBaseAddr;

#if defined(BME_CPE_20)
  printf ("\n-----------------------------------------------------");
  printf ("\n          MDIO INTERFACE REGISTERS ");
  printf ("\n-----------------------------------------------------");

  tsIniReg.uiIniRegAddr = MMDI_WDAT;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      MASTER MDIO WRITE DATA = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  tsIniReg.uiIniRegAddr = MMDI_ADD;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      MASTER MDIO PHY ADDR   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  tsIniReg.uiIniRegAddr = MMDI_RD;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      MASTER MDIO READ OP    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  tsIniReg.uiIniRegAddr = MMDI_OP;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      MASTER MDIO STATUS     = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  tsIniReg.uiIniRegAddr = MMDI_RDAT;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      MASTER MDIO READ DATA  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  tsIniReg.uiIniRegAddr = SMDI_STAT;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      SLAVE MDIO STATUS      = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  tsIniReg.uiIniRegAddr = SMDI_MISC;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      SLAVE MDIO MISC        = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  tsIniReg.uiIniRegAddr = SMDI_CTL;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      SLAVE MDIO CONTROL     = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

#else

  printf ("\n-----------------------------------------------------");
  printf ("\n      BURST MODE ENGINE REGISTERS ");
  printf ("\n-----------------------------------------------------");

  for (i = 0; i < 4; i++)
  {
    j = 0;

    tsIniReg.uiIniRegAddr = BME1_CMD * (i+1);
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d COMMAND REG  = %04x @Addr %03x", 
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr);

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d ADDRESS REG  = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr);

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DATA REG     = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA REG ADDR = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA LENGTH   = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA SRC ADDR = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }
    
    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA DST ADDR = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA DATA     = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA HOST ACK = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA CONTROL  = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr ++;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d DMA STATUS   = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    tsIniReg.uiIniRegAddr = tsIniReg.uiIniRegAddr + 6;

    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      BME # %02d T.S.R        = %04x @Addr %03x",  
             i+1, 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiBmeReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    printf ("\n");
  }
  
  printf ("\n-----------------------------------------------------");
  printf ("\n      PHY ADDRESSS REGISTERS                         ");
  printf ("\n-----------------------------------------------------");
  j = 0;
  for (uiStartAddr = PHY1_ADD; uiStartAddr <= PHY15_ADD; uiStartAddr++)
  {
    tsIniReg.uiIniRegAddr = uiStartAddr;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      PHY # %02d ADDR REG = %04x", 
            (uiStartAddr - PHY1_ADD + 1), 
             tsIniReg.uiIniRdWrData );

    if (tsIniReg.uiIniRdWrData != auiPhyAddrReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

    
  }
#endif

  printf ("\n-----------------------------------------------------");
  printf ("\n      UTOPIA SPECIFIC REGISTERS                      ");
  printf ("\n-----------------------------------------------------");

#if defined(BME_CPE_20)
  uiEndAddr = UPR_0;
#else
  uiEndAddr = UPR_F;
#endif

  j = 0;
  for (uiStartAddr = UPR_0; uiStartAddr <= uiEndAddr; uiStartAddr++)
  {
    tsIniReg.uiIniRegAddr = uiStartAddr;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      UTOPIA POLL REG # %02d   = %04x  @Addr %03x", 
            (uiStartAddr - UPR_0), 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiUtopiaPollReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

  }
  printf ("\n");

#if defined(BME_CPE_20)
  uiEndAddr = UMR_0;
#else
  uiEndAddr = UMR_F;
#endif

  j = 0;
  for (uiStartAddr = UMR_0; uiStartAddr <= uiEndAddr; uiStartAddr++)
  {
    tsIniReg.uiIniRegAddr = uiStartAddr;
    iposPtmfMdioRead ( &tsIniReg );
    printf ("\n      UTOPIA MNTR REG # %02d   = %04x  @Addr %03x", 
            (uiStartAddr - UMR_0), 
             tsIniReg.uiIniRdWrData,
             tsIniReg.uiIniRegAddr );

    if (tsIniReg.uiIniRdWrData != auiUtopiaMonitorReg[j++])
    {
      printf ("*");
      uiRetVal ++;
    }

  }

  printf ("\n");
  tsIniReg.uiIniRegAddr = UPAR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      UTOPIA PHY ACTIVE REG  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != 0)
    {
      printf ("*");
      uiRetVal ++;
    }


  tsIniReg.uiIniRegAddr ++;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      UTOPIA CONFIG REG 0    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != 0)
  {
    printf ("*");
    uiRetVal ++;
  }

  tsIniReg.uiIniRegAddr ++;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      UTOPIA CONFIG REG 1    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != 0)
  {
    printf ("*");
    uiRetVal ++;
  }

  tsIniReg.uiIniRegAddr ++;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      UTOPIA HDLC SPECIAL    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != 0x1e)
  {
    printf ("*");
    uiRetVal ++;
  }

  printf ("\n");
  printf ("\n\n");

  return uiRetVal;
}

/******************************************************************************
*                                                                             *
* Function.. : dbgPtmfPortRegs                           	   	                *
*                                                   	                        *
* Purpose... : Read and display all the  registers of the passed port number  *
*									                                                            *
* Parameters : Port Number and port Address                                   *
*                                                                             *
* Returns... : NONE                                                           *
*                                                                             *
******************************************************************************/
eIniRetCode
  dbgPtmfPortRegs (U8 bIniBaseAddr, U8 bEnetPortNumber)             //, UINT16 uiPortAddress)
{
  tsHostIniMdioAddrData tsIniReg;
  U16                j;
  U32   uiRetVal = 0;

  bEnetPortNumber &= 0x0f;

/*
  if (bEnetPortNumber)
  {
    // Phy Address Set and Enable Phy register
    tsIniReg.uiIniRegAddr   = PHY1_ADD + bEnetPortNumber - 1;
    iposPtmfMdioRead ( &tsIniReg);

    if (tsIniReg.uiIniRdWrData & 0x0020)
    {
      //Port is already enabled.....
      tsIniPortParams[bEnetPortNumber].bPortAddr = 
        tsIniReg.uiIniRdWrData & 0x001f;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf ("\n Port Already Enabled!!!");
#endif //DEBUG_INI
    }
    else
    {
      // Enable addressing of the port and give it an address to access the 
      // MDIO registers.
      tsIniReg.uiIniRdWrData  = 
        tsIniPortParams[bEnetPortNumber].bPortAddr | 0x20;

      iposPtmfMdioWrite ( &tsIniReg);
    }
  }

*/
  // Set the base address in the structure to be passed to the driver 
  // function
//  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;
  tsIniReg.bIniBaseAddr = bIniBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  /****************************************************************************/

  j = 0;

  // xMII port configuration reg
  tsIniReg.uiIniRegAddr = XPCR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      xMII PORT CONFIG REG  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

#if defined(BME_CPE_20)

  // Address Filtering Config register
  tsIniReg.uiIniRegAddr = ACR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      ADDR FILT CONFIG REG  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Address Filtering Static Table Enable register
  tsIniReg.uiIniRegAddr = ASER;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      ADR FILT TABLE EN REG = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

#endif

  // Tx_Fifo Config register 0
  tsIniReg.uiIniRegAddr = TFCR0;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      TX FIFO CONFIG REG 0  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Tx_Fifo Config register 1
  tsIniReg.uiIniRegAddr = TFCR1;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      TX FIFO CONFIG REG 1  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Rx_Fifo Config register 0
  tsIniReg.uiIniRegAddr = RFCR0;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RX FIFO CONFIG REG 0  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Rx_Fifo Config register 1
  tsIniReg.uiIniRegAddr = RFCR1;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RX FIFO CONFIG REG 1  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Clock Gating/SReset config reg
  tsIniReg.uiIniRegAddr = CGRCR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      CLK/RST CONFIG REG    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Ikanos debug features reg
  tsIniReg.uiIniRegAddr = DBGR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      DEBUG CONFIG REG      = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );
  
  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

#if defined(BME_CPE_20)
  // Receive pause frame control register
  tsIniReg.uiIniRegAddr = RXPF;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RX PAUSE CTRL REG     = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );
  
  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }
#endif
 
  /****************************************************************************/
  // Tx HDLC Address/Control Field Register
  tsIniReg.uiIniRegAddr = THAFR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      TX HDLC ADR/CNT REG   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Rx HDLC Address/Control Field Register
  tsIniReg.uiIniRegAddr = RHAFR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RX HDLC ADR/CNT REG   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Min Frame size register
  tsIniReg.uiIniRegAddr = MIFSR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      MIN FRAME SIZE  REG   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Max Frame size register
  tsIniReg.uiIniRegAddr = MAFSR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      MAX FRAME SIZE  REG   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // xMII slot count reg
  tsIniReg.uiIniRegAddr = XSCR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      xMII SLOT COUNT REG   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // [47:40] bits of the SA for P/R F
  tsIniReg.uiIniRegAddr = PFSAR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      47-40 BITS OF SA REG  = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // PF CRC [15: 0]
  tsIniReg.uiIniRegAddr = PFCR0;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      PF CRC LS WORD        = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // PF CRC [31:16]
  tsIniReg.uiIniRegAddr = PFCR1;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      PF CRC MS WORD        = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // RF CRC [15: 0]
  tsIniReg.uiIniRegAddr = RFCRR0;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RF CRC LS WORD        = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // RF CRC [31:16]
  tsIniReg.uiIniRegAddr = RFCRR1;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RF CRC MS WORD        = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );
  
  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

#if defined(BME_CPE_20)
  // Address filtering aging count register
  tsIniReg.uiIniRegAddr = AACR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      ADDR FILT AGING CNT   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );
  
  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }
  
  // Jam sequence length register
  tsIniReg.uiIniRegAddr = JAMC;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      JAM SEQUENCE LENGTH   = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );
  
  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Jam sequence data type register
  tsIniReg.uiIniRegAddr = JAMD;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      JAM SEQUENCE TYPE     = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );
  
  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

#endif


  /****************************************************************************/
  // Pointer/status regs

  // Tx_Fifo Read Pointer Register
  tsIniReg.uiIniRegAddr = TFRPR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      TX FIFO RD POINTER    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Tx_Fifo Write Pointer Register
  tsIniReg.uiIniRegAddr = TFWPR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      TX FIFO WR POINTER    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Rx_Fifo Read Pointer Register
  tsIniReg.uiIniRegAddr = RFRPR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RX FIFO RD POINTER    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Rx_Fifo Write Pointer Register
  tsIniReg.uiIniRegAddr = RFWPR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RX FIFO WR POINTER    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Tx Start Of Frame Pointer Register
  tsIniReg.uiIniRegAddr = TSOFPR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      TX START FRAME PTR    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  // Rx Start Of Frame Pointer Register
  tsIniReg.uiIniRegAddr = RSOFPR;
  iposPtmfMdioRead ( &tsIniReg );
  printf ("\n      RX START FRAME PTR    = %04x  @Addr %03x", 
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

  if (tsIniReg.uiIniRdWrData != auiPtmfPortReg[j++])
  {
    printf ("*");
    uiRetVal ++;
  }

  printf ("\n");

  return uiRetVal;
}

/******************************************************************************
*                                                                             *
* Function.. : dbgPtmfPortCounters                       	   	                *
*                                                   	                        *
* Purpose... : Read and display all the  counters of the passed port number   *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : NONE                                                           *
*                                                                             *
******************************************************************************/
eIniRetCode
  dbgPtmfPortCounters (U8 bEnetPortNumber)             
{
  tsHostIniMdioAddrData tsIniReg;

  bEnetPortNumber &= 0x0f;
/*
  if (bEnetPortNumber)
  {
    // Phy Address Set and Enable Phy register
    tsIniReg.uiIniRegAddr   = PHY1_ADD + bEnetPortNumber - 1;
    iposPtmfMdioRead ( &tsIniReg);

    if (tsIniReg.uiIniRdWrData & 0x0020)
    {
      //Port is already enabled.....
      tsIniPortParams[bEnetPortNumber].bPortAddr = 
        tsIniReg.uiIniRdWrData & 0x001f;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf ("\n Port Already Enabled!!!");
#endif //DEBUG_INI
    }
    else
    {
      // Enable addressing of the port and give it an address to access the 
      // MDIO registers.
      tsIniReg.uiIniRdWrData  = 
        tsIniPortParams[bEnetPortNumber].bPortAddr | 0x20;

      iposPtmfMdioWrite ( &tsIniReg);
    }
  }
*/
  // Set the base address in the structure to be passed to the driver 
  // function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;
  //***************************************************************************
  printf("\n=========== INI Performance Counters for Port #%2d =============",
          bEnetPortNumber + 1);
  
  printf("\n-------------------- ETHERNET RECEIVE -------------------------");

  printf("\n Frames...........: %10lu   Bytes............: %10lu", 
          PrIniReadDword (bEnetPortNumber, TXFCR0),
          PrIniReadDword (bEnetPortNumber, OTCR0));

  printf("\n Pause Frames.....: %10lu   Broadcast Frames.: %10lu", 
          PrIniReadWord (bEnetPortNumber, TPFCR),
          PrIniReadDword (bEnetPortNumber, BFCR0));

  printf("\n Dropped Frames...: %10lu   Alignment Errors.: %10lu", 
          PrIniReadDword (bEnetPortNumber, EDFR0),
          PrIniReadDword (bEnetPortNumber, AECR0));

  printf("\n Oversize.........: %10lu   Undersize........: %10lu", 
          PrIniReadDword (bEnetPortNumber, FTLCR0),
          PrIniReadDword (bEnetPortNumber, RECR0));

  printf("\n CRC Errors.......: %10lu   Carrier Sense Err: %10lu", 
          PrIniReadDword (bEnetPortNumber, CECR0),
          PrIniReadDword (bEnetPortNumber, CSER0));

  printf("\n-------------------- ETHERNET TRANSMIT-------------------------");

  printf("\n Frames...........: %10lu   Bytes............: %10lu", 
          PrIniReadDword (bEnetPortNumber, RXFCR0),
          PrIniReadDword (bEnetPortNumber, ORCR0));

  printf("\n Pause Frames.....: %10lu",
          PrIniReadWord (bEnetPortNumber, PFCTR));
  
  printf("\n-------------------- ETHERNET HALF DUPLEX ---------------------");

  printf("\n Late Collisions..: %10lu   Excess Collisions: %10lu",
          PrIniReadDword (bEnetPortNumber, HLCCR0),
          PrIniReadDword (bEnetPortNumber, HECCR0));

  printf("\n Single Collisions: %10lu   Multi Collisions.: %10lu",
          PrIniReadDword (bEnetPortNumber, HSCCR0),
          PrIniReadDword (bEnetPortNumber, HMCCR0));

  printf("\n Deferred Trans...: %10lu",
          PrIniReadDword (bEnetPortNumber, HDTCR0));
  
  printf("\n------------------------- H.D.L.C.-----------------------------");
  
  printf("\n CRC Errors.......: %10lu   Invalid Frames...: %10lu",
          PrIniReadDword (bEnetPortNumber, RHECR0),
          PrIniReadDword (bEnetPortNumber, CECR0));

  printf("\n Dropped Frames...: %10lu",
          PrIniReadDword (bEnetPortNumber, RHDCR0));

  printf("\n===============================================================\n");

  return HOST_INI_NO_ERROR;
}

#endif // PTMF_DEBUG


/******************************************************************************
*                                                                             *
* Function.. : IniReadDbg                               	   	                *
*                                                   	                        *
******************************************************************************/
void IniReadDbg (U8 bEnetPortNumber, U16 uiRegAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Set the base address in the structure to be passed to the driver 
  // function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;
  tsIniReg.uiIniRegAddr = uiRegAddr;

  iposPtmfMdioRead (&tsIniReg);

  printf (" \n Register value = 0x%x\n", (tsIniReg.uiIniRdWrData));

  return ;
}

/******************************************************************************
*                                                                             *
* Function.. : IniWriteDbg                               	   	                *
*                                                   	                        *
******************************************************************************/
void IniWriteDbg (U8 bEnetPortNumber, U16 uiRegAddr, U16 uiWriteData)
{
  tsHostIniMdioAddrData tsIniReg;

  // Set the base address in the structure to be passed to the driver 
  // function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

  tsIniReg.uiIniRegAddr = uiRegAddr;
  tsIniReg.uiIniRdWrData = uiWriteData;

  iposPtmfMdioWrite (&tsIniReg);

  return ;
}


/******************************************************************************
*                                                                             *
* Function.. : dbgEnetPhyRead                           	   	                *
*                                                   	                        *
******************************************************************************/
void dbgEnetPhyRead (U16 uiEnetPhyAddr, U16 uiRegAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = uiEnetPhyAddr;
  tsIniReg.uiIniRegAddr = uiRegAddr;

  iposMdioRead (&tsIniReg);

  printf (" \n Register value = 0x%x\n", (tsIniReg.uiIniRdWrData));

  return;
}

/******************************************************************************
*                                                                             *
* Function.. : dbgEnetPhyWrite                           	   	                *
*                                                   	                        *
******************************************************************************/
void dbgEnetPhyWrite (U16 uiEnetPhyAddr, U16 uiRegAddr, U16 uiWriteData)
{
  tsHostIniMdioAddrData tsIniReg;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = uiEnetPhyAddr;
  tsIniReg.uiIniRegAddr = uiRegAddr;
  tsIniReg.uiIniRdWrData = uiWriteData;

//  iposMdioWrite (&tsIniReg);

  return ;
}

/******************************************************************************
*                                                                             *
* Function.. : dbgConfigNet                               	   	                *
*                                                   	                        *
******************************************************************************/
void dbgConfigNet (U8 bIniBaseAddr)
{
  tsHostIniMdioAddrData tsIniReg;

  // Set the base address in the structure to be passed to the driver 
  // function
  tsIniReg.bIniBaseAddr = bIniBaseAddr;

  tsIniReg.uiIniRegAddr = UCR0;
  tsIniReg.uiIniRdWrData = 0x01;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = UPR_0;
  tsIniReg.uiIniRdWrData = 0x00;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = UPAR;
  tsIniReg.uiIniRdWrData = 0x01;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = DBGR;
  tsIniReg.uiIniRdWrData = 0x00;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = XPCR;
  tsIniReg.uiIniRdWrData = 0x03;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = XSCR;
  tsIniReg.uiIniRdWrData = 0x0a00;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = MIFSR;
  tsIniReg.uiIniRdWrData = 0x040;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = MAFSR;
  tsIniReg.uiIniRdWrData = 0x0600;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = THAFR;
  tsIniReg.uiIniRdWrData = 0x03ff;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = TFWPR;
  tsIniReg.uiIniRdWrData = 0x0000;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = TFRPR;
  tsIniReg.uiIniRdWrData = 0x0000;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = TFCR1;
  tsIniReg.uiIniRdWrData = 0x1060;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = RFWPR;
  tsIniReg.uiIniRdWrData = 0x0000;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = RFRPR;
  tsIniReg.uiIniRdWrData = 0x0000;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = RFCR1;
  tsIniReg.uiIniRdWrData = 0x0060;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = PFSAR;
  tsIniReg.uiIniRdWrData = 0x0001;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = PFCR0;
  tsIniReg.uiIniRdWrData = 0x9528;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = PFCR1;
  tsIniReg.uiIniRdWrData = 0x4e20;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = RFCRR0;
  tsIniReg.uiIniRdWrData = 0x4309;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = RFCRR1;
  tsIniReg.uiIniRdWrData = 0xd0d0;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = RFCR0;
  tsIniReg.uiIniRdWrData = 0x89;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = TFCR0;
  tsIniReg.uiIniRdWrData = 0x81;
  iposPtmfMdioWrite (&tsIniReg);

  return ;
}



/*------------------------------------------------------------------------------
  PRIVATE FUNCTION DEFINITIONS
  ----------------------------------------------------------------------------*/
/******************************************************************************
*                                                                             *
* Function.. : PrIniEnetPhyAutoNegotiate                     	                *
*                                                   	                        *
* Purpose... : Determine the status of the Enet Link and program the INI ASIC *
*              register with the mode that the PHY auto negotiated            *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : None                                                           *
*                                                                             *
******************************************************************************/
void
  PrIniEnetPhyAutoNegotiate (U8 bEnetPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                  uiTemp;
  U16                  uiPhyStatus;

#ifdef BME_CPE_20
  U8                   bLinkSpeed, bLinkDuplex, bLinkFlowControl;
  U16                  uiMiiSlotCount;
#endif

#ifdef DEBUG_INI
  if (gbDebugLevel <= 0)
    printf("\nINI ASIC ENET PHY AUTO-NEGOTIATION %02x", bEnetPortNumber);
#endif //DEBUG_INI

  // Read the Ethernet PHY Status register.
  uiPhyStatus = iposReadEnetPhyStatus(
                  tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);

#ifdef DEBUG_INI
  if (gbDebugLevel <= 2)
    printf(" PHY STATUS = %x ", uiPhyStatus);
#endif //DEBUG_INI

  // Is Link UP ?
  if ((uiTemp = (uiPhyStatus & ENET_VALID_LINK)))
  {
    // If Link is UP, then check if the link status has changed from the 
    // last time.
    if (uiTemp != tsIniPortParams[bEnetPortNumber].bEnetLinkStatus)
    {
      // Check if the PHY is capable of auto-negotiation
      if (uiPhyStatus & ENET_AUTONEGO_CAPABLE)
      {
        // Check if Auto-negotiation process is OVER
        if (uiPhyStatus & ENET_AUTO_NEGOTIATE_OVER)
        {
#if defined(BME_CPE_20)
          bLinkSpeed = iposReadEnetPhyGetSpeed(
                          tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);
          bLinkDuplex = iposReadEnetPhyGetDuplex(
                          tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);
          bLinkFlowControl =  iposReadEnetPhyLinkPauseCapable(
                                tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);

          // Set the base address in the structure to be passed to the driver 
          // function
          tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

          // Ethernet Port address set for access to the port specific MDIO 
          // registers.
          tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

          // xMII port configuration reg
          tsIniReg.uiIniRegAddr   = XPCR;
          iposPtmfMdioRead ( &tsIniReg);

          if (bLinkSpeed == 100)
          {
            // Link Speed = 100 Mbps
            tsIniReg.uiIniRdWrData |= 0x02;
            uiMiiSlotCount = 0x2cc;

          }
          else
          {
            // Link Speed = 10 Mbps
            tsIniReg.uiIniRdWrData &= 0xfffd;
            uiMiiSlotCount = 0x1c00;

          }

          if (bLinkDuplex)
          {
            // FULL DUPLEX
            tsIniReg.uiIniRdWrData &= 0xffef;
            // PAUSE CAPABLE OR NOT
            if (bLinkFlowControl)
            {
              // Remote End Flow Capable; 
              // Check if Flow Control Enable at modem?
              if (tsIniPortParams[bEnetPortNumber].bFlowControl)
              {
                //Port start with Full duplex Pause/Resume frame generation ON
                tsIniReg.uiIniRdWrData &= 0xfff3;
                tsIniReg.uiIniRdWrData |= 0x0004;
              }
              else
              {
                // No Flow Control
                tsIniReg.uiIniRdWrData &= 0xfff3;
              }
            }
            else
            {
              // No Flow Control
              tsIniReg.uiIniRdWrData &= 0xfff3;
            }
          }
          else
          {
            // HALF DUPLEX
            tsIniReg.uiIniRdWrData |= 0x10;

            // Check if Half Duplex Flow Control Enable at modem?
            if (tsIniPortParams[bEnetPortNumber].bFlowControl)
            {
              if (bLinkFlowControl)
              {
                //Port start with HALF Duplex Flow Control ON
                tsIniReg.uiIniRdWrData &= 0xfff3;
                tsIniReg.uiIniRdWrData |= 0x0008;
                printf ("\n HALF DUPLEX FLOW CONTROL ON \n");
              }
              else
              {              
                // No Flow Control
                tsIniReg.uiIniRdWrData &= 0xfff3;
              }
            }
            else
            {
              // No Flow Control
              tsIniReg.uiIniRdWrData &= 0xfff3;
            }
          }


#ifdef DEBUG_INI
          if (gbDebugLevel <= 5)
            printf("[[[[ XPCR = %x ]]]]", tsIniReg.uiIniRdWrData );
#endif //DEBUG_INI
          
          // xMII port configuration reg
          tsIniReg.uiIniRegAddr   = XPCR;
          iposPtmfMdioWrite ( &tsIniReg);

          // xMII Slot count register used for Half Duplex Flow control.
          tsIniReg.uiIniRegAddr   = XSCR;
          tsIniReg.uiIniRdWrData  = uiMiiSlotCount;
          iposPtmfMdioWrite ( &tsIniReg);

#else
          // Read the Ethernet PHY Status register.
          uiTemp = iposReadEnetPhyQuickStatus(
                      tsIniPortParams[bEnetPortNumber].bEnetPhyAddr);

#ifdef DEBUG_INI
          if (gbDebugLevel <= 2)
            printf(" PHY QUICK STATUS = %x ", uiTemp );
#endif //DEBUG_INI

          // Set the base address in the structure to be passed to the driver 
          // function
          tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

          // Ethernet Port address set for access to the port specific MDIO 
          // registers.
          tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

          // xMII port configuration reg
          tsIniReg.uiIniRegAddr   = XPCR;
          iposPtmfMdioRead ( &tsIniReg);

          // PORT SPEED 100/10
          if (uiTemp & PHY_PORT_SPEED)
            tsIniReg.uiIniRdWrData |= 0x02;
          else
            tsIniReg.uiIniRdWrData &= 0xfffd;

          // DUPLEX = HALF or FULL
          if (uiTemp & PHY_PORT_DUPLEX)
            tsIniReg.uiIniRdWrData &= 0xffef;
          else
            tsIniReg.uiIniRdWrData |= 0x10;

          // PAUSE CAPABLE OR NOT
          if (iposReadEnetPhyLinkPauseCapable(
                tsIniPortParams[bEnetPortNumber].bEnetPhyAddr))
          {
            if (tsIniPortParams[bEnetPortNumber].bFlowControl)
              tsIniReg.uiIniRdWrData |= 0x0004;
            else
              tsIniReg.uiIniRdWrData &= 0xfff3;
          }
          else
            tsIniReg.uiIniRdWrData &= 0xfff3;

  #ifdef DEBUG_INI
          if (gbDebugLevel <= 4)
          {
            printf("XPCR = %x", tsIniReg.uiIniRdWrData );
          }
  #endif //DEBUG_INI
          
          // xMII port configuration reg
          tsIniReg.uiIniRegAddr   = XPCR;
          iposPtmfMdioWrite ( &tsIniReg);
#endif

        }
        else
          return;
      }
      // Link is NOW UP
      tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_VALID_LINK;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 5)
        printf("\n ENET PORT %02d LINK UP:\n ", bEnetPortNumber + 1);
#endif //DEBUG_INI
    }
  }
  else
  {
    // If Link is DOWN, then check if the link status has changed from the 
    // last time.
    if (uiTemp != tsIniPortParams[bEnetPortNumber].bEnetLinkStatus)
    {
      // Link is DOWN
      tsIniPortParams[bEnetPortNumber].bEnetLinkStatus = ENET_INVALID_LINK;

#ifdef DEBUG_INI
      if (gbDebugLevel <= 5)
        printf("\n ENET PORT %02d LINK DOWN:\n", bEnetPortNumber + 1);
#endif //DEBUG_INI

#if defined(BME_CPE_20)

     // Set the base address in the structure to be passed to the driver 
      // function
      tsIniReg.bIniBaseAddr = tsIniPortParams[bEnetPortNumber].bPtmfBaseAddr;

      // Ethernet Port address set for access to the port specific MDIO 
      // registers.
      tsIniReg.uiIniPhyAddr = tsIniPortParams[bEnetPortNumber].bPortAddr;

      // xMII port configuration reg
      tsIniReg.uiIniRegAddr   = XPCR;
      iposPtmfMdioRead ( &tsIniReg);

      // No Flow Control
      tsIniReg.uiIniRdWrData &= 0xfff3;
      iposPtmfMdioWrite ( &tsIniReg);
#endif
    }
  }
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniClrCounter                              	                *
*                                                   	                        *
* Purpose... : Clears all the performance counter variables for a particular  *
*              port                                                           *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : None                                                           *
*                                                                             *
******************************************************************************/
void
  PrIniClrCounter ( U8 bPortNumber)
{
  /* Initialise all the counters to ZERO                                    */
  tsIniCounters[bPortNumber].uiEnetTxFrameCount       = 0;
  tsIniCounters[bPortNumber].uiEnetOctXmitCount       = 0;
  tsIniCounters[bPortNumber].uiEnetDropFrameCount     = 0;
  tsIniCounters[bPortNumber].uiAllignErrorCount       = 0;
  tsIniCounters[bPortNumber].uiLongFrameCount         = 0;
  tsIniCounters[bPortNumber].uiRxErrorCount           = 0;
  tsIniCounters[bPortNumber].uiEnetCrcErrorCount      = 0;
  tsIniCounters[bPortNumber].uiCarrierSenseErrorCount = 0;
  tsIniCounters[bPortNumber].uiBroadCastFrameCount    = 0;
  tsIniCounters[bPortNumber].uiTxPauseFrameCount      = 0;
  tsIniCounters[bPortNumber].uiEnetRxFrameCount       = 0;
  tsIniCounters[bPortNumber].uiEnetOctRcvCount        = 0;
  tsIniCounters[bPortNumber].uiRxHdlcErrorFrameCount  = 0;
  tsIniCounters[bPortNumber].uiRxHdlcInvalidFrameCount= 0;
  tsIniCounters[bPortNumber].uiRxPauseFrameCount      = 0;
  tsIniCounters[bPortNumber].uiRxHdlcDropFrameCount   = 0;
  tsIniCounters[bPortNumber].uiRxHdlcCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdecCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdscCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdmcCount            = 0;
  tsIniCounters[bPortNumber].uiRxHdDefTransCount      = 0;
}
/******************************************************************************
*                                                                             *
* Function.. : PrIniReadWord                                	                *
*                                                   	                        *
* Purpose... : Performs MDIO reads of 1 16-bit registers and returns the      *
*              value                                                          * 
*									                                                            *
* Parameters : Port Number and register address                               *
*                                                                             *
* Returns... : 32-bit unsigned integer                                        *
*                                                                             *
******************************************************************************/
U32
  PrIniReadWord (U8 bPortNumber, U16 uiRegAddr)
{
  tsHostIniMdioAddrData   tsIniReg;

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

  // Read the addressed MDIO register from the specified port.
  tsIniReg.uiIniRegAddr = uiRegAddr ; 
  iposPtmfMdioRead (&tsIniReg);

  return (tsIniReg.uiIniRdWrData);
}
/******************************************************************************
*                                                                             *
* Function.. : PrIniReadDword                             	                  *
*                                                   	                        *
* Purpose... : Performs MDIO reads of 2 16-bit registers and returns a 32     *
*              bit value                                                      * 
*									                                                            *
* Parameters : Port Number and register address                               *
*                                                                             *
* Returns... : 32-bit unsigned integer                                        *
*                                                                             *
******************************************************************************/
U32
  PrIniReadDword ( U8 bPortNumber, U16 uiRegAddr)
{
  tsHostIniMdioAddrData   tsIniReg;
  U32                  uiCountX, uiCountTemp;

  // Set the base address in the structure to be passed to the driver function
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

  // First read the LSW of the double word counter
  tsIniReg.uiIniRegAddr = uiRegAddr ; 
  iposPtmfMdioRead (&tsIniReg);
  uiCountX = tsIniReg.uiIniRdWrData;

  // Read the MSW of the double word counter
  tsIniReg.uiIniRegAddr = uiRegAddr + 1; 
  iposPtmfMdioRead (&tsIniReg);

  uiCountTemp = tsIniReg.uiIniRdWrData;
  uiCountTemp <<= 16;
  uiCountX |= uiCountTemp;

  return uiCountX;
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniUtopiaPollAdd                           	                *
*                                                   	                        *
* Purpose... : Adds an Utopia Phy address to the polling sequence             *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/

eIniRetCode
  PrIniUtopiaPollAdd (U8 bPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiUtopiaPollReg;
  U8                      bPhyCount;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC ADD UTOPIA PHY TO POLLING %02x", bPortNumber);
#endif //DEBUG_INI

  // Set the base address 
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  uiUtopiaPollReg = tsIniPortParams[bPortNumber].bPortIndex & 0x0f;
  uiUtopiaPollReg <<= 6;
  uiUtopiaPollReg |= tsIniPortParams[bPortNumber].bUtopiaPort;
  uiUtopiaPollReg |= (tsIniPortParams[bPortNumber].bRxEnable << 10);

  tsIniReg.uiIniRegAddr = UPAR;
  iposPtmfMdioRead (&tsIniReg);
  bPhyCount = (U8)tsIniReg.uiIniRdWrData;
//  bPhyCount &= 0x0f;

  tsIniReg.uiIniRegAddr = UPR_0;

  while (bPhyCount)
  {
    iposPtmfMdioRead (&tsIniReg);

#ifdef DEBUG_INI
  if (gbDebugLevel <= 1)
    printf("\nADDR= %03x, DATA= %04x, CMP= %04x ",tsIniReg.uiIniRegAddr, 
                                                  tsIniReg.uiIniRdWrData,
                                                  uiUtopiaPollReg );
#endif //DEBUG_INI

    if (uiUtopiaPollReg == tsIniReg.uiIniRdWrData)
    {
#ifdef DEBUG_INI
      if (gbDebugLevel <= 1)
        printf("\nFOUND AT %03x",tsIniReg.uiIniRegAddr );
#endif //DEBUG_INI
      return HOST_INI_NO_ERROR;
    }
    
    tsIniReg.uiIniRegAddr ++;
    bPhyCount--;
  }

  if (tsIniReg.uiIniRegAddr > UPR_F)
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 3)
      printf("\nPOLL FULL!!");
#endif //DEBUG_INI

    return HOST_INI_UNDEFINED_ERROR;
  }
//  tsIniReg.uiIniRdWrData = (tsIniPortParams[bPortNumber].bRxEnable << 10);
  tsIniReg.uiIniRdWrData = uiUtopiaPollReg;
  iposPtmfMdioWrite (&tsIniReg);

#ifdef DEBUG_INI
  if (gbDebugLevel <= 1)
    printf("\nADDR= %03x, DATA= %04x",tsIniReg.uiIniRegAddr, uiUtopiaPollReg );
#endif //DEBUG_INI

  tsIniReg.uiIniRegAddr = UPAR;
  iposPtmfMdioRead (&tsIniReg);

  tsIniReg.uiIniRdWrData ++;

  iposPtmfMdioWrite (&tsIniReg);
  
  return HOST_INI_NO_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniUtopiaPollRemove                        	                *
*                                                   	                        *
* Purpose... : Removes an Utopia Phy address from the polling sequence        *
*									                                                            *
* Parameters : Port Number                                                    *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
eIniRetCode
  PrIniUtopiaPollRemove (U8 bPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;
  U16                     uiUtopiaPollReg, i;
  U16                     uiUtopiaPhy;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC REMOVE UTOPIA PHY FROM POLLING %02x", bPortNumber);
#endif //DEBUG_INI

  // Set the base address 
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;

  // Determine the number of PHYs being polled by the master i.e INI ASIC
  tsIniReg.uiIniRegAddr = UPAR;
  iposPtmfMdioRead (&tsIniReg);
  uiUtopiaPhy = tsIniReg.uiIniRdWrData;
  if (uiUtopiaPhy == 0)
  {
#ifdef DEBUG_INI
    if (gbDebugLevel <= 4)
      printf("\nNO PHY TO REMOVE FROM POLLING ");
#endif //DEBUG_INI
    return HOST_INI_UNDEFINED_ERROR;
  }

  uiUtopiaPhy &= 0x0f;
  uiUtopiaPhy = uiUtopiaPhy - 1;

  for (i = UPR_0; i <= UPR_F; i++, uiUtopiaPhy-- )
  {
    // Read the Utopia poll register and find out the xMII port number
    tsIniReg.uiIniRegAddr = i;
    iposPtmfMdioRead (&tsIniReg);

    uiUtopiaPollReg = tsIniReg.uiIniRdWrData;
    uiUtopiaPollReg >>= 6;
    uiUtopiaPollReg  &= 0x0f;
    
    // Check if this is to be removed from Utopia polling sequence
    if (uiUtopiaPollReg == bPortNumber)
    {
      while (uiUtopiaPhy)
      {
        // Read from i+1 and write to i
        tsIniReg.uiIniRegAddr = i+1;
        iposPtmfMdioRead (&tsIniReg);

        tsIniReg.uiIniRegAddr = i;
        iposPtmfMdioWrite (&tsIniReg);

        // Step to next Utopia Poll register
        i++;
        
        // 
        uiUtopiaPhy --;
      }
      // Last but not the least decrement the No. of Phys to poll by one.
      tsIniReg.uiIniRegAddr = UPAR;
      iposPtmfMdioRead (&tsIniReg);

      tsIniReg.uiIniRdWrData --;
      iposPtmfMdioWrite (&tsIniReg);

      // Return success
      return HOST_INI_NO_ERROR;
    }
    else if (!uiUtopiaPhy)
      break;
  }
  // If you ever get out of the for loop, TROUBLE!!!!
  return HOST_INI_UNDEFINED_ERROR;
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniMapDsl2Enet                           	                  *
*                                                   	                        *
* Purpose... :                         	                                      *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
U32 
  PrIniMapDsl2Enet ( U8 bPortNumber)
{

#ifdef DEBUG_INI
  if (gbDebugLevel <= 0)
    printf("\nINI ASIC MAP DSL LINE TO ENET PORT %02x", bPortNumber);
#endif //DEBUG_INI
  if (bPortNumber == 0 || bPortNumber > MAX_ENET_PORTS )
  {
    printf("\nERROR: WRONG INI PORT NUMBER %02x", bPortNumber);
    return 0;
  }
  return (bPortNumber-1);
}

/******************************************************************************
*                                                                             *
* Function.. : PrIniResetPort                           	                    *
*                                                   	                        *
* Purpose... :                         	                                      *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
void 
  PrIniResetPort (U8 bPortNumber)
{
  tsHostIniMdioAddrData   tsIniReg;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC RESET PORT %02x", bPortNumber);
#endif //DEBUG_INI

  // Ethernet Port address set for access to the port specific MDIO registers.
  tsIniReg.bIniBaseAddr = tsIniPortParams[bPortNumber].bPtmfBaseAddr;
  tsIniReg.uiIniPhyAddr = tsIniPortParams[bPortNumber].bPortAddr;

  tsIniReg.uiIniRegAddr = CGRCR;
  iposPtmfMdioRead (&tsIniReg);

  tsIniReg.uiIniRdWrData |= SOFT_RESET;
  tsIniReg.uiIniRdWrData &= ~PSOFT_RESET;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRdWrData |= PSOFT_RESET;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRdWrData &= ~SOFT_RESET;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRdWrData &= ~PSOFT_RESET;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRdWrData |= PSOFT_RESET;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRdWrData |= SOFT_RESET;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRdWrData &= ~PSOFT_RESET;
  iposPtmfMdioWrite (&tsIniReg);

}

/******************************************************************************
*                                                                             *
* Function.. : PrIniSetClock                            	                    *
*                                                   	                        *
* Purpose... :                         	                                      *
*									                                                            *
* Parameters : N/A                                                            *
*                                                                             *
* Returns... : N/A                                                            *
*                                                                             *
******************************************************************************/
void 
  PrIniSetClock (U8 bPtmfBaseAddr)
{
  tsHostIniMdioAddrData   tsIniReg;

#ifdef DEBUG_INI
  if (gbDebugLevel <= 3)
    printf("\nINI ASIC SET CLOCK " );
#endif //DEBUG_INI

  tsIniReg.bIniBaseAddr = bPtmfBaseAddr;
  tsIniReg.uiIniRegAddr = CLK_PLLNM;
  tsIniReg.uiIniRdWrData = 0xcc;
  iposPtmfMdioWrite (&tsIniReg);

  tsIniReg.uiIniRegAddr = PLL_TEST;
  tsIniReg.uiIniRdWrData = 0x313;
  iposPtmfMdioWrite (&tsIniReg);

}

/*------------------------------------------------------------------------------
                                 END OF FILE
------------------------------------------------------------------------------*/
