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