The linux NCR53C8XX driver README file

Written by Gerard Roudier <groudier@club-internet.fr>
21 Rue Carnot
95170 DEUIL LA BARRE - FRANCE

12 January 1997
===============================================================================

1.  Introduction
2.  Supported chips and SCSI features
3.  Summary of other supported features
4.  Memory mapped I/O versus normal I/O
5.  Tagged command queueing
6.  Parity checking
7.  Profiling information
8.  Control commands
      8.1  Set minimum synchronous period
      8.2  Set wide size
      8.3  Set maximum number of concurrent tagged commands
      8.4  Set order type for tagged command
      8.5  Set debug mode
      8.6  Clear profile counters
      8.7  Set flag (no_sync)
9.  Configuration parameters
10. Boot setup commands
      10.1 Syntax
      10.2 Available arguments
      10.3 Advised boot setup commands
11. Some constants and flags of the ncr53c8xx.h header file
12. Installation
      12.1 Provided files
      12.2 Installation procedure
13. Control commands under linux-1.2.13
14. Known problems
      14.1 Tagged commands with Iomega Jaz device
15. SCSI problem troubleshooting

===============================================================================

1. Introduction

This driver has been ported from FreeBSD to Linux and is currently 
maintained by:
          Gerard Roudier              <groudier@club-internet.fr>

The original driver has been written for 386bsd and FreeBSD by:
          Wolfgang Stanglmeier        <wolf@cologne.de>
          Stefan Esser                <se@mi.Uni-Koeln.de>

You can find technical information about the NCR 8xx family in the
PCI-HOWTO written by Michael Will and in the SCSI-HOWTO written by
Drew Eckhardt.

Information about new chips is available at SYMBIOS web server:

          http://www.symbios.com/

This short documentation only describes the features of the NCR53C8XX
driver, configuration parameters and control commands available
through the proc SCSI file system read / write operations.

This driver has been tested OK with linux/i386 and Linux/Alpha.

Latest driver version and patches are available at:

          ftp://linux.wauug.org/pub/roudier

I am not a native speaker of English and there are probably lots of
mistakes in this README file. Any help will be welcome.


2. Supported chips and SCSI features

The following features are supported for all chips:

	Synchronous negotiation
	Disconnection
	Tagged command queuing
	SCSI parity checking
	Master parity checking

"Wide negotiation" is supported for chips that allow it.  The
following table shows some characteristics of NCR 8xx family chips:

       On board                        Supported by    Tested with
Chip   SDMS BIOS   Wide   Ultra SCSI   the driver      the driver
----   ---------   ----   ----------   ------------    -----------
810        N         N        N            Y             Y
810A       N         N        N            Y             Y
815        Y         N        N            Y             Y
825        Y         Y        N            Y             Y
825A       Y         Y        N            Y             Y
860        N         N        Y(1)         Y             Y
875        Y         Y        Y(1)         Y             Y

(1) Ultra (fast20 / fast40) SCSI data transfers are "in theory" supported 
    by the driver, but not fully tested, since the maintainer does not have 
    for the moment Ultra SCSI hard disks.

3. Summary of other supported features.

        Module:                allow to load the driver
        Memory mapped I/O:     increases performance
        Profiling information: read operations from the proc SCSI file system
        Control commands:      write operations to the proc SCSI file system
        Debugging information: written to syslog (expert only)
	Scatter / gather
	Shared interrupt
        Boot setup commands


4. Memory mapped I/O versus normal I/O

Memory mapped I/O has less latency than normal I/O.  Since
linux-1.3.x, memory mapped I/O is used rather than normal I/O.  Memory
mapped I/O seems to work fine on most hardware configurations, but
some poorly designed motherboards may break this feature.

The configuration option CONFIG_SCSI_NCR53C8XX_IOMAPPED forces the
driver to use normal I/O in all cases.


5. Tagged command queueing

Some SCSI devices do not properly support tagged command queuing.  A
safe configuration is to not enable tagged command queuing support at
boot-up, and to enable support of it with the control command
"settags" described further in this text.

Once you are sure that all your devices properly support tagged
command queuing, you can enable it by default with the
CONFIG_SCSI_NCR53C8XX_TAGGED_QUEUE configuration option.

The maximum number of simultaneous tagged commands queued to a device
is currently set to 4 by default. It is defined in the file
ncr53c8xx.h by SCSI_NCR_MAX_TAGS. This value is suitable for most SCSI
disks.  With large SCSI disks (> 2GB, cache > 512KB average seek time
< 10 ms), 8 tagged commands may give better performance.

In some special conditions, some SCSI disk firmwares may return a
QUEUE FULL status for a SCSI command. This behaviour is managed by the
driver by the following heuristic:

- Each time a QUEUE FULL status is returned, tagged command queueing is 
  temporarily disabled. 

- Every 100 successfully completed SCSI commands, if allowed by the
  current limit, the maximum number of queueable commands is
  incremented and tagged command queueing is reenabled.


6. Parity checking

The driver supports SCSI parity checking and PCI bus master parity
checking.  These features must be enabled in order to ensure safe data
transfers.  However, some flawed devices or mother boards will have
problems with parity. You can disable parity by choosing first
"CONFIG_EXPERIMENTAL".  Then, "make config" will allow to set the
following configuration options:

   CONFIG_SCSI_NCR53C8XX_DISABLE_PARITY_CHECK  (disable SCSI parity checking)
   CONFIG_SCSI_NCR53C8XX_DISABLE_MPARITY_CHECK (disable master parity checking)


7. Profiling information

Profiling information is available through the proc SCSI file system.
The device associated with a host has the following pathname:

          /proc/scsi/ncr53c8xx/N     (N=0,1,2 ....)

Generally, only 1 board is used on hardware configuration, and that device is:
          /proc/scsi/ncr53c8xx/0

However, if the driver has been made as module, the number of the
hosts is incremented each time the driver is loaded.

In order to display profiling information, just enter:

         cat /proc/scsi/ncr53c8xx/0

and you will get something like the following text:

-------------------------------------------------------
General information:
  Chip NCR53C810, device id 0x1, revision id 0x2
  IO port address 0x6000, IRQ number 10
  Using memory mapped IO at virtual address 0x282c000
Profiling information:
  num_trans    = 18014
  num_kbytes   = 671314
  num_disc     = 25763
  num_break    = 1673
  num_int      = 1685
  num_fly      = 18038
  ms_setup     = 4940
  ms_data      = 369940
  ms_disc      = 183090
  ms_post      = 1320
-------------------------------------------------------

General information is easy to understand. The device ID and the
revision ID identify the SCSI chip as follows:

Chip    Device id     Revision Id
----    ---------     -----------
810       0x1            <  0x10
810A      0x1            >= 0x10
815       0x4
825       0x3            <  0x10
860       0x6
825A      0x3            >= 0x10
875       0xf

The profiling information is updated upon completion of SCSI commands.
A data structure is allocated and zeroed when the host adapter is
attached. So, if the driver is a module, the profile counters are
cleared each time the driver is loaded.  The "clearprof" command
allows you to clear these counters at any time.

The following counters are available:

("num" prefix means "number of",
"ms" means milli-seconds)

num_trans
	Number of completed commands
	Example above: 18014 completed commands

num_kbytes
	Number of kbytes transferred
	Example above: 671 MB transferred

num_disc
	Number of SCSI disconnections
	Example above: 25763 SCSI disconnections

num_break
	number of script interruptions (phase mismatch)
	Example above: 1673 script interruptions

num_int
	Number of interrupts other than "on the fly"
	Example above: 1685 interruptions not "on the fly"

num_fly
	Number of interrupts "on the fly"
	Example above: 18038 interruptions "on the fly"

ms_setup
	Elapsed time for SCSI commands setups
	Example above: 4.94 seconds

ms_data
	Elapsed time for data transfers
	Example above: 369.94 seconds spent for data transfer

ms_disc
	Elapsed time for SCSI disconnections
	Example above: 183.09 seconds spent disconnected

ms_post
	Elapsed time for command post processing
	(time from SCSI status get to command completion call)
	Example above: 1.32 seconds spent for post processing

Due to the 1/100 second tick of the system clock, "ms_post" time may
be wrong.

In the example above, we got 18038 interrupts "on the fly" and only
1673 script breaks generally due to disconnections inside a segment 
of the scatter list.


8. Control commands

Control commands can be sent to the driver with write operations to
the proc SCSI file system. The generic command syntax is the
following:

      echo "<verb> <parameters>" >/proc/scsi/ncr53c8xx/0
      (assumes controller number is 0)

Using "all" for "<target>" parameter with the commands below will
apply to all targets of the SCSI chain (except the controller).

Available commands:

8.1 Set minimum synchronous period

    setsync <target> <period>

    target:    target number
    period:    minimum synchronous period in nano-seconds.
               Maximum speed = 1000/(4*period) MB/second

    Specify a period of 255, to force asynchronous transfer mode.

8.2 Set wide size

    setwide <target> <size>

    target:    target number
    size:      0=8 bits, 1=16bits

8.3 Set maximum number of concurrent tagged commands
 
    settags <target> <tags>

    target:    target number
    tags:      number of concurrent tagged commands
               must not be greater than SCSI_NCR_MAX_TAGS (default: 4)

8.4 Set order type for tagged command

    setorder <order>

    order:     3 possible values:
               simple: use SIMPLE TAG for all operations (read and write)
               ordered: use ORDERED TAG for all operations
               default: use default tag type,
                        SIMPLE  TAG for read  operations
                        ORDERED TAG for write operations


8.5 Set debug mode

    setdebug <list of debug flags>

    Available debug flags:
        alloc:   print info about memory allocations (ccb, lcb)
        queue:   print info about insertions into the command start queue
        result:  print sense data on CHECK CONDITION status
        scatter: print info about the scatter process
        scripts: print info about the script binding process
	tiny:    print minimal debugging information
	timing:  print timing information of the NCR chip
	nego:    print information about SCSI negotiations
	phase:   print information on script interruptions

    Use "setdebug" with no argument to reset debug flags.


8.6 Clear profile counters

    clearprof

    The profile counters are automatically cleared when the amount of
    data transfered reaches 1000 GB in order to avoid overflow.
    The "clearprof" command allows you to clear these counters at any time.


8.7 Set flag (no_sync)
 
    setflag <target> <flag>

    target:    target number

    For the moment, only one flag is available:

        no_sync:   not allow target to disconnect.

    Do not specify any flag in order to reset the flag. For example:
    - setflag 4
      will reset no_sync flag for target 4, so will allow it disconnections.
    - setflag all
      will allow disconnection for all devices on the SCSI bus.

9. Configuration parameters

If the firmware of all your devices is perfect enough, all the
features supported by the driver can be enabled at start-up.  However,
if only one has a flaw for some SCSI feature, you can disable the
support by the driver of this feature at linux start-up and enable
this feature after boot-up only for devices that support it safely.

CONFIG_SCSI_NCR53C8XX_IOMAPPED       (default answer: n)
    Answer "y" if you suspect your mother board to not allow memory mapped I/O.
    May slow down performance a little.

CONFIG_SCSI_NCR53C8XX_TAGGED_QUEUE    (default answer: n)
    Answer "y" if you are sure that all your SCSI devices that are able to 
    accept tagged commands will proceed safely.

CONFIG_SCSI_NCR53C8XX_MAX_TAGS         (default answer: 4)
    This option allows you to specify the maximum number of tagged commands 
    that can be queued to a device.

CONFIG_SCSI_NCR53C8XX_SYNC            (default answer: 5)
    This option allows you to specify the frequency in MHz the driver 
    will use at boot time for synchronous data transfer negotiations.
    This frequency can be changed later with the "setsync" control command.
    0 means "asynchronous data transfers".

CONFIG_SCSI_NCR53C8XX_FORCE_SYNC_NEGO (default answer: n)
    Force synchronous negotiation for all SCSI-2 devices.
    Some SCSI-2 devices do not report this feature in byte 7 of inquiry 
    response but do support it properly (TAMARACK scanners for example).

CONFIG_SCSI_NCR53C8XX_NO_DISCONNECT   (default and only reasonnable answer: n)
    If you suspect a device of yours does not properly support disconnections,
    you can answer "y". Then, all SCSI devices will never disconnect the bus 
    even while performing long SCSI operations.


10. Boot setup commands

10.1 Syntax

Setup commands can be passed to the driver at boot time.
A boot setup command for the ncr53c8xx driver begins with the driver name 
"ncr53c8xx=". The kernel syntax parser then expects an optionnal list of
integers separated with comma followed by an optionnal list of  comma- 
separated strings. Example of boot setup command under lilo prompt:

lilo: linux root=/dev/hda2 ncr53c8xx=tags:4,sync:10,debug:0x200

- enable tagged commands, up to 4 tagged commands queued.
- set synchronous negotiation speed to 10 Mega-transfers / second.
- set DEBUG_NEGO flag.

For the moment, the integer list of arguments is disgarded by the driver. 
It will be used in the future in order to allow a per controller setup.

Each string argument must be specified as "keyword:value". Only lower-case 
characters and digits are allowed.

10.2 Available arguments

Master parity checking
      mpar:y     enabled
      mpar:n     disabled

Scsi parity checking
      spar:y     enabled
      spar:n     disabled

Scsi disconnections
      disc:y     enabled
      disc:n     disabled
 
Special features
   Only apply to 810A, 825A, 860 and 875 controllers.
   Have no effect with normal 810 and 825.
      specf:y    enabled
      specf:n    disabled

Ultra SCSI support
   Only apply to 860 and 875 controllers.
   Have no effect with other ones.
      ultra:y    enabled
      ultra:n    disabled

Number of tagged commands
      tags:0     (or tags:1 ) tagged command queuing disabled
      tags:#tags (#tags  > 1) tagged command queuing enabled
  #tags will be truncated to the max queued commands configuration parameter.
  If the driver is configured with a maximum of 4 queued commands, tags:4 is 
  the right argument to specify.

Default synchronous negotiation frequency
      sync:0     disabled (asynchronous transfer mode)
      sync:#MHz  enabled up to #MHz.
  #MHz > 10     Ultra SCSI
  #MHz >  5     Fast  SCSI
  In all cases, the driver will use the minimum transfer period supported by 
  controllers according to NCR53C8XX chip type.

Negotiate synchronous with all devices
  (force sync nego)
      fsn:y      enabled
      fsn:n      disabled

Verbosity level
      verb:0     minimal
      verb:1     normal
      verb:2     too much

Debug mode
      debug:0	clear debug flags
      debug:#x   set debug flags
  #x is an integer value combining the following power-of-2 values:
  DEBUG_ALLOC       0x1
  DEBUG_PHASE       0x2
  DEBUG_POLL        0x4
  DEBUG_QUEUE       0x8
  DEBUG_RESULT     0x10
  DEBUG_SCATTER    0x20
  DEBUG_SCRIPT     0x40
  DEBUG_TINY       0x80
  DEBUG_TIMING    0x100
  DEBUG_NEGO      0x200
  DEBUG_TAGS      0x400
  DEBUG_FREEZE    0x800
  DEBUG_RESTART  0x1000

  You can play safely with DEBUG_NEGO. However, some of these flags may 
  generate bunches of syslog messages. 

Burst max
      burst:0    burst disabled
      burst:255  get burst length from initial IO register settings.
      burst:#x   burst enabled (1<<#x burst transfers max)
  #x is an integer value which is log base 2 of the burst transfers max.
  The NCR53C875 and NCR53C825A support up to 128 burst transfers (#x = 7).
  Other chips only support up to 16 (#x = 4).
  This is a maximum value. The driver set the burst length according to chip 
  and revision ids. By default the driver uses the maximum value supported 
  by the chip.


10.3 Advised boot setup commands

If the driver has been configured with default options, the equivalent 
boot setup is:
    ncr53c8xx=mpar:y,spar:y,disc:y,fsn:n,specf:y,ultra:y,sync:5,tags:0,verb:1

For an installation diskette or a safe but not fast system, boot setup is:
    ncr53c8xx=mpar:y,spar:y,disc:n,fsn:n,specf:n,ultra:n,sync:0,tags:0

My personnal system works flawlessly with the following setup:
    ncr53c8xx=mpar:y,spar:y,disc:y,fsn:n,specf:y,ultra:y,sync:20,tags:8

The driver prints its actual setup when verbosity level is 2. You can try 
"ncr53c8xx=verb:2" to get the "static" setup of the driver, or add "verb:2" 
to your boot setup command in order to check the actual setup the driver is 
using.


11. Some constants and flags of the ncr53c8xx.h header file

Some of these are defined from the configuration parameters.  To
change other "defines", you must edit the header file.  Do that only
if you know what you are doing.

SCSI_NCR_SETUP_ULTRA_SUPPORT	(default: defined)
	Ultra SCSI support.
	Can be changed by the following boot setup command:
		ncr53c8xx=ultra:n

SCSI_NCR_SETUP_SPECIAL_FEATURES	(default: defined)
	If defined, the driver will enable some special features according  
	to chip and revision id.
        For 810A, 860, 825A and 875 scsi chips, this option enables support 
        of features that reduce load of PCI bus and memory accesses during  
        scsi transfer processing: burst op-code fetch, read multiple, 
        read line, prefetch, cache line line, write and invalidate, 
        burst 128 (875 only), large dma fifo (875 only), offset 16 (875 only).
	Can be changed by the following boot setup command:
		ncr53c8xx=specf:n

SCSI_NCR_IOMAPPED		(default: not defined)
	If defined, normal I/O is forced.

SCSI_NCR_SHARE_IRQ		(default: defined)
	If defined, request shared IRQ.
	
SCSI_NCR_MAX_TAGS		(default: 4)
	Maximum number of simultaneous tagged commands to a device.
	Can be changed by "settags <target> <maxtags>"

SCSI_NCR_SETUP_DEFAULT_SYNC     (default: 5)
	Frequency in KHz the driver will use at boot time for synchronous 
	negotiation. 0 means asynchronous.
	Can be changed by "setsync <target> <period>"

SCSI_NCR_SETUP_DEFAULT_TAGS     (default: 4)
	Default number of simultaneous tagged commands to a device.
	< 1 means tagged command queuing disabled at start-up.

SCSI_NCR_ALWAYS_SIMPLE_TAG	(default: defined)
	Use SIMPLE TAG for read and write commands.
	Can be changed by "setorder <ordered|simple|default>"

SCSI_NCR_SETUP_DISCONNECTION	(default: defined)
	If defined, targets are allowed to disconnect.

SCSI_NCR_SETUP_FORCE_SYNC_NEGO	(default: not defined)
	If defined, synchronous negotiation is tried for all SCSI-2 devices.
	Can be changed by "setsync <target> <period>"

SCSI_NCR_SETUP_MASTER_PARITY	(default: defined)
	If defined, master parity checking is enabled.

SCSI_NCR_SETUP_MASTER_PARITY	(default: defined)
	If defined, SCSI parity checking is enabled.

SCSI_NCR_PROFILE		(default: defined)
	If defined, profiling information is gathered.

SCSI_NCR_MAX_SCATTER		(default: 128)
	Scatter list size of the driver ccb.

SCSI_NCR_MAX_TARGET		(default: 16)
	Max number of targets per host.

SCSI_NCR_MAX_HOST		(default: 2)
	Max number of host controllers.

SCSI_NCR_SETTLE_TIME		(default: 2)
	Number of seconds the driver will wait after reset.

SCSI_NCR_TIMEOUT_ALERT		(default: 3)
	If a pending command will time out after this amount of seconds,
	an ordered tag is used for the next command.
	Avoids timeouts for unordered tagged commands.

SCSI_NCR_CAN_QUEUE		(default: 7*SCSI_NCR_MAX_TAGS)
	Max number of commands that can be queued to a host.

SCSI_NCR_CMD_PER_LUN		(default: SCSI_NCR_MAX_TAGS)
	Max number of commands queued to a host for a device.

SCSI_NCR_SG_TABLESIZE		(default: SCSI_NCR_MAX_SCATTER-1)
	Max size of the Linux scatter/gather list.

SCSI_NCR_MAX_LUN	(default: 8)
	Max number of LUNs per target.

12. Installation

12.1 Provided files

Driver and common files:

	README.ncr53c8xx	: this file
	ChangeLog.ncr53c8xx	: change log
	ConfigHelp.ncr53c8xx	: Part of Configure.help about the driver
	ncr53c8xx.h		: definitions
	ncr53c8xx.c		: the driver code
	scsitag.c		: command tool to enable tagged queue
	conf.modules		: sample of /etc/conf.modules

	Install.ncr53c8xx	: installation script

	Patch-1.2.13.ncr53c8xx  : patch for linux-1.2.13
	Patch-2.0.27.ncr53c8xx  : patch for linux-2.0.27

Prior to installing the driver, you must untar the distribution, as follow:

	mkdir ncrB2L
	cd ncrB2L
	tar zxvf ncrBsd2Linux-1.16b-src.tar.gz


12.2 Installation procedure

This install script has been tested with linux-1.2.13 and 2.0.27.

This procedure copies the new driver files to the kernel tree and
applies a patch to some files of the kernel tree.

	If your linux directory is at the standard location
	"/usr/src/linux", just enter:
		Install.ncr53c8xx

	Else enter:
		Install.ncr53c8xx <your_linux_directory>

	Make the kernel:
		Change to linux source directory
		Configure with NCR53C7,8XX support = N
		Configure with NCR53C8XX   support = Y (or m)
		Make dependancies
		Make the kernel (use make zdisk first)
		Make and install modules if you have configured with 'm'


13. Control commands under linux-1.2.13

Profiling data and control commands using the proc SCSI file system
are not available for linux-1.2.13.  The only control command
available is "scsitag" which allows you to enable tagged command
queuing support after linux boot-up.

Tagged command queueing is disabled by default at system startup.

You can enable tagged queue per device with the following command:

	scsitag device_name (ex: scsitag /dev/sda)

Use "cc -o scsitag scsitag.c" to create the "scsitag" executable.


14. Known problems

14.1 Tagged commands with Iomega Jaz device

I have not tried this device, however it has been reported to me the
following: This device is capable of Tagged command queuing. However
while spinning up, it rejects Tagged commands. This behaviour is
conforms to 6.8.2 of SCSI-2 specifications. The current behaviour of
the driver in that situation is not satisfying. So do not enable
Tagged command queuing for devices that are able to spin down.  The
other problem that may appear is timeouts. The only way to avoid
timeouts seems to edit linux/drivers/scsi/sd.c and to increase the
current timeout values.


15. SCSI problem troubleshooting

Most SCSI problems are due to a non conformant SCSI bus or to buggy
devices.  If infortunately you have SCSI problems, you can check the
following things:

- SCSI bus cables
- terminations at both end of the SCSI chain
- linux syslog messages (some of them may help you)

If you donnot find the source of problems, you can configure the
driver with no features enabled.

- only asynchronous data transfers
- tagged commands disabled
- disconnections not allowed

Now, if your SCSI bus is ok, your system have every chance to work
with this safe configuration but performances will not be optimal.

If it still fails, then you can send your problem description to
appropriate mailing lists or news-groups.  Send me a copy in order to
be sure I will receive it.  Obviously, a bug in the driver code is
possible.

     My email address: Gerard Roudier <groudier@club-internet.fr>

Allowing disconnections is important if you use several devices on
your SCSI bus but often causes problems with buggy devices.
Synchronous data transfers increases throughput of fast devices like
hard disks.  Good SCSI hard disks with a large cache gain advantage of
tagged commands queuing.

Try to enable one feature at a time with control commands.  For example:

- echo "setsync all 25" >/proc/scsi/ncr53c8xx/0
  Will enable fast synchronous data transfer negotiation for all targets.

- echo "setflag 3" >/proc/scsi/ncr53c8xx/0
  Will reset flags (no_sync) for target 3, and so will allow it to disconnect 
  the SCSI Bus.

- echo "settags 3 4" >/proc/scsi/ncr53c8xx/0
  Will enable tagged command queuing for target 3 if that device supports it.

Once you have found the device and the feature that cause problems, just 
disable that feature for that device.

===============================================================================
End of NCR53C8XX driver README file



