1*0cbe4818SRobert Mustacchi#! /usr/bin/ksh 2*0cbe4818SRobert Mustacchi# 3*0cbe4818SRobert Mustacchi# This file and its contents are supplied under the terms of the 4*0cbe4818SRobert Mustacchi# Common Development and Distribution License ("CDDL"), version 1.0. 5*0cbe4818SRobert Mustacchi# You may only use this file in accordance with the terms of version 6*0cbe4818SRobert Mustacchi# 1.0 of the CDDL. 7*0cbe4818SRobert Mustacchi# 8*0cbe4818SRobert Mustacchi# A full copy of the text of the CDDL should have accompanied this 9*0cbe4818SRobert Mustacchi# source. A copy of the CDDL is also available via the Internet at 10*0cbe4818SRobert Mustacchi# http://www.illumos.org/license/CDDL. 11*0cbe4818SRobert Mustacchi# 12*0cbe4818SRobert Mustacchi 13*0cbe4818SRobert Mustacchi# 14*0cbe4818SRobert Mustacchi# Copyright 2025 Oxide Computer Company 15*0cbe4818SRobert Mustacchi# 16*0cbe4818SRobert Mustacchi 17*0cbe4818SRobert Mustacchi# 18*0cbe4818SRobert Mustacchi# Various tests that the data we have for the i2c port map command is what we 19*0cbe4818SRobert Mustacchi# expect. This uses the full device profile and makes the following assumptions: 20*0cbe4818SRobert Mustacchi# 21*0cbe4818SRobert Mustacchi# 1. No one has snuck in and added or deleted devices. 22*0cbe4818SRobert Mustacchi# 2. We have to be careful about devices that are manually claimed as they may 23*0cbe4818SRobert Mustacchi# be detached and therefore not listed in the port unless we have the device 24*0cbe4818SRobert Mustacchi# actively open. 25*0cbe4818SRobert Mustacchi# 26*0cbe4818SRobert Mustacchi# We don't currently fake up the DDR4 RDIMMs which are the main user of the 27*0cbe4818SRobert Mustacchi# major-wide shared address binding, so there is no test for that here. 28*0cbe4818SRobert Mustacchi# 29*0cbe4818SRobert Mustacchi 30*0cbe4818SRobert Mustacchi. $(dirname $0)/common.ksh 31*0cbe4818SRobert Mustacchi 32*0cbe4818SRobert Mustacchitypeset -A port_count 33*0cbe4818SRobert Mustacchitypeset -A port_type 34*0cbe4818SRobert Mustacchitypeset port_path= 35*0cbe4818SRobert Mustacchi 36*0cbe4818SRobert Mustacchifunction read_map 37*0cbe4818SRobert Mustacchi{ 38*0cbe4818SRobert Mustacchi typeset path="$1" 39*0cbe4818SRobert Mustacchi typeset map_ifs="$IFS" 40*0cbe4818SRobert Mustacchi 41*0cbe4818SRobert Mustacchi set -A port_count 42*0cbe4818SRobert Mustacchi set -A port_type 43*0cbe4818SRobert Mustacchi IFS=":" 44*0cbe4818SRobert Mustacchi while read -A value; do 45*0cbe4818SRobert Mustacchi port_count[${value[0]}]=${value[1]} 46*0cbe4818SRobert Mustacchi port_type[${value[0]}]=${value[2]} 47*0cbe4818SRobert Mustacchi done <<< $($I2CADM port map -Hpo addr,count,type $path) 48*0cbe4818SRobert Mustacchi IFS="$scan ifs" 49*0cbe4818SRobert Mustacchi port_path="$path" 50*0cbe4818SRobert Mustacchi} 51*0cbe4818SRobert Mustacchi 52*0cbe4818SRobert Mustacchifunction verify 53*0cbe4818SRobert Mustacchi{ 54*0cbe4818SRobert Mustacchi typeset addr="$1" 55*0cbe4818SRobert Mustacchi typeset ptype="$2" 56*0cbe4818SRobert Mustacchi typeset count="$3" 57*0cbe4818SRobert Mustacchi typeset valid= 58*0cbe4818SRobert Mustacchi 59*0cbe4818SRobert Mustacchi if (( port_count[$addr] != count )); then 60*0cbe4818SRobert Mustacchi valid=no 61*0cbe4818SRobert Mustacchi warn "$addr on $port_path has count ${port_count[$addr]}, but" \ 62*0cbe4818SRobert Mustacchi "expected $count" 63*0cbe4818SRobert Mustacchi fi 64*0cbe4818SRobert Mustacchi 65*0cbe4818SRobert Mustacchi if [[ "${port_type[$addr]}" != $ptype ]]; then 66*0cbe4818SRobert Mustacchi valid=no 67*0cbe4818SRobert Mustacchi warn "$addr on $port_path has type ${port_type[$addr]}, but" \ 68*0cbe4818SRobert Mustacchi "expected $ptype" 69*0cbe4818SRobert Mustacchi fi 70*0cbe4818SRobert Mustacchi 71*0cbe4818SRobert Mustacchi if [[ -z "$valid" ]]; then 72*0cbe4818SRobert Mustacchi printf "TEST PASSED: %s on %s has type (%s) and count (%u)\n" \ 73*0cbe4818SRobert Mustacchi "$addr" "$port_path" "$ptype" "$count" 74*0cbe4818SRobert Mustacchi fi 75*0cbe4818SRobert Mustacchi} 76*0cbe4818SRobert Mustacchi 77*0cbe4818SRobert Mustacchi# 78*0cbe4818SRobert Mustacchi# We should find most things on the top-level port. 79*0cbe4818SRobert Mustacchi# 80*0cbe4818SRobert Mustacchiread_map i2csim0/0 81*0cbe4818SRobert Mustacchiverify 0x0 none 0 82*0cbe4818SRobert Mustacchiverify 0x10 local 1 83*0cbe4818SRobert Mustacchiverify 0x20 local 1 84*0cbe4818SRobert Mustacchiverify 0x33 none 0 85*0cbe4818SRobert Mustacchiverify 0x70 local 1 86*0cbe4818SRobert Mustacchiverify 0x71 downstream 4 87*0cbe4818SRobert Mustacchiverify 0x72 downstream 10 88*0cbe4818SRobert Mustacchiverify 0x7f none 0 89*0cbe4818SRobert Mustacchi 90*0cbe4818SRobert Mustacchi# 91*0cbe4818SRobert Mustacchi# Moving onto the first port on the mux, we expect all of the older local 92*0cbe4818SRobert Mustacchi# devices to no longer be there. 93*0cbe4818SRobert Mustacchi# 94*0cbe4818SRobert Mustacchiread_map i2csim0/0/0x70/0 95*0cbe4818SRobert Mustacchiverify 0x10 none 0 96*0cbe4818SRobert Mustacchiverify 0x20 none 0 97*0cbe4818SRobert Mustacchiverify 0x30 none 0 98*0cbe4818SRobert Mustacchiverify 0x71 local 1 99*0cbe4818SRobert Mustacchiverify 0x72 downstream 8 100*0cbe4818SRobert Mustacchi 101*0cbe4818SRobert Mustacchi# 102*0cbe4818SRobert Mustacchi# And even less if we go to one of the ports below it. 103*0cbe4818SRobert Mustacchi# 104*0cbe4818SRobert Mustacchiread_map i2csim0/0/0x70/0/0x71/0 105*0cbe4818SRobert Mustacchifor i in {0..127}; do 106*0cbe4818SRobert Mustacchi (( i == 0x72 )) && continue 107*0cbe4818SRobert Mustacchi verify $i none 0 108*0cbe4818SRobert Mustacchidone 109*0cbe4818SRobert Mustacchiverify 0x72 local 1 110*0cbe4818SRobert Mustacchi 111*0cbe4818SRobert Mustacchi# 112*0cbe4818SRobert Mustacchi# This port should be empty. 113*0cbe4818SRobert Mustacchi# 114*0cbe4818SRobert Mustacchiread_map i2csim0/0/0x70/6 115*0cbe4818SRobert Mustacchifor i in {0..127}; do 116*0cbe4818SRobert Mustacchi verify $i none 0 117*0cbe4818SRobert Mustacchidone 118*0cbe4818SRobert Mustacchi 119*0cbe4818SRobert Mustacchi 120*0cbe4818SRobert Mustacchiif (( i2c_exit == 0 )); then 121*0cbe4818SRobert Mustacchi printf "All tests passed successfully!\n" 122*0cbe4818SRobert Mustacchifi 123*0cbe4818SRobert Mustacchi 124*0cbe4818SRobert Mustacchiexit $i2c_exit 125