I discovered that my Nikon LS-9000 ED scanner was not supported by Linux SANE and decided to make my own driver with the Linux Firewire kernel API libraw1394.
The Library Programs and Command API Specifications for the scanner was recently released by Nikon. The scanner uses the Serial Bus Protocol 2 (SBP-2) and the IEEE Std 1394-1995 standard.
I made a simple test-program with libraw1394 and discovered that I can not read (or write) to most registers specific to the Serial Bus. The test-program for reading was as follows:
// gcc -Wall -o read read.c -l raw1394
#include <stdio.h>
#include <libraw1394/csr.h>
#include <libraw1394/raw1394.h>
int main()
{
raw1394handle_t handle;
handle = raw1394_new_handle_on_port(0);
printf("node: %X\n", raw1394_get_local_id(handle));
quadlet_t read;
for (int i = 0; i <= 1048576; i++) // 0 to 0x100000
{
int result = raw1394_read(handle,
raw1394_get_local_id(handle),
CSR_REGISTER_BASE + (i*4),
sizeof(quadlet_t),
&read);
if (result == 0)
printf("%X\n", i*4);
}
raw1394_destroy_handle(handle);
}
The output (in abbreviated form) was:
$ sudo ./read
node: FFC1
0
4
8
18
1C
200
204
210
218
21C
220
224
228
230
234
400 - 7FC
1000 - 13FC
These offsets do not include the all-important MANAGEMENT_AGENT register, which for the Nikon LS9000 ED is at 0x30000. I could not write to this register either.
There must be a kind of memory access restriction in the kernel. How can I write commands to the MANAGEMENT_AGENT register, for example a Query login ORB?
Before the scanner was connected:
$ lsmod | grep firewire
firewire_ohci 40960 0
firewire_core 65536 1 firewire_ohci
crc_itu_t 16384 1 firewire_core
$ dmesg | grep firewire
[ 0.776039] firewire_ohci 0000:03:00.0: added OHCI v1.10 device as card 0, 4 IR + 8 IT contexts, quirks 0x2
[ 1.276095] firewire_core 0000:03:00.0: created device fw0: GUID 000000000000017e, S400
After the scanner was connected:
$ lsmod | grep firewire
firewire_sbp2 24576 0
firewire_ohci 40960 0
firewire_core 65536 2 firewire_ohci,firewire_sbp2
crc_itu_t 16384 1 firewire_core
$ dmesg | grep firewire
[ 0.776039] firewire_ohci 0000:03:00.0: added OHCI v1.10 device as card 0, 4 IR + 8 IT contexts, quirks 0x2
[ 1.276095] firewire_core 0000:03:00.0: created device fw0: GUID 000000000000017e, S400
[ 3289.660782] firewire_core 0000:03:00.0: rediscovered device fw0
[ 3292.688185] firewire_core 0000:03:00.0: created device fw1: GUID 0090b54003ffffff, S400
[ 3292.688190] firewire_core 0000:03:00.0: phy config: new root=ffc0, gap_count=5
[ 3292.922459] firewire_sbp2 fw1.0: logged in to LUN 0000 (0 retries)
It seems the kernel module firewire_sbp2 starts when the scanner is connected and apparently does the login. Can the functions in firewire_sbp2 be used from an application?
SBP2 is a protocol to transport SCSI commands over FireWire.
In Linux, you can use the SCSI Generic driver (
sg) to send SCSI commands to such a device.