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

📄 mac_diag.c

📁 开发Inetl IXP2400平台所必须的硬件诊断和测试程序。该软件包支持的功能包括CPU基本功能检测
💻 C
📖 第 1 页 / 共 2 页
字号:
/*
 *-------------------------------------------------------------------------------
 *                                                                      
 *                  I N T E L   P R O P R I E T A R Y                   
 *                                                                      
 *     COPYRIGHT (c)  2002 BY  INTEL  CORPORATION.  ALL RIGHTS          
 *     RESERVED.   NO  PART  OF THIS PROGRAM  OR  PUBLICATION  MAY      
 *     BE  REPRODUCED,   TRANSMITTED,   TRANSCRIBED,   STORED  IN  A    
 *     RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER    
 *     LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,    
 *     MAGNETIC,  OPTICAL,  CHEMICAL, MANUAL, OR OTHERWISE,  WITHOUT    
 *     THE PRIOR WRITTEN PERMISSION OF :                                
 *                                                                      
 *                        INTEL  CORPORATION                            
 *                                                                     
 *                     2200 MISSION COLLEGE BLVD                        
 *                                                                      
 *               SANTA  CLARA,  CALIFORNIA  95052-8119                  
 *                                                                      
 * ------------------------------------------------------------------------------
 */

/**
 * System defined include files required.0
 */

/**
 * User defined include files required.
 */
#include "mac_init.h"
#include "diag.h"
#include "mac_diag.h"
#include "packet_pool.h"
#include "error_map.h"
#include "prototypes.h"
#include "register_map.h"
#include "diagstruct.h"


extern UINT32 media_seat;
/**
 * These bit masks are used to set a bit in the mac_test_flag
 * The corresponding diagnostic routine against the set bit is invoked.
 */
#define SYSLB_TEST_MASK         0x8000  	/* bit 15 */
#define LPBK_TEST_MASK          0x10000 	/* bit 16 */
#define REG_RD					0x100000    /* bit 20 */
#define REG_WR					0x200000    /* bit 21 */
#define RD_ALL_REGS				0x400000	/* bit 22 */
#define SYSLB2_TEST_MASK        0x1000000  	/* bit 24 */
#define SYSLB3_TEST_MASK        0x2000000  	/* bit 25 */
#define PHY_READ_ALL			0xF		
#define PHY_REG_WRITE			0xD
#define INTERNAL_LPBK			0xE
#define LINE_TEST_MASK			0xC

/* Local function prototypes */

UINT32 validate_params(void);
void get_option_from_user(void);
short check_autoneg_status(void);
UINT32 do_mac_test(void);


/**
 * Extern function prototypes.
 */
extern void gets(char *str, int len);
extern void gbe_mac_phy_write(UINT32, UINT32,UINT32);
extern UINT32 pl_SysLpbk_test(void);
extern int getCmdLine(char* cmdLine);
extern UINT32 line_side_lpbk(void);
extern UINT32 gbe_mac_phy_read(UINT32 arg_PhyAddress, UINT32 arg_RegAddress);
extern UINT32 Sys_Loopback2_PL_Master(void);
extern UINT32 Sys_Loopback3_PL_Master(void);
extern void Enable_CPSR_Int(void);
extern void eprintf(char *f, ...);
extern UINT32 lpbk_test(void);
extern void reg_write( volatile UINT32 offset, UINT32 val);
extern UINT32 reg_read( volatile UINT32 offset);
extern void Disable_CPSR_Int(void);
extern int ctoi(char c);
extern unsigned int htoi(char *s);
extern void check_error_display_txstats(void);

/**
 * Static function prototypes.
 */
static void show_options_help(void);

char *aTestHelp[] =
{
	"t mac <option>",
	"where options are --",
	" ",
	"    m: Media Loopback test",
	"    syntax for media loopback test is -",
	"    t mac m <loopback mode> <mode> [speed] [duplex] [port] [loop count]",
	" ",
	"    y: System Loopback test",
	"    syntax for system loopback test is -",
	"    t mac y <loopback mode> <mode> [speed] [duplex] [port] [loop count]",
	" ",
	"    d: Lineside Loopback test",
	"    syntax for system loopback test is -",
	"    t mac d <loopback mode> <mode> [speed] [duplex] [port] [loop count]",
	" ",
	"    where",
	"    <loopback mode>: i -> internal loopback",
	"                     e -> external loopback",
	" ",
	"    <mode>: f -> fiber mode",
	"            c -> copper mode",
	"            m0 -> mixed mode with Port 0,1 Copper and Port 2,3 Fibre",
	"            m2 -> mixed mode with Port 0,1 Fibre and Port 2,3 Copper",
	" ",
	"    [speed]:",
	"           10   -> 10 Mbps (copper mode only)",
	"           100  -> 100 Mbps (copper mode only)",
	"           1000 -> 1000 Mbps (copper, fiber and mixed mode)",
	" ",
	"    [duplex]: h -> half duplex (copper mode only)",
	"              f -> full diplex (copper, fiber and mixed mode)",
	" ",
	"    [port]: ",
	"          0/1/2/3 -> Test is executed on one of these ports",
	"          4       -> Test is executed on all ports",
	" ",
	"    [loop count] -> Number of loops for the loopback test.",
    " ",
    "    NOTE: For mixed mode",
    "          <loopback mode> can only be 'e' and [port] must be 4",
	" ",
    "r: read a MAC register",
    "w: write to a MAC register",
    "g: read all MAC registers",
    "a: read all PHY registers",
    "p: write PHY registers",
    
};


#define aTestHelpSz (sizeof(aTestHelp) /sizeof(aTestHelp[0]))  

/** Global variables **/
UINT32 total_args=0,loop=1,ports=4;
UINT8 channel='0',test_opt='?' ;
UINT32 speed=1000;  
UINT8 dplx='f',loopback_mode='i';
UINT32 rxstat[4][30],txstat[4][30];
UINT32 mac_test_flag = 0;

/**
 * Function definitions.
 */

    void mac_test(void)
    {
        register PDiagCommon acL = (PDiagCommon) ACADDRESS;    
		test_opt = acL->argv[2][0];	                
   
        if(acL->HostType == MASTER)             // if master NPU
        { 
			get_option_from_user();

            if (do_mac_test() != DONE)
            {
                eprintf("Aborting Execution !\n");
				return;
            }

			return;
        } 

    }

  
    void get_option_from_user(void)
    {

        short bad_option = 1;
		switch (test_opt) 
        {

			case 'a': mac_test_flag |= PHY_READ_ALL; 	
                      bad_option = 0;
                      break;

			case 'p': mac_test_flag |= PHY_REG_WRITE; 	
                      bad_option = 0;
                      break;

			case 'g': mac_test_flag |= RD_ALL_REGS; 	
                      bad_option = 0;
                      break;
		  		             
			case 'r': mac_test_flag |= REG_RD; 	
                      bad_option = 0;
                      break;

			case 'w': mac_test_flag |= REG_WR; 	
                      bad_option = 0;
                      break;

            case 'm': //eprintf("setting mac test flag\n");
					  mac_test_flag |= LPBK_TEST_MASK;
                      bad_option = 0;
                      break;

            case 'y': //eprintf("setting mac test flag\n");
					  mac_test_flag |= SYSLB_TEST_MASK;
                      bad_option = 0;
                      break;

			case '2': mac_test_flag |= SYSLB2_TEST_MASK;
                      bad_option = 0;
                      break;

			case '3': mac_test_flag |= SYSLB3_TEST_MASK;
                      bad_option = 0;
                      break;

            case 'd': 
					  mac_test_flag |= LINE_TEST_MASK;
                      bad_option = 0;
                      break;

			default:  
    				  show_options_help();
					  break;
        }

		return ;
    }


    static void show_options_help(void)
    {
        short i=0;

        eprintf("Mac test options\n");
        eprintf("----------------\n");
       
        for (i=0;i<aTestHelpSz;i++)
        {
            eprintf("%s\n",aTestHelp[i]);
        }
    }

	
	UINT32 do_mac_test(void) 
    {
		char saddr[5],sval[10];
		short i=0;
		unsigned int address = 0,value=0;	
	
        switch (mac_test_flag)
        {

			case SYSLB_TEST_MASK:
	           /*
		        * invoke system loopback tests
				*/
                 pl_SysLpbk_test(); 
                 break;

			case SYSLB2_TEST_MASK:
				/*
		        * invoke system loopback test # 2
				*/
				Sys_Loopback2_PL_Master(); 
                break;

			case SYSLB3_TEST_MASK:
				/*
		        * invoke system loopback test # 3
				*/
				Sys_Loopback3_PL_Master(); 
                break;

			case LPBK_TEST_MASK:
				/*
				* invoke internal and external media loopback tests
				*/

				lpbk_test(); 
                break;

		    case INTERNAL_LPBK:
				lpbk_test();
				break;

		    case LINE_TEST_MASK:
				line_side_lpbk();
				break;

		    case PHY_REG_WRITE:
				phy_write();
				break;

			case PHY_READ_ALL:
				spConfig();
				gbe_mac_phy_read_all();
		        spRestore();
				break;

			case RD_ALL_REGS:
				read_all_regs();
				break;

			case REG_RD:
				spConfig();
				/*** read vallejo registers ***/
  				eprintf("\nEnter Vallejo Reg. offset :");
				for (i=0;i<=4;i++)
					saddr[i] = '\0';
				i=0;
				gets(saddr, 4);
	
				address=htoi(saddr);
				eprintf("\nReading offset 0x%x, value = 0x%x\n",address,reg_read(address));
				strcpy(saddr,"00000");
				spRestore();

⌨️ 快捷键说明

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