#!/bin/bash

is_cumulus()
{
	grep "Cumulus" /etc/lsb-release > /dev/null 2>&1
	RC=$?

	return $RC
}

# Perform chip reset
reset_asic()
{
	echo 0 > /sys/module/sx_netdev/bind_sx_core

	/usr/bin/hw-management.sh chipdown

	echo "Mellanox ASIC Chip Reset"
	echo "pcidrv_restart" > /proc/mlx_sx/sx_core

	echo 1 > /sys/module/sx_netdev/bind_sx_core
	echo 0 > /var/run/hw-management/config/suspend
}

if is_cumulus; then
	# Start from a clean state with the ASIC
	# If fastboot is not enabled then reset asic
	# set the flag to normal after we are done
	filename=/etc/modprobe.d/sx.modprobe.conf
	if grep -q "1" $filename; then
		/sbin/modprobe sx_core
		echo "options sx_core fast_boot=0" > $filename
	else
		reset_asic
	fi
fi

