# How to configure QLogic target driver for 22xx/23xx/24xx/25xx adapters

How to configure QLogic target driver for 22xx/23xx/24xx/25xx adapters. Step by step guide.
ON TARGET
1: Get the Linux kernel sources for version >= 2.6.26 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. It is strongly recommended to use firmware version 5.x or higher for 24xx/25xx adapters. See here for more details why. Without a firmware image 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. It is possibile either from the SCST downloads page or from the SVN code base. Below we will consider the case of the downloaded from the SVN code. For the release code everything is the same. You only need unpack all downloaded SCST archives in one directory. It then will contain similar content as ~scst/trunk/ below. [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 ) You need subversion (open source version control system) 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 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 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 2.0.0 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: Now let's create our virtual device: [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 16:To see the device remotely, we have to add it to at least in the LUNs set for our target. We must have LUN 0 (LUs numeration must not start from, e.g., 1). The simplest way to do that is to write an scstadmin's config file: HANDLER vdisk_fileio {
DEVICE disk1 {
filename /mnt/disk1
}
} TARGET_DRIVER qla2x00t {
TARGET 25:00:00:f0:98:87:92:f3 {
LUN 0 disk1
enabled 1
}
}
To use it, we need to install scstadmin:
[root@proj ]# make
[root@proj ]# make install
Let's save our config file as /etc/scst.conf
Now run scstadmin:
[root@proj ]# scstadmin -config /etc/scst.conf
Collecting current configuration: done.
-> Checking configuration file 'qq' for errors.
-> Done, 0 warnings found.
-> Opening device 'disk1' using handler 'vdisk_fileio': done.
-> Adding device 'disk1' at LUN 0 to driver/target 'qla2x00t/25:00:00:f0:98:87:92:f3': done.
-> Enabling driver/target 'qla2x00t/25:00:00:f0:98:87:92:f3': done.
All done.
The same can be done directly via SCST's sysfs interface:
[root@proj ]# echo "add_device disk1 filename=/mnt/disk1" >/sys/kernel/scst_tgt/handlers/vdisk_fileio/mgmt
[root@proj ]# echo "add disk1 0" >/sys/kernel/scst_tgt/targets/qla2x00t/25:00:00:f0:98:87:92:f3/luns/mgmt
[root@proj ]# echo "1" >/sys/kernel/scst_tgt/targets/qla2x00t/25:00:00:f0:98:87:92:f3/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