openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

port_test1588.c (88941B)


      1 /*
      2  * 
      3  * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      4  * 
      5  * Copyright 2007-2019 Broadcom Inc. All rights reserved.
      6  *
      7  * File:        port_test1588.c
      8  * Purpose:     Functions to support CLI 1588 testing commands
      9  * Requires:
     10  */
     11 
     12 /* #define INCLUDE_TIMESYNC_DVT_TESTS */
     13 
     14 #ifdef  INCLUDE_TIMESYNC_DVT_TESTS
     15 
     16 #include <sal/core/libc.h>
     17 #include <sal/types.h>
     18 #include <sal/appl/sal.h>
     19 #include <sal/appl/io.h>
     20 #include <sal/core/libc.h>
     21 
     22 #include <shared/bsl.h>
     23 
     24 #if !(defined(LINUX) || defined(UNIX))
     25 #define  strcasecmp    strcmp
     26 #define  strncasecmp   strncmp
     27 #endif  /* UNIX || LINUX */
     28 
     29 #include <assert.h>
     30 #include <soc/debug.h>
     31 
     32 #if defined(BCM_ESW_SUPPORT)
     33 #include <soc/xaui.h>
     34 #endif
     35 #include <soc/phyctrl.h>
     36 #include <soc/phy.h>
     37 #include <soc/phy/phymod_sim.h>
     38 #include <soc/eyescan.h>
     39 
     40 #if defined(PHYMOD_SUPPORT)
     41 #include <appl/diag/phymod/phymod_symop.h>
     42 #include <soc/phyreg.h>
     43 #include <soc/phy/phymod_ctrl.h>
     44 #include <phymod/phymod_reg.h>
     45 #include <phymod/phymod_debug.h>
     46 #endif
     47 
     48 #include <appl/diag/shell.h>
     49 #include <appl/diag/system.h>
     50 #include <appl/diag/parse.h>
     51 #include <appl/diag/diag.h>
     52 #include <appl/diag/dport.h>
     53 
     54 #include <bcm/init.h>
     55 #include <bcm/port.h>
     56 #include <bcm/stg.h>
     57 #include <bcm/error.h>
     58 
     59 #include <bcm_int/control.h>
     60 
     61 #if defined(BCM_ESW_SUPPORT)
     62 #include <bcm_int/esw/port.h>
     63 #endif
     64 
     65 void _print_heartbeat_ts(int unit, bcm_port_t port);
     66 void _print_capture_ts(int unit, bcm_port_t port);
     67 
     68 uint64
     69 _compiler_64_arg(uint32 hi, uint32 low)
     70 {
     71     uint64 val;
     72     COMPILER_64_SET(val, hi, low);
     73     return val;
     74 }
     75 
     76 void
     77 heartbeat_trace(int unit, bcm_port_t port, int msec, int iter) {
     78     int     accelo, ii;
     79     int64   accel;
     80     uint64  delta, present, prev;
     81 
     82     COMPILER_64_SET(accel, 0, 0);
     83     COMPILER_64_SET(prev , 0, 0);
     84     COMPILER_64_SET(delta, 0, 0);
     85 
     86     for ( ii = 0; ii < iter; ++ii ) {
     87         bcm_port_control_phy_timesync_get(unit, port,
     88                       bcmPortControlPhyTimesyncHeartbeatTimestamp, &present);
     89         if ( ! COMPILER_64_IS_ZERO(prev) ) {
     90             COMPILER_64_SET(delta, COMPILER_64_HI(present),
     91                                    COMPILER_64_LO(present));
     92             COMPILER_64_SUB_64(delta, prev);      /* delta = present - prev */
     93         }
     94         if ( ! (COMPILER_64_IS_ZERO(delta) || COMPILER_64_IS_ZERO(accel)) ) {
     95             COMPILER_64_SUB_64(accel, delta);     /* accel = delta's delta  */
     96         }
     97         accelo = COMPILER_64_LO(accel);
     98         cli_out("Heartbeat=%08x_%08x  delta=%08x_%08x  accel = %c%d\n",
     99                 COMPILER_64_HI(present), COMPILER_64_LO(present),
    100                 COMPILER_64_HI(delta)  , COMPILER_64_LO(delta),
    101                 (accelo == 0) ? ' ' : (accelo > 0) ? '+' : '\0', accelo );
    102 
    103         COMPILER_64_SET(prev, COMPILER_64_HI(present),
    104                               COMPILER_64_LO(present));    /* prev = present */
    105         if ( ! COMPILER_64_IS_ZERO(delta) ) {
    106             COMPILER_64_SET(accel, COMPILER_64_HI(delta),
    107                                    COMPILER_64_LO(delta));  /* accel = delta */
    108         }
    109         sal_msleep(msec);
    110     }
    111 }
    112 
    113 
    114 void                                          /* derived from  config_tc6p1() */
    115 config_syncout(int unit, bcm_port_t port,
    116                bcm_port_phy_timesync_syncout_mode_t mode,
    117                int pulse1, int pulse2, int interval)
    118 {
    119     bcm_port_phy_timesync_config_t config;
    120     int     rv;
    121     uint64 *time;
    122     uint32  value = ~(BCM_PORT_PHY_TIMESYNC_LOCAL_TIME_ALWAYS_LOAD);
    123 
    124     rv = bcm_port_control_phy_timesync_set(unit, port,
    125                                            bcmPortControlPhyTimesyncLoadControl,
    126                                            _compiler_64_arg(0, value));
    127     if ( rv != BCM_E_NONE ) {
    128         cli_out("bcm_port_control_phy_timesync_set() failed "
    129                 "with error  u=%d p=%d %s\n", unit, port, bcm_errmsg(rv));
    130     }
    131 
    132     config.validity_mask =
    133         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    134         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
    135         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
    136 
    137     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    138     if (rv != BCM_E_NONE) {
    139         cli_out("bcm_port_phy_timesync_config_get failed "
    140                 "with error u=%d p=%d %s\n", unit, port, bcm_errmsg(rv));
    141     }
    142     time = &(config.syncout.syncout_ts);
    143 
    144     rv = bcm_port_control_phy_timesync_get(unit, port,
    145                 bcmPortControlPhyTimesyncHeartbeatTimestamp, time);
    146     cli_out("Heartbeat TS = %08x%08x\n",
    147             COMPILER_64_HI(*time), COMPILER_64_LO(*time));
    148 
    149     config.flags |=
    150         BCM_PORT_PHY_TIMESYNC_ENABLE |
    151         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    152         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    153     config.gmode                  = bcmPortPhyTimesyncModeCpu;
    154     config.syncout.mode           = mode;
    155     config.syncout.pulse_1_length = pulse1;
    156     config.syncout.pulse_2_length = pulse2;
    157     config.syncout.interval       = interval;
    158     /* add a time offset value to  config.syncout.syncout_ts  in order to     */
    159     COMPILER_64_ADD_32(*time, 0xf0000000L);   /* generate the FrameSync pulse */
    160 
    161     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    162     if (rv != BCM_E_NONE) {
    163         cli_out("bcm_port_phy_timesync_config_set failed "
    164                 "with error  u=%d p=%d %s\n", unit, port, bcm_errmsg(rv));
    165     }
    166     /* sal_msleep(2200);       COMPILER_64_ZERO(config.syncout.syncout_ts); */
    167 
    168     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    169     if (rv != BCM_E_NONE) {
    170         cli_out("bcm_port_phy_timesync_config_get failed "
    171                 "with error u=%d p=%d %s\n", unit, port, bcm_errmsg(rv));
    172     }
    173     cli_out(" SYNCOUT  TS = %08x%08x\n",
    174             COMPILER_64_HI(*time), COMPILER_64_LO(*time));
    175 
    176     _print_heartbeat_ts(unit, port);
    177 }
    178 
    179 
    180 /* Test case 1 */
    181 void
    182 config_i1e1_in(int unit, bcm_port_t port)
    183 {
    184     int rv;
    185     bcm_port_phy_timesync_config_t config;
    186 
    187     config.validity_mask =
    188         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    189         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    190         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE;
    191 
    192     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    193 
    194     if (rv != BCM_E_NONE) {
    195         cli_out("bcm_port_phy_timesync_config_get failed "
    196                 "with error u=%d p=%d %s\n",
    197                 unit, port, bcm_errmsg(rv));
    198     }
    199 
    200     config.flags |=
    201         BCM_PORT_PHY_TIMESYNC_ENABLE |
    202         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    203         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    204 
    205     config.tx_sync_mode =
    206         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    207 
    208     config.rx_sync_mode =
    209         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    210 
    211     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    212 
    213     if (rv != BCM_E_NONE) {
    214         cli_out("bcm_port_phy_timesync_config_set failed "
    215                 "with error  u=%d p=%d %s\n",
    216                 unit, port, bcm_errmsg(rv));
    217     }
    218 }
    219 
    220 void
    221 config_i1e1_out(int unit, bcm_port_t port)
    222 {
    223     int rv;
    224     bcm_port_phy_timesync_config_t config;
    225 
    226     config.validity_mask =
    227         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    228         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    229         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE;
    230 
    231     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    232 
    233     if (rv != BCM_E_NONE) {
    234         cli_out("bcm_port_phy_timesync_config_get "
    235                 "failed with error u=%d p=%d %s\n",
    236                 unit, port, bcm_errmsg(rv));
    237     }
    238 
    239     config.flags |=
    240         BCM_PORT_PHY_TIMESYNC_ENABLE | 
    241         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    242         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    243 
    244     config.tx_sync_mode =
    245         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    246 
    247     config.rx_sync_mode =
    248         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    249 
    250     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    251 
    252     if (rv != BCM_E_NONE) {
    253         cli_out("bcm_port_phy_timesync_config_set failed "
    254                 "with error  u=%d p=%d %s\n",
    255                 unit, port, bcm_errmsg(rv));
    256     }
    257 }
    258 
    259 /* Test case 2 */
    260 void
    261 config_i0e2_in(int unit, bcm_port_t port)
    262 {
    263     int rv;
    264     bcm_port_phy_timesync_config_t config;
    265 
    266     config.validity_mask =
    267         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    268         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    269         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    270         BCM_PORT_PHY_TIMESYNC_VALID_ORIGINAL_TIMECODE;
    271 
    272     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    273 
    274     if (rv != BCM_E_NONE) {
    275         cli_out("bcm_port_phy_timesync_config_get failed "
    276                 "with error u=%d p=%d %s\n",
    277                 unit, port, bcm_errmsg(rv));
    278     }
    279 
    280     config.flags |=
    281         BCM_PORT_PHY_TIMESYNC_ENABLE |
    282         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    283         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    284 
    285     config.tx_sync_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
    286 
    287     config.rx_sync_mode = bcmPortPhyTimesyncEventMessageIngressModeNone;
    288 
    289     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    290 
    291     if (rv != BCM_E_NONE) {
    292         cli_out("bcm_port_phy_timesync_config_set failed "
    293                 "with error  u=%d p=%d %s\n",
    294                 unit, port, bcm_errmsg(rv));
    295     }
    296 
    297     rv = bcm_port_control_phy_timesync_set(unit, port,
    298                                            bcmPortControlPhyTimesyncLoadControl,
    299                                            _compiler_64_arg(0,
    300                                                             BCM_PORT_PHY_TIMESYNC_TIMECODE_LOAD));
    301 
    302     if (rv != BCM_E_NONE) {
    303         cli_out("bcm_port_control_phy_timesync_set failed "
    304                 "with error  u=%d p=%d %s\n",
    305                 unit, port, bcm_errmsg(rv));
    306     }
    307 }
    308 
    309 void
    310 config_i0e2_out(int unit, bcm_port_t port)
    311 {
    312     int rv;
    313     bcm_port_phy_timesync_config_t config;
    314 
    315     config.validity_mask =
    316         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    317         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    318         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    319         BCM_PORT_PHY_TIMESYNC_VALID_ORIGINAL_TIMECODE;
    320 
    321     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    322 
    323     if (rv != BCM_E_NONE) {
    324         cli_out("bcm_port_phy_timesync_config_get failed "
    325                 "with error u=%d p=%d %s\n",
    326                 unit, port, bcm_errmsg(rv));
    327     }
    328 
    329     config.flags |=
    330         BCM_PORT_PHY_TIMESYNC_ENABLE |
    331         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    332         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    333 
    334     config.tx_sync_mode =
    335         bcmPortPhyTimesyncEventMessageEgressModeReplaceCorrectionFieldOrigin;
    336 
    337     config.rx_sync_mode = bcmPortPhyTimesyncEventMessageIngressModeNone;
    338 
    339     config.original_timecode.seconds = _compiler_64_arg(0, 0xbeef8000);
    340 
    341     config.original_timecode.nanoseconds = 0xaaaabbbb;
    342 
    343     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    344 
    345     if (rv != BCM_E_NONE) {
    346         cli_out("bcm_port_phy_timesync_config_set failed "
    347                 "with error  u=%d p=%d %s\n",
    348                 unit, port, bcm_errmsg(rv));
    349     }
    350 
    351     rv = bcm_port_control_phy_timesync_set(unit, port,
    352                                            bcmPortControlPhyTimesyncLoadControl,
    353                                            _compiler_64_arg(0,
    354                                                             BCM_PORT_PHY_TIMESYNC_TIMECODE_LOAD));
    355 
    356     if (rv != BCM_E_NONE) {
    357         cli_out("bcm_port_control_phy_timesync_set failed "
    358                 "with error  u=%d p=%d %s\n",
    359                 unit, port, bcm_errmsg(rv));
    360     }
    361 }
    362 
    363 /* Test case 3 */
    364 void
    365 config_i2e0_in(int unit, bcm_port_t port)
    366 {
    367     int rv;
    368     bcm_port_phy_timesync_config_t config;
    369 
    370     config.validity_mask =
    371         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    372         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    373         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    374         BCM_PORT_PHY_TIMESYNC_VALID_GMODE;
    375 
    376     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    377 
    378     if (rv != BCM_E_NONE) {
    379         cli_out("bcm_port_phy_timesync_config_get failed "
    380                 "with error u=%d p=%d %s\n",
    381                 unit, port, bcm_errmsg(rv));
    382     }
    383 
    384     config.flags |=
    385         BCM_PORT_PHY_TIMESYNC_ENABLE |
    386         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    387         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    388 
    389     config.tx_sync_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
    390     config.rx_sync_mode =
    391         bcmPortPhyTimesyncEventMessageIngressModeInsertTimestamp;
    392     /* config.gmode = bcmPortPhyTimesyncModeCpu; */
    393     config.gmode = bcmPortPhyTimesyncModeFree;
    394 
    395     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    396 
    397     if (rv != BCM_E_NONE) {
    398         cli_out("bcm_port_phy_timesync_config_set failed "
    399                 "with error  u=%d p=%d %s\n",
    400                 unit, port, bcm_errmsg(rv));
    401     }
    402 }
    403 
    404 void
    405 config_i2e0_out(int unit, bcm_port_t port)
    406 {
    407     int rv;
    408     bcm_port_phy_timesync_config_t config;
    409 
    410     config.validity_mask =
    411         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    412         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    413         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    414         BCM_PORT_PHY_TIMESYNC_VALID_ORIGINAL_TIMECODE |
    415         BCM_PORT_PHY_TIMESYNC_VALID_GMODE;
    416 
    417     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    418 
    419     if (rv != BCM_E_NONE) {
    420         cli_out("bcm_port_phy_timesync_config_get failed "
    421                 "with error u=%d p=%d %s\n",
    422                 unit, port, bcm_errmsg(rv));
    423     }
    424 
    425     config.flags |=
    426         BCM_PORT_PHY_TIMESYNC_ENABLE |
    427         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    428         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    429 
    430     config.tx_sync_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
    431     config.rx_sync_mode = bcmPortPhyTimesyncEventMessageIngressModeNone;
    432     /* config.gmode = bcmPortPhyTimesyncModeCpu; */
    433     config.gmode = bcmPortPhyTimesyncModeFree;
    434 
    435     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    436 
    437     if (rv != BCM_E_NONE) {
    438         cli_out("bcm_port_phy_timesync_config_set failed "
    439                 "with error  u=%d p=%d %s\n",
    440                 unit, port, bcm_errmsg(rv));
    441     }
    442 
    443     rv = bcm_port_control_phy_timesync_set(unit, port,
    444                                            bcmPortControlPhyTimesyncLoadControl,
    445                                            _compiler_64_arg(0,
    446                                                             BCM_PORT_PHY_TIMESYNC_TIMECODE_LOAD));
    447 
    448     if (rv != BCM_E_NONE) {
    449         cli_out("bcm_port_control_phy_timesync_set failed "
    450                 "with error  u=%d p=%d %s\n",
    451                 unit, port, bcm_errmsg(rv));
    452     }
    453 }
    454 
    455 void
    456 config_tc5p1(int unit, bcm_port_t port, int arg1, int arg2)
    457 {
    458     int rv;
    459     bcm_port_phy_timesync_config_t config;
    460 
    461     config.validity_mask =
    462         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    463         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
    464         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
    465 
    466     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    467 
    468     if (rv != BCM_E_NONE) {
    469         cli_out("bcm_port_phy_timesync_config_get failed "
    470                 "with error u=%d p=%d %s\n",
    471                 unit, port, bcm_errmsg(rv));
    472     }
    473 
    474     config.flags |=
    475         BCM_PORT_PHY_TIMESYNC_ENABLE |
    476         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    477         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    478 
    479     config.syncout.mode = bcmPortPhyTimesyncSyncoutOneTime;
    480     config.syncout.pulse_1_length = 20000;
    481     config.syncout.syncout_ts = _compiler_64_arg(0, 80000);
    482     config.gmode = bcmPortPhyTimesyncModeCpu;
    483 
    484     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    485 
    486     if (rv != BCM_E_NONE) {
    487         cli_out("bcm_port_phy_timesync_config_set failed "
    488                 "with error  u=%d p=%d %s\n",
    489                 unit, port, bcm_errmsg(rv));
    490     }
    491 
    492     rv = bcm_port_control_phy_timesync_set(unit, port,
    493                                            bcmPortControlPhyTimesyncLoadControl,
    494                                            _compiler_64_arg(0, 0xffffffff));
    495 
    496     if (rv != BCM_E_NONE) {
    497         cli_out("bcm_port_control_phy_timesync_set failed "
    498                 "with error  u=%d p=%d %s\n",
    499                 unit, port, bcm_errmsg(rv));
    500     }
    501 }
    502 
    503 void
    504 config_tc6p1(int unit, bcm_port_t port, int arg1, int arg2)
    505 {
    506     int rv;
    507     bcm_port_phy_timesync_config_t config;
    508 
    509     config.validity_mask =
    510         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    511         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
    512         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
    513 
    514     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    515 
    516     if (rv != BCM_E_NONE) {
    517         cli_out("bcm_port_phy_timesync_config_get failed "
    518                 "with error u=%d p=%d %s\n",
    519                 unit, port, bcm_errmsg(rv));
    520     }
    521 
    522     config.flags |=
    523         BCM_PORT_PHY_TIMESYNC_ENABLE |
    524         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    525         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    526 
    527     config.syncout.mode = bcmPortPhyTimesyncSyncoutPulseTrain;
    528     config.syncout.pulse_1_length = 20000;
    529     config.syncout.pulse_2_length = 10000;
    530     config.syncout.syncout_ts = _compiler_64_arg(0, 80000);
    531     config.gmode = bcmPortPhyTimesyncModeCpu;
    532 
    533     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    534 
    535     if (rv != BCM_E_NONE) {
    536         cli_out("bcm_port_phy_timesync_config_set failed "
    537                 "with error  u=%d p=%d %s\n",
    538                 unit, port, bcm_errmsg(rv));
    539     }
    540 
    541     rv = bcm_port_control_phy_timesync_set(unit, port,
    542                                            bcmPortControlPhyTimesyncLoadControl,
    543                                            _compiler_64_arg(0, 0xffffffff));
    544 
    545     if (rv != BCM_E_NONE) {
    546         cli_out("bcm_port_control_phy_timesync_set failed "
    547                 "with error  u=%d p=%d %s\n",
    548                 unit, port, bcm_errmsg(rv));
    549     }
    550 }
    551 
    552 void
    553 config_tc7p1(int unit, bcm_port_t port, int arg1, int arg2)
    554 {
    555     int rv;
    556     bcm_port_phy_timesync_config_t config;
    557 
    558     config.validity_mask =
    559         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    560         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
    561         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
    562 
    563     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    564 
    565     if (rv != BCM_E_NONE) {
    566         cli_out("bcm_port_phy_timesync_config_get failed "
    567                 "with error u=%d p=%d %s\n",
    568                 unit, port, bcm_errmsg(rv));
    569     }
    570 
    571     config.flags |=
    572         BCM_PORT_PHY_TIMESYNC_ENABLE |
    573         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    574         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    575 
    576     config.syncout.mode = bcmPortPhyTimesyncSyncoutPulseTrainWithSync;
    577     config.syncout.pulse_1_length = 20000;
    578     config.syncout.pulse_2_length = 10000;
    579     config.syncout.syncout_ts = _compiler_64_arg(0, 80000);
    580     config.gmode = bcmPortPhyTimesyncModeCpu;
    581 
    582     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    583 
    584     if (rv != BCM_E_NONE) {
    585         cli_out("bcm_port_phy_timesync_config_set failed "
    586                 "with error  u=%d p=%d %s\n",
    587                 unit, port, bcm_errmsg(rv));
    588     }
    589 
    590     rv = bcm_port_control_phy_timesync_set(unit, port,
    591                                            bcmPortControlPhyTimesyncLoadControl,
    592                                            _compiler_64_arg(0, 0xffffffff));
    593 
    594     if (rv != BCM_E_NONE) {
    595         cli_out("bcm_port_control_phy_timesync_set failed "
    596                 "with error  u=%d p=%d %s\n",
    597                 unit, port, bcm_errmsg(rv));
    598     }
    599 }
    600 
    601 void
    602 config_tc8p1(int unit, bcm_port_t port, int arg1, int arg2)
    603 {
    604     int rv;
    605     bcm_port_phy_timesync_config_t config;
    606 
    607     config.validity_mask =
    608         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    609         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
    610         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE;
    611 
    612     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    613 
    614     if (rv != BCM_E_NONE) {
    615         cli_out("bcm_port_phy_timesync_config_get failed "
    616                 "with error u=%d p=%d %s\n",
    617                 unit, port, bcm_errmsg(rv));
    618     }
    619 
    620     config.flags |=
    621         BCM_PORT_PHY_TIMESYNC_ENABLE |
    622         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    623         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    624 
    625     config.framesync.mode = bcmPortPhyTimesyncFramesyncSyncin0;
    626     config.framesync.length_threshold = 20000;
    627     config.gmode = bcmPortPhyTimesyncModeCpu;
    628 
    629     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    630 
    631     if (rv != BCM_E_NONE) {
    632         cli_out("bcm_port_phy_timesync_config_set failed "
    633                 "with error  u=%d p=%d %s\n",
    634                 unit, port, bcm_errmsg(rv));
    635     }
    636 
    637     rv = bcm_port_control_phy_timesync_set(unit, port,
    638                                            bcmPortControlPhyTimesyncLoadControl,
    639                                            _compiler_64_arg(0, 0xffffffff));
    640 
    641     if (rv != BCM_E_NONE) {
    642         cli_out("bcm_port_control_phy_timesync_set failed "
    643                 "with error  u=%d p=%d %s\n",
    644                 unit, port, bcm_errmsg(rv));
    645     }
    646 }
    647 
    648 /* Test case 1: MPLS label 1 : all ptp pkts  */
    649 void
    650 config_i1e1_all_pkts_mpls1_en_in(int unit, bcm_port_t port)
    651 {
    652     int rv;
    653     bcm_port_phy_timesync_config_t config;
    654 
    655     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    656             BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    657             BCM_PORT_PHY_TIMESYNC_VALID_TX_DELAY_REQUEST_MODE |
    658             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_REQUEST_MODE |
    659             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_RESPONSE_MODE |
    660             BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    661             BCM_PORT_PHY_TIMESYNC_VALID_RX_DELAY_REQUEST_MODE |
    662             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_REQUEST_MODE |
    663             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_RESPONSE_MODE |
    664             BCM_PORT_PHY_TIMESYNC_VALID_MPLS_CONTROL;
    665     config.mpls_control.size = 1;
    666     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
    667      * sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
    668 
    669     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    670     if (rv != BCM_E_NONE) {
    671         cli_out("bcm_port_phy_timesync_config_get failed "
    672                 "with error u=%d p=%d %s\n",
    673                 unit, port, bcm_errmsg(rv));
    674     }
    675 
    676     config.flags |=
    677         BCM_PORT_PHY_TIMESYNC_ENABLE |
    678         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    679         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    680 
    681     config.tx_sync_mode =
    682         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    683     config.rx_sync_mode =
    684         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    685 
    686     config.tx_delay_request_mode =
    687         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    688     config.rx_delay_request_mode =
    689         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    690 
    691     config.tx_pdelay_request_mode =
    692         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    693     config.rx_pdelay_request_mode =
    694         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    695 
    696     config.tx_pdelay_response_mode =
    697         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    698     config.rx_pdelay_response_mode =
    699         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    700 
    701     config.mpls_control.flags = BCM_PORT_PHY_TIMESYNC_MPLS_ENABLE |
    702         BCM_PORT_PHY_TIMESYNC_MPLS_CONTROL_WORD_ENABLE;
    703 
    704     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    705     if (rv != BCM_E_NONE) {
    706         cli_out("bcm_port_phy_timesync_config_set failed "
    707                 "with error  u=%d p=%d %s\n",
    708                 unit, port, bcm_errmsg(rv));
    709     }
    710     /* if(config.mpls_control.labels != NULL) {
    711        sal_free(config.mpls_control.labels);
    712        } */
    713 
    714 }
    715 
    716 void
    717 config_i1e1_all_pkts_mpls1_en_out(int unit, bcm_port_t port)
    718 {
    719     int rv;
    720     bcm_port_phy_timesync_config_t config;
    721 
    722     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    723             BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    724             BCM_PORT_PHY_TIMESYNC_VALID_TX_DELAY_REQUEST_MODE |
    725             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_REQUEST_MODE | 
    726             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_RESPONSE_MODE |
    727             BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    728             BCM_PORT_PHY_TIMESYNC_VALID_RX_DELAY_REQUEST_MODE |
    729             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_REQUEST_MODE |
    730             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_RESPONSE_MODE |
    731             BCM_PORT_PHY_TIMESYNC_VALID_MPLS_CONTROL;
    732 
    733     config.mpls_control.size = 1;
    734     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
    735      sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
    736     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    737     if (rv != BCM_E_NONE) {
    738         cli_out("bcm_port_phy_timesync_config_get failed "
    739                 "with error u=%d p=%d %s\n",
    740                 unit, port, bcm_errmsg(rv));
    741     }
    742 
    743     config.flags |=
    744         BCM_PORT_PHY_TIMESYNC_ENABLE |
    745         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    746         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    747 
    748     config.tx_sync_mode =
    749         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    750     config.rx_sync_mode =
    751         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    752 
    753     config.tx_delay_request_mode =
    754         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    755     config.rx_delay_request_mode =
    756         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    757 
    758     config.tx_pdelay_request_mode =
    759         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    760     config.rx_pdelay_request_mode =
    761         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    762 
    763     config.tx_pdelay_response_mode =
    764         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
    765     config.rx_pdelay_response_mode =
    766         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
    767 
    768     config.mpls_control.flags = BCM_PORT_PHY_TIMESYNC_MPLS_ENABLE |
    769         BCM_PORT_PHY_TIMESYNC_MPLS_CONTROL_WORD_ENABLE;
    770 
    771     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    772     if (rv != BCM_E_NONE) {
    773         cli_out("bcm_port_phy_timesync_config_set failed "
    774                 "with error  u=%d p=%d %s\n",
    775                 unit, port, bcm_errmsg(rv));
    776     }
    777     /* if(config.mpls_control.labels != NULL) {
    778        sal_free(config.mpls_control.labels);
    779        } */
    780 }
    781 
    782 /* Test case 2 : MPLS label 1 : all ptp pkts  */
    783 void
    784 config_i0e2_all_pkts_mpls1_en_in(int unit, bcm_port_t port)
    785 {
    786     int rv;
    787     bcm_port_phy_timesync_config_t config;
    788 
    789     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    790             BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    791             BCM_PORT_PHY_TIMESYNC_VALID_TX_DELAY_REQUEST_MODE |
    792             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_REQUEST_MODE |
    793             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_RESPONSE_MODE |
    794             BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    795             BCM_PORT_PHY_TIMESYNC_VALID_RX_DELAY_REQUEST_MODE |
    796             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_REQUEST_MODE |
    797             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_RESPONSE_MODE |
    798             BCM_PORT_PHY_TIMESYNC_VALID_ORIGINAL_TIMECODE |
    799             BCM_PORT_PHY_TIMESYNC_VALID_MPLS_CONTROL;
    800 
    801     config.mpls_control.size = 1;
    802     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
    803        sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
    804     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    805 
    806     if (rv != BCM_E_NONE) {
    807         cli_out("bcm_port_phy_timesync_config_get failed "
    808                 "with error u=%d p=%d %s\n",
    809                 unit, port, bcm_errmsg(rv));
    810     }
    811 
    812     config.flags |=
    813         BCM_PORT_PHY_TIMESYNC_ENABLE |
    814         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    815         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    816 
    817     config.tx_sync_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
    818     config.rx_sync_mode = bcmPortPhyTimesyncEventMessageIngressModeNone;
    819 
    820     config.tx_delay_request_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
    821     config.rx_delay_request_mode =
    822         bcmPortPhyTimesyncEventMessageIngressModeNone;
    823 
    824     config.tx_pdelay_request_mode =
    825         bcmPortPhyTimesyncEventMessageEgressModeNone;
    826     config.rx_pdelay_request_mode =
    827         bcmPortPhyTimesyncEventMessageIngressModeNone;
    828 
    829     config.tx_pdelay_response_mode =
    830         bcmPortPhyTimesyncEventMessageEgressModeNone;
    831     config.rx_pdelay_response_mode =
    832         bcmPortPhyTimesyncEventMessageIngressModeNone;
    833 
    834     config.mpls_control.flags = BCM_PORT_PHY_TIMESYNC_MPLS_ENABLE |
    835         BCM_PORT_PHY_TIMESYNC_MPLS_CONTROL_WORD_ENABLE;
    836 
    837     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    838 
    839     if (rv != BCM_E_NONE) {
    840         cli_out("bcm_port_phy_timesync_config_set failed "
    841                 "with error  u=%d p=%d %s\n",
    842                 unit, port, bcm_errmsg(rv));
    843     }
    844 
    845     rv = bcm_port_control_phy_timesync_set(unit, port,
    846                                            bcmPortControlPhyTimesyncLoadControl,
    847                                            _compiler_64_arg(0,
    848                                                             BCM_PORT_PHY_TIMESYNC_TIMECODE_LOAD));
    849 
    850     if (rv != BCM_E_NONE) {
    851         cli_out("bcm_port_control_phy_timesync_set failed "
    852                 "with error  u=%d p=%d %s\n",
    853                 unit, port, bcm_errmsg(rv));
    854     }
    855     /* if(config.mpls_control.labels != NULL) {
    856        sal_free(config.mpls_control.labels);
    857        } */
    858 }
    859 
    860 void
    861 config_i0e2_all_pkts_mpls1_en_out(int unit, bcm_port_t port)
    862 {
    863     int rv;
    864     bcm_port_phy_timesync_config_t config;
    865 
    866     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    867             BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    868             BCM_PORT_PHY_TIMESYNC_VALID_TX_DELAY_REQUEST_MODE |
    869             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_REQUEST_MODE |
    870             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_RESPONSE_MODE |
    871             BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    872             BCM_PORT_PHY_TIMESYNC_VALID_RX_DELAY_REQUEST_MODE |
    873             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_REQUEST_MODE |
    874             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_RESPONSE_MODE |
    875             BCM_PORT_PHY_TIMESYNC_VALID_ORIGINAL_TIMECODE |
    876             BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
    877             BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
    878             BCM_PORT_PHY_TIMESYNC_VALID_MPLS_CONTROL;
    879 
    880     config.mpls_control.size = 1;
    881     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
    882      sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
    883     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    884 
    885     if (rv != BCM_E_NONE) {
    886         cli_out("bcm_port_phy_timesync_config_get failed "
    887                 "with error u=%d p=%d %s\n",
    888                 unit, port, bcm_errmsg(rv));
    889     }
    890 
    891     config.flags |=
    892         BCM_PORT_PHY_TIMESYNC_ENABLE |
    893         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    894         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    895 
    896     config.tx_sync_mode =
    897         bcmPortPhyTimesyncEventMessageEgressModeReplaceCorrectionFieldOrigin;
    898     /*config.tx_sync_mode = bcmPortPhyTimesyncEventMessageEgressModeNone; */
    899 
    900     config.rx_sync_mode = bcmPortPhyTimesyncEventMessageIngressModeNone;
    901 
    902     config.tx_delay_request_mode =
    903         bcmPortPhyTimesyncEventMessageEgressModeReplaceCorrectionFieldOrigin;
    904     config.rx_delay_request_mode =
    905         bcmPortPhyTimesyncEventMessageIngressModeNone;
    906 
    907     config.tx_pdelay_request_mode =
    908         bcmPortPhyTimesyncEventMessageEgressModeReplaceCorrectionFieldOrigin;
    909     config.rx_pdelay_request_mode =
    910         bcmPortPhyTimesyncEventMessageIngressModeNone;
    911 
    912     config.tx_pdelay_response_mode =
    913         bcmPortPhyTimesyncEventMessageEgressModeReplaceCorrectionFieldOrigin;
    914     config.rx_pdelay_response_mode =
    915         bcmPortPhyTimesyncEventMessageIngressModeNone;
    916 
    917     config.original_timecode.seconds = _compiler_64_arg(0, 0xbeef8000);
    918     config.original_timecode.nanoseconds = 0xaaaabbbb;
    919 
    920     config.framesync.mode =
    921         bcmPortPhyTimesyncFramesyncCpu /*bcmPortPhyTimesyncFramesyncSyncin0 */ ;
    922     config.framesync.length_threshold = 0x4;
    923     config.framesync.event_offset = 0x8;
    924 
    925     config.gmode = bcmPortPhyTimesyncModeCpu;
    926 
    927     config.mpls_control.flags = BCM_PORT_PHY_TIMESYNC_MPLS_ENABLE |
    928         BCM_PORT_PHY_TIMESYNC_MPLS_CONTROL_WORD_ENABLE;
    929 
    930     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
    931 
    932     if (rv != BCM_E_NONE) {
    933         cli_out("bcm_port_phy_timesync_config_set failed "
    934                 "with error  u=%d p=%d %s\n",
    935                 unit, port, bcm_errmsg(rv));
    936     }
    937 
    938     rv = bcm_port_control_phy_timesync_set(unit, port,
    939                                            bcmPortControlPhyTimesyncLoadControl,
    940                                            _compiler_64_arg(0,
    941                                                             BCM_PORT_PHY_TIMESYNC_TIMECODE_LOAD));
    942 
    943     if (rv != BCM_E_NONE) {
    944         cli_out("bcm_port_control_phy_timesync_set failed "
    945                 "with error  u=%d p=%d %s\n",
    946                 unit, port, bcm_errmsg(rv));
    947     }
    948     /* if(config.mpls_control.labels != NULL) {
    949        sal_free(config.mpls_control.labels);
    950        } */
    951 }
    952 
    953 /* Test case 3 : MPLS label 1 : all ptp pkts  */
    954 void
    955 config_i2e0_all_pkts_mpls1_en_in(int unit, bcm_port_t port)
    956 {
    957     int rv;
    958     bcm_port_phy_timesync_config_t config;
    959 
    960     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
    961             BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
    962             BCM_PORT_PHY_TIMESYNC_VALID_TX_DELAY_REQUEST_MODE |
    963             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_REQUEST_MODE |
    964             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_RESPONSE_MODE |
    965             BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
    966             BCM_PORT_PHY_TIMESYNC_VALID_RX_DELAY_REQUEST_MODE |
    967             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_REQUEST_MODE |
    968             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_RESPONSE_MODE |
    969             BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
    970             BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
    971             BCM_PORT_PHY_TIMESYNC_VALID_MPLS_CONTROL;
    972 
    973     config.mpls_control.size = 1;
    974     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
    975      sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
    976     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
    977 
    978     if (rv != BCM_E_NONE) {
    979         cli_out("bcm_port_phy_timesync_config_get failed "
    980                 "with error u=%d p=%d %s\n",
    981                 unit, port, bcm_errmsg(rv));
    982     }
    983 
    984     config.flags |=
    985         BCM_PORT_PHY_TIMESYNC_ENABLE |
    986         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
    987         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
    988 
    989     config.tx_sync_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
    990     config.rx_sync_mode =
    991         bcmPortPhyTimesyncEventMessageIngressModeInsertTimestamp;
    992 
    993     config.tx_delay_request_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
    994     config.rx_delay_request_mode =
    995         bcmPortPhyTimesyncEventMessageIngressModeInsertTimestamp;
    996 
    997     config.tx_pdelay_request_mode =
    998         bcmPortPhyTimesyncEventMessageEgressModeNone;
    999     config.rx_pdelay_request_mode =
   1000         bcmPortPhyTimesyncEventMessageIngressModeInsertTimestamp;
   1001 
   1002     config.tx_pdelay_response_mode =
   1003         bcmPortPhyTimesyncEventMessageEgressModeNone;
   1004     config.rx_pdelay_response_mode =
   1005         bcmPortPhyTimesyncEventMessageIngressModeInsertTimestamp;
   1006 
   1007     /* config.gmode = bcmPortPhyTimesyncModeCpu; */
   1008     config.gmode = bcmPortPhyTimesyncModeFree;
   1009 
   1010     config.mpls_control.flags = BCM_PORT_PHY_TIMESYNC_MPLS_ENABLE |
   1011         BCM_PORT_PHY_TIMESYNC_MPLS_CONTROL_WORD_ENABLE;
   1012 
   1013     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1014 
   1015     if (rv != BCM_E_NONE) {
   1016         cli_out("bcm_port_phy_timesync_config_set failed "
   1017                 "with error  u=%d p=%d %s\n",
   1018                 unit, port, bcm_errmsg(rv));
   1019     }
   1020     /* if(config.mpls_control.labels != NULL) {
   1021        sal_free(config.mpls_control.labels);
   1022        } */
   1023 }
   1024 
   1025 void
   1026 config_i2e0_all_pkts_mpls1_en_out(int unit, bcm_port_t port)
   1027 {
   1028     int rv;
   1029     bcm_port_phy_timesync_config_t config;
   1030 
   1031     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
   1032             BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
   1033             BCM_PORT_PHY_TIMESYNC_VALID_TX_DELAY_REQUEST_MODE |
   1034             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_REQUEST_MODE |
   1035             BCM_PORT_PHY_TIMESYNC_VALID_TX_PDELAY_RESPONSE_MODE |
   1036             BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
   1037             BCM_PORT_PHY_TIMESYNC_VALID_RX_DELAY_REQUEST_MODE |
   1038             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_REQUEST_MODE |
   1039             BCM_PORT_PHY_TIMESYNC_VALID_RX_PDELAY_RESPONSE_MODE |
   1040             BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1041             BCM_PORT_PHY_TIMESYNC_VALID_MPLS_CONTROL;
   1042 
   1043     config.mpls_control.size = 1;
   1044     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
   1045        sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
   1046     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   1047 
   1048     if (rv != BCM_E_NONE) {
   1049         cli_out("bcm_port_phy_timesync_config_get failed "
   1050                 "with error u=%d p=%d %s\n",
   1051                 unit, port, bcm_errmsg(rv));
   1052     }
   1053 
   1054     config.flags |=
   1055         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1056         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1057         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
   1058 
   1059     config.tx_sync_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
   1060     config.rx_sync_mode = bcmPortPhyTimesyncEventMessageIngressModeNone;
   1061 
   1062     config.tx_delay_request_mode = bcmPortPhyTimesyncEventMessageEgressModeNone;
   1063     config.rx_delay_request_mode =
   1064         bcmPortPhyTimesyncEventMessageIngressModeNone;
   1065 
   1066     config.tx_pdelay_request_mode =
   1067         bcmPortPhyTimesyncEventMessageEgressModeNone;
   1068     config.rx_pdelay_request_mode =
   1069         bcmPortPhyTimesyncEventMessageIngressModeNone;
   1070 
   1071     config.tx_pdelay_response_mode =
   1072         bcmPortPhyTimesyncEventMessageEgressModeNone;
   1073     config.rx_pdelay_response_mode =
   1074         bcmPortPhyTimesyncEventMessageIngressModeNone;
   1075 
   1076 #if 0
   1077     config.gmode = bcmPortPhyTimesyncModeCpu;
   1078 #else
   1079     config.gmode = bcmPortPhyTimesyncModeFree;
   1080 #endif
   1081 
   1082     config.mpls_control.flags = BCM_PORT_PHY_TIMESYNC_MPLS_ENABLE
   1083         | BCM_PORT_PHY_TIMESYNC_MPLS_CONTROL_WORD_ENABLE;
   1084 
   1085     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1086 
   1087     if (rv != BCM_E_NONE) {
   1088         cli_out("bcm_port_phy_timesync_config_set failed "
   1089                 "with error  u=%d p=%d %s\n",
   1090                 unit, port, bcm_errmsg(rv));
   1091     }
   1092 
   1093     rv = bcm_port_control_phy_timesync_set(unit, port,
   1094                                            bcmPortControlPhyTimesyncLoadControl,
   1095                                            _compiler_64_arg(0,
   1096                                                             BCM_PORT_PHY_TIMESYNC_TIMECODE_LOAD));
   1097 
   1098     if (rv != BCM_E_NONE) {
   1099         cli_out("bcm_port_control_phy_timesync_set failed "
   1100                 "with error  u=%d p=%d %s\n",
   1101                 unit, port, bcm_errmsg(rv));
   1102     }
   1103     /* if(config.mpls_control.labels != NULL) {
   1104        sal_free(config.mpls_control.labels);
   1105        } */
   1106 }
   1107 
   1108 void
   1109 config_tc5p1_fs(int unit, bcm_port_t port, int arg1, int arg2)
   1110 {
   1111     int rv;
   1112     bcm_port_phy_timesync_config_t config;
   1113 
   1114     config.validity_mask =
   1115         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
   1116         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1117         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
   1118 
   1119     config.mpls_control.size = 1;
   1120     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
   1121        sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
   1122     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   1123 
   1124     if (rv != BCM_E_NONE) {
   1125         cli_out("bcm_port_phy_timesync_config_get failed "
   1126                 "with error u=%d p=%d %s\n",
   1127                 unit, port, bcm_errmsg(rv));
   1128     }
   1129 
   1130     config.flags |=
   1131         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1132         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1133         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
   1134 
   1135     config.syncout.interval = 0x00000080;
   1136     config.syncout.pulse_1_length = 0x0020;
   1137     config.syncout.pulse_2_length = 0x040;
   1138     config.syncout.syncout_ts = _compiler_64_arg(0, 80000);
   1139     config.syncout.mode = bcmPortPhyTimesyncSyncoutOneTime;
   1140     config.framesync.mode = bcmPortPhyTimesyncFramesyncCpu;
   1141     config.gmode = bcmPortPhyTimesyncModeCpu;
   1142 
   1143     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1144 
   1145     if (rv != BCM_E_NONE) {
   1146         cli_out("bcm_port_phy_timesync_config_set failed "
   1147                 "with error  u=%d p=%d %s\n",
   1148                 unit, port, bcm_errmsg(rv));
   1149     }
   1150 
   1151     rv = bcm_port_control_phy_timesync_set(unit, port,
   1152                                            bcmPortControlPhyTimesyncLoadControl,
   1153                                            _compiler_64_arg(0, 0xffffffff));
   1154 
   1155     rv = bcm_port_control_phy_timesync_set(unit, port,
   1156                                            bcmPortControlPhyTimesyncFrameSync,
   1157                                            _compiler_64_arg(0,
   1158                                                             bcmPortPhyTimesyncFramesyncSyncin0));
   1159 
   1160     if (rv != BCM_E_NONE) {
   1161         cli_out("bcm_port_control_phy_timesync_set failed "
   1162                 "with error  u=%d p=%d %s\n",
   1163                 unit, port, bcm_errmsg(rv));
   1164     }
   1165 
   1166     /* if(config.mpls_control.labels != NULL) {
   1167        sal_free(config.mpls_control.labels);
   1168        } */
   1169 }
   1170 
   1171 void
   1172 config_tc6p1_fs(int unit, bcm_port_t port, int arg1, int arg2)
   1173 {
   1174     int rv;
   1175     bcm_port_phy_timesync_config_t config;
   1176 
   1177     config.validity_mask =
   1178         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
   1179         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1180         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
   1181 
   1182     config.mpls_control.size = 1;
   1183     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
   1184        sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
   1185     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   1186 
   1187     if (rv != BCM_E_NONE) {
   1188         cli_out("bcm_port_phy_timesync_config_get failed "
   1189                 "with error u=%d p=%d %s\n",
   1190                 unit, port, bcm_errmsg(rv));
   1191     }
   1192 
   1193     config.flags |=
   1194         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1195         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1196         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
   1197 
   1198     config.syncout.interval = 0x00000080;
   1199     config.syncout.pulse_1_length = 0x0020;
   1200     config.syncout.pulse_2_length = 0x040;
   1201     config.syncout.syncout_ts = _compiler_64_arg(0, 80000);
   1202     config.syncout.mode = bcmPortPhyTimesyncSyncoutPulseTrain;
   1203     config.framesync.mode = bcmPortPhyTimesyncFramesyncCpu;
   1204     config.gmode = bcmPortPhyTimesyncModeCpu;
   1205 
   1206     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1207 
   1208     if (rv != BCM_E_NONE) {
   1209         cli_out("bcm_port_phy_timesync_config_set failed "
   1210                 "with error  u=%d p=%d %s\n",
   1211                 unit, port, bcm_errmsg(rv));
   1212     }
   1213 
   1214     rv = bcm_port_control_phy_timesync_set(unit, port,
   1215                                            bcmPortControlPhyTimesyncLoadControl,
   1216                                            _compiler_64_arg(0, 0xffffffff));
   1217 
   1218     rv = bcm_port_control_phy_timesync_set(unit, port,
   1219                                            bcmPortControlPhyTimesyncFrameSync,
   1220                                            _compiler_64_arg(0,
   1221                                                             bcmPortPhyTimesyncFramesyncSyncin0));
   1222 
   1223     if (rv != BCM_E_NONE) {
   1224         cli_out("bcm_port_control_phy_timesync_set failed "
   1225                 "with error  u=%d p=%d %s\n",
   1226                 unit, port, bcm_errmsg(rv));
   1227     }
   1228     /* if(config.mpls_control.labels != NULL) {
   1229        sal_free(config.mpls_control.labels);
   1230        } */
   1231 }
   1232 
   1233 void
   1234 config_tc7p1_fs(int unit, bcm_port_t port, int arg1, int arg2)
   1235 {
   1236     int rv;
   1237     bcm_port_phy_timesync_config_t config;
   1238 
   1239     config.validity_mask =
   1240         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
   1241         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1242         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
   1243 
   1244     config.mpls_control.size = 1;
   1245     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size * 
   1246        sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
   1247     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   1248 
   1249     if (rv != BCM_E_NONE) {
   1250         cli_out("bcm_port_phy_timesync_config_get failed "
   1251                 "with error u=%d p=%d %s\n",
   1252                 unit, port, bcm_errmsg(rv));
   1253     }
   1254 
   1255     config.flags |=
   1256         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1257         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1258         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
   1259 
   1260     config.syncout.interval = 0x00000080;
   1261     config.syncout.pulse_1_length = 0x0020;
   1262     config.syncout.pulse_2_length = 0x040;
   1263     config.syncout.syncout_ts = _compiler_64_arg(0, 80000);
   1264     config.syncout.mode = bcmPortPhyTimesyncSyncoutPulseTrainWithSync;
   1265     config.framesync.mode = bcmPortPhyTimesyncFramesyncCpu;
   1266     config.gmode = bcmPortPhyTimesyncModeCpu;
   1267 
   1268     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1269 
   1270     if (rv != BCM_E_NONE) {
   1271         cli_out("bcm_port_phy_timesync_config_set failed "
   1272                 "with error  u=%d p=%d %s\n",
   1273                 unit, port, bcm_errmsg(rv));
   1274     }
   1275 
   1276     rv = bcm_port_control_phy_timesync_set(unit, port,
   1277                                            bcmPortControlPhyTimesyncLoadControl,
   1278                                            _compiler_64_arg(0, 0xffffffff));
   1279 
   1280     rv = bcm_port_control_phy_timesync_set(unit, port,
   1281                                            bcmPortControlPhyTimesyncFrameSync,
   1282                                            _compiler_64_arg(0,
   1283                                                             bcmPortPhyTimesyncFramesyncSyncin0));
   1284 
   1285     if (rv != BCM_E_NONE) {
   1286         cli_out("bcm_port_control_phy_timesync_set failed "
   1287                 "with error  u=%d p=%d %s\n",
   1288                 unit, port, bcm_errmsg(rv));
   1289     }
   1290     /* if(config.mpls_control.labels != NULL) {
   1291        sal_free(config.mpls_control.labels);
   1292        } */
   1293 }
   1294 
   1295 void
   1296 config_tc8p1_fs(int unit, bcm_port_t port, int fs_mode, int fs_threshold, int arg3)
   1297 {
   1298     int rv;
   1299     bcm_port_phy_timesync_config_t config;
   1300 
   1301     config.validity_mask =
   1302         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
   1303         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1304         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE;
   1305 
   1306     config.mpls_control.size = 1;
   1307     /* config.mpls_control.labels = sal_alloc(config.mpls_control.size *
   1308        sizeof(_shr_port_phy_timesync_mpls_label_t), "timesync_mpls_label"); */
   1309     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   1310 
   1311     if (rv != BCM_E_NONE) {
   1312         cli_out("bcm_port_phy_timesync_config_get failed "
   1313                 "with error u=%d p=%d %s\n",
   1314                 unit, port, bcm_errmsg(rv));
   1315     }
   1316 
   1317     config.flags |=
   1318         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1319         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1320         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
   1321 
   1322     config.framesync.mode = fs_mode;       /* bcmPortPhyTimesyncFramesyncSyncin0; */
   1323     config.framesync.length_threshold = fs_threshold;   /* 20000; */
   1324     config.gmode = bcmPortPhyTimesyncModeCpu;
   1325 
   1326     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1327 
   1328     if (rv != BCM_E_NONE) {
   1329         cli_out("bcm_port_phy_timesync_config_set failed "
   1330                 "with error  u=%d p=%d %s\n",
   1331                 unit, port, bcm_errmsg(rv));
   1332     }
   1333 /*
   1334     rv = bcm_port_control_phy_timesync_set(unit, port,
   1335                                            bcmPortControlPhyTimesyncLoadControl,
   1336                                            _compiler_64_arg(0, 0xffffffff));
   1337 
   1338     if (rv != BCM_E_NONE) {
   1339         cli_out("bcm_port_control_phy_timesync_set failed "
   1340                 "with error  u=%d p=%d %s\n",
   1341                 unit, port, bcm_errmsg(rv));
   1342     }
   1343 */
   1344     /* if(config.mpls_control.labels != NULL) {
   1345        sal_free(config.mpls_control.labels);
   1346        } */
   1347 }
   1348 
   1349 void
   1350 cpu_sync(int unit, bcm_port_t port)
   1351 {
   1352     uint64 value;
   1353     int rv;
   1354 
   1355     rv = bcm_port_control_phy_timesync_set(unit, port,
   1356                                            bcmPortControlPhyTimesyncFrameSync,
   1357                                            _compiler_64_arg(0, 1));
   1358                                            /*_compiler_64_arg(0, 0x9));*/
   1359 
   1360     if (rv != BCM_E_NONE) {
   1361         cli_out("bcm_port_control_phy_timesync_set failed "
   1362                 "with error  u=%d p=%d %s\n",
   1363                 unit, port, bcm_errmsg(rv));
   1364     }
   1365 
   1366     rv = bcm_port_control_phy_timesync_get(unit, port,
   1367                                            bcmPortControlPhyTimesyncFrameSync,
   1368                                            &value);
   1369     cli_out("%s() u=%d p=%d FSmode=%08x:%08x\n", __func__,
   1370            unit, port, COMPILER_64_HI(value), COMPILER_64_LO(value));
   1371 }
   1372 
   1373 void
   1374 set_localtime(int unit, bcm_port_t port, uint64 localtime)
   1375 {
   1376     int rv;
   1377 
   1378     rv = bcm_port_control_phy_timesync_set(unit, port,
   1379                                            bcmPortControlPhyTimesyncLocalTime,
   1380                                            localtime);
   1381 
   1382     if (rv != BCM_E_NONE) {
   1383         cli_out("bcm_port_control_phy_timesync_set failed "
   1384                 "with error  u=%d p=%d %s\n",
   1385                 unit, port, bcm_errmsg(rv));
   1386     }
   1387 
   1388     rv = bcm_port_control_phy_timesync_set(unit, port,
   1389                                            bcmPortControlPhyTimesyncLoadControl,
   1390                                            _compiler_64_arg(0,
   1391                                                             BCM_PORT_PHY_TIMESYNC_LOCAL_TIME_LOAD));
   1392 
   1393     if (rv != BCM_E_NONE) {
   1394         cli_out("bcm_port_control_phy_timesync_set failed "
   1395                 "with error  u=%d p=%d %s\n",
   1396                 unit, port, bcm_errmsg(rv));
   1397     }
   1398 
   1399 }
   1400 
   1401 void
   1402 print_local_time(int unit, bcm_port_t port)
   1403 {
   1404     int rv;
   1405     uint64 time;
   1406 
   1407     rv = bcm_port_control_phy_timesync_get(unit, port,
   1408                                            bcmPortControlPhyTimesyncLocalTime,
   1409                                            &time);
   1410 
   1411     if (rv != BCM_E_NONE) {
   1412         cli_out("bcm_port_control_phy_timesync_get failed "
   1413                 "with error  u=%d p=%d %s\n",
   1414                 unit, port, bcm_errmsg(rv));
   1415     }
   1416 
   1417     cli_out("Current Local Time u=%d p=%d  Time = %08x%08x\n",
   1418             unit, port, COMPILER_64_HI(time), COMPILER_64_LO(time));
   1419 }
   1420 
   1421 void
   1422 test1588(int port1, int port2) /* , int fsmode) */
   1423 {
   1424 
   1425     config_i2e0_in(0, port1);
   1426     config_i2e0_out(0, port2);
   1427 
   1428     set_localtime(0, port1, _compiler_64_arg(0xabcdef33, 0x44556677));
   1429     set_localtime(0, port2, _compiler_64_arg(0xabcdef99, 0x44556688));
   1430     cpu_sync(0, port1);
   1431     cpu_sync(0, port2);
   1432 
   1433     print_local_time(0, port1);
   1434     print_local_time(0, port2);
   1435     _print_heartbeat_ts(0, port1);
   1436     _print_capture_ts(0, port1);
   1437     _print_heartbeat_ts(0, port2);
   1438     _print_capture_ts(0, port2);
   1439 }
   1440 
   1441 void
   1442 test1588_1(int port1, int port2)
   1443 {
   1444     config_i1e1_in(0, port1);
   1445     config_i1e1_out(0, port2);
   1446     cpu_sync(0, port1);
   1447     cpu_sync(0, port1);
   1448 }
   1449 
   1450 void
   1451 test1588_2(int port1, int port2)
   1452 {
   1453     config_i0e2_in(0, port1);
   1454     config_i0e2_out(0, port2);
   1455     cpu_sync(0, port1);
   1456     cpu_sync(0, port1);
   1457 }
   1458 
   1459 void
   1460 test1588_3(int port1, int port2)
   1461 {
   1462     config_i2e0_in(0, port1);
   1463     config_i2e0_out(0, port2);
   1464     cpu_sync(0, port1);
   1465     cpu_sync(0, port1);
   1466 }
   1467 
   1468 void
   1469 test1588_4(int port1, int port2)
   1470 {
   1471     config_i0e2_in(0, port1);
   1472     config_i0e2_in(0, port2);
   1473     cpu_sync(0, port1);
   1474     cpu_sync(0, port1);
   1475 }
   1476 
   1477 void
   1478 test1588_5(int port1, int arg1, int arg2)
   1479 {
   1480     config_tc5p1(0, port1, arg1, arg2);
   1481     cpu_sync(0, port1);
   1482 }
   1483 
   1484 void
   1485 test1588_6(int port1, int arg1, int arg2, int arg3)
   1486 {
   1487     config_syncout(0, port1, bcmPortPhyTimesyncSyncoutPulseTrain,
   1488                    arg1, arg2, arg3);
   1489     cpu_sync(0, port1);
   1490 }
   1491 
   1492 void
   1493 test1588_7(int port1, int arg1, int arg2)
   1494 {
   1495     config_tc7p1(0, port1, arg1, arg2);
   1496     cpu_sync(0, port1);
   1497 }
   1498 
   1499 void
   1500 test1588_8(int port1, int arg1, int arg2)
   1501 {
   1502     config_tc8p1(0, port1, arg1, arg2);
   1503     cpu_sync(0, port1);
   1504 }
   1505 
   1506 void
   1507 test1588_1_2(int port1, int port2)
   1508 {
   1509     config_i1e1_all_pkts_mpls1_en_in(0, port1);
   1510     config_i1e1_all_pkts_mpls1_en_out(0, port2);
   1511 }
   1512 
   1513 void
   1514 test1588_2_2(int port1, int port2)
   1515 {
   1516     config_i0e2_all_pkts_mpls1_en_in(0, port1);
   1517     config_i0e2_all_pkts_mpls1_en_out(0, port2);
   1518 }
   1519 
   1520 void
   1521 test1588_3_2(int port1, int port2)
   1522 {
   1523     config_i2e0_all_pkts_mpls1_en_in(0, port1);
   1524     config_i2e0_all_pkts_mpls1_en_out(0, port2);
   1525 }
   1526 
   1527 void
   1528 test1588_4_2(int port1, int port2)
   1529 {
   1530     config_i0e2_all_pkts_mpls1_en_in(0, port1);
   1531     config_i0e2_all_pkts_mpls1_en_in(0, port2);
   1532 }
   1533 
   1534 /*
   1535 void
   1536 test1588_5_2(int port1)
   1537 {
   1538     config_tc5p1_fs(0, port1);
   1539 }
   1540 
   1541 void
   1542 test1588_6_2(int port1)
   1543 {
   1544     config_tc6p1_fs(0, port1);
   1545 }
   1546 
   1547 void
   1548 test1588_7_2(int port1)
   1549 {
   1550     config_tc7p1_fs(0, port1);
   1551 }
   1552 */
   1553 
   1554 void
   1555 test1588_8_2(int port1, int arg1, int arg2, int arg3)
   1556 {
   1557     config_tc8p1_fs(0, port1, arg1, arg2, arg3);
   1558 }
   1559 
   1560 void
   1561 config_fs_test(int unit, bcm_port_t port)
   1562 {
   1563     int rv;
   1564     bcm_port_phy_timesync_config_t config;
   1565     uint64 time, temp;
   1566 
   1567     config.validity_mask =
   1568         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS | BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1569         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE;
   1570 
   1571     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   1572 
   1573     if (rv != BCM_E_NONE) {
   1574         cli_out("bcm_port_phy_timesync_config_get failed "
   1575                 "with error u=%d p=%d %s\n",
   1576                 unit, port, bcm_errmsg(rv));
   1577     }
   1578 
   1579     config.flags |=
   1580         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1581         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1582         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
   1583 
   1584     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1585 
   1586     if (rv != BCM_E_NONE) {
   1587         cli_out("bcm_port_phy_timesync_config_set failed "
   1588                 "with error  u=%d p=%d %s\n",
   1589                 unit, port, bcm_errmsg(rv));
   1590     }
   1591 
   1592     rv = bcm_port_control_phy_timesync_set(unit, port,
   1593                                            bcmPortControlPhyTimesyncFrameSync,
   1594                                            _compiler_64_arg(0, 1));
   1595 
   1596     if (rv != BCM_E_NONE) {
   1597         cli_out("bcm_port_control_phy_timesync_set failed "
   1598                 "with error  u=%d p=%d %s\n",
   1599                 unit, port, bcm_errmsg(rv));
   1600     }
   1601 
   1602     rv = bcm_port_control_phy_timesync_get(unit, port,
   1603                                            bcmPortControlPhyTimesyncHeartbeatTimestamp,
   1604                                            &time);
   1605 
   1606     if (rv != BCM_E_NONE) {
   1607         cli_out("bcm_port_control_phy_timesync_get failed "
   1608                 "with error  u=%d p=%d %s\n",
   1609                 unit, port, bcm_errmsg(rv));
   1610     }
   1611 
   1612     cli_out("Heartbeat TS = %08x%08x\n",
   1613             COMPILER_64_HI(time), COMPILER_64_LO(time));
   1614 
   1615     /* Add delta of 4.3 sec */
   1616     temp = _compiler_64_arg(0x1, 0);
   1617     COMPILER_64_ADD_64(time, temp);
   1618     config.syncout.syncout_ts = time;
   1619 
   1620     cli_out("Syncout   TS = %08x%08x\n",
   1621             COMPILER_64_HI(config.syncout.syncout_ts),
   1622             COMPILER_64_LO(config.syncout.syncout_ts));
   1623 
   1624     config.syncout.interval = 0x00000080;
   1625     config.syncout.pulse_1_length = 25000;
   1626     config.syncout.pulse_2_length = 0x040;
   1627     config.syncout.mode = bcmPortPhyTimesyncSyncoutOneTime;
   1628     config.gmode = bcmPortPhyTimesyncModeCpu;
   1629     config.framesync.mode = bcmPortPhyTimesyncFramesyncSyncin0;
   1630     config.framesync.length_threshold = 20000;
   1631 
   1632     config.validity_mask =
   1633         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1634         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
   1635         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
   1636 
   1637     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1638 
   1639     if (rv != BCM_E_NONE) {
   1640         cli_out("bcm_port_phy_timesync_config_set failed "
   1641                 "with error  u=%d p=%d %s\n",
   1642                 unit, port, bcm_errmsg(rv));
   1643     }
   1644 
   1645     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1646 
   1647     if (rv != BCM_E_NONE) {
   1648         cli_out("bcm_port_phy_timesync_config_set failed "
   1649                 "with error  u=%d p=%d %s\n",
   1650                 unit, port, bcm_errmsg(rv));
   1651     }
   1652 
   1653     rv = bcm_port_control_phy_timesync_set(unit, port,
   1654                                            bcmPortControlPhyTimesyncLoadControl,
   1655                                            _compiler_64_arg(0,
   1656                                                             BCM_PORT_PHY_TIMESYNC_SYNCOUT_LOAD));
   1657 
   1658     if (rv != BCM_E_NONE) {
   1659         cli_out("bcm_port_control_phy_timesync_set failed with error  u=%d p=%d %s\n",
   1660                 unit, port, bcm_errmsg(rv));
   1661     }
   1662 
   1663     rv = bcm_port_control_phy_timesync_set(unit, port,
   1664                                            bcmPortControlPhyTimesyncFrameSync,
   1665                                            _compiler_64_arg(0, 1));
   1666 
   1667     if (rv != BCM_E_NONE) {
   1668         cli_out("bcm_port_control_phy_timesync_set failed with error  u=%d p=%d %s\n",
   1669                 unit, port, bcm_errmsg(rv));
   1670     }
   1671 
   1672     rv = bcm_port_control_phy_timesync_get(unit, port,
   1673                                            bcmPortControlPhyTimesyncHeartbeatTimestamp,
   1674                                            &time);
   1675 
   1676     if (rv != BCM_E_NONE) {
   1677         cli_out("bcm_port_control_phy_timesync_get failed with error  u=%d p=%d %s\n",
   1678                 unit, port, bcm_errmsg(rv));
   1679     }
   1680 
   1681     cli_out("Heartbeat TS = %08x%08x\n",
   1682             COMPILER_64_HI(time), COMPILER_64_LO(time));
   1683 
   1684     sal_usleep(5000000);
   1685 
   1686     rv = bcm_port_control_phy_timesync_set(unit, port,
   1687                                            bcmPortControlPhyTimesyncFrameSync,
   1688                                            _compiler_64_arg(0, 1));
   1689 
   1690     if (rv != BCM_E_NONE) {
   1691         cli_out("bcm_port_control_phy_timesync_set failed "
   1692                 "with error  u=%d p=%d %s\n",
   1693                 unit, port, bcm_errmsg(rv));
   1694     }
   1695 
   1696     rv = bcm_port_control_phy_timesync_get(unit, port,
   1697                                            bcmPortControlPhyTimesyncHeartbeatTimestamp,
   1698                                            &time);
   1699 
   1700     if (rv != BCM_E_NONE) {
   1701         cli_out("bcm_port_control_phy_timesync_get failed "
   1702                 "with error  u=%d p=%d %s\n",
   1703                 unit, port, bcm_errmsg(rv));
   1704     }
   1705 
   1706     cli_out("Heartbeat TS = %08x%08x\n",
   1707             COMPILER_64_HI(time), COMPILER_64_LO(time));
   1708 
   1709 #if 0
   1710     config.validity_mask =
   1711         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS | BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1712         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
   1713 
   1714     config.mpls_control.size = 1;
   1715     config.mpls_control.labels =
   1716         sal_alloc(config.mpls_control.size *
   1717                   sizeof(_shr_port_phy_timesync_mpls_label_t),
   1718                   "timesync_mpls_label");
   1719     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   1720 
   1721     if (rv != BCM_E_NONE) {
   1722         cli_out("bcm_port_phy_timesync_config_get failed "
   1723                 "with error u=%d p=%d %s\n",
   1724                 unit, port, bcm_errmsg(rv));
   1725     }
   1726 
   1727     config.flags |=
   1728         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1729         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1730         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE;
   1731 
   1732     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1733 
   1734     if (rv != BCM_E_NONE) {
   1735         cli_out("bcm_port_phy_timesync_config_set failed "
   1736                 "with error  u=%d p=%d %s\n",
   1737                 unit, port, bcm_errmsg(rv));
   1738     }
   1739 
   1740     rv = bcm_port_control_phy_timesync_set(unit, port,
   1741                                            bcmPortControlPhyTimesyncLoadControl,
   1742                                            _compiler_64_arg(0, 0xffffffff));
   1743 
   1744     rv = bcm_port_control_phy_timesync_set(unit, port,
   1745                                            bcmPortControlPhyTimesyncFrameSync,
   1746                                            _compiler_64_arg(0,
   1747                                                             bcmPortPhyTimesyncFramesyncSyncin0));
   1748 
   1749     if (rv != BCM_E_NONE) {
   1750         cli_out("bcm_port_control_phy_timesync_set failed "
   1751                 "with error  u=%d p=%d %s\n",
   1752                 unit, port, bcm_errmsg(rv));
   1753     }
   1754 
   1755     if (config.mpls_control.labels != NULL) {
   1756         sal_free(config.mpls_control.labels);
   1757     }
   1758 #endif
   1759 }
   1760 
   1761 void
   1762 config_dpll_sync(int unit, bcm_port_t port,
   1763                  uint32 ref_phz_d, uint32 k1, uint32 k2, uint32 k3)
   1764 {
   1765     int rv;
   1766     bcm_port_phy_timesync_config_t config;
   1767     sal_memset(&config, 0, sizeof(config));
   1768 
   1769     config.validity_mask =
   1770         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
   1771         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1772         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
   1773         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
   1774         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
   1775         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE |
   1776         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE |
   1777         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE_DELTA |
   1778         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K1 |
   1779         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K2 |
   1780         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K3;
   1781 
   1782     config.flags =
   1783         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1784         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1785         BCM_PORT_PHY_TIMESYNC_L2_ENABLE |
   1786         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE |
   1787         BCM_PORT_PHY_TIMESYNC_CLOCK_SRC_EXT;
   1788 
   1789     config.gmode = bcmPortPhyTimesyncModeCpu;
   1790     config.framesync.mode = bcmPortPhyTimesyncFramesyncSyncin1;
   1791     config.syncout.mode = bcmPortPhyTimesyncSyncoutDisable;
   1792     config.tx_sync_mode =
   1793         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
   1794     config.rx_sync_mode =
   1795         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
   1796     /* for 1KHz SyncIn */
   1797     config.phy_1588_dpll_ref_phase       = _compiler_64_arg(0, 0);
   1798     config.phy_1588_dpll_ref_phase_delta = ref_phz_d;
   1799     config.phy_1588_dpll_k1              = k1;
   1800     config.phy_1588_dpll_k2              = k2;
   1801     config.phy_1588_dpll_k3              = k3;
   1802 
   1803     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1804     if (rv != BCM_E_NONE) {
   1805         cli_out("bcm_port_phy_timesync_config_set failed "
   1806                 "with error  u=%d p=%d %s\n",
   1807                 unit, port, bcm_errmsg(rv));
   1808     }
   1809 
   1810     rv = bcm_port_control_phy_timesync_set( unit, port,
   1811                bcmPortControlPhyTimesyncLocalTime,
   1812                _compiler_64_arg(0x0, 0x0) );
   1813 
   1814     /* Shadow Register Load ,  do NOT set  LOCAL_TIME_ALWAYS_LOAD */
   1815     rv = bcm_port_control_phy_timesync_set( unit, port, 
   1816                bcmPortControlPhyTimesyncLoadControl,
   1817                _compiler_64_arg(0,
   1818                         BCM_PORT_PHY_TIMESYNC_LOCAL_TIME_LOAD |
   1819                         BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_LOAD |
   1820                         BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_ALWAYS_LOAD |
   1821                         BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_DELTA_LOAD |
   1822                         BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_DELTA_ALWAYS_LOAD |
   1823                         BCM_PORT_PHY_TIMESYNC_DPLL_K3_LOAD |
   1824                         BCM_PORT_PHY_TIMESYNC_DPLL_K3_ALWAYS_LOAD |
   1825                         BCM_PORT_PHY_TIMESYNC_DPLL_K2_LOAD |
   1826                         BCM_PORT_PHY_TIMESYNC_DPLL_K2_ALWAYS_LOAD |
   1827                         BCM_PORT_PHY_TIMESYNC_DPLL_K1_LOAD |
   1828                         BCM_PORT_PHY_TIMESYNC_DPLL_K1_ALWAYS_LOAD) );
   1829     if (rv != BCM_E_NONE) {
   1830         cli_out("bcm_port_control_phy_timesync_set failed "
   1831                 "with error  u=%d p=%d %s\n",
   1832                 unit, port, bcm_errmsg(rv));
   1833     }
   1834 }
   1835 
   1836 void
   1837 config_port_sync_4k(int unit, bcm_port_t port)
   1838 {
   1839     int rv;
   1840     bcm_port_phy_timesync_config_t config;
   1841 
   1842     sal_memset(&config, 0, sizeof(config));
   1843 
   1844     config.validity_mask =
   1845         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS |
   1846         BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1847         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
   1848         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
   1849         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
   1850         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE |
   1851         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE |
   1852         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE_DELTA |
   1853         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K1 |
   1854         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K2 |
   1855         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K3;
   1856 
   1857     config.flags =
   1858         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1859         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1860         BCM_PORT_PHY_TIMESYNC_L2_ENABLE |
   1861         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE |
   1862         BCM_PORT_PHY_TIMESYNC_CLOCK_SRC_EXT;
   1863 
   1864     config.gmode = bcmPortPhyTimesyncModeCpu;
   1865     config.framesync.mode = bcmPortPhyTimesyncFramesyncSyncin1;
   1866     config.syncout.mode = bcmPortPhyTimesyncSyncoutDisable;
   1867     config.tx_sync_mode =
   1868         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
   1869     config.rx_sync_mode =
   1870         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
   1871     /* for 4KHz SyncIn */
   1872     config.phy_1588_dpll_ref_phase = _compiler_64_arg(0, 0);
   1873     config.phy_1588_dpll_ref_phase_delta = 0x0003d090;
   1874     config.phy_1588_dpll_k1 = 0x2a;
   1875     config.phy_1588_dpll_k2 = 0x26;
   1876     config.phy_1588_dpll_k3 = 0;
   1877 
   1878     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1879 
   1880     if (rv != BCM_E_NONE) {
   1881         cli_out("bcm_port_phy_timesync_config_set failed "
   1882                 "with error  u=%d p=%d %s\n",
   1883                 unit, port, bcm_errmsg(rv));
   1884     }
   1885 
   1886     rv = bcm_port_control_phy_timesync_set(unit, port,
   1887                                            bcmPortControlPhyTimesyncLocalTime,
   1888                                            _compiler_64_arg(0x0, 0x0));
   1889     if (rv != BCM_E_NONE) {
   1890         cli_out("bcm_port_control_phy_timesync_set failed "
   1891                 "with error  u=%d p=%d %s\n",
   1892                 unit, port, bcm_errmsg(rv));
   1893     }
   1894 
   1895     rv = bcm_port_control_phy_timesync_set(unit, port,
   1896                                            bcmPortControlPhyTimesyncLoadControl,
   1897                                            _compiler_64_arg(0,
   1898                                            BCM_PORT_PHY_TIMESYNC_LOCAL_TIME_LOAD |
   1899                                            BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_LOAD |
   1900                                            BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_DELTA_LOAD |
   1901                                            BCM_PORT_PHY_TIMESYNC_DPLL_K3_LOAD |
   1902                                            BCM_PORT_PHY_TIMESYNC_DPLL_K2_LOAD |
   1903                                            BCM_PORT_PHY_TIMESYNC_DPLL_K1_LOAD));
   1904     if (rv != BCM_E_NONE) {
   1905         cli_out("bcm_port_control_phy_timesync_set failed "
   1906                 "with error  u=%d p=%d %s\n",
   1907                 unit, port, bcm_errmsg(rv));
   1908     }
   1909 }
   1910 
   1911 void
   1912 config_port_sync_12_5m(int unit, bcm_port_t port)
   1913 {
   1914     int rv;
   1915     bcm_port_phy_timesync_config_t config;
   1916 
   1917     sal_memset(&config, 0, sizeof(config));
   1918 
   1919     config.validity_mask =
   1920         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS | BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1921         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
   1922         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
   1923         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
   1924         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE |
   1925         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE |
   1926         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE_DELTA |
   1927         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K1 |
   1928         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K2 |
   1929         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K3;
   1930 
   1931     config.flags =
   1932         BCM_PORT_PHY_TIMESYNC_ENABLE |
   1933         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   1934         BCM_PORT_PHY_TIMESYNC_L2_ENABLE |
   1935         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE |
   1936         BCM_PORT_PHY_TIMESYNC_CLOCK_SRC_EXT;
   1937 
   1938     config.gmode = bcmPortPhyTimesyncModeCpu;
   1939     config.framesync.mode = bcmPortPhyTimesyncFramesyncSyncin1;
   1940     config.syncout.mode = bcmPortPhyTimesyncSyncoutDisable;
   1941     config.tx_sync_mode =
   1942         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
   1943     config.rx_sync_mode =
   1944         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
   1945     /* for 12.5MHz SyncIn */
   1946     config.phy_1588_dpll_ref_phase = _compiler_64_arg(0, 0);
   1947     config.phy_1588_dpll_ref_phase_delta = 80;
   1948     config.phy_1588_dpll_k1 = 43;
   1949     config.phy_1588_dpll_k2 = 27;
   1950     config.phy_1588_dpll_k3 = 0;
   1951 
   1952     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   1953 
   1954     if (rv != BCM_E_NONE) {
   1955         cli_out("bcm_port_phy_timesync_config_set failed "
   1956                 "with error  u=%d p=%d %s\n",
   1957                 unit, port, bcm_errmsg(rv));
   1958     }
   1959 
   1960     rv = bcm_port_control_phy_timesync_set(unit, port,
   1961                                            bcmPortControlPhyTimesyncLocalTime,
   1962                                            _compiler_64_arg(0x0, 0x0));
   1963 
   1964     if (rv != BCM_E_NONE) {
   1965         cli_out("bcm_port_control_phy_timesync_set failed "
   1966                 "with error  u=%d p=%d %s\n",
   1967                 unit, port, bcm_errmsg(rv));
   1968     }
   1969 
   1970     rv = bcm_port_control_phy_timesync_set(unit, port,
   1971                                            bcmPortControlPhyTimesyncLoadControl,
   1972                                            _compiler_64_arg(0,
   1973                                                             BCM_PORT_PHY_TIMESYNC_LOCAL_TIME_LOAD |
   1974                                                             BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_LOAD |
   1975                                                             BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_DELTA_LOAD |
   1976                                                             BCM_PORT_PHY_TIMESYNC_DPLL_K3_LOAD |
   1977                                                             BCM_PORT_PHY_TIMESYNC_DPLL_K2_LOAD |
   1978                                                             BCM_PORT_PHY_TIMESYNC_DPLL_K1_LOAD));
   1979 
   1980     if (rv != BCM_E_NONE) {
   1981         cli_out("bcm_port_control_phy_timesync_set failed "
   1982                 "with error  u=%d p=%d %s\n",
   1983                 unit, port, bcm_errmsg(rv));
   1984     }
   1985 
   1986 }
   1987 
   1988 void
   1989 config_port_syncout_1k(int unit, bcm_port_t port, int mode)
   1990 {
   1991     int rv;
   1992     bcm_port_phy_timesync_config_t config;
   1993 
   1994     sal_memset(&config, 0, sizeof(config));
   1995 
   1996     config.validity_mask =
   1997         BCM_PORT_PHY_TIMESYNC_VALID_FLAGS | BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   1998         BCM_PORT_PHY_TIMESYNC_VALID_TX_SYNC_MODE |
   1999         BCM_PORT_PHY_TIMESYNC_VALID_RX_SYNC_MODE |
   2000         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
   2001         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE |
   2002         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE |
   2003         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_REF_PHASE_DELTA |
   2004         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K1 |
   2005         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K2 |
   2006         BCM_PORT_PHY_TIMESYNC_VALID_PHY_1588_DPLL_K3;
   2007 
   2008     config.flags =
   2009         BCM_PORT_PHY_TIMESYNC_ENABLE |
   2010         BCM_PORT_PHY_TIMESYNC_HEARTBEAT_TS_ENABLE |
   2011         BCM_PORT_PHY_TIMESYNC_L2_ENABLE |
   2012         BCM_PORT_PHY_TIMESYNC_CAPTURE_TS_ENABLE |
   2013         BCM_PORT_PHY_TIMESYNC_CLOCK_SRC_EXT;
   2014 
   2015     rv = bcm_port_control_phy_timesync_set(unit, port,
   2016                                            bcmPortControlPhyTimesyncLocalTime,
   2017                                            _compiler_64_arg(0xa33, 0x44556677));
   2018 
   2019     if (rv != BCM_E_NONE) {
   2020         cli_out("bcm_port_control_phy_timesync_set failed "
   2021                 "with error  u=%d p=%d %s\n",
   2022                 unit, port, bcm_errmsg(rv));
   2023     }
   2024 
   2025     config.syncout.syncout_ts = _compiler_64_arg(0x1, 0x00000000);
   2026     config.syncout.interval = 25000;
   2027     config.syncout.pulse_1_length = 0x800;
   2028     config.syncout.pulse_2_length = 0x400;
   2029 
   2030     config.gmode = bcmPortPhyTimesyncModeFree;
   2031     config.framesync.mode = bcmPortPhyTimesyncFramesyncNone;
   2032 
   2033     config.syncout.mode = bcmPortPhyTimesyncSyncoutDisable;
   2034     config.tx_sync_mode =
   2035         bcmPortPhyTimesyncEventMessageEgressModeUpdateCorrectionField;
   2036     config.rx_sync_mode =
   2037         bcmPortPhyTimesyncEventMessageIngressModeUpdateCorrectionField;
   2038 
   2039     /* for 1KHz SyncIn */
   2040     config.phy_1588_dpll_ref_phase = _compiler_64_arg(0, 0);
   2041     config.phy_1588_dpll_ref_phase_delta = 0x000f4240;
   2042     config.phy_1588_dpll_k1 = 0x2a;
   2043     config.phy_1588_dpll_k2 = 0x28;
   2044     config.phy_1588_dpll_k3 = 0;
   2045 
   2046     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   2047 
   2048     if (rv != BCM_E_NONE) {
   2049         cli_out("bcm_port_phy_timesync_config_set failed "
   2050                 "with error  u=%d p=%d %s\n",
   2051                 unit, port, bcm_errmsg(rv));
   2052     }
   2053 
   2054     rv = bcm_port_control_phy_timesync_set(unit, port,
   2055                                            bcmPortControlPhyTimesyncLoadControl,
   2056                                            _compiler_64_arg(0,
   2057                                                             BCM_PORT_PHY_TIMESYNC_TN_LOAD |
   2058                                                             BCM_PORT_PHY_TIMESYNC_TIMECODE_LOAD |
   2059                                                             BCM_PORT_PHY_TIMESYNC_SYNCOUT_LOAD |
   2060                                                             BCM_PORT_PHY_TIMESYNC_LOCAL_TIME_LOAD |
   2061                                                             BCM_PORT_PHY_TIMESYNC_NCO_DIVIDER_LOAD |
   2062                                                             BCM_PORT_PHY_TIMESYNC_NCO_ADDEND_LOAD |
   2063                                                             BCM_PORT_PHY_TIMESYNC_DPLL_LOOP_FILTER_LOAD |
   2064                                                             BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_LOAD |
   2065                                                             BCM_PORT_PHY_TIMESYNC_DPLL_REF_PHASE_DELTA_LOAD |
   2066                                                             BCM_PORT_PHY_TIMESYNC_DPLL_K3_LOAD |
   2067                                                             BCM_PORT_PHY_TIMESYNC_DPLL_K2_LOAD |
   2068                                                             BCM_PORT_PHY_TIMESYNC_DPLL_K1_LOAD));
   2069 
   2070     if (rv != BCM_E_NONE) {
   2071         cli_out("bcm_port_control_phy_timesync_set failed "
   2072                 "with error  u=%d p=%d %s\n",
   2073                 unit, port, bcm_errmsg(rv));
   2074     }
   2075 
   2076     rv = bcm_port_control_phy_timesync_set(unit, port,
   2077                                            bcmPortControlPhyTimesyncFrameSync,
   2078                                            _compiler_64_arg(0, 1));
   2079 
   2080     if (rv != BCM_E_NONE) {
   2081         cli_out("bcm_port_control_phy_timesync_set failed "
   2082                 "with error  u=%d p=%d %s\n",
   2083                 unit, port, bcm_errmsg(rv));
   2084     }
   2085 
   2086     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_GMODE |
   2087         BCM_PORT_PHY_TIMESYNC_VALID_FRAMESYNC_MODE |
   2088         BCM_PORT_PHY_TIMESYNC_VALID_SYNCOUT_MODE;
   2089 
   2090     config.gmode = bcmPortPhyTimesyncModeCpu;
   2091     config.framesync.mode = bcmPortPhyTimesyncFramesyncNone;
   2092 
   2093     if (mode == 3) {
   2094         config.syncout.mode = bcmPortPhyTimesyncSyncoutPulseTrainWithSync;
   2095     } else if (mode == 2) {
   2096         config.syncout.mode = bcmPortPhyTimesyncSyncoutPulseTrain;
   2097     } else {
   2098         config.syncout.mode = bcmPortPhyTimesyncSyncoutOneTime;
   2099     }
   2100 
   2101     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   2102 
   2103     if (rv != BCM_E_NONE) {
   2104         cli_out("bcm_port_phy_timesync_config_set failed "
   2105                 "with error  u=%d p=%d %s\n",
   2106                 unit, port, bcm_errmsg(rv));
   2107     }
   2108 
   2109 }
   2110 
   2111 void
   2112 sync_clock_1k(int port1)
   2113 {
   2114     /* config_port_sync_1k(0, port1); */
   2115     config_dpll_sync(0, port1, 0xf4240, 0x2a, 0x28, 0);
   2116 
   2117     print_local_time(0, port1);
   2118     _print_heartbeat_ts(0, port1);
   2119     _print_capture_ts(0, port1);
   2120 }
   2121 
   2122 void
   2123 sync_clock_4k(int port1)
   2124 {
   2125     config_port_sync_4k(0, port1);
   2126 
   2127     print_local_time(0, port1);
   2128     _print_heartbeat_ts(0, port1);
   2129     _print_capture_ts(0, port1);
   2130 }
   2131 
   2132 void
   2133 sync_clock_12_5m(int port1)
   2134 {
   2135     config_port_sync_12_5m(0, port1);
   2136 
   2137     print_local_time(0, port1);
   2138     _print_heartbeat_ts(0, port1);
   2139     _print_capture_ts(0, port1);
   2140 }
   2141 
   2142 void
   2143 config_inband_ts_tc_ip_cap(int unit, bcm_port_t port)
   2144 {
   2145     int rv;
   2146     bcm_port_phy_timesync_config_t config;
   2147 
   2148     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS;
   2149 
   2150     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   2151 
   2152     if (rv != BCM_E_NONE) {
   2153         cli_out("bcm_port_phy_timesync_config_get failed "
   2154                 "with error u=%d p=%d %s\n",
   2155                 unit, port, bcm_errmsg(rv));
   2156     }
   2157 
   2158     config.inband_ts_control.flags =
   2159         BCM_PORT_PHY_TIMESYNC_INBAND_TS_RESV0_ID_CHECK |
   2160         BCM_PORT_PHY_TIMESYNC_INBAND_TS_SYNC_ENABLE |
   2161         BCM_PORT_PHY_TIMESYNC_INBAND_TS_DELAY_RQ_ENABLE |
   2162         BCM_PORT_PHY_TIMESYNC_INBAND_TS_PDELAY_RQ_ENABLE |
   2163         BCM_PORT_PHY_TIMESYNC_INBAND_TS_PDELAY_RESP_ENABLE;
   2164     config.inband_ts_control.resv0_id = 0xf000 | port;
   2165 
   2166     config.flags |= BCM_PORT_PHY_TIMESYNC_ENABLE;
   2167 
   2168     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   2169 
   2170     if (rv != BCM_E_NONE) {
   2171         cli_out("bcm_port_phy_timesync_config_set failed "
   2172                 "with error  u=%d p=%d %s\n",
   2173                 unit, port, bcm_errmsg(rv));
   2174     }
   2175 }
   2176 
   2177 void
   2178 config_inband_ts_tc_da_cap(int unit, bcm_port_t port)
   2179 {
   2180     int rv;
   2181     bcm_port_phy_timesync_config_t config;
   2182 
   2183     config.validity_mask = BCM_PORT_PHY_TIMESYNC_VALID_FLAGS;
   2184 
   2185     rv = bcm_port_phy_timesync_config_get(unit, port, &config);
   2186 
   2187     if (rv != BCM_E_NONE) {
   2188         cli_out("bcm_port_phy_timesync_config_get failed "
   2189                 "with error u=%d p=%d %s\n",
   2190                 unit, port, bcm_errmsg(rv));
   2191     }
   2192 
   2193     config.inband_ts_control.flags =
   2194         BCM_PORT_PHY_TIMESYNC_INBAND_TS_RESV0_ID_CHECK |
   2195         BCM_PORT_PHY_TIMESYNC_INBAND_TS_SYNC_ENABLE |
   2196         BCM_PORT_PHY_TIMESYNC_INBAND_TS_DELAY_RQ_ENABLE |
   2197         BCM_PORT_PHY_TIMESYNC_INBAND_TS_PDELAY_RQ_ENABLE |
   2198         BCM_PORT_PHY_TIMESYNC_INBAND_TS_PDELAY_RESP_ENABLE |
   2199         BCM_PORT_PHY_TIMESYNC_INBAND_TS_MATCH_MAC_ADDR;
   2200     config.inband_ts_control.resv0_id = 0xf000 | port;
   2201 
   2202     config.flags |= BCM_PORT_PHY_TIMESYNC_ENABLE;
   2203 
   2204     rv = bcm_port_phy_timesync_config_set(unit, port, &config);
   2205 
   2206     if (rv != BCM_E_NONE) {
   2207         cli_out("bcm_port_phy_timesync_config_set failed "
   2208                 "with error  u=%d p=%d %s\n",
   2209                 unit, port, bcm_errmsg(rv));
   2210     }
   2211 }
   2212 
   2213 /* PHY OAM tests */
   2214 
   2215 /* Y.1731 */
   2216 void
   2217 phy_oam_y1731_rx(int unit, int port)
   2218 {
   2219     int rv;
   2220     bcm_port_config_phy_oam_t config;
   2221 
   2222     sal_memset(&config, 0, sizeof(soc_port_config_phy_oam_t));
   2223 
   2224     config.rx_dm_config.flags = 0;
   2225     config.rx_dm_config.mode = bcmPortConfigPhyOamDmModeY1731;
   2226     rv = bcm_port_config_phy_oam_set(unit, port, &config);
   2227     if (rv != BCM_E_NONE) {
   2228         cli_out("bcm_port_config_phy_oam_set failed with error  u=%d p=%d %s\n",
   2229                 unit, port, bcm_errmsg(rv));
   2230     }
   2231 
   2232     rv = bcm_port_control_phy_oam_set(unit, port,
   2233                                       bcmPortControlPhyOamDmMacAddress1,
   2234                                       _compiler_64_arg(0x00000000, 0x00000100));
   2235     if (rv != BCM_E_NONE) {
   2236         cli_out("bcm_port_control_phy_oam_set failed "
   2237                 "with error  u=%d p=%d (type %d)%s\n",
   2238                 unit, port, bcmPortControlPhyOamDmMacAddress1, bcm_errmsg(rv));
   2239     }
   2240 
   2241     rv = bcm_port_control_phy_oam_set(unit, port,
   2242                                       bcmPortControlPhyOamDmRxPortMacAddressIndex,
   2243                                       _compiler_64_arg(0, 0x1));
   2244     if (rv != BCM_E_NONE) {
   2245         cli_out("bcm_port_control_phy_oam_set failed "
   2246                 "with error  u=%d p=%d (type %d) %s\n",
   2247                 unit, port, bcmPortControlPhyOamDmRxPortMacAddressIndex,
   2248                 bcm_errmsg(rv));
   2249     }
   2250 }
   2251 
   2252 void
   2253 phy_oam_y1731_tx(int unit, int port)
   2254 {
   2255     int rv;
   2256     bcm_port_config_phy_oam_t config;
   2257 
   2258     sal_memset(&config, 0, sizeof(soc_port_config_phy_oam_t));
   2259 
   2260     config.tx_dm_config.flags = 0;
   2261     config.tx_dm_config.mode = bcmPortConfigPhyOamDmModeY1731;
   2262     rv = bcm_port_config_phy_oam_set(unit, port, &config);
   2263     if (rv != BCM_E_NONE) {
   2264         cli_out("bcm_port_config_phy_oam_set failed with error  u=%d p=%d %s\n",
   2265                 unit, port, bcm_errmsg(rv));
   2266     }
   2267 
   2268     rv = bcm_port_control_phy_oam_set(unit, port,
   2269                                       bcmPortControlPhyOamDmMacAddress1,
   2270                                       _compiler_64_arg(0x0000a000, 0x00000100));
   2271     if (rv != BCM_E_NONE) {
   2272         cli_out("bcm_port_control_phy_oam_set failed "
   2273                 "with error  u=%d p=%d (type %d)%s\n",
   2274                 unit, port, bcmPortControlPhyOamDmMacAddress1, bcm_errmsg(rv));
   2275     }
   2276 
   2277     rv = bcm_port_control_phy_oam_set(unit, port,
   2278                                       bcmPortControlPhyOamDmTxPortMacAddressIndex,
   2279                                       _compiler_64_arg(0, 0x1));
   2280     if (rv != BCM_E_NONE) {
   2281         cli_out("bcm_port_control_phy_oam_set failed "
   2282                 "with error  u=%d p=%d (type %d) %s\n",
   2283                 unit, port, bcmPortControlPhyOamDmTxPortMacAddressIndex,
   2284                 bcm_errmsg(rv));
   2285     }
   2286 }
   2287 
   2288 void
   2289 phy_oam_y1731_mac_da_rx(int unit, int port)
   2290 {
   2291     int rv;
   2292     bcm_port_config_phy_oam_t config;
   2293 
   2294     sal_memset(&config, 0, sizeof(soc_port_config_phy_oam_t));
   2295 
   2296     config.rx_dm_config.flags = BCM_PORT_PHY_OAM_DM_MAC_CHECK_ENABLE;
   2297     config.rx_dm_config.mode = bcmPortConfigPhyOamDmModeY1731;
   2298     rv = bcm_port_config_phy_oam_set(unit, port, &config);
   2299     if (rv != BCM_E_NONE) {
   2300         cli_out("bcm_port_config_phy_oam_set failed with error  u=%d p=%d %s\n",
   2301                 unit, port, bcm_errmsg(rv));
   2302     }
   2303 
   2304     rv = bcm_port_control_phy_oam_set(unit, port,
   2305                                       bcmPortControlPhyOamDmMacAddress1,
   2306                                       _compiler_64_arg(0x00000000, 0x00000100));
   2307     if (rv != BCM_E_NONE) {
   2308         cli_out("bcm_port_control_phy_oam_set failed "
   2309                 "with error  u=%d p=%d (type %d)%s\n",
   2310                 unit, port, bcmPortControlPhyOamDmMacAddress1, bcm_errmsg(rv));
   2311     }
   2312 
   2313     rv = bcm_port_control_phy_oam_set(unit, port,
   2314                                       bcmPortControlPhyOamDmRxPortMacAddressIndex,
   2315                                       _compiler_64_arg(0, 0x1));
   2316     if (rv != BCM_E_NONE) {
   2317         cli_out("bcm_port_control_phy_oam_set failed "
   2318                 "with error  u=%d p=%d (type %d) %s\n",
   2319                 unit, port, bcmPortControlPhyOamDmRxPortMacAddressIndex,
   2320                 bcm_errmsg(rv));
   2321     }
   2322 }
   2323 
   2324 void
   2325 phy_oam_y1731_mac_sa_tx(int unit, int port)
   2326 {
   2327     int rv;
   2328     bcm_port_config_phy_oam_t config;
   2329 
   2330     sal_memset(&config, 0, sizeof(soc_port_config_phy_oam_t));
   2331 
   2332     config.tx_dm_config.flags = BCM_PORT_PHY_OAM_DM_MAC_CHECK_ENABLE;
   2333     config.tx_dm_config.mode = bcmPortConfigPhyOamDmModeY1731;
   2334     rv = bcm_port_config_phy_oam_set(unit, port, &config);
   2335     if (rv != BCM_E_NONE) {
   2336         cli_out("bcm_port_config_phy_oam_set failed with error  u=%d p=%d %s\n",
   2337                 unit, port, bcm_errmsg(rv));
   2338     }
   2339 
   2340     rv = bcm_port_control_phy_oam_set(unit, port,
   2341                                       bcmPortControlPhyOamDmMacAddress2,
   2342                                       _compiler_64_arg(0x0000a000, 0x00000100));
   2343     if (rv != BCM_E_NONE) {
   2344         cli_out("bcm_port_control_phy_oam_set failed "
   2345                 "with error  u=%d p=%d (type %d)%s\n",
   2346                 unit, port, bcmPortControlPhyOamDmMacAddress1, bcm_errmsg(rv));
   2347     }
   2348 
   2349     rv = bcm_port_control_phy_oam_set(unit, port,
   2350                                       bcmPortControlPhyOamDmTxPortMacAddressIndex,
   2351                                       _compiler_64_arg(0, 0x2));
   2352     if (rv != BCM_E_NONE) {
   2353         cli_out("bcm_port_control_phy_oam_set failed "
   2354                 "with error  u=%d p=%d (type %d) %s\n",
   2355                 unit, port, bcmPortControlPhyOamDmTxPortMacAddressIndex,
   2356                 bcm_errmsg(rv));
   2357     }
   2358 }
   2359 
   2360 void
   2361 phy_oam_ctrl_tx_ethtype(int unit, int port)
   2362 {
   2363     int rv;
   2364 
   2365     rv = bcm_port_control_phy_oam_set(unit, port,
   2366                                       bcmPortControlPhyOamDmTxEthertype,
   2367                                       _compiler_64_arg(0, 0xaaaa));
   2368     if (rv != BCM_E_NONE) {
   2369         cli_out("bcm_port_control_phy_oam_set failed "
   2370                 "with error  u=%d p=%d (type %d) %s\n",
   2371                 unit, port, bcmPortControlPhyOamDmTxEthertype, bcm_errmsg(rv));
   2372     }
   2373 
   2374 }
   2375 
   2376 void
   2377 phy_oam_ctrl_rx_ethtype(int unit, int port)
   2378 {
   2379     int rv;
   2380 
   2381     rv = bcm_port_control_phy_oam_set(unit, port,
   2382                                       bcmPortControlPhyOamDmRxEthertype,
   2383                                       _compiler_64_arg(0, 0xbbbb));
   2384     if (rv != BCM_E_NONE) {
   2385         cli_out("bcm_port_control_phy_oam_set failed "
   2386                 "with error  u=%d p=%d (type %d) %s\n",
   2387                 unit, port, bcmPortControlPhyOamDmRxEthertype, bcm_errmsg(rv));
   2388     }
   2389 }
   2390 
   2391 void
   2392 phy_oam_tests(void)
   2393 {
   2394     cli_out(" \n\tTests:\n");
   2395     cli_out("1.1. phy_oam_y1731_rx\n");
   2396     cli_out("1.2. phy_oam_y1731_tx\n");
   2397     cli_out("1.3. phy_oam_y1731_mac_da_rx\n");
   2398     cli_out("1.4. phy_oam_y1731_mac_sa_tx\n");
   2399     cli_out("1.5. phy_oam_ctrl_rx_ethtype\n");
   2400     cli_out("1.6. phy_oam_ctrl_tx_ethtype\n");
   2401 }
   2402 
   2403 
   2404 cmd_result_t
   2405 phy_test1588(int unit, args_t *args, soc_pbmp_t *pbm)
   2406 {
   2407     char       *cmd;
   2408     soc_port_t  p, dport;
   2409 
   2410     int  iter=0, test_case = 0, arg1=0, arg2=0, arg3=0, arg4=0;
   2411     soc_port_t  p01=0, p02=0;
   2412 
   2413     if (((cmd = ARG_GET(args)) == NULL) || (parse_bcm_pbmp(unit, cmd, pbm) < 0)) {
   2414         cli_out("%s: ERROR: unrecognized port bitmap: %s\n", ARG_CMD(args), cmd);
   2415         return CMD_FAIL;
   2416     }
   2417 
   2418     if ((cmd = ARG_GET(args)) != NULL) {
   2419         if ( (! strcmp(cmd, "syncout")) || (! strncmp(cmd, "so", 2)) ) {
   2420             test_case = 350;          /* SyncOUT mode test */
   2421         } else if ( (! strcmp(cmd, "framesync")) || (! strncmp(cmd, "fs", 2)) ) {
   2422             test_case = 382;          /* FrameSync mode test */
   2423         } else if ( (! strncmp(cmd, "dp", 2)) ) {
   2424             test_case = 30;           /* DPLL test */
   2425         } else {
   2426             test_case = parse_integer(cmd);
   2427         }
   2428     }
   2429 
   2430     if ((cmd = ARG_GET(args)) != NULL) {
   2431         arg1 = parse_integer(cmd);
   2432     }
   2433     if ((cmd = ARG_GET(args)) != NULL) {
   2434         arg2 = parse_integer(cmd);
   2435     }
   2436     if ((cmd = ARG_GET(args)) != NULL) {
   2437         arg3 = parse_integer(cmd);
   2438     }
   2439     if ((cmd = ARG_GET(args)) != NULL) {
   2440         arg4 = parse_integer(cmd);
   2441     }
   2442 
   2443     DPORT_SOC_PBMP_ITER(unit, *pbm, dport, p) {
   2444         ++iter;
   2445         if      ( 1 == iter )    p01 = p;
   2446         else if ( 2 == iter )    p02 = p;
   2447         else                     break;
   2448     }
   2449     cli_out("================ "
   2450             "1588 unit test #%d (port %d, %d) arg= %d %d %d %d\n",
   2451             test_case, p01,p02, arg1, arg2, arg3, arg4);
   2452 
   2453     switch ( test_case ) {
   2454         case 0 :
   2455             /* _print_heartbeat_ts(unit, p01); _print_capture_ts(unit, p01);   */
   2456             heartbeat_trace(unit, p01, arg1, arg2);
   2457             break;
   2458         case  10 :
   2459             test1588(p01, p02);      break;
   2460         case  1 :
   2461             test1588_1(p01, p02);    break;
   2462         case  2 :
   2463             test1588_2(p01, p02);    break;
   2464         case  3 :
   2465             test1588_3(p01, p02);    break;
   2466         case  4 :
   2467             test1588_4(p01, p02);    break;
   2468         case  5 :
   2469             config_syncout(0, p01, bcmPortPhyTimesyncSyncoutOneTime,
   2470                            arg1, arg2, arg3);
   2471             cpu_sync(0, p01);
   2472             break;
   2473         case  6 :
   2474             config_syncout(0, p01, bcmPortPhyTimesyncSyncoutPulseTrain,
   2475                            arg1, arg2, arg3);
   2476             cpu_sync(0, p01);
   2477             break;
   2478         case  7 :
   2479             config_syncout(0, p01, bcmPortPhyTimesyncSyncoutPulseTrainWithSync,
   2480                            arg1, arg2, arg3);
   2481             cpu_sync(0, p01);
   2482             break;
   2483         case  8 :
   2484             test1588_8(p01, arg1, arg2);     break;
   2485 
   2486         case  20 :
   2487             config_fs_test(unit, p01);       break;
   2488         case  30 :
   2489             if ( 1 == arg1 ) {  /* DPLL test */
   2490                 config_dpll_sync(unit, p01, 0xf4240, 0x2a, 0x28, 0); /* 1K Sync */
   2491             } else if ( 4 == arg1 ) {
   2492                 config_dpll_sync(unit, p01, 0x3d090, 0x2a, 0x26, 0); /* 4K Sync */
   2493             } else {
   2494                 config_dpll_sync(unit, p01, 80, 43, 27, 0);       /* 12.5M Sync */
   2495             }
   2496             break;
   2497 
   2498         case  102 :
   2499             config_i0e2_in(unit, p01);       break;
   2500         case  202 :
   2501             config_i0e2_out(unit, p01);      break;
   2502         case  111 :
   2503             config_i1e1_in(unit, p01);       break;
   2504         case  211 :
   2505             config_i1e1_out(unit, p01);      break;
   2506         case  120 :
   2507             config_i2e0_in(unit, p01);       break;
   2508         case  220 :
   2509             config_i2e0_out(unit, p01);      break;
   2510 
   2511         case  350 :          /* SyncOUT mode test */
   2512             config_syncout(0, p01, arg1, arg2, arg3, arg4);
   2513             cpu_sync(0, p01);
   2514             break;
   2515         case  382 :          /* FrameSYNC mode test */
   2516             test1588_8_2(p01, arg1, arg2, arg3);    break;
   2517 
   2518         default:
   2519             cli_out("---- Unknown case #%d !\n", test_case);
   2520             return CMD_OK;
   2521     }
   2522 
   2523     /* cli_out("================ done.\n"); */
   2524     return CMD_OK;
   2525 }
   2526 
   2527 #else
   2528 
   2529 #include <soc/types.h>
   2530 #include <appl/diag/shell.h>
   2531 #include <appl/diag/parse.h>
   2532 
   2533 cmd_result_t
   2534 phy_test1588(int unit, args_t *args, soc_pbmp_t *pbm)
   2535 {
   2536     return CMD_NOTIMPL;
   2537 }
   2538 
   2539 #endif  /* INCLUDE_TIMESYNC_DVT_TESTS */