?? sbp2.c
字號:
/* * sbp2.c - SBP-2 protocol driver for IEEE-1394 * * Copyright (C) 2000 James Goodwin, Filanet Corporation (www.filanet.com) * jamesg@filanet.com (JSG) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *//* * Brief Description: * * This driver implements the Serial Bus Protocol 2 (SBP-2) over IEEE-1394 * under Linux. The SBP-2 driver is implemented as an IEEE-1394 high-level * driver. It also registers as a SCSI lower-level driver in order to accept * SCSI commands for transport using SBP-2. * * * Driver Loading: * * Currently, the SBP-2 driver is supported only as a module. Because the * Linux SCSI stack is not Plug-N-Play aware, module load order is * important. Assuming the SCSI core drivers are either built into the * kernel or already loaded as modules, you should load the IEEE-1394 modules * in the following order: * * ieee1394 (e.g. insmod ieee1394) * ohci1394 (e.g. insmod ohci1394) * sbp2 (e.g. insmod sbp2) * * The SBP-2 driver will attempt to discover any attached SBP-2 devices when first * loaded, or after any IEEE-1394 bus reset (e.g. a hot-plug). It will then print * out a debug message indicating if it was able to discover a SBP-2 device. * * Currently, the SBP-2 driver will catch any attached SBP-2 devices during the * initial scsi bus scan (when the driver is first loaded). To add or remove * SBP-2 devices "after" this initial scan (i.e. if you plug-in or un-plug a * device after the SBP-2 driver is loaded), you must either use the scsi procfs * add-single-device, remove-single-device, or a shell script such as * rescan-scsi-bus.sh. * * The easiest way to add/detect new SBP-2 devices is to run the shell script * rescan-scsi-bus.sh (or re-load the SBP-2 driver). This script may be * found at: * http://www.garloff.de/kurt/linux/rescan-scsi-bus.sh * * As an alternative, you may manually add/remove SBP-2 devices via the procfs with * add-single-device <h> <b> <t> <l> or remove-single-device <h> <b> <t> <l>, where: * <h> = host (starting at zero for first SCSI adapter) * <b> = bus (normally zero) * <t> = target (starting at zero for first SBP-2 device) * <l> = lun (normally zero) * * e.g. To manually add/detect a new SBP-2 device * echo "scsi add-single-device 0 0 0 0" > /proc/scsi/scsi * * e.g. To manually remove a SBP-2 device after it's been unplugged * echo "scsi remove-single-device 0 0 0 0" > /proc/scsi/scsi * * e.g. To check to see which SBP-2/SCSI devices are currently registered * cat /proc/scsi/scsi * * After scanning for new SCSI devices (above), you may access any attached * SBP-2 storage devices as if they were SCSI devices (e.g. mount /dev/sda1, * fdisk, mkfs, etc.). * * * Module Load Options: * * sbp2_max_speed - Force max speed allowed * (2 = 400mb, 1 = 200mb, 0 = 100mb. default = 2) * sbp2_serialize_io - Serialize all I/O coming down from the scsi drivers * (0 = deserialized, 1 = serialized, default = 0) * sbp2_max_sectors, - Change max sectors per I/O supported (default = 255) * sbp2_max_outstanding_cmds - Change max outstanding concurrent commands (default = 8) * sbp2_max_cmds_per_lun - Change max concurrent commands per sbp2 device (default = 1) * sbp2_exclusive_login - Set to zero if you'd like to allow multiple hosts the ability * to log in at the same time. Sbp2 device must support this, * and you must know what you're doing (default = 1) * * (e.g. insmod sbp2 sbp2_serialize_io = 1) * * * Current Support: * * The SBP-2 driver is still in an early state, but supports a variety of devices. * I have read/written many gigabytes of data from/to SBP-2 drives, and have seen * performance of more than 25 MBytes/s on individual drives (limit of the media * transfer rate). * * * Following are a sampling of devices that have been tested successfully: * * - Western Digital IEEE-1394 hard drives * - Maxtor IEEE-1394 hard drives * - VST (SmartDisk) IEEE-1394 hard drives and Zip drives (several flavors) * - LaCie IEEE-1394 hard drives (several flavors) * - QPS IEEE-1394 CD-RW/DVD drives and hard drives * - BusLink IEEE-1394 hard drives * - Iomega IEEE-1394 Zip/Jazz/Peerless drives * - ClubMac IEEE-1394 hard drives * - FirePower IEEE-1394 hard drives * - EzQuest IEEE-1394 hard drives and CD-RW drives * - Castlewood/ADS IEEE-1394 ORB drives * - Evergreen IEEE-1394 hard drives and CD-RW drives * - Addonics IEEE-1394 CD-RW drives * - Bellstor IEEE-1394 hard drives and CD-RW drives * - APDrives IEEE-1394 hard drives * - Fujitsu IEEE-1394 MO drives * - Sony IEEE-1394 CD-RW drives * - Epson IEEE-1394 scanners * - ADS IEEE-1394 memory stick and compact flash readers * - SBP-2 bridge-based devices (LSI, Oxford Semiconductor, Indigita bridges) * - Various other standard IEEE-1394 hard drives and enclosures * * * Performance Issues: * * - Make sure you are "not" running fat/fat32 on your attached SBP-2 drives. You'll * get much better performance formatting the drive ext2 (but you will lose the * ability to easily move the drive between Windows/Linux). * * * Current Issues: * * - Error Handling: SCSI aborts and bus reset requests are handled somewhat * but the code needs additional debugging. * * - Module: The SBP-2 driver is currently only supported as a module. It would not take * much work to allow it to be compiled into the kernel, but you'd have to * add some init code to the kernel to support this... and modules are much * more flexible anyway. ;-) * * - Hot-plugging: Interaction with the SCSI stack and support for hot-plugging could * stand some improvement. * * * History: * * 07/25/00 - Initial revision (JSG) * 08/11/00 - Following changes/bug fixes were made (JSG): * * Bug fix to SCSI procfs code (still needs to be synched with 2.4 kernel). * * Bug fix where request sense commands were actually sent on the bus. * * Changed bus reset/abort code to deal with devices that spin up quite * slowly (which result in SCSI time-outs). * * "More" properly pull information from device's config rom, for enumeration * of SBP-2 devices, and determining SBP-2 register offsets. * * Change Simplified Direct Access Device type to Direct Access Device type in * returned inquiry data, in order to make the SCSI stack happy. * * Modified driver to register with the SCSI stack "before" enumerating any attached * SBP-2 devices. This means that you'll have to use procfs scsi-add-device or * some sort of script to discover new SBP-2 devices. * * Minor re-write of some code and other minor changes. * 08/28/00 - Following changes/bug fixes were made (JSG): * * Bug fixes to scatter/gather support (case of one s/g element) * * Updated direction table for scsi commands (mostly DVD commands) * * Retries when trying to detect SBP-2 devices (for slow devices) * * Slightly better error handling (previously none) when commands time-out. * * Misc. other bug fixes and code reorganization. * 09/13/00 - Following changes/bug fixes were made (JSG) * * Moved detection/enumeration code to a kernel thread which is woken up when IEEE-1394 * bus resets occur. * * Added code to handle bus resets and hot-plugging while devices are mounted, but full * hot-plug support is not quite there yet. * * Now use speed map to determine speed and max payload sizes for ORBs * * Clean-up of code and reorganization * 09/19/00 - Added better hot-plug support and other minor changes (JSG) * 10/15/00 - Fixes for latest 2.4.0 test kernel, minor fix for hot-plug race. (JSG) * 12/03/00 - Created pool of request packet structures for use in sending out sbp2 command * and agent reset requests. This removes the kmallocs/kfrees in the critical I/O paths, * and also deals with some subtle race conditions related to allocating and freeing * packets. (JSG) * 12/09/00 - Improved the sbp2 device detection by actually reading the root and unit * directory (khk@khk.net) * 12/23/00 - Following changes/enhancements were made (JSG) * * Only do SCSI to RBC command conversion for Direct Access and Simplified * Direct Access Devices (this is pulled from the config rom root directory). * This is needed because doing the conversion for all device types broke the * Epson scanner. Still looking for a better way of determining when to convert * commands (for RBC devices). Thanks to khk for helping on this! * * Added ability to "emulate" physical dma support, for host adapters such as TILynx. * * Determine max payload and speed by also looking at the host adapter's max_rec field. * 01/19/01 - Added checks to sbp2 login and made the login time-out longer. Also fixed a compile * problem for 2.4.0. (JSG) * 01/24/01 - Fixed problem when individual s/g elements are 64KB or larger. Needed to break * up these larger elements, since the sbp2 page table element size is only 16 bits. (JSG) * 01/29/01 - Minor byteswap fix for login response (used for reconnect and log out). * 03/07/01 - Following changes/enhancements were made (JSG) * * Changes to allow us to catch the initial scsi bus scan (for detecting sbp2 * devices when first loading sbp2.o). To disable this, un-define * SBP2_SUPPORT_INITIAL_BUS_SCAN. * * Temporary fix to deal with many sbp2 devices that do not support individual * transfers of greater than 128KB in size. * * Mode sense conversion from 6 byte to 10 byte versions for CDRW/DVD devices. (Mark Burton) * * Define allowing support for goofy sbp2 devices that do not support mode * sense command at all, allowing them to be mounted rw (such as 1394 memory * stick and compact flash readers). Define SBP2_MODE_SENSE_WRITE_PROTECT_HACK * if you need this fix. * 03/29/01 - Major performance enhancements and misc. other changes. Thanks to Daniel Berlin for many of * changes and suggestions for change: * * Now use sbp2 doorbell and link commands on the fly (instead of serializing requests) * * Removed all bit fields in an attempt to run on PPC machines (still needs a little more work) * * Added large request break-up/linking support for sbp2 chipsets that do not support transfers * greater than 128KB in size. * * Bumped up max commands per lun to two, and max total outstanding commands to eight. * 04/03/01 - Minor clean-up. Write orb pointer directly if no outstanding commands (saves one 1394 bus * transaction). Added module load options (bus scan, mode sense hack, max speed, serialize_io, * no_large_transfers). Better bus reset handling while I/O pending. Set serialize_io to 1 by * default (debugging of deserialized I/O in progress). * 04/04/01 - Added workaround for PPC Pismo firewire chipset. See #define below. (Daniel Berlin) * 04/20/01 - Minor clean-up. Allocate more orb structures when running with sbp2 target chipsets with * 128KB max transfer limit. * 06/16/01 - Converted DMA interfaces to pci_dma - Ben Collins * <bcollins@debian.org * 07/22/01 - Use NodeMngr to get info about the local host and * attached devices. Ben Collins * * 09/15/01 - Remove detection code, instead subscribe to the nodemgr * driver management interface. This also removes the * initial bus scan stuff since the nodemgr calls * sbp2_probe for each sbp2 device already on the bus, * when we register our driver. This change * automtically adds hotplug support to the driver. * Kristian Hogsberg <hogsberg@users.sf.net> * * 11/17/01 - Various bugfixes/cleanups: * * Remember to logout of device in sbp2_disconnect. * * If we fail to reconnect to a device after bus reset * remember to release unit directory, so the ieee1394 * knows we no longer manage it. * * Unregister scsi hosts in sbp2_remove_host when a * hpsb_host goes away. * * Remove stupid hack in sbp2_remove_host. * * Switched to "manual" module initialization * (i.e. not scsi_module.c) and moved sbp2_cleanup * moved sbp2scsi_release to sbp2_module_ext. The * release function is called once pr. registered * scsi host, but sbp2_cleanup should only be called * upon module unload. Moved much initialization * from sbp2scsi_detect to sbp2_module_init. * Kristian Hogsberg <hogsberg@users.sf.net> * 01/06/02 - Misc bug fixes/enhancements: (JSG) * * Enable use_new_eh_code for scsi stuff. * * Do not write all ones for NULL ORB high/low fields, but * rather leave reserved areas zeroed (per SBP2 spec). * * Use newer scsi transfer direction passed down instead of our * direction table. * * Bumped login time-out to 20 seconds, as some devices are slow. * * Fixed a couple scsi unregister bugs on module unload * 01/13/02 - Fixed compatibility with certain SBP2 devices, such as Iomega * 1394 devices (Peerless, Jazz). Also a bit of clean-up of the * driver, thanks to H.J.Lu (hjl@lucon.org). Removed mode_sense_hack * module load option, as it's been fixed in the 2.4 scsi stack. * 02/10/02 - Added support for max_sectors, minor fix for inquiry command, make * up sbp2 device type from inquiry response data if not part of * device's 1394 unit directory. (JSG) * 02/18/02 - Code clean-up and enhancements: (JSG) * * Finish cleaning out hacked code for dealing with broken sbp2 devices * which do not support requests of 128KB or greater. Now use * max_sectors scsi host entry to limit transfer sizes. * * Change status fifo address from a single address to a set of addresses, * with each sbp2 device having its own status fifo address. This makes * it easier to match the status write to the sbp2 device instance. * * Minor change to use lun when logging into sbp2 devices. First step in * supporting multi-lun devices such as CD/DVD changer devices. * * Added a new module load option for setting max sectors. For use by folk * who'd like to bump up the max scsi transfer size supported. * * Enabled deserialized operation by default, allowing for better performance, * particularily when running with multiple sbp2 devices. For debugging, * you may enable serialization through use of the sbp2_serialize_io module * load option (e.g. insmod sbp2 sbp2_serialize_io=1). * 02/20/02 - Added a couple additional module load options. * Needed to bump down max commands per lun because of the !%@&*^# QPS CDRW * drive I have, which doesn't seem to get along with other sbp2 devices * (or handle linked commands well). * 04/21/02 - Added some additional debug capabilities: * * Able to handle phys dma requests directly, if host controller has phys * dma disabled (e.g. insmod ohci1394 phys_dma=0). Undefine CONFIG_IEEE1394_SBP2_PHYS_DMA * if you'd like to disable sbp2 driver from registering for phys address range. * * New packet dump debug define (CONFIG_IEEE1394_SBP2_PACKET_DUMP) which allows * dumping of all sbp2 related packets sent and received. Especially effective * when phys dma is disabled on ohci controller (e.g. insmod ohci1394 phys_dma=0). * * Added new sbp2 module load option (sbp2_exclusive_login) for allowing * non-exclusive login to sbp2 device, for special multi-host applications. * 04/23/02 - Fix for Sony CD-ROM drives. Only send fetch agent reset to sbp2 device if it * returns the dead bit in status. Thanks to Chandan (chandan@toad.net) for this one. * 04/27/02 - Fix sbp2 login problem on SMP systems, enable real spinlocks by default. (JSG) * 06/09/02 - Don't force 36-bute SCSI inquiry, but leave in a define for badly behaved devices. (JSG) *//* * Includes */#include <linux/config.h>#include <linux/kernel.h>#include <linux/list.h>#include <linux/string.h>#include <linux/slab.h>#include <linux/fs.h>#include <linux/poll.h>#include <linux/module.h>#include <linux/types.h>#include <linux/delay.h>#include <linux/sched.h>#include <linux/proc_fs.h>#include <linux/blk.h>#include <linux/smp_lock.h>#include <linux/init.h>#include <linux/blk.h>#include <asm/current.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/byteorder.h>#include <asm/atomic.h>#include <asm/system.h>#include <asm/io.h>#include <asm/scatterlist.h>#ifdef CONFIG_KBUILD_2_5#include <scsi.h>#include <hosts.h>#include <sd.h>#else#include "../scsi/scsi.h"#include "../scsi/hosts.h"#include "../scsi/sd.h"#endif#include "ieee1394.h"#include "ieee1394_types.h"#include "ieee1394_core.h"#include "hosts.h"#include "nodemgr.h"#include "highlevel.h"#include "ieee1394_transactions.h"#include "ieee1394_hotplug.h"#include "sbp2.h"static char version[] __devinitdata = "$Rev: 584 $ James Goodwin <jamesg@filanet.com>";/* * Module load parameter definitions *//* * Change sbp2_max_speed on module load if you have a bad IEEE-1394 * controller that has trouble running 2KB packets at 400mb. * * NOTE: On certain OHCI parts I have seen short packets on async transmit * (probably due to PCI latency/throughput issues with the part). You can * bump down the speed if you are running into problems. * * Valid values: * sbp2_max_speed = 2 (default: max speed 400mb) * sbp2_max_speed = 1 (max speed 200mb) * sbp2_max_speed = 0 (max speed 100mb) */MODULE_PARM(sbp2_max_speed,"i");MODULE_PARM_DESC(sbp2_max_speed, "Force max speed (2 = 400mb default, 1 = 200mb, 0 = 100mb)");static int sbp2_max_speed = SPEED_400;/* * Set sbp2_serialize_io to 1 if you'd like only one scsi command sent * down to us at a time (debugging). This might be necessary for very * badly behaved sbp2 devices. */MODULE_PARM(sbp2_serialize_io,"i");MODULE_PARM_DESC(sbp2_serialize_io, "Serialize all I/O coming down from the scsi drivers (default = 0)");static int sbp2_serialize_io = 0; /* serialize I/O - available for debugging purposes *//* * Bump up sbp2_max_sectors if you'd like to support very large sized * transfers. Please note that some older sbp2 bridge chips are broken for * transfers greater or equal to 128KB. Default is a value of 255 * sectors, or just under 128KB (at 512 byte sector size). I can note that * the Oxsemi sbp2 chipsets have no problems supporting very large
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -