freebsd-dev/sys/cam
Kenneth D. Merry 130f4520cb Add the CAM Target Layer (CTL).
CTL is a disk and processor device emulation subsystem originally written
for Copan Systems under Linux starting in 2003.  It has been shipping in
Copan (now SGI) products since 2005.

It was ported to FreeBSD in 2008, and thanks to an agreement between SGI
(who acquired Copan's assets in 2010) and Spectra Logic in 2010, CTL is
available under a BSD-style license.  The intent behind the agreement was
that Spectra would work to get CTL into the FreeBSD tree.

Some CTL features:

 - Disk and processor device emulation.
 - Tagged queueing
 - SCSI task attribute support (ordered, head of queue, simple tags)
 - SCSI implicit command ordering support.  (e.g. if a read follows a mode
   select, the read will be blocked until the mode select completes.)
 - Full task management support (abort, LUN reset, target reset, etc.)
 - Support for multiple ports
 - Support for multiple simultaneous initiators
 - Support for multiple simultaneous backing stores
 - Persistent reservation support
 - Mode sense/select support
 - Error injection support
 - High Availability support (1)
 - All I/O handled in-kernel, no userland context switch overhead.

(1) HA Support is just an API stub, and needs much more to be fully
    functional.

ctl.c:			The core of CTL.  Command handlers and processing,
			character driver, and HA support are here.

ctl.h:			Basic function declarations and data structures.

ctl_backend.c,
ctl_backend.h:		The basic CTL backend API.

ctl_backend_block.c,
ctl_backend_block.h:	The block and file backend.  This allows for using
			a disk or a file as the backing store for a LUN.
			Multiple threads are started to do I/O to the
			backing device, primarily because the VFS API
			requires that to get any concurrency.

ctl_backend_ramdisk.c:	A "fake" ramdisk backend.  It only allocates a
			small amount of memory to act as a source and sink
			for reads and writes from an initiator.  Therefore
			it cannot be used for any real data, but it can be
			used to test for throughput.  It can also be used
			to test initiators' support for extremely large LUNs.

ctl_cmd_table.c:	This is a table with all 256 possible SCSI opcodes,
			and command handler functions defined for supported
			opcodes.

ctl_debug.h:		Debugging support.

ctl_error.c,
ctl_error.h:		CTL-specific wrappers around the CAM sense building
			functions.

ctl_frontend.c,
ctl_frontend.h:		These files define the basic CTL frontend port API.

ctl_frontend_cam_sim.c:	This is a CTL frontend port that is also a CAM SIM.
			This frontend allows for using CTL without any
			target-capable hardware.  So any LUNs you create in
			CTL are visible in CAM via this port.

ctl_frontend_internal.c,
ctl_frontend_internal.h:
			This is a frontend port written for Copan to do
			some system-specific tasks that required sending
			commands into CTL from inside the kernel.  This
			isn't entirely relevant to FreeBSD in general,
			but can perhaps be repurposed.

ctl_ha.h:		This is a stubbed-out High Availability API.  Much
			more is needed for full HA support.  See the
			comments in the header and the description of what
			is needed in the README.ctl.txt file for more
			details.

ctl_io.h:		This defines most of the core CTL I/O structures.
			union ctl_io is conceptually very similar to CAM's
			union ccb.

ctl_ioctl.h:		This defines all ioctls available through the CTL
			character device, and the data structures needed
			for those ioctls.

ctl_mem_pool.c,
ctl_mem_pool.h:		Generic memory pool implementation used by the
			internal frontend.

ctl_private.h:		Private data structres (e.g. CTL softc) and
			function prototypes.  This also includes the SCSI
			vendor and product names used by CTL.

ctl_scsi_all.c,
ctl_scsi_all.h:		CTL wrappers around CAM sense printing functions.

ctl_ser_table.c:	Command serialization table.  This defines what
			happens when one type of command is followed by
			another type of command.

ctl_util.c,
ctl_util.h:		CTL utility functions, primarily designed to be
			used from userland.  See ctladm for the primary
			consumer of these functions.  These include CDB
			building functions.

scsi_ctl.c:		CAM target peripheral driver and CTL frontend port.
			This is the path into CTL for commands from
			target-capable hardware/SIMs.

README.ctl.txt:		CTL code features, roadmap, to-do list.

usr.sbin/Makefile:	Add ctladm.

ctladm/Makefile,
ctladm/ctladm.8,
ctladm/ctladm.c,
ctladm/ctladm.h,
ctladm/util.c:		ctladm(8) is the CTL management utility.
			It fills a role similar to camcontrol(8).
			It allow configuring LUNs, issuing commands,
			injecting errors and various other control
			functions.

usr.bin/Makefile:	Add ctlstat.

ctlstat/Makefile
ctlstat/ctlstat.8,
ctlstat/ctlstat.c:	ctlstat(8) fills a role similar to iostat(8).
			It reports I/O statistics for CTL.

sys/conf/files:		Add CTL files.

sys/conf/NOTES:		Add device ctl.

sys/cam/scsi_all.h:	To conform to more recent specs, the inquiry CDB
			length field is now 2 bytes long.

			Add several mode page definitions for CTL.

sys/cam/scsi_all.c:	Handle the new 2 byte inquiry length.

sys/dev/ciss/ciss.c,
sys/dev/ata/atapi-cam.c,
sys/cam/scsi/scsi_targ_bh.c,
scsi_target/scsi_cmds.c,
mlxcontrol/interface.c:	Update for 2 byte inquiry length field.

scsi_da.h:		Add versions of the format and rigid disk pages
			that are in a more reasonable format for CTL.

amd64/conf/GENERIC,
i386/conf/GENERIC,
ia64/conf/GENERIC,
sparc64/conf/GENERIC:	Add device ctl.

i386/conf/PAE:		The CTL frontend SIM at least does not compile
			cleanly on PAE.

Sponsored by:	Copan Systems, SGI and Spectra Logic
MFC after:	1 month
2012-01-12 00:34:33 +00:00
..
ata Remove unneeded checks for CAM_DEV_QFRZN after cam_periph_runccb() call. 2012-01-02 17:02:45 +00:00
ctl Add the CAM Target Layer (CTL). 2012-01-12 00:34:33 +00:00
scsi Add the CAM Target Layer (CTL). 2012-01-12 00:34:33 +00:00
cam_ccb.h Add descriptor sense support to CAM, and honor sense residuals properly in 2011-10-03 20:32:55 +00:00
cam_debug.h Implement the usage of Report Luns as part of SCSI probing for SCP3 or 2010-06-08 16:17:25 +00:00
cam_periph.c Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs. 2011-11-07 06:44:47 +00:00
cam_periph.h Lay groundwork in CAM for recording and reporting physical path and 2011-06-14 14:53:17 +00:00
cam_queue.c Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs. 2011-11-07 06:44:47 +00:00
cam_queue.h MFp4: Large set of CAM inprovements. 2010-01-28 08:41:30 +00:00
cam_sim.c Mark MALLOC_DEFINEs static that have no corresponding MALLOC_DECLAREs. 2011-11-07 06:44:47 +00:00
cam_sim.h Introduce CAM_SIM_POLLED SIM flag, indicating that it works in polling mode. 2011-11-17 21:07:56 +00:00
cam_xpt_internal.h Lay groundwork in CAM for recording and reporting physical path and 2011-06-14 14:53:17 +00:00
cam_xpt_periph.h MFp4: Large set of CAM inprovements. 2010-01-28 08:41:30 +00:00
cam_xpt_sim.h MFp4: Large set of CAM inprovements. 2010-01-28 08:41:30 +00:00
cam_xpt.c Move the scsi_da_bios_params() prototype from pc98_machdep.h to md_var.h 2011-11-27 16:22:19 +00:00
cam_xpt.h Fixes for sure bus reference miscounting and potential device and 2011-08-12 20:09:38 +00:00
cam.c Add some FEATURE macros for various features (AUDIT/CAM/IPC/KTR/MAC/NFS/NTP/ 2011-02-25 10:11:01 +00:00
cam.h Add Serial Management Protocol (SMP) passthrough support to CAM. 2010-11-30 22:39:46 +00:00
README.quirks Commit for Nate his "guidelines for submitting quirks". 2007-06-10 04:31:55 +00:00

/* $FreeBSD$ */

                     FreeBSD Quirk Guidelines

                  Nate Lawson - njl at freebsd org

0. Introduction

FreeBSD drivers make every attempt possible to support the standards
behind hardware. Where possible and not in conflict with the standard,
they also attempt to work around hardware which doesn't strictly
conform. However, some devices have flaws which can't be worked
around while keeping the driver compatible with the standard. For
these devices, we have created a quirks mechanism to indicate to
the driver that it must avoid certain commands or use them differently
with a specific model and/or version of hardware. This document
focuses on identifying and committing quirks for storage hardware
involving CAM and UMASS but is applicable to other areas.

CAM provides a generic transport for SCSI-like devices. Many different
transports use SCSI command sets including parallel SCSI, firewire
(1394), USB UMASS, fibre channel, and ATAPI. For block devices (i.e.
hard drives, flash adapters, cameras) there are two standards, SBC
and RBC. SCSI hard drives are usually SBC-compliant and smaller
devices like flash drives are usually RBC-compliant. Multimedia
devices including CDROMs and DVD-RW are usually MMC-compliant.

Please follow these guidelines to get your device working as soon
as possible. If you are a committer, please do NOT commit quirks
directly but follow this process also.

1. Determing the problem

The first step is to determine what's wrong. If the device should
be supported but hangs while attaching, it's possible a quirk can
help. The types of things a quirk can fix are:
`
 * cam/cam_xpt.c quirks 

  o CAM_QUIRK_NOLUNS - do not probe luns other than 0 since device
  responds to all inquiries with "lun present".

  o CAM_QUIRK_NOSERIAL - do not send an inquiry for serial number. 

  o CAM_QUIRK_HILUNS - probe all luns even if some respond "not present"
  since device has a sparse lun space. 

 * cam/scsi/scsi_da.c quirks 

  o DA_Q_NO_SYNC_CACHE - The sync cache command is used to force a
  drive to write out all changes to disk before shutting down. Some
  drives hang when receiving this command even though it is required
  by all SBC and RBC standards. Note that a warning message on
  console is NOT sufficient to add this quirk. The warning messages
  are harmless and only a device or system hang is cause for adding
  this quirk.

  o DA_Q_NO_6_BYTE - The RBC spec (see Links below) does not allow
  for 6-byte READ/WRITE commands. Some manufacturers took that too
  literally and crash when receiving 6-byte commands. This quirk
  causes FreeBSD to only send 10-byte commands. Since the CAM subsystem
  has been modified to not send 6-byte commands to USB, 1394, and
  other transports that don't support SBC, this quirk should be very
  rare.

  o DA_Q_NO_PREVENT - Don't use the prevent/allow commands to keep a
  removable medium from being ejected. Some systems can't handle these
  commands (rare).

 * cam/scsi/scsi_cd.c quirks 

  o CD_Q_NO_TOUCH - not implemented 

  o CD_Q_BCD_TRACKS - convert start/end track to BCD 

  o CD_Q_NO_CHANGER - never treat as a changer 

  o CD_Q_CHANGER - always treat as a changer 

 * cam/scsi/scsi_ch.c quirks 
  o CH_Q_NO_DBD - disable block descriptors in mode sense 

 * cam/scsi/scsi_sa.c quirks 

  o SA_QUIRK_NOCOMP - Can't deal with compression at all 

  o SA_QUIRK_FIXED - Force fixed mode 

  o SA_QUIRK_VARIABLE - Force variable mode 

  o SA_QUIRK_2FM - Needs Two File Marks at EOD 

  o SA_QUIRK_1FM - No more than 1 File Mark at EOD 

  o SA_QUIRK_NODREAD - Don't try and dummy read density 

  o SA_QUIRK_NO_MODESEL - Don't do mode select at all 

  o SA_QUIRK_NO_CPAGE - Don't use DEVICE COMPRESSION page 

 * dev/usb/umass.c quirks 

  o NO_TEST_UNIT_READY - The drive does not support Test Unit Ready.
  Convert to Start Unit. This command is a simple no-op for most
  firmware but some of them hang when this command is sent.

  o RS_NO_CLEAR_UA - The drive does not reset the Unit Attention state
  after REQUEST SENSE has been sent. The INQUIRY command does not
  reset the UA either, and so CAM runs in circles trying to retrieve
  the initial INQUIRY data. This quirk signifies that after a unit
  attention condition, don't try to clear the condition with a request
  sense command.

  o NO_START_STOP - Like test unit ready, don't send this command if it hangs the device. 

  o FORCE_SHORT_INQUIRY - Don't ask for full inquiry data (256
  bytes). Some drives can only handle the shorter inquiry length
  (36 bytes).

  o SHUTTLE_INIT - Needs to be initialised the Shuttle way. Haven't
  looked into what this does but apparently it's mostly Shuttle
  devices.

  o ALT_IFACE_1 - Drive needs to be switched to alternate interface 1. Rare.

  o FLOPPY_SPEED - Drive does not do 1Mb/s, but just floppy speeds (20kb/s). 

  o IGNORE_RESIDUE - The device can't count and gets the residue
  of transfers wrong. This is sometimes needed for devices where
  large transfers cause stalls.

  o NO_GETMAXLUN - Get maximum LUN is a command to identify multiple
  devices sharing the same ID. For instance, a multislot compact
  flash reader might be on two LUNS. Some non-standard devices hang
  when receiving this command so this quirk disables it.

  o WRONG_CSWSIG - The device uses a weird CSWSIGNATURE. Rare. 

  o NO_INQUIRY - Device cannot handle INQUIRY so fake a generic
  response. INQUIRY is one of the most basic commands but some
  drives can't even handle it. (No idea how such devices even work
  at all on other OS's.) This quirk fakes up a valid but generic
  response for devices that can't handle INQUIRY.

  o NO_INQUIRY_EVPD - Device cannot handle an extended INQUIRY
  asking for vital product data (EVPD) so just return a "no data"
  response (check condition) without sending the command to the
  device.

2. Testing a Quirk

After you have an idea what you want to try, edit the proper file
above, using wildcarding to be sure your device is matched. Here
is a list of the common things to try. Note that some devices require
multiple quirks or quirks in different drivers. For example, some
USB pen drives or flash readers require quirks in both da(4) and
umass(4).

* umass(4) device (sys/dev/usb/umass.c) -- this quirk matches an Asahi Optical device with any product ID or revision ID. 
* 
*         { USB_VENDOR_ASAHIOPTICAL, PID_WILDCARD, RID_WILDCARD,
*           UMASS_PROTO_ATAPI | UMASS_PROTO_CBI_I,
*           RS_NO_CLEAR_UA
*         },
* da(4) device (sys/cam/scsi/scsi_da.c) -- this quirk matches a Creative device with a name of "NOMAD_MUVO" and any revision. 
* 
*         {
*                 /*
*                  * Creative Nomad MUVO mp3 player (USB)
*                  * PR: kern/53094
*                  */
*                 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
*                 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
*         },

3. Filing a PR

All quirk submissions MUST go through GNATS. For information on how
to submit a PR, see this page.

Please include the following in your PR:

 * Subject: QUIRK: FooCo USB DVD-RAM drive 
 * Output of "camcontrol inquiry yourdevice" 
 * Manufacturer name, model number, etc. 
 * Transport type (FC, SCSI, USB, Firewire) 
 * Output from dmesg for failed attach attempts 
 * Output from dmesg for successful attach attempts (after quirk added) 
 * Output of "usbdevs -v" with device attached 
 * Valid email address 

Here are some examples of well-formed PRs: 

 * kern/43580 
 * kern/49054 

4. What happens next

I will review your submission, respond with comments, and once the
quirk is deemed necessary and ready for committing, I'll commit it,
referencing the PR. (Again, all quirks must be submitted as PRs).
Questions? Email njl AT freebsd.org.

5. Note to Committers

Please insert quirks in the right section in scsi_da.c, sorted by
PR number. Always include the name and PR number for scsi_da.c (see
above for an example.) Please sort quirks alphabetically in umass.c.
Follow the surrounding style in all drivers. Be sure to correspond
with the submitter to be sure the quirk you are adding is the minimum
necessary, not quirking other useful features and not overly broad
(i.e., too many wildcards).