# controlunits.sh: define some common control unit mappings
# Copyright (C) IBM Corp. 2009
# Author: Steffen Maier <maier@de.ibm.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# The arrays (among other things) should be adapted, if any of those device
# drivers start supporting different CU types/models.

# The following combinations of control unit type and model were taken from the
# Linux network device drivers for s390 on 2008-06-09 from Linux 2.6.25.4.
# The list (among other things) should be adapted, if any of those device
# drivers start supporting different CU types/models.
# (Alternatively, the list could be generated by reading the modaliases
#  directly out of the device driver modules:
#  modinfo qeth/cu3088 | fgrep 'alias:'
#  However, this would still require a list of device driver modules.)
readonly -a CU=(
    1731/01
    1731/05
    3088/08
    3088/1f
    3088/1e
    3088/01
    3088/60
    3088/61
)

# $CU_CARDTYPE array is the only one which may contain entries with spaces
readonly -a CU_CARDTYPE=(
    "OSA (QDIO)"
    "HiperSocket"
    "CTC adapter"
    "escon channel"
    "ficon channel"
    "LCS p390"
    "LCS OSA"
    "LCS CLAW"
)

readonly -a CU_DEVDRV=(
    qeth
    qeth
    ctcm
    ctcm
    ctcm
    lcs
    lcs
    lcs
)

readonly -a CU_DEVNAME=(
    eth
    hsi
    ctc
    ctc
    ctc
    eth
    eth
    eth
)

readonly -a CU_GROUPCHANNELS=(
    3
    3
    2
    2
    2
    2
    2
    2
)

readonly -a CHPIDTYPES=(
    [0x10]=OSE
    [0x11]=OSD
    [0x24]=IQD
)

# Searches for a match of argument 1 on the array $CU and sets $cu_idx
# to the matched array index on success.
# Returns 0 on success, 1 on failure.
function search_cu() {
    local scu=$1
    local i
    for ((i=0; i < ${#CU[@]}; i++)); do
        if [ "$scu" == "${CU[i]}" ]; then
            cu_idx=$i
            return 0
        fi
    done
    return 1
}
