Potin Lai | 7bb0c21 | 2023-04-07 16:15:47 +0800 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | |
| 3 | declare -a PORT_NUM_MAP=(10 3 2 1 7 6 5) |
| 4 | declare -a PORT_NAME_MAP=(BMC SLED1 SLED2 SLED3 SLED4 SLED5 SLED6) |
| 5 | SWITCH_MDIO_BUS="1e650000.mdio-1" |
| 6 | |
| 7 | INNER_PORT_DEV_ID="4" |
| 8 | OUTER_PORT_DEV_ID="3" |
| 9 | RETIMER_MDIO_BUS="1e650018.mdio-1" |
| 10 | |
| 11 | get_switch_port_link_st() |
| 12 | { |
| 13 | local port_phy_id=$1 |
| 14 | |
| 15 | if PORT_ST_VAL="$(mdio "$SWITCH_MDIO_BUS" phy "$port_phy_id" 0x00)"; then |
| 16 | PORT_ST_VAL="${PORT_ST_VAL:2}" |
| 17 | if [ "$((16#$PORT_ST_VAL & 16#0800))" -eq "0" ]; then |
| 18 | PORT_ST="down" |
| 19 | else |
| 20 | PORT_ST="up" |
| 21 | fi |
| 22 | else |
| 23 | PORT_ST="mdio failed" |
| 24 | fi |
| 25 | echo "${PORT_ST}" |
| 26 | } |
| 27 | |
| 28 | get_retimer_port_link_st() |
| 29 | { |
| 30 | local port_dev_id=$1 |
| 31 | |
| 32 | if PORT_ST_VAL="$(mdio "$RETIMER_MDIO_BUS" mmd 0:"$port_dev_id" 0x9002)"; then |
| 33 | PORT_ST_VAL="${PORT_ST_VAL:2}" |
| 34 | if [ "$((16#$PORT_ST_VAL & 16#0004))" -eq "0" ]; then |
| 35 | PORT_ST="down" |
| 36 | else |
| 37 | PORT_ST="up" |
| 38 | fi |
| 39 | else |
| 40 | PORT_ST="mdio failed" |
| 41 | fi |
| 42 | echo "${PORT_ST}" |
| 43 | } |
| 44 | |
| 45 | get_port_link_st() |
| 46 | { |
| 47 | printf "========================================\n" |
| 48 | printf "Link Status\n" |
| 49 | printf "========================================\n" |
| 50 | printf "Switch:\n" |
| 51 | for port_phy in {0..6} |
| 52 | do |
| 53 | printf " Port %d (%s): %s\n" "${PORT_NUM_MAP[port_phy]}" "${PORT_NAME_MAP[port_phy]}" "$(get_switch_port_link_st "${PORT_NUM_MAP[port_phy]}")" |
| 54 | done |
| 55 | printf "\n" |
| 56 | printf "Retimer:\n" |
| 57 | printf " Inner Port (XFI): %s\n" "$(get_retimer_port_link_st "${INNER_PORT_DEV_ID}")" |
| 58 | printf " Outer Port (SFI): %s\n" "$(get_retimer_port_link_st "${OUTER_PORT_DEV_ID}")" |
| 59 | printf "========================================\n\n" |
| 60 | } |
| 61 | |
| 62 | get_switch_port_reg_dump() |
| 63 | { |
| 64 | for port_phy in {0..6} |
| 65 | do |
| 66 | printf "========================================\n" |
| 67 | printf "Port %d (%s)\n" "${PORT_NUM_MAP[port_phy]}" "${PORT_NAME_MAP[port_phy]}" |
| 68 | printf "****************************************\n" |
| 69 | for reg_offset in {0..31} |
| 70 | do |
| 71 | printf "[%02X]: %04X\n" "$reg_offset" "$(mdio "$SWITCH_MDIO_BUS" phy "${PORT_NUM_MAP[port_phy]}" "$reg_offset")" |
| 72 | done |
| 73 | printf "========================================\n\n" |
| 74 | done |
| 75 | } |
| 76 | |
| 77 | print_help() |
| 78 | { |
| 79 | echo "Usage:" |
| 80 | echo " $0 <COMMAND>" |
| 81 | echo "" |
| 82 | echo "COMMAND:" |
| 83 | echo " --link-st" |
| 84 | echo " show link status" |
| 85 | echo "" |
| 86 | echo " --port-reg-dump" |
| 87 | echo " port registers dump" |
| 88 | echo "" |
| 89 | } |
| 90 | |
| 91 | ACTION_CMD="$1" |
| 92 | |
| 93 | if [[ ${ACTION_CMD} =~ -h|--help ]]; then |
| 94 | print_help |
| 95 | elif [ "${ACTION_CMD}" = "--link-st" ]; then |
| 96 | get_port_link_st |
| 97 | elif [ "${ACTION_CMD}" = "--port-reg-dump" ]; then |
| 98 | get_switch_port_reg_dump |
| 99 | else |
| 100 | echo "Unknow command: $ACTION_CMD" |
| 101 | print_help |
| 102 | fi |