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