#!/bin/bash

nic_names=$(grep -R MASTER= /etc/sysconfig/network-scripts/ifcfg-* | awk -F':' '{print $1}' |awk -F'-' '{print $NF}')

for nic in $nic_names
do
    if ip a show $nic |grep -q DOWN 
    then
        [[ -d "/sys/firmware/efi" ]] && BOOTMODE="UEFI" || BOOTMODE="Legacy"
        TIME=$(date +%F_%T_%Z)
        echo mlx-nic-bond-down $nic $BOOTMODE $TIME |tee -a /tmp/debug-nic-down
        ifup $nic
    fi
done

bond_nic1=`cat /sys/class/net/bond0/bonding/slaves | cut -f1 -d' '`
bond_nic2=`cat /sys/class/net/bond0/bonding/slaves | cut -f2 -d' '`

echo 003-rdma.sh binding $bond_nic1 $bond_nic2

/opt/op/startup_mlx.sh $bond_nic1

# ip link set down dev $bond_nic1
mlnx_qos -i $bond_nic1 --trust=dscp
mlnx_qos -i $bond_nic1 --pfc 0,0,0,0,0,1,0,0
# ip link set up dev $bond_nic1

# ip link set down dev $bond_nic2
mlnx_qos -i $bond_nic2 --trust=dscp
mlnx_qos -i $bond_nic2 --pfc 0,0,0,0,0,1,0,0
# ip link set up dev $bond_nic2

cma_roce_mode -d rdma_udisk0 -p 1 -m 2
cma_roce_tos -d rdma_udisk0 -t 184

echo 1 > /sys/module/bonding/parameters/arp_broadcast_mode
echo 1 > /sys/class/net/bond0/bonding/xmit_hash_policy
