/******************************************************************************/
/*                                                                            */
/*         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:    HostPtmfDbg.c
**
**  Project:     
**
**  Target:      MOTOROLA XPC855T based host board
**
**  Platform specific:
**    None.
**
**  Description:
**
**  $Revision: 1.2 $
**  $Date: 2006/12/12 10:53:07 $
**
**
**  **************************************************************************** 
**  Public Functions:
**
**  **************************************************************************** 
**  Private Functions:
**
**  **************************************************************************** 
**  Modification History:
**
**    Date         By     Description
**    -----------  ---    ------------------------------------------------------
**	  Nov-19-2002  SFA    Created
*/
/******************************************************************************/
/*------------------------------------------------------------------------------
  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
/*------------------------------------------------------------------------------
  PRIVATE ENUMERATION DEFINITIONS
  ----------------------------------------------------------------------------*/

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

/*------------------------------------------------------------------------------
  PUBLIC VARIABLES DEFINITIONS
  ----------------------------------------------------------------------------*/
extern tsIposPtmfPortConfig    tsIniPortParams[MAX_ENET_PORTS];

#ifdef ALASKA
extern int openFIFOs(void);
extern int readFromVdsl(char *buffer);
extern int writeToVdsl(char *buffer);
#endif

#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 //BME_CPE_20

#if !defined(CPE_30)

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
};

#endif //#if !defined(CPE_30)

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
  ----------------------------------------------------------------------------*/
static void dbgIniMenuHelp(void);
static void dbgIniSkipSpace(U8 **pabCommandString);

U32 dbgIniGetValue(U8 **pabCommandString);
/*------------------------------------------------------------------------------
  PUBLIC FUNCTION DEFINITIONS
  ----------------------------------------------------------------------------*/

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

U32
  dbgPtmfGlobalRegs (U8 bIniBaseAddr)
{
#if !defined(CPE_30) 
  U16  uiStartAddr, uiEndAddr, j;
#endif

  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

#if !defined(CPE_30)
  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 ++;
  }

#endif //#if !defined(CPE_30)

  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 = PFSARLO;
  iposPtmfMdioRead1 ( &tsIniReg );
  printf ("\n      47-40 BITS OF SA REG  = %08x  @Addr %03x",
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

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

  // PF CRC [31: 0]
  tsIniReg.uiIniRegAddr = PFCRCQ0;
  iposPtmfMdioRead1 ( &tsIniReg );
  printf ("\n      PF CRC Q0 WORD        = %08x  @Addr %03x",
           tsIniReg.uiIniRdWrData,
           tsIniReg.uiIniRegAddr );

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

  // RF CRC [31: 0]
  tsIniReg.uiIniRegAddr = RFCRCQ0;
  iposPtmfMdioRead1 ( &tsIniReg );
  printf ("\n      RF CRC Q0 WORD        = %08x  @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


  printf ("\n");

  return uiRetVal;
}

/******************************************************************************
*                                                                             *
* Function.. : dbgIniRead                               	   	                *
*                                                   	                        *
******************************************************************************/
void dbgIniRead (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.. : dbgIniWrite                               	   	                *
*                                                   	                        *
******************************************************************************/
void dbgIniWrite (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;

#if !defined(CPE_30)

  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);

#endif //#if !defined(CPE_30)

  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 ;
}*/

/******************************************************************************
*                                                                             *
* Function.. : dbgMdioRegs                               	   	                *
*                                                   	                        *
******************************************************************************/
void dbgMdioRegs(U8 bEnetPortNumber)
{
  U8    bIndex;
  U16   uiRegData;

  for (bIndex =0; bIndex <32; bIndex++)
  {
    iposMdioRegRead(bEnetPortNumber, bIndex, &uiRegData);
    printf("\n %02d = 0x%04X ", bIndex, uiRegData);
  }
}

/******************************************************************************
*                                                                             *
* Function.. : dbgPtmfGetVerString                       	   	                *
*                                                   	                        *
******************************************************************************/
void dbgPtmfGetVerString(void)
{
  U8 abVerString[100];

  iposPtmfGetVersion(abVerString);
  printf ("\n %s", abVerString);
}

/******************************************************************************
*                                                                             *
* Function.. : dbgPtmfGetVerNumber                       	   	                *
*                                                   	                        *
******************************************************************************/
void dbgPtmfGetVerNumber(void)
{
  U8    bType, bVerNo;
  U16   uiPartNo;

  iposPtmfGetVersionNumber(&bType, &uiPartNo, &bVerNo);

  printf("\n Enet Interface Type    = %d", bType);
  printf("\n Enet Interface Part    = %d", uiPartNo);
  printf("\n Enet Interface Version = %d", bVerNo);
}


void dbgIniMenu (void)
{
  U8    abMenuCommand[100];
  U32   uiCommand, uiArg1, uiArg2, uiArg3;
  U8    *pCommand, bExitFlag = 0;

#ifdef ALASKA
  openFIFOs();
#endif

  dbgIniMenuHelp();
  
#ifdef ALASKA
    sprintf(abMenuCommand, "CONTINUE");
    if(writeToVdsl((char *)&abMenuCommand) == -1)
	return;
#endif
  while(1)
  {

    printf("\nEnter Selection > ");

#ifdef ALASKA
    fflush(stdout);
    if( readFromVdsl((char *)&abMenuCommand) == -1)
	break;
#else
    gets (abMenuCommand);
#endif

//    printf ("%x = %s ", &abMenuCommand, abMenuCommand);
    
    pCommand = abMenuCommand;

//    printf(" ++ %x-%x ++", pCommand, &pCommand);
    dbgIniSkipSpace(&pCommand);
//    printf("%x ", pCommand);
    uiCommand = dbgIniGetValue(&pCommand);
    switch ((U8)uiCommand)
    {
      case 1:
        uiArg1 = dbgIniGetValue(&pCommand);
        dbgPtmfGlobalRegs (uiArg1);
        break;

      case 2:
        uiArg1 = dbgIniGetValue(&pCommand);
        uiArg2 = dbgIniGetValue(&pCommand);
        dbgPtmfPortRegs (uiArg1, uiArg2);
        break;

      case 3:
        uiArg1 = dbgIniGetValue(&pCommand);
        uiArg2 = dbgIniGetValue(&pCommand);
        dbgIniRead (uiArg1, uiArg2);
        break;

      case 4:
        uiArg1 = dbgIniGetValue(&pCommand);
        uiArg2 = dbgIniGetValue(&pCommand);
        uiArg3 = dbgIniGetValue(&pCommand);
        dbgIniWrite (uiArg1, uiArg2, uiArg3);
        break;

      case 5:
        uiArg1 = dbgIniGetValue(&pCommand);
        uiArg2 = dbgIniGetValue(&pCommand);
        dbgEnetPhyRead (uiArg1, uiArg2);
        break;

      case 6:
        uiArg1 = dbgIniGetValue(&pCommand);
        uiArg2 = dbgIniGetValue(&pCommand);
        uiArg3 = dbgIniGetValue(&pCommand);
        dbgEnetPhyWrite (uiArg1, uiArg2, uiArg3);
        break;
        
      case 7:
        uiArg1 = dbgIniGetValue(&pCommand);
        dbgMdioRegs(uiArg1);
        break;

      case 8:
        dbgPtmfGetVerString();
        break;

      case 9:
        dbgPtmfGetVerNumber();
        break;

      case 10:
        uiArg1 = dbgIniGetValue(&pCommand);
        iposPtmfDbgLevelSet(uiArg1);
        break;

      case 11:
        uiArg1 = dbgIniGetValue(&pCommand);
        dbgPtmfPortCounters (uiArg1);
        break;

      case 12:
        uiArg1 = dbgIniGetValue(&pCommand);
        iposPtmfPrintPortStruct (uiArg1);
        break;

      case 20:
        iposPtmfSetup (0);
        break;

      case 21:
        uiArg1 = dbgIniGetValue(&pCommand);
        iposPtmfStartRx (++uiArg1,0);
        break;

      case 22:
        uiArg1 = dbgIniGetValue(&pCommand);
        iposPtmfStartTx (++uiArg1,0);
        break;

      case 23:
        uiArg1 = dbgIniGetValue(&pCommand);
        iposPtmfStopTx (++uiArg1);
        break;

      case 24:
        uiArg1 = dbgIniGetValue(&pCommand);
        iposPtmfStopRx (++uiArg1);
        break;


      case 99:
        bExitFlag = 1;
        break;

      default:
//        printf ("\n Unknown Command !!!!");
        dbgIniMenuHelp();
        break;
    }
#ifndef ALASKA
    if (bExitFlag)
      break;
#else
    if (bExitFlag)
    {
	sprintf(abMenuCommand, "END");
	writeToVdsl((char *)&abMenuCommand);
	break;
    }
    sprintf(abMenuCommand, "CONTINUE");
    if(writeToVdsl((char *)&abMenuCommand) == -1)
        break;
#endif
  }
}

static void dbgIniMenuHelp()
{
  printf ("\n -------------------------------------------------------");
  printf ("\n Ethernet Interface Debug\n");
  printf ("\n ===================================================================");
  printf ("\n Command  Arg1      Arg2      Arg1      Description ");
  printf ("\n ===================================================================");
  printf ("\n    1     BaseAddr                      Dump All Global Registers ");
  printf ("\n    2     BaseAddr  PortNum             Dump All Port Registers ");
  printf ("\n    3     PortNum   RegAddr             Read INI Register ");
  printf ("\n    4     PortNum   RegAddr   RegData   Write INI Register ");
  printf ("\n    5     PhyAddr   RegNum              Read Enet PHY Register ");
  printf ("\n    6     PhyAddr   RegNum    RegData   Write Enet PHY Register ");
  printf ("\n    7     PortNum                       Dump All Enet PHY Registers ");
  printf ("\n    8                                   INI Version String ");
  printf ("\n    9                                   INI Version Number ");
  printf ("\n   10     Level                         Set Debug Display Level ");
  printf ("\n   11     PortNum                       Dump All Counter Registers ");
  printf ("\n   12     PortNum                       Print Port Structure ");
  
  printf ("\n   20                                   iposPtmfSetup ");
  printf ("\n   21     PortNum                       iposPtmfStartRx ");
  printf ("\n   22     PortNum                       iposPtmfStartTx ");
  printf ("\n   23     PortNum                       iposPtmfStopTx ");
  printf ("\n   24     PortNum                       iposPtmfStopRx ");

  printf ("\n   99                                   EXIT FROM MENU");
  printf ("\n ===================================================================");
  printf ("\n BaseAddr = PTMF/EIU Chip Address; EIU of CPE 2.0 = 0xe0");
  printf ("\n PortNum  = 0,1,2,....");
  printf ("\n RegAddr  = 10 bit value; Upper 5 bits =index; Lower 5 bits = Offset");
  printf ("\n RegNum   = 0 - 31 (5 Bit Register Address)");
  printf ("\n PhyAddr  = Ethernet Phy MDIO Address ");
  printf ("\n            If Phy is accessed through the MDIO Master of EIU,");
  printf ("\n            OR the PHY address with 0xE0");
  printf ("\n Level    = 0,1,2,3,4 or 5");
  printf ("\n ===================================================================");
}

/*
*****************************************************************************
* Function      : Skip Space
* Parameters    : Pointer to the string
* Return        : Nothing
* Description   : 
*****************************************************************************
*/
static void dbgIniSkipSpace(U8 **pabCommandString)
{
//  printf("\n Skip Space %x %x %x", pabCommandString, *pabCommandString, **pabCommandString);

	while( ((U8)(*(*pabCommandString))) == ' ' ) 
  { 
    (*pabCommandString)++ ; 
  }
}
 

/*
*****************************************************************************
* Function      : Skip Pre-Hex (0x or 0X)
* Parameters    : None
* Return        : Nothing
* Description   : 
*****************************************************************************
*/
/*
static U8 dbgIniSkipPreHex( U8 **pabCommandString )
{
  U8  bFlag = 0;

	while (((U8)(*(*pabCommandString))) == '0') || 
         ((U8)(*(*pabCommandString))) == 'x') || 
         ((U8)(*(*pabCommandString))) == 'X') ) 
  { 
    if (((U8)(*(*pabCommandString))) != '0')
      bFlag = 1;

    (*pabCommandString)++ ; 
	}
  return (bFlag);
}

*/
U32 dbgIniGetValue(U8 **pabCommandString)
{
  int iCommand;
//  U8 *pbNext;

//  iCommand = strtoul(*pabCommandString, *pabCommandString, 0);
  iCommand = strtoul(*pabCommandString, (char **)pabCommandString, 0);
  
  dbgIniSkipSpace(pabCommandString);

//  printf("\n Returned Pointer = %x, %d", *pabCommandString, iCommand);
  return((U32)iCommand);
}

/*
  if (dbgIniSkipPreHex(*pabCommandString))
    ;
  else
    iCommand = atoi(pabCommandString);

  printf("Passed Pointer = %x", pabCommandString);
  iCommand = atoi(pabCommandString);
  printf("Returned Pointer = %x, %d", pabCommandString, iCommand);
*/


#endif // PTMF_DEBUG

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