Skip to content

Commit

Permalink
fix decoding for out-of-order fields in registers
Browse files Browse the repository at this point in the history
  • Loading branch information
kcgthb committed May 15, 2020
1 parent 35b3c70 commit a6fe3c9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions ibswinfo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ show_reg() {
mlxreg_ext -d "$dev" --show_reg "$reg" 2>&1
}

# decode multifield values from register
# $1: field name (regex supported)
# $2: reg name
mstr_dec() {
local f=$1
local r=$2
# sort fields, and convert them, in one fell swoop
htos "$(awk -v f="$f" '$0 ~ f {gsub(/\[|\]/," "); print}' \
<<< "${reg[$r]}" | sort -k2n | awk '{printf $NF}')"
}


## -- arg handling ------------------------------------------------------------

Expand Down Expand Up @@ -239,13 +250,13 @@ done <<< "$_regs"
# inventory
[[ ! "$out" =~ status|vitals ]] && {
# part/serial number
pn=$(htos "$(awk '/part_number/ {printf $NF}' <<< "${reg[MSGI]}")")
sn=$(htos "$(awk '/serial_number/ {printf $NF}' <<< "${reg[MSGI]}")")
cn=$(htos "$(awk '/product_name/ {printf $NF}' <<< "${reg[MSGI]}")")
rv=$(htos "$(awk '/revision/ {printf $NF}' <<< "${reg[MSGI]}")")
pn=$(mstr_dec "part_number" MSGI)
sn=$(mstr_dec "serial_number" MSGI)
cn=$(mstr_dec "roduct_name" MSGI)
rv=$(htos "$(awk '/revision/ {printf $NF}' <<< "${reg[MSGI]}")")

# PSID
psid=$(htos "$(awk '/^psid/ {printf $NF}' <<< "${reg[MGIR]}")")
psid=$(mstr_dec '^psid' MGIR)

# FW version
maj=$(htod "$(awk '/extended_major/ {printf $NF}' <<< "${reg[MGIR]}")")
Expand All @@ -254,7 +265,7 @@ done <<< "$_regs"

# node description
#shellcheck disable=SC2046
nd=$(htos $(awk '/node_description/ {print $NF}' <<< "${reg[SPZR]}"))
nd=$(mstr_dec "node_description" SPZR)
guid=$(awk '/node_guid/ {gsub(/0x/,"",$NF); g=g$NF} END {print "0x"g}' \
<<< "${reg[SPZR]}")
}
Expand Down

1 comment on commit a6fe3c9

@kcgthb
Copy link
Member Author

@kcgthb kcgthb commented on a6fe3c9 May 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #5.

Please sign in to comment.