Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sbp2.c - SBP-2 protocol driver for IEEE-1394 |
| 3 | * |
| 4 | * Copyright (C) 2000 James Goodwin, Filanet Corporation (www.filanet.com) |
| 5 | * jamesg@filanet.com (JSG) |
| 6 | * |
| 7 | * Copyright (C) 2003 Ben Collins <bcollins@debian.org> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software Foundation, |
| 21 | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * Brief Description: |
| 26 | * |
| 27 | * This driver implements the Serial Bus Protocol 2 (SBP-2) over IEEE-1394 |
| 28 | * under Linux. The SBP-2 driver is implemented as an IEEE-1394 high-level |
| 29 | * driver. It also registers as a SCSI lower-level driver in order to accept |
| 30 | * SCSI commands for transport using SBP-2. |
| 31 | * |
| 32 | * You may access any attached SBP-2 storage devices as if they were SCSI |
| 33 | * devices (e.g. mount /dev/sda1, fdisk, mkfs, etc.). |
| 34 | * |
| 35 | * Current Issues: |
| 36 | * |
| 37 | * - Error Handling: SCSI aborts and bus reset requests are handled somewhat |
| 38 | * but the code needs additional debugging. |
| 39 | */ |
| 40 | |
Stefan Richter | 902abed | 2006-08-14 18:56:00 +0200 | [diff] [blame] | 41 | #include <linux/blkdev.h> |
| 42 | #include <linux/compiler.h> |
| 43 | #include <linux/delay.h> |
| 44 | #include <linux/device.h> |
| 45 | #include <linux/dma-mapping.h> |
| 46 | #include <linux/gfp.h> |
| 47 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/kernel.h> |
| 49 | #include <linux/list.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #include <linux/module.h> |
| 51 | #include <linux/moduleparam.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/pci.h> |
Stefan Richter | 902abed | 2006-08-14 18:56:00 +0200 | [diff] [blame] | 53 | #include <linux/slab.h> |
| 54 | #include <linux/spinlock.h> |
| 55 | #include <linux/stat.h> |
| 56 | #include <linux/string.h> |
| 57 | #include <linux/stringify.h> |
| 58 | #include <linux/types.h> |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 59 | #include <linux/wait.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | #include <asm/byteorder.h> |
Stefan Richter | 902abed | 2006-08-14 18:56:00 +0200 | [diff] [blame] | 62 | #include <asm/errno.h> |
| 63 | #include <asm/param.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #include <asm/scatterlist.h> |
Stefan Richter | 902abed | 2006-08-14 18:56:00 +0200 | [diff] [blame] | 65 | #include <asm/system.h> |
| 66 | #include <asm/types.h> |
| 67 | |
| 68 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
| 69 | #include <asm/io.h> /* for bus_to_virt */ |
| 70 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | #include <scsi/scsi.h> |
| 73 | #include <scsi/scsi_cmnd.h> |
| 74 | #include <scsi/scsi_dbg.h> |
| 75 | #include <scsi/scsi_device.h> |
| 76 | #include <scsi/scsi_host.h> |
| 77 | |
| 78 | #include "csr1212.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #include "highlevel.h" |
Stefan Richter | 902abed | 2006-08-14 18:56:00 +0200 | [diff] [blame] | 80 | #include "hosts.h" |
| 81 | #include "ieee1394.h" |
| 82 | #include "ieee1394_core.h" |
| 83 | #include "ieee1394_hotplug.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | #include "ieee1394_transactions.h" |
Stefan Richter | 902abed | 2006-08-14 18:56:00 +0200 | [diff] [blame] | 85 | #include "ieee1394_types.h" |
| 86 | #include "nodemgr.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #include "sbp2.h" |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* |
| 90 | * Module load parameter definitions |
| 91 | */ |
| 92 | |
| 93 | /* |
| 94 | * Change max_speed on module load if you have a bad IEEE-1394 |
| 95 | * controller that has trouble running 2KB packets at 400mb. |
| 96 | * |
| 97 | * NOTE: On certain OHCI parts I have seen short packets on async transmit |
| 98 | * (probably due to PCI latency/throughput issues with the part). You can |
| 99 | * bump down the speed if you are running into problems. |
| 100 | */ |
| 101 | static int max_speed = IEEE1394_SPEED_MAX; |
| 102 | module_param(max_speed, int, 0644); |
Jody McIntyre | 2bab359 | 2005-09-30 11:59:07 -0700 | [diff] [blame] | 103 | MODULE_PARM_DESC(max_speed, "Force max speed (3 = 800mb, 2 = 400mb, 1 = 200mb, 0 = 100mb)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | /* |
| 106 | * Set serialize_io to 1 if you'd like only one scsi command sent |
| 107 | * down to us at a time (debugging). This might be necessary for very |
| 108 | * badly behaved sbp2 devices. |
Jody McIntyre | 2bab359 | 2005-09-30 11:59:07 -0700 | [diff] [blame] | 109 | * |
| 110 | * TODO: Make this configurable per device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | */ |
Jody McIntyre | 2bab359 | 2005-09-30 11:59:07 -0700 | [diff] [blame] | 112 | static int serialize_io = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | module_param(serialize_io, int, 0444); |
Jody McIntyre | 2bab359 | 2005-09-30 11:59:07 -0700 | [diff] [blame] | 114 | MODULE_PARM_DESC(serialize_io, "Serialize I/O coming from scsi drivers (default = 1, faster = 0)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * Bump up max_sectors if you'd like to support very large sized |
| 118 | * transfers. Please note that some older sbp2 bridge chips are broken for |
| 119 | * transfers greater or equal to 128KB. Default is a value of 255 |
| 120 | * sectors, or just under 128KB (at 512 byte sector size). I can note that |
| 121 | * the Oxsemi sbp2 chipsets have no problems supporting very large |
| 122 | * transfer sizes. |
| 123 | */ |
| 124 | static int max_sectors = SBP2_MAX_SECTORS; |
| 125 | module_param(max_sectors, int, 0444); |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 126 | MODULE_PARM_DESC(max_sectors, "Change max sectors per I/O supported (default = " |
| 127 | __stringify(SBP2_MAX_SECTORS) ")"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * Exclusive login to sbp2 device? In most cases, the sbp2 driver should |
| 131 | * do an exclusive login, as it's generally unsafe to have two hosts |
| 132 | * talking to a single sbp2 device at the same time (filesystem coherency, |
| 133 | * etc.). If you're running an sbp2 device that supports multiple logins, |
| 134 | * and you're either running read-only filesystems or some sort of special |
Ben Collins | 20f4578 | 2006-06-12 18:13:11 -0400 | [diff] [blame] | 135 | * filesystem supporting multiple hosts, e.g. OpenGFS, Oracle Cluster |
| 136 | * File System, or Lustre, then set exclusive_login to zero. |
| 137 | * |
| 138 | * So far only bridges from Oxford Semiconductor are known to support |
| 139 | * concurrent logins. Depending on firmware, four or two concurrent logins |
| 140 | * are possible on OXFW911 and newer Oxsemi bridges. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | */ |
| 142 | static int exclusive_login = 1; |
| 143 | module_param(exclusive_login, int, 0644); |
| 144 | MODULE_PARM_DESC(exclusive_login, "Exclusive login to sbp2 device (default = 1)"); |
| 145 | |
| 146 | /* |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 147 | * If any of the following workarounds is required for your device to work, |
| 148 | * please submit the kernel messages logged by sbp2 to the linux1394-devel |
| 149 | * mailing list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | * |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 151 | * - 128kB max transfer |
| 152 | * Limit transfer size. Necessary for some old bridges. |
| 153 | * |
| 154 | * - 36 byte inquiry |
| 155 | * When scsi_mod probes the device, let the inquiry command look like that |
| 156 | * from MS Windows. |
| 157 | * |
| 158 | * - skip mode page 8 |
| 159 | * Suppress sending of mode_sense for mode page 8 if the device pretends to |
| 160 | * support the SCSI Primary Block commands instead of Reduced Block Commands. |
Stefan Richter | e9a1c52 | 2006-05-15 22:06:37 +0200 | [diff] [blame] | 161 | * |
| 162 | * - fix capacity |
| 163 | * Tell sd_mod to correct the last sector number reported by read_capacity. |
| 164 | * Avoids access beyond actual disk limits on devices with an off-by-one bug. |
| 165 | * Don't use this with devices which don't have this bug. |
Stefan Richter | 679c0cd | 2006-05-15 22:08:09 +0200 | [diff] [blame] | 166 | * |
| 167 | * - override internal blacklist |
| 168 | * Instead of adding to the built-in blacklist, use only the workarounds |
| 169 | * specified in the module load parameter. |
| 170 | * Useful if a blacklist entry interfered with a non-broken device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | */ |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 172 | static int sbp2_default_workarounds; |
| 173 | module_param_named(workarounds, sbp2_default_workarounds, int, 0644); |
| 174 | MODULE_PARM_DESC(workarounds, "Work around device bugs (default = 0" |
| 175 | ", 128kB max transfer = " __stringify(SBP2_WORKAROUND_128K_MAX_TRANS) |
| 176 | ", 36 byte inquiry = " __stringify(SBP2_WORKAROUND_INQUIRY_36) |
| 177 | ", skip mode page 8 = " __stringify(SBP2_WORKAROUND_MODE_SENSE_8) |
Stefan Richter | e9a1c52 | 2006-05-15 22:06:37 +0200 | [diff] [blame] | 178 | ", fix capacity = " __stringify(SBP2_WORKAROUND_FIX_CAPACITY) |
Stefan Richter | 679c0cd | 2006-05-15 22:08:09 +0200 | [diff] [blame] | 179 | ", override internal blacklist = " __stringify(SBP2_WORKAROUND_OVERRIDE) |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 180 | ", or a combination)"); |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 183 | #define SBP2_INFO(fmt, args...) HPSB_INFO("sbp2: "fmt, ## args) |
| 184 | #define SBP2_ERR(fmt, args...) HPSB_ERR("sbp2: "fmt, ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | /* |
| 187 | * Globals |
| 188 | */ |
Stefan Richter | ea42ea0 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 189 | static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *, u32); |
| 190 | static void sbp2scsi_complete_command(struct scsi_id_instance_data *, u32, |
| 191 | struct scsi_cmnd *, |
| 192 | void (*)(struct scsi_cmnd *)); |
| 193 | static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *); |
| 194 | static int sbp2_start_device(struct scsi_id_instance_data *); |
| 195 | static void sbp2_remove_device(struct scsi_id_instance_data *); |
| 196 | static int sbp2_login_device(struct scsi_id_instance_data *); |
| 197 | static int sbp2_reconnect_device(struct scsi_id_instance_data *); |
| 198 | static int sbp2_logout_device(struct scsi_id_instance_data *); |
| 199 | static void sbp2_host_reset(struct hpsb_host *); |
| 200 | static int sbp2_handle_status_write(struct hpsb_host *, int, int, quadlet_t *, |
| 201 | u64, size_t, u16); |
| 202 | static int sbp2_agent_reset(struct scsi_id_instance_data *, int); |
| 203 | static void sbp2_parse_unit_directory(struct scsi_id_instance_data *, |
| 204 | struct unit_directory *); |
| 205 | static int sbp2_set_busy_timeout(struct scsi_id_instance_data *); |
| 206 | static int sbp2_max_speed_and_size(struct scsi_id_instance_data *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | static const u8 sbp2_speedto_max_payload[] = { 0x7, 0x8, 0x9, 0xA, 0xB, 0xC }; |
| 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | static struct hpsb_highlevel sbp2_highlevel = { |
Stefan Richter | ea42ea0 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 212 | .name = SBP2_DEVICE_NAME, |
| 213 | .host_reset = sbp2_host_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | static struct hpsb_address_ops sbp2_ops = { |
Stefan Richter | ea42ea0 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 217 | .write = sbp2_handle_status_write |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | }; |
| 219 | |
| 220 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
Stefan Richter | ea42ea0 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 221 | static int sbp2_handle_physdma_write(struct hpsb_host *, int, int, quadlet_t *, |
| 222 | u64, size_t, u16); |
| 223 | static int sbp2_handle_physdma_read(struct hpsb_host *, int, quadlet_t *, u64, |
| 224 | size_t, u16); |
| 225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | static struct hpsb_address_ops sbp2_physdma_ops = { |
Stefan Richter | ea42ea0 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 227 | .read = sbp2_handle_physdma_read, |
| 228 | .write = sbp2_handle_physdma_write, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | }; |
| 230 | #endif |
| 231 | |
Stefan Richter | ea42ea0 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 232 | |
| 233 | /* |
| 234 | * Interface to driver core and IEEE 1394 core |
| 235 | */ |
| 236 | static struct ieee1394_device_id sbp2_id_table[] = { |
| 237 | { |
| 238 | .match_flags = IEEE1394_MATCH_SPECIFIER_ID | IEEE1394_MATCH_VERSION, |
| 239 | .specifier_id = SBP2_UNIT_SPEC_ID_ENTRY & 0xffffff, |
| 240 | .version = SBP2_SW_VERSION_ENTRY & 0xffffff}, |
| 241 | {} |
| 242 | }; |
| 243 | MODULE_DEVICE_TABLE(ieee1394, sbp2_id_table); |
| 244 | |
| 245 | static int sbp2_probe(struct device *); |
| 246 | static int sbp2_remove(struct device *); |
| 247 | static int sbp2_update(struct unit_directory *); |
| 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | static struct hpsb_protocol_driver sbp2_driver = { |
| 250 | .name = "SBP2 Driver", |
| 251 | .id_table = sbp2_id_table, |
| 252 | .update = sbp2_update, |
| 253 | .driver = { |
| 254 | .name = SBP2_DEVICE_NAME, |
| 255 | .bus = &ieee1394_bus_type, |
| 256 | .probe = sbp2_probe, |
| 257 | .remove = sbp2_remove, |
| 258 | }, |
| 259 | }; |
| 260 | |
Stefan Richter | ea42ea0 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * Interface to SCSI core |
| 264 | */ |
| 265 | static int sbp2scsi_queuecommand(struct scsi_cmnd *, |
| 266 | void (*)(struct scsi_cmnd *)); |
| 267 | static int sbp2scsi_abort(struct scsi_cmnd *); |
| 268 | static int sbp2scsi_reset(struct scsi_cmnd *); |
| 269 | static int sbp2scsi_slave_alloc(struct scsi_device *); |
| 270 | static int sbp2scsi_slave_configure(struct scsi_device *); |
| 271 | static void sbp2scsi_slave_destroy(struct scsi_device *); |
| 272 | static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *, |
| 273 | struct device_attribute *, char *); |
| 274 | |
| 275 | static DEVICE_ATTR(ieee1394_id, S_IRUGO, sbp2_sysfs_ieee1394_id_show, NULL); |
| 276 | |
| 277 | static struct device_attribute *sbp2_sysfs_sdev_attrs[] = { |
| 278 | &dev_attr_ieee1394_id, |
| 279 | NULL |
| 280 | }; |
| 281 | |
| 282 | static struct scsi_host_template scsi_driver_template = { |
| 283 | .module = THIS_MODULE, |
| 284 | .name = "SBP-2 IEEE-1394", |
| 285 | .proc_name = SBP2_DEVICE_NAME, |
| 286 | .queuecommand = sbp2scsi_queuecommand, |
| 287 | .eh_abort_handler = sbp2scsi_abort, |
| 288 | .eh_device_reset_handler = sbp2scsi_reset, |
| 289 | .slave_alloc = sbp2scsi_slave_alloc, |
| 290 | .slave_configure = sbp2scsi_slave_configure, |
| 291 | .slave_destroy = sbp2scsi_slave_destroy, |
| 292 | .this_id = -1, |
| 293 | .sg_tablesize = SG_ALL, |
| 294 | .use_clustering = ENABLE_CLUSTERING, |
| 295 | .cmd_per_lun = SBP2_MAX_CMDS, |
| 296 | .can_queue = SBP2_MAX_CMDS, |
| 297 | .emulated = 1, |
| 298 | .sdev_attrs = sbp2_sysfs_sdev_attrs, |
| 299 | }; |
| 300 | |
| 301 | |
Stefan Richter | a80614d | 2006-02-14 22:04:19 -0500 | [diff] [blame] | 302 | /* |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 303 | * List of devices with known bugs. |
| 304 | * |
| 305 | * The firmware_revision field, masked with 0xffff00, is the best indicator |
| 306 | * for the type of bridge chip of a device. It yields a few false positives |
| 307 | * but this did not break correctly behaving devices so far. |
Stefan Richter | a80614d | 2006-02-14 22:04:19 -0500 | [diff] [blame] | 308 | */ |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 309 | static const struct { |
| 310 | u32 firmware_revision; |
Stefan Richter | e9a1c52 | 2006-05-15 22:06:37 +0200 | [diff] [blame] | 311 | u32 model_id; |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 312 | unsigned workarounds; |
| 313 | } sbp2_workarounds_table[] = { |
Ben Collins | 4b9a334 | 2006-06-12 18:10:18 -0400 | [diff] [blame] | 314 | /* DViCO Momobay CX-1 with TSB42AA9 bridge */ { |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 315 | .firmware_revision = 0x002800, |
Ben Collins | 4b9a334 | 2006-06-12 18:10:18 -0400 | [diff] [blame] | 316 | .model_id = 0x001010, |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 317 | .workarounds = SBP2_WORKAROUND_INQUIRY_36 | |
| 318 | SBP2_WORKAROUND_MODE_SENSE_8, |
| 319 | }, |
| 320 | /* Initio bridges, actually only needed for some older ones */ { |
| 321 | .firmware_revision = 0x000200, |
| 322 | .workarounds = SBP2_WORKAROUND_INQUIRY_36, |
| 323 | }, |
| 324 | /* Symbios bridge */ { |
| 325 | .firmware_revision = 0xa0b800, |
| 326 | .workarounds = SBP2_WORKAROUND_128K_MAX_TRANS, |
Stefan Richter | e9a1c52 | 2006-05-15 22:06:37 +0200 | [diff] [blame] | 327 | }, |
| 328 | /* |
| 329 | * Note about the following Apple iPod blacklist entries: |
| 330 | * |
| 331 | * There are iPods (2nd gen, 3rd gen) with model_id==0. Since our |
| 332 | * matching logic treats 0 as a wildcard, we cannot match this ID |
| 333 | * without rewriting the matching routine. Fortunately these iPods |
| 334 | * do not feature the read_capacity bug according to one report. |
| 335 | * Read_capacity behaviour as well as model_id could change due to |
| 336 | * Apple-supplied firmware updates though. |
| 337 | */ |
| 338 | /* iPod 4th generation */ { |
| 339 | .firmware_revision = 0x0a2700, |
| 340 | .model_id = 0x000021, |
| 341 | .workarounds = SBP2_WORKAROUND_FIX_CAPACITY, |
| 342 | }, |
| 343 | /* iPod mini */ { |
| 344 | .firmware_revision = 0x0a2700, |
| 345 | .model_id = 0x000023, |
| 346 | .workarounds = SBP2_WORKAROUND_FIX_CAPACITY, |
| 347 | }, |
| 348 | /* iPod Photo */ { |
| 349 | .firmware_revision = 0x0a2700, |
| 350 | .model_id = 0x00007e, |
| 351 | .workarounds = SBP2_WORKAROUND_FIX_CAPACITY, |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 352 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | }; |
| 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | /************************************** |
| 356 | * General utility functions |
| 357 | **************************************/ |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | #ifndef __BIG_ENDIAN |
| 360 | /* |
| 361 | * Converts a buffer from be32 to cpu byte ordering. Length is in bytes. |
| 362 | */ |
Stefan Richter | 2b01b80 | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 363 | static inline void sbp2util_be32_to_cpu_buffer(void *buffer, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | { |
| 365 | u32 *temp = buffer; |
| 366 | |
| 367 | for (length = (length >> 2); length--; ) |
| 368 | temp[length] = be32_to_cpu(temp[length]); |
| 369 | |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | /* |
| 374 | * Converts a buffer from cpu to be32 byte ordering. Length is in bytes. |
| 375 | */ |
Stefan Richter | 2b01b80 | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 376 | static inline void sbp2util_cpu_to_be32_buffer(void *buffer, int length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | u32 *temp = buffer; |
| 379 | |
| 380 | for (length = (length >> 2); length--; ) |
| 381 | temp[length] = cpu_to_be32(temp[length]); |
| 382 | |
| 383 | return; |
| 384 | } |
| 385 | #else /* BIG_ENDIAN */ |
| 386 | /* Why waste the cpu cycles? */ |
Stefan Richter | 611aa19 | 2006-08-02 18:44:00 +0200 | [diff] [blame] | 387 | #define sbp2util_be32_to_cpu_buffer(x,y) do {} while (0) |
| 388 | #define sbp2util_cpu_to_be32_buffer(x,y) do {} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | #endif |
| 390 | |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 391 | static DECLARE_WAIT_QUEUE_HEAD(access_wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 393 | /* |
| 394 | * Waits for completion of an SBP-2 access request. |
| 395 | * Returns nonzero if timed out or prematurely interrupted. |
| 396 | */ |
| 397 | static int sbp2util_access_timeout(struct scsi_id_instance_data *scsi_id, |
| 398 | int timeout) |
| 399 | { |
| 400 | long leftover = wait_event_interruptible_timeout( |
| 401 | access_wq, scsi_id->access_complete, timeout); |
| 402 | |
| 403 | scsi_id->access_complete = 0; |
| 404 | return leftover <= 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 407 | /* Frees an allocated packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | static void sbp2_free_packet(struct hpsb_packet *packet) |
| 409 | { |
| 410 | hpsb_free_tlabel(packet); |
| 411 | hpsb_free_packet(packet); |
| 412 | } |
| 413 | |
| 414 | /* This is much like hpsb_node_write(), except it ignores the response |
| 415 | * subaction and returns immediately. Can be used from interrupts. |
| 416 | */ |
| 417 | static int sbp2util_node_write_no_wait(struct node_entry *ne, u64 addr, |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 418 | quadlet_t *buffer, size_t length) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
| 420 | struct hpsb_packet *packet; |
| 421 | |
| 422 | packet = hpsb_make_writepacket(ne->host, ne->nodeid, |
| 423 | addr, buffer, length); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 424 | if (!packet) |
| 425 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 427 | hpsb_set_packet_complete_task(packet, |
| 428 | (void (*)(void *))sbp2_free_packet, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | packet); |
| 430 | |
| 431 | hpsb_node_fill_packet(ne, packet); |
| 432 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 433 | if (hpsb_send_packet(packet) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | sbp2_free_packet(packet); |
| 435 | return -EIO; |
| 436 | } |
| 437 | |
| 438 | return 0; |
| 439 | } |
| 440 | |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 441 | static void sbp2util_notify_fetch_agent(struct scsi_id_instance_data *scsi_id, |
| 442 | u64 offset, quadlet_t *data, size_t len) |
| 443 | { |
| 444 | /* |
| 445 | * There is a small window after a bus reset within which the node |
| 446 | * entry's generation is current but the reconnect wasn't completed. |
| 447 | */ |
Stefan Richter | 2cccbb5 | 2006-08-14 18:59:00 +0200 | [diff] [blame] | 448 | if (unlikely(atomic_read(&scsi_id->state) == SBP2LU_STATE_IN_RESET)) |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 449 | return; |
| 450 | |
| 451 | if (hpsb_node_write(scsi_id->ne, |
| 452 | scsi_id->sbp2_command_block_agent_addr + offset, |
| 453 | data, len)) |
| 454 | SBP2_ERR("sbp2util_notify_fetch_agent failed."); |
| 455 | /* |
| 456 | * Now accept new SCSI commands, unless a bus reset happended during |
| 457 | * hpsb_node_write. |
| 458 | */ |
Stefan Richter | 2cccbb5 | 2006-08-14 18:59:00 +0200 | [diff] [blame] | 459 | if (likely(atomic_read(&scsi_id->state) != SBP2LU_STATE_IN_RESET)) |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 460 | scsi_unblock_requests(scsi_id->scsi_host); |
| 461 | } |
| 462 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 463 | static void sbp2util_write_orb_pointer(struct work_struct *work) |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 464 | { |
| 465 | quadlet_t data[2]; |
| 466 | |
Stefan Richter | d19c776 | 2006-12-07 22:40:33 +0100 | [diff] [blame^] | 467 | data[0] = ORB_SET_NODE_ID( |
| 468 | (container_of(work, struct scsi_id_instance_data, protocol_work))->hi->host->node_id); |
| 469 | data[1] = (container_of(work, struct scsi_id_instance_data, protocol_work))->last_orb_dma; |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 470 | sbp2util_cpu_to_be32_buffer(data, 8); |
Stefan Richter | d19c776 | 2006-12-07 22:40:33 +0100 | [diff] [blame^] | 471 | sbp2util_notify_fetch_agent(container_of(work, struct scsi_id_instance_data, protocol_work), SBP2_ORB_POINTER_OFFSET, data, 8); |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 472 | } |
| 473 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 474 | static void sbp2util_write_doorbell(struct work_struct *work) |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 475 | { |
Stefan Richter | d19c776 | 2006-12-07 22:40:33 +0100 | [diff] [blame^] | 476 | sbp2util_notify_fetch_agent(container_of(work, struct scsi_id_instance_data, protocol_work), SBP2_DOORBELL_OFFSET, NULL, 4); |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | /* |
| 480 | * This function is called to create a pool of command orbs used for |
| 481 | * command processing. It is called when a new sbp2 device is detected. |
| 482 | */ |
| 483 | static int sbp2util_create_command_orb_pool(struct scsi_id_instance_data *scsi_id) |
| 484 | { |
| 485 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 486 | int i; |
| 487 | unsigned long flags, orbs; |
| 488 | struct sbp2_command_info *command; |
| 489 | |
| 490 | orbs = serialize_io ? 2 : SBP2_MAX_CMDS; |
| 491 | |
| 492 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
| 493 | for (i = 0; i < orbs; i++) { |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 494 | command = kzalloc(sizeof(*command), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | if (!command) { |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 496 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, |
| 497 | flags); |
| 498 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | command->command_orb_dma = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 501 | pci_map_single(hi->host->pdev, &command->command_orb, |
| 502 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 503 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | command->sge_dma = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 505 | pci_map_single(hi->host->pdev, |
| 506 | &command->scatter_gather_element, |
| 507 | sizeof(command->scatter_gather_element), |
| 508 | PCI_DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | INIT_LIST_HEAD(&command->list); |
| 510 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed); |
| 511 | } |
| 512 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
| 513 | return 0; |
| 514 | } |
| 515 | |
| 516 | /* |
| 517 | * This function is called to delete a pool of command orbs. |
| 518 | */ |
| 519 | static void sbp2util_remove_command_orb_pool(struct scsi_id_instance_data *scsi_id) |
| 520 | { |
| 521 | struct hpsb_host *host = scsi_id->hi->host; |
| 522 | struct list_head *lh, *next; |
| 523 | struct sbp2_command_info *command; |
| 524 | unsigned long flags; |
| 525 | |
| 526 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
| 527 | if (!list_empty(&scsi_id->sbp2_command_orb_completed)) { |
| 528 | list_for_each_safe(lh, next, &scsi_id->sbp2_command_orb_completed) { |
| 529 | command = list_entry(lh, struct sbp2_command_info, list); |
| 530 | |
| 531 | /* Release our generic DMA's */ |
| 532 | pci_unmap_single(host->pdev, command->command_orb_dma, |
| 533 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 534 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | pci_unmap_single(host->pdev, command->sge_dma, |
| 536 | sizeof(command->scatter_gather_element), |
| 537 | PCI_DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | kfree(command); |
| 539 | } |
| 540 | } |
| 541 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
| 542 | return; |
| 543 | } |
| 544 | |
| 545 | /* |
| 546 | * This function finds the sbp2_command for a given outstanding command |
| 547 | * orb.Only looks at the inuse list. |
| 548 | */ |
| 549 | static struct sbp2_command_info *sbp2util_find_command_for_orb( |
| 550 | struct scsi_id_instance_data *scsi_id, dma_addr_t orb) |
| 551 | { |
| 552 | struct sbp2_command_info *command; |
| 553 | unsigned long flags; |
| 554 | |
| 555 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
| 556 | if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) { |
| 557 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) { |
| 558 | if (command->command_orb_dma == orb) { |
| 559 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 560 | return command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | } |
| 562 | } |
| 563 | } |
| 564 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 565 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* |
| 569 | * This function finds the sbp2_command for a given outstanding SCpnt. |
| 570 | * Only looks at the inuse list. |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 571 | * Must be called with scsi_id->sbp2_command_orb_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | */ |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 573 | static struct sbp2_command_info *sbp2util_find_command_for_SCpnt( |
| 574 | struct scsi_id_instance_data *scsi_id, void *SCpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
| 576 | struct sbp2_command_info *command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 578 | if (!list_empty(&scsi_id->sbp2_command_orb_inuse)) |
| 579 | list_for_each_entry(command, &scsi_id->sbp2_command_orb_inuse, list) |
| 580 | if (command->Current_SCpnt == SCpnt) |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 581 | return command; |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 582 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | /* |
| 586 | * This function allocates a command orb used to send a scsi command. |
| 587 | */ |
| 588 | static struct sbp2_command_info *sbp2util_allocate_command_orb( |
| 589 | struct scsi_id_instance_data *scsi_id, |
| 590 | struct scsi_cmnd *Current_SCpnt, |
| 591 | void (*Current_done)(struct scsi_cmnd *)) |
| 592 | { |
| 593 | struct list_head *lh; |
| 594 | struct sbp2_command_info *command = NULL; |
| 595 | unsigned long flags; |
| 596 | |
| 597 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
| 598 | if (!list_empty(&scsi_id->sbp2_command_orb_completed)) { |
| 599 | lh = scsi_id->sbp2_command_orb_completed.next; |
| 600 | list_del(lh); |
| 601 | command = list_entry(lh, struct sbp2_command_info, list); |
| 602 | command->Current_done = Current_done; |
| 603 | command->Current_SCpnt = Current_SCpnt; |
| 604 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_inuse); |
| 605 | } else { |
Stefan Richter | d024ebc | 2006-03-28 20:03:55 -0500 | [diff] [blame] | 606 | SBP2_ERR("%s: no orbs available", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | } |
| 608 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 609 | return command; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* Free our DMA's */ |
| 613 | static void sbp2util_free_command_dma(struct sbp2_command_info *command) |
| 614 | { |
| 615 | struct scsi_id_instance_data *scsi_id = |
| 616 | (struct scsi_id_instance_data *)command->Current_SCpnt->device->host->hostdata[0]; |
| 617 | struct hpsb_host *host; |
| 618 | |
| 619 | if (!scsi_id) { |
Stefan Richter | d024ebc | 2006-03-28 20:03:55 -0500 | [diff] [blame] | 620 | SBP2_ERR("%s: scsi_id == NULL", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | return; |
| 622 | } |
| 623 | |
| 624 | host = scsi_id->ud->ne->host; |
| 625 | |
| 626 | if (command->cmd_dma) { |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 627 | if (command->dma_type == CMD_DMA_SINGLE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | pci_unmap_single(host->pdev, command->cmd_dma, |
| 629 | command->dma_size, command->dma_dir); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 630 | else if (command->dma_type == CMD_DMA_PAGE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | pci_unmap_page(host->pdev, command->cmd_dma, |
| 632 | command->dma_size, command->dma_dir); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 633 | /* XXX: Check for CMD_DMA_NONE bug */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | command->dma_type = CMD_DMA_NONE; |
| 635 | command->cmd_dma = 0; |
| 636 | } |
| 637 | |
| 638 | if (command->sge_buffer) { |
| 639 | pci_unmap_sg(host->pdev, command->sge_buffer, |
| 640 | command->dma_size, command->dma_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | command->sge_buffer = NULL; |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | /* |
| 646 | * This function moves a command to the completed orb list. |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 647 | * Must be called with scsi_id->sbp2_command_orb_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | */ |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 649 | static void sbp2util_mark_command_completed( |
| 650 | struct scsi_id_instance_data *scsi_id, |
| 651 | struct sbp2_command_info *command) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | list_del(&command->list); |
| 654 | sbp2util_free_command_dma(command); |
| 655 | list_add_tail(&command->list, &scsi_id->sbp2_command_orb_completed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | } |
| 657 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 658 | /* |
| 659 | * Is scsi_id valid? Is the 1394 node still present? |
| 660 | */ |
| 661 | static inline int sbp2util_node_is_available(struct scsi_id_instance_data *scsi_id) |
| 662 | { |
| 663 | return scsi_id && scsi_id->ne && !scsi_id->ne->in_limbo; |
| 664 | } |
| 665 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | /********************************************* |
| 667 | * IEEE-1394 core driver stack related section |
| 668 | *********************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
| 670 | static int sbp2_probe(struct device *dev) |
| 671 | { |
| 672 | struct unit_directory *ud; |
| 673 | struct scsi_id_instance_data *scsi_id; |
| 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | ud = container_of(dev, struct unit_directory, device); |
| 676 | |
| 677 | /* Don't probe UD's that have the LUN flag. We'll probe the LUN(s) |
| 678 | * instead. */ |
| 679 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN_DIRECTORY) |
| 680 | return -ENODEV; |
| 681 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 682 | scsi_id = sbp2_alloc_device(ud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 684 | if (!scsi_id) |
| 685 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 687 | sbp2_parse_unit_directory(scsi_id, ud); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 689 | return sbp2_start_device(scsi_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | static int sbp2_remove(struct device *dev) |
| 693 | { |
| 694 | struct unit_directory *ud; |
| 695 | struct scsi_id_instance_data *scsi_id; |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 696 | struct scsi_device *sdev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | ud = container_of(dev, struct unit_directory, device); |
| 699 | scsi_id = ud->device.driver_data; |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 700 | if (!scsi_id) |
| 701 | return 0; |
| 702 | |
Stefan Richter | bf637ec | 2006-01-31 00:13:06 -0500 | [diff] [blame] | 703 | if (scsi_id->scsi_host) { |
| 704 | /* Get rid of enqueued commands if there is no chance to |
| 705 | * send them. */ |
| 706 | if (!sbp2util_node_is_available(scsi_id)) |
| 707 | sbp2scsi_complete_all_commands(scsi_id, DID_NO_CONNECT); |
| 708 | /* scsi_remove_device() will trigger shutdown functions of SCSI |
| 709 | * highlevel drivers which would deadlock if blocked. */ |
Stefan Richter | 2cccbb5 | 2006-08-14 18:59:00 +0200 | [diff] [blame] | 710 | atomic_set(&scsi_id->state, SBP2LU_STATE_IN_SHUTDOWN); |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 711 | scsi_unblock_requests(scsi_id->scsi_host); |
Stefan Richter | bf637ec | 2006-01-31 00:13:06 -0500 | [diff] [blame] | 712 | } |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 713 | sdev = scsi_id->sdev; |
| 714 | if (sdev) { |
| 715 | scsi_id->sdev = NULL; |
| 716 | scsi_remove_device(sdev); |
| 717 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
| 719 | sbp2_logout_device(scsi_id); |
| 720 | sbp2_remove_device(scsi_id); |
| 721 | |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | static int sbp2_update(struct unit_directory *ud) |
| 726 | { |
| 727 | struct scsi_id_instance_data *scsi_id = ud->device.driver_data; |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | if (sbp2_reconnect_device(scsi_id)) { |
| 730 | |
| 731 | /* |
| 732 | * Ok, reconnect has failed. Perhaps we didn't |
| 733 | * reconnect fast enough. Try doing a regular login, but |
| 734 | * first do a logout just in case of any weirdness. |
| 735 | */ |
| 736 | sbp2_logout_device(scsi_id); |
| 737 | |
| 738 | if (sbp2_login_device(scsi_id)) { |
| 739 | /* Login failed too, just fail, and the backend |
| 740 | * will call our sbp2_remove for us */ |
| 741 | SBP2_ERR("Failed to reconnect to sbp2 device!"); |
| 742 | return -EBUSY; |
| 743 | } |
| 744 | } |
| 745 | |
| 746 | /* Set max retries to something large on the device. */ |
| 747 | sbp2_set_busy_timeout(scsi_id); |
| 748 | |
| 749 | /* Do a SBP-2 fetch agent reset. */ |
| 750 | sbp2_agent_reset(scsi_id, 1); |
| 751 | |
| 752 | /* Get the max speed and packet size that we can use. */ |
| 753 | sbp2_max_speed_and_size(scsi_id); |
| 754 | |
| 755 | /* Complete any pending commands with busy (so they get |
| 756 | * retried) and remove them from our queue |
| 757 | */ |
| 758 | sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); |
| 759 | |
Stefan Richter | 4fc383c | 2006-08-14 18:46:00 +0200 | [diff] [blame] | 760 | /* Accept new commands unless there was another bus reset in the |
| 761 | * meantime. */ |
| 762 | if (hpsb_node_entry_valid(scsi_id->ne)) { |
Stefan Richter | 2cccbb5 | 2006-08-14 18:59:00 +0200 | [diff] [blame] | 763 | atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING); |
Stefan Richter | 4fc383c | 2006-08-14 18:46:00 +0200 | [diff] [blame] | 764 | scsi_unblock_requests(scsi_id->scsi_host); |
| 765 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | /* This functions is called by the sbp2_probe, for each new device. We now |
| 770 | * allocate one scsi host for each scsi_id (unit directory). */ |
| 771 | static struct scsi_id_instance_data *sbp2_alloc_device(struct unit_directory *ud) |
| 772 | { |
| 773 | struct sbp2scsi_host_info *hi; |
| 774 | struct Scsi_Host *scsi_host = NULL; |
| 775 | struct scsi_id_instance_data *scsi_id = NULL; |
| 776 | |
Stefan Richter | 8551158 | 2005-11-07 06:31:45 -0500 | [diff] [blame] | 777 | scsi_id = kzalloc(sizeof(*scsi_id), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | if (!scsi_id) { |
| 779 | SBP2_ERR("failed to create scsi_id"); |
| 780 | goto failed_alloc; |
| 781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
| 783 | scsi_id->ne = ud->ne; |
| 784 | scsi_id->ud = ud; |
| 785 | scsi_id->speed_code = IEEE1394_SPEED_100; |
| 786 | scsi_id->max_payload_size = sbp2_speedto_max_payload[IEEE1394_SPEED_100]; |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 787 | scsi_id->status_fifo_addr = CSR1212_INVALID_ADDR_SPACE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_inuse); |
| 789 | INIT_LIST_HEAD(&scsi_id->sbp2_command_orb_completed); |
| 790 | INIT_LIST_HEAD(&scsi_id->scsi_list); |
| 791 | spin_lock_init(&scsi_id->sbp2_command_orb_lock); |
Stefan Richter | 2cccbb5 | 2006-08-14 18:59:00 +0200 | [diff] [blame] | 792 | atomic_set(&scsi_id->state, SBP2LU_STATE_RUNNING); |
Stefan Richter | d19c776 | 2006-12-07 22:40:33 +0100 | [diff] [blame^] | 793 | INIT_WORK(&scsi_id->protocol_work, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | |
| 795 | ud->device.driver_data = scsi_id; |
| 796 | |
| 797 | hi = hpsb_get_hostinfo(&sbp2_highlevel, ud->ne->host); |
| 798 | if (!hi) { |
| 799 | hi = hpsb_create_hostinfo(&sbp2_highlevel, ud->ne->host, sizeof(*hi)); |
| 800 | if (!hi) { |
| 801 | SBP2_ERR("failed to allocate hostinfo"); |
| 802 | goto failed_alloc; |
| 803 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | hi->host = ud->ne->host; |
| 805 | INIT_LIST_HEAD(&hi->scsi_ids); |
| 806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
| 808 | /* Handle data movement if physical dma is not |
Stefan Richter | 5566405 | 2006-03-28 19:59:42 -0500 | [diff] [blame] | 809 | * enabled or not supported on host controller */ |
| 810 | if (!hpsb_register_addrspace(&sbp2_highlevel, ud->ne->host, |
| 811 | &sbp2_physdma_ops, |
| 812 | 0x0ULL, 0xfffffffcULL)) { |
| 813 | SBP2_ERR("failed to register lower 4GB address range"); |
| 814 | goto failed_alloc; |
| 815 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | #endif |
| 817 | } |
| 818 | |
Stefan Richter | 147830f | 2006-03-28 19:54:52 -0500 | [diff] [blame] | 819 | /* Prevent unloading of the 1394 host */ |
| 820 | if (!try_module_get(hi->host->driver->owner)) { |
| 821 | SBP2_ERR("failed to get a reference on 1394 host driver"); |
| 822 | goto failed_alloc; |
| 823 | } |
| 824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | scsi_id->hi = hi; |
| 826 | |
| 827 | list_add_tail(&scsi_id->scsi_list, &hi->scsi_ids); |
| 828 | |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 829 | /* Register the status FIFO address range. We could use the same FIFO |
| 830 | * for targets at different nodes. However we need different FIFOs per |
Stefan Richter | a54c9d3 | 2006-05-15 22:09:46 +0200 | [diff] [blame] | 831 | * target in order to support multi-unit devices. |
| 832 | * The FIFO is located out of the local host controller's physical range |
| 833 | * but, if possible, within the posted write area. Status writes will |
| 834 | * then be performed as unified transactions. This slightly reduces |
| 835 | * bandwidth usage, and some Prolific based devices seem to require it. |
| 836 | */ |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 837 | scsi_id->status_fifo_addr = hpsb_allocate_and_register_addrspace( |
| 838 | &sbp2_highlevel, ud->ne->host, &sbp2_ops, |
| 839 | sizeof(struct sbp2_status_block), sizeof(quadlet_t), |
Ben Collins | 40ae6c5 | 2006-06-12 18:13:49 -0400 | [diff] [blame] | 840 | ud->ne->host->low_addr_space, CSR1212_ALL_SPACE_END); |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 841 | if (scsi_id->status_fifo_addr == CSR1212_INVALID_ADDR_SPACE) { |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 842 | SBP2_ERR("failed to allocate status FIFO address range"); |
| 843 | goto failed_alloc; |
| 844 | } |
| 845 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | /* Register our host with the SCSI stack. */ |
Alexandre Oliva | a2ef79e | 2005-06-15 22:26:31 -0700 | [diff] [blame] | 847 | scsi_host = scsi_host_alloc(&scsi_driver_template, |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 848 | sizeof(unsigned long)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | if (!scsi_host) { |
| 850 | SBP2_ERR("failed to register scsi host"); |
| 851 | goto failed_alloc; |
| 852 | } |
| 853 | |
| 854 | scsi_host->hostdata[0] = (unsigned long)scsi_id; |
| 855 | |
| 856 | if (!scsi_add_host(scsi_host, &ud->device)) { |
| 857 | scsi_id->scsi_host = scsi_host; |
| 858 | return scsi_id; |
| 859 | } |
| 860 | |
| 861 | SBP2_ERR("failed to add scsi host"); |
| 862 | scsi_host_put(scsi_host); |
| 863 | |
| 864 | failed_alloc: |
| 865 | sbp2_remove_device(scsi_id); |
| 866 | return NULL; |
| 867 | } |
| 868 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | static void sbp2_host_reset(struct hpsb_host *host) |
| 870 | { |
| 871 | struct sbp2scsi_host_info *hi; |
| 872 | struct scsi_id_instance_data *scsi_id; |
| 873 | |
| 874 | hi = hpsb_get_hostinfo(&sbp2_highlevel, host); |
Stefan Richter | 2cccbb5 | 2006-08-14 18:59:00 +0200 | [diff] [blame] | 875 | if (!hi) |
| 876 | return; |
| 877 | list_for_each_entry(scsi_id, &hi->scsi_ids, scsi_list) |
| 878 | if (likely(atomic_read(&scsi_id->state) != |
| 879 | SBP2LU_STATE_IN_SHUTDOWN)) { |
| 880 | atomic_set(&scsi_id->state, SBP2LU_STATE_IN_RESET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | scsi_block_requests(scsi_id->scsi_host); |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 882 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | } |
| 884 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | /* |
| 886 | * This function is where we first pull the node unique ids, and then |
| 887 | * allocate memory and register a SBP-2 device. |
| 888 | */ |
| 889 | static int sbp2_start_device(struct scsi_id_instance_data *scsi_id) |
| 890 | { |
| 891 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
James Bottomley | 146f726 | 2005-09-10 12:44:09 -0500 | [diff] [blame] | 892 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | /* Login FIFO DMA */ |
| 895 | scsi_id->login_response = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 896 | pci_alloc_consistent(hi->host->pdev, |
| 897 | sizeof(struct sbp2_login_response), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | &scsi_id->login_response_dma); |
| 899 | if (!scsi_id->login_response) |
| 900 | goto alloc_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
| 902 | /* Query logins ORB DMA */ |
| 903 | scsi_id->query_logins_orb = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 904 | pci_alloc_consistent(hi->host->pdev, |
| 905 | sizeof(struct sbp2_query_logins_orb), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | &scsi_id->query_logins_orb_dma); |
| 907 | if (!scsi_id->query_logins_orb) |
| 908 | goto alloc_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
| 910 | /* Query logins response DMA */ |
| 911 | scsi_id->query_logins_response = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 912 | pci_alloc_consistent(hi->host->pdev, |
| 913 | sizeof(struct sbp2_query_logins_response), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | &scsi_id->query_logins_response_dma); |
| 915 | if (!scsi_id->query_logins_response) |
| 916 | goto alloc_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
| 918 | /* Reconnect ORB DMA */ |
| 919 | scsi_id->reconnect_orb = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 920 | pci_alloc_consistent(hi->host->pdev, |
| 921 | sizeof(struct sbp2_reconnect_orb), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | &scsi_id->reconnect_orb_dma); |
| 923 | if (!scsi_id->reconnect_orb) |
| 924 | goto alloc_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | |
| 926 | /* Logout ORB DMA */ |
| 927 | scsi_id->logout_orb = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 928 | pci_alloc_consistent(hi->host->pdev, |
| 929 | sizeof(struct sbp2_logout_orb), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | &scsi_id->logout_orb_dma); |
| 931 | if (!scsi_id->logout_orb) |
| 932 | goto alloc_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
| 934 | /* Login ORB DMA */ |
| 935 | scsi_id->login_orb = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 936 | pci_alloc_consistent(hi->host->pdev, |
| 937 | sizeof(struct sbp2_login_orb), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | &scsi_id->login_orb_dma); |
Stefan Richter | eaceec7 | 2005-12-13 11:05:05 -0500 | [diff] [blame] | 939 | if (!scsi_id->login_orb) |
| 940 | goto alloc_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | |
| 942 | /* |
| 943 | * Create our command orb pool |
| 944 | */ |
| 945 | if (sbp2util_create_command_orb_pool(scsi_id)) { |
| 946 | SBP2_ERR("sbp2util_create_command_orb_pool failed!"); |
| 947 | sbp2_remove_device(scsi_id); |
| 948 | return -ENOMEM; |
| 949 | } |
| 950 | |
| 951 | /* Schedule a timeout here. The reason is that we may be so close |
| 952 | * to a bus reset, that the device is not available for logins. |
| 953 | * This can happen when the bus reset is caused by the host |
| 954 | * connected to the sbp2 device being removed. That host would |
| 955 | * have a certain amount of time to relogin before the sbp2 device |
| 956 | * allows someone else to login instead. One second makes sense. */ |
Stefan Richter | 902abed | 2006-08-14 18:56:00 +0200 | [diff] [blame] | 957 | if (msleep_interruptible(1000)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | sbp2_remove_device(scsi_id); |
| 959 | return -EINTR; |
| 960 | } |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | /* |
| 963 | * Login to the sbp-2 device |
| 964 | */ |
| 965 | if (sbp2_login_device(scsi_id)) { |
| 966 | /* Login failed, just remove the device. */ |
| 967 | sbp2_remove_device(scsi_id); |
| 968 | return -EBUSY; |
| 969 | } |
| 970 | |
| 971 | /* |
| 972 | * Set max retries to something large on the device |
| 973 | */ |
| 974 | sbp2_set_busy_timeout(scsi_id); |
| 975 | |
| 976 | /* |
| 977 | * Do a SBP-2 fetch agent reset |
| 978 | */ |
| 979 | sbp2_agent_reset(scsi_id, 1); |
| 980 | |
| 981 | /* |
| 982 | * Get the max speed and packet size that we can use |
| 983 | */ |
| 984 | sbp2_max_speed_and_size(scsi_id); |
| 985 | |
| 986 | /* Add this device to the scsi layer now */ |
James Bottomley | 146f726 | 2005-09-10 12:44:09 -0500 | [diff] [blame] | 987 | error = scsi_add_device(scsi_id->scsi_host, 0, scsi_id->ud->id, 0); |
| 988 | if (error) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | SBP2_ERR("scsi_add_device failed"); |
Stefan Richter | dc3edd5 | 2005-12-12 23:03:30 -0500 | [diff] [blame] | 990 | sbp2_logout_device(scsi_id); |
| 991 | sbp2_remove_device(scsi_id); |
James Bottomley | 146f726 | 2005-09-10 12:44:09 -0500 | [diff] [blame] | 992 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | return 0; |
Stefan Richter | eaceec7 | 2005-12-13 11:05:05 -0500 | [diff] [blame] | 996 | |
| 997 | alloc_fail: |
| 998 | SBP2_ERR("Could not allocate memory for scsi_id"); |
| 999 | sbp2_remove_device(scsi_id); |
| 1000 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
| 1003 | /* |
| 1004 | * This function removes an sbp2 device from the sbp2scsi_host_info struct. |
| 1005 | */ |
| 1006 | static void sbp2_remove_device(struct scsi_id_instance_data *scsi_id) |
| 1007 | { |
| 1008 | struct sbp2scsi_host_info *hi; |
| 1009 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | if (!scsi_id) |
| 1011 | return; |
| 1012 | |
| 1013 | hi = scsi_id->hi; |
| 1014 | |
| 1015 | /* This will remove our scsi device aswell */ |
| 1016 | if (scsi_id->scsi_host) { |
| 1017 | scsi_remove_host(scsi_id->scsi_host); |
| 1018 | scsi_host_put(scsi_id->scsi_host); |
| 1019 | } |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 1020 | flush_scheduled_work(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | sbp2util_remove_command_orb_pool(scsi_id); |
| 1022 | |
| 1023 | list_del(&scsi_id->scsi_list); |
| 1024 | |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1025 | if (scsi_id->login_response) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | pci_free_consistent(hi->host->pdev, |
| 1027 | sizeof(struct sbp2_login_response), |
| 1028 | scsi_id->login_response, |
| 1029 | scsi_id->login_response_dma); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1030 | if (scsi_id->login_orb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | pci_free_consistent(hi->host->pdev, |
| 1032 | sizeof(struct sbp2_login_orb), |
| 1033 | scsi_id->login_orb, |
| 1034 | scsi_id->login_orb_dma); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1035 | if (scsi_id->reconnect_orb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1036 | pci_free_consistent(hi->host->pdev, |
| 1037 | sizeof(struct sbp2_reconnect_orb), |
| 1038 | scsi_id->reconnect_orb, |
| 1039 | scsi_id->reconnect_orb_dma); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1040 | if (scsi_id->logout_orb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | pci_free_consistent(hi->host->pdev, |
| 1042 | sizeof(struct sbp2_logout_orb), |
| 1043 | scsi_id->logout_orb, |
| 1044 | scsi_id->logout_orb_dma); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1045 | if (scsi_id->query_logins_orb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | pci_free_consistent(hi->host->pdev, |
| 1047 | sizeof(struct sbp2_query_logins_orb), |
| 1048 | scsi_id->query_logins_orb, |
| 1049 | scsi_id->query_logins_orb_dma); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1050 | if (scsi_id->query_logins_response) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | pci_free_consistent(hi->host->pdev, |
| 1052 | sizeof(struct sbp2_query_logins_response), |
| 1053 | scsi_id->query_logins_response, |
| 1054 | scsi_id->query_logins_response_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 1056 | if (scsi_id->status_fifo_addr != CSR1212_INVALID_ADDR_SPACE) |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1057 | hpsb_unregister_addrspace(&sbp2_highlevel, hi->host, |
Ben Collins | 6737231 | 2006-06-12 18:15:31 -0400 | [diff] [blame] | 1058 | scsi_id->status_fifo_addr); |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1059 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | scsi_id->ud->device.driver_data = NULL; |
| 1061 | |
Stefan Richter | 147830f | 2006-03-28 19:54:52 -0500 | [diff] [blame] | 1062 | if (hi) |
| 1063 | module_put(hi->host->driver->owner); |
| 1064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | kfree(scsi_id); |
| 1066 | } |
| 1067 | |
| 1068 | #ifdef CONFIG_IEEE1394_SBP2_PHYS_DMA |
| 1069 | /* |
| 1070 | * This function deals with physical dma write requests (for adapters that do not support |
| 1071 | * physical dma in hardware). Mostly just here for debugging... |
| 1072 | */ |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1073 | static int sbp2_handle_physdma_write(struct hpsb_host *host, int nodeid, |
| 1074 | int destid, quadlet_t *data, u64 addr, |
| 1075 | size_t length, u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
| 1077 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1078 | /* |
| 1079 | * Manually put the data in the right place. |
| 1080 | */ |
| 1081 | memcpy(bus_to_virt((u32) addr), data, length); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1082 | return RCODE_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | /* |
| 1086 | * This function deals with physical dma read requests (for adapters that do not support |
| 1087 | * physical dma in hardware). Mostly just here for debugging... |
| 1088 | */ |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1089 | static int sbp2_handle_physdma_read(struct hpsb_host *host, int nodeid, |
| 1090 | quadlet_t *data, u64 addr, size_t length, |
| 1091 | u16 flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
| 1093 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1094 | /* |
| 1095 | * Grab data from memory and send a read response. |
| 1096 | */ |
| 1097 | memcpy(data, bus_to_virt((u32) addr), length); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1098 | return RCODE_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | } |
| 1100 | #endif |
| 1101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | /************************************** |
| 1103 | * SBP-2 protocol related section |
| 1104 | **************************************/ |
| 1105 | |
| 1106 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | * This function queries the device for the maximum concurrent logins it |
| 1108 | * supports. |
| 1109 | */ |
| 1110 | static int sbp2_query_logins(struct scsi_id_instance_data *scsi_id) |
| 1111 | { |
| 1112 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 1113 | quadlet_t data[2]; |
| 1114 | int max_logins; |
| 1115 | int active_logins; |
| 1116 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1117 | scsi_id->query_logins_orb->reserved1 = 0x0; |
| 1118 | scsi_id->query_logins_orb->reserved2 = 0x0; |
| 1119 | |
| 1120 | scsi_id->query_logins_orb->query_response_lo = scsi_id->query_logins_response_dma; |
| 1121 | scsi_id->query_logins_orb->query_response_hi = ORB_SET_NODE_ID(hi->host->node_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
| 1123 | scsi_id->query_logins_orb->lun_misc = ORB_SET_FUNCTION(SBP2_QUERY_LOGINS_REQUEST); |
| 1124 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_NOTIFY(1); |
Ben Collins | e309fc6 | 2005-11-07 06:31:34 -0500 | [diff] [blame] | 1125 | scsi_id->query_logins_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | |
| 1127 | scsi_id->query_logins_orb->reserved_resp_length = |
| 1128 | ORB_SET_QUERY_LOGINS_RESP_LENGTH(sizeof(struct sbp2_query_logins_response)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1129 | |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1130 | scsi_id->query_logins_orb->status_fifo_hi = |
| 1131 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); |
| 1132 | scsi_id->query_logins_orb->status_fifo_lo = |
| 1133 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | |
| 1135 | sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_orb, sizeof(struct sbp2_query_logins_orb)); |
| 1136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | memset(scsi_id->query_logins_response, 0, sizeof(struct sbp2_query_logins_response)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1140 | data[1] = scsi_id->query_logins_orb_dma; |
| 1141 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 1145 | if (sbp2util_access_timeout(scsi_id, 2*HZ)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1147 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->query_logins_orb_dma) { |
| 1151 | SBP2_INFO("Error querying logins to SBP-2 device - timed out"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1152 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | } |
| 1154 | |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1155 | if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { |
| 1156 | SBP2_INFO("Error querying logins to SBP-2 device - failed"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1157 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | sbp2util_cpu_to_be32_buffer(scsi_id->query_logins_response, sizeof(struct sbp2_query_logins_response)); |
| 1161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | max_logins = RESPONSE_GET_MAX_LOGINS(scsi_id->query_logins_response->length_max_logins); |
Ben Collins | 20f4578 | 2006-06-12 18:13:11 -0400 | [diff] [blame] | 1163 | SBP2_INFO("Maximum concurrent logins supported: %d", max_logins); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | |
| 1165 | active_logins = RESPONSE_GET_ACTIVE_LOGINS(scsi_id->query_logins_response->length_max_logins); |
Ben Collins | 20f4578 | 2006-06-12 18:13:11 -0400 | [diff] [blame] | 1166 | SBP2_INFO("Number of active logins: %d", active_logins); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | |
| 1168 | if (active_logins >= max_logins) { |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1169 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | } |
| 1171 | |
| 1172 | return 0; |
| 1173 | } |
| 1174 | |
| 1175 | /* |
| 1176 | * This function is called in order to login to a particular SBP-2 device, |
| 1177 | * after a bus reset. |
| 1178 | */ |
| 1179 | static int sbp2_login_device(struct scsi_id_instance_data *scsi_id) |
| 1180 | { |
| 1181 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 1182 | quadlet_t data[2]; |
| 1183 | |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1184 | if (!scsi_id->login_orb) |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1185 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | if (!exclusive_login) { |
| 1188 | if (sbp2_query_logins(scsi_id)) { |
| 1189 | SBP2_INFO("Device does not support any more concurrent logins"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1190 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | /* Set-up login ORB, assume no password */ |
| 1195 | scsi_id->login_orb->password_hi = 0; |
| 1196 | scsi_id->login_orb->password_lo = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1197 | |
| 1198 | scsi_id->login_orb->login_response_lo = scsi_id->login_response_dma; |
| 1199 | scsi_id->login_orb->login_response_hi = ORB_SET_NODE_ID(hi->host->node_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
| 1201 | scsi_id->login_orb->lun_misc = ORB_SET_FUNCTION(SBP2_LOGIN_REQUEST); |
| 1202 | scsi_id->login_orb->lun_misc |= ORB_SET_RECONNECT(0); /* One second reconnect time */ |
| 1203 | scsi_id->login_orb->lun_misc |= ORB_SET_EXCLUSIVE(exclusive_login); /* Exclusive access to device */ |
| 1204 | scsi_id->login_orb->lun_misc |= ORB_SET_NOTIFY(1); /* Notify us of login complete */ |
Ben Collins | e309fc6 | 2005-11-07 06:31:34 -0500 | [diff] [blame] | 1205 | scsi_id->login_orb->lun_misc |= ORB_SET_LUN(scsi_id->sbp2_lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | |
| 1207 | scsi_id->login_orb->passwd_resp_lengths = |
| 1208 | ORB_SET_LOGIN_RESP_LENGTH(sizeof(struct sbp2_login_response)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1210 | scsi_id->login_orb->status_fifo_hi = |
| 1211 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); |
| 1212 | scsi_id->login_orb->status_fifo_lo = |
| 1213 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | sbp2util_cpu_to_be32_buffer(scsi_id->login_orb, sizeof(struct sbp2_login_orb)); |
| 1216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | memset(scsi_id->login_response, 0, sizeof(struct sbp2_login_response)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1220 | data[1] = scsi_id->login_orb_dma; |
| 1221 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | hpsb_node_write(scsi_id->ne, scsi_id->sbp2_management_agent_addr, data, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | |
| 1225 | /* |
| 1226 | * Wait for login status (up to 20 seconds)... |
| 1227 | */ |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 1228 | if (sbp2util_access_timeout(scsi_id, 20*HZ)) { |
| 1229 | SBP2_ERR("Error logging into SBP-2 device - timed out"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1230 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | /* |
| 1234 | * Sanity. Make sure status returned matches login orb. |
| 1235 | */ |
| 1236 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->login_orb_dma) { |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1237 | SBP2_ERR("Error logging into SBP-2 device - timed out"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1238 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | } |
| 1240 | |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1241 | if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { |
| 1242 | SBP2_ERR("Error logging into SBP-2 device - failed"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1243 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | /* |
| 1247 | * Byte swap the login response, for use when reconnecting or |
| 1248 | * logging out. |
| 1249 | */ |
| 1250 | sbp2util_cpu_to_be32_buffer(scsi_id->login_response, sizeof(struct sbp2_login_response)); |
| 1251 | |
| 1252 | /* |
| 1253 | * Grab our command block agent address from the login response. |
| 1254 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | scsi_id->sbp2_command_block_agent_addr = |
| 1256 | ((u64)scsi_id->login_response->command_block_agent_hi) << 32; |
| 1257 | scsi_id->sbp2_command_block_agent_addr |= ((u64)scsi_id->login_response->command_block_agent_lo); |
| 1258 | scsi_id->sbp2_command_block_agent_addr &= 0x0000ffffffffffffULL; |
| 1259 | |
| 1260 | SBP2_INFO("Logged into SBP-2 device"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1261 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | /* |
| 1265 | * This function is called in order to logout from a particular SBP-2 |
| 1266 | * device, usually called during driver unload. |
| 1267 | */ |
| 1268 | static int sbp2_logout_device(struct scsi_id_instance_data *scsi_id) |
| 1269 | { |
| 1270 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 1271 | quadlet_t data[2]; |
| 1272 | int error; |
| 1273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | /* |
| 1275 | * Set-up logout ORB |
| 1276 | */ |
| 1277 | scsi_id->logout_orb->reserved1 = 0x0; |
| 1278 | scsi_id->logout_orb->reserved2 = 0x0; |
| 1279 | scsi_id->logout_orb->reserved3 = 0x0; |
| 1280 | scsi_id->logout_orb->reserved4 = 0x0; |
| 1281 | |
| 1282 | scsi_id->logout_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_LOGOUT_REQUEST); |
| 1283 | scsi_id->logout_orb->login_ID_misc |= ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID); |
| 1284 | |
| 1285 | /* Notify us when complete */ |
| 1286 | scsi_id->logout_orb->login_ID_misc |= ORB_SET_NOTIFY(1); |
| 1287 | |
| 1288 | scsi_id->logout_orb->reserved5 = 0x0; |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1289 | scsi_id->logout_orb->status_fifo_hi = |
| 1290 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); |
| 1291 | scsi_id->logout_orb->status_fifo_lo = |
| 1292 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1293 | |
| 1294 | /* |
| 1295 | * Byte swap ORB if necessary |
| 1296 | */ |
| 1297 | sbp2util_cpu_to_be32_buffer(scsi_id->logout_orb, sizeof(struct sbp2_logout_orb)); |
| 1298 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1299 | /* |
| 1300 | * Ok, let's write to the target's management agent register |
| 1301 | */ |
| 1302 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1303 | data[1] = scsi_id->logout_orb_dma; |
| 1304 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1305 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | error = hpsb_node_write(scsi_id->ne, |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1307 | scsi_id->sbp2_management_agent_addr, data, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | if (error) |
| 1309 | return error; |
| 1310 | |
| 1311 | /* Wait for device to logout...1 second. */ |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 1312 | if (sbp2util_access_timeout(scsi_id, HZ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | return -EIO; |
| 1314 | |
| 1315 | SBP2_INFO("Logged out of SBP-2 device"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1316 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1317 | } |
| 1318 | |
| 1319 | /* |
| 1320 | * This function is called in order to reconnect to a particular SBP-2 |
| 1321 | * device, after a bus reset. |
| 1322 | */ |
| 1323 | static int sbp2_reconnect_device(struct scsi_id_instance_data *scsi_id) |
| 1324 | { |
| 1325 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 1326 | quadlet_t data[2]; |
| 1327 | int error; |
| 1328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | /* |
| 1330 | * Set-up reconnect ORB |
| 1331 | */ |
| 1332 | scsi_id->reconnect_orb->reserved1 = 0x0; |
| 1333 | scsi_id->reconnect_orb->reserved2 = 0x0; |
| 1334 | scsi_id->reconnect_orb->reserved3 = 0x0; |
| 1335 | scsi_id->reconnect_orb->reserved4 = 0x0; |
| 1336 | |
| 1337 | scsi_id->reconnect_orb->login_ID_misc = ORB_SET_FUNCTION(SBP2_RECONNECT_REQUEST); |
| 1338 | scsi_id->reconnect_orb->login_ID_misc |= |
| 1339 | ORB_SET_LOGIN_ID(scsi_id->login_response->length_login_ID); |
| 1340 | |
| 1341 | /* Notify us when complete */ |
| 1342 | scsi_id->reconnect_orb->login_ID_misc |= ORB_SET_NOTIFY(1); |
| 1343 | |
| 1344 | scsi_id->reconnect_orb->reserved5 = 0x0; |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1345 | scsi_id->reconnect_orb->status_fifo_hi = |
| 1346 | ORB_SET_STATUS_FIFO_HI(scsi_id->status_fifo_addr, hi->host->node_id); |
| 1347 | scsi_id->reconnect_orb->status_fifo_lo = |
| 1348 | ORB_SET_STATUS_FIFO_LO(scsi_id->status_fifo_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
| 1350 | /* |
| 1351 | * Byte swap ORB if necessary |
| 1352 | */ |
| 1353 | sbp2util_cpu_to_be32_buffer(scsi_id->reconnect_orb, sizeof(struct sbp2_reconnect_orb)); |
| 1354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1356 | data[1] = scsi_id->reconnect_orb_dma; |
| 1357 | sbp2util_cpu_to_be32_buffer(data, 8); |
| 1358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | error = hpsb_node_write(scsi_id->ne, |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1360 | scsi_id->sbp2_management_agent_addr, data, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | if (error) |
| 1362 | return error; |
| 1363 | |
| 1364 | /* |
| 1365 | * Wait for reconnect status (up to 1 second)... |
| 1366 | */ |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 1367 | if (sbp2util_access_timeout(scsi_id, HZ)) { |
| 1368 | SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1369 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | /* |
| 1373 | * Sanity. Make sure status returned matches reconnect orb. |
| 1374 | */ |
| 1375 | if (scsi_id->status_block.ORB_offset_lo != scsi_id->reconnect_orb_dma) { |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1376 | SBP2_ERR("Error reconnecting to SBP-2 device - timed out"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1377 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1380 | if (STATUS_TEST_RDS(scsi_id->status_block.ORB_offset_hi_misc)) { |
| 1381 | SBP2_ERR("Error reconnecting to SBP-2 device - failed"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1382 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1385 | SBP2_INFO("Reconnected to SBP-2 device"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1386 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | } |
| 1388 | |
| 1389 | /* |
| 1390 | * This function is called in order to set the busy timeout (number of |
| 1391 | * retries to attempt) on the sbp2 device. |
| 1392 | */ |
| 1393 | static int sbp2_set_busy_timeout(struct scsi_id_instance_data *scsi_id) |
| 1394 | { |
| 1395 | quadlet_t data; |
| 1396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | data = cpu_to_be32(SBP2_BUSY_TIMEOUT_VALUE); |
Stefan Richter | d024ebc | 2006-03-28 20:03:55 -0500 | [diff] [blame] | 1398 | if (hpsb_node_write(scsi_id->ne, SBP2_BUSY_TIMEOUT_ADDRESS, &data, 4)) |
| 1399 | SBP2_ERR("%s error", __FUNCTION__); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1400 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | /* |
| 1404 | * This function is called to parse sbp2 device's config rom unit |
| 1405 | * directory. Used to determine things like sbp2 management agent offset, |
| 1406 | * and command set used (SCSI or RBC). |
| 1407 | */ |
| 1408 | static void sbp2_parse_unit_directory(struct scsi_id_instance_data *scsi_id, |
| 1409 | struct unit_directory *ud) |
| 1410 | { |
| 1411 | struct csr1212_keyval *kv; |
| 1412 | struct csr1212_dentry *dentry; |
| 1413 | u64 management_agent_addr; |
| 1414 | u32 command_set_spec_id, command_set, unit_characteristics, |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 1415 | firmware_revision; |
| 1416 | unsigned workarounds; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | int i; |
| 1418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | management_agent_addr = 0x0; |
| 1420 | command_set_spec_id = 0x0; |
| 1421 | command_set = 0x0; |
| 1422 | unit_characteristics = 0x0; |
| 1423 | firmware_revision = 0x0; |
| 1424 | |
| 1425 | /* Handle different fields in the unit directory, based on keys */ |
| 1426 | csr1212_for_each_dir_entry(ud->ne->csr, kv, ud->ud_kv, dentry) { |
| 1427 | switch (kv->key.id) { |
| 1428 | case CSR1212_KV_ID_DEPENDENT_INFO: |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1429 | if (kv->key.type == CSR1212_KV_TYPE_CSR_OFFSET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | /* Save off the management agent address */ |
| 1431 | management_agent_addr = |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1432 | CSR1212_REGISTER_SPACE_BASE + |
| 1433 | (kv->value.csr_offset << 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1435 | else if (kv->key.type == CSR1212_KV_TYPE_IMMEDIATE) |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1436 | scsi_id->sbp2_lun = |
| 1437 | ORB_SET_LUN(kv->value.immediate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | break; |
| 1439 | |
| 1440 | case SBP2_COMMAND_SET_SPEC_ID_KEY: |
| 1441 | /* Command spec organization */ |
| 1442 | command_set_spec_id = kv->value.immediate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | break; |
| 1444 | |
| 1445 | case SBP2_COMMAND_SET_KEY: |
| 1446 | /* Command set used by sbp2 device */ |
| 1447 | command_set = kv->value.immediate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | break; |
| 1449 | |
| 1450 | case SBP2_UNIT_CHARACTERISTICS_KEY: |
| 1451 | /* |
| 1452 | * Unit characterisitcs (orb related stuff |
| 1453 | * that I'm not yet paying attention to) |
| 1454 | */ |
| 1455 | unit_characteristics = kv->value.immediate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | break; |
| 1457 | |
| 1458 | case SBP2_FIRMWARE_REVISION_KEY: |
| 1459 | /* Firmware revision */ |
| 1460 | firmware_revision = kv->value.immediate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | break; |
| 1462 | |
| 1463 | default: |
| 1464 | break; |
| 1465 | } |
| 1466 | } |
| 1467 | |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 1468 | workarounds = sbp2_default_workarounds; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | |
Stefan Richter | 679c0cd | 2006-05-15 22:08:09 +0200 | [diff] [blame] | 1470 | if (!(workarounds & SBP2_WORKAROUND_OVERRIDE)) |
| 1471 | for (i = 0; i < ARRAY_SIZE(sbp2_workarounds_table); i++) { |
| 1472 | if (sbp2_workarounds_table[i].firmware_revision && |
| 1473 | sbp2_workarounds_table[i].firmware_revision != |
| 1474 | (firmware_revision & 0xffff00)) |
| 1475 | continue; |
| 1476 | if (sbp2_workarounds_table[i].model_id && |
| 1477 | sbp2_workarounds_table[i].model_id != ud->model_id) |
| 1478 | continue; |
| 1479 | workarounds |= sbp2_workarounds_table[i].workarounds; |
| 1480 | break; |
| 1481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 1483 | if (workarounds) |
Stefan Richter | e9a1c52 | 2006-05-15 22:06:37 +0200 | [diff] [blame] | 1484 | SBP2_INFO("Workarounds for node " NODE_BUS_FMT ": 0x%x " |
| 1485 | "(firmware_revision 0x%06x, vendor_id 0x%06x," |
| 1486 | " model_id 0x%06x)", |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 1487 | NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid), |
Stefan Richter | e9a1c52 | 2006-05-15 22:06:37 +0200 | [diff] [blame] | 1488 | workarounds, firmware_revision, |
| 1489 | ud->vendor_id ? ud->vendor_id : ud->ne->vendor_id, |
| 1490 | ud->model_id); |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 1491 | |
| 1492 | /* We would need one SCSI host template for each target to adjust |
| 1493 | * max_sectors on the fly, therefore warn only. */ |
| 1494 | if (workarounds & SBP2_WORKAROUND_128K_MAX_TRANS && |
| 1495 | (max_sectors * 512) > (128 * 1024)) |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1496 | SBP2_INFO("Node " NODE_BUS_FMT ": Bridge only supports 128KB " |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 1497 | "max transfer size. WARNING: Current max_sectors " |
| 1498 | "setting is larger than 128KB (%d sectors)", |
| 1499 | NODE_BUS_ARGS(ud->ne->host, ud->ne->nodeid), |
| 1500 | max_sectors); |
| 1501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | /* If this is a logical unit directory entry, process the parent |
| 1503 | * to get the values. */ |
| 1504 | if (ud->flags & UNIT_DIRECTORY_LUN_DIRECTORY) { |
| 1505 | struct unit_directory *parent_ud = |
| 1506 | container_of(ud->device.parent, struct unit_directory, device); |
| 1507 | sbp2_parse_unit_directory(scsi_id, parent_ud); |
| 1508 | } else { |
| 1509 | scsi_id->sbp2_management_agent_addr = management_agent_addr; |
| 1510 | scsi_id->sbp2_command_set_spec_id = command_set_spec_id; |
| 1511 | scsi_id->sbp2_command_set = command_set; |
| 1512 | scsi_id->sbp2_unit_characteristics = unit_characteristics; |
| 1513 | scsi_id->sbp2_firmware_revision = firmware_revision; |
| 1514 | scsi_id->workarounds = workarounds; |
| 1515 | if (ud->flags & UNIT_DIRECTORY_HAS_LUN) |
Ben Collins | e309fc6 | 2005-11-07 06:31:34 -0500 | [diff] [blame] | 1516 | scsi_id->sbp2_lun = ORB_SET_LUN(ud->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | } |
| 1518 | } |
| 1519 | |
Ben Collins | fd23ade | 2006-06-12 18:14:14 -0400 | [diff] [blame] | 1520 | #define SBP2_PAYLOAD_TO_BYTES(p) (1 << ((p) + 2)) |
| 1521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | /* |
| 1523 | * This function is called in order to determine the max speed and packet |
| 1524 | * size we can use in our ORBs. Note, that we (the driver and host) only |
| 1525 | * initiate the transaction. The SBP-2 device actually transfers the data |
| 1526 | * (by reading from the DMA area we tell it). This means that the SBP-2 |
| 1527 | * device decides the actual maximum data it can transfer. We just tell it |
| 1528 | * the speed that it needs to use, and the max_rec the host supports, and |
| 1529 | * it takes care of the rest. |
| 1530 | */ |
| 1531 | static int sbp2_max_speed_and_size(struct scsi_id_instance_data *scsi_id) |
| 1532 | { |
| 1533 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
Ben Collins | fd23ade | 2006-06-12 18:14:14 -0400 | [diff] [blame] | 1534 | u8 payload; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1536 | scsi_id->speed_code = |
Ben Collins | 647dcb5 | 2006-06-12 18:12:37 -0400 | [diff] [blame] | 1537 | hi->host->speed[NODEID_TO_NODE(scsi_id->ne->nodeid)]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | |
| 1539 | /* Bump down our speed if the user requested it */ |
| 1540 | if (scsi_id->speed_code > max_speed) { |
| 1541 | scsi_id->speed_code = max_speed; |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1542 | SBP2_INFO("Reducing speed to %s", hpsb_speedto_str[max_speed]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | } |
| 1544 | |
| 1545 | /* Payload size is the lesser of what our speed supports and what |
| 1546 | * our host supports. */ |
Ben Collins | fd23ade | 2006-06-12 18:14:14 -0400 | [diff] [blame] | 1547 | payload = min(sbp2_speedto_max_payload[scsi_id->speed_code], |
| 1548 | (u8) (hi->host->csr.max_rec - 1)); |
| 1549 | |
| 1550 | /* If physical DMA is off, work around limitation in ohci1394: |
| 1551 | * packet size must not exceed PAGE_SIZE */ |
| 1552 | if (scsi_id->ne->host->low_addr_space < (1ULL << 32)) |
| 1553 | while (SBP2_PAYLOAD_TO_BYTES(payload) + 24 > PAGE_SIZE && |
| 1554 | payload) |
| 1555 | payload--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1557 | SBP2_INFO("Node " NODE_BUS_FMT ": Max speed [%s] - Max payload [%u]", |
| 1558 | NODE_BUS_ARGS(hi->host, scsi_id->ne->nodeid), |
| 1559 | hpsb_speedto_str[scsi_id->speed_code], |
| 1560 | SBP2_PAYLOAD_TO_BYTES(payload)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | |
Ben Collins | fd23ade | 2006-06-12 18:14:14 -0400 | [diff] [blame] | 1562 | scsi_id->max_payload_size = payload; |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1563 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | /* |
| 1567 | * This function is called in order to perform a SBP-2 agent reset. |
| 1568 | */ |
| 1569 | static int sbp2_agent_reset(struct scsi_id_instance_data *scsi_id, int wait) |
| 1570 | { |
| 1571 | quadlet_t data; |
| 1572 | u64 addr; |
| 1573 | int retval; |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1574 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | |
Stefan Richter | d19c776 | 2006-12-07 22:40:33 +0100 | [diff] [blame^] | 1576 | /* cancel_delayed_work(&scsi_id->protocol_work); */ |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 1577 | if (wait) |
| 1578 | flush_scheduled_work(); |
| 1579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | data = ntohl(SBP2_AGENT_RESET_DATA); |
| 1581 | addr = scsi_id->sbp2_command_block_agent_addr + SBP2_AGENT_RESET_OFFSET; |
| 1582 | |
| 1583 | if (wait) |
| 1584 | retval = hpsb_node_write(scsi_id->ne, addr, &data, 4); |
| 1585 | else |
| 1586 | retval = sbp2util_node_write_no_wait(scsi_id->ne, addr, &data, 4); |
| 1587 | |
| 1588 | if (retval < 0) { |
| 1589 | SBP2_ERR("hpsb_node_write failed.\n"); |
| 1590 | return -EIO; |
| 1591 | } |
| 1592 | |
| 1593 | /* |
| 1594 | * Need to make sure orb pointer is written on next command |
| 1595 | */ |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1596 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | scsi_id->last_orb = NULL; |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1598 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1600 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | } |
| 1602 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1603 | static void sbp2_prep_command_orb_sg(struct sbp2_command_orb *orb, |
| 1604 | struct sbp2scsi_host_info *hi, |
| 1605 | struct sbp2_command_info *command, |
| 1606 | unsigned int scsi_use_sg, |
| 1607 | struct scatterlist *sgpnt, |
| 1608 | u32 orb_direction, |
| 1609 | enum dma_data_direction dma_dir) |
| 1610 | { |
| 1611 | command->dma_dir = dma_dir; |
| 1612 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); |
| 1613 | orb->misc |= ORB_SET_DIRECTION(orb_direction); |
| 1614 | |
| 1615 | /* Special case if only one element (and less than 64KB in size) */ |
| 1616 | if ((scsi_use_sg == 1) && |
| 1617 | (sgpnt[0].length <= SBP2_MAX_SG_ELEMENT_LENGTH)) { |
| 1618 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1619 | command->dma_size = sgpnt[0].length; |
| 1620 | command->dma_type = CMD_DMA_PAGE; |
| 1621 | command->cmd_dma = pci_map_page(hi->host->pdev, |
| 1622 | sgpnt[0].page, |
| 1623 | sgpnt[0].offset, |
| 1624 | command->dma_size, |
| 1625 | command->dma_dir); |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1626 | |
| 1627 | orb->data_descriptor_lo = command->cmd_dma; |
| 1628 | orb->misc |= ORB_SET_DATA_SIZE(command->dma_size); |
| 1629 | |
| 1630 | } else { |
| 1631 | struct sbp2_unrestricted_page_table *sg_element = |
| 1632 | &command->scatter_gather_element[0]; |
| 1633 | u32 sg_count, sg_len; |
| 1634 | dma_addr_t sg_addr; |
| 1635 | int i, count = pci_map_sg(hi->host->pdev, sgpnt, scsi_use_sg, |
| 1636 | dma_dir); |
| 1637 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1638 | command->dma_size = scsi_use_sg; |
| 1639 | command->sge_buffer = sgpnt; |
| 1640 | |
| 1641 | /* use page tables (s/g) */ |
| 1642 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); |
| 1643 | orb->data_descriptor_lo = command->sge_dma; |
| 1644 | |
| 1645 | /* |
| 1646 | * Loop through and fill out our sbp-2 page tables |
| 1647 | * (and split up anything too large) |
| 1648 | */ |
| 1649 | for (i = 0, sg_count = 0 ; i < count; i++, sgpnt++) { |
| 1650 | sg_len = sg_dma_len(sgpnt); |
| 1651 | sg_addr = sg_dma_address(sgpnt); |
| 1652 | while (sg_len) { |
| 1653 | sg_element[sg_count].segment_base_lo = sg_addr; |
| 1654 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { |
| 1655 | sg_element[sg_count].length_segment_base_hi = |
| 1656 | PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); |
| 1657 | sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; |
| 1658 | sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; |
| 1659 | } else { |
| 1660 | sg_element[sg_count].length_segment_base_hi = |
| 1661 | PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); |
| 1662 | sg_len = 0; |
| 1663 | } |
| 1664 | sg_count++; |
| 1665 | } |
| 1666 | } |
| 1667 | |
| 1668 | /* Number of page table (s/g) elements */ |
| 1669 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); |
| 1670 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1671 | /* Byte swap page tables if necessary */ |
| 1672 | sbp2util_cpu_to_be32_buffer(sg_element, |
| 1673 | (sizeof(struct sbp2_unrestricted_page_table)) * |
| 1674 | sg_count); |
| 1675 | } |
| 1676 | } |
| 1677 | |
| 1678 | static void sbp2_prep_command_orb_no_sg(struct sbp2_command_orb *orb, |
| 1679 | struct sbp2scsi_host_info *hi, |
| 1680 | struct sbp2_command_info *command, |
| 1681 | struct scatterlist *sgpnt, |
| 1682 | u32 orb_direction, |
| 1683 | unsigned int scsi_request_bufflen, |
| 1684 | void *scsi_request_buffer, |
| 1685 | enum dma_data_direction dma_dir) |
| 1686 | { |
| 1687 | command->dma_dir = dma_dir; |
| 1688 | command->dma_size = scsi_request_bufflen; |
| 1689 | command->dma_type = CMD_DMA_SINGLE; |
| 1690 | command->cmd_dma = pci_map_single(hi->host->pdev, scsi_request_buffer, |
| 1691 | command->dma_size, command->dma_dir); |
| 1692 | orb->data_descriptor_hi = ORB_SET_NODE_ID(hi->host->node_id); |
| 1693 | orb->misc |= ORB_SET_DIRECTION(orb_direction); |
| 1694 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1695 | /* |
| 1696 | * Handle case where we get a command w/o s/g enabled (but |
| 1697 | * check for transfers larger than 64K) |
| 1698 | */ |
| 1699 | if (scsi_request_bufflen <= SBP2_MAX_SG_ELEMENT_LENGTH) { |
| 1700 | |
| 1701 | orb->data_descriptor_lo = command->cmd_dma; |
| 1702 | orb->misc |= ORB_SET_DATA_SIZE(scsi_request_bufflen); |
| 1703 | |
| 1704 | } else { |
| 1705 | struct sbp2_unrestricted_page_table *sg_element = |
| 1706 | &command->scatter_gather_element[0]; |
| 1707 | u32 sg_count, sg_len; |
| 1708 | dma_addr_t sg_addr; |
| 1709 | |
| 1710 | /* |
| 1711 | * Need to turn this into page tables, since the |
| 1712 | * buffer is too large. |
| 1713 | */ |
| 1714 | orb->data_descriptor_lo = command->sge_dma; |
| 1715 | |
| 1716 | /* Use page tables (s/g) */ |
| 1717 | orb->misc |= ORB_SET_PAGE_TABLE_PRESENT(0x1); |
| 1718 | |
| 1719 | /* |
| 1720 | * fill out our sbp-2 page tables (and split up |
| 1721 | * the large buffer) |
| 1722 | */ |
| 1723 | sg_count = 0; |
| 1724 | sg_len = scsi_request_bufflen; |
| 1725 | sg_addr = command->cmd_dma; |
| 1726 | while (sg_len) { |
| 1727 | sg_element[sg_count].segment_base_lo = sg_addr; |
| 1728 | if (sg_len > SBP2_MAX_SG_ELEMENT_LENGTH) { |
| 1729 | sg_element[sg_count].length_segment_base_hi = |
| 1730 | PAGE_TABLE_SET_SEGMENT_LENGTH(SBP2_MAX_SG_ELEMENT_LENGTH); |
| 1731 | sg_addr += SBP2_MAX_SG_ELEMENT_LENGTH; |
| 1732 | sg_len -= SBP2_MAX_SG_ELEMENT_LENGTH; |
| 1733 | } else { |
| 1734 | sg_element[sg_count].length_segment_base_hi = |
| 1735 | PAGE_TABLE_SET_SEGMENT_LENGTH(sg_len); |
| 1736 | sg_len = 0; |
| 1737 | } |
| 1738 | sg_count++; |
| 1739 | } |
| 1740 | |
| 1741 | /* Number of page table (s/g) elements */ |
| 1742 | orb->misc |= ORB_SET_DATA_SIZE(sg_count); |
| 1743 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1744 | /* Byte swap page tables if necessary */ |
| 1745 | sbp2util_cpu_to_be32_buffer(sg_element, |
| 1746 | (sizeof(struct sbp2_unrestricted_page_table)) * |
| 1747 | sg_count); |
| 1748 | } |
| 1749 | } |
| 1750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | /* |
| 1752 | * This function is called to create the actual command orb and s/g list |
| 1753 | * out of the scsi command itself. |
| 1754 | */ |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1755 | static void sbp2_create_command_orb(struct scsi_id_instance_data *scsi_id, |
| 1756 | struct sbp2_command_info *command, |
| 1757 | unchar *scsi_cmd, |
| 1758 | unsigned int scsi_use_sg, |
| 1759 | unsigned int scsi_request_bufflen, |
| 1760 | void *scsi_request_buffer, |
| 1761 | enum dma_data_direction dma_dir) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | { |
| 1763 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1764 | struct scatterlist *sgpnt = (struct scatterlist *)scsi_request_buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1765 | struct sbp2_command_orb *command_orb = &command->command_orb; |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1766 | u32 orb_direction; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1767 | |
| 1768 | /* |
| 1769 | * Set-up our command ORB.. |
| 1770 | * |
| 1771 | * NOTE: We're doing unrestricted page tables (s/g), as this is |
| 1772 | * best performance (at least with the devices I have). This means |
| 1773 | * that data_size becomes the number of s/g elements, and |
| 1774 | * page_size should be zero (for unrestricted). |
| 1775 | */ |
| 1776 | command_orb->next_ORB_hi = ORB_SET_NULL_PTR(1); |
| 1777 | command_orb->next_ORB_lo = 0x0; |
| 1778 | command_orb->misc = ORB_SET_MAX_PAYLOAD(scsi_id->max_payload_size); |
| 1779 | command_orb->misc |= ORB_SET_SPEED(scsi_id->speed_code); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1780 | command_orb->misc |= ORB_SET_NOTIFY(1); /* Notify us when complete */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | |
Stefan Richter | 43863eb | 2005-12-12 23:03:24 -0500 | [diff] [blame] | 1782 | if (dma_dir == DMA_NONE) |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1783 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; |
Stefan Richter | 43863eb | 2005-12-12 23:03:24 -0500 | [diff] [blame] | 1784 | else if (dma_dir == DMA_TO_DEVICE && scsi_request_bufflen) |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1785 | orb_direction = ORB_DIRECTION_WRITE_TO_MEDIA; |
Stefan Richter | 43863eb | 2005-12-12 23:03:24 -0500 | [diff] [blame] | 1786 | else if (dma_dir == DMA_FROM_DEVICE && scsi_request_bufflen) |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1787 | orb_direction = ORB_DIRECTION_READ_FROM_MEDIA; |
Stefan Richter | 43863eb | 2005-12-12 23:03:24 -0500 | [diff] [blame] | 1788 | else { |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1789 | SBP2_INFO("Falling back to DMA_NONE"); |
Stefan Richter | 43863eb | 2005-12-12 23:03:24 -0500 | [diff] [blame] | 1790 | orb_direction = ORB_DIRECTION_NO_DATA_TRANSFER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | } |
| 1792 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1793 | /* Set-up our pagetable stuff */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | if (orb_direction == ORB_DIRECTION_NO_DATA_TRANSFER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1795 | command_orb->data_descriptor_hi = 0x0; |
| 1796 | command_orb->data_descriptor_lo = 0x0; |
| 1797 | command_orb->misc |= ORB_SET_DIRECTION(1); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1798 | } else if (scsi_use_sg) |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1799 | sbp2_prep_command_orb_sg(command_orb, hi, command, scsi_use_sg, |
| 1800 | sgpnt, orb_direction, dma_dir); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1801 | else |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1802 | sbp2_prep_command_orb_no_sg(command_orb, hi, command, sgpnt, |
| 1803 | orb_direction, scsi_request_bufflen, |
| 1804 | scsi_request_buffer, dma_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1805 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1806 | /* Byte swap command ORB if necessary */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | sbp2util_cpu_to_be32_buffer(command_orb, sizeof(struct sbp2_command_orb)); |
| 1808 | |
Stefan Richter | cf8d2c0 | 2005-12-13 11:05:03 -0500 | [diff] [blame] | 1809 | /* Put our scsi command in the command ORB */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | memset(command_orb->cdb, 0, 12); |
| 1811 | memcpy(command_orb->cdb, scsi_cmd, COMMAND_SIZE(*scsi_cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /* |
| 1815 | * This function is called in order to begin a regular SBP-2 command. |
| 1816 | */ |
Stefan Richter | 2821276 | 2006-07-23 22:10:00 +0200 | [diff] [blame] | 1817 | static void sbp2_link_orb_command(struct scsi_id_instance_data *scsi_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | struct sbp2_command_info *command) |
| 1819 | { |
| 1820 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 1821 | struct sbp2_command_orb *command_orb = &command->command_orb; |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1822 | struct sbp2_command_orb *last_orb; |
| 1823 | dma_addr_t last_orb_dma; |
| 1824 | u64 addr = scsi_id->sbp2_command_block_agent_addr; |
| 1825 | quadlet_t data[2]; |
| 1826 | size_t length; |
| 1827 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | pci_dma_sync_single_for_device(hi->host->pdev, command->command_orb_dma, |
| 1830 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 1831 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1832 | pci_dma_sync_single_for_device(hi->host->pdev, command->sge_dma, |
| 1833 | sizeof(command->scatter_gather_element), |
| 1834 | PCI_DMA_BIDIRECTIONAL); |
| 1835 | /* |
| 1836 | * Check to see if there are any previous orbs to use |
| 1837 | */ |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1838 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
| 1839 | last_orb = scsi_id->last_orb; |
| 1840 | last_orb_dma = scsi_id->last_orb_dma; |
| 1841 | if (!last_orb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1842 | /* |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1843 | * last_orb == NULL means: We know that the target's fetch agent |
| 1844 | * is not active right now. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | */ |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1846 | addr += SBP2_ORB_POINTER_OFFSET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | data[0] = ORB_SET_NODE_ID(hi->host->node_id); |
| 1848 | data[1] = command->command_orb_dma; |
| 1849 | sbp2util_cpu_to_be32_buffer(data, 8); |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1850 | length = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | /* |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1853 | * last_orb != NULL means: We know that the target's fetch agent |
| 1854 | * is (very probably) not dead or in reset state right now. |
| 1855 | * We have an ORB already sent that we can append a new one to. |
| 1856 | * The target's fetch agent may or may not have read this |
| 1857 | * previous ORB yet. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | */ |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1859 | pci_dma_sync_single_for_cpu(hi->host->pdev, last_orb_dma, |
| 1860 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 1861 | PCI_DMA_TODEVICE); |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1862 | last_orb->next_ORB_lo = cpu_to_be32(command->command_orb_dma); |
| 1863 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | /* Tells hardware that this pointer is valid */ |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1865 | last_orb->next_ORB_hi = 0; |
| 1866 | pci_dma_sync_single_for_device(hi->host->pdev, last_orb_dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 1868 | PCI_DMA_TODEVICE); |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 1869 | addr += SBP2_DOORBELL_OFFSET; |
| 1870 | data[0] = 0; |
| 1871 | length = 4; |
| 1872 | } |
| 1873 | scsi_id->last_orb = command_orb; |
| 1874 | scsi_id->last_orb_dma = command->command_orb_dma; |
| 1875 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 1877 | if (sbp2util_node_write_no_wait(scsi_id->ne, addr, data, length)) { |
| 1878 | /* |
| 1879 | * sbp2util_node_write_no_wait failed. We certainly ran out |
| 1880 | * of transaction labels, perhaps just because there were no |
| 1881 | * context switches which gave khpsbpkt a chance to collect |
| 1882 | * free tlabels. Try again in non-atomic context. If necessary, |
| 1883 | * the workqueue job will sleep to guaranteedly get a tlabel. |
| 1884 | * We do not accept new commands until the job is over. |
| 1885 | */ |
| 1886 | scsi_block_requests(scsi_id->scsi_host); |
Stefan Richter | d19c776 | 2006-12-07 22:40:33 +0100 | [diff] [blame^] | 1887 | PREPARE_WORK(&scsi_id->protocol_work, |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 1888 | last_orb ? sbp2util_write_doorbell: |
Stefan Richter | d19c776 | 2006-12-07 22:40:33 +0100 | [diff] [blame^] | 1889 | sbp2util_write_orb_pointer |
| 1890 | /* */); |
| 1891 | schedule_work(&scsi_id->protocol_work); |
Stefan Richter | 09ee67a | 2006-08-14 18:43:00 +0200 | [diff] [blame] | 1892 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | /* |
| 1896 | * This function is called in order to begin a regular SBP-2 command. |
| 1897 | */ |
| 1898 | static int sbp2_send_command(struct scsi_id_instance_data *scsi_id, |
| 1899 | struct scsi_cmnd *SCpnt, |
| 1900 | void (*done)(struct scsi_cmnd *)) |
| 1901 | { |
| 1902 | unchar *cmd = (unchar *) SCpnt->cmnd; |
| 1903 | unsigned int request_bufflen = SCpnt->request_bufflen; |
| 1904 | struct sbp2_command_info *command; |
| 1905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | /* |
| 1907 | * Allocate a command orb and s/g structure |
| 1908 | */ |
| 1909 | command = sbp2util_allocate_command_orb(scsi_id, SCpnt, done); |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 1910 | if (!command) |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1911 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | |
| 1913 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | * Now actually fill in the comamnd orb and sbp2 s/g list |
| 1915 | */ |
| 1916 | sbp2_create_command_orb(scsi_id, command, cmd, SCpnt->use_sg, |
| 1917 | request_bufflen, SCpnt->request_buffer, |
| 1918 | SCpnt->sc_data_direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1921 | * Link up the orb, and ring the doorbell if needed |
| 1922 | */ |
| 1923 | sbp2_link_orb_command(scsi_id, command); |
| 1924 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1925 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
| 1927 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1928 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | * Translates SBP-2 status into SCSI sense data for check conditions |
| 1930 | */ |
| 1931 | static unsigned int sbp2_status_to_sense_data(unchar *sbp2_status, unchar *sense_data) |
| 1932 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | /* |
| 1934 | * Ok, it's pretty ugly... ;-) |
| 1935 | */ |
| 1936 | sense_data[0] = 0x70; |
| 1937 | sense_data[1] = 0x0; |
| 1938 | sense_data[2] = sbp2_status[9]; |
| 1939 | sense_data[3] = sbp2_status[12]; |
| 1940 | sense_data[4] = sbp2_status[13]; |
| 1941 | sense_data[5] = sbp2_status[14]; |
| 1942 | sense_data[6] = sbp2_status[15]; |
| 1943 | sense_data[7] = 10; |
| 1944 | sense_data[8] = sbp2_status[16]; |
| 1945 | sense_data[9] = sbp2_status[17]; |
| 1946 | sense_data[10] = sbp2_status[18]; |
| 1947 | sense_data[11] = sbp2_status[19]; |
| 1948 | sense_data[12] = sbp2_status[10]; |
| 1949 | sense_data[13] = sbp2_status[11]; |
| 1950 | sense_data[14] = sbp2_status[20]; |
| 1951 | sense_data[15] = sbp2_status[21]; |
| 1952 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1953 | return sbp2_status[8] & 0x3f; /* return scsi status */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | } |
| 1955 | |
| 1956 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | * This function deals with status writes from the SBP-2 device |
| 1958 | */ |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 1959 | static int sbp2_handle_status_write(struct hpsb_host *host, int nodeid, |
| 1960 | int destid, quadlet_t *data, u64 addr, |
| 1961 | size_t length, u16 fl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1962 | { |
| 1963 | struct sbp2scsi_host_info *hi; |
| 1964 | struct scsi_id_instance_data *scsi_id = NULL, *scsi_id_tmp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | struct scsi_cmnd *SCpnt = NULL; |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 1966 | struct sbp2_status_block *sb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | u32 scsi_status = SBP2_SCSI_STATUS_GOOD; |
| 1968 | struct sbp2_command_info *command; |
Jody McIntyre | 7945619 | 2005-11-07 06:29:39 -0500 | [diff] [blame] | 1969 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1971 | if (unlikely(length < 8 || length > sizeof(struct sbp2_status_block))) { |
| 1972 | SBP2_ERR("Wrong size of status block"); |
| 1973 | return RCODE_ADDRESS_ERROR; |
| 1974 | } |
| 1975 | if (unlikely(!host)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | SBP2_ERR("host is NULL - this is bad!"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1977 | return RCODE_ADDRESS_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | hi = hpsb_get_hostinfo(&sbp2_highlevel, host); |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1980 | if (unlikely(!hi)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | SBP2_ERR("host info is NULL - this is bad!"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1982 | return RCODE_ADDRESS_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | /* |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1985 | * Find our scsi_id structure by looking at the status fifo address |
| 1986 | * written to by the sbp2 device. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | list_for_each_entry(scsi_id_tmp, &hi->scsi_ids, scsi_list) { |
Stefan Richter | 35bdddb | 2006-01-31 00:13:33 -0500 | [diff] [blame] | 1989 | if (scsi_id_tmp->ne->nodeid == nodeid && |
| 1990 | scsi_id_tmp->status_fifo_addr == addr) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | scsi_id = scsi_id_tmp; |
| 1992 | break; |
| 1993 | } |
| 1994 | } |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 1995 | if (unlikely(!scsi_id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | SBP2_ERR("scsi_id is NULL - device is gone?"); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 1997 | return RCODE_ADDRESS_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | /* |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 2001 | * Put response into scsi_id status fifo buffer. The first two bytes |
| 2002 | * come in big endian bit order. Often the target writes only a |
| 2003 | * truncated status block, minimally the first two quadlets. The rest |
| 2004 | * is implied to be zeros. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | */ |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 2006 | sb = &scsi_id->status_block; |
| 2007 | memset(sb->command_set_dependent, 0, sizeof(sb->command_set_dependent)); |
| 2008 | memcpy(sb, data, length); |
| 2009 | sbp2util_be32_to_cpu_buffer(sb, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | |
| 2011 | /* |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 2012 | * Ignore unsolicited status. Handle command ORB status. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | */ |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 2014 | if (unlikely(STATUS_GET_SRC(sb->ORB_offset_hi_misc) == 2)) |
| 2015 | command = NULL; |
| 2016 | else |
| 2017 | command = sbp2util_find_command_for_orb(scsi_id, |
| 2018 | sb->ORB_offset_lo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | if (command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, |
| 2021 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 2022 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2023 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, |
| 2024 | sizeof(command->scatter_gather_element), |
| 2025 | PCI_DMA_BIDIRECTIONAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | /* |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 2027 | * Matched status with command, now grab scsi command pointers |
| 2028 | * and check status. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | */ |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 2030 | /* |
| 2031 | * FIXME: If the src field in the status is 1, the ORB DMA must |
| 2032 | * not be reused until status for a subsequent ORB is received. |
| 2033 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | SCpnt = command->Current_SCpnt; |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 2035 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | sbp2util_mark_command_completed(scsi_id, command); |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 2037 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2038 | |
| 2039 | if (SCpnt) { |
Stefan Richter | abbca10 | 2006-08-14 18:51:00 +0200 | [diff] [blame] | 2040 | u32 h = sb->ORB_offset_hi_misc; |
| 2041 | u32 r = STATUS_GET_RESP(h); |
| 2042 | |
| 2043 | if (r != RESP_STATUS_REQUEST_COMPLETE) { |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 2044 | SBP2_INFO("resp 0x%x, sbp_status 0x%x", |
Stefan Richter | abbca10 | 2006-08-14 18:51:00 +0200 | [diff] [blame] | 2045 | r, STATUS_GET_SBP_STATUS(h)); |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 2046 | scsi_status = |
Stefan Richter | abbca10 | 2006-08-14 18:51:00 +0200 | [diff] [blame] | 2047 | r == RESP_STATUS_TRANSPORT_FAILURE ? |
| 2048 | SBP2_SCSI_STATUS_BUSY : |
Stefan Richter | 6065772 | 2006-07-23 22:18:00 +0200 | [diff] [blame] | 2049 | SBP2_SCSI_STATUS_COMMAND_TERMINATED; |
Stefan Richter | abbca10 | 2006-08-14 18:51:00 +0200 | [diff] [blame] | 2050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | /* |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 2052 | * See if the target stored any scsi status information. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | */ |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 2054 | if (STATUS_GET_LEN(h) > 1) |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 2055 | scsi_status = sbp2_status_to_sense_data( |
| 2056 | (unchar *)sb, SCpnt->sense_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | /* |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 2058 | * Check to see if the dead bit is set. If so, we'll |
| 2059 | * have to initiate a fetch agent reset. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | */ |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 2061 | if (STATUS_TEST_DEAD(h)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | sbp2_agent_reset(scsi_id, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | } |
| 2064 | |
| 2065 | /* |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 2066 | * Check here to see if there are no commands in-use. If there |
| 2067 | * are none, we know that the fetch agent left the active state |
| 2068 | * _and_ that we did not reactivate it yet. Therefore clear |
| 2069 | * last_orb so that next time we write directly to the |
| 2070 | * ORB_POINTER register. That way the fetch agent does not need |
| 2071 | * to refetch the next_ORB. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | */ |
Jody McIntyre | 7945619 | 2005-11-07 06:29:39 -0500 | [diff] [blame] | 2073 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
Stefan Richter | cc07818 | 2006-07-23 22:12:00 +0200 | [diff] [blame] | 2074 | if (list_empty(&scsi_id->sbp2_command_orb_inuse)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2075 | scsi_id->last_orb = NULL; |
Jody McIntyre | 7945619 | 2005-11-07 06:29:39 -0500 | [diff] [blame] | 2076 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | |
| 2078 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | /* |
| 2080 | * It's probably a login/logout/reconnect status. |
| 2081 | */ |
Stefan Richter | 3e98eab4 | 2006-07-23 22:16:00 +0200 | [diff] [blame] | 2082 | if ((sb->ORB_offset_lo == scsi_id->reconnect_orb_dma) || |
| 2083 | (sb->ORB_offset_lo == scsi_id->login_orb_dma) || |
| 2084 | (sb->ORB_offset_lo == scsi_id->query_logins_orb_dma) || |
Stefan Richter | e8398bb | 2006-07-23 22:19:00 +0200 | [diff] [blame] | 2085 | (sb->ORB_offset_lo == scsi_id->logout_orb_dma)) { |
| 2086 | scsi_id->access_complete = 1; |
| 2087 | wake_up_interruptible(&access_wq); |
| 2088 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | } |
| 2090 | |
Stefan Richter | edf1fb2 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 2091 | if (SCpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | sbp2scsi_complete_command(scsi_id, scsi_status, SCpnt, |
| 2093 | command->Current_done); |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2094 | return RCODE_COMPLETE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | } |
| 2096 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | /************************************** |
| 2098 | * SCSI interface related section |
| 2099 | **************************************/ |
| 2100 | |
| 2101 | /* |
| 2102 | * This routine is the main request entry routine for doing I/O. It is |
| 2103 | * called from the scsi stack directly. |
| 2104 | */ |
| 2105 | static int sbp2scsi_queuecommand(struct scsi_cmnd *SCpnt, |
| 2106 | void (*done)(struct scsi_cmnd *)) |
| 2107 | { |
| 2108 | struct scsi_id_instance_data *scsi_id = |
| 2109 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; |
| 2110 | struct sbp2scsi_host_info *hi; |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2111 | int result = DID_NO_CONNECT << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2113 | if (!sbp2util_node_is_available(scsi_id)) |
| 2114 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | |
| 2116 | hi = scsi_id->hi; |
| 2117 | |
| 2118 | if (!hi) { |
| 2119 | SBP2_ERR("sbp2scsi_host_info is NULL - this is bad!"); |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2120 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2121 | } |
| 2122 | |
| 2123 | /* |
| 2124 | * Until we handle multiple luns, just return selection time-out |
| 2125 | * to any IO directed at non-zero LUNs |
| 2126 | */ |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2127 | if (SCpnt->device->lun) |
| 2128 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | |
| 2130 | /* |
| 2131 | * Check for request sense command, and handle it here |
| 2132 | * (autorequest sense) |
| 2133 | */ |
| 2134 | if (SCpnt->cmnd[0] == REQUEST_SENSE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | memcpy(SCpnt->request_buffer, SCpnt->sense_buffer, SCpnt->request_bufflen); |
| 2136 | memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer)); |
| 2137 | sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_GOOD, SCpnt, done); |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2138 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
| 2141 | /* |
| 2142 | * Check to see if we are in the middle of a bus reset. |
| 2143 | */ |
| 2144 | if (!hpsb_node_entry_valid(scsi_id->ne)) { |
| 2145 | SBP2_ERR("Bus reset in progress - rejecting command"); |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2146 | result = DID_BUS_BUSY << 16; |
| 2147 | goto done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | /* |
Stefan Richter | 43863eb | 2005-12-12 23:03:24 -0500 | [diff] [blame] | 2151 | * Bidirectional commands are not yet implemented, |
| 2152 | * and unknown transfer direction not handled. |
| 2153 | */ |
| 2154 | if (SCpnt->sc_data_direction == DMA_BIDIRECTIONAL) { |
| 2155 | SBP2_ERR("Cannot handle DMA_BIDIRECTIONAL - rejecting command"); |
| 2156 | result = DID_ERROR << 16; |
| 2157 | goto done; |
| 2158 | } |
| 2159 | |
| 2160 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2161 | * Try and send our SCSI command |
| 2162 | */ |
| 2163 | if (sbp2_send_command(scsi_id, SCpnt, done)) { |
| 2164 | SBP2_ERR("Error sending SCSI command"); |
| 2165 | sbp2scsi_complete_command(scsi_id, SBP2_SCSI_STATUS_SELECTION_TIMEOUT, |
| 2166 | SCpnt, done); |
| 2167 | } |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2168 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2170 | done: |
| 2171 | SCpnt->result = result; |
| 2172 | done(SCpnt); |
| 2173 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | /* |
| 2177 | * This function is called in order to complete all outstanding SBP-2 |
| 2178 | * commands (in case of resets, etc.). |
| 2179 | */ |
| 2180 | static void sbp2scsi_complete_all_commands(struct scsi_id_instance_data *scsi_id, |
| 2181 | u32 status) |
| 2182 | { |
| 2183 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 2184 | struct list_head *lh; |
| 2185 | struct sbp2_command_info *command; |
Jody McIntyre | 7945619 | 2005-11-07 06:29:39 -0500 | [diff] [blame] | 2186 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | |
Jody McIntyre | 7945619 | 2005-11-07 06:29:39 -0500 | [diff] [blame] | 2188 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | while (!list_empty(&scsi_id->sbp2_command_orb_inuse)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | lh = scsi_id->sbp2_command_orb_inuse.next; |
| 2191 | command = list_entry(lh, struct sbp2_command_info, list); |
| 2192 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->command_orb_dma, |
| 2193 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 2194 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2195 | pci_dma_sync_single_for_cpu(hi->host->pdev, command->sge_dma, |
| 2196 | sizeof(command->scatter_gather_element), |
| 2197 | PCI_DMA_BIDIRECTIONAL); |
| 2198 | sbp2util_mark_command_completed(scsi_id, command); |
| 2199 | if (command->Current_SCpnt) { |
| 2200 | command->Current_SCpnt->result = status << 16; |
| 2201 | command->Current_done(command->Current_SCpnt); |
| 2202 | } |
| 2203 | } |
Jody McIntyre | 7945619 | 2005-11-07 06:29:39 -0500 | [diff] [blame] | 2204 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | |
| 2206 | return; |
| 2207 | } |
| 2208 | |
| 2209 | /* |
| 2210 | * This function is called in order to complete a regular SBP-2 command. |
| 2211 | * |
| 2212 | * This can be called in interrupt context. |
| 2213 | */ |
| 2214 | static void sbp2scsi_complete_command(struct scsi_id_instance_data *scsi_id, |
| 2215 | u32 scsi_status, struct scsi_cmnd *SCpnt, |
| 2216 | void (*done)(struct scsi_cmnd *)) |
| 2217 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | /* |
| 2219 | * Sanity |
| 2220 | */ |
| 2221 | if (!SCpnt) { |
| 2222 | SBP2_ERR("SCpnt is NULL"); |
| 2223 | return; |
| 2224 | } |
| 2225 | |
| 2226 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2227 | * Switch on scsi status |
| 2228 | */ |
| 2229 | switch (scsi_status) { |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2230 | case SBP2_SCSI_STATUS_GOOD: |
Stefan Richter | 8f0525f | 2006-03-28 20:03:45 -0500 | [diff] [blame] | 2231 | SCpnt->result = DID_OK << 16; |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2232 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2234 | case SBP2_SCSI_STATUS_BUSY: |
| 2235 | SBP2_ERR("SBP2_SCSI_STATUS_BUSY"); |
| 2236 | SCpnt->result = DID_BUS_BUSY << 16; |
| 2237 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2239 | case SBP2_SCSI_STATUS_CHECK_CONDITION: |
Stefan Richter | 8f0525f | 2006-03-28 20:03:45 -0500 | [diff] [blame] | 2240 | SCpnt->result = CHECK_CONDITION << 1 | DID_OK << 16; |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2241 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2242 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2243 | case SBP2_SCSI_STATUS_SELECTION_TIMEOUT: |
| 2244 | SBP2_ERR("SBP2_SCSI_STATUS_SELECTION_TIMEOUT"); |
| 2245 | SCpnt->result = DID_NO_CONNECT << 16; |
| 2246 | scsi_print_command(SCpnt); |
| 2247 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2248 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2249 | case SBP2_SCSI_STATUS_CONDITION_MET: |
| 2250 | case SBP2_SCSI_STATUS_RESERVATION_CONFLICT: |
| 2251 | case SBP2_SCSI_STATUS_COMMAND_TERMINATED: |
| 2252 | SBP2_ERR("Bad SCSI status = %x", scsi_status); |
| 2253 | SCpnt->result = DID_ERROR << 16; |
| 2254 | scsi_print_command(SCpnt); |
| 2255 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2257 | default: |
| 2258 | SBP2_ERR("Unsupported SCSI status = %x", scsi_status); |
| 2259 | SCpnt->result = DID_ERROR << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | } |
| 2261 | |
| 2262 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2263 | * If a bus reset is in progress and there was an error, complete |
| 2264 | * the command as busy so that it will get retried. |
| 2265 | */ |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2266 | if (!hpsb_node_entry_valid(scsi_id->ne) |
| 2267 | && (scsi_status != SBP2_SCSI_STATUS_GOOD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | SBP2_ERR("Completing command with busy (bus reset)"); |
| 2269 | SCpnt->result = DID_BUS_BUSY << 16; |
| 2270 | } |
| 2271 | |
| 2272 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2273 | * Tell scsi stack that we're done with this command |
| 2274 | */ |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2275 | done(SCpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2278 | static int sbp2scsi_slave_alloc(struct scsi_device *sdev) |
| 2279 | { |
Stefan Richter | a80614d | 2006-02-14 22:04:19 -0500 | [diff] [blame] | 2280 | struct scsi_id_instance_data *scsi_id = |
| 2281 | (struct scsi_id_instance_data *)sdev->host->hostdata[0]; |
| 2282 | |
| 2283 | scsi_id->sdev = sdev; |
Stefan Richter | c394f1e | 2006-08-07 20:48:00 +0200 | [diff] [blame] | 2284 | sdev->allow_restart = 1; |
Stefan Richter | a80614d | 2006-02-14 22:04:19 -0500 | [diff] [blame] | 2285 | |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 2286 | if (scsi_id->workarounds & SBP2_WORKAROUND_INQUIRY_36) |
Stefan Richter | a80614d | 2006-02-14 22:04:19 -0500 | [diff] [blame] | 2287 | sdev->inquiry_len = 36; |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2288 | return 0; |
| 2289 | } |
| 2290 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2291 | static int sbp2scsi_slave_configure(struct scsi_device *sdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | { |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 2293 | struct scsi_id_instance_data *scsi_id = |
| 2294 | (struct scsi_id_instance_data *)sdev->host->hostdata[0]; |
| 2295 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | blk_queue_dma_alignment(sdev->request_queue, (512 - 1)); |
Ben Collins | 365c786 | 2005-11-07 06:31:24 -0500 | [diff] [blame] | 2297 | sdev->use_10_for_rw = 1; |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 2298 | |
| 2299 | if (sdev->type == TYPE_DISK && |
| 2300 | scsi_id->workarounds & SBP2_WORKAROUND_MODE_SENSE_8) |
| 2301 | sdev->skip_ms_page_8 = 1; |
Stefan Richter | e9a1c52 | 2006-05-15 22:06:37 +0200 | [diff] [blame] | 2302 | if (scsi_id->workarounds & SBP2_WORKAROUND_FIX_CAPACITY) |
| 2303 | sdev->fix_capacity = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2304 | return 0; |
| 2305 | } |
| 2306 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2307 | static void sbp2scsi_slave_destroy(struct scsi_device *sdev) |
| 2308 | { |
| 2309 | ((struct scsi_id_instance_data *)sdev->host->hostdata[0])->sdev = NULL; |
| 2310 | return; |
| 2311 | } |
| 2312 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2313 | /* |
| 2314 | * Called by scsi stack when something has really gone wrong. Usually |
| 2315 | * called when a command has timed-out for some reason. |
| 2316 | */ |
| 2317 | static int sbp2scsi_abort(struct scsi_cmnd *SCpnt) |
| 2318 | { |
| 2319 | struct scsi_id_instance_data *scsi_id = |
| 2320 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; |
| 2321 | struct sbp2scsi_host_info *hi = scsi_id->hi; |
| 2322 | struct sbp2_command_info *command; |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 2323 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 2325 | SBP2_INFO("aborting sbp2 command"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | scsi_print_command(SCpnt); |
| 2327 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2328 | if (sbp2util_node_is_available(scsi_id)) { |
Stefan Richter | 23077f1 | 2006-09-11 20:17:14 +0200 | [diff] [blame] | 2329 | sbp2_agent_reset(scsi_id, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
Stefan Richter | 23077f1 | 2006-09-11 20:17:14 +0200 | [diff] [blame] | 2331 | /* Return a matching command structure to the free pool. */ |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 2332 | spin_lock_irqsave(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | command = sbp2util_find_command_for_SCpnt(scsi_id, SCpnt); |
| 2334 | if (command) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | pci_dma_sync_single_for_cpu(hi->host->pdev, |
| 2336 | command->command_orb_dma, |
| 2337 | sizeof(struct sbp2_command_orb), |
Stefan Richter | d4018d7 | 2006-07-23 22:57:00 +0200 | [diff] [blame] | 2338 | PCI_DMA_TODEVICE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | pci_dma_sync_single_for_cpu(hi->host->pdev, |
| 2340 | command->sge_dma, |
| 2341 | sizeof(command->scatter_gather_element), |
| 2342 | PCI_DMA_BIDIRECTIONAL); |
| 2343 | sbp2util_mark_command_completed(scsi_id, command); |
| 2344 | if (command->Current_SCpnt) { |
| 2345 | command->Current_SCpnt->result = DID_ABORT << 16; |
| 2346 | command->Current_done(command->Current_SCpnt); |
| 2347 | } |
| 2348 | } |
Stefan Richter | 24c7cd0 | 2006-04-01 21:11:41 +0200 | [diff] [blame] | 2349 | spin_unlock_irqrestore(&scsi_id->sbp2_command_orb_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | sbp2scsi_complete_all_commands(scsi_id, DID_BUS_BUSY); |
| 2352 | } |
| 2353 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2354 | return SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | } |
| 2356 | |
| 2357 | /* |
| 2358 | * Called by scsi stack when something has really gone wrong. |
| 2359 | */ |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2360 | static int sbp2scsi_reset(struct scsi_cmnd *SCpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | { |
| 2362 | struct scsi_id_instance_data *scsi_id = |
| 2363 | (struct scsi_id_instance_data *)SCpnt->device->host->hostdata[0]; |
| 2364 | |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 2365 | SBP2_INFO("reset requested"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2366 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2367 | if (sbp2util_node_is_available(scsi_id)) { |
Stefan Richter | 3564409 | 2006-11-02 21:16:08 +0100 | [diff] [blame] | 2368 | SBP2_INFO("generating sbp2 fetch agent reset"); |
Stefan Richter | 1f427e8 | 2006-08-14 18:44:00 +0200 | [diff] [blame] | 2369 | sbp2_agent_reset(scsi_id, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | } |
| 2371 | |
Jody McIntyre | abd559b | 2005-09-30 11:59:06 -0700 | [diff] [blame] | 2372 | return SUCCESS; |
Jeff Garzik | 94d0e7b8 | 2005-05-28 07:55:48 -0400 | [diff] [blame] | 2373 | } |
| 2374 | |
Stefan Richter | a237f35 | 2005-11-07 06:31:39 -0500 | [diff] [blame] | 2375 | static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, |
| 2376 | struct device_attribute *attr, |
| 2377 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | { |
| 2379 | struct scsi_device *sdev; |
| 2380 | struct scsi_id_instance_data *scsi_id; |
| 2381 | int lun; |
| 2382 | |
| 2383 | if (!(sdev = to_scsi_device(dev))) |
| 2384 | return 0; |
| 2385 | |
| 2386 | if (!(scsi_id = (struct scsi_id_instance_data *)sdev->host->hostdata[0])) |
| 2387 | return 0; |
| 2388 | |
Ben Collins | e309fc6 | 2005-11-07 06:31:34 -0500 | [diff] [blame] | 2389 | lun = ORB_SET_LUN(scsi_id->sbp2_lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | |
| 2391 | return sprintf(buf, "%016Lx:%d:%d\n", (unsigned long long)scsi_id->ne->guid, |
| 2392 | scsi_id->ud->id, lun); |
| 2393 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | |
| 2395 | MODULE_AUTHOR("Ben Collins <bcollins@debian.org>"); |
| 2396 | MODULE_DESCRIPTION("IEEE-1394 SBP-2 protocol driver"); |
| 2397 | MODULE_SUPPORTED_DEVICE(SBP2_DEVICE_NAME); |
| 2398 | MODULE_LICENSE("GPL"); |
| 2399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2400 | static int sbp2_module_init(void) |
| 2401 | { |
| 2402 | int ret; |
| 2403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2404 | /* Module load debug option to force one command at a time (serializing I/O) */ |
| 2405 | if (serialize_io) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | scsi_driver_template.can_queue = 1; |
| 2407 | scsi_driver_template.cmd_per_lun = 1; |
| 2408 | } |
| 2409 | |
Stefan Richter | 24d3bf8 | 2006-05-15 22:04:59 +0200 | [diff] [blame] | 2410 | if (sbp2_default_workarounds & SBP2_WORKAROUND_128K_MAX_TRANS && |
| 2411 | (max_sectors * 512) > (128 * 1024)) |
| 2412 | max_sectors = 128 * 1024 / 512; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | scsi_driver_template.max_sectors = max_sectors; |
| 2414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2415 | /* Register our high level driver with 1394 stack */ |
| 2416 | hpsb_register_highlevel(&sbp2_highlevel); |
| 2417 | |
| 2418 | ret = hpsb_register_protocol(&sbp2_driver); |
| 2419 | if (ret) { |
| 2420 | SBP2_ERR("Failed to register protocol"); |
| 2421 | hpsb_unregister_highlevel(&sbp2_highlevel); |
| 2422 | return ret; |
| 2423 | } |
| 2424 | |
| 2425 | return 0; |
| 2426 | } |
| 2427 | |
| 2428 | static void __exit sbp2_module_exit(void) |
| 2429 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | hpsb_unregister_protocol(&sbp2_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | hpsb_unregister_highlevel(&sbp2_highlevel); |
| 2432 | } |
| 2433 | |
| 2434 | module_init(sbp2_module_init); |
| 2435 | module_exit(sbp2_module_exit); |