RegCMp

Test a register value

RegCMp

Shortest form: rcm.

Compare a register with a value, for use in scripts and if. regcmp optionally writes a value first, then reads the register up to <LOOPS> times, comparing each time, and stops as soon as a comparison fails. The result is 1 (failure) if a comparison failed and 0 if all succeeded.

Grammar:

regcmp [-q] [<LOOPS> | *] <REGISTER> [<WRITE_VALUE>] {== | !=} <VALUE>

-q suppresses the output; * loops until the comparison fails. -q, *, == and != are case-sensitive. Each value is a number or <FIELD>=<VALUE>[,…]; with fields, only the named fields are compared.

Read-only unless <WRITE_VALUE> is given; then it writes the register on every loop, behind SONiC’s back.

Hardware-validated — Print a message if ce0’s MAC receiver is enabled

drivshell> if "regcmp -q CLMAC_CTRL.ce0 == RX_EN=1" "echo RX enabled"

The example prints nothing on a switch where ce0 is disabled (!ena in ps): the MAC receiver is then off, the comparison fails and if skips the echo. Pick a port that is up, and leave out -q to see the comparison:

Hardware-validated

drivshell> regcmp CLMAC_CTRL.xe0 == RX_EN=1
drivshell> if "regcmp -q CLMAC_CTRL.xe0 == RX_EN=1" "echo RX enabled"
RX enabled

Built-in help

Parameters: [-q] [<LOOPS>] <REG> [<VALUE>] [==|!=] <VALUE>
    If the optional <VALUE> on the left is given, starts by writing
    <VALUE> to <REG>.   Then loops up to <LOOPS> times reading <REG>,
    comparing if it is equal (==) or not equal (!=) to the <VALUE> on
    the right, and stopping if the compare fails.  If -q is specified, no
    output is displayed.  <LOOPS> defaults to 1 and may be * for
    indefinite.  If the compare fails, the command result is 1.  If the
    loops expire (compares succeed), the result is 0.  The result may be
    tested in an IF statement.  Also, each <VALUE> can consist of
    <FIELD>=<VALUE>[,...] to compare individual fields.  Examples:
        if "regcmp -q 1 rpkt.fe0 == 0" "echo RPKT IS ZERO"
        if "regcmp -q config.e0 == fil_en=1" "echo FILTERING ENABLED"