#!/bin/tcsh
#
#	vi: set autoindent tabstop=8 shiftwidth=8 :
#
#	target-install
#
#	Script for installing and configuring the target for 2.4.x kernels.
#
#
#	Copyright (C) 2001-2006 InterOperability Lab (IOL)
#				University of New Hampshire (UNH)
#				Durham, NH 03824
#
#	This program is free software; you can redistribute it and/or modify
#	it under the terms of the GNU General Public License as published by
#	the Free Software Foundation; either version 2, or (at your option)
#	any later version.
#
#	This program is distributed in the hope that it will be useful,
#	but WITHOUT ANY WARRANTY; without even the implied warranty of
#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#	GNU General Public License for more details.
#
#	You should have received a copy of the GNU General Public License
#	along with this program; if not, write to the Free Software
#	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
#	USA.
#
#	The name of IOL and/or UNH may not be used to endorse or promote
#	products derived from this software without specific prior
#	written permission.
#
#

#	change the max and default read/write socket buffer sizes to 1 Megabyte
echo "1048575" > /proc/sys/net/core/rmem_max
echo "1048575" > /proc/sys/net/core/rmem_default
echo "1048575" > /proc/sys/net/core/wmem_max
echo "1048575" > /proc/sys/net/core/wmem_default

#	disable the TCP RTT calculation
echo "0" > /proc/sys/net/ipv4/tcp_timestamps

/sbin/insmod ../target/unh_scsi_target.o
/sbin/insmod ../target/unh_iscsi_target.o
#
############## Configure Target ###############
./iscsi_manage target restore host=0
./iscsi_manage target set TargetPortalGroupTag=1 host=0
#
#### p=0 to never phase collapse, p=1 to always phase collapse
#### p=2 to phase collapse every other opportunity
#### performance is best when phase collapse is always on
./iscsi_manage target force p=1 host=0
#
#### force target to send a response in a key negotiation
#### even when that response is optional according to the standard
#./iscsi_manage target force r host=0
#
#### force target to reflect back the value of any X- or X# key
#### (instead of sending back value of NotUnderstood)
#./iscsi_manage target force xok host=0
#
#	easiest to leave these on (Initiator can always choose None)
./iscsi_manage target set HeaderDigest=CRC32C,None host=0
./iscsi_manage target set DataDigest=CRC32C,None host=0
#
# some reasonable settings for Linux when memory is low
#./iscsi_manage target set MaxConnections=2 host=0
#./iscsi_manage target set MaxOutstandingR2T=4 host=0
#
# some reasonable settings for Linux
./iscsi_manage target set MaxConnections=4 host=0
./iscsi_manage target set MaxOutstandingR2T=8 host=0
#
#### performance usually better the larger these numbers are
#### but larger numbers cause bigger buffers to be preallocated
#### and that can cause memory starvation when memory on the target is low
#
# the defaults
#./iscsi_manage target set MaxRecvDataSegmentLength=8192 host=0
#./iscsi_manage target set MaxBurstLength=262144 host=0
#./iscsi_manage target set FirstBurstLength=65536 host=0
#
# some reasonable settings for Linux
./iscsi_manage target set MaxRecvDataSegmentLength=32768 host=0
./iscsi_manage target set MaxBurstLength=131072 host=0
./iscsi_manage target set FirstBurstLength=32768 host=0
#
# some reasonable settings for Linux
#./iscsi_manage target set MaxRecvDataSegmentLength=8192 host=0
#./iscsi_manage target set MaxBurstLength=131072 host=0
#./iscsi_manage target set FirstBurstLength=32768 host=0
#
# all settings very large (can never be achieved in Linux)
#./iscsi_manage target set MaxRecvDataSegmentLength=16773120 host=0
#./iscsi_manage target set MaxBurstLength=16773120 host=0
#./iscsi_manage target set FirstBurstLength=16773120 host=0
#
# all settings equal and at the maximum feasible for Linux
#./iscsi_manage target set MaxRecvDataSegmentLength=131072 host=0
#./iscsi_manage target set MaxBurstLength=131072 host=0
#./iscsi_manage target set FirstBurstLength=131072 host=0
#
# another set of all settings equal and feasible for Linux
#./iscsi_manage target set MaxRecvDataSegmentLength=65536 host=0
#./iscsi_manage target set MaxBurstLength=65536 host=0
#./iscsi_manage target set FirstBurstLength=65536 host=0
#
# when memory is low on target, best when all write data is solicited
# because there are then no preallocated buffers
# (that is the combination InitialR2T=Yes and ImmediateData=No)
#./iscsi_manage target set InitialR2T=Yes host=0
#./iscsi_manage target set ImmediateData=No host=0
#
# but the combination InitialR2T=No and ImmediateData=Yes
# lets the initiator make the final determination
./iscsi_manage target set InitialR2T=No host=0
./iscsi_manage target set ImmediateData=Yes host=0
#
# when memory is low on the target, set maximum queue depth allowed low too
# (default is 4)
#./iscsi_manage target force Q=2
#
# performance usually better when everything goes in order
# (and that is the default)
# but the combination DataPDUInOrder=No and DataSequenceInOrder=No
# lets the initiator make the final determination
./iscsi_manage target set DataPDUInOrder=No host=0
./iscsi_manage target set DataSequenceInOrder=No host=0
#
############## Error Recovery #################
#./iscsi_manage target set ErrorRecoveryLevel=1 host=0
./iscsi_manage target force r2tp=2 host=0
./iscsi_manage target snack d=y host=0
./iscsi_manage target snack s=y host=0
./iscsi_manage target snack h=1 host=0
#./iscsi_manage target snack a=y host=0
#./iscsi_manage target snack A=y host=0
#
############## Force nop pings to be sent to initiator every 10 seconds ########
#./iscsi_manage target force n=5 host=0
#
############## Require initiator to offer security #############
#./iscsi_manage target force s host=0
#
############## Require initiator to offer operational negotiations #############
#./iscsi_manage target force o host=0
#
################### Chap ######################
#./iscsi_manage target set AuthMethod=CHAP,None host=0
#./iscsi_manage target force b t cl=256 px="wild_cat_and_dog" pn=UNH-reference-Target lx="UNH cowhampshire" ln=anonymous-user-of-UNH-reference-Target host=0
#
################### SRP ######################
#./iscsi_manage target set AuthMethod=SRP,None host=0
#./iscsi_manage target force b sx="old_man_of_the_mountain" sn=UNH-IOL-user-name host=0
#
################# start SLP ##################
#register the SLP service by calling a script regTarget
#source target-reg-slp $1
#
################# text replies ###############
#uncomment this to force SendTarget reply to send one key per Text Response pdu
#./iscsi_manage target force tk1 host=0
#
### if code compiled with RDMA_MODE, then use both - unpredictable results otherwise  ###
#./iscsi_manage target force rdmaLogin host=0
#./iscsi_manage target set RDMAExtensions=Yes host=0
# Ensure that phase collapse is off when using RDMA
#./iscsi_manage target force p=0 host=0
#
#### set run-time debug printout
#	turn on TRACE_ERROR_RECOVERY with 0x200
#	turn on TRACE_ISCSI with 0x004
#	turn on TRACE_ISCSI_FULL with 0x002
#./iscsi_manage target force V=0x04 host=0
