Skip to content

Commit

Permalink
Improve oob-status.sh
Browse files Browse the repository at this point in the history
Summary:
# Description

when oob-status.sh was run over ssh, there was an issue with the fullpath not being correct
Also improved error handling so the output is useful if there is an MDIO communication issue

Testing:
oob-status.sh
Status:
        Link status:
                Port: 0 Link Up
                Port: 1 Link Up
                Port: 2 Link Down
                Port: IMP Link Up
        Link speed:
                Port: 0 1000 Mb/s
                Port: 1 1000 Mb/s
                Port: 2 1000 Mb/s
                Port: IMP 1000 Mb/s

X-link: facebookexternal/openbmc.arista#327

Reviewed By: mikechoifb

Differential Revision: D51692944

Pulled By: joancaneus

fbshipit-source-id: 09a5f1f835d43d9084bf6f843f1dec285153ccf9
  • Loading branch information
DeanKalla authored and facebook-github-bot committed Nov 30, 2023
1 parent 06b1e63 commit b3e473f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ reg_read() {

data=$(reg_page_data "$page" 1)
mdio_write $oob_page_reg "$data"
page_reg_val=$(mdio_read $oob_page_reg)
if [ "$page_reg_val" -ne "$data" ]; then
echo "Error: page register could not be written" >&2
exit 1
fi

data=$(reg_addr_data "$addr" 0x2)
mdio_write $oob_addr_reg "$data"
Expand Down Expand Up @@ -198,6 +203,11 @@ reg_write() {

data=$(reg_page_data "$page" 1)
mdio_write $oob_page_reg "$data"
page_reg_val=$(mdio_read $oob_page_reg)
if [ "$page_reg_val" -ne "$data" ]; then
echo "Error: page register could not be written" >&2
exit 1
fi

# Write data registers
num_data_regs=$(( ( data_size + 1 ) / 2 ))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ trap handle_signal INT TERM QUIT

# mdio prints in the format "PAGE_HEX/OFFSET_HEX VALUE_HEX == VALUE_BIN\n"
MDIO_READ_PATTERN="^.* (0x[a-fA-F0-9]+).*$"
OOB_MDIO_UTIL=/usr/local/bin/oob-mdio-util.sh

# Global variable to stack tabs for formatting
tab=""
Expand All @@ -48,7 +49,7 @@ usage() {
echo ""
echo "oob-status.sh link_status 0 IMP"
echo "Link Status:"
echo " Port 0: Link Down"
echo " Port 0: Link Up"
echo " Port IMP: Link Up"

}
Expand Down Expand Up @@ -90,7 +91,7 @@ do_read_lnksts() {
local page offset result ports port val
page=0x1
offset=0x0
result=$(oob-mdio-util.sh read16 "$page" "$offset" \
result=$("$OOB_MDIO_UTIL" read16 "$page" "$offset" \
| sed -E "s/$MDIO_READ_PATTERN/\1/")
ports="$*"

Expand All @@ -100,14 +101,21 @@ do_read_lnksts() {
for port in $ports; do
port=${port^^}
val=$(port_to_val "$port")
val=$(( (result >> val) & 0x1 ))
if [ -n "$result" ]; then
val=$(( (result >> val) & 0x1 ))
else
val="unknown"
fi
case "$val" in
0)
printf "%sPort: %s Link Down\n" "$tab" "$port"
;;
1)
printf "%sPort: %s Link Up\n" "$tab" "$port"
;;
*)
printf "%sPort: %s Link %s\n" "$tab" "$port" "$val"
;;
esac
done
tab=${tab:1}
Expand All @@ -117,7 +125,7 @@ do_read_spdsts() {
local page offset result ports port val
page=0x1
offset=0x4
result=$(oob-mdio-util.sh read32 "$page" "$offset" \
result=$("$OOB_MDIO_UTIL" read32 "$page" "$offset" \
| sed -E "s/$MDIO_READ_PATTERN/\1/")
ports="$*"

Expand All @@ -127,7 +135,11 @@ do_read_spdsts() {
for port in $ports; do
port=${port^^}
val=$(port_to_val "$port")
val=$(( (result >> (val * 2)) & 0x3 ))
if [ -n "$result" ]; then
val=$(( (result >> (val * 2)) & 0x3 ))
else
val="unknown"
fi
case "$val" in
0)
printf "%sPort: %s 10 Mb/s\n" "$tab" "$port"
Expand All @@ -138,6 +150,9 @@ do_read_spdsts() {
2)
printf "%sPort: %s 1000 Mb/s\n" "$tab" "$port"
;;
*)
printf "%sPort: %s %s\n" "$tab" "$port" "$val"
;;
esac
done
tab=${tab:1}
Expand Down

0 comments on commit b3e473f

Please sign in to comment.