@echo off
rem ************************************************************************************
rem * Description: 	Enables the Fibre controller for booting from fibre.
rem * Name: 		ENBTFIBR.BAT
rem * Dependencies:	FIBRECFG.EXE, DCTQLOG.BAT,DCTEMUL.BAT, DOSLPCFG.EXE, EMULEX.SCR, 
rem *               SETERRLV.EXE, SAVERC.BAT, TKOUT.BAT
rem * Parameters: 	
rem *			%1 = Input IOAddress	
rem *			%2 = Input LUN	
rem *			%3 = Input WWN1	
rem *			%4 = Input WWN2 (Optional)	
rem *			%5 = Input WWN3 (Optional) 
rem *			%6 = Input WWN4 (Optional) 
rem * Return Code:
rem * 			0     = Success 
rem * 			>=1   = Error code defined by FIBRECFG.exe
rem ************************************************************************************

rem ************************************************************************************
rem *** Initialize Return Code
rem ************************************************************************************
set RC=0

rem ************************************************************************************
rem *** Check Parameters
rem ************************************************************************************
if "%1" == "" goto PERROR
if "%2" == "" goto PERROR
if "%3" == "" goto PERROR

rem ************************************************************************************
rem *** Detect Qlogic
rem ************************************************************************************
call dtctqlog
if errorlevel 1 goto DEMULEX

rem ************************************************************************************
rem *** Enable BIOS for QLOGIC
rem ************************************************************************************
set MSG="Enabling Qlogic fibre adapter BIOS at address %1"
call TKOUT.BAT
call enblfibr.bat %1
if errorlevel 1 goto FIBFAIL

set MSG="Configuring Qlogic fibre adapter at address %1 to primary   boot from WWN %3, LUN %2"
call TKOUT.BAT
fibrecfg /R /BE0 %1 %3 %2
if errorlevel 1 goto FIBFAIL

if "%4" == "" goto FIBGOOD
set MSG="Configuring Qlogic fibre adapter at address %1 to secondary boot from WWN %4, LUN %2"
call TKOUT.BAT
fibrecfg /R /BE1 %1 %4 %2
if errorlevel 1 goto FIBFAIL

if "%5" == "" goto FIBGOOD
set MSG="Configuring Qlogic fibre adapter at address %1 to tertiary  boot from WWN %5, LUN %2"
call TKOUT.BAT
fibrecfg /R /BE2 %1 %5 %2
if errorlevel 1 goto FIBFAIL

if "%6" == "" goto FIBGOOD
set MSG="Configuring Qlogic fibre adapter at address %1 to fourth  boot from WWN %6, LUN %2"
call TKOUT.BAT
fibrecfg /R /BE3 %1 %6 %2
if errorlevel 1 goto FIBFAIL

goto FIBGOOD


:DEMULEX
rem *** Detect Emulex
call dtctemul
if errorlevel 1 goto NOFIBRE


set MSG="Enabling Emulex fibre adapter BIOS at address %1"
call TKOUT.BAT
rem * This commands creates emulex.out
doslpcfg @emulex.scr max=4
set MSG="Configuring Emulex fibre adapter at address %1 to primary   boot from WWN %3, LUN %2"
call TKOUT.BAT
fibrecfg /R /BE0 %1 %3 %2 /EM
if errorlevel 1 goto FIBFAIL
call emlxset.bat
doslpcfg enableboot n=%emlxadp% i=1 max=4
if errorlevel 1 goto FIBFAIL
doslpcfg setbootdevice n=%emlxadp% w0=%emlxw0% w1=%emlxw1% l=%LUN% max=4
if errorlevel 1 goto FIBFAIL
del emulex.out
goto FIBGOOD

:NOFIBRE
set MSG="No Fibre adapter detected."
call TKOUT.BAT
SET RC=0
goto END

:FIBFAIL
call saverc.bat
set MSG="Enable Fibre Boot failed."
call TKOUT.BAT
echo "failed" >rs.err
goto ERROR

:FIBGOOD
set MSG="Enable Fibre Boot succeeded."
call TKOUT.BAT
goto END

:PERROR
set MSG="Missing script parameter."
call TKOUT.BAT
set RC=1
goto ERROR

:ERROR
set MSG="Encountered an error and stopped processing in enbtfibr.bat"
call TKOUT.BAT
goto END

:END
SET MSG=
SETERRLV %RC%
