#!/bin/sh
#
# Copyright (c) 2019-2020 Citrix Systems, Inc. All rights reserved.
# This software and documentation contain valuable trade
# secrets and proprietary property belonging to Citrix Systems, Inc.
# None of this software and documentation may be copied,
# duplicated or disclosed without the express
# written permission of Citrix Systems, Inc.
#
# 12/09/19
#
# This file contains shell script code provided as a convenience
# for interested parties contemplating Fortville NIC firmware update.
# It outputs (and logs) important information about installed Fortville
# NICs.
#
# usage:  sh fortville_nic_info
#

SCRIPTS_DIR=/var/tmp/Fortville_Silicom_Intel/scripts
FW_UPDATE_SUBR="./fortville_fw_update_subr"

cd ${SCRIPTS_DIR}

#
# Load the subroutine file
#
if [ -f ${FW_UPDATE_SUBR} ]
then
	. ${FW_UPDATE_SUBR}
else
	echo ">>> Missing ${FW_UPDATE_SUBR} file!"
	exit 100
fi

log_msg ">>> =================================================================="
log_msg ">>> Invoking fortville_nic_info informational script $(date)"

has_silicom_nics
HAS_SILICOM=$?
if [ ${HAS_SILICOM} -eq 0 ]
then
	log_msg ">>> NetScaler has Silicom NICs"
else
	log_msg ">>> NetScaler does not have Silicom NICs"
fi

has_intel_nics
HAS_INTEL=$?
if [ ${HAS_INTEL} -eq 0 ]
then
	log_msg ">>> NetScaler has Intel NICs"
else
	log_msg ">>> NetScaler does not have Intel NICs"
fi

#
# Complain if there are no Fortville NICs in this system.
#
if [ $HAS_SILICOM -ne 0 ] && [ $HAS_INTEL -ne 0 ]
then
	echo "does not have Silicom or Intel"
	echo "Silicom = $HAS_SILICOM Intel = $HAS_INTEL"
	log_msg ">>> This NetScaler does not contain any Fortville NICs."
else
	log_msg ">>> has at least one of Silicom and Intel NICs"
	#echo ">>> Silicom = $HAS_SILICOM, Intel = $HAS_INTEL"
fi

#
# Complain if the kernel does not support Fortville firmware update
#
sysctl dev.ixl.0.en_firmware_update > /dev/null 2>&1
SYSCTL_RET=$?
if [ ${SYSCTL_RET} -ne 0 ]
then
	# kernel without FW update support returns 1
	echo "sysctl did not return 0, ${SYSCTL_RET}"
	log_msg ">>> Installed kernel does not support Fortville firmware" \
	    "update:  ${SYSCTL_RET}"
else
	# kernel with FW update support returns 0
	#echo "sysctl returned 0, ${SYSCTL_RET}"
fi

# Print FW version and EETRACK ID for each Fortville NIC.
fw_eetrack
# Allow the above to flush out to console, log file.
sleep 4

