#!/bin/ksh
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright (c) 2013, Joyent, Inc. All rights reserved.
#

function do_node
{
  cat <<EOF
    <node instance='${1}'>
      <propgroup name='protocol' version='1' name-stability='Private'
        data-stability='Private'>
        <propval name='label' type='string' value='${2}' />
      </propgroup>
      <propgroup name='binding' version='1' name-stability='Private'
        data-stability='Private'>
        <propval name='driver' type='string' value='mpt_sas' />
        <propval name='devctl' type='string' value='${3}' />
        <propval name='enclosure' type='uint32' value='${4}' />
        <propval name='slot' type='uint32' value='${5}' />
      </propgroup>
    </node>
EOF
}


cat <<EOF
<topology name='disk' scheme='hc'>
  <range name='bay' min='0' max='15'>
    <facility name='fail' type='indicator' provider='fac_prov_mptsas' >
      <propgroup name='facility' version='1' name-stability='Private'
        data-stability='Private' >
        <propval name='type' type='uint32' value='0' />
        <propmethod name='mptsas_led_mode' version='0' propname='mode'
          proptype='uint32' mutable='1'>
        </propmethod>
      </propgroup>
    </facility>
    <facility name='ident' type='indicator' provider='fac_prov_mptsas' >
      <propgroup name='facility' version='1' name-stability='Private'
        data-stability='Private' >
        <propval name='type' type='uint32' value='1' />
        <propmethod name='mptsas_led_mode' version='0' propname='mode'
          proptype='uint32' mutable='1'>
        </propmethod>
      </propgroup>
    </facility>
    <facility name='ok2rm' type='indicator' provider='fac_prov_mptsas' >
      <propgroup name='facility' version='1' name-stability='Private'
        data-stability='Private' >
        <propval name='type' type='uint32' value='2' />
        <propmethod name='mptsas_led_mode' version='0' propname='mode'
          proptype='uint32' mutable='1'>
        </propmethod>
      </propgroup>
    </facility>
EOF

enclosure=1
bay=0
slot=0
devctl='/devices/pci@0,0/pci8086,3c02@1/pci15d9,691@0:devctl'
while (( slot <= 7 )); do
  do_node $bay "Front Disk $bay" "$devctl" $enclosure $slot
  (( bay = bay + 1 ))
  (( slot = slot + 1 ))
done

slot=0
devctl='/devices/pci@0,0/pci8086,3c06@2,2/pci15d9,691@0:devctl'
while (( slot <= 7 )); do
  do_node $bay "Front Disk $bay" "$devctl" $enclosure $slot
  (( bay = bay + 1 ))
  (( slot = slot + 1 ))
done

cat <<EOF
    <dependents grouping='children'>
      <range name='disk' min='0' max='0'>
        <enum-method name='disk' version='1' />
      </range>
    </dependents>
  </range>
</topology>
EOF
