📄 sbp2.c
字号:
/* * sbp2.c - SBP-2 protocol driver for IEEE-1394 * * Copyright (C) 2000 James Goodwin, Filanet Corporation (www.filanet.com) * jamesg@filanet.com * * 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.). * * * 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 16 MBytes/s on individual drives (limit of the media * transfer rate). * * Following are the 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 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 scanner * - ADS IEEE-1394 memory stick and compact flash readers * (e.g. "insmod sbp2 mode_sense_hack=1" for mem stick and 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: * * - Currently, all I/O from the scsi stack is serialized by default, as there * are some stress issues under investigation with deserialized I/O. To enable * deserialized I/O for testing, do "insmod sbp2 serialize_io=0" * * - Error Handling: SCSI aborts and bus reset requests are handled somewhat * but the code needs additional debugging. * * - 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. ;-) * * - The scsi stack in recent kernels pass down the data transfer * direction as scsicmd->sc_data_direction, which we should use * instead of the sbp2scsi_direction_table. * * * 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> *//* * 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 <asm/current.h>#include <asm/uaccess.h>#include <asm/io.h>#include <asm/byteorder.h>#include <asm/system.h>#include <asm/io.h>#include <asm/scatterlist.h>#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 "../scsi/scsi.h"#include "../scsi/hosts.h"#include "../scsi/sd.h"#include "sbp2.h"/* * Module load parameter definitions *//* * Set mode_sense_hack to 1 if you have some sort of unusual sbp2 device, * like a 1394 memory stick reader, compact flash reader, or MO drive that * does not support mode sense. Allows you to mount the media rw instead * of ro. */MODULE_PARM(mode_sense_hack,"i");MODULE_PARM_DESC(mode_sense_hack, "Emulate mode sense for devices like 1394 memory stick readers");static int mode_sense_hack = 0;/* * Change 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: * max_speed = 2 (default: max speed 400mb) * max_speed = 1 (max speed 200mb) * max_speed = 0 (max speed 100mb) */MODULE_PARM(max_speed,"i");MODULE_PARM_DESC(max_speed, "Force down max speed (2 = 400mb default, 1 = 200mb, 0 = 100mb)");static int max_speed = SPEED_400;/* * Set serialize_io to 1 if you'd like only one scsi command sent down to * us at a time (debugging). */MODULE_PARM(serialize_io,"i");MODULE_PARM_DESC(serialize_io, "Serialize all I/O coming down from the scsi drivers (debugging)");static int serialize_io = 1; /* serialize I/O until stress issues are resolved *//* * Set no_large_packets to 1 if you'd like to limit the size of requests * sent down to us (normally the sbp2 driver will break up any requests to * any individual devices with 128KB transfer size limits). Sets max s/g * list elements to 0x1f in size and disables s/g clustering. */MODULE_PARM(no_large_packets,"i");MODULE_PARM_DESC(no_large_packets, "Do not allow large transfers from scsi drivers (debugging)");static int no_large_packets = 0;/* * Export information about protocols/devices supported by this driver. */static struct ieee1394_device_id sbp2_id_table[] = { { match_flags: IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, specifier_id: SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff, version: SBP2_SW_VERSION_ENTRY & 0xffffff }, { }};MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table);/* * Debug levels, configured via kernel config. */#ifdef CONFIG_IEEE1394_SBP2_DEBUG_ORBS#define SBP2_ORB_DEBUG(fmt, args...) HPSB_ERR("sbp2("__FUNCTION__"): "fmt, ## args)static u32 global_outstanding_command_orbs = 0;#define outstanding_orb_incr global_outstanding_command_orbs++#define outstanding_orb_decr global_outstanding_command_orbs--#else#define SBP2_ORB_DEBUG(fmt, args...)#define outstanding_orb_incr#define outstanding_orb_decr#endif#ifdef CONFIG_IEEE1394_SBP2_DEBUG_DMA#define SBP2_DMA_ALLOC(fmt, args...) \ HPSB_ERR("sbp2("__FUNCTION__")alloc(%d): "fmt, \ ++global_outstanding_dmas, ## args)#define SBP2_DMA_FREE(fmt, args...) \ HPSB_ERR("sbp2("__FUNCTION__")free(%d): "fmt, \ --global_outstanding_dmas, ## args)static u32 global_outstanding_dmas = 0;#else#define SBP2_DMA_ALLOC(fmt, args...)#define SBP2_DMA_FREE(fmt, args...)#endif#if CONFIG_IEEE1394_SBP2_DEBUG >= 2#define SBP2_DEBUG(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)#define SBP2_INFO(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)#define SBP2_NOTICE(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)#define SBP2_WARN(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)#elif CONFIG_IEEE1394_SBP2_DEBUG == 1#define SBP2_DEBUG(fmt, args...) HPSB_DEBUG("sbp2: "fmt, ## args)#define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args)#define SBP2_NOTICE(fmt, args...) HPSB_NOTICE("sbp2: "fmt, ## args)#define SBP2_WARN(fmt, args...) HPSB_WARN("sbp2: "fmt, ## args)#else #define SBP2_DEBUG(fmt, args...)#define SBP2_INFO(fmt, args...)#define SBP2_NOTICE(fmt, args...)#define SBP2_WARN(fmt, args...)#endif#define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args)/* * Spinlock debugging stuff. I'm playing it safe until the driver has been * debugged on SMP. (JSG) *//* #define SBP2_USE_REAL_SPINLOCKS */#ifdef SBP2_USE_REAL_SPINLOCKS#define sbp2_spin_lock(lock, flags) spin_lock_irqsave(lock, flags) #define sbp2_spin_unlock(lock, flags) spin_unlock_irqrestore(lock, flags);static spinlock_t sbp2_host_info_lock = SPIN_LOCK_UNLOCKED;#else#define sbp2_spin_lock(lock, flags) do {save_flags(flags); cli();} while (0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -