#!/usr/bin/env bash

# support:
# 1. A800

_install() {
    A800=10de:20f3:0302
    if [[ $( lspci -n -d $A800 ) ]];then
        :
    else    
        return 0
    fi

    if [[ $( lspci -nn -d ::0207 ) ]];then
        lspci -nn -d ::0207 | cut -d' ' -f1 | xargs -I {} mlxconfig -y -d {} set LINK_TYPE_P1=eth KEEP_ETH_LINK_UP_P1=1 KEEP_IB_LINK_UP_P1=0
        return 1
    fi
}

_check() {
    A800=10de:20f3:0302
    if [[ $( lspci -n -d $A800 ) ]];then
        :
    else    
        return 0
    fi

    if [[ $( lspci -nn -d ::0207 ) ]];then
        lspci -nn -d ::0207 | cut -d' ' -f1 | xargs -I {} mlxconfig -y -d {} set LINK_TYPE_P1=eth KEEP_ETH_LINK_UP_P1=1 KEEP_IB_LINK_UP_P1=0
        return 1
    fi

    pci_array=(1d:00.0 5f:00.0 96:00.0 cd:00.0)
    net_array=(net4 net5 net6 net7)
    for i in {0..4}
    do
        ethtool -i ${net_array[i]} | grep bus-info |grep -q ${pci_array[i]} || return 1
        mlxconfig -d ${pci_array[i]} q | grep LINK_TYPE_P1 |grep -q eth || return 1
        mlxconfig -d ${pci_array[i]} q | grep KEEP_ETH_LINK_UP_P1 |grep -q 1 || return 1
        mlxconfig -d ${pci_array[i]} q | grep KEEP_IB_LINK_UP_P1 |grep -q 0 || return 1
    done
}

