#!/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
	# Do not leave the ASIC enabled after sx_sdk is stopped
	# otherwise it may e.g., still DMA across reboot/restart
	# If fastboot is not enabled then reset asic
	filename=/etc/modprobe.d/sx.modprobe.conf
	if ! grep -q "1" $filename; then
		reset_asic
	fi
fi

