- sas_host_path="${DEV%%/port*}"
- sas_phy_path="${DEV#*/host*/}"
- sas_phy_path="${sas_phy_path%%/target*}"
- sas_phy_id="${sas_phy_path%%/*}"
- sas_phy_id="${sas_phy_id##*port-}"
- sas_port_id="${sas_phy_path%%/end_device*}"
- sas_port_id="${sas_port_id##*port-}"
- sas_end_id="${sas_phy_path##*end_device-}"
- sas_phy_dev="/sys/class/sas_phy/phy-${sas_phy_id}"
- if [ -e "$sas_phy_dev/sas_address" ]; then
- read phy_address < $sas_phy_dev/sas_address
- read phy_id < $sas_phy_dev/phy_identifier
- fi
- if [ -z "$phy_address" ] ; then
+ sas_end_path="${DEV%%/target*}"
+ sas_host_path="${sas_end_path%%/port*}"
+ sas_phy_path="${sas_end_path#*/host*/}"
+ sas_phy_path="${sas_phy_path%%/*}"
+ sas_phy_path="${sas_host_path}/${sas_phy_path}"
+
+ sas_phy_id=255
+ for phy in $sas_phy_path/phy-*/sas_phy/phy-* ; do
+ if [ -d "$phy" ] ; then
+ read phy_id < $phy/phy_identifier
+ if [ $phy_id -lt $sas_phy_id ]; then
+ sas_phy_id=$phy_id
+ fi
+ fi
+ done
+
+ if [ $sas_phy_id -eq 255 ] ; then