Linux SANE compatibility module Version 1.2 (LSC)

Tero Kivinen <kivinen@iki.fi>
Nov 11 2002

This kernel loadable module emulates all proc filesystem files and devices that is needed to run linux program using scsi Scanner Access Now Easy - SANE interface.

The source can be found from the http://www.iki.fi/kivinen/lsc/lsc-1.2.tar.gz . There is also README file, that contains same information than this html page.

It supports three different devices:

  1. /proc/sys/kernel/sg-big-buff
  2. /proc/scsi/scsi
  3. /dev/sg[0-8]

When it is loaded it automatically creates those devices under the /emul/linux tree, and when it is unloaded it removes all devices it created.

The /proc/sys/kernel/sg-big-buff device is used to read the maximum transfer size between kernel and user mode program. The default value is 128kB - 512 = 130560 bytes. This is supposed to be maximum value allowed by the linux kernel.

The /proc/scsi/scsi device lists information about devices connected to the scsi buses. Say cat /emul/linux/proc/scsi/scsi to see what kind of information it returns.

When the module is loaded it detects all scsi scanners connected to any of the buses, and creates /dev/sg0 device for the first scanner, and /dev/sg1 for the next etc. By default the driver supports 8 scanners, but this can be configured to be larger if needed by changing the LSC_MAX_SCANNERS define in the beginning of the linux_sanei_compat.c.

The scanners are attaced in the order they appear in the scsibuses, starting from the lowest scsi bus, target 0, lun 0 and then going up from there.

When /dev/sg* device is opened the module allocates memory buffers for incoming and outgoing data transfer and starts reading linux sg_header structures from the device. When it receives one it sends the command to real scsi device and writes sg_header packet back to user level. Current driver only supports one concurrent operation per device.

Compilation & Testing

To compile the lsc driver simply unpack the tar file, and run "./configure" and then "make". This creates the lkm module named lsc.o.

Then you can test the module by loading it to kernel with command "modload lsc.o". It should print out its version number to console and also print the number of scsi scanners it found. Then check that the scsi probe system is working properly by saying "cat /emul/linux/proc/scsi/scsi". That file should contain all scsi devices you have connected to all busses.

To unload the driver you need to first find out the Id number of the module by using the "modstat" command and then you can unload the module by "modunload -i xxx" command. In normal case the Id number of the module is 0, so "modunload -i 0" should work.

If you want to load the module automatically when the machine is booted, copy the lsc.o to /lkm directory and then add "/lkm/lsc.o - - - - -" line to the /etc/lkm.conf. Also make sure that the /etc/rc.conf file has "lkm=YES" line.

Known Problems

Old ncr scsi driver does not work well enough to be usable for the LSC. If the probe devices print out something like scsibus0 at ncr0: ... you need to modify your kernel configuration to use newer siop scsi driver. For that you need new enough kernel that has that device (if you have /usr/src/sys/dev/pci/siop_pci.c file then you have it). You also need to replace "ncr*" with "siop*" in the /usr/src/sys/arch/.../conf/XXXXXXX file, where XXXXXX is the kernel configuration file you are using, and then you need to rerun config and recompile the kernel.

Running vuescan

When you have LSC module loaded, you can simply run program that uses linux SANE interface. An example program of such is quite good commercial scanner software called vuescan. You can download a demo version of it from the http://www.hamrick.com/. You can also register to full version on-line for $40.

Tero Kivinen
<kivinen@iki.fi>
http://www.iki.fi/kivinen/lsc/


<kivinen@iki.fi>