How to configure QLogic target driver for 22xx/23xx cards. Step by step guide.

ON TARGET


1: Get the Linux kernel sources for version >= 2.6.16 from kernel.org

I've downloaded kernel version 2.6.26

ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.tar.bz2


2: Get the appropiate firmware for your QLogic card from ftp://ftp.qlogic.com/outgoing/linux/firmware/ and put it under /lib/firmware. Otherwise during boot or when you manually insert the QLogic module, you'll get the following error mesage in the logs(/var/log/messages) < snip >

qla2xxx 0000:13:00.0: Firmware image unavailable.
qla2xxx 0000:13:00.0: Failed to initialize adapter
< snip >
In this case I had to download ql2300_fw.bin


3: Unzip it under /usr/src/
[root@proj src ] bunzip2 /usr/src/linux-2.6.26.tar.bz2
[root@server src ] tar -xvf /usr/src/linux-2.6.26.tar


4: Create symlinks
[root@proj src ] pwd
/usr/src
[root@proj src ] ln -s /usr/src/linux-2.6.26 linux
[root@proj src ] ln -s /usr/src/linux-2.6.26 kernel


5: Get the SCST code from their SVN code base.
[root@proj ] svn co https://scst.svn.sourceforge.net/svnroot/scst
If the command returns successfully then you'll have 'scst'
directory under your current directory ( here it is /root )

Please check if svn (open source version control system) is installed on your Linux box.


6: Change directory to ~scst/trunk/
[root@proj trunk]# pwd
/root/scst/trunk

[root@proj trunk]# ls
AskingQuestions iscsi-release.patch mpt qla2x00t-release.patch scripts scst-full_perf.patch usr www doc iscsi-scst qla2x00t qla_isp scst scst-release.patch usr-full_perf.patch iscsi-full_perf.patch Makefile qla2x00t-full_perf.patch README scstadmin srpt usr-release.patch

For kernels < 2.6.26 you should use ~scst/branches/1.0.0.x/ instead, because qla2x00t driver in trunk/ doesn't support those kernels (see its README).


7: Patch the kernel (the kernel version you've downloaded in step 1)
[root@proj ] cp /root/scst/trunk/scst/kernel/scst_exec_req_fifo-2.6.26.patch /usr/src

[root@proj ] cd /usr/src
[root@proj src] patch -p0 < scst_exec_req_fifo-2.6.26.patch


8: Replace the QLogic FC driver code in the kernel source tree with the modified version of QLogic FC driver code from scst code base.

[root@proj trunk] pwd
/root/scst/trunk
[root@proj trunk] mv /usr/src/linux/drivers/scsi/qla2xxx /usr/src/linux/drivers/scsi/qla2xxx_orig
[root@proj trunk] ln -s /root/scst/trunk/qla2x00t /usr/src/linux/drivers/scsi/qla2xxx


9: Now build the kernel.

Make sure you disable kernel hacking feature, and enable "Device Drivers->SCSI device support->SCSI low level drivers->Qlogic 2xxx target mode support"
(i.e. CONFIG_SCSI_QLA2XXX_TARGET=y)
Also turn OFF HIGHMEM4G|HIGHMEM64G,
i.e.
[root@proj ] grep -i highmem /usr/src/linux/.config
CONFIG_NOHIGHMEM=y
# CONFIG_HIGHMEM4G is not set
# CONFIG_HIGHMEM64G is not set

If you have system with more than 1GB of memory, consider to change CONFIG_VMSPLIT option to the correspinding value.

[root@proj linux ] pwd
/usr/src/linux
[root@proj linux ] make menuconfig
[root@proj linux ] make bzImage
[root@proj linux ] make modules
[root@proj linux ] make modules_install
[root@proj linux ] make install


10: Reboot the machine and during boot select the modified kernel to boot from.


11:Depending on your requirement (performance/debugging) apply the appropiate patches that comes with choose the appropriate SCST build mode. By default SCST has debug build mode. Here is how to switch to the release mode:

[root@proj trunk ] pwd
/root/scst/trunk
[root@proj trunk ] make debug2release


12:OPTIONAL step: do the cleanup before building scst module
(Follow step 11 only if you get error "scst: disagrees about version of symbol struct_module")

This error indicates that the kernel module the script was trying to load was compiled against kernel headers that do not match the running kernel. Doing a clean rebuild of the kernel and SCST should make the above error go away. To make sure nothing of the old kernel is left, Do clean rebuild of kernel and SCST :
Follow the step below:

[root@proj linux ] pwd
/usr/src/linux
[root@proj linux ] make oldconfig
[root@proj linux ] make clean
[root@proj linux ] rm -rf /lib/modules/`uname -r`
[root@proj linux ] make modules
[root@proj linux ] make modules_install
[root@proj linux ] make install
[root@proj linux ] reboot


13:Now build the modules.
But first make sure that the link "/lib/modules/`uname -r`/build"
points to the current running kernel sources.

a) Build scst.
[root@proj ] cd /root/scst/trunk/scst/src
[root@proj ] make all (here I am building everything)
[root@proj ] make install
b) Build QLogic driver.
[root@proj ] cd /root/scst/trunk/qla2x00t
[root@proj ] make
[root@proj ] make install

c) Build QLogic target driver
[root@proj ] cd /root/scst/trunk/qla2x00t/qla2x00-target/
root@proj ] make
[root@proj ] make install


14:Insert the modules.
The driver modules will be installed in '/lib/modules/`you_kernel_version`/extra'.
In addition, scst.h, scst_debug.h as well as Module.symvers or Modules.symvers will be copied to '/usr/local/include/scst'.
The first file contains all SCST's public data definition, which are used by target drivers. The other ones support debug messages logging and build process.

[root@proj scst]# ls -l /lib/modules/`uname -r`/extra
total 232
drwxr-xr-x 2 root root 4096 Jun 20 18:43 dev_handlers
-rw-r--r-- 1 root root 36756 Jun 20 18:46 qla2x00tgt.ko
-rw-r--r-- 1 root root 160192 Jun 20 18:46 qla2xxx.ko
-rw-r--r-- 1 root root 190848 Jun 20 18:43 scst.ko

[root@proj scst]# ls -l /lib/modules/`uname -r`/extra/dev_handlers
total 192
-rw-r--r-- 1 root root 11757 Jun 20 18:43 scst_cdrom.ko
-rw-r--r-- 1 root root 10111 Jun 20 18:43 scst_changer.ko
-rw-r--r-- 1 root root 12420 Jun 20 18:43 scst_disk.ko
-rw-r--r-- 1 root root 12449 Jun 20 18:43 scst_modisk.ko
-rw-r--r-- 1 root root 10131 Jun 20 18:43 scst_processor.ko
-rw-r--r-- 1 root root 10081 Jun 20 18:43 scst_raid.ko
-rw-r--r-- 1 root root 12563 Jun 20 18:43 scst_tape.ko
-rw-r--r-- 1 root root 37937 Jun 20 18:43 scst_user.ko
-rw-r--r-- 1 root root 50194 Jun 20 18:43 scst_vdisk.ko

where:
- scst - SCST itself
- scst_disk - device handler for disks (type 0)
- scst_tape - device handler for tapes (type 1)
- scst_processor - device handler for processors (type 3)
- scst_cdrom - device handler for CDROMs (type 5)
- scst_modisk - device handler for MO disks (type 7)
- scst_changer - device handler for medium changers (type 8)
- scst_raid - device handler for storage array controller (e.g. raid) (type C)
- scst_vdisk - device handler for virtual disks (file, device or ISO CD image).
- scst_user - user space device handler

You can insert any of these modules by 'modprobe' program, I've inserted all the modules !!!
[root@proj ] for _mod in scst qla2xxx qla2x00tgt scst_vdisk scst_user scst_disk....; do modprobe $_mod; done

< snip from dmesg >

scst: SCST version 1.0.0-rc1 loaded successfully (max mem for commands 16251MB, per device 6500MB)
scst: Enabled features: TRACING
scst: Target template qla2x00tgt registered successfully
scst: Virtual device handler vdisk for type 0 registered successfully
scst: Virtual device handler "scst_user" registered successfully
--------
--------
< snip from dmesg >


15:To see the devices remotely, we have to add them to atleast "Default" security group.
Where each security group will have LUN 0(LUs numeration must not start from, e.g., 1)

[root@proj ] dd if=/dev/zero of=/mnt/disk1 bs=1024k count=512
512+0 records in
512+0 records out

[root@proj ] ls -l /mnt/disk1
-rw-r--r-- 1 root root 536870912 Jun 23 13:27 /mnt/disk1

[root@proj ] file /mnt/disk1
/mnt/disk1: data

[root@proj ] echo "open vm_disk /mnt/disk1" > /proc/scsi_tgt/vdisk/vdisk
[root@proj ] echo "add vm_disk 0" >/proc/scsi_tgt/groups/Default/devices

< snip from dmesg >
dev_vdisk: Attached SCSI target virtual disk vm_disk (file="/mnt/disk1", fs=512MB, bs=512, nblocks=1048576, cyln=512)
scst: Attached SCSI target mid-level to virtual device vm_disk (id 1)
scst: Added device vm_disk to group Default (LUN 0, rd_only 0)
< snip from dmesg >

[root@proj ] cat /proc/scsi_tgt/groups/Default/devices
Device (host:ch:id:lun or name) Virtual lun Options
vm_disk 0

[root@proj ] cat /proc/scsi_tgt/vdisk/vdisk
Name Size(MB) Block size Options File name
vm_disk 512 512 /mnt/disk1


16:After the drivers are loaded, the target mode should be enabled via a
sysfs interface on a per card basis. Under the appropriate scsi_host there is an entry target_mode_enabled, where you should write "1", like:
[root@proj ] echo "1" >/sys/class/scsi_host/host11/target_mode_enabled

ON INITIATOR

17:< snip from README >
Without loading appropriate device handler, corresponding device will be invisible for remote initiators, hence we have to add them manully.
< snip from README >

But as I've already loaded the device handler(scst_vdisk) on the target, hence I don't need to perform step 17.

18:After enabling the target mode on the target (see step 16), to see new targets and devices you need either to rescan initiator(s) manually, for example, by rmmod/modprobe the corresponding FC device module on the initiator, or reboot the initiator itself. Automatic discovery isn't supported by all known initiators, so you need a way to make SCSI subsystem on the initiator to do the new devices discovery and hence be able to see the new devices attached.

Alternatively, if your initiator already connected to the target and you simply added new devices to it, you can try to run a manual rescan by:
[root@initiator ] echo "- - -" >/sys/class/scsi_host/hostX/scan
where X: host number